Skip to content

Commit

Permalink
tweak(onesync): refine net time sync code
Browse files Browse the repository at this point in the history
The goal of this commit is to improve the readability of `rage::netTimeSync` related code. Additionally, it aims to improve the maintainability of `CloneExperiments.cpp` by logically splitting certain parts of the file into appropriate chunks. The code refine isn't intended to be a full fledged refactor but rather a first step towards facilitating future refactoring efforts.
  • Loading branch information
Disquse committed Feb 9, 2024
1 parent 88a0a6c commit 2d66539
Show file tree
Hide file tree
Showing 5 changed files with 468 additions and 531 deletions.
74 changes: 74 additions & 0 deletions code/components/gta-net-five/include/netTimeSync.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once

struct TrustAddressData
{
uint32_t m_addr;
uint16_t m_port;
};

struct TrustAddress1604
{
TrustAddressData m_addr1;
TrustAddressData m_addr2;
};

struct TrustAddress2060
{
TrustAddressData m_addr1;
TrustAddressData m_addr2;
TrustAddressData m_addr3;
};

struct TrustAddress2372
{
uint32_t m_addr;
};

template<int Build>
using TrustAddress = std::conditional_t<(Build >= 2372), TrustAddress2372, std::conditional_t<(Build >= 2060), TrustAddress2060, TrustAddress1604>>;

namespace rage
{
class netConnectionManager;

template<int Build>
class netTimeSync
{
public:
virtual ~netTimeSync() = 0;

void Update();
void HandleTimeSync(net::Buffer& buffer);
bool IsInitialized();
void SetConnectionManager(netConnectionManager* mgr);

private:
netConnectionManager* m_connectionMgr; // +8 (1604)
TrustAddress<Build> m_trustAddr; // +16
uint32_t m_sessionKey; // +32
int32_t m_timeDelta; // +36
struct
{
void* self;
void* cb;
} m_messageDelegate; // +40
char m_pad_56[32];
uint32_t m_nextSync; // +88
uint32_t m_configTimeBetweenSyncs; // +92
uint32_t m_configMaxBackoff; // +96, usually 60000
uint32_t m_effectiveTimeBetweenSyncs; // +100
uint32_t m_lastRtt; // +104
uint32_t m_retryCount; // +108
uint32_t m_requestSequence; // +112
uint32_t m_replySequence; // +116
uint32_t m_flags; // +120
uint32_t m_packetFlags; // +124
uint32_t m_lastTime; // +128, used to prevent time from going backwards
uint8_t m_applyFlags; // +132
uint8_t m_disabled; // +133
};
}

static_assert(sizeof(rage::netTimeSync<1604>) == 136);
static_assert(sizeof(rage::netTimeSync<2060>) == 144);
static_assert(sizeof(rage::netTimeSync<2372>) == 128);
Loading

0 comments on commit 2d66539

Please sign in to comment.