Rain World

Rain World

Downpour: Watcher Region Access
Timeline Switching Bug Fix
I trimmed down my code. I have not tested this yet, but I give it a 75% chance of working. If your mod already implements some plugins, then you hopefully can copy/paste parts of this into your mod. ...However, I have a feeling that you might not have the codebase set up.

I'm realizing that you almost certainly don't want to have to bother with this. I think I'll make this a full mod, and then you can either copy/paste the .dll, or you can make my mod a dependency. Or any other option; I don't care. I put MIT licenses on all my mods.

using System; using System.Security; using System.Security.Permissions; using BepInEx; using Watcher; using MoreSlugcats; #pragma warning disable CS0618 [module: UnverifiableCode] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] namespace WarpTimelineFix; [BepInPlugin(MOD_ID, MOD_NAME, MOD_VERSION)] public partial class Plugin : BaseUnityPlugin { public const string MOD_ID = "WarpTimelineFix", MOD_NAME = "Warp Timeline Fix", MOD_VERSION = "0.0.1"; #region Setup public Plugin() {} private void OnEnable() { On.RainWorld.OnModsInit += RainWorldOnOnModsInit; } private void OnDisable() { On.RainWorld.OnModsInit -= RainWorldOnOnModsInit; if (IsInit) { On.OverWorld.InitiateSpecialWarp_WarpPoint -= OverWorld_InitiateSpecialWarp_WarpPoint; On.OverWorld.Update -= OverWorld_Update; On.Watcher.WarpPoint.PerformWarp -= WarpPoint_PerformWarp; IsInit = false; } } private bool IsInit; private void RainWorldOnOnModsInit(On.RainWorld.orig_OnModsInit orig, RainWorld self) { orig(self); try { if (IsInit) return; //Warps On.OverWorld.InitiateSpecialWarp_WarpPoint += OverWorld_InitiateSpecialWarp_WarpPoint; On.OverWorld.Update += OverWorld_Update; On.Watcher.WarpPoint.PerformWarp += WarpPoint_PerformWarp; Logger.LogDebug("Applied hooks"); } catch (Exception ex) { Logger.LogError(ex); throw; } } #endregion #region WarpLogic //FIRST STEP: stop the base game from switching timelines too early private void OverWorld_InitiateSpecialWarp_WarpPoint(On.OverWorld.orig_InitiateSpecialWarp_WarpPoint orig, OverWorld self, ISpecialWarp callback, WarpPoint.WarpPointData warpData, bool useNormalWarpLoader) { SlugcatStats.Timeline source = self.game.TimelinePoint, dest = warpData.destTimeline; orig(self, callback, warpData, useNormalWarpLoader); try { warpData.destTimeline = dest; self.game.GetStorySession.saveState.currentTimelinePosition = source; Logger.LogDebug($"Aborted switching timelines. Current timelines: source={source}, dest={dest}"); } catch (Exception ex) { Logger.LogError(ex); } } //MIDDLE STEP: ensure that the world loader uses the correct timeline when pre-loading a warp private void OverWorld_Update(On.OverWorld.orig_Update orig, OverWorld self) { try { if (self.warpingPreload && Region.RegionReadyToWarp) { var save = self.game.GetStorySession.saveState; var source = save.currentTimelinePosition; save.currentTimelinePosition = self.warpData.destTimeline; orig(self); save.currentTimelinePosition = source; Logger.LogDebug($"Loading warp world loader using timeline {self.warpData.destTimeline} instead of {source}"); return; } } catch (Exception ex) { Logger.LogError(ex); } orig(self); } //FINAL STEP: correctly set the timeline at the END of the warp private void WarpPoint_PerformWarp(On.Watcher.WarpPoint.orig_PerformWarp orig, WarpPoint self) { orig(self); try { self.room.game.GetStorySession.saveState.currentTimelinePosition = self.Data.destTimeline; Logger.LogDebug("Warping to timeline " + self.Data.destTimeline); } catch (Exception ex) { Logger.LogError(ex); } } #endregion }
< >
Showing 1-3 of 3 comments
If you want to just add this plugin to your mod (so it doesn't have to be downloaded as a separate dependency), you can find it here: https://github.com/TheLazyCowboy1/WarpTimelineFix/tree/master/WarpTimelineFix/plugins
You can hopefully then download it, and make a folder called "plugins" in your mod (if it doesn't already exist), and add the .dll to it.

...If my code even works. I'm not sure that it does yet...
Alice  [developer] 15 hours ago 
I was actually busy and just now saw this. I Don't have anything else to do right now so I'll test it out lol
Alice  [developer] 14 hours ago 
After a quick test the code is functional, I really Appreciate you letting me steal your code lol :steamthumbsup:
< >
Showing 1-3 of 3 comments
Per page: 1530 50