Skip to content

Commit 4df9599

Browse files
committed
Fixed me being dumb + Fixed ssl issues with github
1 parent c8d867a commit 4df9599

File tree

10 files changed

+154
-30
lines changed

10 files changed

+154
-30
lines changed

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ configurations {
6060

6161
repositories {
6262
mavenCentral()
63+
mavenLocal()
6364
maven { url 'https://repo.polyfrost.cc/releases' }
6465
maven { url 'https://jitpack.io' }
6566
maven { url 'https://repo.essential.gg/repository/maven-public' }
67+
maven { url 'https://repo.hypixel.net/repository/Hypixel/' }
6668
}
6769

6870
dependencies {
@@ -74,15 +76,16 @@ dependencies {
7476
include('cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+')
7577
include("org.java-websocket:Java-WebSocket:1.5.3")
7678
include('org.reflections:reflections:0.10.2')
77-
include("org.json:json:20220924")
79+
include('org.json:json:20231013')
7880
include('org.slick2d:slick2d-core:1.0.2') {
7981
exclude module: 'lwjgl'
8082
}
8183
include('com.github.JnCrMx:discord-game-sdk4j:v0.5.5')
8284
include('com.neovisionaries:nv-websocket-client:2.14')
8385
include('com.github.MinnDevelopment:java-discord-rpc:v2.0.2')
86+
include('net.hypixel:mod-api:0.3.1')
8487

85-
compileOnly('org.spongepowered:mixin:0.7.11-SNAPSHOT')
88+
compileOnly('org.spongepowered:mixin:0.7.+')
8689

8790
compileOnly("me.djtheredstoner:DevAuth-forge-legacy:1.1.0")
8891
}

src/main/java/llc/redstone/hysentials/Hysentials.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import llc.redstone.hysentials.handlers.guis.GuiScreenPost;
2929
import llc.redstone.hysentials.handlers.htsl.*;
3030
import llc.redstone.hysentials.handlers.misc.HousingJoinHandler;
31+
import llc.redstone.hysentials.handlers.misc.PacketRecievedHandler;
3132
import llc.redstone.hysentials.handlers.misc.QuestHandler;
3233
import llc.redstone.hysentials.handlers.redworks.FormatPlayerName;
3334
import llc.redstone.hysentials.macrowheel.MacroWheelData;
@@ -55,6 +56,7 @@
5556
import llc.redstone.hysentials.htsl.Cluster;
5657
import llc.redstone.hysentials.cosmetics.cubit.CubitCompanion;
5758
import llc.redstone.hysentials.websocket.Socket;
59+
import net.hypixel.modapi.HypixelModAPI;
5860
import net.minecraft.client.Minecraft;
5961
import net.minecraft.client.gui.FontRenderer;
6062
import net.minecraft.client.gui.GuiMainMenu;
@@ -119,6 +121,7 @@ public class Hysentials {
119121
public final CosmeticManager cosmeticManager = new CosmeticManager();
120122
public static List<ICommand> commands;
121123

124+
public ModAPIHandler hypixelModAPI;
122125
public ImageIconRenderer imageIconRenderer;
123126
public JsonData sbBoxes;
124127
public JsonData rankColors;
@@ -184,6 +187,7 @@ public void init(FMLInitializationEvent event) {
184187
throw new RuntimeException(e);
185188
}
186189

190+
HysentialsUtilsKt.init(VERSION);
187191

188192
Socket.init();
189193
Socket.createSocket();
@@ -221,7 +225,6 @@ public void init(FMLInitializationEvent event) {
221225
}
222226

223227
Quest.registerQuests();
224-
HysentialsUtilsKt.init(VERSION);
225228
System.out.println("Hysentials has been initialized!");
226229
}
227230

@@ -443,6 +446,7 @@ private void registerHandlers() {
443446
eventBus.register(new Limit256());
444447
eventBus.register(new QuestHandler());
445448
eventBus.register(new CapeHandler());
449+
eventBus.register(new PacketRecievedHandler());
446450
eventBus.register(cubitCompanion = new CubitCompanion());
447451
eventBus.register(pepperCompanion = new PepperCompanion());
448452
eventBus.register(miyaCompanion = new MiyaCompanion());
@@ -461,6 +465,7 @@ private void registerHandlers() {
461465

462466
EventManager.INSTANCE.register(new BwRanks());
463467

468+
HypixelModAPI.getInstance().registerHandler(hypixelModAPI = new ModAPIHandler());
464469

465470
// Runtime.getRuntime().addShutdownHook(new Thread(() -> {
466471
// JSONArray array = new JSONArray();
@@ -508,6 +513,10 @@ public Logger getLogger() {
508513
return logger;
509514
}
510515

516+
public static ModAPIHandler getModAPI() {
517+
return INSTANCE.hypixelModAPI;
518+
}
519+
511520

512521
public static InputStream post(String url, JSONObject json) throws IOException {
513522
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();

src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import cc.polyfrost.oneconfig.libs.universal.wrappers.message.UTextComponent;
55
import cc.polyfrost.oneconfig.utils.Multithreading;
66
import cc.polyfrost.oneconfig.utils.NetworkUtils;
7+
import io.netty.buffer.AbstractByteBuf;
8+
import io.netty.buffer.ByteBufAllocator;
9+
import io.netty.buffer.EmptyByteBuf;
10+
import io.netty.buffer.Unpooled;
711
import llc.redstone.hysentials.Hysentials;
812
import llc.redstone.hysentials.HysentialsUtilsKt;
913
import llc.redstone.hysentials.config.HysentialsConfig;
@@ -25,13 +29,21 @@
2529
import com.google.gson.JsonObject;
2630
import com.mojang.authlib.GameProfile;
2731
import com.mojang.authlib.properties.PropertyMap;
32+
import net.hypixel.modapi.HypixelModAPI;
33+
import net.hypixel.modapi.packet.PacketRegistry;
34+
import net.hypixel.modapi.packet.impl.clientbound.ClientboundPingPacket;
35+
import net.hypixel.modapi.packet.impl.serverbound.ServerboundLocationPacket;
36+
import net.hypixel.modapi.packet.impl.serverbound.ServerboundPingPacket;
37+
import net.hypixel.modapi.serializer.PacketSerializer;
2838
import net.minecraft.client.Minecraft;
2939
import net.minecraft.command.CommandBase;
3040
import net.minecraft.command.CommandException;
3141
import net.minecraft.command.ICommandSender;
3242
import net.minecraft.entity.player.EntityPlayer;
3343
import net.minecraft.event.ClickEvent;
3444
import net.minecraft.event.HoverEvent;
45+
import net.minecraft.network.PacketBuffer;
46+
import net.minecraft.network.play.client.C17PacketCustomPayload;
3547
import net.minecraft.util.MovingObjectPosition;
3648
import org.apache.commons.io.FileUtils;
3749
import org.json.JSONArray;
@@ -41,6 +53,7 @@
4153
import java.awt.datatransfer.Clipboard;
4254
import java.awt.datatransfer.StringSelection;
4355
import java.io.File;
56+
import java.nio.ByteBuffer;
4457
import java.util.*;
4558
import java.util.List;
4659
import java.util.stream.Collectors;
@@ -135,7 +148,7 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
135148
UChat.chat("&8 - &a" + player.getValue().getUsername());
136149
}
137150
if (Socket.cachedUsers.size() > 25) {
138-
UChat.chat("&8 - &aAnd " + ( Socket.cachedUsers.size() - 25) + " more...");
151+
UChat.chat("&8 - &aAnd " + (Socket.cachedUsers.size() - 25) + " more...");
139152
}
140153
break;
141154
}
@@ -309,6 +322,16 @@ private static void handleTest(String command, String args) {
309322
break;
310323
}
311324

325+
case "hypixel": {
326+
UChat.chat("Sending Hypixel mod API requests...");
327+
for (PacketRegistry.RegisteredType type : HypixelModAPI.getInstance().getRegistry().getRegisteredTypes()) {
328+
Hysentials.getModAPI().sendPacket(type.getServerPacketFactory(), (packet) -> {
329+
UChat.chat("§aReceived packet: " + packet.toString());
330+
});
331+
}
332+
break;
333+
}
334+
312335
case "doorbell": {
313336
Socket.CLIENT.sendText(
314337
new Request(

src/main/java/llc/redstone/hysentials/forge/HysentialsMixinPlugin.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,12 @@ public List<String> getMixins() {
5555
}
5656

5757
@Override
58-
public void preApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
58+
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
5959

6060
}
6161

6262
@Override
63-
public void postApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
64-
// if (!hasApplied && targetClass != null && Objects.equals(targetClassName, "net.minecraft.client.gui.GuiPlayerTabOverlay")) {
65-
// for (MethodNode method : targetClass.methods) {
66-
// final String methodName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(targetClass.name, method.name, method.desc);
67-
// final ListIterator<AbstractInsnNode> iterator = method.instructions.iterator();
68-
// }
69-
// }
70-
}
63+
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
7164

72-
private String mapMethodNameFromNode(AbstractInsnNode node) {
73-
MethodInsnNode methodInsnNode = (MethodInsnNode) node;
74-
return FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(methodInsnNode.owner, methodInsnNode.name, methodInsnNode.desc);
7565
}
7666
}

src/main/java/llc/redstone/hysentials/handlers/htsl/Navigator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cc.polyfrost.oneconfig.libs.universal.ChatColor;
44
import cc.polyfrost.oneconfig.libs.universal.UChat;
5+
import llc.redstone.hysentials.HysentialsUtilsKt;
56
import llc.redstone.hysentials.config.hysentialMods.HousingConfig;
67
import llc.redstone.hysentials.event.events.GuiLoadedEvent;
78
import llc.redstone.hysentials.event.events.GuiMouseClickEvent;
@@ -84,7 +85,7 @@ public class Navigator {
8485

8586
public Navigator() {
8687
try {
87-
ARROW_TEXTURE_LOCATION = new DynamicTexture(getImageFromUrl("https://raw.githubusercontent.com/BusterBrown1218/HTSL/main/assets/red-arrow.png"));
88+
ARROW_TEXTURE_LOCATION = new DynamicTexture(getImageFromUrl(HysentialsUtilsKt.getHYSENTIALS_API() + "/resource?file=red-arrow.png"));
8889
} catch (IOException e) {
8990
throw new RuntimeException(e);
9091
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package llc.redstone.hysentials.handlers.misc;
2+
3+
import io.netty.channel.ChannelDuplexHandler;
4+
import io.netty.channel.ChannelHandlerContext;
5+
import io.netty.channel.ChannelPromise;
6+
import llc.redstone.hysentials.event.CancellableEvent;
7+
import net.hypixel.modapi.HypixelModAPI;
8+
import net.hypixel.modapi.serializer.PacketSerializer;
9+
import net.minecraft.network.Packet;
10+
import net.minecraft.network.play.server.S3FPacketCustomPayload;
11+
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
12+
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
13+
14+
public class PacketRecievedHandler {
15+
@SubscribeEvent
16+
public void onNetworkEvent(FMLNetworkEvent.ClientConnectedToServerEvent event) {
17+
event.manager.channel().pipeline()
18+
.addAfter("fml:packet_handler", "CT_packet_handler", new ChannelDuplexHandler() {
19+
@Override
20+
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
21+
CancellableEvent packetReceivedEvent = new CancellableEvent();
22+
23+
if (msg instanceof S3FPacketCustomPayload) {
24+
S3FPacketCustomPayload packet = (S3FPacketCustomPayload) msg;
25+
26+
HypixelModAPI.getInstance().handle(
27+
packet.getChannelName(),
28+
new PacketSerializer(packet.getBufferData())
29+
);
30+
}
31+
32+
if (!packetReceivedEvent.isCancelled())
33+
ctx.fireChannelRead(msg);
34+
}
35+
36+
@Override
37+
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
38+
CancellableEvent packetSentEvent = new CancellableEvent();
39+
40+
if (msg instanceof Packet) {
41+
42+
}
43+
44+
if (!packetSentEvent.isCancelled())
45+
ctx.write(msg, promise);
46+
}
47+
});
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package llc.redstone.hysentials.util;
2+
3+
import io.netty.buffer.Unpooled;
4+
import net.hypixel.modapi.handler.ClientboundPacketHandler;
5+
import net.hypixel.modapi.packet.HypixelPacket;
6+
import net.hypixel.modapi.serializer.PacketSerializer;
7+
import net.minecraft.client.Minecraft;
8+
import net.minecraft.network.PacketBuffer;
9+
import net.minecraft.network.play.client.C17PacketCustomPayload;
10+
11+
import java.util.HashMap;
12+
import java.util.function.Consumer;
13+
import java.util.function.Function;
14+
15+
public class ModAPIHandler implements ClientboundPacketHandler {
16+
HashMap<String, Consumer<HypixelPacket>> packetAwaiters = new HashMap<>();
17+
@Override
18+
public void handle(HypixelPacket packet) {
19+
packetAwaiters.forEach((identifier, consumer) -> {
20+
if (packet.getIdentifier().equals(identifier)) {
21+
consumer.accept(packet);
22+
}
23+
});
24+
}
25+
26+
public void sendPacket(Function<PacketSerializer, HypixelPacket> packet, PacketBuffer buffer) {
27+
PacketBuffer defaultPacketBuffer = new PacketBuffer(Unpooled.buffer(1).writeByte(1));
28+
HypixelPacket contains = packet.apply(new PacketSerializer(defaultPacketBuffer));
29+
Minecraft.getMinecraft().getNetHandler().addToSendQueue(
30+
new C17PacketCustomPayload(
31+
contains.getIdentifier(),
32+
(buffer == null ? new PacketBuffer(
33+
defaultPacketBuffer
34+
) : buffer)
35+
)
36+
);
37+
}
38+
39+
public void sendPacket(Function<PacketSerializer, HypixelPacket> packet) {
40+
sendPacket(packet, (PacketBuffer) null);
41+
}
42+
43+
public void sendPacket(Function<PacketSerializer, HypixelPacket> packet, Consumer<HypixelPacket> awaiter) {
44+
PacketBuffer defaultPacketBuffer = new PacketBuffer(Unpooled.buffer(1).writeByte(1));
45+
HypixelPacket contains = packet.apply(new PacketSerializer(defaultPacketBuffer));
46+
packetAwaiters.put(contains.getIdentifier(), awaiter);
47+
sendPacket(packet);
48+
}
49+
}

src/main/java/llc/redstone/hysentials/util/Renderer.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javax.imageio.ImageIO;
2424
import java.awt.image.BufferedImage;
2525
import java.io.IOException;
26+
import java.io.InputStream;
2627
import java.net.HttpURLConnection;
2728
import java.net.URL;
2829
import java.net.URLConnection;
@@ -366,19 +367,9 @@ static int clamp(int value) {
366367
return Math.max(0, Math.min(255, value));
367368
}
368369

369-
public static URLConnection makeWebRequest(String url) throws IOException {
370-
URLConnection connection = new URL(url).openConnection();
371-
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (ChatTriggers)");
372-
connection.setConnectTimeout(3000);
373-
connection.setReadTimeout(3000);
374-
return connection;
375-
}
376-
377370
public static BufferedImage getImageFromUrl(String url) throws IOException {
378-
HttpURLConnection conn = (HttpURLConnection) makeWebRequest(url);
379-
conn.setRequestMethod("GET");
380-
conn.setDoOutput(true);
381-
return ImageIO.read(conn.getInputStream());
371+
InputStream conn = NetworkUtils.setupConnection(url, "OneConfig/1.0.0", 5000, false);
372+
return ImageIO.read(conn);
382373
}
383374

384375
private static void translate(int x, int y, float z) {

src/main/kotlin/llc/redstone/hysentials/utils/StringUtils.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ fun CharSequence?.containsAny(vararg sequences: CharSequence?): Boolean {
1414
return sequences.any { it != null && this.contains(it) }
1515
}
1616

17+
//shift a list of strings to the right and return the String
18+
fun List<String>.shiftRight(): String {
19+
val last = this.last()
20+
val list = this.dropLast(1)
21+
return last + list.joinToString("")
22+
}
23+
24+
1725
fun String.toDashedUUID(): String {
1826
if (this.length != 32) return this
1927
return buildString {

src/main/kotlin/llc/redstone/hysentials/websocket/HysentialsListener.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ class HysentialsListener : WebSocketAdapter() {
2525
override fun onConnected(websocket: WebSocket, headers: Map<String, List<String>>) {
2626
println("Connected to websocket server")
2727
relogAttempts = 0
28-
future?.cancel(true)
28+
future?.cancel(false)
2929
val obj = JSONObject()
3030
obj.put("method", "login")
3131
obj.put("username", Minecraft.getMinecraft().session.username)
3232
obj.put("version", VERSION)
3333
obj.put("key", serverId)
3434
websocket.send(obj.toString())
35+
println("Sent login packet")
3536
}
3637

3738
@Throws(Exception::class)

0 commit comments

Comments
 (0)