blackdtools / Blackd-Proxy-CLASSIC

Blackd Proxy CLASSIC
MIT License
9 stars 7 forks source link

sometimes, dead creatures have HP>0, according to $hpofhex-id: #12

Open divinity76 opened 9 years ago

divinity76 commented 9 years ago

for whatever reason, sometimes it doesn't register that a creature has died/gotten HP 0. the result: $hpofhex-id:{$hex-lastattackedid$}$ may return something >0 ... like here, it return the HP before the final blow: http://prntscr.com/602kqr

divinity76 commented 9 years ago

just tested in 7.6, even reading their HP from memory isn't 100% reliable (which is Battle List ID position +132 bytes) , as even in tibia memory, they have "hp before the final blow".. (eg, 1-hit kill a Orc, and the orc may still be in memory, with HP 100, because it had 100% hp before it got 1-hit-K.O'd. however the client has registered that the orc has died, as it's not on the map, but the corpse is :p ) tested with this function

Public Function GetHPPercentFromMemory760(ByVal CreatureID As Double, idConnection As Integer) As Long
' range=0 to 100, or in some OTs, as is supported by the client and protocol,  0 to 255 :o
    Dim c1 As Long
    Dim id As Double
    For c1 = 0 To LAST_BATTLELISTPOS
        id = CDbl(Memory_ReadLong(adrNChar + (CharDist * c1), ProcessID(idConnection)))
        If CreatureID = id Then
         GetHPPercentFromMemory760 = Memory_ReadByte((adrNChar + (CharDist * c1)) + 132, ProcessID(idConnection))
         Exit Function
        End If
    Next c1
         GetHPPercentFromMemory760 = -1
End Function
divinity76 commented 9 years ago

BlackD, any idea why the proxy sometimes fail to notice that a creature has died in 7.6?

divinity76 commented 9 years ago

could it perhaps be that it's the Nagle Algorithm again? maybe the packet buffer system from SckServerGame isn't working correctly (i didn't really understand it), and when the server sends 2 packets at once with nagle, for instance, "SD was shot AND orc died", it only reads the first packet "SD was shot", and don't learn that the orc died?

and maybe only 7.6 is affected because in 7.7+ or whatever, Cipsoft disabled Nagle's altogether? could that be it? (maybe its even 3 packets, SD was shot AND orc lost HP AND orc died, or 4, Ping packet AND SD was shot AND orc lost HP AND orc died~) I don't understand the SckServerGame_DataArrival buffer system, ... can it handle more than 2 packets at once?

wow, judging by this code,

  longPacket = GetTheLong(ConnectionBuffer(idConnection).packet(0), ConnectionBuffer(idConnection).packet(1))
  If longPacket > ((ConnectionBuffer(idConnection).numbytes) - 2) Then
    #If BufferDebug Then
    LogOnFile "bufferLog.txt", "(" & CStr(idConnection) & ") no complete packet at start..."
    #End If
    DoingMainLoop(idConnection) = False
    Exit Sub ' no complete packet at start...
  End If

it's possible for _DataArrival to be called before the packet is completely downloaded! :O

... in that case, i think once could make an easier buffer system with SckServerGame.BytesReceived and SckServerGame.PeekData , but don't know... but does/has this really happened with you? Data_Arrival before the packet is completely downloaded?