Advertisement
crackanddie

FixedPtr

Dec 18th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. [StructLayout(LayoutKind.Explicit, Size = 4)]
  2. public struct FixedPtr
  3. {
  4.     [FieldOffset(0)]
  5.     public int Value;
  6.  
  7.     private FixedPtr(int value)
  8.     {
  9.         Value = value;
  10.     }
  11.  
  12.     public readonly unsafe T Read<T>() where T : unmanaged
  13.     {
  14.         fixed (byte* pointerToFirst = Program.Memory)
  15.         {
  16.             return *(T*)(pointerToFirst + Value);
  17.         }
  18.     }
  19.  
  20.     public readonly unsafe void Write<T>(T value) where T : unmanaged
  21.     {
  22.         fixed (byte* pointerToFirst = Program.Memory)
  23.         {
  24.             *(T*)(pointerToFirst + Value) = value;
  25.         }
  26.     }
  27.  
  28.     public static FixedPtr GetPtrTo(int value)
  29.     {
  30.         return new FixedPtr(value);
  31.     }
  32. }
Tags: PTR fixedptr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement