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 MemoryDomain Domain => _watch.Domain;
|
||||
public MemoryDomain Domain
|
||||
{
|
||||
get => _watch.Domain;
|
||||
set => _watch.Domain = value;
|
||||
}
|
||||
|
||||
public WatchSize Size => _watch.Size;
|
||||
|
||||
|
|
|
@ -404,6 +404,24 @@ namespace BizHawk.Client.Common
|
|||
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
|
||||
= new RigidMultiPredicateSort<Cheat>(new Dictionary<string, Func<Cheat, IComparable>>
|
||||
{
|
||||
|
|
|
@ -3783,21 +3783,32 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
var previousRom = CurrentlyOpenRom;
|
||||
CurrentlyOpenRom = oaOpenrom?.Path ?? openAdvancedArgs;
|
||||
CurrentlyOpenRomArgs = args;
|
||||
|
||||
Tools.Restart(Config, Emulator, Game);
|
||||
|
||||
if (Config.Cheats.LoadFileByGame && Emulator.HasMemoryDomains())
|
||||
if (previousRom != CurrentlyOpenRom)
|
||||
{
|
||||
CheatList.SetDefaultFileName(Tools.GenerateDefaultCheatFilename());
|
||||
if (CheatList.AttemptToLoadCheatFile(Emulator.AsMemoryDomains()))
|
||||
CheatList.NewList(Tools.GenerateDefaultCheatFilename(), autosave: true);
|
||||
if (Config.Cheats.LoadFileByGame && Emulator.HasMemoryDomains())
|
||||
{
|
||||
AddOnScreenMessage("Cheats file loaded");
|
||||
if (CheatList.AttemptToLoadCheatFile(Emulator.AsMemoryDomains()))
|
||||
{
|
||||
AddOnScreenMessage("Cheats file loaded");
|
||||
}
|
||||
}
|
||||
else if (CheatList.Any())
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Emulator.HasMemoryDomains())
|
||||
{
|
||||
CheatList.Clear();
|
||||
CheatList.UpdateDomains(Emulator.AsMemoryDomains());
|
||||
}
|
||||
else
|
||||
{
|
||||
CheatList.NewList(Tools.GenerateDefaultCheatFilename(), autosave: true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3838,6 +3849,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
DisplayManager.UpdateGlobals(Config, Emulator);
|
||||
DisplayManager.Blank();
|
||||
ExtToolManager.BuildToolStrip();
|
||||
CheatList.NewList("", autosave: true);
|
||||
OnRomChanged();
|
||||
return false;
|
||||
}
|
||||
|
@ -3973,6 +3985,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
PauseOnFrame = null;
|
||||
CurrentlyOpenRom = null;
|
||||
CurrentlyOpenRomArgs = null;
|
||||
CheatList.NewList("", autosave: true);
|
||||
OnRomChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -586,11 +586,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
_emulator = emulator;
|
||||
_game = game;
|
||||
_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>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue