// pvfcollectboxdate 把 PVF 字符串池里收集箱的 **[base expiration date]** 改成未来日期, // 使服务端 collectbox.SnapshotBonus 不再判定为「已过期」。 // // 背景: // // internal/modules/dnf/collectbox/owner.go 的 SnapshotBonus: // expiration := state.Expiration[boxIndex] // Insert 不写它,只有 Extend(延期券) 写 // if expiration.IsZero() { // expiration, _ = parseExpiration(definition.BaseExpirationDate) // ← 回退到 base // } // if !expiration.IsZero() && !now.Before(expiration) { return Bonus{} } // 过期 → 不加属性 // // 而 localization/collectbox/collectboxinfo.etc 里各箱的 base 日期都已是过去: // Index1 SAO 2014-12-30 // Index2 生肖之灵 2015-09-01 // Index3 三国志 2017-01-05 // Index4 猎龙者 2017-12-31 // Index5 兽人守护神 2018-12-31 // // 做法:在 PVF 原始字节里**等长替换**这些日期字符串(都是 19 字节), // 因此不会移动任何偏移、不破坏封包结构。 package main import ( "bytes" "encoding/binary" "flag" "fmt" "os" ) // 旧 base 日期 → 新 base 日期(长度必须一致) var replacements = []struct{ old, new string }{ {"2014-12-30 06:00:00", "2099-12-30 06:00:00"}, {"2015-09-01 06:00:00", "2099-09-01 06:00:00"}, {"2017-01-05 06:00:00", "2099-01-05 06:00:00"}, {"2017-12-31 06:00:00", "2099-12-31 06:00:00"}, {"2018-12-31 06:00:00", "2099-12-31 06:00:00"}, } func main() { input := flag.String("pvf", "", "input PVF") out := flag.String("out", "", "output PVF") dry := flag.Bool("dry-run", false, "只统计,不写") flag.Parse() if *input == "" { panic("-pvf is required") } data, err := os.ReadFile(*input) if err != nil { panic(err) } fmt.Printf("输入 %s %d 字节\n", *input, len(data)) total := 0 for _, r := range replacements { if len(r.old) != len(r.new) { panic("替换长度不一致: " + r.old) } n := bytes.Count(data, []byte(r.old)) if n == 0 { fmt.Printf(" %s → %s 未找到\n", r.old, r.new) continue } data = bytes.ReplaceAll(data, []byte(r.old), []byte(r.new)) total += n fmt.Printf(" %s → %s %d 处\n", r.old, r.new, n) } fmt.Printf("共替换 %d 处\n", total) if total == 0 { panic("没有任何替换 —— 日期可能已被改过") } if *dry { fmt.Println("dry-run,未写文件") return } if *out == "" { panic("-out is required") } if err := os.WriteFile(*out, data, 0o644); err != nil { panic(err) } fmt.Printf("已写出 %s %d 字节\n", *out, len(data)) _ = binary.LittleEndian }