diff --git a/build-windows-visual-studio/sm64ex.vcxproj b/build-windows-visual-studio/sm64ex.vcxproj
index 4a62090d..f10f95cd 100644
--- a/build-windows-visual-studio/sm64ex.vcxproj
+++ b/build-windows-visual-studio/sm64ex.vcxproj
@@ -3952,6 +3952,7 @@
+
diff --git a/build-windows-visual-studio/sm64ex.vcxproj.filters b/build-windows-visual-studio/sm64ex.vcxproj.filters
index ed2df259..3e368704 100644
--- a/build-windows-visual-studio/sm64ex.vcxproj.filters
+++ b/build-windows-visual-studio/sm64ex.vcxproj.filters
@@ -15006,6 +15006,9 @@
Source Files\src\pc\network\packets
+
+ Source Files\src\pc\network\packets
+
diff --git a/compile.sh b/compile.sh
index d3177b88..e1432f75 100644
--- a/compile.sh
+++ b/compile.sh
@@ -1 +1 @@
-make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 && winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'break debug_breakpoint_here' -ex 'run' -ex 'quit'
\ No newline at end of file
+make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 STRICT=1 && winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'break debug_breakpoint_here' -ex 'run' -ex 'quit'
\ No newline at end of file
diff --git a/debug.sh b/debug.sh
index 2c8e3876..252afdd6 100644
--- a/debug.sh
+++ b/debug.sh
@@ -1 +1 @@
-make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 && winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'break debug_breakpoint_here'
\ No newline at end of file
+make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 STRICT=1 && winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'break debug_breakpoint_here'
\ No newline at end of file
diff --git a/network.sh b/network.sh
index 3b6d0ea9..b1160372 100755
--- a/network.sh
+++ b/network.sh
@@ -1,5 +1,9 @@
set -e
-make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1
+if [ $# -eq 0 ]; then
+ make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1
+else
+ make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 STRICT=1
+fi
# find file
FILE=./build/us_pc/sm64.us.f3dex2e.exe
diff --git a/src/pc/network/network.h b/src/pc/network/network.h
index 66198f50..f27d9dba 100644
--- a/src/pc/network/network.h
+++ b/src/pc/network/network.h
@@ -1,6 +1,7 @@
#ifndef NETWORK_H
#define NETWORK_H
+#include "PR/ultratypes.h"
#include
#include
#include
@@ -32,13 +33,13 @@ enum PacketType {
};
struct Packet {
- int dataLength;
- int cursor;
+ u16 dataLength;
+ u16 cursor;
bool error;
bool reliable;
u16 seqId;
bool sent;
- char buffer[PACKET_LENGTH];
+ u8 buffer[PACKET_LENGTH];
};
struct SyncObject {
@@ -80,8 +81,8 @@ void network_shutdown(void);
// packet read / write
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable);
-void packet_write(struct Packet* packet, void* data, int length);
-void packet_read(struct Packet* packet, void* data, int length);
+void packet_write(struct Packet* packet, void* data, u16 length);
+void packet_read(struct Packet* packet, void* data, u16 length);
u32 packet_hash(struct Packet* packet);
bool packet_check_hash(struct Packet* packet);
diff --git a/src/pc/network/packets/packet_collect_coin.c b/src/pc/network/packets/packet_collect_coin.c
index 7f76c848..511542a7 100644
--- a/src/pc/network/packets/packet_collect_coin.c
+++ b/src/pc/network/packets/packet_collect_coin.c
@@ -82,7 +82,7 @@ void network_receive_collect_coin(struct Packet* p) {
const void* behavior = get_behavior_from_id(behaviorId);
// check if remote coin id has already been seen
- for (int i = 0; i < MAX_REMOTE_COIN_IDS; i++) {
+ for (u16 i = 0; i < MAX_REMOTE_COIN_IDS; i++) {
if (remoteCoinIds[i] == remoteCoinId) {
// we already saw this coin!
goto SANITY_CHECK_COINS;
diff --git a/src/pc/network/packets/packet_collect_item.c b/src/pc/network/packets/packet_collect_item.c
index 9d523cc1..0d2e4282 100644
--- a/src/pc/network/packets/packet_collect_item.c
+++ b/src/pc/network/packets/packet_collect_item.c
@@ -73,7 +73,7 @@ void network_receive_collect_item(struct Packet* p) {
const void* behavior = get_behavior_from_id(behaviorId);
// check if remote item id has already been seen
- for (int i = 0; i < MAX_REMOTE_ITEM_IDS; i++) {
+ for (u16 i = 0; i < MAX_REMOTE_ITEM_IDS; i++) {
if (remoteItemIds[i] == remoteItemId) {
// we already saw this item!
return;
diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c
index 47e60246..8a564501 100644
--- a/src/pc/network/packets/packet_object.c
+++ b/src/pc/network/packets/packet_object.c
@@ -24,7 +24,7 @@ float player_distance(struct MarioState* marioState, struct Object* o) {
}
void network_clear_sync_objects(void) {
- for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
+ for (u16 i = 0; i < MAX_SYNC_OBJECTS; i++) {
network_forget_sync_object(&syncObjects[i]);
}
nextSyncID = 1;
@@ -36,7 +36,7 @@ void network_set_sync_id(struct Object* o) {
// two-player hack
u8 reserveId = (networkLevelLoaded && networkType == NT_CLIENT) ? 1 : 0;
- for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
+ for (u16 i = 0; i < MAX_SYNC_OBJECTS; i++) {
if (syncObjects[nextSyncID].reserved == reserveId && syncObjects[nextSyncID].o == NULL) { break; }
nextSyncID = (nextSyncID + 1) % MAX_SYNC_OBJECTS;
}
@@ -78,7 +78,7 @@ void network_init_object_field(struct Object *o, void* field) {
assert(o->oSyncID != 0);
// remember to synchronize this extra field
struct SyncObject* so = &syncObjects[o->oSyncID];
- int index = so->extraFieldCount++;
+ u8 index = so->extraFieldCount++;
so->extraFields[index] = field;
}
@@ -234,7 +234,7 @@ static void packet_write_object_extra_fields(struct Packet* p, struct Object* o)
packet_write(p, &so->extraFieldCount, sizeof(u8));
// write the extra field
- for (int i = 0; i < so->extraFieldCount; i++) {
+ for (u8 i = 0; i < so->extraFieldCount; i++) {
assert(so->extraFields[i] != NULL);
packet_write(p, so->extraFields[i], sizeof(u32));
}
@@ -252,7 +252,7 @@ static void packet_read_object_extra_fields(struct Packet* p, struct Object* o)
}
// read the extra fields
- for (int i = 0; i < extraFieldsCount; i++) {
+ for (u8 i = 0; i < extraFieldsCount; i++) {
assert(so->extraFields[i] != NULL);
packet_read(p, so->extraFields[i], sizeof(u32));
}
diff --git a/src/pc/network/packets/packet_read_write.c b/src/pc/network/packets/packet_read_write.c
index c5e71680..89e163e7 100644
--- a/src/pc/network/packets/packet_read_write.c
+++ b/src/pc/network/packets/packet_read_write.c
@@ -17,24 +17,24 @@ void packet_init(struct Packet* packet, enum PacketType packetType, bool reliabl
packet->sent = false;
}
-void packet_write(struct Packet* packet, void* data, int length) {
+void packet_write(struct Packet* packet, void* data, u16 length) {
if (data == NULL) { packet->error = true; return; }
memcpy(&packet->buffer[packet->cursor], data, length);
packet->dataLength += length;
packet->cursor += length;
}
-void packet_read(struct Packet* packet, void* data, int length) {
+void packet_read(struct Packet* packet, void* data, u16 length) {
if (data == NULL) { packet->error = true; return; }
- int cursor = packet->cursor;
+ u16 cursor = packet->cursor;
memcpy(data, &packet->buffer[cursor], length);
packet->cursor = cursor + length;
}
u32 packet_hash(struct Packet* packet) {
u32 hash = 0;
- int byte = 0;
- for (int i = 0; i < packet->dataLength; i++) {
+ u16 byte = 0;
+ for (u16 i = 0; i < packet->dataLength; i++) {
hash ^= ((u32)packet->buffer[i]) << (8 * byte);
byte = (byte + 1) % sizeof(u32);
}
diff --git a/src/pc/network/packets/packet_reservation.c b/src/pc/network/packets/packet_reservation.c
index c492ea2b..879ac91b 100644
--- a/src/pc/network/packets/packet_reservation.c
+++ b/src/pc/network/packets/packet_reservation.c
@@ -24,12 +24,12 @@ void network_receive_reservation_request(UNUSED struct Packet* p) {
void network_send_reservation(void) {
assert(networkType == NT_SERVER);
- int clientPlayerIndex = 1; // two-player hack
+ u8 clientPlayerIndex = 1; // two-player hack
// find all reserved objects
u8 reservedObjs[RESERVATION_COUNT] = { 0 };
- int reservedIndex = 0;
- for (int i = 1; i < MAX_SYNC_OBJECTS; i++) {
+ u16 reservedIndex = 0;
+ for (u16 i = 1; i < MAX_SYNC_OBJECTS; i++) {
if (syncObjects[i].reserved == clientPlayerIndex) {
reservedObjs[reservedIndex++] = i;
if (reservedIndex >= RESERVATION_COUNT) { break; }
@@ -38,7 +38,7 @@ void network_send_reservation(void) {
if (reservedIndex < RESERVATION_COUNT) {
// reserve the rest
- for (int i = MAX_SYNC_OBJECTS - 1; i > 0; i--) {
+ for (u16 i = MAX_SYNC_OBJECTS - 1; i > 0; i--) {
if (syncObjects[i].o != NULL) { continue; }
if (syncObjects[i].reserved != 0) { continue; }
syncObjects[i].reserved = clientPlayerIndex;
@@ -55,18 +55,16 @@ void network_send_reservation(void) {
void network_receive_reservation(struct Packet* p) {
assert(networkType == NT_CLIENT);
- int clientPlayerIndex = 1; // two-player hack
+ u8 clientPlayerIndex = 1; // two-player hack
// find all reserved objects
u8 reservedObjs[RESERVATION_COUNT] = { 0 };
packet_read(p, reservedObjs, sizeof(u8) * RESERVATION_COUNT);
- for (int i = 0; i < RESERVATION_COUNT; i++) {
- int index = reservedObjs[i];
- printf(" %d", index);
+ for (u16 i = 0; i < RESERVATION_COUNT; i++) {
+ u16 index = reservedObjs[i];
if (index == 0) { continue; }
if (syncObjects[index].o != NULL) { continue; }
syncObjects[index].reserved = clientPlayerIndex;
}
- printf("\n");
}
diff --git a/src/pc/network/packets/packet_spawn_objects.c b/src/pc/network/packets/packet_spawn_objects.c
index dc51acd2..49cb5a9b 100644
--- a/src/pc/network/packets/packet_spawn_objects.c
+++ b/src/pc/network/packets/packet_spawn_objects.c
@@ -35,7 +35,7 @@ static u8 generate_parent_id(struct Object* objects[], u8 onIndex) {
return (u8)o->parentObj->oSyncID;
}
- for (u8 i = onIndex; i < onIndex; i--) {
+ for (u8 i = onIndex; i != (u8)-1; i--) {
if (o->parentObj == objects[i]) { return i; }
}
@@ -76,7 +76,7 @@ void network_receive_spawn_objects(struct Packet* p) {
packet_read(p, &objectCount, sizeof(u8));
// check if remote spawn id has already been seen
- for (int i = 0; i < MAX_REMOTE_SPAWN_IDS; i++) {
+ for (u16 i = 0; i < MAX_REMOTE_SPAWN_IDS; i++) {
if (remoteSpawnIds[i] == remoteSpawnId) {
// we already saw this event!
return;
diff --git a/src/pc/network/socket/socket.c b/src/pc/network/socket/socket.c
index 57911e06..2e995319 100644
--- a/src/pc/network/socket/socket.c
+++ b/src/pc/network/socket/socket.c
@@ -1,6 +1,6 @@
#include
-#include "socket.h"
#include "../network.h"
+#include "socket.h"
int socket_bind(SOCKET sock, unsigned int port) {
struct sockaddr_in rxAddr;
@@ -16,9 +16,9 @@ int socket_bind(SOCKET sock, unsigned int port) {
return rc;
}
-int socket_send(SOCKET sock, struct sockaddr_in* txAddr, char* buffer, int bufferLength) {
+int socket_send(SOCKET sock, struct sockaddr_in* txAddr, u8* buffer, u16 bufferLength) {
int txAddrSize = sizeof(struct sockaddr_in);
- int rc = sendto(sock, buffer, bufferLength, 0, (struct sockaddr*)txAddr, txAddrSize);
+ int rc = sendto(sock, (char*)buffer, bufferLength, 0, (struct sockaddr*)txAddr, txAddrSize);
if (rc == SOCKET_ERROR) {
printf("%s sendto failed with error: %d\n", NETWORKTYPESTR, SOCKET_LAST_ERROR);
}
@@ -26,11 +26,11 @@ int socket_send(SOCKET sock, struct sockaddr_in* txAddr, char* buffer, int buffe
return rc;
}
-int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, char* buffer, int bufferLength, int* receiveLength) {
+int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, u8* buffer, u16 bufferLength, u16* receiveLength) {
*receiveLength = 0;
int rxAddrSize = sizeof(struct sockaddr_in);
- int rc = recvfrom(sock, buffer, bufferLength, 0, (struct sockaddr*)rxAddr, &rxAddrSize);
+ int rc = recvfrom(sock, (char*)buffer, bufferLength, 0, (struct sockaddr*)rxAddr, &rxAddrSize);
if (rc == SOCKET_ERROR) {
int error = SOCKET_LAST_ERROR;
if (error != SOCKET_EWOULDBLOCK && error != SOCKET_ECONNRESET) {
diff --git a/src/pc/network/socket/socket.h b/src/pc/network/socket/socket.h
index 1e31ad82..de295a71 100644
--- a/src/pc/network/socket/socket.h
+++ b/src/pc/network/socket/socket.h
@@ -9,8 +9,8 @@
SOCKET socket_initialize(void);
int socket_bind(SOCKET sock, unsigned int port);
-int socket_send(SOCKET sock, struct sockaddr_in* txAddr, char* buffer, int bufferLength);
-int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, char* buffer, int bufferLength, int* receiveLength);
+int socket_send(SOCKET sock, struct sockaddr_in* txAddr, u8* buffer, u16 bufferLength);
+int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, u8* buffer, u16 bufferLength, u16* receiveLength);
void socket_close(SOCKET sock);
#endif