World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
LOD.cpp
См. документацию.
1 #include "Engine/LOD.h"
2 
3 #include "Engine/Engine.h"
4 #include "Engine/ZlibWrapper.h"
5 
9 
11 
15 
19 
23 
25 LOD::File *pGames_LOD = nullptr;
26 
29 
31  for (unsigned int i = 0; i < uNumLoadedFiles; ++i)
32  if (!strcmp(pTextures[i].header.pName, "pending")) return i;
33  return LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending",
35 }
36 
40 }
41 
44 }
45 
48 }
49 
53 }
54 
58 }
59 
61  if (this->uTexturePacksCount) {
62  if ((this->uNumLoadedFiles - 1) >= this->uNumPrevLoadedFiles) {
63  for (uint i = this->uNumLoadedFiles - 1;
64  i >= this->uNumPrevLoadedFiles; --i) {
65  this->pTextures[i].Release();
66  }
67  }
69  this->uNumPrevLoadedFiles = 0;
70  this->uTexturePacksCount = 0;
71  }
72 }
73 
75  if (this->uTexturePacksCount) {
76  this->uTexturePacksCount--;
77  if (!this->uTexturePacksCount) {
78  if ((this->uNumLoadedFiles - 1) >= this->uNumPrevLoadedFiles) {
79  for (uint i = this->uNumLoadedFiles - 1;
80  i >= this->uNumPrevLoadedFiles; --i) {
81  this->pTextures[i].Release();
82  }
83  }
85  this->uNumPrevLoadedFiles = 0;
86  }
87  }
88 }
89 
90 #pragma pack(push, 1)
91 struct LODSpriteLine {
95 };
96 #pragma pack(pop)
97 
98 int LODFile_Sprites::LoadSpriteFromFile(LODSprite *pSprite, const String &pContainer) {
99  FILE *File = FindContainer(pContainer, 0);
100  if (File == nullptr) {
101  return -1;
102  }
103 
104  fread(pSprite, sizeof(LODSpriteHeader), 1, File);
105  strcpy(pSprite->pName, pContainer.c_str());
106  LODSpriteLine *pSpriteLines = new LODSpriteLine[pSprite->uHeight];
107  fread(pSpriteLines, sizeof(LODSpriteLine), pSprite->uHeight, File);
108 
109  uint8_t *pDecompressedBytes = nullptr;
110 
111  int Sizea = pSprite->uSpriteSize;
112  if (pSprite->uDecompressedSize) {
113  pDecompressedBytes = (uint8_t*)malloc(pSprite->uDecompressedSize);
114  void *DstBufa = malloc(Sizea);
115  fread(DstBufa, 1, Sizea, File);
116  zlib::Uncompress(pDecompressedBytes,
117  (unsigned int *)&pSprite->uDecompressedSize,
118  DstBufa, Sizea);
119  pSprite->uSpriteSize = pSprite->uDecompressedSize;
120  free(DstBufa);
121  } else {
122  pDecompressedBytes = (uint8_t*)malloc(Sizea);
123  fread(pDecompressedBytes, 1, Sizea, File);
124  }
125 
126  pSprite->bitmap = new uint8_t[pSprite->uWidth * pSprite->uHeight];
127  memset(pSprite->bitmap, 0, pSprite->uWidth * pSprite->uHeight);
128  for (uint i = 0; i < pSprite->uHeight; i++) {
129  if (pSpriteLines[i].begin >= 0) {
130  memcpy(pSprite->bitmap + (i * pSprite->uWidth) + pSpriteLines[i].begin,
131  pDecompressedBytes + pSpriteLines[i].offset,
132  pSpriteLines[i].end - pSpriteLines[i].begin);
133  }
134  }
135 
136  delete[] pSpriteLines;
137 
138  return 1;
139 }
140 
141 bool LODFile_Sprites::LoadSprites(const String &pFilename) {
142  if (!Open(pFilename)) {
143  return false;
144  }
145 
146  return LoadSubIndices("sprites08");
147 }
148 
149 int LODFile_Sprites::LoadSprite(const char *pContainerName, unsigned int uPaletteID) {
150  for (int i = 0; i < uNumLoadedSprites; ++i) {
151  if (pHardwareSprites[i].pName == pContainerName) {
152  return i;
153  }
154  }
155 
156  if (uNumLoadedSprites >= MAX_LOD_SPRITES) return -1;
157  // if not loaded - load from file
158 
159  if (!pHardwareSprites) {
160  pHardwareSprites = new Sprite[MAX_LOD_SPRITES];
161  }
162 
163  FILE *sprite_file = FindContainer(pContainerName, 0);
164  if (!sprite_file) {
165  return -1;
166  }
167 
168  static_assert(sizeof(LODSpriteHeader) == 32, "Wrong type size");
169 
170  LODSprite *header = new LODSprite();
171  LoadSpriteFromFile(header, pContainerName); // this line is not present here in the original.
172  // necessary for Grayface's mouse picking fix
173 
174  // if (uNumLoadedSprites == 879) __debugbreak();
175 
182 
183  HWLTexture *hwl = render->LoadHwlSprite(pContainerName);
184  if (hwl) {
191 
192  delete[] hwl->pPixels;
193  delete hwl;
194  }
195 
197  return uNumLoadedSprites - 1;
198 }
199 
201 
203 
205 
207  int result = (int)a2;
208  unsigned int v4 = a2->uTargetPitch;
209 
210  uint16_t *pTarget = (uint16_t*)a2->pTarget;
211  uint16_t *pPalette = a2->pPalette;
212  for (int y = 0; y < uHeight; y++) {
213  for (int x = 0; x < uWidth; x++) {
214  uint8_t color = bitmap[y * uWidth + x];
215  if (color != 0) {
216  pTarget[((a2->screen_space_y + y) * a2->uTargetPitch) + a2->screen_space_x + x] = pPalette[color];
217  }
218  }
219  }
220  return result;
221 }
222 
224  for (uint i = (uint)this->dword_11B84; i < this->uNumLoadedFiles; i++) {
225  this->pTextures[i].Release();
226  }
227  this->uTexturePacksCount = 0;
228  this->uNumPrevLoadedFiles = 0;
229  this->uNumLoadedFiles = this->dword_11B84;
230 }
231 
233  int *v1 = (int *)&this->uNumLoadedSprites;
234  int *v2 = &this->field_ECA0;
236 
237  // testing - do no reset sprite count as we are not clearing sprites
238  // see sprite::release below
239 
240  *v1 = *v2;
241 }
242 
244  if (!isFileOpened) {
245  return;
246  }
247 
248  pContainerName.clear();
249  pRoot.clear();
250  free(pSubIndices);
251  pSubIndices = nullptr;
252  fclose(pFile);
253  isFileOpened = false;
254  _6A0CA8_lod_unused = 0;
255 }
256 
258  const String &root_name, const String &lod_name) {
259  if (isFileOpened) return 1;
260  if (root_name.empty()) {
261  return 2;
262  }
263  strcpy(pHeader->pSignature, "LOD");
264  pHeader->LODSize = 100;
265  pHeader->uNumIndices = 1;
266 
267  LOD::Directory dir;
268  strcpy(dir.pFilename, root_name.c_str());
269  dir.field_F = 0;
270  dir.uDataSize = 0;
272  pLODName = lod_name;
273 
274  pFile = fopen(pLODName.c_str(), "wb+");
275  if (!pFile) return 3;
276  fwrite(pHeader, sizeof(LOD::FileHeader), 1, pFile);
277  fwrite(&dir, sizeof(LOD::Directory), 1, pFile);
278  fclose(pFile);
279  pFile = nullptr;
280  return 0;
281 }
282 
284  if (!isFileOpened) {
285  return;
286  }
287 
288  pContainerName.clear();
289  uOffsetToSubIndex = 0;
290  free(pSubIndices);
291  pSubIndices = nullptr;
292 }
293 
296  uLODDataSize = 0;
297 }
298 
300  int *v1 = (int *)&this->uNumLoadedSprites;
301  int *v2 = &this->field_ECA8;
302  DeleteSpritesRange(this->field_ECA8, this->uNumLoadedSprites);
303  *v1 = *v2;
304 }
305 
306 void LODFile_Sprites::DeleteSpritesRange(int uStartIndex, int uStopIndex) {
307  if (this->pHardwareSprites) {
308  if (uStartIndex < uStopIndex) {
309  for (int i = uStartIndex; i < uStopIndex; i++) {
310  pHardwareSprites[i].Release();
311  }
312  }
313  }
314 }
315 
317  if (!(this->word_1A & 0x400)) {
318  delete[] bitmap;
319  }
320 
321  this->word_1A = 0;
322  this->bitmap = nullptr;
323  this->pName[0] = 0;
324  this->word_16 = 0;
325  this->uPaletteId = 0;
326  this->uTexturePitch = 0;
327  this->uHeight = 0;
328  this->uWidth = 0;
329  this->uSpriteSize = 0;
330 }
331 
333  return;
334 
335  // testing actually clearing sprites on release
336  // causes error - if sprite is requested multiple times asset manager can delete
337  // image which may be referenced elsewhere resulting in MAV
338 
339  // bodge for the time being, not resetting loading sprites
340  // reduces memory leak on level transition
341 
342  this->sprite_header->Release();
343  this->texture->Release();
344  this->texture = NULL;
345  this->pName = "NULL";
346  this->uPaletteID = 0;
347 }
348 
349 bool LODFile_IconsBitmaps::Load(const String &pLODFilename, const String &pFolderName) {
350  if (!Open(pLODFilename)) {
351  return false;
352  }
353 
354  return LoadSubIndices(pFolderName);
355 }
356 
358  for (uint i = 0; i < this->uNumLoadedFiles; i++) {
359  this->pTextures[i].Release();
360  }
361  this->uTexturePacksCount = 0;
362  this->uNumPrevLoadedFiles = 0;
363  this->dword_11B84 = 0;
364  this->dword_11B80 = 0;
365  this->uNumLoadedFiles = 0;
366 }
367 
368 unsigned int LODFile_IconsBitmaps::FindTextureByName(const char *pName) {
369  for (uint i = 0; i < this->uNumLoadedFiles; i++) {
370  if (!_stricmp(this->pTextures[i].header.pName, pName)) return i;
371  }
372  return -1;
373 }
374 
376  Texture_MM7 *pTex; // edx@1
377 
378  int loaded_files = this->uNumLoadedFiles;
379  for (pTex = &this->pTextures[loaded_files]; !pTex->header.pName[0]; --pTex)
380  --loaded_files;
381  if (loaded_files < (signed int)this->uNumLoadedFiles) {
382  ++loaded_files;
383  this->uNumLoadedFiles = loaded_files;
384  }
385 }
386 
388  if (this->pHardwareSprites) {
389  for (int i = 0; i < this->uNumLoadedSprites; ++i) {
390  this->pHardwareSprites[i].Release();
391  }
392  }
393 }
394 
396  if (!(this->word_1A & 0x400)) {
397  delete[] bitmap;
398  }
399  bitmap = nullptr;
400 }
401 
403  field_ECA4 = 0;
404  field_ECA0 = 0;
405  pHardwareSprites = 0;
406  // can_load_hardware_sprites = 0;
407  field_ECB4 = 0;
408  uNumLoadedSprites = 0;
409 }
410 
412  for (uint i = 0; i < this->uNumLoadedFiles; i++) {
413  this->pTextures[i].Release();
414  }
415  free(this->pHardwareSurfaces);
416  free(this->pHardwareTextures);
417  free(this->ptr_011BB4);
418  // LOD::File::vdtor((LOD::File *)v1);
419 }
420 
422  /*v2 = v1->pTextures;
423  v3 = 1000;
424  do
425  {
426  Texture_MM7::Texture_MM7(v2);
427  ++v2;
428  --v3;
429  }
430  while ( v3 );*/
431  this->uTexturePacksCount = 0;
432  this->uNumPrevLoadedFiles = 0;
433  this->dword_11B84 = 0;
434  this->dword_11B80 = 0;
435  this->uNumLoadedFiles = 0;
437  // this->can_load_hardware_sprites = 0;
438  this->pHardwareSurfaces = 0;
439  this->pHardwareTextures = 0;
440  this->ptr_011BB4 = 0;
441  this->uTextureRedBits = 0;
442  this->uTextureGreenBits = 0;
443  this->uTextureBlueBits = 0;
444 }
445 
446 bool LOD::WriteableFile::_4621A7() { // закрыть и загрузить записываемый ф-л(при
447  // сохранении)
448  CloseWriteFile();
449  return LoadFile(pLODName, 0);
450 }
451 
453  unsigned int total_size = 0;
454  for (int i = 0; i < uNumSubDirs; i++) {
455  total_size += pSubIndices[i].uDataSize;
456  }
457 
458  // fix offsets
459  int temp_offset = sizeof(LOD::Directory) * uNumSubDirs;
460  for (int i = 0; i < uNumSubDirs; i++) {
461  pSubIndices[i].uOfsetFromSubindicesStart = temp_offset;
462  temp_offset += pSubIndices[i].uDataSize;
463  }
464 
465  String Filename = "lod.tmp";
466  FILE *tmp_file = fopen(Filename.c_str(), "wb+");
467  if (tmp_file == nullptr) {
468  return 5;
469  }
470 
471  fwrite((const void *)&header, sizeof(LOD::FileHeader), 1, tmp_file);
472 
473  LOD::Directory Lindx;
474  strcpy(Lindx.pFilename, "chapter");
475  Lindx.uOfsetFromSubindicesStart = uOffsetToSubIndex; // 10h 16
476  Lindx.uDataSize =
477  sizeof(LOD::Directory) * uNumSubDirs + total_size; // 14h 20
478  Lindx.dword_000018 = 0; // 18h 24
479  Lindx.uNumSubIndices = uNumSubDirs; // 1ch 28
480  Lindx.priority = 0; // 1Eh 30
481  fwrite(&Lindx, sizeof(LOD::Directory), 1, tmp_file);
482  fwrite(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, tmp_file);
483  fseek(pOutputFileHandle, 0, 0);
484  while (total_size > 0) {
485  int write_size = uIOBufferSize;
486  if (total_size <= uIOBufferSize) {
487  write_size = total_size;
488  }
489  fread(pIOBuffer, 1, write_size, pOutputFileHandle);
490  fwrite(pIOBuffer, 1, write_size, tmp_file);
491  total_size -= write_size;
492  }
493 
494  fclose(tmp_file);
495  fclose(pOutputFileHandle);
496  CloseWriteFile();
497  remove("lodapp.tmp");
498  remove(pLODName.c_str());
499  rename(Filename.c_str(), pLODName.c_str());
500  CloseWriteFile();
501  LoadFile(pLODName.c_str(), 0);
502 
503  return 0;
504 }
505 
506 bool LOD::WriteableFile::AppendDirectory(const String &file_name, const void *pData, size_t data_size) {
507  Assert(uNumSubDirs < 299);
508 
509  LOD::Directory dir;
510  strcpy(dir.pFilename, file_name.c_str());
511  dir.uDataSize = data_size;
512 
513  memcpy(&pSubIndices[uNumSubDirs++], &dir, sizeof(LOD::Directory));
514  fwrite(pData, 1, dir.uDataSize, pOutputFileHandle);
515  return true;
516 }
517 
519  if (!isFileOpened) return 1;
520 
521  if (pIOBuffer && uIOBufferSize) {
522  uNumSubDirs = 0;
523  pOutputFileHandle = fopen("lodapp.tmp", "wb+");
524  return pOutputFileHandle ? 1 : 7;
525  } else {
526  return 5;
527  }
528 }
529 
531  if (isFileOpened) {
532  pContainerName[0] = 0;
533  _6A0CA8_lod_unused = 0;
534 
535  isFileOpened = false;
536  fflush(pFile);
537  fclose(pFile);
538  pFile = nullptr;
539  }
540  // else
541  // __debugbreak();
542 }
543 
544 unsigned int LOD::WriteableFile::Write(const String &file_name, const void *pDirData, size_t size, int a4) {
545  LOD::Directory dir;
546  strcpy(dir.pFilename, file_name.c_str());
547  dir.uDataSize = size;
548 
549  // insert new data in sorted index lod file
550  bool bRewrite_data = false;
551  int insert_index = -1;
552  if (!isFileOpened) { // sometimes gives crash
553  return 1;
554  }
555  if (!pSubIndices) {
556  return 2;
557  }
558  if (!pIOBuffer || !uIOBufferSize) {
559  return 3;
560  }
561 
562  for (size_t i = 0; i < uNumSubDirs; i++) {
563  int comp_res = _stricmp(pSubIndices[i].pFilename, dir.pFilename);
564  if (comp_res == 0) {
565  insert_index = i;
566  if (a4 == 0) {
567  bRewrite_data = true;
568  break;
569  }
570  if (a4 == 1) {
571  if (pSubIndices[i].uNumSubIndices < dir.uNumSubIndices) {
572  if (pSubIndices[i].priority < dir.priority)
573  return 4;
574  } else {
575  bRewrite_data = true;
576  }
577  break;
578  }
579  if (a4 == 2) return 4;
580  } else if (comp_res > 0) {
581  if (insert_index == -1) {
582  insert_index = i;
583  break;
584  }
585  }
586  }
587 
588  int size_correction = 0;
589  String Filename = "lod.tmp";
590  FILE *tmp_file = fopen(Filename.c_str(), "wb+");
591  if (!tmp_file) return 5;
592  if (!bRewrite_data)
593  size_correction = 0;
594  else
595  size_correction = pSubIndices[insert_index].uDataSize;
596 
597  // create chapter index
598  LOD::Directory Lindx;
599  strcpy(Lindx.pFilename, "chapter");
600  Lindx.dword_000018 = 0;
601  Lindx.priority = 0;
602  Lindx.uNumSubIndices = uNumSubDirs;
603  Lindx.uOfsetFromSubindicesStart = sizeof(LOD::FileHeader) + sizeof(LOD::Directory);
604  int total_data_size = uLODDataSize + dir.uDataSize - size_correction;
605  if (!bRewrite_data) {
606  total_data_size += sizeof(LOD::Directory);
607  Lindx.uNumSubIndices++;
608  }
609 
610  Lindx.uDataSize = total_data_size;
611  uNumSubDirs = Lindx.uNumSubIndices;
612  // move indexes +1 after insert point
613  if (!bRewrite_data &&
614  (insert_index < uNumSubDirs)) { // перезаписывание файлов для освобождения
615  // места для нового ф-ла
616  for (int i = uNumSubDirs; i > insert_index; --i)
617  memcpy(&pSubIndices[i], &pSubIndices[i - 1],
618  sizeof(LOD::Directory)); // Uninitialized memory access
619  }
620  // insert
621  memcpy(&pSubIndices[insert_index], &dir, sizeof(LOD::Directory)); // записать текущий файл
622  // correct offsets to data
623  if (uNumSubDirs > 0) {
624  size_t offset_to_data = sizeof(LOD::Directory) * uNumSubDirs;
625  for (int i = 0; i < uNumSubDirs; i++) {
626  pSubIndices[i].uOfsetFromSubindicesStart = offset_to_data;
627  offset_to_data += pSubIndices[i].uDataSize;
628  }
629  }
630 
631  // construct lod file with added data
632  fwrite(&header, sizeof(LOD::FileHeader), 1, tmp_file);
633  fwrite(&Lindx, sizeof(LOD::Directory), 1, tmp_file);
634  fseek(pFile, Lindx.uOfsetFromSubindicesStart, SEEK_SET);
635  fwrite(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, tmp_file);
636 
637  size_t offset_to_data = sizeof(LOD::Directory) * uNumSubDirs;
638  if (!bRewrite_data) offset_to_data -= sizeof(LOD::Directory);
639 
640  fseek(pFile, offset_to_data, SEEK_CUR);
641  // copy from open lod to temp lod first half
642  int to_copy_size = pSubIndices[insert_index].uOfsetFromSubindicesStart -
643  pSubIndices[0].uOfsetFromSubindicesStart;
644  while (to_copy_size > 0) {
645  int read_size = uIOBufferSize;
646  if (to_copy_size <= uIOBufferSize) read_size = to_copy_size;
647  fread(pIOBuffer, 1, read_size, pFile);
648  fwrite(pIOBuffer, 1, read_size, tmp_file);
649  to_copy_size -= read_size;
650  }
651  // add container data
652  fwrite(pDirData, 1, dir.uDataSize, tmp_file); // Uninitialized memory access(tmp_file)
653  if (bRewrite_data) fseek(pFile, size_correction, SEEK_CUR);
654 
655  // add remainng data last half
656  int curr_position = ftell(pFile);
657  fseek(pFile, 0, SEEK_END);
658  to_copy_size = ftell(pFile) - curr_position;
659  fseek(pFile, curr_position, SEEK_SET);
660  while (to_copy_size > 0) {
661  int read_size = uIOBufferSize;
662  if (to_copy_size <= uIOBufferSize) read_size = to_copy_size;
663  fread(pIOBuffer, 1, read_size, pFile);
664  fwrite(pIOBuffer, 1, read_size, tmp_file);
665  to_copy_size -= read_size;
666  }
667 
668  // replace old file by new with added data
669  fclose(tmp_file);
670  fclose(pFile);
671  CloseWriteFile();
672  remove(pLODName.c_str());
673  rename(Filename.c_str(), pLODName.c_str());
674  CloseWriteFile();
675 
676  // reload new
677  LoadFile(pLODName, 0); // isFileOpened == true, next file
678  return 0;
679 }
680 
682  pIOBuffer = nullptr;
683  uIOBufferSize = 0;
684 }
685 
686 bool LOD::WriteableFile::LoadFile(const String &pFilename, bool bWriting) {
687  pFile = fopen(pFilename.c_str(), bWriting ? "rb" : "rb+");
688  if (pFile == nullptr) {
689  return false; // возможно файл не закрыт, поэтому не открывается
690  }
691 
692  pLODName = pFilename;
693  fread(&header, sizeof(LOD::FileHeader), 1, pFile);
694 
695  LOD::Directory lod_indx;
696  fread(&lod_indx, sizeof(LOD::Directory), 1, pFile);
697 
698  fseek(pFile, 0, SEEK_SET);
699  isFileOpened = true;
700  pContainerName = "chapter";
701  uLODDataSize = lod_indx.uDataSize;
702  uNumSubDirs = lod_indx.uNumSubIndices;
703  Assert(uNumSubDirs <= 300);
704 
705  uOffsetToSubIndex = lod_indx.uOfsetFromSubindicesStart;
706  fseek(pFile, uOffsetToSubIndex, SEEK_SET);
707 
708  fread(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile);
709  return true;
710 }
711 
712 void LOD::WriteableFile::AllocSubIndicesAndIO(unsigned int uNumSubIndices,
713  unsigned int uBufferSize) {
714  if (pSubIndices) {
715  logger->Warning(L"Attempt to reset a LOD subindex!");
716  free(pSubIndices);
717  pSubIndices = nullptr;
718  }
719  pSubIndices = (LOD::Directory *)malloc(sizeof(LOD::Directory) * uNumSubIndices);
720  if (pIOBuffer) {
721  logger->Warning(L"Attempt to reset a LOD IObuffer!");
722  free(pIOBuffer);
723  pIOBuffer = nullptr;
724  uIOBufferSize = 0;
725  }
726  if (uBufferSize) {
727  pIOBuffer = (uint8_t*)malloc(uBufferSize);
728  uIOBufferSize = uBufferSize;
729  }
730 }
731 
733  free(pSubIndices);
734  pSubIndices = nullptr;
735  free(pIOBuffer);
736  pIOBuffer = nullptr;
737 }
738 
739 LOD::File::File() : isFileOpened(false) {
740  pFile = nullptr;
741  pSubIndices = nullptr;
742  Close();
743 }
744 
746  if (isFileOpened) {
747  fclose(pFile);
748  }
749 }
750 
751 bool LOD::File::Open(const String &sFilename) {
752  if (!OpenFile(sFilename)) {
753  return false;
754  }
755 
756  if (!LoadHeader()) {
757  return false;
758  }
759 
760  return LoadSubIndices(pRoot.front().pFilename);
761 }
762 
763 bool LOD::File::OpenFile(const String &sFilename) {
764  if (isFileOpened) {
765  Close();
766  }
767 
768  pFile = fopen(sFilename.c_str(), "rb");
769  if (pFile == nullptr) {
770  return false;
771  }
772 
773  pLODName = sFilename;
774 
775  return true;
776 }
777 
779  if (pFile == nullptr) {
780  return false;
781  }
782 
783  fseek(pFile, 0, SEEK_SET);
784 
785  if (fread(&header, sizeof(LOD::FileHeader), 1, pFile) != 1) {
786  return false;
787  }
788  for (unsigned int i = 0; i < header.uNumIndices; i++) {
789  LOD::Directory dir;
790  if (fread(&dir, sizeof(LOD::Directory), 1, pFile) != 1) {
791  pRoot.clear();
792  return false;
793  }
794  pRoot.push_back(dir);
795  }
796 
797  fseek(pFile, 0, SEEK_SET);
798 
799  isFileOpened = true;
800 
801  return true;
802 }
803 
804 bool LOD::File::LoadSubIndices(const String &pContainer) {
805  ResetSubIndices();
806 
807  for (LOD::Directory &dir : pRoot) {
808  if (!_stricmp(pContainer.c_str(), dir.pFilename)) {
809  pContainerName = pContainer;
810  uOffsetToSubIndex = dir.uOfsetFromSubindicesStart;
811  uNumSubDirs = dir.uNumSubIndices;
812  fseek(pFile, uOffsetToSubIndex, SEEK_SET);
813  pSubIndices = (LOD::Directory *)malloc(sizeof(LOD::Directory) * uNumSubDirs);
814 
815  if (pSubIndices) {
816  fread(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile);
817  }
818  return true;
819  }
820  }
821  return false;
822 }
823 
825  memset(pFilename, 0, 16);
826  this->uOfsetFromSubindicesStart = 0;
827  this->uDataSize = 0;
828  this->uNumSubIndices = 0;
829  this->dword_000018 = 0;
830  this->priority = 0;
831 }
832 
833 bool LOD::File::DoesContainerExist(const String &pContainer) {
834  for (size_t i = 0; i < uNumSubDirs; ++i) {
835  if (!_stricmp(pContainer.c_str(), pSubIndices[i].pFilename)) {
836  return true;
837  }
838  }
839 
840  return false;
841 }
842 
844  this->field_ECA8 = this->uNumLoadedSprites;
845  if (this->uNumLoadedSprites < this->field_ECA0)
846  this->field_ECA8 = this->field_ECA0;
847  if (this->field_ECA0 < this->field_ECA4) field_ECA0 = this->field_ECA4;
848  return this->uNumLoadedSprites;
849 }
850 
851 FILE *LOD::File::FindContainer(const String &pContainer_Name, size_t *data_size) {
852  if (!isFileOpened) {
853  return nullptr;
854  }
855  if (data_size != nullptr) {
856  *data_size = 0;
857  }
858 
859  for (uint i = 0; i < uNumSubDirs; ++i) {
860  if (!_stricmp(pContainer_Name.c_str(), pSubIndices[i].pFilename)) {
861  fseek(pFile, uOffsetToSubIndex + pSubIndices[i].uOfsetFromSubindicesStart, SEEK_SET);
862  if (data_size != nullptr) {
863  *data_size = pSubIndices[i].uDataSize;
864  }
865  return pFile;
866  }
867  }
868 
869  return nullptr;
870 }
871 
872 void LODFile_IconsBitmaps::SetupPalettes(unsigned int uTargetRBits,
873  unsigned int uTargetGBits,
874  unsigned int uTargetBBits) {
875  if (this->uTextureRedBits != uTargetRBits ||
876  this->uTextureGreenBits != uTargetGBits ||
877  this->uTextureBlueBits != uTargetBBits) { // Uninitialized memory access
878  this->uTextureRedBits = uTargetRBits;
879  this->uTextureGreenBits = uTargetGBits;
880  this->uTextureBlueBits = uTargetBBits;
881  for (unsigned int i = 0; i < this->uNumLoadedFiles; ++i) {
882  if (this->pTextures[i].pPalette24) {
883  FILE *File = FindContainer(this->pTextures[i].header.pName);
884  if (File) {
885  TextureHeader DstBuf;
886  fread(&DstBuf, 1, sizeof(TextureHeader), File);
887  fseek(File, DstBuf.uTextureSize, 1);
888  fread(this->pTextures[i].pPalette24, 1, 0x300, File);
889  }
890  }
891  }
892  }
893 }
894 
895 void *LOD::File::LoadRaw(const String &pContainer, size_t *data_size) {
896  if (data_size != nullptr) {
897  *data_size = 0;
898  }
899 
900  size_t size = 0;
901  FILE *File = FindContainer(pContainer, &size);
902  if (!File) {
903  Error("Unable to load %s", pContainer.c_str());
904  return nullptr;
905  }
906 
907  void *result = malloc(size);
908  if (fread(result, size, 1, File) != 1) {
909  free(result);
910  result = 0;
911  size = 0;
912  }
913 
914  if (data_size != nullptr) {
915  *data_size = size;
916  }
917 
918  return result;
919 }
920 
921 void *LOD::File::LoadCompressedTexture(const String &pContainer, size_t *data_size) {
922  void *result = nullptr;
923  if (data_size != nullptr) {
924  *data_size = 0;
925  }
926 
927  FILE *File = FindContainer(pContainer, 0);
928  if (!File) {
929  Error("Unable to load %s", pContainer.c_str());
930  return nullptr;
931  }
932 
933  TextureHeader DstBuf;
934  fread(&DstBuf, 1, sizeof(TextureHeader), File);
935 
936  if (DstBuf.uDecompressedSize) {
937  result = malloc(DstBuf.uDecompressedSize);
938  void *tmp_buf = malloc(DstBuf.uTextureSize);
939  fread(tmp_buf, 1, DstBuf.uTextureSize, File);
940  zlib::Uncompress(result, &DstBuf.uDecompressedSize, tmp_buf,
941  DstBuf.uTextureSize);
942  DstBuf.uTextureSize = DstBuf.uDecompressedSize;
943  free(tmp_buf);
944  } else {
945  result = malloc(DstBuf.uTextureSize);
946  fread(result, 1, DstBuf.uTextureSize, File);
947  }
948 
949  if (data_size != nullptr) {
950  *data_size = DstBuf.uTextureSize;
951  }
952 
953  return result;
954 }
955 
956 #pragma pack(push, 1)
959  char pMagic[4];
962 };
963 #pragma pack(pop)
964 
965 void *LOD::File::LoadCompressed(const String &pContainer, size_t *data_size) {
966  static_assert(sizeof(CompressedHeader) == 16, "Wrong type size");
967 
968  void *result = nullptr;
969  if (data_size != nullptr) {
970  *data_size = 0;
971  }
972 
973  FILE *File = FindContainer(pContainer, 0);
974  if (!File) {
975  Error("Unable to load %s", pContainer.c_str());
976  return nullptr;
977  }
978 
979  CompressedHeader header;
980  fread(&header, 1, sizeof(CompressedHeader), File);
981  if (header.uVersion != 91969 || (memcmp(&header.pMagic, "mvii", 4) != 0)) {
982  Error("Unable to load %s", pContainer.c_str());
983  return nullptr;
984  }
985 
986  if (header.uDecompressedSize) {
987  result = malloc(header.uDecompressedSize);
988  void *tmp_buf = malloc(header.uCompressedSize);
989  fread(tmp_buf, 1, header.uCompressedSize, File);
990  zlib::Uncompress(result, &header.uDecompressedSize, tmp_buf, header.uCompressedSize);
991  header.uCompressedSize = header.uDecompressedSize;
992  free(tmp_buf);
993  } else {
994  result = malloc(header.uCompressedSize);
995  fread(result, 1, header.uCompressedSize, File);
996  }
997 
998  if (data_size != nullptr) {
999  *data_size = header.uCompressedSize;
1000  }
1001 
1002  return result;
1003 }
1004 
1006  for (size_t index = 0; index < uNumSubDirs; index++) {
1007  if (name == pSubIndices[index].pFilename) {
1008  return index;
1009  }
1010  }
1011 
1012  return -1;
1013 }
1014 
1016 
1018 
1020  const char *pContainer, int mode) {
1021  unsigned int v7; // ebx@6
1022  unsigned int v8; // ecx@6
1023  int result; // eax@7
1024  // uint8_t v15; // [sp+11h] [bp-3h]@13
1025  // uint8_t v16; // [sp+12h] [bp-2h]@13
1026  // uint8_t DstBuf; // [sp+13h] [bp-1h]@13
1027  void *DstBufa; // [sp+1Ch] [bp+8h]@10
1028  void *Sourcea; // [sp+20h] [bp+Ch]@10
1029 
1030  FILE *File = FindContainer(pContainer);
1031  if (File == nullptr) {
1032  return -1;
1033  }
1034 
1035  Texture_MM7 *v6 = pDst;
1036  if (pDst->paletted_pixels && mode == 2 && pDst->pPalette24 &&
1037  (v7 = pDst->header.uTextureSize, fread(pDst, 1, 0x30u, File),
1038  strcpy(pDst->header.pName, pContainer),
1039  v8 = pDst->header.uTextureSize, (int)v8 <= (int)v7)) {
1040  if (!pDst->header.uDecompressedSize ||
1041  this->_011BA4_debug_paletted_pixels_uncompressed) {
1042  fread(pDst->paletted_pixels, 1, pDst->header.uTextureSize, File);
1043  } else {
1044  Sourcea = malloc(pDst->header.uDecompressedSize);
1045  DstBufa = malloc(pDst->header.uTextureSize);
1046  fread(DstBufa, 1, pDst->header.uTextureSize, File);
1047  zlib::Uncompress(Sourcea, &v6->header.uDecompressedSize, DstBufa,
1048  v6->header.uTextureSize);
1050  free(DstBufa);
1051  memcpy(v6->paletted_pixels, Sourcea,
1052  pDst->header.uDecompressedSize);
1053  free(Sourcea);
1054  }
1055  fread(pDst->pPalette24, 1, 0x300, File);
1056  result = 1;
1057  } else {
1058  result = -1;
1059  }
1060  return result;
1061 }
1062 
1064  const char *pContainer,
1065  enum TEXTURE_TYPE eTextureType) {
1066  int result; // esi@14
1067  unsigned int v14; // eax@21
1068  // size_t v22; // ST2C_4@29
1069  // const void *v23; // ecx@29
1070 
1071  size_t data_size = 0;
1072  FILE *pFile = FindContainer(pContainer, &data_size);
1073  if (pFile == nullptr) {
1074  return -1;
1075  }
1076 
1077  TextureHeader *header = &pOutTex->header;
1078  fread(header, 1, sizeof(TextureHeader), pFile);
1079  strncpy(header->pName, pContainer, 16);
1080  data_size -= sizeof(TextureHeader);
1081 
1082  // BITMAPS
1083  if ((header->pBits & 2) && strcmp(header->pName, "sptext01")) {
1084  if (!pHardwareSurfaces || !pHardwareTextures) {
1085  pHardwareSurfaces = new IDirectDrawSurface *[1000];
1086  memset(pHardwareSurfaces, 0, 1000 * sizeof(IDirectDrawSurface *));
1087 
1088  pHardwareTextures = new IDirect3DTexture2 *[1000];
1089  memset(pHardwareTextures, 0, 1000 * sizeof(IDirect3DTexture2 *));
1090 
1091  ptr_011BB4 = new char[1000];
1092  memset(ptr_011BB4, 0, 1000);
1093  }
1094  if (_strnicmp(pContainer, "wtrdr", 5)) {
1095  if (_strnicmp(pContainer, "WtrTyl", 6)) {
1096  v14 = uNumLoadedFiles;
1097  } else {
1098  render->hd_water_tile_id = uNumLoadedFiles;
1099  v14 = uNumLoadedFiles;
1100  }
1101  // result = render->LoadTexture(pContainer, pOutTex->palette_id1,
1102  // (void **)&pHardwareSurfaces[v14], (void
1103  // **)&pHardwareTextures[v14]);
1104  result = 1;
1105  } else {
1106  char *temp_container;
1107  temp_container = (char *)malloc(strlen(pContainer) + 2);
1108  *temp_container = 104; // 'h'
1109  strcpy(temp_container + 1, pContainer);
1110  result = 1;
1111  free((void *)temp_container);
1112  }
1113  return result;
1114  }
1115 
1116  // ICONS
1117  if (!header->uDecompressedSize ||
1118  _011BA4_debug_paletted_pixels_uncompressed) {
1119  if (header->uTextureSize > data_size) {
1120  assert(false);
1121  }
1122  pOutTex->paletted_pixels = (uint8_t *)malloc(header->uTextureSize);
1123  fread(pOutTex->paletted_pixels, 1, header->uTextureSize, pFile);
1124  data_size -= header->uTextureSize;
1125  } else {
1126  if (header->uTextureSize > data_size) {
1127  assert(false);
1128  }
1129  pOutTex->paletted_pixels = (uint8_t *)malloc(header->uDecompressedSize);
1130  void *tmp_buf = malloc(header->uTextureSize);
1131  fread(tmp_buf, 1, (size_t)header->uTextureSize, pFile);
1132  data_size -= header->uTextureSize;
1134  tmp_buf, header->uTextureSize);
1135  header->uTextureSize = header->uDecompressedSize;
1136  free(tmp_buf);
1137  }
1138 
1139  pOutTex->pPalette24 = nullptr;
1140 
1141  if (0x300 > data_size) {
1142  assert(false);
1143  }
1144  pOutTex->pPalette24 = (uint8_t *)malloc(0x300);
1145  fread(pOutTex->pPalette24, 1, 0x300, pFile);
1146  data_size -= 0x300;
1147 
1148  assert(data_size == 0);
1149 
1150  if (header->pBits & 2) {
1151  pOutTex->pLevelOfDetail1 =
1152  &pOutTex->paletted_pixels[header->uSizeOfMaxLevelOfDetail];
1153  // v8->pLevelOfDetail2 =
1154  // &v8->pLevelOfDetail1[v8->uSizeOfMaxLevelOfDetail >> 2];
1155  // v8->pLevelOfDetail3 =
1156  // &v8->pLevelOfDetail2[v8->uSizeOfMaxLevelOfDetail >> 4];
1157  } else {
1158  pOutTex->pLevelOfDetail1 = 0;
1159  // v8->pLevelOfDetail2 = 0;
1160  // v8->pLevelOfDetail3 = 0;
1161  }
1162 
1163  for (int v41 = 1; v41 < 15; ++v41) {
1164  if (1 << v41 == header->uTextureWidth) header->uWidthLn2 = v41;
1165  }
1166  for (int v42 = 1; v42 < 15; ++v42) {
1167  if (1 << v42 == header->uTextureHeight) header->uHeightLn2 = v42;
1168  }
1169 
1170  header->uWidthMinus1 = (1 << header->uWidthLn2) - 1;
1171  header->uHeightMinus1 = (1 << header->uHeightLn2) - 1;
1172 
1173  return 1;
1174 }
1175 
1177  const char *pContainer, enum TEXTURE_TYPE uTextureType) {
1178  uint id = LoadTexture(pContainer, uTextureType);
1179 
1180  Assert(id != -1 && L"Texture_MM7 not found");
1181 
1182  return &pTextures[id];
1183 }
1184 
1185 unsigned int LODFile_IconsBitmaps::LoadTexture(const char *pContainer,
1186  enum TEXTURE_TYPE uTextureType) {
1187  for (uint i = 0; i < uNumLoadedFiles; ++i) {
1188  if (!_stricmp(pContainer, pTextures[i].header.pName)) {
1189  return i;
1190  }
1191  }
1192 
1193  Assert(uNumLoadedFiles < 1000);
1194 
1195  if (LoadTextureFromLOD(&pTextures[uNumLoadedFiles], pContainer,
1196  uTextureType) == -1) {
1197  for (uint i = 0; i < uNumLoadedFiles; ++i) {
1198  if (!_stricmp(pTextures[i].header.pName, "pending")) {
1199  return i;
1200  }
1201  }
1202  LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending",
1203  uTextureType);
1204  }
1205 
1206  return uNumLoadedFiles++;
1207 }
1208 
1210  Assert(idx < MAX_LOD_TEXTURES, "Texture_MM7 index out of bounds (%u)", idx);
1211  if (idx == -1) {
1212  // logger->Warning(L"Texture_MM7 id = %d missing", idx);
1213  return pTextures + LoadDummyTexture();
1214  }
1215  return pTextures + idx;
1216 }
1217 
1219  pGames_LOD = new LOD::File();
1220  if (pGames_LOD->Open(MakeDataPath("data\\games.lod"))) {
1222  pNew_LOD->AllocSubIndicesAndIO(300, 100000);
1223  return true;
1224  }
1225  return false;
1226 }
uint16_t
unsigned __int16 uint16_t
Definition: SDL_config.h:37
SoftwareBillboard::pPalette
uint16_t * pPalette
Definition: IRender.h:179
LOD::Directory::field_F
char field_F
Definition: LOD.h:49
pNew_LOD
LOD::WriteableFile * pNew_LOD
Definition: LOD.cpp:24
LOD::Directory::uDataSize
uint32_t uDataSize
Definition: LOD.h:51
LODFile_Sprites::DeleteSpritesRange
void DeleteSpritesRange(int uStartIndex, int uStopIndex)
Definition: LOD.cpp:306
LOD::WriteableFile::FixDirectoryOffsets
int FixDirectoryOffsets()
Definition: LOD.cpp:452
int16_t
signed __int16 int16_t
Definition: SDL_config.h:36
LOD::WriteableFile::LoadFile
bool LoadFile(const String &pFilename, bool bWriting)
Definition: LOD.cpp:686
LODFile_IconsBitmaps::uTextureRedBits
int uTextureRedBits
Definition: LOD.h:163
LOD.h
LOD::WriteableFile::AllocSubIndicesAndIO
void AllocSubIndicesAndIO(unsigned int uNumSubIndices, unsigned int uBufferSize)
Definition: LOD.cpp:712
pBitmaps_LOD_mm6
LODFile_IconsBitmaps * pBitmaps_LOD_mm6
Definition: LOD.cpp:17
LODSpriteLine
Definition: LOD.cpp:91
LODFile_IconsBitmaps::LODFile_IconsBitmaps
LODFile_IconsBitmaps()
Definition: LOD.cpp:421
LOD::FileHeader::uNumIndices
uint32_t uNumIndices
Definition: LOD.h:39
LOD::WriteableFile::ResetSubIndices
virtual void ResetSubIndices()
Definition: LOD.cpp:294
pSprites_LOD
LODFile_Sprites * pSprites_LOD
Definition: LOD.cpp:20
LODFile_IconsBitmaps::uNumLoadedFiles
unsigned int uNumLoadedFiles
Definition: LOD.h:159
mode
EGLSyncKHR EGLenum mode
Definition: SDL_egl.h:1056
CompressedHeader::uVersion
uint32_t uVersion
Definition: LOD.cpp:958
CompressedHeader::uCompressedSize
uint32_t uCompressedSize
Definition: LOD.cpp:960
LODFile_IconsBitmaps::FindTextureByName
unsigned int FindTextureByName(const char *pName)
Definition: LOD.cpp:368
LOD::Directory::Directory
Directory()
Definition: LOD.cpp:824
LOD::File::ResetSubIndices
virtual void ResetSubIndices()
Definition: LOD.cpp:283
LODFile_IconsBitmaps::ptr_011BB4
char * ptr_011BB4
Definition: LOD.h:173
LODFile_IconsBitmaps::LoadTexturePtr
struct Texture_MM7 * LoadTexturePtr(const char *pContainer, enum TEXTURE_TYPE uTextureType=TEXTURE_DEFAULT)
Definition: LOD.cpp:1176
LOD::Directory::pFilename
char pFilename[15]
Definition: LOD.h:48
LOD::File::LoadCompressedTexture
void * LoadCompressedTexture(const String &pContainer, size_t *data_size=nullptr)
Definition: LOD.cpp:921
SoftwareBillboard::pTarget
void * pTarget
Definition: IRender.h:171
CompressedHeader::pMagic
char pMagic[4]
Definition: LOD.cpp:959
LOD
Definition: LOD.h:20
LOD::WriteableFile::_4621A7
bool _4621A7()
Definition: LOD.cpp:446
LOD::File::DoesContainerExist
bool DoesContainerExist(const String &filename)
Definition: LOD.cpp:833
LODFile_IconsBitmaps::SyncLoadedFilesCount
void SyncLoadedFilesCount()
Definition: LOD.cpp:375
LODSpriteHeader::uSpriteSize
uint32_t uSpriteSize
Definition: LOD.h:185
LODFile_IconsBitmaps::uNumPrevLoadedFiles
int uNumPrevLoadedFiles
Definition: LOD.h:166
LOD::File::header
struct FileHeader header
Definition: LOD.h:87
LOD::File::pRoot
std::vector< Directory > pRoot
Definition: LOD.h:89
LODFile_IconsBitmaps::ReloadTexture
int ReloadTexture(struct Texture_MM7 *pDst, const char *pContainer, int mode)
Definition: LOD.cpp:1019
HWLTexture::uAreaWidth
int uAreaWidth
Definition: HWLContainer.h:15
LODSpriteHeader::uWidth
uint16_t uWidth
Definition: LOD.h:186
LODFile_IconsBitmaps::dword_11B80
int dword_11B80
Definition: LOD.h:160
LODFile_IconsBitmaps::~LODFile_IconsBitmaps
virtual ~LODFile_IconsBitmaps()
Definition: LOD.cpp:411
Sprite::uBufferHeight
int uBufferHeight
Definition: Sprites.h:32
LODFile_IconsBitmaps::uTexturePacksCount
int uTexturePacksCount
Definition: LOD.h:167
LOD::File::Close
void Close()
Definition: LOD.cpp:243
LODSpriteHeader
Definition: LOD.h:177
LODFile_IconsBitmaps::_011BA4_debug_paletted_pixels_uncompressed
int _011BA4_debug_paletted_pixels_uncompressed
Definition: LOD.h:169
LOD::FileHeader::LODSize
uint32_t LODSize
Definition: LOD.h:37
texture
GLenum GLenum GLuint texture
Definition: SDL_opengl_glext.h:1181
CompressedHeader
Definition: LOD.cpp:957
Sprite::texture
Texture * texture
Definition: Sprites.h:28
TextureHeader::pBits
uint32_t pBits
Definition: Image.h:91
LOD::WriteableFile::CloseWriteFile
void CloseWriteFile()
Definition: LOD.cpp:530
HWLTexture
Definition: HWLContainer.h:9
TextureHeader::uWidthLn2
int16_t uWidthLn2
Definition: Image.h:84
index
GLuint index
Definition: SDL_opengl_glext.h:663
Texture_MM7::paletted_pixels
uint8_t * paletted_pixels
Definition: Image.h:102
Engine.h
Sprite
Definition: Sprites.h:10
LOD::Directory::uOfsetFromSubindicesStart
uint32_t uOfsetFromSubindicesStart
Definition: LOD.h:50
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9435
LODFile_Sprites::LoadSprite
int LoadSprite(const char *pContainerName, unsigned int uPaletteID)
Definition: LOD.cpp:149
TEXTURE_24BIT_PALETTE
@ TEXTURE_24BIT_PALETTE
Definition: LOD.h:17
LOD::WriteableFile
Definition: LOD.h:97
pSprites_LOD_mm6
LODFile_Sprites * pSprites_LOD_mm6
Definition: LOD.cpp:21
Sprite::uAreaY
int uAreaY
Definition: Sprites.h:30
LOD::File::pFile
FILE * pFile
Definition: LOD.h:83
HWLTexture::uBufferWidth
int uBufferWidth
Definition: HWLContainer.h:13
Texture_MM7::header
TextureHeader header
Definition: Image.h:101
y
EGLSurface EGLint EGLint y
Definition: SDL_egl.h:1596
LODFile_IconsBitmaps::LoadTextureFromLOD
int LoadTextureFromLOD(struct Texture_MM7 *pOutTex, const char *pContainer, enum TEXTURE_TYPE eTextureType)
Definition: LOD.cpp:1063
LOD::Directory
Definition: LOD.h:45
LODFile_IconsBitmaps::ReleaseLostHardwareTextures
void ReleaseLostHardwareTextures()
Definition: LOD.cpp:1017
LOD::WriteableFile::CreateNewLod
int CreateNewLod(LOD::FileHeader *pHeader, const String &root_name, const String &Source)
Definition: LOD.cpp:257
Sprite::uBufferWidth
int uBufferWidth
Definition: Sprites.h:31
LODFile_Sprites::LODFile_Sprites
LODFile_Sprites()
Definition: LOD.cpp:402
LODFile_IconsBitmaps::_inlined_sub0
void _inlined_sub0()
Definition: LOD.cpp:50
LOD::WriteableFile::FreeSubIndexAndIO
void FreeSubIndexAndIO()
Definition: LOD.cpp:732
pIcons_LOD_mm6
LODFile_IconsBitmaps * pIcons_LOD_mm6
Definition: LOD.cpp:13
SoftwareBillboard
Definition: IRender.h:170
IRender.h
CompressedHeader::uDecompressedSize
uint32_t uDecompressedSize
Definition: LOD.cpp:961
LOD::File::isFileOpened
bool isFileOpened
Definition: LOD.h:85
LODFile_Sprites::~LODFile_Sprites
virtual ~LODFile_Sprites()
Definition: LOD.cpp:387
AssetsManager::GetSprite
Texture * GetSprite(const String &name, unsigned int palette_id, unsigned int lod_sprite_id)
Definition: AssetsManager.cpp:141
TextureHeader::uHeightMinus1
int16_t uHeightMinus1
Definition: Image.h:87
TextureHeader::pName
char pName[16]
Definition: Image.h:79
ZlibWrapper.h
x
EGLSurface EGLint x
Definition: SDL_egl.h:1596
LOD::File::FindContainer
FILE * FindContainer(const String &filename, size_t *data_size=nullptr)
Definition: LOD.cpp:851
LODFile_Sprites::LoadSpriteFromFile
int LoadSpriteFromFile(LODSprite *pSpriteHeader, const String &pContainer)
Definition: LOD.cpp:98
color
GLuint color
Definition: SDL_opengl_glext.h:1151
LODFile_IconsBitmaps::Load
bool Load(const String &pFilename, const String &pFolderName)
Definition: LOD.cpp:349
LODSprite::~LODSprite
~LODSprite()
Definition: LOD.cpp:395
LODFile_IconsBitmaps::pHardwareTextures
struct IDirect3DTexture2 ** pHardwareTextures
Definition: LOD.h:172
LODFile_Sprites::field_ECB4
int field_ECB4
Definition: LOD.h:234
LODFile_IconsBitmaps::SetupPalettes
void SetupPalettes(unsigned int uTargetRBits, unsigned int uTargetGBits, unsigned int uTargetBBits)
Definition: LOD.cpp:872
_6A0CA8_lod_unused
int _6A0CA8_lod_unused
Definition: LOD.cpp:28
LODFile_Sprites::_inlined_sub0
void _inlined_sub0()
Definition: LOD.cpp:55
LOD::File::File
File()
Definition: LOD.cpp:739
Initialize_GamesLOD_NewLOD
bool Initialize_GamesLOD_NewLOD()
Definition: LOD.cpp:1218
v1
GLfloat GLfloat v1
Definition: SDL_opengl_glext.h:694
LODFile_IconsBitmaps::ReleaseAll2
void ReleaseAll2()
Definition: LOD.cpp:223
Sprite::uAreaWidth
int uAreaWidth
Definition: Sprites.h:33
Log::Warning
void Warning(const wchar_t *pFormat,...)
Definition: Log.cpp:28
pIcons_LOD
LODFile_IconsBitmaps * pIcons_LOD
Definition: LOD.cpp:12
LODSprite
Definition: LOD.h:197
TextureHeader::uHeightLn2
int16_t uHeightLn2
Definition: Image.h:85
LODFile_IconsBitmaps::LoadTexture
unsigned int LoadTexture(const char *pContainer, enum TEXTURE_TYPE uTextureType=TEXTURE_DEFAULT)
Definition: LOD.cpp:1185
LOD::Directory::uNumSubIndices
uint16_t uNumSubIndices
Definition: LOD.h:53
Sprite::Release
void Release()
Definition: LOD.cpp:332
LOD::WriteableFile::CreateTempFile
int CreateTempFile()
Definition: LOD.cpp:518
LOD::File::LoadSubIndices
bool LoadSubIndices(const String &sFolder)
Definition: LOD.cpp:804
LODSpriteHeader::uDecompressedSize
uint32_t uDecompressedSize
Definition: LOD.h:192
LOD::File::pSubIndices
struct Directory * pSubIndices
Definition: LOD.h:94
LODFile_Sprites::MoveSpritesToVideoMemory
void MoveSpritesToVideoMemory()
Definition: LOD.cpp:204
LOD::File::GetSubNodeIndex
int GetSubNodeIndex(const String &name) const
Definition: LOD.cpp:1005
LODFile_Sprites::uNumLoadedSprites
unsigned int uNumLoadedSprites
Definition: LOD.h:228
LODFile_IconsBitmaps::pHardwareSurfaces
struct IDirectDrawSurface ** pHardwareSurfaces
Definition: LOD.h:171
HWLTexture::uBufferHeight
int uBufferHeight
Definition: HWLContainer.h:14
TextureHeader::uDecompressedSize
uint32_t uDecompressedSize
Definition: Image.h:90
LODSprite::_4AD2D1_overlays
int _4AD2D1_overlays(struct SoftwareBillboard *a2, int a3)
Definition: LOD.cpp:206
LODSpriteHeader::uHeight
uint16_t uHeight
Definition: LOD.h:187
TextureHeader::uWidthMinus1
int16_t uWidthMinus1
Definition: Image.h:86
SoftwareBillboard::screen_space_x
int screen_space_x
Definition: IRender.h:173
LODFile_IconsBitmaps::uTextureGreenBits
int uTextureGreenBits
Definition: LOD.h:164
pGames_LOD
LOD::File * pGames_LOD
Definition: LOD.cpp:25
TextureHeader::uTextureSize
uint32_t uTextureSize
Definition: Image.h:81
LOD::WriteableFile::Write
unsigned int Write(const String &file_name, const void *pDirData, size_t size, int a4)
Definition: LOD.cpp:544
LOD::File::~File
virtual ~File()
Definition: LOD.cpp:745
TextureHeader::uTextureWidth
uint16_t uTextureWidth
Definition: Image.h:82
LODFile_Sprites
Definition: LOD.h:210
LOD::FileHeader::pSignature
char pSignature[4]
Definition: LOD.h:34
HWLTexture::pPixels
uint16_t * pPixels
Definition: HWLContainer.h:21
pEvents_LOD
LODFile_IconsBitmaps * pEvents_LOD
Definition: LOD.cpp:10
Texture_MM7
Definition: Image.h:97
LODSprite::Release
void Release()
Definition: LOD.cpp:316
id
GLuint id
Definition: SDL_opengl_glext.h:531
LODFile_IconsBitmaps::uTextureBlueBits
int uTextureBlueBits
Definition: LOD.h:165
bitmap
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
Definition: SDL_opengl_glext.h:4537
zlib::Uncompress
int Uncompress(void *dest, unsigned int *destLen, const void *source, unsigned int sourceLen)
Definition: ZlibWrapper.cpp:7
LODSprite::bitmap
uint8_t * bitmap
Definition: LOD.h:206
SoftwareBillboard::screen_space_y
int screen_space_y
Definition: IRender.h:174
LODFile_IconsBitmaps
Definition: LOD.h:125
TextureHeader::uTextureHeight
uint16_t uTextureHeight
Definition: Image.h:83
uint8_t
unsigned __int8 uint8_t
Definition: SDL_config.h:35
LODFile_Sprites::ReleaseLostHardwareSprites
void ReleaseLostHardwareSprites()
Definition: LOD.cpp:200
Sprite::sprite_header
struct LODSprite * sprite_header
Definition: Sprites.h:36
LODFile_IconsBitmaps::RemoveTexturesPackFromTextureList
void RemoveTexturesPackFromTextureList()
Definition: LOD.cpp:74
LODFile_IconsBitmaps::GetTexture
Texture_MM7 * GetTexture(int idx)
Definition: LOD.cpp:1209
LOD::File::LoadCompressed
void * LoadCompressed(const String &pContainer, size_t *data_size=nullptr)
Definition: LOD.cpp:965
_6A0CA4_lod_binary_search
int _6A0CA4_lod_binary_search
Definition: LOD.cpp:27
name
EGLImageKHR EGLint * name
Definition: SDL_egl.h:1497
Sprite::uAreaX
int uAreaX
Definition: Sprites.h:29
pSprites_LOD_mm8
LODFile_Sprites * pSprites_LOD_mm8
Definition: LOD.cpp:22
LODSpriteLine::begin
int16_t begin
Definition: LOD.cpp:92
LOD::File::pContainerName
String pContainerName
Definition: LOD.h:90
LOD::WriteableFile::WriteableFile
WriteableFile()
Definition: LOD.cpp:681
LODSpriteHeader::pName
char pName[12]
Definition: LOD.h:184
MakeDataPath
std::string MakeDataPath(const char *file_rel_path)
Definition: Engine.cpp:126
v2
GLfloat GLfloat GLfloat v2
Definition: SDL_opengl_glext.h:695
assets
AssetsManager * assets
Definition: AssetsManager.cpp:12
uint
unsigned int uint
Definition: MM7.h:4
LOD::File
Definition: LOD.h:58
LOD::Directory::priority
uint16_t priority
Definition: LOD.h:54
Sprite::uPaletteID
int uPaletteID
Definition: Sprites.h:27
LOD::WriteableFile::AppendDirectory
bool AppendDirectory(const String &file_name, const void *pData, size_t data_size)
Definition: LOD.cpp:506
LODFile_Sprites::ReleaseAll
void ReleaseAll()
Definition: LOD.cpp:202
LOD::File::LoadHeader
bool LoadHeader()
Definition: LOD.cpp:778
LOD::File::Open
bool Open(const String &pFilename)
Definition: LOD.cpp:751
LODFile_Sprites::DeleteSomeOtherSprites
void DeleteSomeOtherSprites()
Definition: LOD.cpp:232
pBitmaps_LOD
LODFile_IconsBitmaps * pBitmaps_LOD
Definition: LOD.cpp:16
LODFile_Sprites::_461397
int _461397()
Definition: LOD.cpp:843
LODFile_Sprites::field_ECA0
int field_ECA0
Definition: LOD.h:229
LODFile_Sprites::pHardwareSprites
Sprite * pHardwareSprites
Definition: LOD.h:233
LOD::File::OpenFile
virtual bool OpenFile(const String &sFilename)
Definition: LOD.cpp:763
LODFile_IconsBitmaps::LoadDummyTexture
int LoadDummyTexture()
Definition: LOD.cpp:30
TextureHeader
Definition: Image.h:78
HWLTexture::uAreaX
int uAreaX
Definition: HWLContainer.h:19
LODSpriteLine::offset
uint32_t offset
Definition: LOD.cpp:94
LODFile_IconsBitmaps::_inlined_sub1
void _inlined_sub1()
Definition: LOD.cpp:42
LODFile_IconsBitmaps::dword_11B84
int dword_11B84
Definition: LOD.h:161
LODFile_Sprites::field_ECA4
int field_ECA4
Definition: LOD.h:230
HWLTexture::uAreaY
int uAreaY
Definition: HWLContainer.h:20
TextureHeader::uSizeOfMaxLevelOfDetail
uint32_t uSizeOfMaxLevelOfDetail
Definition: Image.h:80
Texture_MM7::pLevelOfDetail1
uint8_t * pLevelOfDetail1
Definition: Image.h:103
LODFile_IconsBitmaps::ReleaseAll
void ReleaseAll()
Definition: LOD.cpp:357
LODFile_IconsBitmaps::ReleaseHardwareTextures
void ReleaseHardwareTextures()
Definition: LOD.cpp:1015
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:540
logger
Log * logger
Definition: IocContainer.cpp:47
LOD::Directory::dword_000018
uint32_t dword_000018
Definition: LOD.h:52
Texture_MM7::pPalette24
uint8_t * pPalette24
Definition: Image.h:104
HWLContainer.h
pBitmaps_LOD_mm8
LODFile_IconsBitmaps * pBitmaps_LOD_mm8
Definition: LOD.cpp:18
LODFile_IconsBitmaps::pTextures
Texture_MM7 pTextures[MAX_LOD_TEXTURES]
Definition: LOD.h:158
LODFile_IconsBitmaps::_inlined_sub2
void _inlined_sub2()
Definition: LOD.cpp:37
LOD::FileHeader
Definition: LOD.h:22
Sprite::pName
String pName
Definition: Sprites.h:26
SoftwareBillboard::uTargetPitch
unsigned int uTargetPitch
Definition: IRender.h:182
LODFile_Sprites::DeleteSomeSprites
void DeleteSomeSprites()
Definition: LOD.cpp:299
uint32_t
unsigned __int32 uint32_t
Definition: SDL_config.h:39
LOD::File::LoadRaw
void * LoadRaw(const String &pContainer, size_t *data_size=nullptr)
Definition: LOD.cpp:895
String
std::string String
Definition: Strings.h:10
LODFile_Sprites::LoadSprites
bool LoadSprites(const String &pFilename)
Definition: LOD.cpp:141
Sprites.h
Sprite::uAreaHeight
int uAreaHeight
Definition: Sprites.h:34
LODFile_IconsBitmaps::RemoveTexturesFromTextureList
void RemoveTexturesFromTextureList()
Definition: LOD.cpp:60
LODFile_Sprites::_inlined_sub1
void _inlined_sub1()
Definition: LOD.cpp:46
LOD::File::pLODName
String pLODName
Definition: LOD.h:84
Texture_MM7::Release
void Release()
Definition: Image.cpp:165
LODSpriteLine::end
int16_t end
Definition: LOD.cpp:93
TEXTURE_TYPE
TEXTURE_TYPE
Definition: LOD.h:15
pIcons_LOD_mm8
LODFile_IconsBitmaps * pIcons_LOD_mm8
Definition: LOD.cpp:14
HWLTexture::uAreaHeigth
int uAreaHeigth
Definition: HWLContainer.h:16
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52