Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; mc launcher
- #m_info = 0
- #m_error = 1
- #m_question = 2
- Global Version.s = "1.4-R4"
- Global MyName.s = "Minecraft " + Version
- Global MyPath.s = GetPathPart(ProgramFilename())
- Global MinecraftPath.s = MyPath + ".minecraft"
- Global secret.s = ""
- Global param.s = ProgramParameter(0)
- Global outsecret.s = MD5Fingerprint(@param,Len(param))
- Debug outsecret
- Debug ProgramParameter(0)
- ;Global MinecraftPath.s = GetEnvironmentVariable("APPDATA") + "\.minecraft"
- ;Global TaskKillPath.s = GetEnvironmentVariable("WINDIR") + "\system32\taskkill.exe"
- Global UniqueSessionName.s = Str(Random(10000)) + Str(Random(10000)) + Str(Random(10000))
- ;Global TempPath.s = GetEnvironmentVariable("TEMP") + "\" + MD5Fingerprint(@UniqueSessionName,Len(UniqueSessionName))
- Global TempPath.s = MyPath + "\sess_" + MD5Fingerprint(@UniqueSessionName,Len(UniqueSessionName))
- Global JavaPath.s = ""
- Global JavaVersion.s = ""
- Global Java64bits = #False
- Global JavaMem
- Global timer = 0
- Global SaveLogin.s,SavePw.s,AllocatedMemTick.s,SavedLogin.s,SavedPw.s,iamapirate.s,JavaPathPre.s,NumberOfTicks.i,ShadersType.i,MCRender.s
- Global PlayButtonChanged,SettingsButtonChanged,ExitButtonChanged
- Global Running = #False
- Global RunThread
- Global checksum.s
- InitNetwork()
- UsePNGImageDecoder()
- Background = CatchImage(0,?Background)
- PlayButton = CatchImage(1,?PlayButton)
- PlayButtonMin = CatchImage(2,?PlayButtonMin)
- SettingsButton = CatchImage(3,?SettingsButton)
- SettingsButtonMin = CatchImage(4,?SettingsButtonMin)
- ExitButton = CatchImage(5,?ExitButton)
- ExitButtonMin = CatchImage(6,?ExitButtonMin)
- DataSection
- ; graphics
- Background:
- IncludeBinary "back.bmp"
- PlayButton:
- IncludeBinary "play.png"
- PlayButtonMin:
- IncludeBinary "play_min.png"
- SettingsButton:
- IncludeBinary "settings.png"
- SettingsButtonMin:
- IncludeBinary "settings_min.png"
- ExitButton:
- IncludeBinary "exit.png"
- ExitButtonMin:
- IncludeBinary "exit_min.png"
- ; minecraft data
- MCOptiBinary1:
- IncludeBinary "mc.opti.bin.004"
- MCOptiBinary2:
- IncludeBinary "mc.opti.bin.001"
- MCOptiBinary3:
- IncludeBinary "mc.opti.bin.003"
- MCOptiBinary4:
- IncludeBinary "mc.opti.bin.002"
- ; end marker
- MCEnd:
- EndDataSection
- ; size calculation for later extraction
- Global MCOptiBinSize1.i = ?MCOptiBinary2 - ?MCOptiBinary1
- Global MCOptiBinSize2.i = ?MCOptiBinary3 - ?MCOptiBinary2
- Global MCOptiBinSize3.i = ?MCOptiBinary4 - ?MCOptiBinary3
- Global MCOptiBinSize4.i = ?MCEnd - ?McOptiBinary4
- Structure mods
- filename.s
- md5.s
- EndStructure
- Global NewList AllowedMods.mods()
- AddElement(AllowedMods())
- AllowedMods()\filename = "example.jar"
- AllowedMods()\md5 = LCase("5345BFE911D00F81659B5AADEE708F34")
- Procedure AddToLog(message.s,type)
- OpenFile(0,MyPath + "mcl.log",#PB_File_SharedRead|#PB_File_Append)
- time.s = FormatDate("%yyyy/%mm/%dd - %hh:%ii:%ss",Date())
- Select type
- Case #m_info
- WriteStringN(0,time + " [INFO] " + message)
- Case #m_error
- WriteStringN(0,time + " [ERROR] " + message)
- Default
- WriteStringN(0,time + " [INFO] " + message)
- EndSelect
- CloseFile(0)
- ProcedureReturn #True
- EndProcedure
- Procedure Message(message.s,type)
- Select type
- Case #m_error
- MessageBox_(0,message,MyName,#MB_OK|#MB_ICONERROR)
- Case #m_info
- MessageBox_(0,message,MyName,#MB_OK|#MB_ICONINFORMATION)
- Case #m_question
- If MessageBox_(0,message,MyName,#MB_YESNO|#MB_ICONQUESTION) = #IDYES
- ProcedureReturn #True
- Else
- ProcedureReturn #False
- EndIf
- Default
- MessageBox_(0,message,MyName,#MB_OK|#MB_ICONINFORMATION)
- EndSelect
- ProcedureReturn #True
- EndProcedure
- Procedure.b MouseOverGadget(window.l, gadget.l, offsetX.l=0, offsetY.l=0)
- gadgetX.l = GadgetX(gadget) + offsetX
- gadgetY.l = GadgetY(gadget) + offsetY
- gadgetW.l = GadgetWidth(gadget)
- gadgetH.l = GadgetHeight(gadget)
- mouseX.l = WindowMouseX(window)
- mouseY.l = WindowMouseY(window)
- If (mouseX >= gadgetX) And (mouseY >= gadgetY) And (mouseX <= (gadgetX + gadgetW - 1)) And (mouseY <= (gadgetY + gadgetH - 1))
- ProcedureReturn #True
- Else
- ProcedureReturn #False
- EndIf
- EndProcedure
- Procedure.s DownloadToMemory(URL.s,maxbytes=0)
- Protected ServerID.l, Header.s, *Buffer = AllocateMemory(1000), String.s, Server.s, Path.s, i.l, DataLength.l,Bytes.l
- URL = RemoveString(URL,"http://",1)
- i = FindString(URL,"/",1)
- If i
- Server = Left(URL,i-1)
- Path = Right(URL,Len(URL)-i)
- Else
- Server = URL
- EndIf
- ServerID = OpenNetworkConnection(Server,80)
- If ServerID
- ;Header for the GET request
- Header = "GET /"+Path+" HTTP/1.1" + Chr(13) + Chr(10)
- Header + "Accept: */*" + Chr(13) + Chr(10)
- Header + "Connection: Close" + Chr(13) + Chr(10)
- Header + "User-Agent: iSMC/" + Version + Chr(13) + Chr(10)
- Header + "Host: "+Server + Chr(13) + Chr(10) + Chr(13) + Chr(10)
- ;SendNetworkData(ServerID,@Header,Len(Header)) ;Send the GET request
- SendNetworkString(ServerID,Header)
- ;Debug Header
- Delay(1000)
- CloseNetworkConnection(ServerID)
- ; i = 1
- ;
- ; Repeat
- ; Delay(2)
- ; i + 2
- ; If i > 10000
- ; ProcedureReturn ""
- ; EndIf
- ; Until NetworkClientEvent(ServerID) = #PB_NetworkEvent_Data
- ;
- ; Repeat
- ; DataLength = ReceiveNetworkData(ServerID,*Buffer,1000)
- ; ;Debug PeekS(*Buffer,DataLength,#PB_Ascii)
- ; String + PeekS(*Buffer,DataLength,#PB_Ascii)
- ; Bytes + DataLength
- ; Until DataLength = 0 Or (maxbytes > 0 And bytes > maxbytes)
- ;
- ; FreeMemory(*Buffer)
- ;
- ; ;Debug String
- ; i = FindString(String,#CRLF$+#CRLF$,1)
- ; String = Mid(String,i+4,Len(String)-i-3)
- ; ProcedureReturn String
- ; Else
- ; ProcedureReturn ""
- EndIf
- EndProcedure
- Procedure KillProcess(pid)
- phandle = OpenProcess_(#PROCESS_TERMINATE, #False, pid)
- If phandle <> #Null
- If TerminateProcess_(phandle, 1)
- result = #True
- EndIf
- CloseHandle_(phandle)
- EndIf
- ProcedureReturn result
- EndProcedure
- Procedure CheckMods(path.s)
- If secret = outsecret
- ProcedureReturn #True
- EndIf
- If ExamineDirectory(1,path,"*.*")
- While NextDirectoryEntry(1)
- Bad = #False
- Found = #False
- If DirectoryEntryType(1) = #PB_DirectoryEntry_File
- ForEach AllowedMods()
- If DirectoryEntryName(1) = AllowedMods()\filename
- Found = #True
- If Not MD5FileFingerprint(path + "\" + DirectoryEntryName(1)) = AllowedMods()\md5
- Bad = #True
- Break
- EndIf
- EndIf
- If Found
- Break
- EndIf
- Next
- If (Bad And Found) Or (Not Found)
- If Not DeleteFile(path + "\" + DirectoryEntryName(1))
- AddToLog("failed to delete non-whitelisted mod `" + DirectoryEntryName(1) + "`",#m_error)
- ProcedureReturn #False
- Else
- AddToLog("deleting non-whitelisted mod `" + DirectoryEntryName(1) + "`",#m_info)
- EndIf
- EndIf
- EndIf
- Wend
- FinishDirectory(1)
- AddToLog("modcheck done",#m_info)
- ProcedureReturn #True
- EndIf
- ProcedureReturn #False
- EndProcedure
- Procedure Protect(pid)
- ProcedureReturn #True
- EndProcedure
- Procedure FindJava()
- If FileSize(MyPath + "java") = -2
- Java64bits = #False
- JavaVersion = "internal 32-bit"
- JavaPath = MyPath + "java\bin"
- ProcedureReturn #True
- EndIf
- SystemDrive.s = GetEnvironmentVariable("SYSTEMDRIVE")
- If FileSize(SystemDrive + "\Program Files\Java") = -2
- ExamineDirectory(0,SystemDrive + "\Program Files\Java","*.*")
- While NextDirectoryEntry(0)
- If DirectoryEntryType(0) = #PB_DirectoryEntry_Directory And (FindString(DirectoryEntryName(0),"jdk",1) <> 0 Or FindString(DirectoryEntryName(0),"jre",1) <> 0)
- JavaPath = SystemDrive + "\Program Files\Java\" + DirectoryEntryName(0) + "\bin"
- If FileSize(SystemDrive + "\Program Files (x86)") = -2
- JavaVersion = DirectoryEntryName(0) + " 64-bit"
- Java64bits = #True
- Else
- JavaVersion = DirectoryEntryName(0) + " 32-bit"
- Java64bits = #False
- EndIf
- EndIf
- Wend
- FinishDirectory(0)
- If Len(JavaPath) > 2
- ProcedureReturn #True
- Else
- ProcedureReturn #False
- EndIf
- ; dumb method to check if we're running on a 64-bit system
- ; todo: rewrite that asap
- ElseIf FileSize(SystemDrive + "\Program Files (x86)\Java") = -2
- ExamineDirectory(0,SystemDrive + "\Program Files (x86)\Java","*.*")
- While NextDirectoryEntry(0)
- If DirectoryEntryType(0) = #PB_DirectoryEntry_Directory And (FindString(DirectoryEntryName(0),"jdk",1) <> 0 Or FindString(DirectoryEntryName(0),"jre",1) <> 0)
- JavaPath = SystemDrive + "\Program Files (x86)\Java\" + DirectoryEntryName(0) + "\bin"
- JavaVersion = DirectoryEntryName(0) + " 32-bit"
- Java64bits = #False
- EndIf
- Wend
- FinishDirectory(0)
- If Len(JavaPath) > 2
- ProcedureReturn #True
- Else
- ProcedureReturn #False
- EndIf
- EndIf
- ProcedureReturn #False
- EndProcedure
- Procedure.q TotalMemory()
- Protected result.q,memorystatusex.MEMORYSTATUSEX,memorystatus.MEMORYSTATUS,*GlobalMemoryStatusEx,dll.i
- dll=OpenLibrary(#PB_Any,"kernel32.dll")
- If dll
- *GlobalMemoryStatusEx=GetFunction(dll,"GlobalMemoryStatusEx")
- EndIf
- If *GlobalMemoryStatusEx
- memorystatusex\dwLength=SizeOf(MEMORYSTATUSEX)
- CallFunctionFast(*GlobalMemoryStatusEx,memorystatusex)
- result=memorystatusex\ullTotalPhys
- Else
- GlobalMemoryStatus_(memorystatus)
- result=memorystatus\dwTotalPhys
- EndIf
- If dll
- CloseLibrary(dll)
- EndIf
- ProcedureReturn result
- EndProcedure
- Procedure.q AvailableMemory()
- Protected result.q,memorystatusex.MEMORYSTATUSEX,memorystatus.MEMORYSTATUS,*GlobalMemoryStatusEx,dll.i
- dll=OpenLibrary(#PB_Any,"kernel32.dll")
- If dll
- *GlobalMemoryStatusEx=GetFunction(dll,"GlobalMemoryStatusEx")
- EndIf
- If *GlobalMemoryStatusEx
- memorystatusex\dwLength=SizeOf(MEMORYSTATUSEX)
- CallFunctionFast(*GlobalMemoryStatusEx,memorystatusex)
- result=memorystatusex\ullAvailPhys
- Else
- GlobalMemoryStatus_(memorystatus)
- result=memorystatus\dwAvailPhys
- EndIf
- If dll
- CloseLibrary(dll)
- EndIf
- ProcedureReturn result
- EndProcedure
- Procedure MemorySelector()
- MemSize.q = TotalMemory() / 1024 / 1024
- AddToLog("system memory: " + Str(MemSize) + "M",#m_info)
- If MemSize > 2001 And Java64bits = #False
- NumberOfTicks = 6
- AddToLog("assuming that we can't address more than 2G, limiting ticks",#m_info)
- ElseIf MemSize < 1025
- NumberOfTicks = 3
- ElseIf MemSize < 513
- NumberOfTicks = 1
- Else
- NumberOfTicks = Round(MemSize / 256, #PB_Round_Nearest) - 2
- EndIf
- AddToLog("available ticks: " + Str(NumberOfTicks),#m_info)
- TrackBarGadget(10,120,10,270,30,1,NumberOfTicks,#PB_TrackBar_Ticks)
- EndProcedure
- ; callback for background
- Procedure WCB(WindowID, Message, wParam, lParam)
- Result = #PB_ProcessPureBasicEvents
- Select Message
- Case #WM_CTLCOLORSTATIC
- Select lparam
- Case GadgetID(1),GadgetID(3)
- SetBkMode_(wparam,#TRANSPARENT)
- SetTextColor_(wParam,$000000)
- ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
- EndSelect
- EndSelect
- ProcedureReturn Result
- EndProcedure
- Procedure LoadSettings()
- OpenPreferences("mc.ini")
- SaveLogin = ReadPreferenceString("SaveLogin","yes")
- SavePw = ReadPreferenceString("SavePw","no")
- AllocatedMemTick = ReadPreferenceString("AllocatedMemTick","default")
- JavaPathPre = ReadPreferenceString("JavaPath","default")
- SavedLogin = ReadPreferenceString("SavedLogin","")
- SavedPw = ReadPreferenceString("SavedPw","")
- iamapirate = ReadPreferenceString("iamapirate","yes")
- MCRender = ReadPreferenceString("Render","native")
- ShadersType = ReadPreferenceInteger("ShadersType",0)
- ClosePreferences()
- ProcedureReturn #True
- EndProcedure
- Procedure WriteSettings()
- If CreatePreferences("mc.ini")
- WritePreferenceString("SaveLogin",SaveLogin)
- WritePreferenceString("SavePw",SavePw)
- WritePreferenceString("AllocatedMemTick",AllocatedMemTick)
- WritePreferenceString("JavaPath",JavaPathPre)
- WritePreferenceString("Render",MCRender)
- WritePreferenceString("SavedLogin",SavedLogin)
- WritePreferenceString("SavedPw",SavedPw)
- WritePreferenceString("iamapirate",iamapirate)
- WritePreferenceInteger("ShadersType",ShadersType)
- ClosePreferences()
- ProcedureReturn #True
- Else
- ProcedureReturn #False
- EndIf
- EndProcedure
- ; force user to use predefined symbols only
- Procedure.s CheckNickname(nick.s)
- AllowedChars.s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"
- Result.s = ""
- For i = 1 To 16
- If FindString(AllowedChars,Mid(nick,i,1)) > 0
- Result = Result + Mid(nick,i,1)
- EndIf
- Next
- ProcedureReturn Result
- EndProcedure
- Procedure PreRun(mcpath.s)
- If FileSize(mcpath + "\coremods") = -2
- If DeleteDirectory(mcpath + "\coremods","*.*",#PB_FileSystem_Recursive|#PB_FileSystem_Force)
- CreateDirectory(mcpath + "\coremods")
- EndIf
- EndIf
- If CheckMods(mcpath + "\mods")
- ProcedureReturn #True
- EndIf
- ProcedureReturn #False
- EndProcedure
- Procedure RunMC(dummy)
- AddToLog("got launch signal, starting pre-run routines",#m_info)
- Running = #True
- SetEnvironmentVariable("APPDATA",MyPath)
- If Not FileSize(JavaPath + "\javaw.exe") = -1
- If (Not FileSize(MinecraftPath + "\bin\minecraft.jar") = -1) And (CreateDirectory(TempPath))
- ;If #True
- HideGadget(1,1) : HideGadget(2,1) : HideGadget(3,1) : HideGadget(4,1) : HideGadget(5,1) : HideGadget(6,1) : HideGadget(7,1) : HideGadget(500,0)
- SetGadgetState(500,1)
- #PROCESS32LIB = 9999
- If PreRun(MinecraftPath) And OpenLibrary (#PROCESS32LIB, "kernel32.dll")
- AddToLog("done pre-run routines",#m_info)
- ContainerName.s = Str(Random(10000)) + Str(Random(10000)) + Str(Random(10000))
- ;Debug GetEnvironmentVariable("CLASSPATH")
- ;MinecraftArgs.s = "-Xmx" + Str(JavaMem) + "M -Djava.library.path=bin/natives -cp %minput%;bin/jinput.jar;bin/lwjgl.jar;bin/lwjgl_util.jar net.minecraft.client.Minecraft " + GetGadgetText(2) + " " + GetGadgetText(4)
- MinecraftArgs.s = "-Xmx" + Str(JavaMem) + "M -Djava.library.path=bin/natives net.minecraft.client.Minecraft " + GetGadgetText(2) + " " + GetGadgetText(4)
- AddToLog("creating session container",#m_info)
- If CreateFile(111,TempPath + "\" + ContainerName)
- ; building minecraft data based on render
- Select MCRender
- Case "optifine"
- WriteData(111,?MCOptiBinary2,MCOptiBinSize2)
- WriteData(111,?MCOptiBinary4,MCOptiBinSize4)
- WriteData(111,?MCOptiBinary3,MCOptiBinSize3)
- WriteData(111,?MCOptiBinary1,MCOptiBinSize1)
- Default
- MCRender = "optifine"
- WriteData(111,?MCOptiBinary2,MCOptiBinSize2)
- WriteData(111,?MCOptiBinary4,MCOptiBinSize4)
- WriteData(111,?MCOptiBinary3,MCOptiBinSize3)
- WriteData(111,?MCOptiBinary1,MCOptiBinSize1)
- EndSelect
- CloseFile(111)
- SetGadgetState(500,90)
- SetEnvironmentVariable("CLASSPATH",ReplaceString(TempPath + "\" + ContainerName,"\","/") + ";bin/jinput.jar;bin/lwjgl.jar;bin/lwjgl_util.jar")
- SetGadgetState(500,100)
- HideWindow(0,1)
- authstr.s = GetGadgetText(2) + "." + Version
- checksum.s = LCase(MD5Fingerprint(@authstr,StringByteLength(authstr)))
- AddToLog("auth send",#m_info)
- AddToLog("starting minecraft",#m_info)
- AddToLog("[" + MinecraftPath + "]",#m_info)
- AddToLog("[" + JavaPath + "\javaw.exe " + "-Xmx" + Str(JavaMem) + "M -Djava.library.path=bin/natives net.minecraft.client.Minecraft " + GetGadgetText(2) + "]",#m_info)
- AddToLog("[" + MCRender + "]",#m_info)
- AddToLog("[" + Str(JavaMem) + "]",#m_info)
- Minecraft = RunProgram(JavaPath + "\javaw.exe",MinecraftArgs,MinecraftPath,#PB_Program_Open)
- MinecraftPID = ProgramID(Minecraft)
- timer = 0
- While ProgramRunning(Minecraft)
- Delay(1000)
- timer + 1
- Protect(MinecraftPID)
- Wend
- CloseLibrary(#PROCESS32LIB)
- AddToLog("minecraft terminated, removing our stuff",#m_info)
- SetEnvironmentVariable("CLASSPATH","")
- DeleteDirectory(TempPath,"*.*",#PB_FileSystem_Recursive|#PB_FileSystem_Force)
- ;DeleteDirectory(MinecraftPath + "\mods","*.*",#PB_FileSystem_Recursive|#PB_FileSystem_Force)
- If SaveLogin = "yes"
- SavedLogin = GetGadgetText(2)
- Else
- SavedLogin = ""
- EndIf
- If SavePw = "yes"
- SavedPw = GetGadgetText(4)
- If Not SavedPw = ""
- enc.s = Space(1024)
- Base64Encoder(@SavedPw,StringByteLength(SavedPw),@enc,1024)
- SavedPw = enc
- EndIf
- Else
- SavedPw = ""
- EndIf
- WriteSettings()
- AddToLog("exiting...",#m_info)
- End
- Else
- Message("Запуск Minecraft не удался!",#m_error)
- Running = #False
- HideGadget(1,0) : HideGadget(2,0) : HideGadget(3,0) : HideGadget(4,0) : HideGadget(5,0) : HideGadget(6,0) : HideGadget(7,0) : HideGadget(500,1)
- EndIf
- Else
- AddToLog("pre-run routines failed, can't continue",#m_error)
- Message("Клиент поврежден, попробуйте переустановить.",#m_error)
- End
- EndIf
- Else
- AddToLog("there's no minecraft.jar, can't continue",#m_error)
- Message("Minecraft не найден!",#m_error)
- End
- EndIf
- Else
- AddToLog("failed to find java executable, can't continue",#m_error)
- Message("Невозможно найти Java!",#m_error)
- End
- EndIf
- EndProcedure
- CreateFile(0,MyPath + "mcl.log")
- CloseFile(0)
- AddToLog("mc launcher " + Version + " started",#m_info)
- LoadSettings()
- If OpenWindow(0,#PB_Ignore,#PB_Ignore,600,400,"iSMC " + Version,#PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
- ;HideWindow(0,1)
- AddKeyboardShortcut(0,#PB_Shortcut_Escape,100)
- AddKeyboardShortcut(0,#PB_Shortcut_Return,101)
- ProgressBarGadget(500,400,360,180,20,0,100,#PB_ProgressBar_Smooth) : HideGadget(500,1)
- If JavaPathPre = "" Or JavaPathPre = "default"
- If FindJava()
- AddToLog("detected java: " + JavaVersion + " (" + JavaPath + ")",#m_info)
- Else
- AddToLog("can't find java",#m_error)
- EndIf
- Else
- JavaPath = JavaPathPre
- JavaVersion = "unknown"
- AddToLog("pre-defined java: " + JavaVersion + " (" + JavaPath + ")",#m_info)
- EndIf
- hbrBackground = CreatePatternBrush_(Background)
- SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hbrBackground)
- TextGadget(1,50,248,60,20,"логин:")
- StringGadget(2,110,245,100,20,"")
- If SaveLogin = "yes" And Not SavedLogin = ""
- SetGadgetText(2,SavedLogin)
- EndIf
- TextGadget(3,50,278,60,20,"пароль:")
- StringGadget(4,110,275,100,20,"",#PB_String_Password)
- If SavePw = "yes" And Not SavedPw = ""
- If Not SavedPw = "" And SavePw = "yes"
- dec.s = Space(1024)
- Base64Decoder(@SavedPw,StringByteLength(SavedPw),@dec,1024)
- SavedPw = dec
- EndIf
- SetGadgetText(4,SavedPw)
- EndIf
- If iamapirate = "yes"
- HideGadget(4,1)
- HideGadget(3,1)
- SetGadgetText(4,"")
- EndIf
- ImageGadget(5,535,335,48,48,PlayButton)
- ImageGadget(6,515,10,32,32,SettingsButton)
- ImageGadget(7,555,10,32,32,ExitButton)
- SetWindowCallback(@WCB(),0)
- RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
- HideWindow(0,0)
- If OpenWindow(1,#PB_Ignore,#PB_Ignore,400,200,"Настройки",#PB_Window_Invisible|#PB_Window_ScreenCentered|#PB_Window_TitleBar)
- ButtonGadget(20,140,150,130,40,"Применить")
- TextGadget(12,10,12,120,20,"Выделяемая память:")
- CheckBoxGadget(13,10,60,180,20,"Сохранять логин")
- If SaveLogin = "yes"
- SetGadgetState(13,#PB_Checkbox_Checked)
- EndIf
- CheckBoxGadget(14,10,90,180,20,"Сохранять пароль")
- If SavePw = "yes"
- SetGadgetState(14,#PB_Checkbox_Checked)
- EndIf
- CheckBoxGadget(15,10,120,180,20,"Пиратская версия")
- If iamapirate = "yes"
- SetGadgetState(15,#PB_Checkbox_Checked)
- EndIf
- TextGadget(18,210,62,60,20,"Рендер")
- ComboBoxGadget(19,270,60,120,20)
- AddGadgetItem(19,-1,"OptiFine")
- GadgetToolTip(19,"Выбор типа рендера игры")
- MCRender = "optifine"
- SetGadgetState(19,0)
- ;If Not (MCRender = "optifineglsl" Or MCRender = "optifinesglsl")
- ;HideGadget(16,1) : HideGadget(17,1) : HideGadget(22,1) : HideGadget(23,1)
- ;EndIf
- MemorySelector()
- If AllocatedMemTick = "0" Or AllocatedMemTick = "default" Or AllocatedMemTick = ""
- If TotalMemory() / 1024 / 1024 < 513
- AllocatedMemTick = "1"
- SetGadgetState(10,Val(AllocatedMemTick))
- ElseIf TotalMemory() / 1024 / 1024 < 1025
- AllocatedMemTick = "2"
- SetGadgetState(10,Val(AllocatedMemTick))
- Else
- AllocatedMemTick = "3"
- SetGadgetState(10,Val(AllocatedMemTick))
- EndIf
- Else
- If NumberOfTicks >= Val(AllocatedMemTick)
- SetGadgetState(10,Val(AllocatedMemTick))
- Else
- If TotalMemory() / 1024 / 1024 < 513
- AllocatedMemTick = "1"
- SetGadgetState(10,Val(AllocatedMemTick))
- ElseIf TotalMemory() / 1024 / 1024 < 1025
- AllocatedMemTick = "2"
- SetGadgetState(10,Val(AllocatedMemTick))
- Else
- AllocatedMemTick = "3"
- SetGadgetState(10,Val(AllocatedMemTick))
- EndIf
- EndIf
- EndIf
- JavaMem = GetGadgetState(10) * 256
- TextGadget(11,100,40,290,20,Str(GetGadgetState(10) * 256) + "M",#PB_Text_Center)
- If AvailableMemory() / 1024 / 1024 / 256 < GetGadgetState(10)
- SetGadgetColor(11,#PB_Gadget_FrontColor,$0000FF)
- Else
- SetGadgetColor(11,#PB_Gadget_FrontColor,$000000)
- EndIf
- AddToLog("available memory: " + Str(AvailableMemory() / 1024 / 1024) + "M",#m_info)
- EndIf
- EndIf
- ; main cycle
- Repeat
- ev = WaitWindowEvent(50)
- If ev = #PB_Event_Gadget
- Select EventGadget()
- Case 2
- SetGadgetText(2,CheckNickname(GetGadgetText(2)))
- stringLen = Len(GetGadgetText(2))
- SendMessage_(GadgetID(2),#EM_SETSEL,stringLen,stringLen)
- Case 5
- If EventType() = #PB_EventType_LeftClick
- CreateThread(@RunMC(),dummy)
- EndIf
- Case 10
- JavaMem = GetGadgetState(10) * 256
- SetGadgetText(11,Str(JavaMem) + "M")
- AllocatedMemTick = Str(GetGadgetState(10))
- If AvailableMemory() / 1024 / 1024 / 256 < GetGadgetState(10)
- SetGadgetColor(11,#PB_Gadget_FrontColor,$0000FF)
- Else
- SetGadgetColor(11,#PB_Gadget_FrontColor,$000000)
- EndIf
- Case 6
- If EventType() = #PB_EventType_LeftClick
- HideGadget(6,1)
- SettingsButtonChanged = 0
- SetGadgetState(6,SettingsButton)
- HideWindow(0,1)
- HideWindow(1,0)
- BringWindowToTop_(WindowID(1))
- EndIf
- Case 7
- If EventType() = #PB_EventType_LeftClick
- If SaveLogin = "yes"
- SavedLogin = GetGadgetText(2)
- Else
- SavedLogin = ""
- EndIf
- If SavePw = "yes"
- SavedPw = GetGadgetText(4)
- If Not SavedPw = ""
- enc.s = Space(1024)
- Base64Encoder(@SavedPw,StringByteLength(SavedPw),@enc,1024)
- SavedPw = enc
- EndIf
- Else
- SavedPw = ""
- EndIf
- WriteSettings()
- End
- EndIf
- Case 20
- HideWindow(1,1)
- HideWindow(0,0)
- HideGadget(6,0)
- BringWindowToTop_(WindowID(0))
- Case 22
- If EventType() = #PB_EventType_LeftClick
- ShellExecute_(#Null,"open","http://help.home-nadym.ru/MinecraftGraphics",#Null,#Null,0)
- EndIf
- Case 13
- If SaveLogin = "yes"
- SaveLogin = "no"
- Else
- SaveLogin = "yes"
- EndIf
- Case 14
- If SavePw = "yes"
- SavePw = "no"
- Else
- SavePw = "yes"
- EndIf
- Case 15
- If iamapirate = "yes"
- iamapirate = "no"
- HideGadget(4,0)
- HideGadget(3,0)
- SetGadgetText(4,"")
- Else
- iamapirate = "yes"
- HideGadget(4,1)
- HideGadget(3,1)
- SetGadgetText(4,"")
- EndIf
- Case 17
- If EventType() = #PB_EventType_Change
- Select GetGadgetState(17)
- Case 0
- ShadersType = 0
- Case 1
- ShadersType = 1
- Case 2
- ShadersType = 2
- Case 3
- ShadersType = 3
- Case 4
- ShadersType = 4
- Case 5
- ShadersType = 5
- Case 6
- ShadersType = 6
- EndSelect
- EndIf
- Case 19
- If EventType() = #PB_EventType_Change
- Select GetGadgetState(19)
- Case 0
- MCRender = "native"
- HideGadget(16,1) : HideGadget(17,1) : HideGadget(22,1) : HideGadget(23,1)
- Case 1
- MCRender = "optifine"
- HideGadget(16,1) : HideGadget(17,1) : HideGadget(22,1) : HideGadget(23,1)
- Case 2
- MCRender = "optifineglsl"
- HideGadget(16,0) : HideGadget(17,0) : HideGadget(22,0) : HideGadget(23,0)
- Case 3
- MCRender = "optifinesglsl"
- HideGadget(16,0) : HideGadget(17,0) : HideGadget(22,0) : HideGadget(23,0)
- EndSelect
- EndIf
- EndSelect
- Else
- If MouseOverGadget(0,5) And PlayButtonChanged = 0
- SetGadgetState(5,PlayButtonMin)
- PlayButtonChanged = 1
- EndIf
- If Not MouseOverGadget(0,5) And PlayButtonChanged = 1
- SetGadgetState(5,PlayButton)
- PlayButtonChanged = 0
- EndIf
- If MouseOverGadget(0,6) And SettingsButtonChanged = 0
- SetGadgetState(6,SettingsButtonMin)
- SettingsButtonChanged = 1
- EndIf
- If Not MouseOverGadget(0,6) And SettingsButtonChanged = 1
- SetGadgetState(6,SettingsButton)
- SettingsButtonChanged = 0
- EndIf
- If MouseOverGadget(0,7) And ExitButtonChanged = 0
- SetGadgetState(7,ExitButtonMin)
- ExitButtonChanged = 1
- EndIf
- If Not MouseOverGadget(0,7) And ExitButtonChanged = 1
- SetGadgetState(7,ExitButton)
- ExitButtonChanged = 0
- EndIf
- If ev = #WM_LBUTTONDOWN And WindowMouseX(0) < 600 And WindowMouseY(0) < 400 And GetActiveWindow() = 0
- SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
- EndIf
- If ev = #PB_Event_Menu And EventMenu() = 100 And Running = #False
- If SaveLogin = "yes"
- SavedLogin = GetGadgetText(2)
- Else
- SavedLogin = ""
- EndIf
- If SavePw = "yes"
- SavedPw = GetGadgetText(4)
- If Not SavedPw = ""
- enc.s = Space(1024)
- Base64Encoder(@SavedPw,StringByteLength(SavedPw),@enc,1024)
- SavedPw = enc
- EndIf
- Else
- SavedPw = ""
- EndIf
- WriteSettings()
- End
- EndIf
- If ev = #PB_Event_Menu And EventMenu() = 101 And Running = #False
- CreateThread(@RunMC(),dummy)
- EndIf
- EndIf
- Until ev = #PB_Event_CloseWindow
- ; IDE Options = PureBasic 5.20 LTS (Windows - x86)
- ; CursorPosition = 593
- ; FirstLine = 344
- ; Folding = hC5
- ; EnableXP
- ; CompileSourceDirectory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement