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 BearHoney v1.0.3
BepInEx/plugins/BearHoney/BearHoney.dll
Decompiled 14 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using R2API; using RoR2; using RoR2.Audio; using RoR2.UI.LogBook; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("BearHoney")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.3.0")] [assembly: AssemblyInformationalVersion("1.0.3")] [assembly: AssemblyProduct("BearHoney")] [assembly: AssemblyTitle("BearHoney")] [assembly: AssemblyVersion("1.0.3.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BearHoney { internal static class HoneyBottleModel { internal sealed class MeshData { public readonly List<Vector3> Vertices = new List<Vector3>(); public readonly List<Vector2> Uvs = new List<Vector2>(); public readonly List<int> Triangles = new List<int>(); private int AddVertex(Vector3 position, Vector2 uv) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) Vertices.Add(position); Uvs.Add(uv); return Vertices.Count - 1; } private void AddTriangle(int a, int b, int c) { Triangles.Add(a); Triangles.Add(b); Triangles.Add(c); } public static MeshData Lathe(Vector2[] profile, int segments, float uRepeat) { //IL_0058: 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) MeshData meshData = new MeshData(); int num = profile.Length; for (int i = 0; i < num; i++) { for (int j = 0; j <= segments; j++) { float num2 = (float)j / (float)segments; float num3 = num2 * MathF.PI * 2f; float x = profile[i].x; meshData.AddVertex(new Vector3(Mathf.Cos(num3) * x, profile[i].y, Mathf.Sin(num3) * x), new Vector2(num2 * uRepeat, (float)i / (float)(num - 1))); } } for (int k = 0; k < num - 1; k++) { for (int l = 0; l < segments; l++) { int num4 = k * (segments + 1) + l; int num5 = num4 + 1; int num6 = num4 + segments + 1; int c = num6 + 1; meshData.AddTriangle(num4, num6, num5); meshData.AddTriangle(num5, num6, c); } } meshData.EnsureOutwardWinding(); return meshData; } public static MeshData Torus(Vector3 center, float major, float minor, int segU, int segV) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_007b: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) MeshData meshData = new MeshData(); Vector3 val = default(Vector3); for (int i = 0; i <= segU; i++) { float num = (float)i / (float)segU * MathF.PI * 2f; ((Vector3)(ref val))..ctor(Mathf.Cos(num), 0f, Mathf.Sin(num)); for (int j = 0; j <= segV; j++) { float num2 = (float)j / (float)segV * MathF.PI * 2f; Vector3 position = center + val * (major + minor * Mathf.Cos(num2)) + Vector3.up * (minor * Mathf.Sin(num2)); meshData.AddVertex(position, new Vector2((float)i / (float)segU, (float)j / (float)segV)); } } for (int k = 0; k < segU; k++) { for (int l = 0; l < segV; l++) { int num3 = k * (segV + 1) + l; int num4 = num3 + 1; int num5 = num3 + segV + 1; int b = num5 + 1; meshData.AddTriangle(num3, num4, num5); meshData.AddTriangle(num4, b, num5); } } meshData.EnsureOutwardWinding(); return meshData; } public static MeshData Bipyramid(Vector3 center, float radius, float height, int sides) { //IL_000f: 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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_007d: 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_009a: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) MeshData meshData = new MeshData(); float num = height * 0.5f; int a = meshData.AddVertex(center + Vector3.up * num, new Vector2(0.5f, 1f)); int a2 = meshData.AddVertex(center - Vector3.up * num, new Vector2(0.5f, 0f)); int[] array = new int[sides]; for (int i = 0; i < sides; i++) { float num2 = (float)i / (float)sides * MathF.PI * 2f; Vector3 position = center + new Vector3(Mathf.Cos(num2) * radius, 0f, Mathf.Sin(num2) * radius); array[i] = meshData.AddVertex(position, new Vector2((float)i / (float)sides, 0.5f)); } for (int j = 0; j < sides; j++) { int num3 = (j + 1) % sides; meshData.AddTriangle(a, array[j], array[num3]); meshData.AddTriangle(a2, array[num3], array[j]); } meshData.EnsureOutwardWinding(); return meshData; } public static MeshData Sphere(Vector3 center, float radius, int segments, int rings) { //IL_0038: 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_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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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) MeshData meshData = new MeshData(); for (int i = 0; i <= rings; i++) { float num = (float)i / (float)rings; float num2 = num * MathF.PI; for (int j = 0; j <= segments; j++) { float num3 = (float)j / (float)segments; float num4 = num3 * MathF.PI * 2f; Vector3 position = center + new Vector3(Mathf.Sin(num2) * Mathf.Cos(num4), Mathf.Cos(num2), Mathf.Sin(num2) * Mathf.Sin(num4)) * radius; meshData.AddVertex(position, new Vector2(num3, 1f - num)); } } for (int k = 0; k < rings; k++) { for (int l = 0; l < segments; l++) { int num5 = k * (segments + 1) + l; int num6 = num5 + 1; int num7 = num5 + segments + 1; int c = num7 + 1; meshData.AddTriangle(num5, num7, num6); meshData.AddTriangle(num6, num7, c); } } meshData.EnsureOutwardWinding(); return meshData; } public void EnsureOutwardWinding() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) double num = 0.0; for (int i = 0; i < Triangles.Count; i += 3) { Vector3 val = Vertices[Triangles[i]]; Vector3 val2 = Vertices[Triangles[i + 1]]; Vector3 val3 = Vertices[Triangles[i + 2]]; num += (double)Vector3.Dot(val, Vector3.Cross(val2, val3)); } if (!(num >= 0.0)) { for (int j = 0; j < Triangles.Count; j += 3) { int value = Triangles[j + 1]; Triangles[j + 1] = Triangles[j + 2]; Triangles[j + 2] = value; } } } public Mesh ToMesh(string name) { //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) int count = Vertices.Count; int count2 = Triangles.Count; Vector3[] collection = Vertices.ToArray(); Vector2[] collection2 = Uvs.ToArray(); Vertices.AddRange(collection); Uvs.AddRange(collection2); for (int i = 0; i < count2; i += 3) { Triangles.Add(Triangles[i] + count); Triangles.Add(Triangles[i + 2] + count); Triangles.Add(Triangles[i + 1] + count); } Mesh val = new Mesh(); ((Object)val).name = name; val.SetVertices(Vertices); val.SetUVs(0, Uvs); List<Color> list = new List<Color>(Vertices.Count); for (int j = 0; j < Vertices.Count; j++) { list.Add(Color.white); } val.SetColors(list); val.SetTriangles(Triangles, 0); val.RecalculateNormals(); val.RecalculateBounds(); return val; } } private const string BodyObj = "BearHoney.assets.model.honey_body.obj"; private const string CollarObj = "BearHoney.assets.model.honey_collar.obj"; private const string StopperObj = "BearHoney.assets.model.honey_stopper.obj"; private const string RingObj = "BearHoney.assets.model.honey_ring.obj"; private const string PanelObjFormat = "BearHoney.assets.model.honey_panel_{0}.obj"; private const string DropObj = "BearHoney.assets.model.honey_drop.obj"; private static readonly Color Navy = new Color(0.13f, 0.18f, 0.32f); private static readonly Color PanelNavy = new Color(0.075f, 0.105f, 0.185f); private static readonly Color Steel = new Color(0.58f, 0.6f, 0.64f); private static readonly Color Crystal = new Color(0.155f, 0.225f, 0.44f); private static readonly Color Honey = new Color(0.96f, 0.68f, 0.16f); private static readonly Vector2[] BodyProfile = (Vector2[])(object)new Vector2[16] { new Vector2(0.0005f, 0f), new Vector2(0.068f, 0f), new Vector2(0.078f, 0.008f), new Vector2(0.08f, 0.02f), new Vector2(0.076f, 0.032f), new Vector2(0.083f, 0.062f), new Vector2(0.087f, 0.118f), new Vector2(0.083f, 0.162f), new Vector2(0.07f, 0.198f), new Vector2(0.052f, 0.224f), new Vector2(0.034f, 0.248f), new Vector2(0.026f, 0.266f), new Vector2(0.024f, 0.3f), new Vector2(0.028f, 0.316f), new Vector2(0.024f, 0.328f), new Vector2(0.0005f, 0.328f) }; private static readonly Vector2[] CollarProfile = (Vector2[])(object)new Vector2[6] { new Vector2(0.0005f, 0.298f), new Vector2(0.03f, 0.298f), new Vector2(0.031f, 0.304f), new Vector2(0.031f, 0.318f), new Vector2(0.029f, 0.322f), new Vector2(0.0005f, 0.322f) }; public static GameObject Create(Material template) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)template == (Object)null) { return null; } GameObject val = new GameObject("BearHoneyPickupModel"); val.transform.position = new Vector3(0f, -2000f, 0f); BuildMaterials(template, out var body, out var panel, out var collar, out var crystal, out var honey); bool flag = true; flag &= AddObjPart(val, "Body", "BearHoney.assets.model.honey_body.obj", body, cylindricalUv: true, 3f); flag &= AddObjPart(val, "Collar", "BearHoney.assets.model.honey_collar.obj", collar, cylindricalUv: false, 1f); flag &= AddObjPart(val, "Stopper", "BearHoney.assets.model.honey_stopper.obj", crystal, cylindricalUv: false, 1f); flag &= AddObjPart(val, "HoneyRing", "BearHoney.assets.model.honey_ring.obj", honey, cylindricalUv: false, 1f); flag &= AddObjPart(val, "HoneyDrop", "BearHoney.assets.model.honey_drop.obj", honey, cylindricalUv: false, 1f); for (int i = 0; i < 6; i++) { flag &= AddObjPart(val, "HexPanel" + i, $"BearHoney.assets.model.honey_panel_{i}.obj", panel, cylindricalUv: false, 1f); } if (!flag) { Object.Destroy((Object)(object)val); return CreateProcedural(template); } Object.DontDestroyOnLoad((Object)(object)val); return val; } private static bool AddObjPart(GameObject root, string name, string resource, Material material, bool cylindricalUv, float uRepeat) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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) Mesh val = ObjModelLoader.Load(resource, cylindricalUv, uRepeat); if ((Object)(object)val == (Object)null) { return false; } GameObject val2 = new GameObject(name); val2.transform.SetParent(root.transform, false); val2.AddComponent<MeshFilter>().sharedMesh = val; ((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = material; return true; } private static void BuildMaterials(Material template, out Material body, out Material panel, out Material collar, out Material crystal, out Material honey) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) Texture2D texture = BuildPlainTexture(); body = CreateMaterial(template, Navy, 0.15f, 0.55f, (Texture)(object)texture, null); panel = CreateMaterial(template, PanelNavy, 0.2f, 0.62f, (Texture)(object)texture, null); collar = CreateMaterial(template, Steel, 0.85f, 0.65f, (Texture)(object)texture, null); crystal = CreateMaterial(template, Crystal, 0.3f, 0.85f, (Texture)(object)texture, (Color?)new Color(0.05f, 0.13f, 0.3f)); honey = CreateMaterial(template, Honey, 0.05f, 0.75f, (Texture)(object)texture, (Color?)new Color(0.45f, 0.22f, 0.03f)); } private static Material CreateMaterial(Material template, Color color, float metallic, float smoothness, Texture texture, Color? emission) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(template); ((Object)val).name = "BearHoneyMat"; if (val.HasProperty("_Color")) { val.SetColor("_Color", color); } if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if ((Object)(object)texture != (Object)null) { if (val.HasProperty("_MainTex")) { val.SetTexture("_MainTex", texture); } if (val.HasProperty("_BaseMap")) { val.SetTexture("_BaseMap", texture); } } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", metallic); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", smoothness); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", smoothness); } if (emission.HasValue) { if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", emission.Value); val.EnableKeyword("_EMISSION"); } val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; } return val; } private static Texture2D BuildPlainTexture() { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(4, 4, (TextureFormat)4, true); Color32[] array = (Color32[])(object)new Color32[16]; for (int i = 0; i < array.Length; i++) { array[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); } val.SetPixels32(array); val.Apply(true, true); return val; } private static GameObject CreateProcedural(Material template) { //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_001f: 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_0056: Expected O, but got Unknown //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0073: 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_00a3: Expected O, but got Unknown //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Expected O, but got Unknown //IL_010c: Expected O, but got Unknown GameObject val = new GameObject("BearHoneyPickupModelFallback"); val.transform.position = new Vector3(0f, -2000f, 0f); BuildMaterials(template, out var body, out var _, out var collar, out var crystal, out var honey); AddPart(val, "Body", MeshData.Lathe(BodyProfile, 28, 3f), body); AddPart(val, "Collar", MeshData.Lathe(CollarProfile, 24, 1f), collar); AddPart(val, "Stopper", MeshData.Bipyramid(new Vector3(0f, 0.368f, 0f), 0.0335f, 0.092f, 6), crystal); AddPart(val, "HoneyRing", MeshData.Torus(new Vector3(0f, 0.3315f, 0f), 0.0335f, 0.0105f, 24, 10), honey); AddPart(val, "HoneyDrop", MeshData.Sphere(new Vector3(0.0305f, 0.309f, 0f), 0.0128f, 12, 8), honey); Object.DontDestroyOnLoad((Object)val); return val; } private static void AddPart(GameObject root, string name, MeshData data, Material material) { //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_0018: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(root.transform, false); val.AddComponent<MeshFilter>().sharedMesh = data.ToMesh(name); ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = material; } } internal static class ObjModelLoader { public static Mesh Load(string resourceName, bool cylindricalUv, float uRepeat) { //IL_0099: 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_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Expected O, but got Unknown //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_024e: 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_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); if (manifestResourceStream == null) { Debug.LogWarning((object)("[BearHoney] 找不到模型资源:" + resourceName)); return null; } List<Vector3> list = new List<Vector3>(); List<Vector3> list2 = new List<Vector3>(); List<Vector3> list3 = new List<Vector3>(); List<Vector3> list4 = new List<Vector3>(); List<Vector2> list5 = new List<Vector2>(); List<int> list6 = new List<int>(); Dictionary<long, int> lookup = new Dictionary<long, int>(); try { using StreamReader streamReader = new StreamReader(manifestResourceStream); string text; while ((text = streamReader.ReadLine()) != null) { text = text.Trim(); if (text.Length >= 2 && text[0] != '#') { if (text[0] == 'v' && text[1] == ' ') { list.Add(ParseVector(text)); } else if (text[0] == 'v' && text[1] == 'n') { list2.Add(ParseVector(text)); } else if (text[0] == 'f' && text[1] == ' ') { AddFace(text, list, list2, list3, list4, list6, lookup); } } } } catch (Exception ex) { Debug.LogWarning((object)("[BearHoney] 解析模型失败 " + resourceName + ":" + ex.Message)); return null; } finally { manifestResourceStream.Dispose(); } if (list3.Count == 0 || list6.Count == 0) { return null; } int count = list3.Count; int count2 = list6.Count; Vector3[] collection = list3.ToArray(); list3.AddRange(collection); if (list4.Count == count) { Vector3[] array = list4.ToArray(); for (int i = 0; i < array.Length; i++) { list4.Add(-array[i]); } } for (int j = 0; j < count2; j += 3) { list6.Add(list6[j] + count); list6.Add(list6[j + 2] + count); list6.Add(list6[j + 1] + count); } Mesh val = new Mesh(); ((Object)val).name = Path.GetFileNameWithoutExtension(resourceName); val.SetVertices(list3); val.SetTriangles(list6, 0); if (list4.Count == list3.Count) { val.SetNormals(list4); } else { val.RecalculateNormals(); } val.RecalculateBounds(); Bounds bounds = val.bounds; float num = Mathf.Max(((Bounds)(ref bounds)).size.y, 0.0001f); for (int k = 0; k < list3.Count; k++) { Vector3 val2 = list3[k]; float num2 = (cylindricalUv ? ((Mathf.Atan2(val2.z, val2.x) / (MathF.PI * 2f) + 0.5f) * uRepeat) : ((val2.x - ((Bounds)(ref bounds)).min.x) / Mathf.Max(((Bounds)(ref bounds)).size.x, 0.0001f))); float num3 = (val2.y - ((Bounds)(ref bounds)).min.y) / num; list5.Add(new Vector2(num2, num3)); } val.SetUVs(0, list5); List<Color> list7 = new List<Color>(list3.Count); for (int l = 0; l < list3.Count; l++) { list7.Add(Color.white); } val.SetColors(list7); val.RecalculateTangents(); return val; } private static Vector3 ParseVector(string line) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) string[] array = line.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length < 4) { return Vector3.zero; } return new Vector3(float.Parse(array[1], CultureInfo.InvariantCulture), float.Parse(array[2], CultureInfo.InvariantCulture), float.Parse(array[3], CultureInfo.InvariantCulture)); } private static void AddFace(string line, List<Vector3> positions, List<Vector3> normals, List<Vector3> vertices, List<Vector3> vertexNormals, List<int> triangles, Dictionary<long, int> lookup) { string[] array = line.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length >= 4) { int num = array.Length - 1; int[] array2 = new int[num]; for (int i = 0; i < num; i++) { array2[i] = GetCorner(array[i + 1], positions, normals, vertices, vertexNormals, lookup); } for (int j = 1; j < num - 1; j++) { triangles.Add(array2[0]); triangles.Add(array2[j]); triangles.Add(array2[j + 1]); } } } private static int GetCorner(string token, List<Vector3> positions, List<Vector3> normals, List<Vector3> vertices, List<Vector3> vertexNormals, Dictionary<long, int> lookup) { //IL_006c: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) string[] array = token.Split('/'); int num = ParseIndex(array[0], positions.Count); int num2 = ((array.Length > 2 && array[2].Length > 0) ? ParseIndex(array[2], normals.Count) : (-1)); long key = ((long)num << 32) ^ (uint)(num2 + 1); if (lookup.TryGetValue(key, out var value)) { return value; } int count = vertices.Count; vertices.Add((num >= 0 && num < positions.Count) ? positions[num] : Vector3.zero); vertexNormals.Add((num2 >= 0 && num2 < normals.Count) ? normals[num2] : Vector3.up); lookup[key] = count; return count; } private static int ParseIndex(string text, int count) { if (!int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return -1; } if (result >= 0) { return result - 1; } return count + result; } } [BepInPlugin("com.bearhoney.RoR2", "BearHoney", "1.0.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class BearHoneyPlugin : BaseUnityPlugin { [CompilerGenerated] private static class <>O { public static StatHookEventHandler <0>__ApplyStatHooks; public static Action<CharacterBody, BuffDef> <1>__OnBuffFinalStackLost; public static Action<DamageReport> <2>__OnCharacterDeathServer; } public const string PluginGuid = "com.bearhoney.RoR2"; public const string PluginName = "BearHoney"; public const string PluginVersion = "1.0.3"; private const string EquipNameToken = "CANNEDHONEY_EQUIP_NAME"; private const string EquipPickupToken = "CANNEDHONEY_EQUIP_PICKUP"; private const string EquipDescToken = "CANNEDHONEY_EQUIP_DESC"; private const string EquipLoreToken = "CANNEDHONEY_EQUIP_LORE"; private const string AffNameToken = "CANNEDHONEY_AFF_NAME"; private const string AffPickupToken = "CANNEDHONEY_AFF_PICKUP"; private const string AffDescToken = "CANNEDHONEY_AFF_DESC"; private const string AffLoreToken = "CANNEDHONEY_AFF_LORE"; private const string EquipmentName = "BearHoney"; private const string AfflictionName = "BearHoneyAffliction"; private const string BuffName = "bdBearHoney"; private static readonly string[] TonicPrefabAddresses = new string[2] { "RoR2/Base/Tonic/PickupTonic.prefab", "RoR2/Base/Equipment/Tonic/PickupTonic.prefab" }; private static readonly string[] MaterialTemplateAddresses = new string[3] { "RoR2/Base/Fruit/PickupFruit.prefab", "RoR2/Base/Medkit/PickupMedkit.prefab", "RoR2/Base/Equipment/Fruit/PickupFruit.prefab" }; private const string HarmonyId = "com.bearhoney.RoR2.harmony"; public const string TonicUseSound = "Play_item_use_tonic"; public static EquipmentDef HoneyEquipment; public static BuffDef HoneyBuff; public static ItemDef HoneyAffliction; public static ConfigEntry<float> CfgCooldown; public static ConfigEntry<float> CfgBuffDuration; public static ConfigEntry<float> CfgDamageMult; public static ConfigEntry<float> CfgAttackSpeedMult; public static ConfigEntry<float> CfgArmorBonus; public static ConfigEntry<float> CfgHealthMult; public static ConfigEntry<float> CfgShieldMult; public static ConfigEntry<float> CfgRegenMult; public static ConfigEntry<float> CfgMoveSpeedMult; public static ConfigEntry<float> CfgAfflictionChance; public static ConfigEntry<float> CfgAfflictionStatMult; public static ConfigEntry<float> CfgAfflictionCursePerStack; public static ConfigEntry<bool> CfgUseCustomModel; public static ConfigEntry<bool> CfgUseTonicModelFallback; private static GameObject _customModel; private static GameObject _tonicPrefab; private static Material _templateMaterial; private static bool _builtModelLogged; private static bool _soundFailureLogged; private static readonly ConditionalWeakTable<CharacterBody, StrongBox<float>> ShieldBonusCache = new ConditionalWeakTable<CharacterBody, StrongBox<float>>(); private void Awake() { //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) BindConfig(); RegisterLanguage(); Sprite icon = LoadEmbeddedSprite("BearHoney.assets.texHoneyIcon.png"); Sprite buffIcon = LoadEmbeddedSprite("BearHoney.assets.texBuffIcon.png"); Sprite icon2 = LoadEmbeddedSprite("BearHoney.assets.texAfflictionIcon.png"); CreateBuff(buffIcon); CreateEquipment(icon); bool flag = CfgUseCustomModel != null && CfgUseCustomModel.Value; if (!Object.op_Implicit((Object)(object)HoneyEquipment) || !Object.op_Implicit((Object)(object)HoneyEquipment.pickupModelPrefab) || (flag && (Object)(object)_customModel == (Object)null)) { ((MonoBehaviour)this).StartCoroutine(LoadPickupModelRoutine()); } CreateAfflictionItem(icon2); try { Harmony val = new Harmony("com.bearhoney.RoR2.harmony"); val.PatchAll(typeof(PerformEquipmentActionPatch)); val.PatchAll(typeof(LogBookFilterPatch)); ((BaseUnityPlugin)this).Logger.LogInfo((object)"已注册装备激活补丁与图鉴过滤补丁。"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("装备激活补丁注册失败,装备将无法生效:" + ex)); } object obj = <>O.<0>__ApplyStatHooks; if (obj == null) { StatHookEventHandler val2 = ApplyStatHooks; <>O.<0>__ApplyStatHooks = val2; obj = (object)val2; } RecalculateStatsAPI.GetStatCoefficients += (StatHookEventHandler)obj; CharacterBody.onBuffFinalStackLost += OnBuffFinalStackLost; GlobalEventManager.onCharacterDeathServer += OnCharacterDeathServer; ((BaseUnityPlugin)this).Config.Save(); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"「瓶中蜂蜜」加载完成:冷却 {CfgCooldown.Value}s,持续 {CfgBuffDuration.Value}s,伤害 x{CfgDamageMult.Value},攻速 x{CfgAttackSpeedMult.Value},护甲 +{CfgArmorBonus.Value},最大生命 x{CfgHealthMult.Value},护盾 x{CfgShieldMult.Value}(不在描述中显示),回复 x{CfgRegenMult.Value},移速 x{CfgMoveSpeedMult.Value},副作用几率 {CfgAfflictionChance.Value * 100f}%,自定义模型={CfgUseCustomModel.Value}"); } private void OnDestroy() { //IL_0010: 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_001b: Expected O, but got Unknown object obj = <>O.<0>__ApplyStatHooks; if (obj == null) { StatHookEventHandler val = ApplyStatHooks; <>O.<0>__ApplyStatHooks = val; obj = (object)val; } RecalculateStatsAPI.GetStatCoefficients -= (StatHookEventHandler)obj; CharacterBody.onBuffFinalStackLost -= OnBuffFinalStackLost; GlobalEventManager.onCharacterDeathServer -= OnCharacterDeathServer; } private void BindConfig() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Expected O, but got Unknown //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Expected O, but got Unknown //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Expected O, but got Unknown //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Expected O, but got Unknown //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Expected O, but got Unknown //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Expected O, but got Unknown //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Expected O, but got Unknown //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Expected O, but got Unknown //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Expected O, but got Unknown //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Expected O, but got Unknown CfgCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Cooldown", 45f, new ConfigDescription("装备冷却时间(秒)。默认 45。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 600f), Array.Empty<object>())); CfgBuffDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BuffDuration", 20f, new ConfigDescription("激活后增益持续时间(秒)。默认 20。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 600f), Array.Empty<object>())); CfgUseCustomModel = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UseCustomModel", true, "使用 MOD 自带的程序化 3D 拾取模型(不透明瓶身 + 蜂巢刻纹 + 瓶口蜂蜜)。关掉则退回尖晶强心剂的瓶子模型。"); CfgUseTonicModelFallback = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UseTonicModelFallback", true, "自定义模型生成失败时,是否退回使用尖晶强心剂的瓶子模型。"); CfgDamageMult = ((BaseUnityPlugin)this).Config.Bind<float>("BuffStats", "DamageMultiplier", 1.3f, new ConfigDescription("伤害倍率。1.3 = 伤害 +30%。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgAttackSpeedMult = ((BaseUnityPlugin)this).Config.Bind<float>("BuffStats", "AttackSpeedMultiplier", 1.2f, new ConfigDescription("攻击速度倍率。1.2 = 攻速 +20%。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgArmorBonus = ((BaseUnityPlugin)this).Config.Bind<float>("BuffStats", "ArmorBonus", 10f, new ConfigDescription("固定护甲加成。默认 +10。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-1000f, 1000f), Array.Empty<object>())); CfgHealthMult = ((BaseUnityPlugin)this).Config.Bind<float>("BuffStats", "MaxHealthMultiplier", 1.15f, new ConfigDescription("最大生命值倍率。1.15 = +15%。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgShieldMult = ((BaseUnityPlugin)this).Config.Bind<float>("BuffStats", "ShieldMultiplier", 1.15f, new ConfigDescription("护盾倍率。1.15 = +15%。该属性生效,但不会写进道具描述。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgRegenMult = ((BaseUnityPlugin)this).Config.Bind<float>("BuffStats", "RegenMultiplier", 1.5f, new ConfigDescription("被动生命回复倍率。1.5 = +50%。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgMoveSpeedMult = ((BaseUnityPlugin)this).Config.Bind<float>("BuffStats", "MoveSpeedMultiplier", 1.2f, new ConfigDescription("移动速度倍率。1.2 = +20%。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgAfflictionChance = ((BaseUnityPlugin)this).Config.Bind<float>("Affliction", "AfflictionChance", 0.2f, new ConfigDescription("增益结束后获得「蜂蜜副作用」的概率。0.2 = 20%。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); CfgAfflictionStatMult = ((BaseUnityPlugin)this).Config.Bind<float>("Affliction", "AfflictionStatMultiplier", 0.95f, new ConfigDescription("每层副作用对 伤害/攻速/移速/回复 的倍率。0.95 = 每层 -5%。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 2f), Array.Empty<object>())); CfgAfflictionCursePerStack = ((BaseUnityPlugin)this).Config.Bind<float>("Affliction", "AfflictionCursePerStack", 0.1f, new ConfigDescription("每层副作用额外增加的诅咒(影响最大生命)。0.1 = 每层 +10%。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>())); } private void CreateBuff(Sprite buffIcon) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) HoneyBuff = ScriptableObject.CreateInstance<BuffDef>(); ((Object)HoneyBuff).name = "bdBearHoney"; HoneyBuff.buffColor = new Color(0.96f, 0.72f, 0.26f); HoneyBuff.canStack = false; HoneyBuff.isDebuff = false; HoneyBuff.isCooldown = false; HoneyBuff.isHidden = false; HoneyBuff.iconSprite = buffIcon; ContentAddition.AddBuffDef(HoneyBuff); } private void CreateEquipment(Sprite icon) { //IL_0071: 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_0094: Expected O, but got Unknown EquipmentDef obj = ScriptableObject.CreateInstance<EquipmentDef>(); ((Object)obj).name = "BearHoney"; obj.nameToken = "CANNEDHONEY_EQUIP_NAME"; obj.pickupToken = "CANNEDHONEY_EQUIP_PICKUP"; obj.descriptionToken = "CANNEDHONEY_EQUIP_DESC"; obj.loreToken = "CANNEDHONEY_EQUIP_LORE"; obj.cooldown = CfgCooldown.Value; obj.canDrop = true; obj.enigmaCompatible = false; obj.canBeRandomlyTriggered = false; obj.isLunar = true; obj.isBoss = false; obj.colorIndex = (ColorIndex)4; obj.pickupIconSprite = icon; obj.pickupModelPrefab = ResolvePickupModel(); if (!ItemAPI.Add(new CustomEquipment(obj, (ItemDisplayRule[])null))) { ((BaseUnityPlugin)this).Logger.LogError((object)"装备注册失败:ItemAPI 拒绝了 BearHoney"); } HoneyEquipment = obj; } private void CreateAfflictionItem(Sprite icon) { //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_0050: Expected O, but got Unknown ItemTag[] array = (ItemTag[])(object)new ItemTag[2] { (ItemTag)25, (ItemTag)4 }; CustomItem val = new CustomItem("BearHoneyAffliction", "CANNEDHONEY_AFF_NAME", "CANNEDHONEY_AFF_DESC", "CANNEDHONEY_AFF_LORE", "CANNEDHONEY_AFF_PICKUP", icon, (GameObject)null, array, (ItemTier)5, false, false, (UnlockableDef)null, (ItemDisplayRule[])null); HoneyAffliction = val.ItemDef; ForceNoTier(HoneyAffliction); if (!ItemAPI.Add(val)) { ((BaseUnityPlugin)this).Logger.LogError((object)"副作用物品注册失败:ItemAPI 拒绝了 BearHoneyAffliction"); } } private static void ForceNoTier(ItemDef def) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Invalid comparison between Unknown and I4 //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) if ((Object)(object)def == (Object)null) { return; } try { FieldInfo field = typeof(ItemDef).GetField("deprecatedTier", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(def, (object)(ItemTier)5); } } catch (Exception ex) { Debug.LogWarning((object)("[BearHoney] 设置 NoTier 失败:" + ex.Message)); } if ((int)def.tier != 5) { Debug.LogWarning((object)("[BearHoney] 副作用物品品质不是 NoTier(当前 " + ((object)def.tier/*cast due to .constrained prefix*/).ToString() + "),可能仍会出现在图鉴中。")); } } private void RegisterLanguage() { float v = (CfgDamageMult.Value - 1f) * 100f; float v2 = (CfgAttackSpeedMult.Value - 1f) * 100f; float v3 = (CfgHealthMult.Value - 1f) * 100f; float v4 = (CfgRegenMult.Value - 1f) * 100f; float v5 = (CfgMoveSpeedMult.Value - 1f) * 100f; float v6 = (1f - CfgAfflictionStatMult.Value) * 100f; float v7 = CfgAfflictionChance.Value * 100f; string text = "立即获得小幅全属性加成。<color=#FF7F7F>效果结束后有几率产生所有属性降低的副作用。</color>"; string text2 = "饮下瓶中蜂蜜,立即获得属性强化,持续 " + Fmt(CfgBuffDuration.Value) + " 秒。<style=cIsDamage>伤害</style>提高<style=cIsDamage>+" + Fmt(v) + "%</style>,<style=cIsDamage>攻击速度</style>提高<style=cIsDamage>+" + Fmt(v2) + "%</style>,<style=cIsDamage>护甲</style>提高<style=cIsDamage>+" + Fmt(CfgArmorBonus.Value) + "</style>,<style=cIsHealing>最大生命值</style>提高<style=cIsHealing>+" + Fmt(v3) + "%</style>,<style=cIsHealing>生命再生</style>提高<style=cIsHealing>+" + Fmt(v4) + "%</style>,<style=cIsUtility>移动速度</style>提高<style=cIsUtility>+" + Fmt(v5) + "%</style>。\n\n效果结束时,有<style=cIsHealth>" + Fmt(v7) + "%</style>的几率获得<style=cIsHealth>蜂蜜副作用</style>,使你的伤害、攻速、移速与再生降低<style=cIsHealth>" + Fmt(v6) + "%</style><style=cStack>(每层 -" + Fmt(v6) + "%)</style>。"; string text3 = "伤害、攻击速度、移动速度与生命再生降低<style=cIsHealth>-" + Fmt(v6) + "%</style><style=cStack>(每层 -" + Fmt(v6) + "%)</style>,并额外承受<style=cIsHealth>+" + Fmt(CfgAfflictionCursePerStack.Value * 100f) + "%</style>诅咒(降低最大生命值)。"; string text4 = "Immediately gain a small boost to all stats. <color=#FF7F7F>When it ends, may leave a debuff that reduces all stats.</color>"; string text5 = "Drink the bottled honey to gain a burst of power for " + Fmt(CfgBuffDuration.Value) + " seconds. Increase <style=cIsDamage>damage</style> by <style=cIsDamage>+" + Fmt(v) + "%</style>, <style=cIsDamage>attack speed</style> by <style=cIsDamage>+" + Fmt(v2) + "%</style>, <style=cIsDamage>armor</style> by <style=cIsDamage>+" + Fmt(CfgArmorBonus.Value) + "</style>, <style=cIsHealing>maximum health</style> by <style=cIsHealing>+" + Fmt(v3) + "%</style>, <style=cIsHealing>health regeneration</style> by <style=cIsHealing>+" + Fmt(v4) + "%</style>, and <style=cIsUtility>movement speed</style> by <style=cIsUtility>+" + Fmt(v5) + "%</style>.\n\nWhen the effect ends, gain <style=cIsHealth>Honey Sickness</style> with a <style=cIsHealth>" + Fmt(v7) + "%</style> chance, reducing your damage, attack speed, movement speed and regeneration by <style=cIsHealth>" + Fmt(v6) + "%</style><style=cStack> (per stack)</style>."; string text6 = "Reduce damage, attack speed, movement speed and health regeneration by <style=cIsHealth>" + Fmt(v6) + "%</style><style=cStack> per stack</style>, and add <style=cIsHealth>+" + Fmt(CfgAfflictionCursePerStack.Value * 100f) + "%</style> curse (lower maximum health)."; LanguageAPI.Add("CANNEDHONEY_EQUIP_NAME", "Bottled Honey"); LanguageAPI.Add("CANNEDHONEY_EQUIP_NAME", "瓶中蜂蜜", "zh-CN"); LanguageAPI.Add("CANNEDHONEY_EQUIP_PICKUP", text4); LanguageAPI.Add("CANNEDHONEY_EQUIP_PICKUP", text, "zh-CN"); LanguageAPI.Add("CANNEDHONEY_EQUIP_DESC", text5); LanguageAPI.Add("CANNEDHONEY_EQUIP_DESC", text2, "zh-CN"); LanguageAPI.Add("CANNEDHONEY_EQUIP_LORE", "\"The sweet comes with the sting. Remember that, when you lick the lid.\"\n\n— the Beekeeper"); LanguageAPI.Add("CANNEDHONEY_EQUIP_LORE", "“甜美的代价——当你尝到蜂蜜的甜,也别忘了蜂针的刺。”\n\n——养蜂人", "zh-CN"); LanguageAPI.Add("CANNEDHONEY_AFF_NAME", "Honey Sickness"); LanguageAPI.Add("CANNEDHONEY_AFF_NAME", "蜂蜜副作用", "zh-CN"); LanguageAPI.Add("CANNEDHONEY_AFF_PICKUP", "<color=#FFB84D>Weakens you while Bottled Honey is not active.</color>"); LanguageAPI.Add("CANNEDHONEY_AFF_PICKUP", "<color=#FFB84D>不在瓶中蜂蜜状态时,削弱你的全部属性。</color>", "zh-CN"); LanguageAPI.Add("CANNEDHONEY_AFF_DESC", text6); LanguageAPI.Add("CANNEDHONEY_AFF_DESC", text3, "zh-CN"); LanguageAPI.Add("CANNEDHONEY_AFF_LORE", "\"Borrowed sweetness is always paid back with interest.\""); LanguageAPI.Add("CANNEDHONEY_AFF_LORE", "“赊来的甜,终究要连本带利地还。”", "zh-CN"); } private static string Fmt(float v) { if (Math.Abs(v - Mathf.Round(v)) < 0.001f) { return Mathf.RoundToInt(v).ToString(); } return v.ToString("0.##"); } private static void ApplyStatHooks(CharacterBody body, StatHookEventArgs args) { //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Invalid comparison between Unknown and I4 if (!Object.op_Implicit((Object)(object)body)) { return; } int num; if (Object.op_Implicit((Object)(object)HoneyBuff)) { num = (body.HasBuff(HoneyBuff) ? 1 : 0); if (num != 0) { goto IL_0032; } } else { num = 0; } ShieldBonusCache.Remove(body); goto IL_0032; IL_0032: if (num != 0) { args.damageTotalMult *= CfgDamageMult.Value; args.attackSpeedTotalMult *= CfgAttackSpeedMult.Value; args.moveSpeedTotalMult *= CfgMoveSpeedMult.Value; args.regenTotalMult *= CfgRegenMult.Value; args.healthTotalMult *= CfgHealthMult.Value; args.armorAdd += CfgArmorBonus.Value; ApplyShieldBonus(body, args); } else if (Object.op_Implicit((Object)(object)HoneyAffliction) && Object.op_Implicit((Object)(object)body.inventory) && (int)HoneyAffliction.itemIndex != -1) { int itemCountEffective = body.inventory.GetItemCountEffective(HoneyAffliction); if (itemCountEffective > 0) { float num2 = Mathf.Pow(CfgAfflictionStatMult.Value, (float)itemCountEffective); args.damageTotalMult *= num2; args.attackSpeedTotalMult *= num2; args.moveSpeedTotalMult *= num2; args.regenTotalMult *= num2; args.baseCurseAdd += CfgAfflictionCursePerStack.Value * (float)itemCountEffective; } } } private static void ApplyShieldBonus(CharacterBody body, StatHookEventArgs args) { float num = ((CfgShieldMult != null) ? CfgShieldMult.Value : 1f); if (num <= 1.0001f) { ShieldBonusCache.Remove(body); return; } float num2 = 0f; if (ShieldBonusCache.TryGetValue(body, out var value)) { num2 = value.Value; } float num3 = body.maxShield - num2; if (num3 <= 0.0001f) { ShieldBonusCache.Remove(body); return; } float num4 = num3 * (num - 1f); args.baseShieldAdd += num4; if (value != null) { value.Value = num4; } else { ShieldBonusCache.Add(body, new StrongBox<float>(num4)); } } internal static float GetEffectiveChancePercent(float baseChance, float luck) { float num = Mathf.Clamp01(baseChance); int num2 = Mathf.CeilToInt(Mathf.Abs(luck)) + 1; return ((luck > 0f) ? Mathf.Pow(num, (float)num2) : (1f - Mathf.Pow(1f - num, (float)num2))) * 100f; } internal static bool Activate(EquipmentSlot slot) { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Invalid comparison between Unknown and I4 if (!NetworkServer.active || !Object.op_Implicit((Object)(object)slot)) { return false; } CharacterBody characterBody = slot.characterBody; if (!Object.op_Implicit((Object)(object)characterBody) || !Object.op_Implicit((Object)(object)characterBody.inventory) || characterBody.inventory.GetEquipmentDisabled() || !Object.op_Implicit((Object)(object)HoneyBuff)) { return false; } characterBody.AddTimedBuff(HoneyBuff, CfgBuffDuration.Value); PlayTonicUseSound(characterBody); float num = Mathf.Clamp01(CfgAfflictionChance.Value); float num2 = num * 100f; float luck = (Object.op_Implicit((Object)(object)characterBody.master) ? characterBody.master.luck : 0f); float effectiveChancePercent = GetEffectiveChancePercent(num, luck); int num3; int num4; if (Object.op_Implicit((Object)(object)HoneyAffliction)) { num3 = (((int)HoneyAffliction.itemIndex != -1) ? 1 : 0); if (num3 != 0) { num4 = ((!Util.CheckRoll(100f - num2, characterBody.master)) ? 1 : 0); goto IL_00db; } } else { num3 = 0; } num4 = 0; goto IL_00db; IL_00db: bool flag = (byte)num4 != 0; if (num3 == 0) { Debug.LogWarning((object)"[BearHoney] 副作用物品尚未就绪(itemIndex=None),本次不记录层数。"); } else if (flag) { HoneyTracker honeyTracker = EnsureTracker(characterBody); if (Object.op_Implicit((Object)(object)honeyTracker)) { honeyTracker.pendingCount++; Debug.Log((object)("[BearHoney] 本次使用命中副作用(基础 " + num2.ToString("0.##") + "%,运气 " + luck.ToString("0.##") + " → 实际 " + effectiveChancePercent.ToString("0.##") + "%),待结算 " + honeyTracker.pendingCount + " 层。")); } else { Debug.LogWarning((object)"[BearHoney] 命中副作用,但无法在 master 上创建记录组件,本次已丢弃。"); } } else { Debug.Log((object)("[BearHoney] 本次使用未触发副作用(基础 " + num2.ToString("0.##") + "%,运气 " + luck.ToString("0.##") + " → 实际 " + effectiveChancePercent.ToString("0.##") + "%)。")); } return true; } private static void PlayTonicUseSound(CharacterBody body) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)body)) { NetworkSoundEventIndex val = NetworkSoundEventCatalog.FindNetworkSoundEventIndex("Play_item_use_tonic"); if ((int)val != -1 && Object.op_Implicit((Object)(object)body.networkIdentity)) { EntitySoundManager.EmitSoundServer(val, body.networkIdentity); } else if (Util.PlaySound("Play_item_use_tonic", ((Component)body).gameObject) == 0 && !_soundFailureLogged) { _soundFailureLogged = true; Debug.LogWarning((object)"[BearHoney] 使用音效 Play_item_use_tonic 未能播放:事件未注册进 NetworkSoundEventCatalog,且本地 PostEvent 返回 0。"); } } } private static void OnBuffFinalStackLost(CharacterBody body, BuffDef buffDef) { if (!((Object)(object)buffDef != (Object)(object)HoneyBuff) && NetworkServer.active) { SettlePending(body, "增益结束"); } } private static void SettlePending(CharacterBody body, string reason) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Invalid comparison between Unknown and I4 //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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_00ab: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00ce: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)body) || !NetworkServer.active || !Object.op_Implicit((Object)(object)HoneyAffliction)) { return; } HoneyTracker tracker = GetTracker(body); if (!Object.op_Implicit((Object)(object)tracker)) { return; } if (tracker.pendingCount <= 0) { Object.Destroy((Object)(object)tracker); return; } int pendingCount = tracker.pendingCount; tracker.pendingCount = 0; Object.Destroy((Object)(object)tracker); Inventory inventory = body.inventory; if (!Object.op_Implicit((Object)(object)inventory) || (int)HoneyAffliction.itemIndex == -1) { Debug.LogWarning((object)("[BearHoney] 副作用无法结算(" + reason + "):inventory 或 ItemIndex 不可用。")); return; } inventory.GiveItemPermanent(HoneyAffliction, pendingCount); try { PickupIndex val = PickupCatalog.FindPickupIndex(HoneyAffliction.itemIndex); if (Object.op_Implicit((Object)(object)body.master) && val != PickupIndex.none) { GenericPickupController.SendPickupMessage(body.master, new UniquePickup { pickupIndex = val }, pendingCount); } } catch (Exception ex) { Debug.LogWarning((object)("[BearHoney] 发送副作用拾取通知失败:" + ex.Message)); } Debug.Log((object)("[BearHoney] " + reason + ",发放副作用 " + pendingCount + " 层,当前共 " + inventory.GetItemCountEffective(HoneyAffliction) + " 层。")); } private static void OnCharacterDeathServer(DamageReport report) { if (NetworkServer.active && report != null && Object.op_Implicit((Object)(object)report.victimBody)) { SettlePending(report.victimBody, "角色死亡"); } } private static HoneyTracker GetTracker(CharacterBody body) { if (!Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)body.master)) { return null; } return ((Component)body.master).GetComponent<HoneyTracker>(); } private static HoneyTracker EnsureTracker(CharacterBody body) { if (!Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)body.master)) { return null; } HoneyTracker honeyTracker = ((Component)body.master).GetComponent<HoneyTracker>(); if (!Object.op_Implicit((Object)(object)honeyTracker)) { honeyTracker = ((Component)body.master).gameObject.AddComponent<HoneyTracker>(); } return honeyTracker; } private static GameObject ResolvePickupModel() { if (CfgUseCustomModel != null && CfgUseCustomModel.Value) { GameObject val = TryBuildCustomModel(); if (Object.op_Implicit((Object)(object)val)) { return val; } } if (CfgUseTonicModelFallback == null || CfgUseTonicModelFallback.Value) { return TryLoadDisplayPrefab(); } return null; } private static GameObject TryBuildCustomModel() { if (Object.op_Implicit((Object)(object)_customModel)) { return _customModel; } try { Material val = LoadMaterialTemplate(); if (!Object.op_Implicit((Object)(object)val)) { return null; } _customModel = HoneyBottleModel.Create(val); if (Object.op_Implicit((Object)(object)_customModel) && !_builtModelLogged) { _builtModelLogged = true; Debug.Log((object)"[BearHoney] 已生成自定义 3D 拾取模型(切面瓶身 + 六边形浮雕 + 六棱晶体塞 + 瓶口蜂蜜)。"); } } catch (Exception ex) { Debug.LogWarning((object)("[BearHoney] 自定义模型生成失败:" + ex)); _customModel = null; } return _customModel; } private static Material LoadMaterialTemplate() { //IL_0023: 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) if (Object.op_Implicit((Object)(object)_templateMaterial)) { return _templateMaterial; } try { for (int i = 0; i < MaterialTemplateAddresses.Length; i++) { if (Object.op_Implicit((Object)(object)_templateMaterial)) { break; } GameObject val = null; try { val = Addressables.LoadAssetAsync<GameObject>((object)MaterialTemplateAddresses[i]).WaitForCompletion(); } catch { break; } if (Object.op_Implicit((Object)(object)val)) { MeshRenderer componentInChildren = val.GetComponentInChildren<MeshRenderer>(); if (Object.op_Implicit((Object)(object)componentInChildren) && Object.op_Implicit((Object)(object)((Renderer)componentInChildren).sharedMaterial)) { _templateMaterial = ((Renderer)componentInChildren).sharedMaterial; Debug.Log((object)("[BearHoney] 材质模板:" + ((Object)_templateMaterial).name + ",shader=" + ((Object)_templateMaterial.shader).name + ",来源=" + MaterialTemplateAddresses[i])); } } } } catch { } return _templateMaterial; } private static GameObject TryLoadDisplayPrefab() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)_tonicPrefab)) { return _tonicPrefab; } for (int i = 0; i < TonicPrefabAddresses.Length; i++) { try { GameObject val = Addressables.LoadAssetAsync<GameObject>((object)TonicPrefabAddresses[i]).WaitForCompletion(); if (Object.op_Implicit((Object)(object)val)) { _tonicPrefab = val; return val; } } catch { return null; } } return null; } private IEnumerator LoadPickupModelRoutine() { GameObject prefab = null; for (int i = 0; i < 240; i++) { if (Object.op_Implicit((Object)(object)prefab)) { break; } prefab = ResolvePickupModel(); if (!Object.op_Implicit((Object)(object)prefab)) { yield return (object)new WaitForSeconds(0.5f); } } if (!Object.op_Implicit((Object)(object)prefab)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"未能准备拾取模型,装备落地时将不可见(属性效果不受影响)。"); yield break; } if (Object.op_Implicit((Object)(object)HoneyEquipment)) { HoneyEquipment.pickupModelPrefab = prefab; } if (!Object.op_Implicit((Object)(object)HoneyEquipment)) { yield break; } try { PickupDef pickupDef = PickupCatalog.GetPickupDef(PickupCatalog.FindPickupIndex(HoneyEquipment.equipmentIndex)); if (pickupDef != null) { pickupDef.displayPrefab = prefab; } } catch { } ((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)(object)prefab == (Object)(object)_customModel) ? "拾取模型:使用自定义 3D 瓶身模型。" : "拾取模型:退回尖晶强心剂的瓶子模型。")); } private Sprite LoadEmbeddedSprite(string resourceName) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_008e: 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) Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); if (manifestResourceStream == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("找不到内嵌资源:" + resourceName)); return null; } try { using MemoryStream memoryStream = new MemoryStream(); manifestResourceStream.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); ((Texture)val).filterMode = (FilterMode)1; ((Texture)val).wrapMode = (TextureWrapMode)1; if (!ImageConversion.LoadImage(val, memoryStream.ToArray())) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("PNG 解码失败:" + 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), 100f, 0u, (SpriteMeshType)0); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("加载图标失败 " + resourceName + ":" + ex.Message)); return null; } finally { manifestResourceStream.Dispose(); } } } public sealed class HoneyTracker : MonoBehaviour { public int pendingCount; } [HarmonyPatch(typeof(LogBookController), "CanSelectItemEntry")] internal static class LogBookFilterPatch { [HarmonyPostfix] private static void Postfix(ItemDef itemDef, ref bool __result) { if (__result && Object.op_Implicit((Object)(object)itemDef) && Object.op_Implicit((Object)(object)BearHoneyPlugin.HoneyAffliction) && (Object)(object)itemDef == (Object)(object)BearHoneyPlugin.HoneyAffliction) { __result = false; } } } [HarmonyPatch(typeof(EquipmentSlot), "PerformEquipmentAction")] internal static class PerformEquipmentActionPatch { [HarmonyPrefix] private static bool Prefix(EquipmentSlot __instance, EquipmentDef equipmentDef, ref bool __result) { if (!Object.op_Implicit((Object)(object)equipmentDef) || !Object.op_Implicit((Object)(object)BearHoneyPlugin.HoneyEquipment) || (Object)(object)equipmentDef != (Object)(object)BearHoneyPlugin.HoneyEquipment) { return true; } __result = BearHoneyPlugin.Activate(__instance); return false; } } }