Exemplo n.º 1
0
		private static DataBlock ReadDataBlock(IReader reader, byte version)
		{
			if (version > 6)
				throw new InvalidOperationException("Unrecognized \"data\" block version");

			// Block data
			uint originalAddress = reader.ReadUInt32();
			int entryCount = (version >= 1) ? reader.ReadInt32() : 1;
			int align = (version >= 3) ? reader.ReadInt32() : 4;
			byte[] data = ReadByteArray(reader);
			var block = new DataBlock(originalAddress, entryCount, align, data);

			// Address fixups
			int numAddressFixups = reader.ReadInt32();
			for (int i = 0; i < numAddressFixups; i++)
			{
				uint dataAddress = reader.ReadUInt32();
				int writeOffset = reader.ReadInt32();
				block.AddressFixups.Add(new DataBlockAddressFixup(dataAddress, writeOffset));
			}

			// Tagref fixups
			int numTagFixups = reader.ReadInt32();
			for (int i = 0; i < numTagFixups; i++)
			{
				var datum = new DatumIndex(reader.ReadUInt32());
				int writeOffset = reader.ReadInt32();
				block.TagFixups.Add(new DataBlockTagFixup(datum, writeOffset));
			}

			// Resource reference fixups
			int numResourceFixups = reader.ReadInt32();
			for (int i = 0; i < numResourceFixups; i++)
			{
				var datum = new DatumIndex(reader.ReadUInt32());
				int writeOffset = reader.ReadInt32();
				block.ResourceFixups.Add(new DataBlockResourceFixup(datum, writeOffset));
			}

			if (version >= 2)
			{
				// StringID fixups
				int numSIDFixups = reader.ReadInt32();
				for (int i = 0; i < numSIDFixups; i++)
				{
					string str = reader.ReadAscii();
					int writeOffset = reader.ReadInt32();
					block.StringIDFixups.Add(new DataBlockStringIDFixup(str, writeOffset));
				}
			}

			if (version >= 4)
			{
				// Shader fixups
				int numShaderFixups = reader.ReadInt32();
				for (int i = 0; i < numShaderFixups; i++)
				{
					int writeOffset = reader.ReadInt32();
					int shaderDataSize = reader.ReadInt32();
					byte[] shaderData = reader.ReadBlock(shaderDataSize);
					block.ShaderFixups.Add(new DataBlockShaderFixup(writeOffset, shaderData));
				}
			}

			if (version >= 5)
			{
				// Unicode string list fixups
				int numUnicListFixups = reader.ReadInt32();
				for (int i = 0; i < numUnicListFixups; i++)
				{
					// Version 5 is buggy and doesn't include a language index :x
					int languageIndex = i;
					if (version >= 6)
						languageIndex = reader.ReadInt32();

					int writeOffset = reader.ReadInt32();
					int numStrings = reader.ReadInt32();
					UnicListFixupString[] strings = new UnicListFixupString[numStrings];
					for (int j = 0; j < numStrings; j++)
					{
						string stringId = reader.ReadAscii();
						string str = reader.ReadUTF8();
						strings[j] = new UnicListFixupString(stringId, str);
					}
					block.UnicListFixups.Add(new DataBlockUnicListFixup(languageIndex, writeOffset, strings));
				}
			}

			return block;
		}
Exemplo n.º 2
0
        private static DataBlock ReadDataBlock(IReader reader, byte version)
        {
            if (version > 7)
            {
                throw new InvalidOperationException("Unrecognized \"data\" block version");
            }

            // Block data
            uint originalAddress = reader.ReadUInt32();
            int  entryCount      = (version >= 1) ? reader.ReadInt32() : 1;
            int  align           = (version >= 3) ? reader.ReadInt32() : 4;
            bool sort            = false;

            if (version >= 7)
            {
                byte sortval = reader.ReadByte();
                sort = sortval > 0;
            }
            byte[] data  = ReadByteArray(reader);
            var    block = new DataBlock(originalAddress, entryCount, align, sort, data);

            // Address fixups
            int numAddressFixups = reader.ReadInt32();

            for (int i = 0; i < numAddressFixups; i++)
            {
                uint dataAddress = reader.ReadUInt32();
                int  writeOffset = reader.ReadInt32();
                block.AddressFixups.Add(new DataBlockAddressFixup(dataAddress, writeOffset));
            }

            // Tagref fixups
            int numTagFixups = reader.ReadInt32();

            for (int i = 0; i < numTagFixups; i++)
            {
                var datum       = new DatumIndex(reader.ReadUInt32());
                int writeOffset = reader.ReadInt32();
                block.TagFixups.Add(new DataBlockTagFixup(datum, writeOffset));
            }

            // Resource reference fixups
            int numResourceFixups = reader.ReadInt32();

            for (int i = 0; i < numResourceFixups; i++)
            {
                var datum       = new DatumIndex(reader.ReadUInt32());
                int writeOffset = reader.ReadInt32();
                block.ResourceFixups.Add(new DataBlockResourceFixup(datum, writeOffset));
            }

            if (version >= 2)
            {
                // StringID fixups
                int numSIDFixups = reader.ReadInt32();
                for (int i = 0; i < numSIDFixups; i++)
                {
                    string str         = reader.ReadAscii();
                    int    writeOffset = reader.ReadInt32();
                    block.StringIDFixups.Add(new DataBlockStringIDFixup(str, writeOffset));
                }
            }

            if (version >= 4)
            {
                // Shader fixups
                int numShaderFixups = reader.ReadInt32();
                for (int i = 0; i < numShaderFixups; i++)
                {
                    int    writeOffset    = reader.ReadInt32();
                    int    shaderDataSize = reader.ReadInt32();
                    byte[] shaderData     = reader.ReadBlock(shaderDataSize);
                    block.ShaderFixups.Add(new DataBlockShaderFixup(writeOffset, shaderData));
                }
            }

            if (version >= 5)
            {
                // Unicode string list fixups
                int numUnicListFixups = reader.ReadInt32();
                for (int i = 0; i < numUnicListFixups; i++)
                {
                    // Version 5 is buggy and doesn't include a language index :x
                    int languageIndex = i;
                    if (version >= 6)
                    {
                        languageIndex = reader.ReadInt32();
                    }

                    int writeOffset = reader.ReadInt32();
                    int numStrings  = reader.ReadInt32();
                    UnicListFixupString[] strings = new UnicListFixupString[numStrings];
                    for (int j = 0; j < numStrings; j++)
                    {
                        string stringId = reader.ReadAscii();
                        string str      = reader.ReadUTF8();
                        strings[j] = new UnicListFixupString(stringId, str);
                    }
                    block.UnicListFixups.Add(new DataBlockUnicListFixup(languageIndex, writeOffset, strings));
                }
            }

            if (version >= 7)
            {
                int numInteropFixups = reader.ReadInt32();
                for (int i = 0; i < numInteropFixups; i++)
                {
                    uint dataAddress = reader.ReadUInt32();
                    int  writeOffset = reader.ReadInt32();
                    int  type        = reader.ReadInt32();
                    block.InteropFixups.Add(new DataBlockInteropFixup(type, dataAddress, writeOffset));
                }

                int numEffectFixups = reader.ReadInt32();
                for (int i = 0; i < numEffectFixups; i++)
                {
                    int    index          = reader.ReadInt32();
                    int    writeOffset    = reader.ReadInt32();
                    int    type           = reader.ReadInt32();
                    int    effectDataSize = reader.ReadInt32();
                    byte[] effectData     = reader.ReadBlock(effectDataSize);
                    block.EffectFixups.Add(new DataBlockEffectFixup(type, index, writeOffset, effectData));
                }
            }

            return(block);
        }
Exemplo n.º 3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="DataBlockUnicListFixup"/> class.
		/// </summary>
		/// <param name="writeOffset">The write offset.</param>
		/// <param name="strings">The strings.</param>
		public DataBlockUnicListFixup(int languageIndex, int writeOffset, UnicListFixupString[] strings)
		{
			LanguageIndex = languageIndex;
			WriteOffset = writeOffset;
			Strings = strings;
		}