Statstring Parsing by DarkMinion-vL

Thanks to soul and sky for helping with d2 statstring parsing

void CVLBinaryBotDlg::ParseStatstring(char *statstring, char *outbuf)
{
DWORD a, b, c, d, e, f, g, h, i, j;
strcpy(outbuf, statstring);
//Starcraft shareware
if(!strnicmp(statstring, "RHSS", 4))
strcpy(outbuf, "Starcraft shareware.");

//Starcraft
if(!strnicmp(statstring, "RATS", 4))
{
if(sscanf(statstring + 5, "%d %d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j) != 9)
{
sprintf(outbuf, "a Starcraft %sbot.", (d == 1) ? "(spawn) " : "");
return;
}
if(a > 0)
sprintf(outbuf, "Starcraft%s: %d normal game wins, with a rating of %d on the ladder.", (d == 1) ? " (spawn)" : "", c, a);
else
sprintf(outbuf, "Starcraft%s: %d normal game wins.", (d == 1) ? " (spawn)" : "", c);
}

//Brood war
if(!strnicmp(statstring, "PXES", 4))
{
if(sscanf(statstring + 5, "%d %d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j) != 9)
{
sprintf(outbuf, "a Starcraft Brood War %sbot.", (d == 1) ? "(spawn)" : "");
return;
}
if(a > 0)
sprintf(outbuf, "Starcraft Brood War%s: %d normal game wins, with a rating of %d on the ladder.", (d == 1) ? " (spawn)" : "", c, a);
else
sprintf(outbuf, "Starcraft Brood War%s: %d normal game wins.", (d == 1) ? " (spawn)" : "", c);
}

//Warcraft II
if(!strnicmp(statstring, "NB2W", 4))
{
if(sscanf(statstring + 5, "%d %d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j) != 9)
{
sprintf(outbuf, "a Warcraft II %sbot.", (d == 1) ? "(spawn)" : "");
return;
}
if(a > 0)
sprintf(outbuf, "Warcraft II%s: %d normal game wins, with a rating of %d on the ladder.", (d == 1) ? " (spawn)" : "", c, a);
else
sprintf(outbuf, "Warcraft II%s: %d normal game wins.", (d == 1) ? " (spawn)" : "", c);
}

//Diablo shareware
if(!strnicmp(statstring, "RHSD", 4))
{
if(sscanf(statstring + 5, "%d %d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j) != 9)
{
strcpy(outbuf, "a Diablo shareware bot.");
return;
}
char type[32] = "";
if(b == 0) strcpy(type, "warrior");
if(b == 1) strcpy(type, "rogue");
if(b == 2) strcpy(type, "sorcerer);
sprintf(outbuf, "Diablo shareware: Level %d %s with %d dots, %d strength, %d magic, %d dexterity, %d vitality, and %d gold.", a, type, c, d, e, f, g, h);
}

//Diablo
if(!strnicmp(statstring, "LTRD", 4))
{
if(sscanf(statstring + 5, "%d %d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j) != 9)
{
strcpy(outbuf, "a Diablo bot.");
return;
}
char type[32] = "";
if(b == 0) strcpy(type, "warrior");
if(b == 1) strcpy(type, "rogue");
if(b == 2) strcpy(type, "sorcerer");
sprintf(outbuf, "Diablo: Level %d %s with %d dots, %d strength, %d magic, %d dexterity, %d vitality, and %d gold.", a, type, c, d, e, f, g, h);
}

//Diablo II
if(!strnicmp(statstring + 2, "2D", 2))
strcpy(outbuf, ParseD2Stats(statstring));

//Chat bot
if(!strnicmp(statstring, "TAHC", 4))
strcpy(outbuf, "a Chat bot.");
}

char *CVLBinaryBotDlg::ParseD2Stats(char *stats)
{
char *d2classes[] =
{
"amazon",
"sorceress",
"necromancer",
"paladin",
"barbarian",
"druid",
"assassin",
"unknown class"
};
char *statbuf = new char[512];
memset(statbuf, 0, 512);
char *p = 0;
char server[32];
char name[32];
if(strlen(stats) > 4) {
int len = StringCopy(server, stats + 4, ',');
len += StringCopy(name, stats + len + 5, ',');
p = stats + len + 6;
}
if(!strnicmp(stats, "VD2D", 4))
strcat(statbuf, "Diablo II: ");
else
strcat(statbuf, "Diablo II Lord of Destruction: ");
if(!p || strlen(p) != 33) {
strcat(statbuf, "Open character");
} else {
char version = p[0] - 0x80;
char charclass = p[13] - 1;
if(charclass < 0 || charclass > 6)
charclass = 7;
bool female = false;
if(charclass == 0 || charclass == 1 || charclass == 6)
female = true;
int charlevel = p[25];
char hardcore = p[26] & 4;
bool expansion = false;
if(!strnicmp(stats, "PX2D", 4))
{
if(p[26] & 0x20)
{
switch((p[27] & 0x18) >> 3)
{
case 1:
if(hardcore)
mystrcat(statbuf, "Destroyer ");
else
mystrcat(statbuf, "Slayer ");
break;
case 2:
if(hardcore)
mystrcat(statbuf, "Conquerer ");
else
mystrcat(statbuf, "Champion ");
break;
case 3:
if(hardcore)
mystrcat(statbuf, "Guardian ");
else
{
if(!female)
mystrcat(statbuf, "Patriarch ");
else
mystrcat(statbuf, "Matriarch ");
}
break;
}
expansion = true;
}
}
if(!expansion){
switch((p[27] & 0x18) >> 3) {
case 1:
if(female == false) {
if(hardcore)
mystrcat(statbuf, "Count ");
else
mystrcat(statbuf, "Sir ");
} else {
if(hardcore)
mystrcat(statbuf, "Countess ");
else
mystrcat(statbuf, "Dame ");
}
break;
case 2:
if(female == false) {
if(hardcore)
mystrcat(statbuf, "Duke ");
else
mystrcat(statbuf, "Lord ");
} else {
if(hardcore)
mystrcat(statbuf, "Duchess ");
else
mystrcat(statbuf, "Lady ");
}
break;
case 3:
if(female == false) {
if(hardcore)
mystrcat(statbuf, "King ");
else
mystrcat(statbuf, "Baron ");
} else {
if(hardcore)
mystrcat(statbuf, "Queen ");
else
mystrcat(statbuf, "Baroness ");
}
break;
}}
mystrcat(statbuf, "%s, a ", name);
if(hardcore) {
if(p[26] & 0x08)
strcat(statbuf, "dead ");
mystrcat(statbuf, "hardcore level %d ", charlevel);
} else {
mystrcat(statbuf, "level %d ", charlevel);
}
mystrcat(statbuf, "%s on realm %s", d2classes[charclass], server);
}
return statbuf;
}



DarkMinion
Valhalla Legends

Programmer of vLBBot.
Yes, it owns you :)