mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-20 18:29:13 +00:00
Support for loading MP2/MP3/DKCR tweaks
This commit is contained in:
@@ -26,6 +26,19 @@ public:
|
||||
pProperties->Construct(mTweakData.data());
|
||||
}
|
||||
|
||||
TString TweakName()
|
||||
{
|
||||
if (Entry() != nullptr)
|
||||
{
|
||||
return Entry()->Name();
|
||||
}
|
||||
else
|
||||
{
|
||||
IProperty* pNameProperty = mpTemplate->Properties()->ChildByID(0x7FDA1466);
|
||||
return CStringRef(mTweakData.data(), pNameProperty);
|
||||
}
|
||||
}
|
||||
|
||||
inline CScriptTemplate* TweakTemplate() const
|
||||
{
|
||||
return mpTemplate;
|
||||
|
||||
@@ -50,7 +50,81 @@ CTweakData* CTweakLoader::LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry)
|
||||
return pTweakData;
|
||||
}
|
||||
|
||||
void CTweakLoader::LoadNTWK(IInputStream& NTWK, std::vector<CTweakData*>& OutTweaks)
|
||||
void CTweakLoader::LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakData*>& OutTweaks)
|
||||
{
|
||||
// Unimplemented
|
||||
// Validate file. NTWK basically embeds a bunch of tweak objects using the script layers
|
||||
// format, so it has the same version byte that script layers have.
|
||||
uint Magic = NTWK.ReadLong();
|
||||
uint8 LayerVersion = NTWK.ReadByte();
|
||||
|
||||
if (Magic != FOURCC('NTWK'))
|
||||
{
|
||||
errorf("Unrecognized NTWK magic: 0x%08X", Magic);
|
||||
return;
|
||||
}
|
||||
else if (LayerVersion != 1)
|
||||
{
|
||||
errorf("Unrecognized layer version in NTWK: %d", LayerVersion);
|
||||
return;
|
||||
}
|
||||
|
||||
CGameTemplate* pGameTemplate = NGameList::GetGameTemplate( Game );
|
||||
ASSERT( pGameTemplate != nullptr );
|
||||
|
||||
// Start reading tweaks
|
||||
uint NumTweaks = NTWK.ReadLong();
|
||||
|
||||
for (uint TweakIdx = 0; TweakIdx < NumTweaks; TweakIdx++)
|
||||
{
|
||||
// Find the correct template based on the tweak ID.
|
||||
static const std::unordered_map<uint, const char*> skIdToTemplateName =
|
||||
{
|
||||
{ FOURCC('TWAC'), "TweakAdvancedControls" },
|
||||
{ FOURCC('TWAM'), "TweakAutoMapper" },
|
||||
{ FOURCC('TWBL'), "TweakBall" },
|
||||
{ FOURCC('TWC2'), "TweakPlayerControls" },
|
||||
{ FOURCC('TWCB'), "TweakCameraBob" },
|
||||
{ FOURCC('TWCC'), "TweakGamecubeControls" },
|
||||
{ FOURCC('TWCT'), "TweakControls" },
|
||||
{ FOURCC('TWEC'), "TweakExpertControls" },
|
||||
{ FOURCC('TWGM'), "TweakGame" },
|
||||
{ FOURCC('TWGT'), "TweakGraphicalTransitions" },
|
||||
{ FOURCC('TWGU'), "TweakGui" },
|
||||
{ FOURCC('TWGC'), "TweakGuiColors" },
|
||||
{ FOURCC('TWP2'), "TweakPlayer" },
|
||||
{ FOURCC('TWPC'), "TweakPlayerControls" },
|
||||
{ FOURCC('TWPG'), "TweakPlayerGun" },
|
||||
{ FOURCC('TWPL'), "TweakPlayer" },
|
||||
{ FOURCC('TWPM'), "TweakPlayerGun" },
|
||||
{ FOURCC('TWPA'), "TweakParticle" },
|
||||
{ FOURCC('TWPR'), "TweakPlayerRes" },
|
||||
{ FOURCC('TWRC'), "TweakRevolutionControls" },
|
||||
{ FOURCC('TWSS'), "TweakSlideShow" },
|
||||
{ FOURCC('TWTG'), "TweakTargeting" },
|
||||
};
|
||||
|
||||
uint TweakID = NTWK.ReadLong();
|
||||
uint16 TweakSize = NTWK.ReadShort();
|
||||
uint NextTweak = NTWK.Tell() + TweakSize;
|
||||
|
||||
auto Find = skIdToTemplateName.find(TweakID);
|
||||
|
||||
if (Find == skIdToTemplateName.end())
|
||||
{
|
||||
errorf("Unrecognized tweak ID: %s (0x%08X)", *CFourCC(TweakID).ToString(), TweakID);
|
||||
NTWK.GoTo(NextTweak);
|
||||
continue;
|
||||
}
|
||||
|
||||
CScriptTemplate* pTweakTemplate = pGameTemplate->FindMiscTemplate( Find->second );
|
||||
ASSERT( pTweakTemplate != nullptr );
|
||||
|
||||
// Load tweak data
|
||||
NTWK.Skip(0xC);
|
||||
CTweakData* pTweakData = new CTweakData(pTweakTemplate);
|
||||
CScriptLoader::LoadStructData( NTWK, pTweakData->TweakData() );
|
||||
OutTweaks.push_back(pTweakData);
|
||||
|
||||
NTWK.GoTo(NextTweak);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class CTweakLoader
|
||||
public:
|
||||
/** Loader entry point */
|
||||
static CTweakData* LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry);
|
||||
static void LoadNTWK(IInputStream& NTWK, std::vector<CTweakData*>& OutTweaks);
|
||||
static void LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakData*>& OutTweaks);
|
||||
};
|
||||
|
||||
#endif // CTWEAKLOADER_H
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "CTweakManager.h"
|
||||
#include "Core/GameProject/CGameProject.h"
|
||||
#include "Core/GameProject/CResourceIterator.h"
|
||||
#include "Core/Tweaks/CTweakLoader.h"
|
||||
|
||||
CTweakManager::CTweakManager(CGameProject* pInProject)
|
||||
: mpProject(pInProject)
|
||||
@@ -9,19 +10,40 @@ CTweakManager::CTweakManager(CGameProject* pInProject)
|
||||
|
||||
void CTweakManager::LoadTweaks()
|
||||
{
|
||||
ASSERT( mTweakObjects.empty() );
|
||||
|
||||
// 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();
|
||||
pTweaks->Lock();
|
||||
mTweakObjects.push_back(pTweaks);
|
||||
}
|
||||
}
|
||||
|
||||
// MP2+ - Not supported, but tweaks are stored in Standard.ntwk
|
||||
// MP2+ - Load tweaks from Standard.ntwk
|
||||
else
|
||||
{
|
||||
TString FilePath = mpProject->DiscFilesystemRoot(false) + "Standard.ntwk";
|
||||
CFileInStream StandardNTWK(FilePath, EEndian::BigEndian);
|
||||
CTweakLoader::LoadNTWK(StandardNTWK, mpProject->Game(), mTweakObjects);
|
||||
}
|
||||
}
|
||||
|
||||
CTweakManager::~CTweakManager()
|
||||
{
|
||||
for (CTweakData* pTweakData : mTweakObjects)
|
||||
{
|
||||
if (pTweakData->Entry() != nullptr)
|
||||
{
|
||||
pTweakData->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pTweakData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,16 @@ class CTweakManager
|
||||
CGameProject* mpProject;
|
||||
|
||||
/** All tweak resources in the current game */
|
||||
std::vector< TResPtr<CTweakData> > mTweakObjects;
|
||||
std::vector< CTweakData* > mTweakObjects;
|
||||
|
||||
public:
|
||||
CTweakManager(CGameProject* pInProject);
|
||||
~CTweakManager();
|
||||
void LoadTweaks();
|
||||
void SaveTweaks();
|
||||
|
||||
// Accessors
|
||||
inline const std::vector< TResPtr<CTweakData> >& TweakObjects() const
|
||||
inline const std::vector<CTweakData*>& TweakObjects() const
|
||||
{
|
||||
return mTweakObjects;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user