diff --git a/GamecraftModdingAPI/App/CurrentGameMode.cs b/GamecraftModdingAPI/App/CurrentGameMode.cs new file mode 100644 index 0000000..84a6d78 --- /dev/null +++ b/GamecraftModdingAPI/App/CurrentGameMode.cs @@ -0,0 +1,23 @@ +namespace GamecraftModdingAPI.App +{ + public enum CurrentGameMode + { + None, + /// + /// Building a game + /// + Build, + /// + /// Playing a game + /// + Play, + /// + /// Viewing a prefab + /// + View, + /// + /// Viewing a tutorial + /// + Tutorial + } +} \ No newline at end of file diff --git a/GamecraftModdingAPI/App/Game.cs b/GamecraftModdingAPI/App/Game.cs index d6a4eff..3d73478 100644 --- a/GamecraftModdingAPI/App/Game.cs +++ b/GamecraftModdingAPI/App/Game.cs @@ -335,6 +335,18 @@ namespace GamecraftModdingAPI.App gameEngine.ToggleTimeMode(); } + /// + /// The mode of the game. + /// + public CurrentGameMode Mode + { + get + { + if (menuMode || !VerifyMode()) return CurrentGameMode.None; + return (CurrentGameMode) GameMode.CurrentMode; + } + } + /// /// Load the game save. /// This happens asynchronously, so when this method returns the game not loaded yet. diff --git a/GamecraftModdingAPI/BlockGroup.cs b/GamecraftModdingAPI/BlockGroup.cs index 4a0d994..eee660a 100644 --- a/GamecraftModdingAPI/BlockGroup.cs +++ b/GamecraftModdingAPI/BlockGroup.cs @@ -203,5 +203,10 @@ namespace GamecraftModdingAPI public bool IsReadOnly { get; } = false; public Block this[int index] => blocks[index]; //Setting is not supported, since the order doesn't matter + + public override string ToString() + { + return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Rotation)}: {Rotation}, {nameof(Count)}: {Count}"; + } } } \ No newline at end of file diff --git a/GamecraftModdingAPI/Blocks/BlueprintEngine.cs b/GamecraftModdingAPI/Blocks/BlueprintEngine.cs index 1936a17..619fda1 100644 --- a/GamecraftModdingAPI/Blocks/BlueprintEngine.cs +++ b/GamecraftModdingAPI/Blocks/BlueprintEngine.cs @@ -36,6 +36,10 @@ namespace GamecraftModdingAPI.Blocks AccessTools.DeclaredField(PlaceBlueprintUtilityType, "_localBlockMap"); private static readonly MethodInfo BuildBlock = AccessTools.Method(PlaceBlueprintUtilityType, "BuildBlock"); private static readonly MethodInfo BuildWires = AccessTools.Method(PlaceBlueprintUtilityType, "BuildWires"); + private static readonly Type SerializeGhostBlueprintType = + AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BoxSelect.SerializeGhostChildrenOnAddEngine"); + private static readonly MethodInfo SerializeGhostBlueprint = + AccessTools.Method(SerializeGhostBlueprintType, "SerializeClipboardGhostEntities"); private static NativeEntityRemove nativeRemove; private static MachineGraphConnectionEntityFactory connectionFactory; @@ -44,6 +48,8 @@ namespace GamecraftModdingAPI.Blocks private static IEntitySerialization entitySerialization; private static IEntityFactory entityFactory; private static FasterList globalBlockMap; + private static object SerializeGhostBlueprintInstance; + private static GhostChildEntityFactory BuildGhostBlueprintFactory; public void Ready() { @@ -130,6 +136,19 @@ namespace GamecraftModdingAPI.Blocks SelectionSerializationUtility.CopySelectionToClipboard(playerID, entitiesDB, serializationData.blueprintData, entitySerialization, entityFactory, blockIDs, (uint) blockIDs.Length, pos, rot, -1); + BuildGhostBlueprint(selected, pos, rot, playerID); + SerializeGhostBlueprint.Invoke(SerializeGhostBlueprintInstance, new object[] {playerID, blueprintID}); + + } + + private void BuildGhostBlueprint(ICollection blocks, float3 pos, quaternion rot, uint playerID) + { + GhostChildUtility.ClearGhostChildren(playerID, entitiesDB, entityFunctions); + foreach (var block in blocks) + { + GhostChildUtility.BuildGhostChild(in playerID, block.Id, in pos, in rot, entitiesDB, + BuildGhostBlueprintFactory, false); + } } public Block[] PlaceBlueprintBlocks(uint blueprintID, uint playerID, float3 pos, float3 rot) @@ -238,6 +257,34 @@ namespace GamecraftModdingAPI.Blocks } } + [HarmonyPatch] + private static class SerializeGhostBlueprintPatch + { + public static void Postfix(object __instance) + { + SerializeGhostBlueprintInstance = __instance; + } + + public static MethodBase TargetMethod() + { + return AccessTools.GetDeclaredConstructors(SerializeGhostBlueprintType)[0]; + } + } + + [HarmonyPatch] + private static class BuildGhostBlueprintPatch + { + public static void Postfix(GhostChildEntityFactory ghostChildEntityFactory) + { + BuildGhostBlueprintFactory = ghostChildEntityFactory; + } + + public static MethodBase TargetMethod() + { + return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine"))[0]; + } + } + public IEntityFactory Factory { get; set; } } } \ No newline at end of file diff --git a/GamecraftModdingAPI/Blueprint.cs b/GamecraftModdingAPI/Blueprint.cs index 458c56c..765de3d 100644 --- a/GamecraftModdingAPI/Blueprint.cs +++ b/GamecraftModdingAPI/Blueprint.cs @@ -72,5 +72,10 @@ namespace GamecraftModdingAPI { BlockGroup._engine.DisposeBlueprint(Id); } + + public override string ToString() + { + return $"{nameof(Id)}: {Id}"; + } } } \ No newline at end of file diff --git a/GamecraftModdingAPI/Player.cs b/GamecraftModdingAPI/Player.cs index 4778e02..0bed6a2 100644 --- a/GamecraftModdingAPI/Player.cs +++ b/GamecraftModdingAPI/Player.cs @@ -1,5 +1,4 @@ using System; -using Gamecraft.GUI.Blueprints; using Unity.Mathematics; using RobocraftX.Common; using RobocraftX.Common.Players; @@ -354,7 +353,13 @@ namespace GamecraftModdingAPI set => BlockGroup._engine.SelectBlueprint(value?.Id ?? uint.MaxValue); } - // object methods + /// + /// The player's mode in time stopped mode, determining what they place. + /// + public PlayerBuildingMode BuildingMode => (PlayerBuildingMode) playerEngine + .GetCharacterStruct(Id, out _).timeStoppedContext; + + // object methods /// /// Teleport the player to the specified coordinates. diff --git a/GamecraftModdingAPI/Players/PlayerBuildingMode.cs b/GamecraftModdingAPI/Players/PlayerBuildingMode.cs new file mode 100644 index 0000000..c7a5e37 --- /dev/null +++ b/GamecraftModdingAPI/Players/PlayerBuildingMode.cs @@ -0,0 +1,10 @@ +namespace GamecraftModdingAPI.Players +{ + public enum PlayerBuildingMode + { + BlockMode, + ColourMode, + ConfigMode, + BlueprintMode + } +} \ No newline at end of file