Ejemplo n.º 1
0
        public static int ReadOptFunction([MarshalAs(UnmanagedType.LPStr)] string optFilename)
        {
            _tempOptFile     = null;
            _tempOptFileSize = 0;

            if (!File.Exists(optFilename))
            {
                return(0);
            }

            string         optName        = Path.GetFileNameWithoutExtension(optFilename);
            IList <string> objectLines    = GetCustomFileLines("Skins");
            IList <string> baseSkins      = XwaHooksConfig.Tokennize(XwaHooksConfig.GetFileKeyValue(objectLines, optName));
            bool           hasDefaultSkin = GetSkinDirectoryLocatorPath(optName, "Default") != null;
            int            fgCount        = GetFlightgroupsCount(objectLines, optName);
            bool           hasSkins       = hasDefaultSkin || baseSkins.Count != 0 || fgCount != 0;

            if (hasSkins)
            {
                var opt = OptFile.FromFile(optFilename);
                fgCount = Math.Max(fgCount, opt.MaxTextureVersion);
                UpdateOptFile(optName, opt, objectLines, baseSkins, fgCount, hasDefaultSkin);
                //opt.Save("temp.opt", false);

                _tempOptFile     = opt;
                _tempOptFileSize = opt.GetSaveRequiredFileSize(false);
            }

            return(hasSkins ? _tempOptFileSize : 0);
        }
Ejemplo n.º 2
0
        public static int ReadOptFunction([MarshalAs(UnmanagedType.LPStr)] string optFilename)
        {
            if (!File.Exists(optFilename))
            {
                return(0);
            }

            string         optName     = Path.GetFileNameWithoutExtension(optFilename);
            IList <string> objectLines = GetCustomFileLines("Skins");
            IList <string> baseSkins   = XwaHooksConfig.Tokennize(XwaHooksConfig.GetFileKeyValue(objectLines, optName));
            var            baseDefaultSkinDirectory = new DirectoryInfo($"FlightModels\\Skins\\{optName}\\Default");
            bool           baseDefaultSkinExists    = baseDefaultSkinDirectory.Exists && baseDefaultSkinDirectory.EnumerateFiles().Any();
            int            fgCount  = GetFlightgroupsCount(objectLines, optName);
            bool           hasSkins = baseDefaultSkinExists || baseSkins.Count != 0 || fgCount != 0;

            if (hasSkins)
            {
                var opt = OptFile.FromFile(optFilename);
                fgCount = Math.Max(fgCount, opt.MaxTextureVersion);
                UpdateOptFile(optName, opt, objectLines, baseSkins, fgCount);
                opt.Save("temp.opt");
            }

            return(hasSkins ? 1 : 0);
        }
Ejemplo n.º 3
0
        public static IList <string> GetCustomFileLines(string name)
        {
            string xwaMissionFileName           = Marshal.PtrToStringAnsi(new IntPtr(0x06002E8));
            int    currentGameState             = Marshal.ReadInt32(new IntPtr(0x09F60E0 + 0x25FA9));
            int    updateCallback               = Marshal.ReadInt32(new IntPtr(0x09F60E0 + 0x25FB1 + currentGameState * 0x850 + 0x844));
            bool   isTechLibraryGameStateUpdate = updateCallback == 0x00574D70;

            if (isTechLibraryGameStateUpdate)
            {
                _getCustomFileLines_name    = name;
                _getCustomFileLines_mission = null;
                _getCustomFileLines_lines   = XwaHooksConfig.GetFileLines("FlightModels\\" + name + ".txt");

                if (_getCustomFileLines_lines.Count == 0)
                {
                    _getCustomFileLines_lines = XwaHooksConfig.GetFileLines("FlightModels\\default.ini", name);
                }
            }
            else
            {
                if (_getCustomFileLines_name != name || _getCustomFileLines_mission != xwaMissionFileName)
                {
                    _getCustomFileLines_name    = name;
                    _getCustomFileLines_mission = xwaMissionFileName;

                    string mission = XwaHooksConfig.GetStringWithoutExtension(xwaMissionFileName);
                    _getCustomFileLines_lines = XwaHooksConfig.GetFileLines(mission + "_" + name + ".txt");

                    if (_getCustomFileLines_lines.Count == 0)
                    {
                        _getCustomFileLines_lines = XwaHooksConfig.GetFileLines(mission + ".ini", name);
                    }

                    if (_getCustomFileLines_lines.Count == 0)
                    {
                        _getCustomFileLines_lines = XwaHooksConfig.GetFileLines("FlightModels\\" + name + ".txt");
                    }

                    if (_getCustomFileLines_lines.Count == 0)
                    {
                        _getCustomFileLines_lines = XwaHooksConfig.GetFileLines("FlightModels\\default.ini", name);
                    }
                }
            }

            return(_getCustomFileLines_lines);
        }
Ejemplo n.º 4
0
        private static int GetFlightgroupsCount(IList <string> objectLines, string optName)
        {
            int count = 0;

            for (int index = 255; index >= 0; index--)
            {
                string key   = optName + "_fgc_" + index.ToString(CultureInfo.InvariantCulture);
                string value = XwaHooksConfig.GetFileKeyValue(objectLines, key);

                if (!string.IsNullOrEmpty(value))
                {
                    count = index + 1;
                    break;
                }
            }

            return(count);
        }
Ejemplo n.º 5
0
        private static List <int> GetFlightgroupsColors(IList <string> objectLines, string optName, int fgCount, bool hasDefaultSkin)
        {
            bool hasBaseSkins = hasDefaultSkin || !string.IsNullOrEmpty(XwaHooksConfig.GetFileKeyValue(objectLines, optName));

            var colors = new List <int>();

            for (int index = 0; index < 256; index++)
            {
                string key   = optName + "_fgc_" + index.ToString(CultureInfo.InvariantCulture);
                string value = XwaHooksConfig.GetFileKeyValue(objectLines, key);

                if (!string.IsNullOrEmpty(value) || (hasBaseSkins && index < fgCount))
                {
                    colors.Add(index);
                }
            }

            return(colors);
        }
Ejemplo n.º 6
0
        private static List <List <string> > ReadFgSkins(string optName, IList <string> objectLines, IList <string> baseSkins, int fgCount)
        {
            var fgSkins = new List <List <string> >(fgCount);

            for (int i = 0; i < fgCount; i++)
            {
                var    skins = new List <string>(baseSkins);
                string fgKey = optName + "_fgc_" + i.ToString(CultureInfo.InvariantCulture);
                skins.AddRange(XwaHooksConfig.Tokennize(XwaHooksConfig.GetFileKeyValue(objectLines, fgKey)));

                if (skins.Count == 0)
                {
                    skins.Add("Default");
                }

                fgSkins.Add(skins);
            }

            return(fgSkins);
        }