Example #1
0
        private void LoadInteropData(StructureValueCollection headerValues)
        {
            // TODO: fix this shit for the h3beta better
            if (headerValues.HasArray("offset masks") && headerValues.HasArray("sections"))
            {
                SectionOffsetMasks = headerValues.GetArray("offset masks").Select(v => (uint)v.GetInteger("mask")).ToArray();
                Sections           = headerValues.GetArray("sections").Select(v => new ThirdGenInteropSection(v)).ToArray();

                // H3 MCC currently doesn't store section data for campaign/shared, so it must be hacked together
                if (_expander.IsValid && (Type == CacheFileType.Shared || Type == CacheFileType.SinglePlayerShared))
                {
                    if (Sections[(int)ThirdGenInteropSectionType.Resource].Size == 0)
                    {
                        Sections[(int)ThirdGenInteropSectionType.Resource].VirtualAddress = (uint)HeaderSize;
                        Sections[(int)ThirdGenInteropSectionType.Resource].Size           = (uint)FileSize - (uint)HeaderSize;
                    }
                }
            }
            else             //else hack up our own sections
            {
                SectionOffsetMasks = new uint[] { 0, 0, 0, 0 };

                ThirdGenInteropSection debugSection = new ThirdGenInteropSection(
                    (uint)headerValues.GetInteger("string index table offset"),
                    (uint)(headerValues.GetInteger("file size") - headerValues.GetInteger("string index table offset")));
                ThirdGenInteropSection resourceSection = new ThirdGenInteropSection(0, 0);                 // this is between locales and tag, so if we had a locale size, this section could be calculated. Using 0's for now seems to work at least
                ThirdGenInteropSection tagSection      = new ThirdGenInteropSection(
                    (uint)headerValues.GetInteger("tag buffer offset"),
                    (uint)headerValues.GetInteger("virtual size"));
                ThirdGenInteropSection localeSection = new ThirdGenInteropSection(
                    (uint)HeaderSize,
                    (uint)headerValues.GetInteger("tag buffer offset"));                     //bs the size for now

                Sections = new ThirdGenInteropSection[] { debugSection, resourceSection, tagSection, localeSection };
            }

            DebugPointerConverter     = MakePointerConverter(ThirdGenInteropSectionType.Debug);
            ResourcePointerConverter  = MakePointerConverter(ThirdGenInteropSectionType.Resource);
            TagBufferPointerConverter = MakePointerConverter(ThirdGenInteropSectionType.Tag);
            LocalePointerConverter    = MakePointerConverter(ThirdGenInteropSectionType.Localization);
        }