Skip to content

Commit

Permalink
Send custom data via svc_director message instead of delta.
Browse files Browse the repository at this point in the history
Minor refactoring.
  • Loading branch information
s1lentq committed Jan 2, 2018
1 parent a672305 commit 33ce752
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 110 deletions.
1 change: 1 addition & 0 deletions dep/hlsdk/engine/usermsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ typedef struct _UserMsg
} UserMsg;

bool HookUserMsg(char *pszMsgName, pfnUserMsgHook pfn);
bool UnHookUserMsg(char *pszMsgName);

extern UserMsg *g_pClientUserMsgs;
extern std::map<std::string, pfnUserMsgHook> g_ClientUserMsgsMap;
3 changes: 3 additions & 0 deletions dep/hlsdk/pm_shared/pm_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,8 @@ typedef struct playermove_s
void (*PM_PlaySound)(int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch);
const char *(*PM_TraceTexture)(int ground, float *vstart, float *vend);
void (*PM_PlaybackEventFull)(int flags, int clientindex, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2);
pmtrace_t (*PM_PlayerTraceEx)(float *start, float *end, int traceFlags, int (*pfnIgnore)(physent_t *pe));
int (*PM_TestPlayerPositionEx)(float *pos, pmtrace_t *ptrace, int (*pfnIgnore)(physent_t *pe));
struct pmtrace_s *(*PM_TraceLineEx)(float *start, float *end, int flags, int usehulll, int (*pfnIgnore)(physent_t *pe));

} playermove_t;
104 changes: 82 additions & 22 deletions hitboxtracker/client/src/cdll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,104 @@ int Initialize(cl_enginefunc_t *pEnginefuncs, int iVersion)

void HUD_Init()
{
g_pClientfuncs->pHudFrame = HUD_Frame;
g_pClientfuncs->pPostRunCmd = HUD_PostRunCmd;
g_pClientfuncs->pProcessPlayerState = HUD_ProcessPlayerState;
g_pClientfuncs->pStudioInterface = HUD_GetStudioModelInterface;
g_pClientfuncs->pDirectorMessage = HUD_DirectorMessage;

gClientfuncs.pHudInitFunc();
gHUD.Init();
}

void HUD_WeaponsPostThink(local_state_t *from, local_state_t *to, usercmd_t *cmd, double time, unsigned int random_seed)
void HUD_Frame(double time)
{
int flags = from->client.iuser3;
net_status_t st;
gEngfuncs.pNetAPI->Status(&st);

const auto delay = 0.5;
if (st.connected == 1 && st.connection_time > (delay - 0.1) && st.connection_time < delay)
{
// tell the server that i want to sync
gEngfuncs.pfnServerCmd("__request_sync");
}

g_bHoldingKnife = (from->client.m_iId == WEAPON_KNIFE);
g_bHoldingShield = (flags & PLAYER_HOLDING_SHIELD) != 0;
gClientfuncs.pHudFrame(time);
}

void HUD_ProcessPlayerState(entity_state_t *dst, entity_state_t *src)
union split_double_t
{
// save current values of fields from server-side
auto &sync = g_PlayerSyncInfo[src->number];
split_double_t() : d (0.0) {}
split_double_t(double f) : d(f) {}

sync.yaw = src->vuser1[0];
sync.gaityaw = src->vuser1[1];
sync.gaitframe = src->vuser1[2];
double d;
struct {
int32_t lo;
int32_t hi;
};
};

sync.gaitmovement = src->vuser2[0];
sync.gaitsequence = src->vuser2[1];
sync.pitch = src->vuser2[2];
constexpr size_t DIRECTOR_UID = 0xabcdef00;

sync.prevgaitorigin[0] = src->maxs[0];
sync.prevgaitorigin[1] = src->maxs[1];
sync.prevgaitorigin[2] = src->maxs[2];

sync.time = src->mins[0]; // m_clTime
sync.oldtime = src->mins[1]; // m_clOldTime
sync.frametime = src->mins[2]; // m_clTime - m_clOldTime?
void HUD_DirectorMessage(int iSize, void *pbuf)
{
BEGIN_READ(pbuf, iSize);

auto cmd = READ_BYTE();
if (cmd != DRC_CMD_TIMESCALE)
{
gClientfuncs.pDirectorMessage(iSize, pbuf);
return;
}

// make sure that this is our custom message
auto uid = READ_LONG();
if (uid != DIRECTOR_UID)
{
gClientfuncs.pDirectorMessage(iSize, pbuf);
return;
}

auto index = READ_BYTE();

// header packet
if (index == 0)
{
// parse time
split_double_t time, oldtime;

time.lo = READ_LONG();
time.hi = READ_LONG();

oldtime.lo = READ_LONG();
oldtime.hi = READ_LONG();

sv.time = time.d;
sv.oldtime = oldtime.d;
sv.frametime = READ_FLOAT();
}
else
{
auto &sync = g_PlayerSyncInfo[index];

// save current values of fields from server-side
sync.prevgaitorigin[0] = READ_FLOAT();
sync.prevgaitorigin[1] = READ_FLOAT();
sync.prevgaitorigin[2] = READ_FLOAT();

sync.yaw = READ_FLOAT();
sync.pitch = READ_FLOAT();

sync.gaityaw = READ_FLOAT();
sync.gaitframe = READ_FLOAT();
sync.gaitmovement = READ_FLOAT();
sync.gaitsequence = READ_LONG ();
}
}

gClientfuncs.pProcessPlayerState(dst, src);
void HUD_WeaponsPostThink(local_state_t *from, local_state_t *to, usercmd_t *cmd, double time, unsigned int random_seed)
{
g_bHoldingKnife = (from->client.m_iId == WEAPON_KNIFE);
g_bHoldingShield = (from->client.iuser3 & PLAYER_HOLDING_SHIELD) == PLAYER_HOLDING_SHIELD;
}

void R_ForceCVars(qboolean multiplayer)
Expand Down
1 change: 1 addition & 0 deletions hitboxtracker/client/src/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cvar_t *cl_minmodels;
cvar_t *default_fov;
cvar_t *sensitivity;

server_sync_t sv;
player_sync_t g_PlayerSyncInfo [MAX_PLAYERS + 1];
extra_player_info_t g_PlayerExtraInfo[MAX_PLAYERS + 1]; // additional player info sent directly to the client dll

Expand Down
14 changes: 10 additions & 4 deletions hitboxtracker/client/src/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ enum
MAX_TEAM_NAME = 16,
};

struct server_sync_t
{
double time;
double oldtime;
float frametime;
};

struct player_sync_t
{
float yaw;
Expand All @@ -45,9 +52,6 @@ struct player_sync_t
float gaitframe;
float gaitmovement;
int gaitsequence;
float time;
float oldtime;
float frametime;
Vector prevgaitorigin;
};

Expand All @@ -72,7 +76,8 @@ struct extra_player_info_t
};

// Macros to hook function calls into the HUD object
#define HOOK_MESSAGE(x) HookUserMsg(#x, __MsgFunc_##x)
#define HOOK_MESSAGE(x) HookUserMsg(#x, __MsgFunc_##x)
#define UNHOOK_MESSAGE(x) UnHookUserMsg(#x)

#define DECLARE_MESSAGE(y, x)\
int __MsgFunc_##x(const char *pszName, int iSize, void *pbuf)\
Expand Down Expand Up @@ -113,6 +118,7 @@ class CHud

extern CHud gHUD;

extern server_sync_t sv;
extern player_sync_t g_PlayerSyncInfo [MAX_PLAYERS + 1];
extern extra_player_info_t g_PlayerExtraInfo[MAX_PLAYERS + 1];

Expand Down
19 changes: 12 additions & 7 deletions hitboxtracker/client/src/modules/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ bool CEngine::Init(const char *szModuleName, const char *pszFile)

m_Software = !Q_stricmp(szModuleName, ENGINE_CLIENT_SOFT_LIB) ? true : false;

if (!LoadSecureClient_Init() || !LoadInSecureClient_Init())
if (!LoadSecureClient_Init())
{
TraceLog("> %s: Not found ClientFuncs\n", __FUNCTION__);
TraceLog("> %s: Not found LoadSecureClient\n", __FUNCTION__);
return false;
}

if (!LoadInSecureClient_Init())
{
TraceLog("> %s: Not found LoadInSecureClient\n", __FUNCTION__);
return false;
}

Expand Down Expand Up @@ -229,12 +235,11 @@ bool CEngine::StudioLightingInit()

void R_StudioLighting(float *lv, int bone, int flags, const vec_t *normal)
{
if (!pfnR_StudioLighting) {
*lv = 0.75f;
return;
}
*lv = 0.75f;

pfnR_StudioLighting(lv, bone, flags, normal);
if (pfnR_StudioLighting) {
pfnR_StudioLighting(lv, bone, flags, normal);
}

if (g_EngineLib->IsSoftware()) {
*lv = *lv / (USHRT_MAX + 1);
Expand Down
18 changes: 8 additions & 10 deletions hitboxtracker/client/src/studio/GameStudioModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,6 @@ void CGameStudioModelRenderer::StudioSetupBones()
&& m_pCurrentEntity->curstate.sequence != ANIM_SWIM_1
&& m_pCurrentEntity->curstate.sequence != ANIM_SWIM_2)
{
bool bCopy = true;

if (m_pPlayerInfo->gaitsequence >= m_pStudioHeader->numseq || m_pPlayerInfo->gaitsequence < 0)
m_pPlayerInfo->gaitsequence = 0;

Expand All @@ -366,6 +364,7 @@ void CGameStudioModelRenderer::StudioSetupBones()
panim = StudioGetAnim(m_pRenderModel, pseqdesc);
StudioCalcRotations(pos2, q2, pseqdesc, panim, m_pPlayerInfo->gaitframe);

bool bCopy = true;
for (int i = 0; i < m_pStudioHeader->numbones; i++)
{
if (!Q_strcmp(pbones[i].name, "Bip01 Spine"))
Expand Down Expand Up @@ -418,7 +417,7 @@ void CGameStudioModelRenderer::StudioEstimateGait(entity_state_t *pplayer)
float dt;
if (m_pPlayerSync)
{
dt = clamp(m_pPlayerSync->time - m_pPlayerSync->oldtime, 0.0f, 1.0f);
dt = clamp(sv.time - sv.oldtime, 0.0, 1.0);
}
else
{
Expand Down Expand Up @@ -513,7 +512,7 @@ void CGameStudioModelRenderer::StudioProcessGait(entity_state_t *pplayer)
float dt;
if (m_pPlayerSync)
{
dt = clamp(m_pPlayerSync->time - m_pPlayerSync->oldtime, 0.0f, 1.0f);
dt = clamp(sv.time - sv.oldtime, 0.0, 1.0);
}
else
{
Expand Down Expand Up @@ -732,7 +731,7 @@ void CGameStudioModelRenderer::SetupClientAnimation(entity_state_t *pplayer)
st->m_fSequenceLoops = ((GetSequenceFlags(pmodel, st) & STUDIO_LOOPING) != 0) ? TRUE : FALSE;
StudioFrameAdvance(st, fr, dt);

// gEngfuncs.Con_Printf("gs %i frame %f\n", st->gaitsequence, st->frame);
//gEngfuncs.Con_Printf("gs %i frame %f\n", st->gaitsequence, st->frame);

ent->angles = st->realangles;
ent->curstate.angles = st->angles;
Expand Down Expand Up @@ -809,7 +808,7 @@ int CGameStudioModelRenderer::StudioDrawPlayer(int flags, entity_state_t *pplaye

// Call real draw function
int iret = _StudioDrawPlayer(flags, pplayer);
if (iret && m_pCvarDrawEntities->value == 6)
if (iret && (m_pCvarDrawEntities->value == 6 || m_pCvarDrawEntities->value == 7))
{
m_pPlayerSync = &g_PlayerSyncInfo[pplayer->number];
m_pPlayerInfo = IEngineStudio.PlayerInfo(m_nPlayerIndex);
Expand Down Expand Up @@ -982,7 +981,6 @@ int CGameStudioModelRenderer::_StudioDrawPlayer(int flags, entity_state_t *pplay
if (m_pCurrentEntity->index > 0)
{
cl_entity_t *ent = gEngfuncs.GetEntityByIndex(m_pCurrentEntity->index);

Q_memcpy(ent->attachment, m_pCurrentEntity->attachment, sizeof(ent->attachment));
}
}
Expand Down Expand Up @@ -1157,9 +1155,9 @@ void CGameStudioModelRenderer::CalculatePitchBlend(entity_state_t *pplayer)

StudioPlayerBlend(pseqdesc, &iBlend, &m_pCurrentEntity->angles[PITCH]);

m_pCurrentEntity->latched.prevangles[PITCH] = m_pCurrentEntity->angles[PITCH];
m_pCurrentEntity->curstate.blending[1] = iBlend;
m_pCurrentEntity->latched.prevblending[1] = m_pCurrentEntity->curstate.blending[1];
m_pCurrentEntity->latched.prevangles[PITCH] = m_pCurrentEntity->angles[PITCH];
m_pCurrentEntity->curstate.blending[1] = iBlend;
m_pCurrentEntity->latched.prevblending[1] = m_pCurrentEntity->curstate.blending[1];
m_pCurrentEntity->latched.prevseqblending[1] = m_pCurrentEntity->curstate.blending[1];
}

Expand Down
Loading

0 comments on commit 33ce752

Please sign in to comment.