Adapted to taiHen.

Adapted to taiHen.
This commit is contained in:
Rinnegatamante 2017-05-01 15:14:28 +02:00
parent cb38409eb3
commit 8e20fe7337
4 changed files with 105 additions and 63 deletions

50
plugin/CMakeLists.txt Normal file
View 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
)

View File

@ -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
View File

@ -0,0 +1,8 @@
TrackPlug:
attributes: 0
version:
major: 1
minor: 2
main:
start: module_start
stop: module_stop

View File

@ -1,51 +1,62 @@
#include <stdio.h> #include <vitasdk.h>
#include <stdarg.h> #include <taihen.h>
#include <stdlib.h> #include <kuio.h>
#include <string.h> #include <libk/string.h>
#include <psp2/io/dirent.h> #include <libk/stdio.h>
#include <psp2/io/fcntl.h>
#include <psp2/io/stat.h>
#include <psp2/appmgr.h>
#include <psp2/kernel/processmgr.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;
// Creating required folders for TrackPlug if they don't exist int sceDisplaySetFrameBuf_patched(const SceDisplayFrameBuf *pParam, int sync) {
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 // Getting game Title ID
char titleid[16], filename[256];
sceAppMgrAppParamGetString(0, 12, titleid , 256); sceAppMgrAppParamGetString(0, 12, titleid , 256);
// Recovering current playtime // Getting current playtime
sprintf(filename, "ux0:/data/TrackPlug/%s.bin", titleid); SceUID fd;
uint64_t playtime = 0; sprintf(fname, "ux0:/data/TrackPlug/%s.bin", titleid);
int fd = sceIoOpen(filename, SCE_O_RDONLY, 0777); kuIoOpen(fname, SCE_O_RDONLY, &fd);
if (fd >= 0){ if (fd >= 0){
sceIoRead(fd, &playtime, sizeof(uint64_t)); kuIoRead(fd, &playtime, sizeof(uint64_t));
sceIoClose(fd); kuIoClose(fd);
} }
for (;;){ // Getting starting tick
tick = sceKernelGetProcessTimeWide();
// We update the tracking plugin every 10 secs hook = taiHookFunctionImport(&ref,
sceKernelDelayThread(10 * 1000 * 1000); TAI_MAIN_MODULE,
playtime+=10; TAI_ANY_LIBRARY,
0x7A410B64,
sceDisplaySetFrameBuf_patched);
// Updating the tracking file return SCE_KERNEL_START_SUCCESS;
int fd = sceIoOpen(filename, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777);
sceIoWrite(fd, &playtime, sizeof(uint64_t));
sceIoClose(fd);
}
return 0;
} }
int _start(SceSize args, void *argp) { int module_stop(SceSize argc, const void *args) {
SceUID thid = sceKernelCreateThread("TrackPlug", main_thread, 0x40, 0x100000, 0, 0, NULL);
if (thid >= 0) return SCE_KERNEL_STOP_SUCCESS;
sceKernelStartThread(thid, 0, NULL);
return 0;
} }