Implemented Papyrus script version checking, added versions to 4 core scripts

This commit is contained in:
Eddoursul 2023-10-26 21:22:14 +02:00
parent 2cbe179c27
commit 7b24aa0767
12 changed files with 88 additions and 2 deletions

BIN
SKSE/Plugins/EnderalSE.dll (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,6 +8,7 @@ auto EventListener::GetSingleton() -> EventListener*
return std::addressof(singleton);
}
// Unused
void EventListener::Install()
{
RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink<RE::TESContainerChangedEvent>(EventListener::GetSingleton());
@ -57,6 +58,9 @@ auto EventListener::ProcessEvent(
movie->Invoke("_root.QuestJournalFader.Menu_mc.RestoreSavedSettings", nullptr, args.data(), static_cast<std::uint32_t>(args.size()));
}
}
} else if (!a_event->opening && a_event->menuName == RE::MainMenu::MENU_NAME) {
RE::UI::GetSingleton()->RemoveEventSink<RE::MenuOpenCloseEvent>(EventListener::GetSingleton());
CheckScriptVersions();
}
return RE::BSEventNotifyControl::kContinue;

View File

@ -141,6 +141,7 @@ SKSEPluginLoad(const LoadInterface* skse) {
InitializeMessaging();
SKSE::GetModCallbackEventSource()->AddEventSink(EventListener::GetSingleton());
RE::UI::GetSingleton()->AddEventSink<RE::MenuOpenCloseEvent>(EventListener::GetSingleton());
GetPapyrusInterface()->Register(Papyrus::Bind);

View File

@ -65,6 +65,72 @@ inline void CheckIncompatibleMods()
CheckEnderalStatics();
}
inline bool PapyrusGlobalFunctionExists(const char* scriptName, const char* funcName)
{
logger::info("Real - GetGlobalFunctionNames of {}", scriptName);
std::vector<std::string> functionNames;
RE::BSTSmartPointer<RE::BSScript::ObjectTypeInfo> typeInfoPtr;
RE::BSScript::Internal::VirtualMachine::GetSingleton()->GetScriptObjectType(RE::BSFixedString(scriptName), typeInfoPtr);
auto functionCount = typeInfoPtr->GetNumGlobalFuncs();
auto functions = typeInfoPtr->GetGlobalFuncIter();
for (uint32_t i = 0; i < functionCount; i++) {
if (functions[i].func->GetName().c_str() == funcName) {
return true;
}
}
return false;
}
inline void CheckScriptVersions()
{
class ScriptVersionCallback : public RE::BSScript::IStackCallbackFunctor
{
private:
std::uint32_t expectedVersion;
const RE::BSFixedString scriptName;
const RE::BSFixedString funcName = "_GetScriptVersion";
public:
ScriptVersionCallback(const RE::BSFixedString a_scriptName, int a_version) :
scriptName(a_scriptName),
expectedVersion(a_version)
{
if (PapyrusGlobalFunctionExists(scriptName.c_str(), funcName.c_str())) {
const auto vm = RE::BSScript::Internal::VirtualMachine::GetSingleton();
auto callbackPtr = RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor>(this);
vm->DispatchStaticCall(scriptName, funcName, RE::MakeFunctionArguments(), callbackPtr);
} else {
auto a_script = scriptName;
auto a_version = expectedVersion;
SKSE::GetTaskInterface()->AddTask([a_script, a_version]() {
RE::DebugMessageBox(std::format("Script {} is overwritten by a mod, incompatible with current version of Enderal. Expected version: {}, installed version: N/A.", a_script.c_str(), a_version).c_str());
});
}
}
void operator()(RE::BSScript::Variable a_result)
{
if (a_result.GetUInt() != expectedVersion) {
RE::DebugMessageBox(std::format("Script {} is overwritten by a mod, incompatible with current version of Enderal. Expected version: {}, installed version: {}.", scriptName.c_str(), expectedVersion, a_result.GetUInt()).c_str());
}
}
bool CanSave() { return false; }
void SetObject(const RE::BSTSmartPointer<RE::BSScript::Object>&) {}
};
RE::BSTSmartPointer<ScriptVersionCallback>{
new ScriptVersionCallback("_00E_PlayerSetUpScript", 1)
};
RE::BSTSmartPointer<ScriptVersionCallback>{
new ScriptVersionCallback("_00E_QuestFunctions", 1)
};
RE::BSTSmartPointer<ScriptVersionCallback>{
new ScriptVersionCallback("_00E_Game_SkillmenuSC", 1)
};
RE::BSTSmartPointer<ScriptVersionCallback>{
new ScriptVersionCallback("_00E_Theriantrophist_AlchemyControl", 1)
};
}
inline void LoadINI(std::map<std::string, bool>* settings, const char* iniPath)
{
for (auto it = settings->begin(); it != settings->end(); it++) {

View File

@ -11,6 +11,10 @@ Import Math
Import ActorValueInfo
Import _00E_QuestFunctions
int function _GetScriptVersion() Global
return 1
endFunction
; This script handles the custom character menu
;=====================================================================================

View File

@ -3,6 +3,9 @@ Scriptname _00E_PlayerSetUpScript extends ObjectReference
Float Property CURRENT_PATCH_VERSION = 2.13 AutoReadOnly
int function _GetScriptVersion() Global
return 1
endFunction
;=====================================================================================
; EVENTS

View File

@ -4,6 +4,10 @@ Scriptname _00E_QuestFunctions extends Quest Conditional
Import math
Import Utility
int function _GetScriptVersion() Global
return 1
endFunction
;=====================================================================================
; EXP
;=====================================================================================

View File

@ -91,6 +91,10 @@ string[] aPotionModels
; FUNCTIONS
;=====================================================================================
int function _GetScriptVersion() Global
return 1
endFunction
function _addNamedPotion(Potion aPotion, string sName, string sModel)
if ! aPotion || sName == ""