Advertisement
aveyo

DOTA_LAZY_DEVS_TOGGLE_QUICKCAST

Jun 28th, 2017
1,625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 12.33 KB | None | 0 0
  1. goto="HERO" /*
  2. :"HERO"
  3. @echo off &mode 99,11 &color 4F &title DOTA_TOGGLE_QUICKCAST_ALTERNATIVE_FOR_LAZY_DEVS_NOT_FIXING_WEEKS_OLD_GUI_BUG by AveYo v322
  4. echo. &echo  Workaround seems to work only for Arrow, WASD and Legacy Keys - based presets.
  5. echo  Settings - Reset Hotkeys... to one of those profiles. &echo  Please close DOTA before switching the QuickCast option!
  6. call :set_dota
  7. echo  Last used Steam profile: %STEAMDATA%
  8. set "quickcast=[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');"
  9. set "abilities=[System.Windows.Forms.MessageBox]::Show('Enable QuickCast for abilities?','DOTA LAZY DEVS',4,32);"
  10. set "items=[System.Windows.Forms.MessageBox]::Show('Enable QuickCast for items?','DOTA LAZY DEVS',4,32);"
  11. for /f %%q in ('powershell -c "%quickcast%;%abilities%"') do set "qc_abilities=%%q"
  12. for /f %%q in ('powershell -c "%quickcast%;%items%"') do set "qc_items=%%q"
  13. cscript //E:JScript //nologo "%~f0" EnableQuickCast "%qc_abilities%" "%qc_items%" "%STEAMDATA%\570\remote\cfg\dotakeys_personal.lst"
  14. call :end Done!
  15. goto :eof
  16. ::----------------------------------------------------------------------------------------------------------------------------------
  17. :"Batch_Utility_functions"
  18. ::----------------------------------------------------------------------------------------------------------------------------------
  19. :set_dota outputs %STEAMPATH% %STEAMAPPS% %STEAMDATA% %DOTA%                       ||:i AveYo:" Override detection below if needed "
  20. set "STEAMPATH=C:\Steam" &set "DOTA=C:\Games\steamapps\common\dota 2 beta"                    
  21. if not exist "%STEAMPATH%\Steam.exe" call :reg_query "HKCU\SOFTWARE\Valve\Steam" "SteamPath" STEAMPATH
  22. if not exist "%STEAMPATH%\Steam.exe" call :end ! Cannot find SteamPath in registry
  23. if exist "%DOTA%\game\dota\maps\dota.vpk" set "STEAMAPPS=%DOTA:\common\dota 2 beta=%" &goto :eof
  24. for %%s in ("%STEAMPATH%") do set "STEAMPATH=%%~dpns" &set "libfilter=LibraryFolders { TimeNextStatsReport ContentStatsID }"
  25. if not exist "%STEAMPATH%\SteamApps\libraryfolders.vdf" call :end ! Cannot find "%STEAMPATH%\SteamApps\libraryfolders.vdf"
  26. for /f usebackq^ delims^=^"^ tokens^=4 %%s in (`findstr /v "%libfilter%" "%STEAMPATH%\SteamApps\libraryfolders.vdf"`) do (
  27. if exist "%%s\steamapps\appmanifest_570.acf" if exist "%%s\steamapps\common\dota 2 beta\game\dota\maps\dota.vpk" set "libfs=%%s" )
  28. set "STEAMAPPS=%STEAMPATH%\steamapps" &if defined libfs set "STEAMAPPS=%libfs:\\=\%\steamapps"
  29. if not exist "%STEAMAPPS%\common\dota 2 beta\game\dota\maps\dota.vpk" call :end ! Cannot find "%STEAMAPPS%\common\dota 2 beta"
  30. set "DOTA=%STEAMAPPS%\common\dota 2 beta" &cd /d "%STEAMAPPS%\common\dota 2 beta\game\dota"
  31. call :reg_query "HKCU\SOFTWARE\Valve\Steam\ActiveProcess" "ActiveUser" STEAMUSER &set /a "STEAMID=STEAMUSER" >nul 2>nul
  32. if defined STEAMID if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
  33. if not defined STEAMDATA for /f delims^=^ eol^= %%b in ('dir /a:-d /b /o:d /t:w cache_*.soc 2^>nul') do set "usercache=%%~nb"
  34. if not defined STEAMDATA if defined usercache set "STEAMDATA=%steampath%\userdata\%usercache:cache_=%"
  35. if not exist "%STEAMDATA%\570\remote\cfg\dotakeys_personal.lst" call :end ! Cannot find your dotakeys definition file !
  36. goto :eof
  37. :reg_query %1:KeyName %2:ValueName %3:OutputVariable %4:other_options[example: "/t REG_DWORD"]
  38. setlocal &for /f "skip=2 delims=" %%s in ('reg query "%~1" /v "%~2" /z 2^>nul') do set "rq=%%s" &call set "rv=%%rq:*)    =%%"
  39. endlocal &call set "%~3=%rv%" &goto :eof                         ||:i AveYo - Usage:" call :reg_query "HKCU\MyKey" "MyValue" MyVar "
  40. :end %1:Message
  41. if "%~1"=="!" ( color c0 &echo !ERROR%* &timeout /t 16 &color &exit ) else echo  %* &timeout /t 8 &color &exit
  42. ::----------------------------------------------------------------------------------------------------------------------------------
  43. exit /b :End_of_Batch_engine_parsing - only JS sections below this line
  44. ::--------------------------------------------------------------------------------------------------------------------------------*/
  45.                           //:i Switch syntax highlighter in your text editor from BAT to JS
  46. //----------------------------------------------------------------------------------------------------------------------------------
  47. // EnableQuickCast JS function - DOTA GUI option has been broken for weeks...
  48. //----------------------------------------------------------------------------------------------------------------------------------
  49. EnableQuickCast = function(qc_abilities, qc_items, fn) {
  50.   var qc_abilities = (qc_abilities == 'No') ? 0 : 1, qc_items = (qc_items == 'No') ? 0 : !!
  51.   var abilities = ['AbilityPrimary1','AbilityPrimary2','AbilityPrimary3','AbilitySecondary1','AbilitySecondary2','AbilityUltimate'];
  52.   var items = ['Inventory1','Inventory2','Inventory3','Inventory4','Inventory5','Inventory6'];
  53.   var file_src = path.normalize(fn), file_read = fs.readFileSync(file_src, DEF_ENCODING), vdf = ValveDataFormat();
  54.   var file_parse = vdf.parse(file_read), dotakeys = file_parse.KeyBindings.Keys; file_parse.KeyBindings.Version = 12;
  55.   for (i=0;i<6;i++) dotakeys[abilities[i]].Mode = qc_abilities; for (i=0;i<6;i++) dotakeys[items[i]].Mode = qc_items;
  56.   fs.writeFileSync(fn, vdf.stringify(file_parse,true), DEF_ENCODING);
  57.   console.log(' QuickCast for abilities? ' + qc_abilities + '\r\n' + ' QuickCast for items? ' + qc_items);
  58. }
  59. //----------------------------------------------------------------------------------------------------------------------------------
  60. // ValveDataFormat hybrid parser by AveYo, 2016                                                   VDF test on 20.1 MB items_game.txt
  61. // loosely based on vdf-parser by Rossen Popov, 2014-2016                                                           node.js  cscript                
  62. // featuring auto-renaming duplicate keys, saving comments, grabing lame one-line "key" { "k" "v" }         parse:  1.329s   9.285s
  63. // greatly improved cscript performance - it's not that bad overall but still lags behind node.js       stringify:  0.922s   3.439s    
  64. //----------------------------------------------------------------------------------------------------------------------------------
  65. function ValveDataFormat() {
  66.   var jscript = (typeof ScriptEngine=='function' && ScriptEngine()=='JScript');
  67.   var order = !jscript, dups = false, comments = false, newline = '\n', empty = (jscript) ? '' : !REG3XP0!>undefined;
  68.   return {
  69.     parse: function(txt, flag) {
  70.       var obj = {}, stack = [obj], expect_bracket = false, i = 0; comments = flag || false;
  71.       if (/\r\n/.test(txt)) {newline = '\r\n'} else newline = '\n';
  72.       var m, regex =/[^"\r\n]*(\/\/.*)|"([^"]*)"[ \t]+"([^"]*\\"[^"]*\\"[^"]*|[^"]*)"|"([^"]*)"|({)|(})/g;    
  73.       while ((m = regex.exec(txt)) !== null) {
  74.         //lf='\n'; console.log(' cmnt:',m[1],lf ,'key:',m[2],lf ,'val:',m[3],lf ,'add:',m[4],lf ,'open:',m[5],lf ,'close:',m[6],lf);
  75.         if (comments && m[1] !== empty) {
  76.           key = '\x10' + i++; stack[stack.length-1][key] = m[1];                                  // AveYo: optionally save comments
  77.         } else if (m[4] !== empty) {          
  78.           key = m[4]; if (expect_bracket) { console.log('VDF.parse: invalid bracket near '+ m[0]); return this.stringify(obj,true) }
  79.           if (order && key == ''+~~key) {key = '\x11' + key;}  // AveYo: prepend nr. keys with \x11 to keep order in node.js
  80.           if (stack[stack.length-1][key] === undefined) {
  81.             stack[stack.length-1][key] = {};
  82.           } else {
  83.             key += '\x12' + i++; stack[stack.length-1][key] = {}; dups = true; // AveYo: rename duplicate key obj with \x12 + i
  84.           }
  85.           stack.push(stack[stack.length-1][key]); expect_bracket = true;      
  86.         } else if (m[2] !== empty) {
  87.           key = m[2]; if (expect_bracket) { console.log('VDF.parse: invalid bracket near '+ m[0]); return this.stringify(obj,true) }          
  88.           if (order && key == ''+~~key) key = '\x11' + key;    // AveYo: prepend nr. keys with \x11 to keep order in node.js
  89.           if (stack[stack.length-1][key] !== undefined) { key += '\x12' + i++; dups = true }// AveYo: rename duplicate k-v pair
  90.           stack[stack.length-1][key] = m[3]||'';
  91.         } else if (m[5] !== empty) {
  92.           expect_bracket = false; continue; // one level deeper
  93.         } else if (m[6] !== empty) {
  94.           stack.pop(); continue; // one level back
  95.         }
  96.       }
  97.       if (stack.length != 1) { console.log('VDF.parse: open parentheses somewhere'); return this.stringify(obj,true) }
  98.       return obj; // stack[0];
  99.     },
  100.     stringify: function(obj, pretty, nl) {
  101.       if (typeof obj != 'object') { console.log('VDF.stringify: Input not an object'); return obj }
  102.       pretty = ( typeof pretty == 'boolean' && pretty) ? true : !! nl = nl || newline || '\n';
  103.       return this.dump(obj, pretty, nl, 0);
  104.     },
  105.     dump: function(obj, pretty, nl, level) {
  106.       if (typeof obj != 'object') { console.log('VDF.stringify: Key not string or object'); return obj}
  107.       var indent = '\t', buf = '', idt = '', i = 0;
  108.       if (pretty) for (; i < level; i++) idt += indent;
  109.       for (var key in obj) {
  110.         if (typeof obj[key] == 'object')  {
  111.           buf += idt +'"'+ this.redup(key) +'"'+ nl + idt +'{'+ nl + this.dump(obj[key], pretty, nl, level+1) + idt +'}'+ nl;
  112.         } else {
  113.           if (comments && key.indexOf('\x10') !== -1) { buf += idt + obj[key] + nl; continue } // AveYo: restore comments (optional)
  114.           buf += idt +'"'+ this.redup(key) +'"'+ indent + indent +'"'+ obj[key] +'"'+ nl;
  115.         }
  116.       };
  117.       return buf;
  118.     },
  119.     redup: function(key) {
  120.       if (order && key.indexOf('\x11')!== -1) key = key.split('\x11')[1]; // AveYo: restore number keys in node.js
  121.       if (dups && key.indexOf('\x12') !== -1) key = key.split('\x12')[0]; // AveYo: restore duplicate key names
  122.       return key;
  123.     },
  124.     nr: function(key) {return (!jscript && key.indexOf('\x11') == -1) ? '\x11' + key : class="re0">key} //check number key: vdf.nr('nr');
  125.   }
  126. } // End of ValveDataFormat
  127. //----------------------------------------------------------------------------------------------------------------------------------
  128. // JScript Engine by AveYo - can call specific functions as the first script argument    
  129. // a subset of Hybrid Node.js / JScript Engine used in 'No-Bling DOTA mod builder.bat'                
  130. //----------------------------------------------------------------------------------------------------------------------------------
  131. jscript = true, engine = 'JScript', w = WScript, argc = w.Arguments.Count(), argv=[], run='';
  132. if (argc > 0) { run = w.Arguments(0); for (var i=1;i<argc;i++) argv.push( '"'+ w.Arguments(i).replace(/[\\\/]+/g,'\\\\') +'"') }
  133. process={}; process.argv=[ScriptEngine(),w.ScriptFullName]; for (var i=0;i<argc;i++) process.argv[i+2] = w.Arguments(i);
  134. path={}; path.join = function(f,n){return fso.BuildPath(f,n)}; path.normalize = function(f){return fso.GetAbsolutePathName(f)};  
  135. path.basename = function(f){return fso.GetBaseName(f)}; path.dirname=function(f){return fso.GetParentFolderName(f)};path.sep='\\';
  136. console={}; console.log=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u) { w.echo(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u) };
  137. fs={}; fso=new ActiveXObject("Scripting.FileSystemObject"); ado=new ActiveXObject('ADODB.Stream'); DEF_ENCODING='Windows-1252';
  138. FileExists = function(f) { return fso.FileExists(f) }; PathExists = function(f) { return fso.FolderExists(f) };
  139. fs.readFileSync = function(fn, charset) {
  140.   var data=''; ado.Mode=3; ado.Type=2; ado.Charset=charset || 'Windows-1252'; ado.Open(); ado.LoadFromFile(fn);
  141.   while (!ado.EOS) data += ado.ReadText(131072); ado.Close(); return data;
  142. }
  143. fs.writeFileSync = function(fn, data, encoding) {
  144.   ado.Mode=3; ado.Type=2; ado.Charset=encoding || 'Windows-1252'; ado.Open();
  145.   ado.WriteText(data); ado.SaveToFile(fn, 2); ado.Close(); return 0;
  146. }
  147. //----------------------------------------------------------------------------------------------------------------------------------
  148. // Auto-run: if first script argument is a function name - call it, passing the next arguments
  149. //----------------------------------------------------------------------------------------------------------------------------------
  150. if (run && !/[^A-Z0-9$_]/i.test(run)) new Function('if(typeof '+run+'=="function"){'+run+'('+argv+');}')();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement