Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ISCS Launcher 3
- Global MyVersion = 145
- Global RunOption = 0
- ;Global UpdateInProgress = #False
- ;Global FileReceived = #False
- ; loading stuff
- UsePNGImageDecoder()
- InitNetwork()
- ; images
- Global WhiteBackground, WhiteButtonStart, WhiteButtonStartOver, WhiteButtonExit, WhiteButtonExitOver
- Global MapImage
- WhiteBackground = CatchImage(0,?WhiteBackground)
- WhiteButtonStart = CatchImage(1,?WhiteButtonStart)
- WhiteButtonStartOver = CatchImage(2,?WhiteButtonStartOver)
- WhiteButtonExit = CatchImage(3,?WhiteButtonExit)
- WhiteButtonExitOver = CatchImage(4,?WhiteButtonExitOver)
- MapImage = CatchImage(11,?MapImage)
- DataSection
- WhiteBackground:
- IncludeBinary "img\back-white.png"
- WhiteButtonStart:
- IncludeBinary "img\start.png"
- WhiteButtonStartOver:
- IncludeBinary "img\start-over.png"
- WhiteButtonExit:
- IncludeBinary "img\exit.png"
- WhiteButtonExitOver:
- IncludeBinary "img\exit-over.png"
- MapImage:
- IncludeBinary "img\tmp\map.png"
- EndDataSection
- Global RunDir.s = GetPathPart(ProgramFilename())
- ;Global RunDir.s = "S:\misc\work\inter\CS\launcher30\"
- ; z-order hack
- Procedure ForceGadgetZOrder(gadget)
- SetWindowLong_(GadgetID(gadget),#GWL_STYLE,GetWindowLong_(GadgetID(gadget),#GWL_STYLE)|#WS_CLIPSIBLINGS)
- SetWindowPos_(GadgetID(gadget),#HWND_TOP,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
- EndProcedure
- ; mouse-over hack
- 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
- ; loading settings from config
- Procedure LoadSettings(config$)
- OpenPreferences(RunDir + config$)
- Global MasterServer.s = ReadPreferenceString("MasterServer","no")
- Debug MasterServer
- Global UseAC = Val(ReadPreferenceString("UseAC","0"))
- Global OfflineMode = Val(ReadPreferenceString("Offline","0"))
- ClosePreferences()
- EndProcedure
- ; write params to ucp (or elsewhere)
- Procedure WriteSetting(config$,group$,setting$,value$)
- OpenPreferences(RunDir + config$)
- If Not Len(group$)
- WritePreferenceString(setting$,value$)
- Else
- PreferenceGroup(group$)
- WritePreferenceString(setting$,value$)
- EndIf
- ClosePreferences()
- EndProcedure
- ; query process
- Procedure QueryMasterServer(dummy)
- dwnld = #False
- If URLDownloadToFile_(0,"http://" + MasterServer + "/srvstat16",RunDir + "srvstatus.ini",0,0) = #S_OK
- dwnld = #True
- Else
- If ReceiveHTTPFile("http://" + MasterServer + "/srvstat16",RunDir + "srvstatus.ini")
- dwnld = #True
- EndIf
- EndIf
- If dwnld
- OpenPreferences("srvstatus.ini")
- Status = Val(ReadPreferenceString("Status","0"))
- Version = Val(ReadPreferenceString("Version","0"))
- If Version > MyVersion
- Global Patch.s = ReadPreferenceString("Patch","n/a")
- ClosePreferences()
- DeleteFile(RunDir + "srvstatus.ini")
- Global QueryResult = 3
- Else
- If Status = 1
- Global SServer.s = ReadPreferenceString("Server","n/a")
- Global SMap.s = ReadPreferenceString("Map","n/a")
- If SMap <> "n/a"
- Debug "http://" + MasterServer + "/maps/" + SMap + ".png"
- If ReceiveHTTPFile("http://" + MasterServer + "/maps/" + SMap + ".png",RunDir + "map.png")
- If LoadImage(10,RunDir + "map.png")
- SetGadgetState(4,ImageID(10))
- EndIf
- DeleteFile(RunDir + "map.png")
- EndIf
- EndIf
- Global SPlayers.s = ReadPreferenceString("Players","n/a")
- Global STimeleft.s = ReadPreferenceString("Timeleft","n/a")
- ClosePreferences()
- DeleteFile(RunDir + "srvstatus.ini")
- Global QueryResult = 1
- Else
- ClosePreferences()
- DeleteFile(RunDir + "srvstatus.ini")
- Global QueryResult = 2
- EndIf
- EndIf
- Else
- Global QueryResult = 0
- EndIf
- EndProcedure
- ; download patch
- Procedure DoUpdate(state)
- If state = 1
- If ReceiveHTTPFile("http://" + MasterServer + "/" + Patch,RunDir + Patch)
- Global FileReceived = #True
- EndIf
- EndIf
- EndProcedure
- Global ButtonStartChanged,ButtonExitChanged = 0
- LoadFont(1,"Courier",16,#PB_Font_Bold)
- If OpenWindow(0,#PB_Ignore,#PB_Ignore,560,480,"ISCS",#PB_Window_BorderLess | #PB_Window_ScreenCentered )
- ; load settings
- LoadSettings("iscscfg.ini")
- ImageGadget(4,300,120,200,120,MapImage)
- TextGadget(5,300,240,200,20,"map",#PB_Text_Center)
- SetGadgetFont(5,FontID(1))
- TextGadget(6,60,300,500,20,"Сервер:")
- SetGadgetFont(6,FontID(1))
- TextGadget(7,60,320,250,20,"Игроки:")
- SetGadgetFont(7,FontID(1))
- ;TextGadget(8,60,320,250,20,"Смена карты:")
- ;SetGadgetFont(8,FontID(1))
- HideGadget(4,1)
- HideGadget(5,1)
- HideGadget(6,1)
- HideGadget(7,1)
- ;HideGadget(8,1)
- ;HideWindow(0,1)
- ;StickyWindow(0,1)
- regn.i$ = CreateRoundRectRgn_(0,0,560,480,80,80)
- SetWindowRgn_(WindowID(0),regn.i$,#True)
- ;SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
- SetWindowColor(0,$c4c7c6)
- ImageGadget(0,0,0,564,480,WhiteBackground)
- ImageGadget(1,30,390,180,64,WhiteButtonStart)
- HideGadget(1,1)
- ImageGadget(2,356,390,180,64,WhiteButtonExit)
- SetGadgetColor(5,#PB_Gadget_BackColor,GetWindowColor(0))
- SetGadgetColor(6,#PB_Gadget_BackColor,GetWindowColor(0))
- SetGadgetColor(7,#PB_Gadget_BackColor,GetWindowColor(0))
- ;SetGadgetColor(8,#PB_Gadget_BackColor,GetWindowColor(0))
- ForceGadgetZOrder(0)
- ForceGadgetZOrder(1)
- ForceGadgetZOrder(2)
- ForceGadgetZOrder(4)
- ForceGadgetZOrder(5)
- ForceGadgetZOrder(6)
- ForceGadgetZOrder(7)
- ;ForceGadgetZOrder(8)
- ;SetActiveWindow(0)
- ;RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
- ;BringWindowToTop_(WindowID(0))
- If MasterServer <> "no"
- QueryThread = CreateThread(@QueryMasterServer(),dummy)
- QueryInProgress = #True
- TextGadget(100,10,300,540,20,"Запрашиваем статус сервера...",#PB_Text_Center)
- SetGadgetColor(100,#PB_Gadget_BackColor,GetWindowColor(0))
- SetGadgetFont(100,FontID(1))
- ForceGadgetZOrder(100)
- Else
- TextGadget(100,10,300,540,20,"Автономный режим",#PB_Text_Center)
- SetGadgetColor(100,#PB_Gadget_BackColor,GetWindowColor(0))
- SetGadgetFont(100,FontID(1))
- ForceGadgetZOrder(100)
- HideGadget(1,0)
- RunOption = 1
- EndIf
- ;HideWindow(0,0)
- EndIf
- Repeat
- ev = WaitWindowEvent(100)
- If #PB_Event_Gadget And (EventType() = #PB_EventType_LeftClick Or EventType() = #PB_EventType_DragStart)
- Select EventGadget()
- Case 0
- If Not QueryInProgress
- SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
- EndIf
- Case 2
- ev=#PB_Event_CloseWindow
- Case 1
- If RunOption = 1
- Debug "just run"
- HideWindow(0,1)
- If FileSize(RunDir + "cs_data\hl.exe") > 0
- RunProgram("cs_data\hl.exe","-console -game cstrike",RunDir + "cs_data\")
- End
- Else
- MessageRequester("Ошибка!","CS не найден. Попробуйте переустановить клиент.")
- EndIf
- HideWindow(0,0)
- Else
- If UseAC = 1
- Debug "run with AC"
- HideWindow(0,1)
- If FileSize(RunDir + "cs_data\ucp.exe") > 0
- If ProgramParameter() = "-offline" Or OfflineMode = 1 Or GetAsyncKeyState_(#VK_SHIFT) <> 0
- WriteSetting("cs_data\ucp.ini","Settings","Parameters","-nojoy -nomaster -nointro -game cstrike -appid 10 -gl -steam -console")
- RunProgram("cs_data\ucp.exe","",RunDir + "cs_data\")
- End
- Else
- WriteSetting("cs_data\ucp.ini","Settings","Parameters","-nojoy -nomaster -nointro -game cstrike -appid 10 -gl -steam -console +connect " + SServer)
- RunProgram("cs_data\ucp.exe","",RunDir + "cs_data\")
- End
- EndIf
- Else
- MessageRequester("Ошибка!","CS не найден. Попробуйте переустановить клиент.")
- EndIf
- HideWindow(0,0)
- Else
- Debug "run wo AC"
- HideWindow(0,1)
- If FileSize(RunDir + "cs_data\hl.exe") > 0
- If ProgramParameter() = "-offline" Or OfflineMode = 1 Or GetAsyncKeyState_(#VK_SHIFT) <> 0
- RunProgram("cs_data\hl.exe","-console -game cstrike +connect " + SServer,RunDir + "cs_data\")
- End
- Else
- RunProgram("cs_data\hl.exe","-console -game cstrike",RunDir + "cs_data\")
- End
- EndIf
- Else
- MessageRequester("Ошибка!","CS не найден. Попробуйте переустановить клиент.")
- EndIf
- HideWindow(0,0)
- EndIf
- EndIf
- EndSelect
- EndIf
- If MouseOverGadget(0,1) And ButtonStartChanged = 0
- SetGadgetState(1,WhiteButtonStartOver)
- ButtonStartChanged = 1
- EndIf
- If ButtonStartChanged = 1 And MouseOverGadget(0,1)=#False
- SetGadgetState(1,WhiteButtonStart)
- ButtonStartChanged = 0
- EndIf
- If MouseOverGadget(0,2) And ButtonExitChanged = 0
- SetGadgetState(2,WhiteButtonExitOver)
- ButtonExitChanged = 1
- EndIf
- If ButtonExitChanged = 1 And MouseOverGadget(0,2)=#False
- SetGadgetState(2,WhiteButtonExit)
- ButtonExitChanged = 0
- EndIf
- If QueryInProgress = #True
- If Not IsThread(QueryThread)
- QueryInProgress = #False
- Select QueryResult
- Case 0
- Debug "can't query server"
- SetGadgetText(100,"Сервер недоступен")
- ;HideGadget(100,0)
- RunOption = 2
- RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
- Case 1
- Debug "all ok"
- HideGadget(100,1)
- SetGadgetText(5,SMap)
- SetGadgetText(6,"Сервер: " + MasterServer)
- SetGadgetText(7,"Игроки: " + SPlayers)
- ;SetGadgetText(8," Время: " + STimeleft)
- HideGadget(4,0)
- HideGadget(5,0)
- HideGadget(6,0)
- HideGadget(7,0)
- ;HideGadget(8,0)
- HideGadget(1,0)
- RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
- Case 2
- Debug "server is down"
- SetGadgetText(100,"Сервер выключен")
- HideGadget(100,0)
- RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
- Case 3
- Debug "update needed"
- SetGadgetText(100,"Найдена новая версия клиента")
- HideGadget(100,0)
- RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE)
- If MessageRequester("Обновление клиента","Доступно обновление клиента. Установить патч?",#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
- UpdateThread = CreateThread(@DoUpdate(),1)
- UpdateInProgress = #True
- SetGadgetText(100,"Идет установка обновления...")
- ;RunProgram("http://" + MasterServer + "/" + Patch)
- ;ev=#PB_Event_CloseWindow
- Else
- ev=#PB_Event_CloseWindow
- EndIf
- EndSelect
- EndIf
- EndIf
- If UpdateInProgress = #True
- If Not IsThread(UpdateThread)
- UpdateInProgress = #False
- If FileReceived = #True
- RunProgram(RunDir + Patch,"/SILENT /NOCANCEL /DIR=" + Chr(34) + RunDir + Chr(34),RunDir)
- ev=#PB_Event_CloseWindow
- Else
- SetGadgetText(100,"Обновление прошло неудачно :(")
- EndIf
- EndIf
- EndIf
- Until ev=#PB_Event_CloseWindow
- ; IDE Options = PureBasic 5.20 LTS (Windows - x86)
- ; CursorPosition = 76
- ; FirstLine = 59
- ; Folding = --
- ; EnableXP
- ; CompileSourceDirectory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement