コード例 #1
0
        public int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            uint sig = BitConverter.ToUInt32(Buffer, cursor);

            cursor += TypeSizes.INT;

            if (sig == SIGNATURE)
            {
                uint ver = BitConverter.ToUInt32(Buffer, cursor);
                cursor += TypeSizes.INT;

                uint entries = BitConverter.ToUInt32(Buffer, cursor);
                cursor += TypeSizes.INT;

                // decrypt old versions first (v4 first unencryted)
                // note: this might need different passwords for other versions
                if (ver <= VERSION3)
                {
#if WINCLR && X86
                    uint streamlength = BitConverter.ToUInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    uint expectedresponse = BitConverter.ToUInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    Crush32.Decrypt(Buffer, cursor, (int)streamlength, ver, expectedresponse, PASSWORDV3);
#else
                    throw new Exception(RooFile.ERRORCRUSHPLATFORM);
#endif
                }

                // now load strings
                StringResources.Clear();
                for (int i = 0; i < entries; i++)
                {
                    uint ID = BitConverter.ToUInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    // look for terminating 0x00 (NULL)
                    ushort strlen = 0;
                    while ((Buffer.Length > cursor + strlen) && Buffer[cursor + strlen] != 0x00)
                    {
                        strlen++;
                    }

                    string Value = Encoding.Default.GetString(Buffer, cursor, strlen);
                    cursor += strlen + TypeSizes.BYTE;

                    StringResources.TryAdd(ID, Value);
                }
            }
            else
            {
                throw new Exception("Wrong RSC file signature: " + sig + " (expected " + SIGNATURE + ").");
            }

            return(cursor - StartIndex);
        }
コード例 #2
0
        public int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            uint sig = BitConverter.ToUInt32(Buffer, cursor);

            cursor += TypeSizes.INT;

            if (sig == SIGNATURE)
            {
                version = BitConverter.ToUInt32(Buffer, cursor);
                cursor += TypeSizes.INT;

                uint entries = BitConverter.ToUInt32(Buffer, cursor);
                cursor += TypeSizes.INT;

                // decrypt old versions first (v4 first unencryted)
                // note: this might need different passwords for other versions
                if (version <= VERSION3)
                {
#if WINCLR && X86
                    uint streamlength = BitConverter.ToUInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    uint expectedresponse = BitConverter.ToUInt32(Buffer, cursor);
                    cursor += TypeSizes.INT;

                    Crush32.Decrypt(Buffer, cursor, (int)streamlength, version, expectedresponse, PASSWORDV3);
#else
                    throw new Exception(RooFile.ERRORCRUSHPLATFORM);
#endif
                }

                // now load strings
                StringResources.Clear();
                StringResources.Capacity = (int)entries + 100;
                for (int i = 0; i < entries; i++)
                {
                    RsbResourceID entry = new RsbResourceID(version, Buffer, cursor);
                    cursor += entry.ByteLength;

                    StringResources.Add(entry);
                }
            }
            else
            {
                throw new Exception("Wrong RSC file signature: " + sig + " (expected " + SIGNATURE + ").");
            }

            return(cursor - StartIndex);
        }