share/hedgewars/Data/Scripts/OfficialChallenges.lua
author Wuzzy <Wuzzy2@mail.ru>
Mon, 19 Nov 2018 00:54:36 +0100
changeset 14231 74bf2d906097
parent 14070 a5be3ef4bbbe
permissions -rw-r--r--
Turn accidental globals to locals in Lua libraries
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13790
552f0d5ab3e7 use locale rules for the challenge hashes
nemo
parents: 13789
diff changeset
     1
HedgewarsScriptLoad("/Scripts/OfficialChallengeHashes.lua")
11542
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
     2
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
     3
-- modified Adler hash
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
     4
local hashA = 0
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
     5
local hashB = 0
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
     6
local hashModule = 299993
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
     7
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
     8
function resetHash()
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
     9
    hashA = 0
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    10
    hashB = 0
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    11
end
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    12
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    13
function addHashData(i)
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    14
    hashA = (hashA + i + 65536) % hashModule
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    15
    hashB = (hashB + hashA) % hashModule
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    16
end
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    17
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    18
function hashDigest()
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    19
    return(hashB * hashModule + hashA)
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    20
end
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    21
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    22
function detectMapWithDigest()
11545
86528b0cd491 detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
unc0rr
parents: 11542
diff changeset
    23
    if RopePercent == 100 and MinesNum == 0 then
14231
74bf2d906097 Turn accidental globals to locals in Lua libraries
Wuzzy <Wuzzy2@mail.ru>
parents: 14070
diff changeset
    24
        local mapString = hashDigest() .. "," .. LandDigest
11545
86528b0cd491 detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
unc0rr
parents: 11542
diff changeset
    25
86528b0cd491 detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
unc0rr
parents: 11542
diff changeset
    26
        if band(GameFlags, gfBorder) ~= 0 then
86528b0cd491 detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
unc0rr
parents: 11542
diff changeset
    27
            mapString = "Border," .. mapString
86528b0cd491 detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
unc0rr
parents: 11542
diff changeset
    28
        end
86528b0cd491 detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
unc0rr
parents: 11542
diff changeset
    29
14070
a5be3ef4bbbe Update official challenge hashes, improve console logging (warning: racer #17 is missing!)
Wuzzy <Wuzzy2@mail.ru>
parents: 13794
diff changeset
    30
        WriteLnToConsole("OfficialChallenges: Hash: "..mapString)
a5be3ef4bbbe Update official challenge hashes, improve console logging (warning: racer #17 is missing!)
Wuzzy <Wuzzy2@mail.ru>
parents: 13794
diff changeset
    31
        local map = official_racer_maps[mapString]
a5be3ef4bbbe Update official challenge hashes, improve console logging (warning: racer #17 is missing!)
Wuzzy <Wuzzy2@mail.ru>
parents: 13794
diff changeset
    32
        if map ~= nil then
a5be3ef4bbbe Update official challenge hashes, improve console logging (warning: racer #17 is missing!)
Wuzzy <Wuzzy2@mail.ru>
parents: 13794
diff changeset
    33
            WriteLnToConsole("OfficialChallenges: Detected official challenge: "..map)
a5be3ef4bbbe Update official challenge hashes, improve console logging (warning: racer #17 is missing!)
Wuzzy <Wuzzy2@mail.ru>
parents: 13794
diff changeset
    34
        end
a5be3ef4bbbe Update official challenge hashes, improve console logging (warning: racer #17 is missing!)
Wuzzy <Wuzzy2@mail.ru>
parents: 13794
diff changeset
    35
        return map
11545
86528b0cd491 detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
unc0rr
parents: 11542
diff changeset
    36
    end
11542
64a5ab2c4f00 Attempt to implement hash for special points to detect tech racer maps
unC0Rr
parents: 11535
diff changeset
    37
end