//setComboIndexFromLoad sets the correct Combobox item index for the comparisonValue item when a save is loaded void setComboIndexFromLoad(ComboBox combo, object comparisonValue) { foreach (var thisItem in combo.Items) { if (IDs.GetID((string)thisItem) == IDs.GetID(comparisonValue.ToString())) { combo.SelectedIndex = combo.Items.IndexOf(thisItem); } } }
//SelectionChanged is used with some UI controls to update our save variable values when we select a new armor, weapon, item or route private void SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!loading) { if (((ComboBox)sender == weaponCombo || (ComboBox)sender == armorCombo)) { weaponATBox.Text = Stats.getItemAT(IDs.GetID(weaponCombo.SelectedItem.ToString()), IDs.GetID(armorCombo.SelectedItem.ToString())); armorDFBox.Text = Stats.getItemDF(IDs.GetID(armorCombo.SelectedItem.ToString())); } else if ((ComboBox)sender == LOVECombo) { LOVEChanged(); } else if ((ComboBox)sender == routeCombo || (ComboBox)sender == locationCombo) { updateCurrentRoute(); } } }
//makeSave loops through all UI controls and converts and casts to thisSave variable types as required to create a new save void makeSave() { thisSave.PlayerName = nameBox.Text; thisSave.Location = IDs.Locations.GetRoomID(locationCombo.SelectedItem.ToString()); thisSave.LOVE = Convert.ToInt16(LOVECombo.Text); thisSave.KillCount = Convert.ToInt16(killsBox.Text); thisSave.GOLD = Convert.ToInt16(GOLDBox.Text); thisSave.Weapon = IDs.GetID(weaponCombo.SelectedItem.ToString()); thisSave.Armor = IDs.GetID(armorCombo.SelectedItem.ToString()); thisSave.HP = Convert.ToInt16(HPBox.Text); thisSave.friskAT = Convert.ToInt16(friskATBox.Text) + 10; //For some reason, the game sets Frisk's base AT to -10 of what is set in the thisSave.friskDF = Convert.ToInt16(friskDFBox.Text) + 10; //save file. Am I missing something regarding the AT/DF system? thisSave.weaponAT = Convert.ToInt16(weaponATBox.Text); thisSave.armorDF = Convert.ToInt16(armorDFBox.Text); int i = 0; Array.Clear(thisSave.inventoryItems, 0, thisSave.inventoryItems.Length); foreach (Grid grid in inventoryGrid.Children.OfType <Grid>()) { foreach (ComboBox comboBox in grid.Children.OfType <ComboBox>()) { thisSave.inventoryItems[i] = IDs.GetID(comboBox.SelectedItem.ToString()); i++; } } i = 0; Array.Clear(thisSave.phoneItems, 0, thisSave.phoneItems.Length); foreach (var checkBox in phoneItemsGrid.Children.OfType <CheckBox>()) { if ((bool)checkBox.IsChecked) { thisSave.phoneItems[i] = IDs.GetID(checkBox.Content.ToString()); i++; } } thisSave.SaveName = saveNameBox.Text; thisINI = INI.GetINI(); thisINI.sansMetInJudgment = MiscFunctions.SetBooleanValueFromLocation(thisSave.Location, 232); if (thisSave.Location == 999) { thisINI.photoshopFight = true; } else { thisINI.skipFight = false; } if (thisSave.Location == 998) { thisSave = SAVE.SAVEFile.SetSaveForRoute(thisSave, thisSave.Location, Routes.GameRoutes.Genocide); genocideRadio.IsChecked = true; } if (GetSelectedRoute() >= Routes.GameRoutes.TruePacifistAsrielTalk) { thisINI.barrierDestroyed = true; } if (GetSelectedRoute() == Routes.GameRoutes.TruePacifistEpilogue) { thisINI.canTrueReset = true; } else if (GetSelectedRoute() == Routes.GameRoutes.Genocide) { thisINI.killedSans = MiscFunctions.SetBooleanValueFromLocation(thisSave.Location, 232); } }
//loadSAVE sets up the UI for the values from the new saveFile void loadSAVE(SAVE.SAVEFile saveFile) { loading = true; nameBox.Text = saveFile.PlayerName; foreach (var thisItem in locationCombo.Items) { if ((string)thisItem == IDs.Locations.GetRoomString(saveFile.Location)) { locationCombo.SelectedIndex = locationCombo.Items.IndexOf(thisItem); } } LOVECombo.SelectedIndex = saveFile.LOVE - 1; killsBox.Text = saveFile.KillCount.ToString(); GOLDBox.Text = saveFile.GOLD.ToString(); setComboIndexFromLoad(weaponCombo, saveFile.Weapon); setComboIndexFromLoad(armorCombo, saveFile.Armor); HPBox.Text = saveFile.HP.ToString(); friskATBox.Text = saveFile.friskAT.ToString(); friskDFBox.Text = saveFile.friskDF.ToString(); weaponATBox.Text = saveFile.weaponAT.ToString(); armorDFBox.Text = saveFile.armorDF.ToString(); for (int i = 0; i < saveFile.inventoryItems.Length; i++) //Can this be improved like how we handle setting the save? { int item = saveFile.inventoryItems[i]; ComboBox currentComboBox = new ComboBox(); switch (i) { case 0: currentComboBox = item1Combo; break; case 1: currentComboBox = item2Combo; break; case 2: currentComboBox = item3Combo; break; case 3: currentComboBox = item4Combo; break; case 4: currentComboBox = item5Combo; break; case 5: currentComboBox = item6Combo; break; case 6: currentComboBox = item7Combo; break; case 7: currentComboBox = item8Combo; break; } foreach (var thisItem in currentComboBox.Items) { if ((string)thisItem == IDs.GetStringValue(item)) { currentComboBox.SelectedIndex = currentComboBox.Items.IndexOf(thisItem); } } } torielCheck.IsChecked = false; papyrusCheck.IsChecked = false; boxACheck.IsChecked = false; boxBCheck.IsChecked = false; foreach (var phoneItem in saveFile.phoneItems) { switch (phoneItem) { case 206: torielCheck.IsChecked = true; break; case 210: papyrusCheck.IsChecked = true; break; case 220: boxACheck.IsChecked = true; break; case 221: boxBCheck.IsChecked = true; break; } } loading = false; saveNameBox.Text = saveFile.SaveName; thisSave = saveFile; }
//readSaveFile is responsible for reading file0 and converting or casting its string values to our variable data types //We can then use this to setup the editor UI as well as edit data for this specific save private static SAVEFile readSaveFile(string saveFileDirectory) { string ReadLine(int lineNumber) { return(File.ReadLines(saveFileDirectory + "//file0").Skip(lineNumber - 1).Take(1).First().Replace(" ", String.Empty)); } SAVEFile currentSave = new SAVEFile(); //We read the line passed into ReadLine as a parameter and set the variable to the value read, as well as casting/converting as needed currentSave.PlayerName = ReadLine(1); currentSave.LOVE = Convert.ToInt16(ReadLine(2)); currentSave.HP = Convert.ToInt16(ReadLine(3)); currentSave.friskAT = Convert.ToInt16(ReadLine(5)); currentSave.weaponAT = Convert.ToInt16(ReadLine(6)); currentSave.friskDF = Convert.ToInt16(ReadLine(7)); currentSave.armorDF = Convert.ToInt16(ReadLine(8)); currentSave.EXP = Convert.ToInt32(ReadLine(10)); currentSave.GOLD = Convert.ToInt16(ReadLine(11)); currentSave.KillCount = Convert.ToInt16(ReadLine(12)); currentSave.inventoryItems[0] = Convert.ToInt16(ReadLine(13)); currentSave.phoneItems[0] = Convert.ToInt16(ReadLine(14)); currentSave.inventoryItems[1] = Convert.ToInt16(ReadLine(15)); currentSave.phoneItems[1] = Convert.ToInt16(ReadLine(16)); currentSave.inventoryItems[2] = Convert.ToInt16(ReadLine(17)); currentSave.phoneItems[2] = Convert.ToInt16(ReadLine(18)); currentSave.inventoryItems[3] = Convert.ToInt16(ReadLine(19)); currentSave.phoneItems[3] = Convert.ToInt16(ReadLine(20)); currentSave.inventoryItems[4] = Convert.ToInt16(ReadLine(21)); currentSave.inventoryItems[5] = Convert.ToInt16(ReadLine(23)); currentSave.inventoryItems[6] = Convert.ToInt16(ReadLine(25)); currentSave.inventoryItems[7] = Convert.ToInt16(ReadLine(27)); currentSave.Weapon = IDs.GetID(ReadLine(29)); currentSave.Armor = IDs.GetID(ReadLine(30)); currentSave.asrielDefeated = Convert.ToBoolean(Convert.ToInt16(ReadLine(38))); currentSave.randomCountersDisabled = Convert.ToBoolean(Convert.ToInt16(ReadLine(39))); currentSave.ruinsDummyState = (CharacterStates)(Convert.ToInt16(ReadLine(45))); currentSave.torielState = (CharacterStates)(Convert.ToInt16(ReadLine(76))); currentSave.doggoState = (CharacterStates)(Convert.ToInt16(ReadLine(83))); currentSave.dogamyState = (CharacterStates)(Convert.ToInt16(ReadLine(84))); currentSave.greaterDogState = (CharacterStates)(Convert.ToInt16(ReadLine(85))); currentSave.comedianState = (CharacterStates)(Convert.ToInt16(ReadLine(88))); currentSave.papyrusState = (CharacterStates)(Convert.ToInt16(ReadLine(98))); currentSave.shyrenState = (CharacterStates)(Convert.ToInt16(ReadLine(112))); currentSave.papyrusDated = (DateStates)(Convert.ToInt16(ReadLine(119))); currentSave.KillCount = Convert.ToInt16(ReadLine(232)); currentSave.ruinsKills = Convert.ToInt16(ReadLine(233)); currentSave.snowdinKills = Convert.ToInt16(ReadLine(234)); currentSave.waterfallKills = Convert.ToInt16(ReadLine(235)); currentSave.hotlandKills = Convert.ToInt16(ReadLine(236)); currentSave.undyneState = (CharacterStates)(Convert.ToInt16(ReadLine(282))); currentSave.madDummyState = (CharacterStates)(Convert.ToInt16(ReadLine(283))); currentSave.undyneState = (CharacterStates)(Convert.ToInt16(ReadLine(381))); currentSave.undyneDated = (DateStates)(Convert.ToInt16(ReadLine(420))); currentSave.disableAlphysCalls = Convert.ToBoolean(Convert.ToInt16(ReadLine(399))); currentSave.muffetState = (CharacterStates)(Convert.ToInt16(ReadLine(428))); currentSave.disableHotlandPuzzles = Convert.ToBoolean(Convert.ToInt16(ReadLine(431))); currentSave.broGuardsState = (CharacterStates)(Convert.ToInt16(ReadLine(433))); currentSave.coreElevatorUnlocked = Convert.ToBoolean(Convert.ToInt16(449)); currentSave.mettatonState = (CharacterStates)(Convert.ToInt16(ReadLine(456))); currentSave.insideCastle = Convert.ToBoolean(Convert.ToInt16(ReadLine(462))); currentSave.rodeCastleLift = Convert.ToBoolean(Convert.ToInt16(ReadLine(463))); currentSave.unlockedCastleChain = Convert.ToBoolean(Convert.ToInt16(ReadLine(485))); currentSave.undyneOnPhone = Convert.ToBoolean(Convert.ToInt16(ReadLine(496))); currentSave.beatTrueLab = Convert.ToBoolean(Convert.ToInt16(ReadLine(522))); currentSave.dateAlphysFlag = Convert.ToBoolean(Convert.ToInt16(ReadLine(523))); currentSave.pacifistStage = Convert.ToInt16(ReadLine(524)); currentSave.Plot = Convert.ToInt16(ReadLine(543)); currentSave.Location = Convert.ToInt16(ReadLine(548)); currentSave.SaveName = new DirectoryInfo(saveFileDirectory).Name; return(currentSave); }