Astarisk / ethical-copypasta

Other
3 stars 1 forks source link

Python PBotGob.get_sdt() is not working on fork but working on original #1

Closed FirePowi closed 3 years ago

FirePowi commented 3 years ago

So I tried this script I wrote, using both clients:

from __pbot.PBotSession import PBotSession
from __pbot.PBotWindow import PBotWindow
import time

class Script:
    def run(self, sess: PBotSession):
        printsm = sess.PBotUtils.sys_msg
        printch = sess.PBotCharacterAPI.msg_to_chat

        def printsm_error(msg):
            printsm(msg,255,100,100)
        def printsm_log(msg):
            printsm(msg,150,150,150)
        def printsm_info(msg):
            printsm(msg,100,255,100)
        def printsm_end(msg):
            printsm(msg,100,100,255)

        printsm_log("[+] Starting script")

        try:
            printsm_log("\t[+]Searching for anygob")
            gob = sess.PBotGobAPI.get_closest_gob_by_resname(".*")

            printsm_log("\t[+]Trying to get gob's sdt")
            sdt = gob.get_sdt()

            printsm_info("\t[-]I worked perfectly and sdt = {}".format(sdt))

        except Exception as e:
            printsm_error("[-]Something went wrong with script:")
            printsm_log("`{}`".format(e))
        printsm_end("[-]Off")

Ethical fork showed this:

An error occurred while calling o223.getSdt. Trace: py4j.Py4JException: Method getSdt([class java.lang.Integer]) does not exist
    at py4j.reflection.ReflectionEngine.getMethod(Reflection Engine.java:318)
    at py4j.reflection.ReflectionEngine.getMethod(Reflection Engine.java:326)
    at py4j.Gateway.invoke(Gateway.java:274)
    at py4j.commands.AbstractCommand.invokeMethod(Abstr actCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand. java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java :238)
    at java.base/java.lang.Thread.run(Thread.java:829)

While the unethical client worked with it perfectly "[-]I worked perfectly and sdt = XX" been displayed.

I think there’s an issue with updating API in your version and I struggle building it with eclipse (I’m def not a Java dev)

Astarisk commented 3 years ago

Hello! It's not immediately obvious to me what is going on with this issue. The code base should ideally just be the unethical version minus the whole Mapping class bit and everything on my end seems to be up to date with the latest build on puru's end.

As for testing I couldn't reproduce what you are getting as an error. I've downloaded the latest zip of the client myself and was able to run your script just fine (after fixing the incorrect mss in printsn_end). I checked to make sure that the getSdt method existed that's being called and it is in the source here: https://github.com/Astarisk/ethical-copypasta/blob/765c194784f708f927dfcc0ec2ba1b4534b6bce2/src/haven/purus/pbot/api/PBotGob.java#L339

That aside I checked the call stack and everything seems to be properly there. I'm not sure what is going on with your script on your end. You could try to print out the object type that you are calling getSdt on just to see if it is what should be expected to be returned. I don't have a huge understanding of Puru's botting structure but at first glance I haven't seen anything in this version that is off.

As for advice on building it, I'd just clone the git in IntelliJ, Add the build.xml as an Ant file. Typically this works well enough minus issues with Java versions. I don't have experience with getting it to run in eclipse so I have no advice there.

FirePowi commented 3 years ago

I don’t really get it… I’ll try my best describing EVERY step.

So I want last version, I’m downloading the whole https://www.dropbox.com/s/i91o8fh2rkoucmp/ethical-pasta.zip?dl=0

Then I try to log on, but I have an issue: Connection refused: connect Screenshot showing the error message

I figured it might come from hafen.jar, I download the latest and overwrite the one from downloaded files: https://www.dropbox.com/s/cwovglxqq1fdzm8/hafen.zip?dl=0

Then log-in without issue, but get_sdt() isn’t here. I found the /pbot/api/PBotGob.java and its content, the getSdt, I just don’t get what happened. Also thanks for the "mss" ==> "msg" and sorry, I pasted and previous version where I didn’t fix this mistyping.

I’d like to add all my scripts using get_sdt() has the same issue, I just don’t really get it – If needed:

$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment 18.9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9, mixed mode)

On Windows Version 10.0.19042 Build 19042

PS: I’ll try to build with your advise

Astarisk commented 3 years ago

Ah, I see what is going on. You need to make sure to use the bat file to run the client. That is most likely causing the connection refused as the server information is passed as a parameter. As for the second link which contains just the jar. I thought I had removed that link when the first resource changes were done by the devs. That one is an old jar and could be triggering the get_sdt() error. I'll remove that from my post, in the mean time you can just copy the jar over from the bigger zip if you need it. If you still get connection refused after running the client using the bat file, then we may have more of a mystery on our hands. But from what I can tell at a glance the first half is a bat issue and the second half is me messing up.

FirePowi commented 3 years ago

I’ll follow your lead step by step and give you feedback

I’ll try another java version for now, it starts to really look like it’s our best friend (irony for me) messing up

FirePowi commented 3 years ago

Oh no… I checked and you’re using java11 too apparently. Well I’ve finished IntelliJ installation, I’ll try to rebuild the jar from sources

Astarisk commented 3 years ago

I'm a bit baffled as there shouldn't be any changes in between the jars that would cause the newer one to break. I'll keep re-looking through the commit history to see if I missed anything on that front. The best idea I could think is windows or java security blocking connection. But even that seems weird to me at this point. I haven't seen or heard anyone who ran into a connection error with proper parameters. You could in theory also copy the jar into puru folder and see if that launches it, though I'm not sure what that would fully solve.

Astarisk commented 3 years ago

I tried running it on a second PC and I noticed that the run.bat got connection refused on that one, however the second run_with_puru_params.bat did not. So give that a shot. Though it does make me wonder why it works fine on this machine over the other. If that is the case for you I'll remove my first bat file as it was just thrown in quickly when I put this together. This is what it should look like: start java -Xms1G -Xmx2G -Dsun.java2d.uiScale.enabled=false -Dhaven.defserv=game.havenandhearth.com -Dhaven.resurl=https://game.havenandhearth.com/res/ -Dhaven.screenurl=http://game.havenandhearth.com/mt/ss -Dhaven.cachebase=http://game.havenandhearth.com/render/ -Dhaven.mapbase=http://game.havenandhearth.com/java/ -Dhaven.fullscreen=off -jar hafen.jar

FirePowi commented 3 years ago

image

I’ve got this – I changed this line printsm_info("\t[-]I worked perfectly and sdt = {}".format(sdt)) to printsm_info("\t[-]It works… I mean Astarisk rocks!") because of first attempt working, just to "celebrate" (kinda)

You’re doing an amazing support job

Thanks a lot!

I think we may close the issue if you have nothing to add