From cd7835032cb2b8b98ceed0dfcd14bf48cea293f1 Mon Sep 17 00:00:00 2001 From: Asval Date: Tue, 18 Jun 2019 23:04:24 +0200 Subject: [PATCH 1/2] added check if pak is locked fixed dynamic keys not being deleted fixed crash with loading paks and locres reverted searching for a featured icon --- FModel/Forms/AESManager.cs | 4 ++ FModel/Forms/Settings.cs | 7 +-- FModel/MainWindow.cs | 44 +++++++++++-------- FModel/Methods/IconGenerator/ItemIcon.cs | 14 +++--- .../IconGenerator/Translations/LoadLocRes.cs | 16 ++++--- FModel/Methods/Utilities/Utilities.cs | 30 +++++++++++++ 6 files changed, 78 insertions(+), 37 deletions(-) diff --git a/FModel/Forms/AESManager.cs b/FModel/Forms/AESManager.cs index ed0c2559..0d8a36ce 100644 --- a/FModel/Forms/AESManager.cs +++ b/FModel/Forms/AESManager.cs @@ -72,6 +72,10 @@ namespace FModel.Forms { DynamicKeysManager.serialize(txtBox.Text.Substring(2).ToUpper(), dCurrentUsedPak); } + else + { + DynamicKeysManager.serialize("", dCurrentUsedPak); + } } } } diff --git a/FModel/Forms/Settings.cs b/FModel/Forms/Settings.cs index 29e88b0c..738889ea 100644 --- a/FModel/Forms/Settings.cs +++ b/FModel/Forms/Settings.cs @@ -115,14 +115,11 @@ namespace FModel.Forms if (checkBox8.Checked == false) Properties.Settings.Default.loadFeaturedImage = false; + //LOCRES Properties.Settings.Default.IconLanguage = comboBox1.SelectedItem.ToString(); + LoadLocRes.LoadMySelectedLocRes(Properties.Settings.Default.IconLanguage); Properties.Settings.Default.Save(); //SAVE - - if (ThePak.AllpaksDictionary != null) - { - LoadLocRes.LoadMySelectedLocRes(Properties.Settings.Default.IconLanguage); - } Close(); } diff --git a/FModel/MainWindow.cs b/FModel/MainWindow.cs index 8d6f051b..ef4e80bc 100644 --- a/FModel/MainWindow.cs +++ b/FModel/MainWindow.cs @@ -91,11 +91,11 @@ namespace FModel /// /// /// - private void AddPaKs(IEnumerable thePaks, int index) + private void AddPaKs(string thePak) { Invoke(new Action(() => { - loadOneToolStripMenuItem.DropDownItems.Add(Path.GetFileName(thePaks.ElementAt(index))); + loadOneToolStripMenuItem.DropDownItems.Add(thePak); })); } @@ -118,19 +118,23 @@ namespace FModel IEnumerable yourPaKs = Directory.GetFiles(Settings.Default.PAKsPath).Where(x => x.EndsWith(".pak")); for (int i = 0; i < yourPaKs.Count(); i++) { - AddPaKs(yourPaKs, i); //add to toolstrip - string arCurrentUsedPak = yourPaKs.ElementAt(i); //SET CURRENT PAK - string arCurrentUsedPakGuid = ThePak.ReadPakGuid(Settings.Default.PAKsPath + "\\" + Path.GetFileName(arCurrentUsedPak)); //SET CURRENT PAK GUID + if (!Utilities.IsFileLocked(new System.IO.FileInfo(arCurrentUsedPak))) + { + string arCurrentUsedPakGuid = ThePak.ReadPakGuid(Settings.Default.PAKsPath + "\\" + Path.GetFileName(arCurrentUsedPak)); //SET CURRENT PAK GUID - if (arCurrentUsedPakGuid == "0-0-0-0") - { - ThePak.mainPaksList.Add(new PaksEntry(Path.GetFileName(arCurrentUsedPak), arCurrentUsedPakGuid)); - } - if (arCurrentUsedPakGuid != "0-0-0-0") - { - ThePak.dynamicPaksList.Add(new PaksEntry(Path.GetFileName(arCurrentUsedPak), arCurrentUsedPakGuid)); + if (arCurrentUsedPakGuid == "0-0-0-0") + { + ThePak.mainPaksList.Add(new PaksEntry(Path.GetFileName(arCurrentUsedPak), arCurrentUsedPakGuid)); + AddPaKs(Path.GetFileName(arCurrentUsedPak)); //add to toolstrip + } + if (arCurrentUsedPakGuid != "0-0-0-0") + { + ThePak.dynamicPaksList.Add(new PaksEntry(Path.GetFileName(arCurrentUsedPak), arCurrentUsedPakGuid)); + AddPaKs(Path.GetFileName(arCurrentUsedPak)); //add to toolstrip + } } + else { AppendText(Path.GetFileName(arCurrentUsedPak) + " is locked by another process.", Color.Red, true); } } } } @@ -273,6 +277,9 @@ namespace FModel private void RegisterPaKsinDict(ToolStripItemClickedEventArgs theSinglePak = null, bool loadAllPaKs = false) { StringBuilder sb = new StringBuilder(); + ThePak.CurrentUsedPak = null; + ThePak.CurrentUsedPakGuid = null; + bool bMainKeyWorking = false; for (int i = 0; i < ThePak.mainPaksList.Count; i++) { @@ -292,6 +299,8 @@ namespace FModel string[] CurrentUsedPakLines = JohnWick.MyExtractor.GetFileList().ToArray(); if (CurrentUsedPakLines != null) { + bMainKeyWorking = true; + JohnWick.MyKey = Settings.Default.AESKey; string mountPoint = JohnWick.MyExtractor.GetMountPoint(); ThePak.PaksMountPoint.Add(ThePak.mainPaksList[i].thePak, mountPoint.Substring(9)); @@ -326,6 +335,8 @@ namespace FModel if (theSinglePak != null && ThePak.mainPaksList[i].thePak == theSinglePak.ClickedItem.Text) { PakAsTxt = CurrentUsedPakLines; } } } + if (bMainKeyWorking) { LoadLocRes.LoadMySelectedLocRes(Settings.Default.IconLanguage); } + if (theSinglePak != null) //IMPORTANT: IT STILLS LOAD THE DICTIONARY -> IT'S GONNA BE USEFUL FOR TRANSLATIONS { ThePak.CurrentUsedPak = theSinglePak.ClickedItem.Text; @@ -337,7 +348,7 @@ namespace FModel { foreach (AESEntry s in DynamicKeysManager.AESEntries) { - if (s.thePak == ThePak.CurrentUsedPak) + if (s.thePak == ThePak.CurrentUsedPak && s.theKey.Length > 2) { try { @@ -358,7 +369,7 @@ namespace FModel } catch (Exception) { - //do not crash + return; } } } @@ -368,11 +379,8 @@ namespace FModel if (loadAllPaKs) { File.WriteAllText(App.DefaultOutputPath + "\\FortnitePAKs.txt", sb.ToString()); //File will always exist - - ThePak.CurrentUsedPak = null; - ThePak.CurrentUsedPakGuid = null; } - LoadLocRes.LoadMySelectedLocRes(Settings.Default.IconLanguage); + UpdateConsole("Building tree, please wait...", Color.FromArgb(255, 244, 132, 66), "Loading"); } private void TreeParsePath(TreeNodeCollection nodeList, string path) //https://social.msdn.microsoft.com/Forums/en-US/c75c1804-6933-40ba-b17a-0e36ae8bcbb5/how-to-create-a-tree-view-with-full-paths?forum=csharplanguage diff --git a/FModel/Methods/IconGenerator/ItemIcon.cs b/FModel/Methods/IconGenerator/ItemIcon.cs index 41b23be5..1999fab0 100644 --- a/FModel/Methods/IconGenerator/ItemIcon.cs +++ b/FModel/Methods/IconGenerator/ItemIcon.cs @@ -209,11 +209,11 @@ namespace FModel /// private static void GetFeaturedItemIcon(ItemsIdParser theItem, string catName) { - ThePak.CurrentUsedItem = catName; - - string catalogFilePath; - try + if (ThePak.AllpaksDictionary.ContainsKey(catName)) { + ThePak.CurrentUsedItem = catName; + + string catalogFilePath; if (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0") { catalogFilePath = JohnWick.ExtractAsset(ThePak.CurrentUsedPak, catName); @@ -263,13 +263,9 @@ namespace FModel //do not crash when JsonSerialization does weird stuff } } - else { GetItemIcon(theItem); } //Trails_ID_059_Sony2 smh :thinking: } } - catch (KeyNotFoundException) - { - GetItemIcon(theItem); - } + else { GetItemIcon(theItem); } } /// diff --git a/FModel/Methods/IconGenerator/Translations/LoadLocRes.cs b/FModel/Methods/IconGenerator/Translations/LoadLocRes.cs index 00a500fc..ebdd5dc9 100644 --- a/FModel/Methods/IconGenerator/Translations/LoadLocRes.cs +++ b/FModel/Methods/IconGenerator/Translations/LoadLocRes.cs @@ -1,3 +1,5 @@ +using System; + namespace FModel { static class LoadLocRes @@ -30,12 +32,16 @@ namespace FModel private static string getMyLocRes(string selectedLanguage) { - string oldKey = JohnWick.MyKey; - JohnWick.MyKey = Properties.Settings.Default.AESKey; - string locResPath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary["Game_BR.locres"], "Game_BR.locres"); - JohnWick.MyKey = oldKey; + if (ThePak.AllpaksDictionary != null) + { + string oldKey = JohnWick.MyKey; + JohnWick.MyKey = Properties.Settings.Default.AESKey; + string locResPath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary["Game_BR.locres"], "Game_BR.locres"); + JohnWick.MyKey = oldKey; - return LocResSerializer.StringFinder(locResPath.Replace("zh-Hant", selectedLanguage)); + return LocResSerializer.StringFinder(locResPath.Replace("zh-Hant", selectedLanguage)); + } + else { return ""; } } } } diff --git a/FModel/Methods/Utilities/Utilities.cs b/FModel/Methods/Utilities/Utilities.cs index a1a9b1df..8be8a017 100644 --- a/FModel/Methods/Utilities/Utilities.cs +++ b/FModel/Methods/Utilities/Utilities.cs @@ -86,5 +86,35 @@ namespace FModel File.Delete(App.DefaultOutputPath + "\\john-wick-parse_custom.exe"); } } + + /// + /// this should tell me if i can read the file, to avoid crash when a pak is being written by the launcher + /// + /// + /// + public static bool IsFileLocked(FileInfo file) + { + FileStream stream = null; + try + { + stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None); + } + catch (IOException) + { + //the file is unavailable because it is: + //still being written to + //or being processed by another thread + //or does not exist (has already been processed) + return true; + } + finally + { + if (stream != null) + stream.Close(); + } + + //file is not locked + return false; + } } } From 273fab7e3918e4f398d9951dc79af02d1319e27b Mon Sep 17 00:00:00 2001 From: Asval Date: Tue, 18 Jun 2019 23:48:50 +0200 Subject: [PATCH 2/2] searching weapon stats improved by 1 second + locres fix again --- FModel/Methods/IconGenerator/DrawText.cs | 63 +++++++++++-------- .../IconGenerator/Translations/LoadLocRes.cs | 18 ++++-- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/FModel/Methods/IconGenerator/DrawText.cs b/FModel/Methods/IconGenerator/DrawText.cs index cc6d113b..2e19d009 100644 --- a/FModel/Methods/IconGenerator/DrawText.cs +++ b/FModel/Methods/IconGenerator/DrawText.cs @@ -21,6 +21,7 @@ namespace FModel private static string HeroType { get; set; } private static string DefenderType { get; set; } private static string MinToMax { get; set; } + private static JObject jo { get; set; } public static void DrawTexts(ItemsIdParser theItem, Graphics myGraphic, string mode) { @@ -69,6 +70,10 @@ namespace FModel DrawCosmeticUff(theItem, myGraphic); } + /// + /// find a better way to handle errors + /// + /// private static void SetTexts(ItemsIdParser theItem) { CosmeticSource = ""; @@ -330,41 +335,49 @@ namespace FModel /// private static void DrawWeaponStat(string weaponName, Graphics myGraphic) { - ItemIcon.ItemIconPath = string.Empty; - string extractedWeaponsStatPath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary["AthenaRangedWeapons"], "AthenaRangedWeapons"); - if (extractedWeaponsStatPath != null) + if (jo == null) { - if (extractedWeaponsStatPath.Contains(".uasset") || extractedWeaponsStatPath.Contains(".uexp") || extractedWeaponsStatPath.Contains(".ubulk")) + ItemIcon.ItemIconPath = string.Empty; + string extractedWeaponsStatPath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary["AthenaRangedWeapons"], "AthenaRangedWeapons"); + if (extractedWeaponsStatPath != null) { - JohnWick.MyAsset = new PakAsset(extractedWeaponsStatPath.Substring(0, extractedWeaponsStatPath.LastIndexOf('.'))); - try + if (extractedWeaponsStatPath.Contains(".uasset") || extractedWeaponsStatPath.Contains(".uexp") || extractedWeaponsStatPath.Contains(".ubulk")) { - if (JohnWick.MyAsset.GetSerialized() != null) + JohnWick.MyAsset = new PakAsset(extractedWeaponsStatPath.Substring(0, extractedWeaponsStatPath.LastIndexOf('.'))); + try { - string parsedJson = JToken.Parse(JohnWick.MyAsset.GetSerialized()).ToString().TrimStart('[').TrimEnd(']'); - JObject jo = JObject.Parse(parsedJson); - foreach (JToken token in jo.FindTokens(weaponName)) + if (JohnWick.MyAsset.GetSerialized() != null) { - var statParsed = Parser.Weapons.WeaponStatParser.FromJson(token.ToString()); - - Image bulletImage = Resources.dmg64; - myGraphic.DrawImage(ImageUtilities.ResizeImage(bulletImage, 15, 15), new Point(5, 500)); - - Image clipSizeImage = Resources.clipSize64; - myGraphic.DrawImage(ImageUtilities.ResizeImage(clipSizeImage, 15, 15), new Point(52, 500)); - - DrawToRight("Reload Time: " + statParsed.ReloadTime + " seconds", myGraphic); - DrawToLeft(" " + statParsed.DmgPb, myGraphic); //damage per bullet - myGraphic.DrawString(" " + statParsed.ClipSize, new Font(FontUtilities.pfc.Families[0], 13), new SolidBrush(Color.White), new Point(50, 500)); + string parsedJson = JToken.Parse(JohnWick.MyAsset.GetSerialized()).ToString().TrimStart('[').TrimEnd(']'); + jo = JObject.Parse(parsedJson); + loopingLol(weaponName, myGraphic); } } - } - catch (JsonSerializationException) - { - //do not crash when JsonSerialization does weird stuff + catch (JsonSerializationException) + { + //do not crash when JsonSerialization does weird stuff + } } } } + else { loopingLol(weaponName, myGraphic); } + } + private static void loopingLol(string weaponName, Graphics myGraphic) + { + foreach (JToken token in jo.FindTokens(weaponName)) + { + var statParsed = Parser.Weapons.WeaponStatParser.FromJson(token.ToString()); + + Image bulletImage = Resources.dmg64; + myGraphic.DrawImage(ImageUtilities.ResizeImage(bulletImage, 15, 15), new Point(5, 500)); + + Image clipSizeImage = Resources.clipSize64; + myGraphic.DrawImage(ImageUtilities.ResizeImage(clipSizeImage, 15, 15), new Point(52, 500)); + + DrawToRight("Reload Time: " + statParsed.ReloadTime + " seconds", myGraphic); + DrawToLeft(" " + statParsed.DmgPb, myGraphic); //damage per bullet + myGraphic.DrawString(" " + statParsed.ClipSize, new Font(FontUtilities.pfc.Families[0], 13), new SolidBrush(Color.White), new Point(50, 500)); + } } /// diff --git a/FModel/Methods/IconGenerator/Translations/LoadLocRes.cs b/FModel/Methods/IconGenerator/Translations/LoadLocRes.cs index ebdd5dc9..12f0bad5 100644 --- a/FModel/Methods/IconGenerator/Translations/LoadLocRes.cs +++ b/FModel/Methods/IconGenerator/Translations/LoadLocRes.cs @@ -30,14 +30,24 @@ namespace FModel } } + /// + /// 1. if loading a dynamic pak we have to switch between keys because the translation file is the main paks hence string oldKey is there + /// 2. smh if loading a dynamic pak, the guid isn't reset when registering, the temp solution is to fake the guid + /// + /// + /// private static string getMyLocRes(string selectedLanguage) { - if (ThePak.AllpaksDictionary != null) + if (ThePak.AllpaksDictionary != null && ThePak.AllpaksDictionary["Game_BR.locres"] != null) { - string oldKey = JohnWick.MyKey; - JohnWick.MyKey = Properties.Settings.Default.AESKey; + string oldKey = JohnWick.MyKey; //get the old key + + JohnWick.MyKey = Properties.Settings.Default.AESKey; //set the main key to extract + ThePak.CurrentUsedPakGuid = "0-0-0-0"; //fake the guid -> writeFile need this guid to get the mountPoint, otherwise it crashes + string locResPath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary["Game_BR.locres"], "Game_BR.locres"); - JohnWick.MyKey = oldKey; + + JohnWick.MyKey = oldKey; //set the old key return LocResSerializer.StringFinder(locResPath.Replace("zh-Hant", selectedLanguage)); }