This repository has been archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIVModelInfo.h
executable file
·498 lines (383 loc) · 13 KB
/
IVModelInfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#pragma once
class Quaternion;
struct mstudioanimdesc_t;
struct mstudioseqdesc_t;
struct mstudiobodyparts_t;
struct mstudiotexture_t;
class RadianEuler
{
public:
inline RadianEuler(void) { }
inline RadianEuler(float X, float Y, float Z)
{
x = X;
y = Y;
z = Z;
}
inline RadianEuler(Quaternion const &q); // evil auto type promotion!!!
inline RadianEuler(QAngle const &angles); // evil auto type promotion!!!
// Initialization
inline void Init(float ix = 0.0f, float iy = 0.0f, float iz = 0.0f)
{
x = ix;
y = iy;
z = iz;
}
// conversion to qangle
QAngle ToQAngle(void) const;
bool IsValid() const;
void Invalidate();
inline float *Base()
{
return &x;
}
inline const float *Base() const
{
return &x;
}
// array access...
float operator[](int i) const;
float &operator[](int i);
float x, y, z;
};
class Quaternion // same data-layout as engine's vec4_t,
{ // which is a float[4]
public:
inline Quaternion(void) { }
inline Quaternion(float ix, float iy, float iz, float iw) : x(ix), y(iy), z(iz), w(iw) { }
inline Quaternion(RadianEuler const &angle); // evil auto type promotion!!!
inline void Init(float ix = 0.0f, float iy = 0.0f, float iz = 0.0f, float iw = 0.0f)
{
x = ix;
y = iy;
z = iz;
w = iw;
}
bool IsValid() const;
void Invalidate();
bool operator==(const Quaternion &src) const;
bool operator!=(const Quaternion &src) const;
float *Base()
{
return (float *) this;
}
const float *Base() const
{
return (float *) this;
}
// array access...
float operator[](int i) const;
float &operator[](int i);
float x, y, z, w;
};
struct mstudiobone_t {
int sznameindex;
inline char *const pszName(void) const
{
return ((char *) this) + sznameindex;
}
int parent; // parent bone
int bonecontroller[6]; // bone controller index, -1 == none
// default values
Vector pos;
Quaternion quat;
RadianEuler rot;
// compression scale
Vector posscale;
Vector rotscale;
matrix3x4_t poseToBone;
Quaternion qAlignment;
int flags;
int proctype;
int procindex; // procedural rule
mutable int physicsbone; // index into physically simulated bone
inline void *pProcedure() const
{
if (procindex == 0)
return NULL;
else
return (void *) (((unsigned char *) this) + procindex);
};
int surfacepropidx; // index into string tablefor property name
inline char *const pszSurfaceProp(void) const
{
return ((char *) this) + surfacepropidx;
}
inline int GetSurfaceProp(void) const
{
return surfacepropLookup;
}
int contents; // See BSPFlags.h for the contents flags
int surfacepropLookup; // this index must be cached by the loader, not saved in the file
int unused[7]; // remove as appropriate
};
struct mstudiobbox_t {
int bone;
int group;
Vector bbmin;
Vector bbmax;
int hitboxnameindex;
int pad[3];
float radius;
int pad2[4];
char *pszHitboxName()
{
if (hitboxnameindex == 0)
return NULL;
return ((char *) this) + hitboxnameindex;
}
};
struct mstudiohitboxset_t {
int sznameindex;
inline char *const pszName() const
{
return ((char *) this) + sznameindex;
}
int numhitboxes;
int hitboxindex;
inline mstudiobbox_t *pHitbox(int i) const
{
return (mstudiobbox_t *) (((unsigned char *) this) + hitboxindex) + i;
};
};
struct studiohdr_t {
int id;
int version;
int checksum; // this has to be the same in the phy and vtx files to load!
char name[64];
int length;
Vector eyeposition; // ideal eye position
Vector illumposition; // illumination center
Vector hull_min; // ideal movement hull size
Vector hull_max;
Vector view_bbmin; // clipping bounding box
Vector view_bbmax;
int flags;
int numbones; // bones
int boneindex;
inline mstudiobone_t *pBone(int i) const
{
Assert(i >= 0 && i < numbones);
return (mstudiobone_t *)(((unsigned char * ) this) + boneindex ) + i;
};
int RemapSeqBone(int iSequence, int iLocalBone) const; // maps local sequence bone to global bone
int RemapAnimBone(int iAnim, int iLocalBone) const; // maps local animations bone to global bone
int numbonecontrollers; // bone controllers
int bonecontrollerindex;
int numhitboxsets;
int hitboxsetindex;
// Look up hitbox set by index
mstudiohitboxset_t *pHitboxSet(int i) const
{
(i >= 0 && i < numhitboxsets);
return (mstudiohitboxset_t * )(((unsigned char * ) this ) +hitboxsetindex ) +i;
};
// Calls through to hitbox to determine size of specified set
inline mstudiobbox_t *pHitbox(int i, int set) const
{
mstudiohitboxset_t const *s = pHitboxSet(set);
if (!s)
return NULL;
return s->pHitbox(i);
};
// Calls through to set to get hitbox count for set
inline int iHitboxCount(int set) const
{
mstudiohitboxset_t const *s = pHitboxSet(set);
if (!s)
return 0;
return s->numhitboxes;
};
// file local animations? and sequences
//private:
int numlocalanim; // animations/poses
int localanimindex; // animation descriptions
int numlocalseq; // sequences
int localseqindex;
//public:
bool SequencesAvailable() const;
int GetNumSeq() const;
int iRelativeAnim(int baseseq, int relanim) const; // maps seq local anim reference to global anim index
int iRelativeSeq(int baseseq, int relseq) const; // maps seq local seq reference to global seq index
//private:
mutable int activitylistversion; // initialization flag - have the sequences been indexed?
mutable int eventsindexed;
//public:
int GetSequenceActivity(int iSequence);
void SetSequenceActivity(int iSequence, int iActivity);
int GetActivityListVersion();
void SetActivityListVersion(int version) const;
int GetEventListVersion();
void SetEventListVersion(int version);
// raw textures
int numtextures;
int textureindex;
// raw textures search paths
int numcdtextures;
int cdtextureindex;
inline char *pCdtexture(int i) const
{
return (((char *) this) + *((int *) (((unsigned char *) this) +cdtextureindex) + i));
};
// replaceable textures tables
int numskinref;
int numskinfamilies;
int skinindex;
inline short *pSkinref(int i) const
{
return (short *) (((unsigned char *) this) +skinindex) +i;
};
int numbodyparts;
int bodypartindex;
// queryable attachable points
//private:
int numlocalattachments;
int localattachmentindex;
//public:
int GetNumAttachments() const;
int GetAttachmentBone(int i);
// used on my tools in hlmv, not persistant
void SetAttachmentBone(int iAttachment, int iBone);
// animation node to animation node transition graph
//private:
int numlocalnodes;
int localnodeindex;
int localnodenameindex;
inline char *pszLocalNodeName(int iNode) const
{
(iNode >= 0 && iNode < numlocalnodes);
return (((char *) this) + *((int *) (((unsigned char *) this) + localnodenameindex) + iNode));
}
inline unsigned char *pLocalTransition(int i) const
{
(i >= 0 && i < (numlocalnodes * numlocalnodes));
return (unsigned char * )(((unsigned char *) this) + localnodeindex) + i;
};
//public:
int EntryNode(int iSequence);
int ExitNode(int iSequence);
char *pszNodeName(int iNode);
int GetTransition(int iFrom, int iTo) const;
int numflexdesc;
int flexdescindex;
int numflexcontrollers;
int flexcontrollerindex;
int numflexrules;
int flexruleindex;
int numikchains;
int ikchainindex;
int nummouths;
int mouthindex;
//private:
int numlocalposeparameters;
int localposeparamindex;
//public:
int GetNumPoseParameters() const;
int GetSharedPoseParameter(int iSequence, int iLocalPose) const;
int surfacepropindex;
inline char *const pszSurfaceProp() const
{
return ((char *) this) + surfacepropindex;
}
// Key values
int keyvalueindex;
int keyvaluesize;
inline const char *KeyValueText() const
{
return keyvaluesize != 0 ? ((char *) this) + keyvalueindex : NULL;
}
int numlocalikautoplaylocks;
int localikautoplaylockindex;
int GetNumIKAutoplayLocks() const;
int CountAutoplaySequences() const;
int CopyAutoplaySequences(unsigned short *pOut, int outCount) const;
int GetAutoplayList(unsigned short **pOut) const;
// The collision model mass that jay wanted
float mass;
int contents;
// external animations, models, etc.
int numincludemodels;
int includemodelindex;
// implementation specific call to get a named model
const studiohdr_t *FindModel(void **cache, char const *modelname) const;
// implementation specific back pointer to virtual data
mutable void *virtualModel;
//virtualmodel_t GetVirtualModel() const;
// for demand loaded animation blocks
int szanimblocknameindex;
inline char *const pszAnimBlockName() const
{
return ((char *) this) + szanimblocknameindex;
}
int numanimblocks;
int animblockindex;
mutable void *animblockModel;
unsigned char *GetAnimBlock(int i) const;
int bonetablebynameindex;
inline const unsigned char *GetBoneTableSortedByName() const
{
return (unsigned char *) this + bonetablebynameindex;
}
// used by tools only that don't cache, but persist mdl's peer data
// engine uses virtualModel to back link to cache pointers
void *pVertexBase;
void *pIndexBase;
// if STUDIOHDR_FLAGS_CONSTANT_DIRECTIONAL_LIGHT_DOT is set,
// this value is used to calculate directional components of lighting
// on static props
unsigned char constdirectionallightdot;
// set during load of mdl data to track *desired* lod configuration (not actual)
// the *actual* clamped root lod is found in studiohwdata
// this is stored here as a global store to ensure the staged loading matches the rendering
unsigned char rootLOD;
// set in the mdl data to specify that lod configuration should only allow first numAllowRootLODs
// to be set as root LOD:
// numAllowedRootLODs = 0 means no restriction, any lod can be set as root lod.
// numAllowedRootLODs = N means that lod0 - lod(N-1) can be set as root lod, but not lodN or lower.
unsigned char numAllowedRootLODs;
unsigned char unused[1];
int unused4; // zero out if version < 47
int numflexcontrollerui;
int flexcontrolleruiindex;
int unused3[2];
// FIXME: Remove when we up the model version. Move all fields of studiohdr2_t into studiohdr_t.
int studiohdr2index;
// NOTE: No room to add stuff? Up the .mdl file format version
// [and move all fields in studiohdr2_t into studiohdr_t and kill studiohdr2_t],
// or add your stuff to studiohdr2_t. See NumSrcBoneTransforms/SrcBoneTransform for the pattern to use.
int unused2[1];
studiohdr_t() { }
private:
// No copy constructors allowed
studiohdr_t(const studiohdr_t &vOther);
friend struct virtualmodel_t;
};
class IVModelInfo
{
public:
model_t* GetModel(int index)
{
typedef model_t* (* oGetModel)(void*, int);
return getvfunc<oGetModel>(this, 2)(this, index);
}
int GetModelIndex(const char* Filename)
{
typedef int (* oGetModelIndex)(void*, const char*);
return getvfunc<oGetModelIndex>(this, 3)(this, Filename);
}
const char* GetModelName(const model_t *model)
{
typedef const char* (* oGetModelName)(void*, const model_t*);
return getvfunc<oGetModelName>(this, 4)(this, model);
}
void GetModelMaterials(const model_t *model, int count, IMaterial** ppMaterial)
{
typedef studiohdr_t* (* oGetModelMaterials)(void*, const model_t*, int, IMaterial**);
getvfunc<oGetModelMaterials>(this, 18)(this, model, count, ppMaterial);
}
studiohdr_t* GetStudioModel(const model_t* model)
{
typedef studiohdr_t* (* oGetStudioModel)(void*, const model_t*);
return getvfunc<oGetStudioModel>(this, 31)(this, model);
}
};