blackdtools / Blackd-Proxy-CLASSIC

Blackd Proxy CLASSIC
MIT License
9 stars 7 forks source link

[7.6] Looter and wrong stackPos #46

Closed Nrated closed 8 years ago

Nrated commented 8 years ago

Ok, so there's a huge problem with opening bodies on all 7.6 servers that I was playing on. It's counting wrong stackPos. OldLootMode is True on default because bproxy is using OpenCorpse function when looter is enabled. Besides I was checking SmartLootCorpse Function and I've fund big problem there.

For lSS = 1 To 10
    SS = CByte(lSS)
    tileID = GetTheLong(Matrix(ydif, xdif, myZ(idConnection), idConnection).s(SS).t1, Matrix(ydif, xdif, myZ(idConnection), idConnection).s(SS).t2)
    If DatTiles(tileID).alwaysOnTop = True Then  
      SOPT = &HFF
    ElseIf DatTiles(tileID).iscontainer = True Then
      SOPT = SS
      Exit For
    Else
      Exit For
    End If
  Next lSS

ok this thing is wrong. If DatTile(tileID).isContainer = True Then stackPos = current iteration and it's escaping from For - that's good. but when it's not a container then it exits for loop either when it is supposed to keep looping throught lSS(stackPos) to find container. So basicly loops ends anyways right after first iteration and it doesn't matter if container is found or not

Old Loot Mode is using stackpos received from the packet and it's wrong because it should loop through stackPos just like here to find the container! I've made few changes and my looter is opening every dead body. Gonna pull commit after testing it on higher tibia versions ; p

divinity76 commented 8 years ago

yup, it fails a lot (but not always) for me too - especially on difficult terrain

Nrated commented 8 years ago

Yeah it can be easily fixed by adding For which loops through stackPos in OpenCorpse function. I've fixed this thing for myself but I'm playing only tibia 7.6 and I'm too lazy to check higher versions so I don't know if its wise to pull commits without testing it

I'm gonna put my code here in comments so everyone interested can apply this thing for themselves when I'll get back to home

divinity76 commented 8 years ago

Quoting Daniel, Cipsoft changed the stackPos system several times throughout the versions, and at some point, blackd probably fucked up the 7.6 stackpos to fix a newer version of tibia; related issue: https://github.com/blackdtools/Blackd-Proxy-CLASSIC/issues/20

as for 7.6 specific fixes, simply wrap it in a

if(tibiaVersionLong = 760) Then
'fix here
End If
Nrated commented 8 years ago

Well, that's my OpenCorpse Function:


Public Function OpenCorpse(idConnection As Integer) As Long
  Dim aRes As Long
  Dim bpID As Byte
  Dim sCheat As String
  Dim cPacket() As Byte
  Dim topStack As Long
  Dim sPos As Long
  Dim tileID As Long
  Dim xdif As Long
  Dim ydif As Long
  'aRes = SendLogSystemMessageToClient(idConnection, "Detected new corpse at " & _
   myLastCorpseX(idConnection) & " , " & myLastCorpseY(idConnection) & " , " & _
   myLastCorpseZ(idConnection) & " , " & myLastCorpseS(idConnection) & " : " & _
   FiveChrLon(myLastCorpseTileID(idConnection)))
 ' DoEvents
  '0A 00 82 37 7D A7 7D 09 59 0F 02 00
  xdif = myLastCorpseX(idConnection) - myX(idConnection)
  ydif = myLastCorpseY(idConnection) - myY(idConnection)
  bpID = frmBackpacks.GetFirstFreeBpID(idConnection)
  If (myLastCorpseZ(idConnection) <> myZ(idConnection)) Then
    If publicDebugMode = True Then
      aRes = SendLogSystemMessageToClient(idConnection, "[Debug] Ignored looting corpse order because different floor :" & _
       CStr(myLastCorpseX(idConnection)) & "," & CStr(myLastCorpseY(idConnection)) & "," & CStr(myLastCorpseZ(idConnection)) & _
       " at bpID " & GoodHex(bpID))
      DoEvents
    End If
    OpenCorpse = 0
    Exit Function
  End If
  If Not (bpID = &HFF) Then
    requestLootBp(idConnection) = bpID
    If publicDebugMode = True Then
      aRes = SendLogSystemMessageToClient(idConnection, "[Debug] Looting corpse at :" & _
       CStr(myLastCorpseX(idConnection)) & "," & CStr(myLastCorpseY(idConnection)) & "," & CStr(myLastCorpseZ(idConnection)) & _
       " at bpID " & GoodHex(bpID))
      DoEvents
    End If
    If (TibiaVersionLong = 760) Then
    'fix for tibia 7.6.
        For sPos = 1 To 10
            tileID = GetTheLong(Matrix(ydif, xdif, myZ(idConnection), idConnection).s(sPos).t1, Matrix(ydif, xdif, myZ(idConnection), idConnection).s(sPos).t2)
            'Debug.Print DatTiles(tileID).iscontainer
            If DatTiles(tileID).iscontainer = True Then
            'first stacks are reserved for grounds or permament items
            'topStack is 02 in most of cases and then are the items that lies beneath topItem
                topStack = sPos
                Exit For
            End If
        Next sPos
        sCheat = "0A 00 82 " & FiveChrLon(myLastCorpseX(idConnection)) & " " & _
        FiveChrLon(myLastCorpseY(idConnection)) & " " & GoodHex(CByte(myLastCorpseZ(idConnection))) & _
        FiveChrLon(tileID) & " " & GoodHex(CByte(topStack)) & " " & GoodHex(bpID) & " "
    Else
        sCheat = "0A 00 82 " & FiveChrLon(myLastCorpseX(idConnection)) & " " & _
        FiveChrLon(myLastCorpseY(idConnection)) & " " & GoodHex(CByte(myLastCorpseZ(idConnection))) & _
        FiveChrLon(myLastCorpseTileID(idConnection)) & " " & GoodHex(CByte(myLastCorpseS(idConnection))) & " " & GoodHex(bpID) & " "
    End If
    GetCheatPacket cPacket, sCheat
    frmMain.UnifiedSendToServerGame idConnection, cPacket, True
    DoEvents
    ' give 5 seconds max to loot
    lootTimeExpire(idConnection) = GetTickCount() + 5000
  Else
    If publicDebugMode = True Then
      aRes = SendLogSystemMessageToClient(idConnection, "[Debug] Can't loot it. Please open new containers!")
      DoEvents
    End If
  End If
  OpenCorpse = 0
End Function
Nrated commented 8 years ago

We should make looter based on Loot-Channel ; p who's in? : P

divinity76 commented 8 years ago

the current looter is detectable, super fast, with no delays, etc, so yes the looter code needs a lot of work, but.. meh

Nrated commented 8 years ago

Yeah I'm also too lazy for this xD

michelallan commented 6 years ago

I know it's pretty late, but i'm playing a 7.4 server that has problems with looting (some bodies blackd doesn't open), so where do I have to put this function code Nrated said? In conditions?

divinity76 commented 6 years ago

@michelallan do you mean 7.4 client or "7.72 client with server pretending to be 7.4" ?

michelallan commented 6 years ago

@divinity76 yes, must be something like this (i'm playing Tibians.org), can u help me on it?

michelallan commented 6 years ago

I noticed the bot doesn't open bodies when they are under me, what can I do? Do you have the same problem?

divinity76 commented 6 years ago

@michelallan the fist thing you must do is to identify the real tibia version it's using, not the 1 it claims it's using. for example, a couple of years back, many OT servers claimed to be 7.4 but was actually a modded 7.72. if you have a linux system, run cat tibia.exe | strings | pastebinit - or if you're on a windows system, download https://docs.microsoft.com/en-us/sysinternals/downloads/strings and run strings.exe tibia.exe > strings.txt and then upload strings.txt ...

michelallan commented 6 years ago

@divinity76 via command line?

divinity76 commented 6 years ago

yes

michelallan commented 6 years ago

strings.exe should be in the same directory of my tibia.exe (otserv)? im getting 'no matching files were found'

michelallan commented 6 years ago

@divinity76 and when I try to put all in the same directory and execute the command u said, strings.txt is created with the following message "!This program cannot be run in DOS mode."

michelallan commented 6 years ago

@divinity76 about tibia version, I can check it on details and it says is 7.72. By knowing that, is there a way I can fix this problem with looting?

divinity76 commented 6 years ago

you should get over 100 strings, if that is the ONLY string you got, then tibia.exe is packed or encrypted. download Process Explorer ( https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer ) , double click on Tibia.exe in the list, then press Strings -> Memory -> Save -> foo.txt , and upload the foo.txt file pe

divinity76 commented 6 years ago

@michelallan oh, you think it's 7.72? nice, i think the fix is the same as @Nrated 's fix for 7.6,

If (TibiaVersionLong = 760) Then
    'fix for tibia 7.6.
        For sPos = 1 To 10
            tileID = GetTheLong(Matrix(ydif, xdif, myZ(idConnection), idConnection).s(sPos).t1, Matrix(ydif, xdif, myZ(idConnection), idConnection).s(sPos).t2)
            'Debug.Print DatTiles(tileID).iscontainer
            If DatTiles(tileID).iscontainer = True Then
            'first stacks are reserved for grounds or permament items
            'topStack is 02 in most of cases and then are the items that lies beneath topItem
                topStack = sPos
                Exit For
            End If
        Next sPos
    Else

just replace if ( TibiaVersionLong = 760 ) with if ( TibiaVersionLong = 772 ) and see if that works

michelallan commented 6 years ago

@divinity76 i should copy and paste all this code on a .txt file and load on conditions? I'm not a pro user of BlackD :P

michelallan commented 6 years ago

@divinity76 there it is the file using Process Explorer

Tibia.exe.txt

divinity76 commented 6 years ago

@michelallan i should copy and paste all this code on a .txt file and load on conditions?

then you must open modCavebot.bas and find the Function OpenCorpse (it's near line 5506), and replace the entire function with @Nrated 's OpenCorpse, but replace If (TibiaVersionLong = 760) Then with If (TibiaVersionLong = 772) Then

then re-compile BlackD Proxy, and see if the cavebot can open corpses now.. good luck

michelallan commented 6 years ago

@divinity76 it was hard as f*** to make it work, but still I got it. Now I'm checking how the bot is working and I can say that it got better, but still misses sometimes when my char goes up the body. With @Nrated function it should be perfect now? :/

divinity76 commented 6 years ago

@michelallan gratz on compiling it.

With @Nrated function it should be perfect now? :/ - i don't know, try it, lel

michelallan commented 6 years ago

@divinity76 ye I tried already, but as I said, sometimes the bot still misses some corpses

Nrated commented 6 years ago

@michelallan In theory it should work fine, since it is looking for a container on a specific position. You can always run it in debug mode and analize what's wrong with it. Debug.Print all the items on exact position before looting and they print sPos that was picked up by a bot and then you'll know how their stackPos is working.

Also I think that your problem might be caused by different looting type. I'm not sure though :D It's been really long since I was playing with blackd's source.