Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
fix: Difference Between CN and EN regions
Browse files Browse the repository at this point in the history
1. (CN)Fixed the problem of unable to complete the construction
2. (CN)Fixed the crash issue when viewing ship details
3. Recharge is temporarily disabled because according to the code we cannot easily complete in-game purchases as they are implemented through the sdk at the end.
4. Fixed the problem of some page crashes. The reason is that azurlane will check whether the data has been tampered with on certain occasions(not for priv server).
5. Implemented the function of checking whether the commander exists on the login page
6. (CN_JP_KR_TW)Implemented ServerInterconnection in azurlane code, which seems to be used to switch ios/android servers. This content has only been tested in CN_JP_KR_TW.
  • Loading branch information
azurshinano committed Apr 21, 2024
1 parent ca76e66 commit 75f4ef0
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 17 deletions.
21 changes: 9 additions & 12 deletions answer/build_finish.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@ package answer

import (
"github.com/ggmolly/belfast/connection"

"github.com/ggmolly/belfast/protobuf"
"google.golang.org/protobuf/proto"
)

// XXX: i have no idea what this packet is for but this works, so...
// Get the corresponding template_id in the ship build list
func BuildFinish(buffer *[]byte, client *connection.Client) (int, int, error) {
var data protobuf.CS_12043
err := proto.Unmarshal(*buffer, &data)
if err != nil {
return 0, 12043, err
buildInfos := make([]*protobuf.BUILD_INFO, len(client.Commander.Builds))
for i, work := range client.Commander.Builds {
buildInfos[i] = &protobuf.BUILD_INFO{
Pos: proto.Uint32(uint32(i + 1)),
Tid: proto.Uint32(work.ShipID),
}
}

response := protobuf.SC_12044{
InfoList: []*protobuf.BUILD_INFO{ // ???
&protobuf.BUILD_INFO{
Pos: proto.Uint32(1),
Tid: proto.Uint32(1),
},
},
InfoList: buildInfos,
}

return client.SendMessage(12044, &response)
}
19 changes: 19 additions & 0 deletions answer/charge_command_answer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package answer

import (
"github.com/ggmolly/belfast/connection"
"github.com/ggmolly/belfast/protobuf"
"google.golang.org/protobuf/proto"
)

func ChargeCommandAnswer(buffer *[]byte, client *connection.Client) (int, int, error) {
// Disable Charge
response := protobuf.SC_11502{
Result: proto.Uint32(5002),
PayId: proto.String(""),
Url: proto.String(""),
OrderSign: proto.String(""),
}

return client.SendMessage(11502, &response)
}
21 changes: 21 additions & 0 deletions answer/cheater_mark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package answer

import (
"github.com/ggmolly/belfast/connection"
"github.com/ggmolly/belfast/protobuf"
"google.golang.org/protobuf/proto"
)

func CheaterMark(buffer *[]byte, client *connection.Client) (int, int, error) {
var protoData protobuf.CS_10994
err := proto.Unmarshal((*buffer), &protoData)
if err != nil {
return 0, 10995, err
}

response := protobuf.SC_10995{
Result: proto.Uint32(protoData.GetType()),
}

return client.SendMessage(10995, &response)
}
22 changes: 22 additions & 0 deletions answer/forge_10803.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package answer

import (
"github.com/ggmolly/belfast/connection"
"github.com/ggmolly/belfast/consts"
"github.com/ggmolly/belfast/protobuf"
"google.golang.org/protobuf/proto"
"os"
)

// In the Azurlane code, it is called ServerInterconnection, used to switch Android/iOS servers
func Forge_SC10803_CN_JP_KR_TW(buffer *[]byte, client *connection.Client) (int, int, error) {
belfastRegion := os.Getenv("AL_REGION")
response := protobuf.SC_10803_CN_JP_KR_TW{
GatewayIp: proto.String(consts.RegionGateways[belfastRegion]),
GatewayPort: proto.Uint32(80),
ProxyIp: proto.String(consts.RegionProxies[belfastRegion]),
ProxyPort: proto.Uint32(20000),
}

return client.SendMessage(10803, &response)
}
31 changes: 31 additions & 0 deletions answer/player_exist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package answer

import (
"github.com/ggmolly/belfast/connection"
"github.com/ggmolly/belfast/protobuf"
"google.golang.org/protobuf/proto"
)

// Check if an account exists on the game server
func PlayerExist(buffer *[]byte, client *connection.Client) (int, int, error) {
var protoData protobuf.CS_10026
err := proto.Unmarshal((*buffer), &protoData)
if err != nil {
return 0, 10027, err
}

response := protobuf.SC_10027{}

err = client.GetCommander(protoData.GetAccountId())
if err != nil {
// Player not found?
response.UserId = proto.Uint32(0)
response.Level = proto.Uint32(0)
} else {
// Even if the player is punished, we still return player information
response.UserId = proto.Uint32(client.Commander.CommanderID)
response.Level = proto.Uint32(uint32(client.Commander.Level))
}

return client.SendMessage(10027, &response)
}
2 changes: 1 addition & 1 deletion answer/player_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func PlayerInfo(buffer *[]byte, client *connection.Client) (int, int, error) {
CommanderBagMax: proto.Uint32(250),
Display: &protobuf.DISPLAYINFO{
Icon: proto.Uint32(202124), // Should display Belfast's icon
Skin: proto.Uint32(202123), // Should display Belfast's default skin
Skin: proto.Uint32(202124), // Should display Belfast's default skin
IconFrame: proto.Uint32(0),
ChatFrame: proto.Uint32(0),
IconTheme: proto.Uint32(0),
Expand Down
5 changes: 4 additions & 1 deletion answer/send_player_ship_count.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package answer

import (
"github.com/ggmolly/belfast/consts"
"os"
"time"

"github.com/ggmolly/belfast/connection"
Expand All @@ -10,9 +12,10 @@ import (
)

func SendPlayerShipCount(buffer *[]byte, client *connection.Client) (int, int, error) {
belfastRegion := os.Getenv("AL_REGION")
answer := protobuf.SC_11002{
Timestamp: proto.Uint32(uint32(time.Now().Unix())),
Monday_0OclockTimestamp: proto.Uint32(1606114800), // 23/11/2020 08:00:00
Monday_0OclockTimestamp: proto.Uint32(consts.Monday_0OclockTimestamps[belfastRegion]),
ShipCount: proto.Uint32(uint32(len(client.Commander.Ships))),
}
client.Server.JoinRoom(client.Commander.RoomID, client)
Expand Down
2 changes: 1 addition & 1 deletion answer/update_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Forge_SC10801(buffer *[]byte, client *connection.Client) (int, int, error)
ProxyPort: proto.Uint32(20000),
IsTs: proto.Uint32(0),
Timestamp: proto.Uint32(uint32(time.Now().Unix())),
Monday_0OclockTimestamp: proto.Uint32(consts.Monday_0OclockTimestamps[belfastRegion]), // // 23/11/2020 08:00:00
Monday_0OclockTimestamp: proto.Uint32(consts.Monday_0OclockTimestamps[belfastRegion]),

// wtf is this i don't even understand what monday_0oclock_timestamp is
// who would even do such a thing
Expand Down
32 changes: 32 additions & 0 deletions connection/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,38 @@ func (client *Client) CreateCommander(arg2 uint32) (uint32, error) {
logger.LogEvent("Client", "CreateCommander", fmt.Sprintf("failed to give Belfast to account %d: %v", accountId, err), logger.LOG_LEVEL_ERROR)
return 0, err
}

// Give default items to commander
if err := orm.GormDB.Create(&([]orm.CommanderItem{{
// Wisdom Cube
CommanderID: accountId,
ItemID: 20001,
Count: 0,
}})).Error; err != nil {
logger.LogEvent("Client", "CreateCommander", fmt.Sprintf("failed to give default items to account %d: %v", accountId, err), logger.LOG_LEVEL_ERROR)
return 0, err
}
// Give default resources to commander
if err := orm.GormDB.Create(&([]orm.OwnedResource{{
// Gold
CommanderID: accountId,
ResourceID: 1,
Amount: 0,
}, {
// Oil
CommanderID: accountId,
ResourceID: 2,
Amount: 0,
}, {
// Gem
CommanderID: accountId,
ResourceID: 4,
Amount: 0,
}})).Error; err != nil {
logger.LogEvent("Client", "CreateCommander", fmt.Sprintf("failed to give default resources to account %d: %v", accountId, err), logger.LOG_LEVEL_ERROR)
return 0, err
}

logger.LogEvent("Client", "CreateCommander", fmt.Sprintf("created new commander for account %d", accountId), logger.LOG_LEVEL_INFO)
return accountId, nil
}
Expand Down
11 changes: 11 additions & 0 deletions consts/update_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ package consts
var (
RegionGateways = map[string]string{
"EN": "blhxusgate.yo-star.com",
"CN": "line1-login-bili-blhx.bilibiligame.net",
}
RegionProxies = map[string]string{
"EN": "blhxusproxy.yo-star.com",
// Its port in the apk should be 8080, but we don't need to care about it at the moment
"CN": "line1-bak-login-bili-blhx.bilibiligame.net",
}
// This might not change between regions, but it's here just in case
Monday_0OclockTimestamps = map[string]uint32{
"EN": 1606114800,
// No one knows why, but according to version rules, this date may indeed be earlier than EN
"CN": 1606060800,
}

// This map represents the game's url on the respective platforms
Expand All @@ -23,5 +28,11 @@ var (
"0": "https://play.google.com/store/apps/details?id=com.YoStarEN.AzurLane",
"1": "https://itunes.apple.com/us/app/azur-lane/id1411126549",
},
"CN": {
// On Android, it should point to the latest apk address,
// but we can currently point directly to the official website
"0": "https://blhx.biligame.com/",
"1": "https://blhx.biligame.com/",
},
}
)
26 changes: 24 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ func init() {
}
packets.RegisterPacketHandler(10800, []packets.PacketHandler{answer.Forge_SC10801})
packets.RegisterPacketHandler(8239, []packets.PacketHandler{answer.Forge_SC8239})
packets.RegisterLocalizedPacketHandler(10020, packets.LocalizedHandler{
EN: &[]packets.PacketHandler{answer.Forge_SC10021},
packets.RegisterPacketHandler(10020, []packets.PacketHandler{answer.Forge_SC10021})
packets.RegisterLocalizedPacketHandler(10802, packets.LocalizedHandler{
CN: &[]packets.PacketHandler{answer.Forge_SC10803_CN_JP_KR_TW},
TW: &[]packets.PacketHandler{answer.Forge_SC10803_CN_JP_KR_TW},
JP: &[]packets.PacketHandler{answer.Forge_SC10803_CN_JP_KR_TW},
KR: &[]packets.PacketHandler{answer.Forge_SC10803_CN_JP_KR_TW},
})
packets.RegisterPacketHandler(10022, []packets.PacketHandler{answer.JoinServer})
packets.RegisterPacketHandler(10026, []packets.PacketHandler{answer.PlayerExist})
packets.RegisterPacketHandler(11001, []packets.PacketHandler{
answer.LastLogin, // SC_11000
answer.PlayerInfo, // SC_11003
Expand Down Expand Up @@ -143,6 +148,7 @@ func init() {
packets.RegisterPacketHandler(10100, []packets.PacketHandler{answer.SendHeartbeat})
packets.RegisterPacketHandler(11013, []packets.PacketHandler{answer.GiveResources})
packets.RegisterPacketHandler(33000, []packets.PacketHandler{answer.UNK_33001})
packets.RegisterPacketHandler(10994, []packets.PacketHandler{answer.CheaterMark})

// Build
packets.RegisterPacketHandler(12002, []packets.PacketHandler{answer.ShipBuild})
Expand All @@ -163,6 +169,7 @@ func init() {

// Shop
packets.RegisterPacketHandler(16001, []packets.PacketHandler{answer.ShoppingCommandAnswer})
packets.RegisterPacketHandler(11501, []packets.PacketHandler{answer.ChargeCommandAnswer})

// Retire
packets.RegisterPacketHandler(12004, []packets.PacketHandler{answer.RetireShip})
Expand Down Expand Up @@ -225,4 +232,19 @@ func init() {
// Ship comments tab
packets.RegisterPacketHandler(17101, []packets.PacketHandler{answer.GetShipDiscuss}) // Ship discussion (placeholder)
packets.RegisterPacketHandler(17107, []packets.PacketHandler{answer.UpdateShipLike})

// ???
packets.RegisterPacketHandler(15300, []packets.PacketHandler{func(b *[]byte, c *connection.Client) (int, int, error) {
return 0, 0, nil
}})

// ???
packets.RegisterPacketHandler(12299, []packets.PacketHandler{func(b *[]byte, c *connection.Client) (int, int, error) {
return 0, 0, nil
}})

// track
packets.RegisterPacketHandler(10993, []packets.PacketHandler{func(b *[]byte, c *connection.Client) (int, int, error) {
return 0, 0, nil
}})
}
4 changes: 4 additions & 0 deletions misc/game_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func GetGameHashes() HashMap {
State: proto.Uint32(59), // 59 is something, might need to update this later?
Platform: proto.String("1"), // iOS
}
if os.Getenv("AL_REGION") == "CN" {
// fix version invalid?
promptUpdate.State = proto.Uint32(56)
}
packet, err := proto.Marshal(&promptUpdate)
if err != nil {
logger.LogEvent("GameUpdate", "GetHashes", err.Error(), logger.LOG_LEVEL_ERROR)
Expand Down

0 comments on commit 75f4ef0

Please sign in to comment.