/// <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 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(); } }