Skip to content

Commit

Permalink
Add detection for VPKs that might cause issues with VC configs, fix b…
Browse files Browse the repository at this point in the history
…ug where all demoman weapons would be added when selecting "primary weapons"
  • Loading branch information
hbivnm committed Jan 5, 2023
1 parent a28ec7a commit 6ce9b97
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions VenomCrosshairs/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public partial class FormMain : Form
private static readonly string[] tf2MiscPyroWeapons = { };

private static readonly string[] tf2DemomanWeapons = { "Grenade Launcher, Loch-n-Load, Iron Bomber", "Loose Cannon", "Stickybomb Launcher, Scottish Resistance, Sticky Jumper, Quickiebomb Launcher", "Bottle and all reskins", "Eyelander, Scotsman's Skullcutter, Claidheamh Mòr, Persian Persuader, Pain Train", "Half-Zatoichi", "Ullapool Caber" };
private static readonly string[] tf2PrimaryDemomanWeapons = { "Grenade Launcher, Loch-n-Load, Iron Bomber", "Loose Cannon", "Stickybomb Launcher, Scottish Resistance, Sticky Jumper, Quickiebomb Launcher", "Bottle and all reskins", "Eyelander, Scotsman's Skullcutter, Claidheamh Mòr, Persian Persuader, Pain Train", "Half-Zatoichi", "Ullapool Caber" };
private static readonly string[] tf2PrimaryDemomanWeapons = { "Grenade Launcher, Loch-n-Load, Iron Bomber", "Loose Cannon" };
private static readonly string[] tf2SecondaryDemomanWeapons = { "Stickybomb Launcher, Scottish Resistance, Sticky Jumper, Quickiebomb Launcher" };
private static readonly string[] tf2MeleeDemomanWeapons = { "Bottle and all reskins", "Eyelander, Scotsman's Skullcutter, Claidheamh Mòr, Persian Persuader, Pain Train", "Half-Zatoichi", "Ullapool Caber" };
private static readonly string[] tf2MiscDemomanWeapons = { };
Expand Down Expand Up @@ -282,6 +282,7 @@ private void btnRemoveSelected_Click(object sender, EventArgs e)

private void btnReadConfig_Click(object sender, EventArgs e)
{
pictureBoxLoading.Visible = true;
writeToDebugger("Reading current config... ");
string vcScripDir = textBoxTF2Path.Text + $@"\tf\custom\{VC_CONFIG_NAME}\scripts";
if (Directory.Exists(vcScripDir))
Expand Down Expand Up @@ -309,6 +310,7 @@ private void btnReadConfig_Click(object sender, EventArgs e)
MessageBox.Show("No Venom Crosshairs config folder found!\n\nMake sure your custom crosshair folder is named \"" + VC_CONFIG_NAME + "\".", "Venom Crosshairs - Failed to read current config", MessageBoxButtons.OK, MessageBoxIcon.Error);
writeLineToDebugger("Failed!");
}
pictureBoxLoading.Visible = false;
}

private void btnInstall_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -517,8 +519,6 @@ private void initVC()
// Look for old configs from previous versions
renameOldConfig();

// TODO: Search for existing config with different names

pictureBoxLoading.Visible = false;
}
}
Expand All @@ -538,6 +538,43 @@ private void renameOldConfig()
}
}

private void doVPKCheck()
{
string susVPKFiles = "";

writeToDebugger("Preparing vpk process... ");
Process vpkProcess = new Process();
vpkProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
vpkProcess.StartInfo.UseShellExecute = false;
vpkProcess.StartInfo.RedirectStandardOutput = true;
vpkProcess.StartInfo.CreateNoWindow = true;
vpkProcess.StartInfo.FileName = textBoxTF2Path.Text + @"\bin\vpk.exe";
writeLineToDebugger("Done!");

writeToDebugger($"Running vpk process... ");
foreach (string vpkFile in Directory.GetFiles(textBoxTF2Path.Text + @"\tf\custom", "*.vpk"))
{
StreamReader sw;
string vpkOutput;
vpkProcess.StartInfo.Arguments = $" l \"{vpkFile}\"";
vpkProcess.Start();
sw = vpkProcess.StandardOutput;
vpkOutput = sw.ReadToEnd();
vpkProcess.WaitForExit();

foreach (string weaponFile in weaponScriptPairs.Values)
if (vpkOutput.IndexOf(weaponFile) > -1)
{
susVPKFiles += $"\n- \"{Path.GetFileName(vpkFile)}\"";
break;
}
}
writeLineToDebugger("Done!");

if (susVPKFiles != "")
MessageBox.Show($"WARNING: VPK file(s) were found containing weapon scripts and will not work in combination with Venom Crosshairs configs. It is recommended to remove the VPK(s) if you wish configs generated by Venom Crosshairs to work without issues. Fore more info see FAQ on repository wiki.\n\nVPK file(s) potentially causing issues: {susVPKFiles}", "Venom Crosshairs - Weapon script altering VPK file!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

private bool isNewCrosshairsAvailable(bool suppressNotification)
{
writeToDebugger("Fetching public crosshair list... ");
Expand Down Expand Up @@ -840,6 +877,8 @@ private void performInstallation(bool removeOldConfig)
}));
writeLineToDebugger("Done!");

doVPKCheck();

if (!isUpdate)
writeLineToDebugger("Venom Crosshairs config successfully installed!");
else
Expand Down Expand Up @@ -905,13 +944,13 @@ private void downloadAndGenerateCrosshairs()
File.Delete(previewFile);
writeLineToDebugger("Done!");

// Generate previews
writeToDebugger("Preparing vtf2tga process... ");
Process vtf2tgaProcess = new Process();
vtf2tgaProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
vtf2tgaProcess.StartInfo.FileName = textBoxTF2Path.Text + @"\bin\vtf2tga.exe";
writeLineToDebugger("Done!");

// Generate previews
writeToDebugger("Running vtf2tga.exe... ");
foreach (string vtfFile in Directory.GetFiles(PATH_VC_RESOURCES_MATERIALS, "*.vtf"))
{
Expand Down Expand Up @@ -1175,6 +1214,14 @@ private bool performSanityCheck(string path)
return false;
}

// Check if vpk.exe exists (sanity6)
if (!File.Exists(path + @"\bin\vpk.exe"))
{
writeLineToDebugger("Sanity check failed! Error: sanity6");
MessageBox.Show("Could not find \"vpk.exe\".\nPlease verify game files.", "Venom Crosshairs - vpk.exe does not exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}

writeLineToDebugger("Sanity check finished!");
return true;
}
Expand Down

0 comments on commit 6ce9b97

Please sign in to comment.