void asCRestore::WriteByteCode(asDWORD *bc, int length) { while( length ) { asDWORD c = (*bc)&0xFF; WRITE_NUM(*bc); bc += 1; if( c == BC_ALLOC || c == BC_FREE || c == BC_REFCPY || c == BC_OBJTYPE ) { // Translate object type pointers into indices asDWORD tmp[MAX_DATA_SIZE]; int n; for( n = 0; n < asCByteCode::SizeOfType(bcTypes[c])-1; n++ ) tmp[n] = *bc++; *(int*)tmp = FindObjectTypeIdx(*(asCObjectType**)tmp); for( n = 0; n < asCByteCode::SizeOfType(bcTypes[c])-1; n++ ) WRITE_NUM(tmp[n]); } else if( c == BC_TYPEID ) { // Translate type ids into indices asDWORD tmp[MAX_DATA_SIZE]; int n; for( n = 0; n < asCByteCode::SizeOfType(bcTypes[c])-1; n++ ) tmp[n] = *bc++; *(int*)tmp = FindTypeIdIdx(*(int*)tmp); for( n = 0; n < asCByteCode::SizeOfType(bcTypes[c])-1; n++ ) WRITE_NUM(tmp[n]); } else { // Store the bc as is for( int n = 1; n < asCByteCode::SizeOfType(bcTypes[c]); n++ ) WRITE_NUM(*bc++); } length -= asCByteCode::SizeOfType(bcTypes[c]); } }
void asCRestore::WriteByteCode(asDWORD *bc, int length) { while( length ) { asDWORD c = *(asBYTE*)bc; WRITE_NUM(*bc); bc += 1; if( c == asBC_ALLOC ) { asDWORD tmp[MAX_DATA_SIZE]; int n; for( n = 0; n < asBCTypeSize[asBCInfo[c].type]-1; n++ ) tmp[n] = *bc++; // Translate the object type asCObjectType *ot = *(asCObjectType**)tmp; *(int*)tmp = FindObjectTypeIdx(ot); // Translate the constructor func id, if it is a script class if( ot->flags & asOBJ_SCRIPT_OBJECT ) *(int*)&tmp[AS_PTR_SIZE] = FindFunctionIndex(engine->scriptFunctions[*(int*)&tmp[AS_PTR_SIZE]]); for( n = 0; n < asBCTypeSize[asBCInfo[c].type]-1; n++ ) WRITE_NUM(tmp[n]); } else if( c == asBC_FREE || c == asBC_REFCPY || c == asBC_OBJTYPE ) { // Translate object type pointers into indices asDWORD tmp[MAX_DATA_SIZE]; int n; for( n = 0; n < asBCTypeSize[asBCInfo[c].type]-1; n++ ) tmp[n] = *bc++; *(int*)tmp = FindObjectTypeIdx(*(asCObjectType**)tmp); for( n = 0; n < asBCTypeSize[asBCInfo[c].type]-1; n++ ) WRITE_NUM(tmp[n]); } else if( c == asBC_TYPEID ) { // Translate type ids into indices asDWORD tmp[MAX_DATA_SIZE]; int n; for( n = 0; n < asBCTypeSize[asBCInfo[c].type]-1; n++ ) tmp[n] = *bc++; *(int*)tmp = FindTypeIdIdx(*(int*)tmp); for( n = 0; n < asBCTypeSize[asBCInfo[c].type]-1; n++ ) WRITE_NUM(tmp[n]); } else if( c == asBC_CALL || c == asBC_CALLINTF || c == asBC_CALLSYS ) { // Translate the function id asDWORD tmp[MAX_DATA_SIZE]; int n; for( n = 0; n < asBCTypeSize[asBCInfo[c].type]-1; n++ ) tmp[n] = *bc++; *(int*)tmp = FindFunctionIndex(engine->scriptFunctions[*(int*)tmp]); for( n = 0; n < asBCTypeSize[asBCInfo[c].type]-1; n++ ) WRITE_NUM(tmp[n]); } else { // Store the bc as is for( int n = 1; n < asBCTypeSize[asBCInfo[c].type]; n++ ) WRITE_NUM(*bc++); } length -= asBCTypeSize[asBCInfo[c].type]; } }