From c4e8cd59992f7e450afbfce77ff1c0705584f950 Mon Sep 17 00:00:00 2001 From: stratic-dev Date: Tue, 24 Oct 2023 01:48:20 +0100 Subject: [PATCH 1/2] Added paxes fix and missing fields to db --- patch-schema/03-event_quests.sql | 6 ++- server/channelserver/handlers_quest.go | 63 ++++++++++++-------------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/patch-schema/03-event_quests.sql b/patch-schema/03-event_quests.sql index 94aac0c65..b54758ffe 100644 --- a/patch-schema/03-event_quests.sql +++ b/patch-schema/03-event_quests.sql @@ -3,10 +3,14 @@ BEGIN; create table if not exists event_quests ( id serial primary key, + index_value integer, max_players integer, quest_type integer not null, quest_id integer not null, - mark integer + mark integer, + quest_option integer not null, + + ); ALTER TABLE IF EXISTS public.servers DROP COLUMN IF EXISTS season; diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 803509f45..f0995170a 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -47,10 +47,6 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { ) } - if s.server.erupeConfig.GameplayOptions.SeasonOverride { - pkt.Filename = seasonConversion(s, pkt.Filename) - } - data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) if err != nil { s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename)) @@ -62,28 +58,6 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { } } -func questSuffix(s *Session) string { - // Determine the letter to append for day / night - var timeSet string - if TimeGameAbsolute() > 2880 { - timeSet = "d" - } else { - timeSet = "n" - } - return fmt.Sprintf("%s%d", timeSet, s.server.Season()) -} - -func seasonConversion(s *Session, questFile string) string { - filename := fmt.Sprintf("%s%s", questFile[:5], questSuffix(s)) - - // Return original file if file doesn't exist - if _, err := os.Stat(filename); err == nil { - return filename - } else { - return questFile - } -} - func handleMsgMhfLoadFavoriteQuest(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfLoadFavoriteQuest) var data []byte @@ -145,8 +119,9 @@ func loadQuestFile(s *Session, questId int) []byte { func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { var id, mark uint32 var questId int - var maxPlayers, questType uint8 - rows.Scan(&id, &maxPlayers, &questType, &questId, &mark) + var indexValue, maxPlayers, questType uint8 + var questOption uint16 + rows.Scan(&id, &indexValue, &maxPlayers, &questType, &questId, &mark, &questOption) data := loadQuestFile(s, questId) if data == nil { @@ -155,8 +130,8 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { bf := byteframe.NewByteFrame() bf.WriteUint32(id) - bf.WriteUint32(0) - bf.WriteUint8(0) // Indexer + bf.WriteUint32(0) //unk + bf.WriteUint8(indexValue) // Indexer switch questType { case 16: bf.WriteUint8(s.server.erupeConfig.GameplayOptions.RegularRavienteMaxPlayers) @@ -177,16 +152,36 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { } else { bf.WriteBool(true) } - bf.WriteUint16(0) + bf.WriteUint16(0) //unk counter id possibly? if _config.ErupeConfig.RealClientMode >= _config.G1 { bf.WriteUint32(mark) } - bf.WriteUint16(0) + bf.WriteUint16(0) //possible padding bf.WriteUint16(uint16(len(data))) bf.WriteBytes(data) - ps.Uint8(bf, "", true) // What is this string for? + //Season/RequiredObject Flag Replacement + bf.Seek(0x18, 0) + // Bitset Structure: bit 8 unk, bit 7 required objective,bit 6 unk,bit 5 night,bit 4 day,bit 3 cold,bit 2 warm,bit 1 breeding + // if the byte is set to 0 the game choses the quest file corresponding to whatever season the game is on + if s.server.erupeConfig.GameplayOptions.SeasonOverride { + bf.WriteUint16(0) + } else { + bf.WriteUint16(questOption) + } + + // Bitset Structure Quest Varient 1: bit 8 Hiden, bit 7 Fix HC,bit 6 HC to UL,bit 5 GRank,bit 4 Unk,bit 3 UNK,bit 2 UNK,bit 1 UNK + // Bitset Structure Quest Varient 2: bit 8 UNK, bit 7 No Halk Pots,bit 6 No halk/poogie,bit 5 Timer,bit 4 UNK,bit 3 Fixed Difficulty,bit 2 UNK,bit 1 UNK + // Bitset Structure Quest Varient 3: bit 8 Disable Reward Skill, bit 7 GSR to GR,bit 6 unk,bit 5 Musou?,bit 4 Zenith,bit 3 Inception,bit 2 UNK,bit 1 UNK + bf.Seek(0xAF, 0) + quest_variant_3 := bf.ReadUint8() + quest_variant_3 &= 0b11011111 //disables Inception flag at position 3 for any quests that dont have it set. + bf.Seek(0xAF, 0) + bf.WriteUint8(quest_variant_3) + + ps.Uint8(bf, "", true) // Debug/Notes string for quest return bf.Data(), nil + } func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) { @@ -195,7 +190,7 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) { bf := byteframe.NewByteFrame() bf.WriteUint16(0) - rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark FROM event_quests ORDER BY quest_id") + rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, index_value,quest_type, quest_id,quest_option, COALESCE(mark, 0) AS mark FROM event_quests ORDER BY quest_id") for rows.Next() { data, err := makeEventQuest(s, rows) if err != nil { From 64cb106c70f877545e7b519fbf9e85861c768ae5 Mon Sep 17 00:00:00 2001 From: wish Date: Tue, 24 Oct 2023 22:18:09 +1100 Subject: [PATCH 2/2] formatting, strip out unknown values --- patch-schema/03-event_quests.sql | 6 +--- server/channelserver/handlers_quest.go | 47 +++++++++++++------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/patch-schema/03-event_quests.sql b/patch-schema/03-event_quests.sql index b54758ffe..94aac0c65 100644 --- a/patch-schema/03-event_quests.sql +++ b/patch-schema/03-event_quests.sql @@ -3,14 +3,10 @@ BEGIN; create table if not exists event_quests ( id serial primary key, - index_value integer, max_players integer, quest_type integer not null, quest_id integer not null, - mark integer, - quest_option integer not null, - - + mark integer ); ALTER TABLE IF EXISTS public.servers DROP COLUMN IF EXISTS season; diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index f0995170a..aab84b960 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -119,9 +119,8 @@ func loadQuestFile(s *Session, questId int) []byte { func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { var id, mark uint32 var questId int - var indexValue, maxPlayers, questType uint8 - var questOption uint16 - rows.Scan(&id, &indexValue, &maxPlayers, &questType, &questId, &mark, &questOption) + var maxPlayers, questType uint8 + rows.Scan(&id, &maxPlayers, &questType, &questId, &mark) data := loadQuestFile(s, questId) if data == nil { @@ -130,8 +129,8 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { bf := byteframe.NewByteFrame() bf.WriteUint32(id) - bf.WriteUint32(0) //unk - bf.WriteUint8(indexValue) // Indexer + bf.WriteUint32(0) // Unk + bf.WriteUint8(0) // Unk switch questType { case 16: bf.WriteUint8(s.server.erupeConfig.GameplayOptions.RegularRavienteMaxPlayers) @@ -152,36 +151,38 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { } else { bf.WriteBool(true) } - bf.WriteUint16(0) //unk counter id possibly? + bf.WriteUint16(0) // Unk if _config.ErupeConfig.RealClientMode >= _config.G1 { bf.WriteUint32(mark) } - bf.WriteUint16(0) //possible padding + bf.WriteUint16(0) // Unk bf.WriteUint16(uint16(len(data))) bf.WriteBytes(data) - //Season/RequiredObject Flag Replacement - bf.Seek(0x18, 0) - // Bitset Structure: bit 8 unk, bit 7 required objective,bit 6 unk,bit 5 night,bit 4 day,bit 3 cold,bit 2 warm,bit 1 breeding + + // Time Flag Replacement + // Bitset Structure: b8 UNK, b7 Required Objective, b6 UNK, b5 Night, b4 Day, b3 Cold, b2 Warm, b1 Spring // if the byte is set to 0 the game choses the quest file corresponding to whatever season the game is on + bf.Seek(25, 0) + flagByte := bf.ReadUint8() + bf.Seek(25, 0) if s.server.erupeConfig.GameplayOptions.SeasonOverride { - bf.WriteUint16(0) + bf.WriteUint8(flagByte & 0b11100000) } else { - bf.WriteUint16(questOption) + bf.WriteUint8(flagByte) } - // Bitset Structure Quest Varient 1: bit 8 Hiden, bit 7 Fix HC,bit 6 HC to UL,bit 5 GRank,bit 4 Unk,bit 3 UNK,bit 2 UNK,bit 1 UNK - // Bitset Structure Quest Varient 2: bit 8 UNK, bit 7 No Halk Pots,bit 6 No halk/poogie,bit 5 Timer,bit 4 UNK,bit 3 Fixed Difficulty,bit 2 UNK,bit 1 UNK - // Bitset Structure Quest Varient 3: bit 8 Disable Reward Skill, bit 7 GSR to GR,bit 6 unk,bit 5 Musou?,bit 4 Zenith,bit 3 Inception,bit 2 UNK,bit 1 UNK - bf.Seek(0xAF, 0) - quest_variant_3 := bf.ReadUint8() - quest_variant_3 &= 0b11011111 //disables Inception flag at position 3 for any quests that dont have it set. - bf.Seek(0xAF, 0) - bf.WriteUint8(quest_variant_3) + // Bitset Structure Quest Variant 1: b8 UL Fixed, b7 UNK, b6 UNK, b5 UNK, b4 G Rank, b3 HC to UL, b2 Fix HC, b1 Hiden + // Bitset Structure Quest Variant 2: b8 Road, b7 High Conquest, b6 Fixed Difficulty, b5 No Active Feature, b4 Timer, b3 No Cuff, b2 No Halk Pots, b1 Low Conquest + // Bitset Structure Quest Variant 3: b8 No Sigils, b7 UNK, b6 Interception, b5 Zenith, b4 No GP Skills, b3 No Simple Mode?, b2 GSR to GR, b1 No Reward Skills + + bf.Seek(175, 0) + questVariant3 := bf.ReadUint8() + questVariant3 &= 0b11011111 // disable Interception flag + bf.Seek(175, 0) + bf.WriteUint8(questVariant3) ps.Uint8(bf, "", true) // Debug/Notes string for quest - return bf.Data(), nil - } func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) { @@ -190,7 +191,7 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) { bf := byteframe.NewByteFrame() bf.WriteUint16(0) - rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, index_value,quest_type, quest_id,quest_option, COALESCE(mark, 0) AS mark FROM event_quests ORDER BY quest_id") + rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark FROM event_quests ORDER BY quest_id") for rows.Next() { data, err := makeEventQuest(s, rows) if err != nil {