SQC-15_online #1

Merged
memartel_loc merged 349 commits from SQC-15_online into master 2023-12-10 17:41:26 -05:00
Showing only changes of commit 49c9576757 - Show all commits

View File

@ -64,13 +64,95 @@ void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
*buf[0] = (char)netprot::PACKET_TYPE::OUTPUT;
uint64_t time = out->timestamp;
uint8_t time8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF),
(uint8_t)((time >> 48) & 0xFF),
(uint8_t)((time >> 40) & 0xFF),
(uint8_t)((time >> 32) & 0xFF),
(uint8_t)((time >> 24) & 0xFF),
(uint8_t)((time >> 16) & 0xFF),
(uint8_t)((time >> 8) & 0xFF),
(uint8_t)(time & 0xFF) };
memcpy(*buf + 1, time8, sizeof(uint64_t));
uint64_t sid = out->id;
uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF),
(uint8_t)((sid >> 48) & 0xFF),
(uint8_t)((sid >> 40) & 0xFF),
(uint8_t)((sid >> 32) & 0xFF),
(uint8_t)((sid >> 24) & 0xFF),
(uint8_t)((sid >> 16) & 0xFF),
(uint8_t)((sid >> 8) & 0xFF),
(uint8_t)(sid & 0xFF) };
memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
// TODO: Finir ca.
}
void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
*buf[0] = (char)netprot::PACKET_TYPE::SYNC;
uint64_t time = sync->timestamp;
uint8_t stamp8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF),
(uint8_t)((time >> 48) & 0xFF),
(uint8_t)((time >> 40) & 0xFF),
(uint8_t)((time >> 32) & 0xFF),
(uint8_t)((time >> 24) & 0xFF),
(uint8_t)((time >> 16) & 0xFF),
(uint8_t)((time >> 8) & 0xFF),
(uint8_t)(time & 0xFF) };
memcpy(*buf + 1, stamp8, sizeof(uint64_t));
uint64_t sid = sync->sid;
uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF),
(uint8_t)((sid >> 48) & 0xFF),
(uint8_t)((sid >> 40) & 0xFF),
(uint8_t)((sid >> 32) & 0xFF),
(uint8_t)((sid >> 24) & 0xFF),
(uint8_t)((sid >> 16) & 0xFF),
(uint8_t)((sid >> 8) & 0xFF),
(uint8_t)(sid & 0xFF) };
memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
uint32_t timer = sync->timer;
uint8_t time8[sizeof(uint32_t)] = {(uint8_t)((timer >> 24) & 0xFF),
(uint8_t)((timer >> 16) & 0xFF),
(uint8_t)((timer >> 8) & 0xFF),
(uint8_t)(timer & 0xFF) };
memcpy(*buf + sizeof(uint64_t) * 2 + 1, time8, sizeof(uint32_t));
uint16_t ammo = sync->ammo;
uint8_t ammo8[sizeof(uint16_t)] = { (uint8_t)((ammo >> 8) & 0xFF),
(uint8_t)(ammo & 0xFF) };
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + 1, ammo8, sizeof(uint16_t));
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, &sync->hp, sizeof(uint8_t));
uint32_t vec[3];
memcpy(vec, &sync->position, sizeof(Vector3f)); // Pour d<>naturer les floats.
uint8_t vec8[3 * sizeof(uint32_t)] = {
(uint8_t)((vec[0] >> 24) & 0xFF),
(uint8_t)((vec[0] >> 16) & 0xFF),
(uint8_t)((vec[0] >> 8) & 0xFF),
(uint8_t)(vec[0] & 0xFF),
(uint8_t)((vec[1] >> 24) & 0xFF),
(uint8_t)((vec[1] >> 16) & 0xFF),
(uint8_t)((vec[1] >> 8) & 0xFF),
(uint8_t)(vec[1] & 0xFF),
(uint8_t)((vec[2] >> 24) & 0xFF),
(uint8_t)((vec[2] >> 16) & 0xFF),
(uint8_t)((vec[2] >> 8) & 0xFF),
(uint8_t)(vec[2] & 0xFF) };
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 2, vec8, sizeof(uint32_t) * 3);
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2;
}
void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
@ -347,7 +429,65 @@ bool netprot::Deserialize(Output* out, char* buf, const uint32_t buflen) {
}
bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) {
return false;
if (buflen <= sizeof(Sync))
return false;
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
memcpy(diff, &buf[1], sizeof(uint64_t));
sync->timestamp =
(uint64_t)diff[0] << 56 |
(uint64_t)diff[1] << 48 |
(uint64_t)diff[2] << 40 |
(uint64_t)diff[3] << 32 |
(uint64_t)diff[4] << 24 |
(uint64_t)diff[5] << 16 |
(uint64_t)diff[6] << 8 |
(uint64_t)diff[7];
memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
sync->sid =
(uint64_t)diff[0] << 56 |
(uint64_t)diff[1] << 48 |
(uint64_t)diff[2] << 40 |
(uint64_t)diff[3] << 32 |
(uint64_t)diff[4] << 24 |
(uint64_t)diff[5] << 16 |
(uint64_t)diff[6] << 8 |
(uint64_t)diff[7];
memcpy(diff, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint32_t));
sync->timer =
(uint32_t)diff[0] << 24 |
(uint32_t)diff[1] << 16 |
(uint32_t)diff[2] << 8 |
(uint32_t)diff[3];
memcpy(diff, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t)], sizeof(uint16_t));
sync->ammo =
(uint16_t)diff[0] << 8 |
(uint16_t)diff[1];
memcpy(&sync->hp, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t));
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
uint32_t vec[3] = {
(uint32_t)subvec[0] << 24 |
(uint32_t)subvec[1] << 16 |
(uint32_t)subvec[2] << 8 |
(uint32_t)subvec[3],
(uint32_t)subvec[4] << 24 |
(uint32_t)subvec[5] << 16 |
(uint32_t)subvec[6] << 8 |
(uint32_t)subvec[7],
(uint32_t)subvec[8] << 24 |
(uint32_t)subvec[9] << 16 |
(uint32_t)subvec[10] << 8 |
(uint32_t)subvec[11] };
memcpy(&sync->position, vec, sizeof(uint32_t) * 3);
return true;
}
bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) {