From 0b49e14fa653fcfad03cc14413a4d8c763630fb0 Mon Sep 17 00:00:00 2001 From: xiaohengying <2602645221@qq.com> Date: Wed, 26 Jan 2022 00:15:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dvillage=20v=E9=97=AA=E9=80=80?= =?UTF-8?q?=E7=9A=84hug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 - api/entity/Actor.cpp | 9 +- api/graphics/Graphics.cpp | 15 -- api/graphics/Graphics.h | 16 -- api/lib/Remotery.h | 430 ++++++++++++++++----------------- api/tools/DirtyLogger.cpp | 2 +- mod/config/ConfigManager.cpp | 1 - mod/dllmain.cpp | 1 - mod/function/HopperCounter.cpp | 115 +-------- mod/player/PlayerFunction.cpp | 1 - mod/spawn/SpawnHelper.cpp | 1 - mod/village/Village.cpp | 109 ++++++--- mod/village/Village.h | 46 ++-- 13 files changed, 335 insertions(+), 412 deletions(-) delete mode 100644 api/graphics/Graphics.cpp delete mode 100644 api/graphics/Graphics.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e24c56..339c8a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/api/entity/Actor.cpp b/api/entity/Actor.cpp index fa7700a..b244ac1 100644 --- a/api/entity/Actor.cpp +++ b/api/entity/Actor.cpp @@ -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() { diff --git a/api/graphics/Graphics.cpp b/api/graphics/Graphics.cpp deleted file mode 100644 index 47fd022..0000000 --- a/api/graphics/Graphics.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// -// Created by xhy on 2020/12/12. -// - -#include "Graphics.h" - -#include - -#include "BDSMod.h" -#include "Particle.h" - -namespace trapdoor { - - -} // namespace trapdoor diff --git a/api/graphics/Graphics.h b/api/graphics/Graphics.h deleted file mode 100644 index 91f3313..0000000 --- a/api/graphics/Graphics.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by xhy on 2020/12/12. -// - -#ifndef TRAPDOOR_GRAPHICS_H -#define TRAPDOOR_GRAPHICS_H - -//#include "Particle.h" -#include -#include - -#include "BlockPos.h" -#include "Particle.h" -namespace trapdoor {} // namespace trapdoor - -#endif // TRAPDOOR_GRAPHICS_H diff --git a/api/lib/Remotery.h b/api/lib/Remotery.h index 249972d..38e6663 100644 --- a/api/lib/Remotery.h +++ b/api/lib/Remotery.h @@ -16,38 +16,38 @@ See the License for the specific language governing permissions and limitations under the License. */ - /* Compiling --------- -* Windows (MSVC) - add lib/Remotery.c and lib/Remotery.h to your program. Set include - directories to add Remotery/lib path. The required library ws2_32.lib should be picked - up through the use of the #pragma comment(lib, "ws2_32.lib") directive in Remotery.c. +* Windows (MSVC) - add lib/Remotery.c and lib/Remotery.h to your program. Set +include directories to add Remotery/lib path. The required library ws2_32.lib +should be picked up through the use of the #pragma comment(lib, "ws2_32.lib") +directive in Remotery.c. -* Mac OS X (XCode) - simply add lib/Remotery.c and lib/Remotery.h to your program. +* Mac OS X (XCode) - simply add lib/Remotery.c and lib/Remotery.h to your +program. -* Linux (GCC) - add the source in lib folder. Compilation of the code requires -pthreads for - library linkage. For example to compile the same run: cc lib/Remotery.c sample/sample.c - -I lib -pthread -lm +* Linux (GCC) - add the source in lib folder. Compilation of the code requires +-pthreads for library linkage. For example to compile the same run: cc +lib/Remotery.c sample/sample.c -I lib -pthread -lm -You can define some extra macros to modify what features are compiled into Remotery. These are -documented just below this comment. +You can define some extra macros to modify what features are compiled into +Remotery. These are documented just below this comment. */ - #ifndef RMT_INCLUDED_H #define RMT_INCLUDED_H - // Set to 0 to not include any bits of Remotery in your build #ifndef RMT_ENABLED #define RMT_ENABLED 0 #endif -// Help performance of the server sending data to the client by marking this machine as little-endian +// Help performance of the server sending data to the client by marking this +// machine as little-endian #ifndef RMT_ASSUME_LITTLE_ENDIAN #define RMT_ASSUME_LITTLE_ENDIAN 0 #endif @@ -89,10 +89,9 @@ documented just below this comment. #define RMT_GPU_CPU_SYNC_NUM_ITERATIONS 16 #endif -// Time in seconds between each resync to compensate for drifting between GPU & CPU timers, -// effects of power saving, etc. Resyncs can cause stutter, lag spikes, stalls. -// Set to 0 for never. -// Affects OpenGL & D3D11 +// Time in seconds between each resync to compensate for drifting between GPU & +// CPU timers, effects of power saving, etc. Resyncs can cause stutter, lag +// spikes, stalls. Set to 0 for never. Affects OpenGL & D3D11 #ifndef RMT_GPU_CPU_SYNC_SECONDS #define RMT_GPU_CPU_SYNC_SECONDS 30 #endif @@ -106,7 +105,6 @@ documented just below this comment. #define RMT_D3D11_RESYNC_ON_DISJOINT 1 #endif - /* ------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------ @@ -115,7 +113,6 @@ documented just below this comment. ------------------------------------------------------------------------------------------------------------------------ */ - // Platform identification #if defined(_WINDOWS) || defined(_WIN32) #define RMT_PLATFORM_WINDOWS @@ -128,14 +125,14 @@ documented just below this comment. #endif #ifdef RMT_DLL -#if defined (RMT_PLATFORM_WINDOWS) -#if defined (RMT_IMPL) +#if defined(RMT_PLATFORM_WINDOWS) +#if defined(RMT_IMPL) #define RMT_API __declspec(dllexport) #else #define RMT_API __declspec(dllimport) #endif -#elif defined (RMT_PLATFORM_POSIX) -#if defined (RMT_IMPL) +#elif defined(RMT_PLATFORM_POSIX) +#if defined(RMT_IMPL) #define RMT_API __attribute__((visibility("default"))) #else #define RMT_API @@ -145,8 +142,8 @@ documented just below this comment. #define RMT_API #endif -// Allows macros to be written that can work around the inability to do: #define(x) #ifdef x -// with the C preprocessor. +// Allows macros to be written that can work around the inability to do: +// #define(x) #ifdef x with the C preprocessor. #if RMT_ENABLED #define IFDEF_RMT_ENABLED(t, f) t #else @@ -173,12 +170,10 @@ documented just below this comment. #define IFDEF_RMT_USE_METAL(t, f) f #endif - -// Public interface is written in terms of these macros to easily enable/disable itself -#define RMT_OPTIONAL(macro, x) IFDEF_ ## macro(x, ) -#define RMT_OPTIONAL_RET(macro, x, y) IFDEF_ ## macro(x, (y)) - - +// Public interface is written in terms of these macros to easily enable/disable +// itself +#define RMT_OPTIONAL(macro, x) IFDEF_##macro(x, ) +#define RMT_OPTIONAL_RET(macro, x, y) IFDEF_##macro(x, (y)) /* ------------------------------------------------------------------------------------------------------------------------ @@ -188,112 +183,148 @@ documented just below this comment. ------------------------------------------------------------------------------------------------------------------------ */ - - // Boolean typedef unsigned int rmtBool; #define RMT_TRUE ((rmtBool)1) #define RMT_FALSE ((rmtBool)0) - // Unsigned integer types typedef unsigned char rmtU8; typedef unsigned short rmtU16; typedef unsigned int rmtU32; typedef unsigned long long rmtU64; - // Signed integer types typedef char rmtS8; typedef short rmtS16; typedef int rmtS32; typedef long long rmtS64; - // Const, null-terminated string pointer typedef const char *rmtPStr; - // Handle to the main remotery instance typedef struct Remotery Remotery; - // All possible error codes typedef enum rmtError { RMT_ERROR_NONE, - RMT_ERROR_RECURSIVE_SAMPLE, // Not an error but an internal message to calling code + RMT_ERROR_RECURSIVE_SAMPLE, // Not an error but an internal message to + // calling code // System errors - RMT_ERROR_MALLOC_FAIL, // Malloc call within remotery failed - RMT_ERROR_TLS_ALLOC_FAIL, // Attempt to allocate thread local storage failed - RMT_ERROR_VIRTUAL_MEMORY_BUFFER_FAIL, // Failed to create a virtual memory mirror buffer - RMT_ERROR_CREATE_THREAD_FAIL, // Failed to create a thread for the server + RMT_ERROR_MALLOC_FAIL, // Malloc call within remotery failed + RMT_ERROR_TLS_ALLOC_FAIL, // Attempt to allocate thread local storage + // failed + RMT_ERROR_VIRTUAL_MEMORY_BUFFER_FAIL, // Failed to create a virtual memory + // mirror buffer + RMT_ERROR_CREATE_THREAD_FAIL, // Failed to create a thread for the server // Network TCP/IP socket errors - RMT_ERROR_SOCKET_INIT_NETWORK_FAIL, // Network initialisation failure (e.g. on Win32, WSAStartup fails) - RMT_ERROR_SOCKET_CREATE_FAIL, // Can't create a socket for connection to the remote viewer - RMT_ERROR_SOCKET_BIND_FAIL, // Can't bind a socket for the server - RMT_ERROR_SOCKET_LISTEN_FAIL, // Created server socket failed to enter a listen state - RMT_ERROR_SOCKET_SET_NON_BLOCKING_FAIL, // Created server socket failed to switch to a non-blocking state - RMT_ERROR_SOCKET_INVALID_POLL, // Poll attempt on an invalid socket - RMT_ERROR_SOCKET_SELECT_FAIL, // Server failed to call select on socket - RMT_ERROR_SOCKET_POLL_ERRORS, // Poll notified that the socket has errors - RMT_ERROR_SOCKET_ACCEPT_FAIL, // Server failed to accept connection from client - RMT_ERROR_SOCKET_SEND_TIMEOUT, // Timed out trying to send data - RMT_ERROR_SOCKET_SEND_FAIL, // Unrecoverable error occured while client/server tried to send data - RMT_ERROR_SOCKET_RECV_NO_DATA, // No data available when attempting a receive - RMT_ERROR_SOCKET_RECV_TIMEOUT, // Timed out trying to receive data - RMT_ERROR_SOCKET_RECV_FAILED, // Unrecoverable error occured while client/server tried to receive data + RMT_ERROR_SOCKET_INIT_NETWORK_FAIL, // Network initialisation failure (e.g. + // on Win32, WSAStartup fails) + RMT_ERROR_SOCKET_CREATE_FAIL, // Can't create a socket for connection to + // the remote viewer + RMT_ERROR_SOCKET_BIND_FAIL, // Can't bind a socket for the server + RMT_ERROR_SOCKET_LISTEN_FAIL, // Created server socket failed to enter a + // listen state + RMT_ERROR_SOCKET_SET_NON_BLOCKING_FAIL, // Created server socket failed to + // switch to a non-blocking state + RMT_ERROR_SOCKET_INVALID_POLL, // Poll attempt on an invalid socket + RMT_ERROR_SOCKET_SELECT_FAIL, // Server failed to call select on socket + RMT_ERROR_SOCKET_POLL_ERRORS, // Poll notified that the socket has errors + RMT_ERROR_SOCKET_ACCEPT_FAIL, // Server failed to accept connection from + // client + RMT_ERROR_SOCKET_SEND_TIMEOUT, // Timed out trying to send data + RMT_ERROR_SOCKET_SEND_FAIL, // Unrecoverable error occured while + // client/server tried to send data + RMT_ERROR_SOCKET_RECV_NO_DATA, // No data available when attempting a + // receive + RMT_ERROR_SOCKET_RECV_TIMEOUT, // Timed out trying to receive data + RMT_ERROR_SOCKET_RECV_FAILED, // Unrecoverable error occured while + // client/server tried to receive data // WebSocket errors - RMT_ERROR_WEBSOCKET_HANDSHAKE_NOT_GET, // WebSocket server handshake failed, not HTTP GET - RMT_ERROR_WEBSOCKET_HANDSHAKE_NO_VERSION, // WebSocket server handshake failed, can't locate WebSocket version - RMT_ERROR_WEBSOCKET_HANDSHAKE_BAD_VERSION, // WebSocket server handshake failed, unsupported WebSocket version - RMT_ERROR_WEBSOCKET_HANDSHAKE_NO_HOST, // WebSocket server handshake failed, can't locate host - RMT_ERROR_WEBSOCKET_HANDSHAKE_BAD_HOST, // WebSocket server handshake failed, host is not allowed to connect - RMT_ERROR_WEBSOCKET_HANDSHAKE_NO_KEY, // WebSocket server handshake failed, can't locate WebSocket key - RMT_ERROR_WEBSOCKET_HANDSHAKE_BAD_KEY, // WebSocket server handshake failed, WebSocket key is ill-formed - RMT_ERROR_WEBSOCKET_HANDSHAKE_STRING_FAIL, // WebSocket server handshake failed, internal error, bad string code - RMT_ERROR_WEBSOCKET_DISCONNECTED, // WebSocket server received a disconnect request and closed the socket - RMT_ERROR_WEBSOCKET_BAD_FRAME_HEADER, // Couldn't parse WebSocket frame header - RMT_ERROR_WEBSOCKET_BAD_FRAME_HEADER_SIZE, // Partially received wide frame header size - RMT_ERROR_WEBSOCKET_BAD_FRAME_HEADER_MASK, // Partially received frame header data mask - RMT_ERROR_WEBSOCKET_RECEIVE_TIMEOUT, // Timeout receiving frame header - - RMT_ERROR_REMOTERY_NOT_CREATED, // Remotery object has not been created - RMT_ERROR_SEND_ON_INCOMPLETE_PROFILE, // An attempt was made to send an incomplete profile tree to the client + RMT_ERROR_WEBSOCKET_HANDSHAKE_NOT_GET, // WebSocket server handshake + // failed, not HTTP GET + RMT_ERROR_WEBSOCKET_HANDSHAKE_NO_VERSION, // WebSocket server handshake + // failed, can't locate WebSocket + // version + RMT_ERROR_WEBSOCKET_HANDSHAKE_BAD_VERSION, // WebSocket server handshake + // failed, unsupported WebSocket + // version + RMT_ERROR_WEBSOCKET_HANDSHAKE_NO_HOST, // WebSocket server handshake + // failed, can't locate host + RMT_ERROR_WEBSOCKET_HANDSHAKE_BAD_HOST, // WebSocket server handshake + // failed, host is not allowed to + // connect + RMT_ERROR_WEBSOCKET_HANDSHAKE_NO_KEY, // WebSocket server handshake failed, + // can't locate WebSocket key + RMT_ERROR_WEBSOCKET_HANDSHAKE_BAD_KEY, // WebSocket server handshake + // failed, WebSocket key is + // ill-formed + RMT_ERROR_WEBSOCKET_HANDSHAKE_STRING_FAIL, // WebSocket server handshake + // failed, internal error, bad + // string code + RMT_ERROR_WEBSOCKET_DISCONNECTED, // WebSocket server received a disconnect + // request and closed the socket + RMT_ERROR_WEBSOCKET_BAD_FRAME_HEADER, // Couldn't parse WebSocket frame + // header + RMT_ERROR_WEBSOCKET_BAD_FRAME_HEADER_SIZE, // Partially received wide frame + // header size + RMT_ERROR_WEBSOCKET_BAD_FRAME_HEADER_MASK, // Partially received frame + // header data mask + RMT_ERROR_WEBSOCKET_RECEIVE_TIMEOUT, // Timeout receiving frame header + + RMT_ERROR_REMOTERY_NOT_CREATED, // Remotery object has not been created + RMT_ERROR_SEND_ON_INCOMPLETE_PROFILE, // An attempt was made to send an + // incomplete profile tree to the + // client // CUDA error messages - RMT_ERROR_CUDA_DEINITIALIZED, // This indicates that the CUDA driver is in the process of shutting down - RMT_ERROR_CUDA_NOT_INITIALIZED, // This indicates that the CUDA driver has not been initialized with cuInit() or that initialization has failed - RMT_ERROR_CUDA_INVALID_CONTEXT, // This most frequently indicates that there is no context bound to the current thread - RMT_ERROR_CUDA_INVALID_VALUE, // This indicates that one or more of the parameters passed to the API call is not within an acceptable range of values - RMT_ERROR_CUDA_INVALID_HANDLE, // This indicates that a resource handle passed to the API call was not valid - RMT_ERROR_CUDA_OUT_OF_MEMORY, // The API call failed because it was unable to allocate enough memory to perform the requested operation - RMT_ERROR_ERROR_NOT_READY, // This indicates that a resource handle passed to the API call was not valid + RMT_ERROR_CUDA_DEINITIALIZED, // This indicates that the CUDA driver is in + // the process of shutting down + RMT_ERROR_CUDA_NOT_INITIALIZED, // This indicates that the CUDA driver has + // not been initialized with cuInit() or + // that initialization has failed + RMT_ERROR_CUDA_INVALID_CONTEXT, // This most frequently indicates that + // there is no context bound to the current + // thread + RMT_ERROR_CUDA_INVALID_VALUE, // This indicates that one or more of the + // parameters passed to the API call is not + // within an acceptable range of values + RMT_ERROR_CUDA_INVALID_HANDLE, // This indicates that a resource handle + // passed to the API call was not valid + RMT_ERROR_CUDA_OUT_OF_MEMORY, // The API call failed because it was unable + // to allocate enough memory to perform the + // requested operation + RMT_ERROR_ERROR_NOT_READY, // This indicates that a resource handle passed + // to the API call was not valid // Direct3D 11 error messages - RMT_ERROR_D3D11_FAILED_TO_CREATE_QUERY, // Failed to create query for sample + RMT_ERROR_D3D11_FAILED_TO_CREATE_QUERY, // Failed to create query for + // sample // OpenGL error messages - RMT_ERROR_OPENGL_ERROR, // Generic OpenGL error, no need to expose detail since app will need an OpenGL error callback registered + RMT_ERROR_OPENGL_ERROR, // Generic OpenGL error, no need to expose detail + // since app will need an OpenGL error callback + // registered RMT_ERROR_CUDA_UNKNOWN, } rmtError; - typedef enum rmtSampleFlags { // Default behaviour RMTSF_None = 0, - // Search parent for same-named samples and merge timing instead of adding a new sample + // Search parent for same-named samples and merge timing instead of adding a + // new sample RMTSF_Aggregate = 1, // Merge sample with parent if it's the same sample RMTSF_Recursive = 2, } rmtSampleFlags; - /* ------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------ @@ -302,44 +333,39 @@ typedef enum rmtSampleFlags { ------------------------------------------------------------------------------------------------------------------------ */ - - // Can call remotery functions on a null pointer // TODO: Can embed extern "C" in these macros? -#define rmt_Settings() \ - RMT_OPTIONAL_RET(RMT_ENABLED, _rmt_Settings(), NULL ) +#define rmt_Settings() RMT_OPTIONAL_RET(RMT_ENABLED, _rmt_Settings(), NULL) -#define rmt_CreateGlobalInstance(rmt) \ - RMT_OPTIONAL_RET(RMT_ENABLED, _rmt_CreateGlobalInstance(rmt), RMT_ERROR_NONE) +#define rmt_CreateGlobalInstance(rmt) \ + RMT_OPTIONAL_RET(RMT_ENABLED, _rmt_CreateGlobalInstance(rmt), \ + RMT_ERROR_NONE) -#define rmt_DestroyGlobalInstance(rmt) \ +#define rmt_DestroyGlobalInstance(rmt) \ RMT_OPTIONAL(RMT_ENABLED, _rmt_DestroyGlobalInstance(rmt)) -#define rmt_SetGlobalInstance(rmt) \ +#define rmt_SetGlobalInstance(rmt) \ RMT_OPTIONAL(RMT_ENABLED, _rmt_SetGlobalInstance(rmt)) -#define rmt_GetGlobalInstance() \ +#define rmt_GetGlobalInstance() \ RMT_OPTIONAL_RET(RMT_ENABLED, _rmt_GetGlobalInstance(), NULL) -#define rmt_SetCurrentThreadName(rmt) \ +#define rmt_SetCurrentThreadName(rmt) \ RMT_OPTIONAL(RMT_ENABLED, _rmt_SetCurrentThreadName(rmt)) -#define rmt_LogText(text) \ - RMT_OPTIONAL(RMT_ENABLED, _rmt_LogText(text)) +#define rmt_LogText(text) RMT_OPTIONAL(RMT_ENABLED, _rmt_LogText(text)) -#define rmt_BeginCPUSample(name, flags) \ - RMT_OPTIONAL(RMT_ENABLED, { \ - static rmtU32 rmt_sample_hash_##name = 0; \ - _rmt_BeginCPUSample(#name, flags, &rmt_sample_hash_##name); \ +#define rmt_BeginCPUSample(name, flags) \ + RMT_OPTIONAL(RMT_ENABLED, { \ + static rmtU32 rmt_sample_hash_##name = 0; \ + _rmt_BeginCPUSample(#name, flags, &rmt_sample_hash_##name); \ }) -#define rmt_BeginCPUSampleDynamic(namestr, flags) \ +#define rmt_BeginCPUSampleDynamic(namestr, flags) \ RMT_OPTIONAL(RMT_ENABLED, _rmt_BeginCPUSample(namestr, flags, NULL)) -#define rmt_EndCPUSample() \ - RMT_OPTIONAL(RMT_ENABLED, _rmt_EndCPUSample()) - +#define rmt_EndCPUSample() RMT_OPTIONAL(RMT_ENABLED, _rmt_EndCPUSample()) // Callback function pointer types typedef void *(*rmtMallocPtr)(void *mm_context, rmtU32 size); @@ -350,7 +376,6 @@ typedef void (*rmtFreePtr)(void *mm_context, void *ptr); typedef void (*rmtInputHandlerPtr)(const char *text, void *context); - // Struture to fill in to modify Remotery default settings typedef struct rmtSettings { // Which port to listen for incoming connections on @@ -396,7 +421,6 @@ typedef struct rmtSettings { rmtPStr logPath; } rmtSettings; - // Structure to fill in when binding CUDA to Remotery typedef struct rmtCUDABind { // The main context that all driver functions apply before each call @@ -404,9 +428,9 @@ typedef struct rmtCUDABind { // Driver API function pointers that need to be pointed to // Untyped so that the CUDA headers are not required in this file - // NOTE: These are named differently to the CUDA functions because the CUDA API has a habit of using - // macros to point function calls to different versions, e.g. cuEventDestroy is a macro for - // cuEventDestroy_v2. + // NOTE: These are named differently to the CUDA functions because the CUDA + // API has a habit of using macros to point function calls to different + // versions, e.g. cuEventDestroy is a macro for cuEventDestroy_v2. void *CtxSetCurrent; void *CtxGetCurrent; void *EventCreate; @@ -417,81 +441,67 @@ typedef struct rmtCUDABind { } rmtCUDABind; - // Call once after you've initialised CUDA to bind it to Remotery -#define rmt_BindCUDA(bind) \ - RMT_OPTIONAL(RMT_USE_CUDA, _rmt_BindCUDA(bind)) +#define rmt_BindCUDA(bind) RMT_OPTIONAL(RMT_USE_CUDA, _rmt_BindCUDA(bind)) // Mark the beginning of a CUDA sample on the specified asynchronous stream -#define rmt_BeginCUDASample(name, stream) \ - RMT_OPTIONAL(RMT_USE_CUDA, { \ - static rmtU32 rmt_sample_hash_##name = 0; \ - _rmt_BeginCUDASample(#name, &rmt_sample_hash_##name, stream); \ +#define rmt_BeginCUDASample(name, stream) \ + RMT_OPTIONAL(RMT_USE_CUDA, { \ + static rmtU32 rmt_sample_hash_##name = 0; \ + _rmt_BeginCUDASample(#name, &rmt_sample_hash_##name, stream); \ }) // Mark the end of a CUDA sample on the specified asynchronous stream -#define rmt_EndCUDASample(stream) \ +#define rmt_EndCUDASample(stream) \ RMT_OPTIONAL(RMT_USE_CUDA, _rmt_EndCUDASample(stream)) - -#define rmt_BindD3D11(device, context) \ +#define rmt_BindD3D11(device, context) \ RMT_OPTIONAL(RMT_USE_D3D11, _rmt_BindD3D11(device, context)) -#define rmt_UnbindD3D11() \ - RMT_OPTIONAL(RMT_USE_D3D11, _rmt_UnbindD3D11()) +#define rmt_UnbindD3D11() RMT_OPTIONAL(RMT_USE_D3D11, _rmt_UnbindD3D11()) -#define rmt_BeginD3D11Sample(name) \ - RMT_OPTIONAL(RMT_USE_D3D11, { \ - static rmtU32 rmt_sample_hash_##name = 0; \ - _rmt_BeginD3D11Sample(#name, &rmt_sample_hash_##name); \ +#define rmt_BeginD3D11Sample(name) \ + RMT_OPTIONAL(RMT_USE_D3D11, { \ + static rmtU32 rmt_sample_hash_##name = 0; \ + _rmt_BeginD3D11Sample(#name, &rmt_sample_hash_##name); \ }) -#define rmt_BeginD3D11SampleDynamic(namestr) \ +#define rmt_BeginD3D11SampleDynamic(namestr) \ RMT_OPTIONAL(RMT_USE_D3D11, _rmt_BeginD3D11Sample(namestr, NULL)) -#define rmt_EndD3D11Sample() \ - RMT_OPTIONAL(RMT_USE_D3D11, _rmt_EndD3D11Sample()) - +#define rmt_EndD3D11Sample() RMT_OPTIONAL(RMT_USE_D3D11, _rmt_EndD3D11Sample()) -#define rmt_BindOpenGL() \ - RMT_OPTIONAL(RMT_USE_OPENGL, _rmt_BindOpenGL()) +#define rmt_BindOpenGL() RMT_OPTIONAL(RMT_USE_OPENGL, _rmt_BindOpenGL()) -#define rmt_UnbindOpenGL() \ - RMT_OPTIONAL(RMT_USE_OPENGL, _rmt_UnbindOpenGL()) +#define rmt_UnbindOpenGL() RMT_OPTIONAL(RMT_USE_OPENGL, _rmt_UnbindOpenGL()) -#define rmt_BeginOpenGLSample(name) \ - RMT_OPTIONAL(RMT_USE_OPENGL, { \ - static rmtU32 rmt_sample_hash_##name = 0; \ - _rmt_BeginOpenGLSample(#name, &rmt_sample_hash_##name); \ +#define rmt_BeginOpenGLSample(name) \ + RMT_OPTIONAL(RMT_USE_OPENGL, { \ + static rmtU32 rmt_sample_hash_##name = 0; \ + _rmt_BeginOpenGLSample(#name, &rmt_sample_hash_##name); \ }) -#define rmt_BeginOpenGLSampleDynamic(namestr) \ +#define rmt_BeginOpenGLSampleDynamic(namestr) \ RMT_OPTIONAL(RMT_USE_OPENGL, _rmt_BeginOpenGLSample(namestr, NULL)) -#define rmt_EndOpenGLSample() \ +#define rmt_EndOpenGLSample() \ RMT_OPTIONAL(RMT_USE_OPENGL, _rmt_EndOpenGLSample()) - -#define rmt_BindMetal(command_buffer) \ +#define rmt_BindMetal(command_buffer) \ RMT_OPTIONAL(RMT_USE_METAL, _rmt_BindMetal(command_buffer)); -#define rmt_UnbindMetal() \ - RMT_OPTIONAL(RMT_USE_METAL, _rmt_UnbindMetal()); +#define rmt_UnbindMetal() RMT_OPTIONAL(RMT_USE_METAL, _rmt_UnbindMetal()); -#define rmt_BeginMetalSample(name) \ - RMT_OPTIONAL(RMT_USE_METAL, { \ - static rmtU32 rmt_sample_hash_##name = 0; \ - _rmt_BeginMetalSample(#name, &rmt_sample_hash_##name); \ +#define rmt_BeginMetalSample(name) \ + RMT_OPTIONAL(RMT_USE_METAL, { \ + static rmtU32 rmt_sample_hash_##name = 0; \ + _rmt_BeginMetalSample(#name, &rmt_sample_hash_##name); \ }) -#define rmt_BeginMetalSampleDynamic(namestr) \ +#define rmt_BeginMetalSampleDynamic(namestr) \ RMT_OPTIONAL(RMT_USE_METAL, _rmt_BeginMetalSample(namestr, NULL)) -#define rmt_EndMetalSample() \ - RMT_OPTIONAL(RMT_USE_METAL, _rmt_EndMetalSample()) - - - +#define rmt_EndMetalSample() RMT_OPTIONAL(RMT_USE_METAL, _rmt_EndMetalSample()) /* ------------------------------------------------------------------------------------------------------------------------ @@ -501,94 +511,74 @@ typedef struct rmtCUDABind { ------------------------------------------------------------------------------------------------------------------------ */ - - #ifdef __cplusplus - #if RMT_ENABLED // Types that end samples in their destructors extern "C" RMT_API void _rmt_EndCPUSample(void); struct rmt_EndCPUSampleOnScopeExit { - ~rmt_EndCPUSampleOnScopeExit() { - _rmt_EndCPUSample(); - } + ~rmt_EndCPUSampleOnScopeExit() { _rmt_EndCPUSample(); } }; #if RMT_USE_CUDA -extern "C" RMT_API void _rmt_EndCUDASample(void* stream); -struct rmt_EndCUDASampleOnScopeExit -{ - rmt_EndCUDASampleOnScopeExit(void* stream) : stream(stream) - { - } - ~rmt_EndCUDASampleOnScopeExit() - { - _rmt_EndCUDASample(stream); - } - void* stream; +extern "C" RMT_API void _rmt_EndCUDASample(void *stream); +struct rmt_EndCUDASampleOnScopeExit { + rmt_EndCUDASampleOnScopeExit(void *stream) : stream(stream) {} + ~rmt_EndCUDASampleOnScopeExit() { _rmt_EndCUDASample(stream); } + void *stream; }; #endif #if RMT_USE_D3D11 extern "C" RMT_API void _rmt_EndD3D11Sample(void); -struct rmt_EndD3D11SampleOnScopeExit -{ - ~rmt_EndD3D11SampleOnScopeExit() - { - _rmt_EndD3D11Sample(); - } +struct rmt_EndD3D11SampleOnScopeExit { + ~rmt_EndD3D11SampleOnScopeExit() { _rmt_EndD3D11Sample(); } }; #endif #if RMT_USE_OPENGL extern "C" RMT_API void _rmt_EndOpenGLSample(void); -struct rmt_EndOpenGLSampleOnScopeExit -{ - ~rmt_EndOpenGLSampleOnScopeExit() - { - _rmt_EndOpenGLSample(); - } +struct rmt_EndOpenGLSampleOnScopeExit { + ~rmt_EndOpenGLSampleOnScopeExit() { _rmt_EndOpenGLSample(); } }; #endif #if RMT_USE_METAL extern "C" RMT_API void _rmt_EndMetalSample(void); -struct rmt_EndMetalSampleOnScopeExit -{ - ~rmt_EndMetalSampleOnScopeExit() - { - _rmt_EndMetalSample(); - } +struct rmt_EndMetalSampleOnScopeExit { + ~rmt_EndMetalSampleOnScopeExit() { _rmt_EndMetalSample(); } }; #endif #endif - - -// Pairs a call to rmt_BeginSample with its call to rmt_EndSample when leaving scope -#define rmt_ScopedCPUSample(name, flags) \ - RMT_OPTIONAL(RMT_ENABLED, rmt_BeginCPUSample(name, flags)); \ - RMT_OPTIONAL(RMT_ENABLED, rmt_EndCPUSampleOnScopeExit rmt_ScopedCPUSample##name); -#define rmt_ScopedCUDASample(name, stream) \ - RMT_OPTIONAL(RMT_USE_CUDA, rmt_BeginCUDASample(name, stream)); \ - RMT_OPTIONAL(RMT_USE_CUDA, rmt_EndCUDASampleOnScopeExit rmt_ScopedCUDASample##name(stream)); -#define rmt_ScopedD3D11Sample(name) \ - RMT_OPTIONAL(RMT_USE_D3D11, rmt_BeginD3D11Sample(name)); \ - RMT_OPTIONAL(RMT_USE_D3D11, rmt_EndD3D11SampleOnScopeExit rmt_ScopedD3D11Sample##name); -#define rmt_ScopedOpenGLSample(name) \ - RMT_OPTIONAL(RMT_USE_OPENGL, rmt_BeginOpenGLSample(name)); \ - RMT_OPTIONAL(RMT_USE_OPENGL, rmt_EndOpenGLSampleOnScopeExit rmt_ScopedOpenGLSample##name); -#define rmt_ScopedMetalSample(name) \ - RMT_OPTIONAL(RMT_USE_METAL, rmt_BeginMetalSample(name)); \ - RMT_OPTIONAL(RMT_USE_METAL, rmt_EndMetalSampleOnScopeExit rmt_ScopedMetalSample##name); +// Pairs a call to rmt_BeginSample with its call to rmt_EndSample +// when leaving scope +#define rmt_ScopedCPUSample(name, flags) \ + RMT_OPTIONAL(RMT_ENABLED, rmt_BeginCPUSample(name, flags)); \ + RMT_OPTIONAL(RMT_ENABLED, \ + rmt_EndCPUSampleOnScopeExit rmt_ScopedCPUSample##name); +#define rmt_ScopedCUDASample(name, stream) \ + RMT_OPTIONAL(RMT_USE_CUDA, rmt_BeginCUDASample(name, stream)); \ + RMT_OPTIONAL( \ + RMT_USE_CUDA, \ + rmt_EndCUDASampleOnScopeExit rmt_ScopedCUDASample##name(stream)); +#define rmt_ScopedD3D11Sample(name) \ + RMT_OPTIONAL(RMT_USE_D3D11, rmt_BeginD3D11Sample(name)); \ + RMT_OPTIONAL(RMT_USE_D3D11, \ + rmt_EndD3D11SampleOnScopeExit rmt_ScopedD3D11Sample##name); +#define rmt_ScopedOpenGLSample(name) \ + RMT_OPTIONAL(RMT_USE_OPENGL, rmt_BeginOpenGLSample(name)); \ + RMT_OPTIONAL(RMT_USE_OPENGL, \ + rmt_EndOpenGLSampleOnScopeExit rmt_ScopedOpenGLSample##name); +#define rmt_ScopedMetalSample(name) \ + RMT_OPTIONAL(RMT_USE_METAL, rmt_BeginMetalSample(name)); \ + RMT_OPTIONAL(RMT_USE_METAL, \ + rmt_EndMetalSampleOnScopeExit rmt_ScopedMetalSample##name); #endif - - /* ------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------ @@ -597,8 +587,6 @@ struct rmt_EndMetalSampleOnScopeExit ------------------------------------------------------------------------------------------------------------------------ */ - - #if RMT_ENABLED #ifdef __cplusplus @@ -612,36 +600,37 @@ RMT_API void _rmt_SetGlobalInstance(Remotery *remotery); RMT_API Remotery *_rmt_GetGlobalInstance(void); RMT_API void _rmt_SetCurrentThreadName(rmtPStr thread_name); RMT_API void _rmt_LogText(rmtPStr text); -RMT_API void _rmt_BeginCPUSample(rmtPStr name, rmtU32 flags, rmtU32 *hash_cache); +RMT_API void _rmt_BeginCPUSample(rmtPStr name, rmtU32 flags, + rmtU32 *hash_cache); RMT_API void _rmt_EndCPUSample(void); #if RMT_USE_CUDA -RMT_API void _rmt_BindCUDA(const rmtCUDABind* bind); -RMT_API void _rmt_BeginCUDASample(rmtPStr name, rmtU32* hash_cache, void* stream); -RMT_API void _rmt_EndCUDASample(void* stream); +RMT_API void _rmt_BindCUDA(const rmtCUDABind *bind); +RMT_API void _rmt_BeginCUDASample(rmtPStr name, rmtU32 *hash_cache, + void *stream); +RMT_API void _rmt_EndCUDASample(void *stream); #endif #if RMT_USE_D3D11 -RMT_API void _rmt_BindD3D11(void* device, void* context); +RMT_API void _rmt_BindD3D11(void *device, void *context); RMT_API void _rmt_UnbindD3D11(void); -RMT_API void _rmt_BeginD3D11Sample(rmtPStr name, rmtU32* hash_cache); +RMT_API void _rmt_BeginD3D11Sample(rmtPStr name, rmtU32 *hash_cache); RMT_API void _rmt_EndD3D11Sample(void); #endif #if RMT_USE_OPENGL RMT_API void _rmt_BindOpenGL(); RMT_API void _rmt_UnbindOpenGL(void); -RMT_API void _rmt_BeginOpenGLSample(rmtPStr name, rmtU32* hash_cache); +RMT_API void _rmt_BeginOpenGLSample(rmtPStr name, rmtU32 *hash_cache); RMT_API void _rmt_EndOpenGLSample(void); #endif #if RMT_USE_METAL -RMT_API void _rmt_BeginMetalSample(rmtPStr name, rmtU32* hash_cache); +RMT_API void _rmt_BeginMetalSample(rmtPStr name, rmtU32 *hash_cache); RMT_API void _rmt_EndMetalSample(void); #endif #ifdef __cplusplus - } #endif @@ -654,5 +643,4 @@ RMT_API void _rmt_UnbindMetal(); #endif // RMT_ENABLED - #endif diff --git a/api/tools/DirtyLogger.cpp b/api/tools/DirtyLogger.cpp index 10af867..772dffb 100644 --- a/api/tools/DirtyLogger.cpp +++ b/api/tools/DirtyLogger.cpp @@ -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"); } //向日志里面打印信息 diff --git a/mod/config/ConfigManager.cpp b/mod/config/ConfigManager.cpp index 1d62149..e221b82 100644 --- a/mod/config/ConfigManager.cpp +++ b/mod/config/ConfigManager.cpp @@ -7,7 +7,6 @@ #include #include "commands/CommandManager.h" -#include "graphics/Graphics.h" #include "graphics/Particle.h" #include "tools/DirtyLogger.h" diff --git a/mod/dllmain.cpp b/mod/dllmain.cpp index f5fc129..31de580 100644 --- a/mod/dllmain.cpp +++ b/mod/dllmain.cpp @@ -27,7 +27,6 @@ Remotery *rmt = nullptr; // dll注入初始化 void mod_init() { rmt_CreateGlobalInstance(&rmt); - // displayDisclaimerMessageBox(); //免责声明窗口 initConsole(); trapdoor::initLogger("plugins/trapdoor/trapdoor.log"); //初始化日志 #ifdef BETA diff --git a/mod/function/HopperCounter.cpp b/mod/function/HopperCounter.cpp index 0b0703d..100d12c 100644 --- a/mod/function/HopperCounter.cpp +++ b/mod/function/HopperCounter.cpp @@ -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 @@ -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 *slots) - -// { -// SYM_CALL(void (*)(void *, std::vector *), -// 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 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; -// } +} \ No newline at end of file diff --git a/mod/player/PlayerFunction.cpp b/mod/player/PlayerFunction.cpp index 21a9da7..d154bd0 100644 --- a/mod/player/PlayerFunction.cpp +++ b/mod/player/PlayerFunction.cpp @@ -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" diff --git a/mod/spawn/SpawnHelper.cpp b/mod/spawn/SpawnHelper.cpp index b396e78..6692ac9 100644 --- a/mod/spawn/SpawnHelper.cpp +++ b/mod/spawn/SpawnHelper.cpp @@ -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" diff --git a/mod/village/Village.cpp b/mod/village/Village.cpp index 53bf5e7..fb959dc 100644 --- a/mod/village/Village.cpp +++ b/mod/village/Village.cpp @@ -7,7 +7,6 @@ #include "BDSMod.h" #include "TrapdoorMod.h" -#include "graphics/Graphics.h" #include "graphics/Particle.h" #include "tools/Message.h" #include "tools/MsgBuilder.h" @@ -32,6 +31,8 @@ using namespace SymHook; namespace mod { namespace { + + //下面是所有需要的偏移量 const size_t BOUND_OFFSET = 104; // from Village::_trySpawnDefenderDwellers const size_t POPULATION_OFFSET = 22; @@ -40,31 +41,38 @@ namespace mod { // from Village::_trySpawnDefenderDwellers const size_t DWELLER_POI_MAP_OFFSET = 96; // Village::_getDwellerMap - const size_t DWELLER_TICK_MAP_OFFSET = 152; + const size_t DWELLER_TICK_MAP_OFFSET = 160; + //居民数据 struct DwellerData { uint64_t tick; trapdoor::BlockPos pos; }; + enum DwellerType { Villager = 0, IronGolem = 1, Cat = 2, XXX = 3 }; // typedef std::vector> DwellerData; + + //村庄的居民(dweller)表,是一个哈希表 typedef std::array< std::unordered_map, 4> DwellerTickMapType; + //村庄的POI分配表 typedef std::unordered_map, 3>, std::hash> DwellerPOIMapType; + //从固定偏移量获取居民表 DwellerPOIMapType *getDwellerPOIMap(Village *v) { return reinterpret_cast( (char *)v + DWELLER_POI_MAP_OFFSET); } - DwellerTickMapType *getDwellerTicklMap(Village *v) { + //从固定偏移量获取POI分配表 + DwellerTickMapType *getDwellerTickMap(Village *v) { return reinterpret_cast( (char *)v + DWELLER_TICK_MAP_OFFSET); } @@ -106,7 +114,8 @@ namespace mod { auto workedNum = getWorkedVillagerNum(); auto golemNum = getIronGolemNum(); auto bedNum = getBedPOICount(); - int maxValue = 20 > population ? 20 : population; + int maxValue = population > 20 ? 20 : population; + //刷铁傀儡的三个条件 return (float)workedNum > population * 0.75 && golemNum < population / 10 && bedNum > maxValue; } @@ -260,7 +269,7 @@ namespace mod { //这个96是一个POI分配表 void Village::removeAllTags() { - auto *tickMap = getDwellerTicklMap(this); + auto *tickMap = getDwellerTickMap(this); for (auto i : *tickMap) { for (auto &v : i) { auto actor = trapdoor::bdsMod->fetchEntity(v.first.uid, false); @@ -272,13 +281,13 @@ namespace mod { } void Village::showTimeStamp() { - auto *tickMap = getDwellerTicklMap(this); + auto *tickMap = getDwellerTickMap(this); int index = 0; for (auto i : *tickMap) { for (auto &v : i) { auto actor = trapdoor::bdsMod->fetchEntity(v.first.uid, false); if (actor) { - if (index == 0) { + if (index == DwellerType::Villager) { actor->setNameTag(actor->getNameTag() + " " + std::to_string(v.second.tick)); } else { @@ -293,13 +302,10 @@ namespace mod { void VillageHelper::clear() { villageList.clear(); } - void VillageHelper::insert(const VillageWithColor &vw) { - villageList.insert(vw); - } + void VillageHelper::insert(mod::Village *vw) { villageList.insert(vw); } void VillageHelper::draw() { - for (auto vw : villageList) { - auto village = vw.village; + for (auto village : villageList) { if (village) { if (this->showBounds) trapdoor::spawnRectangleParticle( @@ -328,8 +334,7 @@ namespace mod { trapdoor::MessageBuilder builder; builder.text("village.info.allVillages"_i18); int i = 0; - for (auto vw : villageList) { - auto village = vw.village; + for (auto village : villageList) { if (village) { i++; auto aabb = village->getBounds(); @@ -357,7 +362,6 @@ namespace mod { } void VillageHelper::tick() { - // rmt_ScopedCPUSample(VILLAGE_TICK, 0) if (gameTick % 40 == 0) { // todo clear village and draw village; this->draw(); @@ -368,7 +372,46 @@ namespace mod { void VillageHelper::test() { for (auto &v : this->villageList) { - v.village->test(); + //*DwellerTickMapTest + //*PASS + // auto map = + // getDwellerTickMap(v)->operator[](DwellerType::Villager); for + // (auto &kv : map) { + // trapdoor::broadcastMsg("pos=[%d %d %d],timestamp=[%llu]\n", + // kv.second.pos.x, kv.second.pos.y, + // kv.second.pos.z, kv.second.tick); + // } + + //* getDwellerPOIMapTest + //* PASS + // auto map = getDwellerPOIMap(v); + + // for (auto &villager : *map) { + // for (auto &p : villager.second) { + // auto p0 = p.lock(); + // if (p0) { + // auto p0_pos = p0->poiPos; + // trapdoor::broadcastMsg("POI pos =[%d %d %d]\n", + // p0_pos.x, p0_pos.y, p0_pos.z); + // } else { + // trapdoor::broadcastMsg("POI = nullptr\n"); + // } + // } + // } + + //*Villager traverse + auto map = getDwellerTickMap(v)->operator[](DwellerType::Villager); + for (auto &kv : map) { + auto actor = trapdoor::bdsMod->fetchEntity(kv.first.uid, false); + if (actor) { + static int idx = 0; + actor->setNameTag("idx = " + std::to_string(idx)); + ++idx; + } else { + trapdoor::broadcastMsg("find a nullptr[uid = %llu]", + kv.first.uid); + } + } } } @@ -377,9 +420,9 @@ namespace mod { for (auto village : this->villageList) { idx++; __try { - village.village->showVillagerStatus(idx); + village->showVillagerStatus(idx); } __except (EXCEPTION_EXECUTE_HANDLER) { - // nothing + // nothing } } } @@ -389,9 +432,9 @@ namespace mod { mod::Village *target = nullptr; float maxDistance = 1024; for (auto village : this->villageList) { - auto dis = village.village->getCenter().distanceTo(pos); + auto dis = village->getCenter().distanceTo(pos); if (dis < maxDistance) { - target = village.village; + target = village; maxDistance = dis; } } @@ -404,7 +447,7 @@ namespace mod { void Village::test() { // finish - // auto *tickMap = getDwellerTicklMap(this); + // auto *tickMap = getDwellerTickMap(this); // for (auto i : *tickMap) { // for (auto &v : i) { // auto actor = trapdoor::bdsMod->fetchEntity(v.first.uid, @@ -440,13 +483,17 @@ namespace mod { } void VillageHelper::removeAllNameTag() { - __try { - for (auto vill : this->villageList) { - vill.village->removeAllTags(); - } - } __except (EXCEPTION_EXECUTE_HANDLER) { - // nothing + for (auto village : this->villageList) { + village->removeAllTags(); } + + // __try { + // for (auto vill : this->villageList) { + // vill.village->removeAllTags(); + // } + // } __except (EXCEPTION_EXECUTE_HANDLER) { + // // nothing + // } } void VillageHelper::registerCommand(CommandManager &commandManager) { @@ -494,17 +541,13 @@ namespace mod { })); } - bool VillageWithColor::operator<(const VillageWithColor &rhs) const { - return this->village < rhs.village; - } - } // namespace mod +// hook村庄更新 THook(void, Village_tick_2a1ecbf8, mod::Village *vill, void *tick, void *blockSource) { // village tick original(vill, tick, blockSource); - mod::VillageWithColor vw{vill, trapdoor::GRAPHIC_COLOR::GREEN}; trapdoor::bdsMod->asInstance()->getVillageHelper().insert( - vw); + vill); } diff --git a/mod/village/Village.h b/mod/village/Village.h index 98a7a1b..8844937 100644 --- a/mod/village/Village.h +++ b/mod/village/Village.h @@ -6,8 +6,9 @@ #include "entity/Actor.h" #include "graphics/AABB.h" #include "graphics/BlockPos.h" -#include "graphics/Graphics.h" +#include "graphics/Particle.h" #include "graphics/Vec3.h" +#include "lib/Remotery.h" #include "lib/SymHook.h" #include "lib/mod.h" #include "tools/noncopyable .h" @@ -17,50 +18,57 @@ namespace mod { class Village { public: + //获取当前村庄人口数 int getPopulation(); - + //获取当前村庄铁傀儡数 int getIronGolemNum(); + //获取当前村庄的POI数量 int getBedPOICount(); + //获取当天工作过的村民数量 + //! 不可用 int getWorkedVillagerNum(); + //当前是否能生成铁傀儡 bool canSpawnIronGolem(); + //获取村庄中心 trapdoor::Vec3 getCenter(); + //获取村庄半径 float getRadius(); + //获取POI查询范围 trapdoor::AABB getPOIRange(); + //获取铁傀儡刷新区域 trapdoor::AABB getGolemSpawnArea(); + //获取村庄边框 trapdoor::AABB getBounds(); + //打印所有的POI void printAllPOIs(); void showVillagerStatus(int vIdx); + //显示TS值 void showTimeStamp(); + //获取调试新型 std::string getDebugInfo(); + //打印村庄详细新型 bool printVillagerInfo(trapdoor::Actor *player, trapdoor::Actor *actor); + //移除村民头顶标签 void removeAllTags(); + //测试用函数 void test(); }; - //这个其实蛮冗余的,懒得删了 - class VillageWithColor { - public: - Village *village; - trapdoor::GRAPHIC_COLOR color; - - bool operator<(const VillageWithColor &rhs) const; - }; - struct VillageHelperConfig { trapdoor::GRAPHIC_COLOR boundColor = GRAPH_COLOR::BLUE; trapdoor::GRAPHIC_COLOR spawnColor = GRAPH_COLOR::GREEN; @@ -77,6 +85,8 @@ namespace mod { bool showDwellerStatus = false; size_t gameTick = 0; + std::set villageList; + public: inline void setShowBound(bool able) { showBounds = able; } @@ -93,16 +103,16 @@ namespace mod { inline void setShowDwellerStatus(bool able) { showDwellerStatus = able; //关闭头顶显示后移除所有的命名 - if (!able) this->removeAllNameTag(); + if (!able) { + this->removeAllNameTag(); + } } inline bool getShowDwellerStatus() const { return showDwellerStatus; } VillageHelper() = default; - std::set villageList; - - void insert(const VillageWithColor &vw); + void insert(Village *v); void clear(); @@ -114,19 +124,25 @@ namespace mod { void test(); + //打印最近的村民信息 void printNearestVillageInfo(trapdoor::Actor *player, const trapdoor::Vec3 &pos); + //初始化配置信息 inline void setConfig(const VillageHelperConfig &config) { this->villageHelperConfig = config; } + //更新 void tick(); + //打印居民信息 void printDwellerInfo(trapdoor::Actor *player, trapdoor::Actor *actor); + //移除所有头顶标签 void removeAllNameTag(); + //注册village命令 void registerCommand(trapdoor::CommandManager &commandManager); };