+ buffer = p;
+ }
+ else if (!strcmp(pchunk->id, "FACE0000"))
+ {
+ pskface_t *p;
+ if (recordsize != sizeof(*p))
+ Host_Error("%s: %s has unsupported recordsize", loadmodel->name, pchunk->id);
+ // byteswap in place and keep the pointer
+ numfaces = numrecords;
+ faces = (pskface_t *)buffer;
+ for (index = 0, p = (pskface_t *)buffer;index < numrecords;index++, p++)
+ {
+ p->vtxwindex[0] = LittleShort(p->vtxwindex[0]);
+ p->vtxwindex[1] = LittleShort(p->vtxwindex[1]);
+ p->vtxwindex[2] = LittleShort(p->vtxwindex[2]);
+ p->group = LittleLong(p->group);
+ if (p->vtxwindex[0] >= numvtxw)
+ {
+ Con_Printf("%s: face->vtxwindex[0] %i >= numvtxw %i\n", loadmodel->name, p->vtxwindex[0], numvtxw);
+ p->vtxwindex[0] = 0;
+ }
+ if (p->vtxwindex[1] >= numvtxw)
+ {
+ Con_Printf("%s: face->vtxwindex[1] %i >= numvtxw %i\n", loadmodel->name, p->vtxwindex[1], numvtxw);
+ p->vtxwindex[1] = 0;
+ }
+ if (p->vtxwindex[2] >= numvtxw)
+ {
+ Con_Printf("%s: face->vtxwindex[2] %i >= numvtxw %i\n", loadmodel->name, p->vtxwindex[2], numvtxw);
+ p->vtxwindex[2] = 0;
+ }
+ }
+ buffer = p;
+ }
+ else if (!strcmp(pchunk->id, "MATT0000"))
+ {
+ pskmatt_t *p;
+ if (recordsize != sizeof(*p))
+ Host_Error("%s: %s has unsupported recordsize", loadmodel->name, pchunk->id);
+ // byteswap in place and keep the pointer
+ nummatts = numrecords;
+ matts = (pskmatt_t *)buffer;
+ for (index = 0, p = (pskmatt_t *)buffer;index < numrecords;index++, p++)
+ {
+ }
+ buffer = p;
+ }
+ else if (!strcmp(pchunk->id, "REFSKELT"))
+ {
+ pskboneinfo_t *p;
+ if (recordsize != sizeof(*p))
+ Host_Error("%s: %s has unsupported recordsize", loadmodel->name, pchunk->id);
+ // byteswap in place and keep the pointer
+ numbones = numrecords;
+ bones = (pskboneinfo_t *)buffer;
+ for (index = 0, p = (pskboneinfo_t *)buffer;index < numrecords;index++, p++)
+ {
+ p->numchildren = LittleLong(p->numchildren);
+ p->parent = LittleLong(p->parent);
+ p->basepose.quat[0] = LittleFloat(p->basepose.quat[0]);
+ p->basepose.quat[1] = LittleFloat(p->basepose.quat[1]);
+ p->basepose.quat[2] = LittleFloat(p->basepose.quat[2]);
+ p->basepose.quat[3] = LittleFloat(p->basepose.quat[3]);
+ p->basepose.origin[0] = LittleFloat(p->basepose.origin[0]);
+ p->basepose.origin[1] = LittleFloat(p->basepose.origin[1]);
+ p->basepose.origin[2] = LittleFloat(p->basepose.origin[2]);
+ p->basepose.unknown = LittleFloat(p->basepose.unknown);
+ p->basepose.size[0] = LittleFloat(p->basepose.size[0]);
+ p->basepose.size[1] = LittleFloat(p->basepose.size[1]);
+ p->basepose.size[2] = LittleFloat(p->basepose.size[2]);
+#ifdef PSKQUATNEGATIONS
+ if (index)
+ {
+ p->basepose.quat[0] *= -1;
+ p->basepose.quat[1] *= -1;
+ p->basepose.quat[2] *= -1;
+ }
+ else
+ {
+ p->basepose.quat[0] *= 1;
+ p->basepose.quat[1] *= -1;
+ p->basepose.quat[2] *= 1;
+ }
+#endif
+ if (p->parent < 0 || p->parent >= numbones)
+ {
+ Con_Printf("%s: bone->parent %i >= numbones %i\n", loadmodel->name, p->parent, numbones);
+ p->parent = 0;
+ }
+ }
+ buffer = p;
+ }
+ else if (!strcmp(pchunk->id, "RAWWEIGHTS"))
+ {
+ pskrawweights_t *p;
+ if (recordsize != sizeof(*p))
+ Host_Error("%s: %s has unsupported recordsize", loadmodel->name, pchunk->id);
+ // byteswap in place and keep the pointer
+ numrawweights = numrecords;
+ rawweights = (pskrawweights_t *)buffer;
+ for (index = 0, p = (pskrawweights_t *)buffer;index < numrecords;index++, p++)
+ {
+ p->weight = LittleFloat(p->weight);
+ p->pntsindex = LittleLong(p->pntsindex);
+ p->boneindex = LittleLong(p->boneindex);
+ if (p->pntsindex < 0 || p->pntsindex >= numpnts)
+ {
+ Con_Printf("%s: weight->pntsindex %i >= numpnts %i\n", loadmodel->name, p->pntsindex, numpnts);
+ p->pntsindex = 0;
+ }
+ if (p->boneindex < 0 || p->boneindex >= numbones)
+ {
+ Con_Printf("%s: weight->boneindex %i >= numbones %i\n", loadmodel->name, p->boneindex, numbones);
+ p->boneindex = 0;
+ }
+ }
+ buffer = p;
+ }
+ }
+
+ while (animbuffer < animbufferend)
+ {
+ pchunk = (pskchunk_t *)animbuffer;
+ animbuffer = (void *)((unsigned char *)animbuffer + sizeof(pskchunk_t));
+ version = LittleLong(pchunk->version);
+ recordsize = LittleLong(pchunk->recordsize);
+ numrecords = LittleLong(pchunk->numrecords);
+ if (developer.integer >= 100)
+ Con_Printf("%s: %s %x: %i * %i = %i\n", animname, pchunk->id, version, recordsize, numrecords, recordsize * numrecords);
+ if (version != 0x1e83b9 && version != 0x1e9179 && version != 0x2e && version != 0x12f2bc && version != 0x12f2f0)
+ Con_Printf ("%s: chunk %s has unknown version %x (0x1e83b9, 0x1e9179, 0x2e, 0x12f2bc, 0x12f2f0 are currently supported), trying to load anyway!\n", animname, pchunk->id, version);
+ if (!strcmp(pchunk->id, "ANIMHEAD"))
+ {
+ // nothing to do
+ }
+ else if (!strcmp(pchunk->id, "BONENAMES"))
+ {
+ pskboneinfo_t *p;
+ if (recordsize != sizeof(*p))
+ Host_Error("%s: %s has unsupported recordsize", animname, pchunk->id);
+ // byteswap in place and keep the pointer
+ numanimbones = numrecords;
+ animbones = (pskboneinfo_t *)animbuffer;
+ // NOTE: supposedly psa does not need to match the psk model, the
+ // bones missing from the psa would simply use their base
+ // positions from the psk, but this is hard for me to implement
+ // and people can easily make animations that match.
+ if (numanimbones != numbones)
+ Host_Error("%s: this loader only supports animations with the same bones as the mesh");
+ for (index = 0, p = (pskboneinfo_t *)animbuffer;index < numrecords;index++, p++)
+ {
+ p->numchildren = LittleLong(p->numchildren);
+ p->parent = LittleLong(p->parent);
+ p->basepose.quat[0] = LittleFloat(p->basepose.quat[0]);
+ p->basepose.quat[1] = LittleFloat(p->basepose.quat[1]);
+ p->basepose.quat[2] = LittleFloat(p->basepose.quat[2]);
+ p->basepose.quat[3] = LittleFloat(p->basepose.quat[3]);
+ p->basepose.origin[0] = LittleFloat(p->basepose.origin[0]);
+ p->basepose.origin[1] = LittleFloat(p->basepose.origin[1]);
+ p->basepose.origin[2] = LittleFloat(p->basepose.origin[2]);
+ p->basepose.unknown = LittleFloat(p->basepose.unknown);
+ p->basepose.size[0] = LittleFloat(p->basepose.size[0]);
+ p->basepose.size[1] = LittleFloat(p->basepose.size[1]);
+ p->basepose.size[2] = LittleFloat(p->basepose.size[2]);
+#ifdef PSKQUATNEGATIONS
+ if (index)
+ {
+ p->basepose.quat[0] *= -1;
+ p->basepose.quat[1] *= -1;
+ p->basepose.quat[2] *= -1;
+ }
+ else
+ {
+ p->basepose.quat[0] *= 1;
+ p->basepose.quat[1] *= -1;
+ p->basepose.quat[2] *= 1;
+ }
+#endif
+ if (p->parent < 0 || p->parent >= numanimbones)
+ {
+ Con_Printf("%s: bone->parent %i >= numanimbones %i\n", animname, p->parent, numanimbones);
+ p->parent = 0;
+ }
+ // check that bones are the same as in the base
+ if (strcmp(p->name, bones[index].name) || p->parent != bones[index].parent)
+ Host_Error("%s: this loader only supports animations with the same bones as the mesh", animname);
+ }
+ animbuffer = p;
+ }
+ else if (!strcmp(pchunk->id, "ANIMINFO"))
+ {
+ pskaniminfo_t *p;
+ if (recordsize != sizeof(*p))
+ Host_Error("%s: %s has unsupported recordsize", animname, pchunk->id);
+ // byteswap in place and keep the pointer
+ numanims = numrecords;
+ anims = (pskaniminfo_t *)animbuffer;
+ for (index = 0, p = (pskaniminfo_t *)animbuffer;index < numrecords;index++, p++)
+ {
+ p->numbones = LittleLong(p->numbones);
+ p->playtime = LittleFloat(p->playtime);
+ p->fps = LittleFloat(p->fps);
+ p->firstframe = LittleLong(p->firstframe);
+ p->numframes = LittleLong(p->numframes);
+ if (p->numbones != numbones)
+ {
+ Con_Printf("%s: animinfo->numbones != numbones, trying to load anyway!\n", animname);
+ }
+ }
+ animbuffer = p;
+ }
+ else if (!strcmp(pchunk->id, "ANIMKEYS"))
+ {
+ pskanimkeys_t *p;
+ if (recordsize != sizeof(*p))
+ Host_Error("%s: %s has unsupported recordsize", animname, pchunk->id);
+ numanimkeys = numrecords;
+ animkeys = (pskanimkeys_t *)animbuffer;
+ for (index = 0, p = (pskanimkeys_t *)animbuffer;index < numrecords;index++, p++)