Ejemplo n.º 1
0
 internal Script(StructureValueCollection values, IReader reader, FileSegmentGroup metaArea, StringIDSource stringIDs,
                 EngineDescription buildInfo, IPointerExpander expander)
 {
     Load(values, reader, metaArea, stringIDs, buildInfo, expander);
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Serializes the header's values, storing them into a StructureValueCollection.
        /// </summary>
        /// <param name="localeArea">The locale area of the cache file. Can be null.</param>
        /// <param name="localePointerMask">The value to add to locale pointers to translate them to file offsets.</param>
        /// <returns>The resulting StructureValueCollection.</returns>
        public StructureValueCollection Serialize(FileSegmentGroup localeArea)
        {
            var values = new StructureValueCollection();

            values.SetInteger("file size", FileSize);
            values.SetInteger("type", (uint)Type);
            values.SetString("internal name", InternalName);
            values.SetString("scenario name", ScenarioName);
            values.SetInteger("xdk version", (uint)XDKVersion);

            AdjustPartitions();
            values.SetArray("partitions", SerializePartitions());

            RebuildInteropData(localeArea);

            values.SetArray("offset masks", SectionOffsetMasks.Select(m =>
            {
                var result = new StructureValueCollection();
                result.SetInteger("mask", m);
                return(result);
            }).ToArray());

            values.SetArray("sections", Sections.Select(s => s.Serialize()).ToArray());
            values.SetInteger("tag buffer offset", Sections[(int)ThirdGenInteropSectionType.Tag].VirtualAddress);

            if (MetaArea != null)
            {
                values.SetInteger("virtual base address", MetaArea.BasePointer);
                values.SetInteger("index header address", IndexHeaderLocation.AsPointer());
                values.SetInteger("virtual size", (uint)MetaArea.Size);
            }

            if (StringBlockLocation != null)
            {
                values.SetInteger("string block offset", StringBlockLocation.AsPointer());
            }

            values.SetInteger("string table count", (uint)StringIDCount);
            if (StringIDData != null)
            {
                values.SetInteger("string table size", (uint)StringIDData.Size);
                values.SetInteger("string table offset", StringIDDataLocation.AsPointer());
            }

            if (StringIDIndexTableLocation != null)
            {
                values.SetInteger("string index table offset", StringIDIndexTableLocation.AsPointer());
            }

            if (StringArea != null)
            {
                values.SetInteger("string data size", (uint)StringArea.Size);
            }

            values.SetInteger("file table count", (uint)FileNameCount);
            if (FileNameData != null)
            {
                values.SetInteger("file table offset", FileNameDataLocation.AsPointer());
                values.SetInteger("file table size", (uint)FileNameData.Size);
            }

            if (FileNameIndexTableLocation != null)
            {
                values.SetInteger("file index table offset", FileNameIndexTableLocation.AsPointer());
            }

            if (localeArea != null)
            {
                values.SetInteger("locale data index offset", localeArea.BasePointer);
                values.SetInteger("locale data size", (uint)localeArea.Size);
            }

            if (UnknownTableLocation != null)
            {
                values.SetInteger("unknown table count", (uint)UnknownCount);
                values.SetInteger("unknown table offset", UnknownTableLocation.AsPointer());
            }
            return(values);
        }
Ejemplo n.º 3
0
 public ThirdGenSoundResourceGestalt(StructureValueCollection values, IReader reader, FileSegmentGroup metaArea, EngineDescription buildInfo)
 {
     Load(values, reader, metaArea, buildInfo);
 }
Ejemplo n.º 4
0
        private void Load(StructureValueCollection values, FileSegmenter segmenter)
        {
            _eofSegment = segmenter.WrapEOF((int)values.GetInteger("file size"));

            var metaOffset = (int)values.GetInteger("meta offset");

            int tagTableSize = (int)values.GetInteger("tag data offset");
            int tagDataSize  = (int)values.GetInteger("tag data size");

            var headSegment = new FileSegment(
                segmenter.DefineSegment(metaOffset, tagTableSize, 0x1000, SegmentResizeOrigin.Beginning), segmenter);

            var metaSize       = (int)values.GetInteger("meta size");
            int metaOffsetMask = (int)values.GetInteger("meta offset mask");

            var metaSegment = new FileSegment(
                segmenter.DefineSegment(metaOffset + tagTableSize, tagDataSize, 0x1000, SegmentResizeOrigin.End), segmenter);

            MetaArea = new FileSegmentGroup(new MetaOffsetConverter(headSegment, (uint)metaOffsetMask));

            IndexHeaderLocation = MetaArea.AddSegment(headSegment);
            MetaArea.AddSegment(metaSegment);

            Type = (CacheFileType)values.GetInteger("type");

            var headerGroup = new FileSegmentGroup();

            headerGroup.AddSegment(segmenter.WrapSegment(0, HeaderSize, 1, SegmentResizeOrigin.None));

            StringIDCount = (int)values.GetInteger("string table count");
            var sidDataSize = (int)values.GetInteger("string table size");

            StringIDData = segmenter.WrapSegment((int)values.GetInteger("string table offset"), sidDataSize, 1,
                                                 SegmentResizeOrigin.End);
            StringIDIndexTable = segmenter.WrapSegment((int)values.GetInteger("string index table offset"), StringIDCount * 4, 4,
                                                       SegmentResizeOrigin.End);

            FileNameCount = (int)values.GetInteger("file table count");
            var fileDataSize = (int)values.GetInteger("file table size");

            FileNameData = segmenter.WrapSegment((int)values.GetInteger("file table offset"), fileDataSize, 1,
                                                 SegmentResizeOrigin.End);
            FileNameIndexTable = segmenter.WrapSegment((int)values.GetInteger("file index table offset"), FileNameCount * 4, 4,
                                                       SegmentResizeOrigin.End);

            InternalName = values.GetString("internal name");
            ScenarioName = values.GetString("scenario name");

            StringArea = new FileSegmentGroup();
            StringArea.AddSegment(segmenter.WrapSegment((int)values.GetInteger("string block offset"), StringIDCount * 0x80, 0x80,
                                                        SegmentResizeOrigin.End));
            StringArea.AddSegment(StringIDIndexTable);
            StringArea.AddSegment(StringIDData);
            StringArea.AddSegment(FileNameIndexTable);
            StringArea.AddSegment(FileNameData);

            StringIDIndexTableLocation = SegmentPointer.FromOffset(StringIDIndexTable.Offset, StringArea);
            StringIDDataLocation       = SegmentPointer.FromOffset(StringIDData.Offset, StringArea);
            FileNameIndexTableLocation = SegmentPointer.FromOffset(FileNameIndexTable.Offset, StringArea);
            FileNameDataLocation       = SegmentPointer.FromOffset(FileNameData.Offset, StringArea);

            LocaleArea = new FileSegmentGroup();

            var rawTableOffset = (int)values.GetInteger("raw table offset");
            var rawTableSize   = (int)values.GetInteger("raw table size");

            // It is apparently possible to create a cache without a raw table, but -1 gets written as the offset
            if (rawTableOffset != -1)
            {
                RawTable = segmenter.WrapSegment(rawTableOffset, rawTableSize, 0x80, SegmentResizeOrigin.End);
            }

            Checksum = (uint)values.GetInteger("checksum");

            // Set up a bogus partition table
            Partitions    = new Partition[1];
            Partitions[0] = new Partition(SegmentPointer.FromOffset(MetaArea.Offset, MetaArea), (uint)MetaArea.Size);
        }
Ejemplo n.º 5
0
 public SecondGenHeader(StructureValueCollection values, EngineDescription info, FileSegmenter segmenter)
 {
     BuildString = info.BuildVersion;
     HeaderSize  = info.HeaderSize;
     Load(values, segmenter);
 }
Ejemplo n.º 6
0
 public ThirdGenModelPermutation(StructureValueCollection values)
 {
     Load(values);
 }
Ejemplo n.º 7
0
 public FirstGenTag(StructureValueCollection values, FileSegmentGroup metaArea, Dictionary <int, ITagGroup> groupsById)
 {
     Load(values, metaArea, groupsById);
 }
Ejemplo n.º 8
0
 public SecondGenTagGroup(StructureValueCollection values)
 {
     Load(values);
 }
Ejemplo n.º 9
0
 private void Load(StructureValueCollection values)
 {
     Name = new StringID(values.GetInteger("name stringid"));
     ModelSectionIndex = (int)values.GetInteger("model section");
 }
Ejemplo n.º 10
0
 public ThirdGenModelVertexGroup(StructureValueCollection values, IModelSubmesh[] submeshes)
 {
     Load(values, submeshes);
 }
Ejemplo n.º 11
0
 public ThirdGenTag(StructureValueCollection values, ushort index, FileSegmentGroup metaArea,
                    IList <ITagClass> classList)
 {
     Load(values, index, metaArea, classList);
 }
Ejemplo n.º 12
0
 internal ScriptExpression(StructureValueCollection values, ushort index, StringTableReader stringReader)
 {
     Load(values, index, stringReader);
 }
Ejemplo n.º 13
0
        private void CalculateStringGroup(StructureValueCollection values, FileSegmenter segmenter)
        {
            if (DebugPointerConverter == null)
            {
                return;
            }

            StringArea = new FileSegmentGroup(DebugPointerConverter);

            // StringIDs
            StringIDCount = (int)values.GetInteger("string table count");
            if (StringIDCount > 0)
            {
                int sidIndexTableOff = DebugPointerConverter.PointerToOffset((uint)values.GetInteger("string index table offset"));
                int sidDataOff       = DebugPointerConverter.PointerToOffset((uint)values.GetInteger("string table offset"));

                var sidTableSize = (int)values.GetInteger("string table size");
                StringIDIndexTable = segmenter.WrapSegment(sidIndexTableOff, StringIDCount * 4, 4, SegmentResizeOrigin.End);
                StringIDData       = segmenter.WrapSegment(sidDataOff, sidTableSize, 1, SegmentResizeOrigin.End);

                StringIDIndexTableLocation = StringArea.AddSegment(StringIDIndexTable);
                StringIDDataLocation       = StringArea.AddSegment(StringIDData);

                // idk what this is, but H3Beta has it
                if (values.HasInteger("string block offset"))
                {
                    int sidBlockOff = DebugPointerConverter.PointerToOffset((uint)values.GetInteger("string block offset"));
                    StringBlock         = segmenter.WrapSegment(sidBlockOff, StringIDCount * 0x80, 0x80, SegmentResizeOrigin.End);
                    StringBlockLocation = StringArea.AddSegment(StringBlock);
                }

                // newest reach mcc caches store namespace information, hopefully others follow because thats one less thing to worry about every update
                if (values.HasInteger("string namespace table count"))
                {
                    StringIDNamespaceCount = (int)values.GetInteger("string namespace table count");
                    if (StringIDNamespaceCount > 0)
                    {
                        int namespaceTableOff = DebugPointerConverter.PointerToOffset((uint)values.GetInteger("string namespace table offset"));

                        StringIDNamespaceTable = segmenter.WrapSegment(namespaceTableOff, StringIDNamespaceCount * 4, 4, SegmentResizeOrigin.End);

                        StringIDNamespaceTableLocation = StringArea.AddSegment(StringIDNamespaceTable);
                    }
                }
            }

            // Tag names
            FileNameCount = (int)values.GetInteger("file table count");
            if (FileNameCount > 0)
            {
                int nameIndexTableOff = DebugPointerConverter.PointerToOffset((uint)values.GetInteger("file index table offset"));
                int nameDataOff       = DebugPointerConverter.PointerToOffset((uint)values.GetInteger("file table offset"));

                var fileTableSize = (int)values.GetInteger("file table size");
                FileNameIndexTable = segmenter.WrapSegment(nameIndexTableOff, FileNameCount * 4, 4, SegmentResizeOrigin.End);
                FileNameData       = segmenter.WrapSegment(nameDataOff, fileTableSize, 1, SegmentResizeOrigin.End);

                FileNameIndexTableLocation = StringArea.AddSegment(FileNameIndexTable);
                FileNameDataLocation       = StringArea.AddSegment(FileNameData);
            }

            // Some H4-only unknown table
            if (values.HasInteger("unknown table count") && values.HasInteger("unknown table offset"))
            {
                UnknownCount = (int)values.GetInteger("unknown table count");
                if (UnknownCount > 0)
                {
                    int unknownOff = DebugPointerConverter.PointerToOffset((uint)values.GetInteger("unknown table offset"));
                    UnknownTable         = segmenter.WrapSegment(unknownOff, UnknownCount * 0x10, 0x10, SegmentResizeOrigin.End);
                    UnknownTableLocation = StringArea.AddSegment(UnknownTable);
                }
            }
        }
Ejemplo n.º 14
0
 private ScriptObject[] ReadObjects(IReader reader, StructureValueCollection values, ScriptObjectTagBlock block)
 {
     return(block.ReadObjects(values, reader, _metaArea, _stringIDs, _buildInfo, _expander));
 }