找回密码
 register

QQ登录

只需一步,快速开始

查看: 330|回复: 0

[*服务端*] LuaFnTryRecieveItem 引擎函数IDA改写为C++代码

[复制链接]

[*服务端*] LuaFnTryRecieveItem 引擎函数IDA改写为C++代码

[复制链接]
  • 打卡等级:热心大叔
  • 打卡总天数:185
  • 打卡月天数:8
  • 打卡总奖励:183
  • 最近打卡:2025-05-08 13:47:30
Waylee

主题

0

回帖

1万

积分

仙帝

积分
19608
Waylee 2025-3-4 00:20 | 显示全部楼层 |阅读模式 | Google Chrome | Windows 10

马上注册,查看网站隐藏内容!!

您需要 登录 才可以下载或查看,没有账号?register

×

文章性质:备忘笔记·非成品


LuaFnTryRecieveItem函数伪代码(08271B18):

BOOL __cdecl ItemOperator::CreateItem(
        ItemOperator *const this,
        ITEM_LOG_PARAM *pLogParam,
        UINT uItemIndex,
        UINT reason,
        ItemContainer *pDestContainer,
        BOOL *const bNewEmptyPos,
        UINT *const uConIndex,
        INT nDestIndex)
{
  BOOL v8; // edx
  INT NoFullItemIndex; // eax
  _ITEM *m_pItem; // eax
  INT m_Serial; // edx
  int v13; // eax
  Item *Item; // ebx
  Item *v15; // eax
  BOOL IsEmpty; // eax
  BYTE ItemCount; // al
  UINT v18; // [esp-Ch] [ebp-F4h]
  const CHAR *v19; // [esp-4h] [ebp-ECh]
  INT iEmptyBagIndex; // [esp+0h] [ebp-E8h]
  INT iNoFullBagIndex; // [esp+4h] [ebp-E4h]
  _ITEM createItem; // [esp+20h] [ebp-C8h] BYREF

  if ( !pDestContainer )
    __assert__(
      "./Item/ItemOperator.cpp",
      0xBCu,
      "BOOL ItemOperator::CreateItem(ITEM_LOG_PARAM*, UINT, UINT, ItemContainer*, BOOL&, UINT&, INT)",
      "pDestContainer");
  if ( !uItemIndex )
  {
    v19 = "uItemIndex!=0";
    v18 = 189;
    goto LABEL_8;
  }
  if ( uItemIndex == -1 )
  {
    v19 = "uItemIndex!=INVALID_ID";
    v18 = 190;
LABEL_8:
    __assert__(
      "./Item/ItemOperator.cpp",
      v18,
      "BOOL ItemOperator::CreateItem(ITEM_LOG_PARAM*, UINT, UINT, ItemContainer*, BOOL&, UINT&, INT)",
      v19);
  }
  if ( !pLogParam )
    __assert__(
      "./Item/ItemOperator.cpp",
      0xBFu,
      "BOOL ItemOperator::CreateItem(ITEM_LOG_PARAM*, UINT, UINT, ItemContainer*, BOOL&, UINT&, INT)",
      "pLogParam");
  v8 = 0;
  if ( uItemIndex - 1 > 0xFFFFFFFD )
    return v8;
  *uConIndex = -1;
  *bNewEmptyPos = 0;
  if ( ItemRulerCheck::CheckTypeRuler(ITEM_RULER_LIST::IRL_TILE, uItemIndex) )
  {
    NoFullItemIndex = ItemContainer::GetNoFullItemIndex(pDestContainer, uItemIndex);
    iNoFullBagIndex = NoFullItemIndex;
    if ( NoFullItemIndex != -1 )
    {
      *uConIndex = NoFullItemIndex;
      *bNewEmptyPos = 0;
      pLogParam->ItemType = uItemIndex;
      pLogParam->BagPos = (*((int (__cdecl **)(ItemContainer *, INT))pDestContainer->_vptr_ItemContainer + 2))(
                            pDestContainer,
                            NoFullItemIndex);
      pLogParam->SecOpType = ITEM_OP_TYPE::ITEM_CREATE_TILED;
      m_pItem = ItemContainer::GetItem(pDestContainer, iNoFullBagIndex)->m_pItem;
      if ( !m_pItem )
        __assert__("./Item/Item.inl", 0x14u, "_ITEM_GUID Item::GetGUID()", "m_pItem");
      m_Serial = m_pItem->m_ItemGUID.m_Serial;
      v13 = *(_DWORD *)&m_pItem->m_ItemGUID.m_World;
      pLogParam->ItemGuid.m_Serial = m_Serial;
      *(_WORD *)&pLogParam->ItemGuid.m_World = v13;
      Item = ItemContainer::GetItem(pDestContainer, iNoFullBagIndex);
      if ( Item->m_Type )
      {
        if ( Item->m_Type != ITEM_DATA_TYPE::IDT_PET )
          __assert__("./Item/Item.inl", 0xFFu, Item::GetLayedNum(void)const::__PRETTY_FUNCTION__, "FALSE");
        if ( !Item->m_pPet )
          __assert__("./Item/Item.inl", 0xF9u, Item::GetLayedNum(void)const::__PRETTY_FUNCTION__, "m_pPet");
        ItemCount = 1;
      }
      else
      {
        if ( !Item->m_pItem )
          __assert__("./Item/Item.inl", 0xF3u, Item::GetLayedNum(void)const::__PRETTY_FUNCTION__, "m_pItem");
        ItemCount = _ITEM::GetItemCount(Item->m_pItem);
      }
      pLogParam->Count = ItemCount + 1;
      return ItemOperator::IncItemLayCount(this, pDestContainer, iNoFullBagIndex, 1);
    }
  }
  iEmptyBagIndex = ItemContainer::GetEmptyItemIndex(pDestContainer);
  if ( iEmptyBagIndex != -1 )
  {
    createItem.m_ItemGUID.m_Serial = 0;
    createItem.m_ItemGUID.m_Server = 0;
    createItem.m_ItemGUID.m_World = 0;
    memset(&createItem, 0, sizeof(createItem));
    ItemManager::CreateItem(g_pItemManager, pLogParam, uItemIndex, &createItem, reason);
    if ( createItem.m_ItemGUID.m_World || createItem.m_ItemGUID.m_Serial || (v8 = 0, createItem.m_ItemGUID.m_Server) )
    {
      pLogParam->ItemType = uItemIndex;
      pLogParam->BagPos = (*((int (__cdecl **)(ItemContainer *, INT))pDestContainer->_vptr_ItemContainer + 2))(
                            pDestContainer,
                            iEmptyBagIndex);
      pLogParam->ItemGuid.m_Serial = createItem.m_ItemGUID.m_Serial;
      pLogParam->ItemGuid.m_Server = createItem.m_ItemGUID.m_Server;
      pLogParam->ItemGuid.m_World = createItem.m_ItemGUID.m_World;
      v15 = ItemContainer::GetItem(pDestContainer, iEmptyBagIndex);
      IsEmpty = Item::IsEmpty(v15);
      if ( !IsEmpty )
        __assert__(
          "./Item/ItemOperator.cpp",
          0xF8u,
          "BOOL ItemOperator::CreateItem(ITEM_LOG_PARAM*, UINT, UINT, ItemContainer*, BOOL&, UINT&, INT)",
          "FALSE");
      (*((void (__cdecl **)(ItemContainer *, INT, _ITEM *, BOOL))pDestContainer->_vptr_ItemContainer + 16))(
        pDestContainer,
        iEmptyBagIndex,
        &createItem,
        IsEmpty);
      *bNewEmptyPos = 1;
      *uConIndex = iEmptyBagIndex;
      return 1;
    }
    return v8;
  }
  return 0;
}

// positive sp value has been detected, the output may be wrong!
BOOL __cdecl HumanItemLogic::CreateItemToBag(
        ITEM_LOG_PARAM *pLogParam,
        Obj_Human *pHuman,
        UINT uItemIndex,
        UINT *const uBagIndex,
        UINT reason)
{
  BOOL v5; // edx
  BOOL v7; // ebx
  const _ITEM *m_pItem; // eax
  UINT v9; // [esp-34h] [ebp-5Ch]
  const CHAR *v10; // [esp-2Ch] [ebp-54h]
  Item *pItem; // [esp+8h] [ebp-20h]
  ItemContainer *pContainer; // [esp+Ch] [ebp-1Ch]
  BOOL bNewPos; // [esp+14h] [ebp-14h] BYREF
  UINT uContainerPos[4]; // [esp+18h] [ebp-10h] BYREF

  if ( !pHuman )
    __assert__(
      "./Item/HumanItemLogic.cpp",
      0x518u,
      "static BOOL HumanItemLogic::CreateItemToBag(ITEM_LOG_PARAM*, Obj_Human*, UINT, UINT&, UINT)",
      "pHuman");
  if ( !uItemIndex )
  {
    v10 = "uItemIndex!=0";
    v9 = 1305;
    goto LABEL_8;
  }
  if ( uItemIndex == -1 )
  {
    v10 = "uItemIndex!=INVALID_ID";
    v9 = 1306;
LABEL_8:
    __assert__(
      "./Item/HumanItemLogic.cpp",
      v9,
      "static BOOL HumanItemLogic::CreateItemToBag(ITEM_LOG_PARAM*, Obj_Human*, UINT, UINT&, UINT)",
      v10);
  }
  if ( !pLogParam )
    __assert__(
      "./Item/HumanItemLogic.cpp",
      0x51Bu,
      "static BOOL HumanItemLogic::CreateItemToBag(ITEM_LOG_PARAM*, Obj_Human*, UINT, UINT&, UINT)",
      "pLogParam");
  v5 = 0;
  if ( uItemIndex - 1 <= 0xFFFFFFFD )
  {
    pContainer = HumanItemLogic::GetItemContain(pHuman, uItemIndex);
    if ( !pContainer )
      __assert__(
        "./Item/HumanItemLogic.cpp",
        0x522u,
        "static BOOL HumanItemLogic::CreateItemToBag(ITEM_LOG_PARAM*, Obj_Human*, UINT, UINT&, UINT)",
        "pContainer");
    v7 = ItemOperator::CreateItem(
           &g_ItemOperator,
           pLogParam,
           uItemIndex,
           reason,
           pContainer,
           &bNewPos,
           uContainerPos,
           -1);
    if ( v7 )
    {
      *uBagIndex = (*((int (__cdecl **)(ItemContainer *, UINT))pContainer->_vptr_ItemContainer + 2))(
                     pContainer,
                     uContainerPos[0]);
      pItem = ItemContainer::GetItem(pContainer, uContainerPos[0]);
      if ( !pItem )
        __assert__(
          "./Item/HumanItemLogic.cpp",
          0x533u,
          "static BOOL HumanItemLogic::CreateItemToBag(ITEM_LOG_PARAM*, Obj_Human*, UINT, UINT&, UINT)",
          "pItem");
      if ( Item::IsRuler(pItem, ITEM_RULER_LIST::IRL_PICKBIND) )
        ItemOperator::SetItemBind(&g_ItemOperator, pContainer, uContainerPos[0]);
      m_pItem = pItem->m_pItem;
      if ( !m_pItem )
        __assert__("./Item/Item.inl", 0x24Au, "BOOL Item::GetItemBind() const", "m_pItem");
      pLogParam->bBind = _ITEM::GetItemBind(m_pItem);
      Obj_Human::OnItemEnterBag(pHuman, pItem, *uBagIndex);
      return v7;
    }
    else
    {
      *uBagIndex = -1;
      return 0;
    }
  }
  return v5;
}
int __cdecl LuaFnTbl::LuaFnTryRecieveItem(lua_State *L)
{
  int i; // ebx
  unsigned int v2; // esi
  signed int v3; // edi
  long double v4; // fst7
  Scene_3 *Scene; // ebx
  Obj *v6; // esi
  UINT v7; // eax
  UINT v8; // ebx
  UINT v9; // eax
  _ITEM_ATTR_ENUM *ItemAttr; // edx
  int j; // eax
  int k; // eax
  Packet *Item; // eax
  Packet *const v14; // eax
  const CHAR *v16; // [esp-14h] [ebp-57Ch]
  const CHAR *v17; // [esp-10h] [ebp-578h]
  Item *pDestItem; // [esp+10h] [ebp-558h]
  _BYTE v19[3]; // [esp+14h] [ebp-554h]
  SceneID_t sceneId; // [esp+1Ch] [ebp-54Ch]
  unsigned int iBagIndex; // [esp+28h] [ebp-540h] BYREF
  _ITEM_TYPE itemType; // [esp+2Ch] [ebp-53Ch]
  Packets::GCNotifyEquip msg; // [esp+30h] [ebp-538h] BYREF
  ITEM_LOG_PARAM_0 ItemLogParam; // [esp+F0h] [ebp-478h] BYREF
  char s[1048]; // [esp+150h] [ebp-418h] BYREF

  for ( i = 1; i <= 4; ++i )
  {
    if ( L )
    {
      if ( lua_isnumber((lua_State_0 *)L, i) == 1 )
        continue;
      snprintf(s, 0x200u, "ERROR: [%s]Param %d is illegal!", "LuaFnTryRecieveItem", i);
    }
    else
    {
      snprintf(s, 0x200u, "ERROR: [%s] Lua_State==NULL!", "LuaFnTryRecieveItem");
    }
    CacheLog(3, s);
  }
  sceneId = (__int16)lua_tonumber((lua_State_0 *)L, 1);
  v2 = (int)lua_tonumber((lua_State_0 *)L, 2);
  v3 = (int)lua_tonumber((lua_State_0 *)L, 3);
  v4 = lua_tonumber((lua_State_0 *)L, 4);
  if ( v3 <= 0 )
    __assert__("./Script/LuaFnTbl_Ability.h", 0xF75u, "int LuaFnTbl::LuaFnTryRecieveItem(lua_State*)", "iItemId>0");
  Scene = SceneManager::GetScene((SceneManager_1 *const)sceneId, *(int *)&g_pSceneManager, sceneId);
  if ( !Scene )
  {
    v17 = "Scene ID ErrorLuaFnTryRecieveItem";
    v16 = "pScene";
LABEL_28:
    __assertex__("./Script/LuaFnTbl_Ability.h", 0xF77u, "int LuaFnTbl::LuaFnTryRecieveItem(lua_State*)", v16, v17);
  }
  if ( ThreadValueManager::GetCurrentThreadID() != Scene->m_ThreadID )
    __assertex__(
      "./Script/LuaFnTbl_Ability.h",
      0xF77u,
      "int LuaFnTbl::LuaFnTryRecieveItem(lua_State*)",
      "ThreadValueManager::GetCurrentThreadID()==pScene->m_ThreadID",
      "ThreadValueManager::GetCurrentThreadID()==pScene->m_ThreadIDLuaFnTryRecieveItem");
  if ( v2 > 0x752F || (v6 = Scene->m_pObjManager->m_pObj[v2]) == 0 )
  {
    v17 = "selfId ErrorLuaFnTryRecieveItem";
    v16 = "pObj";
    goto LABEL_28;
  }
  if ( (*((int (__cdecl **)(Obj *))v6->_vptr_Obj + 2))(v6) != 1 )
    goto LABEL_23;
  if ( !Obj_Human::IsCanLogic((Obj_Human *const)v6) )
    __assertex__(
      "./Script/LuaFnTbl_Ability.h",
      0xF77u,
      "int LuaFnTbl::LuaFnTryRecieveItem(lua_State*)",
      "pHuman->IsCanLogic()",
      "IsCanLogic() test return falseLuaFnTryRecieveItem");
  if ( Obj_Human::IsExceedingFatigueState((const Obj_Human *const)v6) )
  {
LABEL_23:
    lua_pushnumber((lua_State_0 *)L, -1.0);
  }
  else
  {
    v7 = GetSerialClass(v3) & 0x7F;
    v8 = (GetSerialIndex(v7) << 21) | v7 & 0x1FFFFF | *(_DWORD *)v19 & 0x1FFF80;
    v9 = (GetSerialQual(v3) & 0x7F) << 7;
    itemType = (_ITEM_TYPE)(((GetSerialType(v9) & 0x7F) << 14) | v9 & 0xFFE03FFF | v8 & 0xFFE0007F);
    ItemLogParam.XPos = 0.0;
    ItemLogParam.ZPos = 0.0;
    iBagIndex = -1;
    ItemLogParam.ItemGuid.m_Serial = 0;
    ItemLogParam.ItemGuid.m_Server = 0;
    ItemLogParam.ItemGuid.m_World = 0;
    ItemLogParam.CharGUID = -1;
    ItemLogParam.TargetGUID = -1;
    ItemLogParam.OpType = ITEM_OP_TYPE::ITEM_OP_UNKNOW;
    ItemLogParam.SecOpType = ITEM_OP_TYPE::ITEM_OP_UNKNOW;
    ItemLogParam.BagPos = -1;
    ItemLogParam.Count = 1;
    ItemLogParam.SceneID = -1;
    ItemLogParam.NpcType = -1;
    ItemLogParam.ShopGUID = -1;
    ItemLogParam.GemMax = 0;
    ItemAttr = ItemLogParam.ItemAttr;
    for ( j = 5; j >= 0; --j )
      *ItemAttr++ = 0;
    for ( k = 0; k <= 2; ++k )
      ItemLogParam.Param[k] = 0;
    ItemLogParam.bBind = 0;
    ItemLogParam.bMark = 0;
    ItemLogParam.bPWLock = 0;
    ItemLogParam.OpType = ITEM_OP_TYPE::ITEM_CREATE_FROM_ABILITY_SCRIPT;
    ItemLogParam.CharGUID = Obj_Human::GetGUID((const Obj_Human *const)v6);
    ItemLogParam.SceneID = v6->m_pScene->m_SceneID;
    ItemLogParam.XPos = v6->m_Pos.m_fX;
    ItemLogParam.ZPos = v6->m_Pos.m_fZ;
    HumanItemLogic::CreateItemToBag(
      (ITEM_LOG_PARAM *)&ItemLogParam,
      (Obj_Human *)v6,
      (*(_WORD *)&itemType.gap0[2] >> 5)
    + 1000
    * (((*(unsigned int *)&itemType >> 14) & 0x7F)
     + 100 * (((*(_WORD *)itemType.gap0 >> 7) & 0x7F) + 100 * (itemType.gap0[0] & 0x7F))),
      &iBagIndex,
      (int)v4);
    if ( iBagIndex == -1 )
    {
      lua_pushnumber((lua_State_0 *)L, -1.0);
    }
    else
    {
      SaveItemLog((ITEM_LOG_PARAM *)&ItemLogParam);
      Item = (Packet *)HumanItemLogic::GetItem((Obj_Human *)v6, iBagIndex);
      pDestItem = (Item *)Item;
      if ( !Item )
        __assert__("./Script/LuaFnTbl_Ability.h", 0xF91u, "int LuaFnTbl::LuaFnTryRecieveItem(lua_State*)", "pDestItem");
      Packet::Packet(Item, (int)&msg);
      msg._vptr_Packet = (int (**)(...))off_841DF28;
      msg.m_Item.m_ItemGUID.m_Serial = 0;
      msg.m_Item.m_ItemGUID.m_Server = 0;
      msg.m_Item.m_ItemGUID.m_World = 0;
      memset(&msg.m_Item, 0, sizeof(msg.m_Item));
      msg.m_BagIndex = iBagIndex;
      Item::SaveValueTo(pDestItem, &msg.m_Item);
      (*(void (__cdecl **)(Scene *, Packets::GCNotifyEquip *))(v6[1520].m_pScene->m_nSceneStatus + 12))(
        v6[1520].m_pScene,
        &msg);
      lua_pushnumber((lua_State_0 *)L, (double)iBagIndex);
      msg._vptr_Packet = (int (**)(...))off_841DF28;
      Packet::~Packet(v14, &msg);
    }
  }
  return 1;
}

初步改造后的代码:

***付费内容***

付费看帖
剩余 44% 内容需要支付 500.00 金币 后可完整阅读
支持付费阅读,激励作者创作更好的作品。
您需要登录后才可以回帖 登录 | register

本版积分规则

雪舞知识库 | 浙ICP备15015590号-1 | 萌ICP备20232229号|浙公网安备33048102000118号 |网站地图|天天打卡

GMT+8, 2025-5-9 03:18 , Processed in 0.096183 second(s), 6 queries , Redis On.

Powered by XueWu Licensed

Copyright © Tencent Cloud.

快速回复 返回顶部 返回列表