Skip to content

Commit

Permalink
Include project files, merge LCS branch into master, add rotating LCS…
Browse files Browse the repository at this point in the history
… firetruck turret
  • Loading branch information
erorcun committed Nov 3, 2019
1 parent f35d3d3 commit e5ae177
Show file tree
Hide file tree
Showing 12 changed files with 783 additions and 21 deletions.
55 changes: 55 additions & 0 deletions SACarCam.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29215.179
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SACarCam", "SACarCam\SACarCam.vcxproj", "{F06BC71F-1298-453C-83EA-D29C909403C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
DebugLCS|x64 = DebugLCS|x64
DebugLCS|x86 = DebugLCS|x86
DebugVC|x64 = DebugVC|x64
DebugVC|x86 = DebugVC|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
ReleaseLCS|x64 = ReleaseLCS|x64
ReleaseLCS|x86 = ReleaseLCS|x86
ReleaseVC|x64 = ReleaseVC|x64
ReleaseVC|x86 = ReleaseVC|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F06BC71F-1298-453C-83EA-D29C909403C5}.Debug|x64.ActiveCfg = Debug|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.Debug|x64.Build.0 = Debug|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.Debug|x86.ActiveCfg = Debug|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.Debug|x86.Build.0 = Debug|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.DebugLCS|x64.ActiveCfg = DebugLCS|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.DebugLCS|x64.Build.0 = DebugLCS|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.DebugLCS|x86.ActiveCfg = DebugLCS|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.DebugLCS|x86.Build.0 = DebugLCS|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.DebugVC|x64.ActiveCfg = DebugVC|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.DebugVC|x64.Build.0 = DebugVC|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.DebugVC|x86.ActiveCfg = DebugVC|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.DebugVC|x86.Build.0 = DebugVC|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.Release|x64.ActiveCfg = Release|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.Release|x64.Build.0 = Release|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.Release|x86.ActiveCfg = Release|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.Release|x86.Build.0 = Release|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.ReleaseLCS|x64.ActiveCfg = ReleaseLCS|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.ReleaseLCS|x64.Build.0 = ReleaseLCS|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.ReleaseLCS|x86.ActiveCfg = ReleaseLCS|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.ReleaseLCS|x86.Build.0 = ReleaseLCS|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.ReleaseVC|x64.ActiveCfg = ReleaseVC|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.ReleaseVC|x64.Build.0 = ReleaseVC|x64
{F06BC71F-1298-453C-83EA-D29C909403C5}.ReleaseVC|x86.ActiveCfg = ReleaseVC|Win32
{F06BC71F-1298-453C-83EA-D29C909403C5}.ReleaseVC|x86.Build.0 = ReleaseVC|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0868CAA7-5624-4C86-A01C-D155850F99A5}
EndGlobalSection
EndGlobal
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions GTA.h → SACarCam/GTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,35 @@ class CMatrix
RwMatrix* m_attachment;
bool m_hasRwMatrix; // are we the owner?

CMatrix(void) {
m_attachment = nil;
m_hasRwMatrix = false;
}
void SetRotateZOnly(float angle) {
float c = cosf(angle);
float s = sinf(angle);

m_matrix.right.x = c;
m_matrix.right.y = s;
m_matrix.right.z = 0.0f;

m_matrix.up.x = -s;
m_matrix.up.y = c;
m_matrix.up.z = 0.0f;

m_matrix.at.x = 0.0f;
m_matrix.at.y = 0.0f;
m_matrix.at.z = 1.0f;
}
void SetRotateZ(float angle) {
SetRotateZOnly(angle);
m_matrix.pos.x = 0.0f;
m_matrix.pos.y = 0.0f;
m_matrix.pos.z = 0.0f;
}
void Attach(RwMatrix* matrix, bool owner = false);
void UpdateRW(void);

CVector& GetPosition(void) { return *(CVector*)& m_matrix.pos; }
CVector& GetRight(void) { return *(CVector*)& m_matrix.right; }
CVector& GetForward(void) { return *(CVector*)& m_matrix.up; }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
144 changes: 123 additions & 21 deletions SACarCam.cpp → SACarCam/SACarCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
#include "ModuleList.hpp"
#include "GInputAPI.h"

// Uncomment to compile a special build for RE:LCS (based on VC). Otherwise it will be III/VC build.
// #define RELCS

HMODULE dllModule, hDummyHandle;
int gtaversion = -1;

#define MI_III_YARDIE 135
#define MI_III_RCBANDIT 131
#define MI_III_DODO 126
#define MI_III_RHINO 122
#define MI_III_DODO 126
#define MI_III_FIRETRUCK 97

#define MI_VC_VOODOO 142
Expand All @@ -24,9 +27,29 @@ int gtaversion = -1;
#define MI_VC_RCRAIDER 195
#define MI_VC_RCGOBLIN 231

#define Tank (isIII() ? MI_III_RHINO : MI_VC_RHINO)
#define FireTruk (isIII() ? MI_III_FIRETRUCK : MI_VC_FIRETRUCK)
#define CarWithHydraulics (isIII() ? MI_III_YARDIE : MI_VC_VOODOO)
#define MI_RELCS_FIRETRUCK 138
#define MI_RELCS_RHINO 162
#define MI_RELCS_DODO 164
#define MI_RELCS_RCBANDIT 169 // original LCS didn't use this though, RC vehicles have same camera distance as normal veh - Ryadica926
#define MI_RELCS_YARDIE 173
#define MI_RELCS_RCGOBLIN 211 // same as rc bandit
#define MI_RELCS_RCRAIDER 212 // same as above

#ifndef RELCS
#define Tank (isIII() ? MI_III_RHINO : MI_VC_RHINO)
#define FireTruk (isIII() ? MI_III_FIRETRUCK : MI_VC_FIRETRUCK)
#define CarWithHydraulics (isIII() ? MI_III_YARDIE : MI_VC_VOODOO)

// These are being used only if isVC() is true
#define RcGoblin MI_VC_RCGOBLIN
#define RcRaider MI_VC_RCRAIDER
#else
#define Tank MI_RELCS_RHINO
#define FireTruk MI_RELCS_FIRETRUCK
#define CarWithHydraulics MI_RELCS_YARDIE
#define RcGoblin MI_RELCS_RCGOBLIN
#define RcRaider MI_RELCS_RCRAIDER
#endif

#define DefaultFOV 70.0f

Expand All @@ -36,11 +59,20 @@ GINPUT_PAD_SETTINGS padSettings = {};

// Car zoom modes per veh. types doesn't exist in III, so we will emulate it :)
// We're just injecting the values for VC
float CarZoomModes[] = {
-1.8f, -0.2f, -3.2f, 0.05f, -3.21f, // near
0.2f, 1.4f, 0.65f, 1.9f, 5.69f, // mid
5.2f, 6.0f, 15.9f, 15.9f, 14.2f // far
};

#ifdef RELCS
float CarZoomModes[] = {
-2.0f, -0.2f, -3.2f, 0.05f, -3.20f, // near
1.0f, 2.2f, 1.65f, 2.9f, 5.68f, // mid
5.0f, 6.0f, 15.9f, 15.9f, 14.1f // far
};
#else
float CarZoomModes[] = {
-1.8f, -0.2f, -3.2f, 0.05f, -3.21f, // near
0.2f, 1.4f, 0.65f, 1.9f, 5.69f, // mid
5.2f, 6.0f, 15.9f, 15.9f, 14.2f // far
};
#endif

/*
// Original SA array, but doesn't give same results as SA (Due to collision bounding box sizes?)
Expand Down Expand Up @@ -84,12 +116,20 @@ WRAPPER void cDMAudio::PlayOneShot(int32 audioEntity, uint16 oneShot, float volu

CBaseModelInfo** CModelInfo::ms_modelInfoPtrs = AddressByVersion<CBaseModelInfo **>(0x83D408, 0, 0, 0x92D4C8, 0, 0);

addr attachAddress = AddressByVersion<addr>(0x4B8DD0, 0, 0, 0x4DFA40, 0, 0);
addr updateRwAddress = AddressByVersion<addr>(0x4B8EC0, 0, 0, 0x4DF8F0, 0, 0);
WRAPPER void CMatrix::Attach(RwMatrix* matrix, bool owner) { EAXJMP(attachAddress); }
WRAPPER void CMatrix::UpdateRW(void) { EAXJMP(updateRwAddress); }

// Actually static member of CVehicle
bool &m_bDisableMouseSteering = *AddressByVersion<bool*>(0x60252C, 0, 0, 0x69C610, 0, 0);

uint32 &m_snTimeInMilliseconds = *AddressByVersion<uint32*>(0x885B48, 0, 0, 0x974B2C, 0, 0);
float &ms_fTimeStep = *AddressByVersion<float*>(0x8E2CB4, 0, 0, 0x975424, 0, 0);

#define RwFrameGetMatrix(frame) (RwMatrix*)((addr)frame + 0x10)
#define GetVehicleComponent(car, comp) *(void**)((addr)car + (isIII() ? 0x37C : 0x394) + comp*4) // In CAutomobile. normally returns RwFrame*

#define GetDisablePlayerControls(pad) *((uint8*)((addr)pad + (isIII() ? 0xDF : 0xF0)))
#define GetHandlingFlags(veh) *((uint32*)((addr)veh->pHandling + (isIII() ? 0xC8 : 0xCC)))
#define GetWheelsOnGround(veh) *((uint8*)((addr)veh + (isIII() ? 0x591 : 0x5C4))) // In CAutomobile
Expand Down Expand Up @@ -236,11 +276,17 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
uint8 nextDirectionIsForward = !(pad->GetLookBehindForCar() || pad->GetLookBehindForPed() || pad->GetLookLeft() || pad->GetLookRight()) &&
cam->DirectionWasLooking == LOOKING_FORWARD;

#ifdef RELCS
if (car->m_modelIndex == MI_RELCS_FIRETRUCK) {
camSetArrPos = 7;
} else if (isVC() && (car->m_modelIndex == MI_RELCS_RCBANDIT)) {
#else
if ((isIII() && car->m_modelIndex == MI_III_RCBANDIT) ||
(isVC() && (car->m_modelIndex == MI_VC_RCBARON || car->m_modelIndex == MI_VC_RCBANDIT))) {
#endif
camSetArrPos = 5;
}
else if (isVC() && (car->m_modelIndex == MI_VC_RCRAIDER || car->m_modelIndex == MI_VC_RCGOBLIN)) {
else if (isVC() && (car->m_modelIndex == RcRaider || car->m_modelIndex == RcGoblin)) {
camSetArrPos = 6;
}
else if (car->IsBoat()) {
Expand All @@ -256,6 +302,19 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
camSetArrPos = 2;
}

#ifdef RELCS
// LCS one but index 1(firetruck) moved to last
float CARCAM_SET[][15] = {
{1.3f, 1.0f, 0.4f, 10.0f, 15.0f, 0.5f, 1.0f, 1.0f, 0.85f, 0.2f, 0.075f, 0.05f, 0.8f, 0.7854f, 1.5533f}, // cars
{1.1f, 1.0f, 0.1f, 10.0f, 11.0f, 0.5f, 1.0f, 1.0f, 0.85f, 0.2f, 0.075f, 0.05f, 0.75f, 0.7854f, 1.5533f}, // bike
{1.1f, 1.0f, 0.2f, 10.0f, 15.0f, 0.05f, 0.05f, 0.0f, 0.9f, 0.05f, 0.01f, 0.05f, 1.0f, 0.17453294f, 1.2217305f}, // heli (SA values)
{1.1f, 3.5f, 0.2f, 10.0f, 25.0f, 0.5f, 1.0f, 1.0f, 0.75f, 0.1f, 0.005f, 0.2f, 1.0f, 1.5533431f, 1.5533431f}, // plane (SA values)
{0.9f, 1.0f, 0.1f, 10.0f, 15.0f, 0.5f, 1.0f, 0.0f, 0.9f, 0.05f, 0.005f, 0.05f, 1.0f, -0.2f, 1.2217305f}, // boat
{1.1f, 1.0f, 0.2f, 10.0f, 5.0f, 0.5f, 1.0f, 1.0f, 0.75f, 0.1f, 0.005f, 0.2f, 1.0f, 0.7854f, 1.5533f}, // rc cars
{1.1f, 1.0f, 0.2f, 10.0f, 5.0f, 0.5f, 1.0f, 1.0f, 0.75f, 0.1f, 0.005f, 0.2f, 1.0f, 0.34906587f, 1.2217305f}, // rc heli/planes
{1.3f, 1.0f, 0.4f, 10.0f, 15.0f, 0.5f, 1.0f, 1.0f, 0.85f, 0.2f, 0.075f, 0.05f, 0.8f, -0.18f, 0.7f}, // firetruck...
};
#else
float CARCAM_SET[][15] = {
{1.3f, 1.0f, 0.4f, 10.0f, 15.0f, 0.5f, 1.0f, 1.0f, 0.85f, 0.2f, 0.075f, 0.05f, 0.8f, 0.785398f, 1.5533431f},
{1.1f, 1.0f, 0.1f, 10.0f, 11.0f, 0.5f, 1.0f, 1.0f, 0.85f, 0.2f, 0.075f, 0.05f, 0.75f, 0.78539819f, 1.5533431f},
Expand All @@ -265,12 +324,18 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
{1.1f, 1.0f, 0.2f, 10.0f, 5.0f, 0.5f, 1.0f, 1.0f, 0.75f, 0.1f, 0.005f, 0.2f, 1.0f, 0.78539819f, 1.5533431f}, // rc cars
{1.1f, 1.0f, 0.2f, 10.0f, 5.0f, 0.5f, 1.0f, 1.0f, 0.75f, 0.1f, 0.005f, 0.2f, 1.0f, 0.34906587f, 1.2217305f} // rc heli/planes
};
#endif

#ifdef RELCS
float ZmOneAlphaOffset[] = { 0.12f, 0.08f, 0.15f, 0.08f, 0.08f };
float ZmTwoAlphaOffset[] = { 0.1f, 0.08f, 0.3f, 0.08f, 0.08f };
float ZmThreeAlphaOffset[] = { 0.065f, 0.05f, 0.15f, 0.06f, 0.08f };
#else
float ZmOneAlphaOffset[] = { 0.08f, 0.08f, 0.15f, 0.08f, 0.08f };
float ZmTwoAlphaOffset[] = { 0.07f, 0.08f, 0.3f, 0.08f, 0.08f };
float ZmThreeAlphaOffset[] = { 0.055f, 0.05f, 0.15f, 0.06f, 0.08f };

// RC Heli/planes use same alpha values with heli/planes
#endif
// RC Heli/planes use same alpha values with heli/planes (LCS firetruck will fallback to 0)
uint8 alphaArrPos = (camSetArrPos > 4 ? (isPlane ? 3 : (isHeli ? 2 : 0)) : camSetArrPos);
float zoomModeAlphaOffset = 0.0f;

Expand Down Expand Up @@ -345,13 +410,14 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
// Taken from VC CCam::Cam_On_A_String_Unobscured. If we don't this, we will end up seeing the world from the inside of RC Goblin/Raider.
// I couldn't find where SA does that. It's possible that they've increased the size of these veh.'s collision bounding box.
if (isVC()) {
if (car->m_modelIndex != MI_VC_RCRAIDER && car->m_modelIndex != MI_VC_RCGOBLIN) {
if (car->m_modelIndex != RcRaider && car->m_modelIndex != RcGoblin) {
#ifndef RELCS
if (car->m_modelIndex == MI_VC_RCBARON)
newDistance += 9.5f;
#endif
} else
newDistance += 6.0f;
}

float minDistForThisCar = approxCarLength * CARCAM_SET[camSetArrPos][3];

if (!isHeli || car->m_status == STATUS_PLAYER_REMOTE) {
Expand All @@ -370,11 +436,15 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
}

// SA sets CurrentTweakAngle to this value for RCGOBLIN. VC also adds 0.2f to it
if (isVC() && car->m_modelIndex == MI_VC_RCGOBLIN)
if (isVC() && car->m_modelIndex == RcGoblin)
zoomModeAlphaOffset += 0.178997f;

float minDistForVehType = CARCAM_SET[camSetArrPos][4];
#ifdef RELCS
if (TheCamera->CarZoomIndicator == 1.0f && (camSetArrPos < 2 || camSetArrPos == 7)) {
#else
if (TheCamera->CarZoomIndicator == 1.0f && (camSetArrPos < 2)) {
#endif
minDistForVehType = minDistForVehType * 0.65f;
}

Expand Down Expand Up @@ -603,7 +673,11 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
xMovement = 0.0;
}

#ifdef RELCS
if (camSetArrPos == 0 || camSetArrPos == 7) {
#else
if (camSetArrPos == 0) {
#endif
// This is not working on cars as SA
// Because III/VC doesn't have any buttons tied to LeftStick if you're not in Classic Configuration, using Dodo or using GInput/Pad, so :shrug:
if (fabsf(pad->GetSteeringUpDown()) > 120.0f) {
Expand Down Expand Up @@ -718,7 +792,11 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
cam->Beta += TWOPI;
*/

#ifdef RELCS
if ((camSetArrPos <= 1 || camSetArrPos == 7) && targetAlpha < cam->Alpha && carPosChange >= newDistance) {
#else
if (camSetArrPos <= 1 && targetAlpha < cam->Alpha && carPosChange >= newDistance) {
#endif
if (isCar && GetWheelsOnGround(car) > 1 ||
isBike && GetWheelsOnGroundBike(car) > 1)
alphaSpeedFromStickY += (targetAlpha - cam->Alpha) * 0.075f;
Expand Down Expand Up @@ -847,8 +925,7 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
RwCameraSetNearClipPlane(RwCamera, lessClip);
else
RwCameraSetNearClipPlane(RwCamera, 0.9f);
}
else {
} else {
obstacleTargetDist = (TargetCoors - foundCol.point).Magnitude();
cam->Source = foundCol.point;
if (obstacleTargetDist < 1.2f)
Expand Down Expand Up @@ -899,12 +976,14 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
cam->Source.z = 1.0f;

// Obviously some specific place in LC
if (isIII()) {
#ifndef RELCS
if (isIII())
#endif
if (cam->Source.x > 11.0f && cam->Source.x < 91.0f) {
if (cam->Source.y > -680.0f && cam->Source.y < -600.0f && cam->Source.z < 24.4f)
cam->Source.z = 24.4f;
}
}

// CCam::FixSourceAboveWaterLevel
if (CameraTarget.z >= -2.0f) {
float level = -6000.0;
Expand Down Expand Up @@ -954,7 +1033,7 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
*GetDoomAnglePtrLR(car) -= TWOPI;
}

// Because tank turret has no Y movement
// Because firetruk turret also has Y movement
if (car->m_modelIndex == FireTruk) {
float alphaToFace = atan2f(hi.z, hi.Magnitude2D()) + 0.2617994f;
float neededAlphaTurn = alphaToFace - *GetDoomAnglePtrUD(car);
Expand All @@ -979,6 +1058,21 @@ Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CamCl
} else {
*GetDoomAnglePtrUD(car) = turretMinY;
}

#ifdef RELCS
// Actual rotating turret for RE:LCS
// CAR_BUMP_REAR (firetruck turret lol) = 8
if (GetVehicleComponent(car, 8)) {
CMatrix mat;
CVector pos;

mat.Attach(RwFrameGetMatrix(GetVehicleComponent(car, 8)));
pos = mat.GetPosition();
mat.SetRotateZ(-(*GetDoomAnglePtrLR(car)));
mat.GetPosition() = pos;
mat.UpdateRW();
}
#endif
}
}

Expand Down Expand Up @@ -1085,6 +1179,15 @@ DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
if (reason == DLL_PROCESS_ATTACH) {
dllModule = hInst;

/* Taken from SkyGFX
if (GetAsyncKeyState(VK_F8) & 0x8000) {
AllocConsole();
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
*/

GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)& DllMain, &hDummyHandle);

// III
Expand All @@ -1097,7 +1200,6 @@ DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
InjectHook(0x52260E, &CPad::FakeCarGunUpDown, PATCH_NOTHING);
InjectHook(0x53D628, &CPad::FakeCarGunLeftRight, PATCH_NOTHING);
InjectHook(0x5225D2, &CPad::FakeCarGunLeftRight, PATCH_NOTHING);

// VC
} else if (*(DWORD*)0x667BF5 == 0xB85548EC) {

Expand Down
Loading

0 comments on commit e5ae177

Please sign in to comment.