Esempio n. 1
0
        /// <summary>
        /// Loads a stringID cache from a string_ids.dat file.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <param name="resolver">The stringID resolver to use.</param>
        public StringIdCache(Stream stream, StringIdResolver resolver)
        {
            Resolver = resolver;

            if (stream.Length != 0)
            {
                Load(stream);
            }
            else
            {
                Strings = new List <string>();
            }
        }
Esempio n. 2
0
        public HaloOnlineCacheContext(DirectoryInfo directory) :
            base(directory)
        {
            var tagNames = LoadTagNames();

            using (var stream = OpenTagCacheRead())
                TagCache = new TagCache(stream, tagNames);

            if (CacheVersion.Unknown == (Version = CacheVersionDetection.DetectFromTagCache(TagCache, out var closestVersion)))
            {
                Version = closestVersion;
            }

            Deserializer = new TagDeserializer(Version == CacheVersion.Unknown ? closestVersion : Version);
            Serializer   = new TagSerializer(Version == CacheVersion.Unknown ? closestVersion : Version);

            StringIdResolver stringIdResolver = null;

            if (CacheVersionDetection.Compare(Version, CacheVersion.HaloOnline700123) >= 0)
            {
                stringIdResolver = new StringIdResolverMS30();
            }
            else if (CacheVersionDetection.Compare(Version, CacheVersion.HaloOnline498295) >= 0)
            {
                stringIdResolver = new StringIdResolverMS28();
            }
            else
            {
                stringIdResolver = new StringIdResolverMS23();
            }

            using (var stream = OpenStringIdCacheRead())
                StringIdCache = new StringIdCache(stream, stringIdResolver);

            TagGroup.Instances[new Tag("obje")] = new TagGroup(new Tag("obje"), Tag.Null, Tag.Null, GetStringId("object"));
            TagGroup.Instances[new Tag("item")] = new TagGroup(new Tag("item"), new Tag("obje"), Tag.Null, GetStringId("item"));
            TagGroup.Instances[new Tag("devi")] = new TagGroup(new Tag("devi"), new Tag("obje"), Tag.Null, GetStringId("device"));
            TagGroup.Instances[new Tag("unit")] = new TagGroup(new Tag("unit"), new Tag("obje"), Tag.Null, GetStringId("unit"));
            TagGroup.Instances[new Tag("rm  ")] = new TagGroup(new Tag("rm  "), Tag.Null, Tag.Null, GetStringId("render_method"));
            TagGroup.Instances[new Tag("test")] = new TagGroup(new Tag("test"), Tag.Null, Tag.Null, GetStringId("test_blah"));
        }
Esempio n. 3
0
        public GameCacheContextGen3(MapFile mapFile, EndianReader reader)
        {
            BaseMapFile         = mapFile;
            Version             = BaseMapFile.Version;
            Deserializer        = new TagDeserializer(Version);
            LocalesKey          = SetLocalesKey();
            StringsKey          = SetStringsKey();
            TagsKey             = SetTagsKey();
            NetworkKey          = SetNetworkKey();
            StringMods          = SetStringMods();
            LocaleGlobalsSize   = SetLocaleGlobalsSize();
            LocaleGlobalsOffset = SetLocaleGlobalsOffset();


            var interop = mapFile.Header.GetInterop();

            if (interop != null && interop.ResourceBaseAddress == 0)
            {
                Magic = (int)(interop.RuntimeBaseAddress - mapFile.Header.GetMemoryBufferSize());
            }
            else
            {
                mapFile.Header.ApplyMagic(mapFile.Header.GetStringIDsIndicesOffset() - mapFile.Header.GetHeaderSize(mapFile.Version));
                var resourcePartition = mapFile.Header.GetPartitions()[(int)CacheFilePartitionType.Resources];
                var resourceSection   = interop.Sections[(int)CacheFileSectionType.Resource];
                Magic = BitConverter.ToInt32(BitConverter.GetBytes(resourcePartition.BaseAddress), 0) - (interop.DebugSectionSize + resourceSection.Size);
            }

            if (mapFile.Header.GetTagIndexAddress() == 0)
            {
                return;
            }

            mapFile.Header.SetTagIndexAddress(BitConverter.ToUInt32(BitConverter.GetBytes(mapFile.Header.GetTagIndexAddress() - Magic), 0));

            IndexHeader = mapFile.GetIndexHeader(reader, Magic);
            Strings     = CreateStringTable(reader);
            IndexItems  = CreateCacheIndexTable(reader);

            LocaleTables = new List <CacheLocaleTable>();

            switch (mapFile.Version)
            {
            case CacheVersion.Halo3Retail:
                Resolver = new StringIdResolverHalo3();
                break;

            case CacheVersion.Halo3ODST:
                Resolver = new StringIdResolverHalo3ODST();
                break;

            case CacheVersion.HaloReach:
                Resolver = new StringIdResolverHaloReach();
                break;

            default:
                throw new NotSupportedException(CacheVersionDetection.GetBuildName(mapFile.Version));
            }

            foreach (var language in Enum.GetValues(typeof(GameLanguage)))
            {
                LocaleTables.Add(CreateLocaleTable(reader, (GameLanguage)language));
            }
        }