This repository has been archived by the owner on Jan 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGBA.cs
80 lines (71 loc) · 2.34 KB
/
GBA.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Runtime.InteropServices;
using LiveSplit.EMUHELP;
using LiveSplit.EMUHELP.GBA;
public class GameBoyAdvance : GBA { }
public class GameboyAdvance : GBA { }
public class Gameboyadvance : GBA { }
public class GBA : HelperBase
{
public GBA(bool generateCode) : base(generateCode)
{
var ProcessNames = new string[]
{
"visualboyadvance-m",
"VisualBoyAdvance",
"mGBA",
"NO$GBA.EXE",
"retroarch",
"EmuHawk",
"mednafen",
"GSR",
"GSE",
};
GameProcess = new ProcessHook(ProcessNames);
Debugs.Info(" => GBA Helper started");
}
public GBA()
: this(true) { }
protected override void InitActions()
{
Emu = Game.ProcessName switch
{
"visualboyadvance-m" or "VisualBoyAdvance" => new VisualBoyAdvance(this),
"mGBA" => new mGBA(this),
"NO$GBA" => new NoCashGBA(this),
"retroarch" => new Retroarch(this),
"EmuHawk" => new EmuHawk(this),
"mednafen" => new Mednafen(this),
"GSR" or "GSE" => new GSE(this),
_ => throw new NotImplementedException(),
};
}
internal override bool IsAddressInBounds<T>(ulong address)
{
return (address >> 24) switch
{
2 => address + (ulong)Marshal.SizeOf<T>() <= 0x02040000,
3 => address + (ulong)Marshal.SizeOf<T>() <= 0x03008000,
_ => false,
};
}
internal override bool IsStringAddressInBounds(ulong address, int stringLength)
{
return (address >> 24) switch
{
2 => address + (ulong)stringLength <= 0x02040000,
3 => address + (ulong)stringLength <= 0x03008000,
_ => false,
};
}
public override bool TryGetAddress(ulong address, out IntPtr realAddress)
{
realAddress = (address >> 24) switch
{
2 => Emu.GetMemoryAddress(0) != null && address < 0x02040000 ? (IntPtr)((ulong)Emu.GetMemoryAddress(0) + (address - 0x02000000)) : default,
3 => Emu.GetMemoryAddress(1) != null && address < 0x03008000 ? (IntPtr)((ulong)Emu.GetMemoryAddress(1) + (address - 0x03000000)) : default,
_ => default,
};
return realAddress != default;
}
}