Beispiel #1
0
        public UvrTextureFile(byte[] inHeader, byte[] rawData, string filename)
        {
            backupRaw = new UnpointeredFile(filename, rawData, inHeader);

            this.inHeader = inHeader;
            this.rawData  = rawData;
            this.filename = filename;
            parseData();
        }
        public Psp2TextFile(string inFilename, byte[] rawData)
        {
            backupRaw = new UnpointeredFile(inFilename, rawData, new byte[0]);

            filename = inFilename;
            MemoryStream rawStream     = new MemoryStream(rawData);
            BinaryReader rawReader     = new BinaryReader(rawStream);
            int          categoryCount = rawReader.ReadInt32();

            stringArray = new List <string> [categoryCount];
            int categoryBase = (int)rawStream.Position;

            int[] categoryCounts = new int[categoryCount];
            for (int i = 0; i < categoryCount; i++)
            {
                categoryCounts[i] = rawReader.ReadInt16();
            }

            int highestValue = categoryCounts.Max();

            int[] stringOffsets = new int[highestValue];
            for (int i = 0; i < highestValue; i++)
            {
                stringOffsets[i] = rawReader.ReadInt16();
            }
            int charMapping    = rawReader.ReadInt16();
            int stringStartLoc = (int)rawStream.Position;

            rawStream.Seek(charMapping + stringStartLoc + (charMapping % 2), SeekOrigin.Begin);
            char[] mapping = new char[256];
            for (int i = 0; i < 256 && rawStream.Position < rawData.Length - 2; i++)
            {
                mapping[i] = Convert.ToChar(rawReader.ReadUInt16());
            }
            int currentCategory = 0;

            for (int i = 0; i < highestValue - 1; i++)
            {
                while (i >= categoryCounts[currentCategory])
                {
                    currentCategory++;
                }
                if (stringArray[currentCategory] == null)
                {
                    stringArray[currentCategory] = new List <string>();
                }
                rawStream.Seek(stringStartLoc + stringOffsets[i], SeekOrigin.Begin);
                byte[]        stringBytes = rawReader.ReadBytes(stringOffsets[i + 1] - stringOffsets[i]);
                StringBuilder s           = new StringBuilder();
                for (int k = 0; k < stringBytes.Length; k++)
                {
                    s.Append(mapping[stringBytes[k]]);
                }
                stringArray[currentCategory].Add(s.ToString());
            }
        }