Skip to content

Commit

Permalink
begin to add cppmod back
Browse files Browse the repository at this point in the history
  • Loading branch information
Yangff committed Feb 25, 2024
1 parent f9f84f1 commit 8f00ba8
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 36 deletions.
2 changes: 2 additions & 0 deletions UE4SS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ set(${TARGET}_Sources
"${CMAKE_CURRENT_SOURCE_DIR}/src/SDKGenerator/JSONDumper.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/SDKGenerator/TMapOverrideGen.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/USMapGenerator/Generator.cpp"

"${CMAKE_CURRENT_SOURCE_DIR}/src/Mod/CppMod.cpp"
)

if (WIN32)
Expand Down
2 changes: 2 additions & 0 deletions UE4SS/include/Mod/CppMod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace RC
#ifdef WIN32
HMODULE m_main_dll_module = NULL;
DLL_DIRECTORY_COOKIE m_dlls_path_cookie = NULL;
#else
void * m_dl_handle = nullptr;
#endif
start_type m_start_mod_func = nullptr;
uninstall_type m_uninstall_mod_func = nullptr;
Expand Down
2 changes: 0 additions & 2 deletions UE4SS/include/UE4SSProgram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

#include <LuaLibrary.hpp>
#include <MProgram.hpp>
#ifdef HAS_CPPMOD
#include <Mod/CppMod.hpp>
#endif
#include <Mod/LuaMod.hpp>
#include <Mod/Mod.hpp>
#include <SettingsManager.hpp>
Expand Down
7 changes: 6 additions & 1 deletion UE4SS/src/Mod/CppMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#ifdef LINUX
#define printf_s printf
#define _GNU_SOURCE
#include <dlfcn.h>
#endif

namespace RC
Expand All @@ -20,7 +22,7 @@ namespace RC

if (!std::filesystem::exists(m_dlls_path))
{
Output::send<LogLevel::Warning>(SYSSTR("Could not find the dlls folder for mod {}\n"), (m_mod_name));
Output::send<LogLevel::Warning>(SYSSTR("Could not find the dlls folder for mod {}\n"), m_mod_name);
set_installable(false);
return;
}
Expand Down Expand Up @@ -52,6 +54,9 @@ namespace RC
set_installable(false);
return;
}

#else

#endif
}

Expand Down
16 changes: 1 addition & 15 deletions UE4SS/src/Mod/LuaMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
#include <LuaType/LuaUObject.hpp>
#include <LuaType/LuaFURL.hpp>


#ifdef HAS_CPPMOD
#include <Mod/CppMod.hpp>
#endif


#include <Mod/LuaMod.hpp>
#pragma warning(disable : 4005)
#include <GUI/Dumpers.hpp>
Expand Down Expand Up @@ -3333,7 +3328,7 @@ No overload found for function 'FPackageName:IsValidLongPackageName'.
lua_setglobal(lua.get_lua_state(), "__OriginalReturnValue");
}

#ifdef HAS_CPPMOD

auto LuaMod::fire_on_lua_start_for_cpp_mods() -> void
{
if (!is_started())
Expand Down Expand Up @@ -3373,15 +3368,6 @@ No overload found for function 'FPackageName:IsValidLongPackageName'.
}
}
}
#else
auto LuaMod::fire_on_lua_start_for_cpp_mods() -> void
{
}

auto LuaMod::fire_on_lua_stop_for_cpp_mods() -> void
{
}
#endif

auto LuaMod::start_mod() -> void
{
Expand Down
18 changes: 0 additions & 18 deletions UE4SS/src/UE4SSProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
#include <LuaLibrary.hpp>
#include <LuaType/LuaCustomProperty.hpp>
#include <LuaType/LuaUObject.hpp>
#ifdef HAS_CPPMOD
#include <Mod/CppMod.hpp>
#endif
#include <Mod/LuaMod.hpp>
#include <Mod/Mod.hpp>
#include <ObjectDumper/ObjectToString.hpp>
Expand Down Expand Up @@ -1111,9 +1109,7 @@ namespace RC

auto UE4SSProgram::install_cpp_mods() -> void
{
#ifdef HAS_CPPMOD
install_mods<CppMod>(get_program().m_mods);
#endif
}

auto UE4SSProgram::install_lua_mods() -> void
Expand All @@ -1126,13 +1122,11 @@ namespace RC
ProfilerScope();
for (const auto& mod : m_mods)
{
#ifdef HAS_CPPMOD
if (!dynamic_cast<CppMod*>(mod.get()))
{
continue;
}
mod->fire_unreal_init();
#endif
}
}

Expand All @@ -1141,26 +1135,22 @@ namespace RC
ProfilerScope();
for (const auto& mod : m_mods)
{
#ifdef HAS_CPPMOD
if (!dynamic_cast<CppMod*>(mod.get()))
{
continue;
}
mod->fire_program_start();
#endif
}
}

auto UE4SSProgram::fire_dll_load_for_cpp_mods(SystemStringViewType dll_name) -> void
{
for (const auto& mod : m_mods)
{
#ifdef HAS_CPPMOD
if (auto cpp_mod = dynamic_cast<CppMod*>(mod.get()); cpp_mod)
{
cpp_mod->fire_dll_load(dll_name);
}
#endif
}
}

Expand Down Expand Up @@ -1281,33 +1271,27 @@ namespace RC

auto UE4SSProgram::start_cpp_mods() -> void
{
#ifdef HAS_CPPMOD
ProfilerScope();
auto error_message = start_mods<CppMod>();
if (!error_message.empty())
{
set_error(error_message.c_str());
}
#endif
}

auto UE4SSProgram::uninstall_mods() -> void
{
ProfilerScope();

#ifdef HAS_CPPMOD
std::vector<CppMod*> cpp_mods{};
#endif
std::vector<LuaMod*> lua_mods{};
for (auto& mod : m_mods)
{
#ifdef HAS_CPPMOD
if (auto cpp_mod = dynamic_cast<CppMod*>(mod.get()); cpp_mod)
{
cpp_mods.emplace_back(cpp_mod);
}
else
#endif
if (auto lua_mod = dynamic_cast<LuaMod*>(mod.get()); lua_mod)
{
lua_mods.emplace_back(lua_mod);
Expand All @@ -1320,12 +1304,10 @@ namespace RC
mod->uninstall();
}

#ifdef HAS_CPPMOD
for (auto& mod : cpp_mods)
{
mod->uninstall();
}
#endif
m_mods.clear();
LuaMod::global_uninstall();
}
Expand Down

0 comments on commit 8f00ba8

Please sign in to comment.