Skip to content

Commit

Permalink
Synchronize changes from 1.6 master branch [ci skip]
Browse files Browse the repository at this point in the history
c57f07b Fix Unicode file path passed in CClientIMG (#3171)
  • Loading branch information
github-actions[bot] committed Sep 19, 2023
2 parents e946e62 + c57f07b commit 190deea
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Client/game_sa/CStreamingSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ unsigned char CStreamingSA::GetUnusedStreamHandle()
return INVALID_STREAM_ID;
}

unsigned char CStreamingSA::AddArchive(const char* szFilePath)
unsigned char CStreamingSA::AddArchive(const wchar_t* szFilePath)
{
auto ucArchiveId = GetUnusedArchive();
if (ucArchiveId == INVALID_ARCHIVE_ID)
Expand All @@ -402,7 +402,7 @@ unsigned char CStreamingSA::AddArchive(const char* szFilePath)

// Create new stream handler
const auto streamCreateFlags = *(DWORD*)0x8E3FE0;
HANDLE hFile = CreateFileA(szFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
HANDLE hFile = CreateFileW(szFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
streamCreateFlags | FILE_ATTRIBUTE_READONLY | FILE_FLAG_RANDOM_ACCESS, NULL);

if (hFile == INVALID_HANDLE_VALUE)
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CStreamingSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CStreamingSA final : public CStreaming
void SetStreamingInfo(uint32 modelid, unsigned char usStreamID, uint uiOffset, ushort usSize, uint uiNextInImg = -1);
unsigned char GetUnusedArchive();
unsigned char GetUnusedStreamHandle();
unsigned char AddArchive(const char* szFilePath);
unsigned char AddArchive(const wchar_t* szFilePath);
void RemoveArchive(unsigned char ucStreamHandler);
bool SetStreamingBufferSize(uint32 uiSize);
uint32 GetStreamingBufferSize() { return ms_streamingHalfOfBufferSizeBlocks * 2048 * 2; }; // In bytes
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientIMG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool CClientIMG::Load(fs::path filePath)
if (!fs::exists(filePath))
return false;

m_filePath = filePath.string();
m_filePath = filePath;
m_ifs = std::ifstream(filePath, std::ios::binary);

// Open the file
Expand Down Expand Up @@ -157,7 +157,7 @@ bool CClientIMG::StreamEnable()
m_LargestFileSizeBlocks = std::max(m_LargestFileSizeBlocks, (size_t)fileInfo.usSize);
}

m_ucArchiveID = g_pGame->GetStreaming()->AddArchive(m_filePath.c_str());
m_ucArchiveID = g_pGame->GetStreaming()->AddArchive(m_filePath.wstring().c_str());

if (IsStreamed())
{
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientIMG.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CClientIMG : public CClientEntity
class CClientIMGManager* m_pImgManager;

std::ifstream m_ifs;
std::string m_filePath;
fs::path m_filePath;
unsigned char m_ucArchiveID;
std::vector<tImgFileInfo> m_fileInfos;
size_t m_LargestFileSizeBlocks; // The size of the largest file [in streaming blocks/sectors]
Expand Down
5 changes: 4 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,11 @@ CClientIMG* CLuaEngineDefs::EngineLoadIMG(lua_State* const luaVM, std::string st
// Create the img handle
CClientIMG* pImg = new CClientIMG(m_pManager, INVALID_ELEMENT_ID);

// Fix path encoding for sdt::filesystem
std::wstring utf8Path = SharedUtil::MbUTF8ToUTF16(strFullPath);

// Attempt loading the file
if (pImg->Load(std::move(strFullPath)))
if (pImg->Load(std::move(utf8Path)))
{
// Success. Make it a child of the resource img root
pImg->SetParent(pRoot);
Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/game/CStreaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CStreaming
virtual void RequestSpecialModel(DWORD model, const char* szTexture, DWORD channel) = 0;
virtual CStreamingInfo* GetStreamingInfo(uint32 id) = 0;
virtual void ReinitStreaming() = 0;
virtual unsigned char AddArchive(const char* szFilePath) = 0;
virtual unsigned char AddArchive(const wchar_t *szFilePath) = 0;
virtual void RemoveArchive(unsigned char ucArchiveID) = 0;
virtual void SetStreamingInfo(unsigned int id, unsigned char usStreamID, unsigned int uiOffset, unsigned short usSize, unsigned int uiNextInImg = -1) = 0;
virtual bool SetStreamingBufferSize(uint32 uiSize) = 0;
Expand Down

0 comments on commit 190deea

Please sign in to comment.