Add Cheat Manager (#2964)
* add cheatmanager * use modloader to load cheats for manager * addressed nits
This commit is contained in:
parent
dc8a1d5cba
commit
e98abf1820
12 changed files with 388 additions and 13 deletions
|
@ -664,7 +664,20 @@ namespace Ryujinx.HLE.HOS
|
|||
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Installing cheat '{cheat.Name}'");
|
||||
|
||||
tamperMachine.InstallAtmosphereCheat(cheat.Name, cheat.Instructions, tamperInfo, exeAddress);
|
||||
tamperMachine.InstallAtmosphereCheat(cheat.Name, cheatId, cheat.Instructions, tamperInfo, exeAddress);
|
||||
}
|
||||
|
||||
EnableCheats(titleId, tamperMachine);
|
||||
}
|
||||
|
||||
internal void EnableCheats(ulong titleId, TamperMachine tamperMachine)
|
||||
{
|
||||
var contentDirectory = FindTitleDir(new DirectoryInfo(Path.Combine(GetModsBasePath(), AmsContentsDir)), $"{titleId:x16}");
|
||||
string enabledCheatsPath = Path.Combine(contentDirectory.FullName, CheatDir, "enabled.txt");
|
||||
|
||||
if (File.Exists(enabledCheatsPath))
|
||||
{
|
||||
tamperMachine.EnableCheats(File.ReadAllLines(enabledCheatsPath));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Ryujinx.HLE.HOS.Tamper
|
|||
public string Name { get; }
|
||||
public bool TampersCodeMemory { get; set; } = false;
|
||||
public ITamperedProcess Process { get; }
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public AtmosphereProgram(string name, ITamperedProcess process, Parameter<long> pressedKeys, IOperation entryPoint)
|
||||
{
|
||||
|
@ -22,8 +23,11 @@ namespace Ryujinx.HLE.HOS.Tamper
|
|||
|
||||
public void Execute(ControllerKeys pressedKeys)
|
||||
{
|
||||
_pressedKeys.Value = (long)pressedKeys;
|
||||
_entryPoint.Execute();
|
||||
if (IsEnabled)
|
||||
{
|
||||
_pressedKeys.Value = (long)pressedKeys;
|
||||
_entryPoint.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Ryujinx.HLE.HOS.Tamper
|
|||
{
|
||||
interface ITamperProgram
|
||||
{
|
||||
bool IsEnabled { get; set; }
|
||||
string Name { get; }
|
||||
bool TampersCodeMemory { get; set; }
|
||||
ITamperedProcess Process { get; }
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace Ryujinx.HLE.HOS
|
|||
private Thread _tamperThread = null;
|
||||
private ConcurrentQueue<ITamperProgram> _programs = new ConcurrentQueue<ITamperProgram>();
|
||||
private long _pressedKeys = 0;
|
||||
private Dictionary<string, ITamperProgram> _programDictionary = new Dictionary<string, ITamperProgram>();
|
||||
|
||||
private void Activate()
|
||||
{
|
||||
|
@ -31,7 +32,7 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
}
|
||||
|
||||
internal void InstallAtmosphereCheat(string name, IEnumerable<string> rawInstructions, ProcessTamperInfo info, ulong exeAddress)
|
||||
internal void InstallAtmosphereCheat(string name, string buildId, IEnumerable<string> rawInstructions, ProcessTamperInfo info, ulong exeAddress)
|
||||
{
|
||||
if (!CanInstallOnPid(info.Process.Pid))
|
||||
{
|
||||
|
@ -47,6 +48,7 @@ namespace Ryujinx.HLE.HOS
|
|||
program.TampersCodeMemory = false;
|
||||
|
||||
_programs.Enqueue(program);
|
||||
_programDictionary.TryAdd($"{buildId}-{name}", program);
|
||||
}
|
||||
|
||||
Activate();
|
||||
|
@ -65,6 +67,22 @@ namespace Ryujinx.HLE.HOS
|
|||
return true;
|
||||
}
|
||||
|
||||
public void EnableCheats(string[] enabledCheats)
|
||||
{
|
||||
foreach (var program in _programDictionary.Values)
|
||||
{
|
||||
program.IsEnabled = false;
|
||||
}
|
||||
|
||||
foreach (var cheat in enabledCheats)
|
||||
{
|
||||
if (_programDictionary.TryGetValue(cheat, out var program))
|
||||
{
|
||||
program.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsProcessValid(ITamperedProcess process)
|
||||
{
|
||||
return process.State != ProcessState.Crashed && process.State != ProcessState.Exiting && process.State != ProcessState.Exited;
|
||||
|
@ -105,6 +123,8 @@ namespace Ryujinx.HLE.HOS
|
|||
if (!_programs.TryDequeue(out ITamperProgram program))
|
||||
{
|
||||
// No more programs in the queue.
|
||||
_programDictionary.Clear();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue