Skip to content

Commit

Permalink
FixCascadedShadowMapResolution test
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Aug 24, 2024
1 parent 95a6986 commit 1698794
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions data/plugins/GTAIV.EFLC.FusionFix.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions source/comvars.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -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<grcRenderTargetPC*>(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; }
Expand Down Expand Up @@ -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()
{
Expand Down
48 changes: 28 additions & 20 deletions source/fixes.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -414,10 +415,6 @@ public:
injector::WriteMemory(pattern.count(2).get(0).get<void*>(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");
Expand All @@ -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)
Expand Down Expand Up @@ -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<uint32_t*>(15);
static auto dword_11A1B80 = *pattern.get_first<uint32_t*>(26);

static auto FixCascadedShadowMapResolution = safetyhook::create_mid(pattern.get_first(0), [](SafetyHookContext& regs)
{
*dword_11A1B84 *= 2;
*dword_11A1B80 *= 2;
});
}
}
};
}
} Fixes;

0 comments on commit 1698794

Please sign in to comment.