Skip to content

Commit

Permalink
FPFC fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalit committed Dec 27, 2024
1 parent 6703026 commit 8e3bbbc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
5 changes: 3 additions & 2 deletions qmod/include/CameraController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ DECLARE_CLASS_CODEGEN(QRUE, CameraController, UnityEngine::MonoBehaviour,
DECLARE_INSTANCE_METHOD(void, KeyUp, StringW);
DECLARE_INSTANCE_METHOD(void, MouseDown);
DECLARE_INSTANCE_METHOD(void, MouseUp);
DECLARE_INSTANCE_METHOD(void, AddScroll, float);
DECLARE_INSTANCE_METHOD(float, GetScroll);

#ifdef BEAT_SABER
DECLARE_INSTANCE_METHOD(void, GetControllers);
Expand All @@ -33,10 +35,9 @@ DECLARE_CLASS_CODEGEN(QRUE, CameraController, UnityEngine::MonoBehaviour,
private:
UnityEngine::Vector3 movementF;
UnityEngine::Vector3 movementB;
float scroll;
)

extern bool fpfcEnabled;

extern float rotateSensitivity;
extern float moveSensitivity;

Expand Down
5 changes: 4 additions & 1 deletion qmod/qpm.shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@
"id": "hollywood",
"versionRange": "=1.0.0",
"additionalData": {
"overrideSoName": "libhollywood.so"
"soLink": "https://github.com/Fernthedev/HollywoodQuest/releases/download/v1.0.0/libhollywood.so",
"overrideSoName": "libhollywood.so",
"modLink": "https://github.com/Fernthedev/HollywoodQuest/releases/download/v1.0.0/Hollywood.qmod",
"branchName": "version/v1_0_0"
}
},
"version": "1.0.0"
Expand Down
17 changes: 12 additions & 5 deletions qmod/src/CameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ DEFINE_TYPE(QRUE, CameraController);
using namespace QRUE;
using namespace UnityEngine;

bool fpfcEnabled = true;

float rotateSensitivity = 1;
float moveSensitivity = 1;

Expand Down Expand Up @@ -57,19 +55,18 @@ GameObject* GetPauseMenu() {
#endif

void CameraController::OnEnable() {
fpfcEnabled = true;
LOG_INFO("CameraController enable");

movementF = {0, 0, 0};
movementB = {0, 0, 0};
scroll = 0;

#ifdef BEAT_SABER
GetControllers();
#endif
}

void CameraController::OnDisable() {
fpfcEnabled = false;
LOG_INFO("CameraController disable");

click = false;
Expand Down Expand Up @@ -113,7 +110,7 @@ void CameraController::KeyDown(StringW key) {
keyboardOpen->deleteButtonWasPressedEvent->Invoke();
else if (key == "Enter")
keyboardOpen->okButtonWasPressedEvent->Invoke();
else
else if (key->Length == 1)
keyboardOpen->keyWasPressedEvent->Invoke(key[0]);
return;
}
Expand Down Expand Up @@ -195,6 +192,16 @@ void CameraController::MouseUp() {
#endif
}

void CameraController::AddScroll(float amount) {
scroll += amount;
}

float CameraController::GetScroll() {
float ret = scroll;
scroll = 0;
return ret;
}

#ifdef BEAT_SABER
void CameraController::GetControllers() {
controller0 = nullptr;
Expand Down
34 changes: 28 additions & 6 deletions qmod/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ void onSceneLoad(SceneManagement::Scene scene, SceneManagement::LoadSceneMode) {
if (UnityW(mainCamera))
mainCamera->set_enabled(!fpfc->get_enabled());
#ifdef BEAT_SABER
fpfc->GetControllers();
if (fpfc->get_enabled())
fpfc->GetControllers();
#endif
}

Expand Down Expand Up @@ -123,11 +124,14 @@ void onSceneLoad(SceneManagement::Scene scene, SceneManagement::LoadSceneMode) {
float y = std::stoi(packet.substr(7, 4));
fpfc->Rotate({x, y});
}
} else if (packet.starts_with("scr") && packet.size() >= 4) {
float scroll = std::stof(packet.substr(3, 5));
fpfc->AddScroll(scroll);
} else if (packet.starts_with("start")) {
moveSensitivity = std::stof(packet.substr(5, 5));
rotateSensitivity = std::stof(packet.substr(10, 5));
int fps = std::stoi(packet.substr(15, 3));
float fov = std::stoi(packet.substr(18, 5)) * 20;
float fov = std::stof(packet.substr(18, 5)) * 20;
streamer->Init(1080, 720, fps, 10000000, fov);
if (UnityW(mainCamera))
mainCamera->set_enabled(false);
Expand Down Expand Up @@ -158,6 +162,7 @@ extern "C" void setup(CModInfo* info) {
#include "GlobalNamespace/BloomPrePass.hpp"
#include "GlobalNamespace/DefaultScenesTransitionsFromInit.hpp"
#include "GlobalNamespace/MainCamera.hpp"
#include "GlobalNamespace/OculusVRHelper.hpp"
#include "GlobalNamespace/UIKeyboardManager.hpp"
#include "GlobalNamespace/VRPlatformUtils.hpp"
#include "UnityEngine/Input.hpp"
Expand Down Expand Up @@ -192,7 +197,7 @@ MAKE_HOOK_MATCH(
static bool clickedLastFrame = false;

auto ret = VRInputModule_GetMousePointerEventData(self, id);
if (fpfcEnabled) {
if (fpfc && fpfc->get_enabled()) {
auto state = EventData::FramePressState::NotChanged;
if (click && !clickedLastFrame)
state = EventData::FramePressState::Pressed;
Expand All @@ -212,11 +217,27 @@ MAKE_HOOK_MATCH(
IVRPlatformHelper* self
) {
auto ret = VRPlatformUtils_GetAnyJoystickMaxAxisDefaultImplementation(self);
if (fpfcEnabled)
return {0, UnityEngine::Input::GetAxis("Mouse ScrollWheel")};
if (fpfc && fpfc->get_enabled())
return {0, fpfc->GetScroll()};
return ret;
}

MAKE_HOOK_MATCH(
OculusVRHelper_TriggerHapticPulse,
&OculusVRHelper::TriggerHapticPulse,
void,
OculusVRHelper* self,
XR::XRNode node,
float duration,
float strength,
float frequency
) {
if (fpfc && fpfc->get_enabled())
return;

OculusVRHelper_TriggerHapticPulse(self, node, duration, strength, frequency);
}

MAKE_HOOK_MATCH(UIKeyboardManager_OpenKeyboardFor, &UIKeyboardManager::OpenKeyboardFor, void, UIKeyboardManager* self, HMUI::InputFieldView* input) {

UIKeyboardManager_OpenKeyboardFor(self, input);
Expand Down Expand Up @@ -268,8 +289,9 @@ extern "C" void load() {
#ifdef BEAT_SABER
LOG_INFO("Installing hooks...");
INSTALL_HOOK(logger, DefaultScenesTransitionsFromInit_TransitionToNextScene);
// INSTALL_HOOK(logger, VRPlatformUtils_GetAnyJoystickMaxAxisDefaultImplementation);
INSTALL_HOOK(logger, VRPlatformUtils_GetAnyJoystickMaxAxisDefaultImplementation);
INSTALL_HOOK(logger, VRInputModule_GetMousePointerEventData);
INSTALL_HOOK(logger, OculusVRHelper_TriggerHapticPulse);
INSTALL_HOOK(logger, UIKeyboardManager_OpenKeyboardFor);
INSTALL_HOOK(logger, UIKeyboardManager_CloseKeyboard);
#ifdef UNITY_2021
Expand Down
11 changes: 6 additions & 5 deletions src/Stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,31 @@ function Stream() {
const [pointerLocked, setPointerLocked] = createSignal(false);

const onMouseMove = (event: MouseEvent) => {
// console.log("mouse move", event.movementX, event.movementY);
socket?.send(
"mse" + format(event.movementX, 4) + format(-event.movementY, 4),
);
};

const onMouseDown = (event: MouseEvent) => {
// console.log("mouse down", event.button, event.button === 0);
if (event.button === 0) socket?.send("msed");
};

const onMouseUp = (event: MouseEvent) => {
// console.log("mouse up", event.button, event.button === 0);
if (event.button === 0) socket?.send("mseu");
};

const onKeyDown = (event: KeyboardEvent) => {
// console.log("key down", event.key);
socket?.send("keyd" + event.key);
};

const onKeyUp = (event: KeyboardEvent) => {
// console.log("key up", event.key);
socket?.send("keyu" + event.key);
};

const onWheel = (event: WheelEvent) => {
socket?.send("scr" + fformat(-event.deltaY / 50, 5));
};

document.addEventListener("pointerlockchange", () => {
setPointerLocked(
canvas !== undefined && document.pointerLockElement === canvas,
Expand All @@ -186,12 +185,14 @@ function Stream() {
document.addEventListener("mouseup", onMouseUp);
document.addEventListener("keydown", onKeyDown);
document.addEventListener("keyup", onKeyUp);
document.addEventListener("wheel", onWheel);
} else {
document.removeEventListener("mousemove", onMouseMove);
document.removeEventListener("mousedown", onMouseDown);
document.removeEventListener("mouseup", onMouseUp);
document.removeEventListener("keydown", onKeyDown);
document.removeEventListener("keyup", onKeyUp);
document.removeEventListener("wheel", onWheel);
}
});

Expand Down

0 comments on commit 8e3bbbc

Please sign in to comment.