-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrandspoofer.proxy.kts
81 lines (68 loc) · 2.72 KB
/
brandspoofer.proxy.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import me.marvin.proxy.utils.*
import me.marvin.proxy.networking.*
import me.marvin.proxy.networking.packet.*
import me.marvin.proxy.utils.*
import me.marvin.proxy.utils.ByteBufUtils.*
import io.netty.buffer.*
import io.netty.channel.*
import com.google.gson.*
import java.awt.*
import java.io.*
import java.nio.charset.*
import java.net.*
import java.net.http.*
import java.security.*
import java.util.*
object Constants {
/**
* Ha Unit-ot returnol, akkor nem írja felül a brandet
* Ha null-t returnol, akkor nem küldi el a brandet
* Ha string-et returnol, akkor a string-et küldi el mint brandet
*/
val CLIENT_BRAND: Any? = "vanilla"
}
object Rewriter : PacketListener {
override fun priority(): Byte = 0
override fun handle(type: PacketType, buf: ByteBuf, send: Channel, recv: ChannelHandlerContext, version: Version): Tristate {
if (type == PacketTypes.Play.Client.PLUGIN_MESSAGE) {
IndexRollback.readerManual(buf).use {
val channel = readString(buf)
if (channel == "minecraft:brand") {
if (Constants.CLIENT_BRAND is Unit) {
return Tristate.NOT_SET
} else if (Constants.CLIENT_BRAND is String) {
val brand = readString(buf)
if (brand == Constants.CLIENT_BRAND) {
return Tristate.NOT_SET
} else {
val content = Unpooled.buffer()
writeString(content, Constants.CLIENT_BRAND)
val rewritten = Unpooled.buffer()
writeVarInt(rewritten, type.id(version))
writeString(rewritten, channel)
rewritten.writeBytes(content)
recv.writeAndFlush(rewritten)
content.release()
return Tristate.TRUE
}
} else if (Constants.CLIENT_BRAND == null) {
return Tristate.TRUE
}
}
}
}
return Tristate.NOT_SET
}
}
// TODO: commands
@Entrypoint
fun entry() {
logger.info("[Brand Spoofer] Started!")
logger.info("[Brand Spoofer] Brand rewriting: ${if (Constants.CLIENT_BRAND == null) "cancel" else (if (Constants.CLIENT_BRAND is String) "'${Constants.CLIENT_BRAND}'" else "none")}" )
proxy.registerListeners(Rewriter)
}
@Destructor
fun destruct() {
proxy.unregisterListener(Rewriter)
logger.info("[Brand Spoofer] Stopped!")
}