From f0fc2945d3b40dbd78f02da51121ba01635266c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Fri, 28 Jun 2019 18:21:35 +0200 Subject: [PATCH] Add LOD light support --- gtautil/Commandline/Options.cs | 36 +++++++ gtautil/GTAUtil.csproj | 2 + gtautil/Libraries/gta-toolkit | 2 +- gtautil/Program/FindProps.cs | 51 ++++++++++ gtautil/Program/GenLODLights.cs | 151 +++++++++++++++++++++++++++++ gtautil/Program/Program.cs | 2 + gtautil/Properties/AssemblyInfo.cs | 2 +- 7 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 gtautil/Program/FindProps.cs create mode 100644 gtautil/Program/GenLODLights.cs diff --git a/gtautil/Commandline/Options.cs b/gtautil/Commandline/Options.cs index cefdce6..e1927b8 100644 --- a/gtautil/Commandline/Options.cs +++ b/gtautil/Commandline/Options.cs @@ -287,4 +287,40 @@ public class BuildCacheOptions } + [Verb("genlodlights")] + public class GenLODLigthsOptions + { + [Option('c', "create", Default = false, HelpText = "Create project")] + public bool CreateMode { get; set; } + + [Option('d', "delete", Default = false, HelpText = "Delete lights")] + public bool DeleteMode { get; set; } + + [Option('p', "position", HelpText = "Position")] + public List Position { get; set; } + + [Option('r', "radius", Default = 1.0f, HelpText = "Position")] + public float Radius { get; set; } + + [Option('i', "input", HelpText = "Input directory")] + public string InputDirectory { get; set; } + + [Option('o', "output", HelpText = "Output directory")] + public string OutputDirectory { get; set; } + } + + [Verb("findprops")] + public class FindPropsOptions + { + + [Option('i', "input", HelpText = "Input files")] + public List InputFiles { get; set; } + + [Option('p', "position", HelpText = "Position")] + public List Position { get; set; } + + [Option('r', "radius", Default = 1.0f, HelpText = "Radius")] + public float Radius { get; set; } + } + } diff --git a/gtautil/GTAUtil.csproj b/gtautil/GTAUtil.csproj index 822c4d4..b6a505d 100644 --- a/gtautil/GTAUtil.csproj +++ b/gtautil/GTAUtil.csproj @@ -60,6 +60,8 @@ + + diff --git a/gtautil/Libraries/gta-toolkit b/gtautil/Libraries/gta-toolkit index adfca39..ac9f024 160000 --- a/gtautil/Libraries/gta-toolkit +++ b/gtautil/Libraries/gta-toolkit @@ -1 +1 @@ -Subproject commit adfca39968a515b1f1f687c207c353c4eba4d2a2 +Subproject commit ac9f024d8e065d07e770b3ffdde1a5230341647a diff --git a/gtautil/Program/FindProps.cs b/gtautil/Program/FindProps.cs new file mode 100644 index 0000000..6d18c74 --- /dev/null +++ b/gtautil/Program/FindProps.cs @@ -0,0 +1,51 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using SharpDX; +using RageLib.GTA5.Utilities; +using RageLib.Resources.GTA5.PC.GameFiles; + +namespace GTAUtil +{ + partial class Program + { + static void HandleFindPropsOptions(string[] args) + { + CommandLine.Parse(args, (opts, gOpts) => + { + if(opts.Position == null || opts.Position.Count != 3) + { + Console.Error.WriteLine("Please provide position with --position x,y,z"); + return; + } + + var position = new Vector3(opts.Position[0], opts.Position[1], opts.Position[2]); + var inputFiles = Utils.Expand(opts.InputFiles); + + for (int i = 0; i < inputFiles.Length; i++) + { + var fileInfo = inputFiles[i]; + + if (fileInfo.Name.EndsWith(".ymap")) + { + var ymap = new YmapFile(); + + ymap.Load(fileInfo.FullName); + + for (int j = 0; j < ymap.CMapData.Entities.Count; j++) + { + var entity = ymap.CMapData.Entities[j]; + float distance = Vector3.Distance(position, entity.Position); + + if (distance <= opts.Radius) + { + Console.WriteLine(fileInfo.Name + " => " + entity.Guid); + } + } + } + } + }); + } + } +} diff --git a/gtautil/Program/GenLODLights.cs b/gtautil/Program/GenLODLights.cs new file mode 100644 index 0000000..09560e1 --- /dev/null +++ b/gtautil/Program/GenLODLights.cs @@ -0,0 +1,151 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using SharpDX; +using RageLib.GTA5.Utilities; +using RageLib.Resources.GTA5.PC.GameFiles; + +namespace GTAUtil +{ + partial class Program + { + static void HandleGenLODLightsOptions(string[] args) + { + CommandLine.Parse(args, (opts, gOpts) => + { + if (opts.CreateMode) + { + if (opts.OutputDirectory == null) + { + Console.Error.WriteLine("Please provide output directory with --output"); + return; + } + + Init(args); + + if (!Directory.Exists(opts.OutputDirectory)) + Directory.CreateDirectory(opts.OutputDirectory); + + var mapping = new Dictionary(); + + ArchiveUtilities.ForEachResourceFile(Settings.Default.GTAFolder, (fullFileName, file, encryption) => + { + if (file.Name.EndsWith(".ymap") && file.Name.Contains("lodlights")) + { + Console.WriteLine(file.Name); + + int level = GetDLCLevel(fullFileName); + int oldLevel; + + if (!mapping.TryGetValue(file.Name, out oldLevel)) + { + oldLevel = -1; + mapping.Add(file.Name, level); + } + + if (level > oldLevel) + { + file.Export(opts.OutputDirectory + "\\" + file.Name); + } + } + }); + + } + else if (opts.DeleteMode) + { + Init(args); + + if (opts.InputDirectory == null) + { + Console.Error.WriteLine("Please provide input directory with --input"); + return; + } + + if (opts.Position == null || opts.Position.Count != 3) + { + Console.Error.WriteLine("Please provide position with --position x,y,z"); + return; + } + + if (!Directory.Exists(opts.InputDirectory + "\\modified")) + Directory.CreateDirectory(opts.InputDirectory + "\\modified"); + + Vector3 position = new Vector3(opts.Position[0], opts.Position[1], opts.Position[2]); + string[] files = Directory.GetFiles(opts.InputDirectory, "*.ymap"); + + var ymaps = new Dictionary(); + + for (int i = 0; i < files.Length; i++) + { + string path = files[i]; + string name = files[i].Replace(".ymap", ""); + var ymap = new YmapFile(); + + Console.WriteLine("LOAD " + name); + + ymap.Load(files[i]); + ymaps.Add(name, ymap); + } + + var modified = new Dictionary(); + + foreach (var item in ymaps) + { + string name = item.Key; + YmapFile ymap = item.Value; + + for (int j = ymap.CMapData.DistantLODLightsSOA.Entries.Count - 1; j >= 0; j--) + { + var entry = ymap.CMapData.DistantLODLightsSOA.Entries[j]; + var children = new Dictionary(); + float distance = Vector3.Distance(position, entry.Position); + + foreach (var item2 in ymaps) + { + if(item2.Value.CMapData.Parent == ymap.CMapData.Name) + { + children.Add(item2.Key, item2.Value); + } + } + + if (distance <= opts.Radius) + { + Console.WriteLine("Found DistLODLight in " + name + " at index " + j); + Console.WriteLine(" Delete : " + name + "@" + j); + + ymap.CMapData.DistantLODLightsSOA.Entries.RemoveAt(j); + + if (!modified.ContainsValue(ymap)) + { + modified.Add(name, ymap); + } + + foreach (var item2 in children) + { + string name2 = item2.Key; + YmapFile ymap2 = item2.Value; + + Console.WriteLine(" Delete : " + name2 + "@" + j); + item2.Value.CMapData.LODLightsSOA.Entries.RemoveAt(j); + + if (!modified.ContainsValue(ymap2)) + { + modified.Add(name2, ymap2); + } + } + } + } + } + + foreach (var item in modified) + { + item.Value.Save(opts.InputDirectory + "\\" + item.Key + ".ymap"); + item.Value.Save(opts.InputDirectory + "\\modified\\" + item.Key + ".ymap"); + } + } + + }); + } + } +} diff --git a/gtautil/Program/Program.cs b/gtautil/Program/Program.cs index 7e07af7..e507760 100644 --- a/gtautil/Program/Program.cs +++ b/gtautil/Program/Program.cs @@ -57,6 +57,8 @@ static void Main(string[] args) HandleExportMetaOptions(args); HandleExtractEntitiesOptions(args); HandleFindOptions(args); + HandleFindPropsOptions(args); + HandleGenLODLightsOptions(args); HandleGenPedDefsOptions(args); HandleGenPropDefsOptions(args); HandleGetDLCListOptions(args); diff --git a/gtautil/Properties/AssemblyInfo.cs b/gtautil/Properties/AssemblyInfo.cs index f7fbec6..8a08920 100644 --- a/gtautil/Properties/AssemblyInfo.cs +++ b/gtautil/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut // en utilisant '*', comme indiqué ci-dessous : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.2.3.0")] +[assembly: AssemblyVersion("2.2.4.0")] [assembly: AssemblyFileVersion("1.0.0.0")]