Skip to content

Commit

Permalink
skipintro, led support
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Dec 21, 2023
1 parent 3aceb76 commit 8795a04
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 59 deletions.
4 changes: 3 additions & 1 deletion data/plugins/MaxPayne3.FusionFix.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[MAIN]
SkipIntro = 1
HideSkipButton = 1
DisableGlobalLeaderboards = 1 // Fixes Hoboken Alleys map crash in coop
DisableGlobalLeaderboards = 1 // Fixes Hoboken Alleys map crash in coop
OutlinesSizeMultiplier = 1.0f
BorderlessWindowed = 1
LightSyncRGB = 1 // Only Logitech hardware is supported, requires Logitech G HUB app
GamepadIcons = 0
; 0 - Xbox 360
; 1 - Xbox One
Expand Down
59 changes: 28 additions & 31 deletions source/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import common;
import comvars;
import settings;
import natives;

injector::hook_back<void(__cdecl*)()> hbCGameProcess;
void __cdecl CGameProcessHook()
Expand All @@ -17,30 +18,26 @@ void __cdecl CGameProcessHook()
FusionFix::onGameInitEvent().executeAll();
});

//if (CTimer__m_UserPause && CTimer__m_CodePause)
//{
static auto oldMenuState = 0;

//if (!*CTimer__m_UserPause && !*CTimer__m_CodePause)
//{
uint32_t curMenuState = false;
if (curMenuState != oldMenuState)
{
FusionFix::onMenuExitEvent().executeAll();
}
oldMenuState = curMenuState;
FusionFix::onGameProcessEvent().executeAll();
//}
//else
//{
// uint32_t curMenuState = true;
// if (curMenuState != oldMenuState) {
// FusionFix::onMenuEnterEvent().executeAll();
// }
// oldMenuState = curMenuState;
// FusionFix::onMenuDrawingEvent().executeAll();
//}
//}
static auto oldMenuState = 0;
if (!Natives::IsPauseMenuActive())
{
auto curMenuState = false;
if (curMenuState != oldMenuState)
{
FusionFix::onMenuExitEvent().executeAll();
}
oldMenuState = curMenuState;
FusionFix::onGameProcessEvent().executeAll();
}
else
{
auto curMenuState = true;
if (curMenuState != oldMenuState) {
FusionFix::onMenuEnterEvent().executeAll();
}
oldMenuState = curMenuState;
FusionFix::onMenuDrawingEvent().executeAll();
}

return hbCGameProcess.fun();
}
Expand All @@ -52,14 +49,14 @@ void Init()
auto pattern = hook::pattern("E8 ? ? ? ? E8 ? ? ? ? 8B 0D ? ? ? ? 8B 15 ? ? ? ? 89 0D");
hbCGameProcess.fun = injector::MakeCALL(pattern.get_first(0), CGameProcessHook, true).get();

//static auto futures = FusionFix::onInitEventAsync().executeAllAsync();
static auto futures = FusionFix::onInitEventAsync().executeAllAsync();

//FusionFix::onGameInitEvent() += []()
//{
// for (auto& f : futures.get())
// f.wait();
// futures.get().clear();
//};
FusionFix::onGameInitEvent() += []()
{
for (auto& f : futures.get())
f.wait();
futures.get().clear();
};

FusionFix::onInitEvent().executeAll();
}
Expand Down
27 changes: 17 additions & 10 deletions source/hideskip.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ public:
static raw_mem fnHideSkip1(pattern.get_first(8), { 0x90, 0x90, 0x90, 0x90, 0x90 }); // nop x5
pattern = hook::pattern("8B C8 89 86 ? ? ? ? E8 ? ? ? ? D9 EE 8B 86 ? ? ? ? 8B 38 83 EC 08 D9 54 24 04 8D 4C 24 20 D9 1C 24 E8 ? ? ? ? F3 0F 7E 00 8B 97 ? ? ? ? 83 EC 18 8B CC 66 0F D6 01 F3 0F 7E 40 ? 66 0F D6 41 ? F3 0F 7E 40 ? 6A 18 68 ? ? ? ? 66 0F D6 41 ? 8B 8E ? ? ? ? 6A 18");
static raw_mem fnHideSkip2(pattern.get_first(8), { 0x90, 0x90, 0x90, 0x90, 0x90 }); // nop x5

static auto HideSkipCB = []()
{
if (FusionFixSettings.GetInt("PREF_HIDESKIP"))
{
fnHideSkip1.Write();
fnHideSkip2.Write();
}
else
{
fnHideSkip1.Restore();
fnHideSkip2.Restore();
}
};

HideSkipCB();

FusionFix::onIniFileChange() += []()
{
if (FusionFixSettings.GetInt("PREF_HIDESKIP"))
{
fnHideSkip1.Write();
fnHideSkip2.Write();
}
else
{
fnHideSkip1.Restore();
fnHideSkip2.Restore();
}
HideSkipCB();
};
};
}
Expand Down
9 changes: 8 additions & 1 deletion source/leaderboards.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ public:
auto pattern = hook::pattern("8B 81 ? ? ? ? 83 F8 06");
static raw_mem fnLeaderboards(pattern.get_first(0), { 0xC3 }); // ret

FusionFix::onIniFileChange() += []()
static auto LeaderboardsCB = []()
{
if (FusionFixSettings.GetInt("PREF_DISABLELEADERBOARDS"))
fnLeaderboards.Write();
else
fnLeaderboards.Restore();
};

LeaderboardsCB();

FusionFix::onIniFileChange() += []()
{
LeaderboardsCB();
};
};
}
} Leaderboards;
231 changes: 231 additions & 0 deletions source/led.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
module;

#include <common.hxx>
#include "ledsdk/LogitechLEDLib.h"

export module led;

import common;
import settings;
import natives;

bool bLogiLedInitialized = false;

void AmbientLighting()
{
LogiLedSetTargetDevice(LOGI_DEVICETYPE_ALL);
LogiLedSetLighting(100, 0, 0);
}

void AmmoInClip()
{
static std::vector<LogiLed::KeyName> keysLH = {
LogiLed::KeyName::TILDE, LogiLed::KeyName::ONE, LogiLed::KeyName::TWO, LogiLed::KeyName::THREE,
LogiLed::KeyName::FOUR,LogiLed::KeyName::FIVE,LogiLed::KeyName::SIX,LogiLed::KeyName::SEVEN,
LogiLed::KeyName::EIGHT,LogiLed::KeyName::NINE,LogiLed::KeyName::ZERO,LogiLed::KeyName::MINUS,
LogiLed::KeyName::EQUALS,
};

static std::vector<LogiLed::KeyName> keysRH = {
LogiLed::KeyName::F1, LogiLed::KeyName::F2, LogiLed::KeyName::F3,
LogiLed::KeyName::F4, LogiLed::KeyName::F5, LogiLed::KeyName::F6,
LogiLed::KeyName::F7, LogiLed::KeyName::F8, LogiLed::KeyName::F9,
LogiLed::KeyName::F10, LogiLed::KeyName::F11, LogiLed::KeyName::F12,
LogiLed::KeyName::PRINT_SCREEN, LogiLed::KeyName::SCROLL_LOCK,
LogiLed::KeyName::PAUSE_BREAK,
};

if (Natives::DoesMainPlayerExist())
{
auto pPlayerPed = Natives::GetPlayerPed(Natives::GetPlayerId());
auto pPlayerWeaponRH = Natives::GetWeaponFromHand(pPlayerPed, 0, 0);
auto pPlayerWeaponLH = Natives::GetWeaponFromHand(pPlayerPed, 1, 0);

if (pPlayerWeaponRH)
{
static auto oldAmmoInClip = -1;
auto ammoInClip = Natives::GetWeaponAmmoInClip(pPlayerWeaponRH);
if (ammoInClip != oldAmmoInClip)
{
auto maxAmmoInClip = Natives::GetMaxAmmoInClip(pPlayerPed, Natives::GetWeaponType(pPlayerWeaponRH));
auto ammoInClipPercent = ((float)ammoInClip / (float)maxAmmoInClip) * 100.0f;

for (size_t i = 0; i < keysRH.size(); i++)
{
auto indexInPercent = ((float)i / (float)keysRH.size()) * 100.0f;
if (ammoInClipPercent > indexInPercent)
LogiLedSetLightingForKeyWithKeyName(keysRH[i], 100, 100, 100);
else
LogiLedSetLightingForKeyWithKeyName(keysRH[i], 25, 25, 25);
}
}
oldAmmoInClip = ammoInClip;
}
else
{
for (auto k : keysRH)
LogiLedSetLightingForKeyWithKeyName(k, 25, 25, 25);
}

if (pPlayerWeaponLH)
{
static auto oldAmmoInClip = -1;
auto ammoInClip = Natives::GetWeaponAmmoInClip(pPlayerWeaponLH);
if (ammoInClip != oldAmmoInClip)
{
auto maxAmmoInClip = Natives::GetMaxAmmoInClip(pPlayerPed, Natives::GetWeaponType(pPlayerWeaponLH));
auto ammoInClipPercent = ((float)ammoInClip / (float)maxAmmoInClip) * 100.0f;

for (size_t i = 0; i < keysLH.size(); i++)
{
auto indexInPercent = ((float)i / (float)keysLH.size()) * 100.0f;
if (ammoInClipPercent > indexInPercent)
LogiLedSetLightingForKeyWithKeyName(keysLH[i], 100, 100, 100);
else
LogiLedSetLightingForKeyWithKeyName(keysLH[i], 25, 25, 25);
}
}
oldAmmoInClip = ammoInClip;
}
else
{
for (auto k : keysLH)
LogiLedSetLightingForKeyWithKeyName(k, 25, 25, 25);
}

{
static std::vector<LogiLed::KeyName> keys = {
LogiLed::KeyName::NUM_ONE, LogiLed::KeyName::NUM_TWO, LogiLed::KeyName::NUM_THREE,
LogiLed::KeyName::NUM_FOUR, LogiLed::KeyName::NUM_FIVE, LogiLed::KeyName::NUM_SIX,
LogiLed::KeyName::NUM_SEVEN, LogiLed::KeyName::NUM_EIGHT, LogiLed::KeyName::NUM_NINE,
};

static auto oldPayneKillersAmt = -1;
auto payneKillersAmt = Natives::GetPaynekillerAmt();
if (payneKillersAmt != oldPayneKillersAmt)
{
constexpr auto maxPayneKillersAmt = 9;

for (auto i = 0; i < maxPayneKillersAmt; i++)
{
if (payneKillersAmt > i)
LogiLedSetLightingForKeyWithKeyName(keys[i], 100, 100, 100);
else
LogiLedSetLightingForKeyWithKeyName(keys[i], 25, 25, 25);
}
}
oldPayneKillersAmt = payneKillersAmt;
}
}
}

void CurrentHealth(bool bForce = false)
{
static std::vector<LogiLed::KeyName> keys = {
LogiLed::KeyName::G_1, LogiLed::KeyName::G_2, LogiLed::KeyName::G_3, LogiLed::KeyName::G_4, LogiLed::KeyName::G_5,
};

if (Natives::DoesMainPlayerExist())
{
auto pPlayerPed = Natives::GetPlayerPed(Natives::GetPlayerId());

if (pPlayerPed)
{
auto pPlayerHealth = Natives::GetPedHealth(pPlayerPed);
static auto oldHealth = 0;
if (pPlayerHealth != oldHealth || bForce)
{
auto maxPlayerHealth = Natives::GetPedMaxHealth(pPlayerPed);
float healthPercent = (((float)pPlayerHealth - 100.0f) / ((float)maxPlayerHealth - 100.0f)) * 100.0f;

for (size_t i = 0; i < keys.size(); i++)
{
auto indexInPercent = ((float)i / (float)keys.size()) * 100.0f;
if (healthPercent < indexInPercent)
LogiLedSetLightingForKeyWithKeyName(keys[i], 100, 0, 0);
else
LogiLedSetLightingForKeyWithKeyName(keys[i], 100, 100, 100);
}
}
oldHealth = pPlayerHealth;
}
}
}

void ProcessLEDEvents()
{
AmmoInClip();
CurrentHealth();
}

class LED
{
public:
LED()
{
FusionFix::onInitEvent() += []()
{
if (FusionFixSettings.GetInt("PREF_LEDILLUMINATION"))
{
bLogiLedInitialized = LogiLedInit();
if (bLogiLedInitialized)
AmbientLighting();
}

FusionFix::onIniFileChange() += []()
{
if (FusionFixSettings.GetInt("PREF_LEDILLUMINATION"))
{
if (!bLogiLedInitialized) {
bLogiLedInitialized = LogiLedInit();
if (bLogiLedInitialized)
AmbientLighting();
}
}
else if (bLogiLedInitialized) {
LogiLedShutdown();
bLogiLedInitialized = false;
}
};
};

FusionFix::onGameProcessEvent() += []()
{
if (bLogiLedInitialized)
{
ProcessLEDEvents();
}
};

FusionFix::onMenuEnterEvent() += []()
{
LogiLedSaveCurrentLighting();
LogiLedSetTargetDevice(LOGI_DEVICETYPE_ALL);
AmbientLighting();
};

FusionFix::onMenuExitEvent() += []()
{
LogiLedRestoreLighting();
CurrentHealth(true);
};

FusionFix::onShutdownEvent() += []()
{
if (bLogiLedInitialized) {
LogiLedShutdown();
bLogiLedInitialized = false;
}
};

IATHook::Replace(GetModuleHandleA(NULL), "KERNEL32.DLL",
std::forward_as_tuple("ExitProcess", static_cast<void(__stdcall*)(UINT)>([](UINT uExitCode) {
if (bLogiLedInitialized) {
LogiLedShutdown();
bLogiLedInitialized = false;
}
ExitProcess(uExitCode);
}))
);
}
} LED;
Loading

0 comments on commit 8795a04

Please sign in to comment.