internal void PatchNSD(NSF nsf, OldNSD nsd) { // edit NSD nsd.ChunkCount = nsf.Chunks.Count; var indexdata = nsf.MakeNSDIndex(); nsd.HashKeyMap = indexdata.Item1; nsd.Index = indexdata.Item2; }
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; } } }