Add 'script warnings' for using deprecated functions, add new Discord ID function

This commit is contained in:
Agent X 2024-06-05 18:58:25 -04:00
parent 36ddaa65ac
commit 6305c20410
12 changed files with 85 additions and 4 deletions

View file

@ -8101,6 +8101,11 @@ function get_lighting_dir(index)
-- ...
end
--- @return string
function get_local_discord_id()
-- ...
end
--- @return integer
function get_network_area_timer()
-- ...

View file

@ -1997,6 +1997,24 @@
<br />
## [get_local_discord_id](#get_local_discord_id)
### Lua Example
`local stringValue = get_local_discord_id()`
### Parameters
- None
### Returns
- `string`
### C Prototype
`const char* get_local_discord_id(void);`
[:arrow_up_small:](#)
<br />
## [get_network_area_timer](#get_network_area_timer)
### Lua Example

View file

@ -1686,6 +1686,7 @@
- [get_last_star_or_key](functions-5.md#get_last_star_or_key)
- [get_lighting_color](functions-5.md#get_lighting_color)
- [get_lighting_dir](functions-5.md#get_lighting_dir)
- [get_local_discord_id](functions-5.md#get_local_discord_id)
- [get_network_area_timer](functions-5.md#get_network_area_timer)
- [get_os_name](functions-5.md#get_os_name)
- [get_save_file_modified](functions-5.md#get_save_file_modified)

View file

@ -150,7 +150,7 @@ DJUI_THEME = "DJUI Theme"
DJUI_SCALE = "DJUI Scale"
DJUI_FONT = "DJUI Font"
AUTO = "Auto"
CENTER = "Center"
CENTER = "DJUI Center"
FONT_NORMAL = "Normal"
FONT_ALIASED = "Aliased"
LIGHT_THEME = "Light"

View file

@ -124,8 +124,9 @@ void djui_connect_menu_open(void) {
djui_panel_join_message_create(NULL);
}
void djui_lua_error(char* text) {
void djui_lua_error(char* text, struct DjuiColor color) {
if (!sDjuiLuaError) { return; }
djui_base_set_color(&sDjuiLuaError->base, color.r, color.g, color.b, color.a);
djui_text_set_text(sDjuiLuaError, text);
djui_base_set_visible(&sDjuiLuaError->base, true);
sDjuiLuaErrorTimeout = 30 * 5;

View file

@ -43,7 +43,7 @@ extern bool gDjuiDisabled;
void djui_init(void);
void djui_init_late(void);
void djui_connect_menu_open(void);
void djui_lua_error(char* text);
void djui_lua_error(char* text, struct DjuiColor color);
void djui_render(void);
void djui_reset_hud_params(void);

View file

@ -23,7 +23,18 @@ void smlua_mod_error(void) {
if (mod == NULL) { return; }
char txt[255] = { 0 };
snprintf(txt, 254, "'%s\\#ff0000\\' has script errors!", mod->name);
djui_lua_error(txt);
static const struct DjuiColor color = { 255, 0, 0, 255 };
djui_lua_error(txt, color);
}
void smlua_mod_warning(void) {
struct Mod* mod = gLuaActiveMod;
if (mod == NULL) { mod = gLuaLastHookMod; }
if (mod == NULL) { return; }
char txt[255] = { 0 };
snprintf(txt, 254, "'%s\\#ffe600\\' is using deprecated functions!", mod->name);
static const struct DjuiColor color = { 255, 230, 0, 255 };
djui_lua_error(txt, color);
}
int smlua_error_handler(lua_State* L) {

View file

@ -39,6 +39,7 @@ extern struct Mod* gLuaActiveMod;
extern struct Mod* gLuaLastHookMod;
void smlua_mod_error(void);
void smlua_mod_warning(void);
int smlua_error_handler(UNUSED lua_State* L);
int smlua_pcall(lua_State* L, int nargs, int nresults, int errfunc);
void smlua_exec_file(const char* path);

View file

@ -29901,6 +29901,21 @@ int smlua_func_get_lighting_dir(lua_State* L) {
return 1;
}
int smlua_func_get_local_discord_id(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_local_discord_id", 0, top);
return 0;
}
lua_pushstring(L, get_local_discord_id());
return 1;
}
int smlua_func_get_network_area_timer(UNUSED lua_State* L) {
if (L == NULL) { return 0; }
@ -34070,6 +34085,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "get_last_star_or_key", smlua_func_get_last_star_or_key);
smlua_bind_function(L, "get_lighting_color", smlua_func_get_lighting_color);
smlua_bind_function(L, "get_lighting_dir", smlua_func_get_lighting_dir);
smlua_bind_function(L, "get_local_discord_id", smlua_func_get_local_discord_id);
smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer);
smlua_bind_function(L, "get_os_name", smlua_func_get_os_name);
smlua_bind_function(L, "get_save_file_modified", smlua_func_get_save_file_modified);

View file

@ -8,6 +8,7 @@
#include "game/object_list_processor.h"
char* network_discord_id_from_local_index(UNUSED u8 localIndex) {
smlua_mod_warning();
#ifdef DISCORD_SDK
static char sDiscordId[64] = "";
if (localIndex == 0) {
@ -19,25 +20,31 @@ char* network_discord_id_from_local_index(UNUSED u8 localIndex) {
}
void djui_hud_set_render_behind_hud(bool enable) {
smlua_mod_warning();
if (!gLuaActiveMod) { return; }
gLuaActiveMod->renderBehindHud = enable;
}
struct ModAudio* audio_stream_load_url(UNUSED const char* url) {
smlua_mod_warning();
return NULL;
}
f32 audio_stream_get_tempo(UNUSED struct ModAudio* audio) {
smlua_mod_warning();
return 1;
}
void audio_stream_set_tempo(UNUSED struct ModAudio* audio, UNUSED f32 tempo) {
smlua_mod_warning();
}
void audio_stream_set_speed(UNUSED struct ModAudio* audio, UNUSED f32 initial_freq, UNUSED f32 speed, UNUSED bool pitch) {
smlua_mod_warning();
}
f32 get_environment_region(u8 index) {
smlua_mod_warning();
s32 idx = 6 * index;
if (gEnvironmentRegions != NULL && index > 0 && index <= gEnvironmentRegions[0] && gEnvironmentRegionsLength > idx) {
return gEnvironmentRegions[idx];
@ -46,6 +53,7 @@ f32 get_environment_region(u8 index) {
}
void set_environment_region(u8 index, s32 value) {
smlua_mod_warning();
s32 idx = 6 * index;
if (gEnvironmentRegions != NULL && index > 0 && index <= gEnvironmentRegions[0] && gEnvironmentRegionsLength > idx) {
gEnvironmentRegions[idx] = value;
@ -53,6 +61,7 @@ void set_environment_region(u8 index, s32 value) {
}
void network_player_color_to_palette(struct NetworkPlayer *np, enum PlayerPart part, Color color) {
smlua_mod_warning();
if (np == NULL || !(part < PLAYER_PART_MAX && part >= 0)) { return; }
np->palette.parts[part][0] = color[0];
@ -62,6 +71,7 @@ void network_player_color_to_palette(struct NetworkPlayer *np, enum PlayerPart p
}
void network_player_palette_to_color(struct NetworkPlayer *np, enum PlayerPart part, Color out) {
smlua_mod_warning();
if (np == NULL || !(part < PLAYER_PART_MAX && part >= 0)) {
if (np == NULL) { // output config palette instead if np is NULL
out[0] = configPlayerPalette.parts[part][0];

View file

@ -25,6 +25,10 @@
#include "game/level_geo.h"
#include "game/first_person_cam.h"
#ifdef DISCORD_SDK
#include "pc/discord/discord.h"
#endif
static struct DateTime sDateTime;
///
@ -639,6 +643,18 @@ bool djui_is_playerlist_open(void) {
///
const char* get_local_discord_id(void) {
#ifdef DISCORD_SDK
static char sDiscordId[64] = "";
snprintf(sDiscordId, 64, "%" PRIu64 "", (uint64_t)discord_get_user_id());
return sDiscordId;
#else
return NULL;
#endif
}
///
void set_window_title(const char* title) {
WAPI.set_window_title(title);
}

View file

@ -167,6 +167,8 @@ s32 get_dialog_response(void);
bool djui_is_playerlist_open(void);
const char* get_local_discord_id(void);
void set_window_title(const char* title);
void reset_window_title(void);