ds@1114: /** ds@1114: * vim: set ts=4 : ds@1330: * ============================================================================= dvander@1233: * SourceMod SDKTools Extension ds@1947: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1330: * ============================================================================= ds@1114: * ds@1330: * This program is free software; you can redistribute it and/or modify it under ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the ds@1330: * Free Software Foundation. dvander@1233: * ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1330: * details. dvander@1233: * ds@1330: * You should have received a copy of the GNU General Public License along with ds@1330: * this program. If not, see . dvander@1233: * ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1330: * this exception to all derivative works. AlliedModders LLC defines further ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1330: * or . ds@1114: * ds@1114: * Version: $Id$ ds@1114: */ ds@1114: ds@1114: #include "extension.h" ds@1114: ds@1114: static cell_t LockStringTables(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: bool lock = params[1] ? true : false; ds@1114: ds@1114: return engine->LockNetworkStringTables(lock) ? 1 : 0; ds@1114: } ds@1114: ds@1114: static cell_t FindStringTable(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: char *name; ds@1114: pContext->LocalToString(params[1], &name); ds@1114: ds@1114: INetworkStringTable *pTable = netstringtables->FindTable(name); ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return INVALID_STRING_TABLE; ds@1114: } ds@1114: ds@1114: return pTable->GetTableId(); ds@1114: } ds@1114: ds@1114: static cell_t GetNumStringTables(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: return netstringtables->GetNumTables(); ds@1114: } ds@1114: ds@1114: static cell_t GetStringTableNumStrings(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: return pTable->GetNumStrings(); ds@1114: } ds@1114: ds@1114: static cell_t GetStringTableMaxStrings(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: return pTable->GetMaxStrings(); ds@1114: } ds@1114: ds@1114: static cell_t GetStringTableName(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: size_t numBytes; ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: pContext->StringToLocalUTF8(params[2], params[3], pTable->GetTableName(), &numBytes); ds@1114: ds@1114: return numBytes; ds@1114: } ds@1114: ds@1114: static cell_t FindStringIndex(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: char *str; ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: pContext->LocalToString(params[2], &str); ds@1114: ds@1114: return pTable->FindStringIndex(str); ds@1114: } ds@1114: ds@1114: static cell_t ReadStringTable(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: int stringidx; ds@1114: const char *value; ds@1114: size_t numBytes; ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: stringidx = params[2]; ds@1114: value = pTable->GetString(stringidx); ds@1114: ds@1114: if (!value) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName()); ds@1114: } ds@1114: ds@1114: pContext->StringToLocalUTF8(params[3], params[4], value, &numBytes); ds@1114: ds@1114: return numBytes; ds@1114: } ds@1114: ds@1114: static cell_t GetStringTableDataLength(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: int stringidx; ds@1114: const void *userdata; ds@1114: int datalen; ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: stringidx = params[2]; ds@1114: if (stringidx < 0 || stringidx >= pTable->GetNumStrings()) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName()); ds@1114: } ds@1114: ds@1114: userdata = pTable->GetStringUserData(stringidx, &datalen); ds@1114: if (!userdata) ds@1114: { ds@1114: datalen = 0; ds@1114: } ds@1114: ds@1114: return datalen; ds@1114: } ds@1114: ds@1114: static cell_t GetStringTableData(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: int stringidx; ds@1114: const char *userdata; ds@1114: int datalen; ds@1114: size_t numBytes; ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: stringidx = params[2]; ds@1114: if (stringidx < 0 || stringidx >= pTable->GetNumStrings()) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName()); ds@1114: } ds@1114: ds@1114: userdata = (const char *)pTable->GetStringUserData(stringidx, &datalen); ds@1114: if (!userdata) ds@1114: { ds@1114: userdata = ""; ds@1114: } ds@1114: ds@1114: pContext->StringToLocalUTF8(params[3], params[4], userdata, &numBytes); ds@1114: ds@1114: return numBytes; ds@1114: } ds@1114: ds@1114: static cell_t SetStringTableData(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: int stringidx; ds@1114: char *userdata; ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: stringidx = params[2]; ds@1114: if (stringidx < 0 || stringidx >= pTable->GetNumStrings()) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName()); ds@1114: } ds@1114: ds@1114: pContext->LocalToString(params[3], &userdata); ds@1114: pTable->SetStringUserData(stringidx, params[4], userdata); ds@1114: ds@1114: return 1; ds@1114: } ds@1114: ds@1114: static cell_t AddToStringTable(IPluginContext *pContext, const cell_t *params) ds@1114: { ds@1114: TABLEID idx = static_cast(params[1]); ds@1114: INetworkStringTable *pTable = netstringtables->GetTable(idx); ds@1114: char *str, *userdata; ds@1114: ds@1114: if (!pTable) ds@1114: { ds@1114: return pContext->ThrowNativeError("Invalid string table index %d", idx); ds@1114: } ds@1114: ds@1114: pContext->LocalToString(params[2], &str); ds@1114: pContext->LocalToString(params[3], &userdata); ds@1114: faluco@1560: #if defined ORANGEBOX_BUILD faluco@1560: pTable->AddString(true, str, params[4], userdata); faluco@1560: #else ds@1114: pTable->AddString(str, params[4], userdata); faluco@1560: #endif ds@1114: ds@1114: return 1; ds@1114: } ds@1114: ds@1114: sp_nativeinfo_t g_StringTableNatives[] = ds@1114: { ds@1114: {"LockStringTables", LockStringTables}, ds@1114: {"FindStringTable", FindStringTable}, ds@1114: {"GetNumStringTables", GetNumStringTables}, ds@1114: {"GetStringTableNumStrings", GetStringTableNumStrings}, ds@1114: {"GetStringTableMaxStrings", GetStringTableMaxStrings}, ds@1114: {"GetStringTableName", GetStringTableName}, ds@1114: {"FindStringIndex", FindStringIndex}, ds@1114: {"ReadStringTable", ReadStringTable}, ds@1114: {"GetStringTableDataLength", GetStringTableDataLength}, ds@1114: {"GetStringTableData", GetStringTableData}, ds@1114: {"SetStringTableData", SetStringTableData}, ds@1114: {"AddToStringTable", AddToStringTable}, ds@1114: {NULL, NULL}, ds@1114: };