Advertisement
deseven

iscs

Oct 16th, 2013
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ISCS Launcher 3
  2.  
  3. Global MyVersion = 145
  4. Global RunOption = 0
  5. ;Global UpdateInProgress = #False
  6. ;Global FileReceived = #False
  7.  
  8. ; loading stuff
  9. UsePNGImageDecoder()
  10. InitNetwork()
  11.  
  12. ; images
  13. Global WhiteBackground, WhiteButtonStart, WhiteButtonStartOver, WhiteButtonExit, WhiteButtonExitOver
  14. Global MapImage
  15.  
  16. WhiteBackground = CatchImage(0,?WhiteBackground)
  17. WhiteButtonStart = CatchImage(1,?WhiteButtonStart)
  18. WhiteButtonStartOver = CatchImage(2,?WhiteButtonStartOver)
  19. WhiteButtonExit = CatchImage(3,?WhiteButtonExit)
  20. WhiteButtonExitOver = CatchImage(4,?WhiteButtonExitOver)
  21.  
  22. MapImage = CatchImage(11,?MapImage)
  23.  
  24. DataSection
  25.   WhiteBackground:
  26.   IncludeBinary "img\back-white.png"
  27.   WhiteButtonStart:
  28.   IncludeBinary "img\start.png"
  29.   WhiteButtonStartOver:
  30.   IncludeBinary "img\start-over.png"
  31.   WhiteButtonExit:
  32.   IncludeBinary "img\exit.png"
  33.   WhiteButtonExitOver:
  34.   IncludeBinary "img\exit-over.png"
  35.  
  36.   MapImage:
  37.   IncludeBinary "img\tmp\map.png"
  38. EndDataSection
  39.  
  40. Global RunDir.s = GetPathPart(ProgramFilename())
  41. ;Global RunDir.s = "S:\misc\work\inter\CS\launcher30\"
  42.  
  43. ; z-order hack
  44. Procedure ForceGadgetZOrder(gadget)
  45.   SetWindowLong_(GadgetID(gadget),#GWL_STYLE,GetWindowLong_(GadgetID(gadget),#GWL_STYLE)|#WS_CLIPSIBLINGS)
  46.   SetWindowPos_(GadgetID(gadget),#HWND_TOP,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
  47. EndProcedure
  48.  
  49. ; mouse-over hack
  50. Procedure.b MouseOverGadget(window.l, gadget.l, offsetX.l=0, offsetY.l=0)
  51.   gadgetX.l = GadgetX(gadget) + offsetX
  52.   gadgetY.l = GadgetY(gadget) + offsetY
  53.   gadgetW.l = GadgetWidth(gadget)
  54.   gadgetH.l = GadgetHeight(gadget)
  55.   mouseX.l = WindowMouseX(window)
  56.   mouseY.l = WindowMouseY(window)
  57.   If (mouseX >= gadgetX) And (mouseY >= gadgetY) And (mouseX <= (gadgetX + gadgetW - 1)) And (mouseY <= (gadgetY + gadgetH - 1))
  58.     ProcedureReturn #True
  59.   Else
  60.     ProcedureReturn #False
  61.   EndIf
  62. EndProcedure
  63.  
  64. ; loading settings from config
  65. Procedure LoadSettings(config$)
  66.   OpenPreferences(RunDir + config$)
  67.   Global MasterServer.s = ReadPreferenceString("MasterServer","no")
  68.   Debug MasterServer
  69.   Global UseAC = Val(ReadPreferenceString("UseAC","0"))
  70.   Global OfflineMode = Val(ReadPreferenceString("Offline","0"))
  71.   ClosePreferences()
  72. EndProcedure
  73.  
  74. ; write params to ucp (or elsewhere)
  75. Procedure WriteSetting(config$,group$,setting$,value$)
  76.   OpenPreferences(RunDir + config$)
  77.     If Not Len(group$)
  78.       WritePreferenceString(setting$,value$)
  79.     Else
  80.       PreferenceGroup(group$)
  81.       WritePreferenceString(setting$,value$)
  82.     EndIf
  83.   ClosePreferences()
  84. EndProcedure
  85.  
  86. ; query process
  87. Procedure QueryMasterServer(dummy)
  88.   dwnld = #False
  89.   If URLDownloadToFile_(0,"http://" + MasterServer + "/srvstat16",RunDir + "srvstatus.ini",0,0) = #S_OK
  90.     dwnld = #True
  91.   Else
  92.     If ReceiveHTTPFile("http://" + MasterServer + "/srvstat16",RunDir + "srvstatus.ini")
  93.       dwnld = #True
  94.     EndIf
  95.   EndIf
  96.   If dwnld
  97.     OpenPreferences("srvstatus.ini")
  98.     Status = Val(ReadPreferenceString("Status","0"))
  99.     Version = Val(ReadPreferenceString("Version","0"))
  100.     If Version > MyVersion
  101.       Global Patch.s = ReadPreferenceString("Patch","n/a")
  102.       ClosePreferences()
  103.       DeleteFile(RunDir + "srvstatus.ini")
  104.       Global QueryResult = 3
  105.     Else
  106.       If Status = 1
  107.         Global SServer.s = ReadPreferenceString("Server","n/a")
  108.         Global SMap.s = ReadPreferenceString("Map","n/a")
  109.         If SMap <> "n/a"
  110.           Debug "http://" + MasterServer + "/maps/" + SMap + ".png"
  111.           If ReceiveHTTPFile("http://" + MasterServer + "/maps/" + SMap + ".png",RunDir + "map.png")
  112.             If LoadImage(10,RunDir + "map.png")
  113.               SetGadgetState(4,ImageID(10))
  114.             EndIf
  115.             DeleteFile(RunDir + "map.png")
  116.           EndIf
  117.         EndIf    
  118.         Global SPlayers.s = ReadPreferenceString("Players","n/a")
  119.         Global STimeleft.s = ReadPreferenceString("Timeleft","n/a")
  120.         ClosePreferences()
  121.         DeleteFile(RunDir + "srvstatus.ini")
  122.         Global QueryResult = 1
  123.       Else
  124.         ClosePreferences()
  125.         DeleteFile(RunDir + "srvstatus.ini")
  126.         Global QueryResult = 2
  127.       EndIf
  128.     EndIf
  129.   Else
  130.     Global QueryResult = 0
  131.   EndIf
  132. EndProcedure
  133.  
  134. ; download patch
  135. Procedure DoUpdate(state)
  136.   If state = 1
  137.     If ReceiveHTTPFile("http://" + MasterServer + "/" + Patch,RunDir + Patch)
  138.       Global FileReceived = #True
  139.     EndIf
  140.   EndIf
  141. EndProcedure
  142.  
  143. Global ButtonStartChanged,ButtonExitChanged = 0
  144.  
  145. LoadFont(1,"Courier",16,#PB_Font_Bold)
  146.  
  147. If OpenWindow(0,#PB_Ignore,#PB_Ignore,560,480,"ISCS",#PB_Window_BorderLess | #PB_Window_ScreenCentered )
  148.   ; load settings
  149.   LoadSettings("iscscfg.ini")
  150.   ImageGadget(4,300,120,200,120,MapImage)
  151.   TextGadget(5,300,240,200,20,"map",#PB_Text_Center)
  152.   SetGadgetFont(5,FontID(1))
  153.   TextGadget(6,60,300,500,20,"Сервер:")
  154.   SetGadgetFont(6,FontID(1))
  155.   TextGadget(7,60,320,250,20,"Игроки:")
  156.   SetGadgetFont(7,FontID(1))
  157.   ;TextGadget(8,60,320,250,20,"Смена карты:")
  158.   ;SetGadgetFont(8,FontID(1))
  159.   HideGadget(4,1)
  160.   HideGadget(5,1)
  161.   HideGadget(6,1)
  162.   HideGadget(7,1)
  163.   ;HideGadget(8,1)
  164.   ;HideWindow(0,1)
  165.   ;StickyWindow(0,1)
  166.   regn.i$ = CreateRoundRectRgn_(0,0,560,480,80,80)
  167.   SetWindowRgn_(WindowID(0),regn.i$,#True)
  168.   ;SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
  169.   SetWindowColor(0,$c4c7c6)
  170.   ImageGadget(0,0,0,564,480,WhiteBackground)
  171.   ImageGadget(1,30,390,180,64,WhiteButtonStart)
  172.   HideGadget(1,1)
  173.   ImageGadget(2,356,390,180,64,WhiteButtonExit)
  174.   SetGadgetColor(5,#PB_Gadget_BackColor,GetWindowColor(0))
  175.   SetGadgetColor(6,#PB_Gadget_BackColor,GetWindowColor(0))
  176.   SetGadgetColor(7,#PB_Gadget_BackColor,GetWindowColor(0))
  177.   ;SetGadgetColor(8,#PB_Gadget_BackColor,GetWindowColor(0))
  178.   ForceGadgetZOrder(0)
  179.   ForceGadgetZOrder(1)
  180.   ForceGadgetZOrder(2)
  181.   ForceGadgetZOrder(4)
  182.   ForceGadgetZOrder(5)
  183.   ForceGadgetZOrder(6)
  184.   ForceGadgetZOrder(7)
  185.   ;ForceGadgetZOrder(8)
  186.   ;SetActiveWindow(0)
  187.   ;RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
  188.   ;BringWindowToTop_(WindowID(0))
  189.   If MasterServer <> "no"
  190.     QueryThread = CreateThread(@QueryMasterServer(),dummy)
  191.     QueryInProgress = #True
  192.     TextGadget(100,10,300,540,20,"Запрашиваем статус сервера...",#PB_Text_Center)
  193.     SetGadgetColor(100,#PB_Gadget_BackColor,GetWindowColor(0))
  194.     SetGadgetFont(100,FontID(1))
  195.     ForceGadgetZOrder(100)
  196.   Else
  197.     TextGadget(100,10,300,540,20,"Автономный режим",#PB_Text_Center)
  198.     SetGadgetColor(100,#PB_Gadget_BackColor,GetWindowColor(0))
  199.     SetGadgetFont(100,FontID(1))
  200.     ForceGadgetZOrder(100)
  201.     HideGadget(1,0)
  202.     RunOption = 1
  203.   EndIf
  204.   ;HideWindow(0,0)
  205. EndIf
  206.  
  207. Repeat
  208.   ev = WaitWindowEvent(100)
  209.   If #PB_Event_Gadget And (EventType() = #PB_EventType_LeftClick Or EventType() = #PB_EventType_DragStart)
  210.     Select EventGadget()
  211.       Case 0
  212.           If Not QueryInProgress
  213.             SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
  214.           EndIf
  215.       Case 2
  216.         ev=#PB_Event_CloseWindow
  217.       Case 1
  218.         If RunOption = 1
  219.           Debug "just run"
  220.           HideWindow(0,1)
  221.           If FileSize(RunDir + "cs_data\hl.exe") > 0
  222.             RunProgram("cs_data\hl.exe","-console -game cstrike",RunDir + "cs_data\")
  223.             End
  224.           Else
  225.             MessageRequester("Ошибка!","CS не найден. Попробуйте переустановить клиент.")
  226.           EndIf
  227.           HideWindow(0,0)
  228.         Else
  229.           If UseAC = 1
  230.             Debug "run with AC"
  231.             HideWindow(0,1)
  232.             If FileSize(RunDir + "cs_data\ucp.exe") > 0
  233.               If ProgramParameter() = "-offline" Or OfflineMode = 1 Or GetAsyncKeyState_(#VK_SHIFT) <> 0
  234.                 WriteSetting("cs_data\ucp.ini","Settings","Parameters","-nojoy -nomaster -nointro -game cstrike -appid 10 -gl -steam -console")
  235.                 RunProgram("cs_data\ucp.exe","",RunDir + "cs_data\")
  236.                 End
  237.               Else
  238.                 WriteSetting("cs_data\ucp.ini","Settings","Parameters","-nojoy -nomaster -nointro -game cstrike -appid 10 -gl -steam -console +connect " + SServer)
  239.                 RunProgram("cs_data\ucp.exe","",RunDir + "cs_data\")
  240.                 End
  241.               EndIf
  242.             Else
  243.               MessageRequester("Ошибка!","CS не найден. Попробуйте переустановить клиент.")
  244.             EndIf
  245.             HideWindow(0,0)
  246.           Else
  247.             Debug "run wo AC"
  248.             HideWindow(0,1)
  249.             If FileSize(RunDir + "cs_data\hl.exe") > 0
  250.               If ProgramParameter() = "-offline" Or OfflineMode = 1 Or GetAsyncKeyState_(#VK_SHIFT) <> 0
  251.                 RunProgram("cs_data\hl.exe","-console -game cstrike +connect " + SServer,RunDir + "cs_data\")
  252.                 End
  253.               Else
  254.                 RunProgram("cs_data\hl.exe","-console -game cstrike",RunDir + "cs_data\")
  255.                 End
  256.               EndIf
  257.             Else
  258.               MessageRequester("Ошибка!","CS не найден. Попробуйте переустановить клиент.")
  259.             EndIf
  260.             HideWindow(0,0)
  261.           EndIf
  262.         EndIf
  263.     EndSelect
  264.   EndIf
  265.   If MouseOverGadget(0,1) And ButtonStartChanged = 0
  266.     SetGadgetState(1,WhiteButtonStartOver)
  267.     ButtonStartChanged = 1
  268.   EndIf
  269.   If ButtonStartChanged = 1 And MouseOverGadget(0,1)=#False
  270.     SetGadgetState(1,WhiteButtonStart)
  271.     ButtonStartChanged = 0
  272.   EndIf
  273.   If MouseOverGadget(0,2) And ButtonExitChanged = 0
  274.     SetGadgetState(2,WhiteButtonExitOver)
  275.     ButtonExitChanged = 1
  276.   EndIf
  277.   If ButtonExitChanged = 1 And MouseOverGadget(0,2)=#False
  278.     SetGadgetState(2,WhiteButtonExit)
  279.     ButtonExitChanged = 0
  280.   EndIf
  281.   If QueryInProgress = #True
  282.     If Not IsThread(QueryThread)
  283.       QueryInProgress = #False
  284.       Select QueryResult
  285.         Case 0
  286.           Debug "can't query server"
  287.           SetGadgetText(100,"Сервер недоступен")
  288.           ;HideGadget(100,0)
  289.           RunOption = 2
  290.           RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
  291.         Case 1
  292.           Debug "all ok"
  293.           HideGadget(100,1)
  294.           SetGadgetText(5,SMap)
  295.           SetGadgetText(6,"Сервер: " + MasterServer)
  296.           SetGadgetText(7,"Игроки: " + SPlayers)
  297.           ;SetGadgetText(8," Время: " + STimeleft)
  298.           HideGadget(4,0)
  299.           HideGadget(5,0)
  300.           HideGadget(6,0)
  301.           HideGadget(7,0)
  302.           ;HideGadget(8,0)
  303.           HideGadget(1,0)
  304.           RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
  305.         Case 2
  306.           Debug "server is down"
  307.           SetGadgetText(100,"Сервер выключен")
  308.           HideGadget(100,0)
  309.           RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
  310.         Case 3
  311.           Debug "update needed"
  312.           SetGadgetText(100,"Найдена новая версия клиента")
  313.           HideGadget(100,0)
  314.           RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
  315.           If MessageRequester("Обновление клиента","Доступно обновление клиента. Установить патч?",#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
  316.             UpdateThread = CreateThread(@DoUpdate(),1)
  317.             UpdateInProgress = #True
  318.             SetGadgetText(100,"Идет установка обновления...")
  319.             ;RunProgram("http://" + MasterServer + "/" + Patch)
  320.             ;ev=#PB_Event_CloseWindow
  321.           Else
  322.             ev=#PB_Event_CloseWindow
  323.           EndIf
  324.       EndSelect
  325.     EndIf
  326.   EndIf
  327.   If UpdateInProgress = #True
  328.     If Not IsThread(UpdateThread)
  329.       UpdateInProgress = #False
  330.       If FileReceived = #True
  331.         RunProgram(RunDir + Patch,"/SILENT /NOCANCEL /DIR=" + Chr(34) + RunDir + Chr(34),RunDir)
  332.         ev=#PB_Event_CloseWindow
  333.       Else
  334.         SetGadgetText(100,"Обновление прошло неудачно :(")
  335.       EndIf
  336.     EndIf
  337.   EndIf
  338. Until ev=#PB_Event_CloseWindow
  339. ; IDE Options = PureBasic 5.20 LTS (Windows - x86)
  340. ; CursorPosition = 76
  341. ; FirstLine = 59
  342. ; Folding = --
  343. ; EnableXP
  344. ; CompileSourceDirectory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement