Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Level::addEntity might return a bool actually #131

Open
iProgramMC opened this issue Jul 27, 2024 · 0 comments
Open

Level::addEntity might return a bool actually #131

iProgramMC opened this issue Jul 27, 2024 · 0 comments

Comments

@iProgramMC
Copy link
Member

just stumbled upon this. It occurs to me that Level::addEntity might return a bool, whether or not the entity was added. Here's the relevant pseudocode from MCPE 0.1.0 Canada demo:

bool __fastcall Level::addEntity(Level *this, Entity *pEnt)
{
  Entity *v3; // r1
  int v4; // r0
  Entity **v5; // r1
  Entity **v6; // r5
  unsigned int v7; // r3
  unsigned int v8; // r1
  Entity **v9; // r0
  unsigned int v10; // r2
  Entity **v11; // r1
  size_t v12; // r5
  Entity **v13; // r7
  Entity **v14; // r5
  Entity **v15; // r5
  Entity **v16; // r0
  void *v17; // r1
  unsigned int v18; // r3
  Entity *pEnt_1; // [sp+4h] [bp-2Ch] BYREF
  unsigned int v21; // [sp+Ch] [bp-24h] BYREF

  pEnt_1 = pEnt;
  v3 = Level::getEntity(this, pEnt->m_EntityID);
  if ( v3 )
    Level::removeEntity(this, v3);
  Mth::floor(pEnt_1->m_pos.x * 0.0625);
  Mth::floor(pEnt_1->m_pos.z * 0.0625);
  v4 = pEnt_1->m_vtable->entity.isPlayer(pEnt_1);
  if ( v4 )
  {
    if ( pEnt_1->m_vtable->entity.isPlayer(pEnt_1) )
    {
      v6 = this->m_players.end;
      if ( v6 == this->m_players.capacity )
      {
        v7 = v6 - this->m_players.begin;
        if ( v7 )
          v8 = 2 * v7;
        else
          v8 = 1;
        if ( v8 >= 0x40000000 || v7 > v8 )
          v8 = 0x3FFFFFFF;
        v21 = v8;
        v9 = (Entity **)std::allocator<Player *>::_M_allocate((int)&this->m_players.capacity, v8, &v21);
        v11 = this->m_players.begin;
        v12 = (char *)v6 - (char *)v11;
        v13 = v9;
        if ( v12 )
          v14 = (Entity **)((char *)memmove(v9, v11, v12) + v12);
        else
          v14 = v9;
        *v14 = pEnt_1;
        v15 = v14 + 1;
        v16 = this->m_players.begin;
        if ( v16 )
        {
          v17 = (void *)(((char *)this->m_players.capacity - (char *)v16) & 0xFFFFFFFC);
          if ( (unsigned int)v17 > 0x80 )
            operator delete(v16);
          else
            std::__node_alloc::_M_deallocate((std::__node_alloc *)v16, v17, v10);
        }
        v18 = v21;
        this->m_players.begin = v13;
        this->m_players.end = v15;
        this->m_players.capacity = &v13[v18];
      }
      else
      {
        *v6 = pEnt_1;
        ++this->m_players.end;
      }
    }
    v5 = this->m_entities.end;
    if ( v5 == this->m_entities.capacity )
    {
      sub_B5BD0((const void **)&this->m_entities.begin, (int)v5, &pEnt_1);
    }
    else
    {
      *v5 = pEnt_1;
      ++this->m_entities.end;
    }
    Level::entityAdded(this, pEnt_1);
    LOBYTE(v4) = 1;
  }
  return v4;
}

I'll modify this as soon as I have time to maintain this project again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant