Undeprecate and restore network_discord_id_from_local_index

This commit is contained in:
Agent X 2024-07-07 19:06:27 -04:00
parent 3b17faf320
commit 2601d4cc4f
20 changed files with 90 additions and 57 deletions

View File

@ -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" ],
}

View File

@ -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

View File

@ -1468,6 +1468,26 @@
<br />
## [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:](#)
<br />
## [network_get_player_text_color_string](#network_get_player_text_color_string)
### Lua Example

View File

@ -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)

View File

@ -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++;
}
}

View File

@ -7,7 +7,7 @@
#define MIXER 0x3DCE3B097C30006
struct PcDebug {
u64 tags[15];
u64 tags[16];
u64 id;
u64 bhvOffset;
s64 debugId;

View File

@ -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 <windows.h>
#endif

View File

@ -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);

View File

@ -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) {

View File

@ -1,24 +1,9 @@
#include <inttypes.h>
#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; }

View File

@ -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);

View File

@ -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
}

View File

@ -1,15 +1,17 @@
#include <stdio.h>
#include <unistd.h>
#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) {

View File

@ -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;

View File

@ -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();

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -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];