#include "main.h" #include struct zoneInfo { unsigned short id; char* name; }; unsigned short lastZoneID = 0; bool loadedZones = false; std::vector zones; char buffer[512]; unsigned int longestName = 0; int ZoneInfoLogger(DATA *d) { FILE* fh; if(!loadedZones){ fopen_s( &fh, "mapIDS.txt", "r" ); memset( buffer, 0, 512 ); while(!feof(fh)){ fgets( buffer, 512, fh ); if(!feof(fh)){ zoneInfo* thisZone = new zoneInfo(); char* pch; pch = strtok (buffer,"="); thisZone->id = atoi(pch); pch = strtok (NULL,"="); thisZone->name = new char[ strlen( pch ) ]; memset( thisZone->name, 0, strlen( pch ) ); memcpy( thisZone->name, pch+1, strlen(pch+1) - 1 ); zones.push_back( thisZone ); if(strlen(thisZone->name) > longestName){ longestName = strlen(thisZone->name); } } } fclose( fh ); loadedZones = true; longestName++; } for(unsigned int i = 0; i < d->dataSize; i++){ if(d->data[i] == 0x77 && d->data[i+1] == 0x01 && d->data[i+2] == 0x00){ lastZoneID = *((unsigned short*)&d->data[i+3]); } } if(d->data[0] == 0x75 && d->data[1] == 0x01){ fopen_s( &fh, "mapLog.txt", "a" ); if(fh != NULL){ char spaces1[10]; char spaces2[100]; memset(spaces1,0,10); memset(spaces2,0,100); unsigned int thisZoneloc = *((unsigned int*)&d->data[2]); float thisZoneX = *((float*)&d->data[6]); float thisZoneY = *((float*)&d->data[10]); unsigned short thisZoneID = lastZoneID; if(thisZoneID<10){sprintf(spaces1," ");} else if(thisZoneID<100){sprintf(spaces1," ");} else if(thisZoneID<1000){sprintf(spaces1,"");} memset( buffer, 0, 512 ); for(unsigned short i = 0; i < zones.size(); i++){ if(zones[i]->id == thisZoneID){ for(int j=0; j<(longestName-strlen(zones[i]->name)) - 1; j++){ strcat(spaces2," "); } sprintf_s( buffer, 512, "| %d%s | %s%s | %08x | %f | %f |\n", thisZoneID, spaces1, zones[i]->name, spaces2, thisZoneloc, thisZoneX, thisZoneY ); fputs( buffer, fh ); } } fclose( fh ); } } return 0; } //| MapID | ZoneName | ZoneLoc | X | Y |