Skip to content

Commit

Permalink
Fix Deceive not exiting & change when status is updated in LCU (#32)
Browse files Browse the repository at this point in the history
* Prompts user to elevate if LCU is running as admin
Doesn't crash to access denied exception
Bumped version to v1.4.1

* fixed path when registry entry is not found, added new registry location

* fix if RiotClientInstalls.json exists, but no Riot Client or corrupted

* use List instead of Array for RC paths

* Target .NET 4.8; support .NET 4.6+

(.NET 4.6 is included since first Win10 release)

* use WebSocket to monitor chat status changes

more reliable reflection of masked status in client
does not break after leaving/joining lobbies or exiting games
changed IsValidLCUPath to check for system.yaml instead of Logs folder

* add reference to netstandard, just in case...

* use TLS 1.2 to handle random WebExceptions

* fix _ws assignment and check for null, remove redundant code

* Update LCU status only on gameflow phase change

* fix status on startup, as gameflow isn't changing now

* fix not being able to change status when disabled

* support RC proxy XMPP presence

* Fix Thread (therefore Deceive) not exiting

* Specify when exactly to send status update to LCU

* Bump to 1.6.1

* Fix LCU status not online after game when disabling while in game

* rename to StartupHandler, make CheckForUpdates() return void

class name was also inconsistent with file name
  • Loading branch information
aPinat authored and molenzwiebel committed Dec 15, 2019
1 parent ac4ec8f commit 6a55c7d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 44 deletions.
8 changes: 5 additions & 3 deletions Deceive/ConfigProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public static int StartConfigProxy(string configUrl, int chatPort)

// Run this on a new thread, just for the sake of it.
// It seemed to be buggy if run on the same thread.
new Thread(() =>
var thread = new Thread(() =>
{
server.RunAsync().Wait();
}).Start();
});
thread.IsBackground = true;
thread.Start();

return port;
}
Expand Down Expand Up @@ -117,7 +119,7 @@ private async static Task ProxyAndRewriteResponse(string configUrl, int chatPort
MessageBox.Show(
"Deceive was unable to rewrite a League of Legends configuration file. This normally happens because Riot changed something on their end. Please check if there's a new version of Deceive available, or contact the creator through GitHub (https://github.com/molenzwiebel/deceive) or Discord if there's not.\n\n" +
ex,
MainClass.DeceiveTitle,
StartupHandler.DeceiveTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1
Expand Down
2 changes: 1 addition & 1 deletion Deceive/Deceive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<ItemGroup>
<Compile Include="ConfigProxy.cs" />
<Compile Include="MainController.cs" />
<Compile Include="Program.cs" />
<Compile Include="StartupHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
26 changes: 7 additions & 19 deletions Deceive/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MainController()
{
Icon = Resources.deceive,
Visible = true,
BalloonTipTitle = MainClass.DeceiveTitle,
BalloonTipTitle = StartupHandler.DeceiveTitle,
BalloonTipText = "Deceive is currently masking your status. Right-Click the tray icon for more options."
};
trayIcon.ShowBalloonTip(5000);
Expand All @@ -41,30 +41,18 @@ private async void InitLcuStatus()
{
while (true)
{
if ((_ws = Utils.MonitorChatStatusChange(status)) == null)
if ((_ws = Utils.MonitorChatStatusChange(status, enabled)) == null)
{
// LCU is not ready yet. Wait for a bit.
await Task.Delay(3000);
}
else
{
try
{
Utils.SendStatusToLcu(status);
return;
}
catch
{
// LCU is not ready yet. Wait for a bit.
await Task.Delay(3000);
}
}

} else return;
}
}

private void SetupMenuItems()
{
var aboutMenuItem = new MenuItem(MainClass.DeceiveTitle)
var aboutMenuItem = new MenuItem(StartupHandler.DeceiveTitle)
{
Enabled = false
};
Expand Down Expand Up @@ -105,7 +93,7 @@ private void SetupMenuItems()
{
var result = MessageBox.Show(
"Are you sure you want to stop Deceive? This will also stop League if it is running.",
MainClass.DeceiveTitle,
StartupHandler.DeceiveTitle,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1
Expand Down Expand Up @@ -249,7 +237,7 @@ private void UpdateStatus(string newStatus)
PossiblyRewriteAndResendPresence(lastPresence, newStatus);
_ws.Close();
Utils.SendStatusToLcu(newStatus);
if (enabled) _ws = Utils.MonitorChatStatusChange(newStatus);
_ws = Utils.MonitorChatStatusChange(newStatus, enabled);
}

private void LoadStatus()
Expand Down
4 changes: 2 additions & 2 deletions Deceive/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyVersion("1.6.1.0")]
[assembly: AssemblyFileVersion("1.6.1.0")]
4 changes: 2 additions & 2 deletions Deceive/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Deceive/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@
<value>..\Resources\deceive.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="DeceiveVersion" xml:space="preserve">
<value>v1.6.0</value>
<value>v1.6.1</value>
</data>
</root>
11 changes: 2 additions & 9 deletions Deceive/Program.cs → Deceive/StartupHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@

namespace Deceive
{
class MainClass
class StartupHandler
{
public static string DeceiveTitle
{
get
{
return "Deceive " + Resources.DeceiveVersion;
}
}
public static string DeceiveTitle => "Deceive " + Resources.DeceiveVersion;

[STAThread]
public static void Main(string[] args)
Expand Down Expand Up @@ -67,7 +61,6 @@ private static void StartDeceive()
}

// Step 0: Check for updates in the background.
// Intentionally not awaited.
Utils.CheckForUpdates();

// Step 1: Open a port for our proxy, so we can patch the port number into the system yaml.
Expand Down
22 changes: 15 additions & 7 deletions Deceive/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static string GetLCUPath()
// Notify that the path is invalid.
MessageBox.Show(
"Could not find the League client at " + path + ". Please select the location of 'LeagueClient.exe' manually.",
MainClass.DeceiveTitle,
StartupHandler.DeceiveTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation
);
Expand Down Expand Up @@ -127,9 +127,9 @@ public static string GetLCUPath()

/**
* Asynchronously checks if the current version of Deceive is the latest version. If not, and the user has
* not dismissed the message before, an alert is shwon.
* not dismissed the message before, an alert is shown.
*/
public static async Task CheckForUpdates()
public static async void CheckForUpdates()
{
try
{
Expand All @@ -156,7 +156,7 @@ public static async Task CheckForUpdates()

var result = MessageBox.Show(
$"There is a new version of Deceive available: {latestVersion}. You are currently using Deceive {Resources.DeceiveVersion}. Deceive updates usually fix critical bugs or adapt to changes by Riot, so it is recommended that you install the latest version.\n\nPress OK to visit the download page, or press Cancel to continue. Don't worry, we won't bother you with this message again if you press cancel.",
MainClass.DeceiveTitle,
StartupHandler.DeceiveTitle,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1
Expand Down Expand Up @@ -215,7 +215,7 @@ public static void InitPathWithRunningLCU()
{
var result = MessageBox.Show(
"League is currently running in admin mode. In order to proceed Deceive also needs to be elevated. Do you want Deceive to restart in admin mode?",
MainClass.DeceiveTitle,
StartupHandler.DeceiveTitle,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1
Expand Down Expand Up @@ -345,7 +345,7 @@ internal static void SendStatusToLcu(string status)
}
}

public static WebSocket MonitorChatStatusChange(string status)
public static WebSocket MonitorChatStatusChange(string status, bool enabled)
{
foreach (var process in Process.GetProcessesByName("LeagueClientUx"))
{
Expand All @@ -358,10 +358,18 @@ public static WebSocket MonitorChatStatusChange(string status)
ws.OnMessage += (s, e) =>
{
if (!e.IsText) return;
var json = (JsonArray) SimpleJson.DeserializeObject(e.Data);
if ((long) json[0] != 8) return;
var statusJson = (JsonObject)((JsonObject) json[2])[0];
if (!statusJson.ContainsKey("availability")) return;
var availability = (string) statusJson["availability"];
if (availability == "dnd" || availability == status || availability == "away") return;
Trace.WriteLine((string) statusJson["availability"]);
SendStatusToLcu(status);
if (!enabled) ws.Close();
};
ws.Connect();
ws.Send("[5, \"OnJsonApiEvent_lol-gameflow_v1_gameflow-phase\"]");
ws.Send("[5, \"OnJsonApiEvent_lol-chat_v1_me\"]");
return ws;
}

Expand Down

0 comments on commit 6a55c7d

Please sign in to comment.