Overhaul cheat handling during rom load/close
- Stop overwriting/deleting other games' cheat files after rom change - Always clear/update references to disposed memory domains - Keep current cheats after core restart
This commit is contained in:
parent
76e73e1897
commit
f90126f19b
|
@ -73,7 +73,11 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public int? Compare => _compare.HasValue && !IsSeparator ? _compare : null;
|
public int? Compare => _compare.HasValue && !IsSeparator ? _compare : null;
|
||||||
|
|
||||||
public MemoryDomain Domain => _watch.Domain;
|
public MemoryDomain Domain
|
||||||
|
{
|
||||||
|
get => _watch.Domain;
|
||||||
|
set => _watch.Domain = value;
|
||||||
|
}
|
||||||
|
|
||||||
public WatchSize Size => _watch.Size;
|
public WatchSize Size => _watch.Size;
|
||||||
|
|
||||||
|
|
|
@ -404,6 +404,24 @@ namespace BizHawk.Client.Common
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateDomains(IMemoryDomains domains)
|
||||||
|
{
|
||||||
|
for (int i = _cheatList.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
var cheat = _cheatList[i];
|
||||||
|
var newDomain = domains[cheat.Domain.Name];
|
||||||
|
if (newDomain is not null)
|
||||||
|
{
|
||||||
|
cheat.Domain = newDomain;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_cheatList.RemoveAt(i);
|
||||||
|
Changes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly RigidMultiPredicateSort<Cheat> ColumnSorts
|
private static readonly RigidMultiPredicateSort<Cheat> ColumnSorts
|
||||||
= new RigidMultiPredicateSort<Cheat>(new Dictionary<string, Func<Cheat, IComparable>>
|
= new RigidMultiPredicateSort<Cheat>(new Dictionary<string, Func<Cheat, IComparable>>
|
||||||
{
|
{
|
||||||
|
|
|
@ -3783,21 +3783,32 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var previousRom = CurrentlyOpenRom;
|
||||||
CurrentlyOpenRom = oaOpenrom?.Path ?? openAdvancedArgs;
|
CurrentlyOpenRom = oaOpenrom?.Path ?? openAdvancedArgs;
|
||||||
CurrentlyOpenRomArgs = args;
|
CurrentlyOpenRomArgs = args;
|
||||||
|
|
||||||
Tools.Restart(Config, Emulator, Game);
|
Tools.Restart(Config, Emulator, Game);
|
||||||
|
|
||||||
|
if (previousRom != CurrentlyOpenRom)
|
||||||
|
{
|
||||||
|
CheatList.NewList(Tools.GenerateDefaultCheatFilename(), autosave: true);
|
||||||
if (Config.Cheats.LoadFileByGame && Emulator.HasMemoryDomains())
|
if (Config.Cheats.LoadFileByGame && Emulator.HasMemoryDomains())
|
||||||
{
|
{
|
||||||
CheatList.SetDefaultFileName(Tools.GenerateDefaultCheatFilename());
|
|
||||||
if (CheatList.AttemptToLoadCheatFile(Emulator.AsMemoryDomains()))
|
if (CheatList.AttemptToLoadCheatFile(Emulator.AsMemoryDomains()))
|
||||||
{
|
{
|
||||||
AddOnScreenMessage("Cheats file loaded");
|
AddOnScreenMessage("Cheats file loaded");
|
||||||
}
|
}
|
||||||
else if (CheatList.Any())
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
CheatList.Clear();
|
if (Emulator.HasMemoryDomains())
|
||||||
|
{
|
||||||
|
CheatList.UpdateDomains(Emulator.AsMemoryDomains());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheatList.NewList(Tools.GenerateDefaultCheatFilename(), autosave: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3838,6 +3849,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
DisplayManager.UpdateGlobals(Config, Emulator);
|
DisplayManager.UpdateGlobals(Config, Emulator);
|
||||||
DisplayManager.Blank();
|
DisplayManager.Blank();
|
||||||
ExtToolManager.BuildToolStrip();
|
ExtToolManager.BuildToolStrip();
|
||||||
|
CheatList.NewList("", autosave: true);
|
||||||
OnRomChanged();
|
OnRomChanged();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3973,6 +3985,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
PauseOnFrame = null;
|
PauseOnFrame = null;
|
||||||
CurrentlyOpenRom = null;
|
CurrentlyOpenRom = null;
|
||||||
CurrentlyOpenRomArgs = null;
|
CurrentlyOpenRomArgs = null;
|
||||||
|
CheatList.NewList("", autosave: true);
|
||||||
OnRomChanged();
|
OnRomChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -586,11 +586,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_emulator = emulator;
|
_emulator = emulator;
|
||||||
_game = game;
|
_game = game;
|
||||||
_apiProvider = null;
|
_apiProvider = null;
|
||||||
// If Cheat tool is loaded, restarting will restart the list too anyway
|
|
||||||
if (!Has<Cheats>())
|
|
||||||
{
|
|
||||||
_owner.CheatList.NewList(GenerateDefaultCheatFilename(), autosave: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
var unavailable = new List<IToolForm>();
|
var unavailable = new List<IToolForm>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue