Unique Enchantments

Unique Enchantments

6M Downloads

Usages of MiscUtil#findMethod() and MiscUtil#findField() are unsafe

SmellyModder opened this issue ยท 3 comments

commented

As it stands, MiscUtil#findMethod() and MiscUtil#findField() are using mapped field names when looking up stuff with reflection.
This method of handling the reflection of dynamic names is unsafe because it doesn't account for mapped names that aren't in the provided array.
For example, some usages of these methods would not work on an instance of the game that's mapped with Mojang mappings because no fields/methods would exist that match any of the provided names.
A simple fix for this issue is to use the reflection helper methods provided in Forge's ObfuscationReflectionHelper instead.

I came across this issue when testing this mod in a dev environment mapped with Mojang mappings.

commented

@SmellyModder yeah they are unsave. I have written them myself. We actually tried using "ObfuscatedReflectionHelper" and guess what happened. The game crashed in exported builds even if we used "obfuscated/deobfuscated" names, the system I wrote works for the mappings that are used that's why the mappings used are included in the gradle information.

If you change them then you have to deal with issues that come up. But any code that you change has that risk.

If you know how to fix it with ObfuscationReflectionHelper that it does NOT crash in IDE/Exported Builds then go ahead make a patch, we will test it and if it works we will include it. Because I already tried and failed so I made a version that works.

commented

@SmellyModder i am not joking. I tried with multiple versions of adding that and only had crash results so if you can make it work I would gladly await a pullrequest from you.

commented

@SmellyModder upgraded to Mojang Mappings though still using reflection as before. Just FYI..