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 May 15, 2024
2 parents 5bc2158 + c5425de commit ef7eaeb
Show file tree
Hide file tree
Showing 39 changed files with 496 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
path: sourcemod

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: hl2sdk-mysql-mmsource
with:
Expand Down
1 change: 1 addition & 0 deletions bridge/include/IFileSystemBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class IFileSystemBridge
virtual char *ReadLine(char *pOutput, int maxChars, FileHandle_t file) = 0;
virtual bool EndOfFile(FileHandle_t file) = 0;
virtual bool FileExists(const char *pFileName, const char *pPathID = 0) = 0;
virtual unsigned int Size(FileHandle_t file) = 0;
virtual unsigned int Size(const char *pFileName, const char *pPathID = 0) = 0;
virtual int Read(void* pOutput, int size, FileHandle_t file) = 0;
virtual int Write(void const* pInput, int size, FileHandle_t file) = 0;
Expand Down
27 changes: 14 additions & 13 deletions configs/languages.cfg
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
"Languages"
{
"en" "English" // English
"ar" "Arabic" // Arabic
"pt" "Brazilian" // Brazilian Portuguese
"bg" "Bulgarian" // Bulgarian
"cze" "Czech" // Czech
"chi" "SChinese" // Chinese (Simplified)
"cze" "Czech" // Czech
"da" "Danish" // Danish
"nl" "Dutch" // Dutch
"de" "German" // German
"el" "Greek" // Greek
"en" "English" // English
"es" "Spanish" // Spanish
"fi" "Finnish" // Finnish
"fr" "French" // French
"de" "German" // German
"el" "Greek" // Greek
"he" "Hebrew" // Hebrew
"hu" "Hungarian" // Hungarian
"it" "Italian" // Italian
"jp" "Japanese" // Japanese
"ko" "KoreanA" // Korean
"ko" "Korean" // Korean
"las" "LatAm" // Latin American Spanish
"lv" "Latvian" // Latvian
"ko" "KoreanA" // Korean (https://bugs.alliedmods.net/show_bug.cgi?id=4667)
"las" "LatAm" // Latin American Spanish
"lt" "Lithuanian" // Lithuanian
"lv" "Latvian" // Latvian
"nl" "Dutch" // Dutch
"no" "Norwegian" // Norwegian
"pl" "Polish" // Polish
"pt" "Brazilian" // Brazilian Portuguese
"pt_p" "Portuguese" // Portuguese
"ro" "Romanian" // Romanian
"ru" "Russian" // Russian
"chi" "SChinese" // Chinese (Simplified)
"sk" "Slovak" // Slovak
"es" "Spanish" // Spanish
"sv" "Swedish" // Swedish
"zho" "TChinese" // Chinese (Traditional)
"th" "Thai" // Thai
"th" "Thai" // Thai
"tr" "Turkish" // Turkish
"ua" "Ukrainian" // Ukrainian
"vi" "Vietnamese" // Vietnamese
"zho" "TChinese" // Chinese (Traditional)

}
20 changes: 19 additions & 1 deletion core/HalfLife2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,26 @@ int CHalfLife2::ReferenceToIndex(cell_t entRef)

return hndl.GetEntryIndex();
}
else
{
CEntInfo *pInfo = LookupEntity(entRef);
if (!pInfo)
{
return INVALID_EHANDLE_INDEX;
}
IServerUnknown *pUnk = static_cast<IServerUnknown *>(pInfo->m_pEntity);
if (!pUnk)
{
return INVALID_EHANDLE_INDEX;
}
CBaseEntity *pEntity = pUnk->GetBaseEntity();
if (!pEntity)
{
return INVALID_EHANDLE_INDEX;
}

return entRef;
return entRef;
}
}

cell_t CHalfLife2::EntityToBCompatRef(CBaseEntity *pEntity)
Expand Down
15 changes: 13 additions & 2 deletions core/PlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ bool g_OnMapStarted = false;
IForward *PreAdminCheck = NULL;
IForward *PostAdminCheck = NULL;
IForward *PostAdminFilter = NULL;
IForward *ServerEnterHibernation = NULL;
IForward *ServerExitHibernation = NULL;

const unsigned int *g_NumPlayersToAuth = NULL;
int lifestate_offset = -1;
Expand Down Expand Up @@ -203,6 +205,8 @@ void PlayerManager::OnSourceModAllInitialized()
PreAdminCheck = forwardsys->CreateForward("OnClientPreAdminCheck", ET_Event, 1, p1);
PostAdminCheck = forwardsys->CreateForward("OnClientPostAdminCheck", ET_Ignore, 1, p1);
PostAdminFilter = forwardsys->CreateForward("OnClientPostAdminFilter", ET_Ignore, 1, p1);
ServerEnterHibernation = forwardsys->CreateForward("OnServerEnterHibernation", ET_Ignore, 0, NULL);
ServerExitHibernation = forwardsys->CreateForward("OnServerExitHibernation", ET_Ignore, 0, NULL);

m_bIsListenServer = !engine->IsDedicatedServer();
m_ListenClient = 0;
Expand Down Expand Up @@ -254,6 +258,8 @@ void PlayerManager::OnSourceModShutdown()
forwardsys->ReleaseForward(PreAdminCheck);
forwardsys->ReleaseForward(PostAdminCheck);
forwardsys->ReleaseForward(PostAdminFilter);
forwardsys->ReleaseForward(ServerEnterHibernation);
forwardsys->ReleaseForward(ServerExitHibernation);

delete [] m_Players;

Expand Down Expand Up @@ -646,7 +652,7 @@ void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername

int userId = engine->GetPlayerUserId(pEntity);
#if (SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_SDK2013 \
|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_NUCLEARDAWN || SOURCE_ENGINE == SE_LEFT4DEAD2 || SOURCE_ENGINE == SE_PVKII)
|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_NUCLEARDAWN || SOURCE_ENGINE == SE_PVKII)
static ConVar *tv_name = icvar->FindVar("tv_name");
#endif
#if SOURCE_ENGINE == SE_TF2
Expand Down Expand Up @@ -675,7 +681,7 @@ void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername
#elif SOURCE_ENGINE == SE_BLADE
|| strcmp(playername, "BBTV") == 0
#elif (SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_SDK2013 \
|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_NUCLEARDAWN || SOURCE_ENGINE == SE_LEFT4DEAD2 || SOURCE_ENGINE == SE_PVKII)
|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_NUCLEARDAWN || SOURCE_ENGINE == SE_PVKII)
|| (tv_name && strcmp(playername, tv_name->GetString()) == 0) || (tv_name && tv_name->GetString()[0] == 0 && strcmp(playername, "unnamed") == 0)
#else
|| strcmp(playername, "SourceTV") == 0
Expand Down Expand Up @@ -778,6 +784,11 @@ void PlayerManager::OnSourceModLevelEnd()

void PlayerManager::OnServerHibernationUpdate(bool bHibernating)
{
cell_t res;
if (bHibernating)
ServerEnterHibernation->Execute(&res);
else
ServerExitHibernation->Execute(&res);
/* If bots were added at map start, but not fully inited before hibernation, there will
* be no OnClientDisconnect for them, despite them getting booted right before this.
*/
Expand Down
21 changes: 19 additions & 2 deletions core/logic/smn_datapacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,19 @@ static cell_t smn_WritePackFunction(IPluginContext *pContext, const cell_t *para
pDataPack->RemoveItem();
}

pDataPack->PackFunction(params[2]);
cell_t funcid = params[2];
if (pContext->IsNullFunctionId(funcid))
{
pDataPack->PackFunction(0);
}
else if (funcid <= 0)
{
return pContext->ThrowNativeError("Invalid function id (%X)", funcid);
}
else
{
pDataPack->PackFunction(funcid);
}

return 1;
}
Expand Down Expand Up @@ -365,7 +377,12 @@ static cell_t smn_ReadPackFunction(IPluginContext *pContext, const cell_t *param
return pContext->ThrowNativeError("Invalid data pack type (got %d / expected %d).", pDataPack->GetCurrentType(), CDataPackType::Function);
}

return pDataPack->ReadFunction();
cell_t funcid = pDataPack->ReadFunction();
if (!funcid)
{
return pContext->GetNullFunctionValue();
}
return funcid;
}

static cell_t smn_ReadPackCellArray(IPluginContext *pContext, const cell_t *params)
Expand Down
29 changes: 28 additions & 1 deletion core/logic/smn_fakenatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,33 @@ static cell_t SetNativeArray(IPluginContext *pContext, const cell_t *params)
return SP_ERROR_NONE;
}

static cell_t GetNativeFunction(IPluginContext *pContext, const cell_t *params)
{
if (!s_curnative || (s_curnative->ctx != pContext))
{
return pContext->ThrowNativeError("Not called from inside a native function");
}

cell_t param = params[1];
if (param < 1 || param > s_curparams[0])
{
return pContext->ThrowNativeErrorEx(SP_ERROR_PARAM, "Invalid parameter number: %d", param);
}

cell_t funcid = s_curparams[param];
if (s_curcaller->IsNullFunctionId(funcid))
{
// see alliedmodders/sourcepawn#912, alliedmodders/sourcemod#2068
// convert null function to receiver's expected value so equality checks against INVALID_FUNCTION pass
return pContext->GetNullFunctionValue();
}
else if (funcid <= 0)
{
return pContext->ThrowNativeError("Invalid function id (%X)", funcid);
}
return funcid;
}

static cell_t FormatNativeString(IPluginContext *pContext, const cell_t *params)
{
if (!s_curnative || (s_curnative->ctx != pContext))
Expand Down Expand Up @@ -483,7 +510,7 @@ REGISTER_NATIVES(nativeNatives)
{"GetNativeArray", GetNativeArray},
{"GetNativeCell", GetNativeCell},
{"GetNativeCellRef", GetNativeCellRef},
{"GetNativeFunction", GetNativeCell},
{"GetNativeFunction", GetNativeFunction},
{"GetNativeString", GetNativeString},
{"GetNativeStringLength", GetNativeStringLength},
{"FormatNativeString", FormatNativeString},
Expand Down
41 changes: 40 additions & 1 deletion core/logic/smn_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class FileObject
public:
virtual ~FileObject()
{}
virtual size_t Size() = 0;
virtual size_t Read(void *pOut, int size) = 0;
virtual char *ReadLine(char *pOut, int size) = 0;
virtual size_t Write(const void *pData, int size) = 0;
Expand Down Expand Up @@ -119,6 +120,10 @@ class ValveFile : public FileObject
return true;
}

size_t Size() override {
return (size_t)bridge->filesystem->Size(handle_);
}

size_t Read(void *pOut, int size) override {
return (size_t)bridge->filesystem->Read(pOut, size, handle_);
}
Expand Down Expand Up @@ -183,6 +188,30 @@ class SystemFile : public FileObject
return unlink(path) == 0;
}

size_t Size() override {
#ifdef PLATFORM_WINDOWS
struct _stat s;
int fd = _fileno(fp_);
if (fd == -1)
return -1;
if (_fstat(fd, &s) != 0)
return -1;
if (s.st_mode & S_IFREG)
return static_cast<size_t>(s.st_size);
return -1;
#elif defined PLATFORM_POSIX
struct stat s;
int fd = fileno(fp_);
if (fd == -1)
return -1;
if (fstat(fd, &s) != 0)
return -1;
if (S_ISREG(s.st_mode))
return static_cast<size_t>(s.st_size);
return -1;
#endif
}

size_t Read(void *pOut, int size) override {
return fread(pOut, 1, size, fp_);
}
Expand Down Expand Up @@ -610,7 +639,7 @@ static cell_t sm_RenameFile(IPluginContext *pContext, const cell_t *params)
g_pSM->BuildPath(Path_Game, old_realpath, sizeof(old_realpath), "%s", oldpath);

#ifdef PLATFORM_WINDOWS
return (MoveFileA(old_realpath, new_realpath)) ? 1 : 0;
return (MoveFileExA(old_realpath, new_realpath, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) ? 1 : 0;
#elif defined PLATFORM_POSIX
return (rename(old_realpath, new_realpath)) ? 0 : 1;
#endif
Expand Down Expand Up @@ -1125,6 +1154,15 @@ static cell_t sm_RemoveGameLogHook(IPluginContext *pContext, const cell_t *param
return 1;
}

static cell_t File_Size(IPluginContext *pContext, const cell_t *params)
{
OpenHandle<FileObject> file(pContext, params[1], g_FileType);
if (!file.Ok())
return -1;

return file->Size();
}

template <typename T>
static cell_t File_ReadTyped(IPluginContext *pContext, const cell_t *params)
{
Expand Down Expand Up @@ -1197,6 +1235,7 @@ REGISTER_NATIVES(filesystem)
{"File.Seek", sm_FileSeek},
{"File.Flush", sm_FlushFile},
{"File.Position.get", sm_FilePosition},
{"File.Size", File_Size},
{"File.ReadInt8", File_ReadTyped<int8_t>},
{"File.ReadUint8", File_ReadTyped<uint8_t>},
{"File.ReadInt16", File_ReadTyped<int16_t>},
Expand Down
30 changes: 21 additions & 9 deletions core/logic/smn_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,15 @@ static cell_t sm_AddToForward(IPluginContext *pContext, const cell_t *params)
}
}

IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[3]);

cell_t funcid = params[3];
if (funcid <= 0)
{
return pContext->ThrowNativeError("Invalid function id (%X)", funcid);
}
IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(funcid);
if (!pFunction)
{
return pContext->ThrowNativeError("Invalid function id (%X)", params[3]);
return pContext->ThrowNativeError("Invalid function id (%X)", funcid);
}

return pForward->AddFunction(pFunction);
Expand Down Expand Up @@ -265,11 +269,15 @@ static cell_t sm_RemoveFromForward(IPluginContext *pContext, const cell_t *param
}
}

IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[3]);

cell_t funcid = params[3];
if (funcid <= 0)
{
return pContext->ThrowNativeError("Invalid function id (%X)", funcid);
}
IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(funcid);
if (!pFunction)
{
return pContext->ThrowNativeError("Invalid function id (%X)", params[3]);
return pContext->ThrowNativeError("Invalid function id (%X)", funcid);
}

return pForward->RemoveFunction(pFunction);
Expand Down Expand Up @@ -327,11 +335,15 @@ static cell_t sm_CallStartFunction(IPluginContext *pContext, const cell_t *param
}
}

s_pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[2]);

cell_t funcid = params[2];
if (funcid <= 0)
{
return pContext->ThrowNativeError("Invalid function id (%X)", funcid);
}
s_pFunction = pPlugin->GetBaseContext()->GetFunctionById(funcid);
if (!s_pFunction)
{
return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
return pContext->ThrowNativeError("Invalid function id (%X)", funcid);
}

s_pCallable = static_cast<ICallable *>(s_pFunction);
Expand Down
4 changes: 4 additions & 0 deletions core/logic_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class VFileSystem_Logic : public IFileSystemBridge
{
return filesystem->FileExists(pFileName, pPathID);
}
unsigned int Size(FileHandle_t file) override
{
return filesystem->Size(file);
}
unsigned int Size(const char *pFileName, const char *pPathID = 0) override
{
return filesystem->Size(pFileName, pPathID);
Expand Down
Loading

0 comments on commit ef7eaeb

Please sign in to comment.