Switching mods ahk script

Enhance your gameplay with these tools. This category is also the right place for tools useful for modders.
Mod databases, calculators, cheatsheets, multiplayer, scripts, libs and other useful stuff that is not strictly in-game mods.
Post Reply
Mgis09
Inserter
Inserter
Posts: 27
Joined: Sun May 06, 2018 3:58 pm
Contact:

Switching mods ahk script

Post by Mgis09 »

Hey guys!

I would like to share with you this script that I wrote.
It can switch mods between enabled and disabled state, by modifying mod-list.json.
I found myself going there and usng editor to replace specific occurences.
Because I play vanilla on some days.
But now this script can do it!
Even faster for you if you happen to have ahk installed!


It has three modes of operation.
  1. Asking user what to do.
  2. Using parameter passed to script and enabling all mods.
  3. Using parameter passed to script and disabling all mods, except base.
Also, as a bonus, it shows your last savegame's thumbnail!

Code: Select all

;Factorio Switching mods script by Mgis. factorio-mods-switch-all.ahk
;made for ahk Version 1.1.29.00, some previous should work too
#singleinstance ignore
Coordmode,tooltip,screen
modlist:=A_AppData . "\Factorio\mods\mod-list.json"
Gosub,prev		; can be commented out. Shows Before window
;----------------------------------------------


if 0 >= 1
	GoSub,param		;yeah I know! sometimes zero is greater really

new:=modlist
StringTrimRight,new,new,5
new.="_new.json"
FileRecycle,%new%	;choose one: Recycle or Delete
;FileDelete,%new%

MsgBox, % 3+512,Enable all?,Enable all or disable all or abort?,15
Ifmsgbox,cancel
	exitapp
Ifmsgbox,yes
	en:=true
Ifmsgbox,no
	en:=false
ToolTip, % en?"ENABLING":"DISABLING",550,120,4
SetTimer,aft,1000		; can be commented out
Sleep 1500
t=


Loop, read,%modlist%,*%new%
{
	if not fast
		if A_LoopReadLine contains name
		{
			line:=Trim(A_LoopReadLine)
			ToolTip, %line%,400,100,1
			StringGetPos,x,line, % """",r2
			x+=2
			Sleep 400				;these two affect main speed
			x:=SubStr(line,x)
			StringTrimRight,x,x,2
			ToolTip, %x%,400,120,2
			Sleep 500				;and this
			t.=A_LoopReadLine . "`n"
		}
	if A_LoopReadLine contains enabled
	{
		ln:=Trim(A_LoopReadLine)
		StringTrimLeft,ln,ln,10
		ln:=Trim(ln)
		ToolTip, %ln%,500,140,3
		if en
		{
			y:=StrReplace(A_LoopReadLine,"false","true")
		} else {
			if x not in base
				y:=StrReplace(A_LoopReadLine,"true","false")
			else
			{
				MsgBox,,,base mod - skipping!,1
				y:=A_LoopReadLine
			}
		}
		FileAppend,%y%`n
		t.=y . "`n"
		continue	;go next
	}
	FileAppend,%A_LoopReadLine%`n
}
setTimer,aft,off
ToolTip,After`n`n%t%,220,170,5
msgbox,1,Switching mods,is that ok?,15
ifmsgbox,ok
	FileCopy,%new%,%modlist%,1
FileDelete,%new%
exitapp
return	;autoexec

Esc::
ToolTip,After`n`n%t%,220,170,5
MsgBox,4,Switching mods,Do You wish to cancel?,9
ifmsgbox,yes
	exitapp
return
f1::
pause
return
f2::
fast:=true
return

prev:
FileRead,t,%modlist%
t:=StrReplace(t,A_Space)
t:=StrReplace(t,"`t")
t:=StrReplace(t,"{")
t:=StrReplace(t,"},")
t:=StrReplace(t,"`r`n`r`n","`n")
t:=StrReplace(t,"`n`n","`n")	; I did some cutting cause with 15 mods it couldnt fit
StringTrimRight,img,modlist,18
SplashImage, % img . "temp\preview.jpg", x10 y3 zw-1 zh190 c00 a m1 fs8, %t%,, Before
return

aft:
ToolTip,After`n`n%t%,650,100,5
return


param:
FileRead,t,%modlist%
if 1=1
{
	;MsgBox,,,param 1 is one,1
	;fastest enabling mode:
	t:=StrReplace(t,"false","true")
} else {
	;MsgBox,,,param 1 is other,1
	;fastest disabling mode:
	t:=StrReplace(t,"true","false")
	t:=StrReplace(t,"false","true",,1)	; I assume the first one is basemod
}
	FileDelete,%modlist%
	Sleep 1000
	FileAppend,%t%,*%modlist%
msgbox,,,done,1
exitapp
return



Thanks!

Post Reply

Return to “Tools”