Skip to content

Commit 339812d

Browse files
committed
Add functions to script debugger
1 parent 9c57b41 commit 339812d

6 files changed

Lines changed: 78 additions & 14 deletions

File tree

src/cdc/script/DataType.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace cdc
77
class ScriptType;
88
class EnumDecl;
99
class StructDecl;
10-
class StartFunctionInfo;
11-
class Prototype;
1210

1311
class DataType
1412
{

src/cdc/script/ScriptManager.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,9 @@ namespace cdc
2020
int field_28;
2121
int field_2C;
2222
int field_30;
23-
int field_34;
24-
int field_38;
25-
int field_3C;
26-
int field_40;
23+
HashSet<ScriptObject*> m_threads;
2724
int field_44;
2825
HashSet<ScriptObject*> m_objects;
29-
int field_4C;
30-
int field_50;
31-
int field_54;
32-
int field_58;
3326
int field_5C;
3427

3528
static ScriptManager* GetInstance();

src/cdc/script/ScriptObject.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "ScriptObject.h"
2+
3+
#include "util/Hooking.h"
4+
5+
void cdc::ScriptObject::CallFunction(Function* function, int numArgs, void* args, void* retVal)
6+
{
7+
return Hooking::ThisCall(0x57B380, this, function, numArgs, args, retVal);
8+
}

src/cdc/script/ScriptObject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ namespace cdc
1616
char m_updatingSequences;
1717
char field_19;
1818
__int16 field_1A;
19+
20+
void CallFunction(Function* function, int numArgs, void* args, void* retVal);
1921
};
2022
}

src/cdc/script/ScriptType.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace cdc
1010
{
11+
class StartFunctionInfo;
12+
1113
class DataMember
1214
{
1315
public:
@@ -17,6 +19,37 @@ namespace cdc
1719
int m_init;
1820
};
1921

22+
class Prototype
23+
{
24+
public:
25+
ScriptType* m_script;
26+
27+
unsigned __int8 m_flags;
28+
unsigned __int8 m_callType;
29+
unsigned __int16 m_vtIndex;
30+
31+
ScriptName m_name;
32+
SArray<cdc::DataMember> m_args;
33+
DataType m_retType;
34+
};
35+
36+
class Function
37+
{
38+
public:
39+
Prototype* m_prototype;
40+
41+
unsigned __int8 m_flags;
42+
unsigned __int8 m_state;
43+
unsigned __int16 m_size;
44+
unsigned __int16 m_align;
45+
unsigned __int16 m_stackSize;
46+
47+
SArray<DataMember> m_locals;
48+
SArray<StartFunctionInfo> m_startFunctionList;
49+
int field_14;
50+
int field_18;
51+
};
52+
2053
class ScriptTypeStreamData
2154
{
2255
public:
@@ -36,7 +69,7 @@ namespace cdc
3669
SArray<DataMember> m_members; // 2C
3770
SArray<StartFunctionInfo> m_startFunctionList; // 30
3871
SArray<Prototype> m_prototypes; // 34
39-
int field_38; // 38
72+
SArray<Function> m_functions; // 38
4073
int field_3C; // 3C
4174
int field_40; // 40
4275
int field_44; // 44

src/modules/ScriptDebug.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Dummy
3636
virtual ~Dummy() = 0;
3737
};
3838

39-
// Gets the RTII type name from the passed pointer
39+
// Gets the RTTI type name from the passed pointer
4040
static std::string GetTypeName(uintptr_t* ptr)
4141
{
4242
if (ptr == nullptr)
@@ -146,13 +146,13 @@ void ScriptDebug::DrawScriptDebug(cdc::ScriptObject* object)
146146
auto data = script->m_streamData;
147147

148148
ImGui::Text("%p", object);
149-
ImGui::Text("%d states, %d enums, %d structs, %d members, %d start functions, %d prototypes, %d dependencies",
149+
ImGui::Text("%d states, %d enums, %d structs, %d members, %d prototypes, %d functions, %d dependencies",
150150
data->m_states.size(),
151151
data->m_enums.size(),
152152
data->m_structs.size(),
153153
data->m_members.size(),
154-
data->m_startFunctionList.size(),
155154
data->m_prototypes.size(),
155+
data->m_functions.size(),
156156
data->m_dependencies.size());
157157

158158
if (ImGui::CollapsingHeader("Members"))
@@ -169,6 +169,36 @@ void ScriptDebug::DrawScriptDebug(cdc::ScriptObject* object)
169169
DrawDataMember(object, member);
170170
}
171171
}
172+
173+
if (ImGui::CollapsingHeader("Functions"))
174+
{
175+
for (unsigned int i = 0; i < data->m_functions.size(); i++)
176+
{
177+
auto func = &data->m_functions.m_data[i];
178+
auto proto = func->m_prototype;
179+
180+
std::string args;
181+
for (unsigned int j = 0; j < proto->m_args.size(); j++)
182+
{
183+
auto arg = &proto->m_args.m_data[j];
184+
185+
if (j > 0) args += ", ";
186+
args += s_dataTypes[arg->m_type.m_type];
187+
}
188+
189+
ImGui::PushID(i);
190+
191+
// INT sub_12(INT, INT, STRING)
192+
ImGui::Text("%s sub_%02d(%s)", s_dataTypes[proto->m_retType.m_type], i, args.c_str());
193+
194+
if (ImGui::Button("Call"))
195+
{
196+
object->CallFunction(func, 0, nullptr, nullptr);
197+
}
198+
199+
ImGui::PopID();
200+
}
201+
}
172202
}
173203

174204
void ScriptDebug::DrawDataMember(cdc::ScriptObject* object, cdc::DataMember* member)

0 commit comments

Comments
 (0)