Compare commits

...

5 Commits

Author SHA1 Message Date
Guus Waals 38b62c4d50 WIP 2025-06-06 02:56:59 +08:00
Guus Waals 919430c923 WIP 2025-06-06 02:50:20 +08:00
Guus Waals 599c2f746b Better relocations 2025-06-06 02:27:28 +08:00
Guus Waals 7d095623ba WIP 2025-06-06 02:06:59 +08:00
Guus Waals 080b9f7b8c WIP 2025-06-06 01:14:59 +08:00
13 changed files with 33886 additions and 24602 deletions

View File

@ -9,6 +9,7 @@ import ghidra.program.model.mem.MemoryBlock;
import ghidra.program.model.address.*;
import ghidra.program.model.scalar.Scalar;
import ghidra.program.model.symbol.Reference;
import ghidra.program.model.pcode.*;
import java.util.*;
import java.io.*;
import re3lib.RemanConfig;
@ -19,6 +20,26 @@ public class FindRelocations extends GhidraScript {
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
public void run() throws Exception {
RemanConfig.INSTANCE = new RemanConfig(this);
@ -86,35 +107,112 @@ public class FindRelocations extends GhidraScript {
}
}
private void analyzeInstruction(Instruction instruction) {
String mnemonic = instruction.getMnemonicString().toLowerCase();
private void analyzePcodeForConstants(Instruction instruction, boolean trace, Set<String> foundAddresses) {
try {
// Get the pcode operations for this instruction
PcodeOp[] pcodeOps = instruction.getPcode();
boolean trace = instruction.getAddress().getOffset() == 0x0049b154;
if (trace) {
println("DEBUG: " + mnemonic + " at " + instruction.getAddress());
}
// Check for instructions that commonly use absolute addresses
if (isRelocatableInstruction(mnemonic)) {
// Check references from this instruction
Reference[] refs = instruction.getReferencesFrom();
for (Reference ref : refs) {
Address toAddr = ref.getToAddress();
boolean isInMainMemorySpace = isInMainMemorySpace(toAddr);
if (trace) {
println(" isInMainMemorySpace: " + toAddr + " " + isInMainMemorySpace);
if (trace) {
println("DEBUG: Analyzing pcode for " + instruction.getAddress());
for (PcodeOp op : pcodeOps) {
println("DEBUG: PcodeOp: " + op.toString());
}
if (isInMainMemorySpace) {
}
for (PcodeOp op : pcodeOps) {
// Look for constants in the pcode that look like addresses
Varnode[] inputs = op.getInputs();
for (Varnode input : inputs) {
if (input.isConstant()) {
long constantValue = input.getOffset();
// Check if this constant looks like an address in our target range
if (looksLikeAddress(constantValue)) {
if (trace) {
println("DEBUG: Found constant: 0x" + Long.toHexString(constantValue) + " that looks like an address");
}
try {
Address targetAddr = currentProgram.getAddressFactory().getDefaultAddressSpace()
.getAddress(constantValue);
if (isInMainMemorySpace(targetAddr)) {
String addrKey = targetAddr.toString();
if (!foundAddresses.contains(addrKey)) {
// Find where this constant appears in the instruction bytes
int operandOffset = findAbsoluteAddressOffset(instruction, targetAddr, trace);
if (operandOffset >= 0) {
recordRelocation(instruction.getAddress(), targetAddr, instruction.getMnemonicString(),
"pcode_constant", operandOffset);
foundAddresses.add(addrKey);
}
}
}
} catch (Exception e) {
if (trace) {
println("DEBUG: Invalid address from constant: " + e.getMessage());
}
}
}
}
// Also check for address space references (like *[ram]0x77d4c8)
else if (input.isAddress() && input.getAddress() != null) {
long addressValue = input.getAddress().getOffset();
if (trace) {
println("DEBUG: Found address varnode: 0x" + Long.toHexString(addressValue));
}
if (looksLikeAddress(addressValue)) {
try {
Address targetAddr = input.getAddress();
if (isInMainMemorySpace(targetAddr)) {
String addrKey = targetAddr.toString();
if (!foundAddresses.contains(addrKey)) {
int operandOffset = findAbsoluteAddressOffset(instruction, targetAddr, trace);
if (operandOffset >= 0) {
recordRelocation(instruction.getAddress(), targetAddr, instruction.getMnemonicString(),
"pcode_address", operandOffset);
foundAddresses.add(addrKey);
}
}
}
} catch (Exception e) {
if (trace) {
println("DEBUG: Invalid address from varnode: " + e.getMessage());
}
}
}
}
}
}
} catch (Exception e) {
if (trace) {
println("DEBUG: Error analyzing pcode: " + e.getMessage());
}
}
}
private void analyzeReferences(Instruction instruction, boolean trace, Set<String> foundAddresses) {
// Check references from this instruction (original approach)
Reference[] refs = instruction.getReferencesFrom();
for (Reference ref : refs) {
Address toAddr = ref.getToAddress();
boolean isInMainMemorySpace = isInMainMemorySpace(toAddr);
if (trace) {
println("DEBUG: Reference to " + toAddr + " isInMainMemorySpace: " + isInMainMemorySpace);
}
if (isInMainMemorySpace) {
String addrKey = toAddr.toString();
if (!foundAddresses.contains(addrKey)) {
// Check if the target address appears in the instruction bytes (absolute
// addressing)
int operandOffset = findAbsoluteAddressOffset(instruction, toAddr, trace);
if (operandOffset >= 0) {
recordRelocation(instruction.getAddress(), toAddr, mnemonic,
"absolute_" + ref.getReferenceType().getName(), operandOffset);
recordRelocation(instruction.getAddress(), toAddr, instruction.getMnemonicString(),
"reference_" + ref.getReferenceType().getName(), operandOffset);
foundAddresses.add(addrKey);
} else {
if (trace) {
println(" operandOffset was not found: " + operandOffset);
println("DEBUG: operandOffset was not found: " + operandOffset);
}
}
}
@ -186,13 +284,14 @@ public class FindRelocations extends GhidraScript {
private boolean isRelocatableInstruction(String mnemonic) {
// Instructions that commonly use absolute addresses
return mnemonic.equals("mov") || mnemonic.equals("lea") ||
mnemonic.equals("call") || mnemonic.equals("jmp") ||
mnemonic.equals("push") || mnemonic.equals("cmp") ||
mnemonic.equals("test") || mnemonic.equals("add") ||
mnemonic.equals("sub") || mnemonic.equals("and") ||
mnemonic.equals("or") || mnemonic.equals("xor") ||
mnemonic.startsWith("j"); // All jumps, we'll filter by byte analysis
return true;
// mnemonic.equals("mov") || mnemonic.equals("lea") ||
// mnemonic.equals("call") || mnemonic.equals("jmp") ||
// mnemonic.equals("push") || mnemonic.equals("cmp") ||
// mnemonic.equals("test") || mnemonic.equals("add") ||
// mnemonic.equals("sub") || mnemonic.equals("and") ||
// mnemonic.equals("or") || mnemonic.equals("xor") ||
// mnemonic.startsWith("j"); // All jumps, we'll filter by byte analysis
}
private void analyzeDataReferences(long instructionsProcessed, long totalWork) {

View File

@ -50,6 +50,11 @@ function(setup_target TARGET DBG_MODE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_definitions(${TARGET} PRIVATE MSVC=1)
# Disable SAFESEH on Windows
if(WIN32)
target_link_options(${TARGET} PRIVATE /SAFESEH:NO)
endif()
else()
target_compile_definitions(${TARGET} PRIVATE MSVC=0)
@ -58,6 +63,11 @@ function(setup_target TARGET DBG_MODE)
# Ignore -Wmicrosoft-cast
target_compile_options(${TARGET} PRIVATE -Wno-microsoft-cast)
# Disable SAFESEH on Windows with Clang
if(WIN32)
target_link_options(${TARGET} PRIVATE -Wl,/SAFESEH:NO)
endif()
endif()
# Automatically re-run CMake if any gh_*.cxx files change

View File

@ -203,3 +203,4 @@
0054c925 // _chdir
0054bce5 // strlwr
00402960 // sprintf
0059736c // Direct3DCreate8

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

@ -0,0 +1,192 @@
// 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
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 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) {
DWORD_005e6c20 = g_GLI_width0;
DWORD_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 {
DWORD_005e6c20 = param_3;
DWORD_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_r3_program_files = "\\program files\\Ubi Soft\\Rayman3"; // 005be548
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_ver_axis= (undefined4&) GH_MEM(0x005c67cc);
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);
undefined1& DAT_005d2b18= (undefined1&) GH_MEM(0x005d2b18);
undefined4& DAT_005e693c= (undefined4&) GH_MEM(0x005e693c);
dword& DWORD_005e6c20= (dword&) GH_MEM(0x005e6c20);
dword& DWORD_005e6c24= (dword&) 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);
undefined1& DAT_0063be50= (undefined1&) GH_MEM(0x0063be50);
int& g_windowInitialized= (int&) GH_MEM(0x0077d0a4);
int& g_runMaximized= (int&) GH_MEM(0x0077d0a8);
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);
byte& g_config_unused0= (byte&) GH_MEM(0x007d9df0);
char(&g_driveLetter)[4] = reinterpret_cast<char(&)[4]>(GH_MEM(0x007d9e70));
float& g_perfCounterRate= (float&) 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);
undefined1& g_GLI_tnl= (undefined1&) GH_MEM(0x007edd64);
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_r3_program_files; // 005be548
extern const char* s_driveLetterTemplate; // 005be568
extern undefined4& DAT_005bf684; // 005bf684
extern undefined4& g_config_camera_hor_axis; // 005c67c8
extern undefined4& g_config_camera_ver_axis; // 005c67cc
extern undefined1& g_initVar0; // 005cf960
@ -124,7 +125,13 @@ extern dword& g_soundOnHD; // 005d29bc
extern dword& g_complete; // 005d29c0
extern undefined1& DAT_005d2b18; // 005d2b18
extern undefined4& DAT_005e693c; // 005e693c
extern dword& DWORD_005e6c20; // 005e6c20
extern dword& DWORD_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 undefined1& DAT_0063be50; // 0063be50
extern int& g_windowInitialized; // 0077d0a4
extern int& g_runMaximized; // 0077d0a8
extern undefined4& g_engineShouldRun; // 0077d0b0
@ -148,6 +155,30 @@ extern undefined1& DAT_007d98fc; // 007d98fc
extern undefined4& DAT_007d9cc4; // 007d9cc4
extern byte& g_config_unused0; // 007d9df0
extern char(&g_driveLetter)[4]; // 007d9e70
extern float& 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 undefined1& g_GLI_tnl; // 007edd64
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>
// 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

@ -4,6 +4,8 @@
#define A523F6DB_0645_4DEB_8AEB_3792CB732B49
#if _WIN32
// Use the C interface for COM
#define CINTERFACE
#include <Windows.h>
#include <d3d8.h>
#include <dinput.h>

View File

@ -16,6 +16,7 @@ extern "C" {
#define HOOK_S2(addr, name) void __stdcall name(int, int);
#define HOOK_S3(addr, name) void __stdcall name(int, int, int);
#define HOOK_S4(addr, name) void __stdcall name(int, int, int, int);
#define HOOK_S5(addr, name) void __stdcall name(int, int, int, int, int);
#include "hooks.def"
#undef HOOK
#undef HOOK_S0
@ -23,6 +24,7 @@ extern "C" {
#undef HOOK_S2
#undef HOOK_S3
#undef HOOK_S4
#undef HOOK_S5
}
struct R3Bin {
@ -101,7 +103,8 @@ struct R3Bin {
HINSTANCE hImportDLL = LoadLibraryA(pszModName);
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
@ -127,7 +130,8 @@ struct R3Bin {
PROC *ppfn = (PROC *)&pThunk->u1.Function;
if (!ppfn) {
// ... (error)
throw std::runtime_error(
fmt::format("Failed to get ordinal for {}", pszModName));
}
rva = (size_t)pThunk;
@ -135,13 +139,15 @@ struct R3Bin {
sprintf_s(fe, 100, "#%u", ord);
pfnNew = GetProcAddress(hImportDLL, (LPCSTR)ord);
if (!pfnNew) {
// ... (error)
throw std::runtime_error(fmt::format(
"Failed to get function address for {}", pszModName));
}
} else {
// Get the address of the function address
PROC *ppfn = (PROC *)&pThunk->u1.Function;
if (!ppfn) {
// ... (error)
throw std::runtime_error(fmt::format(
"Failed to get function address for {}", pszModName));
}
rva = (size_t)pThunk;
PSTR fName = (PSTR)h;
@ -151,7 +157,8 @@ struct R3Bin {
break;
pfnNew = GetProcAddress(hImportDLL, fName);
if (!pfnNew) {
// ... (error)
throw std::runtime_error(fmt::format(
"Failed to get function address for {}", pszModName));
}
}
@ -165,11 +172,13 @@ struct R3Bin {
&dwOldProtect)) {
if (!WriteProcessMemory(GetCurrentProcess(), (LPVOID *)rva, &pfnNew,
sizeof(pfnNew), NULL)) {
// ... (error)
throw std::runtime_error(fmt::format(
"Failed to write process memory for {}", pszModName));
}
if (!VirtualProtect((LPVOID)rva, sizeof(pfnNew), dwOldProtect,
&dwOldProtect)) {
// ... (error)
throw std::runtime_error(
fmt::format("Failed to virtual protect for {}", pszModName));
}
}
}
@ -192,6 +201,7 @@ struct R3Bin {
#define HOOK_S2(addr, name) HOOK(addr, name)
#define HOOK_S3(addr, name) HOOK(addr, name)
#define HOOK_S4(addr, name) HOOK(addr, name)
#define HOOK_S5(addr, name) HOOK(addr, name)
#include "hooks.def"
}
@ -212,7 +222,7 @@ uint8_t *gh_map_dbg_mem(size_t addr) {
}
void *gh_stub_impl_ptr(void *ptr) {
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);
return r;
}

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,13 @@ if(WIN32)
)
# 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(
OUTPUT ${BINK_DST}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/third_party/bink/binkw32.dll ${BINK_DST}