MCPcopy Create free account
hub / github.com/Lovrom8/RSMods / GUI

Function GUI

DLL/ModManager.cpp:35–91  ·  view source on GitHub ↗

Hook Game Functions For Our Own Uses (On Alt-Tab, Draw UI, etc).

Source from the content-addressed store, hash-verified

33 /// Hook Game Functions For Our Own Uses (On Alt-Tab, Draw UI, etc).
34 /// </summary>
35 void GUI() {
36 uint32_t d3d9Base;
37 uint32_t adr;
38 uint32_t* vTable = NULL;
39
40 // Find D3D Device
41 while ((d3d9Base = (uint32_t)GetModuleHandleA("d3d9.dll")) == NULL)
42 Sleep(500);
43 adr = MemUtil::FindPattern<uint32_t>(d3d9Base, Offsets::d3dDevice_SearchLen, (byte*)Offsets::d3dDevice_Pattern, Offsets::d3dDevice_Mask) + 2;
44
45 bool runningThroughWine = adr == (uint32_t)2;
46
47 LOG_INFO("Running in Wine: " << std::boolalpha << runningThroughWine << std::endl);
48
49 // Proton / Wine Check.
50 // We do NOT support linux. There is some issues with the D3D pointers.
51 // This check is meant so if someone does load our mods on Linux, we won't just crash. Most mods will just not work.
52 if (runningThroughWine) {
53 LOG_INFO("Performing Wine check" << std::endl);
54 adr = MemUtil::FindPattern<uint32_t>(0x2000000, 0x2B778CC, (byte*)Offsets::d3dDevice_Pattern, Offsets::d3dDevice_Mask) + 2;
55 LOG_INFO(adr << std::endl);
56 }
57
58 if (!adr) {
59 LOG_ERROR("Could not find D3D9 device pointer." << std::endl);
60 return;
61 }
62
63 if (!*(uint32_t*)adr) { // Wing it
64 LOG_ERROR("Could not find DX9 device." << std::endl);
65 MessageBoxA(NULL, "Could not find DX9 device, please restart the game!", "Error", NULL);
66 return;
67 }
68
69 vTable = *(uint32_t**)adr;
70
71 // Third time's the charm?
72 if (!vTable || vTable < (uint32_t*)Offsets::baseHandle) {
73 LOG_ERROR("Could not find D3D device's vTable address." << std::endl);
74 MessageBoxA(NULL, "Could not find D3D device's vTable address \n Restart the game and if you still get this error after a few tries, please report the error!", "Error", NULL);
75 return;
76 }
77
78 // Hook D3D functions to use for our own D3D work. Reference D3DHooks
79 if (!runningThroughWine) {
80 oSetVertexDeclaration = (tSetVertexDeclaration)MemUtil::TrampHook((byte*)vTable[D3DInfo::SetVertexDeclaration_Index], (byte*)D3DHooks::Hook_SetVertexDeclaration, 7); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-setvertexdeclaration
81 oSetVertexShaderConstantF = (tSetVertexShaderConstantF)MemUtil::TrampHook((byte*)vTable[D3DInfo::SetVertexShaderConstantF_Index], (byte*)D3DHooks::Hook_SetVertexShaderConstantF, 7); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-setvertexshaderconstantf
82 oReset = (tReset)DetourFunction((byte*)vTable[D3DInfo::Reset_Index], (byte*)D3DHooks::Hook_Reset); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-reset
83 }
84
85 oSetVertexShader = (tSetVertexShader)MemUtil::TrampHook((byte*)vTable[D3DInfo::SetVertexShader_Index], (byte*)D3DHooks::Hook_SetVertexShader, 7); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-setvertexshader
86 oSetPixelShader = (tSetPixelShader)MemUtil::TrampHook((byte*)vTable[D3DInfo::SetPixelShader_Index], (byte*)D3DHooks::Hook_SetPixelShader, 7); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-setpixelshader
87 oSetStreamSource = (tSetStreamSource)MemUtil::TrampHook((byte*)vTable[D3DInfo::SetStreamSource_Index], (byte*)D3DHooks::Hook_SetStreamSource, 7); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-setstreamsource
88 oEndScene = (tEndScene)MemUtil::TrampHook((byte*)vTable[D3DInfo::EndScene_Index], (byte*)D3DHooks::Hook_EndScene, 7); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-endscene
89 oDrawIndexedPrimitive = (tDrawIndexedPrimitive)MemUtil::TrampHook((byte*)vTable[D3DInfo::DrawIndexedPrimitive_Index], (byte*)D3DHooks::Hook_DIP, 5); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-drawindexedprimitive
90 oDrawPrimitive = (tDrawPrimitive)MemUtil::TrampHook((byte*)vTable[D3DInfo::DrawPrimitive_Index], (byte*)D3DHooks::Hook_DP, 7); // https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-drawprimitive
91 }
92

Callers 1

InitializeModsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected