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 GitHub
parent 02141b151c
commit 8d4f657930
9 changed files with 84 additions and 1 deletions

View File

@ -8562,6 +8562,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

@ -1599,6 +1599,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

@ -43,6 +43,7 @@ u8 gOverrideFreezeCamera = FALSE;
enum RomhackCameraOverride gOverrideRomhackCamera = RCO_ALL;
u8 gRomhackCameraAllowCentering = TRUE;
u8 gOverrideAllowToxicGasCamera = FALSE;
u8 gRomhackCameraAllowDpad = FALSE;
/**
* @file camera.c
@ -12111,6 +12112,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;
}
@ -12257,13 +12273,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

@ -28354,6 +28354,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; }
@ -32509,6 +32526,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

@ -300,6 +300,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) {
#ifdef BETTERCAMERA
return sOverrideEnableCamera.override ? sOverrideEnableCamera.value : configEnableCamera;

View File

@ -53,6 +53,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

@ -642,6 +642,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
gOverrideEnvFx = -1;
gDjuiRenderBehindHud = false;
gRomhackCameraAllowCentering = TRUE;
gRomhackCameraAllowDpad = FALSE;
camera_reset_overrides();
dynos_mod_shutdown();
mods_clear(&gActiveMods);