scriptsdk / CSharp-ScriptSDK-Legacy

ScriptSDK is an advanced extension written in .NET. The framework is based on a local tcp socket protocol library written by maxwell and extend the provided architecture by additional methods and handlers.
GNU General Public License v3.0
9 stars 11 forks source link

Weird tile ID from ReadStaticsXY #20

Closed Bosek closed 6 years ago

Bosek commented 6 years ago

I am getting really weird tile IDs from Stealth.Client.ReadStatics.XY method. infotile says it's ID 3299 (=>CE3), but from the method I get 920C (=>37388). I was thinking there is maybe an offset, but nope.


for (ushort y = (ushort)minY; y < maxY + 1; y++)  
{  
  for (ushort x = (ushort)minX; x < maxX + 1; x++)  
  {  
    var staticTiles = Stealth.Client.ReadStaticsXY(x, y, worldNum);  
    foreach (var staticTile in staticTiles)  
    {  
      if (TreeIDs.Contains(staticTile.Tile))  
      {  
         var position = new Point2D(staticTile.X, staticTile.Y);  
         if (!isKnownTree(position))  
           ScannedTrees.Add(position);  
      }  
    }  
  }  
}
Bosek commented 6 years ago

After a bit of fiddling I've found out that the information is properly sent by the server(Stealth), but the packet is different than expected(X,Y,Z make no sense). I forgot to mention that I am using Stealth v8.8.0 and I guess dev changed something. Sadly the Stealth wiki is horrible. Every language version has different information(EN version saying, that X and Y are bytes, RU version says that they are shorts).

Stealth is obviously no longer sending Packet SCReadStaticsXY with amount of items. So in order to calculate it, I had to manually specify block size and divide.

case PacketType.SCReadStaticsXY:
  var dataSize = 9;
  itemCount = (uint)(barray.Length / dataSize);
  break;

And it works like a charm. Is it ideal solution though? Should I create a PR? I am not sure if it's behaviour new to Stealth 8.8 or it was just untested.