TRP Loader and undo few cellGame changes

This commit is contained in:
Alexandro Sánchez Bach 2014-02-15 01:06:12 +01:00
parent f2a3db0bd8
commit deaedcb6fa
6 changed files with 103 additions and 3 deletions

57
rpcs3/Loader/TRP.cpp Normal file
View file

@ -0,0 +1,57 @@
#include "stdafx.h"
#include "TRP.h"
TRPLoader::TRPLoader(vfsStream& f) : trp_f(f)
{
}
bool TRPLoader::Install(std::string dest, bool show)
{
if(!trp_f.IsOpened()) return false;
if(!LoadHeader(show)) return false;
for (const TRPEntry& entry : m_entries)
{
char* buffer = new char [entry.size];
vfsFile file(dest+entry.name, vfsWrite);
trp_f.Seek(entry.offset);
trp_f.Read(buffer, entry.size);
file.Write(buffer, entry.size);
file.Close();
delete[] buffer;
}
return true;
}
bool TRPLoader::Close()
{
return trp_f.Close();
}
bool TRPLoader::LoadHeader(bool show)
{
trp_f.Seek(0);
if (trp_f.Read(&m_header, sizeof(TRPHeader)) != sizeof(TRPHeader))
return false;
if (!m_header.CheckMagic())
return false;
if (show)
ConLog.Write("TRP version: %x", m_header.trp_version);
m_entries.clear();
m_entries.resize(m_header.trp_files_count);
for(u32 i=0; i<m_header.trp_files_count; i++)
{
if (trp_f.Read(&m_entries[i], sizeof(TRPEntry)) != sizeof(TRPEntry))
return false;
if (show)
ConLog.Write("TRP entry #%d: %s", wxString(m_entries[i].name).wx_str());
}
return true;
}

40
rpcs3/Loader/TRP.h Normal file
View file

@ -0,0 +1,40 @@
#pragma once
#include "Loader.h"
struct TRPHeader
{
u32 trp_magic;
u32 trp_version;
u64 trp_file_size;
u32 trp_files_count;
u32 trp_element_size;
u32 trp_unknown;
unsigned char sha1[20];
unsigned char padding[16];
bool CheckMagic() const {
return trp_magic == 0xDCA23D00;
}
};
struct TRPEntry
{
char name[20];
u64 offset;
u64 size;
u32 unknown;
char padding[12];
};
class TRPLoader
{
vfsStream& trp_f;
TRPHeader m_header;
std::vector<TRPEntry> m_entries;
public:
TRPLoader(vfsStream& f);
virtual bool Install(std::string dest, bool show = false);
virtual bool LoadHeader(bool show = false);
virtual bool Close();
};