Skip to content

Commit 6d406c3

Browse files
Disable certain effects when snowing (#1168)
* Disable certain effects when snowing * use mid hook * slight refactor --------- Co-authored-by: ThirteenAG <[email protected]>
1 parent c3ce288 commit 6d406c3

File tree

1 file changed

+91
-35
lines changed

1 file changed

+91
-35
lines changed

source/seasonal/snow.ixx

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,68 @@ public:
2323
{
2424
CRenderPhaseDeferredLighting_LightsToScreen::OnBuildRenderList() += OnBuildRenderList;
2525

26+
// Disables rain-related audio (e.g. Surface impacts)
27+
auto pattern = hook::pattern("F3 0F 10 05 ? ? ? ? F3 0F 11 04 24 E8 ? ? ? ? 51");
28+
if (!pattern.empty())
29+
{
30+
static auto SetRainAudioHook = safetyhook::create_mid(pattern.get_first(8), [](SafetyHookContext& regs)
31+
{
32+
if (snowEnabled)
33+
{
34+
regs.xmm0.f32[0] = 0.0f;
35+
}
36+
});
37+
}
38+
else
39+
{
40+
pattern = hook::pattern("D9 1C 24 E8 ? ? ? ? 51 D9 1C 24 E8 ? ? ? ? D8 44 24 08 83 C4 04 5E 59 C3 CC");
41+
static auto SetRainAudioHook = safetyhook::create_mid(pattern.get_first(3), [](SafetyHookContext& regs)
42+
{
43+
if (snowEnabled)
44+
{
45+
*(float*)regs.esp = 0.0f;
46+
}
47+
});
48+
}
49+
50+
// Disables wetness-related effects (e.g. Reflections, footstep/vehicle interaction sounds, particles)
51+
pattern = hook::pattern("C7 05 ? ? ? ? 00 00 80 3F F3 0F 10 25 ? ? ? ? F3 0F 10 04");
52+
if (!pattern.empty())
53+
{
54+
pWetness = *pattern.get_first<float*>(2);
55+
static auto SetRainWetnessHook = safetyhook::create_mid(pattern.get_first(10), [](SafetyHookContext& regs)
56+
{
57+
if (snowEnabled)
58+
{
59+
*pWetness = 0.0f;
60+
}
61+
});
62+
}
63+
else
64+
{
65+
pattern = hook::pattern("F3 0F 11 05 ? ? ? ? EB 67");
66+
pWetness = *pattern.get_first<float*>(4);
67+
injector::MakeNOP(pattern.get_first(0), 8, true);
68+
static auto SetRainWetnessHook = safetyhook::create_mid(pattern.get_first(0), [](SafetyHookContext& regs)
69+
{
70+
*pWetness = 1.0f;
71+
72+
if (snowEnabled)
73+
{
74+
*pWetness = 0.0f;
75+
}
76+
});
77+
}
78+
2679
// Snow on vehicles: load textures
27-
auto pattern = find_pattern("E8 ? ? ? ? 8B 0D ? ? ? ? 83 C4 18 8B 01 6A 00", "E8 ? ? ? ? 83 C4 18 8B 0D");
28-
static auto FXRain__CTxdStore__setCurrent = safetyhook::create_mid(pattern.get_first(), [](SafetyHookContext& ctx)
80+
pattern = find_pattern("E8 ? ? ? ? 8B 0D ? ? ? ? 83 C4 18 8B 01 6A 00", "E8 ? ? ? ? 83 C4 18 8B 0D");
81+
static auto FXRain__CTxdStore__setCurrent = safetyhook::create_mid(pattern.get_first(), [](SafetyHookContext& regs)
2982
{
30-
vehicle_generic_glasswindows2_snow = CTxdStore::getEntryByKey(CTxdStore::at(ctx.esi), 0, hashStringLowercaseFromSeed("vehicle_generic_glasswindows2_snow", 0));
31-
vehicle_generic_tyrewallblack_snow = CTxdStore::getEntryByKey(CTxdStore::at(ctx.esi), 0, hashStringLowercaseFromSeed("vehicle_generic_tyrewallblack_snow", 0));
32-
vehicle_generic_glassdirt_snow = CTxdStore::getEntryByKey(CTxdStore::at(ctx.esi), 0, hashStringLowercaseFromSeed("vehicle_generic_glassdirt_snow", 0));
33-
vehicle_genericmud_car_snow = CTxdStore::getEntryByKey(CTxdStore::at(ctx.esi), 0, hashStringLowercaseFromSeed("vehicle_genericmud_car_snow", 0));
34-
vehicle_genericmud_truck_snow = CTxdStore::getEntryByKey(CTxdStore::at(ctx.esi), 0, hashStringLowercaseFromSeed("vehicle_genericmud_truck_snow", 0));
83+
vehicle_generic_glasswindows2_snow = CTxdStore::getEntryByKey(CTxdStore::at(regs.esi), 0, hashStringLowercaseFromSeed("vehicle_generic_glasswindows2_snow", 0));
84+
vehicle_generic_tyrewallblack_snow = CTxdStore::getEntryByKey(CTxdStore::at(regs.esi), 0, hashStringLowercaseFromSeed("vehicle_generic_tyrewallblack_snow", 0));
85+
vehicle_generic_glassdirt_snow = CTxdStore::getEntryByKey(CTxdStore::at(regs.esi), 0, hashStringLowercaseFromSeed("vehicle_generic_glassdirt_snow", 0));
86+
vehicle_genericmud_car_snow = CTxdStore::getEntryByKey(CTxdStore::at(regs.esi), 0, hashStringLowercaseFromSeed("vehicle_genericmud_car_snow", 0));
87+
vehicle_genericmud_truck_snow = CTxdStore::getEntryByKey(CTxdStore::at(regs.esi), 0, hashStringLowercaseFromSeed("vehicle_genericmud_truck_snow", 0));
3588
});
3689

3790
// Snow on vehicles: replace textures
@@ -66,7 +119,7 @@ public:
66119

67120
auto Enable() -> void override
68121
{
69-
enabled = true;
122+
snowEnabled = true;
70123

71124
unsub_OnAfterCopyLight = CRenderPhaseDeferredLighting_LightsToScreen::OnAfterCopyLight() += OnAfterCopyLight;
72125
unsub_onCTimeCycleExtInit = CTimeCycleExt::onCTimeCycleExtInit() += onCTimeCycleExtInit;
@@ -79,7 +132,7 @@ public:
79132

80133
auto Disable() -> void override
81134
{
82-
enabled = false;
135+
snowEnabled = false;
83136

84137
unsub_OnAfterCopyLight();
85138
unsub_onCTimeCycleExtInit();
@@ -91,7 +144,7 @@ public:
91144
}
92145

93146
private:
94-
static inline auto enabled = false;
147+
static inline auto snowEnabled = false;
95148

96149
static inline std::function<void()> unsub_OnAfterCopyLight;
97150
static inline std::function<void()> unsub_onCTimeCycleExtInit;
@@ -120,6 +173,8 @@ private:
120173

121174
static inline rage::grcRenderTargetPC* mNormalRtCopy;
122175

176+
static inline float* pWetness = nullptr;
177+
123178
static auto __fastcall OnDeviceLost() -> void
124179
{
125180
mDiffuseRT = nullptr;
@@ -285,7 +340,7 @@ private:
285340
OnBuildRenderListInit();
286341
}
287342

288-
if (!enabled)
343+
if (!snowEnabled)
289344
return;
290345

291346
// Skip if any required GPU resource is unavailable (e.g., during/after a device reset)
@@ -302,7 +357,8 @@ private:
302357

303358
static auto OnBeforeLighting() -> void
304359
{
305-
auto HasSnow = [](CWeather::eWeatherType /*type*/) -> bool {
360+
auto HasSnow = [](CWeather::eWeatherType /*type*/) -> bool
361+
{
306362
return true;
307363
};
308364

@@ -462,41 +518,41 @@ private:
462518
{
463519
switch (type)
464520
{
465-
case CWeather::SUNNY_WINDY: return true;
466-
case CWeather::CLOUDY: return true;
467-
case CWeather::RAIN: return true;
468-
case CWeather::DRIZZLE: return true;
469-
case CWeather::FOGGY: return true;
470-
case CWeather::LIGHTNING: return true;
471-
default: return false;
521+
case CWeather::SUNNY_WINDY: return true;
522+
case CWeather::CLOUDY: return true;
523+
case CWeather::RAIN: return true;
524+
case CWeather::DRIZZLE: return true;
525+
case CWeather::FOGGY: return true;
526+
case CWeather::LIGHTNING: return true;
527+
default: return false;
472528
}
473529
}
474530

475531
static auto LightVolumeIntensities(CWeather::eWeatherType type) -> float
476532
{
477533
switch (type)
478534
{
479-
case CWeather::SUNNY_WINDY: return 1.1f;
480-
case CWeather::CLOUDY: return 1.15f;
481-
case CWeather::RAIN: return 1.25f;
482-
case CWeather::DRIZZLE: return 1.2f;
483-
case CWeather::FOGGY: return 1.4f;
484-
case CWeather::LIGHTNING: return 1.3f;
485-
default: return 0.0f;
535+
case CWeather::SUNNY_WINDY: return 1.1f;
536+
case CWeather::CLOUDY: return 1.15f;
537+
case CWeather::RAIN: return 1.25f;
538+
case CWeather::DRIZZLE: return 1.2f;
539+
case CWeather::FOGGY: return 1.4f;
540+
case CWeather::LIGHTNING: return 1.3f;
541+
default: return 0.0f;
486542
}
487543
}
488544

489545
static auto LightVolumeScales(CWeather::eWeatherType type) -> float
490546
{
491547
switch (type)
492548
{
493-
case CWeather::SUNNY_WINDY: return 0.1f;
494-
case CWeather::CLOUDY: return 0.15f;
495-
case CWeather::RAIN: return 0.25f;
496-
case CWeather::DRIZZLE: return 0.2f;
497-
case CWeather::FOGGY: return 0.4f;
498-
case CWeather::LIGHTNING: return 0.3f;
499-
default: return 0.0f;
549+
case CWeather::SUNNY_WINDY: return 0.1f;
550+
case CWeather::CLOUDY: return 0.15f;
551+
case CWeather::RAIN: return 0.25f;
552+
case CWeather::DRIZZLE: return 0.2f;
553+
case CWeather::FOGGY: return 0.4f;
554+
case CWeather::LIGHTNING: return 0.3f;
555+
default: return 0.0f;
500556
}
501557
}
502558

@@ -515,7 +571,7 @@ private:
515571
static inline SafetyHookInline shsub_41B920{};
516572
static auto __fastcall sub_41B920(rage::grcTextureReference* tex, void* edx) -> rage::grcTexturePC*
517573
{
518-
if (enabled)
574+
if (snowEnabled)
519575
{
520576
if (!vehicle_generic_glasswindows2)
521577
{
@@ -564,7 +620,7 @@ private:
564620
static inline SafetyHookInline shsub_A9F2D0{};
565621
static auto __stdcall sub_A9F2D0(unsigned int hash, int a2, char a3) -> void*
566622
{
567-
if (enabled)
623+
if (snowEnabled)
568624
{
569625
static std::vector<unsigned int> list = {
570626
0x9EA7160A, // bullet impact smoke

0 commit comments

Comments
 (0)