Implemented demmessage json writer funcs

This commit is contained in:
Jordan Cristiano 2015-06-26 01:06:29 -04:00
parent 9696646576
commit 121dd61e9a
7 changed files with 132 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#include "dem_consolecmd.h" #include "dem_consolecmd.h"
#include "demofile/demofile.h" #include "demofile/demofile.h"
#include "base/jsonfile.h"
namespace DemHandlers namespace DemHandlers
{ {
@ -26,6 +27,7 @@ namespace DemHandlers
bool Dem_ConsoleCmd_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_ConsoleCmd* data) bool Dem_ConsoleCmd_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_ConsoleCmd* data)
{ {
jsonbuf.WriteString("command", data->command.c_str(), data->command.length());
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
#include "dem_datatables.h" #include "dem_datatables.h"
#include "demofile/demofile.h" #include "demofile/demofile.h"
#include "demofile/demojson.h"
namespace DemHandlers namespace DemHandlers
{ {
@ -23,6 +24,8 @@ namespace DemHandlers
bool Dem_DataTables_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_DataTables* data) bool Dem_DataTables_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_DataTables* data)
{ {
//jsonbuf.WriteInt32("dataLengthInBytes", data->data.length());
jsonbuf.WriteBytes("data", data->data.begin(), data->data.length());
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
#include "dem_packet.h" #include "dem_packet.h"
#include "demofile/demofile.h" #include "demofile/demofile.h"
#include "demofile/demojson.h"
namespace DemHandlers namespace DemHandlers
{ {
@ -27,6 +28,8 @@ namespace DemHandlers
bool Dem_Packet_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_Packet* data) bool Dem_Packet_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_Packet* data)
{ {
DemoJsonWriter::WriteCmdInfo(jsonbuf, data->cmdInfo);
DemoJsonWriter::WriteSequenceInfo(jsonbuf, data->sequenceNum1, data->sequenceNum2);
return true; return true;
} }
} }

View File

@ -3,6 +3,7 @@
#include "demofile/demofile.h" #include "demofile/demofile.h"
#include "netmessages/netcontants.h" #include "netmessages/netcontants.h"
#include "sourcesdk/bitbuf.h" #include "sourcesdk/bitbuf.h"
#include "base/jsonfile.h"
#include <memory> #include <memory>
static void StringTableEntry_BitRead(bf_read& bitbuf, DemMsg::Dem_StringTables::StringTableEntry* data) static void StringTableEntry_BitRead(bf_read& bitbuf, DemMsg::Dem_StringTables::StringTableEntry* data)
@ -39,6 +40,14 @@ static void StringTableEntry_BitWrite(bf_write& bitbuf, DemMsg::Dem_StringTables
} }
} }
static void StringTableEntry_JsonWrite(JsonWrite& jsonbuf, const DemMsg::Dem_StringTables::StringTableEntry* data)
{
jsonbuf.StartObject(data->entryName.c_str());
//jsonbuf.WriteUInt32("dataLengthInBytes", data->data.length());
jsonbuf.WriteBytes("data", data->data.begin(), data->data.length());
jsonbuf.EndObject();
}
static void StringTable_BitRead(bf_read& bitbuf, DemMsg::Dem_StringTables::StringTable* data) static void StringTable_BitRead(bf_read& bitbuf, DemMsg::Dem_StringTables::StringTable* data)
{ {
using StringTable = DemMsg::Dem_StringTables::StringTable; using StringTable = DemMsg::Dem_StringTables::StringTable;
@ -91,6 +100,19 @@ static void StringTable_BitWrite(bf_write& bitbuf, DemMsg::Dem_StringTables::Str
} }
} }
static void StringTable_JsonWrite(JsonWrite& jsonbuf, const DemMsg::Dem_StringTables::StringTable* data)
{
using StringTableEntry = DemMsg::Dem_StringTables::StringTableEntry;
jsonbuf.StartArray(data->tableName.c_str());
for (const StringTableEntry& entry : data->entries1)
{
jsonbuf.StartObject();
StringTableEntry_JsonWrite(jsonbuf, &entry);
jsonbuf.EndObject();
}
jsonbuf.EndArray();
}
namespace DemHandlers namespace DemHandlers
{ {
bool Dem_StringTables_FileRead_Internal(FileRead& demofile, DemMsg::Dem_StringTables* data) bool Dem_StringTables_FileRead_Internal(FileRead& demofile, DemMsg::Dem_StringTables* data)
@ -131,6 +153,15 @@ namespace DemHandlers
bool Dem_StringTables_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_StringTables* data) bool Dem_StringTables_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_StringTables* data)
{ {
using StringTable = DemMsg::Dem_StringTables::StringTable;
jsonbuf.StartArray("tables");
for (const StringTable& table : data->stringtables)
{
jsonbuf.StartObject();
StringTable_JsonWrite(jsonbuf, &table);
jsonbuf.EndObject();
}
jsonbuf.EndArray();
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
#include "dem_usercmd.h" #include "dem_usercmd.h"
#include "demofile/demofile.h" #include "demofile/demofile.h"
#include "demofile/demojson.h"
namespace DemHandlers namespace DemHandlers
{ {
@ -23,6 +24,8 @@ namespace DemHandlers
bool Dem_UserCmd_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_UserCmd* data) bool Dem_UserCmd_JsonWrite_Internal(JsonWrite& jsonbuf, DemMsg::Dem_UserCmd* data)
{ {
DemoJsonWriter::WriteUserCmd(jsonbuf, data->commandNum,
data->commandData.begin(), data->commandData.length());
return true; return true;
} }
} }

View File

@ -0,0 +1,69 @@
#include "demojson.h"
#include "demofile/demotypes.h"
void DemoJsonWriter::WriteDemoHeader(base::JsonWriterFile& writer, const demoheader_t& header)
{
writer.StartObject("demoheader");
writer.WriteString("demofilestamp", header.demofilestamp);
writer.WriteInt32("demoprotocol", header.demoprotocol);
writer.WriteInt32("networkprotocol", header.networkprotocol);
writer.WriteString("servername", header.servername);
writer.WriteString("clientname", header.clientname);
writer.WriteString("mapname", header.mapname);
writer.WriteString("gamedirectory", header.gamedirectory);
writer.WriteFloat("playback_time", header.playback_time);
writer.WriteInt32("playback_ticks", header.playback_ticks);
writer.WriteInt32("playback_frames", header.playback_frames);
writer.WriteInt32("signonlength", header.signonlength);
writer.EndObject();
}
void DemoJsonWriter::WriteSequenceInfo(base::JsonWriterFile& writer,
int32_t seqNum1, int32_t seqNum2)
{
writer.WriteInt32("sequenceNum1", seqNum1);
writer.WriteInt32("sequenceNum2", seqNum2);
}
void DemoJsonWriter::WriteCmdInfo(base::JsonWriterFile& writer,
const democmdinfo_t& info)
{
const democmdinfo_t::Split_t& split = info.u[0];
writer.StartObject("democmdinfo");
writer.WriteInt32("flags", split.flags);
WriteVector(writer, "viewOrigin", split.viewOrigin);
WriteAngles(writer, "viewAngles", split.viewAngles);
WriteAngles(writer, "localViewAngles", split.localViewAngles);
WriteVector(writer, "viewOrigin2", split.viewOrigin2);
WriteAngles(writer, "viewAngles2", split.viewAngles2);
WriteAngles(writer, "localViewAngles2", split.localViewAngles2);
writer.EndObject();
}
void DemoJsonWriter::WriteUserCmd(base::JsonWriterFile& writer,
int32_t cmdNum, const uint8_t* buffer, int32_t length)
{
writer.StartObject("usercmd");
writer.WriteInt32("cmd", cmdNum);
writer.WriteBytes("data", buffer, length);
writer.EndObject();
}
void DemoJsonWriter::WriteVector(base::JsonWriterFile& writer, const char* name, const Vector& vec)
{
writer.StartObject(name);
writer.WriteFloat("x", vec.x);
writer.WriteFloat("y", vec.y);
writer.WriteFloat("z", vec.z);
writer.EndObject();
}
void DemoJsonWriter::WriteAngles(base::JsonWriterFile& writer, const char* name, const QAngle& angles)
{
writer.StartObject(name);
writer.WriteFloat("pitch", angles.x);
writer.WriteFloat("yaw", angles.y);
writer.WriteFloat("roll", angles.z);
writer.EndObject();
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "base/jsonfile.h"
#include <cstdint>
#include <cstdio>
struct demoheader_t;
struct democmdinfo_t;
class Vector;
class QAngle;
namespace DemoJsonWriter
{
void WriteDemoHeader(base::JsonWriterFile& writer, const demoheader_t& header);
void WriteSequenceInfo(base::JsonWriterFile& writer, int32_t seqNum1, int32_t seqNum2);
void WriteCmdInfo(base::JsonWriterFile& writer, const democmdinfo_t& info);
void WriteUserCmd(base::JsonWriterFile& writer, int32_t cmdNum, const uint8_t* buffer, int32_t length);
void WriteVector(base::JsonWriterFile& writer, const char* name, const Vector& vec);
void WriteAngles(base::JsonWriterFile& writer, const char* name, const QAngle& angles);
};