diff --git a/game_re/CMakeLists.txt b/game_re/CMakeLists.txt index e89ef076..87dc901b 100644 --- a/game_re/CMakeLists.txt +++ b/game_re/CMakeLists.txt @@ -32,10 +32,12 @@ target_link_libraries(game_re PRIVATE spdlog) file(GLOB GH_AUTO_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_auto/*.cxx) file(GLOB GH_FIX_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_fix/*.cxx) +file(GLOB GH_STUB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_stub/*.cxx) target_sources(game_re PRIVATE ${GH_AUTO_SOURCES} ${GH_FIX_SOURCES} + ${GH_STUB_SOURCES} ) # Ignore -Wformat-security diff --git a/game_re/binders/gh_base.h b/game_re/binders/gh_base.h index bfe9279c..feb3684c 100644 --- a/game_re/binders/gh_base.h +++ b/game_re/binders/gh_base.h @@ -30,6 +30,27 @@ enum R3ModuleId : uint8_t { R3ModId_not_initialized = 0xff, }; +typedef uint32_t cc_type_t; + +template +inline constexpr cc_type_t CONCAT11(T0 a, T1 b) { + return cc_type_t(a) << 8 | cc_type_t(b); +} +template +inline constexpr cc_type_t CONCAT21(T0 a, T1 b) { + return cc_type_t(a) << 8 | cc_type_t(b); +} + +template +inline constexpr cc_type_t CONCAT22(T0 a, T1 b) { + return cc_type_t(a) << 16 | cc_type_t(b); +} + +template +inline constexpr cc_type_t CONCAT23(T0 a, T1 b) { + return cc_type_t(a) << 24 | cc_type_t(b); +} + // Can not export enums for some reason #endif /* A523F6DB_0645_4DEB_8AEB_3792CB732B49 */ diff --git a/game_re/gh_fix/r3_main.cxx b/game_re/gh_fix/r3_main.cxx index 2af16c0e..60467aef 100644 --- a/game_re/gh_fix/r3_main.cxx +++ b/game_re/gh_fix/r3_main.cxx @@ -3,25 +3,27 @@ #include #include "../gh_global.h" -extern undefined r3_initEngine(void); // 00401220 // r3_initEngine +extern "C" { +undefined r3_initEngine(void); // 00401220 // r3_initEngine extern undefined r3_module0_init(void); // 00401000 // r3_module0_init -extern uint32_t r3_containsCmdLine( - uint *param_1, char *param_2); // 004028e0 // r3_containsCmdLine +extern uint32_t +r3_containsCmdLine(uint *param_1, + char *param_2); // 004028e0 // r3_containsCmdLine extern undefined FUN_004010b0(void); // 004010b0 // FUN_004010b0 extern undefined FUN_004464f0(void); // 004464f0 // FUN_004464f0 extern undefined FUN_00503710(void); // 00503710 // FUN_00503710 -extern undefined r3_setupWindow( - HINSTANCE hInstance, undefined4 param_2, - undefined4 param_3); // 00402140 // r3_setupWindow -extern undefined FUN_00401320(void); // 00401320 // FUN_00401320 -extern undefined spawnThread(void); // 004477d0 // spawnThread -extern undefined FUN_005038e0(void); // 005038e0 // FUN_005038e0 -extern undefined FUN_004fb300(void); // 004fb300 // FUN_004fb300 -extern void g_setInitVar0(void); // 00401310 // g_setInitVar0 +extern undefined +r3_setupWindow(HINSTANCE hInstance, undefined4 param_2, + undefined4 param_3); // 00402140 // r3_setupWindow +extern undefined FUN_00401320(void); // 00401320 // FUN_00401320 +extern undefined spawnThread(void); // 004477d0 // spawnThread +extern undefined FUN_005038e0(void); // 005038e0 // FUN_005038e0 +extern undefined FUN_004fb300(void); // 004fb300 // FUN_004fb300 +extern void g_setInitVar0(void); // 00401310 // g_setInitVar0 extern void r3_noop(void *p_cTxt1, - void *p_cTxt2); // 00401100 // r3_noop + void *p_cTxt2); // 00401100 // r3_noop extern undefined r3_checkDisc(void); // 004464f0 // r3_checkDisc -extern undefined gfx_init2(void); // 00470be0 // gfx_init2 +extern undefined gfx_init2(void); // 00470be0 // gfx_init2 extern undefined4 __cdecl r3_get_gli_width( void); // 0047baf0 // r3_get_gli_width extern undefined FUN_00472150(void); // 00472150 // FUN_00472150 @@ -413,7 +415,7 @@ LAB_004017ce: sprintf(acStack_810, s_Please_run_the__s_setup__005b63f4, s_windowTitle); sprintf(acStack_508, s__s_not_initialized__005b63e0, s_windowTitle); // FUN_0043e540(acStack_810, acStack_508, 0); - MessageBoxA(g_gameHWND, acStack_810, acStack_508, - 0 | 0x10000); + MessageBoxA(g_gameHWND, acStack_810, acStack_508, 0 | 0x10000); exit(1); } +} diff --git a/game_re/gh_stub/FUN_004010b0.cxx b/game_re/gh_stub/FUN_004010b0.cxx new file mode 100644 index 00000000..4230cf16 --- /dev/null +++ b/game_re/gh_stub/FUN_004010b0.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 004010b0 +// FUN_004010b0 +extern "C" undefined FUN_004010b0(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: FUN_004010b0"); +} diff --git a/game_re/gh_stub/FUN_00401320.cxx b/game_re/gh_stub/FUN_00401320.cxx new file mode 100644 index 00000000..6b3c5d53 --- /dev/null +++ b/game_re/gh_stub/FUN_00401320.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00401320 +// FUN_00401320 +extern "C" undefined FUN_00401320(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: FUN_00401320"); +} diff --git a/game_re/gh_stub/FUN_00470db0.cxx b/game_re/gh_stub/FUN_00470db0.cxx new file mode 100644 index 00000000..8f6f0478 --- /dev/null +++ b/game_re/gh_stub/FUN_00470db0.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00470db0 +// FUN_00470db0 +extern "C" undefined FUN_00470db0(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: FUN_00470db0"); +} diff --git a/game_re/gh_stub/FUN_00472150.cxx b/game_re/gh_stub/FUN_00472150.cxx new file mode 100644 index 00000000..e91e2ef9 --- /dev/null +++ b/game_re/gh_stub/FUN_00472150.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00472150 +// FUN_00472150 +extern "C" undefined FUN_00472150(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: FUN_00472150"); +} diff --git a/game_re/gh_stub/FUN_004725a0.cxx b/game_re/gh_stub/FUN_004725a0.cxx new file mode 100644 index 00000000..fdf23678 --- /dev/null +++ b/game_re/gh_stub/FUN_004725a0.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 004725a0 +// FUN_004725a0 +extern "C" undefined FUN_004725a0(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: FUN_004725a0"); +} diff --git a/game_re/gh_stub/FUN_004fb300.cxx b/game_re/gh_stub/FUN_004fb300.cxx new file mode 100644 index 00000000..1775221e --- /dev/null +++ b/game_re/gh_stub/FUN_004fb300.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 004fb300 +// FUN_004fb300 +extern "C" undefined FUN_004fb300(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: FUN_004fb300"); +} diff --git a/game_re/gh_stub/FUN_00503710.cxx b/game_re/gh_stub/FUN_00503710.cxx new file mode 100644 index 00000000..6636fe29 --- /dev/null +++ b/game_re/gh_stub/FUN_00503710.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00503710 +// FUN_00503710 +extern "C" undefined FUN_00503710(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: FUN_00503710"); +} diff --git a/game_re/gh_stub/FUN_005038e0.cxx b/game_re/gh_stub/FUN_005038e0.cxx new file mode 100644 index 00000000..c67b8772 --- /dev/null +++ b/game_re/gh_stub/FUN_005038e0.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 005038e0 +// FUN_005038e0 +extern "C" undefined FUN_005038e0(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: FUN_005038e0"); +} diff --git a/game_re/gh_stub/g_setInitVar0.cxx b/game_re/gh_stub/g_setInitVar0.cxx new file mode 100644 index 00000000..1bae4bde --- /dev/null +++ b/game_re/gh_stub/g_setInitVar0.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00401310 +// g_setInitVar0 +extern "C" void g_setInitVar0(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: g_setInitVar0"); +} diff --git a/game_re/gh_stub/gfx_init2.cxx b/game_re/gh_stub/gfx_init2.cxx new file mode 100644 index 00000000..48f1579b --- /dev/null +++ b/game_re/gh_stub/gfx_init2.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00470be0 +// gfx_init2 +extern "C" undefined gfx_init2(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: gfx_init2"); +} diff --git a/game_re/gh_stub/r3_checkDisc.cxx b/game_re/gh_stub/r3_checkDisc.cxx new file mode 100644 index 00000000..d0542664 --- /dev/null +++ b/game_re/gh_stub/r3_checkDisc.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 004464f0 +// r3_checkDisc +extern "C" undefined r3_checkDisc(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: r3_checkDisc"); +} diff --git a/game_re/gh_stub/r3_get_gli_height1.cxx b/game_re/gh_stub/r3_get_gli_height1.cxx new file mode 100644 index 00000000..21a33e50 --- /dev/null +++ b/game_re/gh_stub/r3_get_gli_height1.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 0047bb00 +// r3_get_gli_height1 +extern "C" int r3_get_gli_height1(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: r3_get_gli_height1"); +} diff --git a/game_re/gh_stub/r3_get_gli_width1.cxx b/game_re/gh_stub/r3_get_gli_width1.cxx new file mode 100644 index 00000000..9b1b85cd --- /dev/null +++ b/game_re/gh_stub/r3_get_gli_width1.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 0047baf0 +// r3_get_gli_width1 +extern "C" undefined4 r3_get_gli_width1(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: r3_get_gli_width1"); +} diff --git a/game_re/gh_stub/r3_initEngine.cxx b/game_re/gh_stub/r3_initEngine.cxx new file mode 100644 index 00000000..20aa98b8 --- /dev/null +++ b/game_re/gh_stub/r3_initEngine.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00401220 +// r3_initEngine +extern "C" undefined r3_initEngine(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: r3_initEngine"); +} diff --git a/game_re/gh_stub/r3_module0_init.cxx b/game_re/gh_stub/r3_module0_init.cxx new file mode 100644 index 00000000..5b4be8d9 --- /dev/null +++ b/game_re/gh_stub/r3_module0_init.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00401000 +// r3_module0_init +extern "C" undefined r3_module0_init(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: r3_module0_init"); +} diff --git a/game_re/gh_stub/r3_setupWindow.cxx b/game_re/gh_stub/r3_setupWindow.cxx new file mode 100644 index 00000000..26ab067c --- /dev/null +++ b/game_re/gh_stub/r3_setupWindow.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 00402140 +// r3_setupWindow +extern "C" undefined r3_setupWindow(undefined4 hInstance, undefined4 param_2, undefined4 maximizeWindow) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: r3_setupWindow"); +} diff --git a/game_re/gh_stub/r3_wait_for_dvd.cxx b/game_re/gh_stub/r3_wait_for_dvd.cxx new file mode 100644 index 00000000..f41993ad --- /dev/null +++ b/game_re/gh_stub/r3_wait_for_dvd.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 0043e540 +// r3_wait_for_dvd +extern "C" undefined r3_wait_for_dvd(undefined4 param_1, undefined4 param_2, undefined4 param_3) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: r3_wait_for_dvd"); +} diff --git a/game_re/gh_stub/spawnThread.cxx b/game_re/gh_stub/spawnThread.cxx new file mode 100644 index 00000000..3349eb47 --- /dev/null +++ b/game_re/gh_stub/spawnThread.cxx @@ -0,0 +1,14 @@ +// AUTO-GENERATED FILE!!!! +// This function has yet to be decompiled using 'Dump Current Function' in ghidra +// with possible manualy fixes + +#include +#include "../gh_global.h" +#include + +// 004477d0 +// spawnThread +extern "C" undefined spawnThread(void) { + // TODO: Implement this function + throw std::runtime_error("Function not implemented: spawnThread"); +} diff --git a/game_re/main.cpp b/game_re/main.cpp index f6bcf1b2..f762b218 100644 --- a/game_re/main.cpp +++ b/game_re/main.cpp @@ -3,8 +3,8 @@ #include #include -int r3_main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR *cmdline, - int showCmd); +extern "C" int r3_main(HINSTANCE hInstance, HINSTANCE hPrevInstance, + LPSTR *cmdline, int showCmd); extern void gh_init_data_segment(); int main() { diff --git a/scripts/re3lib/FunctionDumper.java b/scripts/re3lib/FunctionDumper.java index e6894f33..59690bcd 100644 --- a/scripts/re3lib/FunctionDumper.java +++ b/scripts/re3lib/FunctionDumper.java @@ -106,6 +106,13 @@ public class FunctionDumper { String sanitizedFunctionName = Utils.sanitizeIdentifier(function.getName()); String fileName = sanitizedFunctionName + ".cxx"; + // Remove the stub file, since we now use the decompiled file + File stubFile = new File(RecompileConfig.INSTANCE.dirDecompStub, fileName); + if (stubFile.exists()) { + script.println("Removing function stub " + stubFile); + stubFile.delete(); + } + File f0 = new File(RecompileConfig.INSTANCE.dirDecompFix, fileName); if (f0.exists()) { script.println("Func " + function.getName() + " skipped (gh_fix)"); @@ -130,6 +137,7 @@ public class FunctionDumper { writer2.println("#include "); writer2.println("#include \"../gh_global.h\""); writer2.println(); + writer2.println("extern \"C\" {"); HighFunction highFunction = decompRes.getHighFunction(); @@ -216,7 +224,7 @@ public class FunctionDumper { if (calledFunction != null) { if (isValidFunction(calledFunction)) { String proto = calledFunction.getSignature().getPrototypeString(false); - headers.add("extern " + proto + headers.add("" + proto + "; // " + calledFunction.getEntryPoint() + " // " + calledFunction.getName()); externalFunctionCalls.add(calledFunction); @@ -239,16 +247,21 @@ public class FunctionDumper { writer2.println(header); } writer2.println(); - writer2.println("// " + function.getEntryPoint()); + writer2.print("// " + function.getEntryPoint()); writer2.print(codeWriter.toString()); + writer2.println("}"); writer2.println(); } // Possibly generate stubs for external functions for (Function externalFunction : externalFunctionCalls) { + String sanitizedExtFunctionName = Utils.sanitizeIdentifier(externalFunction.getName()); + fileName = sanitizedExtFunctionName + ".cxx"; File f2 = new File(RecompileConfig.INSTANCE.dirDecompFix, fileName); File f3 = new File(RecompileConfig.INSTANCE.dirDecompAuto, fileName); if (f2.exists() || f3.exists()) { + // script.println("Skipping external function: " + externalFunction.getName() + + // " - " + externalFunction.getEntryPoint()); continue; } @@ -266,7 +279,7 @@ public class FunctionDumper { writer2.println(); writer2.println("// " + externalFunction.getEntryPoint()); writer2.println("// " + externalFunction.getName()); - writer2.println(externalFunction.getSignature().getPrototypeString(false) + " {"); + writer2.println("extern \"C\" " + externalFunction.getSignature().getPrototypeString(false) + " {"); writer2.println(" // TODO: Implement this function"); writer2 .println(" throw std::runtime_error(\"Function not implemented: " + externalFunction.getName() + "\");");