Skip to content

Commit

Permalink
Hotfix 4.9.5 - sekiro hot reload fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Meowmaritus committed Oct 7, 2023
1 parent 67c1bc0 commit 695353f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 20 deletions.
52 changes: 34 additions & 18 deletions DSAnimStudioNETCore/LiveRefresh/Memory.cs
Expand Up @@ -396,37 +396,53 @@ public static void ExecuteFunction(byte[] array)
}
}

public static void ExecuteBufferFunction(byte[] array, byte[] argument)
public static void ExecuteBufferFunction(byte[] array, byte[] argument, int argLocationInAsmArray = 0x2)
{
var Size1 = 0x100;
var Size2 = 0x100;

var address = Kernel32.VirtualAllocEx(ProcessHandle, IntPtr.Zero, Size1, 0x1000 | 0x2000, 0X40);
var bufferAddress = Kernel32.VirtualAllocEx(ProcessHandle, IntPtr.Zero, Size2, 0x1000 | 0x2000, 0X40);
var address = Kernel32.VirtualAllocEx(ProcessHandle, IntPtr.Zero, Size1, 0x1000 | 0x2000, 0x40);
var bufferAddress = Kernel32.VirtualAllocEx(ProcessHandle, IntPtr.Zero, Size2, 0x1000 | 0x2000, 0x40);

var bytjmp = 0x2;
var bytjmpAr = new byte[7];
try
{
//var bytjmp = 0x2;
var bytjmpAr = new byte[8];

WriteBytes(bufferAddress, argument);
WriteBytes(bufferAddress, argument);

bytjmpAr = BitConverter.GetBytes((long)bufferAddress);
Array.Copy(bytjmpAr, 0, array, bytjmp, bytjmpAr.Length);
bytjmpAr = BitConverter.GetBytes((long)bufferAddress);
Array.Copy(bytjmpAr, 0, array, argLocationInAsmArray, bytjmpAr.Length);

if (address != IntPtr.Zero)
{
if (WriteBytes(address, array))
if (address != IntPtr.Zero && bufferAddress != IntPtr.Zero)
{

var threadHandle = Kernel32.CreateRemoteThread(ProcessHandle, IntPtr.Zero, 0, address, IntPtr.Zero, 0, out var threadId);
if (threadHandle != IntPtr.Zero)
if (WriteBytes(address, array))
{
Kernel32.WaitForSingleObject(threadHandle, 30000);

var threadHandle = Kernel32.CreateRemoteThread(ProcessHandle, IntPtr.Zero, 0, address, IntPtr.Zero, 0, out var threadId);
if (threadHandle != IntPtr.Zero)
{
Kernel32.WaitForSingleObject(threadHandle, 30000);
}

}

Kernel32.VirtualFreeEx(ProcessHandle, address, Size1, 2);
Kernel32.VirtualFreeEx(ProcessHandle, bufferAddress, Size2, 2);
}
Kernel32.VirtualFreeEx(ProcessHandle, address, Size1, 2);
Kernel32.VirtualFreeEx(ProcessHandle, bufferAddress, Size2, 2);
}
finally
{
if (address != IntPtr.Zero)
{
Kernel32.VirtualFreeEx(ProcessHandle, address, Size1, 2);
}
if (bufferAddress != IntPtr.Zero)
{
Kernel32.VirtualFreeEx(ProcessHandle, bufferAddress, Size2, 2);
}
}


}
}
}
48 changes: 47 additions & 1 deletion DSAnimStudioNETCore/LiveRefresh/RequestFileReload.cs
Expand Up @@ -21,6 +21,7 @@ public static bool CanReloadEntity(string entityName)
case SoulsAssetPipeline.SoulsGames.DS1R:
case SoulsAssetPipeline.SoulsGames.DS3:
case SoulsAssetPipeline.SoulsGames.ER:
case SoulsAssetPipeline.SoulsGames.SDT:
return true;
}
}
Expand Down Expand Up @@ -104,7 +105,52 @@ private static bool RequestReloadChr(string chrName)
{
byte[] chrNameBytes = Encoding.Unicode.GetBytes(chrName);

if (GameRoot.GameType == SoulsAssetPipeline.SoulsGames.DS3)
if (GameRoot.GameType is SoulsAssetPipeline.SoulsGames.SDT)
{
try
{
Memory.AttachProc("sekiro");

if (Memory.ProcessHandle != IntPtr.Zero)
{

Memory.WriteBoolean(Memory.BaseAddress + 0x3D7A34F, true);

var buffer = new byte[] {
0x48, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //mov rcx,0000000000000000 (read value at 143D7A1E0 and put it here)
0x48, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //mov rdx,0000000000000000 (address of chr name string)
0x48, 0x83, 0xEC, 0x28, // sub rsp,28
0xFF, 0x15, 0x02, 0x00, 0x00, 0x00, 0xEB, 0x08, 0x60, 0xAC, 0xA4, 0x40, 0x01, 0x00, 0x00, 0x00, //call 140A4AC60
0x48, 0x83, 0xC4, 0x28, // add rsp,28
0xC3, // ret
};

var ptrThingVal = Memory.ReadInt64((IntPtr)0x143D7A1E0);
var ptrThingVal_AsBytes = BitConverter.GetBytes((long)ptrThingVal);
Array.Copy(ptrThingVal_AsBytes, 0, buffer, 0x2, ptrThingVal_AsBytes.Length);

Memory.ExecuteBufferFunction(buffer, chrNameBytes, argLocationInAsmArray: 0xC);

return true;
}
else
{
ShowInjectionFailed();
}


}
catch
{
ShowInjectionFailed();
}
finally
{
//Memory.CloseHandle();
}
}

else if (GameRoot.GameType == SoulsAssetPipeline.SoulsGames.DS3)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion DSAnimStudioNETCore/Main.cs
Expand Up @@ -24,7 +24,7 @@ namespace DSAnimStudio
/// </summary>
public class Main : Game
{
public const string VERSION = "4.9.4 [PUBLIC]";
public const string VERSION = "4.9.5 [PUBLIC]";

public static void GCCollect()
{
Expand Down

0 comments on commit 695353f

Please sign in to comment.