Fixed all DKCR name generation issues

This commit is contained in:
Aruki 2017-07-05 01:10:57 -06:00
parent 6a01bf5982
commit 8b84b638ac
11 changed files with 69 additions and 15 deletions

View File

@ -9,6 +9,7 @@ using namespace boost::filesystem;
// Macro encapsulating a TString -> boost::filesystem::path conversion // Macro encapsulating a TString -> boost::filesystem::path conversion
// boost does not handle conversion from UTF-8 correctly so we need to do it manually // boost does not handle conversion from UTF-8 correctly so we need to do it manually
#define TO_PATH(String) path( *String.ToUTF16() ) #define TO_PATH(String) path( *String.ToUTF16() )
#define FROM_PATH(Path) TWideString( Path.native() ).ToUTF8()
namespace FileUtil namespace FileUtil
{ {
@ -203,7 +204,7 @@ u64 LastModifiedTime(const TString& rkFilePath)
TString WorkingDirectory() TString WorkingDirectory()
{ {
return boost::filesystem::current_path().string(); return FROM_PATH( boost::filesystem::current_path() );
} }
TString MakeAbsolute(TString Path) TString MakeAbsolute(TString Path)
@ -305,11 +306,11 @@ TString SanitizeName(TString Name, bool Directory, bool RootDir /*= false*/)
return Name; return Name;
// Remove illegal characters from path // Remove illegal characters from path
u32 NumIllegalChars = sizeof(gskIllegalNameChars) / sizeof(wchar_t); u32 NumIllegalChars = sizeof(gskIllegalNameChars) / sizeof(char);
for (u32 iChr = 0; iChr < Name.Size(); iChr++) for (u32 iChr = 0; iChr < Name.Size(); iChr++)
{ {
wchar_t Chr = Name[iChr]; char Chr = Name[iChr];
bool Remove = false; bool Remove = false;
if (Chr >= 0 && Chr <= 31) if (Chr >= 0 && Chr <= 31)
@ -345,7 +346,7 @@ TString SanitizeName(TString Name, bool Directory, bool RootDir /*= false*/)
for (int iChr = (int) Name.Size() - 1; iChr >= 0; iChr--) for (int iChr = (int) Name.Size() - 1; iChr >= 0; iChr--)
{ {
wchar_t Chr = Name[iChr]; char Chr = Name[iChr];
if (Chr == ' ' || Chr == '.') if (Chr == ' ' || Chr == '.')
ChopNum++; ChopNum++;
@ -405,7 +406,7 @@ bool IsValidName(const TString& rkName, bool Directory, bool RootDir /*= false*/
if (rkName.Size() > 255) if (rkName.Size() > 255)
return false; return false;
u32 NumIllegalChars = sizeof(gskIllegalNameChars) / sizeof(wchar_t); u32 NumIllegalChars = sizeof(gskIllegalNameChars) / sizeof(char);
if (Directory && (rkName == "." || rkName == "..")) if (Directory && (rkName == "." || rkName == ".."))
return true; return true;
@ -413,7 +414,7 @@ bool IsValidName(const TString& rkName, bool Directory, bool RootDir /*= false*/
// Check for banned characters // Check for banned characters
for (u32 iChr = 0; iChr < rkName.Size(); iChr++) for (u32 iChr = 0; iChr < rkName.Size(); iChr++)
{ {
wchar_t Chr = rkName[iChr]; char Chr = rkName[iChr];
if (Chr >= 0 && Chr <= 31) if (Chr >= 0 && Chr <= 31)
return false; return false;
@ -476,7 +477,7 @@ void GetDirectoryContents(TString DirPath, TStringList& rOut, bool Recursive /*=
{ {
for (recursive_directory_iterator It( TO_PATH(DirPath) ); It != recursive_directory_iterator(); ++It) for (recursive_directory_iterator It( TO_PATH(DirPath) ); It != recursive_directory_iterator(); ++It)
{ {
AddFileLambda( It->path().string() ); AddFileLambda( FROM_PATH(It->path()) );
} }
} }
@ -484,7 +485,7 @@ void GetDirectoryContents(TString DirPath, TStringList& rOut, bool Recursive /*=
{ {
for (directory_iterator It( TO_PATH(DirPath) ); It != directory_iterator(); ++It) for (directory_iterator It( TO_PATH(DirPath) ); It != directory_iterator(); ++It)
{ {
AddFileLambda( It->path().string() ); AddFileLambda( FROM_PATH(It->path()) );
} }
} }
} }
@ -494,7 +495,7 @@ TString FindFileExtension(const TString& rkDir, const TString& rkName)
{ {
for (directory_iterator It( TO_PATH(rkDir) ); It != directory_iterator(); ++It) for (directory_iterator It( TO_PATH(rkDir) ); It != directory_iterator(); ++It)
{ {
TString Name = It->path().filename().string(); TString Name = FROM_PATH( It->path().filename() );
if (Name.GetFileName(false) == rkName) return Name.GetFileExtension(); if (Name.GetFileName(false) == rkName) return Name.GetFileExtension();
} }

View File

@ -22,6 +22,8 @@ u64 TString::Hash64() const
TWideString TString::ToUTF16() const TWideString TString::ToUTF16() const
{ {
TWideString Out; TWideString Out;
Out.Reserve(Size());
const char *pkCStr = CString(); const char *pkCStr = CString();
while (pkCStr[0]) while (pkCStr[0])
@ -86,12 +88,20 @@ TWideString TString::ToUTF16() const
pkCStr += 6; pkCStr += 6;
} }
// Invalid?
else
{
CodePoint = pkCStr[0];
pkCStr++;
}
// Step 2: Append to output string // Step 2: Append to output string
if ( ((CodePoint >= 0) && (CodePoint <= 0xD7FF)) || if ( ((CodePoint >= 0) && (CodePoint <= 0xD7FF)) ||
((CodePoint >= 0xE000) && (CodePoint <= 0xFFFF)) ) ((CodePoint >= 0xE000) && (CodePoint <= 0xFFFF)) )
Out.Append((wchar_t) (CodePoint & 0xFFFF)); Out.Append((wchar_t) (CodePoint & 0xFFFF));
} }
Out.Shrink();
return Out; return Out;
} }

View File

@ -214,6 +214,16 @@ public:
return mInternalString.substr(StartPos, Length); return mInternalString.substr(StartPos, Length);
} }
inline void Reserve(u32 Amount)
{
mInternalString.reserve(Amount);
}
inline void Shrink()
{
mInternalString.shrink_to_fit();
}
inline void Insert(u32 Pos, CharType Chr) inline void Insert(u32 Pos, CharType Chr)
{ {
#ifdef _DEBUG #ifdef _DEBUG

View File

@ -97,7 +97,7 @@ void GenerateAssetNames(CGameProject *pProj)
TString NewDir = (HasCustomDir ? It->DirectoryPath() : "Uncategorized/"); TString NewDir = (HasCustomDir ? It->DirectoryPath() : "Uncategorized/");
TString NewName = (HasCustomName ? It->Name() : It->ID().ToString()); TString NewName = (HasCustomName ? It->Name() : It->ID().ToString());
It->Move(NewDir, NewName); It->Move(NewDir, NewName, true, true);
} }
#endif #endif
@ -131,7 +131,7 @@ void GenerateAssetNames(CGameProject *pProj)
for (TResourceIterator<eWorld> It(pStore); It; ++It) for (TResourceIterator<eWorld> It(pStore); It; ++It)
{ {
// Set world name // Set world name
CWorld *pWorld = (CWorld*) It->Load(); TResPtr<CWorld> pWorld = It->Load();
TString WorldName = pWorld->Name(); TString WorldName = pWorld->Name();
TString WorldDir = kWorldsRoot + WorldName + '/'; TString WorldDir = kWorldsRoot + WorldName + '/';
@ -205,7 +205,7 @@ void GenerateAssetNames(CGameProject *pProj)
// Rename area stuff // Rename area stuff
CResourceEntry *pAreaEntry = pStore->FindEntry(AreaID); CResourceEntry *pAreaEntry = pStore->FindEntry(AreaID);
ASSERT(pAreaEntry != nullptr); if (!pAreaEntry) continue; // Some DKCR worlds reference areas that don't exist
ApplyGeneratedName(pAreaEntry, WorldMasterDir, AreaName); ApplyGeneratedName(pAreaEntry, WorldMasterDir, AreaName);
CStringTable *pAreaNameTable = pWorld->AreaName(iArea); CStringTable *pAreaNameTable = pWorld->AreaName(iArea);

View File

@ -204,7 +204,7 @@ bool CVirtualDirectory::RemoveChildDirectory(CVirtualDirectory *pSubdir)
// If this is part of the resource store, delete the corresponding filesystem directory // If this is part of the resource store, delete the corresponding filesystem directory
if (mpStore && pSubdir->GetRoot() == mpStore->RootDirectory()) if (mpStore && pSubdir->GetRoot() == mpStore->RootDirectory())
{ {
TString AbsPath = mpStore->DatabaseRootPath() + pSubdir->FullPath(); TString AbsPath = mpStore->ResourcesDir() + pSubdir->FullPath();
FileUtil::DeleteDirectory(AbsPath, true); FileUtil::DeleteDirectory(AbsPath, true);
} }
@ -237,7 +237,10 @@ void CVirtualDirectory::RemoveEmptySubdirectories()
CVirtualDirectory *pDir = mSubdirectories[SubdirIdx]; CVirtualDirectory *pDir = mSubdirectories[SubdirIdx];
if (pDir->IsEmpty()) if (pDir->IsEmpty())
{
RemoveChildDirectory(pDir); RemoveChildDirectory(pDir);
SubdirIdx--;
}
else else
pDir->RemoveEmptySubdirectories(); pDir->RemoveEmptySubdirectories();
} }

View File

@ -29,6 +29,13 @@ IMetaAnimation* CMetaAnimFactory::LoadFromStream(IInputStream& rInput, EGame Gam
} }
// ************ CMetaAnimationPlay ************ // ************ CMetaAnimationPlay ************
CMetaAnimPlay::CMetaAnimPlay(const CAnimPrimitive& rkPrimitive, float UnkA, u32 UnkB)
: mPrimitive(rkPrimitive)
, mUnknownA(UnkA)
, mUnknownB(UnkB)
{
}
CMetaAnimPlay::CMetaAnimPlay(IInputStream& rInput, EGame Game) CMetaAnimPlay::CMetaAnimPlay(IInputStream& rInput, EGame Game)
{ {
mPrimitive = CAnimPrimitive(rInput, Game); mPrimitive = CAnimPrimitive(rInput, Game);

View File

@ -32,6 +32,12 @@ class CAnimPrimitive
public: public:
CAnimPrimitive() : mID(0) {} CAnimPrimitive() : mID(0) {}
CAnimPrimitive(const CAssetID& rkAnimAssetID, u32 CharAnimID, const TString& rkAnimName)
: mID(CharAnimID), mName(rkAnimName)
{
mpAnim = gpResourceStore->LoadResource(rkAnimAssetID);
}
CAnimPrimitive(IInputStream& rInput, EGame Game) CAnimPrimitive(IInputStream& rInput, EGame Game)
{ {
mpAnim = gpResourceStore->LoadResource( CAssetID(rInput, Game) ); mpAnim = gpResourceStore->LoadResource( CAssetID(rInput, Game) );
@ -70,6 +76,7 @@ protected:
u32 mUnknownB; u32 mUnknownB;
public: public:
CMetaAnimPlay(const CAnimPrimitive& rkPrimitive, float UnkA, u32 UnkB);
CMetaAnimPlay(IInputStream& rInput, EGame Game); CMetaAnimPlay(IInputStream& rInput, EGame Game);
virtual EMetaAnimationType Type() const; virtual EMetaAnimationType Type() const;
virtual void GetUniquePrimitives(std::set<CAnimPrimitive>& rPrimSet) const; virtual void GetUniquePrimitives(std::set<CAnimPrimitive>& rPrimSet) const;

View File

@ -137,10 +137,16 @@ CAnimSet* CAnimSetLoader::LoadReturnsCHAR(IInputStream& rCHAR)
for (u32 AnimIdx = 0; AnimIdx < NumAnims; AnimIdx++) for (u32 AnimIdx = 0; AnimIdx < NumAnims; AnimIdx++)
{ {
rCHAR.ReadString(); TString AnimName = rCHAR.ReadString();
CAssetID AnimID(rCHAR, eReturns); CAssetID AnimID(rCHAR, eReturns);
rCHAR.Skip(0x25); rCHAR.Skip(0x25);
rChar.DKDependencies.push_back(AnimID); rChar.DKDependencies.push_back(AnimID);
// small hack - create a meta-anim for it so we can generate asset names for the ANIM files correctly
SAnimation Anim;
Anim.Name = AnimName;
Anim.pMetaAnim = new CMetaAnimPlay( CAnimPrimitive(AnimID, AnimIdx, AnimName), 0.f, 0 );
pSet->mAnimations.push_back(Anim);
} }
// The only other thing we care about right now is the dependency list. If this file doesn't have a dependency list, exit out. // The only other thing we care about right now is the dependency list. If this file doesn't have a dependency list, exit out.
@ -229,6 +235,7 @@ CAnimSet* CAnimSetLoader::LoadReturnsCHAR(IInputStream& rCHAR)
} }
} }
ProcessPrimitives();
return pSet; return pSet;
} }

View File

@ -624,7 +624,9 @@ void CAreaLoader::SetUpObjects(CScriptLayer *pGenLayer)
// Check if this is a duplicate of an existing instance (this only happens with DKCR GenericCreature as far as I'm aware) // Check if this is a duplicate of an existing instance (this only happens with DKCR GenericCreature as far as I'm aware)
if (mpArea->InstanceByID(InstanceID) != nullptr) if (mpArea->InstanceByID(InstanceID) != nullptr)
{ {
if (pInst->ObjectTypeID() != FOURCC('GCTR'))
Log::Write("Duplicate SCGN object: [" + pInst->Template()->Name() + "] " + pInst->InstanceName() + " (" + TString::HexString(pInst->InstanceID(), 8, false) + ")"); Log::Write("Duplicate SCGN object: [" + pInst->Template()->Name() + "] " + pInst->InstanceName() + " (" + TString::HexString(pInst->InstanceID(), 8, false) + ")");
pGenLayer->RemoveInstance(pInst); pGenLayer->RemoveInstance(pInst);
delete pInst; delete pInst;
} }

View File

@ -335,6 +335,9 @@ void CResourceBrowser::OnGenerateAssetNames()
Dialog.DisallowCanceling(); Dialog.DisallowCanceling();
Dialog.SetOneShotTask("Generating asset names"); Dialog.SetOneShotTask("Generating asset names");
// Temporarily set root to null to ensure the window doesn't access the resource store while we're running.
mpDirectoryModel->SetRoot(mpStore->RootDirectory());
QFuture<void> Future = QtConcurrent::run(&GenerateAssetNames, mpStore->Project()); QFuture<void> Future = QtConcurrent::run(&GenerateAssetNames, mpStore->Project());
Dialog.WaitForResults(Future); Dialog.WaitForResults(Future);

View File

@ -71,6 +71,10 @@
<property ID="0x9C403177" type="color"> <property ID="0x9C403177" type="color">
<default>0.0, 0.0, 0.0, 1.0</default> <default>0.0, 0.0, 0.0, 1.0</default>
</property> </property>
<property ID="0x1F68F1B7" type="bool">
<default>false</default>
<description>This property was likely used in debug builds. It is not read by the game and has no ingame effect.</description>
</property>
<property ID="0x29463E36" type="character"/> <property ID="0x29463E36" type="character"/>
<property ID="0x103E9376" type="character"/> <property ID="0x103E9376" type="character"/>
<property ID="0x7024D89B" type="character"/> <property ID="0x7024D89B" type="character"/>