1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 19:32:49 +01:00
openrw/rwengine/include/script/SCMFile.hpp

78 lines
1.6 KiB
C++
Raw Normal View History

2014-07-21 01:34:28 +02:00
#pragma once
#ifndef _SCMFILE_HPP_
#define _SCMFILE_HPP_
#include <vector>
#include <string>
#include <script/ScriptTypes.hpp>
2014-07-21 01:34:28 +02:00
/**
* @brief Handles in-memory SCM file data including section offsets.
*/
class SCMFile {
public:
typedef std::uint32_t uint32;
typedef std::uint16_t u16;
typedef std::uint8_t u8;
enum SCMTarget {
NoTarget = 0,
GTAIII = 0xC6,
GTAVC = 0x6D,
GTASA = 0x73
};
SCMFile()
: _data(nullptr), _target(NoTarget),
2014-07-21 01:34:28 +02:00
mainSize(0), missionLargestSize(0)
{}
~SCMFile()
{
delete[] _data;
}
void loadFile(char* data, unsigned int size);
SCMByte* data() const { return _data; }
template<class T> T read(unsigned int offset) const
{
return *(T*)(_data+offset);
}
uint32 getMainSize() const { return mainSize; }
uint32 getLargestMissionSize() const { return missionLargestSize; }
const std::vector<std::string>& getModels() const { return models; }
const std::vector<unsigned int>& getMissionOffsets() const { return missionOffsets; }
std::uint32_t getGlobalSection() const { return globalSectionOffset; }
std::uint32_t getModelSection() const { return modelSectionOffset; }
std::uint32_t getMissionSection() const { return missionSectionOffset; }
std::uint32_t getCodeSection() const { return codeSectionOffset; }
2014-07-25 04:30:44 +02:00
unsigned int getGlobalsSize() const { return modelSectionOffset - globalSectionOffset; }
2014-07-21 01:34:28 +02:00
private:
SCMByte* _data;
SCMTarget _target;
std::vector<std::string> models;
std::vector<unsigned int> missionOffsets;
uint32 mainSize;
uint32 missionLargestSize;
uint32 globalSectionOffset;
uint32 modelSectionOffset;
uint32 missionSectionOffset;
uint32 codeSectionOffset;
};
#endif