Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create event scripts if they don't exist #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cl_dll/cdll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ void DLLEXPORT HUD_PlayerMove(struct playermove_s* ppmove, int server)

static bool CL_InitClient()
{
EV_HookEvents();
CL_LoadParticleMan();

if (!FileSystem_LoadFileSystem())
Expand All @@ -128,6 +127,8 @@ static bool CL_InitClient()
return false;
}

EV_HookEvents();

// get tracker interface, if any
return true;
}
Expand Down
1 change: 0 additions & 1 deletion cl_dll/com_weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,5 @@ stub functions for such things as precaching. So we don't have to modify weapon
*/
int stub_PrecacheModel(const char* s) { return 0; }
int stub_PrecacheSound(const char* s) { return 0; }
unsigned short stub_PrecacheEvent(int type, const char* s) { return 0; }
const char* stub_NameForFunction(uint32 function) { return "func"; }
void stub_SetModel(edict_t* e, const char* m) {}
1 change: 0 additions & 1 deletion cl_dll/com_weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void HUD_PlaybackEvent(int flags, const struct edict_s* pInvoker, unsigned short
void HUD_SetMaxSpeed(const struct edict_s* ed, float speed);
int stub_PrecacheModel(const char* s);
int stub_PrecacheSound(const char* s);
unsigned short stub_PrecacheEvent(int type, const char* s);
const char* stub_NameForFunction(uint32 function);
void stub_SetModel(struct edict_s* e, const char* m);

Expand Down
48 changes: 28 additions & 20 deletions cl_dll/hl/hl_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
#include "event_api.h"
#include "pmtrace.h"
#include "ev_hldm.h"
#include "filesystem_utils.h"

static void Game_HookEvent(const char* const szEventName, void (*const pfnEvent)(event_args_t*))
{
UTIL_CheckEventScript(szEventName);

gEngfuncs.pfnHookEvent(szEventName, pfnEvent);
}

/*
======================
Expand All @@ -32,24 +40,24 @@ That was what we were going to do, but we ran out of time...oh well.
*/
void Game_HookEvents()
{
gEngfuncs.pfnHookEvent("events/glock1.sc", EV_FireGlock1);
gEngfuncs.pfnHookEvent("events/glock2.sc", EV_FireGlock2);
gEngfuncs.pfnHookEvent("events/shotgun1.sc", EV_FireShotGunSingle);
gEngfuncs.pfnHookEvent("events/shotgun2.sc", EV_FireShotGunDouble);
gEngfuncs.pfnHookEvent("events/mp5.sc", EV_FireMP5);
gEngfuncs.pfnHookEvent("events/mp52.sc", EV_FireMP52);
gEngfuncs.pfnHookEvent("events/python.sc", EV_FirePython);
gEngfuncs.pfnHookEvent("events/gauss.sc", EV_FireGauss);
gEngfuncs.pfnHookEvent("events/gaussspin.sc", EV_SpinGauss);
gEngfuncs.pfnHookEvent("events/train.sc", EV_TrainPitchAdjust);
gEngfuncs.pfnHookEvent("events/vehicle.sc", EV_VehiclePitchAdjust);
gEngfuncs.pfnHookEvent("events/crowbar.sc", EV_Crowbar);
gEngfuncs.pfnHookEvent("events/crossbow1.sc", EV_FireCrossbow);
gEngfuncs.pfnHookEvent("events/crossbow2.sc", EV_FireCrossbow2);
gEngfuncs.pfnHookEvent("events/rpg.sc", EV_FireRpg);
gEngfuncs.pfnHookEvent("events/egon_fire.sc", EV_EgonFire);
gEngfuncs.pfnHookEvent("events/egon_stop.sc", EV_EgonStop);
gEngfuncs.pfnHookEvent("events/firehornet.sc", EV_HornetGunFire);
gEngfuncs.pfnHookEvent("events/tripfire.sc", EV_TripmineFire);
gEngfuncs.pfnHookEvent("events/snarkfire.sc", EV_SnarkFire);
Game_HookEvent("events/glock1.sc", EV_FireGlock1);
Game_HookEvent("events/glock2.sc", EV_FireGlock2);
Game_HookEvent("events/shotgun1.sc", EV_FireShotGunSingle);
Game_HookEvent("events/shotgun2.sc", EV_FireShotGunDouble);
Game_HookEvent("events/mp5.sc", EV_FireMP5);
Game_HookEvent("events/mp52.sc", EV_FireMP52);
Game_HookEvent("events/python.sc", EV_FirePython);
Game_HookEvent("events/gauss.sc", EV_FireGauss);
Game_HookEvent("events/gaussspin.sc", EV_SpinGauss);
Game_HookEvent("events/train.sc", EV_TrainPitchAdjust);
Game_HookEvent("events/vehicle.sc", EV_VehiclePitchAdjust);
Game_HookEvent("events/crowbar.sc", EV_Crowbar);
Game_HookEvent("events/crossbow1.sc", EV_FireCrossbow);
Game_HookEvent("events/crossbow2.sc", EV_FireCrossbow2);
Game_HookEvent("events/rpg.sc", EV_FireRpg);
Game_HookEvent("events/egon_fire.sc", EV_EgonFire);
Game_HookEvent("events/egon_stop.sc", EV_EgonStop);
Game_HookEvent("events/firehornet.sc", EV_HornetGunFire);
Game_HookEvent("events/tripfire.sc", EV_TripmineFire);
Game_HookEvent("events/snarkfire.sc", EV_SnarkFire);
}
1 change: 0 additions & 1 deletion cl_dll/hl/hl_weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ void HUD_InitClientWeapons()
// Fake functions
g_engfuncs.pfnPrecacheModel = stub_PrecacheModel;
g_engfuncs.pfnPrecacheSound = stub_PrecacheSound;
g_engfuncs.pfnPrecacheEvent = stub_PrecacheEvent;
g_engfuncs.pfnNameForFunction = stub_NameForFunction;
g_engfuncs.pfnSetModel = stub_SetModel;
g_engfuncs.pfnSetClientMaxspeed = HUD_SetMaxSpeed;
Expand Down
29 changes: 29 additions & 0 deletions game_shared/filesystem_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,32 @@ bool UTIL_IsValveGameDirectory()

return false;
}

bool UTIL_CheckEventScript(const char* const szEventScript)
{
if (g_pFileSystem->FileExists(szEventScript))
{
return true;
}

#ifdef CLIENT_DLL
gEngfuncs.Con_DPrintf("creating %s\n", szEventScript);
#else
ALERT(at_console, "creating %s\n", szEventScript);
#endif

FSFile eventScript {szEventScript, "w", "GAMECONFIG"};

if (eventScript.IsOpen())
{
return true;
}

#ifdef CLIENT_DLL
gEngfuncs.Con_DPrintf("failed to create %s\n", szEventScript);
#else
ALERT(at_console, "failed to create %s\n", szEventScript);
#endif

return false;
}
6 changes: 6 additions & 0 deletions game_shared/filesystem_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ bool FileSystem_WriteTextToFile(const char* fileName, const char* text, const ch
*/
bool UTIL_IsValveGameDirectory();

/**
* @brief Checks if the script file exists and, if not, attempts to create it.
* @return @c true if the script file exists or has been created
*/
bool UTIL_CheckEventScript(const char* const szEventScript);

/**
* @brief Helper class to automatically close the file handle associated with a file.
*/
Expand Down