different favorite files per game version

This commit is contained in:
CrazyRedMachine 2024-04-29 22:31:32 +02:00
parent e9bdbaa9f7
commit 0e1f365ac2
4 changed files with 133 additions and 129 deletions

View File

@ -4,6 +4,7 @@
#include <stdbool.h> #include <stdbool.h>
struct popnhax_config { struct popnhax_config {
uint8_t game_version;
bool practice_mode; bool practice_mode;
bool hidden_is_offset; bool hidden_is_offset;
bool iidx_hard_gauge; bool iidx_hard_gauge;

View File

@ -19,6 +19,7 @@
#include "minhook/hde32.h" #include "minhook/hde32.h"
#include "minhook/include/MinHook.h" #include "minhook/include/MinHook.h"
uint8_t g_game_version;
uint32_t g_playerdata_ptr_addr; //pointer to the playerdata memory zone (offset 0x08 is popn friend ID as ascii (12 char long), offset 0x1A5 is "is logged in" flag) uint32_t g_playerdata_ptr_addr; //pointer to the playerdata memory zone (offset 0x08 is popn friend ID as ascii (12 char long), offset 0x1A5 is "is logged in" flag)
char *g_current_friendid; char *g_current_friendid;
uint32_t g_current_songid; uint32_t g_current_songid;
@ -78,7 +79,7 @@ void remove_song_from_favorites()
void prepare_favorite_list(){ void prepare_favorite_list(){
char fav_filepath[64]; char fav_filepath[64];
sprintf(fav_filepath, "data_mods\\%s.fav", g_current_friendid); sprintf(fav_filepath, "data_mods\\%d.%s.fav", g_game_version, g_current_friendid);
FILE *file = fopen(fav_filepath, "rb"); FILE *file = fopen(fav_filepath, "rb");
favorites_count = 0; favorites_count = 0;
@ -111,7 +112,7 @@ void commit_favorites()
return; return;
char fav_filepath[64]; char fav_filepath[64];
sprintf(fav_filepath, "data_mods\\%s.fav", g_current_friendid); sprintf(fav_filepath, "data_mods\\%d.%s.fav", g_game_version, g_current_friendid);
FILE *file = fopen(fav_filepath, "w"); FILE *file = fopen(fav_filepath, "w");
if ( file == NULL ) if ( file == NULL )
@ -964,37 +965,6 @@ static void load_databases() {
} }
LOG("\n"); LOG("\n");
} }
/*
bool load_favorites(){
favorites_count = subcategories[0].size;
favorites = subcategories[0].songlist;
return true;
}*/
bool load_favorites(){
FILE *file = fopen("data_mods\\default.fav", "rb");
if (file == NULL)
{
return false;
}
char line[32];
while (fgets(line, sizeof(line), file)) {
/* note that fgets don't strip the terminating \n, checking its
presence would allow to handle lines longer that sizeof(line) */
int songid = strtol(line, NULL, 10);
if ( songid != 0 )
{
favorites = (uint32_t *) realloc(favorites, sizeof(uint32_t)*(favorites_count+5));
favorites[favorites_count++] = songid | 0x00060000; // game wants this otherwise only easy difficulty will appear
}
}
fclose(file);
LOG("added %d songs to favorites\n",favorites_count);
return true;
}
void (*real_getversion)(); void (*real_getversion)();
void hook_getversion() void hook_getversion()
@ -1106,8 +1076,8 @@ LOG("custom title format is %s\n", g_customformat);
return patch_custom_categ(dllFilename); return patch_custom_categ(dllFilename);
} }
bool patch_local_favorites(const char *dllFilename) bool patch_local_favorites(const char *dllFilename, uint8_t version)
{ {
//load_favorites(); g_game_version = version;
return patch_favorite_categ(dllFilename); return patch_favorite_categ(dllFilename);
} }

View File

@ -5,6 +5,6 @@
#include "popnhax/config.h" #include "popnhax/config.h"
bool patch_custom_categs(const char *dllFilename, struct popnhax_config *config); bool patch_custom_categs(const char *dllFilename, struct popnhax_config *config);
bool patch_local_favorites(const char *dllFilename); bool patch_local_favorites(const char *dllFilename, uint8_t version);
#endif #endif

View File

@ -5303,6 +5303,22 @@ static bool option_net_ojama_off(){
return true; return true;
} }
uint8_t get_version()
{
DWORD dllSize = 0;
char *data = getDllData(g_game_dll_fn, &dllSize);
{
int64_t pattern_offset = search(data, dllSize, "\x00\x8B\x56\x04\x0F\xB7\x02\xE8", 8, 0);
if (pattern_offset == -1) {
LOG("popnhax: get_version: cannot retrieve game version (eclale or less?)\n");
return 0;
}
uint8_t version = *(uint8_t*)(data + pattern_offset + 14);
return version;
}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) { switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH: { case DLL_PROCESS_ATTACH: {
@ -5374,7 +5390,9 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
free(tmp_name); free(tmp_name);
} }
LOG("popnhax: game dll: %s\n",g_game_dll_fn); uint8_t game_version = get_version();
LOG("popnhax: game dll: %s (popn%d)\n",g_game_dll_fn, game_version);
LOG("popnhax: config file: %s\n",g_config_fn); LOG("popnhax: config file: %s\n",g_config_fn);
if (!_load_config(g_config_fn, &config, config_psmap)) if (!_load_config(g_config_fn, &config, config_psmap))
@ -5383,12 +5401,15 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
return FALSE; return FALSE;
} }
config.game_version = game_version;
if (force_trans_debug) if (force_trans_debug)
config.translation_debug = true; config.translation_debug = true;
if (force_no_omni) if (force_no_omni)
config.patch_db = false; config.patch_db = false;
if (!config.disable_multiboot) if (!config.disable_multiboot)
{ {
/* automatically force datecode based on dll name when applicable (e.g. popn22_2022061300.dll and no force_datecode) */ /* automatically force datecode based on dll name when applicable (e.g. popn22_2022061300.dll and no force_datecode) */
@ -5398,21 +5419,26 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
LOG("popnhax: multiboot autotune activated (custom game dll, force_datecode off)\n"); LOG("popnhax: multiboot autotune activated (custom game dll, force_datecode off)\n");
memcpy(config.force_datecode, g_game_dll_fn+7, 10); memcpy(config.force_datecode, g_game_dll_fn+7, 10);
LOG("popnhax: multiboot: auto set datecode to %s\n", config.force_datecode); LOG("popnhax: multiboot: auto set datecode to %s\n", config.force_datecode);
if (config.score_challenge && ( strcmp(config.force_datecode,"2020092800") <= 0 ) ) if (config.score_challenge && ( config.game_version < 26 || strcmp(config.force_datecode,"2020092800") <= 0 ) )
{ {
LOG("popnhax: multiboot: auto disable score challenge patch (already ingame)\n"); LOG("popnhax: multiboot: auto disable score challenge patch (already ingame)\n");
config.score_challenge = false; config.score_challenge = false;
} }
if (config.patch_db && ( strcmp(config.force_datecode,"2016121400") < 0 ) ) if (config.patch_db && ( config.game_version == 0 || strcmp(config.force_datecode,"2016121400") < 0 ) )
{ {
LOG("popnhax: multiboot: auto disable omnimix patch (not compatible)\n"); LOG("popnhax: multiboot: auto disable omnimix patch (not compatible)\n");
config.patch_db = false; config.patch_db = false;
} }
if (config.guidese_off && ( strcmp(config.force_datecode,"2016121400") < 0 ) ) if (config.guidese_off && ( config.game_version == 0 || strcmp(config.force_datecode,"2016121400") < 0 ) )
{ {
LOG("popnhax: multiboot: auto disable Guide SE patch (not compatible)\n"); LOG("popnhax: multiboot: auto disable Guide SE patch (not compatible)\n");
config.guidese_off = false; config.guidese_off = false;
} }
if (config.local_favorites && ( config.game_version == 0 || strcmp(config.force_datecode,"2016121400") < 0 ) )
{
LOG("popnhax: multiboot: auto disable local favorites patch (not compatible)\n");
config.local_favorites = false;
}
} }
} }
@ -5616,7 +5642,14 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
} }
if (config.local_favorites) if (config.local_favorites)
patch_local_favorites(g_game_dll_fn); {
if ( config.game_version == 0 )
{
LOG("popnhax: local_favorites: patch is not compatible with your game version.\n");
} else {
patch_local_favorites(g_game_dll_fn, config.game_version);
}
}
if (config.force_full_opt) if (config.force_full_opt)
option_full(); option_full();