Skip to content

Commit

Permalink
Merge branch 'main' into modded-postload
Browse files Browse the repository at this point in the history
  • Loading branch information
ASpoonPlaysGames authored Aug 25, 2023
2 parents 2a999fd + 07e76e3 commit 3619b98
Show file tree
Hide file tree
Showing 340 changed files with 939 additions and 70,456 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Setup msvc
uses: ilammy/msvc-dev-cmd@v1
- name: Configure cmake
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Setup msvc
uses: ilammy/msvc-dev-cmd@v1
- name: Configure cmake
Expand Down
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[submodule "thirdparty/libcurl"]
path = thirdparty/libcurl
url = https://github.com/curl/curl
ignore = untracked
[submodule "thirdparty/minhook"]
path = thirdparty/minhook
url = https://github.com/TsudaKageyu/minhook
ignore = untracked
9 changes: 4 additions & 5 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ The following steps will allow you to compile your own NorthstarLauncher executa
*This guide assumes you have already installed Northstar as shown in [this page](https://r2northstar.gitbook.io/r2northstar-wiki/installing-northstar/basic-setup)*

### Steps
1. **Download the code** from the [R2Northstar/NorthstarLauncher](https://github.com/R2Northstar/NorthstarLauncher) repo
2. **Unzip the file.**
3. **Place the file somewhere memorable,** such as in your Documents directory
4. **Install Visual Studio 2022** from [this link](https://visualstudio.microsoft.com/downloads/). Northstar uses the vc2022 compiler, which is provided with Visual Studio. *You only need to download the Community edition.*
5. If you are prompted to download Workloads, check "Desktop Development with C++" If you are not prompted, don't worry, you'll be able to install this later on as well.
1. **Install Git** from [this link](https://git-scm.com)
2. **Clone** the [R2Northstar/NorthstarLauncher](https://github.com/R2Northstar/NorthstarLauncher) repo with submodules using this command `git clone --recurse-submodules https://github.com/R2Northstar/NorthstarLauncher.git`
3. **Install Visual Studio 2022** from [this link](https://visualstudio.microsoft.com/downloads/). Northstar uses the vc2022 compiler, which is provided with Visual Studio. *You only need to download the Community edition.*
4. If you are prompted to download Workloads, check "Desktop Development with C++" If you are not prompted, don't worry, you'll be able to install this later on as well.

![Desktop Development Workload](https://user-images.githubusercontent.com/40443620/147722260-b6ec90e9-7b74-4fb7-b512-680c039afaef.png)

Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.15)

project(Northstar CXX ASM_MASM)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()

# Language specs
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)
Expand All @@ -16,7 +21,11 @@ set(NS_BINARY_DIR ${CMAKE_BINARY_DIR}/game)
# and then link binaries in ${CMAKE_BINARY_DIR}/game. This means you can copy your
# game into ${CMAKE_BINARY_DIR}/game without it being cluttered up by cmake files.

message("NS: Building to ${NS_BINARY_DIR}")
message(STATUS "NS: Building to ${NS_BINARY_DIR}")


list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(utils)

# Targets
add_subdirectory(loader_wsock32_proxy)
Expand Down
10 changes: 8 additions & 2 deletions NorthstarDLL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# NorthstarDLL

find_package(minhook REQUIRED)
find_package(libcurl REQUIRED)

add_library(NorthstarDLL SHARED
"client/audio.cpp"
"client/audio.h"
Expand Down Expand Up @@ -75,6 +78,8 @@ add_library(NorthstarDLL SHARED
"mods/compiled/modscriptsrson.cpp"
"mods/modmanager.cpp"
"mods/modmanager.h"
"mods/modsavefiles.cpp"
"mods/modsavefiles.h"
"plugins/plugin_abi.h"
"plugins/pluginbackend.cpp"
"plugins/pluginbackend.h"
Expand All @@ -94,6 +99,7 @@ add_library(NorthstarDLL SHARED
"scripts/scripthttprequesthandler.cpp"
"scripts/scripthttprequesthandler.h"
"scripts/scriptjson.cpp"
"scripts/scriptjson.h"
"scripts/scriptutility.cpp"
"server/auth/bansystem.cpp"
"server/auth/bansystem.h"
Expand Down Expand Up @@ -146,8 +152,8 @@ add_library(NorthstarDLL SHARED
)

target_link_libraries(NorthstarDLL PRIVATE
${CMAKE_SOURCE_DIR}/thirdparty/minhook/MinHook.x64.lib
${CMAKE_SOURCE_DIR}/thirdparty/libcurl/lib/libcurl_a.lib
minhook
libcurl
WS2_32.lib
Crypt32.lib
Cryptui.lib
Expand Down
14 changes: 1 addition & 13 deletions NorthstarDLL/core/filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,7 @@ OFFSET_STRUCT(VPKFileEntry)
// clang-format on
#pragma pack(pop)

#pragma pack(push, 1)
// clang-format off
struct VPKData
{
STRUCT_SIZE(0x50);
FIELDS(0x0,
char* directory;
char* filename;
char* extension;
)
};
// clang-format on
#pragma pack(pop)
struct VPKData;

enum SearchPathAdd_t
{
Expand Down
7 changes: 0 additions & 7 deletions NorthstarDLL/core/math/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ union Vector3

float raw[3];

Vector3() : x(0), y(0), z(0) {}
Vector3(float x, float y, float z) : x(x), y(y), z(z) {}
Vector3(float* pRawFloats) // assumes float[3] => vector
{
memcpy(raw, pRawFloats, sizeof(this));
}

void MakeValid()
{
for (auto& fl : raw)
Expand Down
1 change: 0 additions & 1 deletion NorthstarDLL/dedicated/dedicatedlogtoclient.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "pch.h"
#include "dedicatedlogtoclient.h"
#include "engine/r2engine.h"

Expand Down
4 changes: 1 addition & 3 deletions NorthstarDLL/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ bool InitialiseNorthstar()
InitialiseCrashHandler();

// Write launcher version to log
spdlog::info("NorthstarLauncher version: {}", version);
spdlog::info("Command line: {}", GetCommandLineA());
spdlog::info("Using profile: {}", GetNorthstarPrefix());
StartupLog();

InstallInitialHooks();

Expand Down
70 changes: 70 additions & 0 deletions NorthstarDLL/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
#include "core/convar/concommand.h"
#include "config/profile.h"
#include "core/tier0.h"
#include "util/version.h"
#include "spdlog/sinks/basic_file_sink.h"

#include <winternl.h>
#include <cstdlib>
#include <iomanip>
#include <sstream>

Expand Down Expand Up @@ -220,3 +223,70 @@ void NS::log::FlushLoggers()

spdlog::default_logger()->flush();
}

// Wine specific functions
typedef const char*(CDECL* wine_get_host_version_type)(const char**, const char**);
wine_get_host_version_type wine_get_host_version;

typedef const char*(CDECL* wine_get_build_id_type)(void);
wine_get_build_id_type wine_get_build_id;

// Not exported Winapi methods
typedef NTSTATUS(WINAPI* RtlGetVersion_type)(PRTL_OSVERSIONINFOW);
RtlGetVersion_type RtlGetVersion;

void StartupLog()
{
spdlog::info("NorthstarLauncher version: {}", version);
spdlog::info("Command line: {}", GetCommandLineA());
spdlog::info("Using profile: {}", GetNorthstarPrefix());

HMODULE ntdll = GetModuleHandleA("ntdll.dll");
if (!ntdll)
{
// How did we get here
spdlog::info("Operating System: Unknown");
return;
}

wine_get_host_version = (wine_get_host_version_type)GetProcAddress(ntdll, "wine_get_host_version");
if (wine_get_host_version)
{
// Load the rest of the functions we need
wine_get_build_id = (wine_get_build_id_type)GetProcAddress(ntdll, "wine_get_build_id");

const char* sysname;
wine_get_host_version(&sysname, NULL);

spdlog::info("Operating System: {} (Wine)", sysname);
spdlog::info("Wine build: {}", wine_get_build_id());

char* compatToolPtr = std::getenv("STEAM_COMPAT_TOOL_PATHS");
if (compatToolPtr)
{
std::string compatToolPath(compatToolPtr);

spdlog::info("Proton build: {}", compatToolPath.substr(compatToolPath.rfind("/") + 1));
}
}
else
{
// We are real Windows (hopefully)
const char* win_ver = "Unknown";

RTL_OSVERSIONINFOW osvi;
osvi.dwOSVersionInfoSize = sizeof(osvi);

RtlGetVersion = (RtlGetVersion_type)GetProcAddress(ntdll, "RtlGetVersion");
if (RtlGetVersion && !RtlGetVersion(&osvi))
{
// Version reference table
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoa#remarks
spdlog::info("Operating System: Windows (NT{}.{})", osvi.dwMajorVersion, osvi.dwMinorVersion);
}
else
{
spdlog::info("Operating System: Windows");
}
}
}
1 change: 1 addition & 0 deletions NorthstarDLL/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
void CreateLogFiles();
void InitialiseLogging();
void InitialiseConsole();
void StartupLog();

class ColoredLogger;

Expand Down
31 changes: 31 additions & 0 deletions NorthstarDLL/mods/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string>
#include <sstream>
#include <vector>
#include <regex>

ModManager* g_pModManager;

Expand Down Expand Up @@ -587,6 +588,7 @@ void ModManager::LoadMods()
// ensure dirs exist
fs::remove_all(GetCompiledAssetsPath());
fs::create_directories(GetModFolderPath());
fs::create_directories(GetThunderstoreModFolderPath());
fs::create_directories(GetRemoteModFolderPath());

m_DependencyConstants.clear();
Expand Down Expand Up @@ -616,6 +618,31 @@ void ModManager::LoadMods()
if (fs::exists(dir.path() / "mod.json"))
modDirs.push_back(dir.path());

// Special case for Thunderstore mods dir
std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreModFolderPath());
// Set up regex for `AUTHOR-MOD-VERSION` pattern
std::regex pattern(R"(.*\\([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)-(\d+\.\d+\.\d+))");
for (fs::directory_entry dir : thunderstoreModsDir)
{
fs::path modsDir = dir.path() / "mods"; // Check for mods folder in the Thunderstore mod
// Use regex to match `AUTHOR-MOD-VERSION` pattern
if (!std::regex_match(dir.path().string(), pattern))
{
spdlog::warn("The following directory did not match 'AUTHOR-MOD-VERSION': {}", dir.path().string());
continue; // skip loading mod that doesn't match
}
if (fs::exists(modsDir) && fs::is_directory(modsDir))
{
for (fs::directory_entry subDir : fs::directory_iterator(modsDir))
{
if (fs::exists(subDir.path() / "mod.json"))
{
modDirs.push_back(subDir.path());
}
}
}
}

for (fs::path modDir : modDirs)
{
// read mod json file
Expand Down Expand Up @@ -1049,6 +1076,10 @@ fs::path GetModFolderPath()
{
return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX);
}
fs::path GetThunderstoreModFolderPath()
{
return fs::path(GetNorthstarPrefix() + THUNDERSTORE_MOD_FOLDER_SUFFIX);
}
fs::path GetRemoteModFolderPath()
{
return fs::path(GetNorthstarPrefix() + REMOTE_MOD_FOLDER_SUFFIX);
Expand Down
8 changes: 5 additions & 3 deletions NorthstarDLL/mods/modmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <vector>
#include <filesystem>

const std::string MOD_FOLDER_SUFFIX = "/mods";
const std::string REMOTE_MOD_FOLDER_SUFFIX = "/runtime/remote/mods";
const std::string MOD_FOLDER_SUFFIX = "\\mods";
const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "\\packages";
const std::string REMOTE_MOD_FOLDER_SUFFIX = "\\runtime\\remote\\mods";
const fs::path MOD_OVERRIDE_DIR = "mod";
const std::string COMPILED_ASSETS_SUFFIX = "/runtime/compiled";
const std::string COMPILED_ASSETS_SUFFIX = "\\runtime\\compiled";

const std::set<std::string> MODS_BLACKLIST = {"Mod Settings"};

Expand Down Expand Up @@ -176,6 +177,7 @@ class ModManager

fs::path GetModFolderPath();
fs::path GetRemoteModFolderPath();
fs::path GetThunderstoreModFolderPath();
fs::path GetCompiledAssetsPath();

extern ModManager* g_pModManager;
Loading

0 comments on commit 3619b98

Please sign in to comment.