Permalink
Browse files

Merge pull request #6612 from leoetlino/movie-array

Movie: Replace some C style arrays with std::array
  • Loading branch information...
leoetlino committed May 6, 2018
2 parents 34899e8 + 75d056b commit 32235f974d4c7d3664aad6bcedf46434d2b731a0
Showing with 34 additions and 37 deletions.
  1. +2 −4 Source/Core/Core/ConfigLoaders/MovieConfigLoader.cpp
  2. +19 −21 Source/Core/Core/Movie.cpp
  3. +13 −12 Source/Core/Core/Movie.h
@@ -29,8 +29,7 @@ static void LoadFromDTM(Config::Layer* config_layer, Movie::DTMHeader* dtm)
config_layer->Set(Config::MAIN_FAST_DISC_SPEED, dtm->bFastDiscSpeed);
config_layer->Set(Config::MAIN_CPU_CORE, static_cast<int>(dtm->CPUCore));
config_layer->Set(Config::MAIN_SYNC_GPU, dtm->bSyncGPU);
config_layer->Set(Config::MAIN_GFX_BACKEND,
std::string(reinterpret_cast<char*>(dtm->videoBackend)));
config_layer->Set(Config::MAIN_GFX_BACKEND, std::string(dtm->videoBackend.data()));
config_layer->Set(Config::SYSCONF_PROGRESSIVE_SCAN, dtm->bProgressive);
config_layer->Set(Config::SYSCONF_PAL60, dtm->bPAL60);
@@ -73,8 +72,7 @@ void SaveToDTM(Movie::DTMHeader* dtm)
dtm->bEFBCopyEnable = true;
dtm->bEFBCopyCacheEnable = false;
strncpy(reinterpret_cast<char*>(dtm->videoBackend), video_backend.c_str(),
ArraySize(dtm->videoBackend));
strncpy(dtm->videoBackend.data(), video_backend.c_str(), dtm->videoBackend.size());
}
// TODO: Future project, let this support all the configuration options.
@@ -84,9 +84,9 @@ static bool s_bDiscChange = false;
static bool s_bReset = false;
static std::string s_author = "";
static std::string s_discChange = "";
static u8 s_MD5[16];
static std::array<u8, 16> s_MD5;
static u8 s_bongos, s_memcards;
static u8 s_revision[20];
static std::array<u8, 20> s_revision;
static u32 s_DSPiromHash = 0;
static u32 s_DSPcoefHash = 0;
@@ -103,7 +103,7 @@ static WiiManipFunction s_wii_manip_func;
static std::string s_current_file_name;
static void GetSettings();
static bool IsMovieHeader(u8 magic[4])
static bool IsMovieHeader(const std::array<u8, 4>& magic)
{
return magic[0] == 'D' && magic[1] == 'T' && magic[2] == 'M' && magic[3] == 0x1A;
}
@@ -215,10 +215,10 @@ void Init(const BootParameters& boot)
ReadHeader();
std::thread md5thread(CheckMD5);
md5thread.detach();
if (strncmp(tmpHeader.gameID, SConfig::GetInstance().GetGameID().c_str(), 6))
if (strncmp(tmpHeader.gameID.data(), SConfig::GetInstance().GetGameID().c_str(), 6))
{
PanicAlertT("The recorded game (%s) is not the same as the selected game (%s)",
tmpHeader.gameID, SConfig::GetInstance().GetGameID().c_str());
tmpHeader.gameID.data(), SConfig::GetInstance().GetGameID().c_str());
EndPlayInput(false);
}
}
@@ -848,16 +848,16 @@ void ReadHeader()
s_memcards = tmpHeader.memcards;
s_bongos = tmpHeader.bongos;
s_bNetPlay = tmpHeader.bNetPlay;
memcpy(s_revision, tmpHeader.revision, ArraySize(s_revision));
s_revision = tmpHeader.revision;
}
else
{
GetSettings();
}
s_discChange = (char*)tmpHeader.discChange;
s_author = (char*)tmpHeader.author;
memcpy(s_MD5, tmpHeader.md5, 16);
s_discChange = {tmpHeader.discChange.begin(), tmpHeader.discChange.end()};
s_author = {tmpHeader.author.begin(), tmpHeader.author.end()};
s_MD5 = tmpHeader.md5;
s_DSPiromHash = tmpHeader.DSPiromHash;
s_DSPcoefHash = tmpHeader.DSPcoefHash;
}
@@ -1298,7 +1298,7 @@ void SaveRecording(const std::string& filename)
header.filetype[1] = 'T';
header.filetype[2] = 'M';
header.filetype[3] = 0x1A;
strncpy(header.gameID, SConfig::GetInstance().GetGameID().c_str(), 6);
strncpy(header.gameID.data(), SConfig::GetInstance().GetGameID().c_str(), 6);
header.bWii = SConfig::GetInstance().bWii;
header.controllers = s_controllers & (SConfig::GetInstance().bWii ? 0xFF : 0x0F);
@@ -1314,11 +1314,11 @@ void SaveRecording(const std::string& filename)
header.memcards = s_memcards;
header.bClearSave = s_bClearSave;
header.bNetPlay = s_bNetPlay;
strncpy((char*)header.discChange, s_discChange.c_str(), ArraySize(header.discChange));
strncpy((char*)header.author, s_author.c_str(), ArraySize(header.author));
memcpy(header.md5, s_MD5, 16);
strncpy(header.discChange.data(), s_discChange.c_str(), header.discChange.size());
strncpy(header.author.data(), s_author.c_str(), header.author.size());
header.md5 = s_MD5;
header.bongos = s_bongos;
memcpy(header.revision, s_revision, ArraySize(header.revision));
header.revision = s_revision;
header.DSPiromHash = s_DSPiromHash;
header.DSPcoefHash = s_DSPcoefHash;
header.tickCount = s_totalTickCount;
@@ -1400,8 +1400,7 @@ void GetSettings()
SConfig::GetInstance().m_EXIDevice[1] == ExpansionInterface::EXIDEVICE_MEMORYCARDFOLDER)
<< 1;
std::array<u8, 20> revision = ConvertGitRevisionToBytes(Common::scm_rev_git_str);
std::copy(std::begin(revision), std::end(revision), std::begin(s_revision));
s_revision = ConvertGitRevisionToBytes(Common::scm_rev_git_str);
if (!Config::Get(Config::MAIN_DSP_HLE))
{
@@ -1455,10 +1454,10 @@ static void CheckMD5()
}
Core::DisplayMessage("Verifying checksum...", 2000);
unsigned char gameMD5[16];
mbedtls_md_file(s_md5_info, s_current_file_name.c_str(), gameMD5);
std::array<u8, 16> game_md5;
mbedtls_md_file(s_md5_info, s_current_file_name.c_str(), game_md5.data());
if (memcmp(gameMD5, s_MD5, 16) == 0)
if (game_md5 == s_MD5)
Core::DisplayMessage("Checksum of current game matches the recorded game.", 2000);
else
Core::DisplayMessage("Checksum of current game does not match the recorded game!", 3000);
@@ -1471,8 +1470,7 @@ static void GetMD5()
return;
Core::DisplayMessage("Calculating checksum of game file...", 2000);
memset(s_MD5, 0, sizeof(s_MD5));
mbedtls_md_file(s_md5_info, s_current_file_name.c_str(), s_MD5);
mbedtls_md_file(s_md5_info, s_current_file_name.c_str(), s_MD5.data());
Core::DisplayMessage("Finished calculating checksum.", 2000);
}
@@ -4,6 +4,7 @@
#pragma once
#include <array>
#include <functional>
#include <optional>
#include <string>
@@ -58,10 +59,10 @@ static_assert(sizeof(ControllerState) == 8, "ControllerState should be 8 bytes")
#pragma pack(push, 1)
struct DTMHeader
{
u8 filetype[4]; // Unique Identifier (always "DTM"0x1A)
std::array<u8, 4> filetype; // Unique Identifier (always "DTM"0x1A)
char gameID[6]; // The Game ID
bool bWii; // Wii game
std::array<char, 6> gameID; // The Game ID
bool bWii; // Wii game
u8 controllers; // Controllers plugged in (from least to most significant,
// the bits are GC controllers 1-4 and Wiimotes 1-4)
@@ -73,11 +74,11 @@ struct DTMHeader
u64 lagCount; // Number of lag frames in the recording
u64 uniqueID; // (not implemented) A Unique ID comprised of: md5(time + Game ID)
u32 numRerecords; // Number of rerecords/'cuts' of this TAS
u8 author[32]; // Author's name (encoded in UTF-8)
std::array<char, 32> author; // Author's name (encoded in UTF-8)
u8 videoBackend[16]; // UTF-8 representation of the video backend
u8 audioEmulator[16]; // UTF-8 representation of the audio emulator
u8 md5[16]; // MD5 of game iso
std::array<char, 16> videoBackend; // UTF-8 representation of the video backend
std::array<char, 16> audioEmulator; // UTF-8 representation of the audio emulator
std::array<u8, 16> md5; // MD5 of game iso
u64 recordingStartTime; // seconds since 1970 that recording started (used for RTC)
@@ -102,13 +103,13 @@ struct DTMHeader
bool bNetPlay;
bool bPAL60;
u8 language;
u8 reserved[11]; // Padding for any new config options
u8 discChange[40]; // Name of iso file to switch to, for two disc games.
u8 revision[20]; // Git hash
std::array<u8, 11> reserved; // Padding for any new config options
std::array<char, 40> discChange; // Name of iso file to switch to, for two disc games.
std::array<u8, 20> revision; // Git hash
u32 DSPiromHash;
u32 DSPcoefHash;
u64 tickCount; // Number of ticks in the recording
u8 reserved2[11]; // Make heading 256 bytes, just because we can
u64 tickCount; // Number of ticks in the recording
std::array<u8, 11> reserved2; // Make heading 256 bytes, just because we can
};
static_assert(sizeof(DTMHeader) == 256, "DTMHeader should be 256 bytes");

0 comments on commit 32235f9

Please sign in to comment.