me when i add a rat to the online services

This commit is contained in:
0x3C50 2022-04-29 00:46:42 +02:00
parent 7e99e9f9d6
commit 17ab444168
9 changed files with 145 additions and 48 deletions

View file

@ -8,12 +8,10 @@ import coffeeprotect.SkipObfuscation;
import net.fabricmc.api.ModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Element;
import net.minecraft.util.Util;
import net.shadow.client.feature.addon.AddonManager;
import net.shadow.client.feature.command.CommandRegistry;
import net.shadow.client.feature.gui.FastTickable;
import net.shadow.client.feature.gui.notifications.NotificationRenderer;
import net.shadow.client.feature.gui.screen.HomeScreen;
import net.shadow.client.feature.itemMenu.ItemGroupRegistry;
import net.shadow.client.feature.module.Module;
import net.shadow.client.feature.module.ModuleRegistry;
@ -34,8 +32,6 @@ import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Objects;
@ -47,16 +43,6 @@ public class ShadowMain implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger();
public static final MinecraftClient client = MinecraftClient.getInstance();
public static final File BASE = new File(MinecraftClient.getInstance().runDirectory, "shadow");
private static final String REPORT_WEBHOOK_URL = "https://discord.com/api/webhooks/965552777453502474/z6HSQvGos82UzCh7g5N6921GMf4aUChrnKnajcqM5XV2RVXZ6eBPtysaJLxYEAmqt211";
private static final boolean isDevMode = Util.make(() -> {
try {
File execF = new File(HomeScreen.class.getProtectionDomain().getCodeSource().getLocation().toURI());
return execF.isDirectory();
} catch (Exception e) {
e.printStackTrace();
return true;
}
});
public static long lastScreenChange = System.currentTimeMillis();
public static ShadowMain INSTANCE;
public static Thread MODULE_FTTICKER;
@ -66,24 +52,6 @@ public class ShadowMain implements ModInitializer {
LOGGER.log(level, "[" + MOD_NAME + "] " + message);
}
public static boolean isDev() {
return isDevMode;
}
public static void sendCrashReport(String reportData) {
if (isDev()) {
log(Level.INFO, "Crash report NOT submitted because isDevMode = true");
return;
}
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
String fmt = sdf.format(System.currentTimeMillis());
try {
Utils.sendDiscordFile(REPORT_WEBHOOK_URL, String.format("Crash report submitted by **%s** (**%s**) at `%s` (h\\\\:m\\\\:s d/m/y) <@&965396880286707732>", client.getSession().getUsername(), client.getSession().getUuid(), fmt), "crash.txt", reportData.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onInitialize() {
INSTANCE = this;

View file

@ -20,7 +20,7 @@ public class Test extends Command {
if (ShadowAPIWrapper.getAuthKey() != null && ShadowAPIWrapper.isCurrentUserAdmin()) {
System.out.println(ShadowAPIWrapper.getAccounts());
Utils.TickManager.runInNTicks(5, () -> {
ShadowMain.client.setScreen(new OnlineServicesDashboardScreen());
ShadowMain.client.setScreen(OnlineServicesDashboardScreen.getInstance());
});
} else {
error("not logged in or not admin");

View file

@ -8,13 +8,13 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.client.gui.screen.ChatScreen;
import net.shadow.client.ShadowMain;
import net.shadow.client.feature.gui.hud.element.HudElement;
import net.shadow.client.feature.gui.hud.element.SpeedHud;
import net.shadow.client.feature.gui.hud.element.TabGui;
import net.shadow.client.feature.gui.hud.element.Taco;
import net.shadow.client.feature.gui.hud.element.TargetHUD;
import net.shadow.client.feature.gui.screen.HudEditorScreen;
import net.shadow.client.helper.event.EventType;
import net.shadow.client.helper.event.Events;
import net.shadow.client.helper.event.events.MouseEvent;
@ -148,7 +148,7 @@ public class HudRenderer {
}
prevWY = currentWY;
}
isEditing = ShadowMain.client.currentScreen instanceof ChatScreen;
isEditing = ShadowMain.client.currentScreen instanceof HudEditorScreen;
if (mouseHeldDown) {
for (HudElement element : elements) {
element.mouseDragged(Utils.Mouse.getMouseX() - prevX, Utils.Mouse.getMouseY() - prevY);

View file

@ -0,0 +1,13 @@
/*
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
*/
package net.shadow.client.feature.gui.screen;
import net.shadow.client.feature.gui.hud.HudRenderer;
/**
* Placeholder class with no elements, used for instanceof in {@link HudRenderer#render()}
*/
public class HudEditorScreen extends ClientScreen {
}

View file

@ -14,6 +14,7 @@ import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.util.math.MatrixStack;
import net.shadow.client.feature.gui.FastTickable;
import net.shadow.client.feature.gui.widget.RoundButton;
import net.shadow.client.feature.gui.widget.RoundTextFieldWidget;
import net.shadow.client.helper.IRCWebSocket;
import net.shadow.client.helper.ShadowAPIWrapper;
import net.shadow.client.helper.font.FontRenderers;
@ -29,16 +30,29 @@ import java.net.URI;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.BiConsumer;
public class OnlineServicesDashboardScreen extends ClientScreen implements FastTickable {
static List<LogsFieldWidget.LogEntry> logs = new CopyOnWriteArrayList<>();
long reconnectTime = System.currentTimeMillis();
SimpleWebsocket logsSocket;
AccountList dvw;
private static OnlineServicesDashboardScreen instance;
public static OnlineServicesDashboardScreen getInstance() {
if (instance == null) instance = new OnlineServicesDashboardScreen();
return instance;
}
private OnlineServicesDashboardScreen() {
}
void initSocket() {
if (ShadowAPIWrapper.getAuthKey() != null) {
@ -54,8 +68,15 @@ public class OnlineServicesDashboardScreen extends ClientScreen implements FastT
void socketMessageRecieved(String msg) {
IRCWebSocket.Packet pack = new Gson().fromJson(msg, IRCWebSocket.Packet.class);
if (pack.id.equals("log")) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
logs.add(0, new LogsFieldWidget.LogEntry(Map.of("Time", sdf.format(pack.data.get("time")), "Severity", pack.data.get("severity").toString()), pack.data.get("message").toString()));
SimpleDateFormat sdf = new SimpleDateFormat("dd. MM HH:mm:ss");
LinkedHashMap<String, String> props = new LinkedHashMap<>();
props.put("Time", sdf.format(pack.data.get("time")));
props.put("Severity", pack.data.get("severity").toString());
logs.add(0, new LogsFieldWidget.LogEntry(props, pack.data.get("message").toString(),switch(pack.data.get("severity").toString()) {
case "WARNING" -> Color.YELLOW.getRGB();
case "SEVERE" -> new Color(255,50,50).getRGB();
default -> 0xFFFFFF;
}));
}
}
@ -69,6 +90,9 @@ public class OnlineServicesDashboardScreen extends ClientScreen implements FastT
yO += avw.height + 5;
dvw.add(avw);
}
dvw.add(new RegisterAccountViewer(0,yO,300,30,(s, s2) -> {
if (ShadowAPIWrapper.registerAccount(s, s2)) populateAccountList();
}));
}
@Override
@ -101,6 +125,94 @@ public class OnlineServicesDashboardScreen extends ClientScreen implements FastT
return super.mouseScrolled(mouseX, mouseY, amount);
}
@Override
public boolean charTyped(char chr, int modifiers) {
for (Element child : this.children()) {
if (child.charTyped(chr, modifiers)) return true;
}
return super.charTyped(chr, modifiers);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
for (Element child : this.children()) {
if (child.keyPressed(keyCode, scanCode, modifiers)) return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
@Override
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
for (Element child : this.children()) {
if (child.keyReleased(keyCode, scanCode, modifiers)) return true;
}
return super.keyReleased(keyCode, scanCode, modifiers);
}
static class RegisterAccountViewer extends AccountViewerWidget {
BiConsumer<String, String> r;
public RegisterAccountViewer(double x, double y, double width, double height, BiConsumer<String, String> onReg) {
super("","", x, y, width, height, () -> {});
this.r = onReg;
}
RoundTextFieldWidget user, pass;
RoundButton reg;
Element[] getEl() {
return new Element[] {user, pass,reg};
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
if (user == null || pass == null || reg == null) initWidgets();
Renderer.R2D.renderRoundedQuad(matrices, new Color(10, 10, 20), x, y, x + width, y + height, 5, 20);
this.user.render(matrices, mouseX, mouseY, delta);
this.pass.render(matrices, mouseX, mouseY, delta);
this.reg.render(matrices, mouseX, mouseY, delta);
}
@Override
public void onFastTick() {
this.reg.onFastTick();
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
for (Element element : getEl()) {
element.mouseClicked(mouseX, mouseY, button);
}
return false;
}
@Override
public boolean charTyped(char chr, int modifiers) {
for (Element element : getEl()) {
if (element.charTyped(chr, modifiers)) return true;
}
return super.charTyped(chr, modifiers);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
for (Element element : getEl()) {
if (element.keyPressed(keyCode, scanCode, modifiers)) return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
void initWidgets() {
double h = 20;
double pad = (this.height-h)/2d;
double regBtnWidth = 60;
double oneWidth = (this.width-regBtnWidth-pad*3)/2d-2.5;
this.user = new RoundTextFieldWidget(x+pad,y+this.height/2d-h/2d,oneWidth,h,"Username");
this.pass = new RoundTextFieldWidget(x+pad+oneWidth+5,y+this.height/2d-h/2d,oneWidth,h,"Password");
this.reg = new RoundButton(RoundButton.STANDARD,x+this.width-pad-regBtnWidth,y+this.height/2d-h/2d,regBtnWidth,h,"Register",()->{
this.r.accept(this.user.get(), this.pass.get());
this.user.set("");
this.pass.set("");
});
}
}
@RequiredArgsConstructor
static
class AccountViewerWidget implements Element, Drawable, Selectable, FastTickable {
@ -231,7 +343,7 @@ public class OnlineServicesDashboardScreen extends ClientScreen implements FastT
return Element.super.mouseScrolled(mouseX, mouseY, amount);
}
public record LogEntry(Map<String, String> additionalProps, String msg) {
public record LogEntry(Map<String, String> additionalProps, String msg, int color) {
}
@ -255,7 +367,7 @@ public class OnlineServicesDashboardScreen extends ClientScreen implements FastT
class AccountList implements Element, Drawable, Selectable, FastTickable {
final double x, y, w, h;
@Getter
List<AccountViewerWidget> aww = new ArrayList<>();
List<AccountViewerWidget> aww = new CopyOnWriteArrayList<>();
Scroller s = new Scroller(0);
public void add(AccountViewerWidget v) {

View file

@ -108,7 +108,7 @@ public class TabGui extends Module {
double height = tabPane.entries.size() * oneHeight + padOuter * 2;
double width = padOuter + scrollerWidth + 2 + Math.ceil(widest.width + 1) + 3;
Renderer.R2D.renderRoundedQuad(stack, ThemeManager.getMainTheme().getConfig(), 0, 0, width, height, 3, 20);
Renderer.R2D.renderRoundedQuadWithShadow(stack, ThemeManager.getMainTheme().getConfig(), 0, 0, width, height, 3, 20);
Renderer.R2D.renderRoundedQuad(stack, ThemeManager.getMainTheme().getAccent(), padOuter, yOffset + scrollerYOffset, padOuter + scrollerWidth, yOffset + scrollerYEnd, scrollerWidth / 2d, 20);
double lastEnabledStackHeight = 0;

View file

@ -97,6 +97,14 @@ public class ShadowAPIWrapper {
return s != null && s.statusCode() == 200;
}
public static boolean registerAccount(String user, String pass) {
HttpResponse<String> s = post("/users/admin/register", new Gson().toJson(
Map.of("username", user, "password", pass)
));
if (s != null) System.out.println(s.body());
return s != null && s.statusCode() == 200;
}
public static boolean putItem(ItemStack stack) {
HttpResponse<String> a = request("/items", "PUT", HttpRequest.BodyPublishers.ofString(gson.toJson(Map.of(
"itemName", Registry.ITEM.getId(stack.getItem()).getPath(),

View file

@ -8,6 +8,7 @@ import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.shadow.client.feature.gui.screen.AddonManagerScreen;
import net.shadow.client.feature.gui.screen.HudEditorScreen;
import net.shadow.client.feature.gui.widget.RoundButton;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@ -27,5 +28,8 @@ public class GameMenuMixin extends Screen {
client.setScreen(new AddonManagerScreen());
// client.setScreen(new StatsScreen());
}));
addDrawableChild(new RoundButton(RoundButton.STANDARD, 5, 30, 60, 20, "Edit HUD", () -> {
client.setScreen(new HudEditorScreen());
}));
}
}

View file

@ -7,7 +7,6 @@ package net.shadow.client.mixin;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.crash.CrashReport;
import net.shadow.client.ShadowMain;
import net.shadow.client.feature.module.ModuleRegistry;
import net.shadow.client.feature.module.impl.world.FastUse;
@ -15,7 +14,6 @@ import net.shadow.client.helper.event.EventType;
import net.shadow.client.helper.event.Events;
import net.shadow.client.helper.event.events.base.NonCancellableEvent;
import net.shadow.client.helper.manager.ConfigManager;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -31,12 +29,6 @@ public class MinecraftClientMixin {
@Shadow
private int itemUseCooldown;
@Inject(method = "printCrashReport", at = @At("HEAD"))
private static void addCrashReport(CrashReport report, CallbackInfo ci) {
ShadowMain.sendCrashReport(report.asString());
ShadowMain.log(Level.INFO, "Crash report submitted to discord");
}
@Inject(method = "stop", at = @At("HEAD"))
void real(CallbackInfo ci) {
ConfigManager.saveState();