Skip to content

Commit

Permalink
Merge branch 'alliedmodders:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Lxeon authored Sep 14, 2024
2 parents ae68978 + 4e15a92 commit 047b354
Show file tree
Hide file tree
Showing 65 changed files with 706 additions and 577 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
[submodule "hl2sdk-manifests"]
path = hl2sdk-manifests
url = https://github.com/alliedmodders/hl2sdk-manifests.git
[submodule "public/safetyhook"]
path = public/safetyhook
url = https://github.com/alliedmodders/safetyhook
22 changes: 22 additions & 0 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SMConfig(object):
self.target_archs = set()
self.enable_asan = getattr(builder.options, 'enable_asan', False)
self.asan_libs = {}
self.libsafetyhook = {}

if builder.options.targets:
target_archs = builder.options.targets.split(',')
Expand Down Expand Up @@ -520,6 +521,17 @@ class SMConfig(object):

return binary

def AddCDetour(self, binary):
public_path = os.path.join(builder.sourcePath, 'public')
binary.sources += [ os.path.join(public_path, 'CDetour', 'detours.cpp') ]
binary.compiler.cxxincludes += [ os.path.join(public_path, 'safetyhook', 'include') ]

for task in self.libsafetyhook:
if task.target.arch == binary.compiler.target.arch:
binary.compiler.linkflags += [task.binary]
return
raise Exception('No suitable build of safetyhook was found.')

def HL2Library(self, context, compiler, name, sdk):
binary = self.Library(context, compiler, name)
self.ConfigureForExtension(context, binary.compiler)
Expand Down Expand Up @@ -568,6 +580,16 @@ if SM.use_auto_versioning():
{ 'SM': SM }
)

class SafetyHookShim(object):
def __init__(self):
self.all_targets = {}
self.libsafetyhook = {}

SafetyHook = SafetyHookShim()
SafetyHook.all_targets = SM.all_targets
builder.Build('public/safetyhook/AMBuilder', {'SafetyHook': SafetyHook })
SM.libsafetyhook = SafetyHook.libsafetyhook

class SPRoot(object):
def __init__(self):
self.generated_headers = SM.generated_headers
Expand Down
11 changes: 11 additions & 0 deletions core/HalfLife2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ ServerClass *CHalfLife2::FindServerClass(const char *classname)
return pInfo->sc;
}

ServerClass *CHalfLife2::FindEntityServerClass(CBaseEntity *pEntity)
{
IServerNetworkable* pNetwork = ((IServerUnknown *)pEntity)->GetNetworkable();
if (pNetwork == nullptr)
{
return nullptr;
}

return pNetwork->GetServerClass();
}

DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
{
DataTableInfo *pInfo = NULL;
Expand Down
1 change: 1 addition & 0 deletions core/HalfLife2.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class CHalfLife2 :
bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
datamap_t *GetDataMap(CBaseEntity *pEntity);
ServerClass *FindServerClass(const char *classname);
ServerClass *FindEntityServerClass(CBaseEntity *pEntity);
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
bool FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatable_info_t *pDataTable);
void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
Expand Down
5 changes: 0 additions & 5 deletions core/logic/ExtensionSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,6 @@ void CExtension::AddDependency(const IfaceInfo *pInfo)
}
}

bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
{
return (i1.iface == i2.iface) && (i1.owner == i2.owner);
}

void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
{
IfaceInfo info;
Expand Down
2 changes: 1 addition & 1 deletion core/logic/ShareSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace SourceMod

struct IfaceInfo
{
bool operator ==(const IfaceInfo &info)
bool operator ==(const IfaceInfo &info) const
{
return (info.iface == iface && info.owner == owner);
}
Expand Down
8 changes: 7 additions & 1 deletion core/logic/TextParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
SMCResult res;
SMCStates states;
char c;
bool end_of_last_buffer_was_backslash = false;

StringInfo strings[3];
StringInfo emptystring;
Expand Down Expand Up @@ -383,6 +384,10 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (reparse_point)
{
read += (parse_point - reparse_point);
if(read > 0)
{
end_of_last_buffer_was_backslash = reparse_point[-1] == '\\';
}
parse_point = reparse_point;
reparse_point = NULL;
}
Expand Down Expand Up @@ -454,7 +459,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (in_quote)
{
/* If i was 0, we could have reparsed, so make sure there's no buffer underrun */
if ((&parse_point[i] != in_buf) && c == '"' && parse_point[i-1] != '\\')
if ( (&parse_point[i] != in_buf) && c == '"' && !((i == 0 && end_of_last_buffer_was_backslash) || (i > 0 && parse_point[i-1] == '\\')) )
{
/* If we reached a quote in an ignore phase,
* we're staging a string and we must rotate it out.
Expand Down Expand Up @@ -726,6 +731,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (parse_point)
{
parse_point = &parse_point[read];
end_of_last_buffer_was_backslash = parse_point[-1] == '\\';
parse_point -= bytes;
}
}
Expand Down
38 changes: 38 additions & 0 deletions core/logic/smn_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ class FileNatives :
}
virtual bool LogPrint(const char *msg)
{
if (!g_pLogHook) {
return false;
}

cell_t result = 0;
g_pLogHook->PushString(msg);
g_pLogHook->Execute(&result);
Expand Down Expand Up @@ -751,6 +755,39 @@ static cell_t sm_SetFilePermissions(IPluginContext *pContext, const cell_t *para
#endif
}

static cell_t sm_GetFilePermissions(IPluginContext *pContext, const cell_t *params)
{
char *name;
char realpath[PLATFORM_MAX_PATH];

pContext->LocalToString(params[1], &name);
g_pSM->BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name);

cell_t *mask;
pContext->LocalToPhysAddr(params[2], &mask);

#if defined PLATFORM_WINDOWS
struct _stat buffer;
cell_t valid = _stat(realpath, &buffer) == 0;

if ((buffer.st_mode & _S_IREAD) != 0) {
*mask |= (FPERM_U_READ|FPERM_G_READ|FPERM_O_READ)|(FPERM_U_EXEC|FPERM_G_EXEC|FPERM_O_EXEC);
}

if ((buffer.st_mode & _S_IWRITE) != 0) {
*mask |= (FPERM_U_WRITE|FPERM_G_WRITE|FPERM_O_WRITE);
}

return valid;
#else
struct stat buffer;
cell_t valid = stat(realpath, &buffer) == 0;

*mask = buffer.st_mode;
return valid;
#endif
}

static cell_t sm_CreateDirectory(IPluginContext *pContext, const cell_t *params)
{
char *name;
Expand Down Expand Up @@ -1224,6 +1261,7 @@ REGISTER_NATIVES(filesystem)
{"RemoveGameLogHook", sm_RemoveGameLogHook},
{"CreateDirectory", sm_CreateDirectory},
{"SetFilePermissions", sm_SetFilePermissions},
{"GetFilePermissions", sm_GetFilePermissions},

{"File.ReadLine", sm_ReadFileLine},
{"File.Read", sm_ReadFile},
Expand Down
52 changes: 23 additions & 29 deletions core/smn_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,10 @@ inline edict_t *BaseEntityToEdict(CBaseEntity *pEntity)
{
IServerUnknown *pUnk = (IServerUnknown *)pEntity;
IServerNetworkable *pNet = pUnk->GetNetworkable();

if (!pNet)
if (pNet == nullptr)
{
return NULL;
return nullptr;
}

return pNet->GetEdict();
}

Expand Down Expand Up @@ -363,14 +361,20 @@ static cell_t IsValidEntity(IPluginContext *pContext, const cell_t *params)

static cell_t IsEntNetworkable(IPluginContext *pContext, const cell_t *params)
{
edict_t *pEdict = GetEdict(params[1]);
IServerUnknown *pUnknown = (IServerUnknown *)g_HL2.ReferenceToEntity(params[1]);
if (!pUnknown)
{
return 0;
}

if (!pEdict)
IServerNetworkable *pNet = pUnknown->GetNetworkable();
if (!pNet)
{
return 0;
}

return (pEdict->GetNetworkable() != NULL) ? 1 : 0;
edict_t* edict = pNet->GetEdict();
return (edict && !edict->IsFree()) ? 1 : 0;
}

static cell_t GetEntityCount(IPluginContext *pContext, const cell_t *params)
Expand Down Expand Up @@ -436,14 +440,12 @@ static cell_t GetEntityNetClass(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid entity (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
}

IServerNetworkable *pNet = pUnk->GetNetworkable();
if (!pNet)
ServerClass *pClass = g_HL2.FindEntityServerClass(pEntity);
if (!pClass)
{
return 0;
}

ServerClass *pClass = pNet->GetServerClass();

pContext->StringToLocal(params[2], params[3], pClass->GetName());

return 1;
Expand Down Expand Up @@ -1270,13 +1272,11 @@ static cell_t SetEntDataString(IPluginContext *pContext, const cell_t *params)
#define FIND_PROP_SEND(type, type_name) \
sm_sendprop_info_t info;\
SendProp *pProp; \
IServerUnknown *pUnk = (IServerUnknown *)pEntity; \
IServerNetworkable *pNet = pUnk->GetNetworkable(); \
if (!pNet) \
{ \
return pContext->ThrowNativeError("Edict %d (%d) is not networkable", g_HL2.ReferenceToIndex(params[1]), params[1]); \
ServerClass *pServerClass = g_HL2.FindEntityServerClass(pEntity); \
if (pServerClass == nullptr) { \
pContext->ThrowNativeError("Failed to retrieve entity %d (%d) server class!", g_HL2.ReferenceToIndex(params[1]), params[1]); \
} \
if (!g_HL2.FindSendPropInfo(pNet->GetServerClass()->GetName(), prop, &info)) \
if (!g_HL2.FindSendPropInfo(pServerClass->GetName(), prop, &info)) \
{ \
const char *class_name = g_HL2.GetEntityClassname(pEntity); \
return pContext->ThrowNativeError("Property \"%s\" not found (entity %d/%s)", \
Expand Down Expand Up @@ -1434,13 +1434,13 @@ static cell_t GetEntPropArraySize(IPluginContext *pContext, const cell_t *params
{
sm_sendprop_info_t info;

IServerUnknown *pUnk = (IServerUnknown *)pEntity;
IServerNetworkable *pNet = pUnk->GetNetworkable();
if (!pNet)
ServerClass *pServerClass = g_HL2.FindEntityServerClass(pEntity);
if (pServerClass == nullptr)
{
return pContext->ThrowNativeError("Edict %d (%d) is not networkable", g_HL2.ReferenceToIndex(params[1]), params[1]);
return pContext->ThrowNativeError("Failed to retrieve entity %d (%d) server class!", g_HL2.ReferenceToIndex(params[1]), params[1]);
}
if (!g_HL2.FindSendPropInfo(pNet->GetServerClass()->GetName(), prop, &info))

if (!g_HL2.FindSendPropInfo(pServerClass->GetName(), prop, &info))
{
const char *class_name = g_HL2.GetEntityClassname(pEntity);
return pContext->ThrowNativeError("Property \"%s\" not found (entity %d/%s)",
Expand Down Expand Up @@ -2079,13 +2079,7 @@ static cell_t SetEntPropEnt(IPluginContext *pContext, const cell_t *params)
edict_t *pOtherEdict = NULL;
if (pOther)
{
IServerNetworkable *pNetworkable = ((IServerUnknown *) pOther)->GetNetworkable();
if (!pNetworkable)
{
return pContext->ThrowNativeError("Entity %d (%d) does not have a valid edict", g_HL2.ReferenceToIndex(params[4]), params[4]);
}

pOtherEdict = pNetworkable->GetEdict();
pOtherEdict = BaseEntityToEdict(pOther);
if (!pOtherEdict || pOtherEdict->IsFree())
{
return pContext->ThrowNativeError("Entity %d (%d) does not have a valid edict", g_HL2.ReferenceToIndex(params[4]), params[4]);
Expand Down
12 changes: 3 additions & 9 deletions extensions/cstrike/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ project.sources += [
'timeleft.cpp',
'forwards.cpp',
'util_cstrike.cpp',
'../../public/smsdk_ext.cpp',
'../../public/CDetour/detours.cpp',
'../../public/asm/asm.c',
'../../public/libudis86/decode.c',
'../../public/libudis86/itab.c',
'../../public/libudis86/syn-att.c',
'../../public/libudis86/syn-intel.c',
'../../public/libudis86/syn.c',
'../../public/libudis86/udis86.c',
'../../public/smsdk_ext.cpp'
]

for sdk_name in ['css', 'csgo']:
Expand All @@ -34,6 +26,8 @@ for sdk_name in ['css', 'csgo']:

cxx.defines += ['HAVE_STRING_H']
binary = SM.HL2ExtConfig(project, builder, cxx, 'game.cstrike.ext.' + sdk['extension'], sdk)
SM.AddCDetour(binary)

if sdk_name == 'csgo':
compiler = binary.compiler
compiler.cxxincludes += [os.path.join(sdk['path'], 'public', 'steam')]
Expand Down
9 changes: 6 additions & 3 deletions extensions/cstrike/natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,13 @@ static cell_t CS_DropWeapon(IPluginContext *pContext, const cell_t *params)

//Psychonic is awesome for this
sm_sendprop_info_t spi;
IServerUnknown *pUnk = (IServerUnknown *)pWeapon;
IServerNetworkable *pNet = pUnk->GetNetworkable();
ServerClass *pServerClass = gamehelpers->FindEntityServerClass(pWeapon);
if (pServerClass == nullptr)
{
return pContext->ThrowNativeError("Failed to retrieve entity %d server class!", params[2]);
}

if (!UTIL_FindDataTable(pNet->GetServerClass()->m_pTable, "DT_WeaponCSBase", &spi, 0))
if (!UTIL_FindDataTable(pServerClass->m_pTable, "DT_WeaponCSBase", &spi, 0))
return pContext->ThrowNativeError("Entity index %d is not a weapon", params[2]);

if (!gamehelpers->FindSendPropInfo("CBaseCombatWeapon", "m_hOwnerEntity", &spi))
Expand Down
Loading

0 comments on commit 047b354

Please sign in to comment.