Implement FastMap CPE extension

This commit is contained in:
UnknownShadow200 2018-04-01 13:10:38 +10:00
parent 76d2196464
commit 5d401d66ce
8 changed files with 33 additions and 15 deletions

View File

@ -8,7 +8,7 @@ using OpenTK.Input;
namespace ClassicalSharp.Gui.Screens {
// TODO: Hotkey added event for CPE
public sealed class HotkeyListScreen : FilesScreen {
public sealed class HotkeyListScreen : ListScreen {
public HotkeyListScreen(Game game) : base(game) {
titleText = "Modify hotkeys";

View File

@ -5,9 +5,9 @@ using ClassicalSharp.Gui.Widgets;
using OpenTK.Input;
namespace ClassicalSharp.Gui.Screens {
public abstract class FilesScreen : ClickableScreen {
public abstract class ListScreen : ClickableScreen {
public FilesScreen(Game game) : base(game) {
public ListScreen(Game game) : base(game) {
HandlesAllInput = true;
}

View File

@ -9,7 +9,7 @@ using OpenTK.Input;
using BlockID = System.UInt16;
namespace ClassicalSharp.Gui.Screens {
public sealed class LoadLevelScreen : FilesScreen {
public sealed class LoadLevelScreen : ListScreen {
public LoadLevelScreen(Game game) : base(game) {
titleText = "Select a level";

View File

@ -6,7 +6,7 @@ using ClassicalSharp.Textures;
using OpenTK.Input;
namespace ClassicalSharp.Gui.Screens {
public sealed class TexturePackScreen : FilesScreen {
public sealed class TexturePackScreen : ListScreen {
public TexturePackScreen(Game game) : base(game) {
titleText = "Select a texture pack zip";

View File

@ -4,7 +4,7 @@
<ProjectGuid>{BEB1C785-5CAD-48FF-A886-876BF0A318D4}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<RootNamespace>ClassicalSharp</RootNamespace>
<AssemblyName>ClassicalSharp</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
@ -84,10 +84,10 @@
<Compile Include="2D\Drawing\GdiPlusDrawer2D.cs" />
<Compile Include="2D\Drawing\IDrawer2D.cs" />
<Compile Include="2D\Screens\ChatScreen.cs" />
<Compile Include="2D\Screens\ClickableScreen.cs" />
<Compile Include="2D\Screens\DeathScreen.cs" />
<Compile Include="2D\Screens\DisconnectScreen.cs" />
<Compile Include="2D\Screens\InventoryScreen.cs" />
<Compile Include="2D\Screens\Menu\ClickableScreen.cs" />
<Compile Include="2D\Screens\Overlays\Overlay.cs" />
<Compile Include="2D\Screens\Overlays\TexIdsOverlay.cs" />
<Compile Include="2D\Screens\Overlays\WarningOverlays.cs" />
@ -97,7 +97,7 @@
<Compile Include="2D\Screens\Menu\ClassicOptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\EditHotkeyScreen.cs" />
<Compile Include="2D\Screens\Menu\EnvSettingsScreen.cs" />
<Compile Include="2D\Screens\Menu\FilesScreen.cs" />
<Compile Include="2D\Screens\Menu\ListScreen.cs" />
<Compile Include="2D\Screens\Menu\GenLevelScreen.cs" />
<Compile Include="2D\Screens\Menu\GraphicsOptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\GuiOptionsScreen.cs" />

View File

@ -15,14 +15,14 @@ namespace ClassicalSharp.Network {
internal int ServerExtensionsCount;
internal bool sendHeldBlock, useMessageTypes;
internal int envMapVer = 2, blockDefsExtVer = 2;
internal bool needD3Fix, extEntityPos, twoWayPing, blockPerms;
internal bool needD3Fix, extEntityPos, twoWayPing, blockPerms, fastMap;
Game game;
public void Reset(Game game) {
ServerExtensionsCount = 0;
sendHeldBlock = false; useMessageTypes = false;
envMapVer = 2; blockDefsExtVer = 2;
needD3Fix = false; extEntityPos = false; twoWayPing = false;
needD3Fix = false; extEntityPos = false; twoWayPing = false; fastMap = false;
game.SupportsCPEBlocks = false;
NetworkProcessor net = (NetworkProcessor)game.Server;
net.Reset();
@ -65,6 +65,9 @@ namespace ClassicalSharp.Network {
net.writer.ExtendedPositions = true;
} else if (ext == "TwoWayPing") {
twoWayPing = true;
} else if (ext == "FastMap") {
net.packetSizes[Opcode.LevelInit] += 4;
fastMap = true;
}
#if USE16_BIT
else if (ext == "ExtBlocks") {
@ -93,9 +96,9 @@ namespace ClassicalSharp.Network {
public static string[] ClientExtensions = new string[] {
"ClickDistance", "CustomBlocks", "HeldBlock", "EmoteFix", "TextHotKey", "ExtPlayerList",
"EnvColors", "SelectionCuboid", "BlockPermissions", "ChangeModel", "EnvMapAppearance",
"EnvWeatherType", "MessageTypes", "HackControl", "PlayerClick", "FullCP437",
"LongerMessages", "BlockDefinitions", "BlockDefinitionsExt", "BulkBlockUpdate", "TextColors",
"EnvMapAspect", "EntityProperty", "ExtEntityPositions", "TwoWayPing", "InventoryOrder", "InstantMOTD",
"EnvWeatherType", "MessageTypes", "HackControl", "PlayerClick", "FullCP437", "LongerMessages",
"BlockDefinitions", "BlockDefinitionsExt", "BulkBlockUpdate", "TextColors", "EnvMapAspect",
"EntityProperty", "ExtEntityPositions", "TwoWayPing", "InventoryOrder", "InstantMOTD", "FastMap",
#if USE16_BIT
"ExtBlocks",
#endif

View File

@ -67,7 +67,21 @@ namespace ClassicalSharp.Network.Protocols {
void HandlePing() { }
void HandleLevelInit() {
if (gzipStream != null) return;
if (gzipStream == null) StartLoadingState();
// Fast map puts volume in header, doesn't bother with gzip
if (net.cpeData.fastMap) {
int size = reader.ReadInt32();
gzipHeader.done = true;
mapSizeIndex = 4;
#if USE16_BIT
if (reader.ExtendedBlocks) size *= 2;
#endif
map = new byte[size];
}
}
void StartLoadingState() {
game.World.Reset();
game.WorldEvents.RaiseOnNewMap();
@ -101,7 +115,8 @@ namespace ClassicalSharp.Network.Protocols {
void HandleLevelDataChunk() {
// Workaround for some servers that send LevelDataChunk before LevelInit
// due to their async packet sending behaviour.
if (gzipStream == null) HandleLevelInit();
if (gzipStream == null) StartLoadingState();
int usedLength = reader.ReadUInt16();
gzippedMap.pos = 0;
gzippedMap.bufferPos = reader.index;