Exemplo n.º 1
0
        void ModProcess()
        {
            Random rand = new Random(ModLoaderGlobals.RandomizerSeed);

            SceneryColor PantsColor = new SceneryColor(0, 0, 0);

            if (Option_RandPantsColor.Enabled)
            {
                PantsColor = new SceneryColor((byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256), 0);
                // just so that it doesn't affect gameplay randomizers
                rand = new Random(ModLoaderGlobals.RandomizerSeed);
            }

            if (Prop_PantsColor.HasChanged)
            {
                PantsColor = new SceneryColor((byte)Prop_PantsColor.R, (byte)Prop_PantsColor.G, (byte)Prop_PantsColor.B, 0);
            }

            bool CachingPass = false;

            if (Option_RandMusic.Enabled || Option_RandMusicTracks.Enabled || Option_RandMusicInstruments.Enabled)
            {
                CachingPass = true;
            }
            CrashTri_Common.ResetCache();

            List <FileInfo> nsfs = new List <FileInfo>();
            List <FileInfo> nsds = new List <FileInfo>();
            DirectoryInfo   di   = new DirectoryInfo(ConsolePipeline.ExtractedPath);

            AppendFileInfoDir(nsfs, nsds, di); // this should return all NSF/NSD file pairs


            for (int i = 0; i < Math.Min(nsfs.Count, nsds.Count); ++i)
            {
                FileInfo nsfFile = nsfs[i];
                FileInfo nsdFile = nsds[i];
                if (Path.GetFileNameWithoutExtension(nsfFile.Name) != Path.GetFileNameWithoutExtension(nsdFile.Name))
                {
                    //MessageBox.Show($"NSF/NSD file pair mismatch. First mismatch:\n\n{nsfFile.Name}\n{nsdFile.Name}");
                    continue;
                }

                NSF    nsf;
                NewNSD nsd;
                try
                {
                    nsf = NSF.LoadAndProcess(File.ReadAllBytes(nsfFile.FullName), GameVersion.Crash3);
                    nsd = NewNSD.Load(File.ReadAllBytes(nsdFile.FullName));
                }
                catch (Exception ex)
                {
                    if (ex is LoadAbortedException)
                    {
                        Console.WriteLine("Crash: LoadAbortedException: " + nsfFile.Name + "\n" + ex.Message);
                        continue;
                        //return;
                    }
                    else if (ex is LoadSkippedException)
                    {
                        Console.WriteLine("Crash: LoadSkippedException: " + nsfFile.Name + "\n" + ex.Message);
                        continue;
                        //return;
                    }
                    else
                    {
                        throw;
                    }
                }

                Crash3_Levels NSF_Level = GetLevelFromNSF(nsfFile.Name);

                if (CachingPass)
                {
                    if (Option_RandMusicTracks.Enabled)
                    {
                        CrashTri_Common.Cache_Music(nsf);
                    }
                }
                else
                {
                    if (Option_AllCratesWumpa.Enabled)
                    {
                        Crash3_Mods.Mod_TurnCratesIntoWumpa(nsf, rand);
                    }
                    if (Option_RandWarpRoom.Enabled)
                    {
                        Crash3_Mods.Mod_RandomizeWarpRoom(nsf, nsd, NSF_Level, rand);
                    }
                    if (Option_BackwardsLevels.Enabled || Option_RandBackwardsLevels.Enabled)
                    {
                        Crash3_Mods.Mod_BackwardsLevels(nsf, nsd, NSF_Level, Option_RandBackwardsLevels.Enabled, rand);
                    }
                    if (Option_CameraBigFOV.Enabled || Option_RandCameraFOV.Enabled)
                    {
                        Crash3_Mods.Mod_CameraFOV(nsf, rand, Option_RandCameraFOV.Enabled);
                    }
                    if (Option_AllCratesBlank.Enabled)
                    {
                        Crash3_Mods.Mod_AllWoodCrates(nsf, rand);
                    }
                    if (Option_RandCrates.Enabled)
                    {
                        Crash3_Mods.Rand_WoodenCrates(nsf, rand, NSF_Level);
                    }
                    if (Option_RandBosses.Enabled)
                    {
                        Crash3_Mods.Mod_RandomizeBosses(nsf, nsd, NSF_Level, rand, false);
                    }
                    if (Option_RandFlyingLevels.Enabled)
                    {
                        Crash3_Mods.Mod_RandomizeFlyingLevels(nsf, nsd, NSF_Level, rand, false);
                    }
                    if (Option_RandBoxCount.Enabled)
                    {
                        Crash3_Mods.Rand_BoxCount(nsf, rand, NSF_Level);
                    }
                    if (Option_AllEnemiesMissing.Enabled)
                    {
                        Crash3_Mods.Mod_RemoveEnemies(nsf, rand, NSF_Level, false);
                    }
                    if (Option_RandEnemiesAreCrates.Enabled)
                    {
                        Crash3_Mods.Mod_EnemyCrates(nsf, rand, NSF_Level, true);
                    }
                    if (Option_AllEnemiesAreCrates.Enabled)
                    {
                        Crash3_Mods.Mod_EnemyCrates(nsf, rand, NSF_Level, false);
                    }
                    if (Option_RandEnemiesMissing.Enabled)
                    {
                        Crash3_Mods.Mod_RemoveEnemies(nsf, rand, NSF_Level, true);
                    }
                    if (Option_RandCratesMissing.Enabled)
                    {
                        Crash3_Mods.Rand_CratesMissing(nsf, rand);
                    }
                    if (Option_RandCrateContents.Enabled)
                    {
                        Crash3_Mods.Mod_RandomCrateContents(nsf, rand);
                    }
                    if (Option_RandCrateParams.Enabled)
                    {
                        Crash3_Mods.Mod_RandomCrateParams(nsf, rand, NSF_Level);
                    }
                    if (Option_RandInvisibleCrates.Enabled)
                    {
                        Crash3_Mods.Mod_InvisibleCrates(nsf, rand, NSF_Level, true);
                    }
                    if (Option_InvisibleCrates.Enabled)
                    {
                        Crash3_Mods.Mod_InvisibleCrates(nsf, rand, NSF_Level, false);
                    }
                    if (Option_RemoveWarpRoomBarriers.Enabled)
                    {
                        Crash3_Mods.Mod_RemoveBarriers(nsf, NSF_Level);
                    }

                    if (Option_RandWorldPalette.Enabled)
                    {
                        CrashTri_Common.Mod_Scenery_Swizzle(nsf, rand);
                    }
                    if (Option_GreyscaleWorld.Enabled)
                    {
                        CrashTri_Common.Mod_Scenery_Greyscale(nsf);
                    }
                    if (Option_RandWorldColors.Enabled)
                    {
                        CrashTri_Common.Mod_Scenery_Rainbow(nsf, rand);
                    }
                    if (Option_UntexturedWorld.Enabled)
                    {
                        CrashTri_Common.Mod_Scenery_Untextured(nsf);
                    }
                    if (Option_RandWorldTex.Enabled)
                    {
                        CrashTri_Common.Mod_RandomizeWGEOTex(nsf, rand);
                    }
                    if (Option_RandPantsColor.Enabled || Prop_PantsColor.HasChanged)
                    {
                        Crash3_Mods.Mod_PantsColor(nsf, PantsColor);
                    }
                    if (Option_RandObjCol.Enabled)
                    {
                        CrashTri_Common.Mod_RandomizeTGEOCol(nsf, rand);
                    }
                    if (Option_AllCratesAshed.Enabled)
                    {
                        Crash3_Mods.Mod_AshedCrates(nsf, rand, false);
                    }
                    if (Option_RandCratesAshed.Enabled)
                    {
                        Crash3_Mods.Mod_AshedCrates(nsf, rand, true);
                    }
                    if (Option_RandObjTex.Enabled)
                    {
                        CrashTri_Common.Mod_RandomizeTGEOTex(nsf, rand);
                    }
                    if (NSF_Level != Crash3_Levels.Unknown && Option_RandMusicTracks.Enabled)
                    {
                        CrashTri_Common.Randomize_Music(nsf, rand);
                    }
                    if (Option_RandSounds.Enabled)
                    {
                        CrashTri_Common.Mod_RandomizeADIO(nsf, rand);
                    }
                    if (Option_RandStreams.Enabled)
                    {
                        CrashTri_Common.Mod_RandomizeSDIO(nsf, rand);
                    }
                    if (Option_RandObjPalette.Enabled)
                    {
                        CrashTri_Common.Mod_SwizzleObjectColors(nsf, rand);
                    }
                    if (Option_UntexturedObj.Enabled)
                    {
                        CrashTri_Common.Mod_RemoveTGEOTex(nsf, rand);
                    }
                    if (Option_UncoloredObj.Enabled)
                    {
                        CrashTri_Common.Mod_RemoveObjectColors(nsf, rand);
                    }

                    Crash3_Mods.Mod_Metadata(nsf, nsd, NSF_Level, GameRegion.Region);
                }

                PatchNSD(nsf, nsd);

                File.WriteAllBytes(nsfFile.FullName, nsf.Save());
                File.WriteAllBytes(nsdFile.FullName, nsd.Save());

                if (CachingPass && i == Math.Min(nsfs.Count, nsds.Count) - 1)
                {
                    CachingPass = false;
                    i           = -1;
                }
            }
        }
Exemplo n.º 2
0
        void ModProcess()
        {
            Random rand = new Random(ModLoaderGlobals.RandomizerSeed);

            List <FileInfo> nsfs = new List <FileInfo>();
            List <FileInfo> nsds = new List <FileInfo>();
            DirectoryInfo   di   = new DirectoryInfo(ConsolePipeline.ExtractedPath);

            AppendFileInfoDir(nsfs, nsds, di); // this should return all NSF/NSD file pairs

            bool CachingPass = false;

            CrashTri_Common.ResetCache();

            if (Option_RandMusicTracks.Enabled)
            {
                CachingPass = true;
            }


            OldSceneryColor PantsColor = new OldSceneryColor(0, 0, 0, false);

            if (Option_RandPantsColor.Enabled)
            {
                PantsColor = new OldSceneryColor((byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256), false);
                // just so that it doesn't affect gameplay randomizers
                rand = new Random(ModLoaderGlobals.RandomizerSeed);
            }

            if (Prop_PantsColor.HasChanged)
            {
                PantsColor = new OldSceneryColor((byte)(Prop_PantsColor.Value[0] * 255f), (byte)(Prop_PantsColor.Value[1] * 255f), (byte)(Prop_PantsColor.Value[2] * 255f), false);
            }

            if (Option_AddCavernLevel.Enabled)
            {
                File.Delete(Path.Combine(ConsolePipeline.ExtractedPath, @"S0\S0000004.NSD"));
                File.Copy(Path.Combine(ConsolePipeline.ExtractedPath, @"S0\S000000A.NSD"), Path.Combine(ConsolePipeline.ExtractedPath, @"S0\S0000004.NSD"));
            }

            for (int i = 0; i < Math.Min(nsfs.Count, nsds.Count); ++i)
            {
                FileInfo nsfFile = nsfs[i];
                FileInfo nsdFile = nsds[i];
                if (Path.GetFileNameWithoutExtension(nsfFile.Name) != Path.GetFileNameWithoutExtension(nsdFile.Name))
                {
                    //MessageBox.Show($"NSF /NSD file pair mismatch. First mismatch:\n\n{nsfFile.Name}\n{nsdFile.Name}");
                    continue;
                }

                NSF    nsf;
                OldNSD nsd;
                try
                {
                    nsf = NSF.LoadAndProcess(File.ReadAllBytes(nsfFile.FullName), GameVersion.Crash1);
                    nsd = OldNSD.Load(File.ReadAllBytes(nsdFile.FullName));
                }
                catch (Exception ex)
                {
                    if (ex is LoadAbortedException)
                    {
                        Console.WriteLine("Crash: LoadAbortedException: " + nsfFile.Name + "\n" + ex.Message);
                        continue;
                        //return;
                    }
                    else if (ex is LoadSkippedException)
                    {
                        Console.WriteLine("Crash: LoadSkippedException: " + nsfFile.Name + "\n" + ex.Message);
                        continue;
                        //return;
                    }
                    else
                    {
                        throw;
                    }
                }

                Crash1_Levels NSF_Level = GetLevelFromNSF(nsfFile.Name);

                if (CachingPass)
                {
                    if (Option_HogLevelsOnFoot.Enabled)
                    {
                        Crash1_Mods.Cache_NormalCrashData(nsf, nsd, NSF_Level);
                    }
                    if (Option_RandMusicTracks.Enabled)
                    {
                        CrashTri_Common.Cache_Music(nsf);
                    }
                }
                else
                {
                    if (Option_AllCratesWumpa.Enabled)
                    {
                        Crash1_Mods.Mod_TurnCratesIntoWumpa(nsf, rand, NSF_Level);
                    }
                    if (Option_RandCrates.Enabled)
                    {
                        Crash1_Mods.Mod_RandomCrates(nsf, rand, NSF_Level);
                    }
                    if (Option_RandBonusRounds.Enabled)
                    {
                        Crash1_Mods.Mod_RandomizeBonusRounds(nsf, nsd, NSF_Level, rand);
                    }
                    if (Option_BackwardsLevels.Enabled || Option_RandBackwardsLevels.Enabled)
                    {
                        Crash1_Mods.Mod_BackwardsLevels(nsf, nsd, NSF_Level, Option_RandBackwardsLevels.Enabled, rand);
                    }
                    if (Option_BackwardsHogLevels.Enabled)
                    {
                        Crash1_Mods.Mod_HogLevelsBackwards(nsf, nsd, NSF_Level);
                    }
                    if (Option_CameraBigFOV.Enabled || Option_RandCameraFOV.Enabled)
                    {
                        Crash1_Mods.Mod_CameraFOV(nsf, rand, Option_RandCameraFOV.Enabled);
                    }
                    if (Option_AllCratesBlank.Enabled)
                    {
                        Crash1_Mods.Mod_RandomWoodCrates(nsf, rand, NSF_Level);
                    }
                    if (Option_RandCrateContents.Enabled)
                    {
                        Crash1_Mods.Mod_RandomCrateContents(nsf, rand, NSF_Level);
                    }
                    if (Option_RandInvisibleCrates.Enabled)
                    {
                        Crash1_Mods.Mod_InvisibleCrates(nsf, rand, NSF_Level, true);
                    }
                    if (Option_InvisibleCrates.Enabled)
                    {
                        Crash1_Mods.Mod_InvisibleCrates(nsf, rand, NSF_Level, false);
                    }
                    if (Option_RandBosses.Enabled)
                    {
                        Crash1_Mods.Mod_RandomizeBosses(nsf, nsd, NSF_Level, rand, false);
                    }
                    if (Option_AddStormyAscent.Enabled)
                    {
                        Crash1_Mods.Mod_AddStormyAscent(nsf, nsd, NSF_Level, GameRegion.Region);
                    }
                    if (Option_AddCavernLevel.Enabled)
                    {
                        Crash1_Mods.Mod_AddCavernLevel(nsf, nsd, NSF_Level, GameRegion.Region);
                    }
                    if (Option_RandMap.Enabled)
                    {
                        Crash1_Mods.Mod_RandomizeMap(nsf, nsd, NSF_Level, rand, GameRegion.Region);
                    }
                    if (Option_RandWorldPalette.Enabled)
                    {
                        CrashTri_Common.Mod_Scenery_Swizzle(nsf, rand);
                    }
                    if (Option_GreyscaleWorld.Enabled)
                    {
                        CrashTri_Common.Mod_Scenery_Greyscale(nsf);
                    }
                    if (Option_RandWorldColors.Enabled)
                    {
                        CrashTri_Common.Mod_Scenery_Rainbow(nsf, rand);
                    }
                    if (Option_UntexturedWorld.Enabled)
                    {
                        CrashTri_Common.Mod_Scenery_Untextured(nsf);
                    }
                    if (Option_RandPantsColor.Enabled || Prop_PantsColor.HasChanged)
                    {
                        Crash1_Mods.Mod_PantsColor(nsf, PantsColor);
                    }
                    if (NSF_Level != Crash1_Levels.MapMainMenu && Option_RandMusicTracks.Enabled)
                    {
                        CrashTri_Common.Randomize_Music(nsf, rand);
                    }
                    if (Option_RandSounds.Enabled)
                    {
                        CrashTri_Common.Mod_RandomizeADIO(nsf, rand);
                    }
                    if (Option_RandLightCol.Enabled)
                    {
                        Crash1_Mods.Mod_RandomLightColor(nsf, rand);
                    }

                    if (NSF_Level == Crash1_Levels.L16_HeavyMachinery && Option_EnableDog.Enabled)
                    {
                        Crash1_Mods.Mod_EnableDog(nsf);
                    }

                    Crash1_Mods.Mod_Metadata(nsf, nsd, NSF_Level, GameRegion.Region);
                }

                PatchNSD(nsf, nsd);

                File.WriteAllBytes(nsfFile.FullName, nsf.Save());
                File.WriteAllBytes(nsdFile.FullName, nsd.Save());

                if (CachingPass && i == Math.Min(nsfs.Count, nsds.Count) - 1)
                {
                    CachingPass = false;
                    i           = -1;
                }
            }
        }