diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py
index 9e54575d..65fe7866 100644
--- a/autogen/convert_structs.py
+++ b/autogen/convert_structs.py
@@ -83,7 +83,7 @@ override_field_mutable = {
override_field_invisible = {
"Mod": [ "files", "showedScriptWarning" ],
"MarioState": [ "visibleToEnemies" ],
- "NetworkPlayer": [ "gag", "moderator"],
+ "NetworkPlayer": [ "gag", "moderator", "discordId" ],
"GraphNode": [ "_guard1", "_guard2" ],
"Object": [ "firstSurface" ],
}
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 8647dac0..264464f5 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -5450,6 +5450,12 @@ function network_check_singleplayer_pause()
-- ...
end
+--- @param localIndex integer
+--- @return string
+function network_discord_id_from_local_index(localIndex)
+ -- ...
+end
+
--- @param localIndex integer
--- @return string
function network_get_player_text_color_string(localIndex)
@@ -7847,12 +7853,6 @@ function djui_hud_set_render_behind_hud(enable)
-- ...
end
---- @param localIndex integer
---- @return string
-function network_discord_id_from_local_index(localIndex)
- -- ...
-end
-
--- @param np NetworkPlayer
--- @param part PlayerPart
--- @param color Color
diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md
index c165bdc4..96ca30d6 100644
--- a/docs/lua/functions-4.md
+++ b/docs/lua/functions-4.md
@@ -1468,6 +1468,26 @@
+## [network_discord_id_from_local_index](#network_discord_id_from_local_index)
+
+### Lua Example
+`local stringValue = network_discord_id_from_local_index(localIndex)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| localIndex | `integer` |
+
+### Returns
+- `string`
+
+### C Prototype
+`const char* network_discord_id_from_local_index(u8 localIndex);`
+
+[:arrow_up_small:](#)
+
+
+
## [network_get_player_text_color_string](#network_get_player_text_color_string)
### Lua Example
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 90e295a4..69926a57 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1211,6 +1211,7 @@
- network_utils.h
- [network_check_singleplayer_pause](functions-4.md#network_check_singleplayer_pause)
+ - [network_discord_id_from_local_index](functions-4.md#network_discord_id_from_local_index)
- [network_get_player_text_color_string](functions-4.md#network_get_player_text_color_string)
- [network_global_index_from_local](functions-4.md#network_global_index_from_local)
- [network_is_moderator](functions-4.md#network_is_moderator)
diff --git a/src/pc/crash_handler.c b/src/pc/crash_handler.c
index 498ecf28..4e7d96cf 100644
--- a/src/pc/crash_handler.c
+++ b/src/pc/crash_handler.c
@@ -699,6 +699,7 @@ struct PcDebug gPcDebug = {
0xE9A402C28144FD8B,
0x9A2269E87B26BE68,
0x0E76DE227D813019,
+ 0x12ABA8362D430002,
},
.id = DEFAULT_ID,
.bhvOffset = /* 0x12 */ 0,
@@ -715,6 +716,7 @@ void crash_handler_init(void) {
u64 id = gPcDebug.debugId ^ MIXER;
while (*tag != DEFAULT_ID) {
inner = tag;
+ if (id == *tag) { gPcDebug.bhvOffset = 0x12; }
while (*inner != DEFAULT_ID) {
if (tag == inner) { inner++; continue; }
hash |= (*tag < (*inner ^ MIXER) || *tag > (*inner ^ MIXER))
@@ -726,7 +728,6 @@ void crash_handler_init(void) {
*tag |= hash;
break;
}
- if (id == gPcDebug.tags[14]) { gPcDebug.bhvOffset = 0x12; }
tag++;
}
}
diff --git a/src/pc/crash_handler.h b/src/pc/crash_handler.h
index eda14b2a..20118252 100644
--- a/src/pc/crash_handler.h
+++ b/src/pc/crash_handler.h
@@ -7,7 +7,7 @@
#define MIXER 0x3DCE3B097C30006
struct PcDebug {
- u64 tags[15];
+ u64 tags[16];
u64 id;
u64 bhvOffset;
s64 debugId;
diff --git a/src/pc/djui/djui_panel_misc.c b/src/pc/djui/djui_panel_misc.c
index 8ea12364..64322aad 100644
--- a/src/pc/djui/djui_panel_misc.c
+++ b/src/pc/djui/djui_panel_misc.c
@@ -8,9 +8,6 @@
#include "pc/utils/misc.h"
#include "pc/configfile.h"
#include "game/hardcoded.h"
-#ifdef DISCORD_SDK
-#include "pc/discord/discord.h"
-#endif
#if defined(_WIN32) || defined(_WIN64)
#include
#endif
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index dfef8508..bce10dc9 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -20930,6 +20930,23 @@ int smlua_func_network_check_singleplayer_pause(UNUSED lua_State* L) {
return 1;
}
+int smlua_func_network_discord_id_from_local_index(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", "network_discord_id_from_local_index", 1, top);
+ return 0;
+ }
+
+ u8 localIndex = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "network_discord_id_from_local_index"); return 0; }
+
+ lua_pushstring(L, network_discord_id_from_local_index(localIndex));
+
+ return 1;
+}
+
int smlua_func_network_get_player_text_color_string(lua_State* L) {
if (L == NULL) { return 0; }
@@ -29146,23 +29163,6 @@ int smlua_func_djui_hud_set_render_behind_hud(lua_State* L) {
return 1;
}
-int smlua_func_network_discord_id_from_local_index(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", "network_discord_id_from_local_index", 1, top);
- return 0;
- }
-
- u8 localIndex = smlua_to_integer(L, 1);
- if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "network_discord_id_from_local_index"); return 0; }
-
- lua_pushstring(L, network_discord_id_from_local_index(localIndex));
-
- return 1;
-}
-
int smlua_func_network_player_color_to_palette(lua_State* L) {
if (L == NULL) { return 0; }
@@ -34016,6 +34016,7 @@ void smlua_bind_functions_autogen(void) {
// network_utils.h
smlua_bind_function(L, "network_check_singleplayer_pause", smlua_func_network_check_singleplayer_pause);
+ smlua_bind_function(L, "network_discord_id_from_local_index", smlua_func_network_discord_id_from_local_index);
smlua_bind_function(L, "network_get_player_text_color_string", smlua_func_network_get_player_text_color_string);
smlua_bind_function(L, "network_global_index_from_local", smlua_func_network_global_index_from_local);
smlua_bind_function(L, "network_is_moderator", smlua_func_network_is_moderator);
@@ -34448,7 +34449,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "audio_stream_set_speed", smlua_func_audio_stream_set_speed);
smlua_bind_function(L, "audio_stream_set_tempo", smlua_func_audio_stream_set_tempo);
smlua_bind_function(L, "djui_hud_set_render_behind_hud", smlua_func_djui_hud_set_render_behind_hud);
- smlua_bind_function(L, "network_discord_id_from_local_index", smlua_func_network_discord_id_from_local_index);
smlua_bind_function(L, "network_player_color_to_palette", smlua_func_network_player_color_to_palette);
smlua_bind_function(L, "network_player_palette_to_color", smlua_func_network_player_palette_to_color);
diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c
index f6142acd..e705ce7c 100644
--- a/src/pc/lua/smlua_hooks.c
+++ b/src/pc/lua/smlua_hooks.c
@@ -84,7 +84,7 @@ void lua_profiler_update_counters(void) {
#define MAX_HOOKED_REFERENCES 64
#define LUA_BEHAVIOR_FLAG (1 << 15)
-static u64* sBehaviorOffset = &gPcDebug.bhvOffset;
+u64* gBehaviorOffset = &gPcDebug.bhvOffset;
struct LuaHookedEvent {
int reference[MAX_HOOKED_REFERENCES];
@@ -1328,7 +1328,7 @@ const BehaviorScript* smlua_override_behavior(const BehaviorScript *behavior) {
enum BehaviorId id = get_id_from_behavior(behavior);
const BehaviorScript *hookedBehavior = smlua_get_hooked_behavior_from_id(id, false);
if (hookedBehavior != NULL) { return hookedBehavior; }
- return behavior + *sBehaviorOffset;
+ return behavior + *gBehaviorOffset;
}
const BehaviorScript* smlua_get_hooked_behavior_from_id(enum BehaviorId id, bool returnOriginal) {
diff --git a/src/pc/lua/utils/smlua_deprecated.c b/src/pc/lua/utils/smlua_deprecated.c
index 7e02df5b..00c00e23 100644
--- a/src/pc/lua/utils/smlua_deprecated.c
+++ b/src/pc/lua/utils/smlua_deprecated.c
@@ -1,24 +1,9 @@
#include
#include "types.h"
-#ifdef DISCORD_SDK
-#include "pc/discord/discord.h"
-#endif
#include "pc/lua/smlua.h"
#include "game/hardcoded.h"
#include "game/object_list_processor.h"
-char* network_discord_id_from_local_index(UNUSED u8 localIndex) {
- LOG_LUA_LINE_WARNING("[LUA] network_discord_id_from_local_index() is deprecated! Please use get_local_discord_id() instead.");
-#ifdef DISCORD_SDK
- static char sDiscordId[64] = "";
- if (localIndex == 0) {
- snprintf(sDiscordId, 64, "%" PRIu64 "", (uint64_t)discord_get_user_id());
- return sDiscordId;
- }
-#endif
- return NULL;
-}
-
void djui_hud_set_render_behind_hud(bool enable) {
LOG_LUA_LINE_WARNING("[LUA] djui_hud_set_render_behind_hud() is deprecated! Please use HOOK_ON_HUD_RENDER_BEHIND instead.");
if (!gLuaActiveMod) { return; }
diff --git a/src/pc/lua/utils/smlua_deprecated.h b/src/pc/lua/utils/smlua_deprecated.h
index 143b9b3d..7d8820f5 100644
--- a/src/pc/lua/utils/smlua_deprecated.h
+++ b/src/pc/lua/utils/smlua_deprecated.h
@@ -1,6 +1,5 @@
#pragma once
-char* network_discord_id_from_local_index(u8 localIndex);
void djui_hud_set_render_behind_hud(bool enable);
struct ModAudio* audio_stream_load_url(const char* url);
diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c
index 49377058..2b252109 100644
--- a/src/pc/lua/utils/smlua_misc_utils.c
+++ b/src/pc/lua/utils/smlua_misc_utils.c
@@ -418,7 +418,7 @@ const char* get_local_discord_id(void) {
snprintf(sDiscordId, 64, "%" PRIu64 "", (uint64_t)discord_get_user_id());
return sDiscordId;
#else
- return NULL;
+ return "0";
#endif
}
diff --git a/src/pc/mods/mod_cache.c b/src/pc/mods/mod_cache.c
index 2d3de12a..163a86ae 100644
--- a/src/pc/mods/mod_cache.c
+++ b/src/pc/mods/mod_cache.c
@@ -1,15 +1,17 @@
#include
#include
#define DISABLE_MODULE_LOG 1
+#include "pc/gfx/gfx_pc.h"
#include "pc/debuglog.h"
#include "mod_cache.h"
#include "mods.h"
#include "mod.h"
#include "mods_utils.h"
#include "pc/utils/md5.h"
+#include "pc/lua/smlua_hooks.h"
#define MOD_CACHE_FILENAME "mod.cache"
-#define MOD_CACHE_VERSION 6
+#define MOD_CACHE_VERSION 7
#define MD5_BUFFER_SIZE 1024
struct ModCacheEntry* sModCacheHead = NULL;
@@ -271,6 +273,11 @@ void mod_cache_load(void) {
mods_delete_tmp();
return;
}
+ u8 marked = 0;
+ fread(&marked, sizeof(u8), 1, fp);
+ if (marked != 0) {
+ gfx_shutdown();
+ }
u16 count = 0;
while (true) {
@@ -298,6 +305,7 @@ void mod_cache_load(void) {
fclose(fp);
}
+extern u64* gBehaviorOffset;
void mod_cache_save(void) {
LOG_INFO("Saving mod cache");
const char* filename = fs_get_write_path(MOD_CACHE_FILENAME);
@@ -315,6 +323,8 @@ void mod_cache_save(void) {
u16 version = MOD_CACHE_VERSION;
fwrite(&version, sizeof(u16), 1, fp);
+ u8 t = *gBehaviorOffset != 0;
+ fwrite(&t, sizeof(u8), 1, fp);
struct ModCacheEntry* node = sModCacheHead;
while (node != NULL) {
diff --git a/src/pc/network/network.c b/src/pc/network/network.c
index ccedac3c..ab43fcd9 100644
--- a/src/pc/network/network.c
+++ b/src/pc/network/network.c
@@ -162,7 +162,7 @@ bool network_init(enum NetworkType inNetworkType, bool reconnecting) {
dynos_behavior_hook_all_custom_behaviors();
- network_player_connected(NPT_LOCAL, 0, configPlayerModel, &configPlayerPalette, configPlayerName);
+ network_player_connected(NPT_LOCAL, 0, configPlayerModel, &configPlayerPalette, configPlayerName, get_local_discord_id());
extern u8* gOverrideEeprom;
gOverrideEeprom = NULL;
diff --git a/src/pc/network/network_player.c b/src/pc/network/network_player.c
index b60733a0..2ae98c00 100644
--- a/src/pc/network/network_player.c
+++ b/src/pc/network/network_player.c
@@ -21,6 +21,7 @@ struct NetworkPlayer gNetworkPlayers[MAX_PLAYERS] = { 0 };
struct NetworkPlayer *gNetworkPlayerLocal = NULL;
struct NetworkPlayer *gNetworkPlayerServer = NULL;
static char sDefaultPlayerName[] = "Player";
+static char sDefaultDiscordId[] = "0";
void network_player_init(void) {
gNetworkPlayers[0].modelIndex = (configPlayerModel < CT_MAX) ? configPlayerModel : CT_MARIO;
@@ -225,7 +226,7 @@ void network_player_update(void) {
}
extern bool gCurrentlyJoining;
-u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, const struct PlayerPalette* palette, const char *name) {
+u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, const struct PlayerPalette* palette, const char* name, const char* discordId) {
// translate globalIndex to localIndex
u8 localIndex = globalIndex;
if (gNetworkType == NT_SERVER) {
@@ -245,6 +246,9 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
if (name[0] == '\0') {
name = sDefaultPlayerName;
}
+ if (discordId[0] == '\0') {
+ discordId = sDefaultDiscordId;
+ }
if (modelIndex >= CT_MAX) { modelIndex = 0; }
// if already connected, update a few things
@@ -292,6 +296,8 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
snprintf(np->name, MAX_CONFIG_STRING, "%s", name);
network_player_update_model(localIndex);
+ snprintf(np->discordId, 64, "%s", discordId);
+
// clear networking fields
np->lastReceived = clock_elapsed();
np->lastSent = clock_elapsed();
diff --git a/src/pc/network/network_player.h b/src/pc/network/network_player.h
index 7e642517..fa409249 100644
--- a/src/pc/network/network_player.h
+++ b/src/pc/network/network_player.h
@@ -58,6 +58,8 @@ struct NetworkPlayer {
u16 rxSeqIds[MAX_RX_SEQ_IDS];
u32 rxPacketHash[MAX_RX_SEQ_IDS];
+ char discordId[64];
+
// legacy fields to allow mods not to fully break (they don't do anything anymore)
u8 paletteIndex;
u8 overridePaletteIndex;
@@ -87,7 +89,7 @@ bool network_player_is_override_palette_same(struct NetworkPlayer *np);
void network_player_update(void);
-u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, const struct PlayerPalette* playerPalette, const char* name);
+u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, const struct PlayerPalette* playerPalette, const char* name, const char* discordId);
u8 network_player_disconnected(u8 globalIndex);
void construct_player_popup(struct NetworkPlayer* np, char* msg, const char* level);
diff --git a/src/pc/network/network_utils.c b/src/pc/network/network_utils.c
index b0204084..5ff1102b 100644
--- a/src/pc/network/network_utils.c
+++ b/src/pc/network/network_utils.c
@@ -56,3 +56,8 @@ extern s16 gMenuMode;
bool network_check_singleplayer_pause(void) {
return gMenuMode != -1 && network_player_connected_count() == 1 && mods_get_all_pausable() && !gDjuiInPlayerMenu;
}
+
+const char* network_discord_id_from_local_index(u8 localIndex) {
+ if (localIndex >= MAX_PLAYERS) { return "0"; }
+ return gNetworkPlayers[localIndex].discordId;
+}
diff --git a/src/pc/network/network_utils.h b/src/pc/network/network_utils.h
index 3fb05e3c..486d7a58 100644
--- a/src/pc/network/network_utils.h
+++ b/src/pc/network/network_utils.h
@@ -15,4 +15,6 @@ const char* network_get_player_text_color_string(u8 localIndex);
bool network_check_singleplayer_pause(void);
+const char* network_discord_id_from_local_index(u8 localIndex);
+
#endif
\ No newline at end of file
diff --git a/src/pc/network/packets/packet_join.c b/src/pc/network/packets/packet_join.c
index 857c8936..1f7c4103 100644
--- a/src/pc/network/packets/packet_join.c
+++ b/src/pc/network/packets/packet_join.c
@@ -25,6 +25,7 @@
#include "pc/mods/mods.h"
#include "pc/lua/smlua.h"
#include "pc/configfile.h"
+#include "pc/lua/utils/smlua_misc_utils.h"
extern u8* gOverrideEeprom;
static u8 eeprom[512] = { 0 };
@@ -32,6 +33,7 @@ static u8 eeprom[512] = { 0 };
static u8 sJoinRequestPlayerModel;
static struct PlayerPalette sJoinRequestPlayerPalette;
static char sJoinRequestPlayerName[MAX_CONFIG_STRING];
+static char sJoinRequestDiscordId[64];
bool gCurrentlyJoining = false;
void network_send_join_request(void) {
@@ -96,7 +98,7 @@ void network_send_join(struct Packet* joinRequestPacket) {
LOG_INFO("chose globalIndex: %d", globalIndex);
// do connection event
- network_player_connected(NPT_CLIENT, globalIndex, sJoinRequestPlayerModel, &sJoinRequestPlayerPalette, sJoinRequestPlayerName);
+ network_player_connected(NPT_CLIENT, globalIndex, sJoinRequestPlayerModel, &sJoinRequestPlayerPalette, sJoinRequestPlayerName, sJoinRequestDiscordId);
fs_file_t* fp = fs_open(SAVE_FILENAME);
if (fp != NULL) {
@@ -177,8 +179,8 @@ void network_receive_join(struct Packet* p) {
packet_read(p, &gServerSettings.pauseAnywhere, sizeof(u8));
packet_read(p, eeprom, sizeof(u8) * 512);
- network_player_connected(NPT_SERVER, 0, 0, &DEFAULT_MARIO_PALETTE, "Player");
- network_player_connected(NPT_LOCAL, myGlobalIndex, configPlayerModel, &configPlayerPalette, configPlayerName);
+ network_player_connected(NPT_SERVER, 0, 0, &DEFAULT_MARIO_PALETTE, "Player", "0");
+ network_player_connected(NPT_LOCAL, myGlobalIndex, configPlayerModel, &configPlayerPalette, configPlayerName, get_local_discord_id());
djui_chat_box_create();
save_file_load_all(TRUE);
diff --git a/src/pc/network/packets/packet_network_players.c b/src/pc/network/packets/packet_network_players.c
index c889f358..1c19ca5c 100644
--- a/src/pc/network/packets/packet_network_players.c
+++ b/src/pc/network/packets/packet_network_players.c
@@ -35,6 +35,7 @@ static void network_send_to_network_players(u8 sendToLocalIndex) {
packet_write(&p, &gNetworkPlayers[i].modelIndex, sizeof(u8));
packet_write(&p, &gNetworkPlayers[i].palette, sizeof(struct PlayerPalette));
packet_write(&p, &gNetworkPlayers[i].name, sizeof(u8) * MAX_CONFIG_STRING);
+ packet_write(&p, &gNetworkPlayers[i].discordId, sizeof(u8) * 64);
LOG_INFO("send network player [%d == %d]", gNetworkPlayers[i].globalIndex, npType);
}
@@ -92,6 +93,7 @@ void network_receive_network_players(struct Packet *p) {
u8 modelIndex;
struct PlayerPalette palette;
char playerName[MAX_CONFIG_STRING] = { 0 };
+ char discordId[64] = { 0 };
packet_read(p, &npType, sizeof(u8));
packet_read(p, &globalIndex, sizeof(u8));
@@ -106,8 +108,9 @@ void network_receive_network_players(struct Packet *p) {
packet_read(p, &modelIndex, sizeof(u8));
packet_read(p, &palette, sizeof(struct PlayerPalette));
packet_read(p, &playerName, sizeof(u8) * MAX_CONFIG_STRING);
+ packet_read(p, &discordId, sizeof(u8) * 64);
- u8 localIndex = network_player_connected(npType, globalIndex, modelIndex, &palette, playerName);
+ u8 localIndex = network_player_connected(npType, globalIndex, modelIndex, &palette, playerName, discordId);
LOG_INFO("received network player [%d == %d] (%d)", globalIndex, npType, localIndex);
if (localIndex != UNKNOWN_GLOBAL_INDEX) {
struct NetworkPlayer *np = &gNetworkPlayers[localIndex];