Beispiel #1
0
        public static void Twoda_rando(KPaths paths)
        {
            BIF b = new BIF(Path.Combine(paths.data, "2da.bif"));
            KEY k = new KEY(paths.chitin_backup);

            b.AttachKey(k, "data\\2da.bif");

            foreach (BIF.VariableResourceEntry VRE in b.VariableResourceTable.Where(x => Globals.Selected2DAs.Keys.Contains(x.ResRef)))
            {
                TwoDA t = new TwoDA(VRE.EntryData, VRE.ResRef);

                foreach (string col in Globals.Selected2DAs[VRE.ResRef])
                {
                    Randomize.FisherYatesShuffle(t.Data[col]);
                }

                t.WriteToDirectory(paths.Override);
            }
        }
 private static void RandomizeSoundActions(List <FileInfo> files, string outPath)
 {
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundAttack.IsMatch(f.Name)), outPath);       // ATK
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundBattle.IsMatch(f.Name)), outPath);       // BAT
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundLockAttempt.IsMatch(f.Name)), outPath);  // BLOCK
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundCriticalHit.IsMatch(f.Name)), outPath);  // CRIT
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundDead.IsMatch(f.Name)), outPath);         // DEAD
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundMineFound.IsMatch(f.Name)), outPath);    // DMIN
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundLockFailure.IsMatch(f.Name)), outPath);  // FLOCK
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundHit.IsMatch(f.Name)), outPath);          // HIT
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundMineSet.IsMatch(f.Name)), outPath);      // LMIN
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundLowHealth.IsMatch(f.Name)), outPath);    // LOW
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundMedicine.IsMatch(f.Name)), outPath);     // MED
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundPoison.IsMatch(f.Name)), outPath);       // POIS
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundSoloOff.IsMatch(f.Name)), outPath);      // RPRTY
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundSelect.IsMatch(f.Name)), outPath);       // SLCT
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundLockSuccess.IsMatch(f.Name)), outPath);  // SLOCK
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundSoloOn.IsMatch(f.Name)), outPath);       // SPRTY
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundSearch.IsMatch(f.Name)), outPath);       // SRCH
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundStealth.IsMatch(f.Name)), outPath);      // STLH
     Randomize.RandomizeFiles(files.Where(f => SuffixSoundIneffective.IsMatch(f.Name)), outPath);  // TIA
 }
Beispiel #3
0
        /// <summary>
        /// LookupTable is created from the global BoundModules after shuffling included modules.
        /// </summary>
        private static void CreateLookupTableShuffle()
        {
            List <string> excluded = Globals.BoundModules.Where(x => x.Omitted).Select(x => x.Code).ToList();
            List <string> included = Globals.BoundModules.Where(x => !x.Omitted).Select(x => x.Code).ToList();

            // Shuffle the list of included modules.
            List <string> shuffle = new List <string>(included);

            Randomize.FisherYatesShuffle(shuffle);
            LookupTable.Clear();

            for (int i = 0; i < included.Count; i++)
            {
                LookupTable.Add(included[i], shuffle[i]);
            }

            // Include the unmodified list of excluded modules.
            foreach (string name in excluded)
            {
                LookupTable.Add(name, name);
            }
        }
Beispiel #4
0
 /// <summary>
 /// This sets up the seeding at program start.
 /// </summary>
 private void StartForm_Load(object sender, EventArgs e)
 {
     Properties.Settings.Default.Seed = Randomize.GenerateSeed();
     Randomize.RestartRng();
 }
Beispiel #5
0
        public static void item_rando(KPaths paths)
        {
            // Prepare lists for new randomization.
            Max_Rando.Clear();
            Type_Lists.Clear();
            LookupTable.Clear();

            // Load KEY file.
            KEY k = new KEY(paths.chitin);

            // Handle categories
            HandleCategory(k, ArmbandsRegs, Properties.Settings.Default.RandomizeArmbands);
            HandleCategory(k, ArmorRegs, Properties.Settings.Default.RandomizeArmor);
            HandleCategory(k, BeltsRegs, Properties.Settings.Default.RandomizeBelts);
            HandleCategory(k, BlastersRegs, Properties.Settings.Default.RandomizeBlasters);
            HandleCategory(k, HidesRegs, Properties.Settings.Default.RandomizeHides);
            HandleCategory(k, CreatureRegs, Properties.Settings.Default.RandomizeCreature);
            HandleCategory(k, DroidRegs, Properties.Settings.Default.RandomizeDroid);
            HandleCategory(k, GlovesRegs, Properties.Settings.Default.RandomizeGloves);
            HandleCategory(k, GrenadesRegs, Properties.Settings.Default.RandomizeGrenades);
            HandleCategory(k, ImplantsRegs, Properties.Settings.Default.RandomizeImplants);
            HandleCategory(k, LightsabersRegs, Properties.Settings.Default.RandomizeLightsabers);
            HandleCategory(k, MaskRegs, Properties.Settings.Default.RandomizeMask);
            HandleCategory(k, MeleeRegs, Properties.Settings.Default.RandomizeMelee);
            HandleCategory(k, MinesRegs, Properties.Settings.Default.RandomizeMines);
            HandleCategory(k, PazRegs, Properties.Settings.Default.RandomizePaz);
            HandleCategory(k, StimsRegs, Properties.Settings.Default.RandomizeStims);
            HandleCategory(k, UpgradeRegs, Properties.Settings.Default.RandomizeUpgrade);

            // Handle Various
            switch (Properties.Settings.Default.RandomizeVarious)
            {
            default:
            case RandomizationLevel.None:
                break;

            case RandomizationLevel.Type:
                List <string> type = new List <string>(k.KeyTable.Where(x => Matches_None(x.ResRef) && !Is_Forbidden(x.ResRef) && x.ResourceType == (short)ResourceType.UTI).Select(x => x.ResRef));
                Type_Lists.Add(type);
                break;

            case RandomizationLevel.Max:
                Max_Rando.AddRange(k.KeyTable.Where(x => Matches_None(x.ResRef) && !Is_Forbidden(x.ResRef) && x.ResourceType == (short)ResourceType.UTI).Select(x => x.ResRef));
                break;
            }

            // Omitted Items
            foreach (var item in Globals.OmitItems)
            {
                LookupTable.Add(new Tuple <string, string>(item, item));
            }

            // Max Rando
            List <string> Max_Rando_Iterator = new List <string>(Max_Rando);

            Randomize.FisherYatesShuffle(Max_Rando);
            int j = 0;

            foreach (KEY.KeyEntry ke in k.KeyTable.Where(x => Max_Rando_Iterator.Contains(x.ResRef)))
            {
                LookupTable.Add(new Tuple <string, string>(ke.ResRef, Max_Rando[j]));
                ke.ResRef = Max_Rando[j];
                j++;
            }

            // Type Rando
            foreach (List <string> li in Type_Lists)
            {
                List <string> type_copy = new List <string>(li);
                Randomize.FisherYatesShuffle(type_copy);
                j = 0;
                foreach (KEY.KeyEntry ke in k.KeyTable.Where(x => li.Contains(x.ResRef)))
                {
                    LookupTable.Add(new Tuple <string, string>(ke.ResRef, type_copy[j]));
                    ke.ResRef = type_copy[j];
                    j++;
                }
            }

            k.WriteToFile(paths.chitin);
        }
Beispiel #6
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;
        }
Beispiel #7
0
        public static void texture_rando(KPaths paths)
        {
            // Prepare lists for new randomization.
            MaxRando.Clear();
            TypeLists.Clear();

            // Load in texture pack.
            string pack_name;

            switch (Properties.Settings.Default.TexturePack)
            {
            default:
            case TexturePack.HighQuality:
                pack_name = "\\swpc_tex_tpa.erf";
                break;

            case TexturePack.MedQuality:
                pack_name = "\\swpc_tex_tpb.erf";
                break;

            case TexturePack.LowQuality:
                pack_name = "\\swpc_tex_tpc.erf";
                break;
            }

            ERF e = new ERF(paths.TexturePacks + pack_name);

            foreach (var key in e.Key_List)
            {
                if (!NameLookup.ContainsKey(key.ResID))
                {
                    NameLookup.Add(key.ResID, key.ResRef);
                }
            }

            // Handle categories.
            HandleCategory(e, RegexCubeMaps, Properties.Settings.Default.TextureRandomizeCubeMaps);
            HandleCategory(e, RegexCreatures, Properties.Settings.Default.TextureRandomizeCreatures);
            HandleCategory(e, RegexEffects, Properties.Settings.Default.TextureRandomizeEffects);
            HandleCategory(e, RegexItems, Properties.Settings.Default.TextureRandomizeItems);
            HandleCategory(e, RegexPlanetary, Properties.Settings.Default.TextureRandomizePlanetary);
            HandleCategory(e, RegexNPC, Properties.Settings.Default.TextureRandomizeNPC);
            HandleCategory(e, RegexPlayHeads, Properties.Settings.Default.TextureRandomizePlayHeads);
            HandleCategory(e, RegexPlayBodies, Properties.Settings.Default.TextureRandomizePlayBodies);
            HandleCategory(e, RegexPlaceables, Properties.Settings.Default.TextureRandomizePlaceables);
            HandleCategory(e, RegexParty, Properties.Settings.Default.TextureRandomizeParty);
            HandleCategory(e, RegexStunt, Properties.Settings.Default.TextureRandomizeStunt);
            HandleCategory(e, RegexVehicles, Properties.Settings.Default.TextureRandomizeVehicles);
            HandleCategory(e, RegexWeapons, Properties.Settings.Default.TextureRandomizeWeapons);

            // Handle other.
            switch (Properties.Settings.Default.TextureRandomizeOther)
            {
            default:
            case RandomizationLevel.None:
                break;     // Do nothing.

            case RandomizationLevel.Type:
                List <int> type = new List <int>(e.Key_List.Where(x => Matches_None(x.ResRef) && !Is_Forbidden(x.ResRef)).Select(x => x.ResID));
                TypeLists.Add(type);
                break;

            case RandomizationLevel.Max:
                MaxRando.AddRange(e.Key_List.Where(x => Matches_None(x.ResRef) && !Is_Forbidden(x.ResRef)).Select(x => x.ResID));
                break;
            }

            // Max Rando.
            List <int> Max_Rando_Iterator = new List <int>(MaxRando);

            Randomize.FisherYatesShuffle(MaxRando);
            int j = 0;

            foreach (ERF.Key k in e.Key_List.Where(x => Max_Rando_Iterator.Contains(x.ResID)))
            {
                LookupTable.Add(k.ResID, MaxRando[j]);
                k.ResID = MaxRando[j];
                j++;
            }

            // Type Rando.
            foreach (List <int> li in TypeLists)
            {
                List <int> type_copy = new List <int>(li);
                Randomize.FisherYatesShuffle(type_copy);
                j = 0;
                foreach (ERF.Key k in e.Key_List.Where(x => li.Contains(x.ResID)))
                {
                    LookupTable.Add(k.ResID, type_copy[j]);
                    k.ResID = type_copy[j];
                    j++;
                }
            }

            e.WriteToFile(paths.TexturePacks + pack_name);
        }
        // Populates and shuffles the the modules flagged to be randomized. Returns true if override files should be added.
        public static void Module_rando(KPaths paths)
        {
            // Set up the bound module collection if it hasn't been already.
            if (!Properties.Settings.Default.ModulesInitialized)
            {
                Globals.BoundModules.Clear();
                foreach (string s in Globals.MODULES)
                {
                    Globals.BoundModules.Add(new Globals.Mod_Entry(s, true));
                }
                Properties.Settings.Default.ModulesInitialized = true;
            }

            //if (!Properties.Settings.Default.ModulePresetSelected)
            //{
            //    //Figure something out here
            //}

            // Split the Bound modules into their respective lists.
            List <string> ExcludedModules = Globals.BoundModules.Where(x => x.Omitted).Select(x => x.Name).ToList();
            List <string> IncludedModules = Globals.BoundModules.Where(x => !x.Omitted).Select(x => x.Name).ToList();

            // Shuffle the list of included modules.
            List <string> ShuffledModules = IncludedModules.ToList();

            Randomize.FisherYatesShuffle(ShuffledModules);

            // Copy shuffled modules into the base directory.
            Dictionary <string, string> LookupTable = new Dictionary <string, string>();  // Create lookup table to find a given module's new "name".

            for (int i = 0; i < IncludedModules.Count; i++)
            {
                LookupTable.Add(IncludedModules[i], ShuffledModules[i]);
                File.Copy($"{paths.modules_backup}{IncludedModules[i]}.rim", $"{paths.modules}{ShuffledModules[i]}.rim", true);
                File.Copy($"{paths.modules_backup}{IncludedModules[i]}_s.rim", $"{paths.modules}{ShuffledModules[i]}_s.rim", true);
                File.Copy($"{paths.lips_backup}{IncludedModules[i]}_loc.mod", $"{paths.lips}{ShuffledModules[i]}_loc.mod", true);
            }

            // Copy excluded, untouched modules into the base directory.
            foreach (string name in ExcludedModules)
            {
                LookupTable.Add(name, name);
                File.Copy($"{paths.modules_backup}{name}.rim", $"{paths.modules}{name}.rim", true);
                File.Copy($"{paths.modules_backup}{name}_s.rim", $"{paths.modules}{name}_s.rim", true);
                File.Copy($"{paths.lips_backup}{name}_loc.mod", $"{paths.lips}{name}_loc.mod", true);
            }

            // Copy lips extras into the base directory.
            foreach (string name in Globals.lipXtras)
            {
                File.Copy($"{paths.lips_backup}{name}", $"{paths.lips}{name}", true);
            }

            // Write additional override files.
            string       moduleSavePath = Path.Combine(paths.Override, TwoDA_MODULE_SAVE);
            ModuleExtras saveFileExtras = Properties.Settings.Default.ModuleExtrasValue & (ModuleExtras.SaveAllModules | ModuleExtras.SaveMiniGames | ModuleExtras.NoSaveDelete);

            //if (0 == (saveFileExtras ^ (ModuleExtras.Default)))
            //{
            //    // 0b000 - Milestone Delete (Default)
            //    // Do nothing.
            //}

            if (0 == (saveFileExtras ^ (ModuleExtras.NoSaveDelete)))
            {
                // 0b001 - No Milestone Delete
                File.WriteAllBytes(moduleSavePath, Properties.Resources.NODELETE_modulesave);
            }

            if (0 == (saveFileExtras ^ (ModuleExtras.SaveMiniGames)))
            {
                // 0b010 - Include Minigames | Milestone Delete
                File.WriteAllBytes(moduleSavePath, Properties.Resources.MGINCLUDED_modulesave);
            }

            if (0 == (saveFileExtras ^ (ModuleExtras.NoSaveDelete | ModuleExtras.SaveMiniGames)))
            {
                // 0b011 - Include Minigames | No Milestone Delete
                File.WriteAllBytes(moduleSavePath, Properties.Resources.NODELETE_MGINCLUDED_modulesave);
            }

            if (0 == (saveFileExtras ^ (ModuleExtras.SaveAllModules)) ||
                0 == (saveFileExtras ^ (ModuleExtras.SaveMiniGames | ModuleExtras.SaveAllModules)))
            {
                // Treat both the same.
                // 0b100 - Include All Modules | Milestone Delete
                // 0b110 - Include All Modules | Include Minigames | Milestone Delete
                File.WriteAllBytes(moduleSavePath, Properties.Resources.ALLINCLUDED_modulesave);
            }

            if (0 == (saveFileExtras ^ (ModuleExtras.NoSaveDelete | ModuleExtras.SaveAllModules)) ||
                0 == (saveFileExtras ^ (ModuleExtras.NoSaveDelete | ModuleExtras.SaveMiniGames | ModuleExtras.SaveAllModules)))
            {
                // Treat both the same.
                // 0b101 - Include All Modules | No Milestone Delete
                // 0b111 - Include All Modules | Include Minigames | No Milestone Delete
                File.WriteAllBytes(moduleSavePath, Properties.Resources.NODELETE_ALLINCLUDED_modulesave);
            }

            if (Properties.Settings.Default.ModuleExtrasValue.HasFlag(ModuleExtras.FixDream))
            {
                File.WriteAllBytes(Path.Combine(paths.Override, FIXED_DREAM_OVERRIDE), Properties.Resources.k_ren_visionland);
            }

            if (Properties.Settings.Default.ModuleExtrasValue.HasFlag(ModuleExtras.UnlockGalaxyMap))
            {
                File.WriteAllBytes(Path.Combine(paths.Override, UNLOCK_MAP_OVERRIDE), Properties.Resources.k_pebn_galaxy);
            }

            // Fix warp coordinates.
            if (Properties.Settings.Default.ModuleExtrasValue.HasFlag(ModuleExtras.FixCoordinates))
            {
                // Create a lookup for modules needing coordinate fix with their newly shuffled FileInfos.
                var shuffleFileLookup = new Dictionary <string, FileInfo>();
                foreach (var key in Globals.FIXED_COORDINATES.Keys)
                {
                    shuffleFileLookup.Add(key, paths.FilesInModules.FirstOrDefault(fi => fi.Name.Contains(LookupTable[key])));
                }

                foreach (var kvp in shuffleFileLookup)
                {
                    // Set up objects.
                    RIM       r  = new RIM(kvp.Value.FullName);
                    RIM.rFile rf = r.File_Table.Where(x => x.TypeID == (int)ResourceType.IFO).FirstOrDefault();
                    GFF       g  = new GFF(rf.File_Data);

                    // Update coordinate data.
                    g.Field_Array.Where(x => x.Label == Properties.Resources.ModuleEntryX).FirstOrDefault().DataOrDataOffset = Globals.FIXED_COORDINATES[kvp.Key].Item1;
                    g.Field_Array.Where(x => x.Label == Properties.Resources.ModuleEntryY).FirstOrDefault().DataOrDataOffset = Globals.FIXED_COORDINATES[kvp.Key].Item2;
                    g.Field_Array.Where(x => x.Label == Properties.Resources.ModuleEntryZ).FirstOrDefault().DataOrDataOffset = Globals.FIXED_COORDINATES[kvp.Key].Item3;

                    // Write updated data to RIM file.
                    rf.File_Data = g.ToRawData();
                    r.WriteToFile(kvp.Value.FullName);
                }
            }

            // Fixed Rakata riddle Man in Mind Prison.
            if (Properties.Settings.Default.ModuleExtrasValue.HasFlag(ModuleExtras.FixMindPrison))
            {
                // Find the files associated with AREA_MYSTERY_BOX.
                var files = paths.FilesInModules.Where(fi => fi.Name.Contains(LookupTable[AREA_MYSTERY_BOX]));
                foreach (FileInfo fi in files)
                {
                    // Skip any files that don't end in "s.rim".
                    if (fi.Name[fi.Name.Length - 5] != 's')
                    {
                        continue;
                    }

                    // Check the RIM's File_Table for any rFiles labeled with LABEL_MIND_PRISON.
                    RIM r = new RIM(fi.FullName);
                    if (r.File_Table.Where(x => x.Label == LABEL_MIND_PRISON).Any())
                    {
                        bool offadjust = false;
                        foreach (RIM.rFile rf in r.File_Table)
                        {
                            // For the rFile with LABEL_MIND_PRISON, update the file data with the fix.
                            if (rf.Label == LABEL_MIND_PRISON)
                            {
                                rf.File_Data = Properties.Resources.g_brakatan003;
                                rf.DataSize += 192;
                                offadjust    = true;
                                continue;
                            }
                            // For rFiles after LABEL_MIND_PRISON, add the additional data offset.
                            if (offadjust)
                            {
                                rf.DataOffset += 192;
                            }
                        }

                        // Write updated RIM data to file.
                        r.WriteToFile(fi.FullName);
                    }
                }
            }
        }
Beispiel #9
0
        private static void RandomizeSoundActions(List <FileInfo> files, string outPath)
        {
            var actionList = files.Where(f => SuffixSoundAttack.IsMatch(f.Name)).ToList();
            var randList   = Randomize.RandomizeFiles(actionList, outPath); // ATK

            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundBattle.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // BAT
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundLockAttempt.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // BLOCK
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundCriticalHit.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // CRIT
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundDead.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // DEAD
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundMineFound.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // DMIN
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundLockFailure.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // FLOCK
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundHit.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // HIT
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundMineSet.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // LMIN
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundLowHealth.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // LOW
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundMedicine.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // MED
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundPoison.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // POIS
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundSoloOff.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // RPRTY
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundSelect.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // SLCT
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundLockSuccess.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // SLOCK
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundSoloOn.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // SPRTY
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundSearch.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // SRCH
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundStealth.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // STLH
            AddToSoundLookup(actionList, randList);

            actionList = files.Where(f => SuffixSoundIneffective.IsMatch(f.Name)).ToList();
            randList   = Randomize.RandomizeFiles(actionList, outPath);     // TIA
            AddToSoundLookup(actionList, randList);
        }
Beispiel #10
0
        public static void sound_rando(KPaths paths)
        {
            // Prepare lists for new randomization.
            MusicLookupTable.Clear();
            SoundLookupTable.Clear();

            // Get file collections
            List <FileInfo> maxMusic   = new List <FileInfo>();
            List <FileInfo> maxSound   = new List <FileInfo>();
            List <FileInfo> musicFiles = new List <FileInfo>();
            List <FileInfo> soundFiles = new List <FileInfo>();

            if (Directory.Exists(paths.music_backup))
            {
                musicFiles = paths.FilesInMusicBackup.ToList();
            }
            if (Directory.Exists(paths.sounds_backup))
            {
                soundFiles = paths.FilesInSoundsBackup.ToList();
            }

            // Area Music
            List <FileInfo> areaMusic = new List <FileInfo>();

            foreach (var prefix in PrefixListAreaMusic)
            {
                areaMusic.AddRange(musicFiles.Where(f => f.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)));
            }

            if (Properties.Settings.Default.RemoveDmcaMusic)
            {
                areaMusic.RemoveAll(f => DmcaAreaMusic.Contains(f.Name));   // Remove DMCA music from the area list.
            }

            switch (Properties.Settings.Default.RandomizeAreaMusic)
            {
            case RandomizationLevel.Max:
                maxMusic.AddRange(areaMusic);
                break;

            case RandomizationLevel.Type:
                var randList = Randomize.RandomizeFiles(areaMusic, paths.music);
                AddToMusicLookup(areaMusic, randList);
                break;

            case RandomizationLevel.Subtype:
            case RandomizationLevel.None:
            default:
                break;
            }

            // Ambient Noise
            List <FileInfo> ambientNoiseMusic = new List <FileInfo>();

            foreach (var prefix in PrefixListNoise)
            {
                ambientNoiseMusic.AddRange(musicFiles.Where(f => f.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)));
            }

            List <FileInfo> ambientNoiseSound = new List <FileInfo>();

            foreach (var prefix in PrefixListNoise)
            {
                ambientNoiseSound.AddRange(soundFiles.Where(f => f.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)));
            }

            switch (Properties.Settings.Default.RandomizeAmbientNoise)
            {
            case RandomizationLevel.Max:
                maxMusic.AddRange(ambientNoiseMusic);
                maxSound.AddRange(ambientNoiseSound);
                break;

            case RandomizationLevel.Type:
                var randList = Randomize.RandomizeFiles(ambientNoiseMusic, paths.music);
                AddToMusicLookup(ambientNoiseMusic, randList);

                randList = Randomize.RandomizeFiles(ambientNoiseSound, paths.sounds);
                AddToSoundLookup(ambientNoiseSound, randList);
                break;

            case RandomizationLevel.Subtype:
            case RandomizationLevel.None:
            default:
                break;
            }

            // Battle Music
            List <FileInfo> battleMusic    = new List <FileInfo>(musicFiles.Where(f => RegexBattleMusic.IsMatch(f.Name)));
            List <FileInfo> battleMusicEnd = new List <FileInfo>(soundFiles.Where(f => RegexBattleMusic.IsMatch(f.Name)));

            switch (Properties.Settings.Default.RandomizeBattleMusic)
            {
            case RandomizationLevel.Max:
                maxMusic.AddRange(battleMusic);
                maxSound.AddRange(battleMusicEnd);
                break;

            case RandomizationLevel.Type:
                var randList = Randomize.RandomizeFiles(battleMusic, paths.music);
                AddToMusicLookup(battleMusic, randList);

                randList = Randomize.RandomizeFiles(battleMusicEnd, paths.sounds);
                AddToSoundLookup(battleMusicEnd, randList);
                break;

            case RandomizationLevel.Subtype:
            case RandomizationLevel.None:
            default:
                break;
            }

            // Cutscene Noise
            List <FileInfo> cutsceneNoise = new List <FileInfo>(musicFiles.Where(f => RegexCutscene.IsMatch(f.Name)));

            cutsceneNoise.RemoveAll(f => f.Name.StartsWith("57.")); // Remove specific exception

            switch (Properties.Settings.Default.RandomizeCutsceneNoise)
            {
            case RandomizationLevel.Max:
                maxMusic.AddRange(cutsceneNoise);
                break;

            case RandomizationLevel.Type:
                var randList = Randomize.RandomizeFiles(cutsceneNoise, paths.music);
                AddToMusicLookup(cutsceneNoise, randList);
                break;

            case RandomizationLevel.Subtype:
            case RandomizationLevel.None:
            default:
                break;
            }

            // Check if NPC and Party Sounds are combined
            List <FileInfo> npcSounds   = new List <FileInfo>(soundFiles.Where(f => RegexNPCSound.IsMatch(f.Name)));
            List <FileInfo> partySounds = new List <FileInfo>(soundFiles.Where(f => RegexPartySound.IsMatch(f.Name)));

            //if (MixNpcAndPartySounds) // Functionality Disabled
            //{
            //    npcSounds.AddRange(partySounds);
            //}
            //else
            {
                // Party Sounds (if not mixing)
                switch (Properties.Settings.Default.RandomizePartySounds)
                {
                case RandomizationLevel.Max:
                    maxSound.AddRange(partySounds);
                    break;

                case RandomizationLevel.Type:
                    var randList = Randomize.RandomizeFiles(partySounds, paths.sounds);
                    AddToSoundLookup(partySounds, randList);
                    break;

                case RandomizationLevel.Subtype:
                    RandomizeSoundActions(partySounds, paths.sounds);
                    break;

                case RandomizationLevel.None:
                default:
                    break;
                }
            }

            //// NPC Sounds (or both if mixing) // Functionality Disabled
            //switch (RandomizeNpcSounds)
            //{
            //    case RandomizationLevel.Max:
            //        maxSound.AddRange(npcSounds);
            //        break;
            //    case RandomizationLevel.Type:
            //        Randomize.RandomizeFiles(npcSounds, SoundsPath);
            //        break;
            //    case RandomizationLevel.Subtype:
            //        RandomizeSoundActions(npcSounds, SoundsPath);
            //        break;
            //    case RandomizationLevel.None:
            //    default:
            //        break;
            //}

            // Max Randomizations
            if (maxMusic.Any())
            {
                var randList = Randomize.RandomizeFiles(maxMusic, paths.music);
                AddToMusicLookup(maxMusic, randList);
            }
            if (maxSound.Any())
            {
                var randList = Randomize.RandomizeFiles(maxSound, paths.sounds);
                AddToSoundLookup(maxSound, randList);
            }

            // Overwrite DMCA music with alternatives
            if (Properties.Settings.Default.RemoveDmcaMusic)
            {
                var orig = new List <FileInfo>();
                var rand = new List <FileInfo>();
                foreach (var fi in musicFiles.Where(f => DmcaAreaMusic.Contains(f.Name)))
                {
                    var replacement = areaMusic[Randomize.Rng.Next(areaMusic.Count)];
                    File.Copy(replacement.FullName, Path.Combine(paths.music, fi.Name), true);

                    orig.Add(fi);
                    rand.Add(replacement);
                }
                AddToMusicLookup(orig, rand);
            }
        }
Beispiel #11
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;
        }
        public static void sound_rando(KPaths paths)
        {
            var musicFiles = paths.FilesInMusicBackup;
            var soundFiles = paths.FilesInSoundsBackup;

            // Get file collections
            List <FileInfo> maxMusic = new List <FileInfo>();
            List <FileInfo> maxSound = new List <FileInfo>();

            // Area Music
            List <FileInfo> areaMusic = new List <FileInfo>();

            foreach (var prefix in PrefixListAreaMusic)
            {
                areaMusic.AddRange(musicFiles.Where(f => f.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)));
            }

            switch ((RandomizationLevel)Properties.Settings.Default.RandomizeAreaMusic)
            {
            case RandomizationLevel.Max:
                maxMusic.AddRange(areaMusic);
                break;

            case RandomizationLevel.Type:
                Randomize.RandomizeFiles(areaMusic, paths.music);
                break;

            case RandomizationLevel.Subtype:
            case RandomizationLevel.None:
            default:
                break;
            }

            // Ambient Noise
            List <FileInfo> ambientNoiseMusic = new List <FileInfo>();

            foreach (var prefix in PrefixListNoise)
            {
                ambientNoiseMusic.AddRange(musicFiles.Where(f => f.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)));
            }

            List <FileInfo> ambientNoiseSound = new List <FileInfo>();

            foreach (var prefix in PrefixListNoise)
            {
                ambientNoiseSound.AddRange(soundFiles.Where(f => f.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)));
            }

            switch ((RandomizationLevel)Properties.Settings.Default.RandomizeAmbientNoise)
            {
            case RandomizationLevel.Max:
                maxMusic.AddRange(ambientNoiseMusic);
                maxSound.AddRange(ambientNoiseSound);
                break;

            case RandomizationLevel.Type:
                Randomize.RandomizeFiles(ambientNoiseMusic, paths.music);
                Randomize.RandomizeFiles(ambientNoiseSound, paths.sounds);
                break;

            case RandomizationLevel.Subtype:
            case RandomizationLevel.None:
            default:
                break;
            }

            // Battle Music
            List <FileInfo> battleMusic    = new List <FileInfo>(musicFiles.Where(f => RegexBattleMusic.IsMatch(f.Name)));
            List <FileInfo> battleMusicEnd = new List <FileInfo>(soundFiles.Where(f => RegexBattleMusic.IsMatch(f.Name)));

            switch ((RandomizationLevel)Properties.Settings.Default.RandomizeBattleMusic)
            {
            case RandomizationLevel.Max:
                maxMusic.AddRange(battleMusic);
                maxSound.AddRange(battleMusicEnd);
                break;

            case RandomizationLevel.Type:
                Randomize.RandomizeFiles(battleMusic, paths.music);
                Randomize.RandomizeFiles(battleMusicEnd, paths.sounds);
                break;

            case RandomizationLevel.Subtype:
            case RandomizationLevel.None:
            default:
                break;
            }

            // Cutscene Noise
            List <FileInfo> cutsceneNoise = new List <FileInfo>(musicFiles.Where(f => RegexCutscene.IsMatch(f.Name)));

            cutsceneNoise.RemoveAll(f => f.Name.StartsWith("57.")); // Remove specific exception

            switch ((RandomizationLevel)Properties.Settings.Default.RandomizeCutsceneNoise)
            {
            case RandomizationLevel.Max:
                maxMusic.AddRange(cutsceneNoise);
                break;

            case RandomizationLevel.Type:
                Randomize.RandomizeFiles(cutsceneNoise, paths.music);
                break;

            case RandomizationLevel.Subtype:
            case RandomizationLevel.None:
            default:
                break;
            }

            // Check if NPC and Party Sounds are combined
            List <FileInfo> npcSounds   = new List <FileInfo>(soundFiles.Where(f => RegexNPCSound.IsMatch(f.Name)));
            List <FileInfo> partySounds = new List <FileInfo>(soundFiles.Where(f => RegexPartySound.IsMatch(f.Name)));

            //if (MixNpcAndPartySounds) // Functionality Disabled
            //{
            //    npcSounds.AddRange(partySounds);
            //}
            //else
            {
                // Party Sounds (if not mixing)
                switch ((RandomizationLevel)Properties.Settings.Default.RandomizePartySounds)
                {
                case RandomizationLevel.Max:
                    maxSound.AddRange(partySounds);
                    break;

                case RandomizationLevel.Type:
                    Randomize.RandomizeFiles(partySounds, paths.sounds);
                    break;

                case RandomizationLevel.Subtype:
                    RandomizeSoundActions(partySounds, paths.sounds);
                    break;

                case RandomizationLevel.None:
                default:
                    break;
                }
            }

            //// NPC Sounds (or both if mixing) // Functionality Disabled
            //switch (RandomizeNpcSounds)
            //{
            //    case RandomizationLevel.Max:
            //        maxSound.AddRange(npcSounds);
            //        break;
            //    case RandomizationLevel.Type:
            //        Randomize.RandomizeFiles(npcSounds, SoundsPath);
            //        break;
            //    case RandomizationLevel.Subtype:
            //        RandomizeSoundActions(npcSounds, SoundsPath);
            //        break;
            //    case RandomizationLevel.None:
            //    default:
            //        break;
            //}

            // Max Randomizations
            if (maxMusic.Any())
            {
                Randomize.RandomizeFiles(maxMusic, paths.music);
            }
            if (maxSound.Any())
            {
                Randomize.RandomizeFiles(maxSound, paths.sounds);
            }
        }