Skip to content

Commit

Permalink
Delete* natives added & speed improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
brbsh committed Jan 30, 2015
1 parent 723e9cf commit 4a70e6a
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 13 deletions.
111 changes: 102 additions & 9 deletions natives.cpp
Expand Up @@ -31,13 +31,16 @@ const AMX_NATIVE_INFO amxNatives::varNatives[] =
{"GetPVarArrInt", amxNatives::GetPVarArrInt},
{"GetPVarArrFloat", amxNatives::GetPVarArrFloat},
{"GetPVarArrString", amxNatives::GetPVarArrString},
{"DeletePVar_hooked", amxNatives::DeletePVar_hooked},
{"ResetPlayerVars", amxNatives::ResetPlayerVars},

{"SetGVarInt", amxNatives::SetGVarInt},
{"SetGVarFloat", amxNatives::SetGVarFloat},
{"SetGVarString", amxNatives::SetGVarString},
{"GetGVarInt", amxNatives::GetGVarInt},
{"GetGVarFloat", amxNatives::GetGVarFloat},
{"GetGVarString", amxNatives::GetGVarString},
{"DeleteGVar", amxNatives::DeleteGVar},

{"SetGVarArrInt", amxNatives::SetGVarArrInt},
{"SetGVarArrFloat", amxNatives::SetGVarArrFloat},
Expand Down Expand Up @@ -175,18 +178,22 @@ cell AMX_NATIVE_CALL amxNatives::GetPVarArrInt(AMX *amx, cell *params)
char *varname = NULL;
long index = params[3];

boost::unordered_map<int, boost::unordered_map<std::string, boost::unordered_map<long, amxVars> > >::iterator pMap;

amx_StrParam(amx, params[2], varname);

if(!pVarArrPool.count(playerid))
return 0;

if(!pVarArrPool.find(playerid)->second.count(varname))
pMap = pVarArrPool.find(playerid);

if(!pMap->second.count(varname))
return 0;

if(!pVarArrPool.find(playerid)->second.find(varname)->second.count(index))
if(!pMap->second.find(varname)->second.count(index))
return 0;

return pVarArrPool.find(playerid)->second.find(varname)->second.find(index)->second.integer;
return pMap->second.find(varname)->second.find(index)->second.integer;
}


Expand All @@ -206,18 +213,22 @@ cell AMX_NATIVE_CALL amxNatives::GetPVarArrFloat(AMX *amx, cell *params)
long index = params[3];
float value = 0.0f;

boost::unordered_map<int, boost::unordered_map<std::string, boost::unordered_map<long, amxVars> > >::iterator pMap;

amx_StrParam(amx, params[2], varname);

if(!pVarArrPool.count(playerid))
return amx_ftoc(value);

if(!pVarArrPool.find(playerid)->second.count(varname))
pMap = pVarArrPool.find(playerid);

if(!pMap->second.count(varname))
return amx_ftoc(value);

if(!pVarArrPool.find(playerid)->second.find(varname)->second.count(index))
if(!pMap->second.find(varname)->second.count(index))
return amx_ftoc(value);

value = pVarArrPool.find(playerid)->second.find(varname)->second.find(index)->second.floating;
value = pMap->second.find(varname)->second.find(index)->second.floating;

return amx_ftoc(value);
}
Expand All @@ -239,19 +250,77 @@ cell AMX_NATIVE_CALL amxNatives::GetPVarArrString(AMX *amx, cell *params)
cell *dest = NULL;
long index = params[4];

boost::unordered_map<int, boost::unordered_map<std::string, boost::unordered_map<long, amxVars> > >::iterator pMap;

amx_StrParam(amx, params[2], varname);
amx_GetAddr(amx, params[3], &dest);

if(!pVarArrPool.count(playerid))
return 0;

if(!pVarArrPool.find(playerid)->second.count(varname))
pMap = pVarArrPool.find(playerid);

if(!pMap->second.count(varname))
return 0;

if(!pVarArrPool.find(playerid)->second.find(varname)->second.count(index))
if(!pMap->second.find(varname)->second.count(index))
return 0;

amx_SetString(dest, pVarArrPool.find(playerid)->second.find(varname)->second.find(index)->second.string.c_str(), NULL, NULL, params[5]);
amx_SetString(dest, pMap->second.find(varname)->second.find(index)->second.string.c_str(), NULL, NULL, params[5]);

return 1;
}



// native DeletePVar_hooked(playerid, varname[]);
cell AMX_NATIVE_CALL amxNatives::DeletePVar_hooked(AMX *amx, cell *params)
{
if(!arguments(2))
{
logprintf("Var plugin: Invalid argument count (%i) in native 'DeletePVar_hooked'", (params[0] >> 2));

return NULL;
}

int playerid = params[1];
char *varname = NULL;

boost::unordered_map<int, boost::unordered_map<std::string, boost::unordered_map<long, amxVars> > >::iterator pMap;

amx_StrParam(amx, params[2], varname);

if(!pVarArrPool.count(playerid))
return 0;

pMap = pVarArrPool.find(playerid);

if(!pMap->second.count(varname))
return 0;

pMap->second.quick_erase(pMap->second.find(varname));

return 1;
}



// native ResetPlayerVars(playerid);
cell AMX_NATIVE_CALL amxNatives::ResetPlayerVars(AMX *amx, cell *params)
{
if(!arguments(1))
{
logprintf("Var plugin: Invalid argument count (%i) in native 'ResetPlayerVars'", (params[0] >> 2));

return NULL;
}

int playerid = params[1];

if(!pVarArrPool.count(playerid))
return 0;

pVarArrPool.quick_erase(pVarArrPool.find(playerid));

return 1;
}
Expand Down Expand Up @@ -405,6 +474,30 @@ cell AMX_NATIVE_CALL amxNatives::GetGVarString(AMX *amx, cell *params)



// native DeleteGVar(varname[]);
cell AMX_NATIVE_CALL amxNatives::DeleteGVar(AMX *amx, cell *params)
{
if(!arguments(1))
{
logprintf("Var plugin: Invalid argument count (%i) in native 'DeleteGVar'", (params[0] >> 2));

return NULL;
}

char *varname = NULL;

amx_StrParam(amx, params[1], varname);

if(!gVarPool.count(varname))
return 0;

gVarPool.quick_erase(gVarPool.find(varname));

return 1;
}



// native SetGVarArrInt(varname[], value, index = 0);
cell AMX_NATIVE_CALL amxNatives::SetGVarArrInt(AMX *amx, cell *params)
{
Expand Down
3 changes: 3 additions & 0 deletions natives.h
Expand Up @@ -21,13 +21,16 @@ class amxNatives
static cell AMX_NATIVE_CALL GetPVarArrInt(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL GetPVarArrFloat(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL GetPVarArrString(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL DeletePVar_hooked(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL ResetPlayerVars(AMX *amx, cell *params);

static cell AMX_NATIVE_CALL SetGVarInt(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL SetGVarFloat(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL SetGVarString(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL GetGVarInt(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL GetGVarFloat(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL GetGVarString(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL DeleteGVar(AMX *amx, cell *params);

static cell AMX_NATIVE_CALL SetGVarArrInt(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL SetGVarArrFloat(AMX *amx, cell *params);
Expand Down
1 change: 0 additions & 1 deletion var.h
Expand Up @@ -37,6 +37,5 @@ struct amxVars
{
long integer;
float floating;

std::string string;
};
3 changes: 0 additions & 3 deletions var.sln
Expand Up @@ -5,12 +5,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "var", "var.vcxproj", "{4DA2
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4DA2EDC5-0170-4F64-AAFB-3F00DBF96796}.Debug|Win32.ActiveCfg = Debug|Win32
{4DA2EDC5-0170-4F64-AAFB-3F00DBF96796}.Debug|Win32.Build.0 = Debug|Win32
{4DA2EDC5-0170-4F64-AAFB-3F00DBF96796}.Release|Win32.ActiveCfg = Release|Win32
{4DA2EDC5-0170-4F64-AAFB-3F00DBF96796}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
Expand Down

0 comments on commit 4a70e6a

Please sign in to comment.