Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using DiscordRPC;
- using System;
- using System.Diagnostics;
- using System.Linq;
- using System.Runtime.InteropServices;
- namespace Chilong
- {
- class Program
- {
- private static DiscordRpcClient client;
- private static Process cdisplayex;
- private static string windowTitle;
- [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
- public const int WM_GETTEXT = 0x000D;
- public const int WM_GETTEXTLENGTH = 0x000E;
- [DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern int SendMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);
- [DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern int SendMessage(IntPtr hWnd, uint msg, int wParam, StringBuilder lParam);
- static void Main(string[] args)
- {
- Initialize();
- if (Process.GetProcesses().Where(x => x.ProcessName.StartsWith("CDisplayEx")).Count() == 0)
- return;
- while (true)
- {
- Update();
- if (Process.GetProcesses().Where(x => x.ProcessName.StartsWith("CDisplayEx")).Count() == 0)
- {
- Deinitialize();
- Console.WriteLine("Thanks for using Chilong!");
- return;
- }
- }
- }
- private static void Initialize()
- {
- client = new DiscordRpcClient("815595590515032074");
- if(Process.GetProcesses().Where(x => x.ProcessName.StartsWith("CDisplayEx")).Count() == 0)
- {
- Console.WriteLine("SumatraPDF was not found! Is it open?");
- return;
- }
- cdisplayex = Process.GetProcesses().Where(x => x.ProcessName.StartsWith("CDisplayEx")).ToList()[0];
- windowTitle = cdisplayex.MainWindowTitle;
- client.OnReady += (sender, e) =>
- {
- Console.WriteLine("Received Ready from user {0}", e.User.Username);
- };
- client.OnPresenceUpdate += (sender, e) =>
- {
- Console.WriteLine("Received Update! {0}", e.Presence);
- };
- try
- {
- client.Initialize();
- Console.WriteLine("Successfully connected to client!");
- }
- catch(Exception e)
- {
- Console.WriteLine($"Connection to client was not successful!\nERROR: {e.Message}");
- return;
- }
- try { SetNewPresence(); }
- catch(Exception e)
- {
- Console.WriteLine($"Setting presence was not successful!\nERROR: {e.Message}");
- return;
- }
- }
- private static void Update()
- {
- client.OnPresenceUpdate += (sender, e) =>
- {
- Console.WriteLine("Received Update! {0}", e.Presence);
- };
- client.Invoke();
- OnUpdate();
- }
- private static void Deinitialize()
- {
- client.ClearPresence();
- client.Dispose();
- }
- private static void OnUpdate()
- {
- Process process;
- try
- {
- process = Process.GetProcesses().Where(x => x.ProcessName.StartsWith("CDisplayEx")).ToList()[0];
- }
- catch(Exception) { return; }
- if (process.MainWindowTitle != windowTitle)
- {
- cdisplayex = process;
- windowTitle = cdisplayex.MainWindowTitle;
- SetNewPresence();
- }
- }
- private static void SetNewPresence()
- {
- string details = cdisplayex.MainWindowTitle;
- if(details == " " || details == "")
- details = "Picking a New File";
- client.SetPresence(new RichPresence
- {
- Details = details,
- State = "State Placeholder",
- Timestamps = new Timestamps(DateTime.UtcNow),
- Assets = new Assets()
- {
- LargeImageKey = "cdisplayex",
- LargeImageText = "cdisplayex"
- }
- });
- Console.WriteLine("Presence successfully set!");
- }
- }
- public class StringBuilder
- {
- public StringBuilder(int v)
- {
- V = v;
- }
- public int V { get; }
- public int Capacity { get; internal set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement