Skip to content

Commit

Permalink
Switch to TF_IsHolidayActive detour (#3)
Browse files Browse the repository at this point in the history
* Switch to TF_IsHolidayActive detour

* Bump version
  • Loading branch information
Mikusch authored Jun 24, 2022
1 parent 28a8527 commit 8c0edf5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
22 changes: 21 additions & 1 deletion addons/sourcemod/gamedata/hwn_cosmetic_enabler.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2022 Mikusch
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -21,6 +21,12 @@
{
"Signatures"
{
"TF_IsHolidayActive"
{
"library" "server"
"linux" "@_Z18TF_IsHolidayActivei"
"windows" "\x55\x8B\xEC\xA1\x2A\x2A\x2A\x2A\x83\x78\x30\x00\x74\x2A\x32\xC0"
}
"CLogicOnHoliday::InputFire"
{
"library" "server"
Expand All @@ -30,6 +36,20 @@
}
"Functions"
{
"TF_IsHolidayActive"
{
"signature" "TF_IsHolidayActive"
"callconv" "cdecl"
"return" "bool"
"this" "ignore"
"arguments"
{
"eHoliday"
{
"type" "int"
}
}
}
"CLogicOnHoliday::InputFire"
{
"signature" "CLogicOnHoliday::InputFire"
Expand Down
55 changes: 36 additions & 19 deletions addons/sourcemod/scripting/hwn_cosmetic_enabler.sp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2022 Mikusch
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -22,6 +22,7 @@

ConVar tf_enable_halloween_cosmetics;
ConVar tf_forced_holiday;
DynamicDetour g_hDetourIsHolidayActive;
DynamicDetour g_hDetourInputFire;

bool g_bIsEnabled;
Expand All @@ -33,7 +34,7 @@ public Plugin myinfo =
name = "[TF2] Halloween Cosmetic Enabler",
author = "Mikusch",
description = "Enables Halloween cosmetics and spells regardless of current holiday",
version = "1.2.0",
version = "1.3.0",
url = "https://github.com/Mikusch/HalloweenCosmeticEnabler"
}

Expand All @@ -47,9 +48,13 @@ public void OnPluginStart()
GameData hGameData = new GameData("hwn_cosmetic_enabler");
if (hGameData)
{
g_hDetourIsHolidayActive = DynamicDetour.FromConf(hGameData, "TF_IsHolidayActive")
if (!g_hDetourIsHolidayActive)
SetFailState("Failed to setup detour for TF_IsHolidayActive");

g_hDetourInputFire = DynamicDetour.FromConf(hGameData, "CLogicOnHoliday::InputFire");
if (!g_hDetourInputFire)
LogError("Failed to setup detour for CLogicOnHoliday::InputFire");
SetFailState("Failed to setup detour for CLogicOnHoliday::InputFire");

delete hGameData;
}
Expand Down Expand Up @@ -77,22 +82,6 @@ public void OnConfigsExecuted()
TogglePlugin(tf_enable_halloween_cosmetics.BoolValue);
}

public Action TF2_OnIsHolidayActive(TFHoliday eHoliday, bool &bResult)
{
if (!g_bIsEnabled)
return Plugin_Continue;

// Force-enable Halloween at all times unless we specifically request not to
if (eHoliday == TFHoliday_HalloweenOrFullMoon && !g_bNoForcedHoliday)
{
bResult = true;
return Plugin_Changed;
}

// Otherwise, let the game determine which holiday is active
return Plugin_Continue;
}

public void OnClientPutInServer(int iClient)
{
if (!g_bIsEnabled)
Expand Down Expand Up @@ -131,6 +120,24 @@ public void ConVarChanged_EnableHalloweenCosmetics(ConVar hConVar, const char[]
TogglePlugin(hConVar.BoolValue);
}

public MRESReturn DHookCallback_IsHolidayActive_Post(DHookReturn hReturn, DHookParam hParam)
{
TFHoliday eHoliday = hParam.Get(1);

if (!g_bIsEnabled)
return MRES_Ignored;

// Force-enable Halloween at all times unless we specifically request not to
if (eHoliday == TFHoliday_HalloweenOrFullMoon && !g_bNoForcedHoliday)
{
hReturn.Value = true;
return MRES_Supercede;
}

// Otherwise, let the game determine which holiday is active
return MRES_Ignored;
}

public MRESReturn DHookCallback_InputFire_Pre(int iEntity, DHookParam hParam)
{
// Prevent tf_logic_on_holiday from assuming it's always Halloween
Expand Down Expand Up @@ -181,6 +188,11 @@ void TogglePlugin(bool bEnable)
{
tf_forced_holiday.AddChangeHook(ConVarChanged_ForcedHoliday);

if (g_hDetourIsHolidayActive)
{
g_hDetourIsHolidayActive.Enable(Hook_Post, DHookCallback_IsHolidayActive_Post);
}

if (g_hDetourInputFire)
{
g_hDetourInputFire.Enable(Hook_Pre, DHookCallback_InputFire_Pre);
Expand All @@ -191,6 +203,11 @@ void TogglePlugin(bool bEnable)
{
tf_forced_holiday.RemoveChangeHook(ConVarChanged_ForcedHoliday);

if (g_hDetourIsHolidayActive)
{
g_hDetourIsHolidayActive.Disable(Hook_Post, DHookCallback_IsHolidayActive_Post);
}

if (g_hDetourInputFire)
{
g_hDetourInputFire.Disable(Hook_Pre, DHookCallback_InputFire_Pre);
Expand Down

0 comments on commit 8c0edf5

Please sign in to comment.