コード例 #1
0
        public CPSSGFile(System.IO.Stream fileStream)
        {
            using (EndianBinaryReaderEx reader = new EndianBinaryReaderEx(new BigEndianBitConverter(), fileStream)) {
                magic = reader.ReadPSSGString(4);
                if (magic != "PSSG")
                {
                    throw new Exception("This is not a PSSG file!");
                }
                int size = reader.ReadInt32();
                int attributeInfoCount = reader.ReadInt32();
                int nodeInfoCount      = reader.ReadInt32();

                attributeInfo = new CAttributeInfo[attributeInfoCount];
                nodeInfo      = new CNodeInfo[nodeInfoCount];

                for (int i = 0; i < nodeInfoCount; i++)
                {
                    nodeInfo[i] = new CNodeInfo(reader, this);
                }
                long positionAfterInfo = reader.BaseStream.Position;

                rootNode = new CNode(reader, this, null, true);
                if (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    reader.BaseStream.Position = positionAfterInfo;
                    rootNode = new CNode(reader, this, 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 a non-modded version of the pssg file.");
                    }
                }
            }
        }
コード例 #2
0
        public CNodeInfo AddNodeInfo(string name)
        {
            if (GetNodeInfo(name).Length > 0)
            {
                return(null);
            }
            if (nodeInfo == null)
            {
                nodeInfo = new CNodeInfo[1];
            }
            else
            {
                Array.Resize(ref nodeInfo, nodeInfo.Length + 1);
            }
            CNodeInfo nInfo = new CNodeInfo(nodeInfo.Length, name);

            nodeInfo[nInfo.id - 1] = nInfo;
            return(nInfo);
        }
コード例 #3
0
        public CAttributeInfo AddAttributeInfo(string name, CNodeInfo nodeInfo)
        {
            // For each attributeInfo in nodeInfo, the ids have to be consecutive
            if (GetAttributeInfo(name).Length > 0)
            {
                return(null);
            }
            if (attributeInfo == null)
            {
                attributeInfo = new CAttributeInfo[1];
            }
            else
            {
                Array.Resize(ref attributeInfo, attributeInfo.Length + 1);
            }
            int        newID       = 0;
            List <int> currentKeys = new List <int>(nodeInfo.attributeInfo.Keys);

            if (currentKeys.Count > 0)
            {
                foreach (int k in currentKeys)
                {
                    newID = Math.Max(newID, k);
                }
                newID++;
            }
            else
            {
                newID = attributeInfo.Length;
            }
            CAttributeInfo attrInfo = new CAttributeInfo(newID, name);

            if (newID == attributeInfo.Length)
            {
                attributeInfo[attrInfo.id - 1] = attrInfo;
                this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo);
            }
            else
            {
                for (int i = attributeInfo.Length - 2; i >= newID - 1; i--)
                {
                    attributeInfo[i + 1]    = attributeInfo[i];
                    attributeInfo[i + 1].id = i + 2;
                }
                attributeInfo[attrInfo.id - 1] = attrInfo;
                this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo);
                // Fix the NodeInfos
                foreach (CNodeInfo nInfo in this.nodeInfo)
                {
                    List <int> keys = new List <int>(nInfo.attributeInfo.Keys);
                    //keys.Sort();
                    if (nInfo != nodeInfo)
                    {
                        for (int i = keys.Count - 1; i >= 0; i--)
                        {
                            if (keys[i] >= newID)
                            {
                                CAttributeInfo aInfo = attributeInfo[keys[i]];
                                nInfo.attributeInfo.Remove(keys[i]);
                                nInfo.attributeInfo.Add(keys[i] + 1, aInfo);
                            }
                        }
                    }
                }
                // Edit CNode to fix CAttr.id
                rootNode.AddAttributeInfo(newID);
            }
            return(attrInfo);
        }
コード例 #4
0
ファイル: PSSGFile.cs プロジェクト: Ryder25/Ego-PSSG-Editor
 public CNodeInfo AddNodeInfo(string name)
 {
     if (GetNodeInfo(name).Length > 0) {
         return null;
     }
     if (nodeInfo == null)
     {
         nodeInfo = new CNodeInfo[1];
     }
     else
     {
         Array.Resize(ref nodeInfo, nodeInfo.Length + 1);
     }
     CNodeInfo nInfo = new CNodeInfo(nodeInfo.Length, name);
     nodeInfo[nInfo.id - 1] = nInfo;
     return nInfo;
 }
コード例 #5
0
ファイル: PSSGFile.cs プロジェクト: Ryder25/Ego-PSSG-Editor
 public CAttributeInfo AddAttributeInfo(string name, CNodeInfo nodeInfo)
 {
     // For each attributeInfo in nodeInfo, the ids have to be consecutive
     if (GetAttributeInfo(name).Length > 0)
     {
         return null;
     }
     if (attributeInfo == null)
     {
         attributeInfo = new CAttributeInfo[1];
     }
     else
     {
         Array.Resize(ref attributeInfo, attributeInfo.Length + 1);
     }
     int newID = 0;
     List<int> currentKeys = new List<int>(nodeInfo.attributeInfo.Keys);
     if (currentKeys.Count > 0) {
         foreach (int k in currentKeys) {
             newID = Math.Max(newID, k);
         }
         newID++;
     } else {
         newID = attributeInfo.Length;
     }
     CAttributeInfo attrInfo = new CAttributeInfo(newID, name);
     if (newID == attributeInfo.Length) {
         attributeInfo[attrInfo.id - 1] = attrInfo;
         this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo);
     } else {
         for (int i = attributeInfo.Length - 2; i >= newID - 1; i--) {
             attributeInfo[i + 1] = attributeInfo[i];
             attributeInfo[i + 1].id = i + 2;
         }
         attributeInfo[attrInfo.id - 1] = attrInfo;
         this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo);
         // Fix the NodeInfos
         foreach (CNodeInfo nInfo in this.nodeInfo) {
             List<int> keys = new List<int>(nInfo.attributeInfo.Keys);
             //keys.Sort();
             if (nInfo != nodeInfo) {
                 for (int i = keys.Count - 1; i >= 0; i--) {
                     if (keys[i] >= newID) {
                         CAttributeInfo aInfo = attributeInfo[keys[i]];
                         nInfo.attributeInfo.Remove(keys[i]);
                         nInfo.attributeInfo.Add(keys[i] + 1, aInfo);
                     }
                 }
             }
         }
         // Edit CNode to fix CAttr.id
         rootNode.AddAttributeInfo(newID);
     }
     return attrInfo;
 }
コード例 #6
0
ファイル: PSSGFile.cs プロジェクト: Ryder25/Ego-PSSG-Editor
        public CPSSGFile(System.IO.Stream fileStream)
        {
            using (EndianBinaryReaderEx reader = new EndianBinaryReaderEx(new BigEndianBitConverter(), fileStream)) {
                magic = reader.ReadPSSGString(4);
                if (magic != "PSSG") {
                    throw new Exception("This is not a PSSG file!");
                }
                int size = reader.ReadInt32();
                int attributeInfoCount = reader.ReadInt32();
                int nodeInfoCount = reader.ReadInt32();

                attributeInfo = new CAttributeInfo[attributeInfoCount];
                nodeInfo = new CNodeInfo[nodeInfoCount];

                for (int i = 0; i < nodeInfoCount; i++) {
                    nodeInfo[i] = new CNodeInfo(reader, this);
                }
                long positionAfterInfo = reader.BaseStream.Position;

                rootNode = new CNode(reader, this, null, true);
                if (reader.BaseStream.Position < reader.BaseStream.Length) {
                    reader.BaseStream.Position = positionAfterInfo;
                    rootNode = new CNode(reader, this, 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 a non-modded version of the pssg file.");
                    }
                }
            }
        }