Skip to content

Commit

Permalink
bloom toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Oct 29, 2023
1 parent 45b1b60 commit 1d5eec7
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 23 deletions.
3 changes: 2 additions & 1 deletion data/plugins/GTAIV.EFLC.FusionFix.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BorderlessWindowed = 1
RecoilFix = 1
AimingZoomFix = 1
MotionBlur = 0 // used by main menu toggle, do not modify
Bloom = 1 // used by main menu toggle, do not modify
Definition = 6 // used by main menu toggle, do not modify

[SHADOWS]
Expand Down Expand Up @@ -32,7 +33,7 @@ MouseFix = 1
ScreenFilter = 5 // used by main menu toggle, do not modify
DistantBlur = 9 // used by main menu toggle, do not modify
DepthOfField = 1 // used by main menu toggle, do not modify
FixRainDrops = 0
FixRainDrops = 1
RainDropsBlur = 2 // 1, 2 or 4 only
TreeLighting = 6 // used by main menu toggle, do not modify
LightSyncRGB = 0 // used by main menu toggle, do not modify | Only Logitech hardware is supported, requires Logitech G HUB app
Expand Down
1 change: 1 addition & 0 deletions data/update/TBoGT/common/data/frontend_menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@
displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_ADJUST" label="Motion Blur" value="PREF_MOTIONBLUR" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Bloom" value="PREF_BLOOM" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Console Gamma" value="PREF_CONSOLE_GAMMA" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Screen Filter" value="PREF_TIMECYC" scaler="10" displayValue="MENU_DISPLAY_TIMECYC" />
<optionspc action="MENUOPT_ADJUST" label="Distant Blur" value="PREF_TCYC_DOF" scaler="10" displayValue="MENU_DISPLAY_DOF" />
Expand Down
1 change: 1 addition & 0 deletions data/update/TLAD/common/data/frontend_menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@
<optionsps3 action="MENUOPT_ADJUST" label="MO_FLIC" value="PREF_FLICKER_FILTER" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_ADJUST" label="Motion Blur" value="PREF_MOTIONBLUR" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Bloom" value="PREF_BLOOM" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Console Gamma" value="PREF_CONSOLE_GAMMA" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Screen Filter" value="PREF_TIMECYC" scaler="10" displayValue="MENU_DISPLAY_TIMECYC" />
<optionspc action="MENUOPT_ADJUST" label="Distant Blur" value="PREF_TCYC_DOF" scaler="10" displayValue="MENU_DISPLAY_DOF" />
Expand Down
1 change: 1 addition & 0 deletions data/update/common/data/frontend_menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@
<optionsps3 action="MENUOPT_ADJUST" label="MO_FLIC" value="PREF_FLICKER_FILTER" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<options action="MENUOPT_NONE" label="" value="PREF_NULL" scaler="0" displayValue="MENU_DISPLAY_NONE" />
<optionspc action="MENUOPT_ADJUST" label="Motion Blur" value="PREF_MOTIONBLUR" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Bloom" value="PREF_BLOOM" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Console Gamma" value="PREF_CONSOLE_GAMMA" scaler="2" displayValue="MENU_DISPLAY_ON_OFF" />
<optionspc action="MENUOPT_ADJUST" label="Screen Filter" value="PREF_TIMECYC" scaler="10" displayValue="MENU_DISPLAY_TIMECYC" />
<optionspc action="MENUOPT_ADJUST" label="Distant Blur" value="PREF_TCYC_DOF" scaler="10" displayValue="MENU_DISPLAY_DOF" />
Expand Down
62 changes: 50 additions & 12 deletions source/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ void Init()
FusionFix::onInitEvent().executeAll();
}

HRESULT CALLBACK TaskDialogCallbackProc(HWND hwnd, UINT uNotification, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData)
{
switch (uNotification)
{
case TDN_HYPERLINK_CLICKED:
ShellExecuteW(hwnd, L"open", (LPCWSTR)lParam, NULL, NULL, SW_SHOW);
break;
}

return S_OK;
}

void XliveCompat()
{
if (GetProcAddress(GetModuleHandleW(L"xlive"), "IsUltimateASILoader") != NULL)
return;

auto TaskDialogCallbackProc = [](HWND hwnd, UINT uNotification, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData) -> HRESULT
{
switch (uNotification)
{
case TDN_HYPERLINK_CLICKED:
ShellExecuteW(hwnd, L"open", (LPCWSTR)lParam, NULL, NULL, SW_SHOW);
break;
}

return S_OK;
};

TASKDIALOGCONFIG tdc = { sizeof(TASKDIALOGCONFIG) };
int nClickedBtn;
BOOL bCheckboxChecked;
Expand Down Expand Up @@ -95,6 +95,43 @@ void XliveCompat()
TerminateProcess(GetCurrentProcess(), 0);
}

void UALCompat()
{
ModuleList dlls;
dlls.Enumerate(ModuleList::SearchLocation::LocalOnly);
for (auto& e : dlls.m_moduleList)
{
auto m = std::get<HMODULE>(e);
if (GetProcAddress(m, "IsUltimateASILoader") != NULL)
return;
}

TASKDIALOGCONFIG tdc = { sizeof(TASKDIALOGCONFIG) };
int nClickedBtn;
BOOL bCheckboxChecked;
LPCWSTR
szTitle = L"GTAIV.EFLC.FusionFix",
szHeader = L"You are running GTA IV The Complete Edition Fusion Fix with an incompatible version of ASI Loader",
szContent = L"It requires the latest version of " \
L"<a href=\"https://github.com/ThirteenAG/Ultimate-ASI-Loader/releases/latest\">Ultimate ASI Loader</a>\n\n" \
L"<a href=\"https://github.com/ThirteenAG/Ultimate-ASI-Loader/releases/latest\">https://github.com/ThirteenAG/Ultimate-ASI-Loader/releases/latest</a>";
TASKDIALOG_BUTTON aCustomButtons[] = { { 1000, L"Close the program" } };

tdc.hwndParent = gWnd;
tdc.dwFlags = TDF_USE_COMMAND_LINKS | TDF_ENABLE_HYPERLINKS | TDF_SIZE_TO_CONTENT | TDF_CAN_BE_MINIMIZED;
tdc.pButtons = aCustomButtons;
tdc.cButtons = _countof(aCustomButtons);
tdc.pszWindowTitle = szTitle;
tdc.pszMainIcon = TD_INFORMATION_ICON;
tdc.pszMainInstruction = szHeader;
tdc.pszContent = szContent;
tdc.pfCallback = TaskDialogCallbackProc;
tdc.lpCallbackData = 0;

auto hr = TaskDialogIndirect(&tdc, &nClickedBtn, NULL, &bCheckboxChecked);
TerminateProcess(GetCurrentProcess(), 0);
}

extern "C"
{
void __declspec(dllexport) InitializeASI()
Expand All @@ -103,6 +140,7 @@ extern "C"
{
CallbackHandler::RegisterCallback(Init, hook::pattern("F3 0F 10 44 24 ? F3 0F 59 05 ? ? ? ? EB ? E8"));
CallbackHandler::RegisterCallback(L"xlive.dll", XliveCompat);
UALCompat();
});
}
}
Expand Down
1 change: 1 addition & 0 deletions source/settings.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public:
{ 0, "PREF_MOTIONBLUR", "MAIN", "MotionBlur", "" , 0, nullptr, 0, 1 },
{ 0, "PREF_LEDILLUMINATION", "MISC", "LightSyncRGB", "" , 0, nullptr, 0, 1 },
{ 0, "PREF_DEFINITION", "MAIN", "Definition", "MENU_DISPLAY_DEFINITION" , 1, nullptr, DefinitionText.eClassic, std::distance(std::begin(DefinitionText.data), std::end(DefinitionText.data)) - 1 },
{ 0, "PREF_BLOOM", "MAIN", "Bloom", "" , 0, nullptr, 0, 1 },
};

auto i = firstCustomID;
Expand Down
51 changes: 41 additions & 10 deletions source/shaders.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ public:
static auto dw11A2948 = *find_pattern("C7 05 ? ? ? ? ? ? ? ? 0F 85 ? ? ? ? 6A 00", "D8 05 ? ? ? ? D9 1D ? ? ? ? 83 05").get_first<float*>(2);
static auto dw103E49C = *hook::get_pattern<void**>("A3 ? ? ? ? C7 80", 1);

FusionFix::D3D9::onBeforeCreateDevice() += [](LPDIRECT3D9& pDirect3D9, UINT& Adapter, D3DDEVTYPE& DeviceType, HWND& hFocusWindow, DWORD& BehaviorFlags, D3DPRESENT_PARAMETERS*& pPresentationParameters, IDirect3DDevice9**& ppReturnedDeviceInterface)
{
pHDRTexQuarter = nullptr;
};

FusionFix::D3D9::onBeforeReset() += [](LPDIRECT3DDEVICE9& pDevice, D3DPRESENT_PARAMETERS*& pPresentationParameters)
{
pHDRTexQuarter = nullptr;
};

FusionFix::D3D9::onBeginScene() += [](LPDIRECT3DDEVICE9 pDevice)
{
if (*dw103E49C)
Expand Down Expand Up @@ -207,6 +197,47 @@ public:
pTexture = pHDRTexQuarter;
}
};

FusionFix::D3D9::onBeforeCreateDevice() += [](LPDIRECT3D9& pDirect3D9, UINT& Adapter, D3DDEVTYPE& DeviceType, HWND& hFocusWindow, DWORD& BehaviorFlags, D3DPRESENT_PARAMETERS*& pPresentationParameters, IDirect3DDevice9**& ppReturnedDeviceInterface)
{
pHDRTexQuarter = nullptr;
};

FusionFix::D3D9::onBeforeReset() += [](LPDIRECT3DDEVICE9& pDevice, D3DPRESENT_PARAMETERS*& pPresentationParameters)
{
pHDRTexQuarter = nullptr;
};

if (bFixRainDrops)
{
pattern = hook::pattern("A1 ? ? ? ? 50 8B 08 FF 51 40");
if (!pattern.empty())
{
static auto Direct3DDevice = *pattern.get_first<uint32_t*>(1);
struct AuxBeforeResetHook
{
void operator()(injector::reg_pack& regs)
{
regs.eax = *Direct3DDevice;
pHDRTexQuarter = nullptr;
}
}; injector::MakeInline<AuxBeforeResetHook>(pattern.get_first(0));
}
else
{
pattern = hook::pattern("8B 08 8B 51 40 68 ? ? ? ? 50 FF D2 8B");
struct AuxBeforeResetHook
{
void operator()(injector::reg_pack& regs)
{
regs.ecx = *(uint32_t*)regs.eax;
regs.edx = *(uint32_t*)(regs.ecx + 0x40);

pHDRTexQuarter = nullptr;
}
}; injector::MakeInline<AuxBeforeResetHook>(pattern.get_first(0));
}
}
};
};
} Shaders;
13 changes: 13 additions & 0 deletions source/timecyc.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ int timecyc_scanf(const char* i, const char* fmt, int* mAmbient0ColorR, int* mAm
unusedParam10, mSunSize, mUnknown46, mDOFStart, unusedParam11, unusedParam12, mNearDOFBlur, mFarDOFBlur, mWaterReflectionMultiplier, mParticleBrightness,
mCoronaSize, mSkyBrightness, mAOStrength, mRimLightingMultiplier, mDistantCoronaBrightness, mDistantCoronaSize, mPedAOStrength);

if (!FusionFixSettings("PREF_BLOOM"))
*mBloomIntensity = 0.0f;

switch (FusionFixSettings("PREF_TCYC_DOF"))
{
case FusionFixSettings.DofText.eOff:
Expand Down Expand Up @@ -321,6 +324,16 @@ public:
bTimecycUpdated = 200;
});

FusionFixSettings.SetCallback("PREF_BLOOM", [](int32_t value) {
injector::fastcall<void()>::call(CTimeCycleInitialise);
bTimecycUpdated = 200;
});

FusionFixSettings.SetCallback("PREF_SHADOW_QUALITY", [](int32_t value) {
injector::fastcall<void()>::call(CTimeCycleInitialise);
bTimecycUpdated = 200;
});

// z-fighting fix helpers
{
auto pattern = hook::pattern("E8 ? ? ? ? 6A 0C E8 ? ? ? ? 8B 0D");
Expand Down

0 comments on commit 1d5eec7

Please sign in to comment.