From a080bd2dacd6464e348f1918020147a48d7880ee Mon Sep 17 00:00:00 2001 From: MaikyM <51415805+MaikyM@users.noreply.github.com> Date: Thu, 4 Jul 2019 20:10:28 -0600 Subject: [PATCH] Fixed the Featured image when loading a ONE Pak & code optimization. --- FModel/Methods/IconGenerator/ItemIcon.cs | 83 +++++++++++------------- FModel/Methods/JohnWick/JohnWick.cs | 33 ++++------ 2 files changed, 51 insertions(+), 65 deletions(-) diff --git a/FModel/Methods/IconGenerator/ItemIcon.cs b/FModel/Methods/IconGenerator/ItemIcon.cs index 67f4b507..94362a4e 100644 --- a/FModel/Methods/IconGenerator/ItemIcon.cs +++ b/FModel/Methods/IconGenerator/ItemIcon.cs @@ -28,7 +28,7 @@ namespace FModel Checking.WasFeatured = false; SearchAthIteDefIcon(theItem); } - if (featured) + else { if (theItem.DisplayAssetPath != null && theItem.DisplayAssetPath.AssetPathName.Contains("/Game/Catalog/DisplayAssets/")) { @@ -209,63 +209,54 @@ namespace FModel /// private static void GetFeaturedItemIcon(ItemsIdParser theItem, string catName) { - if (ThePak.AllpaksDictionary.ContainsKey(catName)) + ThePak.CurrentUsedItem = catName; + string catalogFilePath = (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0") + ? catalogFilePath = JohnWick.ExtractAsset(ThePak.CurrentUsedPak, catName) + : catalogFilePath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary[catName], catName); + + if (catalogFilePath != null) { - ThePak.CurrentUsedItem = catName; - - string catalogFilePath; - if (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0") + Checking.WasFeatured = true; + if (catalogFilePath.Contains(".uasset") || catalogFilePath.Contains(".uexp") || catalogFilePath.Contains(".ubulk")) { - catalogFilePath = JohnWick.ExtractAsset(ThePak.CurrentUsedPak, catName); - } - else - { - catalogFilePath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary[catName], catName); - } - - if (catalogFilePath != null) - { - Checking.WasFeatured = true; - if (catalogFilePath.Contains(".uasset") || catalogFilePath.Contains(".uexp") || catalogFilePath.Contains(".ubulk")) + JohnWick.MyAsset = new PakAsset(catalogFilePath.Substring(0, catalogFilePath.LastIndexOf('.'))); + try { - JohnWick.MyAsset = new PakAsset(catalogFilePath.Substring(0, catalogFilePath.LastIndexOf('.'))); - try + if (JohnWick.MyAsset.GetSerialized() != null) { - if (JohnWick.MyAsset.GetSerialized() != null) + string parsedJson = JToken.Parse(JohnWick.MyAsset.GetSerialized()).ToString(); + var featuredId = FeaturedParser.FromJson(parsedJson); + for (int i = 0; i < featuredId.Length; i++) { - string parsedJson = JToken.Parse(JohnWick.MyAsset.GetSerialized()).ToString(); - var featuredId = FeaturedParser.FromJson(parsedJson); - for (int i = 0; i < featuredId.Length; i++) + switch (catName) { - switch (catName) - { - case "DA_Featured_Glider_ID_070_DarkViking": - case "DA_Featured_CID_319_Athena_Commando_F_Nautilus": - if (featuredId[i].TileImage != null) - { - string textureFile = featuredId[i].TileImage.ResourceObject; - ItemIconPath = JohnWick.AssetToTexture2D(textureFile); - } - break; - default: - if (featuredId[i].DetailsImage != null) - { - string textureFile = featuredId[i].DetailsImage.ResourceObject; - ItemIconPath = JohnWick.AssetToTexture2D(textureFile); - } - break; - } + case "DA_Featured_Glider_ID_070_DarkViking": + case "DA_Featured_CID_319_Athena_Commando_F_Nautilus": + if (featuredId[i].TileImage != null) + { + string textureFile = featuredId[i].TileImage.ResourceObject; + ItemIconPath = JohnWick.AssetToTexture2D(textureFile); + } + break; + default: + if (featuredId[i].DetailsImage != null) + { + string textureFile = featuredId[i].DetailsImage.ResourceObject; + ItemIconPath = JohnWick.AssetToTexture2D(textureFile); + } + break; } } } - catch (JsonSerializationException) - { - //do not crash when JsonSerialization does weird stuff - } + } + catch (JsonSerializationException) + { + //do not crash when JsonSerialization does weird stuff } } } - else { GetItemIcon(theItem); } + else + GetItemIcon(theItem); } /// diff --git a/FModel/Methods/JohnWick/JohnWick.cs b/FModel/Methods/JohnWick/JohnWick.cs index d38e0ed5..d106f602 100644 --- a/FModel/Methods/JohnWick/JohnWick.cs +++ b/FModel/Methods/JohnWick/JohnWick.cs @@ -1,4 +1,4 @@ -using csharp_wick; +using csharp_wick; using FModel.Parser.RenderMat; using FModel.Properties; using Newtonsoft.Json; @@ -109,28 +109,23 @@ namespace FModel /// the path to the png image 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 textureFilePath = (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0") + ? ExtractAsset(ThePak.CurrentUsedPak, AssetName) + : 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"))) + if (!string.IsNullOrEmpty(textureFilePath)) { - 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"; + 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; }