PropData: load more property values from Source Engine binary model format.
This commit is contained in:
parent
a82c978026
commit
9bb8dcab7c
1 changed files with 80 additions and 24 deletions
|
@ -89,14 +89,14 @@ Prop_GetInfo(int i, int type)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PropData_ParseField(int i, int a)
|
PropData_ParseField(int i, string keyName, string setValue)
|
||||||
{
|
{
|
||||||
switch (argv(0)) {
|
switch (keyName) {
|
||||||
case "name":
|
case "name":
|
||||||
g_propdata[i].name = argv(1);
|
g_propdata[i].name = setValue;
|
||||||
break;
|
break;
|
||||||
case "base":
|
case "base":
|
||||||
g_propdata[i].base = argv(1);
|
g_propdata[i].base = setValue;
|
||||||
break;
|
break;
|
||||||
case "blockLOS":
|
case "blockLOS":
|
||||||
g_propdata[i].flags |= PDFL_BLOCKLOS;
|
g_propdata[i].flags |= PDFL_BLOCKLOS;
|
||||||
|
@ -108,52 +108,52 @@ PropData_ParseField(int i, int a)
|
||||||
g_propdata[i].flags |= PDFL_ALLOWSTATIC;
|
g_propdata[i].flags |= PDFL_ALLOWSTATIC;
|
||||||
break;
|
break;
|
||||||
case "dmg.bullets":
|
case "dmg.bullets":
|
||||||
g_propdata[i].damage_bullets = stof(argv(1));
|
g_propdata[i].damage_bullets = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "dmg.club":
|
case "dmg.club":
|
||||||
g_propdata[i].damage_melee = stof(argv(1));
|
g_propdata[i].damage_melee = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "dmg.explosive":
|
case "dmg.explosive":
|
||||||
g_propdata[i].damage_explosive = stof(argv(1));
|
g_propdata[i].damage_explosive = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "health":
|
case "health":
|
||||||
g_propdata[i].health = stof(argv(1));
|
g_propdata[i].health = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "explosive_damage":
|
case "explosive_damage":
|
||||||
g_propdata[i].explosive_damage = stof(argv(1));
|
g_propdata[i].explosive_damage = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "explosive_radius":
|
case "explosive_radius":
|
||||||
g_propdata[i].explosive_radius = stof(argv(1));
|
g_propdata[i].explosive_radius = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "breakable_particle":
|
case "breakable_particle":
|
||||||
g_propdata[i].breakable_particle = argv(1);
|
g_propdata[i].breakable_particle = setValue;
|
||||||
break;
|
break;
|
||||||
case "breakable_model":
|
case "breakable_model":
|
||||||
g_propdata[i].breakable_model = argv(1);
|
g_propdata[i].breakable_model = setValue;
|
||||||
break;
|
break;
|
||||||
case "breakable_count":
|
case "breakable_count":
|
||||||
g_propdata[i].breakable_count = stoi(argv(1));
|
g_propdata[i].breakable_count = stoi(setValue);
|
||||||
break;
|
break;
|
||||||
case "breakable_skin":
|
case "breakable_skin":
|
||||||
g_propdata[i].breakable_skin = stof(argv(1));
|
g_propdata[i].breakable_skin = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "mass":
|
case "mass":
|
||||||
g_propdata[i].mass = stof(argv(1));
|
g_propdata[i].mass = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "damping":
|
case "damping":
|
||||||
g_propdata[i].damping_linear = stof(argv(1));
|
g_propdata[i].damping_linear = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "rotdamping":
|
case "rotdamping":
|
||||||
g_propdata[i].damping_angular = stof(argv(1));
|
g_propdata[i].damping_angular = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "inertia":
|
case "inertia":
|
||||||
g_propdata[i].inertia = stof(argv(1));
|
g_propdata[i].inertia = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "volume":
|
case "volume":
|
||||||
g_propdata[i].volume = stof(argv(1));
|
g_propdata[i].volume = stof(setValue);
|
||||||
break;
|
break;
|
||||||
case "surfaceprop":
|
case "surfaceprop":
|
||||||
g_propdata[i].surfaceprop = argv(1);
|
g_propdata[i].surfaceprop = setValue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ PropData_Parse(int i, string line, string type)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (braced == 2 && t_name != "") {
|
if (braced == 2 && t_name != "") {
|
||||||
PropData_ParseField(i, c);
|
PropData_ParseField(i, argv(0), argv(1));
|
||||||
} else if (braced == 1 && key != "BreakableModels") {
|
} else if (braced == 1 && key != "BreakableModels") {
|
||||||
/* name/identifer of our message */
|
/* name/identifer of our message */
|
||||||
t_name = strtolower(key);
|
t_name = strtolower(key);
|
||||||
|
@ -250,7 +250,7 @@ PropData_ParsePhyFile(int i, string line, string type)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (braced == 1i && t_name == "solid") {
|
if (braced == 1i && t_name == "solid") {
|
||||||
PropData_ParseField(i, c);
|
PropData_ParseField(i, argv(0), argv(1));
|
||||||
} else if (braced == 1i && t_name == "break") {
|
} else if (braced == 1i && t_name == "break") {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "model":
|
case "model":
|
||||||
|
@ -324,8 +324,9 @@ PropData_ForModel(string modelname)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Defaults go here */
|
/* Defaults go here */
|
||||||
|
|
||||||
fh = fopen(strcat(modelname, ".propdata"), FILE_READ);
|
fh = fopen(strcat(modelname, ".propdata"), FILE_READ);
|
||||||
|
|
||||||
|
/* not found. try again? */
|
||||||
if (fh < 0) {
|
if (fh < 0) {
|
||||||
/* try the Source Engine version */
|
/* try the Source Engine version */
|
||||||
fh = fopen(Util_ChangeExtension(modelname, "phy"), FILE_READ);
|
fh = fopen(Util_ChangeExtension(modelname, "phy"), FILE_READ);
|
||||||
|
@ -391,12 +392,67 @@ PropData_ForModel(string modelname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(fh);
|
||||||
|
|
||||||
|
/* now, we read the Source .mdl file to get the extra prop_data keys that couldn't make it */
|
||||||
|
fh = fopen(modelname, FILE_READ);
|
||||||
|
|
||||||
|
if (fh >= 0) {
|
||||||
|
int surfaceProp;
|
||||||
|
int keyValueIndex;
|
||||||
|
int keyValueCount;
|
||||||
|
bool readData = false;
|
||||||
|
|
||||||
|
filePos = fseek(fh, 0x0134); /* forward to surfaceProp address */
|
||||||
|
fread(fh, (void*)&surfaceProp, 4);
|
||||||
|
fread(fh, (void*)&keyValueIndex, 4);
|
||||||
|
fread(fh, (void*)&keyValueCount, 4);
|
||||||
|
|
||||||
|
/* read surfaceProp */
|
||||||
|
filePos = fseek(fh, surfaceProp);
|
||||||
|
g_propdata[index].surfaceprop = strcat(fgets(fh));
|
||||||
|
|
||||||
|
/* read key/value pairs */
|
||||||
|
filePos = fseek(fh, keyValueIndex);
|
||||||
|
|
||||||
|
for (int keys = 0i; keys < keyValueCount; keys++) {
|
||||||
|
string keyValueLine = fgets(fh);
|
||||||
|
int ab = tokenize(keyValueLine);
|
||||||
|
|
||||||
|
if (keyValueLine == "prop_data {") {
|
||||||
|
readData = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (readData && keyValueLine != "") {
|
||||||
|
int keyCount = tokenize(keyValueLine);
|
||||||
|
|
||||||
|
for (int realKeys = 0i; realKeys < keyCount; realKeys+=2) {
|
||||||
|
PropData_ParseField(index, argv(realKeys), argv(realKeys+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
readData = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float ofs = strstrofs(g_propdata[index].surfaceprop, "\xc0\x80");
|
||||||
|
|
||||||
|
if (ofs >= 0) {
|
||||||
|
g_propdata[index].surfaceprop = substring(g_propdata[index].surfaceprop, 0, ofs);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//print(sprintf("Added %S at id %i with name %S\n", modelname, index, g_propdata[index].name));
|
//print(sprintf("Added %S at id %i with name %S\n", modelname, index, g_propdata[index].name));
|
||||||
hash_add(g_hashpropdata, modelname, (int)index);
|
hash_add(g_hashpropdata, modelname, (int)index);
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
//error(sprintf("phy file (size %i): size: %i id: %i numSolids: %i\n", fsize(fh), fileSize, phyID, numSolids));
|
//error(sprintf("phy file (size %i): size: %i id: %i numSolids: %i\n", fsize(fh), fileSize, phyID, numSolids));
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((line = fgets(fh))) {
|
while ((line = fgets(fh))) {
|
||||||
/* when we found it, quit */
|
/* when we found it, quit */
|
||||||
if (PropData_Parse(index, line, modelname) == TRUE) {
|
if (PropData_Parse(index, line, modelname) == TRUE) {
|
||||||
|
@ -517,7 +573,7 @@ PropData_ParseLine(string line)
|
||||||
if (key == "") {
|
if (key == "") {
|
||||||
break;
|
break;
|
||||||
} else if (braced == 2 && t_name != "" && inmodel == FALSE) {
|
} else if (braced == 2 && t_name != "" && inmodel == FALSE) {
|
||||||
PropData_ParseField(i_p, c);
|
PropData_ParseField(i_p, argv(0), argv(1));
|
||||||
} else if (braced == 3 && t_name != "" && inmodel == TRUE) {
|
} else if (braced == 3 && t_name != "" && inmodel == TRUE) {
|
||||||
BreakModel_ParseField(i_b, c);
|
BreakModel_ParseField(i_b, c);
|
||||||
} else if (braced == 1) {
|
} else if (braced == 1) {
|
||||||
|
|
Loading…
Reference in a new issue