Add cheat documentation, enable input repeat for L and R, show cheat category name

This commit is contained in:
Gericom
2026-03-08 13:03:26 +01:00
parent 43b1bf7afa
commit 6c34d9324d
22 changed files with 189 additions and 67 deletions

View File

@@ -1,27 +1,48 @@
#pragma once
#include "CheatTreeItem.h"
class Cheat : public CheatTreeItem
/// @brief Class representing a single cheat.
class Cheat
{
public:
Cheat()
: _cheatData(nullptr), _cheatDataLength(0) { }
Cheat() { }
Cheat(const char* name, const char* description, u32* flagsPointer, const void* cheatData, u32 cheatDataLength)
: CheatTreeItem(name, description), _flagsPointer(flagsPointer)
: _name(name), _description(description), _flagsPointer(flagsPointer)
, _cheatData(cheatData), _cheatDataLength(cheatDataLength) { }
/// @brief Gets the name of this cheat.
/// @return A pointer to the name of this cheat.
const char* GetName() const
{
return _name;
}
/// @brief Gets the description of this cheat.
/// @return A pointer to the description of this cheat.
const char* GetDescription() const
{
return _description;
}
/// @brief Gets a pointer to the data of this cheat.
/// @param cheatDataLength The length of the cheat data is returned in this reference.
/// @return A pointer to the cheat data.
/// This pointer is only valid for the lifetime of the \see GameCheats instance this cheat belongs to.
const void* GetCheatData(u32& cheatDataLength) const
{
cheatDataLength = _cheatDataLength;
return _cheatData;
}
/// @brief Gets whether this cheat is active (enabled) or not.
/// @return \c true when this cheat is active, or \c false when not active.
bool GetIsCheatActive() const
{
return ((*_flagsPointer >> 24) & 1) == 1;
}
/// @brief Sets whether this cheat is active (enabled) or not.
/// @param isCheatActive \c true to enable this cheat, or \c false to disable this cheat.
void SetIsCheatActive(bool isCheatActive) const
{
u32 flags = *_flagsPointer;
@@ -34,7 +55,9 @@ public:
}
private:
u32* _flagsPointer;
const void* _cheatData;
u32 _cheatDataLength;
const char* _name = nullptr;
const char* _description = nullptr;
u32* _flagsPointer = nullptr;
const void* _cheatData = nullptr;
u32 _cheatDataLength = 0;
};

View File

@@ -1,19 +1,16 @@
#pragma once
#include <memory>
#include "CheatTreeItem.h"
#include "Cheat.h"
#include "ICheatCategory.h"
class CheatCategory : public CheatTreeItem, public ICheatCategory
/// @brief Class representing a cheat category, containing sub-categories and cheats.
class CheatCategory : public ICheatCategory
{
public:
CheatCategory()
: _isMaxOneCheatActive(false), _subCategories(nullptr), _numberOfSubCategories(0)
, _cheats(nullptr), _numberOfCheats(0) { }
CheatCategory() { }
CheatCategory(const char* name, const char* description, bool isMaxOneCheatActive,
CheatCategory* subCategories, u32 numberOfSubCategories, Cheat* cheats, u32 numberOfCheats)
: CheatTreeItem(name, description), _isMaxOneCheatActive(isMaxOneCheatActive)
: _name(name), _description(description), _isMaxOneCheatActive(isMaxOneCheatActive)
, _subCategories(subCategories), _numberOfSubCategories(numberOfSubCategories)
, _cheats(cheats), _numberOfCheats(numberOfCheats) { }
@@ -56,6 +53,18 @@ public:
}
}
const char* GetName() const override
{
return _name;
}
/// @brief Gets the description of this cheat category.
/// @return A pointer to the description of this cheat category.
const char* GetDescription() const
{
return _description;
}
bool GetIsMaxOneCheatActive() const override
{
return _isMaxOneCheatActive;
@@ -74,9 +83,11 @@ public:
}
private:
bool _isMaxOneCheatActive;
CheatCategory* _subCategories;
u32 _numberOfSubCategories;
Cheat* _cheats;
u32 _numberOfCheats;
const char* _name = nullptr;
const char* _description = nullptr;
bool _isMaxOneCheatActive = false;
CheatCategory* _subCategories = nullptr;
u32 _numberOfSubCategories = 0;
Cheat* _cheats = nullptr;
u32 _numberOfCheats = 0;
};

View File

@@ -1,25 +0,0 @@
#pragma once
class CheatTreeItem
{
public:
const char* GetName() const
{
return _name;
}
const char* GetDescription() const
{
return _description;
}
protected:
const char* _name;
const char* _description;
CheatTreeItem()
: _name(nullptr), _description(nullptr) { }
CheatTreeItem(const char* name, const char* description)
: _name(name), _description(description) { }
};

View File

@@ -1,6 +1,7 @@
#pragma once
#include "ICheatRepository.h"
/// @brief Class implementing an empty cheat repository.
class EmptyCheatRepository : public ICheatRepository
{
public:

View File

@@ -3,6 +3,7 @@
#include "CheatCategory.h"
#include "ICheatCategory.h"
/// @brief Class holding the cheats for a game.
class GameCheats : public ICheatCategory
{
public:
@@ -24,16 +25,13 @@ public:
}
}
/// @brief Gets the name of the game.
/// @return A pointer to the name of the game.
const char* GetGameName() const
{
return _gameName;
}
bool GetIsMaxOneCheatActive() const override
{
return false;
}
const CheatCategory* GetCategories(u32& numberOfCategories) const override
{
numberOfCategories = _numberOfCategories;
@@ -46,6 +44,9 @@ public:
return _cheats;
}
/// @brief Gets a pointer to the cheat data.
/// @param cheatDataLength The length of the cheat data is returned in this reference.
/// @return A pointer to the cheat data. This pointer is only valid for the lifetime of this \see GameCheats instance.
u8* GetCheatData(u32& cheatDataLength) const
{
cheatDataLength = _cheatDataLength;
@@ -66,4 +67,15 @@ private:
u32 _numberOfCategories;
Cheat* _cheats;
u32 _numberOfCheats;
// From ICheatCategory
const char* GetName() const override
{
return "";
}
bool GetIsMaxOneCheatActive() const override
{
return false;
}
};

View File

@@ -3,13 +3,28 @@
class CheatCategory;
class Cheat;
/// @brief Interface for a collection of cheats.
class ICheatCategory
{
public:
virtual ~ICheatCategory() = default;
/// @brief Gets the name of this category.
/// @return The name of this category.
virtual const char* GetName() const = 0;
/// @brief Indicates if only one cheat in this category is allowed to be on or not.
/// @return \c true when only one cheat is allowed to be active in this category, or \c false otherwise.
virtual bool GetIsMaxOneCheatActive() const = 0;
/// @brief Gets the sub-categories of this category.
/// @param numberOfCategories The number of categories is returned through this reference.
/// @return A pointer to an array of categories. This may be \c nullptr when \p numberOfCategories is 0.
virtual const CheatCategory* GetCategories(u32& numberOfCategories) const;
/// @brief Gets the cheats in this category.
/// @param numberOfCheats The number of cheats is returned through this reference.
/// @return A pointer to an array of cheats. This may be \c nullptr when \p numberOfCheats is 0.
virtual const Cheat* GetCheats(u32& numberOfCheats) const;
protected:

View File

@@ -2,12 +2,19 @@
#include "GameCheats.h"
#include "fat/FastFileRef.h"
/// @brief Interface for a repository providing access to cheats.
class ICheatRepository
{
public:
virtual ~ICheatRepository() { }
/// @brief Gets the available cheats for the given \p romFile.
/// @param romFile Reference to the rom file.
/// @return A unique pointer to the found cheats, or an empty unique pointer when no cheats were found.
virtual std::unique_ptr<GameCheats> GetCheatsForGame(const FastFileRef& romFile) const = 0;
/// @brief Writes the enable/disabled status of the given \p cheats.
/// @param cheats The cheats to update.
virtual void UpdateEnabledCheatsForGame(const std::unique_ptr<GameCheats>& cheats) const = 0;
protected:

View File

@@ -3,9 +3,13 @@
#include "GameCheats.h"
#include "picoLoader7.h"
/// @brief Factory for creating Pico Loader compatible cheat data.
class PicoLoaderCheatDataFactory
{
public:
/// @brief Converts the given \p gameCheats to Pico Loader format. Only the enabled cheats will be included.
/// @param gameCheats The cheats to convert.
/// @return Pointer to the created cheat data.
pload_cheats_t* CreateCheatData(const std::unique_ptr<GameCheats>& gameCheats) const;
private:

View File

@@ -1,5 +1,6 @@
#pragma once
/// @brief Struct representing an index entry of usrcheat.dat.
struct usr_cheat_index_entry_t
{
u32 gameCode;

View File

@@ -4,6 +4,7 @@
#include "ICheatRepository.h"
#include "UsrCheatDat.h"
/// @brief Class implementing a cheat repository for usrcheat.dat.
class UsrCheatRepository : public ICheatRepository
{
public:

View File

@@ -2,8 +2,12 @@
#include <memory>
#include "UsrCheatRepository.h"
/// @brief Factory for constructing a \see UsrCheatRepository for a usrcheat.dat file.
class UsrCheatRepositoryFactory
{
public:
/// @brief Constructs a \see UsrCheatRepository for the given \p usrCheatDatPath.
/// @param usrCheatDatPath The path to the usrcheat.dat file.
/// @return A unique pointer to the constructed repository, or an empty unique pointer when construction failed.
std::unique_ptr<UsrCheatRepository> FromUsrCheatDat(const TCHAR* usrCheatDatPath);
};