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 TankMod v1.0.0
TankMod.dll
Decompiled 2 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; 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 System.Text.RegularExpressions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using REPOLib.Modules; using TankMod.Items; using TankMod.Runtime; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("Joja")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+49705602d67efb07c4fe49d280db4904df16092c")] [assembly: AssemblyProduct("TankMod")] [assembly: AssemblyTitle("TankMod")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.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.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] [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] [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 TankMod { [HarmonyPatch(typeof(ItemVehicle), "PlayHonk")] internal static class NoTankHonkPatch { private static bool Prefix(ItemVehicle __instance) { return (Object)(object)((Component)__instance).GetComponent<TankCannon>() == (Object)null; } } [BepInPlugin("Joja.TankMod", "TankMod", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class TankModPlugin : BaseUnityPlugin { internal static TankModPlugin Instance { get; private set; } internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } private void Awake() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); ((MonoBehaviour)this).StartCoroutine(RegisterWhenReady()); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } private static IEnumerator RegisterWhenReady() { List<ItemSpec> pendingItems = new List<ItemSpec> { Tank.Spec }; int attempt; for (attempt = 0; attempt < 1200; attempt++) { if (pendingItems.Count <= 0) { break; } pendingItems.RemoveAll((ItemSpec spec) => ItemBuilder.Register(spec, attempt) != ValuableBuilder.Result.TemplateMissing); if (pendingItems.Count > 0) { yield return null; } } foreach (ItemSpec item in pendingItems) { Logger.LogError((object)("Gave up registering item '" + item.Name + "': no vanilla item template became available.")); } } private void OnDestroy() { Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } } namespace TankMod.Runtime { internal static class EmbeddedAssets { private static readonly Assembly Assembly = typeof(EmbeddedAssets).Assembly; private static readonly string[] Names = Assembly.GetManifestResourceNames(); public static byte[] ReadBytes(string path) { using Stream stream = Open(path); using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return memoryStream.ToArray(); } public static string ReadText(string path) { using Stream stream = Open(path); using StreamReader streamReader = new StreamReader(stream); return streamReader.ReadToEnd(); } public static Texture2D LoadTexture(string path, bool linear = false) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear) { name = Path.GetFileNameWithoutExtension(path) }; if (!ImageConversion.LoadImage(val, ReadBytes(path))) { throw new InvalidDataException("Could not decode texture '" + path + "'."); } ((Texture)val).wrapMode = (TextureWrapMode)0; return val; } private static Stream Open(string path) { string wanted = Normalize(path); string text = Names.FirstOrDefault((string n) => Normalize(n).EndsWith(wanted, StringComparison.OrdinalIgnoreCase)); if (text == null) { throw new FileNotFoundException("Embedded asset '" + path + "' not found. Available: " + string.Join(", ", Names)); } return Assembly.GetManifestResourceStream(text); } public static AudioClip LoadWavPcm16(string path) { byte[] array = ReadBytes(path); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = -1; int num6 = 0; using (MemoryStream memoryStream = new MemoryStream(array)) { using BinaryReader binaryReader = new BinaryReader(memoryStream); if (binaryReader.ReadUInt32() != 1179011410) { throw new InvalidDataException("Invalid WAV file."); } binaryReader.ReadUInt32(); if (binaryReader.ReadUInt32() != 1163280727) { throw new InvalidDataException("Invalid WAV file."); } while (memoryStream.Position + 8 <= memoryStream.Length) { string text = new string(binaryReader.ReadChars(4)); int num7 = binaryReader.ReadInt32(); long num8 = memoryStream.Position + num7; if (text == "fmt ") { num4 = binaryReader.ReadUInt16(); num = binaryReader.ReadUInt16(); num2 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadUInt16(); num3 = binaryReader.ReadUInt16(); } else if (text == "data") { num5 = (int)memoryStream.Position; num6 = num7; } memoryStream.Position = num8 + (num7 & 1); if (memoryStream.Position > memoryStream.Length) { break; } } } if (num4 != 1 || num3 != 16) { throw new InvalidDataException($"Expected 16-bit PCM WAV. Format: {num4}, Bit depth: {num3}"); } if (num5 < 0 || num <= 0 || num2 <= 0) { throw new InvalidDataException("WAV file is missing audio data."); } int num9 = num6 / 2; float[] array2 = new float[num9]; for (int i = 0; i < num9; i++) { short num10 = BitConverter.ToInt16(array, num5 + i * 2); array2[i] = (float)num10 / 32768f; } int num11 = num9 / num; AudioClip val = AudioClip.Create(Path.GetFileNameWithoutExtension(path), num11, num, num2, false); val.SetData(array2, 0); ((Object)val).hideFlags = (HideFlags)32; return val; } private static string Normalize(string s) { return s.Replace('\\', '/'); } } internal sealed class GrabButtonPlacer : MonoBehaviour { public Vector3 Target; private IEnumerator Start() { yield return null; ItemVehicle component = ((Component)this).GetComponent<ItemVehicle>(); if ((Object)(object)component == (Object)null) { yield break; } Transform val = Find("Cart Handle"); Transform val2 = Find("Semi Grab Area"); VehicleSeat val3 = ((component.seats != null && component.seats.Length != 0) ? component.seats[0] : null); Vector3 val4 = (((Object)(object)val != (Object)null) ? val.position : (((Object)(object)val3?.grabPoint != (Object)null) ? val3.grabPoint.position : ((Component)this).transform.position)); Vector3 val5 = Target - ((Component)this).transform.InverseTransformPoint(val4); Vector3 val6 = ((Component)this).transform.TransformVector(val5); List<Transform> list = new List<Transform>(); Transform[] array = (Transform[])(object)new Transform[4] { val, val2, val3?.grabPoint, val3?.grabPointVisual }; foreach (Transform t in array) { if (!((Object)(object)t == (Object)null) && !list.Any((Transform m) => (Object)(object)t == (Object)(object)m || t.IsChildOf(m))) { Vector3 val7 = ((Component)this).transform.InverseTransformPoint(t.position); list.Add(t); Transform obj = t; obj.position += val6; ManualLogSource logger = TankModPlugin.Logger; object[] obj2 = new object[4] { ((Object)t).name, null, null, null }; Transform parent = t.parent; obj2[1] = ((parent != null) ? ((Object)parent).name : null); obj2[2] = val7; obj2[3] = ((Component)this).transform.InverseTransformPoint(t.position); logger.LogInfo((object)string.Format("GrabButton: '{0}' (parent '{1}') {2:F2} -> {3:F2} (vehicle coordinates)", obj2)); } } TankModPlugin.Logger.LogInfo((object)$"GrabButton: target {Target:F2}, vehicle scale {((Component)this).transform.lossyScale:F2}"); } private Transform? Find(string name) { return ItemBuilder.FindDeep(((Component)this).transform, name); } } internal sealed class IdleBrake : MonoBehaviour { public float HorizontalDamping = 4f; public float AngularDamping = 4f; public float MaxUpwardSpeed = 0.5f; public float SeatedMaxUpwardSpeed = 2f; private ItemVehicle? _vehicle; private PhysGrabObject? _grabObject; private Rigidbody? _body; private static readonly PropertyInfo? VelocityProperty = typeof(Rigidbody).GetProperty("linearVelocity") ?? typeof(Rigidbody).GetProperty("velocity"); private float _logTimer; private int _logCount; private void Awake() { _vehicle = ((Component)this).GetComponent<ItemVehicle>(); _grabObject = ((Component)this).GetComponent<PhysGrabObject>(); _body = ((Component)this).GetComponent<Rigidbody>(); } private static object? Field(object target, string name) { return target.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(target); } private void LogState() { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) _logTimer -= Time.fixedDeltaTime; if (!(_logTimer > 0f) && _logCount < 80 && !((Object)(object)_vehicle == (Object)null) && !((Object)(object)_body == (Object)null)) { _logTimer = 0.5f; _logCount++; Transform meshTransform = _vehicle.meshTransform; ManualLogSource logger = TankModPlugin.Logger; string[] obj = new string[9] { $"TankDebug #{_logCount}: y={_body.position.y:F2} vel={VelocityProperty?.GetValue(_body)} mass={_body.mass} gravity={_body.useGravity} ", string.Format("front={0} back={1} airborne={2} ", Field(_vehicle, "isFrontGrounded"), Field(_vehicle, "isBackGrounded"), Field(_vehicle, "isVehicleAirborne")), string.Format("slopeValid={0} slope={1} ", Field(_vehicle, "groundSlopeValid"), Field(_vehicle, "groundSlopePitchAngle")), "meshLocal=", null, null, null, null, null }; object obj2; Vector3 val; if (!((Object)(object)meshTransform != (Object)null)) { obj2 = "none"; } else { val = meshTransform.localPosition; obj2 = ((Vector3)(ref val)).ToString("F2"); } obj[4] = (string)obj2; obj[5] = " meshRot="; object obj3; if (!((Object)(object)meshTransform != (Object)null)) { obj3 = "none"; } else { val = meshTransform.localEulerAngles; obj3 = ((Vector3)(ref val)).ToString("F1"); } obj[6] = (string)obj3; obj[7] = " "; obj[8] = $"state={_vehicle.currentState}"; logger.LogInfo((object)string.Concat(obj)); } } private void FixedUpdate() { //IL_0087: 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_009c: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_0135: 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_015b: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_vehicle == (Object)null || (Object)(object)_body == (Object)null || _body.isKinematic || !SemiFunc.IsMasterClientOrSingleplayer()) { return; } bool flag = false; VehicleSeat[] seats = _vehicle.seats; foreach (VehicleSeat val in seats) { if ((Object)(object)val.seatedPlayer != (Object)null) { flag = true; } } if (VelocityProperty == null) { return; } Vector3 val2 = (Vector3)VelocityProperty.GetValue(_body); if (flag) { LogState(); _body.AddForce(Physics.gravity * _body.mass, (ForceMode)0); if (val2.y > SeatedMaxUpwardSpeed) { val2.y = SeatedMaxUpwardSpeed; VelocityProperty.SetValue(_body, val2); } } else if (!((Object)(object)_grabObject != (Object)null) || !_grabObject.grabbed) { float num = Mathf.Clamp01(1f - HorizontalDamping * Time.fixedDeltaTime); val2.x *= num; val2.z *= num; if (val2.y > MaxUpwardSpeed) { val2.y = MaxUpwardSpeed; } VelocityProperty.SetValue(_body, val2); Rigidbody? body = _body; body.angularVelocity *= Mathf.Clamp01(1f - AngularDamping * Time.fixedDeltaTime); } } } internal static class ItemBuilder { private static readonly string[] MeshNodes = new string[2] { "Mesh Healthy", "Mesh Broken" }; public static ValuableBuilder.Result Register(ItemSpec spec, int attempt) { try { GameObject val = Resources.Load<GameObject>(spec.Template); if ((Object)(object)val == (Object)null) { if (attempt == 0 || attempt % 120 == 0) { TankModPlugin.Logger.LogWarning((object)$"Item template '{spec.Template}' not found yet (attempt {attempt})."); } return ValuableBuilder.Result.TemplateMissing; } GameObject val2 = ((spec is VehicleSpec spec2) ? VehicleBuilder.Build(spec2, val) : Build(spec, val)); Items.RegisterItem(val2.GetComponent<ItemAttributes>()); TankModPlugin.Logger.LogInfo((object)$"Registered item '{spec.ItemName}' (template '{((Object)val).name}', attempt {attempt})."); return ValuableBuilder.Result.Registered; } catch (Exception arg) { TankModPlugin.Logger.LogError((object)$"Failed to register item '{spec.Name}': {arg}"); return ValuableBuilder.Result.Failed; } } private static GameObject Build(ItemSpec spec, GameObject template) { //IL_0096: 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_00ba: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(template, ValuableBuilder.Holder); ((Object)val).name = spec.Name; Renderer componentInChildren = template.GetComponentInChildren<Renderer>(true); Material baseMaterial = ((componentInChildren != null) ? componentInChildren.sharedMaterial : null); object physicsMaterial = ValuableBuilder.GetPhysicsMaterial(template.GetComponentInChildren<Collider>(true)); PhysGrabObjectCollider[] componentsInChildren = val.GetComponentsInChildren<PhysGrabObjectCollider>(true); foreach (PhysGrabObjectCollider val2 in componentsInChildren) { Object.DestroyImmediate((Object)(object)((Component)val2).gameObject); } ValuableBuilder.BuildColliders(spec.Colliders, val.transform, physicsMaterial); ReplaceMeshes(val, spec, baseMaterial); Vector3? forceGrabPoint = spec.ForceGrabPoint; if (forceGrabPoint.HasValue) { Vector3 valueOrDefault = forceGrabPoint.GetValueOrDefault(); Transform val3 = FindDeep(val.transform, "Force Grab Point"); if ((Object)(object)val3 != (Object)null) { val3.localPosition = valueOrDefault; } else { TankModPlugin.Logger.LogWarning((object)"Template has no 'Force Grab Point'."); } } ApplyTuning(spec, val); ApplyItem(spec, val); try { val.GetComponent<ItemAttributes>().icon = LoadIcon(spec.Folder); } catch (Exception ex) { TankModPlugin.Logger.LogWarning((object)("Could not load an icon for '" + spec.Name + "': " + ex.Message)); } return val; } private static (Mesh, Material) ReplaceMeshes(GameObject root, ItemSpec spec, Material? baseMaterial) { //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, Mesh> dictionary = ValuableBuilder.LoadMeshes(spec.Folder + "/" + spec.ObjFile, spec.Part.Part == "*"); if (!dictionary.TryGetValue(spec.Part.Part, out var value)) { throw new KeyNotFoundException("OBJ '" + spec.ObjFile + "' has no part '" + spec.Part.Part + "'. Parts: " + string.Join(", ", dictionary.Keys)); } Material val = ValuableBuilder.CreateMaterial(baseMaterial, spec.Part, spec.Folder, shiny: false); ManualLogSource logger = TankModPlugin.Logger; string name = spec.Name; object arg = value.vertexCount; Bounds bounds = value.bounds; logger.LogInfo((object)$"{name}: {arg} vertices, size={((Bounds)(ref bounds)).size}"); string[] meshNodes = MeshNodes; foreach (string text in meshNodes) { Transform val2 = FindDeep(root.transform, text); if ((Object)(object)val2 == (Object)null) { throw new InvalidOperationException("Template has no '" + text + "' node."); } foreach (Transform item in ((IEnumerable)val2).Cast<Transform>().ToList()) { Object.DestroyImmediate((Object)(object)((Component)item).gameObject); } foreach (Component item2 in (from c in ((Component)val2).GetComponents<Component>() where c is MeshFilter || c is MeshRenderer select c).ToList()) { Object.DestroyImmediate((Object)(object)item2); } val2.localPosition = spec.MeshPosition; val2.localRotation = Quaternion.Euler(spec.MeshEuler); val2.localScale = spec.MeshScale; ((Component)val2).gameObject.AddComponent<MeshFilter>().sharedMesh = value; ((Renderer)((Component)val2).gameObject.AddComponent<MeshRenderer>()).sharedMaterial = val; } return (value, val); } private static void ApplyTuning(ItemSpec spec, GameObject root) { if (spec.RigidbodyMass >= 0f) { Rigidbody component = root.GetComponent<Rigidbody>(); if (component != null) { component.mass = spec.RigidbodyMass; } } ItemMelee component2 = root.GetComponent<ItemMelee>(); if ((Object)(object)component2 != (Object)null) { if (spec.DurabilityDrain >= 0f) { component2.durabilityDrainOnEnemiesAndPVP = spec.DurabilityDrain; } if (spec.TorqueStrength >= 0f) { component2.torqueStrength = spec.TorqueStrength; } } NotValuableObject component3 = root.GetComponent<NotValuableObject>(); if ((Object)(object)component3 != (Object)null && spec.ParticleColors != null) { component3.particleColors = spec.ParticleColors; } } internal static void ApplyItem(ItemSpec spec, GameObject root) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) ItemAttributes component = root.GetComponent<ItemAttributes>(); if ((Object)(object)component == (Object)null || (Object)(object)component.item == (Object)null) { throw new InvalidOperationException("Template has no ItemAttributes/Item."); } Item val = Object.Instantiate<Item>(component.item); ((Object)val).name = spec.Name; val.itemName = spec.ItemName; val.itemNameLocalized = null; val.description = spec.Description; if (!spec.KeepTemplateShopSettings) { val.itemType = (itemType)spec.ItemType; val.emojiIcon = (emojiIcon)spec.EmojiIcon; val.itemVolume = (itemVolume)spec.ItemVolume; val.itemSecretShopType = (itemSecretShopType)spec.SecretShopType; val.maxAmount = spec.MaxAmount; val.maxAmountInShop = spec.MaxAmountInShop; val.maxPurchase = spec.MaxPurchase; val.maxPurchaseAmount = spec.MaxPurchaseAmount; val.physicalItem = spec.PhysicalItem; val.value = ValuableBuilder.Preset<Value>("value", spec.ValuePreset, val.value); } val.disabled = false; if (spec.ValueMin >= 0f) { Value val2 = ScriptableObject.CreateInstance<Value>(); ((Object)val2).name = spec.Name + " Value"; val2.valueMin = spec.ValueMin; val2.valueMax = ((spec.ValueMax >= spec.ValueMin) ? spec.ValueMax : spec.ValueMin); ((Object)val2).hideFlags = (HideFlags)32; val.value = val2; } ((Object)val).hideFlags = (HideFlags)32; component.item = val; } internal static Sprite LoadIcon(string folder) { //IL_0032: 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) Texture2D val = EmbeddedAssets.LoadTexture(folder + "/icon.png"); ((Texture)val).wrapMode = (TextureWrapMode)1; Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); ((Object)val2).hideFlags = (HideFlags)32; return val2; } internal static Transform? FindDeep(Transform parent, string name) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown foreach (Transform item in parent) { Transform val = item; if (((Object)val).name == name) { return val; } Transform val2 = FindDeep(val, name); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } } internal class ItemSpec { public string Name = ""; public string ItemName = ""; public string Description = ""; public string Template = "Items/Item Melee Sledge Hammer"; public string Folder = ""; public string ObjFile = ""; public MeshPartSpec Part = new MeshPartSpec(); public Vector3 MeshPosition; public Vector3 MeshEuler; public Vector3 MeshScale = Vector3.one; public ColliderSpec[] Colliders = Array.Empty<ColliderSpec>(); public Vector3? ForceGrabPoint; public float RigidbodyMass = -1f; public float DurabilityDrain = -1f; public float TorqueStrength = -1f; public Gradient? ParticleColors; public string ValuePreset = "Value Expensive"; public int ItemType = 7; public int EmojiIcon = 16; public int ItemVolume = 2; public int SecretShopType = 1; public int MaxAmount = 1; public int MaxAmountInShop = 1; public bool MaxPurchase; public int MaxPurchaseAmount = 1; public bool PhysicalItem = true; public float ValueMin = -1f; public float ValueMax = -1f; public bool KeepTemplateShopSettings; } internal static class ObjLoader { private sealed class Group { public readonly string Name; public readonly List<int> Triangles = new List<int>(); private readonly List<Vector3> _vertices = new List<Vector3>(); private readonly List<Vector2> _uvs = new List<Vector2>(); private readonly List<Vector3> _normals = new List<Vector3>(); private readonly Dictionary<(int, int, int), int> _lookup = new Dictionary<(int, int, int), int>(); private bool _hasUv; private bool _hasNormals; public Group(string name) { Name = name; } public int Vertex(int v, int t, int n, List<Vector3> positions, List<Vector2> uvs, List<Vector3> normals) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0059: 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_0083: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) if (_lookup.TryGetValue((v, t, n), out var value)) { return value; } Vector3 val = positions[v]; _vertices.Add(new Vector3(0f - val.x, val.y, val.z)); if (t >= 0) { _hasUv = true; _uvs.Add(uvs[t]); } else { _uvs.Add(Vector2.zero); } if (n >= 0) { _hasNormals = true; Vector3 val2 = normals[n]; _normals.Add(new Vector3(0f - val2.x, val2.y, val2.z)); } else { _normals.Add(Vector3.up); } int num = _vertices.Count - 1; _lookup[(v, t, n)] = num; return num; } public Mesh Build() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown Mesh val = new Mesh { name = Name }; if (_vertices.Count > 65535) { val.indexFormat = (IndexFormat)1; } val.SetVertices(_vertices); if (_hasUv) { val.SetUVs(0, _uvs); } val.SetTriangles(Triangles, 0); if (_hasNormals) { val.SetNormals(_normals); } else { val.RecalculateNormals(); } val.RecalculateBounds(); return val; } } public static Dictionary<string, Mesh> Load(string text, bool mergeGroups = false) { //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) List<Vector3> list = new List<Vector3>(); List<Vector2> list2 = new List<Vector2>(); List<Vector3> list3 = new List<Vector3>(); Dictionary<string, Group> dictionary = new Dictionary<string, Group>(); Group obj = null; string[] array = text.Split('\n'); foreach (string text2 in array) { string text3 = text2.Trim(); if (text3.Length == 0 || text3[0] == '#') { continue; } string[] array2 = text3.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries); switch (array2[0]) { case "v": list.Add(new Vector3(F(array2[1]), F(array2[2]), F(array2[3]))); break; case "vt": list2.Add(new Vector2(F(array2[1]), F(array2[2]))); break; case "vn": list3.Add(new Vector3(F(array2[1]), F(array2[2]), F(array2[3]))); break; case "o": case "g": obj = GetGroup(dictionary, mergeGroups ? "*" : ((array2.Length > 1) ? array2[1] : "mesh")); break; case "f": if (obj == null) { obj = GetGroup(dictionary, mergeGroups ? "*" : "mesh"); } AddFace(obj, array2, list, list2, list3); break; } } Dictionary<string, Mesh> dictionary2 = new Dictionary<string, Mesh>(); foreach (KeyValuePair<string, Group> item in dictionary) { dictionary2[item.Key] = item.Value.Build(); } return dictionary2; } private static Group GetGroup(Dictionary<string, Group> groups, string name) { if (!groups.TryGetValue(name, out Group value)) { value = (groups[name] = new Group(name)); } return value; } private static float F(string s) { return float.Parse(s, CultureInfo.InvariantCulture); } private static void AddFace(Group group, string[] parts, List<Vector3> positions, List<Vector2> uvs, List<Vector3> normals) { int[] array = new int[parts.Length - 1]; for (int i = 1; i < parts.Length; i++) { string[] array2 = parts[i].Split('/'); int v = Resolve(int.Parse(array2[0], CultureInfo.InvariantCulture), positions.Count); int t = ((array2.Length > 1 && array2[1].Length > 0) ? Resolve(int.Parse(array2[1], CultureInfo.InvariantCulture), uvs.Count) : (-1)); int n = ((array2.Length > 2 && array2[2].Length > 0) ? Resolve(int.Parse(array2[2], CultureInfo.InvariantCulture), normals.Count) : (-1)); array[i - 1] = group.Vertex(v, t, n, positions, uvs, normals); } for (int j = 1; j < array.Length - 1; j++) { group.Triangles.Add(array[0]); group.Triangles.Add(array[j + 1]); group.Triangles.Add(array[j]); } } private static int Resolve(int index, int count) { if (index <= 0) { return count + index; } return index - 1; } } internal static class PresetLibrary { public static T? Find<T>(string kind, string name) where T : Object { if (string.IsNullOrEmpty(name)) { return default(T); } T val = Resources.FindObjectsOfTypeAll<T>().FirstOrDefault((T p) => ((Object)p).name == name); if ((Object)(object)val != (Object)null) { return val; } if (!PresetSources.Map.TryGetValue((kind, name), out string value)) { return default(T); } GameObject obj = Resources.Load<GameObject>(value); ValuableObject val2 = ((obj != null) ? obj.GetComponent<ValuableObject>() : null); if ((Object)(object)val2 == (Object)null) { return default(T); } object obj2 = kind switch { "durability" => val2.durabilityPreset, "value" => val2.valuePreset, "phys" => val2.physAttributePreset, "audio" => val2.audioPreset, _ => null, }; return (T)((obj2 is T) ? obj2 : null); } } internal static class PresetSources { public static readonly Dictionary<(string Kind, string Name), string> Map = new Dictionary<(string, string), string> { [("audio", "PhysAudio - Alchemy Table")] = "Valuables/05 Wide/Valuable Wizard Alchemy Station", [("audio", "PhysAudio - Balloon")] = "Valuables/03 Medium/Valuable Museum Handface", [("audio", "PhysAudio - Barrel")] = "Valuables/03 Medium/Valuable Arctic Propane Tank", [("audio", "PhysAudio - Basket ball")] = "Valuables/02 Small/Valuable Museum Cube ball", [("audio", "PhysAudio - Bottle Pack")] = "Valuables/03 Medium/Valuable Arctic Sample Six Pack", [("audio", "PhysAudio - Cardboard")] = "Valuables/03 Medium/Valuable Museum MonkeyBox", [("audio", "PhysAudio - Cauldron box")] = "Valuables/04 Big/Valuable Wizard Cauldron Box", [("audio", "PhysAudio - Ceramic Big")] = "Valuables/04 Big/Valuable Manor Vase Big", [("audio", "PhysAudio - Ceramic Medium")] = "Valuables/03 Medium/Valuable Manor Kettle", [("audio", "PhysAudio - Ceramic Small")] = "Valuables/01 Tiny/Valuable Arctic Coffee Cup", [("audio", "PhysAudio - Computer")] = "Valuables/03 Medium/Valuable Arctic 3D Printer", [("audio", "PhysAudio - Concrete")] = "Valuables/02 Small/Valuable Desert Fossil", [("audio", "PhysAudio - Egg")] = "Valuables/04 Big/Valuable Museum Egg", [("audio", "PhysAudio - Fire Extinguisher")] = "Valuables/03 Medium/Valuable Arctic Fire Extinguisher", [("audio", "PhysAudio - Flamethrower")] = "Valuables/04 Big/Valuable Arctic Flamethrower", [("audio", "PhysAudio - Flesh Medium")] = "Valuables/03 Medium/Valuable Manor Clown", [("audio", "PhysAudio - Flesh Small")] = "Valuables/01 Tiny/Valuable Museum Cool brain", [("audio", "PhysAudio - Gem Burger")] = "Valuables/02 Small/Valuable Desert Gold Bar", [("audio", "PhysAudio - Glass Big")] = "Valuables/07 Very Tall/Valuable Desert Zero Grav crystal", [("audio", "PhysAudio - Glass Liquid Big")] = "Valuables/04 Big/Valuable Wizard Master Potion", [("audio", "PhysAudio - Glass Liquid Medium")] = "Valuables/01 Tiny/Valuable Wizard Glowing Jar", [("audio", "PhysAudio - Glass Medium")] = "Valuables/03 Medium/Valuable Manor Ship in a bottle", [("audio", "PhysAudio - Glass Small")] = "Valuables/01 Tiny/Valuable Arctic Uranium Petri Dish", [("audio", "PhysAudio - Gnome")] = "Valuables/04 Big/Valuable Manor Scream Doll", [("audio", "PhysAudio - Golden Swirl")] = "Valuables/03 Medium/Valuable Wizard Star Wand", [("audio", "PhysAudio - Gross")] = "Valuables/01 Tiny/Valuable Wizard Eye Ball", [("audio", "PhysAudio - Guitar")] = "Valuables/04 Big/Valuable Arctic Guitar", [("audio", "PhysAudio - Harp")] = "Valuables/06 Tall/Valuable Manor Harp", [("audio", "PhysAudio - Hay")] = "Valuables/03 Medium/Valuable Desert Fluffy Buddy", [("audio", "PhysAudio - Heavy Water")] = "Valuables/06 Tall/Valuable Arctic Heavy Water", [("audio", "PhysAudio - Ice Block")] = "Valuables/04 Big/Valuable Arctic Creature Leg", [("audio", "PhysAudio - Leather Medium")] = "Valuables/01 Tiny/Valuable Arctic Eraser", [("audio", "PhysAudio - Metal Hollow Big")] = "Valuables/03 Medium/Valuable Museum Gumball", [("audio", "PhysAudio - Metal Hollow Medium")] = "Valuables/03 Medium/Valuable Arctic Fan", [("audio", "PhysAudio - Metal Hollow Small")] = "Valuables/01 Tiny/Valuable Arctic Stapler", [("audio", "PhysAudio - Milk")] = "Valuables/06 Tall/Valuable Museum Milk", [("audio", "PhysAudio - Paper")] = "Valuables/03 Medium/Valuable Manor Map", [("audio", "PhysAudio - Piano")] = "Valuables/05 Wide/Valuable Manor Piano", [("audio", "PhysAudio - Pill bottle")] = "Valuables/01 Tiny/Valuable Arctic Pills", [("audio", "PhysAudio - Plastic Big")] = "Valuables/03 Medium/Valuable Desert Suitcase", [("audio", "PhysAudio - Plastic Medium")] = "Valuables/01 Tiny/Valuable Arctic Keycard", [("audio", "PhysAudio - Player")] = "Valuables/03 Medium/Valuable Museum Teeth Bot", [("audio", "PhysAudio - Rock Medium")] = "Valuables/02 Small/Valuable Wizard Pendant", [("audio", "PhysAudio - Spider Potion")] = "Valuables/04 Big/Valuable Wizard Spider Potion", [("audio", "PhysAudio - Unicorn Horn")] = "Valuables/04 Big/Valuable Wizard Unicorn Horn", [("audio", "PhysAudio - VHS")] = "Valuables/02 Small/Valuable Arctic VHS", [("audio", "PhysAudio - Wood Door")] = "Valuables/04 Big/Valuable Desert Golden Shovel", [("audio", "PhysAudio - Wood Hollow Big")] = "Valuables/05 Wide/Valuable Manor Animal Crate", [("audio", "PhysAudio - Wood Hollow Medium")] = "Valuables/01 Tiny/Valuable Museum Fish", [("audio", "PhysAudio - Wood Hollow Small")] = "Valuables/01 Tiny/Valuable Museum RubenDoll", [("durability", "Durability Default")] = "Valuables/01 Tiny/Valuable Arctic Phone", [("durability", "Durability Strong")] = "Valuables/01 Tiny/Valuable Arctic Eraser", [("durability", "Durability Strong+")] = "Valuables/01 Tiny/Valuable Arctic Keycard", [("durability", "Durability Weak")] = "Valuables/01 Tiny/Valuable Arctic Coffee Cup", [("durability", "Durability Weak+")] = "Valuables/01 Tiny/Valuable Museum GoldFish", [("durability", "Durability Weak++")] = "Valuables/01 Tiny/Valuable Museum GoldTooth", [("durability", "Durability Weak+++")] = "Valuables/03 Medium/Valuable Desert Mineral case", [("phys", "PhysAttribute Heavy")] = "Valuables/04 Big/Valuable Arctic Barrel", [("phys", "PhysAttribute Heavy+")] = "Valuables/04 Big/Valuable Arctic Creature Leg", [("phys", "PhysAttribute Heavy++")] = "Valuables/04 Big/Valuable Manor Vase Chunky", [("phys", "PhysAttribute Light")] = "Valuables/01 Tiny/Valuable Arctic Phone", [("phys", "PhysAttribute Light+")] = "Valuables/01 Tiny/Valuable Arctic Coffee Cup", [("phys", "PhysAttribute Light++")] = "Valuables/01 Tiny/Valuable Arctic Eraser", [("phys", "PhysAttribute Medium")] = "Valuables/01 Tiny/Valuable Desert Golden Coin", [("phys", "PhysAttribute Medium+")] = "Valuables/02 Small/Valuable Manor Instrument", [("phys", "PhysAttribute Medium++")] = "Valuables/02 Small/Valuable Arctic HDD", [("phys", "PhysAttribute Medium+++")] = "Valuables/02 Small/Valuable Desert Rocking Chair", [("phys", "PhysAttribute Medium++++")] = "Valuables/03 Medium/Valuable Wizard Eye of Orpigox", [("phys", "PhysAttribute Very Heavy")] = "Valuables/05 Wide/Valuable Museum Horse", [("value", "Value Cheap")] = "Valuables/01 Tiny/Valuable Arctic Eraser", [("value", "Value Cheap+")] = "Valuables/01 Tiny/Valuable Desert Lighter", [("value", "Value Cheap++")] = "Valuables/01 Tiny/Valuable Arctic Phone", [("value", "Value Expensive")] = "Valuables/05 Wide/Valuable Arctic Centrifuge", [("value", "Value Expensive+")] = "Valuables/05 Wide/Valuable Manor Piano", [("value", "Value Expensive++")] = "Valuables/05 Wide/Valuable Wizard Dragon Skull", [("value", "Value High")] = "Valuables/03 Medium/Valuable Arctic 3D Printer", [("value", "Value High+")] = "Valuables/04 Big/Valuable Arctic Barrel", [("value", "Value Medium")] = "Valuables/01 Tiny/Valuable Arctic Coffee Cup", [("value", "Value Medium+")] = "Valuables/02 Small/Valuable Manor Music Box", [("value", "Value Medium++")] = "Valuables/02 Small/Valuable Desert Rocking Chair", [("value", "Value Very Cheap")] = "Valuables/01 Tiny/Valuable Arctic Keycard" }; } internal sealed class SpinWhenHeld : MonoBehaviour { public float DegreesPerSecond = 90f; private PhysGrabObject? _grabObject; private void Awake() { _grabObject = ((Component)this).GetComponentInParent<PhysGrabObject>(); } private void Update() { if ((Object)(object)_grabObject != (Object)null && _grabObject.grabbed) { ((Component)this).transform.Rotate(0f, DegreesPerSecond * Time.deltaTime, 0f, (Space)1); } } } internal sealed class TankCannon : MonoBehaviour { public static ItemCartCannon? Source; public Transform? Muzzle; public float Cooldown = 1.5f; public float Range = 60f; public float RecoilImpulse = 20f; public int EnemyDamage = 2000; public int PlayerDamage = 75; public float EnemyStunTime = 8f; public float EnemyHitForce = 70f; public float PhysHitForce = 80f; public float PlayerHitForce = 60f; public float BlastScale = 1.75f; public bool UseBatteryAsAmmo; private static readonly FieldInfo? LocalSeatField = typeof(ItemVehicle).GetField("localSeatIndex", BindingFlags.Instance | BindingFlags.NonPublic); private ItemVehicle? _vehicle; private PhotonView? _view; private PhysGrabObject? _grabObject; private ParticleScriptExplosion? _explosion; private ItemBattery? _battery; private float _cooldownTimer; private static readonly FieldInfo? VehicleBatteryField = typeof(ItemVehicle).GetField("itemBattery", BindingFlags.Instance | BindingFlags.NonPublic); private void Awake() { _vehicle = ((Component)this).GetComponent<ItemVehicle>(); _view = ((Component)this).GetComponent<PhotonView>(); _grabObject = ((Component)this).GetComponent<PhysGrabObject>(); _explosion = ((Component)this).GetComponent<ParticleScriptExplosion>(); _battery = ((Component)this).GetComponent<ItemBattery>(); } private IEnumerator Start() { yield return null; if (UseBatteryAsAmmo && (Object)(object)_vehicle != (Object)null && VehicleBatteryField != null) { VehicleBatteryField.SetValue(_vehicle, null); TankModPlugin.Logger.LogInfo((object)"Tank cannon: battery detached from the vehicle, used as ammo."); } } private bool HasAmmo() { if (UseBatteryAsAmmo && !((Object)(object)_battery == (Object)null)) { return _battery.batteryLifeInt > 0; } return true; } private void Update() { if (_cooldownTimer > 0f) { _cooldownTimer -= Time.deltaTime; } if ((Object)(object)_vehicle == (Object)null || (Object)(object)Muzzle == (Object)null) { return; } int num = ((LocalSeatField != null) ? ((int)LocalSeatField.GetValue(_vehicle)) : (-1)); if (num < 0 || _cooldownTimer > 0f || !SemiFunc.InputDown((InputKey)2) || !HasAmmo()) { return; } _cooldownTimer = Cooldown; if (SemiFunc.IsMasterClientOrSingleplayer()) { Shoot(); return; } PhotonView? view = _view; if (view != null) { view.RPC("TankFireRequestRPC", (RpcTarget)2, Array.Empty<object>()); } } [PunRPC] public void TankFireRequestRPC(PhotonMessageInfo info = default(PhotonMessageInfo)) { if (SemiFunc.IsMasterClientOrSingleplayer()) { Shoot(); } } private void Shoot() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0064: 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_006c: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: 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_00e2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Muzzle == (Object)null || (Object)(object)_view == (Object)null || !HasAmmo()) { return; } if (UseBatteryAsAmmo) { ItemBattery? battery = _battery; if (battery != null) { battery.RemoveFullBar(1); } } Vector3 position = Muzzle.position; Vector3 forward = Muzzle.forward; Vector3 val = position + forward * Range; bool flag = false; RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(position, forward, ref val2, Range, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) + LayerMask.GetMask(new string[1] { "Enemy" }))) { val = ((RaycastHit)(ref val2)).point; flag = true; } if ((Object)(object)_grabObject != (Object)null && (Object)(object)_grabObject.rb != (Object)null) { _grabObject.rb.AddForceAtPosition(-forward * RecoilImpulse, position, (ForceMode)1); } if (SemiFunc.IsMultiplayer()) { _view.RPC("TankShootRPC", (RpcTarget)0, new object[3] { val, true, flag }); } else { TankShootRPC(val, hit: true, flag); } } [PunRPC] public void TankShootRPC(Vector3 endPosition, bool hit, bool surfaceHit, PhotonMessageInfo info = default(PhotonMessageInfo)) { //IL_0000: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) if (!SemiFunc.MasterOnlyRPC(info)) { return; } if ((Object)(object)Source == (Object)null || (Object)(object)Source.bulletPrefab == (Object)null || (Object)(object)Muzzle == (Object)null) { TankModPlugin.Logger.LogWarning((object)"Tank cannon: no bullet prefab available."); return; } ItemGunBullet component = Object.Instantiate<GameObject>(Source.bulletPrefab, Muzzle.position, Muzzle.rotation).GetComponent<ItemGunBullet>(); component.hitPosition = endPosition; component.bulletHit = hit; SetField(component, "surfaceHit", surfaceHit); SetField(component, "surfaceImpactStrength", 0f); component.shootLineWidthCurve = Source.animationCurve; Source.soundHit.Play(endPosition, 1f, 1f, 1f, 1f); Source.shootSound.Play(Muzzle.position, 1f, 1f, 1f, 1f); GameDirector.instance.CameraShake.ShakeDistance(6f, 3f, 12f, Muzzle.position, 0.15f); GameDirector.instance.CameraImpact.ShakeDistance(10f, 3f, 12f, Muzzle.position, 0.08f); ParticleScriptExplosion? explosion = _explosion; if (explosion != null) { explosion.PlayExplosionSoundMedium(endPosition); } HurtCollider componentInChildren = ((Component)component).GetComponentInChildren<HurtCollider>(true); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.enemyDamage = EnemyDamage; componentInChildren.playerDamage = PlayerDamage; componentInChildren.enemyStunTime = EnemyStunTime; componentInChildren.enemyHitForce = EnemyHitForce; componentInChildren.physHitForce = PhysHitForce; componentInChildren.playerHitForce = PlayerHitForce; Transform transform = ((Component)componentInChildren).transform; transform.localScale *= BlastScale; } PlayerAvatar val = (((Object)(object)_vehicle != (Object)null && _vehicle.seats.Length != 0) ? _vehicle.seats[0].seatedPlayer : null); if ((Object)(object)componentInChildren != (Object)null && (Object)(object)val != (Object)null) { componentInChildren.playerCausingHurt = val; componentInChildren.playerHitFullRuckus = true; } component.ActivateAll(); } private static void SetField(object target, string name, object value) { target.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.SetValue(target, value); } } internal static class ValuableBuilder { internal enum Result { Registered, Failed, TemplateMissing } private static readonly Regex DataMapPattern = new Regex("normal|bump|metal|occlusion|emission|emissive|detail|mask|height|parallax|spec|rough|gloss|\\bao\\b|_ao", RegexOptions.IgnoreCase); private static GameObject? _holder; private static readonly Dictionary<string, Dictionary<string, Mesh>> MeshCache = new Dictionary<string, Dictionary<string, Mesh>>(); private static readonly Dictionary<string, Texture2D> TextureCache = new Dictionary<string, Texture2D>(); private static bool _shaderLogged; private static bool _shineLogged; private static Shader? _standardShader; private static bool _standardChecked; private static Texture2D? _flatNormal; private static readonly Dictionary<Color, Texture2D> SolidCache = new Dictionary<Color, Texture2D>(); private static readonly PropertyInfo? SharedMaterialProperty = typeof(Collider).GetProperty("sharedMaterial"); internal static Transform Holder { get { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)_holder == (Object)null) { _holder = new GameObject("TankMod Prefabs"); _holder.SetActive(false); Object.DontDestroyOnLoad((Object)(object)_holder); } return _holder.transform; } } private static Shader? StandardShader { get { if (!_standardChecked) { _standardChecked = true; _standardShader = Shader.Find("Standard"); TankModPlugin.Logger.LogInfo((object)(((Object)(object)_standardShader != (Object)null) ? "Using the Standard shader for non-shiny valuables." : "Standard shader not available, non-shiny valuables fall back to the template's ShinyMetal.")); } return _standardShader; } } private static Texture2D FlatNormalTexture { get { //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_0027: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_flatNormal == (Object)null) { _flatNormal = new Texture2D(4, 4, (TextureFormat)4, false, true) { name = "flat normal" }; _flatNormal.SetPixels(Enumerable.Repeat<Color>(new Color(0.5f, 0.5f, 1f, 1f), 16).ToArray()); _flatNormal.Apply(false, true); } return _flatNormal; } } public static Result Register(ValuableSpec spec, int attempt) { try { GameObject val = FindTemplate(spec, attempt); if ((Object)(object)val == (Object)null) { return Result.TemplateMissing; } GameObject val2 = Build(spec, val); Valuables.RegisterValuable(val2, spec.LevelPresets.ToList()); TankModPlugin.Logger.LogInfo((object)$"Registered valuable '{spec.Name}' (template '{((Object)val).name}', attempt {attempt})."); return Result.Registered; } catch (Exception arg) { TankModPlugin.Logger.LogError((object)$"Failed to register valuable '{spec.Name}': {arg}"); return Result.Failed; } } private static GameObject? FindTemplate(ValuableSpec spec, int attempt) { GameObject val = Resources.Load<GameObject>(spec.Template); if ((Object)(object)val != (Object)null) { return val; } string[] array = new string[3] { "Valuables/01 Tiny", "Valuables/02 Small", "Valuables" }; foreach (string text in array) { GameObject val2 = ((IEnumerable<GameObject>)Resources.LoadAll<GameObject>(text)).FirstOrDefault((Func<GameObject, bool>)IsPlainValuable); if ((Object)(object)val2 != (Object)null) { return val2; } } GameObject val3 = (from v in Resources.FindObjectsOfTypeAll<ValuableObject>().Where(delegate(ValuableObject v) { //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) Scene scene = ((Component)v).gameObject.scene; return !((Scene)(ref scene)).IsValid(); }) select ((Component)v).gameObject).FirstOrDefault(); if ((Object)(object)val3 != (Object)null) { return val3; } if (attempt == 0 || attempt % 120 == 0) { TankModPlugin.Logger.LogWarning((object)($"No valuable template yet (attempt {attempt}): '{spec.Template}' not found; " + string.Format("LoadAll('Valuables')={0}, ", Resources.LoadAll<GameObject>("Valuables").Length) + $"loaded ValuableObjects={Resources.FindObjectsOfTypeAll<ValuableObject>().Length}.")); } return null; } private static bool IsPlainValuable(GameObject go) { if ((Object)(object)go.GetComponent<ValuableObject>() != (Object)null) { return (Object)(object)go.GetComponent<Rigidbody>() != (Object)null; } return false; } private static GameObject Build(ValuableSpec spec, GameObject template) { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(template, Holder); ((Object)val).name = spec.Name; Renderer componentInChildren = template.GetComponentInChildren<Renderer>(true); Material baseMaterial = ((componentInChildren != null) ? componentInChildren.sharedMaterial : null); object physicsMaterial = GetPhysicsMaterial(template.GetComponentInChildren<Collider>(true)); foreach (Transform item in ((IEnumerable)val.transform).Cast<Transform>().ToList()) { Object.DestroyImmediate((Object)(object)((Component)item).gameObject); } Transform transform = new GameObject("Object").transform; transform.SetParent(val.transform, false); transform.localPosition = spec.ObjectPosition; transform.localRotation = Quaternion.Euler(spec.ObjectEuler); BuildVisuals(spec, transform, baseMaterial); BuildColliders(spec, transform, physicsMaterial); ApplyValuableSettings(spec, val); return val; } private static void BuildVisuals(ValuableSpec spec, Transform objectNode, Material? baseMaterial) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Expected O, but got Unknown bool merged = spec.Parts.Any((MeshPartSpec p) => p.Part == "*"); Dictionary<string, Mesh> dictionary = LoadMeshes(spec.Folder + "/" + spec.ObjFile, merged); Transform transform = new GameObject(spec.Name.ToLowerInvariant()).transform; transform.SetParent(objectNode, false); transform.localPosition = spec.VisualPosition; transform.localRotation = Quaternion.Euler(spec.VisualRotationEuler); transform.localScale = spec.VisualScale; if (spec.SpinWhenHeldSpeed != 0f) { ((Component)transform).gameObject.AddComponent<SpinWhenHeld>().DegreesPerSecond = spec.SpinWhenHeldSpeed; } MeshPartSpec[] parts = spec.Parts; foreach (MeshPartSpec meshPartSpec in parts) { if (!dictionary.TryGetValue(meshPartSpec.Part, out var value)) { throw new KeyNotFoundException("OBJ '" + spec.ObjFile + "' has no part '" + meshPartSpec.Part + "'. Parts: " + string.Join(", ", dictionary.Keys)); } ManualLogSource logger = TankModPlugin.Logger; object[] obj = new object[6] { spec.Name, meshPartSpec.Part, value.vertexCount, value.triangles.Length / 3, value.uv.Length != 0, null }; Bounds bounds = value.bounds; obj[5] = ((Bounds)(ref bounds)).size; logger.LogInfo((object)string.Format("{0}/{1}: {2} vertices, {3} triangles, uv={4}, size={5}", obj)); GameObject val = new GameObject(meshPartSpec.Part); val.transform.SetParent(transform, false); val.AddComponent<MeshFilter>().sharedMesh = value; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = CreateMaterial(baseMaterial, meshPartSpec, spec.Folder, spec.Shiny); } } internal static Dictionary<string, Mesh> LoadMeshes(string path, bool merged) { string key = $"{path}|{merged}"; if (!MeshCache.TryGetValue(key, out Dictionary<string, Mesh> value)) { value = (MeshCache[key] = ObjLoader.Load(EmbeddedAssets.ReadText(path), merged)); } return value; } private static Texture2D LoadTexture(string path) { if (!TextureCache.TryGetValue(path, out Texture2D value)) { value = (TextureCache[path] = EmbeddedAssets.LoadTexture(path)); } return value; } private unsafe static Material CreateStandardMaterial(Shader shader, MeshPartSpec part, string folder) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: 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) Material val = new Material(shader) { name = part.Part }; if (string.IsNullOrEmpty(part.Texture)) { val.color = part.Color; } else { val.color = Color.white; val.mainTexture = (Texture)(object)LoadTexture(folder + "/" + part.Texture); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0f); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", 0.1f); } if (val.HasProperty("_GlossMapScale")) { val.SetFloat("_GlossMapScale", 0.1f); } ManualLogSource logger = TankModPlugin.Logger; string part2 = part.Part; string text; if (!string.IsNullOrEmpty(part.Texture)) { text = "texture " + part.Texture; } else { Color color = part.Color; text = "colour " + ((object)(*(Color*)(&color))/*cast due to .constrained prefix*/).ToString(); } logger.LogInfo((object)("Material '" + part2 + "': Standard, " + text)); return val; } internal unsafe static Material CreateMaterial(Material? baseMaterial, MeshPartSpec part, string folder, bool shiny) { //IL_0036: 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_003c: Expected O, but got Unknown //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Invalid comparison between Unknown and I4 //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Invalid comparison between Unknown and I4 //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_03c8: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) if (!shiny) { Shader standardShader = StandardShader; if (standardShader != null) { return CreateStandardMaterial(standardShader, part, folder); } } Material val = (((Object)(object)baseMaterial != (Object)null) ? new Material(baseMaterial) : new Material(Shader.Find("Standard"))); ((Object)val).name = part.Part; Shader shader = val.shader; if (!_shaderLogged) { _shaderLogged = true; IEnumerable<string> values = from i in Enumerable.Range(0, shader.GetPropertyCount()) select $"{shader.GetPropertyName(i)}:{shader.GetPropertyType(i)}"; TankModPlugin.Logger.LogInfo((object)("Template shader '" + ((Object)shader).name + "' properties: " + string.Join(", ", values))); } if (_shaderLogged && !_shineLogged && val.HasProperty("_ShineColor")) { _shineLogged = true; TankModPlugin.Logger.LogInfo((object)string.Format("Template shine: _ShineColor={0}, _Shine_Remap={1}, _T_Remap={2}", val.GetColor("_ShineColor"), val.GetVector("_Shine_Remap"), val.GetVector("_T_Remap"))); } string text = null; List<string> list = new List<string>(); for (int num = 0; num < shader.GetPropertyCount(); num++) { if ((int)shader.GetPropertyType(num) != 4 || (int)shader.GetPropertyTextureDimension(num) != 2) { continue; } string propertyName = shader.GetPropertyName(num); if (!(propertyName == "_texcoord")) { if (DataMapPattern.IsMatch(propertyName)) { val.SetTexture(propertyName, (Texture)(object)((propertyName.IndexOf("normal", StringComparison.OrdinalIgnoreCase) >= 0) ? FlatNormalTexture : null)); } else { list.Add(propertyName); } } } string[] array = new string[4] { "_Texture", "_MainTex", "_BaseMap", "_Albedo" }; foreach (string text2 in array) { if (list.Contains(text2)) { text = text2; break; } } if (text == null) { text = list.FirstOrDefault(); } string[] array2 = new string[6] { "_NORMALMAP", "_METALLICGLOSSMAP", "_SPECGLOSSMAP", "_PARALLAXMAP", "_EMISSION", "_DETAIL_MULX2" }; foreach (string text3 in array2) { val.DisableKeyword(text3); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0f); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", 0.3f); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", 0.3f); } if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", Color.black); } Texture2D val2 = (string.IsNullOrEmpty(part.Texture) ? SolidTexture(part.Color) : LoadTexture(folder + "/" + part.Texture)); if (text != null) { val.SetTexture(text, (Texture)(object)val2); } if (!shiny) { if (val.HasProperty("_ShineColor")) { val.SetColor("_ShineColor", Color.black); } if (val.HasProperty("_Reflection")) { val.SetTexture("_Reflection", (Texture)null); } } if (val.HasProperty("_Color")) { val.SetColor("_Color", Color.white); } if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", Color.white); } ManualLogSource logger = TankModPlugin.Logger; object[] obj = new object[5] { part.Part, null, null, null, null }; string text4; if (!string.IsNullOrEmpty(part.Texture)) { text4 = part.Texture; } else { Color color = part.Color; text4 = "solid " + ((object)(*(Color*)(&color))/*cast due to .constrained prefix*/).ToString(); } obj[1] = text4; obj[2] = text; obj[3] = ((Texture)val2).width; obj[4] = ((Texture)val2).height; logger.LogInfo((object)string.Format("Material '{0}': albedo '{1}' -> slot '{2}' ({3}x{4})", obj)); return val; } private static Texture2D SolidTexture(Color color) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0039: 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) if (SolidCache.TryGetValue(color, out Texture2D value)) { return value; } Texture2D val = new Texture2D(4, 4, (TextureFormat)4, false) { name = $"solid {color}", filterMode = (FilterMode)0 }; val.SetPixels(Enumerable.Repeat<Color>(color, 16).ToArray()); val.Apply(false, true); return SolidCache[color] = val; } internal static object? GetPhysicsMaterial(Collider? collider) { if (!((Object)(object)collider == (Object)null)) { return SharedMaterialProperty?.GetValue(collider); } return null; } private static void SetPhysicsMaterial(Collider collider, object? material) { if (material != null) { SharedMaterialProperty?.SetValue(collider, material); } } private static void BuildColliders(ValuableSpec spec, Transform objectNode, object? physicsMaterial) { BuildColliders(spec.Colliders, objectNode, physicsMaterial); } internal static void BuildColliders(ColliderSpec[] colliders, Transform objectNode, object? physicsMaterial) { //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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_0059: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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) int num = LayerMask.NameToLayer("PhysGrabObject"); for (int i = 0; i < colliders.Length; i++) { ColliderSpec colliderSpec = colliders[i]; GameObject val = new GameObject($"Valuable Collider ({i})") { layer = ((num != -1) ? num : 0), tag = "Phys Grab Object" }; val.transform.SetParent(objectNode, false); val.transform.localPosition = colliderSpec.Position; val.transform.localRotation = Quaternion.Euler(colliderSpec.Euler); val.transform.localScale = colliderSpec.Scale; Collider collider; if (colliderSpec.Kind == ColliderKind.Box) { BoxCollider val2 = val.AddComponent<BoxCollider>(); val2.size = colliderSpec.Size; val2.center = colliderSpec.Center; collider = (Collider)(object)val2; val.AddComponent<PhysGrabObjectBoxCollider>(); } else { CapsuleCollider val3 = val.AddComponent<CapsuleCollider>(); val3.radius = colliderSpec.Radius; val3.height = colliderSpec.Height; val3.direction = colliderSpec.Direction; val3.center = colliderSpec.Center; collider = (Collider)(object)val3; val.AddComponent<PhysGrabObjectCapsuleCollider>(); } SetPhysicsMaterial(collider, physicsMaterial); val.AddComponent<PhysGrabObjectCollider>().colliderID = colliderSpec.ColliderId; } } private static void ApplyValuableSettings(ValuableSpec spec, GameObject root) { //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) ValuableObject component = root.GetComponent<ValuableObject>(); if ((Object)(object)component == (Object)null) { throw new InvalidOperationException("Template has no ValuableObject."); } component.durabilityPreset = ValuableBuilder.Preset<Durability>("durability", spec.DurabilityPreset, component.durabilityPreset); component.physAttributePreset = ValuableBuilder.Preset<PhysAttribute>("phys", spec.PhysAttributePreset, component.physAttributePreset); component.audioPreset = ValuableBuilder.Preset<PhysAudio>("audio", spec.PhysAudioPreset, component.audioPreset); if (!string.IsNullOrEmpty(spec.ImpactAudioPath)) { PhysAudio audioPreset = component.audioPreset; if ((Object)(object)audioPreset == (Object)null) { throw new InvalidOperationException("No original PhysAudio preset available."); } AudioClip clip = EmbeddedAssets.LoadWavPcm16(spec.ImpactAudioPath); component.audioPreset = CreateImpactAudioPreset(audioPreset, spec.Name, clip); TankModPlugin.Logger.LogInfo((object)("Loaded custom impact audio for '" + spec.Name + "': " + spec.ImpactAudioPath)); } if (spec.ValueMin >= 0f) { Value val = ScriptableObject.CreateInstance<Value>(); ((Object)val).name = spec.Name + " value"; val.valueMin = spec.ValueMin; val.valueMax = ((spec.ValueMax >= spec.ValueMin) ? spec.ValueMax : spec.ValueMin); ((Object)val).hideFlags = (HideFlags)32; component.valuePreset = val; } else { component.valuePreset = ValuableBuilder.Preset<Value>("value", spec.ValuePreset, component.valuePreset); } component.audioPresetPitch = spec.AudioPitch; component.volumeType = spec.Volume; if (spec.ParticleColors != null) { component.particleColors = spec.ParticleColors; } } private static PhysAudio CreateImpactAudioPreset(PhysAudio original, string name, AudioClip clip) { PhysAudio val = ScriptableObject.CreateInstance<PhysAudio>(); ((Object)val).name = name + " custom audio"; ((Object)val).hideFlags = (HideFlags)32; val.impactLight = CloneCustomSound(original.impactLight, clip); val.impactMedium = CloneCustomSound(original.impactMedium, clip); val.impactHeavy = CloneCustomSound(original.impactHeavy, clip); val.breakLight = CloneCustomSound(original.breakLight, clip); val.breakMedium = CloneCustomSound(original.breakMedium, clip); val.breakHeavy = CloneCustomSound(original.breakHeavy, clip); val.destroy = CloneCustomSound(original.destroy, clip); return val; } private static Sound CloneCustomSound(Sound original, AudioClip clip) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) Sound val = CloneSound(original); val.Sounds = (AudioClip[])(object)new AudioClip[1] { clip }; val.Type = (AudioType)3; val.Volume = 1f; val.VolumeRandom = 0f; return val; } private static Sound CloneSound(Sound original) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown Sound val = new Sound(); Sound.CopySound(original, val); return val; } internal static T Preset<T>(string kind, string name, T fallback) where T : Object { if (!string.IsNullOrEmpty(name)) { T val = PresetLibrary.Find<T>(kind, name); if ((Object)(object)val != (Object)null) { return val; } TankModPlugin.Logger.LogWarning((object)(typeof(T).Name + " preset '" + name + "' not found, using the template's.")); } return fallback; } } internal enum ColliderKind { Box, Capsule } internal sealed class ColliderSpec { public ColliderKind Kind; public Vector3 Position; public Vector3 Scale = Vector3.one; public Vector3 Euler = Vector3.zero; public int ColliderId; public Vector3 Size = Vector3.one; public Vector3 Center; public float Radius = 0.5f; public float Height = 2f; public int Direction = 1; } internal sealed class MeshPartSpec { public string Part = "*"; public string Texture = ""; public Color Color = Color.white; } internal sealed class ValuableSpec { public string Name = ""; public string Template = "Valuables/01 Tiny/Valuable Diamond"; public string Folder = ""; public string ObjFile = ""; public MeshPartSpec[] Parts = Array.Empty<MeshPartSpec>(); public ColliderSpec[] Colliders = Array.Empty<ColliderSpec>(); public Vector3 ObjectPosition; public Vector3 ObjectEuler; public Vector3 VisualPosition; public Vector3 VisualRotationEuler = Vector3.zero; public Vector3 VisualScale = Vector3.one; public float SpinWhenHeldSpeed; public Type Volume = (Type)1; public string DurabilityPreset = "Durability Default"; public string ValuePreset = ""; public float ValueMin = -1f; public float ValueMax = -1f; public string PhysAttributePreset = ""; public string PhysAudioPreset = ""; public string ImpactAudioPath = ""; public float AudioPitch = 1f; public bool Shiny; public Gradient? ParticleColors; public string[] LevelPresets = new string[1] { "Valuables - Generic" }; } internal static class Gradients { public static Gradient Make(GradientMode mode, params (float r, float g, float b, float t)[] keys) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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) Gradient val = new Gradient(); val.colorKeys = ((IEnumerable<(float, float, float, float)>)keys).Select((Func<(float, float, float, float), GradientColorKey>)(((float r, float g, float b, float t) k) => new GradientColorKey(new Color(k.r, k.g, k.b), k.t))).ToArray(); val.alphaKeys = (GradientAlphaKey[])(object)new GradientAlphaKey[2] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }; val.mode = mode; return val; } } internal static class VehicleBuilder { public static GameObject Build(VehicleSpec spec, GameObject template) { //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_032d: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Expected O, but got Unknown //IL_041f: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_0429: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Unknown result type (might be due to invalid IL or missing references) //IL_03b5: Unknown result type (might be due to invalid IL or missing references) //IL_03ba: Unknown result type (might be due to invalid IL or missing references) //IL_0449: 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_0456: Unknown result type (might be due to invalid IL or missing references) //IL_0458: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(template, ValuableBuilder.Holder); ((Object)val).name = spec.Name; ItemVehicle component = val.GetComponent<ItemVehicle>(); if ((Object)(object)component == (Object)null) { throw new InvalidOperationException("Template '" + ((Object)template).name + "' has no ItemVehicle."); } Renderer componentInChildren = template.GetComponentInChildren<Renderer>(true); Material baseMaterial = ((componentInChildren != null) ? componentInChildren.sharedMaterial : null); HashSet<Renderer> hashSet = new HashSet<Renderer>(); Renderer[] array = (Renderer[])(object)new Renderer[4] { (Renderer)component.grabMesh, component.hoverEffectRenderer, component.hoverEffectFrontRenderer, component.hoverEffectBackRenderer }; foreach (Renderer val2 in array) { if ((Object)(object)val2 != (Object)null) { hashSet.Add(val2); } } VehicleSeat[] array2 = component.seats ?? Array.Empty<VehicleSeat>(); foreach (VehicleSeat val3 in array2) { if ((Object)(object)val3.grabPointVisual != (Object)null) { Renderer[] componentsInChildren = ((Component)val3.grabPointVisual).GetComponentsInChildren<Renderer>(true); foreach (Renderer item in componentsInChildren) { hashSet.Add(item); } } } Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(true); foreach (Renderer val4 in componentsInChildren2) { if (val4 is MeshRenderer || val4 is SkinnedMeshRenderer) { string text = ((Object)((Component)val4).gameObject).name.ToLowerInvariant(); if (hashSet.Contains(val4) || text.Contains("grab") || text.Contains("handle")) { TankModPlugin.Logger.LogInfo((object)(spec.Name + ": keeping scooter renderer '" + ((Object)((Component)val4).gameObject).name + "'.")); } else { val4.enabled = false; } } } Transform val5 = (((Object)(object)component.meshTransform != (Object)null) ? component.meshTransform : val.transform); Transform transform = new GameObject(spec.Name + " Model").transform; transform.SetParent(val5, false); transform.localPosition = spec.VisualPosition; transform.localRotation = Quaternion.Euler(spec.VisualEuler); transform.localScale = spec.VisualScale; Dictionary<string, Mesh> dictionary = ValuableBuilder.LoadMeshes(spec.Folder + "/" + spec.ObjFile, merged: false); MeshPartSpec[] parts = spec.Parts; foreach (MeshPartSpec meshPartSpec in parts) { if (!dictionary.TryGetValue(meshPartSpec.Part, out var value)) { throw new KeyNotFoundException("OBJ '" + spec.ObjFile + "' has no part '" + meshPartSpec.Part + "'. Parts: " + string.Join(", ", dictionary.Keys)); } ManualLogSource logger = TankModPlugin.Logger; object[] obj = new object[4] { spec.Name, meshPartSpec.Part, value.vertexCount, null }; Bounds bounds = value.bounds; obj[3] = ((Bounds)(ref bounds)).size; logger.LogInfo((object)string.Format("{0}/{1}: {2} vertices, size={3}", obj)); GameObject val6 = new GameObject(meshPartSpec.Part); val6.transform.SetParent(transform, false); val6.AddComponent<MeshFilter>().sharedMesh = value; ((Renderer)val6.AddComponent<MeshRenderer>()).sharedMaterial = ValuableBuilder.CreateMaterial(baseMaterial, meshPartSpec, spec.Folder, shiny: false); } if (component.seats != null && component.seats.Length != 0) { VehicleSeat val7 = component.seats[0]; if ((Object)(object)val7.seatTransform != (Object)null) { Transform seatTransform = val7.seatTransform; seatTransform.localPosition += spec.SeatOffset; } if ((Object)(object)val7.firstMountTransform != (Object)null) { Transform firstMountTransform = val7.firstMountTransform; firstMountTransform.localPosition += spec.SeatOffset; } } else { TankModPlugin.Logger.LogWarning((object)(spec.Name + ": template vehicle has no seats.")); } Vector3? muzzlePosition = spec.MuzzlePosition; if (muzzlePosition.HasValue) { Vector3 valueOrDefault = muzzlePosition.GetValueOrDefault(); AddCannon(val, transform, valueOrDefault, spec.AmmoBars); } muzzlePosition = spec.GrabButtonPosition; if (muzzlePosition.HasValue) { Vector3 valueOrDefault2 = muzzlePosition.GetValueOrDefault(); val.AddComponent<GrabButtonPlacer>().Target = valueOrDefault2; } StretchColliders(spec, val, component); if (spec.Colliders.Length != 0) { ReplaceBoxColliders(spec, val, component, template); } Tune(spec, component); if (!string.IsNullOrEmpty(spec.PhysAttributePreset)) { NotValuableObject component2 = val.GetComponent<NotValuableObject>(); if (component2 != null) { component2.physAttributePreset = ValuableBuilder.Preset<PhysAttribute>("phys", spec.PhysAttributePreset, component2.physAttributePreset); } } if (spec.IdleBrake) { val.AddComponent<IdleBrake>(); } ItemBuilder.ApplyItem(spec, val); try { val.GetComponent<ItemAttributes>().icon = ItemBuilder.LoadIcon(spec.Folder); } catch (Exception ex) { TankModPlugin.Logger.LogWarning((object)("Could not load an icon for '" + spec.Name + "': " + ex.Message)); } return val; } private static void StretchColliders(VehicleSpec spec, GameObject root, ItemVehicle vehicle) { //IL_00dc: 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) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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_0146: 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_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) HashSet<Collider> hashSet = new HashSet<Collider>(from c in root.GetComponentsInChildren<PhysGrabObjectCollider>(true) select ((Component)c).GetComponent<Collider>() into c where (Object)(object)c != (Object)null select c); if (vehicle.vehicleColliders != null) { Collider[] vehicleColliders = vehicle.vehicleColliders; foreach (Collider val in vehicleColliders) { if ((Object)(object)val != (Object)null) { hashSet.Add(val); } } } foreach (Collider item in hashSet) { Transform transform = ((Component)item).transform; TankModPlugin.Logger.LogInfo((object)$"{spec.Name}: collider '{((Object)transform).name}' {((object)item).GetType().Name} pos={transform.localPosition} scale={transform.localScale} rot={transform.localEulerAngles} trigger={item.isTrigger}"); if (!item.isTrigger && !(spec.ColliderScale == Vector3.one)) { Matrix4x4 val2 = Matrix4x4.Rotate(transform.localRotation); Vector3 localScale = transform.localScale; for (int num2 = 0; num2 < 3; num2++) { Vector3 val3 = Vector4.op_Implicit(((Matrix4x4)(ref val2)).GetColumn(num2)); Vector3 val4 = new Vector3(val3.x * spec.ColliderScale.x, val3.y * spec.ColliderScale.y, val3.z * spec.ColliderScale.z); float magnitude = ((Vector3)(ref val4)).magnitude; int num3 = num2; ((Vector3)(ref localScale))[num3] = ((Vector3)(ref localScale))[num3] * magnitude; } transform.localPosition = Vector3.Scale(transform.localPosition, spec.ColliderScale); transform.localScale = localScale; } } Transform[] array = (Transform[])(object)new Transform[6] { vehicle.frontGroundedTransform, vehicle.backGroundedTransform, vehicle.wheelFront, vehicle.wheelBack, vehicle.wheelFrontForcePoint, vehicle.wheelBackForcePoint }; foreach (Transform val5 in array) { if (!((Object)(object)val5 == (Object)null)) { ManualLogSource logger = TankModPlugin.Logger; object[] obj = new object[4] { spec.Name, ((Object)val5).name, null, null }; Transform parent = val5.parent; obj[2] = ((parent != null) ? ((Object)parent).name : null); obj[3] = val5.localPosition; logger.LogInfo((object)string.Format("{0}: wheel/ground point '{1}' parent='{2}' pos={3}", obj)); if ((Object)(object)val5.parent == (Object)(object)root.transform || (Object)(object)val5.parent == (Object)(object)vehicle.meshTransform) { val5.localPosition = Vector3.Scale(val5.localPosition, spec.ColliderScale); } } } } private static void Tune(VehicleSpec spec, ItemVehicle vehicle) { if (spec.LiftForce >= 0f) { vehicle.liftForce = spec.LiftForce; } if (spec.ForwardLiftMultiplier >= 0f) { vehicle.forwardLiftMultiplier = spec.ForwardLiftMultiplier; } if (spec.MaxForwardLift >= 0f) { vehicle.maxForwardLift = spec.MaxForwardLift; } if (spec.HyperMaxSpeed >= 0f) { vehicle.hyperMaxSpeed = spec.HyperMaxSpeed; } if (spec.MaxForwardSpeed >= 0f) { vehicle.maxForwardSpeed = spec.MaxForwardSpeed; } vehicle.hasDrifting = spec.HasDrifting; vehicle.enableRampBoost = spec.EnableRampBoost; vehicle.enableWheelPhysics = spec.WheelLiftPhysics; } private static void AddCannon(GameObject root, Transform visual, Vector3 muzzlePosition, int ammoBars) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) GameObject obj = Resources.Load<GameObject>("Items/Item Cart Cannon"); ItemCartCannon val = ((obj != null) ? obj.GetComponent<ItemCartCannon>() : null); if ((Object)(object)val == (Object)null) { TankModPlugin.Logger.LogWarning((object)"Tank cannon: 'Items/Item Cart Cannon' not found, the tank will not be able to shoot."); return; } TankCannon.Source = val; Transform transform = new GameObject("Muzzle").transform; transform.SetParent(visual, false); transform.localPosition = muzzlePosition; transform.localRotation = Quaternion.identity; TankCannon tankCannon = root.AddComponent<TankCannon>(); tankCannon.Muzzle = transform; if (ammoBars > 0) { ItemBattery component = root.GetComponent<ItemBattery>(); if (component != null) { component.batteryBars = ammoBars; tankCannon.UseBatteryAsAmmo = true; } } } private static void ReplaceBoxColliders(VehicleSpec spec, GameObject root, ItemVehicle vehicle, GameObject template) { object physicsMaterial = ValuableBuilder.GetPhysicsMaterial(template.GetComponentInChildren<Collider>(true)); int num = 0; foreach (PhysGrabObjectCollider item in root.GetComponentsInChildren<PhysGrabObjectCollider>(true).ToList()) { if (!((Object)(object)item == (Object)null)) { BoxCollider component = ((Component)item).GetComponent<BoxCollider>(); if (component != null && !((Collider)component).isTrigger) { Object.DestroyImmediate((Object)(object)((Component)item).gameObject); num++; } } } HashSet<Collider> before = new HashSet<Collider>(root.GetComponentsInChildren<Collider>(true)); ValuableBuilder.BuildColliders(spec.Colliders, root.transform, physicsMaterial); List<Collider> list = (from c in root.GetComponentsInChildren<Collider>(true) where !before.Contains(c) select c).ToList(); IEnumerable<Collider> first = (vehicle.vehicleColliders ?? Array.Empty<Collider>()).Where((Collider c) => (Object)(object)c != (Object)null); vehicle.vehicleColliders = first.Concat(list).ToArray(); TankModPlugin.Logger.LogInfo((object)$"{spec.Name}: replaced {num} box colliders with {list.Count} fitted ones."); } } internal sealed class VehicleSpec : ItemSpec { public MeshPartSpec[] Parts = Array.Empty<MeshPartSpec>(); public Vector3 VisualPosition; public Vector3 VisualEuler; public Vector3 VisualScale = Vector3.one; public Vector3 SeatOffset; public int AmmoBars; public Vector3? MuzzlePosition; public Vector3? GrabButtonPosition; public Vector3 ColliderScale = Vector3.one; public float LiftForce = -1f; public float ForwardLiftMultiplier = -1f; public float MaxForwardLift = -1f; public float HyperMaxSpeed = -1f; public float MaxForwardSpeed = -1f; public bool HasDrifting = true; public bool EnableRampBoost = true; public bool WheelLiftPhysics = true; public string PhysAttributePreset = ""; public bool IdleBrake; } } namespace TankMod.Items { internal static class Tank { private const float Scale = 0.35f; private const float GroundOffset = -0.22f; private const float HullCentreBehind = 1.085f; public static ItemSpec Spec { get { //IL_00d3: 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_00e2: 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) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: 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_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) VehicleSpec vehicleSpec = new VehicleSpec(); vehicleSpec.Name = "Tank"; vehicleSpec.ItemName = "Tank"; vehicleSpec.Description = "A tank."; vehicleSpec.Template = "Items/Item Vehicle Semiscooter"; vehicleSpec.KeepTemplateShopSettings = true; vehicleSpec.ValueMin = 48000f; vehicleSpec.ValueMax = 52000f; vehicleSpec.AmmoBars = 7; vehicleSpec.Folder = "tank"; vehicleSpec.ObjFile = "tank.obj"; vehicleSpec.Parts = new MeshPartSpec[3] { new MeshPartSpec { Part = "body", Texture = "body.jpeg" }, new MeshPartSpec { Part = "metal1", Texture = "metal1.jpeg" }, new MeshPartSpec { Part = "wheel1", Texture = "wheel1.jpeg" } }; vehicleSpec.VisualScale = Vector3.one * 0.35f; vehicleSpec.VisualPosition = new Vector3(0f, -0.22f, 0.37975f); vehicleSpec.ColliderScale = new Vector3(1f, 1f, 0.89599997f); vehicleSpec.LiftForce = 0f; vehicleSpec.ForwardLiftMultiplier = 0f; vehicleSpec.MaxForwardLift = 0f; vehicleSpec.HyperMaxSpeed = 0f; vehicleSpec.HasDrifting = false; vehicleSpec.EnableRampBoost = false; vehicleSpec.WheelLiftPhysics = false; vehicleSpec.PhysAttributePreset = "PhysAttribute Heavy++"; vehicleSpec.IdleBrake = true; vehicleSpec.Colliders = new ColliderSpec[3] { new ColliderSpec { Kind = ColliderKind.Box, Position = ToVehicle(0f, 0.66f, -1.085f), Size = Size(2.98f, 0.97f, 5.8f) }, new ColliderSpec { Kind = ColliderKind.Box, Position = ToVehicle(0f, 1.825f, -0.515f), Size = Size(2.4f, 1.35f, 3.96f) }, new ColliderSpec { Kind = ColliderKind.Box, Position = new Vector3(0f, 0.27f, -0.76f), Size = new Vector3(0.9f, 0.19f, 0.52f) } }; vehicleSpec.MuzzlePosition = new Vector3(-0.052f, 1.891f, 4.1f); vehicleSpec.SeatOffset = new Vector3(0f, 0.27599996f, -0.02f); vehicleSpec.GrabButtonPosition = new Vector3(0f, 0.39f, -0.64f); return vehicleSpec; } } private static Vector3 ToVehicle(float x, float y, float z) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) return new Vector3(x * 0.35f, y * 0.35f + -0.22f, z * 0.35f + 0.37975f); } private static Vector3 Size(float x, float y, float z) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) return new Vector3(x * 0.35f, y * 0.35f, z * 0.35f); } } }