Exemplo n.º 1
0
        public Villager(ISaveFile saveFile, int idx)
        {
            SaveFile = saveFile;
            Index    = idx;

            var offsets = MainOffsets.GetOffsets(SaveFile.GetRevision());

            Offset = offsets.Offset_Vilagers + idx * offsets.Villager_Size;

            Species     = SaveFile.ReadU8(Offset + offsets.Villager_Species);
            VariantIdx  = SaveFile.ReadU8(Offset + offsets.Villager_Variant);
            Personality = SaveFile.ReadU8(Offset + offsets.Villager_Personality);
            Catchphrase = SaveFile.ReadString(Offset + offsets.Villager_Catchphrase, offsets.Villager_CatchphraseLength); // Not sure about the size.

            var ftr = new Item[offsets.Villager_FurnitureCount];

            for (var i = 0; i < ftr.Length; i++)
            {
                ftr[i] = new Item(SaveFile, Offset + offsets.Villager_Furniture + i * 0x2C);
            }
            Furniture = new ItemCollection(ftr);

            Wallpaper = new ItemCollection(new Item[1] {
                new Item(SaveFile, Offset + offsets.Villager_Wallpaper)
            });
            Flooring = new ItemCollection(new Item[1] {
                new Item(SaveFile, Offset + offsets.Villager_Flooring)
            });
        }
Exemplo n.º 2
0
        public Chunk(World world, ChunkPos chunkPos)
        {
            World = world;
            Pos   = chunkPos;

            _storageKey = StorageKey.Get("ChunkData", chunkPos);

            var saveFile   = world?.Universe?.SaveFile;
            var savedValue = saveFile?.ReadAsync(_storageKey)?.Result;

            if (savedValue != null)
            {
                var chunkData = savedValue.Deserialize <ChunkData>();
                if (chunkData != null)
                {
                    try
                    {
                        PasteChunkData(chunkData);
                    }
                    catch
                    {
                        _data       = null;
                        _isCreated  = false;
                        _chunkData  = null;
                        ContentHash = 0;
                    }
                }
            }

            _saveFile = saveFile;
        }
Exemplo n.º 3
0
        public Player(ISaveFile saveFile, int idx, PersonalSaveFile personalSave)
        {
            SaveFile      = saveFile;
            _personalFile = personalSave;
            var offsets = PersonalOffsets.GetOffsets(SaveFile.GetRevision());

            Index = idx;

            PersonalId = new PersonalID(personalSave, offsets.PersonalId);
            Wallet     = new EncryptedInt32(personalSave, offsets.Wallet);
            Bank       = new EncryptedInt32(personalSave, offsets.Bank);
            NookMiles  = new EncryptedInt32(personalSave, offsets.NookMiles);

            // TODO: This should be refactored to detect the "expanded pockets" state
            var pockets = new Item[40];

            for (var i = 0; i < 20; i++)
            {
                pockets[i]      = new Item(personalSave, offsets.Pockets + 0xB8 + i * 8);
                pockets[i + 20] = new Item(personalSave, offsets.Pockets + i * 8);
            }

            Pockets = new ItemCollection(pockets);

            var storage = new Item[5000];

            for (var i = 0; i < 5000; i++)
            {
                storage[i] = new Item(personalSave, offsets.Storage + i * 8);
            }
            Storage = new ItemCollection(storage);
        }
Exemplo n.º 4
0
        public static bool Save(string saveName, ISaveFile saveData, bool autoSave = false)
        {
            BinaryFormatter formatter = GetBinaryFormatter();

            string saveFilePath = GetSaveDirectories(saveName, autoSave);

            FileStream file = File.Open(saveFilePath, FileMode.OpenOrCreate);

            datas.Clear();
            OnBeforeSave?.Invoke();
            saveData.Datas = datas.ToArray();

            try
            {
                formatter.Serialize(file, saveData);
            }
            catch (Exception)
            {
                file.Close();
                return(false);
            }
            file.Close();

            return(true);
        }
Exemplo n.º 5
0
        public Universe(ISaveFile saveFile)
            : base(new Messenger())
        {
            SaveFile = saveFile;

            StartWorld = new World(this);
        }
 public MainWindowViewModel(IFile file, IMessageBox messageBox, ISaveFile saveFile, IOpenFile openFile, IPath path)
 {
     this.file       = file;
     this.messageBox = messageBox;
     this.saveFile   = saveFile;
     this.openFile   = openFile;
     this.path       = path;
 }
Exemplo n.º 7
0
 public void Save(ISaveFile save, int offset)
 {
     save.WriteU16(offset, ItemId);
     save.WriteU8(offset + 2, Flags0);
     save.WriteU8(offset + 3, Flags1);
     save.WriteU16(offset + 4, Count);
     save.WriteU16(offset + 6, UseCount);
 }
Exemplo n.º 8
0
 public AdminController(IItemService itemService, IOrderService orderService, IUserService userService, IWebHostEnvironment env, ISaveFile saveFileService, int pageSize = 5)
 {
     _itemService     = itemService;
     _orderService    = orderService;
     _userService     = userService;
     _saveFileService = saveFileService;
     _env             = env;
     this.pageSize    = pageSize;
 }
Exemplo n.º 9
0
 public static void IsEquivalentTo <T>(this ISaveFile <T> actual, ISaveFile <T> expected) where T : ISaveData
 {
     Asserter.Against(actual)
     .WithHeading($"First {actual.GetType().Prettify()} must be equivalent to the second {expected.GetType().Prettify()}")
     .And(Has.Property(nameof(actual.Nickname)).EqualTo(expected.Nickname))
     .And(Has.Property(nameof(actual.TimeStamp)).EqualTo(expected.TimeStamp))
     .And(Has.Property(nameof(actual.Data)).EqualTo(expected.Data))
     .Invoke();
 }
Exemplo n.º 10
0
        public Building(ISaveFile saveFile, int index)
        {
            var offsets = MainOffsets.GetOffsets(saveFile.GetRevision());

            if (index >= offsets.Building_Count)
            {
                throw new IndexOutOfRangeException("Index was greater than the number of building slots!");
            }
            this = saveFile.ReadStruct <Building>(offsets.Offset_Buildings + index * 0x14);
        }
Exemplo n.º 11
0
        public Game(ISaveFile pSaveFile)
        {
            _saveFile = pSaveFile;
            Database.Initialize();

            var protagonists = _saveFile.GetSavedProtagonists();
            var world        = _saveFile.GetCurrentWorld();

            Battlefield = new Battlefield(protagonists, world);
        }
Exemplo n.º 12
0
        public void Save(ISaveFile saveFile, int index)
        {
            var offsets = MainOffsets.GetOffsets(saveFile.GetRevision());

            if (index >= offsets.Building_Count)
            {
                throw new IndexOutOfRangeException("Index was greater than the number of building slots!");
            }
            saveFile.WriteStruct(offsets.Offset_Buildings + index * 0x14, this);
        }
Exemplo n.º 13
0
        private static void OnChanged(object sender, FileSystemEventArgs e)
        {
            string changedFullPath = e.FullPath;

            using (IEncoderEngine encoderEngine = EncoderEngine.CreateEncoderEngine(changedFullPath))
            {
                encoderEngine.EncodeToJPG();
            }
            ISaveFile saveFile = SaveFile.CreateSaveFile(changedFullPath);

            saveFile.SaveToArchiveFolder();
        }
Exemplo n.º 14
0
        internal static void MustExist(this ISaveFile <ISaveData>?saveFile)
        {
            if (saveFile == null)
            {
                throw new ArgumentNullException(nameof(saveFile));
            }

            saveFile.FileSystemInfo.Refresh();
            if (saveFile.FileSystemInfo.Exists == false)
            {
                throw new FileNotFoundException($"The file referenced by the {saveFile.GetType().Prettify()} {saveFile.Nickname} does not exist!");
            }
        }
Exemplo n.º 15
0
        public Universe(ISaveFile saveFile, Mod mod)
        {
            SaveFile = saveFile;
            _mod     = mod;

            _startWorld           = new World(this);
            _startWorld.Generator = new WorldGenerator(_startWorld);

            _modData = new ModData
            {
                Materials = mod.Materials.Values.Select((m, i) =>
                {
                    m.Index = i;
                    return(m);
                }).ToList(),

                Models = mod.MobTypes.Values.Select((m, i) =>
                {
                    m.Model.Index = i;
                    return(m.Model);
                }).ToList(),
            };

            for (int i = 0; i < 20; ++i)
            {
                MobType type = null;
                if (_mod.MobTypes.Count > 0)
                {
                    string nextMobType = _mod.MobTypes.Keys.ElementAt(i % _mod.MobTypes.Count);
                    type = _mod.MobTypes[nextMobType];
                }

                var e = new Entity()
                {
                    PositionData   = new PositionData(),
                    IsAiControlled = true,
                    MobName        = type?.Name,
                    ModelIndex     = type?.Model.Index
                };

                Movement.Respawn(e.PositionData);
                _entities.Add(e);
            }

            var thread = new Thread(() => RunUniverse());

            thread.IsBackground = true;
            thread.Start();
        }
Exemplo n.º 16
0
 public ProcessCatalogueFile(
     IConstructFileStoragePath constructFileStoragePath,
     ISaveFile saveFile,
     IFileParser fileParser,
     ICompanyCatalogueCollection companyCatalogueCollection,
     ICatalogueUOW catalogueUOW,
     IDeleteFile deleteFile)
 {
     _constructFileStoragePath = constructFileStoragePath;
     _saveFile   = saveFile;
     _fileParser = fileParser;
     _companyCatalogueCollection = companyCatalogueCollection;
     _catalogueUOW = catalogueUOW;
     _deleteFile   = deleteFile;
 }
Exemplo n.º 17
0
        public Universe(ISaveFile saveFile, Mod mod)
        {
            SaveFile = saveFile;
            _mod = mod;

            _startWorld = new World(this);
            _startWorld.Generator = new WorldGenerator(_startWorld);

            _modData = new ModData
            {
                Materials = mod.Materials.Values.Select((m, i) =>
                {
                    m.Index = i;
                    return m;
                }).ToList(),

                Models = mod.MobTypes.Values.Select((m, i) =>
                {
                    m.Model.Index = i;
                    return m.Model;
                }).ToList(),
            };

            for (int i = 0; i < 20; ++i)
            {
                MobType type = null;
                if (_mod.MobTypes.Count > 0)
                {
                    string nextMobType = _mod.MobTypes.Keys.ElementAt(i % _mod.MobTypes.Count);
                    type = _mod.MobTypes[nextMobType];
                }

                var e = new Entity()
                {
                    PositionData = new PositionData(),
                    IsAiControlled = true,
                    MobName = type?.Name,
                    ModelIndex = type?.Model.Index
                };

                Movement.Respawn(e.PositionData);
                _entities.Add(e);
            }

            var thread = new Thread(() => RunUniverse());
            thread.IsBackground = true;
            thread.Start();
        }
Exemplo n.º 18
0
        private static void EncodeAll(string folderName)
        {
            string[] filePathsArray = Directory.GetFiles(folderName, "*.bmp");

            foreach (string path in filePathsArray)
            {
                Console.WriteLine(path);
                using (IEncoderEngine encoderEngine = EncoderEngine.CreateEncoderEngine(path))
                {
                    encoderEngine.EncodeToJPG();
                }
                ISaveFile saveFile = SaveFile.CreateSaveFile(path);
                saveFile.SaveToArchiveFolder();
            }

            Console.WriteLine("Done Encoding.  Click space to exit.");
            Console.ReadKey();
        }
Exemplo n.º 19
0
        public DesignPattern(ISaveFile saveFile, int idx)
        {
            SaveFile = saveFile;
            Index    = idx;
            var offsets = MainOffsets.GetOffsets(SaveFile.GetRevision());

            Offset = offsets.Offset_Patterns + idx * offsets.Pattern_Size;

            Name       = SaveFile.ReadString(Offset + offsets.Pattern_Name, 20);
            PersonalID = SaveFile.ReadStruct <PersonalID>(Offset + offsets.Pattern_PersonalID);

            for (int i = 0; i < 15; i++)
            {
                Palette[i] = new DesignColor(saveFile, Offset + offsets.Pattern_Palette + i * 3);
            }

            Pixels = SaveFile.ReadArray <byte>(Offset + offsets.Pattern_ImageData, Pixels.Length);
        }
Exemplo n.º 20
0
 private static void EncodeSingle(string fileName)
 {
     if (File.Exists(fileName))
     {
         using (IEncoderEngine encoderEngine = EncoderEngine.CreateEncoderEngine(fileName))
         {
             encoderEngine.EncodeToJPG();
         }
         ISaveFile saveFile = SaveFile.CreateSaveFile(fileName);
         saveFile.SaveToArchiveFolder();
         Console.WriteLine("Done encoding file: " + fileName);
         Console.ReadKey();
     }
     else
     {
         Console.WriteLine("Could not find file: " + fileName);
         Console.ReadKey();
     }
 }
Exemplo n.º 21
0
        public FileHelper( ISaveFile saver, ILoadFile loader, IFileOperationsUtility utilities )
        {
            if (saver == null)
            {
                throw new ArgumentNullException( nameof( saver ) );
            }
            if (loader == null)
            {
                throw new ArgumentNullException( nameof( loader ) );
            }
            if (utilities == null)
            {
                throw new ArgumentNullException( nameof( utilities ) );
            }

            _saver = saver;
            _loader = loader;
            _utilities = utilities;
        }
 public FileManagementApplicationService(IConfiguration configuration, ISaveFile saveFile, IMoveFile moveFile)
 {
     _configuration = configuration;
     _saveFile      = saveFile;
     _moveFile      = moveFile;
 }
Exemplo n.º 23
0
 public Item(ISaveFile save, int offset)
     : this(save.ReadU16(offset + 0), save.ReadU8(offset + 2), save.ReadU8(offset + 3),
            save.ReadU16(offset + 4), save.ReadU16(offset + 6))
 {
 }
Exemplo n.º 24
0
 public JsonSaveService(ISaveFile saveFile, IConfiguration configuration, IGetFile getFile)
 {
     _saveFile      = saveFile;
     _configuration = configuration;
     _getFile       = getFile;
 }
Exemplo n.º 25
0
 public JsonManager(ISaveFile saveFileDialog, IOpenFile openFileDialog)
 {
     _saveFileDialog = saveFileDialog;
     _openFileDialog = openFileDialog;
 }
Exemplo n.º 26
0
 public TourPlannerReport(ISaveFile saveFile)
 {
     _saveFile = saveFile;
 }
 public void SetTests()
 {
     _service = new SaveFileService();
 }
 public EncryptedInt32(ISaveFile save, int offset)
     : this(save.ReadU32(offset), save.ReadU16(offset + 4),
            save.ReadU8(offset + 6), save.ReadU8(offset + 7))
 {
 }
Exemplo n.º 29
0
 public PersonalID(ISaveFile save, int offset) => this = save.ReadStruct <PersonalID>(offset);
Exemplo n.º 30
0
 public PlayerSave(ISaveFile saveFile, in string folder, in SaveRevision revision)
Exemplo n.º 31
0
 public DesignColor(ISaveFile saveFile, int offset)
 {
     this = saveFile.ReadStruct <DesignColor>(offset);
 }
Exemplo n.º 32
0
 public TownID(ISaveFile save, int offset) => this = save.ReadStruct <TownID>(offset);