Fixed CPlayer init, it was called too early.
nothing important on the logger
1 #include "sm_platform.h"
4 #include "sm_globals.h"
5 #include "sm_stringutil.h"
7 using namespace SourcePawn;
9 inline const char *_strstr(const char *str, const char *substr)
11 #ifdef PLATFORM_WINDOWS
12 return strstr(str, substr);
14 return (const char *)strstr(str, substr);
18 /*********************************************
20 * STRING MANIPULATION NATIVE IMPLEMENTATIONS *
22 *********************************************/
24 static cell_t sm_strlen(IPluginContext *pCtx, const cell_t *params)
27 pCtx->LocalToString(params[1], &str);
32 static cell_t sm_contain(IPluginContext *pCtx, const cell_t *params)
34 typedef const char *(*STRSEARCH)(const char *, const char *);
38 pCtx->LocalToString(params[1], &str);
39 pCtx->LocalToString(params[2], &substr);
41 func = (params[3]) ? _strstr : stristr;
42 const char *pos = func(str, substr);
51 static cell_t sm_strcmp(IPluginContext *pCtx, const cell_t *params)
53 typedef int (*STRCOMPARE)(const char *, const char *);
57 pCtx->LocalToString(params[1], &str1);
58 pCtx->LocalToString(params[2], &str2);
60 func = (params[3]) ? strcmp : stricmp;
62 return (func(str1, str2));
65 static cell_t sm_strcopy(IPluginContext *pCtx, const cell_t *params)
69 pCtx->LocalToString(params[1], &dest);
70 pCtx->LocalToString(params[3], &src);
72 return strncopy(dest, src, params[2]);
75 static cell_t sm_strconvint(IPluginContext *pCtx, const cell_t *params)
78 pCtx->LocalToString(params[1], &str);
80 return static_cast<cell_t>(strtol(str, &dummy, params[2]));
83 static cell_t sm_numtostr(IPluginContext *pCtx, const cell_t *params)
86 pCtx->LocalToString(params[2], &str);
88 return snprintf(str, params[3], "%d", params[1]);
91 static cell_t sm_strtofloat(IPluginContext *pCtx, const cell_t *params)
94 pCtx->LocalToString(params[1], &str);
96 float val = (float)strtod(str, &dummy);
101 static cell_t sm_floattostr(IPluginContext *pCtx, const cell_t *params)
104 pCtx->LocalToString(params[2], &str);
106 return snprintf(str, params[3], "%f", sp_ctof(params[1]));
109 static cell_t sm_formatex(IPluginContext *pCtx, const cell_t *params)
115 pCtx->LocalToString(params[1], &buf);
116 pCtx->LocalToString(params[3], &fmt);
117 res = atcprintf(buf, static_cast<size_t>(params[2]), fmt, pCtx, params, &arg);
119 return static_cast<cell_t>(res);
122 static char g_formatbuf[2048];
123 static cell_t sm_format(IPluginContext *pCtx, const cell_t *params)
125 char *buf, *fmt, *destbuf;
126 cell_t start_addr, end_addr, maxparam;
131 pCtx->LocalToString(params[1], &destbuf);
132 pCtx->LocalToString(params[3], &fmt);
134 maxlen = static_cast<size_t>(params[2]);
135 start_addr = params[1];
136 end_addr = params[1] + maxlen;
137 maxparam = params[0];
139 for (cell_t i=3; i<=maxparam; i++)
141 if ((params[i] >= start_addr) && (params[i] <= end_addr))
147 buf = (copy) ? g_formatbuf : destbuf;
148 res = atcprintf(buf, maxlen, fmt, pCtx, params, &arg);
152 memcpy(destbuf, g_formatbuf, res+1);
155 return static_cast<cell_t>(res);
158 REGISTER_NATIVES(basicstrings)
160 {"strlen", sm_strlen},
161 {"StrContains", sm_contain},
162 {"StrCompare", sm_strcmp},
163 {"StrCopy", sm_strcopy},
164 {"StringToInt", sm_strconvint},
165 {"IntToString", sm_numtostr},
166 {"StringToFloat", sm_strtofloat},
167 {"FloatToString", sm_floattostr},
168 {"Format", sm_format},
169 {"FormatEx", sm_formatex},