added integrated CSGO DiscordRPC
This commit is contained in:
parent
b3def6bc6c
commit
5d14cdd185
8 changed files with 232 additions and 6 deletions
|
@ -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"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<bool> settings_alwaysOnTop = new UpdateVar<bool>();
|
||||
public static UpdateVar<bool> settings_osxStyleControlls = new UpdateVar<bool>();
|
||||
|
||||
|
@ -37,9 +38,10 @@ namespace WeeXnes.Core
|
|||
public static UpdateVar<bool> settings_RpcShowElapsedTime = new UpdateVar<bool>();
|
||||
public static UpdateVar<string> settings_RpcDefaultClientID = new UpdateVar<string>();
|
||||
public static UpdateVar<bool> settings_RpcAutoStart = new UpdateVar<bool>();
|
||||
|
||||
|
||||
|
||||
public static UpdateVar<bool> settings_builtInCSGORpc = new UpdateVar<bool>();
|
||||
public static GameStateListener gameStateListener = new GameStateListener(4169);
|
||||
|
||||
|
||||
|
||||
public static UpdateVar<string> searchbox_content = new UpdateVar<string>();
|
||||
}
|
||||
|
@ -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));
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -120,6 +120,23 @@
|
|||
VerticalAlignment="Center"
|
||||
FontSize="15"
|
||||
Foreground="White"/>
|
||||
|
||||
|
||||
</CheckBox>
|
||||
|
||||
<CheckBox VerticalAlignment="Top"
|
||||
VerticalContentAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Name="EnableBuiltInCSGO"
|
||||
Checked="EnableBuiltInCSGO_OnChecked"
|
||||
Unchecked="EnableBuiltInCSGO_OnUnchecked"
|
||||
Margin="10,10,0,0">
|
||||
<TextBlock
|
||||
Text="Enable Built in CSGO DiscordRPC"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="15"
|
||||
Foreground="White"/>
|
||||
|
||||
|
||||
</CheckBox>
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
172
WeeXnes/RPC/CSGO.cs
Normal file
172
WeeXnes/RPC/CSGO.cs
Normal file
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,6 +35,9 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CSGSI, Version=1.3.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\CSGSI.1.3.1\lib\CSGSI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DiscordRPC, Version=1.0.175.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DiscordRichPresence.1.0.175\lib\net35\DiscordRPC.dll</HintPath>
|
||||
</Reference>
|
||||
|
@ -64,6 +67,7 @@
|
|||
<Compile Include="Misc\UpdateMessage.xaml.cs">
|
||||
<DependentUpon>UpdateMessage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="RPC\CSGO.cs" />
|
||||
<Compile Include="RPC\Game.cs" />
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CSGSI" version="1.3.1" targetFramework="net48" />
|
||||
<package id="DiscordRichPresence" version="1.0.175" targetFramework="net48" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net48" />
|
||||
</packages>
|
Loading…
Add table
Reference in a new issue