Skip to content

Commit 6ad6d07

Browse files
committed
Fixed LARGE_ADDRESS_AWARE flag not being set for some gta_sa.exe variants
1 parent ad915f6 commit 6ad6d07

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

MTA10/loader/CExePatchedStatus.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,31 @@ EPatchResult UpdatePatchStatusTimestamp( const SString& strGTAEXEPath, EPatchMod
299299
//////////////////////////////////////////////////////////
300300
EPatchResult UpdatePatchStatusLargeMem( const SString& strGTAEXEPath, EPatchMode mode )
301301
{
302+
// Get file position of IMAGE_FILE_HEADER->Characteristics
303+
uint uiFilePosition = 0;
304+
FILE* fh = fopen ( strGTAEXEPath, "rb" );
305+
if ( fh )
306+
{
307+
// 60 is offset of IMAGE_DOS_HEADER->e_lfanew
308+
if ( !fseek ( fh, 60, SEEK_SET ) )
309+
{
310+
long e_lfanew;
311+
if ( fread ( &e_lfanew, sizeof ( e_lfanew ), 1, fh ) == 1 )
312+
{
313+
// 4 is offset of IMAGE_NT_HEADERS->FileHeader
314+
// 18 is offset of IMAGE_FILE_HEADER->Characteristics
315+
uiFilePosition = e_lfanew + 4 + 18;
316+
}
317+
}
318+
fclose ( fh );
319+
}
320+
302321
// Get the value from the header
303322
ushort usCharacteristics = 0;
304-
FILE* fh = fopen ( strGTAEXEPath, "rb" );
323+
fh = fopen ( strGTAEXEPath, "rb" );
305324
if ( fh )
306325
{
307-
if ( !fseek ( fh, 0x96, SEEK_SET ) )
326+
if ( !fseek ( fh, uiFilePosition, SEEK_SET ) )
308327
{
309328
if ( fread ( &usCharacteristics, sizeof ( usCharacteristics ), 1, fh ) != 1 )
310329
{
@@ -341,13 +360,17 @@ EPatchResult UpdatePatchStatusLargeMem( const SString& strGTAEXEPath, EPatchMode
341360
{
342361
return PATCH_SET_RESULT_REQ_ADMIN;
343362
}
344-
if ( !fseek ( fh, 0x96, SEEK_SET ) )
363+
if ( !fseek ( fh, uiFilePosition, SEEK_SET ) )
345364
{
346365
fwrite ( &usCharacteristicsRequired, sizeof ( usCharacteristicsRequired ), 1, fh );
347366
}
348367
fclose ( fh );
349368
}
350369
}
370+
else
371+
{
372+
WriteDebugEventAndReport ( 9805, SString ( "Unable to set LARGE_ADDRESS_AWARE [FilePosition=0x%x Characteristics=0x%x]", uiFilePosition, usCharacteristics ) );
373+
}
351374
return PATCH_SET_RESULT_OK;
352375
}
353376

0 commit comments

Comments
 (0)