Last active
January 18, 2022 08:54
-
-
Save radstevee/56ba8b15e7e975170c8705d716932a53 to your computer and use it in GitHub Desktop.
Counts the world files that start with Speedrun # or New World from every open minecraft instance and displays it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Script by Radsteve | |
; Forked from Specnr's MoveWorlds-Script | |
#SingleInstance, Force | |
SendMode Input | |
SetWorkingDir, %A_ScriptDir% | |
global count := 0 | |
global McDirectories := [] | |
global rawPIDs := [] | |
global instances := 0 | |
sleep, 500 | |
RunHide(Command) | |
{ | |
dhw := A_DetectHiddenWindows | |
DetectHiddenWindows, On | |
Run, %ComSpec%,, Hide, cPid | |
WinWait, ahk_pid %cPid% | |
DetectHiddenWindows, %dhw% | |
DllCall("AttachConsole", "uint", cPid) | |
Shell := ComObjCreate("WScript.Shell") | |
Exec := Shell.Exec(Command) | |
Result := Exec.StdOut.ReadAll() | |
DllCall("FreeConsole") | |
Process, Close, %cPid% | |
Return Result | |
} | |
GetMcDir(pid) | |
{ | |
command := Format("powershell.exe $x = Get-WmiObject Win32_Process -Filter \""ProcessId = {1}\""; $x.CommandLine", pid) | |
rawOut := RunHide(command) | |
if (InStr(rawOut, "--gameDir")) { | |
strStart := RegExMatch(rawOut, "P)--gameDir (?:""(.+?)""|([^\s]+))", strLen, 1) | |
return SubStr(rawOut, strStart+10, strLen-10) . "\" | |
} else { | |
strStart := RegExMatch(rawOut, "P)(?:-Djava\.library\.path=(.+?) )|(?:\""-Djava\.library.path=(.+?)\"")", strLen, 1) | |
if (SubStr(rawOut, strStart+20, 1) == "=") { | |
strLen -= 1 | |
strStart += 1 | |
} | |
return StrReplace(SubStr(rawOut, strStart+20, strLen-28) . ".minecraft\", "/", "\") | |
} | |
} | |
GetInstanceTotal() { | |
idx := 1 | |
global rawPIDs | |
WinGet, all, list | |
Loop, %all% | |
{ | |
WinGet, pid, PID, % "ahk_id " all%A_Index% | |
WinGetTitle, title, ahk_pid %pid% | |
if (InStr(title, "Minecraft*")) { | |
rawPIDs[idx] := pid | |
idx += 1 | |
} | |
} | |
return rawPIDs.MaxIndex() | |
} | |
GetAllPIDs() | |
{ | |
global McDirectories | |
global instances := GetInstanceTotal() | |
; Generate mcdir and order PIDs | |
Loop, %instances% { | |
mcdir := GetMcDir(rawPIDs[A_Index]) | |
McDirectories[A_Index] := mcdir | |
} | |
} | |
GetAllPIDs() | |
for i, mcdir in McDirectories { | |
saves := mcdir . "saves\" | |
Loop, Files, %saves%*, D | |
{ | |
If (InStr(A_LoopFileName, "New World") || InStr(A_LoopFileName, "Speedrun #")) { | |
count := count+1 | |
} | |
} | |
} | |
msgbox, %count% | |
ExitApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment