1818#include < miniz.h>
1919#include < zstd.h>
2020
21+ #include < sourcepp/Bits.h>
2122#include < sourcepp/compression/LZMA.h>
2223#include < vtfpp/ImageConversion.h>
2324
2425using namespace sourcepp ;
26+ using namespace sourcepp ::bits;
2527using namespace vtfpp ;
2628
2729namespace {
@@ -180,13 +182,13 @@ Resource::ConvertedData Resource::convertData() const {
180182 if (this ->data .size () <= sizeof (uint32_t )) {
181183 return {};
182184 }
183- return SHT{{reinterpret_cast <const std::byte*>(this ->data .data ()) + sizeof (uint32_t ), * reinterpret_cast < const uint32_t * >(this ->data .data ())}};
185+ return SHT{{reinterpret_cast <const std::byte*>(this ->data .data ()) + sizeof (uint32_t ), reinterpret_le< uint32_t >(this ->data .data ())}};
184186 case TYPE_CRC:
185187 case TYPE_EXTENDED_FLAGS:
186188 if (this ->data .size () != sizeof (uint32_t )) {
187189 return {};
188190 }
189- return * reinterpret_cast < const uint32_t * >(this ->data .data ());
191+ return reinterpret_le< uint32_t >(this ->data .data ());
190192 case TYPE_LOD_CONTROL_INFO:
191193 if (this ->data .size () != sizeof (uint32_t )) {
192194 return {};
@@ -200,17 +202,17 @@ Resource::ConvertedData Resource::convertData() const {
200202 if (this ->data .size () <= sizeof (uint32_t )) {
201203 return " " ;
202204 }
203- return std::string (reinterpret_cast <const char *>(this ->data .data ()) + sizeof (uint32_t ), * reinterpret_cast < const uint32_t * >(this ->data .data ()));
205+ return std::string (reinterpret_cast <const char *>(this ->data .data ()) + sizeof (uint32_t ), reinterpret_le< uint32_t >(this ->data .data ()));
204206 case TYPE_HOTSPOT_DATA:
205207 if (this ->data .size () <= sizeof (uint32_t )) {
206208 return {};
207209 }
208- return HOT{{reinterpret_cast <const std::byte*>(this ->data .data ()) + sizeof (uint32_t ), * reinterpret_cast < const uint32_t * >(this ->data .data ())}};
210+ return HOT{{reinterpret_cast <const std::byte*>(this ->data .data ()) + sizeof (uint32_t ), reinterpret_le< uint32_t >(this ->data .data ())}};
209211 case TYPE_AUX_COMPRESSION:
210212 if (this ->data .size () <= sizeof (uint32_t ) || this ->data .size () % sizeof (uint32_t ) != 0 ) {
211213 return {};
212214 }
213- return std::span{reinterpret_cast <uint32_t *>(this ->data .data ()), this ->data .size () / 4 };
215+ return std::span{reinterpret_cast <ui32le *>(this ->data .data ()), this ->data .size () / 4 };
214216 default :
215217 break ;
216218 }
@@ -303,16 +305,16 @@ VTF::VTF(std::vector<std::byte>&& vtfData, bool parseHeaderOnly)
303305 if (!(lhs.flags & Resource::FLAG_LOCAL_DATA) && (rhs.flags & Resource::FLAG_LOCAL_DATA)) {
304306 return false ;
305307 }
306- return * reinterpret_cast <uint32_t * >(lhs.data .data ()) < * reinterpret_cast <uint32_t * >(rhs.data .data ());
308+ return reinterpret_le <uint32_t >(lhs.data .data ()) < reinterpret_le <uint32_t >(rhs.data .data ());
307309 });
308310
309311 // Fix up data spans to point to the actual data
310312 Resource* lastResource = nullptr ;
311313 for (auto & resource : this ->resources ) {
312314 if (!(resource.flags & Resource::FLAG_LOCAL_DATA)) {
313315 if (lastResource) {
314- const auto lastOffset = * reinterpret_cast <uint32_t * >(lastResource->data .data ());
315- const auto currentOffset = * reinterpret_cast <uint32_t * >(resource.data .data ());
316+ const auto lastOffset = reinterpret_le <uint32_t >(lastResource->data .data ());
317+ const auto currentOffset = reinterpret_le <uint32_t >(resource.data .data ());
316318 const auto curPos = stream.tell ();
317319 stream.seek (lastOffset);
318320 lastResource->data = stream.read_span <std::byte>(currentOffset - lastOffset);
@@ -322,7 +324,7 @@ VTF::VTF(std::vector<std::byte>&& vtfData, bool parseHeaderOnly)
322324 }
323325 }
324326 if (lastResource) {
325- auto offset = * reinterpret_cast <uint32_t * >(lastResource->data .data ());
327+ auto offset = reinterpret_le <uint32_t >(lastResource->data .data ());
326328 auto curPos = stream.tell ();
327329 stream.seek (offset);
328330 lastResource->data = stream.read_span <std::byte>(stream.size () - offset);
0 commit comments