From b80846091f6814ae64c8eadf4eabe7cc0da61f35 Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 3 Aug 2014 15:38:53 +0200 Subject: [PATCH] III/VC and SA files split --- .../AudioHardwareSA.cpp | 7 +- .../AudioHardwareSA.h | 0 .../General.cpp => SAFix/GeneralSA.cpp | 6 +- SilentPatch/General.h => SAFix/GeneralSA.h | 3 + SilentPatch/LinkList.h => SAFix/LinkListSA.h | 40 +- {SilentPatch => SAFix}/Maths.h | 0 {SilentPatch => SAFix}/ModelInfoSA.cpp | 2 +- {SilentPatch => SAFix}/ModelInfoSA.h | 2 +- {SilentPatch => SAFix}/PNGFile.cpp | 2 +- {SilentPatch => SAFix}/PNGFile.h | 0 SAFix/SAFix.vcxproj | 47 +- SAFix/SAFix.vcxproj.filters | 67 +- SilentPatch/Script.cpp => SAFix/ScriptSA.cpp | 6 +- SilentPatch/Script.h => SAFix/ScriptSA.h | 0 SAFix/SilentPatchSA.cpp | 1393 +++++++++++++++++ SAFix/StdAfxSA.cpp | 1 + SilentPatch/StdAfx.h => SAFix/StdAfxSA.h | 22 +- SAFix/TimerSA.cpp | 4 + SAFix/TimerSA.h | 10 + .../Vehicle.cpp => SAFix/VehicleSA.cpp | 10 +- SilentPatch/Vehicle.h => SAFix/VehicleSA.h | 8 +- SilentPatch/MemoryMgr.h | 126 +- SilentPatch/StdAfx.cpp | 1 - SilentPatch/Timer.cpp | 2 +- SilentPatch/dllmain.cpp | 486 +----- 25 files changed, 1664 insertions(+), 581 deletions(-) rename SilentPatch/AudioHardware.cpp => SAFix/AudioHardwareSA.cpp (98%) rename SilentPatch/AudioHardware.h => SAFix/AudioHardwareSA.h (100%) rename SilentPatch/General.cpp => SAFix/GeneralSA.cpp (95%) rename SilentPatch/General.h => SAFix/GeneralSA.h (99%) rename SilentPatch/LinkList.h => SAFix/LinkListSA.h (72%) rename {SilentPatch => SAFix}/Maths.h (100%) rename {SilentPatch => SAFix}/ModelInfoSA.cpp (99%) rename {SilentPatch => SAFix}/ModelInfoSA.h (99%) rename {SilentPatch => SAFix}/PNGFile.cpp (98%) rename {SilentPatch => SAFix}/PNGFile.h (100%) rename SilentPatch/Script.cpp => SAFix/ScriptSA.cpp (77%) rename SilentPatch/Script.h => SAFix/ScriptSA.h (100%) create mode 100644 SAFix/SilentPatchSA.cpp create mode 100644 SAFix/StdAfxSA.cpp rename SilentPatch/StdAfx.h => SAFix/StdAfxSA.h (73%) create mode 100644 SAFix/TimerSA.cpp create mode 100644 SAFix/TimerSA.h rename SilentPatch/Vehicle.cpp => SAFix/VehicleSA.cpp (96%) rename SilentPatch/Vehicle.h => SAFix/VehicleSA.h (98%) delete mode 100644 SilentPatch/StdAfx.cpp diff --git a/SilentPatch/AudioHardware.cpp b/SAFix/AudioHardwareSA.cpp similarity index 98% rename from SilentPatch/AudioHardware.cpp rename to SAFix/AudioHardwareSA.cpp index 0b97ea6..8d509f7 100644 --- a/SilentPatch/AudioHardware.cpp +++ b/SAFix/AudioHardwareSA.cpp @@ -1,11 +1,12 @@ -#include "StdAfx.h" -#include "AudioHardware.h" +#include "StdAfxSA.h" +#include "AudioHardwareSA.h" //WRAPPER HRESULT STDMETHODCALLTYPE CAEDataStream::Seek(LARGE_INTEGER liDistanceToMove, DWORD dwOrigin, ULARGE_INTEGER* lpNewFilePointer) // { EAXJMP(0x4DC340); } //WRAPPER HRESULT STDMETHODCALLTYPE CAEDataStream::Stat(STATSTG* pStatstg, DWORD grfStatFlag) { EAXJMP(0x4DC3A0); } -WRAPPER bool CAEDataStream::Initialise() { EAXJMP(0x4DC2B0); } +static void* CAEDataStream__Initialise = AddressByVersion(0x4DC2B0, 0, 0); +WRAPPER bool CAEDataStream::Initialise() { VARJMP(CAEDataStream__Initialise); } unsigned int CAEStreamingDecoder::nMallocRefCount = 0; diff --git a/SilentPatch/AudioHardware.h b/SAFix/AudioHardwareSA.h similarity index 100% rename from SilentPatch/AudioHardware.h rename to SAFix/AudioHardwareSA.h diff --git a/SilentPatch/General.cpp b/SAFix/GeneralSA.cpp similarity index 95% rename from SilentPatch/General.cpp rename to SAFix/GeneralSA.cpp index 47647ef..3c01d06 100644 --- a/SilentPatch/General.cpp +++ b/SAFix/GeneralSA.cpp @@ -1,5 +1,5 @@ -#include "StdAfx.h" -#include "General.h" +#include "StdAfxSA.h" +#include "GeneralSA.h" // Wrappers WRAPPER bool CalcScreenCoors(const CVector& vecIn, CVector* vecOut) { WRAPARG(vecIn); WRAPARG(vecOut); EAXJMP(0x71DAB0); } @@ -31,7 +31,7 @@ static void ResetEditableMaterials(std::pair* pData) void CObject::Render() { - if ( m_bDoNotRender ) + if ( m_bDoNotRender || !m_pRwObject ) return; bool bCallRestore; diff --git a/SilentPatch/General.h b/SAFix/GeneralSA.h similarity index 99% rename from SilentPatch/General.h rename to SAFix/GeneralSA.h index f9a0b91..0888b0f 100644 --- a/SilentPatch/General.h +++ b/SAFix/GeneralSA.h @@ -345,6 +345,9 @@ public: float m_fParticlesIntensity; public: + inline void Render_Stub() + { CObject::Render(); } + virtual void Render() override; }; diff --git a/SilentPatch/LinkList.h b/SAFix/LinkListSA.h similarity index 72% rename from SilentPatch/LinkList.h rename to SAFix/LinkListSA.h index 7e25586..151ab06 100644 --- a/SilentPatch/LinkList.h +++ b/SAFix/LinkListSA.h @@ -2,13 +2,13 @@ #define __LINKLIST__ template -class CLink +class CLinkSA { public: - inline void Insert(CLink* pAttach) { + inline void Insert(CLinkSA* pAttach) { pAttach->m_pNext = m_pNext; m_pNext->m_pPrev = pAttach; - + pAttach->m_pPrev = this; m_pNext = pAttach; } @@ -24,22 +24,22 @@ public: T m_pItem; // 0-4 // an item - CLink* m_pPrev; // 4-8 + CLinkSA* m_pPrev; // 4-8 //next link in the list - CLink* m_pNext; // 8-12 + CLinkSA* m_pNext; // 8-12 //prev link in the list }; template -class CLinkList { +class CLinkListSA { public: - CLinkList(void) + CLinkListSA(void) : m_plnLinks(nullptr) { } void Init(int nNumLinks) { - m_plnLinks = new CLink[nNumLinks]; + m_plnLinks = new CLinkSA[nNumLinks]; m_lnListHead.m_pNext = &m_lnListTail; m_lnListTail.m_pPrev = &m_lnListHead; @@ -58,8 +58,8 @@ public: m_plnLinks = nullptr; } - CLink* InsertSorted(const T& pItem) { - CLink* pLink = m_lnFreeListHead.m_pNext; + CLinkSA* InsertSorted(const T& pItem) { + CLinkSA* pLink = m_lnFreeListHead.m_pNext; if(pLink == &m_lnFreeListTail) { return nullptr; @@ -69,7 +69,7 @@ public: pLink->Remove(); - CLink* pInsertAfter = &m_lnListHead; + CLinkSA* pInsertAfter = &m_lnListHead; while(pInsertAfter->m_pNext != &m_lnListTail && pInsertAfter->m_pNext->m_pItem < pItem) { pInsertAfter = pInsertAfter->m_pNext; @@ -80,8 +80,8 @@ public: return pLink; } - CLink* Insert(const T& pItem) { - CLink* pLink = m_lnFreeListHead.m_pNext; + CLinkSA* Insert(const T& pItem) { + CLinkSA* pLink = m_lnFreeListHead.m_pNext; if(pLink == &m_lnFreeListTail) { return nullptr; @@ -101,12 +101,12 @@ public: } } - void Remove(CLink* pLink) { + void Remove(CLinkSA* pLink) { pLink->Remove(); m_lnFreeListHead.Insert(pLink); } - CLink* Next(CLink* pCurrent) { + CLinkSA* Next(CLinkSA* pCurrent) { if(pCurrent == 0) { pCurrent = &m_lnListHead; } @@ -119,15 +119,15 @@ public: } } - CLink m_lnListHead; // 0-12 + CLinkSA m_lnListHead; // 0-12 //head of the list of active links - CLink m_lnListTail; // 12-24 + CLinkSA m_lnListTail; // 12-24 //tail of the list of active links - CLink m_lnFreeListHead; // 24-36 + CLinkSA m_lnFreeListHead; // 24-36 //head of the list of free links - CLink m_lnFreeListTail; // 36-48 + CLinkSA m_lnFreeListTail; // 36-48 //tail of the list of free links - CLink* m_plnLinks; // 48-52 + CLinkSA* m_plnLinks; // 48-52 //pointer to actual array of links }; diff --git a/SilentPatch/Maths.h b/SAFix/Maths.h similarity index 100% rename from SilentPatch/Maths.h rename to SAFix/Maths.h diff --git a/SilentPatch/ModelInfoSA.cpp b/SAFix/ModelInfoSA.cpp similarity index 99% rename from SilentPatch/ModelInfoSA.cpp rename to SAFix/ModelInfoSA.cpp index 6e6911b..591f920 100644 --- a/SilentPatch/ModelInfoSA.cpp +++ b/SAFix/ModelInfoSA.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "StdAfxSA.h" #include "ModelInfoSA.h" WRAPPER void CBaseModelInfo::Shutdown() { EAXJMP(0x4C4D50); } diff --git a/SilentPatch/ModelInfoSA.h b/SAFix/ModelInfoSA.h similarity index 99% rename from SilentPatch/ModelInfoSA.h rename to SAFix/ModelInfoSA.h index 3ae962e..0cc3b52 100644 --- a/SilentPatch/ModelInfoSA.h +++ b/SAFix/ModelInfoSA.h @@ -1,7 +1,7 @@ #ifndef __MODELINFO #define __MODELINFO -#include "General.h" +#include "GeneralSA.h" // TODO: Move to a separate file? typedef struct diff --git a/SilentPatch/PNGFile.cpp b/SAFix/PNGFile.cpp similarity index 98% rename from SilentPatch/PNGFile.cpp rename to SAFix/PNGFile.cpp index 9d568ec..49e3177 100644 --- a/SilentPatch/PNGFile.cpp +++ b/SAFix/PNGFile.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "StdAfxSA.h" #include "PNGFile.h" RwTexture* CPNGFile::ReadFromFile(const char* pFileName) diff --git a/SilentPatch/PNGFile.h b/SAFix/PNGFile.h similarity index 100% rename from SilentPatch/PNGFile.h rename to SAFix/PNGFile.h diff --git a/SAFix/SAFix.vcxproj b/SAFix/SAFix.vcxproj index 2b9ade8..56ca927 100644 --- a/SAFix/SAFix.vcxproj +++ b/SAFix/SAFix.vcxproj @@ -38,10 +38,10 @@ - .dll + .asi - .dll + .asi @@ -49,8 +49,9 @@ Disabled MultiThreadedDebug SILENTPATCH_SA_VER;%(PreprocessorDefinitions) - D:\RWSDK\Graphics\rwsdk\include\d3d9;C:\Program Files\Microsoft DirectX SDK (June 2010)\Include + D:\RWSDK\Graphics\rwsdk\include\d3d9;C:\Program Files\Microsoft DirectX SDK (June 2010)\Include;..\SilentPatch Use + StdAfxSA.h true @@ -74,8 +75,9 @@ SILENTPATCH_SA_VER;NDEBUG;%(PreprocessorDefinitions) true MultiThreaded - D:\RWSDK\Graphics\rwsdk\include\d3d9 + D:\RWSDK\Graphics\rwsdk\include\d3d9;..\SilentPatch Use + StdAfxSA.h true @@ -90,18 +92,18 @@ - - - - - - - + + + + + + + Create Create - - + + @@ -116,23 +118,24 @@ - - - - - - - - - + + + + + + + + + + diff --git a/SAFix/SAFix.vcxproj.filters b/SAFix/SAFix.vcxproj.filters index ee473fc..835c086 100644 --- a/SAFix/SAFix.vcxproj.filters +++ b/SAFix/SAFix.vcxproj.filters @@ -21,31 +21,31 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files @@ -58,30 +58,9 @@ Header Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files - - Header Files - - - Header Files - Header Files\FLAC @@ -100,10 +79,34 @@ Header Files\FLAC - + Header Files - + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + Header Files diff --git a/SilentPatch/Script.cpp b/SAFix/ScriptSA.cpp similarity index 77% rename from SilentPatch/Script.cpp rename to SAFix/ScriptSA.cpp index 20f403c..6dc0328 100644 --- a/SilentPatch/Script.cpp +++ b/SAFix/ScriptSA.cpp @@ -1,7 +1,7 @@ -#include "StdAfx.h" -#include "Script.h" +#include "StdAfxSA.h" +#include "ScriptSA.h" -static int* StatTypesInt = *(int**)0x55C0D8; +static int* StatTypesInt = *AddressByVersion(0x55C0D8, 0, 0); std::pair* CRunningScript::GetDay_GymGlitch() { diff --git a/SilentPatch/Script.h b/SAFix/ScriptSA.h similarity index 100% rename from SilentPatch/Script.h rename to SAFix/ScriptSA.h diff --git a/SAFix/SilentPatchSA.cpp b/SAFix/SilentPatchSA.cpp new file mode 100644 index 0000000..8348cab --- /dev/null +++ b/SAFix/SilentPatchSA.cpp @@ -0,0 +1,1393 @@ +#include "StdAfxSA.h" + +#include "ScriptSA.h" +#include "GeneralSA.h" +#include "ModelInfoSA.h" +#include "VehicleSA.h" +#include "AudioHardwareSA.h" +#include "LinkListSA.h" +#include "PNGFile.h" + +// RW wrappers +// TODO: Multiple EXEs +WRAPPER RwFrame* RwFrameForAllObjects(RwFrame* frame, RwObjectCallBack callBack, void* data) { WRAPARG(frame); WRAPARG(callBack); WRAPARG(data); EAXJMP(0x7F1200); } +WRAPPER RpClump* RpClumpForAllAtomics(RpClump* clump, RpAtomicCallBack callback, void* pData) { WRAPARG(clump); WRAPARG(callback); WRAPARG(pData); EAXJMP(0x749B70); } +WRAPPER RpGeometry* RpGeometryForAllMaterials(RpGeometry* geometry, RpMaterialCallBack fpCallBack, void* pData) { WRAPARG(geometry); WRAPARG(fpCallBack); WRAPARG(pData); EAXJMP(0x74C790); } +WRAPPER RpAtomic* AtomicDefaultRenderCallBack(RpAtomic* atomic) { WRAPARG(atomic); EAXJMP(0x7491C0); } +WRAPPER RwImage* RtPNGImageRead(const RwChar* imageName) { WRAPARG(imageName); EAXJMP(0x7CF9B0); } +WRAPPER RwTexture* RwTextureCreate(RwRaster* raster) { WRAPARG(raster); EAXJMP(0x7F37C0); } +WRAPPER RwRaster* RwRasterCreate(RwInt32 width, RwInt32 height, RwInt32 depth, RwInt32 flags) { WRAPARG(width); WRAPARG(height); WRAPARG(depth); WRAPARG(flags); EAXJMP(0x7FB230); } +WRAPPER RwRaster* RwRasterSetFromImage(RwRaster* raster, RwImage* image) { WRAPARG(raster); WRAPARG(image); EAXJMP(0x804290); } +WRAPPER RwBool RwImageDestroy(RwImage* image) { WRAPARG(image); EAXJMP(0x802740); } +WRAPPER RwImage* RwImageFindRasterFormat(RwImage* ipImage, RwInt32 nRasterType, RwInt32* npWidth, RwInt32* npHeight, RwInt32* npDepth, RwInt32* npFormat) { WRAPARG(ipImage); WRAPARG(nRasterType); WRAPARG(npWidth); WRAPARG(npHeight); WRAPARG(npDepth); WRAPARG(npFormat); EAXJMP(0x8042C0); } +WRAPPER RpMaterial *RpMaterialSetTexture(RpMaterial *material, RwTexture *texture) { EAXJMP(0x74DBC0); } +WRAPPER RwBool RwTextureDestroy(RwTexture* texture) { EAXJMP(0x7F3820); } +WRAPPER void RwD3D9SetRenderState(RwUInt32 state, RwUInt32 value) { WRAPARG(state); WRAPARG(value); EAXJMP(0x7FC2D0); } +WRAPPER void _rwD3D9SetVertexShader(void *shader) { EAXJMP(0x7F9FB0); } +WRAPPER RwBool RwD3D9CreateVertexShader(const RwUInt32 *function, void **shader) { EAXJMP(0x7FAC60); } +WRAPPER void RwD3D9DeleteVertexShader(void *shader) { EAXJMP(0x7FAC90); } +WRAPPER void _rwD3D9VSGetComposedTransformMatrix(void *transformMatrix) { EAXJMP(0x7646E0); } +WRAPPER void _rwD3D9VSSetActiveWorldMatrix(const RwMatrix *worldMatrix) { EAXJMP(0x764650); } +WRAPPER RwMatrix* RwFrameGetLTM(RwFrame* frame) { EAXJMP(0x7F0990); } +WRAPPER void _rwD3D9SetVertexShaderConstant(RwUInt32 registerAddress, + const void *constantData, + RwUInt32 constantCount) { EAXJMP(0x7FACA0); } + +WRAPPER RwBool _rpD3D9VertexDeclarationInstColor(RwUInt8 *mem, + const RwRGBA *color, + RwInt32 numVerts, + RwUInt32 stride) { EAXJMP(0x754AE0); } + +// Other wrappers +void (*GTAdelete)(void*) = AddressByVersion(0x82413F, 0, 0); +auto SetVolume = AddressByVersion(0x4D7C60, 0, 0); +auto InitializeUtrax = AddressByVersion(0x4F35B0, 0, 0); +auto CanSeeOutSideFromCurrArea = AddressByVersion(0x53C4A0, 0, 0); + +auto __rwD3D9TextureHasAlpha = AddressByVersion(0x4C9EA0, 0, 0); +auto GetFrameNodeName = AddressByVersion(0x72FB30, 0, 0); +auto RenderOneXLUSprite = AddressByVersion(0x70D000, 0, 0); + +// That function is fake +auto RenderWeaponHooked = AddressByVersion(0x732F95, 0, 0); + +static BOOL (*IsAlreadyRunning)(); +static void (*TheScriptsLoad)(); +static bool (*InitialiseRenderWare)(); +static void (*ShutdownRenderWare)(); +static void (*sub_5DA6A0)(void*, void*, void*, void*); + + +// SA variables +void** rwengine = *AddressByVersion(0x58FFC0, 0, 0); +signed int& ms_extraVertColourPluginOffset = **AddressByVersion(0x5D6362, 0, 0); + +unsigned char& nGameClockDays = **AddressByVersion(0x4E841D, 0, 0); +unsigned char& nGameClockMonths = **AddressByVersion(0x4E842D, 0, 0); +void*& pUserTracksStuff = **AddressByVersion(0x4D9B7B, 0, 0); +bool& CCutsceneMgr__ms_running = **AddressByVersion(0x53F92D, 0, 0); +unsigned char* ScriptSpace = *AddressByVersion(0x5D5380, 0, 0); +int* ScriptParams = *AddressByVersion(0x48995B, 0, 0); + +float& fFarClipZ = **AddressByVersion(0x70D21F, 0, 0); +RwTexture** const gpCoronaTexture = *AddressByVersion(0x6FAA8C, 0, 0); +int& MoonSize = **AddressByVersion(0x713B0C, 0, 0); + +CZoneInfo*& pCurrZoneInfo = **AddressByVersion(0x58ADB1, 0, 0); +CRGBA* HudColour = *AddressByVersion(0x58ADF6, 0, 0); +unsigned char* ZonesVisited = *AddressByVersion(0x57216A, 0, 0) - 9; + +CLinkListSA& ms_weaponPedsForPC = **AddressByVersion**>(0x53EACA, 0, 0); +CLinkListSA& m_alphaList = **AddressByVersion**>(0x733A4D, 0, 0); + + +// Custom variables +static RwTexture* gpMoonMask = nullptr; +static HMODULE hDLLModule; +static struct +{ + char Extension[8]; + unsigned int Codec; +} UserTrackExtensions[] = { { ".ogg", DECODER_VORBIS }, { ".mp3", DECODER_QUICKTIME }, + { ".wav", DECODER_WAVE }, { ".wma", DECODER_WINDOWSMEDIA }, + { ".wmv", DECODER_WINDOWSMEDIA }, { ".aac", DECODER_QUICKTIME }, + { ".m4a", DECODER_QUICKTIME }, { ".mov", DECODER_QUICKTIME }, + { ".fla", DECODER_FLAC }, { ".flac", DECODER_FLAC } }; + +// lunar.png +static const BYTE gMoonMaskPNG[] = { + 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, + 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, + 0x08, 0x06, 0x00, 0x00, 0x00, 0xAA, 0x69, 0x71, 0xDE, 0x00, 0x00, 0x03, + 0xC1, 0x49, 0x44, 0x41, 0x54, 0x78, 0xDA, 0xED, 0x9B, 0xD7, 0x6B, 0x54, + 0x51, 0x10, 0xC6, 0x27, 0x96, 0x68, 0xEC, 0xA2, 0x41, 0x09, 0x16, 0xAC, + 0x60, 0x50, 0x51, 0xAC, 0xB1, 0xF7, 0x8A, 0x3E, 0xC4, 0x06, 0xBE, 0x08, + 0x3E, 0xE8, 0x83, 0x82, 0xE8, 0x1F, 0xA2, 0x08, 0xFA, 0xA0, 0x0F, 0x82, + 0x2F, 0x82, 0xF5, 0xC1, 0x10, 0x7B, 0x8F, 0x5D, 0x83, 0xA2, 0xA2, 0x60, + 0xC5, 0x42, 0x50, 0x54, 0xEC, 0xC6, 0x12, 0xCB, 0xF7, 0x31, 0xB3, 0x70, + 0x73, 0xD9, 0x9B, 0xCD, 0x66, 0xDB, 0xBD, 0x39, 0xFB, 0xC1, 0x8F, 0x90, + 0x6C, 0x58, 0x76, 0xBE, 0x33, 0x67, 0x66, 0xCE, 0xDD, 0x7B, 0x0B, 0xC4, + 0x71, 0x15, 0xE4, 0xFA, 0x03, 0xE4, 0x5A, 0xD9, 0x30, 0xA0, 0x15, 0xE8, + 0x06, 0x3A, 0x83, 0x8E, 0xA0, 0x1D, 0x68, 0x0B, 0x0A, 0x41, 0x0B, 0xFB, + 0x9F, 0xBF, 0xE0, 0x17, 0xF8, 0x01, 0xBE, 0x83, 0x2F, 0xE0, 0x13, 0x78, + 0x0F, 0xEA, 0xA2, 0x68, 0x40, 0x11, 0x28, 0x01, 0x3D, 0x41, 0x77, 0xD0, + 0x05, 0x74, 0x00, 0xED, 0xED, 0xB5, 0x42, 0x33, 0xA6, 0xA5, 0xFD, 0xFF, + 0x1F, 0x0B, 0x94, 0x26, 0xD4, 0x82, 0x6F, 0xE0, 0x2B, 0xF8, 0x08, 0xDE, + 0x81, 0xD7, 0xA0, 0xC6, 0x5E, 0x0B, 0xB5, 0x01, 0x3D, 0x40, 0x5F, 0xD0, + 0x0B, 0x14, 0x8B, 0xAE, 0x7C, 0x57, 0xD0, 0xDB, 0xCC, 0x28, 0xF6, 0x98, + 0x51, 0x64, 0x26, 0x88, 0x05, 0x5F, 0xEB, 0x09, 0xFA, 0xAD, 0x05, 0xFD, + 0x12, 0x7C, 0x10, 0xCD, 0x04, 0xFE, 0xED, 0x15, 0x78, 0x0E, 0xDE, 0x84, + 0xCD, 0x00, 0x06, 0x3E, 0xD0, 0x82, 0x2F, 0xB1, 0xDF, 0x87, 0x80, 0x41, + 0xA0, 0x1F, 0x68, 0xDD, 0xC4, 0xF7, 0xFD, 0x0D, 0x9E, 0x81, 0x47, 0xE0, + 0x81, 0x05, 0x5E, 0x63, 0x26, 0x3C, 0x4E, 0x87, 0x11, 0xA9, 0x1A, 0xC0, + 0x55, 0x2C, 0xB5, 0x40, 0xFB, 0x58, 0xB0, 0x23, 0xC1, 0x70, 0x7B, 0x2D, + 0x9D, 0x62, 0x86, 0xDC, 0x01, 0xB7, 0xCC, 0x94, 0x17, 0x66, 0xCC, 0x7D, + 0x49, 0x61, 0x6B, 0xA4, 0x62, 0x00, 0x03, 0x1E, 0x06, 0xFA, 0x1B, 0x65, + 0x60, 0x6C, 0x8A, 0xEF, 0xD9, 0x18, 0xFD, 0x03, 0xD7, 0xC1, 0x15, 0xF0, + 0xD4, 0xB8, 0x6B, 0x86, 0x64, 0xCD, 0x00, 0xAE, 0xF0, 0x50, 0xD1, 0x95, + 0x1F, 0x03, 0x26, 0x83, 0x4E, 0x19, 0x0E, 0xDC, 0xAF, 0xCF, 0xA0, 0x0A, + 0xDC, 0x10, 0xCD, 0x84, 0x7B, 0xA2, 0x19, 0x92, 0x51, 0x03, 0x58, 0xB4, + 0x46, 0x8B, 0xAE, 0xFC, 0x60, 0x30, 0xC7, 0xCC, 0xC8, 0xA5, 0x18, 0xF4, + 0x09, 0xF0, 0x50, 0x34, 0x13, 0x6E, 0x4A, 0x12, 0xAD, 0x33, 0x19, 0x03, + 0xDA, 0x88, 0xA6, 0x38, 0x03, 0x1E, 0x01, 0x16, 0x88, 0x16, 0xBC, 0x30, + 0x88, 0x85, 0xF1, 0x08, 0xB8, 0x6D, 0x86, 0x70, 0x8B, 0xFC, 0x4C, 0xA7, + 0x01, 0x5C, 0xF9, 0x32, 0x0B, 0x9C, 0x26, 0x2C, 0x96, 0xEC, 0xA7, 0x7C, + 0x22, 0x71, 0x4B, 0x1C, 0xB6, 0xE0, 0x69, 0x04, 0x6B, 0x44, 0xC2, 0x4C, + 0x68, 0xAC, 0x01, 0xE3, 0xC1, 0x28, 0xFB, 0xB9, 0x44, 0xD2, 0x5F, 0xE1, + 0xD3, 0x25, 0x76, 0x83, 0x83, 0xE0, 0x2A, 0xA8, 0xB6, 0x9F, 0x29, 0x1B, + 0xC0, 0x94, 0x1F, 0x27, 0xBA, 0xF2, 0xCB, 0x25, 0x7C, 0x2B, 0xEF, 0x17, + 0x33, 0x61, 0x9F, 0x68, 0x26, 0x5C, 0x93, 0x04, 0x85, 0x31, 0x91, 0x01, + 0x6C, 0x75, 0x93, 0x44, 0x7B, 0xFB, 0x4A, 0x09, 0xCF, 0x9E, 0x4F, 0x24, + 0xD6, 0x84, 0x3D, 0xA2, 0x33, 0xC3, 0x45, 0x69, 0xA0, 0x45, 0x36, 0x64, + 0x00, 0xD3, 0x7C, 0x86, 0x68, 0xD5, 0x2F, 0x97, 0xDC, 0x57, 0xFB, 0x64, + 0xC5, 0x95, 0x3F, 0x24, 0xDA, 0x15, 0xCE, 0x48, 0xC0, 0xB0, 0xD4, 0x90, + 0x01, 0xDC, 0xF3, 0x13, 0xC0, 0x5C, 0xB0, 0x30, 0xD7, 0xD1, 0x34, 0x51, + 0x95, 0xE0, 0x38, 0xB8, 0x2C, 0x5A, 0x13, 0x1A, 0x6D, 0x00, 0x67, 0xF9, + 0xE9, 0xA2, 0x7B, 0x7F, 0xB5, 0x84, 0x7F, 0xDF, 0x07, 0x89, 0xF5, 0x60, + 0x97, 0x68, 0x2D, 0x38, 0x2B, 0x71, 0xCE, 0x0E, 0x41, 0x06, 0x4C, 0x34, + 0xCA, 0xCD, 0x84, 0x28, 0x8B, 0xC1, 0x73, 0x2B, 0x5C, 0x32, 0x12, 0x1A, + 0xC0, 0xD5, 0x9F, 0x29, 0x3A, 0xDE, 0xAE, 0x95, 0xE8, 0x5F, 0x35, 0xE2, + 0xD9, 0x61, 0x87, 0xE8, 0xD8, 0x7C, 0x5A, 0x7C, 0x59, 0x10, 0x2F, 0x38, + 0xB6, 0xBB, 0x29, 0x60, 0xA9, 0x44, 0x7F, 0xF5, 0x63, 0x62, 0x16, 0x1C, + 0x00, 0x17, 0x44, 0xDB, 0x63, 0xA0, 0x01, 0xAC, 0xFC, 0xF3, 0x45, 0xA7, + 0xBE, 0x75, 0x12, 0xDE, 0x81, 0x27, 0x59, 0xB1, 0x03, 0x6C, 0x17, 0x9D, + 0x0E, 0x8F, 0x8A, 0xA7, 0x23, 0xF8, 0x0D, 0x18, 0x00, 0x66, 0x81, 0x45, + 0x12, 0xDD, 0xCA, 0x1F, 0x24, 0x76, 0x84, 0x0A, 0x70, 0x0A, 0x3C, 0x09, + 0x32, 0x80, 0x85, 0x6F, 0x2A, 0x58, 0x25, 0x7A, 0xDA, 0x6B, 0x4E, 0xE2, + 0x69, 0x71, 0x37, 0x38, 0x2F, 0x9E, 0x62, 0xE8, 0x35, 0x80, 0x07, 0x1E, + 0xAE, 0x3A, 0x27, 0xBF, 0x0D, 0xD2, 0xF4, 0xCB, 0x58, 0x61, 0x15, 0x2F, + 0xAF, 0x6D, 0x15, 0x9D, 0x0C, 0x99, 0x0D, 0x75, 0x7E, 0x03, 0x58, 0xFD, + 0xE7, 0x89, 0xD6, 0x80, 0x15, 0xB9, 0xFE, 0xB4, 0x19, 0xD2, 0x5E, 0xD1, + 0x1A, 0x70, 0x4C, 0xAC, 0x1B, 0x78, 0x0D, 0x60, 0xCA, 0xCF, 0x06, 0xCB, + 0x44, 0xB7, 0x41, 0x73, 0x14, 0xD3, 0x7F, 0x3F, 0x38, 0x29, 0xBA, 0x25, + 0xEA, 0x19, 0xC0, 0xD1, 0x97, 0xFD, 0x9F, 0xFB, 0xBF, 0x34, 0xD7, 0x9F, + 0x34, 0x43, 0xE2, 0x05, 0x54, 0xD6, 0x01, 0xCE, 0x03, 0xD5, 0x7E, 0x03, + 0x38, 0xF8, 0xF0, 0xF0, 0xB3, 0x46, 0xA2, 0x73, 0xEA, 0x4B, 0x56, 0x3C, + 0x25, 0xEE, 0x14, 0x3D, 0x1C, 0x55, 0xF9, 0x0D, 0x60, 0xFA, 0x4F, 0x03, + 0xEB, 0x25, 0xBA, 0xB3, 0x7F, 0x22, 0xF1, 0x6C, 0xB0, 0x0D, 0x9C, 0x13, + 0xDD, 0x06, 0xF5, 0x0C, 0x60, 0x07, 0xE0, 0x04, 0xB8, 0x51, 0x9A, 0x5F, + 0x07, 0x88, 0x89, 0x9D, 0x60, 0x8B, 0xE8, 0x44, 0x58, 0xE9, 0x37, 0x80, + 0xC3, 0x0F, 0x8B, 0xDF, 0x26, 0x89, 0xFE, 0xFC, 0x1F, 0x24, 0x9E, 0x0B, + 0x36, 0x8B, 0x16, 0xC3, 0x8A, 0xBC, 0x01, 0x92, 0xDF, 0x02, 0xF9, 0x22, + 0x98, 0x6F, 0x83, 0x9E, 0x17, 0x9D, 0x1F, 0x84, 0x9C, 0x1F, 0x85, 0x9D, + 0x3F, 0x0C, 0x39, 0x7F, 0x1C, 0xA6, 0x9C, 0xBE, 0x20, 0x42, 0x39, 0x7F, + 0x49, 0xCC, 0xF9, 0x8B, 0xA2, 0x94, 0xD3, 0x97, 0xC5, 0x29, 0xE7, 0xBF, + 0x18, 0xA1, 0x9C, 0xFE, 0x6A, 0x8C, 0x72, 0xFE, 0xCB, 0x51, 0xCA, 0xE9, + 0xAF, 0xC7, 0x29, 0xE7, 0x6F, 0x90, 0xA0, 0x9C, 0xBE, 0x45, 0x26, 0x26, + 0xA7, 0x6F, 0x92, 0x8A, 0xC9, 0xE9, 0xDB, 0xE4, 0x28, 0xE7, 0x6F, 0x94, + 0xA4, 0x9C, 0xBE, 0x55, 0x36, 0x26, 0xA7, 0x6F, 0x96, 0xF6, 0xCA, 0xD9, + 0xDB, 0xE5, 0xBD, 0x72, 0xFA, 0x81, 0x89, 0x98, 0x9C, 0x7E, 0x64, 0xC6, + 0x2B, 0x67, 0x1F, 0x9A, 0x8A, 0x67, 0x84, 0x93, 0x8F, 0xCD, 0xF9, 0xE5, + 0xEC, 0x83, 0x93, 0xF1, 0xE4, 0xE4, 0xA3, 0xB3, 0x91, 0x91, 0xF3, 0x06, + 0xFC, 0x07, 0x2A, 0x0D, 0x50, 0x50, 0xCC, 0xB6, 0x51, 0x67, 0x00, 0x00, + 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82 +}; + + +// Regular functions +static RpMaterial* AlphaTest(RpMaterial* pMaterial, void* pData) +{ + if ( RpMaterialGetTexture(pMaterial) ) + { + if ( __rwD3D9TextureHasAlpha(RpMaterialGetTexture(pMaterial)) ) + { + *static_cast(pData) = TRUE; + return nullptr; + } + } + else if ( RpMaterialGetColor(pMaterial)->alpha < 255 ) + { + *static_cast(pData) = TRUE; + return nullptr; + } + + return pMaterial; +} + +static RpAtomic* RenderAtomic(RpAtomic* pAtomic, float fComp) +{ + UNREFERENCED_PARAMETER(fComp); + return AtomicDefaultRenderCallBack(pAtomic); +} + +RpAtomic* OnePassAlphaRender(RpAtomic* atomic) +{ + BOOL nAlphaBlending; + + RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); + + if ( nAlphaBlending != TRUE ) + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); + auto* pAtomic = AtomicDefaultRenderCallBack(atomic); + + if ( nAlphaBlending != TRUE ) + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); + + return pAtomic; +} + +RpAtomic* TwoPassAlphaRender(RpAtomic* atomic) +{ + // For cutscenes, fall back to one-pass render + if ( CCutsceneMgr__ms_running && !CanSeeOutSideFromCurrArea() ) + return OnePassAlphaRender(atomic); + + int nPushedAlpha, nAlphaFunction; + int nZWrite; + int nAlphaBlending; + + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); + RwRenderStateGet(rwRENDERSTATEZWRITEENABLE, &nZWrite); + RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); + + // 1st pass + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, FALSE); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(255)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONEQUAL)); + + auto* pAtomic = AtomicDefaultRenderCallBack(atomic); + + // 2nd pass + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); + + AtomicDefaultRenderCallBack(atomic); + + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); + + return pAtomic; +} + +RpAtomic* StaticPropellerRender(RpAtomic* pAtomic) +{ + int nPushedAlpha; + + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); + + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0); + auto* pReturnAtomic = AtomicDefaultRenderCallBack(pAtomic); + + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); + return pReturnAtomic; +} + +RpAtomic* RenderBigVehicleActomic(RpAtomic* pAtomic, float fComp) +{ + UNREFERENCED_PARAMETER(fComp); + + const char* pNodeName = GetFrameNodeName(RpAtomicGetFrame(pAtomic)); + + if ( !strncmp(pNodeName, "moving_prop", 11) ) + return TwoPassAlphaRender(pAtomic); + + if ( !strncmp(pNodeName, "static_prop", 11) ) + return StaticPropellerRender(pAtomic); + + return AtomicDefaultRenderCallBack(pAtomic); +} + +void RenderVehicleHiDetailAlphaCB_HunterDoor(RpAtomic* pAtomic) +{ + AlphaObjectInfo NewObject; + + NewObject.callback = RenderAtomic; + NewObject.fCompareValue = -std::numeric_limits::infinity(); + NewObject.pAtomic = pAtomic; + + m_alphaList.InsertSorted(NewObject); +} + +template +void SetRendererForAtomic(RpAtomic* pAtomic) +{ + BOOL bHasAlpha = FALSE; + + RpGeometryForAllMaterials(RpAtomicGetGeometry(pAtomic), AlphaTest, &bHasAlpha); + if ( bHasAlpha ) + RpAtomicSetRenderCallBack(pAtomic, renderer); +} + +void RenderWeapon(CEntity* pEntity) +{ + int nPushedAlpha, nAlphaFunction; + + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); + + if ( nPushedAlpha != 255 ) + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(255)); + + if ( nAlphaFunction != rwALPHATESTFUNCTIONEQUAL ) + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONEQUAL)); + + RenderWeaponHooked(pEntity); + + if ( nPushedAlpha != 255 ) + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); + + if ( nAlphaFunction != rwALPHATESTFUNCTIONEQUAL ) + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); + + ms_weaponPedsForPC.Insert(pEntity); +} + +void RenderWeaponsList() +{ + int nPushedAlpha, nAlphaFunction; + int nZWrite; + int nAlphaBlending; + + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); + RwRenderStateGet(rwRENDERSTATEZWRITEENABLE, &nZWrite); + RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); + + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(255)); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); + + for ( auto i = ms_weaponPedsForPC.m_lnListHead.m_pNext; i != &ms_weaponPedsForPC.m_lnListTail; i = i->m_pNext ) + { + i->V()->SetupLighting(); + RenderWeaponHooked(i->V()); + i->V()->RemoveLighting(); + } + + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); +} + +RpAtomic* RenderPedCB(RpAtomic* pAtomic) +{ + BOOL bHasAlpha = FALSE; + + RpGeometryForAllMaterials(RpAtomicGetGeometry(pAtomic), AlphaTest, &bHasAlpha); + if ( bHasAlpha ) + return TwoPassAlphaRender(pAtomic); + + return AtomicDefaultRenderCallBack(pAtomic); +} + +static CAEFLACDecoder* __stdcall DecoderCtor(CAEDataStream* pData) +{ + return new CAEFLACDecoder(pData); +} + +static CAEWaveDecoder* __stdcall CAEWaveDecoderInit(CAEDataStream* pStream) +{ + return new CAEWaveDecoder(pStream); +} + +static void BasketballFix(unsigned char* pBuf, int nSize) +{ + for ( int i = 0, hits = 0; i < nSize && hits < 7; i++, pBuf++ ) + { + // Pattern check for save pickup XYZ + if ( *(unsigned int*)pBuf == 0x449DE19A ) // Save pickup X + { + hits++; + *(float*)pBuf = 1291.8f; + } + else if ( *(unsigned int*)pBuf == 0xC4416AE1 ) // Save pickup Y + { + hits++; + *(float*)pBuf = -797.8284f; + } + else if ( *(unsigned int*)pBuf == 0x44886C7B ) // Save pickup Z + { + hits++; + *(float*)pBuf = 1089.5f; + } + else if ( *(unsigned int*)pBuf == 0x449DF852 ) // Save point X + { + hits++; + *(float*)pBuf = 1286.8f; + } + else if ( *(unsigned int*)pBuf == 0xC44225C3 ) // Save point Y + { + hits++; + *(float*)pBuf = -797.69f; + } + else if ( *(unsigned int*)pBuf == 0x44885C7B ) // Save point Z + { + hits++; + *(float*)pBuf = 1089.1f; + } + else if ( *(unsigned int*)pBuf == 0x43373AE1 ) // Save point A + { + hits++; + *(float*)pBuf = 90.0f; + } + } +} + +void TheScriptsLoad_BasketballFix() +{ + TheScriptsLoad(); + + BasketballFix(ScriptSpace+8, *(int*)(ScriptSpace+3)); +} + +void StartNewMission_BasketballFix() +{ + if ( ScriptParams[0] == 0 ) + BasketballFix(ScriptSpace+200000, 69000); +} + +bool GetCurrentZoneLockedOrUnlocked(float fPosX, float fPosY) +{ + int Xindex = (fPosX+3000.0f) * (1.0f/600.0f); + int Yindex = (fPosY+3000.0f) * (1.0f/600.0f); + + // "Territories fix" + if ( (Xindex >= 0 && Xindex < 10) && (Yindex >= 0 && Yindex < 10) ) + return ZonesVisited[10*Xindex - Yindex + 9] != 0; + + // Outside of map bounds + return true; +} + +// By NTAuthority +void DrawMoonWithPhases(int moonColor, float* screenPos, float sizeX, float sizeY) +{ + if ( !gpMoonMask ) + gpMoonMask = CPNGFile::ReadFromMemory(gMoonMaskPNG, sizeof(gMoonMaskPNG)); + //D3DPERF_BeginEvent(D3DCOLOR_ARGB(0,0,0,0), L"render moon"); + + float currentDayFraction = nGameClockDays / 31.0f; + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nullptr); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + + float a10 = 1.0f / fFarClipZ; + float size = (MoonSize * 2) + 4.0f; + + RwD3D9SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA); + + RenderOneXLUSprite(screenPos[0], screenPos[1], fFarClipZ, sizeX * size, sizeY * size, 0, 0, 0, 0, a10, -1, 0, 0); + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpMoonMask)); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDINVSRCCOLOR); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCCOLOR); + + float maskX = (sizeX * size) * 5.4f * (currentDayFraction - 0.5f) + screenPos[0]; + float maskY = screenPos[1] + ((sizeY * size) * 0.7f); + + RenderOneXLUSprite(maskX, maskY, fFarClipZ, sizeX * size * 1.7f, sizeY * size * 1.7f, 0, 0, 0, 255, a10, -1, 0, 0); + + RwD3D9SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED); + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[2])); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDDESTALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, 0); + + RenderOneXLUSprite(screenPos[0], screenPos[1], fFarClipZ, sizeX * size, sizeY * size, moonColor, moonColor, moonColor * 0.85f, 255, a10, -1, 0, 0); + + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + + //D3DPERF_EndEvent(); +} + +CRGBA* CRGBA::BlendGangColour(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + *this = Blend(CRGBA(r, g, b), pCurrZoneInfo->ZoneColour.a, HudColour[3], static_cast(255-pCurrZoneInfo->ZoneColour.a)); + this->a = a; + + return this; +} + +#include "nvc.h" + +static IDirect3DVertexShader9* pNVCShader = nullptr; +static bool bRenderNVC = false; +static RpAtomic* pRenderedAtomic; + +bool ShaderAttach() +{ + // CGame::InitialiseRenderWare + if ( InitialiseRenderWare() ) + { + RwD3D9CreateVertexShader(reinterpret_cast(g_vs20_NVC_vertex_shader), reinterpret_cast(&pNVCShader)); + return true; + } + return false; +} + +void ShaderDetach() +{ + if ( pNVCShader ) + RwD3D9DeleteVertexShader(pNVCShader); + + // PluginDetach? + ShutdownRenderWare(); +} + +void SetShader(RxD3D9InstanceData* pInstData) +{ + if ( bRenderNVC ) + { + // TODO: Daynight balance var + D3DMATRIX outMat; + float fEnvVars[2] = { *(float*)0x8D12C0, RpMaterialGetColor(pInstData->material)->alpha * (1.0f/255.0f) }; + RwRGBAReal* AmbientLight = RpLightGetColor(*(RpLight**)0xC886E8); + + // 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))); + _rwD3D9VSGetComposedTransformMatrix(&outMat); + + RwD3D9SetVertexShaderConstant(0, &outMat, 4); + RwD3D9SetVertexShaderConstant(4, fEnvVars, 1); + RwD3D9SetVertexShaderConstant(5, AmbientLight, 1); + } + else + RwD3D9SetVertexShader(pInstData->vertexShader); +} + +static void* HijackAtomic_JumpBack = AddressByVersion(0x5D6480, 0, 0); +void __declspec(naked) HijackAtomic() +{ + _asm + { + mov eax, [esp+8] + mov pRenderedAtomic, eax + jmp HijackAtomic_JumpBack + } +} + +void __declspec(naked) SetShader2() +{ + _asm + { + mov bRenderNVC, 1 + push ecx + push edx + push edi + push ebp + call sub_5DA6A0 + add esp, 10h + mov bRenderNVC, 0 + retn + } +} + +static void* pJackedEsi; +static void* PassDayColoursToShader_NextIt = AddressByVersion(0x5D6382, 0, 0); +static void* PassDayColoursToShader_Return = AddressByVersion(0x5D63BD, 0, 0); +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 + } +} + +// Hooks +void __declspec(naked) LightMaterialsFix() +{ + _asm + { + mov [esi], edi + mov ebx, [ecx] + lea esi, [edx+4] + mov [ebx+4], esi + mov edi, [esi] + mov [ebx+8], edi + add esi, 4 + mov [ebx+12], esi + mov edi, [esi] + mov [ebx+16], edi + add ebx, 20 + mov [ecx], ebx + retn + } +} + +void __declspec(naked) UserTracksFix() +{ + _asm + { + push [esp+4] + call SetVolume + mov ecx, [pUserTracksStuff] + call InitializeUtrax + retn 4 + } +} + +static void* UsageIndex1_JumpBack = AddressByVersion(0x5D611B, 0, 0); +void __declspec(naked) UsageIndex1() +{ + _asm + { + mov byte ptr [esp+eax*8+27h], 1 + inc eax + + jmp UsageIndex1_JumpBack + } +} + +void __declspec(naked) ResetAlphaFuncRefAfterRender() +{ + _asm + { + mov edx, [rwengine] + mov edx, [edx] + mov ecx, [esp+7Ch-74h] + push ecx + push rwRENDERSTATEALPHATESTFUNCTIONREF + call dword ptr [edx+20h] + add esp, 8 + pop edi + pop esi + add esp, 74h + retn + } +} + +static void* PlaneAtomicRendererSetup_JumpBack = AddressByVersion(0x4C7986, 0, 0); +static void* RenderVehicleHiDetailAlphaCB_BigVehicle = AddressByVersion(0x734370, 0, 0); +static void* RenderVehicleHiDetailCB_BigVehicle = AddressByVersion(0x733420, 0, 0); +void __declspec(naked) PlaneAtomicRendererSetup() +{ + static const char aStaticProp[] = "static_prop"; + static const char aMovingProp[] = "moving_prop"; + _asm + { + mov eax, [esi+4] + push eax + call GetFrameNodeName + //push eax + mov [esp+8+8], eax + push 11 + push offset aStaticProp + push eax + call strncmp + add esp, 10h + test eax, eax + jz PlaneAtomicRendererSetup_Alpha + push 11 + push offset aMovingProp + push [esp+12+8] + call strncmp + add esp, 0Ch + test eax, eax + jnz PlaneAtomicRendererSetup_NoAlpha + +PlaneAtomicRendererSetup_Alpha: + push [RenderVehicleHiDetailAlphaCB_BigVehicle] + jmp PlaneAtomicRendererSetup_Return + +PlaneAtomicRendererSetup_NoAlpha: + push [RenderVehicleHiDetailCB_BigVehicle] + +PlaneAtomicRendererSetup_Return: + jmp PlaneAtomicRendererSetup_JumpBack + } +} + +static unsigned int nCachedCRC; + +static void* RenderVehicleHiDetailCB = AddressByVersion(0x733240, 0, 0); +static void* RenderVehicleHiDetailAlphaCB = AddressByVersion(0x733F80, 0, 0); +static void* RenderHeliRotorAlphaCB = AddressByVersion(0x7340B0, 0, 0); +static void* RenderHeliTailRotorAlphaCB = AddressByVersion(0x734170, 0, 0); +static void* HunterTest_JumpBack = AddressByVersion(0x4C7914, 0, 0); +void __declspec(naked) HunterTest() +{ + static const char aDoorDummy[] = "door_lf_ok"; + static const char aStaticRotor[] = "static_rotor"; + static const char aStaticRotor2[] = "static_rotor2"; + static const char aWindscreen[] = "windscreen"; + _asm + { + setnz al + movzx di, al + + push 10 + push offset aWindscreen + push ebp + call strncmp + add esp, 0Ch + test eax, eax + jz HunterTest_RegularAlpha + + push 13 + push offset aStaticRotor2 + push ebp + call strncmp + add esp, 0Ch + test eax, eax + jz HunterTest_StaticRotor2AlphaSet + + push 12 + push offset aStaticRotor + push ebp + call strncmp + add esp, 0Ch + test eax, eax + jz HunterTest_StaticRotorAlphaSet + + test di, di + jnz HunterTest_DoorTest + + push [RenderVehicleHiDetailCB] + jmp HunterTest_JumpBack + +HunterTest_DoorTest: + cmp nCachedCRC, 0x45D0B41C + jnz HunterTest_RegularAlpha + push 10 + push offset aDoorDummy + push ebp + call strncmp + add esp, 0Ch + test eax, eax + jnz HunterTest_RegularAlpha + push RenderVehicleHiDetailAlphaCB_HunterDoor + mov eax, 4C7914h + jmp eax + +HunterTest_RegularAlpha: + push [RenderVehicleHiDetailAlphaCB] + jmp HunterTest_JumpBack + +HunterTest_StaticRotorAlphaSet: + push [RenderHeliRotorAlphaCB] + jmp HunterTest_JumpBack + +HunterTest_StaticRotor2AlphaSet: + push [RenderHeliTailRotorAlphaCB] + jmp HunterTest_JumpBack + } +} + +static void* CacheCRC32_JumpBack = AddressByVersion(0x4C7B10, 0, 0); +void __declspec(naked) CacheCRC32() +{ + _asm + { + mov eax, [ecx+4] + mov nCachedCRC, eax + jmp CacheCRC32_JumpBack + } +} + +static void* LoadFLAC_JumpBack = AddressByVersion(0x4F3743, 0, 0); +void __declspec(naked) LoadFLAC() +{ + _asm + { + jz LoadFLAC_WindowsMedia + sub ebp, 2 + jnz LoadFLAC_Return + push esi + call DecoderCtor + jmp LoadFLAC_Success + +LoadFLAC_WindowsMedia: + jmp LoadFLAC_JumpBack + +LoadFLAC_Success: + test eax, eax + mov [esp+20h+4], eax + jnz LoadFLAC_Return_NoDelete + +LoadFLAC_Return: + mov ecx, esi + call CAEDataStream::~CAEDataStream + push esi + call GTAdelete + add esp, 4 + +LoadFLAC_Return_NoDelete: + mov eax, [esp+20h+4] + mov ecx, [esp+20h-0Ch] + pop esi + pop ebp + pop edi + pop ebx + mov fs:0, ecx + add esp, 10h + retn 4 + } +} + +void __declspec(naked) FLACInit() +{ + _asm + { + mov al, 1 + mov [esi+0Dh], al + pop esi + jnz FLACInit_DontFallBack + mov UserTrackExtensions+12.Codec, DECODER_WINDOWSMEDIA + +FLACInit_DontFallBack: + retn + } +} + +static void* HandleMoonStuffStub_JumpBack = AddressByVersion(0x713D24, 0, 0); +void __declspec(naked) HandleMoonStuffStub() +{ + __asm + { + mov eax, [esp + 78h - 64h] // screen x size + mov ecx, [esp + 78h - 68h] // screen y size + + push ecx + push eax + + lea ecx, [esp + 80h - 54h] // screen coord vector + + push ecx + + push esi + + call DrawMoonWithPhases + + add esp, 10h + + jmp HandleMoonStuffStub_JumpBack + } +} + +// 1.0 ONLY BEGINS HERE +static bool bDarkVehicleThing; +static RpLight*& pDirect = **(RpLight***)0x5BA573; + +void __declspec(naked) DarkVehiclesFix1() +{ + _asm + { + shr eax, 0Eh + test al, 1 + jz DarkVehiclesFix1_DontAppply + mov ecx, [pDirect] + mov ecx, [ecx] + mov al, [ecx+2] + test al, 1 + jnz DarkVehiclesFix1_DontAppply + mov bDarkVehicleThing, 1 + jmp DarkVehiclesFix1_Return + +DarkVehiclesFix1_DontAppply: + mov bDarkVehicleThing, 0 + +DarkVehiclesFix1_Return: + mov eax, 756D90h + jmp eax + } +} + +void __declspec(naked) DarkVehiclesFix2() +{ + _asm + { + jz DarkVehiclesFix2_MakeItDark + mov al, bDarkVehicleThing + test al, al + jnz DarkVehiclesFix2_MakeItDark + mov eax, 5D9A7Ah + jmp eax + +DarkVehiclesFix2_MakeItDark: + mov eax, 5D9B09h + jmp eax + } +} + +void __declspec(naked) DarkVehiclesFix3() +{ + _asm + { + jz DarkVehiclesFix3_MakeItDark + mov al, bDarkVehicleThing + test al, al + jnz DarkVehiclesFix3_MakeItDark + mov eax, 5D9B4Ah + jmp eax + +DarkVehiclesFix3_MakeItDark: + mov eax, 5D9CACh + jmp eax + } +} + +void __declspec(naked) DarkVehiclesFix4() +{ + _asm + { + jz DarkVehiclesFix4_MakeItDark + mov al, bDarkVehicleThing + test al, al + jnz DarkVehiclesFix4_MakeItDark + mov eax, 5D9CB8h + jmp eax + +DarkVehiclesFix4_MakeItDark: + mov eax, 5D9E0Dh + jmp eax + } +} +// 1.0 ONLY ENDS HERE + +static const float fSteamSubtitleSizeX = 0.45f; +static const float fSteamSubtitleSizeY = 0.9f; +static const float fSteamRadioNamePosY = 33.0f; +static const float fSteamRadioNameSizeX = 0.4f; +static const float fSteamRadioNameSizeY = 0.6f; + +BOOL InjectDelayedPatches_10() +{ + if ( !IsAlreadyRunning() ) + { + using namespace MemoryVP; + + // Obtain a path to the ASI + wchar_t wcModulePath[MAX_PATH]; + + GetModuleFileNameW(hDLLModule, wcModulePath, MAX_PATH); + + wchar_t* pSlash = wcsrchr(wcModulePath, '\\'); + if ( pSlash ) + { + *pSlash = '\0'; + PathAppendW(wcModulePath, L"SilentPatchSA.ini"); + } + else + { + // Should never happen - if it does, something's fucking up + return TRUE; + } + + bool bHasImVehFt = GetModuleHandle("ImVehFt.asi") != nullptr; + bool bSAMP = GetModuleHandle("samp") != nullptr; + + if ( GetPrivateProfileIntW(L"SilentPatch", L"TwoPassRendering", FALSE, wcModulePath) != FALSE ) + { + InjectHook(0x4C441F, SetRendererForAtomic, PATCH_CALL); + // Twopass for peds + InjectHook(0x733614, RenderPedCB); + } + else + { + InjectHook(0x4C441F, SetRendererForAtomic, PATCH_CALL); + } + + if ( GetPrivateProfileIntW(L"SilentPatch", L"EnableScriptFixes", TRUE, wcModulePath) != FALSE ) + { + // Gym glitch fix + Patch(0x470B03, 0xCD8B); + Patch(0x470B0A, 0x8B04508B); + Patch(0x470B0E, 0x9000); + Nop(0x470B10, 1); + InjectHook(0x470B05, &CRunningScript::GetDay_GymGlitch, PATCH_CALL); + + // Basketball fix + TheScriptsLoad = (void(*)())(*(int*)0x5D18F1 + 0x5D18F0 + 5); + InjectHook(0x5D18F0, TheScriptsLoad_BasketballFix); + InjectHook(0x464BC0, StartNewMission_BasketballFix, PATCH_JUMP); + } + + if ( !bSAMP && GetPrivateProfileIntW(L"SilentPatch", L"NVCShader", TRUE, wcModulePath) != FALSE ) + { + // Shaders! + // plugin-sdk compatibility + InitialiseRenderWare = (bool(*)())(*(int*)0x5BF3A2 + 0x5BF3A1 + 5); + ShutdownRenderWare = (void(*)())(*(int*)0x53D911 + 0x53D910 + 5); + sub_5DA6A0 = (void(*)(void*,void*,void*,void*))(*(int*)0x5D66F2 + 0x5D66F1 + 5); + + 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); + 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); + } + + if ( GetPrivateProfileIntW(L"SilentPatch", L"SkipIntroSplashes", TRUE, wcModulePath) != FALSE ) + { + // Skip the damn intro splash + Patch(0x748AA8, 0x3DEB); + } + + if ( GetPrivateProfileIntW(L"SilentPatch", L"SmallSteamTexts", TRUE, wcModulePath) != FALSE ) + { + // We're on 1.0 - make texts smaller + Patch(0x58C387, &fSteamSubtitleSizeY); + Patch(0x58C40F, &fSteamSubtitleSizeY); + Patch(0x58C4CE, &fSteamSubtitleSizeY); + + Patch(0x58C39D, &fSteamSubtitleSizeX); + Patch(0x58C425, &fSteamSubtitleSizeX); + Patch(0x58C4E4, &fSteamSubtitleSizeX); + + Patch(0x4E9FD8, &fSteamRadioNamePosY); + Patch(0x4E9F22, &fSteamRadioNameSizeY); + Patch(0x4E9F38, &fSteamRadioNameSizeX); + } + + if ( GetPrivateProfileIntW(L"SilentPatch", L"ColouredZoneNames", FALSE, wcModulePath) != FALSE ) + { + // Coloured zone names + Patch(0x58ADBE, 0x0E75); + Patch(0x58ADC5, 0x0775); + + InjectHook(0x58ADE4, &CRGBA::BlendGangColour); + } + else + { + Patch(0x58ADAE, 0xEB); + } + + // ImVehFt conflicts + if ( !bHasImVehFt ) + { + // Lights + InjectHook(0x4C830C, LightMaterialsFix, PATCH_CALL); + + // Flying components + InjectHook(0x59F180, &CObject::Render_Stub, PATCH_JUMP); + + // Cars getting dirty + // Only 1.0 and Steam + InjectHook(0x4C9648, &CVehicleModelInfo::FindEditableMaterialList, PATCH_CALL); + Patch(0x4C964D, 0x0FEBCE8B); + Patch(0x5D5DC2, 32); // 1.0 ONLY + } + + if ( !bHasImVehFt && !bSAMP ) + { + // Properly random numberplates + DWORD* pVMT = *(DWORD**)0x4C75FC; + void* pFunc; + _asm + { + mov eax, offset CVehicleModelInfo::Shutdown + mov [pFunc], eax + } + Patch(&pVMT[7], pFunc); + Patch(0x6D0E43, 0xEB); + InjectHook(0x4C9660, &CVehicleModelInfo::SetCarCustomPlate); + InjectHook(0x6D6A58, &CVehicle::CustomCarPlate_TextureCreate); + InjectHook(0x6D651C, &CVehicle::CustomCarPlate_BeforeRenderingStart); + InjectHook(0x6FDFE0, CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade, PATCH_JUMP); + //InjectMethodVP(0x6D0E53, CVehicle::CustomCarPlate_AfterRenderingStop, PATCH_NOTHING); + Nop(0x6D6517, 2); + } + + return FALSE; + } + return TRUE; +} + +__forceinline void Patch_SA_10() +{ + using namespace MemoryVP; + + // IsAlreadyRunning needs to be read relatively late - the later, the better + IsAlreadyRunning = (BOOL(*)())(*(int*)0x74872E + 0x74872D + 5); + InjectHook(0x74872D, InjectDelayedPatches_10); + + //Patch(0x5D7265, 0xEB); + + + // Heli rotors + InjectHook(0x6CAB70, &CPlane::Render_Stub, PATCH_JUMP); + InjectHook(0x6C4400, &CHeli::Render_Stub, PATCH_JUMP); + //InjectHook(0x553318, RenderAlphaAtomics); + Patch(0x7341D9, TwoPassAlphaRender); + Patch(0x734127, TwoPassAlphaRender); + 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);*/ + + // RefFix + static const float fRefZVal = 1.0f; + static const float* const pRefFal = &fRefZVal; + + Patch(0x6FB97A, &pRefFal); + Patch(0x6FB9A0, 0); + + // Plane rotors + InjectHook(0x4C7981, PlaneAtomicRendererSetup, PATCH_JUMP); + + // DOUBLE_RWHEELS + Patch(0x4C9290, 0xE281); + Patch(0x4C9292, ~(rwMATRIXTYPEMASK|rwMATRIXINTERNALIDENTITY)); + + // No framedelay + Patch(0x53E923, 0x42EB56); + + // Disable re-initialization of DirectInput mouse device by the game + Patch(0x576CCC, 0xEB); + Patch(0x576EBA, 0xEB); + Patch(0x576F8A, 0xEB); + + // Make sure DirectInput mouse device is set non-exclusive (may not be needed?) + Patch(0x7469A0, 0x909000B0); + + // Weapons rendering + InjectHook(0x5E7859, RenderWeapon); + InjectHook(0x732F30, RenderWeaponsList, PATCH_JUMP); + //Patch(0x53EAC4, 0x0DEB); + //Patch(0x705322, 0x0DEB); + //Patch(0x7271E3, 0x0DEB); + //Patch(0x73314E, 0xC3); + Patch(0x732F95, 0x560CEC83); + Patch(0x732FA2, 0x20245C8B); + Patch(0x733128, 0x20EB); + Patch(0x733135, 0x13EB); + Nop(0x732FBC, 5); + //Nop(0x732F93, 6); + //Nop(0x733144, 6); + Nop(0x732FA6, 6); + //Nop(0x5E46DA, 2); + + // Hunter interior & static_rotor for helis + InjectHook(0x4C78F2, HunterTest, PATCH_JUMP); + InjectHook(0x4C9618, CacheCRC32); + + // Fixed blown up car rendering + // ONLY 1.0 + InjectHook(0x5D993F, DarkVehiclesFix1); + InjectHook(0x5D9A74, DarkVehiclesFix2, PATCH_JUMP); + InjectHook(0x5D9B44, DarkVehiclesFix3, PATCH_JUMP); + InjectHook(0x5D9CB2, DarkVehiclesFix4, PATCH_JUMP); + + // Bindable NUM5 + // Only 1.0 and Steam + Nop(0x57DC55, 2); + + // Moonphases + InjectHook(0x713ACB, HandleMoonStuffStub, PATCH_JUMP); + + // TEMP + //Patch(0x733B05, 40); + //Patch(0x733B55, 40); + //Patch(0x5B3ADD, 4); + + // Twopass rendering (experimental) + Patch(0x4C441E, 0x57); + //InjectHook(0x4C441F, SetRendererForAtomic, PATCH_CALL); + Patch(0x4C4424, 0x5F04C483); + Patch(0x4C4428, 0x0004C25E); + + // Lightbeam fix + Patch(0x6A2E88, 0x0EEB); + Nop(0x6A2E9C, 3); + Patch(0x6E0F63, 0x0AEB); + Patch(0x6E0F7C, 0x0BEB); + Patch(0x6E0F95, 0x0BEB); + Patch(0x6E0FAF, 0x1AEB); + + Patch(0x6E13D5, 0x09EB); + Patch(0x6E13ED, 0x17EB); + Patch(0x6E141F, 0x0AEB); + + Patch(0x6E0FE0, 0x28); + Patch(0x6E142D, 0x18); + Patch(0x6E0FDB, 0xC8-0x7C); + //InjectHook(0x6A2EDA, CullTest); + + InjectHook(0x6A2EF7, ResetAlphaFuncRefAfterRender, PATCH_JUMP); + + // PS2 SUN!!!!!!!!!!!!!!!!! + static const float fSunMult = (1050.0f * 0.95f) / 1500.0f; + + Nop(0x6FB17C, 3); + Patch(0x6FC5B0, &fSunMult); + //Patch(0x6FB172, 0x0BEB); + //Patch(0x6FB1A7, 8); + +#if defined EXPAND_ALPHA_ENTITY_LISTS + // Bigger alpha entity lists + Patch(0x733B05, EXPAND_ALPHA_ENTITY_LISTS * 20); + Patch(0x733B55, EXPAND_ALPHA_ENTITY_LISTS * 20); +#endif + + // Unlocked widescreen resolutions + Patch(0x745B71, 0x9090687D); + Patch(0x74596C, 0x9090127D); + Nop(0x745970, 2); + Nop(0x745B75, 2); + Nop(0x7459E1, 2); + + // Heap corruption fix + Nop(0x5C25D3, 5); + + // User Tracks fix + InjectHook(0x4D9B66, UserTracksFix); + InjectHook(0x4D9BB5, 0x4F2FD0); + //Nop(0x4D9BB5, 5); + + // FLAC support + InjectHook(0x4F373D, LoadFLAC, PATCH_JUMP); + InjectHook(0x4F35E0, FLACInit, PATCH_JUMP); + InjectHook(0x4F3787, CAEWaveDecoderInit); + + Patch(0x4F376A, 0x18EB); + //Patch(0x4F378F, sizeof(CAEWaveDecoder)); + Patch(0x4F3210, UserTrackExtensions); + Patch(0x4F3241, &UserTrackExtensions->Codec); + //Patch(0x4F35E7, &UserTrackExtensions[1].Codec); + Patch(0x4F322D, sizeof(UserTrackExtensions)); + + // Impound garages working correctly + InjectHook(0x425179, 0x448990); + InjectHook(0x425369, 0x448990); + InjectHook(0x425411, 0x448990); + + // Impounding after busted works + Nop(0x443292, 5); + + // Zones fix + InjectHook(0x572130, GetCurrentZoneLockedOrUnlocked, PATCH_JUMP); + + // Fixed police scanner names + char* pScannerNames = *(char**)0x4E72D4; + strncpy(pScannerNames + (8*113), "WESTP", 8); + strncpy(pScannerNames + (8*134), "????", 8); + + // TEMP - dumping IPL data +#ifdef DO_MAP_DUMP + InjectHook(0x538090, DumpIPLStub, PATCH_JUMP); + InjectHook(0x5B92C7, DumpIPLName); +#endif +} + +__forceinline void Patch_SA_Steam() +{ + using namespace MemoryVP; + + //InjectHook(0x72F058, HandleMoonStuffStub_Steam, PATCH_JUMP); +} + + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + UNREFERENCED_PARAMETER(lpvReserved); + + if ( fdwReason == DLL_PROCESS_ATTACH ) + { + hDLLModule = hinstDLL; + + if (*(DWORD*)0x82457C == 0x94BF || *(DWORD*)0x8245BC == 0x94BF) Patch_SA_10(); + //else if (*(DWORD*)0x8252FC == 0x94BF || *(DWORD*)0x82533C == 0x94BF) Patch_SA_11(); + else if (*(DWORD*)0x85EC4A == 0x94BF) Patch_SA_Steam(); + else return FALSE; + } + return TRUE; +} \ No newline at end of file diff --git a/SAFix/StdAfxSA.cpp b/SAFix/StdAfxSA.cpp new file mode 100644 index 0000000..fd76746 --- /dev/null +++ b/SAFix/StdAfxSA.cpp @@ -0,0 +1 @@ +#include "StdAfxSA.h" \ No newline at end of file diff --git a/SilentPatch/StdAfx.h b/SAFix/StdAfxSA.h similarity index 73% rename from SilentPatch/StdAfx.h rename to SAFix/StdAfxSA.h index 91af79e..91089ae 100644 --- a/SilentPatch/StdAfx.h +++ b/SAFix/StdAfxSA.h @@ -11,12 +11,18 @@ #define _WIN32_WINNT 0x0500 #include +#include +#include +#include +#include + +/*#include #include #include #include #include #include -#include +#include */ #define RwEngineInstance (*rwengine) #define RWFRAMESTATICPLUGINSSIZE 24 @@ -25,11 +31,23 @@ #include #include +#include + #include "MemoryMgr.h" #include "Maths.h" +struct AlphaObjectInfo +{ + RpAtomic* pAtomic; + RpAtomic* (*callback)(RpAtomic*, float); + float fCompareValue; + + friend bool operator < (const AlphaObjectInfo &a, const AlphaObjectInfo &b) + { return a.fCompareValue < b.fCompareValue; } +}; + // SA operator delete -void GTAdelete(void* data); +extern void (*GTAdelete)(void* data); extern unsigned char& nGameClockDays; extern unsigned char& nGameClockMonths; diff --git a/SAFix/TimerSA.cpp b/SAFix/TimerSA.cpp new file mode 100644 index 0000000..f0accef --- /dev/null +++ b/SAFix/TimerSA.cpp @@ -0,0 +1,4 @@ +#include "StdAfxSA.h" +#include "TimerSA.h" + +int& CTimer::m_snTimeInMilliseconds = **AddressByVersion(0x4242D1, 0, 0); \ No newline at end of file diff --git a/SAFix/TimerSA.h b/SAFix/TimerSA.h new file mode 100644 index 0000000..3ca2360 --- /dev/null +++ b/SAFix/TimerSA.h @@ -0,0 +1,10 @@ +#ifndef __TIMERSA +#define __TIMERSA + +class CTimer +{ +public: + static int& m_snTimeInMilliseconds; +}; + +#endif \ No newline at end of file diff --git a/SilentPatch/Vehicle.cpp b/SAFix/VehicleSA.cpp similarity index 96% rename from SilentPatch/Vehicle.cpp rename to SAFix/VehicleSA.cpp index 6010831..3ab4c18 100644 --- a/SilentPatch/Vehicle.cpp +++ b/SAFix/VehicleSA.cpp @@ -1,7 +1,7 @@ -#include "StdAfx.h" +#include "StdAfxSA.h" -#include "Vehicle.h" -#include "Timer.h" +#include "VehicleSA.h" +#include "TimerSA.h" WRAPPER void CVehicle::SetComponentAtomicAlpha(RpAtomic* pAtomic, int nAlpha) { WRAPARG(pAtomic); WRAPARG(nAlpha); EAXJMP(0x6D2960); } WRAPPER void CVehicle::Render() { EAXJMP(0x6D0E60); } @@ -98,7 +98,7 @@ void CHeli::Render() bool bHasMovingRotor = m_pCarNode[12] != nullptr; bool bHasMovingRotor2 = m_pCarNode[14] != nullptr; - m_nTimeTillWeNeedThisCar = *CTimer::m_snTimeInMilliseconds + 3000; + m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000; if ( m_fRotorSpeed > 0.0 ) dRotorsSpeed = min(1.7 * (1.0/0.22) * m_fRotorSpeed, 1.5); @@ -153,7 +153,7 @@ void CPlane::Render() bool bHasMovingProp = m_pCarNode[12] != nullptr; bool bHasMovingProp2 = m_pCarNode[14] != nullptr; - m_nTimeTillWeNeedThisCar = *CTimer::m_snTimeInMilliseconds + 3000; + m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000; if ( m_fPropellerSpeed > 0.0 ) dRotorsSpeed = min(1.7 * (1.0/0.31) * m_fPropellerSpeed, 1.5); diff --git a/SilentPatch/Vehicle.h b/SAFix/VehicleSA.h similarity index 98% rename from SilentPatch/Vehicle.h rename to SAFix/VehicleSA.h index 8c294d1..305a0a7 100644 --- a/SilentPatch/Vehicle.h +++ b/SAFix/VehicleSA.h @@ -1,7 +1,7 @@ #ifndef __VEHICLE #define __VEHICLE -#include "General.h" +#include "GeneralSA.h" #include "ModelInfoSA.h" struct CVehicleFlags @@ -133,6 +133,9 @@ public: class NOVMT CHeli : public CAutomobile { public: + inline void Render_Stub() + { CHeli::Render(); } + virtual void Render() override; }; @@ -143,6 +146,9 @@ public: float m_fPropellerSpeed; public: + inline void Render_Stub() + { CPlane::Render(); } + virtual void Render() override; }; diff --git a/SilentPatch/MemoryMgr.h b/SilentPatch/MemoryMgr.h index 838c317..dc07df1 100644 --- a/SilentPatch/MemoryMgr.h +++ b/SilentPatch/MemoryMgr.h @@ -2,18 +2,14 @@ #define __MEMORYMGR #define WRAPPER __declspec(naked) +#define DEPRECATED __declspec(deprecated) #define EAXJMP(a) { _asm mov eax, a _asm jmp eax } +#define VARJMP(a) { _asm jmp a } #define WRAPARG(a) UNREFERENCED_PARAMETER(a) #define NOVMT __declspec(novtable) #define SETVMT(a) *((DWORD_PTR*)this) = (DWORD_PTR)a -// A macro used to inject method pointers -#define InjectMethod(address, hook, nType) { void* __funcPtr; { _asm mov eax, offset hook _asm mov __funcPtr, eax } \ - Memory::InjectHook(address, __funcPtr, nType); } -#define InjectMethodVP(address, hook, nType) { void* __funcPtr; { _asm mov eax, offset hook _asm mov __funcPtr, eax } \ - MemoryVP::InjectHook(address, __funcPtr, nType); } - enum { PATCH_CALL, @@ -21,11 +17,88 @@ enum PATCH_NOTHING, }; +inline signed char* GetVer() +{ + static signed char bVer = -1; + return &bVer; +} + +inline bool* GetEuropean() +{ + static bool bEuropean; + return &bEuropean; +} + +// This function initially detects SA version then chooses the address basing on game version +template +inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) +{ + signed char* bVer = GetVer(); + bool* bEuropean = GetEuropean(); + + if ( *bVer == -1 ) + { + if ( *(DWORD*)0x82457C == 0x94BF ) + { + *bVer = 0; + *bEuropean = false; + } + else if ( *(DWORD*)0x8245BC == 0x94BF ) + { + *bVer = 0; + *bEuropean = true; + } + else if ( *(DWORD*)0x8252FC == 0x94BF ) + { + *bVer = 1; + *bEuropean = false; + } + else if ( *(DWORD*)0x82533C == 0x94BF ) + { + *bVer = 1; + *bEuropean = true; + } + else if (*(DWORD*)0x85EC4A == 0x94BF ) + { + *bVer = 2; + *bEuropean = false; + } + } + switch ( *bVer ) + { + case 1: + assert(address11); + // Adjust to EU if needed + if ( *bEuropean && address11 > 0x746FA0 ) + { + if ( address11 < 0x7BB240 ) + address11 += 0x50; + else + address11 += 0x40; + } + return (T)address11; + case 2: + assert(addressSteam); + return (T)addressSteam; + default: + assert(address10); + // Adjust to EU if needed + if ( *bEuropean && address10 > 0x7466D0 ) + { + if ( address10 < 0x7BA940 ) + address10 += 0x50; + else + address10 += 0x40; + } + return (T)address10; + } +} + namespace Memory { template inline void Patch(AT address, T value) - { *(T*)address = value; } + {*(T*)address = value; } template inline void Nop(AT address, unsigned int nCount) @@ -35,6 +108,13 @@ namespace Memory template inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) { + DWORD dwHook; + _asm + { + mov eax, hook + mov dwHook, eax + } + switch ( nType ) { case PATCH_JUMP: @@ -44,7 +124,8 @@ namespace Memory *(BYTE*)address = 0xE8; break; } - *(DWORD*)((DWORD)address + 1) = (DWORD)hook - (DWORD)address - 5; + + *(DWORD*)((DWORD)address + 1) = dwHook - (DWORD)address - 5; } }; @@ -87,7 +168,14 @@ namespace MemoryVP VirtualProtect((void*)((DWORD)address + 1), 4, PAGE_EXECUTE_READWRITE, &dwProtect[0]); break; } - *(DWORD*)((DWORD)address + 1) = (DWORD)hook - (DWORD)address - 5; + DWORD dwHook; + _asm + { + mov eax, hook + mov dwHook, eax + } + + *(DWORD*)((DWORD)address + 1) = (DWORD)dwHook - (DWORD)address - 5; if ( nType == PATCH_NOTHING ) VirtualProtect((void*)((DWORD)address + 1), 4, dwProtect[0], &dwProtect[1]); else @@ -95,24 +183,4 @@ namespace MemoryVP } }; -// Old code, remove asap -#define patch(a, v, s) _patch((void*)(a), (DWORD)(v), (s)) -#define patchf(a, v) _patch((void*)(a), (float)(v)) -#define nop(a, v) _nop((void*)(a), (v)) -#define call(a, v, bAddCall) _call((void*)(a), (DWORD)(v), (bAddCall)) -#define charptr(a, v) _charptr((void*)(a), (const char*)(v)) - -__declspec(deprecated) inline void _patch(void* pAddress, DWORD data, DWORD iSize) -{ - switch(iSize) - { - case 1: *(BYTE*)pAddress = (BYTE)data; - break; - case 2: *(WORD*)pAddress = (WORD)data; - break; - case 4: *(DWORD*)pAddress = (DWORD)data; - break; - } -} - #endif \ No newline at end of file diff --git a/SilentPatch/StdAfx.cpp b/SilentPatch/StdAfx.cpp deleted file mode 100644 index 09f15b6..0000000 --- a/SilentPatch/StdAfx.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "StdAfx.h" \ No newline at end of file diff --git a/SilentPatch/Timer.cpp b/SilentPatch/Timer.cpp index 863672b..57ae4d7 100644 --- a/SilentPatch/Timer.cpp +++ b/SilentPatch/Timer.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "StdAfxSA.h" #include "Timer.h" diff --git a/SilentPatch/dllmain.cpp b/SilentPatch/dllmain.cpp index d172831..4b282c1 100644 --- a/SilentPatch/dllmain.cpp +++ b/SilentPatch/dllmain.cpp @@ -1,6 +1,6 @@ -#include "StdAfx.h" +#include "StdAfxSA.h" -#include "Timer.h" +//#include "Timer.h" #include "General.h" #include "Vehicle.h" #include "LinkList.h" @@ -39,23 +39,6 @@ struct ClumpVisibilityPlugin unsigned int alpha; }; -// RW wrappers -// TODO: Multiple EXEs -WRAPPER RwFrame* RwFrameForAllObjects(RwFrame* frame, RwObjectCallBack callBack, void* data) { WRAPARG(frame); WRAPARG(callBack); WRAPARG(data); EAXJMP(0x7F1200); } -WRAPPER RpClump* RpClumpForAllAtomics(RpClump* clump, RpAtomicCallBack callback, void* pData) { WRAPARG(clump); WRAPARG(callback); WRAPARG(pData); EAXJMP(0x749B70); } -WRAPPER RpGeometry* RpGeometryForAllMaterials(RpGeometry* geometry, RpMaterialCallBack fpCallBack, void* pData) { WRAPARG(geometry); WRAPARG(fpCallBack); WRAPARG(pData); EAXJMP(0x74C790); } -WRAPPER RpAtomic* AtomicDefaultRenderCallBack(RpAtomic* atomic) { WRAPARG(atomic); EAXJMP(0x7491C0); } -WRAPPER RwImage* RtPNGImageRead(const RwChar* imageName) { WRAPARG(imageName); EAXJMP(0x7CF9B0); } -WRAPPER RwTexture* RwTextureCreate(RwRaster* raster) { WRAPARG(raster); EAXJMP(0x7F37C0); } -WRAPPER RwRaster* RwRasterCreate(RwInt32 width, RwInt32 height, RwInt32 depth, RwInt32 flags) { WRAPARG(width); WRAPARG(height); WRAPARG(depth); WRAPARG(flags); EAXJMP(0x7FB230); } -WRAPPER RwRaster* RwRasterSetFromImage(RwRaster* raster, RwImage* image) { WRAPARG(raster); WRAPARG(image); EAXJMP(0x804290); } -WRAPPER RwBool RwImageDestroy(RwImage* image) { WRAPARG(image); EAXJMP(0x802740); } -WRAPPER RwImage* RwImageFindRasterFormat(RwImage* ipImage, RwInt32 nRasterType, RwInt32* npWidth, RwInt32* npHeight, RwInt32* npDepth, RwInt32* npFormat) { WRAPARG(ipImage); WRAPARG(nRasterType); WRAPARG(npWidth); WRAPARG(npHeight); WRAPARG(npDepth); WRAPARG(npFormat); EAXJMP(0x8042C0); } -WRAPPER RpMaterial *RpMaterialSetTexture(RpMaterial *material, RwTexture *texture) { EAXJMP(0x74DBC0); } -WRAPPER RwBool RwTextureDestroy(RwTexture* texture) { EAXJMP(0x7F3820); } - -WRAPPER bool CanSeeOutSideFromCurrArea() { EAXJMP(0x53C4A0); } - #ifndef SA_STEAM_TEST WRAPPER void RwD3D9SetRenderState(RwUInt32 state, RwUInt32 value) { WRAPARG(state); WRAPARG(value); EAXJMP(0x7FC2D0); } @@ -194,18 +177,16 @@ void __stdcall Recalculate(float& fX, float& fY, signed int nShadow) #elif defined SILENTPATCH_SA_VER static CLinkList& m_alphaList = **(CLinkList**)0x733A4D; -static CLinkList& ms_weaponPedsForPC = **(CLinkList**)0x53EACA; static unsigned char* ZonesVisited = *(unsigned char**)0x57216A - 9; -static const float fRefZVal = 1.0f; -static const float* const pRefFal = &fRefZVal; + static RwInt32& clumpPluginOffset = **(RwInt32**)0x732202; static bool& CCutsceneMgr__ms_running = **(bool**)0x53F92D; #ifndef SA_STEAM_TEST -void** rwengine = *(void***)0x58FFC0; + #else void** rwengine = (void**)0xD22E34; #endif @@ -385,13 +366,19 @@ void RenderWeapon(CEntity* pEntity) RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(255)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONEQUAL)); + if ( nPushedAlpha != 255 ) + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(255)); + + if ( nAlphaFunction != rwALPHATESTFUNCTIONEQUAL ) + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONEQUAL)); ((void(*)(CEntity*))0x732F95)(pEntity); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); + if ( nPushedAlpha != 255 ) + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); + + if ( nAlphaFunction != rwALPHATESTFUNCTIONEQUAL ) + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); ms_weaponPedsForPC.Insert(pEntity); } @@ -1098,8 +1085,6 @@ static const BYTE gMoonMaskPNG[] = { // TODO: EXEs #ifndef SA_STEAM_TEST -unsigned char& nGameClockDays = **(unsigned char**)0x4E841D; -unsigned char& nGameClockMonths = **(unsigned char**)0x4E842D; static float& fFarClipZ = **(float**)0x70D21F; static RwTexture** const gpCoronaTexture = *(RwTexture***)0x6FAA8C; static int& MoonSize = **(int**)0x713B0C; @@ -1163,28 +1148,28 @@ void DrawMoonWithPhases(int moonColor, float* screenPos, float sizeX, float size //D3DPERF_EndEvent(); } +static void* HandleMoonStuffStub_JumpBack = AddressByVersion(0x713D24, 0, 0); void __declspec(naked) HandleMoonStuffStub() { __asm { - mov eax, [esp + 78h - 64h] // screen x size - mov ecx, [esp + 78h - 68h] // screen y size + mov eax, [esp + 78h - 64h] // screen x size + mov ecx, [esp + 78h - 68h] // screen y size - push ecx - push eax + push ecx + push eax - lea ecx, [esp + 80h - 54h] // screen coord vector + lea ecx, [esp + 80h - 54h] // screen coord vector - push ecx + push ecx - push esi + push esi - call DrawMoonWithPhases + call DrawMoonWithPhases - add esp, 10h + add esp, 10h - push 713D24h // TODO: EXEs - retn + jmp HandleMoonStuffStub_JumpBack } } @@ -1215,22 +1200,20 @@ void __declspec(naked) HandleMoonStuffStub_Steam() static unsigned int nCachedCRC; +static void* RenderVehicleHiDetailCB = AddressByVersion(0x733240, 0, 0); void __declspec(naked) HunterTest() { static const char aDoorDummy[] = "door_lf_ok"; static const char aStaticRotor[] = "static_rotor"; static const char aStaticRotor2[] = "static_rotor2"; - static const char aWidescreen[] = "widescreen"; - //static bool bToPleaseFuckingCargobob; + static const char aWindscreen[] = "windscreen"; _asm { - //setnz di setnz al movzx di, al - //mov bToPleaseFuckingCargobob, al push 10 - push offset aWidescreen + push offset aWindscreen push ebp call strncmp add esp, 0Ch @@ -1254,11 +1237,9 @@ void __declspec(naked) HunterTest() jz HunterTest_StaticRotorAlphaSet test di, di - //mov al, bToPleaseFuckingCargobob - //test al, al jnz HunterTest_DoorTest - push 733240h + push [RenderVehicleHiDetailCB] mov eax, 4C7914h jmp eax @@ -1304,45 +1285,6 @@ void __declspec(naked) CacheCRC32() } } -void __declspec(naked) PlaneAtomicRendererSetup() -{ - static const char aStaticProp[] = "static_prop"; - static const char aMovingProp[] = "moving_prop"; - _asm - { - mov eax, [esi+4] - push eax - call GetFrameNodeName - //push eax - mov [esp+8+8], eax - push 11 - push offset aStaticProp - push eax - call strncmp - add esp, 10h - test eax, eax - jz PlaneAtomicRendererSetup_Alpha - push 11 - push offset aMovingProp - push [esp+12+8] - call strncmp - add esp, 0Ch - test eax, eax - jnz PlaneAtomicRendererSetup_NoAlpha - -PlaneAtomicRendererSetup_Alpha: - push 734370h - jmp PlaneAtomicRendererSetup_Return - -PlaneAtomicRendererSetup_NoAlpha: - push 733420h - -PlaneAtomicRendererSetup_Return: - mov eax, 4C7986h - jmp eax - } -} - // 1.0 only static bool bDarkVehicleThing; static RpLight*& pDirect = **(RpLight***)0x5BA573; @@ -1686,8 +1628,6 @@ void __declspec(naked) DumpIPLStub() #endif -#include - #include "nvc.h" static IDirect3DVertexShader9* pNVCShader = nullptr; @@ -1715,55 +1655,6 @@ static BOOL (*IsAlreadyRunning)(); static void (*TheScriptsLoad)(); static bool (*InitialiseRenderWare)(); -bool ShaderAttach() -{ - // CGame::InitialiseRenderWare - if ( InitialiseRenderWare() ) - { - 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(RxD3D9InstanceData* pInstData) -{ - if ( bRenderNVC ) - { - // TODO: Daynight balance var - D3DMATRIX outMat; - float fEnvVars[2] = { *(float*)0x8D12C0, RpMaterialGetColor(pInstData->material)->alpha * (1.0f/255.0f) }; - RwRGBAReal* AmbientLight = RpLightGetColor(*(RpLight**)0xC886E8); - - // 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))); - _rwD3D9VSGetComposedTransformMatrix(&outMat); - - RwD3D9SetVertexShaderConstant(0, &outMat, 4); - RwD3D9SetVertexShaderConstant(4, fEnvVars, 1); - RwD3D9SetVertexShaderConstant(5, AmbientLight, 1); - } - else - RwD3D9SetVertexShader(pInstData->vertexShader); -} - void __declspec(naked) SetShader2() { _asm @@ -1781,28 +1672,7 @@ void __declspec(naked) SetShader2() } } -void __declspec(naked) HijackAtomic() -{ - _asm - { - mov eax, [esp+8] - mov pRenderedAtomic, eax - mov eax, 5D6480h - jmp eax - } -} -void __declspec(naked) UsageIndex1() -{ - _asm - { - mov byte ptr [esp+eax*8+27h], 1 - inc eax - - push 5D611Bh - retn - } -} static void* pJackedEsi; @@ -1883,20 +1753,6 @@ PassDayColoursToShader_Iterate: } } -void __declspec(naked) UserTracksFix() -{ - _asm - { - push [esp+4] - mov eax, 4D7C60h - call eax - mov ecx, 0B6B970h - mov eax, 4F35B0h - call eax - retn 4 - } -} - static CAEFLACDecoder* __stdcall DecoderCtor(CAEDataStream* pData) { return new CAEFLACDecoder(pData); @@ -1959,16 +1815,6 @@ LoadFLAC_Return_NoDelete: } } -static struct -{ - char Extension[8]; - unsigned int Codec; -} UserTrackExtensions[] = { { ".ogg", DECODER_VORBIS }, { ".mp3", DECODER_QUICKTIME }, - { ".wav", DECODER_WAVE }, { ".wma", DECODER_WINDOWSMEDIA }, - { ".wmv", DECODER_WINDOWSMEDIA }, { ".aac", DECODER_QUICKTIME }, - { ".m4a", DECODER_QUICKTIME }, { ".mov", DECODER_QUICKTIME }, - { ".fla", DECODER_FLAC }, { ".flac", DECODER_FLAC } }; - void __declspec(naked) FLACInit() { _asm @@ -1984,88 +1830,6 @@ FLACInit_DontFallBack: } } -void __declspec(naked) LightMaterialsFix() -{ - _asm - { - mov [esi], edi - mov ebx, [ecx] - lea esi, [edx+4] - mov [ebx+4], esi - mov edi, [esi] - mov [ebx+8], edi - add esi, 4 - mov [ebx+12], esi - mov edi, [esi] - mov [ebx+16], edi - add ebx, 20 - mov [ecx], ebx - retn - } -} - -static unsigned char* ScriptSpace = *(unsigned char**)0x5D5380; -static int* ScriptParams = *(int**)0x48995B; - -static CZoneInfo*& pCurrZoneInfo = **(CZoneInfo***)0x58ADB1; -static CRGBA* HudColour = *(CRGBA**)0x58ADF6; - -static void BasketballFix(unsigned char* pBuf, int nSize) -{ - for ( int i = 0, hits = 0; i < nSize && hits < 7; i++, pBuf++ ) - { - // Pattern check for save pickup XYZ - if ( *(unsigned int*)pBuf == 0x449DE19A ) // Save pickup X - { - hits++; - *(float*)pBuf = 1291.8f; - } - else if ( *(unsigned int*)pBuf == 0xC4416AE1 ) // Save pickup Y - { - hits++; - *(float*)pBuf = -797.8284f; - } - else if ( *(unsigned int*)pBuf == 0x44886C7B ) // Save pickup Z - { - hits++; - *(float*)pBuf = 1089.5f; - } - else if ( *(unsigned int*)pBuf == 0x449DF852 ) // Save point X - { - hits++; - *(float*)pBuf = 1286.8f; - } - else if ( *(unsigned int*)pBuf == 0xC44225C3 ) // Save point Y - { - hits++; - *(float*)pBuf = -797.69f; - } - else if ( *(unsigned int*)pBuf == 0x44885C7B ) // Save point Z - { - hits++; - *(float*)pBuf = 1089.1f; - } - else if ( *(unsigned int*)pBuf == 0x43373AE1 ) // Save point A - { - hits++; - *(float*)pBuf = 90.0f; - } - } -} - -void TheScriptsLoad_BasketballFix() -{ - TheScriptsLoad(); - - BasketballFix(ScriptSpace+8, *(int*)(ScriptSpace+3)); -} - -void StartNewMission_BasketballFix() -{ - if ( ScriptParams[0] == 0 ) - BasketballFix(ScriptSpace+200000, 69000); -} - CRGBA* CRGBA::BlendGangColour(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { *this = Blend(CRGBA(r, g, b), pCurrZoneInfo->ZoneColour.a, HudColour[3], static_cast(255-pCurrZoneInfo->ZoneColour.a)); @@ -2237,194 +2001,6 @@ BOOL InjectDelayedPatches_10() return TRUE; } -__forceinline void Patch_SA_10() -{ - using namespace MemoryVP; - - // IsAlreadyRunning needs to be read relatively late - the later, the better - IsAlreadyRunning = (BOOL(*)())(*(int*)0x74872E + 0x74872D + 5); - InjectHook(0x74872D, InjectDelayedPatches_10); - - //Patch(0x5D7265, 0xEB); - - // Temp - CTimer::m_snTimeInMilliseconds = *(int**)0x4242D1; - - // Heli rotors - InjectMethodVP(0x6CAB70, CPlane::Render, PATCH_JUMP); - InjectMethodVP(0x6C4400, CHeli::Render, PATCH_JUMP); - //InjectHook(0x553318, RenderAlphaAtomics); - Patch(0x7341D9, TwoPassAlphaRender); - Patch(0x734127, TwoPassAlphaRender); - 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);*/ - - // RefFix - Patch(0x6FB97A, &pRefFal); - Patch(0x6FB9A0, 0); - - // Plane rotors - InjectHook(0x4C7981, PlaneAtomicRendererSetup, PATCH_JUMP); - - // DOUBLE_RWHEELS - Patch(0x4C9290, 0xE281); - Patch(0x4C9292, ~(rwMATRIXTYPEMASK|rwMATRIXINTERNALIDENTITY)); - - // No framedelay - Patch(0x53E923, 0x42EB56); - - // Disable re-initialization of DirectInput mouse device by the game - Patch(0x576CCC, 0xEB); - Patch(0x576EBA, 0xEB); - Patch(0x576F8A, 0xEB); - - // Make sure DirectInput mouse device is set non-exclusive (may not be needed?) - Patch(0x7469A0, 0x909000B0); - - // Weapons rendering - InjectHook(0x5E7859, RenderWeapon); - InjectHook(0x732F30, RenderWeaponsList, PATCH_JUMP); - //Patch(0x53EAC4, 0x0DEB); - //Patch(0x705322, 0x0DEB); - //Patch(0x7271E3, 0x0DEB); - //Patch(0x73314E, 0xC3); - Patch(0x732F95, 0x560CEC83); - Patch(0x732FA2, 0x20245C8B); - Patch(0x733128, 0x20EB); - Patch(0x733135, 0x13EB); - Nop(0x732FBC, 5); - //Nop(0x732F93, 6); - //Nop(0x733144, 6); - Nop(0x732FA6, 6); - //Nop(0x5E46DA, 2); - - // Hunter interior & static_rotor for helis - InjectHook(0x4C78F2, HunterTest, PATCH_JUMP); - InjectHook(0x4C9618, CacheCRC32); - - // Fixed blown up car rendering - // ONLY 1.0 - InjectHook(0x5D993F, DarkVehiclesFix1); - InjectHook(0x5D9A74, DarkVehiclesFix2, PATCH_JUMP); - InjectHook(0x5D9B44, DarkVehiclesFix3, PATCH_JUMP); - InjectHook(0x5D9CB2, DarkVehiclesFix4, PATCH_JUMP); - - // Bindable NUM5 - // Only 1.0 and Steam - Nop(0x57DC55, 2); - - // Moonphases - InjectHook(0x713ACB, HandleMoonStuffStub, PATCH_JUMP); - - // TEMP - //Patch(0x733B05, 40); - //Patch(0x733B55, 40); - //Patch(0x5B3ADD, 4); - - // Twopass rendering (experimental) - /*Patch(0x4C441E, 0x47C7); - Patch(0x4C4420, 0x48); - Patch(0x4C4421, TwoPassAlphaRender); - Patch(0x4C4425, 0x04C25E5F); - Patch(0x4C4429, 0x00);*/ - Patch(0x4C441E, 0x57); - InjectHook(0x4C441F, SetRendererForAtomic, PATCH_CALL); - Patch(0x4C4424, 0x5F04C483); - Patch(0x4C4428, 0x0004C25E); - - // Lightbeam fix - Patch(0x6A2E88, 0x0EEB); - Nop(0x6A2E9C, 3); - Patch(0x6E0F63, 0x0AEB); - Patch(0x6E0F7C, 0x0BEB); - Patch(0x6E0F95, 0x0BEB); - Patch(0x6E0FAF, 0x1AEB); - - Patch(0x6E13D5, 0x09EB); - Patch(0x6E13ED, 0x17EB); - Patch(0x6E141F, 0x0AEB); - - Patch(0x6E0FE0, 0x28); - Patch(0x6E142D, 0x18); - Patch(0x6E0FDB, 0xC8-0x7C); - //InjectHook(0x6A2EDA, CullTest); - - InjectHook(0x6A2EF7, ResetAlphaFuncRefAfterRender, PATCH_JUMP); - - // PS2 SUN!!!!!!!!!!!!!!!!! - static const float fSunMult = (1050.0f * 0.95f) / 1500.0f; - - Nop(0x6FB17C, 3); - Patch(0x6FC5B0, &fSunMult); - //Patch(0x6FB172, 0x0BEB); - //Patch(0x6FB1A7, 8); - -#if defined EXPAND_ALPHA_ENTITY_LISTS - // Bigger alpha entity lists - Patch(0x733B05, EXPAND_ALPHA_ENTITY_LISTS * 20); - Patch(0x733B55, EXPAND_ALPHA_ENTITY_LISTS * 20); -#endif - - // Unlocked widescreen resolutions - Patch(0x745B71, 0x9090687D); - Patch(0x74596C, 0x9090127D); - Nop(0x745970, 2); - Nop(0x745B75, 2); - Nop(0x7459E1, 2); - - // Heap corruption fix - Nop(0x5C25D3, 5); - - // User Tracks fix - InjectHook(0x4D9B66, UserTracksFix); - InjectHook(0x4D9BB5, 0x4F2FD0); - //Nop(0x4D9BB5, 5); - - // FLAC support - InjectHook(0x4F373D, LoadFLAC, PATCH_JUMP); - InjectHook(0x4F35E0, FLACInit, PATCH_JUMP); - InjectHook(0x4F3787, CAEWaveDecoderInit); - - Patch(0x4F376A, 0x18EB); - //Patch(0x4F378F, sizeof(CAEWaveDecoder)); - Patch(0x4F3210, UserTrackExtensions); - Patch(0x4F3241, &UserTrackExtensions->Codec); - //Patch(0x4F35E7, &UserTrackExtensions[1].Codec); - Patch(0x4F322D, sizeof(UserTrackExtensions)); - - // Impound garages working correctly - InjectHook(0x425179, 0x448990); - InjectHook(0x425369, 0x448990); - InjectHook(0x425411, 0x448990); - - // Impounding after busted works - Nop(0x443292, 5); - - // Zones fix - InjectHook(0x572130, GetCurrentZoneLockedOrUnlocked, PATCH_JUMP); - - // Fixed police scanner names - char* pScannerNames = *(char**)0x4E72D4; - strncpy(pScannerNames + (8*113), "WESTP", 8); - strncpy(pScannerNames + (8*134), "????", 8); - - // TEMP - dumping IPL data -#ifdef DO_MAP_DUMP - InjectHook(0x538090, DumpIPLStub, PATCH_JUMP); - InjectHook(0x5B92C7, DumpIPLName); -#endif -} - __forceinline void Patch_SA_Steam() { using namespace MemoryVP; @@ -2462,6 +2038,4 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) RwD3D9DeleteVertexShader(pNVCShader); }*/ return TRUE; -} - -WRAPPER void GTAdelete(void* data) { EAXJMP(0x82413F); } \ No newline at end of file +} \ No newline at end of file