Fix deflate issue and make it default
This commit is contained in:
parent
e9123b8b25
commit
bfe9d6817f
2 changed files with 20 additions and 11 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
|
@ -68,7 +69,7 @@ func LoadResource(reader io.ReadSeeker, rresID int, key []byte) (data rres.Data)
|
|||
reader.Read(b)
|
||||
|
||||
// Uncompress data
|
||||
data.Data, err = uncompress(b, int(infoHeader.CompType), int(infoHeader.UncompSize))
|
||||
data.Data, err = uncompress(b, int(infoHeader.CompType))
|
||||
if err != nil {
|
||||
TraceLog(LogWarning, "[ID %d] %v", infoHeader.ID, err)
|
||||
}
|
||||
|
@ -136,15 +137,17 @@ func decrypt(key, data []byte, cryptoType int) ([]byte, error) {
|
|||
}
|
||||
|
||||
// uncompress data
|
||||
func uncompress(data []byte, compType, uncompSize int) ([]byte, error) {
|
||||
func uncompress(data []byte, compType int) ([]byte, error) {
|
||||
switch compType {
|
||||
case rres.CompNone:
|
||||
return data, nil
|
||||
case rres.CompDeflate:
|
||||
r := flate.NewReader(bytes.NewReader(data))
|
||||
|
||||
u := make([]byte, uncompSize)
|
||||
r.Read(u)
|
||||
u, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.Close()
|
||||
|
||||
|
@ -152,8 +155,10 @@ func uncompress(data []byte, compType, uncompSize int) ([]byte, error) {
|
|||
case rres.CompLZ4:
|
||||
r := lz4.NewReader(bytes.NewReader(data))
|
||||
|
||||
u := make([]byte, uncompSize)
|
||||
r.Read(u)
|
||||
u, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return u, nil
|
||||
case rres.CompLZMA2:
|
||||
|
@ -162,8 +167,10 @@ func uncompress(data []byte, compType, uncompSize int) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
u := make([]byte, uncompSize)
|
||||
r.Read(u)
|
||||
u, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return u, nil
|
||||
case rres.CompBZIP2:
|
||||
|
@ -172,8 +179,10 @@ func uncompress(data []byte, compType, uncompSize int) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
u := make([]byte, uncompSize)
|
||||
r.Read(u)
|
||||
u, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return u, nil
|
||||
default:
|
||||
|
|
|
@ -49,7 +49,7 @@ func init() {
|
|||
|
||||
func main() {
|
||||
base := flag.String("base", "data", "Resources file basename")
|
||||
comp := flag.Int("comp", rres.CompLZMA2, "Compression type, 0=NONE, 1=DEFLATE, 2=LZ4, 5=LZMA2 (XZ), 6=BZIP2")
|
||||
comp := flag.Int("comp", rres.CompDeflate, "Compression type, 0=NONE, 1=DEFLATE, 2=LZ4, 5=LZMA2 (XZ), 6=BZIP2")
|
||||
enc := flag.Int("enc", rres.CryptoNone, "Encryption type, 0=NONE, 1=XOR, 2=AES, 3=3DES, 4=Blowfish, 5=XTEA")
|
||||
key := flag.String("key", "", "Encryption key")
|
||||
header := flag.Bool("header", false, "Generate C header (.h file)")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue