Compare commits
1 Commits
i-hate-cli
...
cheat-fix
Author | SHA1 | Date | |
---|---|---|---|
5a38c5f190 |
@ -9,12 +9,12 @@
|
||||
#include "core/cheats/cheat_base.h"
|
||||
#include "core/cheats/cheats.h"
|
||||
#include "core/cheats/gateway_cheat.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "ui_configure_cheats.h"
|
||||
|
||||
ConfigureCheats::ConfigureCheats(u64 title_id_, QWidget* parent)
|
||||
: QWidget(parent), ui(std::make_unique<Ui::ConfigureCheats>()), title_id{title_id_} {
|
||||
ConfigureCheats::ConfigureCheats(Cheats::CheatEngine& cheat_engine_, u64 title_id_, QWidget* parent)
|
||||
: QWidget(parent),
|
||||
ui(std::make_unique<Ui::ConfigureCheats>()), cheat_engine{cheat_engine_}, title_id{
|
||||
title_id_} {
|
||||
// Setup gui control settings
|
||||
ui->setupUi(this);
|
||||
ui->tableCheats->setColumnWidth(0, 30);
|
||||
@ -36,15 +36,14 @@ ConfigureCheats::ConfigureCheats(u64 title_id_, QWidget* parent)
|
||||
[this] { SaveCheat(ui->tableCheats->currentRow()); });
|
||||
connect(ui->buttonDelete, &QPushButton::clicked, this, &ConfigureCheats::OnDeleteCheat);
|
||||
|
||||
cheat_engine = std::make_unique<Cheats::CheatEngine>(title_id, Core::System::GetInstance());
|
||||
|
||||
cheat_engine.LoadCheatFile(title_id);
|
||||
LoadCheats();
|
||||
}
|
||||
|
||||
ConfigureCheats::~ConfigureCheats() = default;
|
||||
|
||||
void ConfigureCheats::LoadCheats() {
|
||||
cheats = cheat_engine->GetCheats();
|
||||
cheats = cheat_engine.GetCheats();
|
||||
const int cheats_count = static_cast<int>(cheats.size());
|
||||
|
||||
ui->tableCheats->setRowCount(cheats_count);
|
||||
@ -108,12 +107,12 @@ bool ConfigureCheats::SaveCheat(int row) {
|
||||
ui->textNotes->toPlainText().toStdString());
|
||||
|
||||
if (newly_created) {
|
||||
cheat_engine->AddCheat(cheat);
|
||||
cheat_engine.AddCheat(std::move(cheat));
|
||||
newly_created = false;
|
||||
} else {
|
||||
cheat_engine->UpdateCheat(row, cheat);
|
||||
cheat_engine.UpdateCheat(row, std::move(cheat));
|
||||
}
|
||||
cheat_engine->SaveCheatFile();
|
||||
cheat_engine.SaveCheatFile(title_id);
|
||||
|
||||
int previous_row = ui->tableCheats->currentRow();
|
||||
int previous_col = ui->tableCheats->currentColumn();
|
||||
@ -163,7 +162,7 @@ void ConfigureCheats::OnCheckChanged(int state) {
|
||||
const QCheckBox* checkbox = qobject_cast<QCheckBox*>(sender());
|
||||
int row = static_cast<int>(checkbox->property("row").toInt());
|
||||
cheats[row]->SetEnabled(state);
|
||||
cheat_engine->SaveCheatFile();
|
||||
cheat_engine.SaveCheatFile(title_id);
|
||||
}
|
||||
|
||||
void ConfigureCheats::OnTextEdited() {
|
||||
@ -175,8 +174,8 @@ void ConfigureCheats::OnDeleteCheat() {
|
||||
if (newly_created) {
|
||||
newly_created = false;
|
||||
} else {
|
||||
cheat_engine->RemoveCheat(ui->tableCheats->currentRow());
|
||||
cheat_engine->SaveCheatFile();
|
||||
cheat_engine.RemoveCheat(ui->tableCheats->currentRow());
|
||||
cheat_engine.SaveCheatFile(title_id);
|
||||
}
|
||||
|
||||
LoadCheats();
|
||||
|
@ -5,6 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <QWidget>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Cheats {
|
||||
@ -20,7 +22,8 @@ class ConfigureCheats : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigureCheats(u64 title_id_, QWidget* parent = nullptr);
|
||||
explicit ConfigureCheats(Cheats::CheatEngine& cheat_engine, u64 title_id_,
|
||||
QWidget* parent = nullptr);
|
||||
~ConfigureCheats();
|
||||
bool ApplyConfiguration();
|
||||
|
||||
@ -53,9 +56,9 @@ private slots:
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::ConfigureCheats> ui;
|
||||
std::vector<std::shared_ptr<Cheats::CheatBase>> cheats;
|
||||
Cheats::CheatEngine& cheat_engine;
|
||||
std::span<const std::shared_ptr<Cheats::CheatBase>> cheats;
|
||||
bool edited = false, newly_created = false;
|
||||
int last_row = -1, last_col = -1;
|
||||
u64 title_id;
|
||||
std::unique_ptr<Cheats::CheatEngine> cheat_engine;
|
||||
};
|
||||
|
@ -36,7 +36,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const QString
|
||||
graphics_tab = std::make_unique<ConfigureGraphics>(this);
|
||||
system_tab = std::make_unique<ConfigureSystem>(this);
|
||||
debug_tab = std::make_unique<ConfigureDebug>(this);
|
||||
cheat_tab = std::make_unique<ConfigureCheats>(title_id, this);
|
||||
cheat_tab = std::make_unique<ConfigureCheats>(system.CheatEngine(), title_id, this);
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -10,8 +10,6 @@
|
||||
#include "core/cheats/gateway_cheat.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hw/gpu.h"
|
||||
|
||||
namespace Cheats {
|
||||
|
||||
@ -19,11 +17,11 @@ namespace Cheats {
|
||||
// we use the same value
|
||||
constexpr u64 run_interval_ticks = 50'000'000;
|
||||
|
||||
CheatEngine::CheatEngine(u64 title_id_, Core::System& system_)
|
||||
: system(system_), title_id{title_id_} {
|
||||
LoadCheatFile();
|
||||
CheatEngine::CheatEngine(Core::System& system_) : system{system_} {}
|
||||
|
||||
CheatEngine::~CheatEngine() {
|
||||
if (system.IsPoweredOn()) {
|
||||
Connect();
|
||||
system.CoreTiming().UnscheduleEvent(event, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,24 +32,18 @@ void CheatEngine::Connect() {
|
||||
system.CoreTiming().ScheduleEvent(run_interval_ticks, event);
|
||||
}
|
||||
|
||||
CheatEngine::~CheatEngine() {
|
||||
if (system.IsPoweredOn()) {
|
||||
system.CoreTiming().UnscheduleEvent(event, 0);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<CheatBase>> CheatEngine::GetCheats() const {
|
||||
std::shared_lock<std::shared_mutex> lock(cheats_list_mutex);
|
||||
std::span<const std::shared_ptr<CheatBase>> CheatEngine::GetCheats() const {
|
||||
std::shared_lock lock{cheats_list_mutex};
|
||||
return cheats_list;
|
||||
}
|
||||
|
||||
void CheatEngine::AddCheat(const std::shared_ptr<CheatBase>& cheat) {
|
||||
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
|
||||
cheats_list.push_back(cheat);
|
||||
void CheatEngine::AddCheat(std::shared_ptr<CheatBase>&& cheat) {
|
||||
std::unique_lock lock{cheats_list_mutex};
|
||||
cheats_list.push_back(std::move(cheat));
|
||||
}
|
||||
|
||||
void CheatEngine::RemoveCheat(std::size_t index) {
|
||||
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
|
||||
std::unique_lock lock{cheats_list_mutex};
|
||||
if (index < 0 || index >= cheats_list.size()) {
|
||||
LOG_ERROR(Core_Cheats, "Invalid index {}", index);
|
||||
return;
|
||||
@ -59,16 +51,16 @@ void CheatEngine::RemoveCheat(std::size_t index) {
|
||||
cheats_list.erase(cheats_list.begin() + index);
|
||||
}
|
||||
|
||||
void CheatEngine::UpdateCheat(std::size_t index, const std::shared_ptr<CheatBase>& new_cheat) {
|
||||
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
|
||||
void CheatEngine::UpdateCheat(std::size_t index, std::shared_ptr<CheatBase>&& new_cheat) {
|
||||
std::unique_lock lock{cheats_list_mutex};
|
||||
if (index < 0 || index >= cheats_list.size()) {
|
||||
LOG_ERROR(Core_Cheats, "Invalid index {}", index);
|
||||
return;
|
||||
}
|
||||
cheats_list[index] = new_cheat;
|
||||
cheats_list[index] = std::move(new_cheat);
|
||||
}
|
||||
|
||||
void CheatEngine::SaveCheatFile() const {
|
||||
void CheatEngine::SaveCheatFile(u64 title_id) const {
|
||||
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
|
||||
const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id);
|
||||
|
||||
@ -83,7 +75,7 @@ void CheatEngine::SaveCheatFile() const {
|
||||
}
|
||||
}
|
||||
|
||||
void CheatEngine::LoadCheatFile() {
|
||||
void CheatEngine::LoadCheatFile(u64 title_id) {
|
||||
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
|
||||
const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id);
|
||||
|
||||
@ -96,15 +88,15 @@ void CheatEngine::LoadCheatFile() {
|
||||
|
||||
auto gateway_cheats = GatewayCheat::LoadFile(filepath);
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
|
||||
std::move(gateway_cheats.begin(), gateway_cheats.end(), std::back_inserter(cheats_list));
|
||||
std::unique_lock lock{cheats_list_mutex};
|
||||
cheats_list = std::move(gateway_cheats);
|
||||
}
|
||||
}
|
||||
|
||||
void CheatEngine::RunCallback([[maybe_unused]] std::uintptr_t user_data, s64 cycles_late) {
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(cheats_list_mutex);
|
||||
for (auto& cheat : cheats_list) {
|
||||
std::shared_lock lock{cheats_list_mutex};
|
||||
for (const auto& cheat : cheats_list) {
|
||||
if (cheat->IsEnabled()) {
|
||||
cheat->Execute(system);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
|
||||
@ -24,22 +25,38 @@ class CheatBase;
|
||||
|
||||
class CheatEngine {
|
||||
public:
|
||||
explicit CheatEngine(u64 title_id_, Core::System& system);
|
||||
explicit CheatEngine(Core::System& system);
|
||||
~CheatEngine();
|
||||
|
||||
/// Registers the cheat execution callback.
|
||||
void Connect();
|
||||
std::vector<std::shared_ptr<CheatBase>> GetCheats() const;
|
||||
void AddCheat(const std::shared_ptr<CheatBase>& cheat);
|
||||
|
||||
/// Returns a span of the currently active cheats.
|
||||
std::span<const std::shared_ptr<CheatBase>> GetCheats() const;
|
||||
|
||||
/// Adds a cheat to the cheat engine.
|
||||
void AddCheat(std::shared_ptr<CheatBase>&& cheat);
|
||||
|
||||
/// Removes a cheat at the specified index in the cheats list.
|
||||
void RemoveCheat(std::size_t index);
|
||||
void UpdateCheat(std::size_t index, const std::shared_ptr<CheatBase>& new_cheat);
|
||||
void SaveCheatFile() const;
|
||||
|
||||
/// Updates a cheat at the specified index in the cheats list.
|
||||
void UpdateCheat(std::size_t index, std::shared_ptr<CheatBase>&& new_cheat);
|
||||
|
||||
/// Loads the cheat file from disk for the specified title id.
|
||||
void LoadCheatFile(u64 title_id);
|
||||
|
||||
/// Saves currently active cheats to file for the specified title id.
|
||||
void SaveCheatFile(u64 title_id) const;
|
||||
|
||||
private:
|
||||
void LoadCheatFile();
|
||||
/// The cheat execution callback.
|
||||
void RunCallback(std::uintptr_t user_data, s64 cycles_late);
|
||||
|
||||
private:
|
||||
Core::System& system;
|
||||
Core::TimingEventType* event;
|
||||
std::vector<std::shared_ptr<CheatBase>> cheats_list;
|
||||
mutable std::shared_mutex cheats_list_mutex;
|
||||
Core::TimingEventType* event;
|
||||
Core::System& system;
|
||||
u64 title_id;
|
||||
};
|
||||
} // namespace Cheats
|
||||
|
@ -472,8 +472,8 @@ std::string GatewayCheat::ToString() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string& filepath) {
|
||||
std::vector<std::unique_ptr<CheatBase>> cheats;
|
||||
std::vector<std::shared_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string& filepath) {
|
||||
std::vector<std::shared_ptr<CheatBase>> cheats;
|
||||
|
||||
boost::iostreams::stream<boost::iostreams::file_descriptor_source> file;
|
||||
FileUtil::OpenFStream<std::ios_base::in>(file, filepath);
|
||||
@ -493,7 +493,7 @@ std::vector<std::unique_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string
|
||||
line = Common::StripSpaces(line); // remove spaces at front and end
|
||||
if (line.length() >= 2 && line.front() == '[') {
|
||||
if (!cheat_lines.empty()) {
|
||||
cheats.push_back(std::make_unique<GatewayCheat>(name, cheat_lines, comments));
|
||||
cheats.push_back(std::make_shared<GatewayCheat>(name, cheat_lines, comments));
|
||||
cheats.back()->SetEnabled(enabled);
|
||||
enabled = false;
|
||||
}
|
||||
@ -511,7 +511,7 @@ std::vector<std::unique_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string
|
||||
}
|
||||
}
|
||||
if (!cheat_lines.empty()) {
|
||||
cheats.push_back(std::make_unique<GatewayCheat>(name, cheat_lines, comments));
|
||||
cheats.push_back(std::make_shared<GatewayCheat>(name, cheat_lines, comments));
|
||||
cheats.back()->SetEnabled(enabled);
|
||||
}
|
||||
return cheats;
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
/// (there might be multiple lines of those hex numbers)
|
||||
/// Comment lines start with a '*'
|
||||
/// This function will pares the file for such structures
|
||||
static std::vector<std::unique_ptr<CheatBase>> LoadFile(const std::string& filepath);
|
||||
static std::vector<std::shared_ptr<CheatBase>> LoadFile(const std::string& filepath);
|
||||
|
||||
private:
|
||||
std::atomic<bool> enabled = false;
|
||||
|
@ -72,6 +72,8 @@ Core::Timing& Global() {
|
||||
return System::GetInstance().CoreTiming();
|
||||
}
|
||||
|
||||
System::System() : cheat_engine{*this} {}
|
||||
|
||||
System::~System() = default;
|
||||
|
||||
System::ResultStatus System::RunLoop(bool tight_loop) {
|
||||
@ -318,7 +320,10 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
|
||||
LOG_ERROR(Core, "Failed to find title id for ROM (Error {})",
|
||||
static_cast<u32>(load_result));
|
||||
}
|
||||
cheat_engine = std::make_unique<Cheats::CheatEngine>(title_id, *this);
|
||||
|
||||
cheat_engine.LoadCheatFile(title_id);
|
||||
cheat_engine.Connect();
|
||||
|
||||
perf_stats = std::make_unique<PerfStats>(title_id);
|
||||
|
||||
if (Settings::values.custom_textures) {
|
||||
@ -489,11 +494,11 @@ const Memory::MemorySystem& System::Memory() const {
|
||||
}
|
||||
|
||||
Cheats::CheatEngine& System::CheatEngine() {
|
||||
return *cheat_engine;
|
||||
return cheat_engine;
|
||||
}
|
||||
|
||||
const Cheats::CheatEngine& System::CheatEngine() const {
|
||||
return *cheat_engine;
|
||||
return cheat_engine;
|
||||
}
|
||||
|
||||
void System::RegisterVideoDumper(std::shared_ptr<VideoDumper::Backend> dumper) {
|
||||
@ -540,7 +545,6 @@ void System::Shutdown(bool is_deserializing) {
|
||||
if (!is_deserializing) {
|
||||
GDBStub::Shutdown();
|
||||
perf_stats.reset();
|
||||
cheat_engine.reset();
|
||||
app_loader.reset();
|
||||
}
|
||||
custom_tex_manager.reset();
|
||||
@ -712,7 +716,7 @@ void System::serialize(Archive& ar, const unsigned int file_version) {
|
||||
timing->UnlockEventQueue();
|
||||
Service::GSP::SetGlobalModule(*this);
|
||||
memory->SetDSP(*dsp_core);
|
||||
cheat_engine->Connect();
|
||||
cheat_engine.Connect();
|
||||
VideoCore::g_renderer->Sync();
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <string>
|
||||
#include <boost/serialization/version.hpp>
|
||||
#include "common/common_types.h"
|
||||
#include "core/cheats/cheats.h"
|
||||
#include "core/frontend/applets/mii_selector.h"
|
||||
#include "core/frontend/applets/swkbd.h"
|
||||
#include "core/loader/loader.h"
|
||||
@ -49,10 +50,6 @@ namespace Kernel {
|
||||
class KernelSystem;
|
||||
}
|
||||
|
||||
namespace Cheats {
|
||||
class CheatEngine;
|
||||
}
|
||||
|
||||
namespace VideoDumper {
|
||||
class Backend;
|
||||
}
|
||||
@ -95,6 +92,7 @@ public:
|
||||
ErrorUnknown ///< Any other error
|
||||
};
|
||||
|
||||
System();
|
||||
~System();
|
||||
|
||||
/**
|
||||
@ -372,7 +370,7 @@ private:
|
||||
std::shared_ptr<Frontend::SoftwareKeyboard> registered_swkbd;
|
||||
|
||||
/// Cheats manager
|
||||
std::unique_ptr<Cheats::CheatEngine> cheat_engine;
|
||||
Cheats::CheatEngine cheat_engine;
|
||||
|
||||
/// Video dumper backend
|
||||
std::shared_ptr<VideoDumper::Backend> video_dumper;
|
||||
|
Reference in New Issue
Block a user