Advertisement
aveyo

reset_Steam

Mar 23rd, 2019
13,571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 13.13 KB | None | 0 0
  1. @set @v=2019.03.21 /*
  2. @echo off &color 4f &title Reset STEAM settings by AveYo v%@v:/*=%
  3. echo.
  4. echo      ---------------------------------------------------------------------
  5. echo     :        Reset Steam configuration for the last logged on user        :
  6. echo     :---------------------------------------------------------------------:
  7. echo     :  If any issues, right-click script and click Run as administrator   :
  8. echo     :                                                                     :
  9. echo     :  WARNING! Steam must be closed so that config file can be modified  :
  10. echo      ---------------------------------------------------------------------
  11. echo.
  12. :: Detect Steam path
  13. call :set_steam
  14. echo STEAMDATA: %STEAMDATA%
  15. timeout /t 10
  16. if not defined STEAMDATA echo ERROR! User profile not found, cannot reset Steam options & goto :done
  17. :: Kill Steam
  18. taskkill /im Steam.exe /t /f >nul 2>nul & timeout /t 1 >nul & del /f /q "%STEAMPATH%\.crash" >nul 2>nul & timeout /t 1 >nul
  19. color 1f
  20. :: Edit Steam config file
  21. pushd "%STEAMDATA%\config" & copy /y localconfig.vdf localconfig.vdf.bak >nul
  22. cscript //E:JScript //nologo "%~f0" reset_Steam "localconfig.vdf" "%STEAMID%"
  23. :: Remove registry settings
  24. for %%i in (BigPictureInForeground, DPIScaling, DWriteEnable, H264HWAccel, Rate) do (
  25.  reg delete "HKCU\Software\Valve\Steam" /v %%i /f >nul 2>nul
  26. )
  27. :done
  28. :: [Optional] Restart Steam with fast options
  29. set l1=-silent -console -forceservice -single_core -windowed -manuallyclearframes 0 -nodircheck -norepairfiles -noverifyfiles
  30. set l2=-nocrashmonitor -nocrashdialog -vrdisable -nofriendsui -skipstreamingdrivers +"@AllowSkipGameUpdate 1 -
  31. start "Steam" "%STEAMPATH%\Steam.exe" %l1% %l2%
  32. :: Done!
  33. pushd "%~dp0"
  34. call :end Done
  35. exit/b
  36.  
  37. ::------------------------------------------------------------------------------------------------------------------------------
  38. :: Utility functions
  39. ::------------------------------------------------------------------------------------------------------------------------------
  40. :set_steam [OUTPUTS] STEAMPATH STEAMDATA STEAMID                                      AveYo : Override detection below if needed
  41. set "STEAMPATH=D:\Steam"
  42. if not exist "%STEAMPATH%\Steam.exe" call :reg_query STEAMPATH "HKCU\SOFTWARE\Valve\Steam" "SteamPath"
  43. set "STEAMDATA=" & if defined STEAMPATH for %%# in ("%STEAMPATH%") do set "STEAMPATH=%%~dpnx#"
  44. if not exist "%STEAMPATH%\Steam.exe" call :end ! Cannot find SteamPath in registry
  45. call :reg_query ACTIVEUSER "HKCU\SOFTWARE\Valve\Steam\ActiveProcess" "ActiveUser" & set/a "STEAMID=ACTIVEUSER" >nul 2>nul
  46. if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
  47. if not defined STEAMDATA for /f "delims=" %%# in ('dir "%STEAMPATH%\userdata" /b/o:d/t:w/s 2^>nul') do set "ACTIVEUSER=%%~dp#"
  48. if not defined STEAMDATA for /f "delims=\" %%# in ("%ACTIVEUSER:*\userdata\=%") do set "STEAMID=%%#"
  49. if exist "%STEAMPATH%\userdata\%STEAMID%\config\localconfig.vdf" set "STEAMDATA=%STEAMPATH%\userdata\%STEAMID%"
  50. exit/b
  51. :reg_query [USAGE] call :reg_query ResultVar "HKCU\KeyName" "ValueName"
  52. (for /f "skip=2 delims=" %%s in ('reg query "%~2" /v "%~3" /z 2^>nul') do set ".=%%s" & call set "%~1=%%.:*)    =%%") & exit/b
  53. :end %1:Message[Delayed termination with status message - prefix with ! to signal failure]
  54. echo. & if "%~1"=="!" ( color 0c & echo ERROR! %* & pause & exit ) else echo INFO: %* & pause & exit
  55.  
  56. rem End of batch code */
  57.  
  58. //------------------------------------------------------------------------------------------------------------------------------
  59. // Utility JS functions - callable independently
  60. //------------------------------------------------------------------------------------------------------------------------------
  61. reset_Steam=function(fn, steamid){
  62.   var keys=["streaming_v2", "Broadcast", "friends", "Software/Valve/Steam/Apps", "WebStorage", "system", "News", "Apps"];
  63.   var file=path.normalize(fn), data=fs.readFileSync(file, DEF_ENCODING), vdf=ValveDataFormat(); parsed=vdf.parse(data);
  64. //reset_key(parsed, "UserLocalConfigStore", true);
  65.   cfg = parsed.UserLocalConfigStore;
  66.   for (i in keys) reset_key(cfg, keys[i], false);
  67.   fs.writeFileSync(fn, vdf.stringify(parsed,true), DEF_ENCODING);
  68. };
  69. function reset_key(obj, keypath, main){
  70.   var out=obj, test=keypath.split("/");
  71.   for (i=0; i < test.length; i++) {
  72.     for (KeY in out) {
  73.       if (out.hasOwnProperty(KeY) && (KeY+"").toLowerCase()==(test[i]+"").toLowerCase()) {out=out[KeY];/*w.echo("found "+KeY)*/}
  74.     }
  75.   }
  76.   for (line in out) {
  77.     if (typeof out[line] == "string") {
  78.       w.echo("-", test,"-", line); delete out[line];
  79.     }
  80.     else if (typeof out[line] !== "object" || main) continue;
  81.     for (s in out[line]) {
  82.       if (typeof out[line][s] !== "string") continue;
  83.       w.echo("-", test, "-", line, "-", s); delete out[line][s];
  84.     }
  85.   }
  86.   return out;
  87. }
  88. //------------------------------------------------------------------------------------------------------------------------------
  89. // ValveDataFormat hybrid js parser by AveYo, 2016                                            VDF test on 20.1 MB items_game.txt
  90. // loosely based on vdf-parser by Rossen Popov, 2014-2016                                                       node.js  cscript
  91. // featuring auto-renaming duplicate keys, saving comments, grabbing lame one-line "key" { "k" "v" }     parse:  1.329s   9.285s
  92. // greatly improved cscript performance - it"s not that bad overall but still lags behind node.js    stringify:  0.922s   3.439s
  93. //------------------------------------------------------------------------------------------------------------------------------
  94. function ValveDataFormat(){
  95.   var jscript=(typeof ScriptEngine === "function" && ScriptEngine() === "JScript");
  96.   if (!jscript) { var w={}; w.echo=function(s){console.log(s+"\r");}; } else { w=WScript; }
  97.   var order=!jscript, dups=false, comments=false, newline="\n", empty=(jscript) ? "" : !REG3XP0!>undefined;
  98.   return {
  99.     parse: function(txt, flag){
  100.       var obj={}, stack=[obj], expect_bracket=false, i=0; comments=flag || false;
  101.       if (/\r\n/.test(txt)) {newline="\r\n";} else newline="\n";
  102.       var m, regex =/[^""\r\n]*(\/\/.*)|"([^""]*)"[ \t]+"(.*)"|"([^""]*)"|({)|(})/g;
  103.       while ((m=regex.exec(txt)) !== null) {
  104.         //lf="\n"; w.echo(" cmnt:"+m[1]+lf+" key:"+m[2]+lf+" val:"+m[3]+lf+" add:"+m[4]+lf+" open:"+m[5]+lf+" close:"+m[6]+lf);
  105.         if (comments && m[1] !== empty) {
  106.           i++;key="\x10"+i; stack[stack.length-1][key]=m[1];                                  // AveYo: optionally save comments
  107.         } else if (m[4] !== empty) {
  108.           key=m[4]; if (expect_bracket) { w.echo("VDF.parse: invalid bracket near "+m[0]); return this.stringify(obj,true); }
  109.           if (order && key === ""+~~key) {key="\x11"+key;}          // AveYo: prepend nr. keys with \x11 to keep order in node.js
  110.           if (typeof stack[stack.length-1][key] === "undefined") {
  111.             stack[stack.length-1][key] = {};
  112.           } else {
  113.             i++;key+= "\x12"+i; stack[stack.length-1][key] = {}; dups=true;         // AveYo: rename duplicate key obj with \x12+i
  114.           }
  115.           stack.push(stack[stack.length-1][key]); expect_bracket=true;
  116.         } else if (m[2] !== empty) {
  117.           key=m[2]; if (expect_bracket) { w.echo("VDF.parse: invalid bracket near "+m[0]); return this.stringify(obj,true); }
  118.           if (order && key === ""+~~key) key="\x11"+key;            // AveYo: prepend nr. keys with \x11 to keep order in node.js
  119.           if (typeof stack[stack.length-1][key] !== "undefined") {i++; key+="\x12"+i; dups=true; }// AveYo: rename duplicate k-v
  120.           stack[stack.length-1][key]=m[3]||"";
  121.         } else if (m[5] !== empty) {
  122.           expect_bracket=false; continue; // one level deeper
  123.         } else if (m[6] !== empty) {
  124.           stack.pop(); continue; // one level back
  125.         }
  126.       }
  127.       if (stack.length !== 1) { w.echo("VDF.parse: open parentheses somewhere"); return this.stringify(obj,true); }
  128.       return obj; // stack[0];
  129.     },
  130.     stringify: function(obj, pretty, nl){
  131.       if (typeof obj !== "object") { w.echo("VDF.stringify: Input not an object"); return obj; }
  132.       pretty=( typeof pretty === "boolean" && pretty) ? true : !! nl=nl || newline || "\n";
  133.       return this.dump(obj, pretty, nl, 0);
  134.     },
  135.     dump: function(obj, pretty, nl, level){
  136.       if (typeof obj !== "object") { w.echo("VDF.stringify: Key not string or object"); return obj; }
  137.       var indent="\t", buf="", idt="", i=0;
  138.       if (pretty) { for (i=0; i < level; i++) idt+= indent; }
  139.       for (var key in obj) {
  140.         if (typeof obj[key] === "object")  {
  141.           buf+= idt+'"'+this.redup(key)+'"'+nl+idt+'{'+nl+this.dump(obj[key], pretty, nl, level+1)+idt+'}'+nl;
  142.         } else {
  143.           if (comments && key.indexOf("\x10") !== -1) { buf+= idt+obj[key]+nl; continue; } // AveYo: restore comments (optional)
  144.           buf+= idt+'"'+this.redup(key)+'"'+indent+indent+'"'+obj[key]+'"'+nl;
  145.         }
  146.       }
  147.       return buf;
  148.     },
  149.     redup: function(key){
  150.       if (order && (key+"").indexOf("\x11") !== -1) key=key.split("\x11")[1];           // AveYo: restore number keys in node.js
  151.       if (dups && (key+"").indexOf("\x12") !== -1) key=key.split("\x12")[0];               // AveYo: restore duplicate key names
  152.       return key;
  153.     },
  154.     nr: function(key){return (!jscript && (key+"").indexOf("\x11") === -1) ? "\x11"+key : !REG3XP0!>key;}  // AveYo: check nr: vdf.nr("nr")
  155.   };
  156. } // End of ValveDataFormat
  157.  
  158. //------------------------------------------------------------------------------------------------------------------------------
  159. // Hybrid Node.js / JScript Engine by AveYo - can call specific functions as the first script argument
  160. //------------------------------------------------------------------------------------------------------------------------------
  161. if (typeof ScriptEngine === "function" && ScriptEngine() === "JScript") {
  162.   // start of JScript specific code
  163.   jscript=true;engine="JScript";w=WScript;launcher=new ActiveXObject("WScript.Shell"); argc=w.Arguments.Count();argv=[]; run="";
  164.   if (argc > 0){run=w.Arguments(0); for (var i=1; i < argc; i++) argv.push( '"'+w.Arguments(i).replace(/[\\\/]+/g,"\\\\")+'"');}
  165.   process={};process.argv=[ScriptEngine(),w.ScriptFullName];for (var j=0;j<argc;j++) process.argv[j+2]=w.Arguments(j);RN="\r\n";
  166.   path={}; path.join=function(f,n){return fso.BuildPath(f,n);}; path.normalize=function(f){return fso.GetAbsolutePathName(f);};
  167.   path.basename=function(f){return fso.GetFileName(f);};path.dirname=function(f){return fso.GetParentFolderName(f);};
  168.   fs={};fso=new ActiveXObject("Scripting.FileSystemObject"); ado=new ActiveXObject("ADODB.Stream"); DEF_ENCODING="Windows-1252";
  169.   FileExists=function(f){ return fso.FileExists(f); }; PathExists=function(f){ return fso.FolderExists(f); }; path.sep="\\";
  170.   MakeDir=function(fn){
  171.     if (fso.FolderExists(fn)) return; var pfn=fso.GetAbsolutePathName(fn), d=pfn.match(/[^\\\/]+/g), p="";
  172.     for (var i=0,n=d.length; i<n; i++) { p+= d[i]+"\\"; if (!fso.FolderExists(p)) fso.CreateFolder(p); }
  173.   };
  174.   fs.readFileSync=function(fn, charset){
  175.     var data=""; ado.Mode=3; ado.Type=2; ado.Charset=charset || "Windows-1252"; ado.Open(); ado.LoadFromFile(fn);
  176.     while (!ado.EOS) data+= ado.ReadText(131072); ado.Close(); return data;
  177.   };
  178.   fs.writeFileSync=function(fn, data, encoding){
  179.     ado.Mode=3; ado.Type=2; ado.Charset=encoding || "Windows-1252"; ado.Open();
  180.     ado.WriteText(data); ado.SaveToFile(fn, 2); ado.Close(); return 0;
  181.   };
  182.   // end of JScript specific code
  183. } else {
  184.   // start of Node.js specific code
  185.   jscript=false;engine="Node.js";w={}; argc=process.argv.length; argv=[]; run=""; p=process.argv; w.quit=process.exit;RN="\r\n";
  186.   if (argc > 2) { run=p[2]; for (n=3;n<argc;n++) argv.push('"'+p[n].replace(/[\\\/]+/g,"\\\\")+'"'); }
  187.   path=require("path"); fs=require("fs"); DEF_ENCODING="utf-8"; w.echo=function(s){console.log(s+"\r");};
  188.   FileExists=function(f){ try{ return fs.statSync(f).isFile(); }catch(e) { if (e.code === "ENOENT") return false; } };
  189.   PathExists=function(f){ try{ return fs.statSync(f).isDirectory(); }catch(e) { if (e.code === "ENOENT") return false; } };
  190.   MakeDir=function(f){ try{ fs.mkdirSync(f); }catch(e) { if (e.code === "ENOENT") { MakeDir(path.dirname(f)); MakeDir(f); } } };
  191.   // end of Node.js specific code
  192. }
  193. function timer(hint){
  194.   var s=new Date(); return { end:function(){ var e=new Date(), t=(e.getTime()-s.getTime())/1000; w.echo(hint+": "+t+"s");}};
  195. }
  196. // If run without parameters the .js file must have been double-clicked in shell, so try to launch the correct .bat file instead
  197. if (jscript&&run===""&&FileExists(w.ScriptFullName.slice(0, -2)+"bat")) launcher.Run('"'+w.ScriptFullName.slice(0, -2)+"bat\"");
  198. //------------------------------------------------------------------------------------------------------------------------------
  199. // Auto-run JS: if first script argument is a function name - call it, passing the next arguments
  200. //------------------------------------------------------------------------------------------------------------------------------
  201. if (run && !(/[^A-Z0-9$_]/i.test(run))) new Function("if(typeof "+run+" === \"function\") {"+run+"("+argv+");}")();
  202. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement