diff --git a/SilentPatch/StdAfx.h b/SilentPatch/StdAfx.h index 6c81a6e..b99b4f2 100644 --- a/SilentPatch/StdAfx.h +++ b/SilentPatch/StdAfx.h @@ -26,5 +26,6 @@ //#define HIDE_MATERIAL //#define EXPAND_ALPHA_ENTITY_LISTS 800 +//#define EXPAND_BOAT_ALPHA_ATOMIC_LISTS 400 //#define SA_STEAM_TEST \ No newline at end of file diff --git a/SilentPatch/dllmain.cpp b/SilentPatch/dllmain.cpp index 273dae4..af3267b 100644 --- a/SilentPatch/dllmain.cpp +++ b/SilentPatch/dllmain.cpp @@ -1528,7 +1528,7 @@ void __declspec(naked) DumpIPLStub() #include "nvc.h" static IDirect3DVertexShader9* pNVCShader = nullptr; -static bool bRenderNVC; +static bool bRenderNVC = false; static RpAtomic* pRenderedAtomic; WRAPPER void _rwD3D9SetVertexShader(void *shader) { EAXJMP(0x7F9FB0); } @@ -1546,15 +1546,28 @@ WRAPPER RwBool _rpD3D9VertexDeclarationInstColor(RwUInt8 *mem, RwInt32 numVerts, RwUInt32 stride) { EAXJMP(0x754AE0); } -void CompileShader() -{ - static bool bCompiledYet = false; +WRAPPER bool IsVisionFXActive() { EAXJMP(0x7034F0); } - if ( !bCompiledYet ) +bool ShaderAttach() +{ + // CGame::InitialiseRenderWare + // TODO: EXEs + if ( ((bool(*)())0x5BD600)() ) { - bCompiledYet = true; RwD3D9CreateVertexShader(reinterpret_cast(g_vs20_NVC_vertex_shader), reinterpret_cast(&pNVCShader)); + return true; } + return false; +} + +void ShaderDetach() +{ + if ( pNVCShader ) + RwD3D9DeleteVertexShader(pNVCShader); + + // PluginDetach? + // TODO: EXEs + ((void(*)())0x53BB80)(); } void SetShader(void* shader) @@ -1564,6 +1577,9 @@ void SetShader(void* shader) // TODO: Daynight balance var D3DMATRIX outMat; float fDayNightBalance = *(float*)0x8D12C0; + RwRGBAReal* AmbientLight = RpLightGetColor(*(RpLight**)0xC886E8); + + assert(!shader); RwD3D9SetVertexShader(pNVCShader); @@ -1572,6 +1588,7 @@ void SetShader(void* shader) RwD3D9SetVertexShaderConstant(0, &outMat, 4); RwD3D9SetVertexShaderConstant(4, &fDayNightBalance, 1); + RwD3D9SetVertexShaderConstant(5, AmbientLight, 1); } else RwD3D9SetVertexShader(shader); @@ -1586,7 +1603,6 @@ void __declspec(naked) SetShader2() push edx push edi push ebp - call CompileShader mov eax, 5DA6A0h call eax add esp, 10h @@ -1702,11 +1718,13 @@ __forceinline void Patch_SA_10() using namespace MemoryVP; // TEMP - shaders! - /*InjectHook(0x5DA743, SetShader); + 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(0x5D67F4, HijackAtomic); Patch(0x5D7200, 0xC3); Patch(0x5D67BB, 0x6890); @@ -1719,7 +1737,10 @@ __forceinline void Patch_SA_10() Patch(0x5D60CF, sizeof(D3DCOLOR)); Patch(0x5D60EA, sizeof(D3DCOLOR)); Patch(0x5D60C2, 0x13); - Patch(0x5D62F0, 0xEB);*/ + Patch(0x5D62F0, 0xEB); + + // PostFX fix + Patch(*(float**)0x7034C0, 0.0); //Patch(0x5D7265, 0xEB); @@ -1735,6 +1756,16 @@ __forceinline void Patch_SA_10() Patch(0x73445E, RenderBigVehicleActomic); //Patch(0x73406E, TwoPassAlphaRender); + // Boats + /*Patch(0x4C79DF, 0x19); + Patch(0x733A87, EXPAND_BOAT_ALPHA_ATOMIC_LISTS * sizeof(AlphaObjectInfo)); + Patch(0x733AD7, EXPAND_BOAT_ALPHA_ATOMIC_LISTS * sizeof(AlphaObjectInfo));*/ + + // Fixed strafing? Hopefully + static const float fStrafeCheck = 0.1f; + Patch(0x61E0C2, &fStrafeCheck); + Nop(0x61E0CA, 6); + // Plane rotors InjectHook(0x4C7981, PlaneAtomicRendererSetup, PATCH_JUMP); diff --git a/SilentPatch/nvc.fx b/SilentPatch/nvc.fx index f6136d4..d0e8cc3 100644 --- a/SilentPatch/nvc.fx +++ b/SilentPatch/nvc.fx @@ -15,6 +15,7 @@ struct VS_OUTPUT float4x4 viewProjMatrix : register(c0); float fDayNightBalance : register(c4); +float4 AmbientLight : register(c5); VS_OUTPUT NVC_vertex_shader( in VS_INPUT In ) { @@ -22,7 +23,10 @@ VS_OUTPUT NVC_vertex_shader( in VS_INPUT In ) Out.Position = mul(In.Position, viewProjMatrix); Out.Texture = In.Texture; - Out.Color = In.DayColor * (1.0-fDayNightBalance) + In.NightColor * fDayNightBalance; + + Out.Color = (In.DayColor * (1.0-fDayNightBalance) + In.NightColor * fDayNightBalance); + Out.Color.rgb += AmbientLight.rgb * AmbientLight.a; + Out.Color = saturate(Out.Color); return Out; } \ No newline at end of file diff --git a/SilentPatch/nvc.h b/SilentPatch/nvc.h index 42fda30..44beebd 100644 --- a/SilentPatch/nvc.h +++ b/SilentPatch/nvc.h @@ -8,6 +8,7 @@ // // Parameters: // +// float4 AmbientLight; // float fDayNightBalance; // float4x4 viewProjMatrix; // @@ -18,10 +19,11 @@ // ---------------- ----- ---- // viewProjMatrix c0 4 // fDayNightBalance c4 1 +// AmbientLight c5 1 // vs_2_0 - def c5, 1, 0, 0, 0 + def c6, 1, 0, 0, 0 dcl_position v0 dcl_texcoord v1 dcl_color v2 @@ -30,85 +32,106 @@ dp4 oPos.y, v0, c1 dp4 oPos.z, v0, c2 dp4 oPos.w, v0, c3 - mov r0.x, c4.x - add r0.x, -r0.x, c5.x + mov r0.x, c6.x + add r0.x, r0.x, -c4.x mul r1, v2, c4.x - mad oD0, v3, r0.x, r1 + mad r0, v3, r0.x, r1 + mad r0.xyz, c5, c5.w, r0 + max r0, r0, c6.y + min oD0, r0, c6.x mov oT0.xy, v1 -// approximately 9 instruction slots used +// approximately 12 instruction slots used #endif const BYTE g_vs20_NVC_vertex_shader[] = { 0, 2, 254, 255, 254, 255, - 49, 0, 67, 84, 65, 66, - 28, 0, 0, 0, 143, 0, + 62, 0, 67, 84, 65, 66, + 28, 0, 0, 0, 195, 0, 0, 0, 0, 2, 254, 255, - 2, 0, 0, 0, 28, 0, + 3, 0, 0, 0, 28, 0, 0, 0, 0, 1, 0, 0, - 136, 0, 0, 0, 68, 0, - 0, 0, 2, 0, 4, 0, - 1, 0, 18, 0, 88, 0, + 188, 0, 0, 0, 88, 0, + 0, 0, 2, 0, 5, 0, + 1, 0, 22, 0, 104, 0, 0, 0, 0, 0, 0, 0, - 104, 0, 0, 0, 2, 0, - 0, 0, 4, 0, 2, 0, - 120, 0, 0, 0, 0, 0, - 0, 0, 102, 68, 97, 121, - 78, 105, 103, 104, 116, 66, - 97, 108, 97, 110, 99, 101, - 0, 171, 171, 171, 0, 0, - 3, 0, 1, 0, 1, 0, + 120, 0, 0, 0, 2, 0, + 4, 0, 1, 0, 18, 0, + 140, 0, 0, 0, 0, 0, + 0, 0, 156, 0, 0, 0, + 2, 0, 0, 0, 4, 0, + 2, 0, 172, 0, 0, 0, + 0, 0, 0, 0, 65, 109, + 98, 105, 101, 110, 116, 76, + 105, 103, 104, 116, 0, 171, + 171, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 102, 68, 97, 121, 78, 105, + 103, 104, 116, 66, 97, 108, + 97, 110, 99, 101, 0, 171, + 171, 171, 0, 0, 3, 0, + 1, 0, 1, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 118, 105, 101, 119, 80, 114, + 111, 106, 77, 97, 116, 114, + 105, 120, 0, 171, 3, 0, + 3, 0, 4, 0, 4, 0, 1, 0, 0, 0, 0, 0, - 0, 0, 118, 105, 101, 119, - 80, 114, 111, 106, 77, 97, - 116, 114, 105, 120, 0, 171, - 3, 0, 3, 0, 4, 0, - 4, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 118, 115, - 95, 50, 95, 48, 0, 77, - 105, 99, 114, 111, 115, 111, - 102, 116, 32, 40, 82, 41, - 32, 72, 76, 83, 76, 32, - 83, 104, 97, 100, 101, 114, - 32, 67, 111, 109, 112, 105, - 108, 101, 114, 32, 57, 46, - 50, 57, 46, 57, 53, 50, - 46, 51, 49, 49, 49, 0, - 81, 0, 0, 5, 5, 0, - 15, 160, 0, 0, 128, 63, + 0, 0, 118, 115, 95, 50, + 95, 48, 0, 77, 105, 99, + 114, 111, 115, 111, 102, 116, + 32, 40, 82, 41, 32, 72, + 76, 83, 76, 32, 83, 104, + 97, 100, 101, 114, 32, 67, + 111, 109, 112, 105, 108, 101, + 114, 32, 57, 46, 50, 57, + 46, 57, 53, 50, 46, 51, + 49, 49, 49, 0, 81, 0, + 0, 5, 6, 0, 15, 160, + 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 31, 0, 0, 2, 0, 0, - 0, 128, 0, 0, 15, 144, - 31, 0, 0, 2, 5, 0, - 0, 128, 1, 0, 15, 144, - 31, 0, 0, 2, 10, 0, - 0, 128, 2, 0, 15, 144, - 31, 0, 0, 2, 10, 0, - 1, 128, 3, 0, 15, 144, - 9, 0, 0, 3, 0, 0, - 1, 192, 0, 0, 228, 144, - 0, 0, 228, 160, 9, 0, - 0, 3, 0, 0, 2, 192, - 0, 0, 228, 144, 1, 0, + 0, 0, 0, 0, 31, 0, + 0, 2, 0, 0, 0, 128, + 0, 0, 15, 144, 31, 0, + 0, 2, 5, 0, 0, 128, + 1, 0, 15, 144, 31, 0, + 0, 2, 10, 0, 0, 128, + 2, 0, 15, 144, 31, 0, + 0, 2, 10, 0, 1, 128, + 3, 0, 15, 144, 9, 0, + 0, 3, 0, 0, 1, 192, + 0, 0, 228, 144, 0, 0, 228, 160, 9, 0, 0, 3, - 0, 0, 4, 192, 0, 0, - 228, 144, 2, 0, 228, 160, + 0, 0, 2, 192, 0, 0, + 228, 144, 1, 0, 228, 160, 9, 0, 0, 3, 0, 0, - 8, 192, 0, 0, 228, 144, - 3, 0, 228, 160, 1, 0, - 0, 2, 0, 0, 1, 128, - 4, 0, 0, 160, 2, 0, - 0, 3, 0, 0, 1, 128, - 0, 0, 0, 129, 5, 0, - 0, 160, 5, 0, 0, 3, - 1, 0, 15, 128, 2, 0, - 228, 144, 4, 0, 0, 160, + 4, 192, 0, 0, 228, 144, + 2, 0, 228, 160, 9, 0, + 0, 3, 0, 0, 8, 192, + 0, 0, 228, 144, 3, 0, + 228, 160, 1, 0, 0, 2, + 0, 0, 1, 128, 6, 0, + 0, 160, 2, 0, 0, 3, + 0, 0, 1, 128, 0, 0, + 0, 128, 4, 0, 0, 161, + 5, 0, 0, 3, 1, 0, + 15, 128, 2, 0, 228, 144, + 4, 0, 0, 160, 4, 0, + 0, 4, 0, 0, 15, 128, + 3, 0, 228, 144, 0, 0, + 0, 128, 1, 0, 228, 128, 4, 0, 0, 4, 0, 0, - 15, 208, 3, 0, 228, 144, - 0, 0, 0, 128, 1, 0, - 228, 128, 1, 0, 0, 2, - 0, 0, 3, 224, 1, 0, - 228, 144, 255, 255, 0, 0 + 7, 128, 5, 0, 228, 160, + 5, 0, 255, 160, 0, 0, + 228, 128, 11, 0, 0, 3, + 0, 0, 15, 128, 0, 0, + 228, 128, 6, 0, 85, 160, + 10, 0, 0, 3, 0, 0, + 15, 208, 0, 0, 228, 128, + 6, 0, 0, 160, 1, 0, + 0, 2, 0, 0, 3, 224, + 1, 0, 228, 144, 255, 255, + 0, 0 };