Please exchange the methods asCRestore::WriteObjectType and ReadObjectType for the following:
void asCRestore::WriteObjectType(asCObjectType* ot) { char ch; // Only write the object type name if( ot ) { // Check for template instances/specializations if( ot->templateSubType.GetTokenType() != ttUnrecognizedToken && ot != engine->defaultArrayObjectType ) { ch = 'a'; WRITE_NUM(ch); WriteString(&ot->name); if( ot->templateSubType.IsObject() ) { ch = 's'; WRITE_NUM(ch); WriteObjectType(ot->templateSubType.GetObjectType()); if( ot->templateSubType.IsObjectHandle() ) ch = 'h'; else ch = 'o'; WRITE_NUM(ch); } else { ch = 't'; WRITE_NUM(ch); eTokenType t = ot->templateSubType.GetTokenType(); WRITE_NUM(t); } } else if( ot->flags & asOBJ_TEMPLATE_SUBTYPE ) { ch = 's'; WRITE_NUM(ch); WriteString(&ot->name); } else { ch = 'o'; WRITE_NUM(ch); WriteString(&ot->name); } } else { ch = '\0'; WRITE_NUM(ch); }}asCObjectType* asCRestore::ReadObjectType() { asCObjectType *ot; char ch; READ_NUM(ch); if( ch == 'a' ) { // Read the name of the template type asCString typeName; ReadString(&typeName); asCObjectType *tmpl = engine->GetObjectType(typeName.AddressOf()); READ_NUM(ch); if( ch == 's' ) { ot = ReadObjectType(); asCDataType dt = asCDataType::CreateObject(ot, false); READ_NUM(ch); if( ch == 'h' ) dt.MakeHandle(true); if( tmpl->templateSubType.GetObjectType() == ot ) ot = tmpl; else ot = engine->GetTemplateInstanceType(tmpl, dt); asASSERT(ot); } else { eTokenType tokenType; READ_NUM(tokenType); asCDataType dt = asCDataType::CreatePrimitive(tokenType, false); ot = engine->GetTemplateInstanceType(tmpl, dt); asASSERT(ot); } } else if( ch == 's' ) { // Read the name of the template subtype asCString typeName; ReadString(&typeName); // Find the template subtype for( asUINT n = 0; n < engine->templateSubTypes.GetLength(); n++ ) { if( engine->templateSubTypes[n] && engine->templateSubTypes[n]->name == typeName ) { ot = engine->templateSubTypes[n]; break; } } // TODO: Should give a friendly error in case the template type isn't found asASSERT(ot); } else if( ch == 'o' ) { // Read the object type name asCString typeName; ReadString(&typeName); if( typeName.GetLength() && typeName != "_builtin_object_" && typeName != "_builtin_function_" ) { // Find the object type ot = module->GetObjectType(typeName.AddressOf()); if( !ot ) ot = engine->GetObjectType(typeName.AddressOf()); asASSERT(ot); } else if( typeName == "_builtin_object_" ) { ot = &engine->scriptTypeBehaviours; } else if( typeName == "_builtin_function_" ) { ot = &engine->functionBehaviours; } else assert( false ); } else { // No object type assert( ch == '\0' ); ot = 0; } return ot;}