From fd38243b54941aa8314456d20a6c15df7759d2db Mon Sep 17 00:00:00 2001 From: hymei <824395314@qq.com> Date: Wed, 2 Mar 2022 23:55:50 +0800 Subject: [PATCH] arm64 ptr size fix --- common/studiobyteswap.cpp | 9 +++++++ engine/cl_parse_event.cpp | 4 +-- .../hl2/c_info_teleporter_countdown.cpp | 2 +- public/sentence.cpp | 5 +++- public/studio.h | 25 ++++++++++++++++--- public/tier1/utllinkedlist.h | 2 +- tier0/cpu_posix.cpp | 2 +- 7 files changed, 39 insertions(+), 10 deletions(-) diff --git a/common/studiobyteswap.cpp b/common/studiobyteswap.cpp index 30b3383e..0e4f8fd1 100644 --- a/common/studiobyteswap.cpp +++ b/common/studiobyteswap.cpp @@ -2918,8 +2918,13 @@ BEGIN_BYTESWAP_DATADESC( mstudiomodel_t ) END_BYTESWAP_DATADESC() BEGIN_BYTESWAP_DATADESC( mstudio_modelvertexdata_t ) +#ifdef PLATFORM_64BITS + DEFINE_FIELD( unused_pVertexData, FIELD_INTEGER ), // void* + DEFINE_FIELD( unused_pTangentData, FIELD_INTEGER ), // void* +#else DEFINE_FIELD( pVertexData, FIELD_INTEGER ), // void* DEFINE_FIELD( pTangentData, FIELD_INTEGER ), // void* +#endif END_BYTESWAP_DATADESC() BEGIN_BYTESWAP_DATADESC( mstudioflexdesc_t ) @@ -2998,7 +3003,11 @@ BEGIN_BYTESWAP_DATADESC( mstudiomesh_t ) END_BYTESWAP_DATADESC() BEGIN_BYTESWAP_DATADESC( mstudio_meshvertexdata_t ) +#ifdef PLATFORM_64BITS + DEFINE_FIELD( unused_modelvertexdata, FIELD_INTEGER ), // mstudio_modelvertexdata_t* +#else DEFINE_FIELD( modelvertexdata, FIELD_INTEGER ), // mstudio_modelvertexdata_t* +#endif DEFINE_ARRAY( numLODVertexes, FIELD_INTEGER, MAX_NUM_LODS ), END_BYTESWAP_DATADESC() diff --git a/engine/cl_parse_event.cpp b/engine/cl_parse_event.cpp index 183d763f..bd1eed0b 100644 --- a/engine/cl_parse_event.cpp +++ b/engine/cl_parse_event.cpp @@ -18,7 +18,7 @@ static ConVar cl_showevents ( "cl_showevents", "0", FCVAR_CHEAT, "Print event fi // Input : slot - // *eventname - //----------------------------------------------------------------------------- -void CL_DescribeEvent( int slot, CEventInfo *event, const char *eventname ) +void CL_DescribeEvent( intp slot, CEventInfo *event, const char *eventname ) { int idx = (slot & 31); @@ -81,7 +81,7 @@ void CL_FireEvents( void ) return; } - int i, next; + intp i, next; for ( i = cl.events.Head(); i != cl.events.InvalidIndex(); i = next ) { next = cl.events.Next( i ); diff --git a/game/client/hl2/c_info_teleporter_countdown.cpp b/game/client/hl2/c_info_teleporter_countdown.cpp index e99277c9..d8ba5b2c 100644 --- a/game/client/hl2/c_info_teleporter_countdown.cpp +++ b/game/client/hl2/c_info_teleporter_countdown.cpp @@ -141,7 +141,7 @@ void CTeleportCountdownScreen::OnTick() // Find the active info teleporter countdown C_InfoTeleporterCountdown *pActiveCountdown = NULL; - for ( int i = g_InfoTeleporterCountdownList.Head(); i != g_InfoTeleporterCountdownList.InvalidIndex(); + for ( intp i = g_InfoTeleporterCountdownList.Head(); i != g_InfoTeleporterCountdownList.InvalidIndex(); i = g_InfoTeleporterCountdownList.Next(i) ) { if ( g_InfoTeleporterCountdownList[i]->m_bCountdownStarted ) diff --git a/public/sentence.cpp b/public/sentence.cpp index 251ca25a..49994780 100644 --- a/public/sentence.cpp +++ b/public/sentence.cpp @@ -345,7 +345,9 @@ unsigned int CPhonemeTag::ComputeDataCheckSum() //----------------------------------------------------------------------------- // Purpose: Simple language to string and string to language lookup dictionary //----------------------------------------------------------------------------- +#if defined(__i386__) || defined(__x86_64__) #pragma pack(1) +#endif struct CCLanguage { @@ -369,8 +371,9 @@ static CCLanguage g_CCLanguageLookup[] = { CC_THAI, "thai", 0 , 150, 250 }, { CC_PORTUGUESE,"portuguese", 0 , 0, 150 }, }; - +#if defined(__i386__) || defined(__x86_64__) #pragma pack() +#endif void CSentence::ColorForLanguage( int language, unsigned char& r, unsigned char& g, unsigned char& b ) { diff --git a/public/studio.h b/public/studio.h index 9829de8d..b02c2d48 100644 --- a/public/studio.h +++ b/public/studio.h @@ -1292,8 +1292,15 @@ struct mstudio_modelvertexdata_t int GetGlobalTangentIndex( int i ) const; // base of external vertex data stores +#ifdef PLATFORM_64BITS + int unused_pVertexData; + int unused_pTangentData; + const void *pVertexData; + const void *pTangentData; +#else const void *pVertexData; const void *pTangentData; +#endif }; #ifdef PLATFORM_64BITS @@ -1314,12 +1321,19 @@ struct mstudio_meshvertexdata_t int GetModelVertexIndex( int i ) const; int GetGlobalVertexIndex( int i ) const; +#ifdef PLATFORM_64BITS + // MoeMod : fix 64bit ptr size + int unused_modelvertexdata; + int numLODVertexes[MAX_NUM_LODS]; + const mstudio_modelvertexdata_t *modelvertexdata; +#else // indirection to this mesh's model's vertex data const mstudio_modelvertexdata_t *modelvertexdata; // used for fixup calcs when culling top level lods // expected number of mesh verts at desired lod int numLODVertexes[MAX_NUM_LODS]; +#endif }; struct mstudiomesh_t @@ -1353,7 +1367,7 @@ struct mstudiomesh_t #ifdef PLATFORM_64BITS mstudio_meshvertexdata_t vertexdata; - int unused[7]; // remove as appropriate + int unused[6]; // remove as appropriate #else mstudio_meshvertexdata_t vertexdata; @@ -1424,14 +1438,16 @@ inline bool mstudio_modelvertexdata_t::HasTangentData( void ) const inline int mstudio_modelvertexdata_t::GetGlobalVertexIndex( int i ) const { mstudiomodel_t *modelptr = (mstudiomodel_t *)((byte *)this - offsetof(mstudiomodel_t, vertexdata)); - //Assert( ( modelptr->vertexindex % sizeof( mstudiovertex_t ) ) == 0 ); + Assert(&modelptr->vertexdata == this); + Assert( ( modelptr->vertexindex % sizeof( mstudiovertex_t ) ) == 0 ); return ( i + ( modelptr->vertexindex / sizeof( mstudiovertex_t ) ) ); } inline int mstudio_modelvertexdata_t::GetGlobalTangentIndex( int i ) const { mstudiomodel_t *modelptr = (mstudiomodel_t *)((byte *)this - offsetof(mstudiomodel_t, vertexdata)); - //Assert( ( modelptr->tangentsindex % sizeof( Vector4D ) ) == 0 ); + Assert(&modelptr->vertexdata == this); + Assert( ( modelptr->tangentsindex % sizeof( Vector4D ) ) == 0 ); return ( i + ( modelptr->tangentsindex / sizeof( Vector4D ) ) ); } @@ -1499,7 +1515,8 @@ inline const thinModelVertices_t * mstudiomesh_t::GetThinVertexData( void *pMode inline int mstudio_meshvertexdata_t::GetModelVertexIndex( int i ) const { - mstudiomesh_t *meshptr = (mstudiomesh_t *)((byte *)this - offsetof(mstudiomesh_t,vertexdata)); + mstudiomesh_t *meshptr = (mstudiomesh_t *)((byte *)this - offsetof(mstudiomesh_t,vertexdata)); + Assert(&meshptr->vertexdata == this); return meshptr->vertexoffset + i; } diff --git a/public/tier1/utllinkedlist.h b/public/tier1/utllinkedlist.h index 04872008..2e201805 100644 --- a/public/tier1/utllinkedlist.h +++ b/public/tier1/utllinkedlist.h @@ -24,7 +24,7 @@ // This is a useful macro to iterate from head to tail in a linked list. #define FOR_EACH_LL( listName, iteratorName ) \ - for( int iteratorName=(listName).Head(); (listName).IsUtlLinkedList && iteratorName != (listName).InvalidIndex(); iteratorName = (listName).Next( iteratorName ) ) + for( auto iteratorName=(listName).Head(); (listName).IsUtlLinkedList && iteratorName != (listName).InvalidIndex(); iteratorName = (listName).Next( iteratorName ) ) //----------------------------------------------------------------------------- // class CUtlLinkedList: diff --git a/tier0/cpu_posix.cpp b/tier0/cpu_posix.cpp index 094bc435..2b158947 100644 --- a/tier0/cpu_posix.cpp +++ b/tier0/cpu_posix.cpp @@ -105,7 +105,7 @@ uint64 CalculateCPUFreq() int retval = sysctlbyname("hw.cpufrequency_max", &freq_hz, &freq_size, NULL, 0); // MoeMod : TODO dont know how to get freq on Apple Silicon if(!freq_hz) - freq_hz = 3200000; + freq_hz = 3200000000; return freq_hz; #else // Try to open cpuinfo_max_freq. If the kernel was built with cpu scaling support disabled, this will fail.