Skip to content

Commit

Permalink
add AutoBackportQuest DebugOption
Browse files Browse the repository at this point in the history
  • Loading branch information
sekaiwish committed Feb 11, 2024
1 parent 771f240 commit 6ec9d9d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"TournamentOverride": 0,
"DisableTokenCheck": false,
"QuestTools": false,
"AutoQuestBackport": true,
"ProxyPort": 0,
"CapLink": {
"Values": [51728, 20000, 51729, 1, 20000],
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type DebugOptions struct {
TournamentOverride int // VS Tournament event status
DisableTokenCheck bool // Disables checking login token exists in the DB (security risk!)
QuestTools bool // Enable various quest debug logs
AutoQuestBackport bool // Automatically backport quest files
ProxyPort uint16 // Forces the game to connect to a channel server proxy
CapLink CapLinkOptions
}
Expand Down
21 changes: 21 additions & 0 deletions server/channelserver/handlers_quest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package channelserver

import (
"database/sql"
"encoding/binary"
"erupe-ce/common/byteframe"
"erupe-ce/common/decryption"
ps "erupe-ce/common/pascalstring"
Expand All @@ -21,6 +22,20 @@ type tuneValue struct {
Value uint16
}

func BackportQuest(data []byte) []byte {
wp := binary.LittleEndian.Uint32(data[0:4]) + 96
rp := wp + 4
for i := uint32(0); i < 6; i++ {
if i != 0 {
wp += 4
rp += 8
}
copy(data[wp:wp+4], data[rp:rp+4])
}
copy(data[wp:wp+180], data[rp:rp+180])
return data
}

func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgSysGetFile)

Expand Down Expand Up @@ -63,6 +78,9 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
doAckBufSucceed(s, pkt.AckHandle, data)
return
}
if _config.ErupeConfig.RealClientMode <= _config.Z1 && s.server.erupeConfig.DebugOptions.AutoQuestBackport {
data = BackportQuest(decryption.UnpackSimple(data))
}
doAckBufSucceed(s, pkt.AckHandle, data)
}
}
Expand Down Expand Up @@ -124,6 +142,9 @@ func loadQuestFile(s *Session, questId int) []byte {
}

decrypted := decryption.UnpackSimple(file)
if _config.ErupeConfig.RealClientMode <= _config.Z1 && s.server.erupeConfig.DebugOptions.AutoQuestBackport {
decrypted = BackportQuest(decrypted)
}
fileBytes := byteframe.NewByteFrameFromBytes(decrypted)
fileBytes.SetLE()
fileBytes.Seek(int64(fileBytes.ReadUint32()), 0)
Expand Down

0 comments on commit 6ec9d9d

Please sign in to comment.