Exemple #1
0
        public static PSO_File Read(byte[] rawBytes)
        {
            if (BitConverter.ToUInt16(rawBytes, 6) != 120)
            {
                throw new InvalidDataException("Unsupported PSO File version.");
            }

            PSO_File psoFile = new PSO_File();

            psoFile.PsoEntries = new List <PSO_Entry>();

            int count  = BitConverter.ToInt32(rawBytes, 8);
            int offset = 16;

            for (int i = 0; i < count; i++)
            {
                int       subCount  = BitConverter.ToInt32(rawBytes, offset + 0);
                int       subOffset = BitConverter.ToInt32(rawBytes, offset + 4) + 16;
                PSO_Entry psoEntry  = new PSO_Entry();
                psoEntry.PsoSubEntries = new List <PSO_SubEntry>();

                for (int a = 0; a < subCount; a++)
                {
                    psoEntry.PsoSubEntries.Add(PSO_SubEntry.Read(rawBytes, subOffset));
                    subOffset += 120;
                }

                psoFile.PsoEntries.Add(psoEntry);
                offset += 16;
            }

            return(psoFile);
        }
Exemple #2
0
        public static void Deserialize(string xmlPath)
        {
            string        saveLocation = String.Format("{0}/{1}", Path.GetDirectoryName(xmlPath), Path.GetFileNameWithoutExtension(xmlPath));
            YAXSerializer serializer   = new YAXSerializer(typeof(PSO_File), YAXSerializationOptions.DontSerializeNullObjects);
            PSO_File      odfFile      = (PSO_File)serializer.DeserializeFromFile(xmlPath);

            byte[] bytes = odfFile.Write();
            File.WriteAllBytes(saveLocation, bytes);
        }
Exemple #3
0
        public static PSO_File Serialize(string path, bool writeXml)
        {
            byte[]   rawBytes = File.ReadAllBytes(path);
            PSO_File odfFile  = Read(rawBytes);

            if (writeXml)
            {
                YAXSerializer serializer = new YAXSerializer(typeof(PSO_File));
                serializer.SerializeToFile(odfFile, path + ".xml");
            }

            return(odfFile);
        }