From dd72f42cc2cf6830eb9d33ff034f94ef3e9e443a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 15 Jan 2020 20:41:50 +0100 Subject: [PATCH 1/3] Fix rotation parameter --- GamecraftModdingAPI/Blocks/Placement.cs | 6 +++--- GamecraftModdingAPI/Blocks/PlacementEngine.cs | 20 +++++-------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/Placement.cs b/GamecraftModdingAPI/Blocks/Placement.cs index f650312..d91d214 100644 --- a/GamecraftModdingAPI/Blocks/Placement.cs +++ b/GamecraftModdingAPI/Blocks/Placement.cs @@ -21,14 +21,14 @@ namespace GamecraftModdingAPI.Blocks /// The block's color /// The block color's darkness (0-9) - 0 is default color /// The block's position in the grid - default block size is 0.2 - /// The block's rotation + /// The block's rotation in degrees /// The block's uniform scale - default scale is 1 (with 0.2 width) /// The block's non-uniform scale - 0 means is used /// The player who placed the block /// Whether the operation was successful public static bool PlaceBlock(BlockIDs block, float3 position, - quaternion rotation = new quaternion(), BlockColors color = BlockColors.Default, byte darkness = 0, - int uscale = 1, float3 scale = new float3(), uint playerId = 0) + float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0, + int uscale = 1, float3 scale = default, uint playerId = 0) { if (placementEngine.IsInGame && GameState.IsBuildMode()) { diff --git a/GamecraftModdingAPI/Blocks/PlacementEngine.cs b/GamecraftModdingAPI/Blocks/PlacementEngine.cs index fbad336..0bcf890 100644 --- a/GamecraftModdingAPI/Blocks/PlacementEngine.cs +++ b/GamecraftModdingAPI/Blocks/PlacementEngine.cs @@ -44,19 +44,8 @@ namespace GamecraftModdingAPI.Blocks public IEntitiesDB entitiesDB { get; set; } internal static BlockEntityFactory _blockEntityFactory; //Injected from PlaceBlockEngine - /// - /// Places a block at the given position - /// - /// The block's type - /// The block's color - /// The block color's darkness - 0 is default color - /// The block's position - default block size is 0.2 - /// The block's uniform scale - default scale is 1 (with 0.2 width) - /// The block's non-uniform scale - less than 1 means is used - /// The player who placed the block - /// public void PlaceBlock(BlockIDs block, BlockColors color, byte darkness, float3 position, int uscale, - float3 scale, uint playerId, quaternion rotation) + float3 scale, uint playerId, float3 rotation) { //It appears that only the non-uniform scale has any visible effect, but if that's not given here it will be set to the uniform one if (darkness > 9) throw new Exception("That is too dark. Make sure to use 0-9 as darkness. (0 is default.)"); @@ -68,7 +57,7 @@ namespace GamecraftModdingAPI.Blocks }); } - private EntityStructInitializer BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, quaternion rot) + private EntityStructInitializer BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, float3 rot) { if (_blockEntityFactory == null) throw new Exception("The factory is null."); @@ -79,9 +68,10 @@ namespace GamecraftModdingAPI.Blocks if (scale.z < 4e-5) scale.z = uscale; //RobocraftX.CR.MachineEditing.PlaceBlockEngine ScalingEntityStruct scaling = new ScalingEntityStruct {scale = scale}; - RotationEntityStruct rotation = new RotationEntityStruct {rotation = quaternion.identity}; + Quaternion rotQ = Quaternion.Euler(rot); + RotationEntityStruct rotation = new RotationEntityStruct {rotation = rotQ}; GridRotationStruct gridRotation = new GridRotationStruct - {position = float3.zero, rotation = quaternion.identity}; + {position = position, rotation = rotQ}; CubeCategoryStruct category = new CubeCategoryStruct {category = CubeCategory.General, type = CubeType.Block}; uint dbid = block; From 878ebdb491e964943ef9e9d3e2a38f37ebf88a08 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 7 Feb 2020 01:25:31 +0100 Subject: [PATCH 2/3] Update to newer Gamecraft version --- GamecraftModdingAPI/Blocks/MovementEngine.cs | 5 +++-- GamecraftModdingAPI/Blocks/SignalEngine.cs | 5 +++-- GamecraftModdingAPI/GamecraftModdingAPI.csproj | 6 ------ GamecraftModdingAPI/Utility/Logging.cs | 14 ++++---------- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/MovementEngine.cs b/GamecraftModdingAPI/Blocks/MovementEngine.cs index 7fe10d4..ffb8dde 100644 --- a/GamecraftModdingAPI/Blocks/MovementEngine.cs +++ b/GamecraftModdingAPI/Blocks/MovementEngine.cs @@ -20,6 +20,7 @@ using Unity.Mathematics; using UnityEngine; using GamecraftModdingAPI.Utility; +using Svelto.DataStructures; namespace GamecraftModdingAPI.Blocks { @@ -69,9 +70,9 @@ namespace GamecraftModdingAPI.Blocks public float3 MoveConnectedBlocks(uint blockID, float3 vector) { Stack cubeStack = new Stack(); - Gamecraft.DataStructures.FasterList cubesToMove = new Gamecraft.DataStructures.FasterList(); + FasterList cubesToMove = new FasterList(); ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubesToMove, (in GridConnectionsEntityStruct g) => { return false; }); - for (int i = 0; i < cubesToMove.Count; i++) + for (int i = 0; i < cubesToMove.count; i++) { MoveBlock(cubesToMove[i], vector); entitiesDB.QueryEntity(cubesToMove[i], CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false; diff --git a/GamecraftModdingAPI/Blocks/SignalEngine.cs b/GamecraftModdingAPI/Blocks/SignalEngine.cs index 5dde022..62006e3 100644 --- a/GamecraftModdingAPI/Blocks/SignalEngine.cs +++ b/GamecraftModdingAPI/Blocks/SignalEngine.cs @@ -13,6 +13,7 @@ using RobocraftX.SimulationModeState; using RobocraftX.UECS; using Unity.Entities; using Svelto.Context; +using Svelto.DataStructures; using Svelto.ECS; using Svelto.ECS.EntityStructs; using Unity.Transforms; @@ -37,7 +38,7 @@ namespace GamecraftModdingAPI.Blocks private Stack cubesStack = new Stack(); private bool stackInUse = false; - private Gamecraft.DataStructures.FasterList cubesList = new Gamecraft.DataStructures.FasterList(); + private FasterList cubesList = new FasterList(); private bool listInUse = false; public void Dispose() @@ -171,7 +172,7 @@ namespace GamecraftModdingAPI.Blocks else { Stack cubeStack = new Stack(); - Gamecraft.DataStructures.FasterList cubeList = new Gamecraft.DataStructures.FasterList(); + FasterList cubeList = new FasterList(); ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubesStack, cubesList, (in GridConnectionsEntityStruct g) => { return g.isIsolator; }); uint[] res = cubesList.ToArray(); foreach (var id in res) diff --git a/GamecraftModdingAPI/GamecraftModdingAPI.csproj b/GamecraftModdingAPI/GamecraftModdingAPI.csproj index 395e42e..db285e6 100644 --- a/GamecraftModdingAPI/GamecraftModdingAPI.csproj +++ b/GamecraftModdingAPI/GamecraftModdingAPI.csproj @@ -253,9 +253,6 @@ ..\ref\Gamecraft_Data\Managed\Unity.Addressables.dll - - ..\ref\Gamecraft_Data\Managed\Unity.Animation.Rigging.dll - ..\ref\Gamecraft_Data\Managed\Unity.Burst.dll @@ -307,9 +304,6 @@ ..\ref\Gamecraft_Data\Managed\Unity.Properties.dll - - ..\ref\Gamecraft_Data\Managed\Unity.Rendering.Hybrid.dll - ..\ref\Gamecraft_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll diff --git a/GamecraftModdingAPI/Utility/Logging.cs b/GamecraftModdingAPI/Utility/Logging.cs index 28cc6fc..0f22c0a 100644 --- a/GamecraftModdingAPI/Utility/Logging.cs +++ b/GamecraftModdingAPI/Utility/Logging.cs @@ -89,15 +89,9 @@ namespace GamecraftModdingAPI.Utility /// The extra data to pass to the ILogger. /// This is automatically populated with "OuterException#" and "OuterStacktrace#" entries [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void LogException(Exception e, Dictionary extraData = null) + public static void LogException(Exception e, string msg = null, Dictionary extraData = null) { - Svelto.Console.LogException(e, extraData); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void LogException(string msg, Exception e, Dictionary extraData = null) - { - Svelto.Console.LogException(msg, e, extraData); + Svelto.Console.LogException(e, msg, extraData); } /// @@ -108,9 +102,9 @@ namespace GamecraftModdingAPI.Utility /// The extra data to pass to the ILogger. /// This is implemented similar to LogException(Exception e, Dictionary extraData)'s extraData [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void LogException(object obj, Exception e, Dictionary extraData = null) + public static void LogException(Exception e, object obj, Dictionary extraData = null) { - Svelto.Console.LogException(obj.ToString(), e, extraData); + Svelto.Console.LogException(e, obj.ToString(), extraData); } [MethodImpl(MethodImplOptions.AggressiveInlining)] From eba490fbe8a15adf787a5fa4e6163e9d0892ed75 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 8 Feb 2020 22:05:16 +0100 Subject: [PATCH 3/3] Fix issues and add new block IDs --- GamecraftModdingAPI/Blocks/BlockIDs.cs | 17 +++++++++++++---- GamecraftModdingAPI/Blocks/Placement.cs | 3 ++- GamecraftModdingAPI/Blocks/PlacementEngine.cs | 4 +++- .../Events/GameActivatedPatch.cs | 16 ++++++++++++---- .../Events/GameSwitchedToPatch.cs | 4 ++-- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/BlockIDs.cs b/GamecraftModdingAPI/Blocks/BlockIDs.cs index cbe581d..4915041 100644 --- a/GamecraftModdingAPI/Blocks/BlockIDs.cs +++ b/GamecraftModdingAPI/Blocks/BlockIDs.cs @@ -7,8 +7,7 @@ namespace GamecraftModdingAPI.Blocks { AluminiumCube, AxleS, - Battery, - HingeS, + HingeS = 3, MotorS, HingeM, MotorM, @@ -68,8 +67,7 @@ namespace GamecraftModdingAPI.Blocks GlassConeSegment, GlassCylinder, GlassSphere, - Lever, - Reactor, //64 - one ID is skipped + Lever, //63 - two IDs skipped PlayerSpawn = 66, //Crashes without special handling SmallSpawn, MediumSpawn, @@ -154,6 +152,17 @@ namespace GamecraftModdingAPI.Blocks ConcreteSlicedCube, ConcreteSlope, ConcreteCorner, + RoadCarTyre, + OffRoadCarTyre, + RacingCarTyre, + BicycleTyre, + FrontBikeTyre, + RearBikeTyre, + ChopperBikeTyre, + TractorTyre, + MonsterTruckTyre, + MotocrossBikeTyre, + CartTyre, BeachTree1 = 200, BeachTree2, BeachTree3, diff --git a/GamecraftModdingAPI/Blocks/Placement.cs b/GamecraftModdingAPI/Blocks/Placement.cs index d91d214..4e3083b 100644 --- a/GamecraftModdingAPI/Blocks/Placement.cs +++ b/GamecraftModdingAPI/Blocks/Placement.cs @@ -38,8 +38,9 @@ namespace GamecraftModdingAPI.Blocks } catch (Exception e) { + uREPL.Log.Output(e.Message); #if DEBUG - Logging.LogException(e); + //Logging.LogException(e); #endif return false; } diff --git a/GamecraftModdingAPI/Blocks/PlacementEngine.cs b/GamecraftModdingAPI/Blocks/PlacementEngine.cs index 0bcf890..683d14f 100644 --- a/GamecraftModdingAPI/Blocks/PlacementEngine.cs +++ b/GamecraftModdingAPI/Blocks/PlacementEngine.cs @@ -66,6 +66,9 @@ namespace GamecraftModdingAPI.Blocks if (scale.x < 4e-5) scale.x = uscale; if (scale.y < 4e-5) scale.y = uscale; if (scale.z < 4e-5) scale.z = uscale; + uint dbid = block; + if (!PrefabsID.DBIDMAP.ContainsKey(dbid)) + throw new Exception("Block with ID " + dbid + " not found!"); //RobocraftX.CR.MachineEditing.PlaceBlockEngine ScalingEntityStruct scaling = new ScalingEntityStruct {scale = scale}; Quaternion rotQ = Quaternion.Euler(rot); @@ -74,7 +77,6 @@ namespace GamecraftModdingAPI.Blocks {position = position, rotation = rotQ}; CubeCategoryStruct category = new CubeCategoryStruct {category = CubeCategory.General, type = CubeType.Block}; - uint dbid = block; DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid}; uint num = PrefabsID.DBIDMAP[dbid]; GFXPrefabEntityStructGO gfx = new GFXPrefabEntityStructGO {prefabID = num}; diff --git a/GamecraftModdingAPI/Events/GameActivatedPatch.cs b/GamecraftModdingAPI/Events/GameActivatedPatch.cs index b85a6e6..13f4c59 100644 --- a/GamecraftModdingAPI/Events/GameActivatedPatch.cs +++ b/GamecraftModdingAPI/Events/GameActivatedPatch.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -9,24 +10,31 @@ using RobocraftX; using Svelto.ECS; using GamecraftModdingAPI.Utility; +using RobocraftX.CR.MainGame; namespace GamecraftModdingAPI.Events { /// /// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame() /// - [HarmonyPatch(typeof(FullGameCompositionRoot), "ActivateGame")] + [HarmonyPatch] class GameActivatedPatch { - public static void Postfix(ref EnginesRoot ____mainGameEnginesRoot) + public static void Postfix(ref EnginesRoot enginesRoot) { // register custom game engines - GameEngineManager.RegisterEngines(____mainGameEnginesRoot); + GameEngineManager.RegisterEngines(enginesRoot); // A new EnginesRoot is always created when ActivateGame is called // so all event emitters and handlers must be re-registered. - EventManager.RegisterEngines(____mainGameEnginesRoot); + EventManager.RegisterEngines(enginesRoot); Logging.Log("Dispatching Game Activated event"); EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit(); } + + public static MethodBase TargetMethod() + { + return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose") + .MakeGenericMethod(typeof(object)); + } } } diff --git a/GamecraftModdingAPI/Events/GameSwitchedToPatch.cs b/GamecraftModdingAPI/Events/GameSwitchedToPatch.cs index 04cf065..69b6aff 100644 --- a/GamecraftModdingAPI/Events/GameSwitchedToPatch.cs +++ b/GamecraftModdingAPI/Events/GameSwitchedToPatch.cs @@ -20,8 +20,8 @@ namespace GamecraftModdingAPI.Events public static void Postfix() { // Event emitters and handlers should already be registered by GameActivated event - Logging.Log("Dispatching Game Switched To event"); - EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit(); + Logging.Log("Not dispatching Game Switched To event"); + //EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit(); } } }