Created
March 8, 2025 21:49
-
-
Save ThomasJClark/acc52f6f808693583be9e5d8f102eb97 to your computer and use it in GitHub Desktop.
Elden Ring DLL example
This file contains hidden or 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
| cmake_minimum_required(VERSION 3.28.1) | |
| set(CMAKE_GENERATOR_PLATFORM x64) | |
| project(bingus | |
| VERSION "0.0.1" | |
| LANGUAGES CXX) | |
| set(CMAKE_CXX_STANDARD 20) | |
| set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) | |
| include(FetchContent) | |
| set(SPDLOG_DISABLE_DEFAULT_LOGGER ON) | |
| set(SPDLOG_USE_STD_FORMAT ON) | |
| FetchContent_Declare(spdlog | |
| GIT_REPOSITORY https://github.com/gabime/spdlog.git | |
| GIT_TAG v1.13.0) | |
| FetchContent_Declare(elden-x | |
| GIT_REPOSITORY https://github.com/ThomasJClark/elden-x.git | |
| GIT_TAG bffbaea681f0faf6d61d1da04b63546d969ff22a) | |
| add_definitions(-D_ITERATOR_DEBUG_LEVEL=0) | |
| FetchContent_MakeAvailable(spdlog elden-x) | |
| add_library(${PROJECT_NAME} SHARED dllmain.cpp) | |
| set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) | |
| add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD | |
| COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${PROJECT_NAME}> | |
| COMMAND_EXPAND_LISTS) | |
| target_link_libraries(${PROJECT_NAME} PRIVATE spdlog elden-x) |
This file contains hidden or 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 <elden-x/params/param_table.hpp> | |
| #include <elden-x/singletons.hpp> | |
| #include <elden-x/utils/modutils.hpp> | |
| #define WIN32_LEAN_AND_MEAN | |
| #include <windows.h> | |
| #include <spdlog/sinks/stdout_color_sinks.h> | |
| #include <spdlog/spdlog.h> | |
| #include <chrono> | |
| #include <memory> | |
| #include <thread> | |
| using namespace std; | |
| static void example_mod() | |
| { | |
| er::FD4::find_singletons(); | |
| er::CS::SoloParamRepository::wait_for_params(); | |
| for (auto [id, row] : er::param::EquipParamProtector) | |
| { | |
| row.weight = 99.f; | |
| } | |
| } | |
| bool WINAPI DllMain(HINSTANCE dll_instance, unsigned int fdw_reason, void *reserved) | |
| { | |
| static thread mod_thread; | |
| if (fdw_reason == DLL_PROCESS_ATTACH) | |
| { | |
| auto logger = make_shared<spdlog::logger>("bingus"); | |
| spdlog::set_default_logger(logger); | |
| // Uncomment this to open a console for development logging | |
| // AllocConsole(); | |
| // FILE *stream; | |
| // freopen_s(&stream, "CONOUT$", "w", stdout); | |
| // freopen_s(&stream, "CONOUT$", "w", stderr); | |
| // freopen_s(&stream, "CONIN$", "r", stdin); | |
| // logger->sinks().push_back(make_shared<spdlog::sinks::stdout_color_sink_st>()); | |
| // logger->set_level(spdlog::level::trace); | |
| // logger->flush_on(spdlog::level::trace); | |
| // logger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%n] %^[%l]%$ [%s:%#] %v"); | |
| mod_thread = thread([]() { | |
| try | |
| { | |
| modutils::initialize(); | |
| this_thread::sleep_for(chrono::seconds(2)); | |
| example_mod(); | |
| } | |
| catch (runtime_error const &e) | |
| { | |
| modutils::deinitialize(); | |
| } | |
| }); | |
| } | |
| else if (fdw_reason == DLL_PROCESS_DETACH && reserved != nullptr) | |
| { | |
| mod_thread.join(); | |
| modutils::deinitialize(); | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment