Jump to content

Is there a way to detect when the game gets saved in Papyrus?


Recommended Posts

There is no such event in papyrus. But you can try using SaveLoadMessageStringEvent global event from native f4se plugin. I havent tested but it seems it should fire when save/load message appears on screen.

 

I can't find anything about this type of event. Is there a place where this is documented?

Link to comment
Share on other sites

Unfortunately no. Global events are type of events you can use with event dispatcher without need to have their addresses in memory. But you stil need to know the members of struct it contains when fired, dump it with dumpclass. Usage is following:

struct SaveLoadMessageStringEvent
{
    UInt32 Unk00 //fill with members after you use dumpclass in event body. Members will be dumped in f4se logs folder in file with your plugin name
};
class SaveLoadMessageStringEventSink : public BSTEventSink<SaveLoadMessageStringEvent>
{
public:
    virtual ~SaveLoadMessageStringEventSink() { };

    virtual EventResult ReceiveEvent(SaveLoadMessageStringEvent * evn, void * dispatcher) override
{

        //event will happend here, do whatever you want. You access members like this: evn->unk00
        return kEvent_Continue;
}
};
SaveLoadMessageStringEventSink saveLoadMessageStringEventSink;

Then to add your event sink in event dispatcher, add this code somewhere where your plugin loads (in plugin_load or messaging interface's data ready)

auto eventDispatcher = GET_EVENT_DISPATCHER(SaveLoadMessageStringEvent);
if (eventDispatcher) {
    eventDispatcher->AddEventSink(&saveLoadMessageStringEventSink);
}

Almost forgot, write following somewhere in beginning of your file to use global events like I suggested, this is reg2k code btw:

BSTEventDispatcher<void*>* GetGlobalEventDispatcher(BSTGlobalEvent* globalEvents, const char * dispatcherName)
{
    for (int i = 0; i < globalEvents->eventSources.count; i++) {
    const char* name = GetObjectClassName(globalEvents->eventSources[i]) + 15; // ?$EventSource@V
    if (strstr(name, dispatcherName) == name) {
        return &globalEvents->eventSources[i]->eventDispatcher;
    }
}
return nullptr;
}
#define GET_EVENT_DISPATCHER(EventName) (BSTEventDispatcher<EventName>*) GetGlobalEventDispatcher(*g_globalEvents, #EventName);

P.S I suppose, as one of your mods use f4se plugin dll, you are familiar with them, otherwise all this may not make much sense

Edited by shavkacagarikia
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...