Beispiel #1
0
        //browseButton_Click event allows the user to browse for an designate a new Undertale install directory
        private async void browseButton_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowser2 directoryFolderBrowser = new FolderBrowser2();

            directoryFolderBrowser.ShowDialog((System.Windows.Forms.IWin32Window) this.Owner);

            if (File.Exists(directoryFolderBrowser.DirectoryPath + "//UNDERTALE.exe"))
            {
                WaitingWindow waitWindow = new WaitingWindow("Backing Up", "Backing up game files, please wait. This may take some time.");
                waitWindow.Owner = this;
                Hide();
                waitWindow.Show();
                await Task.Run(() => FileOperations.backupFilesFromGameDirectory(directoryFolderBrowser.DirectoryPath));

                waitWindow.Close();
                Show();

                browseButton.IsEnabled      = false;
                saveEditorButton.IsEnabled  = true;
                musicEditorButton.IsEnabled = true;
                optionsButton.IsEnabled     = true;
                savesCombo.IsEnabled        = true;
                presetsCombo.IsEnabled      = true;
                debugCheck.IsEnabled        = true;
                launchButton.IsEnabled      = true;

                populateSavesCombo();
                populatePresetsCombo();

                try
                {
                    string gameVersion = FileVersionInfo.GetVersionInfo(directoryFolderBrowser.DirectoryPath + "//UNDERTALE.exe").ProductVersion;
                    gameVersion = gameVersion.Replace(" ", String.Empty);   //Remove any spaces at the end of the version

                    XML.WriteGamePath(directoryFolderBrowser.DirectoryPath);

                    directoryBlock.Text    = "Path: " + XML.GetGamePath();
                    directoryBlock.ToolTip = XML.GetGamePath();

                    if (FileOperations.disableDogcheck(gameVersion, directoryFolderBrowser.DirectoryPath + "//data.win"))   //We disable dogcheck at the game directory
                    {
                        versionBlock.Text = "Game Version: " + gameVersion + ", Dog Check DISABLED.";
                    }

                    else
                    {
                        this.Close();
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Unable to verify game version. This could indicate the Undertale.exe file is invalid or corrupt. Please try again and ensure the selected directory is correct. If the issue persists, please redownload the game. The exception is: " + ex, "Invalid Game Version!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            else if (directoryFolderBrowser.DirectoryPath != null)
            {
                Dictionary <Characters, string> messageDict = new Dictionary <Characters, string>()
                {
                    { Characters.Alphys, "I'm real s-s-sorry, but I c-c-couldn't find the Undertale.exe in that folder." },
                    { Characters.Asgore, "I'm greatly sorry human, but I was unable to find the Undertale.exe in that folder." },
                    { Characters.Asriel, "I'm so sorry, but I can't find the Undertale.exe in that folder." },
                    { Characters.Flowey, "YOU. IDIOT. I can't find the Undertale.exe in that folder!" },
                    { Characters.Papyrus, "NYOO HOO HOO. I AM SORRY, BUT I'VE FAILED TO FIND THE UNDERTALE.EXE IN THAT FOLDER." },
                    { Characters.Sans, "c'mon pal, help me out here. i can't find the undertale.exe in that folder." },
                    { Characters.Toriel, "I'm afraid that I was unable to locate the Undertale.exe in that folder, my child." },
                    { Characters.Undyne, "HEY, COME ON PUNK! I can't find the Undertale.exe in that folder." },
                    { Characters.None, "Cannot locate Undertale.exe in the folder specified. Please navigate to a valid Undertale installation folder." }
                };

                UTMessageBox.Show(messageDict, Constants.CharacterReactions.Negative, MessageBoxButton.OK);
            }
        }
Beispiel #2
0
            //WriteSaveFile writes, well, the save file.
            public static bool WriteSaveFile(SAVEFile fileToWrite, INI.INIFile ini)
            {
                //SetFlagFromBool converts a boolean variable or value to a string to be written as a flag in file0
                string SetFlagFromBool(bool booleanToCheck, int valueToSet = 1)
                {
                    if (booleanToCheck)
                    {
                        return(valueToSet.ToString());
                    }

                    else
                    {
                        return("0");
                    }
                }

                //We use an ordered dictionary with the key as the line number in file0 to write the value to
                OrderedDictionary file0Contents = new OrderedDictionary
                {
                    { 1, fileToWrite.PlayerName },
                    { 2, fileToWrite.LOVE.ToString() },
                    { 3, fileToWrite.HP.ToString() },
                    { 4, "0" },
                    { 5, fileToWrite.friskAT.ToString() },
                    { 6, fileToWrite.weaponAT.ToString() },
                    { 7, fileToWrite.friskDF.ToString() },
                    { 8, fileToWrite.armorDF.ToString() },
                    { 9, "4" },
                    { 10, fileToWrite.EXP.ToString() },
                    { 11, fileToWrite.GOLD.ToString() },
                    { 12, fileToWrite.KillCount.ToString() },
                    { 13, fileToWrite.inventoryItems[0].ToString() },
                    { 14, fileToWrite.phoneItems[0].ToString() },
                    { 15, fileToWrite.inventoryItems[1].ToString() },
                    { 16, fileToWrite.phoneItems[1].ToString() },
                    { 17, fileToWrite.inventoryItems[2].ToString() },
                    { 18, fileToWrite.phoneItems[2].ToString() },
                    { 19, fileToWrite.inventoryItems[3].ToString() },
                    { 20, fileToWrite.phoneItems[3].ToString() },
                    { 21, fileToWrite.inventoryItems[4].ToString() },
                    { 22, "0" },
                    { 23, fileToWrite.inventoryItems[5].ToString() },
                    { 24, "0" },
                    { 25, fileToWrite.inventoryItems[6].ToString() },
                    { 26, "0" },
                    { 27, fileToWrite.inventoryItems[7].ToString() },
                    { 28, "0" },
                    { 29, fileToWrite.Weapon },
                    { 30, fileToWrite.Armor },
                    { 38, Convert.ToInt16(fileToWrite.asrielDefeated) },
                    { 39, Convert.ToInt16(fileToWrite.randomCountersDisabled) },
                    { 45, (int)fileToWrite.ruinsDummyState },
                    { 76, (int)fileToWrite.torielState },
                    { 83, (int)fileToWrite.doggoState },
                    { 84, (int)fileToWrite.dogamyState },
                    { 85, (int)fileToWrite.greaterDogState },
                    { 88, (int)fileToWrite.comedianState },
                    { 98, (int)fileToWrite.papyrusState },
                    { 112, (int)fileToWrite.shyrenState },
                    { 119, (int)fileToWrite.papyrusDated },
                    { 232, fileToWrite.KillCount },
                    { 233, fileToWrite.ruinsKills },
                    { 234, fileToWrite.snowdinKills },
                    { 235, fileToWrite.waterfallKills },
                    { 236, fileToWrite.hotlandKills },
                    { 282, (int)fileToWrite.undyneState },
                    { 283, (int)fileToWrite.madDummyState },
                    { 381, (int)fileToWrite.undyneState },
                    { 398, Convert.ToInt16(fileToWrite.disableAlphysCalls) },
                    { 399, Convert.ToInt16(fileToWrite.disableAlphysCalls) },
                    { 402, Convert.ToInt16(fileToWrite.disableHotlandPuzzles) },
                    { 404, Convert.ToInt16(fileToWrite.disableHotlandPuzzles) },
                    { 405, Convert.ToInt16(fileToWrite.disableHotlandPuzzles) },
                    { 406, Convert.ToInt16(fileToWrite.disableHotlandPuzzles) },
                    { 420, (int)fileToWrite.undyneDated },
                    { 428, (int)fileToWrite.muffetState },
                    { 430, Convert.ToInt16(fileToWrite.disableHotlandPuzzles) },
                    { 431, Convert.ToInt16(fileToWrite.disableHotlandPuzzles) },
                    { 433, (int)fileToWrite.broGuardsState },
                    { 449, SetFlagFromBool(fileToWrite.coreElevatorUnlocked) },
                    { 456, (int)fileToWrite.mettatonState },
                    { 462, SetFlagFromBool(fileToWrite.insideCastle) },
                    { 463, SetFlagFromBool(fileToWrite.rodeCastleLift) },
                    { 481, SetFlagFromBool(ini.skipAsrielStory, 17) },
                    { 483, SetFlagFromBool(fileToWrite.unlockedCastleChain) },
                    { 484, SetFlagFromBool(fileToWrite.unlockedCastleChain) },
                    { 485, SetFlagFromBool(fileToWrite.unlockedCastleChain) },
                    { 486, SetFlagFromBool(ini.skipAsrielStory) },
                    { 487, SetFlagFromBool(ini.skipAsrielStory, 2) },
                    { 496, Convert.ToInt16(fileToWrite.undyneOnPhone) },
                    { 510, SetFlagFromBool(fileToWrite.asrielDefeated, 2) },
                    { 512, SetFlagFromBool(fileToWrite.beatTrueLab, 3) },
                    { 513, SetFlagFromBool(fileToWrite.beatTrueLab, 3) },
                    { 514, SetFlagFromBool(fileToWrite.beatTrueLab, 3) },
                    { 515, SetFlagFromBool(fileToWrite.beatTrueLab, 3) },
                    { 516, SetFlagFromBool(fileToWrite.beatTrueLab) },
                    { 517, SetFlagFromBool(fileToWrite.beatTrueLab, 10) },
                    { 518, SetFlagFromBool(fileToWrite.beatTrueLab, 0) },
                    { 519, SetFlagFromBool(fileToWrite.beatTrueLab) },
                    { 520, SetFlagFromBool(fileToWrite.beatTrueLab) },
                    { 521, SetFlagFromBool(fileToWrite.beatTrueLab) },
                    { 522, SetFlagFromBool(fileToWrite.beatTrueLab) },
                    { 523, SetFlagFromBool(fileToWrite.dateAlphysFlag) },
                    { 524, fileToWrite.pacifistStage },
                    { 543, fileToWrite.Plot },
                    { 544, "1" },
                    { 545, "1" },
                    { 546, SetFlagFromBool(MiscFunctions.SetBooleanValueFromLocation(fileToWrite.Location, 12)) }, //Cell Phone
                    { 547, "0" },
                    { 548, fileToWrite.Location.ToString() },
                    { 549, "0" }
                };

                if (fileToWrite.Location == 998)
                {
                    fileToWrite.Location = 235;
                    FileOperations.setGenocide(GenocideStates.Abyss);
                }

                else if (fileToWrite.Location == 999)
                {
                    fileToWrite.Location = 237;
                }

                try
                {
                    StreamWriter file0Writer = new StreamWriter(File.Open(Constants.SavesPath + fileToWrite.SaveName + "//file0", FileMode.Create), Encoding.ASCII);

                    //We iterate through every line and key in file0Contents and if the key value matches lineNumber, we write the corresponding value
                    for (int lineNumber = 1; lineNumber <= 549; lineNumber++)
                    {
                        foreach (DictionaryEntry file0Entry in file0Contents)
                        {
                            if ((int)file0Entry.Key == lineNumber)
                            {
                                file0Writer.WriteLine(file0Entry.Value.ToString());
                                break;
                            }

                            else if ((int)file0Entry.Key > lineNumber)
                            {
                                file0Writer.WriteLine("0");
                                break;
                            }
                        }
                    }

                    file0Writer.Close();

                    if (fileToWrite.Location >= 238 || fileToWrite.Plot >= 208)
                    {
                        File.Copy(Constants.SavesPath + fileToWrite.SaveName + "//file0", Constants.SavesPath + fileToWrite.SaveName + "//file8", true);
                    }
                    return(true);
                }

                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show("An exception occurred when writing the save file. Cannot continue. The exception was: \n\n" + ex, "Error!",
                                                   MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
            }