mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-20 18:29:13 +00:00
MP2/MP3/DKCR tweak saving support
This commit is contained in:
@@ -12,6 +12,33 @@ bool CTweakCooker::CookCTWK(CTweakData* pTweakData, IOutputStream& CTWK)
|
||||
|
||||
bool CTweakCooker::CookNTWK(const std::vector<CTweakData*>& kTweaks, IOutputStream& NTWK)
|
||||
{
|
||||
// Unimplemented
|
||||
return false;
|
||||
NTWK.WriteFourCC( FOURCC('NTWK') ); // NTWK magic
|
||||
NTWK.WriteByte( 1 ); // Version number; must be 1
|
||||
NTWK.WriteLong( kTweaks.size() ); // Number of tweak objects
|
||||
|
||||
for (uint TweakIdx = 0; TweakIdx < kTweaks.size(); TweakIdx++)
|
||||
{
|
||||
CTweakData* pTweakData = kTweaks[TweakIdx];
|
||||
|
||||
// Tweaks in MP2+ are saved with the script object data format
|
||||
// Write a dummy script object header here
|
||||
uint TweakObjectStart = NTWK.Tell();
|
||||
NTWK.WriteLong( pTweakData->TweakID() ); // Object ID
|
||||
NTWK.WriteShort( 0 ); // Object size
|
||||
NTWK.WriteLong( TweakIdx ); // Instance ID
|
||||
NTWK.WriteShort( 0 ); // Link count
|
||||
|
||||
CStructRef TweakProperties = pTweakData->TweakData();
|
||||
CScriptCooker ScriptCooker(TweakProperties.Property()->Game());
|
||||
ScriptCooker.WriteProperty(NTWK, TweakProperties.Property(), TweakProperties.DataPointer(), false);
|
||||
|
||||
uint TweakObjectEnd = NTWK.Tell();
|
||||
uint TweakObjectSize = (uint16) (TweakObjectEnd - TweakObjectStart - 6);
|
||||
NTWK.GoTo(TweakObjectStart + 4);
|
||||
NTWK.WriteShort(TweakObjectSize);
|
||||
NTWK.GoTo(TweakObjectEnd);
|
||||
}
|
||||
|
||||
NTWK.WriteToBoundary(32, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,16 @@ class CTweakData : public CResource
|
||||
/** Script template specifying tweak data layout */
|
||||
CScriptTemplate* mpTemplate;
|
||||
|
||||
/** Tweak ID for MP2+ */
|
||||
uint mTweakID;
|
||||
|
||||
/** Tweak data */
|
||||
std::vector<uint8> mTweakData;
|
||||
|
||||
public:
|
||||
CTweakData(CScriptTemplate* pTemplate, CResourceEntry* pEntry = 0)
|
||||
CTweakData(CScriptTemplate* pTemplate, uint TweakID, CResourceEntry* pEntry = 0)
|
||||
: mpTemplate(pTemplate)
|
||||
, mTweakID(TweakID)
|
||||
, CResource(pEntry)
|
||||
{
|
||||
CStructProperty* pProperties = pTemplate->Properties();
|
||||
@@ -44,6 +48,11 @@ public:
|
||||
return mpTemplate;
|
||||
}
|
||||
|
||||
inline uint32 TweakID() const
|
||||
{
|
||||
return mTweakID;
|
||||
}
|
||||
|
||||
inline CStructRef TweakData() const
|
||||
{
|
||||
return CStructRef((void*) mTweakData.data(), mpTemplate->Properties());
|
||||
|
||||
@@ -36,7 +36,7 @@ CTweakData* CTweakLoader::LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry)
|
||||
ASSERT( pTweakTemplate != nullptr );
|
||||
|
||||
// Load tweak data
|
||||
CTweakData* pTweakData = new CTweakData(pTweakTemplate, pEntry);
|
||||
CTweakData* pTweakData = new CTweakData(pTweakTemplate, pEntry->ID().ToLong(), pEntry);
|
||||
CScriptLoader::LoadStructData( CTWK, pTweakData->TweakData() );
|
||||
|
||||
// Verify
|
||||
@@ -121,7 +121,7 @@ void CTweakLoader::LoadNTWK(IInputStream& NTWK, EGame Game, std::vector<CTweakDa
|
||||
|
||||
// Load tweak data
|
||||
NTWK.Skip(0xC);
|
||||
CTweakData* pTweakData = new CTweakData(pTweakTemplate);
|
||||
CTweakData* pTweakData = new CTweakData(pTweakTemplate, TweakID);
|
||||
CScriptLoader::LoadStructData( NTWK, pTweakData->TweakData() );
|
||||
OutTweaks.push_back(pTweakData);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Core/GameProject/CGameProject.h"
|
||||
#include "Core/GameProject/CResourceIterator.h"
|
||||
#include "Core/Tweaks/CTweakLoader.h"
|
||||
#include "Core/Tweaks/CTweakCooker.h"
|
||||
|
||||
CTweakManager::CTweakManager(CGameProject* pInProject)
|
||||
: mpProject(pInProject)
|
||||
@@ -47,9 +48,37 @@ CTweakManager::~CTweakManager()
|
||||
}
|
||||
}
|
||||
|
||||
void CTweakManager::SaveTweaks()
|
||||
bool CTweakManager::SaveTweaks()
|
||||
{
|
||||
// In MP1, to save an individual tweak asset, just call Tweak->Entry()->Save()
|
||||
// In MP2+, call this function.
|
||||
//@todo
|
||||
// MP1 - Save all tweak assets
|
||||
if (mpProject->Game() <= EGame::Prime)
|
||||
{
|
||||
bool SavedAll = true, SavedAny = false;
|
||||
|
||||
for (CTweakData* pTweakData : mTweakObjects)
|
||||
{
|
||||
if (!pTweakData->Entry()->Save(true))
|
||||
{
|
||||
SavedAll = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SavedAny = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (SavedAny)
|
||||
{
|
||||
mpProject->ResourceStore()->ConditionalSaveStore();
|
||||
}
|
||||
|
||||
return SavedAll;
|
||||
}
|
||||
// MP2+ - Save tweaks to Standard.ntwk
|
||||
else
|
||||
{
|
||||
TString FilePath = mpProject->DiscFilesystemRoot(false) + "Standard.ntwk";
|
||||
CFileOutStream StandardNTWK(FilePath, EEndian::BigEndian);
|
||||
return CTweakCooker::CookNTWK(mTweakObjects, StandardNTWK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
CTweakManager(CGameProject* pInProject);
|
||||
~CTweakManager();
|
||||
void LoadTweaks();
|
||||
void SaveTweaks();
|
||||
bool SaveTweaks();
|
||||
|
||||
// Accessors
|
||||
inline const std::vector<CTweakData*>& TweakObjects() const
|
||||
|
||||
Reference in New Issue
Block a user