public static void Write(PSC_File file, string path) { byte[] bytes = file.SaveToBytes(); //Saving File.WriteAllBytes(path, bytes.ToArray()); }
public static PSC_File Serialize(string path, bool writeXml) { byte[] rawBytes = File.ReadAllBytes(path); PSC_File file = Load(rawBytes); //Write Xml if (writeXml) { YAXSerializer serializer = new YAXSerializer(typeof(PSC_File)); serializer.SerializeToFile(file, path + ".xml"); } return(file); }
public static PSC_File Load(byte[] bytes) { //First, validate that the psc file is from version 1.13 or greater if (BitConverter.ToInt16(bytes, 6) != PSC_HEADER_SIZE) { throw new InvalidDataException("PSC files from game versions prior to 1.13 are not supported."); } PSC_File pscFile = new PSC_File(); int numEntries = BitConverter.ToInt32(bytes, 8); int numConfigurations = BitConverter.ToInt32(bytes, 16); int currentSpecPos = PSC_HEADER_SIZE + ((12 * numEntries) * numConfigurations); for (int i = 0; i < numConfigurations; i++) { PSC_Configuration config = new PSC_Configuration(); config.Index = i; int pscEntryOffset = PSC_HEADER_SIZE + ((12 * numEntries) * i); for (int a = 0; a < numEntries; a++) { PSC_Entry pscEntry = new PSC_Entry(); pscEntry.Index = BitConverter.ToInt32(bytes, pscEntryOffset + 0).ToString(); int numSpec = BitConverter.ToInt32(bytes, pscEntryOffset + 4); for (int s = 0; s < numSpec; s++) { pscEntry.PscSpecEntries.Add(PSC_SpecEntry.Read(bytes, currentSpecPos)); currentSpecPos += 196; } config.PscEntries.Add(pscEntry); pscEntryOffset += 12; } pscFile.Configurations.Add(config); } return(pscFile); }