diff --git a/neo/d3xp/script/Script_Interpreter.cpp b/neo/d3xp/script/Script_Interpreter.cpp index b14b903b..643884a1 100644 --- a/neo/d3xp/script/Script_Interpreter.cpp +++ b/neo/d3xp/script/Script_Interpreter.cpp @@ -785,11 +785,22 @@ void idInterpreter::CallEvent( const function_t *func, int argsize ) { switch( format[ i ] ) { case D_EVENT_INTEGER : var.intPtr = ( int * )&localstack[ start + pos ]; - ( *( int * )&data[ i ] ) = int( *var.floatPtr ); + //( *( int * )&data[ i ] ) = int( *var.floatPtr ); + // DG: for int/intrptr_t arguments, the callbacks from Callbacks.cpp pass + // data[i] directly, not *(int*)&data[i] or some nonsense like that + // so the integer must be assigned to the intptr_t for the value to be + // passed correctly, esp. on 64bit Big Endian machines. + data[ i ] = int( *var.floatPtr ); break; case D_EVENT_FLOAT : var.intPtr = ( int * )&localstack[ start + pos ]; + // NOTE: floats are the only type not passed as int or pointer in intptr_t, + // but as float-data in the first 4 bytes of data[i]. + // So (unlike in the other cases), here this awkward code casting &data[i] + // to another pointer type is actually necessary (same in CallSysEvent()). + // In the other cases one could also use `data[i] = (intptr_t)var.blaPtr;` + // (not doing those changes here now to minimize potential merge conflicts) ( *( float * )&data[ i ] ) = *var.floatPtr; break; @@ -915,7 +926,12 @@ void idInterpreter::CallSysEvent( const function_t *func, int argsize ) { switch( format[ i ] ) { case D_EVENT_INTEGER : source.intPtr = ( int * )&localstack[ start + pos ]; - *( int * )&data[ i ] = int( *source.floatPtr ); + //*( int * )&data[ i ] = int( *source.floatPtr ); + // DG: for int/intrptr_t arguments, the callbacks from Callbacks.cpp pass + // data[i] directly, not *(int*)&data[i] or some nonsense like that + // so the integer must be assigned to the intptr_t for the value to be + // passed correctly, esp. on 64bit Big Endian machines. + data[ i ] = int( *source.floatPtr ); break; case D_EVENT_FLOAT : diff --git a/neo/game/script/Script_Interpreter.cpp b/neo/game/script/Script_Interpreter.cpp index 48668d3e..6da5bdf2 100644 --- a/neo/game/script/Script_Interpreter.cpp +++ b/neo/game/script/Script_Interpreter.cpp @@ -785,11 +785,22 @@ void idInterpreter::CallEvent( const function_t *func, int argsize ) { switch( format[ i ] ) { case D_EVENT_INTEGER : var.intPtr = ( int * )&localstack[ start + pos ]; - ( *( int * )&data[ i ] ) = int( *var.floatPtr ); + //( *( int * )&data[ i ] ) = int( *var.floatPtr ); + // DG: for int/intrptr_t arguments, the callbacks from Callbacks.cpp pass + // data[i] directly, not *(int*)&data[i] or some nonsense like that + // so the integer must be assigned to the intptr_t for the value to be + // passed correctly, esp. on 64bit Big Endian machines. + data[ i ] = int( *var.floatPtr ); break; case D_EVENT_FLOAT : var.intPtr = ( int * )&localstack[ start + pos ]; + // NOTE: floats are the only type not passed as int or pointer in intptr_t, + // but as float-data in the first 4 bytes of data[i]. + // So (unlike in the other cases), here this awkward code casting &data[i] + // to another pointer type is actually necessary (same in CallSysEvent()). + // In the other cases one could also use `data[i] = (intptr_t)var.blaPtr;` + // (not doing those changes here now to minimize potential merge conflicts) ( *( float * )&data[ i ] ) = *var.floatPtr; break; @@ -915,7 +926,12 @@ void idInterpreter::CallSysEvent( const function_t *func, int argsize ) { switch( format[ i ] ) { case D_EVENT_INTEGER : source.intPtr = ( int * )&localstack[ start + pos ]; - *( int * )&data[ i ] = int( *source.floatPtr ); + //*( int * )&data[ i ] = int( *source.floatPtr ); + // DG: for int/intrptr_t arguments, the callbacks from Callbacks.cpp pass + // data[i] directly, not *(int*)&data[i] or some nonsense like that + // so the integer must be assigned to the intptr_t for the value to be + // passed correctly, esp. on 64bit Big Endian machines. + data[ i ] = int( *source.floatPtr ); break; case D_EVENT_FLOAT :