Exemplo n.º 1
0
        public static EquipmentItem[] ReadItems()
        {
            var dataLength = MaxItems * BlockLength;
            var dataBytes  = GameMemory.Read <byte>(Offset, dataLength, false);

            var readItems = new EquipmentItem[MaxItems];

            for (int i = 0; i < MaxItems; i++)
            {
                IntPtr ptrEquipmentData = Marshal.AllocHGlobal(dataLength);
                Marshal.Copy(dataBytes, i * BlockLength, ptrEquipmentData, BlockLength);
                readItems[i] = (EquipmentItem)Marshal.PtrToStructure(ptrEquipmentData, typeof(EquipmentItem));
                Marshal.FreeHGlobal(ptrEquipmentData);
            }

            return(readItems);
        }
Exemplo n.º 2
0
        public static void WriteItem(int itemIndex, EquipmentItem item)
        {
            // Convert data struct to byte array
            var size = Marshal.SizeOf(item);

            var    itemBytes    = new byte[size];
            IntPtr ptrByteArray = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(item, ptrByteArray, true);
            Marshal.Copy(ptrByteArray, itemBytes, 0, size);
            Marshal.FreeHGlobal(ptrByteArray);

            // Write to game's memory
            var offset = Offset + itemIndex * BlockLength;

            GameMemory.Write(offset, itemBytes, false);
        }