Skip to content

Instantly share code, notes, and snippets.

@ianpatt
Created May 2, 2024 00:58
Show Gist options
  • Save ianpatt/a1b031f920061593ee0ffcf314634b36 to your computer and use it in GitHub Desktop.
Save ianpatt/a1b031f920061593ee0ffcf314634b36 to your computer and use it in GitHub Desktop.
test f4se messaging plugin
#include <cstdint>
#include <cstdarg>
#include <cstdio>
typedef uint64_t UInt64;
typedef uint32_t UInt32;
typedef uint8_t UInt8;
#include "PluginAPI.h"
#include "f4se_version.h"
PluginHandle g_pluginHandle = 0;
F4SEMessagingInterface * g_messaging = nullptr;
void Log(const char * fmt, ...)
{
static FILE * s_log = nullptr;
if(!s_log)
fopen_s(&s_log, "i:\\test_f4se_plugin.txt", "w");
if(s_log)
{
va_list args;
va_start(args, fmt);
vfprintf_s(s_log, fmt, args);
fputs("\n", s_log);
va_end(args);
}
}
void OnF4SEMessage(F4SEMessagingInterface::Message * msg)
{
Log("msg: %08X", msg->type);
}
extern "C" {
__declspec(dllexport) F4SEPluginVersionData F4SEPlugin_Version =
{
F4SEPluginVersionData::kVersion,
1,
"test f4se plugin",
"ianpatt",
0, // not version independent
0, // not version independent (extended field)
{ RUNTIME_VERSION_1_10_980, 0 }, // compatible with 1.10.980
0, // works with any version of the script extender. you probably do not need to put anything here
};
__declspec(dllexport) bool F4SEPlugin_Load(const F4SEInterface * f4se)
{
Log("load");
g_pluginHandle = f4se->GetPluginHandle();
Log("handle = %08X", g_pluginHandle);
g_messaging = (F4SEMessagingInterface *)f4se->QueryInterface(kInterface_Messaging);
Log("messaging api = %016I64X", g_messaging);
g_messaging->RegisterListener(g_pluginHandle, "F4SE", OnF4SEMessage);
Log("done");
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment