Skip to content

Commit

Permalink
FIX THE MEMORY LEAK AT LONG LAST
Browse files Browse the repository at this point in the history
we love process handles we love process handles
  • Loading branch information
jxjacob committed Oct 22, 2023
1 parent f0fe233 commit 30bcbc4
Show file tree
Hide file tree
Showing 15 changed files with 597 additions and 239 deletions.
31 changes: 13 additions & 18 deletions GSTHD/AttachToEmulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static Tuple<Process, uint> attachToProject64(Form1 baseForm, bool doOffs
if (gameInfo.Item2 == 8)
{
uint addr = Memory.Int8AddrFix(gameInfo.Item1);
if (Memory.ReadInt8(target, potOff + addr) == gameInfo.Item3)
if (Memory.ReadInt8(target.Handle, potOff + addr) == gameInfo.Item3)
{
Debug.WriteLine(potOff.ToString("X"));
romAddrStart = potOff;
Expand All @@ -67,7 +67,7 @@ public static Tuple<Process, uint> attachToProject64(Form1 baseForm, bool doOffs
else if (gameInfo.Item2 == 16)
{
uint addr = Memory.Int16AddrFix(gameInfo.Item1);
if (Memory.ReadInt16(target, potOff + addr) == gameInfo.Item3)
if (Memory.ReadInt16(target.Handle, potOff + addr) == gameInfo.Item3)
{
Debug.WriteLine(potOff.ToString("X"));
romAddrStart = potOff;
Expand All @@ -76,7 +76,7 @@ public static Tuple<Process, uint> attachToProject64(Form1 baseForm, bool doOffs
}
else if (gameInfo.Item2 == 32)
{
if (Memory.ReadInt32(target, potOff + gameInfo.Item1) == gameInfo.Item3)
if (Memory.ReadInt32(target.Handle, potOff + gameInfo.Item1) == gameInfo.Item3)
{
Debug.WriteLine(potOff.ToString("X"));
romAddrStart = potOff;
Expand All @@ -93,11 +93,6 @@ public static Tuple<Process, uint> attachToProject64(Form1 baseForm, bool doOffs
return Tuple.Create(target, romAddrStart);
}

//for (int i = 0; i < 4; i++)
//{
// switch (i)
// {

for (uint potOff = 0xDFD00000; potOff < 0xE01FFFFF; potOff += 16)
{

Expand All @@ -123,16 +118,16 @@ public static Tuple<Process, uint> attachToProject64(Form1 baseForm, bool doOffs
if (gameInfo.Item2 == 8)
{
uint addr = Memory.Int8AddrFix(gameInfo.Item1);
gamecheck = Memory.ReadInt8(target, romAddrStart + addr);
gamecheck = Memory.ReadInt8(target.Handle, romAddrStart + addr);
}
else if (gameInfo.Item2 == 16)
{
uint addr = Memory.Int16AddrFix(gameInfo.Item1);
gamecheck = Memory.ReadInt16(target, romAddrStart + addr);
gamecheck = Memory.ReadInt16(target.Handle, romAddrStart + addr);
}
else if (gameInfo.Item2 == 32)
{
gamecheck = Memory.ReadInt32(target, romAddrStart + gameInfo.Item1);
gamecheck = Memory.ReadInt32(target.Handle, romAddrStart + gameInfo.Item1);
}
else
{
Expand Down Expand Up @@ -227,16 +222,16 @@ public static Tuple<Process, uint> attachToBizhawk(Form1 baseForm)
if (gameInfo.Item2 == 8)
{
uint addr = Memory.Int8AddrFix(gameInfo.Item1);
gamecheck = Memory.ReadInt8(target, romAddrStart + addr);
gamecheck = Memory.ReadInt8(target.Handle, romAddrStart + addr);
}
else if (gameInfo.Item2 == 16)
{
uint addr = Memory.Int16AddrFix(gameInfo.Item1);
gamecheck = Memory.ReadInt16(target, romAddrStart + addr);
gamecheck = Memory.ReadInt16(target.Handle, romAddrStart + addr);
}
else if (gameInfo.Item2 == 32)
{
gamecheck = Memory.ReadInt32(target, (uint)(addressDLL + romAddrStart + gameInfo.Item1));
gamecheck = Memory.ReadInt32(target.Handle, (uint)(addressDLL + romAddrStart + gameInfo.Item1));
}
else
{
Expand Down Expand Up @@ -309,12 +304,12 @@ public static Tuple<Process, ulong> attachToRMG(Form1 baseForm)


// read the address to find the address of the starting point in the rom
ulong readAddress = Memory.ReadInt64(target, (romAddrStart));
ulong readAddress = Memory.ReadInt64(target.Handle, (romAddrStart));

if (gameInfo.Item2 == 8)
{
var addr = Memory.Int8AddrFix(readAddress + 0x80000000 + gameInfo.Item1);
var wherethefuck = Memory.ReadInt8(target, addr);
var wherethefuck = Memory.ReadInt8(target.Handle, addr);
if ((wherethefuck & 0xff) == gameInfo.Item3)
{
return Tuple.Create(target, (readAddress + 0x80000000));
Expand All @@ -324,7 +319,7 @@ public static Tuple<Process, ulong> attachToRMG(Form1 baseForm)
else if (gameInfo.Item2 == 16)
{
var addr = Memory.Int16AddrFix(readAddress + 0x80000000 + gameInfo.Item1);
var wherethefuck = Memory.ReadInt16(target, addr);
var wherethefuck = Memory.ReadInt16(target.Handle, addr);
if ((wherethefuck & 0xffff) == gameInfo.Item3)
{
return Tuple.Create(target, (readAddress + 0x80000000));
Expand All @@ -334,7 +329,7 @@ public static Tuple<Process, ulong> attachToRMG(Form1 baseForm)
else if (gameInfo.Item2 == 32)
{
// use this previously read address to find the game verification data
var wherethefuck = Memory.ReadInt32(target, (readAddress + 0x80000000 + gameInfo.Item1));
var wherethefuck = Memory.ReadInt32(target.Handle, (readAddress + 0x80000000 + gameInfo.Item1));
if ((wherethefuck & 0xffffffff) == gameInfo.Item3)
{
return Tuple.Create(target, (readAddress + 0x80000000));
Expand Down
Loading

0 comments on commit 30bcbc4

Please sign in to comment.