mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-12-29 15:23:02 +05:00
Cleaned up AudioHardwareSA
Extra security checks
This commit is contained in:
parent
94fe7f01bd
commit
e4bed9f427
7 changed files with 74 additions and 43 deletions
|
@ -12,54 +12,62 @@ void* pMalloc = nullptr;
|
||||||
unsigned int nBlockSize = 0;
|
unsigned int nBlockSize = 0;
|
||||||
unsigned int nLastMallocSize = 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 )
|
switch ( nPoint )
|
||||||
{
|
{
|
||||||
case FILE_BEGIN:
|
case FILE_BEGIN:
|
||||||
nToSeek = nToSeek + dwStartPosition;
|
filePosition.QuadPart = nToSeek + dwStartPosition;
|
||||||
break;
|
break;
|
||||||
case FILE_END:
|
case FILE_END:
|
||||||
nPoint = FILE_BEGIN;
|
nPoint = FILE_BEGIN;
|
||||||
nToSeek = dwStartPosition + dwLength - nToSeek;
|
filePosition.QuadPart = dwStartPosition + dwLength - nToSeek;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
filePosition.QuadPart = nToSeek;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwCurrentPosition = SetFilePointer(hHandle, nToSeek, nullptr, nPoint);
|
SetFilePointerEx(hHandle, filePosition, &filePosition, nPoint);
|
||||||
|
dwCurrentPosition = filePosition.LowPart;
|
||||||
|
|
||||||
return dwCurrentPosition - dwStartPosition;
|
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);
|
ReadFile(hHandle, pBuf, nLen, &nLen, nullptr);
|
||||||
|
|
||||||
dwCurrentPosition += nLen;
|
dwCurrentPosition += nLen;
|
||||||
return nLen;
|
return nLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CAEDataStreamNew::Seek(long nToSeek, int nPoint)
|
DWORD CAEDataStreamNew::Seek(LONG nToSeek, DWORD nPoint)
|
||||||
{
|
{
|
||||||
|
LARGE_INTEGER filePosition;
|
||||||
switch ( nPoint )
|
switch ( nPoint )
|
||||||
{
|
{
|
||||||
case FILE_BEGIN:
|
case FILE_BEGIN:
|
||||||
nToSeek = nToSeek + dwStartPosition;
|
filePosition.QuadPart = nToSeek + dwStartPosition;
|
||||||
break;
|
break;
|
||||||
case FILE_END:
|
case FILE_END:
|
||||||
nPoint = FILE_BEGIN;
|
nPoint = FILE_BEGIN;
|
||||||
nToSeek = dwStartPosition + dwLength - nToSeek;
|
filePosition.QuadPart = dwStartPosition + dwLength - nToSeek;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
filePosition.QuadPart = nToSeek;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwCurrentPosition = SetFilePointer(hHandle, nToSeek, nullptr, nPoint);
|
SetFilePointerEx(hHandle, filePosition, &filePosition, nPoint);
|
||||||
|
dwCurrentPosition = filePosition.LowPart;
|
||||||
|
|
||||||
return dwCurrentPosition - dwStartPosition;
|
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);
|
ReadFile(hHandle, pBuf, nLen, &nLen, nullptr);
|
||||||
|
|
||||||
dwCurrentPosition += nLen;
|
dwCurrentPosition += nLen;
|
||||||
return nLen;
|
return nLen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,11 @@ public:
|
||||||
CloseHandle(hHandle);
|
CloseHandle(hHandle);
|
||||||
bOpened = false;
|
bOpened = false;
|
||||||
}
|
}
|
||||||
GTAdelete(pFilename);
|
if ( pFilename != nullptr )
|
||||||
|
{
|
||||||
|
GTAdelete(pFilename);
|
||||||
|
pFilename = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DWORD GetID()
|
inline DWORD GetID()
|
||||||
|
@ -81,10 +85,15 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Custom methods
|
// Custom methods
|
||||||
unsigned int Seek(long nToSeek, int nPoint);
|
DWORD Seek(LONG nToSeek, DWORD nPoint);
|
||||||
unsigned int FillBuffer(void* pBuf, unsigned long nLen);
|
DWORD FillBuffer(void* pBuf, DWORD nLen);
|
||||||
unsigned int GetCurrentPosition()
|
DWORD GetCurrentPosition()
|
||||||
{ return SetFilePointer(hHandle, 0, nullptr, FILE_CURRENT) - dwStartPosition; }
|
{
|
||||||
|
LARGE_INTEGER filePointer;
|
||||||
|
filePointer.QuadPart = 0;
|
||||||
|
SetFilePointerEx( hHandle, filePointer, &filePointer, FILE_CURRENT );
|
||||||
|
return DWORD(filePointer.QuadPart - dwStartPosition);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1.01 structure
|
// 1.01 structure
|
||||||
|
@ -118,7 +127,11 @@ public:
|
||||||
CloseHandle(hHandle);
|
CloseHandle(hHandle);
|
||||||
bOpened = false;
|
bOpened = false;
|
||||||
}
|
}
|
||||||
GTAdelete(pFilename);
|
if ( pFilename != nullptr )
|
||||||
|
{
|
||||||
|
GTAdelete(pFilename);
|
||||||
|
pFilename = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DWORD GetID()
|
inline DWORD GetID()
|
||||||
|
@ -149,10 +162,15 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Custom methods
|
// Custom methods
|
||||||
unsigned int Seek(long nToSeek, int nPoint);
|
DWORD Seek(LONG nToSeek, DWORD nPoint);
|
||||||
unsigned int FillBuffer(void* pBuf, unsigned long nLen);
|
DWORD FillBuffer(void* pBuf, DWORD nLen);
|
||||||
unsigned int GetCurrentPosition()
|
DWORD GetCurrentPosition()
|
||||||
{ return SetFilePointer(hHandle, 0, nullptr, FILE_CURRENT) - dwStartPosition; }
|
{
|
||||||
|
LARGE_INTEGER filePointer;
|
||||||
|
filePointer.QuadPart = 0;
|
||||||
|
SetFilePointerEx( hHandle, filePointer, &filePointer, FILE_CURRENT );
|
||||||
|
return DWORD(filePointer.QuadPart - dwStartPosition);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CAEDataStream
|
class CAEDataStream
|
||||||
|
@ -213,7 +231,7 @@ public:
|
||||||
{
|
{
|
||||||
++nMallocRefCount;
|
++nMallocRefCount;
|
||||||
|
|
||||||
if ( stream )
|
if ( stream != nullptr )
|
||||||
stream->Initialise();
|
stream->Initialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,16 +239,19 @@ public:
|
||||||
{ return pStream; }
|
{ return pStream; }
|
||||||
|
|
||||||
virtual bool Initialise()=0;
|
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 uint32_t GetStreamLengthMs()=0;
|
||||||
virtual unsigned int GetStreamPlayTimeMs()=0;
|
virtual uint32_t GetStreamPlayTimeMs()=0;
|
||||||
virtual void SetCursor(unsigned int nTime)=0;
|
virtual void SetCursor(uint32_t nTime)=0;
|
||||||
virtual unsigned int GetSampleRate()=0;
|
virtual uint32_t GetSampleRate()=0;
|
||||||
|
|
||||||
virtual ~CAEStreamingDecoder();
|
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
|
#endif
|
|
@ -124,7 +124,7 @@ bool CAEFLACDecoder::Initialise()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CAEFLACDecoder::FillBuffer(void* pBuf, unsigned long nLen)
|
uint32_t CAEFLACDecoder::FillBuffer(void* pBuf, uint32_t nLen)
|
||||||
{
|
{
|
||||||
unsigned int nBytesDecoded = 0;
|
unsigned int nBytesDecoded = 0;
|
||||||
FLAC__int16* pBuffer = static_cast<FLAC__int16*>(pBuf);
|
FLAC__int16* pBuffer = static_cast<FLAC__int16*>(pBuf);
|
||||||
|
|
|
@ -26,15 +26,15 @@ public:
|
||||||
|
|
||||||
virtual ~CAEFLACDecoder();
|
virtual ~CAEFLACDecoder();
|
||||||
virtual bool Initialise() override;
|
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 pStreamInfo->data.stream_info.total_samples * 1000 / pStreamInfo->data.stream_info.sample_rate; }
|
{ 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; }
|
{ 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); }
|
{ 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; }
|
{ return pStreamInfo->data.stream_info.sample_rate; }
|
||||||
virtual unsigned int GetStreamID() override
|
virtual uint32_t GetStreamID() override
|
||||||
{ return GetStream()->GetID(); }
|
{ return GetStream()->GetID(); }
|
||||||
};
|
};
|
|
@ -61,6 +61,7 @@
|
||||||
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
|
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
|
||||||
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
|
||||||
<FloatingPointModel>Fast</FloatingPointModel>
|
<FloatingPointModel>Fast</FloatingPointModel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
@ -94,6 +95,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
|
||||||
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
|
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
|
||||||
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
|
||||||
<FloatingPointModel>Fast</FloatingPointModel>
|
<FloatingPointModel>Fast</FloatingPointModel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
|
|
@ -56,7 +56,7 @@ bool CAEWaveDecoder::Initialise()
|
||||||
return formatChunk.sampleRate <= 48000 && formatChunk.numChannels <= 2 && (formatChunk.bitsPerSample == 8 || formatChunk.bitsPerSample == 16 || formatChunk.bitsPerSample == 24);
|
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 )
|
if ( formatChunk.bitsPerSample == 8 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,22 +25,22 @@ public:
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual bool Initialise() override;
|
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<unsigned long long>(nDataSize) * 8000 / (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels); }
|
{ return static_cast<unsigned long long>(nDataSize) * 8000 / (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels); }
|
||||||
virtual unsigned int GetStreamPlayTimeMs() override
|
virtual uint32_t GetStreamPlayTimeMs() override
|
||||||
{ return static_cast<unsigned long long>(GetStream()->GetCurrentPosition() - nOffsetToData) * 8000 / (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels); }
|
{ return static_cast<unsigned long long>(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<unsigned long long>(nTime) * (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels) / 8000;
|
{ auto nPos = static_cast<unsigned long long>(nTime) * (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels) / 8000;
|
||||||
auto nModulo = (formatChunk.numChannels*formatChunk.bitsPerSample/8);
|
auto nModulo = (formatChunk.numChannels*formatChunk.bitsPerSample/8);
|
||||||
auto nExtra = nPos % nModulo ? nModulo - (nPos % nModulo) : 0;
|
auto nExtra = nPos % nModulo ? nModulo - (nPos % nModulo) : 0;
|
||||||
GetStream()->Seek(nOffsetToData + nPos + nExtra, FILE_BEGIN); }
|
GetStream()->Seek(nOffsetToData + nPos + nExtra, FILE_BEGIN); }
|
||||||
|
|
||||||
virtual unsigned int GetSampleRate() override
|
virtual uint32_t GetSampleRate() override
|
||||||
{ return formatChunk.sampleRate; }
|
{ return formatChunk.sampleRate; }
|
||||||
|
|
||||||
virtual unsigned int GetStreamID() override
|
virtual uint32_t GetStreamID() override
|
||||||
{ return GetStream()->GetID(); }
|
{ return GetStream()->GetID(); }
|
||||||
};
|
};
|
Loading…
Reference in a new issue