/// <summary> /// just convert the asset to a png image with some exceptions in case AssetName is a material /// </summary> /// <param name="AssetName"></param> /// <returns> the path to the png image </returns> public static string AssetToTexture2D(string AssetName) { if (!ThePak.AllpaksDictionary.ContainsKey(AssetName)) { return(string.Empty); } string textureFilePath = ExtractAsset(ThePak.AllpaksDictionary[AssetName], AssetName); string TexturePath = string.Empty; if (!string.IsNullOrEmpty(textureFilePath)) { if (textureFilePath.Contains("MI_UI_FeaturedRenderSwitch_") || textureFilePath.Contains("M_UI_ChallengeTile_PCB") || textureFilePath.Contains("Wraps\\FeaturedMaterials\\") || textureFilePath.Contains("M-Wraps-StreetDemon")) { return(GetRenderSwitchMaterialTexture(textureFilePath)); } else { MyAsset = new PakAsset(textureFilePath.Substring(0, textureFilePath.LastIndexOf(".", StringComparison.Ordinal))); MyAsset.SaveTexture(textureFilePath.Substring(0, textureFilePath.LastIndexOf(".", StringComparison.Ordinal)) + ".png"); TexturePath = textureFilePath.Substring(0, textureFilePath.LastIndexOf(".", StringComparison.Ordinal)) + ".png"; } } return(TexturePath); }
/// <summary> /// serialize the material to get the texture and convert this texture to a png image /// </summary> /// <param name="AssetPath"></param> /// <returns> the path to the png image </returns> public static string GetRenderSwitchMaterialTexture(string AssetPath) { string TexturePath = string.Empty; if (AssetPath.Contains(".uasset") || AssetPath.Contains(".uexp") || AssetPath.Contains(".ubulk")) { MyAsset = new PakAsset(AssetPath.Substring(0, AssetPath.LastIndexOf('.'))); try { if (MyAsset.GetSerialized() != null) { string parsedRsmJson = JToken.Parse(MyAsset.GetSerialized()).ToString(); var rsmid = RenderSwitchMaterial.FromJson(parsedRsmJson); for (int i = 0; i < rsmid.Length; i++) { if (rsmid[i].TextureParameterValues.FirstOrDefault()?.ParameterValue != null) { string textureFile = rsmid[i].TextureParameterValues.FirstOrDefault()?.ParameterValue; TexturePath = AssetToTexture2D(textureFile); } } } } catch (JsonSerializationException) { //do not crash when JsonSerialization does weird stuff } } return(TexturePath); }
/// <summary> /// just convert the asset to a png image with some exceptions in case AssetName is a material /// </summary> /// <param name="AssetName"></param> /// <returns> the path to the png image </returns> public static string AssetToTexture2D(string AssetName) { string textureFilePath; if (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0") { textureFilePath = ExtractAsset(ThePak.CurrentUsedPak, AssetName); } else { textureFilePath = ExtractAsset(ThePak.AllpaksDictionary[AssetName], AssetName); } string TexturePath = string.Empty; if (textureFilePath != null && (textureFilePath.Contains("MI_UI_FeaturedRenderSwitch_") || textureFilePath.Contains("M_UI_ChallengeTile_PCB") || textureFilePath.Contains("Wraps\\FeaturedMaterials\\") || textureFilePath.Contains("M-Wraps-StreetDemon"))) { return(GetRenderSwitchMaterialTexture(textureFilePath)); } else if (textureFilePath != null) { MyAsset = new PakAsset(textureFilePath.Substring(0, textureFilePath.LastIndexOf(".", StringComparison.Ordinal))); MyAsset.SaveTexture(textureFilePath.Substring(0, textureFilePath.LastIndexOf(".", StringComparison.Ordinal)) + ".png"); TexturePath = textureFilePath.Substring(0, textureFilePath.LastIndexOf(".", StringComparison.Ordinal)) + ".png"; } return(TexturePath); }
/// <summary> /// serialize the material to get the texture and convert this texture to a png image /// </summary> /// <param name="AssetPath"></param> /// <returns> the path to the png image </returns> public static string GetRenderSwitchMaterialTexture(string AssetPath) { string TexturePath = string.Empty; if (AssetPath.Contains(".uasset") || AssetPath.Contains(".uexp") || AssetPath.Contains(".ubulk")) { MyAsset = new PakAsset(AssetPath.Substring(0, AssetPath.LastIndexOf('.'))); try { if (MyAsset.GetSerialized() != null) { dynamic AssetData = JsonConvert.DeserializeObject(MyAsset.GetSerialized()); JArray AssetArray = JArray.FromObject(AssetData); JToken textureParameterValues = AssetArray[0]["TextureParameterValues"]; if (textureParameterValues != null) { JArray textureParameterValuesArray = textureParameterValues.Value <JArray>(); foreach (JToken token in textureParameterValuesArray) { JToken parameterInfo = token["ParameterInfo"]; if (parameterInfo != null) { JToken name = parameterInfo["Name"]; if (name != null && name.Value <string>().Equals("TextureB")) { JToken parameterValue = token["ParameterValue"]; if (parameterValue != null) { string textureFile = parameterValue.Value <string>(); TexturePath = AssetToTexture2D(textureFile); } } else if (name != null && name.Value <string>().Contains("Texture")) { JToken parameterValue = token["ParameterValue"]; if (parameterValue != null) { string textureFile = parameterValue.Value <string>(); TexturePath = AssetToTexture2D(textureFile); } } } } } } } catch (JsonSerializationException) { //do not crash when JsonSerialization does weird stuff } } return(TexturePath); }