VrS (Variant realities Script) — File Browser

VrSVariantrealitiesScriptv2.0 / VrSVariantrealitiesScriptv2.0 / VrS / System / Core / vlib.mrc

vlib.mrc — 25.31 KB — Download this file

alias vConsole {
  !window -aeBk0 +d @vConsole 0 0 $window(-3).dw $window(-3).dh
  vecho Right-click to add/remove this window from the switchbar.
  vecho F12 will drop this window down, and F12 again will hide it. Shift-F12 to clear.
}

menu @vConsole {
  $iif($hget(vSwitch,List.@vConsole),Remove window from switchbar,Add window to switchbar): {
    if ($hget(vSwitch,List.@vConsole)) { vS.RemWindow @vConsole }
    else { vS.AddWindow @vConsole }
  }
}

on *:input:@vConsole: { vecho ]] $1- }
on *:close:@vConsole: { .timer 1 0 ReOpenvConsole $iif($hget(vSwitch,List.@vConsole),Yes,No) $window(@vConsole).x $window(@vConsole).y $window(@vConsole).w $window(@vConsole).h }
alias -l ReOpenvConsole { vConsole $2- | if ($1 == Yes) { vS.AddWindow @vConsole } }
alias f12 { 
  if ($window(@vConsole).h == 0) { vConsole.DropDown $iif($mouse.key & 4,Full,Half) | !window -a @vConsole }
  else { 
    vConsole.DropUp 
    if ($window($hget(vSwitch,Active)).state != hidden) && ($window($hget(vSwitch,Active))) { !window -a $hget(vSwitch,Active) }
  }
}
alias vConsole.DropUp {
  var %Total = 60, %Counter = %Total, %H = $window(@vConsole).h, %i = $int($calc(%H / %Total))
  while (%Counter > 0) { 
    !window @vConsole 0 0 $window(-3).dw $calc(%Counter * %i)
    dec %Counter
  }
  !window @vConsole 0 0 $window(-3).dw 0
}
;Syntax: /vConsole.DropDown <Half|Full>
alias vConsole.DropDown {
  !window -a @vConsole
  var %Counter = 0, %Total = 60, %H = $iif($1 == Half,$int($calc($window(-3).dh / 2)),$window(-3).dh), %i = $int($calc(%H / %Total))
  while (%Counter < %Total) { 
    !window @vConsole 0 0 $window(-3).dw $calc(%Counter * %i)
    inc %Counter
  }
  !window @vConsole 0 0 $window(-3).dw %H
}

on *:signal:start.3: { !window -a @vConsole | vConsole.DropUp }

alias sf12 { clear @vConsole }
alias f2 { clear $active }
alias -l vConsoleUpdate {
  if ($line(Status Window,1) != $null) && ($window(@vConsole)) {
    filter -swp @vConsole
    clear Status window
  }
}
alias vDebug { vConsole }
alias vecho { if ($window(@vConsole)) { echo @vConsole $1- } }




;Temporary aliases until Khaled fixes the /hinc and /hdec bugs
alias hinc { hadd $1 $2 $calc($hget($1,$2) + $iif($3,$3,1)) }
alias hdec { hadd $1 $2 $calc($hget($1,$2) - $iif($3,$3,1)) }
alias asc { echo -a $asc($1) }


alias SEcho {
  ; Syntax: /SEcho <Command name> <Syntax>
  set -u %::Command $1
  set -u %::Params $2-
  set -u %:echo vMI.NEcho -tai2 | theme.text SyntaxEcho
}
alias EEcho {
  ; Syntax: /EEcho <Command name> <Description of Error>
  set -u %::Command $1
  set -u %::Params $2-
  set -u %:echo vMI.NEcho -tai2 | theme.text ErrorEcho
}
alias IEcho {
  ; Syntax: /IEcho <Info>
  set -u %::Text $1-
  set -u %:echo vMI.NEcho -tai2 | theme.text InfoEcho
}

alias Core.Titlebar {
  if ($1 == Text) { vBin settitle 0 mIRC/VrS $chr(91) $1- $chr(93) $chr(91) Time: $vtime $chr(93) $chr(91) $vrs(release) $vrs(version) $chr(93) }
  else {
    if ($1 == $null) {
      var %titletext = $gettok($gettok($vBin(gettitle,0),2-,32),1,93) | %titletext = $gettok(%titletext,1,91)
    }
    elseif ($1 == Update) {
      if ($sock(vMI.*,0) < 1) { var %Connections = No IRC Network Connections }
      elseif ($sock(vMI.*,0) == 1) { var %Connections = 1 IRC Network Connection }
      else { var %Connections = Connected to $sock(vMI.*,0) IRC Networks }
      var %titletext User: $vUser - %Connections
    }
    vBin settitle 0 mIRC/VrS $chr(91) %titletext $chr(93) $chr(91) Time: $vtime $chr(93) $chr(91) $vrs(release) $vrs(version) $chr(93) 
  }
}
on *:signal:Timer: { Core.Titlebar Update | vConsoleUpdate }

alias vtime {
  if ($gettok($time,1,58) == 00) { return 12 $+ : $+ $gettok($time,2,58) $+ . $+ $gettok($time,3,58) AM }
  elseif ($gettok($time,1,58) < 12) { return $gettok($time,1-2,58) $+ . $+ $gettok($time,3,58) AM }
  elseif ($gettok($time,1,58) == 12) { return $gettok($time,1-2,58) $+ . $+ $gettok($time,3,58) PM }
  else { return $calc($gettok($time,1,58) - 12) $+ : $+ $gettok($time,2,58) $+ . $+ $gettok($time,3,58) PM }
}

alias Core.SplashWin {
  if ($1 == $null) || ($window(@VirsciS) == $null) {
    .splay $vrsdir(System\Core\Media\startup.wav)
    var %sizex = $pic($vrsdir(System\Core\Media\VrS.png)).width 
    var %sizey = $pic($vrsdir(System\Core\Media\VrS.png)).height
    var %placex = $calc(($window(-1).w / 2) - (%sizex / 2))
    var %placey = $calc(($window(-1).h / 2) - (%sizey / 2))
    !window -Bodpk0nh +bdL @VirsciS %placex %placey %sizex %sizey
    drawpic -c @VirsciS 0 0 $vrsdir(System\Core\Media\VrS.png)
    drawtext -nr @VirsciS $rgb(0,0,0) "Tahoma" 11 $calc(386 - $width($vrs(version),Tahoma,11,0,0)) 32 $vrs(version)
    drawdot @VirsciS
    !window -a @VirsciS
    .timerCloseVrSWindow 1 0 Core.SplashWin.Close
  }
  if ($1- != $null) { 
    drawpic -nc @VirsciS 32 71 32 71 351 15 $vrsdir(System\Core\Media\VrS.png)
    drawtext -ncr @VirsciS $rgb(0,0,0) Tahoma 12 33 71 348 15 $$1-
    drawdot @VirsciS
  }
}

alias Core.SplashWin.Close {
  .signal -n start.user
  if (!%Core.NoMircShow) { showmirc -s }
  !window -c @VirsciS
  unset %Core.NoMircShow
}


alias deltree {
  var %d = $+(",$1-,"), %i = 1, %t = $findfile(%d,*,0)
  while (%i <= %t) { .remove $+(",$findfile(%d,*,1),") | inc %i }
  var %t = $finddir(%d,*,0), %i = %t
  while (%i > 0) { .rmdir $+(",$finddir(%d,*,%i),") | dec %i }
  .rmdir %d
}

alias vLib.WinPosition {
  if ($isid) { return $vReg(U,WinPosition,$1) }
  else { vReg U WinPosition $1 $iif($2-,$2-,$window($1).x $window($1).y $window($1).w $window($1).h) }
}

; Syntax: /hvar <var name> <Data>
alias hvar {
  if ($isid == $true) { return $hget(HVar,$1) }
  else { 
    if ($2 != $null) { hadd HVar $1 $2- }
    else { hdel HVar $1 }
  }
}
; Syntax: /hunset <var name>
alias hunset {
  var %counter = 1
  while (%counter <= $numtok($1-,32)) {
    hdel -w HVar $gettok($1-,%counter,32)
    inc %counter
  }
}

alias dlldir { return $+(",$mircdir,System\Core\DLLs\,$1-,") }

;------------------HTTP file get-------------------

;Syntax: /httpget site.com/file
;Extremely simple file downloader.
alias httpget { vLib.HTTPGet $gettok($1,1,47) 80 Unknown $+(/,$gettok($1,2-,47)) $+($mircdir,Temp\,$nopath($1)) }

; Syntax: /vLib.HTTPGet <Address> <Port> <Size> <Filename> <SaveTo>
alias vLib.HTTPGet {
  if ($left($1,1) == -) { var %Options = $1 | tokenize 32 $2- }
  var %vLib.Sock = $+(vLib.ReceiveHTTP.,$1,.,$2)
  var %vLib.Mark = $1 $3 0 $ctime $4 Header $5-
  sockopen %vLib.Sock $1 $2
  sockmark %vLib.Sock %vLib.Mark
  .remove $+(",$5-,")
}
on 1:sockopen:vLib.ReceiveHTTP.*: {
  if ($sockerr > 0) { .signal -n vLib.HTTPFail $sockname | return }
  sockwrite -n $sockname GET $gettok($sock($sockname).mark,5,32) HTTP/1.0
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname Host: $gettok($sock($sockname).mark,1,32)
  sockwrite -n $sockname $crlf
  sockmark $sockname $gettok($sock($sockname).mark,1-3,32) $ctime $gettok($sock($sockname).mark,5-,32)
  .signal -n vLib.HTTPChecking $sockname
}
on 1:sockread:vLib.ReceiveHTTP.*: {
  :start
  if ($gettok($sock($sockname).mark,6,32) == File) {
    ;File receiving
    if (%Skip != 1) { bunset &vLib.Data | sockread &vLib.Data }
    var %Skip
    if ($sockbr > 0) {
      bwrite $+(",$gettok($sock($sockname).mark,7-,32),") -1 -1 &vLib.Data
      vLib.HTTP.IncMark $sockname $bvar(&vLib.Data,0)
      .signal -n vLib.HTTPProgress $sockname $gettok($sock($sockname).mark,3,32) $gettok($sock($sockname).mark,2,32)
      if ($gettok($sock($sockname).mark,3,32) == $gettok($sock($sockname).mark,2,32)) { 
        .signal -n vLib.HTTPRcvd $sockname $gettok($sock($sockname).mark,1-2,32) $gettok($sock($sockname).mark,5-,32)
        sockclose $sockname
        return
      }
      goto start
    }
  }
  else {
    ;Header
    var %vLib.Data
    sockread %vLib.Data
    if ($sockbr > 0) {
      ;Switch to file mode
      if (%vLib.Data == $null) { 
        sockmark $sockname $gettok($sock($sockname).mark,1-3,32) $ticks $gettok($sock($sockname).mark,5,32) File $gettok($sock($sockname).mark,7-,32)
        .signal -n vLib.HTTPStart $sockname $gettok($sock($sockname).mark,1-2,32) $gettok($sock($sockname).mark,5-,32)
      }
      elseif ($left(%vLib.Data,15) == Content-Length:) { sockmark $sockname $gettok($sock($sockname).mark,1,32) $gettok(%vLib.Data,2,32) $gettok($sock($sockname).mark,3,32) $ctime $gettok($sock($sockname).mark,5-,32) }
      elseif ($gettok(%vLib.Data,1-2,32) == HTTP/1.1 404) || ($gettok(%vLib.Data,1-2,32) == HTTP/1.0 404) {
        .signal -n vLib.HTTPFail $sockname 404 $gettok($sock($sockname).mark,1-2,32) $gettok($sock($sockname).mark,5-,32)
        sockclose $sockname
        return
      }
      goto start
    }
  }
}
on 1:sockclose:vLib.ReceiveHTTP.*: {
  if ($sockerr > 0) { .signal -n vLib.HTTPFail $sockname | return }
  if ($gettok($sock($sockname).mark,3,32) == $gettok($sock($sockname).mark,2,32)) || ($gettok($sock($sockname).mark,2,32) == Unknown) { .signal -n vLib.HTTPRcvd $sockname $gettok($sock($sockname).mark,1-2,32) $gettok($sock($sockname).mark,5-,32) }
  else { .signal -n vLib.HTTPFail $sockname }
  if ($gettok($sock($sockname).mark,2,32) == Unknown) { sockmark $sockname $gettok($sock($sockname).mark,1,32) $gettok($sock($sockname).mark,3,32) $gettok($sock($sockname).mark,3,32) $gettok($sock($sockname).mark,4,32) $gettok($sock($sockname).mark,5-,32) }
}
; Syntax: /vLib.HTTP.IncMark <Sockname> <Increment size>
alias vLib.HTTP.IncMark { sockmark $1 $gettok($sock($1).mark,1,32) $gettok($sock($1).mark,2,32) $calc($gettok($sock($1).mark,3,32) + $2) $gettok($sock($1).mark,4,32) $gettok($sock($1).mark,5-,32) }



alias showsocks {
  var %counter = 1
  while (%counter <= $sock(*,0)) {
    echo -a 14[12 $+ %counter $+ 14] 14N: $+ $sock(*,%counter).name 14P:99,99 $+ $sock(*,%counter).port 14M:99,99 $+ $sock(*,%counter).mark
    inc %counter
  }
}

alias vbin { 
  if (!$isid) { dll $dlldir(vbin.dll) $1- }
  else { return $dll($dlldir(vbin.dll),$1,$2) }
}
alias mkpath {
  var %counter = 1
  while (%counter <= $numtok($1-,92)) {
    if (!$isdir($gettok($1-,$+(1-,%counter),92))) { mkdir $+(",$gettok($1-,$+(1-,%counter),92),") }
    inc %counter
  }
}
alias noext { return $gettok($1-,$+(1-,$calc($numtok($1-,46) - 1)),46) }
alias vrsdir {
  if ($prop == $null) { return $+(",$mircdir,$iif($left($1,1) == \,$right($1-,-1),$1-),") }
  else { return $+($mircdir,$iif($left($1,1) == \,$right($1-,-1),$1-)) }
}

;Syntax: /loadbufhash [-pi] [Prefix] <Hash table> <Section> <File>
alias loadbufhash {
  if ($left($1,1) == -) { var %Options = $1 | tokenize 32 $2- }
  if (p isin %Options) { var %Prefix = $1 | tokenize 32 $2- }
  if (!$ini($3-,$2)) { return }
  !window -h @loadbufhash
  loadbuf $+(-t,$2) @loadbufhash $+(",$3-,")
  var %Total = $line(@loadbufhash,0), %Counter = 1, %Line, %Chr = $iif(i !isin %Options,32,61)
  while (%Counter <= %Total) {
    %Line = $line(@loadbufhash,%Counter)
    if ($left(%Line,1) != $chr(59)) && ($remove(%Line,$chr(32)) != $null) { hadd $1 $+(%Prefix,$gettok(%Line,1,%Chr)) $gettok(%Line,2-,%Chr) }
    inc %Counter
  }
  !window -c @loadbufhash
}





;----vReg----

; Syntax: /vReg.Load <User|Global|Default>
alias vReg.Load {
  if ($hget($+(vReg.,$1)) == $null) { hmake $+(vReg.,$1) 50 }
  if ($1 == Global) { loadbufhash $+(vReg.,$1) vReg $+($mircdir,Settings\Global.srg) }
  elseif ($1 == Default) { loadbufhash $+(vReg.,$1) vReg $+($mircdir,Settings\Default.srg) }
  elseif ($1 == User) && ($vUser) { loadbufhash $+(vReg.,$1) vReg $+($mircdir,Settings\,$vUser,.vrg) }
}


; Syntax: /vReg.Save <User|Global|Default>
alias vReg.Save {
  if ($hget( vReg. [ $+ [ $1 ] ] )) { 
    if ($1 == Global) { 
      var %Counter = 1
      write -c Settings\Global.srg
      write Settings\Global.srg [vReg]
      while (%Counter <= $hget(vReg.Global,0).item) {
        write Settings\Global.srg $hget(vReg.Global,%Counter).item $hget(vReg.Global,$hget(vReg.Global,%Counter).item)
        inc %Counter
      }
    }
    elseif ($1 == Default) { 
      var %Counter = 1
      write -c Settings\Default.srg
      write Settings\Default.srg [vReg]
      while (%Counter <= $hget(vReg.Default,0).item) {
        write Settings\Default.srg $hget(vReg.Default,%Counter).item $hget(vReg.Default,$hget(vReg.Default,%Counter).item)
        inc %Counter
      }
    }
    elseif ($1 == User) && ($vUser) { 
      var %Counter = 1
      write -c $+(Settings\,$vUser,.vrg)
      write $+(Settings\,$vUser,.vrg) [vReg]
      while (%Counter <= $hget(vReg.User,0).item) {
        write $+(Settings\,$vUser,.vrg) $hget(vReg.User,%Counter).item $hget(vReg.User,$hget(vReg.User,%Counter).item)
        inc %Counter
      }
    }
  }
}

alias vReg.LoadAll { vReg.Load User | vReg.Load Global | vReg.Load Default }
alias vReg.SaveAll { vReg.Save User | vReg.Save Global | vReg.Save Default }


;To set the data: /vReg <User|Global|Default> <Section> <Item> <Data>
;To remove data: /vReg <User|Global|Default> <Section> <Item>
;To get data: $vReg(<User|Global|Default>,<Section>,<Item>)
;If a setting does not exist in the User's hash table when using $vReg(), it
;will be pulled from the Default hash table and written into
;the users's hash table under the same name.
;You can leave off the rest of the word on User Global and Default, ie, you can
;use U, G, or D, for brevity.
alias vReg {
  if ($left($1,1) == U) {
    if ($isid == $true) {
      if ($hget(vReg.User,$+($2,.,$3)) != $null) { return $hget(vReg.User,$+($2,.,$3)) }
      elseif ($hget(vReg.Default,$+($2,.,$3)) != $null) { hadd vReg.User $+($2,.,$3) $hget(vReg.Default,$+($2,.,$3)) | return $hget(vReg.User,$+($2,.,$3)) }
    }
    else {
      if ($4 != $null) { hadd vReg.User $+($2,.,$3) $4- }
      else { hdel -w vReg.User $+($2,.,$3) }
    }
  }
  elseif ($left($1,1) == D) {
    if ($isid == $true) {
      if ($hget(vReg.Default,$+($2,.,$3)) != $null) { return $hget(vReg.Default,$+($2,.,$3)) }
    }
    else {
      if ($4 != $null) { hadd vReg.Default $+($2,.,$3) $4- }
      else { hdel -w vReg.Default $+($2,.,$3) }
    }
  }
  elseif ($left($1,1) == G) {
    if ($isid == $true) {
      if ($hget(vReg.Global,$+($2,.,$3)) != $null) { return $hget(vReg.Global,$+($2,.,$3)) }
    }
    else {
      if ($4 != $null) { hadd vReg.Global $+($2,.,$3) $4- }
      else { hdel -w vReg.Global $+($2,.,$3) }
    }
  }
}


;----vPak----

alias vPak {
  if ($left($1,1) == -) { var %Options = $1 | tokenize 32 $2- }
  if (e isin %Options) { var %FileIDs = $1 | tokenize 32 $2- }
  if (l isin %Options) { var %ListDest = $1 | tokenize 32 $2- }
  ;Parse command line for long filenames
  if (" isin $1-) { tokenize 34 $1- | set -u %vPakFile $1 | set -u %vPakPath $3 }
  else { set -u %vPakFile $1 | set -u %vPakPath $2- }
  if (!%vPakPath) && (!%Options) && (%vPakFile) { 
    if (\ !isin %vPakFile) { set -u %vPakFile $+($mircdir,%vPakFile) }
    vPakG %vPakFile
    return
  }
  elseif (!%vPakPath) && (l !isin %Options) && (h !isin %Options) {
    if (!$1) { vPakG | return }
    Display vPak Syntax: /vPak [-puzdlehn] [File ID table] [Window|Hashtable] [filename.vpk] [Path] | return
  }
  if (\ !isin %vPakFile) { set -u %vPakFile $+($mircdir,%vPakFile) }
  if (\ !isin %vPakPath) { set -u %vPakPath $+($mircdir,%vPakPath) }
  if ($right(%vPakPath,1) != \) { set -u %vPakPath $+(%vPakPath,\) }
  if (p isin %Options) {
    ;Pack files up
    Display vPak: Working...
    if (h !isin %Options) { 
      if (!$isdir(%vPakPath)) { Display vPak Error: No such directory %vPakPath | return }
      CreateList %vPakPath
    }
    ;File version is not used yet - it will be used if options are added to vPak files.
    var %FilePos = 20, %vPakFileVersion = 1.0
    .remove $+(",%vPakFile,")
    btrunc $+(",%vPakFile,") 20
    if ($hget(vPakFileList)) { hfree vPakFileList } | hmake vPakFileList 20
    var %Counter = 1
    mkpath $nofile(%vPakFile)
    ;Add files to the vPak archive, and create a new list with file locations
    while (%Counter <= $hget(vPakList,Total)) {
      hadd vPakFileList %Counter $iif($gettok($hget(vPakList,%Counter),1,32) != DIR,%FilePos) $gettok($hget(vPakList,%Counter),1,32) $gettok($hget(vPakList,%Counter),2-,32)
      if ($gettok($hget(vPakList,%Counter),1,32) != DIR) { 
        AddFile %FilePos $gettok($hget(vPakList,%Counter),1,32) $+($hget(vPakList,Parent),\,$gettok($hget(vPakList,%Counter),2-,32))
        inc %FilePos $gettok($hget(vPakList,%Counter),1,32)
      }
      inc %Counter
    }
    ;Write file list to the end of the file, and the position of the start of the list to the beginning.
    WriteFileList %FilePos
    Display vPak: Created %vPakFile
    if (z isin %Options) {
      var %DLL = $dll($dlldir(ngzipn.dll),zip,%vPakFile) | Display vPak: Compressed $nopath(%vPakFile) file to: $nopath($+(%vPakFile,.gz))
      if (d isin %Options) { .remove $+(",%vPakFile,") | Display vPak: Removed $nopath(%vPakFile) }
    }
  }
  elseif (u isin %Options) || (l isin %Options) || (e isin %Options) {
    if ($right(%vPakFile,3) == .gz) { set -u %vPakFile $left(%vPakFile,-3) }
    if (z isin %Options) {
      if (!$isfile($+(%vPakFile,.gz))) { Display vPak Error: The gzipped file could not be found. | return }
      var %DLL = $dll($dlldir(ngzipn.dll),unzip,%vPakFile) | Display vPak: Decompressed $nopath($+(%vPakFile,.gz)) file to: $nopath(%vPakFile)
    }
    if (!$isfile(%vPakFile)) { Display vPak Error: No such file %vPakFile | return }
    if (u isin %Options) {
      Display vPak: Working...
      var %Total = $ExtractFileList, %Counter = 1, %Line
      if (%Total == BadFile) { Display vPak Error: %vPakFile can not be opened because it is an old format. | return BadFile }
      while (%Counter <= %Total) {
        %Line = $hget(vPakFileList,%Counter)
        if ($gettok(%Line,1,32) == DIR) { if (n !isin %Options) { mkpath $+(%vPakPath,$gettok(%Line,2-,32)) } }
        else { mkpath $nofile($+(%vPakPath,$iif(n !isin %Options,$gettok(%Line,3-,32),$nopath($gettok(%Line,3-,32))))) | ExtractFile $gettok(%Line,1-2,32) $+(%vPakPath,$iif(n !isin %Options,$gettok(%Line,3-,32),$nopath($gettok(%Line,3-,32)))) }
        if ($dialog(vPak)) { vPakG.Update %Counter %Total }
        inc %Counter
      }
      Display vPak: Extracted all files from %vPakFile to %vPakPath
    }
    elseif (l isin %Options) {
      if ($left(%ListDest,1) == @) && (!$window(%ListDest)) { Display vPak Error: No such window %ListDest | return }
      elseif ($left(%ListDest,1) != @) && (!$hget(%ListDest)) { Display vPak Error: No such hash table %ListDest | return }
      if ($left(%ListDest,1) == @) { var %Add = aline -l %ListDest }
      else { var %Add = hadd %ListDest }
      var %Total = $ExtractFileList, %Counter = 1, %Line
      if (%Total == BadFile) { Display vPak Error: %vPakFile can not be opened because it is an old format. | return BadFile }
      while (%Counter <= %Total) {
        %Line = $hget(vPakFileList,%Counter)
        %Add $iif($gettok(%Add,1,32) == hadd,%Counter) $iif($gettok(%Line,1,32) == DIR,DIR $gettok(%Line,2-,32),$gettok(%Line,2,32) $gettok(%Line,3-,32))
        inc %Counter
      }
      Display vPak: Extracted file list to %ListDest $iif($gettok(%Add,1,32) == hadd,hash table.,window.)
    }
    elseif (e isin %Options) {
      Display vPak: Working...
      var %Total = $ExtractFileList,%TotalIDs = $hget(%FileIDs,0).item,%Counter = 1
      if (%Total == BadFile) { Display vPak Error: %vPakFile can not be opened because it is an old format. | return BadFile }
      while (%Counter <= %TotalIDs) {
        %Line = $hget(vPakFileList,$hget(%FileIDs,%Counter))
        if ($gettok(%Line,1,32) == DIR) { if (n !isin %Options) { mkpath $+(%vPakPath,$gettok(%Line,2-,32)) } }
        else { mkpath $nofile($+(%vPakPath,$iif(n !isin %Options,$gettok(%Line,3-,32),$nopath($gettok(%Line,3-,32))))) | ExtractFile $gettok(%Line,1-2,32) $+(%vPakPath,$iif(n !isin %Options,$gettok(%Line,3-,32),$nopath($gettok(%Line,3-,32)))) }
        if ($dialog(vPak)) { vPakG.Update %Counter %TotalIDs }
        inc %Counter
      }
      Display vPak: Extracted file IDs from hash table %FileIDs to %vPakPath
    }
    if (d isin %Options) { .remove $+(",%vPakFile,") | Display vPak: Removed $nopath(%vPakFile) }
  }
  hfree -w vPak*
}

alias -l h2d {
  ;hex2dec function
  var %Text, %Counter = 1
  while (%Counter <= $len($1)) { %Text = %Text $base($mid($1,%Counter,2),16,10,2) | inc %Counter 2 }
  return %Text
}
alias -l d2h {
  ;dec2hex function
  var %Text, %Counter = 1
  while (%Counter <= $numtok($1,32)) { %Text = %Text $base($gettok($1-,%Counter,32),10,16,2) | inc %Counter }
  return $remove(%Text,$chr(32))
}

alias -l ExtractFileList {
  ;Read file list to hash table
  if ($hget(vPakFileList)) { hfree vPakFileList } | hmake vPakFileList 20
  bread $+(",%vPakFile,") 0 20 &Header
  var %FilePos = $base($d2h($bvar(&Header,1,4)),16,10), %FileSize = $file(%vPakFile).size,%Counter = 1,%Len
  if ($bvar(&Header,11,1).text != $vPakFileVersion) { return BadFile }
  while (%FilePos < %FileSize) {
    bread $+(",%vPakFile,") %FilePos 1000 &Data
    %Len = $base($d2h($bvar(&Data,1,2)),16,10)
    hadd vPakFileList %Counter $bvar(&Data,3,%Len).text
    inc %FilePos $calc(%Len + 2)
    inc %Counter
  }
  return $calc(%Counter - 1)
}

alias -l WriteFileList {
  var %FilePos = $1, %vPakVersion = $vPakFileVersion
  bset &FilePos 1 $h2d($base(%FilePos,10,16,8))
  bwrite $+(",%vPakFile,") 0 4 &FilePos
  bwrite $+(",%vPakFile,") 10 1 %vPakVersion
  var %Counter = 1, %Len, %Line
  while (%Counter <= $hget(vPakList,Total)) {
    %Len = $len($hget(vPakFileList,%Counter))
    %Line = $hget(vPakFileList,%Counter)
    bset &Len 1 $h2d($base(%Len,10,16,4))
    bwrite $+(",%vPakFile,") %FilePos 2 &Len
    inc %FilePos 2
    bwrite $+(",%vPakFile,") %FilePos %Len %Line
    inc %FilePos %Len
    inc %Counter
  }
}

;Syntax: /ExtractFile <byte position> <size> <path to file to extract>
alias -l ExtractFile {
  if ($left($1,1) == -) { var %Options = $1 | tokenize 32 $2- }
  var %BytePos = 0,%BytesRead
  btrunc $+(",$3-,") 0
  while (%BytePos < $2) {
    bread $+(",%vPakFile,") $calc($1 + %BytePos) 8192 &Bytes
    %BytesRead = $iif($calc(%BytePos + 8192) < $2,8192,$calc($2 - %BytePos)) 
    bwrite $+(",$3-,") %BytePos %BytesRead &Bytes
    inc %BytePos %BytesRead
  }
}

;Syntax: /AddFile <byte position> <size> <path to file to add>
alias -l AddFile {
  var %BytePos = 0,%BytesRead
  while (%BytePos < $2) {
    bread $+(",$3-,") %BytePos 8192 &Bytes
    %BytesRead = $iif($calc(%BytePos + 8192) < $2,8192,$calc($2 - %BytePos)) 
    bwrite $+(",%vPakFile,") $calc($1 + %BytePos) %BytesRead &Bytes
    inc %BytePos %BytesRead
  }
}

;Syntax: /CreateList <Path>
alias -l CreateList {
  if ($hget(vPakList)) { hfree vPakList } | hmake vPakList 20
  !window -hl @vPakList
  var %ListCounter = 1, %Counter = 1, %Total = $finddir($1-,*,@vPakList)
  while (%Counter <= %Total) {
    var %Line = $line(@vPakList,%Counter,1)
    hadd vPakList %ListCounter DIR $remove(%Line,$1-)
    inc %ListCounter | inc %Counter
  }
  clear -l @vPakList
  var %Counter = 1, %Total = $findfile($1-,*.*,@vPakList)
  while (%Counter <= %Total) { 
    var %Line = $line(@vPakList,%Counter,1)
    hadd vPakList %ListCounter $file(%Line).size $remove(%Line,$1-)
    inc %ListCounter | inc %Counter
  }
  !window -c @vPakList
  hadd vPakList Parent $1-
  hadd vPakList Total $calc(%ListCounter - 1)
}

alias -l mkpath {
  var %counter = 1
  while (%counter <= $numtok($1-,92)) {
    if (!$isdir($gettok($1-,$+(1-,%counter),92))) { mkdir $+(",$gettok($1-,$+(1-,%counter),92),") }
    inc %counter
  }
}
alias -l noext { return $gettok($1-,$+(1-,$calc($numtok($1-,46) - 1)),46) }
alias -l Display {
  if ($mtsversion) { set -u %:echo echo $color(info) -qa | set -u %::text $1- | theme.text Echo }
  else { echo $color(info) -qa *** $1- }
}

alias -l vPakVersion { return 1.2 }
alias -l vPakFileVersion { return 2 }

alias editor {
  if ($1 == -r) { vBin accel 109 }
  elseif ($1 == -a) { vBin accel 107 }
  elseif ($1 == -c) { vBin accel 115 }
  elseif ($1 == -t) { vBin accel 133 }
  elseif ($1 == -o) { vBin accel 102 }
  elseif ($1 == -p) { run explorer $vrsdir(System\Core\Popups\) }
}

alias vrs {
  if ($1 == release) { return 2.0 }
  elseif ($1 == version) { return beta4.897 }
}
alias vrsinfo { return 14[12V02r12S14 version 10 $+ $vrs(release) $vrs(version) 14Copyright 1998-2002 12V02ariant 12R02ealities 14- 12www.variantrealities.com - 10Imagination. Use it as a weapon.14] }

;Syntax: $vEnc(<pass>,<text>)
;Property - decrypt - if used, string will be
;decrypted instead of encrypted.
alias vEnc {
  var %Pass = $$1, %Text = $$2-, %TextLen = $len(%Text), %PassLen = $len(%Pass)
  var %PassCounter = 1, %TextCounter = 1, %NewText, %PassChar, %TextChar, %NewChar
  while (%TextCounter <= %TextLen) {
    %PassChar = $asc($mid(%Pass,%PassCounter,1))
    %TextChar = $asc($mid(%Text,%TextCounter,1))
    if ($prop == $null) { 
      %NewChar = $calc(%PassChar + %TextChar)
      if (%NewChar > 255) { dec %NewChar 255 }
    }
    elseif ($prop == decrypt) { 
      %NewChar = $calc(%TextChar - %PassChar)
      if (%NewChar < 1) { inc %NewChar 255 }
    }
    %NewText = %NewText $+ $iif(%NewChar != 32,$chr(%NewChar)," !sp")
    inc %PassCounter
    if (%PassCounter > %PassLen) { %PassCounter = 1 }
    inc %TextCounter
  }
  return $replace(%NewText," !sp",$chr(32))
}