Skip to content

Instantly share code, notes, and snippets.

@Sajidur78
Last active March 17, 2021 22:30
Show Gist options
  • Save Sajidur78/bf1012ebad9dfab27a0986715d56d0d2 to your computer and use it in GitHub Desktop.
Save Sajidur78/bf1012ebad9dfab27a0986715d56d0d2 to your computer and use it in GitHub Desktop.
Binary template/C header for Sonic Lost World ResCharAnimScript(.anm) files.
// This file functions both as a C header file and a binary template
#ifdef _010EDITOR
#define FILE_BASE 0x40
#define _010ARRAY <optimize=false>
#define BCOLOR_PURPLE <bgcolor=cPurple>
#define BEGIN_PTR size_t m_Offset<hidden=true>; \
local size_t curPos = FTell(); \
FSeek(m_Offset + FILE_BASE);
#define END_PTR FSeek(curPos);
typedef uint size_t;
struct PCSTR;
string STRRead(PCSTR& str)
{
if (str.m_Offset != 0)
return str.m_Value;
return "";
}
typedef struct
{
BEGIN_PTR
if (m_Offset != 0)
string m_Value;
END_PTR
}PCSTR <read = STRRead>;
struct AnimationArray;
struct PAnimationArray
{
BEGIN_PTR
AnimationArray m_Value;
END_PTR
};
struct ComplexAnimationArray;
struct PComplexAnimationArray
{
BEGIN_PTR
ComplexAnimationArray m_Value;
END_PTR
};
struct TransitionTable;
struct PTransitionTable
{
BEGIN_PTR
TransitionTable m_Value;
END_PTR
};
struct SimpleDef;
string ANIMATIONRead(SimpleDef& anim)
{
return anim.m_pName.m_Value;
}
struct TransitionInfo;
string TRANSITIONINFORead(TransitionInfo& info)
{
return info.m_pFrom.m_Value + " -> " + info.m_pTo.m_Value;
}
struct AnimationDefArray;
struct PAnimationDefArray
{
BEGIN_PTR
AnimationDefArray m_Value;
END_PTR
};
struct ComplexData;
struct PComplexData
{
BEGIN_PTR
ComplexData m_Value;
END_PTR
};
struct BlenderDef;
struct PBlenderDef
{
BEGIN_PTR
BlenderDef m_Value;
END_PTR
};
#define READ_TRANSITION_INFO <read=TRANSITIONINFORead>
#define READ_ANIMATION <read=ANIMATIONRead>
#else
#define READ_ANIMATION
#define READ_TRANSITION_INFO
#define BEGIN_PTR
#define END_PTR
typedef const char* PCSTR;
struct AnimationDefArray;
typedef AnimationDefArray* PAnimationDefArray;
struct ComplexAnimationArray;
typedef ComplexAnimationArray* PComplexAnimationArray;
struct TransitionTable;
typedef TransitionTable* PTransitionTable;
struct ComplexData;
typedef ComplexData* PComplexData;
struct BlenderDef;
typedef BlenderDef* PBlenderDef;
#endif
#ifdef _010EDITOR
enum <ushort> EAnimationType
#else
enum EAnimationType : ushort
#endif
{
SIMPLE, COMPLEX
};
enum Options
{
STOP = 0,
LOOP = 1,
UNKNOWN = 2,
MIRROR = 4
};
enum PlayMode
{
PLAYMODE_STOP, PLAYMODE_LOOP
};
enum InterpolateMode
{
IMMEDIATE,
STOP_PLAY,
STOP_STOP,
FINISH_STOP,
PLAY_PLAY,
PLAY_STOP,
FINISH_PLAY,
SYNCHRONIZE,
};
enum TriggerValueType
{
TYPE_ENUM,
TYPE_INT,
TYPE_FLOAT,
TYPE_STRING
};
typedef struct
{
PlayMode m_Mode;
short m_RandomMin;
short m_RandomMax;
}PlayModeInfo;
typedef struct
{
PCSTR m_pName;
float m_Weight;
int m_Priority;
}BlendAddNode;
// Size is 20
struct BlenderDef
{
size_t m_StructType; // Always 1
PCSTR m_pName;
float m_Weight;
size_t m_NodeCount;
#ifdef _010EDITOR
BEGIN_PTR
BlendAddNode m_Nodes[m_NodeCount]_010ARRAY;
END_PTR
#else
BlendAddNode* m_pNodes;
#endif
};
// Size is 12
typedef struct
{
size_t m_StructType; // Always 1
size_t m_BlenderCount;
#ifdef _010EDITOR
BEGIN_PTR
PBlenderDef m_Blenders[m_BlenderCount]_010ARRAY;
END_PTR
#else
PBlenderDef* m_ppBlenders;
#endif
}BlenderData;
typedef struct
{
PCSTR m_pName;
}SeqData;
// Size is 20
typedef struct
{
size_t m_StructType; // Always 0
PlayModeInfo m_PlayMode;
size_t m_SequenceCount;
#ifdef _010EDITOR
BEGIN_PTR
SeqData m_Sequences[m_SequenceCount]_010ARRAY;
END_PTR
#else
SeqData* m_pSequences;
#endif
}SequenceTable;
typedef struct
{
PCSTR m_pFrom;
PCSTR m_pTo;
} TransitionInfo READ_TRANSITION_INFO;
struct TransitionTable
{
size_t m_Count;
#ifdef _010EDITOR
BEGIN_PTR
TransitionInfo m_Transitions[m_Count]_010ARRAY;
END_PTR
#else
TransitionInfo* m_pTransitions;
#endif
};
typedef struct
{
InterpolateMode m_Unk1; // Enter interpolation?
InterpolateMode m_Unk2; // Exit interpolation?
float m_Time;
PCSTR m_From;
} InterpolateInfo;
typedef struct
{
size_t m_Count;
#ifdef _010EDITOR
BEGIN_PTR
InterpolateInfo m_Values[m_Count]_010ARRAY;
END_PTR
#else
InterpolateInfo* m_Interpolations;
#endif
} InterpolateArray;
typedef union
{
int m_Int;
float m_Float;
PCSTR m_String;
} EventData;
typedef struct
{
float m_Frame;
uint m_Unk1; // Type?
TriggerValueType m_ValueType;
EventData m_Value;
} TriggerInfo;
typedef struct
{
size_t m_Count;
#ifdef _010EDITOR
BEGIN_PTR
TriggerInfo m_pEvents[m_Count]_010ARRAY;
END_PTR
#else
TriggerInfo* m_pEvents;
#endif
} TriggerInfoArray;
typedef struct
{
PCSTR m_pName;
EAnimationType m_Type;
ushort m_Layer;
PCSTR m_pResource;
float m_StartFrame;
float m_EndFrame;
float m_Speed;
PlayModeInfo m_PlayInfo;
Options m_Options;
InterpolateArray m_Interpolations;
TriggerInfoArray m_Callbacks;
} SimpleDef READ_ANIMATION;
struct ComplexData
{
size_t m_StructType;
#ifdef _010EDITOR
FSeek(FTell() - sizeof(size_t));
if (m_StructType == 1)
BlenderData m_Blender;
else
SequenceTable m_Sequences;
#endif
};
struct SimpleAnimationArray
{
size_t m_AnimationCount;
#ifdef _010EDITOR
BEGIN_PTR
SimpleDef m_pAnimations[m_AnimationCount]_010ARRAY;
END_PTR
#else
SimpleDef* m_pAnimations;
#endif
};
struct ComplexDef
{
PCSTR m_pName;
EAnimationType m_Type;
short m_Layer;
SimpleAnimationArray m_Animations;
PComplexData m_pData;
};
struct ComplexAnimationArray
{
size_t m_Count;
#ifdef _010EDITOR
BEGIN_PTR
ComplexDef m_pComplexAnimations[m_Count]_010ARRAY;
END_PTR
#else
ComplexDef* m_pComplexAnimations;
#endif
};
struct AnimationDefArray
{
SimpleAnimationArray m_SimpleAnimations;
ComplexAnimationArray m_ComplexAnimations;
};
typedef struct
{
PCSTR m_pSignature;
PCSTR m_pVersion;
ushort m_Unk1; // Container count? Target?
ushort m_TriggerCount;
PAnimationDefArray m_pAnimations;
PTransitionTable m_pTransitions;
} FileHeader;
#ifdef _010EDITOR
FSeek(FILE_BASE);
FileHeader m_Header BCOLOR_PURPLE;
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment