Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Java program launcher w/ memory allocation.


  • Please log in to reply
2 replies to this topic
bettyj
  • Members
  • 28 posts
  • Last active: Nov 14 2012 03:39 AM
  • Joined: 22 Aug 2012
Hey everyone. This script I wrote for minecraft, but if modified can work for any java based program.

What it does:
It will first get the amount of physical memory the computer has.
Then It will ask the user a few questions about there game, like mods they are running or if they have an HD texture pack.
Then it will run the game with a percent of allocated memory depending on the settings provided by the user.

feel free to modify or clean up just pls post it here.

; made by bettyj with some help 
; post I got help from ; http://www.autohotkey.com/forum/viewtopic.php?p=225823#225823

SetFormat, float, 6.0

VarSetCapacity( MEMORYSTATUSEX,64,0 ), NumPut( 64,MEMORYSTATUSEX )
DllCall( "GlobalMemoryStatusEx", UInt,&MEMORYSTATUSEX )
TotalPhys := NumGet( MEMORYSTATUSEX,8,"Int64"),   VarSetCapacity( PhysMem,16,0 )
DllCall( "shlwapi.dll\StrFormatByteSize64A", Int64,TotalPhys, Str,PhysMem, UInt,16 )

IfNotExist, %A_AppData%/.minecraft/bettylaunch.jar
{
	IfNotExist, %A_AppData%/.minecraft
		FileCreateDir, %A_AppData%/.minecraft
	URLDownloadToFile, https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft.jar, %A_AppData%/.minecraft/bettylaunch.jar
}
IfNotExist, %A_AppData%/.minecraft/Bettylauch.ini
{
	IniWrite, false, %A_AppData%/.minecraft/Bettylauch.ini, Vars, Setup
	IniWrite, javaw -Xmx4096M -Xms2048M -jar "%A_AppData%/.minecraft/bettylaunch.jar", %A_AppData%/.minecraft/Bettylauch.ini, Vars, RunMC
}
IniRead, isset, %A_AppData%/.minecraft/Bettylauch.ini, Vars, Setup
IniRead, Runtime, %A_AppData%/.minecraft/Bettylauch.ini, Vars, RunMC

Gui, Add, Text, x22 y20 w440 h80 , Welcome to Betty's Minecraft Memory optimizor.  Follow the lists below to Optomize your Minecraft experance.
Gui, Add, CheckBox, x142 y120 w190 h40 vHD, Do you have an HD texturepack?
Gui, Add, CheckBox, x142 y170 w190 h40 vshader, Do you have any shader mods?
Gui, Add, CheckBox, x142 y220 w190 h50 vissues, Do you have issues with Minecraft running out of Memory?
Gui, Add, CheckBox, x142 y280 w190 h50 vmax , Would you rather Me just use max settings?
Gui, Add, Button, x182 y340 w110 h30 , Set
Gui, Add, Text, x12 y120 w100 h240 , If you get any errors pls change some of the settings`, contact me on the fourms`, and try again.
Gui, Show, x557 y282 h600 w479, New GUI Window
Return
ButtonSet:
Gui, Submit 
If max=1
{
	maxall:=((TotalPhys*9.5367e-7)/1.5)
	halfall:=maxall/2
	StringTrimLeft, fixmax, maxall, 2
	StringTrimLeft, fixmin, halfall, 2
	IniWrite, javaw -Xmx%fixmax%M -Xms%fixmin%M -jar %A_AppData%/.minecraft/bettylaunch.jar, %A_AppData%/.minecraft/Bettylauch.ini, Runtime, Runvar
}
else
{
	If shader=1
	{
		maxall:=((TotalPhys*9.5367e-7)/2)
		halfall:=maxall/2
		StringTrimLeft, fixmax, maxall, 2
		StringTrimLeft, fixmin, halfall, 2
		IniWrite, javaw -Xmx%fixmax%M -Xms%fixmin%M -jar %A_AppData%/.minecraft/bettylaunch.jar, %A_AppData%/.minecraft/Bettylauch.ini, Runtime, Runvar
	}
	else
	{
		If HD=1
		{
			maxall:=((TotalPhys*9.5367e-7)/2.25)
			halfall:=maxall/2
			StringTrimLeft, fixmax, maxall, 2
			StringTrimLeft, fixmin, halfall, 2
			IniWrite, javaw -Xmx%fixmax%M -Xms%fixmin%M -jar %A_AppData%/.minecraft/bettylaunch.jar, %A_AppData%/.minecraft/Bettylauch.ini, Runtime, Runvar
		}
		else
		{
			If issues=1
			{
				maxall:=((TotalPhys*9.5367e-7)/3)
				halfall:=maxall/2
				StringTrimLeft, fixmax, maxall, 2
				StringTrimLeft, fixmin, halfall, 2
				IniWrite, javaw -Xmx%fixmax%M -Xms%fixmin%M -jar %A_AppData%/.minecraft/bettylaunch.jar, %A_AppData%/.minecraft/Bettylauch.ini, Runtime, Runvar
		}
	}
	}
}
IniRead, Runvarmc, %A_AppData%/.minecraft/Bettylauch.ini, Runtime, Runvar
Run, %Runvarmc%

GuiClose:
ExitApp


TLM
  • Moderators
  • 3820 posts
  • Last active: Yesterday, 10:04 PM
  • Joined: 21 Aug 2006
Nice job.
Did you see Gogo's fix for the "random" spaces issue?

bettyj
  • Members
  • 28 posts
  • Last active: Nov 14 2012 03:39 AM
  • Joined: 22 Aug 2012
No I didn't but thank you for pointing it out.