diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 1b7e532f..8ab06dc6 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -8599,6 +8599,12 @@ function camera_romhack_allow_centering(allow)
-- ...
end
+--- @param allow integer
+--- @return nil
+function camera_romhack_allow_dpad_usage(allow)
+ -- ...
+end
+
--- @param rco RomhackCameraOverride
--- @return nil
function camera_set_romhack_override(rco)
diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md
index 1e374163..9698cd3f 100644
--- a/docs/lua/functions-5.md
+++ b/docs/lua/functions-5.md
@@ -528,6 +528,26 @@
+## [camera_romhack_allow_dpad_usage](#camera_romhack_allow_dpad_usage)
+
+### Lua Example
+`camera_romhack_allow_dpad_usage(allow)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| allow | `integer` |
+
+### Returns
+- None
+
+### C Prototype
+`void camera_romhack_allow_dpad_usage(u8 allow);`
+
+[:arrow_up_small:](#)
+
+
+
## [camera_set_romhack_override](#camera_set_romhack_override)
### Lua Example
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 6ee83ed7..a75ea83b 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1611,6 +1611,7 @@
- [camera_is_frozen](functions-5.md#camera_is_frozen)
- [camera_reset_overrides](functions-5.md#camera_reset_overrides)
- [camera_romhack_allow_centering](functions-5.md#camera_romhack_allow_centering)
+ - [camera_romhack_allow_dpad_usage](functions-5.md#camera_romhack_allow_dpad_usage)
- [camera_set_romhack_override](functions-5.md#camera_set_romhack_override)
- [camera_unfreeze](functions-5.md#camera_unfreeze)
- [course_is_main_course](functions-5.md#course_is_main_course)
diff --git a/src/game/camera.c b/src/game/camera.c
index 66749859..e35bd861 100644
--- a/src/game/camera.c
+++ b/src/game/camera.c
@@ -44,6 +44,7 @@ u8 gOverrideFreezeCamera = FALSE;
enum RomhackCameraOverride gOverrideRomhackCamera = RCO_ALL;
u8 gRomhackCameraAllowCentering = TRUE;
u8 gOverrideAllowToxicGasCamera = FALSE;
+u8 gRomhackCameraAllowDpad = FALSE;
/**
* @file camera.c
@@ -12085,6 +12086,21 @@ static f32 sRomHackWaterFocus = 0;
static f32 sRomHackWaterPitchOffset = 0;
u8 gRomHackCamSetCollisions = TRUE;
+s32 snap_to_45_degrees(s16 angle) {
+ if (angle % DEGREES(45)) {
+ s16 d1 = ABS(angle) % DEGREES(45);
+ s16 d2 = DEGREES(45) - d1;
+ if (angle > 0) {
+ if (d1 < d2) return angle - d1;
+ else return angle + d2;
+ } else {
+ if (d1 < d2) return angle + d1;
+ else return angle - d2;
+ }
+ }
+ return angle;
+}
+
void rom_hack_cam_set_collisions(u8 enable) {
gRomHackCamSetCollisions = enable;
}
@@ -12231,13 +12247,28 @@ void mode_rom_hack_camera(struct Camera *c) {
sRomHackZoom = 0;
}
+ // Thank you hackersm64
+ if (gRomhackCameraAllowDpad) {
+ if (gMarioStates[0].controller->buttonPressed & U_JPAD) {
+ sRomHackYaw = DEGREES(180 + 90) - gMarioStates[0].faceAngle[1];
+ } else if (gMarioStates[0].controller->buttonDown & L_JPAD) {
+ sRomHackYaw -= DEGREES(1) * (camera_config_is_x_inverted() ? -1 : 1);
+ } else if (gMarioStates[0].controller->buttonDown & R_JPAD) {
+ sRomHackYaw += DEGREES(1) * (camera_config_is_x_inverted() ? -1 : 1);
+ } else if (gMarioStates[0].controller->buttonPressed & D_JPAD) {
+ sRomHackYaw = snap_to_45_degrees(sRomHackYaw);
+ }
+ }
+
// center
if (gMarioStates[0].controller->buttonPressed & L_TRIG && gRomhackCameraAllowCentering) {
center_rom_hack_camera();
}
// clamp yaw
- sRomHackYaw = (sRomHackYaw / DEGREES(45)) * DEGREES(45);
+ if (!gRomhackCameraAllowDpad) {
+ sRomHackYaw = (sRomHackYaw / DEGREES(45)) * DEGREES(45);
+ }
// update the camera focus and such
Vec3f pos;
diff --git a/src/game/camera.h b/src/game/camera.h
index c140ee62..217ad751 100644
--- a/src/game/camera.h
+++ b/src/game/camera.h
@@ -20,6 +20,7 @@ extern u8 gOverrideFreezeCamera;
extern enum RomhackCameraOverride gOverrideRomhackCamera;
extern u8 gRomhackCameraAllowCentering;
extern u8 gOverrideAllowToxicGasCamera;
+extern u8 gRomhackCameraAllowDpad;
/**
* @file camera.h
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index bb65320a..eb3d46c2 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -28463,6 +28463,23 @@ int smlua_func_camera_romhack_allow_centering(lua_State* L) {
return 1;
}
+int smlua_func_camera_romhack_allow_dpad_usage(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 1) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "camera_romhack_allow_dpad_usage", 1, top);
+ return 0;
+ }
+
+ u8 allow = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "camera_romhack_allow_dpad_usage"); return 0; }
+
+ camera_romhack_allow_dpad_usage(allow);
+
+ return 1;
+}
+
int smlua_func_camera_set_romhack_override(lua_State* L) {
if (L == NULL) { return 0; }
@@ -32776,6 +32793,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "camera_is_frozen", smlua_func_camera_is_frozen);
smlua_bind_function(L, "camera_reset_overrides", smlua_func_camera_reset_overrides);
smlua_bind_function(L, "camera_romhack_allow_centering", smlua_func_camera_romhack_allow_centering);
+ smlua_bind_function(L, "camera_romhack_allow_dpad_usage", smlua_func_camera_romhack_allow_dpad_usage);
smlua_bind_function(L, "camera_set_romhack_override", smlua_func_camera_set_romhack_override);
smlua_bind_function(L, "camera_unfreeze", smlua_func_camera_unfreeze);
smlua_bind_function(L, "course_is_main_course", smlua_func_course_is_main_course);
diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c
index bf0d48b1..2c9aca17 100644
--- a/src/pc/lua/utils/smlua_misc_utils.c
+++ b/src/pc/lua/utils/smlua_misc_utils.c
@@ -305,6 +305,10 @@ void camera_allow_toxic_gas_camera(u8 allow) {
gOverrideAllowToxicGasCamera = allow;
}
+void camera_romhack_allow_dpad_usage(u8 allow) {
+ gRomhackCameraAllowDpad = allow;
+}
+
bool camera_config_is_free_cam_enabled(void) {
return sOverrideEnableCamera.override ? sOverrideEnableCamera.value : configEnableCamera;
}
diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h
index 1e997f23..32023695 100644
--- a/src/pc/lua/utils/smlua_misc_utils.h
+++ b/src/pc/lua/utils/smlua_misc_utils.h
@@ -62,6 +62,7 @@ bool camera_is_frozen(void);
void camera_set_romhack_override(enum RomhackCameraOverride rco);
void camera_romhack_allow_centering(u8 allow);
void camera_allow_toxic_gas_camera(u8 allow);
+void camera_romhack_allow_dpad_usage(u8 allow);
bool camera_config_is_free_cam_enabled(void);
bool camera_config_is_analog_cam_enabled(void);
diff --git a/src/pc/network/network.c b/src/pc/network/network.c
index fadfce61..f603d8cf 100644
--- a/src/pc/network/network.c
+++ b/src/pc/network/network.c
@@ -659,6 +659,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
gDjuiRenderBehindHud = false;
gRomhackCameraAllowCentering = TRUE;
gOverrideAllowToxicGasCamera = FALSE;
+ gRomhackCameraAllowDpad = FALSE;
camera_reset_overrides();
dynos_mod_shutdown();
mods_clear(&gActiveMods);