diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ea627b1..c12eebf 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -15,6 +15,8 @@ + + @@ -86,6 +88,16 @@ + + + + + + + + + + diff --git a/api/entity/Item.cpp b/api/entity/Item.cpp index 2970909..183219a 100644 --- a/api/entity/Item.cpp +++ b/api/entity/Item.cpp @@ -13,56 +13,55 @@ #include "tools/DirtyLogger.h" namespace trapdoor { - using namespace SymHook; + using namespace SymHook; - std::string ItemStackBase::getItemName() { - std::string name; - SYM_CALL( - void (*)(ItemStackBase*, std::string*), - MSSYM_B1QA7getNameB1AE13ItemStackBaseB2AAA4QEBAB1QA2AVB2QDA5basicB1UA6stringB1AA2DUB2QDA4charB1UA6traitsB1AA1DB1AA3stdB2AAA1VB2QDA9allocatorB1AA1DB1AA12B2AAA3stdB2AAA2XZ, - this, &name); - return name; - } + std::string ItemStackBase::getItemName() { + std::string name; + SYM_CALL( + void(*)(ItemStackBase * , std::string *), + MSSYM_B1QA7getNameB1AE13ItemStackBaseB2AAA4QEBAB1QA2AVB2QDA5basicB1UA6stringB1AA2DUB2QDA4charB1UA6traitsB1AA1DB1AA3stdB2AAA1VB2QDA9allocatorB1AA1DB1AA12B2AAA3stdB2AAA2XZ, + this, &name); + return name; + } - int ItemStackBase::getNum() { return (int)*((unsigned char*)this + 34); } + int ItemStackBase::getNum() { return (int) *((unsigned char *) this + 34); } - void ItemStackBase::setNull() { - SYM_CALL(void (*)(ItemStackBase*), - SymHook::MSSYM_B1QA7setNullB1AE13ItemStackBaseB2AAA7UEAAXXZ, - this); - } + void ItemStackBase::setNull() { + SYM_CALL(void(*)(ItemStackBase * ), + SymHook::MSSYM_B1QA7setNullB1AE13ItemStackBaseB2AAA7UEAAXXZ, + this); + } } // namespace trapdoor using namespace SymHook; //右键代理类 -THook( - void, - MSSYM_B1QA5useOnB1AA4ItemB2AAA4QEBAB1UE14NAEAVItemStackB2AAA9AEAVActorB2AAA7HHHEMMMB1AA1Z, - void* item, - trapdoor::ItemStackBase* itemStack, - trapdoor::Actor* player, - int x, - int y, - int z, - unsigned int facing, - float dx, - float dy, - float dz) { - uint64_t gameTick = trapdoor::bdsMod->getLevel()->getGameTick(); - // L_INFO("%.2f %.2f %.2f,tick = %llu", x, y, z, gameTick); - trapdoor::RightClickCache targetCache{gameTick, x, y, z}; - - auto& playerCache = - trapdoor::bdsMod->getPlayerBuffer()[player->getNameTag()] - .rightClickCache; - //下面用一个简单的缓存 + 判定消除重复点击 - if (playerCache != targetCache) { - //响应右键事件 - trapdoor::BlockPos pos(x, y, z); - const trapdoor::Vec3 vec3(dx, dy, dz); - trapdoor::bdsMod->useOnHook(player, itemStack->getItemName(), pos, - facing, vec3); - playerCache = targetCache; - } - original(item, itemStack, player, x, y, z, facing, dx, dy, dz); -} +//THook( +// void, +// MSSYM_B1QA5useOnB1AA4ItemB2AAA4QEBAB1UE14NAEAVItemStackB2AAA9AEAVActorB2AAA7HHHEMMMB1AA1Z, +// void *item, +// trapdoor::ItemStackBase *itemStack, +// trapdoor::Actor *player, +// int x, +// int y, +// int z, +// unsigned int facing, +// float dx, +// float dy, +// float dz) { +// uint64_t gameTick = trapdoor::bdsMod->getLevel()->getGameTick(); +// trapdoor::RightClickCache targetCache{gameTick, x, y, z}; +// +// auto &playerCache = +// trapdoor::bdsMod->getPlayerBuffer()[player->getNameTag()] +// .rightClickCache; +// //下面用一个简单的缓存 + 判定消除重复点击 +// if (playerCache != targetCache) { +// //响应右键事件 +// trapdoor::BlockPos pos(x, y, z); +// const trapdoor::Vec3 vec3(dx, dy, dz); +// trapdoor::bdsMod->useOnHook(player, itemStack->getItemName(), pos, +// facing, vec3); +// playerCache = targetCache; +// } +// original(item, itemStack, player, x, y, z, facing, dx, dy, dz); +//} diff --git a/api/lib/mod.h b/api/lib/mod.h index bac6bdc..f0accf1 100644 --- a/api/lib/mod.h +++ b/api/lib/mod.h @@ -1,14 +1,18 @@ #pragma once + #include "Windows.h" #include "detours.h" #include "detver.h" #include + using VA = unsigned __int64; using RVA = unsigned long int; + #include + #define _EXPORTED _declspec(dllexport) -inline const char* Hook_wrap(void** pOriginal, void* f) -{ + +inline const char *Hook_wrap(void **pOriginal, void *f) { int error = DetourTransactionBegin(); if (error != NO_ERROR) { return "Hook: DetourTransactionBegin Error"; @@ -18,8 +22,8 @@ inline const char* Hook_wrap(void** pOriginal, void* f) return "Hook: DetourUpdateThread Error"; } error = DetourAttach( - pOriginal, (void*) - f); + pOriginal, (void *) + f); if (error != NO_ERROR) { return "Hook: DetourAttach Error"; } @@ -29,17 +33,20 @@ inline const char* Hook_wrap(void** pOriginal, void* f) } return nullptr; } -inline void Hook(void** pOriginal, void* f, const char* prefix) { + +inline void Hook(void **pOriginal, void *f, const char *prefix) { auto ret = Hook_wrap(pOriginal, f); if (ret) { - fprintf(stderr, "[!] Hook error at %s : %s\n",ret, prefix); + fprintf(stderr, "[!] Hook error at %s : %s\n", ret, prefix); } } + inline VA GetVA(RVA off) { - return (VA)GetModuleHandle(NULL) + (VA)off; + return (VA) GetModuleHandle(NULL) + (VA) off; } -#define TD_CONCAT3_I(a,b,c) a##b##c -#define TD_CONCAT3(a,b,c) TD_CONCAT3_I(a,b,c) + +#define TD_CONCAT3_I(a, b, c) a##b##c +#define TD_CONCAT3(a, b, c) TD_CONCAT3_I(a,b,c) #define THook(ret, iname, ...) struct TD_CONCAT3(TDHook_, __LINE__,iname) { static ret(*original)(__VA_ARGS__); _EXPORTED static ret p(__VA_ARGS__); TD_CONCAT3(TDHook_, __LINE__,iname) () { original = (decltype(original))GetVA(iname); Hook((void **)&original, (void *)&p, #iname); } }; static TD_CONCAT3(TDHook_, __LINE__,iname) tdh##iname; ret(*TD_CONCAT3(TDHook_, __LINE__,iname)::original)(__VA_ARGS__); ret TD_CONCAT3(TDHook_, __LINE__,iname)::p(__VA_ARGS__) #define FNTYPE_DEF(...) VA (*)(__VA_ARGS__) #define FNTYPE_DEF_0 FNTYPE_DEF()