Пример #1
0
        public Town(MainSaveFile saveFile)
        {
            SaveFile = saveFile;
            var offsets = MainOffsets.GetOffsets(SaveFile.GetRevision());

            // Load Town Data
            TownId = SaveFile.ReadStruct <TownID>(offsets.Offset_TownId);

            // Load Villagers
            for (var i = 0; i < 10; i++)
            {
                Villagers[i] = new Villager(saveFile, i);
            }

            // Load Patterns
            for (var i = 0; i < 50; i++)
            {
                Patterns[i] = new DesignPattern(saveFile, i);
            }

            // Load Buildings
            for (var i = 0; i < 46; i++)
            {
                Buildings[i] = new Building(saveFile, i);
            }

            StalkMarket = new StalkMarket(SaveFile);
        }
Пример #2
0
        private async void OpenFileButton_Click(object o, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog
            {
                Filters = new List <FileDialogFilter>
                {
                    new FileDialogFilter
                    {
                        Name       = "New Horizons Save File",
                        Extensions = new List <string>
                        {
                            "dat"
                        }
                    },
                    new FileDialogFilter
                    {
                        Name       = "All Files",
                        Extensions = new List <string>
                        {
                            "*"
                        }
                    }
                }
            };

            var files = await openFileDialog.ShowAsync(this);

            if (files.Length > 0)
            {
                // Determine whether they selected the header file or the main file
                var    file = files[0];
                string headerPath;
                string filePath;
                if (file.EndsWith("Header.dat"))
                {
                    headerPath = file;
                    filePath   = Path.Combine(Path.GetDirectoryName(file), $"{Path.GetFileNameWithoutExtension(file).Replace("Header", "")}.dat");
                }
                else
                {
                    filePath   = file;
                    headerPath = Path.Combine(Path.GetDirectoryName(file), $"{Path.GetFileNameWithoutExtension(file)}Header.dat");
                }

                if (File.Exists(headerPath) && File.Exists(filePath))
                {
                    saveFile = new MainSaveFile(headerPath, filePath);
                    if (saveFile.Loaded)
                    {
                        villagerDatabase = VillagerDatabaseLoader.LoadVillagerDatabase((uint)saveFile.GetRevision());
                        LoadVillagerComboBoxItems();
                        (o as Button).IsVisible = false;
                        this.FindControl <TabControl>("EditorTabControl").IsVisible = true;
                        this.FindControl <Grid>("BottomBar").IsVisible    = true;
                        this.FindControl <TextBlock>("SaveInfoText").Text = $"Save File for Version {saveFile.GetRevisionString()} Loaded";
                        AddPlayerImages();
                        LoadPlayer(saveFile.GetPlayerSaves()[0].Player);
                        LoadVillagers();
                        LoadVillager(saveFile.Villagers[0]);

                        // Load Item List
                        itemDatabase = ItemDatabaseLoader.LoadItemDatabase((uint)saveFile.GetRevision());
                        var itemsBox = this.FindControl <ComboBox>("ItemSelectBox");
                        itemsBox.Items = itemDatabase.Values;

                        // Set up connections
                        SetupUniversalConnections();
                        SetupPlayerTabConnections();
                        SetupVillagerTabConnections();

                        SetItem(Item.NO_ITEM);
                    }
                    else
                    {
                        saveFile = null;
                    }
                }
            }
        }