mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
36cdb4a544
Also make the `Decrypt` method private. As far as I can tell, the only motivation for exposing the `SetBytes` and `Reset` methods is to allow `CBoot::SetupWiiMemory` to use the same `SettingsHandler` instance to read settings data and then write it back. It seems cleaner to just use two separate instances, and require a given `SettingsHandler` instance to be used for either writing data to a buffer or reading data from a buffer, but not both. A natural next step is to split the `SettingsHandler` class into two classes, one for writing data and one for reading data. I've deferred that change for a future PR.
47 lines
968 B
C++
47 lines
968 B
C++
// Copyright 2008 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Thanks to Treeki for writing the original class - 29/01/2012
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
namespace Common
|
|
{
|
|
class SettingsHandler
|
|
{
|
|
public:
|
|
enum
|
|
{
|
|
SETTINGS_SIZE = 0x100,
|
|
// Key used to encrypt/decrypt setting.txt contents
|
|
INITIAL_SEED = 0x73B5DBFA
|
|
};
|
|
|
|
using Buffer = std::array<u8, SETTINGS_SIZE>;
|
|
SettingsHandler();
|
|
explicit SettingsHandler(const Buffer& buffer);
|
|
|
|
void AddSetting(std::string_view key, std::string_view value);
|
|
|
|
const Buffer& GetBytes() const;
|
|
std::string GetValue(std::string_view key) const;
|
|
|
|
static std::string GenerateSerialNumber();
|
|
|
|
private:
|
|
void Decrypt();
|
|
void WriteLine(std::string_view str);
|
|
void WriteByte(u8 b);
|
|
|
|
std::array<u8, SETTINGS_SIZE> m_buffer;
|
|
u32 m_position, m_key;
|
|
std::string decoded;
|
|
};
|
|
} // namespace Common
|