using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PuttOnly.Core;
using PuttOnly.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("GameAssembly")]
[assembly: IgnoresAccessChecksTo("SharedAssembly")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PuttOnly")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+1b90ff945a285959a9ec2b98a235974fe797ddc3")]
[assembly: AssemblyProduct("PuttOnly")]
[assembly: AssemblyTitle("PuttOnly")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 PuttOnly
{
[BepInPlugin("com.sbg.puttonly", "PuttOnly", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "com.sbg.puttonly";
public const string NAME = "PuttOnly";
public const string VERSION = "1.0.1";
private const string SECTION_GENERAL = "General";
internal static ManualLogSource Log;
internal static ConfigEntry<bool> Enabled;
private void Awake()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Force every swing to be a 0 degree putt. The console command 'puttOnly on|off' changes this for the current session.");
Harmony val = new Harmony("com.sbg.puttonly");
val.PatchAll();
PatchHostSwingCommand.Apply(val);
Log.LogInfo((object)string.Format("[PuttOnly] {0} v{1} loaded. Enabled={2}", "PuttOnly", "1.0.1", Enabled.Value));
}
}
internal static class PuttEnforcer
{
private const float LOG_ANGLE_THRESHOLD_DEGREES = 1f;
private const float RADIANS_TO_DEGREES = 57.29578f;
internal static void Flatten(ref Vector3 worldDirection, ref bool isPutt, PlayerGolfer hitter, string source)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.Enabled.Value)
{
float num = Mathf.Asin(Mathf.Clamp(((Vector3)(ref worldDirection)).normalized.y, -1f, 1f)) * 57.29578f;
Vector3 val = (((Object)(object)hitter != (Object)null) ? ((Component)hitter).transform.forward : Vector3.forward);
(float X, float Y, float Z) tuple = PuttDirection.Flatten(worldDirection.x, worldDirection.y, worldDirection.z, val.x, val.y, val.z);
float item = tuple.X;
float item2 = tuple.Y;
float item3 = tuple.Z;
worldDirection = new Vector3(item, item2, item3);
isPutt = true;
if (num > 1f)
{
Plugin.Log.LogDebug((object)$"[PuttOnly] Flattened a {num:0.#} degree swing ({source}).");
}
}
}
}
internal static class PuttOnlyCommand
{
private const string ARG_ON = "on";
private const string ARG_OFF = "off";
[CCommand("puttOnly", "Force every swing to a 0 degree putt: puttOnly [on|off]", false, false)]
private static void PuttOnly(string state = "")
{
string text = (state ?? string.Empty).Trim().ToLowerInvariant();
if (text == "on" || text == "off")
{
Plugin.Enabled.Value = text == "on";
Plugin.Log.LogInfo((object)$"[PuttOnly] Enabled set to {Plugin.Enabled.Value} from the console.");
ApplyToLocalPlayer();
}
else if (text.Length > 0)
{
Debug.Log((object)"[PuttOnly] Unknown argument. Use: puttOnly on, puttOnly off, or puttOnly to show the state.");
return;
}
Debug.Log((object)("[PuttOnly] Putting only is " + (Plugin.Enabled.Value ? "ON" : "OFF") + "."));
}
private static void ApplyToLocalPlayer()
{
if (Plugin.Enabled.Value && !((Object)(object)GameManager.LocalPlayerAsGolfer == (Object)null))
{
GameManager.LocalPlayerAsGolfer.SetPitch(0f);
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "PuttOnly";
public const string PLUGIN_NAME = "PuttOnly";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace PuttOnly.Patches
{
internal static class PatchHostSwingCommand
{
private const string HANDLER_NAME_PREFIX = "UserCode_CmdHitWithGolfSwing";
internal static void Apply(Harmony harmony)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
MethodInfo methodInfo = typeof(Hittable).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo method) => method.Name.StartsWith("UserCode_CmdHitWithGolfSwing"));
if (methodInfo == null)
{
Plugin.Log.LogError((object)"[PuttOnly] No 'UserCode_CmdHitWithGolfSwing*' method found on Hittable. Swings from players without the mod will not be flattened. The game may have changed how it sends swing commands since this mod was built.");
return;
}
harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(PatchHostSwingCommand), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.Log.LogInfo((object)("[PuttOnly] Patched host swing handler: " + methodInfo.Name));
}
private static void Prefix(ref Vector3 worldDirection, ref bool isPutt, PlayerGolfer hitter)
{
PuttEnforcer.Flatten(ref worldDirection, ref isPutt, hitter, "remote");
}
}
[HarmonyPatch(typeof(Hittable), "HitWithGolfSwing")]
internal static class PatchLocalSwing
{
private static void Prefix(ref Vector3 worldDirection, ref bool isPutt, PlayerGolfer hitter)
{
PuttEnforcer.Flatten(ref worldDirection, ref isPutt, hitter, "local");
}
}
[HarmonyPatch(typeof(PlayerGolfer), "SetPitchInternal")]
internal static class PatchPitchLock
{
private static void Prefix(ref float pitch)
{
if (Plugin.Enabled.Value)
{
pitch = 0f;
}
}
}
}
namespace PuttOnly.Core
{
internal static class PuttDirection
{
private const float MIN_HORIZONTAL_LENGTH = 0.0001f;
public static (float X, float Y, float Z) Flatten(float x, float y, float z, float fallbackX, float fallbackY, float fallbackZ)
{
if (TryNormalizeHorizontal(x, z, out var nx, out var nz))
{
return (X: nx, Y: 0f, Z: nz);
}
if (TryNormalizeHorizontal(fallbackX, fallbackZ, out nx, out nz))
{
return (X: nx, Y: 0f, Z: nz);
}
return (X: 0f, Y: 0f, Z: 1f);
}
private static bool TryNormalizeHorizontal(float x, float z, out float nx, out float nz)
{
float num = (float)Math.Sqrt(x * x + z * z);
if (num < 0.0001f)
{
nx = 0f;
nz = 0f;
return false;
}
nx = x / num;
nz = z / num;
return true;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}