FIX: Fix bug hdiff

This commit is contained in:
2025-09-09 08:47:16 +07:00
parent d58e76d821
commit 1f9c95d6ac
11 changed files with 46 additions and 68 deletions

Binary file not shown.

View File

@@ -25,11 +25,10 @@ export function CutData(gamePath) {
/**
* @param {string} gamePath
* @param {string} patchPath
* @param {boolean} isSkipVerify
* @returns {$CancellablePromise<[boolean, string]>}
*/
export function DataExtract(gamePath, patchPath, isSkipVerify) {
return $Call.ByID(2161622254, gamePath, patchPath, isSkipVerify);
export function DataExtract(gamePath, patchPath) {
return $Call.ByID(2161622254, gamePath, patchPath);
}
/**
@@ -59,9 +58,8 @@ export function LDiffPatchData(gamePath) {
/**
* @param {string} gamePath
* @param {string} patchPath
* @param {boolean} isNeedHDiff
* @returns {$CancellablePromise<[boolean, string]>}
*/
export function VersionValidate(gamePath, patchPath, isNeedHDiff) {
return $Call.ByID(2105077257, gamePath, patchPath, isNeedHDiff);
export function VersionValidate(gamePath, patchPath) {
return $Call.ByID(2105077257, gamePath, patchPath);
}

View File

@@ -131,15 +131,13 @@ export default function DiffPage() {
setStageType('Version Validate')
setProgressUpdate(0)
setMaxProgressUpdate(1)
const isNeedHDiff = validType !== 'hdiffmap.json'
const [validVersion, errorVersion] = await DiffService.VersionValidate(gameDir, diffDir, isNeedHDiff)
const [validVersion, errorVersion] = await DiffService.VersionValidate(gameDir, diffDir)
if (!handleResult(validVersion, errorVersion)) return
setProgressUpdate(1)
}
const isSkipVerify = ['manifest', 'hdifffiles.txt', 'hdifffiles.json'].includes(validType)
setStageType('Data Extract')
const [validData, errorData] = await DiffService.DataExtract(gameDir, diffDir, isSkipVerify)
const [validData, errorData] = await DiffService.DataExtract(gameDir, diffDir)
if (!handleResult(validData, errorData)) return
setStageType('Cut Data')

View File

@@ -35,13 +35,11 @@ func (h *DiffService) CheckTypeHDiff(patchPath string) (bool, string, string) {
return false, "", "not found hdifffiles.txt or hdiffmap.json"
}
func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bool) (bool, string) {
func (h *DiffService) VersionValidate(gamePath, patchPath string) (bool, string) {
oldBinPath := filepath.Join(gamePath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes")
oldVersionData, err := models.ParseBinaryVersion(oldBinPath)
if err != nil {
if _, err := os.Stat(oldBinPath); err != nil {
return false, err.Error()
}
if _, err := os.Stat(patchPath); err != nil {
return false, err.Error()
}
@@ -52,38 +50,33 @@ func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bo
}
}
if !isNeedHDiff {
okFull, errFull := sevenzip.IsFileIn7z(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes")
okDiff, errDiff := sevenzip.IsFileIn7z(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes.hdiff")
if (errFull != nil && errDiff != nil) || (!okFull && !okDiff) {
return false, "BinaryVersion file not found in patch"
}
var tempBinFile string
if okFull {
if err := sevenzip.ExtractAFileFromZip(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes", constant.TempUrl); err != nil {
return false, err.Error()
}
binPath := filepath.Join(constant.TempUrl, "BinaryVersion.bytes")
newVersionData, err := models.ParseBinaryVersion(binPath)
if err != nil {
return false, err.Error()
}
defer os.Remove(binPath)
v := newVersionData.Subtract(oldVersionData)
if v != 0 && v != 1 {
return false, fmt.Sprintf("the diff version %s not valid with game version %s", newVersionData, oldVersionData)
}
return true, "validated"
}
tempBinFile = filepath.Join(constant.TempUrl, "BinaryVersion.bytes")
} else {
if err := sevenzip.ExtractAFileFromZip(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes.hdiff", constant.TempUrl); err != nil {
return false, err.Error()
}
patchBinFile := filepath.Join(constant.TempUrl, "BinaryVersion.bytes.hdiff")
sourceBinFile := filepath.Join(gamePath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes")
tempBinFile := filepath.Join(constant.TempUrl, "BinaryVersion.bytes")
sourceBinFile := oldBinPath
tempBinFile = filepath.Join(constant.TempUrl, "BinaryVersion.bytes")
if err := hpatchz.ApplyPatch(sourceBinFile, patchBinFile, tempBinFile); err != nil {
os.Remove(patchBinFile)
return false, err.Error()
}
os.Remove(patchBinFile)
}
okFullPkg, err1 := sevenzip.IsFileIn7z(patchPath, "pkg_version")
okDiffPkg, err2 := sevenzip.IsFileIn7z(patchPath, "pkg_version.hdiff")
@@ -96,7 +89,6 @@ func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bo
}
}
if okDiffPkg {
if err := sevenzip.ExtractAFileFromZip(patchPath, "pkg_version.hdiff", constant.TempUrl); err != nil {
return false, err.Error()
}
@@ -119,8 +111,11 @@ func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bo
}
os.Remove(tempPkgFile)
// MD5 check BinaryVersion
flags := false
for _, pkgData := range pkgDataList {
if filepath.ToSlash(pkgData.RemoteFile) == "StarRail_Data/StreamingAssets/BinaryVersion.bytes" {
flags = true
md5, err := verifier.FileMD5(tempBinFile)
if err != nil {
os.Remove(tempBinFile)
@@ -134,15 +129,18 @@ func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bo
break
}
}
if !flags {
os.Remove(tempBinFile)
return false, "BinaryVersion file not found in patch"
}
_, err = models.ParseBinaryVersion(tempBinFile)
if err != nil {
os.Remove(tempBinFile)
return false, err.Error()
}
os.Remove(tempBinFile)
return true, "validated"
}
func (h *DiffService) HDiffPatchData(gamePath string) (bool, string) {

View File

@@ -2,15 +2,15 @@ package diffService
import (
"firefly-launcher/pkg/constant"
"firefly-launcher/pkg/verifier"
"firefly-launcher/pkg/sevenzip"
"github.com/wailsapp/wails/v3/pkg/application"
"io"
"os"
"path/filepath"
"io"
"github.com/wailsapp/wails/v3/pkg/application"
)
func (h *DiffService) DataExtract(gamePath, patchPath string, isSkipVerify bool) (bool, string) {
func (h *DiffService) DataExtract(gamePath, patchPath string) (bool, string) {
os.RemoveAll(constant.TempUrl)
if _, err := os.Stat(gamePath); err != nil {
return false, err.Error()
@@ -30,20 +30,7 @@ func (h *DiffService) DataExtract(gamePath, patchPath string, isSkipVerify bool)
os.RemoveAll(constant.TempUrl)
return false, err.Error()
}
if !isSkipVerify {
validator, err := verifier.NewVerifier(gamePath, constant.TempUrl)
if err != nil {
os.RemoveAll(constant.TempUrl)
return false, err.Error()
}
if err := validator.VerifyAll(); err != nil {
os.RemoveAll(constant.TempUrl)
return false, err.Error()
}
}
return true, "validated"
return true, "extract completed"
}
func (h *DiffService) CutData(gamePath string) (bool, string) {

View File

@@ -98,7 +98,6 @@ func main() {
DevToolsEnabled: true,
})
err = app.Run()
if err != nil {
log.Fatal(err)

View File

@@ -10,7 +10,7 @@ const ProxyZipFile = "64bit.zip"
const LauncherFile = "firefly-launcher.exe"
const TempUrl = "./temp"
const CurrentLauncherVersion = "1.7.0"
const CurrentLauncherVersion = "1.7.1"
type ToolFile string
@@ -19,15 +19,13 @@ const (
Tool7zaDLL ToolFile = "bin/7za.dll"
Tool7zxaDLL ToolFile = "bin/7zxa.dll"
ToolHPatchzExe ToolFile = "bin/hpatchz.exe"
ToolHDiffzExe ToolFile = "bin/hdiffz.exe"
)
var RequiredFiles = map[ToolFile]string{
Tool7zaExe: "assets/7zip/7za.exe",
Tool7zaDLL: "assets/7zip/7za.dll",
Tool7zxaDLL: "assets/7zip/7zxa.dll",
ToolHPatchzExe: "assets/HDiffPatch/hpatchz.exe",
ToolHDiffzExe: "assets/HDiffPatch/hdiffz.exe",
Tool7zaExe: "assets/7za.exe",
Tool7zaDLL: "assets/7za.dll",
Tool7zxaDLL: "assets/7zxa.dll",
ToolHPatchzExe: "assets/hpatchz.exe",
}
func (t ToolFile) GetEmbedPath() string {