Ejemplo n.º 1
0
        /// <summary>
        /// Initializes this.
        /// Use this if you want to re-initialize the class without creating a new instance.
        /// </summary>
        /// <param name="headerAddress">The address of the menu metadata header.</param>
        /// <param name="isLoaded">True if the metadata is already loaded into the game, else false.</param>
        public void Initialize(MetadataHeader *headerAddress, bool isLoaded)
        {
            Header = headerAddress;

            var entryHeaderPtr = (byte *)(headerAddress + 1);

            ObjectSectionHeader = (ObjectSectionHeader *)entryHeaderPtr;

            InitializeOrClear(ref Objects, ObjectSectionHeader->NumObjects);
            InitializeOrClear(ref Layers, ObjectSectionHeader->NumObjects);
            InitializeOrClear(ref ActionLayers, ObjectSectionHeader->NumObjects);

            // Add entry
            for (int x = 0; x < ObjectSectionHeader->NumObjects; x++)
            {
                var entryPtr = isLoaded ? ObjectSectionHeader->GetObjectPointer(ObjectSectionHeader, x) : (Object *)(entryHeaderPtr + (uint)ObjectSectionHeader->GetObjectPointer(ObjectSectionHeader, x));
                Objects.Add(entryPtr);

                // Add action layers.
                var actionLayers = GetItemOrDefault(ActionLayers, x);
                InitializeOrClear(ref actionLayers, 1);

                // Add layers
                var layers = GetItemOrDefault(Layers, x);
                InitializeOrClear(ref layers, entryPtr->LayerCount);

                for (int y = 0; y < entryPtr->LayerCount; y++)
                {
                    var subEntryPtr = isLoaded ? entryPtr->GetLayerPointer(entryPtr, y) : (Layer *)((byte *)entryPtr + (uint)entryPtr->GetLayerPointer(entryPtr, y));
                    if (y == 0)
                    {
                        actionLayers.Add((ActionLayer *)subEntryPtr);
                    }
                    else
                    {
                        layers.Add(subEntryPtr);
                    }
                }

                ActionLayers.Add(actionLayers);
                Layers.Add(layers);
            }

            // Add final section.
            TextureIdHeader = isLoaded ? Header->TextureIndicesPtr : (TextureSectionHeader *)((byte *)headerAddress + (uint)Header->TextureIndicesPtr);
        }
        /*
         *  After this struct in memory follow pointers to individual entries.
         *  If the file is not loaded, it is an offset from the start of this header.
         *  If the file is loaded, it they are pointers to the actual entries.
         */

        /// <summary>
        /// Gets a pointer to a given subentry.
        /// </summary>
        public Object *GetObjectPointer(ObjectSectionHeader *thisHeader, int index)
        {
            var pointers = (uint *)(thisHeader + 1);

            return((Object *)pointers[index]);
        }