Dev Assistance - Coins 995 Handling

Various development-related discussions
Post Reply
User avatar
Byte
Noob
Posts: 15
Joined: Mon Sep 05, 2022 2:29 am
Been thanked: 4 times

Dev Assistance - Coins 995 Handling

Post by Byte »

Is there a nice way to use the IntelliJ debugger effectively to identify a line of code that is being executed at runtime?

I have tried getting things running and then pausing the debugger, but that doesn't really put me where I want to be. I want to specifically be doing something in the game and pause in the midst of the action. I'm not sure how possible this is.

I am very familiar with setting breakpoints, but that only helps when you know where you are in the code. In my case, I do not know where I am :lol:

Thanks!
Last edited by Byte on Mon Sep 05, 2022 6:34 pm, edited 1 time in total.
User avatar
Byte
Noob
Posts: 15
Joined: Mon Sep 05, 2022 2:29 am
Been thanked: 4 times

Re: Dev Assistance - Coins 995 Handling

Post by Byte »

The reason I am asking the above is because I am currently trying to get my feet wet on what I thought was a super simple issue: https://gitlab.com/2009scape/2009scape/-/issues/713. It has turned out to be a bit bizarre.

The issue is simple: we're just not quite handling displaying the number of Coins or the "Lovely money!" statement in the right way all the time. User is getting a weird String, but that's just what is currently in items_config.

What I have established is this: examining Coins (995) in any context (be it on the ground, in inventory, in the bank) seems to display an examine text that I can easily find the source of in the codebase.

However, when examining a Coins stack in the player inventory that is >= 100k, I cannot track where this is in the codebase. Somehow there is a completely different path in the code that is being taken, and the result is that the examine statement actually displays the exact number of Coins. I have 'grep'ed the heck out of the baseline to try and find where this could be happening and haven't found it.

So if anyone happens to know why "stacks of 100k or more Coins in the player inventory when examined" is taking a different path through the code, rather than going through the opcode 92 block in the ExaminePacket class, I'd love to know where to look!
Last edited by Byte on Mon Sep 05, 2022 6:34 pm, edited 1 time in total.
User avatar
Ceikry
Site Admin
Posts: 585
Joined: Wed Aug 10, 2022 11:48 pm
Location: Draynor Village
Has thanked: 82 times
Been thanked: 103 times

Re: Dev Assistance - IntelliJ Debugger

Post by Ceikry »

Byte wrote: Mon Sep 05, 2022 3:40 am So if anyone happens to know why "stacks of 100k or more Coins in the player inventory when examined" is taking a different path through the code, rather than going through the opcode 92 block in the ExaminePacket class, I'd love to know where to look!
The reasoning is pretty basic. The "Examine" option on an item in an interface does not actually go through the traditional examine packet, and is instead sent by the client purely as an interface interaction packet, and it's left up to the server to figure out what that interaction was and handle it.

If you look in Server/src/main/kotlin/rs09/game/interaction/inter/bank/BankInterface.kt, you can see the code for handling the bank interface. Opcode 9 (in the context of this specific interface) is the examine opcode:

Code: Select all

        private const val OP_EXAMINE = 9
Which is then handled by sending a message to the player with the item's defined examine text from item_configs:

Code: Select all

            OP_EXAMINE -> sendMessage(player, item.definition.examine)
The reason there's a difference is largely due to this project's history. You should take the time to read it on our README. We inherited a large chunk of this codebase, and what we inherited sucked. That practice of overriding examine texts in the examine packet decoder? Baffling stupidity. Anyways, all you need to do to fix this is either
  • * override the examine at the call site (so in the bank interface handler)
    * move the overrides to the (actually standard) getExamine() method in Server/src/main/java/core/cache/def/Definition.java
    * implement a cleaner way to perform runtime examine overrides (harder but more preferred)
Nerds
User avatar
Byte
Noob
Posts: 15
Joined: Mon Sep 05, 2022 2:29 am
Been thanked: 4 times

Re: Dev Assistance - Coins 995 Handling

Post by Byte »

Thank you very much for your response.

I was not confused by the Bank interface. I noticed that when in the Bank interface, it uses that BankInterface.kt to handle whether the player is examining in the Bank screen or the player inventory screen. Overriding in those two methods would be the simple fix for that issue. So I'm glad we have the same idea!

Where this got weird is when not in an interface like the Bank interface. If I examine Coins in the player inventory < 100k I get "Lovely, money!" which is clearly from the override in the getItemExamine(id) method. This is because it handled an ExaminePacket and opcode 92 was executed for item examine. I have tracked this explicitly with debugging statements in this code.

When I do the same thing (examine Coins in the player inventory), but the number is >= 100k, I get something like "1,300,432 x Coins". None of my debug statements print out. I have found nothing of this format in any of the Server code, which makes me think this is being forcibly overwritten in the Client somewhere. It isn't using ExaminePacket. It doesn't go through opcode 92 for item examine. It doesn't even go through any code in any of the classes you mentioned (i.e. Definition, ItemDefinition). Perhaps trying to override in here would be an ok solution (once I find where it's being forced in the client), but right now it's not even executing through the same code.

Maybe when I ponder this a bit more it'll be clear what the solution for all of these cases are. I am definitely going to check out the client code as well, because I'm curious if the client is doing something sneaky and the server is not the culprit for this specific case.

Thanks again for your help :D Ryan put it nicely when he told me "You tried to jump in a puddle but it turned out to be a sewer"
User avatar
Ceikry
Site Admin
Posts: 585
Joined: Wed Aug 10, 2022 11:48 pm
Location: Draynor Village
Has thanked: 82 times
Been thanked: 103 times

Re: Dev Assistance - Coins 995 Handling

Post by Ceikry »

The most likely case at that point is that the latter case is being handled by a client script. When that happens, stop trying to mess with it. It's guaranteed to be authentic at that point.
Nerds
Post Reply