diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 0ee6e9c..6cae782 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -1,40 +1,11 @@ #include -#include "loader/component_loader.hpp" -#include "component/signatures.hpp" -#include +PLUTONIUM_API plutonium::sdk::plugin* PLUTONIUM_CALLBACK on_initialize() +{ + return plugin::get(); +} BOOL APIENTRY DllMain(HMODULE /*module_*/, DWORD ul_reason_for_call, LPVOID /*reserved_*/) { - if (ul_reason_for_call == DLL_PROCESS_ATTACH) - { - if (game::environment::t4sp()) - { - if (!signatures::process()) - { - MessageBoxA(NULL, - std::format("This version of t4sp-server-plugin is outdated.\n" \ - "Download the latest dll from here: https://github.com/JezuzLizard/T4SP-Server-Plugin/releases\n" \ - "'{}' failed", signatures::get_err_reason()).c_str(), - "ERROR", MB_ICONERROR); - - return FALSE; - } - - if (game::plutonium::printf.get() != nullptr) - { - utils::hook::jump(reinterpret_cast(&printf), game::plutonium::printf); - } - - component_loader::post_unpack(); - } - else - { - MessageBoxA(nullptr, "Unsupported game executable. (t4sp is only supported)", "ERROR, BRO!", 0); - - return FALSE; - } - } - return TRUE; } \ No newline at end of file diff --git a/src/plugin.cpp b/src/plugin.cpp new file mode 100644 index 0000000..16aa4d9 --- /dev/null +++ b/src/plugin.cpp @@ -0,0 +1,73 @@ +#include +#include "component/signatures.hpp" + +#include +#include "loader/component_loader.hpp" + +namespace plugin +{ + std::uint32_t plugin::plugin_version() + { + return 1; + } + + const char* plugin::plugin_name() + { + return "t4sp-server-plugin"; + } + + bool plugin::is_game_supported(plutonium::sdk::game game) + { + return game == plutonium::sdk::game::t4; + } + + void plugin::on_startup(plutonium::sdk::iinterface* interface_ptr, plutonium::sdk::game game) + { + this->interface_ = interface_ptr; + this->game_ = game; + + if (!game::environment::t4sp()) + { + MessageBoxA(nullptr, "Unsupported game executable. (t4sp is only supported)", "ERROR, BRO!", 0); + return; + } + + if (!signatures::process()) + { + MessageBoxA(NULL, + std::format("This version of t4sp-server-plugin is outdated.\n" \ + "Download the latest dll from here: https://github.com/JezuzLizard/T4SP-Server-Plugin/releases\n" \ + "'{}' failed", signatures::get_err_reason()).c_str(), + "ERROR", MB_ICONERROR); + + return; + } + + if (game::plutonium::printf.get() != nullptr) + { + utils::hook::jump(reinterpret_cast(&printf), game::plutonium::printf); + } + + component_loader::post_unpack(); + } + + void plugin::on_shutdown() + { + } + + plutonium::sdk::iinterface* plugin::get_interface() + { + return this->interface_; + } + + plutonium::sdk::game plugin::get_game() + { + return this->game_; + } + + plugin* get() + { + static plugin instance; + return &instance; + } +} diff --git a/src/plugin.hpp b/src/plugin.hpp new file mode 100644 index 0000000..046c0cd --- /dev/null +++ b/src/plugin.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include + +namespace plugin +{ + class plugin : public plutonium::sdk::plugin + { + public: + ~plugin() = default; + + std::uint32_t plugin_version() override; + const char* plugin_name() override; + + bool is_game_supported(plutonium::sdk::game game) override; + + void on_startup(plutonium::sdk::iinterface* interface_ptr, plutonium::sdk::game game) override; + void on_shutdown() override; + + plutonium::sdk::iinterface* get_interface(); + plutonium::sdk::game get_game(); + + private: + plutonium::sdk::iinterface* interface_{}; + plutonium::sdk::game game_{}; + + }; + + plugin* get(); +} diff --git a/src/stdinc.hpp b/src/stdinc.hpp index 2d6f76c..3398aec 100644 --- a/src/stdinc.hpp +++ b/src/stdinc.hpp @@ -71,6 +71,8 @@ #include "game/structs.hpp" #include "game/symbols.hpp" +#include "plugin.hpp" + std::string build_gsc_dump(game::scriptInstance_t inst); void push_opcode_history(game::scriptInstance_t inst, game::OpcodeVM op); void push_builtin_history(game::scriptInstance_t inst, int idx);