Пример #1
0
        public static Dictionary <ushort, SimpleVillager> GetCaravanBindingSource()
        {
            var waDatabase = VillagerInfo.GetVillagerDatabase(SaveType.WelcomeAmiibo);

            if (waDatabase == null)
            {
                return(null);
            }

            foreach (var v in WaSpecialVillagers)
            {
                var specialVillager = new SimpleVillager
                {
                    VillagerId = v.Key,
                    Name       = v.Value
                };
                waDatabase.Add(v.Key, specialVillager);
            }

            return(waDatabase);
        }
Пример #2
0
        public Villager(int offset, int idx, Save save)
        {
            _saveData = save;
            Index     = idx;
            Offset    = offset;
            Offsets   = VillagerInfo.GetVillagerInfo(save.SaveType);

            var structType = typeof(VillagerDataStruct);
            var offsetType = typeof(VillagerOffsets);

            if (save.SaveType == SaveType.WildWorld)
            {
                Exists = _saveData.ReadByte(offset + Offsets.VillagerId) != 0 && _saveData.ReadByte(offset + Offsets.VillagerId) != 0xFF;
            }
            else if (save.SaveType == SaveType.CityFolk)
            {
                Exists = _saveData.ReadByte(offset) != 0;
            }
            else
            {
                Exists = _saveData.ReadUInt16(offset + Offsets.VillagerId, save.IsBigEndian) != 0 &&
                         _saveData.ReadUInt16(offset + Offsets.VillagerId, save.IsBigEndian) != 0xFFFF;
            }
            object boxedData = new VillagerDataStruct();

            foreach (var field in offsetType.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                if (field.GetValue(Offsets) == null || field.Name.Contains("Count") ||
                    field.Name.Contains("Size"))
                {
                    continue;
                }
                if (structType.GetField(field.Name) == null)
                {
                    continue;
                }
                if (field.FieldType != typeof(int) || (int)field.GetValue(Offsets) == -1)
                {
                    continue;
                }

                var fieldType  = structType.GetField(field.Name).FieldType;
                var dataOffset = Offset + (int)field.GetValue(Offsets);

                if (field.Name == "VillagerId" && save.SaveType == SaveType.WildWorld) // Villager IDs are only a byte in WW
                {
                    structType.GetField(field.Name).SetValue(boxedData, _saveData.ReadByte(dataOffset));
                }
                else if (fieldType == typeof(byte))
                {
                    structType.GetField(field.Name).SetValue(boxedData, _saveData.ReadByte(dataOffset));
                }
                else if (fieldType == typeof(byte[]) && offsetType.GetField(field.Name + "Count") != null)
                {
                    structType.GetField(field.Name).SetValue(boxedData, _saveData.ReadByteArray(dataOffset,
                                                                                                (int)offsetType.GetField(field.Name + "Count").GetValue(Offsets)));
                }
                else if (fieldType == typeof(ushort))
                {
                    structType.GetField(field.Name).SetValue(boxedData,
                                                             _saveData.ReadUInt16(dataOffset, _saveData.IsBigEndian));
                }
                else if (fieldType == typeof(ushort[]))
                {
                    structType.GetField(field.Name).SetValue(boxedData, _saveData.ReadUInt16Array(dataOffset,
                                                                                                  (int)offsetType.GetField(field.Name + "Count").GetValue(Offsets),
                                                                                                  _saveData.IsBigEndian));
                }
                else if (fieldType == typeof(uint))
                {
                    structType.GetField(field.Name).SetValue(boxedData,
                                                             _saveData.ReadUInt32(dataOffset, _saveData.IsBigEndian));
                }
                else if (fieldType == typeof(string))
                {
                    structType.GetField(field.Name).SetValue(boxedData, new AcString(_saveData.ReadByteArray(
                                                                                         dataOffset,
                                                                                         (int)offsetType.GetField(field.Name + "Size").GetValue(Offsets)),
                                                                                     _saveData.SaveType)
                                                             .Trim());
                }
                else if (fieldType == typeof(Item))
                {
                    structType.GetField(field.Name).SetValue(boxedData,
                                                             save.SaveGeneration == SaveGeneration.N3DS
                            ? new Item(_saveData.ReadUInt32(dataOffset))
                            : new Item(_saveData.ReadUInt16(dataOffset, _saveData.IsBigEndian)));
                }
                else if (fieldType == typeof(Item[]))
                {
                    var collection =
                        new Item[(int)offsetType.GetField(field.Name + "Count").GetValue(Offsets)];
                    for (var i = 0; i < collection.Length; i++)
                    {
                        if (save.SaveGeneration == SaveGeneration.N3DS)
                        {
                            collection[i] = new Item(_saveData.ReadUInt32(dataOffset + i * 4));
                        }
                        else
                        {
                            collection[i] =
                                new Item(_saveData.ReadUInt16(dataOffset + i * 2, _saveData.IsBigEndian));
                        }
                    }

                    structType.GetField(field.Name).SetValue(boxedData, collection);
                }
            }

            Data = (VillagerDataStruct)boxedData;

            // Set Villager Name for e+ TODO: Separate translated e+ & untranslated e+.
            if (_saveData.SaveType == SaveType.DoubutsuNoMoriEPlus)
            {
                Name = _saveData.ReadString(Offset + 0xC, 6);
            }
            else if (_saveData.SaveType == SaveType.AnimalForestEPlus)
            {
                Name = _saveData.ReadString(Offset + 0xC, 8);
            }

            // Create Player Relations;
            if (save.SaveType != SaveType.AnimalCrossing)
            {
                return;
            }
            {
                AnimalMemories = new AnimalMemory[7];
                for (var i = 0; i < 7; i++)
                {
                    AnimalMemories[i] = new AnimalCrossingAnimalMemory(save, this, Offset + 0x10 + i * 0x138);
                }
            }
        }