Jump to content

[SOLVED] Convert float32 to Time


qwer85
 Share

Recommended Posts

Hello everyone,

I need a little help. I'm writing a plugin which retrieves information from Half-Life Dediated Server using UDP. Everything is going well. I've already got names and current frags. But I found a problem to convert time coded into packet as float32 into time format.

Here is what I have:

Name / Frags / Time

Afer - 8 - 970ABF44 (For example I know that he is playing about 25 minutes)

ONIGA - 1 - 492B4F43

Pro ATF | dRum - 1 - 353F9444

Pylua - 1 - 91C9FC42

oLd sCh0oL.> MaJlgeP - 36 - 83439C44

maks - 6 - 83599C44

PORTER - 19 - 0FAF9844

St0p - 27 - 0B4E9C44

hiiakimaro - 8 - 32213744

Happy - 4 - 94D0D543

The time should be like: HH:MM:SS

Can anyone help me?

Edited by qwer85
Link to comment
Share on other sites

Thats just how float's look in memory :)

#include <winapi.au3>
; Raw
$s = "970ABF44"
; Correct endian
$s = StringMid($s,7,2) & StringMid($s,5,2) & StringMid($s,3,2) & StringMid($s,1,2)
; Convert
$n = _WinAPI_IntToFloat (Dec($s))
ConsoleWrite($n & @CRLF)

i'd assume that the output is in seconds...

Edited by piccaso
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

Thanks a lot, but how do i convert seconds into hour:minute:second format?

[EDIT]

I made foll script and it seems to work:

#include <WinAPI.au3>

ConsoleWrite(_TimeConversion("970ABF44") & @CRLF)

Func _TimeConversion($s_TimeAsFloat32)
    ;DONT FORGET TO ADD #include <WinAPI.au3> ! ! !
    $s_Endian = StringMid($s_TimeAsFloat32,7,2) & StringMid($s_TimeAsFloat32,5,2) & StringMid($s_TimeAsFloat32,3,2) & StringMid($s_TimeAsFloat32,1,2)
    $f_TimeInSec = _WinAPI_IntToFloat(Dec($s_Endian))
    $i_Hours = Int($f_TimeInSec / 3600)
    $i_Mins = Int(($f_TimeInSec - ($i_Hours * 3600)) / 60)
    $i_Sec = Int($f_TimeInSec - (($i_Mins * 60) + ($i_Hours * 3600)))
    Return $i_Hours & ":" & $i_Mins & ":" & $i_Sec
EndFunc
Edited by qwer85
Link to comment
Share on other sites

You dont have to wrap your mind around date calculations, there are udf's for that too:

#include <WinAPI.au3>
#include <Date.au3>

ConsoleWrite(_TimeConversion("970ABF44") & @CRLF)

Func _TimeConversion($s_TimeAsFloat32) ; Using: WinAPI.au3, Date.au3
    Local $s_Endian, $n_TimeInSec, $i_Hours, $i_Mins, $i_Sec
    $s_Endian = StringMid($s_TimeAsFloat32, 7, 2) & StringMid($s_TimeAsFloat32, 5, 2) _
             & StringMid($s_TimeAsFloat32, 3, 2) & StringMid($s_TimeAsFloat32, 1, 2)
    $n_TimeInSec = _WinAPI_IntToFloat (Dec($s_Endian))
    _TicksToTime($n_TimeInSec * 1000, $i_Hours, $i_Mins, $i_Sec)
    Return $i_Hours & ":" & $i_Mins & ":" & $i_Sec
EndFunc

I know, i'm too late :)

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...