Tweak loader for MP1

This commit is contained in:
Aruki
2018-12-27 20:16:39 -07:00
parent d6340dced9
commit 7588200c26
37 changed files with 3780 additions and 65 deletions

View File

@@ -0,0 +1,40 @@
#ifndef CTWEAKDATA_H
#define CTWEAKDATA_H
#include "Core/Resource/CResource.h"
#include "Core/Resource/Script/CScriptTemplate.h"
#include "Core/Resource/Script/Property/TPropertyRef.h"
/** Tweak data assets for MP1 */
class CTweakData : public CResource
{
DECLARE_RESOURCE_TYPE(Tweaks)
/** Script template specifying tweak data layout */
CScriptTemplate* mpTemplate;
/** Tweak data */
std::vector<uint8> mTweakData;
public:
CTweakData(CScriptTemplate* pTemplate, CResourceEntry* pEntry = 0)
: mpTemplate(pTemplate)
, CResource(pEntry)
{
CStructProperty* pProperties = pTemplate->Properties();
mTweakData.resize(pProperties->DataSize());
pProperties->Construct(mTweakData.data());
}
inline CScriptTemplate* TweakTemplate() const
{
return mpTemplate;
}
inline CStructRef TweakData() const
{
return CStructRef((void*) mTweakData.data(), mpTemplate->Properties());
}
};
#endif // CTWEAKDATA_H

View File

@@ -0,0 +1,54 @@
#include "CTweakLoader.h"
#include "Core/Resource/Factory/CScriptLoader.h"
#include "Core/Resource/Script/NGameList.h"
CTweakData* CTweakLoader::LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry)
{
// Find the correct template based on the asset ID.
static const std::unordered_map<uint, const char*> skIdToTemplateName =
{
{ 0x1D180D7C, "TweakParticle" },
{ 0x264A4972, "TweakPlayer" },
{ 0x33B3323A, "TweakGunRes" },
{ 0x39AD28D3, "TweakCameraBob" },
{ 0x3FAEC012, "TweakPlayerControls", },
{ 0x5ED56350, "TweakBall", },
{ 0x5F24EFF8, "TweakSlideShow", },
{ 0x6907A32D, "TweakPlayerGun", },
{ 0x85CA11E9, "TweakPlayerRes", },
{ 0x94C76ECD, "TweakTargeting", },
{ 0x953A7C63, "TweakGame", },
{ 0xC9954E56, "TweakGuiColors", },
{ 0xE66A4F86, "TweakAutoMapper", },
{ 0xED2E48A9, "TweakGui", },
{ 0xF1ED8FD7, "TweakPlayerControls", }
};
auto Find = skIdToTemplateName.find( pEntry->ID().ToLong() );
ASSERT( Find != skIdToTemplateName.end() );
const char* pkTemplateName = Find->second;
// Fetch template
CGameTemplate* pGameTemplate = NGameList::GetGameTemplate( pEntry->Game() );
ASSERT( pGameTemplate != nullptr );
CScriptTemplate* pTweakTemplate = pGameTemplate->FindMiscTemplate(pkTemplateName);
ASSERT( pTweakTemplate != nullptr );
// Load tweak data
CTweakData* pTweakData = new CTweakData(pTweakTemplate, pEntry);
CScriptLoader::LoadStructData( CTWK, pTweakData->TweakData() );
// Verify
if (!CTWK.EoF() && CTWK.PeekShort() != -1)
{
errorf("%s: unread property data, tweak template may be malformed (%d bytes left)", *CTWK.GetSourceString(), CTWK.Size() - CTWK.Tell());
}
return pTweakData;
}
void CTweakLoader::LoadNTWK(IInputStream& NTWK, std::vector<CTweakData*>& OutTweaks)
{
// Unimplemented
}

View File

@@ -0,0 +1,18 @@
#ifndef CTWEAKLOADER_H
#define CTWEAKLOADER_H
#include "CTweakData.h"
/** Class responsible for loading tweak data */
class CTweakLoader
{
/** Private constructor */
CTweakLoader() {}
public:
/** Loader entry point */
static CTweakData* LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry);
static void LoadNTWK(IInputStream& NTWK, std::vector<CTweakData*>& OutTweaks);
};
#endif // CTWEAKLOADER_H

View File

@@ -0,0 +1,33 @@
#include "CTweakManager.h"
#include "Core/GameProject/CGameProject.h"
#include "Core/GameProject/CResourceIterator.h"
CTweakManager::CTweakManager(CGameProject* pInProject)
: mpProject(pInProject)
{
}
void CTweakManager::LoadTweaks()
{
// MP1 - Load all tweak assets into memory
if (mpProject->Game() <= EGame::Prime)
{
for (TResourceIterator<EResourceType::Tweaks> It(mpProject->ResourceStore()); It; ++It)
{
CTweakData* pTweaks = (CTweakData*) It->Load();
mTweakObjects.push_back(pTweaks);
}
}
// MP2+ - Not supported, but tweaks are stored in Standard.ntwk
else
{
}
}
void CTweakManager::SaveTweaks()
{
// In MP1, to save an individual tweak asset, just call Tweak->Entry()->Save()
// In MP2+, call this function.
//@todo
}

View File

@@ -0,0 +1,27 @@
#ifndef CTWEAKMANAGER_H
#define CTWEAKMANAGER_H
#include "CTweakData.h"
/** Class responsible for managing game tweak data, including saving/loading and providing access */
class CTweakManager
{
/** Project */
CGameProject* mpProject;
/** All tweak resources in the current game */
std::vector< TResPtr<CTweakData> > mTweakObjects;
public:
CTweakManager(CGameProject* pInProject);
void LoadTweaks();
void SaveTweaks();
// Accessors
inline const std::vector< TResPtr<CTweakData> >& TweakObjects() const
{
return mTweakObjects;
}
};
#endif // CTWEAKMANAGER_H