protected override void OnStart() { if (!string.IsNullOrEmpty(DemoName)) { var demPath = Path.Combine(Config.CsgoPath, Path.Combine("replays", DemoName + ".dem")); if (File.Exists(demPath)) { _demFile = new DemFile(File.OpenRead(demPath), NetClient); MapName = _demFile.MapName; } } if (_demFile != null) { _demFile.Initialize(); } if (!LoadMap) { return; } var filePath = Path.Combine(Config.CsgoPath, Path.Combine("maps", MapName + ".bsp")); if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { throw new FileNotFoundException("Could not find map file.", filePath); } using (var stream = File.OpenRead(filePath)) { BspFile = new VBspFile(stream); } Resources.AddResourceProvider(BspFile.PakFile); using (Profiler.Begin("CreateEntities")) { var infos = _demFile == null ? BspFile.GetEntityKeyVals().Concat(BspFile.GetStaticPropKeyVals()) : BspFile.GetStaticPropKeyVals(); foreach (var entInfo in infos) { EntityManager.CreateEntity(entInfo); } } ModelIndex = 0; base.OnStart(); Profiler.Print(); }
private void OnDestroy() { if (BspFile != null) { Resources.RemoveResourceProvider(BspFile.PakFile); } if (_demFile != null) { _demFile.Dispose(); _demFile = null; } }