/// <summary> /// Initializes a new instance of the <see cref="ADetour" /> class. /// </summary> /// <param name="target">The target delegate.</param> /// <param name="hook">The hook delegate.</param> /// <param name="identifier"></param> /// <param name="memory">The <see cref="MemoryPlus" /> instance.</param> /// <param name="ignoreRules"></param> public ADetour(Delegate target, Delegate hook, string identifier, IAMemory memory, bool ignoreRules = false) { ProcessMemory = memory; Identifier = identifier; IgnoreRules = ignoreRules; TargetDelegate = target; Target = target.ToFunctionPtr(); _hookDelegate = hook; HookPointer = hook.ToFunctionPtr(); //target //Store the original bytes Original = new List <byte>(); Original.AddRange(memory.Read(Target, 6)); //Setup the detour bytes New = new List <byte> { 0x68 }; var bytes = IntPtr.Size == 4 ? BitConverter.GetBytes(HookPointer.ToInt32()) : BitConverter.GetBytes(HookPointer.ToInt64()); New.AddRange(bytes); New.Add(0xC3); }
private unsafe static byte[] Read1Bpp(IAMemory Memory, TextureInfo Texture) { int Width = Texture.Width; int Height = Texture.Height; byte[] Output = new byte[Width * Height]; ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, 1, 1); (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition( Memory, Texture.Position); fixed(byte *BuffPtr = Output) { long OutOffs = 0; for (int Y = 0; Y < Height; Y++) { for (int X = 0; X < Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); byte Pixel = CpuMem.ReadByteUnchecked(Position + Offset); *(BuffPtr + OutOffs) = Pixel; OutOffs++; } } } return(Output); }
public unsafe static void Write(IAMemory Memory, TextureInfo Texture, byte[] Data) { ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, 1, 4); (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition( Memory, Texture.Position); fixed(byte *BuffPtr = Data) { long InOffs = 0; for (int Y = 0; Y < Texture.Height; Y++) { for (int X = 0; X < Texture.Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); int Pixel = *(int *)(BuffPtr + InOffs); CpuMem.WriteInt32(Position + Offset, Pixel); InOffs += 4; } } } }
public static byte[] Read(IAMemory Memory, Texture Texture) { switch (Texture.Format) { case GalTextureFormat.R32G32B32A32: return(Read16Bpp(Memory, Texture)); case GalTextureFormat.R16G16B16A16: return(Read8Bpp(Memory, Texture)); case GalTextureFormat.A8B8G8R8: return(Read4Bpp(Memory, Texture)); case GalTextureFormat.R32: return(Read4Bpp(Memory, Texture)); case GalTextureFormat.A1B5G5R5: return(Read5551(Memory, Texture)); case GalTextureFormat.B5G6R5: return(Read565(Memory, Texture)); case GalTextureFormat.G8R8: return(Read2Bpp(Memory, Texture)); case GalTextureFormat.R8: return(Read1Bpp(Memory, Texture)); case GalTextureFormat.BC1: return(Read8Bpt4x4(Memory, Texture)); case GalTextureFormat.BC2: return(Read16Bpt4x4(Memory, Texture)); case GalTextureFormat.BC3: return(Read16Bpt4x4(Memory, Texture)); case GalTextureFormat.BC4: return(Read8Bpt4x4(Memory, Texture)); case GalTextureFormat.BC5: return(Read16Bpt4x4(Memory, Texture)); case GalTextureFormat.Astc2D4x4: return(Read16Bpt4x4(Memory, Texture)); } throw new NotImplementedException(Texture.Format.ToString()); }
private unsafe static byte[] Read8Bpt4x4(IAMemory Memory, TextureInfo Texture) { int Width = (Texture.Width + 3) / 4; int Height = (Texture.Height + 3) / 4; byte[] Output = new byte[Width * Height * 8]; ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, 4, 8); (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition( Memory, Texture.Position); fixed(byte *BuffPtr = Output) { long OutOffs = 0; for (int Y = 0; Y < Height; Y++) { for (int X = 0; X < Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); long Tile = CpuMem.ReadInt64Unchecked(Position + Offset); *(long *)(BuffPtr + OutOffs) = Tile; OutOffs += 8; } } } return(Output); }
private unsafe static void Write4Bpp( IAMemory Memory, Texture Texture, byte[] Data, int Width, int Height) { ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 4); (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition( Memory, Texture.Position); fixed(byte *BuffPtr = Data) { long InOffs = 0; for (int Y = 0; Y < Height; Y++) { for (int X = 0; X < Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); int Pixel = *(int *)(BuffPtr + InOffs); CpuMem.WriteInt32Unchecked(Position + Offset, Pixel); InOffs += 4; } } } }
public static void Write(IAMemory Memory, Texture Texture, byte[] Data) { switch (Texture.Format) { case GalTextureFormat.A8B8G8R8: Write4Bpp(Memory, Texture, Data); break; default: throw new NotImplementedException(Texture.Format.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="APatch" /> class. /// </summary> /// <param name="address">The address where the patch is located in Memory.</param> /// <param name="patchWith">The bytes to be written.</param> /// <param name="identifier"></param> /// <param name="processPlus"></param> /// <param name="ignoreRules"></param> public APatch(IntPtr address, byte[] patchWith, string identifier, IAMemory processPlus, bool ignoreRules = false) { Identifier = identifier; ProcessPlus = processPlus; Address = address; PatchBytes = patchWith; OriginalBytes = processPlus.Read(address, patchWith.Length); IgnoreRules = ignoreRules; }
public static (AMemory Memory, long Position) GetMemoryAndPosition( IAMemory Memory, long Position) { if (Memory is NvGpuVmm Vmm) { return(Vmm.Memory, Vmm.GetPhysicalAddress(Position)); } return((AMemory)Memory, Position); }
public static byte[] ReadTexture(IAMemory Memory, GalImage Image, long Position) { AMemory CpuMemory; if (Memory is NvGpuVmm Vmm) { CpuMemory = Vmm.Memory; } else { CpuMemory = (AMemory)Memory; } ISwizzle Swizzle = TextureHelper.GetSwizzle(Image); ImageDescriptor Desc = GetImageDescriptor(Image.Format); (int Width, int Height) = GetImageSizeInBlocks(Image); int BytesPerPixel = Desc.BytesPerPixel; //Note: Each row of the texture needs to be aligned to 4 bytes. int Pitch = (Width * BytesPerPixel + 3) & ~3; byte[] Data = new byte[Height * Pitch]; for (int Y = 0; Y < Height; Y++) { int OutOffs = Y * Pitch; for (int X = 0; X < Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); CpuMemory.ReadBytes(Position + Offset, Data, OutOffs, BytesPerPixel); OutOffs += BytesPerPixel; } } return(Data); }
private unsafe static byte[] Read5551(IAMemory Memory, TextureInfo Texture) { int Width = Texture.Width; int Height = Texture.Height; byte[] Output = new byte[Width * Height * 2]; ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, 1, 2); (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition( Memory, Texture.Position); fixed(byte *BuffPtr = Output) { long OutOffs = 0; for (int Y = 0; Y < Height; Y++) { for (int X = 0; X < Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); uint Pixel = (uint)CpuMem.ReadInt16Unchecked(Position + Offset); Pixel = (Pixel & 0x001f) << 11 | (Pixel & 0x03e0) << 1 | (Pixel & 0x7c00) >> 9 | (Pixel & 0x8000) >> 15; *(short *)(BuffPtr + OutOffs) = (short)Pixel; OutOffs += 2; } } } return(Output); }
public static byte[] ReadTexture(IAMemory Memory, GalImage Image, long Position) { AMemory CpuMemory; if (Memory is NvGpuVmm Vmm) { CpuMemory = Vmm.Memory; } else { CpuMemory = (AMemory)Memory; } ISwizzle Swizzle = TextureHelper.GetSwizzle(Image); ImageDescriptor Desc = GetImageDescriptor(Image.Format); (int Width, int Height) = GetImageSizeInBlocks(Image); int BytesPerPixel = Desc.BytesPerPixel; int OutOffs = 0; byte[] Data = new byte[Width * Height * BytesPerPixel]; for (int Y = 0; Y < Height; Y++) { for (int X = 0; X < Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); CpuMemory.ReadBytes(Position + Offset, Data, OutOffs, BytesPerPixel); OutOffs += BytesPerPixel; } } return(Data); }
public static byte[] Read(IAMemory Memory, Texture Texture) { switch (Texture.Format) { case GalTextureFormat.A8B8G8R8: return(Read4Bpp(Memory, Texture)); case GalTextureFormat.A1B5G5R5: return(Read2Bpp(Memory, Texture)); case GalTextureFormat.B5G6R5: return(Read2Bpp(Memory, Texture)); case GalTextureFormat.BC1: return(Read8Bpt4x4(Memory, Texture)); case GalTextureFormat.BC2: return(Read16Bpt4x4(Memory, Texture)); case GalTextureFormat.BC3: return(Read16Bpt4x4(Memory, Texture)); case GalTextureFormat.BC4: return(Read8Bpt4x4(Memory, Texture)); case GalTextureFormat.BC5: return(Read16Bpt4x4(Memory, Texture)); } throw new NotImplementedException(Texture.Format.ToString()); }
private unsafe static byte[] Read16BptCompressedTexture(IAMemory Memory, TextureInfo Texture, int BlockWidth, int BlockHeight) { int Width = (Texture.Width + (BlockWidth - 1)) / BlockWidth; int Height = (Texture.Height + (BlockHeight - 1)) / BlockHeight; byte[] Output = new byte[Width * Height * 16]; ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, BlockWidth, 16); (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition( Memory, Texture.Position); fixed(byte *BuffPtr = Output) { long OutOffs = 0; for (int Y = 0; Y < Height; Y++) { for (int X = 0; X < Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); long Tile0 = CpuMem.ReadInt64Unchecked(Position + Offset + 0); long Tile1 = CpuMem.ReadInt64Unchecked(Position + Offset + 8); *(long *)(BuffPtr + OutOffs + 0) = Tile0; *(long *)(BuffPtr + OutOffs + 8) = Tile1; OutOffs += 16; } } } return(Output); }
private unsafe static byte[] Read16Bpp(IAMemory Memory, TextureInfo Texture) { int Width = Texture.Width; int Height = Texture.Height; byte[] Output = new byte[Width * Height * 16]; ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, 1, 16); (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition( Memory, Texture.Position); fixed(byte *BuffPtr = Output) { long OutOffs = 0; for (int Y = 0; Y < Height; Y++) { for (int X = 0; X < Width; X++) { long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y); long PxLow = CpuMem.ReadInt64Unchecked(Position + Offset + 0); long PxHigh = CpuMem.ReadInt64Unchecked(Position + Offset + 8); *(long *)(BuffPtr + OutOffs + 0) = PxLow; *(long *)(BuffPtr + OutOffs + 8) = PxHigh; OutOffs += 16; } } } return(Output); }
public void OnSceneGUI() { IAMemory memory = ((IAMemory)target); memory.DrawMemoryEditor(); }
public static byte[] Read(IAMemory Memory, TextureInfo Texture) { switch (Texture.Format) { case GalTextureFormat.R32G32B32A32: return(Read16Bpp(Memory, Texture)); case GalTextureFormat.R16G16B16A16: return(Read8Bpp(Memory, Texture)); case GalTextureFormat.A8B8G8R8: return(Read4Bpp(Memory, Texture)); case GalTextureFormat.R32: return(Read4Bpp(Memory, Texture)); case GalTextureFormat.BF10GF11RF11: return(Read4Bpp(Memory, Texture)); case GalTextureFormat.Z24S8: return(Read4Bpp(Memory, Texture)); case GalTextureFormat.A1B5G5R5: return(Read5551(Memory, Texture)); case GalTextureFormat.B5G6R5: return(Read565(Memory, Texture)); case GalTextureFormat.G8R8: return(Read2Bpp(Memory, Texture)); case GalTextureFormat.R16: return(Read2Bpp(Memory, Texture)); case GalTextureFormat.R8: return(Read1Bpp(Memory, Texture)); case GalTextureFormat.BC6H_SF16: return(Read16BptCompressedTexture(Memory, Texture, 4, 4)); case GalTextureFormat.BC6H_UF16: return(Read16BptCompressedTexture(Memory, Texture, 4, 4)); case GalTextureFormat.BC7U: return(Read16BptCompressedTexture(Memory, Texture, 4, 4)); case GalTextureFormat.BC1: return(Read8Bpt4x4(Memory, Texture)); case GalTextureFormat.BC2: return(Read16BptCompressedTexture(Memory, Texture, 4, 4)); case GalTextureFormat.BC3: return(Read16BptCompressedTexture(Memory, Texture, 4, 4)); case GalTextureFormat.BC4: return(Read8Bpt4x4(Memory, Texture)); case GalTextureFormat.BC5: return(Read16BptCompressedTexture(Memory, Texture, 4, 4)); case GalTextureFormat.ZF32: return(Read4Bpp(Memory, Texture)); case GalTextureFormat.Astc2D4x4: return(Read16BptCompressedTexture(Memory, Texture, 4, 4)); case GalTextureFormat.Astc2D5x5: return(Read16BptCompressedTexture(Memory, Texture, 5, 5)); case GalTextureFormat.Astc2D6x6: return(Read16BptCompressedTexture(Memory, Texture, 6, 6)); case GalTextureFormat.Astc2D8x8: return(Read16BptCompressedTexture(Memory, Texture, 8, 8)); case GalTextureFormat.Astc2D10x10: return(Read16BptCompressedTexture(Memory, Texture, 10, 10)); case GalTextureFormat.Astc2D12x12: return(Read16BptCompressedTexture(Memory, Texture, 12, 12)); case GalTextureFormat.Astc2D5x4: return(Read16BptCompressedTexture(Memory, Texture, 5, 4)); case GalTextureFormat.Astc2D6x5: return(Read16BptCompressedTexture(Memory, Texture, 6, 5)); case GalTextureFormat.Astc2D8x6: return(Read16BptCompressedTexture(Memory, Texture, 8, 6)); case GalTextureFormat.Astc2D10x8: return(Read16BptCompressedTexture(Memory, Texture, 10, 8)); case GalTextureFormat.Astc2D12x10: return(Read16BptCompressedTexture(Memory, Texture, 12, 10)); case GalTextureFormat.Astc2D8x5: return(Read16BptCompressedTexture(Memory, Texture, 8, 5)); case GalTextureFormat.Astc2D10x5: return(Read16BptCompressedTexture(Memory, Texture, 10, 5)); case GalTextureFormat.Astc2D10x6: return(Read16BptCompressedTexture(Memory, Texture, 10, 6)); } throw new NotImplementedException(Texture.Format.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="APatchManager" /> class. /// </summary> /// <param name="processMemory">The process memory.</param> public APatchManager(IAMemory processMemory) { MemoryBase = processMemory; }
/// <summary> /// Initializes a new instance of the <see cref="ADetourManager" /> class. /// </summary> public ADetourManager(IAMemory processPlus) { ProcessPlus = processPlus; }