aboutsummaryrefslogtreecommitdiff
path: root/primedev/core/convar/concommand.cpp
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2023-12-27 00:32:01 +0000
committerGitHub <noreply@github.com>2023-12-27 01:32:01 +0100
commitf5ab6fb5e8be7b73e6003d4145081d5e0c0ce287 (patch)
tree90f2c6a4885dbd181799e2325cf33588697674e1 /primedev/core/convar/concommand.cpp
parentbb8ed59f6891b1196c5f5bbe7346cd171c8215fa (diff)
downloadNorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.tar.gz
NorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.zip
Folder restructuring from primedev (#624)v1.21.2-rc3v1.21.2
Copies of over the primedev folder structure for easier cherry-picking of further changes Co-authored-by: F1F7Y <filip.bartos07@proton.me>
Diffstat (limited to 'primedev/core/convar/concommand.cpp')
-rw-r--r--primedev/core/convar/concommand.cpp157
1 files changed, 157 insertions, 0 deletions
diff --git a/primedev/core/convar/concommand.cpp b/primedev/core/convar/concommand.cpp
new file mode 100644
index 00000000..41f54c76
--- /dev/null
+++ b/primedev/core/convar/concommand.cpp
@@ -0,0 +1,157 @@
+#include "concommand.h"
+#include "shared/misccommands.h"
+#include "engine/r2engine.h"
+
+#include "plugins/pluginbackend.h"
+#include "plugins/plugin_abi.h"
+
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+// 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 m_nFlags & nFlags;
+}
+
+//-----------------------------------------------------------------------------
+// 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;
+}
+
+typedef void (*ConCommandConstructorType)(
+ ConCommand* newCommand, const char* name, FnCommandCallback_t callback, const char* helpString, int flags, void* parent);
+ConCommandConstructorType ConCommandConstructor;
+
+void RegisterConCommand(const char* name, FnCommandCallback_t callback, 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 RegisterConCommand(
+ const char* name, FnCommandCallback_t callback, const char* helpString, int flags, FnCommandCompletionCallback completionCallback)
+{
+ 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);
+ newCommand->m_pCompletionCallback = completionCallback;
+}
+
+ON_DLL_LOAD("engine.dll", ConCommand, (CModule module))
+{
+ ConCommandConstructor = module.Offset(0x415F60).RCast<ConCommandConstructorType>();
+ AddMiscConCommands();
+
+ g_pPluginCommunicationhandler->m_sEngineData.ConCommandConstructor =
+ reinterpret_cast<PluginConCommandConstructorType>(ConCommandConstructor);
+}