|
|
@@ -1,17 +1,15 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Reflection; |
|
|
|
using GamecraftModdingAPI.Blocks; |
|
|
|
using HarmonyLib; |
|
|
|
|
|
|
|
using RobocraftX; |
|
|
|
using RobocraftX.Services; |
|
|
|
using Svelto.Context; |
|
|
|
|
|
|
|
using GamecraftModdingAPI.Utility; |
|
|
|
using GamecraftModdingAPI.Events; |
|
|
|
using GamecraftModdingAPI.Players; |
|
|
|
using GamecraftModdingAPI.Tasks; |
|
|
|
using uREPL; |
|
|
|
|
|
|
|
namespace GamecraftModdingAPI |
|
|
|
{ |
|
|
@@ -46,7 +44,20 @@ namespace GamecraftModdingAPI |
|
|
|
Logging.MetaDebugLog($"Patching Gamecraft"); |
|
|
|
var currentAssembly = Assembly.GetExecutingAssembly(); |
|
|
|
harmony = new Harmony(currentAssembly.GetName().Name); |
|
|
|
harmony.PatchAll(currentAssembly); |
|
|
|
try |
|
|
|
{ |
|
|
|
harmony.PatchAll(currentAssembly); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ //Can't use ErrorBuilder or Logging.LogException (which eventually uses ErrorBuilder) yet |
|
|
|
Logging.Log(e.ToString()); |
|
|
|
Logging.LogWarning("Failed to patch Gamecraft. Attempting to patch to display error..."); |
|
|
|
harmony.Patch(AccessTools.Method(typeof(FullGameCompositionRoot), "OnContextInitialized") |
|
|
|
.MakeGenericMethod(typeof(UnityContext<FullGameCompositionRoot>)), |
|
|
|
new HarmonyMethod(((Action) OnPatchError).Method)); //Can't use lambdas here :( |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// init utility |
|
|
|
Logging.MetaDebugLog($"Initializing Utility"); |
|
|
|
#pragma warning disable 0612,0618 |
|
|
@@ -102,5 +113,11 @@ namespace GamecraftModdingAPI |
|
|
|
Logging.MetaLog($"{currentAssembly.GetName().Name} v{currentAssembly.GetName().Version} shutdown"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static void OnPatchError() |
|
|
|
{ |
|
|
|
ErrorBuilder.DisplayMustQuitError("Failed to patch Gamecraft!\n" + |
|
|
|
"Make sure you're using the latest version of GamecraftModdingAPI or disable mods if the API isn't released yet."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |