Skip to content

Commit

Permalink
untested LCU implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
frostycpu committed Oct 1, 2017
1 parent 88725d9 commit 6a74cbe
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 41 deletions.
8 changes: 4 additions & 4 deletions CallLcds/CallLcds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="rtmp-sharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\rtmp-sharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
Expand All @@ -94,6 +90,10 @@
<Project>{4516f4a5-7594-402c-b0d8-2dd6f80ec8ea}</Project>
<Name>FinalesFunkeln</Name>
</ProjectReference>
<ProjectReference Include="..\lib\rtmp-sharp\rtmp-sharp\rtmp-sharp.csproj">
<Project>{aa1a4f5d-3bd4-4832-9f5d-90727007727e}</Project>
<Name>rtmp-sharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="CallLcdsUi.xaml">
Expand Down
4 changes: 4 additions & 0 deletions FinalesFunkeln/FinalesFunkeln.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\Xceed.Wpf.AvalonDock.dll</HintPath>
</Reference>
<Reference Include="YamlDotNet, Version=4.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.4.2.2\lib\net35\YamlDotNet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
Expand Down Expand Up @@ -147,6 +150,7 @@
<Compile Include="Extensibility\Ui\WindowInfo.cs" />
<Compile Include="IO\PropertiesFile.cs" />
<Compile Include="IO\RiotSerializationContext.cs" />
<Compile Include="IO\YamlFile.cs" />
<Compile Include="Lol\LolClient.cs" />
<Compile Include="Lol\LolClientGameData.cs" />
<Compile Include="Lol\LolClientImages.cs" />
Expand Down
98 changes: 98 additions & 0 deletions FinalesFunkeln/IO/YamlFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization;

namespace FinalesFunkeln.IO
{
public class YamlFile : DynamicObject, IDynamicMetaObjectProvider,IEnumerable<KeyValuePair<string,object>>
{
Dictionary<string, object> _backingDict = new Dictionary<string, object>();
string _fileName;
bool _readOnly;
public YamlFile(string fileName, bool autoInit = true, bool readOnly = false)
{
if (string.IsNullOrEmpty(fileName))
throw new ArgumentNullException("fileName");
_fileName = fileName;
_readOnly = readOnly;
if (autoInit)
Read();
}

public void Read()
{
using (var x = new FileStream(_fileName, FileMode.Open))
{
var des = new Deserializer();
var dict = des.Deserialize<Dictionary<string,object>>(new StreamReader(x));
foreach(var entry in dict)
{
this[entry.Key] = entry.Value;
}
}


}
public void Write()
{
throw new NotImplementedException();
}

public bool GetBoolean(string key)
{
return Convert.ToBoolean(this[key]);
}

public Int32 GetInt32(string key)
{
return Convert.ToInt32(this[key]);
}

public double GetDouble(string key)
{
return Convert.ToDouble(this[key]);
}

public string GetString(string key)
{
return (string)this[key];
}

public object this[string key]
{
get { return _backingDict[key]; }
set { if (_readOnly) throw new InvalidOperationException("Cannot change a value because it's set to read-only"); else _backingDict[key] = value; }
}

public override IEnumerable<string> GetDynamicMemberNames()
{
return _backingDict.Keys;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result= this[binder.Name];
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
_backingDict[binder.Name] = value;
return true;
}

public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
return _backingDict.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return _backingDict.GetEnumerator();
}
}
}
8 changes: 4 additions & 4 deletions FinalesFunkeln/Lol/LolClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ public class LolClient

public LolClientGameData GameData { get; private set; }

public PropertiesFile Properties { get; private set; }
public YamlFile Properties { get; private set; }
public LolConnection Connection { get; private set; }

public ExtensionManager ExtensionManager { get; }

internal LolClient(string directory, PropertiesFile properties, LolProxy proxy, Process process, ExtensionManager extManager)
internal LolClient(string directory, YamlFile properties, LolProxy proxy, Process process, ExtensionManager extManager)
{
if (proxy == null)
throw new ArgumentNullException("proxy");
if(!Directory.Exists(directory))
throw new ArgumentException("directory");
GameData = new LolClientGameData(Path.Combine(directory, GameDataFile));
Images = new LolClientImages(directory, GameData);
//GameData = new LolClientGameData(Path.Combine(directory, GameDataFile));
//Images = new LolClientImages(directory, GameData);
Connection=new LolConnection(proxy, extManager);
Process = process;
Properties = properties;
Expand Down
45 changes: 19 additions & 26 deletions FinalesFunkeln/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ partial class MainWindow
const string InternalConfigDir = "config/internal/";
const string LayoutConfigFilename = "Layout.cbf";
const string DefaultLayoutDefinition = "FinalesFunkeln.Resources.Config.Layout.cbf";
const string LolPropertiesFilename = "lol.properties";
const string LolPropertiesFilename = "system.yaml";
const string LcuSettingsFilename = "LeagueClientSettings.yaml";
const string LcuSettingsPath = "../../../../../../Config/";
const string CertFileName = "data/certs/{0}.p12";
const int RtmpPort = 2099;

Expand All @@ -51,7 +53,8 @@ partial class MainWindow
string _rtmpAddress;
X509Certificate2 _certificate;
ExtensionManager _extensionManager;
PropertiesFile _lolProperties;
YamlFile _lolProperties;
YamlFile _lcuSettings;
Process _lolClientProcess;
LolClient _lolClient;

Expand All @@ -69,12 +72,13 @@ private void Window_Initialized(object sender, EventArgs e)
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
if (!Directory.Exists("data") || !File.Exists("sqlite3.dll"))

if (!Directory.Exists("data"))
{
MessageBox.Show(Debugger.IsAttached ? @"""data"" folder and/or sqlite3.dll not found. Make sure to copy the data folder and sqlite3.dll to the output directory." : "Some files are missing, please reinstall.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(-1);
}

if (!Debugger.IsAttached)
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
_uiManager = new UiManager();
Expand Down Expand Up @@ -212,38 +216,24 @@ void ProcessInjector_ProcessFound(object sender, Process e)
{
ProcessInjector pi = sender as ProcessInjector;
if (pi == null) return;

#if !LCU //The new lol client has a separate process for the UI
//sometimes it takes a while for the main module to be loaded...
while (e.MainWindowHandle == IntPtr.Zero)
#endif

Thread.Sleep(1000);
string loldir = null;
try
{
#if AIRDEBUG && DEBUG
string wmiQuery = string.Format("select CommandLine from Win32_Process where Name='{0}'", "adl.exe");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();
foreach (ManagementObject retObject in retObjectCollection)
loldir = ProcessHelper.SplitCommandLineArgs((string)retObject["CommandLine"])[2];
#elif LCU
loldir = Path.GetDirectoryName(e.MainModule.FileName) ?? string.Empty;
loldir = Path.Combine(loldir, @"../../../../lol_air_client/releases/0.0.4.147/deploy");
//TODO this directory is just a placeholder
#else
loldir = Path.GetDirectoryName(e.MainModule.FileName) ?? string.Empty;
#endif
}
catch (Win32Exception)
{
MessageBox.Show("Cannot access the lolclient process. If this error persists try runnig as an administrator.","Error");
return;

}
_lolProperties = new PropertiesFile(Path.Combine(loldir, LolPropertiesFilename));
var host = _lolProperties["host"];
_rtmpAddress = host.Contains(",") ? host.Substring(0, host.IndexOf(',')) : host;

_lolProperties = new YamlFile(Path.Combine(loldir, LolPropertiesFilename));
_lcuSettings = new YamlFile(Path.Combine(loldir, LcuSettingsPath, LcuSettingsFilename));
//string host = ((dynamic)_lolProperties)["region_data"][((dynamic)_lcuSettings)["install"]["globals"]["region"]]["servers"]["lcds"]["lcds_host"];
_rtmpAddress = ((dynamic)_lolProperties)["region_data"][((dynamic)_lcuSettings)["install"]["globals"]["region"]]["servers"]["lcds"]["lcds_host"];

if (_rtmpAddress == null) return;

Expand Down Expand Up @@ -296,7 +286,10 @@ void InitProxy()
#if !LCU
_proxy = new LolProxy(new IPEndPoint(IPAddress.Loopback, RtmpPort), new Uri(string.Format("rtmps://{0}:{1}", _rtmpAddress, RtmpPort)), _serializationContext, _certificate);
#else
_proxy = new LolProxy(new IPEndPoint(IPAddress.Loopback, RtmpPort), new Uri(string.Format("rtmps://{0}:{1}", _rtmpAddress, RtmpPort)), _serializationContext,_certificate);
//CEF does not allow self-signed certs so we have to disable TLS for the new client
//(locally only, TLS will still be used to communicate with the actual server)
//TLS can be disabled for the client in <clientdeploypath>/system.yaml
_proxy = new LolProxy(new IPEndPoint(IPAddress.Loopback, RtmpPort), new Uri(string.Format("rtmps://{0}:{1}", _rtmpAddress, RtmpPort)), _serializationContext);
#endif

_proxy.AcknowledgeMessageReceived += OnAckMessageReceived;
Expand Down Expand Up @@ -394,7 +387,7 @@ void pi_Injected(object sender, EventArgs e)
{
Dispatcher.Invoke(DispatcherPriority.Input, new ThreadStart(() =>
{
Title = "Finales Funkeln - Injected [" + _lolProperties["platformId"] + "]";
Title = "Finales Funkeln - Injected [" + ((dynamic)_lcuSettings)["install"]["globals"]["region"] + "]";
}));
}

Expand Down
2 changes: 1 addition & 1 deletion FinalesFunkeln/RiotObjects/BroadcastNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace FinalesFunkeln.RiotObjects
{
[Serializable]
[SerializedName("com.riotgames.platform.broadcast.BroadcastNotification")]
//[SerializedName("com.riotgames.platform.broadcast.BroadcastNotification")]
public class BroadcastNotification : ExternalizableJsonObject
{
public BroadcastNotification():base("com.riotgames.platform.broadcast.BroadcastNotification") { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace FinalesFunkeln.RiotObjects
{
[Serializable]
[SerializedName("com.riotgames.platform.systemstate.ClientSystemStatesNotification")]
//[SerializedName("com.riotgames.platform.systemstate.ClientSystemStatesNotification")]
public class ClientSystemStatesNotification : ExternalizableJsonObject
{
public ClientSystemStatesNotification():base("com.riotgames.platform.systemstate.ClientSystemStatesNotification") { }
Expand Down
13 changes: 9 additions & 4 deletions FinalesFunkeln/Util/ProcessInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ namespace FinalesFunkeln.Util
{
class ProcessInjector:IDisposable
{
readonly byte[] _connectCc =
{
0x55, //PUSH EBP
#if LCU
const string CONNECT_FUNCTION = "WSAConnect";
#else
const string CONNECT_FUNCTION = "connect";
#endif
readonly byte[] _connectCc =
{
0x55, //PUSH EBP
0x8B, 0xEC, //MOV EBP, ESP
0x60, //PUSHAD
0x8B, 0x45, 0x0C, //MOV EAX, [EBP+C]
Expand Down Expand Up @@ -117,7 +122,7 @@ internal void Inject()
int jmpaddrloc = connect.Length - 4;

var mod = ProcessMemory.GetModule("ws2_32.dll");
Int32 reladdr = notemem.GetAddress(mod, "connect");
Int32 reladdr = notemem.GetAddress(mod, CONNECT_FUNCTION);
reladdr -= mod;

var lolmod = GetModuleAddress(CurrentProcess, mem, "ws2_32.dll");
Expand Down
1 change: 1 addition & 0 deletions FinalesFunkeln/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="sqlite-net" version="1.0.8" targetFramework="net45" userInstalled="true" />
<package id="YamlDotNet" version="4.2.2" targetFramework="net45" />
</packages>
1 change: 1 addition & 0 deletions lib/rtmpsharpgit/rtmp-sharp
Submodule rtmp-sharp added at 43b8eb

0 comments on commit 6a74cbe

Please sign in to comment.