Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw data loading option for engineLoadIFP #247

Merged
merged 3 commits into from Jul 22, 2018
Merged
Changes from 2 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+38 −13
Diff settings

Always

Just for now

@@ -24,22 +24,22 @@ CClientIFP::CClientIFP(class CClientManager* pManager, ElementID ID) : CClientEn
m_u32Hashkey = 0;
}

bool CClientIFP::LoadIFP(const SString& strFilePath, const SString& strBlockName)
bool CClientIFP::LoadIFP(const SString& strFile, const bool isRawData, const SString& strBlockName)
{
m_strBlockName = strBlockName;
m_pVecAnimations = &m_pIFPAnimations->vecAnimations;

if (LoadIFPFile(strFilePath))
if (LoadIFPFile(strFile, isRawData))
{
m_u32Hashkey = HashString(strBlockName.ToLower());
return true;
}
return false;
}

bool CClientIFP::LoadIFPFile(const SString& strFilePath)
bool CClientIFP::LoadIFPFile(const SString& strFile, const bool isRawData)
{
if (LoadFileToMemory(strFilePath))
if (isRawData ? LoadDataBufferToMemory(strFile) : LoadFileToMemory(strFile))
{
if (ReadIFPByVersion())
{
@@ -205,7 +205,7 @@ class CClientIFP : public CClientEntity, CFileReader
void MarkAsUnloading(void) { m_bUnloading = true; }
bool IsUnloading(void) { return m_bUnloading; }

bool LoadIFP(const SString& strFilePath, const SString& strBlockName);
bool LoadIFP(const SString& strFile, const bool isRawData, const SString& strBlockName);

const SString& GetBlockName(void) { return m_strBlockName; }
const unsigned int& GetBlockNameHash(void) { return m_u32Hashkey; }
@@ -219,7 +219,7 @@ class CClientIFP : public CClientEntity, CFileReader
void SetPosition(const CVector& vecPosition){};

private:
bool LoadIFPFile(const SString& strFilePath);
bool LoadIFPFile(const SString& strFile, const bool isRawData);
bool ReadIFPByVersion(void);
void ReadIFPVersion1(void);
void ReadIFPVersion2(bool bAnp3);
@@ -59,3 +59,19 @@ bool CFileReader::LoadFileToMemory(const SString& strFilePath)
}
return false;
}

bool CFileReader::LoadDataBufferToMemory(const SString& buffer)
{
std::streamsize m_BufferSize = buffer.size();
if (m_BufferSize == eIFSTREAM::SIZE_ERROR)

This comment has been minimized.

Copy link
@saml1er

saml1er Jul 21, 2018

Member

can you please rename m_BufferSize to iBufferSize for consistency? I made the same mistake within CFileReader::LoadFileToMemory, so please do me one more favor and rename m_iFileSize to iFileSize.

This comment has been minimized.

Copy link
@samr46

samr46 Jul 21, 2018

Author Contributor

Sure. Done in 0cf25a0.

{
return false;
}

m_vecFileDataBuffer.reserve(static_cast<size_t>(m_BufferSize));
if (std::copy(buffer.begin(), buffer.end(), m_vecFileDataBuffer.data()))
{
return true;
}
return false;
}
@@ -24,6 +24,7 @@ class CFileReader

CFileReader(void);
bool LoadFileToMemory(const SString& strFilePath);
bool LoadDataBufferToMemory(const SString& buffer);
// Do not call any file reader functions after calling this function
void FreeFileReaderMemory(void);

@@ -10,7 +10,7 @@

#include <StdInc.h>

std::shared_ptr<CClientIFP> CIFPEngine::EngineLoadIFP(CResource* pResource, CClientManager* pManager, const SString& strPath, const SString& strBlockName)
std::shared_ptr<CClientIFP> CIFPEngine::EngineLoadIFP(CResource* pResource, CClientManager* pManager, const SString& strFile, bool bIsRawData, const SString& strBlockName)
{
// Grab the resource root entity
CClientEntity* pRoot = pResource->GetResourceIFPRoot();
@@ -23,7 +23,7 @@ std::shared_ptr<CClientIFP> CIFPEngine::EngineLoadIFP(CResource* pResource, CCli
std::shared_ptr<CClientIFP> pIFP(new CClientIFP(pManager, INVALID_ELEMENT_ID));

// Try to load the IFP file
if (pIFP->LoadIFP(strPath, strBlockName))
if (pIFP->LoadIFP(strFile, bIsRawData, strBlockName))
{
// We can use the map to retrieve correct IFP by block name later
g_pClientGame->InsertIFPPointerToMap(u32BlockNameHash, pIFP);
@@ -99,3 +99,9 @@ bool CIFPEngine::EngineRestoreAnimation(CClientEntity* pEntity, const SString& s
}
return false;
}

// Return true if data looks like IFP file contents
bool CIFPEngine::IsIFPData(const SString& strData)
{
return strData.length() > 32 && memcmp(strData, "\x41\x4E\x50", 3) == 0;
}
@@ -25,11 +25,12 @@ class CIFPEngine
ALL
};

static std::shared_ptr<CClientIFP> EngineLoadIFP(CResource* pResource, CClientManager* pManager, const SString& strPath, const SString& strBlockName);
static std::shared_ptr<CClientIFP> EngineLoadIFP(CResource* pResource, CClientManager* pManager, const SString& strFile, bool bIsRawData, const SString& strBlockName);
static bool EngineReplaceAnimation(CClientEntity* pEntity, const SString& strInternalBlockName, const SString& strInternalAnimName,
const SString& strCustomBlockName, const SString& strCustomAnimName);
static bool EngineRestoreAnimation(CClientEntity* pEntity, const SString& strInternalBlockName, const SString& strInternalAnimName,
const eRestoreAnimation& eRestoreType);
static bool IsIFPData(const SString& strData);
};

#endif
@@ -297,22 +297,23 @@ int CLuaEngineDefs::EngineLoadIFP(lua_State* luaVM)
CResource* pResource = pLuaMain->GetResource();
if (pResource)
{
bool bIsRawData = CIFPEngine::IsIFPData(strFile);
SString strPath;
// Is this a legal filepath?
if (CResourceManager::ParseResourcePathInput(strFile, pResource, &strPath))
if (bIsRawData || CResourceManager::ParseResourcePathInput(strFile, pResource, &strPath))
{
std::shared_ptr<CClientIFP> pIFP = CIFPEngine::EngineLoadIFP(pResource, m_pManager, strPath, strBlockName);
std::shared_ptr<CClientIFP> pIFP = CIFPEngine::EngineLoadIFP(pResource, m_pManager, bIsRawData ? strFile : strPath, bIsRawData, strBlockName);
if (pIFP != nullptr)
{
// Return the IFP element
lua_pushelement(luaVM, pIFP.get());
return 1;
}
else
argStream.SetCustomError(strFile, "Error loading IFP");
argStream.SetCustomError(bIsRawData ? "raw data" : strFile, "Error loading IFP");
}
else
argStream.SetCustomError(strFile, "Bad file path");
argStream.SetCustomError(bIsRawData ? "raw data" : strFile, "Bad file path");
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.