public static void GetObjectInfos(string fileName, Dictionary <string, List <ObjectInfo> > infosByListName) { string levelName; string categoryName; string levelNameWithSuffix = Path.GetFileName(fileName); if (fileName.EndsWith(SM3DWorldZone.MAP_SUFFIX)) { levelName = levelNameWithSuffix.Remove(levelNameWithSuffix.Length - SM3DWorldZone.MAP_SUFFIX.Length); categoryName = "Map"; } else if (fileName.EndsWith(SM3DWorldZone.DESIGN_SUFFIX)) { levelName = levelNameWithSuffix.Remove(levelNameWithSuffix.Length - SM3DWorldZone.DESIGN_SUFFIX.Length); categoryName = "Design"; } else if (fileName.EndsWith(SM3DWorldZone.SOUND_SUFFIX)) { levelName = levelNameWithSuffix.Remove(levelNameWithSuffix.Length - SM3DWorldZone.SOUND_SUFFIX.Length); categoryName = "Sound"; } else { return; } SarcData sarc = SARC.UnpackRamN(YAZ0.Decompress(fileName)); GetObjectInfos(infosByListName, levelName, categoryName, sarc); }
void SarcEditor(object sender, EventArgs e) { OpenFileDialog opn = new OpenFileDialog() { Filter = "szs file|*.szs|every file|*.*" }; if (opn.ShowDialog() != DialogResult.OK) { return; } byte[] file = File.ReadAllBytes(opn.FileName); if (file[0] == 'S' && file[1] == 'A' && file[2] == 'R' && file[3] == 'C') { new SarcEditor(SARC.UnpackRamN(file)).Show(); } else if (file[0] == 'Y' && file[1] == 'a' && file[2] == 'z' && file[3] == '0') { new SarcEditor(SARC.UnpackRamN(YAZ0.Decompress(file))).Show(); } else { MessageBox.Show("Unknown file format"); } }
private void button2_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog { Filter = "SZS files (*.szs)|*.szs", FilterIndex = 1, CheckFileExists = true, CheckPathExists = true, Multiselect = false, Title = "Search for a Switch Stage.", DefaultExt = ".szs", InitialDirectory = Directory.GetCurrentDirectory() }; if (open.ShowDialog().IsResult(DialogResult.OK)) { var dict = new Dictionary <string, byte[]>(); var data = YAZ0.Decompress(open.FileName).LoadAsSarcData(); foreach (var item in data.GetSarcFiles()) { dict.Add(item.Key, item.Value); listView2.Items.Add(item.Key); } Switch_Files = dict; Hash = data.HashOnly; Switch_File = new FileInfo(open.FileName); } }
public void FormLoaded() { if (!Directory.Exists(ModelsFolder)) { Directory.CreateDirectory(ModelsFolder); ZipArchive z = new ZipArchive(new MemoryStream(Resources.baseModels)); z.ExtractToDirectory(ModelsFolder); } if (!Directory.Exists($"{ModelsFolder}/Textures")) { if (GameFolder == "" || !Directory.Exists(GameFolder)) { MessageBox.Show("The game path is not set or not valid, can't extract texture archives"); } else { Directory.CreateDirectory($"{ModelsFolder}/Textures"); MessageBox.Show($"The game texture archives will be extracted in {ModelsFolder}/Textures, this might take a while"); LoadingForm.ShowLoading(ViewForm as Form, "Extracting textures...\r\nThis might take a while"); foreach (var a in Directory.GetFiles($"{GameFolder}ObjectData\\").Where(x => x.EndsWith("Texture.szs") || x.EndsWith("Textures.szs"))) { var Sarc = SARCExt.SARC.UnpackRam(YAZ0.Decompress(File.ReadAllBytes(a))); string keyName = Path.GetFileNameWithoutExtension(a) + ".bch"; if (!Sarc.ContainsKey(keyName)) { continue; } var mod = Ohana3DS_Rebirth.Ohana.Models.BCH.load(new MemoryStream(Sarc[keyName])); Ohana3DS_Rebirth.Ohana.Models.GenericFormats.OBJ.ExportTextures(mod, ModelsFolder); } LoadingForm.EndLoading(); } } }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog { Filter = "szs file (*.szs)|*.szs|All files (*.*)|*.*", FilterIndex = 1, Multiselect = false, Title = "Search for a szs file", CheckFileExists = true, CheckPathExists = true, DefaultExt = ".szs", InitialDirectory = Directory.GetCurrentDirectory() }; if (open.ShowDialog() == DialogResult.OK) { Data = YAZ0.Decompress(open.FileName.ReadBytes()).LoadAsSarcData(); listBox1.Items.Clear(); foreach (var item in Data.Files) { listBox1.Items.Add(item.Key); } label2.Text = Data.endianness.ToString(); } }
public void Save() { byte[] tmp = ToByaml(); //File.WriteAllBytes("Test.byml", tmp); //BymlFileData Output = new BymlFileData() { Version = 1, SupportPaths = false, byteOrder = Syroot.BinaryData.Endian.Big }; //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.BigEndian, Files = new Dictionary <string, byte[]>() }; Data.Files.Add("StageList.byml", tmp); Tuple <int, byte[]> x = SARC.PackN(Data); File.WriteAllBytes(Filename, YAZ0.Compress(x.Item2)); //File.WriteAllBytes("Broken.byml", Data.Files["StageList.byml"]); }
private void decompressBtn_Click(object sender, EventArgs e) { if (openSZSDialog.ShowDialog() == DialogResult.OK) { string of = openSZSDialog.FileName; if (IsYaz0(of)) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { string ep = folderBrowserDialog1.SelectedPath; YAZ0 y = new YAZ0(); NARC f = new NARC(y.Decompress(File.ReadAllBytes(of))); foreach (SFSFile file in f.ToFileSystem().Files) { Console.WriteLine(file.FileName); File.WriteAllBytes(ep + "\\" + file.FileName, file.Data); } MessageBox.Show("Done!"); } } else { MessageBox.Show("The SZS file is not compressed with Yaz0."); } } }
private bool LoadModelWithBase(string basePath, string modelName) { // Attempt to load the bfres that contains the model string modelPath = "Models\\" + modelName + ".bfres"; if (File.Exists(modelPath)) { // Load the bfres LoadBfres(modelPath); return(true); } // Check if the szs archive that contains the bfres exists string szsPath = basePath + modelName + ".szs"; if (File.Exists(szsPath)) { // Decompress the szs into a sarc archive string sarcPath = basePath + modelName; SARC sarc = new SARC(); var unpackedmodel = sarc.unpackRam(YAZ0.Decompress(szsPath)); if (!unpackedmodel.ContainsKey(modelName + ".bfres")) { return(false); } File.WriteAllBytes(modelPath, unpackedmodel[modelName + ".bfres"]); // Load the bfres LoadBfres(modelPath); return(true); } return(false); }
static void SaveCompressedResFile(ResFile resFile, string path) { var mem = new MemoryStream(); resFile.Save(mem); File.WriteAllBytes(path, YAZ0.Compress(mem.ToArray())); }
private void compressBtn_Click(object sender, EventArgs e) { if (openZIPDialog.ShowDialog() == DialogResult.OK) { YAZ0 y = new YAZ0(); NARC SzsArch = new NARC(); SFSDirectory dir = new SFSDirectory("", true); using (ZipFile z = ZipFile.Read(openZIPDialog.FileName)) { for (int i = 0; i < z.Entries.Count; i++) { ZipEntry ze = z.Entries.ToArray()[i]; SFSFile file = new SFSFile(i, ze.FileName, dir); MemoryStream data = new MemoryStream(); ze.Extract(data); file.Data = data.ToArray(); data.Dispose(); dir.Files.Add(file); } foreach (ZipEntry ze in z) { Console.WriteLine(ze); } } SzsArch.FromFileSystem(dir); if (saveSZSDialog.ShowDialog() == DialogResult.OK) { File.WriteAllBytes(saveSZSDialog.FileName, y.Compress(SzsArch.Write())); MessageBox.Show("Done!"); } } }
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); }
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"]); }
public void SaveCompressedModernFile(Stream FS) { FS.Write(new byte[6] { 0x4C, 0x43, 0x50, 0x43, 0x4E, 0x57 }, 0, 4); byte[] Result = YAZ0.Compress(SaveModernFile()).ToArray(); FS.Write(Result, 0, Result.Length); }
public static void ReloadModel(string ModelName) { if (cache.ContainsKey(ModelName)) { cache.Remove(ModelName); Submit(ModelName, new MemoryStream(SARC.UnpackRamN(new MemoryStream(YAZ0.Decompress(Program.TryGetPathViaProject("ObjectData", ModelName + ".szs")))).Files[ModelName + ".bfres"])); } }
public static void ExportCollisionFromObject(string ObjectDataFolder) { var opn = new OpenFileDialog() { InitialDirectory = Directory.Exists(ObjectDataFolder) ? ObjectDataFolder : null, Filter = "szs file | *.szs", Title = "Select an Object which has a collision model" }; if (opn.ShowDialog() != DialogResult.OK) { return; } var szs = SARC.UnpackRam(YAZ0.Decompress(opn.FileName)); foreach (string name in szs.Keys) { if (name.EndsWith(".kcl")) { List <Color> typeColors = null; string attributeFileName = Path.GetFileNameWithoutExtension(name) + "Attribute.byml"; if (szs.ContainsKey(attributeFileName)) { typeColors = GetKCLColors(szs[attributeFileName]); } var sav = new SaveFileDialog() { FileName = name + ".obj", Filter = "obj file|*.obj" }; if (sav.ShowDialog() != DialogResult.OK) { return; } var mod = new MarioKart.MK7.KCL(szs[name]).ToOBJ().toWritableObj(); if (typeColors != null) { for (int i = 0; i < mod.Materials.Count; i++) { if (i >= typeColors.Count) { break; } mod.Materials[i].Colors.normal.X = typeColors[i].R / 255f; mod.Materials[i].Colors.normal.Y = typeColors[i].G / 255f; mod.Materials[i].Colors.normal.Z = typeColors[i].B / 255f; } } mod.WriteObj(sav.FileName); } } }
public void LoadCompressedModernFile(Stream FS) { FS.Position += 2; byte[] Bytes = FS.Read(0, (int)(FS.Length - FS.Position)); MemoryStream MS = new MemoryStream(YAZ0.Decompress(Bytes)) { Position = 0x06 }; LoadModernFile(MS); }
static ResFile LoadBFRES(string filename, bool compressed) { if (compressed) { return(new ResFile(new MemoryStream(YAZ0.Decompress(filename)))); } else { return(new ResFile(filename)); } }
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"]); }
private void button3_Click(object sender, EventArgs e) { var new_dict = new Dictionary <string, byte[]>(); foreach (var item in WiiU_Files) { if (!item.Key.EndsWith(".byml")) { var m = new MemoryStream(); m.Write(item.Value, 0, item.Value.Length); var b = m.ReadStream(); b.ByteOrder = ByteOrder.LittleEndian; var data = b.GetBytes(); b.Dispose(); m.Dispose(); new_dict.Add(item.Key, data); } else { var m = new MemoryStream(item.Value); var d = m.GetByml(); d.byteOrder = ByteOrder.LittleEndian; var data = d.GetBytes(); m.Dispose(); new_dict.Add(item.Key, data); } } var Data = new SarcData { HashOnly = Hashs[0], Files = new_dict, endianness = ByteOrder.LittleEndian }; var name = WiiU_File.Name.Substring(0, WiiU_File.Name.Length - 8); var src = YAZ0.Compress(Data.PackSarcData().GetBytes()); SaveFileDialog save = new SaveFileDialog { Filter = "Szs files (*.szs)|*.szs|All files (*.*)|*.*", FilterIndex = 1, Title = "Save the new Stage.", DefaultExt = ".szs", CheckPathExists = true, InitialDirectory = Directory.GetCurrentDirectory(), OverwritePrompt = true, FileName = name }; if (save.ShowDialog().IsResult(DialogResult.OK)) { File.WriteAllBytes(save.FileName, src); MessageBox.Show("Complete!"); } }
byte[] BfresFromSzs(string fileName) { if (File.Exists($"{GameFolder}ObjectData\\{fileName}.szs")) { var SzsFiles = SARC.UnpackRam(YAZ0.Decompress($"{GameFolder}ObjectData\\{fileName}.szs")); if (SzsFiles.ContainsKey(fileName + ".bfres")) { return(SzsFiles[fileName + ".bfres"]); } } return(null); }
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 static void GetObjectInfos(string fileName, Dictionary <string, List <ObjectInfo> > infosByListName) { string levelName; string categoryName; string fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName); if (fileNameWithoutExt.EndsWith("Map1")) { levelName = fileNameWithoutExt.Remove(fileNameWithoutExt.Length - 4); categoryName = "Map"; } else if (fileNameWithoutExt.EndsWith("Design1")) { levelName = fileNameWithoutExt.Remove(fileNameWithoutExt.Length - 7); categoryName = "Design"; } else if (fileNameWithoutExt.EndsWith("Sound1")) { levelName = fileNameWithoutExt.Remove(fileNameWithoutExt.Length - 6); categoryName = "Sound"; } else { return; } SarcData sarc = SARC.UnpackRamN(YAZ0.Decompress(fileName)); Dictionary <long, ObjectInfo> objectInfosByReference = new Dictionary <long, ObjectInfo>(); ByamlIterator byamlIter = new ByamlIterator(new MemoryStream(sarc.Files[levelName + categoryName + ".byml"])); foreach (DictionaryEntry entry in byamlIter.IterRootDictionary()) { if (!infosByListName.ContainsKey(entry.Key)) { continue; } List <ObjectInfo> objectInfos = new List <ObjectInfo>(); foreach (ArrayEntry obj in entry.IterArray()) { objectInfos.Add(ParseObjectInfo(obj, objectInfosByReference, infosByListName, entry.Key)); } } }
private void replaceToolStripMenuItem_Click(object sender, EventArgs e) { byte[] compressedSarc = null; var s = SARC.PackN(loadedSarc); if (numericUpDown1.Value != 0) { compressedSarc = YAZ0.Compress(s.Item2, (int)numericUpDown1.Value, (uint)s.Item1); } else { compressedSarc = s.Item2; } //sourceStream.Position = 0; sourceStream.Write(compressedSarc, 0, compressedSarc.Length); }
public void OpenFile(string filename, Stream file) { byte[] data; if (file is MemoryStream) { data = ((MemoryStream)file).ToArray(); } else { var s = new MemoryStream(); file.CopyTo(s); data = s.ToArray(); s.Dispose(); } OpenFileHandler.OpenFile(filename, new MemoryStream(YAZ0.Decompress(data))); }
static void ConvertARC(string filePath) { string name = Path.GetFileName(filePath); RARC_Parser rarc = new RARC_Parser(new MemoryStream(YAZ0.Decompress(filePath))); rarc.IsLittleEndian = true; foreach (var file in rarc.Files) { ConvertFile(file); } var mem = new MemoryStream(); rarc.Save(mem); File.WriteAllBytes($"Output/{name}", YAZ0.Compress(mem.ToArray())); }
public static void GetObjectInfosCombined(string fileName, Dictionary <string, List <ObjectInfo> > MAPinfosByListName, Dictionary <string, List <ObjectInfo> > DESIGNinfosByListName, Dictionary <string, List <ObjectInfo> > SOUNDinfosByListName) { string levelName; string levelNameWithSuffix = Path.GetFileName(fileName); levelName = levelNameWithSuffix.Remove(levelNameWithSuffix.Length - SM3DWorldZone.COMBINED_SUFFIX.Length); SarcData sarc = SARC.UnpackRamN(YAZ0.Decompress(fileName)); GetObjectInfos(MAPinfosByListName, levelName, "Map", sarc); GetObjectInfos(DESIGNinfosByListName, levelName, "Design", sarc); GetObjectInfos(SOUNDinfosByListName, levelName, "Sound", sarc); }
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))); } }
// Code to convert models return false == fail public bool ConvertModelFile(string ObjName, string path) { try { string targetSZS = Path.Combine(GameFolder, "ObjectData", ObjName + ".szs"); if (!File.Exists(targetSZS)) return false; var Sarc = SARCExt.SARC.UnpackRam(YAZ0.Decompress(File.ReadAllBytes(targetSZS))); string keyName = ObjName + ".bch"; if (!Sarc.ContainsKey(keyName)) return false; var mod = Ohana3DS_Rebirth.Ohana.Models.BCH.load(new MemoryStream(Sarc[keyName])); Ohana3DS_Rebirth.Ohana.Models.GenericFormats.OBJ.export(mod, path, 0); } catch { return false; } return true; }
public ILevel LoadLevel(string file = null) { if (file == null) { var opn = new OpenFileDialog() { Filter = LevelFormatFilter }; if (opn.ShowDialog() != DialogResult.OK) { return(null); } file = opn.FileName; } var res = new Level(file); string stageName = new DirectoryInfo(file).Parent.Name; string stageModelPath = $"{ModelsFolder}\\{stageName}.obj"; if (!File.Exists(stageModelPath)) { byte[] CourseBfres = YAZ0.Decompress(Path.GetDirectoryName(file) + "\\course_model.szs"); if (BfresConverter.Convert(CourseBfres, ModelsFolder) == null) { stageModelPath = null; } } if (stageModelPath != null) { StageDummyModel = new LevelObj(false, true); StageDummyModel.ModelName = $"{stageName}"; StageDummyModel.Scale = new System.Windows.Media.Media3D.Vector3D(1, 1, 1); res.objs["StageModel - Can't edit"].Add(StageDummyModel); } GC.Collect(); return(res); }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { var sav = new SaveFileDialog() { Filter = "szs file|*.szs|sarc file|*.sarc" }; if (sav.ShowDialog() != DialogResult.OK) { return; } if (numericUpDown1.Value == 0) { File.WriteAllBytes(sav.FileName, SARC.PackN(loadedSarc).Item2); } else { var s = SARC.PackN(loadedSarc); File.WriteAllBytes(sav.FileName, YAZ0.Compress(s.Item2, (int)numericUpDown1.Value, (uint)s.Item1)); } }