Advertisement
Guest User

StreamingPartitionReader::handleLayout

a guest
Jun 14th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.12 KB | None | 0 0
  1. void __thiscall fb::StreamingPartitionReader::handleLayout(fb::StreamingPartitionReader *this)
  2. {
  3.   fb::StreamingPartitionReader *streamingPartitionReader; // esi@1
  4.   fb::TypeInfo **startTypeInfo; // edx@1
  5.   unsigned int numTypeDescriptors; // eax@1
  6.   const fb::TypeInfo *typeInfo; // ecx@1
  7.   fb::TypeInfo *nextTypeInfo; // edi@1
  8.   fb::StreamingPartitionInstanceEntry *currInstance; // edi@6
  9.   unsigned int *currInstanceNameHash; // ebx@6
  10.   fb::ClassInfo *classInfo; // eax@6
  11.   const char *metaString; // ebx@7
  12.   fb::OutAsciiStream *outStream; // eax@8
  13.   unsigned int v11; // edi@12
  14.   fb::TypeInfo **startTypeInfo2; // eax@15
  15.   fb::StreamingPartitionTypeDescriptor *currType; // edi@20
  16.   fb::DataContainerClassInfo *dataContainerClassInfo; // eax@21
  17.   fb::LayoutDescriptor *layoutDescriptor; // eax@21
  18.   fb::ValueTypeInfo *valueTypeInfo; // ebx@22
  19.   int currIndex; // eax@22
  20.   fb::LayoutDescriptor *layoutDescriptor2; // eax@26
  21.   unsigned __int8 currAlign; // al@26
  22.   char currAlign2; // cl@26
  23.   fb::EnumTypeInfo *enumTypeInfo; // ebx@29
  24.   int currPos; // eax@29
  25.   fb::LayoutDescriptor *layoutDescriptor_1; // eax@33
  26.   unsigned int nameHash; // ST0C_4@35
  27.   const char *v25; // eax@35
  28.   const void *targetArrayEnd; // edi@39
  29.   unsigned int targetArrayStart; // ecx@39
  30.   unsigned int arrayCount; // edx@39
  31.   int indexLeft; // eax@39
  32.   unsigned int alignedStartNext; // ebx@39 MAPDST
  33.   int v31; // edx@41
  34.   unsigned int arrayCount_1; // eax@47
  35.   fb::StreamingPartitionArrayEntry *currArray; // ecx@49 MAPDST
  36.   fb::StreamingPartitionFieldDescriptor *currField; // edi@49
  37.   unsigned int realType; // eax@49
  38.   int alignment; // edx@49
  39.   fb::StreamingPartitionTypeDescriptor *currType_1; // eax@53
  40.   int currPos_1; // eax@54
  41.   int arrayStart; // ebx@54
  42.   unsigned int *arrayOffsets; // edx@57
  43.   unsigned int size; // ebx@58
  44.   void *pBuff; // eax@58
  45.   fb::Log::Stream logSteram; // [sp+Ch] [bp-150h]@8
  46.   unsigned int count; // [sp+13Ch] [bp-20h]@47
  47.   unsigned int elementSize; // [sp+144h] [bp-18h]@6
  48.   unsigned int i; // [sp+148h] [bp-14h]@2
  49.   int currPointer; // [sp+14Ch] [bp-10h]@5
  50.   int v50; // [sp+158h] [bp-4h]@8
  51.  
  52.   streamingPartitionReader = this;
  53.   startTypeInfo = this->m_typeInfos.mpBegin;
  54.   numTypeDescriptors = this->m_header.typeDescriptorCount;
  55.   typeInfo = (const fb::TypeInfo *)&this->m_typeInfos;
  56.   nextTypeInfo = typeInfo->m_pNext;
  57.   if ( numTypeDescriptors <= (signed int)((char *)typeInfo->m_pNext - (char *)startTypeInfo) >> 2 )
  58.   {
  59.     eastl::vector<fb::TypeInfo const *,eastl::fixed_vector_allocator<4,16,4,0,1,fb::eastl_arena_allocator>>::erase(
  60.       (eastl::vector<fb::TypeInfo const *,eastl::fixed_vector_allocator<4,16,4,0,1,fb::eastl_arena_allocator> > *)typeInfo,
  61.       &startTypeInfo[numTypeDescriptors],
  62.       (fb::TypeInfo **)typeInfo->m_pNext);
  63.   }
  64.   else
  65.   {
  66.     i = 0;
  67.     eastl::vector<fb::TypeInfo const *,eastl::fixed_vector_allocator<4,16,4,0,1,fb::eastl_arena_allocator>>::DoInsertValues(
  68.       (eastl::vector<fb::TypeInfo const *,eastl::fixed_vector_allocator<4,16,4,0,1,fb::eastl_arena_allocator> > *)typeInfo,
  69.       (fb::TypeInfo **)nextTypeInfo,
  70.       numTypeDescriptors - (((char *)nextTypeInfo - (char *)startTypeInfo) >> 2),
  71.       (fb::TypeInfo *const *)&i);
  72.   }
  73.   currArray = 0;
  74.   i = 0;
  75.   if ( streamingPartitionReader->m_header.typeCount )
  76.   {
  77.     currPointer = 0;
  78.     do
  79.     {
  80.       currInstance = (fb::StreamingPartitionInstanceEntry *)((char *)streamingPartitionReader->m_instanceEntries
  81.                                                            + currPointer);
  82.       currInstanceNameHash = &streamingPartitionReader->m_typeDescriptors[currInstance->typeDescriptorIndex].typeNameHash;
  83.       classInfo = fb::TypeManager::findClassByHash(*currInstanceNameHash);
  84.       elementSize = (unsigned int)classInfo;
  85.       if ( classInfo )
  86.       {
  87.         currArray = (fb::StreamingPartitionArrayEntry *)(16 * currInstance->exportCount
  88.                                                        + HIWORD(classInfo->m_infoData->layoutDescriptor)
  89.                                                        * (currInstance->exportCount + currInstance->internalCount)
  90.                                                        + (~(LOBYTE(classInfo->m_infoData->instanceSize) - 1) & (unsigned int)((char *)currArray + LOBYTE(classInfo->m_infoData->instanceSize) - 1)));
  91.       }
  92.       else
  93.       {
  94.         metaString = fb::StreamingPartitionReader::metaString(streamingPartitionReader, *currInstanceNameHash);
  95.         if ( fb::Log::c_logFilter & 0x20 )
  96.         {
  97.           fb::Log::Stream::Stream(&logSteram, &stru_39E0C38, s_logContext);
  98.           v50 = 0;
  99.           outStream = fb::operator<<((fb::OutAsciiStream *)&logSteram.vfptr, "Failed to resolve type: ");
  100.           fb::operator<<(outStream, metaString);
  101.           fb::Log::Stream::process(&logSteram);
  102.           v50 = -1;
  103.           fb::Log::Stream::~Stream(&logSteram);
  104.         }
  105.         if ( fb::Log::shouldBreak() )
  106.           __debugbreak();
  107.       }
  108.       v11 = currInstance->typeDescriptorIndex;
  109.       if ( v11 && v11 >= streamingPartitionReader->m_typeInfos.mpEnd - streamingPartitionReader->m_typeInfos.mpBegin )
  110.         eastl::AssertionFailure("vector::operator[] -- out of range");
  111.       startTypeInfo2 = streamingPartitionReader->m_typeInfos.mpBegin;
  112.       currPointer += 12;
  113.       startTypeInfo2[v11] = (fb::TypeInfo *)elementSize;
  114.       ++i;
  115.     }
  116.     while ( i < streamingPartitionReader->m_header.typeCount );
  117.   }
  118.   if ( !(_S2_5 & 1) )
  119.   {
  120.     _S2_5 |= 1u;
  121.     v50 = 1;
  122.     fb::SerializationLayoutCache::SerializationLayoutCache(&cache);
  123.     atexit(fb::getLayoutCache_::_2_::_dynamic_atexit_destructor_for__cache__);
  124.     v50 = -1;
  125.   }
  126.   currPointer = 0;
  127.   if ( streamingPartitionReader->m_header.typeDescriptorCount > 0 )
  128.   {
  129.     elementSize = 0;
  130.     do
  131.     {
  132.       currType = (fb::StreamingPartitionTypeDescriptor *)((char *)streamingPartitionReader->m_typeDescriptors
  133.                                                         + elementSize);
  134.       switch ( ((unsigned int)currType->typeFlags.flagBits >> 4) & 0x1F )
  135.       {
  136.         case 3u:
  137.           dataContainerClassInfo = (fb::DataContainerClassInfo *)fb::TypeManager::findTypeByHash(currType->typeNameHash);
  138.           layoutDescriptor = fb::SerializationLayoutCache::getDescriptor(&cache, dataContainerClassInfo);
  139.           fb::StreamingPartitionReader::mapLayout(streamingPartitionReader, currType, layoutDescriptor);
  140.           break;
  141.         case 2u:
  142.           valueTypeInfo = (fb::ValueTypeInfo *)fb::TypeManager::findTypeByHash(currType->typeNameHash);
  143.           currIndex = currPointer;
  144.           if ( currPointer
  145.             && currPointer >= (unsigned int)(streamingPartitionReader->m_typeInfos.mpEnd
  146.                                            - streamingPartitionReader->m_typeInfos.mpBegin) )
  147.           {
  148.             eastl::AssertionFailure("vector::operator[] -- out of range");
  149.             currIndex = currPointer;
  150.           }
  151.           streamingPartitionReader->m_typeInfos.mpBegin[currIndex] = (fb::TypeInfo *)valueTypeInfo;
  152.           if ( valueTypeInfo )
  153.           {
  154.             layoutDescriptor2 = fb::SerializationLayoutCache::getDescriptor(&cache, valueTypeInfo);
  155.             fb::StreamingPartitionReader::mapLayout(streamingPartitionReader, currType, layoutDescriptor2);
  156.             currType->secondaryInstanceSize = HIWORD(valueTypeInfo->m_infoData->layoutDescriptor);
  157.             currAlign = LOBYTE(valueTypeInfo->m_infoData->instanceSize);
  158.             currAlign2 = currType->alignment;
  159.             if ( currAlign2 != currAlign )
  160.             {
  161.               fb::Log::formattedLog(&stru_39E0C24, "Alignment error, %d vs %d", (unsigned __int8)currAlign2, currAlign);
  162.               goto LABEL_36;
  163.             }
  164.           }
  165.           else
  166.           {
  167.             currType->secondaryInstanceSize = 0;
  168.           }
  169.           break;
  170.         case 8u:
  171.           enumTypeInfo = (fb::EnumTypeInfo *)fb::TypeManager::findTypeByHash(currType->typeNameHash);
  172.           currPos = currPointer;
  173.           if ( currPointer
  174.             && currPointer >= (unsigned int)(streamingPartitionReader->m_typeInfos.mpEnd
  175.                                            - streamingPartitionReader->m_typeInfos.mpBegin) )
  176.           {
  177.             eastl::AssertionFailure("vector::operator[] -- out of range");
  178.             currPos = currPointer;
  179.           }
  180.           streamingPartitionReader->m_typeInfos.mpBegin[currPos] = (fb::TypeInfo *)enumTypeInfo;
  181.           if ( enumTypeInfo )
  182.           {
  183.             layoutDescriptor_1 = fb::SerializationLayoutCache::getDescriptor(&cache, enumTypeInfo);
  184.             fb::StreamingPartitionReader::mapLayout(streamingPartitionReader, currType, layoutDescriptor_1);
  185.           }
  186.           break;
  187.         default:
  188.           if ( fb::Log::c_logFilter & 0x20 )
  189.           {
  190.             fb::Log::Stream::Stream(&logSteram, &stru_39E0C10, s_logContext);
  191.             nameHash = currType->typeNameHash;
  192.             v50 = 2;
  193.             v25 = fb::StreamingPartitionReader::metaString(streamingPartitionReader, nameHash);
  194.             fb::operator<<((fb::OutAsciiStream *)&logSteram.vfptr, v25);
  195.             fb::Log::Stream::process(&logSteram);
  196.             v50 = -1;
  197.             fb::Log::Stream::~Stream(&logSteram);
  198.           }
  199. LABEL_36:
  200.           if ( fb::Log::shouldBreak() )
  201.             __debugbreak();
  202.           break;
  203.         case 4u:
  204.           break;
  205.       }
  206.       elementSize += 16;
  207.       ++currPointer;
  208.     }
  209.     while ( currPointer < streamingPartitionReader->m_header.typeDescriptorCount );
  210.   }
  211.   targetArrayEnd = streamingPartitionReader->targetArrayOffsets.mpEnd;
  212.   targetArrayStart = (unsigned int)streamingPartitionReader->targetArrayOffsets.mpBegin;
  213.   arrayCount = streamingPartitionReader->m_header.arrayCount;
  214.   indexLeft = (signed int)((char *)streamingPartitionReader->targetArrayOffsets.mpEnd - targetArrayStart) >> 2;
  215.   alignedStartNext = (unsigned int)((char *)&currArray[1].offset + 3) & 0xFFFFFFF0;
  216.   if ( arrayCount <= indexLeft )
  217.   {
  218.     v31 = targetArrayStart + 4 * arrayCount;
  219.     i = v31;
  220.     if ( v31 < targetArrayStart
  221.       || v31 > (unsigned int)targetArrayEnd
  222.       || (unsigned int)targetArrayEnd < targetArrayStart
  223.       || (unsigned int)targetArrayEnd < v31 )
  224.     {
  225.       eastl::AssertionFailure("vector::erase -- invalid position");
  226.       v31 = i;
  227.     }
  228.     _memmove(
  229.       (void *)v31,
  230.       targetArrayEnd,
  231.       (char *)streamingPartitionReader->targetArrayOffsets.mpEnd - (char *)targetArrayEnd);
  232.     streamingPartitionReader->targetArrayOffsets.mpEnd -= (signed int)((char *)targetArrayEnd - i) >> 2;
  233.   }
  234.   else
  235.   {
  236.     i = 0;
  237.     eastl::vector<unsigned int,eastl::fixed_vector_allocator<4,32,4,0,1,fb::eastl_arena_allocator>>::DoInsertValues(
  238.       (eastl::vector<unsigned int,eastl::fixed_vector_allocator<4,32,4,0,1,fb::eastl_arena_allocator> > *)&streamingPartitionReader->targetArrayOffsets.mpBegin,
  239.       (unsigned int *)targetArrayEnd,
  240.       arrayCount - indexLeft,
  241.       &i);
  242.   }
  243.   arrayCount_1 = streamingPartitionReader->m_header.arrayCount;
  244.   currPointer = 0;
  245.   count = arrayCount_1;
  246.   if ( arrayCount_1 )
  247.   {
  248.     i = 0;
  249.     do
  250.     {
  251.       currArray = (fb::StreamingPartitionArrayEntry *)((char *)streamingPartitionReader->m_arrayEntries + i);
  252.       currField = &streamingPartitionReader->m_fieldDescriptors[streamingPartitionReader->m_typeDescriptors[currArray->typeDescriptorIndex].layoutDescriptor];
  253.       currArray = (fb::StreamingPartitionArrayEntry *)((char *)streamingPartitionReader->m_arrayEntries + i);
  254.       realType = ((unsigned int)currField->flags.flagBits >> 4) & 0x1F;
  255.       elementSize = (unsigned __int8)mapTypeCodeToSize[realType];
  256.       alignment = (unsigned __int8)mapTypeCodeToAlignment[realType];
  257.       if ( !elementSize )
  258.       {
  259.         if ( realType != 2 )
  260.         {
  261.           fb::Log::formattedLog(&stru_39E0BFC, "%s", &secret);
  262.           if ( fb::Log::shouldBreak() )
  263.             __debugbreak();
  264.         }
  265.         currType_1 = &streamingPartitionReader->m_typeDescriptors[currField->fieldType];
  266.         elementSize = currType_1->secondaryInstanceSize;
  267.         alignment = currType_1->alignment;
  268.       }
  269.       currPos_1 = currPointer;
  270.       arrayStart = ~(alignment - 1) & (alignment + alignedStartNext + 3);
  271.       if ( currPointer
  272.         && currPointer >= (unsigned int)(streamingPartitionReader->targetArrayOffsets.mpEnd
  273.                                        - streamingPartitionReader->targetArrayOffsets.mpBegin) )
  274.       {
  275.         eastl::AssertionFailure("vector::operator[] -- out of range");
  276.         currPos_1 = currPointer;
  277.       }
  278.       arrayOffsets = streamingPartitionReader->targetArrayOffsets.mpBegin;
  279.       i += 12;
  280.       arrayOffsets[currPos_1] = arrayStart;
  281.       alignedStartNext = elementSize * currArray->elementCount + arrayStart;
  282.       currPointer = currPos_1 + 1;
  283.     }
  284.     while ( currPos_1 + 1 != count );
  285.   }
  286.   size = streamingPartitionReader->m_header.stringTableSize + alignedStartNext;
  287.   pBuff = fb::MemoryArena::alloc(streamingPartitionReader->m_domain->m_arena, size, 0x10u, 0);
  288.   streamingPartitionReader->m_targetBuffer = (char *)pBuff;
  289.   streamingPartitionReader->m_targetBufferSize = size;
  290.   streamingPartitionReader->m_targetStringBase = (char *)pBuff + alignedStartNext;
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement