示例#1
0
        internal void CacheMusic(NSF nsf, ref List <List <WavebankChunk> > wavebankChunks, ref List <List <MusicEntry> > musicEntries)
        {
            List <WavebankChunk> waveBanks  = new List <WavebankChunk>();
            List <MusicEntry>    musicFiles = new List <MusicEntry>();

            foreach (Chunk chunk in nsf.Chunks)
            {
                if (chunk is NormalChunk normchunk)
                {
                    foreach (Entry entry in normchunk.Entries)
                    {
                        if (entry is MusicEntry music)
                        {
                            musicFiles.Add(music);
                        }
                    }
                }
                else if (chunk is WavebankChunk wavechunk)
                {
                    waveBanks.Add(wavechunk);
                }
            }
            wavebankChunks.Add(waveBanks);
            musicEntries.Add(musicFiles);
        }
示例#2
0
        internal void Mod_MirrorLevel(NSF nsf, NSD nsd, Random rand, bool isRandom)
        {
            //unfinished

            foreach (Chunk chunk in nsf.Chunks)
            {
                if (chunk is NormalChunk zonechunk)
                {
                    foreach (Entry entry in zonechunk.Entries)
                    {
                        if (entry is ZoneEntry zone)
                        {
                        }
                        else if (entry is SceneryEntry scen)
                        {
                            for (int i = 0; i < scen.Vertices.Count; i++)
                            {
                                SceneryVertex vertex   = scen.Vertices[i];
                                int           x        = -vertex.X;
                                int           y        = vertex.Y;
                                int           z        = vertex.Z;
                                int           unknownx = vertex.UnknownX;
                                int           unknowny = vertex.UnknownY;
                                int           unknownz = vertex.UnknownZ;
                                int           color    = vertex.Color;
                                scen.Vertices[i] = new SceneryVertex(x, y, z, unknownx, unknowny, unknownz);
                            }
                        }
                    }
                }
            }

            nsd.Spawns[0].SpawnX = -nsd.Spawns[0].SpawnX;
        }
示例#3
0
        public NSFBox(NSF nsf,GameVersion gameversion)
        {
            this.nsf = nsf;
            this.controller = new NSFController(nsf,gameversion);

            this.searchresults = new List<TreeNode>();

            controller.Node.Expand();

            trvMain = new TreeView();
            trvMain.Dock = DockStyle.Fill;
            trvMain.ImageList = imglist;
            trvMain.HideSelection = false;
            trvMain.Nodes.Add(controller.Node);
            trvMain.SelectedNode = controller.Node;
            trvMain.AllowDrop = true;
            trvMain.AfterSelect += new TreeViewEventHandler(trvMain_AfterSelect);
            trvMain.ItemDrag += new ItemDragEventHandler(trvMain_ItemDrag);
            trvMain.DragOver += new DragEventHandler(trvMain_DragOver);
            trvMain.DragDrop += new DragEventHandler(trvMain_DragDrop);

            pnSplit = new SplitContainer();
            pnSplit.Dock = DockStyle.Fill;
            pnSplit.Panel1.Controls.Add(trvMain);

            this.Controls.Add(pnSplit);
        }
示例#4
0
        public NSFBox(NSF nsf, GameVersion gameversion)
        {
            this.nsf        = nsf;
            this.controller = new NSFController(nsf, gameversion);

            this.searchresults = new List <TreeNode>();

            controller.Node.Expand();

            trvMain               = new TreeView();
            trvMain.Dock          = DockStyle.Fill;
            trvMain.ImageList     = imglist;
            trvMain.HideSelection = false;
            trvMain.Nodes.Add(controller.Node);
            trvMain.SelectedNode = controller.Node;
            trvMain.AllowDrop    = true;
            trvMain.AfterSelect += new TreeViewEventHandler(trvMain_AfterSelect);
            trvMain.ItemDrag    += new ItemDragEventHandler(trvMain_ItemDrag);
            trvMain.DragOver    += new DragEventHandler(trvMain_DragOver);
            trvMain.DragDrop    += new DragEventHandler(trvMain_DragDrop);

            pnSplit      = new SplitContainer();
            pnSplit.Dock = DockStyle.Fill;
            pnSplit.Panel1.Controls.Add(trvMain);

            this.Controls.Add(pnSplit);
        }
示例#5
0
        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;
        }
示例#6
0
        public void OpenNSF(string filename, NSF nsf, GameVersion gameversion)
        {
            NSFBox nsfbox = new NSFBox(nsf, gameversion);

            nsfbox.Dock = DockStyle.Fill;

            TabPage nsftab = new TabPage(filename);

            nsftab.Tag = nsfbox;
            nsftab.Controls.Add(nsfbox);

            tbcTabs.TabPages.Add(nsftab);
            tbcTabs.SelectedTab = nsftab;
        }
示例#7
0
 public NSFController(NSF nsf,GameVersion gameversion)
 {
     this.nsf = nsf;
     this.gameversion = gameversion;
     Node.Text = "NSF File";
     Node.ImageKey = "nsf";
     Node.SelectedImageKey = "nsf";
     foreach (Chunk chunk in nsf.Chunks)
     {
         if (chunk is NormalChunk)
         {
             AddNode(new NormalChunkController(this,(NormalChunk)chunk));
         }
         else if (chunk is TextureChunk)
         {
             AddNode(new TextureChunkController(this,(TextureChunk)chunk));
         }
         else if (chunk is OldSoundChunk)
         {
             AddNode(new OldSoundChunkController(this,(OldSoundChunk)chunk));
         }
         else if (chunk is SoundChunk)
         {
             AddNode(new SoundChunkController(this,(SoundChunk)chunk));
         }
         else if (chunk is WavebankChunk)
         {
             AddNode(new WavebankChunkController(this,(WavebankChunk)chunk));
         }
         else if (chunk is SpeechChunk)
         {
             AddNode(new SpeechChunkController(this,(SpeechChunk)chunk));
         }
         else if (chunk is UnprocessedChunk)
         {
             AddNode(new UnprocessedChunkController(this,(UnprocessedChunk)chunk));
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     AddMenu("Add Chunk - Normal",Menu_Add_NormalChunk);
     AddMenu("Add Chunk - Sound",Menu_Add_SoundChunk);
     AddMenu("Add Chunk - Wavebank",Menu_Add_WavebankChunk);
     AddMenu("Add Chunk - Speech",Menu_Add_SpeechChunk);
     AddMenuSeparator();
     AddMenu("Fix Nitro Detonators",Menu_Fix_Detonator);
     AddMenu("Fix Box Count",Menu_Fix_BoxCount);
 }
示例#8
0
 public NSFController(NSF nsf, GameVersion gameversion)
 {
     this.nsf              = nsf;
     this.gameversion      = gameversion;
     Node.Text             = "NSF File";
     Node.ImageKey         = "nsf";
     Node.SelectedImageKey = "nsf";
     foreach (Chunk chunk in nsf.Chunks)
     {
         if (chunk is NormalChunk)
         {
             AddNode(new NormalChunkController(this, (NormalChunk)chunk));
         }
         else if (chunk is TextureChunk)
         {
             AddNode(new TextureChunkController(this, (TextureChunk)chunk));
         }
         else if (chunk is OldSoundChunk)
         {
             AddNode(new OldSoundChunkController(this, (OldSoundChunk)chunk));
         }
         else if (chunk is SoundChunk)
         {
             AddNode(new SoundChunkController(this, (SoundChunk)chunk));
         }
         else if (chunk is WavebankChunk)
         {
             AddNode(new WavebankChunkController(this, (WavebankChunk)chunk));
         }
         else if (chunk is SpeechChunk)
         {
             AddNode(new SpeechChunkController(this, (SpeechChunk)chunk));
         }
         else if (chunk is UnprocessedChunk)
         {
             AddNode(new UnprocessedChunkController(this, (UnprocessedChunk)chunk));
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     AddMenu("Add Chunk - Normal", Menu_Add_NormalChunk);
     AddMenu("Add Chunk - Sound", Menu_Add_SoundChunk);
     AddMenu("Add Chunk - Wavebank", Menu_Add_WavebankChunk);
     AddMenu("Add Chunk - Speech", Menu_Add_SpeechChunk);
     AddMenuSeparator();
     AddMenu("Fix Nitro Detonators", Menu_Fix_Detonator);
     AddMenu("Fix Box Count", Menu_Fix_BoxCount);
 }
示例#9
0
 public void OpenNSF(string filename)
 {
     try
     {
         byte[] nsfdata = File.ReadAllBytes(filename);
         if (dlgGameVersion.ShowDialog() == DialogResult.OK)
         {
             NSF nsf = NSF.LoadAndProcess(nsfdata, dlgGameVersion.GameVersion);
             OpenNSF(filename, nsf, dlgGameVersion.GameVersion);
         }
     }
     catch (LoadAbortedException)
     {
     }
 }
示例#10
0
 public void PatchNSD(string filename, NSF nsf)
 {
     try
     {
         byte[] data = File.ReadAllBytes(filename);
         NSD    nsd  = NSD.Load(data);
         nsd.ChunkCount = nsf.Chunks.Count;
         Dictionary <int, int> newindex = new Dictionary <int, int>();
         for (int i = 0; i < nsf.Chunks.Count; i++)
         {
             if (nsf.Chunks[i] is IEntry)
             {
                 IEntry entry = (IEntry)nsf.Chunks[i];
                 newindex.Add(entry.EID, i * 2 + 1);
             }
             if (nsf.Chunks[i] is EntryChunk)
             {
                 foreach (Entry entry in ((EntryChunk)nsf.Chunks[i]).Entries)
                 {
                     newindex.Add(entry.EID, i * 2 + 1);
                 }
             }
         }
         foreach (NSDLink link in nsd.Index)
         {
             if (newindex.ContainsKey(link.EntryID))
             {
                 link.ChunkID = newindex[link.EntryID];
                 newindex.Remove(link.EntryID);
             }
             else
             {
                 // ???
             }
         }
         foreach (KeyValuePair <int, int> link in newindex)
         {
             // ???
         }
         if (MessageBox.Show("Are you sure you want to overwrite the NSD file?", "Save Confirmation Prompt", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             File.WriteAllBytes(filename, nsd.Save());
         }
     }
     catch (LoadAbortedException)
     {
     }
 }
示例#11
0
 internal void Randomize_Music(NSF nsf, Random rand, ref List <List <WavebankChunk> > wavebankChunks, ref List <List <MusicEntry> > musicEntries, bool RandomMusic, bool RandomTracks, bool RandomInstruments)
 {
     //unfinished
     foreach (Chunk chunk in nsf.Chunks)
     {
         if (chunk is NormalChunk normchunk)
         {
             foreach (Entry entry in normchunk.Entries)
             {
                 if (entry is MusicEntry music)
                 {
                 }
             }
         }
         else if (chunk is WavebankChunk wavechunk)
         {
         }
     }
 }
示例#12
0
 public void SaveNSF(string filename, NSF nsf)
 {
     try
     {
         byte[] nsfdata = nsf.Save();
         if (MessageBox.Show("Are you sure you want to overwrite this file?", "Save Confirmation Prompt", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             File.WriteAllBytes(filename, nsfdata);
         }
     }
     catch (PackingException)
     {
         MessageBox.Show("A packing error occurred. One of the entry-containing chunks contains over 64 KB of data.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (IOException ex)
     {
         MessageBox.Show("An IO error occurred.\n\n" + ex.Message, "Save", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (UnauthorizedAccessException ex)
     {
         MessageBox.Show("An unauthorized access error occurred.\n\n" + ex.Message, "Save", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#13
0
 public void SaveNSF(string filename,NSF nsf)
 {
     try
     {
         byte[] nsfdata = nsf.Save();
         if (MessageBox.Show("Are you sure you want to overwrite this file?","Save Confirmation Prompt",MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             File.WriteAllBytes(filename,nsfdata);
         }
     }
     catch (PackingException)
     {
         MessageBox.Show("A packing error occurred. One of the entry-containing chunks contains over 64 KB of data.","Save",MessageBoxButtons.OK,MessageBoxIcon.Error);
     }
     catch (IOException ex)
     {
         MessageBox.Show("An IO error occurred.\n\n" + ex.Message,"Save",MessageBoxButtons.OK,MessageBoxIcon.Error);
     }
     catch (UnauthorizedAccessException ex)
     {
         MessageBox.Show("An unauthorized access error occurred.\n\n" + ex.Message,"Save",MessageBoxButtons.OK,MessageBoxIcon.Error);
     }
 }
示例#14
0
 public void PatchNSD(string filename,NSF nsf)
 {
     try
     {
         byte[] data = File.ReadAllBytes(filename);
         NSD nsd = NSD.Load(data);
         nsd.ChunkCount = nsf.Chunks.Count;
         Dictionary<int,int> newindex = new Dictionary<int,int>();
         for (int i = 0;i < nsf.Chunks.Count;i++)
         {
             if (nsf.Chunks[i] is IEntry)
             {
                 IEntry entry = (IEntry)nsf.Chunks[i];
                 newindex.Add(entry.EID,i * 2 + 1);
             }
             if (nsf.Chunks[i] is EntryChunk)
             {
                 foreach (Entry entry in ((EntryChunk)nsf.Chunks[i]).Entries)
                 {
                     newindex.Add(entry.EID,i * 2 + 1);
                 }
             }
         }
         foreach (NSDLink link in nsd.Index)
         {
             if (newindex.ContainsKey(link.EntryID))
             {
                 link.ChunkID = newindex[link.EntryID];
                 newindex.Remove(link.EntryID);
             }
             else
             {
                 // ???
             }
         }
         foreach (KeyValuePair<int,int> link in newindex)
         {
             // ???
         }
         if (MessageBox.Show("Are you sure you want to overwrite the NSD file?","Save Confirmation Prompt",MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             File.WriteAllBytes(filename,nsd.Save());
         }
     }
     catch (LoadAbortedException)
     {
     }
 }
示例#15
0
        public void OpenNSF(string filename,NSF nsf,GameVersion gameversion)
        {
            NSFBox nsfbox = new NSFBox(nsf,gameversion);
            nsfbox.Dock = DockStyle.Fill;

            TabPage nsftab = new TabPage(filename);
            nsftab.Tag = nsfbox;
            nsftab.Controls.Add(nsfbox);

            tbcTabs.TabPages.Add(nsftab);
            tbcTabs.SelectedTab = nsftab;
        }
示例#16
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;
                }
            }
        }
示例#17
0
        internal void PatchNSD(NSF nsf, NewNSD nsd)
        {
            // edit NSD
            nsd.ChunkCount = nsf.Chunks.Count;
            var indexdata = nsf.MakeNSDIndex();

            nsd.HashKeyMap = indexdata.Item1;
            nsd.Index      = indexdata.Item2;

            // patch object entity count
            nsd.EntityCount = 0;
            foreach (Chunk chunk in nsf.Chunks)
            {
                if (!(chunk is EntryChunk))
                {
                    continue;
                }
                foreach (Entry entry in ((EntryChunk)chunk).Entries)
                {
                    if (entry is NewZoneEntry zone)
                    {
                        foreach (Entity ent in zone.Entities)
                        {
                            if (ent.ID != null)
                            {
                                ++nsd.EntityCount;
                            }
                        }
                    }
                }
            }

            // fix loadlists
            int[] eids = new int[nsd.Index.Count];
            for (int i = 0; i < eids.Length; ++i)
            {
                eids[i] = nsd.Index[i].EntryID;
            }
            foreach (Chunk chunk in nsf.Chunks)
            {
                if (!(chunk is EntryChunk))
                {
                    continue;
                }
                foreach (Entry entry in ((EntryChunk)chunk).Entries)
                {
                    if (entry is NewZoneEntry zone)
                    {
                        foreach (Entity ent in zone.Entities)
                        {
                            if (ent.LoadListA != null)
                            {
                                foreach (EntityPropertyRow <int> row in ent.LoadListA.Rows)
                                {
                                    List <int> values = (List <int>)row.Values;
                                    values.Sort(delegate(int a, int b) {
                                        return(Array.IndexOf(eids, a) - Array.IndexOf(eids, b));
                                    });
                                }
                            }
                            if (ent.LoadListB != null)
                            {
                                foreach (EntityPropertyRow <int> row in ent.LoadListB.Rows)
                                {
                                    List <int> values = (List <int>)row.Values;
                                    values.Sort(delegate(int a, int b) {
                                        return(Array.IndexOf(eids, a) - Array.IndexOf(eids, b));
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
示例#18
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;
                }
            }
        }