@@ -299,12 +299,31 @@ EPatchResult UpdatePatchStatusTimestamp( const SString& strGTAEXEPath, EPatchMod
299299// ////////////////////////////////////////////////////////
300300EPatchResult 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