saw792
Is known to say things. That is all.
- Reaction score
- 280
Hidden Script
I just thought I'd share this snippet I discovered. The demo map below shows how it is possible to hide code within other files in the map. In the example within the map, an admin password has been hidden within the model file imported in the map and retrieved through the use of gamecache.
You can see in the map script that at no stage is the comparison string set, yet when the correct password is typed the matching message appears.
Map Code:
JASS:
scope AdminPassword initializer Init
globals
private gamecache g = InitGameCache("preload.w3v")
endglobals
private function Conditions takes nothing returns boolean
local string s = GetStoredString(g, "password", GetPlayerName(GetTriggerPlayer()))
if GetEventPlayerChatString() == s and s != null then
call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, "|cff00ff00Welcome, admin|r")
else
call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, "|cffff0000Incorrect admin code|r")
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t, Player(0), "-", false)
call TriggerAddCondition(t, Condition(function Conditions))
call Preloader("war3mapimported\\model.mdx")
endfunction
endscope
Code inside 'model' file:
JASS:
globals
gamecache g = InitGameCache("preload.w3v")
endglobals
function main takes nothing returns nothing
call StoreString(g, "password", "WorldEdit", "-password1")
call StoreString(g, "password", "saw792", "-24947341")
endfunction
function PreloadFiles takes nothing returns nothing
call main()
endfunction
The model file within the map is not actually a model file at all, it is just disguised as such. Inside is a simple JASS script. The Preloader() native called from the map script points to this file and automatically executes the PreloadFiles() function within the file. This then saves the password to the gamecache where it can be reloaded within the map script.
Limitations of this method:
Things that can't be used within the hidden script:
BJs
Timers
Triggers
TriggerExecute/Evaluate
TriggerSleepAction
I2S (and R2S I assume)
StringHash (GetHandleId?)
<probably lots more, this is all I have tested>
Things that can be used:
Function calls
Gamecache
Global variables
ExecuteFunc (calls function from the MAIN MAP SCRIPT ONLY, not the hidden script)
CreateUnit
UnitAddAbility
Issuing orders
<probably lots more, this is all I have tested>
BJs
Timers
Triggers
TriggerExecute/Evaluate
TriggerSleepAction
I2S (and R2S I assume)
StringHash (GetHandleId?)
<probably lots more, this is all I have tested>
Things that can be used:
Function calls
Gamecache
Global variables
ExecuteFunc (calls function from the MAIN MAP SCRIPT ONLY, not the hidden script)
CreateUnit
UnitAddAbility
Issuing orders
<probably lots more, this is all I have tested>
Perhaps somebody can find a use for this beyond hiding variable setting and such. As it stands, getting the admin code from my example doesn't actually require you to open the file since you can just modify the map to display the stored string, but I believe that is beside the point right now.
Some Examples of Use:
Inside Map:Inside Script:
This will allow you to set your input command code from outside the script without the use of gamecache. In this example the code is "-792"
JASS:
scope Display initializer Init
globals
private string Code = "-"
endglobals
//! textmacro Code takes NUMBER, INTEGER
function $NUMBER$ takes nothing returns nothing
set Code = Code + I2S($INTEGER$)
endfunction
//! endtextmacro
//! runtextmacro Code("Zero", "0")
//! runtextmacro Code("One", "1")
//! runtextmacro Code("Two", "2")
//! runtextmacro Code("Three", "3")
//! runtextmacro Code("Four", "4")
//! runtextmacro Code("Five", "5")
//! runtextmacro Code("Six", "6")
//! runtextmacro Code("Seven", "7")
//! runtextmacro Code("Eight", "8")
//! runtextmacro Code("Nine", "9")
private function Conds takes nothing returns boolean
return GetEventPlayerChatString() == Code
endfunction
private function Acts takes nothing returns nothing
call BJDebugMsg("Input successful")
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call Preloader("war3mapimported\\model.mdx") //Or whatever the path is
call TriggerRegisterPlayerChatEvent(t, Player(0), "-", false)
call TriggerAddCondition(t, Condition(function Conds))
call TriggerAddAction(t, function Acts)
endfunction
endscope
JASS:
function PreloadFiles takes nothing returns nothing
call ExecuteFunc("Seven")
call ExecuteFunc("Nine")
call ExecuteFunc("Two")
endfunction
This will allow you to set your input command code from outside the script without the use of gamecache. In this example the code is "-792"
Enjoy: