diff --git a/SilentPatchSA/ScriptSA.cpp b/SilentPatchSA/ScriptSA.cpp index f30fcf0..2158e07 100644 --- a/SilentPatchSA/ScriptSA.cpp +++ b/SilentPatchSA/ScriptSA.cpp @@ -3,9 +3,9 @@ static int* StatTypesInt = *AddressByVersion(0x55C0D8, 0x55C578, 0x574F24); -std::pair* CRunningScript::GetDay_GymGlitch() +std::pair* CRunningScript::GetDay_GymGlitch() { - static std::pair Out; + static std::pair Out; if ( !strncmp(Name, "gymbike", 8) || !strncmp(Name, "gymbenc", 8) || !strncmp(Name, "gymtrea", 8) || !strncmp(Name, "gymdumb", 8) ) { diff --git a/SilentPatchSA/ScriptSA.h b/SilentPatchSA/ScriptSA.h index dddd2f9..63893c1 100644 --- a/SilentPatchSA/ScriptSA.h +++ b/SilentPatchSA/ScriptSA.h @@ -67,7 +67,7 @@ private: BYTE IsCustom; public: - std::pair* GetDay_GymGlitch(); + std::pair* GetDay_GymGlitch(); }; static_assert(sizeof(CRunningScript) == 0xE0, "Wrong size: CRunningScript"); diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 3175a9b..8f16fa8 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -41,18 +41,37 @@ 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* var_rwD3D9SetVertexShader = AddressByVersion(0x7F9FB0, 0x7FA8B0, 0x833F70); -WRAPPER void _rwD3D9SetVertexShader(void *shader) { VARJMP(var_rwD3D9SetVertexShader); } -static void* varRwD3D9CreateVertexShader = AddressByVersion(0x7FAC60, 0x7FB560, 0x834C20); -WRAPPER RwBool RwD3D9CreateVertexShader(const RwUInt32 *function, void **shader) { VARJMP(varRwD3D9CreateVertexShader); } -static void* var_rwD3D9SetVertexShaderConstant = AddressByVersion(0x7FACA0, 0x7FB5A0, 0x834C60); -WRAPPER void _rwD3D9SetVertexShaderConstant(RwUInt32 registerAddress, - const void *constantData, - RwUInt32 constantCount) { VARJMP(var_rwD3D9SetVertexShaderConstant); } - 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) { return camera->beginUpdate(camera); @@ -237,14 +256,14 @@ struct AlphaObjectInfo // Other wrappers void (*GTAdelete)(void*) = AddressByVersion(0x82413F, 0x824EFF, 0x85E58C); const char* (*GetFrameNodeName)(RwFrame*) = AddressByVersion(0x72FB30, 0x730360, 0x769C20); -RpHAnimHierarchy* (*GetAnimHierarchyFromSkinClump)(RpClump*) = AddressByVersion(0x734A40, 0x735270, 0x7671B0); -auto SetVolume = AddressByVersion(0x4D7C60, 0x4D7E60, 0x4E2750); +RpHAnimHierarchy* (*GetAnimHierarchyFromSkinClump)(RpClump*) = AddressByVersion(0x734A40, 0x735270, 0x7671B0); auto InitializeUtrax = AddressByVersion(0x4F35B0, 0x4F3A10, 0x4FFA80); auto CanSeeOutSideFromCurrArea = AddressByVersion(0x53C4A0, 0x53C940, 0x54E440); auto __rwD3D9TextureHasAlpha = AddressByVersion(0x4C9EA0, 0x4CA090, 0x4D47E0); auto RenderOneXLUSprite = AddressByVersion(0x70D000, 0x70D830, 0x7592C0); +static void (__thiscall* SetVolume)(void*,float); static BOOL (*IsAlreadyRunning)(); static void (*TheScriptsLoad)(); static void (*WipeLocalVariableMemoryForMissionScript)(); @@ -344,11 +363,9 @@ RpAtomic* TwoPassAlphaRender_aap(RpAtomic* atomic) return AtomicDefaultRenderCallBack(atomic); int nPushedAlpha, nAlphaFunction; - int nZWrite; int nAlphaBlending; RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); - RwRenderStateGet(rwRENDERSTATEZWRITEENABLE, &nZWrite); RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); @@ -363,15 +380,19 @@ RpAtomic* TwoPassAlphaRender_aap(RpAtomic* atomic) if ( atomic != nullptr ) { // 2nd pass + int nZWrite; + RwRenderStateGet(rwRENDERSTATEZWRITEENABLE, &nZWrite); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); atomic = AtomicDefaultRenderCallBack(atomic); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); } RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); return atomic; @@ -3053,9 +3074,9 @@ void Patch_SA_10() Nop(0x5C25D3, 5); // User Tracks fix + ReadCall( 0x4D9B66, SetVolume ); InjectHook(0x4D9B66, UserTracksFix); InjectHook(0x4D9BB5, 0x4F2FD0); - //Nop(0x4D9BB5, 5); // FLAC support InjectHook(0x4F373D, LoadFLAC, PATCH_JUMP); @@ -3499,6 +3520,7 @@ void Patch_SA_11() Patch(0x4A9D50, 0xC3); // User Tracks fix + ReadCall( 0x4DA057, SetVolume ); InjectHook(0x4DA057, UserTracksFix); InjectHook(0x4DA0A5, 0x4F3430); @@ -3822,6 +3844,7 @@ void Patch_SA_Steam() Nop(0x5D88AE, 5); // User Tracks fix + SetVolume = reinterpret_cast(0x4E2750); Patch(0x4E4A28, 0xBA); Patch(0x4E4A29, UserTracksFix_Steam); InjectHook(0x4E4A8B, 0x4FF2B0);