diff --git a/Minecraft.Client/Platform_Libs/Dev/Storage/4J_Storage.cpp b/Minecraft.Client/Platform_Libs/Dev/Storage/4J_Storage.cpp deleted file mode 100644 index 12fba123..00000000 --- a/Minecraft.Client/Platform_Libs/Dev/Storage/4J_Storage.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/* -MIT License - -Copyright (c) 2026 Patoke - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "../../../Windows64/4JLibs/inc/4J_Storage.h" -#include "STO_Main.h" - -C4JStorage StorageManager; -XMARKETPLACE_CONTENTOFFER_INFO InternalContentOfferInfo; - -C4JStorage::C4JStorage() {} - -void C4JStorage::Tick(void) -{ - InternalStorageManager.Tick(); -} - -C4JStorage::EMessageResult C4JStorage::RequestMessageBox(UINT uiTitle, UINT uiText, UINT *uiOptionA, UINT uiOptionC, DWORD dwPad, - int (*Func)(LPVOID, int, const C4JStorage::EMessageResult), LPVOID lpParam, - C4JStringTable *pStringTable, WCHAR *pwchFormatString, DWORD dwFocusButton) -{ - return EMessage_Undefined; -} - -C4JStorage::EMessageResult C4JStorage::GetMessageBoxResult() -{ - return EMessage_Undefined; -} - -bool C4JStorage::SetSaveDevice(int (*Func)(LPVOID, const bool), LPVOID lpParam, bool bForceResetOfSaveDevice) -{ - return true; -} - -void C4JStorage::Init(unsigned int uiSaveVersion, LPCWSTR pwchDefaultSaveName, char *pszSavePackName, int iMinimumSaveSize, - int (*Func)(LPVOID, const ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID) -{ - InternalStorageManager.Init(Func, lpParam, szGroupID); -} - -void C4JStorage::ResetSaveData() -{ - InternalStorageManager.m_SaveGame.ResetSaveData(); -} - -void C4JStorage::SetDefaultSaveNameForKeyboardDisplay(LPCWSTR pwchDefaultSaveName) -{ - ; -} - -void C4JStorage::SetSaveTitle(LPCWSTR pwchDefaultSaveName) -{ - InternalStorageManager.m_SaveGame.SetSaveTitle(pwchDefaultSaveName); -} - -LPCWSTR C4JStorage::GetSaveTitle() -{ - return InternalStorageManager.m_SaveGame.GetSaveTitle(); -} - -bool C4JStorage::GetSaveUniqueNumber(INT *piVal) -{ - return InternalStorageManager.m_SaveGame.GetSaveUniqueNumber(piVal); -} - -bool C4JStorage::GetSaveUniqueFilename(char *pszName) -{ - return InternalStorageManager.m_SaveGame.GetSaveUniqueFilename(pszName); -} - -void C4JStorage::SetSaveUniqueFilename(char *szFilename) -{ - InternalStorageManager.m_SaveGame.SetSaveUniqueFilename(szFilename); -} - -void C4JStorage::SetState(ESaveGameControlState eControlState, int (*Func)(LPVOID, const bool), LPVOID lpParam) -{ - ; -} - -void C4JStorage::SetSaveDisabled(bool bDisable) -{ - InternalStorageManager.m_SaveGame.SetSaveDisabled(bDisable); -} - -bool C4JStorage::GetSaveDisabled(void) -{ - return InternalStorageManager.m_SaveGame.GetSaveDisabled(); -} - -unsigned int C4JStorage::GetSaveSize() -{ - return InternalStorageManager.m_SaveGame.GetSaveSize(); -} - -void C4JStorage::GetSaveData(void *pvData, unsigned int *puiBytes) -{ - InternalStorageManager.m_SaveGame.GetSaveData(pvData, puiBytes); -} - -PVOID C4JStorage::AllocateSaveData(unsigned int uiBytes) -{ - return InternalStorageManager.m_SaveGame.AllocateSaveData(uiBytes); -} - -void C4JStorage::SetSaveImages(PBYTE pbThumbnail, DWORD dwThumbnailBytes, PBYTE pbImage, DWORD dwImageBytes, PBYTE pbTextData, DWORD dwTextDataBytes) -{ - InternalStorageManager.m_SaveGame.SetSaveImages(pbThumbnail, dwThumbnailBytes, pbImage, dwImageBytes, pbTextData, dwTextDataBytes); -} - -void C4JStorage::SetDefaultImages(PBYTE pbOptionsImage, DWORD dwOptionsImageBytes, PBYTE pbSaveImage, DWORD dwSaveImageBytes, PBYTE pbSaveThumbnail, DWORD dwSaveThumbnailBytes) -{ - InternalStorageManager.m_SaveGame.SetDefaultImages(pbOptionsImage, dwOptionsImageBytes, pbSaveImage, dwSaveImageBytes, pbSaveThumbnail, dwSaveThumbnailBytes); -} - -void C4JStorage::GetDefaultSaveImage(PBYTE *ppbSaveImage, DWORD *pdwSaveImageBytes) -{ - InternalStorageManager.m_SaveGame.GetDefaultSaveImage(ppbSaveImage, pdwSaveImageBytes); -} - -void C4JStorage::GetDefaultSaveThumbnail(PBYTE *ppbSaveThumbnail, DWORD *pdwSaveThumbnailBytes) -{ - InternalStorageManager.m_SaveGame.GetDefaultSaveThumbnail(ppbSaveThumbnail, pdwSaveThumbnailBytes); -} - -C4JStorage::ESaveGameState C4JStorage::SaveSaveData(int (*Func)(LPVOID, const bool), LPVOID lpParam) -{ - return InternalStorageManager.m_SaveGame.SaveSaveData(Func, lpParam); -} - -void C4JStorage::CopySaveDataToNewSave(PBYTE pbThumbnail, DWORD cbThumbnail, WCHAR *wchNewName, int (*Func)(LPVOID lpParam, bool), LPVOID lpParam) -{ - InternalStorageManager.m_SaveGame.CopySaveDataToNewSave(pbThumbnail, cbThumbnail, wchNewName, Func, lpParam); -} - -void C4JStorage::SetSaveDeviceSelected(unsigned int uiPad, bool bSelected) -{ - ; -} - -bool C4JStorage::GetSaveDeviceSelected(unsigned int iPad) -{ - return true; -} - -C4JStorage::ESaveGameState C4JStorage::DoesSaveExist(bool *pbExists) -{ - return InternalStorageManager.m_SaveGame.DoesSaveExist(pbExists); -} - -bool C4JStorage::EnoughSpaceForAMinSaveGame() -{ - return true; -} - -void C4JStorage::SetMaxSaves(int iMaxC) -{ - (void)iMaxC; -} - -void C4JStorage::SetIncompleteSaveCallback(void (*Func)(LPVOID, const ESaveIncompleteType, int blocksRequired), LPVOID param) -{ - (void)Func; - (void)param; -} - -void C4JStorage::ContinueIncompleteOperation() -{ -} - -C4JStorage::ESaveGameState C4JStorage::GetSaveState() -{ - return C4JStorage::ESaveGame_Idle; -} - -void C4JStorage::SetSaveMessageVPosition(float fY) -{ - ; -} - -C4JStorage::ESaveGameState C4JStorage::GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS *pSaveDetails, const bool), LPVOID lpParam, - char *pszSavePackName) -{ - return InternalStorageManager.m_SaveGame.GetSavesInfo(iPad, Func, lpParam, pszSavePackName); -} - -PSAVE_DETAILS C4JStorage::ReturnSavesInfo() -{ - return InternalStorageManager.m_SaveGame.ReturnSavesInfo(); -} - -void C4JStorage::ClearSavesInfo() -{ - InternalStorageManager.m_SaveGame.ClearSavesInfo(); -} - -C4JStorage::ESaveGameState C4JStorage::LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo, - int (*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), LPVOID lpParam) -{ - return InternalStorageManager.m_SaveGame.LoadSaveDataThumbnail(pSaveInfo, Func, lpParam); -} - -void C4JStorage::GetSaveCacheFileInfo(DWORD dwFile, XCONTENT_DATA &xContentData) -{ - ; -} - -void C4JStorage::GetSaveCacheFileInfo(DWORD dwFile, PBYTE *ppbImageData, DWORD *pdwImageBytes) -{ - ; -} - -C4JStorage::ESaveGameState C4JStorage::LoadSaveData(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, const bool, const bool), LPVOID lpParam) -{ - return InternalStorageManager.m_SaveGame.LoadSaveData(pSaveInfo, Func, lpParam); -} - -C4JStorage::ESaveGameState C4JStorage::DeleteSaveData(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, const bool), LPVOID lpParam) -{ - return InternalStorageManager.m_SaveGame.DeleteSaveData(pSaveInfo, Func, lpParam); -} - -C4JStorage::ESaveGameState C4JStorage::RenameSaveData(int iRenameIndex, uint16_t *pui16NewName, int (*Func)(LPVOID lpParam, const bool), LPVOID lpParam) -{ - return InternalStorageManager.m_SaveGame.RenameSaveData(iRenameIndex, pui16NewName, Func, lpParam); -} - -void C4JStorage::RegisterMarketplaceCountsCallback(int (*Func)(LPVOID lpParam, C4JStorage::DLC_TMS_DETAILS *, int), LPVOID lpParam) -{ - ; -} - -void C4JStorage::SetDLCPackageRoot(char *pszDLCRoot) -{ - InternalStorageManager.m_DLC.SetPackageRoot(pszDLCRoot); -} - -C4JStorage::EDLCStatus C4JStorage::GetDLCOffers(int iPad, int (*Func)(LPVOID, int, DWORD, int), LPVOID lpParam, DWORD dwOfferTypesBitmask) -{ - return EDLC_Idle; -} - -DWORD C4JStorage::CancelGetDLCOffers() -{ - return 0; -} - -void C4JStorage::ClearDLCOffers() -{ - ; -} - -XMARKETPLACE_CONTENTOFFER_INFO &C4JStorage::GetOffer(DWORD dw) -{ - return InternalContentOfferInfo; -} - -int C4JStorage::GetOfferCount() -{ - return 0; -} - -DWORD C4JStorage::InstallOffer(int iOfferIDC, uint64_t *ullOfferIDA, int (*Func)(LPVOID, int, int), LPVOID lpParam, bool bTrial) -{ - return 0; -} - -DWORD C4JStorage::GetAvailableDLCCount(int iPad) -{ - return InternalStorageManager.m_DLC.GetAvailableDLCCount(iPad); -} - -C4JStorage::EDLCStatus C4JStorage::GetInstalledDLC(int iPad, int (*Func)(LPVOID, int, int), LPVOID lpParam) -{ - return InternalStorageManager.m_DLC.GetInstalledDLC(iPad, Func, lpParam); -} - -XCONTENT_DATA &C4JStorage::GetDLC(DWORD dw) -{ - return InternalStorageManager.m_DLC.GetDLC(dw); -} - -DWORD C4JStorage::MountInstalledDLC(int iPad, DWORD dwDLC, int (*Func)(LPVOID, int, DWORD, DWORD), LPVOID lpParam, LPCSTR szMountDrive) -{ - return InternalStorageManager.m_DLC.MountInstalledDLC(iPad, dwDLC, Func, lpParam, szMountDrive); -} - -DWORD C4JStorage::UnmountInstalledDLC(LPCSTR szMountDrive) -{ - return InternalStorageManager.m_DLC.UnmountInstalledDLC(szMountDrive); -} - -void C4JStorage::GetMountedDLCFileList(const char *szMountDrive, std::vector &fileList) -{ - InternalStorageManager.m_DLC.GetMountedDLCFileList(szMountDrive, fileList); -} - -std::string C4JStorage::GetMountedPath(std::string szMount) -{ - return InternalStorageManager.m_DLC.GetMountedPath(szMount); -} - -C4JStorage::ETMSStatus C4JStorage::ReadTMSFile(int iQuadrant, eGlobalStorage eStorageFacility, C4JStorage::eTMS_FileType eFileType, - WCHAR *pwchFilename, BYTE **ppBuffer, DWORD *pdwBufferSize, - int (*Func)(LPVOID, WCHAR *, int, bool, int), LPVOID lpParam, int iAction) -{ - return ETMSStatus_Idle; -} - -bool C4JStorage::WriteTMSFile(int iQuadrant, eGlobalStorage eStorageFacility, WCHAR *pwchFilename, BYTE *pBuffer, DWORD dwBufferSize) -{ - return true; -} - -bool C4JStorage::DeleteTMSFile(int iQuadrant, eGlobalStorage eStorageFacility, WCHAR *pwchFilename) -{ - return true; -} - -void C4JStorage::StoreTMSPathName(WCHAR *pwchName) -{ - ; -} - -C4JStorage::ETMSStatus C4JStorage::TMSPP_ReadFile(int iPad, C4JStorage::eGlobalStorage eStorageFacility, C4JStorage::eTMS_FILETYPEVAL eFileTypeVal, - LPCSTR szFilename, int (*Func)(LPVOID, int, int, PTMSPP_FILEDATA, LPCSTR), LPVOID lpParam, - int iUserData) -{ - return ETMSStatus_Idle; -} - -unsigned int C4JStorage::CRC(unsigned char *buf, int len) -{ - return 0; -} - - diff --git a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_DLC.cpp b/Minecraft.Client/Platform_Libs/Dev/Storage/STO_DLC.cpp deleted file mode 100644 index e939ebcf..00000000 --- a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_DLC.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/* -MIT License - -Copyright (c) 2026 Patoke - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "STO_DLC.h" -#include "STO_Main.h" - -#ifdef __linux__ -#include -#include -#include -#include -#endif - -XCONTENT_DATA &CDLC::GetDLC(DWORD dw) -{ - return m_vInstalledDLCs[dw]; -} - -CDLC::CDLC(void) : m_vInstalledDLCs(), m_szMountPath(), m_vDLCDriveMappings() -{ - m_iHasNewInstalledDLCs = false; - dword0 = 0; - dwordC0 = 0; - m_iHasNewMountedDLCs = false; // @Patoke fix - - ZeroMemory(m_szDLCProductCode, sizeof(m_szDLCProductCode)); - ZeroMemory(m_szProductUpgradeKey, sizeof(m_szProductUpgradeKey)); -} - -C4JStorage::EDLCStatus CDLC::GetOffers(int iPad, int (*Func)(LPVOID, int, DWORD, int), LPVOID lpParam, DWORD dwOfferTypesBitmask) -{ - return C4JStorage::EDLC_NoOffers; -} - -void CDLC::ClearOffers() -{ - ; -} - -C4JStorage::EDLCStatus CDLC::GetInstalledDLC(int iPad, int (*Func)(LPVOID, int, int), LPVOID lpParam) -{ - if (m_iHasNewInstalledDLCs) - { - return C4JStorage::EDLC_Pending; - } - - m_pInstalledDLCFunc = Func; - m_pInstalledDLCParam = lpParam; - m_iHasNewInstalledDLCs = true; - -#ifdef __linux__ - const char *dlcDir = NULL; - struct stat stDir; - if (stat("Windows64Media/DLC", &stDir) == 0 && S_ISDIR(stDir.st_mode)) - { - dlcDir = "Windows64Media/DLC"; - } - else if (stat("Windows64/DLC", &stDir) == 0 && S_ISDIR(stDir.st_mode)) - { - dlcDir = "Windows64/DLC"; - } - - if (!dlcDir) - { - InternalStorageManager.DebugPrintf("No DLC directory, can't have any DLC installed\n"); - return C4JStorage::EDLC_Error; - } - - DIR *dir = opendir(dlcDir); - if (dir) - { - struct dirent *entry; - while ((entry = readdir(dir)) != NULL) - { - if (entry->d_name[0] == '.') - continue; - char fullPath[512]; - snprintf(fullPath, sizeof(fullPath), "%s/%s", dlcDir, entry->d_name); - struct stat stEntry; - if (stat(fullPath, &stEntry) == 0 && S_ISDIR(stEntry.st_mode)) - { - XCONTENT_DATA data; - snprintf(data.szFileName, sizeof(data.szFileName), "%s/%s", dlcDir, entry->d_name); - swprintf(data.szDisplayName, 256, L"%s", entry->d_name); - data.DeviceID = 0; - data.dwContentType = 0; - AddInstalled(&data); - } - } - closedir(dir); - } -#else - bool ret = false; - DWORD atts = GetFileAttributesA("Windows64Media/DLC"); - if (atts == -1) - { - atts = GetFileAttributesA("Windows64/DLC"); - ret = true; - } - - bool validDir = atts != -1 && (atts & FILE_ATTRIBUTE_DIRECTORY); - if (!validDir) - { - InternalStorageManager.DebugPrintf("No DLC directory, can't have any DLC installed\n"); - return C4JStorage::EDLC_Error; - } - - _WIN32_FIND_DATAA hFind; - HANDLE hFindFile; - if (ret) - { - hFindFile = FindFirstFileA("Windows64/DLC/*", &hFind); - } - else - { - hFindFile = FindFirstFileA("Windows64Media/DLC/*", &hFind); - } - - if (hFindFile != (HANDLE)-1LL) - { - do - { - atts = hFind.dwFileAttributes; - - bool isArt = hFind.dwFileAttributes != -1 && (hFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - if (isArt && hFind.cFileName[0] != '.') - { - XCONTENT_DATA data; - - if (ret) - { - sprintf(data.szFileName, "Windows64/DLC/%s", hFind.cFileName); - } - else - { - sprintf(data.szFileName, "Windows64Media/DLC/%s", hFind.cFileName); - } - - swprintf(data.szDisplayName, 256, L"%s", hFind.cFileName); - int displayNameLen = wcslen(data.szDisplayName); - - data.DeviceID = 0; - data.dwContentType = 0; - - AddInstalled(&data); - } - } while (FindNextFileA(hFindFile, &hFind)); - FindClose(hFindFile); - } -#endif - - return C4JStorage::EDLC_Idle; -} - -DWORD CDLC::MountInstalledDLC(int iPad, DWORD dwDLC, int (*Func)(LPVOID, int, DWORD, DWORD), LPVOID lpParam, LPCSTR szMountDrive) -{ - this->m_pMountedDLCFunc = Func; - this->m_pMountedDLCParam = lpParam; - - if (szMountDrive) - { - m_szMountPath = szMountDrive; - } - else - { - m_szMountPath = this->m_szPackageRoot; - } - - this->m_uiCurrentMappedDLC = dwDLC; - - char *dlcdirPath = m_vInstalledDLCs[m_uiCurrentMappedDLC].szFileName; - m_vDLCDriveMappings.push_back(DriveMapping(m_szMountPath, dlcdirPath)); - - dword94 = 0xFFFFFFFF; - m_iHasNewMountedDLCs = true; - - return 997; -} - -DWORD CDLC::UnmountInstalledDLC(LPCSTR szMountDrive) -{ - LPCSTR szDrive = nullptr; - - if (szMountDrive) - { - szDrive = szMountDrive; - } - else - { - szDrive = this->m_szPackageRoot; - } - - for (int i = 0; i < this->m_vDLCDriveMappings.size(); i++) - { - if (m_vDLCDriveMappings[i].m_szDirectoryPath == szDrive) - { - m_vDLCDriveMappings.erase(m_vDLCDriveMappings.begin() + i); - - return 0; - } - } - return 0; -} - -void CDLC::GetMountedDLCFileList(const char *szMountDrive, std::vector &fileList) -{ -#ifdef __linux__ - const char *basePath = m_vInstalledDLCs[m_uiCurrentMappedDLC].szFileName; - DIR *dir = opendir(basePath); - if (dir) - { - struct dirent *entry; - while ((entry = readdir(dir)) != NULL) - { - if (entry->d_name[0] == '.') - continue; - char fullPath[256]; - snprintf(fullPath, sizeof(fullPath), "%s/%s", basePath, entry->d_name); - struct stat st; - if (stat(fullPath, &st) == 0 && !S_ISDIR(st.st_mode)) - { - fileList.push_back(fullPath); - } - } - closedir(dir); - } -#else - char *dlcdirPath = new char[256]; - sprintf(dlcdirPath, "%s/*", m_vInstalledDLCs[m_uiCurrentMappedDLC].szFileName); - - _WIN32_FIND_DATAA atts; - HANDLE hFind = FindFirstFileA(dlcdirPath, &atts); - if (hFind != (HANDLE)-1LL) - { - do - { - if (atts.dwFileAttributes == -1 || (atts.dwFileAttributes & 0x10) != 0x10) - { - char dir[256]; - sprintf(dir, "%s/%s", m_vInstalledDLCs[m_uiCurrentMappedDLC].szFileName, atts.cFileName); - - fileList.push_back(dir); - } - } while (FindNextFileA(hFind, &atts)); - FindClose(hFind); - } - delete[] dlcdirPath; -#endif -} - -std::string CDLC::GetMountedPath(std::string szMount) -{ - for (int ch = 0; ch < szMount.size(); ++ch) - { - if (szMount[ch] == '/' || szMount[ch] == '\\') - { - return ""; - } - - if (szMount[ch] == ':') - { - std::string driveName = szMount.substr(0, ch); - for (int i = 0; i < m_vDLCDriveMappings.size(); ++i) - { - if (m_vDLCDriveMappings[i].m_szDirectoryPath == driveName) - { - std::string newPath = m_vDLCDriveMappings[i].m_szMountPath; - - newPath.append(szMount.substr(ch + 1, -1)); - - return newPath; - } - } - break; - } - } - - return ""; -} - -void CDLC::SetDLCProductCode(const char *szProductCode) -{ - strcpy(m_szDLCProductCode, szProductCode); -} - -void CDLC::SetProductUpgradeKey(const char *szProductCode) -{ - strcpy(m_szProductUpgradeKey, szProductCode); -} - -int CDLC::GetAvailableDLCCount(int iPad) -{ - return 0; -} - -void CDLC::SetPackageRoot(char *pszDLCRoot) -{ - strcpy(this->m_szPackageRoot, pszDLCRoot); -} - -void CDLC::Tick(void) -{ - if (m_iHasNewInstalledDLCs) - { - m_iHasNewInstalledDLCs = false; - m_pInstalledDLCFunc(m_pInstalledDLCParam, m_vInstalledDLCs.size(), 0); - } - if (m_iHasNewMountedDLCs) - { - m_iHasNewMountedDLCs = false; - m_pMountedDLCFunc(m_pMountedDLCParam, 0, 0, dword94); - } -} - -void CDLC::AddInstalled(XCONTENT_DATA *data) -{ - m_vInstalledDLCs.push_back(*data); -} - -DWORD CDLC::CancelOffers(void) -{ - return 0; -} diff --git a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_DLC.h b/Minecraft.Client/Platform_Libs/Dev/Storage/STO_DLC.h deleted file mode 100644 index 89603611..00000000 --- a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_DLC.h +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once -/* -MIT License - -Copyright (c) 2026 Patoke - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "../../../Windows64/4JLibs/inc/4J_Storage.h" - -class CDLC -{ -public: - struct DriveMapping - { - DriveMapping(std::string szDirectoryPath, std::string szMountPath) : m_szDirectoryPath(szDirectoryPath), m_szMountPath(szMountPath) - { - ; - } - - std::string m_szDirectoryPath; - std::string m_szMountPath; - }; - - XCONTENT_DATA &GetDLC(DWORD dw); - CDLC(void); - - C4JStorage::EDLCStatus GetOffers(int iPad, int (*Func)(LPVOID, int, DWORD, int), LPVOID lpParam, - DWORD dwOfferTypesBitmask = XMARKETPLACE_OFFERING_TYPE_CONTENT); - void ClearOffers(); - C4JStorage::EDLCStatus GetInstalledDLC(int iPad, int (*Func)(LPVOID, int, int), LPVOID lpParam); - DWORD MountInstalledDLC(int iPad, DWORD dwDLC, int (*Func)(LPVOID, int, DWORD, DWORD), LPVOID lpParam, LPCSTR szMountDrive = NULL); - DWORD UnmountInstalledDLC(LPCSTR szMountDrive = NULL); - void GetMountedDLCFileList(const char *szMountDrive, std::vector &fileList); - std::string GetMountedPath(std::string szMount); - - void SetDLCProductCode(const char *szProductCode); - void SetProductUpgradeKey(const char *szProductCode); - int GetAvailableDLCCount(int iPad); - void SetPackageRoot(char *pszDLCRoot); - - void Tick(void); - void AddInstalled(XCONTENT_DATA *data); - DWORD CancelOffers(void); - - DWORD dword0; - int (*m_pInstalledDLCFunc)(LPVOID, int, int); - LPVOID m_pInstalledDLCParam; - BYTE gap18[16]; - int m_iHasNewInstalledDLCs; - std::vector m_vInstalledDLCs; - BYTE gap48[4]; - DWORD m_iHasNewMountedDLCs; - int (*m_pMountedDLCFunc)(LPVOID, int, DWORD, DWORD); - LPVOID m_pMountedDLCParam; - std::string m_szMountPath; - DWORD m_uiCurrentMappedDLC; - DWORD dword94; - char m_szPackageRoot[40]; - DWORD dwordC0; - std::vector m_vDLCDriveMappings; - char m_szDLCProductCode[16]; - char m_szProductUpgradeKey[60]; -}; diff --git a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_Main.cpp b/Minecraft.Client/Platform_Libs/Dev/Storage/STO_Main.cpp deleted file mode 100644 index 7f4e8124..00000000 --- a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_Main.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* -MIT License - -Copyright (c) 2026 Patoke - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "STO_Main.h" -#include "../../../Windows64/4JLibs/inc/4J_Storage.h" - -CStorage InternalStorageManager; - -CStorage::CStorage(void) -{ - m_SaveGame = CSaveGame(); - m_DLC = CDLC(); -} - -void CStorage::Init(int (*Func)(LPVOID, const C4JStorage::ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID) {} - -void CStorage::Tick(void) -{ - m_DLC.Tick(); -} - -unsigned int CStorage::CRC(unsigned char *buf, int len) -{ - return ~UpdateCRC(0xFFFFFFFF, buf, len); -} - -void CStorage::MakeCRCTable(void) -{ - for (int c = 0; c < 256; ++c) - { - unsigned int k = c; - for (int n = 0; n < 8; ++n) - { - if ((k & 1) != 0) - { - k = (k >> 1) ^ 0xEDB88320; - } - else - { - k >>= 1; - } - } - m_CRCTable[c] = k; - } - m_bHasCRCTable = true; -} - -unsigned int CStorage::UpdateCRC(unsigned int crc, unsigned __int8 *buf, int len) -{ - if (!m_bHasCRCTable) - { - MakeCRCTable(); - } - - for (int c = 0; c < len; ++c) - { - crc = (crc >> 8) ^ m_CRCTable[(unsigned __int8)(buf[c] ^ crc)]; - } - - return crc; -} - -void CStorage::DebugPrintf(const char *szFormat, ...) -{ - char buf[1024]; - - va_list va; - va_start(va, szFormat); - - vsnprintf(buf, 1024, szFormat, va); - - va_end(va); -} diff --git a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_Main.h b/Minecraft.Client/Platform_Libs/Dev/Storage/STO_Main.h deleted file mode 100644 index 95803eee..00000000 --- a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_Main.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -/* -MIT License - -Copyright (c) 2026 Patoke - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "STO_DLC.h" -#include "STO_SaveGame.h" - -class CStorage -{ -public: - CStorage(void); - - void Init(int (*Func)(LPVOID, const C4JStorage::ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID); - void Tick(void); - unsigned int CRC(unsigned char *buf, int len); - void MakeCRCTable(void); - unsigned int UpdateCRC(unsigned int crc, unsigned __int8 *buf, int len); - void DebugPrintf(const char *szFormat, ...); - - BYTE gap0[8]; - CSaveGame m_SaveGame; - CDLC m_DLC; - BYTE gap278[0x10]; - DWORD m_CRCTable[256]; - bool m_bHasCRCTable; -}; - -extern CStorage InternalStorageManager; \ No newline at end of file diff --git a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_SaveGame.cpp b/Minecraft.Client/Platform_Libs/Dev/Storage/STO_SaveGame.cpp deleted file mode 100644 index 7646a2d1..00000000 --- a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_SaveGame.cpp +++ /dev/null @@ -1,1227 +0,0 @@ -/* -MIT License - -Copyright (c) 2026 Patoke - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "STO_SaveGame.h" -#include - -#ifdef __linux__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif - -static unsigned long s_pngCrcTable[256]; -static bool s_pngCrcTableReady = false; - -static void BuildPngCrcTable() -{ - for (unsigned int n = 0; n < 256; n++) - { - unsigned long c = n; - for (int k = 0; k < 8; k++) - c = (c & 1) ? (0xEDB88320L ^ (c >> 1)) : (c >> 1); - s_pngCrcTable[n] = c; - } - s_pngCrcTableReady = true; -} - -static unsigned long PngCrc32(const unsigned char *buf, unsigned int len) -{ - if (!s_pngCrcTableReady) BuildPngCrcTable(); - unsigned long c = 0xFFFFFFFFL; - for (unsigned int i = 0; i < len; i++) - c = s_pngCrcTable[(c ^ buf[i]) & 0xFF] ^ (c >> 8); - return c ^ 0xFFFFFFFFL; -} - -static inline unsigned int WriteBE32(unsigned int v) -{ - return ((v >> 24) & 0xFF) | - ((v >> 8) & 0xFF00) | - ((v << 8) & 0xFF0000) | - ((v << 24) & 0xFF000000); -} - -static void GetGameHDDPath(char *outPath, int maxLen) -{ - char curDir[256]; -#ifdef __linux__ - getcwd(curDir, sizeof(curDir)); - snprintf(outPath, maxLen, "%s/Linux/GameHDD", curDir); -#else - GetCurrentDirectoryA(sizeof(curDir), curDir); - sprintf_s(outPath, maxLen, "%s\\Windows64\\GameHDD", curDir); -#endif -} - -CSaveGame::CSaveGame() -{ - m_pSaveData = nullptr; - m_uiSaveSize = 0; - m_bIsSafeDisabled = false; - - ZeroMemory(m_szSaveUniqueName, sizeof(m_szSaveUniqueName)); - ZeroMemory(m_wszSaveTitle, sizeof(m_wszSaveTitle)); - - m_pSaveDetails = nullptr; - m_bHasSaveDetails = false; - - m_pbThumbnail = nullptr; - m_dwThumbnailBytes = 0; - m_pbDefaultThumbnail = nullptr; - m_dwDefaultThumbnailBytes = 0; - m_pbDefaultSaveImage = nullptr; - m_dwDefaultSaveImageBytes = 0; - - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - -#ifdef __linux__ - char curDir[256]; - getcwd(curDir, sizeof(curDir)); - char win64Path[256]; - snprintf(win64Path, sizeof(win64Path), "%s/Linux", curDir); - mkdir(win64Path, 0755); - mkdir(gameHDDPath, 0755); -#else - char win64Path[256]; - char curDir[256]; - GetCurrentDirectoryA(sizeof(curDir), curDir); - sprintf_s(win64Path, sizeof(win64Path), "%s\\Windows64", curDir); - CreateDirectoryA(win64Path, 0); - CreateDirectoryA(gameHDDPath, 0); -#endif -} - -void CSaveGame::SetSaveDisabled(bool bDisable) -{ - m_bIsSafeDisabled = bDisable; -} - -bool CSaveGame::GetSaveDisabled(void) -{ - return m_bIsSafeDisabled; -} - -void CSaveGame::ResetSaveData() -{ - free(m_pSaveData); - m_pSaveData = nullptr; - m_uiSaveSize = 0; - - ZeroMemory(m_szSaveUniqueName, sizeof(m_szSaveUniqueName)); - ZeroMemory(m_wszSaveTitle, sizeof(m_wszSaveTitle)); - - if (m_pbThumbnail) - { - free(m_pbThumbnail); - m_pbThumbnail = nullptr; - m_dwThumbnailBytes = 0; - } -} - -C4JStorage::ESaveGameState CSaveGame::GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS *pSaveDetails, const bool), LPVOID lpParam, - char *pszSavePackName) -{ - if (!m_pSaveDetails) - { - m_pSaveDetails = new SAVE_DETAILS(); - memset(m_pSaveDetails, 0, sizeof(SAVE_DETAILS)); - } - - delete[] m_pSaveDetails->SaveInfoA; - m_pSaveDetails->SaveInfoA = nullptr; - m_pSaveDetails->iSaveC = 0; - - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - -#ifdef __linux__ - int resultCount = 0; - DIR *dir = opendir(gameHDDPath); - if (!dir) - { - - } - else - { - struct dirent *entry; - while ((entry = readdir(dir)) != NULL) - { - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; - char saveFilePath[512]; - snprintf(saveFilePath, sizeof(saveFilePath), "%s/%s/saveData.ms", gameHDDPath, entry->d_name); - struct stat st; - if (stat(saveFilePath, &st) == 0) - resultCount++; - } - closedir(dir); - } - - if (resultCount > 0) - { - m_pSaveDetails->SaveInfoA = new SAVE_INFO[resultCount]; - memset(m_pSaveDetails->SaveInfoA, 0, sizeof(SAVE_INFO) * resultCount); - m_pSaveDetails->iSaveC = 0; - - int i = 0; - dir = opendir(gameHDDPath); - if (dir) - { - struct dirent *entry; - while ((entry = readdir(dir)) != NULL) - { - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; - - char saveFilePath[512]; - snprintf(saveFilePath, sizeof(saveFilePath), "%s/%s/saveData.ms", gameHDDPath, entry->d_name); - struct stat stFile; - if (stat(saveFilePath, &stFile) != 0) - continue; - - strncpy(m_pSaveDetails->SaveInfoA[i].UTF8SaveFilename, entry->d_name, sizeof(m_pSaveDetails->SaveInfoA[i].UTF8SaveFilename) - 1); - - char saveDirPath[512]; - snprintf(saveDirPath, sizeof(saveDirPath), "%s/%s", gameHDDPath, entry->d_name); - - char titleBuf[MAX_DISPLAYNAME_LENGTH]; - if (LoadTitleFromFile(saveDirPath, titleBuf, sizeof(titleBuf))) - { - strncpy(m_pSaveDetails->SaveInfoA[i].UTF8SaveTitle, titleBuf, sizeof(m_pSaveDetails->SaveInfoA[i].UTF8SaveTitle) - 1); - } - else - { - strncpy(m_pSaveDetails->SaveInfoA[i].UTF8SaveTitle, entry->d_name, sizeof(m_pSaveDetails->SaveInfoA[i].UTF8SaveTitle) - 1); - } - - m_pSaveDetails->SaveInfoA[i].metaData.dataSize = (DWORD)stFile.st_size; - - char thumbFilePath[512]; - snprintf(thumbFilePath, sizeof(thumbFilePath), "%s/%s/saveThumbnail.png", gameHDDPath, entry->d_name); - struct stat stThumb; - if (stat(thumbFilePath, &stThumb) == 0) - { - m_pSaveDetails->SaveInfoA[i].metaData.thumbnailSize = (DWORD)stThumb.st_size; - } - - m_pSaveDetails->SaveInfoA[i].metaData.modifiedTime = stFile.st_mtime; - - i++; - m_pSaveDetails->iSaveC++; - } - closedir(dir); - } - } - -#else - WIN32_FIND_DATAA findFileData; - WIN32_FILE_ATTRIBUTE_DATA fileInfoBuffer; - - char searchPattern[280]; - sprintf_s(searchPattern, sizeof(searchPattern), "%s\\*", gameHDDPath); - - int resultCount = 0; - HANDLE h = FindFirstFileExA(searchPattern, FindExInfoStandard, &findFileData, FindExSearchLimitToDirectories, 0, 0); - if (h == INVALID_HANDLE_VALUE) - { - DWORD error = GetLastError(); - printf("Error finding save dirs: 0x%08x\n", error); - } - else - { - do - { - if ((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 && - strcmp(findFileData.cFileName, ".") != 0 && - strcmp(findFileData.cFileName, "..") != 0) - { - char saveFilePath[512]; - sprintf_s(saveFilePath, sizeof(saveFilePath), "%s\\%s\\saveData.ms", gameHDDPath, findFileData.cFileName); - if (GetFileAttributesA(saveFilePath) != INVALID_FILE_ATTRIBUTES) - { - resultCount++; - } - } - } while (FindNextFileA(h, &findFileData)); - FindClose(h); - } - - if (resultCount > 0) - { - m_pSaveDetails->SaveInfoA = new SAVE_INFO[resultCount]; - memset(m_pSaveDetails->SaveInfoA, 0, sizeof(SAVE_INFO) * resultCount); - - m_pSaveDetails->iSaveC = 0; - int i = 0; - HANDLE fi = FindFirstFileExA(searchPattern, FindExInfoStandard, &findFileData, FindExSearchLimitToDirectories, 0, 0); - if (fi != INVALID_HANDLE_VALUE) - { - do - { - if ((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 && - strcmp(findFileData.cFileName, ".") != 0 && - strcmp(findFileData.cFileName, "..") != 0) - { - char saveFilePath[512]; - sprintf_s(saveFilePath, sizeof(saveFilePath), "%s\\%s\\saveData.ms", gameHDDPath, findFileData.cFileName); - - if (GetFileAttributesA(saveFilePath) == INVALID_FILE_ATTRIBUTES) - continue; - - strcpy_s(m_pSaveDetails->SaveInfoA[i].UTF8SaveFilename, findFileData.cFileName); - - char saveDirPath[512]; - sprintf_s(saveDirPath, sizeof(saveDirPath), "%s\\%s", gameHDDPath, findFileData.cFileName); - - char titleBuf[MAX_DISPLAYNAME_LENGTH]; - if (LoadTitleFromFile(saveDirPath, titleBuf, sizeof(titleBuf))) - { - strcpy_s(m_pSaveDetails->SaveInfoA[i].UTF8SaveTitle, titleBuf); - } - else - { - strcpy_s(m_pSaveDetails->SaveInfoA[i].UTF8SaveTitle, findFileData.cFileName); - } - - GetFileAttributesExA(saveFilePath, GetFileExInfoStandard, &fileInfoBuffer); - m_pSaveDetails->SaveInfoA[i].metaData.dataSize = fileInfoBuffer.nFileSizeLow; - - char thumbFilePath[512]; - sprintf_s(thumbFilePath, sizeof(thumbFilePath), "%s\\%s\\saveThumbnail.png", gameHDDPath, findFileData.cFileName); - WIN32_FILE_ATTRIBUTE_DATA thumbInfo; - if (GetFileAttributesExA(thumbFilePath, GetFileExInfoStandard, &thumbInfo)) - { - m_pSaveDetails->SaveInfoA[i].metaData.thumbnailSize = thumbInfo.nFileSizeLow; - } - - FILETIME ft = fileInfoBuffer.ftLastWriteTime; - ULARGE_INTEGER ull; - ull.LowPart = ft.dwLowDateTime; - ull.HighPart = ft.dwHighDateTime; - - m_pSaveDetails->SaveInfoA[i].metaData.modifiedTime = (time_t)((ull.QuadPart - 116444736000000000ULL) / 10000000ULL); - - i++; - m_pSaveDetails->iSaveC++; - } - } while (FindNextFileA(fi, &findFileData)); - FindClose(fi); - } - } -#endif - - m_bHasSaveDetails = true; - if (Func) - { - Func(lpParam, m_pSaveDetails, true); - } - - return C4JStorage::ESaveGame_Idle; -} - -PSAVE_DETAILS CSaveGame::ReturnSavesInfo() -{ - if (m_bHasSaveDetails) - return m_pSaveDetails; - else - return nullptr; -} - -void CSaveGame::ClearSavesInfo() -{ - m_bHasSaveDetails = false; - if (m_pSaveDetails) - { - if (m_pSaveDetails->SaveInfoA) - { - delete[] m_pSaveDetails->SaveInfoA; - m_pSaveDetails->SaveInfoA = nullptr; - m_pSaveDetails->iSaveC = 0; - } - delete m_pSaveDetails; - m_pSaveDetails = 0; - } -} - -C4JStorage::ESaveGameState CSaveGame::LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo, - int (*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), LPVOID lpParam) -{ - PBYTE pbThumbnail = nullptr; - DWORD dwThumbnailBytes = 0; - - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - - char thumbPath[512]; -#ifdef __linux__ - snprintf(thumbPath, sizeof(thumbPath), "%s/%s/saveThumbnail.png", gameHDDPath, pSaveInfo->UTF8SaveFilename); - - int fd = open(thumbPath, O_RDONLY); - if (fd >= 0) - { - struct stat st; - if (fstat(fd, &st) == 0 && st.st_size > 0) - { - pbThumbnail = (PBYTE)malloc(st.st_size); - if (pbThumbnail) - { - ssize_t bytesRead = read(fd, pbThumbnail, st.st_size); - if (bytesRead == st.st_size) - { - dwThumbnailBytes = (DWORD)st.st_size; - } - else - { - free(pbThumbnail); - pbThumbnail = nullptr; - } - } - } - close(fd); - } -#else - sprintf_s(thumbPath, sizeof(thumbPath), "%s\\%s\\saveThumbnail.png", gameHDDPath, pSaveInfo->UTF8SaveFilename); - - HANDLE h = CreateFileA(thumbPath, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (h != INVALID_HANDLE_VALUE) - { - DWORD fileSize = GetFileSize(h, NULL); - if (fileSize != 0 && fileSize != INVALID_FILE_SIZE) - { - pbThumbnail = (PBYTE)malloc(fileSize); - if (pbThumbnail) - { - DWORD bytesRead = 0; - if (ReadFile(h, pbThumbnail, fileSize, &bytesRead, 0) && bytesRead == fileSize) - { - dwThumbnailBytes = fileSize; - } - else - { - free(pbThumbnail); - pbThumbnail = nullptr; - } - } - } - CloseHandle(h); - } -#endif - - Func(lpParam, pbThumbnail, dwThumbnailBytes); - - if (pbThumbnail) - { - free(pbThumbnail); - } - - return C4JStorage::ESaveGame_GetSaveThumbnail; -} - -C4JStorage::ESaveGameState CSaveGame::LoadSaveData(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, const bool, const bool), LPVOID lpParam) -{ - SetSaveUniqueFilename(pSaveInfo->UTF8SaveFilename); - - if (m_pSaveData) - { - free(m_pSaveData); - m_pSaveData = nullptr; - } - - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - -#ifdef __linux__ - char saveDirPath[512]; - snprintf(saveDirPath, sizeof(saveDirPath), "%s/%s", gameHDDPath, m_szSaveUniqueName); - - char titleBuf[MAX_DISPLAYNAME_LENGTH]; - if (LoadTitleFromFile(saveDirPath, titleBuf, sizeof(titleBuf))) - { - mbstowcs(m_wszSaveTitle, titleBuf, MAX_DISPLAYNAME_LENGTH); - } - - char fileName[512]; - snprintf(fileName, sizeof(fileName), "%s/saveData.ms", saveDirPath); - - struct stat stFile; - if (stat(fileName, &stFile) != 0) - { - if (Func) Func(lpParam, 0, false); - return C4JStorage::ESaveGame_Idle; - } - - m_uiSaveSize = (unsigned int)stFile.st_size; - m_pSaveData = malloc(m_uiSaveSize); - - int fd = open(fileName, O_RDONLY); - bool success = false; - if (fd >= 0) - { - ssize_t bytesRead = read(fd, m_pSaveData, m_uiSaveSize); - close(fd); - success = (bytesRead == (ssize_t)m_uiSaveSize); - } - - if (!success && m_pSaveData) - { - free(m_pSaveData); - m_pSaveData = nullptr; - m_uiSaveSize = 0; - } - -#else - char saveDirPath[512]; - sprintf_s(saveDirPath, sizeof(saveDirPath), "%s\\%s", gameHDDPath, m_szSaveUniqueName); - - char titleBuf[MAX_DISPLAYNAME_LENGTH]; - if (LoadTitleFromFile(saveDirPath, titleBuf, sizeof(titleBuf))) - { - MultiByteToWideChar(CP_UTF8, 0, titleBuf, -1, m_wszSaveTitle, MAX_DISPLAYNAME_LENGTH); - } - - char fileName[512]; - sprintf_s(fileName, sizeof(fileName), "%s\\saveData.ms", saveDirPath); - - WIN32_FILE_ATTRIBUTE_DATA fileInfo; - if (!GetFileAttributesExA(fileName, GetFileExInfoStandard, &fileInfo)) - { - if (Func) Func(lpParam, 0, false); - return C4JStorage::ESaveGame_Idle; - } - - m_uiSaveSize = fileInfo.nFileSizeLow; - m_pSaveData = malloc(m_uiSaveSize); - - HANDLE h = CreateFileA(fileName, GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - - bool success = false; - if (h != INVALID_HANDLE_VALUE) - { - DWORD bytesRead = 0; - BOOL res = ReadFile(h, m_pSaveData, m_uiSaveSize, &bytesRead, 0); - _ASSERT(res && bytesRead == m_uiSaveSize); - CloseHandle(h); - success = (res && bytesRead == m_uiSaveSize); - } - - if (!success && m_pSaveData) - { - free(m_pSaveData); - m_pSaveData = nullptr; - m_uiSaveSize = 0; - } -#endif - - if (Func) - { - Func(lpParam, 0, success); - } - - return C4JStorage::ESaveGame_Idle; -} - -unsigned int CSaveGame::GetSaveSize() -{ - return m_uiSaveSize; -} - -void CSaveGame::GetSaveData(void *pvData, unsigned int *puiBytes) -{ - if (pvData) - { - memmove(pvData, m_pSaveData, m_uiSaveSize); - *puiBytes = m_uiSaveSize; - } - else - { - *puiBytes = 0; - } -} - -// @Patoke add -bool CSaveGame::GetSaveUniqueNumber(INT *piVal) -{ - if (m_szSaveUniqueName[0] == '\0') - { - return 0; - } - int year, month, day, hour, minute; - sscanf(&m_szSaveUniqueName[4], "%02d%02d%02d%02d%02d", &year, &month, &day, &hour, &minute); - *piVal = 2678400 * year + 86400 * month + 3600 * day + 60 * hour + minute; - return true; -} - -// @Patoke add -bool CSaveGame::GetSaveUniqueFilename(char *pszName) -{ - if (m_szSaveUniqueName[0] == '\0') - { - return false; - } - memset(pszName, 0, 14); - for (int i = 0; i < 12; i++) - { - pszName[i] = m_szSaveUniqueName[i + 2]; - } - return true; -} - -void CSaveGame::SetSaveTitle(LPCWSTR pwchDefaultSaveName) -{ - if (m_szSaveUniqueName[0] == '\0') - { - CreateSaveUniqueName(); - } - wcscpy_s(m_wszSaveTitle, MAX_DISPLAYNAME_LENGTH, pwchDefaultSaveName); -} - -LPCWSTR CSaveGame::GetSaveTitle() -{ - return m_wszSaveTitle; -} - -PVOID CSaveGame::AllocateSaveData(unsigned int uiBytes) -{ - free(m_pSaveData); - - m_pSaveData = malloc(uiBytes); - if (m_pSaveData) - { - m_uiSaveSize = uiBytes; - } - - return m_pSaveData; -} - -// https://github.com/LCEMP/LCEMP -void CSaveGame::SetSaveImages(PBYTE pbThumbnail, DWORD dwThumbnailBytes, PBYTE pbImage, DWORD dwImageBytes, PBYTE pbTextData, DWORD dwTextDataBytes) -{ - if (m_pbThumbnail) - { - free(m_pbThumbnail); - m_pbThumbnail = nullptr; - m_dwThumbnailBytes = 0; - } - - - if (pbThumbnail && dwThumbnailBytes > 0) - { - const DWORD kInsertOffset = 33; // end of PNG sig + IHDR - - if (pbTextData && dwTextDataBytes > 0 && dwThumbnailBytes > kInsertOffset) - { - const DWORD chunkOverhead = 4 + 4 + 4; - const DWORD chunkTotal = chunkOverhead + dwTextDataBytes; - const DWORD newSize = dwThumbnailBytes + chunkTotal; - - m_pbThumbnail = (PBYTE)malloc(newSize); - if (m_pbThumbnail) - { - memcpy(m_pbThumbnail, pbThumbnail, kInsertOffset); - - PBYTE p = m_pbThumbnail + kInsertOffset; - - *(unsigned int *)p = WriteBE32(dwTextDataBytes); - p += 4; - - p[0] = 't'; p[1] = 'E'; p[2] = 'X'; p[3] = 't'; - p += 4; - - memcpy(p, pbTextData, dwTextDataBytes); - p += dwTextDataBytes; - - unsigned long crc = PngCrc32(m_pbThumbnail + kInsertOffset + 4, - 4 + dwTextDataBytes); - *(unsigned int *)p = WriteBE32((unsigned int)crc); - - memcpy(m_pbThumbnail + kInsertOffset + chunkTotal, - pbThumbnail + kInsertOffset, - dwThumbnailBytes - kInsertOffset); - - m_dwThumbnailBytes = newSize; - } - } - else - { - m_pbThumbnail = (PBYTE)malloc(dwThumbnailBytes); - if (m_pbThumbnail) - { - memcpy(m_pbThumbnail, pbThumbnail, dwThumbnailBytes); - m_dwThumbnailBytes = dwThumbnailBytes; - } - } - } -} - -// https://github.com/LCEMP/LCEMP -C4JStorage::ESaveGameState CSaveGame::SaveSaveData(int (*Func)(LPVOID, const bool), LPVOID lpParam) -{ - if (!m_pSaveData || m_uiSaveSize == 0) - { - if (Func) Func(lpParam, false); - return C4JStorage::ESaveGame_Idle; - } - - if (m_szSaveUniqueName[0] == '\0') - { - CreateSaveUniqueName(); - } - - if (!m_pbThumbnail || m_dwThumbnailBytes == 0) - { - PBYTE pbRuntimeThumbnail = nullptr; - DWORD dwRuntimeThumbnailBytes = 0; - app.GetSaveThumbnail(&pbRuntimeThumbnail, &dwRuntimeThumbnailBytes); - - if (pbRuntimeThumbnail && dwRuntimeThumbnailBytes > 0) - { - m_pbThumbnail = pbRuntimeThumbnail; - m_dwThumbnailBytes = dwRuntimeThumbnailBytes; - } - else if (m_pbDefaultThumbnail && m_dwDefaultThumbnailBytes > 0) - { - m_pbThumbnail = (PBYTE)malloc(m_dwDefaultThumbnailBytes); - if (m_pbThumbnail) - { - memcpy(m_pbThumbnail, m_pbDefaultThumbnail, m_dwDefaultThumbnailBytes); - m_dwThumbnailBytes = m_dwDefaultThumbnailBytes; - } - } - } - - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - -#ifdef __linux__ - char saveDirPath[512]; - snprintf(saveDirPath, sizeof(saveDirPath), "%s/%s", gameHDDPath, m_szSaveUniqueName); - mkdir(saveDirPath, 0755); - - char saveFilePath[512]; - snprintf(saveFilePath, sizeof(saveFilePath), "%s/saveData.ms", saveDirPath); - - int fd = open(saveFilePath, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd < 0) - { - if (Func) Func(lpParam, false); - return C4JStorage::ESaveGame_Idle; - } - - ssize_t bytesWritten = write(fd, m_pSaveData, m_uiSaveSize); - close(fd); - - SaveTitleFile(saveDirPath); - - if (m_pbThumbnail && m_dwThumbnailBytes > 0) - { - char thumbPath[512]; - snprintf(thumbPath, sizeof(thumbPath), "%s/saveThumbnail.png", saveDirPath); - - int tfd = open(thumbPath, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (tfd >= 0) - { - write(tfd, m_pbThumbnail, m_dwThumbnailBytes); - close(tfd); - } - - free(m_pbThumbnail); - m_pbThumbnail = nullptr; - m_dwThumbnailBytes = 0; - } - - bool success = (bytesWritten == (ssize_t)m_uiSaveSize); -#else - char saveDirPath[512]; - sprintf_s(saveDirPath, sizeof(saveDirPath), "%s\\%s", gameHDDPath, m_szSaveUniqueName); - CreateDirectoryA(saveDirPath, 0); - - char saveFilePath[512]; - sprintf_s(saveFilePath, sizeof(saveFilePath), "%s\\saveData.ms", saveDirPath); - - HANDLE h = CreateFileA(saveFilePath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (h == INVALID_HANDLE_VALUE) - { - if (Func) Func(lpParam, false); - return C4JStorage::ESaveGame_Idle; - } - - DWORD bytesWritten = 0; - BOOL res = WriteFile(h, m_pSaveData, m_uiSaveSize, &bytesWritten, 0); - CloseHandle(h); - - SaveTitleFile(saveDirPath); - - if (m_pbThumbnail && m_dwThumbnailBytes > 0) - { - char thumbPath[512]; - sprintf_s(thumbPath, sizeof(thumbPath), "%s\\saveThumbnail.png", saveDirPath); - - HANDLE hThumb = CreateFileA(thumbPath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (hThumb != INVALID_HANDLE_VALUE) - { - DWORD thumbWritten = 0; - WriteFile(hThumb, m_pbThumbnail, m_dwThumbnailBytes, &thumbWritten, 0); - CloseHandle(hThumb); - } - - free(m_pbThumbnail); - m_pbThumbnail = nullptr; - m_dwThumbnailBytes = 0; - } - - bool success = (res && bytesWritten == m_uiSaveSize); -#endif - - if (Func) Func(lpParam, success); - - return C4JStorage::ESaveGame_Idle; -} - -C4JStorage::ESaveGameState CSaveGame::DeleteSaveData(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, const bool), LPVOID lpParam) -{ - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - -#ifdef __linux__ - char saveDirPath[512]; - snprintf(saveDirPath, sizeof(saveDirPath), "%s/%s", gameHDDPath, pSaveInfo->UTF8SaveFilename); - - DIR *dir = opendir(saveDirPath); - if (dir) - { - struct dirent *entry; - while ((entry = readdir(dir)) != NULL) - { - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; - char filePath[512]; - snprintf(filePath, sizeof(filePath), "%s/%s", saveDirPath, entry->d_name); - unlink(filePath); - } - closedir(dir); - } - - rmdir(saveDirPath); - - struct stat st; - bool success = (stat(saveDirPath, &st) != 0); -#else - char saveDirPath[512]; - sprintf_s(saveDirPath, sizeof(saveDirPath), "%s\\%s", gameHDDPath, pSaveInfo->UTF8SaveFilename); - - char searchPattern[512]; - sprintf_s(searchPattern, sizeof(searchPattern), "%s\\*", saveDirPath); - - WIN32_FIND_DATAA findData; - HANDLE hFind = FindFirstFileA(searchPattern, &findData); - if (hFind != INVALID_HANDLE_VALUE) - { - do - { - if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - char filePath[512]; - sprintf_s(filePath, sizeof(filePath), "%s\\%s", saveDirPath, findData.cFileName); - DeleteFileA(filePath); - } - } while (FindNextFileA(hFind, &findData)); - FindClose(hFind); - } - - RemoveDirectoryA(saveDirPath); - - bool success = (GetFileAttributesA(saveDirPath) == INVALID_FILE_ATTRIBUTES); -#endif - - if (Func) Func(lpParam, success); - - return C4JStorage::ESaveGame_Idle; -} - -C4JStorage::ESaveGameState CSaveGame::DoesSaveExist(bool *pbExists) -{ - if (m_szSaveUniqueName[0] == '\0') - { - *pbExists = false; - return C4JStorage::ESaveGame_Idle; - } - - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - - char saveFilePath[512]; -#ifdef __linux__ - snprintf(saveFilePath, sizeof(saveFilePath), "%s/%s/saveData.ms", gameHDDPath, m_szSaveUniqueName); - struct stat st; - *pbExists = (stat(saveFilePath, &st) == 0); -#else - sprintf_s(saveFilePath, sizeof(saveFilePath), "%s\\%s\\saveData.ms", gameHDDPath, m_szSaveUniqueName); - *pbExists = (GetFileAttributesA(saveFilePath) != INVALID_FILE_ATTRIBUTES); -#endif - return C4JStorage::ESaveGame_Idle; -} - -void CSaveGame::CopySaveDataToNewSave(PBYTE pbThumbnail, DWORD cbThumbnail, WCHAR *wchNewName, int (*Func)(LPVOID lpParam, bool), LPVOID lpParam) -{ - char oldUniqueName[32]; - strcpy_s(oldUniqueName, m_szSaveUniqueName); - - CreateSaveUniqueName(); - - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - -#ifdef __linux__ - char newSaveDirPath[512]; - snprintf(newSaveDirPath, sizeof(newSaveDirPath), "%s/%s", gameHDDPath, m_szSaveUniqueName); - mkdir(newSaveDirPath, 0755); - - char oldSaveFile[512], newSaveFile[512]; - snprintf(oldSaveFile, sizeof(oldSaveFile), "%s/%s/saveData.ms", gameHDDPath, oldUniqueName); - snprintf(newSaveFile, sizeof(newSaveFile), "%s/saveData.ms", newSaveDirPath); - - { - int sfd = open(oldSaveFile, O_RDONLY); - int dfd = open(newSaveFile, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (sfd >= 0 && dfd >= 0) - { - char buf[8192]; - ssize_t n; - while ((n = read(sfd, buf, sizeof(buf))) > 0) write(dfd, buf, n); - } - if (sfd >= 0) close(sfd); - if (dfd >= 0) close(dfd); - } - - char oldThumbFile[512], newThumbFile[512]; - snprintf(oldThumbFile, sizeof(oldThumbFile), "%s/%s/saveThumbnail.png", gameHDDPath, oldUniqueName); - snprintf(newThumbFile, sizeof(newThumbFile), "%s/saveThumbnail.png", newSaveDirPath); - - { - int sfd = open(oldThumbFile, O_RDONLY); - int dfd = open(newThumbFile, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (sfd >= 0 && dfd >= 0) - { - char buf[8192]; - ssize_t n; - while ((n = read(sfd, buf, sizeof(buf))) > 0) write(dfd, buf, n); - } - if (sfd >= 0) close(sfd); - if (dfd >= 0) close(dfd); - } - - if (pbThumbnail && cbThumbnail > 0) - { - int tfd = open(newThumbFile, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (tfd >= 0) - { - write(tfd, pbThumbnail, cbThumbnail); - close(tfd); - } - } - - if (wchNewName) - { - wcscpy_s(m_wszSaveTitle, MAX_DISPLAYNAME_LENGTH, wchNewName); - } - SaveTitleFile(newSaveDirPath); - - struct stat st; - bool success = (stat(newSaveFile, &st) == 0); -#else - char newSaveDirPath[512]; - sprintf_s(newSaveDirPath, sizeof(newSaveDirPath), "%s\\%s", gameHDDPath, m_szSaveUniqueName); - CreateDirectoryA(newSaveDirPath, 0); - - char oldSaveFile[512], newSaveFile[512]; - sprintf_s(oldSaveFile, sizeof(oldSaveFile), "%s\\%s\\saveData.ms", gameHDDPath, oldUniqueName); - sprintf_s(newSaveFile, sizeof(newSaveFile), "%s\\saveData.ms", newSaveDirPath); - CopyFileA(oldSaveFile, newSaveFile, FALSE); - - char oldThumbFile[512], newThumbFile[512]; - sprintf_s(oldThumbFile, sizeof(oldThumbFile), "%s\\%s\\saveThumbnail.png", gameHDDPath, oldUniqueName); - sprintf_s(newThumbFile, sizeof(newThumbFile), "%s\\saveThumbnail.png", newSaveDirPath); - CopyFileA(oldThumbFile, newThumbFile, FALSE); - - if (pbThumbnail && cbThumbnail > 0) - { - HANDLE hThumb = CreateFileA(newThumbFile, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (hThumb != INVALID_HANDLE_VALUE) - { - DWORD thumbWritten = 0; - WriteFile(hThumb, pbThumbnail, cbThumbnail, &thumbWritten, 0); - CloseHandle(hThumb); - } - } - - if (wchNewName) - { - wcscpy_s(m_wszSaveTitle, MAX_DISPLAYNAME_LENGTH, wchNewName); - } - SaveTitleFile(newSaveDirPath); - - bool success = (GetFileAttributesA(newSaveFile) != INVALID_FILE_ATTRIBUTES); -#endif - if (Func) Func(lpParam, success); -} - -void CSaveGame::SetSaveUniqueFilename(char *szFilename) -{ - strcpy_s(m_szSaveUniqueName, szFilename); -} - -void CSaveGame::CreateSaveUniqueName(void) -{ -#ifdef __linux__ - time_t now = time(NULL); - struct tm t; - gmtime_r(&now, &t); - snprintf(m_szSaveUniqueName, sizeof(m_szSaveUniqueName), "%4d%02d%02d%02d%02d%02d", - t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); -#else - _SYSTEMTIME UTCSysTime; - GetSystemTime(&UTCSysTime); - - sprintf_s(m_szSaveUniqueName, sizeof(m_szSaveUniqueName), "%4d%02d%02d%02d%02d%02d", UTCSysTime.wYear, UTCSysTime.wMonth, UTCSysTime.wDay, - UTCSysTime.wHour, UTCSysTime.wMinute, UTCSysTime.wSecond); -#endif -} - -void CSaveGame::SaveTitleFile(const char *saveDirPath) -{ - if (m_wszSaveTitle[0] == L'\0') - return; - - char titleFilePath[512]; -#ifdef __linux__ - snprintf(titleFilePath, sizeof(titleFilePath), "%s/saveTitle.txt", saveDirPath); - - char utf8Title[MAX_DISPLAYNAME_LENGTH * 3]; - int len = (int)wcstombs(utf8Title, m_wszSaveTitle, sizeof(utf8Title)); - - if (len > 0) - { - int fd = open(titleFilePath, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd >= 0) - { - write(fd, utf8Title, len); - close(fd); - } - } -#else - sprintf_s(titleFilePath, sizeof(titleFilePath), "%s\\saveTitle.txt", saveDirPath); - - char utf8Title[MAX_DISPLAYNAME_LENGTH * 3]; - int len = WideCharToMultiByte(CP_UTF8, 0, m_wszSaveTitle, -1, utf8Title, sizeof(utf8Title), NULL, NULL); - - if (len > 0) - { - HANDLE h = CreateFileA(titleFilePath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (h != INVALID_HANDLE_VALUE) - { - DWORD bytesWritten = 0; - WriteFile(h, utf8Title, len - 1, &bytesWritten, 0); - CloseHandle(h); - } - } -#endif -} - -bool CSaveGame::LoadTitleFromFile(const char *saveDirPath, char *outUTF8Title, int maxLen) -{ - char titleFilePath[512]; -#ifdef __linux__ - snprintf(titleFilePath, sizeof(titleFilePath), "%s/saveTitle.txt", saveDirPath); - - int fd = open(titleFilePath, O_RDONLY); - if (fd < 0) - return false; - - struct stat st; - if (fstat(fd, &st) != 0 || st.st_size == 0 || st.st_size >= maxLen) - { - close(fd); - return false; - } - - ssize_t bytesRead = read(fd, outUTF8Title, st.st_size); - close(fd); - - if (bytesRead > 0) - { - outUTF8Title[bytesRead] = '\0'; - return true; - } - return false; -#else - sprintf_s(titleFilePath, sizeof(titleFilePath), "%s\\saveTitle.txt", saveDirPath); - - HANDLE h = CreateFileA(titleFilePath, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (h == INVALID_HANDLE_VALUE) - return false; - - DWORD fileSize = GetFileSize(h, NULL); - if (fileSize == 0 || fileSize == INVALID_FILE_SIZE || fileSize >= (DWORD)maxLen) - { - CloseHandle(h); - return false; - } - - DWORD bytesRead = 0; - ReadFile(h, outUTF8Title, fileSize, &bytesRead, 0); - CloseHandle(h); - - if (bytesRead > 0) - { - outUTF8Title[bytesRead] = '\0'; - return true; - } - return false; -#endif -} - -void CSaveGame::SetDefaultImages(PBYTE pbOptionsImage, DWORD dwOptionsImageBytes, PBYTE pbSaveImage, DWORD dwSaveImageBytes, PBYTE pbSaveThumbnail, DWORD dwSaveThumbnailBytes) -{ - if (m_pbDefaultSaveImage) - { - free(m_pbDefaultSaveImage); - m_pbDefaultSaveImage = nullptr; - m_dwDefaultSaveImageBytes = 0; - } - if (pbSaveImage && dwSaveImageBytes > 0) - { - m_pbDefaultSaveImage = (PBYTE)malloc(dwSaveImageBytes); - if (m_pbDefaultSaveImage) - { - memcpy(m_pbDefaultSaveImage, pbSaveImage, dwSaveImageBytes); - m_dwDefaultSaveImageBytes = dwSaveImageBytes; - } - } - - if (m_pbDefaultThumbnail) - { - free(m_pbDefaultThumbnail); - m_pbDefaultThumbnail = nullptr; - m_dwDefaultThumbnailBytes = 0; - } - if (pbSaveThumbnail && dwSaveThumbnailBytes > 0) - { - m_pbDefaultThumbnail = (PBYTE)malloc(dwSaveThumbnailBytes); - if (m_pbDefaultThumbnail) - { - memcpy(m_pbDefaultThumbnail, pbSaveThumbnail, dwSaveThumbnailBytes); - m_dwDefaultThumbnailBytes = dwSaveThumbnailBytes; - } - } -} - -void CSaveGame::GetDefaultSaveImage(PBYTE *ppbSaveImage, DWORD *pdwSaveImageBytes) -{ - if (ppbSaveImage) *ppbSaveImage = m_pbDefaultSaveImage; - if (pdwSaveImageBytes) *pdwSaveImageBytes = m_dwDefaultSaveImageBytes; -} - -void CSaveGame::GetDefaultSaveThumbnail(PBYTE *ppbSaveThumbnail, DWORD *pdwSaveThumbnailBytes) -{ - if (ppbSaveThumbnail) *ppbSaveThumbnail = m_pbDefaultThumbnail; - if (pdwSaveThumbnailBytes) *pdwSaveThumbnailBytes = m_dwDefaultThumbnailBytes; -} - -C4JStorage::ESaveGameState CSaveGame::RenameSaveData(int iRenameIndex, uint16_t *pui16NewName, int (*Func)(LPVOID lpParam, const bool), LPVOID lpParam) -{ - bool bSuccess = false; - - if (m_pSaveDetails && iRenameIndex >= 0 && iRenameIndex < m_pSaveDetails->iSaveC && pui16NewName) - { - char gameHDDPath[256]; - GetGameHDDPath(gameHDDPath, sizeof(gameHDDPath)); - - wchar_t newTitle[MAX_DISPLAYNAME_LENGTH]; - int i = 0; - while (i < MAX_DISPLAYNAME_LENGTH - 1 && pui16NewName[i] != 0) - { - newTitle[i] = (wchar_t)pui16NewName[i]; - i++; - } - newTitle[i] = L'\0'; - -#ifdef __linux__ - char saveDirPath[512]; - snprintf(saveDirPath, sizeof(saveDirPath), "%s/%s", gameHDDPath, m_pSaveDetails->SaveInfoA[iRenameIndex].UTF8SaveFilename); - - char titleFilePath[512]; - snprintf(titleFilePath, sizeof(titleFilePath), "%s/saveTitle.txt", saveDirPath); - - char utf8Title[MAX_DISPLAYNAME_LENGTH * 3]; - int len = (int)wcstombs(utf8Title, newTitle, sizeof(utf8Title)); - - if (len > 0) - { - int fd = open(titleFilePath, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd >= 0) - { - write(fd, utf8Title, len); - close(fd); - - wcstombs(m_pSaveDetails->SaveInfoA[iRenameIndex].UTF8SaveTitle, newTitle, MAX_DISPLAYNAME_LENGTH); - bSuccess = true; - } - } -#else - char saveDirPath[512]; - sprintf_s(saveDirPath, sizeof(saveDirPath), "%s\\%s", gameHDDPath, m_pSaveDetails->SaveInfoA[iRenameIndex].UTF8SaveFilename); - - char titleFilePath[512]; - sprintf_s(titleFilePath, sizeof(titleFilePath), "%s\\saveTitle.txt", saveDirPath); - - char utf8Title[MAX_DISPLAYNAME_LENGTH * 3]; - int len = WideCharToMultiByte(CP_UTF8, 0, newTitle, -1, utf8Title, sizeof(utf8Title), NULL, NULL); - - if (len > 0) - { - HANDLE h = CreateFileA(titleFilePath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (h != INVALID_HANDLE_VALUE) - { - DWORD bytesWritten = 0; - WriteFile(h, utf8Title, len - 1, &bytesWritten, 0); - CloseHandle(h); - - WideCharToMultiByte(CP_UTF8, 0, newTitle, -1, m_pSaveDetails->SaveInfoA[iRenameIndex].UTF8SaveTitle, MAX_DISPLAYNAME_LENGTH, NULL, NULL); - bSuccess = true; - } - } -#endif - } - - if (Func) Func(lpParam, bSuccess); - return C4JStorage::ESaveGame_Rename; -} diff --git a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_SaveGame.h b/Minecraft.Client/Platform_Libs/Dev/Storage/STO_SaveGame.h deleted file mode 100644 index 66b405ad..00000000 --- a/Minecraft.Client/Platform_Libs/Dev/Storage/STO_SaveGame.h +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once -/* -MIT License - -Copyright (c) 2026 Patoke - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "../../../Windows64/4JLibs/inc/4J_Storage.h" - -class CSaveGame -{ -public: - CSaveGame(); - void SetSaveDisabled(bool bDisable); - bool GetSaveDisabled(void); - - void ResetSaveData(); - C4JStorage::ESaveGameState GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS *pSaveDetails, const bool), LPVOID lpParam, - char *pszSavePackName); - PSAVE_DETAILS ReturnSavesInfo(); - void ClearSavesInfo(); - C4JStorage::ESaveGameState LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), - LPVOID lpParam); - C4JStorage::ESaveGameState LoadSaveData(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, const bool, const bool), LPVOID lpParam); - unsigned int GetSaveSize(); - void GetSaveData(void *pvData, unsigned int *puiBytes); - bool GetSaveUniqueNumber(INT *piVal); - bool GetSaveUniqueFilename(char *pszName); - void SetSaveTitle(LPCWSTR pwchDefaultSaveName); - PVOID AllocateSaveData(unsigned int uiBytes); - void SetSaveImages(PBYTE pbThumbnail, DWORD dwThumbnailBytes, PBYTE pbImage, DWORD dwImageBytes, PBYTE pbTextData, DWORD dwTextDataBytes); - C4JStorage::ESaveGameState SaveSaveData(int (*Func)(LPVOID, const bool), LPVOID lpParam); - void CopySaveDataToNewSave(PBYTE pbThumbnail, DWORD cbThumbnail, WCHAR *wchNewName, int (*Func)(LPVOID lpParam, bool), LPVOID lpParam); - C4JStorage::ESaveGameState DeleteSaveData(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, const bool), LPVOID lpParam); - C4JStorage::ESaveGameState RenameSaveData(int iRenameIndex, uint16_t *pui16NewName, int (*Func)(LPVOID lpParam, const bool), LPVOID lpParam); - C4JStorage::ESaveGameState DoesSaveExist(bool *pbExists); - void SetSaveUniqueFilename(char *szFilename); - LPCWSTR GetSaveTitle(); - - void CreateSaveUniqueName(void); - void SaveTitleFile(const char *saveDirPath); - static bool LoadTitleFromFile(const char *saveDirPath, char *outUTF8Title, int maxLen); - - void SetDefaultImages(PBYTE pbOptionsImage, DWORD dwOptionsImageBytes, PBYTE pbSaveImage, DWORD dwSaveImageBytes, PBYTE pbSaveThumbnail, DWORD dwSaveThumbnailBytes); - void GetDefaultSaveImage(PBYTE *ppbSaveImage, DWORD *pdwSaveImageBytes); - void GetDefaultSaveThumbnail(PBYTE *ppbSaveThumbnail, DWORD *pdwSaveThumbnailBytes); - - void *m_pSaveData; - unsigned int m_uiSaveSize; - char m_szSaveUniqueName[32]; - wchar_t m_wszSaveTitle[MAX_DISPLAYNAME_LENGTH]; - bool m_bIsSafeDisabled; - bool m_bHasSaveDetails; - SAVE_DETAILS *m_pSaveDetails; - - PBYTE m_pbThumbnail; - DWORD m_dwThumbnailBytes; - - PBYTE m_pbDefaultThumbnail; - DWORD m_dwDefaultThumbnailBytes; - PBYTE m_pbDefaultSaveImage; - DWORD m_dwDefaultSaveImageBytes; -}; diff --git a/Minecraft.Client/cmake/sources/Windows.cmake b/Minecraft.Client/cmake/sources/Windows.cmake index 5b37211c..63bd2309 100644 --- a/Minecraft.Client/cmake/sources/Windows.cmake +++ b/Minecraft.Client/cmake/sources/Windows.cmake @@ -347,15 +347,15 @@ set(_MINECRAFT_CLIENT_WINDOWS_SOURCE_FILES source_group("Source Files" FILES ${_MINECRAFT_CLIENT_WINDOWS_SOURCE_FILES}) set(_MINECRAFT_CLIENT_WINDOWS_PLATFORM_LIBS_DEV_STORAGE - "${CMAKE_CURRENT_SOURCE_DIR}/Platform_Libs/Dev/Storage/4J_Storage.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/Platform_Libs/Dev/Storage/STO_DLC.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/Platform_Libs/Dev/Storage/STO_DLC.h" - "${CMAKE_CURRENT_SOURCE_DIR}/Platform_Libs/Dev/Storage/STO_Main.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/Platform_Libs/Dev/Storage/STO_Main.h" - "${CMAKE_CURRENT_SOURCE_DIR}/Platform_Libs/Dev/Storage/STO_SaveGame.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/Platform_Libs/Dev/Storage/STO_SaveGame.h" + "${CMAKE_CURRENT_SOURCE_DIR}/Windows64/4JLibs/impls/Windows_Libs/Storage/src/4J_Storage.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/Windows64/4JLibs/impls/Windows_Libs/Storage/src/STO_DLC.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/Windows64/4JLibs/impls/Windows_Libs/Storage/inc/STO_DLC.h" + "${CMAKE_CURRENT_SOURCE_DIR}/Windows64/4JLibs/impls/Windows_Libs/Storage/src/STO_Main.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/Windows64/4JLibs/impls/Windows_Libs/Storage/inc/STO_Main.h" + "${CMAKE_CURRENT_SOURCE_DIR}/Windows64/4JLibs/impls/Windows_Libs/Storage/src/STO_SaveGame.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/Windows64/4JLibs/impls/Windows_Libs/Storage/inc/STO_SaveGame.h" ) -source_group("Platform_Libs/Dev/Storage" FILES ${_MINECRAFT_CLIENT_WINDOWS_PLATFORM_LIBS_DEV_STORAGE}) +source_group("Windows64/4JLibs/impls/Windows_Libs/Storage/src" FILES ${_MINECRAFT_CLIENT_WINDOWS_PLATFORM_LIBS_DEV_STORAGE}) set(_MINECRAFT_CLIENT_WINDOWS_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/Xbox/MinecraftWindows.rc"