Browse Source

Add basic analytics disabler (experimental)

tags/v0.1.3.0
NGnius 4 years ago
parent
commit
b4e9b403da
2 changed files with 49 additions and 5 deletions
  1. +11
    -5
      GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
  2. +38
    -0
      GamecraftModdingAPI/Utility/AnalyticsDisablerPatch.cs

+ 11
- 5
GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs View File

@@ -42,11 +42,13 @@ namespace GamecraftModdingAPI.Tests
public void OnApplicationStart()
{
GamecraftModdingAPI.Main.Init();
// in case Steam is not installed/running
// this will crash the game slightly later during startup
//SteamInitPatch.ForcePassSteamCheck = true;
// in case running in a VM
//MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
// in case Steam is not installed/running
// this will crash the game slightly later during startup
//SteamInitPatch.ForcePassSteamCheck = true;
// in case running in a VM
//MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
// disable some Gamecraft analytics
//AnalyticsDisablerPatch.DisableAnalytics = true;
// disable background music
AudioTools.SetVolume(0.0f, "Music");

@@ -90,6 +92,10 @@ namespace GamecraftModdingAPI.Tests
CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
(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"));
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() { }


+ 38
- 0
GamecraftModdingAPI/Utility/AnalyticsDisablerPatch.cs 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));
}
}
}

Loading…
Cancel
Save