From 09060c265fde3532ef70f00fed6ee33b9da342b5 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 9 Dec 2014 20:21:24 -0500 Subject: [PATCH] Convert TFHoliday values to pubvars. --- extensions/tf2/holiday.cpp | 31 +++++++++++++++++++++++++++++++ gamedata/sm-tf2.games.txt | 21 +++++++++++++++++++++ plugins/include/tf2.inc | 23 +++++++++++++---------- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/extensions/tf2/holiday.cpp b/extensions/tf2/holiday.cpp index 1cabdd1f..fa52726c 100644 --- a/extensions/tf2/holiday.cpp +++ b/extensions/tf2/holiday.cpp @@ -126,9 +126,40 @@ void HolidayManager::UnhookIfNecessary() m_iHookID = 0; } +static inline void PopulateHolidayVar(IPluginRuntime *pRuntime, const char *pszName) +{ + uint32_t idx; + if (pRuntime->FindPubvarByName(pszName, &idx) != SP_ERROR_NONE) + return; + + int varValue = -1; + const char *key = g_pGameConf->GetKeyValue(pszName); + if (key) + { + varValue = atoi(key); + } + + sp_pubvar_t *var; + pRuntime->GetPubvarByIndex(idx, &var); + *var->offs = varValue; +} + void HolidayManager::OnPluginLoaded(IPlugin *plugin) { HookIfNecessary(); + + auto *pRuntime = plugin->GetRuntime(); + PopulateHolidayVar(pRuntime, "TFHoliday_Birthday"); + PopulateHolidayVar(pRuntime, "TFHoliday_Halloween"); + PopulateHolidayVar(pRuntime, "TFHoliday_Christmas"); + PopulateHolidayVar(pRuntime, "TFHoliday_EndOfTheLine"); + PopulateHolidayVar(pRuntime, "TFHoliday_ValentinesDay"); + PopulateHolidayVar(pRuntime, "TFHoliday_MeetThePyro"); + PopulateHolidayVar(pRuntime, "TFHoliday_SpyVsEngyWar"); + PopulateHolidayVar(pRuntime, "TFHoliday_FullMoon"); + PopulateHolidayVar(pRuntime, "TFHoliday_HalloweenOrFullMoon"); + PopulateHolidayVar(pRuntime, "TFHoliday_HalloweenOrFullMoonOrValentines"); + PopulateHolidayVar(pRuntime, "TFHoliday_AprilFools"); } void HolidayManager::OnPluginUnloaded(IPlugin *plugin) diff --git a/gamedata/sm-tf2.games.txt b/gamedata/sm-tf2.games.txt index fd3980ce..eaafe74f 100644 --- a/gamedata/sm-tf2.games.txt +++ b/gamedata/sm-tf2.games.txt @@ -146,4 +146,25 @@ } } } + + /* + * TF2 Holiday index values. Formerly SM TFHoliday enum. + */ + "tf" + { + "Keys" + { + "TFHoliday_Birthday" "1" + "TFHoliday_Halloween" "2" + "TFHoliday_Christmas" "3" + "TFHoliday_EndOfTheLine" "4" + "TFHoliday_ValentinesDay" "5" + "TFHoliday_MeetThePyro" "6" + "TFHoliday_SpyVsEngyWar" "7" + "TFHoliday_FullMoon" "8" + "TFHoliday_HalloweenOrFullMoon" "9" + "TFHoliday_HalloweenOrFullMoonOrValentines" "10" + "TFHoliday_AprilFools" "11" + } + } } diff --git a/plugins/include/tf2.inc b/plugins/include/tf2.inc index 6f9ba37e..59c3dfc6 100644 --- a/plugins/include/tf2.inc +++ b/plugins/include/tf2.inc @@ -170,18 +170,21 @@ const Float:TFCondDuration_Infinite = -1.0; enum TFHoliday { - TFHoliday_Birthday = 1, - TFHoliday_Halloween, - TFHoliday_Christmas, - TFHoliday_ValentinesDay, - TFHoliday_MeetThePyro, - TFHoliday_SpyVsEngyWar, - TFHoliday_FullMoon, - TFHoliday_HalloweenOrFullMoon, - TFHoliday_HalloweenOrFullMoonOrValentines, - TFHoliday_AprilFools, + TFHoliday_Invalid = -1 }; +public const TFHoliday:TFHoliday_Birthday; +public const TFHoliday:TFHoliday_Halloween; +public const TFHoliday:TFHoliday_Christmas; +public const TFHoliday:TFHoliday_EndOfTheLine; +public const TFHoliday:TFHoliday_ValentinesDay; +public const TFHoliday:TFHoliday_MeetThePyro; +public const TFHoliday:TFHoliday_SpyVsEngyWar; +public const TFHoliday:TFHoliday_FullMoon; +public const TFHoliday:TFHoliday_HalloweenOrFullMoon; +public const TFHoliday:TFHoliday_HalloweenOrFullMoonOrValentines; +public const TFHoliday:TFHoliday_AprilFools; + enum TFObjectType { TFObject_CartDispenser = 0,