protected void ReadGroupTags(Managers.BlamDefinition gd, IO.EndianReader s)
        {
            uint gt = s.ReadUInt32();

            if (gt != uint.MaxValue)
            {
                GroupTag1 = gd.TagGroupFind(TagInterface.TagGroup.FromUInt(gt));
            }
            else
            {
                GroupTag1 = TagInterface.TagGroup.Null;
            }

            gt = s.ReadUInt32();
            if (gt != uint.MaxValue)
            {
                GroupTag2 = gd.TagGroupFind(TagInterface.TagGroup.FromUInt(gt));
            }
            else
            {
                GroupTag2 = TagInterface.TagGroup.Null;
            }

            gt = s.ReadUInt32();
            if (gt != uint.MaxValue)
            {
                GroupTag3 = gd.TagGroupFind(TagInterface.TagGroup.FromUInt(gt));
            }
            else
            {
                GroupTag3 = TagInterface.TagGroup.Null;
            }
        }
Exemplo n.º 2
0
        public void ReadAlpha(IO.EndianReader s)
        {
            GroupTagInt = s.ReadUInt32();
            groupTag    = Program.Halo2.Manager.TagGroupFind(TagInterface.TagGroup.FromUInt(GroupTagInt));
            IO.ByteSwap.SwapUDWord(ref GroupTagInt);

            s.ReadUInt32(); s.ReadUInt32();
            datum.Read(s);
            tagNameOffset = s.ReadUInt32();
            address       = s.ReadUInt32();                             //offset = (int)(address - s.BaseAddress);
            size          = s.ReadInt32();
            s.ReadInt32();
        }
        void InitializeBspTags(IO.EndianReader s, Blam.CacheFile cache)
        {
            // Seek to the scenario's scenario_structure_bsps_block tag_block field
            s.Seek(items[0].Offset + 1444, System.IO.SeekOrigin.Begin);
            bspTags = new Item[s.ReadInt32()];
            uint sbsp_offset = s.ReadPointer();

            // Seek to the scenario_structure_bsps_block definitions
            s.Seek(sbsp_offset, System.IO.SeekOrigin.Begin);
            DatumIndex    di   = new DatumIndex();
            CacheItemBase item = null;

            // Process each definition's runtime data
            for (int x = 0; x < bspTags.Length; x++)
            {
                s.Seek(28, System.IO.SeekOrigin.Current);
                di.Read(s);
                item       = items[di.Index];
                bspTags[x] = item as CacheItemBase;
                // Seek back to the beginning of the definition so the following stream code works
                s.Seek(-Halo1.Tags.scenario_structure_bsps_block.kSizeOf, System.IO.SeekOrigin.Current);

                // We're actually selectively reading scenario_structure_bsps_block fields here

                // The offset actually points to the bsp header, and the bsp comes after that header
                item.Offset = s.ReadInt32() + Halo1.Tags.scenario_structure_bsps_header.kSizeOf;
                item.Size   = s.ReadInt32();
                cache.BspAddressMasks.Add(s.ReadUInt32() - (uint)item.Offset);                 // won't count the header
                item.BspIndex = bspCount++;
                // Seek to the end of this definition, and thus, the start of the next definition
                s.Seek(20, System.IO.SeekOrigin.Current);
            }
        }
Exemplo n.º 4
0
 /// <summary>Stream the pointer data from a buffer</summary>
 /// <param name="s"></param>
 /// <remarks>Number of bytes read depends on <see cref="Is64bit"/></remarks>
 public void Read(IO.EndianReader s)
 {
     if (!Is64bit)
     {
         this.u32 = s.ReadUInt32();
     }
     else
     {
         this.u64 = s.ReadUInt64();
     }
 }
        public static void Assert(IO.EndianReader s, uint expected)
        {
            Contract.Requires(s != null);

            var version = s.ReadUInt32();

            if (version != expected)
            {
                throw new VersionMismatchException(s.BaseStream, expected, version);
            }
        }
Exemplo n.º 6
0
        public static bool IsScaleformBuffer(IO.EndianReader s, out uint signature)
        {
            signature = s.ReadUInt32() & 0x00FFFFFF;
            switch (signature)
            {
            case kSwfSignature:
            case kGfxSignature:
            case kSwfCompressedSignature:
            case kGfxCompressedSignature:
                return(true);

            default: return(false);
            }
        }
        public static uint Assert(IO.EndianReader s
                                  , uint expectedMin
                                  , uint expectedMax)
        {
            Contract.Requires(s != null);

            var version = s.ReadUInt32();

            if (version < expectedMin || version > expectedMax)
            {
                throw new VersionOutOfRangeException(s.BaseStream, expectedMin, expectedMax, version);
            }

            return(version);
        }
Exemplo n.º 8
0
        /// <summary>Read the header for the pool from a stream to properly initialize this pool's configuration, counts, etc</summary>
        /// <param name="s"></param>
        public void ReadHeader(IO.EndianReader s)
        {
            Contract.Requires(s != null);
            // #TODO: test to see if the config is a built-in, else we could overwrite an existing config
//			Configuration.Read(s);
            int count = s.ReadInt32();

            Size = s.ReadUInt32();

            InitializeCollections(count);
            for (int x = 0; x < mReferences.Count; x++)
            {
                mReferences[x] = new Values.PtrHandle(Settings.AddressSize);
            }
        }
Exemplo n.º 9
0
        public override void Read(IO.EndianReader s)
        {
            GroupTagInt = s.ReadUInt32();
            groupTag    = Program.Halo2.Manager.TagGroupFind(TagInterface.TagGroup.FromUInt(GroupTagInt));
            IO.ByteSwap.SwapUDWord(ref GroupTagInt);

            datum.Read(s);
            address = s.ReadUInt32();

            if (GroupTagInt == uint.MaxValue)
            {
                location = CacheIndex.ItemLocation.Unknown;
            }
            else if (address == 0)
            {
                location = CacheIndex.ItemLocation.External;
            }
            else
            {
                offset = (int)(address - s.BaseAddress);
            }

            size = s.ReadInt32();
        }
Exemplo n.º 10
0
        public Definition Parse()
        {
            Debug.Assert.If(InputStream != null,
                            "Can't parse a definition file when we're not initialized for that mode");

            InputStream.ReadTag();             // Ext
            //groupTag = InputStream.ReadTag();
            engine  = (BlamVersion)InputStream.ReadUInt32();
            version = InputStream.ReadInt16();
            header  = InputStream.ReadInt16();

            this.def = new Definition();
            //this.def.SetOwnerObject(this.def); // we want fields of this definition to point to the definition as their parent
            return(Parse(null));
        }
        public uint GetSizeValue(uint dataOffset)
        {
            if (!ValidOffset(dataOffset))
            {
                throw new ArgumentOutOfRangeException("dataOffset", string.Format("{0} > {1}",
                                                                                  dataOffset.ToString("X8"), mPoolSize.ToString("X6")));
            }
            if (dataOffset < sizeof(uint))
            {
                throw new ArgumentOutOfRangeException("dataOffset", "Offset doesn't have room for a size value");
            }

            uint size_value;

            if (!mDataOffsetToSizeValue.TryGetValue(dataOffset, out size_value))
            {
                if (mBufferedDataRemaining == 0)
                {
                    throw new InvalidOperationException("No data left in buffer");
                }
                else if (mBuffer == null)
                {
                    throw new InvalidOperationException("No underlying buffer");
                }

                uint size_offset = dataOffset - sizeof(uint);
                // Great, now read the entry's value data
                mBuffer.Seek32(size_offset);
                size_value = mBuffer.ReadUInt32();

                // Update how much data is still remaining
                mBufferedDataRemaining -= sizeof(uint);

                if (mBufferedDataRemaining == 0)
                {
                    DisposeBuffer();
                }

                mDataOffsetToSizeValue.Add(dataOffset, size_value);
            }

            return(size_value);
        }
Exemplo n.º 12
0
        public static bool VerifyIsEcf(IO.EndianReader s)
        {
            const int k_sizeof_signature = sizeof(uint);

            Contract.Requires <InvalidOperationException>(s.BaseStream.CanRead);
            Contract.Requires <InvalidOperationException>(s.BaseStream.CanSeek);

            var base_stream = s.BaseStream;

            if ((base_stream.Length - base_stream.Position) < k_sizeof_signature)
            {
                return(false);
            }

            uint sig = s.ReadUInt32();

            base_stream.Seek(-k_sizeof_signature, SeekOrigin.Current);

            return(sig == kSignature);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Stream the datum index from a buffer
 /// </summary>
 /// <param name="input"></param>
 public void Read(IO.EndianReader input)
 {
     Handle = input.ReadUInt32();
 }
        public override void Read(IO.EndianReader s)
        {
            int k_local_sizeof = Blam.CacheFile.ValidateHeader(s, kSizeOf);

            s.Seek(4);
            version = s.ReadInt32();
            if (version != 11 && version != 12)
            {
                throw new InvalidCacheFileException(s.FileName);
            }
            fileLength = s.ReadInt32();
            s.ReadInt32();
            tagIndexAddress    = s.ReadUInt32();
            memoryBufferOffset = s.ReadInt32();
            memoryBufferSize   = s.ReadInt32();

            sourceFile = s.ReadAsciiString(256);
            build      = s.ReadTagString();
            cacheType  = (Blam.CacheType)s.ReadInt16();
            sharedType = (Cache.SharedType)s.ReadInt16();

            s.ReadBool();
            s.ReadBool();             // false if it belongs to a untracked build
            s.ReadBool();
            // PATCH: this is '3' in main menu patches
            s.ReadByte();             // appears to be an ODST-only field

            s.ReadInt32(); s.ReadInt32();
            s.ReadInt32(); s.ReadInt32(); s.ReadInt32();

            #region string id table
            // 0x158
            stringIdsCount        = s.ReadInt32();
            stringIdsBufferSize   = s.ReadInt32();
            stringIdIndicesOffset = s.ReadInt32();
            stringIdsBufferOffset = s.ReadInt32();
            #endregion

            #region filetimes?
            // pretty sure this is a flags field
            // used to tell which of the following 64bit values
            // are used. Damn sure this are FILETIME structures, but
            // hex workshop doesn't like them so I can't be for sure...
            needsShared             = s.ReadInt32() != 0; // just a little 'hack' if you will. if zero, the map is self reliant, so no worries
            Filetime.dwHighDateTime = s.ReadInt32();
            Filetime.dwLowDateTime  = s.ReadInt32();
            if (s.ReadInt32() != 0)
            {
                flags.Add(Halo3.CacheHeaderFlags.DependsOnMainMenu);
            }
            s.ReadInt32();
            if (s.ReadInt32() != 0)
            {
                flags.Add(Halo3.CacheHeaderFlags.DependsOnShared);
            }
            s.ReadInt32();
            if (s.ReadInt32() != 0)
            {
                flags.Add(Halo3.CacheHeaderFlags.DependsOnCampaign);
            }
            s.ReadInt32();
            #endregion

            name = s.ReadTagString();
            s.ReadInt32();
            scenarioPath = s.ReadAsciiString(256);
            // PATCH: this is -1 in main menu patches
            s.ReadInt32();             // minor version, normally not used

            #region tag paths
            tagNamesCount        = s.ReadInt32();
            tagNamesBufferOffset = s.ReadInt32();           // cstring buffer
            tagNamesBufferSize   = s.ReadInt32();           // cstring buffer total size in bytes
            tagNameIndicesOffset = s.ReadInt32();

            TagsUnknown1Count  = s.ReadInt32();
            TagsUnknown1Offset = s.ReadInt32();
            // PATCH: zero for non-patch data
            TagsUnknown2Count  = s.ReadInt32();
            TagsUnknown2Offset = s.ReadInt32();
            #endregion

            checksum = s.ReadUInt32();                // 0x2D4
            s.Seek(32, System.IO.SeekOrigin.Current); // these bytes are always the same. first 8 changed in Halo4

            baseAddress = s.ReadUInt32();             // expected base address
            xdkVersion  = s.ReadInt32();              // xdk version

            #region memory partitions
            // 0x300

            // memory partitions
            memoryPartitions = new Partition[6];
            memoryPartitions[0].BaseAddress = s.ReadUInt32();             // cache resource buffer
            memoryPartitions[0].Size        = s.ReadInt32();

            // readonly
            memoryPartitions[1].BaseAddress = s.ReadUInt32();             // cache gestalt resource buffer
            memoryPartitions[1].Size        = s.ReadInt32();

            memoryPartitions[2].BaseAddress = s.ReadUInt32();             // global tags buffer (cache sound tags likes this memory space too)
            memoryPartitions[2].Size        = s.ReadInt32();
            memoryPartitions[3].BaseAddress = s.ReadUInt32();             // shared tag blocks? (havok data likes this memory space too)
            memoryPartitions[3].Size        = s.ReadInt32();
            memoryPartitions[4].BaseAddress = s.ReadUInt32();             // address
            memoryPartitions[4].Size        = s.ReadInt32();

            // readonly
            memoryPartitions[5].BaseAddress = s.ReadUInt32();             // map tags buffer
            memoryPartitions[5].Size        = s.ReadInt32();
            #endregion

            int count = s.ReadInt32();
            s.Seek(4 + 8, System.IO.SeekOrigin.Current);             // these bytes are always the same
            // if there is a hash in the header, this is the ONLY
            // place where it can be
            s.Seek(20 /*SHA1*/ + 40 + 256 /*RSA*/, System.IO.SeekOrigin.Current);             // ???

            // 0x47C
            cacheInterop.Read(s);
            cacheInterop.PostprocessForCacheRead(k_local_sizeof);

            s.Seek(16, System.IO.SeekOrigin.Current);             // GUID?, these bytes are always the same. ODST is different from Halo 3

            // PATCH: main menu patches have a single entry (where stock has none)
            #region blah 1
            // 0x4AC

            // campaign has a shit load of these
            // but shared doesn't nor mainmenu
            // I compared the sc110 french and english and both have the SAME counts and element data. So
            // I don't think this is a hash or something. At least, if it is, it's not runtime relative so
            // nothing we have to worry about

            s.ReadInt16();             // I've only seen this be two different values (besides zero).
            count = s.ReadInt16();     // I think the above specifies the size of the structure this count represents?
            s.ReadInt32();             // seems to always be zero
            CompressionGuid = new Guid(s.ReadBytes(16));

            s.Seek(count * 28, System.IO.SeekOrigin.Current);             // seek past the elements
            // dword
            // long
            // buffer [0x14] (probably a sha1 hash)
            s.Seek((3600 - count) * 28, System.IO.SeekOrigin.Current);             // seek past the unused elements
            #endregion

            // PATCH: main menu patches have a count of '1' but doesn't appear to have
            #region blah 2
            s.Seek(sizeof(uint) + 0x4E9C, System.IO.SeekOrigin.Current);
#if false
            {
                // 0x18E94

                // going to punt and just assume there is a max count of 13 of these possible

                // maybe related to bsp\'zones'?
                const int blah2_sizeof = 0x60C;

                count = (int)(s.ReadUInt32() >> 24);                               // did someone forget to f*****g byte swap something?
                s.Seek(count * blah2_sizeof, System.IO.SeekOrigin.Current);        // seek past the elements
                s.Seek((13 - count) * blah2_sizeof, System.IO.SeekOrigin.Current); // seek past the unused elements
            }
#endif
            #endregion

            s.Seek(712 + sizeof(uint), System.IO.SeekOrigin.Current);


            ReadPostprocessForInterop();

            if (!cacheInterop.IsNull)
            {
                int debug_mask = (int)cacheInterop[CacheSectionType.Debug].AddressMask;
                if (TagsUnknown1Offset != 0)
                {
                    TagsUnknown1Offset -= debug_mask;
                }
                if (TagsUnknown2Offset != 0)
                {
                    TagsUnknown2Offset -= debug_mask;
                }
            }

            ReadPostprocessForBaseAddresses(s);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Stream the resource pointer from a buffer
 /// </summary>
 /// <param name="input"></param>
 public void Read(IO.EndianReader input)
 {
     Ptr = input.ReadUInt32();
 }
        public static void Read(IO.EndianReader s, out XmbVariant v)
        {
            uint data = s.ReadUInt32();

            Compose(out v, data);
        }
Exemplo n.º 17
0
 /// <summary>Stream an string id from a buffer</summary>
 /// <param name="s"></param>
 //public void Read(IO.EndianReader s)	{ mHandle = s.ReadUInt32(); }
 public void Read(IO.EndianReader s, StringIdDesc desc)
 {
     mHandle = s.ReadUInt32();
     mDesc   = desc;
 }
Exemplo n.º 18
0
            void ReadInt(IO.EndianReader s)
            {
                switch (TypeDesc.SizeOf)
                {
                case sizeof(byte):
                {
                    if (ArrayLength == 1)
                    {
                        Int = TypeDesc.IsUnsigned
                                                                ? (uint)s.ReadByte()
                                                                : (uint)s.ReadSByte();
                    }
                    else
                    {
                        if (TypeDesc.IsUnsigned)
                        {
                            var array = s.ReadBytes(ArrayLength);

                            OpaqueArrayRef = array;
                        }
                        else
                        {
                            var array = new sbyte[ArrayLength];
                            for (int x = 0; x < array.Length; x++)
                            {
                                array[x] = s.ReadSByte();
                            }

                            OpaqueArrayRef = array;
                        }
                    }
                } break;

                case sizeof(ushort):
                {
                    if (ArrayLength == 1)
                    {
                        Int = TypeDesc.IsUnsigned
                                                                ? (uint)s.ReadUInt16()
                                                                : (uint)s.ReadInt16();
                    }
                    else
                    {
                        if (TypeDesc.IsUnsigned)
                        {
                            var array = new ushort[ArrayLength];
                            for (int x = 0; x < array.Length; x++)
                            {
                                array[x] = s.ReadUInt16();
                            }

                            OpaqueArrayRef = array;
                        }
                        else
                        {
                            var array = new short[ArrayLength];
                            for (int x = 0; x < array.Length; x++)
                            {
                                array[x] = s.ReadInt16();
                            }

                            OpaqueArrayRef = array;
                        }
                    }
                } break;

                case sizeof(uint):
                {
                    if (ArrayLength == 1)
                    {
                        Int = TypeDesc.IsUnsigned
                                                                ? (uint)s.ReadUInt32()
                                                                : (uint)s.ReadInt32();
                    }
                    else
                    {
                        if (TypeDesc.IsUnsigned)
                        {
                            var array = new uint[ArrayLength];
                            for (int x = 0; x < array.Length; x++)
                            {
                                array[x] = s.ReadUInt32();
                            }

                            OpaqueArrayRef = array;
                        }
                        else
                        {
                            var array = new int[ArrayLength];
                            for (int x = 0; x < array.Length; x++)
                            {
                                array[x] = s.ReadInt32();
                            }

                            OpaqueArrayRef = array;
                        }
                    }
                } break;

                case sizeof(ulong):
                {
                    if (ArrayLength == 1)
                    {
                        Int64 = TypeDesc.IsUnsigned
                                                                ? (ulong)s.ReadUInt64()
                                                                : (ulong)s.ReadInt64();
                    }
                    else
                    {
                        if (TypeDesc.IsUnsigned)
                        {
                            var array = new ulong[ArrayLength];
                            for (int x = 0; x < array.Length; x++)
                            {
                                array[x] = s.ReadUInt64();
                            }

                            OpaqueArrayRef = array;
                        }
                        else
                        {
                            var array = new long[ArrayLength];
                            for (int x = 0; x < array.Length; x++)
                            {
                                array[x] = s.ReadInt64();
                            }

                            OpaqueArrayRef = array;
                        }
                    }
                } break;

                default:
                    throw new KSoft.Debug.UnreachableException(TypeDesc.SizeOf.ToString());
                }
            }