19#include "tsl/ordered_map.h"
301bool IsOfType(
const std::filesystem::path& path);
379template <
class... Ts,
class Node>
380inline std::tuple<Ts...>
ReadArgs(std::size_t main_node_ind,
const std::vector<Node>& nodes) {
381 static_assert(std::is_same_v<Node, AnimationNode> || std::is_same_v<Node, EffectNode>,
"not a node");
382 std::tuple<Ts...> result;
383 std::size_t offset = 0;
387 static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
decltype(args)>>);
388 static_assert(
sizeof(args) <=
sizeof(Node));
392 auto& main_node = nodes.at(main_node_ind).main;
394 std::size_t required_size =
395 main_node_ind + 1 + (
utl::math::RoundNum(offset +
sizeof(args),
sizeof(Node)) /
sizeof(Node));
397 if (required_size > nodes.size())
400 if (
sizeof(Node) + offset +
sizeof(args) > main_node.next_main_node *
sizeof(Node))
403 std::memcpy(&args,
reinterpret_cast<const char*
>(nodes.data() + main_node_ind + 1) + offset,
sizeof(args));
405 offset +=
sizeof(args);
439template <
class... Ts,
class Node>
440inline void WriteArgs(std::size_t main_node_ind, std::vector<Node>& nodes,
const Ts&&... args) {
441 static_assert(std::is_same_v<Node, AnimationNode> || std::is_same_v<Node, EffectNode>,
"not a node");
442 std::size_t offset = 0;
445 static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
decltype(args)>>);
447 static_assert(
sizeof(args) <=
sizeof(Node));
449 auto& main_node = nodes.at(main_node_ind).main;
453 std::size_t required_size =
454 main_node_ind + 1 + (
utl::math::RoundNum(offset +
sizeof(args),
sizeof(Node)) /
sizeof(Node));
456 if (main_node.next_main_node != 0 &&
457 sizeof(Node) + offset +
sizeof(args) > main_node.next_main_node *
sizeof(Node))
460 if (required_size > nodes.size()) {
461 nodes.resize(required_size);
464 std::memcpy(
reinterpret_cast<char*
>(nodes.data() + main_node_ind + 1) + offset, &args,
sizeof(args));
466 offset +=
sizeof(args);
470 std::size_t index_next_node = 1 +
utl::math::RoundNum(offset,
sizeof(Node)) /
sizeof(Node);
472 auto& main_node = nodes.at(main_node_ind).main;
474 if (index_next_node > main_node.next_main_node) main_node.next_main_node = index_next_node;
486inline std::size_t
NextNodeInd(std::size_t main_node_ind,
const std::vector<Node>& nodes) {
487 static_assert(std::is_same_v<Node, AnimationNode> || std::is_same_v<Node, EffectNode>,
"not a node");
488 const auto& main_node = nodes.at(main_node_ind).main;
489 return main_node_ind + main_node.next_main_node;
513static_assert(
sizeof(RActionCategory) == 0x8);
517static_assert(
sizeof(RHeader) == 0x20);
520 u16 offset_animation_nodes = 0;
521 u16 offset_action_name = 0;
522 u16 offset_effect_nodes = 0;
523 u16 offset_unknown = 0;
526static_assert(
sizeof(RAction) == 0x8);
529 u16 index_function = 0;
530 u8 next_main_node = 1;
534static_assert(
sizeof(RAnimationNode) == 0x4);
535static_assert(
sizeof(RAnimationNode) ==
sizeof(AnimationNode));
538 u8 index_function = 0;
539 u8 next_main_node = 0;
543static_assert(
sizeof(REffectNode) == 0x4);
544static_assert(
sizeof(REffectNode) ==
sizeof(EffectNode));
546struct RActionConfig {
549 std::map<u32, std::vector<RAction>> actions;
550 std::map<u16, std::vector<RAnimationNode>> animation_nodes;
551 std::map<u16, std::string> action_names;
552 std::map<u16, std::vector<REffectNode>> effect_nodes;
557RActionConfig Parse(Reader& f);
Contains the definition for action identifiers that are used across different parts of the library.
Contains macros and definitions for fixed-width types.
std::map< u16, std::set< std::string > > GetAnimationNames(const ActionConfig &action_config)
Returns a map of animation IDs and names of all actions in which those animations were used.
std::tuple< Ts... > ReadArgs(std::size_t main_node_ind, const std::vector< Node > &nodes)
Extracts arguments from a series of nodes.
Definition action.hpp:380
std::size_t NextNodeInd(std::size_t main_node_ind, const std::vector< Node > &nodes)
Calculates the absolute index of the next main node in a vector.
Definition action.hpp:486
void WriteArgs(std::size_t main_node_ind, std::vector< Node > &nodes, const Ts &&... args)
Converts arguments to a series of nodes.
Definition action.hpp:440
std::vector< EffectNode > effect_nodes
Definition action.hpp:265
NNL_PACK(struct { AnimationFunction function;u8 next_main_node;bool flag;}) main
Layout of a main node.
u8 args[4]
Raw memory for storing argument values in argument nodes.
Definition action.hpp:134
std::vector< AnimationNode > animation_nodes
Definition action.hpp:261
u8 args[4]
Array for storing argument values (in argument nodes)
Definition action.hpp:245
std::string name
The name of the action. It does not affect anything.
Definition action.hpp:260
A union that represents a function or argument node within an animation playback chain.
Definition action.hpp:124
A union that represents a function or argument node within an auxiliary effect playback chain.
Definition action.hpp:234
Represents an action.
Definition action.hpp:259
constexpr u16 kNumAnimFuncNSLAR
Definition action.hpp:44
ActionConfig Import(BufferView buffer)
Parses a binary file and converts it to ActionConfig.
AnimationFunction
Enumeration for different animation functions.
Definition action.hpp:68
constexpr u16 kNumAnimFuncNSUNI
Definition action.hpp:38
tsl::ordered_map< action::Id, Action > ActionConfig
Represents a collection of actions associated with an entity.
Definition action.hpp:286
constexpr u16 kNumEffectFuncNSUNI
Definition action.hpp:41
EffectFunction
Enumeration for different effect functions.
Definition action.hpp:157
constexpr u16 kNumEffectFuncNSLAR
Definition action.hpp:47
bool IsOfType(BufferView buffer)
Tests if the provided file is an action config.
Buffer Export(const ActionConfig &action_config)
Converts ActionConfig to a binary file representation.
@ kEndAnimationPlayback
This is used after 0xF, 0x6, 0x5; [].
Definition action.hpp:79
@ kEnableEffect
Definition action.hpp:105
@ kSetMeshGroupVisib
Definition action.hpp:97
@ kEnd
Mark the end of a node sequence; [].
Definition action.hpp:69
@ kUnk11
Might call a function; [{u16,_},{u32}].
Definition action.hpp:93
@ kPlayAnimation
Definition action.hpp:89
@ kInitCountdown
Init a countdown; a0 - time?, a1 ? [{u16,u16}].
Definition action.hpp:83
@ kSetBossHitTarget
Something related to a hit circle on bosses; [{i16,i16}].
Definition action.hpp:85
@ kCheckCountdown
Check if the countdown is 0; [].
Definition action.hpp:84
@ kGoto
Definition action.hpp:71
@ kTransitionToAnimation6
Definition action.hpp:76
@ kUnk13
Might call a function; [{unused}].
Definition action.hpp:95
@ kInitAnimationPlayback
This is used before 0xF (sometimes 0x6); [].
Definition action.hpp:80
@ kTransitionToAnimation5
Seems to be almost the same as 0x6; [{i16,i16}].
Definition action.hpp:75
@ kSetFlags
Definition action.hpp:81
@ kWaitAfter
Definition action.hpp:99
@ kNext
Jump to the next specified node; [].
Definition action.hpp:70
@ kWaitBefore
Definition action.hpp:101
@ kUnkD
Might call a function; [{i32}].
Definition action.hpp:86
@ kDisableTextureSwap
Disable a texture swap; a0 - texture swap id; [{u16,_}].
Definition action.hpp:104
@ kUnk12
?; if a0 == 0 animation gets stuck; [{u16,_}]
Definition action.hpp:94
@ kUnk1A
Definition action.hpp:107
@ kSetAnimSpeed
Definition action.hpp:87
@ kEnableTextureSwap
Activate a texture swap; a0 - texture swap id; [{u16,_}].
Definition action.hpp:103
@ kSetComboTransitFrames
Definition action.hpp:109
@ kSetAnimStartFrame
Definition action.hpp:91
@ kSetFlags16
[{u32},{u16,u16}]
Definition action.hpp:185
@ kNextD
Does nothing?; [].
Definition action.hpp:175
@ kOpacityTransition3
? a0 - type, a1 - num frames, a2 - ? [{u16, i16}, {f32}]
Definition action.hpp:163
@ kPlaySFX
Definition action.hpp:167
@ kAnimateCamera1F
Definition action.hpp:211
@ kNextF
Does nothing?; [].
Definition action.hpp:177
@ kPlayUVAnim
a0 - uv anim id, a1 - u_shift, a2 - v_shift [{u16,i16},{i16,_}]
Definition action.hpp:172
@ kOpacityTransitionB
a0 - unk, a1 - vfx group id, [{u8, u8, u16}, {f32}]
Definition action.hpp:173
@ kOpacityTransition4
? [{u16, i16},{f32}]
Definition action.hpp:164
@ kOpacityTransition6
? [{u16,i16},{i16,i16}]
Definition action.hpp:166
@ kEnableEffect14
a0 - effect id [{u16,i16}]
Definition action.hpp:183
@ kMoveRootBone
Definition action.hpp:209
@ kPlaySFXRND
Definition action.hpp:169
@ kUnk17
? [{u16,i16},{f32},{f32},{f32},{f32}];
Definition action.hpp:186
@ kUnk10
?
Definition action.hpp:178
@ kSlowdown
?
Definition action.hpp:188
@ kSetFlags1
Definition action.hpp:159
@ kSetTextureSwapStat
a0 - swap id, a1 - enabled/disabled [{u16, u16}]
Definition action.hpp:215
@ kUnkC
?
Definition action.hpp:174
@ kUnk18
?
Definition action.hpp:187
@ kUnk1C
?
Definition action.hpp:201
@ kSetFlags15
? [{u32},{u16,u16}]
Definition action.hpp:184
@ kUnk25
? Used in "Scene" action configs [{}, {}]
Definition action.hpp:218
@ kSetFlags23
Set some character flags (?) [{i16,i16},{i16,i16},{i16,i16}].
Definition action.hpp:216
@ kEnableEffect1B
Definition action.hpp:199
@ kSetFlags13
?
Definition action.hpp:181
@ kNextE
Does nothing?; [].
Definition action.hpp:176
@ kEnableDisplayEffect
Definition action.hpp:189
@ kAnimateCamera
Definition action.hpp:202
@ kEnableJutsuEffect
The num of args may vary.
Definition action.hpp:214
constexpr std::size_t kNumActionCategories
Defines the number of action categories;.
Definition action_common.hpp:34
Exception thrown for out-of-range errors.
Definition exception.hpp:111
#define NNL_THROW(object)
Throws an exception or terminates the program if exceptions are disabled.
Definition exception.hpp:46
std::uint16_t u16
16-bit unsigned integer
Definition fixed_type.hpp:62
std::uint32_t u32
32-bit unsigned integer
Definition fixed_type.hpp:60
std::uint8_t u8
8-bit unsigned integer
Definition fixed_type.hpp:64
#define NNL_PACK(...)
A structure packing directive.
Definition fixed_type.hpp:41
T RoundNum(T number, std::size_t multiple)
Rounds number up to the nearest multiple.
Definition math.hpp:219
Provides classes for reading and writing binary data to and from various sources.
Provides various math utility functions.
Contains structures and functions for working with game actions.
Definition action.hpp:31
Definition exception.hpp:56