using MySql.Data.MySqlClient; using MySqlX.XDevAPI.Relational; using Newtonsoft.Json; using PoEco.Net.DB; using PoEco.Net.Utilities; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using static PoEco.Net.JSON.Stash; using static PoEco.Net.Web.PoEPrices; namespace PoEco.Net { internal class Program { public static string version = "1.0.0"; static void Main(string[] args) { if (!args.Contains("--gui")) { Utilities.Message.Splash("PoEco.Net", "mikx"); } int a = args.Length; if (a < 1) { Utilities.Message.CMW("Usage: poeco.exe ", true, 1); Utilities.Message.CMW("--debug Skip parts of the logics for debuging.", true, 1); Utilities.Message.CMW("--lua Generate up to date classes and bases.", true, 1); Utilities.Message.CMW("--gen Generate up to date currencies value.", true, 1); Utilities.Message.CMW("--usergen-rare Generate up to date user rare tab.", true, 1); Utilities.Message.CMW("--usergen-tab Generate up to date user tabs.", true, 1); } else { if (args.Contains("--lua")) { Message.CMW("Generating the latest Classes and Bases from PoB Lua...", true, 1); Web.PoBLua.GetLatestLUA(); DB.ClassGen.GenClass(); Message.CMW("Generation done.", true, 2); } if (args.Contains("--gen")) { Message.CMW("Getting the latest PoE.Ninja Currency Data...", true, 1); if (File.Exists("data/ninja/currency.json")) { File.Delete("data/ninja/currency.json"); } Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "currencyoverview?league=" + JSON.Settings.GetLeague() + "&type=Currency&language=en", "data/ninja/currency.json"); Web.PoENinja.GenCurrency(); Message.CMW("Getting the latest PoE.Ninja Divination Data...", true, 1); if (File.Exists("data/ninja/divination.json")) { File.Delete("data/ninja/divination.json"); } Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "itemoverview?league=" + JSON.Settings.GetLeague() + "&type=DivinationCard&language=en", "data/ninja/divination.json"); Web.PoENinja.GenDivination(); Message.CMW("Getting the latest PoE.Ninja Essence Data...", true, 1); if (File.Exists("data/ninja/essence.json")) { File.Delete("data/ninja/essence.json"); } Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "itemoverview?league=" + JSON.Settings.GetLeague() + "&type=Essence&language=en", "data/ninja/essence.json"); Web.PoENinja.GenEssence(); Message.CMW("Getting the latest PoE.Ninja Scarab Data...", true, 1); if (File.Exists("data/ninja/scarab.json")) { File.Delete("data/ninja/scarab.json"); } Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "itemoverview?league=" + JSON.Settings.GetLeague() + "&type=Scarab&language=en", "data/ninja/scarab.json"); Web.PoENinja.GenFragment(); Message.CMW("Getting the latest PoE.Ninja Fossil Data...", true, 1); if (File.Exists("data/ninja/fossil.json")) { File.Delete("data/ninja/fossil.json"); } Web.PoENinja.SaveData("https://poe.ninja/api/data/" + "itemoverview?league=" + JSON.Settings.GetLeague() + "&type=Fossil&language=en", "data/ninja/fossil.json"); Web.PoENinja.GenFossil(); return; } if (args.Contains("--usergen-rare")) { if (args.Length > 1) { int uid = Convert.ToInt16(args[1]); string user = DB.User.GetUserNameByID(uid)[0]; string discriminator = DB.User.GetUserNameByID(uid)[1]; Message.CMW($"User \"{user}\" processing...", true, 1); Message.CMW($"Checking the database for user \"{user}\"...", true, 1); if (DB.User.CheckUserExists(user, discriminator)) { Message.CMW($"User \"{user}\" exists with ID \"{uid}\".", true, 2); foreach (var png in Directory.GetFiles("data/tabmap")) { File.Delete(png); } File.Copy(@"data/StashTab_Quad.png", $@"data/tabmap/{user}#{discriminator}.png"); if (args.Contains("--clean")) { DB.Item.DeleteAllItemsByUID(uid); } int uct = DB.User.CountTabByUID(uid); foreach (int ti in DB.Stash.EnumerateTabByUID(uid, "rare")) { Message.CMW($"Processing tab \"{ti}\" from user \"{user}\".", true, 2); string token = DB.User.GetUserTokenByID(uid); if (!args.Contains("--debug")) { Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={ti}&accountName={user}%23{discriminator}", $"data/stash/{user}.rare.{ti}.json"); } StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($@"data/stash/{user}.rare.{ti}.json")); int stashitemcount = JSON.Stash.GetUserItemCount(user, ti); int stashitemleft = stashitemcount; List stringItemTxt = new List(); List stringItemMod = new List(); List Rows = new List(); StringBuilder sCommand = new StringBuilder("INSERT INTO poeco_items(uid, tabindex, tabname, tabrgb, cid, bid, uiid, imod, var, img, txt, b64, ctype, min, max) VALUES "); double chaosValue = 0; while (stashitemleft > 0) { int idel = 0; foreach (string i in DB.Item.EnumerateItemByUID(uid, ti)) { if (!JSON.Stash.CheckItemExistsStash(user, ti, i)) { DB.Item.DeleteItemByUIID(uid, ti, i); idel++; } } if (idel > 0) { Message.CMW($"Cleaned Item(s) Database. Deleted {idel} Item(s).", true, 2); } idel = 0; foreach (var i in stash.items) { if (!DB.Item.CheckItemExistsByUIID(i.id)) { if (i.frameType == 2) { Message.CMW($"[{stashitemleft}][{i.id.Substring(0,5)}] Processing {i.name} {i.typeLine}.", true, 2); int icid = DB.Stash.GetClassIDByBase(i.typeLine); string itemclass = DB.Stash.GetClassByID(icid); stringItemTxt.Add($"Item Class: {char.ToUpper(itemclass[0]) + itemclass.Substring(1)}"); stringItemTxt.Add("Rarity: Rare"); stringItemTxt.Add(i.name ?? ""); stringItemTxt.Add(i.typeLine ?? ""); stringItemTxt.Add("--------"); if (i.properties != null && i.properties.Count() > 0) { foreach (Property property in i.properties) { if (property.name == "Quality") stringItemTxt.Add(string.Format("Quality: {0}", property.values[0][0])); if (property.name == "Armour") stringItemTxt.Add(string.Format("Armour: {0}", property.values[0][0])); if (property.name == "Energy Shield") stringItemTxt.Add(string.Format("Energy Shield: {0}", property.values[0][0])); if (property.name == "Evasion Rating") stringItemTxt.Add(string.Format("Evasion Rating: {0}", property.values[0][0])); if (property.values.Count>() == 0) stringItemTxt.Add(property.name ?? ""); if (property.name == "Physical Damage") stringItemTxt.Add(string.Format("Physical Damage: {0}", property.values[0][0])); if (property.name == "Elemental Damage") stringItemTxt.Add(string.Format("Elemental Damage: {0}", property.values[0][0])); if (property.name == "Critical Strike Chance") stringItemTxt.Add(string.Format("Critical Strike Chance: {0}", property.values[0][0])); if (property.name == "Attacks per Second") stringItemTxt.Add(string.Format("Attacks per Second: {0}", property.values[0][0])); if (property.name == "Weapon Range") stringItemTxt.Add(string.Format("Weapon Range: {0}", property.values[0][0])); } stringItemTxt.Add("--------"); } stringItemTxt.Add("Requirements:"); if (i.requirements != null) { foreach (Requirement requirement in i.requirements) { if (requirement.name == "Level") stringItemTxt.Add(string.Format("Level: {0}", requirement.values[0][0])); if (requirement.name == "Str") stringItemTxt.Add(string.Format("Str: {0}", requirement.values[0][0])); if (requirement.name == "Dex") stringItemTxt.Add(string.Format("Dex: {0}", requirement.values[0][0])); if (requirement.name == "Int") stringItemTxt.Add(string.Format("Int: {0}", requirement.values[0][0])); } } stringItemTxt.Add("--------"); if (i.sockets != null) { List stringList2 = new List(); List stringList3 = new List(); List stringList4 = new List(); List stringList5 = new List(); List stringList6 = new List(); List stringList7 = new List(); foreach (Socket socket in i.sockets) { if (socket.group == 0) stringList2.Add(socket.sColour.ToString()); if (socket.group == 1) stringList3.Add(socket.sColour.ToString()); if (socket.group == 2) stringList4.Add(socket.sColour.ToString()); if (socket.group == 3) stringList5.Add(socket.sColour.ToString()); if (socket.group == 4) stringList6.Add(socket.sColour.ToString()); if (socket.group == 5) stringList7.Add(socket.sColour.ToString()); } string str1 = string.Join("-", (IEnumerable)stringList2); string str2 = string.Join("-", (IEnumerable)stringList3); string str3 = string.Join("-", (IEnumerable)stringList4); string str4 = string.Join("-", (IEnumerable)stringList5); string str5 = string.Join("-", (IEnumerable)stringList6); string str6 = string.Join("-", (IEnumerable)stringList7); stringItemTxt.Add("Sockets: " + str1 + " " + str2 + " " + str3 + " " + str4 + " " + str5 + " " + str6); } stringItemTxt.Add("--------"); stringItemTxt.Add(string.Format("Item Level: {0}", (object)i.ilvl)); stringItemTxt.Add("--------"); if (i.implicitMods != null) { foreach (string implicitMod in i.implicitMods) { stringItemTxt.Add(implicitMod ?? ""); stringItemMod.Add(implicitMod + "/n"); } stringItemTxt.Add("--------"); stringItemMod.Add("--------/n"); } if (i.explicitMods != null) { foreach (string explicitMod in i.explicitMods) { stringItemTxt.Add(explicitMod ?? ""); stringItemMod.Add(explicitMod + "/n"); } } File.WriteAllLines("tmp/" + i.id + ".txt", (IEnumerable)stringItemTxt); File.WriteAllLines("tmp/" + i.id + ".mod.txt", (IEnumerable)stringItemMod); string ib64 = Convert.ToBase64String(File.ReadAllBytes("tmp/" + i.id + ".txt")); if (!args.Contains("--debug")) { Web.PoEPrices.GetItemJson(i.id, ib64); } if (File.Exists($"tmp/" + i.id + ".json")) { string type = ""; int tabindex = DB.User.GetUserTabIndex(user); double min = Web.PoEPrices.GetMin(i.id); double max = Web.PoEPrices.GetMax(i.id); type = "c"; if (JsonConvert.DeserializeObject(File.ReadAllText("tmp/" + i.id + ".json")).currency == "divine") { //min = min * JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString("Divine Orb"), "poeco_currency"); //max = max * JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString("Divine Orb"), "poeco_currency"); type = "d"; } Draw.GenQuad(i.w, i.h, i.x, i.y, i.icon, Math.Round(min, 1), Math.Round(max, 1), type, user, discriminator); DB.Stash.AddItemTable(uid, ti, i.id, i.ilvl, icid, DB.Stash.GetBaseIDByName(i.typeLine), i.name, MySqlHelper.EscapeString(File.ReadAllText("tmp/" + i.id + ".mod.txt")), i.icon, MySqlHelper.EscapeString(File.ReadAllText("tmp/" + i.id + ".txt")), ib64, min, max); chaosValue = chaosValue + max; stringItemTxt.Clear(); stringItemMod.Clear(); stashitemleft--; } } else { Message.CMW($"[{i.id}] Skipping {i.name} {i.typeLine}.", true, 3); stashitemleft--; } stringItemTxt.Clear(); stringItemMod.Clear(); } else { stashitemleft--; } } int uic = DB.Item.CountItemByUID(uid, ti); DB.User.SetUserItemCount(uid, uic, ti); chaosValue = chaosValue + DB.User.GetTabValueByTID(uid, ti); DB.User.SetUserTabValue(uid, ti, chaosValue); DB.Stash.SetTabNameByTID(uid,ti, stash.tabs[ti].n); DB.Stash.SetTabRGBByTID(uid, ti, $"{stash.tabs[ti].colour.r}:{stash.tabs[ti].colour.g}:{stash.tabs[ti].colour.b}"); } Message.CMW($"Processed all item(s) in the rare tab.", true, 2); } } } } if (args.Contains("--usergen-pro")) { int uid = Convert.ToInt16(args[1]); string user = DB.User.GetUserNameByID(uid)[0]; string discriminator = DB.User.GetUserNameByID(uid)[1]; int proindex = DB.User.GetUserProfitTabIndex(uid); string token = DB.User.GetUserToken(user); DB.User.DeleteProfits(uid); if (!args.Contains("--debug")) { Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={proindex}&accountName={user}%23{discriminator}", $"data/stash/{user}.profit.{proindex}.json"); } StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($"data/stash/{user}.profit.{proindex}.json")); int currencyIndex = 0; int divIndex = 0; int essenceIndex = 0; int fragIndex = 0; int fossilIndex = 0; foreach (var t in stash.tabs) { switch (t.type) { case "CurrencyStash": if (t.n.Length == 1) { currencyIndex = t.i; } break; case "DivinationCardStash": divIndex = t.i; break; case "EssenceStash": essenceIndex = t.i; break; case "FragmentStash": fragIndex = t.i; break; case "DelveStash": fossilIndex = t.i; break; } } double pvalue = 0; int pcount = JSON.Stash.GetUserProfitCount(user, proindex); DB.Stash.SetTabRGBByTID(uid, proindex, $"{stash.tabs[proindex].colour.r}:{stash.tabs[proindex].colour.g}:{stash.tabs[proindex].colour.b}"); DB.Stash.SetTabNameByTID(uid, proindex, stash.tabs[proindex].n); Message.CMW($"Processing {pcount} items in Profit tab...", true, 2); foreach (var i in stash.items) { if (i.frameType == 5) // Currency { pvalue = pvalue + (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_currency")*i.stackSize); DB.Stash.AddProfitTable(uid, i.id, "currency", MySqlHelper.EscapeString(i.typeLine), i.stackSize, (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_currency") * i.stackSize)); } if (i.frameType == 0) // Fragment { pvalue = pvalue + (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_fragment") * i.stackSize); DB.Stash.AddProfitTable(uid, i.id, "fragment", MySqlHelper.EscapeString(i.typeLine), i.stackSize, (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_fragment") * i.stackSize)); } if (i.frameType == 6) // Div { pvalue = pvalue + (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_divination") * i.stackSize); DB.Stash.AddProfitTable(uid, i.id, "divination", MySqlHelper.EscapeString(i.typeLine), i.stackSize, (JSON.Currency.GetCurrencyValueByName(MySqlHelper.EscapeString(i.typeLine), "poeco_divination") * i.stackSize)); } } DB.User.SetUserItemCount(uid, pcount, proindex); DB.User.SetUserTabValue(uid, proindex, pvalue); } if (args.Contains("--usergen-tab")) { int uid = Convert.ToInt16(args[1]); string user = DB.User.GetUserNameByID(uid)[0]; string discriminator = DB.User.GetUserNameByID(uid)[1]; int rareindex = DB.User.GetUserTabIndex(user); string token = DB.User.GetUserToken(user); if (!args.Contains("--debug")) { Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={rareindex}&accountName={user}%23{discriminator}", $"data/stash/{user}.json"); } StashRoot stash = JsonConvert.DeserializeObject(File.ReadAllText($@"data/stash/{user}.json")); int currencyIndex = 0; int divIndex = 0; int essenceIndex = 0; int fragIndex = 0; int fossilIndex = 0; foreach (var t in stash.tabs) { switch (t.type) { case "CurrencyStash": if (t.n.Length == 1) { currencyIndex = t.i; } break; case "DivinationCardStash": divIndex = t.i; break; case "EssenceStash": essenceIndex = t.i; break; case "FragmentStash": fragIndex = t.i; break; case "DelveStash": fossilIndex = t.i; break; } } if (DB.User.GetUserCurrencyIndex(user, "curindex") != -1) { Message.CMW($"Processing Currency tab...", true, 2); Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={currencyIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{currencyIndex}.json"); JSON.Currency.GenCurrencyTab(user, currencyIndex, "curvalue", "poeco_currency"); } if (DB.User.GetUserCurrencyIndex(user, "divindex") != -1) { Message.CMW($"Processing Divination tab...", true, 2); Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={divIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{divIndex}.json"); JSON.Currency.GenCurrencyTab(user, divIndex, "divvalue", "poeco_divination"); } if (DB.User.GetUserCurrencyIndex(user, "essindex") != -1) { Message.CMW($"Processing Essence tab...", true, 2); Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={essenceIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{essenceIndex}.json"); JSON.Currency.GenCurrencyTab(user, essenceIndex, "essvalue", "poeco_essence"); } if (DB.User.GetUserCurrencyIndex(user, "fraindex") != -1) { Message.CMW($"Processing Fragment tab...", true, 2); Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={fragIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{fragIndex}.json"); JSON.Currency.GenCurrencyTab(user, fragIndex, "fravalue", "poeco_fragment"); } if (DB.User.GetUserCurrencyIndex(user, "fosindex") != -1) { Message.CMW($"Processing Fossil tab...", true, 2); Web.Stash.DownloadStash(token, $"https://www.pathofexile.com/character-window/get-stash-items?league={JSON.Settings.GetLeague()}&tabs=1&tabIndex={fossilIndex}&accountName={user}%23{discriminator}", $"data/stash/{user}.tab.{fossilIndex}.json"); JSON.Currency.GenCurrencyTab(user, fossilIndex, "fosvalue", "poeco_fossil"); } } } } } }