public Type GetFieldType(FieldInfo fieldInfo) { Type typeToReturn = mbinStruct.GetType(); if (fieldInfo != null) { typeToReturn = fieldInfo.GetValue(mbinStruct).GetType(); } return(typeToReturn); }
public void SetData(NMSTemplate template) { _io.Stream.SetLength(0x60); _io.Stream.Position = 0x60; _io.Writer.Write(template.SerializeBytes()); Header.TemplateName = "c" + template.GetType().Name; }
public void SetData(NMSTemplate template) { _io.Stream.SetLength(0x60); _io.Stream.Position = 0x60; byte[] data = template.SerializeBytes(); _io.Writer.Write(data); FileLength = (ulong)data.LongLength; Header.TemplateName = "c" + template.GetType().Name; }
/// <summary>Convert EXML to MBIN</summary> /// <param name="fIn">Source file</param> /// <param name="msOut">Output stream</param> /// <param name="fileOut">Output file path. Passed through as the return value. For geometry files, ".PC" will be appended.</param> /// <returns>fileOut</returns> private static string ConvertEXML(string inputPath, FileStream fIn, MemoryStream msOut, string fileOut) { string templateName; NMSTemplate data = null; try { data = EXmlFile.ReadTemplateFromStream(fIn, out templateName); Type type = NMSTemplate.GetTemplateType(templateName); var nms = (NMSAttribute)(data.GetType().GetCustomAttributes(typeof(NMSAttribute), false)?[0] ?? null); if (nms.Broken) { FileIsBroken(inputPath, data); } if (data is null) { throw new InvalidDataException($"Failed to deserialize EXML."); } if (data is libMBIN.NMS.Toolkit.TkGeometryData | data is libMBIN.NMS.Toolkit.TkGeometryStreamData) { fileOut += ".PC"; } var mbin = new MBINFile(msOut) { Header = new MBINHeader() }; mbin.Header.SetDefaults(data.GetType(), FormatVersion); mbin.SetData(data); mbin.Save(); } catch (Exception e) { throw new ExmlException(e, fIn.Name, data); } return(fileOut); }
public void SetData(NMSTemplate template) { _io.Stream.SetLength(0x60); _io.Stream.Position = 0x60; /* * // if we want to get the file size: * byte[] data = template.SerializeBytes(); * _io.Writer.Write(data); * * this.FileLength = (ulong)data.LongLength; */ // otherwise just do: _io.Writer.Write(template.SerializeBytes()); Header.TemplateName = "c" + template.GetType().Name; }
public static List <MBINField> GetMBINFields(Stream file) { NMSTemplate template = null; using (libMBIN.MBINFile mbin = new libMBIN.MBINFile(file)) { mbin.Load(); // load the header information from the file template = mbin.GetData(); // populate the data struct. } if (template != null) { return(IterateFields(template, template.GetType())); } else { Helpers.BasicDialogBox("MBIN Loading Error...", "Unable to load the MBIN!"); return(null); } }
// ===================== // = 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); } }
private static string GetString(ulong readGUID, ulong expectedGUID, NMSTemplate template) { return($"Mismatch between GUID for struct {template.GetType().Name}.\n" + $"GUID read: {readGUID.ToString()}, expected GUID: {expectedGUID.ToString()}."); }
public InvalidGUIDException(NMSTemplate template) : base($"The template {template.GetType().Name} has no provided NameHash. Please raise an issue on GitHub!") { }
public static void ConvertFile(string fileIn, string fileOut, FormatType inputFormat, FormatType outputFormat) { fileOut = ChangeFileExtension(fileOut, outputFormat); FileMode fileMode = GetFileMode(fileOut); Directory.CreateDirectory(Path.GetDirectoryName(fileOut)); try { using (var indentScope = new Logger.IndentScope()) using (var fIn = new FileStream(fileIn, FileMode.Open, FileAccess.Read)) using (var ms = new MemoryStream()) { if (inputFormat == FormatType.MBIN) { var mbin = new MBINFile(fIn); if (!mbin.Load() || !mbin.Header.IsValid) { throw new InvalidDataException("Not a valid MBIN file!"); } var sw = new StreamWriter(ms); 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, fileIn, mbin); } try { sw.Write(EXmlFile.WriteTemplate(data)); sw.Flush(); if (ms.Length == 0) { throw new InvalidDataException("Invalid EXML data."); } } catch (Exception e) { throw new MbinException($"Failed serializing {mbin.Header.GetXMLTemplateName()} to EXML.", e, fileIn, mbin); } } else if (inputFormat == FormatType.EXML) { NMSTemplate data = null; try { data = EXmlFile.ReadTemplateFromStream(fIn); if (data is null) { throw new InvalidDataException($"Failed to deserialize EXML."); } if (data is TkGeometryData) { fileOut += ".PC"; } var mbin = new MBINFile(ms) { Header = new MBINHeader() }; mbin.Header.SetDefaults(data.GetType()); mbin.SetData(data); mbin.Save(); } catch (Exception e) { throw new ExmlException(e, fileIn, data); } } ms.Flush(); using (var fOut = new FileStream(fileOut, fileMode, FileAccess.Write)) ms.WriteTo(fOut); } } catch (Exception e) { File.Delete(fileOut); if (e is CompilerException) { throw; } throw new CompilerException(e, fileIn); } }
// hold all the vars for the specific template public ExtendedNmsTemplate(string path) { mbinPath = path; baseTemplate = FileIO.LoadFile(path); templateVars = baseTemplate.GetType().GetFields(); }
public MBinViewModel(NMSTemplate template) { _template = template; //This is where the magic happens Fields = new ObservableCollection <MBINField>(IterateFields(_template, _template.GetType())); }