#ifndef NETMESSAGE_H #define NETMESSAGE_H #ifdef _WIN32 #pragma once #endif #include "networksystem/inetworkserializer.h" template class CNetMessagePB; class CNetMessage { public: // Disabled as per CNetMessagePB note CNetMessage() = delete; CNetMessage( const CNetMessage & ) = delete; virtual ~CNetMessage() {} // Returns the underlying proto object virtual void *AsProto() const = 0; virtual void *AsProto2() const = 0; virtual INetworkMessageInternal *GetNetMessage() const = 0; virtual CNetMessage *CopyConstruct( const CNetMessage *other ) const = 0; // Helper function to cast up the abstract message to a concrete CNetMessagePB type. // Doesn't do any validity checks itself! template const CNetMessagePB *ToPB() const { return static_cast *>(this); } template CNetMessagePB *ToPB() { return static_cast *>(this); } private: char unk001[32]; }; // AMNOTE: This is a stub class over real CNetMessagePB! // This is mainly to access the game constructed objects, and not for direct initialization of them // since this misses the CNetMessage implementation which requires supplying other proto related info like // proto binding object, proto msg id/group, etc. // So to allocate the message yourself use INetworkMessageInternal::AllocateMessage() or INetworkMessages::AllocateNetMessageAbstract() // functions instead of direct initialization (they both are equivalent)! // Example usage: // CNetMessagePB *msg = INetworkMessageInternal::AllocateMessage()->ToPB(); // msg->field1( 2 ); // msg->field2( 3 ); // IGameEventSystem::PostEventAbstract( ..., msg, ... ); template class CNetMessagePB : public CNetMessage, public PROTO_TYPE { public: // Prevent manual construction of this object as per the comment above CNetMessagePB() = delete; CNetMessagePB( const CNetMessagePB & ) = delete; }; #endif // NETMESSAGE_H