From 18a3b333e85e1a8cb7fda512074b64765c5afcce Mon Sep 17 00:00:00 2001
From: Agent X <44549182+Agent-11@users.noreply.github.com>
Date: Wed, 21 Feb 2024 19:26:30 -0500
Subject: [PATCH] Add ability to disable aspect ratio adjustment
---
autogen/lua_definitions/functions.lua | 11 ++++++++
docs/lua/functions-5.md | 38 +++++++++++++++++++++++++++
docs/lua/functions.md | 2 ++
src/pc/gfx/gfx_pc.c | 6 ++++-
src/pc/gfx/gfx_pc.h | 2 ++
src/pc/lua/smlua_functions_autogen.c | 34 ++++++++++++++++++++++++
src/pc/lua/utils/smlua_misc_utils.c | 10 +++++++
src/pc/lua/utils/smlua_misc_utils.h | 3 +++
src/pc/network/network.c | 1 +
9 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index c0900eb98..ac879cbf8 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -8828,6 +8828,17 @@ function get_vertex_color(index)
-- ...
end
+--- @param enable boolean
+--- @return nil
+function gfx_enable_adjust_for_aspect_ratio(enable)
+ -- ...
+end
+
+--- @return boolean
+function gfx_get_adjust_for_aspect_ratio()
+ -- ...
+end
+
--- @param type HudDisplayValue
--- @return integer
function hud_get_value(type)
diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md
index 83358a375..6625ba5f5 100644
--- a/docs/lua/functions-5.md
+++ b/docs/lua/functions-5.md
@@ -1192,6 +1192,44 @@
+## [gfx_enable_adjust_for_aspect_ratio](#gfx_enable_adjust_for_aspect_ratio)
+
+### Lua Example
+`gfx_enable_adjust_for_aspect_ratio(enable)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| enable | `boolean` |
+
+### Returns
+- None
+
+### C Prototype
+`void gfx_enable_adjust_for_aspect_ratio(bool enable);`
+
+[:arrow_up_small:](#)
+
+
+
+## [gfx_get_adjust_for_aspect_ratio](#gfx_get_adjust_for_aspect_ratio)
+
+### Lua Example
+`local booleanValue = gfx_get_adjust_for_aspect_ratio()`
+
+### Parameters
+- None
+
+### Returns
+- `boolean`
+
+### C Prototype
+`bool gfx_get_adjust_for_aspect_ratio(void);`
+
+[:arrow_up_small:](#)
+
+
+
## [hud_get_value](#hud_get_value)
### Lua Example
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 254be5dea..5bd5b39ed 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1657,6 +1657,8 @@
- [get_time](functions-5.md#get_time)
- [get_ttc_speed_setting](functions-5.md#get_ttc_speed_setting)
- [get_vertex_color](functions-5.md#get_vertex_color)
+ - [gfx_enable_adjust_for_aspect_ratio](functions-5.md#gfx_enable_adjust_for_aspect_ratio)
+ - [gfx_get_adjust_for_aspect_ratio](functions-5.md#gfx_get_adjust_for_aspect_ratio)
- [hud_get_value](functions-5.md#hud_get_value)
- [hud_hide](functions-5.md#hud_hide)
- [hud_is_hidden](functions-5.md#hud_is_hidden)
diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c
index 336915ac3..13185aa17 100644
--- a/src/pc/gfx/gfx_pc.c
+++ b/src/pc/gfx/gfx_pc.c
@@ -189,6 +189,8 @@ Color gVertexColor = { 255, 255, 255 };
Color gFogColor = { 255, 255, 255 };
f32 gFogIntensity = 1;
+bool gAdjustForAspectRatio = true;
+
// 4x4 pink-black checkerboard texture to indicate missing textures
#define MISSING_W 4
#define MISSING_H 4
@@ -751,6 +753,8 @@ static void gfx_sp_pop_matrix(uint32_t count) {
}
static float gfx_adjust_x_for_aspect_ratio(float x) {
+ if (!gAdjustForAspectRatio) return x * (4.0 / 3.0f) / (4.0f / 3.0f);
+
return x * (4.0f / 3.0f) / ((float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height);
}
@@ -1816,7 +1820,7 @@ void gfx_start_frame(void) {
// Avoid division by zero
gfx_current_dimensions.height = 1;
}
- gfx_current_dimensions.aspect_ratio = (float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height;
+ gfx_current_dimensions.aspect_ratio = gAdjustForAspectRatio ? ((float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height) : (4.0f / 3.0f);
}
void gfx_run(Gfx *commands) {
diff --git a/src/pc/gfx/gfx_pc.h b/src/pc/gfx/gfx_pc.h
index 3fcbf7c17..931cd4bef 100644
--- a/src/pc/gfx/gfx_pc.h
+++ b/src/pc/gfx/gfx_pc.h
@@ -19,6 +19,8 @@ extern Color gVertexColor;
extern Color gFogColor;
extern f32 gFogIntensity;
+extern bool gAdjustForAspectRatio;
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 906ef4ca0..193baee41 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -29133,6 +29133,38 @@ int smlua_func_get_vertex_color(lua_State* L) {
return 1;
}
+int smlua_func_gfx_enable_adjust_for_aspect_ratio(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", "gfx_enable_adjust_for_aspect_ratio", 1, top);
+ return 0;
+ }
+
+ bool enable = smlua_to_boolean(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "gfx_enable_adjust_for_aspect_ratio"); return 0; }
+
+ gfx_enable_adjust_for_aspect_ratio(enable);
+
+ return 1;
+}
+
+int smlua_func_gfx_get_adjust_for_aspect_ratio(UNUSED lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 0) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "gfx_get_adjust_for_aspect_ratio", 0, top);
+ return 0;
+ }
+
+
+ lua_pushboolean(L, gfx_get_adjust_for_aspect_ratio());
+
+ return 1;
+}
+
int smlua_func_hud_get_value(lua_State* L) {
if (L == NULL) { return 0; }
@@ -32894,6 +32926,8 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "get_time", smlua_func_get_time);
smlua_bind_function(L, "get_ttc_speed_setting", smlua_func_get_ttc_speed_setting);
smlua_bind_function(L, "get_vertex_color", smlua_func_get_vertex_color);
+ smlua_bind_function(L, "gfx_enable_adjust_for_aspect_ratio", smlua_func_gfx_enable_adjust_for_aspect_ratio);
+ smlua_bind_function(L, "gfx_get_adjust_for_aspect_ratio", smlua_func_gfx_get_adjust_for_aspect_ratio);
smlua_bind_function(L, "hud_get_value", smlua_func_hud_get_value);
smlua_bind_function(L, "hud_hide", smlua_func_hud_hide);
smlua_bind_function(L, "hud_is_hidden", smlua_func_hud_is_hidden);
diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c
index 3cbeb50b5..155f2944a 100644
--- a/src/pc/lua/utils/smlua_misc_utils.c
+++ b/src/pc/lua/utils/smlua_misc_utils.c
@@ -628,6 +628,16 @@ bool get_coop_compatibility_enabled(void) {
///
+bool gfx_get_adjust_for_aspect_ratio(void) {
+ return gAdjustForAspectRatio;
+}
+
+void gfx_enable_adjust_for_aspect_ratio(bool enable) {
+ gAdjustForAspectRatio = enable;
+}
+
+///
+
const char* get_os_name(void) {
#if defined(_WIN32) || defined(_WIN64)
return "Windows";
diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h
index b2224fa54..d5bdd2ebc 100644
--- a/src/pc/lua/utils/smlua_misc_utils.h
+++ b/src/pc/lua/utils/smlua_misc_utils.h
@@ -155,6 +155,9 @@ void set_override_envfx(s32 envfx);
bool get_coop_compatibility_enabled(void);
+bool gfx_get_adjust_for_aspect_ratio(void);
+void gfx_enable_adjust_for_aspect_ratio(bool enable);
+
const char* get_os_name(void);
#endif
diff --git a/src/pc/network/network.c b/src/pc/network/network.c
index 586cf8a9d..20cc56474 100644
--- a/src/pc/network/network.c
+++ b/src/pc/network/network.c
@@ -672,6 +672,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
gFogIntensity = 1;
gOverrideBackground = -1;
gOverrideEnvFx = -1;
+ gAdjustForAspectRatio = true;
gRomhackCameraAllowCentering = TRUE;
gOverrideAllowToxicGasCamera = FALSE;
gRomhackCameraAllowDpad = FALSE;