-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
5 changed files
with
60 additions
and
2 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,46 @@ | ||
using System.Reflection; | ||
using Discord.WebSocket; | ||
using HarmonyLib; | ||
|
||
namespace Fergun; | ||
|
||
/// <summary> | ||
/// Represents the mobile patcher. | ||
/// </summary> | ||
public static class MobilePatcher | ||
{ | ||
/// <summary> | ||
/// Patches Discord.Net to display the mobile status. | ||
/// </summary> | ||
public static void Patch() | ||
{ | ||
var harmony = new Harmony(nameof(MobilePatcher)); | ||
|
||
var original = AccessTools.Method("Discord.API.DiscordSocketApiClient:SendGatewayAsync"); | ||
var prefix = typeof(MobilePatcher).GetMethod(nameof(Prefix)); | ||
|
||
harmony.Patch(original, new HarmonyMethod(prefix)); | ||
} | ||
|
||
private static readonly Type _identifyParams = | ||
typeof(BaseSocketClient).Assembly.GetType("Discord.API.Gateway.IdentifyParams", true)!; | ||
|
||
private static readonly PropertyInfo? _property = _identifyParams.GetProperty("Properties"); | ||
|
||
public static void Prefix(in byte opCode, in object payload) | ||
{ | ||
if (opCode != 2) // Identify | ||
return; | ||
|
||
if (payload.GetType() != _identifyParams) | ||
return; | ||
|
||
if (_property?.GetValue(payload) is not IDictionary<string, string> props | ||
|| !props.TryGetValue("$device", out string? device) | ||
|| device != "Discord.Net") | ||
return; | ||
|
||
props["$os"] = "android"; | ||
props["$browser"] = "Discord Android"; | ||
} | ||
} |
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
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
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
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