Skip to content

Commit

Permalink
SourceMod 1.12 Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Alienmario committed Oct 25, 2024
1 parent 033cb00 commit 698862d
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 630 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
id: setup-sp
uses: rumblefrog/setup-sp@master
with:
version: '1.11.6960'
version: '1.12.7164'
version-file: ./scripting/include/srccoop/public.inc
define-name: SRCCOOP_VERSION

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The script installation will automatically go through the process of installing
quit
```
- Install [Metamod:Source](https://www.sourcemm.net/downloads.php?branch=stable) (latest tested build ➤ __1155__) onto the server.
- Install [SourceMod](https://www.sourcemod.net/downloads.php?branch=stable) (latest tested build ➤ __6968__) onto the server.
- Install [SourceMod](https://www.sourcemod.net/downloads.php?branch=stable) (latest tested build ➤ __7164__) onto the server.
- Install [the latest SourceCoop release](https://github.com/ampreeT/SourceCoop/releases) onto the server.
- [Forward the necessary ports.](#port-forwarding)
Expand Down
6 changes: 0 additions & 6 deletions scripting/include/srccoop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

#if !defined SRCCOOP_CUSTOM_COMPILE

// Uncomment to disable debugging
// #define NO_DEBUG

#if defined SRCCOOP_HL2DM

#define CHECK_ENGINE "HL2DM"; if (GetEngineVersion() != Engine_HL2DM)
Expand Down Expand Up @@ -145,9 +142,6 @@
#include <topmenus>
#include <sourcescramble>

#pragma newdecls required
#pragma semicolon 1

#include <logdebug>

#include <srccoop/util/assert>
Expand Down
6 changes: 1 addition & 5 deletions scripting/include/srccoop/classdef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

IServerGameClients g_ServerGameClients;
CPlayerInfoManager g_pPlayerInfoManager;
CGlobalVars gpGlobals;

ConVar ai_los_mode;

Expand Down Expand Up @@ -412,9 +411,6 @@ stock void InitClassdef(GameData pGameConfig)
#if defined SRCCOOP_BLACKMESA
InitClassdefBM(pGameConfig);
#endif

if (!(gpGlobals = g_pPlayerInfoManager.GetGlobalVars()))
SetFailState("Could not get gpGlobals from PlayerInfoManager");
}

#define NULL_CBASEENTITY view_as<any>(-1)
Expand Down Expand Up @@ -3307,7 +3303,7 @@ methodmap CGlobalVarsBase
public void SetMaxPlayers(const int iMaxPlayers)
{
assert(this.IsValid(), "Invalid state")
assert(IsInBounds(iMaxPlayers, 0, MaxClients), "Invalid maxplayers [%d]", iMaxPlayers)
assert1(IsInBounds(iMaxPlayers, 0, MaxClients), "Invalid maxplayers [%d]", iMaxPlayers)

StoreToAddress(view_as<Address>(this) + 0x14, iMaxPlayers, NumberType_Int32);
}
Expand Down
46 changes: 23 additions & 23 deletions scripting/include/srccoop/config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,29 @@ enum struct SourceCoopConfig

//------------------------------------------------------

CONF_INIT(\
CONF_STR(SND_BRINGALL)\
CONF_FLT(SND_BRINGALL_VOL)\
CONF_STR(SND_PORTAL)\
CONF_FLT(SND_PORTAL_VOL)\
CONF_STR(PORTAL_PARTICLE)\
CONF_FLT(PORTAL_TOUCH_SIZE)\
CONF_CLR(FROZEN_FADE_COLOR)\
CONF_INT(FROZEN_FADE_DUR_IN)\
CONF_INT(FROZEN_FADE_DUR_OUT)\
CONF_STR(SND_TICK)\
CONF_FLT(SND_TICK_VOL)\
CONF_STR(SND_3)\
CONF_STR(SND_2)\
CONF_STR(SND_1)\
CONF_STR(SND_CHANGELEVEL)\
CONF_FLT(SND_CHANGELEVEL_VOL)\
CONF_STR(SND_CHANGELEVEL_TICK)\
CONF_FLT(SND_CHANGELEVEL_TICK_VOL)\
CONF_STR(CHANGELEVEL_EFFECT_MODEL)\
CONF_INT(CHANGELEVEL_EFFECT_AMOUNT)\
CONF_FLT(CHANGELEVEL_EFFECT_SPEED)\
CONF_FLT(CHANGELEVEL_EFFECT_PERIOD)\
CONF_INIT(
CONF_STR(SND_BRINGALL)
CONF_FLT(SND_BRINGALL_VOL)
CONF_STR(SND_PORTAL)
CONF_FLT(SND_PORTAL_VOL)
CONF_STR(PORTAL_PARTICLE)
CONF_FLT(PORTAL_TOUCH_SIZE)
CONF_CLR(FROZEN_FADE_COLOR)
CONF_INT(FROZEN_FADE_DUR_IN)
CONF_INT(FROZEN_FADE_DUR_OUT)
CONF_STR(SND_TICK)
CONF_FLT(SND_TICK_VOL)
CONF_STR(SND_3)
CONF_STR(SND_2)
CONF_STR(SND_1)
CONF_STR(SND_CHANGELEVEL)
CONF_FLT(SND_CHANGELEVEL_VOL)
CONF_STR(SND_CHANGELEVEL_TICK)
CONF_FLT(SND_CHANGELEVEL_TICK_VOL)
CONF_STR(CHANGELEVEL_EFFECT_MODEL)
CONF_INT(CHANGELEVEL_EFFECT_AMOUNT)
CONF_FLT(CHANGELEVEL_EFFECT_SPEED)
CONF_FLT(CHANGELEVEL_EFFECT_PERIOD)
)

}
Expand Down
2 changes: 1 addition & 1 deletion scripting/include/srccoop/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ public MRESReturn Hook_AIConditionsThink(int _this)
if (!conditionsElement)
continue;

CBaseEntity pActor = CBaseEntity(LoadEntityHandleFromAddress(conditionsElement));
CBaseEntity pActor = CBaseEntity(LoadEntityFromHandleAddress(conditionsElement));
if (!pActor.IsValid())
continue;

Expand Down
1 change: 1 addition & 0 deletions scripting/include/srccoop/globals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ ArrayList g_pCoopModeMemPatchList;
// ----------------------------
IServerGameDLL g_ServerGameDLL;
IServerTools g_ServerTools;
CGlobalVars gpGlobals;

// ----------------------------
// Plugin variables
Expand Down
2 changes: 1 addition & 1 deletion scripting/include/srccoop/levellump.inc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ methodmap CEntityListLump < ArrayList
{
public CEntityListLump()
{
return view_as<CEntityListLump>(new ArrayList(sizeof(CEntityInfoLump)));
return view_as<CEntityListLump>(new ArrayList());
}

// cast
Expand Down
12 changes: 9 additions & 3 deletions scripting/include/srccoop/util/assert.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@

/*
* Assertion utility - only compiled into debug code
* Params: 1 => condition, 2 => message + format arguments
* Params: 0 => condition, 1 => message, 2+ => format arguments
*/

#if defined DEBUG

#define assert(%1,%2) if (!(%1)) SetFailState(%2);
#define assert(%0,%1) if (!(%0)) SetFailState(%1);
#define assert1(%0,%1,%2) if (!(%0)) SetFailState(%1,%2);
#define assert2(%0,%1,%2,%3) if (!(%0)) SetFailState(%1,%2,%3);
#define assert3(%0,%1,%2,%3,%4) if (!(%0)) SetFailState(%1,%2,%3,%4);

#else

#define assert(%1,%2)
#define assert(%0,%1)
#define assert1(%0,%1,%2)
#define assert2(%0,%1,%2,%3)
#define assert3(%0,%1,%2,%3,%4)

#endif
54 changes: 1 addition & 53 deletions scripting/include/srccoop/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -206,34 +206,6 @@ stock int LoadStringFromAddress(Address addr, char[] buffer, int maxlen, bool &b
return c;
}

/**
* DEPRECATE with SM 1.12 => LoadEntityFromHandleAddress
* Retrieves an entity index from a raw entity handle address.
*
* Note that SourceMod's entity conversion routine is an implementation detail that may change.
*
* @param addr Address to a memory location.
* @return Entity index, or -1 if not valid.
*/
stock int LoadEntityHandleFromAddress(Address addr)
{
return EntRefToEntIndex(Deref(addr) | (1 << 31));
}

/**
* DEPRECATE with SM 1.12 => StoreEntityToHandleAddress
* Stores an entity into a raw entity handle address. Stores zero if the entity is not valid.
*
* Note that SourceMod's entity conversion routine is an implementation detail that may change.
*
* @param addr Address to a memory location.
* @param entity Entity index.
*/
stock void StoreEntityHandleToAddress(Address addr, int entity)
{
StoreToAddress(addr, IsValidEntity(entity)? EntIndexToEntRef(entity) & ~(1 << 31) : 0, NumberType_Int32);
}

/**
* Returns an entity index from its address by attempting to read the
* CBaseEntity::m_RefEHandle member. This assumes the address of a CBaseEntity is
Expand All @@ -246,7 +218,7 @@ stock int GetEntityFromAddress(Address pEntity)
{
static int offs_RefEHandle;
if (offs_RefEHandle)
return LoadEntityHandleFromAddress(pEntity + offs_RefEHandle);
return LoadEntityFromHandleAddress(pEntity + offs_RefEHandle);

// if we don't have it already, attempt to lookup offset based on SDK information
// CWorld is derived from CBaseEntity so it should have both offsets
Expand Down Expand Up @@ -274,30 +246,6 @@ stock int GetEntityFromAddress(Address pEntity)
return GetEntityFromAddress(pEntity);
}

//------------------------------------------------------
// Cookie utils
//------------------------------------------------------
#if defined _clientprefs_included
stock bool GetCookieBool(Cookie cookie, int client)
{
static char szBuffer[2];
cookie.Get(client, szBuffer, sizeof(szBuffer));
return StringToInt(szBuffer) == 1;
}

stock void SetCookieBool(Cookie cookie, int client, bool val)
{
cookie.Set(client, val? "1" : "0");
}

stock bool IsCookieSet(Cookie cookie, int client)
{
static char szBuffer[2];
cookie.Get(client, szBuffer, sizeof(szBuffer));
return szBuffer[0] != '\0';
}
#endif

//------------------------------------------------------
// Text utils
//------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions scripting/include/srccoop_api.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
#pragma semicolon 1

#if !defined SRCCOOP_CUSTOM_COMPILE

#if defined SRCCOOP_HL2DM

#else

#if !defined SRCCOOP_BLACKMESA
// SRCCOOP_BLACKMESA is the fallback if no other definition is passed
#define SRCCOOP_BLACKMESA
#endif

#endif

#endif


Expand Down
3 changes: 3 additions & 0 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ void LoadGameData()
if (!(g_ServerTools = IServerTools(GetInterface(pGameConfig, "server", "IServerTools"))))
SetFailState("Could not get interface for %s", "IServerTools");

if (!(gpGlobals = g_pPlayerInfoManager.GetGlobalVars()))
SetFailState("Could not get gpGlobals from PlayerInfoManager");

// Calls

#if defined PLAYERPATCH_SERVERSIDE_RAGDOLLS
Expand Down
27 changes: 2 additions & 25 deletions scripting/srccoop_addon_earbleed.sp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Plugin myinfo =

#define MENUITEM_TOGGLE_EARBLEED "ToggleEarBleed"

CookieCompat pEnabledCookie;
Cookie pEnabledCookie;
ConVar pConvarDefault;

void LoadGameData()
Expand All @@ -43,7 +43,7 @@ public void OnPluginStart()
InitSourceCoopAddon();
LoadGameData();

pEnabledCookie = view_as<CookieCompat>(new Cookie("sourcecoop_earbleed_enabled", "Earbleed toggle", CookieAccess_Protected));
pEnabledCookie = new Cookie("sourcecoop_earbleed_enabled", "Earbleed toggle", CookieAccess_Protected);
pConvarDefault = CreateConVar("sourcecoop_earbleed_default", "0", "Sets the default setting of the earbleed player preference.", _, true, 0.0, true, 1.0);
}

Expand Down Expand Up @@ -112,27 +112,4 @@ public MRESReturn Hook_SetPlayerDSP(DHookParam hParams)
bool ShouldRing(int client)
{
return view_as<bool>(AreClientCookiesCached(client)? pEnabledCookie.GetInt(client, pConvarDefault.IntValue) : pConvarDefault.IntValue);
}

// SM 1.11 Compat - undo when 1.12 stable
methodmap CookieCompat < Cookie
{
public int GetInt(int client, int defaultValue = 0)
{
char buffer[11];
this.Get(client, buffer, sizeof(buffer));

int value;
if (!StringToIntEx(buffer, value))
{
value = defaultValue;
}
return value;
}
public void SetInt(int client, int value) {
char sValue[11];
IntToString(value, sValue, sizeof(sValue));

this.Set(client, sValue);
}
}
19 changes: 5 additions & 14 deletions scripting/srccoop_addon_killsounds.sp
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ public void MyMenuHandler(TopMenu topmenu, TopMenuAction action, TopMenuObject o
{
if (action == TopMenuAction_DisplayOption)
{
Format(buffer, maxlength, "%T", GetCookieBool(pEnabledCookie, param) ? "disable killsounds" : "enable killsounds", param);
Format(buffer, maxlength, "%T", pEnabledCookie.GetInt(param, pConvarDefault.BoolValue) ? "disable killsounds" : "enable killsounds", param);
}
else if (action == TopMenuAction_SelectOption)
{
if (AreClientCookiesCached(param))
{
if (GetCookieBool(pEnabledCookie, param))
if (pEnabledCookie.GetInt(param, pConvarDefault.BoolValue))
{
SetCookieBool(pEnabledCookie, param, false);
pEnabledCookie.SetInt(param, false);
Msg(param, "%t", "killsounds disabled");
}
else
{
SetCookieBool(pEnabledCookie, param, true);
pEnabledCookie.SetInt(param, true);
Msg(param, "%t", "killsounds enabled");
}
}
Expand All @@ -80,23 +80,14 @@ public void OnConfigsExecuted()
PrecacheSound(szSoundPath, true);
}

public void OnClientCookiesCached(int client)
{
if (!IsCookieSet(pEnabledCookie, client))
{
// new player - set the default
SetCookieBool(pEnabledCookie, client, pConvarDefault.BoolValue);
}
}

public void Event_EntityKilled(Event hEvent, const char[] szName, bool bDontBroadcast)
{
CBaseEntity pKilled = CBaseEntity(hEvent.GetInt("entindex_killed"));
CBaseEntity pAttacker = CBaseEntity(hEvent.GetInt("entindex_attacker"));

if (pAttacker.IsClassPlayer() && pKilled.IsClassNPC())
{
if (GetCookieBool(pEnabledCookie, pAttacker.entindex))
if (pEnabledCookie.GetInt(pAttacker.entindex, pConvarDefault.BoolValue))
{
EmitSoundToClient(pAttacker.entindex, szSoundPath, .level = SNDLEVEL_NONE, .volume = flSoundVol);
}
Expand Down
18 changes: 9 additions & 9 deletions scripting/srccoop_addon_revive.sp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ enum struct ReviveConfig
char BAR_MODEL[PLATFORM_MAX_PATH];
char RAGDOLL_PARTICLE[128];

CONF_INIT(\
CONF_STR(SND_START)\
CONF_STR(SND_DENY)\
CONF_STR(SND_RESPAWN)\
CONF_INT(SND_RESPAWN_PITCH)\
CONF_INT(SNDLEVEL)\
CONF_CLR(BAR_COLOR)\
CONF_STR(BAR_MODEL)\
CONF_STR(RAGDOLL_PARTICLE)\
CONF_INIT(
CONF_STR(SND_START)
CONF_STR(SND_DENY)
CONF_STR(SND_RESPAWN)
CONF_INT(SND_RESPAWN_PITCH)
CONF_INT(SNDLEVEL)
CONF_CLR(BAR_COLOR)
CONF_STR(BAR_MODEL)
CONF_STR(RAGDOLL_PARTICLE)
)
}

Expand Down
Loading

0 comments on commit 698862d

Please sign in to comment.