mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-13 01:29:11 +01:00
Boot_WiiWAD: Simplify state_checksum
Simplifies the interface and gets rid of pointer casts.
This commit is contained in:
parent
2cad67952d
commit
3c071cefa0
@ -2,7 +2,10 @@
|
|||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <numeric>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Common/CommonPaths.h"
|
#include "Common/CommonPaths.h"
|
||||||
@ -21,19 +24,6 @@
|
|||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
#include "DiscIO/VolumeCreator.h"
|
#include "DiscIO/VolumeCreator.h"
|
||||||
|
|
||||||
static u32 state_checksum(u32* buf, int len)
|
|
||||||
{
|
|
||||||
u32 checksum = 0;
|
|
||||||
len = len >> 2;
|
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
|
||||||
{
|
|
||||||
checksum += buf[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return checksum;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct StateFlags
|
struct StateFlags
|
||||||
{
|
{
|
||||||
u32 checksum;
|
u32 checksum;
|
||||||
@ -44,6 +34,17 @@ struct StateFlags
|
|||||||
u32 unknown[6];
|
u32 unknown[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static u32 StateChecksum(const StateFlags& flags)
|
||||||
|
{
|
||||||
|
constexpr size_t length_in_bytes = sizeof(StateFlags) - 4;
|
||||||
|
constexpr size_t num_elements = length_in_bytes / sizeof(u32);
|
||||||
|
std::array<u32, num_elements> flag_data;
|
||||||
|
|
||||||
|
std::memcpy(flag_data.data(), &flags.flags, length_in_bytes);
|
||||||
|
|
||||||
|
return std::accumulate(flag_data.cbegin(), flag_data.cend(), 0U);
|
||||||
|
}
|
||||||
|
|
||||||
bool CBoot::Boot_WiiWAD(const std::string& _pFilename)
|
bool CBoot::Boot_WiiWAD(const std::string& _pFilename)
|
||||||
{
|
{
|
||||||
std::string state_filename(Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) +
|
std::string state_filename(Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) +
|
||||||
@ -56,7 +57,7 @@ bool CBoot::Boot_WiiWAD(const std::string& _pFilename)
|
|||||||
state_file.ReadBytes(&state, sizeof(StateFlags));
|
state_file.ReadBytes(&state, sizeof(StateFlags));
|
||||||
|
|
||||||
state.type = 0x03; // TYPE_RETURN
|
state.type = 0x03; // TYPE_RETURN
|
||||||
state.checksum = state_checksum((u32*)&state.flags, sizeof(StateFlags) - 4);
|
state.checksum = StateChecksum(state);
|
||||||
|
|
||||||
state_file.Seek(0, SEEK_SET);
|
state_file.Seek(0, SEEK_SET);
|
||||||
state_file.WriteBytes(&state, sizeof(StateFlags));
|
state_file.WriteBytes(&state, sizeof(StateFlags));
|
||||||
@ -69,7 +70,7 @@ bool CBoot::Boot_WiiWAD(const std::string& _pFilename)
|
|||||||
memset(&state, 0, sizeof(StateFlags));
|
memset(&state, 0, sizeof(StateFlags));
|
||||||
state.type = 0x03; // TYPE_RETURN
|
state.type = 0x03; // TYPE_RETURN
|
||||||
state.discstate = 0x01; // DISCSTATE_WII
|
state.discstate = 0x01; // DISCSTATE_WII
|
||||||
state.checksum = state_checksum((u32*)&state.flags, sizeof(StateFlags) - 4);
|
state.checksum = StateChecksum(state);
|
||||||
state_file.WriteBytes(&state, sizeof(StateFlags));
|
state_file.WriteBytes(&state, sizeof(StateFlags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user