From 16987945ef30ca74c17103b89a60c8867be46799 Mon Sep 17 00:00:00 2001 From: ThirteenAG Date: Sat, 24 Aug 2024 12:08:58 +0800 Subject: [PATCH] FixCascadedShadowMapResolution test --- data/plugins/GTAIV.EFLC.FusionFix.ini | 1 + source/comvars.ixx | 10 +++--- source/fixes.ixx | 48 ++++++++++++++++----------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/data/plugins/GTAIV.EFLC.FusionFix.ini b/data/plugins/GTAIV.EFLC.FusionFix.ini index 78c9d6fa..b6d06412 100644 --- a/data/plugins/GTAIV.EFLC.FusionFix.ini +++ b/data/plugins/GTAIV.EFLC.FusionFix.ini @@ -8,6 +8,7 @@ DynamicShadowForTrees = 1 // replaces static tree shadows wi OverrideCascadeRanges = 1 // increases shadow view distance and improves quality at lower settings ShadowBlendRange = 0.3 // controls the size of the cascade blending regions | [0.0; 1.0] ForceShadowFilter = 0 // 0 : shadow filter tied to definition | 1 : force 4 sample filter | 2 : force 16 sample filter +FixCascadedShadowMapResolution = 1 [SHADOWFILTERSHARP] // CE-like shadows ShadowSoftness = 1.5 // controls shadow blur diff --git a/source/comvars.ixx b/source/comvars.ixx index c6b1fafd..e83053fa 100644 --- a/source/comvars.ixx +++ b/source/comvars.ixx @@ -610,22 +610,21 @@ export namespace rage static grcRenderTargetPC* __stdcall CreateRT(const char* name, int32_t a2, uint32_t width, uint32_t height, uint32_t bitsPerPixel, grcRenderTargetDesc* desc) { // Scale phone screen/phone camera rendertarget resolution with game resolution. - if(std::string_view(name) == "PHONE_SCREEN" || std::string_view(name) == "PHOTO") + if (std::string_view(name) == "PHONE_SCREEN" || std::string_view(name) == "PHOTO") { auto res = (int32_t)(std::ceil((float)*rage::grcDevice::ms_nActiveHeight / 720.0f) * 256.0f); width = res; height = res; } - - // Force water surface rendertarget resolution to always be 256x256. This matches the water tiling on the console version. - if(std::string_view(name) == "WATER_SURFACE0_COLOUR" || std::string_view(name) == "WATER_SURFACE1_COLOUR") + else if (std::string_view(name) == "WATER_SURFACE0_COLOUR" || std::string_view(name) == "WATER_SURFACE1_COLOUR") { + // Force water surface rendertarget resolution to always be 256x256. This matches the water tiling on the console version. width = 256; height = 256; } auto ret = shCreateRT.stdcall(name, a2, width, height, bitsPerPixel, desc); - + // if(strcmp("WATER_REFLECTION_COLOUR", name) == 0) { ret->mMultisampleCount=1; } //else if(strcmp("WATER_REFLECTION_DEPTH" , name) == 0) { ret->mMultisampleCount=1; } //else if(strcmp("REFLECTION_MAP_COLOUR" , name) == 0) { ret->mMultisampleCount=1; } @@ -1043,6 +1042,7 @@ export int bMenuNeedsUpdate2 = 0; export bool bEnableSnow = false; export bool bEnableHall = false; export bool bFixAutoExposure = true; +export bool bFixCascadedShadowMapResolution = true; export inline LONG getWindowWidth() { diff --git a/source/fixes.ixx b/source/fixes.ixx index 93a15dab..eaa5c0fe 100644 --- a/source/fixes.ixx +++ b/source/fixes.ixx @@ -97,6 +97,7 @@ public: //[SHADOWS] bool bHighResolutionShadows = iniReader.ReadInteger("SHADOWS", "HighResolutionShadows", 0) != 0; + bFixCascadedShadowMapResolution = iniReader.ReadInteger("SHADOWS", "FixCascadedShadowMapResolution", 1) != 0; //fix for zoom flag in tbogt if (nAimingZoomFix) @@ -414,10 +415,6 @@ public: injector::WriteMemory(pattern.count(2).get(0).get(8), 0x200, true); } - // Remove code that doubled shadow cascade resolution. - pattern = find_pattern("03 F6 E8 ? ? ? ? 8B 0D ? ? ? ? 8D 54 24 0C", "03 F6 E8 ? ? ? ? 8B 0D ? ? ? ? 8D 44 24 0C"); - injector::MakeNOP(pattern.get_first(0), 2, true); - // Force water surface rendertarget resolution to always be 256x256. This matches the water tiling on the console version. static uint32_t dwWaterQuality = 1; pattern = find_pattern("8B 0D ? ? ? ? 53 BB ? ? ? ? D3 E3 85 D2 0F 85", "8B 0D ? ? ? ? BF ? ? ? ? D3 E7 85 C0 0F 85"); @@ -438,6 +435,33 @@ public: // _DEFERRED_GBUFFER_0_ / _DEFERRED_GBUFFER_1_ / _DEFERRED_GBUFFER_2_ pattern = find_pattern("BA ? ? ? ? 84 C0 0F 45 CA 8B 15", "40 05 00 00 00 8B 0D ? ? ? ? 8B 11 8B 52 38 8D 74 24 14 56 50 A1"); injector::WriteMemory(pattern.get_first(1), rage::getEngineTextureFormat(D3DFMT_A8R8G8B8), true); + + if (bFixCascadedShadowMapResolution) + { + auto pattern = find_pattern("8D 7D 40 8B 01 57 FF 75 10 FF 75 24 FF 75 0C FF 75 20 FF 75 18"); + if (!pattern.empty()) + { + static auto FixCascadedShadowMapResolution = safetyhook::create_mid(pattern.get_first(0), [](SafetyHookContext& regs) + { + auto Width = *(uint32_t*)(regs.ebp + 0x14); + auto Height = *(uint32_t*)(regs.ebp + 0x18); + auto Levels = *(uint32_t*)(regs.ebp + 0x20); + auto Format = *(uint32_t*)(regs.ebp + 0x24); + + if (Format == D3DFORMAT(D3DFMT_R32F) && Height >= 256 && Width == Height * 4 && Levels == 1) + { + *(uint32_t*)(regs.ebp + 0x14) *= 2; + *(uint32_t*)(regs.ebp + 0x18) *= 2; + } + }); + } + } + else + { + // Remove code that doubled shadow cascade resolution. + pattern = find_pattern("03 F6 E8 ? ? ? ? 8B 0D ? ? ? ? 8D 54 24 0C", "03 F6 E8 ? ? ? ? 8B 0D ? ? ? ? 8D 44 24 0C"); + injector::MakeNOP(pattern.get_first(0), 2, true); + } } // P90 Selector Fix (Prev Weapon key) @@ -532,22 +556,6 @@ public: injector::MakeNOP(pattern.get_first(6), 6, true); } } - - if (true) - { - auto pattern = find_pattern("8B 0D ? ? ? ? 8D 54 24 0C 52 6A 20 FF 35 ? ? ? ? A3"); - if (!pattern.empty()) - { - static auto dword_11A1B84 = *pattern.get_first(15); - static auto dword_11A1B80 = *pattern.get_first(26); - - static auto FixCascadedShadowMapResolution = safetyhook::create_mid(pattern.get_first(0), [](SafetyHookContext& regs) - { - *dword_11A1B84 *= 2; - *dword_11A1B80 *= 2; - }); - } - } }; } } Fixes; \ No newline at end of file