Jump to content

Recommended Posts

Posted

Howdy folks

 

I'm having some trouble with the ObfuscationReflectionHelper.   I'm using findfield, and it works fine when I run it in a development environment and when I package it as a mod.

But I've had a bug report from another programmer who finds that it crashes his code.  The difference appears to be that his environment is running with obfuscated names, so that the reflection helper can't find the deobfuscated field name.

 

Any thoughts on what's going on and how I can robustly fix it?  The whole obfuscation/deobfuscation is still something of a black box for me and I can't reproduce his issue so I don't have many clues to point me in the right direction.

 

Cheers

  TGG

 

The code:

  private static World getPrivateWorldFromWorldRenderer(WorldRenderer worldRenderer) throws IllegalAccessException {
    if (worldField == null) {
      worldField = ObfuscationReflectionHelper.findField(WorldRenderer.class, "world");
    }
    return (World)worldField.get(worldRenderer);
  }

  private static Field worldField;

 

His crash log:

https://pastebin.com/ExUU5BaS

and in particular:

Caused by: java.lang.NoSuchFieldException: world

and I notice lots of obfuscated (Searge) names in there:

eg

at net.minecraft.client.renderer.WorldRenderer.func_228426_a_(WorldRenderer.java:1096) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}

 

When I try to reproduce the crash by changing my code to 

worldField = ObfuscationReflectionHelper.findField(WorldRenderer.class, "worldDONOTFIND");

I get the same error but my crash log has deobfuscated (MCP) names in it

 

eg

at net.minecraft.client.renderer.WorldRenderer.updateCameraAndRender(WorldRenderer.java:1118) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
 

 

 

 

 

 

Posted (edited)

The issue with reflection normally is that methods and fields have different names depending on their mappings. Forge in a universal environment will use the srg names (field_123456_a_) while a dev environment will use the mapping names (example). How do we fix this? In comes ObfuscationReflectionHelper where it will take a srg name string and map it to its current mapping environment as needed. So, the field/method being specified must be the srg qualified name. You can find these names using '!mcpf <field_name>' or '!mcpm <method_name>' via dming the forge-bot over on the forge discord.

Edited by ChampionAsh5357

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.