public static PssgFile ReadPssg(Stream fileStream, PssgFileType fileType) { PssgFile file = new PssgFile(fileType); using (PssgBinaryReader reader = new PssgBinaryReader(EndianBitConverter.Big, fileStream, true)) { reader.ReadPSSGString(4); // "PSSG" int size = reader.ReadInt32(); // Load all the pssg node/attribute names PssgSchema.ClearSchemaIds(); PssgSchema.LoadFromPssg(reader); long positionAfterInfo = reader.BaseStream.Position; file.RootNode = new PssgNode(reader, file, null, true); if (reader.BaseStream.Position < reader.BaseStream.Length) { reader.BaseStream.Position = positionAfterInfo; file.RootNode = new PssgNode(reader, file, null, false); if (reader.BaseStream.Position < reader.BaseStream.Length) { throw new Exception("This file is improperly saved and not supported by this version of the PSSG editor." + Environment.NewLine + Environment.NewLine + "Get an older version of the program if you wish to take out its contents, but put it back together using this program and the original version of the pssg file."); } } } return(file); }
public static PssgFile ReadPssg(Stream fileStream, PssgFileType fileType) { PssgFile file = new PssgFile(fileType); using (PssgBinaryReader reader = new PssgBinaryReader(new BigEndianBitConverter(), fileStream)) { reader.ReadPSSGString(4); // "PSSG" int size = reader.ReadInt32(); // Load all the pssg node/attribute names PssgSchema.ClearSchemaIds(); PssgSchema.LoadFromPssg(reader); long positionAfterInfo = reader.BaseStream.Position; file.RootNode = new PssgNode(reader, file, null, true); if (reader.BaseStream.Position < reader.BaseStream.Length) { reader.BaseStream.Position = positionAfterInfo; file.RootNode = new PssgNode(reader, file, null, false); if (reader.BaseStream.Position < reader.BaseStream.Length) { throw new Exception("This file is improperly saved and not supported by this version of the PSSG editor." + Environment.NewLine + Environment.NewLine + "Get an older version of the program if you wish to take out its contents, but put it back together using this program and the original version of the pssg file."); } } } return file; }
public PssgAttribute(PssgSchema.Attribute attributeInfo, object data, PssgFile file, PssgNode ParentNode) { this.AttributeInfo = attributeInfo; this.data = data; this.file = file; this.ParentNode = ParentNode; }
public PssgNode(XElement elem, PssgFile file, PssgNode node) { this.File = file; this.ParentNode = node; this.NodeInfo = PssgSchema.AddNode(elem.Name.LocalName);// PssgSchema.GetNode(elem.Name.LocalName); this.Attributes = new PssgAttributeCollection(); PssgAttribute attr; foreach (XAttribute xAttr in elem.Attributes()) { attr = new PssgAttribute(xAttr, file, this); this.Attributes.Add(attr); } // Add data, and sub nodes code here if (elem.FirstNode != null && elem.FirstNode is XText) { this.data = this.FromString(elem.Value); this.ChildNodes = new PssgNodeCollection(); } else { this.data = new byte[0]; this.ChildNodes = new PssgNodeCollection(elem.Elements().Count()); int nodeCount = 0; foreach (XElement subElem in elem.Elements()) { this.ChildNodes.Add(new PssgNode(subElem, file, this)); ++nodeCount; } } PssgSchema.SetNodeDataTypeIfNull(this.NodeInfo, this.ValueType); }
public AddBox(PssgFile file, int tabIndex) { InitializeComponent(); pssgFile = file; // NodeInfo Combo nodeInfoComboBox1.BeginUpdate(); nodeInfoComboBox1.Items.AddRange(PssgSchema.GetNodeNames()); nodeInfoComboBox1.EndUpdate(); // AttributeInfo Combo attributeInfoComboBox.BeginUpdate(); attributeInfoComboBox.Items.AddRange(PssgSchema.GetAttributeNames()); attributeInfoComboBox.EndUpdate(); // ValueType Combo valueTypeComboBox.Items.Add(typeof(System.UInt16).ToString()); valueTypeComboBox.Items.Add(typeof(System.UInt32).ToString()); valueTypeComboBox.Items.Add(typeof(System.Int16).ToString()); valueTypeComboBox.Items.Add(typeof(System.Int32).ToString()); valueTypeComboBox.Items.Add(typeof(System.Single).ToString()); //valueTypeComboBox.Items.Add(typeof(System.Boolean).ToString()); valueTypeComboBox.Items.Add(typeof(System.String).ToString()); // Select nodeInfoComboBox1.SelectedIndex = 0; if (attributeInfoComboBox.Items.Count > 0) { attributeInfoComboBox.SelectedIndex = 0; } valueTypeComboBox.SelectedIndex = 5; tabControl.SelectedIndex = tabIndex; }
public PssgAttribute(PssgAttribute attrToCopy) { this.file = attrToCopy.file; this.ParentNode = attrToCopy.ParentNode; this.AttributeInfo = attrToCopy.AttributeInfo; this.size = attrToCopy.size; this.data = attrToCopy.data; }
public PssgNode(string name, PssgFile file, PssgNode node) { this.File = file; this.ParentNode = node; this.NodeInfo = PssgSchema.AddNode(name); this.Attributes = new PssgAttributeCollection(); this.data = new byte[0]; this.ChildNodes = new PssgNodeCollection(); }
public PssgAttribute(XAttribute xAttr, PssgFile file, PssgNode node) { this.file = file; this.ParentNode = node; //this.id = PssgSchema.GetAttributeId(ParentNode.Name, xAttr.Name.LocalName); this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, xAttr.Name.LocalName);// PssgSchema.GetAttribute(this.ParentNode.Name, xAttr.Name.LocalName); this.data = this.FromString(xAttr.Value); PssgSchema.SetAttributeDataTypeIfNull(this.AttributeInfo, this.ValueType); }
public PssgAttribute(PssgBinaryReader reader, PssgFile file, PssgNode node) { this.file = file; this.ParentNode = node; int id = reader.ReadInt32(); this.AttributeInfo = PssgSchema.GetAttribute(id); this.size = reader.ReadInt32(); this.data = reader.ReadAttributeValue(this.AttributeInfo.DataType, size); this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, this.Name, this.ValueType); }
public static PssgFile ReadXml(Stream fileStream) { PssgFile file = new PssgFile(PssgFileType.Xml); XDocument xDoc = XDocument.Load(fileStream); //PssgSchema.CreatePssgInfo(out file.nodeInfo, out file.attributeInfo); file.RootNode = new PssgNode((XElement)((XElement)xDoc.FirstNode).FirstNode, file, null); fileStream.Close(); return(file); }
public PssgAttribute(XAttribute xAttr, PssgFile file, PssgNode node) { this.file = file; this.ParentNode = node; //this.id = PssgSchema.GetAttributeId(ParentNode.Name, xAttr.Name.LocalName); string attrName = xAttr.Name.LocalName.StartsWith("___") ? xAttr.Name.LocalName.Substring(3) : xAttr.Name.LocalName; this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, attrName);// PssgSchema.GetAttribute(this.ParentNode.Name, xAttr.Name.LocalName); this.data = this.FromString(xAttr.Value); PssgSchema.SetAttributeDataTypeIfNull(this.AttributeInfo, this.ValueType); }
public static PssgFile Open(Stream stream) { PssgFileType fileType = PssgFile.GetPssgType(stream); if (fileType == PssgFileType.Pssg) { return(PssgFile.ReadPssg(stream, fileType)); } else if (fileType == PssgFileType.Xml) { return(PssgFile.ReadXml(stream, fileType)); } else // CompressedPssg { string tempPath = "temp.pssg"; try { using (var fs = File.Open(tempPath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { // Decompress stream into temp file using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress, true)) { gZipStream.CopyTo(fs); } // Determine the file type after inflate, add CompressedPssg to make compressed fs.Seek(0, SeekOrigin.Begin); fileType = GetPssgType(fs) + (int)PssgFileType.CompressedPssg; PssgFile pFile = fileType switch { PssgFileType.CompressedPssg => PssgFile.ReadPssg(fs, fileType), PssgFileType.CompressedXml => PssgFile.ReadXml(fs, fileType), _ => throw new FileFormatException("This is not a pssg file.") }; return(pFile); } } finally { // Attempt to delete the temporary file try { File.Delete(tempPath); } catch { } } } }
public static PssgFile ReadXml(Stream fileStream, PssgFileType fileType) { PssgFile file = new PssgFile(fileType); XDocument xDoc = XDocument.Load(fileStream); var docElem = xDoc.FirstNode as XElement ?? throw new InvalidDataException("The pssg xml does not have a root element."); var firstNode = docElem.FirstNode as XElement ?? throw new InvalidDataException("The pssg xml does not have an element within the root element."); file.RootNode = new PssgNode(firstNode, file, null); return(file); }
public static PssgFile Open(Stream stream) { PssgFileType fileType = PssgFile.GetPssgType(stream); if (fileType == PssgFileType.Pssg) { return(PssgFile.ReadPssg(stream, fileType)); } else if (fileType == PssgFileType.Xml) { return(PssgFile.ReadXml(stream)); } else // CompressedPssg { string tempPath = "temp.pssg"; try { FileStream fs = File.Open(tempPath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); // Decompress stream into temp file using (stream) { using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress)) { gZipStream.CopyTo(fs); } } // Read temp file, and close it fs.Seek(0, SeekOrigin.Begin); PssgFile pFile = PssgFile.ReadPssg(fs, fileType); return(pFile); } finally { // Attempt to delete the temporary file try { File.Delete(tempPath); } catch { } } } }
static void GetNodeAttributeNameCount(PssgFile file, out int nodeNameCount, out int attributeNameCount) { nodeNameCount = 0; attributeNameCount = 0; foreach (var node in file.GetNodes()) { PssgSchema.Node sNode = node.NodeInfo; if (sNode.Id == -1) { // change this so we don't count it twice sNode.Id = ++nodeNameCount; } foreach (PssgAttribute attr in node.Attributes) { if (attr.AttributeInfo.Id == -1) { // change this so we don't count it twice attr.AttributeInfo.Id = ++attributeNameCount; } } } }
public PssgNode(PssgBinaryReader reader, PssgFile file, PssgNode node, bool useDataNodeCheck) { this.File = file; this.ParentNode = node; int id = reader.ReadInt32(); this.NodeInfo = PssgSchema.GetNode(id); this.size = reader.ReadInt32(); long end = reader.BaseStream.Position + size; this.attributeSize = reader.ReadInt32(); long attributeEnd = reader.BaseStream.Position + attributeSize; if (attributeEnd > reader.BaseStream.Length || end > reader.BaseStream.Length) { throw new Exception("This file is improperly saved and not supported by this version of the PSSG editor." + Environment.NewLine + Environment.NewLine + "Get an older version of the program if you wish to take out its contents, but, put it back together using this program and a non-modded version of the pssg file."); } // Each attr is at least 8 bytes (id + size), so take a conservative guess this.Attributes = new PssgAttributeCollection(); PssgAttribute attr; while (reader.BaseStream.Position < attributeEnd) { attr = new PssgAttribute(reader, file, this); this.Attributes.Add(attr); } bool isDataNode = false; switch (Name) { case "BOUNDINGBOX": case "DATA": case "DATABLOCKDATA": case "DATABLOCKBUFFERED": case "INDEXSOURCEDATA": case "INVERSEBINDMATRIX": case "MODIFIERNETWORKINSTANCEUNIQUEMODIFIERINPUT": case "NeAnimPacketData_B1": case "NeAnimPacketData_B4": case "RENDERINTERFACEBOUNDBUFFERED": case "SHADERINPUT": case "TEXTUREIMAGEBLOCKDATA": case "TRANSFORM": isDataNode = true; break; } if (isDataNode == false && useDataNodeCheck == true) { long currentPos = reader.BaseStream.Position; // Check if it has subnodes while (reader.BaseStream.Position < end) { int tempID = reader.ReadInt32(); if (tempID < 0)//tempID > file.nodeInfo.Length || { isDataNode = true; break; } else { int tempSize = reader.ReadInt32(); if ((reader.BaseStream.Position + tempSize > end) || (tempSize == 0 && tempID == 0) || tempSize < 0) { isDataNode = true; break; } else if (reader.BaseStream.Position + tempSize == end) { break; } else { reader.BaseStream.Position += tempSize; } } } reader.BaseStream.Position = currentPos; } if (isDataNode) { this.data = reader.ReadNodeValue(GetValueType(), (int)(end - reader.BaseStream.Position)); this.ChildNodes = new PssgNodeCollection(); //data = reader.ReadBytes((int)(end - reader.BaseStream.Position)); } else { this.data = new byte[0]; // Each node at least 12 bytes (id + size + arg size) this.ChildNodes = new PssgNodeCollection((int)(end - reader.BaseStream.Position) / 12); int nodeCount = 0; while (reader.BaseStream.Position < end) { this.ChildNodes.Add(new PssgNode(reader, file, this, useDataNodeCheck)); nodeCount++; } } PssgSchema.SetNodeDataTypeIfNull(this.NodeInfo, this.ValueType); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog.FilterIndex = 1; if (!string.IsNullOrEmpty(filePath)) { openFileDialog.FileName = Path.GetFileNameWithoutExtension(filePath); openFileDialog.InitialDirectory = Path.GetDirectoryName(filePath); } if (openFileDialog.ShowDialog() == DialogResult.OK) { try { filePath = openFileDialog.FileName; openFileDialog.Dispose(); clearVars(true); pssg = PssgFile.Open(File.Open(filePath, FileMode.Open, FileAccess.Read)); setupEditor(MainTabs.Auto); } catch (Exception excp) { // Fail this.Text = "Ego PSSG Editor"; MessageBox.Show("The program could not open this file!" + Environment.NewLine + Environment.NewLine + excp.Message, "Could Not Open", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Form1_Load(object sender, EventArgs e) { PssgSchema.LoadSchema(File.Open(schemaPath, FileMode.Open, FileAccess.Read, FileShare.Read)); // File Association Handler (if arg passed, try to open it) //args = new List<string>() { @"C:\Games\Steam\steamapps\common\f1 2011\cars\fe1\livery_main\textures_high\temo.pssg" }.ToArray(); if (args.Length > 0) { filePath = args[0]; clearVars(true); try { pssg = PssgFile.Open(File.Open(filePath, FileMode.Open, FileAccess.Read)); setupEditor(MainTabs.Auto); } catch (Exception excp) { // Fail this.Text = "Ego PSSG Editor"; MessageBox.Show("The program could not open this file!" + Environment.NewLine + Environment.NewLine + excp.Message, "Could Not Open", MessageBoxButtons.OK, MessageBoxIcon.Error); } } args = null; }
private void clearVars(bool clearPSSG) { if (pssg == null) return; // All tab mainTabControl.SelectedTab = mainTabControl.TabPages["allTabPage"]; treeView.Nodes.Clear(); idTextBox.Text = ""; richTextBox1.Text = ""; dataGridView.Tag = null; dataGridView.Rows.Clear(); dataGridView.Columns.Clear(); dataGridView.BringToFront(); // Textures tab textureImageLabel.Text = ""; textureTreeView.Nodes.Clear(); if (texturePictureBox.Image != null) { texturePictureBox.Image.Dispose(); texturePictureBox.Image = null; } // CubeMap Tab cubeMapImageLabel.Text = ""; cubeMapTreeView.Nodes.Clear(); if (cubeMapPictureBox.Image != null) { cubeMapPictureBox.Image.Dispose(); cubeMapPictureBox.Image = null; } // BackEnd Tab mainTabControl.BringToFront(); this.Text = "Ego PSSG Editor"; if (clearPSSG == true) { pssg = null; } }
public static PssgFile ReadXml(Stream fileStream) { PssgFile file = new PssgFile(PssgFileType.Xml); XDocument xDoc = XDocument.Load(fileStream); //PssgSchema.CreatePssgInfo(out file.nodeInfo, out file.attributeInfo); file.RootNode = new PssgNode((XElement)((XElement)xDoc.FirstNode).FirstNode, file, null); fileStream.Close(); return file; }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { clearVars(true); pssg = new PssgFile(PssgFileType.Pssg); }