public static string[] ForPac(TracklistModifier modifier, CMM cmm, string filename) { filename = filename.ToLower(); string key = filename.Substring(0, filename.IndexOfAny("_.".ToCharArray())); int stageId = StageIDMap.StageIDForPac(filename); if (cmm != null && cmm.Map.TryGetValue(stageId, out IEnumerable <Song> songs)) { return(songs.Select(s => s.Filename).ToArray()); } // Tracklist Modifier 1.0 [Phantom Wings] if (cmm.TracklistModifier != null) { byte currentTracklistId = cmm.TracklistModifier[stageId]; for (int i = 0; i < CMM.StandardCMMTracklistModifierData.Length; i++) { if (CMM.StandardCMMTracklistModifierData[i] == currentTracklistId) { int originalStageId = i; // Make sure the index is a valid stage ID. Some bytes // appear more than once, the first time at an index // that's not a valid stage ID (e.g. Battlefield's 00 // at index 0 or Bridge of Eldin's 0A at index 10.) if (Stage.Stages.Any(s => s.ID == i)) { stageId = originalStageId; break; } } } } // Tracklist Modifier [standardtoaster] stageId = modifier[stageId]; if (stageId == 5 && filename.StartsWith("stgmariopast_00")) { return(new[] { "A01", "A16", "A10" }); } if (stageId == 5 && filename.StartsWith("stgmariopast_01")) { return(new[] { "A02", "A03", "A04" }); } if (dict.TryGetValue(stageId, out string[] ret))
public string MenSelmapMarkUsageReport() { Dictionary <string, int> dict = new Dictionary <string, int>(); string pathToPAT0TextureNode = "MiscData[80]/AnmTexPat(NW4R)/MenSelmapPreview/pasted__stnamelogoM"; var look = sc_selmap.FindChild(pathToPAT0TextureNode, false).Children[0]; if (!(look is PAT0TextureNode)) { throw new FormatException(look.Name); } PAT0TextureNode tn = look as PAT0TextureNode; string pathToTextures = "MiscData[80]/Textures(NW4R)"; ResourceNode textures = sc_selmap.FindChild(pathToTextures, false); List <string> marks = (from c in textures.Children where c.Name.Contains("MenSelmapMark") select c.Name).ToList(); var q = from c in (from c in tn.Children where c is PAT0TextureEntryNode select(PAT0TextureEntryNode) c) where marks.Contains(c.Texture) group c by c.Texture into g let count = g.Count() let stageID = BestSSS.StageForIcon((int)g.First().FrameIndex) let one = StageIDMap.PacBasenameForStageID(stageID) orderby count, g.Key select new { count, g.Key, one }; StringBuilder sb = new StringBuilder(); foreach (var line in q) { sb.AppendLine(line.Key + ": " + (line.count == 1 ? line.one : line.count.ToString())); marks.Remove(line.Key); } foreach (var name in marks) { sb.AppendLine(name + ": NOT USED"); } return(sb.ToString()); }
public Song GetSong(string filename, Song originalSong) { int stageID = StageIDMap.StageIDForPac(filename); if (AlternateStageLoaderData.TryGetDefinition(filename, out AlternateStageEntry entry)) { foreach (AlternateStageEntry.Alternate alt in entry.ButtonActivated.Where(b => filename.EndsWith($"_{b.Letter}.pac", StringComparison .InvariantCultureIgnoreCase))) { Song newSong = AltStageSongForcer.GetSong(stageID, alt.ButtonMask, originalSong); if (newSong.ID != originalSong.ID) { return(newSong); } } } return(SongLoaders.GetSong(stageID, originalSong)); }
public void copyIconsToSelcharacter2() { string fileToSaveTo = null; ResourceNode s2 = null; if (common5 != null) { s2 = common5.FindChild("sc_selcharacter2_en", false); } else if (sc_selmap != null) { if (File.Exists("../../menu2/sc_selcharacter2.pac")) { fileToSaveTo = "../../menu2/sc_selcharacter2.pac"; s2 = TempFiles.MakeTempNode(fileToSaveTo); } else if (File.Exists("../../menu2/sc_selcharacter2_en.pac")) { fileToSaveTo = "../../menu2/sc_selcharacter2_en.pac"; s2 = TempFiles.MakeTempNode(fileToSaveTo); } } if (s2 == null) { return; } ResourceNode md0 = s2.FindChild("MenuRule_en/ModelData[0]", false); MSBinNode md1 = s2.FindChild("MenuRule_en/MiscData[1]", false) as MSBinNode; ResourceNode md80 = sc_selmap.FindChild("MiscData[80]", false); if (md0 == null || md80 == null) { return; } Image[] icons = new Image[41]; Image[] frontstnames = new Image[41]; for (int i = 1; i < 60; i++) { if (i == 32) { i = 50; } int sssPos = StageIDMap.sssPositionForSelcharacter2Icon(i); string nameSelmap = BestSSS[sssPos].Item2.ToString("D2"); icons[sssPos] = ((md80.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelmap, false) as TEX0Node).GetImage(0)); frontstnames[sssPos] = ((md80.FindChild("Textures(NW4R)/MenSelmapFrontStname." + nameSelmap, false) as TEX0Node).GetImage(0)); } var d = new RandomSelectEditNamesDialog(md1._strings, icons, frontstnames); d.Message = "When finished, press OK to continue."; if (d.ShowDialog() == DialogResult.OK) { for (int i = 0; i < md1._strings.Count; i++) { md1._strings[i] = d[i].ToString(); } } else { return; } using (ProgressWindow w = new ProgressWindow() { CanCancel = false }) { w.Begin(0, 60, 0); for (int i = 1; i < 60; i++) { if (i == 32) { i = 50; } int sssPos = StageIDMap.sssPositionForSelcharacter2Icon(i); string tempFile1 = TempFiles.Create(".tex0"); string tempFile2 = TempFiles.Create(".plt0"); string nameSelcharacter2 = i.ToString("D2"); string nameSelmap = BestSSS[sssPos].Item2.ToString("D2"); TEX0Node iconFrom = md80.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelmap, false) as TEX0Node; TEX0Node iconTo = md0.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelcharacter2, false) as TEX0Node; var palFrom = md80.FindChild("Palettes(NW4R)/MenSelmapIcon." + nameSelmap, false); var palTo = md0.FindChild("Palettes(NW4R)/MenSelmapIcon." + nameSelcharacter2, false); if (iconFrom != null && iconTo != null && palFrom != null && palTo != null) { iconFrom.Export(tempFile1); iconTo.Replace(tempFile1); palFrom.Export(tempFile2); palTo.Replace(tempFile2); } TEX0Node prevbase = md80.FindChild("Textures(NW4R)/MenSelmapPrevbase." + nameSelmap, false) as TEX0Node; TEX0Node stageswitch = md0.FindChild("Textures(NW4R)/MenStageSwitch." + nameSelcharacter2, false) as TEX0Node; if (prevbase != null && stageswitch != null) { Bitmap thumbnail = new Bitmap(112, 56); using (Graphics g = Graphics.FromImage(thumbnail)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(prevbase.GetImage(0), 0, -28, 112, 112); } stageswitch.Replace(thumbnail); } w.Update(i); } } if (fileToSaveTo != null) { s2.Export(fileToSaveTo); } }
private ActionResult Generate(string csv, string gctPath, ResourceNode sc_selmap, string relpath, ResourceNode info_pac, ResourceNode common2, string brstmPath) { Func <string, List <string> > split = s => { List <string> list = new List <string>(); StringBuilder current = new StringBuilder(); bool inQuote = false; foreach (char c in s) { if (c == '"') { inQuote = !inQuote; } else if (c == ',' && !inQuote) { list.Add(current.ToString()); current.Clear(); } else { current.Append(c); } } list.Add(current.ToString()); return(list); }; List <CEPStage> stages = new List <CEPStage>(); IList <string> firstLine = null; foreach (string line in System.IO.File.ReadAllLines(csv, Encoding.UTF8)) { if (firstLine == null) { firstLine = split(line); } else { CEPStage s = new CEPStage(); int i = 0; foreach (string cell in split(line)) { if (cell != "") { var prop = typeof(CEPStage).GetProperty(firstLine[i]); if (prop?.PropertyType == typeof(bool)) { prop.SetValue(s, bool.Parse(cell)); } else { prop?.SetValue(s, cell); } } i++; } stages.Add(s); } } byte[] gct = System.IO.File.ReadAllBytes(gctPath); var sss = new BrawlManagerLib.CustomSSSCodeset(gct); foreach (CEPStage s in stages) { try { string relname = StageIDMap.RelNameForPac(s.Filename, true); using (var stream = new FileStream(Path.Combine(relpath, relname), FileMode.Open, FileAccess.Read)) { stream.Seek(3, SeekOrigin.Begin); s.ModuleBase = RelNames[stream.ReadByte()]; } } catch (FileNotFoundException) { } if (s.Alternate) { continue; } int iconId = sss.IconForStage(s.Stage.ID); TextureContainer tc = new TextureContainer(sc_selmap, iconId); if (tc.icon_tex0 != null) { using (MemoryStream ms = new MemoryStream()) { using (Bitmap b = tc.icon_tex0.GetImage(0)) { b.Save(ms, ImageFormat.Png); s.PngIcon = ms.ToArray(); } } } } MSBinNode info = (MSBinNode)info_pac.FindChild("MiscData[140]", true); var common2_titledata = new List <SongNameBar.SongIndexEntry>(0); foreach (ResourceNode child in common2.Children) { if (child is Common2MiscDataNode) { SndBgmTitleDataNode sndBgmTitleData = child.Children.FirstOrDefault() as SndBgmTitleDataNode; if (sndBgmTitleData != null) { common2_titledata = sndBgmTitleData.Children.Select(n => new SongNameBar.SongIndexEntry() { ID = (ushort)((SndBgmTitleEntryNode)n).ID, Index = ((SndBgmTitleEntryNode)n).SongTitleIndex }).ToList(); break; } } } List <string> brstms = Directory.EnumerateFiles(brstmPath) .Select(s => Path.GetFileNameWithoutExtension(s)).ToList(); var sdsl = new StageDependentSongLoader(gct); foreach (CEPStage stage in stages) { Song song = sdsl.GetSong(stage.Stage.ID); if (song != null) { stage.SongFilename = song.Filename; stage.SongTitle = info._strings[common2_titledata.Where(c => c.ID == song.ID).Select(c => c.Index).First()]; //brstms.RemoveAll(s => s == song.Filename); } } var expStages = stages.Where(s => s.Filename.Contains("CUSTOM")); return(View(new MainModel { Stages = stages.Except(expStages).Concat(expStages).ToList(), Songs = brstms.Select(b => { var song = SongIDMap.Songs.SingleOrDefault(s => s.Filename == b); return new CEPSong { SongFilename = b, SongTitle = info._strings[( from c in common2_titledata where c.ID == song.ID select c.Index ).SingleOrDefault()], OriginalSongTitle = b.StartsWith("0000") ? null : song.DefaultName }; }) })); }