Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed vehicle driver camera #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiledll_common.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
79 changes: 78 additions & 1 deletion src/callbacks.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2144,4 +2147,78 @@ Material_OriginalRemapTechniqueSet:
ret

SECTION .rodata
oMaterial_OriginalRemapTechniqueSet dd 0x619710
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
11 changes: 11 additions & 0 deletions src/cg_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/cg_vehicles_mp.c
Original file line number Diff line number Diff line change
@@ -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);
}
83 changes: 83 additions & 0 deletions src/cg_view.c
Original file line number Diff line number Diff line change
@@ -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();
}
}
3 changes: 3 additions & 0 deletions src/sys_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ui_shared.h"
#include "sys_patch.h"
#include "callbacks.h"
#include "cg_shared.h"

#include <windows.h>
#include <stdlib.h>
Expand Down Expand Up @@ -1187,6 +1188,8 @@ void Patch_Other(){
*/
SetCall(0x54F538, Cvar_SetFromStringByNameExternal);
SetCall(0x463DEF, CL_FinishMove);
SetJump(0x00451D70, CG_UpdateThirdPerson);
SetJump(0x004509D0, CalcViewValuesVehicleDriver);
}


Expand Down