diff --git a/Projects/UniversalPropertyEnhancer/mod/main.lua b/Projects/UniversalPropertyEnhancer/mod/main.lua index c7441ac..7f31889 100644 --- a/Projects/UniversalPropertyEnhancer/mod/main.lua +++ b/Projects/UniversalPropertyEnhancer/mod/main.lua @@ -1,6 +1,6 @@ AddOnInitializePropManagerFunction(function() - require("upe/palette_icons") - RequireOnAllThreads("upe/property_list_duplicator") - RequireOnAllThreads("upe/property_list_postinit") - RequireOnAllThreads("upe/property_replacer") + modimport("upe/palette_icons") + ModImportOnAllThreads("upe/property_list_duplicator") + ModImportOnAllThreads("upe/property_list_postinit") + ModImportOnAllThreads("upe/property_replacer") end) \ No newline at end of file diff --git a/Projects/UniversalPropertyEnhancer/upe/palette_icons.lua b/Projects/UniversalPropertyEnhancer/upe/palette_icons.lua index 0677144..7800e8f 100644 --- a/Projects/UniversalPropertyEnhancer/upe/palette_icons.lua +++ b/Projects/UniversalPropertyEnhancer/upe/palette_icons.lua @@ -45,6 +45,6 @@ end) --------------------------------------------API-------------------------------------------- ------------------------------------------------------------------------------------------- -function AddPaletteIcon(palette_icon) +function _G.AddPaletteIcon(palette_icon) table.insert(palette_icons, palette_icon) end \ No newline at end of file diff --git a/Projects/UniversalPropertyEnhancer/upe/property_list_duplicator.lua b/Projects/UniversalPropertyEnhancer/upe/property_list_duplicator.lua index ff1c5eb..76d5894 100644 --- a/Projects/UniversalPropertyEnhancer/upe/property_list_duplicator.lua +++ b/Projects/UniversalPropertyEnhancer/upe/property_list_duplicator.lua @@ -68,10 +68,10 @@ end) --------------------------------------------API-------------------------------------------- ------------------------------------------------------------------------------------------- -function AddDuplicatedPropertyList(target_prop_key, source_prop_key) +function _G.AddDuplicatedPropertyList(target_prop_key, source_prop_key) duplication_map[target_prop_key] = source_prop_key end -function ClearDuplicatedPropertyList(target_prop_key) +function _G.ClearDuplicatedPropertyList(target_prop_key) duplication_map[target_prop_key] = nil end \ No newline at end of file diff --git a/Projects/UniversalPropertyEnhancer/upe/property_list_postinit.lua b/Projects/UniversalPropertyEnhancer/upe/property_list_postinit.lua index 616df1b..710ddef 100644 --- a/Projects/UniversalPropertyEnhancer/upe/property_list_postinit.lua +++ b/Projects/UniversalPropertyEnhancer/upe/property_list_postinit.lua @@ -114,10 +114,10 @@ end) --------------------------------------------API-------------------------------------------- ------------------------------------------------------------------------------------------- -AddPropPostInit_Pre, RemovePropPostInit_Pre, ExecutePropPostInit_Pre = GenerateCallbackExecuter() -AddPropPostInit_Post, RemovePropPostInit_Post, ExecutePropPostInit_Post = GenerateCallbackExecuter() +_G.AddPropPostInit_Pre, _G.RemovePropPostInit_Pre, ExecutePropPostInit_Pre = GenerateCallbackExecuter() +_G.AddPropPostInit_Post, _G.RemovePropPostInit_Post, ExecutePropPostInit_Post = GenerateCallbackExecuter() -function AddPropSpecificPostInit(group_id, instance_id, postinit) +function _G.AddPropSpecificPostInit(group_id, instance_id, postinit) local group_instances = postinit_groups[group_id] if not group_instances then group_instances = {} @@ -127,7 +127,7 @@ function AddPropSpecificPostInit(group_id, instance_id, postinit) group_instances[instance_id] = postinit end -function RemovePropSpecificPostInit(group_id, instance_id) +function _G.RemovePropSpecificPostInit(group_id, instance_id) local group_instances = postinit_groups[group_id] if not group_instances then return diff --git a/Projects/UniversalPropertyEnhancer/upe/property_replacer.lua b/Projects/UniversalPropertyEnhancer/upe/property_replacer.lua index 5baa18c..360b302 100644 --- a/Projects/UniversalPropertyEnhancer/upe/property_replacer.lua +++ b/Projects/UniversalPropertyEnhancer/upe/property_replacer.lua @@ -133,22 +133,22 @@ end) --------------------------------------------API-------------------------------------------- ------------------------------------------------------------------------------------------- -AddPropReplacerFunction, RemovePropReplacerFunction, ExecutePropReplacers = GenerateCallbackExecuter() +_G.AddPropReplacerFunction, _G.RemovePropReplacerFunction, ExecutePropReplacers = GenerateCallbackExecuter() -function AddUniversalPropertyReplacer(id, replacer) +function _G.AddUniversalPropertyReplacer(id, replacer) universal_replacements[id] = replacer end -function RemoveUniversalPropertyReplacer(id) +function _G.RemoveUniversalPropertyReplacer(id) universal_replacements[id] = nil end -function AddTypedPropertyReplacer(property_type, id, replacer) +function _G.AddTypedPropertyReplacer(property_type, id, replacer) type_replacement_map[property_type] = type_replacement_map[property_type] or {} type_replacement_map[property_type][id] = replacer end -function RemoveTypedPropertyReplacer(property_type, id) +function _G.RemoveTypedPropertyReplacer(property_type, id) local id_replacment_map = type_replacement_map[property_type] if not id_replacment_map then return diff --git a/source/Features/PaletteIcons.cpp b/source/Features/PaletteIcons.cpp index d7eb76a..b237554 100644 --- a/source/Features/PaletteIcons.cpp +++ b/source/Features/PaletteIcons.cpp @@ -24,7 +24,7 @@ #include -static sol::function sGetPaletteIcons; +static sol::function* sGetPaletteIcons = nullptr; struct PaletteIcon { uint32_t id; @@ -78,21 +78,26 @@ OnLuaInit(sol::state_view s, bool is_main_state) { icon.name.SetText(text.tableID, text.instanceID); } - ) + ), + sol::meta_function::to_string, [](const PaletteIcons& icon) + { + return string().sprintf("PaletteIcons (%p)", &icon); + } ); if (!is_main_state) return; s["AddCustomPaletteIcons"] = [](const sol::function& fn) { - sGetPaletteIcons = fn; + sGetPaletteIcons = new sol::function(fn); }; } OnLuaDispose(sol::state_view s, bool is_main_state) { if (!is_main_state) return; - sGetPaletteIcons.reset(); + delete sGetPaletteIcons; + sGetPaletteIcons = nullptr; } member_detour(LoadPaletteIconProps_detour, PaletteIcons, void()) @@ -103,7 +108,10 @@ member_detour(LoadPaletteIconProps_detour, PaletteIcons, void()) if (LuaSpore::CanExecuteOnMainState() && sGetPaletteIcons) { - const sol::table palette_icons = sGetPaletteIcons(); + const auto result = sGetPaletteIcons->call(); + if (!result.valid()) return; + + const sol::table palette_icons = result; const size_t palette_icons_size = palette_icons.size(); mPaletteIcons.reserve(mPaletteIcons.size() + palette_icons_size); diff --git a/source/Features/PropertyListDuplicator.cpp b/source/Features/PropertyListDuplicator.cpp index 22100ee..e9f1028 100644 --- a/source/Features/PropertyListDuplicator.cpp +++ b/source/Features/PropertyListDuplicator.cpp @@ -49,9 +49,12 @@ virtual_detour(GetRecordKeyList_detour, Resource::cResourceManager, Resource::IR { GetLuaSpore().ExecuteOnFreeState([&func_result, &dst, filter](const sol::state_view& s) { - if (auto fn = sApplyPropertyListDuplicator.get(s)) + if (const auto* fn = sApplyPropertyListDuplicator.get(s)) { - const sol::table record_keys = fn.value()(filter); + const auto result = fn->call(filter); + if (!result.valid()) return; + + const sol::table record_keys = result; const size_t record_keys_size = record_keys.size(); func_result += record_keys_size; @@ -78,9 +81,12 @@ virtual_detour(GetRecordKeyList2_detour, Resource::cResourceManager, Resource::I { GetLuaSpore().ExecuteOnFreeState([&func_result, &dst, filter](const sol::state_view& s) { - if (auto fn = sApplyPropertyListDuplicator.get(s)) + if (const auto* fn = sApplyPropertyListDuplicator.get(s)) { - const sol::table record_keys = fn.value()(filter); + const auto result = fn->call(filter); + if (!result.valid()) return; + + const sol::table record_keys = result; const size_t record_keys_size = record_keys.size(); func_result += record_keys_size; diff --git a/source/Features/PropertyListPostInit.cpp b/source/Features/PropertyListPostInit.cpp index 919dfbb..599c700 100644 --- a/source/Features/PropertyListPostInit.cpp +++ b/source/Features/PropertyListPostInit.cpp @@ -49,9 +49,9 @@ virtual_detour(GetPropertyList_detour, App::cPropManager, App::IPropManager, boo { GetLuaSpore().ExecuteOnFreeState([&pDst, instanceID, groupID](const sol::state_view& s) { - if (auto fn = sApplyPropertyListPostInit.get(s)) + if (const auto* fn = sApplyPropertyListPostInit.get(s)) { - fn.value()(pDst, instanceID, groupID); + fn->call(pDst, instanceID, groupID); } }); } diff --git a/source/Features/PropertyReplacer.cpp b/source/Features/PropertyReplacer.cpp index f509d9f..b186499 100644 --- a/source/Features/PropertyReplacer.cpp +++ b/source/Features/PropertyReplacer.cpp @@ -58,9 +58,9 @@ member_detour(GetPropertyAlt_detour, App::PropertyList, bool(uint32_t propertyID { GetLuaSpore().ExecuteOnFreeState([this, propertyID, &result](const sol::state_view& s) { - if (auto fn = sApplyPropertyReplacerFunction.get(s)) + if (const auto* fn = sApplyPropertyReplacerFunction.get(s)) { - fn.value()(propertyID, result, static_cast(this)); + fn->call(propertyID, result, static_cast(this)); SetPropertyReplaced(result); } }); @@ -81,9 +81,9 @@ member_detour(GetProperty_detour, App::PropertyList, bool(uint32_t propertyID, A { GetLuaSpore().ExecuteOnFreeState([this, propertyID, &result](const sol::state_view& s) { - if (auto fn = sApplyPropertyReplacerFunction.get(s)) + if (const auto* fn = sApplyPropertyReplacerFunction.get(s)) { - fn.value()(propertyID, result, static_cast(this)); + fn->call(propertyID, result, static_cast(this)); SetPropertyReplaced(result); } }); @@ -104,9 +104,9 @@ member_detour(GetPropertyObject_detour, App::PropertyList, App::Property*(uint32 { GetLuaSpore().ExecuteOnFreeState([this, propertyID, &result](const sol::state_view& s) { - if (auto fn = sApplyPropertyReplacerFunction.get(s)) + if (const auto* fn = sApplyPropertyReplacerFunction.get(s)) { - fn.value()(propertyID, result, static_cast(this)); + fn->call(propertyID, result, static_cast(this)); } }); }