lua - add client.addcheat() and client.removecheat() that match the functionality of the gameshark tool. Deprecate the nes.addgamegenie() and nes.removegamegenie() methods in favor of these
This commit is contained in:
parent
c52a896cff
commit
1ce8a368d4
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
using NLua;
|
||||
|
||||
using BizHawk.Client.Common.cheats;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores.Nintendo.NES;
|
||||
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
|
||||
|
@ -31,26 +29,17 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public override string Name => "nes";
|
||||
|
||||
private bool NESAvailable => APIs.Emu.GetSystemId() == "NES";
|
||||
|
||||
private object Settings
|
||||
{
|
||||
get => APIs.Emu.GetSettings();
|
||||
set => APIs.Emu.PutSettings(value);
|
||||
}
|
||||
|
||||
[LuaMethodExample("nes.addgamegenie( \"GXXZZLVI\" );")]
|
||||
[LuaDeprecatedMethod]
|
||||
[LuaMethod("addgamegenie", "Adds the specified game genie code. If an NES game is not currently loaded or the code is not a valid game genie code, this will have no effect")]
|
||||
public void AddGameGenie(string code)
|
||||
{
|
||||
if (NESAvailable && MemoryDomains != null)
|
||||
{
|
||||
var result = NesGameGenieDecoder.Decode(code);
|
||||
if (result.IsValid)
|
||||
{
|
||||
Global.CheatList.Add(result.ToCheat(MemoryDomains.SystemBus, ""));
|
||||
}
|
||||
}
|
||||
Log("Method no longer supported, use client.addcheat() instead");
|
||||
}
|
||||
|
||||
/// <exception cref="InvalidOperationException">loaded core is not NESHawk or QuickNes</exception>
|
||||
|
@ -113,19 +102,11 @@ namespace BizHawk.Client.Common
|
|||
_ => throw new InvalidOperationException()
|
||||
};
|
||||
|
||||
[LuaMethodExample("nes.removegamegenie( \"GXXZZLVI\" );")]
|
||||
[LuaDeprecatedMethod]
|
||||
[LuaMethod("removegamegenie", "Removes the specified game genie code. If an NES game is not currently loaded or the code is not a valid game genie code, this will have no effect")]
|
||||
public void RemoveGameGenie(string code)
|
||||
{
|
||||
if (NESAvailable)
|
||||
{
|
||||
var decoder = NesGameGenieDecoder.Decode(code);
|
||||
if (decoder.IsValid)
|
||||
{
|
||||
Global.CheatList.RemoveRange(
|
||||
Global.CheatList.Where(c => c.Address == decoder.Address));
|
||||
}
|
||||
}
|
||||
Log("Method no longer supported, use client.removecheat() instead");
|
||||
}
|
||||
|
||||
/// <exception cref="InvalidOperationException">loaded core is not NESHawk or QuickNes</exception>
|
||||
|
|
|
@ -777,11 +777,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
// TODO: make these actual properties
|
||||
// This is a quick hack to reduce the dependency on Globals
|
||||
private IEmulator Emulator
|
||||
public IEmulator Emulator
|
||||
{
|
||||
get => GlobalWin.Emulator;
|
||||
|
||||
set
|
||||
private set
|
||||
{
|
||||
GlobalWin.Emulator = value;
|
||||
_currentVideoProvider = GlobalWin.Emulator.AsVideoProviderOrDefault();
|
||||
|
|
|
@ -10,6 +10,7 @@ using System.Threading;
|
|||
using System.Diagnostics;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Client.Common.cheats;
|
||||
|
||||
// ReSharper disable StringLiteralTypo
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
@ -464,5 +465,63 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("client.addcheat(\"NNNPAK\");")]
|
||||
[LuaMethod("addcheat", "adds a cheat code, if supported")]
|
||||
public void AddCheat(string code)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MainForm.Emulator.HasMemoryDomains())
|
||||
{
|
||||
Log($"cheat codes not supported by the current system: {MainForm.Emulator.SystemId}");
|
||||
return;
|
||||
}
|
||||
|
||||
var decoder = new GameSharkDecoder(MainForm.Emulator.AsMemoryDomains(), MainForm.Emulator.SystemId);
|
||||
var result = decoder.Decode(code);
|
||||
|
||||
if (result.IsValid)
|
||||
{
|
||||
var domain = decoder.CheatDomain();
|
||||
Global.CheatList.Add(result.ToCheat(domain, code));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(result.Error);
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("client.removecheat(\"NNNPAK\");")]
|
||||
[LuaMethod("removecheat", "removes a cheat, if it already exists")]
|
||||
public void RemoveCheat(string code)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MainForm.Emulator.HasMemoryDomains())
|
||||
{
|
||||
Log($"cheat codes not supported by the current system: {MainForm.Emulator.SystemId}");
|
||||
return;
|
||||
}
|
||||
|
||||
var decoder = new GameSharkDecoder(MainForm.Emulator.AsMemoryDomains(), MainForm.Emulator.SystemId);
|
||||
var result = decoder.Decode(code);
|
||||
|
||||
if (result.IsValid)
|
||||
{
|
||||
Global.CheatList.RemoveRange(
|
||||
Global.CheatList.Where(c => c.Address == result.Address));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(result.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue