-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathModelInfo.cpp
145 lines (128 loc) · 3.54 KB
/
ModelInfo.cpp
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
#include "StdAfx.h"
#include "ModelInfo.h"
//TODO: Layer the model data in the correct order.
// What if the player has steel toe boots and amuli? Amuli covers the STB!
void ModelInfo::MergeData(ModelInfo* pSrc, DWORD dwLayer)
{
//if ( !pSrc->wBasePalette )
// return;
if (!dwBasePalette)
dwBasePalette = pSrc->dwBasePalette;
for (PaletteRList::iterator newb = pSrc->lPalettes.begin(); newb != pSrc->lPalettes.end(); newb++)
{
DWORD dwNewbID = newb->dwPaletteID;
BYTE bNewbStart = newb->bOffset;
BYTE bNewbEnd = newb->bOffset + newb->bLength;
for (PaletteRList::iterator i = lPalettes.begin(); i != lPalettes.end(); )
{
DWORD dwBobID = i->dwPaletteID;
BYTE bBobStart = i->bOffset;
BYTE bBobEnd = i->bOffset + i->bLength;
if (bBobStart < bNewbStart)
{
if (bBobEnd <= bNewbStart) {
//These do not collide
}
else if (bBobEnd > bNewbEnd) {
//Going to have to split the existing into 2
PaletteRpl pr1(dwBobID, bBobStart, bNewbStart - bBobStart);
PaletteRpl pr2(dwBobID, bNewbEnd, bBobEnd - (bNewbEnd));
lPalettes.push_back(pr1);
lPalettes.push_back(pr2);
}
else
{
//Need to cut off high-side of the existing
PaletteRpl pr1(dwBobID, bBobStart, bNewbStart - bBobStart);
lPalettes.push_back(pr1);
}
i++;
continue;
}
else //if ( bBobStart >= bNewbStart )
{
if (bBobStart >= bNewbEnd)
{
//These do not collide
i++;
}
else if (bBobEnd <= bNewbEnd)
{
//The existing is completely overwritten
i = lPalettes.erase(i);
}
else
{
//Need to cut off low-side of the existing
PaletteRpl pr2(dwBobID, bNewbEnd, bBobEnd - bNewbEnd);
lPalettes.push_back(pr2);
i++;
}
continue;
}
}
}
std::copy(pSrc->lPalettes.begin(), pSrc->lPalettes.end(), std::back_inserter(lPalettes));
for (TextureRList::iterator newb = pSrc->lTextures.begin(); newb != pSrc->lTextures.end(); newb++)
{
BYTE bNewbIndex = newb->bIndex;
for (TextureRList::iterator i = lTextures.begin(); i != lTextures.end(); )
{
if (bNewbIndex != i->bIndex)
i++;
else
i = lTextures.erase(i);
}
}
std::copy(pSrc->lTextures.begin(), pSrc->lTextures.end(), std::back_inserter(lTextures));
for (ModelRList::iterator newb = pSrc->lModels.begin(); newb != pSrc->lModels.end(); newb++)
{
BYTE bNewbIndex = newb->bIndex;
for (ModelRList::iterator i = lModels.begin(); i != lModels.end(); )
{
if (bNewbIndex != i->bIndex)
i++;
else
i = lModels.erase(i);
}
}
std::copy(pSrc->lModels.begin(), pSrc->lModels.end(), std::back_inserter(lModels));
}
BinaryWriter *ModelInfo::NetData()
{
BinaryWriter* Poo = new BinaryWriter;
Poo->WriteBYTE(0x11);
Poo->WriteBYTE((BYTE)lPalettes.size());
Poo->WriteBYTE((BYTE)lTextures.size());
Poo->WriteBYTE((BYTE)lModels.size());
if (!lPalettes.empty())
{
Poo->WritePackedDWORD(dwBasePalette);
for (PaletteRList::iterator i = lPalettes.begin(); i != lPalettes.end(); i++)
{
Poo->WritePackedDWORD(i->dwPaletteID);
Poo->WriteBYTE(i->bOffset);
Poo->WriteBYTE(i->bLength);
}
}
if (!lTextures.empty())
{
for (TextureRList::iterator i = lTextures.begin(); i != lTextures.end(); i++)
{
Poo->WriteBYTE(i->bIndex);
Poo->WritePackedDWORD(i->dwOriginID);
Poo->WritePackedDWORD(i->dwTextureID);
}
}
if (!lModels.empty())
{
for (ModelRList::iterator i = lModels.begin(); i != lModels.end(); i++)
{
Poo->WriteBYTE(i->bIndex);
Poo->WritePackedDWORD(i->dwModelID);
}
}
Poo->Align();
//OutputConsoleBytes( Poo->GetData(), Poo->GetSize() );
return Poo;
}