diff --git a/config.json b/config.json index 9bb641f72..c8705a661 100644 --- a/config.json +++ b/config.json @@ -36,6 +36,7 @@ "TournamentOverride": 0, "DisableTokenCheck": false, "QuestTools": false, + "AutoQuestBackport": true, "ProxyPort": 0, "CapLink": { "Values": [51728, 20000, 51729, 1, 20000], diff --git a/config/config.go b/config/config.go index d2038f150..b0094f628 100644 --- a/config/config.go +++ b/config/config.go @@ -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 } diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index c8bd41f3b..148908dbf 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -2,6 +2,7 @@ package channelserver import ( "database/sql" + "encoding/binary" "erupe-ce/common/byteframe" "erupe-ce/common/decryption" ps "erupe-ce/common/pascalstring" @@ -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) @@ -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) } } @@ -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)