Last active
March 22, 2024 05:19
-
-
Save Ryan-rsm-McKenzie/a5bbe01ee10e84b6b62f9a22ec943a84 to your computer and use it in GitHub Desktop.
CommonLibSSE Papyrus Interface Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "version.h" | |
std::string HelloWorld(RE::StaticFunctionTag*) | |
{ | |
return "Hello world!"; | |
} | |
SInt32 Sum(RE::StaticFunctionTag*, SInt32 a_num1, SInt32 a_num2) | |
{ | |
return a_num1 + a_num2; | |
} | |
bool RegisterFuncs(RE::BSScript::IVirtualMachine* a_vm) | |
{ | |
a_vm->RegisterFunction("HelloWorld", "MyClass", HelloWorld); | |
a_vm->RegisterFunction("Sum", "MyClass", Sum); | |
return true; | |
} | |
extern "C" DLLEXPORT bool APIENTRY SKSEPlugin_Query(const SKSE::QueryInterface* a_skse, SKSE::PluginInfo* a_info) | |
{ | |
SKSE::Logger::OpenRelative(FOLDERID_Documents, L"\\My Games\\Skyrim Special Edition\\SKSE\\MyFirstPlugin.log"); | |
SKSE::Logger::SetPrintLevel(SKSE::Logger::Level::kDebugMessage); | |
SKSE::Logger::SetFlushLevel(SKSE::Logger::Level::kDebugMessage); | |
SKSE::Logger::UseLogStamp(true); | |
_MESSAGE("MyFirstPlugin v%s", MYFP_VERSION_VERSTRING); | |
a_info->infoVersion = SKSE::PluginInfo::kVersion; | |
a_info->name = "MyFirstPlugin"; | |
a_info->version = MYFP_VERSION_MAJOR; | |
if (a_skse->IsEditor()) { | |
_FATALERROR("Loaded in editor, marking as incompatible!\n"); | |
return false; | |
} | |
const auto ver = a_skse->RuntimeVersion(); | |
if (ver < SKSE::RUNTIME_1_5_39) { | |
_FATALERROR("Unsupported runtime version %s!\n", ver.GetString().c_str()); | |
return false; | |
} | |
return true; | |
} | |
extern "C" DLLEXPORT bool APIENTRY SKSEPlugin_Load(const SKSE::LoadInterface* a_skse) | |
{ | |
_MESSAGE("MyFirstPlugin loaded"); | |
if (!SKSE::Init(a_skse)) { | |
return false; | |
} | |
auto papyrus = SKSE::GetPapyrusInterface(); | |
if (!papyrus->Register(RegisterFuncs)) { | |
return false; | |
} | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ScriptName MyClass | |
String Function HelloWorld() Global Native | |
Int Function Sum(Int a_num1, Int a_num2) Global Native |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Much cleaner of a read then this 👍