-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from JanSeliv/develop
Develop
- Loading branch information
Showing
13 changed files
with
299 additions
and
99 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
"DocsURL": "", | ||
"MarketplaceURL": "", | ||
"SupportURL": "mailto:[email protected]", | ||
"EngineVersion": "5.2.0", | ||
"EngineVersion": "5.3.0", | ||
"EnabledByDefault": true, | ||
"CanContainContent": false, | ||
"IsBetaVersion": false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Source/MetaCheatManager/Private/MetaCheatManagerExtension.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Yevhenii Selivanov | ||
|
||
#include "MetaCheatManagerExtension.h" | ||
//--- | ||
#include "MetaCheatManagerUtils.h" | ||
//--- | ||
#include "Engine/Console.h" | ||
//--- | ||
#include UE_INLINE_GENERATED_CPP_BY_NAME(MetaCheatManagerExtension) | ||
|
||
// Is overridden to initialize all cheat commands on startup | ||
void UMetaCheatManagerExtension::PostInitProperties() | ||
{ | ||
Super::PostInitProperties(); | ||
|
||
UMetaCheatManagerUtils::InitAllCheatCommands(this, /*Out*/AllCheatCommands); | ||
|
||
if (!UConsole::RegisterConsoleAutoCompleteEntries.IsBoundToObject(this)) | ||
{ | ||
UConsole::RegisterConsoleAutoCompleteEntries.AddUObject(this, &ThisClass::RegisterAutoCompleteEntries); | ||
} | ||
} | ||
|
||
// Is overridden to convert meta CheatName Your.Cheat.Name to the function name YourCheatFunction whenever user enters the command | ||
bool UMetaCheatManagerExtension::ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice& Ar, UObject* Executor) | ||
{ | ||
const bool bProcessed = UMetaCheatManagerUtils::TryProcessConsoleExec(this, Cmd, Ar, Executor); | ||
return bProcessed || Super::ProcessConsoleExec(Cmd, Ar, Executor); | ||
} | ||
|
||
// Garbage things before destroying the Cheat Manager | ||
void UMetaCheatManagerExtension::BeginDestroy() | ||
{ | ||
UConsole::RegisterConsoleAutoCompleteEntries.RemoveAll(this); | ||
|
||
Super::BeginDestroy(); | ||
} | ||
|
||
// Is bound to return all initialized meta cheat commands to see them in the console | ||
void UMetaCheatManagerExtension::RegisterAutoCompleteEntries(TArray<FAutoCompleteCommand>& OutCommands) const | ||
{ | ||
UMetaCheatManagerUtils::RegisterAutoCompleteEntries(/*out*/OutCommands, AllCheatCommands); | ||
} |
113 changes: 113 additions & 0 deletions
113
Source/MetaCheatManager/Private/MetaCheatManagerUtils.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (c) Yevhenii Selivanov | ||
|
||
#include "MetaCheatManagerUtils.h" | ||
//--- | ||
#include "MetaCheatCommand.h" | ||
#include "MetaCheatManagerInterface.h" | ||
//--- | ||
#include "ConsoleSettings.h" | ||
//--- | ||
#include UE_INLINE_GENERATED_CPP_BY_NAME(MetaCheatManagerUtils) | ||
|
||
void UMetaCheatManagerUtils::InitAllCheatCommands(const TScriptInterface<IMetaCheatManagerInterface> CheatManager, TArray<FMetaCheatCommand>& OutAllCheatCommands) | ||
{ | ||
#if WITH_EDITOR | ||
if (!ensureMsgf(CheatManager, TEXT("ASSERT: [%i] %s:\n'CheatManager' is not valid!"), __LINE__, *FString(__FUNCTION__))) | ||
{ | ||
return; | ||
} | ||
|
||
UObject* CheatManagerObj = CheatManager.GetObject(); | ||
checkf(CheatManagerObj, TEXT("ERROR: [%i] %s:\n'CheatManagerObj' is null!"), __LINE__, *FString(__FUNCTION__)); | ||
|
||
// It automatically adds DefaultMetaCheatManager.ini config on the editor startup to the Config folder on your project | ||
// 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. | ||
// 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. | ||
|
||
if (!CheatManagerObj->HasAllFlags(RF_ClassDefaultObject)) | ||
{ | ||
// Do not init cheat commands for instances since we save them as default values into config file | ||
return; | ||
} | ||
|
||
if (!OutAllCheatCommands.IsEmpty()) | ||
{ | ||
OutAllCheatCommands.Empty(); | ||
} | ||
|
||
// Find all cheat commands | ||
for (TFieldIterator<UFunction> FunctionIt(CheatManagerObj->GetClass(), EFieldIteratorFlags::ExcludeSuper); FunctionIt; ++FunctionIt) | ||
{ | ||
FMetaCheatCommand CheatCommand = FMetaCheatCommand::Create(*FunctionIt); | ||
if (CheatCommand.IsValid()) | ||
{ | ||
OutAllCheatCommands.Emplace(MoveTemp(CheatCommand)); | ||
} | ||
} | ||
|
||
CheatManagerObj->TryUpdateDefaultConfigFile(); | ||
#endif // WITH_EDITOR | ||
} | ||
|
||
// Returns the cheat command associated with specified CheatName meta value | ||
const FMetaCheatCommand& UMetaCheatManagerUtils::GetCheatCommandByCheatName(FName CheatName, const TArray<FMetaCheatCommand>& InAllCheatCommands) | ||
{ | ||
for (const FMetaCheatCommand& CheatCommandIt : InAllCheatCommands) | ||
{ | ||
if (CheatCommandIt.CheatName.IsEqual(CheatName)) | ||
{ | ||
return CheatCommandIt; | ||
} | ||
} | ||
|
||
return FMetaCheatCommand::EmptyCommand; | ||
} | ||
|
||
// Registers auto-complete entries for the cheat commands | ||
void UMetaCheatManagerUtils::RegisterAutoCompleteEntries(TArray<FAutoCompleteCommand>& OutCommands, const TArray<FMetaCheatCommand>& InAllCheatCommands) | ||
{ | ||
for (const FMetaCheatCommand& CheatCommandIt : InAllCheatCommands) | ||
{ | ||
const FAutoCompleteCommand& NewCommand = CheatCommandIt.ToAutoCompleteCommand(); | ||
const bool bIsNew = !OutCommands.ContainsByPredicate([&NewCommand](const FAutoCompleteCommand& CommandIt) { return CommandIt.Command == NewCommand.Command; }); | ||
if (bIsNew) | ||
{ | ||
OutCommands.Emplace(NewCommand); | ||
} | ||
} | ||
} | ||
|
||
// Processes the console execution of meta cheat commands | ||
bool UMetaCheatManagerUtils::TryProcessConsoleExec(const TScriptInterface<IMetaCheatManagerInterface> CheatManager, const TCHAR* const Cmd, FOutputDevice& Ar, UObject* Executor) | ||
{ | ||
if (!ensureMsgf(CheatManager, TEXT("ASSERT: [%i] %s:\n'CheatManager' is not valid!"), __LINE__, *FString(__FUNCTION__))) | ||
{ | ||
return false; | ||
} | ||
|
||
UObject* CheatManagerObj = CheatManager.GetObject(); | ||
checkf(CheatManagerObj, TEXT("ERROR: [%i] %s:\n'CheatManagerObj' is null!"), __LINE__, *FString(__FUNCTION__)); | ||
|
||
constexpr bool bUseEscape = true; | ||
const TCHAR* ParsedCmd = Cmd; | ||
FString CommandName = TEXT(""); | ||
if (!FParse::Token(/*InOut*/ParsedCmd, /*Out*/CommandName, bUseEscape)) | ||
{ | ||
return false; | ||
} | ||
|
||
// CommandName: is the CheatName (Your.Cheat.Name) | ||
// Cmd: is the value (if any) that was passed to the cheat | ||
const FMetaCheatCommand& CheatCommand = GetCheatCommandByCheatName(*CommandName, CheatManager->GetAllCheatCommands()); | ||
if (!CheatCommand.IsValid()) | ||
{ | ||
return false; | ||
} | ||
|
||
// Get the function name (YourCheatFunction) from the CheatName (Your.Cheat.Name) | ||
// and append it with the value that was passed to the cheat to process the call | ||
// YourFunctionCheat Value | ||
constexpr bool bForceCallWithNonExec = true; | ||
const FString CmdString = CheatCommand.FunctionName.ToString() + ParsedCmd; | ||
return CheatManagerObj->CallFunctionByNameWithArguments(*CmdString, Ar, Executor, bForceCallWithNonExec); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.