From 67395247f2c2921c9e48f533ff3d2770d8e6e8f4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 12 May 2016 09:40:02 +1000 Subject: [PATCH] Initial work on EnvMapAppearance version 3. --- ClassicalSharp/Network/CPESupport.cs | 8 +-- ClassicalSharp/Network/Enums.cs | 4 +- .../Network/NetworkProcessor.CPE.cs | 71 +++++++++++-------- .../Network/NetworkProcessor.CPECustom.cs | 18 ++--- ClassicalSharp/Network/NetworkProcessor.cs | 42 +++++------ 5 files changed, 79 insertions(+), 64 deletions(-) diff --git a/ClassicalSharp/Network/CPESupport.cs b/ClassicalSharp/Network/CPESupport.cs index f4ff55ccd..3226876de 100644 --- a/ClassicalSharp/Network/CPESupport.cs +++ b/ClassicalSharp/Network/CPESupport.cs @@ -29,9 +29,9 @@ namespace ClassicalSharp.Network { network.ServerSupportsFullCP437 = false; network.Set( Opcode.CpeEnvSetMapApperance, - network.HandleCpeEnvSetMapAppearance, 69 ); + network.HandleEnvSetMapAppearance, 69 ); network.Set( Opcode.CpeDefineBlockExt, - network.HandleCpeDefineBlockExt, 85 ); + network.HandleDefineBlockExt, 85 ); } /// Sets fields / updates network handles based on the server @@ -51,7 +51,7 @@ namespace ClassicalSharp.Network { envMapVer = version; if( version == 1 ) return; network.Set( Opcode.CpeEnvSetMapApperance, - network.HandleCpeEnvSetMapAppearance2, 73 ); + network.HandleEnvSetMapAppearance2, 73 ); } else if( ext == "LongerMessages" ) { network.ServerSupportsPartialMessages = true; } else if( ext == "FullCP437" ) { @@ -60,7 +60,7 @@ namespace ClassicalSharp.Network { blockDefsExtVer = version; if( version == 1 ) return; network.Set( Opcode.CpeDefineBlockExt, - network.HandleCpeDefineBlockExt, 88 ); + network.HandleDefineBlockExt, 88 ); } } diff --git a/ClassicalSharp/Network/Enums.cs b/ClassicalSharp/Network/Enums.cs index c0120863c..91cf5fb02 100644 --- a/ClassicalSharp/Network/Enums.cs +++ b/ClassicalSharp/Network/Enums.cs @@ -45,7 +45,9 @@ namespace ClassicalSharp.Network { CpeDefineBlockExt = 37, CpeBulkBlockUpdate = 38, CpeSetTextColor = 39, - CpeDefineModel = 40, + CpeSetMapEnvUrl = 40, + CpeSetMapEnvProperty = 41, + CpeDefineModel = 42, } } diff --git a/ClassicalSharp/Network/NetworkProcessor.CPE.cs b/ClassicalSharp/Network/NetworkProcessor.CPE.cs index a7cc2c809..58ab0503d 100644 --- a/ClassicalSharp/Network/NetworkProcessor.CPE.cs +++ b/ClassicalSharp/Network/NetworkProcessor.CPE.cs @@ -57,7 +57,7 @@ namespace ClassicalSharp.Network { #region Reading - internal void HandleCpeExtInfo() { + internal void HandleExtInfo() { string appName = reader.ReadAsciiString(); game.Chat.Add( "Server software: " + appName ); if( Utils.CaselessStarts( appName, "D3 server" ) ) @@ -69,7 +69,7 @@ namespace ClassicalSharp.Network { SendCpeExtInfoReply(); } - internal void HandleCpeExtEntry() { + internal void HandleExtEntry() { string extName = reader.ReadAsciiString(); int extVersion = reader.ReadInt32(); Utils.LogDebug( "cpe ext: {0}, {1}", extName, extVersion ); @@ -99,11 +99,11 @@ namespace ClassicalSharp.Network { } } - internal void HandleCpeSetClickDistance() { + internal void HandleSetClickDistance() { game.LocalPlayer.ReachDistance = reader.ReadInt16() / 32f; } - internal void HandleCpeCustomBlockSupportLevel() { + internal void HandleCustomBlockSupportLevel() { byte supportLevel = reader.ReadUInt8(); MakeCustomBlockSupportLevel( 1 ); SendPacket(); @@ -121,7 +121,7 @@ namespace ClassicalSharp.Network { } } - internal void HandleCpeHoldThis() { + internal void HandleHoldThis() { byte blockType = reader.ReadUInt8(); bool canChange = reader.ReadUInt8() == 0; game.Inventory.CanChangeHeldBlock = true; @@ -129,7 +129,7 @@ namespace ClassicalSharp.Network { game.Inventory.CanChangeHeldBlock = canChange; } - internal void HandleCpeSetTextHotkey() { + internal void HandleSetTextHotkey() { string label = reader.ReadAsciiString(); string action = reader.ReadCp437String(); int keyCode = reader.ReadInt32(); @@ -150,7 +150,7 @@ namespace ClassicalSharp.Network { } } - internal void HandleCpeExtAddPlayerName() { + internal void HandleExtAddPlayerName() { short nameId = reader.ReadInt16(); string playerName = Utils.StripColours( reader.ReadAsciiString() ); playerName = Utils.RemoveEndPlus( playerName ); @@ -182,7 +182,7 @@ namespace ClassicalSharp.Network { } } - internal void HandleCpeExtAddEntity() { + internal void HandleExtAddEntity() { byte entityId = reader.ReadUInt8(); string displayName = reader.ReadAsciiString(); displayName = Utils.RemoveEndPlus( displayName ); @@ -191,7 +191,7 @@ namespace ClassicalSharp.Network { AddEntity( entityId, displayName, skinName, false ); } - internal void HandleCpeExtRemovePlayerName() { + internal void HandleExtRemovePlayerName() { short nameId = reader.ReadInt16(); // Workaround for some servers that don't cast signed bytes to unsigned, before converting them to shorts. if( nameId < 0 ) @@ -203,7 +203,7 @@ namespace ClassicalSharp.Network { } } - internal void HandleCpeMakeSelection() { + internal void HandleMakeSelection() { byte selectionId = reader.ReadUInt8(); string label = reader.ReadAsciiString(); short startX = reader.ReadInt16(); @@ -224,12 +224,12 @@ namespace ClassicalSharp.Network { game.SelectionManager.AddSelection( selectionId, p1, p2, col ); } - internal void HandleCpeRemoveSelection() { + internal void HandleRemoveSelection() { byte selectionId = reader.ReadUInt8(); game.SelectionManager.RemoveSelection( selectionId ); } - internal void HandleCpeEnvColours() { + internal void HandleEnvColours() { byte variable = reader.ReadUInt8(); short red = reader.ReadInt16(); short green = reader.ReadInt16(); @@ -250,7 +250,7 @@ namespace ClassicalSharp.Network { } } - internal void HandleCpeSetBlockPermission() { + internal void HandleSetBlockPermission() { byte blockId = reader.ReadUInt8(); bool canPlace = reader.ReadUInt8() != 0; bool canDelete = reader.ReadUInt8() != 0; @@ -270,41 +270,33 @@ namespace ClassicalSharp.Network { game.Events.RaiseBlockPermissionsChanged(); } - internal void HandleCpeChangeModel() { + internal void HandleChangeModel() { byte playerId = reader.ReadUInt8(); string modelName = reader.ReadAsciiString().ToLowerInvariant(); Player player = game.Players[playerId]; if( player != null ) player.SetModel( modelName ); } - internal void HandleCpeEnvSetMapAppearance() { - string url = reader.ReadAsciiString(); + internal void HandleEnvSetMapAppearance() { + HandleSetEnvMapUrl(); game.World.Env.SetSidesBlock( (Block)reader.ReadUInt8() ); game.World.Env.SetEdgeBlock( (Block)reader.ReadUInt8() ); game.World.Env.SetEdgeLevel( reader.ReadInt16() ); - if( !game.AllowServerTextures ) return; - - if( url == "" ) { - ExtractDefault(); - } else if( Utils.IsUrlPrefix( url, 0 ) ) { - RetrieveTexturePack( url ); - } - Utils.LogDebug( "Image url: " + url ); } - internal void HandleCpeEnvSetMapAppearance2() { - HandleCpeEnvSetMapAppearance(); + internal void HandleEnvSetMapAppearance2() { + HandleEnvSetMapAppearance(); game.World.Env.SetCloudsLevel( reader.ReadInt16() ); short maxViewDist = reader.ReadInt16(); game.MaxViewDistance = maxViewDist <= 0 ? 32768 : maxViewDist; game.SetViewDistance( game.UserViewDistance, false ); } - internal void HandleCpeEnvWeatherType() { + internal void HandleEnvWeatherType() { game.World.Env.SetWeather( (Weather)reader.ReadUInt8() ); } - internal void HandleCpeHackControl() { + internal void HandleHackControl() { LocalPlayer p = game.LocalPlayer; p.Hacks.CanFly = reader.ReadUInt8() != 0; p.Hacks.CanNoclip = reader.ReadUInt8() != 0; @@ -320,7 +312,7 @@ namespace ClassicalSharp.Network { game.Events.RaiseHackPermissionsChanged(); } - internal void HandleCpeExtAddEntity2() { + internal void HandleExtAddEntity2() { byte entityId = reader.ReadUInt8(); string displayName = reader.ReadAsciiString(); string skinName = reader.ReadAsciiString(); @@ -369,6 +361,27 @@ namespace ClassicalSharp.Network { game.Drawer2D.Colours[code] = col; game.Events.RaiseColourCodesChanged(); } + + internal void HandleSetEnvMapUrl() { + string url = reader.ReadAsciiString(); + if( !game.AllowServerTextures ) return; + + if( url == "" ) { + ExtractDefault(); + } else if( Utils.IsUrlPrefix( url, 0 ) ) { + RetrieveTexturePack( url ); + } + Utils.LogDebug( "Image url: " + url ); + } + + internal void HandleSetEnvMapProperty() { + byte type = reader.ReadUInt8(); + int value = reader.ReadInt32(); + + switch( type ) { + // TODO: Property list + } + } } #endregion } \ No newline at end of file diff --git a/ClassicalSharp/Network/NetworkProcessor.CPECustom.cs b/ClassicalSharp/Network/NetworkProcessor.CPECustom.cs index 642f59117..604106b8e 100644 --- a/ClassicalSharp/Network/NetworkProcessor.CPECustom.cs +++ b/ClassicalSharp/Network/NetworkProcessor.CPECustom.cs @@ -7,11 +7,11 @@ namespace ClassicalSharp.Network { public partial class NetworkProcessor : INetworkProcessor { - internal void HandleCpeDefineBlock() { + internal void HandleDefineBlock() { if( !game.AllowCustomBlocks ) { SkipPacketData( Opcode.CpeDefineBlock ); return; } - byte id = HandleCpeDefineBlockCommonStart( false ); + byte id = HandleDefineBlockCommonStart( false ); BlockInfo info = game.BlockInfo; byte shape = reader.ReadUInt8(); if( shape == 0 ) { @@ -22,7 +22,7 @@ namespace ClassicalSharp.Network { info.MaxBB[id].Y = shape / 16f; } - HandleCpeDefineBlockCommonEnd( id ); + HandleDefineBlockCommonEnd( id ); // Update sprite BoundingBox if necessary if( info.IsSprite[id] ) { using( FastBitmap dst = new FastBitmap( game.TerrainAtlas.AtlasBitmap, true, true ) ) @@ -31,7 +31,7 @@ namespace ClassicalSharp.Network { info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F)); } - internal void HandleCpeRemoveBlockDefinition() { + internal void HandleRemoveBlockDefinition() { if( !game.AllowCustomBlocks ) { SkipPacketData( Opcode.CpeRemoveBlockDefinition ); return; } @@ -40,11 +40,11 @@ namespace ClassicalSharp.Network { game.Events.RaiseBlockDefinitionChanged(); } - internal void HandleCpeDefineBlockExt() { + internal void HandleDefineBlockExt() { if( !game.AllowCustomBlocks ) { SkipPacketData( Opcode.CpeDefineBlockExt ); return; } - byte id = HandleCpeDefineBlockCommonStart( cpe.blockDefsExtVer >= 2 ); + byte id = HandleDefineBlockCommonStart( cpe.blockDefsExtVer >= 2 ); BlockInfo info = game.BlockInfo; Vector3 min, max; @@ -57,11 +57,11 @@ namespace ClassicalSharp.Network { info.MinBB[id] = min; info.MaxBB[id] = max; - HandleCpeDefineBlockCommonEnd( id ); + HandleDefineBlockCommonEnd( id ); info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F)); } - byte HandleCpeDefineBlockCommonStart( bool uniqueSideTexs ) { + byte HandleDefineBlockCommonStart( bool uniqueSideTexs ) { byte block = reader.ReadUInt8(); BlockInfo info = game.BlockInfo; info.ResetBlockInfo( block, false ); @@ -95,7 +95,7 @@ namespace ClassicalSharp.Network { return block; } - internal void HandleCpeDefineBlockCommonEnd( byte block ) { + internal void HandleDefineBlockCommonEnd( byte block ) { BlockInfo info = game.BlockInfo; byte blockDraw = reader.ReadUInt8(); SetBlockDraw( info, block, blockDraw ); diff --git a/ClassicalSharp/Network/NetworkProcessor.cs b/ClassicalSharp/Network/NetworkProcessor.cs index e264a5aaf..02e313ea5 100644 --- a/ClassicalSharp/Network/NetworkProcessor.cs +++ b/ClassicalSharp/Network/NetworkProcessor.cs @@ -176,30 +176,30 @@ namespace ClassicalSharp.Network { Set( Opcode.Kick, HandleKick, 65 ); Set( Opcode.SetPermission, HandleSetPermission, 2 ); - Set( Opcode.CpeExtInfo, HandleCpeExtInfo, 67 ); - Set( Opcode.CpeExtEntry, HandleCpeExtEntry, 69 ); - Set( Opcode.CpeSetClickDistance, HandleCpeSetClickDistance, 3 ); - Set( Opcode.CpeCustomBlockSupportLevel, HandleCpeCustomBlockSupportLevel, 2 ); - Set( Opcode.CpeHoldThis, HandleCpeHoldThis, 3 ); - Set( Opcode.CpeSetTextHotkey, HandleCpeSetTextHotkey, 134 ); + Set( Opcode.CpeExtInfo, HandleExtInfo, 67 ); + Set( Opcode.CpeExtEntry, HandleExtEntry, 69 ); + Set( Opcode.CpeSetClickDistance, HandleSetClickDistance, 3 ); + Set( Opcode.CpeCustomBlockSupportLevel, HandleCustomBlockSupportLevel, 2 ); + Set( Opcode.CpeHoldThis, HandleHoldThis, 3 ); + Set( Opcode.CpeSetTextHotkey, HandleSetTextHotkey, 134 ); - Set( Opcode.CpeExtAddPlayerName, HandleCpeExtAddPlayerName, 196 ); - Set( Opcode.CpeExtAddEntity, HandleCpeExtAddEntity, 130 ); - Set( Opcode.CpeExtRemovePlayerName, HandleCpeExtRemovePlayerName, 3 ); + Set( Opcode.CpeExtAddPlayerName, HandleExtAddPlayerName, 196 ); + Set( Opcode.CpeExtAddEntity, HandleExtAddEntity, 130 ); + Set( Opcode.CpeExtRemovePlayerName, HandleExtRemovePlayerName, 3 ); - Set( Opcode.CpeEnvColours, HandleCpeEnvColours, 8 ); - Set( Opcode.CpeMakeSelection, HandleCpeMakeSelection, 86 ); - Set( Opcode.CpeRemoveSelection, HandleCpeRemoveSelection, 2 ); - Set( Opcode.CpeSetBlockPermission, HandleCpeSetBlockPermission, 4 ); - Set( Opcode.CpeChangeModel, HandleCpeChangeModel, 66 ); - Set( Opcode.CpeEnvSetMapApperance, HandleCpeEnvSetMapAppearance, 69 ); - Set( Opcode.CpeEnvWeatherType, HandleCpeEnvWeatherType, 2 ); - Set( Opcode.CpeHackControl, HandleCpeHackControl, 8 ); - Set( Opcode.CpeExtAddEntity2, HandleCpeExtAddEntity2, 138 ); + Set( Opcode.CpeEnvColours, HandleEnvColours, 8 ); + Set( Opcode.CpeMakeSelection, HandleMakeSelection, 86 ); + Set( Opcode.CpeRemoveSelection, HandleRemoveSelection, 2 ); + Set( Opcode.CpeSetBlockPermission, HandleSetBlockPermission, 4 ); + Set( Opcode.CpeChangeModel, HandleChangeModel, 66 ); + Set( Opcode.CpeEnvSetMapApperance, HandleEnvSetMapAppearance, 69 ); + Set( Opcode.CpeEnvWeatherType, HandleEnvWeatherType, 2 ); + Set( Opcode.CpeHackControl, HandleHackControl, 8 ); + Set( Opcode.CpeExtAddEntity2, HandleExtAddEntity2, 138 ); - Set( Opcode.CpeDefineBlock, HandleCpeDefineBlock, 80 ); - Set( Opcode.CpeRemoveBlockDefinition, HandleCpeRemoveBlockDefinition, 2 ); - Set( Opcode.CpeDefineBlockExt, HandleCpeDefineBlockExt, 85 ); + Set( Opcode.CpeDefineBlock, HandleDefineBlock, 80 ); + Set( Opcode.CpeRemoveBlockDefinition, HandleRemoveBlockDefinition, 2 ); + Set( Opcode.CpeDefineBlockExt, HandleDefineBlockExt, 85 ); Set( Opcode.CpeBulkBlockUpdate, HandleBulkBlockUpdate, 1282 ); Set( Opcode.CpeSetTextColor, HandleSetTextColor, 6 ); }