diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-08-24 00:32:31 +0100 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2022-08-25 21:32:55 +0200 |
commit | 46bed8d09f32360377350d71816a76abdfbf2c7c (patch) | |
tree | 7feedae4910dbfe0e53d26ea1e00c4616d2c1850 /NorthstarDLL/concommand.cpp | |
parent | a97f1f07bb5aa31629cd87023e09669eb4bf1fe9 (diff) | |
download | NorthstarLauncher-46bed8d09f32360377350d71816a76abdfbf2c7c.tar.gz NorthstarLauncher-46bed8d09f32360377350d71816a76abdfbf2c7c.zip |
Adjust folder structure (#242)v1.9.5-rc1v1.9.5
* Adjust folder structure
* change launcher directory name
Diffstat (limited to 'NorthstarDLL/concommand.cpp')
-rw-r--r-- | NorthstarDLL/concommand.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/NorthstarDLL/concommand.cpp b/NorthstarDLL/concommand.cpp new file mode 100644 index 00000000..1bdda91b --- /dev/null +++ b/NorthstarDLL/concommand.cpp @@ -0,0 +1,140 @@ +#include "pch.h" +#include "concommand.h" +#include "gameutils.h" +#include "misccommands.h" +#include <iostream> + +typedef void (*ConCommandConstructorType)( + ConCommand* newCommand, const char* name, void (*callback)(const CCommand&), const char* helpString, int flags, void* parent); +ConCommandConstructorType conCommandConstructor; + +void RegisterConCommand(const char* name, void (*callback)(const CCommand&), const char* helpString, int flags) +{ + spdlog::info("Registering ConCommand {}", name); + + // no need to free this ever really, it should exist as long as game does + ConCommand* newCommand = new ConCommand; + conCommandConstructor(newCommand, name, callback, helpString, flags, nullptr); +} + +void InitialiseConCommands(HMODULE baseAddress) +{ + conCommandConstructor = (ConCommandConstructorType)((char*)baseAddress + 0x415F60); + AddMiscConCommands(); +} + +//----------------------------------------------------------------------------- +// Purpose: Returns true if this is a command +// Output : bool +//----------------------------------------------------------------------------- +bool ConCommand::IsCommand(void) const +{ + return true; +} + +//----------------------------------------------------------------------------- +// Purpose: Returns true if this is a command +// Output : bool +//----------------------------------------------------------------------------- +bool ConCommandBase::IsCommand(void) const +{ + return true; +} + +//----------------------------------------------------------------------------- +// Purpose: Has this cvar been registered +// Output : Returns true on success, false on failure. +//----------------------------------------------------------------------------- +bool ConCommandBase::IsRegistered(void) const +{ + return m_bRegistered; +} + +//----------------------------------------------------------------------------- +// Purpose: Test each ConCommand query before execution. +// Input : *pCommandBase - nFlags +// Output : False if execution is permitted, true if not. +//----------------------------------------------------------------------------- +bool ConCommandBase::IsFlagSet(int nFlags) const +{ + return false; // !TODO: Returning false on every query? (original implementation in Northstar before ConCommandBase refactor) +} + +//----------------------------------------------------------------------------- +// Purpose: Checks if ConCommand has requested flags. +// Input : nFlags - +// Output : True if ConCommand has nFlags. +//----------------------------------------------------------------------------- +bool ConCommandBase::HasFlags(int nFlags) +{ + return m_nFlags & nFlags; +} + +//----------------------------------------------------------------------------- +// Purpose: Add's flags to ConCommand. +// Input : nFlags - +//----------------------------------------------------------------------------- +void ConCommandBase::AddFlags(int nFlags) +{ + m_nFlags |= nFlags; +} + +//----------------------------------------------------------------------------- +// Purpose: Removes flags from ConCommand. +// Input : nFlags - +//----------------------------------------------------------------------------- +void ConCommandBase::RemoveFlags(int nFlags) +{ + m_nFlags &= ~nFlags; +} + +//----------------------------------------------------------------------------- +// Purpose: Returns current flags. +// Output : int +//----------------------------------------------------------------------------- +int ConCommandBase::GetFlags(void) const +{ + return m_nFlags; +} + +//----------------------------------------------------------------------------- +// Purpose: +// Output : const ConCommandBase +//----------------------------------------------------------------------------- +ConCommandBase* ConCommandBase::GetNext(void) const +{ + return m_pNext; +} + +//----------------------------------------------------------------------------- +// Purpose: Returns the ConCommandBase help text. +// Output : const char* +//----------------------------------------------------------------------------- +const char* ConCommandBase::GetHelpText(void) const +{ + return m_pszHelpString; +} + +//----------------------------------------------------------------------------- +// Purpose: Copies string using local new/delete operators +// Input : *szFrom - +// Output : char +//----------------------------------------------------------------------------- +char* ConCommandBase::CopyString(const char* szFrom) const +{ + size_t nLen; + char* szTo; + + nLen = strlen(szFrom); + if (nLen <= 0) + { + szTo = new char[1]; + szTo[0] = 0; + } + else + { + szTo = new char[nLen + 1]; + memmove(szTo, szFrom, nLen + 1); + } + return szTo; +} |