challenges refactored (fortbyte unsupported yet)

This commit is contained in:
Asval 2019-06-01 00:24:21 +02:00
parent ef39bf2fd0
commit 5017a8dbeb
7 changed files with 356 additions and 1461 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,11 @@
using FModel.Parser.Challenges;
using FModel.Parser.Items;
using FModel.Properties;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System;
namespace FModel
{
@ -71,5 +66,108 @@ namespace FModel
toDrawOn.DrawString(BundleInfos.getBundleDisplayName(myItem), new Font(FontUtilities.pfc.Families[1], 115), new SolidBrush(Color.White), new Point(325, 70));
}
}
/// <summary>
/// get and draw completion text and its reward
/// if AssetPathName is "None" we take the TemplateId (it's most likely a banner)
/// else we take AssetPathName and we ignore "AthenaBattlePass_WeeklyChallenge_Token" and "AthenaBattlePass_WeeklyBundle_Token" because these are useless
/// ignoring these 2 should give us an item id, we draw this item
/// </summary>
/// <param name="myBundle"></param>
public static void drawCompletionReward(ChallengeBundleIdParser myBundle)
{
if (myBundle.BundleCompletionRewards != null)
{
theY += 100;
for (int x = 0; x < myBundle.BundleCompletionRewards.Length; x++)
{
for (int i = 0; i < myBundle.BundleCompletionRewards[x].Rewards.Length; i++)
{
string compCount = myBundle.BundleCompletionRewards[x].CompletionCount.ToString();
string itemQuantity = myBundle.BundleCompletionRewards[x].Rewards[i].Quantity.ToString();
if (myBundle.BundleCompletionRewards[x].Rewards[i].ItemDefinition.AssetPathName == "None")
{
theY += 140;
DrawingRewards.getRewards(myBundle.BundleCompletionRewards[x].Rewards[i].TemplateId, itemQuantity);
if (compCount == "-1")
{
toDrawOn.DrawString("Complete ALL CHALLENGES to earn the reward item", new Font(FontUtilities.pfc.Families[1], 50), new SolidBrush(Color.White), new Point(100, theY + 22));
}
else
{
toDrawOn.DrawString("Complete ANY " + compCount + " CHALLENGES to earn the reward item", new Font(FontUtilities.pfc.Families[1], 50), new SolidBrush(Color.White), new Point(100, theY + 22));
}
}
else
{
string rewardId = Path.GetFileName(myBundle.BundleCompletionRewards[x].Rewards[i].ItemDefinition.AssetPathName.Substring(0, myBundle.BundleCompletionRewards[x].Rewards[i].ItemDefinition.AssetPathName.LastIndexOf(".", StringComparison.Ordinal)));
if (rewardId != "AthenaBattlePass_WeeklyChallenge_Token" && rewardId != "AthenaBattlePass_WeeklyBundle_Token")
{
theY += 140;
try //needed for rare cases where the icon is in /Content/icon.uasset and atm idk why but i can't extract
{
if (rewardId.Contains("Fortbyte_WeeklyChallengesComplete_")) { drawForbyteReward(); }
else { DrawingRewards.getRewards(rewardId, itemQuantity); }
}
catch (Exception)
{
drawUnknownReward();
}
if (compCount == "-1")
{
toDrawOn.DrawString("Complete ALL CHALLENGES to earn the reward item", new Font(FontUtilities.pfc.Families[1], 50), new SolidBrush(Color.White), new Point(100, theY + 22));
}
else
{
toDrawOn.DrawString("Complete ANY " + compCount + " CHALLENGES to earn the reward item", new Font(FontUtilities.pfc.Families[1], 50), new SolidBrush(Color.White), new Point(100, theY + 22));
}
}
}
}
}
}
}
/// <summary>
/// draw the watermark at the bottom of the bundle of challenges icon
/// </summary>
/// <param name="myBitmap"></param>
public static void drawWatermark(Bitmap myBitmap)
{
toDrawOn.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), new Rectangle(0, theY + 240, myBitmap.Width, 40));
toDrawOn.DrawString(myItem.DisplayName + " Generated using FModel & JohnWickParse - " + DateTime.Now.ToString("dd/MM/yyyy"), new Font(FontUtilities.pfc.Families[0], 20), new SolidBrush(Color.FromArgb(150, 255, 255, 255)), new Point(myBitmap.Width / 2, theY + 250), FontUtilities.centeredString);
}
private static void drawForbyteReward()
{
string textureFile = "T_UI_PuzzleIcon_64";
ItemIcon.ItemIconPath = JohnWick.AssetToTexture2D(textureFile);
if (File.Exists(ItemIcon.ItemIconPath))
{
Image itemIcon;
using (var bmpTemp = new Bitmap(ItemIcon.ItemIconPath))
{
itemIcon = new Bitmap(bmpTemp);
}
toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, theY + 6));
}
else
{
Image itemIcon = Resources.unknown512;
toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, theY + 6));
}
}
private static void drawUnknownReward()
{
Image itemIcon = Resources.unknown512;
toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, theY + 6));
}
}
}

View File

@ -39,12 +39,12 @@ namespace FModel
public static string getLastFolder(string pathToExtractedBundle)
{
string folderAndFileNameWithExtension = pathToExtractedBundle.Substring(pathToExtractedBundle.Substring(0, pathToExtractedBundle.LastIndexOf("\\", StringComparison.Ordinal)).LastIndexOf("\\", StringComparison.Ordinal) + 1).ToUpper();
return folderAndFileNameWithExtension.Substring(0, folderAndFileNameWithExtension.LastIndexOf("\\", StringComparison.Ordinal));
return folderAndFileNameWithExtension.Substring(0, folderAndFileNameWithExtension.LastIndexOf("\\", StringComparison.Ordinal)); //just the folder now
}
/// <summary>
/// main method to set the data to get it out of this class
/// extract quests one by one and add description, count, reward item, reward quantity to List<BundleInfoEntry> BundleData
/// foreach questfile to getQuestData()
/// </summary>
/// <param name="myBundle"></param>
public static void getBundleData(ChallengeBundleIdParser myBundle)
@ -53,78 +53,103 @@ namespace FModel
for (int i = 0; i < myBundle.QuestInfos.Length; i++)
{
string questName = Path.GetFileName(myBundle.QuestInfos[i].QuestDefinition.AssetPathName);
getQuestData(questName.Substring(0, questName.LastIndexOf(".")));
string questName = Path.GetFileName(myBundle.QuestInfos[i].QuestDefinition.AssetPathName).Substring(0, Path.GetFileName(myBundle.QuestInfos[i].QuestDefinition.AssetPathName).LastIndexOf(".", StringComparison.Ordinal));
getQuestData(questName);
}
}
/// <summary>
/// extract quest and add description, count, reward item, reward quantity to List<BundleInfoEntry> BundleData
/// loop if stage exist
/// </summary>
/// <param name="questFile"></param>
private static void getQuestData(string questFile)
{
string questFilePath;
if (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0")
try
{
questFilePath = JohnWick.ExtractAsset(ThePak.CurrentUsedPak, questFile);
}
else
{
questFilePath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary[questFile], questFile);
}
if (questFilePath != null)
{
if (questFilePath.Contains(".uasset") || questFilePath.Contains(".uexp") || questFilePath.Contains(".ubulk"))
string questFilePath;
if (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0")
{
JohnWick.MyAsset = new PakAsset(questFilePath.Substring(0, questFilePath.LastIndexOf('.')));
try
questFilePath = JohnWick.ExtractAsset(ThePak.CurrentUsedPak, questFile);
}
else
{
questFilePath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary[questFile], questFile);
}
if (questFilePath != null)
{
if (questFilePath.Contains(".uasset") || questFilePath.Contains(".uexp") || questFilePath.Contains(".ubulk"))
{
if (JohnWick.MyAsset.GetSerialized() != null)
JohnWick.MyAsset = new PakAsset(questFilePath.Substring(0, questFilePath.LastIndexOf('.')));
try
{
QuestParser[] questParser = QuestParser.FromJson(JToken.Parse(JohnWick.MyAsset.GetSerialized()).ToString());
for (int x = 0; x < questParser.Length; x++)
if (JohnWick.MyAsset.GetSerialized() != null)
{
string oldQuest = string.Empty;
long oldCount = 0;
for (int p = 0; p < questParser[x].Objectives.Length; p++)
QuestParser[] questParser = QuestParser.FromJson(JToken.Parse(JohnWick.MyAsset.GetSerialized()).ToString());
for (int x = 0; x < questParser.Length; x++)
{
string newQuest = questParser[x].Objectives[p].Description;
long newCount = questParser[x].Objectives[p].Count;
if (newQuest != oldQuest && newCount != oldCount)
string oldQuest = string.Empty;
long oldCount = 0;
for (int p = 0; p < questParser[x].Objectives.Length; p++)
{
if (questParser[x].Rewards != null)
{
try
{
string rewardId = questParser[x].Rewards.Where(item => item.ItemPrimaryAssetId.PrimaryAssetType.Name != "Quest").Where(item => item.ItemPrimaryAssetId.PrimaryAssetType.Name != "Token").FirstOrDefault().ItemPrimaryAssetId.PrimaryAssetName;
string rewardQuantity = questParser[x].Rewards.Where(item => item.ItemPrimaryAssetId.PrimaryAssetType.Name != "Quest").Where(item => item.ItemPrimaryAssetId.PrimaryAssetType.Name != "Token").FirstOrDefault().Quantity.ToString();
string newQuest = questParser[x].Objectives[p].Description;
long newCount = questParser[x].Objectives[p].Count;
BundleData.Add(new BundleInfoEntry(newQuest, newCount, rewardId, rewardQuantity));
}
catch (NullReferenceException)
if (newQuest != oldQuest && newCount != oldCount)
{
if (questParser[x].Rewards != null)
{
if (questParser[x].HiddenRewards != null)
try
{
string rewardId = questParser[x].HiddenRewards.FirstOrDefault().TemplateId;
string rewardQuantity = questParser[x].HiddenRewards.FirstOrDefault().Quantity.ToString();
string rewardId = questParser[x].Rewards.Where(item => item.ItemPrimaryAssetId.PrimaryAssetType.Name != "Quest").Where(item => item.ItemPrimaryAssetId.PrimaryAssetType.Name != "Token").FirstOrDefault().ItemPrimaryAssetId.PrimaryAssetName;
string rewardQuantity = questParser[x].Rewards.Where(item => item.ItemPrimaryAssetId.PrimaryAssetType.Name != "Quest").Where(item => item.ItemPrimaryAssetId.PrimaryAssetType.Name != "Token").FirstOrDefault().Quantity.ToString();
BundleData.Add(new BundleInfoEntry(newQuest, newCount, rewardId, rewardQuantity));
}
catch (NullReferenceException)
{
if (questParser[x].HiddenRewards != null)
{
string rewardId = questParser[x].HiddenRewards.FirstOrDefault().TemplateId;
string rewardQuantity = questParser[x].HiddenRewards.FirstOrDefault().Quantity.ToString();
BundleData.Add(new BundleInfoEntry(newQuest, newCount, rewardId, rewardQuantity));
}
}
//get stage
for (int k = 0; k < questParser[x].Rewards.Length; k++)
{
string qAssetType = questParser[x].Rewards[k].ItemPrimaryAssetId.PrimaryAssetType.Name;
string qAssetName = questParser[x].Rewards[k].ItemPrimaryAssetId.PrimaryAssetName;
if (qAssetType == "Quest")
{
getQuestData(qAssetName);
}
}
}
}
else
{
BundleData.Add(new BundleInfoEntry(newQuest, newCount, "", ""));
else
{
BundleData.Add(new BundleInfoEntry(newQuest, newCount, "", ""));
}
oldQuest = newQuest;
oldCount = newCount;
}
}
oldQuest = newQuest;
oldCount = newCount;
}
}
}
catch (JsonSerializationException) { }
}
catch (JsonSerializationException) { }
}
}
catch (KeyNotFoundException)
{
Console.WriteLine("Can't extract " + questFile);
}
}
}
}

View File

@ -11,70 +11,79 @@ using System.Linq;
namespace FModel
{
class DrawingRewards
static class DrawingRewards
{
/// <summary>
/// if itemToExtract is empty, no need to do this
/// if itemToExtract contains ':' ("HomebaseBannerIcon" or "AthenaLoadingScreen" or "CosmeticVariantToken"), split to get the itemId
/// </summary>
/// <param name="itemToExtract"></param>
/// <param name="itemQuantity"></param>
public static void getRewards(string itemToExtract, string itemQuantity)
{
if (itemToExtract.Contains(":"))
if (!string.IsNullOrWhiteSpace(itemToExtract))
{
var parts = itemToExtract.Split(':');
if (parts[0] == "HomebaseBannerIcon") { DrawRewardBanner(parts[1]); }
else { DrawRewardIcon(parts[1]); }
if (itemToExtract.Contains(":"))
{
var parts = itemToExtract.Split(':');
if (parts[0] == "HomebaseBannerIcon") { DrawRewardBanner(parts[1]); }
else { DrawRewardIcon(parts[1]); }
}
else if (string.Equals(itemToExtract, "athenabattlestar", StringComparison.CurrentCultureIgnoreCase)) { drawBattleStar(itemQuantity); }
else if (string.Equals(itemToExtract, "AthenaSeasonalXP", StringComparison.CurrentCultureIgnoreCase)) { drawSeasonalXp(itemQuantity); }
else if (string.Equals(itemToExtract, "MtxGiveaway", StringComparison.CurrentCultureIgnoreCase)) { drawMtxGiveaway(itemQuantity); }
else { DrawRewardIcon(itemToExtract); }
}
else if (string.Equals(itemToExtract, "athenabattlestar", StringComparison.CurrentCultureIgnoreCase)) { drawBattleStar(itemQuantity); }
else if (string.Equals(itemToExtract, "AthenaSeasonalXP", StringComparison.CurrentCultureIgnoreCase)) { drawSeasonalXp(itemQuantity); }
else if (string.Equals(itemToExtract, "MtxGiveaway", StringComparison.CurrentCultureIgnoreCase)) { drawMtxGiveaway(itemQuantity); }
else { DrawRewardIcon(itemToExtract); }
}
/// <summary>
/// JohnWick is case sensitive so that way we search the item in the dictionary with CurrentCultureIgnoreCase and if he exists, we take his name
/// so the name taken will be working for JohnWick
/// </summary>
/// <param name="item"></param>
public static void DrawRewardIcon(string item)
{
ItemIcon.ItemIconPath = string.Empty;
try
{
var value = ThePak.AllpaksDictionary.Where(x => string.Equals(x.Key, item, StringComparison.CurrentCultureIgnoreCase)).Select(d => d.Key).FirstOrDefault();
if (value != null)
{
string extractedIconPath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary[value], value);
if (extractedIconPath != null)
{
if (extractedIconPath.Contains(".uasset") || extractedIconPath.Contains(".uexp") || extractedIconPath.Contains(".ubulk"))
{
JohnWick.MyAsset = new PakAsset(extractedIconPath.Substring(0, extractedIconPath.LastIndexOf('.')));
try
{
if (JohnWick.MyAsset.GetSerialized() != null)
{
var itemId = ItemsIdParser.FromJson(JToken.Parse(JohnWick.MyAsset.GetSerialized()).ToString());
for (int i = 0; i < itemId.Length; i++)
{
ItemIcon.SearchAthIteDefIcon(itemId[i]);
var value = ThePak.AllpaksDictionary.Where(x => string.Equals(x.Key, item, StringComparison.CurrentCultureIgnoreCase)).Select(d => d.Key).FirstOrDefault();
if (File.Exists(ItemIcon.ItemIconPath))
if (value != null)
{
string extractedIconPath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary[value], value);
if (extractedIconPath != null)
{
if (extractedIconPath.Contains(".uasset") || extractedIconPath.Contains(".uexp") || extractedIconPath.Contains(".ubulk"))
{
JohnWick.MyAsset = new PakAsset(extractedIconPath.Substring(0, extractedIconPath.LastIndexOf('.')));
try
{
if (JohnWick.MyAsset.GetSerialized() != null)
{
var itemId = ItemsIdParser.FromJson(JToken.Parse(JohnWick.MyAsset.GetSerialized()).ToString());
for (int i = 0; i < itemId.Length; i++)
{
ItemIcon.SearchAthIteDefIcon(itemId[i]);
if (File.Exists(ItemIcon.ItemIconPath))
{
Image itemIcon;
using (var bmpTemp = new Bitmap(ItemIcon.ItemIconPath))
{
Image itemIcon;
using (var bmpTemp = new Bitmap(ItemIcon.ItemIconPath))
{
itemIcon = new Bitmap(bmpTemp);
}
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
else
{
Image itemIcon = Resources.unknown512;
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
itemIcon = new Bitmap(bmpTemp);
}
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
else
{
Image itemIcon = Resources.unknown512;
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
}
}
catch (JsonSerializationException) { }
}
catch (JsonSerializationException) { }
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static void DrawRewardBanner(string bannerName)
{

View File

@ -304,5 +304,30 @@ namespace FModel
}
}
}
/// <summary>
/// Draw a watermark on an Item Icon
/// Keep in mind the update mode use different settings than the normal mode, hence there's 2 if statement
/// </summary>
/// <param name="toDrawOn"></param>
public static void DrawWatermark(Graphics toDrawOn)
{
if (Checking.UmWorking == false && (Settings.Default.isWatermark && !string.IsNullOrEmpty(Settings.Default.wFilename)))
{
Image watermark = Image.FromFile(Settings.Default.wFilename);
var opacityImage = ImageUtilities.SetImageOpacity(watermark, (float)Settings.Default.wOpacity / 100);
toDrawOn.DrawImage(ImageUtilities.ResizeImage(opacityImage, Settings.Default.wSize, Settings.Default.wSize), (522 - Settings.Default.wSize) / 2, (522 - Settings.Default.wSize) / 2, Settings.Default.wSize, Settings.Default.wSize);
}
if (Checking.UmWorking && (Settings.Default.UMWatermark && !string.IsNullOrEmpty(Settings.Default.UMFilename)))
{
Image watermark = Image.FromFile(Settings.Default.UMFilename);
var opacityImage = ImageUtilities.SetImageOpacity(watermark, (float)Settings.Default.UMOpacity / 100);
toDrawOn.DrawImage(ImageUtilities.ResizeImage(opacityImage, Settings.Default.UMSize, Settings.Default.UMSize), (522 - Settings.Default.UMSize) / 2, (522 - Settings.Default.UMSize) / 2, Settings.Default.UMSize, Settings.Default.UMSize);
}
}
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
namespace FModel
@ -66,9 +67,9 @@ namespace FModel
public static bool UmWorking { get; set; }
}
public struct BundleInfoEntry
public struct BundleInfoEntry: IEquatable<BundleInfoEntry>
{
public BundleInfoEntry(string QuestDescription, long QuestCount, string RewardId, string RewardQuantity)
internal BundleInfoEntry(string QuestDescription, long QuestCount, string RewardId, string RewardQuantity)
{
questDescr = QuestDescription;
questCount = QuestCount;
@ -79,5 +80,10 @@ namespace FModel
public long questCount { get; set; }
public string rewardItemId { get; set; }
public string rewardItemQuantity { get; set; }
bool IEquatable<BundleInfoEntry>.Equals(BundleInfoEntry other)
{
throw new NotImplementedException();
}
}
}

View File

@ -83,6 +83,7 @@ This project is mainly based on what [UModel](https://github.com/gildor2/UModel)
I'd highly suggest you to use [UModel](https://github.com/gildor2/UModel) instead if you wanna use something made professionnaly.
## TODO
- [ ] 2FA support
- [ ] Code refactoring
- [ ] Get new file content
- [ ] Display support for .locres files + compare