Skip to content

Commit

Permalink
More classdef changes (#203)
Browse files Browse the repository at this point in the history
* Replace GetEntIndex with entindex property

* Add entref property

* Replace entity flags with property

* Replace edict flags with property

* Replace address with property

* Lookup array size in ClearSuitQueue
  • Loading branch information
Alienmario authored Dec 28, 2024
1 parent d482859 commit 6cda5cc
Show file tree
Hide file tree
Showing 47 changed files with 467 additions and 549 deletions.
18 changes: 9 additions & 9 deletions scripting/include/srccoop/blackmesa/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MRESReturn Hook_IsPlayerAlly(int _this, Handle hReturn, Handle hParams)
public void Hook_LAVSpawnPost(int iEntIndex)
{
CBaseEntity pEntity = CBaseEntity(iEntIndex);
pEntity.SetEdictAlwaysTransmit(true);
pEntity.edictFlags |= FL_EDICT_ALWAYS;
}

//------------------------------------------------------
Expand Down Expand Up @@ -321,8 +321,8 @@ void MarionettistManipulate(int iMarionettist, int iClient, CBasePlayer pPlayer)

// start it
pPuppet.AcceptInputStr("Manipulate", "!activator", pPlayer);
hkThink.HookEntity(Hook_Post, pPuppet.GetEntIndex(), Hook_MarionettistPuppetThinkPost);
hkUpdateOnRemove.HookEntity(Hook_Post, pPuppet.GetEntIndex(), Hook_MarionettistPuppetRemoved);
hkThink.HookEntity(Hook_Post, pPuppet.entindex, Hook_MarionettistPuppetThinkPost);
hkUpdateOnRemove.HookEntity(Hook_Post, pPuppet.entindex, Hook_MarionettistPuppetRemoved);
g_pActiveMarionettist[iClient] = pPuppet;
}

Expand Down Expand Up @@ -388,7 +388,7 @@ MRESReturn Hook_MarionettistPuppetRemoved(int iEntIndex)
{
if (g_pActiveMarionettist[i] == pPuppet)
{
if (GetEntProp(g_pActiveMarionettist[i].GetEntIndex(), Prop_Data, "m_bIgnoreCollisions"))
if (GetEntProp(g_pActiveMarionettist[i].entindex, Prop_Data, "m_bIgnoreCollisions"))
{
if (IsClientInGame(i))
{
Expand Down Expand Up @@ -798,9 +798,9 @@ public MRESReturn Hook_ToggleIronsights(int _this, Handle hParams)
return MRES_Supercede;

// Values grabbed out of `weapon_crossbow.dmx`.
iFOV = g_pPlayerIronsightClassic[pPlayer.GetEntIndex()] ? 20 : 10;
iFOV = g_pPlayerIronsightClassic[pPlayer.entindex] ? 20 : 10;

if (!g_pPlayerIronsightClassic[pPlayer.GetEntIndex()])
if (!g_pPlayerIronsightClassic[pPlayer.entindex])
{
CPredictedViewModel pViewModel = pPlayer.GetViewModel();
if (pViewModel.IsValid())
Expand All @@ -815,9 +815,9 @@ public MRESReturn Hook_ToggleIronsights(int _this, Handle hParams)
else
{
// Values grabbed out of `weapon_357.dmx`.
iFOV = g_pPlayerIronsightClassic[pPlayer.GetEntIndex()] ? 40 : 55;
iFOV = g_pPlayerIronsightClassic[pPlayer.entindex] ? 40 : 55;

if (!g_pPlayerIronsightClassic[pPlayer.GetEntIndex()])
if (!g_pPlayerIronsightClassic[pPlayer.entindex])
{
pWeapon.SendWeaponAnim(bWillBeUsingIronsights ? ACT_VM_IDLE_TO_IS : ACT_VM_IS_TO_IDLE);
pPlayer.ShowCrosshair(!bWillBeUsingIronsights);
Expand Down Expand Up @@ -845,7 +845,7 @@ public MRESReturn Hook_IronsightGetPrimaryAttackActivity(int _this, Handle hRetu
if (pWeapon.IsInIronsights())
{
CBasePlayer pPlayer = view_as<CBasePlayer>(pWeapon.GetOwner());
if (pPlayer.IsValid() && !g_pPlayerIronsightClassic[pPlayer.GetEntIndex()])
if (pPlayer.IsValid() && !g_pPlayerIronsightClassic[pPlayer.entindex])
{
DHookSetReturn(hReturn, ACT_VM_PRIMARYATTACK_IS);
return MRES_Supercede;
Expand Down
4 changes: 2 additions & 2 deletions scripting/include/srccoop/blackmesa/idle_anims.inc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Action IdleAnims_Hook_SetTransmit(const int iEntity, const int iClient)
public void IdleAnims_Hook_PlayerPreThinkPost(const int iClient)
{
CBasePlayer pPlayer = CBasePlayer(iClient);
int iPlayerIndex = pPlayer.GetEntIndex();
int iPlayerIndex = pPlayer.entindex;
bool bHasModel = g_pIdle[iPlayerIndex].m_pModel.IsValid();
if (pPlayer.IsAlive() && pPlayer.GetActiveWeapon() == NULL_CBASEENTITY)
{
Expand All @@ -137,7 +137,7 @@ public void IdleAnims_Hook_PlayerPreThinkPost(const int iClient)
g_pIdle[iPlayerIndex].m_pModel.SetAnimation("idle_noweapon");
g_pIdle[iPlayerIndex].m_eIdleType = IdleAnimType_IdleNoWeapon;

SDKHook(g_pIdle[iPlayerIndex].m_pModel.GetEntIndex(), SDKHook_SetTransmit, IdleAnims_Hook_SetTransmit);
SDKHook(g_pIdle[iPlayerIndex].m_pModel.entindex, SDKHook_SetTransmit, IdleAnims_Hook_SetTransmit);
hkUpdateOnRemove.HookEntity(Hook_Pre, g_pIdle[iPlayerIndex].m_pModel.entindex, IdleAnims_Hook_IdleKilled);
pPlayer.SetFadeMaxDist(0.000001);

Expand Down
2 changes: 1 addition & 1 deletion scripting/include/srccoop/checkpoint.inc
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ methodmap CCoopSpawnSystem
}
if (pCheckpoint.m_pTouchEnt.IsValid())
{
SDKHook(pCheckpoint.m_pTouchEnt.GetEntIndex(), SDKHook_StartTouchPost, Hook_TouchCheckpoint);
SDKHook(pCheckpoint.m_pTouchEnt.entindex, SDKHook_StartTouchPost, Hook_TouchCheckpoint);
bHasTrigger = true;
}
if (pCheckpoint.m_flRadius > 0.0)
Expand Down
4 changes: 2 additions & 2 deletions scripting/include/srccoop/deathnotice.inc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ methodmap DnManager
{
g_sDnData.m_pBot1 = CBasePlayer(CreateFakeClient("ScBot01"));
g_sDnData.m_pBot1.SetTeam(TEAM_SPECTATOR);
g_sDnData.m_pBot1.SetFlags(FL_FAKECLIENT | FL_NOTARGET);
g_sDnData.m_pBot1.m_fFlags |= (FL_FAKECLIENT | FL_NOTARGET);
}
return g_sDnData.m_pBot1;
}
Expand All @@ -156,7 +156,7 @@ methodmap DnManager
{
g_sDnData.m_pBot2 = CBasePlayer(CreateFakeClient("ScBot02"));
g_sDnData.m_pBot2.SetTeam(TEAM_SPECTATOR);
g_sDnData.m_pBot2.SetFlags(FL_FAKECLIENT | FL_NOTARGET);
g_sDnData.m_pBot2.m_fFlags |= (FL_FAKECLIENT | FL_NOTARGET);
}
return g_sDnData.m_pBot2;
}
Expand Down
28 changes: 14 additions & 14 deletions scripting/include/srccoop/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public MRESReturn Hook_UTIL_GetLocalPlayer(Handle hReturn)
}
}
// LogDebug("Overriding UTIL_GetLocalPlayer");
DHookSetReturn(hReturn, pPlayer.GetEntIndex());
DHookSetReturn(hReturn, pPlayer.entindex);
return MRES_Supercede;
}
// BUGBUG Crash avoidance for Linux SM 1.12 - 7164+
Expand Down Expand Up @@ -289,7 +289,7 @@ public MRESReturn Hook_FindNamedEntity(int _this, Handle hReturn, Handle hParams
CBasePlayer pBestPlayer = GetNearestPlayer(pActor);
if (pBestPlayer != NULL_CBASEENTITY)
{
DHookSetReturn(hReturn, pBestPlayer.GetEntIndex());
DHookSetReturn(hReturn, pBestPlayer.entindex);
return MRES_Supercede;
}
}
Expand Down Expand Up @@ -341,11 +341,11 @@ public MRESReturn Hook_ExpresserHost_DoModifyOrAppendCriteriaPost(Handle hParams
public void Hook_ChangelevelSpawn(int iEntIndex)
{
CChangelevel pEntity = CChangelevel(iEntIndex);
DHookEntity(hkAcceptInput, true, pEntity.GetEntIndex(), _, Hook_ChangelevelAcceptInput);
DHookEntity(hkAcceptInput, true, pEntity.entindex, _, Hook_ChangelevelAcceptInput);

if (!(pEntity.m_spawnflags & SF_CHANGELEVEL_NOTOUCH))
{
SDKHook(pEntity.GetEntIndex(), SDKHook_Touch, Hook_ChangelevelOnTouch);
SDKHook(pEntity.entindex, SDKHook_Touch, Hook_ChangelevelOnTouch);
CreateTimer(Conf.CHANGELEVEL_EFFECT_PERIOD, ChangelevelEffects, pEntity, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}
}
Expand Down Expand Up @@ -543,7 +543,7 @@ public MRESReturn Hook_PointViewcontrolAcceptInput(int _this, Handle hReturn, Ha
CBaseEntity pViewEntity = pActivator.GetViewEntity();
if (pViewEntity.IsValid() && pViewEntity.IsClassname("point_viewcontrol") && pViewEntity != pThis)
{
SetEntPropEnt(pViewEntity.GetEntIndex(), Prop_Data, "m_hPlayer", pActivator.GetEntIndex());
SetEntPropEnt(pViewEntity.entindex, Prop_Data, "m_hPlayer", pActivator.entindex);
bHookSkip = true;
pViewEntity.AcceptInputStr("Disable");
bHookSkip = false;
Expand Down Expand Up @@ -648,7 +648,7 @@ public MRESReturn Hook_EnvZoomAcceptInput(int _this, Handle hReturn, Handle hPar
szNewInput = "Zoom";
if (pActivator.IsPlayer())
{
iNewClient = pActivator.GetEntIndex();
iNewClient = pActivator.entindex;
}
}
else if (strcmp(szInput, "ZoomAll", false) == 0)
Expand Down Expand Up @@ -881,11 +881,11 @@ public void Timer_EnvSpritePostSpawn(Handle timer, CBaseEntity pEntity)
{
if (pEntity.IsValid())
{
if (HasEntProp(pEntity.GetEntIndex(), Prop_Data, "m_flGlowProxySize"))
if (HasEntProp(pEntity.entindex, Prop_Data, "m_flGlowProxySize"))
{
if (GetEntPropFloat(pEntity.GetEntIndex(), Prop_Data, "m_flGlowProxySize") > 64.0)
if (GetEntPropFloat(pEntity.entindex, Prop_Data, "m_flGlowProxySize") > 64.0)
{
SetEntPropFloat(pEntity.GetEntIndex(), Prop_Data, "m_flGlowProxySize", 64.0);
SetEntPropFloat(pEntity.entindex, Prop_Data, "m_flGlowProxySize", 64.0);
}
}
}
Expand All @@ -904,7 +904,7 @@ public MRESReturn Hook_ResolveNamesPost(int _this)
{
CBaseEntity pEnt = CBaseEntity(_this);
CBasePlayer pPlayer = GetNearestPlayer(pEnt);
SetEntPropEnt(_this, Prop_Data, "m_hGoalEntity", pPlayer.GetEntIndex());
SetEntPropEnt(_this, Prop_Data, "m_hGoalEntity", pPlayer.entindex);
}
return MRES_Ignored;
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ public MRESReturn Hook_BaseNpcUpdateSleepState(int _this, Handle hParams)
for (int i = 1; i <= MaxClients; ++i)
{
CBasePlayer pPlayer = CBasePlayer(i);
if (pPlayer.IsValid() && pPlayer.IsAlive() && !pPlayer.HasFlags(FL_NOTARGET) && pPlayer.FVisibleEntity(pBaseNPC))
if (pPlayer.IsValid() && pPlayer.IsAlive() && !(pPlayer.m_fFlags & FL_NOTARGET) && pPlayer.FVisibleEntity(pBaseNPC))
{
pBaseNPC.Wake();
break;
Expand Down Expand Up @@ -1173,7 +1173,7 @@ public bool HasAnyPlayerWalkedIntoWakeRadius(CAI_BaseNPC pBaseNPC)
for (int i = 1; i <= MaxClients; ++i)
{
CBasePlayer pPlayer = CBasePlayer(i);
if (pPlayer.IsValid() && pPlayer.IsAlive() && !pPlayer.HasFlags(FL_NOTARGET))
if (pPlayer.IsValid() && pPlayer.IsAlive() && !(pPlayer.m_fFlags & FL_NOTARGET))
{
float vec3PlayerPosition[3];
pPlayer.GetAbsOrigin(vec3PlayerPosition);
Expand Down Expand Up @@ -1240,7 +1240,7 @@ public MRESReturn Hook_ProtoSniperSelectSchedule(int _this, Handle hReturn)
/*
if (PrecacheSound("NPC_Sniper.TargetDestroyed", true))
{
EmitGameSoundToAll("NPC_Sniper.TargetDestroyed", pSniper.GetEntIndex());
EmitGameSoundToAll("NPC_Sniper.TargetDestroyed", pSniper.entindex);
}
*/
}
Expand Down Expand Up @@ -1513,7 +1513,7 @@ public MRESReturn Hook_UTIL_FindClientInPVSGuts(DHookReturn hReturn, DHookParam
{
// Naive solution with fast execution.
// The original implementation below this implementation causes issues with NPCs doing nothing.
DHookSetReturn(hReturn, GetNearestPlayerPreferAlive(CBaseEntity(hParams.Get(1))).GetEntIndex());
DHookSetReturn(hReturn, GetNearestPlayerPreferAlive(CBaseEntity(hParams.Get(1))).entindex);
return MRES_Supercede;

/*
Expand Down
6 changes: 3 additions & 3 deletions scripting/include/srccoop/instancing.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ methodmap ItemInstancingManager
{
if (!CoopManager.IsFeatureEnabled(FT_INSTANCE_ITEMS_NORESET))
{
g_pPickedUpItems[pPlayer.GetEntIndex()].Clear();
g_pPickedUpItems[pPlayer.entindex].Clear();
}
}

public static void AddPickedUpItem(CBasePlayer pPlayer, CBaseEntity pItem)
{
char key[32]; IntToString(view_as<int>(pItem), key, sizeof(key));
g_pPickedUpItems[pPlayer.GetEntIndex()].SetValue(key, true);
g_pPickedUpItems[pPlayer.entindex].SetValue(key, true);
}

public static bool HasPickedUpItem(CBasePlayer pPlayer, CBaseEntity pItem)
{
int client = pPlayer.GetEntIndex();
int client = pPlayer.entindex;
if (!g_pPickedUpItems[client]) // filter sourceTV
return false;

Expand Down
16 changes: 8 additions & 8 deletions scripting/include/srccoop/manager.inc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ methodmap CoopManager
for (int i = 0; i < pOutputHookList.Length; i++)
{
CEntityOutputHook pOutputHook; pOutputHookList.GetArray(i, pOutputHook);
HookSingleEntityOutput(pEntity.GetEntIndex(), pOutputHook.m_szOutputName, Callback_OutputCallbackForDelay);
HookSingleEntityOutput(pEntity.entindex, pOutputHook.m_szOutputName, Callback_OutputCallbackForDelay);
}
data.m_bMapHasDelayedOutput = true;
}
Expand Down Expand Up @@ -269,13 +269,13 @@ methodmap CoopManager
{
if (g_pLevelLump.m_iIntroType == INTRO_FADE)
{
pPlayer.AddFlags(FL_ATCONTROLS | FL_FROZEN); // Freeze controls and angles.
Client_ScreenFade(pPlayer.GetEntIndex(), 0, FFADE_STAYOUT);
pPlayer.m_fFlags |= (FL_ATCONTROLS | FL_FROZEN); // Freeze controls and angles.
Client_ScreenFade(pPlayer.entindex, 0, FFADE_STAYOUT);
}
else if (g_pLevelLump.m_iIntroType == INTRO_FREEZE)
{
pPlayer.AddFlags(FL_ATCONTROLS); // Freeze controls.
Client_ScreenFade(pPlayer.GetEntIndex(), Conf.FROZEN_FADE_DUR_IN, FFADE_OUT | FFADE_STAYOUT, _,
pPlayer.m_fFlags |= FL_ATCONTROLS; // Freeze controls.
Client_ScreenFade(pPlayer.entindex, Conf.FROZEN_FADE_DUR_IN, FFADE_OUT | FFADE_STAYOUT, _,
Conf.FROZEN_FADE_COLOR[0], Conf.FROZEN_FADE_COLOR[1], Conf.FROZEN_FADE_COLOR[2], Conf.FROZEN_FADE_COLOR[3]);
}

Expand Down Expand Up @@ -587,10 +587,10 @@ public Action Timer_DecrementUntilMapStart(Handle hTimer)
// TODO: Look into this.
// `FL_FROZEN` is being removed even without the below line in Black Mesa (i doubt this affects other games).
// `CBM_MP_GameRules.SetStateEndTime` might be the culprit and might have side effects for other behaviors too.
pClient.RemoveFlags(FL_ATCONTROLS | FL_FROZEN);
pClient.m_fFlags &= ~(FL_ATCONTROLS | FL_FROZEN);
if (g_pLevelLump.m_iIntroType == INTRO_FREEZE)
{
Client_ScreenFade(pClient.GetEntIndex(), Conf.FROZEN_FADE_DUR_OUT, FFADE_PURGE | FFADE_IN, 1,
Client_ScreenFade(pClient.entindex, Conf.FROZEN_FADE_DUR_OUT, FFADE_PURGE | FFADE_IN, 1,
Conf.FROZEN_FADE_COLOR[0], Conf.FROZEN_FADE_COLOR[1], Conf.FROZEN_FADE_COLOR[2], Conf.FROZEN_FADE_COLOR[3]);
}
}
Expand All @@ -603,7 +603,7 @@ public Action Timer_DecrementUntilMapStart(Handle hTimer)
FireOutputData pFireOutputData; data.m_pDelayedOutputs.GetArray(i, pFireOutputData);
if (pFireOutputData.m_pCaller.IsValid())
{
FireEntityOutput(pFireOutputData.m_pCaller.GetEntIndex(), pFireOutputData.m_szName, pFireOutputData.m_pActivator.GetEntIndex(), pFireOutputData.m_flDelay);
FireEntityOutput(pFireOutputData.m_pCaller.entindex, pFireOutputData.m_szName, pFireOutputData.m_pActivator.entindex, pFireOutputData.m_flDelay);

if (pFireOutputData.m_pCaller.IsClassname("trigger_once"))
{
Expand Down
2 changes: 1 addition & 1 deletion scripting/include/srccoop/manager_changelevel.inc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ methodmap ChangeLevelManager < ArrayList

public bool SetPlayerVote(CChangelevel pChangelevel, CBasePlayer pPlayer, int[] iClientVoteIndicies)
{
int iPlayer = pPlayer.GetEntIndex();
int iPlayer = pPlayer.entindex;
ChangeLevelVoteLump pChangeLvlLump;
for (int i = 0; i < this.Length; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions scripting/include/srccoop/manager_persistence.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ methodmap EquipmentManager

public static bool GetEquipment(CBasePlayer pPlayer, CCoopEquipment equipment)
{
if (strlen(g_szSteamIds[pPlayer.GetEntIndex()]) > 0)
if (strlen(g_szSteamIds[pPlayer.entindex]) > 0)
{
return EquipmentManager.GetEquipmentSteam(g_szSteamIds[pPlayer.GetEntIndex()], equipment);
return EquipmentManager.GetEquipmentSteam(g_szSteamIds[pPlayer.entindex], equipment);
}
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions scripting/include/srccoop/manager_survival.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ methodmap SurvivalManager {

public static bool IsDead(CBasePlayer pPlayer)
{
int iSteamID = GetSteamAccountID(pPlayer.GetEntIndex(), g_pConvarValidateSteamIds.BoolValue);
int iSteamID = GetSteamAccountID(pPlayer.entindex, g_pConvarValidateSteamIds.BoolValue);
return data.m_pDeadPlayerIDs.FindValue(iSteamID) != -1;
}

public static void SetDead(CBasePlayer pPlayer, bool bDead)
{
int iSteamID = GetSteamAccountID(pPlayer.GetEntIndex(), g_pConvarValidateSteamIds.BoolValue);
int iSteamID = GetSteamAccountID(pPlayer.entindex, g_pConvarValidateSteamIds.BoolValue);
int index = data.m_pDeadPlayerIDs.FindValue(iSteamID);

if ((index == -1) == bDead)
Expand All @@ -131,7 +131,7 @@ methodmap SurvivalManager {
{
if (!data.m_bRespawning && (!SurvivalManager.CheckSpawnTimeout() || SurvivalManager.IsDead(pPlayer)))
{
int client = pPlayer.GetEntIndex();
int client = pPlayer.entindex;

if (!data.m_bSpecInit[client] && data.m_pRestartTimer == null)
{
Expand Down Expand Up @@ -170,7 +170,7 @@ methodmap SurvivalManager {
{
if (SurvivalManager.GetMode())
{
data.m_bSpecInit[pPlayer.GetEntIndex()] = false;
data.m_bSpecInit[pPlayer.entindex] = false;
SurvivalManager.GameOverCheck();
}
}
Expand All @@ -179,7 +179,7 @@ methodmap SurvivalManager {
{
if (SurvivalManager.GetMode())
{
data.m_bSpecInit[pPlayer.GetEntIndex()] = false;
data.m_bSpecInit[pPlayer.entindex] = false;
SurvivalManager.SetDead(pPlayer, true);
SurvivalManager.GameOverCheck();
}
Expand Down
Loading

0 comments on commit 6cda5cc

Please sign in to comment.