Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable MS Store support #2114

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Disable more telemetry code as it's not needed to run
  • Loading branch information
Measurity committed Jan 24, 2024
commit 5409247ed53cab853cdf5727e21c1686e843909c
39 changes: 36 additions & 3 deletions NitroxPatcher/Patches/Persistent/GameAnalytics_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using System.Reflection;
using HarmonyLib;
using NitroxModel.Helper;
using UnityEngine;

namespace NitroxPatcher.Patches.Persistent;

/// <summary>
/// Patch to disable any analytics uploads to UWE servers. Since game is modded it's not useful for UWE and it's less code to run for us.
/// Patch to disable any analytics uploads to UWE servers. Since game is modded it's not useful for UWE and it's less
/// code to run for us.
/// </summary>
internal class GameAnalytics_Patch : NitroxPatch, IPersistentPatch
{
Expand All @@ -16,19 +18,50 @@ internal class GameAnalytics_Patch : NitroxPatch, IPersistentPatch
private static readonly MethodInfo TARGET_METHOD_SDK = Reflect.Method((SentrySdk t) => t.Start());

/// <summary>
/// Skip manager create as well to remove NRE in Player.log on exit (OnDestroy will try access null SentrySdk instance).
/// Skip manager create as well to remove NRE in Player.log on exit (OnDestroy will try access null SentrySdk
/// instance).
/// </summary>
private static readonly MethodInfo TARGET_METHOD_MANAGER = Reflect.Method((SentrySdkManager t) => t.Awake());

private static readonly MethodInfo TARGET_METHOD_TELEMETRY = Reflect.Method((Telemetry t) => t.Awake());
private static readonly MethodInfo TARGET_METHOD_TELEMETRY_QUIT = Reflect.Method(() => Telemetry.SendGameQuit(default));
private static readonly MethodInfo TARGET_METHOD_GAMEANALYTICS_SEND_EVENT = Reflect.Method(() => GameAnalytics.Send(default(GameAnalytics.Event), default(bool), default(string)));
private static readonly MethodInfo TARGET_METHOD_GAMEANALYTICS_SEND_EVENTINFO = Reflect.Method(() => GameAnalytics.Send(default(GameAnalytics.EventInfo), default(bool), default(string)));
private static readonly MethodInfo TARGET_METHOD_GAMEANALYTICS_SEND_LEGACYEVENT = Reflect.Method(() => GameAnalytics.LegacyEvent(default(GameAnalytics.Event), default(string)));
private static readonly MethodInfo TARGET_METHOD_SPAWNER_ANALYTICS = Reflect.Method((SystemsSpawner t) => t.Awake());

public static bool Prefix(SentrySdk __instance)
{
FieldInfo initializedField = __instance.GetType().GetField("_initialized", BindingFlags.NonPublic | BindingFlags.Instance);
if (initializedField == null)
{
Log.WarnOnce($"{nameof(SentrySdk)} could not be properly disabled because the field '_initialized' is missing. Expect NRE in logs where Telemetry events are processed.");
return false;
}
initializedField.SetValue(__instance, false);
return false;
}

public static bool Prefix(Telemetry __instance)
{
UnityEngine.Object.Destroy(__instance);
return false;
}

public static bool Prefix()
{
return false;
}

public override void Patch(Harmony harmony)
{
PatchPrefix(harmony, TARGET_METHOD_SDK, ((Func<SentrySdk, bool>)Prefix).Method);
PatchPrefix(harmony, TARGET_METHOD_MANAGER, ((Func<SentrySdk, bool>)Prefix).Method);
PatchPrefix(harmony, TARGET_METHOD_MANAGER, ((Func<bool>)Prefix).Method);
PatchPrefix(harmony, TARGET_METHOD_TELEMETRY, ((Func<Telemetry, bool>)Prefix).Method);
PatchPrefix(harmony, TARGET_METHOD_TELEMETRY_QUIT, ((Func<bool>)Prefix).Method);
PatchPrefix(harmony, TARGET_METHOD_GAMEANALYTICS_SEND_EVENT, ((Func<bool>)Prefix).Method);
PatchPrefix(harmony, TARGET_METHOD_GAMEANALYTICS_SEND_EVENTINFO, ((Func<bool>)Prefix).Method);
PatchPrefix(harmony, TARGET_METHOD_GAMEANALYTICS_SEND_LEGACYEVENT, ((Func<bool>)Prefix).Method);
PatchPrefix(harmony, TARGET_METHOD_SPAWNER_ANALYTICS, ((Func<bool>)Prefix).Method);
}
}