admin 发表于 2021-10-30 23:43:58

[转载]限制护身符区域制作

/*----------------------------------------------------------------分割线----------------------------------------------------------------------*/

D2Ptrs.h中:

FUNCPTR(D2COMMON, IsItemOfItemType, bool, __stdcall, (UnitAny* pItem, DWORD ItemType), 0x24430)
FUNCPTR(D2COMMON, AreCharmReqsMet, int, __stdcall, (UnitAny* pItem, UnitAny* pUnit), 0x287D0)


D2Vars.h中:

static   const char* DEFAULT_CONFIG_PATH = "D2CharmLimit.ini";
static   const char* SECTION_NAME = "D2CharmLimit";

struct Configuration
{
       int BagLeft;
       int BagRight;
       int BagTop;
       int BagBottem;
};


VAR(Configuration, Config)

void __fastcall Config_Load();

D2Vars.cpp中:

void __fastcall Config_Load()
{

       INIReader ConfigReader(DEFAULT_CONFIG_PATH);

       Config.BagLeft = ConfigReader.GetInteger(SECTION_NAME, "BagLeft", 0);
       Config.BagRight = ConfigReader.GetInteger(SECTION_NAME, "BagRight", 0);
       Config.BagTop = ConfigReader.GetInteger(SECTION_NAME, "BagTop", 0);
       Config.BagBottem = ConfigReader.GetInteger(SECTION_NAME, "BagBottem", 0);

}

CharmInv.cpp中:

const DWORD DrawRedContinue = (DLLBASE_D2CLIENT + 0x95B47);            //背包里不能用显示红色的地方
const DWORD NoDrawRedContinue = (DLLBASE_D2CLIENT + 0x95AD4);      //背包里能用显示蓝色的地方
const DWORD InvCppAddress = (DLLBASE_D2CLIENT + 0xD476C);

void __declspec (naked) __stdcall CharmInventory()
{
       __asm
       {
               test eax, eax                                                            
               jne IsCharmInventory                                                
               retn 8
IsCharmInventory:
               mov eax,                                                         //eax = UnitAny
               mov eax,                                                    //eax = ItemPath
               push ebx                                                                     //此处为了读配置里的内容,以下同理
               mov ebx, Config.BagLeft                                             //ebx = 左边界
               cmp ,ebx                                                      //pItem与eax+C也就是dwPosX限制分界左边相比较
               pop ebx
               jb NoCharmInventory                                                    //小于就返回
               push ebx                                                                      //同上
               mov ebx, Config.BagRight
               cmp ,ebx
               pop ebx
               ja NoCharmInventory
               push ebx                                                                     //同上
               mov ebx, Config.BagTop
               cmp ,ebx
               pop ebx
               jb NoCharmInventory
               push ebx                                                                      //同上
               mov ebx, Config.BagBottem
               cmp ,ebx
               pop ebx
               ja NoCharmInventory
               mov eax,1                                                                  //可用
               retn 8
NoCharmInventory:
               xor eax, eax
               retn 8
       }
}

void __declspec (naked) __stdcall DrawRed()
{
       __asm
       {
               test eax,eax                                                                              //这里感觉没啥要解释的
               je DrawRed1
               push TYPE_CHARM
               push ebx
               call D2COMMON_IsItemOfItemType                                             //参数在D2Ptrs.h中明确标出
               test eax,eax
               je NoDrawRed
               mov eax,dword ptr ss:
               push eax
               push ebx
               call D2COMMON_AreCharmReqsMet                                              //参数在D2Ptrs.h中明确标出
               test eax,eax
               je DrawRed1
               push InvCppAddress
               jmp NoDrawRedContinue

NoDrawRed:
               push InvCppAddress
               jmp NoDrawRedContinue

DrawRed1:
               jmp DrawRedContinue
       }
}


/*----------------------------------------------------------------分割线----------------------------------------------------------------------*/


文中已注释讲解

附:
D2Ptrs.h中的两Func自然不用多说
D2Vars.h和D2Vars.cpp中都是为了读写配置
此处有个BUG就是LC和GC的第一个格子所处位置有效
此BUG我会在以后尽量修复


/*----------------------------------------------------------------分割线----------------------------------------------------------------------*/

用法:
加载DLL利用大箱子或者是D2Win.dll
INI文件中四个参数很明显是定义边界的,但是需要注意的是第一格是从0开始的

此篇内容大概就酱紫吧
页: [1]
查看完整版本: [转载]限制护身符区域制作