/// <summary> /// Loads an .mbin file and returns an NMSTemplate which can be either used as-is, or cast to a specific type. /// </summary> /// <param name="path">File path to the .mbin to be loaded into memory.</param> /// <returns>NMSTemplate</returns> public static NMSTemplate LoadMbin(string path) { MBINFile mbin = new MBINFile(path); if (!mbin.Load() || !mbin.Header.IsValid) { throw new InvalidDataException("Not a valid MBIN file!"); } NMSTemplate data = null; try { data = mbin.GetData(); if (data is null) { throw new InvalidDataException("Invalid MBIN data."); } } catch (Exception e) { throw new MbinException($"Failed to read {mbin.Header.GetXMLTemplateName()} from MBIN.", e, path); } mbin.Dispose(); return(data); }
public ulong FileLength = 0; // TODO: fileLength instead of FileLength public static bool IsValid(string path) { if (!File.Exists(path)) { return(false); } using (var mbin = new MBINFile(path)) { return(mbin.Load() ? mbin.Header.IsValid : false); } }
public static NMSTemplate LoadNMSFileOLD(string filepath) { int load_mode = 0; NMSTemplate template; string exmlpath = Path.ChangeExtension(filepath, "exml"); exmlpath = exmlpath.ToUpper(); //Make upper case if (File.Exists(exmlpath)) { load_mode = 0; } else { load_mode = 1; } //Load Exml try { if (load_mode == 0) { string xml = File.ReadAllText(exmlpath); template = EXmlFile.ReadTemplateFromString(xml); } else { if (!File.Exists(filepath)) { throw new FileNotFoundException("File not found\n " + filepath); } libMBIN.MBINFile mbinf = new libMBIN.MBINFile(filepath); mbinf.Load(); template = mbinf.GetData(); mbinf.Dispose(); } } catch (Exception ex) { if (ex is System.IO.DirectoryNotFoundException || ex is System.IO.FileNotFoundException) { Util.showError("File " + filepath + " Not Found...", "Error"); } else if (ex is System.Reflection.TargetInvocationException) { Util.showError("libMBIN failed to decompile the file. Try to update the libMBIN.dll (File->updateLibMBIN). If the issue persists contact the developer", "Error"); } return(null); } return(template); }
public void OpenGEOMDATAFilewithlibMBIN() { string filepath = "E:\\SteamLibrary1\\steamapps\\common\\No Man's Sky\\GAMEDATA\\MODELS\\COMMON\\CHARACTERS\\ASTRONAUT\\ASTRONAUT01.GEOMETRY.MBIN.PC"; //string filepath = "E:\\SteamLibrary1\\steamapps\\common\\No Man's Sky\\GAMEDATA\\MODELS\\COMMON\\CHARACTERS\\ASTRONAUT\\ASTRONAUT01.SCENE.EXML"; //Try to read EXML //TkSceneNodeData t = (TkSceneNodeData)libMBIN.EXmlFile.ReadTemplate(filepath); //Console.WriteLine("All Good Loading", t.Name); try { libMBIN.MBINFile mbinf = new libMBIN.MBINFile(filepath); mbinf.Load(); NMSTemplate template = mbinf.GetData(); mbinf.Dispose(); Console.WriteLine("All Good Loading"); } catch (Exception ex) { Console.WriteLine("Something Went Wrong"); Assert.Fail(); } }
// ===================== // = Main Program Loop = // ===================== public TreeView ParseMbin(string mbinPath) { // going to use the type from the Tuple created in loadMbin NMSTemplate template = null; using (libMBIN.MBINFile mbin = new libMBIN.MBINFile(mbinPath)) { mbin.Load(); // load the header information from the file template = mbin.GetData(); // populate the data struct. } if (template != null) { TreeViewItem root = new TreeViewItem(); mainTree.Items.Add(root); IterateFields(template, template.GetType(), root); return(mainTree); } else { MessageBox.Show($"Unable to load file!\n{mbinPath}", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } }