diff --git a/Minecraft.Client/Common/Audio/SoundEngine.cpp b/Minecraft.Client/Common/Audio/SoundEngine.cpp index bfff29e7..0ecb3a93 100644 --- a/Minecraft.Client/Common/Audio/SoundEngine.cpp +++ b/Minecraft.Client/Common/Audio/SoundEngine.cpp @@ -36,6 +36,7 @@ #if defined _XBOX SoundEngine::SoundEngine() {} + void SoundEngine::init(Options *pOptions) {} void SoundEngine::tick(shared_ptr *players, float a) {} void SoundEngine::destroy() {} @@ -171,6 +172,7 @@ void SoundEngine::init(Options* pOptions) if (ma_engine_init(&m_engineConfig, &m_engine) != MA_SUCCESS) { + destroy(); app.DebugPrintf("Failed to initialize miniaudio engine\n"); return; } @@ -471,15 +473,41 @@ SoundEngine::SoundEngine() #endif } -void SoundEngine::destroy() {} +SoundEngine::~SoundEngine() +{ + destroy(); +} + +void SoundEngine::destroy() +{ + for (auto s : m_activeSounds) + { + ma_sound_uninit(&s->sound); + delete s; + } + m_activeSounds.clear(); + + ma_engine_uninit(&m_engine); + + if (random) + { + delete random; + random = nullptr; + } + if (m_bHeardTrackA) + { + delete [] m_bHeardTrackA; + m_bHeardTrackA = nullptr; + } +} #ifdef _DEBUG void SoundEngine::GetSoundName(char *szSoundName,int iSound) { - strcpy((char *)szSoundName,"Minecraft/"); + strcpy_s(szSoundName, 256, "Minecraft/"); wstring name = wchSoundNames[iSound]; char *SoundName = (char *)ConvertSoundPathToName(name); - strcat((char *)szSoundName,SoundName); + strcat_s(szSoundName, 256, SoundName); } #endif @@ -498,12 +526,12 @@ void SoundEngine::play(int iSound, float x, float y, float z, float volume, floa return; } - strcpy((char*)szSoundName, "Minecraft/"); + strcpy_s((char *)szSoundName, _countof(szSoundName), "Minecraft/"); wstring name = wchSoundNames[iSound]; char* SoundName = (char*)ConvertSoundPathToName(name); - strcat((char*)szSoundName, SoundName); + strcat_s((char *)szSoundName, _countof(szSoundName), SoundName); app.DebugPrintf(6, "PlaySound - %d - %s - %s (%f %f %f, vol %f, pitch %f)\n", @@ -538,7 +566,7 @@ void SoundEngine::play(int iSound, float x, float y, float z, float volume, floa for (size_t extIdx = 0; extIdx < extCount; extIdx++) { - for (size_t i = 1; i < 32; i++) + for (size_t i = 1; i < 32; i++) { char numberedPath[256]; sprintf_s(numberedPath, "%s%d%s", basePath, i, extensions[extIdx]); @@ -626,17 +654,17 @@ void SoundEngine::playUI(int iSound, float volume, float pitch) if (iSound >= eSFX_MAX) { - strcpy((char*)szSoundName, "Minecraft/"); + strcpy_s((char *)szSoundName, _countof(szSoundName), "Minecraft/"); name = wchSoundNames[iSound]; } else { - strcpy((char*)szSoundName, "Minecraft/UI/"); + strcpy_s((char *)szSoundName, _countof(szSoundName), "Minecraft/UI/"); name = wchUISoundNames[iSound]; } char* SoundName = (char*)ConvertSoundPathToName(name); - strcat((char*)szSoundName, SoundName); + strcat_s((char *)szSoundName, _countof(szSoundName), SoundName); char basePath[256]; sprintf_s(basePath, "Windows64Media/Sound/Minecraft/UI/%s", ConvertSoundPathToName(name)); @@ -1062,7 +1090,7 @@ void SoundEngine::playMusicUpdate() #endif #else - strcpy((char *)m_szStreamName,m_szMusicPath); + strcpy_s((char *)m_szStreamName, _countof(m_szStreamName), m_szMusicPath); #endif // are we using a mash-up pack? //if(pMinecraft && !pMinecraft->skins->isUsingDefaultSkin() && pMinecraft->skins->getSelected()->hasAudio()) @@ -1093,7 +1121,7 @@ void SoundEngine::playMusicUpdate() #else wstring &wstrSoundName=dlcAudioFile->GetSoundName(m_musicID); char szName[255]; - wcstombs(szName,wstrSoundName.c_str(),255); + wcstombs_s(nullptr, szName, sizeof(szName), wstrSoundName.c_str(), _TRUNCATE); #if defined __PS3__ || defined __ORBIS__ || defined __PSVITA__ string strFile="TPACK:/Data/" + string(szName) + ".wav"; @@ -1101,7 +1129,7 @@ void SoundEngine::playMusicUpdate() string strFile="TPACK:\\Data\\" + string(szName) + ".wav"; #endif std::string mountedPath = StorageManager.GetMountedPath(strFile); - strcpy(m_szStreamName,mountedPath.c_str()); + strcpy_s(m_szStreamName,mountedPath.c_str()); #endif } else @@ -1111,9 +1139,9 @@ void SoundEngine::playMusicUpdate() m_StreamingAudioInfo.bIs3D=true; // Need to adjust to index into the cds in the game's m_szStreamFileA - strcat((char *)m_szStreamName,"cds/"); - strcat((char *)m_szStreamName,m_szStreamFileA[m_musicID-m_iStream_CD_1+eStream_CD_1]); - strcat((char *)m_szStreamName,".wav"); + strcat_s((char *)m_szStreamName, _countof(m_szStreamName), "cds/"); + strcat_s((char *)m_szStreamName, _countof(m_szStreamName), m_szStreamFileA[m_musicID - m_iStream_CD_1 + eStream_CD_1]); + strcat_s((char *)m_szStreamName, _countof(m_szStreamName), ".wav"); } } else @@ -1123,16 +1151,16 @@ void SoundEngine::playMusicUpdate() if(app.GetBootedFromDiscPatch() && (m_musicIDeXuid=eTempXuid; - wcsncpy( pMojangData->wchSkin, pSkin, MAX_CAPENAME_SIZE); - wcsncpy( pMojangData->wchCape, pCape, MAX_CAPENAME_SIZE); + wcsncpy_s( pMojangData->wchSkin, pSkin, MAX_CAPENAME_SIZE); + wcsncpy_s( pMojangData->wchCape, pCape, MAX_CAPENAME_SIZE); MojangData[xuid]=pMojangData; } @@ -7248,7 +7248,7 @@ HRESULT CMinecraftApp::RegisterDLCData(char *pchDLCName, unsigned int uiSortInde pDLCData->iConfig = app.GetiConfigFromName(pchDLCName); pDLCData->uiSortIndex=uiSortIndex; pDLCData->eDLCType = app.GetDLCTypeFromName(pchDLCName); - strcpy(pDLCData->chImageURL,pchImageURL); + strcpy_s(pDLCData->chImageURL,pchImageURL); //bool bIsTrialDLC = app.GetTrialFromName(pchDLCName); switch(pDLCData->eDLCType) @@ -7256,14 +7256,14 @@ HRESULT CMinecraftApp::RegisterDLCData(char *pchDLCName, unsigned int uiSortInde case e_DLC_TexturePacks: { char *pchName=(char *)mi_malloc(strlen(pchDLCName)+1); - strcpy(pchName,pchDLCName); + strcpy_s(pchName,pchDLCName); DLCTextures_PackID[pDLCData->iConfig]=pchName; } break; case e_DLC_MashupPacks: { char *pchName=(char *)mi_malloc(strlen(pchDLCName)+1); - strcpy(pchName,pchDLCName); + strcpy_s(pchName,pchDLCName); DLCTextures_PackID[pDLCData->iConfig]=pchName; } break; @@ -7754,7 +7754,7 @@ void CMinecraftApp::AddLevelToBannedLevelList(int iPad, PlayerUID xuid, char *ps #else memcpy(&pBannedListData->xuid, &xuid, sizeof(PlayerUID)); #endif - strcpy(pBannedListData->pszLevelName,pszLevelName); + strcpy_s(pBannedListData->pszLevelName,pszLevelName); m_vBannedListA[iPad]->push_back(pBannedListData); if (bWriteToTMS) @@ -7874,7 +7874,7 @@ void CMinecraftApp::AddCreditText(LPCWSTR lpStr) pCreditStruct->m_iStringID[0]=NO_TRANSLATED_STRING; pCreditStruct->m_iStringID[1]=NO_TRANSLATED_STRING; pCreditStruct->m_Text=new WCHAR [wcslen(lpStr)+1]; - wcscpy((WCHAR *)pCreditStruct->m_Text,lpStr); + wcscpy_s((WCHAR*)pCreditStruct->m_Text, wcslen(lpStr) + 1, lpStr); vDLCCredits.push_back(pCreditStruct); } @@ -8481,7 +8481,7 @@ unsigned int CMinecraftApp::CreateImageTextData(PBYTE bTextMetadata, int64_t see int iTextMetadataBytes = 0; if(hasSeed) { - strcpy((char *)bTextMetadata,"4J_SEED"); + strcpy_s((char*)bTextMetadata, 8, "4J_SEED"); _i64toa_s(seed,(char *)&bTextMetadata[8],42,10); // get the length @@ -8491,7 +8491,7 @@ unsigned int CMinecraftApp::CreateImageTextData(PBYTE bTextMetadata, int64_t see } // Save the host options that this world was last played with - strcpy((char *)&bTextMetadata[iTextMetadataBytes],"4J_HOSTOPTIONS"); + strcpy_s((char *)&bTextMetadata[iTextMetadataBytes], 15, "4J_HOSTOPTIONS"); _itoa_s(uiHostOptions,(char *)&bTextMetadata[iTextMetadataBytes+15],9,16); iTextMetadataBytes += 15; @@ -8499,7 +8499,7 @@ unsigned int CMinecraftApp::CreateImageTextData(PBYTE bTextMetadata, int64_t see ++iTextMetadataBytes; // Add a null terminator at the end of the host options value // Save the texture pack id - strcpy((char *)&bTextMetadata[iTextMetadataBytes],"4J_TEXTUREPACK"); + strcpy_s((char *)&bTextMetadata[iTextMetadataBytes], 15, "4J_TEXTUREPACK"); _itoa_s(uiTexturePackId,(char *)&bTextMetadata[iTextMetadataBytes+15],9,16); iTextMetadataBytes += 15; @@ -9027,7 +9027,7 @@ int CMinecraftApp::TMSPPFileReturned(LPVOID pParam,int iPad,int iUserData,C4JSto { #if defined(_XBOX) || defined(_WINDOWS64) char szFile[MAX_TMSFILENAME_SIZE]; - wcstombs(szFile,pCurrent->wchFilename,MAX_TMSFILENAME_SIZE); + wcstombs_s(nullptr, szFile, MAX_TMSFILENAME_SIZE, pCurrent->wchFilename, _TRUNCATE); if(strcmp(szFilename,szFile)==0) @@ -9540,7 +9540,7 @@ int CMinecraftApp::TexturePackDialogReturned(void* pParam, int iPad, C4JStorage: strncpy(chKeyName, pSONYDLCInfo->chDLCKeyname, 16); #ifdef __ORBIS__ - strcpy(chName, chKeyName); + strcpy_s(chName, chKeyName); #else sprintf_s(chName, "%s-%s", app.GetCommerceCategory(), chKeyName); #endif diff --git a/Minecraft.Client/Common/DLC/DLCSkinFile.cpp b/Minecraft.Client/Common/DLC/DLCSkinFile.cpp index f7ef2ad0..dbcc93bb 100644 --- a/Minecraft.Client/Common/DLC/DLCSkinFile.cpp +++ b/Minecraft.Client/Common/DLC/DLCSkinFile.cpp @@ -116,7 +116,7 @@ void DLCSkinFile::addParameter(DLCManager::EDLCParameterType type, const wstring #ifdef __PS3__ // 4J Stu - The Xbox version used swscanf_s which isn't available in GCC. - swscanf(value.c_str(), L"%10ls%f%f%f%f%f%f%f%f", wchBodyPart, + swscanf_s(value.c_str(), L"%10ls%f%f%f%f%f%f%f%f", wchBodyPart, #else swscanf_s(value.c_str(), L"%9ls%f%f%f%f%f%f%f%f", wchBodyPart,10, #endif @@ -161,7 +161,7 @@ void DLCSkinFile::addParameter(DLCManager::EDLCParameterType type, const wstring case DLCManager::e_DLCParamType_Anim: #ifdef __PS3__ // 4J Stu - The Xbox version used swscanf_s which isn't available in GCC. - swscanf(value.c_str(), L"%X", &m_uiAnimOverrideBitmask); + swscanf_s(value.c_str(), L"%X", &m_uiAnimOverrideBitmask); #else swscanf_s(value.c_str(), L"%X", &m_uiAnimOverrideBitmask,sizeof(unsigned int)); #endif diff --git a/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp index c5dc0554..bf0e04ef 100644 --- a/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp @@ -292,7 +292,7 @@ void UIScene_AbstractContainerMenu::customDraw(IggyCustomDrawCallbackRegion *reg } else { - swscanf(static_cast(region->name),L"slot_%d",&slotId); + swscanf_s(static_cast(region->name),L"slot_%d",&slotId); if (slotId == -1) { app.DebugPrintf("This is not the control we are looking for\n"); diff --git a/Minecraft.Client/Common/UI/UIScene_BeaconMenu.cpp b/Minecraft.Client/Common/UI/UIScene_BeaconMenu.cpp index 64e12373..82447371 100644 --- a/Minecraft.Client/Common/UI/UIScene_BeaconMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_BeaconMenu.cpp @@ -328,7 +328,7 @@ void UIScene_BeaconMenu::customDraw(IggyCustomDrawCallbackRegion *region) shared_ptr item = nullptr; int slotId = -1; - swscanf(static_cast(region->name),L"slot_%d",&slotId); + swscanf_s(static_cast(region->name),L"slot_%d",&slotId); if(slotId >= 0 && slotId >= m_menu->getSize() ) { diff --git a/Minecraft.Client/Common/UI/UIScene_CraftingMenu.cpp b/Minecraft.Client/Common/UI/UIScene_CraftingMenu.cpp index 16b63c4c..d2ac375a 100644 --- a/Minecraft.Client/Common/UI/UIScene_CraftingMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_CraftingMenu.cpp @@ -532,7 +532,7 @@ void UIScene_CraftingMenu::customDraw(IggyCustomDrawCallbackRegion *region) float alpha = 1.0f; bool decorations = true; bool inventoryItem = false; - swscanf(static_cast(region->name),L"slot_%d",&slotId); + swscanf_s(static_cast(region->name),L"slot_%d",&slotId); if (slotId == -1) { app.DebugPrintf("This is not the control we are looking for\n"); diff --git a/Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp b/Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp index 9bc52f21..206286c4 100644 --- a/Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp +++ b/Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp @@ -142,7 +142,7 @@ void UIScene_DebugOverlay::customDraw(IggyCustomDrawCallbackRegion *region) if(pMinecraft->localplayers[m_iPad] == nullptr || pMinecraft->localgameModes[m_iPad] == nullptr) return; int itemId = -1; - swscanf(static_cast(region->name),L"item_%d",&itemId); + swscanf_s(static_cast(region->name),L"item_%d",&itemId); if (itemId == -1 || itemId > Item::ITEM_NUM_COUNT || Item::items[itemId] == nullptr) { app.DebugPrintf("This is not the control we are looking for\n"); diff --git a/Minecraft.Client/Common/UI/UIScene_EnchantingMenu.cpp b/Minecraft.Client/Common/UI/UIScene_EnchantingMenu.cpp index f90c4b12..525be3d0 100644 --- a/Minecraft.Client/Common/UI/UIScene_EnchantingMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_EnchantingMenu.cpp @@ -264,7 +264,7 @@ void UIScene_EnchantingMenu::customDraw(IggyCustomDrawCallbackRegion *region) else { int slotId = -1; - swscanf(static_cast(region->name),L"slot_Button%d",&slotId); + swscanf_s(static_cast(region->name),L"slot_Button%d",&slotId); if(slotId >= 0) { // Setup GDraw, normal game render states and matrices diff --git a/Minecraft.Client/Common/UI/UIScene_HUD.cpp b/Minecraft.Client/Common/UI/UIScene_HUD.cpp index 71e1f687..b8c7dc0c 100644 --- a/Minecraft.Client/Common/UI/UIScene_HUD.cpp +++ b/Minecraft.Client/Common/UI/UIScene_HUD.cpp @@ -166,7 +166,7 @@ void UIScene_HUD::customDraw(IggyCustomDrawCallbackRegion *region) if(pMinecraft->localplayers[m_iPad] == nullptr || pMinecraft->localgameModes[m_iPad] == nullptr) return; int slot = -1; - swscanf(static_cast(region->name),L"slot_%d",&slot); + swscanf_s(static_cast(region->name),L"slot_%d",&slot); if (slot == -1) { app.DebugPrintf("This is not the control we are looking for\n"); diff --git a/Minecraft.Client/Common/UI/UIScene_JoinMenu.cpp b/Minecraft.Client/Common/UI/UIScene_JoinMenu.cpp index f152e78a..996e99aa 100644 --- a/Minecraft.Client/Common/UI/UIScene_JoinMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_JoinMenu.cpp @@ -817,7 +817,7 @@ int UIScene_JoinMenu::EditServerKeyboardCallback(LPVOID lpParam, bool bRes) wchar_t wDefaultName[64] = {}; if (pClass->m_selectedSession->displayLabel) - wcsncpy(wDefaultName, pClass->m_selectedSession->displayLabel, 63); + wcsncpy_s(wDefaultName, pClass->m_selectedSession->displayLabel, 63); UIKeyboardInitData kbData; kbData.title = L"Server Name"; diff --git a/Minecraft.Client/Common/UI/UIScene_LeaderboardsMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LeaderboardsMenu.cpp index 8eff769e..ec094ec7 100644 --- a/Minecraft.Client/Common/UI/UIScene_LeaderboardsMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LeaderboardsMenu.cpp @@ -964,7 +964,7 @@ int UIScene_LeaderboardsMenu::SetLeaderboardTitleIcons() void UIScene_LeaderboardsMenu::customDraw(IggyCustomDrawCallbackRegion *region) { int slotId = -1; - swscanf(static_cast(region->name),L"slot_%d",&slotId); + swscanf_s(static_cast(region->name),L"slot_%d",&slotId); if (slotId == -1) { //app.DebugPrintf("This is not the control we are looking for\n"); diff --git a/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenu.cpp index 3065d4c4..b1c36229 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenu.cpp @@ -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(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* 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(atoi(narrowPort)); diff --git a/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenuTest.cpp b/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenuTest.cpp index 6eadb7e9..b9addd61 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenuTest.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadCreateJoinMenuTest.cpp @@ -2658,7 +2658,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 @@ -2721,7 +2721,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 diff --git a/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp index d6d66e7e..3b00fa1d 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp @@ -208,7 +208,7 @@ UIScene_LoadMenu::UIScene_LoadMenu(int iPad, void *initData, UILayer *parentLaye else { -#if defined(__PS3__) || defined(__ORBIS__)|| defined(_DURANGO) || defined (__PSVITA__) || defined (_WINDOWS64) +#if defined(__PS3__) || defined(__ORBIS__)|| defined(_DURANGO) || defined (__PSVITA__) // convert to utf16 uint16_t u16Message[MAX_SAVEFILENAME_LENGTH]; size_t srclen,dstlen; @@ -228,46 +228,47 @@ UIScene_LoadMenu::UIScene_LoadMenu(int iPad, void *initData, UILayer *parentLaye } #endif m_thumbnailName = (wchar_t *)u16Message; -/* - if(params->saveDetails->pbThumbnailData) - { - m_pbThumbnailData = params->saveDetails->pbThumbnailData; - m_uiThumbnailSize = params->saveDetails->dwThumbnailSize; - m_bSaveThumbnailReady = true; - } - else -*/ - { - app.DebugPrintf("Requesting the save thumbnail\n"); - // set the save to load - PSAVE_DETAILS pSaveDetails=StorageManager.ReturnSavesInfo(); + app.DebugPrintf("Requesting the save thumbnail\n"); + // set the save to load + PSAVE_DETAILS pSaveDetails=StorageManager.ReturnSavesInfo(); #ifdef _DURANGO - // On Durango, we have an extra flag possible with LoadSaveDataThumbnail, which if true will force the loading of this thumbnail even if the save data isn't sync'd from - // the cloud at this stage. This could mean that there could be a pretty large delay before the callback happens, in this case. - C4JStorage::ESaveGameState eLoadStatus=StorageManager.LoadSaveDataThumbnail(&pSaveDetails->SaveInfoA[(int)m_iSaveGameInfoIndex],&LoadSaveDataThumbnailReturned,(LPVOID)GetCallbackUniqueId(),true); + // On Durango, we have an extra flag possible with LoadSaveDataThumbnail, which if true will force the loading of this thumbnail even if the save data isn't sync'd from + // the cloud at this stage. This could mean that there could be a pretty large delay before the callback happens, in this case. + C4JStorage::ESaveGameState eLoadStatus=StorageManager.LoadSaveDataThumbnail(&pSaveDetails->SaveInfoA[(int)m_iSaveGameInfoIndex],&LoadSaveDataThumbnailReturned,(LPVOID)GetCallbackUniqueId(),true); #else - C4JStorage::ESaveGameState eLoadStatus=StorageManager.LoadSaveDataThumbnail(&pSaveDetails->SaveInfoA[(int)m_iSaveGameInfoIndex],&LoadSaveDataThumbnailReturned,(LPVOID)GetCallbackUniqueId()); + C4JStorage::ESaveGameState eLoadStatus=StorageManager.LoadSaveDataThumbnail(&pSaveDetails->SaveInfoA[(int)m_iSaveGameInfoIndex],&LoadSaveDataThumbnailReturned,(LPVOID)GetCallbackUniqueId()); #endif - m_bShowTimer = true; - } + m_bShowTimer = true; + #if defined(_DURANGO) m_labelGameName.init(params->saveDetails->UTF16SaveName); #else - wchar_t wSaveName[128]; - ZeroMemory(wSaveName, 128 * sizeof(wchar_t) ); - mbstowcs(wSaveName, params->saveDetails->UTF8SaveName, strlen(params->saveDetails->UTF8SaveName)+1); // plus null + wchar_t wSaveName[128]; + ZeroMemory(wSaveName, sizeof(wSaveName) ); + mbstowcs_s(nullptr, wSaveName, 128, params->saveDetails->UTF8SaveName, _TRUNCATE); + m_labelGameName.init(wSaveName); #endif #endif #ifdef _WINDOWS64 - if (params->saveDetails != nullptr && params->saveDetails->UTF8SaveName[0] != '\0') - { - wchar_t wSaveName[128]; - ZeroMemory(wSaveName, sizeof(wSaveName)); - mbstowcs(wSaveName, params->saveDetails->UTF8SaveName, 127); - m_levelName = wstring(wSaveName); - m_labelGameName.init(m_levelName); - } + wchar_t wFilename[MAX_SAVEFILENAME_LENGTH] = {}; + mbstowcs_s(nullptr, wFilename, MAX_SAVEFILENAME_LENGTH, params->saveDetails->UTF8SaveFilename, _TRUNCATE); + m_thumbnailName = wstring(wFilename); + + app.DebugPrintf("Requesting the save thumbnail\n"); + // set the save to load + PSAVE_DETAILS pSaveDetails=StorageManager.ReturnSavesInfo(); + + C4JStorage::ESaveGameState eLoadStatus=StorageManager.LoadSaveDataThumbnail(&pSaveDetails->SaveInfoA[(int)m_iSaveGameInfoIndex],&LoadSaveDataThumbnailReturned,(LPVOID)GetCallbackUniqueId()); + + m_bShowTimer = true; + + wchar_t wSaveName[128]; + ZeroMemory(wSaveName, sizeof(wSaveName)); + mbstowcs_s(nullptr, wSaveName, 128, params->saveDetails->UTF8SaveName, _TRUNCATE); + + m_levelName = wstring(wSaveName); + m_labelGameName.init(m_levelName); #endif } diff --git a/Minecraft.Client/Common/UI/UIScene_PauseMenu.cpp b/Minecraft.Client/Common/UI/UIScene_PauseMenu.cpp index ab725b09..61267aab 100644 --- a/Minecraft.Client/Common/UI/UIScene_PauseMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_PauseMenu.cpp @@ -1221,7 +1221,7 @@ int UIScene_PauseMenu::WarningTrialTexturePackReturned(void *pParam,int iPad,C4J strncpy(chKeyName, pSONYDLCInfo->chDLCKeyname, 16); #ifdef __ORBIS__ - strcpy(chName, chKeyName); + strcpy_s(chName, chKeyName); #else sprintf_s(chName,"%s-%s",app.GetCommerceCategory(),chKeyName); #endif @@ -1298,7 +1298,7 @@ int UIScene_PauseMenu::BuyTexturePack_SignInReturned(void *pParam,bool bContinue strncpy(chKeyName, pSONYDLCInfo->chDLCKeyname, 16); #ifdef __ORBIS__ - strcpy(chName, chKeyName); + strcpy_s(chName, chKeyName); #else sprintf_s(chName,"%s-%s",app.GetCommerceCategory(),chKeyName); #endif diff --git a/Minecraft.Client/Common/UI/UIScene_SkinSelectMenu.cpp b/Minecraft.Client/Common/UI/UIScene_SkinSelectMenu.cpp index b309f907..35542577 100644 --- a/Minecraft.Client/Common/UI/UIScene_SkinSelectMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_SkinSelectMenu.cpp @@ -599,7 +599,7 @@ void UIScene_SkinSelectMenu::InputActionOK(unsigned int iPad) void UIScene_SkinSelectMenu::customDraw(IggyCustomDrawCallbackRegion *region) { int characterId = -1; - swscanf(static_cast(region->name),L"Character%d",&characterId); + swscanf_s(static_cast(region->name),L"Character%d",&characterId); if (characterId == -1) { app.DebugPrintf("Invalid character to render found\n"); @@ -1583,7 +1583,7 @@ int UIScene_SkinSelectMenu::UnlockSkinReturned(void *pParam,int iPad,C4JStorage: strncpy(chKeyName, pSONYDLCInfo->chDLCKeyname, 16); #ifdef __ORBIS__ - strcpy(chName, chKeyName); + strcpy_s(chName, chKeyName); #else sprintf_s(chName,"%s-%s",app.GetCommerceCategory(),chKeyName); #endif diff --git a/Minecraft.Client/Common/UI/UIScene_TradingMenu.cpp b/Minecraft.Client/Common/UI/UIScene_TradingMenu.cpp index bb9e30af..4bdf000a 100644 --- a/Minecraft.Client/Common/UI/UIScene_TradingMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_TradingMenu.cpp @@ -159,7 +159,7 @@ void UIScene_TradingMenu::customDraw(IggyCustomDrawCallbackRegion *region) shared_ptr item = nullptr; int slotId = -1; - swscanf(static_cast(region->name),L"slot_%d",&slotId); + swscanf_s(static_cast(region->name),L"slot_%d",&slotId); if(slotId < MerchantMenu::USE_ROW_SLOT_END) { diff --git a/Minecraft.Client/LevelRenderer.cpp b/Minecraft.Client/LevelRenderer.cpp index 73de2b98..5064ac64 100644 --- a/Minecraft.Client/LevelRenderer.cpp +++ b/Minecraft.Client/LevelRenderer.cpp @@ -3707,7 +3707,7 @@ void LevelRenderer::staticCtor() char threadName[256]; for(unsigned int i = 0; i < MAX_CHUNK_REBUILD_THREADS; ++i) { - sprintf_s(threadName,"Rebuild Chunk Thread %d\n",i); + sprintf_s(threadName, sizeof(threadName), "Rebuild Chunk Thread %d\n",i); rebuildThreads[i] = new C4JThread(rebuildChunkThreadProc,(void *)i,threadName); s_activationEventA[i] = new C4JThread::Event(); diff --git a/Minecraft.World/C4JThread.cpp b/Minecraft.World/C4JThread.cpp index b199ca9a..2c14f6ee 100644 --- a/Minecraft.World/C4JThread.cpp +++ b/Minecraft.World/C4JThread.cpp @@ -983,7 +983,7 @@ C4JThread::EventQueue::EventQueue( UpdateFunc* updateFunc, ThreadInitFunc thread { m_updateFunc = updateFunc; m_threadInitFunc = threadInitFunc; - strcpy(m_threadName, szThreadName); + strcpy_s(m_threadName, szThreadName); m_thread = nullptr; m_startEvent = nullptr; m_finishedEvent = nullptr; diff --git a/Minecraft.World/CompoundTag.h b/Minecraft.World/CompoundTag.h index 7e3293fa..8c6f94f9 100644 --- a/Minecraft.World/CompoundTag.h +++ b/Minecraft.World/CompoundTag.h @@ -237,7 +237,7 @@ public: out << prefix << "{" << endl; char *newPrefix = new char[ strlen(prefix) + 4 ]; - strcpy( newPrefix, prefix); + strcpy_s( newPrefix, prefix); strcat( newPrefix, " "); for( auto& it : tags ) diff --git a/Minecraft.World/DispenserTileEntity.cpp b/Minecraft.World/DispenserTileEntity.cpp index f6b3a78f..4b5a3338 100644 --- a/Minecraft.World/DispenserTileEntity.cpp +++ b/Minecraft.World/DispenserTileEntity.cpp @@ -132,7 +132,7 @@ void DispenserTileEntity::setItem(unsigned int slot, shared_ptr it int DispenserTileEntity::addItem(shared_ptr item) { - for (int i = 0; i < items.length; i++) + for (unsigned int i = 0; i < items.length; i++) { if (items[i] == nullptr || items[i]->id == 0) { diff --git a/Minecraft.World/File.cpp b/Minecraft.World/File.cpp index 3ca7e1b4..103c7083 100644 --- a/Minecraft.World/File.cpp +++ b/Minecraft.World/File.cpp @@ -286,10 +286,10 @@ std::vector *File::listFiles() const std::string mountedPath = StorageManager.GetMountedPath(lpFileName); if(mountedPath.length() > 0) { - strcpy(filePath, mountedPath.c_str()); + strcpy_s(filePath, mountedPath.c_str()); } else if(lpFileName[0] == '/') // already fully qualified path - strcpy(filePath, lpFileName ); + strcpy_s(filePath, lpFileName ); else sprintf_s(filePath,"%s/%s",getUsrDirPath(), lpFileName ); int fd; @@ -314,10 +314,10 @@ std::vector *File::listFiles() const std::string mountedPath = StorageManager.GetMountedPath(lpFileName); if(mountedPath.length() > 0) { - strcpy(filePath, mountedPath.c_str()); + strcpy_s(filePath, mountedPath.c_str()); } else if(lpFileName[0] == '/') // already fully qualified path - strcpy(filePath, lpFileName ); + strcpy_s(filePath, lpFileName ); else sprintf_s(filePath,"%s/%s",getUsrDirPath(), lpFileName ); @@ -429,10 +429,10 @@ std::vector *File::listFiles(FileFilter *filter) const std::string mountedPath = StorageManager.GetMountedPath(lpFileName); if(mountedPath.length() > 0) { - strcpy(filePath, mountedPath.c_str()); + strcpy_s(filePath, mountedPath.c_str()); } else if(lpFileName[0] == '/') // already fully qualified path - strcpy(filePath, lpFileName ); + strcpy_s(filePath, lpFileName ); else sprintf_s(filePath,"%s/%s",getUsrDirPath(), lpFileName ); int fd; @@ -531,10 +531,10 @@ int64_t File::length() std::string mountedPath = StorageManager.GetMountedPath(lpFileName); if(mountedPath.length() > 0) { - strcpy(filePath, mountedPath.c_str()); + strcpy_s(filePath, mountedPath.c_str()); } else if(lpFileName[0] == '/') // already fully qualified path - strcpy(filePath, lpFileName ); + strcpy_s(filePath, lpFileName ); else sprintf_s(filePath,"%s/%s",getUsrDirPath(), lpFileName ); @@ -567,10 +567,10 @@ int64_t File::length() std::string mountedPath = StorageManager.GetMountedPath(lpFileName); if(mountedPath.length() > 0) { - strcpy(filePath, mountedPath.c_str()); + strcpy_s(filePath, mountedPath.c_str()); } else if(lpFileName[0] == '/') // already fully qualified path - strcpy(filePath, lpFileName ); + strcpy_s(filePath, lpFileName ); else sprintf_s(filePath,"%s/%s",getUsrDirPath(), lpFileName ); diff --git a/Minecraft.World/FileHeader.cpp b/Minecraft.World/FileHeader.cpp index a7bdbc90..c9982fa5 100644 --- a/Minecraft.World/FileHeader.cpp +++ b/Minecraft.World/FileHeader.cpp @@ -533,7 +533,7 @@ vector *FileHeader::getDatFilesWithOnlineID(const PlayerUID& pUID) // we're looking for the online name from the pUID in these types of filenames - // P_5e7ff8372ea9_00000004_Mark_4J wchar_t onlineIDW[64]; - mbstowcs(onlineIDW, pUID.getOnlineID(), 64); + mbstowcs_s(nullptr, onlineIDW, 64, pUID.getOnlineID(), _TRUNCATE); vector *files = nullptr; int onlineIDSize = wcslen(onlineIDW); @@ -659,7 +659,6 @@ vector *FileHeader::getDatFilesWithPrimaryUser() ByteOrder FileHeader::getEndian( ESavePlatform plat ) { - ByteOrder platEndian; switch(plat) { case SAVE_FILE_PLATFORM_X360: diff --git a/Minecraft.World/HopperMenu.cpp b/Minecraft.World/HopperMenu.cpp index 996651c6..5b61dc33 100644 --- a/Minecraft.World/HopperMenu.cpp +++ b/Minecraft.World/HopperMenu.cpp @@ -8,7 +8,7 @@ HopperMenu::HopperMenu(shared_ptr inventory, shared_ptr ho hopper->startOpen(); int yo = 51; - for (int x = 0; x < hopper->getContainerSize(); x++) + for (unsigned int x = 0; x < hopper->getContainerSize(); x++) { addSlot(new Slot(hopper, x, 44 + x * 18, 20)); } @@ -42,7 +42,7 @@ shared_ptr HopperMenu::quickMoveStack(shared_ptr player, i if (slotIndex < hopper->getContainerSize()) { - if (!moveItemStackTo(stack, hopper->getContainerSize(), slots.size(), true)) + if (!moveItemStackTo(stack, hopper->getContainerSize(), (int)slots.size(), true)) { return nullptr; } diff --git a/Minecraft.World/HopperTileEntity.cpp b/Minecraft.World/HopperTileEntity.cpp index dffe107b..49f7dbe2 100644 --- a/Minecraft.World/HopperTileEntity.cpp +++ b/Minecraft.World/HopperTileEntity.cpp @@ -197,7 +197,7 @@ bool HopperTileEntity::ejectItems() return false; } - for (int slot = 0; slot < getContainerSize(); slot++) + for (unsigned int slot = 0; slot < getContainerSize(); slot++) { if (getItem(slot) == nullptr) continue; diff --git a/Minecraft.World/Inventory.cpp b/Minecraft.World/Inventory.cpp index 558483d2..2e79f05c 100644 --- a/Minecraft.World/Inventory.cpp +++ b/Minecraft.World/Inventory.cpp @@ -76,7 +76,7 @@ int Inventory::getSlot(int tileId) int Inventory::getSlot(int tileId, int data) { - for (int i = 0; i < items.length; i++) + for (unsigned int i = 0; i < items.length; i++) { if (items[i] != nullptr && items[i]->id == tileId && items[i]->getAuxValue() == data) return i; } @@ -157,7 +157,7 @@ void Inventory::swapPaint(int wheel) int Inventory::clearInventory(int id, int data) { int count = 0; - for (int i = 0; i < items.length; i++) + for (unsigned int i = 0; i < items.length; i++) { shared_ptr item = items[i]; if (item == nullptr) continue; @@ -167,7 +167,7 @@ int Inventory::clearInventory(int id, int data) count += item->count; items[i] = nullptr; } - for (int i = 0; i < armor.length; i++) + for (unsigned int i = 0; i < armor.length; i++) { shared_ptr item = armor[i]; if (item == nullptr) continue; @@ -768,11 +768,11 @@ bool Inventory::canPlaceItem(int slot, shared_ptr item) void Inventory::replaceWith(shared_ptr other) { - for (int i = 0; i < items.length; i++) + for (unsigned int i = 0; i < items.length; i++) { items[i] = ItemInstance::clone(other->items[i]); } - for (int i = 0; i < armor.length; i++) + for (unsigned int i = 0; i < armor.length; i++) { armor[i] = ItemInstance::clone(other->armor[i]); } diff --git a/Minecraft.World/ListTag.h b/Minecraft.World/ListTag.h index b84326a0..bf4c085d 100644 --- a/Minecraft.World/ListTag.h +++ b/Minecraft.World/ListTag.h @@ -57,7 +57,7 @@ public: out << prefix << L"{" << endl; char *newPrefix = new char[ strlen(prefix) + 4 ]; - strcpy( newPrefix, prefix); + strcpy_s( newPrefix, prefix); strcat( newPrefix, " "); for ( auto& it : list ) it->print(newPrefix, out); diff --git a/Minecraft.World/MinecartContainer.cpp b/Minecraft.World/MinecartContainer.cpp index fa3ad5d7..4f309257 100644 --- a/Minecraft.World/MinecartContainer.cpp +++ b/Minecraft.World/MinecartContainer.cpp @@ -30,7 +30,7 @@ void MinecartContainer::destroy(DamageSource *source) { Minecart::destroy(source); - for (int i = 0; i < getContainerSize(); i++) + for (unsigned int i = 0; i < getContainerSize(); i++) { shared_ptr item = getItem(i); if (item != nullptr) @@ -142,7 +142,7 @@ void MinecartContainer::remove() { if (dropEquipment) { - for (int i = 0; i < getContainerSize(); i++) + for (unsigned int i = 0; i < getContainerSize(); i++) { shared_ptr item = getItem(i); if (item != nullptr) @@ -183,7 +183,7 @@ void MinecartContainer::addAdditonalSaveData(CompoundTag *base) ListTag *listTag = new ListTag(); - for (int i = 0; i < items.length; i++) + for (unsigned int i = 0; i < items.length; i++) { if (items[i] != nullptr) { diff --git a/Minecraft.World/Mob.cpp b/Minecraft.World/Mob.cpp index 54a77527..8b5ebe06 100644 --- a/Minecraft.World/Mob.cpp +++ b/Minecraft.World/Mob.cpp @@ -194,7 +194,7 @@ int Mob::getExperienceReward(shared_ptr killedBy) int result = xpReward; ItemInstanceArray slots = getEquipmentSlots(); - for (int i = 0; i < slots.length; i++) + for (unsigned int i = 0; i < slots.length; i++) { if (slots[i] != nullptr && dropChances[i] <= 1) { @@ -277,7 +277,7 @@ void Mob::addAdditonalSaveData(CompoundTag *entityTag) entityTag->putBoolean(L"PersistenceRequired", persistenceRequired); ListTag *gear = new ListTag(); - for (int i = 0; i < equipment.length; i++) + for (unsigned int i = 0; i < equipment.length; i++) { CompoundTag *tag = new CompoundTag(); if (equipment[i] != nullptr) equipment[i]->save(tag); @@ -286,7 +286,7 @@ void Mob::addAdditonalSaveData(CompoundTag *entityTag) entityTag->put(L"Equipment", gear); ListTag *dropChanceList = new ListTag(); - for (int i = 0; i < dropChances.length; i++) + for (unsigned int i = 0; i < dropChances.length; i++) { dropChanceList->add(new FloatTag( std::to_wstring(i), dropChances[i])); } @@ -329,7 +329,7 @@ void Mob::readAdditionalSaveData(CompoundTag *tag) { ListTag *gear = (ListTag *) tag->getList(L"Equipment"); - for (int i = 0; i < equipment.length; i++) + for (unsigned int i = 0; i < equipment.length; i++) { equipment[i] = ItemInstance::fromTag(gear->get(i)); } @@ -338,7 +338,7 @@ void Mob::readAdditionalSaveData(CompoundTag *tag) if (tag->contains(L"DropChances")) { ListTag *items = (ListTag *) tag->getList(L"DropChances"); - for (int i = 0; i < items->size(); i++) + for (unsigned int i = 0; i < items->size(); i++) { dropChances[i] = items->get(i)->data; } @@ -692,7 +692,7 @@ ItemInstanceArray Mob::getEquipmentSlots() void Mob::dropEquipment(bool byPlayer, int playerBonusLevel) { - for (int slot = 0; slot < getEquipmentSlots().length; slot++) + for (unsigned int slot = 0; slot < getEquipmentSlots().length; slot++) { shared_ptr item = getCarried(slot); bool preserve = dropChances[slot] > 1; diff --git a/Minecraft.World/Path.cpp b/Minecraft.World/Path.cpp index afea4a17..0feade68 100644 --- a/Minecraft.World/Path.cpp +++ b/Minecraft.World/Path.cpp @@ -7,7 +7,7 @@ Path::~Path() { if( nodes.data ) { - for( int i = 0; i < nodes.length; i++ ) + for( unsigned int i = 0; i < nodes.length; i++ ) delete nodes.data[i]; delete[] nodes.data; } @@ -96,7 +96,7 @@ bool Path::sameAs(Path *path) { if (path == nullptr) return false; if (path->nodes.length != nodes.length) return false; - for (int i = 0; i < nodes.length; ++i) + for (unsigned int i = 0; i < nodes.length; ++i) if (nodes[i]->x != path->nodes[i]->x || nodes[i]->y != path->nodes[i]->y || nodes[i]->z != path->nodes[i]->z) return false; return true; } diff --git a/Minecraft.World/Player.cpp b/Minecraft.World/Player.cpp index b2bf352e..e3f7ddba 100644 --- a/Minecraft.World/Player.cpp +++ b/Minecraft.World/Player.cpp @@ -1452,7 +1452,7 @@ int Player::getArmorValue() float Player::getArmorCoverPercentage() { int count = 0; - for (int i = 0; i < inventory->armor.length; i++) + for (unsigned int i = 0; i < inventory->armor.length; i++) { if (inventory->armor[i] != nullptr) { count++; diff --git a/Minecraft.World/PlayerEnderChestContainer.cpp b/Minecraft.World/PlayerEnderChestContainer.cpp index 8d0c48e9..4221d0ab 100644 --- a/Minecraft.World/PlayerEnderChestContainer.cpp +++ b/Minecraft.World/PlayerEnderChestContainer.cpp @@ -20,7 +20,7 @@ void PlayerEnderChestContainer::setActiveChest(shared_ptr void PlayerEnderChestContainer::setItemsByTag(ListTag *enderItemsList) { - for (int i = 0; i < getContainerSize(); i++) + for (unsigned int i = 0; i < getContainerSize(); i++) { setItem(i, nullptr); } @@ -28,14 +28,14 @@ void PlayerEnderChestContainer::setItemsByTag(ListTag *enderItemsLi { CompoundTag *tag = enderItemsList->get(i); int slot = tag->getByte(L"Slot") & 0xff; - if (slot >= 0 && slot < getContainerSize()) setItem(slot, ItemInstance::fromTag(tag)); + if (slot >= 0 && slot < (int)getContainerSize()) setItem(slot, ItemInstance::fromTag(tag)); } } ListTag *PlayerEnderChestContainer::createTag() { ListTag *items = new ListTag(L"EnderItems"); - for (int i = 0; i < getContainerSize(); i++) + for (unsigned int i = 0; i < getContainerSize(); i++) { shared_ptr item = getItem(i); if (item != nullptr) diff --git a/Minecraft.World/Recipes.cpp b/Minecraft.World/Recipes.cpp index edd6cd8f..b305ea42 100644 --- a/Minecraft.World/Recipes.cpp +++ b/Minecraft.World/Recipes.cpp @@ -1371,7 +1371,7 @@ shared_ptr Recipes::getItemFor(shared_ptr craft int count = 0; shared_ptr first = nullptr; shared_ptr second = nullptr; - for (int i = 0; i < craftSlots->getContainerSize(); i++) + for (unsigned int i = 0; i < craftSlots->getContainerSize(); i++) { shared_ptr item = craftSlots->getItem(i); if (item != nullptr) diff --git a/Minecraft.World/TileItem.cpp b/Minecraft.World/TileItem.cpp index 8d22594d..8c55bfce 100644 --- a/Minecraft.World/TileItem.cpp +++ b/Minecraft.World/TileItem.cpp @@ -128,7 +128,7 @@ bool TileItem::useOn(shared_ptr instance, shared_ptr playe // // if(iPlaceSound==-1) // { - // strcpy(szPlaceSoundName,"nullptr"); + // strcpy_s(szPlaceSoundName,"nullptr"); // } // else // { @@ -136,7 +136,7 @@ bool TileItem::useOn(shared_ptr instance, shared_ptr playe // } // if(iStepSound==-1) // { - // strcpy(szStepSoundName,"nullptr"); + // strcpy_s(szStepSoundName,"nullptr"); // } // else // {