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 SakeysSneakingBox v1.0.2
BepInEx/plugins/Sakey's Sneaking Box/SakeysSneakingBox.dll
Decompiled 33 minutes agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("SakeysSneakingBox")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("SakeysSneakingBox")] [assembly: AssemblyTitle("SakeysSneakingBox")] [assembly: AssemblyVersion("1.0.0.0")] namespace SakeysSneakingBox; [BepInPlugin("com.sakey.sneakingbox", "Sakey's Sneaking Box", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class SneakingBoxPlugin : BaseUnityPlugin { public struct BoxData { public string itemId; public string displayName; public string description; } public const string PluginGUID = "com.sakey.sneakingbox"; public const string PluginName = "Sakey's Sneaking Box"; public const string PluginVersion = "1.0.0"; public const string ASSET_BUNDLE_NAME = "sneaking_box"; public const string ITEM_NAME = "SneakingBoxUtility"; public const string BOX_MODEL_NAME = "box1"; public const string FROST_EFFECT_NAME = "SE_SneakingBoxFrostResistance"; public static AssetBundle assetBundle; public static StatusEffect FrostResistanceEffect; private Harmony harmony; private static ConfigEntry<string> boxPrice; private static ConfigEntry<bool> sellAtHaldor; private static ConfigEntry<bool> sellAtHildir; private static ConfigEntry<bool> sellAtBogWitch; public static BoxData boxData = new BoxData { itemId = "SneakingBoxUtility", displayName = "段ボール箱", description = "待たせたな。\nただの箱だ。\nだが、ある世界の戦場では重要なアイテムだ" }; private void Awake() { //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Expected O, but got Unknown boxPrice = ((BaseUnityPlugin)this).Config.Bind<string>("General", "BoxPrice", "500", "商人から購入するときのコインの価格です。"); sellAtHaldor = ((BaseUnityPlugin)this).Config.Bind<bool>("Merchant Settings", "SellAtHaldor", true, "ハルドルで販売するかどうか"); sellAtHildir = ((BaseUnityPlugin)this).Config.Bind<bool>("Merchant Settings", "SellAtHildir", false, "ヒルディルで販売するかどうか"); sellAtBogWitch = ((BaseUnityPlugin)this).Config.Bind<bool>("Merchant Settings", "SellAtBogWitch", true, "ボグウィッチで販売するかどうか"); string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "sneaking_box"); assetBundle = AssetBundle.LoadFromFile(text); if ((Object)(object)assetBundle == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)("[SneakingBox] AssetBundleの読み込みに失敗しました: " + text)); } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[SneakingBox] AssetBundle loaded."); } LocalizationManager.OnLocalizationAdded += AddCustomLocalizations; PrefabManager.OnPrefabsRegistered += OnPrefabsRegistered; CreateFrostResistanceEffect(); harmony = new Harmony("com.sakey.sneakingbox"); harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Sakey's Sneaking Box] Plugin loaded successfully."); } private void OnDestroy() { LocalizationManager.OnLocalizationAdded -= AddCustomLocalizations; PrefabManager.OnPrefabsRegistered -= OnPrefabsRegistered; if (harmony != null) { harmony.UnpatchSelf(); } assetBundle = null; } private void AddCustomLocalizations() { if (Localization.instance != null) { Localization.instance.AddWord(boxData.displayName, boxData.displayName); Localization.instance.AddWord(boxData.description, boxData.description); } } private void CreateFrostResistanceEffect() { //IL_0044: 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_0056: 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_0064: 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_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_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown if (!((Object)(object)FrostResistanceEffect != (Object)null)) { SE_Stats obj = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)obj).name = "SE_SneakingBoxFrostResistance"; ((StatusEffect)obj).m_name = "防寒段ボール"; ((StatusEffect)obj).m_tooltip = "段ボールの中に入り、寒さから身を守っている。"; ((StatusEffect)obj).m_icon = null; obj.m_mods = new List<DamageModPair> { new DamageModPair { m_type = (DamageType)64, m_modifier = (DamageModifier)1 }, new DamageModPair { m_type = (DamageType)32, m_modifier = (DamageModifier)1 } }; obj.m_noiseModifier = -1f; obj.m_stealthModifier = -1f; FrostResistanceEffect = (StatusEffect)(object)obj; CustomStatusEffect val = new CustomStatusEffect((StatusEffect)(object)obj, false); ItemManager.Instance.AddStatusEffect(val); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[SneakingBox] 防寒段ボールStatusEffectを登録しました。"); } } private void OnPrefabsRegistered() { //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Expected O, but got Unknown //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_036a: Expected O, but got Unknown //IL_03be: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Expected O, but got Unknown //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Expected O, but got Unknown //IL_03de: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Expected O, but got Unknown //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_040d: Unknown result type (might be due to invalid IL or missing references) //IL_0414: Expected O, but got Unknown //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Expected O, but got Unknown //IL_046e: Unknown result type (might be due to invalid IL or missing references) //IL_0474: Expected O, but got Unknown //IL_047e: Unknown result type (might be due to invalid IL or missing references) //IL_0484: Expected O, but got Unknown //IL_048e: Unknown result type (might be due to invalid IL or missing references) //IL_0494: Expected O, but got Unknown //IL_049b: Unknown result type (might be due to invalid IL or missing references) //IL_04a2: Expected O, but got Unknown //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) PrefabManager.OnPrefabsRegistered -= OnPrefabsRegistered; try { GameObject val = PrefabManager.Instance.CreateClonedPrefab("SneakingBoxUtility", "Wood"); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[SneakingBox] Woodから段ボールPrefabを作成できませんでした。"); return; } ItemDrop component = val.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[SneakingBox] 段ボールPrefabにItemDropがありません。"); return; } ZNetView component2 = val.GetComponent<ZNetView>(); if ((Object)(object)component2 != (Object)null) { component2.m_persistent = true; } if (component.m_itemData != null && component.m_itemData.m_shared != null) { component.m_itemData.m_shared.m_name = boxData.displayName; component.m_itemData.m_shared.m_description = boxData.description; component.m_itemData.m_shared.m_maxStackSize = 1; component.m_itemData.m_shared.m_itemType = (ItemType)18; component.m_itemData.m_shared.m_weight = 1f; component.m_itemData.m_shared.m_armor = 0f; } for (int num = val.transform.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)val.transform.GetChild(num)).gameObject); } val.transform.localScale = Vector3.one; GameObject val2 = new GameObject("attach"); val2.transform.SetParent(val.transform, false); val2.transform.localPosition = Vector3.zero; val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one; if ((Object)(object)assetBundle != (Object)null) { GameObject val3 = assetBundle.LoadAsset<GameObject>("box1"); if ((Object)(object)val3 == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[SneakingBox] AssetBundle内に box1 がありません。"); } else { GameObject obj = Object.Instantiate<GameObject>(val3, val2.transform); ((Object)obj).name = "model"; obj.transform.localPosition = new Vector3(0f, 0.45f, 0f); obj.transform.localRotation = Quaternion.identity; obj.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); LODGroup[] componentsInChildren = obj.GetComponentsInChildren<LODGroup>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } int num2 = LayerMask.NameToLayer("item"); if (num2 == -1) { num2 = 12; } Transform[] componentsInChildren2 = val.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { ((Component)componentsInChildren2[i]).gameObject.layer = num2; } Collider[] componentsInChildren3 = val.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren3[i]); } BoxCollider obj2 = val.AddComponent<BoxCollider>(); obj2.center = new Vector3(0f, 0.45f, 0f); obj2.size = new Vector3(0.6f, 0.6f, 0.6f); Rigidbody val4 = val.GetComponent<Rigidbody>(); if ((Object)(object)val4 == (Object)null) { val4 = val.AddComponent<Rigidbody>(); } val4.isKinematic = false; val4.useGravity = true; } } Sprite val5 = null; if ((Object)(object)assetBundle != (Object)null) { val5 = assetBundle.LoadAsset<Sprite>("icon_box"); } ItemConfig val6 = new ItemConfig(); val6.Name = boxData.displayName; val6.Description = boxData.description; val6.CraftingStation = "piece_workbench"; val6.MinStationLevel = 1; val6.Weight = 1f; val6.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig("SerpentMeat", 1, 0, true), new RequirementConfig("TrophySerpent", 1, 0, true), new RequirementConfig("Torch", 1, 0, true) }; ItemConfig val7 = val6; if ((Object)(object)val5 != (Object)null) { val7.Icons = (Sprite[])(object)new Sprite[1] { val5 }; } CustomItem val8 = new CustomItem(val, true, val7); ItemManager.Instance.AddItem(val8); RecipeConfig val9 = new RecipeConfig(); val9.Name = "Recipe_SneakingBoxUtility"; val9.Item = "SneakingBoxUtility"; val9.CraftingStation = "piece_workbench"; val9.MinStationLevel = 1; val9.Amount = 1; val9.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig("SerpentMeat", 1, 0, true), new RequirementConfig("TrophySerpent", 1, 0, true), new RequirementConfig("Torch", 1, 0, true) }; CustomRecipe val10 = new CustomRecipe(val9); ItemManager.Instance.AddRecipe(val10); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[SneakingBox] 段ボールアイテム登録完了。"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("[SneakingBox] アイテム登録中にエラー:\n" + ex)); } } public static void AddBoxToTrader(Trader trader, List<TradeItem> result) { //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0176: 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_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Expected O, but got Unknown if ((Object)(object)trader == (Object)null || result == null) { return; } GameObject gameObject = ((Component)trader).gameObject; if ((Object)(object)gameObject == (Object)null) { return; } string name = ((Object)gameObject).name; bool flag = name.StartsWith("Haldor", StringComparison.OrdinalIgnoreCase); bool flag2 = name.StartsWith("Hildir", StringComparison.OrdinalIgnoreCase); bool flag3 = name.IndexOf("BogWitch", StringComparison.OrdinalIgnoreCase) >= 0; if ((flag && !sellAtHaldor.Value) || (flag2 && !sellAtHildir.Value) || (flag3 && !sellAtBogWitch.Value) || (!flag && !flag2 && !flag3)) { return; } for (int i = 0; i < result.Count; i++) { TradeItem val = result[i]; if (val != null && !((Object)(object)val.m_prefab == (Object)null) && ((Object)((Component)val.m_prefab).gameObject).name == "SneakingBoxUtility") { return; } } ItemDrop val2 = null; if ((Object)(object)ObjectDB.instance != (Object)null) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("SneakingBoxUtility"); if ((Object)(object)itemPrefab != (Object)null) { val2 = itemPrefab.GetComponent<ItemDrop>(); } } if ((Object)(object)val2 == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { GameObject prefab = ZNetScene.instance.GetPrefab("SneakingBoxUtility"); if ((Object)(object)prefab != (Object)null) { val2 = prefab.GetComponent<ItemDrop>(); } } if (!((Object)(object)val2 == (Object)null)) { if (!int.TryParse(boxPrice.Value, out var result2)) { result2 = 50; } result.Add(new TradeItem { m_prefab = val2, m_stack = 1, m_price = result2, m_requiredGlobalKey = string.Empty }); Logger.LogInfo((object)("[SneakingBox] " + name + " に段ボールを追加しました。")); } } } [HarmonyPatch(typeof(Trader), "GetAvailableItems")] public static class SneakingBoxTraderPatch { private static void Postfix(Trader __instance, ref List<TradeItem> __result) { if (!((Object)(object)__instance == (Object)null)) { if (__result == null) { __result = new List<TradeItem>(); } SneakingBoxPlugin.AddBoxToTrader(__instance, __result); } } } public static class SneakingBoxController { private static GameObject boxVisual; private static Player currentPlayer; private static bool boxModeActive; private static readonly Dictionary<Renderer, bool> originalRendererStates = new Dictionary<Renderer, bool>(); public static bool IsBoxModeActive => boxModeActive; public static bool IsBoxEquipped(Player player) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Invalid comparison between Unknown and I4 if ((Object)(object)player == (Object)null) { return false; } Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory == null) { return false; } List<ItemData> allItems = inventory.GetAllItems(); if (allItems == null) { return false; } foreach (ItemData item in allItems) { if (item != null && item.m_shared != null && item.m_equipped && (int)item.m_shared.m_itemType == 18 && !((Object)(object)item.m_dropPrefab == (Object)null) && ((Object)item.m_dropPrefab).name == "SneakingBoxUtility") { return true; } } return false; } public static void EnterBoxMode(Player player) { if (!((Object)(object)player == (Object)null) && !boxModeActive) { currentPlayer = player; HidePlayerModel(player); CreateBoxVisual(player); AddFrostResistance(player); boxModeActive = true; } } public static void ExitBoxMode(Player player) { if ((Object)(object)player == (Object)null) { player = currentPlayer; } RemoveFrostResistance(player); DestroyBoxVisual(); RestorePlayerModel(); boxModeActive = false; currentPlayer = null; } private static void HidePlayerModel(Player player) { originalRendererStates.Clear(); GameObject visual = ((Character)player).GetVisual(); if ((Object)(object)visual == (Object)null) { return; } Renderer[] componentsInChildren = visual.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null)) { originalRendererStates[val] = val.enabled; val.enabled = false; } } } public static void ReapplyPlayerModelHidden(Player player) { if ((Object)(object)player == (Object)null) { return; } GameObject visual = ((Character)player).GetVisual(); if ((Object)(object)visual == (Object)null) { return; } Renderer[] componentsInChildren = visual.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null)) { if (!originalRendererStates.ContainsKey(val)) { originalRendererStates[val] = val.enabled; } val.enabled = false; } } } private static void RestorePlayerModel() { foreach (KeyValuePair<Renderer, bool> originalRendererState in originalRendererStates) { Renderer key = originalRendererState.Key; if (!((Object)(object)key == (Object)null)) { key.enabled = originalRendererState.Value; } } originalRendererStates.Clear(); } private static void CreateBoxVisual(Player player) { //IL_0079: 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)boxVisual != (Object)null || (Object)(object)SneakingBoxPlugin.assetBundle == (Object)null) { return; } GameObject val = SneakingBoxPlugin.assetBundle.LoadAsset<GameObject>("box1"); if ((Object)(object)val == (Object)null) { Logger.LogError((object)"[SneakingBox] box1をAssetBundleから読み込めませんでした。"); return; } boxVisual = Object.Instantiate<GameObject>(val, ((Component)player).transform); ((Object)boxVisual).name = "SneakingBox_ActiveVisual"; boxVisual.transform.localPosition = new Vector3(0f, 0.6f, 0f); boxVisual.transform.localRotation = Quaternion.Euler(0f, -90f, 0f); boxVisual.transform.Rotate(Vector3.right, -90f, (Space)1); boxVisual.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); BoxCollider val2 = boxVisual.GetComponent<BoxCollider>(); if ((Object)(object)val2 == (Object)null) { val2 = boxVisual.AddComponent<BoxCollider>(); } val2.center = new Vector3(0f, 0.45f, 0f); val2.size = new Vector3(0.6f, 0.6f, 0.6f); Collider[] componentsInChildren = boxVisual.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.Destroy((Object)(object)componentsInChildren[i]); } Rigidbody[] componentsInChildren2 = boxVisual.GetComponentsInChildren<Rigidbody>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.Destroy((Object)(object)componentsInChildren2[i]); } LODGroup[] componentsInChildren3 = boxVisual.GetComponentsInChildren<LODGroup>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.Destroy((Object)(object)componentsInChildren3[i]); } } private static void DestroyBoxVisual() { if (!((Object)(object)boxVisual == (Object)null)) { Object.Destroy((Object)(object)boxVisual); boxVisual = null; } } private static void AddFrostResistance(Player player) { if ((Object)(object)player == (Object)null) { return; } StatusEffect frostResistanceEffect = SneakingBoxPlugin.FrostResistanceEffect; if ((Object)(object)frostResistanceEffect == (Object)null) { return; } SEMan sEMan = ((Character)player).GetSEMan(); if (sEMan != null) { int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)frostResistanceEffect).name); if (!sEMan.HaveStatusEffect(stableHashCode)) { sEMan.AddStatusEffect(frostResistanceEffect, false, 0, 0f); } } } private static void RemoveFrostResistance(Player player) { if ((Object)(object)player == (Object)null) { return; } StatusEffect frostResistanceEffect = SneakingBoxPlugin.FrostResistanceEffect; if ((Object)(object)frostResistanceEffect == (Object)null) { return; } SEMan sEMan = ((Character)player).GetSEMan(); if (sEMan != null) { int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)frostResistanceEffect).name); if (sEMan.HaveStatusEffect(stableHashCode)) { sEMan.RemoveStatusEffect(stableHashCode, false); } } } } [HarmonyPatch(typeof(Player), "Update")] public static class SneakingBoxPlayerUpdatePatch { private static void Postfix(Player __instance) { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } bool num = SneakingBoxController.IsBoxEquipped(__instance); bool flag = ((Character)__instance).IsCrouching(); if (num && flag) { if (!SneakingBoxController.IsBoxModeActive) { SneakingBoxController.EnterBoxMode(__instance); } else { SneakingBoxController.ReapplyPlayerModelHidden(__instance); } } else if (SneakingBoxController.IsBoxModeActive) { SneakingBoxController.ExitBoxMode(__instance); } } } [HarmonyPatch(typeof(Player), "GetStealthFactor")] public static class SneakingBoxStealthPatch { private static void Postfix(Player __instance, ref float __result) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && SneakingBoxController.IsBoxModeActive) { __result = 0f; } } }