using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace RotateBelts
{
[BepInPlugin("com.lll.rotatebelts", "RotateBelts", "1.0.0")]
public class RotateBeltsPlugin : BaseUnityPlugin
{
public const string GUID = "com.lll.rotatebelts";
public const string NAME = "RotateBelts";
public const string VERSION = "1.0.0";
private Harmony _harmony;
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
_harmony = new Harmony("com.lll.rotatebelts");
_harmony.PatchAll(typeof(BlueprintPastePatch));
((BaseUnityPlugin)this).Logger.LogInfo((object)"RotateBelts 1.0.0 loaded!");
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
[HarmonyPatch]
public static class BlueprintPastePatch
{
private static float _rotationX;
private static float _rotationY;
private static float _tiltOffset;
private static bool _beltsOnlyMode;
private static float _totalTiltOffset;
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "DeterminRotate")]
[HarmonyPrefix]
public static bool DeterminRotate_Prefix(BuildTool_BlueprintPaste __instance, ref bool __result)
{
if (__instance.isDragging)
{
return true;
}
if (Input.GetKeyDown((KeyCode)114) && Input.GetKey((KeyCode)306))
{
FilterToBeltsAndSortersOnly(__instance);
_rotationX += 90f;
_rotationX = Mathf.Repeat(_rotationX, 360f);
ApplyCustomRotations(__instance);
__result = true;
return false;
}
if (Input.GetKeyDown((KeyCode)114) && Input.GetKey((KeyCode)304))
{
FilterToBeltsAndSortersOnly(__instance);
_rotationY += 90f;
_rotationY = Mathf.Repeat(_rotationY, 360f);
ApplyCustomRotations(__instance);
__result = true;
return false;
}
return true;
}
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "DeterminAnchorType")]
[HarmonyPrefix]
public static bool DeterminAnchorType_Prefix(BuildTool_BlueprintPaste __instance, ref bool __result)
{
if (__instance.isDragging)
{
return true;
}
if (Input.GetKeyDown((KeyCode)96))
{
FilterToBeltsAndSortersOnly(__instance);
_tiltOffset += 15f;
_tiltOffset = Mathf.Repeat(_tiltOffset, 360f);
_totalTiltOffset += 15f;
_totalTiltOffset = Mathf.Repeat(_totalTiltOffset, 360f);
ApplyTiltOffset(__instance);
__result = true;
return false;
}
return true;
}
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "ResetStates")]
[HarmonyPostfix]
public static void ResetStates_Postfix()
{
_rotationX = 0f;
_rotationY = 0f;
_tiltOffset = 0f;
_beltsOnlyMode = false;
_totalTiltOffset = 0f;
}
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "ResetStatesOnClose")]
[HarmonyPostfix]
public static void ResetStatesOnClose_Postfix()
{
_rotationX = 0f;
_rotationY = 0f;
_tiltOffset = 0f;
_beltsOnlyMode = false;
_totalTiltOffset = 0f;
}
private static void FilterToBeltsAndSortersOnly(BuildTool_BlueprintPaste tool)
{
if (_beltsOnlyMode || tool.blueprint == null || tool.blueprint.buildings == null)
{
return;
}
BlueprintBuilding[] buildings = tool.blueprint.buildings;
foreach (BlueprintBuilding val in buildings)
{
if (val == null || val.itemId <= 0)
{
continue;
}
ModelProto val2 = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)val.modelIndex);
if (val2 != null && val2.prefabDesc != null)
{
PrefabDesc prefabDesc = val2.prefabDesc;
if (!prefabDesc.isBelt && !prefabDesc.isInserter)
{
val.index = -1;
}
}
}
_beltsOnlyMode = true;
}
private static void ApplyCustomRotations(BuildTool_BlueprintPaste tool)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
if (tool.blueprint == null || tool.blueprint.buildings == null)
{
return;
}
BlueprintBuilding[] buildings = tool.blueprint.buildings;
Quaternion val = Quaternion.Euler(_rotationX, 0f, 0f);
Quaternion val2 = Quaternion.Euler(0f, _rotationY, 0f) * val;
Vector3 val9 = default(Vector3);
Vector3 val11 = default(Vector3);
foreach (BlueprintBuilding val3 in buildings)
{
if (val3 == null || val3.index < 0)
{
continue;
}
ModelProto val4 = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)val3.modelIndex);
if (val4 == null || val4.prefabDesc == null)
{
continue;
}
PrefabDesc prefabDesc = val4.prefabDesc;
if (prefabDesc.isBelt || prefabDesc.isInserter)
{
Quaternion val5 = Quaternion.Euler(val3.pitch, val3.yaw, val3.tilt);
Quaternion val6 = val2 * val5;
Vector3 eulerAngles = ((Quaternion)(ref val6)).eulerAngles;
val3.pitch = eulerAngles.x;
val3.yaw = eulerAngles.y;
val3.tilt = eulerAngles.z;
if (prefabDesc.isInserter)
{
Quaternion val7 = Quaternion.Euler(val3.pitch2, val3.yaw2, val3.tilt2);
Quaternion val8 = val2 * val7;
Vector3 eulerAngles2 = ((Quaternion)(ref val8)).eulerAngles;
val3.pitch2 = eulerAngles2.x;
val3.yaw2 = eulerAngles2.y;
val3.tilt2 = eulerAngles2.z;
}
((Vector3)(ref val9))..ctor(val3.localOffset_x, val3.localOffset_y, val3.localOffset_z);
Vector3 val10 = val2 * val9;
val3.localOffset_x = val10.x;
val3.localOffset_y = val10.y;
val3.localOffset_z = val10.z;
if (prefabDesc.isInserter || prefabDesc.isBelt)
{
((Vector3)(ref val11))..ctor(val3.localOffset_x2, val3.localOffset_y2, val3.localOffset_z2);
Vector3 val12 = val2 * val11;
val3.localOffset_x2 = val12.x;
val3.localOffset_y2 = val12.y;
val3.localOffset_z2 = val12.z;
}
}
}
_rotationX = 0f;
_rotationY = 0f;
}
private static void ApplyTiltOffset(BuildTool_BlueprintPaste tool)
{
if (tool.blueprint == null || tool.blueprint.buildings == null)
{
return;
}
BlueprintBuilding[] buildings = tool.blueprint.buildings;
foreach (BlueprintBuilding val in buildings)
{
if (val != null && val.index >= 0)
{
ModelProto val2 = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)val.modelIndex);
if (val2 != null && val2.prefabDesc != null && val2.prefabDesc.isBelt)
{
val.tilt += 15f;
val.tilt = Mathf.Repeat(val.tilt, 360f);
}
}
}
_tiltOffset = 0f;
}
[HarmonyPatch(typeof(BuildModel), "LateGameTickIgnoreActive")]
[HarmonyPostfix]
public static void LateGameTickIgnoreActive_Postfix(BuildModel __instance)
{
if (_beltsOnlyMode && Mathf.Abs(_totalTiltOffset) > 0.01f)
{
string text = $"Tilt: +{_totalTiltOffset:F0}°";
if (!string.IsNullOrEmpty(UIGeneralTips.buildCursorText))
{
UIGeneralTips.buildCursorText = UIGeneralTips.buildCursorText + "\n" + text;
}
else
{
UIGeneralTips.buildCursorText = text;
}
}
}
}
}