Merge branch 'master' of https://github.com/iAmAsval/FModel into simplify_rewards

This commit is contained in:
MaikyM
2019-06-18 16:39:55 -06:00
7 changed files with 126 additions and 62 deletions

View File

@@ -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);
}
/// <summary>
/// find a better way to handle errors
/// </summary>
/// <param name="theItem"></param>
private static void SetTexts(ItemsIdParser theItem)
{
CosmeticSource = "";
@@ -330,41 +335,49 @@ namespace FModel
/// <param name="myGraphic"></param>
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));
}
}
/// <summary>

View File

@@ -209,11 +209,11 @@ namespace FModel
/// <param name="catName"></param>
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); }
}
/// <summary>

View File

@@ -1,3 +1,5 @@
using System;
namespace FModel
{
static class LoadLocRes
@@ -28,14 +30,28 @@ namespace FModel
}
}
/// <summary>
/// 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
/// </summary>
/// <param name="selectedLanguage"></param>
/// <returns></returns>
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 && ThePak.AllpaksDictionary["Game_BR.locres"] != null)
{
string oldKey = JohnWick.MyKey; //get the old key
return LocResSerializer.StringFinder(locResPath.Replace("zh-Hant", selectedLanguage));
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; //set the old key
return LocResSerializer.StringFinder(locResPath.Replace("zh-Hant", selectedLanguage));
}
else { return ""; }
}
}
}

View File

@@ -86,5 +86,35 @@ namespace FModel
File.Delete(App.DefaultOutputPath + "\\john-wick-parse_custom.exe");
}
}
/// <summary>
/// this should tell me if i can read the file, to avoid crash when a pak is being written by the launcher
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
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;
}
}
}