Code:
#include <amxmodx>
const LabelMaxLength = 64;
enum _:BodyParts
{
m_bodyname[LabelMaxLength],
m_nummodels,
m_base,
m_modelindex,
Array:m_models,
};
public plugin_init()
{
new Array:list = getBodygroupsList("models/backweapons2.mdl");
if (list != Invalid_Array)
{
new data[BodyParts];
server_print("^nBodyparts list:^n-");
for (new bodypart = 0, count = ArraySize(list); bodypart < count; ++bodypart)
{
ArrayGetArray(list, bodypart, data);
server_print("Group #1 : ^"%s^"^n", data[m_bodyname]);
server_print("^t Count : %d", data[m_nummodels]);
server_print("^t Base : %d", data[m_base]);
server_print("^t Index : %d", data[m_modelindex]);
server_print("^n^t Models:");
for (new model = 0; model < data[m_nummodels]; ++model)
{
server_print("^t^t %a", ArrayGetStringHandle(data[m_models], model));
}
}
ArrayDestroy(list);
}
}
Array:getBodygroupsList(const model[])
{
new Array:bodygroupsList = Invalid_Array;
new fp = fopen(model, "rb");
if (fp)
{
const studioHeader_NumBodyParts = 0xCC; // Reference index where to start reading in file
//const mstudiobodyparts_Size = 0x4C; // The mstudiobodyparts_t structure size
const mstudiomodel_Size = 0x70; // The mstudiomodel_t structure size
new bodypartCount; // Number of bodygroups
new bodypartIndex; // Reference index where to start reading in file
fseek(fp, studioHeader_NumBodyParts, SEEK_SET);
fread(fp, bodypartCount, BLOCK_INT);
if (!bodypartCount)
{
return Invalid_Array;
}
fread(fp, bodypartIndex, BLOCK_INT);
fseek(fp, bodypartIndex, SEEK_SET);
new data[BodyParts];
new label[LabelMaxLength];
bodygroupsList = ArrayCreate(sizeof(data), bodypartCount);
for (new bodypart = 0; bodypart < bodypartCount; ++bodypart)
{
fread_blocks(fp, data[m_bodyname], sizeof(data[m_bodyname]), BLOCK_CHAR);
fread(fp, data[m_nummodels], BLOCK_INT);
fread(fp, data[m_base], BLOCK_INT);
fread(fp, data[m_modelindex], BLOCK_INT);
if (!data[m_nummodels])
{
continue;
}
data[m_models] = ArrayCreate(LabelMaxLength, data[m_nummodels]);
for (new model = 0; model < data[m_nummodels]; ++model)
{
fread_blocks(fp, label, sizeof(label), BLOCK_CHAR);
fseek(fp, mstudiomodel_Size - sizeof(label), SEEK_CUR); // We don't read all the structure, so we need to jump to next reference
ArrayPushString(data[m_models], label);
}
ArrayPushArray(bodygroupsList, data);
}
fclose(fp);
}
return bodygroupsList;
}