Skip to content

Commit

Permalink
fix patchy fog at uncapped fps
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeulater committed Dec 26, 2023
1 parent d8d42cc commit 1ffc19d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
63 changes: 63 additions & 0 deletions xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "stdafx.h"

#include "rasterizer_dx9_fog.h"

#include "Util/Hooks/Hook.h"

real32 g_rasterizer_fog_dt = 0.0f;

void __declspec(naked) rasterizer_fog_constant_velocity_update()
{
static real32 fog_wind_x_axis_velocity_factor1 = 30.0f;
#define k_delta_time_stack_location (-10h)
__asm
{
pop eax

// esi - atmospheric fog ptr, [esp+1Ch + k_delta_time_stack_location] - dt
// edi - tag definition data
// xmm0 to this point dt as well
movss xmm1, dword ptr[edi+44h]
mulss xmm1, fog_wind_x_axis_velocity_factor1
movss xmm2, dword ptr[esi]
mulss xmm2, dword ptr[esi + 10h]
addss xmm1, xmm2
mulss xmm1, xmm0 // multiply by dt
movss dword ptr[ebp], xmm1

// repeat the code block above 1 more time
movss xmm1, dword ptr[edi + 44h + 4h]
mulss xmm1, fog_wind_x_axis_velocity_factor1
movss xmm2, dword ptr[esi + 4]
mulss xmm2, dword ptr[esi + 10h]
addss xmm1, xmm2
mulss xmm1, xmm0 // multiply by dt
movss dword ptr[ebp + 4], xmm1

// this block without addss
movss xmm1, dword ptr[edi + 44h + 8h]
mulss xmm1, fog_wind_x_axis_velocity_factor1
mulss xmm1, xmm0 // multiply by dt
movss dword ptr[ebp + 8], xmm1

pop edi
pop esi

// push return back
push eax
retn
}
#undef k_delta_time_stack_location
}

void rasterizer_fog_apply_patches()
{
Codecave(Memory::GetAddress(0x2773B5), rasterizer_fog_constant_velocity_update, 42);
// xorps xmm0, xmm0, 2 nops
BYTE xmm0_clear[] = { 0x0F, 0x57, 0xC0, 0x90, 0x90 };
WriteBytes(Memory::GetAddress(0x2776D4), xmm0_clear, sizeof(xmm0_clear));
WriteBytes(Memory::GetAddress(0x2776E8), xmm0_clear, sizeof(xmm0_clear));
WriteBytes(Memory::GetAddress(0x277700), xmm0_clear, sizeof(xmm0_clear));

return;
}
3 changes: 3 additions & 0 deletions xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void rasterizer_fog_apply_patches();
2 changes: 2 additions & 0 deletions xlive/H2MOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "Blam/Engine/units/units.h"
#include "Blam/Engine/widgets/cloth.h"
#include "Blam/Engine/widgets/liquid.h"
#include "Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.h"

#include "H2MOD/EngineHooks/EngineHooks.h"
#include "H2MOD/GUI/ImGui_Integration/ImGui_Handler.h"
Expand Down Expand Up @@ -938,6 +939,7 @@ void H2MOD::ApplyHooks() {
cloth_apply_patches();
camera_apply_patches();
player_control_apply_patches();
rasterizer_fog_apply_patches();
}
else {
LOG_INFO_GAME("{} - applying dedicated server hooks", __FUNCTION__);
Expand Down
2 changes: 2 additions & 0 deletions xlive/Project_Cartographer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@
<ClCompile Include="Blam\Engine\game\players.cpp" />
<ClCompile Include="Blam\Engine\physics\havok_memory.cpp" />
<ClCompile Include="Blam\Engine\rasterizer\dx9\rasterizer_dx9_main.cpp" />
<ClCompile Include="Blam\Engine\rasterizer\dx9\rasterizer_dx9_fog.cpp" />
<ClCompile Include="Blam\Engine\rasterizer\rasterizer_lens_flares.cpp" />
<ClCompile Include="Blam\Engine\rasterizer\rasterizer_settings.cpp" />
<ClCompile Include="Blam\Engine\render\render_cameras.cpp" />
Expand Down Expand Up @@ -830,6 +831,7 @@
<ClInclude Include="Blam\Engine\physics\havok.h" />
<ClInclude Include="Blam\Engine\physics\havok_memory.h" />
<ClInclude Include="Blam\Engine\physics\physics_models.h" />
<ClInclude Include="Blam\Engine\rasterizer\dx9\rasterizer_dx9_fog.h" />
<ClInclude Include="Blam\Engine\rasterizer\dx9\rasterizer_dx9_main.h" />
<ClInclude Include="Blam\Engine\rasterizer\rasterizer_lens_flares.h" />
<ClInclude Include="Blam\Engine\rasterizer\rasterizer_settings.h" />
Expand Down

0 comments on commit 1ffc19d

Please sign in to comment.