diff --git a/BuildingTools/BuildingTools.cs b/BuildingTools/BuildingTools.cs index 5edf947..1d5b899 100644 --- a/BuildingTools/BuildingTools.cs +++ b/BuildingTools/BuildingTools.cs @@ -49,7 +49,7 @@ namespace BuildingTools block.Position = (float3) (reference + (block.Position - reference) * scale); } - Logging.CommandLog("Blocks scaled."); + Logging.CommandLog("Blocks scaled and moved."); }); _commandUtils.RegisterBlockCommand("scaleIndividually", "Scales the blocks you're looking at, but doesn't move them." + " The scale is relative, 1 means no change.", @@ -59,6 +59,7 @@ namespace BuildingTools float3 scale = new float3(scaleX, scaleY, scaleZ); foreach (var block in blocks) block.Scale *= scale; + Logging.CommandLog("Blocks scaled individually."); }); _commandUtils.RegisterBlockCommand("moveBlocks", "Moves (teleports) the selected blocks around both in time stopped and running. The latter will be reset as expected.", (x, y, z, blocks, refBlock) => { @@ -68,6 +69,7 @@ namespace BuildingTools else if (GameState.IsSimulationMode()) foreach (var body in GetSimBodies(blocks)) body.Position += new float3(x, y, z); + Logging.CommandLog("Blocks moved."); }); _commandUtils.RegisterBlockCommand("colorBlocks", "Colors the selected blocks permanently both in time stopped and running. It won't be reset when stopping time.", (color, darkness, blocks, refBlock) => @@ -80,6 +82,7 @@ namespace BuildingTools foreach (var block in blocks) block.Color = new BlockColor {Color = clr, Darkness = darkness}; + Logging.CommandLog("Blocks colored."); }); CommandBuilder.Builder("selectBlocksLookedAt", @@ -118,6 +121,22 @@ namespace BuildingTools _blockSelections.refBlock = _blockSelections.blocks.Length > 0 ? _blockSelections.blocks[0] : null; Logging.CommandLog(_blockSelections.blocks.Length + " blocks selected."); }).Build(); + CommandBuilder.Builder("selectBlocksInGroup", + "Selects the blocks in the block group you are looking at (the blocks currently highlighted when in blueprint mode).") + .Action(() => + { + var block = Player.LocalPlayer.GetBlockLookedAt(); + if (block is null) + { + Logging.CommandLogError("You need to look at a block first (and be close to it)."); + return; + } + + var group = block.BlockGroup; + _blockSelections.blocks = group is null ? new[] {block} : group.ToArray(); + _blockSelections.refBlock = block; + Logging.CommandLog(_blockSelections.blocks.Length + " blocks selected."); + }).Build(); /*ConsoleCommands.RegisterWithChannel("selectSendSignal", ch => { }, ChannelType.Object, "Sends a signal for selecting a given object ID for a command block.");*/ @@ -132,6 +151,7 @@ namespace BuildingTools } foreach (var block in GetSimBodies(blocks)) block.Velocity += new float3(x, y, z); + Logging.CommandLog("Blocks pushed."); }); _commandUtils.RegisterBlockCommand("pushRotateBlocks", "Adds angular velocity to the selected blocks. Only works in simulation.", @@ -144,25 +164,65 @@ namespace BuildingTools } foreach (var block in GetSimBodies(blocks)) block.AngularVelocity += new float3(x, y, z); + Logging.CommandLog("Blocks pushed to rotate."); }); CommandBuilder.Builder("pushPlayer", "Adds velocity to the player.") .Action((x, y, z) => { Player.LocalPlayer.Velocity += new float3(x, y, z); + Logging.CommandLog("Player pushed."); }).Build(); CommandBuilder.Builder("pushRotatePlayer", "Adds angular velocity to the player.") .Action((x, y, z) => { Player.LocalPlayer.AngularVelocity += new float3(x, y, z); + Logging.CommandLog("Player pushed to rotate."); + }).Build(); + CommandBuilder.Builder("addBlocksToGroup", + "Adds the selected blocks to the same group (they will be highlighted together)." + + " This command recreates the blocks that are moved into the group, but block data is almost certainly preserved.") + .Action(() => + { + if (_blockSelections.blocks.Length == 0) + { + Logging.CommandLogWarning("No blocks selected. Use a select command first."); + return; + } + + var group = _blockSelections.refBlock.BlockGroup; + uint refID = _blockSelections.refBlock.Id.entityID; + if (group is null) + { + var copy = _blockSelections.refBlock.Copy(); + group = BlockGroup.Create(copy); + _blockSelections.refBlock.Remove(); + _blockSelections.refBlock = copy; + } + + _blockSelections.blocks = _blockSelections.blocks.Where(block => block.Id.entityID != refID) + .Select(block => + { + if (block.BlockGroup == group) return block; + var copy = block.Copy(); + group.Add(copy); + block.Remove(); + return copy; + }).ToArray(); }).Build(); + var noClip = new NoClipCommand(); GameEngineManager.AddGameEngine(noClip); - CommandBuilder.Builder("noClip", "Allows you to go through blocks. Run again to disable.") + CommandBuilder.Builder("noclip", "Allows you to go through blocks. Run again to disable. Disable before entering the menu.") .Action(noClip.Toggle).Build(); CommandBuilder.Builder("freeScaling", "This command removes scaling restrictions on the selected block. Reselect block to apply.") .Action(() => { var blockID = Player.LocalPlayer.SelectedBlock; + if (blockID == BlockIDs.Invalid) + { + Logging.CommandLogWarning("You don't have any blocks in your hand."); + return; + } FullGameFields._dataDb.GetValue((int) blockID).scalingPermission = ScalingPermission.NonUniform; Logging.CommandLog("Free scaling enabled for " + blockID + " until the game is restarted."); @@ -191,7 +251,8 @@ namespace BuildingTools $"- Color: {block.Color.Color} darkness: {block.Color.Darkness}\n" + $"- Scale: {scale.x:F} {scale.y:F} {scale.z:F}\n" + $"- Label: {block.Label}\n" + - $"- ID: {block.Id}"; + $"- ID: {block.Id}\n" + + $"- Group: {block.BlockGroup.Id}"; } private static string GetBodyInfoInSimMode() @@ -238,6 +299,6 @@ namespace BuildingTools public override void OnApplicationQuit() => Main.Shutdown(); public override string Name { get; } = "BuildingTools"; - public override string Version { get; } = "v1.0.0"; + public override string Version { get; } = "v1.1.0"; } } \ No newline at end of file diff --git a/BuildingTools/BuildingTools.csproj b/BuildingTools/BuildingTools.csproj index 9eb0419..abf3fb4 100644 --- a/BuildingTools/BuildingTools.csproj +++ b/BuildingTools/BuildingTools.csproj @@ -11,7 +11,7 @@ net48 512 true - 1.0.1 + 1.1.0 AnyCPU diff --git a/BuildingTools/NoClipCommand.cs b/BuildingTools/NoClipCommand.cs index 611ae74..7eb75a6 100644 --- a/BuildingTools/NoClipCommand.cs +++ b/BuildingTools/NoClipCommand.cs @@ -57,8 +57,7 @@ namespace BuildingTools public void Toggle() { - // ReSharper disable once AssignmentInConditionalExpression - if (_enabled = !_enabled) Enable(); + if (_enabled) Enable(); else Disable(); } @@ -70,7 +69,6 @@ namespace BuildingTools ChangeCollider(_collisionFilter); if (!entitiesDB.Exists(0U, CommonExclusiveGroups.GameStateGroup)) { - //Disable(); yield break; } @@ -78,66 +76,21 @@ namespace BuildingTools } } - //private BlobAssetReference ChangeCollider(CollisionFilter? newFilter, BlobAssetReference? newCollider) private CollisionFilter ChangeCollider(CollisionFilter newFilter) { foreach (var group in CharacterExclusiveGroups.AllCharacters) { - /*if (!Player.Exists(PlayerType.Local)) - continue;*/ if (!entitiesDB.Exists(new EGID(Player.LocalPlayer.Id, group))) continue; ref var uecsEntity = ref entitiesDB.QueryEntity(new EGID(Player.LocalPlayer.Id, group)); - Console.WriteLine("Found physics entity " + uecsEntity.ID); var collider = _entityManager.GetComponentData(uecsEntity.uecsEntity); - //var collider = _entityManager.GetComponentData(uecsEntity.uecsEntity); - //Console.WriteLine("Collider: " + collider.sphereCollider.Value.Filter.BelongsTo); - /*unsafe - { - Console.WriteLine("Collider ptr: " + (long) collider.ColliderPtr); - } - - Console.WriteLine("Old filter: " + collider.Value.Value.Filter.BelongsTo); - - Console.WriteLine("Collider type: " + collider.Value.Value.Type); - - var oldCollider = collider.Value; - if (newFilter.HasValue) - { - unsafe - { - var colRef = ColliderUtilityUECS.ClonePhysicsCollider(collider.ColliderPtr, newFilter.Value); - collider.Value = colRef; - //collider.Value.Value.Filter = newFilter.Value; - Console.WriteLine("New filter: " + collider.Value.Value.Filter.BelongsTo); - Console.WriteLine("Should be: " + newFilter.Value.BelongsTo); - Console.WriteLine("New collider ptr: " + (long) collider.ColliderPtr); - } - } - else if (newCollider.HasValue) - collider.Value = newCollider.Value; - - //Console.WriteLine("New collider: " + collider.sphereCollider.Value.Filter.BelongsTo); - _entityManager.SetComponentData(uecsEntity.uecsEntity, collider); - Console.WriteLine("Resulting filter: " + _entityManager - .GetComponentData(uecsEntity.uecsEntity).Value.Value.Filter - .BelongsTo); - unsafe - { - Console.WriteLine("Resulting collider ptr: " + (long) _entityManager - .GetComponentData(uecsEntity.uecsEntity).ColliderPtr); - } - - return oldCollider;*/ unsafe { var coll = (CompoundCollider*) collider.Value.GetUnsafePtr(); var filter = coll->Filter; coll->Filter = newFilter; - Console.WriteLine("Changed filter from " + filter.BelongsTo + " to " + newFilter.BelongsTo); - //_entityManager.SetComponentData(uecsEntity.uecsEntity, collider); return filter; } } @@ -154,7 +107,6 @@ namespace BuildingTools public void Ready() { - new Harmony("BuildingTools").PatchAll(Assembly.GetExecutingAssembly()); } public EntitiesDB entitiesDB { get; set; } @@ -164,19 +116,5 @@ namespace BuildingTools public string Name { get; } = "BuildingToolsNoClipEngine"; public bool isRemovable { get; } = true; - - [HarmonyPatch] - public static class Patch - { - public static void Prefix(CompoundCollider __instance, CollisionFilter value) - { - Console.WriteLine("Compound collider filter changed for " + __instance.Type + " to " + value.BelongsTo); - } - - public static MethodBase TargetMethod() - { - return typeof(CompoundCollider).GetProperty("Filter").SetMethod; - } - } } } \ No newline at end of file