Skip to content

Commit

Permalink
add missing functions, notably Get-/SetMaterial(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
luttje committed Aug 24, 2024
1 parent c232cc0 commit d4be1b1
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 75 deletions.
1 change: 1 addition & 0 deletions docs/general/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Additionally, we use the following conventions:
- `Dx` (DirectX), `HDR` and other graphic settings
- `Fcvar` (short for flag convar, kept this way due to the source engine
using this abbreviation when explaining convars)
- `Fov` (short for field of view)
- `Hltv` (short for Half-Life TV)
- `Hud`
- `Hwnd` (short for window handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ local enumsToMergeWithKey = {
MOVE_TYPE = "MOVETYPE",
OBSERVER_MODE = "OBS_MODE",
SOLID = "SOLID",
SOUND_CHANNEL = "CHAN",
SURFACE = "SURF",
SOUND_CHANNEL = "CHAN",
SURFACE = "SURF",

DAMAGE_TYPE = {"DMG", stripUnderscores},
HIT_GROUP = {"HITGROUP", stripUnderscores},
MATERIAL_TYPE = {"MAT", stripUnderscores},
DAMAGE_TYPE = {"DMG", stripUnderscores},
HIT_GROUP = {"HITGROUP", stripUnderscores},
MATERIAL_TYPE = {"MAT", stripUnderscores},
}

for enumKey, enumTargetKey in pairs(enumsToMergeWithKey) do
if (not _E[enumKey]) then
error("Missing enumeration table for key: " .. enumKey)
continue
end

local modifier

if (istable(enumTargetKey)) then
Expand Down Expand Up @@ -168,6 +168,11 @@ TRANSMIT_ALWAYS = _E.EDICT_FLAG.ALWAYS
TRANSMIT_NEVER = _E.EDICT_FLAG.DONTSEND
TRANSMIT_PVS = _E.EDICT_FLAG.PVSCHECK

HUD_PRINTNOTIFY = 1
HUD_PRINTCONSOLE = 2
HUD_PRINTTALK = 3
HUD_PRINTCENTER = 4

TYPE_NONE = -1
TYPE_NIL = 0
TYPE_BOOL = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ include = Include
Msg = PrintMessage
MsgN = PrintMessageLine

OriginalPrintMessage = PrintMessage
PrintMessage = Players.ClientPrintToAll

function GetConVar_Internal(name)
local consoleVariable = ConsoleVariables.Get(name)

Expand Down Expand Up @@ -454,6 +457,8 @@ ENTITY_META.DontDeleteOnRemove = ENTITY_META.RemoveDeleteOnRemove
ENTITY_META.GetFlexIDByName = ENTITY_META.GetFlexIdByName
ENTITY_META.GetNumBodyGroups = ENTITY_META.GetBodyGroupsCount
ENTITY_META.WaterLevel = ENTITY_META.GetWaterLevel
ENTITY_META.SetMaterial = ENTITY_META.SetMaterialOverride
ENTITY_META.GetMaterial = ENTITY_META.GetMaterialOverride

function ENTITY_META:GetDTAngle(index)
return self:GetNetworkDataValue(_E.NETWORK_VARIABLE_TYPE.ANGLE, index)
Expand Down Expand Up @@ -602,6 +607,8 @@ end
local WEAPON_META = FindMetaTable("Weapon")
WEAPON_META.GetHoldType = WEAPON_META.GetAnimationPrefix
WEAPON_META.SetHoldType = WEAPON_META.SetAnimationPrefix
WEAPON_META.Ammo1 = WEAPON_META.GetPrimaryAmmoCount
WEAPON_META.Ammo2 = WEAPON_META.GetSecondaryAmmoCount

local PLAYER_META = FindMetaTable("Player")
PLAYER_META.GetShootPos = ENTITY_META.GetEyePosition
Expand All @@ -627,6 +634,12 @@ PLAYER_META.GetWalkSpeed = PLAYER_META.GetNormalSpeed
PLAYER_META.GetCrouchedWalkSpeed = PLAYER_META.GetCrouchWalkFraction
PLAYER_META.SetCrouchedWalkSpeed = PLAYER_META.SetCrouchWalkFraction
PLAYER_META.Ping = PLAYER_META.GetPing
PLAYER_META.KeyDown = PLAYER_META.IsKeyDown
PLAYER_META.KeyDownLast = PLAYER_META.WasKeyDown
PLAYER_META.KeyPressed = PLAYER_META.WasKeyPressed
PLAYER_META.KeyReleased = PLAYER_META.WasKeyReleased
PLAYER_META.GetFOV = PLAYER_META.GetFov
PLAYER_META.SetFOV = PLAYER_META.SetFov

function PLAYER_META:Crouching()
return self:IsFlagSet(_E.ENGINE_FLAG.DUCKING)
Expand All @@ -640,6 +653,10 @@ function PLAYER_META:GetInfoNum(consoleVariableName, default)
return engine.GetClientConsoleVariableValueAsNumber(self, consoleVariableName) or default
end

function PLAYER_META:PrintMessage(type, message)
Players.ClientPrint(self, type, message)
end

function PLAYER_META:IsDrivingEntity()
return false -- TODO: implement this
end
Expand Down Expand Up @@ -1511,17 +1528,11 @@ end)

hook.Add("PreEntityInitialize", "GModCompatibility.CallSetupDataTables", function(entity)
if (entity.InstallDataTable) then
print("Installing data table for " .. tostring(entity))
entity:InstallDataTable()
else
print("No data table to install for " .. tostring(entity))
end

if (entity.SetupDataTables) then
print("Setting up data tables for " .. tostring(entity))
entity:SetupDataTables()
else
print("No data tables to setup for " .. tostring(entity))
end
end)

Expand Down
54 changes: 40 additions & 14 deletions src/game/client/c_baseanimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ const unsigned int FCLIENTANIM_SEQUENCE_CYCLE = 0x00000001;

static CUtlVector< clientanimating_t > g_ClientSideAnimationList;

// clang-format off

BEGIN_RECV_TABLE_NOBASE( C_BaseAnimating, DT_ServerAnimationData )
RecvPropFloat( RECVINFO( m_flCycle ) ),
END_RECV_TABLE()
RecvPropFloat( RECVINFO( m_flCycle ) ),
END_RECV_TABLE()

void RecvProxy_Sequence( const CRecvProxyData *pData, void *pStruct, void *pOut )
void RecvProxy_Sequence( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
// Have the regular proxy store the data.
RecvProxy_Int32ToInt32( pData, pStruct, pOut );
Expand All @@ -174,7 +176,7 @@ RecvPropFloat( RECVINFO( m_flCycle ) ),
}

IMPLEMENT_CLIENTCLASS_DT( C_BaseAnimating, DT_BaseAnimating, CBaseAnimating )
RecvPropInt( RECVINFO( m_nSequence ), 0, RecvProxy_Sequence ),
RecvPropInt( RECVINFO( m_nSequence ), 0, RecvProxy_Sequence ),
RecvPropInt( RECVINFO( m_nForceBone ) ),
RecvPropVector( RECVINFO( m_vecForce ) ),
RecvPropInt( RECVINFO( m_nSkin ) ),
Expand Down Expand Up @@ -207,11 +209,14 @@ RecvPropInt( RECVINFO( m_nSequence ), 0, RecvProxy_Sequence ),
RecvPropFloat( RECVINFO( m_fadeMaxDist ) ),
RecvPropFloat( RECVINFO( m_flFadeScale ) ),

END_RECV_TABLE()
// Experiment; Material override
RecvPropString( RECVINFO(m_MaterialOverride) ),

END_RECV_TABLE()

BEGIN_PREDICTION_DATA( C_BaseAnimating )
BEGIN_PREDICTION_DATA( C_BaseAnimating )

DEFINE_PRED_FIELD( m_nSkin, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nSkin, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nBody, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
// DEFINE_PRED_FIELD( m_nHitboxSet, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
// DEFINE_PRED_FIELD( m_flModelScale, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
Expand Down Expand Up @@ -255,12 +260,12 @@ RecvPropInt( RECVINFO( m_nSequence ), 0, RecvProxy_Sequence ),

// DEFINE_FIELD( C_BaseFlex, m_iEyeAttachment, FIELD_INTEGER ),

END_PREDICTION_DATA()
END_PREDICTION_DATA()

LINK_ENTITY_TO_CLASS( client_ragdoll, C_ClientRagdoll );
LINK_ENTITY_TO_CLASS( client_ragdoll, C_ClientRagdoll );

BEGIN_DATADESC( C_ClientRagdoll )
DEFINE_FIELD( m_bFadeOut, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bFadeOut, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bImportant, FIELD_BOOLEAN ),
DEFINE_FIELD( m_iCurrentFriction, FIELD_INTEGER ),
DEFINE_FIELD( m_iMinFriction, FIELD_INTEGER ),
Expand All @@ -282,9 +287,11 @@ DEFINE_FIELD( m_bFadeOut, FIELD_BOOLEAN ),
DEFINE_AUTO_ARRAY( m_flScaleTimeEnd, FIELD_FLOAT ),
DEFINE_EMBEDDEDBYREF( m_pRagdoll ),

END_DATADESC()
END_DATADESC()

C_ClientRagdoll::C_ClientRagdoll( bool bRestoring )
static void* WORKAROUND_NASTY_FORMATTING_BUG; // clang-format on

C_ClientRagdoll::C_ClientRagdoll( bool bRestoring )
{
m_iCurrentFriction = 0;
m_iFrictionAnimState = RAGDOLL_FRICTION_NONE;
Expand Down Expand Up @@ -3132,6 +3139,11 @@ int C_BaseAnimating::DrawModel( int flags )
// Necessary for lighting blending
CreateModelInstance();

if ( m_MaterialOverrideReference.IsValid() )
{
modelrender->ForcedMaterialOverride( m_MaterialOverrideReference );
}

if ( !IsFollowingEntity() )
{
drawn = InternalDrawModel( flags | extraFlags );
Expand All @@ -3154,6 +3166,11 @@ int C_BaseAnimating::DrawModel( int flags )
}
}
}

if ( m_MaterialOverrideReference.IsValid() )
{
modelrender->ForcedMaterialOverride( NULL );
}
}

// If we're visualizing our bboxes, draw them
Expand Down Expand Up @@ -4627,8 +4644,8 @@ C_BaseAnimating *C_BaseAnimating::CreateRagdollCopy()
if ( L )
{
LUA_CALL_HOOK_BEGIN( "CreateClientSideRagdoll" );
this->PushLuaInstance( L ); // doc: entity
pRagdoll->PushLuaInstance( L ); // doc: ragdollEntity
this->PushLuaInstance( L ); // doc: entity
pRagdoll->PushLuaInstance( L ); // doc: ragdollEntity
LUA_CALL_HOOK_END( 2, 0 );
}

Expand Down Expand Up @@ -4828,6 +4845,15 @@ void C_BaseAnimating::OnDataChanged( DataUpdateType_t updateType )
delete m_pRagdollInfo;
m_pRagdollInfo = NULL;
}

if ( m_MaterialOverride[0] != 0 )
{
m_MaterialOverrideReference.Init( m_MaterialOverride, TEXTURE_GROUP_MODEL );
}
else if ( m_MaterialOverrideReference.IsValid() )
{
m_MaterialOverrideReference.Shutdown();
}
}

//-----------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions src/game/client/c_baseanimating.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback

virtual bool IsViewModel() const;
virtual void UpdateOnRemove( void );
void SetMaterialOverride( const char *pMaterialName )
{
Q_strncpy( m_MaterialOverride, pMaterialName, sizeof( m_MaterialOverride ) );
}
void GetMaterialOverride( char *pOut, int nLength )
{
Q_strncpy( pOut, m_MaterialOverride, nLength );
}

protected:
// View models scale their attachment positions to account for FOV. To get the unmodified
Expand Down Expand Up @@ -597,6 +605,10 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
float m_fadeMaxDist;
float m_flFadeScale;

// Experiment; Material override
char m_MaterialOverride[MAX_PATH];
CMaterialReference m_MaterialOverrideReference;

private:
float m_flGroundSpeed; // computed linear movement rate for current sequence
float m_flLastEventCheck; // cycle index of when events were last checked
Expand Down
23 changes: 15 additions & 8 deletions src/game/server/baseanimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ int CInfoLightingRelative::UpdateTransmitState( void )

static CIKSaveRestoreOps s_IKSaveRestoreOp;

// clang-format off

BEGIN_DATADESC( CBaseAnimating )

DEFINE_FIELD( m_flGroundSpeed, FIELD_FLOAT ),
Expand Down Expand Up @@ -215,19 +217,19 @@ DEFINE_FIELD( m_flGroundSpeed, FIELD_FLOAT ),

DEFINE_FIELD( m_fBoneCacheFlags, FIELD_SHORT ),

END_DATADESC()
END_DATADESC()

// Sendtable for fields we don't want to send to clientside animating entities
BEGIN_SEND_TABLE_NOBASE( CBaseAnimating, DT_ServerAnimationData )
// Sendtable for fields we don't want to send to clientside animating entities
BEGIN_SEND_TABLE_NOBASE( CBaseAnimating, DT_ServerAnimationData )
// ANIMATION_CYCLE_BITS is defined in shareddefs.h
SendPropFloat( SENDINFO( m_flCycle ), ANIMATION_CYCLE_BITS, SPROP_CHANGES_OFTEN | SPROP_ROUNDDOWN, 0.0f, 1.0f )
END_SEND_TABLE()
END_SEND_TABLE()

void *SendProxy_ClientSideAnimation( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID );
void *SendProxy_ClientSideAnimation( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID );

// SendTable stuff.
IMPLEMENT_SERVERCLASS_ST( CBaseAnimating, DT_BaseAnimating )
SendPropInt( SENDINFO( m_nForceBone ), 8, 0 ),
SendPropInt( SENDINFO( m_nForceBone ), 8, 0 ),
SendPropVector( SENDINFO( m_vecForce ), -1, SPROP_NOSCALE ),

SendPropInt( SENDINFO( m_nSkin ), ANIMATION_SKIN_BITS ),
Expand Down Expand Up @@ -261,9 +263,14 @@ SendPropInt( SENDINFO( m_nForceBone ), 8, 0 ),
SendPropFloat( SENDINFO( m_fadeMaxDist ), 0, SPROP_NOSCALE ),
SendPropFloat( SENDINFO( m_flFadeScale ), 0, SPROP_NOSCALE ),

END_SEND_TABLE()
// Experiment; material override
SendPropString( SENDINFO( m_MaterialOverride ) ),

END_SEND_TABLE()

static void* WORKAROUND_NASTY_FORMATTING_BUG; // clang-format on

CBaseAnimating::CBaseAnimating()
CBaseAnimating::CBaseAnimating()
{
m_vecForce.GetForModify().Init();
m_nForceBone = 0;
Expand Down
11 changes: 11 additions & 0 deletions src/game/server/baseanimating.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ class CBaseAnimating : public CBaseEntity
}

bool PrefetchSequence( int iSequence );
void SetMaterialOverride(const char* pMaterialName)
{
Q_strncpy( m_MaterialOverride.GetForModify(), pMaterialName, MAX_PATH );
}
void GetMaterialOverride( char *pOut, int nLength )
{
Q_strncpy( pOut, m_MaterialOverride.Get(), nLength );
}

private:
void LockStudioHdr();
Expand Down Expand Up @@ -493,6 +501,9 @@ class CBaseAnimating : public CBaseEntity
CNetworkVar( float, m_fadeMaxDist ); // Point at which fading is inactive
CNetworkVar( float, m_flFadeScale ); // Scale applied to min / max

// Experiment; Material overrides
CNetworkString( m_MaterialOverride, MAX_PATH );

public:
COutputEvent m_OnIgnite;

Expand Down
26 changes: 15 additions & 11 deletions src/game/shared/experiment/weapon_experimentbase_scriptedweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,34 @@
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

// clang-format off

IMPLEMENT_NETWORKCLASS_ALIASED( ExperimentScriptedWeapon, DT_ExperimentScriptedWeapon )

BEGIN_NETWORK_TABLE( CExperimentScriptedWeapon, DT_ExperimentScriptedWeapon )
#ifdef CLIENT_DLL
RecvPropString( RECVINFO( m_iScriptedClassname ) ),
RecvPropString( RECVINFO( m_iScriptedClassname ) ),
#else
SendPropString( SENDINFO( m_iScriptedClassname ) ),
SendPropString( SENDINFO( m_iScriptedClassname ) ),
#endif
END_NETWORK_TABLE()
END_NETWORK_TABLE()

BEGIN_PREDICTION_DATA( CExperimentScriptedWeapon )
END_PREDICTION_DATA()

BEGIN_PREDICTION_DATA( CExperimentScriptedWeapon ) END_PREDICTION_DATA()
//=========================================================
// >> CHLSelectFireScriptedWeapon
//=========================================================
BEGIN_DATADESC( CExperimentScriptedWeapon ) END_DATADESC()

//=========================================================
// >> CHLSelectFireScriptedWeapon
//=========================================================
BEGIN_DATADESC( CExperimentScriptedWeapon ) END_DATADESC()
// LINK_ENTITY_TO_CLASS( weapon_experimentbase_scriptedweapon, CExperimentScriptedWeapon ); PRECACHE_WEAPON_REGISTER( weapon_experimentbase_scriptedweapon );

// LINK_ENTITY_TO_CLASS( weapon_experimentbase_scriptedweapon, CExperimentScriptedWeapon
// ); PRECACHE_WEAPON_REGISTER( weapon_experimentbase_scriptedweapon );
static void* WORKAROUND_NASTY_FORMATTING_BUG; // clang-format on

// These functions replace the macros above for runtime registration of
// scripted weapons.
#ifdef CLIENT_DLL
static C_BaseEntity *CCExperimentScriptedWeaponFactory( void )
static C_BaseEntity *CCExperimentScriptedWeaponFactory( void )
{
return static_cast< C_BaseEntity * >( new CExperimentScriptedWeapon );
};
Expand Down
Loading

0 comments on commit d4be1b1

Please sign in to comment.