Decompiled source of CameraFix v0.1.1

CameraFix.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CameraFix;

[BepInPlugin("com.CN_TAOZI.CameraFix", "CameraFix", "0.1.1")]
public class CameraFixPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "com.CN_TAOZI.CameraFix";

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> CrystalBallNoCameraOverride;

	internal static ConfigEntry<bool> HourglassNoLookSpeedSlow;

	private void Awake()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_0093: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		CrystalBallNoCameraOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("CrystalBall", "DisableCameraOverride", true, "拿着水晶球时保持正常第一人称视角(不把相机塞进球里、不强拉瞄准和转身)。");
		HourglassNoLookSpeedSlow = ((BaseUnityPlugin)this).Config.Bind<bool>("Hourglass", "DisableLookSpeedSlow", true, "拿着沙漏时不再把鼠标转向速度拖慢(沙漏的减速/滤镜等其余效果保留)。");
		Harmony val = new Harmony("com.CN_TAOZI.CameraFix");
		TryPatch(val, typeof(CrystalBallPatch), "水晶球");
		TryPatch(val, typeof(TimeGlassPatch), "沙漏");
		TryPatch(val, typeof(OverrideLookSpeedPatch), "转视角速度");
		Log.LogInfo((object)$"CameraFix 已加载:水晶球吸视角=关闭({CrystalBallNoCameraOverride.Value}),沙漏拖慢转视角=关闭({HourglassNoLookSpeedSlow.Value})");
	}

	private static void TryPatch(Harmony harmony, Type patchType, string label)
	{
		try
		{
			harmony.PatchAll(patchType);
			Log.LogInfo((object)("[CameraFix] 补丁成功:" + label + "(" + patchType.Name + ")"));
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"[CameraFix] 补丁失败:{label}({patchType.Name}):{arg}");
		}
	}
}
[HarmonyPatch(typeof(CrystalBallValuable), "StateActive")]
internal static class CrystalBallPatch
{
	private static bool Prefix(CrystalBallValuable __instance)
	{
		if (!CameraFixPlugin.CrystalBallNoCameraOverride.Value)
		{
			return true;
		}
		PhysGrabObject component = ((Component)__instance).GetComponent<PhysGrabObject>();
		if ((Object)(object)component == (Object)null || !component.grabbedLocal)
		{
			return true;
		}
		return false;
	}
}
internal static class HourglassScope
{
	internal static bool SuppressLookSpeed;
}
[HarmonyPatch(typeof(ValuableWizardTimeGlass), "StateActive")]
internal static class TimeGlassPatch
{
	private static void Prefix()
	{
		HourglassScope.SuppressLookSpeed = CameraFixPlugin.HourglassNoLookSpeedSlow.Value;
	}

	private static void Postfix()
	{
		HourglassScope.SuppressLookSpeed = false;
	}
}
[HarmonyPatch(typeof(PlayerController), "OverrideLookSpeed")]
internal static class OverrideLookSpeedPatch
{
	private static bool Prefix()
	{
		return !HourglassScope.SuppressLookSpeed;
	}
}