NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
dMj2dHeader_c Class Reference

#include <game/bases/d_mj2d_data.hpp>

Description

Represents the header of the game's save file.

The save file header contains data that is not related to a specific save slot, along with basic information required to identify the data and preserve its integrity. For the slot-specific save data, refer to dMj2dGame_c.

Contents

The header is composed by the following fields:

  • A region-dependent magic value. A mismatch (for example, by importing a savefile from another region) will cause the save to be marked as corrupted.
  • A major and minor revision number:
    • A different major revision number will cause the version to be updated silently (see versionUpdate for details).
    • A different minor revision number will not trigger any action.
  • The last selected file. It is updated automatically when loading a save slot.
  • The play count for each level in both free mode and coin battle. The values are incremented by 100 every time a level is played, up to a maximum of 10000. It is unknown why this specific convention was chosen.
  • The unlocked worlds in Extra Modes. This bitfield is determined by checking if each world is unlocked in at least one of the story mode files.
  • A CRC32 checksum of all the above data, minus the magic. A mismatch (for example, by hex editing the save file and forgetting to update this value) will cause the save to be marked as corrupted.
    Hint:
    User changes to the above structure must preserve the 32 byte alignment boundary. This is a NAND level restriction.

Modifying the Contents

Read/write access to the fields related to Extra Modes is provided through dedicated functions. All other fields are handled automatically by the game, therefore developer interaction is not required.

Note
Changes to data stored in this class are temporary, unless the save is flushed to NAND. This can be achieved through the dSaveMng_c class.

Resetting the Contents

To reset the contents of the header, call the initialize function.

Definition at line 45 of file d_mj2d_data.hpp.

Public Member Functions

 dMj2dHeader_c ()
 Constructs the holder.
 
void initialize ()
 Initializes the header data.
 
u16 getPlayCountFreeMode (int world, int level) const
 Gets the Free Mode play count for the given world/level. See mPlayCountFreeMode.
 
void setPlayCountFreeMode (int world, int level, int count)
 Sets the Free Mode play count for the given world/level. See mPlayCountFreeMode.
 
u16 getPlayCountCoinBattle (int world, int level) const
 Gets the Coin Battle play count for the given world/level. See mPlayCountCoinBattle.
 
void setPlayCountCoinBattle (int world, int level, int count)
 Sets the Coin Battle play count for the given world/level. See mPlayCountCoinBattle.
 
void onMultiWorldOpenFlag (int world)
 Unlocks the given world in extra modes.
 
bool isMultiWorldOpenFlag (int world)
 Checks if the given world is unlocked in extra modes.
 

Private Member Functions

void versionUpdate ()
 Ensures that the save's major revision number matches the current one.
 
void setSelectFileNo (s8 file)
 Sets the last used save data slot.
 

Private Attributes

char mMagic [4]
 The savegame magic. See SAVE_MAGIC.
 
u8 mRevision [2]
 The save revision numbers. See SAVE_REVISION_MAJOR and SAVE_REVISION_MINOR.
 
u8 mLastSelectedFile
 The last selected save data slot.
 
u8 mUnknown7
 [Unused]. Padding.
 
u16 mPlayCountFreeMode [WORLD_COUNT][STAGE_COUNT]
 The play count of each level in Free Mode.
 
u16 mPlayCountCoinBattle [WORLD_COUNT][STAGE_COUNT]
 The play count of each level in Coin Battle.
 
u16 mMultiWorldOpenFlag
 The worlds unlocked in Extra Modes.
 
u16 mUnknown69A
 [Unused]. Padding.
 
u32 mChecksum
 The CRC32 checksum of the above data (excluding mMagic).
 

Constructor & Destructor Documentation

◆ dMj2dHeader_c()

dMj2dHeader_c::dMj2dHeader_c ( )

Constructs the holder.

Definition at line 267 of file d_mj2d_data.cpp.

Member Function Documentation

◆ initialize()

void dMj2dHeader_c::initialize ( )

Initializes the header data.

Definition at line 270 of file d_mj2d_data.cpp.

◆ getPlayCountFreeMode()

u16 dMj2dHeader_c::getPlayCountFreeMode ( int world,
int level ) const

Gets the Free Mode play count for the given world/level. See mPlayCountFreeMode.

Definition at line 286 of file d_mj2d_data.cpp.

◆ setPlayCountFreeMode()

void dMj2dHeader_c::setPlayCountFreeMode ( int world,
int level,
int count )

Sets the Free Mode play count for the given world/level. See mPlayCountFreeMode.

Definition at line 290 of file d_mj2d_data.cpp.

◆ getPlayCountCoinBattle()

u16 dMj2dHeader_c::getPlayCountCoinBattle ( int world,
int level ) const

Gets the Coin Battle play count for the given world/level. See mPlayCountCoinBattle.

Definition at line 294 of file d_mj2d_data.cpp.

◆ setPlayCountCoinBattle()

void dMj2dHeader_c::setPlayCountCoinBattle ( int world,
int level,
int count )

Sets the Coin Battle play count for the given world/level. See mPlayCountCoinBattle.

Definition at line 298 of file d_mj2d_data.cpp.

◆ onMultiWorldOpenFlag()

void dMj2dHeader_c::onMultiWorldOpenFlag ( int world)

Unlocks the given world in extra modes.

Definition at line 302 of file d_mj2d_data.cpp.

◆ isMultiWorldOpenFlag()

bool dMj2dHeader_c::isMultiWorldOpenFlag ( int world)

Checks if the given world is unlocked in extra modes.

Definition at line 306 of file d_mj2d_data.cpp.

◆ versionUpdate()

void dMj2dHeader_c::versionUpdate ( )
private

Ensures that the save's major revision number matches the current one.

If the revision number does not match, the header data is reset.

Definition at line 310 of file d_mj2d_data.cpp.

◆ setSelectFileNo()

void dMj2dHeader_c::setSelectFileNo ( s8 file)
private

Sets the last used save data slot.

Definition at line 282 of file d_mj2d_data.cpp.

Member Data Documentation

◆ mMagic

char dMj2dHeader_c::mMagic[4]
private

The savegame magic. See SAVE_MAGIC.

Definition at line 72 of file d_mj2d_data.hpp.

◆ mRevision

u8 dMj2dHeader_c::mRevision[2]
private

The save revision numbers. See SAVE_REVISION_MAJOR and SAVE_REVISION_MINOR.

Definition at line 73 of file d_mj2d_data.hpp.

◆ mLastSelectedFile

u8 dMj2dHeader_c::mLastSelectedFile
private

The last selected save data slot.

Definition at line 75 of file d_mj2d_data.hpp.

◆ mUnknown7

u8 dMj2dHeader_c::mUnknown7
private

[Unused]. Padding.

Definition at line 76 of file d_mj2d_data.hpp.

◆ mPlayCountFreeMode

u16 dMj2dHeader_c::mPlayCountFreeMode[WORLD_COUNT][STAGE_COUNT]
private

The play count of each level in Free Mode.

Definition at line 77 of file d_mj2d_data.hpp.

◆ mPlayCountCoinBattle

u16 dMj2dHeader_c::mPlayCountCoinBattle[WORLD_COUNT][STAGE_COUNT]
private

The play count of each level in Coin Battle.

Definition at line 78 of file d_mj2d_data.hpp.

◆ mMultiWorldOpenFlag

u16 dMj2dHeader_c::mMultiWorldOpenFlag
private

The worlds unlocked in Extra Modes.

Definition at line 79 of file d_mj2d_data.hpp.

◆ mUnknown69A

u16 dMj2dHeader_c::mUnknown69A
private

[Unused]. Padding.

Definition at line 80 of file d_mj2d_data.hpp.

◆ mChecksum

u32 dMj2dHeader_c::mChecksum
private

The CRC32 checksum of the above data (excluding mMagic).

Definition at line 82 of file d_mj2d_data.hpp.