Skip to content

Commit

Permalink
Add FeatureSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrM committed Oct 8, 2022
1 parent 8e99057 commit bad3cb6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/CleanCheat.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ClCompile Include="Runners\BasicRunner.cpp" />
<ClCompile Include="SharedDataStruct.cpp" />
<ClInclude Include="CleanCheat.h" />
<ClInclude Include="CleanCheat\FeatureSettings.h" />
<ClInclude Include="CleanCheat\Macros.h" />
<ClInclude Include="CleanCheat\HookManager.h" />
<ClInclude Include="CleanCheat\MemoryManager.h" />
Expand Down
37 changes: 26 additions & 11 deletions src/CleanCheat/FeatureBase.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#pragma once
#include "Macros.h"
#include "FeatureSettings.h"

template <typename TType>
template <typename TType, class TSettings = FeatureSettings>
ABSTRACT class FeatureBase
{
private:
bool _init = false;

public:
TSettings* Settings;

public:
virtual ~FeatureBase() = default;
virtual void Discard() { }

protected:
virtual void OnExecute(TType* param) = 0;
Expand All @@ -20,6 +23,15 @@ ABSTRACT class FeatureBase
}

public:
/// <summary>
/// Determinate initialization status
/// </summary>
/// <returns>`True` if initialized, otherwise `False`</returns>
bool IsInitialized() const
{
return _init;
}

/// <summary>
/// Condition runner will use to determine will execute this feature or not
/// </summary>
Expand All @@ -46,15 +58,6 @@ ABSTRACT class FeatureBase
OnExecute(param);
}

/// <summary>
/// Determinate initialization status
/// </summary>
/// <returns>`True` if initialized, otherwise `False`</returns>
bool IsInitialized() const
{
return _init;
}

/// <summary>
/// Initialize
/// </summary>
Expand All @@ -64,6 +67,18 @@ ABSTRACT class FeatureBase
return false;
_init = true;

Settings = new TSettings();
Settings->OnInit();

return OnInit(initData);
}

/// <summary>
/// Discard
/// </summary>
virtual void Discard()
{
delete Settings;
Settings = nullptr;
}
};
16 changes: 16 additions & 0 deletions src/CleanCheat/FeatureSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

/// <summary>
/// Features settings class
/// </summary>
class FeatureSettings
{
public:
bool Enable = true;

public:
virtual ~FeatureSettings() = default;

protected:
virtual void OnInit() { }
};
4 changes: 2 additions & 2 deletions src/CleanCheat/RunnerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ template <typename TType>
ABSTRACT class RunnerBase
{
protected:
std::vector<FeatureBase<TType>*> _features;
std::vector<FeatureBase<TType, int8_t>*> _features;

public:
virtual ~RunnerBase() = default;
Expand Down Expand Up @@ -35,7 +35,7 @@ ABSTRACT class RunnerBase
{
for (FeatureBase<TType>* const& feature : _features)
{
if (feature->Condition(item))
if (feature->Settings->Enable && feature->Condition(item))
feature->Execute(item);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Features/BasicFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ void BasicFeature::OnExecute(int* param)

bool BasicFeature::Condition(int* param)
{
return true;
return Settings->Enable;
}
8 changes: 7 additions & 1 deletion src/Features/BasicFeature.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#pragma once
#include "CleanCheat/FeatureBase.h"

class BasicFeature final : public FeatureBase<int>
class BasicSettings final : public FeatureSettings
{
public:
bool Test = false;
};

class BasicFeature final : public FeatureBase<int, BasicSettings>
{
protected:
void OnExecute(int* param) override;
Expand Down

0 comments on commit bad3cb6

Please sign in to comment.