Skip to content

Commit

Permalink
Add some comments in engine headers/BXT files and hooked 'engineapi' …
Browse files Browse the repository at this point in the history
…for oldest WON builds (#422)

* Added comments in engine headers and BXT files

* Hooked 'engineapi' in older WON builds

* Fix comment in triangleapi.h

* Replaced with more formatted comments
  • Loading branch information
SmileyAG authored Feb 17, 2023
1 parent 7112aaa commit f8c6c5d
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 43 deletions.
30 changes: 15 additions & 15 deletions BunnymodXT/modules/ClientDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,36 +373,36 @@ void ClientDLL::FindStuff()
{
switch (pattern - patterns::shared::PM_Jump.cbegin())
{
case 0:
case 1:
case 0: // HL-SteamPipe
case 1: // gunman
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 2);
break;
case 2: // AG-Server, shouldn't happen here but who knows.
case 3:
case 3: // AG-Client
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 3);
break;
case 4:
case 4: // BigLolly
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 21);
break;
case 10:
case 11:
case 5:
case 10: // Parasomnia
case 11: // Reissues
case 5: // TWHL-Tower-2
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 5);
break;
case 12:
case 6:
case 14:
case 12: // HL-SWEET
case 6: // Decay
case 14: // CoF-Mod-155
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 24);
break;
case 7:
case 7: // Halfquake-Trilogy
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 6);
break;
case 8:
case 9:
case 13:
case 8: // Half-Payne
case 9: // DSM-Demo-1
case 13: // CoF-5936
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 8);
break;
case 15:
case 15: // CoF-Mod-155-Client
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 9);
break;
}
Expand Down
26 changes: 26 additions & 0 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ void HwDLL::Clear()
ServerDLL::GetInstance().pEngfuncs = nullptr;
ppGlobals = nullptr;
pEngStudio = nullptr;
pEngineAPI = nullptr;

registeredVarsAndCmds = false;
autojump = false;
Expand Down Expand Up @@ -1335,6 +1336,20 @@ void HwDLL::FindStuff()
}
});

void* Sys_EngineAPI;
auto fSys_EngineAPI = FindAsync(
Sys_EngineAPI,
patterns::engine::Sys_EngineAPI,
[&](auto pattern) {
switch (pattern - patterns::engine::Sys_EngineAPI.cbegin())
{
default:
case 0: // HL-WON-1712
pEngineAPI = *reinterpret_cast<engine_api_t**>(reinterpret_cast<uintptr_t>(Sys_EngineAPI) + 41);
break;
}
});

void* ClientDLL_Init;
auto fClientDLL_Init = FindAsync(
ClientDLL_Init,
Expand Down Expand Up @@ -1898,6 +1913,17 @@ void HwDLL::FindStuff()
}
}

{
auto pattern = fSys_EngineAPI.get();
if (Sys_EngineAPI) {
EngineDevMsg("[hw dll] Found Sys_EngineAPI at %p (using the %s pattern).\n", Sys_EngineAPI, pattern->name());
EngineDevMsg("[hw dll] Found engineapi at %p.\n", pEngineAPI);
}
else {
EngineDevWarning("[hw dll] Could not find Sys_EngineAPI.\n");
}
}

{
auto pattern = fClientDLL_Init.get();
if (ClientDLL_Init) {
Expand Down
1 change: 1 addition & 0 deletions BunnymodXT/modules/HwDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class HwDLL : public IHookableNameFilterOrdered

globalvars_t *ppGlobals;
engine_studio_api_t *pEngStudio;
engine_api_t *pEngineAPI;

inline const char* GetString(int string) const {
assert(ppGlobals);
Expand Down
49 changes: 25 additions & 24 deletions BunnymodXT/modules/ServerDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,36 +406,36 @@ void ServerDLL::FindStuff()
{
switch (pattern - patterns::shared::PM_Jump.cbegin())
{
case 0:
case 1:
case 0: // HL-SteamPipe
case 1: // gunman
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 2);
break;
case 2:
case 2: // AG-Server
case 3: // AG-Client, shouldn't happen here but who knows.
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 3);
break;
case 4:
case 4: // BigLolly
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 21);
break;
case 10:
case 11:
case 5:
case 10: // Parasomnia
case 11: // Reissues
case 5: // TWHL-Tower-2
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 5);
break;
case 12:
case 6:
case 14:
case 12: // HL-SWEET
case 6: // Decay
case 14: // CoF-Mod-155
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 24);
break;
case 7:
case 7: // Halfquake-Trilogy
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 6);
break;
case 8:
case 9:
case 13:
case 8: // Half-Payne
case 9: // DSM-Demo-1
case 13: // CoF-5936
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 8);
break;
case 15:
case 15: // CoF-Mod-155-Client
ppmove = *reinterpret_cast<void***>(reinterpret_cast<uintptr_t>(ORIG_PM_Jump) + 9);
break;
}
Expand Down Expand Up @@ -810,6 +810,7 @@ void ServerDLL::FindStuff()
pDispatchRestore,
patterns::server::DispatchRestore,
[&](auto pattern) {
// HL-SteamPipe
pGlobalState = *reinterpret_cast<void**>(pDispatchRestore + 153);
});

Expand Down Expand Up @@ -1031,15 +1032,15 @@ void ServerDLL::FindStuff()
patterns::server::CGraph__InitGraph,
[&](auto pattern) {
switch (pattern - patterns::server::CGraph__InitGraph.cbegin()) {
case 0: // HL-SteamPipe
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 0: // HL-SteamPipe
case 1: // TWHL-Tower-2
case 2: // Echoes
case 3: // Decay
case 4: // Halfquake-Trilogy
case 5: // Parasomnia
case 6: // HL-SWEET
case 7: // Reissues
case 8: // CoF-5936
offm_pNodes = 0x0C;
offm_vecOrigin = 0x00;
offm_cNodes = 0x18;
Expand Down
5 changes: 5 additions & 0 deletions BunnymodXT/patterns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ namespace patterns
"55 8B EC 51 E8 ?? ?? ?? ?? 83 3D ?? ?? ?? ?? 00 75"
);

PATTERNS(Sys_EngineAPI,
"HL-WON-1712",
"8B 4C 24 ?? B8 01 00 00 00 3B C8 74 ?? 33 C0 C3 81 7C 24 ?? F0 00 00 00"
);

PATTERNS(ClientDLL_Init,
"HL-SteamPipe",
"55 8B EC 81 EC 00 02 00 00 68 ?? ?? ?? ?? 8D 85 ?? ?? ?? ?? 68",
Expand Down
1 change: 1 addition & 0 deletions BunnymodXT/stdafx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ using std::ptrdiff_t;
#include "HLSDK/common/event_args.h"
#include "HLSDK/common/demo_api.h"
#include "HLSDK/common/r_studioint.h"
#include "HLSDK/common/engine_launcher_api.h"
#include "HLSDK/engine/studio.h"
#include "HLSDK/engine/cmd.h"

Expand Down
101 changes: 101 additions & 0 deletions HLSDK/common/engine_launcher_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// engine/launcher interface
#if !defined( ENGINE_LAUNCHER_APIH )
#define ENGINE_LAUNCHER_APIH
#ifdef _WIN32
#pragma once
#endif

//typedef void ( *xcommand_t ) ( void );

#define RENDERTYPE_UNDEFINED 0
#define RENDERTYPE_SOFTWARE 1
#define RENDERTYPE_HARDWARE 2

#define ENGINE_LAUNCHER_API_VERSION 1

typedef struct engine_api_s
{
int version;
int rendertype;
int size;

// Functions
int ( *GetEngineState ) ( void );
void ( *Cbuf_AddText ) ( char *text ); // append cmd at end of buf
void ( *Cbuf_InsertText ) ( char *text ); // insert cmd at start of buf
void ( *Cmd_AddCommand ) ( char *cmd_name, void ( *funcname )( void ) );
int ( *Cmd_Argc ) ( void );
char *( *Cmd_Args ) ( void );
char *( *Cmd_Argv ) ( int arg );
void ( *Con_Printf ) ( char *, ... );
void ( *Con_SafePrintf ) ( char *, ... );
void ( *Cvar_Set ) ( char *var_name, char *value );
void ( *Cvar_SetValue ) ( char *var_name, float value );
int ( *Cvar_VariableInt ) ( char *var_name );
char *( *Cvar_VariableString ) ( char *var_name );
float ( *Cvar_VariableValue ) ( char *var_name );
void ( *ForceReloadProfile ) ( void );
int ( *GetGameInfo ) ( struct GameInfo_s *pGI, char *pszChannel );
void ( *GameSetBackground ) ( int bBack );
void ( *GameSetState ) ( int iState );
void ( *GameSetSubState ) ( int iState );
int ( *GetPauseState ) ( void );
int ( *Host_Frame ) ( float time, int iState, int *stateInfo );
void ( *Host_GetHostInfo ) ( float *fps, int *nActive, int *nSpectators, int *nMaxPlayers, char *pszMap );
void ( *Host_Shutdown ) ( void );
int ( *Game_Init ) ( char *lpCmdLine, unsigned char *pMem, int iSize, struct exefuncs_s *pef, void *, int );
void ( *IN_ActivateMouse ) ( void );
void ( *IN_ClearStates ) ( void );
void ( *IN_DeactivateMouse ) ( void );
void ( *IN_MouseEvent ) ( int mstate );
void ( *Keyboard_ReturnToGame ) ( void );
void ( *Key_ClearStates ) ( void );
void ( *Key_Event ) ( int key, int down );
int ( *LoadGame ) ( const char *pszSlot );
void ( *S_BlockSound ) ( void );
void ( *S_ClearBuffer ) ( void );
void ( *S_GetDSPointer ) ( struct IDirectSound **lpDS, struct IDirectSoundBuffer **lpDSBuf );
void *( *S_GetWAVPointer ) ( void );
void ( *S_UnblockSound ) ( void );
int ( *SaveGame ) ( const char *pszSlot, const char *pszComment );
void ( *SetAuth ) ( void *pobj );
void ( *SetMessagePumpDisableMode ) ( int bMode );
void ( *SetPauseState ) ( int bPause );
void ( *SetStartupMode ) ( int bMode );
void ( *SNDDMA_Shutdown ) ( void );
void ( *Snd_AcquireBuffer ) ( void );
void ( *Snd_ReleaseBuffer ) ( void );
void ( *StoreProfile ) ( void );
double ( *Sys_FloatTime ) ( void );
void ( *VID_UpdateWindowVars ) ( void *prc, int x, int y );
void ( *VID_UpdateVID ) ( struct viddef_s *pvid );

// VGUI interfaces
void ( *VGui_CallEngineSurfaceProc ) ( void* hwnd, unsigned int msg, unsigned int wparam, long lparam );

// notifications that the launcher is taking/giving focus to the engine
void ( *EngineTakingFocus ) ( void );
void ( *LauncherTakingFocus ) ( void );

#ifdef _WIN32
// Only filled in by rendertype RENDERTYPE_HARDWARE
void ( *GL_Init ) ( void );
int ( *GL_SetMode ) ( HWND hwndGame, HDC *pmaindc, HGLRC *pbaseRC, int fD3D, const char *p, const char *pszCmdLine );
void ( *GL_Shutdown ) ( HWND hwnd, HDC hdc, HGLRC hglrc );

void ( *QGL_D3DShared ) ( struct tagD3DGlobals *d3dGShared );

int ( WINAPI *glSwapBuffers ) ( HDC dc );
#else
// NOT USED IN LINUX!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void ( *GL_Init ) ( void );
void ( *GL_SetMode ) ( void );
void ( *GL_Shutdown ) ( void );
void ( *QGL_D3DShared ) ( void );
void ( *glSwapBuffers ) ( void );
// LINUX
#endif

} engine_api_t;

#endif // ENGINE_LAUNCHER_APIH
2 changes: 2 additions & 0 deletions HLSDK/common/r_studioint.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ typedef struct engine_studio_api_s
void ( *GL_StudioDrawShadow ) ( void );
void ( *GL_SetRenderMode ) ( int mode );

// Functions below are present only in builds > 1712

void ( *StudioSetRenderamt ) (int iRenderamt); //!!!CZERO added for rendering glass on viewmodels
void ( *StudioSetCullState ) ( int iCull );
void ( *StudioRenderShadow ) ( int iSprite, float *p1, float *p2, float *p3, float *p4 );
Expand Down
3 changes: 3 additions & 0 deletions HLSDK/common/triangleapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ typedef struct triangleapi_s
void ( *CullFace ) ( TRICULLSTYLE style );
int ( *SpriteTexture ) ( struct model_s *pSpriteModel, int frame );
int ( *WorldToScreen ) ( float *world, float *screen ); // Returns 1 if it's z clipped

// Functions below are present only in builds > 1712

void ( *Fog ) ( float flFogColor[3], float flStart, float flEnd, int bOn ); // Works just like GL_FOG, flFogColor is r/g/b.
void ( *ScreenToWorld ) ( float *screen, float *world );
void ( *GetMatrix ) ( const int pname, float *matrix );
Expand Down
13 changes: 11 additions & 2 deletions HLSDK/engine/cdll_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ typedef struct cl_enginefuncs_s
struct event_api_s *pEventAPI;
struct demo_api_s *pDemoAPI;
struct net_api_s *pNetAPI;

// Functions below are present only in builds > 1712

struct IVoiceTweak_s *pVoiceTweak;

// returns 1 if the client is a spectator only (connected to a proxy), 0 otherwise or 2 if in dev_overview mode
Expand Down Expand Up @@ -292,12 +295,18 @@ typedef struct cl_enginefuncs_s
void (*pfnResetTutorMessageDecayData)( void );

void (*pfnPlaySoundByNameAtPitch)( const char *szSound, float volume, int pitch );
void (*pfnFillRGBABlend)( int x, int y, int width, int height, int r, int g, int b, int a );
void (*pfnFillRGBABlend)( int x, int y, int width, int height, int r, int g, int b, int a );

// Functions below are present only in builds > 3248

int (*pfnGetAppID)( void );
cmdalias_t *(*pfnGetAliases)( void );

// Functions below are present only in builds > 4554

void (*pfnVguiWrap2_GetMouseDelta)( int *x, int *y );

// added in 2019 update, not documented yet
// Added in 2019 update, not documented yet
int (*pfnFilteredClientCmd)( const char *cmd );
} cl_enginefunc_t;

Expand Down
9 changes: 7 additions & 2 deletions HLSDK/engine/eiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ typedef struct enginefuncs_s

void (*pfnGetPlayerStats) ( const edict_t *pClient, int *ping, int *packet_loss );

void (*pfnAddServerCommand) ( const char *cmd_name, void (*function) (void) );
void (*pfnAddServerCommand) ( const char *cmd_name, void (*function) (void) );

// Functions below are present only in builds > 1712

// For voice communications, set which clients hear eachother.
// NOTE: these functions take player entity indices (starting at 1).
Expand All @@ -273,10 +275,13 @@ typedef struct enginefuncs_s
void (*pfnConstructTutorMessageDecayBuffer)( int *buffer, int bufferLength );
void (*pfnResetTutorMessageDecayData)( void );
void (*pfnQueryClientCvarValue)( const edict_t *player, const char *cvarName );

// Functions below are present only in builds > 3248

void (*pfnQueryClientCvarValue2)( const edict_t *player, const char *cvarName, int requestID );
int (*CheckParm)( char *parm, char **ppnext );

// added in 8279
// Added in 8279
edict_t* (*pfnPEntityOfEntIndexAllEntities)( int iEntIndex );
} enginefuncs_t;
// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 138
Expand Down

0 comments on commit f8c6c5d

Please sign in to comment.