Partly addressed amb197 - added network string table natives to SDKTools
(Wow, I don't like this code) --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401120
This commit is contained in:
@@ -35,10 +35,11 @@
|
||||
SDKTools g_SdkTools; /**< Global singleton for extension's main interface */
|
||||
IServerGameEnts *gameents = NULL;
|
||||
IEngineTrace *enginetrace = NULL;
|
||||
IEngineSound *engsound = NULL;
|
||||
INetworkStringTableContainer *netstringtables = NULL;
|
||||
IBinTools *g_pBinTools = NULL;
|
||||
IGameConfig *g_pGameConf = NULL;
|
||||
IGameHelpers *g_pGameHelpers = NULL;
|
||||
IEngineSound *engsound = NULL;
|
||||
HandleType_t g_CallHandle = 0;
|
||||
HandleType_t g_TraceHandle = 0;
|
||||
|
||||
@@ -47,6 +48,7 @@ SMEXT_LINK(&g_SdkTools);
|
||||
extern sp_nativeinfo_t g_CallNatives[];
|
||||
extern sp_nativeinfo_t g_TENatives[];
|
||||
extern sp_nativeinfo_t g_TRNatives[];
|
||||
extern sp_nativeinfo_t g_StringTableNatives[];
|
||||
|
||||
bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
{
|
||||
@@ -56,6 +58,7 @@ bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
sharesys->AddNatives(myself, g_TENatives);
|
||||
sharesys->AddNatives(myself, g_SoundNatives);
|
||||
sharesys->AddNatives(myself, g_TRNatives);
|
||||
sharesys->AddNatives(myself, g_StringTableNatives);
|
||||
|
||||
SM_GET_IFACE(GAMEHELPERS, g_pGameHelpers);
|
||||
|
||||
@@ -107,6 +110,7 @@ bool SDKTools::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool
|
||||
GET_V_IFACE_ANY(serverFactory, gameents, IServerGameEnts, INTERFACEVERSION_SERVERGAMEENTS);
|
||||
GET_V_IFACE_ANY(engineFactory, engsound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
|
||||
GET_V_IFACE_ANY(engineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER);
|
||||
GET_V_IFACE_ANY(engineFactory, netstringtables, INetworkStringTableContainer, INTERFACENAME_NETWORKSTRINGTABLESERVER);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,12 +66,16 @@ public: //IConCommandBaseAccessor
|
||||
bool RegisterConCommandBase(ConCommandBase *pVar);
|
||||
};
|
||||
|
||||
/* Interfaces from engine or gamedll */
|
||||
extern IServerGameEnts *gameents;
|
||||
extern IEngineTrace *enginetrace;
|
||||
extern IEngineSound *engsound;
|
||||
extern INetworkStringTableContainer *netstringtables;
|
||||
/* Interfaces from SourceMod */
|
||||
extern IBinTools *g_pBinTools;
|
||||
extern IGameConfig *g_pGameConf;
|
||||
extern IGameHelpers *g_pGameHelpers;
|
||||
extern IEngineSound *engsound;
|
||||
/* Handle types */
|
||||
extern HandleType_t g_CallHandle;
|
||||
extern HandleType_t g_TraceHandle;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Version="8.00"
|
||||
Name="sdktools"
|
||||
ProjectGUID="{7A740927-C751-4312-BF9D-6367F8C508F8}"
|
||||
RootNamespace="sdk"
|
||||
@@ -223,6 +223,10 @@
|
||||
RelativePath="..\vsound.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\vstringtable.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* ===============================================================
|
||||
* SourceMod SDK Tools Extension
|
||||
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
|
||||
* ===============================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include "extension.h"
|
||||
#include "CellRecipientFilter.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* ===============================================================
|
||||
* SourceMod SDK Tools Extension
|
||||
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
|
||||
* ===============================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include "extension.h"
|
||||
|
||||
static cell_t LockStringTables(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
bool lock = params[1] ? true : false;
|
||||
|
||||
return engine->LockNetworkStringTables(lock) ? 1 : 0;
|
||||
}
|
||||
|
||||
static cell_t FindStringTable(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *name;
|
||||
pContext->LocalToString(params[1], &name);
|
||||
|
||||
INetworkStringTable *pTable = netstringtables->FindTable(name);
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return INVALID_STRING_TABLE;
|
||||
}
|
||||
|
||||
return pTable->GetTableId();
|
||||
}
|
||||
|
||||
static cell_t GetNumStringTables(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return netstringtables->GetNumTables();
|
||||
}
|
||||
|
||||
static cell_t GetStringTableNumStrings(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
return pTable->GetNumStrings();
|
||||
}
|
||||
|
||||
static cell_t GetStringTableMaxStrings(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
return pTable->GetMaxStrings();
|
||||
}
|
||||
|
||||
static cell_t GetStringTableName(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
size_t numBytes;
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
pContext->StringToLocalUTF8(params[2], params[3], pTable->GetTableName(), &numBytes);
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
static cell_t FindStringIndex(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
char *str;
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
pContext->LocalToString(params[2], &str);
|
||||
|
||||
return pTable->FindStringIndex(str);
|
||||
}
|
||||
|
||||
static cell_t ReadStringTable(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
int stringidx;
|
||||
const char *value;
|
||||
size_t numBytes;
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
stringidx = params[2];
|
||||
value = pTable->GetString(stringidx);
|
||||
|
||||
if (!value)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName());
|
||||
}
|
||||
|
||||
pContext->StringToLocalUTF8(params[3], params[4], value, &numBytes);
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
static cell_t GetStringTableDataLength(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
int stringidx;
|
||||
const void *userdata;
|
||||
int datalen;
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
stringidx = params[2];
|
||||
if (stringidx < 0 || stringidx >= pTable->GetNumStrings())
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName());
|
||||
}
|
||||
|
||||
userdata = pTable->GetStringUserData(stringidx, &datalen);
|
||||
if (!userdata)
|
||||
{
|
||||
datalen = 0;
|
||||
}
|
||||
|
||||
return datalen;
|
||||
}
|
||||
|
||||
static cell_t GetStringTableData(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
int stringidx;
|
||||
const char *userdata;
|
||||
int datalen;
|
||||
size_t numBytes;
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
stringidx = params[2];
|
||||
if (stringidx < 0 || stringidx >= pTable->GetNumStrings())
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName());
|
||||
}
|
||||
|
||||
userdata = (const char *)pTable->GetStringUserData(stringidx, &datalen);
|
||||
if (!userdata)
|
||||
{
|
||||
userdata = "";
|
||||
}
|
||||
|
||||
pContext->StringToLocalUTF8(params[3], params[4], userdata, &numBytes);
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
CON_COMMAND(sm_lockstate, "Lock state")
|
||||
{
|
||||
bool save = engine->LockNetworkStringTables(false);
|
||||
Msg("save: %d\n", save);
|
||||
engine->LockNetworkStringTables(save);
|
||||
}
|
||||
|
||||
static cell_t SetStringTableData(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
int stringidx;
|
||||
char *userdata;
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
stringidx = params[2];
|
||||
if (stringidx < 0 || stringidx >= pTable->GetNumStrings())
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName());
|
||||
}
|
||||
|
||||
pContext->LocalToString(params[3], &userdata);
|
||||
pTable->SetStringUserData(stringidx, params[4], userdata);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t AddToStringTable(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
TABLEID idx = static_cast<TABLEID>(params[1]);
|
||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||
char *str, *userdata;
|
||||
|
||||
if (!pTable)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid string table index %d", idx);
|
||||
}
|
||||
|
||||
pContext->LocalToString(params[2], &str);
|
||||
pContext->LocalToString(params[3], &userdata);
|
||||
|
||||
pTable->AddString(str, params[4], userdata);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sp_nativeinfo_t g_StringTableNatives[] =
|
||||
{
|
||||
{"LockStringTables", LockStringTables},
|
||||
{"FindStringTable", FindStringTable},
|
||||
{"GetNumStringTables", GetNumStringTables},
|
||||
{"GetStringTableNumStrings", GetStringTableNumStrings},
|
||||
{"GetStringTableMaxStrings", GetStringTableMaxStrings},
|
||||
{"GetStringTableName", GetStringTableName},
|
||||
{"FindStringIndex", FindStringIndex},
|
||||
{"ReadStringTable", ReadStringTable},
|
||||
{"GetStringTableDataLength", GetStringTableDataLength},
|
||||
{"GetStringTableData", GetStringTableData},
|
||||
{"SetStringTableData", SetStringTableData},
|
||||
{"AddToStringTable", AddToStringTable},
|
||||
{NULL, NULL},
|
||||
};
|
||||
Reference in New Issue
Block a user