Skip to content

Commit

Permalink
NetMessage logging added to Quazal logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ihatecompvir committed Apr 22, 2024
1 parent b3fd831 commit 72d49f6
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 197 deletions.
3 changes: 2 additions & 1 deletion include/QuazalHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
Quazal is the creator of the networking middleware used by RB3.
*/

#include "rb3/Quazal/StepSequenceJobStep.h"
#include "quazal/StepSequenceJobStep.h"

extern void OperatorEqualsFmt(char *r3, char *r4);
void OperatorEqualsFmtHook(char *r3, char *r4);
extern int StepSequenceJobSetStep(int *unk, StepSequenceJobStep *step);
int StepSequenceJobSetStepHook(int *unk, StepSequenceJobStep *step);
void NetMessengerDispatchMsgHook(NetMessenger *thisNetMessenger, int *sender, unsigned char byteCode, BinStream *buffer);
392 changes: 199 additions & 193 deletions include/ports.h

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions include/quazal/NetMessenger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef _NETMESSENGER_H
#define _NETMESSENGER_H

#include "rb3/BinStream.h"
#include "rb3/TextStream.h"

typedef struct _NetMessage NetMessage;

typedef void (*NetMessageDestructor_t)(NetMessage *thisNetMessage, int unk);
typedef void (*NetMessageSave_t)(NetMessage *thisNetMessage, BinStream *binStream);
typedef void (*NetMessageLoad_t)(NetMessage *thisNetMessage, BinStream *binStream);
typedef void (*NetMessageDispatch_t)(NetMessage *thisNetMessage);
typedef char (*NetMessageVoiceData_t)(NetMessage *thisNetMessage);
typedef void (*NetMessagePrint_t)(NetMessage *thisNetMessage, TextStream *thisTextStream);
typedef unsigned char (*NetMessageByteCode_t)(NetMessage *thisNetMessage);
typedef char *(*NetMessageName_t)(NetMessage *thisNetMessage);

typedef struct _NetMessage_vtable
{
// wii specific rtti stuff
#ifdef RB3E_WII
void *rtti;
int unk;
#endif

NetMessageDestructor_t destructor; // self-explanatory
NetMessageSave_t save; // serializes the net message into a stream
NetMessageLoad_t load; // deserializes the net message from a stream
NetMessageDispatch_t dispatch; // dispatches the net message (this is ran on recv)
NetMessageVoiceData_t voiceData; // ?? not quite sure what this one is
NetMessagePrint_t print; // prints the net message into a textstream, if possible
NetMessageByteCode_t byteCode; // the "bytecode" of the net message (i.e. its internal numeric ID)
NetMessageName_t name; // the name of the net message (DataArrayMsg, etc.)

} NetMessage_vtable;

// used to synchronize arbitrary data
// this is the parent class of all messages that get synchronized P2P through the MessageBroker
typedef struct _NetMessage
{
NetMessage_vtable *vtable;
};

typedef struct _NetMessenger
{
unsigned int mLastSender;
} NetMessenger;

extern void NetMessengerDispatchMsg(NetMessenger *thisNetMessenger, int *sender, unsigned char byteCode, BinStream *buffer);
extern NetMessage *NetMessageFactoryCreateNetMessage(void *thisNetMessageFactory, unsigned char byteCode);

#endif // _NETMESSENGER_H
File renamed without changes.
4 changes: 3 additions & 1 deletion include/rb3_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
#include "rb3/Vector.h"
#include "quazal/InetAddress.h"
#include "quazal/QuazalSocket.h"
#include "quazal/NetMessenger.h"
#include "quazal/StepSequenceJobStep.h"

// rnd headers
#include "rb3/Rnd/RndPropAnim.h"

// UI headers
#include "rb3/UI/UIPanel.h"

#endif // _RB3INCLUDE_H_
#endif // _RB3INCLUDE_H_
35 changes: 35 additions & 0 deletions source/QuazalHooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "rb3e_include.h"
#include "rb3/BinStream.h"
#include <string.h>

// dirty hack to get the game to print Quazal debug logging out to DbgPrint/OSReport instead
Expand All @@ -23,4 +24,38 @@ int StepSequenceJobSetStepHook(int *unk, StepSequenceJobStep *step)
RB3E_DEBUG("Quazal Job: %s", step->jobName);
}
return StepSequenceJobSetStep(unk, step);
}

// function is very simple so lets just completely rewrite it and also introduce additional safety checks
void NetMessengerDispatchMsgHook(NetMessenger *thisNetMessenger, int *sender, unsigned char byteCode, BinStream *buffer)
{
NetMessage *retMsg = {0};

if (thisNetMessenger == NULL)
{
RB3E_DEBUG("NetMessenger is NULL, can't dispatch message", NULL);
return;
}

if (sender == NULL)
{
RB3E_DEBUG("Sender is NULL, can't dispatch message", NULL);
return;
}

thisNetMessenger->mLastSender = *sender;

retMsg = NetMessageFactoryCreateNetMessage((void *)PORT_THENETMESSAGEFACTORY, byteCode);
if (retMsg == NULL)
{
RB3E_DEBUG("Failed to create NetMessage for byteCode %i", byteCode);
return;
}

RB3E_DEBUG("Dispatching NetMessage of class name %s", retMsg->vtable->name(retMsg));
retMsg->vtable->load(retMsg, buffer);
retMsg->vtable->dispatch(retMsg);
retMsg->vtable->destructor(retMsg, 1);

return;
}
4 changes: 3 additions & 1 deletion source/_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@ RB3E_STUB(BinstreamReadEndian)
RB3E_STUB(BinstreamWriteEndian)
RB3E_STUB(BinstreamWriteLengthString)
RB3E_STUB(MessageBrokerDDL)
RB3E_STUB(PropSyncBool)
RB3E_STUB(PropSyncBool)
RB3E_STUB(NetMessengerDispatchMsg)
RB3E_STUB(NetMessageFactoryCreateNetMessage)
3 changes: 2 additions & 1 deletion source/rb3enhanced.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void ApplyConfigurablePatches()
POKE_32(0x82a976dc, LI(8, 1));
POKE_32(0x82a97920, NOP);
#endif

HookFunction(PORT_NETMESSENGERDISPATCHMSG, &NetMessengerDispatchMsg, &NetMessengerDispatchMsgHook);
HookFunction(PORT_STEPSEQUENCEJOBSETSTEP, &StepSequenceJobSetStep, &StepSequenceJobSetStepHook);
}
#endif
Expand Down Expand Up @@ -329,6 +329,7 @@ void InitialiseFunctions()
POKE_B(&BinstreamWriteEndian, PORT_BINSTREAMWRITEENDIAN);
POKE_B(&BinstreamReadEndian, PORT_BINSTREAMREADENDIAN);
POKE_B(&BinstreamWriteLengthString, PORT_BINSTREAMWRITELENGTHSTRING);
POKE_B(&NetMessageFactoryCreateNetMessage, PORT_NETMESSAGEFACTORYCREATENETMESSAGE);
RB3E_MSG("Functions initialized!", NULL);
}

Expand Down

0 comments on commit 72d49f6

Please sign in to comment.