From 2bf0d9629a6f677d94d164199566bedafc2271ae Mon Sep 17 00:00:00 2001 From: eble_lars Date: Sun, 25 Jul 2021 23:14:53 +0200 Subject: [PATCH] Fix crashing when not all champs can be found in memory Fix rounding gold values in player gold info tab Inform user when memory has an issue Extra logging --- LCUSharp/LCUSharp.csproj | 4 +-- .../LeagueBroadcast.Common.csproj | 4 +-- .../FarsightController.cs | 11 ++++---- .../LeagueBroadcast.Farsight.csproj | 4 +-- .../LeagueBroadcast.Trinket.csproj | 4 +-- .../LeagueBroadcast.Update.csproj | 4 +-- LeagueBroadcast/Ingame/Data/LBH/Team.cs | 3 ++- .../Data/Provider/LiveEventsDataProvider.cs | 4 +++ LeagueBroadcast/Ingame/State/State.cs | 26 ++++++++----------- LeagueBroadcast/LeagueBroadcast.csproj | 4 +-- LeagueBroadcast/OperatingSystem/Extensions.cs | 20 ++++++++++++++ Overlays/ingame/src/util/Utils.ts | 0 .../ingame/src/visual/ScoreboardVisual.ts | 17 +++--------- 13 files changed, 57 insertions(+), 48 deletions(-) create mode 100644 Overlays/ingame/src/util/Utils.ts diff --git a/LCUSharp/LCUSharp.csproj b/LCUSharp/LCUSharp.csproj index ae8304e..26c970d 100644 --- a/LCUSharp/LCUSharp.csproj +++ b/LCUSharp/LCUSharp.csproj @@ -2,8 +2,8 @@ netcoreapp3.1 - 1.4.7.0 - 1.4.7.21201 + 1.4.9.0 + 1.4.9.21204 diff --git a/LeagueBroadcast.Common/LeagueBroadcast.Common.csproj b/LeagueBroadcast.Common/LeagueBroadcast.Common.csproj index e54e8f6..c23b328 100644 --- a/LeagueBroadcast.Common/LeagueBroadcast.Common.csproj +++ b/LeagueBroadcast.Common/LeagueBroadcast.Common.csproj @@ -2,8 +2,8 @@ netcoreapp3.1 - 1.4.9.0 - 1.4.9.21201 + 1.4.14.0 + 1.4.14.21204 latest diff --git a/LeagueBroadcast.Farsight/FarsightController.cs b/LeagueBroadcast.Farsight/FarsightController.cs index abdd608..d9d0c38 100644 --- a/LeagueBroadcast.Farsight/FarsightController.cs +++ b/LeagueBroadcast.Farsight/FarsightController.cs @@ -48,7 +48,7 @@ public void Connect(Process p) public Snapshot CreateSnapshot(double gameTime = 0) { - + Snapshot snap = new(); if (!Memory.IsConnected || !ShouldRun) @@ -56,11 +56,10 @@ public Snapshot CreateSnapshot(double gameTime = 0) return snap; } - if (gameTime > 2) - { - ReadObjects(snap); - ClearMissing(snap); - } + + ReadObjects(snap); + ClearMissing(snap); + return snap; } diff --git a/LeagueBroadcast.Farsight/LeagueBroadcast.Farsight.csproj b/LeagueBroadcast.Farsight/LeagueBroadcast.Farsight.csproj index 51734c3..ac94993 100644 --- a/LeagueBroadcast.Farsight/LeagueBroadcast.Farsight.csproj +++ b/LeagueBroadcast.Farsight/LeagueBroadcast.Farsight.csproj @@ -3,8 +3,8 @@ netcoreapp3.1 latest - 1.4.15.0 - 1.4.15.21201 + 1.4.23.0 + 1.4.23.21204 Library diff --git a/LeagueBroadcast.Trinket/LeagueBroadcast.Trinket.csproj b/LeagueBroadcast.Trinket/LeagueBroadcast.Trinket.csproj index 8ff1b10..516f56d 100644 --- a/LeagueBroadcast.Trinket/LeagueBroadcast.Trinket.csproj +++ b/LeagueBroadcast.Trinket/LeagueBroadcast.Trinket.csproj @@ -2,8 +2,8 @@ netcoreapp3.1 - 1.4.4.0 - 1.4.4.21201 + 1.4.6.0 + 1.4.6.21204 Library diff --git a/LeagueBroadcast.Update/LeagueBroadcast.Update.csproj b/LeagueBroadcast.Update/LeagueBroadcast.Update.csproj index f425833..205e838 100644 --- a/LeagueBroadcast.Update/LeagueBroadcast.Update.csproj +++ b/LeagueBroadcast.Update/LeagueBroadcast.Update.csproj @@ -2,8 +2,8 @@ netcoreapp3.1 - 1.4.9.0 - 1.4.9.21201 + 1.4.14.0 + 1.4.14.21204 diff --git a/LeagueBroadcast/Ingame/Data/LBH/Team.cs b/LeagueBroadcast/Ingame/Data/LBH/Team.cs index 48a0769..0234174 100644 --- a/LeagueBroadcast/Ingame/Data/LBH/Team.cs +++ b/LeagueBroadcast/Ingame/Data/LBH/Team.cs @@ -57,7 +57,8 @@ public void UpdateIDs() public float GetGold(int i) { - return players.Select(p => p.goldHistory.Values.ElementAt(i)).Sum(); + //Get Gold for player at time or 0. Its better than crashing + return players.Select(p => p.goldHistory.Values.ElementAtOrDefault(i)).Sum(); } public float GetGold(double i) diff --git a/LeagueBroadcast/Ingame/Data/Provider/LiveEventsDataProvider.cs b/LeagueBroadcast/Ingame/Data/Provider/LiveEventsDataProvider.cs index e901782..d470be1 100644 --- a/LeagueBroadcast/Ingame/Data/Provider/LiveEventsDataProvider.cs +++ b/LeagueBroadcast/Ingame/Data/Provider/LiveEventsDataProvider.cs @@ -174,6 +174,10 @@ private bool CheckGameConfigLocation(string configLocation) File.WriteAllLines(Path.Join(LeagueFolder, "LiveEvents.ini"), new string[] { "OnMinionKill", "OnNeutralMinionKill" }); Log.Info("LiveEvents.ini created. Added only nescesary events!"); return true; + } catch(Exception e) + { + Log.Warn($"Error Parsing LiveEvents.ini:\n{e.Source} -> {e.Message}\n Stacktrace:\n{e.StackTrace}"); + return true; } } else diff --git a/LeagueBroadcast/Ingame/State/State.cs b/LeagueBroadcast/Ingame/State/State.cs index 6db77cb..b6d1d21 100644 --- a/LeagueBroadcast/Ingame/State/State.cs +++ b/LeagueBroadcast/Ingame/State/State.cs @@ -22,6 +22,7 @@ namespace LeagueBroadcast.Ingame.State class State { private IngameController controller; + private bool ShowedChampionMemoryError = false; public StateData stateData; public List pastIngameEvents; @@ -95,23 +96,18 @@ public void UpdateTeams(List PlayerData, Snapshot gameSnap) GameObject playerObject; try { - //Wukong <-> MonkeyKing - //Rek'Sai, Cho'Gath <-> RekSai, ChoGath - //Dr. Mundo <-> DrMundo - - //Replace this with a map of some kind between memory names and API names - playerObject = gameSnap.Champions.FirstOrDefault(c => c.Name.Equals(p.championID, StringComparison.OrdinalIgnoreCase)); + playerObject = gameSnap.Champions.First(c => c.Name.Equals(p.championID, StringComparison.OrdinalIgnoreCase)); } catch (Exception e) { - //Incorrect values now but its better than crashing? Not sure - playerObject = new(); - - Log.Warn(p.championName + " not found in memory snapshot"); - Log.Warn(e.Message); - Log.Verbose(JsonConvert.SerializeObject(gameSnap.Champions)); - } - if(playerObject == null) - { + //Champ could not be found. Inform user that mapping is currently not working + Log.Warn(p.championName + " not found in memory snapshot. Values will be incorrect!"); + if(!ShowedChampionMemoryError) + { + Log.Warn(e.Message); + Log.Verbose($"Players:\n{JsonConvert.SerializeObject(GetAllPlayers())}\nSnapshot:\n{JsonConvert.SerializeObject(gameSnap.Champions)}"); + MessageBoxUtils.ShowErrorBox("Could not read all champion data from memory. Please submit an issue on github containing the current log and replay."); + ShowedChampionMemoryError = true; + } return; } diff --git a/LeagueBroadcast/LeagueBroadcast.csproj b/LeagueBroadcast/LeagueBroadcast.csproj index 1f70ff6..116ac4e 100644 --- a/LeagueBroadcast/LeagueBroadcast.csproj +++ b/LeagueBroadcast/LeagueBroadcast.csproj @@ -15,8 +15,8 @@ https://github.com/floh22/LeagueBroadcast Git BE_icon.png - 1.4.56.0 - 1.4.56.21202 + 1.4.64.0 + 1.4.64.21204 diff --git a/LeagueBroadcast/OperatingSystem/Extensions.cs b/LeagueBroadcast/OperatingSystem/Extensions.cs index 3b4b524..3202206 100644 --- a/LeagueBroadcast/OperatingSystem/Extensions.cs +++ b/LeagueBroadcast/OperatingSystem/Extensions.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Windows; using System.Windows.Media; namespace LeagueBroadcast.OperatingSystem @@ -30,6 +32,24 @@ public static string ToSerializedString(this Color c) } } + public static class MessageBoxUtils + { + private static MessageBoxResult Current = MessageBoxResult.None; + public static void ShowErrorBox(string text) + { + if (Current != MessageBoxResult.None) + return; + Thread t = new(() => + { + Current = MessageBox.Show(text, "LeagueBroadcast", MessageBoxButton.OK, MessageBoxImage.Error); + Current = MessageBoxResult.None; + } + ); + t.Start(); + } + + } + public static class FlagsHelper { public static void Set(ref T flags, T flag) where T : struct diff --git a/Overlays/ingame/src/util/Utils.ts b/Overlays/ingame/src/util/Utils.ts new file mode 100644 index 0000000..e69de29 diff --git a/Overlays/ingame/src/visual/ScoreboardVisual.ts b/Overlays/ingame/src/visual/ScoreboardVisual.ts index 5682f51..2f0a316 100644 --- a/Overlays/ingame/src/visual/ScoreboardVisual.ts +++ b/Overlays/ingame/src/visual/ScoreboardVisual.ts @@ -4,6 +4,7 @@ import StateData from "~/data/stateData"; import PlaceholderConversion from "~/PlaceholderConversion"; import IngameScene from "~/scenes/IngameScene"; import TextUtils from "~/util/TextUtils"; +import Utils from "~/util/Utils"; import variables from "~/variables"; import { VisualElement } from "./VisualElement"; @@ -323,13 +324,7 @@ export default class ScoreboardVisual extends VisualElement { this.GameTime.text = (Math.floor(timeInSec / 60) >= 10 ? Math.floor(timeInSec / 60) : '0' + Math.floor(timeInSec / 60)) + ':' + (timeInSec % 60 >= 10 ? timeInSec % 60 : '0' + timeInSec % 60); //Update blue team values - var hundred = Math.round((scoreConfig.BlueTeam.Gold % 1000) / 100); - var thousand = Math.floor(scoreConfig.BlueTeam.Gold / 1000); - if (hundred === 10) { - thousand++; - hundred = 0; - } - this.BlueGold.text = thousand + '.' + hundred + 'k'; + this.BlueGold.text = Utils.ConvertGold(scoreConfig.BlueTeam.Gold); this.BlueKills.text = scoreConfig.BlueTeam.Kills + ''; this.BlueTowers.text = scoreConfig.BlueTeam.Towers + ''; @@ -352,13 +347,7 @@ export default class ScoreboardVisual extends VisualElement { } //Update red team values - hundred = Math.round((scoreConfig.RedTeam.Gold % 1000) / 100); - thousand = Math.floor(scoreConfig.RedTeam.Gold / 1000); - if (hundred === 10) { - thousand++; - hundred = 0; - } - this.RedGold.text = Math.floor(scoreConfig.RedTeam.Gold / 1000) + '.' + Math.floor((scoreConfig.RedTeam.Gold % 1000) / 100) + 'k'; + this.RedGold.text = Utils.ConvertGold(scoreConfig.RedTeam.Gold); this.RedKills.text = scoreConfig.RedTeam.Kills + ''; this.RedTowers.text = scoreConfig.RedTeam.Towers + '';