Skip to content

Commit

Permalink
Merge pull request #4 from EnderdracheLP/dev
Browse files Browse the repository at this point in the history
Adding Toggle for Battery Percentage and Option to set Font Size, Tweaked Clock Position, changed MultiplayerLobby clock position
  • Loading branch information
michael-r-elp authored Feb 7, 2021
2 parents 10df1f8 + 9f2f6e0 commit 201d5c7
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 39 deletions.
37 changes: 28 additions & 9 deletions .github/workflows/buildMod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ name: NDK build

on:
push:
branches: [ main ]
branches: [ main, dev ]
pull_request:
branches: [ main ]
branches: [ main, dev ]

jobs:
build:
env:
module_id: clockmod
runs-on: ubuntu-latest

steps:
Expand All @@ -18,15 +20,32 @@ jobs:
lfs: true
- name: Install Powershell
run: sudo apt-get install -y powershell

- name: Setup NDK
id: setup-ndk
uses: nttld/[email protected]

- name: Cache Android NDK
id: cache-ndk
uses: actions/cache@v2
env:
cache-name: cache-ndk
ndkname: android-ndk-r21
with:
ndk-version: r21
path: ndk
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.ndkname }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ env.ndkname }}
- name: Install Android NDK
if: steps.cache-ndk.outputs.cache-hit != 'true'
env:
ndkname: android-ndk-r21
run: |
wget -q -O ndk.zip https://dl.google.com/android/repository/${ndkname}-linux-x86_64.zip
unzip -q ndk.zip
mv ${ndkname} ndk
- name: Create ndkpath.txt
run: echo ${{ steps.setup-ndk.outputs.ndk-path }} > ${GITHUB_WORKSPACE}/ndkpath.txt
run: |
cd ndk
pwd > ${GITHUB_WORKSPACE}/ndkpath.txt
# - name: Cache QPM
# id: cache-qpm
Expand Down Expand Up @@ -76,7 +95,7 @@ jobs:
id: libname
run: |
cd ./libs/arm64-v8a/
pattern="libclockmod.so"
pattern="lib${module_id}*.so"
files=( $pattern )
echo ::set-output name=NAME::"${files[0]}"
- name: Upload non-debug artifact
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
!.vscode/c_cpp_properties.json
!.vscode/tasks.json

# Visual Stuido Stuff
.vs/

# NDK stuff
out/
[Ll]ib/
Expand Down
4 changes: 2 additions & 2 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LOCAL_MODULE := codegen_0_6_2
LOCAL_EXPORT_C_INCLUDES := extern/codegen
LOCAL_SRC_FILES := extern/libcodegen_0_6_2.so
include $(PREBUILT_SHARED_LIBRARY)
# Creating prebuilt for dependency: questui - version: 0.4.3
# Creating prebuilt for dependency: questui - version: 0.4.4
include $(CLEAR_VARS)
LOCAL_MODULE := questui
LOCAL_EXPORT_C_INCLUDES := extern/questui
Expand Down Expand Up @@ -65,7 +65,7 @@ LOCAL_SHARED_LIBRARIES += codegen_0_6_2
LOCAL_SHARED_LIBRARIES += questui
LOCAL_SHARED_LIBRARIES += custom-types
LOCAL_LDLIBS += -llog
LOCAL_CFLAGS += -I'extern/libil2cpp/il2cpp/libil2cpp' -DID='"clockmod"' -DVERSION='"0.1.2"' -I'./shared' -I'./extern' -isystem'extern/codegen/include'
LOCAL_CFLAGS += -I'extern/libil2cpp/il2cpp/libil2cpp' -DID='"clockmod"' -DVERSION='"0.1.3"' -I'./shared' -I'./extern' -isystem'extern/codegen/include'
LOCAL_CPPFLAGS += -std=c++2a
LOCAL_C_INCLUDES += ./include ./src
include $(BUILD_SHARED_LIBRARY)
Binary file modified Cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions bmbfmod.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"id": "clockmod",
"name": "Clock Mod",
"version": "0.1.2",
"version": "0.1.3",
"author": "BoopetyDoopety, EnderdracheLP",
"description": [
"Displays the time in game."
],
"coverImageFilename": "Cover.png",
"icon": "Cover.png",
"category": "Gameplay",
"category": "Other",
"gameVersion": "1.13.2",
"platform": "Quest",
"components": [
Expand Down
13 changes: 7 additions & 6 deletions buildBMBF.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Builds a .zip file for loading with BMBF
& $PSScriptRoot/build.ps1

if ($?) {
Compress-Archive -Path "./libs/arm64-v8a/libclockmod.so", "./libs/arm64-v8a/libbeatsaber-hook_1_0_12.so", "./bmbfmod.json","./Cover.png" -DestinationPath "./Clockmod.zip" -Update
}
# Builds a .zip file for loading with BMBF
& $PSScriptRoot/build.ps1

if ($?) {
Compress-Archive -Path "./libs/arm64-v8a/libclockmod.so", "./libs/arm64-v8a/libbeatsaber-hook_1_0_12.so", "./bmbfmod.json","./Cover.png" -DestinationPath "./Clockmod.zip" -Update
}
echo "Task Completed"
7 changes: 7 additions & 0 deletions buildBMBFDebug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Builds a .zip file for loading with BMBF
& $PSScriptRoot/build.ps1

if ($?) {
Compress-Archive -Path "./obj/local/arm64-v8a/libclockmod.so", "./obj/local/arm64-v8a/libbeatsaber-hook_1_0_12.so", "./bmbfmod.json","./Cover.png" -DestinationPath "./ClockmodDebug.zip" -Update
}
echo "Task Completed"
2 changes: 1 addition & 1 deletion include/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

// Define these functions here so that we can easily read configuration and log information from other files
Configuration& getConfig();
const Logger& getLogger();
Logger& logger();
2 changes: 1 addition & 1 deletion qpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"info": {
"name": "CLock Mod",
"id": "clockmod",
"version": "0.1.2",
"version": "0.1.3",
"url": null,
"additionalData": {}
},
Expand Down
28 changes: 25 additions & 3 deletions src/ClockUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "UnityEngine/GameObject.hpp"
#include "TMPro/TextMeshProUGUI.hpp"
#include <ctime>
#include "GlobalNamespace/OVRPlugin_OVRP_1_1_0.hpp"
using namespace UnityEngine;
using namespace TMPro;

Expand All @@ -29,14 +30,35 @@ void ClockMod::ClockUpdater::Update() {
strftime(timestr, 20, "%H:%M", timeinfo);
}
}
else { // If set to show 12 Hour Format
else { // If set to show 24 Hour Format
if (getConfig().config["SecToggle"].GetBool() == true) { //Check if seconds should be shown
strftime(timestr, 20, "%l:%M:%S %p", timeinfo);
}
else {
strftime(timestr, 20, "%l:%M %p", timeinfo);
};
}
// Sets the fontsize
float fontsize = getConfig().config["FontSize"].GetFloat();
auto text = get_gameObject()->GetComponent<TextMeshProUGUI*>();
text->set_text(il2cpp_utils::createcsstr(timestr));
}
text->set_fontSize(fontsize);
// Sets position
// text->get_transform()->set_position(UnityEngine::Vector3(0, 1, 2.6));
// Get current Battery Level
if (getConfig().config["BattToggle"].GetBool() == true) {
float batterylvl = GlobalNamespace::OVRPlugin::OVRP_1_1_0::ovrp_GetSystemBatteryLevel();
batterylvl = batterylvl * 100;
std::string tandb = timestr;
tandb += " - ";
std::string batterylevel = std::to_string(batterylvl);
batterylevel.erase(batterylevel.find_last_not_of('0') + 1, std::string::npos);
batterylevel.erase(batterylevel.find_last_not_of('.') + 1, std::string::npos);
tandb += batterylevel;
tandb += "%";

text->set_text(il2cpp_utils::createcsstr(tandb));
}
else {
text->set_text(il2cpp_utils::createcsstr(timestr));
}
}
56 changes: 48 additions & 8 deletions src/ClockViewContoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,73 @@ void FormatToggle(ClockMod::ClockViewController* parent, bool newValue) {
void SecToggle(ClockMod::ClockViewController* parent, bool newValue) {
getConfig().config["SecToggle"].SetBool(newValue);
}

void SetFontSize(ClockMod::ClockViewController* parent, float newValue) {
getConfig().config["FontSize"].SetFloat(newValue);
}
void BattToggle(ClockMod::ClockViewController* parent, bool newValue) {
getConfig().config["BattToggle"].SetBool(newValue);
}
//void SetClockXOffset(ClockMod::ClockViewController* parent, float newValue) {
//getConfig().config["ClockXOffset"].SetFloat(newValue);
//}
//void SetClockYOffset(ClockMod::ClockViewController* parent, float newValue) {
//getConfig().config["ClockYOffset"].SetFloat(newValue);
//}
//void SetClockZOffset(ClockMod::ClockViewController* parent, float newValue) {
//getConfig().config["ClockZOffset"].SetFloat(newValue);
//}
void ClockMod::ClockViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) {
if (firstActivation) {

get_gameObject()->AddComponent<Touchable*>();
GameObject* container = QuestUI::BeatSaberUI::CreateScrollableSettingsContainer(get_transform());
// Show Clock during Song Play
UnityEngine::Events::UnityAction_1<bool>* onInSongSettingChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<bool>*>(
auto onInSongSettingChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<bool>*>(
classof(UnityEngine::Events::UnityAction_1<bool>*), this, InSongToggle
);
UnityEngine::UI::Toggle* InsongToggleObject = QuestUI::BeatSaberUI::CreateToggle(container->get_transform(), "Show During Song", getConfig().config["insong"].GetBool(), onInSongSettingChange);
QuestUI::BeatSaberUI::AddHoverHint(InsongToggleObject->get_gameObject(), "Whether or not to show the Clock while playing a Beatmap.");
QuestUI::BeatSaberUI::AddHoverHint(InsongToggleObject->get_gameObject(), "If the Clock should be shown while playing a Beatmap.");
// Change format 24/12
UnityEngine::Events::UnityAction_1<bool>* onFormatSettingChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<bool>*>(
auto onFormatSettingChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<bool>*>(
classof(UnityEngine::Events::UnityAction_1<bool>*), this, FormatToggle
);
UnityEngine::UI::Toggle* FormatToggleObject = QuestUI::BeatSaberUI::CreateToggle(container->get_transform(), "24/12 Toggle", getConfig().config["12Toggle"].GetBool(), onFormatSettingChange);
QuestUI::BeatSaberUI::AddHoverHint(FormatToggleObject->get_gameObject(), "Whether to show time in 24 Hour or 12 Hour format.");
QuestUI::BeatSaberUI::AddHoverHint(FormatToggleObject->get_gameObject(), "If time should be in 12 or 24 Hour format.");
// Show Seconds
UnityEngine::Events::UnityAction_1<bool>* onSecSettingChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<bool>*>(
auto onSecSettingChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<bool>*>(
classof(UnityEngine::Events::UnityAction_1<bool>*), this, SecToggle
);
UnityEngine::UI::Toggle* SecToggleObject = QuestUI::BeatSaberUI::CreateToggle(container->get_transform(), "Show Seconds", getConfig().config["SecToggle"].GetBool(), onSecSettingChange);
QuestUI::BeatSaberUI::AddHoverHint(SecToggleObject->get_gameObject(), "Whether or not to show seconds.");
QuestUI::BeatSaberUI::AddHoverHint(SecToggleObject->get_gameObject(), "If Seconds should be displayed.");
// Change Size
auto onFontSizeChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<float>*>(
classof(UnityEngine::Events::UnityAction_1<float>*), this, SetFontSize); // Decimal places Value Steps Min Value Max Value
QuestUI::IncrementSetting* FontIncrementObject = QuestUI::BeatSaberUI::CreateIncrementSetting(container->get_transform(), "Font Size", 1, 0.1, getConfig().config["FontSize"].GetFloat(), 1.0f, 5.0f, onFontSizeChange);
QuestUI::BeatSaberUI::AddHoverHint(FontIncrementObject->get_gameObject(), "Changes the Font Size of the Clock (Default: 4)");
// Show Battery Percentage
auto onBattSettingChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<bool>*>(
classof(UnityEngine::Events::UnityAction_1<bool>*), this, BattToggle
);
UnityEngine::UI::Toggle* BattToggleObject = QuestUI::BeatSaberUI::CreateToggle(container->get_transform(), "Show Battery Percentage", getConfig().config["BattToggle"].GetBool(), onBattSettingChange);
QuestUI::BeatSaberUI::AddHoverHint(BattToggleObject->get_gameObject(), "Displays Battery percentage next to the clock.");
// Change Pos X
// auto onClockXOffsetChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<float>*>(
// classof(UnityEngine::Events::UnityAction_1<float>*), this, SetClockXOffset); // Decimal places Value Steps Min Value Max Value
// QuestUI::IncrementSetting* ClockXIncrementObject = QuestUI::BeatSaberUI::CreateIncrementSetting(container->get_transform(), "Clock X Offset", 1, 0.1, getConfig().config["ClockXOffset"].GetFloat(), -10.0f, 10.0f, onClockXOffsetChange);
// QuestUI::BeatSaberUI::AddHoverHint(ClockXIncrementObject->get_gameObject(), "Offsets the X Position of the Clock");
// Change Pos Y
// auto onClockYOffsetChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<float>*>(
// classof(UnityEngine::Events::UnityAction_1<float>*), this, SetClockYOffset); // Decimal places Value Steps Min Value Max Value
// QuestUI::IncrementSetting* ClockYIncrementObject = QuestUI::BeatSaberUI::CreateIncrementSetting(container->get_transform(), "Clock Y Offset", 1, 0.1, getConfig().config["ClockYOffset"].GetFloat(), -10.0f, 10.0f, onClockYOffsetChange);
// QuestUI::BeatSaberUI::AddHoverHint(ClockYIncrementObject->get_gameObject(), "Offsets the Y Position of the Clock");
// Change Pos Z
// auto onClockZOffsetChange = il2cpp_utils::MakeDelegate<UnityEngine::Events::UnityAction_1<float>*>(
// classof(UnityEngine::Events::UnityAction_1<float>*), this, SetClockZOffset); // Decimal places Value Steps Min Value Max Value
// QuestUI::IncrementSetting* ClockZIncrementObject = QuestUI::BeatSaberUI::CreateIncrementSetting(container->get_transform(), "Clock Z Offset", 1, 0.1, getConfig().config["ClockZOffset"].GetFloat(), -10.0f, 10.0f, onClockZOffsetChange);
// QuestUI::BeatSaberUI::AddHoverHint(ClockZIncrementObject->get_gameObject(), "Offsets the Z Position of the Clock");
}
}
// Write config
void ClockMod::ClockViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) {
getConfig().Write();
}
}
46 changes: 39 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace GlobalNamespace;
#include "TMPro/TextMeshPro.hpp"
#include "TMPro/TextMeshProUGUI.hpp"
#include "TMPro/TextAlignmentOptions.hpp"
#include "TMPro/TMP_Text.hpp"
using namespace TMPro;

#include "UnityEngine/Canvas.hpp"
Expand All @@ -22,6 +23,7 @@ using namespace TMPro;
#include "UnityEngine/RenderMode.hpp"
#include "UnityEngine/UI/CanvasScaler.hpp"
#include "UnityEngine/CanvasRenderer.hpp"
#include "UnityEngine/MonoBehaviour.hpp"
using namespace UnityEngine;
using namespace UnityEngine::UI;

Expand Down Expand Up @@ -67,7 +69,7 @@ MAKE_HOOK_OFFSETLESS(MainMenuViewController_DidActivate, void, MainMenuViewContr
auto canvas_renderer = canvas_object->AddComponent<CanvasRenderer*>();

canvas_object->AddComponent<CurvedCanvasSettings*>();
canvas_object->get_transform()->set_position(UnityEngine::Vector3(0, 0.5, 2.6));
canvas_object->get_transform()->set_position(UnityEngine::Vector3(0, 0.5, 3));
canvas_object->get_transform()->set_localScale(UnityEngine::Vector3(0.1, 0.1, 0.1));

Object::DontDestroyOnLoad(canvas_object);
Expand All @@ -79,15 +81,23 @@ MAKE_HOOK_OFFSETLESS(MainMenuViewController_DidActivate, void, MainMenuViewContr

layout->GetComponent<LayoutElement*>()->set_minWidth(7);
layout->GetComponent<LayoutElement*>()->set_minHeight(80);
// layout->set_childAlignment(TMPro::TextAlignmentOptions::Center, TMPro::TMP_Text::m_lineSpacing(0));
layout->set_childAlignment(TMPro::TextAlignmentOptions::Center);
layout->get_transform()->set_position(UnityEngine::Vector3(0, -2.20, 3));
clock_text->set_fontSize(4);
clock_text->get_transform()->set_position(UnityEngine::Vector3(0, 1, 2.6));
// layout->set_(TMPro::TMP_Text::m_lineSpacing(0))
layout->get_transform()->set_position(UnityEngine::Vector3(0, -1.7, 3.85));
// float fontsize = getConfig().config["FontSize"].GetFloat();

clock_text->get_transform()->set_position(UnityEngine::Vector3(0, 0.5, 3.85));
clock_text->get_gameObject()->AddComponent<ClockMod::ClockUpdater*>();
}
canvas->get_gameObject()->SetActive(true);
}

//void ClockMod::ClockViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) {
// UnityEngine::MonoBehaviour::Update();
// clock_text->get_transform()->set_position(UnityEngine::Vector3(0, 1, 12.6));
//}

MAKE_HOOK_OFFSETLESS(AudioTimeSyncController_StartSong, void, AudioTimeSyncController* self, float startTimeOffset) {
AudioTimeSyncController_StartSong(self, startTimeOffset);

Expand Down Expand Up @@ -127,13 +137,15 @@ MAKE_HOOK_OFFSETLESS(PauseMenuManager_StartResumeAnimation, void, PauseMenuManag
MAKE_HOOK_OFFSETLESS(MultiplayerLobbyController_ActivateMultiplayerLobby, void, MultiplayerLobbyController* self) {
MultiplayerLobbyController_ActivateMultiplayerLobby(self);

layout->get_transform()->set_position(UnityEngine::Vector3(0, -1.9, 3));
layout->get_transform()->set_position(UnityEngine::Vector3(0, -0.45, 1.62));
layout->get_transform()->set_localScale(UnityEngine::Vector3(0.35, 0.35, 0.35));
}

MAKE_HOOK_OFFSETLESS(MultiplayerLobbyController_DeactivateMultiplayerLobby, void, MultiplayerLobbyController* self) {
MultiplayerLobbyController_DeactivateMultiplayerLobby(self);

layout->get_transform()->set_position(UnityEngine::Vector3(0, -2.2, 3));
layout->get_transform()->set_position(UnityEngine::Vector3(0, -1.7, 3.85));
layout->get_transform()->set_localScale(UnityEngine::Vector3(1.0, 1.0, 1.0));
}

// Called at the early stages of game loading
Expand All @@ -147,7 +159,7 @@ extern "C" void setup(ModInfo & info) {

rapidjson::Document::AllocatorType& allocator = getConfig().config.GetAllocator();
if (!getConfig().config.HasMember("insong")) {
getConfig().config.AddMember("insong", rapidjson::Value(0).SetBool(false), allocator);
getConfig().config.AddMember("insong", rapidjson::Value(0).SetBool(true), allocator);
getConfig().Write();
}
if (!getConfig().config.HasMember("12Toggle")) {
Expand All @@ -158,6 +170,26 @@ extern "C" void setup(ModInfo & info) {
getConfig().config.AddMember("SecToggle", rapidjson::Value(0).SetBool(false), allocator);
getConfig().Write();
}
if (!getConfig().config.HasMember("FontSize")) {
getConfig().config.AddMember("FontSize", rapidjson::Value(0).SetFloat(4), allocator);
getConfig().Write();
}
if (!getConfig().config.HasMember("BattToggle")) {
getConfig().config.AddMember("BattToggle", rapidjson::Value(0).SetBool(false), allocator);
getConfig().Write();
}
// if (!getConfig().config.HasMember("ClockXOffset")) {
// getConfig().config.AddMember("ClockXOffset", rapidjson::Value(0).SetFloat(0), allocator);
// getConfig().Write();
// }
// if (!getConfig().config.HasMember("ClockYOffset")) {
// getConfig().config.AddMember("ClockYOffset", rapidjson::Value(0).SetFloat(0), allocator);
// getConfig().Write();
// }
// if (!getConfig().config.HasMember("ClockZOffset")) {
// getConfig().config.AddMember("ClockZOffset", rapidjson::Value(0).SetFloat(0), allocator);
// getConfig().Write();
// }
}

// Called later on in the game loading - a good time to install function hooks
Expand Down

0 comments on commit 201d5c7

Please sign in to comment.