From 3c2e33c978a17333dc5ca942cfd733f34cd3da49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valdir=20da=20Costa=20J=C3=BAnior?= <24408289+JuniorDjjr@users.noreply.github.com> Date: Mon, 9 May 2022 07:42:11 -0300 Subject: [PATCH] v0.4 Lots of fixes... https://www.mixmods.com.br/2022/05/sa-gtafmod/ --- GTAFmod/GTAFmod.cpp | 110 +++++++++++++++----- GTAFmod/GTAFmod.vcxproj | 224 ++++++++++++++++++++-------------------- 2 files changed, 198 insertions(+), 136 deletions(-) diff --git a/GTAFmod/GTAFmod.cpp b/GTAFmod/GTAFmod.cpp index eceea22..0d65bd4 100644 --- a/GTAFmod/GTAFmod.cpp +++ b/GTAFmod/GTAFmod.cpp @@ -9,6 +9,7 @@ #include "Curve.h" #include "CModelInfo.h" #include "CFileLoader.h" +#include "CMenuManager.h" #include #include @@ -86,18 +87,23 @@ class GTAFmod { Events::drawMenuBackgroundEvent += [] { - // Setup texture - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, m_logoTex->raster); + if (FrontEndMenuManager.m_nCurrentMenuPage == eMenuPage::MENUPAGE_AUDIO_SETTINGS) + { + // Setup texture + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, m_logoTex->raster); + + // Background + CRGBA color = CRGBA(255, 255, 255, 255); - // Background - CRGBA color = CRGBA(255, 255, 255, 255); + CSprite2d::SetVertices(CRect(SCREEN_COORD_LEFT(50.0f), + SCREEN_COORD_BOTTOM(30.0f + 100.0f), SCREEN_COORD_LEFT(30.0f + 200.0f), SCREEN_COORD_BOTTOM(60.0f)), color, color, color, color); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); - CSprite2d::SetVertices(CRect(SCREEN_COORD_LEFT(50.0f), - SCREEN_COORD_BOTTOM(30.0f + 100.0f), SCREEN_COORD_LEFT(50.0f + 200.0f), SCREEN_COORD_BOTTOM(30.0f)), color, color, color, color); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); + // Reset texture + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, 0); + } - // Reset texture - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, 0); + MuteAllAudios(); }; } } @@ -136,6 +142,16 @@ class GTAFmod { FMODAudio::CheckError(fmodSystem->update(), "Update Failed"); } } + static void MuteAllAudios() + { + if (currentAudio) + { + currentAudio->m_RpmEventInstance->setVolume(0.0); + currentAudio->m_GearEventInstance->setVolume(0.0); + currentAudio->m_BackFireEventInstance->setVolume(0.0); + } + FMODAudio::CheckError(fmodSystem->update(), "Update Failed"); + } static void _stdcall OnExitVehicle() { CVehicle* veh = FindPlayerVehicle(-1, true); @@ -150,6 +166,14 @@ class GTAFmod { if (lastVehicle) { + eVehicleApperance vehicleClass = (eVehicleApperance)lastVehicle->GetVehicleAppearance(); + if (vehicleClass == eVehicleApperance::VEHICLE_APPEARANCE_BIKE && !iniConfig->m_bEnableOnMotorbikes || + vehicleClass == eVehicleApperance::VEHICLE_APPEARANCE_AUTOMOBILE && !iniConfig->m_bEnableOnCars || + lastVehicle->m_nVehicleFlags.bIsBig && !iniConfig->m_bEnableOnBigVehicles) { + lastVehicle = nullptr; + return; + } + //Try with instance currentAudio = audioInstance[lastVehicle]; //Try with model index @@ -165,13 +189,18 @@ class GTAFmod { //Set to default if (currentAudio == NULL) { - currentAudio = defaultBank; + if (defaultBank->m_bIsLoaded) + { + currentAudio = defaultBank; + } } - if (currentAudio->m_bIsPlaying == false) - { - fRPM = currentAudio->m_Ini->m_fMinRPM; - currentAudio->m_RpmEventInstance->start(); - currentAudio->m_bIsPlaying = true; + if (currentAudio) { + if (currentAudio->m_bIsPlaying == false) + { + fRPM = currentAudio->m_Ini->m_fMinRPM; + currentAudio->m_RpmEventInstance->start(); + currentAudio->m_bIsPlaying = true; + } } } } @@ -185,6 +214,12 @@ class GTAFmod { } static void _stdcall ProcessVehicleEngine(cVehicleParams* params) { + if (!lastVehicle || currentAudio == NULL) { + if (params->m_pVehicle) { + CallMethod<0x4FBB10, CAEVehicleAudioEntity*, cVehicleParams*>(¶ms->m_pVehicle->m_vehicleAudio, params); + } + return; + } if (lastVehicle && !CTimer::m_UserPause && currentAudio) { @@ -193,9 +228,11 @@ class GTAFmod { float velocity = fabs(params->m_fVelocity); params->m_nCurrentGear = lastVehicle->m_nCurrentGear; params->m_bHandbrakeOn = lastVehicle->m_nVehicleFlags.bIsHandbrakeOn; - float currentRatio = (velocity - m_pTransmission->m_aGears[nGear].m_fChangeDownVelocity) + + /*float currentRatio = (velocity - m_pTransmission->m_aGears[nGear].m_fChangeDownVelocity) / (*(float*)&m_pTransmission->m_aGears[nGear].m_fMaxVelocity - - m_pTransmission->m_aGears[nGear].m_fChangeDownVelocity); + - m_pTransmission->m_aGears[nGear].m_fChangeDownVelocity);*/ + float currentRatio = velocity / m_pTransmission->m_aGears[nGear].m_fMaxVelocity; params->m_fVelocityChangingPercentage = currentRatio; @@ -203,19 +240,32 @@ class GTAFmod { params->m_fVelocityChangingPercentage = 0.0; //Calculate target RPM - float targetRpm = currentAudio->m_Ini->m_fMinRPM + ((currentAudio->m_Ini->m_fMaxRPM - 2000 )* params->m_fVelocityChangingPercentage); + float maxRPM = currentAudio->m_Ini->m_fMaxRPM; + if (iniConfig->m_iRPMmode == 1) + { + maxRPM -= 2000; + } + float targetRpm = maxRPM * params->m_fVelocityChangingPercentage; + targetRpm = max(currentAudio->m_Ini->m_fMinRPM, targetRpm); //Set 3D space position CVector camPos = TheCamera.GetPosition(); CVector vehiclePos = lastVehicle->GetPosition(); CVector dirFor; CVector dirUp; + CVector camDirFor; + CVector camDirUp; CVector offsetFor = CVector(0, -1, 0); CVector offsetUp = CVector(0, 0, 1); - CMatrix* matrix = lastVehicle->m_matrix; + + CMatrix* matrix = lastVehicle->GetMatrix(); RwV3dTransformPoint((RwV3d*)&dirFor, (RwV3d*)&offsetFor, (RwMatrix*)matrix); RwV3dTransformPoint((RwV3d*)&dirUp, (RwV3d*)&offsetUp, (RwMatrix*)matrix); + CMatrix* camMatrix = TheCamera.GetMatrix(); + RwV3dTransformPoint((RwV3d*)&camDirFor, (RwV3d*)&offsetFor, (RwMatrix*)camMatrix); + RwV3dTransformPoint((RwV3d*)&camDirUp, (RwV3d*)&offsetUp, (RwMatrix*)camMatrix); + currentAudio->m_Attributes.position.x = vehiclePos.x; currentAudio->m_Attributes.position.y = vehiclePos.y; currentAudio->m_Attributes.position.z = vehiclePos.z; @@ -241,15 +291,20 @@ class GTAFmod { currentAudio->m_ListenerAttributes.position.x = camPos.x; currentAudio->m_ListenerAttributes.position.y = camPos.y; currentAudio->m_ListenerAttributes.position.z = camPos.z; - currentAudio->m_ListenerAttributes.forward = currentAudio->m_Attributes.forward; - currentAudio->m_ListenerAttributes.up = currentAudio->m_Attributes.up; + + currentAudio->m_ListenerAttributes.forward.x = camDirFor.x - camPos.x; + currentAudio->m_ListenerAttributes.forward.y = camDirFor.y - camPos.y; + currentAudio->m_ListenerAttributes.forward.z = camDirFor.z - camPos.z; + currentAudio->m_ListenerAttributes.up.x = camDirUp.x - camPos.x; + currentAudio->m_ListenerAttributes.up.y = camDirUp.y - camPos.y; + currentAudio->m_ListenerAttributes.up.z = camDirUp.z - camPos.z; fmodSystem->setListenerAttributes(0, ¤tAudio->m_ListenerAttributes); //Get gas pedal float gasPedal = abs(lastVehicle->m_fGasPedal); CAutomobile* automobile = reinterpret_cast(lastVehicle); - bool clutch = automobile->m_nWheelsOnGround == 0 || params->m_bHandbrakeOn || lastVehicle->m_fWheelSpinForAudio > 0.6f; + bool clutch = automobile->m_nWheelsOnGround <= 1 || params->m_bHandbrakeOn || lastVehicle->m_fWheelSpinForAudio > 0.6f; //Gear change time if (CTimer::m_snTimeInMilliseconds < (nLastGearChangeTime + (currentAudio->m_Ini->m_fGearTime * 0.5))) @@ -372,14 +427,21 @@ class GTAFmod { Events::initGameEvent.after.Add(LoadConfigs); //Update FMOD on game Process - Events::gameProcessEvent += []() { + Events::processScriptsEvent += []() { if (currentAudio) { - currentAudio->m_RpmEventInstance->setVolume(CTimer::m_UserPause ? 0.0 : iniConfig->m_fMasterVolume); + float volume = iniConfig->m_fMasterVolume * *(float*)0xB5FCCC * 1.7f; + currentAudio->m_RpmEventInstance->setVolume(volume); + currentAudio->m_GearEventInstance->setVolume(volume); + currentAudio->m_BackFireEventInstance->setVolume(volume); } //Update FMOD FMODAudio::CheckError(fmodSystem->update(), "Update Failed"); }; + + Events::onPauseAllSounds += []() { + MuteAllAudios(); + }; } } gTAFmod; diff --git a/GTAFmod/GTAFmod.vcxproj b/GTAFmod/GTAFmod.vcxproj index 53edb07..c598ce4 100644 --- a/GTAFmod/GTAFmod.vcxproj +++ b/GTAFmod/GTAFmod.vcxproj @@ -1,113 +1,113 @@ - - - - - GTASA Release - Win32 - - - GTASA zDebug - Win32 - - - - {B212DDA4-2A8E-45B2-914D-7BEEB31D06B1} - true - Win32Proj - GTAFmod - 10.0 - - - - DynamicLibrary - false - MultiByte - v142 - true - - - DynamicLibrary - true - MultiByte - v142 - - - - - - - - - - - - - $(GTA_SA_DIR)\modloader\GTAFmod - $(ProjectDir).obj\GTASA\Release\ - GTAFmod.SA - .asi - - - $(GTA_SA_DIR)\modloader\GTAFmod - $(ProjectDir).obj\GTASA\Debug\ - GTAFmod.SA_d - .asi - - - - Level3 - MaxSpeed - true - true - false - MultiThreaded - F:\Programas\FMOD Studio API Windows\api\core\inc;$(PLUGIN_SDK_DIR)\plugin_sa\;$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\;$(PLUGIN_SDK_DIR)\shared\;$(PLUGIN_SDK_DIR)\shared\game\;F:\Programas\FMOD Studio API Windows\api\studio\inc;%(AdditionalIncludeDirectories) - _NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NON_CONFORMING_SWPRINTFS;GTASA;GTAGAME_NAME="San Andreas";GTAGAME_ABBR="SA";GTAGAME_ABBRLOW="sa";GTAGAME_PROTAGONISTNAME="CJ";GTAGAME_CITYNAME="San Andreas";PLUGIN_SGV_10US;%(PreprocessorDefinitions) - stdcpplatest - - - true - true - No - UseLinkTimeCodeGeneration - $(PLUGIN_SDK_DIR)\output\lib\;%(AdditionalLibraryDirectories) - plugin.lib;F:\Programas\FMOD Studio API Windows\api\core\lib\x86\fmod_vc.lib;F:\Programas\FMOD Studio API Windows\api\core\lib\x86\fmodL_vc.lib;F:\Programas\FMOD Studio API Windows\api\studio\lib\x86\fmodstudio_vc.lib;%(AdditionalDependencies) - Windows - - - - - Level3 - Disabled - false - MultiThreadedDebug - F:\Programas\FMOD Studio API Windows\api\studio\inc;$(PLUGIN_SDK_DIR)\plugin_sa\;$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\;$(PLUGIN_SDK_DIR)\shared\;$(PLUGIN_SDK_DIR)\shared\game\;F:\Programas\FMOD Studio API Windows\api\core\inc;%(AdditionalIncludeDirectories) - _DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NON_CONFORMING_SWPRINTFS;GTASA;GTAGAME_NAME="San Andreas";GTAGAME_ABBR="SA";GTAGAME_ABBRLOW="sa";GTAGAME_PROTAGONISTNAME="CJ";GTAGAME_CITYNAME="San Andreas";PLUGIN_SGV_10US;%(PreprocessorDefinitions) - stdcpplatest - - - Debug - Default - $(PLUGIN_SDK_DIR)\output\lib\;%(AdditionalLibraryDirectories) - plugin_d.lib;F:\Programas\FMOD Studio API Windows\api\core\lib\x86\fmod_vc.lib;F:\Programas\FMOD Studio API Windows\api\core\lib\x86\fmodL_vc.lib;F:\Programas\FMOD Studio API Windows\api\studio\lib\x86\fmodstudio_vc.lib;%(AdditionalDependencies) - Windows - - - - - - - - - - - - - - - - - - - + + + + + GTASA Release + Win32 + + + GTASA zDebug + Win32 + + + + {B212DDA4-2A8E-45B2-914D-7BEEB31D06B1} + true + Win32Proj + GTAFmod + 10.0 + + + + DynamicLibrary + false + MultiByte + v142 + true + + + DynamicLibrary + true + MultiByte + v142 + + + + + + + + + + + + + G:\GTA SA The Modded Edition\modloader\GTAFmod\ + $(ProjectDir).obj\GTASA\Release\ + GTAFmod.SA + .asi + + + G:\GTA SA The Modded Edition\modloader\GTAFmod\ + $(ProjectDir).obj\GTASA\Debug\ + GTAFmod.SA + .asi + + + + Level3 + MaxSpeed + true + true + false + MultiThreaded + C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\studio\inc;$(PLUGIN_SDK_DIR)\plugin_sa\;$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\;$(PLUGIN_SDK_DIR)\shared\;$(PLUGIN_SDK_DIR)\shared\game\;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc;%(AdditionalIncludeDirectories) + _NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NON_CONFORMING_SWPRINTFS;GTASA;GTAGAME_NAME="San Andreas";GTAGAME_ABBR="SA";GTAGAME_ABBRLOW="sa";GTAGAME_PROTAGONISTNAME="CJ";GTAGAME_CITYNAME="San Andreas";PLUGIN_SGV_10US;%(PreprocessorDefinitions) + stdcpplatest + + + true + true + No + UseLinkTimeCodeGeneration + $(PLUGIN_SDK_DIR)\output\lib\;%(AdditionalLibraryDirectories) + plugin.lib;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x86\fmod_vc.lib;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x86\fmodL_vc.lib;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\studio\lib\x86\fmodstudio_vc.lib;%(AdditionalDependencies) + Windows + + + + + Level3 + Disabled + false + MultiThreadedDebug + C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\studio\inc;$(PLUGIN_SDK_DIR)\plugin_sa\;$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\;$(PLUGIN_SDK_DIR)\shared\;$(PLUGIN_SDK_DIR)\shared\game\;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc;%(AdditionalIncludeDirectories) + _DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NON_CONFORMING_SWPRINTFS;GTASA;GTAGAME_NAME="San Andreas";GTAGAME_ABBR="SA";GTAGAME_ABBRLOW="sa";GTAGAME_PROTAGONISTNAME="CJ";GTAGAME_CITYNAME="San Andreas";PLUGIN_SGV_10US;%(PreprocessorDefinitions) + stdcpplatest + + + Debug + Default + $(PLUGIN_SDK_DIR)\output\lib\;%(AdditionalLibraryDirectories) + plugin_d.lib;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x86\fmod_vc.lib;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x86\fmodL_vc.lib;C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\studio\lib\x86\fmodstudio_vc.lib;%(AdditionalDependencies) + Windows + + + + + + + + + + + + + + + + + + + \ No newline at end of file