Skip to content

Commit

Permalink
Merge branch 'rc' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Oct 15, 2024
2 parents 69f6249 + 7a55cb9 commit 0597eb7
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 72 deletions.
12 changes: 7 additions & 5 deletions client/thirdparty/Log.h → c-api/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("");
Expand Down
12 changes: 6 additions & 6 deletions c-api/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
}

Expand Down
1 change: 1 addition & 0 deletions c-api/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CSharpResourceImpl.h>
Expand Down
37 changes: 32 additions & 5 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,56 @@ 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")

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)
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
${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()
4 changes: 2 additions & 2 deletions client/src/coreclr/CoreClr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <sstream>
#include <filesystem>
#include <fstream>
#include <Log.h>
#include <zip_file.hpp>

#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;
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions client/src/coreclr/CoreClr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "cpp-sdk/ICore.h"
#include <coreclr.h>
#include <filesystem>
#include <Log.h>
#include <../../c-api/Log.h>
#include <optional>

#include "nuget/NuGet.h"
Expand All @@ -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;
Expand Down Expand Up @@ -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> _nuget;
Expand All @@ -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;
};
2 changes: 1 addition & 1 deletion client/src/coreclr/CoreClrValidation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <json.hpp>
#include <Log.h>
#include <../../c-api/Log.h>
#include <sha1.hpp>
#include <sha512.hpp>
#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion client/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifdef ALTV_CSHARP_SHARED
#include "cpp-sdk/version/version.h"
#endif
#include <Log.h>
#include <../../c-api/Log.h>

using namespace alt;

Expand Down
2 changes: 1 addition & 1 deletion client/src/nuget/NuGet.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "NuGet.h"

#include <Log.h>
#include <../../c-api/Log.h>

#include "utils.h"

Expand Down
8 changes: 1 addition & 7 deletions client/src/runtime/CSharpResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <vector>
#include "CSharpScriptRuntime.h"
#include "CSharpResourceImpl.h"
#include <Log.h>
#include <../../c-api/Log.h>
#include "CRC.h"
#include <sstream>
#include <string>
Expand Down Expand Up @@ -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<alt::IRmlElement*>(object);
OnCreateBaseObjectDelegate(rmlElement, rmlElement->GetType(), rmlElement->GetID());
break;
}
case alt::IBaseObject::Type::RML_DOCUMENT:
{
auto rmlDocument = dynamic_cast<alt::IRmlDocument*>(object);
Expand Down
2 changes: 1 addition & 1 deletion client/src/runtime/CSharpScriptRuntime.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Log.h>
#include <../../c-api/Log.h>
#include "CSharpScriptRuntime.h"
#include "CSharpResourceImpl.h"
#include "natives.h"
Expand Down
2 changes: 1 addition & 1 deletion client/src/runtime/natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstring>
#include <type_traits>
#include <stdlib.h>
Expand Down
16 changes: 8 additions & 8 deletions client/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <codecvt>
#include <future>
#include <Log.h>
#include <../../c-api/Log.h>

EXTERN_C IMAGE_DOS_HEADER __ImageBase;

Expand Down Expand Up @@ -59,7 +59,7 @@ namespace utils
std::char_traits<T>::copy(returnStr, str, ulSize);
return returnStr;
}

template <typename T, typename... Args>
T *get_clr_value(Args &&...args)
{
Expand Down Expand Up @@ -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<alt::IHttpClient::HttpResponse> promise;
std::future<alt::IHttpClient::HttpResponse> future = promise.get_future();

httpClient->Get([](alt::IHttpClient::HttpResponse response, const void* data) {
const auto innerPromise = (std::promise<alt::IHttpClient::HttpResponse>*) 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);

Expand Down
6 changes: 6 additions & 0 deletions client/tools/deinit-cppsdk.bat
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion cpp-sdk
Submodule cpp-sdk updated 2 files
+5 −5 ICore.h
+6 −1 objects/IEntity.h
2 changes: 1 addition & 1 deletion download_dotnet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading

0 comments on commit 0597eb7

Please sign in to comment.