Migrate to .NET 6.0 and create ConfigManagerV2 project

* Make necessary adjustments to have the same working program
* AssemblyInfo is not set via the file anymore, but the csproj file or in the project settings under Package->General (AssemblyVersion is the one displayed in the Help window)
* Add null-forgiving operators etc. for new language version
* Move stuff that is shared between the DamageCalculator and ConfigManagerV2 into its separate project
This commit is contained in:
MathiasL 2022-03-25 19:55:14 +01:00
parent a41fac78be
commit 3d99b1f68b
40 changed files with 18565 additions and 318 deletions

View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32228.430
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfigManagerV2", "ConfigManagerV2\ConfigManagerV2.csproj", "{0C1DD2D0-F373-43A3-9B2D-F42BCA33D95A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0C1DD2D0-F373-43A3-9B2D-F42BCA33D95A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C1DD2D0-F373-43A3-9B2D-F42BCA33D95A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C1DD2D0-F373-43A3-9B2D-F42BCA33D95A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C1DD2D0-F373-43A3-9B2D-F42BCA33D95A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C01AB77A-47A7-4587-AA94-315531A5BAA0}
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,13 @@
<Application x:Class="ConfigManagerV2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ConfigManagerV2"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/DarkTheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View file

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ConfigManagerV2
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View file

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,20 @@
<Window x:Class="ConfigManagerV2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ConfigManagerV2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
Style="{DynamicResource CustomWindowStyle}">
<Grid>
<Menu>
<MenuItem Header="View">
<MenuItem Header="Themes">
<MenuItem Header="Dark" Uid="0" Click="changeTheme_Click" />
<MenuItem Header="Flashbang" Uid="1" Click="changeTheme_Click" />
</MenuItem>
</MenuItem>
</Menu>
</Grid>
</Window>

View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ConfigManagerV2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
#region events
private void changeTheme_Click(object sender, RoutedEventArgs e)
{
switch (int.Parse(((MenuItem)sender).Uid))
{
case 0:
REghZyFramework.Themes.ThemesController.SetTheme(REghZyFramework.Themes.ThemesController.ThemeTypes.Dark);
break;
case 1:
REghZyFramework.Themes.ThemesController.SetTheme(REghZyFramework.Themes.ThemesController.ThemeTypes.Light);
break;
}
e.Handled = true;
}
#endregion
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
using System.Windows;
namespace REghZyFramework.Themes
{
public partial class ColourfulDarkTheme
{
private void CloseWindow_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { CloseWind(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
private void AutoMinimize_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { MaximizeRestore(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
private void Minimize_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { MinimizeWind(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
public void CloseWind(Window window) => window.Close();
public void MaximizeRestore(Window window)
{
if (window.WindowState == WindowState.Maximized)
window.WindowState = WindowState.Normal;
else if (window.WindowState == WindowState.Normal)
window.WindowState = WindowState.Maximized;
}
public void MinimizeWind(Window window) => window.WindowState = WindowState.Minimized;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
using System.Windows;
namespace REghZyFramework.Themes
{
public partial class ColourfulLightTheme
{
private void CloseWindow_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { CloseWind(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
private void AutoMinimize_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { MaximizeRestore(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
private void Minimize_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { MinimizeWind(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
public void CloseWind(Window window) => window.Close();
public void MaximizeRestore(Window window)
{
if (window.WindowState == WindowState.Maximized)
window.WindowState = WindowState.Normal;
else if (window.WindowState == WindowState.Normal)
window.WindowState = WindowState.Maximized;
}
public void MinimizeWind(Window window) => window.WindowState = WindowState.Minimized;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
using System.Windows;
namespace REghZyFramework.Themes
{
public partial class DarkTheme
{
private void CloseWindow_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { CloseWind(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
private void AutoMinimize_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { MaximizeRestore(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
private void Minimize_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { MinimizeWind(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
public void CloseWind(Window window) => window.Close();
public void MaximizeRestore(Window window)
{
if (window.WindowState == WindowState.Maximized)
window.WindowState = WindowState.Normal;
else if (window.WindowState == WindowState.Normal)
window.WindowState = WindowState.Maximized;
}
public void MinimizeWind(Window window) => window.WindowState = WindowState.Minimized;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
using System.Windows;
namespace REghZyFramework.Themes
{
public partial class LightTheme
{
private void CloseWindow_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { CloseWind(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
private void AutoMinimize_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { MaximizeRestore(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
private void Minimize_Event(object sender, RoutedEventArgs e)
{
if (e.Source != null)
try { MinimizeWind(Window.GetWindow((FrameworkElement)e.Source)); } catch { }
}
public void CloseWind(Window window) => window.Close();
public void MaximizeRestore(Window window)
{
if (window.WindowState == WindowState.Maximized)
window.WindowState = WindowState.Normal;
else if (window.WindowState == WindowState.Normal)
window.WindowState = WindowState.Maximized;
}
public void MinimizeWind(Window window) => window.WindowState = WindowState.Minimized;
}
}

View file

@ -0,0 +1,46 @@
using System;
using System.Windows;
namespace REghZyFramework.Themes
{
public static class ThemesController
{
public enum ThemeTypes
{
Light, ColourfulLight,
Dark, ColourfulDark
}
public static ThemeTypes CurrentTheme { get; set; }
private static ResourceDictionary ThemeDictionary
{
get { return Application.Current.Resources.MergedDictionaries[0]; }
set { Application.Current.Resources.MergedDictionaries[0] = value; }
}
private static void ChangeTheme(Uri uri)
{
ThemeDictionary = new ResourceDictionary() { Source = uri };
}
public static void SetTheme(ThemeTypes theme)
{
string themeName = null;
CurrentTheme = theme;
switch (theme)
{
case ThemeTypes.Dark: themeName = "DarkTheme"; break;
case ThemeTypes.Light: themeName = "LightTheme"; break;
case ThemeTypes.ColourfulDark: themeName = "ColourfulDarkTheme"; break;
case ThemeTypes.ColourfulLight: themeName = "ColourfulLightTheme"; break;
}
try
{
if (!string.IsNullOrEmpty(themeName))
ChangeTheme(new Uri($"Themes/{themeName}.xaml", UriKind.Relative));
}
catch { }
}
}
}

View file

@ -1,9 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
# Visual Studio Version 17
VisualStudioVersion = 17.1.32228.430
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Damage Calculator", "DamageCalculator\DamageCalculator.csproj", "{7A7AE40F-8677-44E3-873A-4AB7C9FCFEB4}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DamageCalculator", "DamageCalculator\DamageCalculator.csproj", "{7A7AE40F-8677-44E3-873A-4AB7C9FCFEB4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SteamHelpers", "..\Shared\SteamHelpers\SteamHelpers\SteamHelpers.csproj", "{3632D445-DC7D-43FC-AC66-8503F50FCA2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{7A7AE40F-8677-44E3-873A-4AB7C9FCFEB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A7AE40F-8677-44E3-873A-4AB7C9FCFEB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A7AE40F-8677-44E3-873A-4AB7C9FCFEB4}.Release|Any CPU.Build.0 = Release|Any CPU
{3632D445-DC7D-43FC-AC66-8503F50FCA2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3632D445-DC7D-43FC-AC66-8503F50FCA2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3632D445-DC7D-43FC-AC66-8503F50FCA2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3632D445-DC7D-43FC-AC66-8503F50FCA2A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -0,0 +1,52 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<RootNamespace>Damage_Calculator</RootNamespace>
<AssemblyName>CSGO Damage Calculator</AssemblyName>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>27.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationFramework.Aero2" />
<Reference Update="System">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression" />
</ItemGroup>
<ItemGroup>
<Resource Include="27.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="icon_ct.png" />
<Resource Include="icon_t.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="icon_a_site.png" />
<Resource Include="icon_b_site.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Shared\SteamHelpers\SteamHelpers\SteamHelpers.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Gameloop.Vdf" Version="0.6.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.3.310801">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
</ItemGroup>
</Project>

View file

@ -1,168 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7A7AE40F-8677-44E3-873A-4AB7C9FCFEB4}</ProjectGuid>
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<RootNamespace>Damage_Calculator</RootNamespace>
<AssemblyName>CSGO Damage Calculator</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>27.ico</ApplicationIcon>
<FileVersion>1.2.0.0</FileVersion>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationFramework.Aero2" />
<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" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
<Reference Update="System">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="About.xaml.cs">
<DependentUpon>About.xaml</DependentUpon>
</Compile>
<Compile Include="CsgoHelper.cs" />
<Compile Include="ctrlPlayerSpawn.xaml.cs">
<DependentUpon>ctrlPlayerSpawn.xaml</DependentUpon>
</Compile>
<Compile Include="DDSImageParser.cs" />
<Compile Include="Globals.cs" />
<Compile Include="Help.xaml.cs">
<DependentUpon>Help.xaml</DependentUpon>
</Compile>
<Compile Include="Models\BSPHeader.cs" />
<Compile Include="Models\BSPLump.cs" />
<Compile Include="Models\CsgoWeapon.cs" />
<Compile Include="Models\CsgoMap.cs" />
<Compile Include="Models\MapPoint.cs" />
<Compile Include="Models\PlayerSpawn.cs" />
<Compile Include="Models\Settings.cs" />
<Compile Include="Models\SteamGame.cs" />
<Compile Include="Models\SteamLibrary.cs" />
<Compile Include="Models\Vector3.cs" />
<Compile Include="Serializer.cs" />
<Compile Include="SteamHelper.cs" />
<Compile Include="Themes\ColourfulDarkTheme.xaml.cs" />
<Compile Include="Themes\ColourfulLightTheme.xaml.cs" />
<Compile Include="Themes\DarkTheme.xaml.cs" />
<Compile Include="Themes\LightTheme.xaml.cs" />
<Compile Include="Themes\ThemesController.cs" />
<Compile Include="ZatVdfParser\BackupVdfReader.cs" />
<Compile Include="ZatVdfParser\Element.cs" />
<Compile Include="ZatVdfParser\VdfFile.cs" />
<Compile Include="ZoomBorder.cs" />
<Page Include="About.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ctrlPlayerSpawn.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Help.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Themes\ColourfulDarkTheme.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\ColourfulLightTheme.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\DarkTheme.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\LightTheme.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<Reference Include="System.IO.Compression" />
</ItemGroup>
<ItemGroup>
<Resource Include="27.ico" />
@ -175,5 +38,17 @@
<Resource Include="icon_a_site.png" />
<Resource Include="icon_b_site.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\..\Shared\SteamHelpers\SteamHelpers\SteamHelpers.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Gameloop.Vdf" Version="0.6.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.3.310801">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
</ItemGroup>
</Project>

View file

@ -14,8 +14,8 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Damage_Calculator.Models;
using Damage_Calculator.ZatVdfParser;
using Shared.Models;
using Shared.ZatVdfParser;
using System.Xml.Serialization;
using System.Globalization;
@ -67,8 +67,8 @@ namespace Damage_Calculator
{
InitializeComponent();
Globals.Settings.CsgoHelper.CsgoPath = Globals.Settings.SteamHelper.GetGamePathFromExactName("Counter-Strike: Global Offensive");
if (Globals.Settings.CsgoHelper.CsgoPath == null)
Shared.Globals.Settings.CsgoHelper.CsgoPath = Shared.Globals.Settings.SteamHelper.GetGamePathFromExactName("Counter-Strike: Global Offensive");
if (Shared.Globals.Settings.CsgoHelper.CsgoPath == null)
{
MessageBox.Show("Make sure you have installed CS:GO and Steam correctly.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
this.Close();
@ -83,6 +83,61 @@ namespace Damage_Calculator
bgWorker.RunWorkerAsync();
}
private static string calculateMD5(string filename)
{
using (var md5 = System.Security.Cryptography.MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
private void updateMapsWithCurrentFilter()
{
if (!this.IsInitialized)
return;
// Add maps
var newMaps = new List<ComboBoxItem>();
foreach (var mapItem in this.allMaps)
{
var newMap = new ComboBoxItem();
var map = (CsgoMap)mapItem.Tag;
string mapNameWithPrefix = System.IO.Path.GetFileNameWithoutExtension(map.MapImagePath).ToLower();
// Filter map type
if (mapNameWithPrefix.StartsWith("de") && mnuShowDefusalMaps.IsChecked == false)
continue;
if (mapNameWithPrefix.StartsWith("cs") && mnuShowHostageMaps.IsChecked == false)
continue;
if (mapNameWithPrefix.StartsWith("ar") && mnuShowArmsRaceMaps.IsChecked == false)
continue;
if (mapNameWithPrefix.StartsWith("dz") && mnuShowDangerZoneMaps.IsChecked == false)
continue;
// Filter file existence
if (map.BspFilePath == null && mnuShowMapsMissingBsp.IsChecked == false)
continue;
if (map.NavFilePath == null && mnuShowMapsMissingNav.IsChecked == false)
continue;
if (map.AinFilePath == null && mnuShowMapsMissingAin.IsChecked == false)
continue;
newMap.Tag = map;
newMap.Content = map.MapFileName;
newMaps.Add(newMap);
}
this.comboBoxMaps.ItemsSource = newMaps.OrderBy(m => m.Content);
if (newMaps.Count > 0)
this.comboBoxMaps.SelectedIndex = 0;
}
#region background worker
private void BgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
@ -127,61 +182,6 @@ namespace Damage_Calculator
}
}
private static string calculateMD5(string filename)
{
using (var md5 = System.Security.Cryptography.MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
private void updateMapsWithCurrentFilter()
{
if (!this.IsInitialized)
return;
// Add maps
var newMaps = new List<ComboBoxItem>();
foreach (var mapItem in this.allMaps)
{
var newMap = new ComboBoxItem();
var map = (CsgoMap)mapItem.Tag;
string mapNameWithPrefix = System.IO.Path.GetFileNameWithoutExtension(map.MapImagePath).ToLower();
// Filter map type
if (mapNameWithPrefix.StartsWith("de") && mnuShowDefusalMaps.IsChecked == false)
continue;
if (mapNameWithPrefix.StartsWith("cs") && mnuShowHostageMaps.IsChecked == false)
continue;
if (mapNameWithPrefix.StartsWith("ar") && mnuShowArmsRaceMaps.IsChecked == false)
continue;
if (mapNameWithPrefix.StartsWith("dz") && mnuShowDangerZoneMaps.IsChecked == false)
continue;
// Filter file existence
if (map.BspFilePath == null && mnuShowMapsMissingBsp.IsChecked == false)
continue;
if (map.NavFilePath == null && mnuShowMapsMissingNav.IsChecked == false)
continue;
if (map.AinFilePath == null && mnuShowMapsMissingAin.IsChecked == false)
continue;
newMap.Tag = map;
newMap.Content = map.MapFileName;
newMaps.Add(newMap);
}
this.comboBoxMaps.ItemsSource = newMaps.OrderBy(m => m.Content);
if (newMaps.Count > 0)
this.comboBoxMaps.SelectedIndex = 0;
}
private void BgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.gridLoading.Visibility = Visibility.Collapsed;
@ -189,13 +189,13 @@ namespace Damage_Calculator
private void BgWorker_DoWork(object sender, DoWorkEventArgs e)
{
var maps = Globals.Settings.CsgoHelper.GetMaps();
var maps = Shared.Globals.Settings.CsgoHelper.GetMaps();
bgWorker.ReportProgress(0, maps);
var serializer = new XmlSerializer(typeof(List<CsgoWeapon>));
List<CsgoWeapon> weapons;
string itemsFile = System.IO.Path.Combine(Globals.Settings.CsgoHelper.CsgoPath, "csgo\\scripts\\items\\items_game.txt");
string itemsFile = System.IO.Path.Combine(Shared.Globals.Settings.CsgoHelper.CsgoPath, "csgo\\scripts\\items\\items_game.txt");
string saveFileDir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CSGO Damage Calculator");
string currentHash = calculateMD5(itemsFile);
@ -234,7 +234,7 @@ namespace Damage_Calculator
Directory.CreateDirectory(saveFileDir);
}
weapons = Globals.Settings.CsgoHelper.GetWeapons();
weapons = Shared.Globals.Settings.CsgoHelper.GetWeapons();
serializer.Serialize(new FileStream(System.IO.Path.Combine(saveFileDir, currentHash), FileMode.Create), weapons);
bgWorker.ReportProgress(1, weapons);
}
@ -302,7 +302,7 @@ namespace Damage_Calculator
private void parseBspData(CsgoMap map)
{
map.EntityList = Globals.Settings.CsgoHelper.ReadEntityListFromBsp(map.BspFilePath);
map.EntityList = Shared.Globals.Settings.CsgoHelper.ReadEntityListFromBsp(map.BspFilePath);
// Current format for one entity is:
//
@ -409,7 +409,7 @@ namespace Damage_Calculator
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);
var navFilesFound = Shared.Globals.Settings.CsgoHelper.ReadIfPackedNavFilesInBsp(map.BspFilePath);
if (navFilesFound.Item1)
{
map.NavFileBspPacked = true;

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Gameloop.Vdf" version="0.6.1" targetFramework="net48" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net48" />
</packages>

View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32228.430
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamHelpers", "SteamHelpers\SteamHelpers.csproj", "{BC940FCA-87A6-41DB-A428-795B33268A22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BC940FCA-87A6-41DB-A428-795B33268A22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC940FCA-87A6-41DB-A428-795B33268A22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC940FCA-87A6-41DB-A428-795B33268A22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC940FCA-87A6-41DB-A428-795B33268A22}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {01A0479A-7ED4-455D-B23C-C13589DC6D50}
EndGlobalSection
EndGlobal

View file

@ -1,5 +1,5 @@
using Damage_Calculator.Models;
using Damage_Calculator.ZatVdfParser;
using Shared.Models;
using Shared.ZatVdfParser;
using System;
using System.Collections.Generic;
using System.Globalization;
@ -9,11 +9,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator
namespace Shared
{
public class CsgoHelper
{
public string CsgoPath { get; set; }
public string? CsgoPath { get; set; }
/// <summary>
/// Gets the prefixes allowed for maps when using <see cref="GetMaps"/>.
@ -58,7 +58,7 @@ namespace Damage_Calculator
/// <returns>whether the files and directories exist.</returns>
public bool Validate()
{
return this.Validate(this.CsgoPath);
return this.Validate(this.CsgoPath!);
}
@ -86,7 +86,7 @@ namespace Damage_Calculator
public List<CsgoMap> GetMaps()
{
List<string> mapTextFiles = Directory.GetFiles(System.IO.Path.Combine(this.CsgoPath, "csgo\\resource\\overviews")).ToList().Where(f => f.ToLower().EndsWith(".txt")).Where(f =>
List<string> mapTextFiles = Directory.GetFiles(System.IO.Path.Combine(this.CsgoPath!, "csgo\\resource\\overviews")).ToList().Where(f => f.ToLower().EndsWith(".txt")).Where(f =>
this.mapFileNameValid(f)).ToList();
List<CsgoMap> maps = new List<CsgoMap>();
@ -96,28 +96,28 @@ namespace Damage_Calculator
var map = new CsgoMap();
// Save path to radar file if available
string potentialRadarFile = System.IO.Path.Combine(this.CsgoPath, "csgo\\resource\\overviews", System.IO.Path.GetFileNameWithoutExtension(file) + "_radar.dds");
string potentialRadarFile = System.IO.Path.Combine(this.CsgoPath!, "csgo\\resource\\overviews", System.IO.Path.GetFileNameWithoutExtension(file) + "_radar.dds");
if (File.Exists(potentialRadarFile))
{
map.MapImagePath = potentialRadarFile;
}
// Save path to BSP file if available
string potentialBspFile = System.IO.Path.Combine(this.CsgoPath, "csgo\\maps", System.IO.Path.GetFileNameWithoutExtension(file) + ".bsp");
string potentialBspFile = System.IO.Path.Combine(this.CsgoPath!, "csgo\\maps", System.IO.Path.GetFileNameWithoutExtension(file) + ".bsp");
if (File.Exists(potentialBspFile))
{
map.BspFilePath = potentialBspFile;
}
// Save path to NAV file if available
string potentialNavFile = System.IO.Path.Combine(this.CsgoPath, "csgo\\maps", System.IO.Path.GetFileNameWithoutExtension(file) + ".nav");
string potentialNavFile = System.IO.Path.Combine(this.CsgoPath!, "csgo\\maps", System.IO.Path.GetFileNameWithoutExtension(file) + ".nav");
if (File.Exists(potentialNavFile))
{
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");
string potentialAinFile = System.IO.Path.Combine(this.CsgoPath!, "csgo\\maps\\graphs", System.IO.Path.GetFileNameWithoutExtension(file) + ".ain");
if (File.Exists(potentialAinFile))
{
map.AinFilePath = potentialAinFile;
@ -201,7 +201,7 @@ namespace Damage_Calculator
try
{
// Read actual radar
image = new DDSImage(System.IO.File.ReadAllBytes(map.MapImagePath));
image = new DDSImage(System.IO.File.ReadAllBytes(map.MapImagePath!));
}
catch
{
@ -226,25 +226,25 @@ namespace Damage_Calculator
public List<CsgoWeapon> GetWeapons()
{
string filePath = Path.Combine(this.CsgoPath, "csgo\\scripts\\items\\items_game.txt");
string filePath = Path.Combine(this.CsgoPath!, "csgo\\scripts\\items\\items_game.txt");
if (!File.Exists(filePath))
return null;
return null!;
var vdfItems = new VDFFile(filePath);
Element prefabs = vdfItems["items_game"]?["prefabs"];
Element items = vdfItems["items_game"]?["items"];
Element prefabs = vdfItems["items_game"]?["prefabs"]!;
Element items = vdfItems["items_game"]?["items"]!;
if (prefabs == null || items == null)
return null;
return null!;
var weapons = new List<CsgoWeapon>();
foreach(var item in items.Children)
{
string itemPrefab = item["prefab"]?.Value;
string itemName = item["name"].Value;
string? itemPrefab = item["prefab"]?.Value!;
string? itemName = item["name"].Value;
if (itemPrefab == null || !itemName.StartsWith("weapon_"))
if (itemPrefab == null || !itemName!.StartsWith("weapon_"))
continue;
var weapon = new CsgoWeapon();
@ -259,7 +259,7 @@ namespace Damage_Calculator
return weapons;
}
private bool tryPopulateWeapon(CsgoWeapon weapon, Element prefabs, string prefabName, List<string> prefabTrace = null)
private bool tryPopulateWeapon(CsgoWeapon weapon, Element prefabs, string prefabName, List<string>? prefabTrace = null)
{
Element prefab = prefabs[prefabName];
@ -267,7 +267,7 @@ namespace Damage_Calculator
// Prefab not existent (example was prefab named "valve csgo_tool")
return false;
string nextPrefab = prefab["prefab"]?.Value;
string nextPrefab = prefab["prefab"]?.Value!;
if (prefab == null || (nextPrefab == null && prefabTrace?.FirstOrDefault(pr => pr == "primary" || pr == "secondary") == null))
// We've reached the end of abstraction but it wasn't found to be primary nor secondary
@ -285,7 +285,7 @@ namespace Damage_Calculator
// Base damage
if (weapon.BaseDamage == -1)
{
string damage = attributes["damage"]?.Value;
string damage = attributes["damage"]?.Value!;
if (damage != null)
{
// damage field exists
@ -301,7 +301,7 @@ namespace Damage_Calculator
// Armor penetration
if (weapon.ArmorPenetration == -1)
{
string penetration = attributes["armor ratio"]?.Value;
string penetration = attributes["armor ratio"]?.Value!;
if (penetration != null)
{
// Armor penetration field exists
@ -317,7 +317,7 @@ namespace Damage_Calculator
// Damage dropoff
if (weapon.DamageDropoff == -1)
{
string dropoff = attributes["range modifier"]?.Value;
string dropoff = attributes["range modifier"]?.Value!;
if (dropoff != null)
{
// Damage dropoff field exists
@ -333,7 +333,7 @@ namespace Damage_Calculator
// Max range
if (weapon.MaxBulletRange == -1)
{
string maxrange = attributes["range"]?.Value;
string maxrange = attributes["range"]?.Value!;
if (maxrange != null)
{
// Max range field exists
@ -349,7 +349,7 @@ namespace Damage_Calculator
// Headshot modifier
if (weapon.HeadshotModifier == -1)
{
string headshotModifier = attributes["headshot multiplier"]?.Value;
string headshotModifier = attributes["headshot multiplier"]?.Value!;
if (headshotModifier != null)
{
// Headshot modifier field exists
@ -370,7 +370,7 @@ namespace Damage_Calculator
if (prefabTrace == null)
prefabTrace = new List<string>();
prefabTrace.Add(prefab.Name);
prefabTrace.Add(prefab.Name!);
return this.tryPopulateWeapon(weapon, prefabs, nextPrefab, prefabTrace);
}
@ -414,7 +414,7 @@ namespace Damage_Calculator
}
}
}
return null;
return null!;
}
/// <summary>
@ -426,7 +426,7 @@ namespace Damage_Calculator
{
bool navFound = false;
bool ainFound = false;
byte[] readZipBytes = null;
byte[] readZipBytes = null!;
using (var bspFile = File.OpenRead(bspFilePath))
{

View file

@ -5,14 +5,14 @@ using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.IO;
namespace Damage_Calculator
namespace Shared
{
#region DDSImage Class
public class DDSImage : IDisposable
{
#region Variables
private bool m_isValid = false;
private System.Drawing.Bitmap m_bitmap = null;
private System.Drawing.Bitmap? m_bitmap = null;
#endregion
#region Constructor/Destructor
@ -58,7 +58,7 @@ namespace Damage_Calculator
{
DDSStruct header = new DDSStruct();
PixelFormat pixelFormat = PixelFormat.UNKNOWN;
byte[] data = null;
byte[]? data = null;
if (this.ReadHeader(reader, ref header))
{
@ -84,7 +84,7 @@ namespace Damage_Calculator
private byte[] ReadData(BinaryReader reader, DDSStruct header)
{
byte[] compdata = null;
byte[]? compdata = null;
uint compsize = 0;
if ((header.flags & DDSD_LINEARSIZE) > 1)
@ -620,7 +620,7 @@ namespace Damage_Calculator
{
System.Diagnostics.Debug.WriteLine(pixelFormat);
// allocate bitmap
byte[] rawData = null;
byte[]? rawData = null;
switch (pixelFormat)
{
@ -1767,7 +1767,7 @@ namespace Damage_Calculator
/// </summary>
public System.Drawing.Bitmap BitmapImage
{
get { return this.m_bitmap; }
get { return this.m_bitmap!; }
}
/// <summary>

View file

@ -7,9 +7,9 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
namespace Damage_Calculator
namespace Shared
{
static class Globals
public static class Globals
{
public static Models.Settings Settings = new Models.Settings();
@ -37,7 +37,7 @@ namespace Damage_Calculator
{
fixed (byte* p = &data[0]) // Fixed so GC doesn't move shit, point to the first element
{
return (T)System.Runtime.InteropServices.Marshal.PtrToStructure(new IntPtr(p), typeof(T));
return (T)System.Runtime.InteropServices.Marshal.PtrToStructure(new IntPtr(p), typeof(T))!;
}
}
}

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator.Models
namespace Shared.Models
{
internal class BSPHeader
{

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator.Models
namespace Shared.Models
{
internal class BSPLump
{

View file

@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
namespace Damage_Calculator.Models
namespace Shared.Models
{
public class CsgoMap
{
@ -18,7 +18,7 @@ namespace Damage_Calculator.Models
/// <summary>
/// The actual radar image of the map.
/// </summary>
public BitmapSource MapImage { get; set; }
public BitmapSource? MapImage { get; set; }
/// <summary>
/// The type of gamemode that's played on this map by default.
@ -28,19 +28,19 @@ namespace Damage_Calculator.Models
/// <summary>
/// The absolute path to the DDS map radar file.
/// </summary>
public string MapImagePath { get; set; }
public string? MapImagePath { get; set; }
/// <summary>
/// The absolute path to the actual BSP map file.
/// </summary>
public string BspFilePath { get; set; }
public string? BspFilePath { get; set; }
/// <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, 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; }
public string? NavFilePath { get; set; }
/// <summary>
/// Indicates whether the NAV file was packed inside of the BSP PAKFILE lump.
@ -52,7 +52,7 @@ namespace Damage_Calculator.Models
/// 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; }
public string? AinFilePath { get; set; }
/// <summary>
/// Indicates whether the AIN file was packed inside of the BSP PAKFILE lump.
@ -62,7 +62,7 @@ namespace Damage_Calculator.Models
/// <summary>
/// The map name as given in the file name, but without the prefix.
/// </summary>
public string MapFileName { get; set; }
public string? MapFileName { get; set; }
/// <summary>
/// The multiplier that is stored in the text file with each map.
@ -138,7 +138,7 @@ namespace Damage_Calculator.Models
/// <summary>
/// Raw list of entities in this map, as stored in the BSP file.
/// </summary>
public string EntityList { get; set; }
public string? EntityList { get; set; }
public int AmountPrioritySpawnsCT { get; set; }

View file

@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
namespace Damage_Calculator.Models
namespace Shared.Models
{
public class CsgoWeapon
{
@ -14,7 +14,7 @@ namespace Damage_Calculator.Models
/// Gets or sets the class name of this weapon.
/// e.g. AK47 would be "weapon_ak47"
/// </summary>
public string ClassName { get; set; }
public string? ClassName { get; set; }
/// <summary>
/// Gets or sets the base damage that the weapon deals, in health points.

View file

@ -4,11 +4,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator.Models
namespace Shared.Models
{
class MapPoint
public class MapPoint
{
public System.Windows.Shapes.Ellipse Circle { get; set; }
public System.Windows.Shapes.Ellipse? Circle { get; set; }
public double PercentageX { get; set; }

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator.Models
namespace Shared.Models
{
public class PlayerSpawn
{
@ -21,13 +21,13 @@ namespace Damage_Calculator.Models
/// <summary>
/// The world position of the player spawn.
/// </summary>
public Vector3 Origin { get; set; }
public Vector3? Origin { get; set; }
/// <summary>
/// The rotation of the player spawn.
/// Y is used most here, 0 is East, goes to 360 clockwise.
/// </summary>
public Vector3 Angles { get; set; }
public Vector3? Angles { get; set; }
/// <summary>
/// The type of spawn (standard, 2v2, hostage, ...)

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator.Models
namespace Shared.Models
{
public class Settings
{

View file

@ -4,13 +4,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator.Models
namespace Shared.Models
{
public class SteamGame
{
public string Name { get; set; }
public string? Name { get; set; }
public string InstallFolderName { get; set; }
public string? InstallFolderName { get; set; }
public int AppId { get; set; }

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator.Models
namespace Shared.Models
{
public class SteamLibrary
{
@ -25,7 +25,7 @@ namespace Damage_Calculator.Models
this.DoesExist = doesExist;
}
public string Path { get; set; }
public string? Path { get; set; }
public bool DoesExist { get; set; }
}

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Damage_Calculator.Models
namespace Shared.Models
{
public class Vector3
{

View file

@ -4,22 +4,22 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Damage_Calculator.ZatVdfParser;
using Shared.ZatVdfParser;
using Microsoft.Win32;
using Damage_Calculator.Models;
using Shared.Models;
namespace Damage_Calculator
namespace Shared
{
public class SteamHelper
{
private string steamPath;
private List<SteamLibrary> steamLibraries;
private string? steamPath;
private List<SteamLibrary>? steamLibraries;
/// <summary>
/// Gets the absolute path to the Steam install directory.
/// If it can't be fetched (i.e. Steam is not installed) null is returned.
/// </summary>
public string SteamPath
public string? SteamPath
{
get
{
@ -35,7 +35,7 @@ namespace Damage_Calculator
/// Gets a list of all Steam libraries, and whether they're existent or not.
/// If it can't be fetched (i.e. Steam is not installed) null is returned.
/// </summary>
public List<SteamLibrary> SteamLibraries
public List<SteamLibrary>? SteamLibraries
{
get
{
@ -59,7 +59,7 @@ namespace Damage_Calculator
/// Gets the path to the Steam install directory. (For external use <see cref="SteamPath"/> is preferred.)
/// </summary>
/// <returns>The absolute path to the Steam install directory, or null if it can't be fetched.</returns>
public string GetSteamPath()
public string? GetSteamPath()
{
var steamKey = Registry.CurrentUser.OpenSubKey("software\\valve\\steam");
@ -86,7 +86,7 @@ namespace Damage_Calculator
/// Fetches a list of Steam libraries, which are deposited in the Steam config, as well as whether the libraries exist on the drive.
/// </summary>
/// <returns>A list of all deposited Steam libraries, and if they exist.</returns>
public List<SteamLibrary> GetSteamLibraries()
public List<SteamLibrary>? GetSteamLibraries()
{
if (this.steamPath == null)
this.steamPath = this.GetSteamPath();
@ -100,11 +100,11 @@ namespace Damage_Calculator
// Fetch additional libraries
var configFile = new VDFFile(configFilePath);
IEnumerable<string> additionalSteamLibraries = configFile["InstallConfigStore"]?["Software"]?["valve"]?["Steam"].Children.Where(c => c.Name.StartsWith("BaseInstallFolder_")).Select(c => c.Value);
IEnumerable<string>? additionalSteamLibraries = configFile["InstallConfigStore"]?["Software"]?["valve"]?["Steam"].Children.Where(c => c.Name!.StartsWith("BaseInstallFolder_")).Select(c => c.Value)!;
// List libraries plus default Steam directory, because that's the default library
var allLibraries = new List<SteamLibrary> { new SteamLibrary(this.steamPath) };
foreach(string addLib in additionalSteamLibraries)
foreach(string addLib in additionalSteamLibraries!)
{
allLibraries.Add(new SteamLibrary(addLib.Replace("\\\\", "\\")));
}
@ -112,7 +112,7 @@ namespace Damage_Calculator
return allLibraries;
}
public List<SteamGame> GetInstalledGames()
public List<SteamGame>? GetInstalledGames()
{
var steamLibraries = this.GetSteamLibraries();
@ -126,7 +126,7 @@ namespace Damage_Calculator
if (!library.DoesExist)
continue;
List<string> manifestFiles = Directory.GetFiles(Path.Combine(library.Path, "steamapps")).ToList().Where(f => this.isAppManifestFile(f)).ToList();
List<string> manifestFiles = Directory.GetFiles(Path.Combine(library.Path!, "steamapps")).ToList().Where(f => this.isAppManifestFile(f)).ToList();
foreach (string manifestFile in manifestFiles)
{
@ -140,7 +140,7 @@ namespace Damage_Calculator
var currGame = new SteamGame();
this.populateGameInfo(currGame, root);
this.populateGameInfo(currGame, root!);
if((currGame.GameState & (int)GameState.StateFullyInstalled) != 0)
{
@ -153,7 +153,7 @@ namespace Damage_Calculator
return allGames;
}
public string GetGamePathFromExactName(string gameName)
public string? GetGamePathFromExactName(string gameName)
{
var steamLibraries = this.GetSteamLibraries();
@ -167,7 +167,7 @@ namespace Damage_Calculator
if (!library.DoesExist)
continue;
List<string> manifestFiles = Directory.GetFiles(Path.Combine(library.Path, "steamapps")).ToList().Where(f => this.isAppManifestFile(f)).ToList();
List<string> manifestFiles = Directory.GetFiles(Path.Combine(library.Path!, "steamapps")).ToList().Where(f => this.isAppManifestFile(f)).ToList();
foreach (string manifestFile in manifestFiles)
{
@ -179,7 +179,7 @@ namespace Damage_Calculator
var root = manifestVDF["AppState"];
if(root["name"].Value.Trim().ToLower() != gameName.Trim().ToLower())
if(root!["name"].Value!.Trim().ToLower() != gameName.Trim().ToLower())
{
// Not our wanted game, skip
continue;
@ -192,7 +192,7 @@ namespace Damage_Calculator
if ((currGame.GameState & (int)GameState.StateFullyInstalled) != 0)
{
// Game was fully installed according to steam
return Path.Combine(library.Path, "steamapps", "common", currGame.InstallFolderName);
return Path.Combine(library.Path!, "steamapps", "common", currGame.InstallFolderName!);
}
}
}

View file

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
</Project>

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.IO;
namespace Damage_Calculator.ZatVdfParser
namespace Shared.ZatVdfParser
{
/// <summary>
/// This class was copied from <see cref="https://stackoverflow.com/questions/39065573/reading-values-from-an-acf-manifest-file">here</see> as a backup, in case <see cref="VDFFile"/> didn't work well enough.

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Damage_Calculator.ZatVdfParser
namespace Shared.ZatVdfParser
{
public class Element
{
@ -13,9 +13,9 @@ namespace Damage_Calculator.ZatVdfParser
#region PROPERTIES
public List<Element> Children { get; set; }
public Element Parent { get; set; }
public string Value { get; set; }
public string Name { get; set; }
public Element? Parent { get; set; }
public string? Value { get; set; }
public string? Name { get; set; }
#endregion
#region CONSTRUCTOR
@ -38,7 +38,7 @@ namespace Damage_Calculator.ZatVdfParser
{
get
{
return Children.FirstOrDefault(x => x.Name == key);
return Children.FirstOrDefault(x => x.Name == key)!;
}
}
#endregion

View file

@ -5,7 +5,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Damage_Calculator.ZatVdfParser
namespace Shared.ZatVdfParser
{
public class VDFFile
{
@ -41,7 +41,7 @@ namespace Damage_Calculator.ZatVdfParser
}
private void Parse(string filePathOrText, bool parseTextDirectly)
{
Element currentLevel = null;
Element? currentLevel = null;
// Generate stream from string in case we want to read it directly, instead of using a file stream (boolean parameter)
var stream = new MemoryStream();
@ -52,7 +52,7 @@ namespace Damage_Calculator.ZatVdfParser
using (StreamReader reader = parseTextDirectly ? new StreamReader(stream) : new StreamReader(filePathOrText))
{
string line = null;
string? line = null;
while ((line = reader.ReadLine()) != null)
{
if (line.StartsWith("\0"))
@ -93,7 +93,7 @@ namespace Damage_Calculator.ZatVdfParser
}
else if (line == "}")
{
currentLevel = currentLevel.Parent;
currentLevel = currentLevel!.Parent;
}
/*else if (line == "{")
{
@ -112,7 +112,7 @@ namespace Damage_Calculator.ZatVdfParser
return RootElements[key];
}
}
public Element this[string key]
public Element? this[string key]
{
get
{