Skip to content

Commit

Permalink
Merge pull request #53 from Futuremappermydud/dev/unity2021
Browse files Browse the repository at this point in the history
Unity 2021 Support
  • Loading branch information
Fernthedev authored Jun 26, 2024
2 parents ae61c50 + b8b3f0d commit 316e57c
Show file tree
Hide file tree
Showing 118 changed files with 1,466 additions and 1,533 deletions.
54 changes: 32 additions & 22 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Checks: "*,-llvm*,
-google-readability-namespace,
-llvmlib,
-llvmlibc,
-fuchsi,
-fuchsia,
-alter,
-modernize-use-trailing-return-type,
-modernize-use-trailing-return,
Expand All @@ -12,6 +14,16 @@ Checks: "*,-llvm*,
-fuchsia-default-arguments-calls,
-altera-unroll-loops,
-altera*,
-readability-implicit-bool-conversion,
-cert-err58-cpp,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-hicpp-avoid-c-arrays,
-bugprone-undefined-memory-manipulation,
-misc-use-anonymous-namespace,
-readability-magic-numbers,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-virtual-class-destructor,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-pro-type-static-cast-downcast,
Expand All @@ -22,29 +34,27 @@ Checks: "*,-llvm*,
-hicpp-vararg,
-cppcoreguidelines-pro-bounds-constant-array-index,
-google-build-using-namespace,
-abseil-string-find-str-contains
-abseil-string-find-str-contains,
clang-diagnostic-*,
-bugprone-unchecked-optional-access,
clang-analyzer-*,
fuchsia-statically-constructed-objects,
*,
-llvmlibc-callee-namespace,
-readability-identifier-length,
-llvmlibc-implementation-in-namespace,
-llvmlibc-restrict-system-libc-headers,
-llvm-namespace-comment,
-llvm-include-order,
-altera-*,
-fuchsia-*,
-modernize-use-trailing-return-type,
-cppcoreguidelines-avoid-non-const-global-variables,
-llvm-header-guard,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-avoid-do-while,
-hicpp-vararg,
-concurrency-mt-unsafe,
-abseil-*
clang-analyzer-*,
-bugprone-unchecked-optional-access,
-llvmlibc-callee-namespace,
-readability-identifier-length,
-llvmlibc-implementation-in-namespace,
-llvmlibc-restrict-system-libc-headers,
-llvm-namespace-comment,
-llvm-include-order,
-altera-*,
-fuchsia-*,
-modernize-use-trailing-return-type,
-cppcoreguidelines-avoid-non-const-global-variables,
-llvm-header-guard,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-avoid-do-while,
-hicpp-vararg,
-concurrency-mt-unsafe,
-abseil-*
"
FormatStyle: file
HeaderFilterRegex: ""
Expand Down
3 changes: 3 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Diagnostics:
UnusedIncludes: None

If:
# Note: This is a regexp, notice '.*' at the end of PathMatch string.
PathMatch: ./extern/.*
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/build-ndk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: NDK build

env:
module_id: chroma
qmodName: chroma
qmodName: Chroma

on:
push:
Expand Down Expand Up @@ -48,13 +48,7 @@ jobs:
run: |
cd ${GITHUB_WORKSPACE}
qpm-rust s build
qpm-rust restore
qpm-rust qmod build
- name: Create Qmod
run: |
pwsh -Command ./createqmod.ps1 ${{env.qmodName}}
qpm-rust qmod zip
- name: Get Library Name
id: libname
Expand Down
19 changes: 2 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish QPM Package

env:
module_id: chroma
qmodName: chroma
qmodName: Chroma
cache-name: chroma_cache

on:
Expand Down Expand Up @@ -57,21 +57,11 @@ jobs:
# Name of qmod in release asset. Assumes exists, same as prior
qpm_qmod: ${{env.qmodName}}.qmod

- name: List Post Restore
run: |
echo includes:
ls -la ${GITHUB_WORKSPACE}/extern/includes
echo libs:
ls -la ${GITHUB_WORKSPACE}/extern/libs
echo cache:
ls -la $HOME/.local/share/QPM-Rust/cache
- name: Build
run: |
cd ${GITHUB_WORKSPACE}
qpm-rust s build
qpm-rust restore
qpm-rust qmod build
qpm-rust zip
- name: Get Library Name
id: libname
Expand All @@ -85,11 +75,6 @@ jobs:
run: |
mv ./build/debug/${{ steps.libname.outputs.NAME }} ./build/debug/debug_${{ steps.libname.outputs.NAME }}
- name: Create Qmod
run: |
pwsh -Command ./createqmod.ps1 ${{env.qmodName}}
- name: Upload to Release
id: upload_file_release
uses: softprops/action-gh-release@v0.1.15
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

# compile options used
add_compile_options(-frtti -fexceptions)



add_compile_options(-O3)
# compile definitions used
add_compile_definitions(VERSION=\"${MOD_VERSION}\")
Expand Down Expand Up @@ -74,4 +77,6 @@ add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
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"
)
)

include(assets_include.cmake)
Binary file added assets/standard_shader.bundle
Binary file not shown.
8 changes: 8 additions & 0 deletions assets/ui.bsml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<bg xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='https://raw.githubusercontent.com/RedBrumbler/Quest-BSML-Docs/gh-pages/schema.xsd'>
<vertical pref-width='60' pref-height='30'
vertical-fit='PreferredSize' pad='2'>
<modifier src="#GlobalIcon" text="Environment Enhancements" hover-hint="Toggles whether Chroma should modify the environment as specified by a map." value="environmentEnhancementsEnabled" bind-value="true" apply-on-change="true" />
<modifier src="#LightIcon" text="Custom Color Events" hover-hint="Disables custom colors for Chroma maps. In other words, disables Chroma." value="customColorEventsEnabled" bind-value="true" apply-on-change="true" />
<modifier src="#DisappearingArrows" text="Note coloring" hover-hint="Controls whether notes will be colored or not." value="customNoteColors" bind-value="true" apply-on-change="true" />
</vertical>
</bg>
111 changes: 111 additions & 0 deletions assets_include.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# credit goes to https://github.com/Lauriethefish for this
# Directory where our arbitrary asset files are stored
set(ASSETS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets)
# Directory to save the object files generated by llvm-objcopy
set(ASSET_BINARIES_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/binaryAssets)
# Directory to save the prepended files to
set(PREPENDED_ASSETS_DIR ${CMAKE_CURRENT_BINARY_DIR}/prependedAssets)
set(ASSET_HEADER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include/assets.hpp")

# Define a macro which we will use for defining the symbols to access our asset files below
set(ASSET_HEADER_DATA
"#pragma once
#include <string_view>
#include \"beatsaber-hook/shared/utils/typedefs.h\"
struct IncludedAsset {
IncludedAsset(uint8_t* start, uint8_t* end) : array(reinterpret_cast<Array<uint8_t>*>(start)) {
array->klass = nullptr;
array->monitor = nullptr;
array->bounds = nullptr;
array->max_length = end - start - 33;
*(end - 1)= '\\0';
}
operator ArrayW<uint8_t>() const {
init();
return array;
}
operator std::string_view() const {
return { reinterpret_cast<char*>(array->_values), array->get_Length() };
}
operator std::span<uint8_t>() const {
return { array->_values, array->get_Length() };
}
void init() const {
if(!array->klass)
array->klass = classof(Array<uint8_t>*);
}
private:
Array<uint8_t>* array;
};
#define DECLARE_FILE(name) \\
extern \"C\" uint8_t _binary_##name##_start[]; \\
extern \"C\" uint8_t _binary_##name##_end[]; \\
const IncludedAsset name { _binary_##name##_start, _binary_##name##_end};
namespace IncludedAssets {
\n")

if (EXISTS ${ASSETS_DIRECTORY})
file(MAKE_DIRECTORY ${ASSET_BINARIES_DIRECTORY})
file(MAKE_DIRECTORY ${PREPENDED_ASSETS_DIR})
file(GLOB ASSETS LIST_DIRECTORIES false ${ASSETS_DIRECTORY}/*)

# Iterate through each file in the assets directory. TODO: This could be recursive
foreach(FILE IN LISTS ASSETS)
message("-- Including asset: ${FILE}")
get_filename_component(ASSET ${FILE} NAME) # Find the asset's file name

# make a copy of the file with 32 bytes added in the build dir
add_custom_command(
OUTPUT ${PREPENDED_ASSETS_DIR}/${ASSET}
COMMAND ${CMAKE_COMMAND} -E echo_append " " > ${PREPENDED_ASSETS_DIR}/${ASSET}
COMMAND ${CMAKE_COMMAND} -E cat ${ASSETS_DIRECTORY}/${ASSET} >> ${PREPENDED_ASSETS_DIR}/${ASSET}
COMMAND ${CMAKE_COMMAND} -E echo_append " " >> ${PREPENDED_ASSETS_DIR}/${ASSET}
DEPENDS ${ASSETS_DIRECTORY}/${ASSET}
)

set(OUTPUT_FILE "${ASSET_BINARIES_DIRECTORY}/${ASSET}.o") # Save our asset in the asset binaries directory

# Use llvm-objcopy to create an object file that stores our binary asset
# The resulting file contains 3 symbols: _binary_<file_name>_start, _binary_<file_name>_size and _binary_<file_name>_end
# We only use the first two
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${CMAKE_OBJCOPY} ${ASSET} ${OUTPUT_FILE} --input-target binary --output-target elf64-aarch64 --set-section-flags binary=strings
DEPENDS ${PREPENDED_ASSETS_DIR}/${ASSET}
WORKING_DIRECTORY ${PREPENDED_ASSETS_DIR}
)
list(APPEND BINARY_ASSET_FILES ${OUTPUT_FILE})

# Find the correct objcopy symbol name, this is always the file name with any non-alphanumeric characters replaced with _
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" FIXED_ASSET ${ASSET})
# Add to our assets header
set(ASSET_HEADER_DATA "${ASSET_HEADER_DATA}\tDECLARE_FILE(${FIXED_ASSET})\n")
endforeach()
set(ASSET_HEADER_DATA "${ASSET_HEADER_DATA}\n}\n")

# check if at least 1 asset file, otherwise ignore
list(LENGTH BINARY_ASSET_FILES COUNT)
if (${COUNT} GREATER 0)
# Generate the assets header file
file(GENERATE OUTPUT ${ASSET_HEADER_PATH} CONTENT "${ASSET_HEADER_DATA}")

# Add our assets files to the final SO
add_library(asset_files OBJECT ${BINARY_ASSET_FILES})
set_target_properties(asset_files PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${COMPILE_ID} PRIVATE asset_files ${BINARY_ASSET_FILES})
endif()
else()
message("-- Removing '${ASSET_HEADER_PATH}' as no assets have been found in '${ASSETS_DIRECTORY}'")
file(REMOVE ${ASSET_HEADER_PATH})
endif()
2 changes: 1 addition & 1 deletion copy.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
& $PSScriptRoot/build.ps1
if ($?) {
adb push build/libchroma.so /sdcard/Android/data/com.beatgames.beatsaber/files/mods/libchroma.so
adb push build/libchroma.so /sdcard/ModData/com.beatgames.beatsaber/Modloader/mods/libchroma.so
if ($?) {
adb shell am force-stop com.beatgames.beatsaber
adb shell am start com.beatgames.beatsaber/com.unity3d.player.UnityPlayerActivity
Expand Down
19 changes: 4 additions & 15 deletions include/Chroma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include <string_view>

#define GET_FIND_METHOD(mPtr) il2cpp_utils::il2cpp_type_check::MetadataGetter<mPtr>::get()

template <auto val> using FPtrWrapper = il2cpp_utils::il2cpp_type_check::FPtrWrapper<val>;

inline void PrintJSONValue(rapidjson::Value const& json) {
Expand All @@ -20,7 +18,7 @@ inline void PrintJSONValue(rapidjson::Value const& json) {
PrettyWriter<StringBuffer> writer(sb);
json.Accept(writer);
auto str = sb.GetString();
getLogger().info("%s", str);
ChromaLogger::Logger.info("{}", str);
}

inline void PrintJSONValue(rapidjson::Value const* json) {
Expand All @@ -33,21 +31,12 @@ inline void PrintJSONValue(rapidjson::Value const* json) {
PrettyWriter<StringBuffer> writer(sb);
json->Accept(writer);
auto str = sb.GetString();
getLogger().info("json %s", str);
ChromaLogger::Logger.info("json {}", str);
}

namespace Chroma {
namespace ChromaLogger {
inline static char const* ColorLightSwitch = "ColorLightSwitch";
inline static char const* EnvironmentRemoval = "EnvironmentRemoval";
inline static char const* LightColorizer = "LightColorizer";
inline static char const* TrackLaneRings = "TrackLaneRings";
inline static char const* LegacyLightColor = "LegacyLightColor";
inline static char const* ObjectDataDeserialize = "ObjectDataDeserialize";
inline static char const* TrackController = "GameObjectTrackController";
} // namespace ChromaLogger

inline static const std::u16string_view REQUIREMENTNAME = u"Chroma";

inline static const std::string REQUIREMENTNAME = "Chroma";

namespace NewConstants {
using namespace TracksAD::Constants;
Expand Down
8 changes: 1 addition & 7 deletions include/ChromaConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ DECLARE_CONFIG(ChromaConfig,
"Controls whether notes will be colored or not");
CONFIG_VALUE(environmentEnhancementsEnabled, bool, "Environment Enhancements", true,
"Toggles whether Chroma should modify the environment as specified by a map.");

CONFIG_INIT_FUNCTION(

CONFIG_INIT_VALUE(PrintEnvironmentEnhancementDebug); CONFIG_INIT_VALUE(customColorEventsEnabled);
CONFIG_INIT_VALUE(customNoteColors); CONFIG_INIT_VALUE(environmentEnhancementsEnabled);

))
)
6 changes: 3 additions & 3 deletions include/ChromaController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ChromaController {
return getChromaConfig().customColorEventsEnabled.GetValue() && (ChromaRequired());
}

static void AddForceDoHooks(ModInfo const& otherModInfo);
static void RemoveForceDoHooks(ModInfo const& otherModInfo);
static void AddForceDoHooks(modloader::ModInfo const& otherModInfo);
static void RemoveForceDoHooks(modloader::ModInfo const& otherModInfo);

// Quest internal stuff
static void SetChromaLegacy(bool v);
Expand All @@ -69,6 +69,6 @@ class ChromaController {
DelayedStartEnumerator(GlobalNamespace::BeatmapObjectSpawnController* beatmapObjectSpawnController);

// Since level data is freed on scene load, we copy it before we load.
inline static std::optional<DocumentUTF16> infoDatCopy = std::nullopt;
inline static std::optional<std::vector<std::string>> environmentObjectsRemovalV2 = std::nullopt;
};
} // namespace Chroma
2 changes: 1 addition & 1 deletion include/ChromaEvents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ void deserialize(CustomJSONData::CustomBeatmapData* readOnlyBeatmap);
void parseEventData(TracksAD::BeatmapAssociatedData& beatmapAD, CustomJSONData::CustomEventData const* customEventData,
bool v2);

void AddEventCallbacks(Logger& logger);
void AddEventCallbacks();
} // namespace ChromaEvents
Loading

0 comments on commit 316e57c

Please sign in to comment.