Skip to content

Commit

Permalink
Showing 7 changed files with 441 additions and 292 deletions.
3 changes: 3 additions & 0 deletions api/lib/SymHook.h
Original file line number Diff line number Diff line change
@@ -392,4 +392,7 @@ constexpr RVA MSSYM_MD5_b5c9e566146b3136e6fb37f0c080d91e = 0x00361CB0;
constexpr RVA
MSSYM_B1QE12getDimensionB1AA5LevelB2AAE17UEBAPEAVDimensionB2AAA1VB2QDE11AutomaticIDB1AE10VDimensionB2AAA1HB3AAAA1Z =
0x00F8AE90;

constexpr RVA MSSYM_tickEntitySystemsLevelUEAAXXZ = 0x00F9CFE0;

} // namespace SymHook
9 changes: 5 additions & 4 deletions api/tools/MsgBuilder.cpp
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@

namespace trapdoor {
const uint8_t MessageBuilder::BLACK = 0x0;
const uint8_t MessageBuilder::DARK_GREEN = 0x2;
const uint8_t MessageBuilder::DARK_READ = 0x4;
const uint8_t MessageBuilder::GOLD = 0x6;
const uint8_t MessageBuilder::GRAY = 0x7;
@@ -25,10 +26,10 @@ const uint8_t MessageBuilder::ITALIC = 0x20;
const uint8_t MessageBuilder::RESET = 0x30;

const std::map<uint8_t, std::string> MessageBuilder::STYLE_MAP = {
{BLACK, "§0"}, {DARK_READ, "§4"}, {GOLD, "§6"}, {GRAY, "§7"},
{BLUE, "§9"}, {GREEN, "§a"}, {AQUA, "§b"}, {RED, "§c"},
{LIGHT_PURPLE, "§d"}, {YELLOW, "§e"}, {WHITE, "§f"}, {BOLD, "§l"},
{ITALIC, "§o"}, {RESET, "§r"}};
{BLACK, "§0"}, {DARK_GREEN, "§2"}, {DARK_READ, "§4"}, {GOLD, "§6"},
{GRAY, "§7"}, {BLUE, "§9"}, {GREEN, "§a"}, {AQUA, "§b"},
{RED, "§c"}, {LIGHT_PURPLE, "§d"}, {YELLOW, "§e"}, {WHITE, "§f"},
{BOLD, "§l"}, {ITALIC, "§o"}, {RESET, "§r"}};

MessageBuilder &MessageBuilder::text(const std::string &s) {
messageBuffer.emplace_back(s);
144 changes: 69 additions & 75 deletions api/tools/MsgBuilder.h
Original file line number Diff line number Diff line change
@@ -5,93 +5,87 @@
#ifndef TRAPDOOR_MSGBUILDER_H
#define TRAPDOOR_MSGBUILDER_H

#include <map>
#include <vector>
#include <string>
#include "Message.h"
#include "graphics/AABB.h"
#include "graphics/BlockPos.h"
#include "graphics/Vec3.h"
#include "graphics/AABB.h"
#include "Message.h"
#include <cstdarg>

#include <map>
#include <string>
#include <vector>

namespace trapdoor {
class Actor;

class MessageBuilder {
public:
static const uint8_t DARK_READ;
static const uint8_t RED;
static const uint8_t GOLD;
static const uint8_t YELLOW;
static const uint8_t GREEN;
static const uint8_t AQUA;
static const uint8_t BLUE;
static const uint8_t LIGHT_PURPLE;
static const uint8_t WHITE;
static const uint8_t GRAY;
static const uint8_t BLACK;

static const uint8_t BOLD;
static const uint8_t ITALIC;
static const uint8_t RESET;


MessageBuilder &text(const std::string &s);


template<typename ...Args>
MessageBuilder &textF(const std::string &format, Args ...args) {
this->text(trapdoor::format(format, args...));
return *this;
}

template<typename ...Args>
MessageBuilder &sTextF(uint8_t style, const std::string &format, Args ...args) {
this->sText(trapdoor::format(format, args...), style);
return *this;
}

MessageBuilder &sText(const std::string &s, uint8_t style);

MessageBuilder &pos(const BlockPos &pos);

template<typename T>
MessageBuilder &num(T x) {
if (std::is_arithmetic<T>()) {
if (std::is_floating_point<T>()) {
char buffer[32];
sprintf(buffer, "%.3f", (double) x);
std::string s(buffer);
sText(s, GREEN | BOLD);
} else {
sText(std::to_string(x), GREEN | BOLD);
}
class Actor;

class MessageBuilder {
public:
static const uint8_t DARK_READ;
static const uint8_t RED;
static const uint8_t GOLD;
static const uint8_t YELLOW;
static const uint8_t GREEN;
static const uint8_t DARK_GREEN;
static const uint8_t AQUA;
static const uint8_t BLUE;
static const uint8_t LIGHT_PURPLE;
static const uint8_t WHITE;
static const uint8_t GRAY;
static const uint8_t BLACK;

static const uint8_t BOLD;
static const uint8_t ITALIC;
static const uint8_t RESET;

MessageBuilder &text(const std::string &s);

template <typename... Args>
MessageBuilder &textF(const std::string &format, Args... args) {
this->text(trapdoor::format(format, args...));
return *this;
}

template <typename... Args>
MessageBuilder &sTextF(uint8_t style, const std::string &format,
Args... args) {
this->sText(trapdoor::format(format, args...), style);
return *this;
}

MessageBuilder &sText(const std::string &s, uint8_t style);

MessageBuilder &pos(const BlockPos &pos);

template <typename T> MessageBuilder &num(T x) {
if (std::is_arithmetic<T>()) {
if (std::is_floating_point<T>()) {
char buffer[32];
sprintf(buffer, "%.3f", (double)x);
std::string s(buffer);
sText(s, DARK_GREEN | BOLD);
} else {
sText(std::to_string(x), DARK_GREEN | BOLD);
}
return *this;
}
return *this;
}

MessageBuilder &vec3(const Vec3 &vec3);

MessageBuilder &aabb(AABB aabb);
MessageBuilder &vec3(const Vec3 &vec3);

MessageBuilder &aabb(AABB aabb);

std::string get();
std::string get();

void send(Actor *player);
void send(Actor *player);

void broadcast();

void operator+=(const std::string &str) {
this->text(str);
}
void broadcast();

void operator+=(const std::string &str) { this->text(str); }

private:
const static std::map<uint8_t, std::string> STYLE_MAP;
std::vector<std::string> messageBuffer;
};
private:
const static std::map<uint8_t, std::string> STYLE_MAP;
std::vector<std::string> messageBuffer;
};

typedef MessageBuilder MSG_COLOR;
}
#endif //TRAPDOOR_MSGBUILDER_H
typedef MessageBuilder MSG_COLOR;
} // namespace trapdoor
#endif // TRAPDOOR_MSGBUILDER_H
345 changes: 183 additions & 162 deletions mod/fakePlayer/FakePlayerClient.cpp

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions mod/function/HopperCounter.cpp
Original file line number Diff line number Diff line change
@@ -146,3 +146,98 @@ THook(
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;
// }
25 changes: 10 additions & 15 deletions mod/tick/GameTick.cpp
Original file line number Diff line number Diff line change
@@ -418,21 +418,16 @@ THook(void, MSSYM_B1QE12tickRedstoneB1AA9DimensionB2AAA7UEAAXXZ, void *dim) {
// printf("69:%d 68:%d\n", v1, v2);
}

// THook(
// void,
// MSSYM_B1QA4tickB1AE13EntitySystemsB2AAE23QEAAXAEAVEntityRegistryB3AAAA1Z,
// void *entitySystem,
// void * registry
// ) {
// if (mod::tick::gameProfiler.inProfiling) {
// TIMER_START
// original(entitySystem, registry);
// TIMER_END
// mod::tick::gameProfiler.levelEntitySystemTickTime += timeReslut;
// } else {
// original(entitySystem, registry);
// }
// }
THook(void, MSSYM_tickEntitySystemsLevelUEAAXXZ, void *level) {
if (mod::tick::gameProfiler.inProfiling) {
TIMER_START
original(level);
TIMER_END
mod::tick::gameProfiler.levelEntitySystemTickTime += timeReslut;
} else {
original(level);
}
}

// pending update
//这个符号没了,直接测不准就不要这一条了
112 changes: 76 additions & 36 deletions mod/tick/SimpleProfiler.cpp
Original file line number Diff line number Diff line change
@@ -3,45 +3,85 @@
//

#include "SimpleProfiler.h"
#include "tools/MsgBuilder.h"
#include "Message.h"
#include "entity/Actor.h"
#include "tools/MsgBuilder.h"

namespace mod {
// serverLevelTickTime = 0; //mspt
// levelEntityTickTime = 0; //实体更新 O
// redstoneTickTime = 0; //红石更新O
// dimensionTickTime = 0; //区块加载卸载&村庄 O
// chunkTickTime = 0; //区块更新 O
// chunkBlockEntityTickTime = 0; //方块实体更新
// chunkRandomTickTime = 0; //随机刻更新
// chunkPendingTickTime = 0; //计划刻更新
// chunkRandomPendingTickTime = 0; //随机计划刻更新
// levelEntitySystemTickTime = 0; //实体系统更新 O
void SimpleProfiler::print() const {
auto rounds = static_cast<float >(this->totalRound * 1000);
int tps = static_cast<int>( 1000.0 / (serverLevelTickTime / rounds));
if (tps > 20) tps = 20;
trapdoor::MessageBuilder builder;
auto totalRedstoneTickTime =
static_cast<float>
(redstoneTickTime + redstonePendingUpdateTime + redstonePendingRemoveTime) /
rounds;
builder.textF("Total mspt: %.3fms TPS: %d\n", serverLevelTickTime / rounds, tps)
.textF(" - Redstone: %.3fms\n", totalRedstoneTickTime)
.textF(" - SignalUpdate: %.3fms\n", redstoneTickTime / rounds)
.textF(" - PendingUpdate: %.3fms\n", redstonePendingUpdateTime / rounds)
.textF(" - PendingAdd: %.3fms\n", redstonePendingAddTime / rounds)
.textF(" - PendingRemove: %.3fms\n", redstonePendingRemoveTime / rounds)
.textF(" - EntitySystem: %.3fms\n", levelEntitySystemTickTime / rounds)
.textF(" - Chunk (un)load & village: %.3fms\n", dimensionTickTime / rounds)
// .textF("Trapdoor: %.3fms", trapdoorModTickTime / rounds)
.textF(" - Chunk tick: %.3fms (%d)\n", chunkTickTime / rounds, tickChunkNum / totalRound)
.textF(" - Block entity: %.3fms\n", chunkBlockEntityTickTime / rounds)
.textF(" - Random tick: %.3fms\n", chunkRandomTickTime / rounds)
.textF(" - Pending tick: %.3f/%.3fms\n", chunkRandomPendingTickTime / rounds,
chunkPendingTickTime / rounds)
.broadcast();
}

namespace {

void addShowItem(trapdoor::MessageBuilder &builder, const std::string &prefix,
const std::string &key, float value) {

builder.sText(prefix, trapdoor::MSG_COLOR::GRAY)
.sText(key + ": ", trapdoor::MSG_COLOR::WHITE)
.sTextF(trapdoor::MSG_COLOR::WHITE | trapdoor::MessageBuilder::BOLD,
"%.3fms\n", value);
}
} // namespace

// serverLevelTickTime = 0; //mspt
// levelEntityTickTime = 0; //实体更新 O
// redstoneTickTime = 0; //红石更新O
// dimensionTickTime = 0; //区块加载卸载&村庄 O
// chunkTickTime = 0; //区块更新 O
// chunkBlockEntityTickTime = 0; //方块实体更新
// chunkRandomTickTime = 0; //随机刻更新
// chunkPendingTickTime = 0; //计划刻更新
// chunkRandomPendingTickTime = 0; //随机计划刻更新
// levelEntitySystemTickTime = 0; //实体系统更新 O

void SimpleProfiler::print() const {
auto rounds = static_cast<float>(this->totalRound * 1000);
int tps = static_cast<int>(1000.0 / (serverLevelTickTime / rounds));
if (tps > 20)
tps = 20;
trapdoor::MessageBuilder builder;
auto totalRedstoneTickTime =
static_cast<float>(redstoneTickTime + redstonePendingUpdateTime +
redstonePendingRemoveTime) /
rounds;

builder.textF("MSPT: ");
auto color =
tps < 20 ? trapdoor::MSG_COLOR::RED : trapdoor::MSG_COLOR::WHITE;
builder.sTextF(color, "%.3fms", serverLevelTickTime / rounds)
.text(" TPS: ")
.sTextF(color, "%d", tps)
.textF(" Chunks: %d\n", tickChunkNum / this->totalRound);
addShowItem(builder, " - ", "Redstone", totalRedstoneTickTime);
addShowItem(builder, " - ", "SignalUpdate", redstoneTickTime / rounds);

builder.sText(" - ", trapdoor::MSG_COLOR::GRAY)
.text("PendingUpdate: Invalid\n");
addShowItem(builder, " - ", "PendingRemove",
redstonePendingRemoveTime / rounds);

addShowItem(builder, " - ", "EntitySystem",
levelEntitySystemTickTime / rounds);
addShowItem(builder, " - ", "Chunk (un)load & village",
dimensionTickTime / rounds);

addShowItem(builder, " - ", "ChunkTick", chunkTickTime / rounds);

addShowItem(builder, " - ", "BlockEntities",
chunkBlockEntityTickTime / rounds);
addShowItem(builder, " - ", "RandomTick", chunkRandomTickTime / rounds);

addShowItem(builder, " - ", "PendingTick", chunkPendingTickTime / rounds);

builder.broadcast();

// .textF(" - Chunk tick: %.3fms (%d)\n", chunkTickTime / rounds,
// tickChunkNum / totalRound)
// .textF(" - Block entity: %.3fms\n",
// chunkBlockEntityTickTime / rounds)
// .textF(" - Random tick: %.3fms\n", chunkRandomTickTime / rounds)
// .textF(" - Pending tick: %.3f/%.3fms\n",
// chunkRandomPendingTickTime / rounds,
// chunkPendingTickTime / rounds)
// .text(" - Entity tick: may be the rest")
// .broadcast();
}
} // namespace mod

0 comments on commit 144bca3

Please sign in to comment.