Add basic analytics disabler (experimental)

This commit is contained in:
NGnius 2020-01-26 15:26:48 -05:00
parent 2f5064a41d
commit b4e9b403da
2 changed files with 49 additions and 5 deletions

View file

@ -42,11 +42,13 @@ namespace GamecraftModdingAPI.Tests
public void OnApplicationStart() public void OnApplicationStart()
{ {
GamecraftModdingAPI.Main.Init(); GamecraftModdingAPI.Main.Init();
// in case Steam is not installed/running // in case Steam is not installed/running
// this will crash the game slightly later during startup // this will crash the game slightly later during startup
//SteamInitPatch.ForcePassSteamCheck = true; //SteamInitPatch.ForcePassSteamCheck = true;
// in case running in a VM // in case running in a VM
//MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true; //MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
// disable some Gamecraft analytics
//AnalyticsDisablerPatch.DisableAnalytics = true;
// disable background music // disable background music
AudioTools.SetVolume(0.0f, "Music"); AudioTools.SetVolume(0.0f, "Music");
@ -90,6 +92,10 @@ namespace GamecraftModdingAPI.Tests
CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>( CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
(x,y,z) => { Blocks.Placement.PlaceBlock(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); }, (x,y,z) => { Blocks.Placement.PlaceBlock(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); },
"PlaceAluminium", "Place a block of aluminium at the given coordinates")); "PlaceAluminium", "Place a block of aluminium at the given coordinates"));
Analytics.DeltaDNAHelper.PlayerLifetimeParameters plp = new Analytics.DeltaDNAHelper.PlayerLifetimeParameters();
CommandManager.AddCommand(new SimpleCustomCommandEngine<string>(
(s) => { Analytics.DeltaDNAHelper.SendActionCompletedEvent(in plp, s.Replace(", ", " ")); },
"SendAnalyticsAction", "Send an analytics action"));
} }
public void OnFixedUpdate() { } public void OnFixedUpdate() { }

View file

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using Analytics;
using Harmony;
using RobocraftX.Common;
using Svelto.ECS;
namespace GamecraftModdingAPI.Utility
{
/// <summary>
/// Patch of Analytics.AnalyticsCompositionRoot.Compose<T>(...)
/// This stops some analytics collection built into Gamecraft.
/// DO NOT USE! (This will likely crash your game on shutdown)
/// </summary>
[HarmonyPatch]
class AnalyticsDisablerPatch
{
/// <summary>
/// Don't activate gameplay analytics?
/// </summary>
public static bool DisableAnalytics = false;
public static bool Prefix(object contextHolder, EnginesRoot enginesRoot, RCXMode rcxMode)
{
return !DisableAnalytics;
}
public static MethodBase TargetMethod(HarmonyInstance instance)
{
return typeof(Analytics.AnalyticsCompositionRoot).GetMethod("Compose").MakeGenericMethod(typeof(object));
}
}
}