diff --git a/compiledll_common.cmd b/compiledll_common.cmd index 3c31f39..275977e 100644 --- a/compiledll_common.cmd +++ b/compiledll_common.cmd @@ -69,6 +69,8 @@ gcc.exe -c %FLAGS% "../src/cg_servercmds.c" gcc.exe -c %FLAGS% "../src/cg_main.c" gcc.exe -c %FLAGS% "../src/cg_font.c" gcc.exe -c %FLAGS% "../src/cg_scoreboard.c" +gcc.exe -c %FLAGS% "../src/cg_view.c" +gcc.exe -c %FLAGS% "../src/cg_vehicles_mp.c" gcc.exe -c %FLAGS% "../src/win_main.c" gcc.exe -c %FLAGS% "../src/sys_net.c" gcc.exe -c %FLAGS% "../src/httpftp.c" diff --git a/src/callbacks.asm b/src/callbacks.asm index b3372c1..ef3dbd8 100644 --- a/src/callbacks.asm +++ b/src/callbacks.asm @@ -392,6 +392,9 @@ bin_import Load_Material, 0x047B9C0 bin_import Cvar_Init, 0x56d2b0 bin_import R_CheckDxCaps, 0x6349E0 +bin_import CG_ApplyViewAnimation, 0x00450890 +bin_import CG_GetViewFov, 0x004503A0 +bin_import CG_UpdateFov, 0x00450510 SECTION .text global Cbuf_AddText @@ -2144,4 +2147,78 @@ Material_OriginalRemapTechniqueSet: ret SECTION .rodata -oMaterial_OriginalRemapTechniqueSet dd 0x619710 \ No newline at end of file +oMaterial_OriginalRemapTechniqueSet dd 0x619710 + + + +SECTION .text +global SeatTransformForSlot +SeatTransformForSlot: + mov edx, [esp+4] + mov eax, [esp+8] + mov esi, [esp+12] + mov edi, [esp+16] + mov ecx, [esp+20] + push ecx + push eax + call dword [oSeatTransformForSlot] + add esp, 8 + ret + +SECTION .rodata +oSeatTransformForSlot dd 0x44E820 + +SECTION .text +global CG_OffsetFirstPersonView +CG_OffsetFirstPersonView: + mov edi, [esp+4] + call dword [oCG_OffsetFirstPersonView] + ret + +SECTION .rodata +oCG_OffsetFirstPersonView dd 0x00450050 + +SECTION .text +global CG_PerturbCamera +CG_PerturbCamera: + mov edi, [esp+4] + call dword [oCG_PerturbCamera] + ret + +SECTION .rodata +oCG_PerturbCamera dd 0x0044C730 + +SECTION .text +global CG_VehSphereCoordsToPos +CG_VehSphereCoordsToPos: + mov edx, [esp + 16] + mov eax, [esp + 12] + mov ecx, [esp + 8] + mov ebx, [esp + 4] + push eax + push ecx + push ebx + call dword [oCG_VehSphereCoordsToPos] + add esp, 12 + ret + +SECTION .rodata +oCG_VehSphereCoordsToPos dd 0x0044F8D0 + + +SECTION .text +global ThirdPersonViewTrace +ThirdPersonViewTrace: + mov eax, [esp + 16] + mov ecx, [esp + 12] + mov ebx, [esp + 4] + mov esi, [esp + 8] + push eax + push ecx + push ebx + call dword[oThirdPersonViewTrace] + add esp, 12 + ret + +SECTION .rodata +oThirdPersonViewTrace dd 0x0044FA00 diff --git a/src/cg_shared.h b/src/cg_shared.h index c322ed2..acc14e0 100644 --- a/src/cg_shared.h +++ b/src/cg_shared.h @@ -1065,6 +1065,16 @@ qboolean CG_DeployAdditionalServerCommand(); void __cdecl CG_RegisterSounds(); void CG_Vote_f(); cgSafeAngles_t* CG_GetSafeAngles(); +void CG_ApplyViewAnimation(); +float CG_GetViewFov(); +void CG_UpdateFov(float fov); +void CG_UpdateThirdPerson(); +void CalcViewValuesVehicleDriver(); +void CG_VehSphereCoordsToPos(float sphereDist, float sphereYaw, float sphereAlt, float* result); +void ThirdPersonViewTrace(cg_t *cgameGlob, const float *start, const float* end, float* result); +void CG_OffsetFirstPersonView(cg_t *cgameGlob); +void CG_PerturbCamera(cg_t *cgameGlob); +void CG_VehSeatOriginForLocalClient(int localClientNum, float *result); #define cg_paused getcvaradr(0x8C9400) #define cg_cursorHints getcvaradr(0x8C9404) @@ -1081,6 +1091,7 @@ cgSafeAngles_t* CG_GetSafeAngles(); #define cg_overheadNamesGlow getcvaradr(0x8C631C) #define cg_drawFPSLabels getcvaradr(0x8C63AC) #define cg_gameMessageWidth getcvaradr(0x8C6300) +#define cg_thirdPerson getcvaradr(0x748638) #define CG_ALIGN_Y 12 #define CG_ALIGN_TOP 4 diff --git a/src/cg_vehicles_mp.c b/src/cg_vehicles_mp.c new file mode 100644 index 0000000..1485ac7 --- /dev/null +++ b/src/cg_vehicles_mp.c @@ -0,0 +1,13 @@ +#include "cg_shared.h" + +void SeatTransformForSlot(int localClientNum, int vehEntNum, int vehSlotIdx, float *resultOrigin, float *resultAngles); + +void SeatTransformForClientInfo(int localClientNum, clientInfo_t *ci, float *resultOrigin, float *resultAngles) +{ + SeatTransformForSlot(localClientNum, ci->attachedVehEntNum, ci->attachedVehSlotIndex, resultOrigin, resultAngles); +} + +void CG_VehSeatOriginForLocalClient(int localClientNum, float *result) +{ + SeatTransformForClientInfo(localClientNum, &cg.bgs.clientinfo[cg.predictedPlayerState.clientNum], result, 0); +} \ No newline at end of file diff --git a/src/cg_view.c b/src/cg_view.c new file mode 100644 index 0000000..cafd58f --- /dev/null +++ b/src/cg_view.c @@ -0,0 +1,83 @@ +#include "cg_shared.h" + +#define vehDriverViewHeightMax getcvaradr(0x0CB0CC84) +#define vehDriverViewFocusRange getcvaradr(0x008C9F80) +#define vehDriverViewDist getcvaradr(0x008C9F88) + +void CG_UpdateThirdPerson() +{ + clientInfo_t *clInfo; + int killCamEntity; + + cg.renderingThirdPerson = cg_thirdPerson->boolean || cg.nextSnap->ps.pm_type >= 7; + clInfo = &cg.bgs.clientinfo[cg.predictedPlayerState.clientNum]; + + // if(clInfo->attachedVehEntNum != ENTITYNUM_NONE && clInfo->attachedVehSlotIndex == 0/*VEH_RIDESLOT_DRIVER*/) + // { + // cg.renderingThirdPerson = 1; + // } + + killCamEntity = cg.predictedPlayerState.killCamEntity; + if(cg.inKillCam && killCamEntity != ENTITYNUM_NONE && cgEntities[killCamEntity].nextValid) + { + cg.renderingThirdPerson = 1; + } +} + +void CG_CalcFov() +{ + CG_UpdateFov(CG_GetViewFov()); +} + +void CalcViewValuesVehicleDriver() +{ + if(cg_thirdPerson->boolean) + { + float viewHeightMax; + vec3_t origin; + vec3_t fwd; + vec3_t pos; + float v1; + float v2; + + viewHeightMax = vehDriverViewHeightMax->value; + VectorCopy(cg.predictedPlayerState.origin, origin); + origin[2] += 55.0; + + v1 = (cg.predictedPlayerState.viewangles[0] * 0.0027); + v2 = floorf(v1 + 0.5); + + origin[2] = (((viewHeightMax - fabsf((v1 - v2) * 360.0)) / viewHeightMax) * vehDriverViewFocusRange->value) + origin[2]; + + // CG_VehSphereCoordsToPos(vehDriverViewDist->value, cg.predictedPlayerState.viewangles[1], cg.predictedPlayerState.viewangles[0], pos); + AngleVectors(cg.predictedPlayerState.viewangles, fwd, NULL, NULL); + VectorScale(fwd, vehDriverViewDist->value, fwd); + cg.refdef.vieworg[0] = -fwd[0] + origin[0]; + cg.refdef.vieworg[1] = -fwd[1] + origin[1]; + cg.refdef.vieworg[2] = -fwd[2] + origin[2]; + + ThirdPersonViewTrace(&cg, origin, cg.refdef.vieworg, cg.refdef.vieworg); + + pos[0] = origin[0] - cg.refdef.vieworg[0]; + pos[1] = origin[1] - cg.refdef.vieworg[1]; + pos[2] = origin[2] - cg.refdef.vieworg[2]; + + VectorNormalize(pos); + + vectoangles(pos, cg.refdefViewAngles); + AnglesToAxis(cg.refdefViewAngles, cg.refdef.viewaxis); + + CG_CalcFov(); + } + else + { + CG_VehSeatOriginForLocalClient(0, cg.predictedPlayerState.origin); + VectorCopy(cg.predictedPlayerState.origin, cg.refdef.vieworg); + VectorCopy(cg.predictedPlayerState.viewangles, cg.refdefViewAngles); + CG_OffsetFirstPersonView(&cg); + AnglesToAxis(cg.refdefViewAngles, cg.refdef.viewaxis); + CG_ApplyViewAnimation(); + CG_PerturbCamera(&cg); + CG_CalcFov(); + } +} \ No newline at end of file diff --git a/src/sys_patch.c b/src/sys_patch.c index 1b0de54..5cd48a5 100644 --- a/src/sys_patch.c +++ b/src/sys_patch.c @@ -7,6 +7,7 @@ #include "ui_shared.h" #include "sys_patch.h" #include "callbacks.h" +#include "cg_shared.h" #include #include @@ -1187,6 +1188,8 @@ void Patch_Other(){ */ SetCall(0x54F538, Cvar_SetFromStringByNameExternal); SetCall(0x463DEF, CL_FinishMove); + SetJump(0x00451D70, CG_UpdateThirdPerson); + SetJump(0x004509D0, CalcViewValuesVehicleDriver); }