
{$CLEO}
0000:
thread 'VCSpeed'

wait 15000

if
    0AA9: is_game_version_original
then
else
    004E: end_thread
end




9@ = 0.0

:WAIT_FOR_CAR
wait 0
if
    0256: player $PLAYER_CHAR defined
then
    if
        00DF: actor $PLAYER_ACTOR driving
    then
        0390: load_txd_dictionary 'vcspd'
        038F: load_texture 'dial' as 11
        038F: load_texture 'hub' as 12
        jump @MAIN
    end
end
jump @WAIT_FOR_CAR

:MAIN
wait 0

if
    0256: player $PLAYER_CHAR defined
then
    if
        00DF: actor $PLAYER_ACTOR driving
    then

        // Read screen resolution
        0A8D: 11@ = read_memory 0x9B48DC size 4 virtual_protect 0
        0A8D: 12@ = read_memory 0x9B48E0 size 4 virtual_protect 0

        if and
            11@ > 0
            12@ > 0
        then

            // Convert resolution
            0093: 13@ = integer 11@ to_float
            0093: 14@ = integer 12@ to_float

            // Scale factor
            0087: 15@ = 14@
            15@ /= 1080.0

            // Dial center X
            10@ = 190.0
            006B: 10@ *= 15@
            0063: 13@ -= 10@

            // Dial center Y
            10@ = 185.0
            006B: 10@ *= 15@
            0063: 14@ -= 10@

            // Vehicle speed
            03C0: 0@ = actor $PLAYER_ACTOR car
            02E3: 1@ = car 0@ speed
            1@ *= 3.6

            if
                1@ > 200.0
            then
                1@ = 200.0
            end

            // Needle smoothing
            0087: 10@ = 1@
            0063: 10@ -= 9@
            10@ *= 0.05
            005B: 9@ += 10@

            // Needle angle
            0087: 2@ = 9@
            2@ *= 1.35
            2@ -= 135.0

            // Scaled dial diameter
            11@ = 260.0
            006B: 11@ *= 15@

            // Draw dial
            03F0: enable_text_draw 1
            038D: draw_texture 11 position 13@ 14@ scale 11@ 11@ RGBA 255 255 255 255

            // Needle direction
            02F6: 3@ = sine 2@
            02F7: 4@ = cosine 2@

            3@ *= 2.0
            4@ *= -2.0

            006B: 3@ *= 15@
            006B: 4@ *= 15@

            0087: 5@ = 13@
            0087: 6@ = 14@

            005B: 5@ += 3@
            005B: 5@ += 3@
            005B: 5@ += 3@

            005B: 6@ += 4@
            005B: 6@ += 4@
            005B: 6@ += 4@

            // Scaled needle thickness
            7@ = 3
            8@ = 6.85
            006B: 8@ *= 15@

            12@ = 0.05
            006B: 12@ *= 15@

            :NEEDLE_LOOP

            038E: draw_rectangle position 5@ 6@ size 8@ 8@ RGBA 244 156 215 255

            0063: 8@ -= 12@

            005B: 5@ += 3@
            005B: 6@ += 4@

            7@ += 1

            if
                7@ < 55
            then
                jump @NEEDLE_LOOP
            end

            // Scaled hub diameter
            11@ = 20.0
            006B: 11@ *= 15@

            // Draw central hub
            038D: draw_texture 12 position 13@ 14@ scale 11@ 11@ RGBA 255 255 255 255

        end
    end
end

jump @MAIN
