kms.go

on kitten's pastes | raw

expires: 29 May, 2024

  1package main
  2
  3import (
  4	"log"
  5	"os"
  6	"path/filepath"
  7	"fmt"
  8
  9	"github.com/vinegarhq/vinegar/roblox"
 10	"github.com/vinegarhq/vinegar/roblox/bootstrapper"
 11	"golang.org/x/sync/errgroup"
 12)
 13
 14func main() {
 15	dpd, err := os.MkdirTemp("", "*-deployment")
 16	if err != nil {
 17		log.Fatal(err)
 18	}
 19
 20	dlsd, err := os.MkdirTemp("", "*-downloads")
 21	if err != nil {
 22		log.Fatal(err)
 23	}
 24
 25	d, err := bootstrapper.FetchDeployment(roblox.Player, "")
 26	if err != nil {
 27		log.Fatal(err)
 28	}
 29	
 30	pm, err := bootstrapper.FetchPackageManifest(&d)
 31	if err != nil {
 32		log.Fatal(err)
 33	}
 34
 35
 36	switch os.Args[1] {
 37	case "de":
 38		if err := de(dlsd, dpd, &pm); err != nil {
 39			log.Fatal(err)
 40		}
 41	case "dte":
 42		if err := dte(dlsd, dpd, &pm); err != nil {
 43			log.Fatal(err)
 44		}
 45	}
 46}
 47
 48func dte(dlDir string, exDir string, pm *bootstrapper.PackageManifest) error {
 49	eg := new(errgroup.Group)
 50	for _, p := range pm.Packages {
 51		p := p
 52
 53		eg.Go(func() error {
 54			return p.Download(filepath.Join(dlDir, p.Checksum), pm.DeployURL)
 55		})
 56	}
 57
 58	if err := eg.Wait(); err != nil {
 59		return err
 60	}
 61
 62	pds := bootstrapper.BinaryDirectories(roblox.Player)
 63	for _, p := range pm.Packages {
 64		p := p
 65
 66		eg.Go(func() error {
 67			dest, ok := pds[p.Name]
 68
 69			if !ok {
 70				return fmt.Errorf("unhandled package: %s", p.Name)
 71			}
 72
 73			return p.Extract(filepath.Join(dlDir, p.Checksum), filepath.Join(exDir, dest))
 74		})
 75	}
 76
 77	return eg.Wait()
 78}
 79
 80func de(dlDir string, exDir string, pm *bootstrapper.PackageManifest) error {
 81	eg := new(errgroup.Group)
 82	pds := bootstrapper.BinaryDirectories(roblox.Player)
 83	for _, p := range pm.Packages {
 84		p := p
 85
 86		eg.Go(func() error {
 87			dlDest := filepath.Join(dlDir, p.Checksum)
 88
 89			if err := p.Download(dlDest, pm.DeployURL); err != nil {
 90				return err
 91			}
 92
 93			dest, ok := pds[p.Name]
 94
 95			if !ok {
 96				return fmt.Errorf("unhandled package: %s", p.Name)
 97			}
 98
 99			return p.Extract(dlDest, filepath.Join(exDir, dest))
100		})
101	}
102
103	return eg.Wait()
104}