IConsole.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <CryCommon/platform.h>
  10. #include <AzCore/std/containers/vector.h>
  11. #include <AzCore/std/function/function_template.h>
  12. #include <AzCore/std/string/string_view.h>
  13. struct ConsoleBind;
  14. struct ICVar;
  15. class ITexture;
  16. struct ISystem;
  17. namespace AZ
  18. {
  19. class Name;
  20. }
  21. #define CVAR_INT 1
  22. #define CVAR_FLOAT 2
  23. #define CVAR_STRING 3
  24. // By default, cvars registered as const, read-only, or cheat cannot be modified in release builds for security.
  25. // The common practice has been to hard-code the default values of all these 'const' cvars before generating a release build.
  26. // However, this is restrictive because the cannot be modified at run-time in release, and so cannot differ between (or during) levels.
  27. // If you wish, you can disable this restriction by defining ALLOW_CONST_CVAR_MODIFICATIONS 1 (which is the default for non-release builds),
  28. // thus allowing const/read-only/cheat cvars to be set at run-time in release, and removing the need to explicitly hard-code your default values for release builds.
  29. #if defined(_RELEASE)
  30. #define ALLOW_AUDIT_CVARS 0
  31. #define ALLOW_CONST_CVAR_MODIFICATIONS AZ_TRAIT_CVARS_ENABLED_FOR_RELEASE_BUILDS
  32. #define LOG_CVAR_INFRACTIONS 0
  33. #define LOG_CVAR_USAGE 0
  34. #else
  35. #define ALLOW_AUDIT_CVARS 1
  36. #define ALLOW_CONST_CVAR_MODIFICATIONS 1
  37. #define LOG_CVAR_INFRACTIONS 1
  38. #define LOG_CVAR_USAGE 1
  39. #endif // defined(_RELEASE)
  40. #define CVAR_GROUPS_ARE_PRIVILEGED 1 // allows cvar groups to manipulate const/cheat cvars (turn off to log group cvar manipulation)
  41. #define LOG_CVAR_INFRACTIONS_CALLSTACK (LOG_CVAR_INFRACTIONS && 0) // logs the callstack when certain cvar issues arise; helpful in tracking down where the problem originated
  42. // If this flag is set during registering a console variable, and the variable exists,
  43. // then the variable will store its value in memory given by src
  44. #define CVF_CHANGE_SOURCE (1u << 16)
  45. // Flags used by ICVar
  46. enum EVarFlags
  47. {
  48. VF_NULL = 0x00000000, // just to have one recognizable spot where the flags are located in the Register call
  49. VF_CHEAT = 0x00000002, // stays in the default state when cheats are disabled
  50. VF_DEV_ONLY = 0x00000004, // cvar is only registered with the console in non release builds
  51. VF_DEDI_ONLY = 0x00000008, // cvar is only registered with the console in non release or dedicated server builds
  52. VF_NET_SYNCED = 0x00000080, // synchronised between server and client(s); server authorative
  53. VF_DUMPTODISK = 0x00000100,
  54. VF_READONLY = 0x00000800, // can not be changed by the user
  55. VF_REQUIRE_LEVEL_RELOAD = 0x00001000,
  56. VF_REQUIRE_APP_RESTART = 0x00002000,
  57. VF_WARNING_NOTUSED = 0x00004000, // shows warning that this var was not used in config file
  58. VF_COPYNAME = 0x00008000, // otherwise the const char * to the name will be stored without copying the memory
  59. VF_MODIFIED = 0x00010000, // Set when variable value modified.
  60. VF_WASINCONFIG = 0x00020000, // Set when variable was present in config file.
  61. VF_BITFIELD = 0x00040000, // Allow bitfield setting syntax.
  62. VF_RESTRICTEDMODE = 0x00080000, // is visible and usable in restricted (normal user) console mode
  63. VF_INVISIBLE = 0x00100000, // Invisible to the user in console
  64. VF_ALWAYSONCHANGE = 0x00200000, // Always accept variable value and call on change callback even if variable value didnt change
  65. VF_BLOCKFRAME = 0x00400000, // Blocks the execution of console commands for one frame
  66. VF_CONST_CVAR = 0x00800000, // Set if it is a const cvar not to be set inside cfg-files
  67. VF_CHEAT_ALWAYS_CHECK = 0x01000000, // This variable is critical to check in every hash, since it's extremely vulnerable
  68. VF_CHEAT_NOCHECK = 0x02000000, // This variable is set as VF_CHEAT but doesn't have to be checked/hashed since it's harmless to hack
  69. VF_SYSSPEC_OVERWRITE = 0x04000000, // This variable is specified by system.cfg with the intention to overwrite all subsequent settings
  70. VF_CVARGRP_IGNOREINREALVAL = 0x08000000, // This variable will be ignored when cvar group's real val is checked (Needed for cvars which are in a group but change in various situations)
  71. VF_RESETTABLE = 0x10000000, // This variable will be reset when a commanded reset to defaults occurs
  72. VF_RENDERER_CVAR = 0x20000000, // The update of this variable will be done in render thread
  73. VF_DEPRECATED = 0x40000000, // Deprecated cvars use default values which cannot be modified outside the code
  74. VF_EXPERIMENTAL = 0x80000000, // This variable is used by WIP or experimental feature
  75. };
  76. struct ICVarDumpSink
  77. {
  78. // <interfuscator:shuffle>
  79. virtual ~ICVarDumpSink()= default;
  80. virtual void OnElementFound(ICVar* pCVar) = 0;
  81. // </interfuscator:shuffle>
  82. };
  83. struct IKeyBindDumpSink
  84. {
  85. // <interfuscator:shuffle>
  86. virtual ~IKeyBindDumpSink()= default;
  87. virtual void OnKeyBindFound(const char* sBind, const char* sCommand) = 0;
  88. // </interfuscator:shuffle>
  89. };
  90. struct IOutputPrintSink
  91. {
  92. // <interfuscator:shuffle>
  93. virtual ~IOutputPrintSink()= default;
  94. virtual void Print(const char* inszText) = 0;
  95. // </interfuscator:shuffle>
  96. };
  97. // Callback class to derive from when you want to receive callbacks when console var changes.
  98. struct IConsoleVarSink
  99. {
  100. // <interfuscator:shuffle>
  101. virtual ~IConsoleVarSink()= default;
  102. // Called by Console before changing console var value, to validate if var can be changed.
  103. // Return value: true if ok to change value, false if should not change value.
  104. virtual bool OnBeforeVarChange(ICVar* pVar, const char* sNewValue) = 0;
  105. // Called by Console after variable has changed value
  106. virtual void OnAfterVarChange(ICVar* pVar) = 0;
  107. // </interfuscator:shuffle>
  108. };
  109. // Interface to the arguments of the console command.
  110. struct IConsoleCmdArgs
  111. {
  112. // <interfuscator:shuffle>
  113. virtual ~IConsoleCmdArgs()= default;
  114. // Gets number of arguments supplied to the command (including the command itself)
  115. virtual int GetArgCount() const = 0;
  116. // Gets argument by index, nIndex must be in 0 <= nIndex < GetArgCount()
  117. virtual const char* GetArg(int nIndex) const = 0;
  118. // Gets complete command line
  119. virtual const char* GetCommandLine() const = 0;
  120. // </interfuscator:shuffle>
  121. };
  122. // Interface to the arguments of the console command.
  123. struct IConsoleArgumentAutoComplete
  124. {
  125. // <interfuscator:shuffle>
  126. virtual ~IConsoleArgumentAutoComplete()= default;
  127. // Gets number of matches for the argument to auto complete.
  128. virtual int GetCount() const = 0;
  129. // Gets argument value by index, nIndex must be in 0 <= nIndex < GetCount()
  130. virtual const char* GetValue(int nIndex) const = 0;
  131. // </interfuscator:shuffle>
  132. };
  133. // This a definition of the console command function that can be added to console with AddCommand.
  134. using ConsoleCommandFunc = void (*)(IConsoleCmdArgs*);
  135. // This a definition of the callback function that is called when variable change.
  136. using ConsoleVarFunc = void (*)(ICVar*);
  137. /* Summary: Interface to the engine console.
  138. Description:
  139. The engine console allow to manipulate the internal engine parameters
  140. and to invoke commands.
  141. This interface allow external modules to integrate their functionalities
  142. into the console as commands or variables.
  143. IMPLEMENTATIONS NOTES:
  144. The console takes advantage of the script engine to store the console variables,
  145. this mean that all variables visible through script and console.
  146. */
  147. struct IConsole
  148. {
  149. // <interfuscator:shuffle>
  150. virtual ~IConsole()= default;
  151. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  152. // Deletes the console
  153. virtual void Release() = 0;
  154. // Initialize this instance of engine console
  155. // Arguments:
  156. // pSystem - an instance of ISystem
  157. virtual void Init(ISystem* pSystem) = 0;
  158. // Create a new console variable that store the value in a string
  159. // Arguments:
  160. // sName - console variable name
  161. // sValue - default value
  162. // nFlags - user defined flag, this parameter is used by other subsystems and doesn't affect the console variable (basically of user data)
  163. // help - help text that is shown when you use <sName> ? in the console
  164. // Return:
  165. // pointer to the interface ICVar
  166. virtual ICVar* RegisterString(const char* sName, const char* sValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = nullptr) = 0;
  167. // Create a new console variable that store the value in a int
  168. // Arguments:
  169. // sName - console variable name
  170. // iValue - default value
  171. // nFlags - user defined flag, this parameter is used by other subsystems and doesn't affect the console variable (basically of user data)
  172. // help - help text that is shown when you use <sName> ? in the console
  173. // Return:
  174. // pointer to the interface ICVar
  175. virtual ICVar* RegisterInt(const char* sName, int iValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = nullptr) = 0;
  176. // Create a new console variable that store the value in a float
  177. // Arguments:
  178. // sName - console variable name
  179. // fValue - default value
  180. // nFlags - user defined flag, this parameter is used by other subsystems and doesn't affect the console variable (basically of user data)
  181. // help - help text that is shown when you use <sName> ? in the console
  182. // Return:
  183. // pointer to the interface ICVar
  184. virtual ICVar* RegisterFloat(const char* sName, float fValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = nullptr) = 0;
  185. // Create a new console variable that will update the user defined float
  186. // Arguments:
  187. // sName - console variable name
  188. // src - pointer to the memory that will be updated
  189. // nFlags - user defined flag, this parameter is used by other subsystems and doesn't affect the console variable (basically of user data)
  190. // help - help text that is shown when you use <sName> ? in the console
  191. // allowModify - allow modification through config vars, prevents missing modifications in release mode
  192. // Return:
  193. // pointer to the interface ICVar
  194. virtual ICVar* Register(const char* name, float* src, float defaultvalue, int nFlags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = nullptr, bool allowModify = true) = 0;
  195. // Create a new console variable that will update the user defined integer
  196. // Arguments:
  197. // sName - console variable name
  198. // src - pointer to the memory that will be updated
  199. // nFlags - user defined flag, this parameter is used by other subsystems and doesn't affect the console variable (basically of user data)
  200. // help - help text that is shown when you use <sName> ? in the console
  201. // allowModify - allow modification through config vars, prevents missing modifications in release mode
  202. // Return:
  203. // pointer to the interface ICVar
  204. virtual ICVar* Register(const char* name, int* src, int defaultvalue, int nFlags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = nullptr, bool allowModify = true) = 0;
  205. // Create a new console variable that will update the user defined pointer to null terminated string
  206. // Arguments:
  207. // sName - console variable name
  208. // src - pointer to the memory that will be updated
  209. // nFlags - user defined flag, this parameter is used by other subsystems and doesn't affect the console variable (basically of user data)
  210. // help - help text that is shown when you use <sName> ? in the console
  211. // allowModify - allow modification through config vars, prevents missing modifications in release mode
  212. // Return:
  213. // pointer to the interface ICVar
  214. virtual ICVar* Register(const char* name, const char** src, const char* defaultvalue, int nFlags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = nullptr, bool allowModify = true) = 0;
  215. // ! Remove a variable from the console
  216. // @param sVarName console variable name
  217. // @param bDelete if true the variable is deleted
  218. // @see ICVar
  219. virtual void UnregisterVariable(const char* sVarName, bool bDelete = false) = 0;
  220. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  221. // Set the y coordinate where the console will stop to scroll when is dropped
  222. // @param value y in screen coordinates
  223. virtual void SetScrollMax(int value) = 0;
  224. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225. // add output sink (clases which are interested in the output) - order is not guaranteed
  226. // @param inpSink must not be 0 and is not allowed to be added twice
  227. virtual void AddOutputPrintSink(IOutputPrintSink* inpSink) = 0;
  228. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  229. // remove output sink (clases which are interested in the output) - order is not guaranteed
  230. // @param inpSink must not be 0 and has to be added before
  231. virtual void RemoveOutputPrintSink(IOutputPrintSink* inpSink) = 0;
  232. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  233. // show/hide the console
  234. // @param specifies if the window must be (true=show,false=hide)
  235. // @param specifies iRequestScrollMax <=0 if not used, otherwise it sets SetScrollMax temporary to the given value
  236. virtual void ShowConsole(bool show, int iRequestScrollMax = -1) = 0;
  237. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  238. // Dump all console-variables to a callback-interface
  239. // @param Callback callback-interface which needs to be called for each element
  240. virtual void DumpCVars(ICVarDumpSink* pCallback, unsigned int nFlagsFilter = 0) = 0;
  241. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  242. // Bind a console command to a key
  243. // @param sCmd console command that must be executed
  244. // @param sRes name of the key to invoke the command
  245. virtual void CreateKeyBind(const char* sCmd, const char* sRes) = 0;
  246. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  247. // Iterate through the lines - used for dedicated server (truncated if needed)
  248. // @param indwLineNo 0.. counted from the last printed line on
  249. // @param outszBuffer pointer to the destination string buffer (zero terminated afterwards), must not be 0
  250. // @param indwBufferSize 1.. size of the buffer
  251. // @return true=line was returned, false=there are no more lines
  252. virtual bool GetLineNo(int indwLineNo, char* outszBuffer, int indwBufferSize) const = 0;
  253. // @return current number of lines in the console
  254. virtual int GetLineCount() const = 0;
  255. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  256. // Retrieve a console variable by name - not case sensitive
  257. // @param name variable name
  258. // @return a pointer to the ICVar interface, NULL if is not found
  259. // @see ICVar
  260. virtual ICVar* GetCVar(const char* name) = 0;
  261. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  262. // Read a value from a configuration file (.ini) and return the value
  263. // @param szVarName variable name
  264. // @param szFileName source configuration file
  265. // @param def_val default value (if the variable is not found into the file)
  266. // @return the variable value
  267. virtual char* GetVariable(const char* szVarName, const char* szFileName, const char* def_val) = 0;
  268. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  269. // Read a value from a configuration file (.ini) and return the value
  270. // @param szVarName variable name
  271. // @param szFileName source configuration file
  272. // @param def_val default value (if the variable is not found into the file)
  273. // @return the variable value
  274. virtual float GetVariable(const char* szVarName, const char* szFileName, float def_val) = 0;
  275. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  276. // Print a string in the console and go to the new line
  277. // @param s the string to print
  278. virtual void PrintLine(AZStd::string_view s) = 0;
  279. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  280. // Append a string in the last console line
  281. // @param s the string to print
  282. virtual void PrintLineAppendWithPrevLine(AZStd::string_view s) = 0;
  283. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  284. // Retrieve the status of the console (active/not active)
  285. // @return the variable value(true = active/false = not active)
  286. virtual bool GetStatus() = 0;
  287. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  288. // Clear the console text
  289. virtual void Clear() = 0;
  290. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  291. // Update the console
  292. virtual void Update() = 0;
  293. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  294. // Description:
  295. // Register a new console command.
  296. // Arguments:
  297. // sCommand - Command name.
  298. // func - Pointer to the console command function to be called when command is invoked.
  299. // nFlags - Bitfield consist of VF_ flags (e.g. VF_CHEAT)
  300. // sHelp - Help string, will be displayed when typing in console "command ?".
  301. // Return
  302. // True if successful, false otherwise.
  303. virtual bool AddCommand(const char* sCommand, ConsoleCommandFunc func, int nFlags = 0, const char* sHelp = nullptr) = 0;
  304. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  305. // Description:
  306. // Register a new console command that execute script function.
  307. // EG "Game.Connect(%1)" the symbol "%1" will be replaced with the command parameter 1
  308. // writing in the console "connect 127.0.0.1" will invoke Game.Connect("127.0.0.1")
  309. // Arguments:
  310. // sCommand - Command name.
  311. // sScriptFunc - Script function to be executed when command is invoked.
  312. // nFlags - Bitfield consist of VF_ flags (e.g. VF_CHEAT)
  313. // sHelp - Help string, will be displayed when typing in console "command ?".
  314. // Return
  315. // True if successful, false otherwise.
  316. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  317. virtual bool AddCommand(const char* sName, const char* sScriptFunc, int nFlags = 0, const char* sHelp = nullptr) = 0;
  318. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  319. // Description:
  320. // Removes a console command which was previously registered with AddCommand.
  321. // Arguments:
  322. // sCommand - Command name
  323. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  324. virtual void RemoveCommand(const char* sName) = 0;
  325. // Execute a string in the console
  326. // Arguments:
  327. // command - console command e.g. "map testy" - no leading slash
  328. // bSilentMode - true=suppresses log in error case and logging the command to the console
  329. // bDeferExecution - true=the command is stored in special fifo that allows delayed execution
  330. // by using wait_seconds and wait_frames commands
  331. //
  332. virtual void ExecuteString(const char* command, bool bSilentMode = false, bool bDeferExecution = false) = 0;
  333. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  334. // Print a message into the log and abort the execution of the application
  335. // @param message error string to print in the log
  336. virtual void Exit(const char* command, ...) PRINTF_PARAMS(2, 3) = 0;
  337. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  338. // Return true if the console is opened
  339. // @return the variable value(true = opened/false = closed)
  340. virtual bool IsOpened() = 0;
  341. //////////////////////////////////////////////////////////////////////////
  342. // Auto completion.
  343. //////////////////////////////////////////////////////////////////////////
  344. virtual int GetNumVars() = 0;
  345. virtual int GetNumVisibleVars() = 0;
  346. // Arguments:
  347. // szPrefix - 0 or prefix e.g. "sys_spec_"
  348. // Return
  349. // used size
  350. virtual size_t GetSortedVars(AZStd::vector<AZStd::string_view>& pszArray, const char* szPrefix = nullptr) = 0;
  351. virtual const char* AutoComplete(const char* substr) = 0;
  352. virtual const char* AutoCompletePrev(const char* substr) = 0;
  353. virtual const char* ProcessCompletion(const char* szInputBuffer) = 0;
  354. virtual void RegisterAutoComplete(const char* sVarOrCommand, IConsoleArgumentAutoComplete* pArgAutoComplete) = 0;
  355. virtual void UnRegisterAutoComplete(const char* sVarOrCommand) = 0;
  356. //
  357. virtual void ResetAutoCompletion() = 0;
  358. //////////////////////////////////////////////////////////////////////////
  359. // Arguments:
  360. // szLine - must not be 0
  361. virtual void SetInputLine(const char* szLine) = 0;
  362. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  363. // Dump all key bindings to a callback-interface
  364. // @param Callback callback-interface which needs to be called for each element
  365. virtual void DumpKeyBinds(IKeyBindDumpSink* pCallback) = 0;
  366. virtual const char* FindKeyBind(const char* sCmd) const = 0;
  367. //////////////////////////////////////////////////////////////////////////
  368. // Console variable sink.
  369. // Adds a new console variables sink callback.
  370. virtual void AddConsoleVarSink(IConsoleVarSink* pSink) = 0;
  371. //! Removes a console variables sink callback.
  372. virtual void RemoveConsoleVarSink(IConsoleVarSink* pSink) = 0;
  373. //////////////////////////////////////////////////////////////////////////
  374. // History
  375. //////////////////////////////////////////////////////////////////////////
  376. // \param bUpOrDown true=after pressed "up", false=after pressed "down"
  377. // \return 0 if there is no history line or pointer to the null terminated history line
  378. virtual const char* GetHistoryElement(bool bUpOrDown) = 0;
  379. //! \param szCommand must not be 0
  380. virtual void AddCommandToHistory(const char* szCommand) = 0;
  381. //////////////////////////////////////////////////////////////////////////
  382. //
  383. virtual void LoadConfigVar(const char* sVariable, const char* sValue) = 0;
  384. //////////////////////////////////////////////////////////////////////////
  385. // Enable or disable the activation key (tilde by default).
  386. // This is useful when user is in a text field and want to be able to enter the default key.
  387. // bEnable=true console will show
  388. // bEnable=false console will no show
  389. virtual void EnableActivationKey(bool bEnable) = 0;
  390. // </interfuscator:shuffle>
  391. virtual void SetClientDataProbeString(const char* pName, const char* pValue) = 0;
  392. };
  393. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  394. // Description:
  395. // This interface for the remote console
  396. struct IRemoteConsoleListener
  397. {
  398. virtual ~IRemoteConsoleListener() = default;
  399. virtual void OnConsoleCommand([[maybe_unused]] const char* cmd) {};
  400. virtual void OnGameplayCommand([[maybe_unused]] const char* cmd) {};
  401. };
  402. struct IRemoteConsole
  403. {
  404. virtual ~IRemoteConsole() = default;;
  405. virtual void RegisterConsoleVariables() = 0;
  406. virtual void UnregisterConsoleVariables() = 0;
  407. virtual void Start() = 0;
  408. virtual void Stop() = 0;
  409. virtual bool IsStarted() const = 0;
  410. virtual void AddLogMessage(AZStd::string_view log) = 0;
  411. virtual void AddLogWarning(AZStd::string_view log) = 0;
  412. virtual void AddLogError(AZStd::string_view log) = 0;
  413. virtual void Update() = 0;
  414. virtual void RegisterListener(IRemoteConsoleListener* pListener, const char* name) = 0;
  415. virtual void UnregisterListener(IRemoteConsoleListener* pListener) = 0;
  416. };
  417. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  418. // Description:
  419. // This interface is the 1:1 "C++ representation"
  420. // of a console variable.
  421. // Note:
  422. // A console variable is accessible in C++ trough
  423. // this interface and in all scripts as global variable
  424. // (with the same name of the variable in the console)
  425. struct ICVar
  426. {
  427. enum EConsoleLogMode
  428. {
  429. eCLM_Off, // off
  430. eCLM_ConsoleAndFile, // normal info to console and file
  431. eCLM_FileOnly, // normal info to file only
  432. eCLM_FullInfo // full info to file only
  433. };
  434. // <interfuscator:shuffle>
  435. // TODO make protected;
  436. virtual ~ICVar() = default;
  437. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  438. // delete the variable
  439. // NOTE: the variable will automatically unregister itself from the console
  440. virtual void Release() = 0;
  441. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  442. // Return the integer value of the variable
  443. // @return the value
  444. virtual int GetIVal() const = 0;
  445. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  446. // Return the 64-bit integer value of the variable
  447. // @return the value
  448. virtual int64 GetI64Val() const = 0;
  449. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  450. // Return the float value of the variable
  451. // @return the value
  452. virtual float GetFVal() const = 0;
  453. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  454. // Return the string value of the variable, don't store pointer as multiple calls to this function might return same memory ptr
  455. // @return the value
  456. virtual const char* GetString() const = 0;
  457. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  458. // Return the data probe string value of the variable, don't store pointer as multiple calls to this function might return same memory ptr
  459. // @return the value
  460. virtual const char* GetDataProbeString() const = 0;
  461. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  462. // Reset the CVar to its default value if possible
  463. virtual void Reset() {}
  464. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  465. // set the string value of the variable
  466. // @param s string representation the value
  467. virtual void Set(const char* s) = 0;
  468. // Force to set the string value of the variable - can be called
  469. // from inside code only
  470. // @param s string representation the value
  471. virtual void ForceSet(const char* s) = 0;
  472. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  473. // set the float value of the variable
  474. // @param s float representation the value
  475. virtual void Set(float f) = 0;
  476. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  477. // set the float value of the variable
  478. // @param s integer representation the value
  479. virtual void Set(int i) = 0;
  480. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  481. // clear the specified bits in the flag field
  482. virtual void ClearFlags (int flags) = 0;
  483. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  484. // return the variable's flags
  485. // @return the variable's flags
  486. // See Also: EVarFlags
  487. virtual int GetFlags() const = 0;
  488. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  489. // Set the variable's flags
  490. // See Also: EVarFlags
  491. virtual int SetFlags(int flags) = 0;
  492. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  493. // return the primary variable's type
  494. // @return the primary variable's type e.g. CVAR_INT, CVAR_FLOAT, CVAR_STRING
  495. virtual int GetType() = 0;
  496. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  497. // return the variable's name
  498. // @return the variable's name
  499. virtual const char* GetName() const = 0;
  500. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  501. // return the variable's help text
  502. // @return the variable's help text, can be 0 if no help is available
  503. virtual const char* GetHelp() = 0;
  504. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  505. // return if the variable may be modified in config files
  506. // @return if the variable may be modified in config files
  507. virtual bool IsConstCVar() const = 0;
  508. //////////////////////////////////////////////////////////////////////////
  509. // Set a new on change function callback.
  510. // Deprecated function. The functor should be preferred.
  511. virtual void SetOnChangeCallback(ConsoleVarFunc pChangeFunc) = 0;
  512. //////////////////////////////////////////////////////////////////////////
  513. // Adds a new on change functor to the list.
  514. // It will add from index 1 on (0 is reserved).
  515. // Returns an ID to use when getting or removing the functor
  516. virtual bool AddOnChangeFunctor(AZ::Name functorName, const AZStd::function<void()>& pChangeFunctor) = 0;
  517. //////////////////////////////////////////////////////////////////////////
  518. // Get the current callback function.
  519. virtual ConsoleVarFunc GetOnChangeCallback() const = 0;
  520. //////////////////////////////////////////////////////////////////////////
  521. // only useful for CVarGroups, other types return GetIVal()
  522. // CVarGroups set multiple other CVars and this function returns
  523. // the integer value the CVarGroup should have, when looking at the controlled cvars
  524. // Returns:
  525. // value that would represent the state, -1 if the state cannot be found
  526. virtual int GetRealIVal() const = 0;
  527. virtual void SetLimits(float min, float max) = 0;
  528. virtual void GetLimits(float& min, float& max) = 0;
  529. virtual bool HasCustomLimits() = 0;
  530. // only useful for CVarGroups
  531. // log difference between expected state and real state
  532. virtual void DebugLog([[maybe_unused]] const int iExpectedValue, [[maybe_unused]] const EConsoleLogMode mode) const {}
  533. // </interfuscator:shuffle>
  534. // Set the data probe string value of the variable
  535. virtual void SetDataProbeString(const char* pDataProbeString) = 0;
  536. };