diff --git a/uran/src/helpers.cpp b/uran/src/helpers.cpp index ae6c37b7..b94ee2c8 100644 --- a/uran/src/helpers.cpp +++ b/uran/src/helpers.cpp @@ -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(ent, 0x105C, ucmd); + + // set up the globals + interfaces::gvars->curtime = gInts->Globals->interval_per_tick * GetEntityValue(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(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; diff --git a/uran/src/helpers.h b/uran/src/helpers.h index fb9253ea..480b24bb 100644 --- a/uran/src/helpers.h +++ b/uran/src/helpers.h @@ -75,6 +75,8 @@ bool BulletTime(); bool IsEntityVisiblePenetration(IClientEntity* entity, int hb); +void RunEnginePrediction(IClientEntity* ent, CUserCmd *ucmd = NULL); + // Stolen Code // F1 c&p diff --git a/uran/src/interfaces.cpp b/uran/src/interfaces.cpp index 947dab7f..ddccdc79 100644 --- a/uran/src/interfaces.cpp +++ b/uran/src/interfaces.cpp @@ -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(sharedobj::client->fptr("VCENTERPRINT002", nullptr)); @@ -50,4 +52,8 @@ void interfaces::CreateInterfaces() { //interfaces::gvars = *reinterpret_cast(gSignatures.GetClientSignature("55 89 E5 53 83 EC ? A1 ? ? ? ? 0F B6 5D 0C F3 0F 10 40 10") + 8); interfaces::gvars = **(reinterpret_cast((uintptr_t)11 + gSignatures.GetClientSignature("55 89 E5 83 EC ? 8B 45 08 8B 15 ? ? ? ? F3 0F 10"))); //interfaces::gvars = *reinterpret_cast(hudupdate + 13 + *reinterpret_cast(hudupdate + 13 + 3) + 7); + interfaces::prediction = reinterpret_cast(sharedobj::client->CreateInterface("VClientPrediction001")); + interfaces::gamemovement = reinterpret_cast(sharedobj::client->CreateInterface("GameMovement001")); + + } diff --git a/uran/src/interfaces.h b/uran/src/interfaces.h index c63b55d5..3eb556c0 100644 --- a/uran/src/interfaces.h +++ b/uran/src/interfaces.h @@ -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();