NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
NNL: A library for modding NSUNI and NSLAR

Description

NNL is a C++ library dedicated to the modding of two PlayStation Portable titles:

  • Naruto Shippuden: Ultimate Ninja Impact
  • Naruto Shippuden: Legends: Akatsuki Rising

Features

NNL provides an API for:

  • Archive Management: Unpack and repack game archives.
  • Asset Processing: Parse and manipulate game-native formats, such as 3D models and textures.
  • Format Conversion: Export assets to and import from standard exchange formats, such as glTF and PNG.

Related Tools

The following projects are built on top of the library:

  • UNIT: A CLI tool for batch processing, unpacking, and converting assets.
  • Web Viewer: A browser-based viewer for inspection of game assets.

Integration (CMake)

Add the following to your CMakeLists.txt:

include(FetchContent)
# 1. Configure the library
set(NNL_ENABLE_LOGGING ON)
FetchContent_Declare(
NNL
GIT_REPOSITORY https://github.com/Raw-man/NNL.git
GIT_TAG main
)
FetchContent_MakeAvailable(NNL)
# 2. Link against the alias target
target_link_libraries(${PROJECT_NAME} PUBLIC NNL::NNL)

Building

Ensure you have the following installed:

  • Git
  • Ninja or Make
  • C++17 compiler (GCC 13+, Clang 16+, or MSVC 19.28+)
  • CMake 3.20+
  • Doxygen 1.14+ (optional, for documentation)

Run the following commands:

git clone https://github.com/Raw-man/NNL.git
cd NNL
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build

Once built, you can run the tests. Note: you must provide the main asset archive from NSLAR (ULUS10447):

cd build
ctest --output-on-failure

Documentation

The latest API reference is available online at raw-man.github.io/NNL/

To generate the local HTML API reference, run the custom documentation target after the build step:

cmake --build build --target doc

Usage

This example shows how to extract Naruto's asset from the game archives and convert the data into a standard GLB file.

#include <iostream>
#include "NNL/nnl.hpp"
int main() {
using namespace nnl;
// Initialize the path to the main data archive from NSLAR (ULUS10447).
// Note: Archives from NSUNI require decryption before processing;
// see https://gbatemp.net/threads/pgd-encrypter.432029/
std::filesystem::path cfc_dig_path = std::filesystem::u8path("0000.BIN");
if(!std::filesystem::exists(cfc_dig_path)){
std::cerr << "Error: The file does not exist: " << std::filesystem::absolute(cfc_dig_path) << std::endl;
return 1;
}
// Validate file type. The format namespace lists all currently known asset formats.
// dig::IsOfType() can also be used.
if (format::Detect(cfc_dig_path) != format::kDig)
{
std::cerr << "Error: Invalid file format" << std::endl;
return 1;
}
// Parse the main archive structure. cfc is an std::vector of raw binary archive entries.
dig::Dig cfc = dig::Import(cfc_dig_path);
// For this example, let's access the archive that stores Naruto.
const std::size_t naruto_archive_index = 8;
const dig::FileRecord& naruto_rec = cfc.at(naruto_archive_index);
// Extract and decompress the record. Note: see FileRecord::is_compressed
Buffer decomp_buf = dig::Decompress(naruto_rec.buffer, naruto_rec.decompressed_size);
// The entries that the main archive stores are nested archives as well.
dig_entry::DigEntry cfc_ent = dig_entry::Import(decomp_buf);
// Access the entry that stores the 3D model.
const std::size_t naruto_3d_asset_index = 0;
Buffer& naruto_bin_3d_asset = cfc_ent.at(naruto_3d_asset_index);
// That entry is a container that stores closely related parts of a complete asset
asset::Asset ast_container = asset::Import(naruto_bin_3d_asset);
// Extract individual components
Buffer& bin_nrt_mdl = ast_container.at(asset::Asset3D::kModel);
Buffer& bin_nrt_tex = ast_container.at(asset::Asset3D::kTextureContainer);
Buffer& bin_nrt_anim = ast_container.at(asset::Asset3D::kAnimationContainer);
Buffer& bin_nrt_vis_anim = ast_container.at(asset::Asset3D::kVisanimationContainer);
Buffer& bin_nrt_action_conf = ast_container.at(asset::Asset3D::kActionConfig);
model::Model nrt_mdl = model::Import(bin_nrt_mdl);
visanimation::AnimationContainer nrt_vis_anim = visanimation::Import(bin_nrt_vis_anim);
action::ActionConfig nrt_action_conf = action::Import(bin_nrt_action_conf);
// The reverse operation:
// auto bin_tex_re = texture::Export(nrt_tex);
// Transform game-specific assets into a simplified representation for easier manipulation.
SAsset3D simple_ast;
simple_ast.model = model::Convert(nrt_mdl);
simple_ast.textures = texture::Convert(nrt_tex);
simple_ast.animations = animation::Convert(nrt_anim);
simple_ast.visibility_animations = visanimation::Convert(nrt_vis_anim);
// The reverse operation:
// auto params = texture::GenerateConvertParam(nrt_tex);
// auto tex = texture::Convert(std::move(simple_ast.textures), params);
auto names = action::GetAnimationNames(nrt_action_conf);
for (std::size_t i = 0; i < simple_ast.animations.size(); i++) {
auto& sanim = simple_ast.animations.at(i);
if (!names[i].empty()) sanim.name += "_" + *names[i].begin();
}
// Save the asset to a standard format (GLB).
std::filesystem::path out_path = std::filesystem::u8path("naruto.glb");
simple_ast.ExportGLB(out_path);
// The reverse operation:
// SAsset3D simple_ast_re = SAsset3D::Import(out_path);
return 0;
}
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.
ActionConfig Import(BufferView buffer)
Parses a binary file and converts it to ActionConfig.
tsl::ordered_map< action::Id, Action > ActionConfig
Represents a collection of actions associated with an entity.
Definition action.hpp:286
Holds a collection of skeletal animations.
Definition animation.hpp:92
std::vector< SAnimation > Convert(const AnimationContainer &animations)
Converts multiple in-game animations to a simpler format.
AnimationContainer Import(BufferView buffer)
Imports animations from a binary file.
Asset Import(BufferView buffer)
Parses a binary file and converts it into an Asset object.
std::map< u32, Buffer > Asset
A container for related parts of a complete asset.
Definition asset.hpp:57
DigEntry Import(BufferView buffer)
Parses a binary file and converts it into a DigEntry object.
std::vector< Buffer > DigEntry
A nested archive within a top-level Dig archive.
Definition dig_entry.hpp:48
Buffer Decompress(BufferView buffer, u32 decompressed_size)
Decompress binary data.
u32 decompressed_size
Definition dig.hpp:55
TData buffer
Binary file buffer that stores a nested archive.
Definition dig.hpp:58
TFileRecord< Buffer > FileRecord
A raw entry in the dig archive.
Definition dig.hpp:67
std::vector< FileRecord > Dig
A primary game data archive.
Definition dig.hpp:90
Dig Import(BufferView buffer)
Parses a binary file and converts it into a Dig object.
FileFormat Detect(BufferView buffer)
Detects the file format of the provided buffer.
@ kDig
A primary asset archive (a .BIN file in NSUNI/NSLAR).
Definition format.hpp:40
std::vector< u8 > Buffer
A type alias for std::vector<u8> that denotes a raw, contiguous memory region that may be interpreted...
Definition io.hpp:40
Represents a 3D model with various components.
Definition model.hpp:478
Model Import(BufferView buffer)
Parses a binary file and converts it to a structured model.
Model Convert(SModel &&smodel, const std::vector< ConvertParam > &mesh_params, bool move_with_root=false)
Converts a simplified model representation to the in-game format.
std::vector< SAnimation > animations
Skeletal animations.
Definition sasset3d.hpp:120
std::vector< SVisibilityAnimation > visibility_animations
Visibility animations for mesh groups of the model.
Definition sasset3d.hpp:121
std::vector< STexture > textures
Textures used by the materials of the model.
Definition sasset3d.hpp:119
SModel model
The 3D model.
Definition sasset3d.hpp:118
void ExportGLB(const std::filesystem::path &path, bool flip=true, bool pack_textures=true) const
Exports the asset data to a GLB file.
Represents a 3D asset composed of various components.
Definition sasset3d.hpp:116
Holds a collection of visibility animations.
Definition visanimation.hpp:104
AnimationContainer Convert(std::vector< SVisibilityAnimation > &&sanimations)
Converts multiple simple visibility animations to the in-game format.
AnimationContainer Import(BufferView buffer)
Imports animations from a binary file.
std::vector< STexture > Convert(const TextureContainer &texture_container, bool mipmaps=false)
Converts a container of textures to a simplified representation.
std::vector< Texture > TextureContainer
Type alias for a container of textures.
Definition texture.hpp:191
TextureContainer Import(BufferView buffer)
Parses a binary file and converts it to a structured texture container.
constexpr u32 kTextureContainer
Definition asset.hpp:194
constexpr u32 kVisanimationContainer
Definition asset.hpp:205
constexpr u32 kActionConfig
Definition asset.hpp:196
constexpr u32 kModel
Definition asset.hpp:193
constexpr u32 kAnimationContainer
Definition asset.hpp:195
Definition exception.hpp:56
An all-in-one header for the library.