Bunch of fixes to get MP3 exports working on a basic level; lots of fixes still needed

This commit is contained in:
Aruki
2017-02-18 19:41:39 -07:00
parent 68840e69f9
commit 5485d42b56
30 changed files with 106 additions and 75 deletions

View File

@@ -41,6 +41,7 @@ void ApplyGeneratedName(CResourceEntry *pEntry, const TWideString& rkDir, const
TWideString MakeWorldName(EGame Game, TWideString RawName)
{
// The raw world names are basically formatted differently in every single game...
// MP1 demo - Remove ! from the beginning
if (Game == ePrimeDemo)
{
@@ -75,18 +76,8 @@ TWideString MakeWorldName(EGame Game, TWideString RawName)
RawName = RawName.SubString(UnderscoreA + 1, UnderscoreB - UnderscoreA - 1);
}
// MP3 proto - Remove ! from the beginning and all text after last underscore
else if (Game == eCorruptionProto)
{
if (RawName.StartsWith(L'!'))
RawName = RawName.ChopFront(1);
u32 LastUnderscore = RawName.LastIndexOf(L"_");
RawName = RawName.ChopBack(RawName.Size() - LastUnderscore);
}
// MP2/3 - Remove text before first underscore and after last underscore, strip remaining underscores (except multiplayer maps, which have one underscore)
else if (Game == eEchoes || Game == eCorruption)
// MP2 - Remove text before first underscore and after last underscore, strip remaining underscores (except multiplayer maps, which have one underscore)
else if (Game == eEchoes)
{
u32 FirstUnderscore = RawName.IndexOf(L'_');
u32 LastUnderscore = RawName.LastIndexOf(L"_");
@@ -99,6 +90,23 @@ TWideString MakeWorldName(EGame Game, TWideString RawName)
}
}
// MP3 proto - Remove ! from the beginning and all text after last underscore
else if (Game == eCorruptionProto)
{
if (RawName.StartsWith(L'!'))
RawName = RawName.ChopFront(1);
u32 LastUnderscore = RawName.LastIndexOf(L"_");
RawName = RawName.ChopBack(RawName.Size() - LastUnderscore);
}
// MP3 - Remove text after last underscore
else if (Game == eCorruption)
{
u32 LastUnderscore = RawName.LastIndexOf(L"_");
RawName = RawName.ChopBack(RawName.Size() - LastUnderscore);
}
// DKCR - Remove text after second-to-last underscore
else if (Game == eReturns)
{

View File

@@ -100,12 +100,27 @@ void CGameProject::GetWorldList(std::list<CAssetID>& rOut) const
{
CPackage *pPkg = mPackages[iPkg];
// Little workaround to fix some of Retro's paks having worlds listed in the wrong order...
// Construct a sorted list of worlds in this package
std::list<const SNamedResource*> PackageWorlds;
for (u32 iRes = 0; iRes < pPkg->NumNamedResources(); iRes++)
{
const SNamedResource& rkRes = pPkg->NamedResourceByIndex(iRes);
if (rkRes.Type == "MLVL" && !rkRes.Name.EndsWith("NODEPEND"))
rOut.push_back(rkRes.ID);
PackageWorlds.push_back(&rkRes);
}
PackageWorlds.sort([](const SNamedResource *pkLeft, const SNamedResource *pkRight) -> bool {
return pkLeft->Name.ToUpper() < pkRight->Name.ToUpper();
});
// Add sorted worlds to the output world list
for (auto Iter = PackageWorlds.begin(); Iter != PackageWorlds.end(); Iter++)
{
const SNamedResource *pkRes = *Iter;
rOut.push_back(pkRes->ID);
}
}
}

View File

@@ -29,7 +29,6 @@ CResourceEntry::CResourceEntry(CResourceStore *pStore, const CAssetID& rkID,
mpDirectory = mpStore->GetVirtualDirectory(rkDir, Transient, true);
if (mpDirectory) mpDirectory->AddChild(L"", this);
mGame = ((Transient || !mpStore) ? eUnknownGame : mpStore->Game());
}
CResourceEntry::~CResourceEntry()
@@ -74,6 +73,7 @@ void CResourceEntry::UpdateDependencies()
if (!mpResource)
{
Log::Error("Unable to update cached dependencies; failed to load resource");
mpDependencies = new CDependencyTree(ID());
return;
}
@@ -117,7 +117,7 @@ TString CResourceEntry::CookedAssetPath(bool Relative) const
CFourCC CResourceEntry::CookedExtension() const
{
return mpTypeInfo->CookedExtension(mGame);
return mpTypeInfo->CookedExtension(Game());
}
bool CResourceEntry::IsInDirectory(CVirtualDirectory *pDir) const
@@ -157,17 +157,6 @@ bool CResourceEntry::NeedsRecook() const
return (FileUtil::LastModifiedTime(CookedAssetPath()) < FileUtil::LastModifiedTime(RawAssetPath()));
}
void CResourceEntry::SetGame(EGame NewGame)
{
if (mGame != NewGame)
{
// todo: implement checks here. This needs work because we should trigger a recook and if the extension changes
// we should delete the old file. Also a lot of resources can't evaluate this correctly due to file version
// numbers being shared between games.
mGame = NewGame;
}
}
bool CResourceEntry::Save(bool SkipCacheSave /*= false*/)
{
// SkipCacheSave argument tells us not to save the resource cache file. This is generally not advised because we don't
@@ -196,7 +185,7 @@ bool CResourceEntry::Save(bool SkipCacheSave /*= false*/)
TString SerialName = mpTypeInfo->TypeName();
SerialName.RemoveWhitespace();
CXMLWriter Writer(Path, SerialName, 0, mGame);
CXMLWriter Writer(Path, SerialName, 0, Game());
mpResource->Serialize(Writer);
if (!Writer.Save())
@@ -501,5 +490,10 @@ void CResourceEntry::RemoveFromProject()
CGameProject* CResourceEntry::Project() const
{
return mpStore->Project();
return mpStore ? mpStore->Project() : nullptr;
}
EGame CResourceEntry::Game() const
{
return mpStore ? mpStore->Game() : eUnknownGame;
}

View File

@@ -33,7 +33,6 @@ class CResourceEntry
CResourceStore *mpStore;
CDependencyTree *mpDependencies;
CAssetID mID;
EGame mGame;
CVirtualDirectory *mpDirectory;
TWideString mName;
FResEntryFlags mFlags;
@@ -59,7 +58,6 @@ public:
bool IsInDirectory(CVirtualDirectory *pDir) const;
u64 Size() const;
bool NeedsRecook() const;
void SetGame(EGame NewGame);
bool Save(bool SkipCacheSave = false);
bool Cook();
CResource* Load();
@@ -70,6 +68,7 @@ public:
void AddToProject(const TWideString& rkDir, const TWideString& rkName);
void RemoveFromProject();
CGameProject* Project() const;
EGame Game() const;
// Accessors
void SetDirty() { mFlags.SetFlag(eREF_NeedsRecook); }
@@ -83,7 +82,6 @@ public:
inline CResourceStore* ResourceStore() const { return mpStore; }
inline CDependencyTree* Dependencies() const { return mpDependencies; }
inline CAssetID ID() const { return mID; }
inline EGame Game() const { return mGame; }
inline CVirtualDirectory* Directory() const { return mpDirectory; }
inline TWideString DirectoryPath() const { return mpDirectory->FullPath(); }
inline TWideString Name() const { return mName; }