Reconstruction layout: generated-src/ (generated) and src/ (curated), CMake, the first takeover: RNG

The decompiled C++ tree moves to generated-src/ (classes.h, C++20); src/ is for code written by hand. A curated function
defines the generated declaration and starts its comment with its address, and source_tree.py stops emitting that body.
src/rng.cpp takes over RNG (SetSeed, the constructor, Next, RandomInt, RandomFloat, Shuffle) with the shift table read
from the exe as a constexpr array; src/log.h names KAGE_LogMessage's levels (1 INFO, 2 NET, 4 WARN, 8 ERROR, 16 ASSERT,
from its prefix jump table). CMakeLists.txt builds src/*.cpp against generated-src/classes.h (clean with -Wall -Wextra).
structs.hpp and headers.py are retired: scripts/merge_fields.py writes the merged field list, classes.h checks the layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-11-19 21:10:23 -05:00
1 parent 2ff2d5d87f
commit 3ce74c6e2d
331 files changed
+485 -7835

No files matched your search

+942
View File
@@ -0,0 +1,942 @@
#include "classes.h"
// 004073b0
byte AnimationState::IsLoopingAnimation()
{
if (this->_animData == (void *)0x0) {
return 0;
}
return *GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(this->_animData) + 0x34));
}
// 004086e0
AnimationState::AnimationState(void *owner, AnimationState *other)
{
void *animData;
longlong allocBytes;
this->_animation = owner;
animData = other->_animData;
this->_animData = animData;
if ((animData == (void *)0x0) || (*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x1c)) == 0)) {
this->_layerFrames = (void *)0x0;
}
else {
allocBytes = (ulonglong)*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x1c)) * 4;
animData = operator_new_tracked
(-GHIDRA_UINT((GHIDRA_INT(((ulonglong)allocBytes >> 0x20)) != 0)) | GHIDRA_UINT(allocBytes));
this->_layerFrames = animData;
memcpy(animData,other->_layerFrames,*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animData) + 0x1c)) << 2);
animData = this->_animData;
}
if ((animData == (void *)0x0) || (*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x24)) == 0)) {
this->_nullLayerFrames = (void *)0x0;
}
else {
allocBytes = (ulonglong)*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x24)) * 4;
animData = operator_new_tracked
(-GHIDRA_UINT((GHIDRA_INT(((ulonglong)allocBytes >> 0x20)) != 0)) | GHIDRA_UINT(allocBytes));
this->_nullLayerFrames = animData;
memcpy(animData,other->_nullLayerFrames,*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animData) + 0x24)) << 2);
}
this->_animFrame = other->_animFrame;
this->_isPlaying = other->_isPlaying;
this->_currentlyTriggeredEvents = other->_currentlyTriggeredEvents;
this->_previouslyTriggeredEvents = other->_previouslyTriggeredEvents;
return;
}
// 004087a0
AnimationState::~AnimationState()
{
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
puStack_c = &LAB_00af0b40;
local_10 = ExceptionList;
ExceptionList = &local_10;
if (this->_layerFrames != (void *)0x0) {
local_8 = 0;
tracked_alloc(1,this->_layerFrames,0);
this->_layerFrames = (void *)0x0;
}
if (this->_nullLayerFrames != (void *)0x0) {
local_8 = 1;
tracked_alloc(1,this->_nullLayerFrames,0);
this->_nullLayerFrames = (void *)0x0;
}
ExceptionList = local_10;
return;
}
// 00408830
void AnimationState::SetAnimationData(void *animData)
{
void *pvVar1;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
longlong allocBytes;
puStack_c = &LAB_00af0b60;
local_10 = ExceptionList;
ExceptionList = &local_10;
this->_animData = animData;
if (this->_layerFrames != (void *)0x0) {
local_8 = 0;
tracked_alloc(1,this->_layerFrames,0);
this->_layerFrames = (void *)0x0;
}
if (this->_nullLayerFrames != (void *)0x0) {
local_8 = 1;
tracked_alloc(1,this->_nullLayerFrames,0);
this->_nullLayerFrames = (void *)0x0;
}
local_8 = 0xffffffff;
pvVar1 = this->_animData;
if (pvVar1 != (void *)0x0) {
if (*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(pvVar1) + 0x1c)) != 0) {
allocBytes = (ulonglong)*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(pvVar1) + 0x1c)) * 4;
pvVar1 = tracked_alloc(0,(void *)0x0,
(ulonglong)
(-GHIDRA_UINT((GHIDRA_INT(((ulonglong)allocBytes >> 0x20)) != 0)) | GHIDRA_UINT(allocBytes))
);
this->_layerFrames = pvVar1;
memset(pvVar1,0xff,*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animData) + 0x1c)) << 2);
pvVar1 = this->_animData;
if (pvVar1 == (void *)0x0) goto LAB_00408935;
}
if (*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(pvVar1) + 0x24)) != 0) {
allocBytes = (ulonglong)*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(pvVar1) + 0x24)) * 4;
pvVar1 = tracked_alloc(0,(void *)0x0,
(ulonglong)
(-GHIDRA_UINT((GHIDRA_INT(((ulonglong)allocBytes >> 0x20)) != 0)) | GHIDRA_UINT(allocBytes))
);
this->_nullLayerFrames = pvVar1;
memset(pvVar1,0xff,*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animData) + 0x24)) << 2);
}
}
LAB_00408935:
this->_animFrame = (float)&DAT_bf800000;
this->_isPlaying = 0;
this->_currentlyTriggeredEvents = 0;
this->_previouslyTriggeredEvents = 0;
ExceptionList = local_10;
return;
}
// 00408970
void AnimationState::ChangeAnimationKeepFrame(void *animData)
{
qword qVar1;
void *newNullLayerCount;
void *pvVar2;
uint uVar3;
qword *allocatedBytes;
uint newLayerCount;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
void *newAnimData;
void *temp_5f5450bd6d;
newAnimData = animData;
local_8 = 0xffffffff;
puStack_c = &LAB_00af0b80;
local_10 = ExceptionList;
ExceptionList = &local_10;
newNullLayerCount = this->_animData;
if (newNullLayerCount == (void *)0x0) {
uVar3 = 0;
}
else {
uVar3 = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(newNullLayerCount) + 0x1c));
}
if (animData == (void *)0x0) {
newLayerCount = 0;
}
else {
newLayerCount = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x1c));
}
if (newNullLayerCount == (void *)0x0) {
animData = (void *)0x0;
}
else {
animData = *(void **)(GHIDRA_CAST<char *>(newNullLayerCount) + 0x24);
}
if (newAnimData == (void *)0x0) {
newNullLayerCount = (void *)0x0;
}
else {
newNullLayerCount = *(void **)(GHIDRA_CAST<char *>(newAnimData) + 0x24);
}
if (uVar3 != newLayerCount) {
if (GHIDRA_INT(newLayerCount) < 1) {
if (this->_layerFrames != (void *)0x0) {
local_8 = 0;
tracked_alloc(1,this->_layerFrames,0);
local_8 = 0xffffffff;
this->_layerFrames = (void *)0x0;
}
}
else {
pvVar2 = tracked_alloc(0,(void *)0x0,
(ulonglong)
(-GHIDRA_UINT((GHIDRA_INT(((ulonglong)newLayerCount * 4 >> 0x20)) != 0)) |
GHIDRA_UINT(((ulonglong)newLayerCount * 4))));
memset(pvVar2,0xff,newLayerCount * 4);
if (0 < GHIDRA_INT(uVar3)) {
memcpy(pvVar2,this->_layerFrames,uVar3 << 2);
}
temp_5f5450bd6d = this->_layerFrames;
if (temp_5f5450bd6d != (void *)0x0) {
if (g_mainHeap == (void *)0x0) {
allocatedBytes = &g_allocatedBytesNoHeap;
}
else {
allocatedBytes = GHIDRA_CAST<qword *>((GHIDRA_INT(g_mainHeap) + 0x30));
}
uVar3 = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(temp_5f5450bd6d) + -4));
qVar1 = *allocatedBytes;
*GHIDRA_CAST<uint *>(allocatedBytes) = GHIDRA_UINT(*allocatedBytes) - uVar3;
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(allocatedBytes) + 4)) =
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(allocatedBytes) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar1) < uVar3));
free((void *)(GHIDRA_INT(temp_5f5450bd6d) + -4));
local_8 = 0xffffffff;
}
this->_layerFrames = pvVar2;
}
}
if (animData != newNullLayerCount) {
if (GHIDRA_INT(newNullLayerCount) < 1) {
if (this->_nullLayerFrames != (void *)0x0) {
local_8 = 2;
tracked_alloc(1,this->_nullLayerFrames,0);
this->_nullLayerFrames = (void *)0x0;
}
}
else {
pvVar2 = tracked_alloc(0,(void *)0x0,
(ulonglong)
(-GHIDRA_UINT((GHIDRA_INT((ZEXT48(newNullLayerCount) * 4 >> 0x20)) != 0)) |
GHIDRA_UINT((ZEXT48(newNullLayerCount) * 4))));
memset(pvVar2,0xff,GHIDRA_INT(newNullLayerCount) * 4);
if (0 < GHIDRA_INT(animData)) {
memcpy(pvVar2,this->_nullLayerFrames,GHIDRA_INT(animData) << 2);
}
newNullLayerCount = this->_nullLayerFrames;
if (newNullLayerCount != (void *)0x0) {
if (g_mainHeap == (void *)0x0) {
allocatedBytes = &g_allocatedBytesNoHeap;
}
else {
allocatedBytes = GHIDRA_CAST<qword *>((GHIDRA_INT(g_mainHeap) + 0x30));
}
uVar3 = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(newNullLayerCount) + -4));
qVar1 = *allocatedBytes;
*GHIDRA_CAST<uint *>(allocatedBytes) = GHIDRA_UINT(*allocatedBytes) - uVar3;
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(allocatedBytes) + 4)) =
*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(allocatedBytes) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar1) < uVar3));
free((void *)(GHIDRA_INT(newNullLayerCount) + -4));
this->_nullLayerFrames = (void *)0x0;
}
this->_layerFrames = pvVar2;
}
}
this->_animData = newAnimData;
ExceptionList = local_10;
return;
}
// 00408b90
void AnimationState::AdvanceLayerPosition(int layerId, float targetFrame)
{
int frameIdx;
void *animData;
int frameOffset;
int layerData;
void *layerFrames;
animData = this->_animData;
if (((animData == (void *)0x0) || (layerId < 0)) || (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x1c)) <= layerId)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("id out of bounds\n"));
animData = this->_animData;
}
layerFrames = this->_layerFrames;
frameIdx = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(layerFrames) + layerId * 4));
layerData = layerId * 0x10 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x18));
if (-1 < frameIdx) {
frameOffset = frameIdx * 0x6c;
do {
frameIdx = frameIdx + 1;
if (*GHIDRA_CAST<int *>((layerData + 8)) <= frameIdx) {
return;
}
if (targetFrame < (float)*GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>((layerData + 4)) + 0x68 + frameOffset))) {
return;
}
frameOffset = frameOffset + 0x6c;
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(layerFrames) + layerId * 4)) = frameIdx;
} while (-1 < frameIdx);
}
return;
}
// 00408c10
void AnimationState::AdvanceNullLayerPosition(int nullLayerID, float targetFrame)
{
int keyframe;
void *animData;
int keyframeOffset;
int nullLayerAnim;
void *nullLayerFrames;
animData = this->_animData;
if (((animData == (void *)0x0) || (nullLayerID < 0)) ||
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x24)) <= nullLayerID)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("id out of bounds\n"));
animData = this->_animData;
}
nullLayerFrames = this->_nullLayerFrames;
keyframe = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(nullLayerFrames) + nullLayerID * 4));
nullLayerAnim = nullLayerID * 0x10 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x20));
if (-1 < keyframe) {
keyframeOffset = keyframe * 0x54;
do {
keyframe = keyframe + 1;
if (*GHIDRA_CAST<int *>((nullLayerAnim + 0xc)) <= keyframe) {
return;
}
if (targetFrame < (float)*GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>((nullLayerAnim + 8)) + 0x50 + keyframeOffset))) {
return;
}
keyframeOffset = keyframeOffset + 0x54;
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(nullLayerFrames) + nullLayerID * 4)) = keyframe;
} while (-1 < keyframe);
}
return;
}
// 00408c90
void AnimationState::FireTriggersAtCurrentFrame()
{
uint eventIdx;
void *animData;
animData = this->_animData;
if (animData == (void *)0x0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("AnimationData is NULL\n"));
animData = this->_animData;
}
eventIdx = 0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x2c)) != 0) {
do {
if ((float)*GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x28)) + 4 + eventIdx * 8)) == this->_animFrame) {
this->_currentlyTriggeredEvents =
this->_currentlyTriggeredEvents |
1 << (*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x28)) + eventIdx * 8)) & 0x1f);
this->_previouslyTriggeredEvents =
this->_previouslyTriggeredEvents |
1 << (*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x28)) + eventIdx * 8)) & 0x1f);
}
eventIdx = eventIdx + 1;
} while (eventIdx < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x2c)));
}
return;
}
// 00408d00
void AnimationState::AdvancePosition(int targetFrame)
{
void *animData;
uint layer;
float targetFrameFloat;
float currentFrame;
double dVar1;
currentFrame = this->_animFrame;
dVar1 = floor((double)currentFrame);
if (targetFrame < GHIDRA_INT(dVar1)) {
KAGE_LogMessage(0x10,(byte *)
"Animation::AdvancePosition cannot go backward (new: %d, cur: %d)\n");
currentFrame = this->_animFrame;
}
targetFrameFloat = (float)targetFrame;
this->_currentlyTriggeredEvents = 0;
if (currentFrame < targetFrameFloat) {
do {
dVar1 = floor((double)this->_animFrame);
this->_animFrame = (float)dVar1 + 1.0;
FireTriggersAtCurrentFrame(this);
} while (this->_animFrame <= targetFrameFloat && targetFrameFloat != this->_animFrame);
}
animData = this->_animData;
layer = 0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x1c)) != 0) {
do {
AdvanceLayerPosition(this,layer,targetFrameFloat);
animData = this->_animData;
layer = layer + 1;
} while (layer < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x1c)));
}
layer = 0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x24)) != 0) {
do {
AdvanceNullLayerPosition(this,layer,targetFrameFloat);
layer = layer + 1;
} while (layer < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this->_animData) + 0x24)));
}
return;
}
// 00408e00
void AnimationState::SetFrameFloat(float frame)
{
void *animData;
uint layer;
float10 lastFrame;
float clampedFrame;
lastFrame = (float10)nextafterf((float)*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animData) + 0x30)),0);
clampedFrame = (float)lastFrame;
if (frame <= (float)lastFrame) {
clampedFrame = frame;
}
this->_currentlyTriggeredEvents = 0;
this->_animFrame = clampedFrame;
FireTriggersAtCurrentFrame(this);
animData = this->_animData;
layer = 0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x1c)) != 0) {
do {
if (((animData == (void *)0x0) || (GHIDRA_INT(layer) < 0)) ||
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x1c)) <= GHIDRA_INT(layer))) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("id out of bounds\n"));
}
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this->_layerFrames) + layer * 4)) = 0;
AdvanceLayerPosition(this,layer,frame);
animData = this->_animData;
layer = layer + 1;
} while (layer < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x1c)));
}
layer = 0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x24)) != 0) {
do {
if (((animData == (void *)0x0) || (GHIDRA_INT(layer) < 0)) ||
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x24)) <= GHIDRA_INT(layer))) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("id out of bounds\n"));
}
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this->_nullLayerFrames) + layer * 4)) = 0;
AdvanceNullLayerPosition(this,layer,frame);
animData = this->_animData;
layer = layer + 1;
} while (layer < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x24)));
}
return;
}
// 00408ef0
void AnimationState::SetLayerFrame(int layerID, int frame)
{
void *animData;
int dataLayerId;
if (((layerID < 0) || (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animation) + 0x80)) <= layerID)) &&
(KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("LayerId out of bounds\n")), layerID < 0)) {
return;
}
if (layerID < *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animation) + 0x80))) {
animData = this->_animData;
dataLayerId = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + layerID * 4 + 0x38));
if (((animData == (void *)0x0) || (dataLayerId < 0)) ||
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x1c)) <= dataLayerId)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("id out of bounds\n"));
}
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this->_layerFrames) + dataLayerId * 4)) = 0;
AdvanceLayerPosition(this,dataLayerId,(float)frame);
}
return;
}
// 00408f70
int AnimationState::GetLayerFrameIdx(int layerId)
{
if (((layerId < 0) || (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animation) + 0x80)) <= layerId)) &&
(KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("LayerId out of bounds\n")), layerId < 0)) {
return 0;
}
if (layerId < *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animation) + 0x80))) {
return *GHIDRA_CAST<int *>((GHIDRA_INT(this->_layerFrames) +
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animData) + layerId * 4 + 0x38)) * 4));
}
return 0;
}
// 00408fc0
void AnimationState::SetNullLayerFrame(int nullLayerId, int frame)
{
if ((nullLayerId < 0) || (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animation) + 0x88)) <= nullLayerId)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("layerId out of bounds\n"));
}
if (((this->_animData == (void *)0x0) || (nullLayerId < 0)) ||
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animData) + 0x24)) <= nullLayerId)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("id out of bounds\n"));
}
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this->_nullLayerFrames) + nullLayerId * 4)) = 0;
AdvanceNullLayerPosition(this,nullLayerId,(float)frame);
return;
}
// 00409030
void AnimationState::Update()
{
int targetFrame;
float nextFrame;
double dVar1;
void *animData;
float currentFrame;
animData = this->_animData;
if ((animData != (void *)0x0) && (this->_isPlaying != 0)) {
currentFrame = this->_animFrame;
nextFrame = currentFrame + *GHIDRA_CAST<float *>((GHIDRA_CAST<char *>(this->_animation) + 0x104));
dVar1 = floor((double)nextFrame);
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x30)) <= GHIDRA_INT(dVar1)) {
if (*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(animData) + 0x34)) != '\0') {
Rewind(this);
return;
}
targetFrame = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x30)) + -1;
dVar1 = floor((double)currentFrame);
if (GHIDRA_INT(dVar1) <= targetFrame) {
AdvancePosition(this,targetFrame);
}
this->_isPlaying = 0;
return;
}
AdvancePosition(this,GHIDRA_INT(dVar1));
this->_animFrame = nextFrame;
}
return;
}
// 0040a1b0
void AnimationState::Rewind()
{
void *animData;
uint layerIdx;
this->_animFrame = 0.0;
this->_currentlyTriggeredEvents = 0;
this->_previouslyTriggeredEvents = 0;
FireTriggersAtCurrentFrame();
animData = this->_animData;
layerIdx = 0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x1c)) != 0) {
do {
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this->_layerFrames) + layerIdx * 4)) = 0;
layerIdx = layerIdx + 1;
animData = this->_animData;
} while (layerIdx < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x1c)));
}
layerIdx = 0;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x24)) != 0) {
do {
*GHIDRA_CAST<undefined4 *>((GHIDRA_CAST<char *>(this->_nullLayerFrames) + layerIdx * 4)) = 0;
layerIdx = layerIdx + 1;
} while (layerIdx < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this->_animData) + 0x24)));
}
return;
}
// 0040a220
void * AnimationState::GetLayerFrame(int layerId)
{
int iVar1;
void *animData;
int frameIndex;
if (this->_animData == (void *)0x0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("AnimationData is NULL\n"));
}
if ((layerId < 0) || (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animation) + 0x80)) <= layerId)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("LayerId out of bounds\n"));
}
animData = this->_animData;
if ((((animData == (void *)0x0) || (layerId < 0)) ||
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animation) + 0x80)) < layerId)) ||
(((iVar1 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + layerId * 4 + 0x38)), iVar1 < 0 ||
(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x1c)) <= iVar1)) ||
((frameIndex = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_layerFrames) + iVar1 * 4)), frameIndex < 0 ||
(iVar1 = iVar1 * 0x10 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x18)), *GHIDRA_CAST<int *>((iVar1 + 8)) <= frameIndex))))
)) {
return (void *)0x0;
}
return (void *)(frameIndex * 0x6c + *GHIDRA_CAST<int *>((iVar1 + 4)));
}
// 0040ac70
void * AnimationState::GetNullFrameById(int nullLayerId)
{
void *animData;
int *nullLayer;
uint layerIdx;
int *layerFrameIt;
int frameIndex;
animData = this->_animData;
if (animData == (void *)0x0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("AnimationData is NULL\n"));
animData = this->_animData;
}
layerIdx = 0;
if (*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x24)) != 0) {
layerFrameIt = this->_nullLayerFrames;
nullLayer = *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(animData) + 0x20));
do {
if (((*nullLayer == nullLayerId) && (frameIndex = *layerFrameIt, -1 < frameIndex)) &&
(frameIndex < nullLayer[3])) {
return (void *)(frameIndex * 0x54 + nullLayer[2]);
}
layerIdx = layerIdx + 1;
nullLayer = nullLayer + 4;
layerFrameIt = layerFrameIt + 1;
} while (layerIdx < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x24)));
}
return (void *)0x0;
}
// 0040ace0
void * AnimationState::GetNullFrame(byte *nullLayerName)
{
byte *layerNameCursor;
uint cmpResult;
void *animData;
uint *nullTrack;
byte *nameCursor;
uint uVar1;
uint nullLayerIdx;
byte *nullLayerEntry;
int *frameIdxPtr;
bool isLess;
byte ch;
int frameIdx;
if (this->_animData == (void *)0x0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("AnimationData is NULL\n"));
}
nullLayerIdx = 0;
uVar1 = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this->_animation) + 0x88));
if (uVar1 != 0) {
nullLayerEntry = *GHIDRA_CAST<byte **>((GHIDRA_CAST<char *>(this->_animation) + 0x84));
do {
layerNameCursor = nullLayerEntry;
if (0xf < *GHIDRA_CAST<uint *>((nullLayerEntry + 0x14))) {
layerNameCursor = *GHIDRA_CAST<byte **>(nullLayerEntry);
}
nameCursor = nullLayerName;
do {
ch = *layerNameCursor;
isLess = ch < *nameCursor;
if (ch != *nameCursor) {
LAB_0040ad50:
cmpResult = -GHIDRA_UINT(isLess) | 1;
goto LAB_0040ad55;
}
if (ch == 0) break;
ch = layerNameCursor[1];
isLess = ch < nameCursor[1];
if (ch != nameCursor[1]) goto LAB_0040ad50;
layerNameCursor = layerNameCursor + 2;
nameCursor = nameCursor + 2;
} while (ch != 0);
cmpResult = 0;
LAB_0040ad55:
if (cmpResult == 0) {
animData = this->_animData;
if (animData == (void *)0x0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("AnimationData is NULL\n"));
animData = this->_animData;
}
uVar1 = 0;
if (*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x24)) != 0) {
nullTrack = *GHIDRA_CAST<uint **>((GHIDRA_CAST<char *>(animData) + 0x20));
frameIdxPtr = this->_nullLayerFrames;
do {
if (((*nullTrack == nullLayerIdx) && (frameIdx = *frameIdxPtr, -1 < frameIdx)) &&
(frameIdx < GHIDRA_INT(nullTrack[3]))) {
return (void *)(frameIdx * 0x54 + nullTrack[2]);
}
uVar1 = uVar1 + 1;
nullTrack = nullTrack + 4;
frameIdxPtr = frameIdxPtr + 1;
} while (uVar1 < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x24)));
}
return (void *)0x0;
}
nullLayerIdx = nullLayerIdx + 1;
nullLayerEntry = nullLayerEntry + 0x18;
} while (nullLayerIdx < uVar1);
}
return (void *)0x0;
}
// 0040add0
byte AnimationState::IsEventTriggered(byte *eventName)
{
byte *eventNameChar;
uint compareResult;
byte *queryChar;
byte *eventEntry;
uint eventIndex;
bool isLess;
byte ch;
uint eventCount;
if (this->_animData == (void *)0x0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("AnimationData is NULL\n"));
}
eventIndex = 0;
eventCount = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this->_animation) + 0x90));
if (eventCount != 0) {
eventEntry = *GHIDRA_CAST<byte **>((GHIDRA_CAST<char *>(this->_animation) + 0x8c));
do {
eventNameChar = eventEntry;
if (0xf < *GHIDRA_CAST<uint *>((eventEntry + 0x14))) {
eventNameChar = *GHIDRA_CAST<byte **>(eventEntry);
}
queryChar = eventName;
do {
ch = *eventNameChar;
isLess = ch < *queryChar;
if (ch != *queryChar) {
LAB_0040ae32:
compareResult = -GHIDRA_UINT(isLess) | 1;
goto LAB_0040ae37;
}
if (ch == 0) break;
ch = eventNameChar[1];
isLess = ch < queryChar[1];
if (ch != queryChar[1]) goto LAB_0040ae32;
eventNameChar = eventNameChar + 2;
queryChar = queryChar + 2;
} while (ch != 0);
compareResult = 0;
LAB_0040ae37:
if (compareResult == 0) {
if (GHIDRA_INT(eventIndex) < 0) {
return 0;
}
return (this->_currentlyTriggeredEvents & 1 << ((byte)eventIndex & 0x1f)) != 0;
}
eventIndex = eventIndex + 1;
eventEntry = eventEntry + 0x18;
} while (eventIndex < eventCount);
}
return 0;
}
// 0040ae70
byte AnimationState::WasEventTriggered(byte *eventName)
{
byte *entryNameCursor;
uint compareResult;
byte *wantedName;
byte *eventEntry;
uint eventIdx;
bool isLess;
uint eventCount;
byte nameChar;
if (this->_animData == (void *)0x0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("AnimationData is NULL\n"));
}
eventIdx = 0;
eventCount = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this->_animation) + 0x90));
if (eventCount != 0) {
eventEntry = *GHIDRA_CAST<byte **>((GHIDRA_CAST<char *>(this->_animation) + 0x8c));
do {
entryNameCursor = eventEntry;
if (0xf < *GHIDRA_CAST<uint *>((eventEntry + 0x14))) {
entryNameCursor = *GHIDRA_CAST<byte **>(eventEntry);
}
wantedName = eventName;
do {
nameChar = *entryNameCursor;
isLess = nameChar < *wantedName;
if (nameChar != *wantedName) {
LAB_0040aed2:
compareResult = -GHIDRA_UINT(isLess) | 1;
goto LAB_0040aed7;
}
if (nameChar == 0) break;
nameChar = entryNameCursor[1];
isLess = nameChar < wantedName[1];
if (nameChar != wantedName[1]) goto LAB_0040aed2;
entryNameCursor = entryNameCursor + 2;
wantedName = wantedName + 2;
} while (nameChar != 0);
compareResult = 0;
LAB_0040aed7:
if (compareResult == 0) {
if (GHIDRA_INT(eventIdx) < 0) {
return 0;
}
return (this->_previouslyTriggeredEvents & 1 << ((byte)eventIdx & 0x1f)) != 0;
}
eventIdx = eventIdx + 1;
eventEntry = eventEntry + 0x18;
} while (eventIdx < eventCount);
}
return 0;
}
// 0040af10
int AnimationState::NextEventTrigger(byte *eventName)
{
byte *triggerName;
uint compareResult;
byte *wantedName;
uint uVar1;
int framesUntil;
uint eventIndex;
byte *eventNameEntry;
int nearestDelta;
int nextFrame;
bool isLess;
int bestFrame;
void *animData;
byte ch;
int eventFrame;
if (this->_animData == (void *)0x0) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("AnimationData is NULL\n"));
}
eventIndex = 0;
uVar1 = *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(this->_animation) + 0x90));
if (uVar1 != 0) {
eventNameEntry = *GHIDRA_CAST<byte **>((GHIDRA_CAST<char *>(this->_animation) + 0x8c));
do {
triggerName = eventNameEntry;
if (0xf < *GHIDRA_CAST<uint *>((eventNameEntry + 0x14))) {
triggerName = *GHIDRA_CAST<byte **>(eventNameEntry);
}
wantedName = eventName;
do {
ch = *triggerName;
isLess = ch < *wantedName;
if (ch != *wantedName) {
LAB_0040af74:
compareResult = -GHIDRA_UINT(isLess) | 1;
goto LAB_0040af79;
}
if (ch == 0) break;
ch = triggerName[1];
isLess = ch < wantedName[1];
if (ch != wantedName[1]) goto LAB_0040af74;
triggerName = triggerName + 2;
wantedName = wantedName + 2;
} while (ch != 0);
compareResult = 0;
LAB_0040af79:
if (compareResult == 0) {
if (GHIDRA_INT(eventIndex) < 0) {
return -1;
}
nextFrame = -1;
uVar1 = 0;
bestFrame = -1;
nearestDelta = -1;
animData = this->_animData;
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x2c)) != 0) {
do {
if (*GHIDRA_CAST<uint *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x28)) + uVar1 * 8)) == eventIndex) {
eventFrame = *GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(animData) + 0x28)) + 4 + uVar1 * 8));
framesUntil = eventFrame - GHIDRA_INT(this->_animFrame);
nextFrame = bestFrame;
if ((0 < framesUntil) && ((nearestDelta < 0 || (framesUntil < nearestDelta)))) {
nearestDelta = framesUntil;
nextFrame = eventFrame;
bestFrame = eventFrame;
}
}
uVar1 = uVar1 + 1;
} while (uVar1 < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(animData) + 0x2c)));
}
return nextFrame;
}
eventIndex = eventIndex + 1;
eventNameEntry = eventNameEntry + 0x18;
} while (eventIndex < uVar1);
}
return -1;
}
// 0040bbf0
AnimationState * AnimationState::copy_assign(AnimationState *other)
{
void *pvVar1;
int iVar2;
int iVar3;
void *pvVar4;
void *pvVar5;
undefined3 uVar6;
byte isPlaying;
pvVar1 = other->_animData;
this->_animation = other->_animation;
this->_animData = pvVar1;
pvVar1 = other->_nullLayerFrames;
this->_layerFrames = other->_layerFrames;
this->_nullLayerFrames = pvVar1;
isPlaying = other->_isPlaying;
uVar6 = *GHIDRA_CAST<undefined3 *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>((other)) + 0x15))));
this->_animFrame = other->_animFrame;
this->_isPlaying = isPlaying;
*GHIDRA_CAST<undefined3 *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>((this)) + 0x15)))) = uVar6;
iVar2 = other->_previouslyTriggeredEvents;
this->_currentlyTriggeredEvents = other->_currentlyTriggeredEvents;
this->_previouslyTriggeredEvents = iVar2;
pvVar1 = other[1]._animData;
this[1]._animation = other[1]._animation;
this[1]._animData = pvVar1;
this[1]._layerFrames = other[1]._layerFrames;
*GHIDRA_CAST<undefined1 *>(&this[1]._nullLayerFrames) = *GHIDRA_CAST<undefined1 *>(&other[1]._nullLayerFrames);
isPlaying = other[1]._isPlaying;
uVar6 = *GHIDRA_CAST<undefined3 *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(other[1])) + 0x15))));
iVar2 = other[1]._currentlyTriggeredEvents;
iVar3 = other[1]._previouslyTriggeredEvents;
this[1]._animFrame = other[1]._animFrame;
this[1]._isPlaying = isPlaying;
*GHIDRA_CAST<undefined3 *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(this[1])) + 0x15)))) = uVar6;
this[1]._currentlyTriggeredEvents = iVar2;
this[1]._previouslyTriggeredEvents = iVar3;
pvVar1 = other[2]._animData;
pvVar4 = other[2]._layerFrames;
pvVar5 = other[2]._nullLayerFrames;
this[2]._animation = other[2]._animation;
this[2]._animData = pvVar1;
this[2]._layerFrames = pvVar4;
this[2]._nullLayerFrames = pvVar5;
isPlaying = other[2]._isPlaying;
uVar6 = *GHIDRA_CAST<undefined3 *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(other[2])) + 0x15))));
this[2]._animFrame = other[2]._animFrame;
this[2]._isPlaying = isPlaying;
*GHIDRA_CAST<undefined3 *>(&(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(this[2])) + 0x15)))) = uVar6;
this[2]._currentlyTriggeredEvents = other[2]._currentlyTriggeredEvents;
this[2]._previouslyTriggeredEvents = other[2]._previouslyTriggeredEvents;
*GHIDRA_CAST<undefined1 *>(&this[3]._animation) = *GHIDRA_CAST<undefined1 *>(&other[3]._animation);
this[3]._animData = other[3]._animData;
this[3]._layerFrames = other[3]._layerFrames;
return this;
}
// 00440e30
int AnimationState::GetAnimationLength()
{
if (this->_animData == (void *)0x0) {
return 0;
}
return *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this->_animData) + 0x30));
}