Beispiel #1
0
        public Room(ushort[] Room_Buffer, int Floor)
        {
            bool Includes_Wall     = Room_Buffer[1] == 0xFFFE;
            int  Data_Start_Offset = Includes_Wall ? 16 : 1; //Data with wall looks like this: 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, ..., 0xFFFE, 0xITEM_ID

            Room_Size = HouseData.ReadHouseSize(Room_Buffer, Includes_Wall);
            for (int i = 0; i < 4; i++) //4 layers per room
            {
                ushort[] Layer_Buffer = new ushort[0x114];
                Buffer.BlockCopy(Room_Buffer, i * 0x228, Layer_Buffer, 0, 0x228);
                Layers[i] = new Layer(Layer_Buffer, Room_Size, Floor, i, true);
            }
            Carpet    = new Item((ushort)((0x26 << 8) + (Room_Buffer[0x450] & 0xFF00) >> 8));
            Wallpaper = new Item((ushort)((0x27 << 8) + Room_Buffer[0x450] & 0x00FF));
            Unknown_1 = (byte)((Room_Buffer[0x451] & 0xFF00) >> 4);
            Unknown_2 = (byte)(Room_Buffer[0x451] & 0x00FF);
        }
Beispiel #2
0
        public House(int index, int offset)
        {
            Index  = index;
            Offset = offset;

            var houseSize = HouseInfo.GetHouseSize(offset, MainForm.SaveFile.SaveType);
            var basement  = false;

            //Console.WriteLine("House Index: " + Index);
            //Console.WriteLine("House Offset: 0x" + Offset.ToString("X"));
            //Console.WriteLine("House Size: " + HouseSize.ToString());
            if (MainForm.SaveFile.SaveGeneration == SaveGeneration.N64 || MainForm.SaveFile.SaveGeneration == SaveGeneration.GCN)
            {
                basement = HouseInfo.HasBasement(offset, MainForm.SaveFile.SaveType);
                //Console.WriteLine("Basement: " + Basement.ToString());
            }

            // Load House Data
            var    offsets            = HouseInfo.GetHouseOffsets(MainForm.SaveFile.SaveType);
            var    saveData           = MainForm.SaveFile;
            var    playerDataType     = typeof(HouseData);
            var    playerSaveInfoType = typeof(HouseOffsets);
            object boxedData          = new HouseData();

            foreach (var field in playerSaveInfoType.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                if (field.GetValue(offsets) == null || field.Name.Contains("Count") ||
                    field.Name.Contains("Size"))
                {
                    continue;
                }
                if (playerDataType.GetField(field.Name) == null)
                {
                    continue;
                }
                if (field.FieldType != typeof(int) || (int)field.GetValue(offsets) == -1)
                {
                    continue;
                }
                var currentField = playerDataType.GetField(field.Name);
                var fieldType    = currentField.FieldType;
                var dataOffset   = offset + (int)field.GetValue(offsets);

                if (field.Name.Equals("Room_Carpet") || field.Name.Equals("Room_Wallpaper") ||
                    field.Name.Equals("Room_Song"))
                {
                    continue;
                }
                if (fieldType == typeof(byte))
                {
                    currentField.SetValue(boxedData, saveData.ReadByte(dataOffset));
                }
                else if (fieldType == typeof(byte[]) && playerSaveInfoType.GetField(field.Name + "Count") != null)
                {
                    currentField.SetValue(boxedData, saveData.ReadByteArray(dataOffset,
                                                                            (int)playerSaveInfoType.GetField(field.Name + "Count").GetValue(offsets)));
                }
                else if (fieldType == typeof(ushort))
                {
                    currentField.SetValue(boxedData, saveData.ReadUInt16(dataOffset, saveData.IsBigEndian));
                }
                else if (fieldType == typeof(ushort[]))
                {
                    currentField.SetValue(boxedData, saveData.ReadUInt16Array(dataOffset,
                                                                              (int)playerSaveInfoType.GetField(field.Name + "Count").GetValue(offsets), saveData.IsBigEndian));
                }
                else if (fieldType == typeof(uint))
                {
                    currentField.SetValue(boxedData, saveData.ReadUInt32(dataOffset, saveData.IsBigEndian));
                }
                else if (fieldType == typeof(string))
                {
                    currentField.SetValue(boxedData, new AcString(saveData.ReadByteArray(dataOffset,
                                                                                         (int)playerSaveInfoType.GetField(field.Name + "Size").GetValue(offsets)), saveData.SaveType).Trim());
                }
                else if (fieldType == typeof(Item))
                {
                    if (saveData.SaveGeneration == SaveGeneration.N3DS)
                    {
                        currentField.SetValue(boxedData, new Item(saveData.ReadUInt32(dataOffset, false)));
                    }
                    else
                    {
                        currentField.SetValue(boxedData, new Item(saveData.ReadUInt16(dataOffset, saveData.IsBigEndian)));
                    }
                }
                else if (fieldType == typeof(NewLeafInt32))
                {
                    var intData = saveData.ReadUInt32Array(dataOffset, 2);
                    currentField.SetValue(boxedData, new NewLeafInt32(intData[0], intData[1]));
                }
                else if (fieldType == typeof(AcDate) && dataOffset > 0)
                {
                    currentField.SetValue(boxedData, new AcDate(saveData.ReadByteArray(dataOffset,
                                                                                       (int)playerSaveInfoType.GetField(field.Name + "Size").GetValue(offsets))));
                }
            }
            Data = (HouseData)boxedData;

            // Load Rooms/Layers
            var       itemDataSize  = MainForm.SaveFile.SaveGeneration == SaveGeneration.N3DS ? 4 : 2;
            const int itemsPerLayer = 256; //Offsets.Layer_Size / ItemDataSize;

            Data.Rooms = new Room[offsets.RoomCount];
            var roomNames = HouseInfo.GetRoomNames(saveData.SaveGeneration);

            for (var i = 0; i < offsets.RoomCount; i++)
            {
                var roomOffset = offset + offsets.RoomStart + i * offsets.RoomSize;
                var room       = new Room
                {
                    Index  = i,
                    Offset = roomOffset,
                    Name   = roomNames[i],
                    Layers = new Layer[offsets.LayerCount]
                };

                if (saveData.SaveGeneration == SaveGeneration.N64 || saveData.SaveGeneration == SaveGeneration.GCN)
                {
                    room.Carpet    = new Item((ushort)(0x2600 | saveData.ReadByte(roomOffset + offsets.RoomCarpet)));
                    room.Wallpaper = new Item((ushort)(0x2700 | saveData.ReadByte(roomOffset + offsets.RoomWallpaper)));
                }
                else
                {
                    room.Carpet    = new Item(saveData.ReadUInt16(roomOffset + offsets.RoomCarpet, saveData.IsBigEndian));
                    room.Wallpaper = new Item(saveData.ReadUInt16(roomOffset + offsets.RoomWallpaper, saveData.IsBigEndian));
                }

                for (var x = 0; x < offsets.LayerCount; x++)
                {
                    var layerOffset = roomOffset + offsets.LayerSize * x;
                    var layer       = new Layer
                    {
                        Offset = layerOffset,
                        Index  = x,
                        Items  = new Furniture[itemsPerLayer],
                        Parent = room
                    };

                    // Load furniture for the layer
                    for (var f = 0; f < itemsPerLayer; f++)
                    {
                        var furnitureOffset = layerOffset + f * itemDataSize;
                        if (itemDataSize == 4)
                        {
                            layer.Items[f] = new Furniture(saveData.ReadUInt32(furnitureOffset));
                        }
                        else
                        {
                            layer.Items[f] = new Furniture(saveData.ReadUInt16(furnitureOffset, saveData.IsBigEndian));
                        }
                    }

                    room.Layers[x] = layer;
                }
                Data.Rooms[i] = room;
            }
        }
Beispiel #3
0
        public House(int Index, int Offset)
        {
            this.Index  = Index;
            this.Offset = Offset;

            int  HouseSize = HouseInfo.GetHouseSize(Offset, MainForm.Save_File.Save_Type);
            bool Basement  = false;

            //Console.WriteLine("House Index: " + Index);
            //Console.WriteLine("House Offset: 0x" + Offset.ToString("X"));
            //Console.WriteLine("House Size: " + HouseSize.ToString());
            if (MainForm.Save_File.Save_Generation == SaveGeneration.N64 || MainForm.Save_File.Save_Generation == SaveGeneration.GCN)
            {
                Basement = HouseInfo.HasBasement(Offset, MainForm.Save_File.Save_Type);
                //Console.WriteLine("Basement: " + Basement.ToString());
            }

            // Load House Data
            var    Offsets            = HouseInfo.GetHouseOffsets(MainForm.Save_File.Save_Type);
            var    SaveData           = MainForm.Save_File;
            Type   PlayerDataType     = typeof(HouseData);
            Type   PlayerSaveInfoType = typeof(HouseOffsets);
            object BoxedData          = new HouseData();

            foreach (var Field in PlayerSaveInfoType.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                if (Field.GetValue(Offsets) != null && !Field.Name.Contains("Count") && !Field.Name.Contains("Size"))
                {
                    if (PlayerDataType.GetField(Field.Name) != null)
                    {
                        if (Field.FieldType == typeof(int) && (int)Field.GetValue(Offsets) != -1)
                        {
                            var  Current_Field = PlayerDataType.GetField(Field.Name);
                            Type FieldType     = Current_Field.FieldType;
                            int  DataOffset    = Offset + (int)Field.GetValue(Offsets);

                            if (!Field.Name.Equals("Room_Carpet") && !Field.Name.Equals("Room_Wallpaper") && !Field.Name.Equals("Room_Song"))
                            {
                                if (FieldType == typeof(byte))
                                {
                                    Current_Field.SetValue(BoxedData, SaveData.ReadByte(DataOffset));
                                }
                                else if (FieldType == typeof(byte[]) && PlayerSaveInfoType.GetField(Field.Name + "Count") != null)
                                {
                                    Current_Field.SetValue(BoxedData, SaveData.ReadByteArray(DataOffset,
                                                                                             (int)PlayerSaveInfoType.GetField(Field.Name + "Count").GetValue(Offsets)));
                                }
                                else if (FieldType == typeof(ushort))
                                {
                                    Current_Field.SetValue(BoxedData, SaveData.ReadUInt16(DataOffset, SaveData.Is_Big_Endian));
                                }
                                else if (FieldType == typeof(ushort[]))
                                {
                                    Current_Field.SetValue(BoxedData, SaveData.ReadUInt16Array(DataOffset,
                                                                                               (int)PlayerSaveInfoType.GetField(Field.Name + "Count").GetValue(Offsets), SaveData.Is_Big_Endian));
                                }
                                else if (FieldType == typeof(uint))
                                {
                                    Current_Field.SetValue(BoxedData, SaveData.ReadUInt32(DataOffset, SaveData.Is_Big_Endian));
                                }
                                else if (FieldType == typeof(string))
                                {
                                    Current_Field.SetValue(BoxedData, new ACString(SaveData.ReadByteArray(DataOffset,
                                                                                                          (int)PlayerSaveInfoType.GetField(Field.Name + "Size").GetValue(Offsets)), SaveData.Save_Type).Trim());
                                }
                                else if (FieldType == typeof(Item))
                                {
                                    if (SaveData.Save_Type == SaveType.New_Leaf || SaveData.Save_Type == SaveType.Welcome_Amiibo)
                                    {
                                        Current_Field.SetValue(BoxedData, new Item(SaveData.ReadUInt32(DataOffset, false)));
                                    }
                                    else
                                    {
                                        Current_Field.SetValue(BoxedData, new Item(SaveData.ReadUInt16(DataOffset, SaveData.Is_Big_Endian)));
                                    }
                                }
                                else if (FieldType == typeof(NL_Int32))
                                {
                                    uint[] Int_Data = SaveData.ReadUInt32Array(DataOffset, 2);
                                    Current_Field.SetValue(BoxedData, new NL_Int32(Int_Data[0], Int_Data[1]));
                                }
                                else if (FieldType == typeof(ACDate) && DataOffset > 0)
                                {
                                    Current_Field.SetValue(BoxedData, new ACDate(SaveData.ReadByteArray(DataOffset,
                                                                                                        (int)PlayerSaveInfoType.GetField(Field.Name + "Size").GetValue(Offsets))));
                                }
                            }
                        }
                    }
                }
            }
            Data = (HouseData)BoxedData;

            // Load Rooms/Layers
            int ItemDataSize  = MainForm.Save_File.Save_Generation == SaveGeneration.N3DS ? 4 : 2;
            int ItemsPerLayer = 256; //Offsets.Layer_Size / ItemDataSize;

            Data.Rooms = new Room[Offsets.Room_Count];
            var RoomNames = HouseInfo.GetRoomNames(SaveData.Save_Generation);

            for (int i = 0; i < Offsets.Room_Count; i++)
            {
                int RoomOffset = Offset + Offsets.Room_Start + i * Offsets.Room_Size;
                var Room       = new Room
                {
                    Index  = i,
                    Offset = RoomOffset,
                    Name   = RoomNames[i],
                    Layers = new Layer[Offsets.Layer_Count]
                };

                if (SaveData.Save_Generation == SaveGeneration.N64 || SaveData.Save_Generation == SaveGeneration.GCN)
                {
                    Room.Carpet    = new Item((ushort)(0x2600 | SaveData.ReadByte(RoomOffset + Offsets.Room_Carpet)));
                    Room.Wallpaper = new Item((ushort)(0x2700 | SaveData.ReadByte(RoomOffset + Offsets.Room_Wallpaper)));
                }
                else
                {
                    Room.Carpet    = new Item(SaveData.ReadUInt16(RoomOffset + Offsets.Room_Carpet, SaveData.Is_Big_Endian));
                    Room.Wallpaper = new Item(SaveData.ReadUInt16(RoomOffset + Offsets.Room_Wallpaper, SaveData.Is_Big_Endian));
                }

                for (int x = 0; x < Offsets.Layer_Count; x++)
                {
                    int LayerOffset = RoomOffset + Offsets.Layer_Size * x;
                    var Layer       = new Layer
                    {
                        Offset = LayerOffset,
                        Index  = x,
                        Items  = new Furniture[ItemsPerLayer],
                        Parent = Room
                    };

                    // Load furniture for the layer
                    for (int f = 0; f < ItemsPerLayer; f++)
                    {
                        int FurnitureOffset = LayerOffset + f * ItemDataSize;
                        if (ItemDataSize == 4)
                        {
                            Layer.Items[f] = new Furniture(SaveData.ReadUInt32(FurnitureOffset));
                        }
                        else
                        {
                            Layer.Items[f] = new Furniture(SaveData.ReadUInt16(FurnitureOffset, SaveData.Is_Big_Endian));
                        }
                    }

                    Room.Layers[x] = Layer;
                }
                Data.Rooms[i] = Room;
            }
        }