Skip to content

Commit

Permalink
bug fix and standardize variable name
Browse files Browse the repository at this point in the history
* standardize variable name
* fix netease ai commands sending are not atomicity
* correct comment: "S2CModEvent" -> "ModEventS2C"
* each netease ai command always have a response body, so there is no need for a timeout limit
* bug fix on adjust "sendcommandfeedback" game rule
* bug fix on adjust command type while under "SkipMCPCheckChallenges" situation
  • Loading branch information
Happy2018new committed Mar 30, 2024
1 parent 58857ba commit 9c6c09c
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 238 deletions.
8 changes: 4 additions & 4 deletions fastbuilder/bdump/nbt_assigner/block_container_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (c *Container) MoveItemIntoContainer(
if err != nil {
return fmt.Errorf("MoveItemIntoContainer: %v", err)
}
containerOpeningData := api.Resources.Container.GetContainerOpeningData()
container_opening_data := api.Resources.Container.GetContainerOpeningData()
got := SupportContainerPool[c.BlockEntity.Block.Name]
// 获取 itemLocation 处的物品数据,
// 以及已打开容器的数据
Expand All @@ -222,7 +222,7 @@ func (c *Container) MoveItemIntoContainer(
Slot: itemLocation,
},
GameInterface.ItemLocation{
WindowID: containerOpeningData.WindowID,
WindowID: container_opening_data.WindowID,
ContainerID: got.ContainerID,
Slot: destination,
},
Expand Down Expand Up @@ -711,7 +711,7 @@ func (c *Container) ItemPlanner(contents []GeneralItem) ([]GeneralItem, error) {
}
defer api.CloseContainer()
// 占用容器资源并打开容器
containerOpeningData := api.Resources.Container.GetContainerOpeningData()
container_opening_data := api.Resources.Container.GetContainerOpeningData()
got := SupportContainerPool[c.BlockEntity.Block.Name]
// 获取已打开容器的数据
for key, value := range moveIndex {
Expand All @@ -733,7 +733,7 @@ func (c *Container) ItemPlanner(contents []GeneralItem) ([]GeneralItem, error) {
Slot: key,
},
GameInterface.ItemLocation{
WindowID: containerOpeningData.WindowID,
WindowID: container_opening_data.WindowID,
ContainerID: got.ContainerID,
Slot: value.Basic.Slot,
},
Expand Down
2 changes: 1 addition & 1 deletion fastbuilder/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func EnterReadlineThread(env *environment.PBEnvironment, breaker chan struct{})
resp := gameInterface.SendAICommandWithResponse(
cmd[1:],
ResourcesControl.CommandRequestOptions{
TimeOut: ResourcesControl.CommandRequestDefaultDeadLine,
TimeOut: ResourcesControl.CommandRequestNoDeadLine,
},
)
if resp.Error != nil {
Expand Down
10 changes: 10 additions & 0 deletions fastbuilder/function/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"

"phoenixbuilder/fastbuilder/args"
"phoenixbuilder/fastbuilder/builder"
"phoenixbuilder/fastbuilder/configuration"
"phoenixbuilder/fastbuilder/environment"
Expand Down Expand Up @@ -181,6 +182,9 @@ func InitPresetFunctions(fh *FunctionHolder) {
ArgumentTypes: []byte{},
Content: func(env *environment.PBEnvironment, _ []interface{}) {
env.GameInterface.SendSettingsCommand("gamerule sendcommandfeedback true", false)
if args.SkipMCPCheckChallenges {
defer env.GameInterface.SendSettingsCommand("gamerule sendcommandfeedback false", false)
}
resp := env.GameInterface.SendCommandWithResponse(
fmt.Sprintf(
"execute @a[name=\"%s\"] ~ ~ ~ testforblock ~ ~ ~ air",
Expand Down Expand Up @@ -218,6 +222,9 @@ func InitPresetFunctions(fh *FunctionHolder) {
FunctionType: FunctionTypeSimple,
Content: func(env *environment.PBEnvironment, _ []interface{}) {
env.GameInterface.SendSettingsCommand("gamerule sendcommandfeedback true", false)
if args.SkipMCPCheckChallenges {
defer env.GameInterface.SendSettingsCommand("gamerule sendcommandfeedback false", false)
}
resp := env.GameInterface.SendCommandWithResponse(
fmt.Sprintf(
"execute @a[name=\"%s\"] ~ ~ ~ testforblock ~ ~ ~ air",
Expand Down Expand Up @@ -254,6 +261,9 @@ func InitPresetFunctions(fh *FunctionHolder) {
FunctionType: FunctionTypeSimple,
Content: func(env *environment.PBEnvironment, _ []interface{}) {
env.GameInterface.SendSettingsCommand("gamerule sendcommandfeedback true", false)
if args.SkipMCPCheckChallenges {
defer env.GameInterface.SendSettingsCommand("gamerule sendcommandfeedback false", false)
}
resp := env.GameInterface.SendCommandWithResponse(
fmt.Sprintf(
"execute @a[name=\"%s\"] ~ ~ ~ testforblock ~ ~ ~ air",
Expand Down
5 changes: 4 additions & 1 deletion fastbuilder/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package task

import (
"fmt"
"phoenixbuilder/fastbuilder/args"
NBTAssigner "phoenixbuilder/fastbuilder/bdump/nbt_assigner"
"phoenixbuilder/fastbuilder/builder"
"phoenixbuilder/fastbuilder/commands_generator"
Expand Down Expand Up @@ -252,7 +253,9 @@ func CreateTask(commandLine string, env *environment.PBEnvironment) *Task {
} else {
//isFastMode=false
gameInterface.SendWSCommand("gamemode c")
gameInterface.SendWSCommand("gamerule sendcommandfeedback true")
if !args.SkipMCPCheckChallenges {
gameInterface.SendWSCommand("gamerule sendcommandfeedback true")
}
}
for {
task.ContinueLock.Lock()
Expand Down
10 changes: 5 additions & 5 deletions game_control/game_interface/anvil_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func (g *GameInterface) RenameItemByAnvil(
// 获取被改物品的相关信息。
// 如果发生了错误或指定的物品为空气,
// 则会跳过这个物品
containerOpeningData := g.Resources.Container.GetContainerOpeningData()
container_opening_data := g.Resources.Container.GetContainerOpeningData()
// 获取已打开的容器的数据
if containerOpeningData == nil {
if container_opening_data == nil {
return res, fmt.Errorf("RenameItemByAnvil: Anvil have been closed")
}
// 确保容器未被关闭
Expand All @@ -132,7 +132,7 @@ func (g *GameInterface) RenameItemByAnvil(
Slot: value.Slot,
},
ItemLocation{
WindowID: containerOpeningData.WindowID,
WindowID: container_opening_data.WindowID,
ContainerID: 0x0,
Slot: 1,
},
Expand All @@ -155,7 +155,7 @@ func (g *GameInterface) RenameItemByAnvil(
continue
}
// 移动物品到铁砧
backup, err := g.Resources.Inventory.GetItemStackInfo(uint32(containerOpeningData.WindowID), 1)
backup, err := g.Resources.Inventory.GetItemStackInfo(uint32(container_opening_data.WindowID), 1)
if err != nil {
panic(fmt.Errorf("RenameItemByAnvil: %v", err))
}
Expand All @@ -172,7 +172,7 @@ func (g *GameInterface) RenameItemByAnvil(
Slot: 1,
StackNetworkID: backup.StackNetworkID,
},
uint32(containerOpeningData.WindowID),
uint32(container_opening_data.WindowID),
)
if err != nil {
panic(fmt.Sprintf("RenameItemByAnvil: %v", err))
Expand Down
15 changes: 9 additions & 6 deletions game_control/game_interface/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ func (g *GameInterface) send_command_with_options(
options ResourcesControl.CommandRequestOptions,
origin *uint32,
) *ResourcesControl.CommandRespond {
var command_type string
var err error
command_request_id := ResourcesControl.GenerateUUID()
// 初始化
{
var command_type string
// 初始化
switch origin {
case nil:
command_type = ResourcesControl.CommandTypeAICommand
Expand All @@ -158,10 +159,6 @@ func (g *GameInterface) send_command_with_options(
}
}
// 写入请求
if origin != nil {
command_type = ResourcesControl.CommandTypeStandard
}
// 恢复微调
}
// 写入请求到等待队列
switch origin {
Expand All @@ -187,6 +184,8 @@ func (g *GameInterface) send_command_with_options(
}
// 加载响应体
if args.SkipMCPCheckChallenges && origin != nil {
resp.Type = ResourcesControl.CommandTypeStandard
// 覆写原始命令请求的类型
switch resp.Respond {
case nil:
fake_resp := DefaultCommandOutput
Expand All @@ -206,6 +205,7 @@ func (g *GameInterface) send_command_with_options(
default:
resp.Respond.CommandOrigin.Origin = *origin
}
// 覆写 命令来源 和 命令输出 相关的字段
switch *origin {
case protocol.CommandOriginAutomationPlayer:
resp.Respond.CommandOrigin.RequestID = DefaultCommandRequestID
Expand All @@ -215,6 +215,7 @@ func (g *GameInterface) send_command_with_options(
resp.Respond.OutputType = packet.CommandOutputTypeNone
resp.Respond.DataSet = ""
}
// 覆写 请求ID、输出类型 和 数据集
}
// 针对限制性情况的响应体微调
return &resp
Expand Down Expand Up @@ -261,8 +262,10 @@ func (g *GameInterface) SendWSCommand(command string) error {

// 向租赁服发送 魔法指令 且无视返回值
func (g *GameInterface) SendAICommand(command string) error {
holder := g.Resources.Command.Occupy()
defer g.Resources.Command.Release(holder)
uniqueId, _ := uuid.NewUUID()
// get command request id
// prepare
err := g.Resources.Command.WriteRequest(
uniqueId,
ResourcesControl.CommandRequestOptions{
Expand Down
18 changes: 9 additions & 9 deletions game_control/game_interface/game_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,23 @@ const (

// 描述各个维度的 ID
const (
OverWorldID = byte(iota) // 主世界
NetherID // 下界
EndID // 末地
OverWorldID = byte(iota)
NetherID
EndID
)

// 描述各个维度可放置方块的最高高度
const (
OverWorld_MaxPosy = int32(319) // 主世界
Nether_MaxPosy = int32(127) // 下界
End_MaxPosy = int32(255) // 末地
OverWorld_MaxPosy = int32(319)
Nether_MaxPosy = int32(127)
End_MaxPosy = int32(255)
)

// 描述各个维度可放置方块的最低高度
const (
OverWorld_MinPosy = int32(-64) // 主世界
Nether_MinPosy = int32(0) // 下界
End_MinPosy // 末地
OverWorld_MinPosy = int32(-64)
Nether_MinPosy = int32(0)
End_MinPosy
)

// 描述一个默认状态下的
Expand Down
16 changes: 8 additions & 8 deletions game_control/game_interface/item_renaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func (g *GameInterface) RenameItem(
name string,
slot uint8,
) (*AnvilOperationResponse, error) {
containerOpeningData := g.Resources.Container.GetContainerOpeningData()
container_opening_data := g.Resources.Container.GetContainerOpeningData()
// 取得已打开的容器的数据
if containerOpeningData == nil {
if container_opening_data == nil {
return nil, fmt.Errorf("RenameItem: Anvil has not opened")
}
// 如果铁砧未被打开
get, err := g.Resources.Inventory.GetItemStackInfo(
uint32(containerOpeningData.WindowID),
uint32(container_opening_data.WindowID),
1,
)
if err != nil {
Expand Down Expand Up @@ -113,7 +113,7 @@ func (g *GameInterface) RenameItem(
{
Details: map[ResourcesControl.ContainerID]ResourcesControl.StackRequestContainerInfo{
0x0: {
WindowID: uint32(containerOpeningData.WindowID),
WindowID: uint32(container_opening_data.WindowID),
ChangeResult: map[uint8]protocol.ItemInstance{
1: AirItem,
},
Expand Down Expand Up @@ -148,7 +148,7 @@ func (g *GameInterface) RenameItem(
return &AnvilOperationResponse{
Successful: false,
Destination: &ItemLocation{
WindowID: containerOpeningData.WindowID,
WindowID: container_opening_data.WindowID,
ContainerID: 0,
Slot: 1,
},
Expand Down Expand Up @@ -221,19 +221,19 @@ func (g *GameInterface) RenameItem(
},
},
0x0: {
WindowID: uint32(containerOpeningData.WindowID),
WindowID: uint32(container_opening_data.WindowID),
ChangeResult: map[uint8]protocol.ItemInstance{
1: AirItem,
},
},
0x1: {
WindowID: uint32(containerOpeningData.WindowID),
WindowID: uint32(container_opening_data.WindowID),
ChangeResult: map[uint8]protocol.ItemInstance{
2: AirItem,
},
},
0x3c: {
WindowID: uint32(containerOpeningData.WindowID),
WindowID: uint32(container_opening_data.WindowID),
ChangeResult: map[uint8]protocol.ItemInstance{
0x32: AirItem,
},
Expand Down
14 changes: 7 additions & 7 deletions game_control/resources_control/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ request_type 指代原始的命令请求的类型,
options 指定当次命令请求的自定义设置项
*/
func (c *commandRequestWithResponse) WriteRequest(
func (c *command_request_with_response) WriteRequest(
key uuid.UUID,
options CommandRequestOptions,
request_type string,
Expand Down Expand Up @@ -57,7 +57,7 @@ func (c *commandRequestWithResponse) WriteRequest(
// 尝试向请求 ID 为 key 的命令请求写入返回值 resp 。
// 属于私有实现。
// 如果 key 不存在,亦不会返回错误
func (c *commandRequestWithResponse) try_to_write_response(
func (c *command_request_with_response) try_to_write_response(
key uuid.UUID,
resp packet.CommandOutput,
) error {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (c *commandRequestWithResponse) try_to_write_response(
// 如果响应体对应的命令请求未被找到,
// 则会造成程序 panic 。
// 属于私有实现
func (c *commandRequestWithResponse) on_ai_command(event stc_mc.AICommand) {
func (c *command_request_with_response) on_ai_command(event stc_mc.AICommand) {
defer func() {
c.ai_command_resp = nil
}()
Expand All @@ -103,7 +103,7 @@ func (c *commandRequestWithResponse) on_ai_command(event stc_mc.AICommand) {
resp, exist0 := c.response.Load(e.CommandRequestID)
channel, exist1 := c.signal.Load(e.CommandRequestID)
if !exist0 || !exist1 {
panic("on_ai_command: Attempt to send NeteaseAICommand(packet.PyRpc/CS2ModEvent/ExecuteCommandEvent) without using ResourcesControlCenter")
panic("on_ai_command: Attempt to send NeteaseAICommand(packet.PyRpc/ModEventCS2/ExecuteCommandEvent) without using ResourcesControlCenter")
}
// load data by command request id
if resp.Respond == nil && c.ai_command_resp != nil {
Expand Down Expand Up @@ -135,7 +135,7 @@ func (c *commandRequestWithResponse) on_ai_command(event stc_mc.AICommand) {
// get the oldest ai command request and release lock
channel, exist := c.signal.Load(command_request_id)
if resp == nil || !exist {
panic("on_ai_command: Attempt to send NeteaseAICommand(packet.PyRpc/CS2ModEvent/ExecuteCommandEvent) without using ResourcesControlCenter")
panic("on_ai_command: Attempt to send NeteaseAICommand(packet.PyRpc/ModEventCS2/ExecuteCommandEvent) without using ResourcesControlCenter")
}
// load data and check
resp.AICommand.PreCheckError = e
Expand All @@ -153,7 +153,7 @@ func (c *commandRequestWithResponse) on_ai_command(event stc_mc.AICommand) {
resp, exist0 := c.response.Load(e.CommandRequestID)
channel, exist1 := c.signal.Load(e.CommandRequestID)
if options == nil || !exist0 || !exist1 {
panic("on_ai_command: Attempt to send NeteaseAICommand(packet.PyRpc/CS2ModEvent/ExecuteCommandEvent) without using ResourcesControlCenter")
panic("on_ai_command: Attempt to send NeteaseAICommand(packet.PyRpc/ModEventCS2/ExecuteCommandEvent) without using ResourcesControlCenter")
}
// load data from command request id
if resp.Respond == nil && c.ai_command_resp != nil {
Expand All @@ -174,7 +174,7 @@ func (c *commandRequestWithResponse) on_ai_command(event stc_mc.AICommand) {

// 读取请求 ID 为 key 的命令请求的响应体,
// 同时移除此命令请求
func (c *commandRequestWithResponse) LoadResponseAndDelete(key uuid.UUID) CommandRespond {
func (c *command_request_with_response) LoadResponseAndDelete(key uuid.UUID) CommandRespond {
c.request_lock.RLock()
options := c.request.GetElement(key)
c.request_lock.RUnlock()
Expand Down
Loading

0 comments on commit 9c6c09c

Please sign in to comment.