This repository has been archived on 2024-06-25. You can view files and clone it, but cannot push or open issues or pull requests.
BetterTrackPlug/plugin/main.c

62 lines
1.4 KiB
C
Raw Normal View History

2017-05-01 16:14:28 +03:00
#include <vitasdk.h>
#include <taihen.h>
#include <kuio.h>
#include <libk/string.h>
#include <libk/stdio.h>
2016-10-17 23:27:03 +03:00
2017-05-01 16:14:28 +03:00
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) {
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);
}
2016-10-17 23:27:03 +03:00
2017-05-01 16:14:28 +03:00
return TAI_CONTINUE(int, ref, pParam, sync);
}
void _start() __attribute__ ((weak, alias ("module_start")));
int module_start(SceSize argc, const void *args) {
2016-10-17 23:27:03 +03:00
// Getting game Title ID
sceAppMgrAppParamGetString(0, 12, titleid , 256);
2017-05-01 16:14:28 +03:00
// Getting current playtime
SceUID fd;
sprintf(fname, "ux0:/data/TrackPlug/%s.bin", titleid);
kuIoOpen(fname, SCE_O_RDONLY, &fd);
2016-10-17 23:27:03 +03:00
if (fd >= 0){
2017-05-01 16:14:28 +03:00
kuIoRead(fd, &playtime, sizeof(uint64_t));
kuIoClose(fd);
2016-10-17 23:27:03 +03:00
}
2017-05-01 16:14:28 +03:00
// Getting starting tick
tick = sceKernelGetProcessTimeWide();
2016-10-17 23:27:03 +03:00
2017-05-01 16:14:28 +03:00
hook = taiHookFunctionImport(&ref,
TAI_MAIN_MODULE,
TAI_ANY_LIBRARY,
0x7A410B64,
sceDisplaySetFrameBuf_patched);
2016-10-17 23:27:03 +03:00
2017-05-01 16:14:28 +03:00
return SCE_KERNEL_START_SUCCESS;
2016-10-17 23:27:03 +03:00
}
2017-05-01 16:14:28 +03:00
int module_stop(SceSize argc, const void *args) {
2016-10-17 23:27:03 +03:00
2017-05-01 16:14:28 +03:00
return SCE_KERNEL_STOP_SUCCESS;
2016-10-17 23:27:03 +03:00
}