2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 13:54:46 -05:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-03-12 15:33:41 -04:00
|
|
|
#include <string>
|
2014-07-08 15:58:25 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2014-07-27 13:37:09 -04:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
|
|
|
class IniFile;
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2008-11-24 19:11:15 +00:00
|
|
|
namespace PatchEngine
|
|
|
|
{
|
2018-05-13 14:10:58 -04:00
|
|
|
enum class PatchType
|
2008-10-15 16:33:22 +00:00
|
|
|
{
|
2018-05-13 14:10:58 -04:00
|
|
|
Patch8Bit,
|
|
|
|
Patch16Bit,
|
|
|
|
Patch32Bit,
|
2008-10-15 16:33:22 +00:00
|
|
|
};
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2008-11-24 19:11:15 +00:00
|
|
|
struct PatchEntry
|
2008-10-15 16:33:22 +00:00
|
|
|
{
|
2018-05-13 13:53:49 -04:00
|
|
|
PatchEntry() = default;
|
|
|
|
PatchEntry(PatchType t, u32 addr, u32 value_) : type(t), address(addr), value(value_) {}
|
2018-05-13 14:10:58 -04:00
|
|
|
PatchType type = PatchType::Patch8Bit;
|
2018-05-13 13:53:49 -04:00
|
|
|
u32 address = 0;
|
|
|
|
u32 value = 0;
|
Patches for Resident Evil 2/3 audio issues
These games are erroneously zeroing buffers before they can be fully copied to ARAM by DMA. The responsible memset() calls are followed by a call to DVDRead() which issues dcbi instructions that effectively cancel the memset() on real hardware. Because Dolphin lacks dcache emulation, the effects of the memset() calls are observed, which causes missing audio.
In a comment on the original bug, phire noted that the issue can be corrected by simply nop'ing out the offending memset() calls. Because the games dynamically load different .rel executables based on the character and/or language, the addresses of these calls can vary.
To deal generally with the problem of code being dynamically loaded to fixed, known addresses, the patch engine is extended to support conditional patches which require a match against a known value. This sort of thing is already achievable with Action Replay/Gecko codes, but their use depends on enabling cheats globally in Dolphin, which is not a prerequisite shared by patches.
Patches are included for every region, character, and language combination. They are enabled by default.
The end result is an approximation of the games' behavior on real hardware without the associated complexity of proper dcache emulation.
https://bugs.dolphin-emu.org/issues/9840
2020-12-29 14:24:46 -08:00
|
|
|
u32 comparand = 0;
|
|
|
|
bool conditional = false;
|
2008-10-15 16:33:22 +00:00
|
|
|
};
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2008-11-24 19:11:15 +00:00
|
|
|
struct Patch
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::vector<PatchEntry> entries;
|
2020-12-10 12:58:27 +01:00
|
|
|
bool enabled = false;
|
2020-12-10 15:21:04 +01:00
|
|
|
bool default_enabled = false;
|
2018-05-13 13:53:49 -04:00
|
|
|
bool user_defined = false; // False if this code is shipped with Dolphin.
|
2008-11-24 19:11:15 +00:00
|
|
|
};
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2018-05-13 14:10:58 -04:00
|
|
|
const char* PatchTypeAsString(PatchType type);
|
|
|
|
|
2010-10-02 02:04:44 +00:00
|
|
|
int GetSpeedhackCycles(const u32 addr);
|
2014-03-12 15:33:41 -04:00
|
|
|
void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, IniFile& globalIni,
|
2013-09-07 23:02:49 +02:00
|
|
|
IniFile& localIni);
|
2013-09-23 02:39:14 -04:00
|
|
|
void LoadPatches();
|
2016-09-24 15:14:51 +00:00
|
|
|
bool ApplyFramePatches();
|
2013-07-25 16:43:00 -04:00
|
|
|
void Shutdown();
|
2017-04-06 15:34:40 +01:00
|
|
|
void Reload();
|
2011-07-09 21:00:30 +00:00
|
|
|
|
|
|
|
inline int GetPatchTypeCharLength(PatchType type)
|
|
|
|
{
|
|
|
|
int size = 8;
|
|
|
|
switch (type)
|
|
|
|
{
|
2018-05-13 14:10:58 -04:00
|
|
|
case PatchType::Patch8Bit:
|
2011-07-09 21:00:30 +00:00
|
|
|
size = 2;
|
|
|
|
break;
|
|
|
|
|
2018-05-13 14:10:58 -04:00
|
|
|
case PatchType::Patch16Bit:
|
2011-07-09 21:00:30 +00:00
|
|
|
size = 4;
|
|
|
|
break;
|
|
|
|
|
2018-05-13 14:10:58 -04:00
|
|
|
case PatchType::Patch32Bit:
|
2011-07-09 21:00:30 +00:00
|
|
|
size = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2017-01-03 18:59:33 -05:00
|
|
|
} // namespace PatchEngine
|