Implement shared resources fix for HSR

This commit is contained in:
mkrsym1 2023-06-08 20:13:21 +03:00
parent 2584898be6
commit 38dbf82f7f
4 changed files with 27 additions and 1 deletions

View File

@ -11,12 +11,18 @@ enum game_id {
GAME_HSR_CN
};
#define INVOKE_CALLBACK(callback, ...) if (callback) { callback(__VA_ARGS__); }
typedef void (*unityplayer_callback_t)(HMODULE unityModule);
struct game_data {
enum game_id id; // Temporary
const char *name;
const char *assembly_path;
const char *tp6_section_name; // Unused for now
const char *tvm_section_name;
unityplayer_callback_t unityplayer_callback;
};
void game_detect(struct game_data *buf);

View File

@ -39,4 +39,6 @@ void hi3_fill_data(struct game_data *buf) {
buf->assembly_path = HI3_ASSEMBLY_PATH;
buf->tp6_section_name = HI3_TP6_SECTION_NAME;
buf->tvm_section_name = HI3_TVM_SECTION_NAME;
buf->unityplayer_callback = NULL;
}

View File

@ -20,6 +20,21 @@ const struct crc_id_pair HSR_REGIONS[] = {
{ 0x3e644d26, GAME_HSR_CN } // cn v1.1.0
};
static void _unityplayer_callback(HMODULE unityModule) {
// Disable shared resources
// Temporarily hardcoded offset
// v1.1.0, same for os and cn
unsigned char *srAddr = ((unsigned char*)unityModule) + 0x16430;
DWORD oldProtect;
VirtualProtect(srAddr, 1, PAGE_EXECUTE_READWRITE, &oldProtect);
*srAddr = 0xC3; // ret
VirtualProtect(srAddr, 1, oldProtect, &oldProtect);
}
void hsr_fill_data(struct game_data *buf) {
uint32_t crc = utils_file_crc32c("UnityPlayer.dll");
@ -39,4 +54,6 @@ void hsr_fill_data(struct game_data *buf) {
buf->assembly_path = HSR_ASSEMBLY_PATH;
buf->tp6_section_name = HSR_TP6_SECTION_NAME;
buf->tvm_section_name = HSR_TVM_SECTION_NAME;
buf->unityplayer_callback = &_unityplayer_callback;
}

View File

@ -29,8 +29,9 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) {
// ...magic
tp6_setup_patcher(&game, instance, baseModule);
// Load the UnityPlayer module
// Load the UnityPlayer module and invoke the callback
HMODULE unityModule = LoadLibraryA("UnityPlayer.dll");
INVOKE_CALLBACK(game.unityplayer_callback, unityModule);
return TRUE;
}