public void ParseFile(CancellationToken cancelToken, Action <float, string> onProgressChanged = null, Action onFinished = null) { isParsed = false; isParsing = true; //currentMessage = "Reading BSP Data"; //onProgressChanged?.Invoke(PercentLoaded, currentMessage); using (VPKParser vpkParser = new VPKParser(vpkLoc)) using (BSPParser bspParser = new BSPParser(Path.Combine(mapDir, mapName + ".bsp"))) { bspParser.ParseData(cancelToken); //if (!cancelToken.IsCancellationRequested) // lightmaps = bspParser.GetLightmaps(cancelToken); int facesCount = Mathf.RoundToInt(bspParser.faces.Length * FaceLoadPercent); int propsCount = Mathf.RoundToInt(bspParser.staticProps.staticPropInfo.Length * ModelLoadPercent); totalItemsToLoad = facesCount + propsCount; bool validVPK = vpkParser.IsValid(); currentMessage = "Reading Map Faces"; onProgressChanged?.Invoke(PercentLoaded, currentMessage); ReadFaces(bspParser, validVPK ? vpkParser : null, cancelToken, onProgressChanged); currentMessage = "Reading Map Models"; onProgressChanged?.Invoke(PercentLoaded, currentMessage); if (validVPK) { ReadStaticProps(bspParser, vpkParser, cancelToken, onProgressChanged); } } onFinished?.Invoke(); isParsing = false; isParsed = true; }
public List <string> GetDependencies(CancellationToken cancelToken) { List <string> dependencies = new List <string>(); using (VPKParser vpkParser = new VPKParser(vpkLoc)) using (BSPParser bspParser = new BSPParser(Path.Combine(mapDir, mapName + ".bsp"))) { bool validVPK = vpkParser.IsValid(); if (!validVPK) { return(null); } bspParser.ParseData(cancelToken); if (cancelToken.IsCancellationRequested) { return(null); } //Note: If there are materials that point to textures in separate archives or there are textures used by the models whose vpk archive is not already // added by other dependencies, those archives will not be added. That would require us to read the materials and models to get what textures they use. #region Map face textures dependencies if (FaceLoadPercent > 0) { foreach (dface_t face in bspParser.faces) { if (cancelToken.IsCancellationRequested) { return(null); } texflags currentTexFlags = GetFaceTextureFlags(face, bspParser); string rawTextureLocation = GetFaceTextureLocation(face, bspParser); if (!IsUndesiredTexture(rawTextureLocation, currentTexFlags)) { string fixedLocation = VMTData.FixLocation(bspParser, vpkParser, rawTextureLocation); if (!vpkParser.FileExists(fixedLocation)) { fixedLocation = SourceTexture.FixLocation(bspParser, vpkParser, rawTextureLocation); } string dependency = vpkParser.LocateInArchive(fixedLocation); if (!string.IsNullOrEmpty(dependency) && !dependencies.Contains(dependency)) { dependencies.Add(dependency); } } } } #endregion #region Model dependencies if (ModelLoadPercent > 0) { for (int i = 0; i < bspParser.staticProps.staticPropInfo.Length; i++) { if (cancelToken.IsCancellationRequested) { return(null); } var currentPropInfo = bspParser.staticProps.staticPropInfo[i]; ushort propType = currentPropInfo.PropType; string modelFullPath = bspParser.staticProps.staticPropDict.names[propType]; modelFullPath = modelFullPath.Substring(0, modelFullPath.LastIndexOf(".")); string mdlPath = modelFullPath + ".mdl"; string vvdPath = modelFullPath + ".vvd"; string vtxPath = modelFullPath + ".vtx"; if (!vpkParser.FileExists(vtxPath)) { vtxPath = modelFullPath + ".dx90.vtx"; } string dependency = vpkParser.LocateInArchive(mdlPath); if (!string.IsNullOrEmpty(dependency) && !dependencies.Contains(dependency)) { dependencies.Add(dependency); } dependency = vpkParser.LocateInArchive(vvdPath); if (!string.IsNullOrEmpty(dependency) && !dependencies.Contains(dependency)) { dependencies.Add(dependency); } dependency = vpkParser.LocateInArchive(vtxPath); if (!string.IsNullOrEmpty(dependency) && !dependencies.Contains(dependency)) { dependencies.Add(dependency); } } } #endregion } return(dependencies); }