diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 48889b7..37943bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,12 +6,12 @@ jobs: build: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 6.x @@ -20,7 +20,7 @@ jobs: with: verbosity: Diagnostic - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: SmolMod.dll path: SmolMod/bin/Release/net6.0/SmolMod.dll diff --git a/.gitignore b/.gitignore index 7efe594..99ee102 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ .vs .idea bin -obj \ No newline at end of file +obj +*.user +*.DotSettings \ No newline at end of file diff --git a/SmolMod/Extensions.cs b/SmolMod/Extensions.cs deleted file mode 100644 index 78e6c8d..0000000 --- a/SmolMod/Extensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using UnityEngine; - -namespace SmolMod; - -public static class Extensions -{ - public static Transform AdjustScale(this Transform transform, float scaleMod) - { - transform.localScale *= scaleMod; - return transform; - } - - public static Transform AdjustPosition(this Transform transform, float scaleMod) - { - var pos = transform.localPosition; - transform.localPosition = new Vector3(pos.x, pos.y, pos.z * scaleMod); - return transform; - } -} \ No newline at end of file diff --git a/SmolMod/Patches/AirShipPatches.cs b/SmolMod/Patches/AirShipPatches.cs deleted file mode 100644 index 73184d6..0000000 --- a/SmolMod/Patches/AirShipPatches.cs +++ /dev/null @@ -1,69 +0,0 @@ -using HarmonyLib; -using UnityEngine; - -namespace SmolMod.Patches; - -public static class AirShipPatches -{ - // Adjust spawn positions on airship - [HarmonyPatch(typeof(SpawnInMinigame), nameof(SpawnInMinigame.Begin))] - public static class AirShipSpawnGamePatch - { - public static void Postfix(SpawnInMinigame __instance) - { - foreach (var location in __instance.Locations) - { - location.Location *= SmolModPlugin.ScaleMod; - } - } - } - - // Replace hardcoded 3f with scaled value - [HarmonyPatch(typeof(MovingPlatformBehaviour), nameof(MovingPlatformBehaviour.Use), typeof(PlayerControl))] - public static class MovingPlatformPatch - { - public static bool Prefix(MovingPlatformBehaviour __instance, PlayerControl player) - { - var vector = __instance.transform.position - player.transform.position; - if (player.Data.IsDead || player.Data.Disconnected) - { - return false; - } - if (__instance.Target || vector.magnitude > 3f * SmolModPlugin.ScaleMod) - { - return false; - } - __instance.IsDirty = true; - __instance.StartCoroutine(__instance.UsePlatform(player)); - - return false; - } - } - - // Replace Platform CanUse hardcoded 2f with scaled value - [HarmonyPatch(typeof(PlatformConsole), nameof(PlatformConsole.CanUse))] - public static class PlatformConsolePatch - { - public static bool Prefix(PlatformConsole __instance, GameData.PlayerInfo pc, ref float __result, ref bool canUse, ref bool couldUse) - { - var num = float.MaxValue; - var @object = pc.Object; - couldUse = !pc.IsDead && - @object.CanMove && - !__instance.Platform.InUse && - Vector2.Distance(__instance.Platform.transform.position, __instance.transform.position) < 2f * SmolModPlugin.ScaleMod; - canUse = couldUse; - if (canUse) - { - var truePosition = @object.GetTruePosition(); - var position = __instance.transform.position; - num = Vector2.Distance(truePosition, position); - canUse &= num <= __instance.UsableDistance && !PhysicsHelpers.AnythingBetween(truePosition, position, Constants.ShipOnlyMask, false); - } - __result = num; - - - return false; - } - } -} \ No newline at end of file diff --git a/SmolMod/Patches/HudStartPatch.cs b/SmolMod/Patches/HudStartPatch.cs new file mode 100644 index 0000000..c79ae08 --- /dev/null +++ b/SmolMod/Patches/HudStartPatch.cs @@ -0,0 +1,50 @@ +using HarmonyLib; +using UnityEngine; + +namespace SmolMod.Patches; + +// adapted from https://github.com/Among-Us-Modding/Laboratory/blob/main/Laboratory/Utilities/CameraZoomController.cs +[HarmonyPatch(typeof(HudManager),nameof(HudManager.Start))] +public static class HudStartPatch +{ + private static ShadowCollab _shadowCollab; + private static Camera _cam; + private static float _defaultOrthographicSize; + + public static void Postfix(HudManager __instance) + { + _shadowCollab = Object.FindObjectOfType(); + _shadowCollab.StopAllCoroutines(); + + HudManager.Instance.FullScreen.transform.localScale *= 50; + + var mainCam = Camera.main!; + + GameObject newCamObj = new("ZoomCamera"); + var newCamTransform = newCamObj.transform; + newCamTransform.parent = mainCam.transform; + newCamTransform.localPosition = new Vector3(0, 0, 0); + newCamTransform.localScale = new Vector3(1, 1, 1); + + _cam = newCamObj.AddComponent(); + _cam.CopyFrom(mainCam); + _cam.depth += 1; + mainCam.ResetReplacementShader(); + + _defaultOrthographicSize = _cam.orthographicSize; + + UpdateSize(); + } + + public static void UpdateSize() + { + if (!_shadowCollab || !_cam) + { + return; + } + + _shadowCollab.ShadowCamera.aspect = _cam.aspect; + var val = _shadowCollab.ShadowCamera.orthographicSize = _cam.orthographicSize = _defaultOrthographicSize / SmolModPlugin.ScaleMod; + _shadowCollab.ShadowQuad.transform.localScale = new Vector3(val * _cam.aspect, val) * 2f; + } +} \ No newline at end of file diff --git a/SmolMod/Patches/LobbySizePatch.cs b/SmolMod/Patches/LobbySizePatch.cs deleted file mode 100644 index bdd5c96..0000000 --- a/SmolMod/Patches/LobbySizePatch.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Make the lobby bigger and adjust spawn positions - -using HarmonyLib; - -namespace SmolMod.Patches; - -[HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.Start))] -public static class LobbySizePatch -{ - public static void Postfix(LobbyBehaviour __instance) - { - __instance.transform.AdjustScale(SmolModPlugin.ScaleMod).AdjustPosition(SmolModPlugin.ScaleMod); - - for (var i = 0; i < __instance.SpawnPositions.Count; i++) - { - __instance.SpawnPositions[i] *= SmolModPlugin.ScaleMod; - } - } -} \ No newline at end of file diff --git a/SmolMod/Patches/NetworkPatches.cs b/SmolMod/Patches/NetworkPatches.cs deleted file mode 100644 index 1edbaf9..0000000 --- a/SmolMod/Patches/NetworkPatches.cs +++ /dev/null @@ -1,23 +0,0 @@ -using HarmonyLib; -using UnityEngine; - -namespace SmolMod.Patches; - -// Patch Vector2 network operations to support players without the mod -[HarmonyPatch(typeof(NetHelpers))] -public static class NetworkPatches -{ - [HarmonyPrefix] - [HarmonyPatch(nameof(NetHelpers.WriteVector2))] - public static void WriteVector2Prefix(ref Vector2 vec) - { - vec /= SmolModPlugin.ScaleMod; - } - - [HarmonyPostfix] - [HarmonyPatch(nameof(NetHelpers.ReadVector2))] - public static void ReadVector2Prefix(ref Vector2 __result) - { - __result *= SmolModPlugin.ScaleMod; - } -} \ No newline at end of file diff --git a/SmolMod/Patches/PlayerControlPatch.cs b/SmolMod/Patches/PlayerControlPatch.cs new file mode 100644 index 0000000..47c13a6 --- /dev/null +++ b/SmolMod/Patches/PlayerControlPatch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using UnityEngine; + +namespace SmolMod.Patches; + +[HarmonyPatch(typeof(PlayerControl),nameof(PlayerControl.Start))] +public static class PlayerControlPatch +{ + // adapted from https://github.com/Among-Us-Modding/Laboratory/blob/main/Laboratory/Player/SizeModifier.cs + private static readonly Vector3 DefaultSize = new (0.7f, 0.7f, 1f); + + public static void Postfix(PlayerControl __instance) + { + __instance.UpdateSize(); + } + + public static void UpdateSize(this PlayerControl player) + { + var size = DefaultSize / SmolModPlugin.ScaleMod; + + player.Collider.Cast().radius = 0.2233912f / (size.x / DefaultSize.x); + player.transform.localScale = size; + } +} \ No newline at end of file diff --git a/SmolMod/Patches/PlayerPatches.cs b/SmolMod/Patches/PlayerPatches.cs deleted file mode 100644 index 73a8340..0000000 --- a/SmolMod/Patches/PlayerPatches.cs +++ /dev/null @@ -1,38 +0,0 @@ -using HarmonyLib; - -namespace SmolMod.Patches; - -public static class PlayerPatches -{ - // Multiply local player speed and max report distance by Scale Modifier - // This works with the CustomNetworkTransform patches to add compatibility with users who don't have the mod - [HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.Start))] - public static class PlayerReportPatch - { - public static void Postfix(PlayerControl __instance) - { - __instance.MaxReportDistance *= SmolModPlugin.ScaleMod; - __instance.MyPhysics.Speed *= SmolModPlugin.ScaleMod; - } - } - - // Multiply light source distance by ScaleMod - [HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.CalculateLightRadius))] - public static class PlayerLightPatch - { - public static void Postfix(ref float __result) - { - __result *= SmolModPlugin.ScaleMod; - } - } - - // Make pets bigger to make the players look smaller - [HarmonyPatch(typeof(PetBehaviour), nameof(PetBehaviour.Start))] - public static class PetSizePatch - { - public static void Postfix(PetBehaviour __instance) - { - __instance.transform.AdjustScale(SmolModPlugin.ScaleMod); - } - } -} \ No newline at end of file diff --git a/SmolMod/Patches/ShipSizePatch.cs b/SmolMod/Patches/ShipSizePatch.cs deleted file mode 100644 index 0a4a2e0..0000000 --- a/SmolMod/Patches/ShipSizePatch.cs +++ /dev/null @@ -1,79 +0,0 @@ -using HarmonyLib; -using UnityEngine; - -namespace SmolMod.Patches; - -public static class ShipPatches -{ - // for some reason, using TargetMethods crashes the game. - // patch UsableDistance getters for IUsables without a usableDistance field. - [HarmonyPatch(typeof(DoorConsole), "UsableDistance", MethodType.Getter)] - [HarmonyPatch(typeof(Ladder), "UsableDistance", MethodType.Getter)] - [HarmonyPatch(typeof(OptionsConsole), "UsableDistance", MethodType.Getter)] - [HarmonyPatch(typeof(Vent), "UsableDistance", MethodType.Getter)] - public static class UsableDistancePatch - { - public static void Postfix(ref float __result) - { - __result *= SmolModPlugin.ScaleMod; - } - } - - // Adjust ShipStatus size, MapScale, Spawn Radius, Spawn Centers, and IUsables with usableDistance fields - [HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.Start))] - public static class ShipSizePatch - { - public static void Postfix(ShipStatus __instance) - { - var scaleMod = SmolModPlugin.ScaleMod; - - __instance.transform.AdjustScale(scaleMod).AdjustPosition(scaleMod); - __instance.MapScale *= scaleMod; - __instance.SpawnRadius *= scaleMod; - __instance.InitialSpawnCenter *= scaleMod; - __instance.MeetingSpawnCenter *= scaleMod; - __instance.MeetingSpawnCenter2 *= scaleMod; - - foreach (var t in __instance.DummyLocations) - { - t.AdjustPosition(scaleMod); - } - - // feel free to find a better way to do this and PR it for me thx! - foreach (var console in Object.FindObjectsOfType(true)) - { - console.usableDistance *= scaleMod; - } - - foreach (var deconControl in Object.FindObjectsOfType(true)) - { - deconControl.usableDistance *= scaleMod; - } - - foreach (var mapConsole in Object.FindObjectsOfType(true)) - { - mapConsole.usableDistance *= scaleMod; - } - - foreach (var openDoorConsole in Object.FindObjectsOfType(true)) - { - openDoorConsole.usableDisance *= scaleMod; - } - - foreach (var platformConsole in Object.FindObjectsOfType(true)) - { - platformConsole.usableDistance *= scaleMod; - } - - foreach (var systemConsole in Object.FindObjectsOfType(true)) - { - systemConsole.usableDistance *= scaleMod; - } - - foreach (var ziplineConsole in Object.FindObjectsOfType(true)) - { - ziplineConsole.usableDistance *= scaleMod; - } - } - } -} diff --git a/SmolMod/Patches/ZiplinePatch.cs b/SmolMod/Patches/ZiplinePatch.cs deleted file mode 100644 index fedceda..0000000 --- a/SmolMod/Patches/ZiplinePatch.cs +++ /dev/null @@ -1,14 +0,0 @@ -using HarmonyLib; - -namespace SmolMod.Patches; - -// Fix zipline locations -[HarmonyPatch(typeof(ZiplineBehaviour), nameof(ZiplineBehaviour.Awake))] -public static class ZiplinePatch -{ - public static void Prefix(ZiplineBehaviour __instance) - { - __instance.landingPositionTop.position /= SmolModPlugin.ScaleMod; - __instance.landingPositionBottom.position /= SmolModPlugin.ScaleMod; - } -} \ No newline at end of file diff --git a/SmolMod/SmolModPlugin.cs b/SmolMod/SmolModPlugin.cs index ad20c57..d9bc19f 100644 --- a/SmolMod/SmolModPlugin.cs +++ b/SmolMod/SmolModPlugin.cs @@ -3,6 +3,7 @@ using BepInEx.Configuration; using BepInEx.Unity.IL2CPP; using HarmonyLib; +using SmolMod.Patches; using UnityEngine.SceneManagement; namespace SmolMod; @@ -22,7 +23,20 @@ public override void Load() ConfigScale = Config.Bind("Scale", "GlobalModifier", 1.5f, "Scale modifier used for SmolMod scaling"); Harmony.PatchAll(); - // taken out of reactor, but this mod doesn't depend on reactor, so that's why its here + ConfigScale.SettingChanged += (_, _) => + { + if (HudManager.InstanceExists) + { + HudStartPatch.UpdateSize(); + } + + foreach (var player in PlayerControl.AllPlayerControls) + { + player.UpdateSize(); + } + }; + + // taken out of reactor, but this mod doesn't depend on reactor, so that's why it's here SceneManager.add_sceneLoaded((Action) ((scene, _) => { if (scene.name == "MainMenu")