Skip to content

Commit f9e577f

Browse files
authored
Merge pull request issuimo#29 from MY-Git-Li/main
修复 issuimo#28 问题
2 parents 9b7ae30 + 7c174be commit f9e577f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

UnityResolve.hpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,23 @@ class UnityResolve final {
188188
auto SetStaticValue(T* value) const -> void {
189189
if (!static_field) return;
190190
if (mode_ == Mode::Il2Cpp) return Invoke<void, void*, T*>("il2cpp_field_static_set_value", address, value);
191+
else
192+
{
193+
void* VTable = Invoke<void*>("mono_class_vtable", pDomain, klass->address);
194+
return Invoke<void, void*, void*, T*>("mono_field_static_set_value", VTable, address, value);
195+
196+
}
191197
}
192198

193199
template <typename T>
194200
auto GetStaticValue(T* value) const -> void {
195201
if (!static_field) return;
196202
if (mode_ == Mode::Il2Cpp) return Invoke<void, void*, T*>("il2cpp_field_static_get_value", address, value);
203+
else
204+
{
205+
void* VTable = Invoke<void*>("mono_class_vtable", pDomain, klass->address);
206+
return Invoke<void, void*, void*, T*>("mono_field_static_get_value", VTable, address, value);
207+
}
197208
}
198209

199210
template <typename T, typename C>
@@ -708,7 +719,12 @@ class UnityResolve final {
708719
if ((field = Invoke<void*>("mono_class_get_fields", pKlass, &iter))) {
709720
const auto pField = new Field{ .address = field, .name = Invoke<const char*>("mono_field_get_name", field), .type = new Type{.address = Invoke<void*>("mono_field_get_type", field)}, .klass = klass, .offset = Invoke<int>("mono_field_get_offset", field), .static_field = false, .vTable = nullptr };
710721
int tSize{};
711-
pField->static_field = pField->offset <= 0;
722+
/*pField->static_field = pField->offset <= 0;*/
723+
int flags = Invoke<int>("mono_field_get_flags", field);
724+
if (flags & 0x10)//0x10=FIELD_ATTRIBUTE_STATIC
725+
{
726+
pField->static_field = true;
727+
}
712728
pField->type->name = Invoke<const char*>("mono_type_get_name", pField->type->address);
713729
pField->type->size = Invoke<int>("mono_type_size", pField->type->address, &tSize);
714730
klass->fields.push_back(pField);

0 commit comments

Comments
 (0)