From 8e20fe7337dffff46bead80d605115bd04bfc458 Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Mon, 1 May 2017 15:14:28 +0200 Subject: [PATCH] Adapted to taiHen. Adapted to taiHen. --- plugin/CMakeLists.txt | 50 ++++++++++++++++++++++++++ plugin/Makefile | 27 -------------- plugin/TrackPlug.yml | 8 +++++ plugin/main.c | 83 ++++++++++++++++++++++++------------------- 4 files changed, 105 insertions(+), 63 deletions(-) create mode 100644 plugin/CMakeLists.txt delete mode 100644 plugin/Makefile create mode 100644 plugin/TrackPlug.yml diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt new file mode 100644 index 0000000..4379dc2 --- /dev/null +++ b/plugin/CMakeLists.txt @@ -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 +) diff --git a/plugin/Makefile b/plugin/Makefile deleted file mode 100644 index a9e5b81..0000000 --- a/plugin/Makefile +++ /dev/null @@ -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." \ No newline at end of file diff --git a/plugin/TrackPlug.yml b/plugin/TrackPlug.yml new file mode 100644 index 0000000..11cab3b --- /dev/null +++ b/plugin/TrackPlug.yml @@ -0,0 +1,8 @@ +TrackPlug: + attributes: 0 + version: + major: 1 + minor: 2 + main: + start: module_start + stop: module_stop diff --git a/plugin/main.c b/plugin/main.c index e91cee7..892a9a7 100644 --- a/plugin/main.c +++ b/plugin/main.c @@ -1,51 +1,62 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -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; + } \ No newline at end of file