mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 03:55:11 +00:00
Started working toward allowing disconnection
This commit is contained in:
parent
3e6fd0829a
commit
d75b0e9133
19 changed files with 141 additions and 13 deletions
|
@ -53,5 +53,8 @@ const char* dynos_level_get_token(u32 index);
|
|||
Trajectory* dynos_level_get_trajectory(const char* name);
|
||||
void dynos_level_load_background(void *ptr);
|
||||
|
||||
// -- other -- //
|
||||
void dynos_mod_shutdown(void);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -12,6 +12,8 @@ extern "C" {
|
|||
#define POINTER_CODE (u32) 0x52544E50
|
||||
#define LUA_VAR_CODE (u32) 0x5641554C
|
||||
|
||||
#define MOD_PACK_INDEX 99
|
||||
|
||||
//
|
||||
// Enums
|
||||
//
|
||||
|
@ -644,6 +646,7 @@ void *DynOS_SwapCmd(void *aCmd);
|
|||
void *DynOS_UpdateCmd(void *aCmd);
|
||||
void DynOS_UpdateGfx();
|
||||
bool DynOS_IsTransitionActive();
|
||||
void DynOS_Mod_Shutdown();
|
||||
void DynOS_ReturnToMainMenu();
|
||||
|
||||
//
|
||||
|
@ -695,6 +698,7 @@ s32 DynOS_Level_GetCount();
|
|||
const s32 *DynOS_Level_GetList();
|
||||
s32 DynOS_Level_GetCourse(s32 aLevel);
|
||||
void DynOS_Level_Override(void* originalScript, void* newScript);
|
||||
void DynOS_Level_Unoverride();
|
||||
const void *DynOS_Level_GetScript(s32 aLevel);
|
||||
const u8 *DynOS_Level_GetName(s32 aLevel, bool aDecaps, bool aAddCourseNumber);
|
||||
const u8 *DynOS_Level_GetActName(s32 aLevel, s32 aAct, bool aDecaps, bool aAddStarNumber);
|
||||
|
@ -764,6 +768,7 @@ void DynOS_Actor_Valid(const void* aGeoref, ActorGfx& aActorGfx);
|
|||
void DynOS_Actor_Invalid(const void* aGeoref, s32 aPackIndex);
|
||||
void DynOS_Actor_Override(void** aSharedChild);
|
||||
void DynOS_Actor_Override_All(void);
|
||||
void DynOS_Actor_ModShutdown();
|
||||
|
||||
//
|
||||
// Anim Manager
|
||||
|
@ -784,6 +789,7 @@ void DynOS_Tex_Activate(DataNode<TexData>* aNode, bool aCustomTexture);
|
|||
void DynOS_Tex_Deactivate(DataNode<TexData>* aNode);
|
||||
void DynOS_Tex_AddCustom(const SysPath &aFilename, const char *aTexName);
|
||||
bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo);
|
||||
void DynOS_Tex_ModShutdown();
|
||||
|
||||
//
|
||||
// Lvl Manager
|
||||
|
@ -797,6 +803,7 @@ DataNode<MovtexQC>* DynOS_Lvl_GetMovtexQuadCollection(s32 index);
|
|||
Trajectory* DynOS_Lvl_GetTrajectory(const char* aName);
|
||||
void DynOS_Lvl_LoadBackground(void *aPtr);
|
||||
void* DynOS_Lvl_Override(void *aCmd);
|
||||
void DynOS_Lvl_ModShutdown();
|
||||
|
||||
//
|
||||
// Col Manager
|
||||
|
@ -804,6 +811,7 @@ void* DynOS_Lvl_Override(void *aCmd);
|
|||
|
||||
void DynOS_Col_Activate(const SysPath &aFilePath, const char *aCollisionName);
|
||||
Collision* DynOS_Col_Get(const char* collisionName);
|
||||
void DynOS_Col_ModShutdown();
|
||||
|
||||
//
|
||||
// Movtexqc Manager
|
||||
|
@ -812,6 +820,7 @@ Collision* DynOS_Col_Get(const char* collisionName);
|
|||
void DynOS_MovtexQC_Register(const char* name, s16 level, s16 area, s16 type);
|
||||
DataNode<MovtexQC>* DynOS_MovtexQC_GetFromId(u32 id);
|
||||
DataNode<MovtexQC>* DynOS_MovtexQC_GetFromIndex(s32 index);
|
||||
void DynOS_MovtexQC_ModShutdown();
|
||||
|
||||
//
|
||||
// Bin
|
||||
|
|
|
@ -156,4 +156,9 @@ void dynos_level_load_background(void *ptr) {
|
|||
DynOS_Lvl_LoadBackground(ptr);
|
||||
}
|
||||
|
||||
// -- other -- //
|
||||
void dynos_mod_shutdown(void) {
|
||||
DynOS_Mod_Shutdown();
|
||||
}
|
||||
|
||||
}
|
|
@ -46,6 +46,7 @@ struct DynosWarp {
|
|||
};
|
||||
|
||||
static void *sDynosLevelScripts[LEVEL_COUNT] = { NULL };
|
||||
static void *sDynosLevelScriptsOriginal[LEVEL_COUNT] = { NULL };
|
||||
static Array<DynosWarp> sDynosLevelWarps[LEVEL_COUNT] = { Array<DynosWarp>() };
|
||||
static Array<s32> sDynosLevelList = Array<s32>(); // Ordered by Course Id, COURSE_NONE excluded
|
||||
|
||||
|
@ -90,6 +91,7 @@ static s32 DynOS_Level_PreprocessMasterScript(u8 aType, void *aCmd) {
|
|||
void *_Script = (void *) DynOS_Level_CmdGet(aCmd, 0x0C);
|
||||
if (sDynosLevelNum >= 0 && sDynosLevelNum < LEVEL_COUNT && !sDynosLevelScripts[sDynosLevelNum]) {
|
||||
sDynosLevelScripts[sDynosLevelNum] = _Script;
|
||||
sDynosLevelScriptsOriginal[sDynosLevelNum] = _Script;
|
||||
}
|
||||
sDynosLevelNum = -1;
|
||||
return 2;
|
||||
|
@ -237,6 +239,15 @@ void DynOS_Level_Override(void* originalScript, void* newScript) {
|
|||
}
|
||||
}
|
||||
|
||||
void DynOS_Level_Unoverride() {
|
||||
for (s32 i = 0; i < LEVEL_COUNT; i++) {
|
||||
sDynosCurrentLevelNum = i;
|
||||
sDynosLevelWarps[i].Clear();
|
||||
sDynosLevelScripts[i] = sDynosLevelScriptsOriginal[i];
|
||||
DynOS_Level_ParseScript(sDynosLevelScripts[i], DynOS_Level_PreprocessScript);
|
||||
}
|
||||
}
|
||||
|
||||
const void *DynOS_Level_GetScript(s32 aLevel) {
|
||||
DynOS_Level_Init();
|
||||
return sDynosLevelScripts[aLevel];
|
||||
|
|
|
@ -66,3 +66,15 @@ void DynOS_UpdateGfx() {
|
|||
bool DynOS_IsTransitionActive() {
|
||||
return gWarpTransition.isActive;
|
||||
}
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
void DynOS_Mod_Shutdown() {
|
||||
DynOS_Actor_ModShutdown();
|
||||
DynOS_Col_ModShutdown();
|
||||
DynOS_Lvl_ModShutdown();
|
||||
DynOS_MovtexQC_ModShutdown();
|
||||
DynOS_Tex_ModShutdown();
|
||||
}
|
||||
|
|
|
@ -51,10 +51,10 @@ void DynOS_Actor_AddCustom(const SysPath &aFilename, const char *aActorName) {
|
|||
}
|
||||
|
||||
// Alloc and init the actors gfx list
|
||||
ActorGfx actorGfx;
|
||||
ActorGfx actorGfx = { 0 };
|
||||
actorGfx.mGfxData = _GfxData;
|
||||
actorGfx.mGraphNode = (GraphNode *) DynOS_Geo_GetGraphNode(geoLayout, false);
|
||||
actorGfx.mPackIndex = 99;
|
||||
actorGfx.mPackIndex = MOD_PACK_INDEX;
|
||||
|
||||
// Add to list
|
||||
DynOS_Actor_Valid(georef, actorGfx);
|
||||
|
@ -150,3 +150,27 @@ void DynOS_Actor_Override_All(void) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DynOS_Actor_ModShutdown() {
|
||||
auto& _DynosCustomActors = DynosCustomActors();
|
||||
while (_DynosCustomActors.Count() > 0) {
|
||||
auto& pair = _DynosCustomActors[0];
|
||||
DynOS_Actor_Invalid(pair.second, MOD_PACK_INDEX);
|
||||
free((void*)pair.first);
|
||||
_DynosCustomActors.Remove(0);
|
||||
}
|
||||
|
||||
auto& _ValidActors = DynosValidActors();
|
||||
for (auto it = _ValidActors.cbegin(); it != _ValidActors.cend();) {
|
||||
auto& actorGfx = it->second;
|
||||
if (actorGfx.mPackIndex == MOD_PACK_INDEX) {
|
||||
free(actorGfx.mGraphNode);
|
||||
DynOS_Gfx_Free(actorGfx.mGfxData);
|
||||
_ValidActors.erase(it++);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
DynOS_Actor_Override_All();
|
||||
}
|
||||
|
|
|
@ -54,3 +54,13 @@ Collision* DynOS_Col_Get(const char* collisionName) {
|
|||
// check builtin collisions
|
||||
return (Collision*)DynOS_Builtin_LvlCol_GetFromName(collisionName);
|
||||
}
|
||||
|
||||
void DynOS_Col_ModShutdown() {
|
||||
auto& _DynosCollisions = DynosCollisions();
|
||||
while (_DynosCollisions.Count() > 0) {
|
||||
auto& pair = _DynosCollisions[0];
|
||||
free((void*)pair.first);
|
||||
Delete(pair.second);
|
||||
_DynosCollisions.Remove(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,22 @@ Array<Pair<const char*, GfxData*>> &DynOS_Lvl_GetArray() {
|
|||
return sDynosCustomLevelScripts;
|
||||
}
|
||||
|
||||
void DynOS_Lvl_ModShutdown() {
|
||||
DynOS_Level_Unoverride();
|
||||
|
||||
auto& _CustomLevelScripts = DynOS_Lvl_GetArray();
|
||||
while (_CustomLevelScripts.Count() > 0) {
|
||||
auto& pair = _CustomLevelScripts[0];
|
||||
DynOS_Tex_Invalid(pair.second);
|
||||
Delete(pair.second);
|
||||
free((void*)pair.first);
|
||||
_CustomLevelScripts.Remove(0);
|
||||
}
|
||||
|
||||
auto& _OverrideLevelScripts = DynosOverrideLevelScripts();
|
||||
_OverrideLevelScripts.Clear();
|
||||
}
|
||||
|
||||
void DynOS_Lvl_Activate(s32 modIndex, const SysPath &aFilename, const char *aLevelName) {
|
||||
auto& _CustomLevelScripts = DynOS_Lvl_GetArray();
|
||||
auto& _OverrideLevelScripts = DynosOverrideLevelScripts();
|
||||
|
|
|
@ -67,3 +67,12 @@ DataNode<MovtexQC>* DynOS_MovtexQC_GetFromIndex(s32 index) {
|
|||
|
||||
return mMovtexQCs[index];
|
||||
}
|
||||
|
||||
void DynOS_MovtexQC_ModShutdown() {
|
||||
auto& _DynosRegisteredMovtexQCs = DynosRegisteredMovtexQCs();
|
||||
while (_DynosRegisteredMovtexQCs.Count() > 0) {
|
||||
auto& registered = _DynosRegisteredMovtexQCs[0];
|
||||
Delete(registered.dataNode);
|
||||
_DynosRegisteredMovtexQCs.Remove(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -422,6 +422,7 @@ void DynOS_Tex_AddCustom(const SysPath &aFilename, const char *aTexName) {
|
|||
// Load
|
||||
SysPath _PackFolder = "";
|
||||
DataNode<TexData>* _Node = DynOS_Tex_LoadFromBinary(_PackFolder, aFilename, _TexName, false);
|
||||
free(_TexName);
|
||||
if (_Node) {
|
||||
DynOS_Tex_Activate(_Node, true);
|
||||
}
|
||||
|
@ -468,3 +469,11 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) {
|
|||
aOutTexInfo->texture = (u8*)info->pointer;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DynOS_Tex_ModShutdown() {
|
||||
auto& _DynosCustomTexs = DynosCustomTexs();
|
||||
while (_DynosCustomTexs.Count() > 0) {
|
||||
auto& pair = _DynosCustomTexs[0];
|
||||
DynOS_Tex_Deactivate(pair.second);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ void djui_panel_join_message_error(char* message) {
|
|||
}
|
||||
|
||||
void djui_panel_join_message_cancel(struct DjuiBase* caller) {
|
||||
network_shutdown(true);
|
||||
network_shutdown(true, false);
|
||||
djui_panel_menu_back(caller);
|
||||
}
|
||||
|
||||
|
|
|
@ -180,6 +180,7 @@ void smlua_update(void) {
|
|||
void smlua_shutdown(void) {
|
||||
smlua_text_utils_reset_all();
|
||||
smlua_audio_utils_reset_all();
|
||||
audio_custom_shutdown();
|
||||
smlua_cobject_allowlist_shutdown();
|
||||
smlua_cpointer_allowlist_shutdown();
|
||||
lua_State* L = gLuaState;
|
||||
|
|
|
@ -418,7 +418,7 @@ void network_register_mod(char* modName) {
|
|||
string_linked_list_append(&gRegisteredMods, modName);
|
||||
}
|
||||
|
||||
void network_shutdown(bool sendLeaving) {
|
||||
void network_shutdown(bool sendLeaving, bool exiting) {
|
||||
if (gDjuiChatBox != NULL) {
|
||||
djui_base_destroy(&gDjuiChatBox->base);
|
||||
gDjuiChatBox = NULL;
|
||||
|
@ -440,4 +440,23 @@ void network_shutdown(bool sendLeaving) {
|
|||
}
|
||||
|
||||
gNetworkType = NT_NONE;
|
||||
|
||||
if (exiting) { return; }
|
||||
|
||||
// reset other stuff
|
||||
extern u8* gOverrideEeprom;
|
||||
gOverrideEeprom = NULL;
|
||||
dynos_mod_shutdown();
|
||||
mods_clear(&gActiveMods);
|
||||
mods_clear(&gRemoteMods);
|
||||
smlua_shutdown();
|
||||
extern s16 gChangeLevel;
|
||||
gChangeLevel = LEVEL_CASTLE_GROUNDS;
|
||||
|
||||
// TODO: enable
|
||||
/*extern bool gDjuiInMainMenu;
|
||||
if (!gDjuiInMainMenu) {
|
||||
gDjuiInMainMenu = true;
|
||||
djui_panel_main_create(NULL);
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -130,6 +130,6 @@ void network_receive(u8 localIndex, void* addr, u8* data, u16 dataLength);
|
|||
void* network_duplicate_address(u8 localIndex);
|
||||
void network_update(void);
|
||||
void network_register_mod(char* modName);
|
||||
void network_shutdown(bool sendLeaving);
|
||||
void network_shutdown(bool sendLeaving, bool exiting);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -157,7 +157,7 @@ void network_player_update(void) {
|
|||
#ifndef DEVELOPMENT
|
||||
if (elapsed > NETWORK_PLAYER_TIMEOUT * 1.5f) {
|
||||
LOG_INFO("dropping due to no server connectivity");
|
||||
network_shutdown(false);
|
||||
network_shutdown(false, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -273,7 +273,7 @@ u8 network_player_disconnected(u8 globalIndex) {
|
|||
LOG_ERROR("player disconnected, but it's local.. this shouldn't happen!");
|
||||
return UNKNOWN_GLOBAL_INDEX;
|
||||
} else {
|
||||
network_shutdown(true);
|
||||
network_shutdown(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ void network_receive_join(struct Packet* p) {
|
|||
packet_read(p, &remoteVersion, sizeof(u8) * MAX_VERSION_LENGTH);
|
||||
LOG_INFO("server has version: %s", version);
|
||||
if (memcmp(version, remoteVersion, MAX_VERSION_LENGTH) != 0) {
|
||||
network_shutdown(true);
|
||||
network_shutdown(true, false);
|
||||
LOG_ERROR("version mismatch");
|
||||
char mismatchMessage[256] = { 0 };
|
||||
snprintf(mismatchMessage, 256, "\\#ffa0a0\\Error:\\#c8c8c8\\ Version mismatch.\n\nYour version: \\#a0a0ff\\%s\\#c8c8c8\\\nTheir version: \\#a0a0ff\\%s\\#c8c8c8\\\n\nSomeone is out of date!\n", version, remoteVersion);
|
||||
|
@ -186,7 +186,7 @@ void network_receive_join(struct Packet* p) {
|
|||
}
|
||||
|
||||
if (string_linked_list_mismatch(&gRegisteredMods, &head)) {
|
||||
network_shutdown(true);
|
||||
network_shutdown(true, false);
|
||||
|
||||
struct StringBuilder* builder = string_builder_create(512);
|
||||
string_builder_append(builder, "\\#ffa0a0\\Error:\\#c8c8c8\\ mods don't match.\n\n");
|
||||
|
|
|
@ -32,5 +32,5 @@ void network_receive_kick(struct Packet* p) {
|
|||
case EKT_BANNED: djui_panel_join_message_error("\\#ffa0a0\\Error:\\#c8c8c8\\ The server banned you."); break;
|
||||
default: djui_panel_join_message_error("\\#ffa0a0\\Error:\\#c8c8c8\\ Host has closed the connection."); break;
|
||||
}
|
||||
network_shutdown(false);
|
||||
network_shutdown(false, false);
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ void network_receive_mod_list(struct Packet* p) {
|
|||
packet_read(p, &remoteVersion, sizeof(u8) * MAX_VERSION_LENGTH);
|
||||
LOG_INFO("server has version: %s", version);
|
||||
if (memcmp(version, remoteVersion, MAX_VERSION_LENGTH) != 0) {
|
||||
network_shutdown(true);
|
||||
network_shutdown(true, false);
|
||||
LOG_ERROR("version mismatch");
|
||||
char mismatchMessage[256] = { 0 };
|
||||
snprintf(mismatchMessage, 256, "\\#ffa0a0\\Error:\\#c8c8c8\\ Version mismatch.\n\nYour version: \\#a0a0ff\\%s\\#c8c8c8\\\nTheir version: \\#a0a0ff\\%s\\#c8c8c8\\\n\nSomeone is out of date!\n", version, remoteVersion);
|
||||
|
@ -205,7 +205,7 @@ void network_receive_mod_list_entry(struct Packet* p) {
|
|||
// sanity check mod size
|
||||
if (mod->size >= MAX_MOD_SIZE) {
|
||||
djui_popup_create("Server had too large of a mod.\nQuitting.", 4);
|
||||
network_shutdown(false);
|
||||
network_shutdown(false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ void game_deinit(void) {
|
|||
audio_custom_shutdown();
|
||||
audio_shutdown();
|
||||
gfx_shutdown();
|
||||
network_shutdown(true);
|
||||
network_shutdown(true, true);
|
||||
smlua_shutdown();
|
||||
mods_shutdown();
|
||||
inited = false;
|
||||
|
|
Loading…
Reference in a new issue