From c3ee5ef7598b76de82c910b30dabb69d648a8755 Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 22 Jul 2023 13:34:29 +1000 Subject: [PATCH 1/4] rewrite TransitMessage Find Party --- server/channelserver/handlers.go | 89 +++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 29 deletions(-) diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index 9c25638b5..3fc1cd976 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -6,6 +6,7 @@ import ( "erupe-ce/common/mhfcourse" ps "erupe-ce/common/pascalstring" "erupe-ce/common/stringsupport" + _config "erupe-ce/config" "fmt" "io" "net" @@ -447,48 +448,78 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) { } } case 4: // Find Party + type FindPartyParams struct { + StagePrefix string + RankRestriction uint16 + Targets []uint16 + } + findPartyParams := FindPartyParams{} bf := byteframe.NewByteFrameFromBytes(pkt.MessageData) - setting := bf.ReadUint8() + numParams := int(bf.ReadUint8()) maxResults := bf.ReadUint16() - bf.Seek(2, 1) - partyType := bf.ReadUint16() - rankRestriction := uint16(0) - if setting >= 2 { - bf.Seek(2, 1) - rankRestriction = bf.ReadUint16() - } - targets := make([]uint16, 4) - if setting >= 3 { - bf.Seek(1, 1) - lenTargets := int(bf.ReadUint8()) - for i := 0; i < lenTargets; i++ { - targets[i] = bf.ReadUint16() + for i := 0; i < numParams; i++ { + switch bf.ReadUint8() { + case 0: + values := int(bf.ReadUint8()) + for i := 0; i < values; i++ { + if _config.ErupeConfig.RealClientMode >= _config.Z1 { + findPartyParams.RankRestriction = bf.ReadUint16() + } else { + findPartyParams.RankRestriction = uint16(bf.ReadInt8()) + } + } + case 1: + values := int(bf.ReadUint8()) + for i := 0; i < values; i++ { + if _config.ErupeConfig.RealClientMode >= _config.Z1 { + findPartyParams.Targets = append(findPartyParams.Targets, bf.ReadUint16()) + } else { + findPartyParams.Targets = append(findPartyParams.Targets, uint16(bf.ReadInt8())) + } + } + case 2: + values := int(bf.ReadUint8()) + for i := 0; i < values; i++ { + var value int16 + if _config.ErupeConfig.RealClientMode >= _config.Z1 { + value = bf.ReadInt16() + } else { + value = int16(bf.ReadInt8()) + } + switch value { + case 0: // Public Bar + findPartyParams.StagePrefix = "sl2Ls210" + case 1: // Tokotoko Partnya + findPartyParams.StagePrefix = "sl2Ls463" + case 2: // Hunting Prowess Match + findPartyParams.StagePrefix = "sl2Ls286" + case 3: // Volpakkun Together + findPartyParams.StagePrefix = "sl2Ls465" + case 5: // Quick Party + // Unk + } + } } } - var stagePrefix string - switch partyType { - case 0: // Public Bar - stagePrefix = "sl2Ls210" - case 1: // Tokotoko Partnya - stagePrefix = "sl2Ls463" - case 2: // Hunting Prowess Match - stagePrefix = "sl2Ls286" - case 3: // Volpakkun Together - stagePrefix = "sl2Ls465" - case 5: // Quick Party - // Unk - } for _, c := range s.server.Channels { for _, stage := range c.stages { if count == maxResults { break } - if strings.HasPrefix(stage.id, stagePrefix) { + if strings.HasPrefix(stage.id, findPartyParams.StagePrefix) { sb3 := byteframe.NewByteFrameFromBytes(stage.rawBinaryData[stageBinaryKey{1, 3}]) sb3.Seek(4, 0) stageRankRestriction := sb3.ReadUint16() stageTarget := sb3.ReadUint16() - if rankRestriction != 0xFFFF && stageRankRestriction < rankRestriction { + if stageRankRestriction > findPartyParams.RankRestriction { + continue + } + if len(findPartyParams.Targets) > 0 { + for _, target := range findPartyParams.Targets { + if target == stageTarget { + break + } + } continue } count++ From c625f595e3c201b7764182966d3f0af07de9e5db Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 22 Jul 2023 13:40:01 +1000 Subject: [PATCH 2/4] set default StagePrefix for Find Party --- server/channelserver/handlers.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index 3fc1cd976..04e08a8e8 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -453,7 +453,9 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) { RankRestriction uint16 Targets []uint16 } - findPartyParams := FindPartyParams{} + findPartyParams := FindPartyParams{ + StagePrefix: "sl2Ls210", + } bf := byteframe.NewByteFrameFromBytes(pkt.MessageData) numParams := int(bf.ReadUint8()) maxResults := bf.ReadUint16() From cc428d85d35ec012ab7fe0f5ab3a83aac24f2126 Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 22 Jul 2023 13:49:30 +1000 Subject: [PATCH 3/4] read additional Find Party data into struct --- server/channelserver/handlers.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index 04e08a8e8..81cd1838a 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -452,6 +452,9 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) { StagePrefix string RankRestriction uint16 Targets []uint16 + Unk0 []uint16 + Unk1 []uint16 + QuestID []uint16 } findPartyParams := FindPartyParams{ StagePrefix: "sl2Ls210", @@ -501,6 +504,33 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) { // Unk } } + case 3: // Unknown + values := int(bf.ReadUint8()) + for i := 0; i < values; i++ { + if _config.ErupeConfig.RealClientMode >= _config.Z1 { + findPartyParams.Unk0 = append(findPartyParams.Unk0, bf.ReadUint16()) + } else { + findPartyParams.Unk0 = append(findPartyParams.Unk0, uint16(bf.ReadInt8())) + } + } + case 4: // Looking for n or already have n + values := int(bf.ReadUint8()) + for i := 0; i < values; i++ { + if _config.ErupeConfig.RealClientMode >= _config.Z1 { + findPartyParams.Unk1 = append(findPartyParams.Unk1, bf.ReadUint16()) + } else { + findPartyParams.Unk1 = append(findPartyParams.Unk1, uint16(bf.ReadInt8())) + } + } + case 5: + values := int(bf.ReadUint8()) + for i := 0; i < values; i++ { + if _config.ErupeConfig.RealClientMode >= _config.Z1 { + findPartyParams.QuestID = append(findPartyParams.QuestID, bf.ReadUint16()) + } else { + findPartyParams.QuestID = append(findPartyParams.QuestID, uint16(bf.ReadInt8())) + } + } } } for _, c := range s.server.Channels { From dbedab4d33b8712d5feb942349239c23808662e0 Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 22 Jul 2023 16:47:44 +1000 Subject: [PATCH 4/4] add ClientMode support based on Forward.4 --- network/crypt_conn.go | 8 +++++--- network/mhfpacket/msg_mhf_acquire_cafe_item.go | 9 +++++++-- network/mhfpacket/msg_sys_terminal_log.go | 2 +- server/channelserver/handlers_guild.go | 4 ++++ server/entranceserver/make_resp.go | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/network/crypt_conn.go b/network/crypt_conn.go index 439e9e3a0..3a952ee19 100644 --- a/network/crypt_conn.go +++ b/network/crypt_conn.go @@ -47,8 +47,10 @@ func (cc *CryptConn) ReadPacket() ([]byte, error) { return nil, err } + dataSize := uint32(cph.DataSize) + (uint32(cph.Pf0-0x03) * 0x1000) + // Now read the encrypted packet body after getting its size from the header. - encryptedPacketBody := make([]byte, cph.DataSize) + encryptedPacketBody := make([]byte, dataSize) _, err = io.ReadFull(cc.conn, encryptedPacketBody) if err != nil { return nil, err @@ -56,7 +58,7 @@ func (cc *CryptConn) ReadPacket() ([]byte, error) { // Update the key rotation before decrypting. if cph.KeyRotDelta != 0 { - cc.readKeyRot = (uint32(cph.KeyRotDelta) * (cc.readKeyRot + 1)) + cc.readKeyRot = uint32(cph.KeyRotDelta) * (cc.readKeyRot + 1) } out, combinedCheck, check0, check1, check2 := crypto.Decrypt(encryptedPacketBody, cc.readKeyRot, nil) @@ -94,7 +96,7 @@ func (cc *CryptConn) SendPacket(data []byte) error { keyRotDelta := byte(3) if keyRotDelta != 0 { - cc.sendKeyRot = (uint32(keyRotDelta) * (cc.sendKeyRot + 1)) + cc.sendKeyRot = uint32(keyRotDelta) * (cc.sendKeyRot + 1) } // Encrypt the data diff --git a/network/mhfpacket/msg_mhf_acquire_cafe_item.go b/network/mhfpacket/msg_mhf_acquire_cafe_item.go index 8dcad0b53..04e603a44 100644 --- a/network/mhfpacket/msg_mhf_acquire_cafe_item.go +++ b/network/mhfpacket/msg_mhf_acquire_cafe_item.go @@ -2,10 +2,11 @@ package mhfpacket import ( "errors" + _config "erupe-ce/config" + "erupe-ce/common/byteframe" "erupe-ce/network" "erupe-ce/network/clientctx" - "erupe-ce/common/byteframe" ) // MsgMhfAcquireCafeItem represents the MSG_MHF_ACQUIRE_CAFE_ITEM @@ -30,7 +31,11 @@ func (m *MsgMhfAcquireCafeItem) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Cl m.ItemType = bf.ReadUint16() m.ItemID = bf.ReadUint16() m.Quant = bf.ReadUint16() - m.PointCost = bf.ReadUint32() + if _config.ErupeConfig.RealClientMode >= _config.G1 { + m.PointCost = bf.ReadUint32() + } else { + m.PointCost = uint32(bf.ReadUint16()) + } m.Unk0 = bf.ReadUint16() return nil } diff --git a/network/mhfpacket/msg_sys_terminal_log.go b/network/mhfpacket/msg_sys_terminal_log.go index 27cc5b1f6..43bf43dd3 100644 --- a/network/mhfpacket/msg_sys_terminal_log.go +++ b/network/mhfpacket/msg_sys_terminal_log.go @@ -39,7 +39,7 @@ func (m *MsgSysTerminalLog) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Client m.Unk0 = bf.ReadUint16() values := 15 - if _config.ErupeConfig.RealClientMode <= _config.S6 { + if _config.ErupeConfig.RealClientMode <= _config.F4 { values = 7 } for i := 0; i < int(m.EntryCount); i++ { diff --git a/server/channelserver/handlers_guild.go b/server/channelserver/handlers_guild.go index 879969e79..3c28a7bed 100644 --- a/server/channelserver/handlers_guild.go +++ b/server/channelserver/handlers_guild.go @@ -130,6 +130,8 @@ func (g *Guild) Rank() uint16 { if g.RankRP < u { if _config.ErupeConfig.RealClientMode <= _config.S6 && i >= 12 { return 12 + } else if _config.ErupeConfig.RealClientMode <= _config.F4 && i >= 13 { + return 13 } else if _config.ErupeConfig.RealClientMode <= _config.G32 && i >= 14 { return 14 } @@ -138,6 +140,8 @@ func (g *Guild) Rank() uint16 { } if _config.ErupeConfig.RealClientMode <= _config.S6 { return 12 + } else if _config.ErupeConfig.RealClientMode <= _config.F4 { + return 13 } else if _config.ErupeConfig.RealClientMode <= _config.G32 { return 14 } diff --git a/server/entranceserver/make_resp.go b/server/entranceserver/make_resp.go index 86256d02c..3d64dd9f2 100644 --- a/server/entranceserver/make_resp.go +++ b/server/entranceserver/make_resp.go @@ -56,7 +56,7 @@ func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte { bf.WriteUint8(si.Recommended) } - if s.erupeConfig.RealClientMode <= _config.S6 { + if s.erupeConfig.RealClientMode <= _config.F4 { combined := append(stringsupport.UTF8ToSJIS(si.Name), []byte{0x00}...) combined = append(combined, stringsupport.UTF8ToSJIS(si.Description)...) bf.WriteBytes(stringsupport.PaddedString(string(combined), 65, false))