mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 17:43:21 +01:00
parse bin chat as UTF8
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
package binpacket
|
package binpacket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"erupe-ce/network"
|
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
|
"erupe-ce/common/stringsupport"
|
||||||
|
"erupe-ce/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ChatType represents the chat message type (Thanks to @Alice on discord for identifying these!)
|
// ChatType represents the chat message type (Thanks to @Alice on discord for identifying these!)
|
||||||
@@ -36,13 +37,10 @@ func (m *MsgBinChat) Parse(bf *byteframe.ByteFrame) error {
|
|||||||
m.Unk0 = bf.ReadUint8()
|
m.Unk0 = bf.ReadUint8()
|
||||||
m.Type = ChatType(bf.ReadUint8())
|
m.Type = ChatType(bf.ReadUint8())
|
||||||
m.Flags = bf.ReadUint16()
|
m.Flags = bf.ReadUint16()
|
||||||
senderNameSize := bf.ReadUint16()
|
_ = bf.ReadUint16() // lenSenderName
|
||||||
messageSize := bf.ReadUint16()
|
_ = bf.ReadUint16() // lenMessage
|
||||||
|
m.Message = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||||
// TODO(Andoryuuta): Need proper shift-jis and null termination.
|
m.SenderName = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||||
m.Message = string(bf.ReadBytes(uint(messageSize))[:messageSize-1])
|
|
||||||
m.SenderName = string(bf.ReadBytes(uint(senderNameSize))[:senderNameSize-1])
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,10 +49,11 @@ func (m *MsgBinChat) Build(bf *byteframe.ByteFrame) error {
|
|||||||
bf.WriteUint8(m.Unk0)
|
bf.WriteUint8(m.Unk0)
|
||||||
bf.WriteUint8(uint8(m.Type))
|
bf.WriteUint8(uint8(m.Type))
|
||||||
bf.WriteUint16(m.Flags)
|
bf.WriteUint16(m.Flags)
|
||||||
bf.WriteUint16(uint16(len(m.SenderName) + 1))
|
cMessage := stringsupport.UTF8ToSJIS(m.Message)
|
||||||
bf.WriteUint16(uint16(len(m.Message) + 1))
|
cSenderName := stringsupport.UTF8ToSJIS(m.SenderName)
|
||||||
bf.WriteNullTerminatedBytes([]byte(m.Message))
|
bf.WriteUint16(uint16(len(cSenderName) + 1))
|
||||||
bf.WriteNullTerminatedBytes([]byte(m.SenderName))
|
bf.WriteUint16(uint16(len(cMessage) + 1))
|
||||||
|
bf.WriteNullTerminatedBytes(cMessage)
|
||||||
|
bf.WriteNullTerminatedBytes(cSenderName)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user