Debugging, attempting to prevent scale change

This commit is contained in:
Norbi Peti 2020-01-17 02:04:12 +01:00
parent 72d3f65fb1
commit 9c30f0f3b8
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -1,4 +1,6 @@
using System; using System;
using System.Reflection;
using Harmony;
using RobocraftX.GUI.CommandLine; using RobocraftX.GUI.CommandLine;
using RobocraftX.Multiplayer; using RobocraftX.Multiplayer;
using RobocraftX.StateSync; using RobocraftX.StateSync;
@ -30,7 +32,7 @@ namespace ExtraCommands.Basics
CustomCommandUtility.Register<float, float, float>("SetScale", SetScaleCommand, "Set the scale for the next block. Use 0 0 0 to reset. The displayed cube is uniformly scaled until placed."); CustomCommandUtility.Register<float, float, float>("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) private void SetScaleCommand(float x, float y, float z)
{ {
@ -39,6 +41,7 @@ namespace ExtraCommands.Basics
entitiesDB.QueryEntities<GhostScalingEntityStruct>( entitiesDB.QueryEntities<GhostScalingEntityStruct>(
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out uint count); (ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out uint count);
Console.WriteLine("Found " + count + "/" + scalings.Length + " scalings."); Console.WriteLine("Found " + count + "/" + scalings.Length + " scalings.");
var egid = new EGID(0, NamedExclusiveGroup<GHOST_BLOCKS>.Group);
for (int index = 0; index < count; index++) for (int index = 0; index < count; index++)
{ {
Console.WriteLine("G scaling " + index + ": " + scalings[index].ghostScale); Console.WriteLine("G scaling " + index + ": " + scalings[index].ghostScale);
@ -48,18 +51,28 @@ namespace ExtraCommands.Basics
ref var scale = ref entitiesDB.QueryEntities<BlockPlacementScaleEntityStruct>( ref var scale = ref entitiesDB.QueryEntities<BlockPlacementScaleEntityStruct>(
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out _)[index]; (ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out _)[index];
Console.WriteLine("Scale " + index + ": " + scale.snapGridScale); 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, 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; Console.WriteLine("Attempting to update scale...");
scale.snapGridScale = (int) _scale.x; if (_scale.x < 4e-5 || _scale.y < 4e-5 || _scale.z < 4e-5) return;
scale.blockPlacementHeight = (int) _scale.y; 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<BlockPlacementScaleEntityStruct>(egid);
Console.WriteLine("Scale published");
scaling.scale = _scale; scaling.scale = _scale;
entitiesDB.PublishEntityChange<ScalingEntityStruct>(egid);
Console.WriteLine("Scaling published");
gscaling.ghostScale = _scale; gscaling.ghostScale = _scale;
gscaling.hasBlockBeenUnformedScaled = true; //Apply scale instead of overwriting it
entitiesDB.PublishEntityChange<GhostScalingEntityStruct>(egid);
Console.WriteLine("Scale updated (" + scaling.scale + ")");
} }
public override void Dispose() public override void Dispose()
@ -81,5 +94,42 @@ namespace ExtraCommands.Basics
public void Remove(ref GhostScalingEntityStruct entityView, EGID egid) 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);
}
}
} }
} }