mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/GabsPuNs-MinecraftConsoles.git
synced 2026-06-20 01:15:33 +00:00
Changes
This commit is contained in:
@@ -31,39 +31,15 @@
|
||||
|
||||
static wstring ReadLevelNameFromSaveFile(const wstring& filePath)
|
||||
{
|
||||
// Check for a worldname.txt sidecar written by the rename feature first
|
||||
size_t slashPos = filePath.rfind(L'\\');
|
||||
if (slashPos != wstring::npos)
|
||||
{
|
||||
wstring sidecarPath = filePath.substr(0, slashPos + 1) + L"worldname.txt";
|
||||
FILE *fr = nullptr;
|
||||
if (_wfopen_s(&fr, sidecarPath.c_str(), L"r") == 0 && fr)
|
||||
{
|
||||
char buf[128] = {};
|
||||
if (fgets(buf, sizeof(buf), fr))
|
||||
{
|
||||
int len = static_cast<int>(strlen(buf));
|
||||
while (len > 0 && (buf[len-1] == '\n' || buf[len-1] == '\r' || buf[len-1] == ' '))
|
||||
buf[--len] = '\0';
|
||||
fclose(fr);
|
||||
if (len > 0)
|
||||
{
|
||||
wchar_t wbuf[128] = {};
|
||||
mbstowcs(wbuf, buf, 127);
|
||||
return wstring(wbuf);
|
||||
}
|
||||
}
|
||||
else fclose(fr);
|
||||
}
|
||||
}
|
||||
|
||||
HANDLE hFile = CreateFileW(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
|
||||
if (hFile == INVALID_HANDLE_VALUE) return L"";
|
||||
|
||||
DWORD fileSize = GetFileSize(hFile, nullptr);
|
||||
if (fileSize < 12 || fileSize == INVALID_FILE_SIZE) { CloseHandle(hFile); return L""; }
|
||||
if (fileSize < 12 || fileSize == INVALID_FILE_SIZE) {
|
||||
CloseHandle(hFile); return L"";
|
||||
}
|
||||
|
||||
unsigned char *rawData = new unsigned char[fileSize];
|
||||
unsigned char* rawData = new unsigned char[fileSize];
|
||||
DWORD bytesRead = 0;
|
||||
if (!ReadFile(hFile, rawData, fileSize, &bytesRead, nullptr) || bytesRead != fileSize)
|
||||
{
|
||||
@@ -73,8 +49,8 @@ static wstring ReadLevelNameFromSaveFile(const wstring& filePath)
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
|
||||
unsigned char *saveData = nullptr;
|
||||
unsigned int saveSize = 0;
|
||||
unsigned char* saveData = nullptr;
|
||||
unsigned int saveSize = 0;
|
||||
bool freeSaveData = false;
|
||||
|
||||
if (*(unsigned int*)rawData == 0)
|
||||
@@ -88,7 +64,7 @@ static wstring ReadLevelNameFromSaveFile(const wstring& filePath)
|
||||
}
|
||||
saveData = new unsigned char[decompSize];
|
||||
Compression::getCompression()->Decompress(saveData, &decompSize, rawData + 8, fileSize - 8);
|
||||
saveSize = decompSize;
|
||||
saveSize = decompSize;
|
||||
freeSaveData = true;
|
||||
}
|
||||
else
|
||||
@@ -101,13 +77,13 @@ static wstring ReadLevelNameFromSaveFile(const wstring& filePath)
|
||||
if (saveSize >= 12)
|
||||
{
|
||||
unsigned int headerOffset = *(unsigned int*)saveData;
|
||||
unsigned int numEntries = *(unsigned int*)(saveData + 4);
|
||||
unsigned int numEntries = *(unsigned int*)(saveData + 4);
|
||||
const unsigned int entrySize = sizeof(FileEntrySaveData);
|
||||
|
||||
if (headerOffset < saveSize && numEntries > 0 && numEntries < 10000 &&
|
||||
headerOffset + numEntries * entrySize <= saveSize)
|
||||
{
|
||||
FileEntrySaveData *table = (FileEntrySaveData *)(saveData + headerOffset);
|
||||
FileEntrySaveData* table = (FileEntrySaveData*)(saveData + headerOffset);
|
||||
for (unsigned int i = 0; i < numEntries; i++)
|
||||
{
|
||||
if (wcscmp(table[i].filename, L"level.dat") == 0)
|
||||
@@ -117,12 +93,12 @@ static wstring ReadLevelNameFromSaveFile(const wstring& filePath)
|
||||
if (off >= 12 && off + len <= saveSize && len > 0 && len < 4 * 1024 * 1024)
|
||||
{
|
||||
byteArray ba;
|
||||
ba.data = (BYTE*)(saveData + off);
|
||||
ba.data = (BYTE*)(saveData + off);
|
||||
ba.length = len;
|
||||
CompoundTag *root = NbtIo::decompress(ba);
|
||||
CompoundTag* root = NbtIo::decompress(ba);
|
||||
if (root != nullptr)
|
||||
{
|
||||
CompoundTag *dataTag = root->getCompound(L"Data");
|
||||
CompoundTag* dataTag = root->getCompound(L"Data");
|
||||
if (dataTag != nullptr)
|
||||
result = dataTag->getString(L"LevelName");
|
||||
delete root;
|
||||
@@ -136,8 +112,8 @@ static wstring ReadLevelNameFromSaveFile(const wstring& filePath)
|
||||
|
||||
if (freeSaveData) delete[] saveData;
|
||||
delete[] rawData;
|
||||
// "world" is the engine default - it means no real name was ever set,
|
||||
// so return empty to let the caller fall back to the save filename (timestamp).
|
||||
// "world" is the engine default — it means no real name was ever set, so
|
||||
// return empty to let the caller fall back to the save filename (timestamp).
|
||||
if (result == L"world") result = L"";
|
||||
return result;
|
||||
}
|
||||
@@ -762,7 +738,7 @@ void UIScene_LoadCreateJoinMenu::tick()
|
||||
int origIdx = sortedIdx[i];
|
||||
wchar_t wFilename[MAX_SAVEFILENAME_LENGTH];
|
||||
ZeroMemory(wFilename, sizeof(wFilename));
|
||||
mbstowcs(wFilename, m_pSaveDetails->SaveInfoA[origIdx].UTF8SaveFilename, MAX_SAVEFILENAME_LENGTH - 1);
|
||||
mbstowcs_s(nullptr, wFilename, MAX_SAVEFILENAME_LENGTH, m_pSaveDetails->SaveInfoA[origIdx].UTF8SaveFilename, _TRUNCATE);
|
||||
wstring filePath = wstring(L"Windows64\\GameHDD\\") + wstring(wFilename) + wstring(L"\\saveData.ms");
|
||||
|
||||
HANDLE hFile = CreateFileW(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
|
||||
@@ -791,7 +767,7 @@ void UIScene_LoadCreateJoinMenu::tick()
|
||||
if (!levelName.empty())
|
||||
{
|
||||
m_buttonListSaves.addItem(levelName, wstring(L""));
|
||||
wcstombs(m_saveDetails[i].UTF8SaveName, levelName.c_str(), 127);
|
||||
wcstombs_s(nullptr, m_saveDetails[i].UTF8SaveName, 127, levelName.c_str(), _TRUNCATE);
|
||||
m_saveDetails[i].UTF8SaveName[127] = '\0';
|
||||
}
|
||||
else
|
||||
@@ -1441,11 +1417,11 @@ int UIScene_LoadCreateJoinMenu::KeyboardCompleteWorldNameCallback(LPVOID lpParam
|
||||
|
||||
// Convert to narrow for storage and in-memory update
|
||||
char narrowName[128] = {};
|
||||
wcstombs(narrowName, wNewName, 127);
|
||||
wcstombs_s(nullptr, narrowName, sizeof(narrowName), wNewName, _TRUNCATE);
|
||||
|
||||
// Build the sidecar path: Windows64\GameHDD\{folder}\worldname.txt
|
||||
wchar_t wFilename[MAX_SAVEFILENAME_LENGTH] = {};
|
||||
mbstowcs(wFilename, pClass->m_saveDetails[listPos].UTF8SaveFilename, MAX_SAVEFILENAME_LENGTH - 1);
|
||||
mbstowcs_s(nullptr, wFilename, MAX_SAVEFILENAME_LENGTH, pClass->m_saveDetails[listPos].UTF8SaveFilename, _TRUNCATE);
|
||||
wstring sidecarPath = wstring(L"Windows64\\GameHDD\\") + wstring(wFilename) + wstring(L"\\worldname.txt");
|
||||
|
||||
FILE *fw = nullptr;
|
||||
@@ -1975,7 +1951,7 @@ void UIScene_LoadCreateJoinMenu::UpdateGamesList()
|
||||
|
||||
vector<FriendSessionInfo*>* newSessions = g_NetworkManager.GetSessionList( m_iPad, 1, m_bShowingPartyGamesOnly );
|
||||
|
||||
if (m_currentSessions != NULL && m_currentSessions->size() == newSessions->size())
|
||||
if (m_currentSessions != nullptr && m_currentSessions->size() == newSessions->size())
|
||||
{
|
||||
bool same = true;
|
||||
for (size_t i = 0; i < newSessions->size(); i++)
|
||||
@@ -2524,7 +2500,7 @@ int UIScene_LoadCreateJoinMenu::SaveOptionsDialogReturned(void *pParam,int iPad,
|
||||
#ifdef _WINDOWS64
|
||||
{
|
||||
wchar_t wSaveName[128];
|
||||
ZeroMemory(wSaveName, 128 * sizeof(wchar_t));
|
||||
ZeroMemory(wSaveName, sizeof(wSaveName));
|
||||
mbstowcs_s(nullptr, wSaveName, 128, pClass->m_saveDetails[pClass->m_iSaveListIndex - pClass->m_iDefaultButtonsC].UTF8SaveName, _TRUNCATE);
|
||||
UIKeyboardInitData kbData;
|
||||
kbData.title = app.GetString(IDS_RENAME_WORLD_TITLE);
|
||||
@@ -2656,7 +2632,7 @@ int UIScene_LoadCreateJoinMenu::MustSignInReturnedTexturePack(void *pParam,bool
|
||||
strncpy(chKeyName, pSONYDLCInfo->chDLCKeyname, 16);
|
||||
|
||||
#ifdef __ORBIS__
|
||||
strcpy(chName, chKeyName);
|
||||
strcpy_s(chName, chKeyName);
|
||||
#else
|
||||
sprintf_s(chName,"%s-%s",app.GetCommerceCategory(),chKeyName);
|
||||
#endif
|
||||
@@ -2719,7 +2695,7 @@ int UIScene_LoadCreateJoinMenu::TexturePackDialogReturned(void *pParam,int iPad,
|
||||
strncpy(chKeyName, pSONYDLCInfo->chDLCKeyname, 16);
|
||||
|
||||
#ifdef __ORBIS__
|
||||
strcpy(chName, chKeyName);
|
||||
strcpy_s(chName, chKeyName);
|
||||
#else
|
||||
sprintf_s(chName,"%s-%s",app.GetCommerceCategory(),chKeyName);
|
||||
#endif
|
||||
@@ -4252,9 +4228,9 @@ void UIScene_LoadCreateJoinMenu::AppendServerToFile(const wstring& ip, const wst
|
||||
char narrowIP[256] = {};
|
||||
char narrowPort[16] = {};
|
||||
char narrowName[256] = {};
|
||||
wcstombs(narrowIP, ip.c_str(), sizeof(narrowIP) - 1);
|
||||
wcstombs(narrowPort, port.c_str(), sizeof(narrowPort) - 1);
|
||||
wcstombs(narrowName, name.c_str(), sizeof(narrowName) - 1);
|
||||
wcstombs_s(nullptr, narrowIP, sizeof(narrowIP), ip.c_str(), _TRUNCATE);
|
||||
wcstombs_s(nullptr, narrowPort, sizeof(narrowPort), port.c_str(), _TRUNCATE);
|
||||
wcstombs_s(nullptr, narrowName, sizeof(narrowName), name.c_str(), _TRUNCATE);
|
||||
|
||||
uint16_t portNum = static_cast<uint16_t>(atoi(narrowPort));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user