Пример #1
0
 /// <summary>
 /// This sets up the seeding at program start.
 /// </summary>
 private void StartForm_Load(object sender, EventArgs e)
 {
     //Randomize.GenerateSeed();
     //Properties.Settings.Default.Seed = Randomize.Rng.Next();
     //Properties.Settings.Default.Seed = Randomize.Seed;
     Properties.Settings.Default.Seed = Randomize.GenerateSeed();
     Randomize.RestartRng();
 }
Пример #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;
        }
Пример #3
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;
        }