Esempio n. 1
0
File: Main.cs Progetto: CHazz/DUXDMP
        public void Start()
        {
            TimingManager.FixedUpdateAdd(TimingManager.TimingStage.BetterLateThanNever, TimingManagerFixedUpdate);
            dmpDir      = Path.Combine(Path.Combine(Path.Combine(KSPUtil.ApplicationRootPath, "GameData"), "DarkMultiPlayer"), "Plugins");
            dmpDataDir  = Path.Combine(dmpDir, "Data");
            gameDataDir = Path.Combine(KSPUtil.ApplicationRootPath, "GameData");
            kspRootPath = KSPUtil.ApplicationRootPath;

            //Fix DarkLog time/thread marker in the log during init.
            DarkLog.SetMainThread();
            lastClockTicks           = DateTime.UtcNow.Ticks;
            lastRealTimeSinceStartup = 0f;

            dmpClient         = this;
            dmpSettings       = new Settings();
            toolbarSupport    = new ToolbarSupport(dmpSettings);
            universeSyncCache = new UniverseSyncCache(dmpSettings);
            modWindow         = new ModWindow();
            modWorker         = new ModWorker(modWindow);
            modWindow.SetDependenices(modWorker);
            universeConverter       = new UniverseConverter(dmpSettings);
            universeConverterWindow = new UniverseConverterWindow(universeConverter);
            optionsWindow           = new OptionsWindow(dmpSettings, universeSyncCache, modWorker, universeConverterWindow, toolbarSupport);
            connectionWindow        = new ConnectionWindow(dmpSettings, optionsWindow);
            disclaimerWindow        = new DisclaimerWindow(dmpSettings);
            dmpModInterface         = new DMPModInterface();
            SafetyBubble.RegisterDefaultLocations();

            if (!CompatibilityChecker.IsCompatible() || !InstallChecker.IsCorrectlyInstalled())
            {
                modDisabled = true;
            }

            if (dmpSettings.disclaimerAccepted != 1)
            {
                modDisabled = true;
                disclaimerWindow.SpawnDialog();
            }

            Profiler.DMPReferenceTime.Start();
            DontDestroyOnLoad(this);

            // Prevents symlink warning for development.
            SetupDirectoriesIfNeeded();

            // UniverseSyncCache needs to run expiry here
            universeSyncCache.ExpireCache();

            GameEvents.onHideUI.Add(() =>
            {
                showGUI = false;
            });
            GameEvents.onShowUI.Add(() =>
            {
                showGUI = true;
            });

            HandleCommandLineArgs();
            DarkLog.Debug("DarkMultiPlayer " + Common.PROGRAM_VERSION + ", protocol " + Common.PROTOCOL_VERSION + " Initialized!");
        }
Esempio n. 2
0
        public void Start()
        {
            if (!CompatibilityChecker.IsCompatible() || !InstallChecker.IsCorrectlyInstalled())
            {
                modDisabled = true;
            }

            if (dmpSettings.disclaimerAccepted != 1)
            {
                modDisabled = true;
                disclaimerWindow.SpawnDialog();
            }

            Profiler.DMPReferenceTime.Start();
            DontDestroyOnLoad(this);

            // Prevents symlink warning for development.
            SetupDirectoriesIfNeeded();

            // UniverseSyncCache needs to run expiry here
            universeSyncCache.ExpireCache();

            GameEvents.onHideUI.Add(() =>
            {
                showGUI = false;
            });
            GameEvents.onShowUI.Add(() =>
            {
                showGUI = true;
            });

            HandleCommandLineArgs();
            long testTime = Compression.TestSysIOCompression();

            DarkLog.Debug("System.IO compression works: " + Compression.sysIOCompressionWorks + ", test time: " + testTime + " ms.");
            DarkLog.Debug("DarkMultiPlayer " + Common.PROGRAM_VERSION + ", protocol " + Common.PROTOCOL_VERSION + " Initialized!");
        }
Esempio n. 3
0
        private void DrawContent(int windowID)
        {
            if (GUI.Button(new Rect(windowRect.width - 24, 0, 19, 19), "X"))
            {
                display = false;
            }
            //Player color
            GUI.DragWindow(moveRect);
            GUI.Box(new Rect(2, 20, windowRect.width - 4, 20), string.Empty, sectionHeaderStyle);
            selectedTab = (OptionsTab)GUILayout.Toolbar((int)selectedTab, GetOptionsTabStrings(), toolbarBtnStyle);

            int windowY = 17;

            windowY += 20 + 2;
            int groupY = 0;

            if (selectedTab == OptionsTab.PLAYER)
            {
                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 106));
                groupY = 0;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Name:", descriptorStyle);
                plrNameStyle.normal.textColor = dmpSettings.playerColor;
                if (networkWorker != null && networkWorker.state == DarkMultiPlayerCommon.ClientState.RUNNING)
                {
                    GUI.Label(new Rect(descWidth + sepWidth, groupY,
                                       windowRect.width - (descWidth + sepWidth) - 20, 20),
                              dmpSettings.playerName, plrNameStyle);
                }
                else
                {
                    string newName = GUI.TextField(new Rect(
                                                       descWidth + sepWidth,
                                                       0,
                                                       windowRect.width - (descWidth + sepWidth) - 20,
                                                       20), dmpSettings.playerName, plrNameStyle);

                    if (!newName.Equals(dmpSettings.playerName))
                    {
                        dmpSettings.playerName = newName;
                        dmpSettings.SaveSettings();
                    }
                }
                groupY += 20 + 4;


                Color playerColor = dmpSettings.playerColor;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Red:", descriptorStyle);
                playerColor.r = GUI.HorizontalSlider(new Rect(
                                                         descWidth + sepWidth,
                                                         groupY + 5,
                                                         windowRect.width - (descWidth + sepWidth) - 20,
                                                         12
                                                         ), dmpSettings.playerColor.r, 0, 1);
                groupY += 20;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Green:", descriptorStyle);
                playerColor.g = GUI.HorizontalSlider(new Rect(
                                                         descWidth + sepWidth,
                                                         groupY + 5,
                                                         windowRect.width - (descWidth + sepWidth) - 20,
                                                         12
                                                         ), dmpSettings.playerColor.g, 0, 1);
                groupY += 20;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Blue:", descriptorStyle);
                playerColor.b = GUI.HorizontalSlider(new Rect(
                                                         descWidth + sepWidth,
                                                         groupY + 5,
                                                         windowRect.width - (descWidth + sepWidth) - 20,
                                                         12
                                                         ), dmpSettings.playerColor.b, 0, 1);
                groupY += 22;

                if (GUI.Button(new Rect(0, groupY, windowRect.width - 20, 20), "Random Color", buttonStyle))
                {
                    playerColor = PlayerColorWorker.GenerateRandomColor();
                }

                if (!playerColor.Equals(dmpSettings.playerColor))
                {
                    dmpSettings.playerColor = playerColor;
                    dmpSettings.SaveSettings();

                    if (networkWorker != null && playerColorWorker != null && networkWorker.state == DarkMultiPlayerCommon.ClientState.RUNNING)
                    {
                        playerColorWorker.SendPlayerColorToServer();
                    }
                }

                GUI.EndGroup();
                // windowY += 106 + 5;
            }
            if (selectedTab == OptionsTab.CACHE)
            {
                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 84));
                groupY = 0;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Current:", descriptorStyle);
                GUI.Label(
                    new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 102, 20),
                    Mathf.Round(universeSyncCache.currentCacheSize / 1024).ToString() + " KB");

                groupY += 20;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Maximum:", descriptorStyle);
                string newSizeStr = GUI.TextField(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 152, 20), (dmpSettings.cacheSize / 1024).ToString(), textFieldStyle);
                GUI.Label(new Rect(descWidth + sepWidth + 80, groupY, 100, 20), "kilobytes (KB)");
                int newSize;
                if (string.IsNullOrEmpty(newSizeStr))
                {
                    newSize = 1;
                }
                else
                {
                    if (int.TryParse(newSizeStr, out newSize))
                    {
                        if (newSize < 1)
                        {
                            newSize = 1;
                        }
                        else if (newSize > 1000000)
                        {
                            newSize = 1000000;
                        }
                    }
                    else
                    {
                        newSize = 100000;
                    }
                }

                if (newSize != dmpSettings.cacheSize)
                {
                    dmpSettings.cacheSize = newSize * 1024;
                    dmpSettings.SaveSettings();
                }
                groupY += 22;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Manage:", descriptorStyle);
                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), "Expire"))
                {
                    universeSyncCache.ExpireCache();
                }

                groupY += 22;

                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), "Delete"))
                {
                    universeSyncCache.DeleteCache();
                }
                GUI.EndGroup();
            }
            //Key bindings
            if (selectedTab == OptionsTab.CONTROLS)
            {
                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 92));
                groupY = 0;

                GUI.Label(new Rect(0, groupY, windowRect.width - 20, 48),
                          "Click a button below to select the action you want to change. Then press a key to set the binding. To cancel, click the button again or press Escape.",
                          noteStyle);
                groupY += 48;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Chat:", descriptorStyle);
                string chatKey = dmpSettings.chatKey.ToString();
                if (settingChat)
                {
                    chatKey = settingKeyMessage;
                    if (Event.current.isKey)
                    {
                        if (Event.current.keyCode != KeyCode.Escape)
                        {
                            dmpSettings.chatKey = Event.current.keyCode;
                            dmpSettings.SaveSettings();
                        }
                        settingChat = false;
                    }
                }

                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), chatKey, buttonStyle))
                {
                    settingScreenshot = false;
                    settingChat       = !settingChat;
                }
                groupY += 22;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Screenshot:", descriptorStyle);
                string screenshotKey = dmpSettings.screenshotKey.ToString();
                if (settingScreenshot)
                {
                    screenshotKey = settingKeyMessage;
                    if (Event.current.isKey)
                    {
                        if (Event.current.keyCode != KeyCode.Escape)
                        {
                            dmpSettings.screenshotKey = Event.current.keyCode;
                            dmpSettings.SaveSettings();
                        }
                        settingScreenshot = false;
                    }
                }

                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), screenshotKey, buttonStyle))
                {
                    settingChat       = false;
                    settingScreenshot = !settingScreenshot;
                }
                GUI.EndGroup();
            }
            if (selectedTab == OptionsTab.ADVANCED)
            {
                GUI.Box(new Rect(2, windowY, windowRect.width - 4, 20), "Mod Control", sectionHeaderStyle);
                windowY += 22;

                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 42));
                groupY = 0;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Generate:", descriptorStyle);
                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), "Whitelist", buttonStyle))
                {
                    modWorker.GenerateModControlFile(true);
                }

                groupY += 22;

                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), "Blacklist", buttonStyle))
                {
                    modWorker.GenerateModControlFile(false);
                }

                GUI.EndGroup();
                windowY += 47;

                GUI.Box(new Rect(2, windowY, windowRect.width - 4, 20), "Other", sectionHeaderStyle);
                windowY += 22;

                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 148));
                groupY = 0;

                bool toggleCompression = GUI.Toggle(new Rect(0, groupY, windowRect.width - 20, 20), dmpSettings.compressionEnabled, "Compress Network Traffic");
                if (toggleCompression != dmpSettings.compressionEnabled)
                {
                    dmpSettings.compressionEnabled = toggleCompression;
                    dmpSettings.SaveSettings();
                }
                groupY += 22;

                bool toggleRevert = GUI.Toggle(new Rect(0, groupY, windowRect.width - 20, 20), dmpSettings.revertEnabled, "Enable Revert");
                if (toggleRevert != dmpSettings.revertEnabled)
                {
                    dmpSettings.revertEnabled = toggleRevert;
                    dmpSettings.SaveSettings();
                }
                groupY += 22;

                universeConverterWindow.display = GUI.Toggle(new Rect(0, groupY, windowRect.width - 20, 20), universeConverterWindow.display, "Generate DMP universe from saved game...", buttonStyle);
                groupY += 22;

                if (GUI.Button(new Rect(0, groupY, windowRect.width - 20, 20), "Reset Disclaimer", buttonStyle))
                {
                    dmpSettings.disclaimerAccepted = 0;
                    dmpSettings.SaveSettings();
                }
                groupY += 22;

                if (GUI.Button(new Rect(0, groupY, windowRect.width - 20, 20), toolbarMode, buttonStyle))
                {
                    int newSetting = (int)dmpSettings.toolbarType + 1;
                    //Overflow to 0
                    if (!Enum.IsDefined(typeof(DMPToolbarType), newSetting))
                    {
                        newSetting = 0;
                    }
                    dmpSettings.toolbarType = (DMPToolbarType)newSetting;
                    dmpSettings.SaveSettings();
                    UpdateToolbarString();
                    toolbarSupport.DetectSettingsChange();
                }
                groupY += 22;

#if DEBUG
                if (GUI.Button(new Rect(0, groupY, windowRect.width - 20, 20), "Check missing parts", buttonStyle))
                {
                    modWorker.CheckCommonStockParts();
                }
#endif

                GUI.EndGroup();
            }
        }
Esempio n. 4
0
        public void Start()
        {
            //Set buffered UDPMesh
            UDPMeshLib.UdpMeshCommon.USE_BUFFERS = true;
            //Set pool sizes for ByteRecycler
            ByteRecycler.AddPoolSize(SMALL_MESSAGE_SIZE);
            ByteRecycler.AddPoolSize(MEDIUM_MESSAGE_SIZE);
            ByteRecycler.AddPoolSize(LARGE_MESSAGE_SIZE);
            MessageWriter.RegisterType <ByteArray>(WriteByteArrayToStream);
            MessageReader.RegisterType <ByteArray>(ReadByteArrayFromStream);

            //Prevent loads if multiple copies of DMP are installed. KSP will instantate us twice.
            if (dmpClient != null)
            {
                warnDuplicateInstall = true;
                return;
            }

            if (!CompatibilityChecker.IsCompatible() || !InstallChecker.IsCorrectlyInstalled())
            {
                modDisabled = true;
                enabled     = false;
                return;
            }

            TimingManager.FixedUpdateAdd(TimingManager.TimingStage.BetterLateThanNever, TimingManagerFixedUpdate);
            dmpDir      = Path.Combine(Path.Combine(Path.Combine(KSPUtil.ApplicationRootPath, "GameData"), "DarkMultiPlayer"), "Plugins");
            dmpDataDir  = Path.Combine(dmpDir, "Data");
            gameDataDir = Path.Combine(KSPUtil.ApplicationRootPath, "GameData");
            kspRootPath = KSPUtil.ApplicationRootPath;

            //Fix DarkLog time/thread marker in the log during init.
            DarkLog.SetMainThread();
            lastClockTicks           = DateTime.UtcNow.Ticks;
            lastRealTimeSinceStartup = 0f;

            dmpClient = this;
            profiler  = new Profiler();
            kspTime   = profiler.GetCurrentTime;
            kspMemory = profiler.GetCurrentMemory;

            dmpSettings       = new Settings();
            toolbarSupport    = new ToolbarSupport(dmpSettings);
            universeSyncCache = new UniverseSyncCache(dmpSettings);
            modWindow         = new ModWindow();
            modWorker         = new ModWorker(modWindow);
            modWindow.SetDependenices(modWorker);
            universeConverter          = new UniverseConverter(dmpSettings);
            universeConverterWindow    = new UniverseConverterWindow(universeConverter);
            serverListDisclaimerWindow = new ServerListDisclaimerWindow(dmpSettings);
            optionsWindow        = new OptionsWindow(dmpSettings, universeSyncCache, modWorker, universeConverterWindow, toolbarSupport, serverListDisclaimerWindow);
            serverListConnection = new ServerListConnection(dmpSettings);
            serversWindow        = new ServersWindow(dmpSettings, optionsWindow, serverListConnection);
            serverListConnection.SetDependancy(serversWindow);
            connectionWindow = new ConnectionWindow(dmpSettings, optionsWindow, serversWindow, serverListDisclaimerWindow);
            disclaimerWindow = new DisclaimerWindow(dmpSettings);
            dmpModInterface  = new DMPModInterface();
            //SafetyBubble.RegisterDefaultLocations();


            if (dmpSettings.disclaimerAccepted != 1)
            {
                modDisabled = true;
                disclaimerWindow.SpawnDialog();
            }

            Application.wantsToQuit += WantsToQuit;
            DontDestroyOnLoad(this);

            // Prevents symlink warning for development.
            SetupDirectoriesIfNeeded();

            // UniverseSyncCache needs to run expiry here
            universeSyncCache.ExpireCache();

            GameEvents.onHideUI.Add(() =>
            {
                showGUI = false;
            });
            GameEvents.onShowUI.Add(() =>
            {
                showGUI = true;
            });

            HandleCommandLineArgs();
            DarkLog.Debug("DarkMultiPlayer " + Common.PROGRAM_VERSION + ", protocol " + Common.PROTOCOL_VERSION + " Initialized!");
        }