mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
|
||||
internal static class VoiceChatBanFlagPatches
|
||||
{
|
||||
private static bool _armed;
|
||||
|
||||
internal static void Apply(Harmony harmony)
|
||||
{
|
||||
if (_armed) return;
|
||||
_armed = true;
|
||||
|
||||
Patch(harmony, "IsVoiceChatBanned", nameof(BannedPostfix));
|
||||
Patch(harmony, "AllowedToVoiceChat", nameof(AllowedPostfix));
|
||||
}
|
||||
|
||||
private static void Patch(Harmony harmony, string propertyName, string handler)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
var getter = AccessTools.Method(typeof(SettingsModel), "get_" + propertyName)
|
||||
?? AccessTools.Property(typeof(SettingsModel), propertyName)?.GetGetMethod(true);
|
||||
if (getter == null)
|
||||
{
|
||||
RadicadeEacBypassPlugin.LogSource.LogWarning("[VoiceBanFlag] SettingsModel."
|
||||
+ propertyName + " has no getter in this build, so the Audio page keeps its own value.");
|
||||
return;
|
||||
}
|
||||
|
||||
harmony.Patch(getter, postfix: new HarmonyMethod(typeof(VoiceChatBanFlagPatches)
|
||||
.GetMethod(handler, BindingFlags.Static | BindingFlags.NonPublic)));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RadicadeEacBypassPlugin.LogSource.LogWarning("[VoiceBanFlag] could not patch SettingsModel."
|
||||
+ propertyName + ": " + ex.GetType().Name + ": " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private static void BannedPostfix(ref bool __result)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!VoiceChatRestrictionPatches.RestrictionInForce) return;
|
||||
|
||||
__result = true;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private static void AllowedPostfix(ref bool __result)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!VoiceChatRestrictionPatches.RestrictionInForce) return;
|
||||
|
||||
__result = false;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user