Fix initial issues and add error on patch fail

Fixed compilation and loading issues for 2020.10.27.17.13
This commit is contained in:
Norbi Peti 2020-10-29 00:37:47 +01:00
parent c6a1ea35cc
commit 987fbe673a
8 changed files with 33 additions and 22 deletions

0
Automation/gen_csproj.py Normal file → Executable file
View file

View file

@ -2,10 +2,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Gamecraft.ColourPalette;
using Gamecraft.Wires; using Gamecraft.Wires;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Common; using RobocraftX.Common;
using RobocraftX.GUI.Hotbar.Colours;
using RobocraftX.Physics; using RobocraftX.Physics;
using RobocraftX.Scene.Simulation; using RobocraftX.Scene.Simulation;
using Svelto.DataStructures; using Svelto.DataStructures;

View file

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

View file

@ -20,8 +20,11 @@ namespace GamecraftModdingAPI.Blocks
if (!entitiesDB.Exists<MachineGraphConnectionsEntityStruct>(target)) if (!entitiesDB.Exists<MachineGraphConnectionsEntityStruct>(target))
return false; return false;
var connections = entitiesDB.QueryEntity<MachineGraphConnectionsEntityStruct>(target); 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--) 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); _entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
return true; return true;
} }

View file

@ -76,7 +76,7 @@ namespace GamecraftModdingAPI.Input
case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_9; break; case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_9; break;
default: 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 (escape) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Escape;
if (enter) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Return; if (enter) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Return;
if (debug) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleDebugDisplay; 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 (tertiary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.TertiaryAction;
if (primaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryActionHeld; if (primaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryActionHeld;
if (secondaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SecondaryActionHeld; 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 (ctrl) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CtrlAction;
if (toggleColourMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleColourMode; if (toggleColourMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleColourMode;
if (scaleBlockUp) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockUp; if (scaleBlockUp) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockUp;

View file

@ -1,8 +1,6 @@
using System; using System;
using System.Reflection; using System.Reflection;
using RobocraftX.GUI;
using RobocraftX.GUI.Hotbar;
using Svelto.ECS; using Svelto.ECS;
using HarmonyLib; using HarmonyLib;
@ -17,7 +15,7 @@ namespace GamecraftModdingAPI.Inventory
public static BlockIDs EquippedPartID { get => (BlockIDs)selectedBlockInt; } 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) public static void Prefix(uint playerID, int selectedDBPartID, ExclusiveGroupStruct groupID)
{ {

View file

@ -1,17 +1,15 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection; using System.Reflection;
using GamecraftModdingAPI.Blocks; using GamecraftModdingAPI.Blocks;
using HarmonyLib; using HarmonyLib;
using RobocraftX;
using RobocraftX.Services;
using Svelto.Context;
using GamecraftModdingAPI.Utility; using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Events; using GamecraftModdingAPI.Events;
using GamecraftModdingAPI.Players;
using GamecraftModdingAPI.Tasks; using GamecraftModdingAPI.Tasks;
using uREPL;
namespace GamecraftModdingAPI namespace GamecraftModdingAPI
{ {
@ -46,7 +44,20 @@ namespace GamecraftModdingAPI
Logging.MetaDebugLog($"Patching Gamecraft"); Logging.MetaDebugLog($"Patching Gamecraft");
var currentAssembly = Assembly.GetExecutingAssembly(); var currentAssembly = Assembly.GetExecutingAssembly();
harmony = new Harmony(currentAssembly.GetName().Name); 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 // init utility
Logging.MetaDebugLog($"Initializing Utility"); Logging.MetaDebugLog($"Initializing Utility");
#pragma warning disable 0612,0618 #pragma warning disable 0612,0618
@ -102,5 +113,11 @@ namespace GamecraftModdingAPI
Logging.MetaLog($"{currentAssembly.GetName().Name} v{currentAssembly.GetName().Version} shutdown"); 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.");
}
} }
} }

View file

@ -173,11 +173,6 @@ namespace GamecraftModdingAPI.Tests
Logging.CommandLog("Finished in " + sw.ElapsedMilliseconds + "ms"); Logging.CommandLog("Finished in " + sw.ElapsedMilliseconds + "ms");
}) })
.Build(); .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; Block b = null;
CommandBuilder.Builder("moveBlockInSim", "Run in build mode first while looking at a block, then in sim to move it up") CommandBuilder.Builder("moveBlockInSim", "Run in build mode first while looking at a block, then in sim to move it up")