-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30791ea
commit d99e9b2
Showing
21 changed files
with
1,145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28010.2046 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CyberDisc-RichPresence", "CyberDisc-RichPresence\CyberDisc-RichPresence.csproj", "{9528DEB3-FDD2-4EC0-BCAB-CA3B0117E681}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9528DEB3-FDD2-4EC0-BCAB-CA3B0117E681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9528DEB3-FDD2-4EC0-BCAB-CA3B0117E681}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9528DEB3-FDD2-4EC0-BCAB-CA3B0117E681}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9528DEB3-FDD2-4EC0-BCAB-CA3B0117E681}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {19E9C6BC-D1B2-41C9-A191-BB421FD7FA38} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | ||
</startup> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using System.Windows.Automation; | ||
using DiscordRPC; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace CyberDisc_RichPresence | ||
{ | ||
|
||
public class CDRichPresence : Form | ||
{ | ||
private NotifyIcon trayIcon; | ||
private IContainer components; | ||
public DiscordRpcClient client; | ||
|
||
public CDRichPresence() | ||
{ | ||
InitializeComponent(); | ||
Load += OnLoad; | ||
ContextMenu menu = new ContextMenu(); | ||
menu.MenuItems.Add(0, new MenuItem("Exit", new EventHandler(Exit_click))); | ||
trayIcon.ContextMenu = menu; | ||
} | ||
|
||
private void OnLoad(object sender, EventArgs e) | ||
{ | ||
Run(); | ||
} | ||
|
||
private async Task Run() | ||
{ | ||
await Task.Delay(10); | ||
Hide(); | ||
StartRichPresence(); | ||
trayIcon.ShowBalloonTip(1000); | ||
} | ||
|
||
private void OnResize(object sender, EventArgs e) | ||
{ | ||
if (WindowState == FormWindowState.Minimized) | ||
{ | ||
Hide(); | ||
} | ||
} | ||
|
||
private void Exit_click(object sender, EventArgs e) | ||
{ | ||
trayIcon.Dispose(); | ||
Environment.Exit(0); | ||
} | ||
|
||
public void StartRichPresence() | ||
{ | ||
client = new DiscordRpcClient("537710248664760322"); | ||
client.Initialize(); | ||
client.SetPresence(new RichPresence() | ||
{ | ||
Details = "Idle", | ||
//State = "Idle", | ||
Assets = new Assets() | ||
{ | ||
LargeImageKey = "cd-logo", | ||
LargeImageText = "Cyber Discovery", | ||
SmallImageKey = "cd-logo" | ||
} | ||
}); | ||
var timer = new System.Timers.Timer(150); | ||
timer.Elapsed += (sender, args) => { UpdateFromURL(); }; | ||
timer.Start(); | ||
} | ||
|
||
private void UpdateFromURL() | ||
{ | ||
client.Invoke(); | ||
string url = CurrentURL(); | ||
if (url == null || url == "") | ||
{ | ||
client.ClearPresence(); | ||
return; | ||
} | ||
if (url.Contains("game")) | ||
{ | ||
DoGameUpdate(url); | ||
return; | ||
} | ||
if (url.Contains("assess")) | ||
{ | ||
DoAssesUpdate(url); | ||
return; | ||
} | ||
if (url.Contains("essentials")) | ||
{ | ||
DoEssentialsUpdates(url); | ||
return; | ||
} | ||
if (url.Contains("elite")) | ||
{ | ||
DoEliteUpdates(url); | ||
return; | ||
} | ||
SetRP("Idle", "", "cd"); | ||
} | ||
|
||
private void DoEliteUpdates(string url) | ||
{ | ||
SetRP("Playing elite", "Wait what this isnt possible", "game"); | ||
} | ||
|
||
private void DoEssentialsUpdates(string url) | ||
{ | ||
SetRP("Playing essentials", "Coming soon", "game"); | ||
} | ||
|
||
private void DoAssesUpdate(string url) | ||
{ | ||
try | ||
{ | ||
string cdchal = url.Split('-')[1]; | ||
UpdateRP("", "", cdchal, "assess"); | ||
} | ||
catch | ||
{ | ||
SetRP("Idle", "", "assess"); | ||
return; | ||
} | ||
} | ||
|
||
private void DoGameUpdate(string url) | ||
{ | ||
try | ||
{ | ||
string cdbase; | ||
string cdlevel; | ||
string cdchal; | ||
string[] args = url.Split('?')[1].Split('&'); | ||
cdbase = args.Where(s => s.Contains("base")).FirstOrDefault().Split('=')[1]; | ||
cdlevel = args.Where(s => s.Contains("level")).FirstOrDefault().Split('=')[1]; | ||
cdchal = args.Where(s => s.Contains("challenge")).FirstOrDefault().Split('=')[1]; | ||
UpdateRP(cdbase, cdlevel, cdchal, "game"); | ||
} | ||
catch | ||
{ | ||
SetRP("Idle", "", "game"); | ||
return; | ||
} | ||
} | ||
|
||
private void UpdateRP(string cdbase, string cdlevel, string cdchal, string cdstage) | ||
{ | ||
string leveltext = ""; | ||
switch (cdbase) | ||
{ | ||
case "1": | ||
leveltext = "On HQ L" + cdlevel + "C" + cdchal; | ||
break; | ||
case "2": | ||
leveltext = "On Moon L" + cdlevel + "C" + cdchal; | ||
break; | ||
case "3": | ||
leveltext = "On Forensics L" + cdlevel + "C" + cdchal; | ||
break; | ||
} | ||
if (cdstage == "assess") leveltext = "On challenge " + cdchal; | ||
SetRP("Playing " + cdstage, leveltext, cdstage); | ||
} | ||
|
||
private string CurrentURL() | ||
{ | ||
List<string> urls = new List<string>(); | ||
Process[] procsChrome = Process.GetProcessesByName("chrome"); | ||
foreach (Process chrome in procsChrome) | ||
{ | ||
if (chrome.MainWindowHandle == IntPtr.Zero) continue; | ||
|
||
AutomationElement element = AutomationElement.FromHandle(chrome.MainWindowHandle); | ||
if (element == null) | ||
return null; | ||
Condition conditions = new AndCondition( | ||
new PropertyCondition(AutomationElement.ProcessIdProperty, chrome.Id), | ||
new PropertyCondition(AutomationElement.IsControlElementProperty, true), | ||
new PropertyCondition(AutomationElement.IsContentElementProperty, true), | ||
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); | ||
|
||
AutomationElement elementx = element.FindFirst(TreeScope.Descendants, conditions); | ||
if (elementx == null) continue; | ||
urls.Add(((ValuePattern)elementx.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string); | ||
} | ||
return urls.Where(s => s.Contains("joincyberdiscovery")).FirstOrDefault(); | ||
} | ||
|
||
private void SetRP(string baseText, string challengeText, string icon) | ||
{ | ||
client.SetPresence(new RichPresence() | ||
{ | ||
Details = baseText, | ||
State = challengeText, | ||
Assets = new Assets() | ||
{ | ||
LargeImageKey = "cd-logo", | ||
LargeImageText = "Cyber Discovery", | ||
SmallImageKey = icon | ||
} | ||
}); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
components = new Container(); | ||
ComponentResourceManager resources = new ComponentResourceManager(typeof(CDRichPresence)); | ||
trayIcon = new NotifyIcon(this.components); | ||
SuspendLayout(); | ||
trayIcon.BalloonTipIcon = ToolTipIcon.Info; | ||
trayIcon.BalloonTipText = "Rich presence is running, right click to interact"; | ||
trayIcon.BalloonTipTitle = "CyberDiscovery Rich Presence"; | ||
trayIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("trayIcon.Icon"))); | ||
trayIcon.Text = "CyberDiscovery Rich Presence"; | ||
trayIcon.Visible = true; | ||
ClientSize = new System.Drawing.Size(120, 0); | ||
Name = "CDRichPresence"; | ||
ResumeLayout(false); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.