From c0ea1d362318799a9a076139b6a448ffc68d887f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 May 2026 21:58:26 +0000 Subject: [PATCH 1/4] Initial plan From 87326e8afe99edefa34fedca3931c4803e4e002c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 May 2026 22:03:29 +0000 Subject: [PATCH 2/4] Add .clang-format file and apply formatting to all src C++ files Agent-Logs-Url: https://github.com/ikkentim/SampSharp/sessions/3251c519-d370-4e30-8b2b-1707792a2b47 Co-authored-by: ikkentim <2820647+ikkentim@users.noreply.github.com> --- .clang-format | 49 ++ .editorconfig | 6 + src/legacy/SampSharp/config.cpp | 12 +- src/legacy/SampSharp/config.h | 7 +- src/legacy/SampSharp/config_cfg.cpp | 30 +- src/legacy/SampSharp/config_cfg.h | 8 +- src/legacy/SampSharp/config_composite.cpp | 21 +- src/legacy/SampSharp/config_composite.h | 10 +- src/legacy/SampSharp/config_omp.cpp | 32 +- src/legacy/SampSharp/config_omp.h | 8 +- src/legacy/SampSharp/config_win.cpp | 27 +- src/legacy/SampSharp/config_win.h | 8 +- src/legacy/SampSharp/coreclr_app.cpp | 315 ++++---- src/legacy/SampSharp/coreclr_app.h | 37 +- src/legacy/SampSharp/includes/.clang-format | 3 + src/legacy/SampSharp/interop.cpp | 40 +- src/legacy/SampSharp/interop.h | 4 +- src/legacy/SampSharp/locator.cpp | 116 +-- src/legacy/SampSharp/locator.h | 13 +- src/legacy/SampSharp/logging.cpp | 22 +- src/legacy/SampSharp/logging.h | 12 +- src/legacy/SampSharp/main.cpp | 101 ++- src/legacy/SampSharp/nethost.h | 5 +- src/legacy/SampSharp/nethost_coreclr.cpp | 42 +- src/legacy/SampSharp/nethost_coreclr.h | 6 +- src/legacy/SampSharp/platforms.h | 32 +- src/legacy/SampSharp/strutil.cpp | 9 +- src/legacy/SampSharp/testing.cpp | 56 +- src/legacy/SampSharp/version.h | 31 +- src/sampsharp-component/compat.cpp | 11 +- src/sampsharp-component/compat.hpp | 18 +- src/sampsharp-component/crash-handler.cpp | 115 +-- src/sampsharp-component/crash-handler.hpp | 2 +- src/sampsharp-component/managed-host.cpp | 186 +++-- src/sampsharp-component/managed-host.hpp | 17 +- src/sampsharp-component/proxies/api.cpp | 731 +++++++++--------- src/sampsharp-component/proxies/config.cpp | 10 +- src/sampsharp-component/proxies/extension.cpp | 34 +- src/sampsharp-component/proxies/logger.cpp | 28 +- .../proxies/pool-event-handler.cpp | 25 +- src/sampsharp-component/proxies/pool.cpp | 6 +- .../proxies/robin-hood.cpp | 16 +- src/sampsharp-component/proxies/vehicles.cpp | 3 +- src/sampsharp-component/proxy-api.hpp | 312 +++++--- .../sampsharp-component.cpp | 56 +- .../sampsharp-component.hpp | 61 +- 46 files changed, 1491 insertions(+), 1202 deletions(-) create mode 100644 .clang-format create mode 100644 src/legacy/SampSharp/includes/.clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..d78c5bce --- /dev/null +++ b/.clang-format @@ -0,0 +1,49 @@ +--- +Language: Cpp +BasedOnStyle: LLVM + +# Indentation +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +ContinuationIndentWidth: 4 +ConstructorInitializerIndentWidth: 4 +NamespaceIndentation: All +IndentCaseLabels: false +AccessModifierOffset: -4 + +# Column limit +ColumnLimit: 120 + +# Braces – Allman style (opening brace on its own line) +BreakBeforeBraces: Allman + +# Pointer and reference alignment +PointerAlignment: Left +ReferenceAlignment: Left + +# Spaces +SpaceBeforeParens: ControlStatements +SpaceAfterTemplateKeyword: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeRangeBasedForLoopColon: true + +# Constructor initializers +BreakConstructorInitializers: AfterColon +PackConstructorInitializers: Never + +# Template declarations +AlwaysBreakTemplateDeclarations: Yes + +# Short constructs +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortBlocksOnASingleLine: Empty + +# Include sorting – preserve existing order to avoid breaking build dependencies +SortIncludes: Never +... diff --git a/.editorconfig b/.editorconfig index 5a3dc022..bef40a2d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,11 @@ root = true +[*.{cpp,hpp,h,c}] +indent_size = 4 +indent_style = space +tab_width = 4 +end_of_line = lf + [CMakeLists.txt] indent_size = 4 indent_style = space diff --git a/src/legacy/SampSharp/config.cpp b/src/legacy/SampSharp/config.cpp index 5cebe2fd..71118e20 100644 --- a/src/legacy/SampSharp/config.cpp +++ b/src/legacy/SampSharp/config.cpp @@ -16,17 +16,21 @@ #include "config.h" #include "strutil.h" -bool config::get_config_bool(std::string name, bool& result) { +bool config::get_config_bool(std::string name, bool& result) +{ std::string value; - if (!get_config_string(name, value)) { + if (!get_config_string(name, value)) + { return false; } - if (iequals(value, "on") || iequals(value, "yes") || iequals(value, "true")) { + if (iequals(value, "on") || iequals(value, "yes") || iequals(value, "true")) + { result = true; return true; } - if (iequals(value, "off") || iequals(value, "no") || iequals(value, "false")) { + if (iequals(value, "off") || iequals(value, "no") || iequals(value, "false")) + { result = false; return true; } diff --git a/src/legacy/SampSharp/config.h b/src/legacy/SampSharp/config.h index ab590e24..c960e8ff 100644 --- a/src/legacy/SampSharp/config.h +++ b/src/legacy/SampSharp/config.h @@ -16,8 +16,9 @@ #pragma once #include -class config { +class config +{ public: - virtual bool get_config_string(std::string name, std::string &result) = 0; - virtual bool get_config_bool(std::string name, bool &result); + virtual bool get_config_string(std::string name, std::string& result) = 0; + virtual bool get_config_bool(std::string name, bool& result); }; diff --git a/src/legacy/SampSharp/config_cfg.cpp b/src/legacy/SampSharp/config_cfg.cpp index 5a6f2651..bc75085e 100644 --- a/src/legacy/SampSharp/config_cfg.cpp +++ b/src/legacy/SampSharp/config_cfg.cpp @@ -20,23 +20,23 @@ #include #include -static void trim(std::string& s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { - return !std::isspace(ch); - })); - - s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { - return !std::isspace(ch); - }).base(), s.end()); +static void trim(std::string& s) +{ + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); + + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); } -config_cfg::config_cfg() { +config_cfg::config_cfg() +{ std::ifstream file("server.cfg"); - - if (file.is_open()) { + + if (file.is_open()) + { std::string line, name, value; - while (std::getline(file, line, '\n')) { + while (std::getline(file, line, '\n')) + { std::stringstream stream(line); std::getline(stream, name, ' '); @@ -50,10 +50,12 @@ config_cfg::config_cfg() { } } -bool config_cfg::get_config_string(std::string name, std::string& result) { +bool config_cfg::get_config_string(std::string name, std::string& result) +{ const auto iterator = values_.find(name); - if (iterator == values_.end()) { + if (iterator == values_.end()) + { return false; } diff --git a/src/legacy/SampSharp/config_cfg.h b/src/legacy/SampSharp/config_cfg.h index a79fbea7..19c5bca9 100644 --- a/src/legacy/SampSharp/config_cfg.h +++ b/src/legacy/SampSharp/config_cfg.h @@ -17,10 +17,12 @@ #include "config.h" #include -class config_cfg final : public config { - public: +class config_cfg final : public config +{ +public: config_cfg(); - bool get_config_string(std::string name, std::string &result) override; + bool get_config_string(std::string name, std::string& result) override; + private: std::map values_; }; diff --git a/src/legacy/SampSharp/config_composite.cpp b/src/legacy/SampSharp/config_composite.cpp index fefcd193..ffef4a8f 100644 --- a/src/legacy/SampSharp/config_composite.cpp +++ b/src/legacy/SampSharp/config_composite.cpp @@ -16,13 +16,17 @@ #include "config_composite.h" #include -void config_composite::add_config(config* config) { +void config_composite::add_config(config* config) +{ configs_.push_back(config); } -bool config_composite::get_config_string(std::string name, std::string& result) { - for (auto && config : configs_) { - if(config->get_config_string(name, result)) { +bool config_composite::get_config_string(std::string name, std::string& result) +{ + for (auto&& config : configs_) + { + if (config->get_config_string(name, result)) + { return true; } } @@ -30,9 +34,12 @@ bool config_composite::get_config_string(std::string name, std::string& result) return false; } -bool config_composite::get_config_bool(std::string name, bool& result) { - for (auto && config : configs_) { - if(config->get_config_bool(name, result)) { +bool config_composite::get_config_bool(std::string name, bool& result) +{ + for (auto&& config : configs_) + { + if (config->get_config_bool(name, result)) + { return true; } } diff --git a/src/legacy/SampSharp/config_composite.h b/src/legacy/SampSharp/config_composite.h index 2993065f..80f66083 100644 --- a/src/legacy/SampSharp/config_composite.h +++ b/src/legacy/SampSharp/config_composite.h @@ -17,11 +17,13 @@ #include "config.h" #include -class config_composite final : public config { - public: +class config_composite final : public config +{ +public: void add_config(config* config); - bool get_config_string(std::string name, std::string &result) override; + bool get_config_string(std::string name, std::string& result) override; bool get_config_bool(std::string name, bool& result) override; + private: - std::vector configs_; + std::vector configs_; }; diff --git a/src/legacy/SampSharp/config_omp.cpp b/src/legacy/SampSharp/config_omp.cpp index 572d7b22..81c9ccbc 100644 --- a/src/legacy/SampSharp/config_omp.cpp +++ b/src/legacy/SampSharp/config_omp.cpp @@ -18,26 +18,31 @@ #include #include -config_omp::config_omp() { +config_omp::config_omp() +{ // read config file as json std::ifstream input_file("config.json"); - if (!input_file.is_open()) { + if (!input_file.is_open()) + { return; } const auto str = std::string((std::istreambuf_iterator(input_file)), std::istreambuf_iterator()); nlohmann::json json = nlohmann::json::parse(str); - if(!json.is_object()) { + if (!json.is_object()) + { return; } // map the json to a simple flat structure like regular SA-MP config file. We'll only be using a few // keys in SampSharp. If open.mp will provide a different config API in their SDK we'll use that // instead of the json file, once the SDK is released. - for (auto it = json.begin(); it != json.end(); ++it) { - switch (it.value().type()) { - + for (auto it = json.begin(); it != json.end(); ++it) + { + switch (it.value().type()) + { + case nlohmann::detail::value_t::string: values_[it.key()] = it.value().get(); break; @@ -53,26 +58,29 @@ config_omp::config_omp() { case nlohmann::detail::value_t::number_float: values_[it.key()] = std::to_string(it.value().get()); break; - default: ; + default:; } } - // Map the main_scripts (pawn game modes) into gamemodeN keys. auto main_scripts = json["pawn"]["main_scripts"]; int index = 0; - for (auto it = main_scripts.begin(); it != main_scripts.end(); ++it) { - if(it.value().is_string()) { + for (auto it = main_scripts.begin(); it != main_scripts.end(); ++it) + { + if (it.value().is_string()) + { std::string key = "gamemode" + std::to_string(index++); values_[key] = it.value().get(); } } } -bool config_omp::get_config_string(std::string name, std::string& result) { +bool config_omp::get_config_string(std::string name, std::string& result) +{ const auto iterator = values_.find(name); - if (iterator == values_.end()) { + if (iterator == values_.end()) + { return false; } diff --git a/src/legacy/SampSharp/config_omp.h b/src/legacy/SampSharp/config_omp.h index cb604b6d..f8b538e0 100644 --- a/src/legacy/SampSharp/config_omp.h +++ b/src/legacy/SampSharp/config_omp.h @@ -17,10 +17,12 @@ #include "config.h" #include -class config_omp final : public config { - public: +class config_omp final : public config +{ +public: config_omp(); - bool get_config_string(std::string name, std::string &result) override; + bool get_config_string(std::string name, std::string& result) override; + private: std::map values_; }; diff --git a/src/legacy/SampSharp/config_win.cpp b/src/legacy/SampSharp/config_win.cpp index 47f19d63..4cd8e04c 100644 --- a/src/legacy/SampSharp/config_win.cpp +++ b/src/legacy/SampSharp/config_win.cpp @@ -23,20 +23,20 @@ #if SAMPSHARP_WINDOWS #include -std::string wide_to_string(const wchar_t *wc) { +std::string wide_to_string(const wchar_t* wc) +{ std::wstring wide = wc; std::string str(wide.length(), 0); - std::transform(wide.begin(), wide.end(), str.begin(), [] (wchar_t c) { - return (char)c; - }); + std::transform(wide.begin(), wide.end(), str.begin(), [](wchar_t c) { return (char)c; }); return str; } #endif -config_win::config_win() { +config_win::config_win() +{ #if SAMPSHARP_WINDOWS int argc; wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); @@ -45,20 +45,23 @@ config_win::config_win() { { auto key = wide_to_string(argv[i]); - if(key.find("--") != 0 || key.length() <= 2) { + if (key.find("--") != 0 || key.length() <= 2) + { continue; } key = key.substr(2); - + const size_t eq = key.find('='); - if(eq != std::string::npos){ + if (eq != std::string::npos) + { const auto value = key.substr(eq + 1); key = key.substr(0, eq); values_.insert(std::make_pair(key, value)); } - else if (argc > i + 1){ + else if (argc > i + 1) + { const auto value = wide_to_string(argv[++i]); values_.insert(std::make_pair(key, value)); } @@ -66,10 +69,12 @@ config_win::config_win() { #endif } -bool config_win::get_config_string(std::string name, std::string& result) { +bool config_win::get_config_string(std::string name, std::string& result) +{ const auto iterator = values_.find(name); - if (iterator == values_.end()) { + if (iterator == values_.end()) + { return false; } diff --git a/src/legacy/SampSharp/config_win.h b/src/legacy/SampSharp/config_win.h index 48627eed..6a02f156 100644 --- a/src/legacy/SampSharp/config_win.h +++ b/src/legacy/SampSharp/config_win.h @@ -17,10 +17,12 @@ #include "config.h" #include -class config_win final : public config { - public: +class config_win final : public config +{ +public: config_win(); - bool get_config_string(std::string name, std::string &result) override; + bool get_config_string(std::string name, std::string& result) override; + private: std::map values_; }; diff --git a/src/legacy/SampSharp/coreclr_app.cpp b/src/legacy/SampSharp/coreclr_app.cpp index 6c1fda0e..761d39b7 100644 --- a/src/legacy/SampSharp/coreclr_app.cpp +++ b/src/legacy/SampSharp/coreclr_app.cpp @@ -30,41 +30,41 @@ #include #if SAMPSHARP_LINUX -# include -# include -# include -# include -# if defined(__FreeBSD__) -# include -# include -# endif -# if defined(HAVE_SYS_SYSCTL_H) || defined(__FreeBSD__) -# include -# endif +#include +#include +#include +#include +#if defined(__FreeBSD__) +#include +#include +#endif +#if defined(HAVE_SYS_SYSCTL_H) || defined(__FreeBSD__) +#include +#endif #endif #if SAMPSHARP_LINUX -# define __DIR_SEPARATOR_FORWARD +#define __DIR_SEPARATOR_FORWARD #endif #ifdef __DIR_SEPARATOR_FORWARD -# define DIR_SEPARATOR "/" +#define DIR_SEPARATOR "/" #else -# define DIR_SEPARATOR "\\" +#define DIR_SEPARATOR "\\" #endif - #if !defined(PATH_MAX) && defined(MAX_PATH) -# define PATH_MAX MAX_PATH +#define PATH_MAX MAX_PATH #endif #if SAMPSHARP_LINUX -bool coreclr_app::load_symbol(void *coreclr_lib, const char *symbol, - void **ptr) { +bool coreclr_app::load_symbol(void* coreclr_lib, const char* symbol, void** ptr) +{ *ptr = dlsym(coreclr_lib, symbol); - if(!*ptr) { + if (!*ptr) + { log_error("Function %s not found in the libcoreclr.so.", symbol); return false; } @@ -73,8 +73,8 @@ bool coreclr_app::load_symbol(void *coreclr_lib, const char *symbol, } #endif -int coreclr_app::initialize(const char *clr_dir_c, const char* exe_path, - const char* app_domain_friendly_name) { +int coreclr_app::initialize(const char* clr_dir_c, const char* exe_path, const char* app_domain_friendly_name) +{ std::filesystem::path exe_path_p = exe_path; std::filesystem::path clr_dir_p = clr_dir_c; @@ -116,37 +116,39 @@ int coreclr_app::initialize(const char *clr_dir_c, const char* exe_path, #if SAMPSHARP_LINUX module_ = dlopen(coreclr_dll.c_str(), RTLD_NOW | RTLD_LOCAL); - if(!module_) { - const char *error = dlerror(); + if (!module_) + { + const char* error = dlerror(); log_error("Failed to load CoreCLR library: %s.", error); return -1; } - if(!load_symbol(module_, "coreclr_initialize", (void **)&coreclr_initialize_)) { + if (!load_symbol(module_, "coreclr_initialize", (void**)&coreclr_initialize_)) + { return -1; } - if(!load_symbol(module_, "coreclr_shutdown", (void **)&coreclr_shutdown_)) { + if (!load_symbol(module_, "coreclr_shutdown", (void**)&coreclr_shutdown_)) + { return -1; } - if(!load_symbol(module_, "coreclr_shutdown_2", (void **)&coreclr_shutdown_2_)) { + if (!load_symbol(module_, "coreclr_shutdown_2", (void**)&coreclr_shutdown_2_)) + { return -1; } - if(!load_symbol(module_, "coreclr_create_delegate", (void **)&coreclr_create_delegate_)) { + if (!load_symbol(module_, "coreclr_create_delegate", (void**)&coreclr_create_delegate_)) + { return -1; } - if(!load_symbol(module_, "coreclr_execute_assembly", (void **)&coreclr_execute_assembly_)) { + if (!load_symbol(module_, "coreclr_execute_assembly", (void**)&coreclr_execute_assembly_)) + { return -1; } - const char *property_keys[] = { - "TRUSTED_PLATFORM_ASSEMBLIES", - "APP_PATHS", - "APP_NI_PATHS", - "NATIVE_DLL_SEARCH_DIRECTORIES", - "System.GC.Server", - "System.Globalization.Invariant", + const char* property_keys[] = { + "TRUSTED_PLATFORM_ASSEMBLIES", "APP_PATHS", "APP_NI_PATHS", + "NATIVE_DLL_SEARCH_DIRECTORIES", "System.GC.Server", "System.Globalization.Invariant", }; - const char *property_values[] = { + const char* property_values[] = { // TRUSTED_PLATFORM_ASSEMBLIES tpa_list.c_str(), // APP_PATHS @@ -161,15 +163,9 @@ int coreclr_app::initialize(const char *clr_dir_c, const char* exe_path, "false", }; - return coreclr_initialize_( - abs_exe_path_.c_str(), - app_domain_friendly_name, - sizeof(property_keys) / sizeof(property_keys[0]), - property_keys, - property_values, - &host_, - &domain_id_ - ); + return coreclr_initialize_(abs_exe_path_.c_str(), app_domain_friendly_name, + sizeof(property_keys) / sizeof(property_keys[0]), property_keys, property_values, &host_, + &domain_id_); #elif SAMPSHARP_WINDOWS std::wstring wapp_dir = std::wstring(app_dir.begin(), app_dir.end()); std::wstring wclr_dir = std::wstring(clr_dir.begin(), clr_dir.end()); @@ -185,9 +181,8 @@ int coreclr_app::initialize(const char *clr_dir_c, const char* exe_path, return -1; } - - const FnGetCLRRuntimeHost get_clr_runtime_host = FnGetCLRRuntimeHost( - ::GetProcAddress(module_, "GetCLRRuntimeHost")); + const FnGetCLRRuntimeHost get_clr_runtime_host = + FnGetCLRRuntimeHost(::GetProcAddress(module_, "GetCLRRuntimeHost")); if (!get_clr_runtime_host) { @@ -204,18 +199,15 @@ int coreclr_app::initialize(const char *clr_dir_c, const char* exe_path, return -1; } - - hr = host_->SetStartupFlags( - static_cast( - // STARTUP_SERVER_GC | // Use server GC - // STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN | // Maximize domain-neutral loading - // STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST | // Domain-neutral loading for strongly-named assemblies - STARTUP_CONCURRENT_GC | // Use concurrent GC - STARTUP_SINGLE_APPDOMAIN | // All code executes in the default AppDomain - // (required to use the runtimeHost->ExecuteAssembly helper function) - STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN // Prevents domain-neutral loading - ) - ); + hr = host_->SetStartupFlags(static_cast( + // STARTUP_SERVER_GC | // Use server GC + // STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN | // Maximize domain-neutral loading + // STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST | // Domain-neutral loading for strongly-named assemblies + STARTUP_CONCURRENT_GC | // Use concurrent GC + STARTUP_SINGLE_APPDOMAIN | // All code executes in the default AppDomain + // (required to use the runtimeHost->ExecuteAssembly helper function) + STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN // Prevents domain-neutral loading + )); if (FAILED(hr)) { @@ -233,45 +225,32 @@ int coreclr_app::initialize(const char *clr_dir_c, const char* exe_path, const int app_domain_flags = // APPDOMAIN_FORCE_TRIVIAL_WAIT_OPERATIONS | // Do not pump messages during wait - // APPDOMAIN_SECURITY_SANDBOXED | // Causes assemblies not from the TPA list to be loaded as partially trusted - APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS | // Enable platform-specific assemblies to run - APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP | // Allow PInvoking from non-TPA assemblies - APPDOMAIN_DISABLE_TRANSPARENCY_ENFORCEMENT; // Entirely disables transparency checks + // APPDOMAIN_SECURITY_SANDBOXED | // Causes assemblies not from the TPA list to be loaded as + // partially trusted + APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS | // Enable platform-specific assemblies to run + APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP | // Allow PInvoking from non-TPA assemblies + APPDOMAIN_DISABLE_TRANSPARENCY_ENFORCEMENT; // Entirely disables transparency checks // Setup key/value pairs for AppDomain properties - const wchar_t* propertyKeys[] = { - L"TRUSTED_PLATFORM_ASSEMBLIES", - L"APP_PATHS", - L"APP_NI_PATHS", - L"NATIVE_DLL_SEARCH_DIRECTORIES", - L"PLATFORM_RESOURCE_ROOTS", - L"AppDomainCompatSwitch" - }; + const wchar_t* propertyKeys[] = {L"TRUSTED_PLATFORM_ASSEMBLIES", + L"APP_PATHS", + L"APP_NI_PATHS", + L"NATIVE_DLL_SEARCH_DIRECTORIES", + L"PLATFORM_RESOURCE_ROOTS", + L"AppDomainCompatSwitch"}; std::wstring wtpa_list = std::wstring(tpa_list.begin(), tpa_list.end()); std::wstring wnative_search_dirs = std::wstring(native_search_dirs.begin(), native_search_dirs.end()); // Property values which were constructed in step 5 - const wchar_t* propertyValues[] = { - wtpa_list.c_str(), - wapp_dir.c_str(), - wapp_dir.c_str(), - wnative_search_dirs.c_str(), - wapp_dir.c_str(), - L"UseLatestBehaviorWhenTFMNotSpecified" - }; - + const wchar_t* propertyValues[] = {wtpa_list.c_str(), wapp_dir.c_str(), + wapp_dir.c_str(), wnative_search_dirs.c_str(), + wapp_dir.c_str(), L"UseLatestBehaviorWhenTFMNotSpecified"}; // Create the AppDomain - hr = host_->CreateAppDomainWithManager( - wapp_domain_friendly_name.c_str(), - app_domain_flags, - nullptr, - nullptr, - sizeof(propertyKeys)/sizeof(wchar_t*), - propertyKeys, - propertyValues, - &domain_id_); + hr = host_->CreateAppDomainWithManager(wapp_domain_friendly_name.c_str(), app_domain_flags, nullptr, nullptr, + sizeof(propertyKeys) / sizeof(wchar_t*), propertyKeys, propertyValues, + &domain_id_); if (FAILED(hr)) { @@ -283,14 +262,15 @@ int coreclr_app::initialize(const char *clr_dir_c, const char* exe_path, #endif } -int coreclr_app::construct_tpa(const char *directory, std::string &tpa_list) { +int coreclr_app::construct_tpa(const char* directory, std::string& tpa_list) +{ #if SAMPSHARP_LINUX - const char * const tpaExtensions[] = { - ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir - ".dll", - ".ni.exe", - ".exe", - }; + const char* const tpaExtensions[] = { + ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir + ".dll", + ".ni.exe", + ".exe", + }; DIR* dir = opendir(directory); if (dir == nullptr) @@ -322,25 +302,25 @@ int coreclr_app::construct_tpa(const char *directory, std::string &tpa_list) { // Handle symlinks and file systems that do not support d_type case DT_LNK: case DT_UNKNOWN: + { + std::string fullFilename; + + fullFilename.append(directory); + fullFilename.append("/"); + fullFilename.append(entry->d_name); + + struct stat sb; + if (stat(fullFilename.c_str(), &sb) == -1) { - std::string fullFilename; - - fullFilename.append(directory); - fullFilename.append("/"); - fullFilename.append(entry->d_name); - - struct stat sb; - if (stat(fullFilename.c_str(), &sb) == -1) - { - continue; - } - - if (!S_ISREG(sb.st_mode)) - { - continue; - } + continue; } - break; + + if (!S_ISREG(sb.st_mode)) + { + continue; + } + } + break; default: continue; @@ -376,11 +356,7 @@ int coreclr_app::construct_tpa(const char *directory, std::string &tpa_list) { closedir(dir); #elif SAMPSHARP_WINDOWS - const wchar_t *tpaExtensions[] = { - L"*.dll", - L"*.exe", - L"*.winmd" - }; + const wchar_t* tpaExtensions[] = {L"*.dll", L"*.exe", L"*.winmd"}; for (int i = 0; i < _countof(tpaExtensions); i++) { @@ -401,16 +377,13 @@ int coreclr_app::construct_tpa(const char *directory, std::string &tpa_list) { std::wstring wname = std::wstring(find.cFileName); std::string name(wname.length(), 0); - std::transform(wname.begin(), wname.end(), name.begin(), [] (wchar_t c) { - return (char)c; - }); + std::transform(wname.begin(), wname.end(), name.begin(), [](wchar_t c) { return (char)c; }); tpa_list.append(std::string(directory)); tpa_list.append(DIR_SEPARATOR); tpa_list.append(name); tpa_list.append(TPA_DELIMITER); - } - while (FindNextFileW(fhandle, &find)); + } while (FindNextFileW(fhandle, &find)); FindClose(fhandle); } } @@ -418,9 +391,10 @@ int coreclr_app::construct_tpa(const char *directory, std::string &tpa_list) { return 0; } -void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, - std::string &tpa_list) { - if(std::filesystem::path(abs_exe_path).extension() != ".dll") { +void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, std::string& tpa_list) +{ + if (std::filesystem::path(abs_exe_path).extension() != ".dll") + { return; } @@ -432,12 +406,14 @@ void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, runtimeconfig_path_p = abs_exe_path; runtimeconfig_path_p = runtimeconfig_path_p.replace_extension(".runtimeconfig.dev.json"); - if(!exists(runtimeconfig_path_p)) { - runtimeconfig_path_p = abs_exe_path; - runtimeconfig_path_p = runtimeconfig_path_p.replace_extension(".runtimeconfig.json"); + if (!exists(runtimeconfig_path_p)) + { + runtimeconfig_path_p = abs_exe_path; + runtimeconfig_path_p = runtimeconfig_path_p.replace_extension(".runtimeconfig.json"); } - - if(!exists(runtimeconfig_path_p)) { + + if (!exists(runtimeconfig_path_p)) + { return; } @@ -447,7 +423,8 @@ void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, std::filesystem::path deps_path_p(abs_exe_path); deps_path_p = deps_path_p.replace_extension(".deps.json"); - if(!exists(deps_path_p)) { + if (!exists(deps_path_p)) + { return; } @@ -460,44 +437,43 @@ void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, std::ifstream runtimeconfig_stream(runtimeconfig_path); std::string runtimeconfig_json; - runtimeconfig_stream.seekg(0, std::ios::end); + runtimeconfig_stream.seekg(0, std::ios::end); runtimeconfig_json.reserve((size_t)runtimeconfig_stream.tellg()); runtimeconfig_stream.seekg(0, std::ios::beg); - runtimeconfig_json.assign( - std::istreambuf_iterator(runtimeconfig_stream), - std::istreambuf_iterator()); + runtimeconfig_json.assign(std::istreambuf_iterator(runtimeconfig_stream), std::istreambuf_iterator()); runtimeconfig_stream.close(); std::ifstream deps_stream(deps_path); std::string deps_json; - deps_stream.seekg(0, std::ios::end); + deps_stream.seekg(0, std::ios::end); deps_json.reserve((size_t)deps_stream.tellg()); deps_stream.seekg(0, std::ios::beg); - deps_json.assign( - std::istreambuf_iterator(deps_stream), - std::istreambuf_iterator()); + deps_json.assign(std::istreambuf_iterator(deps_stream), std::istreambuf_iterator()); deps_stream.close(); // Find probing paths - + nlohmann::json runtimeconfig = nlohmann::json::parse(runtimeconfig_json); - + std::vector probing_paths; - + auto probes = runtimeconfig["runtimeOptions"]["additionalProbingPaths"]; - for (auto it = probes.begin(); it != probes.end(); ++it) { - if(!it.value().is_string()) { + for (auto it = probes.begin(); it != probes.end(); ++it) + { + if (!it.value().is_string()) + { continue; } std::string path = it.value().get(); - - if(is_directory(std::filesystem::path(path))) { + + if (is_directory(std::filesystem::path(path))) + { probing_paths.push_back(path); log_debug("Probe path found: %s", path.c_str()); @@ -509,11 +485,13 @@ int coreclr_app::release() { int retval = -1; #if SAMPSHARP_LINUX - if(coreclr_shutdown_) { + if (coreclr_shutdown_) + { retval = coreclr_shutdown_(host_, domain_id_); } - if(module_) { + if (module_) + { dlclose(module_); module_ = NULL; } @@ -524,7 +502,8 @@ int coreclr_app::release() host_->Stop(); retval = (int)host_->Release(); - if(module_) { + if (module_) + { FreeLibrary(module_); module_ = nullptr; } @@ -533,15 +512,16 @@ int coreclr_app::release() return retval; } -int coreclr_app::create_delegate(const char* assembly_name, - const char* type_name, const char* method_name, void** delegate) { +int coreclr_app::create_delegate(const char* assembly_name, const char* type_name, const char* method_name, + void** delegate) +{ #if SAMPSHARP_LINUX - if(!coreclr_create_delegate_) { + if (!coreclr_create_delegate_) + { return -1; } - return coreclr_create_delegate_(host_, domain_id_, assembly_name, - type_name, method_name, delegate); + return coreclr_create_delegate_(host_, domain_id_, assembly_name, type_name, method_name, delegate); #elif SAMPSHARP_WINDOWS std::string an = std::string(assembly_name); @@ -552,13 +532,15 @@ int coreclr_app::create_delegate(const char* assembly_name, std::wstring wtn = std::wstring(tn.begin(), tn.end()); std::wstring wmn = std::wstring(mn.begin(), mn.end()); - return host_->CreateDelegate(domain_id_, wan.c_str(), wtn.c_str(), wmn.c_str(), (INT_PTR*)delegate); + return host_->CreateDelegate(domain_id_, wan.c_str(), wtn.c_str(), wmn.c_str(), (INT_PTR*)delegate); #endif } -int coreclr_app::execute_assembly(int argc, const char** argv, unsigned int* exit_code) { +int coreclr_app::execute_assembly(int argc, const char** argv, unsigned int* exit_code) +{ #if SAMPSHARP_LINUX - if(!coreclr_execute_assembly_) { + if (!coreclr_execute_assembly_) + { return -1; } @@ -571,14 +553,16 @@ int coreclr_app::execute_assembly(int argc, const char** argv, unsigned int* exi size_t written; size_t len = argc; - for(int i = 0; i < argc; i++) { + for (int i = 0; i < argc; i++) + { len += strlen(argv[i]); } - - wchar_t *wargs = new wchar_t[len]; - wchar_t **wargv = new wchar_t*[argc]; - for(int i = 0; i < argc; i++) { + wchar_t* wargs = new wchar_t[len]; + wchar_t** wargv = new wchar_t*[argc]; + + for (int i = 0; i < argc; i++) + { wargs[pos] = L'\0'; mbstowcs_s(&written, wargs + pos, len - pos, argv[i], len - pos); @@ -588,7 +572,8 @@ int coreclr_app::execute_assembly(int argc, const char** argv, unsigned int* exi // Execute DWORD dexit_code = -1; - const DWORD retval = host_->ExecuteAssembly(domain_id_, wabs_exe_path.c_str(), argc, (const wchar_t **)wargv, &dexit_code); + const DWORD retval = + host_->ExecuteAssembly(domain_id_, wabs_exe_path.c_str(), argc, (const wchar_t**)wargv, &dexit_code); *exit_code = dexit_code; diff --git a/src/legacy/SampSharp/coreclr_app.h b/src/legacy/SampSharp/coreclr_app.h index d35f797d..655cb7ab 100644 --- a/src/legacy/SampSharp/coreclr_app.h +++ b/src/legacy/SampSharp/coreclr_app.h @@ -18,54 +18,52 @@ #include #include "platforms.h" #if SAMPSHARP_LINUX -# include +#include #elif SAMPSHARP_WINDOWS -# include +#include #endif #if SAMPSHARP_LINUX -# define CORECLR_CALL -# define CORECLR_LIB "libcoreclr.so" -# define TPA_DELIMITER ":" +#define CORECLR_CALL +#define CORECLR_LIB "libcoreclr.so" +#define TPA_DELIMITER ":" #elif SAMPSHARP_WINDOWS -# define CORECLR_CALL __stdcall -# define CORECLR_LIB "coreclr.dll" -# define TPA_DELIMITER ";" +#define CORECLR_CALL __stdcall +#define CORECLR_LIB "coreclr.dll" +#define TPA_DELIMITER ";" #endif #if SAMPSHARP_LINUX typedef void host_t; typedef unsigned int domaind_id_t; -typedef void * module_t; +typedef void* module_t; #elif SAMPSHARP_WINDOWS typedef ICLRRuntimeHost2 host_t; typedef DWORD domaind_id_t; typedef HMODULE module_t; #endif - -class coreclr_app { +class coreclr_app +{ public: - int initialize(const char *clr_dir, const char* exe_path, - const char* app_domain_friendly_name); - int create_delegate(const char* assembly_name, const char* type_name, - const char* method_name, void** delegate); + int initialize(const char* clr_dir, const char* exe_path, const char* app_domain_friendly_name); + int create_delegate(const char* assembly_name, const char* type_name, const char* method_name, void** delegate); int execute_assembly(int argc, const char** argv, unsigned int* exit_code); int release(); private: - int construct_tpa(const char *directory, std::string &tpa_list); - void add_deps_to_tpa(std::string abs_exe_path, std::string &tpa_list); + int construct_tpa(const char* directory, std::string& tpa_list); + void add_deps_to_tpa(std::string abs_exe_path, std::string& tpa_list); private: std::string abs_exe_path_; - host_t *host_ = NULL; + host_t* host_ = NULL; module_t module_ = NULL; domaind_id_t domain_id_ = 0; #if SAMPSHARP_LINUX private: - bool load_symbol(void *coreclr_lib, const char *symbol, void **ptr); + bool load_symbol(void* coreclr_lib, const char* symbol, void** ptr); coreclr_initialize_ptr coreclr_initialize_ = NULL; coreclr_shutdown_ptr coreclr_shutdown_ = NULL; @@ -74,4 +72,3 @@ class coreclr_app { coreclr_execute_assembly_ptr coreclr_execute_assembly_ = NULL; #endif }; - diff --git a/src/legacy/SampSharp/includes/.clang-format b/src/legacy/SampSharp/includes/.clang-format new file mode 100644 index 00000000..57fe428d --- /dev/null +++ b/src/legacy/SampSharp/includes/.clang-format @@ -0,0 +1,3 @@ +--- +DisableFormat: true +... diff --git a/src/legacy/SampSharp/interop.cpp b/src/legacy/SampSharp/interop.cpp index b6ab9534..2e38f163 100644 --- a/src/legacy/SampSharp/interop.cpp +++ b/src/legacy/SampSharp/interop.cpp @@ -16,45 +16,53 @@ #include "interop.h" #include "platforms.h" -struct sampsharp_api_t { +struct sampsharp_api_t +{ size_t size; - void **plugin_data; - void *find_native; - void *invoke_native; + void** plugin_data; + void* find_native; + void* invoke_native; } sampsharp_api; -typedef void api_public_call_t(AMX *amx, const char *name, cell *params, cell *retval); +typedef void api_public_call_t(AMX* amx, const char* name, cell* params, cell* retval); typedef void api_tick_t(); -api_public_call_t *bound_public_call = nullptr; -api_tick_t *bound_tick = nullptr; +api_public_call_t* bound_public_call = nullptr; +api_tick_t* bound_tick = nullptr; -void sampsharp_api_setup(void **plugin_data) { +void sampsharp_api_setup(void** plugin_data) +{ sampsharp_api.size = sizeof(sampsharp_api); sampsharp_api.plugin_data = plugin_data; - sampsharp_api.find_native = (void *)sampgdk_FindNative; - sampsharp_api.invoke_native = (void *)sampgdk_InvokeNativeArray; + sampsharp_api.find_native = (void*)sampgdk_FindNative; + sampsharp_api.invoke_native = (void*)sampgdk_InvokeNativeArray; } -void sampsharp_api_cleanup() { +void sampsharp_api_cleanup() +{ sampsharp_api.plugin_data = nullptr; bound_public_call = nullptr; bound_tick = nullptr; } -void sampsharp_api_public_call(AMX *amx, const char *name, cell *params, cell *retval) { - if(bound_public_call) { +void sampsharp_api_public_call(AMX* amx, const char* name, cell* params, cell* retval) +{ + if (bound_public_call) + { bound_public_call(amx, name, params, retval); } } -void sampsharp_api_tick() { - if(bound_tick) { +void sampsharp_api_tick() +{ + if (bound_tick) + { bound_tick(); } } -SAMPSHARP_EXPORT void SAMPSHARP_CALL_PTR sampsharp_api_initialize(api_public_call_t *public_call, api_tick_t* tick) { +SAMPSHARP_EXPORT void SAMPSHARP_CALL_PTR sampsharp_api_initialize(api_public_call_t* public_call, api_tick_t* tick) +{ bound_public_call = public_call; bound_tick = tick; return &sampsharp_api; diff --git a/src/legacy/SampSharp/interop.h b/src/legacy/SampSharp/interop.h index 5533e70a..a10375d1 100644 --- a/src/legacy/SampSharp/interop.h +++ b/src/legacy/SampSharp/interop.h @@ -17,8 +17,8 @@ #include -void sampsharp_api_setup(void **plugin_data); +void sampsharp_api_setup(void** plugin_data); void sampsharp_api_cleanup(); -void sampsharp_api_public_call(AMX *amx, const char *name, cell *params, cell *retval); +void sampsharp_api_public_call(AMX* amx, const char* name, cell* params, cell* retval); void sampsharp_api_tick(); \ No newline at end of file diff --git a/src/legacy/SampSharp/locator.cpp b/src/legacy/SampSharp/locator.cpp index 72975b51..fc7845e7 100644 --- a/src/legacy/SampSharp/locator.cpp +++ b/src/legacy/SampSharp/locator.cpp @@ -24,27 +24,31 @@ #if SAMPSHARP_WINDOWS #define HOSTFXR_LIB "hostfxr.dll" -# define CORECLR_LIB "coreclr.dll" +#define CORECLR_LIB "coreclr.dll" #elif SAMPSHARP_LINUX #define HOSTFXR_LIB "libhostfxr.so" -# define CORECLR_LIB "libcoreclr.so" +#define CORECLR_LIB "libcoreclr.so" #endif -locator::locator(config* cfg) : cfg_(cfg) {} +locator::locator(config* cfg) : + cfg_(cfg) +{ +} -fs::path locator::get_hostfxr() const { +fs::path locator::get_hostfxr() const +{ std::string hint; fs::path result; - cfg_->get_config_string("coreclr", hint) || - cfg_->get_config_string("runtime", hint); + cfg_->get_config_string("coreclr", hint) || cfg_->get_config_string("runtime", hint); detect_lib(result, hint, HOSTFXR_LIB); return result; } -fs::path locator::get_coreclr() const { +fs::path locator::get_coreclr() const +{ std::string hint; fs::path result; cfg_->get_config_string("runtime", hint); @@ -54,7 +58,8 @@ fs::path locator::get_coreclr() const { return result; } -fs::path locator::get_gamemode() const { +fs::path locator::get_gamemode() const +{ std::string base, gamemode; fs::path result; cfg_->get_config_string("gamemode", gamemode); @@ -65,8 +70,10 @@ fs::path locator::get_gamemode() const { return result; } -bool locator::detect_lib_recursive(fs::path& result, const fs::path& search_path, const std::string& lib) { - if (!is_directory(search_path)) { +bool locator::detect_lib_recursive(fs::path& result, const fs::path& search_path, const std::string& lib) +{ + if (!is_directory(search_path)) + { return false; } @@ -74,14 +81,17 @@ bool locator::detect_lib_recursive(fs::path& result, const fs::path& search_path // Check in current directory const fs::path check_path = search_path / lib; - if (exists(check_path)) { + if (exists(check_path)) + { result = check_path; return true; } // Check every subdirectory - for (const auto& entry : fs::directory_iterator(search_path)) { - if (entry.is_directory() && detect_lib_recursive(result, entry.path(), lib)) { + for (const auto& entry : fs::directory_iterator(search_path)) + { + if (entry.is_directory() && detect_lib_recursive(result, entry.path(), lib)) + { return true; } } @@ -89,54 +99,61 @@ bool locator::detect_lib_recursive(fs::path& result, const fs::path& search_path return false; } -bool locator::detect_lib(fs::path& result, const std::string& path_hint, const std::string& lib) { - if (!path_hint.empty()) { +bool locator::detect_lib(fs::path& result, const std::string& path_hint, const std::string& lib) +{ + if (!path_hint.empty()) + { const fs::path hint = path_hint; - - if (hint.filename() == lib && exists(hint)) { + if (hint.filename() == lib && exists(hint)) + { result = hint; return true; } - if (is_directory(hint) && detect_lib_recursive(result, fs::path("runtime"), lib)) { + if (is_directory(hint) && detect_lib_recursive(result, fs::path("runtime"), lib)) + { return true; } } const auto runtime = getenv("SAMPSHARP_RUNTIME"); - return - runtime && strlen(runtime) > 0 && detect_lib_recursive(result, fs::path(runtime), lib) || - detect_lib_recursive(result, fs::path("runtime"), lib) || - detect_lib_recursive(result, fs::path("dotnet"), lib); + return runtime && strlen(runtime) > 0 && detect_lib_recursive(result, fs::path(runtime), lib) || + detect_lib_recursive(result, fs::path("runtime"), lib) || + detect_lib_recursive(result, fs::path("dotnet"), lib); } -bool is_runtime_config(const fs::path& path, const std::string& search_name) { - if(search_name.length() == 0) { +bool is_runtime_config(const fs::path& path, const std::string& search_name) +{ + if (search_name.length() == 0) + { return path.extension() == ".json" && path.stem().extension() == ".runtimeconfig"; } return iequals(path.filename().string(), search_name); } -bool locator::detect_gamemode_recursive(fs::path& result, const std::string& search_name, const fs::path& search_path) { - if (!is_directory(search_path)) { +bool locator::detect_gamemode_recursive(fs::path& result, const std::string& search_name, const fs::path& search_path) +{ + if (!is_directory(search_path)) + { return false; } log_debug("Checking for game mode in %s...", search_path.string().c_str()); // Check in current directory - for (const auto& entry : fs::directory_iterator(search_path)) { + for (const auto& entry : fs::directory_iterator(search_path)) + { - if (entry.is_regular_file() && is_runtime_config(entry.path(), search_name)) { + if (entry.is_regular_file() && is_runtime_config(entry.path(), search_name)) + { fs::path rc_path = entry.path(); - fs::path dll_path = rc_path - .replace_extension("") - .replace_extension(".dll"); // .runtimeconfig.json -> .dll + fs::path dll_path = rc_path.replace_extension("").replace_extension(".dll"); // .runtimeconfig.json -> .dll - if (exists(dll_path)) { + if (exists(dll_path)) + { result = dll_path; return true; } @@ -148,31 +165,38 @@ bool locator::detect_gamemode_recursive(fs::path& result, const std::string& sea int best_version_number = 0; fs::path best_version; - for (const auto& entry : fs::directory_iterator(search_path)) { - if (!entry.is_directory()) { + for (const auto& entry : fs::directory_iterator(search_path)) + { + if (!entry.is_directory()) + { continue; } fs::path entry_path = entry.path(); std::string entry_dirname = entry_path.filename().string(); std::smatch match; - if (std::regex_match(entry_dirname, match, regex_version)) { + if (std::regex_match(entry_dirname, match, regex_version)) + { int version_number = stoi(match[1]) * 1000 + stoi(match[2]); - if (version_number > best_version_number) { + if (version_number > best_version_number) + { best_version = entry_path; best_version_number = version_number; } } } - if (!best_version.empty() && detect_gamemode_recursive(result, search_name, best_version)) { + if (!best_version.empty() && detect_gamemode_recursive(result, search_name, best_version)) + { return true; } // Check every subdirectory - for (const auto& entry : fs::directory_iterator(search_path)) { - if (entry.is_directory() && detect_gamemode_recursive(result, search_name, entry.path())) { + for (const auto& entry : fs::directory_iterator(search_path)) + { + if (entry.is_directory() && detect_gamemode_recursive(result, search_name, entry.path())) + { return true; } } @@ -180,13 +204,11 @@ bool locator::detect_gamemode_recursive(fs::path& result, const std::string& sea return false; } -bool locator::detect_gamemode(const std::string& dir_hint, const std::string& name, fs::path& result) { - const auto search_name = name.length() == 0 - ? "" - : name + ".runtimeconfig.json"; +bool locator::detect_gamemode(const std::string& dir_hint, const std::string& name, fs::path& result) +{ + const auto search_name = name.length() == 0 ? "" : name + ".runtimeconfig.json"; - return - (dir_hint.length() > 0 && detect_gamemode_recursive(result, search_name, dir_hint)) || - detect_gamemode_recursive(result, search_name, "gamemode") || - detect_gamemode_recursive(result, search_name, "gamemodes"); + return (dir_hint.length() > 0 && detect_gamemode_recursive(result, search_name, dir_hint)) || + detect_gamemode_recursive(result, search_name, "gamemode") || + detect_gamemode_recursive(result, search_name, "gamemodes"); } diff --git a/src/legacy/SampSharp/locator.h b/src/legacy/SampSharp/locator.h index 1d696451..f58fa937 100644 --- a/src/legacy/SampSharp/locator.h +++ b/src/legacy/SampSharp/locator.h @@ -25,19 +25,20 @@ namespace fs = std::filesystem; class locator { public: - locator(config *cfg); + locator(config* cfg); /* returns path to libhostfxr. */ fs::path get_hostfxr() const; /* returns path to libcoreclr. */ fs::path get_coreclr() const; /* returns path to runtimeconfig of gamemode. */ fs::path get_gamemode() const; - + private: static bool detect_lib_recursive(fs::path& result, const fs::path& search_path, const std::string& lib); - static bool detect_lib(fs::path &result, const std::string &path_hint, const std::string &lib); - static bool detect_gamemode_recursive(fs::path& result, const std::string& search_name, const fs::path& search_path); - static bool detect_gamemode(const std::string &dir_hint, const std::string &name, fs::path &result); + static bool detect_lib(fs::path& result, const std::string& path_hint, const std::string& lib); + static bool detect_gamemode_recursive(fs::path& result, const std::string& search_name, + const fs::path& search_path); + static bool detect_gamemode(const std::string& dir_hint, const std::string& name, fs::path& result); - config *cfg_; + config* cfg_; }; \ No newline at end of file diff --git a/src/legacy/SampSharp/logging.cpp b/src/legacy/SampSharp/logging.cpp index f66ab0c1..89ceeb28 100644 --- a/src/legacy/SampSharp/logging.cpp +++ b/src/legacy/SampSharp/logging.cpp @@ -21,13 +21,14 @@ /* platform specifics */ #if SAMPSHARP_WINDOWS -# define vsnprintf vsprintf_s +#define vsnprintf vsprintf_s #endif -#define LEN_PRINT_BUFFER (1024) +#define LEN_PRINT_BUFFER (1024) /** log a message */ -void vlog(const char* prefix, const char *format, va_list args) { +void vlog(const char* prefix, const char* format, va_list args) +{ char buffer[LEN_PRINT_BUFFER]; vsnprintf(buffer, LEN_PRINT_BUFFER, format, args); buffer[LEN_PRINT_BUFFER - 1] = '\0'; @@ -35,7 +36,8 @@ void vlog(const char* prefix, const char *format, va_list args) { sampgdk_logprintf("[SampSharp:%s] %s", prefix, buffer); } -void log_print(const char *format, ...) { +void log_print(const char* format, ...) +{ va_list args; va_start(args, format); sampgdk_vlogprintf(format, args); @@ -43,7 +45,8 @@ void log_print(const char *format, ...) { } /** log error */ -void log_error(const char * format, ...) { +void log_error(const char* format, ...) +{ va_list args; va_start(args, format); vlog("ERROR", format, args); @@ -51,7 +54,8 @@ void log_error(const char * format, ...) { } /** log error */ -void log_warning(const char * format, ...) { +void log_warning(const char* format, ...) +{ va_list args; va_start(args, format); vlog("WARNING", format, args); @@ -59,7 +63,8 @@ void log_warning(const char * format, ...) { } /** log debug */ -void log_debug2(const char * format, ...) { +void log_debug2(const char* format, ...) +{ va_list args; va_start(args, format); vlog("DEBUG", format, args); @@ -67,7 +72,8 @@ void log_debug2(const char * format, ...) { } /** log info */ -void log_info(const char * format, ...) { +void log_info(const char* format, ...) +{ va_list args; va_start(args, format); vlog("INFO", format, args); diff --git a/src/legacy/SampSharp/logging.h b/src/legacy/SampSharp/logging.h index b899dbcc..7c6fc278 100644 --- a/src/legacy/SampSharp/logging.h +++ b/src/legacy/SampSharp/logging.h @@ -17,23 +17,23 @@ #include "platforms.h" -void log_debug2(const char *format, ...); +void log_debug2(const char* format, ...); /** prints text to the output */ -void log_print(const char *format, ...); +void log_print(const char* format, ...); /** log an error */ -void log_error(const char *format, ...); +void log_error(const char* format, ...); /** log a warning */ -void log_warning(const char *format, ...); +void log_warning(const char* format, ...); /** log debug info */ #ifdef LOG_DEBUG #define log_debug(format, ...) log_debug2(format, ##__VA_ARGS__) #else -#define log_debug(format, ...) while(0) +#define log_debug(format, ...) while (0) #endif /** log info */ -void log_info(const char *format, ...); +void log_info(const char* format, ...); diff --git a/src/legacy/SampSharp/main.cpp b/src/legacy/SampSharp/main.cpp index ddedafee..add58759 100644 --- a/src/legacy/SampSharp/main.cpp +++ b/src/legacy/SampSharp/main.cpp @@ -26,19 +26,22 @@ #include "interop.h" #include "nethost_coreclr.h" -nethost *host = nullptr; +nethost* host = nullptr; bool started = false; -extern void *pAMXFunctions; +extern void* pAMXFunctions; -void write_empty_gamemode() { - if(fs::exists("gamemodes/empty.amx")) { +void write_empty_gamemode() +{ + if (fs::exists("gamemodes/empty.amx")) + { return; } log_info("Writing gamemodes/empty.amx to disk"); - if(!fs::exists("gamemodes")) { + if (!fs::exists("gamemodes")) + { fs::create_directory("gamemodes"); } @@ -46,25 +49,27 @@ void write_empty_gamemode() { fout.open("gamemodes/empty.amx", std::ios::binary | std::ios::out); // compiled bytecode for script: main() return; - const uint8_t empty_amx[] = { - 0x45, 0x00, 0x00, 0x00, 0xE0, 0xF1, 0x08, 0x08, 0x04, 0x00, 0x08, 0x00, 0x3C, 0x00, 0x00, 0x00, - 0x54, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x54, 0x40, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x80, 0x78, 0x00, 0x2E, - 0x81, 0x09, 0x80, 0x59, 0x30}; - - fout.write((const char *)empty_amx, sizeof(empty_amx)); + const uint8_t empty_amx[] = {0x45, 0x00, 0x00, 0x00, 0xE0, 0xF1, 0x08, 0x08, 0x04, 0x00, 0x08, 0x00, 0x3C, 0x00, + 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x54, 0x40, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x1F, 0x00, 0x00, 0x00, 0x80, 0x78, 0x00, 0x2E, 0x81, 0x09, 0x80, 0x59, 0x30}; + + fout.write((const char*)empty_amx, sizeof(empty_amx)); fout.close(); } -bool validate_config(config *cfg) { +bool validate_config(config* cfg) +{ bool skip; - if(cfg->get_config_bool("skip_empty_check", skip) && skip) { + if (cfg->get_config_bool("skip_empty_check", skip) && skip) + { return true; } - + /* check whether gamemodeN values contain acceptable values. */ - for (int i = 0; i < 15; i++) { + for (int i = 0; i < 15; i++) + { std::ostringstream gamemode_key; std::string gamemode_value; @@ -74,17 +79,19 @@ bool validate_config(config *cfg) { const bool exists = cfg->get_config_string(gamemode_key.str(), gamemode_value); const bool is_empty = gamemode_value == "empty" || gamemode_value.rfind("empty ") == 0; - if (i == 0 && !is_empty) { + if (i == 0 && !is_empty) + { log_error("Can not load sampsharp if a non-SampSharp gamemode is set to load."); log_error("Please ensure you set 'gamemode0 empty 1' in your server.cfg file."); log_error("To override this behaviour add 'skip_empty_check 1' to your server.cfg file."); return false; } - if (i > 0 && exists) { + if (i > 0 && exists) + { log_error("Can not load sampsharp if a non-SampSharp gamemode is set to load."); log_error("Please ensure you only specify one script gamemode, namely 'gamemode0" - "empty 1' in your server.cfg file."); + "empty 1' in your server.cfg file."); log_error("To override this behaviour add 'skip_empty_check 1' to your server.cfg file."); return false; } @@ -95,15 +102,19 @@ bool validate_config(config *cfg) { return true; } -PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() { +PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() +{ return sampgdk::Supports() | SUPPORTS_PROCESS_TICK | SUPPORTS_AMX_NATIVES; } -bool is_open_mp(void **ppData) { +bool is_open_mp(void** ppData) +{ // open.mp sets plugin data to zero for uninitialized fields. probe a few to make some assumptions. // it might however be a better idea to simply check the name of the current process... - for (int i = 0x02; i < 0x10; i++) { - if (ppData[i] != nullptr) { + for (int i = 0x02; i < 0x10; i++) + { + if (ppData[i] != nullptr) + { return false; } } @@ -111,8 +122,10 @@ bool is_open_mp(void **ppData) { return true; } -PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { - if (!sampgdk::Load(ppData)) { +PLUGIN_EXPORT bool PLUGIN_CALL Load(void** ppData) +{ + if (!sampgdk::Load(ppData)) + { return false; } @@ -120,7 +133,7 @@ PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { sampsharp_api_setup(ppData); log_info("v%s, (C)2014-2022 Tim Potze", PLUGIN_VERSION_STR); - + config_composite config; #if SAMPSHARP_WINDOWS @@ -130,7 +143,8 @@ PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { #endif config_omp config_omp; - if(is_open_mp(ppData)) { + if (is_open_mp(ppData)) + { log_debug("Adding open.mp config reader"); config.add_config(&config_omp); } @@ -140,22 +154,25 @@ PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { locator loc(&config); - if(!validate_config(&config)) { + if (!validate_config(&config)) + { return false; } - + host = new nethost_coreclr(); - if(!host->setup(&loc, &config)) { + if (!host->setup(&loc, &config)) + { delete host; host = nullptr; return false; } - + return true; } -PLUGIN_EXPORT void PLUGIN_CALL Unload() { +PLUGIN_EXPORT void PLUGIN_CALL Unload() +{ delete host; host = nullptr; @@ -163,25 +180,29 @@ PLUGIN_EXPORT void PLUGIN_CALL Unload() { sampgdk::Unload(); } -PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX* amx) { +PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX* amx) +{ return load_test_natives(amx); } -PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX* amx) { +PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX* amx) +{ return 1; } -PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() { +PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() +{ sampsharp_api_tick(); } -PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall(AMX *amx, const char *name, - cell *params, cell *retval) { - if(!started && host) { +PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall(AMX* amx, const char* name, cell* params, cell* retval) +{ + if (!started && host) + { started = true; host->start(); } - + sampsharp_api_public_call(amx, name, params, retval); return true; } diff --git a/src/legacy/SampSharp/nethost.h b/src/legacy/SampSharp/nethost.h index 025eb837..e54de4b2 100644 --- a/src/legacy/SampSharp/nethost.h +++ b/src/legacy/SampSharp/nethost.h @@ -17,10 +17,11 @@ #include "config.h" #include "locator.h" -class nethost { +class nethost +{ public: virtual ~nethost() = default; - virtual bool setup(locator *locator, config* cfg) = 0; + virtual bool setup(locator* locator, config* cfg) = 0; virtual void start() = 0; virtual void stop() = 0; }; diff --git a/src/legacy/SampSharp/nethost_coreclr.cpp b/src/legacy/SampSharp/nethost_coreclr.cpp index 7bc5075a..9eb57645 100644 --- a/src/legacy/SampSharp/nethost_coreclr.cpp +++ b/src/legacy/SampSharp/nethost_coreclr.cpp @@ -16,21 +16,24 @@ #include "nethost_coreclr.h" #include "logging.h" -nethost_coreclr::~nethost_coreclr() { +nethost_coreclr::~nethost_coreclr() +{ release(); } -bool nethost_coreclr::setup(locator *locator, config* cfg) { +bool nethost_coreclr::setup(locator* locator, config* cfg) +{ coreclr_ = locator->get_coreclr(); gamemode_ = locator->get_gamemode(); - if(coreclr_.empty() || !exists(coreclr_)) { + if (coreclr_.empty() || !exists(coreclr_)) + { log_error("Invalid coreclr directory specified in server.cfg."); return false; } - - - if(gamemode_.empty() || !exists(gamemode_)) { + + if (gamemode_.empty() || !exists(gamemode_)) + { log_error("Invalid gamemode specified in server.cfg."); return false; } @@ -40,7 +43,8 @@ bool nethost_coreclr::setup(locator *locator, config* cfg) { return true; } -void nethost_coreclr::start() { +void nethost_coreclr::start() +{ int retval; unsigned int exitcode; @@ -48,23 +52,26 @@ void nethost_coreclr::start() { const auto exe_path = (gamemode_).string(); log_info("Initializing .NET runtime..."); - if((retval = app_.initialize(clr_dir.c_str(), exe_path.c_str(), "SampSharp Host")) < 0) { + if ((retval = app_.initialize(clr_dir.c_str(), exe_path.c_str(), "SampSharp Host")) < 0) + { log_error("Failed to initialize CoreCLR runtime. Error %d.", retval); return; } host_init_ = true; - + log_info("Starting game mode host..."); - const char *args[1]; + const char* args[1]; args[0] = "--hosted"; - if((retval = app_.execute_assembly(std::size(args), args, &exitcode)) < 0) { + if ((retval = app_.execute_assembly(std::size(args), args, &exitcode)) < 0) + { log_error("Failed to prepare game mode. Error %d.", retval); return; } - if(exitcode) { + if (exitcode) + { log_error("Failed to prepare game mode. Exit code %d.", exitcode); return; } @@ -73,13 +80,16 @@ void nethost_coreclr::start() { running_ = true; } -void nethost_coreclr::stop() { +void nethost_coreclr::stop() +{ release(); } -void nethost_coreclr::release() { - if(host_init_) { +void nethost_coreclr::release() +{ + if (host_init_) + { app_.release(); host_init_ = false; - } + } } \ No newline at end of file diff --git a/src/legacy/SampSharp/nethost_coreclr.h b/src/legacy/SampSharp/nethost_coreclr.h index aa1ee7ef..c9f4f342 100644 --- a/src/legacy/SampSharp/nethost_coreclr.h +++ b/src/legacy/SampSharp/nethost_coreclr.h @@ -2,12 +2,14 @@ #include "coreclr_app.h" #include "nethost.h" -class nethost_coreclr : public nethost { +class nethost_coreclr : public nethost +{ public: ~nethost_coreclr() override; - bool setup(locator *locator, config* cfg) override; + bool setup(locator* locator, config* cfg) override; void start() override; void stop() override; + private: void release(); diff --git a/src/legacy/SampSharp/platforms.h b/src/legacy/SampSharp/platforms.h index dd2b3091..3b4813b9 100644 --- a/src/legacy/SampSharp/platforms.h +++ b/src/legacy/SampSharp/platforms.h @@ -16,39 +16,39 @@ #pragma once #if (defined __CYGWIN32__ || defined RC_INVOKED) && !defined WIN32 -# define WIN32 +#define WIN32 #endif #if defined WIN32 || defined _WIN32 || defined __WIN32__ -# define SAMPSHARP_LINUX 0 -# define SAMPSHARP_WINDOWS 1 +#define SAMPSHARP_LINUX 0 +#define SAMPSHARP_WINDOWS 1 #endif #if defined __linux__ || defined __linux || defined linux -# if !defined LINUX -# define LINUX -# endif -# define SAMPSHARP_LINUX 1 -# define SAMPSHARP_WINDOWS 0 +#if !defined LINUX +#define LINUX +#endif +#define SAMPSHARP_LINUX 1 +#define SAMPSHARP_WINDOWS 0 #endif #ifdef __cplusplus -# define SAMPSHARP_EXPORT extern "C" +#define SAMPSHARP_EXPORT extern "C" #else -# define SAMPSHARP_EXPORT +#define SAMPSHARP_EXPORT #endif #if defined DEBUG || defined _DEBUG -# define ENABLE_TEST_NATIVES -# define LOG_DEBUG +#define ENABLE_TEST_NATIVES +#define LOG_DEBUG #endif #if SAMPSHARP_WINDOWS -# define SAMPSHARP_CALL __stdcall -# define SAMPSHARP_CALL_PTR *SAMPSHARP_CALL +#define SAMPSHARP_CALL __stdcall +#define SAMPSHARP_CALL_PTR *SAMPSHARP_CALL #elif SAMPSHARP_LINUX -# define SAMPSHARP_CALL __attribute__((visibility("default"))) -# define SAMPSHARP_CALL_PTR SAMPSHARP_CALL * +#define SAMPSHARP_CALL __attribute__((visibility("default"))) +#define SAMPSHARP_CALL_PTR SAMPSHARP_CALL* #else #error Unsupported platform #endif diff --git a/src/legacy/SampSharp/strutil.cpp b/src/legacy/SampSharp/strutil.cpp index db360c28..c6c53954 100644 --- a/src/legacy/SampSharp/strutil.cpp +++ b/src/legacy/SampSharp/strutil.cpp @@ -17,10 +17,7 @@ #include #include -bool iequals(const std::string& a, const std::string& b) { - return std::equal(a.begin(), a.end(), - b.begin(), b.end(), - [](char a, char b) { - return tolower(a) == tolower(b); - }); +bool iequals(const std::string& a, const std::string& b) +{ + return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](char a, char b) { return tolower(a) == tolower(b); }); } diff --git a/src/legacy/SampSharp/testing.cpp b/src/legacy/SampSharp/testing.cpp index eab3bcbe..1b66f04c 100644 --- a/src/legacy/SampSharp/testing.cpp +++ b/src/legacy/SampSharp/testing.cpp @@ -21,13 +21,15 @@ #ifdef ENABLE_TEST_NATIVES // native sampsharptest_inout(a); -cell test_inout(AMX* amx, cell* params) { +cell test_inout(AMX* amx, cell* params) +{ log_info("test_inout %d", params[1]); return params[1]; } // native sampsharptest_inrefout(a, &b); -cell test_inrefout(AMX* amx, cell* params) { +cell test_inrefout(AMX* amx, cell* params) +{ cell* address; amx_GetAddr(amx, params[2], &address); *address = params[1]; @@ -37,7 +39,8 @@ cell test_inrefout(AMX* amx, cell* params) { } // native sampsharptest_inoutstr(const a[], b[], blen = sizeof b); -cell test_inoutstr(AMX* amx, cell* params) { +cell test_inoutstr(AMX* amx, cell* params) +{ char* str; amx_StrParam(amx, params[1], str); @@ -51,7 +54,8 @@ cell test_inoutstr(AMX* amx, cell* params) { } // native sampsharptest_inoutarr(const a[], b[], ablen = sizeof a); -cell test_inoutarr(AMX* amx, cell* params) { +cell test_inoutarr(AMX* amx, cell* params) +{ cell* addr_a; cell* addr_b; @@ -67,10 +71,12 @@ cell test_inoutarr(AMX* amx, cell* params) { } // native sampsharptest_varargs({Float,_}:...); -cell test_varargs(AMX* amx, cell* params) { +cell test_varargs(AMX* amx, cell* params) +{ log_info("test_varargs len=%d", params[0]); - for (unsigned int i = 0; i < params[0] / sizeof(cell); i++) { + for (unsigned int i = 0; i < params[0] / sizeof(cell); i++) + { cell* addr; amx_GetAddr(amx, params[i + 1], &addr); @@ -81,13 +87,15 @@ cell test_varargs(AMX* amx, cell* params) { } // native sampsharptest_varargs_mix(a, b, {Float,_}:...); -cell test_varargs_mix(AMX* amx, cell* params) { +cell test_varargs_mix(AMX* amx, cell* params) +{ log_info("test_varargs_mix len=%d", params[0]); log_info("test_varargs_mix arg[0]=%d", params[1]); log_info("test_varargs_mix arg[1]=%d", params[2]); - for (unsigned int i = 2; i < params[0] / sizeof(cell); i++) { + for (unsigned int i = 2; i < params[0] / sizeof(cell); i++) + { cell* addr; amx_GetAddr(amx, params[i + 1], &addr); @@ -98,10 +106,12 @@ cell test_varargs_mix(AMX* amx, cell* params) { } // native sampsharptest_varargs_str({_}:...); -cell test_varargs_str(AMX* amx, cell* params) { +cell test_varargs_str(AMX* amx, cell* params) +{ log_info("test_varargs_str len=%d", params[0]); - for (unsigned int i = 0; i < params[0] / sizeof(cell); i++) { + for (unsigned int i = 0; i < params[0] / sizeof(cell); i++) + { char* str; amx_StrParam(amx, params[i + 1], str); @@ -112,24 +122,24 @@ cell test_varargs_str(AMX* amx, cell* params) { return 1; } -extern "C" const AMX_NATIVE_INFO native_list[] = { - {"sampsharptest_inout", test_inout}, - {"sampsharptest_inrefout", test_inrefout}, - {"sampsharptest_inoutstr", test_inoutstr}, - {"sampsharptest_inoutarr", test_inoutarr}, - {"sampsharptest_varargs", test_varargs}, - {"sampsharptest_varargs_mix", test_varargs_mix}, - {"sampsharptest_varargs_str", test_varargs_str}, - {NULL, NULL} -}; - -int load_test_natives(AMX* amx) { +extern "C" const AMX_NATIVE_INFO native_list[] = {{"sampsharptest_inout", test_inout}, + {"sampsharptest_inrefout", test_inrefout}, + {"sampsharptest_inoutstr", test_inoutstr}, + {"sampsharptest_inoutarr", test_inoutarr}, + {"sampsharptest_varargs", test_varargs}, + {"sampsharptest_varargs_mix", test_varargs_mix}, + {"sampsharptest_varargs_str", test_varargs_str}, + {NULL, NULL}}; + +int load_test_natives(AMX* amx) +{ return amx_Register(amx, native_list, -1); } #else -int load_test_natives(AMX* amx) { +int load_test_natives(AMX* amx) +{ return 1; } #endif diff --git a/src/legacy/SampSharp/version.h b/src/legacy/SampSharp/version.h index 83568cdc..2fb1b860 100644 --- a/src/legacy/SampSharp/version.h +++ b/src/legacy/SampSharp/version.h @@ -15,28 +15,23 @@ #pragma once -#define PLUGIN_VERSION_MAJOR 0 -#define PLUGIN_VERSION_MINOR 11 -#define PLUGIN_VERSION_PATCH 0 -#define PLUGIN_VERSION_ALPHA 0 +#define PLUGIN_VERSION_MAJOR 0 +#define PLUGIN_VERSION_MINOR 11 +#define PLUGIN_VERSION_PATCH 0 +#define PLUGIN_VERSION_ALPHA 0 -#define __PLUGIN_STRINGIZE(x) #x -#define __PLUGIN_STRINGIZEX(x) __PLUGIN_STRINGIZE(x) +#define __PLUGIN_STRINGIZE(x) #x +#define __PLUGIN_STRINGIZEX(x) __PLUGIN_STRINGIZE(x) -#define __PLUGIN_VERSION_STR \ - __PLUGIN_STRINGIZEX(PLUGIN_VERSION_MAJOR) "." \ - __PLUGIN_STRINGIZEX(PLUGIN_VERSION_MINOR) "." \ - __PLUGIN_STRINGIZEX(PLUGIN_VERSION_PATCH) +#define __PLUGIN_VERSION_STR \ + __PLUGIN_STRINGIZEX(PLUGIN_VERSION_MAJOR) \ + "." __PLUGIN_STRINGIZEX(PLUGIN_VERSION_MINOR) "." __PLUGIN_STRINGIZEX(PLUGIN_VERSION_PATCH) #if PLUGIN_VERSION_ALPHA > 0 -# define PLUGIN_VERSION_STR __PLUGIN_VERSION_STR "-alpha" \ - __PLUGIN_STRINGIZEX(PLUGIN_VERSION_ALPHA) +#define PLUGIN_VERSION_STR __PLUGIN_VERSION_STR "-alpha" __PLUGIN_STRINGIZEX(PLUGIN_VERSION_ALPHA) #else -# define PLUGIN_VERSION_STR __PLUGIN_VERSION_STR +#define PLUGIN_VERSION_STR __PLUGIN_VERSION_STR #endif -#define PLUGIN_VERSION ( \ - (PLUGIN_VERSION_MAJOR << 16) | \ - (PLUGIN_VERSION_MINOR << 8) | \ - (PLUGIN_VERSION_PATCH) | \ - (PLUGIN_VERSION_ALPHA << 24)) +#define PLUGIN_VERSION \ + ((PLUGIN_VERSION_MAJOR << 16) | (PLUGIN_VERSION_MINOR << 8) | (PLUGIN_VERSION_PATCH) | (PLUGIN_VERSION_ALPHA << 24)) diff --git a/src/sampsharp-component/compat.cpp b/src/sampsharp-component/compat.cpp index 17b64591..a41b2390 100644 --- a/src/sampsharp-component/compat.cpp +++ b/src/sampsharp-component/compat.cpp @@ -4,7 +4,7 @@ #include -std::wstring widen_impl(std::string const &in) +std::wstring widen_impl(std::string const& in) { std::wstring out{}; @@ -12,16 +12,15 @@ std::wstring widen_impl(std::string const &in) { const int inSize = static_cast(in.size()); - const int len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, - in.c_str(), inSize, nullptr, 0); - if ( len == 0 ) + const int len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, in.c_str(), inSize, nullptr, 0); + if (len == 0) { throw std::runtime_error("Invalid character sequence."); } out.resize(len); - MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, - in.c_str(), inSize, out.data(), static_cast(out.size())); + MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, in.c_str(), inSize, out.data(), + static_cast(out.size())); } return out; diff --git a/src/sampsharp-component/compat.hpp b/src/sampsharp-component/compat.hpp index 3635db6e..f0c0ac27 100644 --- a/src/sampsharp-component/compat.hpp +++ b/src/sampsharp-component/compat.hpp @@ -5,21 +5,21 @@ #include #ifdef WIN32 -# define WINDOWS true +#define WINDOWS true #endif #ifdef WINDOWS -# include -# define STR(s) L ## s -# define widen(x) widen_impl(x) -# define PATH_SEP '\\' +#include +#define STR(s) L##s +#define widen(x) widen_impl(x) +#define PATH_SEP '\\' -std::wstring widen_impl(std::string const &in); +std::wstring widen_impl(std::string const& in); #else -# define STR(s) s -# define widen(x) x -# define PATH_SEP '/' +#define STR(s) s +#define widen(x) x +#define PATH_SEP '/' #endif using string_t = std::basic_string; diff --git a/src/sampsharp-component/crash-handler.cpp b/src/sampsharp-component/crash-handler.cpp index 408c7dc3..3f9760bf 100644 --- a/src/sampsharp-component/crash-handler.cpp +++ b/src/sampsharp-component/crash-handler.cpp @@ -25,21 +25,36 @@ namespace sampsharp::crash { switch (code) { - case EXCEPTION_ACCESS_VIOLATION: return "ACCESS_VIOLATION"; - case EXCEPTION_STACK_OVERFLOW: return "STACK_OVERFLOW"; - case EXCEPTION_ILLEGAL_INSTRUCTION: return "ILLEGAL_INSTRUCTION"; - case EXCEPTION_PRIV_INSTRUCTION: return "PRIV_INSTRUCTION"; - case EXCEPTION_INT_DIVIDE_BY_ZERO: return "INT_DIVIDE_BY_ZERO"; - case EXCEPTION_INT_OVERFLOW: return "INT_OVERFLOW"; - case EXCEPTION_FLT_DIVIDE_BY_ZERO: return "FLT_DIVIDE_BY_ZERO"; - case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: return "ARRAY_BOUNDS_EXCEEDED"; - case EXCEPTION_DATATYPE_MISALIGNMENT: return "DATATYPE_MISALIGNMENT"; - case EXCEPTION_IN_PAGE_ERROR: return "IN_PAGE_ERROR"; - case 0xC0000374: return "HEAP_CORRUPTION"; - case 0xC0000409: return "FAST_FAIL/STACK_BUFFER_OVERRUN"; - case 0xE06D7363: return "C++ EXCEPTION"; - case 0xE0434352: return "CLR EXCEPTION"; - default: return "UNKNOWN"; + case EXCEPTION_ACCESS_VIOLATION: + return "ACCESS_VIOLATION"; + case EXCEPTION_STACK_OVERFLOW: + return "STACK_OVERFLOW"; + case EXCEPTION_ILLEGAL_INSTRUCTION: + return "ILLEGAL_INSTRUCTION"; + case EXCEPTION_PRIV_INSTRUCTION: + return "PRIV_INSTRUCTION"; + case EXCEPTION_INT_DIVIDE_BY_ZERO: + return "INT_DIVIDE_BY_ZERO"; + case EXCEPTION_INT_OVERFLOW: + return "INT_OVERFLOW"; + case EXCEPTION_FLT_DIVIDE_BY_ZERO: + return "FLT_DIVIDE_BY_ZERO"; + case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: + return "ARRAY_BOUNDS_EXCEEDED"; + case EXCEPTION_DATATYPE_MISALIGNMENT: + return "DATATYPE_MISALIGNMENT"; + case EXCEPTION_IN_PAGE_ERROR: + return "IN_PAGE_ERROR"; + case 0xC0000374: + return "HEAP_CORRUPTION"; + case 0xC0000409: + return "FAST_FAIL/STACK_BUFFER_OVERRUN"; + case 0xE06D7363: + return "C++ EXCEPTION"; + case 0xE0434352: + return "CLR EXCEPTION"; + default: + return "UNKNOWN"; } } @@ -68,9 +83,10 @@ namespace sampsharp::crash void logModuleFor(void* addr) { HMODULE mod = nullptr; - if (!GetModuleHandleExA( - GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - static_cast(addr), &mod) || !mod) + if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + static_cast(addr), &mod) || + !mod) { log(" %p ", addr); return; @@ -95,14 +111,12 @@ namespace sampsharp::crash const BOOL haveLine = SymGetLineFromAddr64(GetCurrentProcess(), pc, &lineDisp, &line); if (haveSym && haveLine) - log(" %p %s!%s+0x%llx (%s:%lu)", addr, modName, sym->Name, - static_cast(disp), line.FileName, line.LineNumber); + log(" %p %s!%s+0x%llx (%s:%lu)", addr, modName, sym->Name, static_cast(disp), + line.FileName, line.LineNumber); else if (haveSym) - log(" %p %s!%s+0x%llx", addr, modName, sym->Name, - static_cast(disp)); + log(" %p %s!%s+0x%llx", addr, modName, sym->Name, static_cast(disp)); else - log(" %p %s+0x%llx", addr, modName, - static_cast(offset)); + log(" %p %s+0x%llx", addr, modName, static_cast(offset)); } // Safely read 8 bytes from a possibly-bad address. Returns false on fault. @@ -159,8 +173,7 @@ namespace sampsharp::crash walkCtx.Rip = retAddr; walkCtx.Rsp += sizeof(DWORD64); recovered_pc = true; - log("[crash] recovered caller PC: 0x%llx", - static_cast(retAddr)); + log("[crash] recovered caller PC: 0x%llx", static_cast(retAddr)); } else { @@ -186,8 +199,8 @@ namespace sampsharp::crash int walked = 0; for (int i = 0; i < 64; ++i) { - if (!StackWalk64(machine, process, GetCurrentThread(), &frame, &walkCtx, - nullptr, SymFunctionTableAccess64, SymGetModuleBase64, nullptr)) + if (!StackWalk64(machine, process, GetCurrentThread(), &frame, &walkCtx, nullptr, + SymFunctionTableAccess64, SymGetModuleBase64, nullptr)) break; if (frame.AddrPC.Offset == 0) break; @@ -209,11 +222,13 @@ namespace sampsharp::crash DWORD64 val = 0; if (!safeRead64(rsp + i * sizeof(DWORD64), &val)) break; - if (val < 0x10000) continue; + if (val < 0x10000) + continue; HMODULE mod = nullptr; - if (GetModuleHandleExA( - GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast(val), &mod) && mod) + if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(val), &mod) && + mod) { logModuleFor(reinterpret_cast(val)); ++found; @@ -229,13 +244,11 @@ namespace sampsharp::crash char path[MAX_PATH]; SYSTEMTIME st; GetLocalTime(&st); - snprintf(path, sizeof(path), - "sampsharp_crash_%04u%02u%02u_%02u%02u%02u_%lu.dmp", - st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, - GetCurrentProcessId()); + snprintf(path, sizeof(path), "sampsharp_crash_%04u%02u%02u_%02u%02u%02u_%lu.dmp", st.wYear, st.wMonth, + st.wDay, st.wHour, st.wMinute, st.wSecond, GetCurrentProcessId()); - const HANDLE file = CreateFileA(path, GENERIC_WRITE, 0, nullptr, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + const HANDLE file = + CreateFileA(path, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (file == INVALID_HANDLE_VALUE) { log("[crash] failed to create minidump file '%s' (err=%lu)", path, GetLastError()); @@ -247,15 +260,12 @@ namespace sampsharp::crash mei.ExceptionPointers = ep; mei.ClientPointers = FALSE; - const auto type = static_cast( - MiniDumpWithFullMemory | - MiniDumpWithHandleData | - MiniDumpWithThreadInfo | - MiniDumpWithUnloadedModules | - MiniDumpWithFullMemoryInfo); + const auto type = + static_cast(MiniDumpWithFullMemory | MiniDumpWithHandleData | MiniDumpWithThreadInfo | + MiniDumpWithUnloadedModules | MiniDumpWithFullMemoryInfo); - const BOOL ok = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), - file, type, ep ? &mei : nullptr, nullptr, nullptr); + const BOOL ok = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file, type, + ep ? &mei : nullptr, nullptr, nullptr); CloseHandle(file); if (ok) @@ -274,8 +284,7 @@ namespace sampsharp::crash void* addr = ep->ExceptionRecord->ExceptionAddress; log("================ SampSharp CRASH ================"); - log("[crash] code=0x%08lX (%s) addr=%p thread=%lu pid=%lu", - code, codeName(code), addr, + log("[crash] code=0x%08lX (%s) addr=%p thread=%lu pid=%lu", code, codeName(code), addr, GetCurrentThreadId(), GetCurrentProcessId()); if (code == EXCEPTION_ACCESS_VIOLATION && ep->ExceptionRecord->NumberParameters >= 2) @@ -308,7 +317,7 @@ namespace sampsharp::crash } LPTOP_LEVEL_EXCEPTION_FILTER g_previous_filter = nullptr; - } + } // namespace void install(ICore* core) { @@ -326,13 +335,15 @@ namespace sampsharp::crash if (core) core->logLn(LogLevel::Message, "[SampSharp] crash handler installed"); } -} +} // namespace sampsharp::crash #else // !_WIN32 namespace sampsharp::crash { - void install(ICore*) {} -} + void install(ICore*) + { + } +} // namespace sampsharp::crash #endif diff --git a/src/sampsharp-component/crash-handler.hpp b/src/sampsharp-component/crash-handler.hpp index 35906073..2a2613a7 100644 --- a/src/sampsharp-component/crash-handler.hpp +++ b/src/sampsharp-component/crash-handler.hpp @@ -9,4 +9,4 @@ namespace sampsharp::crash // exception code/address, module, stack trace, and writes a minidump next // to the executable. No-op on other platforms. void install(ICore* core); -} +} // namespace sampsharp::crash diff --git a/src/sampsharp-component/managed-host.cpp b/src/sampsharp-component/managed-host.cpp index 60790feb..a31e4632 100644 --- a/src/sampsharp-component/managed-host.cpp +++ b/src/sampsharp-component/managed-host.cpp @@ -4,17 +4,17 @@ #include #if !defined WINDOWS -# include -# include -# define MAX_PATH PATH_MAX +#include +#include +#define MAX_PATH PATH_MAX #endif #define ERROR_MISSING_EXPORT 0x99999999 #define ERROR_UNKNOWN 0x99999998 -bool ManagedHost::initialize(const char ** error_ptr) +bool ManagedHost::initialize(const char** error_ptr) { - if(_isReady) + if (_isReady) { return true; } @@ -36,16 +36,17 @@ bool ManagedHost::isReady() const return _isReady; } -bool ManagedHost::loadFor(const StringView root_path, const StringView assembly_name, const char ** error_ptr) +bool ManagedHost::loadFor(const StringView root_path, const StringView assembly_name, const char** error_ptr) { auto root_path_ = root_path.to_string(); const auto assembly_name_ = assembly_name.to_string(); const char sep = root_path_.back(); - if(sep != '\\' && sep != '/') { + if (sep != '\\' && sep != '/') + { root_path_ = root_path_ + PATH_SEP; } - + const string_t config_path = widen(root_path_) + widen(assembly_name_) + STR(".runtimeconfig.json"); int rc = load_runtime(config_path.c_str(), &load_assembly_and_get_function_pointer_fptr); @@ -60,15 +61,16 @@ bool ManagedHost::loadFor(const StringView root_path, const StringView assembly_ *error_ptr = get_error(ERROR_UNKNOWN); return false; } - + assem_path_ = widen((root_path_ + assembly_name_ + ".dll")); - + return true; } -bool ManagedHost::getEntryPoint(const StringView entry_type_name, const StringView name, void ** delegate_ptr, const char ** error_ptr) const +bool ManagedHost::getEntryPoint(const StringView entry_type_name, const StringView name, void** delegate_ptr, + const char** error_ptr) const { - if(load_assembly_and_get_function_pointer_fptr == nullptr) + if (load_assembly_and_get_function_pointer_fptr == nullptr) { return false; } @@ -76,13 +78,9 @@ bool ManagedHost::getEntryPoint(const StringView entry_type_name, const StringVi const string_t entry_type_name_w = widen(entry_type_name.to_string()); const string_t name_w = widen(name.to_string()); - const int rc = load_assembly_and_get_function_pointer_fptr( - assem_path_.c_str(), - entry_type_name_w.c_str(), - name_w.c_str(), - UNMANAGEDCALLERSONLY_METHOD, - nullptr, - delegate_ptr); + const int rc = + load_assembly_and_get_function_pointer_fptr(assem_path_.c_str(), entry_type_name_w.c_str(), name_w.c_str(), + UNMANAGEDCALLERSONLY_METHOD, nullptr, delegate_ptr); if (rc) { @@ -93,39 +91,39 @@ bool ManagedHost::getEntryPoint(const StringView entry_type_name, const StringVi return true; } -void *ManagedHost::load_library(const char_t * path) +void* ManagedHost::load_library(const char_t* path) { #ifdef WINDOWS HMODULE h = ::LoadLibraryW(path); assert(h != nullptr); - return (void *)h; + return (void*)h; #else - void * h = dlopen(path, RTLD_LAZY | RTLD_LOCAL); + void* h = dlopen(path, RTLD_LAZY | RTLD_LOCAL); assert(h != nullptr); return h; #endif } -void * ManagedHost::get_export(void * h, const char * name) +void* ManagedHost::get_export(void* h, const char* name) { #ifdef WINDOWS - auto f = (void*)::GetProcAddress(static_cast(h), name); // NOLINT(clang-diagnostic-microsoft-cast) + auto f = (void*)::GetProcAddress(static_cast(h), name); // NOLINT(clang-diagnostic-microsoft-cast) assert(f != nullptr); return f; #else - void * f = dlsym(h, name); + void* f = dlsym(h, name); assert(f != nullptr); return f; #endif } -int ManagedHost::load_hostfxr(const char_t * assembly_path) +int ManagedHost::load_hostfxr(const char_t* assembly_path) { // Pre-allocate a large buffer for the path to hostfxr char_t buffer[MAX_PATH]; size_t buffer_size = sizeof(buffer) / sizeof(char_t); - - const get_hostfxr_parameters params { sizeof(get_hostfxr_parameters), assembly_path, nullptr }; + + const get_hostfxr_parameters params{sizeof(get_hostfxr_parameters), assembly_path, nullptr}; const int rc = get_hostfxr_path(buffer, &buffer_size, ¶ms); if (rc != 0) { @@ -133,11 +131,12 @@ int ManagedHost::load_hostfxr(const char_t * assembly_path) } // Load hostfxr and get desired exports - void *lib = load_library(buffer); - init_for_config_fptr = (hostfxr_initialize_for_runtime_config_fn)get_export(lib, "hostfxr_initialize_for_runtime_config"); + void* lib = load_library(buffer); + init_for_config_fptr = + (hostfxr_initialize_for_runtime_config_fn)get_export(lib, "hostfxr_initialize_for_runtime_config"); get_delegate_fptr = (hostfxr_get_runtime_delegate_fn)get_export(lib, "hostfxr_get_runtime_delegate"); close_fptr = (hostfxr_close_fn)get_export(lib, "hostfxr_close"); - + if (!init_for_config_fptr || !get_delegate_fptr || !close_fptr) { return ERROR_MISSING_EXPORT; @@ -146,10 +145,10 @@ int ManagedHost::load_hostfxr(const char_t * assembly_path) return 0; } -int ManagedHost::load_runtime(const char_t * config_path, load_assembly_and_get_function_pointer_fn * fptr) const +int ManagedHost::load_runtime(const char_t* config_path, load_assembly_and_get_function_pointer_fn* fptr) const { // Load .NET Core - void * ptr = nullptr; + void* ptr = nullptr; hostfxr_handle cxt = nullptr; int rc = init_for_config_fptr(config_path, nullptr, &cxt); if (rc != 0) @@ -164,56 +163,93 @@ int ManagedHost::load_runtime(const char_t * config_path, load_assembly_and_get_ } // Get the load assembly function pointer - rc = get_delegate_fptr( - cxt, - hdt_load_assembly_and_get_function_pointer, - &ptr); + rc = get_delegate_fptr(cxt, hdt_load_assembly_and_get_function_pointer, &ptr); close_fptr(cxt); *fptr = (load_assembly_and_get_function_pointer_fn)ptr; return rc; } -const char * ManagedHost::get_error(int code) const +const char* ManagedHost::get_error(int code) const { switch ((unsigned int)code) { - case 0x00000000: return "Operation was successful"; - case 0x00000001: return "Initialization was successful, but another host context is already initialized"; - case 0x00000002: return "Initialization was successful, but another host context is already initialized and the requested context specified runtime properties which are not the same"; - case 0x80008081: return "One or more arguments are invalid"; - case 0x80008082: return "Failed to load a hosting component"; - case 0x80008083: return "One of the hosting components is missing"; - case 0x80008084: return "One of the hosting components is missing a required entry point"; - case 0x80008085: return "Failed to get the path of the current hosting component and determine the .NET installation location"; - case 0x80008087: return "The `coreclr` library could not be found"; - case 0x80008088: return "Failed to load the `coreclr` library or finding one of the required entry points"; - case 0x80008089: return "Call to `coreclr_initialize` failed"; - case 0x8000808a: return "Call to `coreclr_execute_assembly` failed"; - case 0x8000808b: return "Initialization of the `hostpolicy` dependency resolver failed"; - case 0x8000808c: return "Resolution of dependencies in `hostpolicy` failed"; - case 0x8000808e: return "Initialization of the `hostpolicy` library failed"; - case 0x80008092: return "Arguments to `hostpolicy` are invalid"; - case 0x80008093: return "The `.runtimeconfig.json` file is invalid"; - case 0x80008094: return "[internal usage only]"; - case 0x80008095: return "`apphost` failed to determine which application to run"; - case 0x80008096: return "Failed to find a compatible framework version"; - case 0x80008097: return "Host command failed"; - case 0x80008098: return "Buffer provided to a host API is too small to fit the requested value"; - case 0x8000809a: return "Application path imprinted in `apphost` doesn't exist"; - case 0x8000809b: return "Failed to find the requested SDK"; - case 0x8000809c: return "Application has multiple references to the same framework which are not compatible"; - case 0x8000809d: return "[internal usage only]"; - case 0x8000809f: return "Error extracting single-file bundle"; - case 0x800080a0: return "Error reading or writing files during single-file bundle extraction"; - case 0x800080a1: return "The application's `.runtimeconfig.json` contains a runtime property which is produced by the hosting layer"; - case 0x800080a2: return "Feature which requires certain version of the hosting layer was used on a version which doesn't support it"; - case 0x800080a3: return "Current state is incompatible with the requested operation"; - case 0x800080a4: return "Property requested by `hostfxr_get_runtime_property_value` doesn't exist"; - case 0x800080a5: return "Host configuration is incompatible with existing host context"; - case 0x800080a6: return "Hosting API does not support the requested scenario"; - case 0x800080a7: return "Support for a requested feature is disabled"; - case ERROR_MISSING_EXPORT: return "Missing export fuction in host library"; - default: return "Unkown error"; + case 0x00000000: + return "Operation was successful"; + case 0x00000001: + return "Initialization was successful, but another host context is already initialized"; + case 0x00000002: + return "Initialization was successful, but another host context is already initialized and the requested " + "context specified runtime properties which are not the same"; + case 0x80008081: + return "One or more arguments are invalid"; + case 0x80008082: + return "Failed to load a hosting component"; + case 0x80008083: + return "One of the hosting components is missing"; + case 0x80008084: + return "One of the hosting components is missing a required entry point"; + case 0x80008085: + return "Failed to get the path of the current hosting component and determine the .NET installation location"; + case 0x80008087: + return "The `coreclr` library could not be found"; + case 0x80008088: + return "Failed to load the `coreclr` library or finding one of the required entry points"; + case 0x80008089: + return "Call to `coreclr_initialize` failed"; + case 0x8000808a: + return "Call to `coreclr_execute_assembly` failed"; + case 0x8000808b: + return "Initialization of the `hostpolicy` dependency resolver failed"; + case 0x8000808c: + return "Resolution of dependencies in `hostpolicy` failed"; + case 0x8000808e: + return "Initialization of the `hostpolicy` library failed"; + case 0x80008092: + return "Arguments to `hostpolicy` are invalid"; + case 0x80008093: + return "The `.runtimeconfig.json` file is invalid"; + case 0x80008094: + return "[internal usage only]"; + case 0x80008095: + return "`apphost` failed to determine which application to run"; + case 0x80008096: + return "Failed to find a compatible framework version"; + case 0x80008097: + return "Host command failed"; + case 0x80008098: + return "Buffer provided to a host API is too small to fit the requested value"; + case 0x8000809a: + return "Application path imprinted in `apphost` doesn't exist"; + case 0x8000809b: + return "Failed to find the requested SDK"; + case 0x8000809c: + return "Application has multiple references to the same framework which are not compatible"; + case 0x8000809d: + return "[internal usage only]"; + case 0x8000809f: + return "Error extracting single-file bundle"; + case 0x800080a0: + return "Error reading or writing files during single-file bundle extraction"; + case 0x800080a1: + return "The application's `.runtimeconfig.json` contains a runtime property which is produced by the hosting " + "layer"; + case 0x800080a2: + return "Feature which requires certain version of the hosting layer was used on a version which doesn't " + "support it"; + case 0x800080a3: + return "Current state is incompatible with the requested operation"; + case 0x800080a4: + return "Property requested by `hostfxr_get_runtime_property_value` doesn't exist"; + case 0x800080a5: + return "Host configuration is incompatible with existing host context"; + case 0x800080a6: + return "Hosting API does not support the requested scenario"; + case 0x800080a7: + return "Support for a requested feature is disabled"; + case ERROR_MISSING_EXPORT: + return "Missing export fuction in host library"; + default: + return "Unkown error"; } } \ No newline at end of file diff --git a/src/sampsharp-component/managed-host.hpp b/src/sampsharp-component/managed-host.hpp index 16b7e867..ed31414d 100644 --- a/src/sampsharp-component/managed-host.hpp +++ b/src/sampsharp-component/managed-host.hpp @@ -17,17 +17,18 @@ class ManagedHost final hostfxr_close_fn close_fptr = nullptr; load_assembly_and_get_function_pointer_fn load_assembly_and_get_function_pointer_fptr = nullptr; - static void * load_library(const char_t *); - static void * get_export(void *, const char *); + static void* load_library(const char_t*); + static void* get_export(void*, const char*); - int load_hostfxr(const char_t * assembly_path); + int load_hostfxr(const char_t* assembly_path); - int load_runtime(const char_t * config_path, load_assembly_and_get_function_pointer_fn * fptr) const; - const char * get_error(int code) const; + int load_runtime(const char_t* config_path, load_assembly_and_get_function_pointer_fn* fptr) const; + const char* get_error(int code) const; public: bool isReady() const; - bool initialize(const char ** error_ptr); - bool loadFor(const StringView root_path, const StringView assembly_name, const char ** error_ptr); - bool getEntryPoint(const StringView entry_type_name, const StringView name, void ** delegate_ptr, const char ** error_ptr) const; + bool initialize(const char** error_ptr); + bool loadFor(const StringView root_path, const StringView assembly_name, const char** error_ptr); + bool getEntryPoint(const StringView entry_type_name, const StringView name, void** delegate_ptr, + const char** error_ptr) const; }; \ No newline at end of file diff --git a/src/sampsharp-component/proxies/api.cpp b/src/sampsharp-component/proxies/api.cpp index 126ac765..3ffc1a9c 100644 --- a/src/sampsharp-component/proxies/api.cpp +++ b/src/sampsharp-component/proxies/api.cpp @@ -22,7 +22,9 @@ #ifdef __clang__ #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" // has C-linkage specified, but returns user-defined type '' which is incompatible with C [-Wreturn-type-c-linkage] +#pragma clang diagnostic ignored \ + "-Wreturn-type-c-linkage" // has C-linkage specified, but returns user-defined type '' which is + // incompatible with C [-Wreturn-type-c-linkage] #endif @@ -37,39 +39,39 @@ using IntPair = Pair; using BoolStringPair = Pair; using HoursMinutesPair = Pair; using SizePair = Pair; -using NewConnectionPlayerPair = Pair; -using CarriagesArray = StaticArray; +using NewConnectionPlayerPair = Pair; +using CarriagesArray = StaticArray; using VehicleModelArray = StaticArray; using SkillsArray = StaticArray; // include/Server/Components/Actors PROXY(IActor, void, setSkin, int); PROXY(IActor, int, getSkin); -PROXY(IActor, void, applyAnimation, AnimationData &); -PROXY(IActor, const AnimationData &, getAnimation); +PROXY(IActor, void, applyAnimation, AnimationData&); +PROXY(IActor, const AnimationData&, getAnimation); PROXY(IActor, void, clearAnimations); PROXY(IActor, void, setHealth, float); PROXY(IActor, float, getHealth); PROXY(IActor, void, setInvulnerable, bool); PROXY(IActor, bool, isInvulnerable); -PROXY(IActor, bool, isStreamedInForPlayer, IPlayer &); -PROXY(IActor, void, streamInForPlayer, IPlayer &); -PROXY(IActor, void, streamOutForPlayer, IPlayer &); -PROXY(IActor, const ActorSpawnData &, getSpawnData); +PROXY(IActor, bool, isStreamedInForPlayer, IPlayer&); +PROXY(IActor, void, streamInForPlayer, IPlayer&); +PROXY(IActor, void, streamOutForPlayer, IPlayer&); +PROXY(IActor, const ActorSpawnData&, getSpawnData); PROXY_CAST(IActor, IEntity); -PROXY(IActorsComponent, IActor *, create, int, Vector3, float); +PROXY(IActorsComponent, IActor*, create, int, Vector3, float); PROXY_EVENT_DISPATCHER(IActorsComponent, ActorEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(ActorEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerGiveDamageActor, IPlayer &, IActor &, float, unsigned, BodyPart) -PROXY_EVENT_HANDLER_EVENT(void, onActorStreamOut, IActor &, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onActorStreamIn, IActor &, IPlayer &) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerGiveDamageActor, IPlayer&, IActor&, float, unsigned, BodyPart) +PROXY_EVENT_HANDLER_EVENT(void, onActorStreamOut, IActor&, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onActorStreamIn, IActor&, IPlayer&) PROXY_EVENT_HANDLER_END(ActorEventHandler, onPlayerGiveDamageActor, onActorStreamOut, onActorStreamIn) // include/Server/Components/Checkpoints PROXY(ICheckpointDataBase, Vector3, getPosition); -PROXY(ICheckpointDataBase, void, setPosition, Vector3 &); +PROXY(ICheckpointDataBase, void, setPosition, Vector3&); PROXY(ICheckpointDataBase, float, getRadius); PROXY(ICheckpointDataBase, void, setRadius, float); PROXY(ICheckpointDataBase, bool, isPlayerInside); @@ -81,46 +83,46 @@ PROXY(ICheckpointDataBase, bool, isEnabled); PROXY(IRaceCheckpointData, RaceCheckpointType, getType); PROXY(IRaceCheckpointData, void, setType, RaceCheckpointType); PROXY(IRaceCheckpointData, Vector3, getNextPosition); -PROXY(IRaceCheckpointData, void, setNextPosition, Vector3 &); +PROXY(IRaceCheckpointData, void, setNextPosition, Vector3&); -PROXY(IPlayerCheckpointData, IRaceCheckpointData &, getRaceCheckpoint); -PROXY(IPlayerCheckpointData, ICheckpointData &, getCheckpoint); +PROXY(IPlayerCheckpointData, IRaceCheckpointData&, getRaceCheckpoint); +PROXY(IPlayerCheckpointData, ICheckpointData&, getCheckpoint); PROXY_EVENT_DISPATCHER(ICheckpointsComponent, PlayerCheckpointEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerCheckpointEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerEnterCheckpoint, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerLeaveCheckpoint, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerEnterRaceCheckpoint, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerLeaveRaceCheckpoint, IPlayer &) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerEnterCheckpoint, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerLeaveCheckpoint, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerEnterRaceCheckpoint, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerLeaveRaceCheckpoint, IPlayer&) PROXY_EVENT_HANDLER_END(PlayerCheckpointEventHandler, onPlayerEnterCheckpoint, onPlayerLeaveCheckpoint, onPlayerEnterRaceCheckpoint, onPlayerLeaveRaceCheckpoint) // include/Server/Components/Classes -PROXY(IClass, const PlayerClass &, getClass); -PROXY(IClass, void, setClass, PlayerClass &); +PROXY(IClass, const PlayerClass&, getClass); +PROXY(IClass, void, setClass, PlayerClass&); PROXY_CAST(IClass, IIDProvider); -PROXY(IPlayerClassData, const PlayerClass &, getClass); -PROXY(IPlayerClassData, void, setSpawnInfo, PlayerClass &); +PROXY(IPlayerClassData, const PlayerClass&, getClass); +PROXY(IPlayerClassData, void, setSpawnInfo, PlayerClass&); PROXY(IPlayerClassData, void, spawnPlayer); -PROXY(IClassesComponent, IClass *, create, int, int, Vector3, float, WeaponSlots &); +PROXY(IClassesComponent, IClass*, create, int, int, Vector3, float, WeaponSlots&); PROXY_EVENT_DISPATCHER(IClassesComponent, ClassEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(ClassEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerRequestClass, IPlayer &, unsigned int) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerRequestClass, IPlayer&, unsigned int) PROXY_EVENT_HANDLER_END(ClassEventHandler, onPlayerRequestClass) // include/Server/Components/Console -PROXY(IConsoleComponent, void, send, StringView, ConsoleCommandSenderData &); -PROXY(IConsoleComponent, void, sendMessage, ConsoleCommandSenderData &, StringView); +PROXY(IConsoleComponent, void, send, StringView, ConsoleCommandSenderData&); +PROXY(IConsoleComponent, void, sendMessage, ConsoleCommandSenderData&, StringView); PROXY_EVENT_DISPATCHER(IConsoleComponent, ConsoleEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(ConsoleEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onConsoleText, StringView, StringView, const ConsoleCommandSenderData &) -PROXY_EVENT_HANDLER_EVENT(void, onRconLoginAttempt, IPlayer &, StringView, bool) -PROXY_EVENT_HANDLER_EVENT(void, onConsoleCommandListRequest, FlatHashSet &) +PROXY_EVENT_HANDLER_EVENT(bool, onConsoleText, StringView, StringView, const ConsoleCommandSenderData&) +PROXY_EVENT_HANDLER_EVENT(void, onRconLoginAttempt, IPlayer&, StringView, bool) +PROXY_EVENT_HANDLER_EVENT(void, onConsoleCommandListRequest, FlatHashSet&) PROXY_EVENT_HANDLER_END(ConsoleEventHandler, onConsoleText, onRconLoginAttempt, onConsoleCommandListRequest) PROXY(IPlayerConsoleData, bool, hasConsoleAccess); @@ -133,62 +135,62 @@ PROXY(IPlayerCustomModelsData, bool, sendDownloadUrl, StringView); PROXY(ICustomModelsComponent, bool, addCustomModel, ModelType, int32_t, int32_t, StringView, StringView, int32_t, uint8_t, uint8_t); -PROXY(ICustomModelsComponent, bool, getBaseModel, uint32_t &, uint32_t &); +PROXY(ICustomModelsComponent, bool, getBaseModel, uint32_t&, uint32_t&); PROXY(ICustomModelsComponent, StringView, getModelNameFromChecksum, uint32_t); PROXY(ICustomModelsComponent, bool, isValidCustomModel, int32_t); -PROXY(ICustomModelsComponent, bool, getCustomModelPath, int32_t, StringView &, StringView &); +PROXY(ICustomModelsComponent, bool, getCustomModelPath, int32_t, StringView&, StringView&); PROXY_EVENT_DISPATCHER(ICustomModelsComponent, PlayerModelsEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerModelsEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerFinishedDownloading, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerRequestDownload, IPlayer &, ModelDownloadType, uint32_t) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerFinishedDownloading, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerRequestDownload, IPlayer&, ModelDownloadType, uint32_t) PROXY_EVENT_HANDLER_END(PlayerModelsEventHandler, onPlayerFinishedDownloading, onPlayerRequestDownload) // include/Server/Components/Databases // @skip // include/Server/Components/Dialogs -PROXY(IPlayerDialogData, void, hide, IPlayer &); -PROXY(IPlayerDialogData, void, show, IPlayer &, int, DialogStyle, StringView, StringView, StringView, StringView); -PROXY(IPlayerDialogData, void, get, int &, DialogStyle &, StringView &, StringView &, StringView &, StringView &); +PROXY(IPlayerDialogData, void, hide, IPlayer&); +PROXY(IPlayerDialogData, void, show, IPlayer&, int, DialogStyle, StringView, StringView, StringView, StringView); +PROXY(IPlayerDialogData, void, get, int&, DialogStyle&, StringView&, StringView&, StringView&, StringView&); PROXY(IPlayerDialogData, int, getActiveID) PROXY_EVENT_DISPATCHER(IDialogsComponent, PlayerDialogEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerDialogEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onDialogResponse, IPlayer &, int, DialogResponse, int, StringView) +PROXY_EVENT_HANDLER_EVENT(void, onDialogResponse, IPlayer&, int, DialogResponse, int, StringView) PROXY_EVENT_HANDLER_END(PlayerDialogEventHandler, onDialogResponse) // include/Server/Components/Fixes PROXY(IPlayerFixesData, bool, sendGameText, StringView, Milliseconds, int); PROXY(IPlayerFixesData, bool, hideGameText, int); PROXY(IPlayerFixesData, bool, hasGameText, int); -PROXY(IPlayerFixesData, bool, getGameText, int, StringView &, Milliseconds &, Milliseconds &); -PROXY(IPlayerFixesData, void, applyAnimation, IPlayer *, IActor *, AnimationData *); +PROXY(IPlayerFixesData, bool, getGameText, int, StringView&, Milliseconds&, Milliseconds&); +PROXY(IPlayerFixesData, void, applyAnimation, IPlayer*, IActor*, AnimationData*); PROXY(IFixesComponent, bool, sendGameTextToAll, StringView, Milliseconds, int); PROXY(IFixesComponent, bool, hideGameTextForAll, int); -PROXY(IFixesComponent, void, clearAnimation, IPlayer *, IActor *); +PROXY(IFixesComponent, void, clearAnimation, IPlayer*, IActor*); // include/Server/Components/GangZones -PROXY(IBaseGangZone, bool, isShownForPlayer, IPlayer &); -PROXY(IBaseGangZone, bool, isFlashingForPlayer, IPlayer &); -PROXY(IBaseGangZone, void, showForPlayer, IPlayer &, Colour &); -PROXY(IBaseGangZone, void, hideForPlayer, IPlayer &); -PROXY(IBaseGangZone, void, flashForPlayer, IPlayer &, Colour &); -PROXY(IBaseGangZone, void, stopFlashForPlayer, IPlayer &); +PROXY(IBaseGangZone, bool, isShownForPlayer, IPlayer&); +PROXY(IBaseGangZone, bool, isFlashingForPlayer, IPlayer&); +PROXY(IBaseGangZone, void, showForPlayer, IPlayer&, Colour&); +PROXY(IBaseGangZone, void, hideForPlayer, IPlayer&); +PROXY(IBaseGangZone, void, flashForPlayer, IPlayer&, Colour&); +PROXY(IBaseGangZone, void, stopFlashForPlayer, IPlayer&); PROXY(IBaseGangZone, GangZonePos, getPosition); -PROXY(IBaseGangZone, void, setPosition, GangZonePos &); -PROXY(IBaseGangZone, bool, isPlayerInside, IPlayer &); -PROXY(IBaseGangZone, const FlatHashSet &, getShownFor); -PROXY(IBaseGangZone, Colour, getFlashingColourForPlayer, IPlayer &); -PROXY(IBaseGangZone, Colour, getColourForPlayer, IPlayer &); -PROXY(IBaseGangZone, void, setLegacyPlayer, IPlayer *); -PROXY(IBaseGangZone, IPlayer *, getLegacyPlayer); +PROXY(IBaseGangZone, void, setPosition, GangZonePos&); +PROXY(IBaseGangZone, bool, isPlayerInside, IPlayer&); +PROXY(IBaseGangZone, const FlatHashSet&, getShownFor); +PROXY(IBaseGangZone, Colour, getFlashingColourForPlayer, IPlayer&); +PROXY(IBaseGangZone, Colour, getColourForPlayer, IPlayer&); +PROXY(IBaseGangZone, void, setLegacyPlayer, IPlayer*); +PROXY(IBaseGangZone, IPlayer*, getLegacyPlayer); PROXY_CAST(IBaseGangZone, IIDProvider); -PROXY(IGangZonesComponent, IGangZone *, create, GangZonePos); -PROXY(IGangZonesComponent, const FlatHashSet &, getCheckingGangZones); -PROXY(IGangZonesComponent, void, useGangZoneCheck, IGangZone &, bool); +PROXY(IGangZonesComponent, IGangZone*, create, GangZonePos); +PROXY(IGangZonesComponent, const FlatHashSet&, getCheckingGangZones); +PROXY(IGangZonesComponent, void, useGangZoneCheck, IGangZone&, bool); PROXY(IGangZonesComponent, int, toLegacyID, int); PROXY(IGangZonesComponent, int, fromLegacyID, int); PROXY(IGangZonesComponent, void, releaseLegacyID, int); @@ -197,9 +199,9 @@ PROXY(IGangZonesComponent, void, setLegacyID, int, int); PROXY_EVENT_DISPATCHER(IGangZonesComponent, GangZoneEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(GangZoneEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerEnterGangZone, IPlayer &, IGangZone &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerLeaveGangZone, IPlayer &, IGangZone &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickGangZone, IPlayer &, IGangZone &) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerEnterGangZone, IPlayer&, IGangZone&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerLeaveGangZone, IPlayer&, IGangZone&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickGangZone, IPlayer&, IGangZone&) PROXY_EVENT_HANDLER_END(GangZoneEventHandler, onPlayerEnterGangZone, onPlayerLeaveGangZone, onPlayerClickGangZone) PROXY(IPlayerGangZoneData, int, toLegacyID, int); @@ -224,34 +226,34 @@ PROXY(IMenu, void, disableRow, MenuRow); PROXY(IMenu, bool, isRowEnabled, MenuRow); PROXY(IMenu, void, disable); PROXY(IMenu, bool, isEnabled); -PROXY(IMenu, const Vector2 &, getPosition); +PROXY(IMenu, const Vector2&, getPosition); PROXY(IMenu, int, getRowCount, MenuColumn); PROXY(IMenu, int, getColumnCount); PROXY_PTR(IMenu, Vector2, getColumnWidths); PROXY(IMenu, StringView, getColumnHeader, MenuColumn); PROXY(IMenu, StringView, getCell, MenuColumn, MenuRow); -PROXY(IMenu, void, initForPlayer, IPlayer &); -PROXY(IMenu, void, showForPlayer, IPlayer &); -PROXY(IMenu, void, hideForPlayer, IPlayer &); +PROXY(IMenu, void, initForPlayer, IPlayer&); +PROXY(IMenu, void, showForPlayer, IPlayer&); +PROXY(IMenu, void, hideForPlayer, IPlayer&); PROXY_CAST(IMenu, IIDProvider); PROXY(IPlayerMenuData, uint8_t, getMenuID); PROXY(IPlayerMenuData, void, setMenuID, uint8_t); -PROXY(IMenusComponent, IMenu *, create, StringView, Vector2, uint8_t, float, float); +PROXY(IMenusComponent, IMenu*, create, StringView, Vector2, uint8_t, float, float); PROXY_EVENT_DISPATCHER(IMenusComponent, MenuEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(MenuEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerSelectedMenuRow, IPlayer &, MenuRow) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerExitedMenu, IPlayer &) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerSelectedMenuRow, IPlayer&, MenuRow) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerExitedMenu, IPlayer&) PROXY_EVENT_HANDLER_END(MenuEventHandler, onPlayerSelectedMenuRow, onPlayerExitedMenu) // include/Server/Components/NPCs -PROXY(INPC, IPlayer *, getPlayer); +PROXY(INPC, IPlayer*, getPlayer); PROXY(INPC, Vector3, getPosition); -PROXY(INPC, void, setPosition, const Vector3 &, bool); +PROXY(INPC, void, setPosition, const Vector3&, bool); PROXY(INPC, GTAQuat, getRotation); -PROXY(INPC, void, setRotation, const GTAQuat &, bool); +PROXY(INPC, void, setRotation, const GTAQuat&, bool); PROXY(INPC, int, getVirtualWorld); PROXY(INPC, void, setVirtualWorld, int); PROXY(INPC, unsigned, getInterior); @@ -274,16 +276,16 @@ PROXY(INPC, bool, isInvulnerable); PROXY(INPC, void, setInvulnerable, bool); PROXY(INPC, bool, isMoving); PROXY(INPC, bool, move, Vector3, NPCMoveType, float, float); -PROXY(INPC, bool, moveToPlayer, IPlayer &, NPCMoveType, float, float, Milliseconds, bool); +PROXY(INPC, bool, moveToPlayer, IPlayer&, NPCMoveType, float, float, Milliseconds, bool); PROXY(INPC, void, stopMove); -PROXY(INPC, const FlatPtrHashSet &, streamedForPlayers); +PROXY(INPC, const FlatPtrHashSet&, streamedForPlayers); PROXY(INPC, void, clearAnimations); -PROXY(INPC, void, applyAnimation, const AnimationData &); -PROXY(INPC, bool, isStreamedInForPlayer, const IPlayer &); +PROXY(INPC, void, applyAnimation, const AnimationData&); +PROXY(INPC, bool, isStreamedInForPlayer, const IPlayer&); PROXY(INPC, void, setWeaponSkillLevel, PlayerWeaponSkill, int); PROXY(INPC, int, getWeaponSkillLevel, PlayerWeaponSkill); PROXY(INPC, void, setKeys, uint16_t, uint16_t, uint16_t); -PROXY(INPC, void, getKeys, uint16_t &, uint16_t &, uint16_t &); +PROXY(INPC, void, getKeys, uint16_t&, uint16_t&, uint16_t&); PROXY(INPC, void, meleeAttack, int, bool); PROXY(INPC, void, stopMeleeAttack); PROXY(INPC, bool, isMeleeAttacking); @@ -298,13 +300,13 @@ PROXY(INPC, PlayerWeaponState, getWeaponState); PROXY(INPC, void, setWeaponState, PlayerWeaponState); PROXY(INPC, void, setAmmoInClip, int); PROXY(INPC, int, getAmmoInClip); -PROXY(INPC, void, shoot, int, PlayerBulletHitType, uint8_t, const Vector3 &, const Vector3 &, bool, EntityCheckType); +PROXY(INPC, void, shoot, int, PlayerBulletHitType, uint8_t, const Vector3&, const Vector3&, bool, EntityCheckType); PROXY(INPC, bool, isShooting); -PROXY(INPC, void, aimAt, const Vector3 &, bool, int, bool, const Vector3 &, EntityCheckType); -PROXY(INPC, void, aimAtPlayer, IPlayer &, bool, int, bool, const Vector3 &, const Vector3 &, EntityCheckType); +PROXY(INPC, void, aimAt, const Vector3&, bool, int, bool, const Vector3&, EntityCheckType); +PROXY(INPC, void, aimAtPlayer, IPlayer&, bool, int, bool, const Vector3&, const Vector3&, EntityCheckType); PROXY(INPC, void, stopAim); PROXY(INPC, bool, isAiming); -PROXY(INPC, bool, isAimingAtPlayer, IPlayer &); +PROXY(INPC, bool, isAimingAtPlayer, IPlayer&); PROXY(INPC, void, setWeaponAccuracy, uint8_t, float); PROXY(INPC, float, getWeaponAccuracy, uint8_t); PROXY(INPC, void, setWeaponReloadTime, uint8_t, int); @@ -315,9 +317,9 @@ PROXY(INPC, int, getWeaponShootTime, uint8_t); PROXY(INPC, void, setWeaponClipSize, uint8_t, int); PROXY(INPC, int, getWeaponClipSize, uint8_t); PROXY(INPC, int, getWeaponActualClipSize, uint8_t); -PROXY(INPC, void, enterVehicle, IVehicle &, uint8_t, NPCMoveType); +PROXY(INPC, void, enterVehicle, IVehicle&, uint8_t, NPCMoveType); PROXY(INPC, void, exitVehicle); -PROXY(INPC, bool, putInVehicle, IVehicle &, uint8_t); +PROXY(INPC, bool, putInVehicle, IVehicle&, uint8_t); PROXY(INPC, bool, removeFromVehicle); PROXY(INPC, bool, moveByPath, int, NPCMoveType, float, bool); PROXY(INPC, void, pausePath); @@ -327,9 +329,9 @@ PROXY(INPC, bool, isMovingByPath); PROXY(INPC, bool, isPathPaused); PROXY(INPC, int, getCurrentPathId); PROXY(INPC, int, getCurrentPathPointIndex); -PROXY(INPC, IVehicle *, getVehicle); +PROXY(INPC, IVehicle*, getVehicle); PROXY(INPC, int, getVehicleSeat); -PROXY(INPC, IVehicle *, getEnteringVehicle); +PROXY(INPC, IVehicle*, getEnteringVehicle); PROXY(INPC, int, getEnteringVehicleSeat); PROXY(INPC, void, useVehicleSiren, bool); PROXY(INPC, bool, isVehicleSirenUsed); @@ -343,7 +345,7 @@ PROXY(INPC, void, setVehicleTrainSpeed, float); PROXY(INPC, float, getVehicleTrainSpeed); PROXY(INPC, void, resetAnimation); PROXY(INPC, void, setAnimation, int, float, bool, bool, bool, bool, int); -PROXY(INPC, void, getAnimation, int &, float &, bool &, bool &, bool &, bool &, int &); +PROXY(INPC, void, getAnimation, int&, float&, bool&, bool&, bool&, bool&, int&); PROXY(INPC, void, setSpecialAction, PlayerSpecialAction); PROXY(INPC, PlayerSpecialAction, getSpecialAction); PROXY_NAMED_OVERLOAD(INPC, INPC, bool, startPlayback, ByName, StringView, bool, Vector3, GTAQuat); @@ -360,27 +362,27 @@ PROXY(INPC, bool, isPlayingNodePaused); PROXY(INPC, bool, isPlayingNode); PROXY(INPC, uint16_t, changeNode, int, uint16_t); PROXY(INPC, bool, updateNodePoint, uint16_t); -PROXY(INPC, void, setSurfingData, const PlayerSurfingData &); +PROXY(INPC, void, setSurfingData, const PlayerSurfingData&); PROXY(INPC, PlayerSurfingData, getSurfingData); PROXY(INPC, void, resetSurfingData); -PROXY(INPC, bool, isMovingToPlayer, IPlayer &); -PROXY(INPC, void, kill, IPlayer *, uint8_t); -PROXY(INPC, IPlayer *, getPlayerAimingAt); -PROXY(INPC, IPlayer *, getPlayerMovingTo); +PROXY(INPC, bool, isMovingToPlayer, IPlayer&); +PROXY(INPC, void, kill, IPlayer*, uint8_t); +PROXY(INPC, IPlayer*, getPlayerAimingAt); +PROXY(INPC, IPlayer*, getPlayerMovingTo); PROXY(INPC, Vector3, getPositionMovingTo); PROXY_CAST(INPC, IIDProvider); -PROXY(INPCComponent, INPC *, create, StringView); -PROXY(INPCComponent, void, destroy, INPC &); +PROXY(INPCComponent, INPC*, create, StringView); +PROXY(INPCComponent, void, destroy, INPC&); PROXY(INPCComponent, int, createPath); PROXY(INPCComponent, bool, destroyPath, int); PROXY(INPCComponent, void, destroyAllPaths); PROXY_PTR(INPCComponent, size_t, getPathCount); -PROXY(INPCComponent, bool, addPointToPath, int, const Vector3 &, float); +PROXY(INPCComponent, bool, addPointToPath, int, const Vector3&, float); PROXY(INPCComponent, bool, removePointFromPath, int, size_t); PROXY(INPCComponent, bool, clearPath, int); PROXY_PTR(INPCComponent, size_t, getPathPointCount, int); -PROXY(INPCComponent, bool, getPathPoint, int, size_t, Vector3 &, float &); -PROXY(INPCComponent, bool, hasPathPointInRange, int, const Vector3 &, float); +PROXY(INPCComponent, bool, getPathPoint, int, size_t, Vector3&, float&); +PROXY(INPCComponent, bool, hasPathPointInRange, int, const Vector3&, float); PROXY(INPCComponent, bool, isValidPath, int); PROXY(INPCComponent, int, loadRecord, StringView); PROXY(INPCComponent, bool, unloadRecord, int); @@ -392,40 +394,40 @@ PROXY(INPCComponent, void, closeNode, int); PROXY(INPCComponent, bool, isNodeOpen, int); PROXY(INPCComponent, uint8_t, getNodeType, int); PROXY(INPCComponent, bool, setNodePoint, int, uint16_t); -PROXY(INPCComponent, bool, getNodePointPosition, int, Vector3 &); +PROXY(INPCComponent, bool, getNodePointPosition, int, Vector3&); PROXY(INPCComponent, int, getNodePointCount, int); -PROXY(INPCComponent, bool, getNodeInfo, int, uint32_t &, uint32_t &, uint32_t &); +PROXY(INPCComponent, bool, getNodeInfo, int, uint32_t&, uint32_t&, uint32_t&); PROXY_CAST(INPCComponent, INetworkComponent); PROXY_EVENT_DISPATCHER(INPCComponent, NPCEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(NPCEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishMove, INPC &) -PROXY_EVENT_HANDLER_EVENT(void, onNPCCreate, INPC &) -PROXY_EVENT_HANDLER_EVENT(void, onNPCDestroy, INPC &) -PROXY_EVENT_HANDLER_EVENT(void, onNPCSpawn, INPC &) -PROXY_EVENT_HANDLER_EVENT(void, onNPCRespawn, INPC &) -PROXY_EVENT_HANDLER_EVENT(void, onNPCWeaponStateChange, INPC &, PlayerWeaponState, PlayerWeaponState) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCTakeDamage, INPC &, IPlayer &, float, uint8_t, BodyPart) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCGiveDamage, INPC &, IPlayer &, float, uint8_t, BodyPart) -PROXY_EVENT_HANDLER_EVENT(void, onNPCDeath, INPC &, IPlayer *, int) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotMissed, INPC &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotPlayer, INPC &, IPlayer &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotNPC, INPC &, INPC &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotVehicle, INPC &, IVehicle &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotObject, INPC &, IObject &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotPlayerObject, INPC &, IPlayerObject &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(void, onNPCPlaybackStart, INPC &, int) -PROXY_EVENT_HANDLER_EVENT(void, onNPCPlaybackEnd, INPC &, int) -PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishNodePoint, INPC &, int, uint16_t) -PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishNode, INPC &, int) -PROXY_EVENT_HANDLER_EVENT(bool, onNPCChangeNode, INPC &, int, int) -PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishMovePathPoint, INPC &, int, int) -PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishMovePath, INPC &, int) +PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishMove, INPC&) +PROXY_EVENT_HANDLER_EVENT(void, onNPCCreate, INPC&) +PROXY_EVENT_HANDLER_EVENT(void, onNPCDestroy, INPC&) +PROXY_EVENT_HANDLER_EVENT(void, onNPCSpawn, INPC&) +PROXY_EVENT_HANDLER_EVENT(void, onNPCRespawn, INPC&) +PROXY_EVENT_HANDLER_EVENT(void, onNPCWeaponStateChange, INPC&, PlayerWeaponState, PlayerWeaponState) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCTakeDamage, INPC&, IPlayer&, float, uint8_t, BodyPart) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCGiveDamage, INPC&, IPlayer&, float, uint8_t, BodyPart) +PROXY_EVENT_HANDLER_EVENT(void, onNPCDeath, INPC&, IPlayer*, int) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotMissed, INPC&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotPlayer, INPC&, IPlayer&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotNPC, INPC&, INPC&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotVehicle, INPC&, IVehicle&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotObject, INPC&, IObject&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCShotPlayerObject, INPC&, IPlayerObject&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(void, onNPCPlaybackStart, INPC&, int) +PROXY_EVENT_HANDLER_EVENT(void, onNPCPlaybackEnd, INPC&, int) +PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishNodePoint, INPC&, int, uint16_t) +PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishNode, INPC&, int) +PROXY_EVENT_HANDLER_EVENT(bool, onNPCChangeNode, INPC&, int, int) +PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishMovePathPoint, INPC&, int, int) +PROXY_EVENT_HANDLER_EVENT(void, onNPCFinishMovePath, INPC&, int) PROXY_EVENT_HANDLER_END(NPCEventHandler, onNPCFinishMove, onNPCCreate, onNPCDestroy, onNPCSpawn, onNPCRespawn, - onNPCWeaponStateChange, onNPCTakeDamage, onNPCGiveDamage, onNPCDeath, - onNPCShotMissed, onNPCShotPlayer, onNPCShotNPC, onNPCShotVehicle, onNPCShotObject, - onNPCShotPlayerObject, onNPCPlaybackStart, onNPCPlaybackEnd, onNPCFinishNodePoint, - onNPCFinishNode, onNPCChangeNode, onNPCFinishMovePathPoint, onNPCFinishMovePath) + onNPCWeaponStateChange, onNPCTakeDamage, onNPCGiveDamage, onNPCDeath, onNPCShotMissed, + onNPCShotPlayer, onNPCShotNPC, onNPCShotVehicle, onNPCShotObject, onNPCShotPlayerObject, + onNPCPlaybackStart, onNPCPlaybackEnd, onNPCFinishNodePoint, onNPCFinishNode, onNPCChangeNode, + onNPCFinishMovePathPoint, onNPCFinishMovePath) // include/Server/Components/Objects PROXY(IBaseObject, void, setDrawDistance, float); @@ -434,51 +436,50 @@ PROXY(IBaseObject, void, setModel, int); PROXY(IBaseObject, int, getModel); PROXY(IBaseObject, void, setCameraCollision, bool); PROXY(IBaseObject, bool, getCameraCollision); -PROXY(IBaseObject, void, move, ObjectMoveData &); +PROXY(IBaseObject, void, move, ObjectMoveData&); PROXY(IBaseObject, bool, isMoving); PROXY(IBaseObject, void, stop); -PROXY(IBaseObject, const ObjectMoveData &, getMovingData); -PROXY(IBaseObject, void, attachToVehicle, IVehicle &, Vector3, Vector3); +PROXY(IBaseObject, const ObjectMoveData&, getMovingData); +PROXY(IBaseObject, void, attachToVehicle, IVehicle&, Vector3, Vector3); PROXY(IBaseObject, void, resetAttachment); -PROXY(IBaseObject, const ObjectAttachmentData &, getAttachmentData); -PROXY(IBaseObject, bool, getMaterialData, uint32_t, const ObjectMaterialData *&); +PROXY(IBaseObject, const ObjectAttachmentData&, getAttachmentData); +PROXY(IBaseObject, bool, getMaterialData, uint32_t, const ObjectMaterialData*&); PROXY(IBaseObject, void, setMaterial, uint32_t, int, StringView, StringView, Colour); PROXY(IBaseObject, void, setMaterialText, uint32_t, StringView, ObjectMaterialSize, StringView, int, bool, Colour, Colour, ObjectMaterialTextAlign); PROXY_CAST(IBaseObject, IEntity); -PROXY(IObject, void, attachToPlayer, IPlayer &, Vector3, Vector3); -PROXY(IObject, void, attachToObject, IObject &, Vector3, Vector3, bool); +PROXY(IObject, void, attachToPlayer, IPlayer&, Vector3, Vector3); +PROXY(IObject, void, attachToObject, IObject&, Vector3, Vector3, bool); -PROXY(IPlayerObject, void, attachToObject, IPlayerObject &, Vector3, Vector3); -PROXY(IPlayerObject, void, attachToPlayer, IPlayer &, Vector3, Vector3); +PROXY(IPlayerObject, void, attachToObject, IPlayerObject&, Vector3, Vector3); +PROXY(IPlayerObject, void, attachToPlayer, IPlayer&, Vector3, Vector3); PROXY(IObjectsComponent, void, setDefaultCameraCollision, bool); PROXY(IObjectsComponent, bool, getDefaultCameraCollision); -PROXY(IObjectsComponent, IObject *, create, int, Vector3, Vector3, float); +PROXY(IObjectsComponent, IObject*, create, int, Vector3, Vector3, float); PROXY_EVENT_DISPATCHER(IObjectsComponent, ObjectEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(ObjectEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onMoved, IObject &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerObjectMoved, IPlayer &, IPlayerObject &) -PROXY_EVENT_HANDLER_EVENT(void, onObjectSelected, IPlayer &, IObject &, int, Vector3) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerObjectSelected, IPlayer &, IPlayerObject &, int, Vector3) -PROXY_EVENT_HANDLER_EVENT(void, onObjectEdited, IPlayer &, IObject &, ObjectEditResponse, Vector3, Vector3) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerObjectEdited, IPlayer &, IPlayerObject &, ObjectEditResponse, Vector3, - Vector3) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerAttachedObjectEdited, IPlayer &, int, bool, const ObjectAttachmentSlotData &) +PROXY_EVENT_HANDLER_EVENT(void, onMoved, IObject&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerObjectMoved, IPlayer&, IPlayerObject&) +PROXY_EVENT_HANDLER_EVENT(void, onObjectSelected, IPlayer&, IObject&, int, Vector3) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerObjectSelected, IPlayer&, IPlayerObject&, int, Vector3) +PROXY_EVENT_HANDLER_EVENT(void, onObjectEdited, IPlayer&, IObject&, ObjectEditResponse, Vector3, Vector3) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerObjectEdited, IPlayer&, IPlayerObject&, ObjectEditResponse, Vector3, Vector3) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerAttachedObjectEdited, IPlayer&, int, bool, const ObjectAttachmentSlotData&) PROXY_EVENT_HANDLER_END(ObjectEventHandler, onMoved, onPlayerObjectMoved, onObjectSelected, onPlayerObjectSelected, onObjectEdited, onPlayerObjectEdited, onPlayerAttachedObjectEdited) -PROXY(IPlayerObjectData, IPlayerObject *, create, int, Vector3, Vector3, float); -PROXY(IPlayerObjectData, void, setAttachedObject, int, ObjectAttachmentSlotData &); +PROXY(IPlayerObjectData, IPlayerObject*, create, int, Vector3, Vector3, float); +PROXY(IPlayerObjectData, void, setAttachedObject, int, ObjectAttachmentSlotData&); PROXY(IPlayerObjectData, void, removeAttachedObject, int); PROXY(IPlayerObjectData, bool, hasAttachedObject, int); -PROXY(IPlayerObjectData, const ObjectAttachmentSlotData &, getAttachedObject, int); +PROXY(IPlayerObjectData, const ObjectAttachmentSlotData&, getAttachedObject, int); PROXY(IPlayerObjectData, void, beginSelecting); PROXY(IPlayerObjectData, bool, selectingObject); PROXY(IPlayerObjectData, void, endEditing); -PROXY(IPlayerObjectData, void, beginEditing, IObject &); -PROXY_OVERLOAD(IPlayerObjectData, void, beginEditing, _player, IPlayerObject &); +PROXY(IPlayerObjectData, void, beginEditing, IObject&); +PROXY_OVERLOAD(IPlayerObjectData, void, beginEditing, _player, IPlayerObject&); PROXY(IPlayerObjectData, bool, editingObject); PROXY(IPlayerObjectData, void, editAttachedObject, int); PROXY_CAST_NAMED(IPlayerObjectData, IPlayerObjectData, IPool, IPool); @@ -493,16 +494,16 @@ PROXY(IBasePickup, PickupType, getType); PROXY(IBasePickup, void, setPositionNoUpdate, Vector3); PROXY(IBasePickup, void, setModel, int, bool); PROXY(IBasePickup, int, getModel); -PROXY(IBasePickup, bool, isStreamedInForPlayer, const IPlayer &); -PROXY(IBasePickup, void, streamInForPlayer, IPlayer &); -PROXY(IBasePickup, void, streamOutForPlayer, IPlayer &); -PROXY(IBasePickup, void, setPickupHiddenForPlayer, IPlayer &, bool); -PROXY(IBasePickup, bool, isPickupHiddenForPlayer, IPlayer &); -PROXY(IBasePickup, void, setLegacyPlayer, IPlayer *); -PROXY(IBasePickup, IPlayer *, getLegacyPlayer); +PROXY(IBasePickup, bool, isStreamedInForPlayer, const IPlayer&); +PROXY(IBasePickup, void, streamInForPlayer, IPlayer&); +PROXY(IBasePickup, void, streamOutForPlayer, IPlayer&); +PROXY(IBasePickup, void, setPickupHiddenForPlayer, IPlayer&, bool); +PROXY(IBasePickup, bool, isPickupHiddenForPlayer, IPlayer&); +PROXY(IBasePickup, void, setLegacyPlayer, IPlayer*); +PROXY(IBasePickup, IPlayer*, getLegacyPlayer); PROXY_CAST(IBasePickup, IEntity); -PROXY(IPickupsComponent, IPickup *, create, int, PickupType, Vector3, uint32_t, bool); +PROXY(IPickupsComponent, IPickup*, create, int, PickupType, Vector3, uint32_t, bool); PROXY(IPickupsComponent, int, toLegacyID, int); PROXY(IPickupsComponent, int, fromLegacyID, int); PROXY(IPickupsComponent, void, releaseLegacyID, int); @@ -511,7 +512,7 @@ PROXY(IPickupsComponent, void, setLegacyID, int, int); PROXY_EVENT_DISPATCHER(IPickupsComponent, PickupEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(PickupEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerPickUpPickup, IPlayer &, IPickup &) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerPickUpPickup, IPlayer&, IPickup&) PROXY_EVENT_HANDLER_END(PickupEventHandler, onPlayerPickUpPickup) PROXY(IPlayerPickupData, int, toLegacyID, int); @@ -531,69 +532,69 @@ PROXY(IPlayerRecordingData, void, stop); // include/Server/Components/TextDraws PROXY_PTR(ITextDrawBase, Vector2, getPosition); -PROXY(ITextDrawBase, ITextDrawBase &, setPosition, Vector2); +PROXY(ITextDrawBase, ITextDrawBase&, setPosition, Vector2); PROXY(ITextDrawBase, void, setText, StringView); PROXY(ITextDrawBase, StringView, getText); -PROXY(ITextDrawBase, ITextDrawBase &, setLetterSize, Vector2); +PROXY(ITextDrawBase, ITextDrawBase&, setLetterSize, Vector2); PROXY_PTR(ITextDrawBase, Vector2, getLetterSize); -PROXY(ITextDrawBase, ITextDrawBase &, setTextSize, Vector2); +PROXY(ITextDrawBase, ITextDrawBase&, setTextSize, Vector2); PROXY_PTR(ITextDrawBase, Vector2, getTextSize); -PROXY(ITextDrawBase, ITextDrawBase &, setAlignment, TextDrawAlignmentTypes); +PROXY(ITextDrawBase, ITextDrawBase&, setAlignment, TextDrawAlignmentTypes); PROXY(ITextDrawBase, TextDrawAlignmentTypes, getAlignment); -PROXY(ITextDrawBase, ITextDrawBase &, setColour, Colour); +PROXY(ITextDrawBase, ITextDrawBase&, setColour, Colour); PROXY_PTR(ITextDrawBase, Colour, getLetterColour); -PROXY(ITextDrawBase, ITextDrawBase &, useBox, bool); +PROXY(ITextDrawBase, ITextDrawBase&, useBox, bool); PROXY(ITextDrawBase, bool, hasBox); -PROXY(ITextDrawBase, ITextDrawBase &, setBoxColour, Colour); +PROXY(ITextDrawBase, ITextDrawBase&, setBoxColour, Colour); PROXY_PTR(ITextDrawBase, Colour, getBoxColour); -PROXY(ITextDrawBase, ITextDrawBase &, setShadow, int); +PROXY(ITextDrawBase, ITextDrawBase&, setShadow, int); PROXY(ITextDrawBase, int, getShadow); -PROXY(ITextDrawBase, ITextDrawBase &, setOutline, int); +PROXY(ITextDrawBase, ITextDrawBase&, setOutline, int); PROXY(ITextDrawBase, int, getOutline); -PROXY(ITextDrawBase, ITextDrawBase &, setBackgroundColour, Colour); +PROXY(ITextDrawBase, ITextDrawBase&, setBackgroundColour, Colour); PROXY_PTR(ITextDrawBase, Colour, getBackgroundColour); -PROXY(ITextDrawBase, ITextDrawBase &, setStyle, TextDrawStyle); +PROXY(ITextDrawBase, ITextDrawBase&, setStyle, TextDrawStyle); PROXY(ITextDrawBase, TextDrawStyle, getStyle); -PROXY(ITextDrawBase, ITextDrawBase &, setProportional, bool); +PROXY(ITextDrawBase, ITextDrawBase&, setProportional, bool); PROXY(ITextDrawBase, bool, isProportional); -PROXY(ITextDrawBase, ITextDrawBase &, setSelectable, bool); +PROXY(ITextDrawBase, ITextDrawBase&, setSelectable, bool); PROXY(ITextDrawBase, bool, isSelectable); -PROXY(ITextDrawBase, ITextDrawBase &, setPreviewModel, int); +PROXY(ITextDrawBase, ITextDrawBase&, setPreviewModel, int); PROXY(ITextDrawBase, int, getPreviewModel); -PROXY(ITextDrawBase, ITextDrawBase &, setPreviewRotation, Vector3); +PROXY(ITextDrawBase, ITextDrawBase&, setPreviewRotation, Vector3); PROXY(ITextDrawBase, Vector3, getPreviewRotation); -PROXY(ITextDrawBase, ITextDrawBase &, setPreviewVehicleColour, int, int); +PROXY(ITextDrawBase, ITextDrawBase&, setPreviewVehicleColour, int, int); PROXY_PTR(ITextDrawBase, IntPair, getPreviewVehicleColour); -PROXY(ITextDrawBase, ITextDrawBase &, setPreviewZoom, float); +PROXY(ITextDrawBase, ITextDrawBase&, setPreviewZoom, float); PROXY(ITextDrawBase, float, getPreviewZoom); PROXY(ITextDrawBase, void, restream); PROXY_CAST(ITextDrawBase, IIDProvider); -PROXY(ITextDraw, void, showForPlayer, IPlayer &); -PROXY(ITextDraw, void, hideForPlayer, IPlayer &); -PROXY(ITextDraw, bool, isShownForPlayer, const IPlayer &); -PROXY(ITextDraw, void, setTextForPlayer, IPlayer &, StringView); +PROXY(ITextDraw, void, showForPlayer, IPlayer&); +PROXY(ITextDraw, void, hideForPlayer, IPlayer&); +PROXY(ITextDraw, bool, isShownForPlayer, const IPlayer&); +PROXY(ITextDraw, void, setTextForPlayer, IPlayer&, StringView); PROXY(IPlayerTextDraw, void, show); PROXY(IPlayerTextDraw, void, hide); PROXY(IPlayerTextDraw, bool, isShown); -PROXY(ITextDrawsComponent, ITextDraw *, create, Vector2, StringView); -PROXY_OVERLOAD(ITextDrawsComponent, ITextDraw *, create, _model, Vector2, int); +PROXY(ITextDrawsComponent, ITextDraw*, create, Vector2, StringView); +PROXY_OVERLOAD(ITextDrawsComponent, ITextDraw*, create, _model, Vector2, int); PROXY_EVENT_DISPATCHER(ITextDrawsComponent, TextDrawEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(TextDrawEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickTextDraw, IPlayer &, ITextDraw &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickPlayerTextDraw, IPlayer &, IPlayerTextDraw &) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerCancelTextDrawSelection, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerCancelPlayerTextDrawSelection, IPlayer &) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickTextDraw, IPlayer&, ITextDraw&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickPlayerTextDraw, IPlayer&, IPlayerTextDraw&) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerCancelTextDrawSelection, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerCancelPlayerTextDrawSelection, IPlayer&) PROXY_EVENT_HANDLER_END(TextDrawEventHandler, onPlayerClickTextDraw, onPlayerClickPlayerTextDraw, onPlayerCancelTextDrawSelection, onPlayerCancelPlayerTextDrawSelection) PROXY(IPlayerTextDrawData, void, beginSelection, Colour); PROXY(IPlayerTextDrawData, bool, isSelecting); PROXY(IPlayerTextDrawData, void, endSelection); -PROXY(IPlayerTextDrawData, IPlayerTextDraw *, create, Vector2, StringView); -PROXY_OVERLOAD(IPlayerTextDrawData, IPlayerTextDraw *, create, _model, Vector2, int); +PROXY(IPlayerTextDrawData, IPlayerTextDraw*, create, Vector2, StringView); +PROXY_OVERLOAD(IPlayerTextDrawData, IPlayerTextDraw*, create, _model, Vector2, int); PROXY_CAST_NAMED(IPlayerTextDrawData, IPlayerTextDrawData, IPool, IPool); // include/Server/Components/TextLabels @@ -603,9 +604,9 @@ PROXY(ITextLabelBase, void, setColour, Colour); PROXY_PTR(ITextLabelBase, Colour, getColour); PROXY(ITextLabelBase, void, setDrawDistance, float); PROXY(ITextLabelBase, float, getDrawDistance); -PROXY(ITextLabelBase, void, attachToPlayer, IPlayer &, Vector3); -PROXY(ITextLabelBase, void, attachToVehicle, IVehicle &, Vector3); -PROXY(ITextLabelBase, const TextLabelAttachmentData &, getAttachmentData); +PROXY(ITextLabelBase, void, attachToPlayer, IPlayer&, Vector3); +PROXY(ITextLabelBase, void, attachToVehicle, IVehicle&, Vector3); +PROXY(ITextLabelBase, const TextLabelAttachmentData&, getAttachmentData); PROXY(ITextLabelBase, void, detachFromPlayer, Vector3); PROXY(ITextLabelBase, void, detachFromVehicle, Vector3); PROXY(ITextLabelBase, void, setTestLOS, bool); @@ -613,21 +614,21 @@ PROXY(ITextLabelBase, bool, getTestLOS); PROXY(ITextLabelBase, void, setColourAndText, Colour, StringView); PROXY_CAST(ITextLabelBase, IEntity); -PROXY(ITextLabel, bool, isStreamedInForPlayer, IPlayer &); -PROXY(ITextLabel, void, streamInForPlayer, IPlayer &); -PROXY(ITextLabel, void, streamOutForPlayer, IPlayer &); - -PROXY(ITextLabelsComponent, ITextLabel *, create, StringView, Colour, Vector3, float, int, bool); -PROXY_OVERLOAD(ITextLabelsComponent, ITextLabel *, create, _player, StringView, Colour, Vector3, float, int, bool, - IPlayer &); -PROXY_OVERLOAD(ITextLabelsComponent, ITextLabel *, create, _vehicle, StringView, Colour, Vector3, float, int, bool, - IVehicle &); - -PROXY(IPlayerTextLabelData, IPlayerTextLabel *, create, StringView, Colour, Vector3, float, bool); -PROXY_OVERLOAD(IPlayerTextLabelData, IPlayerTextLabel *, create, _player, StringView, Colour, Vector3, float, bool, - IPlayer &); -PROXY_OVERLOAD(IPlayerTextLabelData, IPlayerTextLabel *, create, _vehicle, StringView, Colour, Vector3, float, bool, - IVehicle &); +PROXY(ITextLabel, bool, isStreamedInForPlayer, IPlayer&); +PROXY(ITextLabel, void, streamInForPlayer, IPlayer&); +PROXY(ITextLabel, void, streamOutForPlayer, IPlayer&); + +PROXY(ITextLabelsComponent, ITextLabel*, create, StringView, Colour, Vector3, float, int, bool); +PROXY_OVERLOAD(ITextLabelsComponent, ITextLabel*, create, _player, StringView, Colour, Vector3, float, int, bool, + IPlayer&); +PROXY_OVERLOAD(ITextLabelsComponent, ITextLabel*, create, _vehicle, StringView, Colour, Vector3, float, int, bool, + IVehicle&); + +PROXY(IPlayerTextLabelData, IPlayerTextLabel*, create, StringView, Colour, Vector3, float, bool); +PROXY_OVERLOAD(IPlayerTextLabelData, IPlayerTextLabel*, create, _player, StringView, Colour, Vector3, float, bool, + IPlayer&); +PROXY_OVERLOAD(IPlayerTextLabelData, IPlayerTextLabel*, create, _vehicle, StringView, Colour, Vector3, float, bool, + IVehicle&); PROXY_CAST_NAMED(IPlayerTextLabelData, IPlayerTextLabelData, IPool, IPool); // include/Server/Components/Timers @@ -641,36 +642,36 @@ PROXY_CAST_NAMED(IPlayerTextLabelData, IPlayerTextLabelData, IPool &, streamedForPlayers); -PROXY(IVehicle, IPlayer *, getDriver); -PROXY(IVehicle, const FlatHashSet &, getPassengers); +PROXY(IVehicle, bool, updateFromDriverSync, VehicleDriverSyncPacket&, IPlayer&); +PROXY(IVehicle, bool, updateFromPassengerSync, VehiclePassengerSyncPacket&, IPlayer&); +PROXY(IVehicle, bool, updateFromUnoccupied, VehicleUnoccupiedSyncPacket&, IPlayer&); +PROXY(IVehicle, bool, updateFromTrailerSync, VehicleTrailerSyncPacket&, IPlayer&); +PROXY(IVehicle, const FlatPtrHashSet&, streamedForPlayers); +PROXY(IVehicle, IPlayer*, getDriver); +PROXY(IVehicle, const FlatHashSet&, getPassengers); PROXY(IVehicle, void, setPlate, StringView); PROXY(IVehicle, StringView, getPlate); -PROXY(IVehicle, void, setDamageStatus, int, int, uint8_t, uint8_t, IPlayer *); -PROXY(IVehicle, void, getDamageStatus, int &, int &, int &, int &); +PROXY(IVehicle, void, setDamageStatus, int, int, uint8_t, uint8_t, IPlayer*); +PROXY(IVehicle, void, getDamageStatus, int&, int&, int&, int&); PROXY(IVehicle, void, setPaintJob, int); PROXY(IVehicle, int, getPaintJob); PROXY(IVehicle, void, addComponent, int); PROXY(IVehicle, int, getComponentInSlot, int); PROXY(IVehicle, void, removeComponent, int); -PROXY(IVehicle, void, putPlayer, IPlayer &, int); +PROXY(IVehicle, void, putPlayer, IPlayer&, int); PROXY(IVehicle, void, setZAngle, float); PROXY(IVehicle, float, getZAngle); -PROXY(IVehicle, void, setParams, VehicleParams &); -PROXY(IVehicle, void, setParamsForPlayer, IPlayer &, VehicleParams &); +PROXY(IVehicle, void, setParams, VehicleParams&); +PROXY(IVehicle, void, setParamsForPlayer, IPlayer&, VehicleParams&); PROXY_PTR(IVehicle, VehicleParams, getParams); PROXY(IVehicle, bool, isDead); PROXY(IVehicle, void, respawn); @@ -679,15 +680,15 @@ PROXY(IVehicle, void, setRespawnDelay, Seconds); PROXY(IVehicle, bool, isRespawning); PROXY(IVehicle, void, setInterior, int); PROXY(IVehicle, int, getInterior); -PROXY(IVehicle, void, attachTrailer, IVehicle &); +PROXY(IVehicle, void, attachTrailer, IVehicle&); PROXY(IVehicle, void, detachTrailer); PROXY(IVehicle, bool, isTrailer); -PROXY(IVehicle, IVehicle *, getTrailer); -PROXY(IVehicle, IVehicle *, getCab); +PROXY(IVehicle, IVehicle*, getTrailer); +PROXY(IVehicle, IVehicle*, getCab); PROXY(IVehicle, void, repair); -PROXY(IVehicle, void, addCarriage, IVehicle *, int); +PROXY(IVehicle, void, addCarriage, IVehicle*, int); PROXY(IVehicle, void, updateCarriage, Vector3, Vector3); -PROXY(IVehicle, const CarriagesArray &, getCarriages); +PROXY(IVehicle, const CarriagesArray&, getCarriages); PROXY(IVehicle, void, setVelocity, Vector3); PROXY(IVehicle, Vector3, getVelocity); PROXY(IVehicle, void, setAngularVelocity, Vector3); @@ -695,8 +696,8 @@ PROXY(IVehicle, Vector3, getAngularVelocity); PROXY(IVehicle, int, getModel); PROXY(IVehicle, uint8_t, getLandingGearState); PROXY(IVehicle, bool, hasBeenOccupied); -PROXY(IVehicle, const TimePoint &, getLastOccupiedTime); -PROXY(IVehicle, const TimePoint &, getLastSpawnTime); +PROXY(IVehicle, const TimePoint&, getLastOccupiedTime); +PROXY(IVehicle, const TimePoint&, getLastSpawnTime); PROXY(IVehicle, bool, isOccupied); PROXY(IVehicle, void, setSiren, bool); PROXY(IVehicle, uint8_t, getSirenState); @@ -705,30 +706,30 @@ PROXY(IVehicle, float, getTrainSpeed); PROXY(IVehicle, int, getLastDriverPoolID); PROXY_CAST(IVehicle, IEntity); -PROXY(IVehiclesComponent, VehicleModelArray &, models); -PROXY(IVehiclesComponent, IVehicle *, create, bool, int, Vector3, float, int, int, Seconds, bool); +PROXY(IVehiclesComponent, VehicleModelArray&, models); +PROXY(IVehiclesComponent, IVehicle*, create, bool, int, Vector3, float, int, int, Seconds, bool); PROXY_EVENT_DISPATCHER(IVehiclesComponent, VehicleEventHandler, getEventDispatcher); PROXY_EVENT_HANDLER_BEGIN(VehicleEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onVehicleStreamIn, IVehicle &, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onVehicleStreamOut, IVehicle &, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onVehicleDeath, IVehicle &, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerEnterVehicle, IPlayer &, IVehicle &, bool) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerExitVehicle, IPlayer &, IVehicle &) -PROXY_EVENT_HANDLER_EVENT(void, onVehicleDamageStatusUpdate, IVehicle &, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(bool, onVehiclePaintJob, IPlayer &, IVehicle &, int) -PROXY_EVENT_HANDLER_EVENT(bool, onVehicleMod, IPlayer &, IVehicle &, int) -PROXY_EVENT_HANDLER_EVENT(bool, onVehicleRespray, IPlayer &, IVehicle &, int, int) -PROXY_EVENT_HANDLER_EVENT(void, onEnterExitModShop, IPlayer &, bool, int) -PROXY_EVENT_HANDLER_EVENT(void, onVehicleSpawn, IVehicle &) -PROXY_EVENT_HANDLER_EVENT(bool, onUnoccupiedVehicleUpdate, IVehicle &, IPlayer &, UnoccupiedVehicleUpdate const) -PROXY_EVENT_HANDLER_EVENT(bool, onTrailerUpdate, IPlayer &, IVehicle &) -PROXY_EVENT_HANDLER_EVENT(bool, onVehicleSirenStateChange, IPlayer &, IVehicle &, uint8_t) +PROXY_EVENT_HANDLER_EVENT(void, onVehicleStreamIn, IVehicle&, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onVehicleStreamOut, IVehicle&, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onVehicleDeath, IVehicle&, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerEnterVehicle, IPlayer&, IVehicle&, bool) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerExitVehicle, IPlayer&, IVehicle&) +PROXY_EVENT_HANDLER_EVENT(void, onVehicleDamageStatusUpdate, IVehicle&, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(bool, onVehiclePaintJob, IPlayer&, IVehicle&, int) +PROXY_EVENT_HANDLER_EVENT(bool, onVehicleMod, IPlayer&, IVehicle&, int) +PROXY_EVENT_HANDLER_EVENT(bool, onVehicleRespray, IPlayer&, IVehicle&, int, int) +PROXY_EVENT_HANDLER_EVENT(void, onEnterExitModShop, IPlayer&, bool, int) +PROXY_EVENT_HANDLER_EVENT(void, onVehicleSpawn, IVehicle&) +PROXY_EVENT_HANDLER_EVENT(bool, onUnoccupiedVehicleUpdate, IVehicle&, IPlayer&, UnoccupiedVehicleUpdate const) +PROXY_EVENT_HANDLER_EVENT(bool, onTrailerUpdate, IPlayer&, IVehicle&) +PROXY_EVENT_HANDLER_EVENT(bool, onVehicleSirenStateChange, IPlayer&, IVehicle&, uint8_t) PROXY_EVENT_HANDLER_END(VehicleEventHandler, onVehicleStreamIn, onVehicleStreamOut, onVehicleDeath, onPlayerEnterVehicle, onPlayerExitVehicle, onVehicleDamageStatusUpdate, onVehiclePaintJob, - onVehicleMod, onVehicleRespray, onEnterExitModShop, onVehicleSpawn, - onUnoccupiedVehicleUpdate, onTrailerUpdate, onVehicleSirenStateChange) + onVehicleMod, onVehicleRespray, onEnterExitModShop, onVehicleSpawn, onUnoccupiedVehicleUpdate, + onTrailerUpdate, onVehicleSirenStateChange) -PROXY(IPlayerVehicleData, IVehicle *, getVehicle); +PROXY(IPlayerVehicleData, IVehicle*, getVehicle); PROXY(IPlayerVehicleData, void, resetVehicle); PROXY(IPlayerVehicleData, int, getSeat); PROXY(IPlayerVehicleData, bool, isInModShop); @@ -736,41 +737,41 @@ PROXY(IPlayerVehicleData, bool, isInDriveByMode); PROXY(IPlayerVehicleData, bool, isCuffed); // include/component -PROXY(IExtensible, IExtension *, getExtension, UID); -PROXY(IExtensible, bool, addExtension, IExtension *, bool); -PROXY(IExtensible, bool, removeExtension, IExtension *); +PROXY(IExtensible, IExtension*, getExtension, UID); +PROXY(IExtensible, bool, addExtension, IExtension*, bool); +PROXY(IExtensible, bool, removeExtension, IExtension*); PROXY_OVERLOAD(IExtensible, bool, removeExtension, _uid, UID); PROXY(IComponent, int, supportedVersion); PROXY(IComponent, StringView, componentName); PROXY_CAST(IComponent, IUIDProvider); -PROXY(IComponentList, IComponent *, queryComponent, UID); +PROXY(IComponentList, IComponent*, queryComponent, UID); // include/core PROXY(IConfig, StringView, getString, StringView); -PROXY(IConfig, int *, getInt, StringView); -PROXY(IConfig, float *, getFloat, StringView); +PROXY(IConfig, int*, getInt, StringView); +PROXY(IConfig, float*, getFloat, StringView); PROXY(IConfig, size_t, getStrings, StringView, Span); PROXY(IConfig, size_t, getStringsCount, StringView); PROXY(IConfig, ConfigOptionType, getType, StringView); PROXY(IConfig, size_t, getBansCount); -PROXY(IConfig, const BanEntry &, getBan, size_t); -PROXY(IConfig, void, addBan, BanEntry &); +PROXY(IConfig, const BanEntry&, getBan, size_t); +PROXY(IConfig, void, addBan, BanEntry&); PROXY_OVERLOAD(IConfig, void, removeBan, _index, size_t); -PROXY(IConfig, void, removeBan, BanEntry &); +PROXY(IConfig, void, removeBan, BanEntry&); PROXY(IConfig, void, writeBans); PROXY(IConfig, void, reloadBans); PROXY(IConfig, void, clearBans); -PROXY(IConfig, bool, isBanned, BanEntry &); +PROXY(IConfig, bool, isBanned, BanEntry&); PROXY_PTR(IConfig, BoolStringPair, getNameFromAlias, StringView); -PROXY(IConfig, bool *, getBool, StringView); +PROXY(IConfig, bool*, getBool, StringView); PROXY(ICore, SemanticVersion, getVersion); PROXY(ICore, int, getNetworkBitStreamVersion); -PROXY(ICore, IPlayerPool &, getPlayers); -PROXY(ICore, IConfig &, getConfig); -PROXY(ICore, const FlatPtrHashSet &, getNetworks); +PROXY(ICore, IPlayerPool&, getPlayers); +PROXY(ICore, IConfig&, getConfig); +PROXY(ICore, const FlatPtrHashSet&, getNetworks); PROXY(ICore, unsigned, getTickCount); PROXY(ICore, void, setGravity, float); PROXY(ICore, float, getGravity); @@ -804,63 +805,63 @@ PROXY(IEntity, int, getVirtualWorld); PROXY(IEntity, void, setVirtualWorld, int); // include/events -PROXY_NAMED(IEventDispatcher, IEventDispatcher, bool, addEventHandler, void **, event_order_t); -PROXY_NAMED(IEventDispatcher, IEventDispatcher, bool, hasEventHandler, void **, event_order_t); -PROXY_NAMED(IEventDispatcher, IEventDispatcher, bool, removeEventHandler, void **); -PROXY_NAMED(IEventDispatcher, IEventDispatcher, size_t, count); +PROXY_NAMED(IEventDispatcher, IEventDispatcher, bool, addEventHandler, void**, event_order_t); +PROXY_NAMED(IEventDispatcher, IEventDispatcher, bool, hasEventHandler, void**, event_order_t); +PROXY_NAMED(IEventDispatcher, IEventDispatcher, bool, removeEventHandler, void**); +PROXY_NAMED(IEventDispatcher, IEventDispatcher, size_t, count); -PROXY_NAMED(IIndexedEventDispatcher, IIndexedEventDispatcher, bool, addEventHandler, void **, size_t, +PROXY_NAMED(IIndexedEventDispatcher, IIndexedEventDispatcher, bool, addEventHandler, void**, size_t, event_order_t); -PROXY_NAMED(IIndexedEventDispatcher, IIndexedEventDispatcher, bool, hasEventHandler, void **, size_t, +PROXY_NAMED(IIndexedEventDispatcher, IIndexedEventDispatcher, bool, hasEventHandler, void**, size_t, event_order_t); -PROXY_NAMED(IIndexedEventDispatcher, IIndexedEventDispatcher, bool, removeEventHandler, void **, size_t); -PROXY_NAMED(IIndexedEventDispatcher, IIndexedEventDispatcher, size_t, count, size_t); -PROXY_NAMED_OVERLOAD(IIndexedEventDispatcher, IIndexedEventDispatcher, size_t, count, _index, size_t); +PROXY_NAMED(IIndexedEventDispatcher, IIndexedEventDispatcher, bool, removeEventHandler, void**, size_t); +PROXY_NAMED(IIndexedEventDispatcher, IIndexedEventDispatcher, size_t, count, size_t); +PROXY_NAMED_OVERLOAD(IIndexedEventDispatcher, IIndexedEventDispatcher, size_t, count, _index, size_t); // include/network PROXY_EVENT_HANDLER_BEGIN(NetworkEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPeerConnect, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onPeerDisconnect, IPlayer &, PeerDisconnectReason) +PROXY_EVENT_HANDLER_EVENT(void, onPeerConnect, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onPeerDisconnect, IPlayer&, PeerDisconnectReason) PROXY_EVENT_HANDLER_END(NetworkEventHandler, onPeerConnect, onPeerDisconnect) PROXY_EVENT_HANDLER_BEGIN(NetworkInEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onReceivePacket, IPlayer &, int, NetworkBitStream &) -PROXY_EVENT_HANDLER_EVENT(bool, onReceiveRPC, IPlayer &, int, NetworkBitStream &) +PROXY_EVENT_HANDLER_EVENT(bool, onReceivePacket, IPlayer&, int, NetworkBitStream&) +PROXY_EVENT_HANDLER_EVENT(bool, onReceiveRPC, IPlayer&, int, NetworkBitStream&) PROXY_EVENT_HANDLER_END(NetworkInEventHandler, onReceivePacket, onReceiveRPC) PROXY_EVENT_HANDLER_BEGIN(SingleNetworkInEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onReceive, IPlayer &, NetworkBitStream &) +PROXY_EVENT_HANDLER_EVENT(bool, onReceive, IPlayer&, NetworkBitStream&) PROXY_EVENT_HANDLER_END(SingleNetworkInEventHandler, onReceive) PROXY_EVENT_HANDLER_BEGIN(NetworkOutEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onSendPacket, IPlayer *, int, NetworkBitStream &) -PROXY_EVENT_HANDLER_EVENT(bool, onSendRPC, IPlayer *, int, NetworkBitStream &) +PROXY_EVENT_HANDLER_EVENT(bool, onSendPacket, IPlayer*, int, NetworkBitStream&) +PROXY_EVENT_HANDLER_EVENT(bool, onSendRPC, IPlayer*, int, NetworkBitStream&) PROXY_EVENT_HANDLER_END(NetworkOutEventHandler, onSendPacket, onSendRPC) PROXY_EVENT_HANDLER_BEGIN(SingleNetworkOutEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onSend, IPlayer *, NetworkBitStream &) +PROXY_EVENT_HANDLER_EVENT(bool, onSend, IPlayer*, NetworkBitStream&) PROXY_EVENT_HANDLER_END(SingleNetworkOutEventHandler, onSend) PROXY(INetwork, ENetworkType, getNetworkType); -PROXY(INetwork, IEventDispatcher &, getEventDispatcher); -PROXY(INetwork, IEventDispatcher &, getInEventDispatcher); +PROXY(INetwork, IEventDispatcher&, getEventDispatcher); +PROXY(INetwork, IEventDispatcher&, getInEventDispatcher); PROXY_INDEXED_EVENT_DISPATCHER(INetwork, SingleNetworkInEventHandler, getPerRPCInEventDispatcher); PROXY_INDEXED_EVENT_DISPATCHER(INetwork, SingleNetworkInEventHandler, getPerPacketInEventDispatcher); PROXY_EVENT_DISPATCHER(INetwork, NetworkOutEventHandler, getOutEventDispatcher); PROXY_INDEXED_EVENT_DISPATCHER(INetwork, SingleNetworkOutEventHandler, getPerRPCOutEventDispatcher); PROXY_INDEXED_EVENT_DISPATCHER(INetwork, SingleNetworkOutEventHandler, getPerPacketOutEventDispatcher); -PROXY(INetwork, bool, sendPacket, IPlayer &, Span, int, bool); -PROXY(INetwork, bool, broadcastPacket, Span, int, const IPlayer *, bool); -PROXY(INetwork, bool, sendRPC, IPlayer &, int, Span, int, bool); -PROXY(INetwork, bool, broadcastRPC, int, Span, int, IPlayer *, bool); -PROXY(INetwork, NetworkStats, getStatistics, IPlayer *); -PROXY(INetwork, unsigned, getPing, IPlayer &); -PROXY(INetwork, void, disconnect, IPlayer &); -PROXY(INetwork, void, ban, BanEntry &, Milliseconds); -PROXY(INetwork, void, unban, BanEntry &); +PROXY(INetwork, bool, sendPacket, IPlayer&, Span, int, bool); +PROXY(INetwork, bool, broadcastPacket, Span, int, const IPlayer*, bool); +PROXY(INetwork, bool, sendRPC, IPlayer&, int, Span, int, bool); +PROXY(INetwork, bool, broadcastRPC, int, Span, int, IPlayer*, bool); +PROXY(INetwork, NetworkStats, getStatistics, IPlayer*); +PROXY(INetwork, unsigned, getPing, IPlayer&); +PROXY(INetwork, void, disconnect, IPlayer&); +PROXY(INetwork, void, ban, BanEntry&, Milliseconds); +PROXY(INetwork, void, unban, BanEntry&); PROXY(INetwork, void, update); -PROXY(INetworkComponent, INetwork *, getNetwork); +PROXY(INetworkComponent, INetwork*, getNetwork); PROXY(INetworkQueryExtension, bool, addRule, StringView, StringView) PROXY(INetworkQueryExtension, bool, removeRule, StringView) @@ -870,7 +871,7 @@ PROXY(INetworkQueryExtension, bool, isValidRule, StringView) PROXY(IPlayer, void, kick); PROXY(IPlayer, void, ban, StringView); PROXY(IPlayer, bool, isBot); -PROXY(IPlayer, const PeerNetworkData &, getNetworkData); +PROXY(IPlayer, const PeerNetworkData&, getNetworkData); PROXY(IPlayer, unsigned, getPing); PROXY(IPlayer, bool, sendPacket, Span, int, bool); PROXY(IPlayer, bool, sendRPC, int, Span, int, bool); @@ -888,8 +889,8 @@ PROXY(IPlayer, Vector3, getCameraLookAt); PROXY(IPlayer, void, setCameraBehind); PROXY(IPlayer, void, interpolateCameraPosition, Vector3, Vector3, int, PlayerCameraCutType); PROXY(IPlayer, void, interpolateCameraLookAt, Vector3, Vector3, int, PlayerCameraCutType); -PROXY(IPlayer, void, attachCameraToObject, IObject &); -PROXY_OVERLOAD(IPlayer, void, attachCameraToObject, _player, IPlayerObject &); +PROXY(IPlayer, void, attachCameraToObject, IObject&); +PROXY_OVERLOAD(IPlayer, void, attachCameraToObject, _player, IPlayerObject&); PROXY(IPlayer, EPlayerNameStatus, setName, StringView); PROXY(IPlayer, StringView, getName); PROXY(IPlayer, StringView, getSerial); @@ -907,9 +908,9 @@ PROXY(IPlayer, StringView, getShopName); PROXY(IPlayer, void, setDrunkLevel, int); PROXY(IPlayer, int, getDrunkLevel); PROXY(IPlayer, void, setColour, Colour); -PROXY(IPlayer, const Colour &, getColour); -PROXY(IPlayer, void, setOtherColour, IPlayer &, Colour); -PROXY(IPlayer, bool, getOtherColour, IPlayer &, Colour &); +PROXY(IPlayer, const Colour&, getColour); +PROXY(IPlayer, void, setOtherColour, IPlayer&, Colour); +PROXY(IPlayer, bool, getOtherColour, IPlayer&, Colour&); PROXY(IPlayer, void, setControllable, bool); PROXY(IPlayer, bool, getControllable); PROXY(IPlayer, void, setSpectating, bool); @@ -918,11 +919,11 @@ PROXY(IPlayer, unsigned, getWantedLevel); PROXY(IPlayer, void, playSound, uint32_t, Vector3); PROXY(IPlayer, uint32_t, lastPlayedSound); PROXY(IPlayer, void, playAudio, StringView, bool, Vector3, float); -PROXY(IPlayer, bool, playerCrimeReport, IPlayer &, int); +PROXY(IPlayer, bool, playerCrimeReport, IPlayer&, int); PROXY(IPlayer, void, stopAudio); PROXY(IPlayer, StringView, lastPlayedAudio); PROXY(IPlayer, void, createExplosion, Vector3, int, float); -PROXY(IPlayer, void, sendDeathMessage, IPlayer &, IPlayer *, int); +PROXY(IPlayer, void, sendDeathMessage, IPlayer&, IPlayer*, int); PROXY(IPlayer, void, sendEmptyDeathMessage); PROXY(IPlayer, void, removeDefaultObjects, unsigned, Vector3, float); PROXY(IPlayer, void, forceClassSelection); @@ -933,7 +934,7 @@ PROXY(IPlayer, int, getMoney); PROXY(IPlayer, void, setMapIcon, int, Vector3, int, Colour, MapIconStyle); PROXY(IPlayer, void, unsetMapIcon, int); PROXY(IPlayer, void, useStuntBonuses, bool); -PROXY(IPlayer, void, toggleOtherNameTag, IPlayer &, bool); +PROXY(IPlayer, void, toggleOtherNameTag, IPlayer&, bool); PROXY(IPlayer, void, setTime, Hours, Minutes); PROXY_PTR(IPlayer, HoursMinutesPair, getTime); PROXY(IPlayer, void, useClock, bool); @@ -950,27 +951,27 @@ PROXY(IPlayer, float, getArmour); PROXY(IPlayer, void, setGravity, float); PROXY(IPlayer, float, getGravity); PROXY(IPlayer, void, setWorldTime, Hours); -PROXY(IPlayer, void, applyAnimation, const AnimationData &, PlayerAnimationSyncType); +PROXY(IPlayer, void, applyAnimation, const AnimationData&, PlayerAnimationSyncType); PROXY(IPlayer, void, clearAnimations, PlayerAnimationSyncType); PROXY(IPlayer, PlayerAnimationData, getAnimationData); PROXY(IPlayer, PlayerSurfingData, getSurfingData); -PROXY(IPlayer, void, streamInForPlayer, IPlayer &); -PROXY(IPlayer, bool, isStreamedInForPlayer, const IPlayer &); -PROXY(IPlayer, void, streamOutForPlayer, IPlayer &); -PROXY(IPlayer, const FlatPtrHashSet &, streamedForPlayers); +PROXY(IPlayer, void, streamInForPlayer, IPlayer&); +PROXY(IPlayer, bool, isStreamedInForPlayer, const IPlayer&); +PROXY(IPlayer, void, streamOutForPlayer, IPlayer&); +PROXY(IPlayer, const FlatPtrHashSet&, streamedForPlayers); PROXY(IPlayer, PlayerState, getState); PROXY(IPlayer, void, setTeam, int); PROXY(IPlayer, int, getTeam); PROXY(IPlayer, void, setSkin, int, bool); PROXY(IPlayer, int, getSkin); -PROXY(IPlayer, void, setChatBubble, StringView, const Colour &, float, Milliseconds); -PROXY(IPlayer, void, sendClientMessage, const Colour &, StringView); -PROXY(IPlayer, void, sendChatMessage, IPlayer &, StringView); +PROXY(IPlayer, void, setChatBubble, StringView, const Colour&, float, Milliseconds); +PROXY(IPlayer, void, sendClientMessage, const Colour&, StringView); +PROXY(IPlayer, void, sendChatMessage, IPlayer&, StringView); PROXY(IPlayer, void, sendCommand, StringView); PROXY(IPlayer, void, sendGameText, StringView, Milliseconds, int); PROXY(IPlayer, void, hideGameText, int); PROXY(IPlayer, bool, hasGameText, int); -PROXY(IPlayer, bool, getGameText, int, StringView &, Milliseconds &, Milliseconds &); +PROXY(IPlayer, bool, getGameText, int, StringView&, Milliseconds&, Milliseconds&); PROXY(IPlayer, void, setWeather, int); PROXY(IPlayer, int, getWeather); PROXY(IPlayer, void, setWorldBounds, Vector4); @@ -984,23 +985,23 @@ PROXY(IPlayer, void, setVelocity, Vector3); PROXY(IPlayer, Vector3, getVelocity); PROXY(IPlayer, void, setInterior, unsigned); PROXY(IPlayer, unsigned, getInterior); -PROXY(IPlayer, const PlayerKeyData &, getKeyData); -PROXY(IPlayer, const SkillsArray &, getSkillLevels); -PROXY(IPlayer, const PlayerAimData &, getAimData); -PROXY(IPlayer, const PlayerBulletData &, getBulletData); +PROXY(IPlayer, const PlayerKeyData&, getKeyData); +PROXY(IPlayer, const SkillsArray&, getSkillLevels); +PROXY(IPlayer, const PlayerAimData&, getAimData); +PROXY(IPlayer, const PlayerBulletData&, getBulletData); PROXY(IPlayer, void, useCameraTargeting, bool); PROXY(IPlayer, bool, hasCameraTargeting); PROXY(IPlayer, void, removeFromVehicle, bool); -PROXY(IPlayer, IPlayer *, getCameraTargetPlayer); -PROXY(IPlayer, IVehicle *, getCameraTargetVehicle); -PROXY(IPlayer, IObject *, getCameraTargetObject); -PROXY(IPlayer, IActor *, getCameraTargetActor); -PROXY(IPlayer, IPlayer *, getTargetPlayer); -PROXY(IPlayer, IActor *, getTargetActor); +PROXY(IPlayer, IPlayer*, getCameraTargetPlayer); +PROXY(IPlayer, IVehicle*, getCameraTargetVehicle); +PROXY(IPlayer, IObject*, getCameraTargetObject); +PROXY(IPlayer, IActor*, getCameraTargetActor); +PROXY(IPlayer, IPlayer*, getTargetPlayer); +PROXY(IPlayer, IActor*, getTargetActor); PROXY(IPlayer, void, setRemoteVehicleCollisions, bool); -PROXY(IPlayer, void, spectatePlayer, IPlayer &, PlayerSpectateMode); -PROXY(IPlayer, void, spectateVehicle, IVehicle &, PlayerSpectateMode); -PROXY(IPlayer, const PlayerSpectateData &, getSpectateData); +PROXY(IPlayer, void, spectatePlayer, IPlayer&, PlayerSpectateMode); +PROXY(IPlayer, void, spectateVehicle, IVehicle&, PlayerSpectateMode); +PROXY(IPlayer, const PlayerSpectateData&, getSpectateData); PROXY(IPlayer, void, sendClientCheck, int, int, int, int); PROXY(IPlayer, void, toggleGhostMode, bool); PROXY(IPlayer, bool, isGhostModeEnabled); @@ -1014,20 +1015,20 @@ PROXY(IPlayer, bool, isTeleportAllowed); PROXY(IPlayer, bool, isUsingOfficialClient); PROXY_CAST(IPlayer, IEntity); -PROXY(IPlayerPool, const FlatPtrHashSet &, entries); -PROXY(IPlayerPool, const FlatPtrHashSet &, players); -PROXY(IPlayerPool, const FlatPtrHashSet &, bots); -PROXY(IPlayerPool, bool, isNameTaken, StringView, const IPlayer *); -PROXY(IPlayerPool, void, sendClientMessageToAll, const Colour &, StringView); -PROXY(IPlayerPool, void, sendChatMessageToAll, IPlayer &, StringView); +PROXY(IPlayerPool, const FlatPtrHashSet&, entries); +PROXY(IPlayerPool, const FlatPtrHashSet&, players); +PROXY(IPlayerPool, const FlatPtrHashSet&, bots); +PROXY(IPlayerPool, bool, isNameTaken, StringView, const IPlayer*); +PROXY(IPlayerPool, void, sendClientMessageToAll, const Colour&, StringView); +PROXY(IPlayerPool, void, sendChatMessageToAll, IPlayer&, StringView); PROXY(IPlayerPool, void, sendGameTextToAll, StringView, Milliseconds, int); PROXY(IPlayerPool, void, hideGameTextForAll, int); -PROXY(IPlayerPool, void, sendDeathMessageToAll, IPlayer *, IPlayer &, int); +PROXY(IPlayerPool, void, sendDeathMessageToAll, IPlayer*, IPlayer&, int); PROXY(IPlayerPool, void, sendEmptyDeathMessageToAll); PROXY(IPlayerPool, void, createExplosionForAll, Vector3, int, float); -PROXY_PTR(IPlayerPool, NewConnectionPlayerPair, requestPlayer, const PeerNetworkData &, const PeerRequestParams &); -PROXY(IPlayerPool, void, broadcastPacket, Span, int, const IPlayer *, bool); -PROXY(IPlayerPool, void, broadcastRPC, int, Span, int, const IPlayer *, bool); +PROXY_PTR(IPlayerPool, NewConnectionPlayerPair, requestPlayer, const PeerNetworkData&, const PeerRequestParams&); +PROXY(IPlayerPool, void, broadcastPacket, Span, int, const IPlayer*, bool); +PROXY(IPlayerPool, void, broadcastRPC, int, Span, int, const IPlayer*, bool); PROXY(IPlayerPool, bool, isNameValid, StringView); PROXY(IPlayerPool, void, allowNickNameCharacter, char, bool); PROXY(IPlayerPool, bool, isNickNameCharacterAllowed, char); @@ -1036,86 +1037,86 @@ PROXY_CAST_NAMED(IPlayerPool, IPlayerPool, IReadOnlyPool, IReadOnlyPool PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerSpawnEventHandler, getPlayerSpawnDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerSpawnEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerRequestSpawn, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerSpawn, IPlayer &) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerRequestSpawn, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerSpawn, IPlayer&) PROXY_EVENT_HANDLER_END(PlayerSpawnEventHandler, onPlayerRequestSpawn, onPlayerSpawn) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerConnectEventHandler, getPlayerConnectDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerConnectEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onIncomingConnection, IPlayer &, StringView, unsigned short) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerConnect, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerDisconnect, IPlayer &, PeerDisconnectReason) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerClientInit, IPlayer &) +PROXY_EVENT_HANDLER_EVENT(void, onIncomingConnection, IPlayer&, StringView, unsigned short) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerConnect, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerDisconnect, IPlayer&, PeerDisconnectReason) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerClientInit, IPlayer&) PROXY_EVENT_HANDLER_END(PlayerConnectEventHandler, onIncomingConnection, onPlayerConnect, onPlayerDisconnect, onPlayerClientInit) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerStreamEventHandler, getPlayerStreamDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerStreamEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerStreamIn, IPlayer &, IPlayer &) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerStreamOut, IPlayer &, IPlayer &) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerStreamIn, IPlayer&, IPlayer&) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerStreamOut, IPlayer&, IPlayer&) PROXY_EVENT_HANDLER_END(PlayerStreamEventHandler, onPlayerStreamIn, onPlayerStreamOut) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerTextEventHandler, getPlayerTextDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerTextEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerText, IPlayer &, StringView) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerCommandText, IPlayer &, StringView) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerText, IPlayer&, StringView) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerCommandText, IPlayer&, StringView) PROXY_EVENT_HANDLER_END(PlayerTextEventHandler, onPlayerText, onPlayerCommandText) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerShotEventHandler, getPlayerShotDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerShotEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotMissed, IPlayer &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotPlayer, IPlayer &, IPlayer &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotVehicle, IPlayer &, IVehicle &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotObject, IPlayer &, IObject &, const PlayerBulletData &) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotPlayerObject, IPlayer &, IPlayerObject &, const PlayerBulletData &) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotMissed, IPlayer&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotPlayer, IPlayer&, IPlayer&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotVehicle, IPlayer&, IVehicle&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotObject, IPlayer&, IObject&, const PlayerBulletData&) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerShotPlayerObject, IPlayer&, IPlayerObject&, const PlayerBulletData&) PROXY_EVENT_HANDLER_END(PlayerShotEventHandler, onPlayerShotMissed, onPlayerShotPlayer, onPlayerShotVehicle, onPlayerShotObject, onPlayerShotPlayerObject) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerChangeEventHandler, getPlayerChangeDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerChangeEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerScoreChange, IPlayer &, int) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerNameChange, IPlayer &, StringView) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerInteriorChange, IPlayer &, unsigned, unsigned) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerStateChange, IPlayer &, PlayerState, PlayerState) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerKeyStateChange, IPlayer &, uint32_t, uint32_t) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerScoreChange, IPlayer&, int) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerNameChange, IPlayer&, StringView) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerInteriorChange, IPlayer&, unsigned, unsigned) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerStateChange, IPlayer&, PlayerState, PlayerState) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerKeyStateChange, IPlayer&, uint32_t, uint32_t) PROXY_EVENT_HANDLER_END(PlayerChangeEventHandler, onPlayerScoreChange, onPlayerNameChange, onPlayerInteriorChange, onPlayerStateChange, onPlayerKeyStateChange) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerDamageEventHandler, getPlayerDamageDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerDamageEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerDeath, IPlayer &, IPlayer *, int) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerTakeDamage, IPlayer &, IPlayer *, float, unsigned, BodyPart) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerGiveDamage, IPlayer &, IPlayer &, float, unsigned, BodyPart) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerDeath, IPlayer&, IPlayer*, int) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerTakeDamage, IPlayer&, IPlayer*, float, unsigned, BodyPart) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerGiveDamage, IPlayer&, IPlayer&, float, unsigned, BodyPart) PROXY_EVENT_HANDLER_END(PlayerDamageEventHandler, onPlayerDeath, onPlayerTakeDamage, onPlayerGiveDamage) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerClickEventHandler, getPlayerClickDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerClickEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickMap, IPlayer &, Vector3) -PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickPlayer, IPlayer &, IPlayer &, PlayerClickSource) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickMap, IPlayer&, Vector3) +PROXY_EVENT_HANDLER_EVENT(void, onPlayerClickPlayer, IPlayer&, IPlayer&, PlayerClickSource) PROXY_EVENT_HANDLER_END(PlayerClickEventHandler, onPlayerClickMap, onPlayerClickPlayer) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerCheckEventHandler, getPlayerCheckDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerCheckEventHandler) -PROXY_EVENT_HANDLER_EVENT(void, onClientCheckResponse, IPlayer &, int, int, int) +PROXY_EVENT_HANDLER_EVENT(void, onClientCheckResponse, IPlayer&, int, int, int) PROXY_EVENT_HANDLER_END(PlayerCheckEventHandler, onClientCheckResponse) PROXY_EVENT_DISPATCHER(IPlayerPool, PlayerUpdateEventHandler, getPlayerUpdateDispatcher); PROXY_EVENT_HANDLER_BEGIN(PlayerUpdateEventHandler) -PROXY_EVENT_HANDLER_EVENT(bool, onPlayerUpdate, IPlayer &, TimePoint) +PROXY_EVENT_HANDLER_EVENT(bool, onPlayerUpdate, IPlayer&, TimePoint) PROXY_EVENT_HANDLER_END(PlayerUpdateEventHandler, onPlayerUpdate) PROXY_EVENT_DISPATCHER_NAMED(IPlayerPool, PoolEventHandler, PoolEventHandler, getPoolEventDispatcher); // include/pool -PROXY_CAST_NAMED(IPoolComponent, IPoolComponent, IPool, IPool); -PROXY_NAMED(IReadOnlyPool, IReadOnlyPool, void *, get, int); -PROXY_NAMED_PTR(IReadOnlyPool, IReadOnlyPool, SizePair, bounds); - -PROXY_NAMED(IPool, IPool, void, release, int); -PROXY_NAMED(IPool, IPool, void, lock, int); -PROXY_NAMED(IPool, IPool, bool, unlock, int); -PROXY_NAMED(IPool, IPool, IEventDispatcher> &, getPoolEventDispatcher); -PROXY_NAMED(IPool, IPool, size_t, count); +PROXY_CAST_NAMED(IPoolComponent, IPoolComponent, IPool, IPool); +PROXY_NAMED(IReadOnlyPool, IReadOnlyPool, void*, get, int); +PROXY_NAMED_PTR(IReadOnlyPool, IReadOnlyPool, SizePair, bounds); + +PROXY_NAMED(IPool, IPool, void, release, int); +PROXY_NAMED(IPool, IPool, void, lock, int); +PROXY_NAMED(IPool, IPool, bool, unlock, int); +PROXY_NAMED(IPool, IPool, IEventDispatcher>&, getPoolEventDispatcher); +PROXY_NAMED(IPool, IPool, size_t, count); #ifdef __clang__ #pragma clang diagnostic pop diff --git a/src/sampsharp-component/proxies/config.cpp b/src/sampsharp-component/proxies/config.cpp index 88da8dd7..eb9bbe22 100644 --- a/src/sampsharp-component/proxies/config.cpp +++ b/src/sampsharp-component/proxies/config.cpp @@ -1,21 +1,21 @@ #include #include "../proxy-api.hpp" -typedef bool(API_CALLTYPE *OptionEnumeratorCallbackFn)(StringView name, ConfigOptionType type); +typedef bool(API_CALLTYPE* OptionEnumeratorCallbackFn)(StringView name, ConfigOptionType type); class OptionEnumeratorCallbackImpl final : public OptionEnumeratorCallback { OptionEnumeratorCallbackFn _fn; public: - OptionEnumeratorCallbackImpl(OptionEnumeratorCallbackFn fn) : _fn(fn) {} - bool proc(StringView name, ConfigOptionType type) override + OptionEnumeratorCallbackImpl(OptionEnumeratorCallbackFn fn) : + _fn(fn) { - return _fn(name, type); } + bool proc(StringView name, ConfigOptionType type) override { return _fn(name, type); } }; -extern "C" SDK_EXPORT void __CDECL IConfig_enumOptions(IConfig *subject, OptionEnumeratorCallbackFn callback) +extern "C" SDK_EXPORT void __CDECL IConfig_enumOptions(IConfig* subject, OptionEnumeratorCallbackFn callback) { if (!subject) { diff --git a/src/sampsharp-component/proxies/extension.cpp b/src/sampsharp-component/proxies/extension.cpp index e535f216..7ab254a3 100644 --- a/src/sampsharp-component/proxies/extension.cpp +++ b/src/sampsharp-component/proxies/extension.cpp @@ -3,20 +3,22 @@ #include "../proxy-api.hpp" -typedef void(API_CALLTYPE * free_fn)(); +typedef void(API_CALLTYPE* free_fn)(); class ManagedExtensionImpl final : IExtension { private: UID extensionID_; free_fn free_fptr_; - void * handle_; + void* handle_; -public: - ManagedExtensionImpl(UID extensionID, free_fn free_fptr, void * handle) : +public: + ManagedExtensionImpl(UID extensionID, free_fn free_fptr, void* handle) : extensionID_(extensionID), free_fptr_(free_fptr), - handle_(handle) { } + handle_(handle) + { + } UID getExtensionID() override { return extensionID_; } @@ -24,38 +26,39 @@ class ManagedExtensionImpl final : IExtension { free_fptr_(); delete this; - } + } - void * getHandle() {return handle_; } + void* getHandle() { return handle_; } - void reset() override { } + void reset() override {} }; -extern "C" SDK_EXPORT ManagedExtensionImpl * __CDECL ManagedExtensionImpl_create(UID a, free_fn b, void * c) +extern "C" SDK_EXPORT ManagedExtensionImpl* __CDECL ManagedExtensionImpl_create(UID a, free_fn b, void* c) { return new ManagedExtensionImpl(a, b, c); } -extern "C" SDK_EXPORT void __CDECL ManagedExtensionImpl_delete(ManagedExtensionImpl * handler) +extern "C" SDK_EXPORT void __CDECL ManagedExtensionImpl_delete(ManagedExtensionImpl* handler) { delete handler; } -extern "C" SDK_EXPORT void * __CDECL ManagedExtensionImpl_getHandle(ManagedExtensionImpl * handler) +extern "C" SDK_EXPORT void* __CDECL ManagedExtensionImpl_getHandle(ManagedExtensionImpl* handler) { return handler->getHandle(); } -struct workaround { - void * vptr; +struct workaround +{ + void* vptr; FlatHashMap> miscExtensions; }; -extern "C" SDK_EXPORT IExtension * __CDECL IExtensible_getExtension_workaround(IExtensible * subject, UID extensionID) +extern "C" SDK_EXPORT IExtension* __CDECL IExtensible_getExtension_workaround(IExtensible* subject, UID extensionID) { // workaround for the fact that the SDK doesn't expose the miscExtensions field // ref: https://github.com/openmultiplayer/open.mp-sdk/issues/44 - workaround * w = (workaround *) subject; + workaround* w = (workaround*)subject; auto it = w->miscExtensions.find(extensionID); if (it != w->miscExtensions.end()) @@ -65,4 +68,3 @@ extern "C" SDK_EXPORT IExtension * __CDECL IExtensible_getExtension_workaround(I return subject->getExtension(extensionID); } - diff --git a/src/sampsharp-component/proxies/logger.cpp b/src/sampsharp-component/proxies/logger.cpp index 1be0e01a..7d61115a 100644 --- a/src/sampsharp-component/proxies/logger.cpp +++ b/src/sampsharp-component/proxies/logger.cpp @@ -1,26 +1,38 @@ #include #include "../proxy-api.hpp" -extern "C" SDK_EXPORT void __CDECL ILogger_printLn(ILogger * subject, const char * msg) +extern "C" SDK_EXPORT void __CDECL ILogger_printLn(ILogger* subject, const char* msg) { - if (!subject) { return; } + if (!subject) + { + return; + } return subject->printLn("%s", msg); } -extern "C" SDK_EXPORT void __CDECL ILogger_logLn(ILogger * subject, LogLevel level, const char * msg) +extern "C" SDK_EXPORT void __CDECL ILogger_logLn(ILogger* subject, LogLevel level, const char* msg) { - if (!subject) { return; } + if (!subject) + { + return; + } return subject->logLn(level, "%s", msg); } -extern "C" SDK_EXPORT void __CDECL ILogger_printLnU8(ILogger * subject, const char * msg) +extern "C" SDK_EXPORT void __CDECL ILogger_printLnU8(ILogger* subject, const char* msg) { - if (!subject) { return; } + if (!subject) + { + return; + } return subject->printLnU8("%s", msg); } -extern "C" SDK_EXPORT void __CDECL ILogger_logLnU8(ILogger * subject, LogLevel level, const char * msg) +extern "C" SDK_EXPORT void __CDECL ILogger_logLnU8(ILogger* subject, LogLevel level, const char* msg) { - if (!subject) { return; } + if (!subject) + { + return; + } return subject->logLnU8(level, "%s", msg); } diff --git a/src/sampsharp-component/proxies/pool-event-handler.cpp b/src/sampsharp-component/proxies/pool-event-handler.cpp index 53db3c73..fc24c7e3 100644 --- a/src/sampsharp-component/proxies/pool-event-handler.cpp +++ b/src/sampsharp-component/proxies/pool-event-handler.cpp @@ -4,33 +4,30 @@ #include "../proxy-api.hpp" // PoolEventHandler -class PoolEventHandlerImpl final : PoolEventHandler +class PoolEventHandlerImpl final : PoolEventHandler { - typedef void(API_CALLTYPE * handle_fn)(void *&); + typedef void(API_CALLTYPE* handle_fn)(void*&); handle_fn onPoolEntryCreated_; handle_fn onPoolEntryDestroyed_; -public: - PoolEventHandlerImpl(void ** onPoolEntryCreated, void ** onPoolEntryDestroyed) : - onPoolEntryCreated_(reinterpret_cast(onPoolEntryCreated)), - onPoolEntryDestroyed_(reinterpret_cast(onPoolEntryDestroyed)) { } - void onPoolEntryCreated(void *& entry) override - { - onPoolEntryCreated_(entry); - } - void onPoolEntryDestroyed(void *& entry) override +public: + PoolEventHandlerImpl(void** onPoolEntryCreated, void** onPoolEntryDestroyed) : + onPoolEntryCreated_(reinterpret_cast(onPoolEntryCreated)), + onPoolEntryDestroyed_(reinterpret_cast(onPoolEntryDestroyed)) { - onPoolEntryDestroyed_(entry); } + + void onPoolEntryCreated(void*& entry) override { onPoolEntryCreated_(entry); } + void onPoolEntryDestroyed(void*& entry) override { onPoolEntryDestroyed_(entry); } }; -extern "C" SDK_EXPORT PoolEventHandlerImpl * __CDECL PoolEventHandlerImpl_create(void ** a, void ** b) +extern "C" SDK_EXPORT PoolEventHandlerImpl* __CDECL PoolEventHandlerImpl_create(void** a, void** b) { return new PoolEventHandlerImpl(a, b); } -extern "C" SDK_EXPORT void __CDECL PoolEventHandlerImpl_delete(const PoolEventHandlerImpl * handler) +extern "C" SDK_EXPORT void __CDECL PoolEventHandlerImpl_delete(const PoolEventHandlerImpl* handler) { delete handler; } diff --git a/src/sampsharp-component/proxies/pool.cpp b/src/sampsharp-component/proxies/pool.cpp index 00b4fa16..a21e0707 100644 --- a/src/sampsharp-component/proxies/pool.cpp +++ b/src/sampsharp-component/proxies/pool.cpp @@ -2,8 +2,10 @@ #include "../proxy-api.hpp" template -struct IPoolHack : public IPool { - const FlatPtrHashSet& exposeEntries() { +struct IPoolHack : public IPool +{ + const FlatPtrHashSet& exposeEntries() + { return this->entries(); // Accessing protected method } }; diff --git a/src/sampsharp-component/proxies/robin-hood.cpp b/src/sampsharp-component/proxies/robin-hood.cpp index be8e088f..3a275a17 100644 --- a/src/sampsharp-component/proxies/robin-hood.cpp +++ b/src/sampsharp-component/proxies/robin-hood.cpp @@ -1,27 +1,31 @@ #include #include "../proxy-api.hpp" -struct FlatHashSetPtr { void* a; void* b; }; +struct FlatHashSetPtr +{ + void* a; + void* b; +}; -extern "C" SDK_EXPORT FlatHashSetPtr __CDECL FlatPtrHashSet_begin(FlatPtrHashSet& set) +extern "C" SDK_EXPORT FlatHashSetPtr __CDECL FlatPtrHashSet_begin(FlatPtrHashSet& set) { auto it = set.begin(); return *(FlatHashSetPtr*)⁢ } -extern "C" SDK_EXPORT FlatHashSetPtr __CDECL FlatPtrHashSet_end(FlatPtrHashSet& set) +extern "C" SDK_EXPORT FlatHashSetPtr __CDECL FlatPtrHashSet_end(FlatPtrHashSet& set) { auto it = set.end(); return *(FlatHashSetPtr*)⁢ } -extern "C" SDK_EXPORT FlatHashSetPtr __CDECL FlatPtrHashSet_inc(FlatPtrHashSet::iterator value) +extern "C" SDK_EXPORT FlatHashSetPtr __CDECL FlatPtrHashSet_inc(FlatPtrHashSet::iterator value) { value++; return *(FlatHashSetPtr*)&value; } -extern "C" SDK_EXPORT size_t __CDECL FlatPtrHashSet_size(FlatPtrHashSet& set) +extern "C" SDK_EXPORT size_t __CDECL FlatPtrHashSet_size(FlatPtrHashSet& set) { return set.size(); } @@ -44,7 +48,7 @@ extern "C" SDK_EXPORT FlatHashSetPtr __CDECL FlatHashSetStringView_inc(FlatHashS return *(FlatHashSetPtr*)&value; } -extern "C" SDK_EXPORT size_t __CDECL FlatHashSetStringView_size(FlatHashSet& set) +extern "C" SDK_EXPORT size_t __CDECL FlatHashSetStringView_size(FlatHashSet& set) { return set.size(); } diff --git a/src/sampsharp-component/proxies/vehicles.cpp b/src/sampsharp-component/proxies/vehicles.cpp index eee8a648..2b5732ad 100644 --- a/src/sampsharp-component/proxies/vehicles.cpp +++ b/src/sampsharp-component/proxies/vehicles.cpp @@ -17,7 +17,8 @@ extern "C" SDK_EXPORT bool vehicles_getVehicleModelInfo(int model, VehicleModelI { return Impl::getVehicleModelInfo(model, type, out); } -extern "C" SDK_EXPORT void vehicles_getRandomVehicleColour(int modelid, int& colour1, int& colour2, int& colour3, int& colour4) +extern "C" SDK_EXPORT void vehicles_getRandomVehicleColour(int modelid, int& colour1, int& colour2, int& colour3, + int& colour4) { return Impl::getRandomVehicleColour(modelid, colour1, colour2, colour3, colour4); } diff --git a/src/sampsharp-component/proxy-api.hpp b/src/sampsharp-component/proxy-api.hpp index e2fcccc9..92aeb4a5 100644 --- a/src/sampsharp-component/proxy-api.hpp +++ b/src/sampsharp-component/proxy-api.hpp @@ -26,8 +26,8 @@ namespace sampsharp [[noreturn]] inline T proxy_default_unsupported(const char* name) { std::fprintf(stderr, - "sampsharp: PROXY call with null subject returning an unsupported type for '%s'. Aborting.\n", - name); + "sampsharp: PROXY call with null subject returning an unsupported type for '%s'. Aborting.\n", + name); std::terminate(); } @@ -60,66 +60,105 @@ namespace sampsharp // // expand variadic args as a numbered parameter list. e.g. _EXPAND_PARAM(a, b, X, Y) -> aXb _2, aYb _1 -#define _EXPAND_PARAM(prefix,postfix,...) _EXPAND_PARAM_N(__VA_ARGS__,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)(prefix,postfix,##__VA_ARGS__) -#define _EXPAND_PARAM_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, n, ...) _EXPAND_PARAM ## n +#define _EXPAND_PARAM(prefix, postfix, ...) \ + _EXPAND_PARAM_N(__VA_ARGS__, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, \ + 2, 1, 0) \ + (prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ + _21, _22, _23, _24, _25, n, ...) \ + _EXPAND_PARAM##n #define _EXPAND_PARAM1(prefix, postfix, type, ...) prefix##type##postfix _1 -#define _EXPAND_PARAM2(prefix, postfix, type, ...) prefix##type##postfix _2, _EXPAND_PARAM1(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM3(prefix, postfix, type, ...) prefix##type##postfix _3, _EXPAND_PARAM2(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM4(prefix, postfix, type, ...) prefix##type##postfix _4, _EXPAND_PARAM3(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM5(prefix, postfix, type, ...) prefix##type##postfix _5, _EXPAND_PARAM4(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM6(prefix, postfix, type, ...) prefix##type##postfix _6, _EXPAND_PARAM5(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM7(prefix, postfix, type, ...) prefix##type##postfix _7, _EXPAND_PARAM6(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM8(prefix, postfix, type, ...) prefix##type##postfix _8, _EXPAND_PARAM7(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM9(prefix, postfix, type, ...) prefix##type##postfix _9, _EXPAND_PARAM8(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM10(prefix, postfix, type, ...) prefix##type##postfix _10, _EXPAND_PARAM9(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM11(prefix, postfix, type, ...) prefix##type##postfix _11, _EXPAND_PARAM10(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM12(prefix, postfix, type, ...) prefix##type##postfix _12, _EXPAND_PARAM11(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM13(prefix, postfix, type, ...) prefix##type##postfix _13, _EXPAND_PARAM12(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM14(prefix, postfix, type, ...) prefix##type##postfix _14, _EXPAND_PARAM13(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM15(prefix, postfix, type, ...) prefix##type##postfix _15, _EXPAND_PARAM14(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM16(prefix, postfix, type, ...) prefix##type##postfix _16, _EXPAND_PARAM15(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM17(prefix, postfix, type, ...) prefix##type##postfix _17, _EXPAND_PARAM16(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM18(prefix, postfix, type, ...) prefix##type##postfix _18, _EXPAND_PARAM17(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM19(prefix, postfix, type, ...) prefix##type##postfix _19, _EXPAND_PARAM18(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM20(prefix, postfix, type, ...) prefix##type##postfix _20, _EXPAND_PARAM19(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM21(prefix, postfix, type, ...) prefix##type##postfix _21, _EXPAND_PARAM20(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM22(prefix, postfix, type, ...) prefix##type##postfix _22, _EXPAND_PARAM21(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM23(prefix, postfix, type, ...) prefix##type##postfix _23, _EXPAND_PARAM22(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM24(prefix, postfix, type, ...) prefix##type##postfix _24, _EXPAND_PARAM23(prefix, postfix, ##__VA_ARGS__) -#define _EXPAND_PARAM25(prefix, postfix, type, ...) prefix##type##postfix _25, _EXPAND_PARAM24(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM2(prefix, postfix, type, ...) \ + prefix##type##postfix _2, _EXPAND_PARAM1(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM3(prefix, postfix, type, ...) \ + prefix##type##postfix _3, _EXPAND_PARAM2(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM4(prefix, postfix, type, ...) \ + prefix##type##postfix _4, _EXPAND_PARAM3(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM5(prefix, postfix, type, ...) \ + prefix##type##postfix _5, _EXPAND_PARAM4(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM6(prefix, postfix, type, ...) \ + prefix##type##postfix _6, _EXPAND_PARAM5(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM7(prefix, postfix, type, ...) \ + prefix##type##postfix _7, _EXPAND_PARAM6(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM8(prefix, postfix, type, ...) \ + prefix##type##postfix _8, _EXPAND_PARAM7(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM9(prefix, postfix, type, ...) \ + prefix##type##postfix _9, _EXPAND_PARAM8(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM10(prefix, postfix, type, ...) \ + prefix##type##postfix _10, _EXPAND_PARAM9(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM11(prefix, postfix, type, ...) \ + prefix##type##postfix _11, _EXPAND_PARAM10(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM12(prefix, postfix, type, ...) \ + prefix##type##postfix _12, _EXPAND_PARAM11(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM13(prefix, postfix, type, ...) \ + prefix##type##postfix _13, _EXPAND_PARAM12(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM14(prefix, postfix, type, ...) \ + prefix##type##postfix _14, _EXPAND_PARAM13(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM15(prefix, postfix, type, ...) \ + prefix##type##postfix _15, _EXPAND_PARAM14(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM16(prefix, postfix, type, ...) \ + prefix##type##postfix _16, _EXPAND_PARAM15(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM17(prefix, postfix, type, ...) \ + prefix##type##postfix _17, _EXPAND_PARAM16(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM18(prefix, postfix, type, ...) \ + prefix##type##postfix _18, _EXPAND_PARAM17(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM19(prefix, postfix, type, ...) \ + prefix##type##postfix _19, _EXPAND_PARAM18(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM20(prefix, postfix, type, ...) \ + prefix##type##postfix _20, _EXPAND_PARAM19(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM21(prefix, postfix, type, ...) \ + prefix##type##postfix _21, _EXPAND_PARAM20(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM22(prefix, postfix, type, ...) \ + prefix##type##postfix _22, _EXPAND_PARAM21(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM23(prefix, postfix, type, ...) \ + prefix##type##postfix _23, _EXPAND_PARAM22(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM24(prefix, postfix, type, ...) \ + prefix##type##postfix _24, _EXPAND_PARAM23(prefix, postfix, ##__VA_ARGS__) +#define _EXPAND_PARAM25(prefix, postfix, type, ...) \ + prefix##type##postfix _25, _EXPAND_PARAM24(prefix, postfix, ##__VA_ARGS__) // expand variadic args as a numbered argument list. e.g. _EXPAND_ARG(,X, Y) -> _2, _1 -#define _EXPAND_ARG(prefix, ...) _EXPAND_ARG_N(__VA_ARGS__,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)(prefix,##__VA_ARGS__) -#define _EXPAND_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, n, ...) _EXPAND_ARG ## n -#define _EXPAND_ARG1(prefix,type, ...) prefix _1 -#define _EXPAND_ARG2(prefix,type, ...) prefix _2, _EXPAND_ARG1(prefix,##__VA_ARGS__) -#define _EXPAND_ARG3(prefix,type, ...) prefix _3, _EXPAND_ARG2(prefix,##__VA_ARGS__) -#define _EXPAND_ARG4(prefix,type, ...) prefix _4, _EXPAND_ARG3(prefix,##__VA_ARGS__) -#define _EXPAND_ARG5(prefix,type, ...) prefix _5, _EXPAND_ARG4(prefix,##__VA_ARGS__) -#define _EXPAND_ARG6(prefix,type, ...) prefix _6, _EXPAND_ARG5(prefix,##__VA_ARGS__) -#define _EXPAND_ARG7(prefix,type, ...) prefix _7, _EXPAND_ARG6(prefix,##__VA_ARGS__) -#define _EXPAND_ARG8(prefix,type, ...) prefix _8, _EXPAND_ARG7(prefix,##__VA_ARGS__) -#define _EXPAND_ARG9(prefix,type, ...) prefix _9, _EXPAND_ARG8(prefix,##__VA_ARGS__) -#define _EXPAND_ARG10(prefix,type, ...) prefix _10, _EXPAND_ARG9(prefix,##__VA_ARGS__) -#define _EXPAND_ARG11(prefix,type, ...) prefix _11, _EXPAND_ARG10(prefix,##__VA_ARGS__) -#define _EXPAND_ARG12(prefix,type, ...) prefix _12, _EXPAND_ARG11(prefix,##__VA_ARGS__) -#define _EXPAND_ARG13(prefix,type, ...) prefix _13, _EXPAND_ARG12(prefix,##__VA_ARGS__) -#define _EXPAND_ARG14(prefix,type, ...) prefix _14, _EXPAND_ARG13(prefix,##__VA_ARGS__) -#define _EXPAND_ARG15(prefix,type, ...) prefix _15, _EXPAND_ARG14(prefix,##__VA_ARGS__) -#define _EXPAND_ARG16(prefix,type, ...) prefix _16, _EXPAND_ARG15(prefix,##__VA_ARGS__) -#define _EXPAND_ARG17(prefix,type, ...) prefix _17, _EXPAND_ARG16(prefix,##__VA_ARGS__) -#define _EXPAND_ARG18(prefix,type, ...) prefix _18, _EXPAND_ARG17(prefix,##__VA_ARGS__) -#define _EXPAND_ARG19(prefix,type, ...) prefix _19, _EXPAND_ARG18(prefix,##__VA_ARGS__) -#define _EXPAND_ARG20(prefix,type, ...) prefix _20, _EXPAND_ARG19(prefix,##__VA_ARGS__) -#define _EXPAND_ARG21(prefix,type, ...) prefix _21, _EXPAND_ARG20(prefix,##__VA_ARGS__) -#define _EXPAND_ARG22(prefix,type, ...) prefix _22, _EXPAND_ARG21(prefix,##__VA_ARGS__) -#define _EXPAND_ARG23(prefix,type, ...) prefix _23, _EXPAND_ARG22(prefix,##__VA_ARGS__) -#define _EXPAND_ARG24(prefix,type, ...) prefix _24, _EXPAND_ARG23(prefix,##__VA_ARGS__) -#define _EXPAND_ARG25(prefix,type, ...) prefix _25, _EXPAND_ARG24(prefix,##__VA_ARGS__) +#define _EXPAND_ARG(prefix, ...) \ + _EXPAND_ARG_N(__VA_ARGS__, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, \ + 1, 0) \ + (prefix, ##__VA_ARGS__) +#define _EXPAND_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, \ + _22, _23, _24, _25, n, ...) \ + _EXPAND_ARG##n +#define _EXPAND_ARG1(prefix, type, ...) prefix _1 +#define _EXPAND_ARG2(prefix, type, ...) prefix _2, _EXPAND_ARG1(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG3(prefix, type, ...) prefix _3, _EXPAND_ARG2(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG4(prefix, type, ...) prefix _4, _EXPAND_ARG3(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG5(prefix, type, ...) prefix _5, _EXPAND_ARG4(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG6(prefix, type, ...) prefix _6, _EXPAND_ARG5(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG7(prefix, type, ...) prefix _7, _EXPAND_ARG6(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG8(prefix, type, ...) prefix _8, _EXPAND_ARG7(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG9(prefix, type, ...) prefix _9, _EXPAND_ARG8(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG10(prefix, type, ...) prefix _10, _EXPAND_ARG9(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG11(prefix, type, ...) prefix _11, _EXPAND_ARG10(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG12(prefix, type, ...) prefix _12, _EXPAND_ARG11(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG13(prefix, type, ...) prefix _13, _EXPAND_ARG12(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG14(prefix, type, ...) prefix _14, _EXPAND_ARG13(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG15(prefix, type, ...) prefix _15, _EXPAND_ARG14(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG16(prefix, type, ...) prefix _16, _EXPAND_ARG15(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG17(prefix, type, ...) prefix _17, _EXPAND_ARG16(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG18(prefix, type, ...) prefix _18, _EXPAND_ARG17(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG19(prefix, type, ...) prefix _19, _EXPAND_ARG18(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG20(prefix, type, ...) prefix _20, _EXPAND_ARG19(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG21(prefix, type, ...) prefix _21, _EXPAND_ARG20(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG22(prefix, type, ...) prefix _22, _EXPAND_ARG21(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG23(prefix, type, ...) prefix _23, _EXPAND_ARG22(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG24(prefix, type, ...) prefix _24, _EXPAND_ARG23(prefix, ##__VA_ARGS__) +#define _EXPAND_ARG25(prefix, type, ...) prefix _25, _EXPAND_ARG24(prefix, ##__VA_ARGS__) /// expand variadic args as a numbered initializer list. e.g. _EXPAND_INIT(X, Y) -> X_(_2), Y_(_1) -#define _EXPAND_INIT(...) _EXPAND_INIT_N(__VA_ARGS__,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)(__VA_ARGS__) -#define _EXPAND_INIT_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, n, ...) _EXPAND_INIT ## n +#define _EXPAND_INIT(...) \ + _EXPAND_INIT_N(__VA_ARGS__, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, \ + 2, 1, 0) \ + (__VA_ARGS__) +#define _EXPAND_INIT_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, \ + _22, _23, _24, _25, n, ...) \ + _EXPAND_INIT##n #define _EXPAND_INIT1(type, ...) type##_(_1) #define _EXPAND_INIT2(type, ...) type##_(_2), _EXPAND_INIT1(__VA_ARGS__) #define _EXPAND_INIT3(type, ...) type##_(_3), _EXPAND_INIT2(__VA_ARGS__) @@ -146,108 +185,133 @@ namespace sampsharp #define _EXPAND_INIT24(type, ...) type##_(_24), _EXPAND_INIT23(__VA_ARGS__) #define _EXPAND_INIT25(type, ...) type##_(_25), _EXPAND_INIT24(__VA_ARGS__) -#define __PROXY_IMPL(type_subject, type_return, method, proxy_name, ...) \ - extern "C" SDK_EXPORT type_return __CDECL \ - proxy_name(type_subject * subject __VA_OPT__(, _EXPAND_PARAM(,,##__VA_ARGS__))) \ - { \ - if (!subject) { return ::sampsharp::proxy_default(#proxy_name); } \ - return subject -> method ( \ - __VA_OPT__(_EXPAND_ARG(,##__VA_ARGS__)) \ - ); \ +#define __PROXY_IMPL(type_subject, type_return, method, proxy_name, ...) \ + extern "C" SDK_EXPORT type_return __CDECL proxy_name( \ + type_subject* subject __VA_OPT__(, _EXPAND_PARAM(, , ##__VA_ARGS__))) \ + { \ + if (!subject) \ + { \ + return ::sampsharp::proxy_default(#proxy_name); \ + } \ + return subject->method(__VA_OPT__(_EXPAND_ARG(, ##__VA_ARGS__))); \ } -#define __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, proxy_name, ...) \ - extern "C" SDK_EXPORT void __CDECL \ - proxy_name(type_subject * subject __VA_OPT__(, _EXPAND_PARAM(,,__VA_ARGS__)), type_return * result) \ - { \ - if (!subject) { if (result) { *result = type_return{}; } return; } \ - *result = subject -> method ( \ - __VA_OPT__(_EXPAND_ARG(,##__VA_ARGS__)) \ - ); \ +#define __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, proxy_name, ...) \ + extern "C" SDK_EXPORT void __CDECL proxy_name(type_subject* subject __VA_OPT__(, _EXPAND_PARAM(, , __VA_ARGS__)), \ + type_return* result) \ + { \ + if (!subject) \ + { \ + if (result) \ + { \ + *result = type_return{}; \ + } \ + return; \ + } \ + *result = subject->method(__VA_OPT__(_EXPAND_ARG(, ##__VA_ARGS__))); \ } // // macros for definition of exported proxy functions // - -#define __PROXY_CAST_NAMED(type_from, type_from_name, type_to, type_to_name) \ - extern "C" SDK_EXPORT type_to * __CDECL \ - cast_##type_from_name##_to_##type_to_name(type_from * from) \ - { \ - return static_cast(from); \ +#define __PROXY_CAST_NAMED(type_from, type_from_name, type_to, type_to_name) \ + extern "C" SDK_EXPORT type_to* __CDECL cast_##type_from_name##_to_##type_to_name(type_from* from) \ + { \ + return static_cast(from); \ } -/// proxy function for casting from one type to another and vice versa e.g. PROXY_CAST_NAMED(IFoo, foo, IBar, bar) -> IBar * cast_foo_to_bar(IFoo * from) { return static_cast(from); } -#define PROXY_CAST_NAMED(type_from, type_from_name, type_to, type_to_name) \ - __PROXY_CAST_NAMED(type_from, type_from_name, type_to, type_to_name); \ +/// proxy function for casting from one type to another and vice versa e.g. PROXY_CAST_NAMED(IFoo, foo, IBar, bar) -> +/// IBar * cast_foo_to_bar(IFoo * from) { return static_cast(from); } +#define PROXY_CAST_NAMED(type_from, type_from_name, type_to, type_to_name) \ + __PROXY_CAST_NAMED(type_from, type_from_name, type_to, type_to_name); \ __PROXY_CAST_NAMED(type_to, type_to_name, type_from, type_from_name) -/// proxy function for casting from one type to another e.g. PROXY_CAST(IFoo, IBar) -> IBar * cast_IFoo_to_IBar(IFoo * from) { return static_cast(from); } +/// proxy function for casting from one type to another e.g. PROXY_CAST(IFoo, IBar) -> IBar * cast_IFoo_to_IBar(IFoo * +/// from) { return static_cast(from); } #define PROXY_CAST(type_from, type_to) PROXY_CAST_NAMED(type_from, type_from, type_to, type_to) - + /// proxy function macro. e.g. PROXY(subj, int, foo, bool) -> int subj_foo(subj * x, bool _1) { return x->foo(_1); } -#define PROXY(type_subject, type_return, method, ...) __PROXY_IMPL(type_subject, type_return, method, type_subject##_##method, __VA_ARGS__) +#define PROXY(type_subject, type_return, method, ...) \ + __PROXY_IMPL(type_subject, type_return, method, type_subject##_##method, __VA_ARGS__) -/// proxy function macro. e.g. PROXY_RESULT_PTR(subj, int, foo, bool) -> void subj_foo(subj * x, bool _1, int * result) { *result = x->foo(_1); } -#define PROXY_PTR(type_subject, type_return, method, ...) __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, type_subject##_##method, __VA_ARGS__) +/// proxy function macro. e.g. PROXY_RESULT_PTR(subj, int, foo, bool) -> void subj_foo(subj * x, bool _1, int * result) +/// { *result = x->foo(_1); } +#define PROXY_PTR(type_subject, type_return, method, ...) \ + __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, type_subject##_##method, __VA_ARGS__) -/// proxy function macro for an overload. output is similar to PROXY macro, except the function name is post-fixed by overload argument -#define PROXY_OVERLOAD(type_subject, type_return, method, overload, ...) __PROXY_IMPL(type_subject, type_return, method, type_subject##_##method##overload, __VA_ARGS__) +/// proxy function macro for an overload. output is similar to PROXY macro, except the function name is post-fixed by +/// overload argument +#define PROXY_OVERLOAD(type_subject, type_return, method, overload, ...) \ + __PROXY_IMPL(type_subject, type_return, method, type_subject##_##method##overload, __VA_ARGS__) -/// proxy function macro for an overload. output is similar to PROXY_PTR macro, except the function name is post-fixed by overload argument -#define PROXY_OVERLOAD_PTR(type_subject, type_return, method, overload, ...) __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, type_subject##_##method##overload, __VA_ARGS__) +/// proxy function macro for an overload. output is similar to PROXY_PTR macro, except the function name is post-fixed +/// by overload argument +#define PROXY_OVERLOAD_PTR(type_subject, type_return, method, overload, ...) \ + __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, type_subject##_##method##overload, __VA_ARGS__) /// proxy function macro. e.g. PROXY(subj, int, foo, bool) -> int subj_foo(subj * x, bool _1) { return x->foo(_1); } -#define PROXY_NAMED(type_subject, name_subject, type_return, method, ...) __PROXY_IMPL(type_subject, type_return, method, name_subject##_##method, __VA_ARGS__) +#define PROXY_NAMED(type_subject, name_subject, type_return, method, ...) \ + __PROXY_IMPL(type_subject, type_return, method, name_subject##_##method, __VA_ARGS__) -/// proxy function macro. e.g. PROXY_RESULT_PTR(subj, int, foo, bool) -> void subj_foo(subj * x, bool _1, int * result) { *result = x->foo(_1); } -#define PROXY_NAMED_PTR(type_subject, name_subject, type_return, method, ...) __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, name_subject##_##method, __VA_ARGS__) +/// proxy function macro. e.g. PROXY_RESULT_PTR(subj, int, foo, bool) -> void subj_foo(subj * x, bool _1, int * result) +/// { *result = x->foo(_1); } +#define PROXY_NAMED_PTR(type_subject, name_subject, type_return, method, ...) \ + __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, name_subject##_##method, __VA_ARGS__) -/// proxy function macro for an overload. output is similar to PROXY macro, except the function name is post-fixed by overload argument -#define PROXY_NAMED_OVERLOAD(type_subject, name_subject, type_return, method, overload, ...) __PROXY_IMPL(type_subject, type_return, method, name_subject##_##method##overload, __VA_ARGS__) +/// proxy function macro for an overload. output is similar to PROXY macro, except the function name is post-fixed by +/// overload argument +#define PROXY_NAMED_OVERLOAD(type_subject, name_subject, type_return, method, overload, ...) \ + __PROXY_IMPL(type_subject, type_return, method, name_subject##_##method##overload, __VA_ARGS__) -/// proxy function macro for an overload. output is similar to PROXY_PTR macro, except the function name is post-fixed by overload argument -#define PROXY_NAMED_OVERLOAD_PTR(type_subject, name_subject, type_return, method, overload, ...) __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, name_subject##_##method##overload, __VA_ARGS__) +/// proxy function macro for an overload. output is similar to PROXY_PTR macro, except the function name is post-fixed +/// by overload argument +#define PROXY_NAMED_OVERLOAD_PTR(type_subject, name_subject, type_return, method, overload, ...) \ + __PROXY_IMPL_RESULT_PTR(type_subject, type_return, method, name_subject##_##method##overload, __VA_ARGS__) /// proxy for event dispatcher functions and function to get the event dispatcher -#define PROXY_EVENT_DISPATCHER(type_subject, type_handler, method) \ +#define PROXY_EVENT_DISPATCHER(type_subject, type_handler, method) \ PROXY(type_subject, IEventDispatcher&, method); /// proxy for event dispatcher functions and function to get the event dispatcher wit specific handler name -#define PROXY_EVENT_DISPATCHER_NAMED(type_subject, handler_type, handler_name, method) \ +#define PROXY_EVENT_DISPATCHER_NAMED(type_subject, handler_type, handler_name, method) \ PROXY(type_subject, IEventDispatcher&, method); /// proxy for event dispatcher functions and function to get the event dispatcher -#define PROXY_INDEXED_EVENT_DISPATCHER(type_subject, type_handler, method) \ +#define PROXY_INDEXED_EVENT_DISPATCHER(type_subject, type_handler, method) \ PROXY(type_subject, IIndexedEventDispatcher&, method); -/// start of event handler proxy class -#define PROXY_EVENT_HANDLER_BEGIN(handler_type) \ - class handler_type##Impl final : handler_type { +/// start of event handler proxy class +#define PROXY_EVENT_HANDLER_BEGIN(handler_type) \ + class handler_type##Impl final : handler_type \ + { /// end of event handler proxy class + functions for creating/destroying proxy -#define PROXY_EVENT_HANDLER_END(handler_type, ...) \ - public: \ - handler_type##Impl(_EXPAND_ARG(void**, __VA_ARGS__)) : \ - _EXPAND_INIT(__VA_ARGS__) { } \ - }; \ - extern "C" SDK_EXPORT handler_type##Impl* __CDECL handler_type##Impl_create(_EXPAND_ARG(void**, __VA_ARGS__)) \ - { \ - return new handler_type##Impl(_EXPAND_ARG(,##__VA_ARGS__)); \ - } \ - extern "C" SDK_EXPORT void __CDECL handler_type##Impl_delete(handler_type##Impl* handler) \ - { \ - delete handler; \ +#define PROXY_EVENT_HANDLER_END(handler_type, ...) \ +public: \ + handler_type##Impl(_EXPAND_ARG(void**, __VA_ARGS__)) : \ + _EXPAND_INIT(__VA_ARGS__) \ + { \ + } \ + } \ + ; \ + extern "C" SDK_EXPORT handler_type##Impl* __CDECL handler_type##Impl_create(_EXPAND_ARG(void**, __VA_ARGS__)) \ + { \ + return new handler_type##Impl(_EXPAND_ARG(, ##__VA_ARGS__)); \ + } \ + extern "C" SDK_EXPORT void __CDECL handler_type##Impl_delete(handler_type##Impl* handler) \ + { \ + delete handler; \ } /// event handler function in event handler proxy class -#define PROXY_EVENT_HANDLER_EVENT(type_return, name, ...) \ - private: \ - typedef type_return(API_CALLTYPE * name##_fn)(_EXPAND_PARAM(, , __VA_ARGS__)); \ - void** name##_ = nullptr; \ - public: \ - type_return name(_EXPAND_PARAM(, , __VA_ARGS__)) override \ - { \ - return ((name##_fn)name##_)(_EXPAND_ARG(,##__VA_ARGS__)); \ +#define PROXY_EVENT_HANDLER_EVENT(type_return, name, ...) \ +private: \ + typedef type_return(API_CALLTYPE* name##_fn)(_EXPAND_PARAM(, , __VA_ARGS__)); \ + void** name##_ = nullptr; \ + \ +public: \ + type_return name(_EXPAND_PARAM(, , __VA_ARGS__)) override \ + { \ + return ((name##_fn)name##_)(_EXPAND_ARG(, ##__VA_ARGS__)); \ } diff --git a/src/sampsharp-component/sampsharp-component.cpp b/src/sampsharp-component/sampsharp-component.cpp index 93917c69..396086bf 100644 --- a/src/sampsharp-component/sampsharp-component.cpp +++ b/src/sampsharp-component/sampsharp-component.cpp @@ -8,12 +8,12 @@ #define CFG_ENTRY_POINT_METHOD "sampsharp.entry_point_method" #define CFG_DISABLE_CRASH_HANDLER "sampsharp.disable_crash_handler" -static void __CDECL __setOnCleanup(void **cb) +static void __CDECL __setOnCleanup(void** cb) { SampSharpComponent::getInstance()->setOnCleanup((on_cleanup_fn)cb); } -static void __CDECL __setOnFreeComponent(void **cb) +static void __CDECL __setOnFreeComponent(void** cb) { SampSharpComponent::getInstance()->setOnFreeComponent((on_free_component_fn)cb); } @@ -25,7 +25,7 @@ StringView SampSharpComponent::componentName() const SemanticVersion SampSharpComponent::componentVersion() const { - return { VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD }; + return {VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD}; } void SampSharpComponent::onLoad(ICore* c) @@ -33,25 +33,28 @@ void SampSharpComponent::onLoad(ICore* c) core_ = c; bool disableCrashHandler = *c->getConfig().getBool(CFG_DISABLE_CRASH_HANDLER); - if(!disableCrashHandler) { + if (!disableCrashHandler) + { sampsharp::crash::install(c); } } void SampSharpComponent::provideConfiguration(ILogger& logger, IEarlyConfig& config, const bool defaults) { - #define initConfigString(key, value) \ - if(defaults || config.getType(key) == ConfigOptionType_None) { \ - config.setString(key, value); \ - } - +#define initConfigString(key, value) \ + if (defaults || config.getType(key) == ConfigOptionType_None) \ + { \ + config.setString(key, value); \ + } + initConfigString(CFG_DIRECTORY, "gamemode"); initConfigString(CFG_ASSEMBLY, "GameMode"); initConfigString(CFG_ENTRY_POINT_TYPE, "SampSharp.Entrypoint"); initConfigString(CFG_ENTRY_POINT_METHOD, "Initialize"); - if(defaults || config.getType(CFG_DISABLE_CRASH_HANDLER) == ConfigOptionType_None) { - config.setBool(CFG_DISABLE_CRASH_HANDLER, false); + if (defaults || config.getType(CFG_DISABLE_CRASH_HANDLER) == ConfigOptionType_None) + { + config.setBool(CFG_DISABLE_CRASH_HANDLER, false); } } @@ -67,33 +70,38 @@ void SampSharpComponent::onInit(IComponentList* components) std::string entry_point = entry_point_type.to_string() + ", " + assembly.to_string(); const auto full_entry_point = StringView(entry_point); - const char * error = nullptr; - - if(!managed_host_.initialize(&error)) + const char* error = nullptr; + + if (!managed_host_.initialize(&error)) { - core_->logLn(Error, "Failed to initialize the .NET host framework resolver. Has the .NET runtime been installed?"); + core_->logLn(Error, + "Failed to initialize the .NET host framework resolver. Has the .NET runtime been installed?"); core_->logLn(Error, "Error message: %s", error); return; } - if(!managed_host_.loadFor(directory, assembly, &error)) + if (!managed_host_.loadFor(directory, assembly, &error)) { - core_->logLn(Error, "Failed to initialize the .NET runtime for '%s/%s'. Is the '*.runtimeconfig.json' file available? Is the .NET runtime available?", directory.to_string().c_str(), assembly.to_string().c_str()); + core_->logLn(Error, + "Failed to initialize the .NET runtime for '%s/%s'. Is the '*.runtimeconfig.json' file available? " + "Is the .NET runtime available?", + directory.to_string().c_str(), assembly.to_string().c_str()); core_->logLn(Error, "Error message: %s", error); return; } on_init_fn on_init; - if(!managed_host_.getEntryPoint(full_entry_point, entry_point_method, reinterpret_cast(&on_init), &error)) + if (!managed_host_.getEntryPoint(full_entry_point, entry_point_method, reinterpret_cast(&on_init), &error)) { - core_->logLn(Error, "The entrypoint '%s.%s, %s' could not be found.", entry_point_type.to_string().c_str(), entry_point_method.to_string().c_str(), assembly.to_string().c_str()); + core_->logLn(Error, "The entrypoint '%s.%s, %s' could not be found.", entry_point_type.to_string().c_str(), + entry_point_method.to_string().c_str(), assembly.to_string().c_str()); core_->logLn(Error, "Error message: %s", error); return; } - SampSharpInfo info { VERSION_API, componentVersion() }; - SampSharpInitParams init { core_, components, &info, __setOnCleanup, __setOnFreeComponent }; - + SampSharpInfo info{VERSION_API, componentVersion()}; + SampSharpInitParams init{core_, components, &info, __setOnCleanup, __setOnFreeComponent}; + on_init(init); } @@ -107,11 +115,11 @@ void SampSharpComponent::free() { on_cleanup_(); } - + delete this; } -void SampSharpComponent::onFree(IComponent *component) +void SampSharpComponent::onFree(IComponent* component) { if (on_free_component_) { diff --git a/src/sampsharp-component/sampsharp-component.hpp b/src/sampsharp-component/sampsharp-component.hpp index 40095753..7b9f681f 100644 --- a/src/sampsharp-component/sampsharp-component.hpp +++ b/src/sampsharp-component/sampsharp-component.hpp @@ -7,58 +7,61 @@ struct SampSharpInfo { - SampSharpInfo(int api_version, SemanticVersion version) : - size(sizeof(SampSharpInfo)), + SampSharpInfo(int api_version, SemanticVersion version) : + size(sizeof(SampSharpInfo)), api_version(api_version), - version(version) { } + version(version) + { + } // sizeof(SampSharpInfo) for backwards compatibility - size_t size; + size_t size; // version of SampSharp component <> hosted API. Version mismatch will cause launch failure. - int api_version; + int api_version; // version of the SampSharp component - SemanticVersion version; + SemanticVersion version; }; -typedef void(API_CALLTYPE *on_cleanup_fn)(); -typedef void(API_CALLTYPE *on_free_component_fn)(IComponent *component); - -typedef void(API_CALLTYPE *configure_callback_fn)(void **cb); +typedef void(API_CALLTYPE* on_cleanup_fn)(); +typedef void(API_CALLTYPE* on_free_component_fn)(IComponent* component); +typedef void(API_CALLTYPE* configure_callback_fn)(void** cb); struct SampSharpInitParams { - SampSharpInitParams(ICore * core, IComponentList * componentList, SampSharpInfo * info, configure_callback_fn setOnCleanup, configure_callback_fn setOnFreeComponent) : + SampSharpInitParams(ICore* core, IComponentList* componentList, SampSharpInfo* info, + configure_callback_fn setOnCleanup, configure_callback_fn setOnFreeComponent) : size(sizeof(SampSharpInitParams)), info(info), core(core), componentList(componentList), setOnCleanup(setOnCleanup), - setOnFreeComponent(setOnFreeComponent) { } + setOnFreeComponent(setOnFreeComponent) + { + } // sizeof(SampSharpInitParams) for backwards compatibility - size_t size; - SampSharpInfo * info; - ICore * core; - IComponentList * componentList; + size_t size; + SampSharpInfo* info; + ICore* core; + IComponentList* componentList; configure_callback_fn setOnCleanup; configure_callback_fn setOnFreeComponent; }; -typedef void (CORECLR_DELEGATE_CALLTYPE *on_init_fn)(SampSharpInitParams); +typedef void(CORECLR_DELEGATE_CALLTYPE* on_init_fn)(SampSharpInitParams); struct ISampSharpComponent : IComponent { PROVIDE_UID(0x0B61929D1E94A319); }; -class SampSharpComponent final - : public ISampSharpComponent +class SampSharpComponent final : public ISampSharpComponent { private: - ICore * core_ = nullptr; - ManagedHost managed_host_ {}; - inline static SampSharpComponent * instance_ = nullptr; + ICore* core_ = nullptr; + ManagedHost managed_host_{}; + inline static SampSharpComponent* instance_ = nullptr; on_cleanup_fn on_cleanup_ = nullptr; on_free_component_fn on_free_component_ = nullptr; @@ -67,23 +70,23 @@ class SampSharpComponent final SemanticVersion componentVersion() const override; - void onLoad(ICore * c) override; + void onLoad(ICore* c) override; + + void provideConfiguration(ILogger& logger, IEarlyConfig& config, bool defaults) override; - void provideConfiguration(ILogger & logger, IEarlyConfig & config, bool defaults) override; - - void onInit(IComponentList * components) override; + void onInit(IComponentList* components) override; void onReady() override; void free() override; - void onFree(IComponent *component) override; + void onFree(IComponent* component) override; void reset() override; void setOnCleanup(on_cleanup_fn cb) { on_cleanup_ = cb; } void setOnFreeComponent(on_free_component_fn cb) { on_free_component_ = cb; } - - static SampSharpComponent * getInstance(); + + static SampSharpComponent* getInstance(); }; From 90fb1332b537cdf7800feb5ce2ddd66d80843dc4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 May 2026 22:06:03 +0000 Subject: [PATCH 3/4] Revert clang-format changes to legacy code; add DisableFormat override for legacy tree Agent-Logs-Url: https://github.com/ikkentim/SampSharp/sessions/5a2292e5-020c-4592-9ef6-c99d3d622f63 Co-authored-by: ikkentim <2820647+ikkentim@users.noreply.github.com> --- src/legacy/.clang-format | 3 + src/legacy/SampSharp/config.cpp | 12 +- src/legacy/SampSharp/config.h | 7 +- src/legacy/SampSharp/config_cfg.cpp | 30 +-- src/legacy/SampSharp/config_cfg.h | 8 +- src/legacy/SampSharp/config_composite.cpp | 21 +- src/legacy/SampSharp/config_composite.h | 10 +- src/legacy/SampSharp/config_omp.cpp | 32 +-- src/legacy/SampSharp/config_omp.h | 8 +- src/legacy/SampSharp/config_win.cpp | 27 +- src/legacy/SampSharp/config_win.h | 8 +- src/legacy/SampSharp/coreclr_app.cpp | 315 +++++++++++----------- src/legacy/SampSharp/coreclr_app.h | 37 +-- src/legacy/SampSharp/interop.cpp | 40 ++- src/legacy/SampSharp/interop.h | 4 +- src/legacy/SampSharp/locator.cpp | 116 ++++---- src/legacy/SampSharp/locator.h | 13 +- src/legacy/SampSharp/logging.cpp | 22 +- src/legacy/SampSharp/logging.h | 12 +- src/legacy/SampSharp/main.cpp | 101 +++---- src/legacy/SampSharp/nethost.h | 5 +- src/legacy/SampSharp/nethost_coreclr.cpp | 42 ++- src/legacy/SampSharp/nethost_coreclr.h | 6 +- src/legacy/SampSharp/platforms.h | 32 +-- src/legacy/SampSharp/strutil.cpp | 9 +- src/legacy/SampSharp/testing.cpp | 56 ++-- src/legacy/SampSharp/version.h | 31 ++- 27 files changed, 460 insertions(+), 547 deletions(-) create mode 100644 src/legacy/.clang-format diff --git a/src/legacy/.clang-format b/src/legacy/.clang-format new file mode 100644 index 00000000..57fe428d --- /dev/null +++ b/src/legacy/.clang-format @@ -0,0 +1,3 @@ +--- +DisableFormat: true +... diff --git a/src/legacy/SampSharp/config.cpp b/src/legacy/SampSharp/config.cpp index 71118e20..5cebe2fd 100644 --- a/src/legacy/SampSharp/config.cpp +++ b/src/legacy/SampSharp/config.cpp @@ -16,21 +16,17 @@ #include "config.h" #include "strutil.h" -bool config::get_config_bool(std::string name, bool& result) -{ +bool config::get_config_bool(std::string name, bool& result) { std::string value; - if (!get_config_string(name, value)) - { + if (!get_config_string(name, value)) { return false; } - if (iequals(value, "on") || iequals(value, "yes") || iequals(value, "true")) - { + if (iequals(value, "on") || iequals(value, "yes") || iequals(value, "true")) { result = true; return true; } - if (iequals(value, "off") || iequals(value, "no") || iequals(value, "false")) - { + if (iequals(value, "off") || iequals(value, "no") || iequals(value, "false")) { result = false; return true; } diff --git a/src/legacy/SampSharp/config.h b/src/legacy/SampSharp/config.h index c960e8ff..ab590e24 100644 --- a/src/legacy/SampSharp/config.h +++ b/src/legacy/SampSharp/config.h @@ -16,9 +16,8 @@ #pragma once #include -class config -{ +class config { public: - virtual bool get_config_string(std::string name, std::string& result) = 0; - virtual bool get_config_bool(std::string name, bool& result); + virtual bool get_config_string(std::string name, std::string &result) = 0; + virtual bool get_config_bool(std::string name, bool &result); }; diff --git a/src/legacy/SampSharp/config_cfg.cpp b/src/legacy/SampSharp/config_cfg.cpp index bc75085e..5a6f2651 100644 --- a/src/legacy/SampSharp/config_cfg.cpp +++ b/src/legacy/SampSharp/config_cfg.cpp @@ -20,23 +20,23 @@ #include #include -static void trim(std::string& s) -{ - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); - - s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); +static void trim(std::string& s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); + + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { + return !std::isspace(ch); + }).base(), s.end()); } -config_cfg::config_cfg() -{ +config_cfg::config_cfg() { std::ifstream file("server.cfg"); - - if (file.is_open()) - { + + if (file.is_open()) { std::string line, name, value; - while (std::getline(file, line, '\n')) - { + while (std::getline(file, line, '\n')) { std::stringstream stream(line); std::getline(stream, name, ' '); @@ -50,12 +50,10 @@ config_cfg::config_cfg() } } -bool config_cfg::get_config_string(std::string name, std::string& result) -{ +bool config_cfg::get_config_string(std::string name, std::string& result) { const auto iterator = values_.find(name); - if (iterator == values_.end()) - { + if (iterator == values_.end()) { return false; } diff --git a/src/legacy/SampSharp/config_cfg.h b/src/legacy/SampSharp/config_cfg.h index 19c5bca9..a79fbea7 100644 --- a/src/legacy/SampSharp/config_cfg.h +++ b/src/legacy/SampSharp/config_cfg.h @@ -17,12 +17,10 @@ #include "config.h" #include -class config_cfg final : public config -{ -public: +class config_cfg final : public config { + public: config_cfg(); - bool get_config_string(std::string name, std::string& result) override; - + bool get_config_string(std::string name, std::string &result) override; private: std::map values_; }; diff --git a/src/legacy/SampSharp/config_composite.cpp b/src/legacy/SampSharp/config_composite.cpp index ffef4a8f..fefcd193 100644 --- a/src/legacy/SampSharp/config_composite.cpp +++ b/src/legacy/SampSharp/config_composite.cpp @@ -16,17 +16,13 @@ #include "config_composite.h" #include -void config_composite::add_config(config* config) -{ +void config_composite::add_config(config* config) { configs_.push_back(config); } -bool config_composite::get_config_string(std::string name, std::string& result) -{ - for (auto&& config : configs_) - { - if (config->get_config_string(name, result)) - { +bool config_composite::get_config_string(std::string name, std::string& result) { + for (auto && config : configs_) { + if(config->get_config_string(name, result)) { return true; } } @@ -34,12 +30,9 @@ bool config_composite::get_config_string(std::string name, std::string& result) return false; } -bool config_composite::get_config_bool(std::string name, bool& result) -{ - for (auto&& config : configs_) - { - if (config->get_config_bool(name, result)) - { +bool config_composite::get_config_bool(std::string name, bool& result) { + for (auto && config : configs_) { + if(config->get_config_bool(name, result)) { return true; } } diff --git a/src/legacy/SampSharp/config_composite.h b/src/legacy/SampSharp/config_composite.h index 80f66083..2993065f 100644 --- a/src/legacy/SampSharp/config_composite.h +++ b/src/legacy/SampSharp/config_composite.h @@ -17,13 +17,11 @@ #include "config.h" #include -class config_composite final : public config -{ -public: +class config_composite final : public config { + public: void add_config(config* config); - bool get_config_string(std::string name, std::string& result) override; + bool get_config_string(std::string name, std::string &result) override; bool get_config_bool(std::string name, bool& result) override; - private: - std::vector configs_; + std::vector configs_; }; diff --git a/src/legacy/SampSharp/config_omp.cpp b/src/legacy/SampSharp/config_omp.cpp index 81c9ccbc..572d7b22 100644 --- a/src/legacy/SampSharp/config_omp.cpp +++ b/src/legacy/SampSharp/config_omp.cpp @@ -18,31 +18,26 @@ #include #include -config_omp::config_omp() -{ +config_omp::config_omp() { // read config file as json std::ifstream input_file("config.json"); - if (!input_file.is_open()) - { + if (!input_file.is_open()) { return; } const auto str = std::string((std::istreambuf_iterator(input_file)), std::istreambuf_iterator()); nlohmann::json json = nlohmann::json::parse(str); - if (!json.is_object()) - { + if(!json.is_object()) { return; } // map the json to a simple flat structure like regular SA-MP config file. We'll only be using a few // keys in SampSharp. If open.mp will provide a different config API in their SDK we'll use that // instead of the json file, once the SDK is released. - for (auto it = json.begin(); it != json.end(); ++it) - { - switch (it.value().type()) - { - + for (auto it = json.begin(); it != json.end(); ++it) { + switch (it.value().type()) { + case nlohmann::detail::value_t::string: values_[it.key()] = it.value().get(); break; @@ -58,29 +53,26 @@ config_omp::config_omp() case nlohmann::detail::value_t::number_float: values_[it.key()] = std::to_string(it.value().get()); break; - default:; + default: ; } } + // Map the main_scripts (pawn game modes) into gamemodeN keys. auto main_scripts = json["pawn"]["main_scripts"]; int index = 0; - for (auto it = main_scripts.begin(); it != main_scripts.end(); ++it) - { - if (it.value().is_string()) - { + for (auto it = main_scripts.begin(); it != main_scripts.end(); ++it) { + if(it.value().is_string()) { std::string key = "gamemode" + std::to_string(index++); values_[key] = it.value().get(); } } } -bool config_omp::get_config_string(std::string name, std::string& result) -{ +bool config_omp::get_config_string(std::string name, std::string& result) { const auto iterator = values_.find(name); - if (iterator == values_.end()) - { + if (iterator == values_.end()) { return false; } diff --git a/src/legacy/SampSharp/config_omp.h b/src/legacy/SampSharp/config_omp.h index f8b538e0..cb604b6d 100644 --- a/src/legacy/SampSharp/config_omp.h +++ b/src/legacy/SampSharp/config_omp.h @@ -17,12 +17,10 @@ #include "config.h" #include -class config_omp final : public config -{ -public: +class config_omp final : public config { + public: config_omp(); - bool get_config_string(std::string name, std::string& result) override; - + bool get_config_string(std::string name, std::string &result) override; private: std::map values_; }; diff --git a/src/legacy/SampSharp/config_win.cpp b/src/legacy/SampSharp/config_win.cpp index 4cd8e04c..47f19d63 100644 --- a/src/legacy/SampSharp/config_win.cpp +++ b/src/legacy/SampSharp/config_win.cpp @@ -23,20 +23,20 @@ #if SAMPSHARP_WINDOWS #include -std::string wide_to_string(const wchar_t* wc) -{ +std::string wide_to_string(const wchar_t *wc) { std::wstring wide = wc; std::string str(wide.length(), 0); - std::transform(wide.begin(), wide.end(), str.begin(), [](wchar_t c) { return (char)c; }); + std::transform(wide.begin(), wide.end(), str.begin(), [] (wchar_t c) { + return (char)c; + }); return str; } #endif -config_win::config_win() -{ +config_win::config_win() { #if SAMPSHARP_WINDOWS int argc; wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); @@ -45,23 +45,20 @@ config_win::config_win() { auto key = wide_to_string(argv[i]); - if (key.find("--") != 0 || key.length() <= 2) - { + if(key.find("--") != 0 || key.length() <= 2) { continue; } key = key.substr(2); - + const size_t eq = key.find('='); - if (eq != std::string::npos) - { + if(eq != std::string::npos){ const auto value = key.substr(eq + 1); key = key.substr(0, eq); values_.insert(std::make_pair(key, value)); } - else if (argc > i + 1) - { + else if (argc > i + 1){ const auto value = wide_to_string(argv[++i]); values_.insert(std::make_pair(key, value)); } @@ -69,12 +66,10 @@ config_win::config_win() #endif } -bool config_win::get_config_string(std::string name, std::string& result) -{ +bool config_win::get_config_string(std::string name, std::string& result) { const auto iterator = values_.find(name); - if (iterator == values_.end()) - { + if (iterator == values_.end()) { return false; } diff --git a/src/legacy/SampSharp/config_win.h b/src/legacy/SampSharp/config_win.h index 6a02f156..48627eed 100644 --- a/src/legacy/SampSharp/config_win.h +++ b/src/legacy/SampSharp/config_win.h @@ -17,12 +17,10 @@ #include "config.h" #include -class config_win final : public config -{ -public: +class config_win final : public config { + public: config_win(); - bool get_config_string(std::string name, std::string& result) override; - + bool get_config_string(std::string name, std::string &result) override; private: std::map values_; }; diff --git a/src/legacy/SampSharp/coreclr_app.cpp b/src/legacy/SampSharp/coreclr_app.cpp index 761d39b7..6c1fda0e 100644 --- a/src/legacy/SampSharp/coreclr_app.cpp +++ b/src/legacy/SampSharp/coreclr_app.cpp @@ -30,41 +30,41 @@ #include #if SAMPSHARP_LINUX -#include -#include -#include -#include -#if defined(__FreeBSD__) -#include -#include -#endif -#if defined(HAVE_SYS_SYSCTL_H) || defined(__FreeBSD__) -#include -#endif +# include +# include +# include +# include +# if defined(__FreeBSD__) +# include +# include +# endif +# if defined(HAVE_SYS_SYSCTL_H) || defined(__FreeBSD__) +# include +# endif #endif #if SAMPSHARP_LINUX -#define __DIR_SEPARATOR_FORWARD +# define __DIR_SEPARATOR_FORWARD #endif #ifdef __DIR_SEPARATOR_FORWARD -#define DIR_SEPARATOR "/" +# define DIR_SEPARATOR "/" #else -#define DIR_SEPARATOR "\\" +# define DIR_SEPARATOR "\\" #endif + #if !defined(PATH_MAX) && defined(MAX_PATH) -#define PATH_MAX MAX_PATH +# define PATH_MAX MAX_PATH #endif #if SAMPSHARP_LINUX -bool coreclr_app::load_symbol(void* coreclr_lib, const char* symbol, void** ptr) -{ +bool coreclr_app::load_symbol(void *coreclr_lib, const char *symbol, + void **ptr) { *ptr = dlsym(coreclr_lib, symbol); - if (!*ptr) - { + if(!*ptr) { log_error("Function %s not found in the libcoreclr.so.", symbol); return false; } @@ -73,8 +73,8 @@ bool coreclr_app::load_symbol(void* coreclr_lib, const char* symbol, void** ptr) } #endif -int coreclr_app::initialize(const char* clr_dir_c, const char* exe_path, const char* app_domain_friendly_name) -{ +int coreclr_app::initialize(const char *clr_dir_c, const char* exe_path, + const char* app_domain_friendly_name) { std::filesystem::path exe_path_p = exe_path; std::filesystem::path clr_dir_p = clr_dir_c; @@ -116,39 +116,37 @@ int coreclr_app::initialize(const char* clr_dir_c, const char* exe_path, const c #if SAMPSHARP_LINUX module_ = dlopen(coreclr_dll.c_str(), RTLD_NOW | RTLD_LOCAL); - if (!module_) - { - const char* error = dlerror(); + if(!module_) { + const char *error = dlerror(); log_error("Failed to load CoreCLR library: %s.", error); return -1; } - if (!load_symbol(module_, "coreclr_initialize", (void**)&coreclr_initialize_)) - { + if(!load_symbol(module_, "coreclr_initialize", (void **)&coreclr_initialize_)) { return -1; } - if (!load_symbol(module_, "coreclr_shutdown", (void**)&coreclr_shutdown_)) - { + if(!load_symbol(module_, "coreclr_shutdown", (void **)&coreclr_shutdown_)) { return -1; } - if (!load_symbol(module_, "coreclr_shutdown_2", (void**)&coreclr_shutdown_2_)) - { + if(!load_symbol(module_, "coreclr_shutdown_2", (void **)&coreclr_shutdown_2_)) { return -1; } - if (!load_symbol(module_, "coreclr_create_delegate", (void**)&coreclr_create_delegate_)) - { + if(!load_symbol(module_, "coreclr_create_delegate", (void **)&coreclr_create_delegate_)) { return -1; } - if (!load_symbol(module_, "coreclr_execute_assembly", (void**)&coreclr_execute_assembly_)) - { + if(!load_symbol(module_, "coreclr_execute_assembly", (void **)&coreclr_execute_assembly_)) { return -1; } - const char* property_keys[] = { - "TRUSTED_PLATFORM_ASSEMBLIES", "APP_PATHS", "APP_NI_PATHS", - "NATIVE_DLL_SEARCH_DIRECTORIES", "System.GC.Server", "System.Globalization.Invariant", + const char *property_keys[] = { + "TRUSTED_PLATFORM_ASSEMBLIES", + "APP_PATHS", + "APP_NI_PATHS", + "NATIVE_DLL_SEARCH_DIRECTORIES", + "System.GC.Server", + "System.Globalization.Invariant", }; - const char* property_values[] = { + const char *property_values[] = { // TRUSTED_PLATFORM_ASSEMBLIES tpa_list.c_str(), // APP_PATHS @@ -163,9 +161,15 @@ int coreclr_app::initialize(const char* clr_dir_c, const char* exe_path, const c "false", }; - return coreclr_initialize_(abs_exe_path_.c_str(), app_domain_friendly_name, - sizeof(property_keys) / sizeof(property_keys[0]), property_keys, property_values, &host_, - &domain_id_); + return coreclr_initialize_( + abs_exe_path_.c_str(), + app_domain_friendly_name, + sizeof(property_keys) / sizeof(property_keys[0]), + property_keys, + property_values, + &host_, + &domain_id_ + ); #elif SAMPSHARP_WINDOWS std::wstring wapp_dir = std::wstring(app_dir.begin(), app_dir.end()); std::wstring wclr_dir = std::wstring(clr_dir.begin(), clr_dir.end()); @@ -181,8 +185,9 @@ int coreclr_app::initialize(const char* clr_dir_c, const char* exe_path, const c return -1; } - const FnGetCLRRuntimeHost get_clr_runtime_host = - FnGetCLRRuntimeHost(::GetProcAddress(module_, "GetCLRRuntimeHost")); + + const FnGetCLRRuntimeHost get_clr_runtime_host = FnGetCLRRuntimeHost( + ::GetProcAddress(module_, "GetCLRRuntimeHost")); if (!get_clr_runtime_host) { @@ -199,15 +204,18 @@ int coreclr_app::initialize(const char* clr_dir_c, const char* exe_path, const c return -1; } - hr = host_->SetStartupFlags(static_cast( - // STARTUP_SERVER_GC | // Use server GC - // STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN | // Maximize domain-neutral loading - // STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST | // Domain-neutral loading for strongly-named assemblies - STARTUP_CONCURRENT_GC | // Use concurrent GC - STARTUP_SINGLE_APPDOMAIN | // All code executes in the default AppDomain - // (required to use the runtimeHost->ExecuteAssembly helper function) - STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN // Prevents domain-neutral loading - )); + + hr = host_->SetStartupFlags( + static_cast( + // STARTUP_SERVER_GC | // Use server GC + // STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN | // Maximize domain-neutral loading + // STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST | // Domain-neutral loading for strongly-named assemblies + STARTUP_CONCURRENT_GC | // Use concurrent GC + STARTUP_SINGLE_APPDOMAIN | // All code executes in the default AppDomain + // (required to use the runtimeHost->ExecuteAssembly helper function) + STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN // Prevents domain-neutral loading + ) + ); if (FAILED(hr)) { @@ -225,32 +233,45 @@ int coreclr_app::initialize(const char* clr_dir_c, const char* exe_path, const c const int app_domain_flags = // APPDOMAIN_FORCE_TRIVIAL_WAIT_OPERATIONS | // Do not pump messages during wait - // APPDOMAIN_SECURITY_SANDBOXED | // Causes assemblies not from the TPA list to be loaded as - // partially trusted - APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS | // Enable platform-specific assemblies to run - APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP | // Allow PInvoking from non-TPA assemblies - APPDOMAIN_DISABLE_TRANSPARENCY_ENFORCEMENT; // Entirely disables transparency checks + // APPDOMAIN_SECURITY_SANDBOXED | // Causes assemblies not from the TPA list to be loaded as partially trusted + APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS | // Enable platform-specific assemblies to run + APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP | // Allow PInvoking from non-TPA assemblies + APPDOMAIN_DISABLE_TRANSPARENCY_ENFORCEMENT; // Entirely disables transparency checks // Setup key/value pairs for AppDomain properties - const wchar_t* propertyKeys[] = {L"TRUSTED_PLATFORM_ASSEMBLIES", - L"APP_PATHS", - L"APP_NI_PATHS", - L"NATIVE_DLL_SEARCH_DIRECTORIES", - L"PLATFORM_RESOURCE_ROOTS", - L"AppDomainCompatSwitch"}; + const wchar_t* propertyKeys[] = { + L"TRUSTED_PLATFORM_ASSEMBLIES", + L"APP_PATHS", + L"APP_NI_PATHS", + L"NATIVE_DLL_SEARCH_DIRECTORIES", + L"PLATFORM_RESOURCE_ROOTS", + L"AppDomainCompatSwitch" + }; std::wstring wtpa_list = std::wstring(tpa_list.begin(), tpa_list.end()); std::wstring wnative_search_dirs = std::wstring(native_search_dirs.begin(), native_search_dirs.end()); // Property values which were constructed in step 5 - const wchar_t* propertyValues[] = {wtpa_list.c_str(), wapp_dir.c_str(), - wapp_dir.c_str(), wnative_search_dirs.c_str(), - wapp_dir.c_str(), L"UseLatestBehaviorWhenTFMNotSpecified"}; + const wchar_t* propertyValues[] = { + wtpa_list.c_str(), + wapp_dir.c_str(), + wapp_dir.c_str(), + wnative_search_dirs.c_str(), + wapp_dir.c_str(), + L"UseLatestBehaviorWhenTFMNotSpecified" + }; + // Create the AppDomain - hr = host_->CreateAppDomainWithManager(wapp_domain_friendly_name.c_str(), app_domain_flags, nullptr, nullptr, - sizeof(propertyKeys) / sizeof(wchar_t*), propertyKeys, propertyValues, - &domain_id_); + hr = host_->CreateAppDomainWithManager( + wapp_domain_friendly_name.c_str(), + app_domain_flags, + nullptr, + nullptr, + sizeof(propertyKeys)/sizeof(wchar_t*), + propertyKeys, + propertyValues, + &domain_id_); if (FAILED(hr)) { @@ -262,15 +283,14 @@ int coreclr_app::initialize(const char* clr_dir_c, const char* exe_path, const c #endif } -int coreclr_app::construct_tpa(const char* directory, std::string& tpa_list) -{ +int coreclr_app::construct_tpa(const char *directory, std::string &tpa_list) { #if SAMPSHARP_LINUX - const char* const tpaExtensions[] = { - ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir - ".dll", - ".ni.exe", - ".exe", - }; + const char * const tpaExtensions[] = { + ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir + ".dll", + ".ni.exe", + ".exe", + }; DIR* dir = opendir(directory); if (dir == nullptr) @@ -302,25 +322,25 @@ int coreclr_app::construct_tpa(const char* directory, std::string& tpa_list) // Handle symlinks and file systems that do not support d_type case DT_LNK: case DT_UNKNOWN: - { - std::string fullFilename; - - fullFilename.append(directory); - fullFilename.append("/"); - fullFilename.append(entry->d_name); - - struct stat sb; - if (stat(fullFilename.c_str(), &sb) == -1) - { - continue; - } - - if (!S_ISREG(sb.st_mode)) { - continue; + std::string fullFilename; + + fullFilename.append(directory); + fullFilename.append("/"); + fullFilename.append(entry->d_name); + + struct stat sb; + if (stat(fullFilename.c_str(), &sb) == -1) + { + continue; + } + + if (!S_ISREG(sb.st_mode)) + { + continue; + } } - } - break; + break; default: continue; @@ -356,7 +376,11 @@ int coreclr_app::construct_tpa(const char* directory, std::string& tpa_list) closedir(dir); #elif SAMPSHARP_WINDOWS - const wchar_t* tpaExtensions[] = {L"*.dll", L"*.exe", L"*.winmd"}; + const wchar_t *tpaExtensions[] = { + L"*.dll", + L"*.exe", + L"*.winmd" + }; for (int i = 0; i < _countof(tpaExtensions); i++) { @@ -377,13 +401,16 @@ int coreclr_app::construct_tpa(const char* directory, std::string& tpa_list) std::wstring wname = std::wstring(find.cFileName); std::string name(wname.length(), 0); - std::transform(wname.begin(), wname.end(), name.begin(), [](wchar_t c) { return (char)c; }); + std::transform(wname.begin(), wname.end(), name.begin(), [] (wchar_t c) { + return (char)c; + }); tpa_list.append(std::string(directory)); tpa_list.append(DIR_SEPARATOR); tpa_list.append(name); tpa_list.append(TPA_DELIMITER); - } while (FindNextFileW(fhandle, &find)); + } + while (FindNextFileW(fhandle, &find)); FindClose(fhandle); } } @@ -391,10 +418,9 @@ int coreclr_app::construct_tpa(const char* directory, std::string& tpa_list) return 0; } -void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, std::string& tpa_list) -{ - if (std::filesystem::path(abs_exe_path).extension() != ".dll") - { +void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, + std::string &tpa_list) { + if(std::filesystem::path(abs_exe_path).extension() != ".dll") { return; } @@ -406,14 +432,12 @@ void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, std::string& tpa_lis runtimeconfig_path_p = abs_exe_path; runtimeconfig_path_p = runtimeconfig_path_p.replace_extension(".runtimeconfig.dev.json"); - if (!exists(runtimeconfig_path_p)) - { - runtimeconfig_path_p = abs_exe_path; - runtimeconfig_path_p = runtimeconfig_path_p.replace_extension(".runtimeconfig.json"); + if(!exists(runtimeconfig_path_p)) { + runtimeconfig_path_p = abs_exe_path; + runtimeconfig_path_p = runtimeconfig_path_p.replace_extension(".runtimeconfig.json"); } - - if (!exists(runtimeconfig_path_p)) - { + + if(!exists(runtimeconfig_path_p)) { return; } @@ -423,8 +447,7 @@ void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, std::string& tpa_lis std::filesystem::path deps_path_p(abs_exe_path); deps_path_p = deps_path_p.replace_extension(".deps.json"); - if (!exists(deps_path_p)) - { + if(!exists(deps_path_p)) { return; } @@ -437,43 +460,44 @@ void coreclr_app::add_deps_to_tpa(std::string abs_exe_path, std::string& tpa_lis std::ifstream runtimeconfig_stream(runtimeconfig_path); std::string runtimeconfig_json; - runtimeconfig_stream.seekg(0, std::ios::end); + runtimeconfig_stream.seekg(0, std::ios::end); runtimeconfig_json.reserve((size_t)runtimeconfig_stream.tellg()); runtimeconfig_stream.seekg(0, std::ios::beg); - runtimeconfig_json.assign(std::istreambuf_iterator(runtimeconfig_stream), std::istreambuf_iterator()); + runtimeconfig_json.assign( + std::istreambuf_iterator(runtimeconfig_stream), + std::istreambuf_iterator()); runtimeconfig_stream.close(); std::ifstream deps_stream(deps_path); std::string deps_json; - deps_stream.seekg(0, std::ios::end); + deps_stream.seekg(0, std::ios::end); deps_json.reserve((size_t)deps_stream.tellg()); deps_stream.seekg(0, std::ios::beg); - deps_json.assign(std::istreambuf_iterator(deps_stream), std::istreambuf_iterator()); + deps_json.assign( + std::istreambuf_iterator(deps_stream), + std::istreambuf_iterator()); deps_stream.close(); // Find probing paths - + nlohmann::json runtimeconfig = nlohmann::json::parse(runtimeconfig_json); - + std::vector probing_paths; - + auto probes = runtimeconfig["runtimeOptions"]["additionalProbingPaths"]; - for (auto it = probes.begin(); it != probes.end(); ++it) - { - if (!it.value().is_string()) - { + for (auto it = probes.begin(); it != probes.end(); ++it) { + if(!it.value().is_string()) { continue; } std::string path = it.value().get(); - - if (is_directory(std::filesystem::path(path))) - { + + if(is_directory(std::filesystem::path(path))) { probing_paths.push_back(path); log_debug("Probe path found: %s", path.c_str()); @@ -485,13 +509,11 @@ int coreclr_app::release() { int retval = -1; #if SAMPSHARP_LINUX - if (coreclr_shutdown_) - { + if(coreclr_shutdown_) { retval = coreclr_shutdown_(host_, domain_id_); } - if (module_) - { + if(module_) { dlclose(module_); module_ = NULL; } @@ -502,8 +524,7 @@ int coreclr_app::release() host_->Stop(); retval = (int)host_->Release(); - if (module_) - { + if(module_) { FreeLibrary(module_); module_ = nullptr; } @@ -512,16 +533,15 @@ int coreclr_app::release() return retval; } -int coreclr_app::create_delegate(const char* assembly_name, const char* type_name, const char* method_name, - void** delegate) -{ +int coreclr_app::create_delegate(const char* assembly_name, + const char* type_name, const char* method_name, void** delegate) { #if SAMPSHARP_LINUX - if (!coreclr_create_delegate_) - { + if(!coreclr_create_delegate_) { return -1; } - return coreclr_create_delegate_(host_, domain_id_, assembly_name, type_name, method_name, delegate); + return coreclr_create_delegate_(host_, domain_id_, assembly_name, + type_name, method_name, delegate); #elif SAMPSHARP_WINDOWS std::string an = std::string(assembly_name); @@ -532,15 +552,13 @@ int coreclr_app::create_delegate(const char* assembly_name, const char* type_nam std::wstring wtn = std::wstring(tn.begin(), tn.end()); std::wstring wmn = std::wstring(mn.begin(), mn.end()); - return host_->CreateDelegate(domain_id_, wan.c_str(), wtn.c_str(), wmn.c_str(), (INT_PTR*)delegate); + return host_->CreateDelegate(domain_id_, wan.c_str(), wtn.c_str(), wmn.c_str(), (INT_PTR*)delegate); #endif } -int coreclr_app::execute_assembly(int argc, const char** argv, unsigned int* exit_code) -{ +int coreclr_app::execute_assembly(int argc, const char** argv, unsigned int* exit_code) { #if SAMPSHARP_LINUX - if (!coreclr_execute_assembly_) - { + if(!coreclr_execute_assembly_) { return -1; } @@ -553,16 +571,14 @@ int coreclr_app::execute_assembly(int argc, const char** argv, unsigned int* exi size_t written; size_t len = argc; - for (int i = 0; i < argc; i++) - { + for(int i = 0; i < argc; i++) { len += strlen(argv[i]); } + + wchar_t *wargs = new wchar_t[len]; + wchar_t **wargv = new wchar_t*[argc]; - wchar_t* wargs = new wchar_t[len]; - wchar_t** wargv = new wchar_t*[argc]; - - for (int i = 0; i < argc; i++) - { + for(int i = 0; i < argc; i++) { wargs[pos] = L'\0'; mbstowcs_s(&written, wargs + pos, len - pos, argv[i], len - pos); @@ -572,8 +588,7 @@ int coreclr_app::execute_assembly(int argc, const char** argv, unsigned int* exi // Execute DWORD dexit_code = -1; - const DWORD retval = - host_->ExecuteAssembly(domain_id_, wabs_exe_path.c_str(), argc, (const wchar_t**)wargv, &dexit_code); + const DWORD retval = host_->ExecuteAssembly(domain_id_, wabs_exe_path.c_str(), argc, (const wchar_t **)wargv, &dexit_code); *exit_code = dexit_code; diff --git a/src/legacy/SampSharp/coreclr_app.h b/src/legacy/SampSharp/coreclr_app.h index 655cb7ab..d35f797d 100644 --- a/src/legacy/SampSharp/coreclr_app.h +++ b/src/legacy/SampSharp/coreclr_app.h @@ -18,52 +18,54 @@ #include #include "platforms.h" #if SAMPSHARP_LINUX -#include +# include #elif SAMPSHARP_WINDOWS -#include +# include #endif #if SAMPSHARP_LINUX -#define CORECLR_CALL -#define CORECLR_LIB "libcoreclr.so" -#define TPA_DELIMITER ":" +# define CORECLR_CALL +# define CORECLR_LIB "libcoreclr.so" +# define TPA_DELIMITER ":" #elif SAMPSHARP_WINDOWS -#define CORECLR_CALL __stdcall -#define CORECLR_LIB "coreclr.dll" -#define TPA_DELIMITER ";" +# define CORECLR_CALL __stdcall +# define CORECLR_LIB "coreclr.dll" +# define TPA_DELIMITER ";" #endif #if SAMPSHARP_LINUX typedef void host_t; typedef unsigned int domaind_id_t; -typedef void* module_t; +typedef void * module_t; #elif SAMPSHARP_WINDOWS typedef ICLRRuntimeHost2 host_t; typedef DWORD domaind_id_t; typedef HMODULE module_t; #endif -class coreclr_app -{ + +class coreclr_app { public: - int initialize(const char* clr_dir, const char* exe_path, const char* app_domain_friendly_name); - int create_delegate(const char* assembly_name, const char* type_name, const char* method_name, void** delegate); + int initialize(const char *clr_dir, const char* exe_path, + const char* app_domain_friendly_name); + int create_delegate(const char* assembly_name, const char* type_name, + const char* method_name, void** delegate); int execute_assembly(int argc, const char** argv, unsigned int* exit_code); int release(); private: - int construct_tpa(const char* directory, std::string& tpa_list); - void add_deps_to_tpa(std::string abs_exe_path, std::string& tpa_list); + int construct_tpa(const char *directory, std::string &tpa_list); + void add_deps_to_tpa(std::string abs_exe_path, std::string &tpa_list); private: std::string abs_exe_path_; - host_t* host_ = NULL; + host_t *host_ = NULL; module_t module_ = NULL; domaind_id_t domain_id_ = 0; #if SAMPSHARP_LINUX private: - bool load_symbol(void* coreclr_lib, const char* symbol, void** ptr); + bool load_symbol(void *coreclr_lib, const char *symbol, void **ptr); coreclr_initialize_ptr coreclr_initialize_ = NULL; coreclr_shutdown_ptr coreclr_shutdown_ = NULL; @@ -72,3 +74,4 @@ class coreclr_app coreclr_execute_assembly_ptr coreclr_execute_assembly_ = NULL; #endif }; + diff --git a/src/legacy/SampSharp/interop.cpp b/src/legacy/SampSharp/interop.cpp index 2e38f163..b6ab9534 100644 --- a/src/legacy/SampSharp/interop.cpp +++ b/src/legacy/SampSharp/interop.cpp @@ -16,53 +16,45 @@ #include "interop.h" #include "platforms.h" -struct sampsharp_api_t -{ +struct sampsharp_api_t { size_t size; - void** plugin_data; - void* find_native; - void* invoke_native; + void **plugin_data; + void *find_native; + void *invoke_native; } sampsharp_api; -typedef void api_public_call_t(AMX* amx, const char* name, cell* params, cell* retval); +typedef void api_public_call_t(AMX *amx, const char *name, cell *params, cell *retval); typedef void api_tick_t(); -api_public_call_t* bound_public_call = nullptr; -api_tick_t* bound_tick = nullptr; +api_public_call_t *bound_public_call = nullptr; +api_tick_t *bound_tick = nullptr; -void sampsharp_api_setup(void** plugin_data) -{ +void sampsharp_api_setup(void **plugin_data) { sampsharp_api.size = sizeof(sampsharp_api); sampsharp_api.plugin_data = plugin_data; - sampsharp_api.find_native = (void*)sampgdk_FindNative; - sampsharp_api.invoke_native = (void*)sampgdk_InvokeNativeArray; + sampsharp_api.find_native = (void *)sampgdk_FindNative; + sampsharp_api.invoke_native = (void *)sampgdk_InvokeNativeArray; } -void sampsharp_api_cleanup() -{ +void sampsharp_api_cleanup() { sampsharp_api.plugin_data = nullptr; bound_public_call = nullptr; bound_tick = nullptr; } -void sampsharp_api_public_call(AMX* amx, const char* name, cell* params, cell* retval) -{ - if (bound_public_call) - { +void sampsharp_api_public_call(AMX *amx, const char *name, cell *params, cell *retval) { + if(bound_public_call) { bound_public_call(amx, name, params, retval); } } -void sampsharp_api_tick() -{ - if (bound_tick) - { +void sampsharp_api_tick() { + if(bound_tick) { bound_tick(); } } -SAMPSHARP_EXPORT void SAMPSHARP_CALL_PTR sampsharp_api_initialize(api_public_call_t* public_call, api_tick_t* tick) -{ +SAMPSHARP_EXPORT void SAMPSHARP_CALL_PTR sampsharp_api_initialize(api_public_call_t *public_call, api_tick_t* tick) { bound_public_call = public_call; bound_tick = tick; return &sampsharp_api; diff --git a/src/legacy/SampSharp/interop.h b/src/legacy/SampSharp/interop.h index a10375d1..5533e70a 100644 --- a/src/legacy/SampSharp/interop.h +++ b/src/legacy/SampSharp/interop.h @@ -17,8 +17,8 @@ #include -void sampsharp_api_setup(void** plugin_data); +void sampsharp_api_setup(void **plugin_data); void sampsharp_api_cleanup(); -void sampsharp_api_public_call(AMX* amx, const char* name, cell* params, cell* retval); +void sampsharp_api_public_call(AMX *amx, const char *name, cell *params, cell *retval); void sampsharp_api_tick(); \ No newline at end of file diff --git a/src/legacy/SampSharp/locator.cpp b/src/legacy/SampSharp/locator.cpp index fc7845e7..72975b51 100644 --- a/src/legacy/SampSharp/locator.cpp +++ b/src/legacy/SampSharp/locator.cpp @@ -24,31 +24,27 @@ #if SAMPSHARP_WINDOWS #define HOSTFXR_LIB "hostfxr.dll" -#define CORECLR_LIB "coreclr.dll" +# define CORECLR_LIB "coreclr.dll" #elif SAMPSHARP_LINUX #define HOSTFXR_LIB "libhostfxr.so" -#define CORECLR_LIB "libcoreclr.so" +# define CORECLR_LIB "libcoreclr.so" #endif -locator::locator(config* cfg) : - cfg_(cfg) -{ -} +locator::locator(config* cfg) : cfg_(cfg) {} -fs::path locator::get_hostfxr() const -{ +fs::path locator::get_hostfxr() const { std::string hint; fs::path result; - cfg_->get_config_string("coreclr", hint) || cfg_->get_config_string("runtime", hint); + cfg_->get_config_string("coreclr", hint) || + cfg_->get_config_string("runtime", hint); detect_lib(result, hint, HOSTFXR_LIB); return result; } -fs::path locator::get_coreclr() const -{ +fs::path locator::get_coreclr() const { std::string hint; fs::path result; cfg_->get_config_string("runtime", hint); @@ -58,8 +54,7 @@ fs::path locator::get_coreclr() const return result; } -fs::path locator::get_gamemode() const -{ +fs::path locator::get_gamemode() const { std::string base, gamemode; fs::path result; cfg_->get_config_string("gamemode", gamemode); @@ -70,10 +65,8 @@ fs::path locator::get_gamemode() const return result; } -bool locator::detect_lib_recursive(fs::path& result, const fs::path& search_path, const std::string& lib) -{ - if (!is_directory(search_path)) - { +bool locator::detect_lib_recursive(fs::path& result, const fs::path& search_path, const std::string& lib) { + if (!is_directory(search_path)) { return false; } @@ -81,17 +74,14 @@ bool locator::detect_lib_recursive(fs::path& result, const fs::path& search_path // Check in current directory const fs::path check_path = search_path / lib; - if (exists(check_path)) - { + if (exists(check_path)) { result = check_path; return true; } // Check every subdirectory - for (const auto& entry : fs::directory_iterator(search_path)) - { - if (entry.is_directory() && detect_lib_recursive(result, entry.path(), lib)) - { + for (const auto& entry : fs::directory_iterator(search_path)) { + if (entry.is_directory() && detect_lib_recursive(result, entry.path(), lib)) { return true; } } @@ -99,61 +89,54 @@ bool locator::detect_lib_recursive(fs::path& result, const fs::path& search_path return false; } -bool locator::detect_lib(fs::path& result, const std::string& path_hint, const std::string& lib) -{ - if (!path_hint.empty()) - { +bool locator::detect_lib(fs::path& result, const std::string& path_hint, const std::string& lib) { + if (!path_hint.empty()) { const fs::path hint = path_hint; - if (hint.filename() == lib && exists(hint)) - { + + if (hint.filename() == lib && exists(hint)) { result = hint; return true; } - if (is_directory(hint) && detect_lib_recursive(result, fs::path("runtime"), lib)) - { + if (is_directory(hint) && detect_lib_recursive(result, fs::path("runtime"), lib)) { return true; } } const auto runtime = getenv("SAMPSHARP_RUNTIME"); - return runtime && strlen(runtime) > 0 && detect_lib_recursive(result, fs::path(runtime), lib) || - detect_lib_recursive(result, fs::path("runtime"), lib) || - detect_lib_recursive(result, fs::path("dotnet"), lib); + return + runtime && strlen(runtime) > 0 && detect_lib_recursive(result, fs::path(runtime), lib) || + detect_lib_recursive(result, fs::path("runtime"), lib) || + detect_lib_recursive(result, fs::path("dotnet"), lib); } -bool is_runtime_config(const fs::path& path, const std::string& search_name) -{ - if (search_name.length() == 0) - { +bool is_runtime_config(const fs::path& path, const std::string& search_name) { + if(search_name.length() == 0) { return path.extension() == ".json" && path.stem().extension() == ".runtimeconfig"; } return iequals(path.filename().string(), search_name); } -bool locator::detect_gamemode_recursive(fs::path& result, const std::string& search_name, const fs::path& search_path) -{ - if (!is_directory(search_path)) - { +bool locator::detect_gamemode_recursive(fs::path& result, const std::string& search_name, const fs::path& search_path) { + if (!is_directory(search_path)) { return false; } log_debug("Checking for game mode in %s...", search_path.string().c_str()); // Check in current directory - for (const auto& entry : fs::directory_iterator(search_path)) - { + for (const auto& entry : fs::directory_iterator(search_path)) { - if (entry.is_regular_file() && is_runtime_config(entry.path(), search_name)) - { + if (entry.is_regular_file() && is_runtime_config(entry.path(), search_name)) { fs::path rc_path = entry.path(); - fs::path dll_path = rc_path.replace_extension("").replace_extension(".dll"); // .runtimeconfig.json -> .dll + fs::path dll_path = rc_path + .replace_extension("") + .replace_extension(".dll"); // .runtimeconfig.json -> .dll - if (exists(dll_path)) - { + if (exists(dll_path)) { result = dll_path; return true; } @@ -165,38 +148,31 @@ bool locator::detect_gamemode_recursive(fs::path& result, const std::string& sea int best_version_number = 0; fs::path best_version; - for (const auto& entry : fs::directory_iterator(search_path)) - { - if (!entry.is_directory()) - { + for (const auto& entry : fs::directory_iterator(search_path)) { + if (!entry.is_directory()) { continue; } fs::path entry_path = entry.path(); std::string entry_dirname = entry_path.filename().string(); std::smatch match; - if (std::regex_match(entry_dirname, match, regex_version)) - { + if (std::regex_match(entry_dirname, match, regex_version)) { int version_number = stoi(match[1]) * 1000 + stoi(match[2]); - if (version_number > best_version_number) - { + if (version_number > best_version_number) { best_version = entry_path; best_version_number = version_number; } } } - if (!best_version.empty() && detect_gamemode_recursive(result, search_name, best_version)) - { + if (!best_version.empty() && detect_gamemode_recursive(result, search_name, best_version)) { return true; } // Check every subdirectory - for (const auto& entry : fs::directory_iterator(search_path)) - { - if (entry.is_directory() && detect_gamemode_recursive(result, search_name, entry.path())) - { + for (const auto& entry : fs::directory_iterator(search_path)) { + if (entry.is_directory() && detect_gamemode_recursive(result, search_name, entry.path())) { return true; } } @@ -204,11 +180,13 @@ bool locator::detect_gamemode_recursive(fs::path& result, const std::string& sea return false; } -bool locator::detect_gamemode(const std::string& dir_hint, const std::string& name, fs::path& result) -{ - const auto search_name = name.length() == 0 ? "" : name + ".runtimeconfig.json"; +bool locator::detect_gamemode(const std::string& dir_hint, const std::string& name, fs::path& result) { + const auto search_name = name.length() == 0 + ? "" + : name + ".runtimeconfig.json"; - return (dir_hint.length() > 0 && detect_gamemode_recursive(result, search_name, dir_hint)) || - detect_gamemode_recursive(result, search_name, "gamemode") || - detect_gamemode_recursive(result, search_name, "gamemodes"); + return + (dir_hint.length() > 0 && detect_gamemode_recursive(result, search_name, dir_hint)) || + detect_gamemode_recursive(result, search_name, "gamemode") || + detect_gamemode_recursive(result, search_name, "gamemodes"); } diff --git a/src/legacy/SampSharp/locator.h b/src/legacy/SampSharp/locator.h index f58fa937..1d696451 100644 --- a/src/legacy/SampSharp/locator.h +++ b/src/legacy/SampSharp/locator.h @@ -25,20 +25,19 @@ namespace fs = std::filesystem; class locator { public: - locator(config* cfg); + locator(config *cfg); /* returns path to libhostfxr. */ fs::path get_hostfxr() const; /* returns path to libcoreclr. */ fs::path get_coreclr() const; /* returns path to runtimeconfig of gamemode. */ fs::path get_gamemode() const; - + private: static bool detect_lib_recursive(fs::path& result, const fs::path& search_path, const std::string& lib); - static bool detect_lib(fs::path& result, const std::string& path_hint, const std::string& lib); - static bool detect_gamemode_recursive(fs::path& result, const std::string& search_name, - const fs::path& search_path); - static bool detect_gamemode(const std::string& dir_hint, const std::string& name, fs::path& result); + static bool detect_lib(fs::path &result, const std::string &path_hint, const std::string &lib); + static bool detect_gamemode_recursive(fs::path& result, const std::string& search_name, const fs::path& search_path); + static bool detect_gamemode(const std::string &dir_hint, const std::string &name, fs::path &result); - config* cfg_; + config *cfg_; }; \ No newline at end of file diff --git a/src/legacy/SampSharp/logging.cpp b/src/legacy/SampSharp/logging.cpp index 89ceeb28..f66ab0c1 100644 --- a/src/legacy/SampSharp/logging.cpp +++ b/src/legacy/SampSharp/logging.cpp @@ -21,14 +21,13 @@ /* platform specifics */ #if SAMPSHARP_WINDOWS -#define vsnprintf vsprintf_s +# define vsnprintf vsprintf_s #endif -#define LEN_PRINT_BUFFER (1024) +#define LEN_PRINT_BUFFER (1024) /** log a message */ -void vlog(const char* prefix, const char* format, va_list args) -{ +void vlog(const char* prefix, const char *format, va_list args) { char buffer[LEN_PRINT_BUFFER]; vsnprintf(buffer, LEN_PRINT_BUFFER, format, args); buffer[LEN_PRINT_BUFFER - 1] = '\0'; @@ -36,8 +35,7 @@ void vlog(const char* prefix, const char* format, va_list args) sampgdk_logprintf("[SampSharp:%s] %s", prefix, buffer); } -void log_print(const char* format, ...) -{ +void log_print(const char *format, ...) { va_list args; va_start(args, format); sampgdk_vlogprintf(format, args); @@ -45,8 +43,7 @@ void log_print(const char* format, ...) } /** log error */ -void log_error(const char* format, ...) -{ +void log_error(const char * format, ...) { va_list args; va_start(args, format); vlog("ERROR", format, args); @@ -54,8 +51,7 @@ void log_error(const char* format, ...) } /** log error */ -void log_warning(const char* format, ...) -{ +void log_warning(const char * format, ...) { va_list args; va_start(args, format); vlog("WARNING", format, args); @@ -63,8 +59,7 @@ void log_warning(const char* format, ...) } /** log debug */ -void log_debug2(const char* format, ...) -{ +void log_debug2(const char * format, ...) { va_list args; va_start(args, format); vlog("DEBUG", format, args); @@ -72,8 +67,7 @@ void log_debug2(const char* format, ...) } /** log info */ -void log_info(const char* format, ...) -{ +void log_info(const char * format, ...) { va_list args; va_start(args, format); vlog("INFO", format, args); diff --git a/src/legacy/SampSharp/logging.h b/src/legacy/SampSharp/logging.h index 7c6fc278..b899dbcc 100644 --- a/src/legacy/SampSharp/logging.h +++ b/src/legacy/SampSharp/logging.h @@ -17,23 +17,23 @@ #include "platforms.h" -void log_debug2(const char* format, ...); +void log_debug2(const char *format, ...); /** prints text to the output */ -void log_print(const char* format, ...); +void log_print(const char *format, ...); /** log an error */ -void log_error(const char* format, ...); +void log_error(const char *format, ...); /** log a warning */ -void log_warning(const char* format, ...); +void log_warning(const char *format, ...); /** log debug info */ #ifdef LOG_DEBUG #define log_debug(format, ...) log_debug2(format, ##__VA_ARGS__) #else -#define log_debug(format, ...) while (0) +#define log_debug(format, ...) while(0) #endif /** log info */ -void log_info(const char* format, ...); +void log_info(const char *format, ...); diff --git a/src/legacy/SampSharp/main.cpp b/src/legacy/SampSharp/main.cpp index add58759..ddedafee 100644 --- a/src/legacy/SampSharp/main.cpp +++ b/src/legacy/SampSharp/main.cpp @@ -26,22 +26,19 @@ #include "interop.h" #include "nethost_coreclr.h" -nethost* host = nullptr; +nethost *host = nullptr; bool started = false; -extern void* pAMXFunctions; +extern void *pAMXFunctions; -void write_empty_gamemode() -{ - if (fs::exists("gamemodes/empty.amx")) - { +void write_empty_gamemode() { + if(fs::exists("gamemodes/empty.amx")) { return; } log_info("Writing gamemodes/empty.amx to disk"); - if (!fs::exists("gamemodes")) - { + if(!fs::exists("gamemodes")) { fs::create_directory("gamemodes"); } @@ -49,27 +46,25 @@ void write_empty_gamemode() fout.open("gamemodes/empty.amx", std::ios::binary | std::ios::out); // compiled bytecode for script: main() return; - const uint8_t empty_amx[] = {0x45, 0x00, 0x00, 0x00, 0xE0, 0xF1, 0x08, 0x08, 0x04, 0x00, 0x08, 0x00, 0x3C, 0x00, - 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x54, 0x40, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, - 0x1F, 0x00, 0x00, 0x00, 0x80, 0x78, 0x00, 0x2E, 0x81, 0x09, 0x80, 0x59, 0x30}; - - fout.write((const char*)empty_amx, sizeof(empty_amx)); + const uint8_t empty_amx[] = { + 0x45, 0x00, 0x00, 0x00, 0xE0, 0xF1, 0x08, 0x08, 0x04, 0x00, 0x08, 0x00, 0x3C, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x54, 0x40, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x80, 0x78, 0x00, 0x2E, + 0x81, 0x09, 0x80, 0x59, 0x30}; + + fout.write((const char *)empty_amx, sizeof(empty_amx)); fout.close(); } -bool validate_config(config* cfg) -{ +bool validate_config(config *cfg) { bool skip; - if (cfg->get_config_bool("skip_empty_check", skip) && skip) - { + if(cfg->get_config_bool("skip_empty_check", skip) && skip) { return true; } - + /* check whether gamemodeN values contain acceptable values. */ - for (int i = 0; i < 15; i++) - { + for (int i = 0; i < 15; i++) { std::ostringstream gamemode_key; std::string gamemode_value; @@ -79,19 +74,17 @@ bool validate_config(config* cfg) const bool exists = cfg->get_config_string(gamemode_key.str(), gamemode_value); const bool is_empty = gamemode_value == "empty" || gamemode_value.rfind("empty ") == 0; - if (i == 0 && !is_empty) - { + if (i == 0 && !is_empty) { log_error("Can not load sampsharp if a non-SampSharp gamemode is set to load."); log_error("Please ensure you set 'gamemode0 empty 1' in your server.cfg file."); log_error("To override this behaviour add 'skip_empty_check 1' to your server.cfg file."); return false; } - if (i > 0 && exists) - { + if (i > 0 && exists) { log_error("Can not load sampsharp if a non-SampSharp gamemode is set to load."); log_error("Please ensure you only specify one script gamemode, namely 'gamemode0" - "empty 1' in your server.cfg file."); + "empty 1' in your server.cfg file."); log_error("To override this behaviour add 'skip_empty_check 1' to your server.cfg file."); return false; } @@ -102,19 +95,15 @@ bool validate_config(config* cfg) return true; } -PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() -{ +PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() { return sampgdk::Supports() | SUPPORTS_PROCESS_TICK | SUPPORTS_AMX_NATIVES; } -bool is_open_mp(void** ppData) -{ +bool is_open_mp(void **ppData) { // open.mp sets plugin data to zero for uninitialized fields. probe a few to make some assumptions. // it might however be a better idea to simply check the name of the current process... - for (int i = 0x02; i < 0x10; i++) - { - if (ppData[i] != nullptr) - { + for (int i = 0x02; i < 0x10; i++) { + if (ppData[i] != nullptr) { return false; } } @@ -122,10 +111,8 @@ bool is_open_mp(void** ppData) return true; } -PLUGIN_EXPORT bool PLUGIN_CALL Load(void** ppData) -{ - if (!sampgdk::Load(ppData)) - { +PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { + if (!sampgdk::Load(ppData)) { return false; } @@ -133,7 +120,7 @@ PLUGIN_EXPORT bool PLUGIN_CALL Load(void** ppData) sampsharp_api_setup(ppData); log_info("v%s, (C)2014-2022 Tim Potze", PLUGIN_VERSION_STR); - + config_composite config; #if SAMPSHARP_WINDOWS @@ -143,8 +130,7 @@ PLUGIN_EXPORT bool PLUGIN_CALL Load(void** ppData) #endif config_omp config_omp; - if (is_open_mp(ppData)) - { + if(is_open_mp(ppData)) { log_debug("Adding open.mp config reader"); config.add_config(&config_omp); } @@ -154,25 +140,22 @@ PLUGIN_EXPORT bool PLUGIN_CALL Load(void** ppData) locator loc(&config); - if (!validate_config(&config)) - { + if(!validate_config(&config)) { return false; } - + host = new nethost_coreclr(); - if (!host->setup(&loc, &config)) - { + if(!host->setup(&loc, &config)) { delete host; host = nullptr; return false; } - + return true; } -PLUGIN_EXPORT void PLUGIN_CALL Unload() -{ +PLUGIN_EXPORT void PLUGIN_CALL Unload() { delete host; host = nullptr; @@ -180,29 +163,25 @@ PLUGIN_EXPORT void PLUGIN_CALL Unload() sampgdk::Unload(); } -PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX* amx) -{ +PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX* amx) { return load_test_natives(amx); } -PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX* amx) -{ +PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX* amx) { return 1; } -PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() -{ +PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() { sampsharp_api_tick(); } -PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall(AMX* amx, const char* name, cell* params, cell* retval) -{ - if (!started && host) - { +PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall(AMX *amx, const char *name, + cell *params, cell *retval) { + if(!started && host) { started = true; host->start(); } - + sampsharp_api_public_call(amx, name, params, retval); return true; } diff --git a/src/legacy/SampSharp/nethost.h b/src/legacy/SampSharp/nethost.h index e54de4b2..025eb837 100644 --- a/src/legacy/SampSharp/nethost.h +++ b/src/legacy/SampSharp/nethost.h @@ -17,11 +17,10 @@ #include "config.h" #include "locator.h" -class nethost -{ +class nethost { public: virtual ~nethost() = default; - virtual bool setup(locator* locator, config* cfg) = 0; + virtual bool setup(locator *locator, config* cfg) = 0; virtual void start() = 0; virtual void stop() = 0; }; diff --git a/src/legacy/SampSharp/nethost_coreclr.cpp b/src/legacy/SampSharp/nethost_coreclr.cpp index 9eb57645..7bc5075a 100644 --- a/src/legacy/SampSharp/nethost_coreclr.cpp +++ b/src/legacy/SampSharp/nethost_coreclr.cpp @@ -16,24 +16,21 @@ #include "nethost_coreclr.h" #include "logging.h" -nethost_coreclr::~nethost_coreclr() -{ +nethost_coreclr::~nethost_coreclr() { release(); } -bool nethost_coreclr::setup(locator* locator, config* cfg) -{ +bool nethost_coreclr::setup(locator *locator, config* cfg) { coreclr_ = locator->get_coreclr(); gamemode_ = locator->get_gamemode(); - if (coreclr_.empty() || !exists(coreclr_)) - { + if(coreclr_.empty() || !exists(coreclr_)) { log_error("Invalid coreclr directory specified in server.cfg."); return false; } - - if (gamemode_.empty() || !exists(gamemode_)) - { + + + if(gamemode_.empty() || !exists(gamemode_)) { log_error("Invalid gamemode specified in server.cfg."); return false; } @@ -43,8 +40,7 @@ bool nethost_coreclr::setup(locator* locator, config* cfg) return true; } -void nethost_coreclr::start() -{ +void nethost_coreclr::start() { int retval; unsigned int exitcode; @@ -52,26 +48,23 @@ void nethost_coreclr::start() const auto exe_path = (gamemode_).string(); log_info("Initializing .NET runtime..."); - if ((retval = app_.initialize(clr_dir.c_str(), exe_path.c_str(), "SampSharp Host")) < 0) - { + if((retval = app_.initialize(clr_dir.c_str(), exe_path.c_str(), "SampSharp Host")) < 0) { log_error("Failed to initialize CoreCLR runtime. Error %d.", retval); return; } host_init_ = true; - + log_info("Starting game mode host..."); - const char* args[1]; + const char *args[1]; args[0] = "--hosted"; - if ((retval = app_.execute_assembly(std::size(args), args, &exitcode)) < 0) - { + if((retval = app_.execute_assembly(std::size(args), args, &exitcode)) < 0) { log_error("Failed to prepare game mode. Error %d.", retval); return; } - if (exitcode) - { + if(exitcode) { log_error("Failed to prepare game mode. Exit code %d.", exitcode); return; } @@ -80,16 +73,13 @@ void nethost_coreclr::start() running_ = true; } -void nethost_coreclr::stop() -{ +void nethost_coreclr::stop() { release(); } -void nethost_coreclr::release() -{ - if (host_init_) - { +void nethost_coreclr::release() { + if(host_init_) { app_.release(); host_init_ = false; - } + } } \ No newline at end of file diff --git a/src/legacy/SampSharp/nethost_coreclr.h b/src/legacy/SampSharp/nethost_coreclr.h index c9f4f342..aa1ee7ef 100644 --- a/src/legacy/SampSharp/nethost_coreclr.h +++ b/src/legacy/SampSharp/nethost_coreclr.h @@ -2,14 +2,12 @@ #include "coreclr_app.h" #include "nethost.h" -class nethost_coreclr : public nethost -{ +class nethost_coreclr : public nethost { public: ~nethost_coreclr() override; - bool setup(locator* locator, config* cfg) override; + bool setup(locator *locator, config* cfg) override; void start() override; void stop() override; - private: void release(); diff --git a/src/legacy/SampSharp/platforms.h b/src/legacy/SampSharp/platforms.h index 3b4813b9..dd2b3091 100644 --- a/src/legacy/SampSharp/platforms.h +++ b/src/legacy/SampSharp/platforms.h @@ -16,39 +16,39 @@ #pragma once #if (defined __CYGWIN32__ || defined RC_INVOKED) && !defined WIN32 -#define WIN32 +# define WIN32 #endif #if defined WIN32 || defined _WIN32 || defined __WIN32__ -#define SAMPSHARP_LINUX 0 -#define SAMPSHARP_WINDOWS 1 +# define SAMPSHARP_LINUX 0 +# define SAMPSHARP_WINDOWS 1 #endif #if defined __linux__ || defined __linux || defined linux -#if !defined LINUX -#define LINUX -#endif -#define SAMPSHARP_LINUX 1 -#define SAMPSHARP_WINDOWS 0 +# if !defined LINUX +# define LINUX +# endif +# define SAMPSHARP_LINUX 1 +# define SAMPSHARP_WINDOWS 0 #endif #ifdef __cplusplus -#define SAMPSHARP_EXPORT extern "C" +# define SAMPSHARP_EXPORT extern "C" #else -#define SAMPSHARP_EXPORT +# define SAMPSHARP_EXPORT #endif #if defined DEBUG || defined _DEBUG -#define ENABLE_TEST_NATIVES -#define LOG_DEBUG +# define ENABLE_TEST_NATIVES +# define LOG_DEBUG #endif #if SAMPSHARP_WINDOWS -#define SAMPSHARP_CALL __stdcall -#define SAMPSHARP_CALL_PTR *SAMPSHARP_CALL +# define SAMPSHARP_CALL __stdcall +# define SAMPSHARP_CALL_PTR *SAMPSHARP_CALL #elif SAMPSHARP_LINUX -#define SAMPSHARP_CALL __attribute__((visibility("default"))) -#define SAMPSHARP_CALL_PTR SAMPSHARP_CALL* +# define SAMPSHARP_CALL __attribute__((visibility("default"))) +# define SAMPSHARP_CALL_PTR SAMPSHARP_CALL * #else #error Unsupported platform #endif diff --git a/src/legacy/SampSharp/strutil.cpp b/src/legacy/SampSharp/strutil.cpp index c6c53954..db360c28 100644 --- a/src/legacy/SampSharp/strutil.cpp +++ b/src/legacy/SampSharp/strutil.cpp @@ -17,7 +17,10 @@ #include #include -bool iequals(const std::string& a, const std::string& b) -{ - return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](char a, char b) { return tolower(a) == tolower(b); }); +bool iequals(const std::string& a, const std::string& b) { + return std::equal(a.begin(), a.end(), + b.begin(), b.end(), + [](char a, char b) { + return tolower(a) == tolower(b); + }); } diff --git a/src/legacy/SampSharp/testing.cpp b/src/legacy/SampSharp/testing.cpp index 1b66f04c..eab3bcbe 100644 --- a/src/legacy/SampSharp/testing.cpp +++ b/src/legacy/SampSharp/testing.cpp @@ -21,15 +21,13 @@ #ifdef ENABLE_TEST_NATIVES // native sampsharptest_inout(a); -cell test_inout(AMX* amx, cell* params) -{ +cell test_inout(AMX* amx, cell* params) { log_info("test_inout %d", params[1]); return params[1]; } // native sampsharptest_inrefout(a, &b); -cell test_inrefout(AMX* amx, cell* params) -{ +cell test_inrefout(AMX* amx, cell* params) { cell* address; amx_GetAddr(amx, params[2], &address); *address = params[1]; @@ -39,8 +37,7 @@ cell test_inrefout(AMX* amx, cell* params) } // native sampsharptest_inoutstr(const a[], b[], blen = sizeof b); -cell test_inoutstr(AMX* amx, cell* params) -{ +cell test_inoutstr(AMX* amx, cell* params) { char* str; amx_StrParam(amx, params[1], str); @@ -54,8 +51,7 @@ cell test_inoutstr(AMX* amx, cell* params) } // native sampsharptest_inoutarr(const a[], b[], ablen = sizeof a); -cell test_inoutarr(AMX* amx, cell* params) -{ +cell test_inoutarr(AMX* amx, cell* params) { cell* addr_a; cell* addr_b; @@ -71,12 +67,10 @@ cell test_inoutarr(AMX* amx, cell* params) } // native sampsharptest_varargs({Float,_}:...); -cell test_varargs(AMX* amx, cell* params) -{ +cell test_varargs(AMX* amx, cell* params) { log_info("test_varargs len=%d", params[0]); - for (unsigned int i = 0; i < params[0] / sizeof(cell); i++) - { + for (unsigned int i = 0; i < params[0] / sizeof(cell); i++) { cell* addr; amx_GetAddr(amx, params[i + 1], &addr); @@ -87,15 +81,13 @@ cell test_varargs(AMX* amx, cell* params) } // native sampsharptest_varargs_mix(a, b, {Float,_}:...); -cell test_varargs_mix(AMX* amx, cell* params) -{ +cell test_varargs_mix(AMX* amx, cell* params) { log_info("test_varargs_mix len=%d", params[0]); log_info("test_varargs_mix arg[0]=%d", params[1]); log_info("test_varargs_mix arg[1]=%d", params[2]); - for (unsigned int i = 2; i < params[0] / sizeof(cell); i++) - { + for (unsigned int i = 2; i < params[0] / sizeof(cell); i++) { cell* addr; amx_GetAddr(amx, params[i + 1], &addr); @@ -106,12 +98,10 @@ cell test_varargs_mix(AMX* amx, cell* params) } // native sampsharptest_varargs_str({_}:...); -cell test_varargs_str(AMX* amx, cell* params) -{ +cell test_varargs_str(AMX* amx, cell* params) { log_info("test_varargs_str len=%d", params[0]); - for (unsigned int i = 0; i < params[0] / sizeof(cell); i++) - { + for (unsigned int i = 0; i < params[0] / sizeof(cell); i++) { char* str; amx_StrParam(amx, params[i + 1], str); @@ -122,24 +112,24 @@ cell test_varargs_str(AMX* amx, cell* params) return 1; } -extern "C" const AMX_NATIVE_INFO native_list[] = {{"sampsharptest_inout", test_inout}, - {"sampsharptest_inrefout", test_inrefout}, - {"sampsharptest_inoutstr", test_inoutstr}, - {"sampsharptest_inoutarr", test_inoutarr}, - {"sampsharptest_varargs", test_varargs}, - {"sampsharptest_varargs_mix", test_varargs_mix}, - {"sampsharptest_varargs_str", test_varargs_str}, - {NULL, NULL}}; - -int load_test_natives(AMX* amx) -{ +extern "C" const AMX_NATIVE_INFO native_list[] = { + {"sampsharptest_inout", test_inout}, + {"sampsharptest_inrefout", test_inrefout}, + {"sampsharptest_inoutstr", test_inoutstr}, + {"sampsharptest_inoutarr", test_inoutarr}, + {"sampsharptest_varargs", test_varargs}, + {"sampsharptest_varargs_mix", test_varargs_mix}, + {"sampsharptest_varargs_str", test_varargs_str}, + {NULL, NULL} +}; + +int load_test_natives(AMX* amx) { return amx_Register(amx, native_list, -1); } #else -int load_test_natives(AMX* amx) -{ +int load_test_natives(AMX* amx) { return 1; } #endif diff --git a/src/legacy/SampSharp/version.h b/src/legacy/SampSharp/version.h index 2fb1b860..83568cdc 100644 --- a/src/legacy/SampSharp/version.h +++ b/src/legacy/SampSharp/version.h @@ -15,23 +15,28 @@ #pragma once -#define PLUGIN_VERSION_MAJOR 0 -#define PLUGIN_VERSION_MINOR 11 -#define PLUGIN_VERSION_PATCH 0 -#define PLUGIN_VERSION_ALPHA 0 +#define PLUGIN_VERSION_MAJOR 0 +#define PLUGIN_VERSION_MINOR 11 +#define PLUGIN_VERSION_PATCH 0 +#define PLUGIN_VERSION_ALPHA 0 -#define __PLUGIN_STRINGIZE(x) #x -#define __PLUGIN_STRINGIZEX(x) __PLUGIN_STRINGIZE(x) +#define __PLUGIN_STRINGIZE(x) #x +#define __PLUGIN_STRINGIZEX(x) __PLUGIN_STRINGIZE(x) -#define __PLUGIN_VERSION_STR \ - __PLUGIN_STRINGIZEX(PLUGIN_VERSION_MAJOR) \ - "." __PLUGIN_STRINGIZEX(PLUGIN_VERSION_MINOR) "." __PLUGIN_STRINGIZEX(PLUGIN_VERSION_PATCH) +#define __PLUGIN_VERSION_STR \ + __PLUGIN_STRINGIZEX(PLUGIN_VERSION_MAJOR) "." \ + __PLUGIN_STRINGIZEX(PLUGIN_VERSION_MINOR) "." \ + __PLUGIN_STRINGIZEX(PLUGIN_VERSION_PATCH) #if PLUGIN_VERSION_ALPHA > 0 -#define PLUGIN_VERSION_STR __PLUGIN_VERSION_STR "-alpha" __PLUGIN_STRINGIZEX(PLUGIN_VERSION_ALPHA) +# define PLUGIN_VERSION_STR __PLUGIN_VERSION_STR "-alpha" \ + __PLUGIN_STRINGIZEX(PLUGIN_VERSION_ALPHA) #else -#define PLUGIN_VERSION_STR __PLUGIN_VERSION_STR +# define PLUGIN_VERSION_STR __PLUGIN_VERSION_STR #endif -#define PLUGIN_VERSION \ - ((PLUGIN_VERSION_MAJOR << 16) | (PLUGIN_VERSION_MINOR << 8) | (PLUGIN_VERSION_PATCH) | (PLUGIN_VERSION_ALPHA << 24)) +#define PLUGIN_VERSION ( \ + (PLUGIN_VERSION_MAJOR << 16) | \ + (PLUGIN_VERSION_MINOR << 8) | \ + (PLUGIN_VERSION_PATCH) | \ + (PLUGIN_VERSION_ALPHA << 24)) From a2839e92f6e54d5552bb8df2e5eaedd805ecf037 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 May 2026 22:08:17 +0000 Subject: [PATCH 4/4] Remove redundant includes/.clang-format (covered by src/legacy/.clang-format) Agent-Logs-Url: https://github.com/ikkentim/SampSharp/sessions/77f277a6-3474-4b98-a3f1-45953ea3519d Co-authored-by: ikkentim <2820647+ikkentim@users.noreply.github.com> --- src/legacy/SampSharp/includes/.clang-format | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/legacy/SampSharp/includes/.clang-format diff --git a/src/legacy/SampSharp/includes/.clang-format b/src/legacy/SampSharp/includes/.clang-format deleted file mode 100644 index 57fe428d..00000000 --- a/src/legacy/SampSharp/includes/.clang-format +++ /dev/null @@ -1,3 +0,0 @@ ---- -DisableFormat: true -...