Added romhack camera dpad functionality (#497)

* Aglambi (Added romhack camera dpad functionality)

* Remove this random comment on request

* Make dpad camera disabled by default

* Force axis alignment when dpad camera is off
This commit is contained in:
Sunk 2023-11-04 19:59:22 -04:00 committed by Agent X
parent 56e7470e7b
commit da5c4a68db
9 changed files with 84 additions and 1 deletions

View file

@ -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)

View file

@ -528,6 +528,26 @@
<br />
## [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:](#)
<br />
## [camera_set_romhack_override](#camera_set_romhack_override)
### Lua Example

View file

@ -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)

View file

@ -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;

View file

@ -20,6 +20,7 @@ extern u8 gOverrideFreezeCamera;
extern enum RomhackCameraOverride gOverrideRomhackCamera;
extern u8 gRomhackCameraAllowCentering;
extern u8 gOverrideAllowToxicGasCamera;
extern u8 gRomhackCameraAllowDpad;
/**
* @file camera.h

View file

@ -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);

View file

@ -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;
}

View file

@ -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);

View file

@ -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);