2023-06-29 04:10:08 -04:00
|
|
|
#include "mxdsaction.h"
|
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
#include "legoutil.h"
|
2023-10-07 11:30:04 -04:00
|
|
|
#include "mxomni.h"
|
|
|
|
#include "mxtimer.h"
|
|
|
|
|
2023-08-06 13:39:22 -04:00
|
|
|
#include <float.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2023-08-10 13:57:19 -04:00
|
|
|
DECOMP_SIZE_ASSERT(MxDSAction, 0x94)
|
|
|
|
|
|
|
|
// GLOBAL OFFSET: LEGO1 0x10101410
|
|
|
|
MxU16 g_unkSep = TWOCC(',', ' ');
|
|
|
|
|
2023-06-29 04:10:08 -04:00
|
|
|
// OFFSET: LEGO1 0x100ad810
|
|
|
|
MxDSAction::MxDSAction()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
this->m_flags = MxDSAction::Flag_Enabled;
|
|
|
|
this->m_startTime = INT_MIN;
|
|
|
|
this->m_extraData = NULL;
|
|
|
|
this->m_extraLength = 0;
|
|
|
|
this->m_duration = INT_MIN;
|
|
|
|
this->m_loopCount = -1;
|
|
|
|
|
|
|
|
this->SetType(MxDSType_Action);
|
|
|
|
this->m_location.Fill(FLT_MAX);
|
|
|
|
this->m_direction.Fill(FLT_MAX);
|
|
|
|
this->m_up.Fill(FLT_MAX);
|
|
|
|
this->m_unk84 = NULL;
|
|
|
|
this->m_unk88 = 0;
|
|
|
|
this->m_omni = NULL;
|
|
|
|
this->m_unkTimingField = INT_MIN;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-07-16 02:51:11 -04:00
|
|
|
// OFFSET: LEGO1 0x100ada80
|
2023-06-29 04:10:08 -04:00
|
|
|
MxDSAction::~MxDSAction()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
delete[] this->m_extraData;
|
2023-08-06 13:39:22 -04:00
|
|
|
}
|
2023-08-08 22:38:07 -04:00
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100adaf0
|
2023-10-24 19:38:27 -04:00
|
|
|
void MxDSAction::CopyFrom(MxDSAction& p_dsAction)
|
2023-08-08 22:38:07 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
this->SetObjectId(p_dsAction.GetObjectId());
|
|
|
|
this->m_flags = p_dsAction.m_flags;
|
|
|
|
this->m_startTime = p_dsAction.m_startTime;
|
|
|
|
this->m_duration = p_dsAction.m_duration;
|
|
|
|
this->m_loopCount = p_dsAction.m_loopCount;
|
|
|
|
|
|
|
|
this->m_location.CopyFrom(p_dsAction.m_location);
|
|
|
|
this->m_direction.CopyFrom(p_dsAction.m_direction);
|
|
|
|
this->m_up.CopyFrom(p_dsAction.m_up);
|
|
|
|
|
|
|
|
AppendData(p_dsAction.m_extraLength, p_dsAction.m_extraData);
|
|
|
|
this->m_unk84 = p_dsAction.m_unk84;
|
|
|
|
this->m_unk88 = p_dsAction.m_unk88;
|
|
|
|
this->m_omni = p_dsAction.m_omni;
|
|
|
|
this->m_unkTimingField = p_dsAction.m_unkTimingField;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100adc10
|
2023-10-24 19:38:27 -04:00
|
|
|
MxDSAction& MxDSAction::operator=(MxDSAction& p_dsAction)
|
2023-08-08 22:38:07 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (this == &p_dsAction)
|
|
|
|
return *this;
|
2023-08-08 22:38:07 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
MxDSObject::operator=(p_dsAction);
|
|
|
|
this->CopyFrom(p_dsAction);
|
|
|
|
return *this;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100adbe0
|
|
|
|
MxU32 MxDSAction::GetSizeOnDisk()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxU32 totalSizeOnDisk;
|
2023-08-08 22:38:07 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
totalSizeOnDisk = MxDSObject::GetSizeOnDisk() + 90 + this->m_extraLength;
|
|
|
|
this->m_sizeOnDisk = totalSizeOnDisk - MxDSObject::GetSizeOnDisk();
|
2023-08-08 22:38:07 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return totalSizeOnDisk;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100adf70
|
2023-10-24 19:38:27 -04:00
|
|
|
void MxDSAction::Deserialize(char** p_source, MxS16 p_unk24)
|
2023-08-08 22:38:07 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxDSObject::Deserialize(p_source, p_unk24);
|
|
|
|
|
|
|
|
GetScalar(p_source, this->m_flags);
|
|
|
|
GetScalar(p_source, this->m_startTime);
|
|
|
|
GetScalar(p_source, this->m_duration);
|
|
|
|
GetScalar(p_source, this->m_loopCount);
|
|
|
|
GetDouble(p_source, this->m_location[0]);
|
|
|
|
GetDouble(p_source, this->m_location[1]);
|
|
|
|
GetDouble(p_source, this->m_location[2]);
|
|
|
|
GetDouble(p_source, this->m_direction[0]);
|
|
|
|
GetDouble(p_source, this->m_direction[1]);
|
|
|
|
GetDouble(p_source, this->m_direction[2]);
|
|
|
|
GetDouble(p_source, this->m_up[0]);
|
|
|
|
GetDouble(p_source, this->m_up[1]);
|
|
|
|
GetDouble(p_source, this->m_up[2]);
|
|
|
|
|
|
|
|
MxU16 extraLength = GetScalar((MxU16**) p_source);
|
|
|
|
if (extraLength) {
|
|
|
|
AppendData(extraLength, *p_source);
|
|
|
|
*p_source += extraLength;
|
|
|
|
}
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100ad940
|
|
|
|
MxLong MxDSAction::GetDuration()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return this->m_duration;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100ad950
|
|
|
|
void MxDSAction::SetDuration(MxLong p_duration)
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
this->m_duration = p_duration;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100adc40
|
2023-10-24 19:38:27 -04:00
|
|
|
MxDSAction* MxDSAction::Clone()
|
2023-08-08 22:38:07 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxDSAction* clone = new MxDSAction();
|
2023-08-08 22:38:07 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (clone)
|
|
|
|
*clone = *this;
|
2023-08-08 22:38:07 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return clone;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100add00
|
2023-10-24 19:38:27 -04:00
|
|
|
void MxDSAction::MergeFrom(MxDSAction& p_dsAction)
|
2023-08-08 22:38:07 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (p_dsAction.m_startTime != INT_MIN)
|
|
|
|
this->m_startTime = p_dsAction.m_startTime;
|
|
|
|
|
|
|
|
if (p_dsAction.GetDuration() != INT_MIN)
|
|
|
|
this->m_duration = p_dsAction.GetDuration();
|
|
|
|
|
|
|
|
if (p_dsAction.m_loopCount != -1)
|
|
|
|
this->m_loopCount = p_dsAction.m_loopCount;
|
|
|
|
|
|
|
|
if (p_dsAction.m_location[0] != FLT_MAX)
|
|
|
|
this->m_location[0] = p_dsAction.m_location[0];
|
|
|
|
if (p_dsAction.m_location[1] != FLT_MAX)
|
|
|
|
this->m_location[1] = p_dsAction.m_location[1];
|
|
|
|
if (p_dsAction.m_location[2] != FLT_MAX)
|
|
|
|
this->m_location[2] = p_dsAction.m_location[2];
|
|
|
|
|
|
|
|
if (p_dsAction.m_direction[0] != FLT_MAX)
|
|
|
|
this->m_direction[0] = p_dsAction.m_direction[0];
|
|
|
|
if (p_dsAction.m_direction[1] != FLT_MAX)
|
|
|
|
this->m_direction[1] = p_dsAction.m_direction[1];
|
|
|
|
if (p_dsAction.m_direction[2] != FLT_MAX)
|
|
|
|
this->m_direction[2] = p_dsAction.m_up[2]; // This is correct
|
|
|
|
|
|
|
|
if (p_dsAction.m_up[0] != FLT_MAX)
|
|
|
|
this->m_up[0] = p_dsAction.m_up[0];
|
|
|
|
if (p_dsAction.m_up[1] != FLT_MAX)
|
|
|
|
this->m_up[1] = p_dsAction.m_up[1];
|
|
|
|
if (p_dsAction.m_up[2] != FLT_MAX)
|
|
|
|
this->m_up[2] = p_dsAction.m_up[2];
|
|
|
|
|
|
|
|
MxU16 extraLength = p_dsAction.m_extraLength;
|
|
|
|
char* extraData = p_dsAction.m_extraData;
|
|
|
|
|
|
|
|
// Taking those references forces the compiler to move the values onto the stack.
|
|
|
|
// The original code most likely looked different, but this yields a 100% match.
|
|
|
|
MxU16& _extraLength = extraLength;
|
|
|
|
char*& _extraData = extraData;
|
|
|
|
if (extraLength && extraData) {
|
|
|
|
if (!this->m_extraData || !strncmp("XXX", this->m_extraData, 3)) {
|
|
|
|
delete[] this->m_extraData;
|
|
|
|
this->m_extraLength = 0;
|
|
|
|
AppendData(extraLength, extraData);
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100ad960
|
|
|
|
MxBool MxDSAction::HasId(MxU32 p_objectId)
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return this->GetObjectId() == p_objectId;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100ada40
|
2023-10-13 17:36:16 -04:00
|
|
|
void MxDSAction::SetUnkTimingField(MxLong p_unkTimingField)
|
2023-08-08 22:38:07 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
this->m_unkTimingField = p_unkTimingField;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100ada50
|
2023-10-13 17:36:16 -04:00
|
|
|
MxLong MxDSAction::GetUnkTimingField()
|
2023-08-08 22:38:07 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return this->m_unkTimingField;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
2023-09-25 16:28:25 -04:00
|
|
|
// Win32 defines GetCurrentTime to GetTickCount
|
|
|
|
#undef GetCurrentTime
|
|
|
|
|
2023-08-08 22:38:07 -04:00
|
|
|
// OFFSET: LEGO1 0x100adcd0
|
|
|
|
MxLong MxDSAction::GetCurrentTime()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return Timer()->GetTime() - this->m_unkTimingField;
|
2023-08-08 22:38:07 -04:00
|
|
|
}
|
|
|
|
|
2023-08-10 13:57:19 -04:00
|
|
|
// OFFSET: LEGO1 0x100ade60
|
2023-10-24 19:38:27 -04:00
|
|
|
void MxDSAction::AppendData(MxU16 p_extraLength, const char* p_extraData)
|
2023-08-08 22:38:07 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (this->m_extraData == p_extraData || !p_extraData)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this->m_extraLength) {
|
|
|
|
char* concat = new char[p_extraLength + this->m_extraLength + sizeof(g_unkSep)];
|
|
|
|
memcpy(concat, this->m_extraData, this->m_extraLength);
|
|
|
|
|
|
|
|
*(MxU16*) &concat[this->m_extraLength] = g_unkSep;
|
|
|
|
memcpy(&concat[this->m_extraLength + sizeof(g_unkSep)], p_extraData, p_extraLength);
|
|
|
|
|
|
|
|
this->m_extraLength += p_extraLength + sizeof(g_unkSep);
|
|
|
|
delete[] this->m_extraData;
|
|
|
|
this->m_extraData = concat;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char* copy = new char[p_extraLength];
|
|
|
|
this->m_extraData = copy;
|
|
|
|
|
|
|
|
if (copy) {
|
|
|
|
this->m_extraLength = p_extraLength;
|
|
|
|
memcpy(copy, p_extraData, p_extraLength);
|
|
|
|
}
|
|
|
|
}
|
2023-08-09 19:48:49 -04:00
|
|
|
}
|