From ee4f0ec8f4eaed117667fc90fa124e5e4a125622 Mon Sep 17 00:00:00 2001 From: _AG Date: Mon, 28 Feb 2022 21:43:54 +0100 Subject: [PATCH] Add first III/VC target config, adjust controls, close #74 --- premake5.lua | 105 ++++++++++++++++++++++++++++------------ source/3dMarkersNew.cpp | 5 +- source/CellPhone.cpp | 2 + source/FontNew.cpp | 23 +++++---- source/GPS.cpp | 16 +++++- source/GPS.h | 4 ++ source/GameLogicNew.cpp | 6 +++ source/HudNew.cpp | 3 +- source/PadNew.cpp | 10 ++-- source/VHud.h | 6 +++ 10 files changed, 132 insertions(+), 48 deletions(-) diff --git a/premake5.lua b/premake5.lua index 4aece56..49dcc80 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,65 +1,110 @@ workspace "v-hud" - configurations { "Release", "Debug" } + configurations { "ReleaseSA", "DebugSA", "ReleaseVC", "DebugVC", "ReleaseIII", "DebugIII" } location "project_files" project "v-hud" + kind "SharedLib" + language "C++" + targetdir "output/asi/" + objdir ("output/obj") + targetextension ".asi" + characterset ("MBCS") + linkoptions "/SAFESEH:NO" + buildoptions { "-std:c++latest", "/permissive" } + defines { "_CRT_SECURE_NO_WARNINGS", "_CRT_NON_CONFORMING_SWPRINTFS", "_USE_MATH_DEFINES" } + disablewarnings { "4244", "4800", "4305", "4073", "4838", "4996", "4221", "4430", "26812", "26495", "6031" } + defines { "_DX9_SDK_INSTALLED" } + links { "d3d9", "d3dx9", "bass" } + files { "source/**.*", - "vendor/pugixml/src/*.*", + "vendor/pugixml/src/*.*" } includedirs { - "source/**", + "source/**" } includedirs { "vendor/GInputAPI", "$(PLUGIN_SDK_DIR)/shared/", "$(PLUGIN_SDK_DIR)/shared/game/", - "$(PLUGIN_SDK_DIR)/plugin_sa/", - "$(PLUGIN_SDK_DIR)/plugin_sa/game_sa/", "vendor/pugixml/src", "$(DXSDK_DIR)/Include/", "vendor/ModUtils", "vendor/bass" } + filter { "configurations:*III" } + defines { "GTAIII", "PLUGIN_SGV_10EN" } + includedirs { + "$(PLUGIN_SDK_DIR)/plugin_III/", + "$(PLUGIN_SDK_DIR)/plugin_III/game_III/", + "$(RWD3D9_DIR)/source" + } + targetname "VHudIII" + debugdir "$(GTA_III_DIR)" + debugcommand "$(GTA_III_DIR)/gta3.exe" + postbuildcommands "copy /y \"$(TargetPath)\" \"$(GTA_III_DIR)\\scripts\\VHudIII.asi\"" + libdirs { "$(RWD3D9_DIR)/libs" } + links { "rwd3d9" } + + filter { "configurations:*VC" } + defines { "GTAVC", "PLUGIN_SGV_10EN" } + includedirs { + "$(PLUGIN_SDK_DIR)/plugin_vc/", + "$(PLUGIN_SDK_DIR)/plugin_vc/game_vc/", + "$(RWD3D9_DIR)/source" + } + targetname "VHudVC" + debugdir "$(GTA_VC_DIR)" + debugcommand "$(GTA_VC_DIR)/gta-vc.exe" + postbuildcommands "copy /y \"$(TargetPath)\" \"$(GTA_VC_DIR)\\scripts\\VHudVC.asi\"" + libdirs { "$(RWD3D9_DIR)/libs" } + links { "rwd3d9" } + + filter { "configurations:*SA" } + defines { "GTASA", "PLUGIN_SGV_10US" } + includedirs { + "$(PLUGIN_SDK_DIR)/plugin_sa/", + "$(PLUGIN_SDK_DIR)/plugin_sa/game_sa/" + } + targetname "VHud" + debugdir "$(GTA_SA_DIR)" + debugcommand "$(GTA_SA_DIR)/gta-sa.exe" + postbuildcommands "copy /y \"$(TargetPath)\" \"$(GTA_SA_DIR)\\scripts\\VHud.asi\"" + + filter { } + libdirs { "$(PLUGIN_SDK_DIR)/output/lib/", "$(DXSDK_DIR)/Lib/x86", "vendor/bass" } - kind "SharedLib" - language "C++" - targetdir "output/asi/" - objdir ("output/obj") - targetextension ".asi" - characterset ("MBCS") - linkoptions "/SAFESEH:NO" - buildoptions { "-std:c++latest", "/permissive" } - defines { "_CRT_SECURE_NO_WARNINGS", "_CRT_NON_CONFORMING_SWPRINTFS", "_USE_MATH_DEFINES" } - disablewarnings { "4244", "4800", "4305", "4073", "4838", "4996", "4221", "4430", "26812", "26495", "6031" } - defines { "GTASA", "PLUGIN_SGV_10US", "_DX9_SDK_INSTALLED" } - links { "d3d9", "d3dx9", "bass" } - - filter "configurations:Debug" - links { "plugin_d" } - targetname "VHud" + filter "configurations:Debug*" defines { "DEBUG" } symbols "on" staticruntime "on" - debugdir "$(GTA_SA_DIR)" - debugcommand "$(GTA_SA_DIR)/gta-sa.exe" - postbuildcommands "copy /y \"$(TargetPath)\" \"$(GTA_SA_DIR)\\scripts\\VHud.asi\"" - filter "configurations:Release" - links { "plugin" } - targetname "VHud" + filter "configurations:Release*" defines { "NDEBUG" } symbols "off" optimize "On" staticruntime "on" - debugdir "$(GTA_SA_DIR)" - debugcommand "$(GTA_SA_DIR)/gta-sa.exe" - postbuildcommands "copy /y \"$(TargetPath)\" \"$(GTA_SA_DIR)\\scripts\\VHud.asi\"" + + filter "configurations:ReleaseSA" + links { "plugin" } + filter "configurations:ReleaseVC" + links { "plugin_vc" } + filter "configurations:ReleaseIII" + links { "plugin_iii" } + + filter "configurations:DebugSA" + links { "plugin_d" } + filter "configurations:DebugVC" + links { "plugin_vc_d" } + filter "configurations:DebugIII" + links { "plugin_iii_d" } + + filter { } diff --git a/source/3dMarkersNew.cpp b/source/3dMarkersNew.cpp index ef0949d..955945e 100644 --- a/source/3dMarkersNew.cpp +++ b/source/3dMarkersNew.cpp @@ -1,3 +1,4 @@ +#ifdef GTASA #include "VHud.h" #include "3dMarkersNew.h" #include "TextureMgr.h" @@ -133,4 +134,6 @@ void C3dMarkersNew::Shutdown() { } bInitialised = false; -} \ No newline at end of file +} + +#endif diff --git a/source/CellPhone.cpp b/source/CellPhone.cpp index 8b79cfd..81e84d5 100644 --- a/source/CellPhone.cpp +++ b/source/CellPhone.cpp @@ -1,3 +1,4 @@ +#ifdef GTASA #include "VHud.h" #include "CellPhone.h" #include "HudNew.h" @@ -544,3 +545,4 @@ void CCellPhone::Draw() { DrawPhone(HUD_RIGHT(382.0f), HUD_BOTTOM(offset)); } +#endif diff --git a/source/FontNew.cpp b/source/FontNew.cpp index bb82a22..ade7724 100644 --- a/source/FontNew.cpp +++ b/source/FontNew.cpp @@ -11,6 +11,10 @@ #include "pugixml.hpp" +#ifndef GTASA +#include "rwd3d9.h" +#endif + using namespace plugin; using namespace pugi; @@ -275,7 +279,7 @@ void CFontNew::Clear() { } long CFontNew::AddFont(CFontTT t, LPD3DXFONT* font) { - return D3DXCreateFontA(GetD3DDevice(), t.height, t.width, FW_NORMAL, 0, FALSE, t.charSet, OUT_DEFAULT_PRECIS, t.quality, DEFAULT_PITCH | FF_DONTCARE, t.fontName, font); + return D3DXCreateFontA((LPDIRECT3DDEVICE9)RwD3D9GetCurrentD3DDevice(), t.height, t.width, FW_NORMAL, 0, FALSE, t.charSet, OUT_DEFAULT_PRECIS, t.quality, DEFAULT_PITCH | FF_DONTCARE, t.fontName, font); } void CFontNew::Shutdown() { @@ -939,10 +943,11 @@ float CFontNew::DrawChar(bool print, bool calc, float x, float y, char c, int st IDirect3DVertexShader9* savedVertexShader = NULL; IDirect3DPixelShader9* savedPixelShader = NULL; - GetD3DDevice()->GetRenderState(D3DRS_COLORWRITEENABLE, &savedColorWrite); - GetD3DDevice()->GetVertexDeclaration(&savedVertexDecl); - GetD3DDevice()->GetVertexShader(&savedVertexShader); - GetD3DDevice()->GetPixelShader(&savedPixelShader); + auto device = (LPDIRECT3DDEVICE9)RwD3D9GetCurrentD3DDevice(); + device->GetRenderState(D3DRS_COLORWRITEENABLE, &savedColorWrite); + device->GetVertexDeclaration(&savedVertexDecl); + device->GetVertexShader(&savedVertexShader); + device->GetPixelShader(&savedPixelShader); D3DXMatrixScaling(&S, w, h, 1.0f); m_pSprite->GetTransform(&P); @@ -952,10 +957,10 @@ float CFontNew::DrawChar(bool print, bool calc, float x, float y, char c, int st m_pSprite->End(); m_pSprite->SetTransform(&P); - GetD3DDevice()->SetRenderState(D3DRS_COLORWRITEENABLE, savedColorWrite); - GetD3DDevice()->SetVertexDeclaration(savedVertexDecl); - GetD3DDevice()->SetVertexShader(savedVertexShader); - GetD3DDevice()->SetPixelShader(savedPixelShader); + device->SetRenderState(D3DRS_COLORWRITEENABLE, savedColorWrite); + device->SetVertexDeclaration(savedVertexDecl); + device->SetVertexShader(savedVertexShader); + device->SetPixelShader(savedPixelShader); } if (calc) { diff --git a/source/GPS.cpp b/source/GPS.cpp index ed93a9c..c8979ad 100644 --- a/source/GPS.cpp +++ b/source/GPS.cpp @@ -31,6 +31,7 @@ static LateStaticInit InstallHooks([]() { pathNodes[i] = -1; } +#ifdef GTASA patch::SetFloat(0x450ACD + 1, MAX_SEARCH_RADIUS); patch::SetPointer(0x451782, &pathNodes); patch::SetPointer(0x451904, &pathNodes); @@ -38,6 +39,7 @@ static LateStaticInit InstallHooks([]() { patch::SetPointer(0x451B33, &pathNodes); patch::SetUInt(0x4518F8, MAX_PATH_NODES); patch::SetUInt(0x4519B0, MAX_PATH_NODES - 5); +#endif }); void CGPS::Init() { @@ -150,15 +152,22 @@ void CGPS::DrawLine(CVector2D const&a, CVector2D const&b, float width, CRGBA col } void CGPS::ProcessPath(CLocalization& l) { - if (!FindPlayerPed(0)) +#ifdef GTASA + if (!FindPlayerPed(PLAYER_ID)) return; CVector start = FindPlayerCentreOfWorld(0); CVector end = l.vecDest; +#ifdef GTASA ThePaths.DoPathSearch(0, start, CNodeAddress(), end, l.resultNodes, &l.nNodesCount, MAX_NODE_POINTS, &l.fGPSDistance, 999999.0f, NULL, 999999.0f, false, CNodeAddress(), false, false); - +#else + CVehicle* veh = FindPlayerPed(PLAYER_ID)->m_pVehicle; + if (!veh) + return; + ThePaths.DoPathSearch(0, start, -1, end, l.resultNodes, &l.nNodesCount, MAX_NODE_POINTS, veh, NULL, 999999.0f, -1); +#endif if (l.nNodesCount > 0) { for (short i = 0; i < l.nNodesCount; i++) { CVector nodePosn = ThePaths.GetPathNode(l.resultNodes[i])->GetNodeCoors(); @@ -184,9 +193,11 @@ void CGPS::ProcessPath(CLocalization& l) { DrawLine(l.nodePoints[i], l.nodePoints[i + 1], w, col); } } +#endif } void CGPS::DrawPathLine() { +#ifdef GTASA if (!MenuNew.Settings.gpsRoute) return; @@ -249,6 +260,7 @@ void CGPS::DrawPathLine() { } } } +#endif } char CGPS::GetPathDirection(CVector start, CVector plr, CVector end) { diff --git a/source/GPS.h b/source/GPS.h index 9568714..0603bd9 100644 --- a/source/GPS.h +++ b/source/GPS.h @@ -21,7 +21,11 @@ struct CLocalization { float fGPSDistance; char nPathDirection; short nNodesCount; +#ifdef GTASA CNodeAddress resultNodes[MAX_NODE_POINTS]; +#else + CPathNode* resultNodes[MAX_NODE_POINTS]; +#endif CVector2D nodePoints[MAX_NODE_POINTS]; unsigned int pathColor; diff --git a/source/GameLogicNew.cpp b/source/GameLogicNew.cpp index 560494f..388cda2 100644 --- a/source/GameLogicNew.cpp +++ b/source/GameLogicNew.cpp @@ -9,7 +9,13 @@ using namespace plugin; CGameLogicNew GameLogicNew; static LateStaticInit InstallHooks([]() { +#ifdef GTASA CdeclEvent, PRIORITY_BEFORE, ArgPickNone, void()> onResurrection; +#elif GTAVC + CdeclEvent, PRIORITY_BEFORE, ArgPickNone, void()> onResurrection; +#elif GTA3 + CdeclEvent, PRIORITY_BEFORE, ArgPickNone, void()> onResurrection; +#endif onResurrection += [] { CHudNew::ReInit(); diff --git a/source/HudNew.cpp b/source/HudNew.cpp index e30932f..c7eeb6a 100644 --- a/source/HudNew.cpp +++ b/source/HudNew.cpp @@ -122,7 +122,8 @@ static LateStaticInit InstallHooks([]() { }; patch::RedirectJump(0x705331, (void*)0x7053AF); - patch::PutRetn(0x742CF0); + patch::Nop(0x7434F2, 5); + patch::Nop(0x7433A3, 5); // CMessages::InsertPlayerControlKeysInString diff --git a/source/PadNew.cpp b/source/PadNew.cpp index bad3d3f..83f7168 100644 --- a/source/PadNew.cpp +++ b/source/PadNew.cpp @@ -42,7 +42,7 @@ CControls Controls[NUM_CONTROL_ACTIONS] = { { "PED_ANSWER_PHONE", KEY(rsTAB), GAMEPAD_LEFTSHOULDER1, GAMEPAD_LEFTSHOULDER1 }, { "SNEAK_ABOUT", KEY(rsLCTRL), GAMEPAD_NONE, GAMEPAD_NONE }, { "VEHICLE_FIREWEAPON", MOUSE(rsMOUSELEFTBUTTON), GAMEPAD_CIRCLE, GAMEPAD_CIRCLE }, - { "VEHICLE_FIREWEAPON_ALT", KEY(rsLCTRL), GAMEPAD_LEFTSHOULDER1, GAMEPAD_CROSS }, + { "VEHICLE_FIREWEAPON_ALT", KEY(rsRCTRL), GAMEPAD_LEFTSHOULDER1, GAMEPAD_CROSS }, { "VEHICLE_STEERLEFT", KEY('A'), GAMEPAD_THUMBLXL, GAMEPAD_THUMBLXL }, { "VEHICLE_STEERRIGHT", KEY('D'), GAMEPAD_THUMBLXR, GAMEPAD_THUMBLXR }, { "VEHICLE_STEERUP", KEY(rsPGUP), GAMEPAD_THUMBLYU }, @@ -61,10 +61,10 @@ CControls Controls[NUM_CONTROL_ACTIONS] = { { "VEHICLE_LOOKRIGHT", KEY('E'), GAMEPAD_THUMBRXR, GAMEPAD_THUMBRXR }, { "VEHICLE_LOOKBEHIND", KEY('C'), GAMEPAD_THUMBR, GAMEPAD_THUMBR, }, { "VEHICLE_MOUSELOOK", KEY(rsNULL), GAMEPAD_NONE, GAMEPAD_NONE }, - { "VEHICLE_TURRETLEFT", KEY(rsPADLEFT), GAMEPAD_THUMBRXL, GAMEPAD_THUMBRXL }, - { "VEHICLE_TURRETRIGHT", KEY(rsPADRIGHT), GAMEPAD_THUMBRXR, GAMEPAD_THUMBRXR }, - { "VEHICLE_TURRETUP", KEY(rsPADUP), GAMEPAD_THUMBRYU, GAMEPAD_THUMBRYU }, - { "VEHICLE_TURRETDOWN", KEY(rsPADDOWN), GAMEPAD_THUMBRYD, GAMEPAD_THUMBRYD }, + { "VEHICLE_TURRETLEFT", KEY('T'), GAMEPAD_THUMBRXL, GAMEPAD_THUMBRXL}, + { "VEHICLE_TURRETRIGHT", KEY('G'), GAMEPAD_THUMBRXR, GAMEPAD_THUMBRXR}, + { "VEHICLE_TURRETUP", KEY('R'), GAMEPAD_THUMBRYU, GAMEPAD_THUMBRYU }, + { "VEHICLE_TURRETDOWN", KEY('Y'), GAMEPAD_THUMBRYD, GAMEPAD_THUMBRYD }, { "PED_CYCLE_TARGET_LEFT", KEY('Q'), GAMEPAD_LEFTSHOULDER2, GAMEPAD_LEFTSHOULDER1 }, { "PED_CYCLE_TARGET_RIGHT", KEY('E'), GAMEPAD_RIGHTSHOULDER2, GAMEPAD_RIGHTSHOULDER1 }, { "PED_CENTER_CAMERA_BEHIND_PLAYER", KEY(rsNULL), GAMEPAD_LEFTSHOULDER1, GAMEPAD_RIGHTSHOULDER1 }, diff --git a/source/VHud.h b/source/VHud.h index 622db1e..562a657 100644 --- a/source/VHud.h +++ b/source/VHud.h @@ -5,6 +5,12 @@ #include "LateStaticInit.h" +#ifdef GTASA +#define PLAYER_ID 0 +#else +#define PLAYER_ID +#endif + enum eUGEvents { UG_EVENT_BEFORE_RENDER2DSTUFF, UG_EVENT_AFTER_RENDER2DSTUFF,