lep / pjass

The famous jass syntax checker.
BSD 2-Clause "Simplified" License
25 stars 6 forks source link

Map protection: mixed CR and LF against editing #11

Open Luashine opened 4 months ago

Luashine commented 4 months ago

I found why you couldn't modify the map before the map has used MIXED line endings, some CR lines, some are LF lines. Because rawcodes sometimes contained LF, you can't just convert the whole file's line endings. But if there's a CR line too long it will crash the game/script. Notepad++ detected the file as CR. I think you can circumvent the detection (LF is preferred, but CRLF works too) if you replace the CR line endings in globals block at the beginning with LF -- notepad++: search and replace & replace in selection only & extended: search \r replace: \n


Now for the pjass: #6 - there I tested converting the whole file to\r and it just crashed the game.

In current case the map protection interchangeably used \r and \n for lines. On one hand \r apparently counts as a line separator for the interpreter, so you can have a two statements with line1\rline2\n. At the same time, the protection used \n too and thus avoided crashing the game like in #6 (too long \r line)

I wanted to document it in some capacity first and foremost. Notepad++ is troublesome if it detects the file as CR because then you can't paste any long code into the map because it will produce a "long CR line" (and in the end cheaters are still not stopped by that...)

pjass does not report any errors, technically it's correct. The game is alright with that. But I think there's a different limit similar to #6 where pjass didn't report me any errors yet but the game parsed the Jass wrongly.

6/22 12:23:21.585 Opening map - C:/Users/shiny/Documents/Warcraft III/Maps/Jassdoc/UpgradeRPG-UnitTest/Upgrade_RPG_7.0G_Reporged Eng-inst.w3x 6/22 12:23:22.326 Map contains invalid Jass scripts that couldn't be compiled by war3, file: war3map.j @ 3378, error: encountered undeclared identifier 'r' on line 3378

This error happened right after I added the following code right after "endglobals" in CR mode using Notepad++:

function CreateUnitLogging takes player p, integer rawcode, real x, real y, real face returns unit
    local unit u
    local integer createdId
    local string unitModel
    local string funcCallString

    set u = CreateUnit(p,rawcode,x,y,face)
    set createdId = GetUnitTypeId(u)
    set funcCallString = "call CreateUnit("+ I2S(GetPlayerId(p)) +","+ I2S(rawcode) +","+R2S(x)+","+R2S(y)+","+R2S(face)+")"

    // patch 1.31.0.11889
    set unitModel = BlzGetUnitStringField(u, ConvertUnitStringField ('umdl'))

    call BJDebugMsg(funcCallString + " & model: '" + unitModel + "'")

    if rawcode != createdId then
        call BJDebugMsg("MISMATCH!!! last unit has id : " + I2S(createdId))
    endif

    // this leaks because we cannot clear and return u at the same time without a global or another function
    return u
endfunction

I will attach the map's blizzard.j and war3map.j (MPQ:scripts/ folder) as compressed zip. Looks like the protection is easy to encounter, at least two versions of Upgrade RPG (Korean) have it. The blizzard.j file is based on 1.24+ version, it has some additions. The Reporged version doesn't need Dz API or anything of that kind and runs on 1.36.2

Upgrade_RPG_7.0G_Reporged Eng.w3x

Scripts.zip


What to do:

  1. Find out the exact limit where this begins to cause problems (after pasting the above code in CR mode)
  2. If possible make pjass warn about mixed CR & LF in a file. Not CRLF but separately used CR and LF. A general once per file warning or if (1) is found an exact error message too. Ah I remember there was a problem with warnings vs errors right? :)