mirror of
https://github.com/libretro/Mesen.git
synced 2025-01-31 13:52:19 +00:00
Cheats: Fixed CHT file loading logic for cheats that are not saved as "enabled" in the CHT file
This commit is contained in:
parent
b1ffc15fef
commit
94dd9683d1
@ -10,46 +10,61 @@ namespace Mesen.GUI.Forms.Cheats
|
||||
{
|
||||
class FceuxCheatLoader
|
||||
{
|
||||
private static string GetValue(List<string> data, int index)
|
||||
{
|
||||
if(data.Count > index) {
|
||||
return data[index];
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static List<CheatInfo> Load(string filename, string gameName, string gameCrc)
|
||||
{
|
||||
List<CheatInfo> cheats = new List<CheatInfo>();
|
||||
|
||||
foreach(string cheatLine in File.ReadAllLines(filename)) {
|
||||
try {
|
||||
string[] data = cheatLine.Split(':');
|
||||
if(!string.IsNullOrWhiteSpace(cheatLine)) {
|
||||
List<string> data = new List<string>(cheatLine.Split(':'));
|
||||
|
||||
if(data.Length >= 3) {
|
||||
string address = null;
|
||||
string value = null;
|
||||
string compare = null;
|
||||
string description = null;
|
||||
if(data.Count >= 3) {
|
||||
bool enabled = false;
|
||||
if(data[0].Length <= 2) {
|
||||
enabled = true;
|
||||
data[1] = data[0] + data[1];
|
||||
data.RemoveAt(0);
|
||||
}
|
||||
|
||||
if(data[0] == "C" || data[0] == "S" || data[0] == "CS" || data[0] == "SC" || string.IsNullOrWhiteSpace(data[0])) {
|
||||
address = data[1];
|
||||
value = data[2];
|
||||
compare = data[0].Contains("C") ? data[3] : null;
|
||||
description = data[0].Contains("C") ? data[4] : data[3];
|
||||
} else {
|
||||
address = data[0];
|
||||
value = data[1];
|
||||
description = data[2];
|
||||
string address = data[0].Substring(data[0].Length - 4);
|
||||
string value = data[1];
|
||||
string compare = null;
|
||||
string description = null;
|
||||
if(data[0].StartsWith("SC") && data[0].Length >= 6 || (data[0].StartsWith("C") && data[0].Length >= 5)) {
|
||||
compare = data[2];
|
||||
description = GetValue(data, 3);
|
||||
} else {
|
||||
description = GetValue(data, 2);
|
||||
}
|
||||
|
||||
var cheat = new CheatInfo() {
|
||||
GameCrc = gameCrc,
|
||||
GameName = gameName,
|
||||
CheatName = description,
|
||||
Enabled = enabled,
|
||||
CheatType = CheatType.Custom,
|
||||
IsRelativeAddress = true,
|
||||
Address = HexToInt(address),
|
||||
Value = (byte)HexToInt(value)
|
||||
};
|
||||
|
||||
if(compare != null) {
|
||||
cheat.CompareValue = (byte)HexToInt(compare);
|
||||
cheat.UseCompareValue = true;
|
||||
}
|
||||
|
||||
cheats.Add(cheat);
|
||||
}
|
||||
|
||||
var cheat = new CheatInfo();
|
||||
cheat.GameCrc = gameCrc;
|
||||
cheat.GameName = gameName;
|
||||
cheat.CheatName = description;
|
||||
cheat.Enabled = false;
|
||||
|
||||
cheat.CheatType = CheatType.Custom;
|
||||
cheat.IsRelativeAddress = true;
|
||||
cheat.Address = HexToInt(address);
|
||||
cheat.Value = (byte)HexToInt(value);
|
||||
if(compare != null) {
|
||||
cheat.CompareValue = (byte)HexToInt(compare);
|
||||
cheat.UseCompareValue = true;
|
||||
}
|
||||
cheats.Add(cheat);
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user