Advertisement
deseven

mc

Jun 14th, 2013
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; mc launcher
  2.  
  3. #m_info = 0
  4. #m_error = 1
  5. #m_question = 2
  6.  
  7. Global Version.s = "1.4-R4"
  8. Global MyName.s = "Minecraft " + Version
  9. Global MyPath.s = GetPathPart(ProgramFilename())
  10. Global MinecraftPath.s = MyPath + ".minecraft"
  11. Global secret.s = ""
  12. Global param.s = ProgramParameter(0)
  13. Global outsecret.s = MD5Fingerprint(@param,Len(param))
  14. Debug outsecret
  15. Debug ProgramParameter(0)
  16. ;Global MinecraftPath.s = GetEnvironmentVariable("APPDATA") + "\.minecraft"
  17. ;Global TaskKillPath.s = GetEnvironmentVariable("WINDIR") + "\system32\taskkill.exe"
  18. Global UniqueSessionName.s = Str(Random(10000)) + Str(Random(10000)) + Str(Random(10000))
  19. ;Global TempPath.s = GetEnvironmentVariable("TEMP") + "\" + MD5Fingerprint(@UniqueSessionName,Len(UniqueSessionName))
  20. Global TempPath.s = MyPath + "\sess_" + MD5Fingerprint(@UniqueSessionName,Len(UniqueSessionName))
  21. Global JavaPath.s = ""
  22. Global JavaVersion.s = ""
  23. Global Java64bits = #False
  24. Global JavaMem
  25. Global timer = 0
  26. Global SaveLogin.s,SavePw.s,AllocatedMemTick.s,SavedLogin.s,SavedPw.s,iamapirate.s,JavaPathPre.s,NumberOfTicks.i,ShadersType.i,MCRender.s
  27. Global PlayButtonChanged,SettingsButtonChanged,ExitButtonChanged
  28. Global Running = #False
  29. Global RunThread
  30. Global checksum.s
  31.  
  32. InitNetwork()
  33.  
  34. UsePNGImageDecoder()
  35.  
  36. Background = CatchImage(0,?Background)
  37. PlayButton = CatchImage(1,?PlayButton)
  38. PlayButtonMin = CatchImage(2,?PlayButtonMin)
  39. SettingsButton = CatchImage(3,?SettingsButton)
  40. SettingsButtonMin = CatchImage(4,?SettingsButtonMin)
  41. ExitButton = CatchImage(5,?ExitButton)
  42. ExitButtonMin = CatchImage(6,?ExitButtonMin)
  43.  
  44. DataSection
  45.  
  46.   ; graphics
  47.   Background:
  48.   IncludeBinary "back.bmp"
  49.   PlayButton:
  50.   IncludeBinary "play.png"
  51.   PlayButtonMin:
  52.   IncludeBinary "play_min.png"
  53.   SettingsButton:
  54.   IncludeBinary "settings.png"
  55.   SettingsButtonMin:
  56.   IncludeBinary "settings_min.png"
  57.   ExitButton:
  58.   IncludeBinary "exit.png"
  59.   ExitButtonMin:
  60.   IncludeBinary "exit_min.png"
  61.  
  62.   ; minecraft data
  63.   MCOptiBinary1:
  64.   IncludeBinary "mc.opti.bin.004"
  65.   MCOptiBinary2:
  66.   IncludeBinary "mc.opti.bin.001"
  67.   MCOptiBinary3:
  68.   IncludeBinary "mc.opti.bin.003"
  69.   MCOptiBinary4:
  70.   IncludeBinary "mc.opti.bin.002"
  71.   ; end marker
  72.   MCEnd:
  73.  
  74. EndDataSection
  75.  
  76. ; size calculation for later extraction
  77. Global MCOptiBinSize1.i = ?MCOptiBinary2 - ?MCOptiBinary1
  78. Global MCOptiBinSize2.i = ?MCOptiBinary3 - ?MCOptiBinary2
  79. Global MCOptiBinSize3.i = ?MCOptiBinary4 - ?MCOptiBinary3
  80. Global MCOptiBinSize4.i = ?MCEnd - ?McOptiBinary4
  81.  
  82. Structure mods
  83.   filename.s
  84.   md5.s
  85. EndStructure
  86.  
  87. Global NewList AllowedMods.mods()
  88.  
  89. AddElement(AllowedMods())
  90. AllowedMods()\filename = "example.jar"
  91. AllowedMods()\md5 = LCase("5345BFE911D00F81659B5AADEE708F34")
  92.  
  93. Procedure AddToLog(message.s,type)
  94.   OpenFile(0,MyPath + "mcl.log",#PB_File_SharedRead|#PB_File_Append)
  95.   time.s = FormatDate("%yyyy/%mm/%dd - %hh:%ii:%ss",Date())
  96.   Select type
  97.     Case #m_info
  98.       WriteStringN(0,time + " [INFO] " + message)
  99.     Case #m_error
  100.       WriteStringN(0,time + " [ERROR] " + message)
  101.     Default
  102.       WriteStringN(0,time + " [INFO] " + message)
  103.   EndSelect
  104.   CloseFile(0)
  105.   ProcedureReturn #True
  106. EndProcedure
  107.  
  108. Procedure Message(message.s,type)
  109.   Select type
  110.     Case #m_error
  111.       MessageBox_(0,message,MyName,#MB_OK|#MB_ICONERROR)
  112.     Case #m_info
  113.       MessageBox_(0,message,MyName,#MB_OK|#MB_ICONINFORMATION)
  114.     Case #m_question
  115.       If MessageBox_(0,message,MyName,#MB_YESNO|#MB_ICONQUESTION) = #IDYES
  116.         ProcedureReturn #True
  117.       Else
  118.         ProcedureReturn #False
  119.       EndIf
  120.     Default
  121.       MessageBox_(0,message,MyName,#MB_OK|#MB_ICONINFORMATION)
  122.   EndSelect
  123.   ProcedureReturn #True
  124. EndProcedure
  125.  
  126. Procedure.b MouseOverGadget(window.l, gadget.l, offsetX.l=0, offsetY.l=0)
  127.   gadgetX.l = GadgetX(gadget) + offsetX
  128.   gadgetY.l = GadgetY(gadget) + offsetY
  129.   gadgetW.l = GadgetWidth(gadget)
  130.   gadgetH.l = GadgetHeight(gadget)
  131.   mouseX.l = WindowMouseX(window)
  132.   mouseY.l = WindowMouseY(window)
  133.   If (mouseX >= gadgetX) And (mouseY >= gadgetY) And (mouseX <= (gadgetX + gadgetW - 1)) And (mouseY <= (gadgetY + gadgetH - 1))
  134.     ProcedureReturn #True
  135.   Else
  136.     ProcedureReturn #False
  137.   EndIf
  138. EndProcedure
  139.  
  140. Procedure.s DownloadToMemory(URL.s,maxbytes=0)
  141.   Protected ServerID.l, Header.s, *Buffer = AllocateMemory(1000), String.s, Server.s, Path.s, i.l, DataLength.l,Bytes.l
  142.  
  143.   URL = RemoveString(URL,"http://",1)
  144.   i = FindString(URL,"/",1)
  145.   If i
  146.     Server = Left(URL,i-1)
  147.     Path = Right(URL,Len(URL)-i)
  148.   Else
  149.     Server = URL
  150.   EndIf
  151.  
  152.   ServerID = OpenNetworkConnection(Server,80)
  153.   If ServerID
  154.     ;Header for the GET request
  155.     Header = "GET /"+Path+" HTTP/1.1" + Chr(13) + Chr(10)
  156.     Header + "Accept: */*" + Chr(13) + Chr(10)
  157.     Header + "Connection: Close" + Chr(13) + Chr(10)
  158.     Header + "User-Agent: iSMC/" + Version + Chr(13) + Chr(10)
  159.     Header + "Host: "+Server + Chr(13) + Chr(10) + Chr(13) + Chr(10)
  160.    
  161.     ;SendNetworkData(ServerID,@Header,Len(Header)) ;Send the GET request
  162.     SendNetworkString(ServerID,Header)
  163.     ;Debug Header
  164.    
  165.     Delay(1000)
  166.    
  167.     CloseNetworkConnection(ServerID)
  168.    
  169. ;     i = 1
  170. ;    
  171. ;     Repeat
  172. ;       Delay(2)
  173. ;       i + 2
  174. ;       If i > 10000
  175. ;         ProcedureReturn ""
  176. ;       EndIf
  177. ;     Until NetworkClientEvent(ServerID) = #PB_NetworkEvent_Data
  178. ;    
  179. ;     Repeat
  180. ;       DataLength = ReceiveNetworkData(ServerID,*Buffer,1000)
  181. ;       ;Debug PeekS(*Buffer,DataLength,#PB_Ascii)
  182. ;       String + PeekS(*Buffer,DataLength,#PB_Ascii)
  183. ;       Bytes + DataLength
  184. ;     Until DataLength = 0 Or (maxbytes > 0 And bytes > maxbytes)
  185. ;    
  186. ;     FreeMemory(*Buffer)
  187. ;    
  188. ;     ;Debug String
  189. ;     i = FindString(String,#CRLF$+#CRLF$,1)
  190. ;     String = Mid(String,i+4,Len(String)-i-3)
  191. ;     ProcedureReturn String
  192. ;   Else
  193. ;     ProcedureReturn ""
  194.   EndIf
  195. EndProcedure
  196.  
  197. Procedure KillProcess(pid)
  198.     phandle = OpenProcess_(#PROCESS_TERMINATE, #False, pid)
  199.     If phandle <> #Null
  200.         If TerminateProcess_(phandle, 1)
  201.             result = #True
  202.         EndIf
  203.         CloseHandle_(phandle)
  204.     EndIf
  205.     ProcedureReturn result
  206. EndProcedure
  207.  
  208. Procedure CheckMods(path.s)
  209.   If secret = outsecret
  210.     ProcedureReturn #True
  211.   EndIf
  212.   If ExamineDirectory(1,path,"*.*")
  213.     While NextDirectoryEntry(1)
  214.       Bad = #False
  215.       Found = #False
  216.       If DirectoryEntryType(1) = #PB_DirectoryEntry_File
  217.         ForEach AllowedMods()
  218.           If DirectoryEntryName(1) = AllowedMods()\filename
  219.             Found = #True
  220.             If Not MD5FileFingerprint(path + "\" + DirectoryEntryName(1)) = AllowedMods()\md5
  221.               Bad = #True
  222.               Break
  223.             EndIf
  224.           EndIf
  225.           If Found
  226.             Break
  227.           EndIf
  228.         Next
  229.         If (Bad And Found) Or (Not Found)
  230.           If Not DeleteFile(path + "\" + DirectoryEntryName(1))
  231.             AddToLog("failed to delete non-whitelisted mod `" + DirectoryEntryName(1) + "`",#m_error)
  232.             ProcedureReturn #False
  233.           Else
  234.             AddToLog("deleting non-whitelisted mod `" + DirectoryEntryName(1) + "`",#m_info)
  235.           EndIf
  236.         EndIf
  237.       EndIf
  238.     Wend
  239.     FinishDirectory(1)
  240.     AddToLog("modcheck done",#m_info)
  241.     ProcedureReturn #True
  242.   EndIf
  243.   ProcedureReturn #False
  244. EndProcedure
  245.  
  246. Procedure Protect(pid)
  247.   ProcedureReturn #True
  248. EndProcedure
  249.  
  250. Procedure FindJava()
  251.   If FileSize(MyPath + "java") = -2
  252.     Java64bits = #False
  253.     JavaVersion = "internal 32-bit"
  254.     JavaPath = MyPath + "java\bin"
  255.     ProcedureReturn #True
  256.   EndIf
  257.   SystemDrive.s = GetEnvironmentVariable("SYSTEMDRIVE")
  258.   If FileSize(SystemDrive + "\Program Files\Java") = -2
  259.     ExamineDirectory(0,SystemDrive + "\Program Files\Java","*.*")
  260.     While NextDirectoryEntry(0)
  261.       If DirectoryEntryType(0) = #PB_DirectoryEntry_Directory And (FindString(DirectoryEntryName(0),"jdk",1) <> 0 Or FindString(DirectoryEntryName(0),"jre",1) <> 0)
  262.         JavaPath = SystemDrive + "\Program Files\Java\" + DirectoryEntryName(0) + "\bin"
  263.         If FileSize(SystemDrive + "\Program Files (x86)") = -2
  264.           JavaVersion = DirectoryEntryName(0) + " 64-bit"
  265.           Java64bits = #True
  266.         Else
  267.           JavaVersion = DirectoryEntryName(0) + " 32-bit"
  268.           Java64bits = #False
  269.         EndIf
  270.       EndIf
  271.     Wend
  272.     FinishDirectory(0)
  273.     If Len(JavaPath) > 2
  274.       ProcedureReturn #True
  275.     Else
  276.       ProcedureReturn #False
  277.     EndIf
  278.   ; dumb method to check if we're running on a 64-bit system
  279.   ; todo: rewrite that asap
  280.   ElseIf FileSize(SystemDrive + "\Program Files (x86)\Java") = -2
  281.     ExamineDirectory(0,SystemDrive + "\Program Files (x86)\Java","*.*")
  282.     While NextDirectoryEntry(0)
  283.       If DirectoryEntryType(0) = #PB_DirectoryEntry_Directory And (FindString(DirectoryEntryName(0),"jdk",1) <> 0 Or FindString(DirectoryEntryName(0),"jre",1) <> 0)
  284.         JavaPath = SystemDrive + "\Program Files (x86)\Java\" + DirectoryEntryName(0) + "\bin"
  285.         JavaVersion = DirectoryEntryName(0) + " 32-bit"
  286.         Java64bits = #False
  287.       EndIf
  288.     Wend
  289.     FinishDirectory(0)
  290.     If Len(JavaPath) > 2
  291.       ProcedureReturn #True
  292.     Else
  293.       ProcedureReturn #False
  294.     EndIf
  295.   EndIf
  296.   ProcedureReturn #False
  297. EndProcedure
  298.  
  299. Procedure.q TotalMemory()
  300.   Protected result.q,memorystatusex.MEMORYSTATUSEX,memorystatus.MEMORYSTATUS,*GlobalMemoryStatusEx,dll.i
  301.   dll=OpenLibrary(#PB_Any,"kernel32.dll")
  302.   If dll
  303.     *GlobalMemoryStatusEx=GetFunction(dll,"GlobalMemoryStatusEx")
  304.   EndIf
  305.   If *GlobalMemoryStatusEx
  306.     memorystatusex\dwLength=SizeOf(MEMORYSTATUSEX)
  307.     CallFunctionFast(*GlobalMemoryStatusEx,memorystatusex)
  308.     result=memorystatusex\ullTotalPhys
  309.   Else
  310.     GlobalMemoryStatus_(memorystatus)
  311.     result=memorystatus\dwTotalPhys
  312.   EndIf
  313.   If dll
  314.     CloseLibrary(dll)
  315.   EndIf
  316.   ProcedureReturn result
  317. EndProcedure
  318.  
  319. Procedure.q AvailableMemory()
  320.   Protected result.q,memorystatusex.MEMORYSTATUSEX,memorystatus.MEMORYSTATUS,*GlobalMemoryStatusEx,dll.i
  321.   dll=OpenLibrary(#PB_Any,"kernel32.dll")
  322.   If dll
  323.     *GlobalMemoryStatusEx=GetFunction(dll,"GlobalMemoryStatusEx")
  324.   EndIf
  325.   If *GlobalMemoryStatusEx
  326.     memorystatusex\dwLength=SizeOf(MEMORYSTATUSEX)
  327.     CallFunctionFast(*GlobalMemoryStatusEx,memorystatusex)
  328.     result=memorystatusex\ullAvailPhys
  329.   Else
  330.     GlobalMemoryStatus_(memorystatus)
  331.     result=memorystatus\dwAvailPhys
  332.   EndIf
  333.   If dll
  334.     CloseLibrary(dll)
  335.   EndIf
  336.   ProcedureReturn result
  337. EndProcedure
  338.  
  339. Procedure MemorySelector()
  340.   MemSize.q = TotalMemory() / 1024 / 1024
  341.   AddToLog("system memory: " + Str(MemSize) + "M",#m_info)
  342.   If MemSize > 2001 And Java64bits = #False
  343.     NumberOfTicks = 6
  344.     AddToLog("assuming that we can't address more than 2G, limiting ticks",#m_info)
  345.   ElseIf MemSize < 1025
  346.     NumberOfTicks = 3
  347.   ElseIf MemSize < 513
  348.     NumberOfTicks = 1
  349.   Else
  350.     NumberOfTicks = Round(MemSize / 256, #PB_Round_Nearest) - 2
  351.   EndIf
  352.   AddToLog("available ticks: " + Str(NumberOfTicks),#m_info)
  353.   TrackBarGadget(10,120,10,270,30,1,NumberOfTicks,#PB_TrackBar_Ticks)
  354. EndProcedure
  355.  
  356. ; callback for background
  357. Procedure WCB(WindowID, Message, wParam, lParam)
  358.   Result = #PB_ProcessPureBasicEvents
  359.   Select Message
  360.     Case #WM_CTLCOLORSTATIC
  361.       Select lparam
  362.         Case GadgetID(1),GadgetID(3)
  363.           SetBkMode_(wparam,#TRANSPARENT)
  364.           SetTextColor_(wParam,$000000)
  365.           ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
  366.       EndSelect
  367.   EndSelect
  368.   ProcedureReturn Result
  369. EndProcedure
  370.  
  371. Procedure LoadSettings()
  372.   OpenPreferences("mc.ini")
  373.   SaveLogin = ReadPreferenceString("SaveLogin","yes")
  374.   SavePw = ReadPreferenceString("SavePw","no")
  375.   AllocatedMemTick = ReadPreferenceString("AllocatedMemTick","default")
  376.   JavaPathPre = ReadPreferenceString("JavaPath","default")
  377.   SavedLogin = ReadPreferenceString("SavedLogin","")
  378.   SavedPw = ReadPreferenceString("SavedPw","")
  379.   iamapirate = ReadPreferenceString("iamapirate","yes")
  380.   MCRender = ReadPreferenceString("Render","native")
  381.   ShadersType = ReadPreferenceInteger("ShadersType",0)
  382.   ClosePreferences()
  383.   ProcedureReturn #True
  384. EndProcedure
  385.  
  386. Procedure WriteSettings()
  387.   If CreatePreferences("mc.ini")
  388.     WritePreferenceString("SaveLogin",SaveLogin)
  389.     WritePreferenceString("SavePw",SavePw)
  390.     WritePreferenceString("AllocatedMemTick",AllocatedMemTick)
  391.     WritePreferenceString("JavaPath",JavaPathPre)
  392.     WritePreferenceString("Render",MCRender)
  393.     WritePreferenceString("SavedLogin",SavedLogin)
  394.     WritePreferenceString("SavedPw",SavedPw)
  395.     WritePreferenceString("iamapirate",iamapirate)
  396.     WritePreferenceInteger("ShadersType",ShadersType)
  397.     ClosePreferences()
  398.     ProcedureReturn #True
  399.   Else
  400.     ProcedureReturn #False
  401.   EndIf
  402. EndProcedure
  403.  
  404. ; force user to use predefined symbols only
  405. Procedure.s CheckNickname(nick.s)
  406.   AllowedChars.s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"
  407.   Result.s = ""
  408.   For i = 1 To 16
  409.     If FindString(AllowedChars,Mid(nick,i,1)) > 0
  410.       Result = Result + Mid(nick,i,1)
  411.     EndIf
  412.   Next
  413.   ProcedureReturn Result
  414. EndProcedure
  415.  
  416. Procedure PreRun(mcpath.s)
  417.   If FileSize(mcpath + "\coremods") = -2
  418.     If DeleteDirectory(mcpath + "\coremods","*.*",#PB_FileSystem_Recursive|#PB_FileSystem_Force)
  419.       CreateDirectory(mcpath + "\coremods")
  420.     EndIf
  421.   EndIf
  422.   If CheckMods(mcpath + "\mods")
  423.     ProcedureReturn #True
  424.   EndIf
  425.   ProcedureReturn #False
  426. EndProcedure
  427.  
  428. Procedure RunMC(dummy)
  429.   AddToLog("got launch signal, starting pre-run routines",#m_info)
  430.   Running = #True
  431.   SetEnvironmentVariable("APPDATA",MyPath)
  432.   If Not FileSize(JavaPath + "\javaw.exe") = -1
  433.     If (Not FileSize(MinecraftPath + "\bin\minecraft.jar") = -1) And (CreateDirectory(TempPath))
  434.       ;If #True
  435.       HideGadget(1,1) : HideGadget(2,1) : HideGadget(3,1) : HideGadget(4,1) : HideGadget(5,1) : HideGadget(6,1) : HideGadget(7,1) : HideGadget(500,0)
  436.       SetGadgetState(500,1)
  437.       #PROCESS32LIB = 9999
  438.       If PreRun(MinecraftPath) And OpenLibrary (#PROCESS32LIB, "kernel32.dll")
  439.         AddToLog("done pre-run routines",#m_info)
  440.         ContainerName.s = Str(Random(10000)) + Str(Random(10000)) + Str(Random(10000))
  441.         ;Debug GetEnvironmentVariable("CLASSPATH")
  442.         ;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)
  443.         MinecraftArgs.s = "-Xmx" + Str(JavaMem) + "M -Djava.library.path=bin/natives net.minecraft.client.Minecraft " + GetGadgetText(2) + " " + GetGadgetText(4)
  444.         AddToLog("creating session container",#m_info)
  445.         If CreateFile(111,TempPath + "\" + ContainerName)
  446.          
  447.           ; building minecraft data based on render
  448.           Select MCRender
  449.             Case "optifine"
  450.               WriteData(111,?MCOptiBinary2,MCOptiBinSize2)
  451.               WriteData(111,?MCOptiBinary4,MCOptiBinSize4)
  452.               WriteData(111,?MCOptiBinary3,MCOptiBinSize3)
  453.               WriteData(111,?MCOptiBinary1,MCOptiBinSize1)
  454.             Default
  455.               MCRender = "optifine"
  456.               WriteData(111,?MCOptiBinary2,MCOptiBinSize2)
  457.               WriteData(111,?MCOptiBinary4,MCOptiBinSize4)
  458.               WriteData(111,?MCOptiBinary3,MCOptiBinSize3)
  459.               WriteData(111,?MCOptiBinary1,MCOptiBinSize1)
  460.           EndSelect
  461.           CloseFile(111)
  462.          
  463.           SetGadgetState(500,90)
  464.           SetEnvironmentVariable("CLASSPATH",ReplaceString(TempPath + "\" + ContainerName,"\","/") + ";bin/jinput.jar;bin/lwjgl.jar;bin/lwjgl_util.jar")
  465.           SetGadgetState(500,100)
  466.           HideWindow(0,1)
  467.           authstr.s = GetGadgetText(2) + "." + Version
  468.           checksum.s = LCase(MD5Fingerprint(@authstr,StringByteLength(authstr)))
  469.           AddToLog("auth send",#m_info)
  470.           AddToLog("starting minecraft",#m_info)
  471.           AddToLog("[" + MinecraftPath + "]",#m_info)
  472.           AddToLog("[" + JavaPath + "\javaw.exe " + "-Xmx" + Str(JavaMem) + "M -Djava.library.path=bin/natives net.minecraft.client.Minecraft " + GetGadgetText(2) + "]",#m_info)
  473.           AddToLog("[" + MCRender + "]",#m_info)
  474.           AddToLog("[" + Str(JavaMem) + "]",#m_info)
  475.           Minecraft = RunProgram(JavaPath + "\javaw.exe",MinecraftArgs,MinecraftPath,#PB_Program_Open)
  476.           MinecraftPID = ProgramID(Minecraft)
  477.           timer = 0
  478.           While ProgramRunning(Minecraft)
  479.             Delay(1000)
  480.             timer + 1
  481.             Protect(MinecraftPID)
  482.           Wend
  483.           CloseLibrary(#PROCESS32LIB)
  484.           AddToLog("minecraft terminated, removing our stuff",#m_info)
  485.           SetEnvironmentVariable("CLASSPATH","")
  486.           DeleteDirectory(TempPath,"*.*",#PB_FileSystem_Recursive|#PB_FileSystem_Force)
  487.           ;DeleteDirectory(MinecraftPath + "\mods","*.*",#PB_FileSystem_Recursive|#PB_FileSystem_Force)
  488.           If SaveLogin = "yes"
  489.             SavedLogin = GetGadgetText(2)
  490.           Else
  491.             SavedLogin = ""
  492.           EndIf
  493.           If SavePw = "yes"
  494.             SavedPw = GetGadgetText(4)
  495.             If Not SavedPw = ""
  496.               enc.s = Space(1024)
  497.               Base64Encoder(@SavedPw,StringByteLength(SavedPw),@enc,1024)
  498.               SavedPw = enc
  499.             EndIf
  500.           Else
  501.             SavedPw = ""
  502.           EndIf
  503.           WriteSettings()
  504.           AddToLog("exiting...",#m_info)
  505.           End
  506.         Else
  507.           Message("Запуск Minecraft не удался!",#m_error)
  508.           Running = #False
  509.           HideGadget(1,0) : HideGadget(2,0) : HideGadget(3,0) : HideGadget(4,0) : HideGadget(5,0) : HideGadget(6,0) : HideGadget(7,0) : HideGadget(500,1)
  510.         EndIf
  511.       Else
  512.         AddToLog("pre-run routines failed, can't continue",#m_error)
  513.         Message("Клиент поврежден, попробуйте переустановить.",#m_error)
  514.         End
  515.       EndIf
  516.     Else
  517.       AddToLog("there's no minecraft.jar, can't continue",#m_error)
  518.       Message("Minecraft не найден!",#m_error)
  519.       End
  520.     EndIf
  521.   Else
  522.     AddToLog("failed to find java executable, can't continue",#m_error)
  523.     Message("Невозможно найти Java!",#m_error)
  524.     End
  525.   EndIf
  526. EndProcedure
  527.  
  528. CreateFile(0,MyPath + "mcl.log")
  529. CloseFile(0)
  530. AddToLog("mc launcher " + Version + " started",#m_info)
  531.  
  532. LoadSettings()
  533.  
  534. If OpenWindow(0,#PB_Ignore,#PB_Ignore,600,400,"iSMC " + Version,#PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
  535.   ;HideWindow(0,1)
  536.   AddKeyboardShortcut(0,#PB_Shortcut_Escape,100)
  537.   AddKeyboardShortcut(0,#PB_Shortcut_Return,101)
  538.   ProgressBarGadget(500,400,360,180,20,0,100,#PB_ProgressBar_Smooth) : HideGadget(500,1)
  539.   If JavaPathPre = "" Or JavaPathPre = "default"
  540.     If FindJava()
  541.       AddToLog("detected java: " + JavaVersion + " (" + JavaPath + ")",#m_info)
  542.     Else
  543.       AddToLog("can't find java",#m_error)
  544.     EndIf
  545.   Else
  546.     JavaPath = JavaPathPre
  547.     JavaVersion = "unknown"
  548.     AddToLog("pre-defined java: " + JavaVersion + " (" + JavaPath + ")",#m_info)
  549.   EndIf
  550.   hbrBackground = CreatePatternBrush_(Background)
  551.   SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hbrBackground)
  552.   TextGadget(1,50,248,60,20,"логин:")
  553.   StringGadget(2,110,245,100,20,"")
  554.   If SaveLogin = "yes" And Not SavedLogin = ""      
  555.     SetGadgetText(2,SavedLogin)
  556.   EndIf
  557.   TextGadget(3,50,278,60,20,"пароль:")
  558.   StringGadget(4,110,275,100,20,"",#PB_String_Password)
  559.   If SavePw = "yes" And Not SavedPw = ""
  560.     If Not SavedPw = "" And SavePw = "yes"
  561.       dec.s = Space(1024)
  562.       Base64Decoder(@SavedPw,StringByteLength(SavedPw),@dec,1024)
  563.       SavedPw = dec
  564.     EndIf
  565.     SetGadgetText(4,SavedPw)
  566.   EndIf
  567.   If iamapirate = "yes"
  568.     HideGadget(4,1)
  569.     HideGadget(3,1)
  570.     SetGadgetText(4,"")
  571.   EndIf
  572.   ImageGadget(5,535,335,48,48,PlayButton)
  573.   ImageGadget(6,515,10,32,32,SettingsButton)
  574.   ImageGadget(7,555,10,32,32,ExitButton)
  575.   SetWindowCallback(@WCB(),0)
  576.   RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
  577.   HideWindow(0,0)
  578.   If OpenWindow(1,#PB_Ignore,#PB_Ignore,400,200,"Настройки",#PB_Window_Invisible|#PB_Window_ScreenCentered|#PB_Window_TitleBar)
  579.     ButtonGadget(20,140,150,130,40,"Применить")
  580.     TextGadget(12,10,12,120,20,"Выделяемая память:")
  581.     CheckBoxGadget(13,10,60,180,20,"Сохранять логин")
  582.     If SaveLogin = "yes"
  583.       SetGadgetState(13,#PB_Checkbox_Checked)
  584.     EndIf
  585.     CheckBoxGadget(14,10,90,180,20,"Сохранять пароль")
  586.     If SavePw = "yes"
  587.       SetGadgetState(14,#PB_Checkbox_Checked)
  588.     EndIf
  589.     CheckBoxGadget(15,10,120,180,20,"Пиратская версия")
  590.     If iamapirate = "yes"
  591.       SetGadgetState(15,#PB_Checkbox_Checked)
  592.     EndIf
  593.     TextGadget(18,210,62,60,20,"Рендер")
  594.     ComboBoxGadget(19,270,60,120,20)
  595.     AddGadgetItem(19,-1,"OptiFine")
  596.     GadgetToolTip(19,"Выбор типа рендера игры")
  597.     MCRender = "optifine"
  598.     SetGadgetState(19,0)
  599.     ;If Not (MCRender = "optifineglsl" Or MCRender = "optifinesglsl")
  600.       ;HideGadget(16,1) : HideGadget(17,1) : HideGadget(22,1) : HideGadget(23,1)
  601.     ;EndIf
  602.     MemorySelector()
  603.     If AllocatedMemTick = "0" Or AllocatedMemTick = "default" Or AllocatedMemTick = ""
  604.       If TotalMemory() / 1024 / 1024 < 513
  605.         AllocatedMemTick = "1"
  606.         SetGadgetState(10,Val(AllocatedMemTick))
  607.       ElseIf TotalMemory() / 1024 / 1024 < 1025
  608.         AllocatedMemTick = "2"
  609.         SetGadgetState(10,Val(AllocatedMemTick))
  610.       Else
  611.         AllocatedMemTick = "3"
  612.         SetGadgetState(10,Val(AllocatedMemTick))
  613.       EndIf
  614.     Else
  615.       If NumberOfTicks >= Val(AllocatedMemTick)
  616.         SetGadgetState(10,Val(AllocatedMemTick))
  617.       Else
  618.         If TotalMemory() / 1024 / 1024 < 513
  619.           AllocatedMemTick = "1"
  620.           SetGadgetState(10,Val(AllocatedMemTick))
  621.         ElseIf TotalMemory() / 1024 / 1024 < 1025
  622.           AllocatedMemTick = "2"
  623.           SetGadgetState(10,Val(AllocatedMemTick))
  624.         Else
  625.           AllocatedMemTick = "3"
  626.           SetGadgetState(10,Val(AllocatedMemTick))
  627.         EndIf
  628.       EndIf
  629.     EndIf
  630.     JavaMem = GetGadgetState(10) * 256
  631.     TextGadget(11,100,40,290,20,Str(GetGadgetState(10) * 256) + "M",#PB_Text_Center)
  632.     If AvailableMemory() / 1024 / 1024 / 256 < GetGadgetState(10)
  633.       SetGadgetColor(11,#PB_Gadget_FrontColor,$0000FF)
  634.     Else
  635.       SetGadgetColor(11,#PB_Gadget_FrontColor,$000000)
  636.     EndIf
  637.     AddToLog("available memory: " + Str(AvailableMemory() / 1024 / 1024) + "M",#m_info)
  638.   EndIf
  639. EndIf
  640.  
  641. ; main cycle
  642. Repeat
  643.   ev = WaitWindowEvent(50)
  644.   If ev = #PB_Event_Gadget
  645.     Select EventGadget()
  646.       Case 2
  647.         SetGadgetText(2,CheckNickname(GetGadgetText(2)))
  648.         stringLen = Len(GetGadgetText(2))
  649.         SendMessage_(GadgetID(2),#EM_SETSEL,stringLen,stringLen)
  650.       Case 5
  651.         If EventType() = #PB_EventType_LeftClick
  652.           CreateThread(@RunMC(),dummy)
  653.         EndIf
  654.       Case 10
  655.         JavaMem = GetGadgetState(10) * 256
  656.         SetGadgetText(11,Str(JavaMem) + "M")
  657.         AllocatedMemTick = Str(GetGadgetState(10))
  658.         If AvailableMemory() / 1024 / 1024 / 256 < GetGadgetState(10)
  659.           SetGadgetColor(11,#PB_Gadget_FrontColor,$0000FF)
  660.         Else
  661.           SetGadgetColor(11,#PB_Gadget_FrontColor,$000000)
  662.         EndIf
  663.       Case 6
  664.         If EventType() = #PB_EventType_LeftClick
  665.           HideGadget(6,1)
  666.           SettingsButtonChanged = 0
  667.           SetGadgetState(6,SettingsButton)
  668.           HideWindow(0,1)
  669.           HideWindow(1,0)
  670.           BringWindowToTop_(WindowID(1))
  671.         EndIf
  672.       Case 7
  673.         If EventType() = #PB_EventType_LeftClick
  674.           If SaveLogin = "yes"
  675.             SavedLogin = GetGadgetText(2)
  676.           Else
  677.             SavedLogin = ""
  678.           EndIf
  679.           If SavePw = "yes"
  680.             SavedPw = GetGadgetText(4)
  681.             If Not SavedPw = ""
  682.               enc.s = Space(1024)
  683.               Base64Encoder(@SavedPw,StringByteLength(SavedPw),@enc,1024)
  684.               SavedPw = enc
  685.             EndIf
  686.           Else
  687.             SavedPw = ""
  688.           EndIf
  689.           WriteSettings()
  690.           End
  691.         EndIf
  692.       Case 20
  693.         HideWindow(1,1)
  694.         HideWindow(0,0)
  695.         HideGadget(6,0)
  696.         BringWindowToTop_(WindowID(0))
  697.       Case 22
  698.         If EventType() = #PB_EventType_LeftClick
  699.           ShellExecute_(#Null,"open","http://help.home-nadym.ru/MinecraftGraphics",#Null,#Null,0)  
  700.         EndIf  
  701.       Case 13
  702.         If SaveLogin = "yes"
  703.           SaveLogin = "no"
  704.         Else
  705.           SaveLogin = "yes"
  706.         EndIf
  707.       Case 14
  708.         If SavePw = "yes"
  709.           SavePw = "no"
  710.         Else
  711.           SavePw = "yes"
  712.         EndIf
  713.       Case 15
  714.         If iamapirate = "yes"
  715.           iamapirate = "no"
  716.           HideGadget(4,0)
  717.           HideGadget(3,0)
  718.           SetGadgetText(4,"")
  719.         Else
  720.           iamapirate = "yes"
  721.           HideGadget(4,1)
  722.           HideGadget(3,1)
  723.           SetGadgetText(4,"")
  724.         EndIf
  725.       Case 17
  726.         If EventType() = #PB_EventType_Change
  727.           Select GetGadgetState(17)
  728.             Case 0
  729.               ShadersType = 0
  730.             Case 1
  731.               ShadersType = 1
  732.             Case 2
  733.               ShadersType = 2
  734.             Case 3
  735.               ShadersType = 3
  736.             Case 4
  737.               ShadersType = 4
  738.             Case 5
  739.               ShadersType = 5
  740.             Case 6
  741.               ShadersType = 6
  742.           EndSelect
  743.         EndIf
  744.       Case 19
  745.         If EventType() = #PB_EventType_Change
  746.           Select GetGadgetState(19)
  747.             Case 0
  748.               MCRender = "native"
  749.               HideGadget(16,1) : HideGadget(17,1) : HideGadget(22,1) : HideGadget(23,1)
  750.             Case 1
  751.               MCRender = "optifine"
  752.               HideGadget(16,1) : HideGadget(17,1) : HideGadget(22,1) : HideGadget(23,1)
  753.             Case 2
  754.               MCRender = "optifineglsl"
  755.               HideGadget(16,0) : HideGadget(17,0) : HideGadget(22,0) : HideGadget(23,0)
  756.             Case 3
  757.               MCRender = "optifinesglsl"
  758.               HideGadget(16,0) : HideGadget(17,0) : HideGadget(22,0) : HideGadget(23,0)
  759.           EndSelect
  760.         EndIf
  761.     EndSelect
  762.   Else
  763.     If MouseOverGadget(0,5) And PlayButtonChanged = 0
  764.       SetGadgetState(5,PlayButtonMin)
  765.       PlayButtonChanged = 1
  766.     EndIf
  767.     If Not MouseOverGadget(0,5) And PlayButtonChanged = 1
  768.       SetGadgetState(5,PlayButton)
  769.       PlayButtonChanged = 0
  770.     EndIf
  771.     If MouseOverGadget(0,6) And SettingsButtonChanged = 0
  772.       SetGadgetState(6,SettingsButtonMin)
  773.       SettingsButtonChanged = 1
  774.     EndIf
  775.     If Not MouseOverGadget(0,6) And SettingsButtonChanged = 1
  776.       SetGadgetState(6,SettingsButton)
  777.       SettingsButtonChanged = 0
  778.     EndIf
  779.     If MouseOverGadget(0,7) And ExitButtonChanged = 0
  780.       SetGadgetState(7,ExitButtonMin)
  781.       ExitButtonChanged = 1
  782.     EndIf
  783.     If Not MouseOverGadget(0,7) And ExitButtonChanged = 1
  784.       SetGadgetState(7,ExitButton)
  785.       ExitButtonChanged = 0
  786.     EndIf
  787.     If ev = #WM_LBUTTONDOWN And WindowMouseX(0) < 600 And WindowMouseY(0) < 400 And GetActiveWindow() = 0
  788.       SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
  789.     EndIf
  790.     If ev = #PB_Event_Menu And EventMenu() = 100 And Running = #False
  791.       If SaveLogin = "yes"
  792.         SavedLogin = GetGadgetText(2)
  793.       Else
  794.         SavedLogin = ""
  795.       EndIf
  796.       If SavePw = "yes"
  797.         SavedPw = GetGadgetText(4)
  798.         If Not SavedPw = ""
  799.           enc.s = Space(1024)
  800.           Base64Encoder(@SavedPw,StringByteLength(SavedPw),@enc,1024)
  801.           SavedPw = enc
  802.         EndIf
  803.       Else
  804.         SavedPw = ""
  805.       EndIf
  806.       WriteSettings()
  807.       End
  808.     EndIf
  809.     If ev = #PB_Event_Menu And EventMenu() = 101 And Running = #False
  810.       CreateThread(@RunMC(),dummy)
  811.     EndIf
  812.   EndIf
  813. Until ev = #PB_Event_CloseWindow
  814.  
  815. ; IDE Options = PureBasic 5.20 LTS (Windows - x86)
  816. ; CursorPosition = 593
  817. ; FirstLine = 344
  818. ; Folding = hC5
  819. ; EnableXP
  820. ; CompileSourceDirectory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement