From ede1d92f0be1abe3eaf605ef891142c2902a4930 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 28 Sep 2017 21:13:14 +0200 Subject: [PATCH] NVC shader removed --- SilentPatch/nvc.fx | 36 -- SilentPatchSA/Shaders.rc | 4 - SilentPatchSA/SilentPatchSA.cpp | 428 -------------------- SilentPatchSA/SilentPatchSA.vcxproj | 24 -- SilentPatchSA/SilentPatchSA.vcxproj.filters | 11 - 5 files changed, 503 deletions(-) delete mode 100644 SilentPatch/nvc.fx delete mode 100644 SilentPatchSA/Shaders.rc diff --git a/SilentPatch/nvc.fx b/SilentPatch/nvc.fx deleted file mode 100644 index 713d6e0..0000000 --- a/SilentPatch/nvc.fx +++ /dev/null @@ -1,36 +0,0 @@ -struct VS_INPUT -{ - float4 Position : POSITION; - float2 Texture : TEXCOORD0; - float4 NightColor : COLOR0; - float4 DayColor : COLOR1; -}; - -struct VS_OUTPUT -{ - float4 Position : POSITION; - float2 Texture : TEXCOORD0; - float4 Color : COLOR0; -}; - -float2 fEnvVars : register(c0); -float4 AmbientLight : register(c1); -float4x4 worldViewProj : register(c2); -//float4x4 world : register(c2); -//float4x4 view : register(c6); -//float4x4 proj : register(c10); - -VS_OUTPUT NVC_vertex_shader( in VS_INPUT In ) -{ - VS_OUTPUT Out; - - //Out.Position = mul(proj, mul(view, mul(world, In.Position))); - Out.Position = mul(worldViewProj, In.Position); - Out.Texture = In.Texture; - - Out.Color.rgb = lerp(In.DayColor, In.NightColor, fEnvVars[0]).rgb + AmbientLight.rgb; - Out.Color.a = In.NightColor.a * fEnvVars[1]; - Out.Color = saturate(Out.Color); - - return Out; -} \ No newline at end of file diff --git a/SilentPatchSA/Shaders.rc b/SilentPatchSA/Shaders.rc deleted file mode 100644 index f308f40..0000000 --- a/SilentPatchSA/Shaders.rc +++ /dev/null @@ -1,4 +0,0 @@ -#include "resource.h" - -IDR_NVCSHADER RCDATA "..\\SilentPatch\\nvc.cso" -IDR_LUNAR64 RCDATA "lunar64.png" diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 546c084..2a4e388 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -91,36 +91,6 @@ static void* varRwMatrixRotate = AddressByVersion(0x7F1FD0, 0x7F28D0, 0x8 WRAPPER RwMatrix* RwMatrixRotate(RwMatrix* matrix, const RwV3d* axis, RwReal angle, RwOpCombineType combineOp) { WRAPARG(matrix); WRAPARG(axis); WRAPARG(angle); WRAPARG(combineOp); VARJMP(varRwMatrixRotate); } static void* varRwD3D9SetRenderState = AddressByVersion(0x7FC2D0, 0x7FCBD0, 0x836290); WRAPPER void RwD3D9SetRenderState(RwUInt32 state, RwUInt32 value) { WRAPARG(state); WRAPARG(value); VARJMP(varRwD3D9SetRenderState); } -static void* varRwD3D9GetTransform = AddressByVersion(0x7FA4F0, 0x7FADF0, 0x8344B0); -WRAPPER void _RwD3D9GetTransform(RwUInt32 state, void* matrix) { VARJMP(varRwD3D9GetTransform); } - -static LPDIRECT3DDEVICE9& _RwD3DDevice = **AddressByVersion(0x7FAC64 + 1, 0x7FB564 + 1, 0x34C24 + 1); -static void*& _rwD3D9LastVertexShaderUsed = **AddressByVersion(0x7FAC7C + 2, 0x7FB57C + 2, 0x834C3C + 2); - -void _rwD3D9SetVertexShaderConstant(RwUInt32 registerAddress, const void *constantData, RwUInt32 constantCount) -{ - _RwD3DDevice->SetVertexShaderConstantF( registerAddress, (const float*)constantData, constantCount ); -} - -RwBool RwD3D9CreateVertexShader(const RwUInt32 *function, void **shader) -{ - HRESULT result = _RwD3DDevice->CreateVertexShader( (const DWORD*)function, (LPDIRECT3DVERTEXSHADER9*)shader ); - if ( SUCCEEDED(result) ) - { - _rwD3D9LastVertexShaderUsed = (void*)-1; - return TRUE; - } - return FALSE; -} - -void _rwD3D9SetVertexShader(void *shader) -{ - if ( _rwD3D9LastVertexShaderUsed != shader ) - { - HRESULT result = _RwD3DDevice->SetVertexShader( (LPDIRECT3DVERTEXSHADER9)shader ); - _rwD3D9LastVertexShaderUsed = SUCCEEDED(result) ? shader : (void*)-1; - } -} RwCamera* RwCameraBeginUpdate(RwCamera* camera) { @@ -320,17 +290,13 @@ static void (__thiscall* SetVolume)(void*,float); static BOOL (*IsAlreadyRunning)(); static void (*TheScriptsLoad)(); static void (*WipeLocalVariableMemoryForMissionScript)(); -static bool (*InitialiseRenderWare)(); -static void (*ShutdownRenderWare)(); static void (*DoSunAndMoon)(); -static void (*D3D9RenderPreLit)(void*, void*, void*, void*); auto WorldRemove = AddressByVersion(0x563280, 0, 0x57D370, 0x57C480, 0x57C3B0); // SA variables void** rwengine = *AddressByVersion(0x58FFC0, 0x53F032, 0x48C194, 0x48B167, 0x48B167); -RwInt32& ms_extraVertColourPluginOffset = **AddressByVersion(0x5D6362, 0x5D6B42, 0x5F2B65); unsigned char& nGameClockDays = **AddressByVersion(0x4E841D, 0x4E886D, 0x4F3871); unsigned char& nGameClockMonths = **AddressByVersion(0x4E842D, 0x4E887D, 0x4F3861); @@ -344,9 +310,6 @@ int& MoonSize = **AddressByVersion(0x713B0C, 0x71433C, 0x72F0AB); CZoneInfo*& pCurrZoneInfo = **AddressByVersion(0x58ADB1, 0x58B581, 0x407F93); CRGBA* HudColour = *AddressByVersion(0x58ADF6, 0x58B5C6, 0x440648); -float& m_fDNBalanceParam = **AddressByVersion(0x4A9062, 0x4A90F2, 0x4B2512); -RpLight*& pAmbient = **AddressByVersion(0x5BA53A, 0x735D11, 0x5D90F0); - CLinkListSA& ms_weaponPedsForPC = **AddressByVersion**>(0x53EACA, 0x53EF6A, 0x551101); CLinkListSA& m_alphaList = **AddressByVersion**>(0x733A4D, 0x73427D, 0x76DCA3); @@ -1581,280 +1544,6 @@ void InstallMemValidator() #endif -#pragma warning(push) -#pragma warning(disable:4838) -#include -#pragma warning(pop) - -static void* pNVCShader = nullptr; -static bool bRenderNVC = false; -static bool bXMSupported; - -bool ShaderAttach() -{ - // CGame::InitialiseRenderWare - if ( InitialiseRenderWare() ) - { - HRSRC resource = FindResourceW(hDLLModule, MAKEINTRESOURCE(IDR_NVCSHADER), RT_RCDATA); - RwUInt32* shader = static_cast(LockResource( LoadResource(hDLLModule, resource) )); - - RwD3D9CreateVertexShader(shader, reinterpret_cast(&pNVCShader)); - - bXMSupported = XMVerifyCPUSupport() != FALSE; - return true; - } - return false; -} - -void ShaderDetach() -{ - if ( pNVCShader != nullptr ) - { - RwD3D9DeleteVertexShader(pNVCShader); - pNVCShader = nullptr; - } - - // PluginDetach? - ShutdownRenderWare(); -} - -// Function for 1.01 -BOOL Initialise3D(void* pParam) -{ - RwBool (*RsRwInitialize)(void*); - Memory::ReadCall( 0x5BFB92, RsRwInitialize); - if ( RsRwInitialize(pParam) ) - return ShaderAttach(); - return false; -} - -void SetShader(RxD3D9InstanceData* pInstData) -{ - if (bRenderNVC ) - { - float fEnvVars[2] = { m_fDNBalanceParam, RpMaterialGetColor(pInstData->material)->alpha * (1.0f/255.0f) }; - RwRGBAReal* AmbientLight = RpLightGetColor(pAmbient); - - // Normalise the balance - if ( fEnvVars[0] < 0.0f ) - fEnvVars[0] = 0.0f; - else if ( fEnvVars[0] > 1.0f ) - fEnvVars[0] = 1.0f; - - RwD3D9SetVertexShader(pNVCShader); - - //_rwD3D9VSSetActiveWorldMatrix(RwFrameGetLTM(RpAtomicGetFrame(pRenderedAtomic))); - //_rwD3D9VSSetActiveWorldMatrix(RwFrameGetMatrix(RpAtomicGetFrame(pRenderedAtomic))); - //_rwD3D9VSGetComposedTransformMatrix(&outMat); - - XMMATRIX worldMat, viewMat, projMat; - XMMATRIX worldViewProjMat; - _RwD3D9GetTransform(D3DTS_WORLD, &worldMat); - _RwD3D9GetTransform(D3DTS_VIEW, &viewMat); - _RwD3D9GetTransform(D3DTS_PROJECTION, &projMat); - - if ( bXMSupported ) - { - worldViewProjMat = XMMatrixMultiply(XMMatrixMultiply(worldMat, viewMat), projMat); - } - else - { - XMMATRIX tempMat; - ZeroMemory(&worldViewProjMat, sizeof(worldViewProjMat)); - ZeroMemory(&tempMat, sizeof(tempMat)); - - for( int i = 0; i < 4; i++ ) - { - for( int j = 0; j < 4; j++ ) - { - for(int x = 0; x < 4; x++) - tempMat.m[i][j] += worldMat.m[i][x] * viewMat.m[x][j]; - } - } - - for( int i = 0; i < 4; i++ ) - { - for( int j = 0; j < 4; j++ ) - { - for(int x = 0; x < 4; x++) - worldViewProjMat.m[i][j] += tempMat.m[i][x] * projMat.m[x][j]; - } - } - - } - - //RwD3D9SetVertexShaderConstant(2, &worldMat, 4); - //RwD3D9SetVertexShaderConstant(6, &viewMat, 4); - //RwD3D9SetVertexShaderConstant(10, &projMat, 4); - RwD3D9SetVertexShaderConstant(2, &worldViewProjMat, 4); - - RwD3D9SetVertexShaderConstant(0, fEnvVars, 1); - RwD3D9SetVertexShaderConstant(1, AmbientLight, 1); - } - else - RwD3D9SetVertexShader(pInstData->vertexShader); -} - -void __declspec(naked) SetShader2() -{ - _asm - { - mov bRenderNVC, 1 - push ecx - push edx - push edi - push ebp - call D3D9RenderPreLit - add esp, 10h - mov bRenderNVC, 0 - retn - } -} - -static void* pJackedEsi; -static void* PassDayColoursToShader_NextIt = AddressByVersion(0x5D6382, 0x5D6B62, 0x5F2B81); -static void* PassDayColoursToShader_Return = AddressByVersion(0x5D63BD, 0x5D6B9D, 0x5F2BB4); -void __declspec(naked) HijackEsi() -{ - _asm - { - mov [esp+48h-2Ch], eax - mov pJackedEsi, esi - lea esi, [ebp+44h] - - jmp PassDayColoursToShader_NextIt - } -} - -void __declspec(naked) PassDayColoursToShader() -{ - _asm - { - mov [esp+54h],eax - jz PassDayColoursToShader_FindDayColours - jmp PassDayColoursToShader_NextIt - -PassDayColoursToShader_FindDayColours: - xor eax, eax - -PassDayColoursToShader_FindDayColours_Loop: - cmp byte ptr [esp+eax*8+48h-28h+6], D3DDECLUSAGE_COLOR - jnz PassDayColoursToShader_FindDayColours_Next - cmp byte ptr [esp+eax*8+48h-28h+7], 1 - jz PassDayColoursToShader_DoDayColours - -PassDayColoursToShader_FindDayColours_Next: - inc eax - jmp PassDayColoursToShader_FindDayColours_Loop - -PassDayColoursToShader_DoDayColours: - mov esi, pJackedEsi - mov edx, [ms_extraVertColourPluginOffset] - mov edx, dword ptr [edx] - mov edx, dword ptr [edx+esi+4] - mov edi, dword ptr [ebp+18h] - mov [esp+48h+4], edx - mov edx, dword ptr [ebp+4] - lea eax, [esp+eax*8+48h-26h] - mov [esp+48h+0Ch], edx - mov [esp+48h-2Ch], eax - lea esi, [ebp+44h] - -PassDayColoursToShader_Iterate: - mov edx, dword ptr [esi+14h] - mov eax, dword ptr [esi] - push edi - push edx - mov edx, dword ptr [esp+50h+4] - lea edx, [edx+eax*4] - imul eax, edi - push edx - mov edx, dword ptr [esp+54h-2Ch] - movzx edx, word ptr [edx] - add ecx, eax - add edx, ecx - push edx - call _rpD3D9VertexDeclarationInstColor - mov ecx, dword ptr [esp+58h-34h] - mov [esi+8], eax - mov eax, dword ptr [esp+58h+0Ch] - add esp, 10h - add esi, 24h - dec eax - mov [esp+48h+0Ch], eax - jnz PassDayColoursToShader_Iterate - - jmp PassDayColoursToShader_Return - } -} - -void __declspec(naked) PassDayColoursToShader_Steam() -{ - _asm - { - dec ebx - jz PassDayColoursToShader_FindDayColours - jmp PassDayColoursToShader_NextIt - -PassDayColoursToShader_FindDayColours: - xor eax, eax - -PassDayColoursToShader_FindDayColours_Loop: - cmp byte ptr [esp+eax*8+48h-28h+6], D3DDECLUSAGE_COLOR - jnz PassDayColoursToShader_FindDayColours_Next - cmp byte ptr [esp+eax*8+48h-28h+7], 1 - jz PassDayColoursToShader_DoDayColours - -PassDayColoursToShader_FindDayColours_Next: - inc eax - jmp PassDayColoursToShader_FindDayColours_Loop - -PassDayColoursToShader_DoDayColours: - mov esi, pJackedEsi - mov edx, [ms_extraVertColourPluginOffset] - mov edx, dword ptr [edx] - mov edx, dword ptr [edx+esi+4] - mov edi, dword ptr [ebp+18h] - mov [esp+48h+0Ch], edx - mov ebx, dword ptr [ebp+4] - lea eax, [esp+eax*8+48h-26h] - mov [esp+48h-2Ch], eax - lea esi, [ebp+44h] - -PassDayColoursToShader_Iterate: - mov edx, dword ptr [esi+14h] - mov eax, dword ptr [esi] - push edi - push edx - mov edx, dword ptr [esp+50h+0Ch] - lea edx, [edx+eax*4] - imul eax, edi - push edx - mov edx, dword ptr [esp+54h-2Ch] - add eax, dword ptr [esp+54h-34h] - movzx edx, word ptr [edx] - add edx, eax - push edx - call _rpD3D9VertexDeclarationInstColor - mov [esi+8], eax - add esp, 10h - add esi, 24h - dec ebx - jnz PassDayColoursToShader_Iterate - - jmp PassDayColoursToShader_Return - } -} - -void __declspec(naked) ChangeEdi_Steam() -{ - _asm - { - mov edi, SIZE D3DCOLOR - cmp byte ptr [esp+4Ch-35h], 0 - retn - } -} // Hooks void __declspec(naked) LightMaterialsFix() @@ -2691,40 +2380,6 @@ BOOL InjectDelayedPatches_10() } } - - if ( !bSAMP && GetPrivateProfileIntW(L"SilentPatch", L"NVCShader", -1, wcModulePath) == 1 ) - { - // Shaders! - // plugin-sdk compatibility - ReadCall( 0x5BF3A1, InitialiseRenderWare ); - ReadCall( 0x53D910, ShutdownRenderWare ); - ReadCall( 0x5D66F1, D3D9RenderPreLit ); - - InjectHook(0x5DA743, SetShader); - InjectHook(0x5D66F1, SetShader2); - InjectHook(0x5D6116, UsageIndex1, PATCH_JUMP); - InjectHook(0x5D63B7, PassDayColoursToShader, PATCH_JUMP); - InjectHook(0x5D637B, HijackEsi, PATCH_JUMP); - InjectHook(0x5BF3A1, ShaderAttach); - InjectHook(0x53D910, ShaderDetach); - Patch(0x5D7200, 0xC3); - Patch(0x5D67BB, 0x6890); - Patch(0x5D67D7, 0x6890); - Patch(0x5D67BD, 0x5D5FE0); - Patch(0x5D67D9, 0x5D5FE0); - Patch(0x5DA73F, 0x90909056); - - Patch(0x5D60D9, D3DDECLTYPE_D3DCOLOR); - Patch(0x5D60E2, D3DDECLUSAGE_COLOR); - Patch(0x5D60CF, sizeof(D3DCOLOR)); - Patch(0x5D60EA, sizeof(D3DCOLOR)); - Patch(0x5D60C2, 0x13); - Patch(0x5D62F0, 0xEB); - - // PostFX fix - Patch(*(float**)0x7034C0, 0.0); - } - // Weapons rendering InjectHook(0x5E7859, RenderWeapon); InjectHook(0x732F30, RenderWeaponPedsForPC, PATCH_JUMP); @@ -3077,54 +2732,6 @@ BOOL InjectDelayedPatches_11() } } - if ( !bSAMP && GetPrivateProfileIntW(L"SilentPatch", L"NVCShader", -1, wcModulePath) == 1 ) - { - // Shaders! - // plugin-sdk compatibility - // 1.01 needs to reverse Initialise3D - ReadCall( 0x5BFB9E, InitialiseRenderWare ); - ReadCall( 0x53DDB0, ShutdownRenderWare ); - ReadCall( 0x5D6ED1, D3D9RenderPreLit ); - - InjectHook(0x5BFB70, Initialise3D, PATCH_JUMP); - InjectHook(0x5D6ED1, SetShader2); - InjectHook(0x5D68F6, UsageIndex1, PATCH_JUMP); - InjectHook(0x5D6B97, PassDayColoursToShader, PATCH_JUMP); - InjectHook(0x5D6B5B, HijackEsi, PATCH_JUMP); - //InjectHook(0x5BF3A1, ShaderAttach); - InjectHook(0x53DDB0, ShaderDetach); - Patch(0x5D79E0, 0xC3); - Patch(0x5D6F9B, 0x6890); - Patch(0x5D6FB7, 0x6890); - Patch(0x5D6F9D, 0x5D67C0); - Patch(0x5D6FB9, 0x5D67C0); - - Patch(0x5D68B9, D3DDECLTYPE_D3DCOLOR); - Patch(0x5D68C2, D3DDECLUSAGE_COLOR); - Patch(0x5D68AF, sizeof(D3DCOLOR)); - Patch(0x5D68CA, sizeof(D3DCOLOR)); - Patch(0x5D68A2, 0x13); - Patch(0x5D6AD0, 0xEB); - - if ( *(DWORD*)0x5DAEC0 == 0x0C2444F6 ) - { - InjectHook(0x5DAEC0 + 0xA3, SetShader); - Patch(0x5DAEC0 + 0x9F, 0x90909056); - } - else - { - // securom'd EXE - if ( *(DWORD*)0x14D0882 == 0x51104E8B ) - { - InjectHook(0x14D088B, SetShader, PATCH_JUMP); - Patch(0x14D0882, 0x90909056); - } - } - - // PostFX fix - Patch(*(float**)0x703CF0, 0.0); - } - // Weapons rendering InjectHook(0x5E8079, RenderWeapon); InjectHook(0x733760, RenderWeaponPedsForPC, PATCH_JUMP); @@ -3310,41 +2917,6 @@ BOOL InjectDelayedPatches_Steam() } } - if ( !bSAMP && GetPrivateProfileIntW(L"SilentPatch", L"NVCShader", -1, wcModulePath) == 1 ) - { - // Shaders! - // plugin-sdk compatibility - ReadCall( 0x5DE5A1, InitialiseRenderWare ); - ReadCall( 0x550070, ShutdownRenderWare ); - ReadCall( 0x5F663E, D3D9RenderPreLit ); - - InjectHook(0x5F6EB3, SetShader); - InjectHook(0x5F2F02, SetShader2); - //InjectHook(0x5F292C, UsageIndex1, PATCH_JUMP); - InjectHook(0x5F2BAF, PassDayColoursToShader_Steam, PATCH_JUMP); - InjectHook(0x5F2B7A, HijackEsi, PATCH_JUMP); - InjectHook(0x5DE5A1, ShaderAttach); - InjectHook(0x550070, ShaderDetach); - Patch(0x5F3760, 0xC3); - Patch(0x5F2FCB, 0x6890); - Patch(0x5F2FE7, 0x6890); - Patch(0x5F2FCD, 0x5F27C0); - Patch(0x5F2FE9, 0x5F27C0); - Patch(0x5F6EAF, 0x90909056); - - Patch(0x5F28D0, 1); - Patch(0x5F28C1, D3DDECLTYPE_D3DCOLOR); - Patch(0x5F28CB, D3DDECLUSAGE_COLOR); - //Patch(0x5D60CF, sizeof(D3DCOLOR)); - //Patch(0x5D60EA, sizeof(D3DCOLOR)); - InjectHook(0x5F28A7, ChangeEdi_Steam, PATCH_CALL); - //Patch(0x5D60C2, 0x13); - Patch(0x5F2AE7, 0xEB); - - // PostFX fix - Patch(*(float**)0x746E57, 0.0); - } - // Weapons rendering InjectHook(0x604DD9, RenderWeapon); InjectHook(0x76D170, RenderWeaponPedsForPC, PATCH_JUMP); diff --git a/SilentPatchSA/SilentPatchSA.vcxproj b/SilentPatchSA/SilentPatchSA.vcxproj index 46fc247..14577f5 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj +++ b/SilentPatchSA/SilentPatchSA.vcxproj @@ -211,29 +211,6 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio - - - Document - fxc /T vs_2_0 /E NVC_vertex_shader /Fo ..\SilentPatch\nvc.cso ..\SilentPatch\nvc.fx - ..\SilentPatch\nvc.cso - Compiling shaders... - fxc /T vs_2_0 /E NVC_vertex_shader /Fo ..\SilentPatch\nvc.cso ..\SilentPatch\nvc.fx - fxc /T vs_2_0 /E NVC_vertex_shader /Fo ..\SilentPatch\nvc.cso ..\SilentPatch\nvc.fx - Compiling shaders... - Compiling shaders... - ..\SilentPatch\nvc.cso - ..\SilentPatch\nvc.cso - NVC_vertex_shader - Vertex - NVC_vertex_shader - NVC_vertex_shader - Vertex - Vertex - $(SolutionDir)\SilentPatch\%(Filename).cso - $(SolutionDir)\SilentPatch\%(Filename).cso - $(SolutionDir)\SilentPatch\%(Filename).cso - - @@ -266,7 +243,6 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio - diff --git a/SilentPatchSA/SilentPatchSA.vcxproj.filters b/SilentPatchSA/SilentPatchSA.vcxproj.filters index fd45a67..2c2d8d4 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj.filters +++ b/SilentPatchSA/SilentPatchSA.vcxproj.filters @@ -13,9 +13,6 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - {729e19b1-4747-44c3-b99e-1ecc383d1cad} - {57615a2f-8bc4-461f-b9f6-86d5f8286d7a} @@ -160,16 +157,8 @@ - - Resource Files - Resource Files - - - Shaders - - \ No newline at end of file