Skip to content

Instantly share code, notes, and snippets.

@LiuQixuan
Last active April 26, 2024 13:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save LiuQixuan/1a3810046c1152808fc9d65c699f8d8d to your computer and use it in GitHub Desktop.
Save LiuQixuan/1a3810046c1152808fc9d65c699f8d8d to your computer and use it in GitHub Desktop.
Install game_hdiff.zip for GenshinImpact
#先读我!
#$HdiffFilePath 为 升级包 完整路径
#$GamePath 为 游戏完整路径(非启动器路径)
#$ToolPath 为 hpatchz.exe 完整路径(如果有官方启动器就填写启动器完整路径,如果没有去该地址下载:https://github.com/sisong/HDiffPatch/releases)
param($HdiffFilePath="H:\GameSetup\setup\Genshine Impact\game_2.8.52_2.8.53_hdiff_tODgBJm8uenIGUX5.zip",$GamePath="H:\Games\Genshin Impact\Genshin Impact game")
$ToolPath = 'G:\ProgramFiles\hdiffpatch_v4.1.3'
$github = "https://gist.github.com/LiuQixuan/1a3810046c1152808fc9d65c699f8d8d"
$host.ui.RawUI.WindowTitle = "Install game_hdiff.zip for GenshinImpact"
Write-Host '该文件执行后不可逆,确保升级包与已安装游戏版本适配.'
Write-Host "遇到错误前往项目地址反馈:$github"
$hpatchz = Join-Path $ToolPath -ChildPath 'hpatchz.exe'
if(!(Test-Path $hpatchz)){
Write-Host "patch工具未找到,复制链接下载解压并更新脚本顶部$ToolPath变量`n下载地址:https://github.com/sisong/HDiffPatch/releases"
exit
}
function Protect-Exit([string]$keyValue='.',[string]$addtext=''){
if($addtext -ne ''){
$addtext = "`t" + $addtext
}
$keyText = ''
if($keyValue -eq '.'){
$keyText = "任意键"
}else{
$keyText = $keyValue
}
$isContinue = Read-Host "按$keyText`退出$addtext"
if($isContinue -match "[$keyValue]" ){
exit
}
}
Class Logger{
$time = ""
$logPath = ""
Logger(){
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M"
$this.logPath = Join-Path -Path $PSScriptRoot -ChildPath "diffInstall.$($this.time).time.log"
}
Logger([string]$Path){
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M"
$this.logPath = Join-Path -Path (Get-ItemProperty -Path $Path).Root -ChildPath "diffInstall.$($this.time).log"
}
[void]refreshTime(){
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M_%S"
}
[void]print([string]$Message,[string]$type){
Write-Host -Object "[$($this.time)]-[$($type.ToUpper())]-$Message"
}
[void]print([string]$Message){
$this.print($Message,'Error')
}
[void]log([string]$Message,[string]$type){
Write-Host -Object "[$($this.time)]-[$($type.ToUpper())]-$Message">>$($this.logPath)
}
[void]log([string]$Message){
$this.log($Message,'Error')
}
[void]write([string]$Message,[string]$type){
"[$($this.time)]-[$($type.ToUpper())]-$Message">>$($this.logPath)
}
[void]write([string]$Message){
$this.write($Message,'Error')
}
}
[Logger]$logger = [Logger]::new()
Protect-Exit -keyValue 'N' -addtext '按其他按键继续'
if((Test-Path -Path $HdiffFilePath) -and ((Get-ItemProperty -Path $HdiffFilePath).Extension -eq '.zip')){
$tmpPath = Join-Path -Path $GamePath -ChildPath "hdiff"
if( (Test-Path $GamePath) -and (Get-ChildItem $GamePath).name.Contains('GenshinImpact_Data') ){
New-Item -ItemType Directory $tmpPath
Expand-Archive -LiteralPath $HdiffFilePath -DestinationPath $tmpPath
if(Test-Path -Path (Join-Path -Path $tmpPath -ChildPath 'deletefiles.txt')){
if(Test-Path -Path (Join-Path -Path $tmpPath -ChildPath 'hdifffiles.txt')){
$delList = Get-Content (Join-Path -Path $tmpPath -ChildPath 'deletefiles.txt')
foreach($item in $delList){
if(!(Remove-Item -Path (Join-Path -Path $GamePath -ChildPath $item))){
$logger.write("[FileNotFound]:$item")
}
}
Remove-Item -Path (Join-Path -Path $tmpPath -ChildPath 'deletefiles.txt')
foreach($item in Get-Content -Path (Join-Path -Path $tmpPath -ChildPath 'hdifffiles.txt')|ConvertFrom-Json){
$oldFilePath = Join-Path -Path $GamePath -ChildPath $item.remoteName
$diffFilePath = (Join-Path -Path $tmpPath -ChildPath $item.remoteName)+'.hdiff'
if((Test-Path -Path $oldFilePath) -and (Test-Path -Path $diffFilePath)){
&$hpatchz -f $oldFilePath $diffFilePath $oldFilePath
}else{
$logger.write("[OldPCKFileNotFound]:$($item.remoteName)")
}
}
Remove-Item -Path (Join-Path -Path $tmpPath -ChildPath 'hdifffiles.txt')
Remove-Item -Path (Join-Path -Path $tmpPath -ChildPath 'GenshinImpact_Data\StreamingAssets\Audio\GeneratedSoundBanks') -Force -Recurse
(Get-ChildItem -Path $tmpPath).FullName|Copy-Item -Recurse -Force -Destination $GamePath
}else{
$logger.log("[UpdatePackageBroken]-[FileNotFound:hdifffiles.txt]:$HdiffFilePath")
}
}else{
$logger.log("[UpdatePackageBroken]-[FileNotFound:deletefiles.txt]:$HdiffFilePath")
}
Remove-Item -Path $tmpPath -Force -Recurse
Write-Host "升级完成,现在可以关闭窗口.`n如有错误请把$($logger.logPath)`的内容发到项目留言中寻求帮助.`n项目地址:$github"
Protect-Exit -keyValue '.'
}else{
$logger.log("[PathError]:游戏路径错误,检查路径内是否包含`"GenshinImpact_Data`"文件夹.")
}
}else{
$logger.log("[PathError]:升级包路径错误.")
}
#Read Me!
#$HdiffFilePath is update package full path
#$GamePath is game full path (not game launcher)
#$ToolPath is hpatchz.exe full path(if your game client contain launcher fill launcher path,or not download tools from url:https://github.com/sisong/HDiffPatch/releases)
param($HdiffFilePath="H:\GameSetup\setup\Genshine Impact\game_2.8.52_2.8.53_hdiff_tODgBJm8uenIGUX5.zip",$GamePath="H:\Games\Genshin Impact\Genshin Impact game")
$ToolPath = 'G:\ProgramFiles\hdiffpatch_v4.1.3'
$github = "https://gist.github.com/LiuQixuan/1a3810046c1152808fc9d65c699f8d8d"
$host.ui.RawUI.WindowTitle = "Install game_hdiff.zip for GenshinImpact"
Write-Host 'This file is irreversible after execution, make sure the version of update-package is compatible with the installed game version.'
Write-Host "If you encounter errors, go to the project address for feedback:$github"
$hpatchz = Join-Path $ToolPath -ChildPath 'hpatchz.exe'
if(!(Test-Path $hpatchz)){
Write-Host "patch tools not found,download tools package and unzip it copy the path to cover $ToolPath variable`ndownload url:https://github.com/sisong/HDiffPatch/releases"
exit
}
function Protect-Exit([string]$keyValue='.',[string]$addtext=''){
if($addtext -ne ''){
$addtext = "`t" + $addtext
}
$keyText = ''
if($keyValue -eq '.'){
$keyText = "any key"
}else{
$keyText = $keyValue
}
$isContinue = Read-Host "press $keyText quit $addtext"
if($isContinue -match "[$keyValue]" ){
exit
}
}
Class Logger{
$time = ""
$logPath = ""
Logger(){
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M"
$this.logPath = Join-Path -Path $PSScriptRoot -ChildPath "diffInstall.$($this.time).time.log"
}
Logger([string]$Path){
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M"
$this.logPath = Join-Path -Path (Get-ItemProperty -Path $Path).Root -ChildPath "diffInstall.$($this.time).log"
}
[void]refreshTime(){
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M_%S"
}
[void]print([string]$Message,[string]$type){
Write-Host -Object "[$($this.time)]-[$($type.ToUpper())]-$Message"
}
[void]print([string]$Message){
$this.print($Message,'Error')
}
[void]log([string]$Message,[string]$type){
Write-Host -Object "[$($this.time)]-[$($type.ToUpper())]-$Message">>$($this.logPath)
}
[void]log([string]$Message){
$this.log($Message,'Error')
}
[void]write([string]$Message,[string]$type){
"[$($this.time)]-[$($type.ToUpper())]-$Message">>$($this.logPath)
}
[void]write([string]$Message){
$this.write($Message,'Error')
}
}
[Logger]$logger = [Logger]::new()
Protect-Exit -keyValue 'N' -addtext 'press any key continue'
if((Test-Path -Path $HdiffFilePath) -and ((Get-ItemProperty -Path $HdiffFilePath).Extension -eq '.zip')){
$tmpPath = Join-Path -Path $GamePath -ChildPath "hdiff"
if( (Test-Path $GamePath) -and (Get-ChildItem $GamePath).name.Contains('GenshinImpact_Data') ){
New-Item -ItemType Directory $tmpPath
Expand-Archive -LiteralPath $HdiffFilePath -DestinationPath $tmpPath
if(Test-Path -Path (Join-Path -Path $tmpPath -ChildPath 'deletefiles.txt')){
if(Test-Path -Path (Join-Path -Path $tmpPath -ChildPath 'hdifffiles.txt')){
$delList = Get-Content (Join-Path -Path $tmpPath -ChildPath 'deletefiles.txt')
foreach($item in $delList){
if(!(Remove-Item -Path (Join-Path -Path $GamePath -ChildPath $item))){
$logger.write("[FileNotFound]:$item")
}
}
Remove-Item -Path (Join-Path -Path $tmpPath -ChildPath 'deletefiles.txt')
foreach($item in Get-Content -Path (Join-Path -Path $tmpPath -ChildPath 'hdifffiles.txt')|ConvertFrom-Json){
$oldFilePath = Join-Path -Path $GamePath -ChildPath $item.remoteName
$diffFilePath = (Join-Path -Path $tmpPath -ChildPath $item.remoteName)+'.hdiff'
if((Test-Path -Path $oldFilePath) -and (Test-Path -Path $diffFilePath)){
&$hpatchz -f $oldFilePath $diffFilePath $oldFilePath
}else{
$logger.write("[OldPCKFileNotFound]:$($item.remoteName)")
}
}
Remove-Item -Path (Join-Path -Path $tmpPath -ChildPath 'hdifffiles.txt')
Remove-Item -Path (Join-Path -Path $tmpPath -ChildPath 'GenshinImpact_Data\StreamingAssets\Audio\GeneratedSoundBanks') -Force -Recurse
(Get-ChildItem -Path $tmpPath).FullName|Copy-Item -Recurse -Force -Destination $GamePath
}else{
$logger.log("[UpdatePackageBroken]-[FileNotFound:hdifffiles.txt]:$HdiffFilePath")
}
}else{
$logger.log("[UpdatePackageBroken]-[FileNotFound:deletefiles.txt]:$HdiffFilePath")
}
Remove-Item -Path $tmpPath -Force -Recurse
Write-Host "The upgrade is complete, you can now close the window.`nIf there is an error, please Send the content of $($logger.logPath) to the project message for help.`nproject url:$github"
Protect-Exit -keyValue '.'
}else{
$logger.log("[PathError]:The game path is wrong, check if the path contains the `"GenshinImpact_Data`" folder.")
}
}else{
$logger.log("[PathError]:Update package path error.")
}
@LiuQixuan
Copy link
Author

中文脚本编码选择GBK,使用utf8保存会乱码导致脚本解析错误无法运行,英文则可以直接复制粘贴直接运行,不存在编码导致不能正常运行的情况。
Select GBK save Chinese script encoding. Using utf8 to save will cause garbled script parsing errors and fail to run. In English, you can directly copy code and paste it to run directly. There is no encoding that causes it to fail to run normally.

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