File information

Last updated

Original upload

Created by

Janquel and wSkeever

Uploaded by

Janquel

Virus scan

Safe to use

About this mod

Method and dummy example plugin for how a mod author could modify persistent references to your mod's current position and orientation

Requirements
Permissions and credits
Changelogs
HEY EVERYONE, LET'S ALL GO TO PROM



.....okay, not every backronym can be a winner. Moving on.

Description

Keeping the entire previous description in quotes below for posterity (and because I'm not a huge fan of editing stuff out of existence), but unfortunately cases were found which made this tool untenable to recommend in its current format, as there were cases where things which had been altered (locked, unlocked, etc) by quests were being reset to states they shouldn't be thanks to this tool, and....there honestly wasn't a hell of a lot I could do to alter the xEdit script to prevent this from happening.

So instead, I've now taken down the xEdit script. The plugin and papyrus script are both available (so examples of the quest, how one can have the formid list, etc) as a modder's resource, and please, please, please if you're a mod maker who's moving persistent references, feel free to take this and apply it in your mod. But the general use case has too many exceptions which don't really work for me to feel comfortable recommending it any longer.




Background

So everyone knows the common recommendation (or rather, they should): don't change your load order mid-playthrough. Don't install things, don't uninstall things - basically, once you start actually playing, just don't mess with anything. It's a bad idea. We all understand, we get ready to go, we get through Bleak Falls, and then OOH SHINY THING RELEASES ON NEXUS. Still, we follow those guidelines (or at least, we should *stares at the audience until they look away sheepishly* ) Now, for a lot of you, that may be understood, but what might not be is the whys of this. Honestly, it's primarily two things:

  • First off, we have our event triggers. Some stuff, with some mods, only happen with certain event triggers. It could be the start of the game, it could be Unbound being finished. It could be some random quest being completed - without the mod being properly installed when those triggers occur, some script stuff which prepares stuff down the line never occurs, and things spiral until your game breaks. (People who use console commands to get through quests and try to get stuff for Legacy of the Dragonborn? I'm talking about YOU. THIS is why your stuff breaks. Stop doing that *swats with rolled up newspaper* This mod does LITERALLY NOTHING about this. Honestly, it's probably impossible to make a general use mod to help out with this thing, so STOP DOING THAT.
  • Secondly, we have persistent references - it's the thing you always hear me talking about. "Persistent" in this circumstance means "persistent location." Basically, once they're loaded into the game, they're stuck. Everything you see in the game space has a location coordinate (x, y, z - remember geometry? That stuff). Temporary references can move. Persistent references can't. Once they're in, they're baked in. This is because they're referenced by something specific - an NPC's package AI, a Quest, a Script, SOMETHING. The game basically needs to know where they are in order to work. This is how you get stuff missing, or embedded in walls, or whatever - you installed something mid-playthrough, and that THING (the door, the bed, the whatever) stays in its persistent location, while everything else moves around it. Maybe you never ran into this, but something broke and you have no idea why - this is still why. Most of these persistent references are invisible. They're markers for NPCs to move to, or interact with, or things you're supposed to activate.....but their spot is where they were when you started the game, and you installed some random mod 20 hours in, and all of a sudden that stuff is inaccessible and you crash to desktop because an NPC AI package triggered and they couldn't route to the marker.


Basically, when folks say don't mess with stuff mid-save the above is why. Don't do it. Bad dog. No cookie.

So anyway, this mod solves that second scenario, theoretically.

Questions of Varying Frequency

So wait, you're saying I can install mods mid-playthrough now? Awesome!

No! That's a terrible idea! Don't do it!

But you just sai...

Yes, because you and I both know you were going to do it anyway. Don't look at me that way, and don't bullcrap me. This just gives you a fighting chance.

Can I remove mods mid-playthrough?

No! That's a terrible idea! Don't do it!

Oh, I get what you're doing *taps forehead like Roll Safe*

No, seriously. Installing mods is a bad idea which will eventually break your stuff, probably, but removing mods is going to break your game right now unless you know how to properly work surgery on your save files and even then it's still not the best idea. You want to get rid of something? Start your game over. Full stop. Unless it's something you just added (SEE QUESTION ONE, DAMNIT), and you have a recent save you can go back to from before it was installed. That's hunky dory.

Okay, disclaimer taken in and understood. Anything else I should know?

Trying to use this should be thought to "void warranty" on getting debug help from other mod pages. You're knowingly messing with crap. Back up your save, and if stuff goes off the rails later, that's that. Start over, or revert to the backup.

I'm being very candid with this: this thing is doing something the game did not originally intend to do. If you choose to use it, that's on you. Mod makers get bothered with enough requests and questions (and people saying stuff is broken when it's a load order problem or whatever) without even opening up this can of worms. To be quite honest, I'm still, even as I'm typing this, not sure it's a good idea to release it.

This also, as noted, doesn't do jack about the first bullet point above, so don't expect major quest mods, or things that integrate into questlines, to suddenly work for this. Think of it as primarily a tool for messing around with new looks/layouts, more than anything else.

Finally, this isn't intended to be included when you start the game - I put a deadman switch around it such that it's expecting MQ101 (Unbound) to be finished. It's one of the only things I can do to ensure that the teleport-a-thon won't mess with things, so you'll just have to live with that.


Installation
We're looking at a multi-stage process here.

1. Install using a mod manager as per usual. If you're not using one, just close this window.
2. Once it's installed, go to the directory it was installed in and look for an "Edit Scripts" folder. Inside of here is an xEdit script - you'll need to copy that to your xEdit Edit Scripts folder. I'm not going to talk through this process in detail, because....well, frankly given everything I went through in the above scenario, if you don't know what I'm talking about it honestly is probably better for you to avoid this thing and consider it "intermediate to advanced" modding. Just search on Nexus (or click the link below) for xEdit itself, but you've got a little bit of reading to catch up on how all this stuff works.
3. Load up your full load order, with the PersistentRefs.esp loaded last (it can be before your cell settings patch or whatever, that's fine).
4. Apply Scripts > choose persistentrefs. It'll take a little bit, but not super long. It should keep everything in a single patch, but might make a second patch depending on your load order. If this happens, you're a monster and must be stopped. (Seriously, I had a load order with 1000+ plugins I tested and this didn't happen, so if it does for you, you've got some WEIRD CRAP going on. Also, thanks for being a beta tester in that case, I guess).
5. Save, boot your game with the plugin enabled, load your save.
6. Sit and wait (seriously, this will take a bit - don't play while it's running. It'll be a few minutes, and you'll have a series of teleports at the end which will be a good indication it's wrapping up).

....and honestly, that it?

If you have previously installed this, it's run once, and then you re-ran the xEdit script and want to run again, open your game and do the following:
1. Open the console and type "help runmarker". It should bring up a list of stuff, you'll want the one from PersistentRefs.esp
2. type "prid FE<three hex numbers>805" - this should correspond to the runmarker which was mentioned above. If you're on VR, it'll probably be something else, just put in the number you got from step 1.
3. type "enable"
4. Save, quit to main menu, and load your save

It'll run again upon loading your save.


How does it work?

Very carefully.

Okay, settle in, this will take a bit.

xEdit script

Here's the rough pseudocode:
  • Iterate through your load order until it finds PersistentRefs.esp, so it knows the index. NOTE: It won't work if this isn't enabled. It then stores this both as the original file, and the destination file
  • Wipes anything in the Cell section
  • Sets the next reference id to 0x806 (since the others are in use)
  • Initializes a formID list of destination locations for inn beds (more on this later) to be equal to the ACTUAL list of inn beds, which has been pre-populated
  • It then starts iterating through your whole load order - I start from the plugin AFTER Dragonborn.esm, because it otherwise seemed like a whole lot of pointless effort since everyone should have those fixed from first boot. Additionally, it checks if the current output master count is over 250 (arbitrary number, gave a little lee-way), and if so copies the important stuff (quest, formlists, worldmarkers) to the new plugin.
  • At this point, for each file in your load order, it starts checking out the entire CELL hierarchy.
  • For each element in the Persistent section of each cell, if it's a REFR, ARCH, or PHZD, is winning the override (read: no other plugin is overriding it), and isn't the master (read: isn't the one which CREATED that reference), then we add any masters needed for that ref, compare it to its master to see if the position/rotation changed, and if so, add it to the PersistentRefs formID list, and then check to see if it's a given inn bed. If it IS one of the inn beds, create a duplicate of the bed at the location we want, and change the base type of that duplicate to a COCMarkerHeading (once more, more on this later), then overwrite the destination location for inn beds
  • Repeat the above for any worldspace persistent references

Plugin/Papyrus script

Once more, rough pseudocode:
  • Call function on initialization, or if the player loads the game
  • If the run marker is enabled and MQ101 is completed, move the "start marker" to the location of the player, and start iterating through that persistent ref formid list we had
  • For each reference, if they're enabled, disable them, move to their editor location, and re-enable. If they're NOT enabled, just move them.
  • Reset the parent cell, as a sanity procedure
  • Once we've iterated through everything, iterate through the inn bed list
  • For each one of them, move the player to the bed location, and do the same as the previous, EXCEPT convert the bed to an xmarker before moving, then convert them back to their appropriate base, as well as manually rotating them to their correct orientation.
  • Finally, return the player to the "start marker" and disable the run marker.

Why the extra stuff for inn beds? Because the Room Rental script is a giant pain in the ass and like.....makes those references super duper persistent. You can't move them with console commands, you can't do anything. So special behavior needs to be done for these, where we convert the base (because you CAN move xmarkers). We have to teleport to the cell, however, because in order to set the correct rotation, they have to be 3d-loaded (read: player is in the cell). Hence: a bit of hoop jumping.

As for the run marker thing, I tried doing some revision control but couldn't figure out any way to make the values in the plugin get updated into the script (since the quest should only initialize once), but doing an extra console command didn't seem like a ton of undue effort for this thing, given everything else already involved.

Any limitations we should be aware of? Any additions we can make?

Only one I can think of offhand is that it wouldn't work with any room rental beds which are in worldspace, but as far as I'm aware there AREN'T any, so carving out exceptions for that didn't seem worthwhile. Additionally, if you want this to work with some other room rental beds, you just need to manually add them to the InnBeds formID list - everything else should be automated.

Also, any mod authors that want to steal the papyrus script and adjust it to include with your mods, by all means, have at.

And finally, this does LITERALLY NOTHING for people whose load orders aren't correct and have their references in the wrong position.

Credits
Bethesda for Skyrim Special Edition and the Creation Kit
ElminsterAU for SSEEdit
po3 for the papyrus extender and the functions in question which made this possible
aers for the reference counter, which was where I started learning how Delphi scripts worked for this
wankingSkeever for....honestly, a ton of this. He provided the original (not generalized) script, and was able to provide suggestions at a number of roadblocks, most notably the issue with inn beds not moving (and coming up with the base swap solution). It literally wouldn't be possible without him. Also, he kept bugging me asking where it was when I started working on other stuff, so you've got him to thank for that prodding, too :V
Thanks to Zilav in the xEdit discord for answering a few scripting questions