diff --git a/xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.cpp b/xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.cpp new file mode 100644 index 000000000..c9149cf7f --- /dev/null +++ b/xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.cpp @@ -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; +} \ No newline at end of file diff --git a/xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.h b/xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.h new file mode 100644 index 000000000..5632c844b --- /dev/null +++ b/xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.h @@ -0,0 +1,3 @@ +#pragma once + +void rasterizer_fog_apply_patches(); diff --git a/xlive/H2MOD.cpp b/xlive/H2MOD.cpp index 33be0847e..c1b383f9d 100644 --- a/xlive/H2MOD.cpp +++ b/xlive/H2MOD.cpp @@ -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" @@ -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__); diff --git a/xlive/Project_Cartographer.vcxproj b/xlive/Project_Cartographer.vcxproj index 40620db56..156a4249d 100644 --- a/xlive/Project_Cartographer.vcxproj +++ b/xlive/Project_Cartographer.vcxproj @@ -517,6 +517,7 @@ + @@ -830,6 +831,7 @@ +