Skip to content

Commit

Permalink
Add support for mod settings
Browse files Browse the repository at this point in the history
  • Loading branch information
OrfeasZ committed Dec 30, 2023
1 parent ff36dae commit ed3a0d0
Show file tree
Hide file tree
Showing 10 changed files with 662 additions and 47 deletions.
4 changes: 4 additions & 0 deletions ZHMModSDK/Include/Glacier/ZString.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class ZString
m_nLength = static_cast<uint32_t>(str.size()) | 0x80000000;
}

ZString(const std::string& str) {
Allocate(str.c_str(), str.size());
}

ZString(const char* str) :
m_pChars(str)
{
Expand Down
118 changes: 118 additions & 0 deletions ZHMModSDK/Include/IModSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,124 @@ class IModSDK
virtual bool PatchCode(const char* p_Pattern, const char* p_Mask, void* p_NewCode, size_t p_CodeSize, ptrdiff_t p_Offset) = 0;

virtual void ImGuiGameRenderTarget(ZRenderDestination* p_RT, const ImVec2& p_Size = { 0, 0 }) = 0;

/**
* Set a plugin setting value for the given name.
* @param p_Plugin The plugin to set the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
virtual void SetPluginSetting(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, const ZString& p_Value) = 0;

/**
* Set a plugin setting integer value for the given name.
* @param p_Plugin The plugin to set the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
virtual void SetPluginSettingInt(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, int64 p_Value) = 0;

/**
* Set a plugin setting unsigned integer value for the given name.
* @param p_Plugin The plugin to set the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
virtual void SetPluginSettingUInt(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, uint64 p_Value) = 0;

/**
* Set a plugin setting double value for the given name.
* @param p_Plugin The plugin to set the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
virtual void SetPluginSettingDouble(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, double p_Value) = 0;

/**
* Set a plugin setting boolean value for the given name.
* @param p_Plugin The plugin to set the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
virtual void SetPluginSettingBool(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, bool p_Value) = 0;

/**
* Get a plugin setting string value for the given name.
* @param p_Plugin The plugin to get the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist.
* @return The value of the setting, or the default value if the setting does not exist.
*/
virtual ZString GetPluginSetting(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, const ZString& p_DefaultValue) = 0;

/**
* Get a plugin setting integer value for the given name.
* @param p_Plugin The plugin to get the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist or is not an integer.
* @return The value of the setting, or the default value if the setting does not exist or is not an integer.
*/
virtual int64 GetPluginSettingInt(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, int64 p_DefaultValue) = 0;

/**
* Get a plugin setting unsigned integer value for the given name.
* @param p_Plugin The plugin to get the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist or is not an unsigned integer.
* @return The value of the setting, or the default value if the setting does not exist or is not an unsigned integer.
*/
virtual uint64 GetPluginSettingUInt(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, uint64 p_DefaultValue) = 0;

/**
* Get a plugin setting double value for the given name.
* @param p_Plugin The plugin to get the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist or is not a double.
* @return The value of the setting, or the default value if the setting does not exist or is not a double.
*/
virtual double GetPluginSettingDouble(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, double p_DefaultValue) = 0;

/**
* Get a plugin setting boolean value for the given name.
* @param p_Plugin The plugin to get the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist or is not a boolean.
* @return The value of the setting, or the default value if the setting does not exist or is not a boolean.
*/
virtual bool GetPluginSettingBool(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name, bool p_DefaultValue) = 0;

/**
* Check if a plugin setting with the given name exists.
* @param p_Plugin The plugin to check the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @return True if the setting exists, false otherwise.
*/
virtual bool HasPluginSetting(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name) = 0;

/**
* Remove a plugin setting with the given name.
* @param p_Plugin The plugin to remove the setting for.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
*/
virtual void RemovePluginSetting(IPluginInterface* p_Plugin, const ZString& p_Section, const ZString& p_Name) = 0;

/**
* Reload the settings for the given plugin.
* @param p_Plugin The plugin to reload the settings for.
*/
virtual void ReloadPluginSettings(IPluginInterface* p_Plugin) = 0;
};

/**
Expand Down
132 changes: 132 additions & 0 deletions ZHMModSDK/Include/IPluginInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,138 @@ class IPluginInterface
virtual void OnDrawUI(bool p_HasFocus) {}
virtual void OnDraw3D(IRenderer* p_Renderer) {}
virtual void OnDrawMenu() {}

public:
/**
* Set a setting string value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
void SetSetting(const ZString& p_Section, const ZString& p_Name, const ZString& p_Value) {
SDK()->SetPluginSetting(this, p_Section, p_Name, p_Value);
}

/**
* Set a setting integer value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
void SetSettingInt(const ZString& p_Section, const ZString& p_Name, int64 p_Value) {
SDK()->SetPluginSettingInt(this, p_Section, p_Name, p_Value);
}

/**
* Set a setting unsigned integer value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
void SetSettingUInt(const ZString& p_Section, const ZString& p_Name, uint64 p_Value) {
SDK()->SetPluginSettingUInt(this, p_Section, p_Name, p_Value);
}

/**
* Set a setting double value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
void SetSettingDouble(const ZString& p_Section, const ZString& p_Name, double p_Value) {
SDK()->SetPluginSettingDouble(this, p_Section, p_Name, p_Value);
}

/**
* Set a setting boolean value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_Value The value of the setting.
*/
void SetSettingBool(const ZString& p_Section, const ZString& p_Name, bool p_Value) {
SDK()->SetPluginSettingBool(this, p_Section, p_Name, p_Value);
}

/**
* Get a setting string value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist.
* @return The value of the setting, or the default value if the setting does not exist.
*/
ZString GetSetting(const ZString& p_Section, const ZString& p_Name, const ZString& p_DefaultValue) {
return SDK()->GetPluginSetting(this, p_Section, p_Name, p_DefaultValue);
}

/**
* Get a setting integer value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist or is not an integer.
* @return The value of the setting, or the default value if the setting does not exist or is not an integer.
*/
int64 GetSettingInt(const ZString& p_Section, const ZString& p_Name, int64 p_DefaultValue) {
return SDK()->GetPluginSettingInt(this, p_Section, p_Name, p_DefaultValue);
}

/**
* Get a setting unsigned integer value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist or is not an unsigned integer.
* @return The value of the setting, or the default value if the setting does not exist or is not an unsigned integer.
*/
uint64 GetSettingUInt(const ZString& p_Section, const ZString& p_Name, uint64 p_DefaultValue) {
return SDK()->GetPluginSettingUInt(this, p_Section, p_Name, p_DefaultValue);
}

/**
* Get a setting double value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist or is not a double.
* @return The value of the setting, or the default value if the setting does not exist or is not a double.
*/
double GetSettingDouble(const ZString& p_Section, const ZString& p_Name, double p_DefaultValue) {
return SDK()->GetPluginSettingDouble(this, p_Section, p_Name, p_DefaultValue);
}

/**
* Get a setting boolean value for the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @param p_DefaultValue The default value to return if the setting does not exist or is not a boolean.
* @return The value of the setting, or the default value if the setting does not exist or is not a boolean.
*/
bool GetSettingBool(const ZString& p_Section, const ZString& p_Name, bool p_DefaultValue) {
return SDK()->GetPluginSettingBool(this, p_Section, p_Name, p_DefaultValue);
}

/**
* Check if a setting with the given name exists.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
* @return True if the setting exists, false otherwise.
*/
bool HasSetting(const ZString& p_Section, const ZString& p_Name) {
return SDK()->HasPluginSetting(this, p_Section, p_Name);
}

/**
* Remove a setting with the given name.
* @param p_Section The section of the setting in the INI file.
* @param p_Name The name of the setting.
*/
void RemoveSetting(const ZString& p_Section, const ZString& p_Name) {
SDK()->RemovePluginSetting(this, p_Section, p_Name);
}

/**
* Reload the settings for the current plugin.
*/
void ReloadSettings() {
SDK()->ReloadPluginSettings(this);
}

friend class ModSDK;
};
Expand Down
3 changes: 2 additions & 1 deletion ZHMModSDK/Src/Glacier/ZString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ZString::~ZString()
void ZString::Allocate(const char* str, size_t size)
{
m_nLength = static_cast<uint32_t>(size);
m_pChars = reinterpret_cast<char*>((*Globals::MemoryManager)->m_pNormalAllocator->Allocate(size));
m_pChars = reinterpret_cast<char*>((*Globals::MemoryManager)->m_pNormalAllocator->Allocate(size + 1));
memcpy(const_cast<char*>(m_pChars), str, size);
const_cast<char*>(m_pChars)[size] = '\0';
}
Loading

0 comments on commit ed3a0d0

Please sign in to comment.