mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-12 15:04:38 +01:00
golang formatting pass
This commit is contained in:
@@ -10,12 +10,12 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
var m_shiftIndex int = 0
|
||||
var m_flag byte = byte(0)
|
||||
var mShiftIndex = 0
|
||||
var mFlag = byte(0)
|
||||
|
||||
func UnpackSimple(data []byte) []byte {
|
||||
m_shiftIndex = 0
|
||||
m_flag = byte(0)
|
||||
mShiftIndex = 0
|
||||
mFlag = byte(0)
|
||||
|
||||
bf := byteframe.NewByteFrameFromBytes(data)
|
||||
bf.SetLE()
|
||||
@@ -44,28 +44,28 @@ func ProcessDecode(data *byteframe.ByteFrame, outBuffer []byte) {
|
||||
outIndex := 0
|
||||
|
||||
for int(data.Index()) < len(data.Data()) && outIndex < len(outBuffer)-1 {
|
||||
if JPKBitshift(data) == 0 {
|
||||
if JPKBitShift(data) == 0 {
|
||||
outBuffer[outIndex] = ReadByte(data)
|
||||
outIndex++
|
||||
continue
|
||||
} else {
|
||||
if JPKBitshift(data) == 0 {
|
||||
len := (JPKBitshift(data) << 1) | JPKBitshift(data)
|
||||
if JPKBitShift(data) == 0 {
|
||||
length := (JPKBitShift(data) << 1) | JPKBitShift(data)
|
||||
off := ReadByte(data)
|
||||
JPKCopy(outBuffer, int(off), int(len)+3, &outIndex)
|
||||
JPKCopy(outBuffer, int(off), int(length)+3, &outIndex)
|
||||
continue
|
||||
} else {
|
||||
hi := ReadByte(data)
|
||||
lo := ReadByte(data)
|
||||
var len int = int((hi & 0xE0)) >> 5
|
||||
var off int = ((int(hi) & 0x1F) << 8) | int(lo)
|
||||
if len != 0 {
|
||||
JPKCopy(outBuffer, off, len+2, &outIndex)
|
||||
length := int(hi&0xE0) >> 5
|
||||
off := ((int(hi) & 0x1F) << 8) | int(lo)
|
||||
if length != 0 {
|
||||
JPKCopy(outBuffer, off, length+2, &outIndex)
|
||||
continue
|
||||
} else {
|
||||
if JPKBitshift(data) == 0 {
|
||||
len := (JPKBitshift(data) << 3) | (JPKBitshift(data) << 2) | (JPKBitshift(data) << 1) | JPKBitshift(data)
|
||||
JPKCopy(outBuffer, off, int(len)+2+8, &outIndex)
|
||||
if JPKBitShift(data) == 0 {
|
||||
length := (JPKBitShift(data) << 3) | (JPKBitShift(data) << 2) | (JPKBitShift(data) << 1) | JPKBitShift(data)
|
||||
JPKCopy(outBuffer, off, int(length)+2+8, &outIndex)
|
||||
continue
|
||||
} else {
|
||||
temp := ReadByte(data)
|
||||
@@ -85,15 +85,15 @@ func ProcessDecode(data *byteframe.ByteFrame, outBuffer []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func JPKBitshift(data *byteframe.ByteFrame) byte {
|
||||
m_shiftIndex--
|
||||
func JPKBitShift(data *byteframe.ByteFrame) byte {
|
||||
mShiftIndex--
|
||||
|
||||
if m_shiftIndex < 0 {
|
||||
m_shiftIndex = 7
|
||||
m_flag = ReadByte(data)
|
||||
if mShiftIndex < 0 {
|
||||
mShiftIndex = 7
|
||||
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) {
|
||||
@@ -105,5 +105,5 @@ func JPKCopy(outBuffer []byte, offset int, length int, index *int) {
|
||||
|
||||
func ReadByte(bf *byteframe.ByteFrame) byte {
|
||||
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 {
|
||||
file_bytes := byteframe.NewByteFrameFromBytes(quest)
|
||||
file_bytes.SetLE()
|
||||
file_bytes.Seek(int64(string_pointer), io.SeekStart)
|
||||
fileBytes := byteframe.NewByteFrameFromBytes(quest)
|
||||
fileBytes.SetLE()
|
||||
fileBytes.Seek(int64(string_pointer), io.SeekStart)
|
||||
|
||||
quest_name_pointer := file_bytes.ReadInt32()
|
||||
quest_main_pointer := file_bytes.ReadInt32()
|
||||
quest_a_pointer := file_bytes.ReadInt32()
|
||||
quest_b_pointer := file_bytes.ReadInt32()
|
||||
quest_clear_pointer := file_bytes.ReadInt32()
|
||||
quest_failure_pointer := file_bytes.ReadInt32()
|
||||
quest_contractor_pointer := file_bytes.ReadInt32()
|
||||
quest_description_pointer := file_bytes.ReadInt32()
|
||||
questNamePointer := fileBytes.ReadInt32()
|
||||
questMainPointer := fileBytes.ReadInt32()
|
||||
questAPointer := fileBytes.ReadInt32()
|
||||
questBPointer := fileBytes.ReadInt32()
|
||||
questClearPointer := fileBytes.ReadInt32()
|
||||
questFailurePointer := fileBytes.ReadInt32()
|
||||
questContractorPointer := fileBytes.ReadInt32()
|
||||
questDescriptionPointer := fileBytes.ReadInt32()
|
||||
|
||||
// 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.
|
||||
file_bytes.Seek(int64(quest_name_pointer), io.SeekStart)
|
||||
quest_name_string := file_bytes.ReadNullTerminatedBytes()
|
||||
file_bytes.Seek(int64(quest_main_pointer), io.SeekStart)
|
||||
quest_main_string := file_bytes.ReadNullTerminatedBytes()
|
||||
file_bytes.Seek(int64(quest_a_pointer), io.SeekStart)
|
||||
quest_a_string := file_bytes.ReadNullTerminatedBytes()
|
||||
file_bytes.Seek(int64(quest_b_pointer), io.SeekStart)
|
||||
quest_b_string := file_bytes.ReadNullTerminatedBytes()
|
||||
file_bytes.Seek(int64(quest_clear_pointer), io.SeekStart)
|
||||
quest_clear_string := file_bytes.ReadNullTerminatedBytes()
|
||||
file_bytes.Seek(int64(quest_failure_pointer), io.SeekStart)
|
||||
quest_failure_string := file_bytes.ReadNullTerminatedBytes()
|
||||
file_bytes.Seek(int64(quest_contractor_pointer), io.SeekStart)
|
||||
quest_contractor_string := file_bytes.ReadNullTerminatedBytes()
|
||||
file_bytes.Seek(int64(quest_description_pointer), io.SeekStart)
|
||||
quest_description_string := file_bytes.ReadNullTerminatedBytes()
|
||||
fileBytes.Seek(int64(questNamePointer), io.SeekStart)
|
||||
questNameString := fileBytes.ReadNullTerminatedBytes()
|
||||
fileBytes.Seek(int64(questMainPointer), io.SeekStart)
|
||||
questMainString := fileBytes.ReadNullTerminatedBytes()
|
||||
fileBytes.Seek(int64(questAPointer), io.SeekStart)
|
||||
questAString := fileBytes.ReadNullTerminatedBytes()
|
||||
fileBytes.Seek(int64(questBPointer), io.SeekStart)
|
||||
questBString := fileBytes.ReadNullTerminatedBytes()
|
||||
fileBytes.Seek(int64(questClearPointer), io.SeekStart)
|
||||
questClearString := fileBytes.ReadNullTerminatedBytes()
|
||||
fileBytes.Seek(int64(questFailurePointer), io.SeekStart)
|
||||
questFailureString := fileBytes.ReadNullTerminatedBytes()
|
||||
fileBytes.Seek(int64(questContractorPointer), io.SeekStart)
|
||||
questContractorString := fileBytes.ReadNullTerminatedBytes()
|
||||
fileBytes.Seek(int64(questDescriptionPointer), io.SeekStart)
|
||||
questDescriptionString := fileBytes.ReadNullTerminatedBytes()
|
||||
|
||||
pointer_start := 352
|
||||
pointerStart := 352
|
||||
|
||||
new_pointers := byteframe.NewByteFrame()
|
||||
new_pointers.SetLE()
|
||||
newPointers := byteframe.NewByteFrame()
|
||||
newPointers.SetLE()
|
||||
|
||||
new_pointers.WriteInt32(int32(pointer_start))
|
||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + 1))
|
||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + 2))
|
||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + len(quest_a_string) + 3))
|
||||
new_pointers.WriteInt32(int32(pointer_start + len(quest_name_string) + len(quest_main_string) + len(quest_a_string) + len(quest_b_string) + 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))
|
||||
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))
|
||||
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))
|
||||
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + 1))
|
||||
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + 2))
|
||||
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + 3))
|
||||
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + len(questBString) + 26))
|
||||
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + len(questBString) + len(questClearString) + 5))
|
||||
newPointers.WriteInt32(int32(pointerStart + len(questNameString) + len(questMainString) + len(questAString) + len(questBString) + len(questClearString) + len(questFailureString) + 6))
|
||||
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)
|
||||
new_pointers.WriteNullTerminatedBytes(quest_main_string)
|
||||
new_pointers.WriteNullTerminatedBytes(quest_a_string)
|
||||
new_pointers.WriteNullTerminatedBytes(quest_b_string)
|
||||
new_pointers.WriteNullTerminatedBytes(quest_clear_string)
|
||||
new_pointers.WriteNullTerminatedBytes(quest_failure_string)
|
||||
new_pointers.WriteNullTerminatedBytes(quest_contractor_string)
|
||||
new_pointers.WriteNullTerminatedBytes(quest_description_string)
|
||||
newPointers.WriteNullTerminatedBytes(questNameString)
|
||||
newPointers.WriteNullTerminatedBytes(questMainString)
|
||||
newPointers.WriteNullTerminatedBytes(questAString)
|
||||
newPointers.WriteNullTerminatedBytes(questBString)
|
||||
newPointers.WriteNullTerminatedBytes(questClearString)
|
||||
newPointers.WriteNullTerminatedBytes(questFailureString)
|
||||
newPointers.WriteNullTerminatedBytes(questContractorString)
|
||||
newPointers.WriteNullTerminatedBytes(questDescriptionString)
|
||||
|
||||
new_pointers.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.WriteUint8(18)
|
||||
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 {
|
||||
file, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", quest_id)))
|
||||
func loadQuestFile(s *Session, questId string) []byte {
|
||||
file, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", questId)))
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -153,22 +153,22 @@ func loadQuestFile(s *Session, quest_id string) []byte {
|
||||
|
||||
decrypted := decryption.UnpackSimple(file)
|
||||
|
||||
file_bytes := byteframe.NewByteFrameFromBytes(decrypted)
|
||||
file_bytes.SetLE()
|
||||
file_bytes.Seek(0, io.SeekStart)
|
||||
fileBytes := byteframe.NewByteFrameFromBytes(decrypted)
|
||||
fileBytes.SetLE()
|
||||
fileBytes.Seek(0, io.SeekStart)
|
||||
|
||||
data_pointer := file_bytes.ReadInt32()
|
||||
file_bytes.Seek(int64(data_pointer), io.SeekStart)
|
||||
dataPointer := fileBytes.ReadInt32()
|
||||
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.
|
||||
quest_body := byteframe.NewByteFrameFromBytes(file_bytes.ReadBytes(320))
|
||||
quest_body.SetLE()
|
||||
quest_body.Seek(40, io.SeekStart)
|
||||
questBody := byteframe.NewByteFrameFromBytes(fileBytes.ReadBytes(320))
|
||||
questBody.SetLE()
|
||||
questBody.Seek(40, io.SeekStart)
|
||||
|
||||
strings := readOriginalPointers(quest_body.ReadInt32(), decrypted)
|
||||
strings := readOriginalPointers(questBody.ReadInt32(), decrypted)
|
||||
|
||||
body := byteframe.NewByteFrame()
|
||||
body.WriteBytes(quest_body.Data())
|
||||
body.WriteBytes(questBody.Data())
|
||||
body.Seek(0, io.SeekEnd)
|
||||
body.WriteBytes(strings)
|
||||
|
||||
@@ -177,8 +177,8 @@ func loadQuestFile(s *Session, quest_id string) []byte {
|
||||
|
||||
func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) {
|
||||
var id int32
|
||||
var max_players, quest_type, quest_id uint16
|
||||
rows.Scan(&id, &max_players, &quest_type, &quest_id)
|
||||
var maxPlayers, questType, questId uint16
|
||||
rows.Scan(&id, &maxPlayers, &questType, &questId)
|
||||
|
||||
bf := byteframe.NewByteFrame()
|
||||
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.
|
||||
bf.WriteInt32(id)
|
||||
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.WriteBytes([]byte{0x00, 0x01})
|
||||
bf.WriteUint16(0)
|
||||
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 {
|
||||
return nil, fmt.Errorf("failed to load quest file")
|
||||
@@ -218,13 +218,13 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
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.
|
||||
for rows.Next() {
|
||||
var pointer []byte
|
||||
var max_players, quest_type, checksum, quest_id uint16
|
||||
rows.Scan(&pointer, &max_players, &quest_type, &checksum, &quest_id)
|
||||
var maxPlayers, questType, checksum, questId uint16
|
||||
rows.Scan(&pointer, &maxPlayers, &questType, &checksum, &questId)
|
||||
|
||||
data, err := makeEventQuest(s, rows)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user