Skip to content

Commit

Permalink
fix CLI and fix overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
gabehxd committed Jul 18, 2020
1 parent 5756ea9 commit 8b9ae3f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 53 deletions.
12 changes: 6 additions & 6 deletions PresenceClient/PresenceClient-CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Program
{
static Timer timer;
static Socket client;
static ulong LastProgramId = 0;
static string LastProgramName = string.Empty;
static Timestamps time = null;
static DiscordRpcClient rpc;
static ConsoleOptions Arguments;
Expand Down Expand Up @@ -98,21 +98,21 @@ private static void DataListen()
Title title = new Title(bytes);
if (title.Magic == 0xffaadd23)
{
if (LastProgramId != title.ProgramId)
if (LastProgramName != title.Name)
{
time = Timestamps.Now;
}
if ((rpc != null && rpc.CurrentPresence == null) || LastProgramId != title.ProgramId)
if ((rpc != null && rpc.CurrentPresence == null) || LastProgramName != title.Name)
{
if (Arguments.IgnoreHomeScreen && title.ProgramId == 0)
if (Arguments.IgnoreHomeScreen && title.Name == "Home Menu")
{
rpc.ClearPresence();
}
else
{
rpc.SetPresence(Utils.CreateDiscordPresence(title, time));
}
LastProgramId = title.ProgramId;
LastProgramName = title.Name;
}
}
else
Expand All @@ -133,7 +133,7 @@ private static void DataListen()

private static void OnConnectTimeout(object sender, ElapsedEventArgs e)
{
LastProgramId = 0;
LastProgramName = string.Empty;
time = null;
}

Expand Down
2 changes: 1 addition & 1 deletion PresenceClient/PresenceClient-GUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private void DataListen()
{
if (rpc != null)
{
if (checkMainMenu.Checked == false && title.ProgramId == 0)
if (checkMainMenu.Checked == false && title.Name == "Main Menu")
rpc.ClearPresence();
else
{
Expand Down
27 changes: 25 additions & 2 deletions PresenceClient/PresenceCommon/Types/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,31 @@ public Title(byte[] bytes)
{
TitlePacket title = DataHandler.ByteArrayToStructure<TitlePacket>(bytes);
Magic = title.magic;
ProgramId = title.programId;
Name = Encoding.UTF8.GetString(title.name, 0, title.name.Length).Split('\0')[0];

if (title.programId == 0)
{
ProgramId = 0x0100000000001000;
Name = "Home Menu";
}
else
{
ProgramId = title.programId;
Name = Encoding.UTF8.GetString(title.name, 0, title.name.Length).Split('\0')[0];
}
if (title.programId == 0xffaadd23)
{
if (Utils.QuestOverrides.ContainsKey(Name) && Utils.QuestOverrides[Name].CustomName != null)
{
Name = Utils.QuestOverrides[Name].CustomName;
}
}
else
{
if (Utils.SwitchOverrides.ContainsKey(Name) && Utils.SwitchOverrides[Name].CustomName != null)
{
Name = Utils.SwitchOverrides[Name].CustomName;
}
}
}
}
}
61 changes: 19 additions & 42 deletions PresenceClient/PresenceCommon/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace PresenceCommon
{
public static class Utils
{
private static readonly Dictionary<string, OverrideInfo> QuestOverrides;
private static readonly Dictionary<string, OverrideInfo> SwitchOverrides;
public static readonly Dictionary<string, OverrideInfo> QuestOverrides;
public static readonly Dictionary<string, OverrideInfo> SwitchOverrides;
static Utils()
{
WebClient client = new WebClient();
Expand All @@ -32,75 +32,52 @@ public static RichPresence CreateDiscordPresence(Title title, Timestamps time, s

Assets assets = new Assets
{
SmallImageKey = smallImageKey,
SmallImageKey = smallImageKey
};

assets.LargeImageText = title.Name;
if (title.ProgramId != 0xffaadd23)
{
assets.SmallImageText = "SwitchPresence-Rewritten";

if (!SwitchOverrides.ContainsKey(title.Name))
{
if (title.Name == "SNULL")
{
assets.LargeImageText = !string.IsNullOrWhiteSpace(largeImageText) ? largeImageText : "Home Menu";
assets.LargeImageKey = !string.IsNullOrWhiteSpace(largeImageKey) ? largeImageKey : $"0{0x0100000000001000:x}";
presence.Details = "In the home menu";
}
else
{
assets.LargeImageText = !string.IsNullOrWhiteSpace(largeImageText) ? largeImageText : title.Name;
assets.LargeImageKey = !string.IsNullOrWhiteSpace(largeImageKey) ? largeImageKey : $"0{title.ProgramId:x}";
presence.Details = $"Playing {title.Name}";
}
assets.LargeImageKey = $"0{title.ProgramId:x}";
presence.Details = $"Playing {title.Name}";
}
else
{
OverrideInfo pkgInfo = SwitchOverrides[title.Name];
assets.LargeImageKey = pkgInfo.CustomKey ?? (!string.IsNullOrWhiteSpace(largeImageKey) ? largeImageKey : $"0{title.ProgramId:x}");
assets.LargeImageKey = pkgInfo.CustomKey ?? $"0{title.ProgramId:x}";

presence.Details = pkgInfo.CustomPrefix ?? "Playing";

if (pkgInfo.CustomName != null)
{
presence.Details += $" {pkgInfo.CustomName}";
assets.LargeImageText = pkgInfo.CustomName;
}
else
{
presence.Details += $" {title.Name}";
assets.LargeImageText = title.Name;
}
presence.Details += $" {title.Name}";
}
}
else
{
assets.SmallImageText = "QuestPresence";

if (!QuestOverrides.ContainsKey(title.Name))
{
assets.LargeImageText = !string.IsNullOrWhiteSpace(largeImageText) ? largeImageText : title.Name;
assets.LargeImageKey = !string.IsNullOrWhiteSpace(largeImageKey) ? largeImageKey : title.Name.ToLower().Replace(" ", "");
assets.LargeImageKey = title.Name.ToLower().Replace(" ", "");
presence.Details = $"Playing {title.Name}";
}
else
{
OverrideInfo pkgInfo = QuestOverrides[title.Name];

assets.LargeImageKey = pkgInfo.CustomKey ?? (pkgInfo.CustomName != null ? pkgInfo.CustomName.ToLower().Replace(" ", "") : title.Name.ToLower().Replace(" ", ""));
assets.LargeImageKey = pkgInfo.CustomKey ?? title.Name.ToLower().Replace(" ", "");

presence.Details = pkgInfo.CustomPrefix ?? "Playing";

if (pkgInfo.CustomName != null)
{
presence.Details += $" {pkgInfo.CustomName}";
assets.LargeImageText = pkgInfo.CustomName;
}
else
{
presence.Details += $" {title.Name}";
assets.LargeImageText = title.Name;
}
presence.Details += $" {title.Name}";
}
}
if (!string.IsNullOrEmpty(largeImageKey))
assets.LargeImageKey = largeImageKey;

if (!string.IsNullOrEmpty(largeImageText))
assets.LargeImageText = largeImageText;

presence.Assets = assets;
presence.Timestamps = time;
Expand All @@ -124,7 +101,7 @@ public static byte[] ReceiveExactly(Socket handler, int length = 628)
return buffer;
}

private partial class OverrideInfo
public partial class OverrideInfo
{
public string CustomName { set; get; }
public string CustomPrefix { set; get; }
Expand Down
4 changes: 2 additions & 2 deletions Resource/QuestApplicationOverrides.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"QuestPresence": {
"CustomPrefix": "On the",
"CustomName": "Main Menu",
"CustomName": "Home Menu",
"CustomKey": null
},
"Oculus App Runtime": {
"CustomPrefix": "On the",
"CustomName": "Main Menu",
"CustomName": "Home Menu",
"CustomKey": null
},
"Netflix": {
Expand Down
5 changes: 5 additions & 0 deletions Resource/SwitchApplicationOverrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"CustomPrefix": "Watching",
"CustomName": null,
"CustomKey": null
},
"Home Menu": {
"CustomPrefix": "In the",
"CustomName": null,
"CustomKey": null
}
}

0 comments on commit 8b9ae3f

Please sign in to comment.