diff --git a/Minecraft.Client/Level/ServerLevel.cpp b/Minecraft.Client/Level/ServerLevel.cpp index ae949c831..9657a3511 100644 --- a/Minecraft.Client/Level/ServerLevel.cpp +++ b/Minecraft.Client/Level/ServerLevel.cpp @@ -632,6 +632,7 @@ std::vector *ServerLevel::fetchTicksInChunk(LevelChunk *chunk, std::vector *results = new std::vector; ChunkPos *pos = chunk->getPos(); + // 4jcraft added cast to unsigned int west = (unsigned) pos->x << 4; int east = west + 16; int north =(unsigned) pos->z << 4; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCManager.cpp b/Minecraft.Client/Platform/Common/DLC/DLCManager.cpp index 030030ddb..c87d2b85a 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCManager.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCManager.cpp @@ -411,13 +411,13 @@ bool DLCManager::readDLCDataFile(DWORD &dwFilesProcessed, const std::string &pat } // a bunch of makros to reduce memcpy and offset boilerplate -#define DLC_READ_DWORD(buf, off) ({ DWORD _temp; memcpy(&_temp, (buf) + (off), sizeof(DWORD)); _temp; }) +#define DLC_READ_UINT(out, buf, off) memcpy(out, (buf) + (off), sizeof(unsigned int)) #define DLC_READ_PARAM(out, buf, off) memcpy((out), (buf) + (off), sizeof(C4JStorage::DLC_FILE_PARAM)) #define DLC_READ_DETAIL(out, buf, off) memcpy((out), (buf) + (off), sizeof(C4JStorage::DLC_FILE_DETAILS)) -// for details, read below in the function below +// for details, read in the function below #define DLC_PARAM_WSTR(buf, off) DLC_WSTRING((buf) + (off) + offsetof(C4JStorage::DLC_FILE_PARAM, wchData)) #define DLC_DETAIL_WSTR(buf, off) DLC_WSTRING((buf) + (off) + offsetof(C4JStorage::DLC_FILE_DETAILS, wchFile)) @@ -445,16 +445,13 @@ bool DLCManager::processDLCDataFile(DWORD &dwFilesProcessed, PBYTE pbData, DWORD // (scince bufferoffset after advancing by variable string length is not // guaranteed to be properly aligned, so casting to a scalar/struct is UB) - // those casts are dangerous and will crash on ARM cpus when the pointers are - // not properly aligned at the offset. this includes for casting into the storage - // structs and casting into an unsigned integer - // everything else is aquivalent. i did not concern myself with the fact that - // EOF was not checked a single time. the lion doesnt bother with making code safe. + // those casts coult be dangerous on e.g. ARM, because it doesnt handle + // missaligned loads, like x86/x64, so it would crash // WHO TF USES HUNGARIAN NOTATION - // safe, offset 0, aligned - unsigned int uiVersion=*(unsigned int *)pbData; + unsigned int uiVersion; + DLC_READ_UINT(&uiVersion, pbData, uiCurrentByte); uiCurrentByte+=sizeof(int); if(uiVersion < CURRENT_DLC_VERSION_NUM) @@ -465,7 +462,8 @@ bool DLCManager::processDLCDataFile(DWORD &dwFilesProcessed, PBYTE pbData, DWORD } pack->SetDataPointer(pbData); // safe, offset 4, aligned - unsigned int uiParameterCount=*(unsigned int *)&pbData[uiCurrentByte]; + unsigned int uiParameterCount; + DLC_READ_UINT(&uiParameterCount, pbData, uiCurrentByte); uiCurrentByte+=sizeof(int); C4JStorage::DLC_FILE_PARAM parBuf; @@ -485,7 +483,8 @@ bool DLCManager::processDLCDataFile(DWORD &dwFilesProcessed, PBYTE pbData, DWORD } //ulCurrentByte+=ulParameterCount * sizeof(C4JStorage::DLC_FILE_PARAM); - unsigned int uiFileCount = DLC_READ_DWORD(pbData, uiCurrentByte); + unsigned int uiFileCount; + DLC_READ_UINT(&uiFileCount, pbData, uiCurrentByte); uiCurrentByte+=sizeof(int); C4JStorage::DLC_FILE_DETAILS fileBuf; @@ -497,7 +496,7 @@ bool DLCManager::processDLCDataFile(DWORD &dwFilesProcessed, PBYTE pbData, DWORD dwTemp+=DLC_DETAIL_ADV(fileBuf.dwWchCount); DLC_READ_DETAIL(&fileBuf, pbData, dwTemp); } - PBYTE pbTemp=&pbData[dwTemp];//+ sizeof(C4JStorage::DLC_FILE_DETAILS)*ulFileCount; + PBYTE pbTemp = &pbData[dwTemp];//+ sizeof(C4JStorage::DLC_FILE_DETAILS)*ulFileCount; DLC_READ_DETAIL(&fileBuf, pbData, uiCurrentByte); for(unsigned int i=0;iprocessSchematic(chunkBox, chunk); } + // 4jcraft added cast to unsigned int cx = ((unsigned)chunk->x << 4); int cz = ((unsigned)chunk->z << 4); diff --git a/Minecraft.Client/Platform/Common/Network/PlatformNetworkManagerStub.cpp b/Minecraft.Client/Platform/Common/Network/PlatformNetworkManagerStub.cpp index 9dfc45a17..5e366e190 100644 --- a/Minecraft.Client/Platform/Common/Network/PlatformNetworkManagerStub.cpp +++ b/Minecraft.Client/Platform/Common/Network/PlatformNetworkManagerStub.cpp @@ -119,6 +119,7 @@ bool CPlatformNetworkManagerStub::Initialise(CGameNetworkManager *pGameNetworkMa m_pGameNetworkManager = pGameNetworkManager; m_flagIndexSize = flagIndexSize; g_pPlatformNetworkManager = this; + // 4jcraft added this, as it was never called m_pIQNet = new IQNet(); for( int i = 0; i < XUSER_MAX_COUNT; i++ ) { diff --git a/Minecraft.World/IO/Files/ConsoleSaveFileSplit.cpp b/Minecraft.World/IO/Files/ConsoleSaveFileSplit.cpp index ffb873643..90778f02c 100644 --- a/Minecraft.World/IO/Files/ConsoleSaveFileSplit.cpp +++ b/Minecraft.World/IO/Files/ConsoleSaveFileSplit.cpp @@ -1230,6 +1230,7 @@ bool ConsoleSaveFileSplit::GetNumericIdentifierFromName(const std::wstring &file swscanf_s(body, L"%d.%d.mcr", &x, &z ); // Pack full id + // 4jcraft added cast to unsigned id |= ( ( (unsigned int) x << 8 ) & 0x0000ff00 ); id |= ( z & 0x000000ff ); diff --git a/Minecraft.World/Util/Mth.cpp b/Minecraft.World/Util/Mth.cpp index b290b5877..752986135 100644 --- a/Minecraft.World/Util/Mth.cpp +++ b/Minecraft.World/Util/Mth.cpp @@ -21,7 +21,7 @@ void Mth::init() _sin = new float[SIN_TAB_CNT]; for (int i = 0; i < SIN_TAB_CNT; i++) { - _sin[i] = (float) ::sin(i * PI * 2 / 65536.0f); + _sin[i] = (float) ::sin(i * PI * 2 / (float) SIN_TAB_CNT); } } @@ -44,7 +44,7 @@ float Mth::cos(float i) // which is aquivalent to shift by pi / 2 // and again the same modulo logic to cramp and map it onto the computed table - return _sin[(int32_t) fmodf(i * sinScale + ((float) SIN_TAB_CNT / 4), (float)SIN_TAB_CNT) & (SIN_TAB_CNT - 1)]; + return _sin[(int32_t) fmodf(i * sinScale + ((float) SIN_TAB_CNT / 4), (float) SIN_TAB_CNT) & (SIN_TAB_CNT - 1)]; } diff --git a/Minecraft.World/Util/Random.cpp b/Minecraft.World/Util/Random.cpp index 509189a8f..20c92c588 100644 --- a/Minecraft.World/Util/Random.cpp +++ b/Minecraft.World/Util/Random.cpp @@ -88,8 +88,8 @@ int Random::nextInt(int n) if ((n & -n) == n) // i.e., n is a power of 2 - // 4jcraft added casts to unsigned (and uint64) - return (unsigned int)(((__uint64)next(31) * n) >> 31); // 4J Stu - Made __int64 instead of long + // 4jcraft added casts to unsigned (and uint64_t) + return (int)(((uint64_t)next(31) * n) >> 31); // 4J Stu - Made __int64 instead of long int bits, val; do @@ -109,7 +109,7 @@ float Random::nextFloat() __int64 Random::nextLong() { // 4jcraft added casts to unsigned - return (__uint64)((__uint64)next(32) << 32) + next(32); + return (int64_t)((uint64_t) next(32) << 32) + next(32); } bool Random::nextBoolean() diff --git a/Minecraft.World/WorldGen/Features/LargeFeature.cpp b/Minecraft.World/WorldGen/Features/LargeFeature.cpp index 187ec5dd1..caf3d040e 100644 --- a/Minecraft.World/WorldGen/Features/LargeFeature.cpp +++ b/Minecraft.World/WorldGen/Features/LargeFeature.cpp @@ -28,8 +28,8 @@ void LargeFeature::apply(ChunkSource *ChunkSource, Level *level, int xOffs, int { for (int z = zOffs - r; z <= zOffs + r; z++) { - __int64 xx = (uint64_t) x * xScale; - __int64 zz = (uint64_t) z * zScale; + int64_t xx = (uint64_t) x * xScale; + int64_t zz = (uint64_t) z * zScale; random->setSeed(xx ^ zz ^ level->getSeed()); addFeature(level, x, z, xOffs, zOffs, blocks); }