Clone of PhatAC @ https://github.com/floaterxk/PhatAC

ModelInfo.cpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "StdAfx.h"
  2. #include "ModelInfo.h"
  3. //TODO: Layer the model data in the correct order.
  4. // What if the player has steel toe boots and amuli? Amuli covers the STB!
  5. void ModelInfo::MergeData(ModelInfo* pSrc, DWORD dwLayer)
  6. {
  7. //if ( !pSrc->wBasePalette )
  8. // return;
  9. if (!dwBasePalette)
  10. dwBasePalette = pSrc->dwBasePalette;
  11. for (PaletteRList::iterator newb = pSrc->lPalettes.begin(); newb != pSrc->lPalettes.end(); newb++)
  12. {
  13. DWORD dwNewbID = newb->dwPaletteID;
  14. BYTE bNewbStart = newb->bOffset;
  15. BYTE bNewbEnd = newb->bOffset + newb->bLength;
  16. for (PaletteRList::iterator i = lPalettes.begin(); i != lPalettes.end(); )
  17. {
  18. DWORD dwBobID = i->dwPaletteID;
  19. BYTE bBobStart = i->bOffset;
  20. BYTE bBobEnd = i->bOffset + i->bLength;
  21. if (bBobStart < bNewbStart)
  22. {
  23. if (bBobEnd <= bNewbStart) {
  24. //These do not collide
  25. }
  26. else if (bBobEnd > bNewbEnd) {
  27. //Going to have to split the existing into 2
  28. PaletteRpl pr1(dwBobID, bBobStart, bNewbStart - bBobStart);
  29. PaletteRpl pr2(dwBobID, bNewbEnd, bBobEnd - (bNewbEnd));
  30. lPalettes.push_back(pr1);
  31. lPalettes.push_back(pr2);
  32. }
  33. else
  34. {
  35. //Need to cut off high-side of the existing
  36. PaletteRpl pr1(dwBobID, bBobStart, bNewbStart - bBobStart);
  37. lPalettes.push_back(pr1);
  38. }
  39. i++;
  40. continue;
  41. }
  42. else //if ( bBobStart >= bNewbStart )
  43. {
  44. if (bBobStart >= bNewbEnd)
  45. {
  46. //These do not collide
  47. i++;
  48. }
  49. else if (bBobEnd <= bNewbEnd)
  50. {
  51. //The existing is completely overwritten
  52. i = lPalettes.erase(i);
  53. }
  54. else
  55. {
  56. //Need to cut off low-side of the existing
  57. PaletteRpl pr2(dwBobID, bNewbEnd, bBobEnd - bNewbEnd);
  58. lPalettes.push_back(pr2);
  59. i++;
  60. }
  61. continue;
  62. }
  63. }
  64. }
  65. std::copy(pSrc->lPalettes.begin(), pSrc->lPalettes.end(), std::back_inserter(lPalettes));
  66. for (TextureRList::iterator newb = pSrc->lTextures.begin(); newb != pSrc->lTextures.end(); newb++)
  67. {
  68. BYTE bNewbIndex = newb->bIndex;
  69. for (TextureRList::iterator i = lTextures.begin(); i != lTextures.end(); )
  70. {
  71. if (bNewbIndex != i->bIndex)
  72. i++;
  73. else
  74. i = lTextures.erase(i);
  75. }
  76. }
  77. std::copy(pSrc->lTextures.begin(), pSrc->lTextures.end(), std::back_inserter(lTextures));
  78. for (ModelRList::iterator newb = pSrc->lModels.begin(); newb != pSrc->lModels.end(); newb++)
  79. {
  80. BYTE bNewbIndex = newb->bIndex;
  81. for (ModelRList::iterator i = lModels.begin(); i != lModels.end(); )
  82. {
  83. if (bNewbIndex != i->bIndex)
  84. i++;
  85. else
  86. i = lModels.erase(i);
  87. }
  88. }
  89. std::copy(pSrc->lModels.begin(), pSrc->lModels.end(), std::back_inserter(lModels));
  90. }
  91. BinaryWriter *ModelInfo::NetData()
  92. {
  93. BinaryWriter* Poo = new BinaryWriter;
  94. Poo->WriteBYTE(0x11);
  95. Poo->WriteBYTE((BYTE)lPalettes.size());
  96. Poo->WriteBYTE((BYTE)lTextures.size());
  97. Poo->WriteBYTE((BYTE)lModels.size());
  98. if (!lPalettes.empty())
  99. {
  100. Poo->WritePackedDWORD(dwBasePalette);
  101. for (PaletteRList::iterator i = lPalettes.begin(); i != lPalettes.end(); i++)
  102. {
  103. Poo->WritePackedDWORD(i->dwPaletteID);
  104. Poo->WriteBYTE(i->bOffset);
  105. Poo->WriteBYTE(i->bLength);
  106. }
  107. }
  108. if (!lTextures.empty())
  109. {
  110. for (TextureRList::iterator i = lTextures.begin(); i != lTextures.end(); i++)
  111. {
  112. Poo->WriteBYTE(i->bIndex);
  113. Poo->WritePackedDWORD(i->dwOriginID);
  114. Poo->WritePackedDWORD(i->dwTextureID);
  115. }
  116. }
  117. if (!lModels.empty())
  118. {
  119. for (ModelRList::iterator i = lModels.begin(); i != lModels.end(); i++)
  120. {
  121. Poo->WriteBYTE(i->bIndex);
  122. Poo->WritePackedDWORD(i->dwModelID);
  123. }
  124. }
  125. Poo->Align();
  126. //OutputConsoleBytes( Poo->GetData(), Poo->GetSize() );
  127. return Poo;
  128. }