Skip to content

Commit

Permalink
Merge pull request #6 from Dakota628/new-toc-format
Browse files Browse the repository at this point in the history
Support new TOC/SNO format
  • Loading branch information
Dakota628 authored Oct 10, 2024
2 parents e9dd87c + 810c139 commit 68b6e3a
Show file tree
Hide file tree
Showing 18 changed files with 67,445 additions and 24,098 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Parses various D4 files.
### dumpsnometa
Dumps SNO meta files as spew output.

Example: `dumpsnometa World_SecretCellar.qst > World_SecretCellar.qst.dump`
Example: `dumpsnometa CoreTOC.dat World_SecretCellar.qst > World_SecretCellar.qst.dump`

### dumptoc
Dumps TOC files as YAML output.
Expand Down
10 changes: 5 additions & 5 deletions cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
speechMetaPrefix = filepath.Join("enUS_Speech", "meta")
)

func generateHtmlWorker(c chan string, wg *sync.WaitGroup, toc d4.Toc, gbData *d4.GbData, refs mapset.Set[[2]int32], outputPath string, progress *atomic.Uint64) {
func generateHtmlWorker(c chan string, wg *sync.WaitGroup, toc *d4.Toc, gbData *d4.GbData, refs mapset.Set[[2]int32], outputPath string, progress *atomic.Uint64) {
defer wg.Done()

snoPath := filepath.Join(outputPath, "sno")
Expand All @@ -47,7 +47,7 @@ func generateHtmlWorker(c chan string, wg *sync.WaitGroup, toc d4.Toc, gbData *d
}

// Parse sno file
snoMeta, err := d4.ReadSnoMetaFile(snoMetaFilePath)
snoMeta, err := d4.ReadSnoMetaFile(snoMetaFilePath, toc)
if err != nil {
slog.Error("Error reading sno meta file", slog.Any("error", err), slog.String("snoMetaFilePath", snoMetaFilePath))
continue
Expand Down Expand Up @@ -102,7 +102,7 @@ func generateHtmlWorker(c chan string, wg *sync.WaitGroup, toc d4.Toc, gbData *d
}
}

func generateHtmlForFiles(toc d4.Toc, gbData *d4.GbData, refs mapset.Set[[2]int32], files []string, outputPath string, progress *atomic.Uint64) error {
func generateHtmlForFiles(toc *d4.Toc, gbData *d4.GbData, refs mapset.Set[[2]int32], files []string, outputPath string, progress *atomic.Uint64) error {
// Files arr to channel
c := make(chan string, len(files))
for _, file := range files {
Expand All @@ -121,7 +121,7 @@ func generateHtmlForFiles(toc d4.Toc, gbData *d4.GbData, refs mapset.Set[[2]int3
return nil
}

func generateAllHtml(toc d4.Toc, refs mapset.Set[[2]int32], gameDataPath string, outputPath string) error {
func generateAllHtml(toc *d4.Toc, refs mapset.Set[[2]int32], gameDataPath string, outputPath string) error {
// Make paths
metaPath := filepath.Join(gameDataPath, metaPrefix)
baseMetaGlobPath := filepath.Join(metaPath, "**", "*.*")
Expand Down Expand Up @@ -209,7 +209,7 @@ func generateGroupsFile(outputPath string) error {
return err
}

func generateNamesFile(toc d4.Toc, outputPath string) error {
func generateNamesFile(toc *d4.Toc, outputPath string) error {
namesFilePath := filepath.Join(outputPath, "names.mpk")

b, err := msgpack.Marshal(toc.Entries)
Expand Down
2 changes: 1 addition & 1 deletion cmd/diffmanifest/diffmanifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {

metaPath := util.FindLocalizedFile(path, util.FileTypeMeta, sno.Group, sno.Name)

meta, err := d4.ReadSnoMetaFile(metaPath)
meta, err := d4.ReadSnoMetaFile(metaPath, toc)
if err != nil {
slog.Error("Error reading meta", slog.String("path", metaPath), slog.String("err", err.Error()))
return
Expand Down
85 changes: 0 additions & 85 deletions cmd/dumpformathash/dumpformathash.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/dumpmap/dumpmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
os.Exit(1)
}

util.EachSnoMetaAsync(workers, dataPath, d4.SnoGroupWorld, func(meta d4.SnoMeta) {
util.EachSnoMetaAsync(workers, dataPath, toc, d4.SnoGroupWorld, func(meta d4.SnoMeta) {
slog.Info("Checking SNO...", slog.Int("id", int(meta.Id.Value)))

if meta.Meta.(*d4.WorldDefinition).FHasZoneMap.Value != 1 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/dumpsnohtml/dump_sno_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
os.Exit(1)
}

snoMeta, err := d4.ReadSnoMetaFile(snoMetaPath)
snoMeta, err := d4.ReadSnoMetaFile(snoMetaPath, toc)
if err != nil {
slog.Error("failed to read sno meta file", slog.Any("error", err))
os.Exit(1)
Expand Down
15 changes: 11 additions & 4 deletions cmd/dumpsnometa/dump_sno_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ var spewConfig = spew.ConfigState{
}

func main() {
if len(os.Args) < 2 {
slog.Error("usage: dumpsnometa snoMetaFile")
if len(os.Args) < 3 {
slog.Error("usage: dumpsnometa coreTOCFile snoMetaFile")
os.Exit(1)
}

snoMetaPath := os.Args[1]
tocPath := os.Args[1]
snoMetaPath := os.Args[2]

snoMeta, err := d4.ReadSnoMetaFile(snoMetaPath)
toc, err := d4.ReadTocFile(tocPath)
if err != nil {
slog.Error("failed to read TOC file", slog.Any("error", err))
os.Exit(1)
}

snoMeta, err := d4.ReadSnoMetaFile(snoMetaPath, toc)
if err != nil {
slog.Error("failed to read sno meta file", slog.Any("error", err))
os.Exit(1)
Expand Down
8 changes: 7 additions & 1 deletion cmd/dumptex/dumptex.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ func main() {
texPayloadPath := filepath.Join(dataPath, "base", "payload", "Texture", texName)
texPaylowPath := filepath.Join(dataPath, "base", "paylow", "Texture", texName)

snoMeta, err := d4.ReadSnoMetaFile(texDefPath)
toc, err := d4.ReadTocFile(filepath.Join(dataPath, "base", "CoreTOC.dat"))
if err != nil {
slog.Error("Failed to read toc file", slog.Any("error", err))
os.Exit(1)
}

snoMeta, err := d4.ReadSnoMetaFile(texDefPath, toc)
if err != nil {
slog.Error("Failed to read tex def sno meta file", slog.Any("error", err))
os.Exit(1)
Expand Down
9 changes: 8 additions & 1 deletion cmd/ml/ml.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/mpraski/clusters"
"golang.org/x/exp/slog"
"os"
"path/filepath"
"strconv"
)

Expand All @@ -27,8 +28,14 @@ func main() {
dataPath := os.Args[1]
snoGroupIntStr := parseSnoGroup(os.Args[2])

// Read toc
toc, err := d4.ReadTocFile(filepath.Join(dataPath, "base", "CoreTOC.dat"))
if err != nil {
panic(err)
}

// Determine features
snoIds, features, err := ml.ExtractGroupFeatures(dataPath, snoGroupIntStr)
snoIds, features, err := ml.ExtractGroupFeatures(dataPath, toc, snoGroupIntStr)
if err != nil {
panic(err)
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/structgen/structgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ func GenerateForAllTypes(f *jen.File, _ d4data.Definitions, def d4data.Definitio
).Line()
}

// Construct Size function
f.Func().Params(
receiver,
).Id("TypeSize").Params().Int64().Block(
jen.Return(jen.Lit(def.Size)),
).Line()

return nil
}

Expand Down
Loading

0 comments on commit 68b6e3a

Please sign in to comment.