コード例 #1
0
            private HeliCamOffsetsDictionary()
            {
                if (!File.Exists(IniFileName))
                {
                    Game.LogTrivial($"The .ini file '{IniFileName}' doesn't exist, creating default...");
                    CreateDefault();
                }

                internalDictionary = new Dictionary <Model, Vector3>();

                InitializationFile iniFile = new InitializationFile(IniFileName);

                foreach (string section in iniFile.GetSectionNames())
                {
                    float x = 0.0f, y = 0.0f, z = 0.0f;

                    bool             success = false;
                    System.Exception exc = null;
                    try
                    {
                        if (iniFile.DoesSectionExist(section))
                        {
                            if (iniFile.DoesKeyExist(section, "X") &&
                                iniFile.DoesKeyExist(section, "Y") &&
                                iniFile.DoesKeyExist(section, "Z"))
                            {
                                x = iniFile.ReadSingle(section, "X", -0.8f);
                                y = iniFile.ReadSingle(section, "Y", 1.17f);
                                z = iniFile.ReadSingle(section, "Z", 0.52f);

                                Game.LogTrivial($"HeliCam - Offset found and loaded for vehicle model: {section}");
                                success = true;
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        exc = ex;
                    }

                    if (!success)
                    {
                        Game.LogTrivial($"  <WARNING> HeliCam - Failed to load offset for vehicle model: {section}");
                        if (exc != null)
                        {
                            Game.LogTrivial($"  <WARNING> {exc}");
                        }
                        Game.LogTrivial("       Using default settings");
                        x = DefaultOffset.X;
                        y = DefaultOffset.Y;
                        z = DefaultOffset.Z;
                    }

                    internalDictionary.Add(section, new Vector3(x, y, z));
                }
            }
コード例 #2
0
        public void ReadLegacy(string iniFile)
        {
            IsLegacy = true;

            InitializationFile ini = new InitializationFile(iniFile);

            Data = new Dictionary <string, VehicleData>();

            string[] sections = ini.GetSectionNames();
            if (sections != null)
            {
                foreach (string modelName in sections)
                {
                    float x = 0.0f, y = 0.0f, z = 0.0f;

                    bool             success = false;
                    System.Exception exc = null;
                    try
                    {
                        if (ini.DoesSectionExist(modelName))
                        {
                            if (ini.DoesKeyExist(modelName, "X") &&
                                ini.DoesKeyExist(modelName, "Y") &&
                                ini.DoesKeyExist(modelName, "Z"))
                            {
                                x = ini.ReadSingle(modelName, "X", -0.8f);
                                y = ini.ReadSingle(modelName, "Y", 1.17f);
                                z = ini.ReadSingle(modelName, "Z", 0.52f);

                                success = true;
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        exc = ex;
                    }

                    if (!success)
                    {
                        if (exc != null)
                        {
                            Game.LogTrivial($"  <WARNING> Failed to load spotlight offset position settings for vehicle model: {modelName}");
                            Game.LogTrivial($"  <WARNING> {exc}");
                        }

                        x = VehicleData.DefaultOffsetX;
                        y = VehicleData.DefaultOffsetY;
                        z = VehicleData.DefaultOffsetZ;
                    }

                    Data.Add(modelName, new VehicleData(new XYZ(x, y, z)));
                }
            }
        }
コード例 #3
0
ファイル: Settings.cs プロジェクト: timnboys/Spotlight
        private Dictionary <string, Vector3> ReadSpotlightOffsets(InitializationFile iniFile)
        {
            Game.LogTrivial("Loading spotlight offsets...");

            Dictionary <string, Vector3> dict = new Dictionary <string, Vector3>();

            foreach (string modelName in iniFile.GetSectionNames())
            {
                float x = 0.0f, y = 0.0f, z = 0.0f;

                bool             success = false;
                System.Exception exc = null;
                try
                {
                    if (iniFile.DoesSectionExist(modelName))
                    {
                        if (iniFile.DoesKeyExist(modelName, "X") &&
                            iniFile.DoesKeyExist(modelName, "Y") &&
                            iniFile.DoesKeyExist(modelName, "Z"))
                        {
                            x = iniFile.ReadSingle(modelName, "X", -0.8f);
                            y = iniFile.ReadSingle(modelName, "Y", 1.17f);
                            z = iniFile.ReadSingle(modelName, "Z", 0.52f);

                            Game.LogTrivial($"  Spotlight offset position settings found and loaded for vehicle model: {modelName}");
                            success = true;
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    exc = ex;
                }

                if (!success)
                {
                    Game.LogTrivial($"  <WARNING> Failed to load spotlight offset position settings for vehicle model: {modelName}");
                    if (exc != null)
                    {
                        Game.LogTrivial($"  <WARNING> {exc}");
                    }
                    Game.LogTrivial("       Using default settings");
                    x = -0.8f;
                    y = 1.17f;
                    z = 0.52f;
                }

                dict.Add(modelName, new Vector3(x, y, z));
            }

            Game.LogTrivial("Finished loading spotlight offsets");
            return(dict);
        }
コード例 #4
0
        private static void SetupTextures()
        {
            GeneralIni.Create();
            SetupBackgroundSettings();
            ButtonsPerPage = PositioningIni.ReadInt32("General", "ButtonsPerPage", 4);
            for (int i = 1; i <= ButtonsPerPage; i++)
            {
                if (PositioningIni.DoesKeyExist("Button" + i, "XOffset") && PositioningIni.DoesKeyExist("Button" + i, "YOffset"))
                {
                    int XOffset = PositioningIni.ReadInt32("Button" + i, "XOffset", 0);
                    int YOffset = PositioningIni.ReadInt32("Button" + i, "YOffset", 0);
                    buttonOffsets.Add(new Point(XOffset, YOffset));
                }
                else
                {
                    Albo1125.Common.CommonLibrary.ExtensionMethods.DisplayPopupTextBoxWithConfirmation("PoliceSmartRadio DisplayPositioning.ini Error", "Your UI has set " + ButtonsPerPage + " buttons per page, but has not specified XOffsets and YOffsets for so many buttons. Aborting.", true);
                    return;
                }
            }

            OnFootButtonPages    = SetupButtonPage(onFootXML);
            InVehicleButtonPages = SetupButtonPage(inVehicleXML);
            if (firstTimeLaunch)
            {
                HandleFirstLaunch();
            }
            CurrentButtonPages = OnFootButtonPages;
            CurrentPage        = CurrentButtonPages.Count > 0 ? CurrentButtonPages[0] : new ButtonPage();

            DoneLoadingTextures = true;
            Game.LogTrivial("Police SmartRadio is done loading. Button actions ready to be added.");
            SetupUserGeneralSettings();
            ButtonSelectSound.Load();
            ButtonScrollSound.Load();
            MainLogic();
        }
コード例 #5
0
        public void WriteLegacy(string iniFile)
        {
            InitializationFile ini = new InitializationFile(iniFile, CultureInfo.InvariantCulture, false);

            foreach (KeyValuePair <string, VehicleData> item in Data)
            {
                // Write overloads don't use the format provider passed in the constructor, so use ToString instead
                ini.Write(item.Key, VehicleData.IniKeyX, item.Value.Offset.X.ToString(CultureInfo.InvariantCulture));
                ini.Write(item.Key, VehicleData.IniKeyY, item.Value.Offset.Y.ToString(CultureInfo.InvariantCulture));
                ini.Write(item.Key, VehicleData.IniKeyZ, item.Value.Offset.Z.ToString(CultureInfo.InvariantCulture));

                if (item.Value.DisableTurretSpecified)
                {
                    ini.Write(item.Key, VehicleData.IniKeyDisableTurret, item.Value.DisableTurret.ToString(CultureInfo.InvariantCulture));
                }
                else if (ini.DoesKeyExist(item.Key, VehicleData.IniKeyDisableTurret))
                {
                    ini.DeleteKey(item.Key, VehicleData.IniKeyDisableTurret);
                }
            }
            ini.Layout();

            //using (StreamWriter writer = new StreamWriter(iniFile, false))
            //{
            //    foreach (KeyValuePair<string, VehicleData> item in Data)
            //    {
            //        writer.WriteLine($"[{item.Key}]");
            //        writer.WriteLine($"{VehicleData.IniKeyX} = {item.Value.Offset.X.ToString(CultureInfo.InvariantCulture)}");
            //        writer.WriteLine($"{VehicleData.IniKeyY} = {item.Value.Offset.Y.ToString(CultureInfo.InvariantCulture)}");
            //        writer.WriteLine($"{VehicleData.IniKeyZ} = {item.Value.Offset.Z.ToString(CultureInfo.InvariantCulture)}");
            //        if (item.Value.DisableTurretSpecified)
            //        {
            //            writer.WriteLine($"{VehicleData.IniKeyDisableTurret} = {item.Value.DisableTurret.ToString(CultureInfo.InvariantCulture)}");
            //        }
            //        writer.WriteLine();
            //    }
            //}
        }
コード例 #6
0
 public static void Main()
 {
     Log("Loading...");
     Game.TerminateAllScripts("selector");
     (new FileInfo(ini)).Directory.Create();
     cfg = new InitializationFile(ini);
     if (!File.Exists(ini))
     {
         Log($"File {ini} doesn't exist, creating new one.");
         cfg.Write("General", "debug", "false");
         cfg.Write("General", "addBlipsOnStartup", "true");
         cfg.Write("General", "revealMapOnStartup", "false");
         cfg.Write("General", "customBlipsXML", $"{folder}customBlips.xml");
     }
     else
     {
         if (!cfg.DoesKeyExist("General", "debug"))
         {
             cfg.Write("General", "debug", "false");
         }
         if (!cfg.DoesKeyExist("General", "addBlipsOnStartup"))
         {
             cfg.Write("General", "addBlipsOnStartup", "true");
         }
         if (!cfg.DoesKeyExist("General", "revealMapOnStartup"))
         {
             cfg.Write("General", "revealMapOnStartup", "false");
         }
         if (cfg.ReadString("General", "customBlipsXML", "") == "")
         {
             cfg.Write("General", "customBlipsXML", $"{folder}customBlips.xml");
         }
     }
     if (cfg.ReadBoolean("General", "revealMapOnStartup", false))
     {
         Log("revealMapOnStartup set, revealing map...");
     }
     Game.IsFullMapRevealForced = true;
     file = cfg.ReadString("General", "customBlipsXML");
     if (bool.Parse(cfg.ReadString("General", "addBlipsOnStartUP")))
     {
         DirectoryInfo d = new DirectoryInfo(folder);
         foreach (var file in d.GetFiles("*.xml"))
         {
             try
             {
                 XDocument xDocument = XDocument.Load(file.FullName);
                 XElement  root      = xDocument.Element("CustomBlips");
                 foreach (XElement el in root.Descendants())
                 {
                     var blip = XmlToBlip(el);
                     Log($"Added new Blip {blip.Name} from {file.Name} at {blip.Position.X},{blip.Position.Y},{blip.Position.Z}", true);
                 }
                 Log($"Added all Blips from {file.Name}");
             }
             catch
             {
                 Log($"Cannot load {file.FullName}\nMake sure it exists and check it's validaty with http://codebeautify.org/xmlvalidator");
             }
         }
     }
     Log("Loaded successfully.");
     GameFiber.Hibernate();
 }
コード例 #7
0
        public void ReadLegacy(string iniFile)
        {
            IsLegacy = true;

            InitializationFile ini = new InitializationFile(iniFile);

            Data = new Dictionary <string, VehicleData>();

            string[] sections = ini.GetSectionNames();
            if (sections != null)
            {
                foreach (string modelName in sections)
                {
                    float x = VehicleData.DefaultOffsetX, y = VehicleData.DefaultOffsetY, z = VehicleData.DefaultOffsetZ;
                    bool  disableTurret       = VehicleData.DefaultDisableTurret;
                    int   spotlightExtraLight = VehicleData.DefaultSpotlightExtraLight;

                    bool             success = false;
                    System.Exception exc     = null;
                    try
                    {
                        if (ini.DoesKeyExist(modelName, VehicleData.IniKeyX) &&
                            ini.DoesKeyExist(modelName, VehicleData.IniKeyY) &&
                            ini.DoesKeyExist(modelName, VehicleData.IniKeyZ))
                        {
                            x = ini.ReadSingle(modelName, VehicleData.IniKeyX, VehicleData.DefaultOffsetX);
                            y = ini.ReadSingle(modelName, VehicleData.IniKeyY, VehicleData.DefaultOffsetY);
                            z = ini.ReadSingle(modelName, VehicleData.IniKeyZ, VehicleData.DefaultOffsetZ);
                            if (ini.DoesKeyExist(modelName, VehicleData.IniKeyDisableTurret))
                            {
                                disableTurret = ini.ReadBoolean(modelName, VehicleData.IniKeyDisableTurret, VehicleData.DefaultDisableTurret);
                            }
                            if (ini.DoesKeyExist(modelName, VehicleData.IniKeySpotlightExtraLight))
                            {
                                spotlightExtraLight = ini.ReadInt32(modelName, VehicleData.IniKeySpotlightExtraLight, VehicleData.DefaultSpotlightExtraLight);
                                if (spotlightExtraLight <= VehicleData.DefaultSpotlightExtraLight || spotlightExtraLight > 4) // there's only four possible extralight_* bones
                                {
                                    spotlightExtraLight = VehicleData.DefaultSpotlightExtraLight;
                                }
                            }

                            success = true;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        exc = ex;
                    }

                    if (!success)
                    {
                        if (exc != null)
                        {
                            Game.LogTrivial($"  <WARNING> Failed to load spotlight offset position settings for vehicle model: {modelName}");
                            Game.LogTrivial($"  <WARNING> {exc}");
                        }

                        x                   = VehicleData.DefaultOffsetX;
                        y                   = VehicleData.DefaultOffsetY;
                        z                   = VehicleData.DefaultOffsetZ;
                        disableTurret       = VehicleData.DefaultDisableTurret;
                        spotlightExtraLight = VehicleData.DefaultSpotlightExtraLight;
                    }

                    Data.Add(modelName, new VehicleData(new XYZ(x, y, z), disableTurret, spotlightExtraLight));
                }
            }
        }
コード例 #8
0
ファイル: Main.cs プロジェクト: waynieoaks/RecovFR
        private static void LoadValuesFromIniFile()
        {
            // string path = "Plugins\\RecovFR.ini";
            InitializationFile ini = new InitializationFile(INIpath);

            ini.Create();

            try
            {
                if (ini.DoesKeyExist("Keybindings", "BackupKey"))
                {
                    BackupKey = ini.ReadEnum <Keys>("Keybindings", "BackupKey", Keys.F12);
                }
                else
                {
                    ini.Write("Keybindings", "BackupKey", "F12");
                    BackupKey = Keys.F12;
                }

                if (ini.DoesKeyExist("Keybindings", "BackupModifierKey"))
                {
                    BackupModifierKey = ini.ReadEnum <Keys>("Keybindings", "BackupModifierKey", Keys.ControlKey);
                }
                else
                {
                    ini.Write("Keybindings", "BackupModifierKey", "ControlKey");
                    BackupModifierKey = Keys.ControlKey;
                }

                if (ini.DoesKeyExist("Keybindings", "RestoreKey"))
                {
                    RestoreKey = ini.ReadEnum <Keys>("Keybindings", "RestoreKey", Keys.F12);
                }
                else
                {
                    ini.Write("Keybindings", "RestoreKey", "F12");
                    RestoreKey = Keys.F12;
                }

                if (ini.DoesKeyExist("Keybindings", "RestoreModifierKey"))
                {
                    RestoreModifierKey = ini.ReadEnum <Keys>("Keybindings", "RestoreModifierKey", Keys.Menu);
                }
                else
                {
                    ini.Write("Keybindings", "RestoreModifierKey", "ControlKey");
                    RestoreModifierKey = Keys.Menu;
                }

                if (ini.DoesKeyExist("Keybindings", "MenuKey"))
                {
                    MenuKey = ini.ReadEnum <Keys>("Keybindings", "MenuKey", Keys.F11);
                }
                else
                {
                    ini.Write("Keybindings", "MenuKey", "F11");
                    MenuKey = Keys.F11;
                }

                if (ini.DoesKeyExist("Keybindings", "MenuModifierKey"))
                {
                    MenuModifierKey = ini.ReadEnum <Keys>("Keybindings", "MenuModifierKey", Keys.None);
                }
                else
                {
                    ini.Write("Keybindings", "MenuModifierKey", "None");
                    MenuModifierKey = Keys.None;
                }

                if (ini.DoesKeyExist("Features", "AutoBackups"))
                {
                    AutoBackups = ini.ReadBoolean("Features", "AutoBackups", false);
                }
                else
                {
                    ini.Write("Features", "AutoBackups", "false");
                    AutoBackups = false;
                }

                if (ini.DoesKeyExist("Features", "AutoBackupInt"))
                {
                    AutoBackupInt = ini.ReadByte("Features", "AutoBackupInt", 60);
                }
                else
                {
                    ini.Write("Features", "AutoBackupInt", "60");
                    AutoBackupInt = 60;
                }

                if (ini.DoesKeyExist("Features", "ShowNotifications"))
                {
                    ShowNotifications = ini.ReadBoolean("Features", "ShowNotifications", false);
                }
                else
                {
                    ini.Write("Features", "ShowNotifications", "false");
                    ShowNotifications = false;
                }

                if (ini.DoesKeyExist("RestoreOptions", "PlayerGodMode"))
                {
                    PlayerGodMode = ini.ReadBoolean("RestoreOptions", "PlayerGodMode", false);
                }
                else
                {
                    ini.Write("RestoreOptions", "PlayerGodMode", "False");
                    PlayerGodMode = false;
                }

                if (ini.DoesKeyExist("RestoreOptions", "VehicleGodMode"))
                {
                    VehicleGodMode = ini.ReadBoolean("RestoreOptions", "VehicleGodMode", false);
                }
                else
                {
                    ini.Write("RestoreOptions", "VehicleGodMode", "false");
                    VehicleGodMode = false;
                }

                if (ini.DoesKeyExist("RestoreOptions", "FreezeWeather"))
                {
                    FreezeWeather = ini.ReadBoolean("RestoreOptions", "FreezeWeather", false);
                }
                else
                {
                    ini.Write("RestoreOptions", "FreezeWeather", "false");
                    FreezeWeather = false;
                }

                if (ini.DoesKeyExist("RestoreOptions", "SnowOnGround"))
                {
                    SnowOnGround = ini.ReadBoolean("RestoreOptions", "SnowOnGround", false);
                }
                else
                {
                    ini.Write("RestoreOptions", "SnowOnGround", "false");
                    SnowOnGround = false;
                }

                if (ini.DoesKeyExist("RestoreOptions", "FreezeTime"))
                {
                    FreezeTime = ini.ReadBoolean("RestoreOptions", "FreezeTime", false);
                }
                else
                {
                    ini.Write("RestoreOptions", "FreezeTime", "false");
                    FreezeTime = false;
                }
                Game.LogTrivial("Settings initialisation complete.");
            }
            catch (Exception e)
            {
                ErrorLogger(e, "Initialisation", "Unable to read INI file.");
            }
        }
コード例 #9
0
ファイル: Main.cs プロジェクト: waynieoaks/ELS-Cinematic
        private static void LoadValuesFromIniFile()
        {
            InitializationFile ini = new InitializationFile(INIpath);

            ini.Create();

            try
            {
                //Keyboard ini

                if (ini.DoesKeyExist("Keyboard", "CinematicKey"))
                {
                    CinematicKey = ini.ReadEnum <Keys>("Keyboard", "CinematicKey", Keys.R);
                }
                else
                {
                    ini.Write("Keyboard", "CinematicKey", "R");
                    CinematicKey = Keys.R;
                }

                if (ini.DoesKeyExist("Keyboard", "CinematicModifierKey"))
                {
                    CinematicModifierKey = ini.ReadEnum <Keys>("Keyboard", "CinematicModifierKey", Keys.ControlKey);
                }
                else
                {
                    ini.Write("Keyboard", "CinematicModifierKey", "ControlKey");
                    CinematicModifierKey = Keys.ControlKey;
                }

                // Controller ini

                if (ini.DoesKeyExist("Controller", "CinematicButton"))
                {
                    CinematicButton = ini.ReadEnum <ControllerButtons>("Controller", "CinematicButton", ControllerButtons.None);
                }
                else
                {
                    ini.Write("Controller", "CinematicButton", "None");
                    CinematicButton = ControllerButtons.None;
                }

                if (ini.DoesKeyExist("Controller", "CinematicModifierButton"))
                {
                    CinematicModifierButton = ini.ReadEnum <ControllerButtons>("Controller", "CinematicModifierButton", ControllerButtons.None);
                }
                else
                {
                    ini.Write("Controller", "CinematicModifierButton", "None");
                    CinematicModifierButton = ControllerButtons.None;
                }

                // Other ini

                if (ini.DoesKeyExist("Other", "ShowDebug"))
                {
                    ShowDebug = ini.ReadBoolean("Other", "ShowDebug", false);
                }
                else
                {
                    ini.Write("Other", "ShowDebug", "false");
                    ShowDebug = false;
                }

                Game.LogTrivial("Settings initialisation complete.");
            }
            catch (Exception e)
            {
                ErrorLogger(e, "Initialisation", "Unable to read INI file.");
            }
        }