Update CS:GO team score gamedata.
3 * =============================================================================
4 * SourceMod Regular Expressions Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include <sourcemod_version.h>
33 #include "extension.h"
34 #include <sh_string.h>
37 using namespace SourceHook;
41 * @brief Implement Regex extension code here.
44 RegexExtension g_RegexExtension; /**< Global singleton for extension's main interface */
46 SMEXT_LINK(&g_RegexExtension);
48 RegexHandler g_RegexHandler;
49 HandleType_t g_RegexHandle=0;
53 bool RegexExtension::SDK_OnLoad(char *error, size_t err_max, bool late)
55 g_pShareSys->AddNatives(myself,regex_natives);
56 g_RegexHandle = g_pHandleSys->CreateType("Regex", &g_RegexHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
60 void RegexExtension::SDK_OnUnload()
62 g_pHandleSys->RemoveType(g_RegexHandle, myself->GetIdentity());
66 const char *RegexExtension::GetExtensionVerString()
68 return SOURCEMOD_VERSION;
71 const char *RegexExtension::GetExtensionDateString()
73 return SOURCEMOD_BUILD_TIME;
76 static cell_t CompileRegex(IPluginContext *pCtx, const cell_t *params)
79 pCtx->LocalToString(params[1], ®ex);
81 RegEx *x = new RegEx();
83 if (x->Compile(regex, params[2]) == 0)
86 pCtx->LocalToPhysAddr(params[5], &eOff);
87 const char *err = x->mError;
88 *eOff = x->mErrorOffset;
89 pCtx->StringToLocal(params[3], params[4], err ? err:"unknown");
93 return g_pHandleSys->CreateHandle(g_RegexHandle, (void*)x, pCtx->GetIdentity(), myself->GetIdentity(), NULL);
97 static cell_t MatchRegex(IPluginContext *pCtx, const cell_t *params)
99 Handle_t hndl = static_cast<Handle_t>(params[1]);
103 sec.pIdentity = myself->GetIdentity();
107 if ((err=g_pHandleSys->ReadHandle(hndl, g_RegexHandle, &sec, (void **)&x)) != HandleError_None)
109 return pCtx->ThrowNativeError("Invalid file handle %x (error %d)", hndl, err);
114 pCtx->ThrowNativeError("Regex data not found\n");
120 pCtx->LocalToString(params[2], &str);
122 int e = x->Match(str);
126 /* there was a match error. move on. */
128 pCtx->LocalToPhysAddr(params[3], &res);
129 *res = x->mErrorOffset;
130 /* only clear the match results, since the regex object
131 may still be referenced later */
138 /* only clear the match results, since the regex object
139 may still be referenced later */
146 return x->mSubStrings;
150 static cell_t GetRegexSubString(IPluginContext *pCtx, const cell_t *params)
152 Handle_t hndl=static_cast<Handle_t>(params[1]);
156 sec.pIdentity=myself->GetIdentity();
160 if ((err=g_pHandleSys->ReadHandle(hndl, g_RegexHandle, &sec, (void **)&x)) != HandleError_None)
162 return pCtx->ThrowNativeError("Invalid file handle %x (error %d)", hndl, err);
167 pCtx->ThrowNativeError("Regex data not found\n");
171 static char buffer[4096];
172 const char *ret=x->GetSubstring(params[2], buffer, sizeof(buffer));
179 pCtx->StringToLocalUTF8(params[3], params[4], ret, NULL);
184 void RegexHandler::OnHandleDestroy(HandleType_t type, void *object)
186 RegEx *x = (RegEx *)object;
192 const sp_nativeinfo_t regex_natives[] =
194 {"GetRegexSubString", GetRegexSubString},
195 {"MatchRegex", MatchRegex},
196 {"CompileRegex", CompileRegex},