r5sdk/r5dev/pluginsystem/modsystem.h
Kawe Mazidjatari 15244bf27a Modsystem improvements
- Added command line parameter '-modsystem_debug' to allow debugging during init, as we initialize before the first Cbuf_Execute() call (responsible for executing command line post engine init).
- Added warning to 'CLocalize::LoadLocalizationFileLists', when a mod localization file fails to load.
- All mod instances are now added to a single vector, but their 'state' determine whether or not they are enabled. This allows for toggling them on while in-game in the future, without having to rebuild the engine mod list.
- Changed all filesystem calls to use that of the engine instead.
- Changed all container types to valve ones, to maintain compatibility with the filesystem of the engine, and perhaps other things in the future.
- Forced all loads/writes to "PLATFORM" path (this is where the 'mods' folder resides).
- Forced localization files to be only read from the mod instance's directory.
- Allocated each mod instance dynamically, and stored their pointers in the modlist vector to reduce memory overhead during the move operation to modlist, and potential growth of modlist vector (which if required, will reallocate everything, and thus move it all. This especially is expensive with nested vectors (CUtlVector anly supports being nested as a pointer)).
2023-07-09 22:49:46 +02:00

80 lines
2.0 KiB
C++

#pragma once
#include "vpc/keyvalues.h"
#include "vpc/rson.h"
#include "filesystem/filesystem.h"
#include "public/vscript/ivscript.h"
#define MOD_STATUS_LIST_FILE "mods.vdf"
#define MOD_SETTINGS_FILE "mod.vdf"
#define MOD_BASE_DIRECTORY "mods"
class CModAppSystemGroup;
class CModSystem
{
public:
enum eModState : int8_t
{
UNLOADED = -1, // loading was unsuccessful (error occurred)
LOADING, // if mod is being loaded
LOADED, // if a mod has been loaded
DISABLED, // if disabled by user
ENABLED, // if enabled by user and loaded properly
};
struct ModInstance_t
{
ModInstance_t(const CUtlString& basePath);
~ModInstance_t();
bool ParseSettings();
void ParseConVars();
void ParseLocalizationFiles();
inline void SetState(eModState state) { m_iState = state; };
inline bool IsLoaded() const { return m_iState == eModState::LOADED; };
inline bool IsEnabled() const { return m_iState == eModState::ENABLED; };
inline const CUtlString& GetBasePath() const { return m_BasePath; };
inline CUtlString GetScriptCompileListPath() const { return m_BasePath + GAME_SCRIPT_COMPILELIST; };
KeyValues* GetRequiredSettingsKey(const char* settingsPath, const char* key) const;
inline RSON::Node_t* LoadScriptCompileList() const
{
return RSON::LoadFromFile(GetScriptCompileListPath().Get(), "PLATFORM");
};
KeyValues* m_SettingsKV;
eModState m_iState = eModState::UNLOADED;
bool m_bHasScriptCompileList; // if this mod has a scripts.rson file that exists
CUtlVector<CUtlString> m_LocalizationFiles;
CUtlString m_Name;
CUtlString m_ModID;
CUtlString m_Description;
CUtlString m_Version;
CUtlString m_BasePath;
};
~CModSystem();
void Init();
// load mod enabled/disabled status from file on disk
void UpdateModStatusList();
void LoadModStatusList(CUtlMap<CUtlString, bool>& enabledList);
void WriteModStatusList();
const inline CUtlVector<ModInstance_t*>& GetModList() { return m_ModList; };
private:
CUtlVector<ModInstance_t*> m_ModList;
};
extern CModSystem* g_pModSystem;