Adapted to taiHen.
Adapted to taiHen.
This commit is contained in:
parent
cb38409eb3
commit
8e20fe7337
50
plugin/CMakeLists.txt
Normal file
50
plugin/CMakeLists.txt
Normal file
@ -0,0 +1,50 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
if(DEFINED ENV{VITASDK})
|
||||
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
|
||||
else()
|
||||
message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
project(TrackPlug)
|
||||
include("${VITASDK}/share/vita.cmake" REQUIRED)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -O3 -std=gnu99")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions")
|
||||
|
||||
include_directories(
|
||||
)
|
||||
|
||||
link_directories(
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
if (NOT ${RELEASE})
|
||||
add_definitions(-DENABLE_LOGGING)
|
||||
endif()
|
||||
|
||||
add_executable(TrackPlug
|
||||
main.c
|
||||
)
|
||||
|
||||
target_link_libraries(TrackPlug
|
||||
taihen_stub
|
||||
SceAppUtil_stub
|
||||
SceAppMgr_stub
|
||||
SceLibKernel_stub
|
||||
SceDisplay_stub
|
||||
k
|
||||
gcc
|
||||
ScePower_stub
|
||||
kuio_stub
|
||||
)
|
||||
|
||||
set_target_properties(TrackPlug
|
||||
PROPERTIES LINK_FLAGS "-nostdlib"
|
||||
)
|
||||
|
||||
vita_create_self(TrackPlug.suprx TrackPlug
|
||||
CONFIG ${CMAKE_SOURCE_DIR}/TrackPlug.yml
|
||||
)
|
@ -1,27 +0,0 @@
|
||||
TARGET = TrackPlug
|
||||
OBJS = main.o
|
||||
|
||||
LIBS = -lSceAppUtil_stub -lSceAppMgr_stub -lSceFios2_stub -lSceKernel_stub -lScePower_stub -lSceLibc_stub
|
||||
|
||||
PREFIX = arm-vita-eabi
|
||||
CC = $(PREFIX)-gcc
|
||||
CFLAGS = -g -Wl,-q -Wall -O3 -nostartfiles
|
||||
ASFLAGS = $(CFLAGS)
|
||||
|
||||
all: $(TARGET).suprx
|
||||
|
||||
%.suprx: %.velf
|
||||
vita-make-fself $< $@
|
||||
|
||||
%.velf: %.elf
|
||||
vita-elf-create $< $@
|
||||
|
||||
$(TARGET).elf: $(OBJS)
|
||||
$(CC) $(CFLAGS) $^ $(LIBS) -o $@
|
||||
|
||||
clean:
|
||||
@rm -rf $(TARGET).suprx $(TARGET).velf $(TARGET).elf $(OBJS)
|
||||
|
||||
send: $(TARGET).suprx
|
||||
curl -T $(TARGET).suprx ftp://$(PSVITAIP):1337/ux0:/plugins/$(TARGET).suprx
|
||||
@echo "Sent."
|
8
plugin/TrackPlug.yml
Normal file
8
plugin/TrackPlug.yml
Normal file
@ -0,0 +1,8 @@
|
||||
TrackPlug:
|
||||
attributes: 0
|
||||
version:
|
||||
major: 1
|
||||
minor: 2
|
||||
main:
|
||||
start: module_start
|
||||
stop: module_stop
|
@ -1,51 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <psp2/io/dirent.h>
|
||||
#include <psp2/io/fcntl.h>
|
||||
#include <psp2/io/stat.h>
|
||||
#include <psp2/appmgr.h>
|
||||
#include <psp2/kernel/processmgr.h>
|
||||
#include <vitasdk.h>
|
||||
#include <taihen.h>
|
||||
#include <kuio.h>
|
||||
#include <libk/string.h>
|
||||
#include <libk/stdio.h>
|
||||
|
||||
int main_thread(SceSize args, void *argp) {
|
||||
static SceUID hook;
|
||||
static tai_hook_ref_t ref;
|
||||
static char titleid[16];
|
||||
static char fname[256];
|
||||
static uint64_t playtime = 0;
|
||||
static uint64_t tick = 0;
|
||||
|
||||
int sceDisplaySetFrameBuf_patched(const SceDisplayFrameBuf *pParam, int sync) {
|
||||
|
||||
// Creating required folders for TrackPlug if they don't exist
|
||||
sceIoMkdir("ux0:/data/TrackPlug", 0777);
|
||||
uint64_t t_tick = sceKernelGetProcessTimeWide();
|
||||
|
||||
// Saving playtime every 10 seconds
|
||||
if ((t_tick - tick) > 10000000){
|
||||
tick = t_tick;
|
||||
playtime += 10;
|
||||
SceUID fd;
|
||||
kuIoOpen(fname, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, &fd);
|
||||
kuIoWrite(fd, &playtime, sizeof(uint64_t));
|
||||
kuIoClose(fd);
|
||||
}
|
||||
|
||||
return TAI_CONTINUE(int, ref, pParam, sync);
|
||||
}
|
||||
|
||||
void _start() __attribute__ ((weak, alias ("module_start")));
|
||||
int module_start(SceSize argc, const void *args) {
|
||||
|
||||
// Getting game Title ID
|
||||
char titleid[16], filename[256];
|
||||
sceAppMgrAppParamGetString(0, 12, titleid , 256);
|
||||
|
||||
// Recovering current playtime
|
||||
sprintf(filename, "ux0:/data/TrackPlug/%s.bin", titleid);
|
||||
uint64_t playtime = 0;
|
||||
int fd = sceIoOpen(filename, SCE_O_RDONLY, 0777);
|
||||
// Getting current playtime
|
||||
SceUID fd;
|
||||
sprintf(fname, "ux0:/data/TrackPlug/%s.bin", titleid);
|
||||
kuIoOpen(fname, SCE_O_RDONLY, &fd);
|
||||
if (fd >= 0){
|
||||
sceIoRead(fd, &playtime, sizeof(uint64_t));
|
||||
sceIoClose(fd);
|
||||
kuIoRead(fd, &playtime, sizeof(uint64_t));
|
||||
kuIoClose(fd);
|
||||
}
|
||||
|
||||
for (;;){
|
||||
// Getting starting tick
|
||||
tick = sceKernelGetProcessTimeWide();
|
||||
|
||||
// We update the tracking plugin every 10 secs
|
||||
sceKernelDelayThread(10 * 1000 * 1000);
|
||||
playtime+=10;
|
||||
|
||||
// Updating the tracking file
|
||||
int fd = sceIoOpen(filename, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777);
|
||||
sceIoWrite(fd, &playtime, sizeof(uint64_t));
|
||||
sceIoClose(fd);
|
||||
hook = taiHookFunctionImport(&ref,
|
||||
TAI_MAIN_MODULE,
|
||||
TAI_ANY_LIBRARY,
|
||||
0x7A410B64,
|
||||
sceDisplaySetFrameBuf_patched);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
return SCE_KERNEL_START_SUCCESS;
|
||||
}
|
||||
|
||||
int _start(SceSize args, void *argp) {
|
||||
SceUID thid = sceKernelCreateThread("TrackPlug", main_thread, 0x40, 0x100000, 0, 0, NULL);
|
||||
if (thid >= 0)
|
||||
sceKernelStartThread(thid, 0, NULL);
|
||||
int module_stop(SceSize argc, const void *args) {
|
||||
|
||||
return 0;
|
||||
return SCE_KERNEL_STOP_SUCCESS;
|
||||
|
||||
}
|
Reference in New Issue
Block a user