SettingsHandler: Add Open and Save member functions
This commit is contained in:
parent
f37c5f1f1c
commit
98291cd843
|
@ -18,6 +18,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/SettingsHandler.h"
|
#include "Common/SettingsHandler.h"
|
||||||
#include "Common/Timer.h"
|
#include "Common/Timer.h"
|
||||||
|
|
||||||
|
@ -26,9 +27,30 @@ SettingsHandler::SettingsHandler()
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SettingsHandler::Open(const std::string& settings_file_path)
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
|
||||||
|
File::IOFile file{settings_file_path, "rb"};
|
||||||
|
if (!file.ReadBytes(m_buffer.data(), m_buffer.size()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Decrypt();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SettingsHandler::Save(const std::string& destination_file_path) const
|
||||||
|
{
|
||||||
|
if (!File::CreateFullPath(destination_file_path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
File::IOFile file{destination_file_path, "wb"};
|
||||||
|
return file.WriteBytes(m_buffer.data(), m_buffer.size());
|
||||||
|
}
|
||||||
|
|
||||||
const u8* SettingsHandler::GetData() const
|
const u8* SettingsHandler::GetData() const
|
||||||
{
|
{
|
||||||
return m_buffer;
|
return m_buffer.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string SettingsHandler::GetValue(const std::string& key)
|
const std::string SettingsHandler::GetValue(const std::string& key)
|
||||||
|
@ -62,10 +84,10 @@ const std::string SettingsHandler::GetValue(const std::string& key)
|
||||||
|
|
||||||
void SettingsHandler::Decrypt()
|
void SettingsHandler::Decrypt()
|
||||||
{
|
{
|
||||||
const u8* str = m_buffer;
|
const u8* str = m_buffer.data();
|
||||||
while (*str != 0)
|
while (*str != 0)
|
||||||
{
|
{
|
||||||
if (m_position >= SETTINGS_SIZE)
|
if (m_position >= m_buffer.size())
|
||||||
return;
|
return;
|
||||||
decoded.push_back((u8)(m_buffer[m_position] ^ m_key));
|
decoded.push_back((u8)(m_buffer[m_position] ^ m_key));
|
||||||
m_position++;
|
m_position++;
|
||||||
|
@ -79,7 +101,7 @@ void SettingsHandler::Reset()
|
||||||
decoded = "";
|
decoded = "";
|
||||||
m_position = 0;
|
m_position = 0;
|
||||||
m_key = INITIAL_SEED;
|
m_key = INITIAL_SEED;
|
||||||
memset(m_buffer, 0, SETTINGS_SIZE);
|
m_buffer = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsHandler::AddSetting(const std::string& key, const std::string& value)
|
void SettingsHandler::AddSetting(const std::string& key, const std::string& value)
|
||||||
|
@ -102,7 +124,7 @@ void SettingsHandler::AddSetting(const std::string& key, const std::string& valu
|
||||||
|
|
||||||
void SettingsHandler::WriteByte(u8 b)
|
void SettingsHandler::WriteByte(u8 b)
|
||||||
{
|
{
|
||||||
if (m_position >= SETTINGS_SIZE)
|
if (m_position >= m_buffer.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_buffer[m_position] = b ^ m_key;
|
m_buffer[m_position] = b ^ m_key;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
@ -13,8 +14,6 @@
|
||||||
class SettingsHandler
|
class SettingsHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SettingsHandler();
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
SETTINGS_SIZE = 0x100,
|
SETTINGS_SIZE = 0x100,
|
||||||
|
@ -22,6 +21,11 @@ public:
|
||||||
INITIAL_SEED = 0x73B5DBFA
|
INITIAL_SEED = 0x73B5DBFA
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SettingsHandler();
|
||||||
|
|
||||||
|
bool Open(const std::string& settings_file_path);
|
||||||
|
bool Save(const std::string& destination_file_path) const;
|
||||||
|
|
||||||
void AddSetting(const std::string& key, const std::string& value);
|
void AddSetting(const std::string& key, const std::string& value);
|
||||||
|
|
||||||
const u8* GetData() const;
|
const u8* GetData() const;
|
||||||
|
@ -34,7 +38,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void WriteByte(u8 b);
|
void WriteByte(u8 b);
|
||||||
|
|
||||||
u8 m_buffer[SETTINGS_SIZE];
|
std::array<u8, SETTINGS_SIZE> m_buffer;
|
||||||
u32 m_position, m_key;
|
u32 m_position, m_key;
|
||||||
std::string decoded;
|
std::string decoded;
|
||||||
};
|
};
|
||||||
|
|
|
@ -196,18 +196,14 @@ bool CBoot::SetupWiiMemory(u64 ios_title_id)
|
||||||
|
|
||||||
SettingsHandler gen;
|
SettingsHandler gen;
|
||||||
std::string serno;
|
std::string serno;
|
||||||
std::string settings_Filename(
|
const std::string settings_file_path(
|
||||||
Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + WII_SETTING);
|
Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + WII_SETTING);
|
||||||
if (File::Exists(settings_Filename))
|
if (File::Exists(settings_file_path) && gen.Open(settings_file_path))
|
||||||
{
|
{
|
||||||
File::IOFile settingsFileHandle(settings_Filename, "rb");
|
serno = gen.GetValue("SERNO");
|
||||||
if (settingsFileHandle.ReadBytes((void*)gen.GetData(), SettingsHandler::SETTINGS_SIZE))
|
gen.Reset();
|
||||||
{
|
|
||||||
gen.Decrypt();
|
File::Delete(settings_file_path);
|
||||||
serno = gen.GetValue("SERNO");
|
|
||||||
gen.Reset();
|
|
||||||
}
|
|
||||||
File::Delete(settings_Filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serno.empty() || serno == "000000000")
|
if (serno.empty() || serno == "000000000")
|
||||||
|
@ -233,19 +229,15 @@ bool CBoot::SetupWiiMemory(u64 ios_title_id)
|
||||||
gen.AddSetting("VIDEO", region_setting.video);
|
gen.AddSetting("VIDEO", region_setting.video);
|
||||||
gen.AddSetting("GAME", region_setting.game);
|
gen.AddSetting("GAME", region_setting.game);
|
||||||
|
|
||||||
File::CreateFullPath(settings_Filename);
|
if (!gen.Save(settings_file_path))
|
||||||
{
|
{
|
||||||
File::IOFile settingsFileHandle(settings_Filename, "wb");
|
PanicAlertT("SetupWiiMemory: Can't create setting.txt file");
|
||||||
|
return false;
|
||||||
if (!settingsFileHandle.WriteBytes(gen.GetData(), SettingsHandler::SETTINGS_SIZE))
|
|
||||||
{
|
|
||||||
PanicAlertT("SetupWiiMemory: Can't create setting.txt file");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Write the 256 byte setting.txt to memory.
|
|
||||||
Memory::CopyToEmu(0x3800, gen.GetData(), SettingsHandler::SETTINGS_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the 256 byte setting.txt to memory.
|
||||||
|
Memory::CopyToEmu(0x3800, gen.GetData(), SettingsHandler::SETTINGS_SIZE);
|
||||||
|
|
||||||
INFO_LOG(BOOT, "Setup Wii Memory...");
|
INFO_LOG(BOOT, "Setup Wii Memory...");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -126,24 +126,19 @@ IPCCommandResult NetKDRequest::IOCtl(const IOCtlRequest& request)
|
||||||
INFO_LOG(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_GENERATED_USER_ID");
|
INFO_LOG(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_GENERATED_USER_ID");
|
||||||
if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_INITIAL)
|
if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_INITIAL)
|
||||||
{
|
{
|
||||||
std::string settings_Filename(
|
const std::string settings_file_path(
|
||||||
Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + WII_SETTING);
|
Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + WII_SETTING);
|
||||||
SettingsHandler gen;
|
SettingsHandler gen;
|
||||||
std::string area, model;
|
std::string area, model;
|
||||||
bool _GotSettings = false;
|
bool got_settings = false;
|
||||||
|
|
||||||
if (File::Exists(settings_Filename))
|
if (File::Exists(settings_file_path) && gen.Open(settings_file_path))
|
||||||
{
|
{
|
||||||
File::IOFile settingsFileHandle(settings_Filename, "rb");
|
area = gen.GetValue("AREA");
|
||||||
if (settingsFileHandle.ReadBytes((void*)gen.GetData(), SettingsHandler::SETTINGS_SIZE))
|
model = gen.GetValue("MODEL");
|
||||||
{
|
got_settings = true;
|
||||||
gen.Decrypt();
|
|
||||||
area = gen.GetValue("AREA");
|
|
||||||
model = gen.GetValue("MODEL");
|
|
||||||
_GotSettings = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (_GotSettings)
|
if (got_settings)
|
||||||
{
|
{
|
||||||
u8 area_code = GetAreaCode(area);
|
u8 area_code = GetAreaCode(area);
|
||||||
u8 id_ctr = config.IdGen();
|
u8 id_ctr = config.IdGen();
|
||||||
|
|
Loading…
Reference in New Issue