Implement 3DS region auto-detect

This commit is contained in:
wheremyfoodat 2023-08-13 18:08:22 +03:00
parent b896d9a4aa
commit 408dbe75a0
6 changed files with 84 additions and 0 deletions

View file

@ -5,6 +5,7 @@
#include "io_file.hpp"
#include "helpers.hpp"
#include "crypto/aes_engine.hpp"
#include "services/region_codes.hpp"
struct NCCH {
struct EncryptionInfo {
@ -60,6 +61,8 @@ struct NCCH {
std::vector<u8> codeFile;
// Contains of the cart's save data
std::vector<u8> saveData;
// The cart region. Only the CXI's region matters to us. Necessary to get past region locking
std::optional<Regions> region = std::nullopt;
// Returns true on success, false on failure
// Partition index/offset/size must have been set before this
@ -71,6 +74,9 @@ struct NCCH {
bool hasCode() { return codeFile.size() != 0; }
bool hasSaveData() { return saveData.size() != 0; }
// Parse SMDH for region info and such. Returns false on failure, true on success
bool parseSMDH(const std::vector<u8>& smdh);
std::pair<bool, Crypto::AESKey> getPrimaryKey(Crypto::AESEngine &aesEngine, const Crypto::AESKey &keyY);
std::pair<bool, Crypto::AESKey> getSecondaryKey(Crypto::AESEngine &aesEngine, const Crypto::AESKey &keyY);

View file

@ -9,6 +9,7 @@
#include "helpers.hpp"
#include "handles.hpp"
#include "loader/ncsd.hpp"
#include "services/region_codes.hpp"
#include "services/shared_font.hpp"
namespace PhysicalAddrs {
@ -151,6 +152,8 @@ private:
// Values taken from 3DBrew and Citra
static constexpr FirmwareInfo firm{.unk = 0, .revision = 0, .minor = 0x34, .major = 2, .syscoreVer = 2, .sdkVer = 0x0000F297};
// Adjusted upon loading a ROM based on the ROM header. Used by CFG::SecureInfoGetArea to get past region locks
Regions region = Regions::USA;
public:
u16 kernelVersion = 0;
@ -261,4 +264,5 @@ public:
void setVRAM(u8* pointer) { vram = pointer; }
bool allocateMainThreadStack(u32 size);
Regions getConsoleRegion();
};