diff --git a/game_re/gh_fix/r3_windowProc.cxx b/game_re/gh_fix/r3_windowProc.cxx index e2d7c447..ab4a991d 100644 --- a/game_re/gh_fix/r3_windowProc.cxx +++ b/game_re/gh_fix/r3_windowProc.cxx @@ -8,7 +8,7 @@ undefined FUN_00401320(void); // 00401320 // FUN_00401320 // cdecl undefined r3_windowUnlockCursor(void); // 004013a0 // r3_windowUnlockCursor // cdecl // 004025e0 -long r3_windowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) +long __stdcall r3_windowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { long lVar1; diff --git a/java/ghidra/re3lib/FunctionDumper.java b/java/ghidra/re3lib/FunctionDumper.java index ff41c58c..fd835cf9 100644 --- a/java/ghidra/re3lib/FunctionDumper.java +++ b/java/ghidra/re3lib/FunctionDumper.java @@ -133,7 +133,8 @@ public class FunctionDumper { // Extract calling convention from Ghidra function String callingConventionName = externalFunction.getCallingConventionName(); - FunctionDatabase.CallingConvention callingConvention = FunctionDatabase.CallingConvention.fromString(callingConventionName); + FunctionDatabase.CallingConvention callingConvention = FunctionDatabase.CallingConvention + .fromString(callingConventionName); script.println("Detected calling convention: " + callingConventionName + " -> " + callingConvention); try (PrintWriter writer2 = new PrintWriter(f4, "UTF-8")) { @@ -212,7 +213,8 @@ public class FunctionDumper { // Extract calling convention from Ghidra function String callingConventionName = function.getCallingConventionName(); - FunctionDatabase.CallingConvention callingConvention = FunctionDatabase.CallingConvention.fromString(callingConventionName); + FunctionDatabase.CallingConvention callingConvention = FunctionDatabase.CallingConvention + .fromString(callingConventionName); script.println("Detected calling convention: " + callingConventionName + " -> " + callingConvention); // Handle forceFixType flag @@ -290,6 +292,17 @@ public class FunctionDumper { List externalFunctionCalls = new ArrayList<>(); HashMap replacementMap = new HashMap<>(); + String newFunctionName = sanitizedFunctionName; + if (callingConvention != FunctionDatabase.CallingConvention.Stdcall || + callingConvention != FunctionDatabase.CallingConvention.Fastcall) { + newFunctionName = callingConventionName + " " + newFunctionName; + } + + String originalFunctionName = function.getName(); + if (newFunctionName != originalFunctionName) { + replacementMap.put(originalFunctionName, newFunctionName); + } + DecompileResults decompRes = RemanConfig.INSTANCE.decompCache.getOrInsert(function); try (PrintWriter writer2 = new PrintWriter(f0, "UTF-8")) { writer2.println("// AUTO-GENERATED FILE, MOVE TO 'gh_fix' FOLDER PREVENT OVERWRITING!!!!! "); @@ -316,11 +329,6 @@ public class FunctionDumper { // Parse preliminary line tokens for (int i = 0; i < line.getNumTokens(); i++) { ClangToken token = line.getToken(i); - // Remove some of the calling conventions, keep __stdcall/fastcall - if (token.getText().equals("__cdecl") || token.getText().equals("__thiscall")) { - // Remove function declaration - continue; - } if (!token.getText().isEmpty()) tokens.add(token); } @@ -421,7 +429,7 @@ public class FunctionDumper { String proto = externalFunction.getSignature().getPrototypeString(false); String name = externalFunction.getName(); proto = proto.replace(name, Utils.sanitizeIdentifier(name)); - + // Add calling convention information to the comment String callingConv = externalFunction.getCallingConventionName(); FunctionDatabase.CallingConvention conv = FunctionDatabase.CallingConvention.fromString(callingConv);