public void *GetResource(MDLResourceType type, int entryId) { if (entryId < 0) { return(null); } int groupId = ModelLinker.IndexBank[_header._version].IndexOf(type); if (groupId < 0) { return(null); } byte *addr; fixed(void *p = &this) addr = (byte *)p; int offset = *((bint *)addr + 4 + groupId); if (offset > 0) { ResourceGroup *pGroup = (ResourceGroup *)(addr + offset); return((byte *)pGroup + (&pGroup->_first)[entryId + 1]._dataOffset); } return(null); }
//internal List<ResourceNode> _nodeCache; public MDL0GroupNode(MDLResourceType type) { _type = type; _name = _type.ToString("g"); }
//protected override int OnCalculateSize(bool force) //{ // int size = 0; // //Definitions // foreach (ResourceNode node in Children) // { // size += node.CalculateSize(force); // } // return size; //} protected internal override void PostProcess(VoidPtr bresAddress, VoidPtr dataAddress, int dataLength, StringTable stringTable) { base.PostProcess(bresAddress, dataAddress, dataLength, stringTable); MDL0Header * header = (MDL0Header *)dataAddress; ResourceGroup *pGroup, sGroup; ResourceEntry *pEntry, sEntry; bint * offsets = header->Offsets; int index, sIndex; //Model name header->StringOffset = (int)((byte *)stringTable[Name] + 4 - (byte *)header); //Post-process groups, using linker lists List <MDLResourceType> gList = ModelLinker.IndexBank[_version]; foreach (MDL0GroupNode node in Children) { MDLResourceType type = (MDLResourceType)Enum.Parse(typeof(MDLResourceType), node.Name); if (((index = gList.IndexOf(type)) >= 0) && (type != MDLResourceType.Shaders)) { node.PostProcess(dataAddress, dataAddress + offsets[index], stringTable); } } //Post-process definitions index = gList.IndexOf(MDLResourceType.Defs); pGroup = (ResourceGroup *)(dataAddress + offsets[index]); pGroup->_first = new ResourceEntry(0xFFFF, 0, 0, 0); pEntry = &pGroup->_first + 1; index = 1; if (_hasTree) { ResourceEntry.Build(pGroup, index++, (byte *)pGroup + (pEntry++)->_dataOffset, (BRESString *)stringTable["NodeTree"]); } if (_hasMix) { ResourceEntry.Build(pGroup, index++, (byte *)pGroup + (pEntry++)->_dataOffset, (BRESString *)stringTable["NodeMix"]); } if (_hasOpa) { ResourceEntry.Build(pGroup, index++, (byte *)pGroup + (pEntry++)->_dataOffset, (BRESString *)stringTable["DrawOpa"]); } if (_hasXlu) { ResourceEntry.Build(pGroup, index++, (byte *)pGroup + (pEntry++)->_dataOffset, (BRESString *)stringTable["DrawXlu"]); } //Link shader names using material list index = offsets[gList.IndexOf(MDLResourceType.Materials)]; sIndex = offsets[gList.IndexOf(MDLResourceType.Shaders)]; if ((index > 0) && (sIndex > 0)) { pGroup = (ResourceGroup *)(dataAddress + index); sGroup = (ResourceGroup *)(dataAddress + sIndex); pEntry = &pGroup->_first + 1; sEntry = &sGroup->_first + 1; sGroup->_first = new ResourceEntry(0xFFFF, 0, 0, 0); index = pGroup->_numEntries; for (int i = 1; i <= index; i++) { ResourceEntry.Build(sGroup, i, (byte *)sGroup + (sEntry++)->_dataOffset, (BRESString *)((byte *)pGroup + (pEntry++)->_stringOffset - 4)); } } }
public void* GetResource(MDLResourceType type, int entryId) { if (entryId < 0) return null; int groupId = ModelLinker.IndexBank[_header._version].IndexOf(type); if (groupId < 0) return null; byte* addr; fixed (void* p = &this) addr = (byte*)p; int offset = *((bint*)addr + 4 + groupId); if (offset > 0) { ResourceGroup* pGroup = (ResourceGroup*)(addr + offset); return (byte*)pGroup + (&pGroup->_first)[entryId + 1]._dataOffset; } return null; }