using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Free2Move.Extensions;
using Free2Move.FeatureInfo;
using Free2Move.Features;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Lordfirespeed")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allow 360° movement (movement in any direction) when using axis inputs such as thumbsticks.")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2+807070e86d879bd98f5f47af125d791f4d8425e1")]
[assembly: AssemblyProduct("Free2Move")]
[assembly: AssemblyTitle("lordfirespeed.free_2_move")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/lordfirespeed/lethal-company-free2move")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 System.Runtime.Versioning
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class RequiresPreviewFeaturesAttribute : Attribute
{
public string? Message { get; }
public string? Url { get; set; }
public RequiresPreviewFeaturesAttribute()
{
}
public RequiresPreviewFeaturesAttribute(string? message)
{
Message = message;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
public string ParameterName { get; }
public CallerArgumentExpressionAttribute(string parameterName)
{
ParameterName = parameterName;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CollectionBuilderAttribute : Attribute
{
public Type BuilderType { get; }
public string MethodName { get; }
public CollectionBuilderAttribute(Type builderType, string methodName)
{
BuilderType = builderType;
MethodName = methodName;
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public const string RefStructs = "RefStructs";
public const string RequiredMembers = "RequiredMembers";
public string FeatureName { get; }
public bool IsOptional { get; set; }
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
}
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
{
public string[] Arguments { get; }
public InterpolatedStringHandlerArgumentAttribute(string argument)
{
Arguments = new string[1] { argument };
}
public InterpolatedStringHandlerArgumentAttribute(params string[] arguments)
{
Arguments = arguments;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class InterpolatedStringHandlerAttribute : Attribute
{
}
[EditorBrowsable(EditorBrowsableState.Never)]
[ExcludeFromCodeCoverage]
internal static class IsExternalInit
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class ModuleInitializerAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class RequiredMemberAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[ExcludeFromCodeCoverage]
internal sealed class RequiresLocationAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class SkipLocalsInitAttribute : Attribute
{
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class ExperimentalAttribute : Attribute
{
public string DiagnosticId { get; }
public string? UrlFormat { get; set; }
public ExperimentalAttribute(string diagnosticId)
{
DiagnosticId = diagnosticId;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class StringSyntaxAttribute : Attribute
{
public const string CompositeFormat = "CompositeFormat";
public const string DateOnlyFormat = "DateOnlyFormat";
public const string DateTimeFormat = "DateTimeFormat";
public const string EnumFormat = "EnumFormat";
public const string GuidFormat = "GuidFormat";
public const string Json = "Json";
public const string NumericFormat = "NumericFormat";
public const string Regex = "Regex";
public const string TimeOnlyFormat = "TimeOnlyFormat";
public const string TimeSpanFormat = "TimeSpanFormat";
public const string Uri = "Uri";
public const string Xml = "Xml";
public string Syntax { get; }
public object?[] Arguments { get; }
public StringSyntaxAttribute(string syntax)
{
Syntax = syntax;
Arguments = new object[0];
}
public StringSyntaxAttribute(string syntax, params object?[] arguments)
{
Syntax = syntax;
Arguments = arguments;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class UnscopedRefAttribute : Attribute
{
}
}
namespace Free2Move
{
public class Free2MoveConfig
{
private class ConfigEntryBuilder<T>
{
public required ConfigDefinition Definition { get; init; }
public required T DefaultValue { get; init; }
public required ConfigDescription Description { get; init; }
public required ConfigFile ConfigFile { get; init; }
public ConfigEntry<T> Bind()
{
return ConfigFile.Bind<T>(Definition, DefaultValue, Description);
}
public static implicit operator ConfigEntry<T>(ConfigEntryBuilder<T> builder)
{
return builder.Bind();
}
}
private const string DefaultSection = "General";
public readonly ConfigEntry<bool> Enabled;
public Free2MoveConfig(BaseUnityPlugin plugin)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
Enabled = new ConfigEntryBuilder<bool>
{
ConfigFile = plugin.Config,
Definition = new ConfigDefinition("General", "Enabled"),
DefaultValue = true,
Description = new ConfigDescription("Globally enable/disable the plugin", (AcceptableValueBase)null, Array.Empty<object>())
};
}
}
public class Free2MovePatcher : MonoBehaviour
{
private readonly IList<IFeatureInfo<IFeature>> _features = new List<IFeatureInfo<IFeature>>(2)
{
new FeatureInfo<MoveInAnyDirection>
{
Name = "Free Movement",
EnabledCondition = () => BoundConfig.Enabled.Value,
ListenToConfigEntries = (ConfigEntryBase[])(object)new ConfigEntryBase[1] { (ConfigEntryBase)BoundConfig.Enabled }
},
new FeatureInfo<MoveInCardinalDirections>
{
Name = "Restrict Movement",
EnabledCondition = () => !BoundConfig.Enabled.Value,
ListenToConfigEntries = (ConfigEntryBase[])(object)new ConfigEntryBase[1] { (ConfigEntryBase)BoundConfig.Enabled }
}
};
internal static PluginInfo Info { get; set; }
internal static ManualLogSource Logger => Free2MovePlugin.Logger;
internal static Free2MoveConfig BoundConfig => Free2MovePlugin.BoundConfig;
private void Start()
{
FeatureInfoInitializers.HarmonyFactory = (string harmonyName) => new Harmony("lordfirespeed.free_2_move-" + harmonyName);
FeatureInfoInitializers.LogSourceFactory = (string patchName) => Logger.CreateLogSource("Free2Move/" + patchName);
Logger.LogInfo((object)"Initialising features...");
CollectionExtensions.Do<IFeatureInfo<IFeature>>((IEnumerable<IFeatureInfo<IFeature>>)_features, (Action<IFeatureInfo<IFeature>>)delegate(IFeatureInfo<IFeature> patch)
{
patch.Initialise();
});
Logger.LogInfo((object)"Done!");
}
private void OnDestroy()
{
CollectionExtensions.Do<IFeatureInfo<IFeature>>((IEnumerable<IFeatureInfo<IFeature>>)_features, (Action<IFeatureInfo<IFeature>>)delegate(IFeatureInfo<IFeature> patch)
{
patch.Dispose();
});
}
}
[BepInPlugin("lordfirespeed.free_2_move", "Free2Move", "0.1.2")]
public sealed class Free2MovePlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; private set; }
internal static Free2MoveConfig BoundConfig { get; private set; }
private void Awake()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
BoundConfig = new Free2MoveConfig((BaseUnityPlugin)(object)this);
GameObject val = new GameObject("Free2Move")
{
hideFlags = (HideFlags)61
};
val.AddComponent<Free2MovePatcher>();
Object.DontDestroyOnLoad((Object)val);
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "lordfirespeed.free_2_move";
public const string PLUGIN_NAME = "Free2Move";
public const string PLUGIN_VERSION = "0.1.2";
}
}
namespace Free2Move.Features
{
public interface IFeature
{
ManualLogSource Logger
{
set
{
}
}
Harmony Harmony
{
set
{
}
}
void OnEnable()
{
}
void OnDisable()
{
}
void OnConfigChange()
{
}
}
public interface IPlayerInputActionFeature
{
static InputActionAsset PlayerInputActions => IngamePlayerSettings.Instance.playerInput.actions;
static InputAction PlayerMoveAction => PlayerInputActions.FindAction("Move", true);
}
public sealed class MoveInAnyDirection : IFeature, IPlayerInputActionFeature
{
private static ManualLogSource _logger;
ManualLogSource IFeature.Logger
{
set
{
_logger = value;
}
}
public void OnEnable()
{
SetAnalogBindingMode();
}
private void SetAnalogBindingMode()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
BindingSyntax val = InputActionSetupExtensions.ChangeCompositeBinding(IPlayerInputActionFeature.PlayerMoveAction, "Gamepad");
((BindingSyntax)(ref val)).WithPath("2DVector(mode=2)");
}
}
public sealed class MoveInCardinalDirections : IFeature, IPlayerInputActionFeature
{
private static ManualLogSource _logger;
ManualLogSource IFeature.Logger
{
set
{
_logger = value;
}
}
public void OnEnable()
{
ResetBindingMode();
}
private void ResetBindingMode()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
BindingSyntax val = InputActionSetupExtensions.ChangeCompositeBinding(IPlayerInputActionFeature.PlayerMoveAction, "Gamepad");
((BindingSyntax)(ref val)).WithPath("2DVector");
}
}
}
namespace Free2Move.FeatureInfo
{
internal static class FeatureInfoInitializers
{
public static Func<string, Harmony> HarmonyFactory { get; set; } = delegate
{
throw new InvalidOperationException("FeatureInfo HarmonyFactory has not been initialized.");
};
public static Func<string, ManualLogSource> LogSourceFactory { get; set; } = delegate
{
throw new InvalidOperationException("FeatureInfo LogSourceFactory has not been initialized.");
};
}
internal class FeatureInfo<TFeature> : IFeatureInfo<TFeature>, IDisposable where TFeature : class, IFeature, new()
{
private readonly object _patchingLock = new object();
private Harmony? _featureHarmony;
private ManualLogSource? _featureLogger;
private TFeature? _featureInstance;
private readonly EventHandler<SettingChangedEventArgs> _onChangeEventHandler;
private bool _disposed;
public required string Name { get; init; }
public Func<bool>? EnabledCondition { get; init; }
public ConfigEntryBase[] ListenToConfigEntries { get; init; } = Array.Empty<ConfigEntryBase>();
public bool IsEnabled
{
get
{
if (EnabledCondition != null)
{
return EnabledCondition();
}
return true;
}
}
public bool ShouldLoad => IsEnabled;
public FeatureInfo()
{
_onChangeEventHandler = delegate(object _, SettingChangedEventArgs eventArgs)
{
if (ListenToConfigEntries.Contains(eventArgs.ChangedSetting))
{
OnChange();
}
};
}
public void Initialise()
{
if (_disposed)
{
throw new InvalidOperationException("FeatureInfo has already been disposed!.");
}
if (_featureHarmony != null)
{
throw new InvalidOperationException("FeatureInfo has already been initialised!");
}
_featureHarmony = FeatureInfoInitializers.HarmonyFactory(typeof(TFeature).Name);
_featureLogger = FeatureInfoInitializers.LogSourceFactory(Name);
CollectionExtensions.Do<ConfigEntryBase>((IEnumerable<ConfigEntryBase>)ListenToConfigEntries, (Action<ConfigEntryBase>)delegate(ConfigEntryBase entry)
{
entry.ConfigFile.SettingChanged += _onChangeEventHandler;
});
OnChange();
}
private void OnChange()
{
if (ShouldLoad)
{
if (_featureInstance == null)
{
Enable();
}
else
{
_featureInstance.OnConfigChange();
}
}
else
{
Disable();
}
}
private void InstantiateFeature()
{
if (_featureHarmony == null)
{
throw new Exception("FeatureInfo has not been initialised. Cannot patch without a Harmony instance.");
}
if (_featureLogger == null)
{
throw new Exception("FeatureInfo has not been initialised. Cannot patch without a Logger instance.");
}
Free2MovePlugin.Logger.LogDebug((object)"Instantiating feature...");
_featureInstance = new TFeature();
Free2MovePlugin.Logger.LogDebug((object)"Assigning logger...");
_featureInstance.Logger = _featureLogger;
Free2MovePlugin.Logger.LogDebug((object)"Assigning harmony...");
_featureInstance.Harmony = _featureHarmony;
}
private void Enable()
{
lock (_patchingLock)
{
if (_featureHarmony == null)
{
throw new Exception("FeatureInfo has not been initialised. Cannot patch without a Harmony instance.");
}
if (_featureInstance == null)
{
Free2MovePlugin.Logger.LogInfo((object)("Enabling " + Name + " feature..."));
InstantiateFeature();
_featureInstance.OnEnable();
_featureHarmony.PatchAllWithNestedTypes(typeof(TFeature));
}
}
}
private void Disable()
{
lock (_patchingLock)
{
if (_featureHarmony == null)
{
throw new Exception("FeatureInfo has not been initialised. Cannot unpatch without a Harmony instance.");
}
if (_featureInstance != null)
{
Free2MovePlugin.Logger.LogInfo((object)("Disabling " + Name + " feature..."));
_featureHarmony.UnpatchSelf();
_featureInstance.OnDisable();
_featureInstance = null;
}
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}
if (disposing && _featureHarmony != null)
{
CollectionExtensions.Do<ConfigEntryBase>((IEnumerable<ConfigEntryBase>)ListenToConfigEntries, (Action<ConfigEntryBase>)delegate(ConfigEntryBase entry)
{
entry.ConfigFile.SettingChanged -= _onChangeEventHandler;
});
Disable();
}
_disposed = true;
}
}
public interface IFeatureInfo<out TFeature> : IDisposable where TFeature : IFeature
{
string Name { get; }
bool IsEnabled { get; }
void Initialise();
}
}
namespace Free2Move.Extensions
{
public static class HarmonyExtensions
{
private const BindingFlags SearchNestedTypeBindingFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
public static void PatchAllNestedTypesOnly(this Harmony harmony, Type type)
{
Type[] nestedTypes = type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (Type type2 in nestedTypes)
{
harmony.PatchAllWithNestedTypes(type2);
}
}
public static void PatchAllWithNestedTypes(this Harmony harmony, Type type)
{
harmony.PatchAll(type);
harmony.PatchAllNestedTypesOnly(type);
}
}
public static class ManualLogSourceExtensions
{
private class CodeInstructionFormatter
{
private int _instructionIndexPadLength = instructionCount.ToString().Length;
public CodeInstructionFormatter(int instructionCount)
{
}
public string Format(CodeInstruction instruction, int index)
{
return $" IL_{index.ToString().PadLeft(_instructionIndexPadLength, '0')}: {instruction}";
}
}
public static void LogDebugInstructionsFrom(this ManualLogSource source, CodeMatcher matcher)
{
string name = new StackTrace().GetFrame(1).GetMethod().Name;
CodeInstructionFormatter @object = new CodeInstructionFormatter(matcher.Length);
StringBuilder stringBuilder = new StringBuilder("'" + name + "' Matcher Instructions:\n").AppendLine(string.Join("\n", matcher.InstructionEnumeration().Select(@object.Format))).AppendLine("End of matcher instructions.");
source.LogDebug((object)stringBuilder.ToString());
}
}
}