소스 검색

Debugging, attempting to prevent scale change

master
NorbiPeti 4 년 전
부모
커밋
9c30f0f3b8
로그인 계정: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG 키 ID: DBA4C4549A927E56
1개의 변경된 파일56개의 추가작업 그리고 6개의 파일을 삭제
  1. +56
    -6
      extracommands/SetScaleCommandEngine.cs

+ 56
- 6
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<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);
}
}
}
}

불러오는 중...
취소
저장