From 5f4e2749c01a83cd34496321f346226d865185c7 Mon Sep 17 00:00:00 2001 From: Warren Ulrich Date: Wed, 5 Jul 2023 02:36:41 -0700 Subject: [PATCH] initial commit --- .gitignore | 3 ++ CMakeLists.txt | 48 +++++++++++++++++++ src/main.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1de8a47 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ + +.vscode/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f49e35d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,48 @@ + +cmake_minimum_required(VERSION 3.26) + +project(object_debugger) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_SHARED_LINKER_FLAGS "-Os -s -m32 -static-libgcc -static-libstdc++ -static") +set(CMAKE_SHARED_LIBRARY_PREFIX "") + +if (NOT DEFINED ALPACABOT_DIR) + set(ALPACABOT_DIR $ENV{USERPROFILE}\\AlpacaBot) +endif() + +if (NOT DEFINED ALPACABOT_INCLUDE_DIR) + set(ALPACABOT_INCLUDE_DIR ${ALPACABOT_DIR}\\Include) +endif() + +if (NOT DEFINED ALPACABOT_LIB_DIR) + set(ALPACABOT_LIB_DIR ${ALPACABOT_DIR}\\Library) +endif() + +if (NOT DEFINED ALPACABOT_SCRIPT_DIR) + set(ALPACABOT_SCRIPT_DIR ${ALPACABOT_DIR}\\Scripts\\Local) +endif() + +set(SOURCE_FILES + src/main.cpp +) + +add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${ALPACABOT_SCRIPT_DIR}/${PROJECT_NAME} +) + +target_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${ALPACABOT_INCLUDE_DIR} +) + +target_link_directories(${PROJECT_NAME} PRIVATE + ${ALPACABOT_LIB_DIR} +) + +target_link_libraries(${PROJECT_NAME} PRIVATE + AlpacaLibrary +) diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..f516155 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,125 @@ +#include +#include +#include +#include + +#include + +#include + +void Setup() { + ScriptInfo Info; + Info.Name = "Object Debugger"; + Info.Description = "Debug objects"; + Info.Version = "1.00"; + Info.Category = "Magic"; + Info.Author = "Warren"; + Info.UID = "UID"; + Info.ForumPage = "forum.alpacabot.org"; + SetScriptInfo(Info); +} + +bool OnStart() { + SetLoopDelay(5); + return true; +} + +std::vector get_game_objects() { + return GameObjects::GetAllWithin(10); +} + +std::vector get_wall_objects() { + return WallObjects::GetAllWithin(10); +} + +std::vector get_ground_objects() { + return GroundObjects::GetAllWithin(10); +} + +std::vector get_decorative_objects() { + return DecorativeObjects::GetAllWithin(10); +} + +std::vector get_npcs() { return NPCs::GetAllWithin(10); } + +std::vector get_players() { + return Players::GetAllWithin(10); +} + +enum class paint_mode { + game_objects, + wall_objects, + ground_objects, + decorative_objects, + npcs, + players +}; + +void paint_object(const auto &obj, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + const auto model = obj.GetModel(); + Paint::DrawModel(model, r, g, b, a); +} + +paint_mode pmode = paint_mode::players; + +bool Loop() { + Paint::Clear(); + + if (GetAsyncKeyState(VK_MENU)) { + pmode = static_cast((static_cast(pmode) + 1) % 6); + Wait(200); + } + + auto paint_objects = [&](const auto &objects, uint8_t r, uint8_t g, + uint8_t b) { + for (const auto &obj : objects) { + const auto name = obj.GetName(); + if (name == "") + continue; + + const auto tile = obj.GetTile(); + if (!tile) + continue; + + const auto w2s = Internal::TileToMainscreen(tile, 0, 0, 0); + if (!w2s) + continue; + + paint_object(obj, r, g, b, 255); + + std::stringstream ss; + ss << name; + ss << ": (" << tile.X << ", " << tile.Y << ", " << tile.Plane << ")"; + + Paint::DrawString(ss.str(), w2s, 255, 255, 255, 255); + } + }; + + switch (pmode) { + case paint_mode::game_objects: + paint_objects(get_game_objects(), 255, 0, 0); + break; + case paint_mode::wall_objects: + paint_objects(get_wall_objects(), 0, 255, 0); + break; + case paint_mode::ground_objects: + paint_objects(get_ground_objects(), 0, 0, 255); + break; + case paint_mode::decorative_objects: + paint_objects(get_decorative_objects(), 255, 255, 0); + break; + case paint_mode::npcs: + paint_objects(get_npcs(), 128, 0, 128); + break; + case paint_mode::players: + paint_objects(get_players(), 0, 255, 255); + break; + } + + Paint::SwapBuffer(); + return true; +} + +bool OnBreak() { return true; } + +void OnEnd() {} \ No newline at end of file