Skip to content

Commit 440f1de

Browse files
committed
WCS2004:
- Fixed some issues RoomZoomRaceForImpact: - Unlocked the resolution list - The fix now calculates aspect ratio automatically from the selected resolution in the launcher
1 parent 0f75a96 commit 440f1de

3 files changed

Lines changed: 70 additions & 98 deletions

File tree

project/RoomZoomRaceForImpactWidescreenFix.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<LanguageStandard>stdcpplatest</LanguageStandard>
108108
<LanguageStandard_C>stdclatest</LanguageStandard_C>
109109
<DebugInformationFormat>None</DebugInformationFormat>
110-
<Optimization>Disabled</Optimization>
110+
<Optimization>MaxSpeed</Optimization>
111111
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
112112
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
113113
</ClCompile>

source/fixes/RoomZoomRaceForImpactWidescreenFix/dllmain.cpp

Lines changed: 66 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ HMODULE thisModule;
2626

2727
// Fix details
2828
std::string sFixName = "RoomZoomRaceForImpactWidescreenFix";
29-
std::string sFixVersion = "1.0";
29+
std::string sFixVersion = "1.1";
3030
std::filesystem::path sFixPath;
3131

3232
// Ini
@@ -41,20 +41,30 @@ std::string sExeName;
4141

4242
// Ini variables
4343
bool bFixActive;
44-
int iCurrentResX;
45-
int iCurrentResY;
4644
float fFOVFactor;
4745

4846
// Constants
4947
constexpr float fOldAspectRatio = 4.0f / 3.0f;
50-
constexpr float fCarSelectionMenuFOV = 0.785398185253f;
48+
constexpr float fOriginalGameplayFOV1 = 1.047196507f;
5149

5250
// Variables
5351
float fNewAspectRatio;
5452
float fAspectRatioScale;
55-
float fCurrentCameraFOV;
56-
float fNewCameraFOV;
57-
uint8_t* CameraFOVAddress;
53+
float fNewGameplayFOV1;
54+
float fNewGameplayFOV2;
55+
uintptr_t GameplayFOV2Offset;
56+
57+
enum ResolutionInstructionsIndices
58+
{
59+
ResListUnlock,
60+
ResWidthHeight
61+
};
62+
63+
enum CameraFOVInstructionsIndices
64+
{
65+
Gameplay1,
66+
Gameplay2
67+
};
5868

5969
// Game detection
6070
enum class Game
@@ -150,25 +160,9 @@ void Configuration()
150160
spdlog_confparse(bFixActive);
151161

152162
// Load resolution from ini
153-
inipp::get_value(ini.sections["Settings"], "Width", iCurrentResX);
154-
inipp::get_value(ini.sections["Settings"], "Height", iCurrentResY);
155163
inipp::get_value(ini.sections["Settings"], "FOVFactor", fFOVFactor);
156-
spdlog_confparse(iCurrentResX);
157-
spdlog_confparse(iCurrentResY);
158164
spdlog_confparse(fFOVFactor);
159165

160-
// If resolution not specified, use desktop resolution
161-
if (iCurrentResX <= 0 || iCurrentResY <= 0)
162-
{
163-
spdlog::info("Resolution not specified in ini file. Using desktop resolution.");
164-
// Implement Util::GetPhysicalDesktopDimensions() accordingly
165-
auto desktopDimensions = Util::GetPhysicalDesktopDimensions();
166-
iCurrentResX = desktopDimensions.first;
167-
iCurrentResY = desktopDimensions.second;
168-
spdlog_confparse(iCurrentResX);
169-
spdlog_confparse(iCurrentResY);
170-
}
171-
172166
spdlog::info("----------");
173167
}
174168

@@ -190,102 +184,80 @@ bool DetectGame()
190184
return false;
191185
}
192186

193-
static SafetyHookMid AspectRatioInstructionHook{};
187+
static SafetyHookMid ResolutionInstructionsHook{};
188+
static SafetyHookMid GameplayFOVInstruction2Hook{};
194189

195-
void AspectRatioInstructionMidHook(SafetyHookContext& ctx)
190+
void SetARAndFOV()
196191
{
197-
_asm
192+
std::uint8_t* AspectRatioInstructionScanResult = Memory::PatternScan(exeModule, "D8 89 ?? ?? ?? ?? 8B B1");
193+
if (AspectRatioInstructionScanResult)
198194
{
199-
fmul dword ptr ds:[fNewAspectRatio]
200-
}
201-
}
195+
spdlog::info("Aspect Ratio Instruction: Address is {:s}+{:x}", sExeName.c_str(), AspectRatioInstructionScanResult - (std::uint8_t*)exeModule);
202196

203-
void WidescreenFix()
204-
{
205-
if (eGameType == Game::RZRFI && bFixActive == true)
197+
Memory::PatchBytes(AspectRatioInstructionScanResult + 1, "\x0D");
198+
199+
Memory::Write(AspectRatioInstructionScanResult + 2, &fNewAspectRatio);
200+
}
201+
else
206202
{
207-
fNewAspectRatio = static_cast<float>(iCurrentResX) / static_cast<float>(iCurrentResY);
203+
spdlog::error("Failed to locate aspect ratio instruction memory address.");
204+
return;
205+
}
208206

209-
fAspectRatioScale = fNewAspectRatio / fOldAspectRatio;
207+
std::vector<std::uint8_t*> CameraFOVInstructionsScansResult = Memory::PatternScan(exeModule, "68 ?? ?? ?? ?? E8 ?? ?? ?? ?? A1 ?? ?? ?? ?? C1 E0 ?? 8D 88",
208+
"8B 0C 85 ?? ?? ?? ?? 51 E8 ?? ?? ?? ?? 83 3D");
209+
if (Memory::AreAllSignaturesValid(CameraFOVInstructionsScansResult) == true)
210+
{
211+
spdlog::info("Gameplay FOV Instruction 1: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[Gameplay1] - (std::uint8_t*)exeModule);
210212

211-
Sleep(1000);
213+
spdlog::info("Gameplay FOV Instruction 2: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[Gameplay2] - (std::uint8_t*)exeModule);
212214

213-
std::uint8_t* ResolutionInstructionsScanResult = Memory::PatternScan(exeModule, "89 0A 8B 88 ?? ?? ?? ?? 8B 54 24 08 89 0A");
214-
if (ResolutionInstructionsScanResult)
215-
{
216-
spdlog::info("Resolution Instructions Scan: Address is {:s}+{:x}", sExeName.c_str(), ResolutionInstructionsScanResult - (std::uint8_t*)exeModule);
215+
fNewGameplayFOV1 = Maths::CalculateNewFOV_RadBased(fOriginalGameplayFOV1, fAspectRatioScale) * fFOVFactor;
217216

218-
Memory::PatchBytes(ResolutionInstructionsScanResult, "\x90\x90", 2);
217+
Memory::Write(CameraFOVInstructionsScansResult[Gameplay1] + 1, fNewGameplayFOV1);
219218

220-
static SafetyHookMid ResolutionWidthInstructionMidHook{};
219+
GameplayFOV2Offset = Memory::GetPointerFromAddress(CameraFOVInstructionsScansResult[Gameplay2] + 3, Memory::PointerMode::Absolute);
221220

222-
ResolutionWidthInstructionMidHook = safetyhook::create_mid(ResolutionInstructionsScanResult, [](SafetyHookContext& ctx)
223-
{
224-
Memory::ReadMem(ctx.edx) = iCurrentResX;
225-
});
221+
Memory::WriteNOPs(CameraFOVInstructionsScansResult[Gameplay2], 7);
226222

227-
Memory::PatchBytes(ResolutionInstructionsScanResult + 12, "\x90\x90", 2);
223+
GameplayFOVInstruction2Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[Gameplay2], [](SafetyHookContext& ctx)
224+
{
225+
float& fCurrentGameplayFOV2 = Memory::ReadMem(ctx.eax * 0x4 + GameplayFOV2Offset);
228226

229-
static SafetyHookMid ResolutionHeightInstruction1MidHook{};
227+
fNewGameplayFOV2 = fCurrentGameplayFOV2 * fFOVFactor;
230228

231-
ResolutionHeightInstruction1MidHook = safetyhook::create_mid(ResolutionInstructionsScanResult + 12, [](SafetyHookContext& ctx)
232-
{
233-
Memory::ReadMem(ctx.edx) = iCurrentResY;
234-
});
235-
}
236-
else
237-
{
238-
spdlog::error("Failed to locate resolution instructions scan memory address.");
239-
return;
240-
}
229+
ctx.ecx = std::bit_cast<uintptr_t>(fNewGameplayFOV2);
230+
});
231+
}
232+
}
241233

242-
std::uint8_t* AspectRatioInstructionScanResult = Memory::PatternScan(exeModule, "C1 E1 05 D8 89 ?? ?? ?? ??");
243-
if (AspectRatioInstructionScanResult)
234+
void WidescreenFix()
235+
{
236+
if (eGameType == Game::RZRFI && bFixActive == true)
237+
{
238+
std::vector<std::uint8_t*> ResolutionInstructionsScansResult = Memory::PatternScan(exeModule, "3B CA 0F 85 ?? ?? ?? ?? 3D",
239+
"8B 44 24 ?? 8B 4C 24 ?? 8B 7C 24 ?? 8B 54 24");
240+
if (Memory::AreAllSignaturesValid(ResolutionInstructionsScansResult) == true)
244241
{
245-
spdlog::info("Aspect Ratio Instruction: Address is {:s}+{:x}", sExeName.c_str(), AspectRatioInstructionScanResult + 3 - (std::uint8_t*)exeModule);
242+
spdlog::info("Resolution List Unlock Scan: Address is {:s}+{:x}", sExeName.c_str(), ResolutionInstructionsScansResult[ResListUnlock] - (std::uint8_t*)exeModule);
246243

247-
Memory::PatchBytes(AspectRatioInstructionScanResult + 3, "\x90\x90\x90\x90\x90\x90", 6);
244+
spdlog::info("Resolution Instructions Scan: Address is {:s}+{:x}", sExeName.c_str(), ResolutionInstructionsScansResult[ResWidthHeight] - (std::uint8_t*)exeModule);
248245

249-
AspectRatioInstructionHook = safetyhook::create_mid(AspectRatioInstructionScanResult + 3, AspectRatioInstructionMidHook);
250-
}
251-
else
252-
{
253-
spdlog::error("Failed to locate aspect ratio instruction memory address.");
254-
return;
255-
}
246+
Memory::WriteNOPs(ResolutionInstructionsScansResult[ResListUnlock], 30);
256247

257-
std::uint8_t* CameraFOVInstructionScanResult = Memory::PatternScan(exeModule, "8B 44 24 04 A3 ?? ?? ?? ?? B8 01 00 00 00 C2 04 00 CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC 8B 44 24 04");
258-
if (CameraFOVInstructionScanResult)
259-
{
260-
spdlog::info("Camera FOV Instruction: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionScanResult + 4 - (std::uint8_t*)exeModule);
248+
ResolutionInstructionsHook = safetyhook::create_mid(ResolutionInstructionsScansResult[ResWidthHeight], [](SafetyHookContext& ctx)
249+
{
250+
int& fCurrentWidth = Memory::ReadMem(ctx.esp + 0x14);
261251

262-
CameraFOVAddress = Memory::GetPointerFromAddress(CameraFOVInstructionScanResult + 5, Memory::PointerMode::Absolute);
252+
int& fCurrentHeight = Memory::ReadMem(ctx.esp + 0x18);
263253

264-
Memory::PatchBytes(CameraFOVInstructionScanResult + 4, "\x90\x90\x90\x90\x90", 5);
254+
fNewAspectRatio = static_cast<float>(fCurrentWidth) / static_cast<float>(fCurrentHeight);
265255

266-
static SafetyHookMid CameraFOVInstructionMidHook{};
256+
SetARAndFOV();
267257

268-
CameraFOVInstructionMidHook = safetyhook::create_mid(CameraFOVInstructionScanResult + 4, [](SafetyHookContext& ctx)
269-
{
270-
fCurrentCameraFOV = std::bit_cast<float>(ctx.eax);
271-
272-
if (fCurrentCameraFOV != fCarSelectionMenuFOV)
273-
{
274-
fNewCameraFOV = fCurrentCameraFOV * fFOVFactor;
275-
}
276-
else
277-
{
278-
fNewCameraFOV = fCurrentCameraFOV;
279-
}
280-
281-
Memory::ReadMem(CameraFOVAddress) = fNewCameraFOV;
258+
ResolutionInstructionsHook.disable();
282259
});
283260
}
284-
else
285-
{
286-
spdlog::error("Failed to locate camera FOV instruction memory address.");
287-
return;
288-
}
289261
}
290262
}
291263

source/fixes/WorldChampionshipSnooker2004WidescreenFix/dllmain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ void WidescreenFix()
233233

234234
ResolutionInstructionsHook = safetyhook::create_mid(ResolutionInstructionsScansResult[ResWidthHeight], [](SafetyHookContext& ctx)
235235
{
236-
float& fCurrentWidth = Memory::ReadMem(ctx.esp + 0x8);
236+
int& iCurrentWidth = Memory::ReadMem(ctx.esp + 0x8);
237237

238-
float& fCurrentHeight = Memory::ReadMem(ctx.esp + 0xC);
238+
int& iCurrentHeight = Memory::ReadMem(ctx.esp + 0xC);
239239

240-
fNewAspectRatio = fCurrentWidth / fCurrentHeight;
240+
fNewAspectRatio = static_cast<float>(iCurrentWidth) / static_cast<float>(iCurrentHeight);
241241

242242
SetARAndFOV();
243243

0 commit comments

Comments
 (0)