From 57499a82ac1b6b30e7829e20e4a7db8a02d9bbde Mon Sep 17 00:00:00 2001
From: BSzili
Date: Fri, 5 Sep 2025 07:24:38 +0200
Subject: [PATCH] Big endian fixes
---
Sources/Engine/Base/Anim.cpp | 10 +--
Sources/Engine/Base/Stream.cpp | 1 +
Sources/Engine/Brushes/BrushIO.cpp | 12 ++--
Sources/Engine/Entities/Entity.cpp | 2 +-
Sources/Engine/Graphics/Color.cpp | 6 ++
Sources/Engine/Graphics/DrawPort.cpp | 5 ++
Sources/Engine/Graphics/Fog.cpp | 4 ++
Sources/Engine/Graphics/ImageInfo.cpp | 8 +++
Sources/Engine/Graphics/Texture.cpp | 27 +++----
Sources/Engine/Light/LayerMixer.cpp | 40 ++++++++++-
Sources/Engine/Math/Matrix.h | 27 +++++++
Sources/Engine/Models/Model.cpp | 11 ++-
Sources/Engine/Network/NetworkMessage.cpp | 42 +++++++++++
Sources/Engine/Network/NetworkMessage.h | 23 +++---
Sources/Engine/Network/PlayerBuffer.cpp | 1 +
Sources/Engine/Network/PlayerSource.cpp | 18 +++++
Sources/Engine/Network/Server.cpp | 18 +++++
Sources/Engine/Network/SessionState.cpp | 86 ++++++++++++++++++++++-
Sources/Engine/Ska/AnimSet.cpp | 14 ++--
Sources/Engine/Ska/Mesh.cpp | 16 ++---
Sources/Engine/Ska/Mesh.h | 6 +-
Sources/Engine/Ska/Skeleton.cpp | 4 +-
Sources/Engine/Sound/SoundDecoder.cpp | 2 +-
Sources/Engine/Sound/SoundLibrary.cpp | 4 +-
Sources/Engine/Terrain/Terrain.cpp | 8 ++-
Sources/Entities/Common/Common.h | 20 ++++++
Sources/Entities/Player.es | 16 ++---
Sources/EntitiesMP/Player.es | 8 +--
28 files changed, 359 insertions(+), 80 deletions(-)
diff --git a/Sources/Engine/Base/Anim.cpp b/Sources/Engine/Base/Anim.cpp
index 8eff66e..be8dd73 100644
--- a/Sources/Engine/Base/Anim.cpp
+++ b/Sources/Engine/Base/Anim.cpp
@@ -458,15 +458,15 @@ void CAnimData::Write_t( CTStream *ostrFile) // throw char *
// First we save main ID
ostrFile->WriteID_t( CChunkID( "ADAT"));
// Then we save number of how many animations do we have and then save them all
- ostrFile->Write_t( &ad_NumberOfAnims, sizeof( INDEX));
+ (*ostrFile)<Write_t( &ad_Anims[i].oa_Name, sizeof( NAME));
- ostrFile->Write_t( &ad_Anims[i].oa_SecsPerFrame, sizeof( TIME));
- ostrFile->Write_t( &ad_Anims[i].oa_NumberOfFrames, sizeof( INDEX));
- ostrFile->Write_t( ad_Anims[i].oa_FrameIndices,
- ad_Anims[i].oa_NumberOfFrames * sizeof( INDEX));
+ (*ostrFile)<Write_t(&itbvx->bvx_vdPreciseRelative, sizeof(DOUBLE3D));
+ (*postrm)<bvx_vdPreciseRelative;
}}
(*postrm).WriteID_t("PLNs"); // 'planes'
@@ -289,7 +289,7 @@ void CBrushSector::Write_t( CTStream *postrm) // throw char *
// for each plane
{FOREACHINSTATICARRAY(bsc_abplPlanes, CBrushPlane, itbpl) {
// write precise plane coordinates
- postrm->Write_t(&itbpl->bpl_pldPreciseRelative, sizeof(DOUBLEplane3D));
+ (*postrm)<bpl_pldPreciseRelative;
}}
(*postrm).WriteID_t("EDGs"); // 'edges'
@@ -320,7 +320,7 @@ void CBrushSector::Write_t( CTStream *postrm) // throw char *
bpo.bpo_abptTextures[1].Write_t(*postrm);
bpo.bpo_abptTextures[2].Write_t(*postrm);
// write other polygon properties
- (*postrm).Write_t(&bpo.bpo_bppProperties, sizeof(bpo.bpo_bppProperties));
+ (*postrm)<0) {
- (*postrm).Write_t(&bpo.bpo_aiTriangleElements[0], ctElements*sizeof(INDEX));
+ for (INDEX i = 0; i < ctElements; i++) {
+ (*postrm)<Width);
+ BYTESWAP(pTGAHdr->Height);
+ BYTESWAP(pTGAHdr->Xorigin);
+ BYTESWAP(pTGAHdr->Yorigin);
// TGA image bytes definition follows up
pTGAImage = pTGABuffer + sizeof(struct TGAHeader) + pTGAHdr->IdLength;
@@ -475,9 +479,13 @@ void CImageInfo::SaveTGA_t( const CTFileName &strFileName) const // throw char *
// set TGA picture size dimensions
memset( pTGABuffer, 0x0, sizeof(struct TGAHeader));
pTGAHdr->Width = (UWORD)ii_Width;
+ BYTESWAP(pTGAHdr->Width);
pTGAHdr->Height = (UWORD)ii_Height;
+ BYTESWAP(pTGAHdr->Height);
pTGAHdr->BitsPerPixel = (UBYTE)ii_BitsPerPixel;
pTGAHdr->ImageType = 2;
+ BYTESWAP(pTGAHdr->Xorigin);
+ BYTESWAP(pTGAHdr->Yorigin);
// flip image vertically
BOOL bAlphaChannel = (slBytesPerPixel==4);
diff --git a/Sources/Engine/Graphics/Texture.cpp b/Sources/Engine/Graphics/Texture.cpp
index 514f252..909c80f 100644
--- a/Sources/Engine/Graphics/Texture.cpp
+++ b/Sources/Engine/Graphics/Texture.cpp
@@ -752,8 +752,9 @@ void CTextureData::Read_t( CTStream *inFile)
// alloc memory block and read mip-maps
inFile->Read_t( td_pulFrames, slTexSize);
#if PLATFORM_BIGENDIAN
- for (SLONG i = 0; i < slTexSize/4; i++)
- BYTESWAP(td_pulFrames[i]);
+ UWORD *uwptr = (UWORD *)td_pulFrames;
+ for (SLONG i = 0; i < slTexSize/2; i++)
+ BYTESWAP(uwptr[i]);
#endif
}
// if current version
@@ -765,10 +766,6 @@ void CTextureData::Read_t( CTStream *inFile)
if( bAlphaChannel) {
// read texture with alpha channel from file
inFile->Read_t( pulCurrentFrame, pixFrameSizeOnDisk *4);
- #if PLATFORM_BIGENDIAN
- for (SLONG i = 0; i < pixFrameSizeOnDisk; i++)
- BYTESWAP(pulCurrentFrame[i]);
- #endif
} else {
// read texture without alpha channel from file
inFile->Read_t( pulCurrentFrame, pixFrameSizeOnDisk *3);
@@ -825,6 +822,15 @@ void CTextureData::Read_t( CTStream *inFile)
ULONG ulSize = AllocEffectBuffers(this);
inFile->Read_t( td_pubBuffer1, ulSize);
inFile->Read_t( td_pubBuffer2, ulSize);
+ #if PLATFORM_BIGENDIAN
+ SWORD* pNew = (SWORD*)td_pubBuffer1;
+ SWORD* pOld = (SWORD*)td_pubBuffer2;
+ for (int i = 0; i < ulSize / 2; i++)
+ {
+ BYTESWAP(pNew[i]);
+ BYTESWAP(pOld[i]);
+ }
+ #endif
}
// if this is chunk containing effect data
else if( idChunk == CChunkID("FXDT"))
@@ -1008,10 +1014,6 @@ void CTextureData::Read_t( CTStream *inFile)
// writes texutre to file
void CTextureData::Write_t( CTStream *outFile) // throw char *
{
- #if PLATFORM_BIGENDIAN
- STUBBED("Byte swapping");
- #endif
-
// cannot write textures that have been mangled somehow
_bExport = FALSE;
if( td_ptegEffect==NULL && IsModified()) throw( TRANS("Cannot write texture that has modified frames."));
@@ -1084,14 +1086,15 @@ void CTextureData::Write_t( CTStream *outFile) // throw char *
{ // write type of effect source
*outFile << itEffectSource->tes_ulEffectSourceType;
// write structure holding effect source properties
- outFile->Write_t( &itEffectSource->tes_tespEffectSourceProperties, sizeof( struct TextureEffectSourceProperties));
+ *outFile >> itEffectSource->tes_tespEffectSourceProperties;
INDEX ctEffectSourcePixels = itEffectSource->tes_atepPixels.Count();
// write count of effect pixels
*outFile << ctEffectSourcePixels;
// if there are any effect pixels
if( ctEffectSourcePixels>0) {
// write all effect pixels in one block
- outFile->Write_t( &itEffectSource->tes_atepPixels[0], sizeof(struct TextureEffectPixel)*ctEffectSourcePixels);
+ for (INDEX i = 0; i < ctEffectSourcePixels; i++)
+ *outFile >> itEffectSource->tes_atepPixels[i];
}
}
// if effect buffers are valid
diff --git a/Sources/Engine/Light/LayerMixer.cpp b/Sources/Engine/Light/LayerMixer.cpp
index e7daa71..67aa226 100755
--- a/Sources/Engine/Light/LayerMixer.cpp
+++ b/Sources/Engine/Light/LayerMixer.cpp
@@ -143,21 +143,48 @@ static inline void IncrementColorWithClip( UBYTE &ubR, UBYTE &ubG, UBYTE &ubB,
// add the intensity to the pixel
inline void CLayerMixer::AddToCluster( UBYTE *pub)
{
+#if PLATFORM_LITTLEENDIAN
IncrementByteWithClip(pub[0], ((UBYTE*)&lm_colLight)[3]);
IncrementByteWithClip(pub[1], ((UBYTE*)&lm_colLight)[2]);
IncrementByteWithClip(pub[2], ((UBYTE*)&lm_colLight)[1]);
+#else
+ IncrementByteWithClip(pub[0], ((UBYTE*)&lm_colLight)[0]);
+ IncrementByteWithClip(pub[1], ((UBYTE*)&lm_colLight)[1]);
+ IncrementByteWithClip(pub[2], ((UBYTE*)&lm_colLight)[2]);
+ IncrementByteWithClip(pub[3], ((UBYTE*)&lm_colLight)[3]);
+#endif
}
inline void CLayerMixer::AddAmbientToCluster( UBYTE *pub)
{
+#if PLATFORM_LITTLEENDIAN
IncrementByteWithClip(pub[0], ((UBYTE*)&lm_colAmbient)[3]);
IncrementByteWithClip(pub[1], ((UBYTE*)&lm_colAmbient)[2]);
IncrementByteWithClip(pub[2], ((UBYTE*)&lm_colAmbient)[1]);
+#else
+ IncrementByteWithClip(pub[0], ((UBYTE*)&lm_colAmbient)[0]);
+ IncrementByteWithClip(pub[1], ((UBYTE*)&lm_colAmbient)[1]);
+ IncrementByteWithClip(pub[2], ((UBYTE*)&lm_colAmbient)[2]);
+ IncrementByteWithClip(pub[3], ((UBYTE*)&lm_colAmbient)[3]);
+#endif
}
inline void CLayerMixer::AddToCluster( UBYTE *pub, SLONG slIntensity)
{
+#if PLATFORM_LITTLEENDIAN
IncrementByteWithClip(pub[0], (long) (((UBYTE*)&lm_colLight)[3] *slIntensity)>>16);
IncrementByteWithClip(pub[1], (long) (((UBYTE*)&lm_colLight)[2] *slIntensity)>>16);
IncrementByteWithClip(pub[2], (long) (((UBYTE*)&lm_colLight)[1] *slIntensity)>>16);
+#else
+ UBYTE r, g, b, a;
+ ColorToRGBA(lm_colLight, r, g, b, a);
+
+ SLONG dR = ((SLONG)r * (SLONG)slIntensity) >> 16;
+ SLONG dG = ((SLONG)g * (SLONG)slIntensity) >> 16;
+ SLONG dB = ((SLONG)b * (SLONG)slIntensity) >> 16;
+
+ IncrementByteWithClip(pub[0], dR);
+ IncrementByteWithClip(pub[1], dG);
+ IncrementByteWithClip(pub[2], dB);
+#endif
}
@@ -1406,6 +1433,12 @@ rowDone:
SLONG slR1=0,slG1=0,slB1=0;
ColorToRGB( col0, (UBYTE&)slR0,(UBYTE&)slG0,(UBYTE&)slB0);
ColorToRGB( col1, (UBYTE&)slR1,(UBYTE&)slG1,(UBYTE&)slB1);
+ BYTESWAP(slR0);
+ BYTESWAP(slG0);
+ BYTESWAP(slB0);
+ BYTESWAP(slR1);
+ BYTESWAP(slG1);
+ BYTESWAP(slB1);
if( gp.gp_bDark) {
slR0 = -slR0; slG0 = -slG0; slB0 = -slB0;
slR1 = -slR1; slG1 = -slG1; slB1 = -slB1;
@@ -1813,10 +1846,7 @@ void CLayerMixer::MixOneMipmap(CBrushShadowMap *pbsm, INDEX iMipmap)
// Forces C fallback; BYTESWAP itself is a no-op on little endian.
ULONG swapped = BYTESWAP32_unsigned(colAmbient);
#else
- STUBBED("actually need byteswap?");
- // (uses inline asm on MacOS PowerPC)
ULONG swapped = colAmbient;
- BYTESWAP(swapped);
#endif
for (ULONG *ptr = this->lm_pulShadowMap; count; count--)
@@ -1964,7 +1994,11 @@ __forceinline void CLayerMixer::FillShadowLayer( COLOR col)
#else
DWORD* dst = (DWORD*)lm_pulShadowMap;
int n = lm_pixCanvasSizeU*lm_pixCanvasSizeV;
+#if PLATFORM_LITTLEENDIAN
DWORD color = BYTESWAP32_unsigned(col);
+#else
+ DWORD color = col;
+#endif
while(n--) {*(dst++)=color;}
#endif
}
diff --git a/Sources/Engine/Math/Matrix.h b/Sources/Engine/Math/Matrix.h
index a4167b4..841d0d2 100755
--- a/Sources/Engine/Math/Matrix.h
+++ b/Sources/Engine/Math/Matrix.h
@@ -68,11 +68,38 @@ public:
friend __forceinline CTStream &operator>>(CTStream &strm, Matrix &matrix)
{
strm.Read_t(&matrix, sizeof(matrix));
+ #if PLATFORM_BIGENDIAN
+ for (int i = 0; i < iRows; i++)
+ {
+ for (int j = 0; j < iColumns; j++)
+ {
+ BYTESWAP(matrix.matrix[i][j]);
+ }
+ }
+ #endif
return strm;
}
friend __forceinline CTStream &operator<<(CTStream &strm, Matrix &matrix)
{
+ #if PLATFORM_BIGENDIAN
+ for (int i = 0; i < iRows; i++)
+ {
+ for (int j = 0; j < iColumns; j++)
+ {
+ BYTESWAP(matrix.matrix[i][j]);
+ }
+ }
+ #endif
strm.Write_t(&matrix, sizeof(matrix));
+ #if PLATFORM_BIGENDIAN
+ for (int i = 0; i < iRows; i++)
+ {
+ for (int j = 0; j < iColumns; j++)
+ {
+ BYTESWAP(matrix.matrix[i][j]);
+ }
+ }
+ #endif
return strm;
}
};
diff --git a/Sources/Engine/Models/Model.cpp b/Sources/Engine/Models/Model.cpp
index e3847d2..80c9fd7 100644
--- a/Sources/Engine/Models/Model.cpp
+++ b/Sources/Engine/Models/Model.cpp
@@ -1178,10 +1178,6 @@ void CModelData::Write_t( CTStream *pFile) // throw char *
// Save flags
(*pFile) << md_Flags;
- #if PLATFORM_BIGENDIAN
- STUBBED("byte order");
- #endif
-
// Save vertices and frames ct
pFile->WriteFullChunk_t( CChunkID("IVTX"), &md_VerticesCt, sizeof(INDEX));
pFile->WriteFullChunk_t( CChunkID("IFRM"), &md_FramesCt, sizeof(INDEX));
@@ -1689,6 +1685,7 @@ void CModelData::Read_t( CTStream *pFile) // throw char *
// Read color names (Read count, read existing names)
INDEX iValidColorsCt;
pFile->ReadFullChunk_t( CChunkID("ICLN"), &iValidColorsCt, sizeof(INDEX));
+ BYTESWAP(iValidColorsCt);
for( i=0; iWriteID_t( CChunkID( "MODT"));
*pFile << mo_colBlendColor;
- pFile->Write_t( &mo_PatchMask, sizeof(ULONG));
- pFile->Write_t( &mo_Stretch, sizeof(FLOAT3D));
- pFile->Write_t( &mo_ColorMask, sizeof(ULONG));
+ *pFile << mo_PatchMask;
+ *pFile << mo_Stretch;
+ *pFile << mo_ColorMask;
}
//------------------------------------------ READ
void CModelObject::Read_t( CTStream *pFile) // throw char *
diff --git a/Sources/Engine/Network/NetworkMessage.cpp b/Sources/Engine/Network/NetworkMessage.cpp
index 1c8df08..b6bf0b8 100644
--- a/Sources/Engine/Network/NetworkMessage.cpp
+++ b/Sources/Engine/Network/NetworkMessage.cpp
@@ -915,7 +915,13 @@ CNetworkMessage &operator<<(CNetworkMessage &nm, const CPlayerAction &pa)
} else {
UBYTE ub=1;
nm.WriteBits(&ub, 1);
+#if PLATFORM_BIGENDIAN
+ ULONG tmp = *pul;
+ BYTESWAP(tmp);
+ nm.WriteBits(&tmp, 32);
+#else
nm.WriteBits(pul, 32);
+#endif
}
pul++;
}
@@ -933,27 +939,57 @@ CNetworkMessage &operator<<(CNetworkMessage &nm, const CPlayerAction &pa)
} else if (ulFlags <= 3) {
UBYTE ub=4;
nm.WriteBits(&ub, 3);
+#if PLATFORM_BIGENDIAN
+ ULONG tmp = ulFlags;
+ BYTESWAP(tmp);
+ nm.WriteBits(&tmp, 1);
+#else
nm.WriteBits(&ulFlags, 1);
+#endif
// (4-15) 0001 = 4 bit value follows
} else if (ulFlags <= 15) {
UBYTE ub=8;
nm.WriteBits(&ub, 4);
+#if PLATFORM_BIGENDIAN
+ ULONG tmp = ulFlags;
+ BYTESWAP(tmp);
+ nm.WriteBits(&tmp, 4);
+#else
nm.WriteBits(&ulFlags, 4);
+#endif
// (16-255) 00001 = 8 bit value follows
} else if (ulFlags <= 255) {
UBYTE ub=16;
nm.WriteBits(&ub, 5);
+#if PLATFORM_BIGENDIAN
+ ULONG tmp = ulFlags;
+ BYTESWAP(tmp);
+ nm.WriteBits(&tmp, 8);
+#else
nm.WriteBits(&ulFlags, 8);
+#endif
// (256-65535) 000001 = 16 bit value follows
} else if (ulFlags <= 65535) {
UBYTE ub=32;
nm.WriteBits(&ub, 6);
+#if PLATFORM_BIGENDIAN
+ ULONG tmp = ulFlags;
+ BYTESWAP(tmp);
+ nm.WriteBits(&tmp, 16);
+#else
nm.WriteBits(&ulFlags, 16);
+#endif
// (65536-) 000000 = 32 bit value follows
} else {
UBYTE ub=0;
nm.WriteBits(&ub, 6);
+#if PLATFORM_BIGENDIAN
+ ULONG tmp = ulFlags;
+ BYTESWAP(tmp);
+ nm.WriteBits(&tmp, 32);
+#else
nm.WriteBits(&ulFlags, 32);
+#endif
}
return nm;
}
@@ -970,6 +1006,7 @@ CNetworkMessage &operator>>(CNetworkMessage &nm, CPlayerAction &pa)
*pul = 0;
} else {
nm.ReadBits(pul, 32);
+ BYTESWAP(*pul);
}
pul++;
}
@@ -995,23 +1032,28 @@ CNetworkMessage &operator>>(CNetworkMessage &nm, CPlayerAction &pa)
} else if (iZeros==2) {
ulFlags = 0;
nm.ReadBits(&ulFlags, 1);
+ BYTESWAP(ulFlags);
ulFlags |= 2;
// (4-15) 0001 = 4 bit value follows
} else if (iZeros==3) {
ulFlags = 0;
nm.ReadBits(&ulFlags, 4);
+ BYTESWAP(ulFlags);
// (16-255) 00001 = 8 bit value follows
} else if (iZeros==4) {
ulFlags = 0;
nm.ReadBits(&ulFlags, 8);
// (256-65535) 000001 = 16 bit value follows
+ BYTESWAP(ulFlags);
} else if (iZeros==5) {
ulFlags = 0;
nm.ReadBits(&ulFlags, 16);
+ BYTESWAP(ulFlags);
// (65536-) 000000 = 32 bit value follows
} else {
ulFlags = 0;
nm.ReadBits(&ulFlags, 32);
+ BYTESWAP(ulFlags);
}
pa.pa_ulButtons = ulFlags;
return nm;
diff --git a/Sources/Engine/Network/NetworkMessage.h b/Sources/Engine/Network/NetworkMessage.h
index 800e662..064ee78 100644
--- a/Sources/Engine/Network/NetworkMessage.h
+++ b/Sources/Engine/Network/NetworkMessage.h
@@ -160,23 +160,24 @@ public:
void WriteBits(const void *pvBuffer, INDEX ctBits);
/* Read an object from message. */
- inline CNetworkMessage &operator>>(float &f) { Read( &f, sizeof( f)); return *this; }
- inline CNetworkMessage &operator>>(ULONG &ul) { Read(&ul, sizeof(ul)); return *this; }
- inline CNetworkMessage &operator>>(UWORD &uw) { Read(&uw, sizeof(uw)); return *this; }
+ inline CNetworkMessage &operator>>(float &f) { Read( &f, sizeof( f)); BYTESWAP(f); return *this; }
+ inline CNetworkMessage &operator>>(double &d) { Read( &d, sizeof( d)); BYTESWAP(d); return *this; }
+ inline CNetworkMessage &operator>>(ULONG &ul) { Read(&ul, sizeof(ul)); BYTESWAP(ul); return *this; }
+ inline CNetworkMessage &operator>>(UWORD &uw) { Read(&uw, sizeof(uw)); BYTESWAP(uw); return *this; }
inline CNetworkMessage &operator>>(UBYTE &ub) { Read(&ub, sizeof(ub)); return *this; }
- inline CNetworkMessage &operator>>(SLONG &sl) { Read(&sl, sizeof(sl)); return *this; }
- inline CNetworkMessage &operator>>(SWORD &sw) { Read(&sw, sizeof(sw)); return *this; }
+ inline CNetworkMessage &operator>>(SLONG &sl) { Read(&sl, sizeof(sl)); BYTESWAP(sl); return *this; }
+ inline CNetworkMessage &operator>>(SWORD &sw) { Read(&sw, sizeof(sw)); BYTESWAP(sw); return *this; }
inline CNetworkMessage &operator>>(SBYTE &sb) { Read(&sb, sizeof(sb)); return *this; }
inline CNetworkMessage &operator>>(MESSAGETYPE &mt) { Read(&mt, sizeof(mt)); return *this; }
CNetworkMessage &operator>>(CTString &str);
/* Write an object into message. */
- inline CNetworkMessage &operator<<(const float &f) { Write( &f, sizeof( f)); return *this; }
- inline CNetworkMessage &operator<<(const double &d) { Write( &d, sizeof( d)); return *this; }
- inline CNetworkMessage &operator<<(const ULONG &ul) { Write(&ul, sizeof(ul)); return *this; }
- inline CNetworkMessage &operator<<(const UWORD &uw) { Write(&uw, sizeof(uw)); return *this; }
+ inline CNetworkMessage &operator<<(const float &f) { float zf = f; BYTESWAP( zf); Write( &zf, sizeof( zf)); return *this; }
+ inline CNetworkMessage &operator<<(const double &d) { double zd = d; BYTESWAP( zd); Write( &zd, sizeof( zd)); return *this; }
+ inline CNetworkMessage &operator<<(const ULONG &ul) { ULONG zul = ul; BYTESWAP(zul); Write(&zul, sizeof(zul)); return *this; }
+ inline CNetworkMessage &operator<<(const UWORD &uw) { UWORD zuw = uw; BYTESWAP(zuw); Write(&zuw, sizeof(zuw)); return *this; }
inline CNetworkMessage &operator<<(const UBYTE &ub) { Write(&ub, sizeof(ub)); return *this; }
- inline CNetworkMessage &operator<<(const SLONG &sl) { Write(&sl, sizeof(sl)); return *this; }
- inline CNetworkMessage &operator<<(const SWORD &sw) { Write(&sw, sizeof(sw)); return *this; }
+ inline CNetworkMessage &operator<<(const SLONG &sl) { SLONG zsl = sl; BYTESWAP(zsl); Write(&zsl, sizeof(zsl)); return *this; }
+ inline CNetworkMessage &operator<<(const SWORD &sw) { SWORD zsw = sw; BYTESWAP(zsw); Write(&zsw, sizeof(zsw)); return *this; }
inline CNetworkMessage &operator<<(const SBYTE &sb) { Write(&sb, sizeof(sb)); return *this; }
inline CNetworkMessage &operator<<(const MESSAGETYPE &mt) { Write(&mt, sizeof(mt)); return *this; }
CNetworkMessage &operator<<(const CTString &str);
diff --git a/Sources/Engine/Network/PlayerBuffer.cpp b/Sources/Engine/Network/PlayerBuffer.cpp
index 622101c..c177be9 100644
--- a/Sources/Engine/Network/PlayerBuffer.cpp
+++ b/Sources/Engine/Network/PlayerBuffer.cpp
@@ -71,6 +71,7 @@ void CPlayerBuffer::ReceiveActionPacket(CNetworkMessage *pnm, INDEX iMaxBuffer)
// read sendbehind
INDEX iSendBehind = 0;
pnm->ReadBits(&iSendBehind, 2);
+ BYTESWAP(iSendBehind);
// foreach resent action
for(INDEX i=0; iGetRealTimeTick(), SLONG(pls_paAction.pa_llCreated));
@@ -217,7 +229,13 @@ void CPlayerSource::WriteActionPacket(CNetworkMessage &nm)
}
// save sendbehind if needed
+#if PLATFORM_BIGENDIAN
+ tmp = iSendBehind;
+ BYTESWAP(tmp);
+ nm.WriteBits(&tmp, 2);
+#else
nm.WriteBits(&iSendBehind, 2);
+#endif
for(INDEX i=0; iSendToClient(iClient, nmPings);
@@ -1354,11 +1369,13 @@ void CServer::Handle(INDEX iClient, CNetworkMessage &nmMessage)
// see if saved in the message
BOOL bSaved = 0;
nmMessage.ReadBits(&bSaved, 1);
+ BYTESWAP(bSaved);
// if saved
if (bSaved) {
// read client index
INDEX iPlayer = 0;
nmMessage.ReadBits(&iPlayer, 4);
+ BYTESWAP(iPlayer);
CPlayerBuffer &plb = srv_aplbPlayers[iPlayer];
// if the player is not on that client
if (plb.plb_iClient!=iClient) {
@@ -1369,6 +1386,7 @@ void CServer::Handle(INDEX iClient, CNetworkMessage &nmMessage)
// read ping
plb.plb_iPing = 0;
nmMessage.ReadBits(&plb.plb_iPing, 10);
+ BYTESWAP(plb.plb_iPing);
// let the corresponding client buffer receive the message
INDEX iMaxBuffer = sso.sso_sspParams.ssp_iBufferActions;
extern INDEX cli_bPredictIfServer;
diff --git a/Sources/Engine/Network/SessionState.cpp b/Sources/Engine/Network/SessionState.cpp
index cdc3b9e..54a1cb5 100644
--- a/Sources/Engine/Network/SessionState.cpp
+++ b/Sources/Engine/Network/SessionState.cpp
@@ -43,6 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include
#include
#include
+#include
#define SESSIONSTATEVERSION_OLD 1
#define SESSIONSTATEVERSION_WITHBULLETTIME 2
@@ -1614,6 +1615,46 @@ void CSessionState::Read_t(CTStream *pstr) // throw char *
// read session properties from stream
(*pstr)>>_pNetwork->ga_strSessionName;
pstr->Read_t(_pNetwork->ga_aubProperties, NET_MAXSESSIONPROPERTIES);
+ CSessionProperties* psp = (CSessionProperties*)_pNetwork->ga_aubProperties;
+ BYTESWAP(psp->sp_ctMaxPlayers);
+ BYTESWAP(psp->sp_bWaitAllPlayers);
+ BYTESWAP(psp->sp_bQuickTest);
+ BYTESWAP(psp->sp_bCooperative);
+ BYTESWAP(psp->sp_bSinglePlayer);
+ BYTESWAP(psp->sp_bUseFrags);
+ BYTESWAP((INDEX&)psp->sp_gmGameMode);
+ BYTESWAP((INDEX&)psp->sp_gdGameDifficulty);
+ BYTESWAP(psp->sp_ulSpawnFlags);
+ BYTESWAP(psp->sp_bMental);
+ BYTESWAP(psp->sp_iScoreLimit);
+ BYTESWAP(psp->sp_iFragLimit);
+ BYTESWAP(psp->sp_iTimeLimit);
+ BYTESWAP(psp->sp_bTeamPlay);
+ BYTESWAP(psp->sp_bFriendlyFire);
+ BYTESWAP(psp->sp_bWeaponsStay);
+ BYTESWAP(psp->sp_bAmmoStays);
+ BYTESWAP(psp->sp_bHealthArmorStays);
+ BYTESWAP(psp->sp_bPlayEntireGame);
+ BYTESWAP(psp->sp_bAllowHealth);
+ BYTESWAP(psp->sp_bAllowArmor);
+ BYTESWAP(psp->sp_bInfiniteAmmo);
+ BYTESWAP(psp->sp_bRespawnInPlace);
+ BYTESWAP(psp->sp_fEnemyMovementSpeed);
+ BYTESWAP(psp->sp_fEnemyAttackSpeed);
+ BYTESWAP(psp->sp_fDamageStrength);
+ BYTESWAP(psp->sp_fAmmoQuantity);
+ BYTESWAP(psp->sp_fManaTransferFactor);
+ BYTESWAP(psp->sp_iInitialMana);
+ BYTESWAP(psp->sp_fExtraEnemyStrength);
+ BYTESWAP(psp->sp_fExtraEnemyStrengthPerPlayer);
+ BYTESWAP(psp->sp_ctCredits);
+ BYTESWAP(psp->sp_ctCreditsLeft);
+ BYTESWAP(psp->sp_tmSpawnInvulnerability);
+ BYTESWAP(psp->sp_iBlood);
+ BYTESWAP(psp->sp_bGibs);
+ BYTESWAP(psp->sp_bEndOfGame);
+ BYTESWAP(psp->sp_ulLevelsMask);
+ BYTESWAP(psp->sp_bUseExtraEnemies);
// read world and its state
ReadWorldAndState_t(pstr);
@@ -1764,7 +1805,48 @@ void CSessionState::Write_t(CTStream *pstr) // throw char *
(*pstr)<ga_strSessionName;
- pstr->Write_t(_pNetwork->ga_aubProperties, NET_MAXSESSIONPROPERTIES);
+ CUniversalSessionProperties sp;
+ memcpy(&sp, _pNetwork->ga_aubProperties, NET_MAXSESSIONPROPERTIES);
+ BYTESWAP(sp.usp_sp.sp_ctMaxPlayers);
+ BYTESWAP(sp.usp_sp.sp_bWaitAllPlayers);
+ BYTESWAP(sp.usp_sp.sp_bQuickTest);
+ BYTESWAP(sp.usp_sp.sp_bCooperative);
+ BYTESWAP(sp.usp_sp.sp_bSinglePlayer);
+ BYTESWAP(sp.usp_sp.sp_bUseFrags);
+ BYTESWAP((INDEX&)sp.usp_sp.sp_gmGameMode);
+ BYTESWAP((INDEX&)sp.usp_sp.sp_gdGameDifficulty);
+ BYTESWAP(sp.usp_sp.sp_ulSpawnFlags);
+ BYTESWAP(sp.usp_sp.sp_bMental);
+ BYTESWAP(sp.usp_sp.sp_iScoreLimit);
+ BYTESWAP(sp.usp_sp.sp_iFragLimit);
+ BYTESWAP(sp.usp_sp.sp_iTimeLimit);
+ BYTESWAP(sp.usp_sp.sp_bTeamPlay);
+ BYTESWAP(sp.usp_sp.sp_bFriendlyFire);
+ BYTESWAP(sp.usp_sp.sp_bWeaponsStay);
+ BYTESWAP(sp.usp_sp.sp_bAmmoStays);
+ BYTESWAP(sp.usp_sp.sp_bHealthArmorStays);
+ BYTESWAP(sp.usp_sp.sp_bPlayEntireGame);
+ BYTESWAP(sp.usp_sp.sp_bAllowHealth);
+ BYTESWAP(sp.usp_sp.sp_bAllowArmor);
+ BYTESWAP(sp.usp_sp.sp_bInfiniteAmmo);
+ BYTESWAP(sp.usp_sp.sp_bRespawnInPlace);
+ BYTESWAP(sp.usp_sp.sp_fEnemyMovementSpeed);
+ BYTESWAP(sp.usp_sp.sp_fEnemyAttackSpeed);
+ BYTESWAP(sp.usp_sp.sp_fDamageStrength);
+ BYTESWAP(sp.usp_sp.sp_fAmmoQuantity);
+ BYTESWAP(sp.usp_sp.sp_fManaTransferFactor);
+ BYTESWAP(sp.usp_sp.sp_iInitialMana);
+ BYTESWAP(sp.usp_sp.sp_fExtraEnemyStrength);
+ BYTESWAP(sp.usp_sp.sp_fExtraEnemyStrengthPerPlayer);
+ BYTESWAP(sp.usp_sp.sp_ctCredits);
+ BYTESWAP(sp.usp_sp.sp_ctCreditsLeft);
+ BYTESWAP(sp.usp_sp.sp_tmSpawnInvulnerability);
+ BYTESWAP(sp.usp_sp.sp_iBlood);
+ BYTESWAP(sp.usp_sp.sp_bGibs);
+ BYTESWAP(sp.usp_sp.sp_bEndOfGame);
+ BYTESWAP(sp.usp_sp.sp_ulLevelsMask);
+ BYTESWAP(sp.usp_sp.sp_bUseExtraEnemies);
+ pstr->Write_t(&sp, NET_MAXSESSIONPROPERTIES);
// write world and its state
WriteWorldAndState_t(pstr);
@@ -2003,10 +2085,12 @@ void CSessionState::SessionStateLoop(void)
CPlayerTarget &plt = ses_apltPlayers[i];
BOOL bHas = 0;
nmMessage.ReadBits(&bHas, 1);
+ BYTESWAP(bHas);
if (bHas) {
if (plt.IsActive() && plt.plt_penPlayerEntity!=NULL) {
INDEX iPing = 0;
nmMessage.ReadBits(&iPing, 10);
+ BYTESWAP(iPing);
plt.plt_penPlayerEntity->en_tmPing = iPing/1000.0f;
}
}
diff --git a/Sources/Engine/Ska/AnimSet.cpp b/Sources/Engine/Ska/AnimSet.cpp
index 3dd133f..37a3d6d 100644
--- a/Sources/Engine/Ska/AnimSet.cpp
+++ b/Sources/Engine/Ska/AnimSet.cpp
@@ -396,7 +396,10 @@ void CAnimSet::Write_t(CTStream *ostrFile)
// write bone envelope ID
(*ostrFile)<Write_t(&be.be_mDefaultPos[0],sizeof(FLOAT)*12);
+ for(int i = 0; i < 12; i++)
+ {
+ (*ostrFile)<Write_t(&be.be_apPos[ip],sizeof(AnimPos));
+ (*ostrFile)<Write_t(&arRot,sizeof(AnimRot));
+ (*ostrFile)<0)
@@ -439,7 +442,10 @@ void CAnimSet::Write_t(CTStream *ostrFile)
// write morph factors count
INDEX ctmf = me.me_aFactors.Count();
(*ostrFile)<Write_t(&me.me_aFactors[0],sizeof(FLOAT)*ctmf);
+ for(int i = 0; i < ctmf; i++)
+ {
+ (*ostrFile)<Write_t(&mLod.mlod_aVertices[0],sizeof(MeshVertex)*ctVx);
+ for (int i = 0; i < ctVx; i++) (*ostrFile)<<(MeshVertex)mLod.mlod_aVertices[i];
// write normals
- ostrFile->Write_t(&mLod.mlod_aNormals[0],sizeof(MeshNormal)*ctVx);
+ for (int i = 0; i < ctVx; i++) (*ostrFile)<<(MeshNormal)mLod.mlod_aNormals[i];
// write uvmaps count
(*ostrFile)<Write_t(&mLod.mlod_aUVMaps[iuv].muv_aTexCoords[0],sizeof(MeshTexCoord)*ctVx);
+ for (int i = 0; i < ctVx; i++) (*ostrFile)<<(MeshTexCoord)mLod.mlod_aUVMaps[iuv].muv_aTexCoords[i];
}
// write surfaces count
- ostrFile->Write_t(&ctSf,sizeof(INDEX));
+ (*ostrFile)<Write_t(&mLod.mlod_aSurfaces[isf].msrf_aTriangles[0],sizeof(MeshTriangle)*ctTris);
+ for (int i = 0; i < ctTris; i++) (*ostrFile)<<(MeshTriangle)mLod.mlod_aSurfaces[isf].msrf_aTriangles[i];
// write bool that this surface has a shader
INDEX bShaderExists = (msrf.msrf_pShader!=NULL);
@@ -652,7 +652,7 @@ void CMesh::Write_t(CTStream *ostrFile)
// write wertex weights count
(*ostrFile)<Write_t(&mLod.mlod_aWeightMaps[iwm].mwm_aVertexWeight[0],sizeof(MeshVertexWeight)*ctWw);
+ for (int i = 0; i < ctWw; i++) (*ostrFile)<<(MeshVertexWeight)mLod.mlod_aWeightMaps[ctWw].mwm_aVertexWeight[i];
}
// write morphmaps count
@@ -667,9 +667,9 @@ void CMesh::Write_t(CTStream *ostrFile)
(*ostrFile)<Write_t(&mLod.mlod_aMorphMaps[imm].mmp_bRelative,sizeof(BOOL));
// write morph sets count
- ostrFile->Write_t(&ctms,sizeof(INDEX));
+ (*ostrFile)<Write_t(&mLod.mlod_aMorphMaps[imm].mmp_aMorphMap[0],sizeof(MeshVertexMorph)*ctms);
+ for (int i = 0; i < ctms; i++) (*ostrFile)<>(CTStream &strm, MeshVertex &mv)
return(strm);
}
-static inline CTStream &operator>>(CTStream &strm, const MeshVertex &mv)
+static inline CTStream &operator<<(CTStream &strm, const MeshVertex &mv)
{
strm<>(CTStream &strm, MeshNormal &mn)
return(strm);
}
-static inline CTStream &operator>>(CTStream &strm, const MeshNormal &mn)
+static inline CTStream &operator<<(CTStream &strm, const MeshNormal &mn)
{
strm<>(CTStream &strm, MeshVertexMorph &mwm)
return(strm);
}
-static inline CTStream &operator>>(CTStream &strm, const MeshVertexMorph &mwm)
+static inline CTStream &operator<<(CTStream &strm, const MeshVertexMorph &mwm)
{
strm<Write_t(&sb.sb_mAbsPlacement,sizeof(FLOAT)*12);
+ for (int i = 0; i < 12; i++) (*ostrFile)<Write_t(&sb.sb_qvRelPlacement,sizeof(QVect));
+ (*ostrFile)<ogg_vfVorbisFile, pch, ctBytesToDecode-ctDecoded, &iCurrrentSection);
#else
long iRes = pov_read(sdc_pogg->ogg_vfVorbisFile, pch, ctBytesToDecode-ctDecoded,
- 0, 2, 1, &iCurrrentSection);
+ PLATFORM_BIGENDIAN, 2, 1, &iCurrrentSection);
#endif
if (iRes<=0) {
return ctDecoded;
diff --git a/Sources/Engine/Sound/SoundLibrary.cpp b/Sources/Engine/Sound/SoundLibrary.cpp
index 7f518f6..abade44 100644
--- a/Sources/Engine/Sound/SoundLibrary.cpp
+++ b/Sources/Engine/Sound/SoundLibrary.cpp
@@ -219,9 +219,9 @@ static BOOL StartUp_SDLaudio( CSoundLibrary &sl, BOOL bReport=TRUE)
if (bps <= 8)
desired.format = AUDIO_U8;
else if (bps <= 16)
- desired.format = AUDIO_S16LSB;
+ desired.format = AUDIO_S16SYS;
else if (bps <= 32)
- desired.format = AUDIO_S32LSB;
+ desired.format = AUDIO_S32SYS;
else {
CPrintF(TRANSV("Unsupported bits-per-sample: %d\n"), bps);
return FALSE;
diff --git a/Sources/Engine/Terrain/Terrain.cpp b/Sources/Engine/Terrain/Terrain.cpp
index 9af3da6..70cb2ac 100644
--- a/Sources/Engine/Terrain/Terrain.cpp
+++ b/Sources/Engine/Terrain/Terrain.cpp
@@ -1972,10 +1972,12 @@ void CTerrain::Write_t( CTStream *ostrFile)
INDEX iShadingMapSize = GetShadingMapWidth() * GetShadingMapHeight() * sizeof(UWORD);
// Write shadow map
ASSERT(tr_tdShadowMap.td_pulFrames!=NULL);
- ostrFile->Write_t(&tr_tdShadowMap.td_pulFrames[0],iShadowMapSize);
+ for (INDEX i = 0; i < iShadowMapSize; i++)
+ (*ostrFile)<Write_t(&tr_auwShadingMap[0],iShadingMapSize);
+ for (INDEX i = 0; i < iShadingMapSize; i++)
+ (*ostrFile)<WriteID_t("TSEN"); // 'Terrain shadowmap end'
@@ -1989,7 +1991,7 @@ void CTerrain::Write_t( CTStream *ostrFile)
(*ostrFile).WriteID_t("TRHM"); // 'Terrain heightmap'
// write height map
- (*ostrFile).Write_t(&tr_auwHeightMap[0],sizeof(UWORD)*tr_pixHeightMapWidth*tr_pixHeightMapHeight);
+ for (int i = 0; i < (tr_pixHeightMapWidth * tr_pixHeightMapHeight); i++) (*ostrFile)<>(CTStream &strm, PlayerStats &ps)
+{
+ strm>>ps.ps_iScore;
+ strm>>ps.ps_iKills;
+ strm>>ps.ps_iDeaths;
+ strm>>ps.ps_iSecrets;
+ strm>>ps.ps_tmTime;
+ return strm;
+}
+
+static inline CTStream &operator<<(CTStream &strm, const PlayerStats &ps)
+{
+ strm<Write_t(&m_psLevelStats, sizeof(m_psLevelStats));
- ostr->Write_t(&m_psLevelTotal, sizeof(m_psLevelTotal));
- ostr->Write_t(&m_psGameStats , sizeof(m_psGameStats ));
- ostr->Write_t(&m_psGameTotal , sizeof(m_psGameTotal ));
+ (*ostr)<Read_t(&m_psLevelStats, sizeof(m_psLevelStats));
- istr->Read_t(&m_psLevelTotal, sizeof(m_psLevelTotal));
- istr->Read_t(&m_psGameStats , sizeof(m_psGameStats ));
- istr->Read_t(&m_psGameTotal , sizeof(m_psGameTotal ));
+ (*istr)>>m_psLevelStats;
+ (*istr)>>m_psLevelTotal;
+ (*istr)>>m_psGameStats;
+ (*istr)>>m_psGameTotal;
// set your real appearance if possible
ValidateCharacter();
diff --git a/Sources/EntitiesMP/Player.es b/Sources/EntitiesMP/Player.es
index ffb45c8..c972df4 100755
--- a/Sources/EntitiesMP/Player.es
+++ b/Sources/EntitiesMP/Player.es
@@ -1530,10 +1530,10 @@ functions:
for(INDEX iMsg=0; iMsgWrite_t(&m_psLevelStats, sizeof(m_psLevelStats));
- ostr->Write_t(&m_psLevelTotal, sizeof(m_psLevelTotal));
- ostr->Write_t(&m_psGameStats , sizeof(m_psGameStats ));
- ostr->Write_t(&m_psGameTotal , sizeof(m_psGameTotal ));
+ (*ostr)<