mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-23 20:57:12 -04:00
Fix SetPermission sent before Handshake crashing client
This commit is contained in:
parent
f96b767314
commit
dccef50a90
@ -134,6 +134,8 @@ namespace ClassicalSharp.Entities {
|
||||
/// <remarks> Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax, and horspeed=xyz </remarks>
|
||||
public void UpdateHacksState() {
|
||||
SetAllHacks(true);
|
||||
if (HacksFlags == null) return;
|
||||
|
||||
MaxSpeedMultiplier = 1;
|
||||
// By default (this is also the case with WoM), we can use hacks.
|
||||
if (HacksFlags.Contains("-hax")) SetAllHacks(false);
|
||||
|
@ -71,11 +71,11 @@ namespace ClassicalSharp.Map {
|
||||
|
||||
nbt.Write(NbtTagType.Int8);
|
||||
nbt.Write("H");
|
||||
nbt.WriteUInt8((byte)Utils.DegreesToPacked(p.SpawnRotY));
|
||||
nbt.WriteUInt8(Utils.DegreesToPacked(p.SpawnRotY));
|
||||
|
||||
nbt.Write(NbtTagType.Int8);
|
||||
nbt.Write("P");
|
||||
nbt.WriteUInt8((byte)Utils.DegreesToPacked(p.SpawnHeadX));
|
||||
nbt.WriteUInt8(Utils.DegreesToPacked(p.SpawnHeadX));
|
||||
|
||||
nbt.Write(NbtTagType.End);
|
||||
}
|
||||
|
@ -288,8 +288,8 @@ namespace ClassicalSharp.Network.Protocols {
|
||||
|
||||
writer.WriteUInt8((byte)payload); // held block when using HeldBlock, otherwise just 255
|
||||
writer.WritePosition(pos);
|
||||
writer.WriteUInt8((byte)Utils.DegreesToPacked(rotY));
|
||||
writer.WriteUInt8((byte)Utils.DegreesToPacked(headX));
|
||||
writer.WriteUInt8(Utils.DegreesToPacked(rotY));
|
||||
writer.WriteUInt8(Utils.DegreesToPacked(headX));
|
||||
net.SendPacket();
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,8 @@ namespace ClassicalSharp {
|
||||
return (int)(degrees * period / 360.0) % period;
|
||||
}
|
||||
|
||||
public static int DegreesToPacked(double degrees) {
|
||||
return (int)(degrees * 256 / 360.0) & 0xFF;
|
||||
public static byte DegreesToPacked(double degrees) {
|
||||
return (byte)(degrees * 256 / 360.0);
|
||||
}
|
||||
|
||||
public static double PackedToDegrees(byte packed) {
|
||||
|
@ -176,6 +176,7 @@
|
||||
<ClInclude Include="Platform.h" />
|
||||
<ClInclude Include="Random.h" />
|
||||
<ClInclude Include="NotchyGenerator.h" />
|
||||
<ClInclude Include="String.h" />
|
||||
<ClInclude Include="Typedefs.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -183,6 +184,7 @@
|
||||
<ClCompile Include="Noise.c" />
|
||||
<ClCompile Include="NotchyGenerator.c" />
|
||||
<ClCompile Include="Random.c" />
|
||||
<ClCompile Include="String.c" />
|
||||
<ClCompile Include="WinPlatform.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@ -28,6 +28,12 @@
|
||||
<Filter Include="Header Files\Platform">
|
||||
<UniqueIdentifier>{3b121dcd-fc2e-4c0e-9e69-0a258df73fa8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Utils">
|
||||
<UniqueIdentifier>{ce9032c9-7a6b-44bf-889b-5c368d5ecda7}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Utils">
|
||||
<UniqueIdentifier>{23df7aa9-c2fe-4dd9-ad2e-b07776510024}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="NotchyGenerator.h">
|
||||
@ -54,6 +60,9 @@
|
||||
<ClInclude Include="Platform.h">
|
||||
<Filter>Header Files\Platform</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="String.h">
|
||||
<Filter>Header Files\Utils</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="NotchyGenerator.c">
|
||||
@ -71,5 +80,8 @@
|
||||
<ClCompile Include="WinPlatform.c">
|
||||
<Filter>Source Files\Platform</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="String.c">
|
||||
<Filter>Source Files\Utils</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -5,7 +5,15 @@
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
// returns a bit mask for the nth bit in an integer
|
||||
#define bit(x) (1 << x)
|
||||
|
||||
// returns smallest of two numbers
|
||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
// returns largest of two numbers
|
||||
#define max(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
// returns absolute value of a number
|
||||
#define abs(x) (x >= 0 ? x : -x)
|
||||
#endif
|
@ -21,7 +21,6 @@ void Platform_MemFree(void* mem);
|
||||
|
||||
/* Sets a block of memory to the given byte value. */
|
||||
void Platform_MemSet(void* dst, UInt8 value, UInt32 numBytes);
|
||||
|
||||
/* Copies a block of non-overlapping memory. */
|
||||
void Platform_MemCpy(void* dst, void* src, UInt32 numBytes);
|
||||
|
||||
|
36
src/Client/String.c
Normal file
36
src/Client/String.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include "String.h"
|
||||
|
||||
void String_Empty(String* str, UInt8* buffer, Int16 capacity) {
|
||||
str->buffer = buffer;
|
||||
str->capacity = capacity;
|
||||
str->length = 0;
|
||||
}
|
||||
|
||||
void String_Constant(String* str, const UInt8* buffer) {
|
||||
Int16 length = 0;
|
||||
UInt8 cur = 0;
|
||||
|
||||
while ((cur = *buffer) != 0) {
|
||||
length++; buffer++;
|
||||
}
|
||||
|
||||
str->buffer = buffer;
|
||||
str->capacity = length;
|
||||
str->length = length;
|
||||
}
|
||||
|
||||
bool String_Equals(String* a, String* b) {
|
||||
if (a->length != b->length) return false;
|
||||
|
||||
for (Int32 i = 0; i < a->length; i++) {
|
||||
if (a->buffer[i] != b->buffer[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int String_IndexOf(String* str, UInt8 c) {
|
||||
for (Int32 i = 0; i < str->length; i++) {
|
||||
if (str->buffer[i] == c) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
31
src/Client/String.h
Normal file
31
src/Client/String.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef CS_STRING_H
|
||||
#define CS_STRING_H
|
||||
#include "Typedefs.h"
|
||||
/* Implements operations for a string.
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
typedef struct String {
|
||||
/* Pointer to raw characters. Size is capacity + 1, as buffer is null terminated. */
|
||||
UInt8* buffer;
|
||||
|
||||
/* Number of characters used. */
|
||||
Int16 length;
|
||||
|
||||
/* Max number of characters that can be in buffer. */
|
||||
Int16 capacity;
|
||||
} String;
|
||||
|
||||
/* Constructs a new string, filled with NULL characters. */
|
||||
void String_Empty(String* str, UInt8* buffer, Int16 capacity);
|
||||
|
||||
/* Constructs a new string from a constant readonly string. */
|
||||
void String_Constant(String* str, const UInt8* buffer);
|
||||
|
||||
/* Returns whether two strings have same contents. */
|
||||
bool String_Equals(String* a, String* b);
|
||||
|
||||
/* Finds the first index of c in given string, -1 if not found. */
|
||||
int String_IndexOf(String* str, UInt8 c);
|
||||
|
||||
#endif
|
@ -4,7 +4,7 @@
|
||||
|
||||
HANDLE heap;
|
||||
void Platform_Init() {
|
||||
heap = HeapCreate(0, 0, 0);
|
||||
heap = GetProcessHeap(); // TODO: HeapCreate instead? probably not
|
||||
}
|
||||
|
||||
void Platform_Free() {
|
||||
@ -12,7 +12,7 @@ void Platform_Free() {
|
||||
}
|
||||
|
||||
void* Platform_MemAlloc(UInt32 numBytes) {
|
||||
return HeapAlloc(heap, 0, 0);
|
||||
return HeapAlloc(heap, 0, numBytes);
|
||||
}
|
||||
|
||||
void Platform_MemFree(void* mem) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user