Skip to content

Commit

Permalink
-added additonal checks
Browse files Browse the repository at this point in the history
-added/fixed ability to change game path + path gets automatically saved & selected now (thanks to szaamerik)
-document folder is now 'dynamic' and not 'static' anymore (not everyone has it on C: drive, also thanks to szaamerik)

---Wheel Swap (replace)---
-fixed tool outputing multiple textures
-fixed wheel texture not getting renamed properly
  • Loading branch information
ThisIsDas committed Sep 20, 2023
1 parent 75ccce1 commit fddc116
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ForzaModelTool/ForzaModelTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<UseWindowsForms>true</UseWindowsForms>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>stare.ico</ApplicationIcon>
<Version>2.0.0</Version>
<Version>2.1.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
48 changes: 24 additions & 24 deletions ForzaModelTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public partial class MainWindow : Window
public static bool validPath;
public static string GamePath;
public static string rawPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Forza Model Tool\";
public static string curPath;

public MainWindow()
{
Expand All @@ -34,9 +35,9 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
TXT_GamePath.Text = File.ReadAllText(rawPath + @"\Path.txt");
GamePath = File.ReadAllText(rawPath + @"\Path.txt");
curPath = GamePath;
TXT_NoPath.Visibility = Visibility.Hidden;
// call the path button func to populate the list bc I was too lazy to analyze whats going on in the code lmao
BTN_Path_Click(new object(), new RoutedEventArgs());
validPath = true;
}
}
}
Expand Down Expand Up @@ -64,33 +65,32 @@ private void MinButton_Click(object sender, RoutedEventArgs e)
//click on path button > select game path, if wrong throws error message, if correct move on
public void BTN_Path_Click(object sender, RoutedEventArgs e)
{
//Pop-up to select Folder, yoinked from YT
if (TXT_GamePath.Text == "")
{
FolderBrowserDialog dialog = new();
dialog.ShowDialog();
GamePath = dialog.SelectedPath;
}
FolderBrowserDialog dialog = new();
DialogResult result = dialog.ShowDialog();
GamePath = dialog.SelectedPath;

//if game path includes ForzaHorizon5.exe or not
if (File.Exists(GamePath + "\\ForzaHorizon5.exe"))
if (result == System.Windows.Forms.DialogResult.OK)
{
validPath = true;
TXT_GamePath.Text = new FileInfo(GamePath).FullName;
TXT_NoPath.Visibility = Visibility.Hidden;
//BTN_Path.IsEnabled = false;
//if game path includes ForzaHorizon5.exe or not
if (File.Exists(GamePath + "\\ForzaHorizon5.exe"))
{
validPath = true;
TXT_GamePath.Text = new FileInfo(GamePath).FullName;
TXT_NoPath.Visibility = Visibility.Hidden;

if (!File.Exists(rawPath + @"\Path.txt"))
using (File.Create(rawPath + @"\Path.txt")) { } // Prevent crash from "file in use"
if (!File.Exists(rawPath + @"\Path.txt"))
using (File.Create(rawPath + @"\Path.txt")) { } // Prevent crash from "file in use"

File.WriteAllText(rawPath + @"\Path.txt", GamePath);
}
else
{
System.Windows.MessageBox.Show("Path is wrong or not selected.", "Error", MessageBoxButton.OK, (MessageBoxImage)MessageBoxIcon.Error);
validPath = false;
TXT_NoPath.Visibility = Visibility.Visible;
File.WriteAllText(rawPath + @"\Path.txt", GamePath);
}
else
{
System.Windows.MessageBox.Show("Path is wrong or not selected.", "Error", MessageBoxButton.OK, (MessageBoxImage)MessageBoxIcon.Error);
validPath = false;
TXT_NoPath.Visibility = Visibility.Visible;
}
}
else GamePath = curPath;
}

// view switching (from szaamerik)
Expand Down
10 changes: 10 additions & 0 deletions ForzaModelTool/Views/ModelSwapView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public void CarLists()
LST_TargetCar.Items.Add(Path.GetFileNameWithoutExtension(car));
}
}

if (MainWindow.curPath != GamePath)
{
LST_DonorCar.Items.Clear();
LST_TargetCar.Items.Clear();

MainWindow.curPath = GamePath;

CarLists();
}
}

//looks in GamePath + CarName.zip from list for .modelbin, lists all in new dropdown list
Expand Down
33 changes: 26 additions & 7 deletions ForzaModelTool/Views/WheelSwapView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public void CarList()
foreach (string car in Cars)
LST_DonorWheel.Items.Add(Path.GetFileNameWithoutExtension(car));
}

if (MainWindow.curPath != GamePath)
{
LST_DonorWheel.Items.Clear();
MainWindow.curPath = GamePath;
CarList();
}
}

// if list empty, fill wheel list (aftermarket wheels)
Expand All @@ -106,6 +113,13 @@ public void WheelList()
foreach (string wheel in Wheels)
LST_TargetWheel.Items.Add(Path.GetFileNameWithoutExtension(wheel));
}

if (MainWindow.curPath != GamePath)
{
LST_TargetWheel.Items.Clear();
MainWindow.curPath = GamePath;
WheelList();
}
}

// populate wheel variant list (some cars have wheels with different depths aka variants)
Expand Down Expand Up @@ -158,6 +172,8 @@ private void Swapper(bool bChecked)
bool foundTexture = false;
bool textureError = false;

MainWindow.FolderCheck();

// if add-on checkbox checked, create wheel zip with car name, else create wheel zip of selected car wheel renamed to target wheel
if (bChecked)
{
Expand Down Expand Up @@ -255,8 +271,8 @@ private void Swapper(bool bChecked)
foreach (ZipArchiveEntry entry in archive.Entries)
if (entry.FullName.Contains("_wheellf_ao", StringComparison.OrdinalIgnoreCase))
{
archive.GetEntry(entry.FullName).ExtractToFile($"{ExportWPath}{"\\"}{TexturePath}{"\\"}{entry.Name}", true);
foundTexture = true;
archive.GetEntry(entry.FullName).ExtractToFile($"{ExportWPath}{"\\"}{TexturePath}{"\\"}{LST_TargetWheel.SelectedItem}{"_wheelLF_AO.swatchbin"}", true);
break;
}

Expand All @@ -269,17 +285,18 @@ private void Swapper(bool bChecked)
foreach (ZipArchiveEntry entry in archive.Entries)
if (entry.FullName.Contains(LST_DonorWheel.SelectedItem.ToString() + "_wheellf_ao", StringComparison.OrdinalIgnoreCase))
{
archive.GetEntry(entry.FullName).ExtractToFile($"{ExportWPath}{"\\"}{TexturePath}{"\\"}{LST_TargetWheel.SelectedItem}{"_wheelLF_AO.swatchbin"}", true);
foundTexture = true;
archive.GetEntry(entry.FullName).ExtractToFile($"{ExportWPath}{"\\"}{TexturePath}{"\\"}{LST_TargetWheel.SelectedItem}{"_wheelLF_AO.swatchbin"}", true);
break;
}
}
}
break;
}
if (!foundTexture)
{
MessageBox.Show("Texture was not found.", "Missing Texture", MessageBoxButton.OK, MessageBoxImage.Error);
textureError = true;
MessageBox.Show("Texture was not found.", "Missing Texture", MessageBoxButton.OK, MessageBoxImage.Error);
}

// if texture file found, create + move zip to \media\Stripped\MediaOverride\RC0\Cars\_library\scene\wheels
Expand All @@ -288,7 +305,7 @@ private void Swapper(bool bChecked)
if (!Directory.Exists(GamePathMediaOW))
Directory.CreateDirectory(GamePathMediaOW);

if (!File.Exists($"{ExportWPath}{".zip"}"))
if (!File.Exists($"{GamePathMediaOW}{"\\"}{LST_TargetWheel.SelectedItem}{".zip"}"))
{
ZipFile.CreateFromDirectory(ExportWPath, $"{GamePathMediaOW}{"\\"}{LST_TargetWheel.SelectedItem}{".zip"}");
MessageBox.Show($"{Path.GetFileNameWithoutExtension(LST_TargetWheel.SelectedItem.ToString())}{".zip"}" + " was successfully created!", ":)");
Expand All @@ -301,6 +318,7 @@ private void Swapper(bool bChecked)
if (result == MessageBoxResult.Yes)
{
//move + overwrite created target zip to '\media\Stripped\MediaOverride\RC0\Cars\_library\scene\wheels'
ZipFile.CreateFromDirectory(ExportWPath, $"{ExportWPath}{".zip"}");
File.Move($"{ExportWPath}{".zip"}", $"{GamePathMediaOW}{"\\"}{LST_TargetWheel.SelectedItem}{".zip"}", true);
MessageBox.Show($"{Path.GetFileNameWithoutExtension(LST_TargetWheel.SelectedItem.ToString())}{".zip"}" + " was successfully created!", ":)");
}
Expand All @@ -312,11 +330,12 @@ private void Swapper(bool bChecked)
}
}
}
// delete leftover folders/files
if (Directory.Exists(ExportCPath))
Directory.Delete(ExportCPath, true);
}
}

// delete leftover folders/files
if (Directory.Exists($"{rawPath}{"Wheel Swap\\"}{Path.GetFileNameWithoutExtension(LST_TargetWheel.SelectedItem.ToString())}"))
Directory.Delete($"{rawPath}{"Wheel Swap\\"}{Path.GetFileNameWithoutExtension(LST_TargetWheel.SelectedItem.ToString())}", true);
}
}
}

1 comment on commit fddc116

@NikitaKoshkin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello and thank for tool
I didn’t really understand how to contact
I'll write here

position error along the Y or X axis, for example, when I took a spoiler from С63 Amg 2012 (black edition spoiler) and replaced it for C63s AMG 2016 Forza Edition spoiler, he was to the left of the car

the same thing with the exhaust on the Nissan Skyline Spec 2 from the Toyota Supra MK4, he was drowned deep into the car

Please sign in to comment.