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 Bicicreta v0.7.0
Bicicreta.dll
Decompiled a week 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 System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; 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.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("assembly_googleanalytics")] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_lux")] [assembly: IgnoresAccessChecksTo("assembly_postprocessing")] [assembly: IgnoresAccessChecksTo("assembly_simplemeshcombine")] [assembly: IgnoresAccessChecksTo("assembly_sunshafts")] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: IgnoresAccessChecksTo("gui_framework")] [assembly: IgnoresAccessChecksTo("SoftReferenceableAssets")] [assembly: IgnoresAccessChecksTo("Splatform")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("GitMCP")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Adds a buildable, rideable bicycle to Valheim.")] [assembly: AssemblyFileVersion("0.7.0.0")] [assembly: AssemblyInformationalVersion("0.7.0+5ccf629eea856fe386a8a80d94b32b2228c345cf")] [assembly: AssemblyProduct("Bicicreta")] [assembly: AssemblyTitle("Bicicreta")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.7.0.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 Bicicreta { internal static class BicicretaAppearance { private const string VisualName = "BicicretaVisual"; private const string CartSource = "Cart"; private const string WheelPath = "Wheel1/default"; private const string FramePath = "Vagon/new/default"; private const string ChairSource = "piece_chair02"; private const string ChairPath = "New/high"; private const float DonorWheelRadius = 0.5f; private const float DonorFrameLength = 3.27f; private const float DonorFrameWidth = 1.546f; private const string WoodSource = "wood_pole"; private const string WoodPath = "New"; private static readonly Vector3 ChairPan = new Vector3(0f, 0.5f, -0.05f); private static readonly Vector3 ChairScale = new Vector3(0.85f, 0.5f, 0.55f); internal static void Apply(GameObject prefab) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_006c: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00dd: 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_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) if (!BicicretaPlugin.UseStandInModel.Value) { BicicretaPlugin.Log.LogInfo((object)"UseStandInModel is off; leaving the clone's own model in place."); return; } int num = 0; Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; num++; } GameObject val = new GameObject("BicicretaVisual"); val.transform.SetParent(prefab.transform, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; Vector3 scale = Vector3.one * 0.8f; Transform val2 = Hub(val.transform, "FrontWheel", 0.55f); Transform val3 = Hub(val.transform, "RearWheel", -1.35f); int num2 = 0; num2 += Fit("Cart", "Wheel1/default", val2, "FrontWheel", Vector3.zero, scale); num2 += Fit("Cart", "Wheel1/default", val3, "RearWheel", Vector3.zero, scale); float num3 = 0.4587156f; num2 += Fit("Cart", "Vagon/new/default", val.transform, "Frame", new Vector3(0f, 0.6f, -0.19999999f), new Vector3(0.19404916f, num3, num3)); num2 += Fit("piece_chair02", "New/high", val.transform, "Seat", new Vector3(0f, 1.03f, -0.56f), ChairScale, ChairPan); num2 += Handlebar(val.transform); BicicretaWheels bicicretaWheels = prefab.AddComponent<BicicretaWheels>(); bicicretaWheels.FrontHub = val2; bicicretaWheels.RearHub = val3; BicicretaPlugin.Log.LogInfo((object)$"Hid {num} lox renderer(s) and built a bicycle from {num2} borrowed part(s)."); } private static Transform Hub(Transform parent, string name, float offset) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: 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_003e: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name + "Hub"); val.transform.SetParent(parent, false); val.transform.localPosition = new Vector3(0f, 0.4f, offset); val.transform.localRotation = Quaternion.identity; return val.transform; } private static int Handlebar(Transform parent) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) float num = 0.07f; float num2 = num * 0.7f; float num3 = 0.87f; return Fit("wood_pole", "New", parent, "HandlebarStem", new Vector3(0f, 1.47f - num3 / 2f, 0.044999998f), new Vector3(num, num3, num)) + Fit("wood_pole", "New", parent, "HandlebarNeck", new Vector3(0f, 1.47f, -0.0075000003f), new Vector3(num2, num2, 0.105f)) + Fit("wood_pole", "New", parent, "HandlebarBar", new Vector3(0f, 1.47f, -0.06f), new Vector3(0.36f, num, num)); } internal static int Fit(string donorName, string path, Transform parent, string name, Vector3 target, Vector3 scale, Vector3? anchor = null) { //IL_00ac: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: 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_00fc: Unknown result type (might be due to invalid IL or missing references) GameObject prefab = PrefabManager.Instance.GetPrefab(donorName); Transform val = (((Object)(object)prefab == (Object)null) ? null : prefab.transform.Find(path)); MeshFilter val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<MeshFilter>()); if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null) { BicicretaPlugin.Log.LogWarning((object)("'" + donorName + "/" + path + "' is gone; the bicycle is missing its " + name + ".")); return 0; } GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent); ((Object)val3).name = name; val3.transform.localRotation = Quaternion.identity; val3.transform.localScale = scale; Transform transform = val3.transform; Vector3? val4 = anchor; Vector3 val5; if (!val4.HasValue) { Bounds bounds = val2.sharedMesh.bounds; val5 = ((Bounds)(ref bounds)).center; } else { val5 = val4.GetValueOrDefault(); } transform.localPosition = target - Vector3.Scale(val5, scale); LODGroup[] componentsInChildren = val3.GetComponentsInChildren<LODGroup>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } Collider[] componentsInChildren2 = val3.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren2[i]); } Renderer[] componentsInChildren3 = val3.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { componentsInChildren3[i].enabled = true; } return 1; } } internal static class BicicretaAssets { private const string BundleResourceName = "bicicreta"; private const string IconResourceName = "Bicicreta.Assets.bicicreta_icon.png"; internal static AssetBundle Bundle { get; private set; } internal static Sprite Icon { get; private set; } internal static void Load() { Assembly executingAssembly = Assembly.GetExecutingAssembly(); if (HasEmbeddedResource(executingAssembly, "bicicreta")) { Bundle = AssetUtils.LoadAssetBundleFromResources("bicicreta", executingAssembly); BicicretaPlugin.Log.LogInfo((object)"Loaded asset bundle 'bicicreta'."); } Icon = LoadEmbeddedSprite(executingAssembly, "Bicicreta.Assets.bicicreta_icon.png"); } private static bool HasEmbeddedResource(Assembly assembly, string name) { string[] manifestResourceNames = assembly.GetManifestResourceNames(); for (int i = 0; i < manifestResourceNames.Length; i++) { if (manifestResourceNames[i].EndsWith(name, StringComparison.OrdinalIgnoreCase)) { return true; } } return false; } private static Sprite LoadEmbeddedSprite(Assembly assembly, string resourceName) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) using Stream stream = assembly.GetManifestResourceStream(resourceName); if (stream == null) { BicicretaPlugin.Log.LogWarning((object)("Embedded sprite '" + resourceName + "' missing; the piece will use its clone source's icon.")); return null; } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2); if (!AssetUtils.LoadImage(val, memoryStream.ToArray())) { BicicretaPlugin.Log.LogWarning((object)("Could not decode '" + resourceName + "'.")); return null; } return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } } internal static class BicicretaBody { internal static void Apply(GameObject prefab) { Resize(prefab); LowerRider(prefab); } private static void Resize(GameObject prefab) { //IL_0046: 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) CapsuleCollider component = prefab.GetComponent<CapsuleCollider>(); if ((Object)(object)component == (Object)null) { BicicretaPlugin.Log.LogWarning((object)"No CapsuleCollider on the bicycle; it will keep the lox's bulk."); return; } component.height = 1.3f; component.radius = 0.45f; component.center = new Vector3(0f, 0.65f, 0f); CapsuleCollider[] componentsInChildren = prefab.GetComponentsInChildren<CapsuleCollider>(true); foreach (CapsuleCollider val in componentsInChildren) { if ((Object)(object)val != (Object)(object)component) { ((Component)val).gameObject.SetActive(false); } } Transform val2 = prefab.transform.Find("EyePos"); if ((Object)(object)val2 != (Object)null) { val2.localPosition = new Vector3(0f, 1.03f, 0f); } } private static void LowerRider(GameObject prefab) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) Sadle componentInChildren = prefab.GetComponentInChildren<Sadle>(true); if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.m_attachPoint == (Object)null) { BicicretaPlugin.Log.LogWarning((object)"No saddle attach point; the rider will sit at lox height."); return; } Vector3 localPosition = default(Vector3); ((Vector3)(ref localPosition))..ctor(0f, 1.015f, -0.099999994f); componentInChildren.m_attachPoint.SetParent(prefab.transform, false); componentInChildren.m_attachPoint.localPosition = localPosition; componentInChildren.m_attachPoint.localRotation = Quaternion.identity; ((Component)componentInChildren).transform.localPosition = localPosition; Collider[] components = ((Component)componentInChildren).GetComponents<Collider>(); for (int i = 0; i < components.Length; i++) { components[i].enabled = false; } } } internal static class BicicretaGeometry { internal const float WheelRadius = 0.4f; internal const float FrontWheel = 0.55f; internal const float RearWheel = -1.35f; internal const float FrameFront = 0.55f; internal const float FrameBack = -0.95f; internal const float FrameLength = 1.5f; internal const float FrameMiddle = -0.19999999f; internal const float FrameWidth = 0.3f; internal const float FrameHeight = 0.6f; internal const float FrameBodyFront = 0.08f; internal const float SeatPanHeight = 1.03f; internal const float SeatPanOffset = -0.56f; internal const float RiderSeatBack = 0.46f; internal const float RiderSeatDrop = -0.015f; internal const float AttachHeight = 1.015f; internal const float AttachOffset = -0.099999994f; internal const float HandlebarHeight = 1.47f; internal const float HandlebarOffset = -0.06f; internal const float HandlebarWidth = 0.36f; internal const float BarThickness = 0.07f; internal const float StemOffset = 0.044999998f; internal const float BodyHeight = 1.3f; internal const float BodyRadius = 0.45f; internal const float HitRadius = 1.35f; } internal static class BicicretaHarmless { internal static void Apply(GameObject prefab) { int num = Disarm(prefab); int num2 = 0; Aoe[] componentsInChildren = prefab.GetComponentsInChildren<Aoe>(true); foreach (Aoe obj in componentsInChildren) { obj.m_hitProps = false; obj.m_hitTerrain = false; obj.m_radius = Mathf.Min(obj.m_radius, 1.35f); num2++; } BicicretaPlugin.Log.LogInfo((object)$"Dropped {num} lox weapon(s) and held {num2} collision damager(s) to living targets."); } private static int Disarm(GameObject prefab) { Humanoid component = prefab.GetComponent<Humanoid>(); if ((Object)(object)component == (Object)null) { BicicretaPlugin.Log.LogWarning((object)"No Humanoid on the bicycle; it may still be armed."); return 0; } int result = Count(component.m_defaultItems) + Count(component.m_randomWeapon); component.m_defaultItems = (GameObject[])(object)new GameObject[0]; component.m_randomWeapon = (GameObject[])(object)new GameObject[0]; component.m_randomItems = (RandomItem[])(object)new RandomItem[0]; component.m_randomSets = (ItemSet[])(object)new ItemSet[0]; component.m_unarmedWeapon = null; return result; } private static int Count(GameObject[] items) { if (items != null) { return items.Length; } return 0; } } internal static class BicicretaMount { internal const string PrefabName = "bicicreta_mount"; private const string CloneSource = "Lox"; internal static bool Register() { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_007e: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown GameObject val = PrefabManager.Instance.CreateClonedPrefab("bicicreta_mount", "Lox"); if ((Object)(object)val == (Object)null) { BicicretaPlugin.Log.LogError((object)"Could not clone 'Lox'; has the game changed it?"); return false; } if (!Tame(val) || !Domesticate(val) || !TuneRiding(val)) { return false; } BicicretaHarmless.Apply(val); BicicretaBody.Apply(val); BicicretaAppearance.Apply(val); BicicretaSilence.Apply(val); CreatureConfig val2 = new CreatureConfig { Name = "$bicicreta_mount_name", Faction = (Faction)0 }; CustomCreature val3 = new CustomCreature(val, false, val2); if (!CreatureManager.Instance.AddCreature(val3)) { BicicretaPlugin.Log.LogError((object)"Failed to register creature 'bicicreta_mount'."); return false; } return true; } private static bool Tame(GameObject prefab) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown Tameable component = prefab.GetComponent<Tameable>(); if ((Object)(object)component == (Object)null) { BicicretaPlugin.Log.LogError((object)"'Lox' has no Tameable component."); return false; } component.m_startsTamed = true; component.m_commandable = false; component.m_dropSaddleOnDeath = false; component.m_petEffect = new EffectList(); prefab.AddComponent<BicicretaTag>(); return true; } private static bool Domesticate(GameObject prefab) { MonsterAI component = prefab.GetComponent<MonsterAI>(); if ((Object)(object)component == (Object)null) { BicicretaPlugin.Log.LogError((object)"'Lox' has no MonsterAI component."); return false; } ((BaseAI)component).m_randomMoveRange = 0f; ((BaseAI)component).m_randomMoveInterval = 0f; component.m_alertRange = 0f; component.m_enableHuntPlayer = false; component.m_attackPlayerObjects = false; ((BaseAI)component).m_afraidOfFire = false; ((BaseAI)component).m_avoidFire = false; component.m_consumeItems?.Clear(); ((BaseAI)component).m_avoidWater = true; ((BaseAI)component).m_avoidLava = true; prefab.GetComponent<CharacterDrop>()?.m_drops.Clear(); return true; } private static bool TuneRiding(GameObject prefab) { Sadle componentInChildren = prefab.GetComponentInChildren<Sadle>(true); if ((Object)(object)componentInChildren == (Object)null) { BicicretaPlugin.Log.LogError((object)"'Lox' has no Sadle component to ride."); return false; } componentInChildren.m_hoverText = "$bicicreta_mount_ride"; float value = BicicretaPlugin.StaminaDrain.Value; componentInChildren.m_runStaminaDrain *= value; componentInChildren.m_swimStaminaDrain *= value; Character component = prefab.GetComponent<Character>(); if ((Object)(object)component != (Object)null) { float value2 = BicicretaPlugin.RideSpeed.Value; component.m_speed *= value2; component.m_runSpeed *= value2; component.m_turnSpeed *= value2; component.m_runTurnSpeed *= value2; } return true; } internal static void RegisterDrops() { //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown GameObject prefab = PrefabManager.Instance.GetPrefab("bicicreta_mount"); CharacterDrop val = ((prefab != null) ? prefab.GetComponent<CharacterDrop>() : null); if ((Object)(object)val == (Object)null) { BicicretaPlugin.Log.LogWarning((object)"No CharacterDrop on the bicycle; it will refund nothing."); return; } val.m_drops.Clear(); RequirementConfig[] resources = BicicretaStand.Resources; foreach (RequirementConfig val2 in resources) { ObjectDB instance = ObjectDB.instance; GameObject val3 = ((instance != null) ? instance.GetItemPrefab(val2.Item) : null); if ((Object)(object)val3 == (Object)null) { BicicretaPlugin.Log.LogWarning((object)("Could not resolve '" + val2.Item + "' to refund.")); continue; } int num = val2.Amount / 2; val.m_drops.Add(new Drop { m_prefab = val3, m_amountMin = num, m_amountMax = num, m_chance = 1f }); } BicicretaPlugin.Log.LogInfo((object)$"Bicicreta refunds {val.m_drops.Count} material type(s) when broken."); } } [BepInPlugin("com.gitmcp.bicicreta", "Bicicreta", "0.7.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class BicicretaPlugin : BaseUnityPlugin { public const string PluginGuid = "com.gitmcp.bicicreta"; public const string PluginName = "Bicicreta"; public const string PluginVersion = "0.7.0"; internal static ManualLogSource Log; internal static ConfigEntry<float> RideSpeed; internal static ConfigEntry<float> StaminaDrain; internal static ConfigEntry<bool> UseStandInModel; private Harmony _harmony; private void Awake() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; BindConfig(); _harmony = new Harmony("com.gitmcp.bicicreta"); _harmony.PatchAll(typeof(BicicretaPlugin).Assembly); PrefabManager.OnVanillaPrefabsAvailable += RegisterContent; ItemManager.OnItemsRegistered += RegisterDrops; } private void BindConfig() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown RideSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Bicicreta", "RideSpeed", 1.6f, new ConfigDescription("Multiplier on the bicycle's ride speed, relative to a saddled lox.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 4f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); StaminaDrain = ((BaseUnityPlugin)this).Config.Bind<float>("Bicicreta", "StaminaDrain", 0.5f, new ConfigDescription("Multiplier on the stamina pedalling costs, relative to a saddled lox.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); UseStandInModel = ((BaseUnityPlugin)this).Config.Bind<bool>("Bicicreta", "UseStandInModel", true, new ConfigDescription("Hide the lox and build a bicycle out of borrowed vanilla parts. Turn this off to see the unmodified clone, which is useful when diagnosing the model.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); } private void RegisterContent() { PrefabManager.OnVanillaPrefabsAvailable -= RegisterContent; Localizations.Register(); BicicretaAssets.Load(); if (!BicicretaMount.Register()) { Log.LogError((object)"Bicicreta mount was not registered; not adding the build piece."); return; } BicicretaStand.Register(); int num = _harmony.GetPatchedMethods().Count(); Log.LogInfo((object)string.Format("{0} {1} registered its content, {2} method(s) patched.", "Bicicreta", "0.7.0", num)); } private void RegisterDrops() { ItemManager.OnItemsRegistered -= RegisterDrops; BicicretaMount.RegisterDrops(); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class BicicretaSilence { internal static void Apply(GameObject prefab) { int num = 0; MonoBehaviour[] componentsInChildren = prefab.GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } FieldInfo[] fields = ((object)val).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (FieldInfo fieldInfo in fields) { if (fieldInfo.FieldType == typeof(EffectList)) { int num2 = num; object? value = fieldInfo.GetValue(val); num = num2 + Hush((EffectList)((value is EffectList) ? value : null)); } } FootStep val2 = (FootStep)(object)((val is FootStep) ? val : null); if (val2 != null) { num += Hush(val2); } } AudioSource[] componentsInChildren2 = prefab.GetComponentsInChildren<AudioSource>(true); foreach (AudioSource obj in componentsInChildren2) { obj.Stop(); obj.playOnAwake = false; ((Behaviour)obj).enabled = false; num++; } BicicretaPlugin.Log.LogInfo((object)$"Silenced {num} lox sound source(s)."); } private static int Hush(EffectList list) { if (list?.m_effectPrefabs == null) { return 0; } List<EffectData> list2 = new List<EffectData>(); int num = 0; EffectData[] effectPrefabs = list.m_effectPrefabs; foreach (EffectData val in effectPrefabs) { if (MakesSound(val?.m_prefab)) { num++; } else { list2.Add(val); } } list.m_effectPrefabs = list2.ToArray(); return num; } private static int Hush(FootStep steps) { int num = 0; foreach (StepEffect effect in steps.m_effects) { List<GameObject> list = new List<GameObject>(); GameObject[] effectPrefabs = effect.m_effectPrefabs; foreach (GameObject val in effectPrefabs) { if (MakesSound(val)) { num++; } else { list.Add(val); } } effect.m_effectPrefabs = list.ToArray(); } return num; } private static bool MakesSound(GameObject effect) { if ((Object)(object)effect != (Object)null) { return (Object)(object)effect.GetComponentInChildren<AudioSource>(true) != (Object)null; } return false; } } internal static class BicicretaStand { internal const string PrefabName = "bicicreta_stand"; internal static readonly RequirementConfig[] Resources = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig("Wood", 10, 0, true), new RequirementConfig("Bronze", 4, 0, true), new RequirementConfig("LeatherScraps", 4, 0, true) }; private const string CloneSource = "Cart"; internal static void Register() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown GameObject val = PrefabManager.Instance.CreateClonedPrefab("bicicreta_stand", "Cart"); if ((Object)(object)val == (Object)null) { BicicretaPlugin.Log.LogError((object)"Could not clone 'Cart' for the build piece."); return; } Vagon component = val.GetComponent<Vagon>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } val.AddComponent<BicicretaStandSpawner>(); PieceConfig val2 = new PieceConfig { Name = "$bicicreta_stand_name", Description = "$bicicreta_stand_description", PieceTable = PieceTables.Hammer, Category = PieceCategories.Misc, CraftingStation = CraftingStations.Workbench, Requirements = Resources }; if ((Object)(object)BicicretaAssets.Icon != (Object)null) { val2.Icon = BicicretaAssets.Icon; } CustomPiece val3 = new CustomPiece(val, false, val2); if (!PieceManager.Instance.AddPiece(val3)) { BicicretaPlugin.Log.LogError((object)"Failed to register piece 'bicicreta_stand'."); } } } internal class BicicretaStandSpawner : MonoBehaviour { private void Awake() { ZNetView component = ((Component)this).GetComponent<ZNetView>(); if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner()) { ((MonoBehaviour)this).Invoke("SpawnBicycle", 0f); } } private void SpawnBicycle() { //IL_0058: 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) ZNetView component = ((Component)this).GetComponent<ZNetView>(); if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner()) { ZNetScene instance = ZNetScene.instance; GameObject val = ((instance != null) ? instance.GetPrefab("bicicreta_mount") : null); if ((Object)(object)val == (Object)null) { BicicretaPlugin.Log.LogError((object)"'bicicreta_mount' is not registered; leaving the piece in place."); return; } Object.Instantiate<GameObject>(val, ((Component)this).transform.position, ((Component)this).transform.rotation); component.Destroy(); } } } internal class BicicretaTag : MonoBehaviour { private Sadle _saddle; internal Sadle Saddle { get { if ((Object)(object)_saddle == (Object)null) { _saddle = ((Component)this).GetComponentInChildren<Sadle>(true); } return _saddle; } } } internal class BicicretaWheels : MonoBehaviour { private const float DegreesPerMetre = 450f / (float)Math.PI; private const float SpeedEasing = 8f; private const float Still = 0.01f; internal Transform FrontHub; internal Transform RearHub; private Character _character; private float _speed; private float _angle; private void Awake() { _character = ((Component)this).GetComponent<Character>(); } private void LateUpdate() { //IL_0031: 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_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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)FrontHub == (Object)null) && !((Object)(object)RearHub == (Object)null) && !((Object)(object)_character == (Object)null)) { float num = Vector3.Dot(_character.GetVelocity(), ((Component)this).transform.forward); if (Mathf.Abs(num) < 0.01f && Mathf.Abs(_speed) < 0.01f) { _speed = 0f; return; } _speed = Mathf.Lerp(_speed, num, 1f - Mathf.Exp(-8f * Time.deltaTime)); _angle = Mathf.Repeat(_angle + _speed * (450f / (float)Math.PI) * Time.deltaTime, 360f); Quaternion localRotation = Quaternion.Euler(_angle, 0f, 0f); FrontHub.localRotation = localRotation; RearHub.localRotation = localRotation; } } } internal static class Localizations { internal static void Register() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "bicicreta_stand_name", "Bicicreta" }, { "bicicreta_stand_description", "A two-wheeled contraption. Build it, then ride it." }, { "bicicreta_mount_name", "Bicicreta" }, { "bicicreta_mount_ride", "Ride" } }); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Bicicreta"; public const string PLUGIN_NAME = "Bicicreta"; public const string PLUGIN_VERSION = "0.7.0"; } } namespace Bicicreta.Patches { internal static class BicicretaHover { internal static string Name() { return Localization.instance.Localize("$bicicreta_mount_name"); } internal static string Text() { return Localization.instance.Localize("$bicicreta_mount_name\n[<color=yellow><b>$KEY_Use</b></color>] $bicicreta_mount_ride"); } } [HarmonyPatch(typeof(Sadle))] internal static class SadlePatches { [HarmonyPrefix] [HarmonyPatch("Interact")] private static bool NeverRemoveSaddle(Sadle __instance, bool alt, ref bool __result) { if (!alt || (Object)(object)((Component)__instance).GetComponentInParent<BicicretaTag>() == (Object)null) { return true; } __result = false; return false; } [HarmonyPrefix] [HarmonyPatch("GetHoverText")] private static bool HoverText(Sadle __instance, ref string __result) { if ((Object)(object)((Component)__instance).GetComponentInParent<BicicretaTag>() == (Object)null) { return true; } __result = BicicretaHover.Text(); return false; } } [HarmonyPatch(typeof(Tameable))] internal static class TameablePatches { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void KeepSaddleFitted(Tameable __instance) { if (!((Object)(object)((Component)__instance).GetComponent<BicicretaTag>() == (Object)null)) { ZNetView nview = __instance.m_nview; if ((Object)(object)nview != (Object)null && nview.IsValid() && nview.IsOwner()) { nview.GetZDO().Set(ZDOVars.s_haveSaddleHash, true); } if ((Object)(object)__instance.m_saddle != (Object)null) { ((Component)__instance.m_saddle).gameObject.SetActive(true); } } } [HarmonyPrefix] [HarmonyPatch("Interact")] private static bool RideInsteadOfPetting(Tameable __instance, Humanoid user, bool hold, bool alt, ref bool __result) { BicicretaTag component = ((Component)__instance).GetComponent<BicicretaTag>(); if ((Object)(object)component == (Object)null) { return true; } __result = false; if (hold || alt) { return false; } Sadle saddle = component.Saddle; if ((Object)(object)saddle == (Object)null) { return false; } __result = saddle.Interact(user, false, false); return false; } [HarmonyPrefix] [HarmonyPatch("GetHoverText")] private static bool HoverText(Tameable __instance, ref string __result) { if ((Object)(object)((Component)__instance).GetComponent<BicicretaTag>() == (Object)null) { return true; } __result = BicicretaHover.Text(); return false; } [HarmonyPrefix] [HarmonyPatch("GetHoverName")] private static bool HoverName(Tameable __instance, ref string __result) { if ((Object)(object)((Component)__instance).GetComponent<BicicretaTag>() == (Object)null) { return true; } __result = BicicretaHover.Name(); return false; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }