Skip to content

Commit e8ad0c7

Browse files
committed
fix(memory): LoadFromSignatureName
1 parent bfd7959 commit e8ad0c7

File tree

2 files changed

+59
-51
lines changed

2 files changed

+59
-51
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Over here will be noted all the update change logs.
88

99
- Hook variable not existing
1010

11+
### Memory
12+
13+
- fix(memory): LoadFromSignatureName
14+
1115
## v1.6.12 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.12)
1216

1317
### Automation

src/scripting/memory/memory.cpp

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,35 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
1111

1212
ADD_CLASS_FUNCTION("Memory", "Memory", [](FunctionContext* context, ClassData* data) -> void {
1313
auto classData = context->GetArgumentOr<ClassData*>(0, nullptr);
14-
if(classData) {
15-
if(classData->HasData("ptr")) {
14+
if (classData) {
15+
if (classData->HasData("ptr")) {
1616
data->SetData("ptr", classData->GetData<void*>("ptr"));
1717
}
18-
} else {
18+
}
19+
else {
1920
auto strptr = context->GetArgumentOr<std::string>(0, "");
20-
if(starts_with(strptr, "0x")) {
21+
if (starts_with(strptr, "0x")) {
2122
data->SetData("ptr", (void*)StringToPtr(strptr));
22-
} else {
23+
}
24+
else {
2325
data->SetData("ptr", nullptr);
2426
}
2527
}
2628
});
27-
29+
2830
ADD_CLASS_FUNCTION("Memory", "~Memory", [](FunctionContext* context, ClassData* data) -> void {
29-
if(data->HasData("should_free")) {
30-
if(data->GetData<bool>("should_free")) {
31+
if (data->HasData("should_free")) {
32+
if (data->GetData<bool>("should_free")) {
3133
free(data->GetData<void*>("ptr"));
3234
}
33-
}
35+
}
3436
});
3537

3638
ADD_CLASS_FUNCTION("Memory", "Allocate", [](FunctionContext* context, ClassData* data) -> void {
3739
uint64_t size = context->GetArgumentOr<uint64_t>(0, 0);
38-
if(size == 0) return;
39-
40-
if(data->HasData("should_free") && data->GetData<bool>("should_free")) {
40+
if (size == 0) return;
41+
42+
if (data->HasData("should_free") && data->GetData<bool>("should_free")) {
4143
free(data->GetData<void*>("ptr"));
4244
}
4345

@@ -46,7 +48,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
4648
});
4749

4850
ADD_CLASS_FUNCTION("Memory", "Deallocate", [](FunctionContext* context, ClassData* data) -> void {
49-
if(data->HasData("should_free") && data->GetData<bool>("should_free")) {
51+
if (data->HasData("should_free") && data->GetData<bool>("should_free")) {
5052
free(data->GetData<void*>("ptr"));
5153
data->SetData("should_free", false);
5254
data->SetData("ptr", nullptr);
@@ -64,20 +66,21 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
6466
ADD_CLASS_FUNCTION("Memory", "LoadFromAddress", [](FunctionContext* context, ClassData* data) -> void {
6567

6668
auto classData = context->GetArgumentOr<ClassData*>(0, nullptr);
67-
if(classData) {
68-
if(classData->HasData("ptr")) {
69-
if(data->HasData("should_free") && data->GetData<bool>("should_free")) {
69+
if (classData) {
70+
if (classData->HasData("ptr")) {
71+
if (data->HasData("should_free") && data->GetData<bool>("should_free")) {
7072
free(data->GetData<void*>("ptr"));
7173
data->SetData("should_free", false);
7274
data->SetData("ptr", nullptr);
7375
}
7476

7577
data->SetData("ptr", classData->GetData<void*>("ptr"));
7678
}
77-
} else {
79+
}
80+
else {
7881
auto strptr = context->GetArgumentOr<std::string>(0, "");
79-
if(starts_with(strptr, "0x")) {
80-
if(data->HasData("should_free") && data->GetData<bool>("should_free")) {
82+
if (starts_with(strptr, "0x")) {
83+
if (data->HasData("should_free") && data->GetData<bool>("should_free")) {
8184
free(data->GetData<void*>("ptr"));
8285
data->SetData("should_free", false);
8386
data->SetData("ptr", nullptr);
@@ -90,31 +93,32 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
9093

9194
ADD_CLASS_FUNCTION("Memory", "LoadFromSignatureName", [](FunctionContext* context, ClassData* data) -> void {
9295
auto signame = context->GetArgumentOr<std::string>(0, "");
93-
if(signame == "") return;
96+
if (signame == "") return;
9497

95-
if(data->HasData("should_free") && data->GetData<bool>("should_free")) {
98+
if (data->HasData("should_free") && data->GetData<bool>("should_free")) {
9699
free(data->GetData<void*>("ptr"));
97100
data->SetData("should_free", false);
98101
data->SetData("ptr", nullptr);
99102
}
103+
100104
data->SetData("ptr", g_GameData.FetchRawSignature(signame));
101105
});
102106

103-
ADD_CLASS_FUNCTION("Memory", "LoadFromSignatureName", [](FunctionContext* context, ClassData* data) -> void {
107+
ADD_CLASS_FUNCTION("Memory", "LoadFromSignature", [](FunctionContext* context, ClassData* data) -> void {
104108
auto md = context->GetArgumentOr<std::string>(0, "");
105-
if(md == "") return;
109+
if (md == "") return;
106110
auto signature = context->GetArgumentOr<std::string>(1, "");
107-
if(signature == "") return;
111+
if (signature == "") return;
108112

109113
void* sig = nullptr;
110114
auto mod = DetermineModuleByLibrary(md);
111115

112116
if (signature.at(0) == '@') sig = mod.GetFunctionByName((signature.c_str() + 1)).RCast<void*>();
113117
else sig = mod.FindPattern(signature).RCast<void*>();
114118

115-
if(!sig) return;
119+
if (!sig) return;
116120

117-
if(data->HasData("should_free") && data->GetData<bool>("should_free")) {
121+
if (data->HasData("should_free") && data->GetData<bool>("should_free")) {
118122
free(data->GetData<void*>("ptr"));
119123
data->SetData("should_free", false);
120124
data->SetData("ptr", nullptr);
@@ -124,7 +128,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
124128

125129
ADD_CLASS_FUNCTION("Memory", "AddOffsetByName", [](FunctionContext* context, ClassData* data) -> void {
126130
std::string offsetName = context->GetArgumentOr<std::string>(0, "");
127-
if(offsetName == "") return;
131+
if (offsetName == "") return;
128132

129133
auto offset = g_GameData.GetOffset(offsetName);
130134
uintptr_t ptr = (uintptr_t)data->GetData<void*>("ptr");
@@ -134,7 +138,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
134138

135139
ADD_CLASS_FUNCTION("Memory", "RemoveOffsetByName", [](FunctionContext* context, ClassData* data) -> void {
136140
std::string offsetName = context->GetArgumentOr<std::string>(0, "");
137-
if(offsetName == "") return;
141+
if (offsetName == "") return;
138142

139143
auto offset = g_GameData.GetOffset(offsetName);
140144
uintptr_t ptr = (uintptr_t)data->GetData<void*>("ptr");
@@ -144,7 +148,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
144148

145149
ADD_CLASS_FUNCTION("Memory", "AddOffset", [](FunctionContext* context, ClassData* data) -> void {
146150
int64_t offset = context->GetArgumentOr<int64_t>(0, 0);
147-
if(offset == 0) return;
151+
if (offset == 0) return;
148152

149153
uintptr_t ptr = (uintptr_t)data->GetData<void*>("ptr");
150154
ptr += offset;
@@ -153,7 +157,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
153157

154158
ADD_CLASS_FUNCTION("Memory", "RemoveOffset", [](FunctionContext* context, ClassData* data) -> void {
155159
int64_t offset = context->GetArgumentOr<int64_t>(0, 0);
156-
if(offset == 0) return;
160+
if (offset == 0) return;
157161

158162
uintptr_t ptr = (uintptr_t)data->GetData<void*>("ptr");
159163
ptr -= offset;
@@ -162,7 +166,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
162166

163167
ADD_CLASS_FUNCTION("Memory", "AccessVTableFromOffset", [](FunctionContext* context, ClassData* data) -> void {
164168
std::string offsetName = context->GetArgumentOr<std::string>(0, "");
165-
if(offsetName == "") return;
169+
if (offsetName == "") return;
166170

167171
auto offset = g_GameData.GetOffset(offsetName);
168172
data->SetData("ptr", ((void***)data->GetData<void*>("ptr"))[0][offset]);
@@ -171,23 +175,23 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
171175

172176
ADD_CLASS_FUNCTION("Memory", "AccessIndexFromOffset", [](FunctionContext* context, ClassData* data) -> void {
173177
std::string offsetName = context->GetArgumentOr<std::string>(0, "");
174-
if(offsetName == "") return;
178+
if (offsetName == "") return;
175179

176180
auto offset = g_GameData.GetOffset(offsetName);
177181
data->SetData("ptr", ((void**)data->GetData<void*>("ptr"))[offset]);
178182
});
179183

180184
ADD_CLASS_FUNCTION("Memory", "AccessVTable", [](FunctionContext* context, ClassData* data) -> void {
181185
int64_t offset = context->GetArgumentOr<int64_t>(0, 0);
182-
if(offset == 0) return;
186+
if (offset == 0) return;
183187

184188
data->SetData("ptr", ((void***)data->GetData<void*>("ptr"))[0][offset]);
185189
data->SetData("accessed_vtable", true);
186190
});
187191

188192
ADD_CLASS_FUNCTION("Memory", "AccessIndex", [](FunctionContext* context, ClassData* data) -> void {
189193
int64_t offset = context->GetArgumentOr<int64_t>(0, 0);
190-
if(offset == 0) return;
194+
if (offset == 0) return;
191195

192196
data->SetData("ptr", ((void**)data->GetData<void*>("ptr"))[offset]);
193197
});
@@ -249,7 +253,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
249253
ADD_CLASS_FUNCTION("Memory", "SetVector", [](FunctionContext* context, ClassData* data) -> void {
250254
void* m_ptr = data->GetData<void*>("ptr");
251255
ClassData* cdata = context->GetArgumentOr<ClassData*>(0, nullptr);
252-
if(!cdata) return;
256+
if (!cdata) return;
253257
Vector value = cdata->GetData<Vector>("vector_ptr");
254258

255259
*((Vector*)(m_ptr)) = value;
@@ -258,7 +262,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
258262
ADD_CLASS_FUNCTION("Memory", "SetVector2D", [](FunctionContext* context, ClassData* data) -> void {
259263
void* m_ptr = data->GetData<void*>("ptr");
260264
ClassData* cdata = context->GetArgumentOr<ClassData*>(0, nullptr);
261-
if(!cdata) return;
265+
if (!cdata) return;
262266
Vector2D value = cdata->GetData<Vector2D>("Vector2D_ptr");
263267

264268
*((Vector2D*)(m_ptr)) = value;
@@ -267,7 +271,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
267271
ADD_CLASS_FUNCTION("Memory", "SetVector4D", [](FunctionContext* context, ClassData* data) -> void {
268272
void* m_ptr = data->GetData<void*>("ptr");
269273
ClassData* cdata = context->GetArgumentOr<ClassData*>(0, nullptr);
270-
if(!cdata) return;
274+
if (!cdata) return;
271275
Vector4D value = cdata->GetData<Vector4D>("Vector4D_ptr");
272276

273277
*((Vector4D*)(m_ptr)) = value;
@@ -276,7 +280,7 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
276280
ADD_CLASS_FUNCTION("Memory", "SetColor", [](FunctionContext* context, ClassData* data) -> void {
277281
void* m_ptr = data->GetData<void*>("ptr");
278282
ClassData* cdata = context->GetArgumentOr<ClassData*>(0, nullptr);
279-
if(!cdata) return;
283+
if (!cdata) return;
280284
Color value = cdata->GetData<Color>("Color_ptr");
281285

282286
*((Color*)(m_ptr)) = value;
@@ -285,92 +289,92 @@ LoadScriptingComponent(memory, [](PluginObject plugin, EContext* ctx) -> void {
285289
ADD_CLASS_FUNCTION("Memory", "SetQAngle", [](FunctionContext* context, ClassData* data) -> void {
286290
void* m_ptr = data->GetData<void*>("ptr");
287291
ClassData* cdata = context->GetArgumentOr<ClassData*>(0, nullptr);
288-
if(!cdata) return;
292+
if (!cdata) return;
289293
QAngle value = cdata->GetData<QAngle>("QAngle_ptr");
290294

291295
*((QAngle*)(m_ptr)) = value;
292296
});
293297

294298
ADD_CLASS_FUNCTION("Memory", "GetBool", [](FunctionContext* context, ClassData* data) -> void {
295299
void* m_ptr = data->GetData<void*>("ptr");
296-
if(!m_ptr) return context->SetReturn(false);
300+
if (!m_ptr) return context->SetReturn(false);
297301

298302
context->SetReturn(*((bool*)(m_ptr)));
299303
});
300304

301305
ADD_CLASS_FUNCTION("Memory", "GetInt", [](FunctionContext* context, ClassData* data) -> void {
302306
void* m_ptr = data->GetData<void*>("ptr");
303-
if(!m_ptr) return context->SetReturn(0);
307+
if (!m_ptr) return context->SetReturn(0);
304308

305309
context->SetReturn(*((int*)(m_ptr)));
306310
});
307311

308312
ADD_CLASS_FUNCTION("Memory", "GetInt64", [](FunctionContext* context, ClassData* data) -> void {
309313
void* m_ptr = data->GetData<void*>("ptr");
310-
if(!m_ptr) return context->SetReturn(0);
314+
if (!m_ptr) return context->SetReturn(0);
311315

312316
context->SetReturn(*((int64_t*)(m_ptr)));
313317
});
314318

315319
ADD_CLASS_FUNCTION("Memory", "GetUint", [](FunctionContext* context, ClassData* data) -> void {
316320
void* m_ptr = data->GetData<void*>("ptr");
317-
if(!m_ptr) return context->SetReturn(0);
321+
if (!m_ptr) return context->SetReturn(0);
318322

319323
context->SetReturn(*((uint32_t*)(m_ptr)));
320324
});
321325

322326
ADD_CLASS_FUNCTION("Memory", "GetUint64", [](FunctionContext* context, ClassData* data) -> void {
323327
void* m_ptr = data->GetData<void*>("ptr");
324-
if(!m_ptr) return context->SetReturn(0);
328+
if (!m_ptr) return context->SetReturn(0);
325329

326330
context->SetReturn(*((uint64_t*)(m_ptr)));
327331
});
328332

329333
ADD_CLASS_FUNCTION("Memory", "GetFloat", [](FunctionContext* context, ClassData* data) -> void {
330334
void* m_ptr = data->GetData<void*>("ptr");
331-
if(!m_ptr) return context->SetReturn(0.0);
335+
if (!m_ptr) return context->SetReturn(0.0);
332336

333337
context->SetReturn(*((float*)(m_ptr)));
334338
});
335339

336340
ADD_CLASS_FUNCTION("Memory", "GetDouble", [](FunctionContext* context, ClassData* data) -> void {
337341
void* m_ptr = data->GetData<void*>("ptr");
338-
if(!m_ptr) return context->SetReturn(0.0);
342+
if (!m_ptr) return context->SetReturn(0.0);
339343

340344
context->SetReturn(*((double*)(m_ptr)));
341345
});
342346

343347
ADD_CLASS_FUNCTION("Memory", "GetVector", [](FunctionContext* context, ClassData* data) -> void {
344348
void* m_ptr = data->GetData<void*>("ptr");
345-
if(!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("Vector", { { "vector_ptr", Vector(0.0,0.0,0.0) } }));
349+
if (!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("Vector", { { "vector_ptr", Vector(0.0,0.0,0.0) } }));
346350

347351
context->SetReturn(MAKE_CLASS_INSTANCE("Vector", { { "vector_ptr", *((Vector*)(m_ptr)) } }));
348352
});
349353

350354
ADD_CLASS_FUNCTION("Memory", "GetVector2D", [](FunctionContext* context, ClassData* data) -> void {
351355
void* m_ptr = data->GetData<void*>("ptr");
352-
if(!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("Vector2D", { { "Vector2D_ptr", Vector2D(0.0,0.0) } }));
356+
if (!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("Vector2D", { { "Vector2D_ptr", Vector2D(0.0,0.0) } }));
353357

354358
context->SetReturn(MAKE_CLASS_INSTANCE("Vector2D", { { "Vector2D_ptr", *((Vector2D*)(m_ptr)) } }));
355359
});
356360

357361
ADD_CLASS_FUNCTION("Memory", "GetVector4D", [](FunctionContext* context, ClassData* data) -> void {
358362
void* m_ptr = data->GetData<void*>("ptr");
359-
if(!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("Vector4D", { { "Vector4D_ptr", Vector4D(0.0,0.0,0.0,0.0) } }));
363+
if (!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("Vector4D", { { "Vector4D_ptr", Vector4D(0.0,0.0,0.0,0.0) } }));
360364

361365
context->SetReturn(MAKE_CLASS_INSTANCE("Vector4D", { { "Vector4D_ptr", *((Vector4D*)(m_ptr)) } }));
362366
});
363367

364368
ADD_CLASS_FUNCTION("Memory", "GetColor", [](FunctionContext* context, ClassData* data) -> void {
365369
void* m_ptr = data->GetData<void*>("ptr");
366-
if(!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("Color", { { "Color_ptr", Color(0,0,0,0) } }));
370+
if (!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("Color", { { "Color_ptr", Color(0,0,0,0) } }));
367371

368372
context->SetReturn(MAKE_CLASS_INSTANCE("Color", { { "Color_ptr", *((Color*)(m_ptr)) } }));
369373
});
370374

371375
ADD_CLASS_FUNCTION("Memory", "GetQAngle", [](FunctionContext* context, ClassData* data) -> void {
372376
void* m_ptr = data->GetData<void*>("ptr");
373-
if(!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("QAngle", { { "QAngle_ptr", QAngle(0.0,0.0,0.0) } }));
377+
if (!m_ptr) return context->SetReturn(MAKE_CLASS_INSTANCE("QAngle", { { "QAngle_ptr", QAngle(0.0,0.0,0.0) } }));
374378

375379
context->SetReturn(MAKE_CLASS_INSTANCE("QAngle", { { "QAngle_ptr", *((QAngle*)(m_ptr)) } }));
376380
});

0 commit comments

Comments
 (0)