Jesus4Lyf
Good Idea™
- Reaction score
- 397
MapLock
Version 1.0
Requirements:
- Jass NewGen
Description:
Locks your map so it can't be edited (as easily) by hackers.
North:
JASS:
South:
JASS:
scope MapLockSouth initializer CheckLock
globals
private constant boolean LOCKED=false
private constant integer KEY=0x96E0000
private constant integer KEYDEPTH=0x10000000 // Add/remove 0's to change key's max length.
//****************************************************
private string array TOCHAR
endglobals
private function InitTOCHAR takes nothing returns nothing
set TOCHAR[0]="0"
set TOCHAR[1]="1"
set TOCHAR[2]="2"
set TOCHAR[3]="3"
set TOCHAR[4]="4"
set TOCHAR[5]="5"
set TOCHAR[6]="6"
set TOCHAR[7]="7"
set TOCHAR[8]="8"
set TOCHAR[9]="9"
set TOCHAR[10]="A"
set TOCHAR[11]="B"
set TOCHAR[12]="C"
set TOCHAR[13]="D"
set TOCHAR[14]="E"
set TOCHAR[15]="F"
endfunction
private function ToHex takes integer i returns string
local integer r
local string result=""
call InitTOCHAR()
loop
exitwhen i==0
set r=i-(i/16)*16
set result=TOCHAR[r]+result
set i=(i-r)/16
endloop
return "0x"+result
endfunction
private function C2I takes code f returns integer
return f
return 0
endfunction
private function GetKey takes code f returns integer
local integer key=C2I(f)-MapLockNorth_GetIndex()
return key-(key/KEYDEPTH)*KEYDEPTH
endfunction
private function FatalError takes nothing returns nothing
call C2I(function IsNoVictoryCheat) // Fatal error, gg.
endfunction
private function CheckLock takes nothing returns nothing
if LOCKED then
if GetKey(function CheckLock)!=KEY then
call FatalError()
endif
else
call BJDebugMsg("Key: "+ToHex(GetKey(function CheckLock)))
endif
endfunction
endscope
Explanation:
Put MapLockNorth as the first thing in your map, and MapLockSouth as the last. All your map code goes in between them. Think of them like magnets. In the field between them they generate a protection whereby if anything is changed, the map will crash with a fatal error.
Simply set LOCKED to false while working on the map. Hitting test map will display the map's KEY value. When you wish to lock the map, simply run the map, note the KEY, change the KEY constant to whatever it says, and change LOCKED to true.
If you wish to use the optimizer with this, you must optimize the map before getting the KEY, as the optimizer changes the code of the map.
Updates:
Version 1.0 - Release.