Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Bheithir.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
56 changes: 44 additions & 12 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Program
private static readonly Dictionary<string, Presence> emulators = new Dictionary<string, Presence>()
{
{ "dosbox", new DosBox() },
{ "dosbox-x", new DosBox_X() },
{ "fceux", new Fceux() },
{ "snes9x", new Snes9x() },
{ "fusion", new Fusion() },
Expand All @@ -22,31 +23,62 @@ private static void Main(string[] args)
{
bool success = false;
string emulator = "";
while(!success)

if (args.Length > 0)
{
Console.WriteLine("What emulator are you using?");
Console.ForegroundColor = ConsoleColor.Cyan;
emulator = Console.ReadLine().ToLower();
if(emulators.ContainsKey(emulator))
break;
Console.ResetColor();
Console.WriteLine("You misspelled the emulator name or that emulator is not supported!\n");
for (int i = 0; i < args.Length; i++)
{
if (args[i].StartsWith("-"))
{
string flag = args[i].Substring(1).ToLower();
if (emulators.ContainsKey(flag))
{
emulator = flag;
success = true;
break;
}
else
{
Console.WriteLine("The specified emulator is not supported!");
return;
}
}
}
}

if (!success)
{
while (!success)
{
Console.WriteLine("What emulator are you using?");
Console.ForegroundColor = ConsoleColor.Cyan;
emulator = Console.ReadLine().ToLower();
Console.ResetColor();

if (emulators.ContainsKey(emulator))
{
success = true;
}
else
{
Console.WriteLine("You misspelled the emulator name or that emulator is not supported!\n");
}
}
}
Console.ResetColor();

Presence presence = emulators[emulator];

if (!Process.GetProcesses().Where(x => x.ProcessName.StartsWith(presence.ProcessName)).Any())
if (!Process.GetProcesses().Any(x => x.ProcessName.StartsWith(presence.ProcessName)))
{
Console.WriteLine("The specified emulator was not found! Is it open?");
return;
}

presence.Initialize();
while(true)
while (true)
{
presence.Update();
if(!Process.GetProcesses().Where(x => x.ProcessName.StartsWith(presence.ProcessName)).Any())
if (!Process.GetProcesses().Any(x => x.ProcessName.StartsWith(presence.ProcessName)))
{
presence.Deinitialize();
Console.WriteLine("Thanks for using Bheithir!");
Expand Down
Binary file added assets/dosbox-x-rpc-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/dosbox-x-rpc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 138 additions & 0 deletions emulators/DosBox_X.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using DiscordRPC;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Bheithir.Emulators
{
class DosBox_X : Presence
{
public DosBox_X()
{
DiscordAppId = "1138396799669895248";
ProcessName = "dosbox-x";
WindowPattern = new Regex("(,\\s)+", RegexOptions.Compiled);
}

public override void Initialize()
{
Client = new DiscordRpcClient(DiscordAppId);

Process = Process.GetProcesses().Where(x => x.ProcessName.StartsWith(ProcessName)).ToList()[0];
WindowTitle = Process.MainWindowTitle;

Client.OnReady += (sender, e) => { };
Client.OnPresenceUpdate += (sender, e) => { };

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;
}
}
public override void Update()
{
Client.OnPresenceUpdate += (sender, e) => { };
Client.Invoke();
OnUpdate();
}
public override void Deinitialize()
{
Client.ClearPresence();
Client.Dispose();
}

public override void OnUpdate()
{
Process process;
try
{
process = Process.GetProcesses().Where(x => x.ProcessName.StartsWith(ProcessName)).ToList()[0];
}
catch (Exception) { return; }

if (process.MainWindowTitle != WindowTitle)
{
Process = process;
WindowTitle = Process.MainWindowTitle;
SetNewPresence();
}
}
public override void SetNewPresence()
{
char[] delimiters = { ':', '[', ']' };
string[] titleParts = WindowTitle.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

if (titleParts.Length >= 2)
{
string part1 = titleParts[0].Trim();
string[] part2Parts = titleParts[1].Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
string part2 = part2Parts.Length > 0 ? part2Parts[0].Trim() : "";
string part3 = part2Parts.Length > 1 ? part2Parts[1].Trim() : "";

string details;
try
{
if (titleParts[1].Contains("COMMAND"))
details = "Idling in the Command Line";
else
details = part2;
}
catch (Exception c)
{
Console.WriteLine(c);
return;
}


string status;
try
{
status = part3;
}
catch (Exception c)
{
Console.WriteLine(c);
return;
}

try
{
Client.SetPresence(new RichPresence
{
Details = details,
State = status,
Timestamps = new Timestamps(DateTime.UtcNow),
Assets = new Assets()
{
LargeImageKey = "dos",
LargeImageText = "DOSBox-X"
}
});
Console.WriteLine("Presence successfully set!");
}
catch (Exception)
{
Console.WriteLine("Presence was not set successfully!");
return;
}
}
}
}
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Bheithir is a program that sets Discord Rich Presence (RPC) status for various e
## What emulators are supported right now?
- [DOSBox](https://www.dosbox.com/)
- [MS-DOS](https://en.wikipedia.org/wiki/MS-DOS) emulator primarilly designed for playing games
- [DOSBox-X](https://dosbox-x.com/)
- Fork of [DOSBox](https://www.dosbox.com/) an [MS-DOS](https://en.wikipedia.org/wiki/MS-DOS) emulator primarilly designed for playing games
- [FCEUX](http://www.fceux.com/web/home.html)
- [NES](https://en.wikipedia.org/wiki/Nintendo_Entertainment_System)
- [SNES9X](http://www.snes9x.com/)
Expand Down