• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Desync checker for JASS snippets

Status
Not open for further replies.

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
Here is a tool which regulars of our IRC channel might already have heard about;
a tool to check jass snippets for potential desync causing programming constructs.
And i mean snippets as unfortunately this tool is quite slow. So it doesn't work on
your whole war3map.j. I would recommend to not feed it more than ~1000 SLOC.
Sadly i have not enough time (=money) to make this faster, even though the
usefullness of this is greatly dimished by not being able to be run over the whole map.
Still i think it's better to release this as is instead of sitting on it without any use.

Demo


JASS:
// Snippet from Blizzard.j prior to 1.31. Fixed in latest patch

function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, GetCameraTargetPositionLoc())
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
            // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
            // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
            // User is close enough, so don't touch the camera.
        endif
    endif
endfunction

Code:
$ desync-check snippet-bj.j
Unsafe usage in line 9
   set dist = DistanceBetweenPoints(loc,GetCameraTargetPositionLoc()) //4

Togehter with the executable are three text files named "async.txt",
"unsafe.txt" and "paramsafe.txt".
Each file contains a list of natives/functions which have special properties.
  • async.txt: natives/functions which may return different values for different players
  • unsafe.txt: natives/functions which should never be called in an async context
  • paramsafe.txt: natives/functions which can under certain circumstances be called in an async context (see below)

These lists are very likely to not be exhaustive, so feel free to expand them.

Demo for paramsafe functions


While we know that AddSpecialEffect cannot be blindly used to create an effect locally
we have found this way to do it:
JASS:
function CreateLocalEffect takes player p, string path, real x, real y returns nothing
    if p != GetLocalPlayer() then
        set path = ""
    endif
    call AddSpecialEffect(path, x, y)
endfunction
Code:
$ ./desync-check snippet-sfx-fixed.j

In contrast this will throw an error
JASS:
function CreateLocalEffect takes player p, string path, real x, real y returns nothing
    if p == GetLocalPlayer() then
        call AddSpecialEffect(path, x, y)
    endif
endfunction
Code:
$ ./desync-check snippet-sfx.j
Unsafe usage in line 4
   call AddSpecialEffect(path,x,y) //4


And while all the snippets i've shown here are all bound to one function body
this tool will work over multiple function calls.
On another note while this only works for JASS the general ideas can be very well
ported to Lua if one had the time.
 

Attachments

  • desync-check.zip
    2.2 MB · Views: 180
Last edited:

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
Does it only check for GetLocalPlayer calls (made directly, or from natives) ? Or also other potential causes ? :)
All the information the tool has is in the three provided .txt-files and the script you feed it. If you use unsafe Blizzard.j functions you should declare them or provide their source code.
And it uses any function in async.txt to check potential desyncs (GetLocalPlayer is one of them).
 
All the information the tool has is in the three provided .txt-files and the script you feed it. If you use unsafe Blizzard.j functions you should declare them or provide their source code.
And it uses any function in async.txt to check potential desyncs (GetLocalPlayer is one of them).

Thanks I'll check in details then.
Also I discovered that (you probably never encountered the case) the tool stops with an error when it encounters an escaped quote sign in a string. Example: "\"World Editor\"" :)

upload_2019-9-6_19-47-49.png
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
Thanks I'll check in details then.
Also I discovered that (you probably never encountered the case) the tool stops with an error when it encounters an escaped quote sign in a string. Example: "\"World Editor\"" :)

View attachment 332266
Should be fixed now. It now should also not bail on native declarations.
 
Status
Not open for further replies.
Top