Skip to content
Merged
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
69 changes: 59 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,13 +1,62 @@
Language: Cpp
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
ColumnLimit: 200
CommentPragmas: NOLINT:.*
AccessModifierOffset: -1
AlignAfterOpenBracket: BlockIndent
AlignOperands: AlignAfterOperator
AlignTrailingComments:
Kind: Never
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakAfterAttributes: Never
BreakBeforeConceptDeclarations: Always
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: false
ColumnLimit: 150
DerivePointerAlignment: false
IncludeBlocks: Preserve
FixNamespaceComments: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: "^<[^.>]+>$"
Priority: 2
SortPriority: 3
CaseSensitive: false
- Regex: '^<.+\.(h|hpp)>$'
Priority: 2
SortPriority: 4
CaseSensitive: false
- Regex: '^"[A-Z].*\/.+\.hpp"$'
Priority: 5
CaseSensitive: true
- Regex: "^.+/shared/.+"
Priority: 1
SortPriority: 2
CaseSensitive: true
- Regex: ".*"
Priority: 1
SortPriority: 1
CaseSensitive: false
IndentExternBlock: Indent
IndentRequiresClause: false
IndentWidth: 4
PointerAlignment: Left
TabWidth: 4
UseTab: Never
Cpp11BracedListStyle: false
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: true
LineEnding: LF
NamespaceIndentation: All
PackConstructorInitializers: CurrentLine
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 50
QualifierAlignment: Right
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SkipMacroDefinitionBody: true
SpaceAfterCStyleCast: true
SpacesBeforeTrailingComments: 2
7 changes: 7 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Diagnostics:
UnusedIncludes: None
---
If:
PathMatch: ./extern/.*
Index:
Background: Skip
2 changes: 1 addition & 1 deletion .github/workflows/build-ndk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Build & Create qmod
run: |
cd ${GITHUB_WORKSPACE}
qpm s qmod
qpm qmod zip

- name: Get Library Name
id: libname
Expand Down
67 changes: 18 additions & 49 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,57 +1,26 @@
# Prerequisites
*.d
# VSCode
.cache/
.vscode/

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# VSCode config stuff
!.vscode/c_cpp_properties.json
!.vscode/tasks.json
.cache

# NDK stuff
out/
[Ll]ib/
[Ll]ibs/
[Oo]bj/
[Oo]bjs/
ndkpath.txt
*.zip
# Jetbrains IDEs
.idea/

# Files generated by QPM
extern/
extern.cmake
ndkpath.txt
qpm_defines.cmake
extern.cmake
mod.json

# Build outputs and artifacts
build/
*.zip
*.qmod
*.backup

# Script outputs and artifacts
*.txt
*.log
mod.json
.vs/
*.html

# Exceptions
!CMakeLists.txt
117 changes: 56 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,94 +1,89 @@
# include some defines automatically made by qpm
cmake_minimum_required(VERSION 3.22)

# Include definitions generated by QPM on restore
include(qpm_defines.cmake)

cmake_minimum_required(VERSION 3.22)
project(${COMPILE_ID})

# c++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED 23)

# define that stores the actual source directory
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Provide compile commands so they can be used for intellisense
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

# compile options used
add_link_options(-Wl,--exclude-libs,ALL)
# Set compiler options
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
add_compile_options(-frtti -fPIE -fPIC -fexceptions -fvisibility=hidden)
add_compile_options(-Wall -Werror -Wextra -Wno-invalid-offsetof -O3 -Wno-vla-cxx-extension)

# Extra -Wno's that were not there originally to make it work
add_compile_options(-Wno-unused-variable -Wno-unused-function)
# compile definitions used
add_compile_definitions(VERSION=\"${MOD_VERSION}\")
add_compile_definitions(MOD_ID=\"${MOD_ID}\")

# Expose definitions from qpm_defines.cmake
add_compile_definitions(VERSION="${MOD_VERSION}")
add_compile_definitions(MOD_ID="${MOD_ID}")

# TODO: Implement more robustly
add_compile_definitions(VERSION_LONG=1)
add_compile_definitions(NEED_UNSAFE_CSHARP)
add_compile_definitions(UNITY_6)
add_compile_definitions(NO_VERBOSE_LOGS)
# For performing debug logging of very hard to diagnose issues
if (NOT DEFINED LOCAL_TEST)
add_compile_definitions(CT_USE_GCDESCRIPTOR_DEBUG)
endif()

string(LENGTH "${CMAKE_CURRENT_LIST_DIR}/" FOLDER_LENGTH)
add_compile_definitions("PAPER_ROOT_FOLDER_LENGTH=${FOLDER_LENGTH}")
# Add any extra definitions from the build script
get_cmake_property(variable_names VARIABLES)

foreach(variable_name ${variable_names})
if(variable_name MATCHES "^_bs_build_def_.*$")
string(SUBSTRING ${variable_name} 14 -1 definition_name)
add_compile_definitions(${definition_name}=${${variable_name}})
message("Added definition: " ${definition_name} "=" ${${variable_name}})
endif()
endforeach()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Trim source folder in logcat messages
string(LENGTH "${CMAKE_CURRENT_SOURCE_DIR}/" FOLDER_LENGTH)
add_compile_definitions("PAPER_ROOT_FOLDER_LENGTH=${FOLDER_LENGTH}")

if (DEFINED LOCAL_TEST)
if(DEFINED LOCAL_TEST)
MESSAGE(STATUS "Building lib with Test defines")
add_compile_definitions(LOCAL_TEST)
add_compile_definitions(TEST_DELEGATE)
elseif(DEFINED LOCAL_TEST_COROUTINE)
MESSAGE(STATUS "Building lib with Coroutine test defines")
add_compile_definitions(LOCAL_TEST_COROUTINE)
else()
# For performing debug logging of very hard to diagnose issues
# add_compile_definitions(CT_USE_GCDESCRIPTOR_DEBUG)
endif()

# recursively get all src files
RECURSE_FILES(cpp_file_list ${SOURCE_DIR}/*.cpp)
RECURSE_FILES(c_file_list ${SOURCE_DIR}/*.c)
RECURSE_FILES(inline_hook_c ${EXTERN_DIR}/includes/beatsaber-hook/shared/inline-hook/*.c)
RECURSE_FILES(inline_hook_cpp ${EXTERN_DIR}/includes/beatsaber-hook/shared/inline-hook/*.cpp)

# add all src files to compile
add_library(
${COMPILE_ID}
SHARED
${cpp_file_list}
${c_file_list}
${inline_hook_c}
${inline_hook_cpp}
)
# Define the code directories
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

# Recursively get all source files
recurse_files(cpp_file_list ${SOURCE_DIR}/*.cpp)
recurse_files(c_file_list ${SOURCE_DIR}/*.c)

# Add all source files to compilation
add_library(${COMPILE_ID} SHARED ${cpp_file_list} ${c_file_list})

# add src dir as include dir
target_include_directories(${COMPILE_ID} PRIVATE ${SOURCE_DIR})
# add include dir as include dir
# Add include directories to compilation
target_include_directories(${COMPILE_ID} PRIVATE ${INCLUDE_DIR})
# add shared dir as include dir
target_include_directories(${COMPILE_ID} PUBLIC ${SHARED_DIR})

# Link necessary Android libraries
target_link_libraries(${COMPILE_ID} PRIVATE -llog)
# add extern stuff like libs and other includes

# Add autogenerated definitions and link libraries for dependencies
add_link_options(-Wl, --exclude-libs, ALL)
include(extern.cmake)

add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_STRIP} -g -S -d --strip-all
"lib${COMPILE_ID}.so" -o "stripped_lib${COMPILE_ID}.so"
COMMENT "Strip debug symbols done on final binary.")

add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory debug
COMMENT "Make directory for debug symbols"
)

add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename lib${COMPILE_ID}.so debug/lib${COMPILE_ID}.so
COMMENT "Rename the lib to debug_ since it has debug symbols"
)

add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename stripped_lib${COMPILE_ID}.so lib${COMPILE_ID}.so
COMMENT "Rename the stripped lib to regular"
)
add_custom_command(
TARGET ${COMPILE_ID}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "debug"
COMMAND ${CMAKE_COMMAND} -E rename "lib${COMPILE_ID}.so" "debug/lib${COMPILE_ID}.so"
COMMAND ${CMAKE_STRIP} -d --strip-all "debug/lib${COMPILE_ID}.so" -o "lib${COMPILE_ID}.so"
COMMENT "Create stripped and debug libraries"
)
16 changes: 0 additions & 16 deletions CMakeSettings.json

This file was deleted.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
Type patching POC
For il2cpp

## Build Instructions

Install [QPM](https://github.com/QuestPackageManager/QPM.CLI/releases/latest), [CMake](https://cmake.org/download/), [Ninja](https://github.com/ninja-build/ninja/releases/latest), and [Python 3](https://www.python.org/downloads/), then run:

```sh
qpm ndk resolve
qpm restore
qpm qmod zip
```

## Credits

* [Sc2ad](https://github.com/Sc2ad) and [jakibaki](https://github.com/jakibaki) - [beatsaber-hook](https://github.com/sc2ad/beatsaber-hook)
Expand Down
40 changes: 0 additions & 40 deletions build.ps1

This file was deleted.

Loading
Loading