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 WoodenRamp v1.2.0
WoodenRamp/WoodenRamp.dll
Decompiled 2 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")] [assembly: AssemblyCompany("WoodenRamp")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("WoodenRamp")] [assembly: AssemblyTitle("WoodenRamp")] [assembly: AssemblyVersion("1.0.0.0")] [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 WoodenRamp { [BepInPlugin("com.jeffehboy.woodenramp", "WoodenRamp", "0.3.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class WoodenRampPlugin : BaseUnityPlugin { private enum Kind { Ramp, Beam } public const string PluginGUID = "com.jeffehboy.woodenramp"; public const string PluginName = "WoodenRamp"; public const string PluginVersion = "0.3.0"; private const float Width = 2f; private const float Rise = 1f; private const float SectionOverlap = 0.05f; private const float OverlapLift = 0.005f; private const float BeamCopyThickness = 0.97f; private const float EndReach = 1f; private const float RaiseExtra = 0f; private const float BeamWidth = 1.1f; private const float BeamHeight = 1.3f; private ConfigEntry<int> _woodCost; private ConfigEntry<int> _woodCostShort; private ConfigEntry<int> _woodCostBeam; private static readonly string[][] MenuOrder = new string[3][] { new string[2] { "piece_woodenramp", "wood_stair" }, new string[2] { "piece_woodenramp_short", "piece_woodenramp" }, new string[2] { "piece_woodenbeam14", "wood_beam" } }; private void Awake() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown _woodCost = ((BaseUnityPlugin)this).Config.Bind<int>("Recipe", "WoodCost", 4, new ConfigDescription("Wood required to build one long (2x4) ramp.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); _woodCostShort = ((BaseUnityPlugin)this).Config.Bind<int>("Recipe", "WoodCostShort", 2, new ConfigDescription("Wood required to build one short (2x2) ramp.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); _woodCostBeam = ((BaseUnityPlugin)this).Config.Bind<int>("Recipe", "WoodCostBeam", 2, new ConfigDescription("Wood required to build one 14 degree beam.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); PrefabManager.OnVanillaPrefabsAvailable += AddPieces; PieceManager.OnPiecesRegistered += PlaceNextToVanillaWood; } private static void PlaceNextToVanillaWood() { PieceTable pieceTable = PieceManager.Instance.GetPieceTable(PieceTables.Hammer); if ((Object)(object)pieceTable == (Object)null) { return; } List<GameObject> pieces = pieceTable.m_pieces; string[][] menuOrder = MenuOrder; foreach (string[] array in menuOrder) { string pieceName = array[0]; string afterName = array[1]; int num = pieces.FindIndex((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == pieceName); if (num >= 0) { GameObject item = pieces[num]; pieces.RemoveAt(num); int num2 = pieces.FindIndex((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == afterName); if (num2 < 0) { Logger.LogWarning((object)("Couldn't find '" + afterName + "' in the hammer menu; leaving " + pieceName + " at the end.")); pieces.Add(item); } else { pieces.Insert(num2 + 1, item); } } } } private void AddPieces() { PrefabManager.OnVanillaPrefabsAvailable -= AddPieces; AddSlopedPiece(Kind.Ramp, "wood_floor", "piece_woodenramp", "Wood ramp 14°", "A gentle wooden ramp, 2 m wide and 4 m long, rising 1 m. Made for hauling carts up hills.", "ramp_icon.png", 4f, _woodCost.Value); AddSlopedPiece(Kind.Ramp, "wood_floor", "piece_woodenramp_short", "Wood ramp 26°", "A steeper wooden ramp, 2 m wide and 2 m long, rising 1 m. For tight spots.", "ramp_icon_short.png", 2f, _woodCostShort.Value); AddSlopedPiece(Kind.Beam, "wood_beam", "piece_woodenbeam14", "Wood beam 14°", "A wooden beam with the same length and slope as the 14° ramp: 4 m along the ground, rising 1 m.", "beam14_icon.png", 4f, _woodCostBeam.Value); } private static void AddSlopedPiece(Kind kind, string basePrefab, string prefabName, string name, string description, string iconFile, float run, int woodCost) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown PieceConfig val = new PieceConfig(); val.Name = name; val.Description = description; val.Icon = LoadEmbeddedSprite(iconFile); val.PieceTable = PieceTables.Hammer; val.Category = PieceCategories.Building; val.CraftingStation = CraftingStations.Workbench; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("Wood", woodCost, 0, true) }; PieceConfig val2 = val; CustomPiece val3 = new CustomPiece(prefabName, basePrefab, val2); if ((Object)(object)val3.PiecePrefab == (Object)null) { Logger.LogError((object)("Could not clone '" + basePrefab + "'; " + name + " not added.")); } else { Reshape(val3.PiecePrefab, kind, run); PieceManager.Instance.AddPiece(val3); Logger.LogInfo((object)(name + " added.")); } } private static Sprite LoadEmbeddedSprite(string fileName) { //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) Assembly assembly = typeof(WoodenRampPlugin).Assembly; string text = null; string[] manifestResourceNames = assembly.GetManifestResourceNames(); foreach (string text2 in manifestResourceNames) { if (text2.EndsWith(fileName)) { text = text2; break; } } if (text == null) { Logger.LogWarning((object)("Icon '" + fileName + "' not found in the DLL; using the default icon.")); return null; } byte[] array; using (Stream stream = assembly.GetManifestResourceStream(text)) { using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); array = memoryStream.ToArray(); } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); MethodInfo methodInfo = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")?.GetMethod("LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }); if (methodInfo == null) { Logger.LogWarning((object)"Couldn't find Unity's image loader; using the default icon."); return null; } methodInfo.Invoke(null, new object[2] { val, array }); return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } private static void Reshape(GameObject prefab, Kind kind, float run) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Expected O, but got Unknown //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_03b4: Unknown result type (might be due to invalid IL or missing references) //IL_0401: Unknown result type (might be due to invalid IL or missing references) //IL_046e: Unknown result type (might be due to invalid IL or missing references) //IL_0490: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Unknown result type (might be due to invalid IL or missing references) //IL_044e: Unknown result type (might be due to invalid IL or missing references) //IL_050c: Unknown result type (might be due to invalid IL or missing references) //IL_0526: Unknown result type (might be due to invalid IL or missing references) //IL_0545: Unknown result type (might be due to invalid IL or missing references) //IL_0616: Unknown result type (might be due to invalid IL or missing references) //IL_062e: Unknown result type (might be due to invalid IL or missing references) //IL_0587: Unknown result type (might be due to invalid IL or missing references) //IL_05a0: Unknown result type (might be due to invalid IL or missing references) //IL_05b6: Unknown result type (might be due to invalid IL or missing references) //IL_05cc: Unknown result type (might be due to invalid IL or missing references) //IL_05e4: Unknown result type (might be due to invalid IL or missing references) //IL_05f9: Unknown result type (might be due to invalid IL or missing references) Transform transform = prefab.transform; List<Transform> list = new List<Transform>(); foreach (Transform item2 in transform) { Transform item = item2; list.Add(item); } float num = float.MinValue; foreach (Transform item3 in list) { if (((Component)item3).CompareTag("snappoint")) { num = Mathf.Max(num, item3.localPosition.y); Object.DestroyImmediate((Object)(object)((Component)item3).gameObject); } } Bounds val = FindMeshBounds(transform); float num2 = ((num == float.MinValue) ? 0f : Mathf.Clamp(((Bounds)(ref val)).max.y - num, 0f, 0.3f)); Logger.LogInfo((object)$"{((Object)prefab).name}: base mesh bounds centre {((Bounds)(ref val)).center:F3}, size {((Bounds)(ref val)).size:F3}, surface {num2:F3} m above snap points"); float num3 = ((kind == Kind.Ramp) ? ((Bounds)(ref val)).max.y : ((Bounds)(ref val)).center.y); Transform transform2 = new GameObject("SlopePivot").transform; transform2.SetParent(transform, false); transform2.localPosition = new Vector3(0f, num3, 0f); Transform transform3 = new GameObject("Section0").transform; transform3.SetParent(transform2, false); Transform transform4 = new GameObject("Centre").transform; transform4.SetParent(transform3, false); list.Clear(); foreach (Transform item4 in transform) { Transform val2 = item4; if ((Object)(object)val2 != (Object)(object)transform2) { list.Add(val2); } } foreach (Transform item5 in list) { item5.SetParent(transform4, true); } transform4.localPosition = new Vector3(0f - ((Bounds)(ref val)).center.x, 0f, 0f - ((Bounds)(ref val)).center.z); bool turn = kind == Kind.Ramp || ((Bounds)(ref val)).size.x > ((Bounds)(ref val)).size.z; transform3.localRotation = (turn ? Quaternion.Euler(0f, 90f, 0f) : Quaternion.identity); float num4 = (turn ? ((Bounds)(ref val)).size.x : ((Bounds)(ref val)).size.z); float num5 = (turn ? ((Bounds)(ref val)).size.z : ((Bounds)(ref val)).size.x); float num6 = ((kind == Kind.Ramp) ? (num2 + 0f) : 0f); float num7 = Mathf.Sqrt(run * run + 1f); float num8 = Mathf.Atan2(1f, run) * 57.29578f; int num9 = Mathf.Max(1, Mathf.RoundToInt(num7 / num4)); float num10 = ((num9 > 1) ? 0.05f : 0f); Renderer[] componentsInChildren = ((Component)transform3).GetComponentsInChildren<Renderer>(true); transform3.localScale = AlongScale(1f + num10, 1f); transform3.localPosition = new Vector3(0f, 0f, SegmentZ(0, num9, num4)); List<Transform> list2 = new List<Transform>(); for (int i = 1; i < num9; i++) { Transform transform5 = Object.Instantiate<GameObject>(((Component)transform3).gameObject, transform2).transform; ((Object)transform5).name = "Section" + i; transform5.localRotation = transform3.localRotation; if (kind == Kind.Ramp) { transform5.localScale = AlongScale(1f + num10, 1f); transform5.localPosition = new Vector3(0f, (float)i * 0.005f, SegmentZ(i, num9, num4)); } else { transform5.localScale = AlongScale(1f + num10, 0.97f); transform5.localPosition = new Vector3(0f, 0f, SegmentZ(i, num9, num4)); } ((Component)transform5).gameObject.AddComponent<MirrorActiveState>().source = transform3; list2.Add(transform5); } float num11 = ((kind == Kind.Ramp) ? (2f / num5) : 1.1f); float num12 = ((kind == Kind.Ramp) ? 1f : 1.3f); transform2.localScale = new Vector3(num11, num12, 1f * num7 / (num4 * ((float)num9 + num10))); transform2.localRotation = Quaternion.Euler(0f - num8, 0f, 0f); transform2.localPosition = new Vector3(0f, 0.5f + num6, 0f); ShareLods(transform, transform3, componentsInChildren, list2); float num13 = run / 2f; if (kind == Kind.Ramp) { float num14 = 1f; AddSnapPoint(transform, new Vector3(0f - num14, 0f, 0f - num13)); AddSnapPoint(transform, new Vector3(0f, 0f, 0f - num13)); AddSnapPoint(transform, new Vector3(num14, 0f, 0f - num13)); AddSnapPoint(transform, new Vector3(0f - num14, 1f, num13)); AddSnapPoint(transform, new Vector3(0f, 1f, num13)); AddSnapPoint(transform, new Vector3(num14, 1f, num13)); } else { AddSnapPoint(transform, new Vector3(0f, 0f, 0f - num13)); AddSnapPoint(transform, new Vector3(0f, 1f, num13)); } Vector3 AlongScale(float along, float other) { //IL_0015: 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) return turn ? new Vector3(along, other, other) : new Vector3(other, other, along); } } private static void ShareLods(Transform root, Transform section, Renderer[] sectionRenderers, List<Transform> copies) { LODGroup[] componentsInChildren = ((Component)root).GetComponentsInChildren<LODGroup>(true); foreach (LODGroup lodGroup in componentsInChildren) { if (((Component)lodGroup).transform.IsChildOf(section) || copies.Any((Transform c) => ((Component)lodGroup).transform.IsChildOf(c))) { lodGroup.RecalculateBounds(); continue; } LOD[] lODs = lodGroup.GetLODs(); for (int num = 0; num < lODs.Length; num++) { List<Renderer> list = lODs[num].renderers.Where((Renderer r) => (Object)(object)r != (Object)null).ToList(); Renderer[] renderers = lODs[num].renderers; foreach (Renderer val in renderers) { if ((Object)(object)val == (Object)null || !sectionRenderers.Contains(val)) { continue; } string text = RelativePath(((Component)val).transform, section); foreach (Transform copy in copies) { Transform val2 = ((text.Length == 0) ? copy : copy.Find(text)); Renderer val3 = (Renderer)(((Object)(object)val2 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val3 != (Object)null) { list.Add(val3); } } } lODs[num].renderers = list.ToArray(); } lodGroup.SetLODs(lODs); lodGroup.RecalculateBounds(); } } private static string RelativePath(Transform t, Transform ancestor) { List<string> list = new List<string>(); while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)ancestor) { list.Add(((Object)t).name); t = t.parent; } list.Reverse(); return string.Join("/", list); } private static float SegmentZ(int i, int n, float length) { return ((float)i - (float)(n - 1) / 2f) * length; } private static Bounds FindMeshBounds(Transform root) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) bool flag = false; Bounds val = default(Bounds); Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix; MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val2 in componentsInChildren) { if ((Object)(object)val2.sharedMesh == (Object)null || !IsShown(((Component)val2).transform, root)) { continue; } Bounds bounds = val2.sharedMesh.bounds; Matrix4x4 val3 = worldToLocalMatrix * ((Component)val2).transform.localToWorldMatrix; for (int j = 0; j < 8; j++) { Vector3 val4 = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(new Vector3(((j & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((j & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((j & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z)); if (!flag) { ((Bounds)(ref val))..ctor(val4, Vector3.zero); flag = true; } else { ((Bounds)(ref val)).Encapsulate(val4); } } } return (Bounds)(flag ? val : new Bounds(Vector3.zero, new Vector3(2f, 0f, 2f))); } private static bool IsShown(Transform t, Transform root) { while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root) { if (!((Component)t).gameObject.activeSelf) { return false; } t = t.parent; } return true; } private static void AddSnapPoint(Transform root, Vector3 localPos) { //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_0018: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("_snappoint") { tag = "snappoint" }; val.transform.SetParent(root, false); val.transform.localPosition = localPos; val.SetActive(false); } } public class MirrorActiveState : MonoBehaviour { public Transform source; private void LateUpdate() { if ((Object)(object)source != (Object)null) { Mirror(source, ((Component)this).transform); } } private static void Mirror(Transform from, Transform to) { int num = Mathf.Min(from.childCount, to.childCount); for (int i = 0; i < num; i++) { Transform child = from.GetChild(i); Transform child2 = to.GetChild(i); bool activeSelf = ((Component)child).gameObject.activeSelf; if (((Component)child2).gameObject.activeSelf != activeSelf) { ((Component)child2).gameObject.SetActive(activeSelf); } if (activeSelf) { Mirror(child, child2); } } } } }