From 4c7d07ee0be898e583ae6778726da3bfb909762e Mon Sep 17 00:00:00 2001 From: Brybry Date: Tue, 2 Feb 2021 00:34:13 +0100 Subject: [PATCH] Initial code commit (ver 1.0.0) --- .gitignore | 35 ++++ BetterPolus.sln | 16 ++ BetterPolus/BetterPolus.csproj | 21 +++ BetterPolus/BetterPolusPlugin.cs | 26 +++ BetterPolus/ShipStatusPatch.cs | 278 +++++++++++++++++++++++++++++++ 5 files changed, 376 insertions(+) create mode 100644 .gitignore create mode 100644 BetterPolus.sln create mode 100644 BetterPolus/BetterPolus.csproj create mode 100644 BetterPolus/BetterPolusPlugin.cs create mode 100644 BetterPolus/ShipStatusPatch.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8dd089 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# Common IntelliJ Platform excludes + +# User specific +**/.idea/**/workspace.xml +**/.idea/**/tasks.xml +**/.idea/shelf/* +**/.idea/dictionaries +**/.idea/httpRequests/ + +# Sensitive or high-churn files +**/.idea/**/dataSources/ +**/.idea/**/dataSources.ids +**/.idea/**/dataSources.xml +**/.idea/**/dataSources.local.xml +**/.idea/**/sqlDataSources.xml +**/.idea/**/dynamic.xml + +# Rider +# Rider auto-generates .iml files, and contentModel.xml +**/.idea/**/*.iml +**/.idea/**/contentModel.xml +**/.idea/**/modules.xml + +*.suo +*.user +.vs/ +[Bb]in/ +[Oo]bj/ +_UpgradeReport_Files/ +[Pp]ackages/ + +Thumbs.db +Desktop.ini +.DS_Store +.idea/ \ No newline at end of file diff --git a/BetterPolus.sln b/BetterPolus.sln new file mode 100644 index 0000000..0fd231b --- /dev/null +++ b/BetterPolus.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterPolus", "BetterPolus\BetterPolus.csproj", "{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/BetterPolus/BetterPolus.csproj b/BetterPolus/BetterPolus.csproj new file mode 100644 index 0000000..fcfef87 --- /dev/null +++ b/BetterPolus/BetterPolus.csproj @@ -0,0 +1,21 @@ + + + netstandard2.1 + 1.0.0 + 2020.12.9s + NuclearPowered/Mappings:0.1.0-alpha.2 + + Mod allowing some enhancements in Polus Map + Brybry + + + + + + + + + + + + \ No newline at end of file diff --git a/BetterPolus/BetterPolusPlugin.cs b/BetterPolus/BetterPolusPlugin.cs new file mode 100644 index 0000000..0aacec0 --- /dev/null +++ b/BetterPolus/BetterPolusPlugin.cs @@ -0,0 +1,26 @@ +using BepInEx; +using BepInEx.IL2CPP; +using BepInEx.Logging; +using HarmonyLib; +using Reactor; + +namespace BetterPolus +{ + [BepInPlugin(Id)] + [BepInProcess("Among Us.exe")] + [BepInDependency(ReactorPlugin.Id)] + public class BetterPolusPlugin : BasePlugin + { + public const string Id = "ch.brybry.betterpolus"; + + public Harmony Harmony { get; } = new Harmony(Id); + public static ManualLogSource Logger; + + + public override void Load() + { + Logger = Log; + Harmony.PatchAll(); + } + } +} diff --git a/BetterPolus/ShipStatusPatch.cs b/BetterPolus/ShipStatusPatch.cs new file mode 100644 index 0000000..86fc7b8 --- /dev/null +++ b/BetterPolus/ShipStatusPatch.cs @@ -0,0 +1,278 @@ +using System.Linq; +using HarmonyLib; +using UnityEngine; + +namespace BetterPolus +{ + [HarmonyPatch(typeof(ShipStatus))] + public static class ShipStatusPatch + { + // Positions + public static readonly Vector3 DvdScreenNewPos = new Vector3(26.635f, -15.92f, 1f); + public static readonly Vector3 VitalsNewPos = new Vector3(30.255f, -6.66f, 1f); + public static readonly Vector3 WifiNewPos = new Vector3(15.975f, 0.084f, 1f); + public static readonly Vector3 NavNewPos = new Vector3(11.07f, -15.298f, -0.015f); + + // Scales + public const float DvdScreenNewScale = 0.75f; + public const float VitalsNewScale = 1.05f; + + // Checks + public static bool IsObjectsFetched; + public static bool IsAdjustmentsDone; + public static bool IsVentsFetched; + + // Tasks Tweak + public static Console WifiConsole; + public static Console NavConsole; + + // Vitals Tweak + public static SystemConsole Vitals; + public static GameObject WeatherMap; + public static GameObject DvdScreenOffice; + + // Vents Tweak + public static Vent ElectricBuildingVent; + public static Vent ElectricalVent; + public static Vent ScienceBuildingVent; + public static Vent StorageVent; + + [HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.Begin))] + public static class ShipStatusBeginPatch + { + [HarmonyPrefix] + [HarmonyPatch] + public static void Prefix(ShipStatus __instance) + { + ApplyChanges(__instance); + } + } + + [HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.Awake))] + public static class ShipStatusAwakePatch + { + [HarmonyPrefix] + [HarmonyPatch] + public static void Prefix(ShipStatus __instance) + { + ApplyChanges(__instance); + } + } + + [HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.FixedUpdate))] + public static class ShipStatusFixedUpdatePatch + { + [HarmonyPrefix] + [HarmonyPatch] + public static void Prefix(ShipStatus __instance) + { + if (!IsObjectsFetched || !IsAdjustmentsDone) + { + ApplyChanges(__instance); + } + } + } + + public static void ApplyChanges(ShipStatus instance) + { + if (instance.Type == ShipStatus.MapType.Pb) + { + FindPolusObjects(); + AdjustPolus(); + } + } + + public static void AdjustPolus() + { + MoveVitals(); + SwitchNavWifi(); + AdjustVents(); + + IsAdjustmentsDone = true; + } + + // -------------------- + // - Objects Fetching - + // -------------------- + + public static void FindVents() + { + BetterPolusPlugin.Logger.LogMessage("Fetching Vent Objects"); + + var ventsList = Object.FindObjectsOfType().ToList(); + + if (ElectricBuildingVent == null) + { + ElectricBuildingVent = ventsList.Find(vent => vent.gameObject.name == "ElectricBuildingVent"); + } + + if (ElectricalVent == null) + { + ElectricalVent = ventsList.Find(vent => vent.gameObject.name == "ElectricalVent"); + } + + if (ScienceBuildingVent == null) + { + ScienceBuildingVent = ventsList.Find(vent => vent.gameObject.name == "ScienceBuildingVent"); + } + + if (StorageVent == null) + { + StorageVent = ventsList.Find(vent => vent.gameObject.name == "StorageVent"); + } + + IsVentsFetched = ElectricBuildingVent != null && ElectricalVent != null && ScienceBuildingVent != null && + StorageVent != null; + } + + public static void FindPolusObjects() + { + + FindVents(); + + // if (Comms == null) + // { + // Comms = Object.FindObjectsOfType().ToList().Find(o => o.name == "Comms"); + // } + // + // if (DropShip == null) + // { + // DropShip = Object.FindObjectsOfType().ToList().Find(o => o.name == "Dropship"); + // } + + if (WifiConsole == null) + { + BetterPolusPlugin.Logger.LogMessage("Fetching WifiConsole Object"); + WifiConsole = Object.FindObjectsOfType().ToList() + .Find(console => console.name == "panel_wifi"); + } + + if (NavConsole == null) + { + BetterPolusPlugin.Logger.LogMessage("Fetching NavConsole Object"); + NavConsole = Object.FindObjectsOfType().ToList() + .Find(console => console.name == "panel_nav"); + } + + if (Vitals == null) + { + BetterPolusPlugin.Logger.LogMessage("Fetching Vitals Object"); + Vitals = Object.FindObjectsOfType().ToList() + .Find(console => console.name == "panel_vitals"); + } + + if (WeatherMap == null) + { + BetterPolusPlugin.Logger.LogMessage("Fetching WeatherMap Object"); + WeatherMap = Object.FindObjectsOfType().ToList() + .Find(o => o.name == "Weathermap0001"); + } + + if (DvdScreenOffice == null) + { + BetterPolusPlugin.Logger.LogMessage("Fetching DvdScreenAdmin Object"); + GameObject DvdScreenAdmin = Object.FindObjectsOfType().ToList() + .Find(o => o.name == "dvdscreen"); + + if (DvdScreenAdmin != null) + { + BetterPolusPlugin.Logger.LogMessage("Creating DvdScreenOffice Object"); + DvdScreenOffice = Object.Instantiate(DvdScreenAdmin); + } + } + + IsObjectsFetched = WifiConsole != null && NavConsole != null && Vitals != null && WeatherMap != null && + DvdScreenOffice != null; + } + + // ------------------- + // - Map Adjustments - + // ------------------- + + public static void AdjustVents() + { + if (IsVentsFetched) + { + BetterPolusPlugin.Logger.LogMessage("Adjusting Vents"); + + ElectricBuildingVent.Left = ElectricalVent; + ElectricalVent.Center = ElectricBuildingVent; + + ScienceBuildingVent.Left = StorageVent; + StorageVent.Center = ScienceBuildingVent; + } + else + { + BetterPolusPlugin.Logger.LogError("Couldn't adjust Vents as not all objects have been fetched."); + } + } + + public static void SwitchNavWifi() + { + if (IsObjectsFetched) + { + if (WifiConsole.transform.position != WifiNewPos) + { + BetterPolusPlugin.Logger.LogMessage("Moving Wifi to Dropship"); + Transform wifiTransform = WifiConsole.transform; + wifiTransform.position = WifiNewPos; + WifiConsole.Room = SystemTypes.Dropship; + } + + if (NavConsole.transform.position != NavNewPos) + { + BetterPolusPlugin.Logger.LogMessage("Moving Nav to Comms"); + Transform navTransform = NavConsole.transform; + navTransform.position = NavNewPos; + NavConsole.Room = SystemTypes.Comms; + } + } + else + { + BetterPolusPlugin.Logger.LogError("Couldn't Switch Nav & Wifi as not all objects have been fetched."); + } + } + + public static void MoveVitals() + { + if (IsObjectsFetched) + { + if (Vitals.transform.position != VitalsNewPos) + { + // Vitals + BetterPolusPlugin.Logger.LogMessage("Moving Vitals to Laboratory"); + Transform vitalsTransform = Vitals.gameObject.transform; + vitalsTransform.position = VitalsNewPos; + var localScale = vitalsTransform.localScale; + localScale = + new Vector3(VitalsNewScale, localScale.y, localScale.z); + vitalsTransform.localScale = localScale; + } + + if (WeatherMap.active) + { + // WeatherMap + BetterPolusPlugin.Logger.LogMessage("Deactivating WeatherMap"); + WeatherMap.SetActive(false); + } + + if (DvdScreenOffice.transform.position != DvdScreenNewPos) + { + // DvdScreen + BetterPolusPlugin.Logger.LogMessage("Moving DvdScreenOffice"); + Transform dvdScreenTransform = DvdScreenOffice.transform; + dvdScreenTransform.position = DvdScreenNewPos; + var localScale = dvdScreenTransform.localScale; + localScale = + new Vector3(DvdScreenNewScale, localScale.y, + localScale.z); + dvdScreenTransform.localScale = localScale; + } + } + else + { + BetterPolusPlugin.Logger.LogError("Couldn't move Vitals as not all objects have been fetched."); + } + } + } +} \ No newline at end of file