Skip to content

Commit

Permalink
修复village v闪退的hug
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohengying committed Jan 25, 2022
1 parent fa3c637 commit 0b49e14
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 412 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ add_library(${MOD_API_NAME} STATIC
api/graphics/AABB.h
api/graphics/BlockPos.cpp
api/graphics/Vec3.cpp
api/graphics/Graphics.cpp
api/graphics/BlockPos.cpp
api/world/Biome.cpp
api/world/Dimension.cpp
Expand Down
9 changes: 7 additions & 2 deletions api/entity/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ namespace trapdoor {
}

void Actor::setNameTag(const std::string &name) {
SYM_CALL(void (*)(void *actor, const std::string &str),
Actor_setNameTag_2f9772d3, this, name);
__try {
SYM_CALL(void (*)(void *actor, const std::string &str),
Actor_setNameTag_2f9772d3, this, name);

} __except (EXCEPTION_EXECUTE_HANDLER) {
// nothing
}
}

std::string ActorDefinitionIdentifier::getName() {
Expand Down
15 changes: 0 additions & 15 deletions api/graphics/Graphics.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions api/graphics/Graphics.h

This file was deleted.

430 changes: 209 additions & 221 deletions api/lib/Remotery.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/tools/DirtyLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace trapdoor {
void initLogger(const std::string &logFileName) {
logger = fopen(logFileName.c_str(), "a+");
if (!logger) logger = stderr;
L_INFO("TRAPDOOR LOGGER INIT");
// L_INFO("TRAPDOOR LOGGER INIT");
}

//向日志里面打印信息
Expand Down
1 change: 0 additions & 1 deletion mod/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <iostream>

#include "commands/CommandManager.h"
#include "graphics/Graphics.h"
#include "graphics/Particle.h"
#include "tools/DirtyLogger.h"

Expand Down
1 change: 0 additions & 1 deletion mod/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Remotery *rmt = nullptr;
// dll注入初始化
void mod_init() {
rmt_CreateGlobalInstance(&rmt);
// displayDisclaimerMessageBox(); //免责声明窗口
initConsole();
trapdoor::initLogger("plugins/trapdoor/trapdoor.log"); //初始化日志
#ifdef BETA
Expand Down
115 changes: 11 additions & 104 deletions mod/function/HopperCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,19 @@ namespace mod {
}
std::string stringBuilder;
trapdoor::MessageBuilder builder;
stringBuilder +=
trapdoor::format("Channel " C_INT ":\nTotal " C_INT
" items in " C_INT " gt ( " C_FLOAT " min(s) )\n",
channel, n, gameTick, gameTick / 1200.0);
builder.textF("Channel [%d]: Total %d items in %d gt (%.3f min(s))",
channel, n, gameTick, gameTick / 1200.0);

for (const auto &i : counterList) {
auto itemName = GetItemLocalName(i.first);
stringBuilder += trapdoor::format(
" - %s " C_INT " (" C_FLOAT " / hour )\n", itemName.c_str(),
i.second, i.second * 1.0 / gameTick * 72000);
builder.textF(" - %s: ", itemName.c_str())
.sTextF(trapdoor::MSG_COLOR::GREEN, "%d", i.second)
.text("(")
.sTextF(trapdoor::MSG_COLOR::GREEN, "%.3f",
i.second * 1.0 / gameTick * 72000)
.text("/hour)\n");
}
trapdoor::info(actor, stringBuilder);
builder.send(actor);
}
} // namespace mod

Expand Down Expand Up @@ -148,99 +150,4 @@ THook(void, HopperBlockActor_setItem_c0e5f3ce,
} else {
original(hopperActor, index, itemStack);
}
}
//下面是一些漏斗性能的测试代码,不用管
// 0x00CCE6D0
// ?_tryMoveItems@Hopper@@IEAA_NAEAVBlockSource@@AEAVContainer@@AEBVVec3@@H_N@Z
//(class BlockSource & __ptr64,class Container & __ptr64,class Vec3 const &
//__ptr64,int,bool) __ptr64
// constexpr SymHook::RVA SYM_hopper_trymove_item = 0x00CCE6D0;
// THook(void, SYM_hopper_trymove_item, void *block, void *region,
// void *fromContainer, void *pos, int attachedFace, bool canPushItems) {
// rmt_ScopedCPUSample(HOPPER_MOVE_ITEM, 0);
// original(block, region, fromContainer, pos, attachedFace, canPushItems);
// }

// // 0x010DB8D0
// ?_ensureTickingOrder@HopperBlockActor@@AEAAXAEAVBlockSource@@H@Z

// constexpr SymHook::RVA SYM_ensureTickOrder = 0x010DB8D0;
// THook(void, SYM_ensureTickOrder, void *block, void *bs, int rec) {
// rmt_ScopedCPUSample(ENSURE_ORDER, 0);
// original(block, bs, rec);
// }

// //# [ԭ��] protected: bool __cdecl Hopper::_tryTakeInItemFromSlot(class
// // BlockSource & __ptr64,class Container & __ptr64,class Container &
// //__ptr64,int,int) __ptr64 0x00CCF410
// //
// ?_tryTakeInItemFromSlot@Hopper@@IEAA_NAEAVBlockSource@@AEAVContainer@@1HH@Z

// constexpr SymHook::RVA SYM_tryTakcItem = 0x00CCF410;

// THook(bool, SYM_tryTakcItem, void *self, void *region, void *toContainer,
// void *fromContainer, int slot, int face) {
// rmt_ScopedCPUSample(TAKE_A_ITEM, 0);
// return original(self, region, toContainer, fromContainer, slot, face);
// }

// //# [ԭ��] protected: bool __cdecl Hopper::_isEmptyContainer(class
// Container
// //&
// //__ptr64,int) __ptr64 0x00CCAEF0
// // ?_isEmptyContainer@Hopper@@IEAA_NAEAVContainer@@H@Z

// constexpr SymHook::RVA SYM_HopperIsEmpty = 0x00CCAEF0;

// THook(bool, SYM_HopperIsEmpty, void *hopper, void *c, int a) {
// rmt_ScopedCPUSample(HOPPER_EMPTY_CHECK, 0);
// return original(hopper, c, a);
// }

// constexpr SymHook::RVA SYM_Item_Isnull = 0x00C88A10;
// constexpr SymHook::RVA SYm_Item_getMaxStackSize = 0x00C863D0;

// bool isNull(trapdoor::ItemStackBase *item) {
// return SYM_CALL(bool (*)(trapdoor::ItemStackBase *), SYM_Item_Isnull,
// item);
// }

// unsigned char getMaxStackSize(trapdoor::ItemStackBase *item) {
// return SYM_CALL(unsigned char (*)(trapdoor::ItemStackBase *),
// SYm_Item_getMaxStackSize, item);
// }

// //# [ԭ��] protected: bool __cdecl Hopper::_isFullContainer(class
// // BlockSource
// //&
// //__ptr64,class Container & __ptr64,int) __ptr64 0x00CCAF80
// // ?_isFullContainer@Hopper@@IEAA_NAEAVBlockSource@@AEAVContainer@@H@Z

// constexpr SymHook::RVA SYM_ContainerGetSlots = 0x00BDAAE0;

// void getSlotsFromContainer(void *container,
// std::vector<trapdoor::ItemStackBase *> *slots)

// {
// SYM_CALL(void (*)(void *, std::vector<trapdoor::ItemStackBase *> *),
// SYM_ContainerGetSlots, container, slots);
// }

// constexpr SymHook::RVA SYM_HopperIsFull = 0x00CCAF80;
// THook(bool, SYM_HopperIsFull, void *hopper, void *bs, void *c, int a) {
// // rmt_ScopedCPUSample(HOPPER_FULL_CHECK, 0);

// std::vector<trapdoor::ItemStackBase *> slots;
// getSlotsFromContainer(c, &slots);
// for (const auto &i : slots) {
// if (isNull(i)) {
// return false;
// }
// if (i->getNum() < getMaxStackSize(i)) {
// return false;
// }
// }
// return true;
// // return original(hopper, bs, c, a);
// // return false;
// }
}
1 change: 0 additions & 1 deletion mod/player/PlayerFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "TrapdoorMod.h"
#include "entity/Actor.h"
#include "graphics/BlockPos.h"
#include "graphics/Graphics.h"
#include "graphics/Particle.h"
#include "language/I18nManager.h"
#include "lib/Remotery.h"
Expand Down
1 change: 0 additions & 1 deletion mod/spawn/SpawnHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "block/Block.h"
#include "block/BlockLegacy.h"
#include "graphics/AABB.h"
#include "graphics/Graphics.h"
#include "graphics/Particle.h"
#include "lib/SymHook.h"
#include "lib/mod.h"
Expand Down
Loading

0 comments on commit 0b49e14

Please sign in to comment.