WIP game event parsing
This commit is contained in:
@ -25,10 +25,7 @@ namespace NetHandlers
|
||||
using JsonWrite = base::JsonWriterFile;
|
||||
}
|
||||
|
||||
struct SourceGameContext
|
||||
{
|
||||
int16_t protocol;
|
||||
};
|
||||
struct SourceGameContext;
|
||||
|
||||
#if !defined(MAX_OSPATH)
|
||||
#define MAX_OSPATH 260 // max length of a filesystem pathname
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "svc_createstringtable.h"
|
||||
#include "base/bitfile.h"
|
||||
#include "base/jsonfile.h"
|
||||
#include "game/sourcecontext.h"
|
||||
#include "netmath.h"
|
||||
#include "netcontants.h"
|
||||
|
||||
|
@ -5,13 +5,32 @@
|
||||
#include "netcontants.h"
|
||||
#include "netmath.h"
|
||||
|
||||
#ifdef WIP_GAMEEVENTS
|
||||
#include "svc_gameeventlist.h"
|
||||
#endif
|
||||
|
||||
namespace NetHandlers
|
||||
{
|
||||
bool SVC_GameEvent_BitRead_Internal(BitRead& bitbuf, SourceGameContext& context, NetMsg::SVC_GameEvent* data)
|
||||
{
|
||||
data->dataLengthInBits = bitbuf.ReadUBitLong(11);
|
||||
data->data.reset(new uint8_t[math::BitsToBytes(data->dataLengthInBits)]);
|
||||
bitbuf.ReadBits(data->data.get(), data->dataLengthInBits);
|
||||
const unsigned int numBits = bitbuf.ReadUBitLong(11);
|
||||
const size_t numBytes = math::BitsToBytes(numBits);
|
||||
|
||||
data->dataLengthInBits = numBits;
|
||||
data->data.reset(new uint8_t[numBytes]);
|
||||
bitbuf.ReadBits(data->data.get(), numBits);
|
||||
|
||||
#ifdef WIP_GAMEEVENTS
|
||||
{
|
||||
BitRead bitbuf2(data->data.get(), numBytes, numBits);
|
||||
const size_t id = bitbuf2.ReadUBitLong(9);
|
||||
//std::vector<char> stringMem;
|
||||
//GameEvents::ParseEventData(bitbuf2, context.gameEventList->eventDescriptors[id], stringMem);
|
||||
GameEvents::PrintEventData(bitbuf2, context.gameEventList->eventDescriptors[id]);
|
||||
printf("%i\n", id);
|
||||
}
|
||||
#endif // WIP_GAMEEVENTS
|
||||
|
||||
return !bitbuf.IsOverflowed();
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "nethandlers.h"
|
||||
#include "game/gameevents.h"
|
||||
#include <memory>
|
||||
|
||||
namespace NetMsg
|
||||
{
|
||||
struct SVC_GameEvent
|
||||
{
|
||||
GameEvents::EventDataMap eventData;
|
||||
std::unique_ptr<uint8_t[]> data;
|
||||
uint16_t dataLengthInBits;
|
||||
};
|
||||
|
@ -2,11 +2,12 @@
|
||||
#include "svc_gameeventlist.h"
|
||||
#include "base/bitfile.h"
|
||||
#include "base/jsonfile.h"
|
||||
#include "game/sourcecontext.h"
|
||||
#include "netcontants.h"
|
||||
#include "netmath.h"
|
||||
|
||||
using EventDescriptor = NetMsg::SVC_GameEventList::EventDescriptor;
|
||||
using EventValue = NetMsg::SVC_GameEventList::EventValue;
|
||||
using EventDescriptor = GameEvents::EventDescriptor;
|
||||
using EventValue = GameEvents::EventValue;
|
||||
|
||||
uint32_t CalculateNumDataBits(const std::vector<EventDescriptor>& eventDescriptors)
|
||||
{
|
||||
@ -38,13 +39,20 @@ namespace NetHandlers
|
||||
event.id = bitbuf.ReadUBitLong(MAX_EVENT_BITS);
|
||||
bitbuf.ReadString(event.name, sizeof(event.name));
|
||||
EventValue value;
|
||||
while ((value.type = bitbuf.ReadUBitLong(3)) > 0)
|
||||
while ((value.type = static_cast<GameEvents::EventValueType>(bitbuf.ReadUBitLong(3))) > 0)
|
||||
{
|
||||
bitbuf.ReadString(value.name, sizeof(value.name));
|
||||
event.values.push_back(value);
|
||||
}
|
||||
event.values.shrink_to_fit();
|
||||
}
|
||||
|
||||
#ifdef WIP_GAMEEVENTS
|
||||
if (!context.gameEventList)
|
||||
{
|
||||
context.gameEventList = new NetMsg::SVC_GameEventList(*data);
|
||||
}
|
||||
#endif
|
||||
return !bitbuf.IsOverflowed();
|
||||
}
|
||||
|
||||
@ -52,6 +60,7 @@ namespace NetHandlers
|
||||
{
|
||||
bitbuf.WriteUBitLong(data->eventDescriptors.size(), MAX_EVENT_BITS);
|
||||
bitbuf.WriteUBitLong(data->dataLengthInBits, 20);
|
||||
assert(data->dataLengthInBits == CalculateNumDataBits(data->eventDescriptors));
|
||||
for (EventDescriptor& event : data->eventDescriptors)
|
||||
{
|
||||
bitbuf.WriteUBitLong(event.id, MAX_EVENT_BITS);
|
||||
@ -79,7 +88,7 @@ namespace NetHandlers
|
||||
base::JsonReaderArray values = obj.ReadArray("values");
|
||||
values.TransformTo(event.values, [](base::JsonReaderObject& obj, EventValue& value)
|
||||
{
|
||||
value.type = obj.ReadUInt32("type");
|
||||
value.type = static_cast<GameEvents::EventValueType>(obj.ReadUInt32("type"));
|
||||
obj.ReadString("name", value.name, sizeof(value.name));
|
||||
});
|
||||
});
|
||||
|
@ -3,26 +3,15 @@
|
||||
|
||||
#include "nethandlers.h"
|
||||
#include "netcontants.h"
|
||||
#include "game/gameevents.h"
|
||||
#include <vector>
|
||||
|
||||
namespace NetMsg
|
||||
{
|
||||
struct SVC_GameEventList
|
||||
{
|
||||
struct EventValue
|
||||
{
|
||||
uint8_t type;
|
||||
char name[MAX_EVENT_NAME_LENGTH];
|
||||
};
|
||||
struct EventDescriptor
|
||||
{
|
||||
uint16_t id;
|
||||
char name[MAX_EVENT_NAME_LENGTH];
|
||||
std::vector<EventValue> values;
|
||||
};
|
||||
|
||||
std::vector<GameEvents::EventDescriptor> eventDescriptors;
|
||||
uint32_t dataLengthInBits;
|
||||
std::vector<EventDescriptor> eventDescriptors;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "svc_prefetch.h"
|
||||
#include "base/bitfile.h"
|
||||
#include "base/jsonfile.h"
|
||||
#include "game/sourcecontext.h"
|
||||
#include "netcontants.h"
|
||||
|
||||
namespace NetHandlers
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "svc_serverinfo.h"
|
||||
#include "base/bitfile.h"
|
||||
#include "base/jsonfile.h"
|
||||
#include "game/sourcecontext.h"
|
||||
|
||||
namespace NetHandlers
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "svc_tempentities.h"
|
||||
#include "base/bitfile.h"
|
||||
#include "base/jsonfile.h"
|
||||
#include "game/sourcecontext.h"
|
||||
#include "netcontants.h"
|
||||
#include "netmath.h"
|
||||
|
||||
|
Reference in New Issue
Block a user