Skip to content

Commit

Permalink
misc plugin api updates
Browse files Browse the repository at this point in the history
Copied more helpers from mmlib. Exposed more funcs. Added more hooks.
  • Loading branch information
wootguy committed Oct 31, 2024
1 parent 247bba1 commit 91c0dd5
Show file tree
Hide file tree
Showing 25 changed files with 1,350 additions and 52 deletions.
24 changes: 24 additions & 0 deletions dlls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,22 @@ set(UTIL_SRC
../game_shared/shared_util.cpp
)

set(NET_HDR
net/Socket.h
net/IPV4.h
net/Packet.h
)
set(NET_SRC
net/IPV4.cpp
net/Packet.cpp
)

if (UNIX)
set(NET_SRC ${NET_SRC} net/network_unix.cpp net/Socket_unix.cpp)
else()
set(NET_SRC ${NET_SRC} net/network_win.cpp net/Socket_win.cpp)
endif()

set(GAME_HDR
client.h
../engine/custom.h
Expand Down Expand Up @@ -570,6 +586,7 @@ set(ALL_SRC
${GENERATED_SRCS}
${ENT_SRC} ${ENT_HDR}
${UTIL_SRC} ${UTIL_HDR}
${NET_SRC} ${NET_HDR}
${GAME_SRC} ${GAME_HDR}
${MISC_HDR}
)
Expand All @@ -596,6 +613,8 @@ if(UNIX)
LINK_FLAGS "-m32 -g ${ASAN_LFLAGS}"
)

target_link_libraries(${PROJECT_NAME} PRIVATE WS2_32 IPHLPAPI)

elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEF:${CMAKE_CURRENT_SOURCE_DIR}/hl.def")
Expand All @@ -617,6 +636,7 @@ elseif(MSVC)
source_group("Header Files\\Entities\\weapon\\ammo" FILES ${AMMO_HDR})
source_group("Header Files\\Game" FILES ${GAME_HDR})
source_group("Header Files\\Util" FILES ${UTIL_HDR})
source_group("Header Files\\Network" FILES ${NET_HDR})

source_group("Source Files\\Entities" FILES ${ENTITY_SRC})
source_group("Source Files\\Generated" FILES ${GENERATED_SRCS})
Expand All @@ -636,7 +656,11 @@ elseif(MSVC)
source_group("Source Files\\Entities\\weapon" FILES ${WEAPON_SRC})
source_group("Source Files\\Entities\\weapon\\ammo" FILES ${AMMO_SRC})
source_group("Source Files\\Util" FILES ${UTIL_SRC})
source_group("Source Files\\Network" FILES ${NET_SRC})
source_group("Source Files\\Game" FILES ${GAME_SRC})

# WinSock libraries for network utils
target_link_libraries(${PROJECT_NAME} PRIVATE WS2_32 IPHLPAPI)

else()
message(FATAL_ERROR "TODO: Mac support")
Expand Down
12 changes: 12 additions & 0 deletions dlls/PluginHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ struct HLCOOP_PLUGIN_HOOKS {
HOOK_RETURN_DATA (*pfnWriteString)(const char* value);
HOOK_RETURN_DATA (*pfnWriteEntity)(int value);
HOOK_RETURN_DATA (*pfnMessageEnd)();

// called before the engine sets the model, after model replacement in the mod
HOOK_RETURN_DATA (*pfnSetModel)(edict_t* edict, const char* model);

// called immediately after the engine sets a model
HOOK_RETURN_DATA (*pfnSetModelPost)(edict_t* edict, const char* model);

// called after the engine precaches the given model
HOOK_RETURN_DATA (*pfnPrecacheModelPost)(const char* model);

// called before an event is played
HOOK_RETURN_DATA(*pfnPlaybackEvent)(int flags, const edict_t* pInvoker, unsigned short eventindex, float delay, float* origin, float* angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2);
};

EXPORT void RegisterPlugin(void* plugin, HLCOOP_PLUGIN_HOOKS* hooks, const char* name);
Expand Down
2 changes: 1 addition & 1 deletion dlls/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void PluginManager::UpdateServerPlugins(bool forceUpdate) {
{
lineNum++;

int endPos = line.find_first_of("#/");
int endPos = line.find("//");
if (endPos != -1)
line = trimSpaces(line.substr(0, endPos));

Expand Down
42 changes: 21 additions & 21 deletions dlls/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@
#include "monsterevent.h"
#endif

extern int IsSoundEvent( int eventNumber );
EXPORT int IsSoundEvent( int eventNumber );

// Ranomly pick a sequence tagged with the given activity
int LookupActivity( void *pmodel, entvars_t *pev, int activity );
EXPORT int LookupActivity( void *pmodel, entvars_t *pev, int activity );

// Pick the sequence with the heaviest random chance
int LookupActivityHeaviest( void *pmodel, entvars_t *pev, int activity );
EXPORT int LookupActivityHeaviest( void *pmodel, entvars_t *pev, int activity );

// Find the n'th sequence tagged with the given activity. If the offset is greater than
// the number of sequences tagged with this activity, then the last found sequence is returned.
int LookupActivityWithOffset(void* pmodel, entvars_t* pev, int activity, int offset);

bool ActivityHasEvent(void* pmodel, int activity, int event);

int LookupSequence( void *pmodel, const char *label );
void GetSequenceInfo( void *pmodel, entvars_t *pev, float *pflFrameRate, float *pflGroundSpeed );
int GetSequenceFlags( void *pmodel, entvars_t *pev );
int LookupAnimationEvents( void *pmodel, entvars_t *pev, float flStart, float flEnd );
float SetController( void *pmodel, entvars_t *pev, int iController, float flValue );
float SetBlending( void *pmodel, entvars_t *pev, int iBlender, float flValue );
void GetEyePosition( void *pmodel, float *vecEyePosition );
void SequencePrecache( void *pmodel, const char *pSequenceName );
int FindTransition( void *pmodel, int iEndingAnim, int iGoalAnim, int *piDir );
void SetBodygroup( void *pmodel, entvars_t *pev, int iGroup, int iValue );
int GetBodygroup( void *pmodel, entvars_t *pev, int iGroup );

int GetAnimationEvent( void *pmodel, entvars_t *pev, MonsterEvent_t *pMonsterEvent, float flStart, float flEnd, int index );
int ExtractBbox( void *pmodel, int sequence, float *mins, float *maxs );
EXPORT int LookupActivityWithOffset(void* pmodel, entvars_t* pev, int activity, int offset);

EXPORT bool ActivityHasEvent(void* pmodel, int activity, int event);

EXPORT int LookupSequence( void *pmodel, const char *label );
EXPORT void GetSequenceInfo( void *pmodel, entvars_t *pev, float *pflFrameRate, float *pflGroundSpeed );
EXPORT int GetSequenceFlags( void *pmodel, entvars_t *pev );
EXPORT int LookupAnimationEvents( void *pmodel, entvars_t *pev, float flStart, float flEnd );
EXPORT float SetController( void *pmodel, entvars_t *pev, int iController, float flValue );
EXPORT float SetBlending( void *pmodel, entvars_t *pev, int iBlender, float flValue );
EXPORT void GetEyePosition( void *pmodel, float *vecEyePosition );
EXPORT void SequencePrecache( void *pmodel, const char *pSequenceName );
EXPORT int FindTransition( void *pmodel, int iEndingAnim, int iGoalAnim, int *piDir );
EXPORT void SetBodygroup( void *pmodel, entvars_t *pev, int iGroup, int iValue );
EXPORT int GetBodygroup( void *pmodel, entvars_t *pev, int iGroup );

EXPORT int GetAnimationEvent( void *pmodel, entvars_t *pev, MonsterEvent_t *pMonsterEvent, float flStart, float flEnd, int index );
EXPORT int ExtractBbox( void *pmodel, int sequence, float *mins, float *maxs );

// From /engine/studio.h
#define STUDIO_LOOPING 0x0001
Expand Down
5 changes: 4 additions & 1 deletion dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class CBaseMonster;
class CBasePlayerWeapon;
class CTalkSquadMonster;
class CBaseToggle;
class CBaseAnimating;


#define SF_NORESPAWN ( 1 << 10 )// !!!set this bit on guns and stuff that should never respawn.
Expand Down Expand Up @@ -204,6 +205,7 @@ class EXPORT CBaseEntity
virtual CBasePlayerWeapon* GetWeaponPtr(void) { return NULL; };
virtual CTalkSquadMonster * MyTalkSquadMonsterPointer( void ) { return NULL;}
virtual CBaseToggle* MyTogglePointer(void) { return NULL; }
virtual CBaseAnimating* MyAnimatingPointer(void) { return NULL; }
virtual int GetToggleState( void ) { return TS_AT_TOP; }
virtual void AddPoints( int score, BOOL bAllowNegativeScore ) {}
virtual void AddPointsToTeam( int score, BOOL bAllowNegativeScore ) {}
Expand Down Expand Up @@ -289,7 +291,7 @@ class EXPORT CBaseEntity
int IsDormant( void );
BOOL IsLockedByMaster( void ) { return FALSE; }

static CBaseEntity *Instance( edict_t *pent )
static CBaseEntity *Instance( const edict_t *pent )
{
if ( !pent )
pent = ENT(0);
Expand Down Expand Up @@ -519,6 +521,7 @@ class EXPORT CBaseAnimating : public CBaseDelay
virtual int GetEntindexPriority() { return ENTIDX_PRIORITY_NORMAL; }
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
virtual CBaseAnimating* MyAnimatingPointer(void) { return this; }

static TYPEDESCRIPTION m_SaveData[];

Expand Down
2 changes: 2 additions & 0 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,8 @@ void StartFrame( void )
lagcomp_update();

g_Scheduler.Think();

handleThreadPrints();
}


Expand Down
4 changes: 2 additions & 2 deletions dlls/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ std::string getLogTimeStr();

void writeDebugLog(std::ofstream& outFile, std::string lastLogName, std::string prefix, std::string line);

const char* msgDestStr(int msg_dest);
EXPORT const char* msgDestStr(int msg_dest);

const char* msgTypeStr(int msg_type);
EXPORT const char* msgTypeStr(int msg_type);

void log_msg(msg_info& msg);

Expand Down
16 changes: 16 additions & 0 deletions dlls/eng_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ int PRECACHE_MODEL(const char* path) {
world->v.modelindex = oldModelIdx;
}

CALL_HOOKS(int, pfnPrecacheModelPost, path);

return modelIdx;
}
else {
Expand Down Expand Up @@ -491,8 +493,12 @@ bool SET_MODEL(edict_t* edict, const char* model) {
model = NOT_PRECACHED_MODEL;
}

CALL_HOOKS(bool, pfnSetModel, edict, model);

g_engfuncs.pfnSetModel(edict, model);

CALL_HOOKS(bool, pfnSetModelPost, edict, model);

return replaced;
}

Expand Down Expand Up @@ -652,4 +658,14 @@ const char* CMD_ARGS() {
void CHANGE_LEVEL(const char* pszLevelName, const char* pszLandmarkName) {
CALL_HOOKS_VOID(pfnChangeLevel, pszLevelName, pszLandmarkName);
g_engfuncs.pfnChangeLevel(pszLevelName, pszLandmarkName);
}

void PLAYBACK_EVENT_FULL(int flags, const edict_t* pInvoker, unsigned short eventindex, float delay,
float* origin, float* angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1,
int bparam2)
{
CALL_HOOKS_VOID(pfnPlaybackEvent, flags, pInvoker, eventindex, delay, origin, angles, fparam1, fparam2,
iparam1, iparam2, bparam1, bparam2);
g_engfuncs.pfnPlaybackEvent(flags, pInvoker, eventindex, delay, origin, angles, fparam1, fparam2,
iparam1, iparam2, bparam1, bparam2);
}
2 changes: 2 additions & 0 deletions dlls/eng_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ inline void MESSAGE_BEGIN(int msg_dest, int msg_type, const float* pOrigin = NUL
#define CMD_ARGC (*g_engfuncs.pfnCmd_Argc)
#define CMD_ARGV (*g_engfuncs.pfnCmd_Argv)
#define CHANGE_LEVEL (*g_engfuncs.pfnChangeLevel)
#define PLAYBACK_EVENT_FULL (*g_engfuncs.pfnPlaybackEvent)
#else
// engine wrappers which handle model/sound replacement logic
EXPORT int PRECACHE_GENERIC(const char* path);
Expand Down Expand Up @@ -86,4 +87,5 @@ EXPORT const char* CMD_ARGV(int argc);
EXPORT int CMD_ARGC();
EXPORT const char* CMD_ARGS();
EXPORT void CHANGE_LEVEL(const char* pszLevelName, const char* pszLandmarkName);
EXPORT void PLAYBACK_EVENT_FULL(int flags, const edict_t* pInvoker, unsigned short eventindex, float delay, float* origin, float* angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2);
#endif
9 changes: 4 additions & 5 deletions dlls/enginecallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,18 @@ EXPORT void DEBUG_MSG(ALERT_TYPE target, const char* format, ...);

#if defined(PLUGIN_BUILD) && defined(PLUGIN_NAME)
#define ALERT(target, fmt, ...) { \
DEBUG_MSG(target, "[" PLUGIN_NAME "] " fmt, ##__VA_ARGS__ ); \
DEBUG_MSG(target, "[" PLUGIN_NAME "] "); \
DEBUG_MSG(target, fmt, ##__VA_ARGS__ ); \
}
#else
#define ALERT DEBUG_MSG
#endif

#define print(...) {ALERT(at_console, __VA_ARGS__);}
#define println(...) {ALERT(at_console, __VA_ARGS__); ALERT(at_console, "\n");}
#define println(...) {ALERT(at_console, __VA_ARGS__); DEBUG_MSG(at_console, "\n");}
#define ENGINE_FPRINTF (*g_engfuncs.pfnEngineFprintf)
#define ALLOC_PRIVATE (*g_engfuncs.pfnPvAllocEntPrivateData)
inline void *GET_PRIVATE( edict_t *pent )
inline void *GET_PRIVATE( const edict_t *pent )
{
if ( pent )
return pent->pvPrivateData;
Expand Down Expand Up @@ -136,8 +137,6 @@ inline void *GET_PRIVATE( edict_t *pent )
#define NUMBER_OF_ENTITIES (*g_engfuncs.pfnNumberOfEntities)
#define IS_DEDICATED_SERVER (*g_engfuncs.pfnIsDedicatedServer)

#define PLAYBACK_EVENT_FULL (*g_engfuncs.pfnPlaybackEvent)

#define ENGINE_SET_PVS (*g_engfuncs.pfnSetFatPVS)
#define ENGINE_SET_PAS (*g_engfuncs.pfnSetFatPAS)

Expand Down
14 changes: 7 additions & 7 deletions dlls/monster/CShockTrooper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,13 +965,13 @@ void CShockTrooper::HandleAnimEvent(MonsterEvent_t* pEvent)
GetAttachment(0, vecArmPos, vecArmAngles);

MESSAGE_BEGIN(MSG_PVS, SVC_TEMPENTITY, vecArmPos);
g_engfuncs.pfnWriteByte(TE_SPRITE);
g_engfuncs.pfnWriteCoord(vecArmPos.x);
g_engfuncs.pfnWriteCoord(vecArmPos.y);
g_engfuncs.pfnWriteCoord(vecArmPos.z);
g_engfuncs.pfnWriteShort(iShockTrooperMuzzleFlash);
g_engfuncs.pfnWriteByte(4);
g_engfuncs.pfnWriteByte(128);
WRITE_BYTE(TE_SPRITE);
WRITE_COORD(vecArmPos.x);
WRITE_COORD(vecArmPos.y);
WRITE_COORD(vecArmPos.z);
WRITE_COORD(iShockTrooperMuzzleFlash);
WRITE_BYTE(4);
WRITE_BYTE(128);
MESSAGE_END();

Shoot();
Expand Down
4 changes: 3 additions & 1 deletion dlls/mstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ bool mstream::eom()

void mstream::freeBuf()
{
delete [] (char*)start;
if (start)
delete [] (char*)start;
start = 0;
}

mstream::~mstream( void )
Expand Down
2 changes: 2 additions & 0 deletions dlls/mstream.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#include "Platform.h"
#include "vector.h"
#include <stdint.h>

class EXPORT mstream
Expand Down
Loading

0 comments on commit 91c0dd5

Please sign in to comment.