Skip to content

Commit

Permalink
Handle edge cases for FText
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Mar 24, 2021
1 parent ca11ee8 commit afe5aca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/Vilsol/ue4pak
go 1.14

require (
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.10.0
github.com/gobwas/glob v0.2.3
github.com/sirupsen/logrus v1.7.0
Expand Down
17 changes: 17 additions & 0 deletions parser/parser_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ func (parser *PakParser) ReadFText() *FText {
HistoryType: historyType,
}

if flags == 2 && historyType == -1 {
// TODO Unknown
if parser.ReadInt32() == 0 {
return &text
}

text.SourceString = parser.ReadString()
return &text
}

if flags == 0 && historyType == 11 {
// TODO Unknown
parser.Read(8)
text.SourceString = parser.ReadString()
return &text
}

if historyType != 0 {
return &text
}
Expand Down
1 change: 1 addition & 0 deletions parser/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var structResolvers = map[string]StructResolver{
"MovieSceneFloatChannel": nil,
"LevelSequenceBindingReferenceArray": nil,
"MovieSceneTrackFieldData": nil,
"NiagaraDataInterfaceGPUParamInfo": nil,
}

type StructType struct {
Expand Down
22 changes: 11 additions & 11 deletions utils/bytewise.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"github.com/fatih/color"
"math"
"strconv"
"strings"
"unicode/utf16"
)

Expand Down Expand Up @@ -48,11 +48,6 @@ func HexDumpWidth(data []byte, perRow int) string {

rows := int(math.Ceil(float64(len(data)) / float64(perRow)))

rowWidth := perRow * 5
if len(data) < perRow {
rowWidth = len(data) * 5
}

lengthChars := 0
stringChars := uint32(0)

Expand All @@ -70,23 +65,28 @@ func HexDumpWidth(data []byte, perRow int) string {
}

hexTemp := fmt.Sprintf("%#-4x", data[offset]) + " "
charTemp := fmt.Sprintf("%s", safeChar(data[offset]))
charTemp := safeChar(data[offset])

if lengthChars > 0 {
switch {
case lengthChars > 0:
hexSide += color.BlueString(hexTemp)
charSide += color.BlueString(charTemp)
lengthChars--
} else if stringChars > 0 {
case stringChars > 0:
hexSide += color.GreenString(hexTemp)
charSide += color.GreenString(charTemp)
stringChars--
} else {
default:
hexSide += hexTemp
charSide += charTemp
}
}

result += fmt.Sprintf("%-#6x: %-"+strconv.Itoa(rowWidth)+"s%s\n", i*perRow, hexSide, charSide)
result += fmt.Sprintf("%-#6x: %s", i*perRow, hexSide)
if len(data[i*perRow:]) < perRow && len(data) > perRow {
result += strings.Repeat(" ", (perRow-len(data[i*perRow:]))*5)
}
result += fmt.Sprintf("%s\n", charSide)
}

return result
Expand Down

0 comments on commit afe5aca

Please sign in to comment.