Skip to content

Instantly share code, notes, and snippets.

@Halkcyon
Forked from OneFaced/UpdateArcDps.cmd
Last active March 1, 2022 17:30
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Halkcyon/b9dd802e56e5889a62d1c1d3bc9761e6 to your computer and use it in GitHub Desktop.
Save Halkcyon/b9dd802e56e5889a62d1c1d3bc9761e6 to your computer and use it in GitHub Desktop.
Automatically update ArcDps and BuildTemplates from deltaconnected for Guild Wars 2
# 2>NUL & powershell -nop -nol -ep bypass "gc -ra '%~f0'|iex" & EXIT /B
# ^ boilerplate to execute script from batch context
# Update this variable to where you have GW2 installed and named.
# This defaults to `C:\Program Files\`
[System.IO.FileInfo] $GW2_PATH = "$Env:ProgramFiles\Guild Wars 2\Gw2-64.exe"
# This line can be removed if you don't want to pass any arguments.
# It does not get used if you already have a
# `%APPDATA%\Guild Wars 2\Settings.json` file.
# Documentation:
# https://wiki.guildwars2.com/wiki/Command_line_arguments
$GW2_ARGS = @('/mapLoadinfo', '/bmp', '/autologin', '/fps:60')
if (Get-Process -Name $GW2_PATH.Name -ErrorAction SilentlyContinue) {
exit
}
function Start-Gw2() {
$startProcessParams = @{
FilePath = $GW2_PATH.FullName
}
if (-not $(Test-Path -Path "$Env:AppData\Guild Wars 2\Settings.json") -and $GW2_ARGS) {
$startProcessParams['ArgumentList'] = $GW2_ARGS
}
Start-Process @startprocessParams
Start-Sleep -Seconds 10
$startProcessParams = @{
FilePath = "$($GW2_PATH.DirectoryName)\addons\taco\GW2TacO.exe"
WorkingDirectory = "$($GW2_PATH.DirectoryName)\addons\taco\"
}
Start-Process @startProcessParams
exit
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$arcPath = "$($GW2_PATH.DirectoryName)\bin64\d3d9.dll"
$arcUri = 'https://www.deltaconnected.com/arcdps/x64/d3d9.dll'
$templatesPath = "$($GW2_PATH.DirectoryName)\bin64\d3d9_arcdps_buildtemplates.dll"
$templatesUri = 'https://www.deltaconnected.com/arcdps/x64/buildtemplates/d3d9_arcdps_buildtemplates.dll'
try {
$invokeWebRequestParams = @{
Uri = 'https://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum'
UseBasicParsing = $true
ErrorAction = [System.Management.Automation.ActionPreference]::Stop
}
$remoteHash = $(
@($(Invoke-WebRequest @invokeWebRequestParams).RawContent -split "`n").Where{$_}[-1] -split '\s'
)[0]
}
catch {
"Failed to retrieve checksum for ArcDPS: $PSItem"
$null = $Host.UI.RawUI.ReadKey()
Start-Gw2
}
if ($remoteHash.Length -ne 32) {
"Bad MD5 checksum from ArcDPS: $remoteHash."
$null = $Host.UI.RawUI.ReadKey()
Start-Gw2
}
#region ArcDPS/BuildTemplates download
if (Test-Path -Path $arcPath) {
if ($(Get-FileHash -Path $arcPath -Algorithm MD5).Hash -ne $remoteHash) {
'ArcDPS is out-of-date.'
if (Test-Path -Path "$arcPath.bak") {
Remove-Item -Path "$arcPath.bak", "$templatesPath.bak" -Force
}
Rename-Item -Path $arcPath -NewName "$arcPath.bak"
Rename-Item -Path $templatesPath -NewName "$templatesPath.bak"
try {
Invoke-WebRequest -Uri $arcUri -OutFile $arcPath -ErrorAction Stop
Invoke-WebRequest -Uri $templatesUri -OutFile $templatesPath -ErrorAction Stop
}
catch {
Remove-Item -Path $arcPath, $templatesPath -Force -ErrorAction Ignore
Rename-Item -Path "$arcPath.bak" -NewName $arcPath
Rename-Item -Path "$templatesPath.bak" -NewName $templatesPath
"Failed to update ArcDPS: $PSItem Restored old version."
$null = $Host.UI.RawUI.ReadKey()
Start-Gw2
}
'ArcDPS install complete.'
}
else {
'ArcDPS is up-to-date.'
}
}
else {
Invoke-WebRequest -Uri $arcUri -OutFile $arcPath
Invoke-WebRequest -Uri $templatesUri -OutFile $templatesPath
'ArcDPS install complete.'
Start-Sleep -Seconds 1
}
#endregion
Start-Gw2
@runcajsz
Copy link

runcajsz commented Mar 11, 2018

I was getting a "Could not establish trust relationship for the SSL/TLS..." error when calling Invoke-WebRequest with a https site. I need to extend your script with this code before Invoke-WebRequest:

if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback=@"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
 }
[ServerCertificateValidationCallback]::Ignore();

Source: https://stackoverflow.com/a/38729034
I had to use the -UseBasicParsing parameter for Invoke-WebRequest as well and now your script is working in my system without any problem. Thanks for your script!

@WildCard1
Copy link

Worked flawlessly - thank you!

@Halkcyon
Copy link
Author

Halkcyon commented Jun 7, 2019

Rev#25 - cleaned up batch boilerplate and am planning on adding taco update support.

@arwandar
Copy link

arwandar commented Aug 27, 2019

Thanks for the gist, I adapted it because I set Tac0 in another folder, here is what I've done, if you'd like to add it :)

# Update this variable to where you have GW2 installed and named.
# This defaults to `C:\Program Files\`
[System.IO.FileInfo] $GW2_PATH = "D:\Guild Wars 2\Gw2-64.exe"
# Update this variable to where you have TACO located.
# This defaults to `C:\Program Files\Guild Wars 2\addons\taco\`
$TACO_PATH = "C:\Program Files\Guild Wars 2\addons\taco\"

or use
$TACO_PATH = "$($GW2_PATH.DirectoryName)\addons\taco\"
and

function Start-Gw2() {
    $startProcessParams = @{
        FilePath = $GW2_PATH.FullName
    }
    if (-not $(Test-Path -Path "$Env:AppData\Guild Wars 2\Settings.json") -and $GW2_ARGS) {
        $startProcessParams['ArgumentList'] = $GW2_ARGS
    }
    Start-Process @startprocessParams
    Start-Sleep -Seconds 10
    $startProcessParams = @{
        FilePath         = "$($TACO_PATH)GW2TacO.exe"
        WorkingDirectory = "$($TACO_PATH)"
    }
    Start-Process @startProcessParams
    exit
}

Feel free to reach me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment