Skip to content

Commit

Permalink
Temporarily remove item::useOn hook
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed Feb 22, 2021
1 parent 8414e93 commit 329f279
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 56 deletions.
14 changes: 13 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 45 additions & 46 deletions api/entity/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//}
25 changes: 16 additions & 9 deletions api/lib/mod.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#pragma once

#include "Windows.h"
#include "detours.h"
#include "detver.h"
#include <iostream>

using VA = unsigned __int64;
using RVA = unsigned long int;

#include<cstdio>

#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";
Expand All @@ -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";
}
Expand All @@ -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()
Expand Down

0 comments on commit 329f279

Please sign in to comment.