Exemple #1
0
 private void ResetRandomizationCategories()
 {
     ModuleRando.Reset();
     ItemRando.Reset();
     SoundRando.Reset();
     ModelRando.Reset();
     TextureRando.Reset();
     TwodaRandom.Reset();
     TextRando.Reset();
     OtherRando.Reset();
 }
Exemple #2
0
        // Runs the necessary Randomization Scripts
        private void RunRando()
        {
            // Final check for already randomized game before randomizing.
            if (File.Exists(paths.RANDOMIZED_LOG))
            {
                RandomizationError = true;
                MessageBox.Show(Properties.Resources.AlreadyRandomized, Properties.Resources.RandomizationError);
                return;
            }

            // Determine Step size and throw error if no categories are selected.
            int ActiveCategories = CountActiveCategories();

            if (ActiveCategories == 0)
            {
                RandomizationError = true;
                MessageBox.Show(Properties.Resources.ErrorNoRandomization, Properties.Resources.RandomizationError);
                return;
            }
            ActiveCategories++;

            int step_size     = 100 / ActiveCategories;
            int curr_progress = 0;

            using (StreamWriter sw = new StreamWriter(paths.RANDOMIZED_LOG))
            {
                sw.WriteLine(DateTime.Now.ToString());
                sw.WriteLine(Properties.Resources.LogHeader);
                Properties.Settings.Default.KotorIsRandomized = true;
                Randomize.SetSeed(Properties.Settings.Default.Seed);    // Not sure when is the best time to set the seed.
                ResetRandomizationCategories();

                // Randomize the categories.
                try
                {
                    // Copy over custom appearance.2da to fix potential model and texture issues.
                    paths.BackUpOverrideDirectory();
                    File.WriteAllBytes(Path.Combine(paths.Override, "appearance.2da"), Properties.Resources.appearance);
                    File.WriteAllBytes(Path.Combine(paths.Override, "k_pdan_13_area.ncs"), Properties.Resources.k_pdan_13_area);

                    if (Properties.Settings.Default.DoRandomization_Module)
                    {
                        Randomize.RestartRng();
                        curr_task = Properties.Resources.RandomizingModules;
                        bwRandomizing.ReportProgress(curr_progress);
                        CreateModuleBackups();
                        ModuleRando.Module_rando(paths); // Run appropriate rando script.
                        sw.WriteLine(Properties.Resources.LogModulesDone);
                        curr_progress += step_size;
                    }
                    if (Properties.Settings.Default.DoRandomization_Item)
                    {
                        Randomize.RestartRng();
                        curr_task = Properties.Resources.RandomizingItems;
                        bwRandomizing.ReportProgress(curr_progress);
                        CreateItemBackups();
                        ItemRando.item_rando(paths); // Run appropriate rando script.
                        sw.WriteLine(Properties.Resources.LogItemsDone);
                        curr_progress += step_size;
                    }
                    if (Properties.Settings.Default.DoRandomization_Sound)
                    {
                        Randomize.RestartRng();
                        curr_task = Properties.Resources.RandomizingMusicSound;
                        bwRandomizing.ReportProgress(curr_progress);

                        // If music files are to be randomized, create backups.
                        if (Properties.Settings.Default.RandomizeAreaMusic != (int)RandomizationLevel.None ||
                            Properties.Settings.Default.RandomizeAmbientNoise != (int)RandomizationLevel.None ||
                            Properties.Settings.Default.RandomizeBattleMusic != (int)RandomizationLevel.None ||
                            Properties.Settings.Default.RandomizeCutsceneNoise != (int)RandomizationLevel.None ||
                            Properties.Settings.Default.RemoveDmcaMusic)
                        {
                            CreateMusicBackups();
                        }

                        // If sound files are to be randomized, create backups.
                        if (Properties.Settings.Default.RandomizeAmbientNoise != (int)RandomizationLevel.None ||
                            Properties.Settings.Default.RandomizeBattleMusic != (int)RandomizationLevel.None ||
                            Properties.Settings.Default.RandomizeNpcSounds != (int)RandomizationLevel.None ||
                            Properties.Settings.Default.RandomizePartySounds != (int)RandomizationLevel.None)
                        {
                            CreateSoundBackups();
                        }

                        SoundRando.sound_rando(paths); // Run appropriate rando script.
                        sw.WriteLine(Properties.Resources.LogMusicSoundDone);
                        curr_progress += step_size;
                    }
                    if (Properties.Settings.Default.DoRandomization_Model)
                    {
                        Randomize.RestartRng();
                        curr_task = Properties.Resources.RandomizingModels;
                        bwRandomizing.ReportProgress(curr_progress);
                        CreateModelBackups();
                        ModelRando.model_rando(paths); // Run appropriate rando script.
                        sw.WriteLine(Properties.Resources.LogModelsDone);
                        curr_progress += step_size;
                    }
                    if (Properties.Settings.Default.DoRandomization_Texture)
                    {
                        Randomize.RestartRng();
                        curr_task = Properties.Resources.RandomizingTextures;
                        bwRandomizing.ReportProgress(curr_progress);
                        CreateTextureBackups();
                        TextureRando.texture_rando(paths); // Run appropriate rando script.
                        sw.WriteLine(Properties.Resources.LogTexturesDone);
                        curr_progress += step_size;
                    }
                    if (Properties.Settings.Default.DoRandomization_TwoDA)
                    {
                        Randomize.RestartRng();
                        curr_task = Properties.Resources.Randomizing2DA;
                        bwRandomizing.ReportProgress(curr_progress);
                        CreateTwoDABackups();
                        TwodaRandom.Twoda_rando(paths); // Run appropriate rando script.
                        sw.WriteLine(Properties.Resources.Log2DADone);
                        curr_progress += step_size;
                    }
                    if (Properties.Settings.Default.DoRandomization_Text)
                    {
                        Randomize.RestartRng();
                        curr_task = Properties.Resources.RandomizingText;
                        bwRandomizing.ReportProgress(curr_progress);
                        CreateTextBackups();
                        TextRando.text_rando(paths); // Run appropriate rando script.
                        sw.WriteLine(Properties.Resources.LogTextDone);
                        curr_progress += step_size;
                    }
                    if (Properties.Settings.Default.DoRandomization_Other)
                    {
                        Randomize.RestartRng();
                        curr_task = Properties.Resources.RandomizingOther;
                        bwRandomizing.ReportProgress(curr_progress);
                        CreateOtherBackups();
                        OtherRando.other_rando(paths); // Run appropriate rando script.
                        sw.WriteLine(Properties.Resources.LogOtherDone);
                        curr_progress += step_size;
                    }
                }
                catch (Exception e)
                {
                    // Catch any randomization errors (e.g., reachability failure) and print a message.
                    RandomizationError = true;
                    MessageBox.Show($"Error encountered during randomization: {Environment.NewLine}{e.Message}", Properties.Resources.RandomizationError, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                finally
                {
                    // Creates a basic log file with a date, version, and things done.
                    curr_task = Properties.Resources.TaskFinishing;
                    bwRandomizing.ReportProgress(curr_progress);
                    sw.WriteLine("\nThe Kotor Randomizer was created by Lane Dibello, with help from Glasnonck, and the greater Kotor Speedrunning community.");
                    sw.WriteLine("If you encounter any issues please try to contact me @Lane#5847 on Discord");
                }
            }
            curr_progress += step_size;
        }
Exemple #3
0
        public void CreateSpoilerLogs()
        {
            int step_size     = 11; // Calculation: 100 / (8 categories + savepath)
            int curr_progress = 0;  //

            string spoilersPath = Path.Combine(Environment.CurrentDirectory, "Spoilers");

            //if (Directory.Exists(spoilersPath)) { Directory.Delete(spoilersPath, true); }
            Directory.CreateDirectory(spoilersPath);

            //var timestamp = DateTime.Now.ToString("yy-MM-dd_HH-mm-ss");
            var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
            var filename  = $"{timestamp}, Seed {Properties.Settings.Default.Seed}.xlsx";
            var path      = Path.Combine(spoilersPath, filename);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            try
            {
                using (var workbook = new XLWorkbook())
                {
                    curr_task = "Creating Spoilers - Item";
                    bwSpoilers.ReportProgress(curr_progress);
                    ItemRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Model";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    ModelRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Module";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    ModuleRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Music / Sound";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    SoundRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Other";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    OtherRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Text";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    TextRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Texture";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    TextureRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - 2DA";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    TwodaRandom.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Saving File";
                    bwSpoilers.ReportProgress(curr_progress += step_size);

                    // If any worksheets have been added, save the spoiler log.
                    if (workbook.Worksheets.Count > 0)
                    {
                        StringBuilder wsList = new StringBuilder();
                        foreach (var sheet in workbook.Worksheets)
                        {
                            wsList.Append($"{sheet.Name}, ");
                        }

                        wsList.Remove(wsList.Length - 2, 2);
                        workbook.SaveAs(path);

                        SpoilerCreated = true;
                    }
                    else
                    {
                        SpoilerCreated = false;
                        SpoilerMessage = $"No spoilers created. Either the game has not been randomized, or the selected randomizations do not generate spoilers.";
                    }
                }
            }
            catch (Exception e)
            {
                SpoilerCreated = false;
                SpoilerMessage = $"Exception caught while creating spoilers: {e.ToString()}";
            }
        }
Exemple #4
0
        // Runs the necessary Randomization Scripts
        private void RunRando()
        {
            // Determine Step size and throw error if no categories are selected.
            int ActiveCategories = CountActiveCategories();

            if (ActiveCategories == 0)
            {
                MessageBox.Show(Properties.Resources.ErrorNoRandomization);
                return;
            }
            ActiveCategories++;

            int step_size     = 100 / ActiveCategories;
            int curr_progress = 0;

            using (StreamWriter sw = new StreamWriter(paths.RANDOMIZED_LOG))
            {
                sw.WriteLine(DateTime.Now.ToString());
                sw.WriteLine(Properties.Resources.LogHeader);
                Properties.Settings.Default.KotorIsRandomized = true;
                Randomize.SetSeed(Properties.Settings.Default.Seed);    // Not sure when is the best time to set the seed.

                // Randomize the categories.
                if (Properties.Settings.Default.DoRandomization_Module)
                {
                    Randomize.RestartRng();
                    curr_task = Properties.Resources.RandomizingModules;
                    bwRandomizing.ReportProgress(curr_progress);
                    CreateModuleBackups();
                    ModuleRando.Module_rando(paths); // Run appropriate rando script.
                    sw.WriteLine(Properties.Resources.LogModulesDone);
                    curr_progress += step_size;
                }
                if (Properties.Settings.Default.DoRandomization_Item)
                {
                    Randomize.RestartRng();
                    curr_task = Properties.Resources.RandomizingItems;
                    bwRandomizing.ReportProgress(curr_progress);
                    CreateItemBackups();
                    ItemRando.item_rando(paths); // Run appropriate rando script.
                    sw.WriteLine(Properties.Resources.LogItemsDone);
                    curr_progress += step_size;
                }
                if (Properties.Settings.Default.DoRandomization_Sound)
                {
                    Randomize.RestartRng();
                    curr_task = Properties.Resources.RandomizingMusicSound;
                    bwRandomizing.ReportProgress(curr_progress);
                    CreateSoundBackups();
                    SoundRando.sound_rando(paths); // Run appropriate rando script.
                    sw.WriteLine(Properties.Resources.LogMusicSoundDone);
                    curr_progress += step_size;
                }
                if (Properties.Settings.Default.DoRandomization_Model)
                {
                    Randomize.RestartRng();
                    curr_task = Properties.Resources.RandomizingModels;
                    bwRandomizing.ReportProgress(curr_progress);
                    CreateModelBackups();
                    ModelRando.model_rando(paths); // Run appropriate rando script.
                    sw.WriteLine(Properties.Resources.LogModelsDone);
                    curr_progress += step_size;
                }
                if (Properties.Settings.Default.DoRandomization_Texture)
                {
                    Randomize.RestartRng();
                    curr_task = Properties.Resources.RandomizingTextures;
                    bwRandomizing.ReportProgress(curr_progress);
                    CreateTextureBackups();
                    TextureRando.texture_rando(paths); // Run appropriate rando script.
                    sw.WriteLine(Properties.Resources.LogTexturesDone);
                    curr_progress += step_size;
                }
                if (Properties.Settings.Default.DoRandomization_TwoDA)
                {
                    Randomize.RestartRng();
                    curr_task = Properties.Resources.Randomizing2DA;
                    bwRandomizing.ReportProgress(curr_progress);
                    CreateTwoDABackups();
                    TwodaRandom.Twoda_rando(paths); // Run appropriate rando script.
                    sw.WriteLine(Properties.Resources.Log2DADone);
                    curr_progress += step_size;
                }
                if (Properties.Settings.Default.DoRandomization_Text)
                {
                    Randomize.RestartRng();
                    curr_task = Properties.Resources.RandomizingText;
                    bwRandomizing.ReportProgress(curr_progress);
                    CreateTextBackups();
                    // ** Not yet implemented. ** // Run appropriate rando script.
                    sw.WriteLine(Properties.Resources.LogTextDone);
                    curr_progress += step_size;
                }
                if (Properties.Settings.Default.DoRandomization_Other)
                {
                    Randomize.RestartRng();
                    curr_task = Properties.Resources.RandomizingOther;
                    bwRandomizing.ReportProgress(curr_progress);
                    CreateOtherBackups();
                    OtherRando.other_rando(paths); // Run appropriate rando script.
                    sw.WriteLine(Properties.Resources.LogOtherDone);
                    curr_progress += step_size;
                }

                // Creates a basic log file with a date, version, and things done.
                curr_task = Properties.Resources.TaskFinishing;
                bwRandomizing.ReportProgress(curr_progress);
                sw.WriteLine("\nThe Kotor Randomizer was created by Lane Dibello, with help from Glasnonck, and the greater Kotor Speedrunning community.");
                sw.WriteLine("If you encounter any issues please try to contact me @Lane#5847 on Discord");
            }
            curr_progress += step_size;
        }