Skip to content

Commit

Permalink
CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tashcan committed Jan 7, 2024
1 parent d90492b commit e677e33
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 11 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and test

Check failure on line 1 in .github/workflows/ci.yaml

View workflow job for this annotation

GitHub Actions / build

.github/workflows/ci.yaml#L1

This run was manually canceled.

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Configure CMake
run: cmake -B build -S ${{ github.workspace }}

- name: Build
run: cmake --build build --target stfc-community-patch -j --config Release

- name: Package
run: |
mv build/Release/stfc-community-patch.dll version.dll
- uses: actions/upload-artifact@v2
with:
name: stfc-community-patch
path: version.dll
53 changes: 53 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
push:
tags:
- "v*"

name: Create Release

jobs:
deploy:
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
name: Create Release
runs-on: windows-2022
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
Changes in this Release
- First Change
- Second Change
draft: true
prerelease: false

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: ci.yaml
workflow_conclusion: success

- name: Package
run: |
tar -c -a -f stfc-community-patch.zip -C stfc-community-patch *.dll
- name: Upload Community Patch
id: upload-patch
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./stfc-community-patch.zip
asset_name: stfc-community-patch.zip
asset_content_type: application/zip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
out/
build/
*.code-workspace
/.cache/
compile_commands.json
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.11)
project(STFC-Community-Patch)
set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /W4 /permissive- /bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /W4 /permissive- /bigobj /await")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

# Windows' math include does not define constants by default.
Expand Down Expand Up @@ -100,7 +100,7 @@ SET(PATCHES

file(GLOB_RECURSE PRIME src/prime/*.cc src/prime/*.h)

add_library(stfc-communty-patch SHARED ${TARGET_SRC} ${PATCHES} ${PRIME}
add_library(stfc-community-patch SHARED ${TARGET_SRC} ${PATCHES} ${PRIME}
src/version.def
"src/il2cpp/il2cpp_helper.h"
"src/prime/TabBarViewController.h"
Expand All @@ -117,14 +117,14 @@ add_library(stfc-communty-patch SHARED ${TARGET_SRC} ${PATCHES} ${PRIME}
"src/prime/IEnumerator.h"
"src/prime/LanguageManager.h")

set_property(TARGET stfc-communty-patch PROPERTY CXX_STANDARD 20)
set_property(TARGET stfc-communty-patch PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET stfc-community-patch PROPERTY CXX_STANDARD 20)
set_property(TARGET stfc-community-patch PROPERTY CXX_STANDARD_REQUIRED ON)

target_sources(stfc-communty-patch PRIVATE src/version.rc)
target_sources(stfc-community-patch PRIVATE src/version.rc)

include_directories(stfc-communty-patch third_party src src/patches third_party/xorstr/include ${Protobuf_INCLUDE_DIRS})
include_directories(stfc-community-patch third_party src src/patches third_party/xorstr/include ${Protobuf_INCLUDE_DIRS})

add_dependencies(stfc-communty-patch EASTL)
target_link_libraries(stfc-communty-patch PRIVATE spud nlohmann_json::nlohmann_json protobuf::libprotobuf tomlplusplus_tomlplusplus absl::base absl::synchronization absl::strings spdlog EASTL)
add_dependencies(stfc-community-patch EASTL)
target_link_libraries(stfc-community-patch PRIVATE spud nlohmann_json::nlohmann_json protobuf::libprotobuf tomlplusplus_tomlplusplus absl::base absl::synchronization absl::strings spdlog EASTL)

add_subdirectory(third_party)
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ This will download three submodules and further submodules that they have, so th

## Installing

Please note that when this project compiles, it will create a DLL called `stfc-communty-patch.dll`. This
Please note that when this project compiles, it will create a DLL called `stfc-community-patch.dll`. This
file must be either copied to the `C:\Games\Star Trek Fleet Command\Star Trek Fleet Command\default\game`
folder as `version.dll` or create a symbolic link to the file using an elevated (administrator) command
prompt:

```console
cd C:\Games\Star Trek Fleet Command\Star Trek Fleet Command\default\game
mklink [output folder]\stfc-communty-patch.dll version.dll
mklink [output folder]\stfc-community-patch.dll version.dll
```

If you do link the file, please note you will need to close the game to recompile.
Expand Down Expand Up @@ -63,7 +63,7 @@ Create or enter the `.vs/` folder and place the following in `launch.vs.json`:
"type": "default",
"exe": "C:\\Games\\Star Trek Fleet Command\\Star Trek Fleet Command\\default\\game\\prime.exe",
"project": "CMakeLists.txt",
"projectTarget": "stfc-communty-patch.dll",
"projectTarget": "stfc-community-patch.dll",
"name": "Prime",
"cwd": "C:\\Games\\Star Trek Fleet Command\\Star Trek Fleet Command\\default\\game"
}
Expand Down
3 changes: 3 additions & 0 deletions src/patches/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ void Config::Load()
std::string disabled_banner_types_str =
get_config_or_default<std::string>(config, parsed, "ui", "disabled_banner_types", "");

this->config_settings_url = get_config_or_default<std::string>(config, parsed, "config", "settings_url", "");
this->config_assets_url_override = get_config_or_default<std::string>(config, parsed, "config", "assets_url_override", "");

std::vector<std::string> types = absl::StrSplit(disabled_banner_types_str, ",", absl::SkipWhitespace());

std::string bannerString = "";
Expand Down
3 changes: 3 additions & 0 deletions src/patches/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ class Config
bool sync_traits;
bool sync_buildings;
bool sync_ships;

std::string config_settings_url;
std::string config_assets_url_override;
};
115 changes: 115 additions & 0 deletions src/patches/parts/testing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <spud/detour.h>

#include "config.h"
#include "utils.h"

#include "prime/BlurController.h"
Expand Down Expand Up @@ -118,8 +119,122 @@ void Chat_handleNewMessage(void* _this, Il2CppString* message)
// original(_this, message);
}

class AppConfig
{
public:
__declspec(property(get = __get_PlatformSettingsUrl,
put = __set_PlatformSettingsUrl)) Il2CppString* PlatformSettingsUrl;
__declspec(property(get = __get_PlatformApiKey, put = __set_PlatformApiKey)) Il2CppString* PlatformApiKey;
__declspec(property(get = __get_AssetUrlOverride, put = __set_AssetUrlOverride)) Il2CppString* AssetUrlOverride;

private:
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper = il2cpp_get_class_helper("Assembly-CSharp", "Digit.Client.Core", "AppConfig");
return class_helper;
}

public:
Il2CppString* __get_PlatformSettingsUrl()
{
static auto prop = get_class_helper().GetProperty("PlatformSettingsUrl");
return prop.GetRaw<Il2CppString>((void*)this);
}

void __set_PlatformSettingsUrl(Il2CppString* v)
{
static auto prop = get_class_helper().GetProperty("PlatformSettingsUrl");
return prop.SetRaw((void*)this, *v);
}

Il2CppString* __get_PlatformApiKey()
{
static auto prop = get_class_helper().GetProperty("PlatformApiKey");
return prop.GetRaw<Il2CppString>((void*)this);
}

void __set_PlatformApiKey(Il2CppString* v)
{
static auto prop = get_class_helper().GetProperty("PlatformApiKey");
return prop.SetRaw((void*)this, *v);
}

Il2CppString* __get_AssetUrlOverride()
{
static auto prop = get_class_helper().GetProperty("AssetUrlOverride");
return prop.GetRaw<Il2CppString>((void*)this);
}

void __set_AssetUrlOverride(Il2CppString* v)
{
static auto prop = get_class_helper().GetProperty("AssetUrlOverride");
return prop.SetRaw((void*)this, *v);
}
};

class Model
{
public:
__declspec(property(get = __get_AppConfig)) AppConfig* AppConfig_;

private:
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper = il2cpp_get_class_helper("Assembly-CSharp", "Digit.Client.Core", "Model");
return class_helper;
}

public:
AppConfig* __get_AppConfig()
{
static auto field = get_class_helper().GetField("_appConfig");
return *(AppConfig**)((ptrdiff_t)this + field.offset());
}
};

void* AppConfig_LoadConfig(auto original)
{
auto app_config = original();
return app_config;
}

AppConfig* Model_LoadConfigs(auto original, Model* _this)
{
original(_this);
auto config = _this->AppConfig_;

static auto il2cpp_string_new_utf16 = (il2cpp_string_new_utf16_t)(GetProcAddress(
GetModuleHandle(xorstr_("GameAssembly.dll")), xorstr_("il2cpp_string_new_utf16")));
static auto il2cpp_string_new =
(il2cpp_string_new_t)(GetProcAddress(GetModuleHandle(xorstr_("GameAssembly.dll")), xorstr_("il2cpp_string_new")));

if (!Config::Get().config_settings_url.empty()) {
auto new_settings_url = il2cpp_string_new(Config::Get().config_settings_url.c_str());
config->PlatformSettingsUrl = new_settings_url;
}

if (!Config::Get().config_assets_url_override.empty()) {
auto new_url = il2cpp_string_new(Config::Get().config_assets_url_override.c_str());
config->AssetUrlOverride = new_url;
}

return config;
}

void InstallTestPatches()
{
auto app_config = il2cpp_get_class_helper("Assembly-CSharp", "Digit.Client.Core", "AppConfig");
auto load_config_ptr = app_config.GetMethod("LoadConfig");
SPUD_STATIC_DETOUR(load_config_ptr, AppConfig_LoadConfig);

auto model = il2cpp_get_class_helper("Assembly-CSharp", "Digit.Client.Core", "Model");
auto load_configs_ptr = model.GetMethod("LoadConfigs");
SPUD_STATIC_DETOUR(load_configs_ptr, Model_LoadConfigs);

auto battle_target_data =
il2cpp_get_class_helper("Digit.Client.PrimeLib.Runtime", "Digit.PrimeServer.Models", "BattleTargetData");
battle_target_data = battle_target_data;

auto chat_service =
il2cpp_get_class_helper("Digit.Client.PrimeLib.Runtime", "Digit.PrimePlatform.Services", "ChatService");
auto ptr = chat_service.GetMethod("HandleMessageReceived");
Expand Down

0 comments on commit e677e33

Please sign in to comment.