diff --git a/SilentPatchSA/AudioHardwareSA.cpp b/SilentPatchSA/AudioHardwareSA.cpp index 8393e74..74ea667 100644 --- a/SilentPatchSA/AudioHardwareSA.cpp +++ b/SilentPatchSA/AudioHardwareSA.cpp @@ -12,54 +12,62 @@ void* pMalloc = nullptr; unsigned int nBlockSize = 0; unsigned int nLastMallocSize = 0; -unsigned int CAEDataStreamOld::Seek(long nToSeek, int nPoint) +DWORD CAEDataStreamOld::Seek(LONG nToSeek, DWORD nPoint) { + LARGE_INTEGER filePosition; switch ( nPoint ) { case FILE_BEGIN: - nToSeek = nToSeek + dwStartPosition; + filePosition.QuadPart = nToSeek + dwStartPosition; break; case FILE_END: nPoint = FILE_BEGIN; - nToSeek = dwStartPosition + dwLength - nToSeek; + filePosition.QuadPart = dwStartPosition + dwLength - nToSeek; + break; + default: + filePosition.QuadPart = nToSeek; break; } - dwCurrentPosition = SetFilePointer(hHandle, nToSeek, nullptr, nPoint); + SetFilePointerEx(hHandle, filePosition, &filePosition, nPoint); + dwCurrentPosition = filePosition.LowPart; return dwCurrentPosition - dwStartPosition; } -unsigned int CAEDataStreamOld::FillBuffer(void* pBuf, unsigned long nLen) +DWORD CAEDataStreamOld::FillBuffer(void* pBuf, DWORD nLen) { ReadFile(hHandle, pBuf, nLen, &nLen, nullptr); - dwCurrentPosition += nLen; return nLen; } -unsigned int CAEDataStreamNew::Seek(long nToSeek, int nPoint) +DWORD CAEDataStreamNew::Seek(LONG nToSeek, DWORD nPoint) { + LARGE_INTEGER filePosition; switch ( nPoint ) { case FILE_BEGIN: - nToSeek = nToSeek + dwStartPosition; + filePosition.QuadPart = nToSeek + dwStartPosition; break; case FILE_END: nPoint = FILE_BEGIN; - nToSeek = dwStartPosition + dwLength - nToSeek; + filePosition.QuadPart = dwStartPosition + dwLength - nToSeek; + break; + default: + filePosition.QuadPart = nToSeek; break; } - dwCurrentPosition = SetFilePointer(hHandle, nToSeek, nullptr, nPoint); + SetFilePointerEx(hHandle, filePosition, &filePosition, nPoint); + dwCurrentPosition = filePosition.LowPart; return dwCurrentPosition - dwStartPosition; } -unsigned int CAEDataStreamNew::FillBuffer(void* pBuf, unsigned long nLen) +DWORD CAEDataStreamNew::FillBuffer(void* pBuf, DWORD nLen) { ReadFile(hHandle, pBuf, nLen, &nLen, nullptr); - dwCurrentPosition += nLen; return nLen; } diff --git a/SilentPatchSA/AudioHardwareSA.h b/SilentPatchSA/AudioHardwareSA.h index c18725e..5440bba 100644 --- a/SilentPatchSA/AudioHardwareSA.h +++ b/SilentPatchSA/AudioHardwareSA.h @@ -50,7 +50,11 @@ public: CloseHandle(hHandle); bOpened = false; } - GTAdelete(pFilename); + if ( pFilename != nullptr ) + { + GTAdelete(pFilename); + pFilename = nullptr; + } } inline DWORD GetID() @@ -81,10 +85,15 @@ public: public: // Custom methods - unsigned int Seek(long nToSeek, int nPoint); - unsigned int FillBuffer(void* pBuf, unsigned long nLen); - unsigned int GetCurrentPosition() - { return SetFilePointer(hHandle, 0, nullptr, FILE_CURRENT) - dwStartPosition; } + DWORD Seek(LONG nToSeek, DWORD nPoint); + DWORD FillBuffer(void* pBuf, DWORD nLen); + DWORD GetCurrentPosition() + { + LARGE_INTEGER filePointer; + filePointer.QuadPart = 0; + SetFilePointerEx( hHandle, filePointer, &filePointer, FILE_CURRENT ); + return DWORD(filePointer.QuadPart - dwStartPosition); + } }; // 1.01 structure @@ -118,7 +127,11 @@ public: CloseHandle(hHandle); bOpened = false; } - GTAdelete(pFilename); + if ( pFilename != nullptr ) + { + GTAdelete(pFilename); + pFilename = nullptr; + } } inline DWORD GetID() @@ -149,10 +162,15 @@ public: public: // Custom methods - unsigned int Seek(long nToSeek, int nPoint); - unsigned int FillBuffer(void* pBuf, unsigned long nLen); - unsigned int GetCurrentPosition() - { return SetFilePointer(hHandle, 0, nullptr, FILE_CURRENT) - dwStartPosition; } + DWORD Seek(LONG nToSeek, DWORD nPoint); + DWORD FillBuffer(void* pBuf, DWORD nLen); + DWORD GetCurrentPosition() + { + LARGE_INTEGER filePointer; + filePointer.QuadPart = 0; + SetFilePointerEx( hHandle, filePointer, &filePointer, FILE_CURRENT ); + return DWORD(filePointer.QuadPart - dwStartPosition); + } }; class CAEDataStream @@ -213,7 +231,7 @@ public: { ++nMallocRefCount; - if ( stream ) + if ( stream != nullptr ) stream->Initialise(); } @@ -221,16 +239,19 @@ public: { return pStream; } virtual bool Initialise()=0; - virtual unsigned int FillBuffer(void* pBuf,unsigned long nLen)=0; + virtual uint32_t FillBuffer(void* pBuf,uint32_t nLen)=0; - virtual unsigned int GetStreamLengthMs()=0; - virtual unsigned int GetStreamPlayTimeMs()=0; - virtual void SetCursor(unsigned int nTime)=0; - virtual unsigned int GetSampleRate()=0; + virtual uint32_t GetStreamLengthMs()=0; + virtual uint32_t GetStreamPlayTimeMs()=0; + virtual void SetCursor(uint32_t nTime)=0; + virtual uint32_t GetSampleRate()=0; virtual ~CAEStreamingDecoder(); - virtual unsigned int GetStreamID()=0; + virtual uint32_t GetStreamID()=0; }; +static_assert(sizeof(CAEDataStreamOld) == 0x28, "Wrong size: CAEDataStreamOld"); +static_assert(sizeof(CAEDataStreamNew) == 0x2C, "Wrong size: CAEDataStreamNew"); + #endif \ No newline at end of file diff --git a/SilentPatchSA/FLACDecoderSA.cpp b/SilentPatchSA/FLACDecoderSA.cpp index cf56b09..56538c6 100644 --- a/SilentPatchSA/FLACDecoderSA.cpp +++ b/SilentPatchSA/FLACDecoderSA.cpp @@ -124,7 +124,7 @@ bool CAEFLACDecoder::Initialise() return false; } -unsigned int CAEFLACDecoder::FillBuffer(void* pBuf, unsigned long nLen) +uint32_t CAEFLACDecoder::FillBuffer(void* pBuf, uint32_t nLen) { unsigned int nBytesDecoded = 0; FLAC__int16* pBuffer = static_cast(pBuf); diff --git a/SilentPatchSA/FLACDecoderSA.h b/SilentPatchSA/FLACDecoderSA.h index 9964250..cc1c722 100644 --- a/SilentPatchSA/FLACDecoderSA.h +++ b/SilentPatchSA/FLACDecoderSA.h @@ -26,15 +26,15 @@ public: virtual ~CAEFLACDecoder(); virtual bool Initialise() override; - virtual unsigned int FillBuffer(void* pBuf, unsigned long nLen) override; - virtual unsigned int GetStreamLengthMs() override + virtual uint32_t FillBuffer(void* pBuf, uint32_t nLen) override; + virtual uint32_t GetStreamLengthMs() override { return pStreamInfo->data.stream_info.total_samples * 1000 / pStreamInfo->data.stream_info.sample_rate; } - virtual unsigned int GetStreamPlayTimeMs() override + virtual uint32_t GetStreamPlayTimeMs() override { return nCurrentSample * 1000 / pStreamInfo->data.stream_info.sample_rate; } - virtual void SetCursor(unsigned int nTime) override + virtual void SetCursor(uint32_t nTime) override { FLAC__stream_decoder_seek_absolute(pFLACDecoder, nTime * pStreamInfo->data.stream_info.sample_rate / 1000); } - virtual unsigned int GetSampleRate() override + virtual uint32_t GetSampleRate() override { return pStreamInfo->data.stream_info.sample_rate; } - virtual unsigned int GetStreamID() override + virtual uint32_t GetStreamID() override { return GetStream()->GetID(); } }; \ No newline at end of file diff --git a/SilentPatchSA/SilentPatchSA.vcxproj b/SilentPatchSA/SilentPatchSA.vcxproj index 563f0cf..0a9e4b7 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj +++ b/SilentPatchSA/SilentPatchSA.vcxproj @@ -61,6 +61,7 @@ NoExtensions /Zc:threadSafeInit- %(AdditionalOptions) Fast + true true @@ -94,6 +95,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio NoExtensions /Zc:threadSafeInit- %(AdditionalOptions) Fast + true true diff --git a/SilentPatchSA/WaveDecoderSA.cpp b/SilentPatchSA/WaveDecoderSA.cpp index c0314a0..e9cd2d7 100644 --- a/SilentPatchSA/WaveDecoderSA.cpp +++ b/SilentPatchSA/WaveDecoderSA.cpp @@ -56,7 +56,7 @@ bool CAEWaveDecoder::Initialise() return formatChunk.sampleRate <= 48000 && formatChunk.numChannels <= 2 && (formatChunk.bitsPerSample == 8 || formatChunk.bitsPerSample == 16 || formatChunk.bitsPerSample == 24); } -unsigned int CAEWaveDecoder::FillBuffer(void* pBuf, unsigned long nLen) +uint32_t CAEWaveDecoder::FillBuffer(void* pBuf, uint32_t nLen) { if ( formatChunk.bitsPerSample == 8 ) { diff --git a/SilentPatchSA/WaveDecoderSA.h b/SilentPatchSA/WaveDecoderSA.h index 98d2c19..f6d813e 100644 --- a/SilentPatchSA/WaveDecoderSA.h +++ b/SilentPatchSA/WaveDecoderSA.h @@ -25,22 +25,22 @@ public: {} virtual bool Initialise() override; - virtual unsigned int FillBuffer(void* pBuf, unsigned long nLen) override; + virtual uint32_t FillBuffer(void* pBuf, uint32_t nLen) override; - virtual unsigned int GetStreamLengthMs() override + virtual uint32_t GetStreamLengthMs() override { return static_cast(nDataSize) * 8000 / (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels); } - virtual unsigned int GetStreamPlayTimeMs() override + virtual uint32_t GetStreamPlayTimeMs() override { return static_cast(GetStream()->GetCurrentPosition() - nOffsetToData) * 8000 / (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels); } - virtual void SetCursor(unsigned int nTime) override + virtual void SetCursor(uint32_t nTime) override { auto nPos = static_cast(nTime) * (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels) / 8000; auto nModulo = (formatChunk.numChannels*formatChunk.bitsPerSample/8); auto nExtra = nPos % nModulo ? nModulo - (nPos % nModulo) : 0; GetStream()->Seek(nOffsetToData + nPos + nExtra, FILE_BEGIN); } - virtual unsigned int GetSampleRate() override + virtual uint32_t GetSampleRate() override { return formatChunk.sampleRate; } - virtual unsigned int GetStreamID() override + virtual uint32_t GetStreamID() override { return GetStream()->GetID(); } }; \ No newline at end of file