Merge branch 'alliedmodders:master' into master

This commit is contained in:
fdxx 2024-06-10 09:33:00 +08:00 committed by GitHub
commit 048fd5383d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 84 additions and 71430 deletions

3
.gitmodules vendored
View File

@ -9,3 +9,6 @@
[submodule "hl2sdk-manifests"] [submodule "hl2sdk-manifests"]
path = hl2sdk-manifests path = hl2sdk-manifests
url = https://github.com/alliedmodders/hl2sdk-manifests.git url = https://github.com/alliedmodders/hl2sdk-manifests.git
[submodule "public/safetyhook"]
path = public/safetyhook
url = https://github.com/alliedmodders/safetyhook

View File

@ -55,6 +55,7 @@ class SMConfig(object):
self.target_archs = set() self.target_archs = set()
self.enable_asan = getattr(builder.options, 'enable_asan', False) self.enable_asan = getattr(builder.options, 'enable_asan', False)
self.asan_libs = {} self.asan_libs = {}
self.libsafetyhook = {}
if builder.options.targets: if builder.options.targets:
target_archs = builder.options.targets.split(',') target_archs = builder.options.targets.split(',')
@ -522,13 +523,14 @@ class SMConfig(object):
def AddCDetour(self, binary): def AddCDetour(self, binary):
public_path = os.path.join(builder.sourcePath, 'public') public_path = os.path.join(builder.sourcePath, 'public')
binary.sources += [ binary.sources += [ os.path.join(public_path, 'CDetour', 'detours.cpp') ]
os.path.join(public_path, 'CDetour', 'detours.cpp'), binary.compiler.cxxincludes += [ os.path.join(public_path, 'safetyhook', 'include') ]
os.path.join(public_path, 'safetyhook', 'safetyhook.cpp'),
os.path.join(public_path, 'safetyhook', 'Zydis.c') for task in self.libsafetyhook:
] if task.target.arch == binary.compiler.target.arch:
binary.compiler.cxxincludes += [ os.path.join(public_path, 'safetyhook') ] binary.compiler.linkflags += [task.binary]
binary.compiler.includes += [ os.path.join(public_path, 'safetyhook') ] return
raise Exception('No suitable build of safetyhook was found.')
def HL2Library(self, context, compiler, name, sdk): def HL2Library(self, context, compiler, name, sdk):
binary = self.Library(context, compiler, name) binary = self.Library(context, compiler, name)
@ -578,6 +580,16 @@ if SM.use_auto_versioning():
{ 'SM': SM } { '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): class SPRoot(object):
def __init__(self): def __init__(self):
self.generated_headers = SM.generated_headers self.generated_headers = SM.generated_headers

View File

@ -342,6 +342,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
SMCResult res; SMCResult res;
SMCStates states; SMCStates states;
char c; char c;
bool end_of_last_buffer_was_backslash = false;
StringInfo strings[3]; StringInfo strings[3];
StringInfo emptystring; StringInfo emptystring;
@ -383,6 +384,10 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (reparse_point) if (reparse_point)
{ {
read += (parse_point - reparse_point); read += (parse_point - reparse_point);
if(read > 0)
{
end_of_last_buffer_was_backslash = reparse_point[-1] == '\\';
}
parse_point = reparse_point; parse_point = reparse_point;
reparse_point = NULL; reparse_point = NULL;
} }
@ -454,7 +459,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (in_quote) if (in_quote)
{ {
/* If i was 0, we could have reparsed, so make sure there's no buffer underrun */ /* 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, /* If we reached a quote in an ignore phase,
* we're staging a string and we must rotate it out. * we're staging a string and we must rotate it out.
@ -726,6 +731,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (parse_point) if (parse_point)
{ {
parse_point = &parse_point[read]; parse_point = &parse_point[read];
end_of_last_buffer_was_backslash = parse_point[-1] == '\\';
parse_point -= bytes; parse_point -= bytes;
} }
} }

View File

@ -755,6 +755,39 @@ static cell_t sm_SetFilePermissions(IPluginContext *pContext, const cell_t *para
#endif #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) static cell_t sm_CreateDirectory(IPluginContext *pContext, const cell_t *params)
{ {
char *name; char *name;
@ -1228,6 +1261,7 @@ REGISTER_NATIVES(filesystem)
{"RemoveGameLogHook", sm_RemoveGameLogHook}, {"RemoveGameLogHook", sm_RemoveGameLogHook},
{"CreateDirectory", sm_CreateDirectory}, {"CreateDirectory", sm_CreateDirectory},
{"SetFilePermissions", sm_SetFilePermissions}, {"SetFilePermissions", sm_SetFilePermissions},
{"GetFilePermissions", sm_GetFilePermissions},
{"File.ReadLine", sm_ReadFileLine}, {"File.ReadLine", sm_ReadFileLine},
{"File.Read", sm_ReadFile}, {"File.Read", sm_ReadFile},

View File

@ -234,7 +234,7 @@ void CHookManager::OnClientConnected(int client)
} }
} }
int hookid = SH_ADD_VPHOOK(IClientMessageHandler, ProcessVoiceData, (IClientMessageHandler *)((intptr_t)(pClient) + 4), SH_MEMBER(this, &CHookManager::ProcessVoiceData), true); int hookid = SH_ADD_VPHOOK(IClientMessageHandler, ProcessVoiceData, (IClientMessageHandler *)((intptr_t)(pClient) + sizeof(void *)), SH_MEMBER(this, &CHookManager::ProcessVoiceData), true);
hook.SetHookID(hookid); hook.SetHookID(hookid);
netProcessVoiceData.push_back(new CVTableHook(hook)); netProcessVoiceData.push_back(new CVTableHook(hook));
} }
@ -584,7 +584,7 @@ bool CHookManager::SendFile(const char *filename, unsigned int transferID)
#if !defined CLIENTVOICE_HOOK_SUPPORT #if !defined CLIENTVOICE_HOOK_SUPPORT
bool CHookManager::ProcessVoiceData(CLC_VoiceData *msg) bool CHookManager::ProcessVoiceData(CLC_VoiceData *msg)
{ {
IClient *pClient = (IClient *)((intptr_t)(META_IFACEPTR(IClient)) - 4); IClient *pClient = (IClient *)((intptr_t)(META_IFACEPTR(IClient)) - sizeof(void *));
if (pClient == NULL) if (pClient == NULL)
{ {
return true; return true;

View File

@ -753,8 +753,8 @@ CEntityFactoryDictionary *GetEntityFactoryDictionary()
int32_t funcOffset = *(int32_t *)((intptr_t)addr + offset); int32_t funcOffset = *(int32_t *)((intptr_t)addr + offset);
// Get real address of function // Get real address of function
// Address of signature + offset of relative offset + sizeof(int32_t) offset + relative offset // Address of signature + offset of relative offset + pointer size + relative offset
addr = (void *)((intptr_t)addr + offset + 4 + funcOffset); addr = (void *)((intptr_t)addr + offset + sizeof(void *) + funcOffset);
} }
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0); pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0);

View File

@ -601,6 +601,15 @@ native bool CreateDirectory(const char[] path, int mode=FPERM_O_READ|FPERM_O_EXE
*/ */
native bool SetFilePermissions(const char[] path, int mode); native bool SetFilePermissions(const char[] path, int mode);
/**
* Retrieves a file or directories permissions.
*
* @param path Path to the file.
* @param mode Variable to store the permissions in.
* @return True on success, false otherwise.
*/
native bool GetFilePermissions(const char[] path, int &mode);
/** /**
* Returns a file timestamp as a unix timestamp. * Returns a file timestamp as a unix timestamp.
* *

View File

@ -95,7 +95,7 @@ native void SortStrings(char[][] array, int array_size, SortOrder order = Sort_A
* 0 if first is equal to second * 0 if first is equal to second
* 1 if first should go after second * 1 if first should go after second
*/ */
typedef SortFunc1D = function int (any elem1, any elem2, const any[] array, Handle hndl); typedef SortFunc1D = function int (int elem1, int elem2, const int[] array, Handle hndl);
/** /**
* Sorts a custom 1D array. You must pass in a comparison function. * Sorts a custom 1D array. You must pass in a comparison function.
@ -105,7 +105,7 @@ typedef SortFunc1D = function int (any elem1, any elem2, const any[] array, Hand
* @param sortfunc Sort function. * @param sortfunc Sort function.
* @param hndl Optional Handle to pass through the comparison calls. * @param hndl Optional Handle to pass through the comparison calls.
*/ */
native void SortCustom1D(any[] array, int array_size, SortFunc1D sortfunc, Handle hndl=INVALID_HANDLE); native void SortCustom1D(int[] array, int array_size, SortFunc1D sortfunc, Handle hndl=INVALID_HANDLE);
/** /**
* Sort comparison function for 2D array elements (sub-arrays). * Sort comparison function for 2D array elements (sub-arrays).
@ -121,7 +121,7 @@ native void SortCustom1D(any[] array, int array_size, SortFunc1D sortfunc, Handl
*/ */
typeset SortFunc2D typeset SortFunc2D
{ {
function int (any[] elem1, any[] elem2, const any[][] array, Handle hndl); function int (int[] elem1, int[] elem2, const int[][] array, Handle hndl);
function int (char[] elem1, char[] elem2, const char[][] array, Handle hndl); function int (char[] elem1, char[] elem2, const char[][] array, Handle hndl);
}; };

View File

@ -105,7 +105,7 @@ void Test_Sort1D() {
AssertArrayEq("SortCustom1D Integers Ascending", intArray, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, sizeof(intArray)); AssertArrayEq("SortCustom1D Integers Ascending", intArray, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, sizeof(intArray));
float floatArray[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}; float floatArray[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2};
SortCustom1D(floatArray, sizeof(floatArray), Custom1DSortFloat); SortCustom1D(view_as<any>(floatArray), sizeof(floatArray), Custom1DSortFloat);
AssertArrayEq("SortCustom1D Floats Ascending", floatArray, {0.4, 1.7, 2.1, 3.2, 4.8, 5.2, 6.3, 7.6, 8.2, 8.5}, sizeof(floatArray)); AssertArrayEq("SortCustom1D Floats Ascending", floatArray, {0.4, 1.7, 2.1, 3.2, 4.8, 5.2, 6.3, 7.6, 8.2, 8.5}, sizeof(floatArray));
} }

View File

@ -32,7 +32,7 @@
#ifndef _INCLUDE_SOURCEMOD_DETOURS_H_ #ifndef _INCLUDE_SOURCEMOD_DETOURS_H_
#define _INCLUDE_SOURCEMOD_DETOURS_H_ #define _INCLUDE_SOURCEMOD_DETOURS_H_
#include "../safetyhook/safetyhook.hpp" #include "safetyhook.hpp"
#include <smsdk_ext.h> #include <smsdk_ext.h>
#define DETOUR_MEMBER_CALL(name) (this->*name##_Actual) #define DETOUR_MEMBER_CALL(name) (this->*name##_Actual)

@ -1 +1 @@
Subproject commit e38cfe3cbf2047916e4a68017840bd325a8f7080 Subproject commit 285b4f853c0003023838140113e3ec066bd800c6

1
public/safetyhook Submodule

@ -0,0 +1 @@
Subproject commit 29d1c73cfae68f8cb7d297205d87579a23bd902a

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit 08d4d0c8b0a54d5778a643c6e16e1cd5b093bcc6 Subproject commit d59a51b5741823903ecbe8c014632ee1f8aad65d