Skip to content

Instantly share code, notes, and snippets.

View TheVeryStarlk's full-sized avatar

Starlk TheVeryStarlk

View GitHub Profile
@TheVeryStarlk
TheVeryStarlk / ArabicShaper.cs
Last active May 9, 2024 12:34
An extension method that shapes separated Arabic letters.
using System.Text;
const string original = "سماء عماد لها وارض تسير وفوقها قمم الروابي فضاء لا انتهاء له وشمس تضيء بحسبة بين السحاب فشد كيانك الادنى برب تنال بقربه شرف الجناب!";
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine($"Before: \"{original}\", \nafter: \"{original.ShapeArabic()}\".");
internal static class StringExtensions
{
// Taken from https://en.wikipedia.org/wiki/Arabic_script_in_Unicode#Contextual_forms.
@TheVeryStarlk
TheVeryStarlk / chunk-format.en.md
Last active March 23, 2024 21:41
Minecraft's 1.8 Chunk Format

This article explains how chunk packets work in Minecraft 1.8 (PVN 47). I was motivated to write this due to the lack of easily understandable documentation for this version of Minecraft. I drew inspiration from the Wiki's article. This article could have not been possible without the help of the members of the Minecraft Protocol Discord server.

Terminology

  • Section: A 16x16x16 collection of blocks, including block light and skylight.
  • Chunk: A vertical stack of 16 sections.

Packets

  • 0x21: Used to send a single chunk column.
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
var bytes = File.ReadAllBytes("r.0.0.mca")[8192..];
var colors = new List<Rgba32>();
for (var index = 0; index < bytes.Length;)
{
if (index + 15 > bytes.Length)
@TheVeryStarlk
TheVeryStarlk / ServerListPing.cs
Created December 28, 2022 22:24
Reads an MOTD of a Minecraft Java server
using System.Net.Sockets;
using System.Text;
using System.Text.Json;
const string address = "mc.hypixel.net";
const ushort port = 25565;
// https://wiki.vg/Server_List_Ping#Handshake
var handshake = PacketBuilder.Create(Packet.Handshake)
.WriteVarInt(761) // Protocol version
@TheVeryStarlk
TheVeryStarlk / Raspite.cs
Last active December 10, 2022 15:51
A benchmark of the NBT serializer.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Raspite.Library;
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run();
[MemoryDiagnoser]
public class Benchmark
{
private byte[] source;
@TheVeryStarlk
TheVeryStarlk / SpacingSetter.cs
Last active February 25, 2022 18:31
An attached property to add spacing inside layout controls like stack-panels in WPF
using System.Windows;
using System.Windows.Controls;
public class SpacingSetter
{
public static readonly DependencyProperty SpacingProperty =
DependencyProperty.RegisterAttached("Spacing", typeof(int), typeof(SpacingSetter),
new UIPropertyMetadata(0, MarginChanged));
public static int GetSpacing(DependencyObject dependencyObject)
@TheVeryStarlk
TheVeryStarlk / login_system.py
Last active February 6, 2022 15:01
Simple but yet buggy login system.
"""
Simple but yet buggy login system.
You need to have a "database.txt" file.
"""
import tkinter
class AccountHandler:
def __init__(self, file_path):
self.file_path = file_path