More AMTL conversion - 🔥 CString and CVector
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "amxmodx.h"
|
||||
#include "osdep.h" // sleep, etc
|
||||
#include "CFile.h"
|
||||
#include "amxxfile.h"
|
||||
#include "amxdbg.h"
|
||||
#include "newmenus.h"
|
||||
@@ -501,12 +500,12 @@ int set_amxnatives(AMX* amx, char error[128])
|
||||
for (CList<CModule, const char *>::iterator a = g_modules.begin(); a ; ++a)
|
||||
{
|
||||
cm = &(*a);
|
||||
for (size_t i=0; i<cm->m_Natives.size(); i++)
|
||||
for (size_t i=0; i<cm->m_Natives.length(); i++)
|
||||
{
|
||||
amx_Register(amx, cm->m_Natives[i], -1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cm->m_NewNatives.size(); i++)
|
||||
for (size_t i = 0; i < cm->m_NewNatives.length(); i++)
|
||||
{
|
||||
amx_Register(amx, cm->m_NewNatives[i], -1);
|
||||
}
|
||||
@@ -663,14 +662,14 @@ const char* get_amxscriptname(AMX* amx)
|
||||
|
||||
void get_modname(char* buffer)
|
||||
{
|
||||
strcpy(buffer, g_mod_name.c_str());
|
||||
strcpy(buffer, g_mod_name.chars());
|
||||
}
|
||||
|
||||
char* build_pathname(const char *fmt, ...)
|
||||
{
|
||||
static char string[256];
|
||||
int b;
|
||||
int a = b = UTIL_Format(string, 255, "%s%c", g_mod_name.c_str(), PATH_SEP_CHAR);
|
||||
int a = b = UTIL_Format(string, 255, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR);
|
||||
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
@@ -694,7 +693,7 @@ char* build_pathname(const char *fmt, ...)
|
||||
|
||||
char *build_pathname_r(char *buffer, size_t maxlen, const char *fmt, ...)
|
||||
{
|
||||
UTIL_Format(buffer, maxlen, "%s%c", g_mod_name.c_str(), PATH_SEP_CHAR);
|
||||
UTIL_Format(buffer, maxlen, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR);
|
||||
|
||||
size_t len = strlen(buffer);
|
||||
char *ptr = buffer + len;
|
||||
@@ -740,17 +739,17 @@ char* build_pathname_addons(const char *fmt, ...)
|
||||
return string;
|
||||
}
|
||||
|
||||
bool ConvertModuleName(const char *pathString, String &path)
|
||||
bool ConvertModuleName(const char *pathString, char *path)
|
||||
{
|
||||
String local;
|
||||
char local[PLATFORM_MAX_PATH];
|
||||
|
||||
local.assign(pathString);
|
||||
char *tmpname = const_cast<char *>(local.c_str());
|
||||
strncopy(local, pathString, sizeof(local));
|
||||
char *tmpname = local;
|
||||
char *orig_path = tmpname;
|
||||
|
||||
path.clear();
|
||||
*path = '\0';
|
||||
|
||||
size_t len = local.size();
|
||||
size_t len = strlen(local);
|
||||
if (!len)
|
||||
return false;
|
||||
|
||||
@@ -817,34 +816,24 @@ bool ConvertModuleName(const char *pathString, String &path)
|
||||
*ptr = '\0';
|
||||
}
|
||||
|
||||
path.assign(orig_path);
|
||||
path.append(PATH_SEP_CHAR);
|
||||
path.append(tmpname);
|
||||
path.append("_amxx");
|
||||
#if defined(__linux__)
|
||||
#if defined AMD64 || PAWN_CELL_SIZE==64
|
||||
path.append("_amd64");
|
||||
#else
|
||||
path.append("_i");
|
||||
path.append(iDigit);
|
||||
path.append("86");
|
||||
#endif
|
||||
#endif
|
||||
#if defined WIN32
|
||||
path.append(".dll");
|
||||
#elif defined __linux__
|
||||
path.append(".so");
|
||||
#elif defined __APPLE__
|
||||
path.append(".dylib");
|
||||
size_t length = UTIL_Format(path, PLATFORM_MAX_PATH, "%s%c%s_amxx", orig_path, PATH_SEP_CHAR, tmpname);
|
||||
|
||||
#if defined PLATFORM_LINUX
|
||||
# if defined AMD64 || PAWN_CELL_SIZE == 64
|
||||
length += strncopy(path + length, "_amd64", PLATFORM_MAX_PATH - length);
|
||||
# else
|
||||
length += UTIL_Format(path + length, PLATFORM_MAX_PATH - length, "_i%d86", iDigit);
|
||||
# endif
|
||||
#endif
|
||||
UTIL_Format(path + length, PLATFORM_MAX_PATH - length, ".%s", PLATFORM_LIB_EXT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool noFileBail)
|
||||
{
|
||||
char pathString[512];
|
||||
String path;
|
||||
char pathString[PLATFORM_MAX_PATH];
|
||||
char path[PLATFORM_MAX_PATH];
|
||||
|
||||
build_pathname_r(
|
||||
pathString,
|
||||
@@ -858,23 +847,23 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no
|
||||
if (!ConvertModuleName(pathString, path))
|
||||
return false;
|
||||
} else {
|
||||
path.assign(pathString);
|
||||
strncopy(path, pathString, sizeof(path));
|
||||
}
|
||||
|
||||
if (noFileBail)
|
||||
{
|
||||
FILE *fp = fopen(path.c_str(), "rb");
|
||||
FILE *fp = fopen(path, "rb");
|
||||
if (!fp)
|
||||
return false;
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
CList<CModule, const char *>::iterator a = g_modules.find(path.c_str());
|
||||
CList<CModule, const char *>::iterator a = g_modules.find(path);
|
||||
|
||||
if (a)
|
||||
return false;
|
||||
|
||||
CModule* cc = new CModule(path.c_str());
|
||||
CModule* cc = new CModule(path);
|
||||
|
||||
cc->queryModule();
|
||||
|
||||
@@ -883,31 +872,31 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no
|
||||
switch (cc->getStatusValue())
|
||||
{
|
||||
case MODULE_BADLOAD:
|
||||
report_error(1, "[AMXX] Module is not a valid library (file \"%s\")", path.c_str());
|
||||
report_error(1, "[AMXX] Module is not a valid library (file \"%s\")", path);
|
||||
break;
|
||||
case MODULE_NOINFO:
|
||||
report_error(1, "[AMXX] Couldn't find info about module (file \"%s\")", path.c_str());
|
||||
report_error(1, "[AMXX] Couldn't find info about module (file \"%s\")", path);
|
||||
break;
|
||||
case MODULE_NOQUERY:
|
||||
report_error(1, "[AMXX] Couldn't find \"AMX_Query\" or \"AMXX_Query\" (file \"%s\")", path.c_str());
|
||||
report_error(1, "[AMXX] Couldn't find \"AMX_Query\" or \"AMXX_Query\" (file \"%s\")", path);
|
||||
break;
|
||||
case MODULE_NOATTACH:
|
||||
report_error(1, "[AMXX] Couldn't find \"%s\" (file \"%s\")", cc->isAmxx() ? "AMXX_Attach" : "AMX_Attach", path.c_str());
|
||||
report_error(1, "[AMXX] Couldn't find \"%s\" (file \"%s\")", cc->isAmxx() ? "AMXX_Attach" : "AMX_Attach", path);
|
||||
break;
|
||||
case MODULE_OLD:
|
||||
report_error(1, "[AMXX] Module has a different interface version (file \"%s\")", path.c_str());
|
||||
report_error(1, "[AMXX] Module has a different interface version (file \"%s\")", path);
|
||||
break;
|
||||
case MODULE_NEWER:
|
||||
report_error(1, "[AMXX] Module has a newer interface version (file \"%s\"). Please download a new amxmodx.", path.c_str());
|
||||
report_error(1, "[AMXX] Module has a newer interface version (file \"%s\"). Please download a new amxmodx.", path);
|
||||
break;
|
||||
case MODULE_INTERROR:
|
||||
report_error(1, "[AMXX] Internal error during module load (file \"%s\")", path.c_str());
|
||||
report_error(1, "[AMXX] Internal error during module load (file \"%s\")", path);
|
||||
break;
|
||||
case MODULE_NOT64BIT:
|
||||
report_error(1, "[AMXX] Module \"%s\" is not 64 bit compatible.", path.c_str());
|
||||
report_error(1, "[AMXX] Module \"%s\" is not 64 bit compatible.", path);
|
||||
break;
|
||||
case MODULE_BADGAME:
|
||||
report_error(1, "[AMXX] Module \"%s\" cannot load on game \"%s\"", path.c_str(), g_mod_name.c_str());
|
||||
report_error(1, "[AMXX] Module \"%s\" cannot load on game \"%s\"", path, g_mod_name.chars());
|
||||
break;
|
||||
default:
|
||||
error = false;
|
||||
@@ -928,7 +917,7 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no
|
||||
get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"),
|
||||
shortname);
|
||||
ConvertModuleName(mmpathname, path);
|
||||
cc->attachMetamod(path.c_str(), now);
|
||||
cc->attachMetamod(path, now);
|
||||
}
|
||||
|
||||
bool retVal = cc->attachModule();
|
||||
@@ -965,35 +954,37 @@ int loadModules(const char* filename, PLUG_LOADTIME now)
|
||||
return 0;
|
||||
}
|
||||
|
||||
String line;
|
||||
char line[256];
|
||||
char moduleName[256];
|
||||
char buffer[255];
|
||||
int loaded = 0;
|
||||
|
||||
String path;
|
||||
|
||||
while (!feof(fp))
|
||||
{
|
||||
buffer[0] = '\0';
|
||||
fgets(buffer, sizeof(buffer)-1, fp);
|
||||
|
||||
if (buffer[0] == ';' || buffer[0] == '\n')
|
||||
UTIL_TrimLeft(buffer);
|
||||
UTIL_TrimRight(buffer);
|
||||
|
||||
if (!buffer[0] || buffer[0] == ';' || buffer[0] == '\n')
|
||||
continue;
|
||||
|
||||
bool simplify = true;
|
||||
|
||||
if (buffer[0] == '>')
|
||||
{
|
||||
simplify = false;
|
||||
line.assign(&buffer[1]);
|
||||
} else {
|
||||
line.assign(buffer);
|
||||
strncopy(line, &buffer[1], sizeof(line));
|
||||
}
|
||||
else
|
||||
{
|
||||
strncopy(line, buffer, sizeof(line));
|
||||
}
|
||||
|
||||
line.trim();
|
||||
|
||||
*moduleName = 0;
|
||||
*moduleName = '\0';
|
||||
|
||||
if (sscanf(line.c_str(), "%s", moduleName) == EOF)
|
||||
if (sscanf(line, "%s", moduleName) == EOF)
|
||||
continue;
|
||||
|
||||
if (LoadModule(moduleName, now, simplify))
|
||||
@@ -1130,7 +1121,7 @@ int MNF_AddNatives(AMX_NATIVE_INFO* natives)
|
||||
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
|
||||
return FALSE; // may only be called from attach
|
||||
|
||||
g_CurrentlyCalledModule->m_Natives.push_back(natives);
|
||||
g_CurrentlyCalledModule->m_Natives.append(natives);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1140,21 +1131,14 @@ int MNF_AddNewNatives(AMX_NATIVE_INFO *natives)
|
||||
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
|
||||
return FALSE; // may only be called from attach
|
||||
|
||||
g_CurrentlyCalledModule->m_NewNatives.push_back(natives);
|
||||
g_CurrentlyCalledModule->m_NewNatives.append(natives);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const char *MNF_GetModname(void)
|
||||
{
|
||||
// :TODO: Do we have to do this??
|
||||
// I dunno who wrote the above comment but no
|
||||
#if 0
|
||||
static char buffer[64];
|
||||
strcpy(buffer, g_mod_name.c_str());
|
||||
return buffer;
|
||||
#endif
|
||||
return g_mod_name.c_str();
|
||||
return g_mod_name.chars();
|
||||
}
|
||||
|
||||
AMX *MNF_GetAmxScript(int id)
|
||||
@@ -1314,7 +1298,7 @@ const char * MNF_GetPlayerName(int id)
|
||||
if (id < 1 || id > gpGlobals->maxClients)
|
||||
return NULL;
|
||||
|
||||
return GET_PLAYER_POINTER_I(id)->name.c_str();
|
||||
return GET_PLAYER_POINTER_I(id)->name.chars();
|
||||
}
|
||||
|
||||
void MNF_OverrideNatives(AMX_NATIVE_INFO *natives, const char *name)
|
||||
@@ -1340,7 +1324,7 @@ const char * MNF_GetPlayerIP(int id)
|
||||
if (id < 1 || id > gpGlobals->maxClients)
|
||||
return NULL;
|
||||
|
||||
return GET_PLAYER_POINTER_I(id)->ip.c_str();
|
||||
return GET_PLAYER_POINTER_I(id)->ip.chars();
|
||||
}
|
||||
|
||||
int MNF_IsPlayerInGame(int id)
|
||||
@@ -1614,7 +1598,7 @@ const char *MNF_GetPlayerTeam(int id)
|
||||
if (id < 1 || id > gpGlobals->maxClients)
|
||||
return NULL;
|
||||
|
||||
return (GET_PLAYER_POINTER_I(id)->team.c_str());
|
||||
return (GET_PLAYER_POINTER_I(id)->team.chars());
|
||||
}
|
||||
|
||||
#ifndef MEMORY_TEST
|
||||
@@ -1703,7 +1687,7 @@ int MNF_SetPlayerTeamInfo(int player, int teamid, const char *teamname)
|
||||
if (player < 1 || player > gpGlobals->maxClients)
|
||||
return 0;
|
||||
|
||||
CPlayer *pPlayer = GET_PLAYER_POINTER_I(player);
|
||||
CPlayer *pPlayer = GET_PLAYER_POINTER_I(player);
|
||||
|
||||
if (!pPlayer->ingame)
|
||||
return 0;
|
||||
@@ -1711,7 +1695,7 @@ int MNF_SetPlayerTeamInfo(int player, int teamid, const char *teamname)
|
||||
pPlayer->teamId = teamid;
|
||||
if (teamname != NULL)
|
||||
{
|
||||
pPlayer->team.assign(teamname);
|
||||
pPlayer->team = teamname;
|
||||
|
||||
// Make sure team is registered, otherwise
|
||||
// natives relying on team id will return wrong result.
|
||||
|
||||
Reference in New Issue
Block a user