added a crapload of random natives
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40538
This commit is contained in:
@@ -512,6 +512,28 @@ static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
|
||||
|
||||
if (!pPlayer)
|
||||
{
|
||||
return pContext->ThrowNativeError("Player %d is not a valid player", params[1]);
|
||||
}
|
||||
|
||||
if (!pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Player %d is not connected", params[1]);
|
||||
}
|
||||
|
||||
char buffer[256];
|
||||
g_SourceMod.FormatString(buffer, sizeof(buffer)-1, pContext, params, 2);
|
||||
|
||||
engine->ClientCommand(pPlayer->GetEdict(), "%s", buffer);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(consoleNatives)
|
||||
{
|
||||
{"CreateConVar", sm_CreateConVar},
|
||||
@@ -543,5 +565,6 @@ REGISTER_NATIVES(consoleNatives)
|
||||
{"ServerCommand", sm_ServerCommand},
|
||||
{"InsertServerCommand", sm_InsertServerCommand},
|
||||
{"ServerExecute", sm_ServerExecute},
|
||||
{"ClientCommand", sm_ClientCommand},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
+161
-1
@@ -12,7 +12,9 @@
|
||||
*/
|
||||
|
||||
#include "sm_globals.h"
|
||||
#include "sourcemod.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include "CPlayerManager.h"
|
||||
|
||||
static cell_t SetRandomSeed(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
@@ -36,10 +38,168 @@ static cell_t GetRandomInt(IPluginContext *pContext, const cell_t *params)
|
||||
return engrandom->RandomInt(params[1], params[2]);
|
||||
}
|
||||
|
||||
static cell_t IsMapValid(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *map;
|
||||
pContext->LocalToString(params[1], &map);
|
||||
|
||||
return engine->IsMapValid(map);
|
||||
}
|
||||
|
||||
static cell_t IsDedicatedServer(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return engine->IsDedicatedServer();
|
||||
}
|
||||
|
||||
static cell_t GetEntityCount(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return engine->GetEntityCount();
|
||||
}
|
||||
|
||||
static cell_t IsValidEntity(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Shouldn't be necessary... not sure though */
|
||||
return pEdict->IsFree() ? 0 : 1;
|
||||
}
|
||||
|
||||
static cell_t CreateEdict(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
edict_t *pEdict = engine->CreateEdict();
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return engine->IndexOfEdict(pEdict);
|
||||
}
|
||||
|
||||
static cell_t RemoveEdict(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return pContext->ThrowNativeError("Edict %d is not a valid edict", params[1]);
|
||||
}
|
||||
|
||||
engine->RemoveEdict(pEdict);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t GetEngineTime(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
float fTime = engine->Time();
|
||||
return sp_ftoc(fTime);
|
||||
}
|
||||
|
||||
static cell_t GetGameTime(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return sp_ftoc(gpGlobals->curtime);
|
||||
}
|
||||
|
||||
static cell_t CreateFakeClient(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *netname;
|
||||
|
||||
pContext->LocalToString(params[1], &netname);
|
||||
|
||||
edict_t *pEdict = engine->CreateFakeClient(netname);
|
||||
|
||||
/* :TODO: does the engine fire forwards for us and whatnot? no idea... */
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return engine->IndexOfEdict(pEdict);
|
||||
}
|
||||
|
||||
static cell_t SetFakeClientConVar(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
|
||||
|
||||
if (!pPlayer)
|
||||
{
|
||||
return pContext->ThrowNativeError("Player %d is not a valid player", params[1]);
|
||||
}
|
||||
|
||||
if (!pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Player %d is not connected", params[1]);
|
||||
}
|
||||
|
||||
if (!pPlayer->IsFakeClient())
|
||||
{
|
||||
return pContext->ThrowNativeError("Player %d is not a fake client", params[1]);
|
||||
}
|
||||
|
||||
char *cvar, *value;
|
||||
|
||||
pContext->LocalToString(params[2], &cvar);
|
||||
pContext->LocalToString(params[3], &value);
|
||||
|
||||
engine->SetFakeClientConVarValue(pPlayer->GetEdict(), cvar, value);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t GetGameDescription(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
const char *description;
|
||||
|
||||
if (params[3])
|
||||
{
|
||||
description = gamedll->GetGameDescription();
|
||||
} else {
|
||||
description = SERVER_CALL(GetGameDescription)();
|
||||
}
|
||||
|
||||
size_t numBytes;
|
||||
|
||||
pContext->StringToLocalUTF8(params[1], params[2], description, &numBytes);
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
static cell_t GetMaxEntities(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return gpGlobals->maxEntities;
|
||||
}
|
||||
|
||||
static cell_t GetCurrentMap(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
size_t bytes;
|
||||
pContext->StringToLocalUTF8(params[1], params[2], STRING(gpGlobals->mapname), &bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(halflifeNatives)
|
||||
{
|
||||
{"SetRandomSeed", SetRandomSeed},
|
||||
{"CreateEdict", CreateEdict},
|
||||
{"CreateFakeClient", CreateFakeClient},
|
||||
{"GetCurrentMap", GetCurrentMap},
|
||||
{"GetEngineTime", GetEngineTime},
|
||||
{"GetEntityCount", GetEntityCount},
|
||||
{"GetGameDescription", GetGameDescription},
|
||||
{"GetGameTime", GetGameTime},
|
||||
{"GetMaxEntities", GetMaxEntities},
|
||||
{"GetRandomFloat", GetRandomFloat},
|
||||
{"GetRandomInt", GetRandomInt},
|
||||
{"IsDedicatedServer", IsDedicatedServer},
|
||||
{"IsMapValid", IsMapValid},
|
||||
{"IsValidEntity", IsValidEntity},
|
||||
{"RemoveEdict", RemoveEdict},
|
||||
{"SetFakeClientConVar", SetFakeClientConVar},
|
||||
{"SetRandomSeed", SetRandomSeed},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -26,6 +26,7 @@ ICvar *icvar = NULL;
|
||||
IGameEventManager2 *gameevents = NULL;
|
||||
IUniformRandomStream *engrandom = NULL;
|
||||
CallClass<IVEngineServer> *enginePatch = NULL;
|
||||
CallClass<IServerGameDLL> *gamedllPatch = NULL;
|
||||
|
||||
PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
|
||||
|
||||
|
||||
@@ -53,9 +53,11 @@ extern ISmmPluginManager *g_pMMPlugins;
|
||||
extern CGlobalVars *gpGlobals;
|
||||
extern IGameEventManager2 *gameevents;
|
||||
extern SourceHook::CallClass<IVEngineServer> *enginePatch;
|
||||
extern SourceHook::CallClass<IServerGameDLL> *gamedllPatch;
|
||||
extern IUniformRandomStream *engrandom;
|
||||
|
||||
#define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func)
|
||||
#define SERVER_CALL(func) SH_CALL(gamedllPatch, &IServerGameDLL::func)
|
||||
|
||||
PLUGIN_GLOBALVARS();
|
||||
|
||||
|
||||
@@ -160,6 +160,7 @@ void SourceModBase::StartSourceMod(bool late)
|
||||
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false);
|
||||
|
||||
enginePatch = SH_GET_CALLCLASS(engine);
|
||||
gamedllPatch = SH_GET_CALLCLASS(gamedll);
|
||||
|
||||
/* Notify! */
|
||||
SMGlobalClass *pBase = SMGlobalClass::head;
|
||||
@@ -345,6 +346,12 @@ void SourceModBase::CloseSourceMod()
|
||||
enginePatch = NULL;
|
||||
}
|
||||
|
||||
if (gamedllPatch)
|
||||
{
|
||||
SH_RELEASE_CALLCLASS(gamedllPatch);
|
||||
gamedllPatch = NULL;
|
||||
}
|
||||
|
||||
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
|
||||
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
|
||||
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false);
|
||||
|
||||
Reference in New Issue
Block a user