Skip to content

Commit

Permalink
Add Context.Warnf(), improve fault tolerance
Browse files Browse the repository at this point in the history
For example, content/audio/Helldiver_Standard_VO.wwise_bank can now be partially extracted.
  • Loading branch information
xypwn committed Jan 15, 2025
1 parent bf9e60a commit e70db95
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
28 changes: 18 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ func (a *App) MatchingFiles(
return res, nil
}

// Prints hash if human-readable name is unknown.
func (a *App) LookupHash(hash stingray.Hash) string {
if name, ok := a.Hashes[hash]; ok {
return name
}
return hash.String()
}

type extractContext struct {
ctx context.Context
app *App
Expand All @@ -399,16 +407,18 @@ type extractContext struct {
config map[string]string
outPath string
files []string
printer *Printer
}

func newExtractContext(ctx context.Context, app *App, file *stingray.File, runner *exec.Runner, config map[string]string, outPath string) *extractContext {
func newExtractContext(ctx context.Context, app *App, file *stingray.File, runner *exec.Runner, config map[string]string, outPath string, printer *Printer) *extractContext {
return &extractContext{
ctx: ctx,
app: app,
file: file,
runner: runner,
config: config,
outPath: outPath,
printer: printer,
}
}

Expand Down Expand Up @@ -451,17 +461,14 @@ func (c *extractContext) TriadID() *stingray.Hash {
func (c *extractContext) ArmorSets() map[stingray.Hash]dlbin.ArmorSet {
return c.app.ArmorSets
}
func (c *extractContext) Warnf(f string, a ...any) {
name, typ := c.app.LookupHash(c.file.ID().Name), c.app.LookupHash(c.file.ID().Type)
c.printer.Warnf("extract %v.%v: %v", name, typ, fmt.Sprintf(f, a...))
}

// Returns path to extracted file/directory.
func (a *App) ExtractFile(ctx context.Context, id stingray.FileID, outDir string, extrCfg map[string]map[string]string, runner *exec.Runner, gltfDoc *gltf.Document) ([]string, error) {
name, ok := a.Hashes[id.Name]
if !ok {
name = id.Name.String()
}
typ, ok := a.Hashes[id.Type]
if !ok {
typ = id.Type.String()
}
func (a *App) ExtractFile(ctx context.Context, id stingray.FileID, outDir string, extrCfg map[string]map[string]string, runner *exec.Runner, gltfDoc *gltf.Document, printer *Printer) ([]string, error) {
name, typ := a.LookupHash(id.Name), a.LookupHash(id.Type)

file, ok := a.DataDir.Files[id]
if !ok {
Expand Down Expand Up @@ -534,6 +541,7 @@ func (a *App) ExtractFile(ctx context.Context, id stingray.FileID, outDir string
runner,
cfg,
outPath,
printer,
)
if err := extr(extrCtx); err != nil {
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/filediver-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ extractor config:
}
prt.Statusf("File %v/%v: %v", i+1, len(files), truncName)
document := documents[typ]
if _, err := a.ExtractFile(ctx, id, *outDir, extrCfg, runner, document); err == nil {
if _, err := a.ExtractFile(ctx, id, *outDir, extrCfg, runner, document, prt); err == nil {
numExtrFiles++
} else {
if errors.Is(err, context.Canceled) {
Expand Down
2 changes: 2 additions & 0 deletions extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Context interface {
// Selected triad ID, if any (-t option).
TriadID() *stingray.Hash
ArmorSets() map[stingray.Hash]dlbin.ArmorSet
// Prints a warning message.
Warnf(f string, a ...any)
}

type ExtractFunc func(ctx Context) error
Expand Down
2 changes: 1 addition & 1 deletion extractor/unit/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func ConvertOpts(ctx extractor.Context, imgOpts *extr_material.ImageOptions, glt
meshesToLoad = []uint32{uint32(highestDetailIdx)}
}
} else {
fmt.Println("\nAdding LODs anyway since no lodgroups in unitInfo?")
ctx.Warnf("Adding LODs anyway since no lodgroups in unitInfo?")
for i := uint32(0); i < unitInfo.NumMeshes; i++ {
meshesToLoad = append(meshesToLoad, i)
}
Expand Down
4 changes: 2 additions & 2 deletions extractor/wwise/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ func ConvertBnk(ctx extractor.Context) error {
return err
}
if err := func() error {
if err := convertWemStream(ctx, fmt.Sprintf(".bnk/%03d", i), wemR, format); err != nil {
return err
if err := convertWemStream(ctx, fmt.Sprintf(".bnk.dir/%03d", i), wemR, format); err != nil {
ctx.Warnf("file %v: %v", i, err)
}
return nil
}(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion wwise/bnk.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func openBnk(r io.ReadSeeker, bkhdKey *BkhdXorKey) (*Bnk, error) {
}
}

// Read DIDX (contained file info)
// Read DIDX (data index)
var files []bnkIndex
if sections.DidxSize > 0 && sections.DataSize > 0 {
if _, err := r.Seek(int64(sections.DidxOffset), io.SeekStart); err != nil {
Expand Down

0 comments on commit e70db95

Please sign in to comment.