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); }
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); }
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); }
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); }
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); }