Skip to content

Commit

Permalink
workaround for shadow mess
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Aug 5, 2024
1 parent 5edc25c commit 517f808
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 42 deletions.
1 change: 0 additions & 1 deletion data/plugins/GTAIV.EFLC.FusionFix.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ShadowBlendRange = 0.3 // controls the size of the cascad
ForceShadowFilter = 0 // 0 : shadow filter tied to definition | 1 : force 4 sample filter | 2 : force 16 sample filter

[NIGHTSHADOWS] // WARNING: enabling any of these options is not recommended
LamppostShadows = 0 // 0: lampposts don't cast shadows, like consoles | 1: forces all lampposts to cast shadows, like PC
HeadlightShadows = 0 // 0: headlights don't cast shadows, like consoles | 1: forces all headlights to cast shadows, like PC
VehicleNightShadows = 0 // 1: enables shadows cast by vehicles from artificial lights, do not use with HeadlightShadows = 1
Expand Down
5 changes: 0 additions & 5 deletions data/update/GTAIV.EFLC.FusionFix/cdimagemake.ims
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,3 @@
-importFromDirectory "FusionLights"
-rebuild
-close

-create "FusionLightsShadowcast.img" "3" "IMG_VERSION_3_ENCRYPTION_TYPE_NONE"
-importFromDirectory "FusionLightsShadowcast"
-rebuild
-close
2 changes: 2 additions & 0 deletions data/update/TBoGT/common/data/frontend_menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@
<optionspc action="MENUOPT_ADJUST" label="Antialiasing" value="PREF_ANTIALIASING" scaler="8" displayValue="MENU_DISPLAY_ANTIALIASING" />
<optionspc action="MENUOPT_ADJUST" label="FPS Limiter" value="PREF_FPS_LIMIT_PRESET" scaler="15" displayValue="MENU_DISPLAY_FRAMELIMIT" />
<optionspc action="MENUOPT_ADJUST" label="MO_FOV" value="PREF_EPISODIC_RACECLASS_RACE_3" scaler="10" displayValue="MENU_DISPLAY_SLIDERBAR" />
<optionspc action="MENUOPT_ADJUST" label="LamppostShadows" value="PREF_LAMPPOSTSHADOWS" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_GRAPHICS_ANALYZER"
label="MO_ANALYZER" value="PREF_NULL" scaler="1"
Expand Down Expand Up @@ -1167,6 +1168,7 @@
<optionspc action="MENUOPT_ADJUST" label="Antialiasing" value="PREF_ANTIALIASING" scaler="8" displayValue="MENU_DISPLAY_ANTIALIASING" />
<optionspc action="MENUOPT_ADJUST" label="FPS Limiter" value="PREF_FPS_LIMIT_PRESET" scaler="15" displayValue="MENU_DISPLAY_FRAMELIMIT" />
<optionspc action="MENUOPT_ADJUST" label="MO_FOV" value="PREF_EPISODIC_RACECLASS_RACE_3" scaler="10" displayValue="MENU_DISPLAY_SLIDERBAR" />
<optionspc action="MENUOPT_ADJUST" label="LamppostShadows" value="PREF_LAMPPOSTSHADOWS" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_GRAPHICS_ANALYZER"
label="MO_ANALYZER" value="PREF_NULL" scaler="1"
Expand Down
2 changes: 2 additions & 0 deletions data/update/TLAD/common/data/frontend_menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@
<optionspc action="MENUOPT_ADJUST" label="Antialiasing" value="PREF_ANTIALIASING" scaler="8" displayValue="MENU_DISPLAY_ANTIALIASING" />
<optionspc action="MENUOPT_ADJUST" label="FPS Limiter" value="PREF_FPS_LIMIT_PRESET" scaler="15" displayValue="MENU_DISPLAY_FRAMELIMIT" />
<optionspc action="MENUOPT_ADJUST" label="MO_FOV" value="PREF_EPISODIC_RACECLASS_RACE_3" scaler="10" displayValue="MENU_DISPLAY_SLIDERBAR" />
<optionspc action="MENUOPT_ADJUST" label="LamppostShadows" value="PREF_LAMPPOSTSHADOWS" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_GRAPHICS_ANALYZER" label="MO_ANALYZER" value="PREF_NULL" scaler="1" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_BENCHMARK" label="MO_BENCHMARK" value="PREF_NULL" scaler="1" displayValue="MENU_DISPLAY_NONE" />
Expand All @@ -1213,6 +1214,7 @@
<optionspc action="MENUOPT_ADJUST" label="Antialiasing" value="PREF_ANTIALIASING" scaler="8" displayValue="MENU_DISPLAY_ANTIALIASING" />
<optionspc action="MENUOPT_ADJUST" label="FPS Limiter" value="PREF_FPS_LIMIT_PRESET" scaler="15" displayValue="MENU_DISPLAY_FRAMELIMIT" />
<optionspc action="MENUOPT_ADJUST" label="MO_FOV" value="PREF_EPISODIC_RACECLASS_RACE_3" scaler="10" displayValue="MENU_DISPLAY_SLIDERBAR" />
<optionspc action="MENUOPT_ADJUST" label="LamppostShadows" value="PREF_LAMPPOSTSHADOWS" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_GRAPHICS_ANALYZER" label="MO_ANALYZER" value="PREF_NULL" scaler="1" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_BENCHMARK" label="MO_BENCHMARK" value="PREF_NULL" scaler="1" displayValue="MENU_DISPLAY_NONE" />
Expand Down
2 changes: 2 additions & 0 deletions data/update/common/data/frontend_menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@
<optionspc action="MENUOPT_ADJUST" label="Antialiasing" value="PREF_ANTIALIASING" scaler="8" displayValue="MENU_DISPLAY_ANTIALIASING" />
<optionspc action="MENUOPT_ADJUST" label="FPS Limiter" value="PREF_FPS_LIMIT_PRESET" scaler="15" displayValue="MENU_DISPLAY_FRAMELIMIT" />
<optionspc action="MENUOPT_ADJUST" label="MO_FOV" value="PREF_EPISODIC_RACECLASS_RACE_3" scaler="10" displayValue="MENU_DISPLAY_SLIDERBAR" />
<optionspc action="MENUOPT_ADJUST" label="LamppostShadows" value="PREF_LAMPPOSTSHADOWS" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_GRAPHICS_ANALYZER" label="MO_ANALYZER" value="PREF_NULL" scaler="1" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_BENCHMARK" label="MO_BENCHMARK" value="PREF_NULL" scaler="1" displayValue="MENU_DISPLAY_NONE" />
Expand All @@ -811,6 +812,7 @@
<optionspc action="MENUOPT_ADJUST" label="Antialiasing" value="PREF_ANTIALIASING" scaler="8" displayValue="MENU_DISPLAY_ANTIALIASING" />
<optionspc action="MENUOPT_ADJUST" label="FPS Limiter" value="PREF_FPS_LIMIT_PRESET" scaler="15" displayValue="MENU_DISPLAY_FRAMELIMIT" />
<optionspc action="MENUOPT_ADJUST" label="MO_FOV" value="PREF_EPISODIC_RACECLASS_RACE_3" scaler="10" displayValue="MENU_DISPLAY_SLIDERBAR" />
<optionspc action="MENUOPT_ADJUST" label="LamppostShadows" value="PREF_LAMPPOSTSHADOWS" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_GRAPHICS_ANALYZER" label="MO_ANALYZER" value="PREF_NULL" scaler="1" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_BENCHMARK" label="MO_BENCHMARK" value="PREF_NULL" scaler="1" displayValue="MENU_DISPLAY_NONE" />
Expand Down
1 change: 0 additions & 1 deletion release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ call buildshaders.bat
-x!update\GTAIV.EFLC.FusionFix\TBOGT.FusionFix ^
-x!update\GTAIV.EFLC.FusionFix\FusionTrees ^
-x!update\GTAIV.EFLC.FusionFix\FusionLights ^
-x!update\GTAIV.EFLC.FusionFix\FusionLightsShadowcast ^
-x!update\GTAIV.EFLC.FusionFix\cdimagemake.ims ^
-xr!*\.gitkeep
61 changes: 40 additions & 21 deletions source/extrainfo.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export module extrainfo;

import common;
import comvars;
import settings;

class ExtraInfo
{
Expand All @@ -20,37 +21,55 @@ public:

if (bExtraInfo)
{
auto pattern = hook::pattern("05 ? ? ? ? E9 ? ? ? ? E8 ? ? ? ? 84 C0");
auto pattern = hook::pattern("F3 0F 10 44 24 ? 6A FF 6A FF 50 83 EC 08 F3 0F 11 44 24 ? F3 0F 10 44 24 ? F3 0F 11 04 24 E8 ? ? ? ? 83 C4 14");
if (!pattern.empty())
{
struct MS_PAUSED_HOOK
static auto PauseHook = safetyhook::create_mid(pattern.get_first(0), [](SafetyHookContext& regs)
{
void operator()(injector::reg_pack& regs)
static std::wstring extra = L"";

if (CGameConfigReader::ms_imgFiles)
{
static std::wstring extra = L"";
regs.eax += 0x78;

if (CGameConfigReader::ms_imgFiles)
auto s = std::wstring_view((wchar_t*)regs.eax);
auto imgNum = 0;
auto imgArrSize = 0;
for (auto& it : *CGameConfigReader::ms_imgFiles)
{
if (it.m_hFile != -1)
imgNum++;
imgArrSize++;
}
extra = s;
extra += L"~n~";
extra += L" ";
extra += L"~p~IMG Files: " + std::to_wstring(imgNum) + L" / " + std::to_wstring(imgArrSize);
if (imgNum >= imgArrSize) extra += L"; ~r~WARNING: 255 IMG limit exceeded, will cause streaming issues.";

static auto LamppostShadows = FusionFixSettings.GetRef("PREF_LAMPPOSTSHADOWS");
if (LamppostShadows->get())
{
auto s = std::wstring_view((wchar_t*)regs.eax);
auto imgNum = 0;
auto imgArrSize = 0;
for (auto& it : *CGameConfigReader::ms_imgFiles)
{
if (it.m_hFile != -1)
imgNum++;
imgArrSize++;
}
extra = s;
extra += L"~n~";
extra += L" ";
extra += L"IMG Files: " + std::to_wstring(imgNum) + L" / " + std::to_wstring(imgArrSize);
if (imgNum >= imgArrSize) extra += L"; WARNING: IMG Files limit reached!";
extra += L"~r~WARNING: Lamppost shadows may cause visual artifacts and performance issues.";
}

regs.eax = (uintptr_t)extra.c_str();
static auto ViewDistance = FusionFixSettings.GetRef("PREF_VIEW_DISTANCE");
static auto DetailQuality = FusionFixSettings.GetRef("PREF_DETAIL_QUALITY");
if (ViewDistance->get() > 24 || DetailQuality->get() > 30)
{
extra += L"~n~";
extra += L" ";
if (ViewDistance->get() > 24 && DetailQuality->get() > 30)
extra += L"~r~WARNING: View Distance slider above 25 and Detail Distance slider above 31 may cause object pop-in.";
else if (ViewDistance->get() > 24)
extra += L"~r~WARNING: View Distance slider above 25 may cause object pop-in.";
else if (DetailQuality->get() > 30)
extra += L"~r~WARNING: Detail Distance slider above 31 may cause object pop-in.";
}

regs.eax = (uintptr_t)extra.c_str();
}
}; injector::MakeInline<MS_PAUSED_HOOK>(pattern.get_first(0));
});
}
}
};
Expand Down
55 changes: 55 additions & 0 deletions source/fixes.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ public:
return r;
}


static inline injector::hook_back<void(__cdecl*)(void*, float)> hbsub_ABD2C0;
static void __cdecl sub_ABD2C0(void* a1, float a2)
{
*(uint32_t*)((uintptr_t)a1 + 0x48) |= 4;
return hbsub_ABD2C0.fun(a1, a2);
}

static inline SafetyHookInline shsub_925DB0{};
static int __cdecl sub_925DB0(int a1, int a2, int flags)
{
static auto LamppostShadows = FusionFixSettings.GetRef("PREF_LAMPPOSTSHADOWS");
if (!LamppostShadows->get())
{
if (!Natives::IsInteriorScene())
return -1;
}

if ((flags & 0x8000000) != 0)
return -1;

return shsub_925DB0.ccall<int>(a1, a2, flags);
}

Fixes()
{
FusionFix::onInitEventAsync() += []()
Expand Down Expand Up @@ -452,6 +476,37 @@ public:
if (!pattern.empty())
injector::MakeNOP(pattern.get_first(0), 8, true);
}

// Lampposts issue workaround
{
auto pattern = find_pattern("89 4C 24 18 74 13");
if (!pattern.empty())
{
static auto ShadowsHook = safetyhook::create_mid(pattern.get_first(0), [](SafetyHookContext& regs)
{
if ((*(uint32_t*)(regs.edi + 0x4C) & 0x8000000) != 0)
{
regs.ecx |= 0x8000000; // new flag to detect affected lampposts
regs.ecx |= 4; // original light flag, currently disabled for these models
}
});
}
else
{
pattern = hook::pattern("BB ? ? ? ? 74 0E F7 46");
static auto ShadowsHook = safetyhook::create_mid(pattern.get_first(0), [](SafetyHookContext& regs)
{
if ((*(uint32_t*)(regs.esi + 0x4C) & 0x8000000) != 0)
{
regs.ebx |= 0x8000000; // new flag to detect affected lampposts
regs.ebx |= 4; // original light flag, currently disabled for these models
}
});
}

pattern = hook::pattern("80 3D ? ? ? ? ? 75 04 83 C8 FF");
shsub_925DB0 = safetyhook::create_inline(pattern.get_first(), sub_925DB0);
}
};
}
} Fixes;
14 changes: 0 additions & 14 deletions source/imgloader.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public:
{
FusionFix::onInitEvent() += []()
{
CIniReader iniReader("");
static auto bLamppostShadows = iniReader.ReadInteger("NIGHTSHADOWS", "LamppostShadows", 0) != 0;

//IMG Loader
auto pattern = find_pattern("E8 ? ? ? ? 6A 00 E8 ? ? ? ? 83 C4 14 6A 00 B9 ? ? ? ? E8 ? ? ? ? 83 3D", "E8 ? ? ? ? 6A 00 E8 ? ? ? ? 83 C4 14 6A 00 B9");
static auto CImgManager__addImgFile = (void(__cdecl*)(const char*, char, int)) injector::GetBranchDestination(pattern.get_first(0)).get();
Expand Down Expand Up @@ -48,17 +45,6 @@ public:

if (!std::filesystem::is_directory(file) && iequals(filePath.extension().native(), L".img"))
{
if (bLamppostShadows)
{
if (iequals(filePath.stem().native(), L"FusionLights"))
continue;
}
else
{
if (iequals(filePath.stem().native(), L"FusionLightsShadowcast"))
continue;
}

static std::vector<std::filesystem::path> episodicPaths = {
std::filesystem::path("IV"),
std::filesystem::path("TLAD"),
Expand Down
1 change: 1 addition & 0 deletions source/settings.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public:
{ 0, "PREF_ANTIALIASING", "MISC", "Antialiasing", "MENU_DISPLAY_ANTIALIASING", 1, nullptr, AntialiasingText.eMO_OFF, std::distance(std::begin(AntialiasingText.data), std::end(AntialiasingText.data)) - 1 },
{ 0, "PREF_UPDATE", "UPDATE", "CheckForUpdates", "", 0, nullptr, 0, 1 },
{ 0, "PREF_BLOCKONLOSTFOCUS", "MAIN", "BlockOnLostFocus", "", 0, nullptr, 0, 1 },
{ 0, "PREF_LAMPPOSTSHADOWS", "SHADOWS", "LamppostShadows", "", 0, nullptr, 0, 1 },
// Enums are at capacity, to use more enums, replace multiplayer ones. On/Off toggles should still be possible to add.
};

Expand Down

0 comments on commit 517f808

Please sign in to comment.