//string browseMapDir, browseTextureDir;
    void Button_clicked(OxGUI sender)
    {
        #region Main Menu
        if (sender == viewLiveButton)
        {
            currentMenu = Menu.Live;
        }
        if (sender == viewReplaysButton)
        {
            currentMenu = Menu.Replays;
        }
        if (sender == viewMapsButton)
        {
            currentMenu = Menu.Maps;
            if (BSPMap.loadedMaps.Count > 0)
            {
                BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].SetVisibility(true);
            }
        }
        if (sender == settingsButton)
        {
            currentMenu = Menu.Settings;
        }
        if (sender == exitButton)
        {
            Application.Quit();
        }
        #endregion

        #region Live Menu
        if (sender == connectButton)
        {
            currentMenu   = Menu.ReplayInterface;
            currentReplay = new Demo(addressBox.text, true);
            currentReplay.ParseReplay();
            Camera.main.transform.GetComponent <CameraControl>().blockControl = false;
        }
        #endregion

        #region Replays Menu
        if (sender == importReplayButton)
        {
            Demo loadedReplay = new Demo(replayFileList.text, false);
            loadedReplay.ParseReplay();
            if (!loadedReplay.alreadyParsed)
            {
                loadedReplay.demoMap.SetVisibility(false);
            }
            RefreshReplaysList();
        }
        if (sender == watchReplayButton)
        {
            //currentReplay = Demo.loadedDemos[loadedReplayList.SelectedIndex()];
            currentReplay = Demo.loadedDemos[loadedReplayList.items[loadedReplayList.selectedIndex].text];
            currentMenu   = Menu.ReplayInterface;
            currentReplay.demoMap.SetVisibility(true);
            Camera.main.transform.GetComponent <CameraControl>().blockControl = false;
        }
        if (sender == removeReplayButton)
        {
            if (Demo.loadedDemos.Count > 0)
            {
                //Demo.loadedDemos[loadedReplayList.SelectedIndex()].SelfDestruct();
                Demo.loadedDemos[loadedReplayList.items[loadedReplayList.selectedIndex].text].SelfDestruct();
                RefreshReplaysList();
            }
        }
        #endregion

        #region Replay Interface
        if (sender == playButton)
        {
            if (currentReplay != null)
            {
                currentReplay.play = !currentReplay.play;

                if (currentReplay.play)
                {
                    playButton.text = "Pause";
                }
                else
                {
                    playButton.text = "Play";
                }
            }
        }
        #endregion

        #region Map Menu
        if (sender == loadMapButton)
        {
            //Debug.Log("Displaying: " + mapFileChooser.text);
            BSPMap loadedMap = new BSPMap(mapFileChooser.text.Substring(mapFileChooser.text.LastIndexOf("/") + 1));
            if (!loadedMap.alreadyMade)
            {
                //CoroutineRunner(loadedMap.BuildMap);
                loadedMap.BuildMap();
                if (BSPMap.loadedMaps.Count > 1)
                {
                    BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].SetVisibility(false);
                }
                currentMap = BSPMap.loadedMaps.Count - 1;
            }
        }
        if (sender == nextMapButton)
        {
            if (currentMap < BSPMap.loadedMaps.Count - 1)
            {
                //GameObject prevMap = BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].mapGameObject;
                BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].SetVisibility(false);
                currentMap++;
                //GameObject theMap = BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].mapGameObject;
                BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].SetVisibility(true);
            }
        }
        if (sender == exploreMapButton)
        {
            currentMenu = Menu.ExploreInterface;
            Camera.main.transform.GetComponent <CameraControl>().blockControl = false;
        }
        if (sender == prevMapButton)
        {
            if (currentMap > 0)
            {
                //GameObject prevMap = BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].mapGameObject;
                BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].SetVisibility(false);
                currentMap--;
                //GameObject theMap = BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].mapGameObject;
                BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].SetVisibility(true);
            }
        }
        #endregion

        #region Settings Menu
        if (sender == browseMapsLocationButton)
        {
            //browseMapDir = BSPMap.mapsDir.Substring(0, BSPMap.mapsDir.Length - 1);
            mapDirChooser.FillBrowserList(ApplicationPreferences.mapsDir.Substring(0, ApplicationPreferences.mapsDir.Length - 1), false);
            currentMenu = Menu.MapDir;
        }
        if (sender == browseTexturesLocationButton)
        {
            //browseTextureDir = BSPMap.texturesDir.Substring(0, BSPMap.texturesDir.Length - 1);
            textureDirChooser.FillBrowserList(ApplicationPreferences.texturesDir.Substring(0, ApplicationPreferences.texturesDir.Length - 1), false);
            currentMenu = Menu.TextureDir;
        }
        if (sender == browseModelsLocationButton)
        {
            modelDirChooser.FillBrowserList(ApplicationPreferences.modelsDir.Substring(0, ApplicationPreferences.modelsDir.Length - 1), false);
            currentMenu = Menu.ModelDir;
        }
        #endregion

        #region General Buttons
        if (sender == backButton)
        {
            if (currentMenu == Menu.Live || currentMenu == Menu.Replays || currentMenu == Menu.Settings)
            {
                currentMenu = Menu.Main;
            }
            if (currentMenu == Menu.Maps)
            {
                if (BSPMap.loadedMaps.Count > 0)
                {
                    BSPMap.loadedMaps[BSPMap.loadedMaps.Keys.ElementAt(currentMap)].SetVisibility(false);
                }
                currentMenu = Menu.Main;
            }
            if (currentMenu == Menu.ReplayInterface)
            {
                bool live = false;
                if (currentReplay != null)
                {
                    if (currentReplay.port > -1)
                    {
                        live = true;
                    }
                    currentReplay.Stop();
                    if (currentReplay.demoMap != null)
                    {
                        currentReplay.demoMap.SetVisibility(false);
                    }
                    currentReplay = null;
                }
                if (live)
                {
                    currentMenu = Menu.Live;
                }
                else
                {
                    currentMenu = Menu.Replays;
                }
                Camera.main.transform.GetComponent <CameraControl>().blockControl = true;
                Camera.main.transform.GetComponent <CameraControl>().GoToDefault();
            }
            if (currentMenu == Menu.ExploreInterface)
            {
                currentMenu = Menu.Maps;
                Camera.main.transform.GetComponent <CameraControl>().blockControl = true;
                Camera.main.transform.GetComponent <CameraControl>().GoToDefault();
            }
        }
        #endregion
    }
Beispiel #2
0
    public void ParseReplay()
    {
        if (port > -1)
        {
            if (gotvSocket == null)
            {
                gotvSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                gotvSocket.ReceiveTimeout = 500;
                gotvSocket.SendTimeout    = 500;
                gotvEndPoint = new IPEndPoint(IPAddress.Parse(locationToParse), port);
                gotvSocket.Connect(gotvEndPoint);

                byte[] clientMessage;
                byte[] gotvReply;

                short header          = -1;
                short protocolVersion = -1;
                int   challengeNum    = -1;

                try
                {
                    clientMessage = GetBytesUTF16("\xff\xff\xff\xff" + "qconnect" + "0x00000000" + "\x00");
                    //initialConnect = HexStringToByteArray("ffffffff" + StringToHexString("qconnect") + StringToHexString("0x00000000") + "00");
                    //initialConnect = System.Text.Encoding.ASCII.GetBytes("");
                    gotvSocket.Send(clientMessage);
                }
                catch (Exception e) { Debug.Log(e.Message); }

                try
                {
                    gotvReply = new byte[59];
                    gotvSocket.Receive(gotvReply);

                    header          = (short)gotvReply[4];
                    challengeNum    = BitConverter.ToInt32(gotvReply, 5);
                    protocolVersion = BitConverter.ToInt16(gotvReply, 42);
                    //Debug.Log("Connect Reply: " + GetStringUTF16(gotvReply));
                    Debug.Log("Header: " + header + " Challenge Number: " + challengeNum + " Protocol Version: " + protocolVersion);

                    //Debug.Log("Before BZip2: " + System.Text.Encoding.Default.GetString(gotvReply));
                    //System.IO.MemoryStream decompressed = new System.IO.MemoryStream();
                    //BZip2.Decompress(new NetworkStream(gotvSocket), decompressed, true);
                    //gotvReply = new byte[((int)decompressed.Length)];
                    //decompressed.Read(gotvReply, 0, gotvReply.Length);
                    //Debug.Log("After BZip2: " + System.Text.Encoding.Default.GetString(gotvReply));
                }
                catch (Exception e) { Debug.Log(e.Message); }

                if (challengeNum > -1)
                {
                    try
                    {
                        //clientMessage = HexStringToByteArray("ffffffff6bc734000003000000cdf23a000037423436324445443235454644424531414633323436343445423143463832463834433437453836414344344242323437464231353042453131363746353330000110aa010aa7010a0d120931363935353539383018010a0512013118030a0512013018040a0512013018050a0a1206546865204f7818060a0512013218070a0512013118080a061202363418090a0612022430180a0a05120130180b0a05120131180c0a05120133180d0a0612023634180e0a08120431323030180f0a091205383030303018100a0512013118110a0512013118120a091205302e30333118130a0512013018140a05120134181500000000000000000200000000e4011870361402002002280000005a027168f64ee8a51970361402002002fa95c3ac300000000200000004000000048648b30100000008b74e00040000006401000064000000080000001870361402002002b4050000048648b3d9005081010000005c7cbcac5cdbf3ac02001aa60100000000001e4fefdd838a1de4c1f4b33cf21e98fef558760080cc9db102a76836b8b68f78b469e2da01293a6091e290e3dd0f6bf4d2cc542e2fa687c1c2d5542b9d00d0d1d442501a51306945c05951152302ddd615362f66e2ebe6c68bfabdac0c32b416eb4e74df967f825c815f45ca9ef460c68545c4a81629a00a48c106b3dd89f98501");
                        clientMessage = GetBytesUTF16(GenerateChallengePacket(challengeNum, protocolVersion));
                        gotvSocket.Send(clientMessage);
                    }
                    catch (Exception e) { Debug.Log(e.Message); }
                }
            }
        }
        else if (!alreadyParsed)
        {
            System.IO.FileStream replayFile = new System.IO.FileStream(locationToParse, System.IO.FileMode.Open);
            demoParser               = new DemoInfo.DemoParser(replayFile);
            demoParser.TickDone     += demoParser_TickDone;
            demoParser.HeaderParsed += demoParser_HeaderParsed;
            demoParser.ParseHeader();
            demoParser.ParseToEnd();
            replayFile.Close();

            if (BSPMap.loadedMaps.ContainsKey(demoParser.Map))
            {
                demoMap = BSPMap.loadedMaps[demoParser.Map];
            }
            else
            {
                demoMap = new BSPMap(demoParser.Map);
                //Camera.main.GetComponent<ProgramInterface>().CoroutineRunner(demoMap.BuildMap);
                demoMap.BuildMap();
            }

            demoParser.Dispose();
        }
    }