Skip to content

Commit

Permalink
Merge pull request #88 from fortressforever/features/default-cfgs
Browse files Browse the repository at this point in the history
Generate <classname>.cfg/userconfig.cfg files at runtime if they don't exist
  • Loading branch information
squeek502 committed Dec 15, 2014
2 parents 800274d + 7f02632 commit 2ea366a
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 102 deletions.
113 changes: 11 additions & 102 deletions cl_dll/cdll_client_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
#include <cl_dll/iviewport.h>
// END: Added by Mulchman for team menu at level start up

// <-- FF
#include "ff_cdll_client_int.h"
extern CFFClient gFFClient;
// --> FF

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

Expand Down Expand Up @@ -405,119 +410,23 @@ void DisplayBoneSetupEnts()
#endif
}


//-----------------------------------------------------------------------------
// Purpose: engine to client .dll interface
//-----------------------------------------------------------------------------
class CHLClient : public IBaseClientDLL
{
public:
CHLClient();

virtual int Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, CGlobalVarsBase *pGlobals );

virtual void Shutdown( void );

virtual void LevelInitPreEntity( const char *pMapName );
virtual void LevelInitPostEntity();
virtual void LevelShutdown( void );

virtual ClientClass *GetAllClasses( void );

virtual int HudVidInit( void );
virtual void HudProcessInput( bool bActive );
virtual void HudUpdate( bool bActive );
virtual void HudReset( void );
virtual void HudText( const char * message );

// Mouse Input Interfaces
virtual void IN_ActivateMouse( void );
virtual void IN_DeactivateMouse( void );
virtual void IN_MouseEvent( int mstate, bool down );
virtual void IN_Accumulate( void );
virtual void IN_ClearStates( void );
virtual bool IN_IsKeyDown( const char *name, bool& isdown );
// Raw signal
virtual int IN_KeyEvent( int eventcode, int keynum, const char *pszCurrentBinding );
// Create movement command
virtual void CreateMove ( int sequence_number, float input_sample_frametime, bool active );
virtual void ExtraMouseSample( float frametime, bool active );
virtual bool WriteUsercmdDeltaToBuffer( bf_write *buf, int from, int to, bool isnewcommand );
virtual void EncodeUserCmdToBuffer( bf_write& buf, int slot );
virtual void DecodeUserCmdFromBuffer( bf_read& buf, int slot );


virtual void View_Render( vrect_t *rect );
virtual void RenderView( const CViewSetup &view, int nClearFlags, bool drawViewmodel );
virtual void View_Fade( ScreenFade_t *pSF );

virtual void SetCrosshairAngle( const QAngle& angle );

virtual void InitSprite( CEngineSprite *pSprite, const char *loadname );
virtual void ShutdownSprite( CEngineSprite *pSprite );

virtual int GetSpriteSize( void ) const;

virtual void VoiceStatus( int entindex, qboolean bTalking );

virtual void InstallStringTableCallback( const char *tableName );

virtual void FrameStageNotify( ClientFrameStage_t curStage );

virtual bool DispatchUserMessage( int msg_type, bf_read &msg_data );

// Save/restore system hooks
virtual CSaveRestoreData *SaveInit( int size );
virtual void SaveWriteFields( CSaveRestoreData *, const char *, void *, datamap_t *, typedescription_t *, int );
virtual void SaveReadFields( CSaveRestoreData *, const char *, void *, datamap_t *, typedescription_t *, int );
virtual void PreSave( CSaveRestoreData * );
virtual void Save( CSaveRestoreData * );
virtual void WriteSaveHeaders( CSaveRestoreData * );
virtual void ReadRestoreHeaders( CSaveRestoreData * );
virtual void Restore( CSaveRestoreData *, bool );
virtual void DispatchOnRestore();
virtual void WriteSaveGameScreenshot( const char *pFilename );

// Given a list of "S(wavname) S(wavname2)" tokens, look up the localized text and emit
// the appropriate close caption if running with closecaption = 1
virtual void EmitSentenceCloseCaption( char const *tokenstream );
virtual void EmitCloseCaption( char const *captionname, float duration );

virtual CStandardRecvProxies* GetStandardRecvProxies();

virtual bool CanRecordDemo( char *errorMsg, int length ) const;

// save game screenshot writing
virtual void WriteSaveGameScreenshotOfSize( const char *pFilename, int width, int height );

// See RenderViewInfo_t
virtual void RenderViewEx( const CViewSetup &view, int nClearFlags, int whatToDraw );

// Gets the location of the player viewpoint
virtual bool GetPlayerView( CViewSetup &playerView );

public:
void PrecacheMaterial( const char *pMaterialName );

private:
void UncacheAllMaterials( );

CUtlVector< IMaterial * > m_CachedMaterials;
};

/*
// Class definition moved to cdll_client_int.h, so that we can inherit from it
// FF sets its own version of these variables
CHLClient gHLClient;
IBaseClientDLL *clientdll = &gHLClient;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CHLClient, IBaseClientDLL, CLIENT_DLL_INTERFACE_VERSION, gHLClient );
*/


//-----------------------------------------------------------------------------
// Precaches a material
//-----------------------------------------------------------------------------
void PrecacheMaterial( const char *pMaterialName )
{
gHLClient.PrecacheMaterial( pMaterialName );
gFFClient.PrecacheMaterial( pMaterialName );
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1301,7 +1210,7 @@ void CHLClient::VoiceStatus( int entindex, qboolean bTalking )
void OnMaterialStringTableChanged( void *object, INetworkStringTable *stringTable, int stringNumber, const char *newString, void const *newData )
{
// Make sure this puppy is precached
gHLClient.PrecacheMaterial( newString );
gFFClient.PrecacheMaterial( newString );

RequestCacheUsedMaterials();
}
Expand Down
99 changes: 99 additions & 0 deletions cl_dll/cdll_client_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,105 @@ extern IAvi *avi;
extern bool g_bLevelInitialized;
extern bool g_bTextMode;

//-----------------------------------------------------------------------------
// Purpose: engine to client .dll interface
//-----------------------------------------------------------------------------
// FF: Class definition moved here from the .cpp so that we can inherit from it
class CHLClient : public IBaseClientDLL
{
public:
CHLClient();

virtual int Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, CGlobalVarsBase *pGlobals );

virtual void Shutdown( void );

virtual void LevelInitPreEntity( const char *pMapName );
virtual void LevelInitPostEntity();
virtual void LevelShutdown( void );

virtual ClientClass *GetAllClasses( void );

virtual int HudVidInit( void );
virtual void HudProcessInput( bool bActive );
virtual void HudUpdate( bool bActive );
virtual void HudReset( void );
virtual void HudText( const char * message );

// Mouse Input Interfaces
virtual void IN_ActivateMouse( void );
virtual void IN_DeactivateMouse( void );
virtual void IN_MouseEvent( int mstate, bool down );
virtual void IN_Accumulate( void );
virtual void IN_ClearStates( void );
virtual bool IN_IsKeyDown( const char *name, bool& isdown );
// Raw signal
virtual int IN_KeyEvent( int eventcode, int keynum, const char *pszCurrentBinding );
// Create movement command
virtual void CreateMove ( int sequence_number, float input_sample_frametime, bool active );
virtual void ExtraMouseSample( float frametime, bool active );
virtual bool WriteUsercmdDeltaToBuffer( bf_write *buf, int from, int to, bool isnewcommand );
virtual void EncodeUserCmdToBuffer( bf_write& buf, int slot );
virtual void DecodeUserCmdFromBuffer( bf_read& buf, int slot );


virtual void View_Render( vrect_t *rect );
virtual void RenderView( const CViewSetup &view, int nClearFlags, bool drawViewmodel );
virtual void View_Fade( ScreenFade_t *pSF );

virtual void SetCrosshairAngle( const QAngle& angle );

virtual void InitSprite( CEngineSprite *pSprite, const char *loadname );
virtual void ShutdownSprite( CEngineSprite *pSprite );

virtual int GetSpriteSize( void ) const;

virtual void VoiceStatus( int entindex, qboolean bTalking );

virtual void InstallStringTableCallback( const char *tableName );

virtual void FrameStageNotify( ClientFrameStage_t curStage );

virtual bool DispatchUserMessage( int msg_type, bf_read &msg_data );

// Save/restore system hooks
virtual CSaveRestoreData *SaveInit( int size );
virtual void SaveWriteFields( CSaveRestoreData *, const char *, void *, datamap_t *, typedescription_t *, int );
virtual void SaveReadFields( CSaveRestoreData *, const char *, void *, datamap_t *, typedescription_t *, int );
virtual void PreSave( CSaveRestoreData * );
virtual void Save( CSaveRestoreData * );
virtual void WriteSaveHeaders( CSaveRestoreData * );
virtual void ReadRestoreHeaders( CSaveRestoreData * );
virtual void Restore( CSaveRestoreData *, bool );
virtual void DispatchOnRestore();
virtual void WriteSaveGameScreenshot( const char *pFilename );

// Given a list of "S(wavname) S(wavname2)" tokens, look up the localized text and emit
// the appropriate close caption if running with closecaption = 1
virtual void EmitSentenceCloseCaption( char const *tokenstream );
virtual void EmitCloseCaption( char const *captionname, float duration );

virtual CStandardRecvProxies* GetStandardRecvProxies();

virtual bool CanRecordDemo( char *errorMsg, int length ) const;

// save game screenshot writing
virtual void WriteSaveGameScreenshotOfSize( const char *pFilename, int width, int height );

// See RenderViewInfo_t
virtual void RenderViewEx( const CViewSetup &view, int nClearFlags, int whatToDraw );

// Gets the location of the player viewpoint
virtual bool GetPlayerView( CViewSetup &playerView );

public:
void PrecacheMaterial( const char *pMaterialName );

private:
void UncacheAllMaterials( );

CUtlVector< IMaterial * > m_CachedMaterials;
};

// Returns true if a new OnDataChanged event is registered for this frame.
bool AddDataChangeEvent( IClientNetworkable *ent, DataUpdateType_t updateType, int *pStoredEvent );
Expand Down
8 changes: 8 additions & 0 deletions cl_dll/client_scratch-2005.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@
RelativePath=".\ff\clientmode_ff.h"
>
</File>
<File
RelativePath=".\ff\ff_cdll_client_int.cpp"
>
</File>
<File
RelativePath=".\ff\ff_cdll_client_int.h"
>
</File>
<File
RelativePath=".\ff\ff_glyph.cpp"
>
Expand Down
90 changes: 90 additions & 0 deletions cl_dll/ff/ff_cdll_client_int.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "cbase.h"
#include "ff_cdll_client_int.h"

#include "filesystem.h"
#include "ff_utils.h"

#define CLASSCFG_PATH "cfg/%s.cfg"
#define CLASSCFG_DEFAULT_PATH "cfg/classcfg_default.cfg"
// userconfig is a helper cfg for the default class configs
#define USERCONFIG_PATH "cfg/userconfig.cfg"
#define USERCONFIG_DEFAULT_PATH "cfg/userconfig_default.cfg"

int CFFClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, CGlobalVarsBase *pGlobals )
{
int ret = BaseClass::Init( appSystemFactory, physicsFactory, pGlobals );

PopulateMissingClassConfigs();
PopulateMissingUserConfig();

return ret;
}

void CFFClient::PopulateMissingClassConfigs()
{
bool bIsBufferPopulated = false;
CUtlBuffer bufferDefaultConfig;
char szConfigPath[MAX_PATH] = {0};

// it's still worth creating empty class .cfg files if the default cfg
// doesn't exist, so just mark the buffer as populated and continue as normal
if (!filesystem->FileExists(CLASSCFG_DEFAULT_PATH, "MOD"))
bIsBufferPopulated = true;

for (int iClass=CLASS_SCOUT; iClass<=CLASS_CIVILIAN; iClass++ )
{
Q_snprintf(szConfigPath, sizeof(szConfigPath), CLASSCFG_PATH, Class_IntToString(iClass));

// don't overwrite existing cfgs
if (filesystem->FileExists(szConfigPath))
continue;

// only read the file if we know theres a use for its contents
if (!bIsBufferPopulated)
{
// read in binary mode
FileHandle_t fileDefaultConfig = filesystem->Open(CLASSCFG_DEFAULT_PATH, "rb");

// if we fail to open the file, act like the file doesn't exist
// and generate blank class cfgs
if ( fileDefaultConfig != FILESYSTEM_INVALID_HANDLE )
{
filesystem->ReadToBuffer( fileDefaultConfig, bufferDefaultConfig );
filesystem->Close(fileDefaultConfig);
}

bIsBufferPopulated = true;
}

filesystem->WriteFile(szConfigPath, "MOD", bufferDefaultConfig);
}
}

void CFFClient::PopulateMissingUserConfig()
{
// don't overwrite existing cfgs
if (filesystem->FileExists(USERCONFIG_PATH, "MOD"))
return;

CUtlBuffer bufferDefaultConfig;

// if the default doesn't exist or fails to get read, then a blank
// userconfig.cfg will be created
if (filesystem->FileExists(USERCONFIG_DEFAULT_PATH, "MOD"))
{
FileHandle_t fileDefaultConfig = filesystem->Open(USERCONFIG_DEFAULT_PATH, "rb");

if ( fileDefaultConfig != FILESYSTEM_INVALID_HANDLE )
{
filesystem->ReadToBuffer( fileDefaultConfig, bufferDefaultConfig );
filesystem->Close(fileDefaultConfig);
}
}

filesystem->WriteFile(USERCONFIG_PATH, "MOD", bufferDefaultConfig);
}

CFFClient gFFClient;
IBaseClientDLL *clientdll = &gFFClient;

EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CFFClient, IBaseClientDLL, CLIENT_DLL_INTERFACE_VERSION, gFFClient );
29 changes: 29 additions & 0 deletions cl_dll/ff/ff_cdll_client_int.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef FF_CDLL_CLIENT_INT_H
#define FF_CDLL_CLIENT_INT_H
#pragma once

#include "cdll_client_int.h"

class CHLClient;

//-----------------------------------------------------------------------------
// Purpose: engine to client .dll interface
//-----------------------------------------------------------------------------
class CFFClient : public CHLClient
{
public:
// squeek: I couldn't get DECLARE_CLASS_NOBASE to compile in CHLClient, so I couldn't use DECLARE_CLASS here
// this works but it could potentially have negative consequences
DECLARE_CLASS_GAMEROOT( CFFClient, CHLClient );

// <-- Extended functions (meaning the BaseClass function is always called)
virtual int Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, CGlobalVarsBase *pGlobals );
// --> Extended functions

// <-- FF-specific functions
void PopulateMissingClassConfigs();
void PopulateMissingUserConfig();
// -->
};

#endif

0 comments on commit 2ea366a

Please sign in to comment.