Save Functions - MarklyThomas/Secret-Repo GitHub Wiki
Description: |
---|
This initiates the data of the save slots in Data Select. |
function void ExtraChar.InitExtraSlots()
{
zeroMemory(sharedmemory.xtrachar, 0x08)
ExtraChar.LoadExtraSlots() // Read saved extra characters data
ExtraChar.SaveExtraSlots() // Save to create the keys in the Persistent Data file
ExtraChar.debugLog("Extra SRAM and Persistent Data loaded.") // Debug message
ExtraChar.InitExtraSlots_LoadLegacy() // Legacy load
ExtraChar.InitExtraSlots_SaveCorrection() // Fix your saves if they break
}
ℹ️ Location: scripts\general\saveslots.lemon
Description: |
---|
This fixes your legacy saves if they break during the fixing process. |
function void ExtraChar.InitExtraSlots_SaveCorrection()
{
// Loop simulates slots
for (u32 i = 0x00; i < 0x08; ++i)
{
u32 tempValue0 = 0xffffe6ac + i * 0x0a // Slot address
u32 tempValue1 = sharedmemory.xtrachar + i // Extra address
u8 tempValue2 = (u8[tempValue0 + 0x00] & 0x80) // Unused slot
u8 tempValue3 = (u8[tempValue0 + 0x02] >> 0x04) // Character (see CHARS_* constants)
// If an extra character is sitting here
if (u8[tempValue1] > 0x00)
{
// This slot is unused (has been deleted), or is no longer Sonic only
if (tempValue2 || tempValue3 != CHARS_SONIC_ALONE)
{
// Debug message
ExtraChar.debugLog(stringformat("Extra #%d was deleted from slot #%d; Extra address: 0x%06x", u8[tempValue1], i + 0x01, tempValue1))
// Remove an extra character from a slot
zeroMemory(tempValue1, 0x01)
ExtraChar.SaveExtraSlots()
}
}
}
}
ℹ️ Location: scripts\general\saveslots.lemon
Description: |
---|
The function pulls stored data from Persistent Data and SRAM. |
function void ExtraChar.LoadExtraSlots()
{
SRAM.load(sharedmemory.xtrachar, 0x660, 0x08)
System.loadPersistentData(sharedmemory.xtrachar, "SRAM_Extraslots", 0x08)
}
ℹ️ Location: scripts\general\saveslots.lemon
Description: |
---|
Converts and deletes your legacy saves for use with ESU. |
function void ExtraChar.InitExtraSlots_LoadLegacy()
{
// Loop simulates slots
for (u8 i = 0x00; i < 0x08; ++i)
{
// Legacy save offset
u8 tempValue0 = 0x820000
for (u8 k = i; k < 0x01; --k)
tempValue0 += 0x01
tempValue0 *= 0x04
u8 tempValue1 = System.loadPersistentData(tempValue0, stringformat("ExtraSlot_%d", i + 0x01), 0x04) // Load Legacy data
u32 tempValue2 = sharedmemory.xtrachar + i // New save address
// If there is a Legacy slot here
if (tempValue1 > 0x00)
{
// Debug message
ExtraChar.debugLog(stringformat("Detected Legacy Extra char on Slot #%d; Merged.", i + 0x01))
// Save new data
u8[tempValue2] = tempValue1
ExtraChar.SaveExtraSlots()
// Delete legacy data
System.savePersistentData(tempValue0, stringformat("ExtraSlot_%d", i + 0x01), 0x00)
}
}
}
ℹ️ Location: scripts\general\saveslots.lemon
Description: |
---|
Description: The function stores dynamic data in Persistent Data and SRAM. |
This allows you to edit your save data with the S3&K save editor, without loosing your character. |
function void ExtraChar.SaveExtraSlots()
{
SRAM.save(sharedmemory.xtrachar, 0x660, 0x08)
System.savePersistentData(sharedmemory.xtrachar, "SRAM_Extraslots", 0x08)
}
ℹ️ Location: scripts\general\saveslots.lemon