Added support for loading dependencies of EVNT and STRG

This commit is contained in:
parax0 2016-07-27 03:24:15 -06:00
parent 7f2cac6216
commit 11a7b86120
5 changed files with 103 additions and 30 deletions

View File

@ -313,7 +313,7 @@ public:
{
CharType Chr = At(iChar);
if (Chr >= 'a' && Chr <= 'z')
if (Chr >= CHAR_LITERAL('a') && Chr <= CHAR_LITERAL('z'))
Out[iChar] = Chr - 0x20;
else
Out[iChar] = Chr;
@ -553,10 +553,10 @@ public:
// Now we can finally check the actual string and make sure all the characters are valid hex characters.
for (u32 iChr = 0; iChr < Width; iChr++)
{
char Chr = Str[iChr];
if (!((Chr >= '0') && (Chr <= '9')) &&
!((Chr >= 'a') && (Chr <= 'f')) &&
!((Chr >= 'A') && (Chr <= 'F')))
CharType Chr = Str[iChr];
if (!((Chr >= CHAR_LITERAL('0')) && (Chr <= CHAR_LITERAL('9'))) &&
!((Chr >= CHAR_LITERAL('a')) && (Chr <= CHAR_LITERAL('f'))) &&
!((Chr >= CHAR_LITERAL('A')) && (Chr <= CHAR_LITERAL('F'))))
return false;
}
@ -832,23 +832,23 @@ public:
// Static
static TBasicString<CharType> FromInt32(s32 Value, int Width = 0, int Base = 16)
{
std::basic_stringstream<CharType> sstream;
sstream << std::setbase(Base) << std::setw(Width) << std::setfill(CHAR_LITERAL('0')) << Value;
return sstream.str();
std::basic_stringstream<CharType> SStream;
SStream << std::setbase(Base) << std::setw(Width) << std::setfill(CHAR_LITERAL('0')) << Value;
return SStream.str();
}
static TBasicString<CharType> FromInt64(s64 Value, int Width = 0, int Base = 16)
{
std::basic_stringstream<CharType> sstream;
sstream << std::setbase(Base) << std::setw(Width) << std::setfill(CHAR_LITERAL('0')) << Value;
return sstream.str();
std::basic_stringstream<CharType> SStream;
SStream << std::setbase(Base) << std::setw(Width) << std::setfill(CHAR_LITERAL('0')) << Value;
return SStream.str();
}
static TBasicString<CharType> FromFloat(float Value, int MinDecimals = 1)
{
std::basic_stringstream<CharType> sstream;
sstream << Value;
_TString Out = sstream.str();
std::basic_stringstream<CharType> SStream;
SStream << Value;
_TString Out = SStream.str();
int NumZeroes = Out.Size() - (Out.IndexOf(LITERAL(".")) + 1);
@ -906,13 +906,13 @@ public:
static TBasicString<CharType> HexString(unsigned long Num, int Width = 8, bool AddPrefix = true, bool Uppercase = true)
{
std::basic_stringstream<CharType> sstream;
sstream << std::hex << std::setw(Width) << std::setfill('0') << Num;
std::basic_stringstream<CharType> SStream;
SStream << std::hex << std::setw(Width) << std::setfill('0') << Num;
_TString str = sstream.str();
if (Uppercase) str = str.ToUpper();
if (AddPrefix) str.Prepend(LITERAL("0x"));
return str;
_TString Str = SStream.str();
if (Uppercase) Str = Str.ToUpper();
if (AddPrefix) Str.Prepend(LITERAL("0x"));
return Str;
}
static bool CompareCStrings(const CharType* pkA, const CharType* pkB)
@ -930,24 +930,24 @@ public:
static u32 CStringLength(const CharType* pkStr)
{
// Replacement for strlen so we can measure any CharType
u32 out = 0;
u32 Out = 0;
while (true)
{
if (*pkStr == 0) return out;
out++;
if (*pkStr == 0) return Out;
Out++;
pkStr++;
}
}
static bool IsWhitespace(CharType c)
static bool IsWhitespace(CharType Chr)
{
return ( (c == CHAR_LITERAL('\t')) ||
(c == CHAR_LITERAL('\n')) ||
(c == CHAR_LITERAL('\v')) ||
(c == CHAR_LITERAL('\f')) ||
(c == CHAR_LITERAL('\r')) ||
(c == CHAR_LITERAL(' ')) );
return ( (Chr == CHAR_LITERAL('\t')) ||
(Chr == CHAR_LITERAL('\n')) ||
(Chr == CHAR_LITERAL('\v')) ||
(Chr == CHAR_LITERAL('\f')) ||
(Chr == CHAR_LITERAL('\r')) ||
(Chr == CHAR_LITERAL(' ')) );
}
};

View File

@ -256,6 +256,7 @@ CResource* CResourceEntry::Load(IInputStream& rInput)
switch (mType)
{
case eAnimation: mpResource = CAnimationLoader::LoadANIM(rInput, this); break;
case eAnimEventData: mpResource = CUnsupportedFormatLoader::LoadEVNT(rInput, this); break;
case eAnimSet: mpResource = CAnimSetLoader::LoadANCSOrCHAR(rInput, this); break;
case eArea: mpResource = CAreaLoader::LoadMREA(rInput, this); break;
case eDependencyGroup: mpResource = CDependencyGroupLoader::LoadDGRP(rInput, this); break;

View File

@ -41,6 +41,33 @@ public:
return TWideString();
}
CDependencyTree* BuildDependencyTree() const
{
// The only dependencies STRGs have is they can reference FONTs with the &font=; formatting tag
CDependencyTree *pTree = new CDependencyTree(ID());
EIDLength IDLength = (Game() <= eEchoes ? e32Bit : e64Bit);
for (u32 iLang = 0; iLang < mLangTables.size(); iLang++)
{
const SLangTable& rkTable = mLangTables[iLang];
for (u32 iStr = 0; iStr < rkTable.Strings.size(); iStr++)
{
static const TWideString skTag = L"&font=";
const TWideString& rkStr = rkTable.Strings[iStr];
for (u32 FontIdx = rkStr.IndexOfPhrase(*skTag); FontIdx != -1; FontIdx = rkStr.IndexOfPhrase(*skTag, FontIdx + 1))
{
u32 IDStart = FontIdx + skTag.Size();
TWideString StrFontID = rkStr.SubString(IDStart, IDLength * 2);
pTree->AddDependency( CAssetID::FromString(StrFontID) );
}
}
}
return pTree;
}
};
#endif // CSTRINGTABLE_H

View File

@ -12,6 +12,50 @@ CDependencyGroup* CUnsupportedFormatLoader::LoadCSNG(IInputStream& rCSNG, CResou
return pGroup;
}
CDependencyGroup* CUnsupportedFormatLoader::LoadEVNT(IInputStream& rEVNT, CResourceEntry *pEntry)
{
u32 Version = rEVNT.ReadLong();
ASSERT(Version == 1 || Version == 2);
CDependencyGroup *pGroup = new CDependencyGroup(pEntry);
// Loop Events
u32 NumLoopEvents = rEVNT.ReadLong();
for (u32 iLoop = 0; iLoop < NumLoopEvents; iLoop++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x1C, SEEK_CUR);
}
// User Events
u32 NumUserEvents = rEVNT.ReadLong();
for (u32 iUser = 0; iUser < NumUserEvents; iUser++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x1F, SEEK_CUR);
rEVNT.ReadString();
}
// Effect Events
u32 NumEffectEvents = rEVNT.ReadLong();
for (u32 iFX = 0; iFX < NumEffectEvents; iFX++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x23, SEEK_CUR);
pGroup->AddDependency(rEVNT.ReadLong());
rEVNT.ReadString();
rEVNT.Seek(0x8, SEEK_CUR);
}
return pGroup;
}
CDependencyGroup* CUnsupportedFormatLoader::LoadHINT(IInputStream& rHINT, CResourceEntry *pEntry)
{
u32 Magic = rHINT.ReadLong();

View File

@ -12,6 +12,7 @@ class CUnsupportedFormatLoader
public:
static CDependencyGroup* LoadCSNG(IInputStream& rCSNG, CResourceEntry *pEntry);
static CDependencyGroup* LoadEVNT(IInputStream& rEVNT, CResourceEntry *pEntry);
static CDependencyGroup* LoadHINT(IInputStream& rHINT, CResourceEntry *pEntry);
static CDependencyGroup* LoadMAPW(IInputStream& rMAPW, CResourceEntry *pEntry);
static CDependencyGroup* LoadMAPU(IInputStream& rMAPU, CResourceEntry *pEntry);