mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 07:25:03 +01:00
golang formatting pass
This commit is contained in:
@@ -10,12 +10,12 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
var m_shiftIndex int = 0
|
var mShiftIndex = 0
|
||||||
var m_flag byte = byte(0)
|
var mFlag = byte(0)
|
||||||
|
|
||||||
func UnpackSimple(data []byte) []byte {
|
func UnpackSimple(data []byte) []byte {
|
||||||
m_shiftIndex = 0
|
mShiftIndex = 0
|
||||||
m_flag = byte(0)
|
mFlag = byte(0)
|
||||||
|
|
||||||
bf := byteframe.NewByteFrameFromBytes(data)
|
bf := byteframe.NewByteFrameFromBytes(data)
|
||||||
bf.SetLE()
|
bf.SetLE()
|
||||||
@@ -44,28 +44,28 @@ func ProcessDecode(data *byteframe.ByteFrame, outBuffer []byte) {
|
|||||||
outIndex := 0
|
outIndex := 0
|
||||||
|
|
||||||
for int(data.Index()) < len(data.Data()) && outIndex < len(outBuffer)-1 {
|
for int(data.Index()) < len(data.Data()) && outIndex < len(outBuffer)-1 {
|
||||||
if JPKBitshift(data) == 0 {
|
if JPKBitShift(data) == 0 {
|
||||||
outBuffer[outIndex] = ReadByte(data)
|
outBuffer[outIndex] = ReadByte(data)
|
||||||
outIndex++
|
outIndex++
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
if JPKBitshift(data) == 0 {
|
if JPKBitShift(data) == 0 {
|
||||||
len := (JPKBitshift(data) << 1) | JPKBitshift(data)
|
length := (JPKBitShift(data) << 1) | JPKBitShift(data)
|
||||||
off := ReadByte(data)
|
off := ReadByte(data)
|
||||||
JPKCopy(outBuffer, int(off), int(len)+3, &outIndex)
|
JPKCopy(outBuffer, int(off), int(length)+3, &outIndex)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
hi := ReadByte(data)
|
hi := ReadByte(data)
|
||||||
lo := ReadByte(data)
|
lo := ReadByte(data)
|
||||||
var len int = int((hi & 0xE0)) >> 5
|
length := int(hi&0xE0) >> 5
|
||||||
var off int = ((int(hi) & 0x1F) << 8) | int(lo)
|
off := ((int(hi) & 0x1F) << 8) | int(lo)
|
||||||
if len != 0 {
|
if length != 0 {
|
||||||
JPKCopy(outBuffer, off, len+2, &outIndex)
|
JPKCopy(outBuffer, off, length+2, &outIndex)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
if JPKBitshift(data) == 0 {
|
if JPKBitShift(data) == 0 {
|
||||||
len := (JPKBitshift(data) << 3) | (JPKBitshift(data) << 2) | (JPKBitshift(data) << 1) | JPKBitshift(data)
|
length := (JPKBitShift(data) << 3) | (JPKBitShift(data) << 2) | (JPKBitShift(data) << 1) | JPKBitShift(data)
|
||||||
JPKCopy(outBuffer, off, int(len)+2+8, &outIndex)
|
JPKCopy(outBuffer, off, int(length)+2+8, &outIndex)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
temp := ReadByte(data)
|
temp := ReadByte(data)
|
||||||
@@ -85,15 +85,15 @@ func ProcessDecode(data *byteframe.ByteFrame, outBuffer []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func JPKBitshift(data *byteframe.ByteFrame) byte {
|
func JPKBitShift(data *byteframe.ByteFrame) byte {
|
||||||
m_shiftIndex--
|
mShiftIndex--
|
||||||
|
|
||||||
if m_shiftIndex < 0 {
|
if mShiftIndex < 0 {
|
||||||
m_shiftIndex = 7
|
mShiftIndex = 7
|
||||||
m_flag = ReadByte(data)
|
mFlag = ReadByte(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (byte)((m_flag >> m_shiftIndex) & 1)
|
return (byte)((mFlag >> mShiftIndex) & 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func JPKCopy(outBuffer []byte, offset int, length int, index *int) {
|
func JPKCopy(outBuffer []byte, offset int, length int, index *int) {
|
||||||
@@ -105,5 +105,5 @@ func JPKCopy(outBuffer []byte, offset int, length int, index *int) {
|
|||||||
|
|
||||||
func ReadByte(bf *byteframe.ByteFrame) byte {
|
func ReadByte(bf *byteframe.ByteFrame) byte {
|
||||||
value := bf.ReadUint8()
|
value := bf.ReadUint8()
|
||||||
return byte(value)
|
return value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,69 +83,69 @@ func handleMsgMhfSaveFavoriteQuest(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readOriginalPointers(string_pointer int32, quest []byte) []byte {
|
func readOriginalPointers(string_pointer int32, quest []byte) []byte {
|
||||||
file_bytes := byteframe.NewByteFrameFromBytes(quest)
|
fileBytes := byteframe.NewByteFrameFromBytes(quest)
|
||||||
file_bytes.SetLE()
|
fileBytes.SetLE()
|
||||||
file_bytes.Seek(int64(string_pointer), io.SeekStart)
|
fileBytes.Seek(int64(string_pointer), io.SeekStart)
|
||||||
|
|
||||||
quest_name_pointer := file_bytes.ReadInt32()
|
questNamePointer := fileBytes.ReadInt32()
|
||||||
quest_main_pointer := file_bytes.ReadInt32()
|
questMainPointer := fileBytes.ReadInt32()
|
||||||
quest_a_pointer := file_bytes.ReadInt32()
|
questAPointer := fileBytes.ReadInt32()
|
||||||
quest_b_pointer := file_bytes.ReadInt32()
|
questBPointer := fileBytes.ReadInt32()
|
||||||
quest_clear_pointer := file_bytes.ReadInt32()
|
questClearPointer := fileBytes.ReadInt32()
|
||||||
quest_failure_pointer := file_bytes.ReadInt32()
|
questFailurePointer := fileBytes.ReadInt32()
|
||||||
quest_contractor_pointer := file_bytes.ReadInt32()
|
questContractorPointer := fileBytes.ReadInt32()
|
||||||
quest_description_pointer := file_bytes.ReadInt32()
|
questDescriptionPointer := fileBytes.ReadInt32()
|
||||||
|
|
||||||
// Read the strings in order to determine the length of the new string pointers for use in the new offsets
|
// Read the strings in order to determine the length of the new string pointers for use in the new offsets
|
||||||
// It must seek to each initial pointer since the order is not consistent.
|
// It must seek to each initial pointer since the order is not consistent.
|
||||||
file_bytes.Seek(int64(quest_name_pointer), io.SeekStart)
|
fileBytes.Seek(int64(questNamePointer), io.SeekStart)
|
||||||
quest_name_string := file_bytes.ReadNullTerminatedBytes()
|
questNameString := fileBytes.ReadNullTerminatedBytes()
|
||||||
file_bytes.Seek(int64(quest_main_pointer), io.SeekStart)
|
fileBytes.Seek(int64(questMainPointer), io.SeekStart)
|
||||||
quest_main_string := file_bytes.ReadNullTerminatedBytes()
|
questMainString := fileBytes.ReadNullTerminatedBytes()
|
||||||
file_bytes.Seek(int64(quest_a_pointer), io.SeekStart)
|
fileBytes.Seek(int64(questAPointer), io.SeekStart)
|
||||||
quest_a_string := file_bytes.ReadNullTerminatedBytes()
|
questAString := fileBytes.ReadNullTerminatedBytes()
|
||||||
file_bytes.Seek(int64(quest_b_pointer), io.SeekStart)
|
fileBytes.Seek(int64(questBPointer), io.SeekStart)
|
||||||
quest_b_string := file_bytes.ReadNullTerminatedBytes()
|
questBString := fileBytes.ReadNullTerminatedBytes()
|
||||||
file_bytes.Seek(int64(quest_clear_pointer), io.SeekStart)
|
fileBytes.Seek(int64(questClearPointer), io.SeekStart)
|
||||||
quest_clear_string := file_bytes.ReadNullTerminatedBytes()
|
questClearString := fileBytes.ReadNullTerminatedBytes()
|
||||||
file_bytes.Seek(int64(quest_failure_pointer), io.SeekStart)
|
fileBytes.Seek(int64(questFailurePointer), io.SeekStart)
|
||||||
quest_failure_string := file_bytes.ReadNullTerminatedBytes()
|
questFailureString := fileBytes.ReadNullTerminatedBytes()
|
||||||
file_bytes.Seek(int64(quest_contractor_pointer), io.SeekStart)
|
fileBytes.Seek(int64(questContractorPointer), io.SeekStart)
|
||||||
quest_contractor_string := file_bytes.ReadNullTerminatedBytes()
|
questContractorString := fileBytes.ReadNullTerminatedBytes()
|
||||||
file_bytes.Seek(int64(quest_description_pointer), io.SeekStart)
|
fileBytes.Seek(int64(questDescriptionPointer), io.SeekStart)
|
||||||
quest_description_string := file_bytes.ReadNullTerminatedBytes()
|
questDescriptionString := fileBytes.ReadNullTerminatedBytes()
|
||||||
|
|
||||||
pointer_start := 352
|
pointerStart := 352
|
||||||
|
|
||||||
new_pointers := byteframe.NewByteFrame()
|
newPointers := byteframe.NewByteFrame()
|
||||||
new_pointers.SetLE()
|
newPointers.SetLE()
|
||||||
|
|
||||||
new_pointers.WriteInt32(int32(pointer_start))
|
newPointers.WriteInt32(int32(pointerStart))
|
||||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + 1))
|
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + 1))
|
||||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + 2))
|
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + 2))
|
||||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + len(quest_a_string) + 3))
|
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + 3))
|
||||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + len(quest_a_string) + len(quest_b_string) + 26))
|
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + len(questBString) + 26))
|
||||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + len(quest_a_string) + len(quest_b_string) + len(quest_clear_string) + 5))
|
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + len(questBString) + len(questClearString) + 5))
|
||||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + len(quest_a_string) + len(quest_b_string) + len(quest_clear_string) + len(quest_failure_string) + 6))
|
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + len(questBString) + len(questClearString) + len(questFailureString) + 6))
|
||||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + len(quest_a_string) + len(quest_b_string) + len(quest_clear_string) + len(quest_failure_string) + len(quest_contractor_string) + 7))
|
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + len(questBString) + len(questClearString) + len(questFailureString) + len(questContractorString) + 7))
|
||||||
|
|
||||||
new_pointers.WriteNullTerminatedBytes(quest_name_string)
|
newPointers.WriteNullTerminatedBytes(questNameString)
|
||||||
new_pointers.WriteNullTerminatedBytes(quest_main_string)
|
newPointers.WriteNullTerminatedBytes(questMainString)
|
||||||
new_pointers.WriteNullTerminatedBytes(quest_a_string)
|
newPointers.WriteNullTerminatedBytes(questAString)
|
||||||
new_pointers.WriteNullTerminatedBytes(quest_b_string)
|
newPointers.WriteNullTerminatedBytes(questBString)
|
||||||
new_pointers.WriteNullTerminatedBytes(quest_clear_string)
|
newPointers.WriteNullTerminatedBytes(questClearString)
|
||||||
new_pointers.WriteNullTerminatedBytes(quest_failure_string)
|
newPointers.WriteNullTerminatedBytes(questFailureString)
|
||||||
new_pointers.WriteNullTerminatedBytes(quest_contractor_string)
|
newPointers.WriteNullTerminatedBytes(questContractorString)
|
||||||
new_pointers.WriteNullTerminatedBytes(quest_description_string)
|
newPointers.WriteNullTerminatedBytes(questDescriptionString)
|
||||||
|
|
||||||
new_pointers.WriteUint8(18)
|
newPointers.WriteUint8(18)
|
||||||
new_pointers.WriteBytes([]byte{0x83, 0x59, 0x89, 0x5B, 0x83, 0x3A, 0x58, 0xB6, 0x8E, 0x59, 0x82, 0xCC, 0x83, 0x58, 0x83, 0x58, 0x83, 0x81})
|
newPointers.WriteBytes([]byte{0x83, 0x59, 0x89, 0x5B, 0x83, 0x3A, 0x58, 0xB6, 0x8E, 0x59, 0x82, 0xCC, 0x83, 0x58, 0x83, 0x58, 0x83, 0x81})
|
||||||
|
|
||||||
return new_pointers.Data()
|
return newPointers.Data()
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadQuestFile(s *Session, quest_id string) []byte {
|
func loadQuestFile(s *Session, questId string) []byte {
|
||||||
file, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", quest_id)))
|
file, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", questId)))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -153,22 +153,22 @@ func loadQuestFile(s *Session, quest_id string) []byte {
|
|||||||
|
|
||||||
decrypted := decryption.UnpackSimple(file)
|
decrypted := decryption.UnpackSimple(file)
|
||||||
|
|
||||||
file_bytes := byteframe.NewByteFrameFromBytes(decrypted)
|
fileBytes := byteframe.NewByteFrameFromBytes(decrypted)
|
||||||
file_bytes.SetLE()
|
fileBytes.SetLE()
|
||||||
file_bytes.Seek(0, io.SeekStart)
|
fileBytes.Seek(0, io.SeekStart)
|
||||||
|
|
||||||
data_pointer := file_bytes.ReadInt32()
|
dataPointer := fileBytes.ReadInt32()
|
||||||
file_bytes.Seek(int64(data_pointer), io.SeekStart)
|
fileBytes.Seek(int64(dataPointer), io.SeekStart)
|
||||||
|
|
||||||
// The 320 bytes directly following the data pointer must go directly into the event's body, after the header and before the string pointers.
|
// The 320 bytes directly following the data pointer must go directly into the event's body, after the header and before the string pointers.
|
||||||
quest_body := byteframe.NewByteFrameFromBytes(file_bytes.ReadBytes(320))
|
questBody := byteframe.NewByteFrameFromBytes(fileBytes.ReadBytes(320))
|
||||||
quest_body.SetLE()
|
questBody.SetLE()
|
||||||
quest_body.Seek(40, io.SeekStart)
|
questBody.Seek(40, io.SeekStart)
|
||||||
|
|
||||||
strings := readOriginalPointers(quest_body.ReadInt32(), decrypted)
|
strings := readOriginalPointers(questBody.ReadInt32(), decrypted)
|
||||||
|
|
||||||
body := byteframe.NewByteFrame()
|
body := byteframe.NewByteFrame()
|
||||||
body.WriteBytes(quest_body.Data())
|
body.WriteBytes(questBody.Data())
|
||||||
body.Seek(0, io.SeekEnd)
|
body.Seek(0, io.SeekEnd)
|
||||||
body.WriteBytes(strings)
|
body.WriteBytes(strings)
|
||||||
|
|
||||||
@@ -177,8 +177,8 @@ func loadQuestFile(s *Session, quest_id string) []byte {
|
|||||||
|
|
||||||
func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) {
|
func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) {
|
||||||
var id int32
|
var id int32
|
||||||
var max_players, quest_type, quest_id uint16
|
var maxPlayers, questType, questId uint16
|
||||||
rows.Scan(&id, &max_players, &quest_type, &quest_id)
|
rows.Scan(&id, &maxPlayers, &questType, &questId)
|
||||||
|
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
bf.SetLE()
|
bf.SetLE()
|
||||||
@@ -186,14 +186,14 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) {
|
|||||||
// Reconstructing the event-header itself. A lot of the data is not actually necessary for the quest to operate normally.
|
// Reconstructing the event-header itself. A lot of the data is not actually necessary for the quest to operate normally.
|
||||||
bf.WriteInt32(id)
|
bf.WriteInt32(id)
|
||||||
bf.WriteInt32(0)
|
bf.WriteInt32(0)
|
||||||
bf.WriteBytes([]byte{0x0F, byte(max_players), byte(quest_type), 0x01})
|
bf.WriteBytes([]byte{0x0F, byte(maxPlayers), byte(questType), 0x01})
|
||||||
bf.WriteUint16(0)
|
bf.WriteUint16(0)
|
||||||
bf.WriteUint16(0)
|
bf.WriteUint16(0)
|
||||||
bf.WriteBytes([]byte{0x00, 0x01})
|
bf.WriteBytes([]byte{0x00, 0x01})
|
||||||
bf.WriteUint16(0)
|
bf.WriteUint16(0)
|
||||||
bf.WriteBytes([]byte{0x02, 0x00})
|
bf.WriteBytes([]byte{0x02, 0x00})
|
||||||
|
|
||||||
data := loadQuestFile(s, fmt.Sprintf("%d", quest_id)+"d0")
|
data := loadQuestFile(s, fmt.Sprintf("%d", questId)+"d0")
|
||||||
|
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return nil, fmt.Errorf("failed to load quest file")
|
return nil, fmt.Errorf("failed to load quest file")
|
||||||
@@ -218,13 +218,13 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
bf.WriteUint16(0)
|
bf.WriteUint16(0)
|
||||||
|
|
||||||
rows, _ := s.server.db.Query("SELECT id, max_players, quest_type, quest_id FROM event_quests ORDER BY quest_id ASC")
|
rows, _ := s.server.db.Query("SELECT id, max_players, quest_type, quest_id FROM event_quests ORDER BY quest_id")
|
||||||
|
|
||||||
// Loop through each row and load the quest entry if it exists.
|
// Loop through each row and load the quest entry if it exists.
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var pointer []byte
|
var pointer []byte
|
||||||
var max_players, quest_type, checksum, quest_id uint16
|
var maxPlayers, questType, checksum, questId uint16
|
||||||
rows.Scan(&pointer, &max_players, &quest_type, &checksum, &quest_id)
|
rows.Scan(&pointer, &maxPlayers, &questType, &checksum, &questId)
|
||||||
|
|
||||||
data, err := makeEventQuest(s, rows)
|
data, err := makeEventQuest(s, rows)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user