mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-08 14:47:24 +00:00
revising everything
This commit is contained in:
parent
6cfc1efec2
commit
6d952e24f5
|
|
@ -632,6 +632,7 @@ std::vector<TickNextTickData> *ServerLevel::fetchTicksInChunk(LevelChunk *chunk,
|
|||
std::vector<TickNextTickData> *results = new std::vector<TickNextTickData>;
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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;i<uiFileCount;i++)
|
||||
|
|
@ -517,7 +516,8 @@ bool DLCManager::processDLCDataFile(DWORD &dwFilesProcessed, PBYTE pbData, DWORD
|
|||
}
|
||||
|
||||
// Params
|
||||
unsigned int uiParamCount = DLC_READ_DWORD(pbTemp, 0);
|
||||
unsigned int uiParamCount;
|
||||
DLC_READ_UINT(&uiParamCount, pbTemp, 0);
|
||||
pbTemp+=sizeof(int);
|
||||
|
||||
DLC_READ_PARAM(&parBuf, pbTemp, 0);
|
||||
|
|
|
|||
|
|
@ -244,6 +244,7 @@ void LevelGenerationOptions::processSchematics(LevelChunk *chunk)
|
|||
rule->processSchematic(chunkBox, chunk);
|
||||
}
|
||||
|
||||
// 4jcraft added cast to unsigned
|
||||
int cx = ((unsigned)chunk->x << 4);
|
||||
int cz = ((unsigned)chunk->z << 4);
|
||||
|
||||
|
|
|
|||
|
|
@ -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++ )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
||||
|
|
|
|||
|
|
@ -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)];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue