Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some multiplayer fixes #729

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion code/src/actors/link_puppet.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ void EnLinkPuppet_Destroy(EnLinkPuppet* this, GlobalContext* globalCtx) {
}

void EnLinkPuppet_Update(EnLinkPuppet* this, GlobalContext* globalCtx) {
if (!this->ghostPtr->inUse || this->ghostPtr->ghostData.currentScene != gGlobalContext->sceneNum) {
if (!this->ghostPtr->inUse || !this->ghostPtr->isInGame ||
this->ghostPtr->ghostData.currentScene != gGlobalContext->sceneNum) {
Actor_Kill(&this->base);
return;
}

this->base.world.pos = this->ghostPtr->ghostData.position;
this->base.shape.rot = this->ghostPtr->ghostData.rotation;
// Overwrite prevPos so model doesn't get stuck to terrain because of Actor_UpdateBgCheckInfo
this->base.prevPos = this->base.world.pos;

// Mesh Groups
for (size_t index = 0; index < BIT_COUNT(this->ghostPtr->ghostData.meshGroups1); index++) {
Expand Down
6 changes: 4 additions & 2 deletions code/src/multiplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,11 +895,13 @@ void Multiplayer_Send_GhostPing(void) {
memset(mBuffer, 0, mBufSize);
u8 memSpacer = 0;
mBuffer[memSpacer++] = PACKET_GHOSTPING; // 0: Identifier
mBuffer[memSpacer++] = IsInGameOrBossChallenge();
Multiplayer_SendPacket(memSpacer, UDS_BROADCAST_NETWORKNODEID);
}

void Multiplayer_Receive_GhostPing(u16 senderID) {
Multiplayer_Ghosts_UpdateGhostData(senderID, NULL);
u8 isInGame = mBuffer[1];
Multiplayer_Ghosts_UpdateGhostData(senderID, NULL, isInGame);
}

void Multiplayer_Send_GhostData(void) {
Expand Down Expand Up @@ -957,7 +959,7 @@ void Multiplayer_Receive_GhostData(u16 senderID) {
u32 packetSize = sizeof(GhostData) - sizeof(ghostData.jointTable);
memcpy(&ghostData, &mBuffer[1], packetSize);

Multiplayer_Ghosts_UpdateGhostData(senderID, &ghostData);
Multiplayer_Ghosts_UpdateGhostData(senderID, &ghostData, TRUE);
}

void Multiplayer_Send_GhostData_JointTable(void) {
Expand Down
7 changes: 5 additions & 2 deletions code/src/multiplayer_ghosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Multiplayer_Ghosts_Tick(void) {
}
}

void Multiplayer_Ghosts_UpdateGhostData(u16 networkID, GhostData* ghostData) {
void Multiplayer_Ghosts_UpdateGhostData(u16 networkID, GhostData* ghostData, u8 isInGame) {
LinkGhost* ghostX = NULL;
// Find existing ghost
for (size_t i = 0; i < ARRAY_SIZE(ghosts); i++) {
Expand Down Expand Up @@ -47,6 +47,7 @@ void Multiplayer_Ghosts_UpdateGhostData(u16 networkID, GhostData* ghostData) {
}
// Set vars
ghostX->lastTick = svcGetSystemTick();
ghostX->isInGame = isInGame;
if (ghostData != NULL) {
memcpy(&ghostX->ghostData, ghostData, sizeof(GhostData) - sizeof(ghostData->jointTable));
}
Expand Down Expand Up @@ -90,7 +91,9 @@ void Multiplayer_Ghosts_SpawnPuppets(void) {
for (size_t i = 0; i < ARRAY_SIZE(ghosts); i++) {
LinkGhost* ghost = &ghosts[i];

if (ghost->inUse && ghost->ghostData.currentScene == gGlobalContext->sceneNum && !IsPuppetSpawned(ghost)) {
if (ghost->inUse && ghost->isInGame && ghost->ghostData.currentScene == gGlobalContext->sceneNum &&
!IsPuppetSpawned(ghost)) {

EnLinkPuppet_InitVars.objectId = (gSaveContext.linkAge == 0) ? 20 : 21;
EnLinkPuppet* puppet = (EnLinkPuppet*)Actor_Spawn(
&gGlobalContext->actorCtx, gGlobalContext, EnLinkPuppet_InitVars.id, //
Expand Down
3 changes: 2 additions & 1 deletion code/src/multiplayer_ghosts.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ typedef struct {
bool inUse;
u64 lastTick;
u16 networkID;
u8 isInGame;
GhostData ghostData;
} LinkGhost;

void Multiplayer_Ghosts_Tick(void);
void Multiplayer_Ghosts_UpdateGhostData(u16 networkID, GhostData* ghostData);
void Multiplayer_Ghosts_UpdateGhostData(u16 networkID, GhostData* ghostData, u8 isInGame);
void Multiplayer_Ghosts_UpdateGhostData_JointTable(u16 networkID, LimbData* limbData);
GhostData* Multiplayer_Ghosts_GetGhostData(u16 networkID);
void Multiplayer_Ghosts_SpawnPuppets(void);
Expand Down
Loading