Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of CustomShovel v1.0.1
CustomShovel.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.IO; 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 GameNetcodeStuff; using HarmonyLib; using IL; using LethalConfig; using LethalConfig.ConfigItems; using LethalConfig.ConfigItems.Options; using Microsoft.CodeAnalysis; using ModelReplacement; using ModelReplacement.AvatarBodyUpdater; using Mono.Cecil.Cil; using MonoMod.Cil; using Unity.Netcode; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Rumi")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+fdc44488b65e9a96c8ffb8ef5e420bec3c999f97")] [assembly: AssemblyProduct("CustomShovel")] [assembly: AssemblyTitle("CustomShovel")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] 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; } } } namespace Rumi.CustomShovel { [BepInPlugin("Rumi.CustomShovel", "CustomShovel", "1.0.1")] public class CustomShovel : BaseUnityPlugin { public const string modGuid = "Rumi.CustomShovel"; public const string modName = "CustomShovel"; public const string modVersion = "1.0.1"; private static Assembly? _currentAssembly; private static string? _assemblyName; private static Transform? _emptyTransform; private static Material? _coloredMaterial; public static Assembly currentAssembly => _currentAssembly ?? (_currentAssembly = Assembly.GetExecutingAssembly()); public static string assemblyName => _assemblyName ?? (_assemblyName = currentAssembly.FullName.Split(',')[0]); public static ManualLogSource? logger { get; private set; } public static CustomShovelConfig? config { get; private set; } public static Harmony harmony { get; } = new Harmony("Rumi.CustomShovel"); public static Transform emptyTransform { get { //IL_0012: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_emptyTransform == (Object)null) { _emptyTransform = new GameObject("Easy Shovel Empty Transform").transform; Object.DontDestroyOnLoad((Object)(object)_emptyTransform); } return _emptyTransform; } } public static Material coloredMaterial { get { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown if ((Object)(object)_coloredMaterial == (Object)null) { _coloredMaterial = new Material(Shader.Find("Hidden/Internal-Colored")); ((Object)_coloredMaterial).hideFlags = (HideFlags)61; _coloredMaterial.SetInt("_SrcBlend", 5); _coloredMaterial.SetInt("_DstBlend", 10); _coloredMaterial.SetInt("_Cull", 0); _coloredMaterial.SetInt("_ZWrite", 0); } return _coloredMaterial; } } private void Awake() { logger = ((BaseUnityPlugin)this).Logger; _ = emptyTransform; ManualLogSource? obj = logger; if (obj != null) { obj.LogInfo((object)"Start loading plugin..."); } ManualLogSource? obj2 = logger; if (obj2 != null) { obj2.LogInfo((object)"Config Loading..."); } try { config = new CustomShovelConfig(((BaseUnityPlugin)this).Config); } catch (Exception ex) { config = null; ManualLogSource? obj3 = logger; if (obj3 != null) { obj3.LogError((object)ex); } ManualLogSource? obj4 = logger; if (obj4 != null) { obj4.LogWarning((object)"Failed to load config file\nSettings will be loaded with defaults!"); } } ManualLogSource? obj5 = logger; if (obj5 != null) { obj5.LogInfo((object)"HitShovel IL Patch..."); } CustomShovelPatches.Init(); ManualLogSource? obj6 = logger; if (obj6 != null) { obj6.LogInfo((object)"PlayerControllerB And Camera Patch..."); } harmony.PatchAll(typeof(CustomShovelDrawHitbox)); CustomShovelDrawHitbox.Init(); ManualLogSource? obj7 = logger; if (obj7 != null) { obj7.LogInfo((object)"ModelReplacementAPI And PlayerControllerB Patch..."); } try { harmony.PatchAll(typeof(CustomShovelSkinFix)); } catch (TypeLoadException ex2) { ManualLogSource? obj8 = logger; if (obj8 != null) { obj8.LogError((object)ex2); } ManualLogSource? obj9 = logger; if (obj9 != null) { obj9.LogWarning((object)"ModelReplacementAPI Patch Fail! (This is not a bug and occurs when ModelReplacementAPI is not present)"); } } catch (Exception ex3) { ManualLogSource? obj10 = logger; if (obj10 != null) { obj10.LogError((object)ex3); } ManualLogSource? obj11 = logger; if (obj11 != null) { obj11.LogError((object)"ModelReplacementAPI Patch Fail!"); } } ManualLogSource? obj12 = logger; if (obj12 != null) { obj12.LogInfo((object)"Plugin CustomShovel is loaded!"); } } } public class CustomShovelConfig { private readonly ConfigEntry<float> _radius; public const float dRadius = 0.8f; private readonly ConfigEntry<float> _maxDistance; public const float dMaxDistance = 1.5f; private readonly ConfigEntry<bool> _showShovelHitbox; public const bool dShowShovelHitbox = false; public float radius { get { return _radius?.Value ?? 0.8f; } set { _radius.Value = value; } } public float maxDistance { get { return _maxDistance?.Value ?? 1.5f; } set { _maxDistance.Value = value; } } public bool showShovelHitbox { get { return _showShovelHitbox?.Value ?? false; } set { _showShovelHitbox.Value = value; } } public CustomShovelConfig(ConfigFile config) { _radius = config.Bind<float>("General", "Radius", 0.8f, "Sets the radius of the hitbox circle."); _radius.SettingChanged += delegate { CustomShovelPatches.ShovelPatchUpdate(); }; _maxDistance = config.Bind<float>("General", "Max Distance", 1.5f, "Determines the max distance of the hitbox"); _maxDistance.SettingChanged += delegate { CustomShovelPatches.ShovelPatchUpdate(); }; _showShovelHitbox = config.Bind<bool>("Debug", "Show Shovel Hitbox", false, "Shows the shovel's hitbox with a line."); try { LethalConfigPatch(); } catch (FileNotFoundException ex) { ManualLogSource? logger = CustomShovel.logger; if (logger != null) { logger.LogError((object)ex); } ManualLogSource? logger2 = CustomShovel.logger; if (logger2 != null) { logger2.LogWarning((object)"Lethal Config Patch Fail! (This is not a bug and occurs when LethalConfig is not present)"); } } catch (Exception ex2) { ManualLogSource? logger3 = CustomShovel.logger; if (logger3 != null) { logger3.LogError((object)ex2); } ManualLogSource? logger4 = CustomShovel.logger; if (logger4 != null) { logger4.LogError((object)"Lethal Config Patch Fail!"); } } } private void LethalConfigPatch() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown ConfigEntry<float> obj = _radius; FloatSliderOptions val = new FloatSliderOptions(); ((BaseRangeOptions<float>)val).Min = 0.1f; ((BaseRangeOptions<float>)val).Max = 10f; ((BaseOptions)val).RequiresRestart = false; LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(obj, val)); ConfigEntry<float> obj2 = _maxDistance; FloatSliderOptions val2 = new FloatSliderOptions(); ((BaseRangeOptions<float>)val2).Min = 0.1f; ((BaseRangeOptions<float>)val2).Max = 10f; ((BaseOptions)val2).RequiresRestart = false; LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(obj2, val2)); LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(_showShovelHitbox, false)); } } public static class CustomShovelDrawHitbox { private static PlayerControllerB? _player; public static PlayerControllerB? player => _player; public static void Init() { RenderPipelineManager.endCameraRendering += RenderPipelineManager_endCameraRendering; } [HarmonyPatch(typeof(PlayerControllerB), "Update")] [HarmonyPostfix] private static void PlayerControllerB_Update_Postfix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject) && __instance.isPlayerControlled && !__instance.isPlayerDead) { _player = __instance; } } private static void RenderPipelineManager_endCameraRendering(ScriptableRenderContext arg1, Camera arg2) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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_0137: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) CustomShovelConfig? config = CustomShovel.config; if (config == null || !config.showShovelHitbox || (Object)(object)CustomShovel.emptyTransform == (Object)null || (Object)(object)player == (Object)null || !player.isHoldingObject || !(player.currentlyHeldObjectServer is Shovel)) { return; } float num = CustomShovel.config?.radius ?? 0.8f; float num2 = CustomShovel.config?.maxDistance ?? 1.5f; Vector3 position = ((Component)player.gameplayCamera).transform.position; Vector3 forward = ((Component)player.gameplayCamera).transform.forward; RaycastHit[] array = Physics.SphereCastAll(position, num, forward, num2, 11012424, (QueryTriggerInteraction)2); RaycastHit val = array.Aggregate((RaycastHit x, RaycastHit y) => (!(((RaycastHit)(ref x)).distance > ((RaycastHit)(ref y)).distance)) ? y : x); if (array.Length != 0) { Vector3 center = position + (((RaycastHit)(ref val)).distance - num) * forward; GL.PushMatrix(); GL.MultMatrix(CustomShovel.emptyTransform.localToWorldMatrix); if (CustomShovel.coloredMaterial.SetPass(0)) { Circle3D(center, num, Vector3.right); Circle3D(center, num, Vector3.forward); Circle3D(center, num, Vector3.up); } for (int i = 0; i < array.Length; i++) { Circle3D(((RaycastHit)(ref array[i])).point, 0.1f, forward); } GL.PopMatrix(); } } public static void Circle3D(Vector3 center, float radius, Vector3 normal) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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) GL.Begin(1); GL.Color(Color.red); normal = ((Vector3)(ref normal)).normalized; Vector3 val; if (!(normal == Vector3.up)) { val = Vector3.ProjectOnPlane(Vector3.up, normal); } else { Vector3 val2 = Vector3.ProjectOnPlane(Vector3.forward, normal); val = ((Vector3)(ref val2)).normalized; } Vector3 val3 = val; Vector3 val4 = Vector3.Cross(normal, val3); for (float num = 0f; num < MathF.PI * 2f; num += 0.25f) { Vector3 val5 = center + val3 * Mathf.Cos(num) * radius + val4 * Mathf.Sin(num) * radius; GL.Vertex(val5); if (num != 0f) { GL.Vertex(val5); } } GL.End(); } } public static class CustomShovelPatches { public static void Init() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown Shovel.HitShovel += new Manipulator(HitShovel); } public static void ShovelPatchUpdate() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown Shovel.HitShovel -= new Manipulator(HitShovel); Shovel.HitShovel += new Manipulator(HitShovel); } private static void HitShovel(ILContext il) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown ILCursor val = new ILCursor(il); if (val.TryGotoNext(new Func<Instruction, bool>[6] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld<Shovel>(x, "previousPlayerHeldBy"), (Instruction x) => ILPatternMatchingExt.MatchLdfld<PlayerControllerB>(x, "gameplayCamera"), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Component>(x, "get_transform"), (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Transform>(x, "get_position") })) { ManualLogSource? logger = CustomShovel.logger; if (logger != null) { logger.LogMessage((object)"Try Goto Next Success!"); } int index = val.Index; val.Index = index + 1; val.RemoveRange(25); val.EmitDelegate<Action<Shovel>>((Action<Shovel>)delegate(Shovel instance) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) instance.objectsHitByShovel = Physics.SphereCastAll(((Component)instance.previousPlayerHeldBy.gameplayCamera).transform.position, CustomShovel.config?.radius ?? 0.8f, ((Component)instance.previousPlayerHeldBy.gameplayCamera).transform.forward, CustomShovel.config?.maxDistance ?? 1.5f, instance.shovelMask, (QueryTriggerInteraction)2); }); } else { ManualLogSource? logger2 = CustomShovel.logger; if (logger2 != null) { logger2.LogError((object)"Try Goto Next Failed! Bad IL Code!"); } } } } public static class CustomShovelSkinFix { private static bool refresh; [HarmonyPatch(typeof(ModelReplacementAPI), "SetPlayerModelReplacement")] [HarmonyPrefix] public static void ModelReplacementAPI_SetPlayerModelReplacement(ref PlayerControllerB player, ref Type type) { BodyReplacementBase val = default(BodyReplacementBase); if (((Component)player).gameObject.TryGetComponent<BodyReplacementBase>(ref val)) { int currentSuitID = player.currentSuitID; string unlockableName = StartOfRound.Instance.unlockablesList.unlockables[currentSuitID].unlockableName; if (((object)val).GetType() == type && val.suitName == unlockableName) { return; } } ManualLogSource? logger = CustomShovel.logger; if (logger != null) { logger.LogInfo((object)"SetPlayerModelReplacement call detected"); } refresh = true; } [HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")] [HarmonyPostfix] private static void PlayerControllerB_LateUpdate_Postfix() { if (!refresh) { return; } refresh = false; int num = LayerMask.NameToLayer("Default"); int layer = LayerMask.NameToLayer("Ignore Raycast"); OffsetBuilder[] array = Object.FindObjectsByType<OffsetBuilder>((FindObjectsInactive)1, (FindObjectsSortMode)0); for (int i = 0; i < array.Length; i++) { Transform[] componentsInChildren = ((Component)array[i]).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Component)val).gameObject.layer == num) { ((Component)val).gameObject.layer = layer; } } } RotationOffset[] array2 = Object.FindObjectsByType<RotationOffset>((FindObjectsInactive)1, (FindObjectsSortMode)0); for (int k = 0; k < array.Length; k++) { Transform[] componentsInChildren2 = ((Component)array2[k]).GetComponentsInChildren<Transform>(true); foreach (Transform val2 in componentsInChildren2) { if (((Component)val2).gameObject.layer == num) { ((Component)val2).gameObject.layer = layer; } } } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }