Cstrike: cs_set_user_model - Add a param to choose whether modelindex should be updated

This commit is contained in:
Arkshine
2015-07-09 13:36:53 +02:00
parent 5d6f829624
commit 86e33d0cb1
4 changed files with 59 additions and 12 deletions

View File

@ -43,7 +43,7 @@ int TeamOffset;
int MenuOffset;
server_static_t *ServerStatic;
double *RealTime;
server_t *Server;
void InitializeHacks()
{
@ -531,8 +531,13 @@ void InitGlobalVars()
ServerStatic = reinterpret_cast<server_static_t*>(address);
}
#endif
if (CommonConfig->GetAddress("realtime", &address))
if (CommonConfig->GetAddress("sv", &address))
{
RealTime = reinterpret_cast<double*>(*reinterpret_cast<uintptr_t*>(address));
Server = *reinterpret_cast<server_t**>(address);
}
if (!Server)
{
MF_Log("sv global variable is not available\n");
}
}

View File

@ -46,6 +46,6 @@ extern DLL_FUNCTIONS *g_pFunctionTable;
extern bool NoKifesMode;
extern server_static_t *ServerStatic;
extern double *RealTime;
extern server_t *Server;
#endif // CSTRIKE_HACKS_H

View File

@ -856,7 +856,7 @@ static cell AMX_NATIVE_CALL cs_get_user_model(AMX *amx, cell *params)
return MF_SetAmxString(amx, params[2], GETCLIENTKEYVALUE(GETINFOKEYBUFFER(pPlayer), "model"), params[3]);
}
// native cs_set_user_model(index, const model[]);
// native cs_set_user_model(index, const model[], bool:update_index = false);
static cell AMX_NATIVE_CALL cs_set_user_model(AMX *amx, cell *params)
{
int index = params[1];
@ -874,8 +874,45 @@ static cell AMX_NATIVE_CALL cs_set_user_model(AMX *amx, cell *params)
int length;
const char *newModel = MF_GetAmxString(amx, params[2], 0, &length);
if (!*newModel)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Model can not be empty");
return 0;
}
Players[index].SetModel(newModel);
Players[index].UpdateModel(MF_GetPlayerEdict(index));
Players[index].UpdateModel(pPlayer);
if (*params / sizeof(cell) >= 3 && params[3] != 0)
{
if (!Server)
{
MF_LogError(amx, AMX_ERR_NATIVE, "cs_set_user_model is disabled with update_index parameter set");
return 0;
}
GET_OFFSET("CBasePlayer", m_modelIndexPlayer);
char model[260];
UTIL_Format(model, sizeof(model), "models/player/%s/%s.mdl", newModel, newModel);
for (size_t i = 0; i < HL_MODEL_MAX; ++i)
{
if (Server->model_precache[i] && !strcmp(Server->model_precache[i], model))
{
if (pPlayer->v.modelindex != i)
{
SET_MODEL(pPlayer, model);
}
set_pdata<int>(pPlayer, m_modelIndexPlayer, i);
return 1;
}
}
MF_LogError(amx, AMX_ERR_NATIVE, "Model must be precached");
return 0;
}
return 1;
}