Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from Subversionary/RPCFUCK
Browse files Browse the repository at this point in the history
Faking Discord RPC usernames
  • Loading branch information
misandrie authored May 15, 2024
2 parents 9a167ec + b3dac3d commit e7e31db
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 6 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</PropertyGroup>
<ItemGroup>
<!-- Launcher-loader shared stuff -->
<PackageVersion Include="JetBrains.Annotations" Version="10.3.0" />
<PackageVersion Include="Lib.Harmony" Version="2.3.0-prerelease.4" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.4" />
<PackageVersion Include="MonoMod.Utils" Version="25.0.3" />
Expand Down
10 changes: 9 additions & 1 deletion Marsey/Config/MarseyConf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ public static class MarseyConf
/// <see cref="HWID"/>
public static bool ForceHWID;

/// <see cref="DiscordRPC"/>
/// <see cref="DiscordRPC.Disable"/>
public static bool KillRPC;

/// <see cref="DiscordRPC.Fake"/>
public static bool FakeRPC;

/// <see cref="Marsey.Game.Resources.Dumper.Dumper"/>
public static bool Dumper;

Expand All @@ -66,6 +69,9 @@ public static class MarseyConf
/// </summary>
public static bool DisableAnyBackports;

/// <summary>
/// Reflect changes made here to the Dictionary in the launcher's Connector.cs
/// </summary>
public static readonly Dictionary<string, Action<string>> EnvVarMap = new Dictionary<string, Action<string>>
{
{ "MARSEY_LOGGING", value => Logging = value == "true" },
Expand All @@ -76,6 +82,8 @@ public static class MarseyConf
{ "MARSEY_FORCINGHWID", value => ForceHWID = value == "true" },
{ "MARSEY_FORCEDHWID", value => HWID.SetHWID(value)},
{ "MARSEY_DISABLE_PRESENCE", value => KillRPC = value == "true" },
{ "MARSEY_FAKE_PRESENCE", value => FakeRPC = value == "true"},
{ "MARSEY_PRESENCE_USERNAME", value => DiscordRPC.SetUsername(value)},
{ "MARSEY_DUMP_ASSEMBLIES", value => Dumper = value == "true" },
{ "MARSEY_JAMMER", value => JamDials = value == "true" },
{ "MARSEY_DISABLE_REC", value => DisableREC = value == "true" },
Expand Down
47 changes: 43 additions & 4 deletions Marsey/Game/Patches/DiscordRPC.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using JetBrains.Annotations;
using Marsey.Config;
using Marsey.Handbreak;
using Marsey.Misc;
Expand All @@ -7,10 +8,19 @@ namespace Marsey.Game.Patches;

public static class DiscordRPC
{
public static void Disable()
private static string FakeUsername = "Marsey";

public static void Patch()
{
if (MarseyConf.KillRPC) Disable();
else if (MarseyConf.FakeRPC) Fake();
}

/// <summary>
/// Does not let DiscordRPC initialize independent of game config
/// </summary>
private static void Disable()
{
if (!MarseyConf.KillRPC) return;

MarseyLogger.Log(MarseyLogger.LogType.DEBG, "DiscordRPC", "Disabling.");

Helpers.PatchMethod(
Expand All @@ -22,5 +32,34 @@ public static void Disable()
);
}

/// <summary>
/// Changes the username displayed in DiscordRPC, if enabled
/// </summary>
private static void Fake()
{
MarseyLogger.Log(MarseyLogger.LogType.DEBG, "DiscordRPC", $"Faking RPC username to {FakeUsername}.");

Helpers.PatchMethod(
Helpers.TypeFromQualifiedName("Robust.Client.Utility.DiscordRichPresence"),
"Update",
typeof(DiscordRPC),
"ChangeUsername",
HarmonyPatchType.Prefix);
}

// ReSharper disable once RedundantAssignment
[UsedImplicitly]
private static void ChangeUsername(ref string username)
{
username = FakeUsername;
}

private static bool Skip() => false;
}

public static void SetUsername(string name)
{
if (name != "")
FakeUsername = name;
}

}
1 change: 1 addition & 0 deletions Marsey/Marsey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" />
<PackageReference Include="Lib.Harmony" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Marsey/Stealthsey/Hidesey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static void Disperse()
public static void PostLoad()
{
HWID.Force();
DiscordRPC.Disable();
DiscordRPC.Patch();

// Cleanup
Disperse();
Expand Down
2 changes: 2 additions & 0 deletions SS14.Launcher/Models/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ private void ConfigureMarsey()
{ "MARSEY_JAMMER", _cfg.GetCVar(CVars.JamDials) ? "true" : null },
{ "MARSEY_DISABLE_REC", _cfg.GetCVar(CVars.Blackhole) ? "true" : null },
{ "MARSEY_DISABLE_PRESENCE", _cfg.GetCVar(CVars.DisableRPC) ? "true" : null },
{ "MARSEY_FAKE_PRESENCE", _cfg.GetCVar(CVars.FakeRPC) ? "true" : null },
{ "MARSEY_PRESENCE_USERNAME", _cfg.GetCVar(CVars.RPCUsername) },
{ "MARSEY_FORCINGHWID", _cfg.GetCVar(CVars.ForcingHWId) ? "true" : null },
{ "MARSEY_FORCEDHWID", _cfg.GetCVar(CVars.ForcingHWId) ? MarseyGetHWID() : null },
{ "MARSEY_FORKID", _forkid },
Expand Down
10 changes: 10 additions & 0 deletions SS14.Launcher/Models/Data/CVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ public static readonly CVarDef<bool> HasDismissedEarlyAccessWarning
/// </summary>
public static readonly CVarDef<bool> DisableRPC = CVarDef.Create("DisableRPC", false);

/// <summary>
/// Do we fake the username on RPC?
/// </summary>
public static readonly CVarDef<bool> FakeRPC = CVarDef.Create("FakeRPC", false);

/// <summary>
/// Username to fake RPC with
/// </summary>
public static readonly CVarDef<string> RPCUsername = CVarDef.Create("RPCUsername", "");

/// <summary>
/// Do we disable redialing?
/// </summary>
Expand Down
26 changes: 26 additions & 0 deletions SS14.Launcher/ViewModels/MainWindowTabs/OptionsTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class OptionsTabViewModel : MainWindowTabViewModel, INotifyPropertyChange
public ICommand GenHWIdCommand { get; }
public ICommand DumpConfigCommand { get; }
public ICommand SetUsernameCommand { get; }
public ICommand SetRPCUsernameCommand { get; }
public ICommand SetGuestUsernameCommand { get; }
public ICommand SetEndpointCommand { get; }
public IEnumerable<HideLevel> HideLevels { get; } = Enum.GetValues(typeof(HideLevel)).Cast<HideLevel>();
Expand All @@ -52,6 +53,7 @@ public OptionsTabViewModel()
_contentManager = Locator.Current.GetRequiredService<ContentManager>();

SetHWIdCommand = new RelayCommand(OnSetHWIdClick);
SetRPCUsernameCommand = new RelayCommand(OnSetRPCUsernameClick);
GenHWIdCommand = new RelayCommand(OnGenHWIdClick);
SetUsernameCommand = new RelayCommand(OnSetUsernameClick);
SetGuestUsernameCommand = new RelayCommand(OnSetGuestUsernameClick);
Expand Down Expand Up @@ -226,6 +228,24 @@ public bool DisableRPC
}
}

public bool FakeRPC
{
get => Cfg.GetCVar(CVars.FakeRPC);
set
{
Cfg.SetCVar(CVars.FakeRPC, value);
OnPropertyChanged(nameof(FakeRPC));
Cfg.CommitConfig();
}
}

private string _RPCUsername = "";
public string RPCUsername
{
get => Cfg.GetCVar(CVars.RPCUsername);
set => _RPCUsername = value;
}

public bool ForcingHWID
{
get => Cfg.GetCVar(CVars.ForcingHWId);
Expand Down Expand Up @@ -410,6 +430,12 @@ private void OnSetHWIdClick()
Log.Warning("Passed HWId is not a valid hexadecimal string! Refusing to apply.");
}

private void OnSetRPCUsernameClick()
{
Cfg.SetCVar(CVars.RPCUsername, _RPCUsername);
Cfg.CommitConfig();
}

private void OnGenHWIdClick()
{
string hwid = HWID.GenerateRandom();
Expand Down
13 changes: 13 additions & 0 deletions SS14.Launcher/Views/MainWindowTabs/OptionsTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@
Text="Does not let Discord RPC initialize, hiding your username and server from your profile."
Margin="8" />

<CheckBox VerticalAlignment="Center" Margin="4" IsChecked="{Binding FakeRPC}">Fake RPC Username</CheckBox>
<TextBlock VerticalAlignment="Center" TextWrapping="Wrap"
Text="Changes the username on Discord Rich Presence."
Margin="8" />

<Grid IsVisible="{Binding FakeRPC}" RowDefinitions="*, *, *" ColumnDefinitions="*, Auto">
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center" TextWrapping="NoWrap"
Text="Set your username below. This username will be shown in the discord rich presence activity when hovering on the big icon."
Margin="8"/>
<TextBox Grid.Row="1" Grid.Column="0" Width="600" MaxWidth="1000" HorizontalAlignment="Left" x:Name="RPCUsernameTextBox" VerticalAlignment="Center" Margin="4" Text="{Binding RPCUsername}"/>
<Button Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Content="Set username" Command="{Binding SetRPCUsernameCommand}" VerticalAlignment="Center" Margin="4"/>
</Grid>

<CheckBox VerticalAlignment="Center" Margin="4" IsChecked="{Binding MarseyJam}">Disable Redial</CheckBox>
<TextBlock VerticalAlignment="Center" TextWrapping="Wrap"
Text="Does not let game admins (or the game itself) to reconnect you to another station."
Expand Down

0 comments on commit e7e31db

Please sign in to comment.