From 2c9fea511732a0fb8772898e39b1c66c41a7c56c Mon Sep 17 00:00:00 2001 From: vadzz Date: Sat, 24 Aug 2024 18:15:46 +0300 Subject: [PATCH 01/10] ALTV-330 Add runtime prefix for logs --- c-api/core.cpp | 12 ++++++------ client/thirdparty/Log.h | 12 +++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/c-api/core.cpp b/c-api/core.cpp index 71de297..b9444f4 100644 --- a/c-api/core.cpp +++ b/c-api/core.cpp @@ -12,23 +12,23 @@ CAPI_START() void Core_LogInfo(alt::ICore* core, const char* str) { - core->LogInfo(str); + core->LogInfo(cs::Log::LOG_PREFIX, str); } void Core_LogDebug(alt::ICore* core, const char* str) { - core->LogDebug(str); + core->LogDebug(cs::Log::LOG_PREFIX, str); } void Core_LogWarning(alt::ICore* core, const char* str) { - core->LogWarning(str); + core->LogWarning(cs::Log::LOG_PREFIX, str); } void Core_LogError(alt::ICore* core, const char* str) { - core->LogError(str); + core->LogError(cs::Log::LOG_PREFIX, str); } void Core_LogColored(alt::ICore* core, const char* str) { - core->LogColored(str); + core->LogColored(cs::Log::LOG_PREFIX, str); } alt::MValueConst* Core_CreateMValueNil(alt::ICore* core) { @@ -1218,7 +1218,7 @@ void Core_TriggerServerEventUnreliable(alt::ICore* core, const char* event, alt: void Core_ShowCursor(alt::ICore* core, alt::IResource* resource, uint8_t state) { if(!resource->ToggleCursor(state)) { - core->LogWarning("Cursor state can't go < 0"); + core->LogWarning(cs::Log::LOG_PREFIX, "Cursor state can't go < 0"); } } diff --git a/client/thirdparty/Log.h b/client/thirdparty/Log.h index 49c6c3e..0d5e7a8 100644 --- a/client/thirdparty/Log.h +++ b/client/thirdparty/Log.h @@ -23,6 +23,8 @@ class Log Log() = default; public: + static constexpr const char* LOG_PREFIX = "[C#]"; + Log(const Log&) = delete; Log(Log&&) = delete; Log& operator=(const Log&) = delete; @@ -104,11 +106,11 @@ class Log { switch(log.type) { - case INFO: alt::ICore::Instance().LogInfo(log.buf.str()); break; - case DEBUG: alt::ICore::Instance().LogDebug(log.buf.str().c_str()); break; - case WARNING: alt::ICore::Instance().LogWarning(log.buf.str().c_str()); break; - case ERR: alt::ICore::Instance().LogError(log.buf.str().c_str()); break; - case COLORED: alt::ICore::Instance().LogColored(log.buf.str().c_str()); break; + case INFO: alt::ICore::Instance().LogInfo(LOG_PREFIX, log.buf.str()); break; + case DEBUG: alt::ICore::Instance().LogDebug(LOG_PREFIX, log.buf.str().c_str()); break; + case WARNING: alt::ICore::Instance().LogWarning(LOG_PREFIX, log.buf.str().c_str()); break; + case ERR: alt::ICore::Instance().LogError(LOG_PREFIX, log.buf.str().c_str()); break; + case COLORED: alt::ICore::Instance().LogColored(LOG_PREFIX, log.buf.str().c_str()); break; } log.buf.str(""); From 9654df2c47b5e95291ca4b5a0cbddeed8f939e3e Mon Sep 17 00:00:00 2001 From: doxoh Date: Sat, 24 Aug 2024 19:38:03 +0200 Subject: [PATCH 02/10] ALTV-330 fix build --- {client/thirdparty => c-api}/Log.h | 2 +- c-api/core.h | 1 + client/src/coreclr/CoreClr.cpp | 2 +- client/src/coreclr/CoreClr.h | 12 ++++++------ client/src/coreclr/CoreClrValidation.cpp | 2 +- client/src/main.cpp | 2 +- client/src/nuget/NuGet.cpp | 2 +- client/src/runtime/CSharpResourceImpl.cpp | 2 +- client/src/runtime/CSharpScriptRuntime.cpp | 2 +- client/src/runtime/natives.cpp | 2 +- client/src/utils.h | 16 ++++++++-------- server/windows-build.bat | 2 ++ 12 files changed, 25 insertions(+), 22 deletions(-) rename {client/thirdparty => c-api}/Log.h (98%) create mode 100644 server/windows-build.bat diff --git a/client/thirdparty/Log.h b/c-api/Log.h similarity index 98% rename from client/thirdparty/Log.h rename to c-api/Log.h index 0d5e7a8..90bebe9 100644 --- a/client/thirdparty/Log.h +++ b/c-api/Log.h @@ -1,7 +1,7 @@ #pragma once #include -#include "cpp-sdk/ICore.h" +#include "../cpp-sdk/ICore.h" namespace cs { class Log diff --git a/c-api/core.h b/c-api/core.h index 60f63b2..7c40d66 100644 --- a/c-api/core.h +++ b/c-api/core.h @@ -13,6 +13,7 @@ #include "data/ped_model_info.h" #include "data/weapon_model_info.h" #include "utils/export.h" +#include "Log.h" #ifdef ALT_SERVER_API #include diff --git a/client/src/coreclr/CoreClr.cpp b/client/src/coreclr/CoreClr.cpp index c5a605d..fc3d6c1 100644 --- a/client/src/coreclr/CoreClr.cpp +++ b/client/src/coreclr/CoreClr.cpp @@ -6,12 +6,12 @@ #include #include #include -#include #include #include "utils.h" #include "../../c-api/client.h" #include "../../c-api/func_table.h" +#include "../../c-api/Log.h" using namespace alt; using namespace std; diff --git a/client/src/coreclr/CoreClr.h b/client/src/coreclr/CoreClr.h index 9c15743..acccde4 100644 --- a/client/src/coreclr/CoreClr.h +++ b/client/src/coreclr/CoreClr.h @@ -5,7 +5,7 @@ #include "cpp-sdk/ICore.h" #include #include -#include +#include <../../c-api/Log.h> #include #include "nuget/NuGet.h" @@ -20,12 +20,12 @@ struct Progress float total; float current; progressfn_t& updateFn; - + void Update() const { updateFn(state, current, total, 1000); } - + void Advance(float value) { current += value; @@ -63,7 +63,7 @@ class CoreClr { coreclr_shutdown_2_ptr _shutdownCoreClr = nullptr; coreclr_create_delegate_ptr _createDelegate = nullptr; coreclr_execute_assembly_ptr _executeAssembly = nullptr; - + void* _runtimeHost = nullptr; unsigned int _domainId = 0; std::optional _nuget; @@ -78,9 +78,9 @@ class CoreClr { void DownloadHost(alt::IHttpClient* httpClient, Progress& progress) const; void DownloadNuGet(alt::IHttpClient* httpClient, nlohmann::json json, Progress& progress); void DownloadNuGets(alt::IHttpClient* httpClient, progressfn_t& progress); - + void InitializeCoreclr(); void Update(progressfn_t progressFn, int attempt); - + std::string GetBaseCdnUrl() const; }; diff --git a/client/src/coreclr/CoreClrValidation.cpp b/client/src/coreclr/CoreClrValidation.cpp index 98e4887..ec94116 100644 --- a/client/src/coreclr/CoreClrValidation.cpp +++ b/client/src/coreclr/CoreClrValidation.cpp @@ -1,5 +1,5 @@ #include -#include +#include <../../c-api/Log.h> #include #include #include diff --git a/client/src/main.cpp b/client/src/main.cpp index 9eb0a5b..aa03396 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -5,7 +5,7 @@ #ifdef ALTV_CSHARP_SHARED #include "cpp-sdk/version/version.h" #endif -#include +#include <../../c-api/Log.h> using namespace alt; diff --git a/client/src/nuget/NuGet.cpp b/client/src/nuget/NuGet.cpp index e79b05d..9db8bce 100644 --- a/client/src/nuget/NuGet.cpp +++ b/client/src/nuget/NuGet.cpp @@ -1,6 +1,6 @@ #include "NuGet.h" -#include +#include <../../c-api/Log.h> #include "utils.h" diff --git a/client/src/runtime/CSharpResourceImpl.cpp b/client/src/runtime/CSharpResourceImpl.cpp index b9273a3..90f1376 100644 --- a/client/src/runtime/CSharpResourceImpl.cpp +++ b/client/src/runtime/CSharpResourceImpl.cpp @@ -3,7 +3,7 @@ #include #include "CSharpScriptRuntime.h" #include "CSharpResourceImpl.h" -#include +#include <../../c-api/Log.h> #include "CRC.h" #include #include diff --git a/client/src/runtime/CSharpScriptRuntime.cpp b/client/src/runtime/CSharpScriptRuntime.cpp index 40774f4..ff0a865 100644 --- a/client/src/runtime/CSharpScriptRuntime.cpp +++ b/client/src/runtime/CSharpScriptRuntime.cpp @@ -1,4 +1,4 @@ -#include +#include <../../c-api/Log.h> #include "CSharpScriptRuntime.h" #include "CSharpResourceImpl.h" #include "natives.h" diff --git a/client/src/runtime/natives.cpp b/client/src/runtime/natives.cpp index 977a650..960c9f3 100644 --- a/client/src/runtime/natives.cpp +++ b/client/src/runtime/natives.cpp @@ -5,7 +5,7 @@ #include "../../c-api/data/types.h" #include "../../c-api/data/function_table.h" #include "../../c-api/client.h" -#include "Log.h" +#include "../../c-api/Log.h" #include #include #include diff --git a/client/src/utils.h b/client/src/utils.h index a8d7228..1918ef8 100644 --- a/client/src/utils.h +++ b/client/src/utils.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include <../../c-api/Log.h> EXTERN_C IMAGE_DOS_HEADER __ImageBase; @@ -59,7 +59,7 @@ namespace utils std::char_traits::copy(returnStr, str, ulSize); return returnStr; } - + template T *get_clr_value(Args &&...args) { @@ -99,27 +99,27 @@ namespace utils std::transform(str.begin(), str.end(), str.begin(), [](const unsigned char c){ return std::tolower(c); }); return str; } - + inline alt::IHttpClient::HttpResponse download_file_sync(alt::IHttpClient* httpClient, const std::string& url) { auto attempt = 0; - + while (true) { if (++attempt > 5) throw std::runtime_error("Failed to download file " + url); - + std::promise promise; std::future future = promise.get_future(); - + httpClient->Get([](alt::IHttpClient::HttpResponse response, const void* data) { const auto innerPromise = (std::promise*) data; - + if (response.statusCode != 200) { std::stringstream ss; ss << "HTTP " << response.statusCode << " " << response.body; innerPromise->set_exception(std::make_exception_ptr(std::runtime_error(ss.str()))); return; } - + innerPromise->set_value(response); }, url, &promise); diff --git a/server/windows-build.bat b/server/windows-build.bat new file mode 100644 index 0000000..76e76cc --- /dev/null +++ b/server/windows-build.bat @@ -0,0 +1,2 @@ +cmake . -Bcmake-build-release +cmake --build cmake-build-release --config RelWithDebInfo \ No newline at end of file From adaa7be97a5742c9c99425ee0488c04e8f7bc973 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sat, 24 Aug 2024 19:39:24 +0200 Subject: [PATCH 03/10] ALTV-330 update submodule --- cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-sdk b/cpp-sdk index b1ced94..33a3a4c 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit b1ced94027a7b3c0c2167b12e45da80b49c8527b +Subproject commit 33a3a4c6d95c5f293a42c5b51d59c476829d2238 From 4c7a9ea128262b1c81ca9feb77e93f18a5e4b342 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sat, 24 Aug 2024 19:42:43 +0200 Subject: [PATCH 04/10] ALTV-330 add prefix to log --- server/src/CoreClr.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/server/src/CoreClr.cpp b/server/src/CoreClr.cpp index 69526a9..d5b6224 100644 --- a/server/src/CoreClr.cpp +++ b/server/src/CoreClr.cpp @@ -40,7 +40,7 @@ CoreClr::CoreClr(alt::ICore* core) int rc = get_hostfxr_path(buffer, &buffer_size, nullptr); if (rc != 0) { - core->LogError("invalid get_hostfxr_path " + std::to_string(rc)); + core->LogError(cs::Log::LOG_PREFIX, "invalid get_hostfxr_path " + std::to_string(rc)); } else { @@ -49,7 +49,7 @@ CoreClr::CoreClr(alt::ICore* core) _coreClrLib = LoadLibraryEx(std::string(bufferWString.begin(), bufferWString.end()).c_str(), nullptr, 0); if (_coreClrLib == nullptr) { - core->LogInfo(std::string("coreclr-module: Unable to find CoreCLR dll")); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Unable to find CoreCLR dll")); return; } @@ -77,7 +77,7 @@ CoreClr::CoreClr(alt::ICore* core) if (_initializeFxr == nullptr || _getDelegate == nullptr || _closeFxr == nullptr || _runApp == nullptr || _initForCmd == nullptr) { - core->LogInfo(std::string("coreclr-module: Unable to find CoreCLR dll methods")); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Unable to find CoreCLR dll methods")); return; } return; @@ -121,7 +121,7 @@ CoreClr::CoreClr(alt::ICore* core) delete[] fullPath; if (_coreClrLib == nullptr) { - core->LogInfo(std::string("coreclr-module: Unable to find CoreCLR dll")); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Unable to find CoreCLR dll")); return; } @@ -153,7 +153,7 @@ CoreClr::CoreClr(alt::ICore* core) if (_initializeFxr == nullptr || _getDelegate == nullptr || _closeFxr == nullptr || _runApp == nullptr || _initForCmd == nullptr) { - core->LogInfo(std::string("coreclr-module: Unable to find CoreCLR dll methods")); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Unable to find CoreCLR dll methods")); return; } } @@ -402,7 +402,7 @@ void CoreClr::GetPath(alt::ICore* core, const char* defaultPath) auto directory = opendir(defaultPath); if (directory == nullptr) { - core->LogInfo(std::string("coreclr-module: dotnet core sdk not found in ") + defaultPath); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: dotnet core sdk not found in ") + defaultPath); return; } struct dirent* entry; @@ -413,12 +413,12 @@ void CoreClr::GetPath(alt::ICore* core, const char* defaultPath) { if (entry->d_type == DT_DIR && memcmp(entry->d_name, ".", 1) != 0 && memcmp(entry->d_name, "..", 2) != 0) { - core->LogInfo(std::string("coreclr-module: version found: ") + entry->d_name); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: version found: ") + entry->d_name); if (greatest == nullptr) { if (semver_parse(entry->d_name, &greatest_version)) { - core->LogInfo(std::string("coreclr-module: invalid version found: ") + entry->d_name); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: invalid version found: ") + entry->d_name); continue; } greatest = entry->d_name; @@ -426,7 +426,7 @@ void CoreClr::GetPath(alt::ICore* core, const char* defaultPath) } if (semver_parse(entry->d_name, &compare_version)) { - core->LogInfo(std::string("coreclr-module: invalid version found: ") + entry->d_name); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: invalid version found: ") + entry->d_name); continue; } if (semver_compare(compare_version, greatest_version) > 0) @@ -452,14 +452,14 @@ void CoreClr::GetPath(alt::ICore* core, const char* defaultPath) } if (greatest == nullptr) { - core->LogInfo(std::string("coreclr-module: No dotnet sdk version found")); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: No dotnet sdk version found")); return; } else { semver_free(&greatest_version); } - core->LogInfo(std::string("coreclr-module: greatest version: ") + greatest); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: greatest version: ") + greatest); size_t size = strlen(defaultPath) + strlen(greatest) + 1; runtimeDirectory = (char*)malloc(size); memset(runtimeDirectory, '\0', size); @@ -520,7 +520,7 @@ void thread_proc(struct thread_user_data* userData) userData->closeFxr(userData->cxt); std::stringstream stream; stream << "Run App failed: " << std::hex << std::showbase << rc; - alt::ICore::Instance().LogError(stream.str()); + alt::ICore::Instance().LogError(cs::Log::LOG_PREFIX, stream.str()); } delete userData; } @@ -529,13 +529,13 @@ void CoreClr::GenerateRuntimeConfigText(std::ofstream* outfile) { if (version == nullptr) { - core->LogError("Unknown coreclr version"); + core->LogError(cs::Log::LOG_PREFIX, "Unknown coreclr version"); return; } semver_t sem_ver; if (semver_parse_version(version, &sem_ver) != 0) { - core->LogError("Couldn't parse coreclr version"); + core->LogError(cs::Log::LOG_PREFIX, "Couldn't parse coreclr version"); return; } auto minor_version = std::to_string(sem_ver.major) + std::string(".") + std::to_string(sem_ver.minor); @@ -592,12 +592,12 @@ void CoreClr::CreateManagedHost() { if (rc == 0x80008094) { - core->LogError( + core->LogError(cs::Log::LOG_PREFIX, "Make sure you have AltV.Net.Host.dll and AltV.Net.Host.runtimeconfig.json in the folder of the altv-server executable or binary."); } std::stringstream stream; stream << "Init for cmd failed: " << std::hex << std::showbase << rc; - core->LogError(stream.str()); + core->LogError(cs::Log::LOG_PREFIX, stream.str()); _closeFxr(cxt); if (result) { @@ -626,7 +626,7 @@ bool CoreClr::ExecuteManagedResource(const char* resourcePath, const char* resou while (hostResourceExecute == nullptr) { cv.wait(lck); } if (hostResourceExecute == nullptr) { - core->LogInfo(std::string("coreclr-module: Core CLR host not loaded")); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Core CLR host not loaded")); return false; } @@ -663,7 +663,7 @@ bool CoreClr::ExecuteManagedResourceUnload(const char* resourcePath, const char* while (hostResourceExecuteUnload == nullptr) { cv.wait(lck); } if (hostResourceExecuteUnload == nullptr) { - core->LogInfo(std::string("coreclr-module: Core CLR host not loaded")); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Core CLR host not loaded")); return false; } From f1a725546af4ac53ce2dc5958e70e0fd084f4198 Mon Sep 17 00:00:00 2001 From: doxoh Date: Sat, 24 Aug 2024 19:45:20 +0200 Subject: [PATCH 05/10] ALTV-330 fix more --- server/src/CoreClr.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/src/CoreClr.cpp b/server/src/CoreClr.cpp index d5b6224..288908d 100644 --- a/server/src/CoreClr.cpp +++ b/server/src/CoreClr.cpp @@ -63,7 +63,7 @@ CoreClr::CoreClr(alt::ICore* core) #else _coreClrLib = dlopen(std::string(buffer).c_str(), RTLD_NOW | RTLD_LOCAL); if (_coreClrLib == nullptr) { - core->LogInfo(std::string("coreclr-module: Unable to find CoreCLR dll [") + std::string(buffer) + "]: " + dlerror()); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Unable to find CoreCLR dll [") + std::string(buffer) + "]: " + dlerror()); return; } _initializeFxr = (hostfxr_initialize_for_runtime_config_fn) dlsym(_coreClrLib, @@ -139,7 +139,7 @@ CoreClr::CoreClr(alt::ICore* core) strcat(fullPath, fileName); _coreClrLib = dlopen(fullPath, RTLD_NOW | RTLD_LOCAL); if (_coreClrLib == nullptr) { - core->LogInfo(std::string("coreclr-module: Unable to find CoreCLR dll [") + fullPath + "]: " + dlerror()); + core->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Unable to find CoreCLR dll [") + fullPath + "]: " + dlerror()); return; } _initializeFxr = (hostfxr_initialize_for_runtime_config_fn) dlsym(_coreClrLib, @@ -181,7 +181,7 @@ CoreClr::~CoreClr() /*bool CoreClr::GetDelegate(alt::ICore* core, void* runtimeHost, unsigned int domainId, const char* moduleName, const char* classPath, const char* methodName, void** callback) { if (runtimeHost == nullptr || domainId == 0) { - server->LogInfo(std::string("coreclr-module: Core CLR host not loaded")); + server->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Core CLR host not loaded")); return false; } int result = _createDelegate(runtimeHost, domainId, moduleName, classPath, methodName, callback); @@ -189,7 +189,7 @@ CoreClr::~CoreClr() if (this->PrintError(server, result)) { return false; } - server->LogInfo( + server->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Unable to get ") + moduleName + ":" + classPath + "." + methodName + " domain:" + domainId); @@ -208,10 +208,10 @@ CoreClr::~CoreClr() for (auto path : directories) { auto directory = opendir(path); if (directory == nullptr) { - server->LogInfo(std::string("coreclr-module: Runtime directory not found")); + server->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Runtime directory not found")); return assemblies; } - server->LogInfo(std::string("coreclr-module: Runtime directory found")); + server->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Runtime directory found")); struct dirent* entry; struct stat sb{}; for (auto ext : tpaExtensions) { @@ -248,7 +248,7 @@ CoreClr::~CoreClr() // Check if the extension matches the one we are looking for size_t extPos = strlen(entry->d_name) - extLength; - //server->LogInfo(std::string(ext) + "," + extLength + "," + entry->d_name); + //server->LogInfo(cs::Log::LOG_PREFIX, std::string(ext) + "," + extLength + "," + entry->d_name); if (extPos <= 0 || memcmp(ext, entry->d_name + extPos, extLength) != 0) { continue; } @@ -315,7 +315,7 @@ CoreClr::~CoreClr() domainId); if (result < 0) { - server->LogInfo(std::string("coreclr-module: Unable to create app domain: 0x")); + server->LogInfo(cs::Log::LOG_PREFIX, std::string("coreclr-module: Unable to create app domain: 0x")); this->PrintError(server, result); } else { server->LogInfo(std::string("coreclr-module: Created app domain: 0x") + appPath); From 92a8a5ea90dbc2bba217e40fff8b536130cac091 Mon Sep 17 00:00:00 2001 From: Till Schreiber Date: Tue, 10 Sep 2024 08:32:52 +0200 Subject: [PATCH 06/10] chore: update sdk --- cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-sdk b/cpp-sdk index 33a3a4c..b782525 160000 --- a/cpp-sdk +++ b/cpp-sdk @@ -1 +1 @@ -Subproject commit 33a3a4c6d95c5f293a42c5b51d59c476829d2238 +Subproject commit b7825258fafcb6d9aa3906b41e27cfe2d8bf93af From 8a6dcc7a02ee5b404a29616c125cab4ca404f540 Mon Sep 17 00:00:00 2001 From: Till Schreiber Date: Tue, 10 Sep 2024 12:39:23 +0200 Subject: [PATCH 07/10] fix sdk build --- c-api/Log.h | 2 +- client/CMakeLists.txt | 36 +++++++++++++++++++++++++++++----- client/tools/deinit-cppsdk.bat | 6 ++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 client/tools/deinit-cppsdk.bat diff --git a/c-api/Log.h b/c-api/Log.h index 90bebe9..0d5e7a8 100644 --- a/c-api/Log.h +++ b/c-api/Log.h @@ -1,7 +1,7 @@ #pragma once #include -#include "../cpp-sdk/ICore.h" +#include "cpp-sdk/ICore.h" namespace cs { class Log diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 755f02e..e1cc53a 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -25,6 +25,13 @@ set(CSHARP_MODULE_DEFS # -DDEBUG_CLIENT ) +# cpp-sdk +if(NOT ALTV_CSHARP_CPP_SDK) + set(ALTV_CSHARP_CPP_SDK ../) +else() + set(ALTV_CSHARP_DEINIT_CPPSDK 1) +endif() + file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.cpp") file(GLOB_RECURSE CAPI_FILES "../c-api/*.h" "../c-api/*.cpp") @@ -32,22 +39,41 @@ if(WIN32 AND (MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")) add_definitions(/MP) endif() -if(DYNAMIC_BUILD) - set(SDK_PROJECT_NAME csharp-alt-sdk) - include(../cpp-sdk/CMakeLists.txt) +set(SDK_PROJECT_NAME alt-sdk-csharp) +if(NOT TARGET ${SDK_PROJECT_NAME}) + include(${ALTV_CSHARP_CPP_SDK}/cpp-sdk/CMakeLists.txt) +endif() +if(DYNAMIC_BUILD) add_library(${TARGET_NAME} SHARED "${PROJECT_SOURCE_FILES}" "${CAPI_FILES}") target_compile_definitions(${PROJECT_NAME} PRIVATE ${CSHARP_MODULE_DEFS} -DALTV_CSHARP_SHARED ) include_directories(${TARGET_NAME} PRIVATE "src" "thirdparty" "..") - add_dependencies(${TARGET_NAME} csharp-alt-sdk) else() add_library(${TARGET_NAME}-static STATIC "${PROJECT_SOURCE_FILES}" "${CAPI_FILES}") target_compile_definitions(${PROJECT_NAME}-static PRIVATE ${CSHARP_MODULE_DEFS} ) include_directories(${TARGET_NAME}-static PRIVATE "src" "thirdparty" ${ALTV_CSHARP_CPP_SDK}) - # add_dependencies(${TARGET_NAME}-static csharp-alt-sdk) +endif() + + +if(ALTV_CSHARP_DEINIT_CPPSDK) + if(CMAKE_HOST_WIN32) + add_custom_command(TARGET ${PROJECT_NAME}-static + PRE_BUILD + COMMAND cmd /C "tools\\deinit-cppsdk.bat" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + else() + if(EXISTS "../cpp-sdk/SDK.h") + add_custom_command(TARGET ${PROJECT_NAME}-static + PRE_BUILD + COMMAND "git submodule deinit -f ../cpp-sdk" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + endif() + endif() endif() diff --git a/client/tools/deinit-cppsdk.bat b/client/tools/deinit-cppsdk.bat new file mode 100644 index 0000000..dfdcfb1 --- /dev/null +++ b/client/tools/deinit-cppsdk.bat @@ -0,0 +1,6 @@ +@echo off + +if EXIST ../cpp-sdk/SDK.h ( + echo alt:V C# - Using external cpp-sdk, deiniting local cpp-sdk + git submodule deinit -f ../cpp-sdk +) From 4837f367eef832e7f6d73b12cc6f2e5437753974 Mon Sep 17 00:00:00 2001 From: Till Schreiber Date: Sun, 15 Sep 2024 14:42:40 +0200 Subject: [PATCH 08/10] fix(client): fix rmlelement crash --- client/src/runtime/CSharpResourceImpl.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/client/src/runtime/CSharpResourceImpl.cpp b/client/src/runtime/CSharpResourceImpl.cpp index 90f1376..30902e1 100644 --- a/client/src/runtime/CSharpResourceImpl.cpp +++ b/client/src/runtime/CSharpResourceImpl.cpp @@ -696,12 +696,6 @@ void CSharpResourceImpl::OnCreateBaseObject(alt::IBaseObject* object) OnCreateBaseObjectDelegate(audioFilter, audioFilter->GetType(), audioFilter->GetID()); break; } - case alt::IBaseObject::Type::RML_ELEMENT: - { - auto rmlElement = dynamic_cast(object); - OnCreateBaseObjectDelegate(rmlElement, rmlElement->GetType(), rmlElement->GetID()); - break; - } case alt::IBaseObject::Type::RML_DOCUMENT: { auto rmlDocument = dynamic_cast(object); From 2e895b5904b1d0b7b064344798ea8acada02abf3 Mon Sep 17 00:00:00 2001 From: Till Schreiber Date: Mon, 30 Sep 2024 08:46:46 +0200 Subject: [PATCH 09/10] fix build --- client/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index e1cc53a..ad135e4 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -51,6 +51,7 @@ if(DYNAMIC_BUILD) -DALTV_CSHARP_SHARED ) include_directories(${TARGET_NAME} PRIVATE "src" "thirdparty" "..") + add_dependencies(${TARGET_NAME} alt-sdk-csharp) else() add_library(${TARGET_NAME}-static STATIC "${PROJECT_SOURCE_FILES}" "${CAPI_FILES}") target_compile_definitions(${PROJECT_NAME}-static PRIVATE From 98abdcaa4a604e9528fb9b772e2d7532db21970d Mon Sep 17 00:00:00 2001 From: Till Schreiber Date: Mon, 30 Sep 2024 08:59:11 +0200 Subject: [PATCH 10/10] Feat/dotnet8 (#157) * chore: bump to dotnet8 * fix(client): load correct dotnet version * fix(client): fix some errors for downloading required files --- client/src/coreclr/CoreClr.cpp | 2 +- download_dotnet.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/coreclr/CoreClr.cpp b/client/src/coreclr/CoreClr.cpp index fc3d6c1..abd0714 100644 --- a/client/src/coreclr/CoreClr.cpp +++ b/client/src/coreclr/CoreClr.cpp @@ -193,7 +193,7 @@ uint8_t GetCachedAssembly(const char* name, int* bufferSize, void** buffer) { auto stream = std::ifstream(path, std::ios::binary); miniz_cpp::zip_file zip(stream); std::stringstream contentStream; - auto fileName = std::string("lib/net6.0/") + name + ".dll"; + auto fileName = std::string("lib/net8.0/") + name + ".dll"; if (!zip.has_file(fileName)) { cs::Log::Warning << "Nupkg was found, but no dll was found in it " << fileName << cs::Log::Endl; zip.printdir(); diff --git a/download_dotnet.ps1 b/download_dotnet.ps1 index 2fa8edd..88f9d2f 100644 --- a/download_dotnet.ps1 +++ b/download_dotnet.ps1 @@ -10,7 +10,7 @@ $start = $pwd cd $path -$dotnetRelease = Invoke-WebRequest 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/6.0/releases.json' | ConvertFrom-Json +$dotnetRelease = Invoke-WebRequest 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json' | ConvertFrom-Json $dotnetVersion = $dotnetRelease."latest-release"