Skip to content

Commit

Permalink
Add LOD light support
Browse files Browse the repository at this point in the history
  • Loading branch information
indilo53 committed Jun 28, 2019
1 parent 59d0f7e commit f0fc294
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 2 deletions.
36 changes: 36 additions & 0 deletions gtautil/Commandline/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> 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<string> InputFiles { get; set; }

[Option('p', "position", HelpText = "Position")]
public List<float> Position { get; set; }

[Option('r', "radius", Default = 1.0f, HelpText = "Radius")]
public float Radius { get; set; }
}

}
2 changes: 2 additions & 0 deletions gtautil/GTAUtil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
<Compile Include="Commandline\Commandline.cs" />
<Compile Include="Commandline\Options.cs" />
<Compile Include="Program\CompileDrawableShaders.cs" />
<Compile Include="Program\FindProps.cs" />
<Compile Include="Program\GenLODLights.cs" />
<Compile Include="Program\GenCol.cs" />
<Compile Include="Program\ExtractArchive.cs" />
<Compile Include="Program\CreateArchive.cs" />
Expand Down
51 changes: 51 additions & 0 deletions gtautil/Program/FindProps.cs
Original file line number Diff line number Diff line change
@@ -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<FindPropsOptions>(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);
}
}
}
}
});
}
}
}
151 changes: 151 additions & 0 deletions gtautil/Program/GenLODLights.cs
Original file line number Diff line number Diff line change
@@ -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<GenLODLigthsOptions>(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<string, int>();
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<string, YmapFile>();
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<string, YmapFile>();
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<string, YmapFile>();
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");
}
}
});
}
}
}
2 changes: 2 additions & 0 deletions gtautil/Program/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion gtautil/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit f0fc294

Please sign in to comment.