Browse Source

Fix initial issues and add error on patch fail

Fixed compilation and loading issues for 2020.10.27.17.13
tags/v1.7.0
NorbiPeti 3 years ago
parent
commit
987fbe673a
8 changed files with 33 additions and 22 deletions
  1. +0
    -0
      Automation/gen_csproj.py
  2. +1
    -1
      GamecraftModdingAPI/Blocks/BlockEngine.cs
  3. +1
    -3
      GamecraftModdingAPI/Blocks/PlacementEngine.cs
  4. +4
    -1
      GamecraftModdingAPI/Blocks/RemovalEngine.cs
  5. +2
    -2
      GamecraftModdingAPI/Input/FakeInput.cs
  6. +1
    -3
      GamecraftModdingAPI/Inventory/HotbarSlotSelectionHandlerEnginePatch.cs
  7. +24
    -7
      GamecraftModdingAPI/Main.cs
  8. +0
    -5
      GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs

+ 0
- 0
Automation/gen_csproj.py View File


+ 1
- 1
GamecraftModdingAPI/Blocks/BlockEngine.cs View File

@@ -2,10 +2,10 @@ using System;
using System.Collections.Generic;
using System.Linq;

using Gamecraft.ColourPalette;
using Gamecraft.Wires;
using RobocraftX.Blocks;
using RobocraftX.Common;
using RobocraftX.GUI.Hotbar.Colours;
using RobocraftX.Physics;
using RobocraftX.Scene.Simulation;
using Svelto.DataStructures;


+ 1
- 3
GamecraftModdingAPI/Blocks/PlacementEngine.cs View File

@@ -70,9 +70,7 @@ namespace GamecraftModdingAPI.Blocks
DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid};
BlockPlacementScaleEntityStruct placementScale = new BlockPlacementScaleEntityStruct
{
blockPlacementHeight = uscale, blockPlacementWidth = uscale, desiredScaleFactor = uscale,
snapGridScale = uscale,
unitSnapOffset = 0, isUsingUnitSize = true
blockPlacementHeight = uscale, blockPlacementWidth = uscale, desiredScaleFactor = uscale
};
EquippedColourStruct colour = new EquippedColourStruct {indexInPalette = color};



+ 4
- 1
GamecraftModdingAPI/Blocks/RemovalEngine.cs View File

@@ -20,8 +20,11 @@ namespace GamecraftModdingAPI.Blocks
if (!entitiesDB.Exists<MachineGraphConnectionsEntityStruct>(target))
return false;
var connections = entitiesDB.QueryEntity<MachineGraphConnectionsEntityStruct>(target);
var groups = entitiesDB.FindGroups<MachineGraphConnectionsEntityStruct>();
var connStructMapper =
entitiesDB.QueryNativeMappedEntities<MachineGraphConnectionsEntityStruct>(groups);
for (int i = connections.connections.Count<MachineConnectionStruct>() - 1; i >= 0; i--)
_connectionFactory.RemoveConnection(connections, i, entitiesDB);
_connectionFactory.RemoveConnection(connections, i, connStructMapper);
_entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
return true;
}


+ 2
- 2
GamecraftModdingAPI/Input/FakeInput.cs View File

@@ -76,7 +76,7 @@ namespace GamecraftModdingAPI.Input
case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_9; break;
default: break;
}
if (commandLine) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleCommandLine;
//if (commandLine) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleCommandLine; - TODO
if (escape) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Escape;
if (enter) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Return;
if (debug) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleDebugDisplay;
@@ -125,7 +125,7 @@ namespace GamecraftModdingAPI.Input
if (tertiary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.TertiaryAction;
if (primaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryActionHeld;
if (secondaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SecondaryActionHeld;
if (toggleUnitGrid) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleUnitGrid;
//if (toggleUnitGrid) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleUnitGrid;
if (ctrl) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CtrlAction;
if (toggleColourMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleColourMode;
if (scaleBlockUp) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockUp;


+ 1
- 3
GamecraftModdingAPI/Inventory/HotbarSlotSelectionHandlerEnginePatch.cs View File

@@ -1,8 +1,6 @@
using System;
using System.Reflection;

using RobocraftX.GUI;
using RobocraftX.GUI.Hotbar;
using Svelto.ECS;

using HarmonyLib;
@@ -17,7 +15,7 @@ namespace GamecraftModdingAPI.Inventory

public static BlockIDs EquippedPartID { get => (BlockIDs)selectedBlockInt; }

private static MethodInfo PatchedMethod { get; } = AccessTools.Method(AccessTools.TypeByName("RobocraftX.GUI.Hotbar.HotbarSlotSelectionHandlerEngine"), "ActivateSlotForCube", parameters: new Type[] { typeof(uint), typeof(int), typeof(ExclusiveGroupStruct) });
private static MethodInfo PatchedMethod { get; } = AccessTools.Method("Gamecraft.GUI.Hotbar.Blocks.SyncHotbarSlotSelectedToEquipedPartEngine:ActivateSlotForCube", parameters: new Type[] { typeof(uint), typeof(int), typeof(ExclusiveGroupStruct) });

public static void Prefix(uint playerID, int selectedDBPartID, ExclusiveGroupStruct groupID)
{


+ 24
- 7
GamecraftModdingAPI/Main.cs View File

@@ -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.");
}
}
}

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

@@ -173,11 +173,6 @@ namespace GamecraftModdingAPI.Tests
Logging.CommandLog("Finished in " + sw.ElapsedMilliseconds + "ms");
})
.Build();
//With Sync(): 1135ms
//Without Sync(): 134ms
//Async: 348 794ms, doesn't freeze game
//Without Sync() but wait for submission: 530ms
//With Sync() at the end: 380ms

Block b = null;
CommandBuilder.Builder("moveBlockInSim", "Run in build mode first while looking at a block, then in sim to move it up")


Loading…
Cancel
Save