Advertisement
MattFiler

create_havok_world

Jan 23rd, 2022
541
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void create_havok_world(char *param_1)
  2. {
  3.   COLLISION_MAPPING *pCVar1;
  4.   DYNAMIC_PHYSICS_SYSTEM *pDVar2;
  5.   void *pvVar3;
  6.   int iVar4;
  7.   undefined *puVar5;
  8.   undefined8 uVar6;
  9.   undefined8 uVar7;
  10.   uint uVar8;
  11.   undefined4 uVar9;
  12.   size_t sVar10;
  13.   WEIGHTED_COLLISION_MANAGER *this;
  14.   undefined8 *puVar11;
  15.   void *pvVar12;
  16.   hkpWorld *phVar13;
  17.   long *plVar14;
  18.   undefined4 *puVar15;
  19.   long lVar16;
  20.   ulong uVar17;
  21.   hkpPhysicsSystem *phVar18;
  22.   hkpWorldCinfo *this_00;
  23.   int iVar19;
  24.   hkpWorldObject *this_01;
  25.   hkpPhysicsSystem **pphVar20;
  26.   long lVar21;
  27.   uint local_98c;
  28.   uint local_988 [2];
  29.   ulong local_980;
  30.   undefined8 uStack2424;
  31.   undefined8 uStack2416;
  32.   undefined8 uStack2408;
  33.   char acStack2128 [2000];
  34.   long local_80;
  35.  
  36.   local_80 = *(long *)__got::___stack_chk_guard;
  37.   __stubs::_bzero(acStack2128,2000);
  38.   _macdoze_sprintf(acStack2128,"%sCOLLISION.MAP");
  39.   CA::FileIn::FileIn((FileIn *)&local_980,acStack2128,true);
  40.   local_988[0] = 0;
  41.   CA::FileIn::read((FileIn *)&local_980,local_988,4);
  42.   local_98c = 0;
  43.   CA::FileIn::read((FileIn *)&local_980,&local_98c,4);
  44.   DAT_102538a50 = local_98c;
  45.   DAT_102538b20 = local_98c + 3000;
  46.   if (DAT_102538b20 != 0) {
  47.     uVar17 = (ulong)DAT_102538b20;
  48.     sVar10 = (uVar17 + (ulong)DAT_102538b20 * 2) * 0x10;
  49.     if (CA::ca_malloc_aligned_hook == (code *)0x0) {
  50.       DAT_102538b18 = (void *)__aligned_malloc(sVar10,8);
  51.     }
  52.     else {
  53.       DAT_102538b18 = (void *)(*CA::ca_malloc_aligned_hook)(sVar10,8);
  54.     }
  55.     puVar15 = (undefined4 *)((long)DAT_102538b18 + 0x10);
  56.     do {
  57.       *(undefined8 *)(puVar15 + -2) = 0;
  58.       *(undefined8 *)(puVar15 + -4) = 0xffffffff00000000;
  59.       *puVar15 = 0;
  60.       *(undefined8 *)(puVar15 + 1) = 0xffffffffffffffff;
  61.       *(undefined8 *)(puVar15 + 5) = 0;
  62.       *(undefined8 *)(puVar15 + 3) = 0;
  63.       puVar15[7] = 0;
  64.       puVar15 = puVar15 + 0xc;
  65.       uVar17 = uVar17 - 1;
  66.     } while (uVar17 != 0);
  67.   }
  68.   CA::FileIn::read((FileIn *)&local_980,DAT_102538b18,local_988[0]);
  69.   CA::FileIn::_FileIn((FileIn *)&local_980);
  70.   _macdoze_sprintf(acStack2128,"%sPHYSICS.MAP");
  71.   CA::FileIn::FileIn((FileIn *)&local_980,acStack2128,true);
  72.   local_988[0] = 0;
  73.   CA::FileIn::read((FileIn *)&local_980,local_988,4);
  74.   local_98c = 0;
  75.   CA::FileIn::read((FileIn *)&local_980,&local_98c,4);
  76.   uVar17 = (ulong)local_98c;
  77.   if (local_98c != 0) {
  78.     DAT_102538b30 = local_98c;
  79.     if (CA::ca_malloc_aligned_hook == (code *)0x0) {
  80.       DAT_102538b28 = (void *)__aligned_malloc(uVar17 * 0x50,8);
  81.     }
  82.     else {
  83.       DAT_102538b28 = (void *)(*CA::ca_malloc_aligned_hook)(uVar17 * 0x50,8);
  84.     }
  85.     lVar16 = 0;
  86.     do {
  87.       puVar15 = (undefined4 *)((long)DAT_102538b28 + lVar16);
  88.       *puVar15 = 0xffffffff;
  89.       *(undefined8 *)(puVar15 + 3) = 0;
  90.       *(undefined8 *)(puVar15 + 1) = 0;
  91.       *(undefined8 *)(puVar15 + 5) = 0x3f80000000000000;
  92.       *(undefined8 *)(puVar15 + 9) = 0;
  93.       *(undefined8 *)(puVar15 + 7) = 0;
  94.       puVar15[0xb] = 0x3f800000;
  95.       *(undefined8 *)(puVar15 + 0xc) = 0;
  96.       *(undefined8 *)(puVar15 + 0xe) = 0;
  97.       *(undefined8 *)(puVar15 + 0x10) = 0x3f800000;
  98.       lVar16 = lVar16 + 0x50;
  99.       *(undefined8 *)(puVar15 + 0x12) = 0;
  100.       uVar17 = uVar17 - 1;
  101.     } while (uVar17 != 0);
  102.     CA::FileIn::read((FileIn *)&local_980,DAT_102538b28,local_988[0]);
  103.   }
  104.   CA::FileIn::_FileIn((FileIn *)&local_980);
  105.   if (DAT_102538b20 != 0) {
  106.     lVar16 = 0;
  107.     uVar17 = 0;
  108.     do {
  109.       pCVar1 = (COLLISION_MAPPING *)((long)DAT_102538b18 + lVar16);
  110.       local_980 = local_980 & 0xffffffff00000000 | (ulong)*(uint *)(pCVar1 + 8);
  111.       local_988[0] = *(uint *)(pCVar1 + 0x10);
  112.       uVar8 = CATHODE::ResourceRegistry::find_resource_index
  113.                         (CATHODE::ResourceRegistry::m_instance,(ShortGuid *)&local_980,
  114.                          (ShortGuid *)local_988);
  115.       if (uVar8 != 0xffffffff) {
  116.         CATHODE::ResourceDatabase::add_resource_COLLISION_MAPPING_
  117.                   ((ResourceDatabase *)CATHODE::ResourceRegistry::m_instance,uVar8,pCVar1);
  118.         *(undefined4 *)(pCVar1 + 8) = 0;
  119.       }
  120.       uVar17 = uVar17 + 1;
  121.       lVar16 = lVar16 + 0x30;
  122.     } while (uVar17 < DAT_102538b20);
  123.   }
  124.   if (DAT_102538b30 != 0) {
  125.     lVar16 = 0;
  126.     uVar17 = 0;
  127.     do {
  128.       pDVar2 = (DYNAMIC_PHYSICS_SYSTEM *)((long)DAT_102538b28 + lVar16);
  129.       local_980 = local_980 & 0xffffffff00000000 | (ulong)*(uint *)(pDVar2 + 8);
  130.       local_988[0] = *(uint *)(pDVar2 + 0xc);
  131.       uVar8 = CATHODE::ResourceRegistry::find_resource_index
  132.                         (CATHODE::ResourceRegistry::m_instance,(ShortGuid *)&local_980,
  133.                          (ShortGuid *)local_988);
  134.       if (uVar8 != 0xffffffff) {
  135.         CATHODE::ResourceDatabase::add_resource_DYNAMIC_PHYSICS_SYSTEM_
  136.                   ((ResourceDatabase *)CATHODE::ResourceRegistry::m_instance,uVar8,pDVar2);
  137.       }
  138.       uVar17 = uVar17 + 1;
  139.       lVar16 = lVar16 + 0x50;
  140.     } while (uVar17 < DAT_102538b30);
  141.   }
  142.   _macdoze_sprintf(acStack2128,"%sCOLLISION.BIN");
  143.   this = (WEIGHTED_COLLISION_MANAGER *)WEIGHTED_COLLISION_MANAGER::get_instance();
  144.   WEIGHTED_COLLISION_MANAGER::initialise(this,acStack2128);
  145.   _macdoze_sprintf(acStack2128,"data\\material_data\\%s");
  146.   load_physical_materials_database_from_xml(acStack2128);
  147.   _macdoze_sprintf(acStack2128,"%s%s%s");
  148.   DAT_102538a98 = read_packfile(acStack2128,(void **)&_systemsData,"hkpPhysicsData");
  149.   _macdoze_sprintf(acStack2128,"%s%s%s");
  150.   DAT_102538a90 = read_packfile(acStack2128,(void **)&_physicsData,"hkpPhysicsData");
  151.   lVar16 = _physicsData;
  152.   if (0 < *(int *)(_physicsData + 0x28)) {
  153.     lVar21 = 0;
  154.     do {
  155.       phVar18 = *(hkpPhysicsSystem **)(*(long *)(lVar16 + 0x20) + lVar21 * 8);
  156.       if (0 < *(int *)(phVar18 + 0x20)) {
  157.         iVar19 = 0;
  158. LAB_1004d0a54:
  159.         this_01 = *(hkpWorldObject **)(*(long *)(phVar18 + 0x18) + (long)iVar19 * 8);
  160.         switch(*(uint *)(this_01 + 0x4c) & 0x1f) {
  161.         case 0:
  162.           hkpWorldObject::addProperty(this_01,0x1130,0x44000080);
  163.           _compoundShape = *(undefined8 *)(this_01 + 0x20);
  164.           hkpRigidBody::setRestitution((hkpRigidBody *)this_01,1.0);
  165.           hkpRigidBody::setFriction((hkpRigidBody *)this_01,1.0);
  166.           pvVar12 = __stubs::_pthread_getspecific(hkMemoryRouter::s_memoryRouter);
  167.           pvVar3 = hkMemoryRouter::s_fallbackRouter;
  168.           if (pvVar12 != (void *)0x0) {
  169.             pvVar3 = pvVar12;
  170.           }
  171.           puVar11 = (undefined8 *)
  172.                     (**(code **)(**(long **)((long)pvVar3 + 0x58) + 0x10))
  173.                               (*(long **)((long)pvVar3 + 0x58),0x30);
  174.           puVar11[3] = 0x3f0000003c23d70a;
  175.           puVar11[2] = 0x3e4ccccd3e4ccccd;
  176.           puVar11[4] = 0x3f0000003dcccccd;
  177.           *(undefined4 *)(puVar11 + 5) = 0;
  178.           *puVar11 = &PTR_getExactType_1021a8a38;
  179.           puVar11[1] = this_01;
  180.           hkpEntity::addContactListener((hkpEntity *)this_01,(hkpContactListener *)puVar11);
  181.           *(undefined2 *)(this_01 + 0xfe) = 1;
  182.           this_01[0x4a] = (hkpWorldObject)0x0;
  183.           break;
  184.         case 9:
  185.           hkpWorldObject::addProperty(this_01,0x1130,0x44800000);
  186.           _ballisticShape = *(long *)(this_01 + 0x20);
  187.           pvVar12 = __stubs::_pthread_getspecific(hkMemoryRouter::s_memoryRouter);
  188.           pvVar3 = hkMemoryRouter::s_fallbackRouter;
  189.           if (pvVar12 != (void *)0x0) {
  190.             pvVar3 = pvVar12;
  191.           }
  192.           puVar11 = (undefined8 *)
  193.                     (**(code **)(**(long **)((long)pvVar3 + 0x58) + 0x10))
  194.                               (*(long **)((long)pvVar3 + 0x58),0x30);
  195.           *puVar11 = &PTR_getExactType_1021a89c0;
  196.           puVar11[1] = this_01;
  197.           puVar11[3] = 0x3f0000003c23d70a;
  198.           puVar11[2] = 0x3e4ccccd3e4ccccd;
  199.           puVar11[4] = 0x3f0000003dcccccd;
  200.           *(undefined4 *)(puVar11 + 5) = 0;
  201.           hkpEntity::addContactListener((hkpEntity *)this_01,(hkpContactListener *)puVar11);
  202.           *(undefined2 *)(this_01 + 0xfe) = 1;
  203.           this_01[0x4a] = (hkpWorldObject)0x0;
  204.           iVar4 = *(int *)(_ballisticShape + 0x40);
  205.           goto joined_r0x0001004d0b90;
  206.         case 0xb:
  207.           hkpWorldObject::addProperty(this_01,0x1130,0x44008000);
  208.           _landscapeShape = *(long *)(this_01 + 0x20);
  209.           uVar9 = hkpGroupFilter::calcFilterInfo(9,0,0,0);
  210.           *(undefined4 *)(this_01 + 0x4c) = uVar9;
  211.           pvVar12 = __stubs::_pthread_getspecific(hkMemoryRouter::s_memoryRouter);
  212.           pvVar3 = hkMemoryRouter::s_fallbackRouter;
  213.           if (pvVar12 != (void *)0x0) {
  214.             pvVar3 = pvVar12;
  215.           }
  216.           puVar11 = (undefined8 *)
  217.                     (**(code **)(**(long **)((long)pvVar3 + 0x58) + 0x10))
  218.                               (*(long **)((long)pvVar3 + 0x58),0x30);
  219.           *puVar11 = &PTR_getExactType_1021a89c0;
  220.           puVar11[1] = this_01;
  221.           puVar11[3] = 0x3f0000003c23d70a;
  222.           puVar11[2] = 0x3e4ccccd3e4ccccd;
  223.           puVar11[4] = 0x3f0000003dcccccd;
  224.           *(undefined4 *)(puVar11 + 5) = 0;
  225.           hkpEntity::addContactListener((hkpEntity *)this_01,(hkpContactListener *)puVar11);
  226.           *(undefined2 *)(this_01 + 0xfe) = 1;
  227.           this_01[0x4a] = (hkpWorldObject)0x0;
  228.           iVar4 = *(int *)(_landscapeShape + 0x40);
  229. joined_r0x0001004d0b90:
  230.           if (iVar4 == 0) goto LAB_1004d0bcc;
  231.           break;
  232.         case 0xd:
  233.           hkpWorldObject::addProperty(this_01,0x1130,0x44008080);
  234.           _pathShape = *(undefined8 *)(this_01 + 0x20);
  235.           goto LAB_1004d0bcc;
  236.         case 0x12:
  237.           _proxyShape = *(undefined8 *)(this_01 + 0x20);
  238. LAB_1004d0bcc:
  239.           hkReferencedObject::addReference((hkReferencedObject *)this_01);
  240.           hkpPhysicsSystem::removeRigidBody(phVar18,iVar19);
  241.           lVar16 = _physicsData;
  242.           if (*(int *)(phVar18 + 0x20) <= iVar19) goto LAB_1004d0980;
  243.           goto LAB_1004d0a54;
  244.         }
  245.         iVar19 = iVar19 + 1;
  246.         lVar16 = _physicsData;
  247.         if (*(int *)(phVar18 + 0x20) <= iVar19) goto LAB_1004d0980;
  248.         goto LAB_1004d0a54;
  249.       }
  250. LAB_1004d0980:
  251.       lVar21 = lVar21 + 1;
  252.     } while (lVar21 < *(int *)(lVar16 + 0x28));
  253.   }
  254.   this_00 = *(hkpWorldCinfo **)(lVar16 + 0x18);
  255.   hkpWorldCinfo::setBroadPhaseWorldSize(this_00,1024.0);
  256.   hkpWorldCinfo::setupSolverInfo(this_00,4);
  257.   this_00[199] = (hkpWorldCinfo)0x0;
  258.   *(undefined4 *)(this_00 + 0x100) = 0x80;
  259.   this_00[0x38] = (hkpWorldCinfo)0x2;
  260.   this_00[0xfd] = (hkpWorldCinfo)0x3;
  261.   this_00[0x10c] = (hkpWorldCinfo)0x1;
  262.   *(undefined4 *)(this_00 + 0x60) = 0x3dcccccd;
  263.   this_00[0x94] = (hkpWorldCinfo)0x0;
  264.   *(undefined4 *)(this_00 + 0x80) = 0x3d088889;
  265.   *(undefined8 *)(this_00 + 0x28) = 0;
  266.   *(undefined8 *)(this_00 + 0x20) = 0xc0fb22d200000000;
  267.   uVar7 = hkpBroadPhase::s_createTreeBroadPhaseFunction;
  268.   uVar6 = hkpBroadPhase::s_createSweepAndPruneBroadPhaseFunction;
  269.   uVar17 = cRead_8(fpcr);
  270.   cWrite_8(fpcr,uVar17 | 0x1000000);
  271.   hkpBroadPhase::s_createSweepAndPruneBroadPhaseFunction = hk3AxisSweep32CreateBroadPhase;
  272.   hkpBroadPhase::s_createTreeBroadPhaseFunction = hkpTreeBroadPhase32_createTreeBroadPhase;
  273.   pvVar12 = __stubs::_pthread_getspecific(hkMemoryRouter::s_memoryRouter);
  274.   pvVar3 = hkMemoryRouter::s_fallbackRouter;
  275.   if (pvVar12 != (void *)0x0) {
  276.     pvVar3 = pvVar12;
  277.   }
  278.   phVar13 = (hkpWorld *)
  279.             (**(code **)(**(long **)((long)pvVar3 + 0x58) + 0x10))
  280.                       (*(long **)((long)pvVar3 + 0x58),0x440);
  281.   hkpWorld::hkpWorld(phVar13,*(hkpWorldCinfo **)(_physicsData + 0x18),0x133ece8);
  282.   _world = phVar13;
  283.   hkpWorld::setMemoryWatchDog
  284.             (phVar13,(hkWorldMemoryAvailableWatchDog *)&_havok_world_memory_watchdog);
  285.   phVar13 = _world;
  286.   *(undefined8 *)(_world + 0x354) = 0x461c4000461c4000;
  287.   *(undefined8 *)(phVar13 + 0x36c) = 0x358637be358637be;
  288.   *(undefined8 *)(phVar13 + 0x364) = 0x358637be358637be;
  289.   hkpWorld::registerWithJobQueue(_jobQueue);
  290.   phVar13 = _world;
  291.   pvVar12 = __stubs::_pthread_getspecific(hkMemoryRouter::s_memoryRouter);
  292.   pvVar3 = hkMemoryRouter::s_fallbackRouter;
  293.   if (pvVar12 != (void *)0x0) {
  294.     pvVar3 = pvVar12;
  295.   }
  296.   plVar14 = (long *)(**(code **)(**(long **)((long)pvVar3 + 0x58) + 0x10))
  297.                               (*(long **)((long)pvVar3 + 0x58),0x80);
  298.   hkpBroadPhaseBorder::hkpBroadPhaseBorder((hkpBroadPhaseBorder *)plVar14,_world,0,0);
  299.   puVar5 = PTR_vtable_101f12888;
  300.   *plVar14 = (long)(PTR_vtable_101f12888 + 0x10);
  301.   plVar14[3] = (long)(puVar5 + 0x70);
  302.   plVar14[4] = (long)(puVar5 + 0xa8);
  303.   plVar14[5] = (long)(puVar5 + 0xe0);
  304.   hkpWorld::setBroadPhaseBorder(phVar13,(hkpBroadPhaseBorder *)plVar14);
  305.   if (DAT_102538b30 != 0) {
  306.     uVar17 = 0;
  307.     do {
  308.       pvVar3 = DAT_102538b28;
  309.       DYNAMIC_PHYSICS_SYSTEM::create_system
  310.                 ((DYNAMIC_PHYSICS_SYSTEM *)((long)DAT_102538b28 + uVar17 * 0x50));
  311.       pphVar20 = (hkpPhysicsSystem **)((long)pvVar3 + uVar17 * 0x50 + 0x48);
  312.       phVar18 = *pphVar20;
  313.       if (phVar18 != (hkpPhysicsSystem *)0x0) {
  314.         hkpWorld::addPhysicsSystem(_world,phVar18);
  315.         phVar18 = *pphVar20;
  316.         if (0 < *(int *)(phVar18 + 0x20)) {
  317.           lVar16 = 0;
  318.           do {
  319.             hkpEntity::addContactListener
  320.                       (*(hkpEntity **)(*(long *)(phVar18 + 0x18) + lVar16 * 8),
  321.                        ImpactListener::m_instance);
  322.             lVar16 = lVar16 + 1;
  323.           } while (lVar16 < *(int *)(phVar18 + 0x20));
  324.         }
  325.       }
  326.       uVar17 = uVar17 + 1;
  327.     } while (uVar17 < DAT_102538b30);
  328.   }
  329.   _macdoze_sprintf(acStack2128,"%sENVIRONMENT_ANIMATION.DAT");
  330.   EnvironmentAnimationSystem::initialise
  331.             (*(EnvironmentAnimationSystem **)(_game_globals + 0xf8),acStack2128);
  332.   uStack2424 = 0;
  333.   local_980 = 0;
  334.   uStack2408 = 0;
  335.   uStack2416 = 0;
  336.   pvVar12 = __stubs::_pthread_getspecific(hkMemoryRouter::s_memoryRouter);
  337.   pvVar3 = hkMemoryRouter::s_fallbackRouter;
  338.   if (pvVar12 != (void *)0x0) {
  339.     pvVar3 = pvVar12;
  340.   }
  341.   plVar14 = (long *)(**(code **)(**(long **)((long)pvVar3 + 0x58) + 0x10))
  342.                               (*(long **)((long)pvVar3 + 0x58),0x130);
  343.   hkpAabbPhantom::hkpAabbPhantom((hkpAabbPhantom *)plVar14,(hkAabb *)&local_980,0);
  344.   _aabbPhantom = plVar14;
  345.   (**(code **)(*plVar14 + 0x60))(plVar14);
  346.   hkpWorld::addPhantom(_world,(hkpPhantom *)_aabbPhantom);
  347.   hkpAgentRegisterUtil::registerAllAgents(*(hkpCollisionDispatcher **)(_world + 200));
  348.   if (0 < *(int *)(_physicsData + 0x28)) {
  349.     lVar16 = 0;
  350.     do {
  351.       hkpWorld::addPhysicsSystem
  352.                 (_world,*(hkpPhysicsSystem **)(*(long *)(_physicsData + 0x20) + lVar16 * 8));
  353.       lVar16 = lVar16 + 1;
  354.     } while (lVar16 < *(int *)(_physicsData + 0x28));
  355.   }
  356.   hkpWorld::updateCollisionFilterOnWorld(_world,0,1);
  357.   if (*(long *)__got::___stack_chk_guard == local_80) {
  358.     hkpBroadPhase::s_createSweepAndPruneBroadPhaseFunction = (code *)uVar6;
  359.     hkpBroadPhase::s_createTreeBroadPhaseFunction = (code *)uVar7;
  360.     return;
  361.   }
  362.   hkpBroadPhase::s_createSweepAndPruneBroadPhaseFunction = (code *)uVar6;
  363.   hkpBroadPhase::s_createTreeBroadPhaseFunction = (code *)uVar7;
  364.                     // WARNING: Subroutine does not return
  365.   __stubs::___stack_chk_fail();
  366. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement