fix of bowser castle crash (#70)

* fix of bowser castle crash

* format multiplayer

* Update MultiplayerWindow.cpp

* fix crash
This commit is contained in:
coco875
2024-09-10 19:43:34 +02:00
committed by GitHub
parent 56de6d00ea
commit cf05266bf9
5 changed files with 91 additions and 69 deletions
+57 -37
View File
@@ -25,11 +25,11 @@ void assign_player_control_types(void) {
if (clients[i].isAI) {
gPlayers[playerIndex].nControlFlags = 0;
} else if (clients[i].hasAuthority) {
//printf("PLAYER SLOT %d, INDEX %d\n", clients[i].slot, clients[i].character);
// printf("PLAYER SLOT %d, INDEX %d\n", clients[i].slot, clients[i].character);
// Set player to the camera
//cameras[0].playerId = clients[i].slot;
//D_800DC5EC->player = &gPlayers[clients[i].slot];
// cameras[0].playerId = clients[i].slot;
// D_800DC5EC->player = &gPlayers[clients[i].slot];
// printf("PLAYER SLOT %d, INDEX %d\n", clients[i].slot, clients[i].character);
gPlayers[playerIndex].nControlFlags =
PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE; // Requires server replication to move.
@@ -50,7 +50,6 @@ void network_cup_vote(uint32_t course) {
send_int_packet(gNetwork.tcpSocket, PACKET_COURSE_VOTE, course, sizeof(uint32_t));
}
void set_course(const char* data) {
if (data != NULL) {
gCupSelection = data[0];
@@ -121,12 +120,12 @@ void networking_start_session(const char* data) {
gGotoMode = RACING; // Enter race state
gGamestateNext = RACING;
gCCSelection = CC_150;
//gCupSelection = FLOWER_CUP;
// gCupSelection = FLOWER_CUP;
gCupCourseSelection = CUP_COURSE_ONE;
gScreenModeSelection = SCREEN_MODE_1P;
gModeSelection = GRAND_PRIX;
gPlayerCount = 1;
//gCurrentCourseId = 8;
// gCurrentCourseId = 8;
gDebugMenuSelection = DEBUG_MENU_EXITED;
func_8009E1C0();
func_800CA330(0x19);
@@ -165,20 +164,22 @@ void spawn_network_players(f32* arg0, f32* arg1, f32 arg2) {
u32 pos[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
printf("----- Spawn Players ------\n");
//for (size_t i = 0; i < NETWORK_MAX_PLAYERS; i++) {
//s32 playerIndex = clients[i].slot;
//printf("Spawned %s, in slot %d as char %d with flags 0x%X", clients[i].username, clients[i].slot, gPlayers[playerIndex].nCharacter, gPlayers[playerIndex].nControlFlags);
// for (size_t i = 0; i < NETWORK_MAX_PLAYERS; i++) {
// s32 playerIndex = clients[i].slot;
// printf("Spawned %s, in slot %d as char %d with flags 0x%X", clients[i].username, clients[i].slot,
// gPlayers[playerIndex].nCharacter, gPlayers[playerIndex].nControlFlags);
//if (gPlayers[playerIndex].nCharacter == -1) {
// printf("\n\nCORRUPT PLAYER DATA\n\n");
//} else {
//printf(" X: %d, Z: %d\n", arg0[D_80165270[posX[playerIndex]]], arg1[D_80165270[posZ[playerIndex]]] + 250.0f) ;
//spawn_player(&gPlayers[clients[i].slot], clients[i].slot, arg0[D_80165270[posX[clients[i].slot]]], arg1[D_80165270[posZ[clients[i].slot]]] + 250.0f, arg2, 32768.0f, clients[i].character, gPlayers[playerIndex].nControlFlags);
//}
// This index isn't right like this ^
// if (gPlayers[playerIndex].nCharacter == -1) {
// printf("\n\nCORRUPT PLAYER DATA\n\n");
// } else {
// printf(" X: %d, Z: %d\n", arg0[D_80165270[posX[playerIndex]]], arg1[D_80165270[posZ[playerIndex]]] + 250.0f) ;
// spawn_player(&gPlayers[clients[i].slot], clients[i].slot, arg0[D_80165270[posX[clients[i].slot]]],
// arg1[D_80165270[posZ[clients[i].slot]]] + 250.0f, arg2, 32768.0f, clients[i].character,
// gPlayers[playerIndex].nControlFlags);
// }
// This index isn't right like this ^
//if localClient.Slots
// if localClient.Slots
for (size_t i = 0; i < 8; i++) {
printf("a %d, %d\n", clients[i].slot, clients[i].character);
@@ -186,34 +187,53 @@ void spawn_network_players(f32* arg0, f32* arg1, f32 arg2) {
for (size_t i = 0; i < NETWORK_MAX_PLAYERS; i++) {
if (clients[i].hasAuthority) {
spawn_player(&gPlayers[0], i, arg0[clients[i].slot], arg1[clients[i].slot] + 250.0f, arg2, 32768.0f, clients[i].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
spawn_player(&gPlayers[0], i, arg0[clients[i].slot], arg1[clients[i].slot] + 250.0f, arg2, 32768.0f,
clients[i].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
}
}
for (size_t i = 0; i < NETWORK_MAX_PLAYERS - 1; i++) {
if (!clients[i].hasAuthority) {
spawn_player(&gPlayers[clients[i].slot], i, arg0[clients[i].slot], arg1[clients[i].slot] + 250.0f, arg2, 32768.0f, clients[i].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
spawn_player(&gPlayers[clients[i].slot], i, arg0[clients[i].slot], arg1[clients[i].slot] + 250.0f, arg2,
32768.0f, clients[i].character,
PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
}
}
// spawn_player(&gPlayers[clients[0].slot], 0, arg0[clients[0].slot], arg1[clients[0].slot] + 250.0f, arg2, 32768.0f, clients[0].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
// spawn_player(&gPlayers[clients[1].slot], 1, arg0[clients[1].slot], arg1[clients[1].slot] + 250.0f, arg2, 32768.0f, clients[1].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[2].slot], 2, arg0[clients[2].slot], arg1[clients[2].slot] + 250.0f, arg2, 32768.0f, clients[2].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[3].slot], 3, arg0[clients[3].slot], arg1[clients[3].slot] + 250.0f, arg2, 32768.0f, clients[3].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[4].slot], 4, arg0[clients[4].slot], arg1[clients[4].slot] + 250.0f, arg2, 32768.0f, clients[4].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[5].slot], 5, arg0[clients[5].slot], arg1[clients[5].slot] + 250.0f, arg2, 32768.0f, clients[5].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[6].slot], 6, arg0[clients[6].slot], arg1[clients[6].slot] + 250.0f, arg2, 32768.0f, clients[6].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[7].slot], 7, arg0[clients[7].slot], arg1[clients[7].slot] + 250.0f, arg2, 32768.0f, clients[7].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[0].slot], 0, arg0[clients[0].slot], arg1[clients[0].slot] + 250.0f, arg2,
// 32768.0f, clients[0].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
// spawn_player(&gPlayers[clients[1].slot], 1, arg0[clients[1].slot], arg1[clients[1].slot] + 250.0f, arg2,
// 32768.0f, clients[1].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[2].slot], 2, arg0[clients[2].slot], arg1[clients[2].slot] + 250.0f, arg2,
// 32768.0f, clients[2].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[3].slot], 3, arg0[clients[3].slot], arg1[clients[3].slot] + 250.0f, arg2,
// 32768.0f, clients[3].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[4].slot], 4, arg0[clients[4].slot], arg1[clients[4].slot] + 250.0f, arg2,
// 32768.0f, clients[4].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[5].slot], 5, arg0[clients[5].slot], arg1[clients[5].slot] + 250.0f, arg2,
// 32768.0f, clients[5].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[6].slot], 6, arg0[clients[6].slot], arg1[clients[6].slot] + 250.0f, arg2,
// 32768.0f, clients[6].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[7].slot], 7, arg0[clients[7].slot], arg1[clients[7].slot] + 250.0f, arg2,
// 32768.0f, clients[7].character, PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
//}
printf("--------------------------\n");
// gPlayers[i].nControlFlags
// spawn_player(&gPlayers[clients[0].slot], clients[0].slot, arg0[D_80165270[0]], arg1[D_80165270[0]] + 250.0f, arg2, 32768.0f, gCharacterSelections[0], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
// spawn_player(&gPlayers[clients[1].slot], clients[1].slot, arg0[D_80165270[1]], arg1[D_80165270[1]] + 250.0f, arg2, 32768.0f, chooseKartAIPlayers[0], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[2].slot], clients[2].slot, arg0[D_80165270[3]], arg1[D_80165270[2]] + 250.0f, arg2, 32768.0f, chooseKartAIPlayers[1], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[3].slot], clients[3].slot, arg0[D_80165270[2]], arg1[D_80165270[3]] + 250.0f, arg2, 32768.0f, chooseKartAIPlayers[2], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[4].slot], clients[4].slot, arg0[D_80165270[5]], arg1[D_80165270[4]] + 250.0f, arg2, 32768.0f, chooseKartAIPlayers[3], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[5].slot], clients[5].slot, arg0[D_80165270[4]], arg1[D_80165270[5]] + 250.0f, arg2, 32768.0f, chooseKartAIPlayers[4], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[6].slot], clients[6].slot, arg0[D_80165270[7]], arg1[D_80165270[6]] + 250.0f, arg2, 32768.0f, chooseKartAIPlayers[5], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[7].slot], clients[7].slot, arg0[D_80165270[6]], arg1[D_80165270[7]] + 250.0f, arg2, 32768.0f, chooseKartAIPlayers[6], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[0].slot], clients[0].slot, arg0[D_80165270[0]], arg1[D_80165270[0]] + 250.0f,
// arg2, 32768.0f, gCharacterSelections[0], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
// spawn_player(&gPlayers[clients[1].slot], clients[1].slot, arg0[D_80165270[1]], arg1[D_80165270[1]] + 250.0f,
// arg2, 32768.0f, chooseKartAIPlayers[0], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[2].slot], clients[2].slot, arg0[D_80165270[3]], arg1[D_80165270[2]] + 250.0f,
// arg2, 32768.0f, chooseKartAIPlayers[1], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[3].slot], clients[3].slot, arg0[D_80165270[2]], arg1[D_80165270[3]] + 250.0f,
// arg2, 32768.0f, chooseKartAIPlayers[2], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[4].slot], clients[4].slot, arg0[D_80165270[5]], arg1[D_80165270[4]] + 250.0f,
// arg2, 32768.0f, chooseKartAIPlayers[3], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[5].slot], clients[5].slot, arg0[D_80165270[4]], arg1[D_80165270[5]] + 250.0f,
// arg2, 32768.0f, chooseKartAIPlayers[4], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[6].slot], clients[6].slot, arg0[D_80165270[7]], arg1[D_80165270[6]] + 250.0f,
// arg2, 32768.0f, chooseKartAIPlayers[5], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
// spawn_player(&gPlayers[clients[7].slot], clients[7].slot, arg0[D_80165270[6]], arg1[D_80165270[7]] + 250.0f,
// arg2, 32768.0f, chooseKartAIPlayers[6], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_KART_AI);
}
+30 -30
View File
@@ -13,13 +13,13 @@ extern "C" {
#include "networking/networking.h"
#include "actor_types.h"
#include "code_800029B0.h"
struct Actor gActorList[];
extern char *gCourseNames[];
extern char *gCupNames[];
extern struct Actor gActorList[];
extern char* gCourseNames[];
extern char* gCupNames[];
extern char* D_800E76A8[];
extern Network gNetwork;
extern Camera cameras[];
extern UnkStruct_800DC5EC *D_800DC5EC;
extern UnkStruct_800DC5EC* D_800DC5EC;
}
namespace Multiplayer {
@@ -42,35 +42,35 @@ void MultiplayerWindow::DrawElement() {
if (!gNetwork.isConnected) {
static char username[NETWORK_USERNAME_LENGTH] = "TestUser";
static char username[NETWORK_USERNAME_LENGTH] = "TestUser";
ImGui::Text("Username:");
ImGui::InputText("##edit", username, IM_ARRAYSIZE(username));
ImGui::Text("Username:");
ImGui::InputText("##edit", username, IM_ARRAYSIZE(username));
static char address[32] = "127.0.0.1:64010";
static char addressCopy[32];
strncpy(addressCopy, address, sizeof(addressCopy));
addressCopy[sizeof(addressCopy) - 1] = '\0'; // Ensure null termination
static char address[32] = "127.0.0.1:64010";
static char addressCopy[32];
strncpy(addressCopy, address, sizeof(addressCopy));
addressCopy[sizeof(addressCopy) - 1] = '\0'; // Ensure null termination
ImGui::Text("Host:");
ImGui::InputText("##edit3", addressCopy, IM_ARRAYSIZE(addressCopy));
ImGui::Text("Host:");
ImGui::InputText("##edit3", addressCopy, IM_ARRAYSIZE(addressCopy));
if (ImGui::Button("Connect!")) {
char* ip = NULL;
uint16_t port = 0;
if (ImGui::Button("Connect!")) {
char* ip = NULL;
uint16_t port = 0;
char* token = strtok(addressCopy, ":");
ip = token;
char* token = strtok(addressCopy, ":");
ip = token;
token = strtok(NULL, ":");
if (token != NULL) {
port = (uint16_t)atoi(token);
token = strtok(NULL, ":");
if (token != NULL) {
port = (uint16_t) atoi(token);
}
gNetwork.enabled = true;
ConnectToServer(ip, port, username);
}
gNetwork.enabled = true;
ConnectToServer(ip, port, username);
}
} else {
ImGui::Spacing();
@@ -104,7 +104,6 @@ void MultiplayerWindow::DrawElement() {
ImGui::Spacing();
ImGui::Text("-- %s --", gCupNames[sCup]);
if (ImGui::Button("test", ImVec2(-1, 0))) {
// Add disconnect logic here
cameras[0].playerId = 2;
@@ -112,16 +111,17 @@ void MultiplayerWindow::DrawElement() {
}
for (size_t i = 0; i < NETWORK_MAX_PLAYERS; i++) {
ImGui::Text("Slot %d: char: %d, hasAuthority: %d", clients[i].slot, clients[i].character, gPlayers[i].nHasAuthority);
ImGui::Text("Slot %d: char: %d, hasAuthority: %d", clients[i].slot, clients[i].character,
gPlayers[i].nHasAuthority);
}
/* Stick UI to the bottom of the panel */
float windowHeight = ImGui::GetWindowHeight();
// Move the cursor to a position relative to the bottom of the window
ImGui::SetCursorPosY(windowHeight - ImGui::GetFrameHeightWithSpacing() * 2); // Adjust Y position for two buttons
ImGui::SetCursorPosY(windowHeight -
ImGui::GetFrameHeightWithSpacing() * 2); // Adjust Y position for two buttons
char buttonLabel[32];
@@ -152,4 +152,4 @@ void MultiplayerWindow::DrawElement() {
void MultiplayerWindow::UpdateElement() {
}
} // namespace GameInfo
} // namespace Multiplayer
+1 -1
View File
@@ -13,4 +13,4 @@ class MultiplayerWindow : public Ship::GuiWindow {
void DrawElement() override;
void UpdateElement() override;
};
} // namespace GameInfo
} // namespace Multiplayer
+1 -1
View File
@@ -1257,7 +1257,7 @@ void render_double_deck(UNUSED struct UnkStruct_800DC5EC* arg0) {
void render_dks_jungle_parkway(struct UnkStruct_800DC5EC* arg0) {
func_802B5D64(D_800DC610, D_802B87D4, 0, 1);
func_802B5D64(D_800DC610[1], D_802B87D4, D_802B87D0, 1);
func_802B5D64(&D_800DC610[1], D_802B87D4, D_802B87D0, 1);
gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH);
gSPClearGeometryMode(gDisplayListHead++, G_CULL_BACK | G_LIGHTING);
+2
View File
@@ -446,6 +446,8 @@ void func_802A487C(Vtx* arg0, UNUSED struct UnkStruct_800DC5EC* arg1, UNUSED s32
}
void func_802A4A0C(Vtx* vtx, struct UnkStruct_800DC5EC* arg1, UNUSED s32 arg2, UNUSED s32 arg3, UNUSED f32* arg4) {
s32 id = arg1 - D_8015F480;
arg1->camera = &cameras[id]; // bad fix of bowser castle crash where camera get an invalid value
Camera* camera = arg1->camera;
s16 temp_t5;
f32 temp_f0;