Browse Source

Add command to disable the environment switch

Was in the test plugin
tags/v1.2.0
NorbiPeti 3 years ago
parent
commit
3e309a4e4c
3 changed files with 77 additions and 0 deletions
  1. +10
    -0
      BuildingTools/BuildingTools.cs
  2. +4
    -0
      BuildingTools/BuildingTools.csproj
  3. +63
    -0
      BuildingTools/NoGarageCommand.cs

+ 10
- 0
BuildingTools/BuildingTools.cs View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DataLoader;
using HarmonyLib;
using TechbloxModdingAPI;
using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Commands;
@@ -237,6 +239,14 @@ namespace BuildingTools
ScalingPermission.NonUniform;
Logging.CommandLog("Free scaling enabled for " + blockID + " until the game is restarted.");
}).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()


+ 4
- 0
BuildingTools/BuildingTools.csproj View File

@@ -37,6 +37,10 @@
<HintPath>..\ref\Plugins\TechbloxModdingAPI.dll</HintPath>
<HintPath>..\..\ref\Plugins\TechbloxModdingAPI.dll</HintPath>
</Reference>
<Reference Include="0Harmony">
<HintPath>..\ref\Plugins\0Harmony.dll</HintPath>
<HintPath>..\..\ref\Plugins\0Harmony.dll</HintPath>
</Reference>
<Reference Include="IllusionInjector">
<HintPath>..\ref\TechbloxPreview_Data\Managed\IllusionInjector.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\IllusionInjector.dll</HintPath>


+ 63
- 0
BuildingTools/NoGarageCommand.cs View 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…
Cancel
Save