Skip to content

Commit 0912cba

Browse files
authored
Merge pull request #3 from JanSeliv/develop
Develop
2 parents 65890ed + f9c263e commit 0912cba

10 files changed

Lines changed: 298 additions & 98 deletions

MetaCheatManager.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"DocsURL": "",
1111
"MarketplaceURL": "",
1212
"SupportURL": "mailto:janseliw@gmail.com",
13-
"EngineVersion": "5.2.0",
13+
"EngineVersion": "5.3.0",
1414
"EnabledByDefault": true,
1515
"CanContainContent": false,
1616
"IsBetaVersion": false,

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ Visit our [Release](https://github.com/JanSeliv/MetaCheatManager/releases) page
1515
Also, explore this [game project repository](https://github.com/JanSeliv/Bomber) to see the Meta Cheat Manager in action.
1616

1717
## 📅 Changelog
18+
#### 2024-01-14
19+
- Updated to **Unreal Engine 5.3**.
20+
- Added 'Cheat Manager Extensions' support, useful for plugins and Game Feature modules populating their own cheats.
1821
#### 2023-05-31
1922
- 🎉 Initial public release on Unreal Engine 5.2
2023

2124
## 📫 Feedback & Contribution
2225

23-
This is an open-source project and we encourage you to contribute. If you encounter any bugs or if you have any feature requests, please file an issue in the GitHub repository.
26+
Feedback and contributions from the community are highly appreciated!
27+
28+
If you'd like to contribute, please fork the project and create a pull request targeting the `develop` branch.
29+
30+
If you've found a bug or have an idea for a new feature, please open a new issue on GitHub. Thank you!
2431

2532
## 📜 License
2633

Source/MetaCheatManager/MetaCheatManager.Build.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public MetaCheatManager(ReadOnlyTargetRules Target) : base(Target)
88
{
99
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
1010
CppStandard = CppStandardVersion.Latest;
11+
bEnableNonInlinedGenCppWarnings = true;
1112

1213
PublicDependencyModuleNames.AddRange(new[]
1314
{

Source/MetaCheatManager/Private/MetaCheatManager.cpp

Lines changed: 7 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,18 @@
22

33
#include "MetaCheatManager.h"
44
//---
5+
#include "MetaCheatManagerUtils.h"
6+
//---
57
#include "Engine/Console.h"
68
//---
79
#include UE_INLINE_GENERATED_CPP_BY_NAME(MetaCheatManager)
810

9-
// Returns the cheat command associated with specified CheatName meta value
10-
const FMetaCheatCommand& UMetaCheatManager::GetCheatCommandByCheatName(const FName& CheatName) const
11-
{
12-
for (const FMetaCheatCommand& CheatCommandIt : AllCheatCommands)
13-
{
14-
if (CheatCommandIt.CheatName.IsEqual(CheatName))
15-
{
16-
return CheatCommandIt;
17-
}
18-
}
19-
20-
return FMetaCheatCommand::EmptyCommand;
21-
}
22-
2311
// Is overridden to initialize all cheat commands on editor startup
2412
void UMetaCheatManager::PostInitProperties()
2513
{
2614
Super::PostInitProperties();
2715

28-
InitAllCheatCommands();
29-
}
30-
31-
// Called when CheatManager is created to allow any needed initialization
32-
void UMetaCheatManager::InitCheatManager()
33-
{
34-
Super::InitCheatManager();
16+
UMetaCheatManagerUtils::InitAllCheatCommands(this, /*Out*/AllCheatCommands);
3517

3618
if (!UConsole::RegisterConsoleAutoCompleteEntries.IsBoundToObject(this))
3719
{
@@ -42,26 +24,8 @@ void UMetaCheatManager::InitCheatManager()
4224
// Is overridden to convert meta CheatName Your.Cheat.Name to the function name YourCheatFunction whenever user enters the command
4325
bool UMetaCheatManager::ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice& Ar, UObject* Executor)
4426
{
45-
constexpr bool bUseEscape = true;
46-
const FString OriginalCmd = Cmd;
47-
FString CommandName = TEXT("");
48-
if (FParse::Token(/*InOut*/Cmd, /*Out*/CommandName, bUseEscape))
49-
{
50-
// CommandName: is the CheatName (Your.Cheat.Name)
51-
// Cmd: is the value (if any) that was passed to the cheat
52-
const FMetaCheatCommand& CheatCommand = GetCheatCommandByCheatName(*CommandName);
53-
if (CheatCommand.IsValid())
54-
{
55-
// Get the function name (YourCheatFunction) from the CheatName (Your.Cheat.Name)
56-
// and append it with the value that was passed to the cheat to process the call
57-
// YourFunctionCheat Value
58-
constexpr bool bForceCallWithNonExec = true;
59-
const FString CmdString = CheatCommand.FunctionName.ToString() + Cmd;
60-
return CallFunctionByNameWithArguments(*CmdString, Ar, Executor, bForceCallWithNonExec);
61-
}
62-
}
63-
64-
return Super::ProcessConsoleExec(*OriginalCmd, Ar, Executor);
27+
const bool bProcessed = UMetaCheatManagerUtils::TryProcessConsoleExec(this, Cmd, Ar, Executor);
28+
return bProcessed || Super::ProcessConsoleExec(Cmd, Ar, Executor);
6529
}
6630

6731
// Garbage things before destroying the Cheat Manager
@@ -73,43 +37,7 @@ void UMetaCheatManager::BeginDestroy()
7337
}
7438

7539
// Is bound to return all initialized meta cheat commands to see them in the console
76-
void UMetaCheatManager::RegisterAutoCompleteEntries(TArray<FAutoCompleteCommand>& Commands) const
77-
{
78-
for (const FMetaCheatCommand& CheatCommandIt : AllCheatCommands)
79-
{
80-
Commands.Emplace(CheatCommandIt.ToAutoCompleteCommand());
81-
}
82-
}
83-
84-
// Finds and saves all cheat commands marked with 'CheatName' metadata
85-
void UMetaCheatManager::InitAllCheatCommands()
40+
void UMetaCheatManager::RegisterAutoCompleteEntries(TArray<FAutoCompleteCommand>& OutCommands) const
8641
{
87-
#if WITH_EDITOR
88-
// It automatically adds DefaultMetaCheatManager.ini config on the editor startup to the Config folder on your project
89-
// to have your cheat commands with custom Cheat Names in the packaged build as well, you don't need to do anything specific about it.
90-
// Such solution is used because any metadata can be obtained only in the Editor, so we store it in the config file for the build.
91-
92-
if (!HasAllFlags(RF_ClassDefaultObject))
93-
{
94-
// Do not init cheat commands for instances since we save them as default values into config file
95-
return;
96-
}
97-
98-
if (!AllCheatCommands.IsEmpty())
99-
{
100-
AllCheatCommands.Empty();
101-
}
102-
103-
// Find all cheat commands
104-
for (TFieldIterator<UFunction> FunctionIt(GetClass(), EFieldIteratorFlags::ExcludeSuper); FunctionIt; ++FunctionIt)
105-
{
106-
FMetaCheatCommand CheatCommand = FMetaCheatCommand::Create(*FunctionIt);
107-
if (CheatCommand.IsValid())
108-
{
109-
AllCheatCommands.Emplace(MoveTemp(CheatCommand));
110-
}
111-
}
112-
113-
TryUpdateDefaultConfigFile();
114-
#endif // WITH_EDITOR
42+
UMetaCheatManagerUtils::RegisterAutoCompleteEntries(/*out*/OutCommands, AllCheatCommands);
11543
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Yevhenii Selivanov
2+
3+
#include "MetaCheatManagerExtension.h"
4+
//---
5+
#include "MetaCheatManagerUtils.h"
6+
//---
7+
#include "Engine/Console.h"
8+
//---
9+
#include UE_INLINE_GENERATED_CPP_BY_NAME(MetaCheatManagerExtension)
10+
11+
// Is overridden to initialize all cheat commands on startup
12+
void UMetaCheatManagerExtension::PostInitProperties()
13+
{
14+
Super::PostInitProperties();
15+
16+
UMetaCheatManagerUtils::InitAllCheatCommands(this, /*Out*/AllCheatCommands);
17+
18+
if (!UConsole::RegisterConsoleAutoCompleteEntries.IsBoundToObject(this))
19+
{
20+
UConsole::RegisterConsoleAutoCompleteEntries.AddUObject(this, &ThisClass::RegisterAutoCompleteEntries);
21+
}
22+
}
23+
24+
// Is overridden to convert meta CheatName Your.Cheat.Name to the function name YourCheatFunction whenever user enters the command
25+
bool UMetaCheatManagerExtension::ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice& Ar, UObject* Executor)
26+
{
27+
const bool bProcessed = UMetaCheatManagerUtils::TryProcessConsoleExec(this, Cmd, Ar, Executor);
28+
return bProcessed || Super::ProcessConsoleExec(Cmd, Ar, Executor);
29+
}
30+
31+
// Garbage things before destroying the Cheat Manager
32+
void UMetaCheatManagerExtension::BeginDestroy()
33+
{
34+
UConsole::RegisterConsoleAutoCompleteEntries.RemoveAll(this);
35+
36+
Super::BeginDestroy();
37+
}
38+
39+
// Is bound to return all initialized meta cheat commands to see them in the console
40+
void UMetaCheatManagerExtension::RegisterAutoCompleteEntries(TArray<FAutoCompleteCommand>& OutCommands) const
41+
{
42+
UMetaCheatManagerUtils::RegisterAutoCompleteEntries(/*out*/OutCommands, AllCheatCommands);
43+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright (c) Yevhenii Selivanov
2+
3+
#include "MetaCheatManagerUtils.h"
4+
//---
5+
#include "MetaCheatCommand.h"
6+
#include "MetaCheatManagerInterface.h"
7+
//---
8+
#include "ConsoleSettings.h"
9+
//---
10+
#include UE_INLINE_GENERATED_CPP_BY_NAME(MetaCheatManagerUtils)
11+
12+
void UMetaCheatManagerUtils::InitAllCheatCommands(const TScriptInterface<IMetaCheatManagerInterface> CheatManager, TArray<FMetaCheatCommand>& OutAllCheatCommands)
13+
{
14+
#if WITH_EDITOR
15+
if (!ensureMsgf(CheatManager, TEXT("ASSERT: [%i] %s:\n'CheatManager' is not valid!"), __LINE__, *FString(__FUNCTION__)))
16+
{
17+
return;
18+
}
19+
20+
UObject* CheatManagerObj = CheatManager.GetObject();
21+
checkf(CheatManagerObj, TEXT("ERROR: [%i] %s:\n'CheatManagerObj' is null!"), __LINE__, *FString(__FUNCTION__));
22+
23+
// It automatically adds DefaultMetaCheatManager.ini config on the editor startup to the Config folder on your project
24+
// to have your cheat commands with custom Cheat Names in the packaged build as well, you don't need to do anything specific about it.
25+
// Such solution is used because any metadata can be obtained only in the Editor, so we store it in the config file for the build.
26+
27+
if (!CheatManagerObj->HasAllFlags(RF_ClassDefaultObject))
28+
{
29+
// Do not init cheat commands for instances since we save them as default values into config file
30+
return;
31+
}
32+
33+
if (!OutAllCheatCommands.IsEmpty())
34+
{
35+
OutAllCheatCommands.Empty();
36+
}
37+
38+
// Find all cheat commands
39+
for (TFieldIterator<UFunction> FunctionIt(CheatManagerObj->GetClass(), EFieldIteratorFlags::ExcludeSuper); FunctionIt; ++FunctionIt)
40+
{
41+
FMetaCheatCommand CheatCommand = FMetaCheatCommand::Create(*FunctionIt);
42+
if (CheatCommand.IsValid())
43+
{
44+
OutAllCheatCommands.Emplace(MoveTemp(CheatCommand));
45+
}
46+
}
47+
48+
CheatManagerObj->TryUpdateDefaultConfigFile();
49+
#endif // WITH_EDITOR
50+
}
51+
52+
// Returns the cheat command associated with specified CheatName meta value
53+
const FMetaCheatCommand& UMetaCheatManagerUtils::GetCheatCommandByCheatName(FName CheatName, const TArray<FMetaCheatCommand>& InAllCheatCommands)
54+
{
55+
for (const FMetaCheatCommand& CheatCommandIt : InAllCheatCommands)
56+
{
57+
if (CheatCommandIt.CheatName.IsEqual(CheatName))
58+
{
59+
return CheatCommandIt;
60+
}
61+
}
62+
63+
return FMetaCheatCommand::EmptyCommand;
64+
}
65+
66+
// Registers auto-complete entries for the cheat commands
67+
void UMetaCheatManagerUtils::RegisterAutoCompleteEntries(TArray<FAutoCompleteCommand>& OutCommands, const TArray<FMetaCheatCommand>& InAllCheatCommands)
68+
{
69+
for (const FMetaCheatCommand& CheatCommandIt : InAllCheatCommands)
70+
{
71+
const FAutoCompleteCommand& NewCommand = CheatCommandIt.ToAutoCompleteCommand();
72+
const bool bIsNew = !OutCommands.ContainsByPredicate([&NewCommand](const FAutoCompleteCommand& CommandIt) { return CommandIt.Command == NewCommand.Command; });
73+
if (bIsNew)
74+
{
75+
OutCommands.Emplace(NewCommand);
76+
}
77+
}
78+
}
79+
80+
// Processes the console execution of meta cheat commands
81+
bool UMetaCheatManagerUtils::TryProcessConsoleExec(const TScriptInterface<IMetaCheatManagerInterface> CheatManager, const TCHAR* const Cmd, FOutputDevice& Ar, UObject* Executor)
82+
{
83+
if (!ensureMsgf(CheatManager, TEXT("ASSERT: [%i] %s:\n'CheatManager' is not valid!"), __LINE__, *FString(__FUNCTION__)))
84+
{
85+
return false;
86+
}
87+
88+
UObject* CheatManagerObj = CheatManager.GetObject();
89+
checkf(CheatManagerObj, TEXT("ERROR: [%i] %s:\n'CheatManagerObj' is null!"), __LINE__, *FString(__FUNCTION__));
90+
91+
constexpr bool bUseEscape = true;
92+
const TCHAR* ParsedCmd = Cmd;
93+
FString CommandName = TEXT("");
94+
if (!FParse::Token(/*InOut*/ParsedCmd, /*Out*/CommandName, bUseEscape))
95+
{
96+
return false;
97+
}
98+
99+
// CommandName: is the CheatName (Your.Cheat.Name)
100+
// Cmd: is the value (if any) that was passed to the cheat
101+
const FMetaCheatCommand& CheatCommand = GetCheatCommandByCheatName(*CommandName, CheatManager->GetAllCheatCommands());
102+
if (!CheatCommand.IsValid())
103+
{
104+
return false;
105+
}
106+
107+
// Get the function name (YourCheatFunction) from the CheatName (Your.Cheat.Name)
108+
// and append it with the value that was passed to the cheat to process the call
109+
// YourFunctionCheat Value
110+
constexpr bool bForceCallWithNonExec = true;
111+
const FString CmdString = CheatCommand.FunctionName.ToString() + ParsedCmd;
112+
return CheatManagerObj->CallFunctionByNameWithArguments(*CmdString, Ar, Executor, bForceCallWithNonExec);
113+
}

Source/MetaCheatManager/Public/MetaCheatManager.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include "GameFramework/CheatManager.h"
6+
#include "MetaCheatManagerInterface.h"
67
//---
78
#include "MetaCheatCommand.h"
89
//---
@@ -46,17 +47,14 @@
4647
*/
4748
UCLASS(Config = "MetaCheatManager", DefaultConfig)
4849
class METACHEATMANAGER_API UMetaCheatManager : public UCheatManager
50+
, public IMetaCheatManagerInterface
4951
{
5052
GENERATED_BODY()
5153

54+
public:
5255
/** Returns all cheat commands exposed by this cheat manager.
5356
* @see UMetaCheatManager::AllCheatCommands */
54-
UFUNCTION(BlueprintPure)
55-
const FORCEINLINE TArray<FMetaCheatCommand>& GetAllCheatCommands() const { return AllCheatCommands; }
56-
57-
/** Returns the cheat command associated with specified CheatName meta value. */
58-
UFUNCTION(BlueprintPure)
59-
virtual const FMetaCheatCommand& GetCheatCommandByCheatName(const FName& CheatName) const;
57+
virtual const FORCEINLINE TArray<FMetaCheatCommand>& GetAllCheatCommands() const override { return AllCheatCommands; }
6058

6159
protected:
6260
/** Contains all cheat commands exposed by this cheat manager.
@@ -67,9 +65,6 @@ class METACHEATMANAGER_API UMetaCheatManager : public UCheatManager
6765
/** Is overridden to initialize all cheat commands on editor startup. */
6866
virtual void PostInitProperties() override;
6967

70-
/** Called when CheatManager is created to allow any needed initialization. */
71-
virtual void InitCheatManager() override;
72-
7368
/** Is overridden to convert a meta CheatName 'Your.Cheat.Name'
7469
* to the function name 'YourCheatFunction' to process the call whenever user enters the command. */
7570
virtual bool ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice& Ar, UObject* Executor) override;
@@ -78,12 +73,5 @@ class METACHEATMANAGER_API UMetaCheatManager : public UCheatManager
7873
virtual void BeginDestroy() override;
7974

8075
/** Is bound to return all initialized meta cheat commands to see them in the console. */
81-
virtual void RegisterAutoCompleteEntries(TArray<FAutoCompleteCommand>& Commands) const;
82-
83-
/** Finds and saves all cheat commands marked with 'CheatName' metadata.
84-
* @warning its implementation is editor-only
85-
* since we don't have access to any meta data in builds,
86-
* but you can override it to use your own implementation.
87-
* @see UMetaCheatManager::AllCheatCommandsInternal */
88-
virtual void InitAllCheatCommands();
76+
virtual void RegisterAutoCompleteEntries(TArray<FAutoCompleteCommand>& OutCommands) const override;
8977
};

0 commit comments

Comments
 (0)