mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-11 12:05:51 +00:00
NANDContentLoader/WiiWAD: Get rid of raw delete and new
This commit is contained in:
parent
e638775bc7
commit
c78c54c546
8 changed files with 234 additions and 254 deletions
|
@ -10,11 +10,10 @@
|
|||
|
||||
#include "Core/Boot/Boot_DOL.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/PowerPC/PowerPC.h"
|
||||
|
||||
CDolLoader::CDolLoader(u8* buffer, size_t size)
|
||||
CDolLoader::CDolLoader(const std::vector<u8>& buffer)
|
||||
{
|
||||
m_is_valid = Initialize(buffer, size);
|
||||
m_is_valid = Initialize(buffer);
|
||||
}
|
||||
|
||||
CDolLoader::CDolLoader(const std::string& filename)
|
||||
|
@ -27,19 +26,19 @@ CDolLoader::CDolLoader(const std::string& filename)
|
|||
pStream.ReadBytes(temp_buffer.data(), temp_buffer.size());
|
||||
}
|
||||
|
||||
m_is_valid = Initialize(temp_buffer.data(), temp_buffer.size());
|
||||
m_is_valid = Initialize(temp_buffer);
|
||||
}
|
||||
|
||||
CDolLoader::~CDolLoader()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDolLoader::Initialize(u8* buffer, size_t size)
|
||||
bool CDolLoader::Initialize(const std::vector<u8>& buffer)
|
||||
{
|
||||
if (size < sizeof(SDolHeader))
|
||||
if (buffer.size() < sizeof(SDolHeader))
|
||||
return false;
|
||||
|
||||
memcpy(&m_dolheader, buffer, sizeof(SDolHeader));
|
||||
memcpy(&m_dolheader, buffer.data(), sizeof(SDolHeader));
|
||||
|
||||
// swap memory
|
||||
u32* p = (u32*)&m_dolheader;
|
||||
|
@ -56,11 +55,11 @@ bool CDolLoader::Initialize(u8* buffer, size_t size)
|
|||
{
|
||||
if (m_dolheader.textSize[i] != 0)
|
||||
{
|
||||
if (size < m_dolheader.textOffset[i] + m_dolheader.textSize[i])
|
||||
if (buffer.size() < m_dolheader.textOffset[i] + m_dolheader.textSize[i])
|
||||
return false;
|
||||
|
||||
u8* text_start = buffer + m_dolheader.textOffset[i];
|
||||
m_text_sections.emplace_back(text_start, text_start + m_dolheader.textSize[i]);
|
||||
const u8* text_start = &buffer[m_dolheader.textOffset[i]];
|
||||
m_text_sections.emplace_back(text_start, &text_start[m_dolheader.textSize[i]]);
|
||||
|
||||
for (unsigned int j = 0; !m_is_wii && j < (m_dolheader.textSize[i] / sizeof(u32)); ++j)
|
||||
{
|
||||
|
@ -81,11 +80,11 @@ bool CDolLoader::Initialize(u8* buffer, size_t size)
|
|||
{
|
||||
if (m_dolheader.dataSize[i] != 0)
|
||||
{
|
||||
if (size < m_dolheader.dataOffset[i] + m_dolheader.dataSize[i])
|
||||
if (buffer.size() < m_dolheader.dataOffset[i] + m_dolheader.dataSize[i])
|
||||
return false;
|
||||
|
||||
u8* data_start = buffer + m_dolheader.dataOffset[i];
|
||||
m_data_sections.emplace_back(data_start, data_start + m_dolheader.dataSize[i]);
|
||||
const u8* data_start = &buffer[m_dolheader.dataOffset[i]];
|
||||
m_data_sections.emplace_back(data_start, &data_start[m_dolheader.dataSize[i]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ class CDolLoader
|
|||
{
|
||||
public:
|
||||
CDolLoader(const std::string& filename);
|
||||
CDolLoader(u8* buffer, size_t size);
|
||||
CDolLoader(const std::vector<u8>& buffer);
|
||||
~CDolLoader();
|
||||
|
||||
bool IsValid() const { return m_is_valid; }
|
||||
|
@ -54,5 +54,5 @@ private:
|
|||
bool m_is_wii;
|
||||
|
||||
// Copy sections to internal buffers
|
||||
bool Initialize(u8* buffer, size_t size);
|
||||
bool Initialize(const std::vector<u8>& buffer);
|
||||
};
|
||||
|
|
|
@ -97,13 +97,13 @@ bool CBoot::Boot_WiiWAD(const std::string& _pFilename)
|
|||
WII_IPC_HLE_Interface::SetDefaultContentFile(_pFilename);
|
||||
|
||||
std::unique_ptr<CDolLoader> pDolLoader;
|
||||
if (pContent->m_pData)
|
||||
if (pContent->m_data.empty())
|
||||
{
|
||||
pDolLoader = std::make_unique<CDolLoader>(pContent->m_pData, pContent->m_Size);
|
||||
pDolLoader = std::make_unique<CDolLoader>(pContent->m_Filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
pDolLoader = std::make_unique<CDolLoader>(pContent->m_Filename);
|
||||
pDolLoader = std::make_unique<CDolLoader>(pContent->m_data);
|
||||
}
|
||||
if (!pDolLoader->IsValid())
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue