Skip to content

Commit

Permalink
Fix crashing when not all champs can be found in memory
Browse files Browse the repository at this point in the history
Fix rounding gold values in player gold info tab
Inform user when memory has an issue
Extra logging
  • Loading branch information
floh22 committed Jul 25, 2021
1 parent 8630b9f commit 2bf0d96
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 48 deletions.
4 changes: 2 additions & 2 deletions LCUSharp/LCUSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyVersion>1.4.7.0</AssemblyVersion>
<FileVersion>1.4.7.21201</FileVersion>
<AssemblyVersion>1.4.9.0</AssemblyVersion>
<FileVersion>1.4.9.21204</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions LeagueBroadcast.Common/LeagueBroadcast.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyVersion>1.4.9.0</AssemblyVersion>
<FileVersion>1.4.9.21201</FileVersion>
<AssemblyVersion>1.4.14.0</AssemblyVersion>
<FileVersion>1.4.14.21204</FileVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
11 changes: 5 additions & 6 deletions LeagueBroadcast.Farsight/FarsightController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,18 @@ public void Connect(Process p)

public Snapshot CreateSnapshot(double gameTime = 0)
{


Snapshot snap = new();
if (!Memory.IsConnected || !ShouldRun)
{
return snap;
}

if (gameTime > 2)
{
ReadObjects(snap);
ClearMissing(snap);
}

ReadObjects(snap);
ClearMissing(snap);

return snap;
}

Expand Down
4 changes: 2 additions & 2 deletions LeagueBroadcast.Farsight/LeagueBroadcast.Farsight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<AssemblyVersion>1.4.15.0</AssemblyVersion>
<FileVersion>1.4.15.21201</FileVersion>
<AssemblyVersion>1.4.23.0</AssemblyVersion>
<FileVersion>1.4.23.21204</FileVersion>
<OutputType>Library</OutputType>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions LeagueBroadcast.Trinket/LeagueBroadcast.Trinket.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyVersion>1.4.4.0</AssemblyVersion>
<FileVersion>1.4.4.21201</FileVersion>
<AssemblyVersion>1.4.6.0</AssemblyVersion>
<FileVersion>1.4.6.21204</FileVersion>
<OutputType>Library</OutputType>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions LeagueBroadcast.Update/LeagueBroadcast.Update.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyVersion>1.4.9.0</AssemblyVersion>
<FileVersion>1.4.9.21201</FileVersion>
<AssemblyVersion>1.4.14.0</AssemblyVersion>
<FileVersion>1.4.14.21204</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion LeagueBroadcast/Ingame/Data/LBH/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 11 additions & 15 deletions LeagueBroadcast/Ingame/State/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace LeagueBroadcast.Ingame.State
class State
{
private IngameController controller;
private bool ShowedChampionMemoryError = false;

public StateData stateData;
public List<RiotEvent> pastIngameEvents;
Expand Down Expand Up @@ -95,23 +96,18 @@ public void UpdateTeams(List<Player> 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;
}

Expand Down
4 changes: 2 additions & 2 deletions LeagueBroadcast/LeagueBroadcast.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<RepositoryUrl>https://github.com/floh22/LeagueBroadcast</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageIcon>BE_icon.png</PackageIcon>
<AssemblyVersion>1.4.56.0</AssemblyVersion>
<FileVersion>1.4.56.21202</FileVersion>
<AssemblyVersion>1.4.64.0</AssemblyVersion>
<FileVersion>1.4.64.21204</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions LeagueBroadcast/OperatingSystem/Extensions.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<T>(ref T flags, T flag) where T : struct
Expand Down
Empty file.
17 changes: 3 additions & 14 deletions Overlays/ingame/src/visual/ScoreboardVisual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 + '';

Expand All @@ -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 + '';

Expand Down

0 comments on commit 2bf0d96

Please sign in to comment.