Skip to content

Commit

Permalink
feat(launcher): Add -full for full patch capability
Browse files Browse the repository at this point in the history
  • Loading branch information
cedws committed Nov 11, 2024
1 parent 4ff9dc3 commit 6b200c2
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"slices"
"sync"
"time"

Expand All @@ -39,6 +40,11 @@ var (
errTimeoutFileList = fmt.Errorf("timed out waiting for latest file list")
)

var (
desiredTables = []string{"Base"}
undesiredTables = []string{"_TableList", "About", "PatchClient"}
)

var makeTableOnce = sync.OnceValue(func() crc32.Table {
polyReversed := bits.Reverse32(0x4C11DB7)
return *crc32.MakeTable(polyReversed)
Expand Down Expand Up @@ -96,6 +102,7 @@ func main() {
username, password string
loginServerAddr, patchServerAddr string
patchOnly bool
fullPatch bool
)

flag.StringVar(&dir, "dir", "Wizard101", "client directory")
Expand All @@ -107,6 +114,7 @@ func main() {
flag.StringVar(&patchServerAddr, "patch-server", defaultPatchServer, "patch server addr")

flag.BoolVar(&patchOnly, "patch-only", false, "only patch files without logging in")
flag.BoolVar(&fullPatch, "full", false, "patch all game files")

flag.Parse()

Expand All @@ -120,6 +128,7 @@ func main() {
Username: username,
Password: password,
PatchOnly: patchOnly,
FullPatch: fullPatch,
LoginServerAddr: loginServerAddr,
PatchServerAddr: patchServerAddr,
ConcurrencyLimit: defaultConcurrencyLimit,
Expand Down Expand Up @@ -158,6 +167,7 @@ type launchParams struct {
Username string
Password string
PatchOnly bool
FullPatch bool
LoginServerAddr string
PatchServerAddr string
ConcurrencyLimit int
Expand Down Expand Up @@ -219,20 +229,34 @@ func (p *patchClient) processTables(ctx context.Context, urlPrefix string, table
errGroup.SetLimit(p.launchParams.ConcurrencyLimit)

for _, table := range tables {
if table.Name == "Base" {
slog.Info("Processing files for table", "table", table.Name)

for _, record := range table.Records {
errGroup.Go(func() error {
return p.processRecord(ctx, urlPrefix, record)
})
}
if !shouldProcessTable(table.Name, p.launchParams.FullPatch) {
continue
}

slog.Info("Processing files for table", "table", table.Name)

for _, record := range table.Records {
errGroup.Go(func() error {
return p.processRecord(ctx, urlPrefix, record)
})
}
}

return errGroup.Wait()
}

func shouldProcessTable(name string, fullPatch bool) bool {
if !fullPatch && !slices.Contains(desiredTables, name) {
return false
}

if fullPatch && slices.Contains(undesiredTables, name) {
return false
}

return true
}

func (p *patchClient) processRecord(ctx context.Context, urlPrefix string, record dml.Record) error {
var (
source = record["SrcFileName"].(string)
Expand Down

0 comments on commit 6b200c2

Please sign in to comment.