public static SourceTexture GrabTexture(BSPParser bspParser, VPKParser vpkParser, string rawPath) { SourceTexture srcTexture = null; if (!string.IsNullOrEmpty(rawPath)) { string vtfFilePath = FixLocation(bspParser, vpkParser, rawPath); if (!string.IsNullOrEmpty(vtfFilePath)) { if (loadedTextures.ContainsKey(vtfFilePath)) { srcTexture = loadedTextures[vtfFilePath]; } else { if (bspParser != null && bspParser.HasPakFile(vtfFilePath)) { //Debug.Log("Loaded " + vtfFilePath + " from pakfile"); srcTexture = ReadAndCache(bspParser.GetPakFile(vtfFilePath), vtfFilePath); } else if (vpkParser != null && vpkParser.FileExists(vtfFilePath)) { try { vpkParser.LoadFileAsStream(vtfFilePath, (stream, origOffset, fileLength) => { srcTexture = ReadAndCache(stream, origOffset, vtfFilePath); }); } catch (Exception e) { Debug.LogError("SourceTexture: " + e.ToString()); } } else { Debug.LogError("SourceTexture: Could not find Texture FixedPath(" + vtfFilePath + ") RawPath(" + rawPath + ")"); } } } else { Debug.LogError("SourceTexture: Could not find texture at " + rawPath); } } else { Debug.LogError("SourceTexture: Texture string path is null or empty"); } return(srcTexture); }
/*public static VMTData GrabVMT(byte[] data, string rawPath) * { * VMTData vmtData = null; * * if (!string.IsNullOrEmpty(rawPath)) * { * string vmtFilePath = rawPath.Replace("\\", "/").ToLower(); * * if (vmtCache.ContainsKey(vmtFilePath)) * { * vmtData = vmtCache[vmtFilePath]; * } * else * { * vmtData = new VMTData(vmtFilePath); * vmtData.Parse(data); * } * } * else * Debug.LogError("VMTData: Given path is null or empty"); * * return vmtData; * }*/ public static VMTData GrabVMT(BSPParser bspParser, VPKParser vpkParser, string rawPath, bool grabDependants = true) { VMTData vmtData = null; if (!string.IsNullOrEmpty(rawPath)) { string vmtFilePath = FixLocation(bspParser, vpkParser, rawPath); if (vmtCache.ContainsKey(vmtFilePath)) { vmtData = vmtCache[vmtFilePath]; if (grabDependants) { vmtData.GrabDependants(bspParser, vpkParser); } } else { if (bspParser != null && bspParser.HasPakFile(vmtFilePath)) { vmtData = new VMTData(vmtFilePath); //Debug.Log("Loaded " + vmtFilePath + " from pakfile"); vmtData.Parse(bspParser.GetPakFile(vmtFilePath)); if (grabDependants) { vmtData.GrabDependants(bspParser, vpkParser); } } else if (vpkParser != null && vpkParser.FileExists(vmtFilePath)) { try { byte[] vmtByteData = null; vpkParser.LoadFileAsStream(vmtFilePath, (stream, origOffset, fileLength) => { vmtByteData = new byte[fileLength]; stream.Position = origOffset; stream.Read(vmtByteData, 0, vmtByteData.Length); }); vmtData = new VMTData(vmtFilePath); vmtData.Parse(vmtByteData); if (grabDependants) { vmtData.GrabDependants(bspParser, vpkParser); } } catch (System.Exception e) { Debug.LogError("VMTData: " + e.ToString()); } } else { string vtfFilePath = SourceTexture.FixLocation(bspParser, vpkParser, rawPath); if ((bspParser != null && bspParser.HasPakFile(vtfFilePath)) || (vpkParser != null && vpkParser.FileExists(vtfFilePath))) { vmtData = new VMTData(vmtFilePath); vmtData.baseTexturePath = rawPath; if (grabDependants) { vmtData.GrabDependants(bspParser, vpkParser); } } else { Debug.LogError("VMTData: Could not find VMT file at FixedPath(" + vmtFilePath + ") RawPath(" + rawPath + ")"); } } } } else { Debug.LogError("VMTData: Given path is null or empty"); } return(vmtData); }