1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  4. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  5. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  6. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  7. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Desync checker for JASS snippets

Discussion in 'Warcraft Editing Tools' started by LeP, Sep 5, 2019.

  1. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    445
    Resources:
    0
    Resources:
    0
    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



    Code (vJASS):

    // 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 (Text):

    $ 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:
    Code (vJASS):

    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 (Text):

    $ ./desync-check snippet-sfx-fixed.j
     
    In contrast this will throw an error
    Code (vJASS):

    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 (Text):

    $ ./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.
     

    Attached Files:

    Last edited: Sep 7, 2019
  2. Ricola3D

    Ricola3D

    Joined:
    Feb 27, 2019
    Messages:
    175
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Does it only check for GetLocalPlayer calls (made directly, or from natives) ? Or also other potential causes ? :)
     
  3. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    445
    Resources:
    0
    Resources:
    0
    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).
     
  4. Ricola3D

    Ricola3D

    Joined:
    Feb 27, 2019
    Messages:
    175
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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
     
  5. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    445
    Resources:
    0
    Resources:
    0
    Should be fixed now. It now should also not bail on native declarations.