diff --git a/Release_Tool/Program.cs b/Release_Tool/Program.cs index 5184a85..8f979ac 100644 --- a/Release_Tool/Program.cs +++ b/Release_Tool/Program.cs @@ -126,8 +126,10 @@ namespace Release_Tool files.Add(new file(@"WeeXnes_UAC\bin\Release\WeeXnes_UAC.exe", "WeeXnes_UAC.exe")); files.Add(new file(@"WeeXnes\bin\Release\DiscordRPC.dll", "DiscordRPC.dll")); files.Add(new file(@"WeeXnes\bin\Release\Newtonsoft.Json.dll", "Newtonsoft.Json.dll")); + files.Add(new file(@"WeeXnes\bin\Release\CSGSI.dll", "CSGSI.dll")); files.Add(new file(@"Autostart\bin\Release\Autostart.exe", "Autostart.exe")); files.Add(new file(@"Update\bin\Release\Update.exe", "Update.exe")); + } } } \ No newline at end of file diff --git a/WeeXnes/Core/Globals.cs b/WeeXnes/Core/Globals.cs index bb49822..c470682 100644 --- a/WeeXnes/Core/Globals.cs +++ b/WeeXnes/Core/Globals.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using CSGSI; using Nocksoft.IO.ConfigFiles; namespace WeeXnes.Core @@ -15,11 +16,11 @@ namespace WeeXnes.Core public static string encryptionKey = "8zf5#RdyQ]$4x4_"; public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeeXnes"); public static string SettingsFileName = "settings.ini"; - public static string version = "3.3"; + public static string version = "3.4"; public static bool info_isRpcRunning = false; public static bool info_RpcAutoStart; public static string apiUrl = "http://www.weexnes.com:5169/"; - + public static UpdateVar settings_alwaysOnTop = new UpdateVar(); public static UpdateVar settings_osxStyleControlls = new UpdateVar(); @@ -37,9 +38,10 @@ namespace WeeXnes.Core public static UpdateVar settings_RpcShowElapsedTime = new UpdateVar(); public static UpdateVar settings_RpcDefaultClientID = new UpdateVar(); public static UpdateVar settings_RpcAutoStart = new UpdateVar(); - - - + public static UpdateVar settings_builtInCSGORpc = new UpdateVar(); + public static GameStateListener gameStateListener = new GameStateListener(4169); + + public static UpdateVar searchbox_content = new UpdateVar(); } @@ -95,6 +97,8 @@ namespace WeeXnes.Core Globals.settings_RpcDefaultClientID.Value = "605116707035676701"; } + Globals.settings_builtInCSGORpc.Value = Convert.ToBoolean(SettingsFile.GetValue("rpc", "csgoPresence")); + } @@ -182,6 +186,10 @@ namespace WeeXnes.Core { SettingsFile.SetValue("rpc","RpcAutoStart", Convert.ToString(Globals.settings_RpcAutoStart.Value)); }; + Globals.settings_builtInCSGORpc.ValueChanged += () => + { + SettingsFile.SetValue("rpc","csgoPresence", Convert.ToString(Globals.settings_RpcAutoStart.Value)); + }; } } diff --git a/WeeXnes/MVVM/View/DiscordRpcView.xaml.cs b/WeeXnes/MVVM/View/DiscordRpcView.xaml.cs index 2b323a3..edc2d5d 100644 --- a/WeeXnes/MVVM/View/DiscordRpcView.xaml.cs +++ b/WeeXnes/MVVM/View/DiscordRpcView.xaml.cs @@ -20,6 +20,7 @@ using System.Windows.Navigation; using System.Windows.Shapes; using WeeXnes.Core; using WeeXnes.RPC; +using WeeXnes.RPC.CSGO; namespace WeeXnes.MVVM.View { @@ -101,6 +102,7 @@ namespace WeeXnes.MVVM.View private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { + CSGORPC csrpc = new CSGORPC("777202324145438812"); Globals.info_isRpcRunning = true; writeLog(new customEvent("Thread Started", EventType.ProcessStartedEvent)); bool runWorker = true; @@ -116,12 +118,18 @@ namespace WeeXnes.MVVM.View { game.stop(); } + csrpc.stop(); } Process[] processes = Process.GetProcesses(); foreach (Game game in Games) { game.checkState(processes); } + + if (Globals.settings_builtInCSGORpc.Value) + { + csrpc.checkState(processes); + } Thread.Sleep(delay); } } @@ -315,7 +323,6 @@ namespace WeeXnes.MVVM.View private void UserControl_Unloaded(object sender, RoutedEventArgs e) { stopBackgroundWorker(); - } private void ListViewVersions_OnLoaded(object sender, RoutedEventArgs e) diff --git a/WeeXnes/MVVM/View/SettingView.xaml b/WeeXnes/MVVM/View/SettingView.xaml index 7c2e162..a4b5c13 100644 --- a/WeeXnes/MVVM/View/SettingView.xaml +++ b/WeeXnes/MVVM/View/SettingView.xaml @@ -120,6 +120,23 @@ VerticalAlignment="Center" FontSize="15" Foreground="White"/> + + + + + + + diff --git a/WeeXnes/MVVM/View/SettingView.xaml.cs b/WeeXnes/MVVM/View/SettingView.xaml.cs index 181313b..3c8ba48 100644 --- a/WeeXnes/MVVM/View/SettingView.xaml.cs +++ b/WeeXnes/MVVM/View/SettingView.xaml.cs @@ -91,6 +91,11 @@ namespace WeeXnes.MVVM.View CensorKeysSwitch.IsChecked = true; } + if (Globals.settings_builtInCSGORpc.Value) + { + EnableBuiltInCSGO.IsChecked = true; + } + tb_DefaultClientID.Text = Globals.settings_RpcDefaultClientID.Value; } private void SetUiUpdateListeners() @@ -340,5 +345,15 @@ namespace WeeXnes.MVVM.View { Globals.settings_osxStyleControlls.Value = false; } + + private void EnableBuiltInCSGO_OnChecked(object sender, RoutedEventArgs e) + { + Globals.settings_builtInCSGORpc.Value = true; + } + + private void EnableBuiltInCSGO_OnUnchecked(object sender, RoutedEventArgs e) + { + Globals.settings_builtInCSGORpc.Value = false; + } } } diff --git a/WeeXnes/RPC/CSGO.cs b/WeeXnes/RPC/CSGO.cs new file mode 100644 index 0000000..d7f08cf --- /dev/null +++ b/WeeXnes/RPC/CSGO.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CSGSI; +using CSGSI.Nodes; +using WeeXnes.Core; +using WeeXnes.MVVM.View; +using DiscordRPC; +using DiscordRPC.Message; +using EventType = WeeXnes.Core.EventType; + +namespace WeeXnes.RPC.CSGO +{ + class EventCache + { + public static string cache1 = ""; + } + + public class CSGORPC + { + + public DiscordRpcClient client { get; set; } + public string ProcessName { get; set; } + public bool isRunning { get; set; } + public CSGORPC(string ClientID) + { + this.ProcessName = "csgo"; + this.client = new DiscordRpcClient(ClientID); + Globals.gameStateListener.NewGameState += GameStateListenerOnNewGameState; + } + + private void GameStateListenerOnNewGameState(GameState gs) + { + + if (gs.Player.Activity == PlayerActivity.Menu) + { + this.client.UpdateLargeAsset("menu"); + this.client.UpdateDetails("In Menu"); + this.client.UpdateState(""); + } + else if (gs.Player.Activity == PlayerActivity.Playing) + { + this.client.UpdateLargeAsset(gs.Map.Name); + this.client.UpdateDetails("Playing on " + gs.Map.Name); + if (gs.Player.Team == PlayerTeam.T) + { + this.client.UpdateSmallAsset("t_logo"); + }else if(gs.Player.Team == PlayerTeam.CT) + { + this.client.UpdateSmallAsset("ct_logo"); + } + else + { + this.client.UpdateSmallAsset(""); + } + } + + } + + public void start() + { + + Globals.gameStateListener.Start(); + if (!client.IsInitialized) + { + client.Initialize(); + } + client.OnReady += ClientOnOnReady; + client.OnPresenceUpdate += ClientOnOnPresenceUpdate; + client.SetPresence(new RichPresence() + { + Details = "Playing CSGO", + State = "Launching Game...", + Assets = new Assets() + { + LargeImageKey = "menu", + LargeImageText = "", + SmallImageKey = "", + SmallImageText = "" + } + }); + if (Globals.settings_RpcShowElapsedTime.Value) + { + client.UpdateStartTime(); + } + } + + private void ClientOnOnPresenceUpdate(object sender, PresenceMessage args) + { + DiscordRpcView.logContent = new customEvent("[" + this.ProcessName + ".exe] ➜ Received Update on " + args.Name, EventType.RPCUpdateEvent); + DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog"; + } + + private void ClientOnOnReady(object sender, ReadyMessage args) + { + DiscordRpcView.logContent = new customEvent("[" + this.ProcessName + ".exe] ➜ Received Ready from user " + args.User.Username, EventType.RPCReadyEvent); + DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog"; + } + + public void stop() + { + + Globals.gameStateListener.Stop(); + + if (this.client.IsInitialized) + { + client.ClearPresence(); + client.OnReady -= ClientOnOnReady; + client.OnPresenceUpdate -= ClientOnOnPresenceUpdate; + } + } + public void checkState(Process[] processes) + { + if(!String.IsNullOrEmpty(this.ProcessName)) + { + bool foundProcess = false; + foreach (Process process in processes) + { + if (process.ProcessName == this.ProcessName) + { + foundProcess = true; + } + } + + if (!this.isRunning) + { + if (foundProcess) + { + //Do when Process is launched + //message.running(this.ProcessName); + start(); + + /* + Globals.logContent.Value = output; + Globals.logUpdateTrigger.Value = "mjfgoklemkgoeg"; + */ + DiscordRpcView.logContent = new customEvent("↪ " + "CSGO" + " [" + this.ProcessName + ".exe] started", EventType.ProcessStartedEvent); + DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog"; + this.isRunning = true; + } + } + if (this.isRunning) + { + if (!foundProcess) + { + //Do when Process is closed + //message.closed(this.ProcessName); + stop(); + /* + Globals.logContent.Value = output; + Globals.logUpdateTrigger.Value = "mjfgoklemkgoeg"; + */ + DiscordRpcView.logContent = new customEvent( "↩ " + "CSGO" + " [" + this.ProcessName + ".exe] closed", EventType.ProcessStoppedEvent); + DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog"; + + this.isRunning = false; + } + } + } + + + + } + public override string ToString() + { + return "CSGO"; + } + } +} diff --git a/WeeXnes/WeeXnes.csproj b/WeeXnes/WeeXnes.csproj index 94ffb11..3db30a8 100644 --- a/WeeXnes/WeeXnes.csproj +++ b/WeeXnes/WeeXnes.csproj @@ -35,6 +35,9 @@ 4 + + ..\packages\CSGSI.1.3.1\lib\CSGSI.dll + ..\packages\DiscordRichPresence.1.0.175\lib\net35\DiscordRPC.dll @@ -64,6 +67,7 @@ UpdateMessage.xaml + MSBuild:Compile diff --git a/WeeXnes/packages.config b/WeeXnes/packages.config index 4c05494..e6c23ab 100644 --- a/WeeXnes/packages.config +++ b/WeeXnes/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file