Skip to content

Fix filter class offset and add conditional logging - #24

Closed
hardcpp wants to merge 1 commit into
QuestPackageManager:masterfrom
hardcpp:liveness-log-fix-proposition1
Closed

hardcpp wants to merge 1 commit into
QuestPackageManager:masterfrom
hardcpp:liveness-log-fix-proposition1

Conversation

@hardcpp

@hardcpp hardcpp commented Aug 10, 2026

Copy link
Copy Markdown

Fix wrong offset for reading filterClass on liveness log

Evidence from Unity6 Editor/Data/il2cpp/libil2cpp/vm/Liveness.cpp:45.
image

Comment thread src/register.cpp
custom_types::logger.critical("HasParentUnsafe return: {}", ret);
if (filterClass) {
custom_types::logger.critical("Attempting HasParentUnsafe({}, {})...", fmt::ptr(GET_CLASS(val)), fmt::ptr(filterClass));
auto ret = HasParentUnsafe(GET_CLASS(val), filterClass);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iirc, there were two reasons for this.

  1. We want to still print even when filter class was null
  2. Calling with a null filter class would behave the same as what hasparentunsafe did, that is, if this function was already called with a null filter class, then it would crash in the same place if there were no checks inside the logic of hasparentunsafe

Comment thread src/register.cpp
// specifically, val is a pointer to: 39D0 before obj
// Offset of filter class
auto filterClass = *reinterpret_cast<Il2CppClass**>(reinterpret_cast<uintptr_t>(state) + 0x10);
auto filterClass = *reinterpret_cast<Il2CppClass**>(reinterpret_cast<uintptr_t>(state) + 0x08);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we swap this to the actual state structure from the il2cpp headers? I think that'll make it work more cleanly and across different versions of unity too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The struct is in a .cpp, we dont have access

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've discussed this before with you. Just copy the struct and use it :I

@sc2ad sc2ad Aug 10, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we shouldn't copy it here since that'll effectively be the same issue as the hard coded offset, but it'll be better than the hard coded offset, so we can do that if there's too much garbage in the cpp to include it directly.

I think we can try getting pieces of this structure out, but that's probably out of scope. I'm mostly worried about support for different unity versions. Can we guard this with the unity_* defines to one or the other?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the struct would make the easier far easier to resolve in future versions instead of offset math that we can easily get wrong.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we shouldn't copy it here since that'll effectively be the same issue as the hard coded offset, but it'll be better than the hard coded offset, so we can do that if there's too much garbage in the cpp to include it directly.

I think we can try getting pieces of this structure out, but that's probably out of scope. I'm mostly worried about support for different unity versions. Can we guard this with the unity_* defines to one or the other?

We can but so far i observed same offset on unity2022 & 6

Comment thread src/register.cpp
// specifically, val is a pointer to: 39D0 before obj
// Offset of filter class
auto filterClass = *reinterpret_cast<Il2CppClass**>(reinterpret_cast<uintptr_t>(state) + 0x10);
auto filterClass = *reinterpret_cast<Il2CppClass**>(reinterpret_cast<uintptr_t>(state) + 0x08);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've discussed this before with you. Just copy the struct and use it :I

sc2ad added a commit that referenced this pull request Aug 25, 2026
We do this by forcibly including the il2cpp source directly. This required some hackiness to get around the bs-hook typedefs.h issues,
but ultimately this should be an improvement, since that source is relatively stable across Unity updates so far.

This should also help prevent many of spurious liveness issues that were plaguing people in the past.

Atomic logic and HasParentUnsafe logic taken from: #24
sc2ad added a commit that referenced this pull request Aug 25, 2026
We do this by forcibly including the il2cpp source directly. This required some hackiness to get around the bs-hook typedefs.h issues,
but ultimately this should be an improvement, since that source is relatively stable across Unity updates so far.

This should also help prevent many of spurious liveness issues that were plaguing people in the past.

Atomic logic and HasParentUnsafe logic taken from: #24
sc2ad added a commit that referenced this pull request Aug 25, 2026
We do this by forcibly including the il2cpp source directly. This required some hackiness to get around the bs-hook typedefs.h issues,
but ultimately this should be an improvement, since that source is relatively stable across Unity updates so far.

This should also help prevent many of spurious liveness issues that were plaguing people in the past.

Atomic logic and HasParentUnsafe logic taken from: #24
sc2ad added a commit that referenced this pull request Aug 28, 2026
We do this by forcibly including the il2cpp source directly. This required some hackiness to get around the bs-hook typedefs.h issues,
but ultimately this should be an improvement, since that source is relatively stable across Unity updates so far.

This should also help prevent many of spurious liveness issues that were plaguing people in the past.

Atomic logic and HasParentUnsafe logic taken from: #24
@sc2ad

sc2ad commented Aug 28, 2026

Copy link
Copy Markdown

Resolved in: #26

@sc2ad sc2ad closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants