Merge branch 'runengineprediction' into 'master'

add a runengineprediction helper function and the interfaces required

See merge request !1
This commit is contained in:
nullifiedcat 2016-12-03 06:43:57 -05:00
commit 6e5cfc7ba6
4 changed files with 79 additions and 0 deletions

View File

@ -715,6 +715,73 @@ bool IsEntityVisiblePenetration(IClientEntity* entity, int hb) {
return false;
}
class CMoveData;
void RunEnginePrediction(IClientEntity* ent, CUserCmd *ucmd) {
// we are going to require some helper functions for this to work
// notably SetupMove, FinishMove and ProcessMovement
// setup the types of the functions
typedef void(*SetupMoveFn)(IClientEntity *, CUserCmd *, class IMoveHelper *, CMoveData *);
typedef void(*FinishMoveFn)(IClientEntity *, CUserCmd*, CMoveData*);
typedef void(*ProcessMovementFn)(IClientEntity *, CMoveData *);
typedef void(*StartTrackPredictionErrorsFn)(IClientEntity *);
typedef void(*FinishTrackPredictionErrorsFn)(IClientEntity *);
// get the vtable
void **predictionVtable = (void **)interfaces::prediction;
// get the functions
SetupMoveFn oSetupMove = (SetupMoveFn) predictionVtable[19];
FinishMoveFn oFinishMove = (FinishMoveFn) predictionVtable[20];
// get the vtable
void **gameMovementVtable = (void **)interfaces::gamemovement;
// get the functions
ProcessMovementFn oProcessMovement = (ProcessMovementFn) gameMovementVtable[2];
StartTrackPredictionErrorsFn oStartTrackPredictionErrors = (StartTrackPredictionErrorsFn) gameMovementVtable[3];
FinishTrackPredictionErrorsFn oFinishTrackPredictionErrors = (FinishTrackPredictionErrorsFn) gameMovementVtable[4];
// use this as movedata (should be big enough - otherwise the stack will die!)
unsigned char moveData[2048];
CMoveData *pMoveData = (CMoveData *)&(moveData[0]);
// back up globals
float frameTime = interfaces::gvars->frametime;
float curTime = interfaces::gvars->curtime;
CUserCmd defaultCmd;
if(ucmd == NULL)
{
ucmd = &defaultCmd;
}
// set the current command
SetEntityValue<void *>(ent, 0x105C, ucmd);
// set up the globals
interfaces::gvars->curtime = gInts->Globals->interval_per_tick * GetEntityValue<int>(ent, eoffsets.nTickBase);
interfaces::gvars->frametime = gInts->Globals->interval_per_tick;
oStartTrackPredictionErrors(ent);
oSetupMove(ent, ucmd, NULL, pMoveData);
oProcessMovement(ent, ucmd, pMoveData);
oFinishMove(ent, pMoveData);
oFinishTrackPredictionErrors(ent);
// reset the current command
SetEntityValue<void *>(ent, 0x105C, NULL);
// restore globals
interfaces::gvars->frametime = frametime;
interfaces::gvars->curtime = curTime;
return;
}
char* strfmt(const char* fmt, ...) {
char* buf = new char[1024];
va_list list;

View File

@ -75,6 +75,8 @@ bool BulletTime();
bool IsEntityVisiblePenetration(IClientEntity* entity, int hb);
void RunEnginePrediction(IClientEntity* ent, CUserCmd *ucmd = NULL);
// Stolen Code
// F1 c&p

View File

@ -28,6 +28,8 @@ IVModelInfoClient* interfaces::model = 0;
IInputSystem* interfaces::input = 0;
ICvar* interfaces::cvar = 0;
CGlobalVarsBase* interfaces::gvars = 0;
IPrediction* interfaces::prediction = 0;
IGameMovement* interfaces::gamemovement = 0;
void interfaces::CreateInterfaces() {
interfaces::centerPrint = reinterpret_cast<ICenterPrint*>(sharedobj::client->fptr("VCENTERPRINT002", nullptr));
@ -50,4 +52,8 @@ void interfaces::CreateInterfaces() {
//interfaces::gvars = *reinterpret_cast<CGlobalVarsBase**>(gSignatures.GetClientSignature("55 89 E5 53 83 EC ? A1 ? ? ? ? 0F B6 5D 0C F3 0F 10 40 10") + 8);
interfaces::gvars = **(reinterpret_cast<CGlobalVarsBase***>((uintptr_t)11 + gSignatures.GetClientSignature("55 89 E5 83 EC ? 8B 45 08 8B 15 ? ? ? ? F3 0F 10")));
//interfaces::gvars = *reinterpret_cast<CGlobalVarsBase**>(hudupdate + 13 + *reinterpret_cast<uint32_t*>(hudupdate + 13 + 3) + 7);
interfaces::prediction = reinterpret_cast<IPrediction*>(sharedobj::client->CreateInterface("VClientPrediction001"));
interfaces::gamemovement = reinterpret_cast<IGameMovement*>(sharedobj::client->CreateInterface("GameMovement001"));
}

View File

@ -27,6 +27,8 @@ class IVModelInfoClient;
class IInputSystem;
class IClient;
class CGlobalVarsBase;
class IPrediction;
class IGameMovement;
namespace interfaces {
@ -44,6 +46,8 @@ extern IEngineTrace* trace;
extern IVModelInfoClient* model;
extern IInputSystem* input;
extern CGlobalVarsBase* gvars;
extern IPrediction* prediction;
extern IGameMovement* gamemovement;
void CreateInterfaces();