예제 #1
0
        public void ReadRequestedStrings(IReader reader, SegmentPointer baseLocation, CachedStringTable output)
        {
            int baseOffset = baseLocation.AsOffset();

            int lastEnd = -1;
            foreach (int offset in _requestedStrings)
            {
                if (offset <= lastEnd)
                    continue;
                reader.SeekTo(baseOffset + offset);
                string str = reader.ReadAscii();
                output.CacheString(offset, str);
                lastEnd = offset + str.Length;
            }
        }
예제 #2
0
		private void FixShaderReferences(DataBlock block, IStream stream, SegmentPointer baseOffset)
		{
			foreach (DataBlockShaderFixup fixup in block.ShaderFixups)
			{
				stream.SeekTo(baseOffset.AsOffset() + fixup.WriteOffset);
				_cacheFile.ShaderStreamer.ImportShader(fixup.Data, stream);
			}
		}
예제 #3
0
		private void WriteDataBlock(DataBlock block, SegmentPointer location, IStream stream, ITag tag = null)
		{
			if (tag == null && _dataBlockAddresses.ContainsKey(block)) // Don't write anything if the block has already been written
				return;

			// Associate the location with the block
			_dataBlockAddresses[block] = location.AsPointer();

			// Create a MemoryStream and write the block data to it (so fixups can be performed before writing it to the file)
			using (var buffer = new MemoryStream(block.Data.Length))
			{
				var bufferWriter = new EndianWriter(buffer, stream.Endianness);
				bufferWriter.WriteBlock(block.Data);

				// Apply fixups
				FixBlockReferences(block, bufferWriter, stream);
				FixTagReferences(block, bufferWriter, stream);
				FixResourceReferences(block, bufferWriter, stream);
				FixStringIdReferences(block, bufferWriter);
				if (tag != null)
					FixUnicListReferences(block, tag, bufferWriter, stream);

				// Write the buffer to the file
				stream.SeekTo(location.AsOffset());
				stream.WriteBlock(buffer.GetBuffer(), 0, (int) buffer.Length);
			}

			// Write shader fixups (they can't be done in-memory because they require cache file expansion)
			FixShaderReferences(block, stream, location);
		}
예제 #4
0
        private void WriteDataBlock(DataBlock block, SegmentPointer location, IStream stream)
        {
            // Don't write anything if the block has already been written
            if (_dataBlockAddresses.ContainsKey(block))
                return;

            // Associate the location with the block
            _dataBlockAddresses[block] = location.AsPointer();

            // Create a MemoryStream and write the block data to it (so fixups can be performed before writing it to the file)
            using (var buffer = new MemoryStream(block.Data.Length))
            {
                var bufferWriter = new EndianWriter(buffer, stream.Endianness);
                bufferWriter.WriteBlock(block.Data);

                // Apply fixups
                FixBlockReferences(block, bufferWriter, stream);
                FixTagReferences(block, bufferWriter, stream);
                FixResourceReferences(block, bufferWriter, stream);
                FixStringIDReferences(block, bufferWriter);

                // Write the buffer to the file
                stream.SeekTo(location.AsOffset());
                stream.WriteBlock(buffer.GetBuffer(), 0, (int) buffer.Length);
            }
        }
예제 #5
0
        private List<IScript> LoadScripts(StructureValueCollection values, IReader reader, FileSegmentGroup metaArea, StringIDSource stringIDs, ExpressionTable expressions, StructureLayout entryLayout, BuildInformation buildInfo)
        {
            int scriptCount = (int)values.GetInteger("number of scripts");
            if (scriptCount == 0)
                return new List<IScript>();

            ScriptsLocation = SegmentPointer.FromPointer(values.GetInteger("script table address"), metaArea);

            // Read all of the script entries first, then go back and create the objects
            // ThirdGenScript reads parameters from its constructor - this may or may not need cleaning up to make this more obvious
            reader.SeekTo(ScriptsLocation.AsOffset());
            List<StructureValueCollection> scriptData = new List<StructureValueCollection>();
            for (int i = 0; i < scriptCount; i++)
                scriptData.Add(StructureReader.ReadStructure(reader, entryLayout));

            List<IScript> result = new List<IScript>();
            foreach (StructureValueCollection scriptValues in scriptData)
                result.Add(new ThirdGenScript(reader, scriptValues, metaArea, stringIDs, expressions, buildInfo));
            return result;
        }
예제 #6
0
        private List<ITag> ReadTags(IReader reader, SegmentPointer tagTableLocation, int numTags, BuildInformation buildInfo, FileSegmentGroup metaArea)
        {
            StructureLayout layout = buildInfo.GetLayout("tag entry");

            List<ITag> result = new List<ITag>();
            reader.SeekTo(tagTableLocation.AsOffset());
            for (int i = 0; i < numTags; i++)
            {
                StructureValueCollection values = StructureReader.ReadStructure(reader, layout);
                result.Add(new ThirdGenTag(values, (ushort)i, metaArea, _classes));
            }
            return result;
        }
예제 #7
0
        private List<ITagClass> ReadClasses(IReader reader, SegmentPointer classTableLocation, int numClasses, BuildInformation buildInfo)
        {
            StructureLayout layout = buildInfo.GetLayout("class entry");

            List<ITagClass> result = new List<ITagClass>();
            reader.SeekTo(classTableLocation.AsOffset());
            for (int i = 0; i < numClasses; i++)
            {
                StructureValueCollection values = StructureReader.ReadStructure(reader, layout);
                result.Add(new ThirdGenTagClass(values));
            }
            return result;
        }