Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ColorsAPI #554

Merged
merged 1 commit into from
Oct 19, 2024
Merged

Conversation

KingEnderBrine
Copy link
Contributor

I can only assume the real issue is JIT in Unity 2021 being very agressive with optimizations for dynamically generated methods (hooks in our case) when accessing static readonly arrays.

From debugging and logging it seems to me that a hook refers to a specific object ptr instead of a field. Adding new color creates new array and the hook still using old array which eventually gets deallocated and the hook returns random data.
Only making a hook, works fine. Only adding new colors to an array works fine. But doing both results in wrong results. A happy accident that it doesn't cause a crash, just because these methods don't use actual array length and instead uses enum value.

Probably propper solution would be making a patcher that would remove readonly modificator from these fields to ensure there is no more JIT shenanigans, but for this case it should be fine the way I did it.

@KingEnderBrine
Copy link
Contributor Author

Fixing #516

@xiaoxiao921 xiaoxiao921 linked an issue Oct 19, 2024 that may be closed by this pull request
@xiaoxiao921 xiaoxiao921 merged commit f4765f7 into risk-of-thunder:master Oct 19, 2024
4 checks passed
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.

ColorsAPI hooks are broken
2 participants