diff --git a/README.md b/README.md index c709b67..c515b22 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ To apply the patches you can use the upload action or do it local via the [patch - section/StopReclaimWhenPaused.cpp ## Additions +- Adds `GetHighlightCommand() - return table of command or nil` to UI (section/GetHighlightCommand.cpp) - Adds new methods to the the `Projectile` class (section/ProjectileNewMethods.cpp): - `Projectile:SetNewTargetGroundXYZ(x, y, z)` - `x, y, z = Projectile:GetCurrentTargetPositionXYZ()` diff --git a/section/GetHighlightCommand.cpp b/section/GetHighlightCommand.cpp new file mode 100644 index 0000000..439a09a --- /dev/null +++ b/section/GetHighlightCommand.cpp @@ -0,0 +1,42 @@ +#include "include/moho.h" +#include "include/magic_classes.h" + +#define lua_push(L, name, val) \ + lua_pushstring(L, name); \ + lua_pushnumber(L, val); \ + lua_rawset(L, -3); + +int UIGetHighlightCommand(lua_State *L) { + auto commandId = g_CWldSession->mouse.highlightCommandId; + if (commandId == -1) return 0; + volatile incomplete::Command* command; + asm("push %[commandId];" + "call 0x8B5BB0" + :"=a"(command) + :"S"(g_CWldSession->unk3), [commandId]"g"(commandId) + :); + if (!command) return 0; + lua_newtable(L); + lua_push(L, "commandType", command->commandType); + lua_push(L, "x", command->pos.x); + lua_push(L, "y", command->pos.y); + lua_push(L, "z", command->pos.z); + auto targetId = command->targetId; + if (targetId != 0xF0000000) { + char buf[16]; + sprintf_s(buf, sizeof(buf), "%d", targetId); + lua_pushstring(L, "targetId"); + lua_pushstring(L, buf); + lua_rawset(L, -3); + } + auto bp = command->bpBuild; + if (bp) { + lua_pushstring(L, "blueprintId"); + lua_pushstring(L, bp->name.data()); + lua_rawset(L, -3); + } + return 1; +}; + +UIRegFunc RegGetHighlightCommand{"GetHighlightCommand", + "GetHighlightCommand() - return table of command or nil", UIGetHighlightCommand}; \ No newline at end of file diff --git a/section/SimGetCommandQueue.cpp b/section/SimGetCommandQueue.cpp index ae797ab..11a8b89 100644 --- a/section/SimGetCommandQueue.cpp +++ b/section/SimGetCommandQueue.cpp @@ -2,27 +2,20 @@ void __thiscall SimGetCommandQueueInsert(LuaObject *this_, LuaObject *obj) { - auto unitCmd = reinterpret_cast(obj) - 0x20; - obj->SetInteger("commandType", *reinterpret_cast(unitCmd + 0x98)); - obj->SetNumber("x", *reinterpret_cast(unitCmd + 0xA4)); - obj->SetNumber("y", *reinterpret_cast(unitCmd + 0xA8)); - obj->SetNumber("z", *reinterpret_cast(unitCmd + 0xAC)); - auto targetId = *reinterpret_cast(unitCmd + 0xA0); + auto command = reinterpret_cast(reinterpret_cast(obj) + 0x20); + obj->SetInteger("commandType", command->commandType); + obj->SetNumber("x", command->pos.x); + obj->SetNumber("y", command->pos.y); + obj->SetNumber("z", command->pos.z); + auto targetId = command->targetId; if (targetId != 0xF0000000) { char buf[16]; sprintf_s(buf, sizeof(buf), "%d", targetId); //like game doing entityId with std::string obj->SetString("targetId", buf); } - auto v3 = *reinterpret_cast(unitCmd + 0x60); - if (v3) //like in sub_842770 - { - const char* bpId; - if ( *(int *)(v3 + 32) < 0x10u ) - bpId = (const char *)(v3 + 12); - else - bpId = *(const char **)(v3 + 12); - obj->SetString("blueprintId", bpId); - } + auto bp = command->bpBuild; + if (bp) + obj->SetString("blueprintId", bp->name.data()); this_->Insert(obj); } diff --git a/section/include/moho.h b/section/include/moho.h index eb9c78f..6764c10 100644 --- a/section/include/moho.h +++ b/section/include/moho.h @@ -1103,7 +1103,7 @@ struct CWldSession float mouseWorldPosZ; void *unk2; void *unk3; - int IsDragger; + int highlightCommandId; float mouseScreenPosX; float mouseScreenPosY; } mouse; @@ -1455,4 +1455,18 @@ struct WRenViewport // : WD3DViewport Clutter clutter; // at 0x2134 Silhouette silhouette; -}; \ No newline at end of file +}; + +namespace incomplete { + struct Command + { + Command *self; + uint8_t pad1[0x1C]; + RBlueprint *bpBuild; // at 0x20 + uint8_t pad2[0x34]; + int commandType; // at 0x58 // see EUnitCommandType; sub_552170 + uint8_t pad3[0x4]; + int targetId; // at 0x60 // valid if != 0xF0000000 + Vector3f pos; // at 0x64 + }; +}