Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetHighlightCommand #65

Merged
merged 10 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down
42 changes: 42 additions & 0 deletions section/GetHighlightCommand.cpp
Original file line number Diff line number Diff line change
@@ -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};
25 changes: 9 additions & 16 deletions section/SimGetCommandQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@

void __thiscall SimGetCommandQueueInsert(LuaObject *this_, LuaObject *obj)
{
auto unitCmd = reinterpret_cast<uintptr_t>(obj) - 0x20;
obj->SetInteger("commandType", *reinterpret_cast<int*>(unitCmd + 0x98));
obj->SetNumber("x", *reinterpret_cast<float*>(unitCmd + 0xA4));
obj->SetNumber("y", *reinterpret_cast<float*>(unitCmd + 0xA8));
obj->SetNumber("z", *reinterpret_cast<float*>(unitCmd + 0xAC));
auto targetId = *reinterpret_cast<unsigned long*>(unitCmd + 0xA0);
auto command = reinterpret_cast<incomplete::Command*>(reinterpret_cast<uintptr_t>(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<uintptr_t*>(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);
}

Expand Down
18 changes: 16 additions & 2 deletions section/include/moho.h
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ struct CWldSession
float mouseWorldPosZ;
void *unk2;
void *unk3;
int IsDragger;
int highlightCommandId;
float mouseScreenPosX;
float mouseScreenPosY;
} mouse;
Expand Down Expand Up @@ -1455,4 +1455,18 @@ struct WRenViewport // : WD3DViewport
Clutter clutter;
// at 0x2134
Silhouette silhouette;
};
};

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
};
}