Add command to disable the environment switch
Was in the test plugin
This commit is contained in:
parent
12fd814c45
commit
3e309a4e4c
3 changed files with 77 additions and 0 deletions
|
@ -1,7 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using DataLoader;
|
using DataLoader;
|
||||||
|
using HarmonyLib;
|
||||||
using TechbloxModdingAPI;
|
using TechbloxModdingAPI;
|
||||||
using TechbloxModdingAPI.Blocks;
|
using TechbloxModdingAPI.Blocks;
|
||||||
using TechbloxModdingAPI.Commands;
|
using TechbloxModdingAPI.Commands;
|
||||||
|
@ -237,6 +239,14 @@ namespace BuildingTools
|
||||||
ScalingPermission.NonUniform;
|
ScalingPermission.NonUniform;
|
||||||
Logging.CommandLog("Free scaling enabled for " + blockID + " until the game is restarted.");
|
Logging.CommandLog("Free scaling enabled for " + blockID + " until the game is restarted.");
|
||||||
}).Build();
|
}).Build();
|
||||||
|
var noGarage = new NoGarageCommand();
|
||||||
|
CommandBuilder.Builder("noGarage", "Disables the environment switching and allows building on the track.")
|
||||||
|
.Action(() =>
|
||||||
|
{
|
||||||
|
noGarage.Toggle();
|
||||||
|
}).Build();
|
||||||
|
|
||||||
|
new Harmony("BuildTools").PatchAll(Assembly.GetExecutingAssembly());
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetBlockInfo()
|
private string GetBlockInfo()
|
||||||
|
|
|
@ -37,6 +37,10 @@
|
||||||
<HintPath>..\ref\Plugins\TechbloxModdingAPI.dll</HintPath>
|
<HintPath>..\ref\Plugins\TechbloxModdingAPI.dll</HintPath>
|
||||||
<HintPath>..\..\ref\Plugins\TechbloxModdingAPI.dll</HintPath>
|
<HintPath>..\..\ref\Plugins\TechbloxModdingAPI.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="0Harmony">
|
||||||
|
<HintPath>..\ref\Plugins\0Harmony.dll</HintPath>
|
||||||
|
<HintPath>..\..\ref\Plugins\0Harmony.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="IllusionInjector">
|
<Reference Include="IllusionInjector">
|
||||||
<HintPath>..\ref\TechbloxPreview_Data\Managed\IllusionInjector.dll</HintPath>
|
<HintPath>..\ref\TechbloxPreview_Data\Managed\IllusionInjector.dll</HintPath>
|
||||||
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\IllusionInjector.dll</HintPath>
|
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\IllusionInjector.dll</HintPath>
|
||||||
|
|
63
BuildingTools/NoGarageCommand.cs
Normal file
63
BuildingTools/NoGarageCommand.cs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace BuildingTools
|
||||||
|
{
|
||||||
|
public class NoGarageCommand
|
||||||
|
{
|
||||||
|
private static bool _enabled;
|
||||||
|
|
||||||
|
public void Toggle()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Toggling no garage");
|
||||||
|
if(_enabled = !_enabled)
|
||||||
|
Enable();
|
||||||
|
Console.WriteLine($"{(_enabled ? "Enabled" : "Disabled")} no garage");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Enable()
|
||||||
|
{
|
||||||
|
var type = AccessTools.TypeByName("Techblox.Environment.Temporary.EnvironmentSwitchEngine");
|
||||||
|
var simObj = (GameObject)AccessTools.Field(type,
|
||||||
|
"THIS_IS_TEMPORARY_CODE_IT_IS_GOING_TO_BE_DELETED_ONCE_WE_HAVE_THE_FINAL_WORLD_SWITCHING_sim_go")
|
||||||
|
.GetValue(null);
|
||||||
|
/*var buildObjField = AccessTools.Field(type,
|
||||||
|
"THIS_IS_TEMPORARY_CODE_IT_IS_GOING_TO_BE_DELETED_ONCE_WE_HAVE_THE_FINAL_WORLD_SWITCHING_build_go");
|
||||||
|
var buildObj = (GameObject) buildObjField.GetValue(null);
|
||||||
|
Console.WriteLine($"obj: {simObj}");*/
|
||||||
|
var componentType = AccessTools.TypeByName("Techblox.Garage.GarageMachineBoundaryImplementor");
|
||||||
|
//var component = buildObj.GetComponent(componentType);
|
||||||
|
//var newBuildObj = Object.Instantiate(simObj);
|
||||||
|
simObj.AddComponent(componentType);
|
||||||
|
var component = simObj.GetComponent(componentType);
|
||||||
|
AccessTools.Field(componentType, "_bounds")
|
||||||
|
.SetValue(component, new Bounds(default, new Vector3(50, 2, 50)));
|
||||||
|
AccessTools.Field(componentType, "_padding")
|
||||||
|
.SetValue(component, 1f);
|
||||||
|
AccessTools.Field(componentType, "_cameraLookPointDistance")
|
||||||
|
.SetValue(component, 1f);
|
||||||
|
//buildObjField.SetValue(null, newBuildObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch]
|
||||||
|
private static class EnvironmentPatch
|
||||||
|
{
|
||||||
|
public static bool Prefix(object __instance)
|
||||||
|
{
|
||||||
|
if (!_enabled) return true;
|
||||||
|
Console.WriteLine("Got a time stopped init event");
|
||||||
|
AccessTools.Method("Techblox.Environment.Temporary.EnvironmentSwitchEngine:OnTimeRunningInitializationComplete")
|
||||||
|
.Invoke(__instance, Array.Empty<object>());
|
||||||
|
Console.WriteLine("Successfully called time running init event");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodBase TargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.Method("Techblox.Environment.Temporary.EnvironmentSwitchEngine:OnTimeStoppedInitializationComplete");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue