From 78e5901c9384a574b8ca6fac50b503203094c4fc Mon Sep 17 00:00:00 2001 From: AureumApes Date: Mon, 25 Dec 2023 01:33:34 +0100 Subject: [PATCH] Fix a commonly reported bug, which caused falling through map --- SRMP/Patches/Patch_Region.cs | 170 +++++++++++++++++++++++++++++++++++ SRMP/SRMP.cs | 163 --------------------------------- 2 files changed, 170 insertions(+), 163 deletions(-) diff --git a/SRMP/Patches/Patch_Region.cs b/SRMP/Patches/Patch_Region.cs index e5183ac..7c7dee2 100644 --- a/SRMP/Patches/Patch_Region.cs +++ b/SRMP/Patches/Patch_Region.cs @@ -4,6 +4,7 @@ using SRMultiplayer.Networking; using SRMultiplayer.Packets; using System; using System.Collections.Generic; + using System.Linq; using System.Text; using UnityEngine; @@ -38,6 +39,175 @@ namespace SRMultiplayer.Patches } } } + [HarmonyPatch(typeof(Region))] + [HarmonyPatch("Awake")] + class Region_Awake + { + static void Postfix(Region __instance) + { + var netRegion = __instance.gameObject.AddComponent(); + netRegion.ID = __instance.gameObject.GetGameObjectPath().GetHashCode(); + netRegion.Region = __instance; + netRegion.FastForwarder = __instance.gameObject.GetComponent(); + + Globals.Regions.Add(netRegion.ID, netRegion); + + + foreach (var landPlotLocation in __instance.gameObject.GetComponentsInChildren(true)) + { + var netLandplot = landPlotLocation.gameObject.GetOrAddComponent(); + netLandplot.Plot = landPlotLocation.GetComponentInChildren(true); + netLandplot.Location = landPlotLocation; + netLandplot.Region = netRegion; + + Globals.LandPlots.Add(netLandplot.Location.id, netLandplot); + } + + foreach (var accessDoor in __instance.gameObject.GetComponentsInChildren(true)) + { + var netAccessDoor = accessDoor.gameObject.GetOrAddComponent(); + netAccessDoor.Door = accessDoor; + netAccessDoor.Region = netRegion; + + Globals.AccessDoors.Add(accessDoor.id, netAccessDoor); + } + + foreach (var gordo in __instance.gameObject.GetComponentsInChildren(true)) + { + var netGordo = gordo.gameObject.GetOrAddComponent(); + netGordo.Gordo = gordo; + netGordo.Region = netRegion; + + Globals.Gordos.Add(netGordo.ID, netGordo); + } + + foreach (var puzzleSlot in __instance.gameObject.GetComponentsInChildren(true)) + { + var netPuzzleSlot = puzzleSlot.gameObject.GetOrAddComponent(); + netPuzzleSlot.Slot = puzzleSlot; + netPuzzleSlot.Region = netRegion; + + Globals.PuzzleSlots.Add(puzzleSlot.id, netPuzzleSlot); + } + + foreach (var masterSwitch in __instance.gameObject.GetComponentsInChildren(true)) + { + var netSwitch = masterSwitch.gameObject.GetOrAddComponent(); + netSwitch.Switch = masterSwitch; + netSwitch.Region = netRegion; + + Globals.Switches.Add(masterSwitch.id, netSwitch); + } + + foreach (var gadgetSite in __instance.gameObject.GetComponentsInChildren(true)) + { + var netGadgetSite = gadgetSite.gameObject.GetOrAddComponent(); + netGadgetSite.Site = gadgetSite; + netGadgetSite.Region = netRegion; + + Globals.GadgetSites.Add(gadgetSite.id, netGadgetSite); + } + + foreach (var treaturePod in __instance.gameObject.GetComponentsInChildren(true)) + { + var netTreasurePod = treaturePod.gameObject.GetOrAddComponent(); + netTreasurePod.Pod = treaturePod; + netTreasurePod.Region = netRegion; + + Globals.TreasurePods.Add(treaturePod.id, netTreasurePod); + } + + foreach (var spawner in __instance.gameObject.GetComponentsInChildren(true)) + { + var netSpawner = spawner.gameObject.GetOrAddComponent(); + netSpawner.ID = spawner.gameObject.GetGameObjectPath().GetHashCode(); + netSpawner.Spawner = spawner; + netSpawner.Region = netRegion; + + Globals.Spawners.Add(netSpawner.ID, netSpawner); + } + + foreach (var exchangeAcceptor in __instance.gameObject.GetComponentsInChildren(true)) + { + var netAcceptor = exchangeAcceptor.gameObject.GetOrAddComponent(); + netAcceptor.ID = exchangeAcceptor.gameObject.GetGameObjectPath().GetHashCode(); + netAcceptor.Acceptor = exchangeAcceptor; + netAcceptor.Region = netRegion; + + Globals.ExchangeAcceptors.Add(netAcceptor.ID, netAcceptor); + } + + foreach (var fireColumn in __instance.gameObject.GetComponentsInChildren(true)) + { + var netColumn = fireColumn.gameObject.GetOrAddComponent(); + netColumn.ID = fireColumn.gameObject.GetGameObjectPath().GetHashCode(); + netColumn.Column = fireColumn; + netColumn.Region = netRegion; + + Globals.FireColumns.Add(netColumn.ID, netColumn); + } + + foreach (var kookadobaPatchNode in __instance.gameObject.GetComponentsInChildren(true)) + { + var netNode = kookadobaPatchNode.gameObject.GetOrAddComponent(); + netNode.ID = kookadobaPatchNode.gameObject.GetGameObjectPath().GetHashCode(); + netNode.Node = kookadobaPatchNode; + netNode.Region = netRegion; + + Globals.Kookadobas.Add(netNode.ID, netNode); + } + + foreach (var nutcracker in __instance.gameObject.GetComponentsInChildren(true)) + { + var netCracker = nutcracker.gameObject.GetOrAddComponent(); + netCracker.ID = nutcracker.gameObject.GetGameObjectPath().GetHashCode(); + netCracker.Cracker = nutcracker; + + Globals.Nutcrackers.Add(netCracker.ID, netCracker); + } + + foreach (var trigger in __instance.gameObject.GetComponentsInChildren(true)) + { + var netTrigger = trigger.gameObject.GetOrAddComponent(); + netTrigger.ID = trigger.gameObject.GetGameObjectPath().GetHashCode(); + netTrigger.Ammo = trigger; + + Globals.RaceTriggers.Add(netTrigger.ID, netTrigger); + } + + foreach (var trigger in __instance.gameObject.GetComponentsInChildren(true)) + { + var netTrigger = trigger.gameObject.GetOrAddComponent(); + netTrigger.ID = trigger.gameObject.GetGameObjectPath().GetHashCode(); + netTrigger.Checkpoint = trigger; + + Globals.RaceTriggers.Add(netTrigger.ID, netTrigger); + } + + foreach (var trigger in __instance.gameObject.GetComponentsInChildren(true)) + { + var netTrigger = trigger.gameObject.GetOrAddComponent(); + netTrigger.ID = trigger.gameObject.GetGameObjectPath().GetHashCode(); + netTrigger.Energy = trigger; + + Globals.RaceTriggers.Add(netTrigger.ID, netTrigger); + } + + foreach (var spawnResource in __instance.gameObject.GetComponentsInChildren(true)) + { + var netSpawnResource = spawnResource.gameObject.GetOrAddComponent(); + netSpawnResource.ID = spawnResource.gameObject.GetGameObjectPath().GetHashCode(); + netSpawnResource.SpawnResource = spawnResource; + netSpawnResource.Region = netRegion; + netSpawnResource.LandPlot = spawnResource.GetComponentInParent(true); + + if (!Globals.SpawnResources.ContainsKey(netSpawnResource.ID)) + { + Globals.SpawnResources.Add(netSpawnResource.ID, netSpawnResource); + } + } + } + } [HarmonyPatch(typeof(Region))] [HarmonyPatch("Unproxy")] diff --git a/SRMP/SRMP.cs b/SRMP/SRMP.cs index 7cb7b5c..dc2132a 100644 --- a/SRMP/SRMP.cs +++ b/SRMP/SRMP.cs @@ -215,169 +215,6 @@ namespace SRMultiplayer Globals.FXPrefabs.Add(splashOnTrigger.playerSplashFX.name, splashOnTrigger.playerSplashFX); Globals.FXPrefabs.Add(splashOnTrigger.splashFX.name, splashOnTrigger.splashFX); - foreach (var region in Resources.FindObjectsOfTypeAll()) - { - var netRegion = region.gameObject.AddComponent(); - netRegion.ID = region.gameObject.GetGameObjectPath().GetHashCode(); - netRegion.Region = region; - netRegion.FastForwarder = region.gameObject.GetComponent(); - - Globals.Regions.Add(netRegion.ID, netRegion); - - foreach(var landPlotLocation in region.gameObject.GetComponentsInChildren(true)) - { - var netLandplot = landPlotLocation.gameObject.GetOrAddComponent(); - netLandplot.Plot = landPlotLocation.GetComponentInChildren(true); - netLandplot.Location = landPlotLocation; - netLandplot.Region = netRegion; - - Globals.LandPlots.Add(netLandplot.Location.id, netLandplot); - } - - foreach (var accessDoor in region.gameObject.GetComponentsInChildren(true)) - { - var netAccessDoor = accessDoor.gameObject.GetOrAddComponent(); - netAccessDoor.Door = accessDoor; - netAccessDoor.Region = netRegion; - - Globals.AccessDoors.Add(accessDoor.id, netAccessDoor); - } - - foreach (var gordo in region.gameObject.GetComponentsInChildren(true)) - { - var netGordo = gordo.gameObject.GetOrAddComponent(); - netGordo.Gordo = gordo; - netGordo.Region = netRegion; - - Globals.Gordos.Add(netGordo.ID, netGordo); - } - - foreach (var puzzleSlot in region.gameObject.GetComponentsInChildren(true)) - { - var netPuzzleSlot = puzzleSlot.gameObject.GetOrAddComponent(); - netPuzzleSlot.Slot = puzzleSlot; - netPuzzleSlot.Region = netRegion; - - Globals.PuzzleSlots.Add(puzzleSlot.id, netPuzzleSlot); - } - - foreach (var masterSwitch in region.gameObject.GetComponentsInChildren(true)) - { - var netSwitch = masterSwitch.gameObject.GetOrAddComponent(); - netSwitch.Switch = masterSwitch; - netSwitch.Region = netRegion; - - Globals.Switches.Add(masterSwitch.id, netSwitch); - } - - foreach (var gadgetSite in region.gameObject.GetComponentsInChildren(true)) - { - var netGadgetSite = gadgetSite.gameObject.GetOrAddComponent(); - netGadgetSite.Site = gadgetSite; - netGadgetSite.Region = netRegion; - - Globals.GadgetSites.Add(gadgetSite.id, netGadgetSite); - } - - foreach (var treaturePod in region.gameObject.GetComponentsInChildren(true)) - { - var netTreasurePod = treaturePod.gameObject.GetOrAddComponent(); - netTreasurePod.Pod = treaturePod; - netTreasurePod.Region = netRegion; - - Globals.TreasurePods.Add(treaturePod.id, netTreasurePod); - } - - foreach (var spawner in region.gameObject.GetComponentsInChildren(true)) - { - var netSpawner = spawner.gameObject.GetOrAddComponent(); - netSpawner.ID = spawner.gameObject.GetGameObjectPath().GetHashCode(); - netSpawner.Spawner = spawner; - netSpawner.Region = netRegion; - - Globals.Spawners.Add(netSpawner.ID, netSpawner); - } - - foreach (var exchangeAcceptor in region.gameObject.GetComponentsInChildren(true)) - { - var netAcceptor = exchangeAcceptor.gameObject.GetOrAddComponent(); - netAcceptor.ID = exchangeAcceptor.gameObject.GetGameObjectPath().GetHashCode(); - netAcceptor.Acceptor = exchangeAcceptor; - netAcceptor.Region = netRegion; - - Globals.ExchangeAcceptors.Add(netAcceptor.ID, netAcceptor); - } - - foreach (var fireColumn in region.gameObject.GetComponentsInChildren(true)) - { - var netColumn = fireColumn.gameObject.GetOrAddComponent(); - netColumn.ID = fireColumn.gameObject.GetGameObjectPath().GetHashCode(); - netColumn.Column = fireColumn; - netColumn.Region = netRegion; - - Globals.FireColumns.Add(netColumn.ID, netColumn); - } - - foreach (var kookadobaPatchNode in region.gameObject.GetComponentsInChildren(true)) - { - var netNode = kookadobaPatchNode.gameObject.GetOrAddComponent(); - netNode.ID = kookadobaPatchNode.gameObject.GetGameObjectPath().GetHashCode(); - netNode.Node = kookadobaPatchNode; - netNode.Region = netRegion; - - Globals.Kookadobas.Add(netNode.ID, netNode); - } - - foreach (var nutcracker in region.gameObject.GetComponentsInChildren(true)) - { - var netCracker = nutcracker.gameObject.GetOrAddComponent(); - netCracker.ID = nutcracker.gameObject.GetGameObjectPath().GetHashCode(); - netCracker.Cracker = nutcracker; - - Globals.Nutcrackers.Add(netCracker.ID, netCracker); - } - - foreach (var trigger in region.gameObject.GetComponentsInChildren(true)) - { - var netTrigger = trigger.gameObject.GetOrAddComponent(); - netTrigger.ID = trigger.gameObject.GetGameObjectPath().GetHashCode(); - netTrigger.Ammo = trigger; - - Globals.RaceTriggers.Add(netTrigger.ID, netTrigger); - } - - foreach (var trigger in region.gameObject.GetComponentsInChildren(true)) - { - var netTrigger = trigger.gameObject.GetOrAddComponent(); - netTrigger.ID = trigger.gameObject.GetGameObjectPath().GetHashCode(); - netTrigger.Checkpoint = trigger; - - Globals.RaceTriggers.Add(netTrigger.ID, netTrigger); - } - - foreach (var trigger in region.gameObject.GetComponentsInChildren(true)) - { - var netTrigger = trigger.gameObject.GetOrAddComponent(); - netTrigger.ID = trigger.gameObject.GetGameObjectPath().GetHashCode(); - netTrigger.Energy = trigger; - - Globals.RaceTriggers.Add(netTrigger.ID, netTrigger); - } - - foreach (var spawnResource in region.gameObject.GetComponentsInChildren(true)) - { - var netSpawnResource = spawnResource.gameObject.GetOrAddComponent(); - netSpawnResource.ID = spawnResource.gameObject.GetGameObjectPath().GetHashCode(); - netSpawnResource.SpawnResource = spawnResource; - netSpawnResource.Region = netRegion; - netSpawnResource.LandPlot = spawnResource.GetComponentInParent(true); - - if (!Globals.SpawnResources.ContainsKey(netSpawnResource.ID)) - { - Globals.SpawnResources.Add(netSpawnResource.ID, netSpawnResource); - } - } - } if (Globals.IsClient) {