Skip to content

Instantly share code, notes, and snippets.

@metasta
Created March 31, 2010 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metasta/349983 to your computer and use it in GitHub Desktop.
Save metasta/349983 to your computer and use it in GitHub Desktop.
csstats.dat reader
/*********************************
*
* readstats
* Convert csstats.dat to CSV format
*
* usage:
* ./readstats ./path/to/csstats.dat
*
*********************************/
#include <stdio.h>
#include <stdlib.h>
#define VERSION 11
#define die(msg) {fputs(msg,stderr);exit(1);}
char * read_string(FILE * fp)
{
unsigned short l; char * s;
if(fread(&l, 2, 1, fp) < 1) die("fread() failed\n");
if(l == 0) exit(fclose(fp));
s = malloc(l);
if(fread(s, 1, l, fp) < l) die("fread() failed\n");
return s;
}
int main(int argc, char ** argv)
{
FILE * fp; short v; unsigned short i; unsigned int a[20], n;
if(argc != 2) die("usage: readstats ./path/to/csstats.dat\n");
if((fp=fopen(argv[1],"rb")) == NULL) die("fopen() failed\n");
if(fread(&v, 2, 1, fp) < 1) die("fread() failed\n");
if(v != VERSION) die("Version incorrect\n");
for(n = 1; ; n++){
printf("%d\t%s\t", n, read_string(fp)); /* Rank, Name */
printf("%s\t", read_string(fp)); /* SteamID */
if(fread(a, 4, 20, fp) < 20) die("fread() failed\n");
for(i= 0; i<11; i++) printf("%d\t", a[i]);
for(i=12; i<18; i++) printf("%d\t", a[i]);
printf("%d\n", a[18]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment