mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 03:55:11 +00:00
Coin/star collection packet fixes
Added flag to send packet to everyone in the level regardless of area. Coin collection packets now send to everyone in the level which keeps coin counts consistent among players. Star collection packets will no longer collect the wrong star if in a different area than the originating player.
This commit is contained in:
parent
0b88ed7cce
commit
ee53beb10b
37 changed files with 127 additions and 72 deletions
|
@ -138,6 +138,10 @@ void network_send_to(u8 localIndex, struct Packet* p) {
|
|||
if (p->actNum != np->currActNum) { return; }
|
||||
if (p->levelNum != np->currLevelNum) { return; }
|
||||
if (p->areaIndex != np->currAreaIndex) { return; }
|
||||
} else if (p->levelMustMatch) {
|
||||
if (p->courseNum != np->currCourseNum) { return; }
|
||||
if (p->actNum != np->currActNum) { return; }
|
||||
if (p->levelNum != np->currLevelNum) { return; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,6 +227,10 @@ void network_send(struct Packet* p) {
|
|||
if (p->actNum != np->currActNum) { continue; }
|
||||
if (p->levelNum != np->currLevelNum) { continue; }
|
||||
if (p->areaIndex != np->currAreaIndex) { continue; }
|
||||
} else if (p->levelMustMatch) {
|
||||
if (p->courseNum != np->currCourseNum) { continue; }
|
||||
if (p->actNum != np->currActNum) { continue; }
|
||||
if (p->levelNum != np->currLevelNum) { continue; }
|
||||
}
|
||||
|
||||
p->localIndex = i;
|
||||
|
|
|
@ -18,6 +18,20 @@ void packet_process(struct Packet* p) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
} else if (p->levelMustMatch) {
|
||||
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum;
|
||||
bool levelMismatch =
|
||||
(p->courseNum != gCurrCourseNum
|
||||
|| p->actNum != gCurrActStarNum
|
||||
|| p->levelNum != gCurrLevelNum);
|
||||
// drop packet
|
||||
if (levelMismatch) {
|
||||
if (gNetworkType != NT_SERVER) {
|
||||
LOG_INFO("dropping level mismatch packet %d", p->packetType);
|
||||
LOG_INFO(" (%d, %d, %d) != (%d, %d, %d)", p->courseNum, p->actNum, p->levelNum, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch (p->packetType) {
|
||||
|
|
|
@ -56,6 +56,12 @@ enum PacketType {
|
|||
PACKET_CUSTOM = 255,
|
||||
};
|
||||
|
||||
enum PacketLevelMatchType {
|
||||
PLMT_NONE,
|
||||
PLMT_AREA,
|
||||
PLMT_LEVEL
|
||||
};
|
||||
|
||||
struct Packet {
|
||||
enum PacketType packetType;
|
||||
u8 localIndex;
|
||||
|
@ -64,6 +70,7 @@ struct Packet {
|
|||
bool error;
|
||||
bool reliable;
|
||||
bool levelAreaMustMatch;
|
||||
bool levelMustMatch;
|
||||
bool requestBroadcast;
|
||||
u8 destGlobalId;
|
||||
u16 seqId;
|
||||
|
@ -88,7 +95,7 @@ void packet_process(struct Packet* p);
|
|||
void packet_receive(struct Packet* packet);
|
||||
|
||||
// packet_read_write.c
|
||||
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable, bool levelAreaMustMatch);
|
||||
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable, enum PacketLevelMatchType levelAreaMustMatch);
|
||||
void packet_duplicate(struct Packet* srcPacket, struct Packet* dstPacket);
|
||||
void packet_set_flags(struct Packet* packet);
|
||||
void packet_set_destination(struct Packet* packet, u8 destGlobalId);
|
||||
|
@ -166,7 +173,7 @@ void network_receive_join(struct Packet* p);
|
|||
|
||||
// packet_custom.c
|
||||
u8 network_register_custom_packet(void (*send_callback)(struct Packet* p, void* params), void (*receive_callback)(struct Packet* p));
|
||||
void network_send_custom(u8 customId, bool reliable, bool levelAreaMustMatch, void* params);
|
||||
void network_send_custom(u8 customId, bool reliable, enum PacketLevelMatchType levelAreaMustMatch, void* params);
|
||||
void network_receive_custom(struct Packet* p);
|
||||
|
||||
// packet_chat.c
|
||||
|
|
|
@ -39,7 +39,7 @@ void network_send_area(struct NetworkPlayer* toNp) {
|
|||
packet_ordered_begin();
|
||||
{
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_AREA, true, false);
|
||||
packet_init(&p, PACKET_AREA, true, PLMT_NONE);
|
||||
|
||||
// level location
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
|
|
|
@ -11,7 +11,7 @@ void network_send_area_request(struct NetworkPlayer* fromNp, struct NetworkPlaye
|
|||
}
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_AREA_REQUEST, true, false);
|
||||
packet_init(&p, PACKET_AREA_REQUEST, true, PLMT_NONE);
|
||||
packet_write(&p, &fromNp->globalIndex, sizeof(u8));
|
||||
packet_write(&p, &fromNp->currCourseNum, sizeof(s16));
|
||||
packet_write(&p, &fromNp->currActNum, sizeof(s16));
|
||||
|
|
|
@ -48,7 +48,7 @@ void network_send_change_area(void) {
|
|||
}
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_CHANGE_AREA, true, false);
|
||||
packet_init(&p, PACKET_CHANGE_AREA, true, PLMT_NONE);
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrLevelNum, sizeof(s16));
|
||||
|
|
|
@ -54,7 +54,7 @@ void network_send_change_level(void) {
|
|||
}
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_CHANGE_LEVEL, true, false);
|
||||
packet_init(&p, PACKET_CHANGE_LEVEL, true, PLMT_NONE);
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrLevelNum, sizeof(s16));
|
||||
|
|
|
@ -32,7 +32,7 @@ static void print_network_player_table(void) {
|
|||
void network_send_chat(char* message, u8 globalIndex) {
|
||||
u16 messageLength = strlen(message);
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_CHAT, true, false);
|
||||
packet_init(&p, PACKET_CHAT, true, PLMT_NONE);
|
||||
packet_write(&p, &globalIndex, sizeof(u8));
|
||||
packet_write(&p, &messageLength, sizeof(u16));
|
||||
packet_write(&p, message, messageLength * sizeof(u8));
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "src/game/object_helpers.h"
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
extern s16 gCurrCourseNum, gCurrAreaIndex;
|
||||
|
||||
// defined in sparkle_spawn_star.inc.c
|
||||
void bhv_spawn_star_no_level_exit(struct Object* object, u32 sp20, u8 networkSendEvent);
|
||||
|
||||
|
@ -49,61 +51,54 @@ void network_send_collect_coin(struct Object* o) {
|
|||
u16 behaviorId = get_id_from_behavior(o->behavior);
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_COLLECT_COIN, true, true);
|
||||
packet_init(&p, PACKET_COLLECT_COIN, true, PLMT_LEVEL);
|
||||
packet_write(&p, &behaviorId, sizeof(u16));
|
||||
packet_write(&p, &o->oPosX, sizeof(f32) * 3);
|
||||
packet_write(&p, &gMarioStates[0].numCoins, sizeof(s16));
|
||||
packet_write(&p, &o->oDamageOrCoinValue, sizeof(s32));
|
||||
packet_write(&p, &gCurrAreaIndex, sizeof(s16));
|
||||
|
||||
network_send(&p);
|
||||
}
|
||||
|
||||
void network_receive_collect_coin(struct Packet* p) {
|
||||
s16 oldNumCoins = gMarioStates[0].numCoins;
|
||||
|
||||
u16 behaviorId;
|
||||
f32 pos[3] = { 0 };
|
||||
s16 numCoins = 0;
|
||||
s32 coinValue = 0;
|
||||
s16 areaIndex = 0;
|
||||
|
||||
packet_read(p, &behaviorId, sizeof(u16));
|
||||
packet_read(p, &pos, sizeof(f32) * 3);
|
||||
packet_read(p, &numCoins, sizeof(s16));
|
||||
packet_read(p, &coinValue, sizeof(s32));
|
||||
packet_read(p, &areaIndex, sizeof(s16));
|
||||
|
||||
const void* behavior = get_behavior_from_id(behaviorId);
|
||||
if (areaIndex == gCurrAreaIndex) {
|
||||
const void* behavior = get_behavior_from_id(behaviorId);
|
||||
|
||||
// make sure it's valid
|
||||
if (behavior == NULL) { goto SANITY_CHECK_COINS; }
|
||||
// make sure it's valid
|
||||
if (behavior == NULL) { goto SANITY_CHECK_COINS; }
|
||||
|
||||
// find the coin
|
||||
float minDist = (behavior == bhvRedCoin) ? 200 : 1000;
|
||||
struct Object* coin = find_nearest_coin(behavior, pos, coinValue, minDist);
|
||||
if (coin == NULL) { goto SANITY_CHECK_COINS; }
|
||||
// find the coin
|
||||
float minDist = (behavior == bhvRedCoin) ? 200 : 1000;
|
||||
struct Object* coin = find_nearest_coin(behavior, pos, coinValue, minDist);
|
||||
if (coin == NULL) { goto SANITY_CHECK_COINS; }
|
||||
|
||||
// destroy coin
|
||||
coin->oInteractStatus = INT_STATUS_INTERACTED;
|
||||
|
||||
// add to local mario's coin count
|
||||
gMarioStates[0].numCoins += coinValue;
|
||||
|
||||
// check for 100-coin star
|
||||
extern s16 gCurrCourseNum;
|
||||
if (COURSE_IS_MAIN_COURSE(gCurrCourseNum)
|
||||
&& gMarioStates[0].numCoins - coin->oDamageOrCoinValue < 100
|
||||
&& gMarioStates[0].numCoins >= 100) {
|
||||
bhv_spawn_star_no_level_exit(gMarioStates[p->localIndex].marioObj, 6, FALSE);
|
||||
// destroy coin
|
||||
coin->oInteractStatus = INT_STATUS_INTERACTED;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
SANITY_CHECK_COINS:;
|
||||
// make sure we're at least at the same coin count
|
||||
s16 oldCoinCount = gMarioStates[0].numCoins;
|
||||
gMarioStates[0].numCoins = max(numCoins, gMarioStates[0].numCoins);
|
||||
gMarioStates[0].numCoins = max(numCoins, gMarioStates[0].numCoins + coinValue);
|
||||
|
||||
// check for 100-coin star
|
||||
if (COURSE_IS_MAIN_COURSE(gCurrCourseNum)
|
||||
&& oldCoinCount < 100
|
||||
&& gMarioStates[0].numCoins >= 100) {
|
||||
&& oldNumCoins < 100
|
||||
&& gMarioStates[0].numCoins >= 100
|
||||
&& gCurrAreaIndex == areaIndex) {
|
||||
bhv_spawn_star_no_level_exit(gMarioStates[p->localIndex].marioObj, 6, FALSE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ void network_send_collect_item(struct Object* o) {
|
|||
u16 behaviorId = get_id_from_behavior(o->behavior);
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_COLLECT_ITEM, true, true);
|
||||
packet_init(&p, PACKET_COLLECT_ITEM, true, PLMT_AREA);
|
||||
packet_write(&p, &behaviorId, sizeof(u16));
|
||||
packet_write(&p, &o->oPosX, sizeof(f32) * 3);
|
||||
|
||||
|
|
|
@ -48,11 +48,12 @@ void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex) {
|
|||
u16 behaviorId = get_id_from_behavior(o->behavior);
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_COLLECT_STAR, true, false);
|
||||
|
||||
packet_init(&p, PACKET_COLLECT_STAR, true, PLMT_NONE);
|
||||
packet_write(&p, &gCurrSaveFileNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrLevelNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrAreaIndex, sizeof(s16));
|
||||
packet_write(&p, &o->oPosX, sizeof(f32) * 3);
|
||||
packet_write(&p, &behaviorId, sizeof(u16));
|
||||
packet_write(&p, &coinScore, sizeof(s16));
|
||||
|
@ -66,12 +67,16 @@ void network_receive_collect_star(struct Packet* p) {
|
|||
u16 behaviorId;
|
||||
s16 coinScore, starIndex;
|
||||
s16 lastSaveFileNum = gCurrSaveFileNum;
|
||||
s16 lastCourseNum = gCurrCourseNum;
|
||||
s16 lastLevelNum = gCurrLevelNum;
|
||||
s16 lastCourseNum = gCurrCourseNum;
|
||||
s16 lastStarActNum = gCurrActStarNum;
|
||||
s16 lastLevelNum = gCurrLevelNum;
|
||||
s16 lastAreaIndex = gCurrAreaIndex;
|
||||
|
||||
packet_read(p, &gCurrSaveFileNum, sizeof(s16));
|
||||
packet_read(p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_read(p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_read(p, &gCurrLevelNum, sizeof(s16));
|
||||
packet_read(p, &gCurrAreaIndex, sizeof(s16));
|
||||
packet_read(p, &pos, sizeof(f32) * 3);
|
||||
packet_read(p, &behaviorId, sizeof(u16));
|
||||
packet_read(p, &coinScore, sizeof(s16));
|
||||
|
@ -86,12 +91,23 @@ void network_receive_collect_star(struct Packet* p) {
|
|||
gMarioStates[i].numStars = numStars;
|
||||
}
|
||||
|
||||
struct NetworkPlayer* np = gNetworkPlayerLocal;
|
||||
bool levelAreaMismatch = ((np == NULL)
|
||||
|| np->currCourseNum != gCurrCourseNum
|
||||
|| np->currActNum != gCurrActStarNum
|
||||
|| np->currLevelNum != gCurrLevelNum
|
||||
|| np->currAreaIndex != gCurrAreaIndex);
|
||||
|
||||
gCurrSaveFileNum = lastSaveFileNum;
|
||||
gCurrCourseNum = lastCourseNum;
|
||||
gCurrActStarNum = lastStarActNum;
|
||||
gCurrLevelNum = lastLevelNum;
|
||||
gCurrAreaIndex = lastAreaIndex;
|
||||
|
||||
struct Object* star = find_nearest_star(behavior, pos, 500);
|
||||
if (star != NULL) {
|
||||
star->oInteractStatus = INT_STATUS_INTERACTED;
|
||||
if (!levelAreaMismatch) {
|
||||
struct Object* star = find_nearest_star(behavior, pos, 500);
|
||||
if (star != NULL) {
|
||||
star->oInteractStatus = INT_STATUS_INTERACTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ u8 network_register_custom_packet(void (*send_callback)(struct Packet* p, void*
|
|||
return i;
|
||||
}
|
||||
|
||||
void network_send_custom(u8 customId, bool reliable, bool levelAreaMustMatch, void* params) {
|
||||
void network_send_custom(u8 customId, bool reliable, enum PacketLevelMatchType levelAreaMustMatch, void* params) {
|
||||
if (customPackets[customId].send_callback == NULL) { return; }
|
||||
|
||||
struct Packet p;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
void network_send_death(void) {
|
||||
if (gMarioStates[0].numLives < -1) { gMarioStates[0].numLives = -1; }
|
||||
struct Packet p = { 0 };
|
||||
packet_init(&p, PACKET_DEATH, true, false);
|
||||
packet_init(&p, PACKET_DEATH, true, PLMT_NONE);
|
||||
packet_write(&p, &gMarioStates[0].numLives, sizeof(u8));
|
||||
network_send(&p);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ void network_send_join_request(void) {
|
|||
gOverrideEeprom = eeprom;
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_JOIN_REQUEST, true, false);
|
||||
packet_init(&p, PACKET_JOIN_REQUEST, true, PLMT_NONE);
|
||||
|
||||
packet_write(&p, &configPlayerModel, sizeof(u8));
|
||||
packet_write(&p, &configPlayerPalette, sizeof(u8));
|
||||
|
@ -82,7 +82,7 @@ void network_send_join(struct Packet* joinRequestPacket) {
|
|||
LOG_INFO("sending version: %s", version);
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_JOIN, true, false);
|
||||
packet_init(&p, PACKET_JOIN, true, PLMT_NONE);
|
||||
packet_write(&p, &version, sizeof(u8) * MAX_VERSION_LENGTH);
|
||||
packet_write(&p, &joinRequestPacket->localIndex, sizeof(u8));
|
||||
packet_write(&p, &gCurrSaveFileNum, sizeof(s16));
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
void network_send_keep_alive(u8 localIndex) {
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_KEEP_ALIVE, false, false);
|
||||
packet_init(&p, PACKET_KEEP_ALIVE, false, PLMT_NONE);
|
||||
network_send_to(localIndex, &p);
|
||||
LOG_INFO("sending keep alive");
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
void network_send_kick(enum KickReasonType kickReason) {
|
||||
u8 kickReasonType = kickReason;
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_KICK, false, false);
|
||||
packet_init(&p, PACKET_KICK, false, PLMT_NONE);
|
||||
packet_write(&p, &kickReasonType, sizeof(u8));
|
||||
network_send_to(0, &p);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ void network_send_leaving(u8 globalIndex) {
|
|||
}
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_LEAVING, true, false);
|
||||
packet_init(&p, PACKET_LEAVING, true, PLMT_NONE);
|
||||
packet_write(&p, &globalIndex, sizeof(u8));
|
||||
if (gNetworkType == NT_SERVER) {
|
||||
network_send(&p);
|
||||
|
|
|
@ -16,7 +16,7 @@ void network_send_level(struct NetworkPlayer* toNp, bool sendArea) {
|
|||
packet_ordered_begin();
|
||||
{
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_LEVEL, true, false);
|
||||
packet_init(&p, PACKET_LEVEL, true, PLMT_NONE);
|
||||
|
||||
// level location
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
|
|
|
@ -17,7 +17,7 @@ void network_send_level_area_inform(struct NetworkPlayer* np) {
|
|||
u16 seq = ++sLevelAreaInformSeq[np->globalIndex][i];
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_LEVEL_AREA_INFORM, true, false);
|
||||
packet_init(&p, PACKET_LEVEL_AREA_INFORM, true, PLMT_NONE);
|
||||
packet_write(&p, &seq, sizeof(u16));
|
||||
packet_write(&p, &np->globalIndex, sizeof(u8));
|
||||
packet_write(&p, &np->currCourseNum, sizeof(s16));
|
||||
|
|
|
@ -11,7 +11,7 @@ void network_send_level_area_request(struct NetworkPlayer* fromNp, struct Networ
|
|||
}
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_LEVEL_AREA_REQUEST, true, false);
|
||||
packet_init(&p, PACKET_LEVEL_AREA_REQUEST, true, PLMT_NONE);
|
||||
packet_write(&p, &fromNp->globalIndex, sizeof(u8));
|
||||
packet_write(&p, &fromNp->currCourseNum, sizeof(s16));
|
||||
packet_write(&p, &fromNp->currActNum, sizeof(s16));
|
||||
|
|
|
@ -37,7 +37,7 @@ static void network_send_level_macro_area(struct NetworkPlayer* destNp, u8 areaI
|
|||
|
||||
// write header
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_LEVEL_MACRO, true, false);
|
||||
packet_init(&p, PACKET_LEVEL_MACRO, true, PLMT_NONE);
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrLevelNum, sizeof(s16));
|
||||
|
|
|
@ -11,7 +11,7 @@ void network_send_level_request(struct NetworkPlayer* fromNp, struct NetworkPlay
|
|||
}
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_LEVEL_REQUEST, true, false);
|
||||
packet_init(&p, PACKET_LEVEL_REQUEST, true, PLMT_NONE);
|
||||
packet_write(&p, &fromNp->globalIndex, sizeof(u8));
|
||||
packet_write(&p, &fromNp->currCourseNum, sizeof(s16));
|
||||
packet_write(&p, &fromNp->currActNum, sizeof(s16));
|
||||
|
|
|
@ -112,7 +112,7 @@ void network_send_level_respawn_info(struct Object* o, u8 respawnInfoBits) {
|
|||
|
||||
// write header
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_LEVEL_RESPAWN_INFO, true, false);
|
||||
packet_init(&p, PACKET_LEVEL_RESPAWN_INFO, true, PLMT_NONE);
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrLevelNum, sizeof(s16));
|
||||
|
|
|
@ -36,7 +36,7 @@ static void network_send_level_spawn_info_area(struct NetworkPlayer* destNp, u8
|
|||
|
||||
// write header
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_LEVEL_SPAWN_INFO, true, false);
|
||||
packet_init(&p, PACKET_LEVEL_SPAWN_INFO, true, PLMT_NONE);
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrActStarNum, sizeof(s16));
|
||||
packet_write(&p, &gCurrLevelNum, sizeof(s16));
|
||||
|
|
|
@ -13,7 +13,7 @@ static void network_send_to_network_players(u8 sendToLocalIndex) {
|
|||
u8 connectedCount = network_player_connected_count();
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_NETWORK_PLAYERS, true, false);
|
||||
packet_init(&p, PACKET_NETWORK_PLAYERS, true, PLMT_NONE);
|
||||
packet_write(&p, &connectedCount, sizeof(u8));
|
||||
for (int i = 0; i < MAX_PLAYERS; i++) {
|
||||
if (!gNetworkPlayers[i].connected) { continue; }
|
||||
|
|
|
@ -446,7 +446,7 @@ void network_send_object_reliability(struct Object* o, bool reliable) {
|
|||
|
||||
// write the packet data
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_OBJECT, reliable, true);
|
||||
packet_init(&p, PACKET_OBJECT, reliable, PLMT_AREA);
|
||||
packet_write_object_header(&p, o);
|
||||
packet_write_object_full_sync(&p, o);
|
||||
packet_write_object_standard_fields(&p, o);
|
||||
|
|
|
@ -192,7 +192,7 @@ void network_send_player(u8 localIndex) {
|
|||
read_packet_data(&data, &gMarioStates[localIndex]);
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_PLAYER, false, true);
|
||||
packet_init(&p, PACKET_PLAYER, false, PLMT_AREA);
|
||||
packet_write(&p, &gNetworkPlayers[localIndex].globalIndex, sizeof(u8));
|
||||
packet_write(&p, &data, sizeof(struct PacketPlayerData));
|
||||
network_send(&p);
|
||||
|
|
|
@ -12,14 +12,15 @@ static bool sOrderedPackets = false;
|
|||
static u8 sCurrentOrderedGroupId = 0;
|
||||
static u8 sCurrentOrderedSeqId = 0;
|
||||
|
||||
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable, bool levelAreaMustMatch) {
|
||||
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable, enum PacketLevelMatchType levelAreaMustMatch) {
|
||||
memset(packet->buffer, 0, PACKET_LENGTH);
|
||||
packet->packetType = packetType;
|
||||
packet->cursor = 0;
|
||||
packet->dataLength = 0;
|
||||
packet->error = false;
|
||||
packet->reliable = reliable;
|
||||
packet->levelAreaMustMatch = levelAreaMustMatch;
|
||||
packet->levelAreaMustMatch = (levelAreaMustMatch == PLMT_AREA);
|
||||
packet->levelMustMatch = (levelAreaMustMatch == PLMT_LEVEL);
|
||||
packet->requestBroadcast = false;
|
||||
packet->sent = false;
|
||||
packet->orderedFromGlobalId = sOrderedPackets ? gNetworkPlayerLocal->globalIndex : 0;
|
||||
|
@ -56,7 +57,7 @@ void packet_init(struct Packet* packet, enum PacketType packetType, bool reliabl
|
|||
}
|
||||
|
||||
// write location
|
||||
if (levelAreaMustMatch) {
|
||||
if (packet->levelAreaMustMatch) {
|
||||
packet_write(packet, &gCurrCourseNum, sizeof(u8));
|
||||
packet_write(packet, &gCurrActStarNum, sizeof(u8));
|
||||
packet_write(packet, &gCurrLevelNum, sizeof(u8));
|
||||
|
@ -65,6 +66,13 @@ void packet_init(struct Packet* packet, enum PacketType packetType, bool reliabl
|
|||
packet->actNum = gCurrActStarNum;
|
||||
packet->levelNum = gCurrLevelNum;
|
||||
packet->areaIndex = gCurrAreaIndex;
|
||||
} else if (packet->levelMustMatch) {
|
||||
packet_write(packet, &gCurrCourseNum, sizeof(u8));
|
||||
packet_write(packet, &gCurrActStarNum, sizeof(u8));
|
||||
packet_write(packet, &gCurrLevelNum, sizeof(u8));
|
||||
packet->courseNum = gCurrCourseNum;
|
||||
packet->actNum = gCurrActStarNum;
|
||||
packet->levelNum = gCurrLevelNum;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,6 +84,7 @@ void packet_duplicate(struct Packet* srcPacket, struct Packet* dstPacket) {
|
|||
dstPacket->error = srcPacket->error;
|
||||
dstPacket->reliable = srcPacket->reliable;
|
||||
dstPacket->levelAreaMustMatch = srcPacket->levelAreaMustMatch;
|
||||
dstPacket->levelMustMatch = srcPacket->levelMustMatch;
|
||||
dstPacket->requestBroadcast = srcPacket->requestBroadcast;
|
||||
dstPacket->destGlobalId = srcPacket->destGlobalId;
|
||||
dstPacket->sent = false;
|
||||
|
@ -106,6 +115,7 @@ void packet_set_flags(struct Packet* packet) {
|
|||
flags |= SET_BIT(packet->levelAreaMustMatch, 0);
|
||||
flags |= SET_BIT(packet->requestBroadcast, 1);
|
||||
flags |= SET_BIT(packet->orderedGroupId != 0, 2);
|
||||
flags |= SET_BIT(packet->levelMustMatch, 3);
|
||||
packet->buffer[PACKET_FLAG_BUFFER_OFFSET] = flags;
|
||||
}
|
||||
|
||||
|
@ -130,6 +140,7 @@ u8 packet_initial_read(struct Packet* packet) {
|
|||
packet->levelAreaMustMatch = GET_BIT(flags, 0);
|
||||
packet->requestBroadcast = GET_BIT(flags, 1);
|
||||
bool packetIsOrdered = GET_BIT(flags, 2);
|
||||
packet->levelMustMatch = GET_BIT(flags, 3);
|
||||
|
||||
// read destination
|
||||
packet_read(packet, &packet->destGlobalId, sizeof(u8));
|
||||
|
@ -147,6 +158,10 @@ u8 packet_initial_read(struct Packet* packet) {
|
|||
packet_read(packet, &packet->actNum, sizeof(u8));
|
||||
packet_read(packet, &packet->levelNum, sizeof(u8));
|
||||
packet_read(packet, &packet->areaIndex, sizeof(u8));
|
||||
} else if (packet->levelMustMatch) {
|
||||
packet_read(packet, &packet->courseNum, sizeof(u8));
|
||||
packet_read(packet, &packet->actNum, sizeof(u8));
|
||||
packet_read(packet, &packet->levelNum, sizeof(u8));
|
||||
}
|
||||
|
||||
// don't drop packet
|
||||
|
|
|
@ -60,7 +60,7 @@ void network_send_ack(struct Packet* p) {
|
|||
|
||||
// send back the ACK
|
||||
struct Packet ack = { 0 };
|
||||
packet_init(&ack, PACKET_ACK, false, false);
|
||||
packet_init(&ack, PACKET_ACK, false, PLMT_NONE);
|
||||
packet_write(&ack, &seqId, sizeof(u16));
|
||||
network_send_to(0, &ack);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ void network_send_reservation_list(struct NetworkPlayer* np, u8 syncIds[]) {
|
|||
assert(gNetworkType == NT_SERVER);
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_RESERVATION_LIST, true, false);
|
||||
packet_init(&p, PACKET_RESERVATION_LIST, true, PLMT_NONE);
|
||||
|
||||
packet_write(&p, &np->currCourseNum, sizeof(u8));
|
||||
packet_write(&p, &np->currActNum, sizeof(u8));
|
||||
|
|
|
@ -17,7 +17,7 @@ void network_send_reservation_release(u8 syncId) {
|
|||
if (syncId < RESERVED_IDS_SYNC_OBJECT_OFFSET) { return; }
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_RESERVATION_RELEASE, true, false);
|
||||
packet_init(&p, PACKET_RESERVATION_RELEASE, true, PLMT_NONE);
|
||||
|
||||
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex;
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(u8));
|
||||
|
|
|
@ -17,7 +17,7 @@ void network_send_reservation_use(u8 syncId) {
|
|||
if (syncId < RESERVED_IDS_SYNC_OBJECT_OFFSET) { return; }
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_RESERVATION_USE, true, false);
|
||||
packet_init(&p, PACKET_RESERVATION_USE, true, PLMT_NONE);
|
||||
|
||||
extern s16 gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex;
|
||||
packet_write(&p, &gCurrCourseNum, sizeof(u8));
|
||||
|
|
|
@ -6,7 +6,7 @@ void network_send_save_file(s32 fileIndex) {
|
|||
if (gNetworkPlayerServer == NULL) { return; }
|
||||
assert(gNetworkType == NT_CLIENT);
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_SAVE_FILE, true, false);
|
||||
packet_init(&p, PACKET_SAVE_FILE, true, PLMT_NONE);
|
||||
packet_write(&p, &fileIndex, sizeof(s32));
|
||||
network_send_to(gNetworkPlayerServer->localIndex, &p);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
void network_send_save_set_flag(s32 fileIndex, s32 courseIndex, u8 courseStars, u32 flags) {
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_SAVE_SET_FLAG, true, false);
|
||||
packet_init(&p, PACKET_SAVE_SET_FLAG, true, PLMT_NONE);
|
||||
packet_write(&p, &fileIndex, sizeof(s32));
|
||||
packet_write(&p, &courseIndex, sizeof(s32));
|
||||
packet_write(&p, &courseStars, sizeof(u8));
|
||||
|
|
|
@ -54,7 +54,7 @@ void network_send_spawn_objects_to(u8 sendToLocalIndex, struct Object* objects[]
|
|||
if (gCurrActStarNum == 99) { return; }
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_SPAWN_OBJECTS, true, true);
|
||||
packet_init(&p, PACKET_SPAWN_OBJECTS, true, PLMT_AREA);
|
||||
|
||||
// objects
|
||||
packet_write(&p, &objectCount, sizeof(u8));
|
||||
|
|
|
@ -9,7 +9,7 @@ extern struct Object* gCurrentObject;
|
|||
|
||||
void network_send_spawn_star(struct Object* o, u8 starType, f32 x, f32 y, f32 z, u32 behParams) {
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_SPAWN_STAR, true, true);
|
||||
packet_init(&p, PACKET_SPAWN_STAR, true, PLMT_AREA);
|
||||
packet_write(&p, &starType, sizeof(u8));
|
||||
packet_write(&p, &x, sizeof(f32));
|
||||
packet_write(&p, &y, sizeof(f32));
|
||||
|
@ -58,7 +58,7 @@ void network_send_spawn_star_nle(struct Object* o, u32 params) {
|
|||
}
|
||||
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_SPAWN_STAR_NLE, true, true);
|
||||
packet_init(&p, PACKET_SPAWN_STAR_NLE, true, PLMT_AREA);
|
||||
packet_write(&p, &globalIndex, sizeof(u8));
|
||||
packet_write(&p, &o->oSyncID, sizeof(u32));
|
||||
packet_write(&p, ¶ms, sizeof(u32));
|
||||
|
|
|
@ -19,7 +19,7 @@ void network_send_sync_valid(struct NetworkPlayer* toNp) {
|
|||
|
||||
u8 myGlobalIndex = gNetworkPlayerLocal->globalIndex;
|
||||
struct Packet p;
|
||||
packet_init(&p, PACKET_SYNC_VALID, true, false);
|
||||
packet_init(&p, PACKET_SYNC_VALID, true, PLMT_NONE);
|
||||
packet_write(&p, &toNp->currCourseNum, sizeof(s16));
|
||||
packet_write(&p, &toNp->currActNum, sizeof(s16));
|
||||
packet_write(&p, &toNp->currLevelNum, sizeof(s16));
|
||||
|
|
Loading…
Reference in a new issue