Add ThirdPerson + FullUpdate

This commit is contained in:
BotoX 2017-02-26 00:28:40 +01:00
parent 028213944f
commit 33a8bb32c6
5 changed files with 248 additions and 0 deletions

View File

@ -0,0 +1,20 @@
"Games"
{
"#default"
{
"#supported"
{
"engine" "orangebox"
"engine" "orangebox_valve"
"engine" "css"
}
"Offsets"
{
"CBaseClient::UpdateAcknowledgedFramecount"
{
"linux" "44"
}
}
}
}

View File

@ -0,0 +1,106 @@
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <FullUpdate>
Handle g_hCBaseClient_UpdateAcknowledgedFramecount;
int g_iLastFullUpdate[MAXPLAYERS + 1] = { 0, ... };
public Plugin myinfo =
{
name = "FullUpdate",
author = "BotoX",
description = "Serverside cl_fullupdate",
version = "1.0"
}
public void OnPluginStart()
{
Handle hGameConf = LoadGameConfigFile("FullUpdate2.games");
if(hGameConf == INVALID_HANDLE)
{
SetFailState("Couldn't load FullUpdate2.games game config!");
return;
}
// void CBaseClient::UpdateAcknowledgedFramecount()
StartPrepSDKCall(SDKCall_Raw);
if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CBaseClient::UpdateAcknowledgedFramecount"))
{
CloseHandle(hGameConf);
SetFailState("PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, \"CBaseClient::UpdateAcknowledgedFramecount\" failed!");
return;
}
CloseHandle(hGameConf);
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
g_hCBaseClient_UpdateAcknowledgedFramecount = EndPrepSDKCall();
RegConsoleCmd("sm_fullupdate", Command_FullUpdate);
RegConsoleCmd("cl_fullupdate", Command_FullUpdate);
RegConsoleCmd("fullupdate", Command_FullUpdate);
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("ClientFullUpdate", Native_FullUpdate);
RegPluginLibrary("FullUpdate");
return APLRes_Success;
}
public void OnClientConnected(int client)
{
g_iLastFullUpdate[client] = 0;
}
bool FullUpdate(int client)
{
if(g_iLastFullUpdate[client] + 1 > GetTime())
return false;
// The IClient vtable is +4 from the IGameEventListener2 (CBaseClient) vtable due to multiple inheritance.
Address pIClient = GetClientIClient(client) - view_as<Address>(4);
if(!pIClient)
return false;
SDKCall(g_hCBaseClient_UpdateAcknowledgedFramecount, pIClient, -1);
g_iLastFullUpdate[client] = GetTime();
return true;
}
public int Native_FullUpdate(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
if(client > MaxClients || client <= 0)
{
ThrowNativeError(SP_ERROR_NATIVE, "Client is not valid.");
return 0;
}
if(!IsClientInGame(client))
{
ThrowNativeError(SP_ERROR_NATIVE, "Client is not in-game.");
return 0;
}
if(IsFakeClient(client))
{
ThrowNativeError(SP_ERROR_NATIVE, "Client is fake-client.");
return 0;
}
return FullUpdate(client);
}
public Action Command_FullUpdate(int client, int args)
{
FullUpdate(client);
return Plugin_Handled;
}

View File

@ -0,0 +1,24 @@
#if defined _FullUpdate_Included
#endinput
#endif
#define _FullUpdate_Included
native bool ClientFullUpdate(int client);
public SharedPlugin __pl_FullUpdate =
{
name = "FullUpdate",
file = "FullUpdate.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};
#if !defined REQUIRE_PLUGIN
public __pl_FullUpdate_SetNTVOptional()
{
MarkNativeAsOptional("ClientFullUpdate");
}
#endif

View File

@ -0,0 +1,97 @@
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <FullUpdate>
#include <multicolors>
bool g_bThirdPerson[MAXPLAYERS + 1] = { false, ... };
// Spectator Movement modes (from smlib)
enum Obs_Mode
{
OBS_MODE_NONE = 0, // not in spectator mode
OBS_MODE_DEATHCAM, // special mode for death cam animation
OBS_MODE_FREEZECAM, // zooms to a target, and freeze-frames on them
OBS_MODE_FIXED, // view from a fixed camera position
OBS_MODE_IN_EYE, // follow a player in first person view
OBS_MODE_CHASE, // follow a player in third person view
OBS_MODE_POI, // PASSTIME point of interest - game objective, big fight, anything interesting; added in the middle of the enum due to tons of hard-coded "<ROAMING" enum compares
OBS_MODE_ROAMING, // free roaming
NUM_OBSERVER_MODES
};
public Plugin myinfo =
{
name = "FullUpdate",
author = "BotoX",
description = "Serverside cl_fullupdate",
version = "1.0"
}
public void OnPluginStart()
{
RegConsoleCmd("sm_tp", Command_ThirdPerson, "Toggle thirdperson");
HookEvent("player_death", Event_PlayerDeathPost, EventHookMode_Post);
HookEvent("player_spawn", Event_PlayerSpawnPost, EventHookMode_Post);
}
public void OnClientConnected(int client)
{
g_bThirdPerson[client] = false;
}
public Action Command_ThirdPerson(int client, int args)
{
if(g_bThirdPerson[client])
ThirdPersonOff(client);
else
ThirdPersonOn(client);
}
public void Event_PlayerDeathPost(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
ThirdPersonOff(client);
}
public void Event_PlayerSpawnPost(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
ThirdPersonOff(client);
}
void ThirdPersonOn(int client)
{
if(g_bThirdPerson[client])
return;
if(!IsPlayerAlive(client))
return;
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", 0);
SetEntProp(client, Prop_Send, "m_iObserverMode", OBS_MODE_DEATHCAM);
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 0);
SetEntProp(client, Prop_Send, "m_iFOV", 120);
g_bThirdPerson[client] = true;
CPrintToChat(client, "\x03[ThirdPerson]\x01 is {green}ON{default}.");
}
void ThirdPersonOff(int client)
{
if(!g_bThirdPerson[client])
return;
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", -1);
SetEntProp(client, Prop_Send, "m_iObserverMode", 0);
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 1);
SetEntProp(client, Prop_Send, "m_iFOV", 90);
ClientFullUpdate(client);
g_bThirdPerson[client] = false;
CPrintToChat(client, "\x03[ThirdPerson]\x01 is {red}OFF{default}.");
}

View File

@ -0,0 +1 @@
../../../FullUpdate/scripting/include/FullUpdate.inc