Skip to content

Commit

Permalink
Update 1.8.0 (#50)
Browse files Browse the repository at this point in the history
* Using a real XmlWriter fixes player unable to join MUC lobby

Bumped version to 1.7.1
Added some Debug output, changed Console to Trace for release mode as we have no console

* change localhost to 127.0.0.1 to fix ::1 being unreachable

* Add tray menu item to disable overlay and to stop connecting to MUC

* fix update prompt showing for newer Deceive builds

remove version string from Resources and get from assembly info

* log Debug/Trace output to file, add more Debug info

* add support for VALORANT

* bump to 1.8.0, update packages, cleanup code

check for LoR and VALORANT processes
kill Deceive when Riot Client has exited

* fix League+ status

* fix crash when Deceive starting up faster than LCUx

* add command line flag "no-overlay" to disable overlay
  • Loading branch information
aPinat committed Apr 18, 2020
1 parent 0bbc2f1 commit 91aaa44
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 102 deletions.
10 changes: 6 additions & 4 deletions Deceive/ConfigProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class ConfigProxy
internal int ConfigPort { get; }

internal event EventHandler<ChatServerEventArgs> PatchedChatServer;

internal class ChatServerEventArgs : EventArgs
{
internal string ChatHost { get; set; }
Expand All @@ -41,7 +41,7 @@ internal ConfigProxy(string configUrl, int chatPort)

// Start a web server that sends everything to ProxyAndRewriteResponse
var server = new WebServer(o => o
.WithUrlPrefix("http://localhost:" + port)
.WithUrlPrefix("http://127.0.0.1:" + port)
.WithMode(HttpListenerMode.EmbedIO))
.WithModule(new ActionModule("/", HttpVerbs.Get,
ctx => ProxyAndRewriteResponse(configUrl, chatPort, ctx)));
Expand Down Expand Up @@ -82,6 +82,7 @@ private async Task ProxyAndRewriteResponse(string configUrl, int chatPort, IHttp
var result = await _client.SendAsync(message);
var content = await result.Content.ReadAsStringAsync();
var modifiedContent = content;
Debug.WriteLine(content);

try
{
Expand Down Expand Up @@ -121,8 +122,9 @@ private async Task ProxyAndRewriteResponse(string configUrl, int chatPort, IHttp
}

modifiedContent = SimpleJson.SerializeObject(configObject);

if (riotChatHost != null && riotChatPort != 0) {

if (riotChatHost != null && riotChatPort != 0)
{
PatchedChatServer?.Invoke(this, new ChatServerEventArgs {ChatHost = riotChatHost, ChatPort = riotChatPort});
}
}
Expand Down
20 changes: 10 additions & 10 deletions Deceive/Deceive.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Costura.Fody.3.3.3\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.3.3.3\build\Costura.Fody.props')" />
<Import Project="..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -45,19 +45,19 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d">
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d">
<HintPath>..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EmbedIO, Version=3.3.3.0, Culture=neutral, PublicKeyToken=5e5f048b6e04267e">
<HintPath>..\packages\EmbedIO.3.3.3\lib\netstandard2.0\EmbedIO.dll</HintPath>
<Reference Include="EmbedIO, Version=3.4.3.0, Culture=neutral, PublicKeyToken=5e5f048b6e04267e">
<HintPath>..\packages\EmbedIO.3.4.3\lib\netstandard2.0\EmbedIO.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Swan.Lite, Version=2.6.1.0, Culture=neutral, PublicKeyToken=30c707c872729fff">
<HintPath>..\packages\Unosquare.Swan.Lite.2.6.1\lib\net461\Swan.Lite.dll</HintPath>
<Reference Include="Swan.Lite, Version=3.0.0.0, Culture=neutral, PublicKeyToken=30c707c872729fff">
<HintPath>..\packages\Unosquare.Swan.Lite.3.0.0\lib\net461\Swan.Lite.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -116,12 +116,12 @@
<EmbeddedResource Include="Resources\deceive.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.4.0.2\build\Fody.targets" Condition="Exists('..\packages\Fody.4.0.2\build\Fody.targets')" />
<Import Project="..\packages\Fody.6.1.1\build\Fody.targets" Condition="Exists('..\packages\Fody.6.1.1\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.4.0.2\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.4.0.2\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.3.3.3\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.3.3.3\build\Costura.Fody.props'))" />
<Error Condition="!Exists('..\packages\Fody.6.1.1\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.1.1\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props'))" />
</Target>
</Project>
20 changes: 11 additions & 9 deletions Deceive/LCUOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ public sealed class LCUOverlay : Window

private static readonly Brush OfflineMobileColor = new SolidColorBrush(Color.FromRgb(137, 141, 127));
private static readonly Brush InactiveColor = new SolidColorBrush(Colors.LimeGreen);

// 1920x1080 sizes.
private static readonly Rect HugeBackgroundRect = new Rect(1692, 72, 180, 41);
private static readonly Point HugeTextOrigin = new Point(1697, 75);
private static readonly double HugeFontSize = 18.0;

// 1600x900 sizes.
private static readonly Rect LargeBackgroundRect = new Rect(1412, 57, 147, 33);
private static readonly Point LargeTextOrigin = new Point(1414, 60);
private static readonly double LargeFontSize = 16.0;

// 1280x720 sizes.
private static readonly Rect MediumBackgroundRect = new Rect(1129, 46, 121, 28);
private static readonly Point MediumTextOrigin = new Point(1130, 48);
private static readonly double MediumFontSize = 12.0;

// 1024x576 sizes.
private static readonly Rect SmallBackgroundRect = new Rect(904, 38, 93, 19);
private static readonly Point SmallTextOrigin = new Point(903, 38);
Expand All @@ -42,7 +42,7 @@ public sealed class LCUOverlay : Window
private Canvas _canvas;
private Label _textLabel;
private Canvas _background;

public LCUOverlay()
{
// Set up main window.
Expand Down Expand Up @@ -87,7 +87,7 @@ public void UpdateStatus(string status, bool enabled)
{
var content = "";
var color = OfflineMobileColor;

if (!enabled)
{
content = "Online (No Deceive)";
Expand Down Expand Up @@ -120,7 +120,8 @@ protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
_background.Height = HugeBackgroundRect.Height;
Canvas.SetLeft(_background, HugeBackgroundRect.X);
Canvas.SetTop(_background, HugeBackgroundRect.Y);
} else if (Width == 1600 && Height == 900)
}
else if (Width == 1600 && Height == 900)
{
// Large
_textLabel.FontSize = LargeFontSize;
Expand All @@ -131,7 +132,8 @@ protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
_background.Height = LargeBackgroundRect.Height;
Canvas.SetLeft(_background, LargeBackgroundRect.X);
Canvas.SetTop(_background, LargeBackgroundRect.Y);
} else if (Width == 1280 && Height == 720)
}
else if (Width == 1280 && Height == 720)
{
// Medium
_textLabel.FontSize = MediumFontSize;
Expand Down Expand Up @@ -160,7 +162,7 @@ protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);

this.MakeWindowTransparent();
}
}
Expand Down
133 changes: 104 additions & 29 deletions Deceive/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Net.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using Deceive.Properties;

Expand All @@ -17,15 +19,16 @@ internal class MainController : ApplicationContext
private bool _enabled = true;
private string _status;
private readonly string _statusFile = Path.Combine(Utils.DataDir, "status");

private bool _connectToMuc = true;

private LCUOverlay _overlay = null;
private WindowFollower _follower = null;

private SslStream _incoming;
private SslStream _outgoing;
private string _lastPresence; // we resend this if the state changes

internal MainController(bool isLeague)
internal MainController(bool createOverlay)
{
_trayIcon = new NotifyIcon
{
Expand All @@ -37,18 +40,29 @@ internal MainController(bool isLeague)
_trayIcon.ShowBalloonTip(5000);

// Create overlay and start following the LCU with it.
if (isLeague)
if (createOverlay) CreateOverlay();

LoadStatus();
UpdateUI();
}

private async void CreateOverlay()
{
while (true)
{
var process = Process.GetProcessesByName("LeagueClientUx").First();

var process = Process.GetProcessesByName("LeagueClientUx").FirstOrDefault();
if (process == null)
{
await Task.Delay(5000);
continue;
}

_overlay = new LCUOverlay();
_overlay.Show();
_follower = new WindowFollower(_overlay, process);
_follower.StartFollowing();
return;
}

LoadStatus();
UpdateUI();
}

private void UpdateUI()
Expand All @@ -68,6 +82,34 @@ private void UpdateUI()
Checked = _enabled
};

var overlayMenuItem = new MenuItem("Show status overlay", (a, e) =>
{
if (_overlay == null)
{
CreateOverlay();
}
else
{
_follower.Dispose();
_overlay.Close();
_overlay = null;
}
UpdateUI();
})
{
Checked = _overlay != null
};

var mucMenuItem = new MenuItem("Enable lobby chat", (a, e) =>
{
_connectToMuc = !_connectToMuc;
UpdateUI();
})
{
Checked = _connectToMuc
};

var offlineStatus = new MenuItem("Offline", (a, e) =>
{
UpdateStatus(_status = "offline");
Expand Down Expand Up @@ -107,7 +149,7 @@ private void UpdateUI()
Application.Exit();
});

_trayIcon.ContextMenu = new ContextMenu(new[] {aboutMenuItem, enabledMenuItem, typeMenuItem, quitMenuItem});
_trayIcon.ContextMenu = new ContextMenu(new[] {aboutMenuItem, enabledMenuItem, typeMenuItem, overlayMenuItem, mucMenuItem, quitMenuItem});
_overlay?.UpdateStatus(_status, _enabled);
}

Expand All @@ -132,6 +174,8 @@ private void IncomingLoop()
byteCount = _incoming.Read(bytes, 0, bytes.Length);

var content = Encoding.UTF8.GetString(bytes, 0, byteCount);
Debug.WriteLine("FROM RC: " + content);

// If this is possibly a presence stanza, rewrite it.
if (content.Contains("<presence") && _enabled)
{
Expand All @@ -143,9 +187,13 @@ private void IncomingLoop()
}
} while (byteCount != 0);
}
catch (Exception e)
{
Trace.WriteLine(e);
}
finally
{
Console.WriteLine(@"Incoming closed.");
Trace.WriteLine(@"Incoming closed.");
SaveStatus();
Application.Exit();
}
Expand All @@ -161,14 +209,16 @@ private void OutgoingLoop()
do
{
byteCount = _outgoing.Read(bytes, 0, bytes.Length);
Debug.WriteLine("TO RC: " + Encoding.UTF8.GetString(bytes, 0, byteCount));
_incoming.Write(bytes, 0, byteCount);
} while (byteCount != 0);

Console.WriteLine(@"Outgoing closed.");
Trace.WriteLine(@"Outgoing closed.");
}
catch
catch (Exception e)
{
Console.WriteLine(@"Outgoing errored.");
Trace.WriteLine(e);
Trace.WriteLine(@"Outgoing errored.");
SaveStatus();
Application.Exit();
}
Expand All @@ -183,32 +233,57 @@ private void PossiblyRewriteAndResendPresence(string content, string targetStatu
var xml = XDocument.Load(new StringReader(wrappedContent));

if (xml.Root == null) return;

if (xml.Root.HasElements == false) return;

foreach (var presence in xml.Root.Elements())
{
Console.WriteLine(presence);
if (presence.Name != "presence") continue;
if (presence.Attribute("to") != null) continue;

presence.Element("show").Value = targetStatus;
if (presence.Name != "presence") continue;
if (presence.Attribute("to") != null)
{
if (_connectToMuc) continue;
presence.Remove();
}

presence.Element("show")?.ReplaceNodes(targetStatus);

if (targetStatus == "chat") continue;
presence.Element("status")?.Remove();
presence.Element("games")?.Element("league_of_legends")?.Remove();

if (targetStatus == "mobile")
{
presence.Element("games")?.Element("league_of_legends")?.Element("p")?.Remove();
presence.Element("games")?.Element("league_of_legends")?.Element("m")?.Remove();
presence.Element("games")?.Element("league_of_legends")?.Element("st")?.ReplaceNodes(targetStatus);
}
else
{
presence.Element("games")?.Element("league_of_legends")?.Remove();
}

//Remove Legends of Runeterra presence
presence.Element("games")?.Element("bacon")?.Remove();

//Remove VALORANT presence
presence.Element("games")?.Element("valorant")?.Remove();
}

var xmlOut = string.Join("", xml.Root.Elements().Select(o => o.ToString()));
_outgoing.Write(Encoding.UTF8.GetBytes(xmlOut));
Console.WriteLine(xmlOut);

var sb = new StringBuilder();
var xws = new XmlWriterSettings {OmitXmlDeclaration = true, Encoding = Encoding.UTF8, ConformanceLevel = ConformanceLevel.Fragment};
using (var xw = XmlWriter.Create(sb, xws))
{
foreach (var xElement in xml.Root.Elements())
{
xElement.WriteTo(xw);
}
}

_outgoing.Write(Encoding.UTF8.GetBytes(sb.ToString()));
Debug.WriteLine("DECEIVE: " + sb);
}
catch
catch (Exception e)
{
Console.WriteLine(@"Error rewriting presence.");
//Don't send raw value.
//_outgoing.Write(Encoding.UTF8.GetBytes(content));
Trace.WriteLine(e);
Trace.WriteLine(@"Error rewriting presence.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions Deceive/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,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.7.0.0")]
[assembly: AssemblyFileVersion("1.7.0.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
Loading

0 comments on commit 91aaa44

Please sign in to comment.