Debugging, attempting to prevent scale change
This commit is contained in:
parent
72d3f65fb1
commit
9c30f0f3b8
1 changed files with 56 additions and 6 deletions
|
@ -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<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)
|
||||
{
|
||||
|
@ -39,6 +41,7 @@ namespace ExtraCommands.Basics
|
|||
entitiesDB.QueryEntities<GhostScalingEntityStruct>(
|
||||
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group, out uint count);
|
||||
Console.WriteLine("Found " + count + "/" + scalings.Length + " scalings.");
|
||||
var egid = new EGID(0, NamedExclusiveGroup<GHOST_BLOCKS>.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<BlockPlacementScaleEntityStruct>(
|
||||
(ExclusiveGroup.ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.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<BlockPlacementScaleEntityStruct>(egid);
|
||||
Console.WriteLine("Scale published");
|
||||
scaling.scale = _scale;
|
||||
entitiesDB.PublishEntityChange<ScalingEntityStruct>(egid);
|
||||
Console.WriteLine("Scaling published");
|
||||
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()
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue