2019-09-24 21:59:36 +00:00
|
|
|
/*
|
|
|
|
Created on: Sep 23, 2019
|
|
|
|
|
|
|
|
Copyright 2019 flyinghead
|
|
|
|
|
2021-03-19 18:31:01 +00:00
|
|
|
This file is part of Flycast.
|
2019-09-24 21:59:36 +00:00
|
|
|
|
2021-03-19 18:31:01 +00:00
|
|
|
Flycast is free software: you can redistribute it and/or modify
|
2019-09-24 21:59:36 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2021-03-19 18:31:01 +00:00
|
|
|
Flycast is distributed in the hope that it will be useful,
|
2019-09-24 21:59:36 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2021-03-19 18:31:01 +00:00
|
|
|
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
2019-09-24 21:59:36 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "types.h"
|
|
|
|
|
2021-04-06 09:41:04 +00:00
|
|
|
struct WidescreenCheat
|
2019-09-24 21:59:36 +00:00
|
|
|
{
|
|
|
|
const char *game_id;
|
2019-09-27 12:41:59 +00:00
|
|
|
const char *area_or_version;
|
2019-09-24 21:59:36 +00:00
|
|
|
u32 addresses[16];
|
|
|
|
u32 values[16];
|
2022-06-24 09:47:24 +00:00
|
|
|
u32 origValues[16];
|
2019-09-24 21:59:36 +00:00
|
|
|
};
|
|
|
|
|
2021-04-06 09:41:04 +00:00
|
|
|
struct Cheat
|
|
|
|
{
|
|
|
|
enum class Type {
|
|
|
|
disabled,
|
|
|
|
setValue,
|
|
|
|
increase,
|
|
|
|
decrease,
|
|
|
|
runNextIfEq,
|
|
|
|
runNextIfNeq,
|
|
|
|
runNextIfGt,
|
2021-10-10 15:24:17 +00:00
|
|
|
runNextIfLt,
|
|
|
|
copy
|
2021-04-06 09:41:04 +00:00
|
|
|
};
|
2022-01-29 17:40:19 +00:00
|
|
|
Type type;
|
2021-04-06 09:41:04 +00:00
|
|
|
std::string description;
|
2022-01-29 17:40:19 +00:00
|
|
|
bool enabled;
|
|
|
|
u32 size;
|
|
|
|
u32 address;
|
|
|
|
u32 value;
|
|
|
|
u8 valueMask;
|
|
|
|
u32 repeatCount;
|
|
|
|
u32 repeatValueIncrement;
|
|
|
|
u32 repeatAddressIncrement;
|
|
|
|
u32 destAddress;
|
2022-04-13 11:10:56 +00:00
|
|
|
bool builtIn;
|
2022-01-29 17:40:19 +00:00
|
|
|
|
|
|
|
Cheat(Type type = Type::disabled, const std::string& description = "", bool enabled = false, u32 size = 0, u32 address = 0,
|
2022-05-29 11:30:06 +00:00
|
|
|
u32 value = 0, u8 valueMask = 0, u32 repeatCount = 1, u32 repeatValueIncrement = 0,
|
2022-04-13 11:10:56 +00:00
|
|
|
u32 repeatAddressIncrement = 0, u32 destAddress = 0, bool builtIn = false)
|
2022-05-29 11:30:06 +00:00
|
|
|
: type(type), description(description), enabled(enabled), size(size), address(address), value(value), valueMask(valueMask),
|
2022-04-13 11:10:56 +00:00
|
|
|
repeatCount(repeatCount), repeatValueIncrement(repeatValueIncrement), repeatAddressIncrement(repeatAddressIncrement),
|
|
|
|
destAddress(destAddress), builtIn(builtIn)
|
2022-01-29 17:40:19 +00:00
|
|
|
{
|
|
|
|
}
|
2021-04-06 09:41:04 +00:00
|
|
|
};
|
|
|
|
|
2019-09-24 21:59:36 +00:00
|
|
|
class CheatManager
|
|
|
|
{
|
|
|
|
public:
|
2021-04-06 09:41:04 +00:00
|
|
|
void reset(const std::string& gameId);
|
|
|
|
void apply();
|
|
|
|
size_t cheatCount() const { return cheats.size(); }
|
|
|
|
const std::string& cheatDescription(size_t index) const { return cheats[index].description; }
|
|
|
|
bool cheatEnabled(size_t index) const { return cheats[index].enabled; }
|
|
|
|
void enableCheat(size_t index, bool enabled) { cheats[index].enabled = enabled; }
|
|
|
|
void loadCheatFile(const std::string& filename);
|
2021-10-10 15:24:17 +00:00
|
|
|
void saveCheatFile(const std::string& filename);
|
2021-04-06 09:41:04 +00:00
|
|
|
// Returns true if using 16:9 anamorphic screen ratio
|
|
|
|
bool isWidescreen() const { return widescreen_cheat != nullptr; }
|
2021-10-10 15:24:17 +00:00
|
|
|
void addGameSharkCheat(const std::string& name, const std::string& s);
|
2021-03-19 18:31:01 +00:00
|
|
|
|
2019-09-24 21:59:36 +00:00
|
|
|
private:
|
2021-04-06 09:41:04 +00:00
|
|
|
u32 readRam(u32 addr, u32 bits);
|
|
|
|
void writeRam(u32 addr, u32 value, u32 bits);
|
2022-03-27 13:23:21 +00:00
|
|
|
void setActive(bool active);
|
2021-04-06 09:41:04 +00:00
|
|
|
|
|
|
|
static const WidescreenCheat widescreen_cheats[];
|
|
|
|
static const WidescreenCheat naomi_widescreen_cheats[];
|
|
|
|
const WidescreenCheat *widescreen_cheat = nullptr;
|
2021-03-19 18:31:01 +00:00
|
|
|
bool active = false;
|
2021-04-06 09:41:04 +00:00
|
|
|
std::vector<Cheat> cheats;
|
|
|
|
std::string gameId;
|
2021-10-10 15:24:17 +00:00
|
|
|
|
|
|
|
friend class CheatManagerTest_TestLoad_Test;
|
|
|
|
friend class CheatManagerTest_TestGameShark_Test;
|
|
|
|
friend class CheatManagerTest_TestSave_Test;
|
2019-09-24 21:59:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CheatManager cheatManager;
|