Skip to content

Commit

Permalink
Add info to unit:GetCommandQueue() (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
RutreD committed Jul 22, 2023
1 parent 71f3206 commit 74dc0f5
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ This are just the patch files for this game. I decided to separate them from pat
- hooks/LuaMessages.cpp

## Additions
- Adds the commandType, position, targetId and blueprintId to sim unit:GetCommandQueue
- hooks/SimGetCommandQueue.cpp
- section/SimGetCommandQueue.cpp
- Adds new category 'OBSTRUCTSBUILDING' for props to block buildings from being build on top of those
- hooks/Reclaimable.cpp
- section/Reclaimable.cpp
Expand Down
5 changes: 5 additions & 0 deletions hooks/SimGetCommandQueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "../define.h"
asm(
".section h0; .set h0,0x6CE3BA;"
"CALL "QU(SimGetCommandQueueInsert)";"
);
70 changes: 70 additions & 0 deletions section/SimGetCommandQueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "include/moho.h"
#include "include/LuaAPI.h"

void __thiscall SimGetCommandQueueInsert(LuaObject *this_, LuaObject *obj)
{
auto unit = reinterpret_cast<uintptr_t>(obj) - 0x20;
CLuaObject::SetInteger(obj, "commandType", *reinterpret_cast<int*>(unit + 0x98));
CLuaObject::SetNumber(obj, "x", *reinterpret_cast<float*>(unit + 0xA4));
CLuaObject::SetNumber(obj, "y", *reinterpret_cast<float*>(unit + 0xA8));
CLuaObject::SetNumber(obj, "z", *reinterpret_cast<float*>(unit + 0xAC));
auto targetId = *reinterpret_cast<unsigned long*>(unit + 0xA0);
if (targetId != 0xF0000000) {
char buf[16];
sprintf_s(buf, sizeof(buf), "%d", targetId); //like game doing entityId with std::string
CLuaObject::SetString(obj, "targetId", buf);
}
auto v3 = *reinterpret_cast<uintptr_t*>(unit + 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);
CLuaObject::SetString(obj, "blueprintId", bpId);
}
CLuaObject::Insert(this_, obj);
}

/* Commands
1 = Stop
2 = Move
3 = Dive
4 = FormMove
5 = BuildSiloTactical
6 = BuildSiloNuke
7 = BuildFactory
8 = BuildMobile
9 = BuildAssist
10 = Attack
11 = FormAttack
12 = Nuke
13 = Tactical
14 = Teleport
15 = Guard
16 = Patrol
17 = Ferry
18 = FormPatrol
19 = Reclaim
20 = Repair
21 = Capture
22 = TransportLoadUnits
23 = TransportReverseLoadUnits
24 = TransportUnloadUnits
25 = TransportUnloadSpecificUnits
26 = DetachFromTransport
27 = Upgrade
28 = Script
29 = AssistCommander
30 = KillSelf
31 = DestroySelf
32 = Sacrifice
33 = Pause
34 = OverCharge
35 = AggressiveMove
36 = FormAggressiveMove
37 = AssistMove
38 = SpecialAction
39 = Dock
*/
4 changes: 2 additions & 2 deletions section/include/LuaAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ VALIDATE_SIZE(TObject, 8)
FDecl(0x909750, AssignString, __thiscall void (*)(LuaObject* this_, LuaState*, const char*))
FDecl(0x9099b0, AssignTObject, __thiscall void (*)(LuaObject* this_, LuaState*, const TObject*))
FDecl(0x9096f0, AssignThread, __thiscall void (*)(LuaObject* this_, LuaState*))
FDecl(0x909af0, Insert, __thiscall void (*)(LuaObject* this_, const LuaObject&))
FDecl(0x909ce0, Insert2, __thiscall void (*)(LuaObject* this_, int, const LuaObject&))
FDecl(0x909af0, Insert, __thiscall void (*)(LuaObject* this_, LuaObject*))
FDecl(0x909ce0, Insert2, __thiscall void (*)(LuaObject* this_, int, LuaObject*))
FDecl(0x907630, Register, __thiscall void (*)(LuaObject* this_, const char*, int (__cdecl*)(lua_State*), int))
FDecl(0x9075f0, Reset, __thiscall void (*)(LuaObject* this_))
FDecl(0x9080c0, SetBoolean, __thiscall void (*)(LuaObject* this_, const char*, bool))
Expand Down
3 changes: 3 additions & 0 deletions section/include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Get debugging info about a Lua call:
#define g_ExeVersion2 GDecl(0x87612d, const int)
#define g_ExeVersion3 GDecl(0x4d3d40, const int)

FDecl(0x9C4940, AbortF, void (*)(wchar_t* format, ...))
FDecl(0x937CB0, LogF, int (*)(const char *fmt, ...))
FDecl(0x937D30, WarningF, int (*)(const char *fmt, ...))
FDecl(0x937C30, SpewF, int (*)(const char *fmt, ...))
Expand All @@ -79,6 +80,8 @@ FDecl(0xA89110, memset, void* (*)(void *dest, int ch, size_t count))
FDecl(0xA89190, memcpy, void* (*)(void *dest, const void *src, size_t count))
FDecl(0x452FC0, sqrtf, float (*)(float arg))
FDecl(0xA94450, strlen, size_t (*)(const char *str))
FDecl(0xAA549E, strcmp, int (*)(const char *str1, const char *str2))
FDecl(0xA82F32, sprintf_s, int (*)(char *const Buffer, const size_t BufferCount, const char *const Format, ...))

FDecl(0x405550, InitString, __thiscall void (*)(void *this_, const char *str))
FDecl(0x4059E0, AssignString, __thiscall void (*)(void *this_, const char *str, size_t size))
Expand Down

0 comments on commit 74dc0f5

Please sign in to comment.