From 9c30f0f3b83aa62c6d206fb05c5d02e4ce02f79a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 17 Jan 2020 02:04:12 +0100 Subject: [PATCH] Debugging, attempting to prevent scale change --- extracommands/SetScaleCommandEngine.cs | 62 +++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/extracommands/SetScaleCommandEngine.cs b/extracommands/SetScaleCommandEngine.cs index 62fefdb..cab399f 100644 --- a/extracommands/SetScaleCommandEngine.cs +++ b/extracommands/SetScaleCommandEngine.cs @@ -1,4 +1,6 @@ using System; +using System.Reflection; +using Harmony; using RobocraftX.GUI.CommandLine; using RobocraftX.Multiplayer; using RobocraftX.StateSync; @@ -30,7 +32,7 @@ namespace ExtraCommands.Basics CustomCommandUtility.Register("SetScale", SetScaleCommand, "Set the scale for the next block. Use 0 0 0 to reset. The displayed cube is uniformly scaled until placed."); } - private float3 _scale; + private static float3 _scale; private void SetScaleCommand(float x, float y, float z) { @@ -39,6 +41,7 @@ namespace ExtraCommands.Basics entitiesDB.QueryEntities( (ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup.Group, out uint count); Console.WriteLine("Found " + count + "/" + scalings.Length + " scalings."); + var egid = new EGID(0, NamedExclusiveGroup.Group); for (int index = 0; index < count; index++) { Console.WriteLine("G scaling " + index + ": " + scalings[index].ghostScale); @@ -48,18 +51,28 @@ namespace ExtraCommands.Basics ref var scale = ref entitiesDB.QueryEntities( (ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup.Group, out _)[index]; Console.WriteLine("Scale " + index + ": " + scale.snapGridScale); - UpdateScale(ref scale, ref scaling, ref scalings[index]); + UpdateScale(ref scale, ref scaling, ref scalings[index], egid); } } private void UpdateScale(ref BlockPlacementScaleEntityStruct scale, ref ScalingEntityStruct scaling, - ref GhostScalingEntityStruct gscaling) + ref GhostScalingEntityStruct gscaling, EGID egid) { - if (_scale.x < 4e5 || _scale.y < 4e5 || _scale.z < 4e5) return; - scale.snapGridScale = (int) _scale.x; - scale.blockPlacementHeight = (int) _scale.y; + Console.WriteLine("Attempting to update scale..."); + if (_scale.x < 4e-5 || _scale.y < 4e-5 || _scale.z < 4e-5) return; + Console.WriteLine("Scale is set, continuing."); + scale.snapGridScale = Math.Max((int) _scale.x, 1); + scale.blockPlacementHeight = Math.Max((int) _scale.y, 1); + scale.desiredScaleFactor = Math.Max((int) _scale.x, 1); + entitiesDB.PublishEntityChange(egid); + Console.WriteLine("Scale published"); scaling.scale = _scale; + entitiesDB.PublishEntityChange(egid); + Console.WriteLine("Scaling published"); gscaling.ghostScale = _scale; + gscaling.hasBlockBeenUnformedScaled = true; //Apply scale instead of overwriting it + entitiesDB.PublishEntityChange(egid); + Console.WriteLine("Scale updated (" + scaling.scale + ")"); } public override void Dispose() @@ -81,5 +94,42 @@ namespace ExtraCommands.Basics public void Remove(ref GhostScalingEntityStruct entityView, EGID egid) { }*/ + //ScaleGhostBlockEngine.UpdateScaling + [HarmonyPatch] + public class ScalePatch + { + static bool Prefix() + { + if (math.any(_scale < new float3(4e-5))) + return true; + return false; //Prevent updating + } + + static MethodBase TargetMethod(HarmonyInstance instance) + { + return typeof(ScaleGhostBlockEngine).GetMethod("UpdateScaling", + BindingFlags.NonPublic | BindingFlags.Instance); + } + } + //UniformScaleGhostBlockEngine.SimulatePhysicsStep - Does not update the ghost block but the outline still gets rounded + //RobocraftX.Blocks.Ghost.GhostScalingSyncEngine (reflection) - Doesn't do anything immediately visible + //[HarmonyPatch(typeof(UniformScaleGhostBlockEngine))] + //[HarmonyPatch("SimulatePhysicsStep")] + [HarmonyPatch] + public class UniformScalePatch + { + static bool Prefix() + { + if (math.any(_scale < new float3(4e-5))) + return true; + return false; //Prevent updating + } + + static MethodBase TargetMethod(HarmonyInstance instance) + { + return Type.GetType("RobocraftX.Blocks.Ghost.GhostScalingSyncEngine").GetMethod("SimulatePhysicsStep", + BindingFlags.NonPublic | BindingFlags.Instance); + } + } } } \ No newline at end of file