diff --git a/SWD2Randomizer/Form1.Designer.cs b/SWD2Randomizer/Form1.Designer.cs index 9bc31f7..4f6ea47 100644 --- a/SWD2Randomizer/Form1.Designer.cs +++ b/SWD2Randomizer/Form1.Designer.cs @@ -42,6 +42,10 @@ private void InitializeComponent() this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.logText = new System.Windows.Forms.TextBox(); + this.checkUpgrades = new System.Windows.Forms.CheckBox(); + this.checkResources = new System.Windows.Forms.CheckBox(); + this.checkAreas = new System.Windows.Forms.CheckBox(); + this.checkItems = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); @@ -82,7 +86,7 @@ private void InitializeComponent() // // randomizeBtn // - this.randomizeBtn.Location = new System.Drawing.Point(9, 45); + this.randomizeBtn.Location = new System.Drawing.Point(9, 72); this.randomizeBtn.Name = "randomizeBtn"; this.randomizeBtn.Size = new System.Drawing.Size(75, 23); this.randomizeBtn.TabIndex = 3; @@ -101,7 +105,7 @@ private void InitializeComponent() // // restoreBtn // - this.restoreBtn.Location = new System.Drawing.Point(90, 45); + this.restoreBtn.Location = new System.Drawing.Point(90, 72); this.restoreBtn.Name = "restoreBtn"; this.restoreBtn.Size = new System.Drawing.Size(75, 23); this.restoreBtn.TabIndex = 5; @@ -161,6 +165,10 @@ private void InitializeComponent() // groupBox2 // this.groupBox2.Controls.Add(this.logText); + this.groupBox2.Controls.Add(this.checkItems); + this.groupBox2.Controls.Add(this.checkAreas); + this.groupBox2.Controls.Add(this.checkResources); + this.groupBox2.Controls.Add(this.checkUpgrades); this.groupBox2.Controls.Add(this.seedLabel); this.groupBox2.Controls.Add(this.textSeed); this.groupBox2.Controls.Add(this.randomizeBtn); @@ -172,21 +180,70 @@ private void InitializeComponent() this.groupBox2.Size = new System.Drawing.Size(590, 253); this.groupBox2.TabIndex = 11; this.groupBox2.TabStop = false; + this.groupBox2.Enter += new System.EventHandler(this.groupBox2_Enter); // // logText // - this.logText.Location = new System.Drawing.Point(9, 79); + this.logText.Location = new System.Drawing.Point(0, 101); this.logText.Multiline = true; this.logText.Name = "logText"; this.logText.ReadOnly = true; - this.logText.Size = new System.Drawing.Size(575, 168); + this.logText.Size = new System.Drawing.Size(575, 152); this.logText.TabIndex = 10; // + // checkUpgrades + // + this.checkUpgrades.AutoSize = true; + this.checkUpgrades.Checked = true; + this.checkUpgrades.CheckState = System.Windows.Forms.CheckState.Checked; + this.checkUpgrades.Location = new System.Drawing.Point(369, 49); + this.checkUpgrades.Name = "checkUpgrades"; + this.checkUpgrades.Size = new System.Drawing.Size(126, 17); + this.checkUpgrades.TabIndex = 10; + this.checkUpgrades.Text = "Randomize upgrades"; + this.checkUpgrades.UseVisualStyleBackColor = true; + // + // checkResources + // + this.checkResources.AutoSize = true; + this.checkResources.Checked = true; + this.checkResources.CheckState = System.Windows.Forms.CheckState.Checked; + this.checkResources.Location = new System.Drawing.Point(235, 49); + this.checkResources.Name = "checkResources"; + this.checkResources.Size = new System.Drawing.Size(128, 17); + this.checkResources.TabIndex = 10; + this.checkResources.Text = "Randomize resources"; + this.checkResources.UseVisualStyleBackColor = true; + // + // checkAreas + // + this.checkAreas.AutoSize = true; + this.checkAreas.Checked = true; + this.checkAreas.CheckState = System.Windows.Forms.CheckState.Checked; + this.checkAreas.Location = new System.Drawing.Point(121, 49); + this.checkAreas.Name = "checkAreas"; + this.checkAreas.Size = new System.Drawing.Size(108, 17); + this.checkAreas.TabIndex = 10; + this.checkAreas.Text = "Randomize areas"; + this.checkAreas.UseVisualStyleBackColor = true; + // + // checkItems + // + this.checkItems.AutoSize = true; + this.checkItems.Checked = true; + this.checkItems.CheckState = System.Windows.Forms.CheckState.Checked; + this.checkItems.Location = new System.Drawing.Point(9, 49); + this.checkItems.Name = "checkItems"; + this.checkItems.Size = new System.Drawing.Size(106, 17); + this.checkItems.TabIndex = 10; + this.checkItems.Text = "Randomize items"; + this.checkItems.UseVisualStyleBackColor = true; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(614, 349); + this.ClientSize = new System.Drawing.Size(613, 356); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = "Form1"; @@ -215,6 +272,10 @@ private void InitializeComponent() private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.TextBox logText; + private System.Windows.Forms.CheckBox checkUpgrades; + private System.Windows.Forms.CheckBox checkItems; + private System.Windows.Forms.CheckBox checkAreas; + private System.Windows.Forms.CheckBox checkResources; } } diff --git a/SWD2Randomizer/Form1.cs b/SWD2Randomizer/Form1.cs index 8ae9f86..d95c18d 100644 --- a/SWD2Randomizer/Form1.cs +++ b/SWD2Randomizer/Form1.cs @@ -104,15 +104,34 @@ private void randomizeBtn_Click(object sender, EventArgs e) string zipFile = Path.Combine(Directory.GetCurrentDirectory(), "data01.impak.zip"); string extractedDir = Path.Combine(Directory.GetCurrentDirectory(), "data01"); + string enfile = Path.Combine(baseDir, "Language", "en.csv.z"); + using (FileStream originalFileStream = File.OpenRead(enfile)) + { + originalFileStream.Seek(6, SeekOrigin.Begin); + string newFileName = enfile.Remove(enfile.Length - 2); + + using (FileStream decompressedFileStream = File.Create(newFileName)) + { + using (DeflateStream decompressionStream = new DeflateStream(originalFileStream, CompressionMode.Decompress)) + { + decompressionStream.CopyTo(decompressedFileStream); + } + } + } + StringBuilder logsb = new StringBuilder(); /* Generate a new seed if blank */ if (string.IsNullOrWhiteSpace(textSeed.Text)) { - SetSeedBasedOnDifficulty(); + SetSeedBasedOnSettings(); + } + else + { + GetSettingsFromSeed(); } - string difficulty = GetRandomizerDifficulty(); + string difficulty = listDifficulty.SelectedItem.ToString(); logsb.Append("Selecting difficulty is ").AppendLine(difficulty); logText.Text = logsb.ToString(); @@ -206,7 +225,7 @@ private void randomizeBtn_Click(object sender, EventArgs e) locations = new LocationsCasual().Locations; } - Randomizer randomizer = new Randomizer(extractedDir, parsedSeed, locations); + Randomizer randomizer = new Randomizer(extractedDir, parsedSeed, locations, checkItems.Checked, checkAreas.Checked, checkResources.Checked, checkUpgrades.Checked); logsb.Append("Randomize"); logText.Text = logsb.ToString(); @@ -286,49 +305,58 @@ private void randomizeBtn_Click(object sender, EventArgs e) } - private void SetSeedBasedOnDifficulty() + private void SetSeedBasedOnSettings() { + textSeed.Text = ""; switch (listDifficulty.SelectedItem.ToString()) { case "Casual": - textSeed.Text = string.Format("C{0:0000000}", (new SeedRandom()).Next(10000000)); + textSeed.Text += "C"; break; default: - textSeed.Text = string.Format("S{0:0000000}", (new SeedRandom()).Next(10000000)); + textSeed.Text += "S"; break; } + if (checkItems.Checked) { textSeed.Text += "I"; } + if (checkAreas.Checked) { textSeed.Text += "A"; } + if (checkResources.Checked) { textSeed.Text += "R"; } + if (checkUpgrades.Checked) { textSeed.Text += "U"; } + + textSeed.Text += string.Format("{0:0000000}", (new SeedRandom()).Next(10000000)); } - private string GetRandomizerDifficulty() + private void GetSettingsFromSeed() { - string difficulty = "Speedrunner"; - if (textSeed.Text.ToUpper().Contains("C")) { - difficulty = "Casual"; + listDifficulty.SelectedItem = "Casual"; } else if (textSeed.Text.ToUpper().Contains("S")) { - difficulty = "Speedrunner"; + listDifficulty.SelectedItem = "Speedrunner"; } - listDifficulty.SelectedItem = difficulty; - - return difficulty; + checkItems.Checked = textSeed.Text.ToUpper().Contains("I"); + checkAreas.Checked = textSeed.Text.ToUpper().Contains("A"); + checkResources.Checked = textSeed.Text.ToUpper().Contains("R"); + checkUpgrades.Checked = textSeed.Text.ToUpper().Contains("U"); } private string GetSeed() { - if (textSeed.Text.ToUpper().Contains("C")) - { - return textSeed.Text.ToUpper().Replace("C", ""); - } - else if (textSeed.Text.ToUpper().Contains("S")) - { - return textSeed.Text.ToUpper().Replace("S", ""); - } - MessageBox.Show("The seed string is unrecognized.", "Seed Difficulty", MessageBoxButtons.OK, MessageBoxIcon.Error); - return ""; + string seed = textSeed.Text.ToUpper(); + seed = seed.Replace("C", ""); + seed = seed.Replace("S", ""); + seed = seed.Replace("I", ""); + seed = seed.Replace("A", ""); + seed = seed.Replace("R", ""); + seed = seed.Replace("U", ""); + return seed; + } + + private void groupBox2_Enter(object sender, EventArgs e) + { + } } } diff --git a/SWD2Randomizer/Patcher.cs b/SWD2Randomizer/Patcher.cs index b89f7fd..4823551 100644 --- a/SWD2Randomizer/Patcher.cs +++ b/SWD2Randomizer/Patcher.cs @@ -90,7 +90,7 @@ public void PatchOasis() } XmlNode hubIntro = doc.SelectSingleNode("//Level[@Name='the_hub']/LayerFilters/Filter[@Layer='filter_intro']"); - hubIntro.ParentNode.RemoveChild(hubIntro); + hubIntro.InnerXml = @""; XmlNode hubPostIntro = doc.SelectSingleNode("//Level[@Name='the_hub']/LayerFilters/Filter[@Layer='filter_post_intro']"); hubPostIntro.InnerXml = @" @@ -288,7 +288,7 @@ public void PatchIntro() checkQuestProp.InnerXml = @" 32566045 - ProgressQuest5 + ProgressQuest6 2389, 2036 ProgressQuest 2280, 2004, 216, 63 diff --git a/SWD2Randomizer/Randomizer.cs b/SWD2Randomizer/Randomizer.cs index c886e8d..17234ed 100644 --- a/SWD2Randomizer/Randomizer.cs +++ b/SWD2Randomizer/Randomizer.cs @@ -12,13 +12,21 @@ class Randomizer private readonly int seed; private List haveFlags; private List locations; + private bool items; + private bool areas; + private bool resources; + private bool upgrades; - public Randomizer(string baseDir, int seed, List locations) + public Randomizer(string baseDir, int seed, List locations, bool items, bool areas, bool resources, bool upgrades) { random = new SeedRandom(seed); this.locations = locations; this.seed = seed; this.baseDir = baseDir; + this.items = items; + this.areas = areas; + this.resources = resources; + this.upgrades = upgrades; haveFlags = new List(); } @@ -26,11 +34,17 @@ public int Randomize() { bool ret; - ret = PermuteFlags(Location.RandomizeType.Upgrade); - if (!ret) return -1; + if (items) + { + ret = PermuteFlags(Location.RandomizeType.Upgrade); + if (!ret) return -1; + } - ret = PermuteFlags(Location.RandomizeType.Area); - if (!ret) return -1; + if (areas) + { + ret = PermuteFlags(Location.RandomizeType.Area); + if (!ret) return -1; + } ret = CheckValid(); if (!ret) return 0; @@ -168,8 +182,15 @@ public int Randomize() doc.Save(patchFile); } - RandomizeResources(); - RandomizeCogUpgrades(); + if (resources) + { + RandomizeResources(); + } + + if (upgrades) + { + RandomizeCogUpgrades(); + } return 1; }