Skip to content

Commit

Permalink
fixed issues in spectate mode
Browse files Browse the repository at this point in the history
  • Loading branch information
BoSen29 committed Aug 15, 2023
1 parent 5d625a5 commit 82fd609
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ Note: the Overlay in Twitch needs to be configured to match the identity provide
Note: current implementation might experience issues when two streamers are in the same game, without equal stream-delay. Fix in progress.

## Changelog
1.1.6 - Fixed fetching data during spectate sessions.
1.1.5 - Fixed the data fetching issues.
1.1.4 - Another attempted fix at solving the issue of missing data from scoreboard. Now with forced exceptions @ 0.
1.1.3 - Fixed issues fetching Scoreboard-data during high-density mercenary spawning on west side.
84 changes: 52 additions & 32 deletions UnitTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using aag.Natives.Lib.Properties;
using Assets.Features.Dev;
using System.Text.RegularExpressions;
using UnityEngine;

namespace Logless
{
Expand Down Expand Up @@ -62,6 +63,7 @@ public class Plugin : BaseUnityPlugin
private Queue<QueuedItem> _queue = new Queue<QueuedItem>();
private List<Leaks> leaks = new List<Leaks>();
private int retries = 0;

Check warning on line 65 in UnitTracker.cs

View workflow job for this annotation

GitHub Actions / build-and-release

The field 'Plugin.retries' is assigned but its value is never used

Check warning on line 65 in UnitTracker.cs

View workflow job for this annotation

GitHub Actions / build-and-release

The field 'Plugin.retries' is assigned but its value is never used
private bool waveStartSynced = false;
public void Awake() {
configUrl = Config.Bind("General", "UpdateURL", "https://ltd2.krettur.no/v2/update", "HTTPS endpoint to post on waveStarted event, default is the extension used by the Twitch Overlay.");
configJwt = Config.Bind("General", "JWT", "", "JWT to authenticate your data, reach out to @bosen in discord to get your token for the Twitch Overlay.");
Expand Down Expand Up @@ -160,25 +162,25 @@ private QueuedItem fetchWaveStartedInfo()
}


int leftPercentage = 100;
int rightPercentage = 100;
try
{
UnitProperties left = Snapshot.UnitProperties[HudApi.GetHudSourceUnit(HudSection.LeftKing)];
UnitProperties right = Snapshot.UnitProperties[HudApi.GetHudSourceUnit(HudSection.RightKing)];
int leftPercentage = 100;
int rightPercentage = 100;
try
{
UnitProperties left = Snapshot.UnitProperties[HudApi.GetHudSourceUnit(HudSection.LeftKing)];
UnitProperties right = Snapshot.UnitProperties[HudApi.GetHudSourceUnit(HudSection.RightKing)];

//leftPercentage = (int)Math.Round(left.Hp.PercentLife); // (int)Math.Round(left.Hp.CurrentLife / left.Hp.MaxLife * 100);
//rightPercentage = (int)Math.Round(right.Hp.PercentLife); //Math.Round(right.Hp.CurrentLife / right.Hp.MaxLife * 100);
//leftPercentage = (int)Math.Round(left.Hp.PercentLife); // (int)Math.Round(left.Hp.CurrentLife / left.Hp.MaxLife * 100);
//rightPercentage = (int)Math.Round(right.Hp.PercentLife); //Math.Round(right.Hp.CurrentLife / right.Hp.MaxLife * 100);

leftPercentage = (int)Math.Round(left.Hp.GetLastLife(Snapshot.RenderTime) / left.Hp.GetMaxLife(Snapshot.RenderTime) * 100);
rightPercentage = (int)Math.Round(right.Hp.GetLastLife(Snapshot.RenderTime) / right.Hp.GetMaxLife(Snapshot.RenderTime) * 100);
// CurrentLife / MaxLife;
leftPercentage = (int)Math.Round(left.Hp.GetLastLife(Snapshot.RenderTime) / left.Hp.GetMaxLife(Snapshot.RenderTime) * 100);
rightPercentage = (int)Math.Round(right.Hp.GetLastLife(Snapshot.RenderTime) / right.Hp.GetMaxLife(Snapshot.RenderTime) * 100);
// CurrentLife / MaxLife;

}
catch
{
Console.WriteLine("King unavailable, asuming 100%");
}
}
catch
{
Console.WriteLine("King unavailable, asuming 100%");
}
Log("wave query was successfull.");
return
new QueuedItem(
Expand All @@ -200,34 +202,52 @@ public void Update()
this._registered = true;
Log("Registering event handlers.");

bool waveStartSynced = false;
HudApi.OnPostSetHudTheme += theme => {
Log("OnPostSetHudTheme: " + theme);
if (theme == "day") {
if (waveStartSynced) return;
waveStartSynced = true;
if (this.waveStartSynced && !ClientApi.IsSpectator()) return;
this.waveStartSynced = true;
actualWaveNumber += 1;
this.actualWaveNumber += 1;
Task.Run(async () => {
await Task.Delay(1000);
var prevState = fetchWaveStartedInfo();
var lastState = prevState;
int retries = 0;
bool done = false;
while (!done && retries < 6)
{
await Task.Delay(1000);
var newState = fetchWaveStartedInfo();
if (prevState == null || prevState?.serializedBody != newState?.serializedBody)
{
Log("wave state has changed OR wave query was unsuccessful.");
Log("old state: " + prevState?.serializedBody);
Log("new state: " + newState?.serializedBody);
prevState = newState;
}
else
{
Log("submitting wave state to server: " + newState?.serializedBody);
this._queue.Enqueue(newState);
done = true;
}
check:
await Task.Delay(1000);
var newState = fetchWaveStartedInfo();
if (prevState == null || prevState?.serializedBody != newState?.serializedBody) {
Log("wave state has changed OR wave query was unsuccessful.");
Log("old state: " +prevState?.serializedBody);
Log("new state: " +newState?.serializedBody);
prevState = newState;
goto check;
if (retries == 6)
{
lastState = newState;
}
}
if (!done)
{
Log("Submitting an unfinished state " + lastState?.serializedBody);
this._queue.Enqueue(lastState);
}
Log("submitting wave state to server: " + newState?.serializedBody);
this._queue.Enqueue(newState);
});
}
else {
waveStartSynced = false;
this.waveStartSynced = false;
}
};

Expand Down

0 comments on commit 82fd609

Please sign in to comment.