public CMeshSystem FetchMeshSystem(char[] pName, CMeshSystem system) { var entry = Entries.FindIndex(x => x.Name.ToLower() == new string(pName).ToLower()); var fetched = FetchMeshSystem((uint)entry, system); if (!fetched) { throw new Exception($"Failed to fetch mesh system for object {new string(pName)}"); } return(system); }
public bool FetchMeshSystem(uint index, CMeshSystem system) { if (index >= NumEntries()) { return(false); } SUberEntry entry = Entries[(int)index]; SUberEntry nextEntry = Entries[(int)index + 1]; var bytes = ModelData.Skip((int)entry.ModelDataOffset).Take((int)nextEntry.ModelDataOffset - (int)entry.ModelDataOffset).ToArray(); m_ModelDataCache.m_pBuffer = bytes; var r = new CDynMemoryReader(ref m_ModelDataCache); m_pMeshDataCur = entry.MeshDataOffset; m_pMeshDataEnd = m_pMeshDataCur + (nextEntry.MeshDataOffset - entry.MeshDataOffset); m_LookupOffset = entry.LookupOffset; m_U32Offset = entry.U32Offset; if (!system.Load(ref r, this)) { return(false); } system.Name = entry.Name; if (entry.Name.StartsWith("map") && char.IsNumber(entry.Name[3]) && char.IsNumber(entry.Name[4])) { system.Flags |= (int)MeshFlags.MESHSYS_FLAG_MAP_GEOMETRY; } if (entry.Name.StartsWith("ugd") && char.IsNumber(entry.Name[3]) && char.IsNumber(entry.Name[4])) { system.Flags |= (int)MeshFlags.MESHSYS_FLAG_MAP_GEOMETRY; } if (entry.Name.StartsWith("lava") && char.IsNumber(entry.Name[4]) && char.IsNumber(entry.Name[5])) { system.Flags |= (int)MeshFlags.MESHSYS_FLAG_MAP_GEOMETRY; } return(true); }