Override envfx from Lua (#316)

* Override envfx from Lua

set_override_envfx(-1) to reset override

* Fix type mismatch
This commit is contained in:
Agent X 2023-03-23 14:46:15 -04:00 committed by GitHub
parent c79a001f5f
commit 1a86d46d95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 161 additions and 2 deletions

View file

@ -41,7 +41,8 @@ in_files = [
"src/pc/network/version.h", "src/pc/network/version.h",
"include/geo_commands.h", "include/geo_commands.h",
"include/level_commands.h", "include/level_commands.h",
"src/audio/external.h" "src/audio/external.h",
"src/game/envfx_snow.h"
] ]
exclude_constants = { exclude_constants = {

View file

@ -3263,6 +3263,33 @@ RESOLUTION_N64 = 1
--- @type HudUtilsResolution --- @type HudUtilsResolution
RESOLUTION_COUNT = 2 RESOLUTION_COUNT = 2
--- @type integer
ENVFX_BUBBLE_START = 10
--- @type integer
ENVFX_FLOWERS = 11
--- @type integer
ENVFX_JETSTREAM_BUBBLES = 14
--- @type integer
ENVFX_LAVA_BUBBLES = 12
--- @type integer
ENVFX_MODE_NONE = 0
--- @type integer
ENVFX_SNOW_BLIZZARD = 3
--- @type integer
ENVFX_SNOW_NORMAL = 1
--- @type integer
ENVFX_SNOW_WATER = 2
--- @type integer
ENVFX_WHIRLPOOL_BUBBLES = 13
--- @type integer --- @type integer
SEQ_PLAYER_ENV = 1 SEQ_PLAYER_ENV = 1

View file

@ -8296,6 +8296,11 @@ function get_dialog_id()
-- ... -- ...
end end
--- @return integer
function get_envfx()
-- ...
end
--- @param index integer --- @param index integer
--- @return number --- @return number
function get_environment_region(index) function get_environment_region(index)
@ -8453,6 +8458,12 @@ function set_lighting_dir(index, value)
-- ... -- ...
end end
--- @param envfx integer
--- @return nil
function set_override_envfx(envfx)
-- ...
end
--- @param far number --- @param far number
--- @return nil --- @return nil
function set_override_far(far) function set_override_far(far)

View file

@ -14,6 +14,7 @@
- [djui_hud_utils.h](#djui_hud_utilsh) - [djui_hud_utils.h](#djui_hud_utilsh)
- [enum DjuiFontType](#enum-DjuiFontType) - [enum DjuiFontType](#enum-DjuiFontType)
- [enum HudUtilsResolution](#enum-HudUtilsResolution) - [enum HudUtilsResolution](#enum-HudUtilsResolution)
- [envfx_snow.h](#envfx_snowh)
- [external.h](#externalh) - [external.h](#externalh)
- [geo_commands.h](#geo_commandsh) - [geo_commands.h](#geo_commandsh)
- [graph_node.h](#graph_nodeh) - [graph_node.h](#graph_nodeh)
@ -1101,6 +1102,21 @@
<br /> <br />
## [envfx_snow.h](#envfx_snow.h)
- ENVFX_BUBBLE_START
- ENVFX_FLOWERS
- ENVFX_JETSTREAM_BUBBLES
- ENVFX_LAVA_BUBBLES
- ENVFX_MODE_NONE
- ENVFX_SNOW_BLIZZARD
- ENVFX_SNOW_NORMAL
- ENVFX_SNOW_WATER
- ENVFX_WHIRLPOOL_BUBBLES
[:arrow_up_small:](#)
<br />
## [external.h](#external.h) ## [external.h](#external.h)
- SEQ_PLAYER_ENV - SEQ_PLAYER_ENV
- SEQ_PLAYER_LEVEL - SEQ_PLAYER_LEVEL

View file

@ -8196,6 +8196,24 @@
<br /> <br />
## [get_envfx](#get_envfx)
### Lua Example
`local integerValue = get_envfx()`
### Parameters
- None
### Returns
- `integer`
### C Prototype
`u16 get_envfx(void);`
[:arrow_up_small:](#)
<br />
## [get_environment_region](#get_environment_region) ## [get_environment_region](#get_environment_region)
### Lua Example ### Lua Example
@ -8693,6 +8711,26 @@
<br /> <br />
## [set_override_envfx](#set_override_envfx)
### Lua Example
`set_override_envfx(envfx)`
### Parameters
| Field | Type |
| ----- | ---- |
| envfx | `integer` |
### Returns
- None
### C Prototype
`void set_override_envfx(s32 envfx);`
[:arrow_up_small:](#)
<br />
## [set_override_far](#set_override_far) ## [set_override_far](#set_override_far)
### Lua Example ### Lua Example

View file

@ -1541,6 +1541,7 @@
- [get_current_save_file_num](functions-4.md#get_current_save_file_num) - [get_current_save_file_num](functions-4.md#get_current_save_file_num)
- [get_dialog_box_state](functions-4.md#get_dialog_box_state) - [get_dialog_box_state](functions-4.md#get_dialog_box_state)
- [get_dialog_id](functions-4.md#get_dialog_id) - [get_dialog_id](functions-4.md#get_dialog_id)
- [get_envfx](functions-4.md#get_envfx)
- [get_environment_region](functions-4.md#get_environment_region) - [get_environment_region](functions-4.md#get_environment_region)
- [get_hand_foot_pos_x](functions-4.md#get_hand_foot_pos_x) - [get_hand_foot_pos_x](functions-4.md#get_hand_foot_pos_x)
- [get_hand_foot_pos_y](functions-4.md#get_hand_foot_pos_y) - [get_hand_foot_pos_y](functions-4.md#get_hand_foot_pos_y)
@ -1566,6 +1567,7 @@
- [set_environment_region](functions-4.md#set_environment_region) - [set_environment_region](functions-4.md#set_environment_region)
- [set_last_star_or_key](functions-4.md#set_last_star_or_key) - [set_last_star_or_key](functions-4.md#set_last_star_or_key)
- [set_lighting_dir](functions-4.md#set_lighting_dir) - [set_lighting_dir](functions-4.md#set_lighting_dir)
- [set_override_envfx](functions-4.md#set_override_envfx)
- [set_override_far](functions-4.md#set_override_far) - [set_override_far](functions-4.md#set_override_far)
- [set_override_fov](functions-4.md#set_override_fov) - [set_override_fov](functions-4.md#set_override_fov)
- [set_override_near](functions-4.md#set_override_near) - [set_override_near](functions-4.md#set_override_near)

View file

@ -9,6 +9,9 @@
#include "envfx_snow.h" #include "envfx_snow.h"
#include "level_geo.h" #include "level_geo.h"
u16 gReadOnlyEnvFx = 0;
s32 gOverrideEnvFx = -1;
/** /**
* Geo function that generates a displaylist for environment effects such as * Geo function that generates a displaylist for environment effects such as
* snow or jet stream bubbles. * snow or jet stream bubbles.
@ -27,7 +30,8 @@ Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtxf) {
if (GET_HIGH_U16_OF_32(*params) != gAreaUpdateCounter) { if (GET_HIGH_U16_OF_32(*params) != gAreaUpdateCounter) {
UNUSED struct Camera *sp2C = gCurGraphNodeCamera->config.camera; UNUSED struct Camera *sp2C = gCurGraphNodeCamera->config.camera;
s32 snowMode = GET_LOW_U16_OF_32(*params); gReadOnlyEnvFx = GET_LOW_U16_OF_32(*params);
s32 snowMode = gOverrideEnvFx == -1 ? gReadOnlyEnvFx : gOverrideEnvFx;
vec3f_to_vec3s(camTo, gCurGraphNodeCamera->focus); vec3f_to_vec3s(camTo, gCurGraphNodeCamera->focus);
vec3f_to_vec3s(camFrom, gCurGraphNodeCamera->pos); vec3f_to_vec3s(camFrom, gCurGraphNodeCamera->pos);

View file

@ -11,6 +11,9 @@ struct Struct802761D0
u8 filler4[0x18-0x4]; u8 filler4[0x18-0x4];
}; };
extern u16 gReadOnlyEnvFx;
extern s32 gOverrideEnvFx;
Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf); Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf);
Gfx *geo_skybox_main(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx); Gfx *geo_skybox_main(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx);

View file

@ -1305,6 +1305,15 @@ char gSmluaConstants[] = ""
"FONT_MENU = 1\n" "FONT_MENU = 1\n"
"FONT_HUD = 2\n" "FONT_HUD = 2\n"
"FONT_COUNT = 3\n" "FONT_COUNT = 3\n"
"ENVFX_MODE_NONE = 0\n"
"ENVFX_SNOW_NORMAL = 1\n"
"ENVFX_SNOW_WATER = 2\n"
"ENVFX_SNOW_BLIZZARD = 3\n"
"ENVFX_BUBBLE_START = 10\n"
"ENVFX_FLOWERS = 11\n"
"ENVFX_LAVA_BUBBLES = 12\n"
"ENVFX_WHIRLPOOL_BUBBLES = 13\n"
"ENVFX_JETSTREAM_BUBBLES = 14\n"
"SEQ_PLAYER_LEVEL = 0\n" "SEQ_PLAYER_LEVEL = 0\n"
"SEQ_PLAYER_ENV = 1\n" "SEQ_PLAYER_ENV = 1\n"
"SEQ_PLAYER_SFX = 2\n" "SEQ_PLAYER_SFX = 2\n"

View file

@ -27072,6 +27072,21 @@ int smlua_func_get_dialog_id(UNUSED lua_State* L) {
return 1; return 1;
} }
int smlua_func_get_envfx(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", "get_envfx", 0, top);
return 0;
}
lua_pushinteger(L, get_envfx());
return 1;
}
int smlua_func_get_environment_region(lua_State* L) { int smlua_func_get_environment_region(lua_State* L) {
if (L == NULL) { return 0; } if (L == NULL) { return 0; }
@ -27511,6 +27526,23 @@ int smlua_func_set_lighting_dir(lua_State* L) {
return 1; return 1;
} }
int smlua_func_set_override_envfx(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", "set_override_envfx", 1, top);
return 0;
}
s32 envfx = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_override_envfx"); return 0; }
set_override_envfx(envfx);
return 1;
}
int smlua_func_set_override_far(lua_State* L) { int smlua_func_set_override_far(lua_State* L) {
if (L == NULL) { return 0; } if (L == NULL) { return 0; }
@ -30536,6 +30568,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "get_current_save_file_num", smlua_func_get_current_save_file_num); smlua_bind_function(L, "get_current_save_file_num", smlua_func_get_current_save_file_num);
smlua_bind_function(L, "get_dialog_box_state", smlua_func_get_dialog_box_state); smlua_bind_function(L, "get_dialog_box_state", smlua_func_get_dialog_box_state);
smlua_bind_function(L, "get_dialog_id", smlua_func_get_dialog_id); smlua_bind_function(L, "get_dialog_id", smlua_func_get_dialog_id);
smlua_bind_function(L, "get_envfx", smlua_func_get_envfx);
smlua_bind_function(L, "get_environment_region", smlua_func_get_environment_region); smlua_bind_function(L, "get_environment_region", smlua_func_get_environment_region);
smlua_bind_function(L, "get_hand_foot_pos_x", smlua_func_get_hand_foot_pos_x); smlua_bind_function(L, "get_hand_foot_pos_x", smlua_func_get_hand_foot_pos_x);
smlua_bind_function(L, "get_hand_foot_pos_y", smlua_func_get_hand_foot_pos_y); smlua_bind_function(L, "get_hand_foot_pos_y", smlua_func_get_hand_foot_pos_y);
@ -30561,6 +30594,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region); smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region);
smlua_bind_function(L, "set_last_star_or_key", smlua_func_set_last_star_or_key); smlua_bind_function(L, "set_last_star_or_key", smlua_func_set_last_star_or_key);
smlua_bind_function(L, "set_lighting_dir", smlua_func_set_lighting_dir); smlua_bind_function(L, "set_lighting_dir", smlua_func_set_lighting_dir);
smlua_bind_function(L, "set_override_envfx", smlua_func_set_override_envfx);
smlua_bind_function(L, "set_override_far", smlua_func_set_override_far); smlua_bind_function(L, "set_override_far", smlua_func_set_override_far);
smlua_bind_function(L, "set_override_fov", smlua_func_set_override_fov); smlua_bind_function(L, "set_override_fov", smlua_func_set_override_fov);
smlua_bind_function(L, "set_override_near", smlua_func_set_override_near); smlua_bind_function(L, "set_override_near", smlua_func_set_override_near);

View file

@ -20,6 +20,7 @@
#include "game/skybox.h" #include "game/skybox.h"
#include "pc/gfx/gfx_pc.h" #include "pc/gfx/gfx_pc.h"
#include "include/course_table.h" #include "include/course_table.h"
#include "game/level_geo.h"
u32 get_network_area_timer(void) { u32 get_network_area_timer(void) {
return gNetworkAreaTimer; return gNetworkAreaTimer;
@ -427,3 +428,13 @@ void set_ttc_speed_setting(s16 speed) {
u32 get_time(void) { u32 get_time(void) {
return time(NULL); return time(NULL);
} }
///
u16 get_envfx(void) {
return gReadOnlyEnvFx;
}
void set_override_envfx(s32 envfx) {
gOverrideEnvFx = envfx;
}

View file

@ -107,4 +107,7 @@ void set_ttc_speed_setting(s16 speed);
u32 get_time(void); u32 get_time(void);
u16 get_envfx(void);
void set_override_envfx(s32 envfx);
#endif #endif