Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity update for custom types #24

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/actions/canary-ndk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Setup canary ndk"
description: "Sets up canary ndk"
outputs:
ndk-path:
value: ${{ steps.path.outputs.path }}
description: "Output path of the ndk"
cache-hit:
value: ${{ steps.cache.outputs.cache-hit }}
description: "Whether a cache hit occurred for the ndk"
runs:
using: "composite"
steps:
- name: NDK cache
id: cache
uses: actions/cache@v3
with:
path: ${HOME}/android-ndk-r27-canary/
key: ${{ runner.os }}-ndk-r27-canary

- name: Download canary ndk
if: ${{ !steps.cache.outputs.cache-hit }}
env:
CANARY_URL: https://github.com/QuestPackageManager/ndk-canary-archive/releases/download/27.0.1/android-ndk-10883340-linux-x86_64.zip
run: wget ${CANARY_URL} -O ${HOME}/ndk.zip
shell: bash

- name: Unzip ndk
if: ${{ !steps.cache.outputs.cache-hit }}
run: 7z x "${HOME}/ndk.zip" -o"${HOME}/"
shell: bash

- name: Set output
id: path
shell: bash
run: echo "path=${HOME}/android-ndk-r27-canary" >> ${GITHUB_OUTPUT}
21 changes: 14 additions & 7 deletions .github/workflows/build-ndk.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
name: NDK build

env:
module_id: custom-types
qmodName: CustomTypes
cache-name: customtypes_cache

on:
workflow_dispatch:
push:
branches-ignore:
- "version-*"
pull_request:
branches: [master]
branches-ignore:
- "version-*"

env:
module_id: custom-types
qmodName: CustomTypes
cache-name: customtypes_cache

jobs:
build:
Expand All @@ -24,9 +27,13 @@ jobs:

- uses: seanmiddleditch/gha-setup-ninja@v3

- name: Setup canary NDK
id: setup-ndk
uses: ./.github/actions/canary-ndk

- name: Create ndkpath.txt
run: |
echo "$ANDROID_NDK_LATEST_HOME" > ${GITHUB_WORKSPACE}/ndkpath.txt
echo ${{ steps.setup-ndk.outputs.ndk-path }} > ${GITHUB_WORKSPACE}/ndkpath.txt
cat ${GITHUB_WORKSPACE}/ndkpath.txt

- name: QPM Rust Action
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ jobs:

- uses: seanmiddleditch/gha-setup-ninja@v3

- name: Setup canary NDK
id: setup-ndk
uses: ./.github/actions/canary-ndk

- name: Create ndkpath.txt
run: |
echo "$ANDROID_NDK_LATEST_HOME" > ${GITHUB_WORKSPACE}/ndkpath.txt
echo ${{ steps.setup-ndk.outputs.ndk-path }} > ${GITHUB_WORKSPACE}/ndkpath.txt
cat ${GITHUB_WORKSPACE}/ndkpath.txt

- name: Get Tag Version
id: get_tag_version
- name: Extract version
id: version
run: |
echo ${GITHUB_REF#refs/tags/}
echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/v}
echo "TAG=${GITHUB_REF#refs/tags/}" >> ${GITHUB_OUTPUT}
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> ${GITHUB_OUTPUT}

- name: QPM Rust Action
uses: Fernthedev/qpm-rust-action@main
Expand All @@ -47,8 +50,8 @@ jobs:
publish: true
publish_token: ${{secrets.PUBLISH_KEY}}

version: ${{ steps.get_tag_version.outputs.VERSION }}
tag: ${{ steps.get_tag_version.outputs.TAG }}
version: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.TAG }}

# set to true if applicable, ASSUMES the file is already a release asset
qpm_release_bin: true
Expand Down Expand Up @@ -76,13 +79,12 @@ jobs:
pwsh -Command ./createqmod.ps1 ${{env.qmodName}}

- name: Rename debug file
run: mv "./build/debug/${{ steps.libname.outputs.NAME }}" "./build/debug/debug_${{ steps.libname.outputs.NAME }}"
run: mv "./build/debug/${{ steps.libname.outputs.NAME }}" "./build/debug_${{ steps.libname.outputs.NAME }}"

- name: Upload to Release
id: upload_file_release
uses: softprops/[email protected]
with:
name: ${{ github.event.inputs.release_msg }}
tag_name: ${{ github.event.inputs.version }}
files: |
./build/${{ steps.libname.outputs.NAME }}
Expand Down
9 changes: 6 additions & 3 deletions qpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
"info": {
"name": "custom-types",
"id": "custom-types",
"version": "0.4.6",
"version": "0.16.0",
"url": "https://github.com/sc2ad/Il2CppQuestTypePatching",
"additionalData": {
"overrideSoName": "libcustom-types.so",
"cmake": true
"cmake": true,
"compileOptions": {
"cppFlags": [ "-Wno-invalid-offsetof" ]
}
}
},
"dependencies": [
{
"id": "beatsaber-hook",
"versionRange": "^4.0.0",
"versionRange": "^5.0.1",
"additionalData": {
"extraFiles": [
"src/inline-hook"
Expand Down
48 changes: 25 additions & 23 deletions qpm.shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
"info": {
"name": "custom-types",
"id": "custom-types",
"version": "0.4.6",
"version": "0.16.0",
"url": "https://github.com/sc2ad/Il2CppQuestTypePatching",
"additionalData": {
"overrideSoName": "libcustom-types.so",
"compileOptions": {
"cppFlags": [
"-Wno-invalid-offsetof"
]
},
"cmake": true
}
},
"workspace": {
"scripts": {
"build": [
"pwsh ./build.ps1"
]
}
},
"dependencies": [
{
"id": "beatsaber-hook",
"versionRange": "^4.0.0",
"versionRange": "^5.0.1",
"additionalData": {
"extraFiles": [
"src/inline-hook"
Expand All @@ -36,43 +34,47 @@
"private": true
}
}
]
],
"workspace": {
"scripts": {
"build": [
"pwsh ./build.ps1"
]
}
}
},
"restoredDependencies": [
{
"dependency": {
"id": "libil2cpp",
"versionRange": "=0.2.3",
"versionRange": "=0.3.1",
"additionalData": {
"headersOnly": true
}
},
"version": "0.2.3"
"version": "0.3.1"
},
{
"dependency": {
"id": "beatsaber-hook",
"versionRange": "=4.0.1",
"versionRange": "=5.0.1",
"additionalData": {
"soLink": "https://github.com/sc2ad/beatsaber-hook/releases/download/v4.0.1/libbeatsaber-hook_4_0_1.so",
"debugSoLink": "https://github.com/sc2ad/beatsaber-hook/releases/download/v4.0.1/debug_libbeatsaber-hook_4_0_1.so",
"branchName": "version/v4_0_1"
"soLink": "https://github.com/QuestPackageManager/beatsaber-hook/releases/download/v5.0.1/libbeatsaber-hook_5_0_1.so",
"debugSoLink": "https://github.com/QuestPackageManager/beatsaber-hook/releases/download/v5.0.1/debug_libbeatsaber-hook_5_0_1.so",
"branchName": "version/v5_0_1"
}
},
"version": "4.0.1"
"version": "5.0.1"
},
{
"dependency": {
"id": "scotland2",
"versionRange": "=0.1.2",
"versionRange": "=0.1.3",
"additionalData": {
"soLink": "https://github.com/sc2ad/scotland2/releases/download/v0.1.2/libsl2.so",
"debugSoLink": "https://github.com/sc2ad/scotland2/releases/download/v0.1.2/debug_libsl2.so",
"overrideSoName": "libsl2.so",
"branchName": "version/v0_1_2"
"overrideSoName": "libsl2.so"
}
},
"version": "0.1.2"
"version": "0.1.3"
},
{
"dependency": {
Expand Down
22 changes: 9 additions & 13 deletions shared/coroutine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace custom_types::Helpers {
#include <functional>
#include "macros.hpp"

#ifdef HAS_CODEGEN
#if __has_include("System/Collections/IEnumerator.hpp")
#include "System/Collections/IEnumerator.hpp"
namespace custom_types::Helpers {
using enumeratorT = System::Collections::IEnumerator*;
Expand All @@ -46,6 +46,7 @@ namespace custom_types::Helpers {
namespace custom_types::Helpers {
struct Wrapper {
enumeratorT instance;
constexpr Wrapper() : instance(nullptr) {}
constexpr Wrapper(enumeratorT value) : instance(value) {}
};
static_assert(sizeof(Wrapper) == sizeof(enumeratorT));
Expand All @@ -57,6 +58,8 @@ namespace custom_types::Helpers {
using Coroutine = generator<Wrapper>;
using CoroFuncType = std::function<Coroutine ()>;
}
MARK_GEN_REF_PTR_T(custom_types::Helpers::generator);
MARK_REF_PTR_T(custom_types::Helpers::Coroutine*);
// Coroutine* mapped to void*
template<>
struct ::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<custom_types::Helpers::Coroutine*> {
Expand All @@ -73,6 +76,7 @@ struct ::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<custom_types::Help
return il2cpp_functions::Class_GetPtrClass(il2cpp_functions::defaults->void_class);
}
};
MARK_REF_PTR_T(custom_types::Helpers::CoroFuncType*);

namespace custom_types::Helpers {
/// @brief A helper type for creating custom coroutines C# from C++.
Expand Down Expand Up @@ -186,15 +190,11 @@ namespace custom_types::Helpers {
}
}

DECLARE_CLASS_INTERFACES(custom_types::Helpers, ResetableCoroutine, "System", "Object", sizeof(Il2CppObject),
DECLARE_CLASS_INTERFACES(custom_types::Helpers, ResetableCoroutine, "System", "Object", sizeof(Il2CppObject),
(il2cpp_utils::GetClassFromName("System.Collections", "IEnumerator")),
private:
custom_types::Helpers::CoroFuncType coroCreator;
custom_types::Helpers::Wrapper current;
// Explicitly delete copy constructor
ResetableCoroutine(const ResetableCoroutine& other) = delete;
// Explicitly delete move constructor
ResetableCoroutine(ResetableCoroutine&& other) = delete;
// These fields exist as C# fields for semantic purposes only
DECLARE_INSTANCE_FIELD(custom_types::Helpers::Coroutine*, currentCoro);
DECLARE_INSTANCE_FIELD(bool, valid);
Expand All @@ -206,16 +206,12 @@ DECLARE_CLASS_INTERFACES(custom_types::Helpers, ResetableCoroutine, "System", "O
DECLARE_DTOR(Finalize);
)

DECLARE_CLASS_INTERFACES(custom_types::Helpers, StandardCoroutine, "System", "Object", sizeof(Il2CppObject),
DECLARE_CLASS_INTERFACES(custom_types::Helpers, StandardCoroutine, "System", "Object", sizeof(Il2CppObject),
(il2cpp_utils::GetClassFromName("System.Collections", "IEnumerator")),
struct CoroutineNotResettable : std::runtime_error {
CoroutineNotResettable() : std::runtime_error("StandardCoroutine is not resettable!") {}
};
custom_types::Helpers::Wrapper current;
// Explicitly delete copy constructor
StandardCoroutine(const StandardCoroutine& other) = delete;
// Explicitly delete move constructor
StandardCoroutine(StandardCoroutine&& other) = delete;
// These fields exist as C# fields for semantic purposes only
DECLARE_INSTANCE_FIELD(custom_types::Helpers::Coroutine*, currentCoro);
DECLARE_INSTANCE_FIELD(bool, valid);
Expand Down Expand Up @@ -260,7 +256,7 @@ namespace custom_types::Helpers {
constexpr T* operator->() noexcept {
return ptr;
}

private:
T* ptr;
};
Expand All @@ -272,7 +268,7 @@ namespace custom_types::Helpers {
struct CoroutineHelper {
private:
static void EnsureCoroutines();

public:
/// @brief Creates a new StandardCoroutine from the provided Coroutine instance, which is immediately rendered invalid.
/// This function will throw a ::custom_types::Helpers::CoroutineAllocationFailed exception on failure.
Expand Down
24 changes: 12 additions & 12 deletions shared/delegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace custom_types {

int get_delegate_count();

inline void setup_for_delegate(MethodInfo* info) {
inline void setup_for_delegate([[maybe_unused]] MethodInfo* info) {
// The method in question actually isn't quite fit for being a proper delegate
// So, here we will set it just to make sure it does what we want.
info->is_marshaled_from_native = true;
info->indirect_call_via_invokers = true;
// TODO: Support virtual invokes some time in the distant, distant future.
// m->slot = kInvalidIl2CppMethodSlot;
// m->invoker_method = parent_invoke->invoker_method;
Expand Down Expand Up @@ -126,11 +126,11 @@ struct DelegateWrapperStatic : Il2CppObject {
const Il2CppType* returnType() const override {
return ::il2cpp_functions::class_get_type(::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<RI>::get());
}
std::vector<ParameterInfo> params() const override {
int32_t counter = 1;
std::vector<const Il2CppType*> params() const override {
il2cpp_functions::Init();
return {ParameterInfo{"inst", 0, static_cast<uint32_t>(-1), ::il2cpp_functions::class_get_type(___TypeRegistration::klass_ptr)},
(ParameterInfo{"param", counter++, static_cast<uint32_t>(-1), ::il2cpp_functions::class_get_type(::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<TArgsI>::get())})...
return {
::il2cpp_functions::class_get_type(___TypeRegistration::klass_ptr),
(il2cpp_functions::class_get_type(::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<TArgsI>::get()))...
};
}
uint8_t params_size() const override {
Expand Down Expand Up @@ -169,7 +169,7 @@ struct DelegateWrapperStatic : Il2CppObject {
::il2cpp_functions::Init();
return &il2cpp_functions::defaults->void_class->byval_arg;
}
std::vector<ParameterInfo> params() const override {
std::vector<const Il2CppType*> params() const override {
return {};
}
uint8_t params_size() const override {
Expand Down Expand Up @@ -338,11 +338,11 @@ struct DelegateWrapperInstance : Il2CppObject {
::il2cpp_functions::Init();
return ::il2cpp_functions::class_get_type(::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<RI>::get());
}
std::vector<ParameterInfo> params() const override {
int32_t counter = 1;
std::vector<const Il2CppType*> params() const override {
il2cpp_functions::Init();
return {ParameterInfo{"inst", 0, static_cast<uint32_t>(-1), ::il2cpp_functions::class_get_type(___TypeRegistration::klass_ptr)},
(ParameterInfo{"param", counter++, static_cast<uint32_t>(-1), ::il2cpp_functions::class_get_type(::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<TArgsI>::get())})...
return {
::il2cpp_functions::class_get_type(___TypeRegistration::klass_ptr),
(::il2cpp_functions::class_get_type(::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<TArgsI>::get()))...
};
}
uint8_t params_size() const override {
Expand Down Expand Up @@ -406,7 +406,7 @@ struct DelegateWrapperInstance : Il2CppObject {
::il2cpp_functions::Init();
return &il2cpp_functions::defaults->void_class->byval_arg;
}
std::vector<ParameterInfo> params() const override {
std::vector<const Il2CppType*> params() const override {
return {};
}
uint8_t params_size() const override {
Expand Down
Loading
Loading