Navigation

    CCBlueX Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Solved A way to replace a specific amount of lines of code in Mixin?

    General
    5
    14
    165
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mems last edited by mems

      Let's say that there's a function that includes a few lines of code that a person doesn't want to see and wants to replace them in a Mixin file, how can they do that?

      In dumb talk:

      Original game function code:

          public void onEntityPosition(EntityPositionS2CPacket packet) {
              NetworkThreadUtils.forceMainThread(packet, this, this.client);
              Entity entity = this.world.getEntityById(packet.getId());
              if (entity != null) {
                  double d = packet.getX();
                  double e = packet.getY();
                  double f = packet.getZ();
                  entity.updateTrackedPosition(d, e, f);
                  if (!entity.isLogicalSideForUpdatingMovement()) {
                      float g = (float)(packet.getYaw() * 360) / 256.0F;
                      float h = (float)(packet.getPitch() * 360) / 256.0F;
                      entity.updateTrackedPositionAndAngles(d, e, f, g, h, 3, true);
                      entity.setOnGround(packet.isOnGround());
                  }
      
              }
          }
      

      A person wants to replace/mixin out only these:

      double d = packet.getX();
      double e = packet.getY();
      double f = packet.getZ();
      

      After a way of replacing them:

          public void onEntityPosition(EntityPositionS2CPacket packet) {
              NetworkThreadUtils.forceMainThread(packet, this, this.client);
              Entity entity = this.world.getEntityById(packet.getId());
              if (entity != null) {
                  double def = 0D; // AFTER
                  entity.updateTrackedPosition(d, e, f);
                  if (!entity.isLogicalSideForUpdatingMovement()) {
                      float g = (float)(packet.getYaw() * 360) / 256.0F;
                      float h = (float)(packet.getPitch() * 360) / 256.0F;
                      entity.updateTrackedPositionAndAngles(d, e, f, g, h, 3, true);
                      entity.setOnGround(packet.isOnGround());
                  }
      
              }
          }
      

      Possible? If there's anyone with a good Mixin knowledge, mind giving a solution?

      EDIT: My only working way of accomplishing it is by making different injections for each part.

      S 1 Reply Last reply Reply Quote 0
      • M
        mems last edited by mems

        Okay, holy crap. I managed to find a way to make it work with 1 injection only... My idea was that if this.positionLookSetup was false (which means that player hasn't joined the server yet) then keep the original code running normally. If it was set to true though, then cancel and add the custom code, and that way it will not affect the mod that sends its changes after this.positionLookSetup. Tested it and there are no problems on any version now, so far.

        H 1 Reply Last reply Reply Quote 1
        • I
          idk my name last edited by

          @Overwrite

          M 1 Reply Last reply Reply Quote 0
          • M
            mems @idk my name last edited by

            @idk-my-name In my case it's too dangerous to use due to the fact that some other mods might potentially want to modify the same function too and if I overwrite it, only bad stuff will happen.

            S 1 Reply Last reply Reply Quote 0
            • S
              SigmaClient 0 @mems last edited by SigmaClient 0

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • S
                SigmaClient 0 @mems last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • M
                  mems last edited by mems

                  Nevermind, I will consider my method after a bit of intensive thinking.

                  EDIT: If someone still has a better way then feel free to post.

                  1 Reply Last reply Reply Quote 0
                  • Topic has been marked as solved  M mems 
                  • A
                    Aftery last edited by

                    how about injecting before func and modifying the packet itself?

                    M 1 Reply Last reply Reply Quote 0
                    • M
                      mems @Aftery last edited by mems

                      @aftery I might be wrong, but your idea kind of reminds me of injecting at the top of the function, cancelling it all, and after that, adding the original code with the changes that I want to make. That's probably not what you mean though?

                      That function I posted was just a random one as an example of what I want to accomplish, by the way. The function that I actually want to make changes on is this one: https://pastebin.com/95kfXWUM

                      And these 3 lines are the only ones I want to somehow replace/remove:

                              playerEntity.updatePositionAndAngles(e, g, i, j, k);
                              this.connection.send(new TeleportConfirmC2SPacket(packet.getTeleportId()));
                              this.connection.send(new Full(playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), playerEntity.getYaw(), playerEntity.getPitch(), false));
                      

                      I should have put that function as the example instead of that random one I chose...

                      EDIT: My only way to solve it that I still don't really like is by making different injections for each line. The first one would be updatePositionAndAngles, the 2nd one TeleportConfirmC2SPacket and so on.

                      A 1 Reply Last reply Reply Quote 0
                      • A
                        Aftery @mems last edited by Aftery

                        @mems yeah my post was specifically for that one case in the OP example
                        a cleaner way might be to inject before playerEntity.updatePositionAndAngles(e, g, i, j, k);, running the leftover code and cancelling callbackinfo, which only uses 1 mixin tho idk if thats possible
                        ed: there doesnt seem to be a way to use asm directly through mixins >_>

                        M 1 Reply Last reply Reply Quote 0
                        • M
                          mems @Aftery last edited by mems

                          @aftery I have used that method too and I can say it does work, but here's where things get kinda worse. There's a mod that also injects to that function, but after the this.positionLookSetup statement and modifying it (in my case cancelling callbackinfo) prevents me from joining servers. Click here for more info. Essentially if my chosen version for a server is 1.13.2 and below, then I have 0 chances of joining it. If higher than 1.13.2 though, it works normally.

                          EDIT: Perhaps a way to cancel callbackinfo until it reaches the this.positionLookSetup statement would be cool.

                          A 1 Reply Last reply Reply Quote 0
                          • A
                            Aftery @mems last edited by

                            @mems yeah in that case i dont think you have any better/cleaner option unless theres some undocumented way to access the underlying mixin asm-stuff-thing-something idk

                            M 1 Reply Last reply Reply Quote 0
                            • M
                              mems @Aftery last edited by

                              @aftery I guess I will go with multiple injections and then make use of Redirect. I will keep searching for any better results though.

                              1 Reply Last reply Reply Quote 0
                              • Topic has been marked as unsolved  M mems 
                              • Topic has been marked as solved  M mems 
                              • M
                                mems last edited by mems

                                Okay, holy crap. I managed to find a way to make it work with 1 injection only... My idea was that if this.positionLookSetup was false (which means that player hasn't joined the server yet) then keep the original code running normally. If it was set to true though, then cancel and add the custom code, and that way it will not affect the mod that sends its changes after this.positionLookSetup. Tested it and there are no problems on any version now, so far.

                                H 1 Reply Last reply Reply Quote 1
                                • Topic has been marked as unsolved  M mems 
                                • Topic has been marked as solved  M mems 
                                • H
                                  halal.club @mems last edited by

                                  @mems sigma cleint mixin bypass men)))

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post