22
33#include < BufferStream.h>
44#include < sourcepp/detail/BufferUtils.h>
5+ #include < iostream>
56
67using namespace sourcepp ;
78using namespace sourcepp ::detail;
@@ -45,13 +46,13 @@ bool MDL::open(const std::byte* data, std::size_t size) {
4546 int hitboxSetCount = stream.read <int >();
4647 int hitboxSetOffset = stream.read <int >();
4748
48- // int animDescCount = stream.read<int>();
49- // int animDescOffset = stream.read<int>();
49+ // int animDescCount = stream.read<int>();
50+ // int animDescOffset = stream.read<int>();
5051 stream.skip <int >(2 );
5152
52- // int sequenceDescCount = stream.read<int>();
53- // int sequenceDescOffset = stream.read<int>();
54- stream.skip <int >(2 );
53+ int sequenceDescCount = stream.read <int >();
54+ int sequenceDescOffset = stream.read <int >();
55+ // stream.skip<int>(2);
5556
5657 stream.read (this ->activityListVersion );
5758 stream.read (this ->eventsIndexed );
@@ -62,8 +63,10 @@ bool MDL::open(const std::byte* data, std::size_t size) {
6263 int materialDirCount = stream.read <int >();
6364 int materialDirOffset = stream.read <int >();
6465
65- // todo: skins
66- stream.skip <int >(3 );
66+ int skinReferenceCount = stream.read <int >();
67+ int skinReferenceFamilyCount = stream.read <int >();
68+ int skinReferenceOffset = stream.read <int >();
69+
6770
6871 int bodyPartCount = stream.read <int >();
6972 int bodyPartOffset = stream.read <int >();
@@ -167,6 +170,28 @@ bool MDL::open(const std::byte* data, std::size_t size) {
167170 readStringAtOffset (stream, materialDir, std::ios::beg, 0 );
168171 }
169172
173+ // The short is the skindex of a material in the this.materials vector.
174+ // The skin family is the amount of textures per skin.
175+ // As weird as the valve developer wiki makes it out.
176+ // The two numbers:
177+ // (skin0) -> (00 00)(material0) (02 00)(material2)
178+ // (skin0) -> (01 00)(material1) (02 00)(material2)
179+ // (skin0) -> (02 00)(material2) (02 00)(material2)
180+ // Are two bytes grouped into a short.
181+ stream.seek (skinReferenceOffset);
182+ for (int i = 0 ; i < skinReferenceFamilyCount; i++)
183+ {
184+ std::vector<short > skinFamily;
185+ for (int j = 0 ; j < skinReferenceCount; j++)
186+ {
187+ short skin;
188+ stream.read <short >(skin);
189+ skinFamily.push_back (skin);
190+ std::cout << " material index " << j << " (material: " << materials[skin].name << " )" << " of skin" << i << std::endl;
191+ }
192+ this ->skins .push_back (skinFamily);
193+ }
194+
170195 for (int i = 0 ; i < bodyPartCount; i++) {
171196 auto bodyPartPos = bodyPartOffset + i * (sizeof (int ) * 4 );
172197 stream.seek (bodyPartPos);
0 commit comments