Better relocations

This commit is contained in:
Guus Waals 2025-06-06 02:27:28 +08:00
parent 7d095623ba
commit 599c2f746b
11 changed files with 9006 additions and 41 deletions

View File

@ -20,6 +20,26 @@ public class FindRelocations extends GhidraScript {
long addrMin, addrMax; long addrMin, addrMax;
private void analyzeInstruction(Instruction instruction) {
String mnemonic = instruction.getMnemonicString().toLowerCase();
boolean trace = instruction.getAddress().getOffset() == 0x004ac0f0;
if (trace) {
println("DEBUG: " + mnemonic + " at " + instruction.getAddress());
}
// Check for instructions that commonly use absolute addresses
if (isRelocatableInstruction(mnemonic)) {
// Always run both analyses to catch all cases
// Pcode analysis is better for complex addressing, reference analysis catches
// simple cases
Set<String> foundAddresses = new HashSet<>();
analyzePcodeForConstants(instruction, trace, foundAddresses);
analyzeReferences(instruction, trace, foundAddresses);
}
}
@Override @Override
public void run() throws Exception { public void run() throws Exception {
RemanConfig.INSTANCE = new RemanConfig(this); RemanConfig.INSTANCE = new RemanConfig(this);
@ -87,51 +107,33 @@ public class FindRelocations extends GhidraScript {
} }
} }
private void analyzeInstruction(Instruction instruction) {
String mnemonic = instruction.getMnemonicString().toLowerCase();
boolean trace = instruction.getAddress().getOffset() == 0x0049b154 || instruction.getAddress().getOffset() == 0x00401280 || instruction.getAddress().getOffset() == 0x004014ee;
if (trace) {
println("DEBUG: " + mnemonic + " at " + instruction.getAddress());
}
// Check for instructions that commonly use absolute addresses
if (isRelocatableInstruction(mnemonic)) {
// Always run both analyses to catch all cases
// Pcode analysis is better for complex addressing, reference analysis catches simple cases
Set<String> foundAddresses = new HashSet<>();
analyzePcodeForConstants(instruction, trace, foundAddresses);
analyzeReferences(instruction, trace, foundAddresses);
}
}
private void analyzePcodeForConstants(Instruction instruction, boolean trace, Set<String> foundAddresses) { private void analyzePcodeForConstants(Instruction instruction, boolean trace, Set<String> foundAddresses) {
try { try {
// Get the pcode operations for this instruction // Get the pcode operations for this instruction
PcodeOp[] pcodeOps = instruction.getPcode(); PcodeOp[] pcodeOps = instruction.getPcode();
if (trace) { if (trace) {
println("DEBUG: Analyzing pcode for " + instruction.getAddress()); println("DEBUG: Analyzing pcode for " + instruction.getAddress());
for (PcodeOp op : pcodeOps) { for (PcodeOp op : pcodeOps) {
println("DEBUG: PcodeOp: " + op.toString()); println("DEBUG: PcodeOp: " + op.toString());
} }
} }
for (PcodeOp op : pcodeOps) { for (PcodeOp op : pcodeOps) {
// Look for constants in the pcode that look like addresses // Look for constants in the pcode that look like addresses
Varnode[] inputs = op.getInputs(); Varnode[] inputs = op.getInputs();
for (Varnode input : inputs) { for (Varnode input : inputs) {
if (input.isConstant()) { if (input.isConstant()) {
long constantValue = input.getOffset(); long constantValue = input.getOffset();
// Check if this constant looks like an address in our target range // Check if this constant looks like an address in our target range
if (looksLikeAddress(constantValue)) { if (looksLikeAddress(constantValue)) {
if (trace) { if (trace) {
println("DEBUG: Found constant: 0x" + Long.toHexString(constantValue) + " that looks like an address"); println("DEBUG: Found constant: 0x" + Long.toHexString(constantValue) + " that looks like an address");
} }
try { try {
Address targetAddr = currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(constantValue); Address targetAddr = currentProgram.getAddressFactory().getDefaultAddressSpace()
.getAddress(constantValue);
if (isInMainMemorySpace(targetAddr)) { if (isInMainMemorySpace(targetAddr)) {
String addrKey = targetAddr.toString(); String addrKey = targetAddr.toString();
if (!foundAddresses.contains(addrKey)) { if (!foundAddresses.contains(addrKey)) {
@ -157,7 +159,7 @@ public class FindRelocations extends GhidraScript {
if (trace) { if (trace) {
println("DEBUG: Found address varnode: 0x" + Long.toHexString(addressValue)); println("DEBUG: Found address varnode: 0x" + Long.toHexString(addressValue));
} }
if (looksLikeAddress(addressValue)) { if (looksLikeAddress(addressValue)) {
try { try {
Address targetAddr = input.getAddress(); Address targetAddr = input.getAddress();
@ -201,7 +203,8 @@ public class FindRelocations extends GhidraScript {
if (isInMainMemorySpace) { if (isInMainMemorySpace) {
String addrKey = toAddr.toString(); String addrKey = toAddr.toString();
if (!foundAddresses.contains(addrKey)) { if (!foundAddresses.contains(addrKey)) {
// Check if the target address appears in the instruction bytes (absolute addressing) // Check if the target address appears in the instruction bytes (absolute
// addressing)
int operandOffset = findAbsoluteAddressOffset(instruction, toAddr, trace); int operandOffset = findAbsoluteAddressOffset(instruction, toAddr, trace);
if (operandOffset >= 0) { if (operandOffset >= 0) {
recordRelocation(instruction.getAddress(), toAddr, instruction.getMnemonicString(), recordRelocation(instruction.getAddress(), toAddr, instruction.getMnemonicString(),
@ -281,13 +284,14 @@ public class FindRelocations extends GhidraScript {
private boolean isRelocatableInstruction(String mnemonic) { private boolean isRelocatableInstruction(String mnemonic) {
// Instructions that commonly use absolute addresses // Instructions that commonly use absolute addresses
return mnemonic.equals("mov") || mnemonic.equals("lea") || return true;
mnemonic.equals("call") || mnemonic.equals("jmp") || // mnemonic.equals("mov") || mnemonic.equals("lea") ||
mnemonic.equals("push") || mnemonic.equals("cmp") || // mnemonic.equals("call") || mnemonic.equals("jmp") ||
mnemonic.equals("test") || mnemonic.equals("add") || // mnemonic.equals("push") || mnemonic.equals("cmp") ||
mnemonic.equals("sub") || mnemonic.equals("and") || // mnemonic.equals("test") || mnemonic.equals("add") ||
mnemonic.equals("or") || mnemonic.equals("xor") || // mnemonic.equals("sub") || mnemonic.equals("and") ||
mnemonic.startsWith("j"); // All jumps, we'll filter by byte analysis // mnemonic.equals("or") || mnemonic.equals("xor") ||
// mnemonic.startsWith("j"); // All jumps, we'll filter by byte analysis
} }
private void analyzeDataReferences(long instructionsProcessed, long totalWork) { private void analyzeDataReferences(long instructionsProcessed, long totalWork) {

193
game_re/gh_fix/gfx_init.cxx Normal file
View File

@ -0,0 +1,193 @@
// AUTO-GENERATED FILE, MOVE TO 'gh_fix' FOLDER PREVENT OVERWRITING!!!!!
#include <r3/binders/auto.h>
#include <gh_global.h>
extern "C" {
undefined FUN_00496ac0(void); // 00496ac0 // FUN_00496ac0 // cdecl
IDirect3D8 * Direct3DCreate8(UINT SDKVersion); // 0051e0a8 // Direct3DCreate8 // stdcall
undefined FUN_00470b00(void); // 00470b00 // FUN_00470b00 // cdecl
undefined FUN_00484ea0(undefined4 param_1); // 00484ea0 // FUN_00484ea0 // cdecl
// 0046f870
/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */
/* WARNING: Enum "_D3DFORMAT": Some values do not have unique names */
undefined4 __stdcall gfx_init(HWND hwnd,int param_2,UINT param_3,UINT param_4,int param_5)
{
undefined4 *puVar1;
HRESULT HVar2;
int iVar3;
D3DFORMAT AdapterFormat;
D3DPRESENT_PARAMETERS *pDVar4;
D3DDISPLAYMODE DStack_54;
D3DDISPLAYMODE displayMode;
D3DPRESENT_PARAMETERS DStack_34;
puVar1 = &DAT_007eaf60;
for (iVar3 = 0x13; iVar3 != 0; iVar3 = iVar3 + -1) {
*puVar1 = 0;
puVar1 = puVar1 + 1;
}
puVar1 = &g_gfx_lastColorOp;
for (iVar3 = 0x58; iVar3 != 0; iVar3 = iVar3 + -1) {
*puVar1 = 0;
puVar1 = puVar1 + 1;
}
puVar1 = &DAT_007eb044;
do {
*puVar1 = 0xbf800000;
puVar1 = puVar1 + 0xb;
} while ((int)puVar1 < 0x7eb1a4);
DAT_005bf684 = param_2;
if (param_2 == 0) {
_DAT_005e6c20 = g_GLI_width0;
_DAT_005e6c24 = g_GLI_height0;
DAT_005e6c28 = g_GLI_bitdepth0;
if (param_3 == 0) {
param_3 = g_GLI_width0;
}
if (param_4 == 0) {
param_4 = g_GLI_height0;
}
if (param_5 == 0) {
param_5 = g_GLI_bitdepth0;
}
}
else {
_DAT_005e6c20 = param_3;
_DAT_005e6c24 = param_4;
DAT_005e6c28 = param_5;
}
gfx_d3d = Direct3DCreate8(0xdc);
if (gfx_d3d == (IDirect3D8 *)0x0) {
return 1;
}
HVar2 = (*gfx_d3d->lpVtbl->GetAdapterDisplayMode)(gfx_d3d,0,&displayMode);
if (HVar2 < 0) {
return 1;
}
pDVar4 = &DStack_34;
for (iVar3 = 0xd; iVar3 != 0; iVar3 = iVar3 + -1) {
pDVar4->BackBufferWidth = 0;
pDVar4 = (D3DPRESENT_PARAMETERS *)&pDVar4->BackBufferHeight;
}
DStack_34.Windowed = (BOOL)(DAT_005bf684 == 0);
if (DAT_005bf684 == 0) {
DStack_34.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
DStack_34.BackBufferFormat = displayMode.Format;
param_5 = FUN_00484ea0(displayMode.Format);
AdapterFormat = displayMode.Format;
DAT_005e6c28 = param_5;
}
else {
DStack_34.SwapEffect = D3DSWAPEFFECT_FLIP;
if (param_5 == 0x10) {
DStack_34.BackBufferFormat = D3DFMT_R5G6B5;
AdapterFormat = D3DFMT_R5G6B5;
}
else {
DStack_34.BackBufferFormat = D3DFMT_A8R8G8B8;
AdapterFormat = D3DFMT_X8R8G8B8;
}
}
DStack_34.FullScreen_PresentationInterval = (UINT)(DAT_005bf684 != 0);
DStack_34.BackBufferHeight = param_4;
DStack_34.BackBufferCount = 1;
DStack_34.EnableAutoDepthStencil = 1;
DStack_34.FullScreen_RefreshRateInHz = 0;
DStack_34.BackBufferWidth = param_3;
if (0x10 < param_5) {
HVar2 = (*gfx_d3d->lpVtbl->CheckDeviceFormat)
(gfx_d3d,g_GLI_adapter,D3DDEVTYPE_HAL,AdapterFormat,2,D3DRTYPE_SURFACE,
D3DFMT_D24S8);
if (HVar2 == 0) {
DStack_34.AutoDepthStencilFormat = D3DFMT_D24S8;
DAT_0063be50 = 1;
goto LAB_0046fa6f;
}
HVar2 = (*gfx_d3d->lpVtbl->CheckDeviceFormat)
(gfx_d3d,g_GLI_adapter,D3DDEVTYPE_HAL,AdapterFormat,2,D3DRTYPE_SURFACE,
D3DFMT_D32);
DAT_0063be50 = 0;
if (HVar2 == 0) {
DStack_34.AutoDepthStencilFormat = D3DFMT_D32;
goto LAB_0046fa6f;
}
}
DAT_0063be50 = 0;
DStack_34.AutoDepthStencilFormat = D3DFMT_D16;
(*gfx_d3d->lpVtbl->CheckDeviceFormat)
(gfx_d3d,g_GLI_adapter,D3DDEVTYPE_HAL,AdapterFormat,2,D3DRTYPE_SURFACE,D3DFMT_D16);
LAB_0046fa6f:
DStack_34.Flags = 1;
if (g_GLI_tnl == '\0') {
HVar2 = (*gfx_d3d->lpVtbl->CreateDevice)
(gfx_d3d,g_GLI_adapter,D3DDEVTYPE_HAL,hwnd,0x24,&DStack_34,&gfx_device);
if (HVar2 < 0) {
return 1;
}
}
else {
HVar2 = (*gfx_d3d->lpVtbl->CreateDevice)
(gfx_d3d,g_GLI_adapter,D3DDEVTYPE_HAL,hwnd,0x44,&DStack_34,&gfx_device);
if ((HVar2 < 0) &&
(HVar2 = (*gfx_d3d->lpVtbl->CreateDevice)
(gfx_d3d,g_GLI_adapter,D3DDEVTYPE_HAL,hwnd,0x24,&DStack_34,&gfx_device),
HVar2 < 0)) {
return 1;
}
}
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_NORMALIZENORMALS,0);
DAT_007eafa4 = 0;
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_ZENABLE,1);
DAT_007eafa0 = 1;
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_ZFUNC,4);
DAT_007eaf7c = 4;
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_DITHERENABLE,1);
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_SPECULARENABLE,0);
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_CULLMODE,1);
(*gfx_device->lpVtbl->SetTextureStageState)(gfx_device,0,D3DTSS_COLORARG1,2);
(*gfx_device->lpVtbl->SetTextureStageState)(gfx_device,0,D3DTSS_COLORARG2,0);
(*gfx_device->lpVtbl->SetTextureStageState)(gfx_device,0,D3DTSS_COLOROP,4);
(*gfx_device->lpVtbl->SetTextureStageState)(gfx_device,0,D3DTSS_MINFILTER,2);
(*gfx_device->lpVtbl->SetTextureStageState)(gfx_device,0,D3DTSS_MAGFILTER,2);
(*gfx_device->lpVtbl->SetTextureStageState)(gfx_device,1,D3DTSS_MINFILTER,2);
(*gfx_device->lpVtbl->SetTextureStageState)(gfx_device,1,D3DTSS_MAGFILTER,2);
FUN_00470b00();
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_ALPHATESTENABLE,0);
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_ALPHAFUNC,7);
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_ALPHAREF,0xc0);
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_CLIPPING,1);
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_LIGHTING,0);
DAT_007eafcc = 0x3f800000;
DAT_007eafc8 = 0x3f800000;
DAT_007eafc4 = 0x3f800000;
DAT_007eafc0 = 0x3f800000;
_DAT_007eafdc = 0x3f800000;
_DAT_007eafd8 = 0x3f800000;
_DAT_007eafd4 = 0x3f800000;
_DAT_007eafd0 = 0x3f800000;
_DAT_007eaff8 = 0;
_DAT_007eaff4 = 0;
_DAT_007eaff0 = 0;
_DAT_007eaffc = 0x3f800000;
_DAT_007eb000 = 0;
(*gfx_device->lpVtbl->SetMaterial)(gfx_device,(D3DMATERIAL8 *)&DAT_007eafc0);
(*gfx_device->lpVtbl->SetRenderState)(gfx_device,D3DRS_FOGVERTEXMODE,3);
if ((g_startOfGfxStruct.d3dSurface != (IDirect3DSurface8 *)0x0) ||
(HVar2 = (*gfx_device->lpVtbl->GetBackBuffer)
(gfx_device,0,D3DBACKBUFFER_TYPE_MONO,&g_startOfGfxStruct.d3dSurface),
HVar2 == 0)) {
(*gfx_device->lpVtbl->GetDisplayMode)(gfx_device,&DStack_54);
DStack_54.Height = 0;
DStack_54.Width = DStack_54.RefreshRate;
_g_perfCounterRate = (float)DStack_54.RefreshRate;
FUN_00496ac0();
}
return 0;
}
}

View File

@ -102,6 +102,7 @@ const char* s_Veuillez_ins_rer_le_DVD_dans_vot_005be500 = "Veuillez ins←rer le
const char* s_fmt_c_colon_s = "%c:%s"; // 005be540 const char* s_fmt_c_colon_s = "%c:%s"; // 005be540
const char* s_r3_program_files = "\\program files\\Ubi Soft\\Rayman3"; // 005be548 const char* s_r3_program_files = "\\program files\\Ubi Soft\\Rayman3"; // 005be548
const char* s_driveLetterTemplate = "A:\\"; // 005be568 const char* s_driveLetterTemplate = "A:\\"; // 005be568
undefined4& DAT_005bf684= (undefined4&) GH_MEM(0x005bf684);
undefined4& g_config_camera_hor_axis= (undefined4&) GH_MEM(0x005c67c8); undefined4& g_config_camera_hor_axis= (undefined4&) GH_MEM(0x005c67c8);
undefined4& g_config_camera_ver_axis= (undefined4&) GH_MEM(0x005c67cc); undefined4& g_config_camera_ver_axis= (undefined4&) GH_MEM(0x005c67cc);
undefined1& g_initVar0= (undefined1&) GH_MEM(0x005cf960); undefined1& g_initVar0= (undefined1&) GH_MEM(0x005cf960);
@ -119,7 +120,13 @@ dword& g_soundOnHD= (dword&) GH_MEM(0x005d29bc);
dword& g_complete= (dword&) GH_MEM(0x005d29c0); dword& g_complete= (dword&) GH_MEM(0x005d29c0);
undefined1& DAT_005d2b18= (undefined1&) GH_MEM(0x005d2b18); undefined1& DAT_005d2b18= (undefined1&) GH_MEM(0x005d2b18);
undefined4& DAT_005e693c= (undefined4&) GH_MEM(0x005e693c); undefined4& DAT_005e693c= (undefined4&) GH_MEM(0x005e693c);
undefined4& DAT_005e6c20= (undefined4&) GH_MEM(0x005e6c20);
undefined4& DAT_005e6c24= (undefined4&) GH_MEM(0x005e6c24);
undefined4& DAT_005e6c28= (undefined4&) GH_MEM(0x005e6c28);
IDirect3D8*& gfx_d3d = (IDirect3D8*&)GH_MEM(0x005e6c30); // 005e6c30
r3_astruct_2& g_startOfGfxStruct= (r3_astruct_2&) GH_MEM(0x005f5e24);
undefined4& DAT_0063be24= (undefined4&) GH_MEM(0x0063be24); undefined4& DAT_0063be24= (undefined4&) GH_MEM(0x0063be24);
undefined1& DAT_0063be50= (undefined1&) GH_MEM(0x0063be50);
int& g_windowInitialized= (int&) GH_MEM(0x0077d0a4); int& g_windowInitialized= (int&) GH_MEM(0x0077d0a4);
int& g_runMaximized= (int&) GH_MEM(0x0077d0a8); int& g_runMaximized= (int&) GH_MEM(0x0077d0a8);
undefined4& g_engineShouldRun= (undefined4&) GH_MEM(0x0077d0b0); undefined4& g_engineShouldRun= (undefined4&) GH_MEM(0x0077d0b0);
@ -143,6 +150,30 @@ undefined1& DAT_007d98fc= (undefined1&) GH_MEM(0x007d98fc);
undefined4& DAT_007d9cc4= (undefined4&) GH_MEM(0x007d9cc4); undefined4& DAT_007d9cc4= (undefined4&) GH_MEM(0x007d9cc4);
byte& g_config_unused0= (byte&) GH_MEM(0x007d9df0); byte& g_config_unused0= (byte&) GH_MEM(0x007d9df0);
char(&g_driveLetter)[4] = reinterpret_cast<char(&)[4]>(GH_MEM(0x007d9e70)); char(&g_driveLetter)[4] = reinterpret_cast<char(&)[4]>(GH_MEM(0x007d9e70));
undefined4& g_perfCounterRate= (undefined4&) GH_MEM(0x007e5ad8);
undefined4& DAT_007eaf60= (undefined4&) GH_MEM(0x007eaf60);
undefined4& DAT_007eaf7c= (undefined4&) GH_MEM(0x007eaf7c);
undefined4& DAT_007eafa0= (undefined4&) GH_MEM(0x007eafa0);
undefined4& DAT_007eafa4= (undefined4&) GH_MEM(0x007eafa4);
undefined4& DAT_007eafc0= (undefined4&) GH_MEM(0x007eafc0);
undefined4& DAT_007eafc4= (undefined4&) GH_MEM(0x007eafc4);
undefined4& DAT_007eafc8= (undefined4&) GH_MEM(0x007eafc8);
undefined4& DAT_007eafcc= (undefined4&) GH_MEM(0x007eafcc);
undefined4& DAT_007eafd0= (undefined4&) GH_MEM(0x007eafd0);
undefined4& DAT_007eafd4= (undefined4&) GH_MEM(0x007eafd4);
undefined4& DAT_007eafd8= (undefined4&) GH_MEM(0x007eafd8);
undefined4& DAT_007eafdc= (undefined4&) GH_MEM(0x007eafdc);
undefined4& DAT_007eaff0= (undefined4&) GH_MEM(0x007eaff0);
undefined4& DAT_007eaff4= (undefined4&) GH_MEM(0x007eaff4);
undefined4& DAT_007eaff8= (undefined4&) GH_MEM(0x007eaff8);
undefined4& DAT_007eaffc= (undefined4&) GH_MEM(0x007eaffc);
undefined4& DAT_007eb000= (undefined4&) GH_MEM(0x007eb000);
undefined4& g_gfx_lastColorOp= (undefined4&) GH_MEM(0x007eb020);
undefined4& DAT_007eb044= (undefined4&) GH_MEM(0x007eb044);
IDirect3DDevice8*& gfx_device = (IDirect3DDevice8*&)GH_MEM(0x007edb18); // 007edb18
undefined4& g_GLI_width0= (undefined4&) GH_MEM(0x007edd44);
undefined4& g_GLI_height0= (undefined4&) GH_MEM(0x007edd48);
undefined4& g_GLI_bitdepth0= (undefined4&) GH_MEM(0x007edd4c);
undefined4& g_GLI_adapter= (undefined4&) GH_MEM(0x007edd60); undefined4& g_GLI_adapter= (undefined4&) GH_MEM(0x007edd60);
undefined1& g_GLI_tnl= (undefined1&) GH_MEM(0x007edd64); undefined1& g_GLI_tnl= (undefined1&) GH_MEM(0x007edd64);
undefined1& g_config_tex_compressed= (undefined1&) GH_MEM(0x007edd65); undefined1& g_config_tex_compressed= (undefined1&) GH_MEM(0x007edd65);

View File

@ -107,6 +107,7 @@ extern const char* s_Veuillez_ins_rer_le_DVD_dans_vot_005be500; // 005be500
extern const char* s_fmt_c_colon_s; // 005be540 extern const char* s_fmt_c_colon_s; // 005be540
extern const char* s_r3_program_files; // 005be548 extern const char* s_r3_program_files; // 005be548
extern const char* s_driveLetterTemplate; // 005be568 extern const char* s_driveLetterTemplate; // 005be568
extern undefined4& DAT_005bf684; // 005bf684
extern undefined4& g_config_camera_hor_axis; // 005c67c8 extern undefined4& g_config_camera_hor_axis; // 005c67c8
extern undefined4& g_config_camera_ver_axis; // 005c67cc extern undefined4& g_config_camera_ver_axis; // 005c67cc
extern undefined1& g_initVar0; // 005cf960 extern undefined1& g_initVar0; // 005cf960
@ -124,7 +125,13 @@ extern dword& g_soundOnHD; // 005d29bc
extern dword& g_complete; // 005d29c0 extern dword& g_complete; // 005d29c0
extern undefined1& DAT_005d2b18; // 005d2b18 extern undefined1& DAT_005d2b18; // 005d2b18
extern undefined4& DAT_005e693c; // 005e693c extern undefined4& DAT_005e693c; // 005e693c
extern undefined4& DAT_005e6c20; // 005e6c20
extern undefined4& DAT_005e6c24; // 005e6c24
extern undefined4& DAT_005e6c28; // 005e6c28
extern IDirect3D8*& gfx_d3d; // 005e6c30
extern r3_astruct_2& g_startOfGfxStruct; // 005f5e24
extern undefined4& DAT_0063be24; // 0063be24 extern undefined4& DAT_0063be24; // 0063be24
extern undefined1& DAT_0063be50; // 0063be50
extern int& g_windowInitialized; // 0077d0a4 extern int& g_windowInitialized; // 0077d0a4
extern int& g_runMaximized; // 0077d0a8 extern int& g_runMaximized; // 0077d0a8
extern undefined4& g_engineShouldRun; // 0077d0b0 extern undefined4& g_engineShouldRun; // 0077d0b0
@ -148,6 +155,30 @@ extern undefined1& DAT_007d98fc; // 007d98fc
extern undefined4& DAT_007d9cc4; // 007d9cc4 extern undefined4& DAT_007d9cc4; // 007d9cc4
extern byte& g_config_unused0; // 007d9df0 extern byte& g_config_unused0; // 007d9df0
extern char(&g_driveLetter)[4]; // 007d9e70 extern char(&g_driveLetter)[4]; // 007d9e70
extern undefined4& g_perfCounterRate; // 007e5ad8
extern undefined4& DAT_007eaf60; // 007eaf60
extern undefined4& DAT_007eaf7c; // 007eaf7c
extern undefined4& DAT_007eafa0; // 007eafa0
extern undefined4& DAT_007eafa4; // 007eafa4
extern undefined4& DAT_007eafc0; // 007eafc0
extern undefined4& DAT_007eafc4; // 007eafc4
extern undefined4& DAT_007eafc8; // 007eafc8
extern undefined4& DAT_007eafcc; // 007eafcc
extern undefined4& DAT_007eafd0; // 007eafd0
extern undefined4& DAT_007eafd4; // 007eafd4
extern undefined4& DAT_007eafd8; // 007eafd8
extern undefined4& DAT_007eafdc; // 007eafdc
extern undefined4& DAT_007eaff0; // 007eaff0
extern undefined4& DAT_007eaff4; // 007eaff4
extern undefined4& DAT_007eaff8; // 007eaff8
extern undefined4& DAT_007eaffc; // 007eaffc
extern undefined4& DAT_007eb000; // 007eb000
extern undefined4& g_gfx_lastColorOp; // 007eb020
extern undefined4& DAT_007eb044; // 007eb044
extern IDirect3DDevice8*& gfx_device; // 007edb18
extern undefined4& g_GLI_width0; // 007edd44
extern undefined4& g_GLI_height0; // 007edd48
extern undefined4& g_GLI_bitdepth0; // 007edd4c
extern undefined4& g_GLI_adapter; // 007edd60 extern undefined4& g_GLI_adapter; // 007edd60
extern undefined1& g_GLI_tnl; // 007edd64 extern undefined1& g_GLI_tnl; // 007edd64
extern undefined1& g_config_tex_compressed; // 007edd65 extern undefined1& g_config_tex_compressed; // 007edd65

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 0051e0a8
// Direct3DCreate8
extern "C" IDirect3D8 * Direct3DCreate8(UINT SDKVersion) {
return gh_stub_impl_stdcall<(stub_t)0x0051e0a8, IDirect3D8 *>(SDKVersion);
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 00470b00
// FUN_00470b00
extern "C" undefined FUN_00470b00(void) {
return gh_stub_impl_cdecl<(stub_t)0x00470b00, undefined>();
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 00484ea0
// FUN_00484ea0
extern "C" undefined FUN_00484ea0(undefined4 param_1) {
return gh_stub_impl_cdecl<(stub_t)0x00484ea0, undefined>(param_1);
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 00496ac0
// FUN_00496ac0
extern "C" undefined FUN_00496ac0(void) {
return gh_stub_impl_cdecl<(stub_t)0x00496ac0, undefined>();
}

View File

@ -101,7 +101,8 @@ struct R3Bin {
HINSTANCE hImportDLL = LoadLibraryA(pszModName); HINSTANCE hImportDLL = LoadLibraryA(pszModName);
if (!hImportDLL) { if (!hImportDLL) {
// ... (error) throw std::runtime_error(
fmt::format("Failed to load import {}", pszModName));
} }
// Get caller's import address table (IAT) for the callee's functions // Get caller's import address table (IAT) for the callee's functions
@ -127,7 +128,8 @@ struct R3Bin {
PROC *ppfn = (PROC *)&pThunk->u1.Function; PROC *ppfn = (PROC *)&pThunk->u1.Function;
if (!ppfn) { if (!ppfn) {
// ... (error) throw std::runtime_error(
fmt::format("Failed to get ordinal for {}", pszModName));
} }
rva = (size_t)pThunk; rva = (size_t)pThunk;
@ -135,13 +137,15 @@ struct R3Bin {
sprintf_s(fe, 100, "#%u", ord); sprintf_s(fe, 100, "#%u", ord);
pfnNew = GetProcAddress(hImportDLL, (LPCSTR)ord); pfnNew = GetProcAddress(hImportDLL, (LPCSTR)ord);
if (!pfnNew) { if (!pfnNew) {
// ... (error) throw std::runtime_error(fmt::format(
"Failed to get function address for {}", pszModName));
} }
} else { } else {
// Get the address of the function address // Get the address of the function address
PROC *ppfn = (PROC *)&pThunk->u1.Function; PROC *ppfn = (PROC *)&pThunk->u1.Function;
if (!ppfn) { if (!ppfn) {
// ... (error) throw std::runtime_error(fmt::format(
"Failed to get function address for {}", pszModName));
} }
rva = (size_t)pThunk; rva = (size_t)pThunk;
PSTR fName = (PSTR)h; PSTR fName = (PSTR)h;
@ -151,7 +155,8 @@ struct R3Bin {
break; break;
pfnNew = GetProcAddress(hImportDLL, fName); pfnNew = GetProcAddress(hImportDLL, fName);
if (!pfnNew) { if (!pfnNew) {
// ... (error) throw std::runtime_error(fmt::format(
"Failed to get function address for {}", pszModName));
} }
} }
@ -165,11 +170,13 @@ struct R3Bin {
&dwOldProtect)) { &dwOldProtect)) {
if (!WriteProcessMemory(GetCurrentProcess(), (LPVOID *)rva, &pfnNew, if (!WriteProcessMemory(GetCurrentProcess(), (LPVOID *)rva, &pfnNew,
sizeof(pfnNew), NULL)) { sizeof(pfnNew), NULL)) {
// ... (error) throw std::runtime_error(fmt::format(
"Failed to write process memory for {}", pszModName));
} }
if (!VirtualProtect((LPVOID)rva, sizeof(pfnNew), dwOldProtect, if (!VirtualProtect((LPVOID)rva, sizeof(pfnNew), dwOldProtect,
&dwOldProtect)) { &dwOldProtect)) {
// ... (error) throw std::runtime_error(
fmt::format("Failed to virtual protect for {}", pszModName));
} }
} }
} }
@ -212,7 +219,7 @@ uint8_t *gh_map_dbg_mem(size_t addr) {
} }
void *gh_stub_impl_ptr(void *ptr) { void *gh_stub_impl_ptr(void *ptr) {
R3Bin::get(); R3Bin::get();
void* r = (void *)R3Bin::get().translateAddress((void *)ptr); void *r = (void *)R3Bin::get().translateAddress((void *)ptr);
SPDLOG_DEBUG("Forwarding implementation at {} => {}", ptr, r); SPDLOG_DEBUG("Forwarding implementation at {} => {}", ptr, r);
return r; return r;
} }

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,13 @@ if(WIN32)
) )
# Copy to output dir # Copy to output dir
set(BINK_DST ${CMAKE_BINARY_DIR}/bin/binkw32.dll) if(CMAKE_CONFIGURATION_TYPES)
# Multi-config generators (MSVC, Xcode, etc.)
set(BINK_DST ${CMAKE_BINARY_DIR}/bin/$<CONFIG>/binkw32.dll)
else()
# Single-config generators (Make, Ninja, etc.)
set(BINK_DST ${CMAKE_BINARY_DIR}/bin/binkw32.dll)
endif()
add_custom_command( add_custom_command(
OUTPUT ${BINK_DST} OUTPUT ${BINK_DST}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/third_party/bink/binkw32.dll ${BINK_DST} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/third_party/bink/binkw32.dll ${BINK_DST}