From 4f5a876b577c5a5f41c1098ac1f05a1f825dd584 Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 29 Jul 2023 17:25:28 +1000 Subject: [PATCH] Revert "simplify and expand Stage Object indexer" This reverts commit 19e1eae5e2fc3302bd3639c92a642f45ca00bb6c. --- server/channelserver/sys_stage.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/server/channelserver/sys_stage.go b/server/channelserver/sys_stage.go index 7b8fb15eb..b69995724 100644 --- a/server/channelserver/sys_stage.go +++ b/server/channelserver/sys_stage.go @@ -30,7 +30,7 @@ type Stage struct { // Objects objects map[uint32]*Object - objectIndex uint16 + objectIndex uint8 // Map of session -> charID. // These are clients that are CURRENTLY in the stage @@ -56,6 +56,7 @@ func NewStage(ID string) *Stage { clients: make(map[*Session]uint32), reservedClientSlots: make(map[uint32]bool), objects: make(map[uint32]*Object), + objectIndex: 0, rawBinaryData: make(map[stageBinaryKey][]byte), maxPlayers: 4, } @@ -96,10 +97,16 @@ func (s *Stage) isQuest() bool { } func (s *Stage) NextObjectID() uint32 { - s.objectIndex++ + s.objectIndex = s.objectIndex + 1 + // Objects beyond 127 do not duplicate correctly + // Indexes 0 and 127 does not update position correctly + if s.objectIndex == 127 { + s.objectIndex = 1 + } bf := byteframe.NewByteFrame() - bf.WriteUint16(127) - bf.WriteUint16(s.objectIndex) - bf.Seek(0, 0) - return bf.ReadUint32() + bf.WriteUint8(0) + bf.WriteUint8(s.objectIndex) + bf.WriteUint16(0) + obj := uint32(bf.Data()[3]) | uint32(bf.Data()[2])<<8 | uint32(bf.Data()[1])<<16 | uint32(bf.Data()[0])<<24 + return obj }