Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for relative gamedata offsets #20

Merged
merged 3 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ In April 2021, [Mikusch](https://github.com/Mikusch) decided to remake the plugi

- SourceMod 1.11+
- [TF2Attributes](https://github.com/nosoop/tf2attributes)
- [MemoryPatch](https://github.com/Kenzzer/MemoryPatch) (compile only)
- [TF2 Utils](https://github.com/nosoop/SM-TFUtils)
- [MemoryPatch](https://github.com/Kenzzer/MemoryPatch) (compile only)
40 changes: 24 additions & 16 deletions addons/sourcemod/gamedata/mannvsmann.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@
{
"tf"
{
"Keys"
{
"CTFPlayer_BaseOffset"
{
"linux" "m_bIsMiniBoss"
"windows" "m_bIsMiniBoss"
}
"CCurrencyPack_BaseOffset"
{
"linux" "m_bDistributed"
"windows" "m_bDistributed"
}
"CPopulationManager_BaseOffset"
{
"linux" "m_vecOrigin"
"windows" "m_vecOrigin"
}
}
"Signatures"
{
"CUpgrades::ApplyUpgradeToItem"
Expand Down Expand Up @@ -164,11 +182,6 @@
}
"Offsets"
{
"CBaseEntity::GetBaseEntity"
{
"linux" "6"
"windows" "5"
}
"CCurrencyPack::MyTouch"
{
"linux" "226"
Expand Down Expand Up @@ -219,25 +232,20 @@
"linux" "229"
"windows" "227"
}
"CTFPlayerShared::m_pOuter"
{
"linux" "400"
"windows" "400"
}
"CTFPlayer::m_hReviveMarker"
{
"linux" "9164"
"windows" "9160"
"linux" "316"
"windows" "316"
}
"CCurrencyPack::m_nAmount"
{
"linux" "1276"
"windows" "1256"
"linux" "-26"
"windows" "-26"
}
"CPopulationManager::m_isRestoringCheckpoint"
{
"linux" "1512"
"windows" "1492"
"linux" "700"
"windows" "700"
}
}
"Functions"
Expand Down
32 changes: 12 additions & 20 deletions addons/sourcemod/scripting/mannvsmann.sp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#include <tf2_stocks>
#include <dhooks>
#include <tf2attributes>
#include <tf2utils>
#include <memorypatch>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.9.1"
#define PLUGIN_VERSION "1.10.0"

#define DEFAULT_UPGRADES_FILE "scripts/items/mvm_upgrades.txt"

Expand Down Expand Up @@ -202,12 +203,6 @@ ConVar mvm_defender_team;
// DHooks
TFTeam g_CurrencyPackTeam = TFTeam_Invalid;

// Offsets
int g_OffsetPlayerSharedOuter;
int g_OffsetPlayerReviveMarker;
int g_OffsetCurrencyPackAmount;
int g_OffsetRestoringCheckpoint;

// Other globals
Handle g_CurrencyHudSync;
Handle g_BuybackHudSync;
Expand All @@ -222,6 +217,7 @@ bool g_ForceMapReset;
#include "mannvsmann/dhooks.sp"
#include "mannvsmann/events.sp"
#include "mannvsmann/helpers.sp"
#include "mannvsmann/offsets.sp"
#include "mannvsmann/patches.sp"
#include "mannvsmann/sdkhooks.sp"
#include "mannvsmann/sdkcalls.sp"
Expand All @@ -243,21 +239,17 @@ public void OnPluginStart()
g_CurrencyHudSync = CreateHudSynchronizer();
g_BuybackHudSync = CreateHudSynchronizer();

Commands_Initialize();
ConVars_Initialize();
Events_Initialize();
Commands_Init();
ConVars_Init();
Events_Init();

GameData gamedata = new GameData("mannvsmann");
if (gamedata)
{
DHooks_Initialize(gamedata);
Patches_Initialize(gamedata);
SDKCalls_Initialize(gamedata);

g_OffsetPlayerSharedOuter = gamedata.GetOffset("CTFPlayerShared::m_pOuter");
g_OffsetPlayerReviveMarker = gamedata.GetOffset("CTFPlayer::m_hReviveMarker");
g_OffsetCurrencyPackAmount = gamedata.GetOffset("CCurrencyPack::m_nAmount");
g_OffsetRestoringCheckpoint = gamedata.GetOffset("CPopulationManager::m_isRestoringCheckpoint");
DHooks_Init(gamedata);
Patches_Init(gamedata);
Offsets_Init(gamedata);
SDKCalls_Init(gamedata);

delete gamedata;
}
Expand Down Expand Up @@ -373,7 +365,7 @@ public void OnEntityDestroyed(int entity)
// Remove the currency value from the world money
if (!GetEntProp(entity, Prop_Send, "m_bDistributed"))
{
int amount = GetEntData(entity, g_OffsetCurrencyPackAmount);
int amount = GetEntData(entity, GetOffset("CCurrencyPack", "m_nAmount"));
AddWorldMoney(TF2_GetTeam(entity), -amount);
}
}
Expand Down Expand Up @@ -593,7 +585,7 @@ void SetupOnMapStart()
// Set custom upgrades file and add it to downloads
char path[PLATFORM_MAX_PATH];
mvm_custom_upgrades_file.GetString(path, sizeof(path));
if (path[0] != EOS)
if (path[0])
{
SetCustomUpgradesFile(path);
}
Expand Down
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/mannvsmann/commands.sp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#pragma semicolon 1
#pragma newdecls required

void Commands_Initialize()
void Commands_Init()
{
RegAdminCmd("sm_currency_give", ConCmd_GiveCurrency, ADMFLAG_CHEATS, "Have some in-game money.");
}
Expand Down
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/mannvsmann/convars.sp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#pragma semicolon 1
#pragma newdecls required

void ConVars_Initialize()
void ConVars_Init()
{
CreateConVar("mvm_version", PLUGIN_VERSION, "Mann vs. Mann plugin version", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY | FCVAR_DONTRECORD);
mvm_enable = CreateConVar("mvm_enable", "1", "When set, the plugin will be enabled.");
Expand Down Expand Up @@ -94,7 +94,7 @@ static void ConVarChanged_ShowHealth(ConVar convar, const char[] oldValue, const

static void ConVarChanged_CustomUpgradesFile(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (newValue[0] != EOS)
if (newValue[0])
{
SetCustomUpgradesFile(newValue);
}
Expand Down
34 changes: 17 additions & 17 deletions addons/sourcemod/scripting/mannvsmann/dhooks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static DynamicHook g_DHookCheckRespawnWaves;
static RoundState g_PreHookRoundState;
static TFTeam g_PreHookTeam; // For clients, use the MvMPlayer methodmap

void DHooks_Initialize(GameData gamedata)
void DHooks_Init(GameData gamedata)
{
g_DynamicDetours = new ArrayList(sizeof(DetourData));
g_DynamicHookIds = new ArrayList();
Expand Down Expand Up @@ -420,45 +420,45 @@ static MRESReturn DHookCallback_DistributeCurrencyAmount_Post(DHookReturn ret, D
return MRES_Ignored;
}

static MRESReturn DHookCallback_ConditionGameRulesThink_Pre(Address playerShared)
static MRESReturn DHookCallback_ConditionGameRulesThink_Pre(Address pShared)
{
// Enables radius currency collection, radius spy scan and increased rage gain during setup
SetMannVsMachineMode(true);

return MRES_Ignored;
}

static MRESReturn DHookCallback_ConditionGameRulesThink_Post(Address playerShared)
static MRESReturn DHookCallback_ConditionGameRulesThink_Post(Address pShared)
{
ResetMannVsMachineMode();

return MRES_Ignored;
}

static MRESReturn DHookCallback_CanRecieveMedigunChargeEffect_Pre(Address playerShared, DHookReturn ret, DHookParam params)
static MRESReturn DHookCallback_CanRecieveMedigunChargeEffect_Pre(Address pShared, DHookReturn ret, DHookParam params)
{
// MvM allows flag carriers to be ubered (enabled from CTFPlayerShared::ConditionGameRulesThink), but we don't want this for balance reasons
SetMannVsMachineMode(false);

return MRES_Ignored;
}

static MRESReturn DHookCallback_CanRecieveMedigunChargeEffect_Post(Address playerShared, DHookReturn ret, DHookParam params)
static MRESReturn DHookCallback_CanRecieveMedigunChargeEffect_Post(Address pShared, DHookReturn ret, DHookParam params)
{
ResetMannVsMachineMode();

return MRES_Ignored;
}

static MRESReturn DHookCallback_RadiusSpyScan_Pre(Address playerShared)
static MRESReturn DHookCallback_RadiusSpyScan_Pre(Address pShared)
{
int outer = GetPlayerSharedOuter(playerShared);
TFTeam team = TF2_GetClientTeam(outer);
int player = TF2Util_GetPlayerFromSharedAddress(pShared);
TFTeam team = TF2_GetClientTeam(player);

// This MvM feature may confuse players, so we allow servers to toggle it
if (!mvm_radius_spy_scan.BoolValue)
{
MvMPlayer(outer).SetTeam(TFTeam_Spectator);
MvMPlayer(player).SetTeam(TFTeam_Spectator);
return MRES_Ignored;
}

Expand All @@ -467,7 +467,7 @@ static MRESReturn DHookCallback_RadiusSpyScan_Pre(Address playerShared)
{
if (IsClientInGame(client))
{
if (client == outer)
if (client == player)
{
MvMPlayer(client).SetTeam(TFTeam_Red);
}
Expand All @@ -488,13 +488,13 @@ static MRESReturn DHookCallback_RadiusSpyScan_Pre(Address playerShared)
return MRES_Ignored;
}

static MRESReturn DHookCallback_RadiusSpyScan_Post(Address playerShared)
static MRESReturn DHookCallback_RadiusSpyScan_Post(Address pShared)
{
int outer = GetPlayerSharedOuter(playerShared);
int player = TF2Util_GetPlayerFromSharedAddress(pShared);

if (!mvm_radius_spy_scan.BoolValue)
{
MvMPlayer(outer).ResetTeam();
MvMPlayer(player).ResetTeam();
return MRES_Ignored;
}

Expand All @@ -509,7 +509,7 @@ static MRESReturn DHookCallback_RadiusSpyScan_Post(Address playerShared)
return MRES_Ignored;
}

static MRESReturn DHookCallback_ApplyRocketPackStun_Pre(Address playerShared, DHookParam params)
static MRESReturn DHookCallback_ApplyRocketPackStun_Pre(Address pShared, DHookParam params)
{
// Minibosses in MvM get slowed down instead of fully stunned
for (int client = 1; client <= MaxClients; client++)
Expand All @@ -523,7 +523,7 @@ static MRESReturn DHookCallback_ApplyRocketPackStun_Pre(Address playerShared, DH
return MRES_Ignored;
}

static MRESReturn DHookCallback_ApplyRocketPackStun_Post(Address playerShared, DHookParam params)
static MRESReturn DHookCallback_ApplyRocketPackStun_Post(Address pShared, DHookParam params)
{
for (int client = 1; client <= MaxClients; client++)
{
Expand Down Expand Up @@ -843,7 +843,7 @@ static MRESReturn DHookCallback_RoundRespawn_Pre()
else
{
// Retain player upgrades (forces a call to CTFPlayer::ReapplyPlayerUpgrades)
SetEntData(populator, g_OffsetRestoringCheckpoint, true);
SetEntData(populator, GetOffset("CPopulationManager", "m_isRestoringCheckpoint"), true, 1);
}
}

Expand All @@ -855,7 +855,7 @@ static MRESReturn DHookCallback_RoundRespawn_Post()
int populator = FindEntityByClassname(-1, "info_populator");
if (populator != -1)
{
SetEntData(populator, g_OffsetRestoringCheckpoint, false);
SetEntData(populator, GetOffset("CPopulationManager", "m_isRestoringCheckpoint"), false, 1);
}

return MRES_Ignored;
Expand Down
6 changes: 3 additions & 3 deletions addons/sourcemod/scripting/mannvsmann/events.sp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum struct EventData

static ArrayList g_Events;

void Events_Initialize()
void Events_Init()
{
g_Events = new ArrayList(sizeof(EventData));

Expand Down Expand Up @@ -280,10 +280,10 @@ static void EventHook_PlayerDeath(Event event, const char[] name, bool dontBroad
{
if (!(death_flags & TF_DEATHFLAG_DEADRINGER) && !silent_kill)
{
if (GetEntDataEnt2(victim, g_OffsetPlayerReviveMarker) == -1)
if (GetEntDataEnt2(victim, GetOffset("CTFPlayer", "m_hReviveMarker")) == -1)
{
// Create revive marker
SetEntDataEnt2(victim, g_OffsetPlayerReviveMarker, SDKCall_ReviveMarkerCreate(victim));
SetEntDataEnt2(victim, GetOffset("CTFPlayer", "m_hReviveMarker"), SDKCall_ReviveMarkerCreate(victim));
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions addons/sourcemod/scripting/mannvsmann/helpers.sp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ Address GetPlayerShared(int client)
return GetEntityAddress(client) + offset;
}

int GetPlayerSharedOuter(Address playerShared)
{
Address outer = view_as<Address>(LoadFromAddress(playerShared + view_as<Address>(g_OffsetPlayerSharedOuter), NumberType_Int32));
return SDKCall_GetBaseEntity(outer);
}

void SetCustomUpgradesFile(const char[] path)
{
if (FileExists(path, true, "MOD"))
Expand Down Expand Up @@ -149,7 +143,7 @@ void ClearCustomUpgradesFile()

bool IsMannVsMachineMode()
{
return view_as<bool>(GameRules_GetProp("m_bPlayingMannVsMachine"));
return GameRules_GetProp("m_bPlayingMannVsMachine") != 0;
}

void SetMannVsMachineMode(bool value)
Expand Down
Loading