static void LoadStaticProps() { BSPFileReader.BaseStream.Seek(BSP_Header.Lumps[35].FileOfs, SeekOrigin.Begin); Int32 GameLumpCount = BSPFileReader.ReadInt32(); dgamelump_t[] BSP_GameLump = new dgamelump_t[GameLumpCount]; BSPFileReader.ReadArray(ref BSP_GameLump); for (Int32 i = 0; i < GameLumpCount; i++) { if (BSP_GameLump[i].Id == 1936749168) { BSPFileReader.BaseStream.Seek(BSP_GameLump[i].FileOfs, SeekOrigin.Begin); var Start = BSPFileReader.BaseStream.Position; String[] ModelEntries = new String[BSPFileReader.ReadInt32()]; for (Int32 j = 0; j < ModelEntries.Length; j++) { ModelEntries[j] = new String(BSPFileReader.ReadChars(128)).Replace(".mdl", ""); if (ModelEntries[j].Contains('\0')) { ModelEntries[j] = ModelEntries[j].Split('\0')[0]; } } UInt16[] LeafEntries = new UInt16[BSPFileReader.ReadInt32()]; BSPFileReader.ReadArray(ref LeafEntries); Int32 nStaticProps = BSPFileReader.ReadInt32(); //prop_size = (size -(reader.tell()-start))//self.prop_num //REDxEYE "fix". Int32 prop_size = 0; try { prop_size = (Int32)((BSP_GameLump[i].FileLen - (BSPFileReader.BaseStream.Position - Start)) / nStaticProps); } catch (DivideByZeroException) { Debug.Log(String.Format("Static props not found. Division of {0} by zero.", nStaticProps)); } for (Int32 l = 0; l < nStaticProps; l++) { var prop_start = BSPFileReader.BaseStream.Position; StaticPropLumpV4_t StaticPropLump_t = new StaticPropLumpV4_t(); BSPFileReader.ReadType(ref StaticPropLump_t); switch (BSP_GameLump[i].Version) { case 5: BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV5_t))); break; case 6: BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV6_t))); break; case 7: BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV7_t))); break; case 8: BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV8_t))); break; case 9: BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV9_t))); break; case 10: BSPFileReader.ReadBytes(Marshal.SizeOf(typeof(StaticPropLumpV10_t))); break; } BSPFileReader.BaseStream.Seek(prop_start + prop_size, 0); String StaticPropName = ModelEntries[StaticPropLump_t.m_PropType]; Transform MdlTransform = StudioMDLLoader.Load(StaticPropName); MdlTransform.position = MathUtils.SwapZY(StaticPropLump_t.m_Origin) * ConfigLoader.WorldScale; Vector3 EulerAngles = new Vector3(StaticPropLump_t.m_Angles.z, -StaticPropLump_t.m_Angles.y, StaticPropLump_t.m_Angles.x); MdlTransform.eulerAngles = EulerAngles; MdlTransform.SetParent(BSP_WorldSpawn.transform); } } } }
private static void LoadStaticProps() { BinaryReader.BaseStream.Position = BSP_Header.lumps[35].fileofs; GameObject staticProps = new GameObject(WorldController.MapName + "_props"); int gamelumpCount = BinaryReader.ReadInt32(); dgamelump_t[] gamelumps = CRead.ReadType <dgamelump_t>((uint)gamelumpCount); for (int i = 0; i < gamelumpCount; i++) { if (gamelumps[i].id == 1936749168) { BinaryReader.BaseStream.Position = gamelumps[i].fileofs; int dictEntries = BinaryReader.ReadInt32(); string[] names = new string[dictEntries]; for (int l = 0; l < dictEntries; l++) { names[l] = new string(BinaryReader.ReadChars(128)); if (names[l].Contains(Convert.ToChar(0))) { names[l] = names[l].Remove(names[l].IndexOf(Convert.ToChar(0))); } } int leafEntries = BinaryReader.ReadInt32(); CRead.ReadType <ushort>((uint)leafEntries); int nStaticProps = BinaryReader.ReadInt32(); for (int l = 0; l < nStaticProps; l++) { StaticPropLumpV4_t StaticPropLump_t = CRead.ReadType <StaticPropLumpV4_t>(); switch (gamelumps[i].version) { case 5: CRead.ReadType <StaticPropLumpV5_t>(); break; case 6: CRead.ReadType <StaticPropLumpV6_t>(); break; case 7: CRead.ReadType <StaticPropLumpV7_t>(); break; case 8: CRead.ReadType <StaticPropLumpV8_t>(); break; case 9: CRead.ReadType <StaticPropLumpV9_t>(); break; case 10: CRead.ReadType <StaticPropLumpV10_t>(); break; } // Load studio model and apply position Transform mdlTransform = StudioMdlLoader.LoadMdl(names[StaticPropLump_t.m_PropType].Replace(".mdl", "")); mdlTransform.localPosition = WorldController.SwapZY(StaticPropLump_t.m_Origin) * WorldController.WorldScale; // Calculate rotation for model Vector3 mdlRotation = new Vector3(StaticPropLump_t.m_Angles.z, -StaticPropLump_t.m_Angles.y, StaticPropLump_t.m_Angles.x); mdlTransform.eulerAngles = mdlRotation; mdlTransform.parent = staticProps.transform; } } } }