Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [StructLayout(LayoutKind.Explicit, Size = 4)]
- public struct FixedPtr
- {
- [FieldOffset(0)]
- public int Value;
- private FixedPtr(int value)
- {
- Value = value;
- }
- public readonly unsafe T Read<T>() where T : unmanaged
- {
- fixed (byte* pointerToFirst = Program.Memory)
- {
- return *(T*)(pointerToFirst + Value);
- }
- }
- public readonly unsafe void Write<T>(T value) where T : unmanaged
- {
- fixed (byte* pointerToFirst = Program.Memory)
- {
- *(T*)(pointerToFirst + Value) = value;
- }
- }
- public static FixedPtr GetPtrTo(int value)
- {
- return new FixedPtr(value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement