private void OpenSzsFile_click(object sender, EventArgs e) { string name = ((ToolStripMenuItem)sender).Text; var byml = ByamlFile.Load(new MemoryStream(LoadedLevel.SzsFiles[name]), false, Syroot.BinaryData.ByteOrder.LittleEndian); new RedCarpet.ByamlViewer(byml).Show(); }
void LoadObjects(int scenarioIndex = -1) { Stream s = new MemoryStream(SzsFiles[Path.GetFileNameWithoutExtension(Filename) + ".byml"]); LoadedByml = ByamlFile.Load(s, false, Syroot.BinaryData.ByteOrder.LittleEndian); if (scenarioIndex == -1) { string res = "0"; InputDialog.Show("Select scenario", $"enter scenario value [0,{LoadedByml.Count- 1}]", ref res); if (!int.TryParse(res, out scenarioIndex)) { scenarioIndex = 0; } } _ScenarioIndex = scenarioIndex; var Scenario = (Dictionary <string, dynamic>)LoadedByml[scenarioIndex]; if (Scenario.Keys.Count == 0) { Scenario.Add("ObjectList", new List <dynamic>()); } foreach (string k in Scenario.Keys) { objs.Add(k, new ObjList(k, Scenario[k])); } }
public static bool TryOpen(string filename, out StageList stageList) { stageList = null; SarcData sarc = SARC.UnpackRamN(YAZ0.Decompress(filename)); BymlFileData byml; if (sarc.Files.ContainsKey("StageList.byml")) { byml = ByamlFile.LoadN(new MemoryStream(sarc.Files["StageList.byml"]), true, ByteOrder.BigEndian); } else { throw new Exception("Failed to find the StageList"); } if (!byml.RootNode.TryGetValue("WorldList", out dynamic worldList)) { return(false); } List <World> worlds = new List <World>(); for (int i = 0; i < worldList.Count; i++) { worlds.Add(new World(worldList[i])); } stageList = new StageList(filename, worlds, byml.byteOrder); return(true); }
static void Main(string[] args) { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length > 0) { foreach (var arg in args) { var f = new FileInfo(arg); if (f.Extension == ".byml") { var b = File.ReadAllBytes(f.FullName); var m = new MemoryStream(b); var byml = m.GetByml(); var y = byml.ToYaml(); Directory.SetCurrentDirectory(f.Directory.FullName); var n = Path.GetFileNameWithoutExtension(f.FullName); using var s = new StreamWriter(n + ".yml"); s.Write(y); s.Close(); } else if (f.Extension == ".yml") { var y = f.FullName.FromYaml(); var b = ByamlFile.SaveN(y); Directory.SetCurrentDirectory(f.Directory.FullName); var n = Path.GetFileNameWithoutExtension(f.FullName); File.WriteAllBytes(n + ".byml", b); } } } }
public void LoadObjList() { if (PluginRuntime.Mk8GamePath == "") { FolderSelectDialog dlg = new FolderSelectDialog(); if (dlg.ShowDialog() == DialogResult.OK) { PluginRuntime.Mk8GamePath = dlg.SelectedPath; } } var byml = ByamlFile.LoadN($"{PluginRuntime.Mk8GamePath}/Data/Objflow.byaml", true).RootNode; foreach (var item in byml) { int ID = item["ObjId"]; List <string> files = ((IList <object>)item["ResName"]).Cast <string>().ToList(); ObjIDNameList.Add(ID, files[0]); Console.WriteLine(ID + " " + files[0]); } byml = null; GC.Collect(); }
public void FormLoaded() { if (!Directory.Exists(ModelsFolder)) { Directory.CreateDirectory(ModelsFolder); } if (!File.Exists($"{GameFolder}Data/Objflow.byaml")) { MessageBox.Show($"Can't open {GameFolder}Data/Objflow.byaml models and object names won't be shown"); } else { ObjIDNameList.Clear(); var byml = ByamlFile.LoadN($"{GameFolder}Data/Objflow.byaml", true).RootNode; foreach (var item in byml) { int ID = item["ObjId"]; List <string> files = ((IList <object>)item["ResName"]).Cast <string>().ToList(); if (/*files.Count > 1 || */ files.Count == 0) { Debugger.Break(); } ObjIDNameList.Add(ID, files[0]); } byml = null; GC.Collect(); } }
/// <summary> /// Loads part data from the given suffix and model name. /// This will attach the part to a joint of the current actor model and add to the PartActors list. /// </summary> public void LoadPart(string suffix, string modelName) { string path = $"{GlobalSettings.GamePath}\\ObjectData\\{modelName}.szs"; if (!File.Exists(path)) { Console.WriteLine($"Failed to find part at path {path}!"); return; } //Init parameter data var partParams = Files[$"InitPartsFixInfo{suffix}.byml"]; var partModel = new PartsModel(ByamlFile.LoadN(partParams.FileData).RootNode); var actor = new ActorBase(); actor.LoadActor(path); PartActors.Add(modelName, actor); if (actor.ModelFile == null) { Console.WriteLine($"Failed to find model for {modelName}!"); return; } //Parts attach to joints of the current model from the part model AttachJoint(partModel, actor.ModelFile); }
static List <Color> GetKCLColors(byte[] byml) { var attributeFile = ByamlFile.FastLoadN(new MemoryStream(byml)); var typeColors = new List <Color>(); foreach (dynamic attrib in attributeFile.RootNode) { Console.WriteLine(attrib["FloorCode"]); switch (attrib["FloorCode"]) { case "Ground": typeColors.Add(Color.FromArgb(255, 200, 200, 200)); break; case "DamageFire": case "DamageFire2D": typeColors.Add(Color.FromArgb(255, 200, 50, 0)); break; case "Poison": case "Poison2D": typeColors.Add(Color.FromArgb(255, 255, 0, 200)); break; case "SandSink": typeColors.Add(Color.FromArgb(255, 10, 30, 0)); break; case "Skate": typeColors.Add(Color.FromArgb(255, 0, 220, 255)); break; default: typeColors.Add(Color.FromArgb(255, 255, 255, 255)); break; } } return(typeColors); }
public StageList(string input) { Filename = input; BymlFileData Input; SarcData Data = SARC.UnpackRamN(YAZ0.Decompress(input)); if (Data.Files.ContainsKey("StageList.byml")) { Input = ByamlFile.LoadN(new MemoryStream(Data.Files["StageList.byml"]), true, ByteOrder.BigEndian); } else { throw new Exception("Failed to find the StageList"); } List <dynamic> temp = Input.RootNode["WorldList"]; for (int i = 0; i < temp.Count; i++) { Worlds.Add(new World(temp[i])); } //File.WriteAllBytes("Original.byml",Data.Files["StageList.byml"]); }
private void Main_Load(object sender, EventArgs e) { if (Args.Length > 0) { foreach (var arg in Args) { var f = new FileInfo(arg); if (f.Extension == ".byml") { var b = File.ReadAllBytes(f.FullName); var m = new MemoryStream(b); var byml = m.GetByml(); var y = byml.ToYaml(); Directory.SetCurrentDirectory(f.Directory.FullName); using var s = new StreamWriter(f.Name + ".yml"); s.Write(y); s.Close(); } else if (f.Extension == ".yml") { var y = f.FullName.FromYaml(); var b = ByamlFile.SaveN(y); Directory.SetCurrentDirectory(f.Directory.FullName); File.WriteAllBytes(f.Name + ".byml", b); } } } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { if (args.Length > 0) { foreach (var arg in args) { var f = new FileInfo(arg); if (f.Extension == ".byml") { var b = File.ReadAllBytes(f.FullName); var m = new MemoryStream(b); var byml = m.GetByml(); var y = byml.ToYaml(); Directory.SetCurrentDirectory(f.Directory.FullName); var n = Path.GetFileNameWithoutExtension(f.FullName); var s = new StreamWriter(n + ".yml"); s.Write(y); s.Close(); } else if (f.Extension == ".yml") { var y = f.FullName.FromYaml(); var b = ByamlFile.SaveN(y); Directory.SetCurrentDirectory(f.Directory.FullName); var n = Path.GetFileNameWithoutExtension(f.FullName); File.WriteAllBytes(n + ".byml", b); } } } else { Console.WriteLine("Enter a file here."); var R = Console.ReadLine(); var f = new FileInfo(R); if (f.Exists) { if (f.Extension == ".byml") { var b = File.ReadAllBytes(f.FullName); var m = new MemoryStream(b); var byml = m.GetByml(); var y = byml.ToYaml(); Directory.SetCurrentDirectory(f.Directory.FullName); var n = Path.GetFileNameWithoutExtension(f.FullName); var s = new StreamWriter(n + ".yml"); s.Write(y); s.Close(); } else if (f.Extension == ".yml") { var y = f.FullName.FromYaml(); var b = ByamlFile.SaveN(y); Directory.SetCurrentDirectory(f.Directory.FullName); var n = Path.GetFileNameWithoutExtension(f.FullName); File.WriteAllBytes(n + ".byml", b); } } } }
public static void OpenByml(Stream file, BYAML byaml, string FileName, bool?paths, Stream saveStream, bool AsDialog) { bool _paths = paths == null?SupportPaths() : paths.Value; var byml = ByamlFile.LoadN(file, _paths); OpenByml(byml, byaml, saveStream, AsDialog); }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { saveStream.Position = 0; saveStream.SetLength(0); ByamlFile.SaveN(saveStream, new BymlFileData { Version = bymlVer, byteOrder = byteOrder, SupportPaths = pathSupport, RootNode = byml }); }
public void Load(Stream stream) { CanSave = true; IsDialog = IFileInfo != null && IFileInfo.InArchive; data = ByamlFile.LoadN(stream); }
private static void ParseYML(string FileName) { BymlFileData data = ByamlFile.LoadN(FileName, true); var serializer = new SharpYaml.Serialization.Serializer(); var text = serializer.Serialize(data); Console.WriteLine(text); }
public void Load(Stream stream) { CanSave = true; //Keep the stream open. //This is for the file to optionally be reloaded for different encoding types IsDialog = IFileInfo != null && IFileInfo.InArchive; BymlData = ByamlFile.LoadN(stream); }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sav = new SaveFileDialog(); sav.Filter = "byml file | *.byml"; if (sav.ShowDialog() == DialogResult.OK) { ByamlFile.Save(sav.FileName, byml); } }
public void Save(System.IO.Stream stream) { ByamlFile.SaveN(stream, new BymlFileData { Version = BymlData.Version, byteOrder = BymlData.byteOrder, SupportPaths = BymlData.SupportPaths, RootNode = BymlData.RootNode }); }
public byte[] ToByaml() { ApplyChangesToByml(); MemoryStream mem = new MemoryStream(); ByamlFile.Save(mem, LoadedByml, false, Syroot.BinaryData.ByteOrder.LittleEndian); var res = mem.ToArray(); return(res); }
private void SaveAttributeByml(bool UpdateArchive = false) { if (AttributeByml == null || AttributeByml.RootNode == null) { return; } string byml = $"{Path.GetFileNameWithoutExtension(Text)}Attribute.byml"; if (IFileInfo.ArchiveParent != null) { foreach (var file in IFileInfo.ArchiveParent.Files) { if (file.FileName == byml) { var mem = new MemoryStream(); ByamlFile.SaveN(mem, new BymlFileData { Version = AttributeByml.Version, byteOrder = AttributeByml.byteOrder, SupportPaths = AttributeByml.SupportPaths, RootNode = AttributeByml.RootNode }); file.FileData = mem.ToArray(); //Reload the file format if (file.FileFormat != null) { file.FileFormat = null; file.FileFormat = file.OpenFile(); } } } } else if (!UpdateArchive) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Supported Formats|*.byml"; sfd.FileName = byml; sfd.DefaultExt = ".byml"; if (sfd.ShowDialog() == DialogResult.OK) { using (var fileStream = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write)) { ByamlFile.SaveN(fileStream, new BymlFileData { Version = AttributeByml.Version, byteOrder = AttributeByml.byteOrder, SupportPaths = AttributeByml.SupportPaths, RootNode = AttributeByml.RootNode }); } } } }
public void Save() { //byte[] tmp = ToByaml(); //File.WriteAllBytes("Test.byml", tmp); BymlFileData Output = new BymlFileData() { Version = 1, SupportPaths = false, byteOrder = ByteOrder }; Dictionary <string, dynamic> FinalRoot = new Dictionary <string, dynamic>(); List <dynamic> worlds = new List <dynamic>(); for (int i = 0; i < Worlds.Count; i++) { worlds.Add(Worlds[i].ToByaml()); } FinalRoot.Add("WorldList", worlds); Output.RootNode = FinalRoot; SarcData Data = new SarcData() { byteOrder = ByteOrder, Files = new Dictionary <string, byte[]>() }; Data.Files.Add("StageList.byml", ByamlFile.SaveN(Output)); Tuple <int, byte[]> x = SARC.PackN(Data); if (Filename.StartsWith(Program.GamePath) && !string.IsNullOrEmpty(Program.ProjectPath)) { switch (MessageBox.Show( Program.CurrentLanguage.GetTranslation("SaveStageListInProjectText") ?? "Would you like to save the StageList.szs to your ProjectPath instead of your BaseGame?", Program.CurrentLanguage.GetTranslation("SaveStageListInProjectHeader") ?? "Save in ProjectPath", MessageBoxButtons.YesNoCancel)) { case DialogResult.Yes: Directory.CreateDirectory(Path.Combine(Program.ProjectPath, "SystemData")); Filename = Path.Combine(Program.ProjectPath, "SystemData", "StageList.szs"); break; case DialogResult.No: break; case DialogResult.Cancel: return; } } File.WriteAllBytes(Filename, YAZ0.Compress(x.Item2)); //File.WriteAllBytes("Broken.byml", Data.Files["StageList.byml"]); }
public byte[] Save() { MemoryStream mem = new MemoryStream(); ByamlFile.SaveN(mem, new BymlFileData { Version = data.Version, byteOrder = data.byteOrder, SupportPaths = data.SupportPaths, RootNode = data.RootNode }); return(mem.ToArray()); }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sav = new SaveFileDialog() { FileName = FileName, Filter = "byml file | *.byml" }; if (sav.ShowDialog() == DialogResult.OK) { ByamlFile.SaveN(sav.FileName, new BymlFileData { Version = bymlVer, byteOrder = byteOrder, SupportPaths = pathSupport, RootNode = byml }); } }
public void parseBYML(string name) { //calling it Object wasn't a great idea, i stared at the code for half hour before realizing that it's a custom class lol loadedMap = new Object(); if (name.EndsWith("Map1.byml")) //the szs name always ends with 1, but the map byml doesn't, this seems to be true for every level { loadedBymlFileName = name.Replace("Map1.byml", "Map.byml"); } else if (name.EndsWith("Design1.byml")) { loadedBymlFileName = name.Replace("Design1.byml", "Design.byml"); } else if (name.EndsWith("Sound1.byml")) { loadedBymlFileName = name.Replace("Sound1.byml", "Sound.byml"); } else { loadedBymlFileName = name; } LoadedByml = ByamlFile.Load(new MemoryStream(LoadedSarc[loadedBymlFileName])); foreach (string k in LoadedByml.Keys) { if (!(LoadedByml[k] is List <dynamic>)) { continue; } SectionSelect.Items.Add(k); loadedMap.mobjs.Add(k, new List <MapObject>()); LoadObjectsSection(k); } if (SectionSelect.Items.Contains("Objs")) { SectionSelect.SelectedItem = "Objs"; } else if (SectionSelect.Items.Contains("ObjectList")) { SectionSelect.SelectedItem = "ObjectList"; } else { SectionSelect.SelectedIndex = 0; } cpath.Text = LoadedByml["FilePath"]; }
private void bymlViewerToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog opn = new OpenFileDialog(); opn.InitialDirectory = BASEPATH + "StageData"; opn.Filter = "byml files, szs files |*.byml;*.szs"; if (opn.ShowDialog() != DialogResult.OK) { return; } dynamic byml = null; if (opn.FileName.EndsWith("byml")) { byml = ByamlFile.Load(opn.FileName); } else if (opn.FileName.EndsWith("szs")) { SARC sarc = new SARC(); var unpackedsarc = sarc.unpackRam(YAZ0.Decompress(opn.FileName)); string bymlName = Path.GetFileNameWithoutExtension(opn.FileName) + ".byml"; if (bymlName.EndsWith("Map1.byml")) //the szs name always ends with 1, but the map byml doesn't, this seems to be true for every level { bymlName = bymlName.Replace("Map1.byml", "Map.byml"); } else if (bymlName.EndsWith("Design1.byml")) { bymlName = bymlName.Replace("Design1.byml", "Design.byml"); } else if (bymlName.EndsWith("Sound1.byml")) { bymlName = bymlName.Replace("Sound1.byml", "Sound.byml"); } byml = ByamlFile.Load(new MemoryStream(unpackedsarc[bymlName])); } else { throw new Exception("Not supported"); } if (byml is Dictionary <string, dynamic> ) { new ByamlViewer(byml).Show(); } else { throw new Exception("Not supported"); } }
public Level(bool empty, string levelN) { if (!empty) { throw new Exception(); } SzsFiles = new Dictionary <string, byte[]>(); Filename = levelN; LoadedByml = new dynamic[15]; for (int i = 0; i < 15; i++) { LoadedByml[i] = new Dictionary <string, dynamic>(); } SzsFiles.Add(Path.GetFileNameWithoutExtension(Filename) + ".byml", ByamlFile.Save(LoadedByml, false, Syroot.BinaryData.ByteOrder.LittleEndian)); LoadObjects(); }
private void convertToLittleEndianToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog d = new OpenFileDialog()) { if (d.ShowDialog() == DialogResult.OK) { dynamic byaml = ByamlFile.Load(d.FileName, SupportPaths, byteOrder); ByamlFile.Save(d.FileName + ".new.byaml", byaml, SupportPaths, byteOrderLE); const string message = "Successfully converted byaml to little endian!"; const string caption = "Success"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void testSaveLevelToolStripMenuItem_Click(object sender, EventArgs e) { if (LoadedByml == null) { return; } MemoryStream mem = new MemoryStream(); ByamlFile.Save(mem, LoadedByml); LoadedSarc[loadedBymlFileName] = mem.ToArray(); SaveFileDialog s = new SaveFileDialog(); s.Filter = "szs file|*.szs"; if (s.ShowDialog() == DialogResult.OK) { File.WriteAllBytes(s.FileName, YAZ0.Compress(SARC.pack(LoadedSarc))); } }
private void convertToBigEndianToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog d = new OpenFileDialog()) { d.Title = "Open File"; d.Filter = "Binary yaml|*.byaml;*.bprm;*.szs;|All files (*.*)|*.*"; if (d.ShowDialog() == DialogResult.OK) { dynamic byaml = ByamlFile.Load(d.FileName, SupportPaths, byteOrderLE); ByamlFile.Save(d.FileName + ".new.byaml", byaml, SupportPaths, byteOrder); const string message = "Successfully converted byaml to big endian!"; const string caption = "Success"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// <summary> /// Loads the actor from an archive file given an IArchiveFile. /// </summary> public void LoadActor(IArchiveFile fileArchive) { //Add files to a lookup for quick searching foreach (var file in fileArchive.Files) { Files.Add(file.FileName, file); //Initalize sub actor data to determine how to display part information if (file.FileName == "InitSubActor.byml") { InitSubActor = new InitSubActor(ByamlFile.LoadN(file.FileData).RootNode); } if (file.FileName == "InitModel.byml") { InitModel = new InitModel(ByamlFile.LoadN(file.FileData).RootNode); } if (file.FileName.EndsWith(".bfres")) //Note there should only be one model file { ModelFile = file.OpenFile() as IRenderableFile; } } }