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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
#include "ZAnimation.h"
#include <utility>
#include "ZFile.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "File.h"
#include "HighLevel/HLAnimationIntermediette.h"
#include "Globals.h"
using namespace std;
ZAnimation::ZAnimation() : ZResource()
{
frameCount = 0;
}
void ZAnimation::ParseRawData()
{
const uint8_t* data = rawData.data();
// Read the header
frameCount = BitConverter::ToInt16BE(data, rawDataIndex + 0);
}
void ZAnimation::Save(const std::string& outFolder)
{
if (Globals::Instance->testMode)
{
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromZAnimation(this);
string xml = anim->OutputXML();
File::WriteAllText(outFolder + "/" + name + ".anmi", xml);
delete anim;
}
}
void ZAnimation::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
name = reader->Attribute("Name");
}
string ZAnimation::GetSourceOutputCode(const std::string& prefix)
{
return "";
}
ZNormalAnimation::ZNormalAnimation() : ZAnimation()
{
rotationValues = vector<uint16_t>();
rotationIndices = vector<RotationIndex>();
limit = 0;
}
std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
{
string defaultPrefix = name.c_str();
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
string headerStr = StringHelper::Sprintf("{ %i }, %sFrameData, %sJointIndices, %i",
frameCount, defaultPrefix.c_str(), defaultPrefix.c_str(), limit);
parent->declarations[rawDataIndex] = new Declaration(DeclarationAlignment::None, 16, "AnimationHeader", StringHelper::Sprintf("%s", name.c_str()), false, headerStr);
string indicesStr = "";
string valuesStr = " ";
const int lineLength = 14;
const int offset = 0;
for (int i = 0; i < rotationValues.size(); i++)
{
valuesStr += StringHelper::Sprintf("0x%04X, ", rotationValues[i]);
if ((i - offset + 1) % lineLength == 0)
valuesStr += "\n ";
}
for (int i = 0; i < rotationIndices.size(); i++)
{
indicesStr += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x, rotationIndices[i].y, rotationIndices[i].z);
if (i != (rotationIndices.size() - 1))
indicesStr += "\n";
}
parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16, (int)rotationValues.size() * 2, "static s16",
StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()), rotationValues.size(), valuesStr);
parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16, (int)rotationIndices.size() * 6, "static JointIndex",
StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()), rotationIndices.size(), indicesStr);
}
return "";
}
int ZNormalAnimation::GetRawDataSize()
{
return 16;
}
ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath)
{
ZNormalAnimation* anim = new ZNormalAnimation();
anim->rawData = std::move(nRawData);
anim->rawDataIndex = rawDataIndex;
anim->ParseXML(reader);
anim->ParseRawData();
return anim;
}
void ZNormalAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
const uint8_t* data = rawData.data();
rotationValuesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 4) & 0x00FFFFFF;
rotationIndicesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 8) & 0x00FFFFFF;
limit = BitConverter::ToInt16BE(data, rawDataIndex + 12);
uint32_t currentPtr = rotationValuesSeg;
// Read the Rotation Values
for (int i = 0; i < ((rotationIndicesSeg - rotationValuesSeg) / 2); i++)
{
rotationValues.push_back(BitConverter::ToInt16BE(data, currentPtr));
currentPtr += 2;
}
currentPtr = rotationIndicesSeg;
// Read the Rotation Indices
for (int i = 0; i < ((rawDataIndex - rotationIndicesSeg) / 6); i++)
{
rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr), BitConverter::ToInt16BE(data, currentPtr + 2), BitConverter::ToInt16BE(data, currentPtr + 4)));
currentPtr += 6;
}
}
ZLinkAnimation::ZLinkAnimation() : ZAnimation()
{
segmentAddress = 0;
}
std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
{
string segSymbol = segmentAddress == 0 ? "NULL" : parent->GetDeclarationName(segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(), segmentAddress));
string headerStr = StringHelper::Sprintf("{ %i }, 0x%08X",
frameCount, segmentAddress);
parent->declarations[rawDataIndex] = new Declaration(DeclarationAlignment::None, 16, "LinkAnimationHeader", StringHelper::Sprintf("%s", name.c_str()), false, headerStr);
}
return "";
}
int ZLinkAnimation::GetRawDataSize()
{
return 8;
}
ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath)
{
ZLinkAnimation* anim = new ZLinkAnimation();
anim->rawData = std::move(nRawData);
anim->rawDataIndex = rawDataIndex;
anim->ParseXML(reader);
anim->ParseRawData();
return anim;
}
void ZLinkAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
const uint8_t* data = rawData.data();
//segmentAddress = SEG2FILESPACE(BitConverter::ToInt32BE(data, rawDataIndex + 4));
segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4));
}
|