diff --git a/.gitignore b/.gitignore index 35063fc..ad3c17f 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,11 @@ CodeCoverage/ # NUnit *.VisualState.xml TestResult.xml -nunit-*.xml \ No newline at end of file +nunit-*.xml + +.idea/ + +.user +.config/ +*.DotSettings +*.user \ No newline at end of file diff --git a/BetterBugphobia.sln b/BetterBugphobia.sln new file mode 100644 index 0000000..7e12004 --- /dev/null +++ b/BetterBugphobia.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5C123AC3-ACF6-48C8-B344-3907B42C7B69}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterBugphobia", "src\BetterBugphobia\BetterBugphobia.csproj", "{E69F6D87-9F83-4108-8E24-58FE8F482BF0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E69F6D87-9F83-4108-8E24-58FE8F482BF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E69F6D87-9F83-4108-8E24-58FE8F482BF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E69F6D87-9F83-4108-8E24-58FE8F482BF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E69F6D87-9F83-4108-8E24-58FE8F482BF0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {E69F6D87-9F83-4108-8E24-58FE8F482BF0} = {5C123AC3-ACF6-48C8-B344-3907B42C7B69} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {92F6D475-68F0-44D6-A1AF-A28F5948E381} + EndGlobalSection +EndGlobal diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a9c50a3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +TODO: You can follow this format for your changelog: diff --git a/Config.Build.user.props b/Config.Build.user.props new file mode 100644 index 0000000..fe3ac52 --- /dev/null +++ b/Config.Build.user.props @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/Config.Build.user.props.template b/Config.Build.user.props.template new file mode 100644 index 0000000..fe3ac52 --- /dev/null +++ b/Config.Build.user.props.template @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..59e2986 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,42 @@ + + + + + + + + + + latest + + enable + + true + + true + embedded + + + + $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./ + + + + + + $(MSBuildThisFileDirectory) + + $(HOME)/.local/share/ + $(MSBuildProgramFiles32)/ + $(PathBeforeSteam)Steam/steamapps/common/PEAK/ + $(PeakGameRootDir)/BepInEx/plugins/ + $(PeakGameRootDir)/PEAK_Data/Managed/ + + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..fa22e41 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,60 @@ + + + + + + + https://nuget.bepinex.dev/v3/index.json; + https://nuget.windows10ce.com/nuget/v3/index.json + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + build + publish + + + + + + diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..1fc4520 Binary files /dev/null and b/icon.png differ diff --git a/src/BetterBugphobia/BetterBugphobia.csproj b/src/BetterBugphobia/BetterBugphobia.csproj new file mode 100644 index 0000000..dac5bbc --- /dev/null +++ b/src/BetterBugphobia/BetterBugphobia.csproj @@ -0,0 +1,31 @@ + + + + + netstandard2.1 + + com.github.StarAppeal.BetterBugphobia + + BetterBugphobia + + 0.1.0 + + + + + diff --git a/src/BetterBugphobia/BugPhobiaPatch.cs b/src/BetterBugphobia/BugPhobiaPatch.cs new file mode 100644 index 0000000..754349a --- /dev/null +++ b/src/BetterBugphobia/BugPhobiaPatch.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using HarmonyLib; +using UnityEngine; + +namespace BetterBugphobia; + +[HarmonyPatch(typeof(BugPhobia), "Start")] +public class BugPhobiaPatch +{ + private static readonly Dictionary MonsterTypeCache = new(); + + [HarmonyPostfix] + static void Postfix(BugPhobia __instance) + { + string gameObjectName = __instance.gameObject.name; + + if (MonsterTypeCache.TryGetValue(gameObjectName, out var monsterName)) + { + Plugin.Log.LogInfo($"[BetterBugphobia] Cache Hit: {monsterName}"); + } + else + { + var allComponents = __instance.gameObject.GetComponents(); + foreach (var component in allComponents) + { + var componentName = component.GetType().Name; + if (!Plugin.bugPhobiaMap.ContainsKey(componentName)) continue; + monsterName = componentName; + break; + } + + if (monsterName != null) + { + MonsterTypeCache[gameObjectName] = monsterName; + } + } + + Plugin.Log.LogInfo($"[BetterBugphobia] Patching {monsterName}"); + + if (monsterName == null) return; + + Plugin.ApplyBugphobia(__instance, monsterName); + + Plugin.Log.LogInfo($"[BetterBugphobia] Patch finished for {monsterName}"); + } +} \ No newline at end of file diff --git a/src/BetterBugphobia/Plugin.cs b/src/BetterBugphobia/Plugin.cs new file mode 100644 index 0000000..db127da --- /dev/null +++ b/src/BetterBugphobia/Plugin.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using BepInEx; +using BepInEx.Configuration; +using BepInEx.Logging; +using HarmonyLib; +using UnityEngine; + +namespace BetterBugphobia; + +[BepInAutoPlugin] +public partial class Plugin : BaseUnityPlugin +{ + internal static ManualLogSource Log { get; private set; } = null!; + + private List mobList = [typeof(Spider), typeof(Scorpion), typeof(Antlion), typeof(Beetle)]; + + public static Dictionary> bugPhobiaMap = new(); + + private void Awake() + { + Log = Logger; + + foreach (var mob in mobList) + { + var configEntry = Config.Bind("General", mob.Name, false, "BingBong?"); + configEntry.SettingChanged += OnSettingChanged; + bugPhobiaMap.Add(mob.Name, configEntry); + } + + Harmony.CreateAndPatchAll(typeof(Plugin).Assembly); + + Log.LogInfo($"Plugin {Name} is loaded!"); + } + + private void OnSettingChanged(object? sender, EventArgs e) + { + Log.LogInfo("Setting Changed!"); + ApplyAllBugphobiaSettings(); + } + + private void ApplyAllBugphobiaSettings() + { + foreach (var mobType in mobList) + { + foreach (var mob in FindObjectsOfType(mobType)) + { + var monsterComponent = mob as MonoBehaviour; + if (monsterComponent == null) continue; + if (monsterComponent.TryGetComponent(out var bugPhobiaComponent)) + { + ApplyBugphobia(bugPhobiaComponent, mobType.Name); + } + } + } + } + + public static void ApplyBugphobia(BugPhobia bugPhobiaComponent, string monsterName) + { + if (!bugPhobiaMap.TryGetValue(monsterName, out var configEntry)) return; + foreach(var go in bugPhobiaComponent.defaultGameObjects) go.SetActive(!configEntry.Value); + foreach(var go in bugPhobiaComponent.bugPhobiaGameObjects) go.SetActive(configEntry.Value); + } +} + diff --git a/src/BetterBugphobia/thunderstore.toml b/src/BetterBugphobia/thunderstore.toml new file mode 100644 index 0000000..108f10a --- /dev/null +++ b/src/BetterBugphobia/thunderstore.toml @@ -0,0 +1,44 @@ +[config] +schemaVersion = "0.0.1" + +[general] +repository = "https://thunderstore.io" + +[package] +namespace = "StarAppeal" +name = "BetterBugphobia" +description = "Individually toggle each bug to be BING BONG" +websiteUrl = "" # TODO: Add a link to your mod repository here (optional) +containsNsfwContent = false + +[package.dependencies] +BepInEx-BepInExPack_PEAK = "5.4.2403" + +[build] +icon = "../../icon.png" +readme = "../../README.md" +outdir = "../../artifacts/thunderstore/" + +[[build.copy]] +source = "../../artifacts/bin/BetterBugphobia/release/com.github.StarAppeal.BetterBugphobia.dll" +target = "plugins/" + +[[build.copy]] +source = "../../CHANGELOG.md" +target = "/" + +[[build.copy]] +source = "../../LICENSE" +target = "/" + +# The following config options only apply when using TCLI to publish to Thunderstore directly: + +[publish] +# See communities at: +# https://thunderstore.io/api/experimental/community/ +communities = [ "peak", ] + +[publish.categories] +# See categories at: +# https://thunderstore.io/api/experimental/community/peak/category/ +peak = [ "mods", ]