diff --git a/dlls/csx/source/CRank.cpp b/dlls/csx/source/CRank.cpp index 39e6439b..970eca74 100755 --- a/dlls/csx/source/CRank.cpp +++ b/dlls/csx/source/CRank.cpp @@ -220,41 +220,59 @@ void RankSystem::updatePos( RankStats* rr , Stats* s ) } +/** + * Who put these backwards... + */ +#define TRYREAD(t_var, t_num, t_size, t_file) \ + if (fread(t_var, t_size, t_num, t_file) != t_num) { \ + break; \ + } + void RankSystem::loadRank( const char* filename ) { FILE *bfp = fopen( filename , "rb" ); - if ( !bfp ) return; + if (!bfp) + { + MF_Log("Could not load csstats file: %s", filename); + return; + } short int i = 0; - fread(&i, 1 , sizeof(short int) , bfp); + if (fread(&i, sizeof(short int), 1, bfp) != 1) + { + fclose(bfp); + return; + } if (i == RANK_VERSION) { Stats d; char unique[64], name[64]; - fread(&i , 1, sizeof(short int), bfp); - - while( i ) + if (fread(&i, sizeof(short int), 1, bfp) != 1) { - fread(name , i,sizeof(char) , bfp); - fread(&i , 1, sizeof(short int), bfp); - fread(unique , i,sizeof(char) , bfp); - fread(&d.tks, 1,sizeof(int), bfp); - fread(&d.damage, 1,sizeof(int), bfp); - fread(&d.deaths, 1,sizeof(int), bfp); - fread(&d.kills, 1,sizeof(int), bfp); - fread(&d.shots, 1,sizeof(int), bfp); - fread(&d.hits, 1,sizeof(int), bfp); - fread(&d.hs, 1,sizeof(int), bfp); + fclose(bfp); + return; + } - fread(&d.bDefusions, 1,sizeof(int), bfp); - fread(&d.bDefused, 1,sizeof(int), bfp); - fread(&d.bPlants, 1,sizeof(int), bfp); - fread(&d.bExplosions, 1,sizeof(int), bfp); - - fread(d.bodyHits, 1,sizeof(d.bodyHits), bfp); - fread(&i , 1, sizeof(short int), bfp); + while(i && !feof(bfp)) + { + TRYREAD(name, i, sizeof(char), bfp); + TRYREAD(&i, 1, sizeof(short int), bfp); + TRYREAD(unique , i, sizeof(char) , bfp); + TRYREAD(&d.tks, 1, sizeof(int), bfp); + TRYREAD(&d.damage, 1, sizeof(int), bfp); + TRYREAD(&d.deaths, 1, sizeof(int), bfp); + TRYREAD(&d.kills, 1, sizeof(int), bfp); + TRYREAD(&d.shots, 1, sizeof(int), bfp); + TRYREAD(&d.hits, 1, sizeof(int), bfp); + TRYREAD(&d.hs, 1, sizeof(int), bfp); + TRYREAD(&d.bDefusions, 1, sizeof(int), bfp); + TRYREAD(&d.bDefused, 1, sizeof(int), bfp); + TRYREAD(&d.bPlants, 1, sizeof(int), bfp); + TRYREAD(&d.bExplosions, 1, sizeof(int), bfp); + TRYREAD(d.bodyHits, 1, sizeof(d.bodyHits), bfp); + TRYREAD(&i, 1, sizeof(short int), bfp); RankSystem::RankStats* a = findEntryInRank( unique , name ); diff --git a/dlls/dod2/dodx/CRank.cpp b/dlls/dod2/dodx/CRank.cpp index 6885cf05..b546f12d 100755 --- a/dlls/dod2/dodx/CRank.cpp +++ b/dlls/dod2/dodx/CRank.cpp @@ -232,36 +232,57 @@ void RankSystem::updatePos( RankStats* rr , Stats* s ) } -void RankSystem::loadRank( const char* filename ) +/** + * Who put these backwards... + */ +#define TRYREAD(t_var, t_num, t_size, t_file) \ + if (fread(t_var, t_size, t_num, t_file) != t_num) { \ + break; \ + } + +void RankSystem::loadRank(const char* filename) { - FILE *bfp = fopen( filename , "rb" ); + FILE *bfp = fopen(filename , "rb"); - if ( !bfp ) return; + if (!bfp) + { + MF_Log("Could not load stats file: %s", filename); + return; + } short int i = 0; - fread(&i, 1 , sizeof(short int) , bfp); + if (!fread(&i, sizeof(short int), 1, bfp) != 1) + { + fclose(bfp); + return; + } + if (i == RANK_VERSION) { Stats d; char unique[64], name[64]; - fread(&i , 1, sizeof(short int), bfp); - - while( i ) + if (fread(&i, sizeof(short int), 1, bfp) != 1) { - fread(name , i,sizeof(char) , bfp); - fread(&i , 1, sizeof(short int), bfp); - fread(unique , i,sizeof(char) , bfp); - fread(&d.tks, 1,sizeof(int), bfp); - fread(&d.damage, 1,sizeof(int), bfp); - fread(&d.deaths, 1,sizeof(int), bfp); - fread(&d.kills, 1,sizeof(int), bfp); - fread(&d.shots, 1,sizeof(int), bfp); - fread(&d.hits, 1,sizeof(int), bfp); - fread(&d.hs, 1,sizeof(int), bfp); - fread(&d.points, 1,sizeof(int), bfp); - fread(d.bodyHits, 1,sizeof(d.bodyHits), bfp); - fread(&i , 1, sizeof(short int), bfp); + fclose(bfp); + return; + } + + while(i && !feof(bfp)) + { + TRYREAD(name, i, sizeof(char), bfp); + TRYREAD(&i, 1, sizeof(short int), bfp); + TRYREAD(unique, i, sizeof(char) , bfp); + TRYREAD(&d.tks, 1, sizeof(int), bfp); + TRYREAD(&d.damage, 1, sizeof(int), bfp); + TRYREAD(&d.deaths, 1, sizeof(int), bfp); + TRYREAD(&d.kills, 1, sizeof(int), bfp); + TRYREAD(&d.shots, 1, sizeof(int), bfp); + TRYREAD(&d.hits, 1, sizeof(int), bfp); + TRYREAD(&d.hs, 1, sizeof(int), bfp); + TRYREAD(&d.points, 1, sizeof(int), bfp); + TRYREAD(d.bodyHits, 1, sizeof(d.bodyHits), bfp); + TRYREAD(&i, 1, sizeof(short int), bfp); RankSystem::RankStats* a = findEntryInRank( unique , name ); if ( a ) a->updatePosition( &d ); diff --git a/dlls/tfc/tfcx/CRank.cpp b/dlls/tfc/tfcx/CRank.cpp index 8c3a4fc6..88dde13c 100755 --- a/dlls/tfc/tfcx/CRank.cpp +++ b/dlls/tfc/tfcx/CRank.cpp @@ -229,35 +229,56 @@ void RankSystem::updatePos( RankStats* rr , Stats* s ) } -void RankSystem::loadRank( const char* filename ) + +/** + * Who put these backwards... + */ +#define TRYREAD(t_var, t_num, t_size, t_file) \ + if (fread(t_var, t_size, t_num, t_file) != t_num) { \ + break; \ + } + +void RankSystem::loadRank(const char* filename) { - FILE *bfp = fopen( filename , "rb" ); + FILE *bfp = fopen(filename , "rb"); - if ( !bfp ) return; + if (!bfp) + { + MF_Log("Could not load stats file: %s", filename); + return; + } short int i = 0; - fread(&i, 1 , sizeof(short int) , bfp); + if (fread(&i, sizeof(short int), 1, bfp) != 1) + { + fclose(bfp); + return; + } if (i == RANK_VERSION) { Stats d; char unique[64], name[64]; - fread(&i , 1, sizeof(short int), bfp); - - while( i ) + if (fread(&i, sizeof(short int), 1, bfp) != 1) { - fread(name , i,sizeof(char) , bfp); - fread(&i , 1, sizeof(short int), bfp); - fread(unique , i,sizeof(char) , bfp); - fread(&d.tks, 1,sizeof(int), bfp); - fread(&d.damage, 1,sizeof(int), bfp); - fread(&d.deaths, 1,sizeof(int), bfp); - fread(&d.kills, 1,sizeof(int), bfp); - fread(&d.shots, 1,sizeof(int), bfp); - fread(&d.hits, 1,sizeof(int), bfp); - fread(&d.hs, 1,sizeof(int), bfp); - fread(d.bodyHits, 1,sizeof(d.bodyHits), bfp); - fread(&i , 1, sizeof(short int), bfp); + fclose(bfp); + return; + } + + while(i && !feof(bfp)) + { + TRYREAD(name, i, sizeof(char), bfp); + TRYREAD(&i, 1, sizeof(short int), bfp); + TRYREAD(unique, i, sizeof(char), bfp); + TRYREAD(&d.tks, 1, sizeof(int), bfp); + TRYREAD(&d.damage, 1, sizeof(int), bfp); + TRYREAD(&d.deaths, 1, sizeof(int), bfp); + TRYREAD(&d.kills, 1, sizeof(int), bfp); + TRYREAD(&d.shots, 1, sizeof(int), bfp); + TRYREAD(&d.hits, 1, sizeof(int), bfp); + TRYREAD(&d.hs, 1, sizeof(int), bfp); + TRYREAD(d.bodyHits, 1, sizeof(d.bodyHits), bfp); + TRYREAD(&i, 1, sizeof(short int), bfp); RankSystem::RankStats* a = findEntryInRank( unique , name ); if ( a ) a->updatePosition( &d ); diff --git a/dlls/ts/tsx/CRank.cpp b/dlls/ts/tsx/CRank.cpp index ec61407c..5e23564b 100755 --- a/dlls/ts/tsx/CRank.cpp +++ b/dlls/ts/tsx/CRank.cpp @@ -229,35 +229,55 @@ void RankSystem::updatePos( RankStats* rr , Stats* s ) } -void RankSystem::loadRank( const char* filename ) +/** + * Who put these backwards... + */ +#define TRYREAD(t_var, t_num, t_size, t_file) \ + if (fread(t_var, t_size, t_num, t_file) != t_num) { \ + break; \ + } + +void RankSystem::loadRank(const char* filename) { - FILE *bfp = fopen( filename , "rb" ); + FILE *bfp = fopen(filename , "rb"); - if ( !bfp ) return; + if (!bfp) + { + MF_Log("Could not load stats file: %s", filename); + return; + } short int i = 0; - fread(&i, 1 , sizeof(short int) , bfp); + if (fread(&i, sizeof(short int), 1, bfp) != 1) + { + fclose(bfp); + return; + } if (i == RANK_VERSION) { Stats d; char unique[64], name[64]; - fread(&i , 1, sizeof(short int), bfp); - - while( i ) + if (fread(&i, sizeof(short int), 1, bfp) != 1) { - fread(name , i,sizeof(char) , bfp); - fread(&i , 1, sizeof(short int), bfp); - fread(unique , i,sizeof(char) , bfp); - fread(&d.tks, 1,sizeof(int), bfp); - fread(&d.damage, 1,sizeof(int), bfp); - fread(&d.deaths, 1,sizeof(int), bfp); - fread(&d.kills, 1,sizeof(int), bfp); - fread(&d.shots, 1,sizeof(int), bfp); - fread(&d.hits, 1,sizeof(int), bfp); - fread(&d.hs, 1,sizeof(int), bfp); - fread(d.bodyHits, 1,sizeof(d.bodyHits), bfp); - fread(&i , 1, sizeof(short int), bfp); + fclose(bfp); + return; + } + + while(i && !feof(bfp)) + { + TRYREAD(name, i, sizeof(char), bfp); + TRYREAD(&i, 1, sizeof(short int), bfp); + TRYREAD(unique, i, sizeof(char), bfp); + TRYREAD(&d.tks, 1, sizeof(int), bfp); + TRYREAD(&d.damage, 1, sizeof(int), bfp); + TRYREAD(&d.deaths, 1, sizeof(int), bfp); + TRYREAD(&d.kills, 1, sizeof(int), bfp); + TRYREAD(&d.shots, 1, sizeof(int), bfp); + TRYREAD(&d.hits, 1, sizeof(int), bfp); + TRYREAD(&d.hs, 1, sizeof(int), bfp); + TRYREAD(d.bodyHits, 1, sizeof(d.bodyHits), bfp); + TRYREAD(&i, 1, sizeof(short int), bfp); RankSystem::RankStats* a = findEntryInRank( unique , name ); if ( a ) a->updatePosition( &d );