├── .gitignore ├── pack ├── compressor.go ├── hash.go ├── encryption_test.go ├── encryption.go ├── otf.go └── resource_pack.go ├── example └── otf.go ├── go.mod ├── README.md ├── .github └── workflows │ └── build.yaml ├── main.go ├── internal └── stealer │ └── stealer.go ├── go.sum └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .token_cache 2 | .idea -------------------------------------------------------------------------------- /pack/compressor.go: -------------------------------------------------------------------------------- 1 | package pack 2 | 3 | import ( 4 | "bytes" 5 | "image/png" 6 | ) 7 | 8 | func compressPng(data []byte) ([]byte, error) { 9 | img, err := png.Decode(bytes.NewReader(data)) 10 | if err != nil { 11 | return nil, err 12 | } 13 | encoder := png.Encoder{CompressionLevel: png.BestCompression} 14 | var buf bytes.Buffer 15 | if err := encoder.Encode(&buf, img); err != nil { 16 | return nil, err 17 | } 18 | return buf.Bytes(), nil 19 | } 20 | -------------------------------------------------------------------------------- /example/otf.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/akmalfairuz/bedrockpack/pack" 5 | "github.com/sandertv/gophertunnel/minecraft" 6 | "log/slog" 7 | ) 8 | 9 | func main() { 10 | log := slog.Default() 11 | 12 | conf := pack.OTFConfig{ 13 | OrgName: "Faithful-Resource-Pack", 14 | RepoName: "Faithful-32x-Bedrock", 15 | Branch: "bedrock-latest", 16 | PAT: "", 17 | } 18 | otf := conf.New(log) 19 | if err := otf.Start(); err != nil { 20 | log.Error("failed to start otf", "error", err) 21 | return 22 | } 23 | 24 | listener, err := minecraft.Listen("raknet", "127.0.0.1:19132") 25 | if err != nil { 26 | panic(err) 27 | } 28 | 29 | otf.SetListener(listener) 30 | 31 | for { 32 | _, _ = listener.Accept() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/akmalfairuz/bedrockpack 2 | 3 | go 1.23.0 4 | 5 | toolchain go1.23.4 6 | 7 | require ( 8 | github.com/google/uuid v1.6.0 9 | github.com/sandertv/gophertunnel v1.44.1-0.20250228152750-9a988d58ee2d 10 | golang.org/x/oauth2 v0.28.0 11 | ) 12 | 13 | require ( 14 | github.com/df-mc/atomic v1.10.0 // indirect 15 | github.com/go-gl/mathgl v1.2.0 // indirect 16 | github.com/go-jose/go-jose/v3 v3.0.3 // indirect 17 | github.com/go-jose/go-jose/v4 v4.0.5 // indirect 18 | github.com/golang/protobuf v1.5.2 // indirect 19 | github.com/golang/snappy v1.0.0 // indirect 20 | github.com/klauspost/compress v1.18.0 // indirect 21 | github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect 22 | github.com/pelletier/go-toml v1.9.5 // indirect 23 | github.com/sandertv/go-raknet v1.14.3-0.20250305181847-6af3e95113d6 // indirect 24 | golang.org/x/crypto v0.36.0 // indirect 25 | golang.org/x/image v0.25.0 // indirect 26 | golang.org/x/net v0.37.0 // indirect 27 | golang.org/x/text v0.23.0 // indirect 28 | google.golang.org/appengine v1.6.7 // indirect 29 | google.golang.org/protobuf v1.33.0 // indirect 30 | ) 31 | -------------------------------------------------------------------------------- /pack/hash.go: -------------------------------------------------------------------------------- 1 | package pack 2 | 3 | import ( 4 | sha256lib "crypto/sha256" 5 | "encoding/binary" 6 | "github.com/google/uuid" 7 | ) 8 | 9 | func sha256(input []byte) []byte { 10 | hash := sha256lib.Sum256(input) 11 | return hash[:] 12 | } 13 | 14 | // uuidFromSeed generates a UUID from a given hash and modifies the last 4 bytes using mod. 15 | func uuidFromSeed(hash []byte, mod int) string { 16 | if len(hash) < 16 { 17 | // Zero-fill if the hash is too short 18 | hash = append(hash, make([]byte, 16-len(hash))...) 19 | } 20 | var uuidBytes [16]byte 21 | copy(uuidBytes[:], hash[:16]) // Use the first 16 bytes for the UUID 22 | 23 | // Extract last 4 bytes and convert to int32 24 | last4Bytes := binary.BigEndian.Uint32(uuidBytes[12:16]) 25 | newLast4Bytes := last4Bytes + uint32(mod) 26 | 27 | // Put the modified value back 28 | binary.BigEndian.PutUint32(uuidBytes[12:16], newLast4Bytes) 29 | 30 | // Set UUID variant and version (version 4, random UUID structure) 31 | uuidBytes[6] = (uuidBytes[6] & 0x0F) | (4 << 4) // Set version 4 32 | uuidBytes[8] = (uuidBytes[8] & 0x3F) | 0x80 // Set variant 33 | 34 | return uuid.UUID(uuidBytes).String() 35 | } 36 | -------------------------------------------------------------------------------- /pack/encryption_test.go: -------------------------------------------------------------------------------- 1 | package pack 2 | 3 | import ( 4 | "bytes" 5 | "encoding/hex" 6 | "testing" 7 | ) 8 | 9 | func TestEncrypt(t *testing.T) { 10 | txt := []byte("HELLO WORLD THIS IS BEDROCKPACK 9418894178") 11 | key := []byte("0123Z5678K0123u567890123Z56789P1") 12 | 13 | encrypted, err := encryptCfb(txt, key) 14 | if err != nil { 15 | t.Fatal(err) 16 | } 17 | 18 | if hex.EncodeToString(encrypted) != "173918d75ea78e660b4f8927e11ad475941c55ccb0bb0fbd39e1e4f5d9233e86281677cc2e11d199ab19" { 19 | t.Fatal("mismatch") 20 | } 21 | } 22 | 23 | func TestDecrypt(t *testing.T) { 24 | encrypted, err := hex.DecodeString("173918d75ea78e660b4f8927e11ad475941c55ccb0bb0fbd39e1e4f5d9233e86281677cc2e11d199ab19") 25 | if err != nil { 26 | t.Fatal(err) 27 | } 28 | 29 | key := []byte("0123Z5678K0123u567890123Z56789P1") 30 | decrypted, err := decryptCfb(encrypted, key) 31 | if err != nil { 32 | t.Fatal(err) 33 | } 34 | 35 | if !bytes.Equal(decrypted, []byte("HELLO WORLD THIS IS BEDROCKPACK 9418894178")) { 36 | t.Fatal("mismatch") 37 | } 38 | } 39 | 40 | func TestEncryptDecryptCfb(t *testing.T) { 41 | txt := []byte("HELLO WORLD THIS IS BEDROCKPACK 9418894178") 42 | key := []byte("0123Z5678K0123u567890123Z56789P1") 43 | 44 | encrypted, err := encryptCfb(txt, key) 45 | if err != nil { 46 | t.Fatal(err) 47 | } 48 | 49 | decrypted, err := decryptCfb(encrypted, key) 50 | if err != nil { 51 | t.Fatal(err) 52 | } 53 | 54 | if !bytes.Equal(txt, decrypted) { 55 | t.Fatal("mismatch") 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bedrockpack 2 | A Minecraft Bedrock tool for decrypting, encrypting, managing, and stealing resource packs! 3 | 4 | ## Download 5 | https://github.com/AkmalFairuz/bedrockpack/releases/ 6 | 7 | ## Usage 8 | 9 | #### Decrypt the resource pack using the given key 10 | ``` 11 | bedrockpack decrypt 12 | ``` 13 | 14 | #### Encrypt the resource pack using either the given key or a generated key 15 | - Automatically minify all the JSON files 16 | - Automatically regenerate the UUID of the resource pack in manifest.json 17 | - Automatically compress .png files with the best compression level. 18 | ``` 19 | bedrockpack encrypt 20 | ``` 21 | 22 | #### Steal the resource pack from a server and decrypt it automatically 23 | - Xbox authentication is required. 24 | ``` 25 | bedrockpack steal 26 | ``` 27 | 28 | ## On The Fly Resource Pack 29 | 30 | This feature allows servers to use resource packs from a GitHub repository. The server will monitor the repository for changes and automatically update the resource pack on the server. This is useful for servers that want to use a custom resource pack without having to manually upload it to the server and restarting the server. 31 | 32 | See [example/otf.go](example/otf.go) 33 | 34 | ### Features 35 | - UUID are automatically generated based on the pack content 36 | - Automatically encrypt the pack and the encryption key are generated based on the pack content 37 | - Automatically minify all the JSON files 38 | - Automatically compress .png files with the best compression level. 39 | -------------------------------------------------------------------------------- /pack/encryption.go: -------------------------------------------------------------------------------- 1 | package pack 2 | 3 | import ( 4 | "crypto/aes" 5 | "math/rand" 6 | ) 7 | 8 | func decryptCfb(data []byte, key []byte) ([]byte, error) { 9 | b, err := aes.NewCipher(key) 10 | if err != nil { 11 | return nil, err 12 | } 13 | 14 | shiftRegister := append(key[:16], data...) // prefill with iv + cipherdata 15 | _tmp := make([]byte, 16) 16 | off := 0 17 | for off < len(data) { 18 | b.Encrypt(_tmp, shiftRegister) 19 | data[off] ^= _tmp[0] 20 | shiftRegister = shiftRegister[1:] 21 | off++ 22 | } 23 | return data, nil 24 | } 25 | 26 | func encryptCfb(data []byte, key []byte) ([]byte, error) { 27 | b, err := aes.NewCipher(key) 28 | if err != nil { 29 | return nil, err 30 | } 31 | 32 | shiftRegister := make([]byte, 16) 33 | copy(shiftRegister, key[:16]) // prefill with iv 34 | _tmp := make([]byte, 16) 35 | off := 0 36 | for off < len(data) { 37 | b.Encrypt(_tmp, shiftRegister) 38 | data[off] ^= _tmp[0] 39 | shiftRegister = append(shiftRegister[1:], data[off]) 40 | off++ 41 | } 42 | return data, nil 43 | } 44 | 45 | func GenerateKey() []byte { 46 | const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 47 | const length = 32 48 | result := make([]byte, length) 49 | for i := 0; i < length; i++ { 50 | result[i] = chars[rand.Intn(len(chars))] 51 | } 52 | 53 | return result 54 | } 55 | 56 | func GenerateKeyFromSeed(seed []byte) []byte { 57 | const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 58 | const length = 32 59 | result := make([]byte, length) 60 | for i := 0; i < length; i++ { 61 | result[i] = chars[int(seed[i%len(seed)])%len(chars)] 62 | } 63 | 64 | return result 65 | } 66 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | # This workflow will build a golang project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go 3 | 4 | name: Go Build Binaries 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | permissions: 11 | contents: write 12 | packages: write 13 | 14 | jobs: 15 | release-linux-amd64: 16 | name: release linux/amd64 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v4 20 | - uses: wangyoucao577/go-release-action@v1 21 | with: 22 | github_token: ${{ secrets.GITHUB_TOKEN }} 23 | goos: linux 24 | goarch: amd64 25 | release-windows-amd64: 26 | name: release windows/amd64 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v4 30 | - uses: wangyoucao577/go-release-action@v1 31 | with: 32 | github_token: ${{ secrets.GITHUB_TOKEN }} 33 | goos: windows 34 | goarch: amd64 35 | 36 | release-linux-arm64: 37 | name: release linux/arm64 38 | runs-on: ubuntu-latest 39 | steps: 40 | - uses: actions/checkout@v4 41 | - uses: wangyoucao577/go-release-action@v1 42 | with: 43 | github_token: ${{ secrets.GITHUB_TOKEN }} 44 | goos: linux 45 | goarch: arm64 46 | release-darwin-arm64: 47 | name: release darwin/arm64 48 | runs-on: ubuntu-latest 49 | steps: 50 | - uses: actions/checkout@v4 51 | - uses: wangyoucao577/go-release-action@v1 52 | with: 53 | github_token: ${{ secrets.GITHUB_TOKEN }} 54 | goos: darwin 55 | goarch: arm64 56 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/akmalfairuz/bedrockpack/internal/stealer" 6 | "github.com/akmalfairuz/bedrockpack/pack" 7 | "os" 8 | ) 9 | 10 | func printHelp() { 11 | fmt.Println("Usage:") 12 | fmt.Println(" bedrockpack decrypt ") 13 | fmt.Println(" Decrypt the resource pack using the given key") 14 | fmt.Println(" bedrockpack encrypt ") 15 | fmt.Println(" Encrypt the resource pack using either the given key or a generated key") 16 | fmt.Println(" Automatically minify all the JSON files") 17 | fmt.Println(" Automatically regenerate the UUID of the resource pack in manifest.json") 18 | fmt.Println(" bedrockpack steal ") 19 | fmt.Println(" Steal the resource pack from a server and decrypt it automatically") 20 | fmt.Println(" Xbox authentication is required") 21 | } 22 | 23 | func main() { 24 | args := os.Args[1:] 25 | if len(args) == 0 { 26 | printHelp() 27 | return 28 | } 29 | 30 | switch args[0] { 31 | case "encrypt": 32 | if len(args) < 2 { 33 | printHelp() 34 | return 35 | } 36 | 37 | fmt.Println("Loading " + args[1] + " resource pack...") 38 | rp, err := pack.LoadResourcePack(args[1]) 39 | if err != nil { 40 | panic(err) 41 | } 42 | 43 | fmt.Println("Backup resource pack...") 44 | if err := rp.Save(args[1] + ".bak"); err != nil { 45 | panic(err) 46 | } 47 | 48 | var key []byte 49 | if len(args) > 2 { 50 | key = []byte(args[2]) 51 | } else { 52 | key = pack.GenerateKey() 53 | } 54 | 55 | fmt.Println("Regenerate resource pack UUID...") 56 | if err := rp.RegenerateUUID(nil); err != nil { 57 | panic(err) 58 | } 59 | fmt.Printf("New resource pack UUID: %s\n", rp.UUID()) 60 | 61 | fmt.Println("Minifying JSON files in resource pack...") 62 | if err := rp.MinifyJSONFiles(); err != nil { 63 | panic(err) 64 | } 65 | 66 | fmt.Println("Compressing .png files in resource pack...") 67 | if err := rp.CompressPNGFiles(); err != nil { 68 | panic(err) 69 | } 70 | 71 | fmt.Println("Encrypting resource pack with key " + string(key) + "...") 72 | if err := rp.Encrypt(key); err != nil { 73 | panic(err) 74 | } 75 | 76 | if err := rp.Save(args[1]); err != nil { 77 | panic(err) 78 | } 79 | _ = os.WriteFile(args[1]+".key.txt", key, 0777) 80 | fmt.Println("Resource pack encrypted!") 81 | case "decrypt": 82 | if len(args) < 3 { 83 | printHelp() 84 | return 85 | } 86 | 87 | fmt.Println("Loading " + args[1] + " resource pack...") 88 | rp, err := pack.LoadResourcePack(args[1]) 89 | if err != nil { 90 | panic(err) 91 | } 92 | 93 | fmt.Println("Backup resource pack...") 94 | if err := rp.Save(args[1] + ".bak"); err != nil { 95 | panic(err) 96 | } 97 | 98 | key := []byte(args[2]) 99 | fmt.Println("Decrypting resource pack with key " + string(key) + "...") 100 | if err := rp.Decrypt(key); err != nil { 101 | panic(err) 102 | } 103 | 104 | if err := rp.Save(args[1]); err != nil { 105 | panic(err) 106 | } 107 | fmt.Println("Resource pack decrypted!") 108 | case "steal": 109 | if len(args) < 2 { 110 | printHelp() 111 | return 112 | } 113 | stealer.Run(args[1]) 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /internal/stealer/stealer.go: -------------------------------------------------------------------------------- 1 | package stealer 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/akmalfairuz/bedrockpack/pack" 8 | "github.com/sandertv/gophertunnel/minecraft" 9 | "github.com/sandertv/gophertunnel/minecraft/auth" 10 | "github.com/sandertv/gophertunnel/minecraft/resource" 11 | "golang.org/x/oauth2" 12 | "io" 13 | "net/http" 14 | "os" 15 | "os/signal" 16 | "strings" 17 | "syscall" 18 | "time" 19 | ) 20 | 21 | func Run(serverAddress string) { 22 | if len(strings.Split(serverAddress, ":")) == 1 { 23 | serverAddress = serverAddress + ":19132" 24 | } 25 | cacheTokenBytes, err := os.ReadFile(".token_cache") 26 | if err == nil { 27 | var cacheTok *oauth2.Token 28 | if err := json.Unmarshal(cacheTokenBytes, &cacheTok); err == nil { 29 | if time.Now().Add(time.Second * 30).Before(cacheTok.Expiry) { 30 | fmt.Println("Using .token_cache for authentication") 31 | src := auth.RefreshTokenSource(cacheTok) 32 | handleConn(serverAddress, src) 33 | return 34 | } 35 | } 36 | } 37 | 38 | token, err := auth.RequestLiveToken() 39 | if err != nil { 40 | panic(err) 41 | } 42 | tokBytes, err := json.Marshal(token) 43 | if err := os.WriteFile(".token_cache", tokBytes, 0777); err != nil { 44 | panic(err) 45 | } 46 | 47 | src := auth.RefreshTokenSource(token) 48 | handleConn(serverAddress, src) 49 | } 50 | 51 | func handleConn(serverAddress string, src oauth2.TokenSource) { 52 | ctx, cancel := context.WithCancel(context.Background()) 53 | sigs := make(chan os.Signal, 1) 54 | signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) 55 | var serverConn *minecraft.Conn 56 | var err error 57 | go func() { 58 | <-sigs 59 | if serverConn != nil { 60 | _ = serverConn.Close() 61 | serverConn = nil 62 | } 63 | cancel() 64 | os.Exit(0) 65 | }() 66 | 67 | fmt.Printf("Connecting to %s... (may take up to 5 minutes) \n", serverAddress) 68 | serverConn, err = minecraft.Dialer{ 69 | TokenSource: src, 70 | }.DialContext(ctx, "raknet", serverAddress) 71 | if err != nil { 72 | panic(err) 73 | } 74 | 75 | fmt.Println("Getting resource pack information...") 76 | if err := serverConn.DoSpawnContext(ctx); err != nil { 77 | panic(err) 78 | } 79 | 80 | for i, rp := range serverConn.ResourcePacks() { 81 | if err := stealPack(i, serverAddress, rp); err != nil { 82 | panic(err) 83 | } 84 | } 85 | 86 | _ = serverConn.Close() 87 | } 88 | 89 | func stealPack(i int, serverAddress string, rp *resource.Pack) error { 90 | packBytes, err := downloadPack(rp) 91 | if err != nil { 92 | return err 93 | } 94 | pac, err := pack.LoadResourcePackFromBytes(packBytes) 95 | if err != nil { 96 | return fmt.Errorf("error loading resource pack: %w", err) 97 | } 98 | fmt.Printf("Decrypting resource pack %s with key %s ...\n", rp.Name(), rp.ContentKey()) 99 | if err := pac.Decrypt([]byte(rp.ContentKey())); err != nil { 100 | return fmt.Errorf("error when decrypting resource pack: %w", err) 101 | } 102 | 103 | rpName := rp.Name() 104 | disallowedChars := []string{"\\", "/", ":", "*", "?", "\"", "<", ">", "|"} // Windows disallowed characters 105 | for _, char := range disallowedChars { 106 | rpName = strings.ReplaceAll(rpName, char, "") 107 | } 108 | 109 | prefix, _, _ := strings.Cut(serverAddress, ":") 110 | _ = os.Mkdir(prefix, 0777) 111 | savePath := fmt.Sprintf("%s/%d_%s.zip", prefix, i, rpName) 112 | 113 | fmt.Printf("Resource pack saved in %s\n", savePath) 114 | return pac.Save(savePath) 115 | } 116 | 117 | func downloadPack(pack *resource.Pack) ([]byte, error) { 118 | if pack.DownloadURL() != "" { 119 | fmt.Printf("Downloading resource pack %s from %s\n", pack.Name(), pack.DownloadURL()) 120 | resp, err := http.Get(pack.DownloadURL()) 121 | if err != nil { 122 | return nil, err 123 | } 124 | if resp.StatusCode >= 400 { 125 | return nil, fmt.Errorf("error: %v", resp.StatusCode) 126 | } 127 | packBytes, err := io.ReadAll(resp.Body) 128 | if err != nil { 129 | return nil, err 130 | } 131 | return packBytes, err 132 | } 133 | buf := make([]byte, pack.Len()) 134 | off := 0 135 | for { 136 | n, err := pack.ReadAt(buf[off:], int64(off)) 137 | if err != nil { 138 | if err == io.EOF { 139 | break 140 | } 141 | return nil, err 142 | } 143 | off += n 144 | } 145 | return buf, nil 146 | } 147 | -------------------------------------------------------------------------------- /pack/otf.go: -------------------------------------------------------------------------------- 1 | package pack 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/sandertv/gophertunnel/minecraft" 8 | "github.com/sandertv/gophertunnel/minecraft/resource" 9 | "io" 10 | "log/slog" 11 | "net/http" 12 | "time" 13 | ) 14 | 15 | type OTF struct { 16 | log *slog.Logger 17 | listener *minecraft.Listener 18 | orgName string 19 | repoName string 20 | branch string 21 | // pat is personal access token 22 | pat string 23 | currentPackCommit string 24 | currentPackKey string 25 | currentPack *resource.Pack 26 | } 27 | 28 | const ( 29 | otfUserAgent = "BedrockPack-OTF-Agent" 30 | ) 31 | 32 | type OTFConfig struct { 33 | OrgName string 34 | RepoName string 35 | Branch string 36 | PAT string 37 | } 38 | 39 | func (conf OTFConfig) New(log *slog.Logger) *OTF { 40 | return &OTF{ 41 | log: log.With("pack_repo", conf.OrgName+"/"+conf.RepoName+":"+conf.Branch), 42 | orgName: conf.OrgName, 43 | repoName: conf.RepoName, 44 | branch: conf.Branch, 45 | pat: conf.PAT, 46 | } 47 | } 48 | 49 | // Start ... 50 | func (o *OTF) Start() error { 51 | // try first tick 52 | if err := o.tick(); err != nil { 53 | return err 54 | } 55 | 56 | // then start the ticker 57 | ticker := time.NewTicker(10 * time.Minute) 58 | defer ticker.Stop() 59 | go func() { 60 | for { 61 | select { 62 | case <-ticker.C: 63 | if err := o.tick(); err != nil { 64 | o.log.Error("failed to tick", "error", err) 65 | } 66 | } 67 | } 68 | }() 69 | return nil 70 | } 71 | 72 | // tick ... 73 | func (o *OTF) tick() error { 74 | commitHash, err := o.lastCommit(o.branch) 75 | if err != nil { 76 | return fmt.Errorf("failed to get last commit: %w", err) 77 | } 78 | 79 | if o.currentPackCommit == commitHash { 80 | return nil 81 | } 82 | 83 | if o.currentPackCommit != "" { 84 | o.log.Info("detected pack update, updating pack", "new_commit_hash", commitHash) 85 | } 86 | 87 | o.log.Info("downloading pack") 88 | packBytes, err := o.downloadRepoZip(commitHash) 89 | if err != nil { 90 | return fmt.Errorf("failed to download pack: %w", err) 91 | } 92 | 93 | o.log.Info("loading pack") 94 | pack, err := LoadResourcePackFromBytes(packBytes) 95 | if err != nil { 96 | return fmt.Errorf("failed to load pack: %w", err) 97 | } 98 | 99 | pack.DeleteFile("README.md") 100 | pack.DeleteFilesByPrefix(".git") // .github, .gitignore, etc. 101 | 102 | o.log.Info("minifying json files") 103 | if err := pack.MinifyJSONFiles(); err != nil { 104 | return fmt.Errorf("failed to minify JSON files: %w", err) 105 | } 106 | 107 | o.log.Info("compressing png files") 108 | if err := pack.CompressPNGFiles(); err != nil { 109 | return fmt.Errorf("failed to compress PNG files: %w", err) 110 | } 111 | 112 | packHash := pack.ComputeHash() 113 | packKey := GenerateKeyFromSeed(packHash) 114 | 115 | o.log.Info("generating uuid") 116 | if err := pack.RegenerateUUID(packHash); err != nil { 117 | return fmt.Errorf("failed to regenerate pack UUID: %w", err) 118 | } 119 | 120 | o.log.Info("encrypting pack", "pack_key", string(packKey)) 121 | if err := pack.Encrypt(packKey); err != nil { 122 | return fmt.Errorf("failed to encrypt pack: %w", err) 123 | } 124 | 125 | o.log.Info("saving pack") 126 | compiledPackBytes, err := pack.SaveToBytes() 127 | if err != nil { 128 | return fmt.Errorf("failed to save pack: %w", err) 129 | } 130 | 131 | packBytes = nil // free memory 132 | 133 | o.log.Info("compiling pack") 134 | compiledPack, err := resource.Read(bytes.NewBuffer(compiledPackBytes)) 135 | if err != nil { 136 | return fmt.Errorf("failed to read pack: %w", err) 137 | } 138 | 139 | compiledPackBytes = nil // free memory 140 | 141 | o.log.Info("pack updated", "pack_uuid", compiledPack.UUID().String()) 142 | var prevPackUUID string 143 | if o.currentPack != nil { 144 | prevPackUUID = o.currentPack.UUID().String() 145 | } 146 | o.currentPackKey = string(packKey) 147 | o.currentPackCommit = commitHash 148 | o.currentPack = compiledPack 149 | 150 | if o.listener != nil { 151 | if prevPackUUID != "" { 152 | o.listener.RemoveResourcePack(prevPackUUID) 153 | } 154 | o.addPackToListener() 155 | } 156 | 157 | return nil 158 | } 159 | 160 | // SetListener ... 161 | func (o *OTF) SetListener(listener *minecraft.Listener) { 162 | o.listener = listener 163 | o.addPackToListener() 164 | } 165 | 166 | // addPackToListener adds the pack to the listener. 167 | func (o *OTF) addPackToListener() { 168 | if o.listener == nil || o.currentPack == nil { 169 | return 170 | } 171 | o.listener.AddResourcePack(o.currentPack.WithContentKey(o.currentPackKey)) 172 | } 173 | 174 | // Listener ... 175 | func (o *OTF) Listener() *minecraft.Listener { 176 | return o.listener 177 | } 178 | 179 | // initializeHeaders sets the necessary headers for the HTTP request. 180 | func (o *OTF) initializeHeaders(req *http.Request) { 181 | if o.pat != "" { 182 | req.Header.Set("Authorization", "Bearer "+o.pat) 183 | } 184 | req.Header.Set("User-Agent", otfUserAgent) 185 | req.Header.Set("X-GitHub-Api-Version", "2022-11-28") 186 | } 187 | 188 | // lastCommit fetches the latest commit hash from the given branch. 189 | func (o *OTF) lastCommit(branch string) (string, error) { 190 | url := fmt.Sprintf("https://api.github.com/repos/%s/%s/commits?sha=%s&per_page=1", o.orgName, o.repoName, branch) 191 | 192 | req, err := http.NewRequest("GET", url, nil) 193 | if err != nil { 194 | return "", err 195 | } 196 | o.initializeHeaders(req) 197 | 198 | resp, err := http.DefaultClient.Do(req) 199 | if err != nil { 200 | return "", err 201 | } 202 | defer resp.Body.Close() 203 | 204 | if resp.StatusCode != http.StatusOK { 205 | return "", fmt.Errorf("GitHub API returned status: %d", resp.StatusCode) 206 | } 207 | 208 | var commits []struct { 209 | SHA string `json:"sha"` 210 | } 211 | if err := json.NewDecoder(resp.Body).Decode(&commits); err != nil { 212 | return "", err 213 | } 214 | 215 | if len(commits) == 0 { 216 | return "", fmt.Errorf("no commits found for branch: %s", branch) 217 | } 218 | 219 | return commits[0].SHA, nil 220 | } 221 | 222 | // downloadRepoZip downloads the entire repository as a .zip for a specific commit or branch. 223 | func (o *OTF) downloadRepoZip(ref string) ([]byte, error) { 224 | url := fmt.Sprintf("https://api.github.com/repos/%s/%s/zipball/%s", o.orgName, o.repoName, ref) 225 | 226 | req, err := http.NewRequest("GET", url, nil) 227 | if err != nil { 228 | return nil, err 229 | } 230 | o.initializeHeaders(req) 231 | 232 | resp, err := http.DefaultClient.Do(req) 233 | if err != nil { 234 | return nil, err 235 | } 236 | defer resp.Body.Close() 237 | 238 | if resp.StatusCode != http.StatusOK { 239 | return nil, fmt.Errorf("failed to download repository: %s (status: %d)", url, resp.StatusCode) 240 | } 241 | 242 | // Read the response body into a byte slice 243 | data, err := io.ReadAll(resp.Body) 244 | if err != nil { 245 | return nil, err 246 | } 247 | 248 | return data, nil 249 | } 250 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/df-mc/atomic v1.10.0 h1:0ZuxBKwR/hxcFGorKiHIp+hY7hgY+XBTzhCYD2NqSEg= 5 | github.com/df-mc/atomic v1.10.0/go.mod h1:Gw9rf+rPIbydMjA329Jn4yjd/O2c/qusw3iNp4tFGSc= 6 | github.com/go-gl/mathgl v1.0.0 h1:t9DznWJlXxxjeeKLIdovCOVJQk/GzDEL7h/h+Ro2B68= 7 | github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ= 8 | github.com/go-gl/mathgl v1.1.0 h1:0lzZ+rntPX3/oGrDzYGdowSLC2ky8Osirvf5uAwfIEA= 9 | github.com/go-gl/mathgl v1.1.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ= 10 | github.com/go-gl/mathgl v1.2.0 h1:v2eOj/y1B2afDxF6URV1qCYmo1KW08lAMtTbOn3KXCY= 11 | github.com/go-gl/mathgl v1.2.0/go.mod h1:pf9+b5J3LFP7iZ4XXaVzZrCle0Q/vNpB/vDe5+3ulRE= 12 | github.com/go-jose/go-jose/v3 v3.0.3 h1:fFKWeig/irsp7XD2zBxvnmA/XaRWp5V3CBsZXJF7G7k= 13 | github.com/go-jose/go-jose/v3 v3.0.3/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ= 14 | github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE= 15 | github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA= 16 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 17 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 18 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 19 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 20 | github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= 21 | github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 22 | github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= 23 | github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 24 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 25 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 26 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 27 | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 28 | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 29 | github.com/klauspost/compress v1.15.1 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A= 30 | github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= 31 | github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= 32 | github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= 33 | github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= 34 | github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= 35 | github.com/muhammadmuzzammil1998/jsonc v1.0.0 h1:8o5gBQn4ZA3NBA9DlTujCj2a4w0tqWrPVjDwhzkgTIs= 36 | github.com/muhammadmuzzammil1998/jsonc v1.0.0/go.mod h1:saF2fIVw4banK0H4+/EuqfFLpRnoy5S+ECwTOCcRcSU= 37 | github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= 38 | github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= 39 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 40 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 41 | github.com/sandertv/go-raknet v1.14.2 h1:UZLyHn5yQU2Dq2GVq/LlxwAUikaq4q4AA1rl/Pf3AXQ= 42 | github.com/sandertv/go-raknet v1.14.2/go.mod h1:/yysjwfCXm2+2OY8mBazLzcxJ3irnylKCyG3FLgUPVU= 43 | github.com/sandertv/go-raknet v1.14.3-0.20250305181847-6af3e95113d6 h1:ZfK7NCzIDE+dzp5x6NIO4JDLsjsOxi762CNR1Obds2Q= 44 | github.com/sandertv/go-raknet v1.14.3-0.20250305181847-6af3e95113d6/go.mod h1:/yysjwfCXm2+2OY8mBazLzcxJ3irnylKCyG3FLgUPVU= 45 | github.com/sandertv/gophertunnel v1.38.0 h1:hGCq9uhAmIFOLAaw/qcLkmcHVo7dVzf3I9Iqx0GOb+0= 46 | github.com/sandertv/gophertunnel v1.38.0/go.mod h1:nqbZPCBZmKot/DHiY4efq8QQj6gvLvIk8LWPxXF8+6g= 47 | github.com/sandertv/gophertunnel v1.44.1-0.20250228152750-9a988d58ee2d h1:s41L726crgaFj0/6DMPt8Zg9Z2n1d5yGmcQVO+0iMHw= 48 | github.com/sandertv/gophertunnel v1.44.1-0.20250228152750-9a988d58ee2d/go.mod h1:4NOhhvyP+1GQ3TA9aec7TFAfTUP+O3Jhi5f+m+aUvQg= 49 | github.com/sandertv/gophertunnel v1.44.1-0.20250312143112-67b1aa6edbe7 h1:igmTC+NX/X1NjPeyjzR9lQP2dxecTnbz7ytTsw77d1c= 50 | github.com/sandertv/gophertunnel v1.44.1-0.20250312143112-67b1aa6edbe7/go.mod h1:lvzOdyb2fkoo3uySe++hy4UKq0I649oUFJKkro2ZHpY= 51 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 52 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 53 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 54 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 55 | go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= 56 | go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 57 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 58 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 59 | golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= 60 | golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= 61 | golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= 62 | golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= 63 | golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= 64 | golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= 65 | golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 66 | golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= 67 | golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= 68 | golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ= 69 | golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs= 70 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 71 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 72 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 73 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 74 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 75 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 76 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 77 | golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= 78 | golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= 79 | golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= 80 | golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= 81 | golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= 82 | golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= 83 | golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M= 84 | golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec= 85 | golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= 86 | golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= 87 | golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc= 88 | golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= 89 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 90 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 91 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 92 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 93 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 94 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 95 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 96 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 97 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 98 | golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 99 | golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 100 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 101 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 102 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 103 | golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= 104 | golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= 105 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 106 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 107 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 108 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 109 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 110 | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 111 | golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= 112 | golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= 113 | golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= 114 | golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= 115 | golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= 116 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 117 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 118 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 119 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 120 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 121 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 122 | google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= 123 | google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 124 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 125 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 126 | google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= 127 | google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= 128 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 129 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 130 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 131 | -------------------------------------------------------------------------------- /pack/resource_pack.go: -------------------------------------------------------------------------------- 1 | package pack 2 | 3 | import ( 4 | "archive/zip" 5 | "bytes" 6 | "encoding/binary" 7 | "encoding/json" 8 | "errors" 9 | "fmt" 10 | "io" 11 | "math/rand" 12 | "os" 13 | "path/filepath" 14 | "regexp" 15 | "sort" 16 | "strings" 17 | ) 18 | 19 | type ResourcePack struct { 20 | uuid string 21 | files map[string][]byte 22 | encrypted bool 23 | } 24 | 25 | func LoadResourcePack(path string) (*ResourcePack, error) { 26 | packBytes, err := os.ReadFile(path) 27 | if err != nil { 28 | return nil, err 29 | } 30 | 31 | return LoadResourcePackFromBytes(packBytes) 32 | } 33 | 34 | func LoadResourcePackFromBytes(packBytes []byte) (*ResourcePack, error) { 35 | rp := &ResourcePack{} 36 | 37 | if err := rp.load(packBytes); err != nil { 38 | return nil, err 39 | } 40 | 41 | return rp, nil 42 | } 43 | 44 | func (r *ResourcePack) load(packBytes []byte) error { 45 | reader, err := zip.NewReader(bytes.NewReader(packBytes), int64(len(packBytes))) 46 | if err != nil { 47 | return err 48 | } 49 | 50 | manifestFound := false 51 | basePath := "" 52 | 53 | r.files = map[string][]byte{} 54 | for _, fileInfo := range reader.File { 55 | file, err := fileInfo.Open() 56 | if err != nil { 57 | return err 58 | } 59 | content, err := io.ReadAll(file) 60 | if err != nil { 61 | return err 62 | } 63 | if filepath.Base(fileInfo.Name) == "manifest.json" { 64 | var manifest map[string]any 65 | if err := json.Unmarshal(content, &manifest); err != nil { 66 | return err 67 | } 68 | if _, ok := manifest["header"]; !ok { 69 | return errors.New("manifest.json header not found") 70 | } 71 | if _, ok := manifest["header"].(map[string]any); !ok { 72 | return errors.New("manifest.json header is not a map[string]any") 73 | } 74 | if _, ok := manifest["header"].(map[string]any)["uuid"]; !ok { 75 | return errors.New("manifest.json header uuid not found") 76 | } 77 | packUuid, ok := manifest["header"].(map[string]any)["uuid"].(string) 78 | if !ok { 79 | return errors.New("manifest.json header uuid is not a string") 80 | } 81 | r.uuid = packUuid 82 | manifestFound = true 83 | basePath = filepath.Dir(fileInfo.Name) 84 | } 85 | 86 | if fileInfo.Name == "" { 87 | continue 88 | } 89 | r.files[fileInfo.Name] = content 90 | } 91 | 92 | if !manifestFound { 93 | return errors.New("manifest.json not found") 94 | } 95 | 96 | if basePath != "." { 97 | if !strings.HasSuffix(basePath, "/") { 98 | basePath += "/" 99 | } 100 | for fileName, fileBytes := range r.files { 101 | if strings.HasPrefix(fileName, basePath) { 102 | newFileName := strings.TrimPrefix(fileName, basePath) 103 | if newFileName == "" { 104 | continue 105 | } 106 | r.files[newFileName] = fileBytes 107 | delete(r.files, fileName) 108 | } 109 | } 110 | } 111 | 112 | if _, ok := r.files["contents.json"]; ok { 113 | r.encrypted = true 114 | } 115 | 116 | return nil 117 | } 118 | 119 | type contentJson struct { 120 | Content []contentJsonEntry `json:"content"` 121 | } 122 | 123 | type contentJsonEntry struct { 124 | Path string `json:"path"` 125 | Key string `json:"key"` 126 | } 127 | 128 | func (r *ResourcePack) UUID() string { 129 | return r.uuid 130 | } 131 | 132 | func (r *ResourcePack) DeleteFile(fileName string) { 133 | delete(r.files, fileName) 134 | } 135 | 136 | func (r *ResourcePack) DeleteFilesByPrefix(prefix string) { 137 | for fileName := range r.files { 138 | if strings.HasPrefix(fileName, prefix) { 139 | delete(r.files, fileName) 140 | } 141 | } 142 | } 143 | 144 | func (r *ResourcePack) DeleteFilesBySuffix(suffix string) { 145 | for fileName := range r.files { 146 | if strings.HasSuffix(fileName, suffix) { 147 | delete(r.files, fileName) 148 | } 149 | } 150 | } 151 | 152 | func (r *ResourcePack) loadFile(fileName string) ([]byte, error) { 153 | fileBytes, ok := r.files[fileName] 154 | if !ok { 155 | return nil, fmt.Errorf("file %s not found", fileName) 156 | } 157 | return fileBytes, nil 158 | } 159 | 160 | func (r *ResourcePack) Decrypt(key []byte) error { 161 | if !r.encrypted { 162 | return nil 163 | } 164 | 165 | contentsBytes, err := r.loadFile("contents.json") 166 | if err != nil { 167 | return err 168 | } 169 | 170 | if len(contentsBytes) < 256 { 171 | return errors.New("contents.json bytes is less than 256 bytes") 172 | } 173 | 174 | contentRaw := contentsBytes[256:] 175 | decryptedContents, err := decryptCfb(contentRaw, key) 176 | if err != nil { 177 | return err 178 | } 179 | 180 | var contents contentJson 181 | if err := json.Unmarshal(decryptedContents, &contents); err != nil { 182 | return err 183 | } 184 | 185 | for _, content := range contents.Content { 186 | if content.Key == "" { 187 | continue 188 | } 189 | fileBytes, ok := r.files[content.Path] 190 | if !ok { 191 | continue 192 | } 193 | 194 | decryptedFileBytes, err := decryptCfb(fileBytes, []byte(content.Key)) 195 | if err != nil { 196 | return fmt.Errorf("failed to decrypt %s file with key %s: %w", content.Path, content.Key, err) 197 | } 198 | 199 | r.files[content.Path] = decryptedFileBytes 200 | } 201 | 202 | delete(r.files, "contents.json") 203 | r.encrypted = false 204 | return nil 205 | } 206 | 207 | func (r *ResourcePack) CompressPNGFiles() error { 208 | if r.encrypted { 209 | return errors.New("pack is encrypted") 210 | } 211 | 212 | for fileName, fileBytes := range r.files { 213 | if !strings.HasSuffix(fileName, ".png") { 214 | continue 215 | } 216 | compressedBytes, err := compressPng(fileBytes) 217 | if err != nil { 218 | return err 219 | } 220 | if len(compressedBytes) < len(fileBytes) { 221 | r.files[fileName] = compressedBytes 222 | continue 223 | } 224 | } 225 | return nil 226 | } 227 | 228 | var ( 229 | jsonReplaceRegex1 = regexp.MustCompile(`(?im)^\s+\/\/.*$`) 230 | jsonReplaceRegex2 = regexp.MustCompile(`(?im)\/\/[^"\[\]]+$`) 231 | ) 232 | 233 | func (r *ResourcePack) MinifyJSONFiles() error { 234 | if r.encrypted { 235 | return errors.New("pack is encrypted") 236 | } 237 | for fileName, fileBytes := range r.files { 238 | if !strings.HasSuffix(fileName, ".json") { 239 | continue 240 | } 241 | fileBytes = jsonReplaceRegex1.ReplaceAll(fileBytes, []byte("")) 242 | fileBytes = jsonReplaceRegex2.ReplaceAll(fileBytes, []byte("")) 243 | var data any 244 | if err := json.Unmarshal(fileBytes, &data); err != nil { 245 | // SKIP 246 | //fmt.Println(err) 247 | continue 248 | } 249 | 250 | minifiedJSON, err := json.Marshal(data) 251 | if err != nil { 252 | // SKIP 253 | //fmt.Println(err) 254 | continue 255 | } 256 | 257 | r.files[fileName] = minifiedJSON 258 | } 259 | 260 | return nil 261 | } 262 | 263 | func (r *ResourcePack) Encrypt(key []byte) error { 264 | if r.encrypted { 265 | return errors.New("unable to encrypt pack that already encrypted before") 266 | } 267 | 268 | contents := make([]contentJsonEntry, 0) 269 | 270 | for fileName, decryptedFileBytes := range r.files { 271 | if fileName == "manifest.json" || fileName == "pack_icon.png" { 272 | contents = append(contents, contentJsonEntry{ 273 | Path: fileName, 274 | }) 275 | continue 276 | } 277 | 278 | fileKey := GenerateKey() 279 | encryptedFileBytes, err := encryptCfb(decryptedFileBytes, fileKey) 280 | if err != nil { 281 | return err 282 | } 283 | r.files[fileName] = encryptedFileBytes 284 | 285 | contents = append(contents, contentJsonEntry{ 286 | Path: fileName, 287 | Key: string(fileKey), 288 | }) 289 | } 290 | 291 | contentBytes, err := json.Marshal(contentJson{Content: contents}) 292 | if err != nil { 293 | return err 294 | } 295 | 296 | contentBytes2 := bytes.NewBuffer(nil) 297 | contentBytes2.Write(make([]byte, 4)) // version 298 | contentBytes2.WriteString("\xfc\xb9\xcf\x9b") // type 299 | contentBytes2.Write(make([]byte, 8)) // padding 300 | contentBytes2.WriteString("\x24") // separator 301 | contentBytes2.WriteString(r.uuid) // uuid 302 | contentBytes2.Write(make([]byte, 256-contentBytes2.Len())) 303 | 304 | encryptedContentBytes, err := encryptCfb(contentBytes, key) 305 | if err != nil { 306 | return err 307 | } 308 | contentBytes2.Write(encryptedContentBytes) 309 | 310 | r.files["contents.json"] = contentBytes2.Bytes() 311 | return nil 312 | } 313 | 314 | func (r *ResourcePack) ComputeHash() []byte { 315 | toHash := bytes.Buffer{} 316 | fileLen := make([]byte, 4) 317 | 318 | fileNames := make([]string, 0, len(r.files)) 319 | for fileName := range r.files { 320 | fileNames = append(fileNames, fileName) 321 | } 322 | sort.Strings(fileNames) 323 | 324 | binary.BigEndian.PutUint32(fileLen, uint32(len(fileNames))) 325 | toHash.Write(fileLen) 326 | 327 | for _, fileName := range fileNames { 328 | fileBytes := r.files[fileName] 329 | 330 | fileNameLen := make([]byte, 2) 331 | binary.BigEndian.PutUint16(fileNameLen, uint16(len(fileName))) 332 | toHash.Write(fileNameLen) 333 | toHash.WriteString(strings.ReplaceAll(fileName, "\\", "/")) 334 | 335 | fileBytesLen := make([]byte, 4) 336 | binary.BigEndian.PutUint32(fileBytesLen, uint32(len(fileBytes))) 337 | toHash.Write(fileBytesLen) 338 | toHash.Write(fileBytes) 339 | } 340 | 341 | return sha256(toHash.Bytes()) 342 | } 343 | 344 | func (r *ResourcePack) Save(path string) error { 345 | zipFile, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0777) 346 | if err != nil { 347 | return err 348 | } 349 | defer zipFile.Close() 350 | arc := zip.NewWriter(zipFile) 351 | 352 | for fileName, fileBytes := range r.files { 353 | w, err := arc.Create(fileName) 354 | if err != nil { 355 | return err 356 | } 357 | if _, err := w.Write(fileBytes); err != nil { 358 | return err 359 | } 360 | } 361 | 362 | return arc.Close() 363 | } 364 | 365 | // SaveToBytes returns the zip file as a byte slice without creating a file 366 | func (r *ResourcePack) SaveToBytes() ([]byte, error) { 367 | var buf bytes.Buffer 368 | arc := zip.NewWriter(&buf) 369 | 370 | for fileName, fileBytes := range r.files { 371 | w, err := arc.Create(fileName) 372 | if err != nil { 373 | return nil, err 374 | } 375 | if _, err := w.Write(fileBytes); err != nil { 376 | return nil, err 377 | } 378 | } 379 | 380 | if err := arc.Close(); err != nil { 381 | return nil, err 382 | } 383 | 384 | return buf.Bytes(), nil 385 | } 386 | 387 | func (r *ResourcePack) RegenerateUUID(seed []byte) error { 388 | if seed == nil { 389 | seed = make([]byte, 16) 390 | for i := 0; i < 16; i++ { 391 | seed[i] = byte(rand.Intn(256)) 392 | } 393 | } 394 | 395 | if len(seed) < 16 { 396 | // zero fill 397 | seed = append(seed, make([]byte, 16-len(seed))...) 398 | } 399 | 400 | manifestBytes, err := r.loadFile("manifest.json") 401 | if err != nil { 402 | return err 403 | } 404 | 405 | var manifest map[string]any 406 | if err := json.Unmarshal(manifestBytes, &manifest); err != nil { 407 | return err 408 | } 409 | 410 | mod := 0 411 | newPackUuid := uuidFromSeed(seed, mod) 412 | mod++ 413 | 414 | if _, ok := manifest["header"]; !ok { 415 | return errors.New("manifest.json header not found") 416 | } 417 | 418 | if _, ok := manifest["header"].(map[string]any); !ok { 419 | return errors.New("manifest.json header is not a map[string]any") 420 | } 421 | 422 | manifest["header"].(map[string]any)["uuid"] = newPackUuid 423 | 424 | modules, ok := manifest["modules"] 425 | if ok { 426 | modules2, ok := modules.([]any) 427 | if !ok { 428 | return errors.New("manifest.json modules is not a []any") 429 | } 430 | for _, module := range modules2 { 431 | if _, ok := module.(map[string]any); !ok { 432 | return errors.New("manifest.json module is not a map[string]any") 433 | } 434 | module.(map[string]any)["uuid"] = uuidFromSeed(seed, mod) 435 | mod++ 436 | } 437 | } 438 | 439 | manifestBytes2, err := json.Marshal(manifest) 440 | if err != nil { 441 | return err 442 | } 443 | 444 | r.uuid = newPackUuid 445 | r.files["manifest.json"] = manifestBytes2 446 | return nil 447 | } 448 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------