Add AIN file indicator and nav/ain packed indicator

* Version increase to 1.2
This commit is contained in:
MathiasL 2022-03-24 23:03:53 +01:00
parent 7d7ce53dae
commit 5ef79f6426
6 changed files with 112 additions and 4 deletions

View file

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -115,6 +116,13 @@ namespace Damage_Calculator
map.NavFilePath = potentialNavFile;
}
// Save path to AIN file if available
string potentialAinFile = System.IO.Path.Combine(this.CsgoPath, "csgo\\maps\\graphs", System.IO.Path.GetFileNameWithoutExtension(file) + ".ain");
if (File.Exists(potentialAinFile))
{
map.AinFilePath = potentialAinFile;
}
// Set map type
switch (System.IO.Path.GetFileNameWithoutExtension(file).Split('_').First().ToLower())
{
@ -409,6 +417,59 @@ namespace Damage_Calculator
return null;
}
/// <summary>
/// Reads packed files from a BSP and returns whether any 1. NAV or 2. AIN files were found.
/// </summary>
/// <param name="bspFilePath">The absolute path to the BSP file.</param>
/// <returns>A tuple containing whether nav or ain files were found, in that order.</returns>
public (bool, bool) ReadIfPackedNavFilesInBsp(string bspFilePath)
{
bool navFound = false;
bool ainFound = false;
byte[] readZipBytes = null;
using (var bspFile = File.OpenRead(bspFilePath))
{
using (var reader = new BinaryReader(bspFile))
{
// Stuff before lumps + pakfile index * lump array item length
reader.BaseStream.Position = 8 + (40 * 16);
// Get lump pos and size
int offset = reader.ReadInt32();
int length = reader.ReadInt32();
// Read zip file
reader.BaseStream.Position = offset;
readZipBytes = reader.ReadBytes(length);
}
}
if (readZipBytes == null)
return (false, false);
using (var stream = new MemoryStream(readZipBytes))
{
using(var zip = new ZipArchive(stream, ZipArchiveMode.Read))
{
foreach(var entry in zip.Entries)
{
if (entry.FullName.EndsWith(".nav"))
// Found a packed NAV file
navFound = true;
if(entry.FullName.EndsWith(".ain"))
// Found a packed AIN file
ainFound = true;
if (navFound && ainFound)
// If both already found, return prematurely
return (true, true);
}
return (navFound, ainFound);
}
}
}
private bool isLumpUnused(byte[] lump)
{
for(int i = 0; i < lump.Length; i++)

View file

@ -44,6 +44,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />

View file

@ -97,7 +97,14 @@
<StackPanel>
<StackPanel>
<CheckBox x:Name="chkHasMapFile" Content="Has map file" IsEnabled="False" />
<CheckBox x:Name="chkHasNavFile" Content="Has nav file" IsEnabled="False" />
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="chkHasNavFile" Content="Has NAV file" IsEnabled="False" />
<TextBlock x:Name="txtNavFilePacked" FontSize="10" Margin="5,0,0,0" Text="(Packed)" Visibility="Collapsed" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="chkHasAinFile" Content="Has AIN file" IsEnabled="False" />
<TextBlock x:Name="txtAinFilePacked" FontSize="10" Margin="5,0,0,0" Text="(Packed)" Visibility="Collapsed" />
</StackPanel>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Text="Max bomb damage:" />
<TextBlock Margin="5,0,0,0" x:Name="txtBombMaxDamage" Text="0" Foreground="IndianRed" />

View file

@ -227,7 +227,13 @@ namespace Damage_Calculator
// Set indicator checkboxes
this.chkHasMapFile.IsChecked = map.BspFilePath != null;
this.chkHasNavFile.IsChecked = map.NavFilePath != null;
this.chkHasAinFile.IsChecked = map.AinFilePath != null;
// Set packed indicators for indicator checkboxes
this.txtNavFilePacked.Visibility = map.NavFileBspPacked ? Visibility.Visible : Visibility.Collapsed;
this.txtAinFilePacked.Visibility = map.AinFileBspPacked ? Visibility.Visible : Visibility.Collapsed;
this.resetCanvas();
this.rightZoomBorder.Reset();
@ -354,6 +360,22 @@ namespace Damage_Calculator
map.SpawnPoints.Add(spawn);
}
}
if (map.NavFilePath == null || map.AinFilePath == null)
{
// If either no NAV or no AIN file has been found, try to update them via the BSP pakfile
var navFilesFound = Globals.Settings.CsgoHelper.ReadIfPackedNavFilesInBsp(map.BspFilePath);
if (navFilesFound.Item1)
{
map.NavFileBspPacked = true;
map.NavFilePath = "PACKED";
}
if (navFilesFound.Item2)
{
map.AinFileBspPacked = true;
map.AinFilePath = "PACKED";
}
}
}
private Vector3 stringToVector3(string coords)

View file

@ -37,11 +37,28 @@ namespace Damage_Calculator.Models
/// <summary>
/// The absolute path to the file that holds this map's navigation meshes and callouts.
/// This might not always be existent, because it is generated by the map builder.
/// This might not always be existent, because it is generated by the map builder, but can be packed inside the BSP. In that case its value is "PACKED".
/// It is always created with maps that are in the main game, because they need callouts and bot movements.
/// </summary>
public string NavFilePath { get; set; }
/// <summary>
/// Indicates whether the NAV file was packed inside of the BSP PAKFILE lump.
/// </summary>
public bool NavFileBspPacked { get; set; }
/// <summary>
/// The absolute path to the file that holds some additional navigational.
/// This might not always be existent, because it is generated by the map builder, but can be packed inside the BSP. In that case its value is "PACKED".
/// It *might* always be created with maps that are in the main game.
/// </summary>
public string AinFilePath { get; set; }
/// <summary>
/// Indicates whether the AIN file was packed inside of the BSP PAKFILE lump.
/// </summary>
public bool AinFileBspPacked { get; set; }
/// <summary>
/// The map name as given in the file name, but without the prefix.
/// </summary>

View file

@ -51,5 +51,5 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.2")]
[assembly: AssemblyFileVersion("1.1.0.2")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]