Please disclose if your mod was created primarily 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 ZenTerrain v0.3.3
plugins/ZenTerrain.dll
Decompiled 5 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using Zen; using Zen.Lib; using Zen.Lib.Config; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ZenTerrain")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ZenTerrain")] [assembly: AssemblyCopyright("Copyright \ufffd 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.0")] [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 ZenTerrain { internal static class Configs { public static readonly ConfigEntry<float> RaiseLimit; public static readonly ConfigEntry<float> DigLimit; public static readonly ConfigEntry<float> BuriedSearchRadius; public static readonly ConfigEntry<KeyCode> AdminOverrideKey; static Configs() { AdminOverrideKey = Config.Define<KeyCode>(true, "Modification", "Admin Override Key", (KeyCode)304, "Admin can override the limits by being in God Mode and holding down this key when terraforming."); RaiseLimit = Config.Define<float>(true, "Modification", "Terrain Raise Limit", 0.5f, Config.AcceptRange<float>(0f, 8f), "Max height that terrain can be raised from default. (Vanilla: 8)"); DigLimit = Config.Define<float>(true, "Modification", "Terrain Dig Limit", 1f, Config.AcceptRange<float>(0f, 8f), "Max depth that terrain can be lowered from default. (Vanilla: 8)"); BuriedSearchRadius = Config.Define<float>(true, "Modification", "Buried Search Radius", 3f, Config.AcceptRange<float>(0f, 8f), "Radius to search for buried objects that if found will allow bypass of digging restrictions."); } } [BepInPlugin("ZenDragon.ZenTerrain", "ZenTerrain", "0.3.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class Plugin : ZenMod<Plugin> { public const string PluginName = "ZenTerrain"; public const string PluginVersion = "0.3.3"; public const string PluginGUID = "ZenDragon.ZenTerrain"; protected override void Setup() { } protected override void TitleScene(bool isFirstBoot) { } protected override void WorldStart() { } protected override void Shutdown() { } } [HarmonyPatch] public static class TerrainLimit { public const float VanillaLimit = 8f; private static readonly Collider[] HitCache = (Collider[])(object)new Collider[1024]; private static readonly LayerMask SearchLayers = LayerMask.op_Implicit(LayerMask.GetMask(new string[3] { "Default", "Default_small", "static_solid" })); private static readonly int WishboneSE = StringExtensionMethods.GetStableHashCode("Wishbone"); private static float ApplyLimit(float curHeight, float delta) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) Logging<Plugin>.Info((object)$"Apply Limit height: {curHeight} delta: {delta}", 0); float num = curHeight + delta; if ((((Character)Player.m_localPlayer).InGodMode() && ZInput.GetKey(Configs.AdminOverrideKey.Value, true)) || ((Character)Player.m_localPlayer).InInterior()) { return Mathf.Clamp(num, -8f, 8f); } StatusEffect statusEffect = ((Character)Player.m_localPlayer).GetSEMan().GetStatusEffect(WishboneSE); SE_Finder val = (SE_Finder)(object)((statusEffect is SE_Finder) ? statusEffect : null); if (Object.op_Implicit((Object)(object)val?.m_beacon)) { Logging<Plugin>.Info((object)"Wishbone is in effect, checking for dig exceptions", 0); if (Mathf.Clamp01(val.m_lastDistance / val.m_beacon.m_range) < 0.15f) { return Mathf.Clamp(num, -8f, Configs.RaiseLimit.Value); } } int num2 = Physics.OverlapSphereNonAlloc(((Component)Player.m_localPlayer).transform.position, Configs.BuriedSearchRadius.Value, HitCache, LayerMask.op_Implicit(SearchLayers)); for (int i = 0; i < num2; i++) { if (IsMinable(((Component)HitCache[i]).gameObject)) { return Mathf.Clamp(num, -8f, Configs.RaiseLimit.Value); } } if (curHeight < 0f - Configs.DigLimit.Value) { if (delta > 0f) { return Mathf.Clamp(num, -8f, Configs.RaiseLimit.Value); } return curHeight; } if (curHeight > Configs.RaiseLimit.Value) { if (delta < 0f) { return Mathf.Clamp(num, 0f - Configs.DigLimit.Value, 8f); } return curHeight; } return Mathf.Clamp(num, 0f - Configs.DigLimit.Value, Configs.RaiseLimit.Value); static bool HasOre(DropTable? dropTable) { if (dropTable != null) { return dropTable.GetDropList().Any((GameObject drop) => ((Object)drop).name.Contains("Ore") || ((Object)drop).name.Contains("Scrap")); } return false; } static bool IsMinable(GameObject obj) { if (!HasOre(obj.GetComponentInParent<MineRock5>()?.m_dropItems) && !HasOre(obj.GetComponentInParent<MineRock>()?.m_dropItems) && !Object.op_Implicit((Object)(object)obj.GetComponentInParent<Beacon>())) { return Object.op_Implicit((Object)(object)obj.GetComponentInChildren<Beacon>()); } return true; } } [HarmonyTranspiler] [HarmonyPatch(typeof(TerrainComp), "RaiseTerrain")] public static IEnumerable<CodeInstruction> TerrainComp_RaiseTerrain_Transpiler(IEnumerable<CodeInstruction> codes, ILGenerator gen) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown //IL_00e1: Unknown result type (might be due to invalid IL or missing references) Func<float, float, float> func = ApplyLimit; CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[3] { CodeMatch.op_Implicit(OpCodes.Ldloc_S), CodeMatch.op_Implicit(OpCodes.Add), CodeMatch.op_Implicit(OpCodes.Stind_R4) }; CodeMatch[] array2 = (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)(-8f), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)8f, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)typeof(Mathf).GetMethod("Clamp", new Type[3] { typeof(float), typeof(float), typeof(float) }), (string)null) }; return new CodeMatcher(codes, gen).MatchStartForward(array).ThrowIfInvalid("Unable to match first sequence").Set(OpCodes.Ldc_R4, (object)0f) .MatchStartForward(array2) .ThrowIfInvalid("Unable to match second sequence") .SetAndAdvance(OpCodes.Ldloc_S, (object)(byte)14) .SetAndAdvance(OpCodes.Nop, (object)null) .Set(OpCodes.Call, (object)func.Method) .InstructionEnumeration(); } } }