From 78fe5a7ce5405b5850edea7dd1c1d8bdcd7eb524 Mon Sep 17 00:00:00 2001 From: devRael1 Date: Sat, 9 Mar 2024 19:14:26 +0100 Subject: [PATCH 01/14] Update patch 14.5 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eaa206d..1c37371 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A set of several small tools for League Of Legends. -### Works with the latest `14.4` update of League of Legends ([Patch Notes : 14.4](https://na.leagueoflegends.com/en-us/news/game-updates/patch-14-4-notes/)) +### Works with the latest `14.5` update of League of Legends ([Patch Notes : 14.4](https://na.leagueoflegends.com/en-us/news/game-updates/patch-14-5-notes/)) ![Loly - Tools](/Ressources/mainMenu.png) ## `❗ Usage` From 53f07b56271a344b59945ae57661726f2076f99e Mon Sep 17 00:00:00 2001 From: devRael1 Date: Sun, 10 Mar 2024 21:04:56 +0100 Subject: [PATCH 02/14] New SessionPhase enum to optimize code --- src/Tasks/Scheduled/AnalyzeSessionTask.cs | 63 +++++++---------------- src/Tasks/Scheduled/LeagueClientTask.cs | 27 +++------- src/Tasks/TaskCore.cs | 10 +--- src/Variables/Enums/SessionPhase.cs | 15 ++++++ src/Variables/Global.cs | 7 ++- 5 files changed, 46 insertions(+), 76 deletions(-) create mode 100644 src/Variables/Enums/SessionPhase.cs diff --git a/src/Tasks/Scheduled/AnalyzeSessionTask.cs b/src/Tasks/Scheduled/AnalyzeSessionTask.cs index bf063fd..097c43c 100644 --- a/src/Tasks/Scheduled/AnalyzeSessionTask.cs +++ b/src/Tasks/Scheduled/AnalyzeSessionTask.cs @@ -20,79 +20,71 @@ public static void AnalyzeSession() string[] gameSession = Requests.ClientRequest("GET", "lol-gameflow/v1/gameflow-phase", true); if (gameSession[0] == "200") { - string phase = gameSession[1].Replace("\\", "").Replace("\"", ""); - if (Global.Session != phase) - { - Global.Session = phase; - } - + SessionPhase phase = (SessionPhase)Enum.Parse(typeof(SessionPhase), gameSession[1].Replace("\\", "").Replace("\"", "")); + if (Global.Session != phase) Global.Session = phase; HandlePhaseLogic(phase); } } } - private static void HandlePhaseLogic(string phase) + private static void HandlePhaseLogic(SessionPhase phase) { switch (phase) { - case "Lobby": + case SessionPhase.Lobby: Global.FetchedPlayers = false; Global.AcceptedCurrentMatch = false; - Global.ChampSelectInProgress = false; Thread.Sleep(TimeSpan.FromSeconds(5)); break; - case "Matchmaking": + case SessionPhase.Matchmaking: Global.FetchedPlayers = false; - Global.ChampSelectInProgress = false; Thread.Sleep(TimeSpan.FromSeconds(5)); break; - case "ReadyCheck": + case SessionPhase.ReadyCheck: HandleReadyCheckPhase(); + Thread.Sleep(TimeSpan.FromSeconds(2)); break; - case "ChampSelect": + case SessionPhase.ChampSelect: HandleChampSelectPhase(); Thread.Sleep(TimeSpan.FromSeconds(5)); break; - case "InProgress": + case SessionPhase.InProgress: Thread.Sleep(TimeSpan.FromSeconds(10)); break; - case "WaitingForStats": + case SessionPhase.WaitingForStats: Thread.Sleep(TimeSpan.FromSeconds(15)); break; - case "PreEndOfGame": + case SessionPhase.PreEndOfGame: Thread.Sleep(TimeSpan.FromSeconds(10)); break; - case "EndOfGame": + case SessionPhase.EndOfGame: Thread.Sleep(TimeSpan.FromSeconds(15)); break; - case "None": - Global.ChampSelectInProgress = false; + case SessionPhase.None: Global.FetchedPlayers = false; + Global.AcceptedCurrentMatch = false; Thread.Sleep(TimeSpan.FromSeconds(5)); break; default: - Global.ChampSelectInProgress = false; Global.FetchedPlayers = false; + Global.AcceptedCurrentMatch = false; Thread.Sleep(TimeSpan.FromSeconds(10)); break; } - if (phase != "ChampSelect") - { - Global.LastChatRoom = ""; - } + if (phase != SessionPhase.ChampSelect) Global.LastChatRoom = ""; } private static void HandleReadyCheckPhase() { Global.FetchedPlayers = false; - Global.ChampSelectInProgress = false; if (!Settings.AutoAccept) { Thread.Sleep(TimeSpan.FromSeconds(5)); return; } + AutoAccept.AutoAcceptQueue(); } @@ -101,24 +93,9 @@ private static void HandleChampSelectPhase() // TODO: Create the detection of dodge champ select system Global.AcceptedCurrentMatch = false; - if (Settings.AutoAcceptOnce) - { - Settings.AutoAcceptOnce = false; - Settings.AutoAccept = false; - } - - if (Settings.LobbyRevealer && !Global.FetchedPlayers) - { - CreateTask(LobbyRevealer.GetLobbyRevealing, $"LobbyRevealing the current lobby", LogModule.Loly); - } - - if (Settings.AutoChat || Settings.PicknBan) - { - CreateTask(ChampSelectSession.HandleChampSelect, $"ChampSelect session analyze", LogModule.Loly); - } - - Thread.Sleep(TimeSpan.FromSeconds(2)); - Global.ChampSelectInProgress = true; + if (Settings.AutoAccept && Settings.AutoAcceptOnce) Settings.AutoAccept = false; + if (Settings.LobbyRevealer && !Global.FetchedPlayers) CreateTask(LobbyRevealer.GetLobbyRevealing, $"LobbyRevealing the current lobby", LogModule.Loly); + if (Settings.AutoChat || Settings.PicknBan) ChampSelectSession.HandleChampSelect(); } } } diff --git a/src/Tasks/Scheduled/LeagueClientTask.cs b/src/Tasks/Scheduled/LeagueClientTask.cs index 946d696..dea7299 100644 --- a/src/Tasks/Scheduled/LeagueClientTask.cs +++ b/src/Tasks/Scheduled/LeagueClientTask.cs @@ -22,12 +22,8 @@ public static void LolClientTask() Global.IsLeagueOpen = true; Process client = Process.GetProcessesByName("LeagueClientUx").FirstOrDefault(); - if (Global.AuthClient.Count == 0 && Global.AuthRiot.Count == 0) - { - GetLeagueAuth(); - } - - LoadSummonerId(false); + if (Global.AuthClient.Count == 0 && Global.AuthRiot.Count == 0) GetLeagueAuth(); + if (Global.SummonerLogged.SummonerId == null) LoadSummonerId(); if (Global.Region == "") { @@ -36,10 +32,7 @@ public static void LolClientTask() Global.Region = regionSplit.Region.ToLower(); } - if (!_lcuPid.Equals(client.Id)) - { - _lcuPid = client.Id; - } + if (!_lcuPid.Equals(client.Id)) _lcuPid = client.Id; } else { @@ -95,22 +88,14 @@ private static string Cmd(string gamename) foreach (ManagementBaseObject managementBaseObject in mngmtClass.GetInstances()) { ManagementObject o = (ManagementObject)managementBaseObject; - if (o["Name"].Equals(gamename)) - { - commandline = "[" + o["CommandLine"] + "]"; - } + if (o["Name"].Equals(gamename)) commandline = "[" + o["CommandLine"] + "]"; } return commandline; } - private static void LoadSummonerId(bool force = false) + private static void LoadSummonerId() { - if (Global.SummonerLogged?.SummonerId != null && !force) - { - return; - } - Logger.Info(LogModule.Loly, "Getting your Summoner ID"); string[] currentSummoner = Requests.WaitSuccessClientRequest("GET", "lol-summoner/v1/current-summoner", true); @@ -124,7 +109,7 @@ private static void LoadSummonerId(bool force = false) Global.SummonerLogged.AccountId = currentSum.AccountId; Global.SummonerLogged.Puuid = currentSum.Puuid; - Logger.Info(LogModule.Loly, $"Summoner ID loaded : {Global.SummonerLogged.SummonerId}"); + Logger.Info(LogModule.Loly, $"Logged Summoner ID loaded : {Global.SummonerLogged.SummonerId}"); } } } diff --git a/src/Tasks/TaskCore.cs b/src/Tasks/TaskCore.cs index 8fbcdec..4b6a789 100644 --- a/src/Tasks/TaskCore.cs +++ b/src/Tasks/TaskCore.cs @@ -15,18 +15,12 @@ public TaskCore() public void StartAllTasks() { - foreach (ScheduledTask scheduledTask in _scheduledTasks) - { - scheduledTask.Start(); - } + foreach (ScheduledTask scheduledTask in _scheduledTasks) scheduledTask.Start(); } public void StopAllTasks() { - foreach (ScheduledTask scheduledTask in _scheduledTasks) - { - scheduledTask.Stop(); - } + foreach (ScheduledTask scheduledTask in _scheduledTasks) scheduledTask.Stop(); } } } diff --git a/src/Variables/Enums/SessionPhase.cs b/src/Variables/Enums/SessionPhase.cs new file mode 100644 index 0000000..8441521 --- /dev/null +++ b/src/Variables/Enums/SessionPhase.cs @@ -0,0 +1,15 @@ +namespace Loly.src.Variables.Enums +{ + public enum SessionPhase + { + Lobby, + Matchmaking, + ReadyCheck, + ChampSelect, + InProgress, + WaitingForStats, + PreEndOfGame, + EndOfGame, + None + } +} diff --git a/src/Variables/Global.cs b/src/Variables/Global.cs index 72273cb..5c415b8 100644 --- a/src/Variables/Global.cs +++ b/src/Variables/Global.cs @@ -9,7 +9,7 @@ public class Global public const string GithubPage = "https://github.com/devRael1/LolyTools"; public const string SoftName = "League of Legends - Loly Tools"; public const string SoftAuthor = "devRael"; - private static string _session = ""; + private static SessionPhase _session = SessionPhase.None; public static List PlayerList = new(); public static List ChampionsList = new(); @@ -25,10 +25,9 @@ public class Global public static bool IsLeagueOpen { get; set; } = false; public static bool LogsMenuEnable { get; set; } = false; public static string Region { get; set; } = ""; - public static bool IsProdEnvironment { get; set; } = false; - public static bool ChampSelectInProgress { get; set; } = false; + public static bool IsProdEnvironment { get; set; } = true; - public static string Session + public static SessionPhase Session { get => _session; set From b64f7c6072da44125167b0a5623f9c6c08342b04 Mon Sep 17 00:00:00 2001 From: devRael1 Date: Sun, 10 Mar 2024 21:05:59 +0100 Subject: [PATCH 03/14] Patch error with PickAndBan tool Update time before each message in AutoChat --- src/Tools/AutoChat.cs | 2 +- src/Tools/ChampSelectSession.cs | 103 +++++++++++++------------------- 2 files changed, 43 insertions(+), 62 deletions(-) diff --git a/src/Tools/AutoChat.cs b/src/Tools/AutoChat.cs index 0e40e80..33e3094 100644 --- a/src/Tools/AutoChat.cs +++ b/src/Tools/AutoChat.cs @@ -38,7 +38,7 @@ public static void HandleChampSelectAutoChat() count++; } - Thread.Sleep(attempts * 200); + Thread.Sleep(attempts * 100); } } diff --git a/src/Tools/ChampSelectSession.cs b/src/Tools/ChampSelectSession.cs index 35fa360..039f2eb 100644 --- a/src/Tools/ChampSelectSession.cs +++ b/src/Tools/ChampSelectSession.cs @@ -16,23 +16,16 @@ public class ChampSelectSession public static bool CanSentMessages { get; set; } public static long ChampSelectStart { get; set; } public static InitRole CurrentRole { get; set; } + public static string AssignedRole { get; set; } public static void HandleChampSelect() { - if (Global.ChampSelectInProgress) - { - return; - } - string[] currentChampSelect = Requests.ClientRequest("GET", "lol-champ-select/v1/session", true); - if (currentChampSelect[0] != "200") - { - return; - } + if (currentChampSelect[0] != "200") return; ChampSelectResponse champSelectResponse = JsonConvert.DeserializeObject(currentChampSelect[1]); string currentChatRoom = champSelectResponse.ChatDetails.MultiUserChatId; - if (Global.LastChatRoom != currentChatRoom || Global.LastChatRoom == "") + if (Global.LastChatRoom != currentChatRoom) { HoverPick = false; LockedPick = false; @@ -48,68 +41,56 @@ public static void HandleChampSelect() { Logger.Info(LogModule.PickAndBan, "Pick and Ban are locked. Waiting for game to start"); Thread.Sleep(TimeSpan.FromSeconds(10)); + return; } - else - { - List myTeam = champSelectResponse.MyTeam; - foreach (MemberTeam member in myTeam) - { - if (!member.SummonerId.Equals(Global.SummonerLogged.SummonerId)) - { - continue; - } - string position = member.AssignedPosition; - string assignedRole = position.ToLower() switch - { - "utility" => "Support", - "middle" => "Mid", - "jungle" => "Jungle", - "bottom" => "Adc", - "top" => "Top", - _ => "Default" - }; - - CurrentRole = (InitRole)Settings.LoLRoles.GetType().GetProperty(assignedRole).GetValue(Settings.LoLRoles); - Logger.Info(LogModule.PickAndBan, $"Assigned Role: {assignedRole}"); - break; - } + List myTeam = champSelectResponse.MyTeam; + foreach (MemberTeam member in myTeam) + { + if (!member.SummonerId.Equals(Global.SummonerLogged.SummonerId)) continue; - if (CurrentRole.PickChamp.Id == null) + string position = member.AssignedPosition; + string assignedRole = position.ToLower() switch { - HoverPick = true; - LockedPick = true; - } + "utility" => "Support", + "middle" => "Mid", + "jungle" => "Jungle", + "bottom" => "Adc", + "top" => "Top", + _ => "Default" + }; - if (CurrentRole.BanChamp.Id == null) - { - HoverBan = true; - LockedBan = true; - } + CurrentRole = (InitRole)Settings.LoLRoles.GetType().GetProperty(assignedRole).GetValue(Settings.LoLRoles); + break; + } - if (Settings.AutoChat && Settings.ChatMessages.Count > 0) - { - if (Global.LastChatRoom != currentChatRoom) - { - CanSentMessages = true; - } - } + if (CurrentRole.PickChamp.Id == null) + { + HoverPick = true; + LockedPick = true; + } - Global.LastChatRoom = currentChatRoom; + if (CurrentRole.BanChamp.Id == null) + { + HoverBan = true; + LockedBan = true; + } - if (Settings.AutoChat && CanSentMessages) - { - CreateTask(AutoChat.HandleChampSelectAutoChat, $"Sending Auto Chat messages", LogModule.AutoChat); - } + if (Settings.AutoChat && Settings.ChatMessages.Count > 0) + { + if (Global.LastChatRoom != currentChatRoom) CanSentMessages = true; + } - if (!HoverPick || !LockedPick || !HoverBan || !LockedBan) - { - PicknBan.ChampSelectResponse = champSelectResponse; - CreateTask(PicknBan.HandleChampSelectActions, $"Handling Pick and Ban", LogModule.PickAndBan); - } + Global.LastChatRoom = currentChatRoom; - CanSentMessages = false; + if (Settings.AutoChat && CanSentMessages) AutoChat.HandleChampSelectAutoChat(); + if (!HoverPick || !LockedPick || !HoverBan || !LockedBan) + { + PicknBan.ChampSelectResponse = champSelectResponse; + PicknBan.HandleChampSelectActions(); } + + CanSentMessages = false; } } } From f29f2c3ba0556b7561bc29bdea9fd6968e36b641 Mon Sep 17 00:00:00 2001 From: devRael1 Date: Sun, 10 Mar 2024 21:07:08 +0100 Subject: [PATCH 04/14] Some update and optimization of code Update PickAndBan tool (new enum class, optimize code...) --- src/Tools/LobbyRevealer.cs | 5 -- src/Tools/PicknBan.cs | 116 ++++++++++++------------------------- src/Tools/Utils.cs | 9 +-- 3 files changed, 40 insertions(+), 90 deletions(-) diff --git a/src/Tools/LobbyRevealer.cs b/src/Tools/LobbyRevealer.cs index 2bff49c..dbc739d 100644 --- a/src/Tools/LobbyRevealer.cs +++ b/src/Tools/LobbyRevealer.cs @@ -21,11 +21,6 @@ public static void GetTokenOpGg() public static void GetLobbyRevealing() { - if (Global.ChampSelectInProgress) - { - return; - } - if (OpGGToken == null) { GetTokenOpGg(); diff --git a/src/Tools/PicknBan.cs b/src/Tools/PicknBan.cs index 5b1b2e5..6f97758 100644 --- a/src/Tools/PicknBan.cs +++ b/src/Tools/PicknBan.cs @@ -9,6 +9,11 @@ namespace Loly.src.Tools; public class PicknBan { public static ChampSelectResponse ChampSelectResponse { get; set; } + private enum ActionType + { + Pick, + Ban + } public static void HandleChampSelectActions() { @@ -17,144 +22,97 @@ public static void HandleChampSelectActions() { foreach (Action action in arrActions) { - if (action.ActorCellId != ChampSelectResponse.LocalPlayerCellId || action.Completed) - { - continue; - } - - if (action.Type == "pick") - { - HandlePickAction(action); - } - - if (action.Type == "ban") - { - HandleBanAction(action); - } + if (action.ActorCellId != ChampSelectResponse.LocalPlayerCellId || action.Completed) continue; + if (action.Type == "pick") HandlePickAction(action); + if (action.Type == "ban") HandleBanAction(action); } } } private static void MarkPhaseStart(int actionId) { - if (actionId == Global.LastActionId) - { - return; - } - + if (actionId == Global.LastActionId) return; Global.LastActionId = actionId; } private static void HandlePickAction(Action action) { - if (ChampSelectSession.CurrentRole.PickChamp.Id == null) - { - return; - } + if (ChampSelectSession.CurrentRole.PickChamp.Id == null) return; if (!ChampSelectSession.HoverPick) { string champSelectPhase = ChampSelectResponse.Timer.Phase; long currentTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - if (currentTime - 3000 > ChampSelectSession.ChampSelectStart || champSelectPhase != "PLANNING") - { - HoverChampion(action.Id, "pick"); - } + if (currentTime - 3000 > ChampSelectSession.ChampSelectStart || champSelectPhase != "PLANNING") HoverChampion(action.Id, ActionType.Pick); } - if (!action.IsInProgress) - { - return; - } + if (!action.IsInProgress) return; MarkPhaseStart(action.Id); - if (ChampSelectSession.LockedPick) - { - return; - } + if (ChampSelectSession.LockedPick) return; Thread.Sleep(ChampSelectSession.CurrentRole.PickChamp.Delay); - LockChampion(action.Id, "pick"); + LockChampion(action.Id, ActionType.Pick); } private static void HandleBanAction(Action action) { - if (ChampSelectSession.CurrentRole.BanChamp.Id == null) - { - return; - } - + if (ChampSelectSession.CurrentRole.BanChamp.Id == null) return; string champSelectPhase = ChampSelectResponse.Timer.Phase; - - if (!action.IsInProgress || champSelectPhase == "PLANNING") - { - return; - } + if (!action.IsInProgress || champSelectPhase == "PLANNING") return; MarkPhaseStart(action.Id); - if (!ChampSelectSession.HoverBan) - { - HoverChampion(action.Id, "ban"); - } - - if (ChampSelectSession.LockedBan) - { - return; - } + if (!ChampSelectSession.HoverBan) HoverChampion(action.Id, ActionType.Ban); + if (ChampSelectSession.LockedBan) return; Thread.Sleep(ChampSelectSession.CurrentRole.BanChamp.Delay); - LockChampion(action.Id, "ban"); + LockChampion(action.Id, ActionType.Ban); } - private static void HoverChampion(int actionId, string actType) + private static void HoverChampion(int actionId, ActionType actionType) { - ChampItem champion = actType == "pick" ? ChampSelectSession.CurrentRole.PickChamp : ChampSelectSession.CurrentRole.BanChamp; - Logger.Info(LogModule.PickAndBan, $"Hover '{champion.Name}' champion for {actType}"); + ChampItem champion = actionType == ActionType.Pick ? ChampSelectSession.CurrentRole.PickChamp : ChampSelectSession.CurrentRole.BanChamp; + Logger.Info(LogModule.PickAndBan, $"Hover '{champion.Name}' champion for {actionType}"); string[] champSelectAction = Requests.ClientRequest("PATCH", $"lol-champ-select/v1/session/actions/{actionId}", true, $"{{\"championId\":{champion.Id}}}"); - if (champSelectAction[0] != "204") - { - return; - } + if (champSelectAction[0] != "204") return; - switch (actType) + switch (actionType) { - case "pick": + case ActionType.Pick: ChampSelectSession.HoverPick = true; break; - case "ban": + case ActionType.Ban: ChampSelectSession.HoverBan = true; break; } - Logger.Info(LogModule.PickAndBan, $"'{champion.Name}' has been hovered for {actType}"); + Logger.Info(LogModule.PickAndBan, $"'{champion.Name}' has been hovered for {actionType}"); + int delay = actionType == ActionType.Pick ? ChampSelectSession.CurrentRole.PickChamp.Delay : ChampSelectSession.CurrentRole.BanChamp.Delay; + Logger.Info(LogModule.PickAndBan, $"Waiting {delay}ms to '{actionType}' him"); } - private static void LockChampion(int actionId, string actType) + private static void LockChampion(int actionId, ActionType actionType) { - ChampItem champion = actType == "pick" ? ChampSelectSession.CurrentRole.PickChamp : ChampSelectSession.CurrentRole.BanChamp; - Logger.Info(LogModule.PickAndBan, $"Locking '{champion.Name}' champion for {actType}"); + ChampItem champion = actionType == ActionType.Pick ? ChampSelectSession.CurrentRole.PickChamp : ChampSelectSession.CurrentRole.BanChamp; + Logger.Info(LogModule.PickAndBan, $"Locking '{champion.Name}' champion for {actionType}"); string[] champSelectAction = Requests.ClientRequest("PATCH", $"lol-champ-select/v1/session/actions/{actionId}", true, $"{{\"completed\":true,\"championId\":{champion.Id}}}"); - if (champSelectAction[0] != "204") - { - return; - } + if (champSelectAction[0] != "204") return; - switch (actType) + switch (actionType) { - case "pick": + case ActionType.Pick: ChampSelectSession.LockedPick = true; break; - case "ban": + case ActionType.Ban: ChampSelectSession.LockedBan = true; break; } - Logger.Info(LogModule.PickAndBan, $"'{champion.Name}' has been locked for {actType}"); - + Logger.Info(LogModule.PickAndBan, $"'{champion.Name}' has been locked for {actionType}"); } } \ No newline at end of file diff --git a/src/Tools/Utils.cs b/src/Tools/Utils.cs index d7ad674..d3fa938 100644 --- a/src/Tools/Utils.cs +++ b/src/Tools/Utils.cs @@ -56,8 +56,8 @@ public static string LrParse(string source, string left, string right, int innt public static void LogNewError(string actionName, LogModule logModule, Exception ex) { Logger.Error(logModule, $"An error occured to execute : {actionName}", null); - Logger.Error(logModule, "Please check the logs for more information.", null); - Logger.Error(logModule, "Error message : ", ex); + Logger.Error(logModule, "Please check the logs file for more information.", null); + Logger.Error(logModule, "Error : ", ex); } public static string FormatStr(string str) @@ -105,10 +105,7 @@ public static void CreateTask(Action action, string errorMessage, LogModule logM Task.Run(action) .ContinueWith(t => { - if (t.IsFaulted) - { - LogNewError(errorMessage, logModule, t.Exception); - } + if (t.IsFaulted) LogNewError(errorMessage, logModule, t.Exception); }); } From a9c75d8975399be0a045ee6c5ae58948bbcbb3c9 Mon Sep 17 00:00:00 2001 From: devRael1 Date: Sun, 10 Mar 2024 21:07:27 +0100 Subject: [PATCH 05/14] Update message log system for : Request --- src/Logs/Logger.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Logs/Logger.cs b/src/Logs/Logger.cs index f3c36f9..a480c33 100644 --- a/src/Logs/Logger.cs +++ b/src/Logs/Logger.cs @@ -182,7 +182,7 @@ private static void ExecuteLogRequest(IRequest valueOfRequest) contentFile.Append($"Request to API - Endpoint: {request.Url} - Method: {request.Method}"); if (!string.IsNullOrWhiteSpace(request.Body)) { - contentFile.Append($"- Payload: {request.Body}"); + contentFile.Append($" - Payload: {request.Body}"); } } } @@ -194,7 +194,7 @@ private static void ExecuteLogRequest(IRequest valueOfRequest) contentFile.Append($"Response from API - Status: {response.StatusCode} - Method: {response.Method}"); if (response.Data != null) { - contentFile.Append($"- Response: {response.Data[1]}"); + contentFile.Append($" - Response: {response.Data[1]}"); } } } From c97d98367d8c4c4cb20ddbfd576dd3c0eb2c012b Mon Sep 17 00:00:00 2001 From: devRael1 Date: Sun, 10 Mar 2024 21:08:21 +0100 Subject: [PATCH 06/14] New system to logs unhandle exception (in `Program.cs`) --- Program.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Program.cs b/Program.cs index 5fabe01..e1580c2 100644 --- a/Program.cs +++ b/Program.cs @@ -3,7 +3,9 @@ using Loly.src.Menus; using Loly.src.Menus.Core; using Loly.src.Tasks; +using Loly.src.Tools; using Loly.src.Variables; +using Loly.src.Variables.Enums; namespace Loly; @@ -11,6 +13,8 @@ internal class Program { private static void Main() { + AppDomain.CurrentDomain.UnhandledException += UnhandledException; + Settings.SetDefaultSettings(); Settings.CreateOrUpdateSettings(); @@ -29,4 +33,9 @@ private static void Main() Interface.ShowArt(); MainMenu.StartMenu(); } + + private static void UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Utils.LogNewError("Unhandled exception", LogModule.Loly, (Exception)e.ExceptionObject); + } } \ No newline at end of file From 1a1ffc311f33a88fe53fc816bbe6707ebac4ed9d Mon Sep 17 00:00:00 2001 From: devRael1 Date: Sun, 10 Mar 2024 21:09:08 +0100 Subject: [PATCH 07/14] Update StatusCode in `HttpRequestException` request --- src/Tools/Requests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tools/Requests.cs b/src/Tools/Requests.cs index 51a76bf..9f293be 100644 --- a/src/Tools/Requests.cs +++ b/src/Tools/Requests.cs @@ -56,7 +56,7 @@ public static string[] ClientRequest(string method, string url, bool useclient, } catch (HttpRequestException ex) { - Logger.Request(new Response { Method = method, StatusCode = 0, Exception = ex }); + Logger.Request(new Response { Method = method, StatusCode = Convert.ToInt32(ex.StatusCode), Exception = ex }); return new[] { "999", "" }; } catch (Exception ex) From 75f3a5561e2e7e33bb0af4a8daee5ebce067fb8a Mon Sep 17 00:00:00 2001 From: devRael1 Date: Tue, 12 Mar 2024 18:26:02 +0100 Subject: [PATCH 08/14] Update AutoAccept system Patch issue with spamming message `Failed to auto accept the current match...` --- src/Tasks/Scheduled/AnalyzeSessionTask.cs | 3 ++- src/Tools/AutoAccept.cs | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Tasks/Scheduled/AnalyzeSessionTask.cs b/src/Tasks/Scheduled/AnalyzeSessionTask.cs index 097c43c..4395a8d 100644 --- a/src/Tasks/Scheduled/AnalyzeSessionTask.cs +++ b/src/Tasks/Scheduled/AnalyzeSessionTask.cs @@ -38,11 +38,12 @@ private static void HandlePhaseLogic(SessionPhase phase) break; case SessionPhase.Matchmaking: Global.FetchedPlayers = false; + Global.AcceptedCurrentMatch = false; Thread.Sleep(TimeSpan.FromSeconds(5)); break; case SessionPhase.ReadyCheck: HandleReadyCheckPhase(); - Thread.Sleep(TimeSpan.FromSeconds(2)); + Thread.Sleep(TimeSpan.FromSeconds(1)); break; case SessionPhase.ChampSelect: HandleChampSelectPhase(); diff --git a/src/Tools/AutoAccept.cs b/src/Tools/AutoAccept.cs index 864a48c..6799f41 100644 --- a/src/Tools/AutoAccept.cs +++ b/src/Tools/AutoAccept.cs @@ -9,19 +9,17 @@ public class AutoAccept { public static void AutoAcceptQueue() { + if (Global.AcceptedCurrentMatch) return; + string[] response = ClientRequest("POST", "lol-matchmaking/v1/ready-check/accept", true); - if (response[0] != "200") + if (response[0] != "204") { - Logger.Info(LogModule.AutoAccept, "Failed to auto accept the current match"); - Logger.Info(LogModule.AutoAccept, "Check logs to get more informations."); + Logger.Warn(LogModule.AutoAccept, "Failed to auto accept the current match"); + Logger.Warn(LogModule.AutoAccept, "Check Requests logs to get more informations."); return; } - if (!Global.AcceptedCurrentMatch) - { - Logger.Info(LogModule.AutoAccept, "The current match has been auto accepted"); - } - + Logger.Info(LogModule.AutoAccept, "The current match has been auto accepted"); Global.AcceptedCurrentMatch = true; } } \ No newline at end of file From d3d1bb9f0ff8729fd091ab84ddb67ec5a25c4722 Mon Sep 17 00:00:00 2001 From: devRael1 Date: Tue, 12 Mar 2024 18:27:39 +0100 Subject: [PATCH 09/14] Update StatusCode in `HttpRequestException` request in `WebRequest` function Update README --- README.md | 2 +- src/Tools/Requests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c37371..0686fa3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A set of several small tools for League Of Legends. -### Works with the latest `14.5` update of League of Legends ([Patch Notes : 14.4](https://na.leagueoflegends.com/en-us/news/game-updates/patch-14-5-notes/)) +### Works with the latest `14.5` update of League of Legends ([Patch Notes : 14.5](https://na.leagueoflegends.com/en-us/news/game-updates/patch-14-5-notes/)) ![Loly - Tools](/Ressources/mainMenu.png) ## `❗ Usage` diff --git a/src/Tools/Requests.cs b/src/Tools/Requests.cs index 9f293be..772a705 100644 --- a/src/Tools/Requests.cs +++ b/src/Tools/Requests.cs @@ -119,7 +119,7 @@ public static string WebRequest(string url, bool logResponse = true) } catch (HttpRequestException ex) { - Logger.Request(new Response { Method = "GET", StatusCode = 0, Exception = ex }); + Logger.Request(new Response { Method = "GET", StatusCode = Convert.ToInt32(ex.StatusCode), Exception = ex }); return null; } catch (Exception ex) From c3d19de901f5bb9f0a0d1954c262d29234c34bad Mon Sep 17 00:00:00 2001 From: devRael1 Date: Tue, 12 Mar 2024 18:48:43 +0100 Subject: [PATCH 10/14] Update log system for request Add URL in response log for request --- src/Logs/Logger.cs | 4 ++-- src/Tools/Requests.cs | 19 ++++++++++--------- src/Variables/Class/Request.cs | 3 +++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Logs/Logger.cs b/src/Logs/Logger.cs index a480c33..6405d46 100644 --- a/src/Logs/Logger.cs +++ b/src/Logs/Logger.cs @@ -179,7 +179,7 @@ private static void ExecuteLogRequest(IRequest valueOfRequest) { if (!string.IsNullOrWhiteSpace(request.Method) || !string.IsNullOrWhiteSpace(request.Url)) { - contentFile.Append($"Request to API - Endpoint: {request.Url} - Method: {request.Method}"); + contentFile.Append($"Request to API > Endpoint: {request.Url} - Method: {request.Method}"); if (!string.IsNullOrWhiteSpace(request.Body)) { contentFile.Append($" - Payload: {request.Body}"); @@ -191,7 +191,7 @@ private static void ExecuteLogRequest(IRequest valueOfRequest) { if (!string.IsNullOrWhiteSpace(response.Method)) { - contentFile.Append($"Response from API - Status: {response.StatusCode} - Method: {response.Method}"); + contentFile.Append($"Response from API > Endpoint: {response.Url} - Status: {response.StatusCode} - Method: {response.Method}"); if (response.Data != null) { contentFile.Append($" - Response: {response.Data[1]}"); diff --git a/src/Tools/Requests.cs b/src/Tools/Requests.cs index 772a705..4c9daea 100644 --- a/src/Tools/Requests.cs +++ b/src/Tools/Requests.cs @@ -49,19 +49,19 @@ public static string[] ClientRequest(string method, string url, bool useclient, string responseFromServer = response.Content.ReadAsStringAsync().Result; response.EnsureSuccessStatusCode(); - Logger.Request(new Response { Method = method, StatusCode = statusCode, Data = new[] { statusString, responseFromServer } }); + Logger.Request(new Response { Method = method, Url = url, StatusCode = statusCode, Data = new[] { statusString, responseFromServer } }); response.Dispose(); return new[] { statusString, responseFromServer }; } catch (HttpRequestException ex) { - Logger.Request(new Response { Method = method, StatusCode = Convert.ToInt32(ex.StatusCode), Exception = ex }); + Logger.Request(new Response { Method = method, Url = url, StatusCode = Convert.ToInt32(ex.StatusCode), Exception = ex }); return new[] { "999", "" }; } catch (Exception ex) { - Logger.Request(new Response { Method = method, StatusCode = 0, Exception = ex }); + Logger.Request(new Response { Method = method, Url = url, StatusCode = 0, Exception = ex }); return new[] { "999", "" }; } } @@ -95,14 +95,14 @@ public static string WebRequest(string url, bool logResponse = true) try { using HttpClient client = new(); + client.DefaultRequestHeaders.UserAgent.ParseAdd( + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"); Logger.Request(new Request { Method = "GET", Url = url }); HttpResponseMessage response = client.GetAsync($"https://{url}").Result; - if (!response.IsSuccessStatusCode) - { - return null; - } + if (!response.IsSuccessStatusCode) return null; + HttpContent responseContent = response.Content; string responseString = responseContent.ReadAsStringAsync().Result; @@ -111,6 +111,7 @@ public static string WebRequest(string url, bool logResponse = true) Logger.Request(new Response { Method = "GET", + Url = url, StatusCode = (int)response.StatusCode, Data = new[] { response.StatusCode.ToString(), logResponse ? responseString : "NOT LOGGED" } }); @@ -119,12 +120,12 @@ public static string WebRequest(string url, bool logResponse = true) } catch (HttpRequestException ex) { - Logger.Request(new Response { Method = "GET", StatusCode = Convert.ToInt32(ex.StatusCode), Exception = ex }); + Logger.Request(new Response { Method = "GET", Url = url, StatusCode = Convert.ToInt32(ex.StatusCode), Exception = ex }); return null; } catch (Exception ex) { - Logger.Request(new Response { Method = "GET", StatusCode = 0, Exception = ex }); + Logger.Request(new Response { Method = "GET", Url = url, StatusCode = 0, Exception = ex }); return null; } } diff --git a/src/Variables/Class/Request.cs b/src/Variables/Class/Request.cs index 95a9a00..7b481d3 100644 --- a/src/Variables/Class/Request.cs +++ b/src/Variables/Class/Request.cs @@ -3,6 +3,8 @@ public interface IRequest { public string Method { get; set; } + public string Url { get; set; } + public Exception Exception { get; set; } } @@ -17,6 +19,7 @@ public class Request : IRequest public class Response : IRequest { public string Method { get; set; } + public string Url { get; set; } public int StatusCode { get; set; } public string[] Data { get; set; } public Exception Exception { get; set; } From 75497859b84554779c824c2193833f6cb28bcb28 Mon Sep 17 00:00:00 2001 From: devRael1 Date: Tue, 12 Mar 2024 18:49:26 +0100 Subject: [PATCH 11/14] Patch issue with token of OP.GG Update LobbyRevealer system to run LobbyRevealing in one task in background --- src/Tools/LobbyRevealer.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Tools/LobbyRevealer.cs b/src/Tools/LobbyRevealer.cs index dbc739d..a862d55 100644 --- a/src/Tools/LobbyRevealer.cs +++ b/src/Tools/LobbyRevealer.cs @@ -14,7 +14,7 @@ public class LobbyRevealer public static void GetTokenOpGg() { Logger.Info(LogModule.LobbyRevealer, "Fetching OP.GG token"); - string response = Requests.WebRequest("www.op.gg/multisearch", false); + string response = Requests.WebRequest("www.op.gg", false); OpGGToken = Utils.LrParse(response, "\"buildId\":\"", "\",\"assetPrefix") ?? "null"; Logger.Info(LogModule.LobbyRevealer, $"Fetching OP.GG token successfully (Token: {OpGGToken})"); } @@ -27,9 +27,8 @@ public static void GetLobbyRevealing() } GetPlayers(Requests.ClientRequest("GET", "/chat/v5/participants/lol-champ-select", false)[1]); - Utils.CreateTask(GetAdvancedPlayersStats, "Fetching Advanced player stats !", LogModule.LobbyRevealer); - Global.FetchedPlayers = true; + GetAdvancedPlayersStats(); } public static void GetPlayers(string req) From ff14f906395ec6f34cdcc13e2bffdfaba857872b Mon Sep 17 00:00:00 2001 From: devRael1 Date: Wed, 13 Mar 2024 08:02:56 +0100 Subject: [PATCH 12/14] Update ClearLogsFiles task to 1 hour --- src/Tasks/TaskCore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tasks/TaskCore.cs b/src/Tasks/TaskCore.cs index 4b6a789..8b95301 100644 --- a/src/Tasks/TaskCore.cs +++ b/src/Tasks/TaskCore.cs @@ -10,7 +10,7 @@ public TaskCore() { _scheduledTasks.Add(new ScheduledTask(LeagueClientTask.LolClientTask, "LolClientTask", TimeSpan.FromSeconds(5), true, false)); _scheduledTasks.Add(new ScheduledTask(AnalyzeSessionTask.AnalyzeSession, "AnalyzeSession", TimeSpan.FromMinutes(1), true, true)); - _scheduledTasks.Add(new ScheduledTask(ClearLogsFilesTask.RunClearLogsFiles, "RunClearLogsFiles", TimeSpan.FromHours(2), true, false)); + _scheduledTasks.Add(new ScheduledTask(ClearLogsFilesTask.RunClearLogsFiles, "RunClearLogsFiles", TimeSpan.FromHours(1), true, false)); } public void StartAllTasks() From 1c74bf70cefac8d6bda92e9cb31c18234d2c749e Mon Sep 17 00:00:00 2001 From: devRael1 Date: Fri, 15 Mar 2024 18:17:14 +0100 Subject: [PATCH 13/14] Update some sentences Update name of `CreateTask` function to `CreateBackgroundTask` --- src/Tasks/Scheduled/AnalyzeSessionTask.cs | 2 +- src/Tasks/Scheduled/LeagueClientTask.cs | 4 +++- src/Tasks/ScheduledTask.cs | 4 ++-- src/Tools/AutoChat.cs | 2 +- src/Tools/LobbyRevealer.cs | 2 +- src/Tools/Utils.cs | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Tasks/Scheduled/AnalyzeSessionTask.cs b/src/Tasks/Scheduled/AnalyzeSessionTask.cs index 4395a8d..50838b5 100644 --- a/src/Tasks/Scheduled/AnalyzeSessionTask.cs +++ b/src/Tasks/Scheduled/AnalyzeSessionTask.cs @@ -95,7 +95,7 @@ private static void HandleChampSelectPhase() Global.AcceptedCurrentMatch = false; if (Settings.AutoAccept && Settings.AutoAcceptOnce) Settings.AutoAccept = false; - if (Settings.LobbyRevealer && !Global.FetchedPlayers) CreateTask(LobbyRevealer.GetLobbyRevealing, $"LobbyRevealing the current lobby", LogModule.Loly); + if (Settings.LobbyRevealer && !Global.FetchedPlayers) CreateBackgroundTask(LobbyRevealer.GetLobbyRevealing, $"LobbyRevealing the current lobby", LogModule.Loly); if (Settings.AutoChat || Settings.PicknBan) ChampSelectSession.HandleChampSelect(); } } diff --git a/src/Tasks/Scheduled/LeagueClientTask.cs b/src/Tasks/Scheduled/LeagueClientTask.cs index dea7299..72d3725 100644 --- a/src/Tasks/Scheduled/LeagueClientTask.cs +++ b/src/Tasks/Scheduled/LeagueClientTask.cs @@ -27,9 +27,11 @@ public static void LolClientTask() if (Global.Region == "") { + Logger.Info(LogModule.Loly, "Fetching region of your League Of Legends Client"); string response = Requests.WaitSuccessClientRequest("GET", "/riotclient/region-locale", true)[1]; PlayerRegion regionSplit = JsonConvert.DeserializeObject(response); Global.Region = regionSplit.Region.ToLower(); + Logger.Info(LogModule.Loly, $"Region fetched successfully : {Global.Region.ToUpper()}"); } if (!_lcuPid.Equals(client.Id)) _lcuPid = client.Id; @@ -96,7 +98,7 @@ private static string Cmd(string gamename) private static void LoadSummonerId() { - Logger.Info(LogModule.Loly, "Getting your Summoner ID"); + Logger.Info(LogModule.Loly, "Fetching your Summoner ID"); string[] currentSummoner = Requests.WaitSuccessClientRequest("GET", "lol-summoner/v1/current-summoner", true); CurrentSummoner currentSum = JsonConvert.DeserializeObject(currentSummoner[1]); diff --git a/src/Tasks/ScheduledTask.cs b/src/Tasks/ScheduledTask.cs index ae88c37..86efadf 100644 --- a/src/Tasks/ScheduledTask.cs +++ b/src/Tasks/ScheduledTask.cs @@ -35,7 +35,7 @@ public void Start() { if (runNow) { - Utils.CreateTask(taskAction, $"Task [{taskName}]", LogModule.Tasks); + Utils.CreateBackgroundTask(taskAction, $"Task [{taskName}]", LogModule.Tasks); } if (!infinite) @@ -52,7 +52,7 @@ public void Stop() private void TimerElapsed(object sender, ElapsedEventArgs e) { - Utils.CreateTask(taskAction, $"Task [{taskName}]", LogModule.Tasks); + Utils.CreateBackgroundTask(taskAction, $"Task [{taskName}]", LogModule.Tasks); } } } diff --git a/src/Tools/AutoChat.cs b/src/Tools/AutoChat.cs index 33e3094..a9501cc 100644 --- a/src/Tools/AutoChat.cs +++ b/src/Tools/AutoChat.cs @@ -11,7 +11,7 @@ public class AutoChat public static void HandleChampSelectAutoChat() { - Logger.Info(LogModule.AutoChat, "Getting Chat & Summoner ID"); + Logger.Info(LogModule.AutoChat, "Fetching Chat information & Summoner ID"); string[] myChatProfile = Requests.ClientRequest("GET", "lol-chat/v1/me", true); ChatMe chatProfileJson = JsonConvert.DeserializeObject(myChatProfile[1]); string currentChatId = chatProfileJson.Id; diff --git a/src/Tools/LobbyRevealer.cs b/src/Tools/LobbyRevealer.cs index a862d55..b3d3bd4 100644 --- a/src/Tools/LobbyRevealer.cs +++ b/src/Tools/LobbyRevealer.cs @@ -73,7 +73,7 @@ public static void GetPlayers(string req) public static void GetAdvancedPlayersStats() { - Logger.Info(LogModule.LobbyRevealer, $"Getting advanced stats of {Global.PlayerList.Count} players in background..."); + Logger.Info(LogModule.LobbyRevealer, $"Fetching advanced stats of {Global.PlayerList.Count} players in background..."); Parallel.ForEach(Global.PlayerList, player => { diff --git a/src/Tools/Utils.cs b/src/Tools/Utils.cs index d3fa938..a0625b4 100644 --- a/src/Tools/Utils.cs +++ b/src/Tools/Utils.cs @@ -100,7 +100,7 @@ public static string FormatBytes(long bytes, bool seconds, int decimals = 2) return $"{(bytes / Math.Pow(k, i)).ToString($"F{dm}")} {sizes[i]}{(seconds ? "/s" : "")}"; } - public static void CreateTask(Action action, string errorMessage, LogModule logModule) + public static void CreateBackgroundTask(Action action, string errorMessage, LogModule logModule) { Task.Run(action) .ContinueWith(t => From fe8fb8c42a65289270091ecd068f6b81e52c2db1 Mon Sep 17 00:00:00 2001 From: devRael1 Date: Fri, 15 Mar 2024 18:17:38 +0100 Subject: [PATCH 14/14] Update version `2.2.0` Update README --- README.md | 5 +++++ Version.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0686fa3..f16e1e2 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ No need to install this if you have a more recent version installed. More features coming soon... ## `📷 Screenshots` +
+Click here to see all screenshots... + ### Updater Menu
See screenshot... @@ -64,6 +67,8 @@ More features coming soon... devRael1
+
+ ## `❓ Bugs report / Suggestions` If you want to report a bug or suggest a feature, you can open an issue [here](https://github.com/devRael1/LolyTools/issues) or contact me on Discord.
My Discord: `1043813027205619804` diff --git a/Version.cs b/Version.cs index 1b98480..d8c62a0 100644 --- a/Version.cs +++ b/Version.cs @@ -11,7 +11,7 @@ public static class Version public static string FullVersionNoStage => $"{Major}.{Minor}.{Hotfix}"; private static int Major => 2; - private static int Minor => 1; + private static int Minor => 2; private static int Hotfix => 0; } }