Jump to content

Changing the Session, is it possible?


TealNerd

Recommended Posts

So in Minecraft 1.7.10, the Minecraft session field is private and final. I can change it to public with an access transformer (which is easy) but I can't actually modify the session id because it's final. Is there a way to edit this or would I have to code a fully custom client?

Link to comment
Share on other sites

You can set it to be accessible using reflection. This StackoOverflow post shows you how to do it:

http://stackoverflow.com/questions/3301635/change-private-static-final-field-using-java-reflection

 

But be aware that reflection uses quite a lot of cpu power...

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

First of all, I suggest using either the ReflectionHelper or ObfuscationReflectionHelper classes - they make cleaner code, and change this:

 

try
{
    Field field = SomeClass.class.getDeclaredField("someFieldName");
    field.setAccessible(true);
    Object object = field.get(SOMECLASS_INSTANCE);
    //do stuff
}
catch (Exception e)
{
    try
    {
        Field field = SomeClass.class.getDeclaredField("field_SRG_NAME");
        field.setAccessible(true);
        Object object = field.get(SOMECLASS_INSTANCE);
        //do stuff
    }
    catch(Exception e2)
    {
        //Log exception
    }
}

 

into

 

Object object = ReflectionHelper.getPrivateValue(SomeClass.class, SOMECLASS_INSTANCE, "someFieldName", "field_SRG_NAME");

 

Much cleaner.

 

Example code

Field sessionField = ReflectionHelper.findField(Minecraft.class, "session", "field_71449_j");
ReflectionHelper.setPrivateValue(Field.class, sessionField, sessionField.getModifiers() & ~Modifier.FINAL, "modifiers");
ReflectionHelper.setPrivateValue(Minecraft.class, Minecraft.getMinecraft(), YOUR_SESSION_INSTANCE, "session", "field_71449_j");

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Link to comment
Share on other sites

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.

×
×
  • Create New...

Important Information

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