diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs index df72ce2..3db425a 100644 --- a/RageCoop.Client/Networking/Receive.cs +++ b/RageCoop.Client/Networking/Receive.cs @@ -49,6 +49,7 @@ namespace RageCoop.Client #endif break; case NetConnectionStatus.Connected: + Memory.ApplyPatches(); Main.QueueAction(() => { CoopMenu.ConnectedMenuSetting(); @@ -60,6 +61,7 @@ namespace RageCoop.Client Main.Logger.Info(">> Connected <<"); break; case NetConnectionStatus.Disconnected: + Memory.RestorePatches(); DownloadManager.Cleanup(); // Reset all values diff --git a/RageCoop.Client/Util/Memory.cs b/RageCoop.Client/Util/Memory.cs index 2e648c4..5e52126 100644 --- a/RageCoop.Client/Util/Memory.cs +++ b/RageCoop.Client/Util/Memory.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,13 +8,73 @@ using GTA.Math; using GTA; using SHVDN; using RageCoop.Core; +using System.Runtime.InteropServices; namespace RageCoop.Client { - internal static class Memory + internal unsafe class MemPatch{ + private byte[] _data; + private byte[] _orginal; + private IntPtr _address; + public MemPatch(byte* address, byte[] data) + { + _data = data; + _orginal = new byte[data.Length]; + _address = (IntPtr)address; + Marshal.Copy((IntPtr)address, _orginal, 0, data.Length); + } + public void Install() + { + Marshal.Copy(_data, 0, _address, _data.Length); + } + public void Uninstall() + { + Marshal.Copy(_orginal, 0, _address, _orginal.Length); + } + } + +internal static unsafe class Memory { + public static MemPatch VignettingPatch; + public static MemPatch VignettingCallPatch; + public static MemPatch TimeScalePatch; + static Memory() + { + + + // Weapon/radio wheel slow-mo patch + // Thanks @CamxxCore, https://github.com/CamxxCore/GTAVWeaponWheelMod + var result = NativeMemory.FindPattern("\x38\x51\x64\x74\x19", "xxxxx"); + if(result == null) { throw new NotSupportedException("Can't find memory pattern to patch weapon/radio slow-mo"); } + var address = result+26; + address = address + *(int*)address + 4u; + VignettingPatch=new MemPatch(address, new byte[] { RET, 0x90, 0x90, 0x90, 0x90 }); + VignettingCallPatch=new MemPatch(result+8, new byte[]{ 0x90, 0x90, 0x90, 0x90, 0x90}); + TimeScalePatch=new MemPatch(result+34, new byte[] { XOR_32_64, 0xD2 }); + + } + public static void ApplyPatches() + { + VignettingPatch.Install(); + VignettingCallPatch.Install(); + TimeScalePatch.Install(); + } + public static void RestorePatches() + { + VignettingPatch.Uninstall(); + VignettingCallPatch.Uninstall(); + TimeScalePatch.Uninstall(); + } + #region PATCHES + #endregion #region OFFSET-CONST public const int PositionOffset = 144; + #endregion + #region OPCODE + + const byte XOR_32_64 = 0x31; + const byte RET = 0xC3; + #endregion public static Vector3 ReadPosition(this Entity e) { @@ -27,7 +88,7 @@ namespace RageCoop.Client { return e.ReadQuaternion().ToEulerDegrees(); } - public unsafe static Vector3 ReadVector3(IntPtr address) + public static Vector3 ReadVector3(IntPtr address) { float* ptr = (float*)address.ToPointer(); return new Vector3()