added files.

This commit is contained in:
nitrogenoliquido committed 2026-10-14 22:15:53 -05:00
commit e908ab2355
353 files changed
+130515

No files matched your search

@@ -0,0 +1,752 @@
package dev.slinky.client.gui;
import dev.slinky.client.event.SemanticEvent;
import dev.slinky.client.gui.profile.ProfileIcons;
import dev.slinky.client.gui.profile.ProfileServices;
import dev.slinky.client.gui.settings.InlineModuleSettings;
import dev.slinky.client.input.MinecraftInputAdapter;
import dev.slinky.client.numeric.NumericMath;
import dev.slinky.client.numeric.NumericServices;
import dev.slinky.client.render.DrawPlan;
import dev.slinky.client.render.RenderAccess;
import dev.slinky.client.render.RenderConstants;
import dev.slinky.client.render.RenderEventPayload;
import dev.slinky.client.render.RenderMath;
import dev.slinky.client.render.font.CanvasFonts;
import dev.slinky.client.render.hook.RenderHooks;
import dev.slinky.module.Module;
import dev.slinky.module.ModuleManager;
import dev.slinky.module.render.GuiModule;
import dev.slinky.setting.BooleanSetting;
import dev.slinky.setting.ColorSetting;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import net.minecraft.client.gui.GuiScreen;
import org.lwjgl.input.Mouse;
public final class ClickGuiScreen extends GuiScreen implements RenderHooks.GuiFrame {
private final ModuleManager manager;
private final GuiModule module;
private final GuiMath.Runtime state;
private final ProfileServices.Host profiles;
private List<ProfileServices.Record> profileRows = Collections.emptyList();
private float profileHeight;
private final Object newProfile = new Object();
private final Object hexEdit = new Object();
private final Map<Module, Float> heights = new IdentityHashMap<>();
private final Map<Module, GuiMath.Toggle> toggles = new IdentityHashMap<>();
private final Map<Module, GuiPresentation.Expansion> expansions = new IdentityHashMap<>();
private final Map<Module, GuiPresentation.Binding> bindings = new IdentityHashMap<>();
private final Map<String, GuiPresentation.Binding> profileBindings = new HashMap<>();
private final GuiPresentation presentation = new GuiPresentation(CanvasFonts::width, true);
private final InlineModuleSettings inline;
private int lastMouseX;
private int lastMouseY;
private float lastPartialTicks;
private final GuiPresentation.Tooltip tooltip = new GuiPresentation.Tooltip();
private float drawScale;
private float drawOffsetX;
private float drawOffsetY;
private final HoldActivation heldAction = new HoldActivation();
private final Object unloadAction = new Object();
private static final float BORDER = 0.33F;
private static final float TRACK_EDGE = 0.2509804F;
private static final float TRACK_RADIUS = 5.0F;
private static final float KNOB_RADIUS = 10.0F;
private static final float EDGE_WIDTH = 2.0F;
private static final float LABEL_ROW = 19.0F;
private static final float LABEL_OFFSET = 9.0F;
public ClickGuiScreen(ModuleManager manager, GuiModule module) {
this(manager, module, manager.input().profiles());
}
public ClickGuiScreen(ModuleManager manager, GuiModule module, ProfileServices.Host profiles) {
this.manager = manager;
this.module = module;
this.state = module.runtime();
this.profiles = profiles;
this.inline = new InlineModuleSettings(manager, this.presentation, this.tooltip);
}
private static float c(int at) {
return RenderConstants.f(at);
}
private static double d(int at) {
return RenderConstants.d(at);
}
public boolean doesGuiPauseGame() {
return false;
}
public void drawScreen(int x, int y, float partial) {
this.lastMouseX = x;
this.lastMouseY = y;
this.lastPartialTicks = partial;
}
public void initGui() {
this.allowUserInput = this.module.findSetting("allow_input").isConfigured() && ((BooleanSetting)this.module.findSetting("allow_input")).isEnabled();
}
public void onGuiClosed() {
this.heldAction.reset();
this.module.screenClosed();
}
@Override
public void drawRecoveredFrame(float partial) {
this.allowUserInput = ((BooleanSetting)this.module.findSetting("allow_input")).isEnabled();
DrawPlan plan = this.framePlan(
this.mc.displayWidth,
this.mc.displayHeight,
this.module.scale(),
(float)Mouse.getX(),
(float)(this.mc.displayHeight - Mouse.getY() - 1),
RenderAccess.now()
);
RenderAccess.submit(new SemanticEvent(10), plan);
}
public DrawPlan framePlan(int displayWidth, int displayHeight, float scale, float mouseX, float mouseY, double now) {
DrawPlan var10;
try (CanvasFonts.GuiFaceScope fonts = CanvasFonts.guiFace()) {
var10 = this.buildFramePlan(displayWidth, displayHeight, scale, mouseX, mouseY, now);
}
return var10;
}
private DrawPlan buildFramePlan(int displayWidth, int displayHeight, float scale, float mouseX, float mouseY, double now) {
float elapsed = this.state.elapsed(now);
float previousFade = this.state.fade;
this.heldAction.beginFrame();
this.state.rawX = mouseX;
this.state.rawY = mouseY;
float w = (float)displayWidth / scale;
float h = (float)displayHeight / scale;
RenderMath.Rect panel = this.state.beginFrame(w, h, scale, this.module.wide(), now);
float opacity = fade(previousFade);
this.drawScale = scale;
this.drawOffsetX = 0.0F;
this.drawOffsetY = c(1313236) + opacity * c(1313240) - this.state.scroll;
DrawPlan plan = new DrawPlan()
.canvas()
.push()
.scale(scale, scale, 1.0F)
.opacity(opacity)
.color(c(1313228), c(1313228), c(1313228), c(1313232))
.rect(0.0F, 0.0F, w, h, 0.0F)
.translate(0.0F, this.drawOffsetY, 0.0F);
GuiMath.Layout layout = this.state.layouts.peek();
RenderMath.Rect tabs = layout.next(c(1312896));
plan.color(c(1312900), c(1312900), c(1312900), 1.0F).rect(tabs.x, tabs.y, tabs.width, tabs.height, c(1312904));
float tabWidth = tabs.width / (float)GuiAppearance.TABS.length;
this.state.selectedAnimation = GuiMath.limited(
this.state.selectedAnimation, (float)GuiAppearance.tab(this.state.selected), (float)((double)elapsed / d(1312912))
);
RenderMath.Rect highlight = new RenderMath.Rect(tabs.x + this.state.selectedAnimation * tabWidth, tabs.y, tabWidth, tabs.height).inset(c(1312920));
plan.color(c(1312924), c(1312924), c(1312924), 1.0F).rect(highlight.x, highlight.y, highlight.width, highlight.height, c(1312928));
String[] labels = GuiAppearance.TABS;
for (int i = 0; i < labels.length; i++) {
RenderMath.Rect r = new RenderMath.Rect(tabs.x + (float)i * tabWidth, tabs.y, tabWidth, tabs.height);
if (i == labels.length - 1) {
if (this.heldAction.update(this.unloadAction, this.state.hover(r), this.state.down, this.state.modal == 0, !this.state.consumed, now)) {
this.state.closeRequested = true;
this.manager.shutdown();
}
float held = this.heldAction.progress(this.unloadAction);
if (held > 0.0F) {
plan.color(0.8F, 0.25F, 0.27F, 0.25F).rect(r.x + 6.0F, r.y + 6.0F, (r.width - 12.0F) * held, r.height - 12.0F, 14.0F);
}
} else if (this.state.click(r)) {
this.state.selected = GuiAppearance.category(i);
this.state.mode = 0;
}
RenderMath.Rect inner = r.inset(c(1312920));
boolean hover = this.state.hover(inner);
int color = i == labels.length - 1
? rgb(c(hover ? 1312948 : 1312936), c(hover ? 1312952 : 1312944), c(hover ? 1312952 : 1312944))
: this.gray(hover ? 1312940 : 1312936);
this.presentation.text(plan, labels[i], inner, 1, 0, c(1312932), color);
}
float difference = (float)GuiAppearance.tab(this.state.selected) - this.state.selectedAnimation;
plan.push();
if (difference != 0.0F) {
float magnitude = Float.intBitsToFloat(Float.floatToRawIntBits(difference) & RenderConstants.i(1313024));
float alpha = c(1312976) - (magnitude + magnitude);
if (magnitude > c(1312972)) {
alpha = 0.0F;
}
this.drawOffsetX = (float)((double)difference * ((double)w * d(1313040)));
plan.opacity(alpha).translate(this.drawOffsetX, 0.0F, 0.0F);
}
if (this.state.selected < 5) {
this.renderCategory(plan, layout, now, elapsed, w, h);
} else {
this.renderProfiles(plan, layout, now, w, h);
}
plan.unclip().pop();
this.state.pop();
int categoryBottom = this.state.contentBottom;
this.drawOffsetX = 0.0F;
this.presentation.tooltip(plan, this.tooltip, elapsed);
plan.unclip().pop();
if (this.state.modal != 0) {
float modalOpacity = fade(this.state.modalProgress);
plan.push().scale(scale, scale, 1.0F).opacity(modalOpacity).color(c(1313228), c(1313228), c(1313228), c(1313232)).rect(0.0F, 0.0F, w, h, 0.0F);
this.drawOffsetY = c(1313236) + modalOpacity * c(1313240);
plan.translate(0.0F, this.drawOffsetY, 0.0F);
this.state.mouseY = this.state.mouseY - this.state.scroll;
this.state.resetLayout();
RenderMath.Rect modalPanel = panel;
if (panel.width > c(1313172)) {
modalPanel = new RenderMath.Rect((float)((double)panel.x + (double)(panel.width + c(1313176)) * d(1313080)), panel.y, c(1313172), panel.height);
}
GuiMath.Layout modalLayout = this.state.push(modalPanel, c(1313016), c(1313020), false);
this.renderModal(plan, modalLayout, now);
this.state.pop();
plan.unclip().pop();
}
this.state.contentBottom = categoryBottom;
this.state.endFrame(h, now);
this.heldAction.endFrame();
return plan;
}
public void expanded(Module entry, boolean open) {
GuiPresentation.Expansion expansion = new GuiPresentation.Expansion();
expansion.open = open;
this.expansions.put(entry, expansion);
}
private static float fade(float progress) {
return c(1313220) - NumericServices.powf(c(1313220) - progress, c(1313224));
}
private static int rgb(float r, float g, float b) {
return 0xFF000000 | ((int)(r * 255.0F) & 0xFF) << 16 | ((int)(g * 255.0F) & 0xFF) << 8 | (int)(b * 255.0F) & 0xFF;
}
private void clip(DrawPlan plan, GuiMath.Layout layout) {
RenderMath.Rect r = layout.clip;
plan.clip((r.x + this.drawOffsetX) * this.drawScale, (r.y + this.drawOffsetY) * this.drawScale, r.width * this.drawScale, r.height * this.drawScale);
}
private void renderCategory(DrawPlan plan, GuiMath.Layout layout, double now, float elapsed, float width, float height) {
ColorSetting.Value accent = this.module.accent();
layout.autoColumns(c(1313248));
for (Module entry : GuiAppearance.entries(this.manager, this.state.selected)) {
float old = this.heights.containsKey(entry) ? this.heights.get(entry) : 0.0F;
RenderMath.Rect outer = layout.next(old);
if (GuiMath.intersects(new RenderMath.Rect(0.0F, this.state.scroll, width, height), outer)) {
plan.color(c(1313264), c(1313264), c(1313264), 1.0F).rect(outer.x, outer.y, outer.width, outer.height, c(1313268));
GuiMath.Layout inside = this.state.push(outer, c(1313272), 12.0F, true);
this.clip(plan, inside);
inside.columns(1);
RenderMath.Rect title = inside.next(c(1313268));
GuiPresentation.Expansion expansion = this.expansions.get(entry);
if (expansion == null) {
expansion = new GuiPresentation.Expansion();
this.expansions.put(entry, expansion);
}
float advance;
if (this.module.compact()) {
advance = this.presentation
.moduleText(
this.state, plan, expansion, !entry.getSettings().isEmpty(), entry.getName(), title, 16.0F, this.gray(1313280), this.gray(1313284)
);
} else {
advance = this.presentation.text(plan, entry.getName(), title, 0, 0, c(1313276), this.gray(1313280));
}
int flags = RenderModuleAccess.observedFlags(entry);
if ((flags & 1) == 0) {
GuiPresentation.Binding record = this.bindings.get(entry);
if (record == null) {
record = new GuiPresentation.Binding(entry.getBinding(), entry.isHoldBinding(), entry, key -> {
this.manager.setBinding(entry, key);
this.manager.persist();
});
this.bindings.put(entry, record);
}
if (this.state.mode != 1 || this.state.identity != entry) {
record.key = entry.getBinding();
record.hold = entry.isHoldBinding();
}
this.presentation
.binding(
this.state,
plan,
record,
new RenderMath.Rect(advance + c(1313288), title.y, title.width - advance + title.x, title.height),
new float[]{accent.red, accent.green, accent.blue, 1.0F},
(flags & 8) == 0
);
if (entry.isHoldBinding() != record.hold) {
entry.setHoldBinding(record.hold);
this.manager.persist();
}
}
if ((flags & 2) == 0) {
RenderMath.Rect toggle = new RenderMath.Rect(title.x + title.width + c(1313292), title.y, c(1313296), title.height);
GuiMath.Toggle animation = this.toggles.get(entry);
if (animation == null) {
animation = new GuiMath.Toggle();
this.toggles.put(entry, animation);
}
boolean enabled = GuiWidgets.toggle(
this.state, plan, animation, toggle, entry.isEnabled(), new float[]{accent.red, accent.green, accent.blue, 1.0F}, now
);
if (enabled != entry.isEnabled()) {
try {
this.manager.toggle(entry);
} catch (IllegalArgumentException var22) {
expansion.open = true;
this.state.beginPrompt(var22.getMessage(), () -> {
}, now);
}
}
}
if (!this.module.compact()) {
RenderMath.Rect description = inside.next(c(1313268));
this.presentation
.moduleText(
this.state,
plan,
expansion,
!entry.getSettings().isEmpty(),
GuiAppearance.description(entry),
description,
14.0F,
this.gray(1313300),
this.gray(1313304)
);
}
if (expansion.open) {
this.inline.render(entry, this.state, plan, inside, new float[]{accent.red, accent.green, accent.blue, 1.0F}, now);
}
float target = GuiPresentation.categoryHeight(this.state.pop());
this.heights.put(entry, old == 0.0F ? target : GuiMath.limited(old, target, (float)((double)elapsed / d(1313256))));
plan.unclip();
}
}
}
private void center(DrawPlan p, String text, RenderMath.Rect r, float font, int color) {
float measured = CanvasFonts.width(text, 0, font);
float x = (float)((double)r.width * d(1312824) + (double)r.x) - measured * 0.5F;
float y = (float)((double)r.height * d(1312824) + (double)(r.y + c(1312832)));
p.canvasText(text, x, y, color, font, 17);
}
public static float[] colorBlend(float[] a, float[] b, float fraction) {
return GuiWidgets.blend(a, b, fraction);
}
private int gray(int at) {
int g = (int)(c(at) * 255.0F);
return 0xFF000000 | g << 16 | g << 8 | g;
}
private void actionEvent(int action, String name) {
SemanticEvent event = new SemanticEvent(11);
RenderEventPayload payload = RenderEventPayload.attach(event);
payload.action = action;
payload.profileName = name;
try {
this.manager.dispatch(event);
} finally {
RenderEventPayload.detach(event);
}
this.state.profileStamp = -1.0;
}
private void error(IOException error) {
SemanticEvent event = new SemanticEvent(12);
RenderEventPayload payload = RenderEventPayload.attach(event);
payload.errorCode = error instanceof ProfileServices.Failure ? ((ProfileServices.Failure)error).code : 1;
payload.message = error.getMessage();
try {
this.manager.dispatch(event);
} finally {
RenderEventPayload.detach(event);
}
}
private void perform(int action, String name, boolean overwrite) {
try {
if (action == 0) {
this.profiles.load(name);
} else if (action == 1) {
this.profiles.save(name, overwrite);
} else if (action == 2) {
this.profiles.explore();
} else if (action == 3) {
this.profiles.delete(name);
}
this.actionEvent(action, name);
} catch (IOException var5) {
this.error(var5);
}
}
private void profileAction(int action, String name, double now) {
if (action == 1 && name == null) {
this.error(new ProfileServices.Failure(6003, RenderConstants.text(1313671)));
} else if (action == 3 && name == null) {
this.error(new ProfileServices.Failure(6004, RenderConstants.text(1313637)));
} else if (this.state.profileActionsConfirmed) {
this.perform(action, name, true);
} else {
int at = 1313840 + RenderConstants.i(1313840 + action * 4);
this.state.beginPrompt(RenderConstants.text(at).replace("%s", name == null ? RenderConstants.text(1313482) : name), () -> {
this.state.profileActionsConfirmed = true;
this.perform(action, name, true);
}, now);
}
}
private void renderProfiles(DrawPlan plan, GuiMath.Layout layout, double now, float width, float height) {
if (this.state.mode == 0 && now > this.state.profileStamp + d(1313048)) {
try {
this.profileRows = this.profiles.records();
} catch (IOException var21) {
this.profileRows = this.profiles.snapshot();
this.error(var21);
}
this.state.profileStamp = now;
}
layout.autoColumns(c(1313056));
float radius = c(1313064);
float font = c(1313068);
for (int row = 0; row <= this.profileRows.size(); row++) {
ProfileServices.Record record = row == 0 ? null : this.profileRows.get(row - 1);
RenderMath.Rect outer = layout.next(this.profileHeight);
if (GuiMath.intersects(new RenderMath.Rect(0.0F, this.state.scroll, width, height), outer)) {
plan.color(c(1313060), c(1313060), c(1313060), 1.0F).rect(outer.x, outer.y, outer.width, outer.height, radius);
GuiMath.Layout inside = this.state.push(outer, c(1313016), 12.0F, true);
this.clip(plan, inside);
inside.columns(1);
RenderMath.Rect head = inside.next(radius);
float advance = this.presentation.text(plan, record == null ? RenderConstants.text(1313482) : record.name, head, 0, 0, font, this.gray(1313072));
if (record != null) {
GuiPresentation.Binding binding = this.profileBindings.get(record.name);
if (binding == null) {
binding = new GuiPresentation.Binding(record.binding, false, record.name, key -> {
record.binding = key;
this.profiles.bind(record.name, key);
});
this.profileBindings.put(record.name, binding);
}
if (this.state.mode != 1 || this.state.identity != binding.identity) {
binding.key = record.binding;
}
ColorSetting.Value accent = this.module.accent();
this.presentation
.binding(
this.state,
plan,
binding,
new RenderMath.Rect(advance + c(1313076), head.y, head.width - advance + head.x, head.height),
new float[]{accent.red, accent.green, accent.blue, 1.0F},
false
);
}
for (int slot = 0; slot < 4; slot++) {
RenderMath.Rect button = new RenderMath.Rect(head.x + head.width - (float)(80 - 20 * slot) - (float)(36 - 12 * slot), head.y, radius, 20.0F);
boolean enabled = (slot & (record == null ? 1 : 0)) == 0;
int at = 1313492 + RenderConstants.i(1313492 + slot * 4);
String label = RenderConstants.text(at);
ProfileIcons.draw(plan, button, slot, enabled, enabled && this.state.hover(button));
if (enabled && this.state.hover(button)) {
this.tooltip
.request(label, NumericMath.truncateInt((double)button.x + (double)button.width * d(1313080)), NumericMath.truncateInt(button.y));
}
if (enabled && this.state.click(button)) {
this.profileAction(slot, record == null ? null : record.name, now);
}
}
if (!this.module.compact()) {
RenderMath.Rect date = inside.next(radius);
this.presentation.text(plan, record == null ? RenderConstants.text(1313536) : record.date, date, 0, 0, c(1313088), this.gray(1313092));
}
this.profileHeight = this.state.pop();
plan.unclip();
}
}
RenderMath.Rect create = layout.next(this.profileHeight);
plan.color(c(1313060), c(1313060), c(1313060), c(1312972)).rect(create.x, create.y, create.width, create.height, radius);
if (this.state.click(create)) {
this.state.activateText(this.newProfile, GuiMath::profileNameFilter);
}
if (this.state.textActive(this.newProfile)) {
RenderMath.Rect input = new RenderMath.Rect(
create.x, (float)((double)create.y + (double)create.height * d(1313080) + d(1313104)), create.width, c(1313124)
);
this.presentation.textEntry(this.state, plan, input, 1, font, now);
String name = this.state.takeText();
if (name != null) {
this.perform(1, name, false);
}
} else {
this.center(plan, RenderConstants.text(1313821), create, c(1313096), this.gray(this.state.hover(create) ? 1312976 : 1313072));
}
}
private void renderModal(DrawPlan plan, GuiMath.Layout parent, double now) {
this.state.modalDrawing = true;
this.state.modalProgress = RenderMath.min(c(1314448), (float)((double)this.state.modalProgress + (now - this.state.modalStamp) / d(1314440)));
parent.columns(1);
RenderMath.Rect outer = parent.next(this.state.modalHeight);
plan.color(c(1314452), c(1314452), c(1314452), 1.0F).rect(outer.x, outer.y, outer.width, outer.height, c(1314456));
GuiMath.Layout inner = this.state.push(outer, c(1314460), 12.0F, true);
this.clip(plan, inner);
inner.columns(1);
RenderMath.Rect heading = inner.next(c(1314456));
this.presentation.text(plan, this.state.title, heading, 0, 0, c(1314464), this.gray(1314468));
RenderMath.Rect close = new RenderMath.Rect(heading.width - heading.height + heading.x, heading.y, heading.height, heading.height);
float inset = (float)((double)close.width * d(1314488));
boolean hover = this.state.hover(close);
plan.color(c(hover ? 1314476 : 1314472), c(hover ? 1314480 : 1314472), c(hover ? 1314480 : 1314472), 1.0F)
.lineWidth(c(1314484))
.line(close.x + inset, close.y + inset, close.x + close.width - inset, close.y + close.height - inset)
.line(close.x + close.width - inset, close.y + inset, close.x + inset, close.y + close.height - inset);
boolean closePressed = this.state.click(close);
int mode = this.state.modal;
if (mode == 1 || mode == 4) {
RenderMath.Rect input = inner.next(c(1314496));
plan.color(c(1314504), c(1314504), c(1314504), 1.0F).lineWidth(c(1314484)).roundedStroke(input.x, input.y, input.width, input.height, c(1314460));
if (!this.state.textActive(this.state.identity)) {
this.state.finishModal(true);
} else {
this.presentation.textEntry(this.state, plan, input.inset(c(1314508)), 1, c(1314500), now);
if (mode == 1) {
this.state.submitModalText();
} else {
this.state.filterOptions(now);
RenderMath.Rect pair = null;
Integer chosen = null;
for (int i = 0; i < this.state.matches.size(); i++) {
if ((i & 1) == 0) {
pair = inner.next(c(1314520));
}
RenderMath.Rect button = new RenderMath.Rect(pair.x + (float)(i & 1) * pair.width * c(1314524), pair.y, pair.width * c(1314524), pair.height);
int index = this.state.matches.get(i);
this.presentation
.text(plan, this.state.options.get(index), button, 0, 0, c(1314464), this.gray(this.state.hover(button) ? 1314448 : 1314468));
if (this.state.click(button)) {
chosen = index;
}
}
if (this.state.overflow != 0) {
RenderMath.Rect note = inner.next(c(1314520));
this.presentation
.text(
plan,
RenderConstants.text(1314705).replace("%u", Integer.toString(Math.min(this.state.overflow, 9999))),
note,
0,
0,
c(1314500),
this.gray(1314472)
);
}
if (chosen != null) {
this.state.choose(chosen);
}
}
}
} else if (mode == 3) {
RenderMath.Rect prompt = inner.next(c(1314496));
this.presentation.text(plan, this.state.prompt, prompt, 0, 0, c(1314500), this.gray(1314468));
RenderMath.Rect button = inner.next(c(1314496));
boolean over = this.state.hover(button);
plan.color(c(over ? 1314476 : 1314468), c(over ? 1314480 : 1314528), c(over ? 1314480 : 1314528), 1.0F)
.rect(button.x, button.y, button.width, button.height, c(1314532));
this.center(plan, RenderConstants.text(1314696), button, c(1314500), this.gray(1314448));
if (this.state.click(button)) {
this.state.confirmPrompt();
}
} else if (mode == 2) {
this.renderColor(plan, inner);
}
this.state.modalHeight = this.state.pop();
plan.unclip();
this.state.modalDrawing = false;
this.state.modalStamp = now;
if (closePressed && this.state.modal != 0) {
this.state.finishModal(true);
}
}
private static float[] sample(float[][] stops, float t) {
if (stops.length == 1) {
return stops[0];
} else {
float position = RenderMath.clamp(0.0F, 1.0F, t) * (float)(stops.length - 1);
int index = Math.min(stops.length - 2, (int)position);
float f = position - (float)index;
float[] color = new float[4];
for (int c = 0; c < 4; c++) {
color[c] = stops[index][c] + (stops[index + 1][c] - stops[index][c]) * f;
}
return color;
}
}
private void renderColor(DrawPlan plan, GuiMath.Layout layout) {
RenderMath.Rect row = layout.next(c(1314536));
plan.color(this.state.rgb[0], this.state.rgb[1], this.state.rgb[2], 1.0F).rect(row.x, row.y, row.height, row.height, c(1314532));
plan.color(0.33F, 0.33F, 0.33F, 1.0F).lineWidth(1.0F).roundedStroke(row.x, row.y, row.height, row.height, c(1314532));
String hex = String.format(
Locale.ROOT,
"%02x%02x%02x",
(int)(NumericMath.truncateLong(this.state.rgb[0] * c(1314540)) & 255L),
(int)(NumericMath.truncateLong(this.state.rgb[1] * c(1314540)) & 255L),
(int)(NumericMath.truncateLong(this.state.rgb[2] * c(1314540)) & 255L)
);
plan.canvasText(
RenderConstants.text(1314681) + (this.state.textActive(this.hexEdit) ? this.state.text.toString() : hex),
row.x + row.height + c(1314460),
row.y,
this.gray(1314472),
c(1314456),
9
);
if (this.state.click(row)) {
this.state.activateText(this.hexEdit, GuiMath::hexFilter);
}
if (this.state.textActive(this.hexEdit)) {
String value = this.state.takeText();
if (value != null) {
this.state.hex(value);
}
}
for (int component = 0; component < 3; component++) {
RenderMath.Rect label = layout.next(19.0F);
plan.canvasText(
RenderConstants.text(component == 0 ? 1314642 : (component == 1 ? 1314646 : 1314657)), label.x, label.y + 9.0F, this.gray(1314468), c(1314500), 9
);
RenderMath.Rect slider = layout.next(c(1314500));
float edge = 1.0F;
RenderMath.Rect track = new RenderMath.Rect(slider.x + edge, slider.y, slider.width - 2.0F, slider.height);
float[][] stops;
if (component == 0) {
int steps = (int)c(1314560);
stops = new float[steps + 1][];
for (int i = 0; i <= steps; i++) {
stops[i] = GuiMath.hsl((float)i / (float)steps, this.state.hsl[1], this.state.hsl[2], 255);
}
} else {
stops = new float[][]{
GuiMath.hsl(this.state.hsl[0], component == 1 ? 0.0F : this.state.hsl[1], component == 2 ? 0.0F : this.state.hsl[2], 255),
GuiMath.hsl(this.state.hsl[0], component == 1 ? c(1314448) : this.state.hsl[1], component == 2 ? c(1314448) : this.state.hsl[2], 255)
};
}
plan.pillGradient(track, 5.0F, stops);
plan.color(0.2509804F, 0.2509804F, 0.2509804F, 1.0F).lineWidth(2.0F).roundedStroke(track.x, track.y, track.width, track.height, 5.0F);
float outer = 10.0F + edge;
float px = (slider.width - 2.0F * outer) * this.state.hsl[component] + slider.x + outer;
float py = (float)((double)slider.height * d(1314616) + (double)slider.y);
float[] under = sample(stops, this.state.hsl[component]);
plan.color(under[0], under[1], under[2], 1.0F).op("circle", px, py, 10.0F);
plan.color(0.2509804F, 0.2509804F, 0.2509804F, 1.0F).lineWidth(2.0F).circleStroke(px, py, 10.0F);
this.state.colorSlider(slider, component, outer);
}
RenderMath.Rect label = layout.next(19.0F);
plan.canvasText(RenderConstants.text(1314667), label.x, label.y + 9.0F, this.gray(1314468), c(1314500), 9);
row = layout.next(c(1314520));
float x = row.x;
float width = (row.width + c(1314564)) * c(1314568);
float spacing = c(1314460) + width;
for (int back = 8; back > 0; back--) {
int index = this.state.historyIndex >= back ? this.state.historyIndex - back : this.state.historyIndex + 8 - back;
float[] color = this.state.history[index];
RenderMath.Rect button = new RenderMath.Rect(x, row.y, width, row.height);
plan.color(color[0], color[1], color[2], 1.0F).rect(button.x, button.y, button.width, button.height, 5.0F);
boolean over = this.state.hover(button);
float edge = over ? 0.55F : 0.33F;
plan.color(edge, edge, edge, 1.0F).lineWidth(1.0F).roundedStroke(button.x, button.y, button.width, button.height, 5.0F);
if (this.state.click(button)) {
this.state.selectHistory(index);
}
x += spacing;
}
}
public void handleMouseInput() throws IOException {
MinecraftInputAdapter.mouse(this.manager);
super.handleMouseInput();
}
public void handleKeyboardInput() throws IOException {
if ((MinecraftInputAdapter.keyboard(this.manager) & 0xFF) == 0) {
super.handleKeyboardInput();
} else {
this.mc.dispatchKeypresses();
}
}
protected void keyTyped(char character, int key) throws IOException {
if (key == 1) {
this.manager.requestEnabled(this.module, false);
} else {
super.keyTyped(character, key);
}
}
}
@@ -0,0 +1,83 @@
package dev.slinky.client.gui;
import com.google.gson.JsonArray;
import dev.slinky.module.Module;
import dev.slinky.module.ModuleManager;
import dev.slinky.module.catalog.ModuleCatalog;
import dev.slinky.setting.Setting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public final class GuiAppearance {
public static final String[] TABS = new String[]{"Combat", "Move", "Visual", "Block", "Utility", "Profiles", "Unload"};
private static final int[] CATEGORIES = new int[]{0, 1, 2, 3, 4, 5};
public static int category(int tab) {
return CATEGORIES[tab];
}
public static int tab(int category) {
for (int i = 0; i < CATEGORIES.length; i++) {
if (CATEGORIES[i] == category) {
return i;
}
}
return tab(4);
}
public static boolean includes(int page, int category) {
return page == category;
}
public static List<Module> entries(ModuleManager manager, int page) {
List<Module> entries = new ArrayList<>();
for (Module module : manager.all()) {
if (includes(page, module.metadataCategory())) {
entries.add(module);
}
}
Collections.sort(entries, Comparator.comparing(Module::getName, String.CASE_INSENSITIVE_ORDER));
return entries;
}
public static String description(Module module) {
JsonArray observations = ModuleCatalog.module(module.getName()).getAsJsonArray("descriptor_observations");
return observations.size() == 0 ? module.getDescription() : observations.get(0).getAsJsonObject().get("description").getAsString();
}
public static void configureMissing(Module gui) {
if (gui != null) {
boolean fresh = true;
for (Setting<?> setting : gui.getSettings()) {
fresh &= !setting.isConfigured();
}
if (fresh && gui.getBinding() == 0) {
gui.setBinding(99);
}
configure(gui, "scale", "Medium (100%)");
configure(gui, "accent_color", "1.0,0.35,0.0");
configure(gui, "allow_input", "false");
configure(gui, "compact", "false");
configure(gui, "wide", "false");
}
}
private static void configure(Module gui, String key, String value) {
Setting<?> setting = gui.findSetting(key);
if (!setting.isConfigured()) {
setting.parseAndSet(value);
setting.saveCurrent();
}
}
private GuiAppearance() {
}
}
@@ -0,0 +1,909 @@
package dev.slinky.client.gui;
import dev.slinky.client.numeric.FloatNumeric;
import dev.slinky.client.numeric.NumericMath;
import dev.slinky.client.render.RenderConstants;
import dev.slinky.client.render.RenderMath;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
public final strictfp class GuiMath {
private static strictfp float c(int at) {
return RenderConstants.f(at);
}
private static strictfp double d(int at) {
return RenderConstants.d(at);
}
public static strictfp RenderMath.Rect rounded(RenderMath.Rect r) {
return new RenderMath.Rect(FloatNumeric.round(r.x), FloatNumeric.round(r.y), FloatNumeric.round(r.width), FloatNumeric.round(r.height));
}
public static strictfp boolean intersects(RenderMath.Rect a, RenderMath.Rect b) {
return !(a.x > b.x + b.width) && !(b.x > a.x + a.width) && !(a.y > b.y + b.height) && !(b.y > a.y + a.height);
}
public static strictfp float[] range(
GuiMath.Runtime runtime,
Object lowId,
Object highId,
GuiMath.Slider low,
GuiMath.Slider high,
RenderMath.Rect r,
float lower,
float upper,
float min,
float max,
float step,
float displayScale,
double now
) {
float difference = max - min;
float ratio = (float)((double)((float)(now - low.stamp)) / d(1314080));
low.animation = limited(low.animation, RenderMath.clamp(0.0F, c(1314076), (lower - min) / difference), ratio);
high.animation = limited(high.animation, RenderMath.clamp(0.0F, c(1314076), (upper - min) / difference), ratio);
low.stamp = high.stamp = now;
float lowX = RenderMath.lerp(r.x, r.x + r.width, low.animation);
float highX = RenderMath.lerp(r.x, r.x + r.width, high.animation);
RenderMath.Rect[] hits = GuiWidgets.rangeHits(r, r, lowX, highX);
float a = low.action(runtime, lowId, r, hits[0], lower, min, max, step, displayScale);
float b = upper;
if (low.active) {
if (a > upper) {
b = a;
}
} else {
b = high.action(runtime, highId, r, hits[1], upper, min, max, step, displayScale);
if (a > b) {
a = b;
}
}
return new float[]{a, b};
}
public static strictfp float limited(float a, float b, float t) {
return RenderMath.lerp(a, b, RenderMath.min(c(1304784), t));
}
public static strictfp float parseNumber(String text) {
byte[] input = bytes(text);
int i = 0;
int sign = 1;
int integer = 0;
if (input.length > 0 && input[0] == 45) {
i = 1;
sign = -1;
}
while (i < input.length && (input[i] & 255) - 48 < 10 && (input[i] & 255) >= 48) {
integer = integer * 10 + (input[i] & 255) - 48;
i++;
}
if (i < input.length && (input[i] & 255 | 2) == 46) {
float fraction = 0.0F;
float multiplier = c(1314008);
i++;
while (i < input.length && (input[i] & 255) - 48 < 10 && (input[i] & 255) >= 48) {
fraction += (float)((input[i] & 255) - 48) * multiplier;
multiplier = (float)((double)multiplier * d(1314016));
i++;
}
return ((float)integer + fraction) * (float)sign;
} else {
return (float)(integer * sign);
}
}
public static strictfp void numericFilter(StringBuilder text, int character) {
int b = character & 0xFF;
if (text.length() != 100) {
if (b >= 48 && b <= 57 || b == 45 || b == 46 || b == 44) {
text.append((char)b);
}
}
}
public static strictfp void catalogFilter(StringBuilder text, int character) {
if (text.length() <= 99 && RenderMath.catalogCharacter(character)) {
text.append((char)(character & 0xFF));
}
}
public static strictfp void profileNameFilter(StringBuilder text, int character) {
int b = character & 0xFF;
if (text.length() < 15 && (b - 32 & 0xFF) < 95 && b != 47 && b != 92) {
text.append((char)b);
}
}
public static strictfp void hexFilter(StringBuilder text, int character) {
if (text.length() <= 5) {
int b = character & 0xFF;
if ((b - 65 & 0xFF) <= 5) {
b |= 32;
} else if ((b - 97 & 0xFF) >= 6 && (b - 48 & 0xFF) >= 10) {
return;
}
text.append((char)b);
}
}
private static strictfp byte[] bytes(String s) {
return s.getBytes(StandardCharsets.UTF_8);
}
private static strictfp String clip(String s, int n) {
byte[] a = bytes(s);
return new String(a, 0, Math.min(n, a.length), StandardCharsets.UTF_8);
}
public static strictfp boolean substring(byte[] candidate, byte[] search) {
if (search.length == 0) {
return true;
} else {
for (int start = 0; start <= candidate.length - search.length; start++) {
int matched = 0;
while (lower(candidate[start + matched] & 255) == lower(search[matched] & 255)) {
if (++matched == search.length) {
return true;
}
}
}
return false;
}
}
private static strictfp int lower(int b) {
return (b - 65 & 0xFF) < 26 ? b | 32 : b;
}
public static strictfp float[] rgbToHsl(float[] rgb, boolean history, boolean modal) {
float r = rgb[0];
float g = rgb[1];
float b = rgb[2];
float max = b;
float min = b;
if (!Float.isNaN(g)) {
max = RenderMath.max(b, g);
min = RenderMath.min(b, g);
}
if (!Float.isNaN(r)) {
max = RenderMath.max(max, r);
min = RenderMath.min(min, r);
}
float half = c(modal ? 1314524 : 1314400);
float one = c(modal ? 1314484 : 1314404);
float six = c(modal ? 1314560 : 1314412);
float sum = max + min;
float light = half * sum;
float hue = 0.0F;
float saturation = 0.0F;
if (max != min) {
float diff = max - min;
float den = half < light ? one - max - min : sum;
if (max == r) {
hue = (g - b) / diff + (g < b ? six : 0.0F);
} else if (max == g) {
hue = (b - r) / diff + c(modal ? 1314484 : 1314404);
} else if (max == b) {
hue = (r - g) / diff + c(modal ? 1314508 : 1314408);
} else {
hue = light;
}
saturation = diff / den;
hue /= six;
}
return new float[]{hue, saturation, light};
}
private static strictfp float clamp(float v) {
return v < 0.0F ? 0.0F : RenderMath.min(c(2838936), v);
}
private static strictfp float wrap(float v) {
float one = c(2838936);
if (v < 0.0F) {
v += one;
}
if (one < v) {
v += c(2838948);
}
return v;
}
private static strictfp float channel(float h, float high, float low) {
if (c(2838952) > h) {
return (high - low) * h * c(2838960) + low;
} else if (c(2838940) > h) {
return high;
} else {
return c(2838956) > h ? (c(2838956) - h) * (high - low) * c(2838960) + low : low;
}
}
public static strictfp float[] hsl(float hue, float saturation, float light, int alpha) {
hue = FloatNumeric.remainder(hue, c(2838936));
if (hue < 0.0F) {
hue += c(2838936);
}
saturation = clamp(saturation);
light = clamp(light);
float high = c(2838940) >= light ? (saturation + c(2838936)) * light : saturation + light - light * saturation;
float low = light + light - high;
return new float[]{
clamp(channel(wrap(c(2838944) + hue), high, low)),
clamp(channel(wrap(hue), high, low)),
clamp(channel(wrap(hue + c(2838964)), high, low)),
(float)(alpha & 0xFF) / c(2838968)
};
}
public static strictfp float floor(float value) {
int bits = Float.floatToRawIntBits(value);
int exponent = bits >>> 23 & 0xFF;
if (exponent >= 150) {
return value;
} else if (exponent >= 127) {
int keep = -1 << (22 - exponent & 31);
int discard = ~keep;
return (bits & discard) == 0 ? value : Float.intBitsToFloat(bits + (-(bits >>> 31) & discard) & keep);
} else if (bits >= 0) {
return 0.0F;
} else {
return value == 0.0F ? value : c(2868916);
}
}
public interface Filter {
void append(StringBuilder var1, int var2);
}
public static final strictfp class Layout {
public RenderMath.Rect rect;
public RenderMath.Rect clip;
public float spacing;
public float inset;
public float y;
public float x;
public int columns = 1;
public int count;
public boolean scissor;
final RenderMath.Rect[] cache = new RenderMath.Rect[4];
Layout(RenderMath.Rect r, float spacing, float inset) {
this.rect = r;
this.spacing = spacing;
this.inset = inset;
this.x = r.x;
this.y = r.y;
}
private strictfp void flush(float initial) {
if (this.count != 0) {
int last = this.count - 1;
RenderMath.Rect p = this.cache[last & 3];
float bottom = p.y + p.height;
float result = initial;
for (int i = last - last % this.columns; i <= last; i++) {
result = RenderMath.max(bottom, result);
}
if (result != initial) {
this.y = result + this.spacing;
}
}
}
public strictfp void columns(int requested) {
this.flush(GuiMath.c(1312804));
this.columns = requested == 0 ? 1 : Math.min(4, requested);
this.count = 0;
}
public strictfp void autoColumns(float width) {
this.flush(GuiMath.c(1312808));
this.columns = NumericMath.truncateInt((this.rect.width + this.spacing) / (width + this.spacing));
this.columns = this.columns == 0 ? 1 : Math.min(4, this.columns);
this.count = 0;
}
public strictfp RenderMath.Rect next(float height) {
int current = this.count++;
RenderMath.Rect previous = current >= this.columns ? this.cache[current - this.columns & 3] : null;
float nx;
float ny;
float w;
if (current % this.columns != 0) {
RenderMath.Rect left = this.cache[current - 1 & 3];
nx = left.x + left.width + this.spacing;
w = left.width;
ny = current >= this.columns ? this.spacing + (previous.y + previous.height) : this.y;
} else {
nx = this.x;
if (current < this.columns) {
ny = this.y;
w = (this.rect.width - (float)(this.columns - 1) * this.spacing) / (float)this.columns;
} else {
ny = previous.y + previous.height + this.spacing;
w = previous.width;
}
}
RenderMath.Rect raw = new RenderMath.Rect(nx, ny, w, height);
this.cache[current & 3] = raw;
return GuiMath.rounded(raw);
}
public strictfp float end() {
this.flush(GuiMath.c(1312800));
return this.spacing + this.spacing + (this.y - this.rect.y);
}
}
public static final strictfp class Runtime {
public int mode;
public int modal;
public int selected;
public boolean down;
public boolean consumed;
public boolean modifier;
public boolean closeRequested;
public boolean modalDrawing;
public boolean submitted;
public float mouseX;
public float mouseY;
public float rawX;
public float rawY;
public float scroll;
public float scrollMaximum;
public float fade;
public float selectedAnimation;
public float modalProgress;
public float modalHeight;
public float tooltipProgress;
public double stamp;
public double modalStamp;
public double profileStamp;
public Object identity;
public GuiMath.Filter filter;
public IntConsumer binding;
public Consumer<String> textCompletion;
public Runnable completion;
public final StringBuilder text = new StringBuilder();
public String title;
public String prompt;
public float[] rgb;
public float[] hsl;
public final float[][] history = new float[8][3];
public int historyIndex;
public List<String> options = Collections.emptyList();
public final List<Integer> matches = new ArrayList<>();
public int overflow;
public double searchStamp;
public final Deque<GuiMath.Layout> layouts = new ArrayDeque<>();
public int contentBottom;
public boolean[] sliderActive = new boolean[3];
public boolean profileActionsConfirmed;
private Consumer<Integer> selection;
public strictfp void start(double now) {
this.fade = 0.0F;
this.stamp = now;
}
public strictfp GuiMath.Layout push(RenderMath.Rect input, float spacing, float inset, boolean scissor) {
RenderMath.Rect r = input;
if (!this.layouts.isEmpty()) {
RenderMath.Rect parent = this.layouts.peek().rect;
float x = parent.x > input.x ? parent.x : input.x;
float y = parent.y > input.y ? parent.y : input.y;
float w = input.width;
float h = input.height;
if (w + x > parent.x + parent.width) {
w = parent.x + parent.width - x;
if (0.0F > w) {
w = 0.0F;
}
}
if (h + y > parent.y + parent.height) {
h = parent.y + parent.height - y;
if (0.0F > h) {
h = 0.0F;
}
}
r = new RenderMath.Rect(x, y, w, h);
}
GuiMath.Layout l = new GuiMath.Layout(r.inset(inset), spacing, inset);
l.scissor = scissor;
if (scissor) {
l.clip = GuiMath.rounded(input).inset(spacing);
}
this.layouts.push(l);
return l;
}
public strictfp float pop() {
GuiMath.Layout l = this.layouts.pop();
float height = l.end();
if (l.y > (float)this.contentBottom) {
this.contentBottom = NumericMath.truncateInt(l.y);
}
return height;
}
public strictfp void resetLayout() {
this.layouts.clear();
this.contentBottom = 0;
}
public strictfp boolean hover(RenderMath.Rect r) {
return (this.modal == 0 || this.modalDrawing) && r.contains(this.mouseX, this.mouseY) && (this.mode == 0 || this.mode == 3);
}
public strictfp boolean click(RenderMath.Rect r) {
if (this.hover(r) && this.down && !this.consumed) {
this.consumed = true;
return true;
} else {
return false;
}
}
public strictfp void finishFrame() {
if (this.down && !this.consumed) {
this.consumed = true;
}
this.consumed = this.down;
}
public strictfp void activateBinding(Object id, IntConsumer callback) {
this.mode = 1;
this.identity = id;
this.binding = callback;
}
public strictfp void activateText(Object id, GuiMath.Filter callback) {
if ((this.mode & -2) != 2 || this.identity != id) {
this.mode = 2;
this.text.setLength(0);
this.submitted = false;
this.identity = id;
this.filter = callback;
}
}
public strictfp boolean textActive(Object id) {
return (this.mode & -2) == 2 && this.identity == id;
}
public strictfp void releaseText() {
if (this.mode == 2) {
this.mode = 3;
}
}
public strictfp String takeText() {
if ((this.mode & -2) == 2 && this.submitted) {
this.mode = 0;
this.submitted = false;
return this.text.toString();
} else {
return null;
}
}
public strictfp void clearInteraction() {
this.mode = 0;
this.down = false;
}
public strictfp boolean input(int kind, int key, int x, int y, float wheel, boolean pressed, byte[] utf8) {
if (kind == 1) {
this.rawX = (float)x;
this.rawY = (float)y;
return false;
} else if (kind == 3) {
if (this.modal == 0) {
this.scroll = wheel * GuiMath.c(1312880) + this.scroll;
}
return false;
} else if (kind != 2) {
return false;
} else {
if (pressed) {
if ((this.mode & -2) == 2) {
if (key == 1 && this.mode != 3) {
this.mode = 0;
return true;
}
if (key == 83) {
if (this.text.length() > 0) {
this.text.setLength(this.text.length() - 1);
}
return true;
}
if (key == 85) {
if (this.text.length() > 0) {
this.submitted = true;
}
return true;
}
if (key == 87) {
this.mode = 0;
return true;
}
if (key != 1) {
for (int i = 0; i < Math.min(4, utf8.length) && utf8[i] != 0; i++) {
this.filter.append(this.text, utf8[i] & 255);
}
return true;
}
} else {
if (this.mode == 1) {
this.binding.accept(key != 1 && key != 87 ? key : 0);
this.mode = 0;
return true;
}
if (this.mode == 0 && this.modal != 0 && key == 87) {
this.finishModal(true);
return true;
}
}
}
if (key == 100 || key == 101) {
this.modifier = pressed;
} else if (key == 1) {
this.down = pressed;
}
return false;
}
}
public strictfp long inputWord(long incomingSavedRsi, long callerStateWord, int kind, int key, int x, int y, float wheel, boolean pressed, byte[] utf8) {
long saved = incomingSavedRsi;
if (kind == 2 && pressed && Integer.compareUnsigned(this.mode, 1) <= 0) {
saved = callerStateWord;
}
return this.input(kind, key, x, y, wheel, pressed, utf8) ? saved & 4294967040L | 1L : 0L;
}
public strictfp void beginText(String title, Object user, GuiMath.Filter filter, Consumer<String> callback, double now) {
this.finishModal(true);
this.modal = 1;
this.title = title;
this.modalStamp = now;
this.modalProgress = this.modalHeight = 0.0F;
this.textCompletion = callback;
this.completion = () -> callback.accept(null);
this.activateText(user, filter);
}
public strictfp void beginPrompt(String message, Runnable callback, double now) {
this.finishModal(true);
this.modal = 3;
this.title = RenderConstants.text(1314628);
this.prompt = GuiMath.clip(message, 100);
this.completion = callback;
this.modalStamp = now;
this.modalProgress = this.modalHeight = 0.0F;
}
public strictfp void beginColor(float[] color, Consumer<float[]> callback, double now) {
this.beginColor("Color", color, callback, now);
}
public strictfp void beginColor(String label, float[] color, Consumer<float[]> callback, double now) {
this.finishModal(true);
this.modal = 2;
this.title = label;
this.rgb = (float[])color.clone();
this.hsl = GuiMath.rgbToHsl(this.rgb, false, false);
this.completion = () -> callback.accept((float[])this.rgb.clone());
this.modalStamp = now;
this.modalProgress = this.modalHeight = 0.0F;
Arrays.fill(this.sliderActive, false);
}
public strictfp void beginOptions(String title, List<String> candidates, Consumer<Integer> callback, double now) {
this.finishModal(true);
this.modal = 4;
this.title = title;
this.options = new ArrayList<>(candidates);
this.completion = () -> callback.accept(null);
this.selection = callback;
this.modalStamp = now;
this.modalProgress = this.modalHeight = 0.0F;
this.matches.clear();
this.overflow = 0;
this.searchStamp = 0.0;
this.activateText(this, GuiMath::catalogFilter);
this.releaseText();
}
public strictfp void choose(int index) {
this.selection.accept(index);
this.finishModal(false);
}
public strictfp void finishModal(boolean apply) {
this.mode = 0;
int old = this.modal;
if ((old == 1 || old == 2 || old == 4) && apply && this.completion != null) {
this.completion.run();
}
if (old == 2 && this.rgb != null) {
boolean found = false;
for (int back = 8; back > 0; back--) {
int index = this.historyIndex >= back ? this.historyIndex - back : this.historyIndex + 8 - back;
float[] p = this.history[index];
if (this.rgb[0] == p[0] && this.rgb[1] == p[1] && this.rgb[2] == p[2]) {
found = true;
break;
}
}
if (!found) {
this.historyIndex = this.historyIndex >= 1 ? this.historyIndex - 1 : 7;
this.history[this.historyIndex] = (float[])this.rgb.clone();
}
}
if (old == 4) {
this.matches.clear();
this.overflow = 0;
}
if (old != 0) {
this.modal = 0;
}
}
public strictfp void confirmPrompt() {
if (this.completion != null) {
this.completion.run();
}
this.finishModal(false);
}
public strictfp void submitModalText() {
String s = this.takeText();
if (s != null) {
this.textCompletion.accept(s);
this.finishModal(false);
}
}
public strictfp void filterOptions(double now) {
if (!(GuiMath.d(1314512) > now - this.searchStamp)) {
this.matches.clear();
this.overflow = 0;
byte[] search = GuiMath.bytes(this.text.toString());
for (int row = 0; row < this.options.size(); row++) {
byte[] candidate = GuiMath.bytes(this.options.get(row));
if (candidate.length >= search.length && GuiMath.substring(candidate, search)) {
if (this.matches.size() >= 30) {
this.overflow++;
} else {
this.matches.add(row);
}
}
}
this.searchStamp = now;
}
}
public strictfp boolean colorSlider(RenderMath.Rect r, int component, float inset) {
if (this.click(r)) {
this.sliderActive[component] = true;
} else {
if (!this.down) {
this.sliderActive[component] = false;
return false;
}
if (!this.sliderActive[component]) {
return false;
}
}
this.hsl[component] = RenderMath.clamp(0.0F, GuiMath.c(1314624), (this.mouseX - r.x - inset) / (r.width - 2.0F * inset));
this.rgb = GuiMath.hsl(this.hsl[0], this.hsl[1], this.hsl[2], 255);
return true;
}
public strictfp void hex(String hex) {
if (hex.length() > 5) {
for (int i = 0; i < 3; i++) {
int a = hex.charAt(2 * i) & 255;
int b = hex.charAt(2 * i + 1) & 255;
int high = a + ((byte)a >= 97 ? 169 : 208) & 0xFF;
int low = b + ((byte)b >= 97 ? 169 : 208) & 0xFF;
this.rgb[i] = (float)((double)(high << 4 | low) / GuiMath.d(1314552));
}
}
this.hsl = GuiMath.rgbToHsl(this.rgb, false, true);
}
public strictfp void selectHistory(int index) {
this.rgb = (float[])this.history[index].clone();
this.hsl = GuiMath.rgbToHsl(this.rgb, true, true);
}
public strictfp float elapsed(double now) {
return (float)(now - this.stamp);
}
public strictfp RenderMath.Rect beginFrame(float width, float height, float scale, boolean wide, double now) {
if (0.0F > this.scroll) {
this.scroll = 0.0F;
} else if (this.scroll > this.scrollMaximum) {
this.scroll = this.scrollMaximum;
}
this.mouseX = this.rawX * (GuiMath.c(1312976) / scale);
this.mouseY = this.rawY * (GuiMath.c(1312976) / scale) + this.scroll;
float elapsed = this.elapsed(now);
this.fade = RenderMath.min(GuiMath.c(1312976), (float)((double)this.fade + (double)elapsed / GuiMath.d(1313008)));
float panelWidth = RenderMath.min(width, GuiMath.c(wide ? 1312964 : 1312968));
float left = (width - panelWidth) * GuiMath.c(1312972);
this.resetLayout();
RenderMath.Rect panel = new RenderMath.Rect(left, 0.0F, panelWidth, height);
this.push(panel, GuiMath.c(1313016), GuiMath.c(1313020), false).columns(1);
return panel;
}
public strictfp void endFrame(float height, double now) {
this.scrollMaximum = RenderMath.max(0.0F, (float)this.contentBottom - height + GuiMath.c(1313020));
this.finishFrame();
this.stamp = now;
}
}
public static final strictfp class Slider {
public boolean active;
public float animation;
public double stamp;
public strictfp float update(
GuiMath.Runtime runtime,
Object id,
RenderMath.Rect track,
float value,
float min,
float max,
float step,
float displayScale,
boolean decimal,
double now
) {
return this.update(runtime, id, track, track, value, min, max, step, displayScale, now);
}
public strictfp float update(
GuiMath.Runtime runtime,
Object id,
RenderMath.Rect track,
RenderMath.Rect hit,
float value,
float min,
float max,
float step,
float displayScale,
double now
) {
float fraction = RenderMath.clamp(0.0F, GuiMath.c(1313988), (value - min) / (max - min));
this.animation = GuiMath.limited(this.animation, fraction, (float)((double)((float)(now - this.stamp)) / GuiMath.d(1313992)));
this.stamp = now;
return this.action(runtime, id, track, hit, value, min, max, step, displayScale);
}
public strictfp float action(
GuiMath.Runtime runtime, Object id, RenderMath.Rect track, RenderMath.Rect hit, float value, float min, float max, float step, float displayScale
) {
if (runtime.click(hit)) {
this.active = true;
if (runtime.modifier) {
runtime.activateText(id, GuiMath::numericFilter);
}
} else if (!runtime.down && !runtime.textActive(id)) {
this.active = false;
}
if (!this.active) {
return value;
} else {
if (runtime.textActive(id)) {
String input = runtime.takeText();
if (input == null) {
return value;
}
value = GuiMath.parseNumber(input);
if (displayScale != 0.0F) {
value /= displayScale;
}
} else {
value = (max - min) * ((runtime.mouseX - track.x) / track.width) + min;
}
if (step != 0.0F) {
value = FloatNumeric.round(value / step) * step;
}
return min >= value ? min : (value >= max ? max : value);
}
}
}
public static final strictfp class Toggle {
public float progress;
public double stamp;
public strictfp boolean animate(boolean value, double now) {
double elapsed = (double)((float)(now - this.stamp));
if (elapsed > GuiMath.d(1313856)) {
this.progress = value ? 1.0F : 0.0F;
} else if (value) {
if (GuiMath.c(1313872) > this.progress) {
this.progress = RenderMath.min((float)((double)this.progress + elapsed / GuiMath.d(1313856)), GuiMath.c(1313872));
}
} else if (this.progress > 0.0F) {
this.progress = RenderMath.max((float)((double)this.progress + elapsed / GuiMath.d(1313864)), 0.0F);
}
this.stamp = now;
return value;
}
public strictfp float smooth() {
return RenderMath.smooth(this.progress);
}
}
}
@@ -0,0 +1,86 @@
package dev.slinky.client.gui;
import dev.slinky.client.gui.settings.GuiModuleSettings;
import dev.slinky.module.Module;
import dev.slinky.module.ModuleCategory;
import dev.slinky.module.ModuleManager;
import java.io.IOException;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
public final class GuiModuleList extends GuiScreen {
private final ModuleManager modules;
private ModuleCategory selected = ModuleCategory.COMBAT;
public GuiModuleList(ModuleManager modules) {
this.modules = modules;
}
public void initGui() {
this.buttonList.clear();
int categoryWidth = Math.max(62, this.width / ModuleCategory.values().length);
int categoryId = 1000;
for (ModuleCategory category : ModuleCategory.values()) {
this.buttonList.add(new GuiButton(categoryId++, category.ordinal() * categoryWidth, 20, categoryWidth, 20, category.getDisplayName()));
}
List<Module> visible = this.modules.inCategory(this.selected);
int y = 58;
for (int index = 0; index < visible.size(); index++) {
Module module = visible.get(index);
String state = module.isEnabled() ? "ON " : "OFF ";
this.buttonList.add(new GuiButton(2000 + index, this.width / 2 - 120, y, 240, 20, state + module.getName()));
y += 24;
}
}
protected void actionPerformed(GuiButton button) throws IOException {
if (button.id >= 1000 && button.id < 1000 + ModuleCategory.values().length) {
this.selected = ModuleCategory.values()[button.id - 1000];
this.initGui();
} else {
if (button.id >= 2000) {
List<Module> visible = this.modules.inCategory(this.selected);
int index = button.id - 2000;
if (index >= 0 && index < visible.size()) {
try {
this.modules.toggle(visible.get(index));
} catch (IllegalArgumentException var5) {
this.mc.displayGuiScreen(new GuiModuleSettings(this.modules, visible.get(index)));
return;
}
this.initGui();
}
}
}
}
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, "Slinky Semantic 1.8.9", this.width / 2, 6, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRendererObj, "Right-click a module to edit its settings", this.width / 2, this.height - 18, 10526880);
}
public boolean doesGuiPauseGame() {
return false;
}
protected void mouseClicked(int x, int y, int button) throws IOException {
if (button == 1) {
for (GuiButton entry : this.buttonList) {
if (entry.id >= 2000 && entry.mousePressed(this.mc, x, y)) {
int index = entry.id - 2000;
this.mc.displayGuiScreen(new GuiModuleSettings(this.modules, this.modules.inCategory(this.selected).get(index)));
return;
}
}
}
super.mouseClicked(x, y, button);
}
}
@@ -0,0 +1,284 @@
package dev.slinky.client.gui;
import dev.slinky.client.numeric.FloatTrigonometry;
import dev.slinky.client.numeric.NumericMath;
import dev.slinky.client.render.DrawPlan;
import dev.slinky.client.render.RenderConstants;
import dev.slinky.client.render.RenderMath;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.IntConsumer;
public final strictfp class GuiPresentation {
private final GuiPresentation.Metrics metrics;
private final boolean canvas;
private final Map<Integer, Float> keyWidths = new HashMap<>();
public GuiPresentation(GuiPresentation.Metrics metrics) {
this(metrics, false);
}
public GuiPresentation(GuiPresentation.Metrics metrics, boolean canvas) {
this.metrics = Objects.requireNonNull(metrics);
this.canvas = canvas;
}
private static strictfp float c(int at) {
return RenderConstants.f(at);
}
private static strictfp double d(int at) {
return RenderConstants.d(at);
}
private static strictfp int rgba(float r, float g, float b, float a) {
return (int)(a * 255.0F) << 24 | ((int)(r * 255.0F) & 0xFF) << 16 | ((int)(g * 255.0F) & 0xFF) << 8 | (int)(b * 255.0F) & 0xFF;
}
private static strictfp int gray(float value) {
return rgba(value, value, value, 1.0F);
}
public static strictfp float[] alignedAnchor(RenderMath.Rect r, int alignment) {
float x = r.x;
if (alignment == 2) {
x += r.width;
} else if (alignment != 0) {
x = (float)((double)r.width * d(1312824) + (double)x);
}
float y = r.y + c(1312832);
y = (float)((double)r.height * d(1312824) + (double)y);
return new float[]{x, y};
}
public strictfp float text(DrawPlan plan, String text, RenderMath.Rect rect, int alignment, int style, float size, int color) {
float[] anchor = alignedAnchor(rect, alignment);
float advance = this.metrics.width(text, style, size);
float x = anchor[0];
if (alignment == 2) {
x -= advance;
} else if (alignment != 0) {
x -= advance * (float)d(1312824);
}
if (this.canvas) {
return plan.canvasText(text, anchor[0], anchor[1], color, size, (alignment == 0 ? 1 : (alignment == 2 ? 4 : 2)) | 16, style);
} else {
plan.text(text, x, anchor[1] - size * 0.5F, color, false, size);
return x + advance;
}
}
public strictfp float moduleText(
GuiMath.Runtime state,
DrawPlan plan,
GuiPresentation.Expansion expansion,
boolean hasCallback,
String text,
RenderMath.Rect rect,
float font,
int normal,
int highlight
) {
if (!hasCallback) {
return this.text(plan, text, rect, 0, 0, font, normal);
} else {
RenderMath.Rect expander = new RenderMath.Rect(rect.x, rect.y, rect.height, rect.height);
float spacing = c(1313312);
float textX = expander.x + expander.width + spacing;
float advance = this.metrics.width(text, 0, font);
RenderMath.Rect label = new RenderMath.Rect(textX, rect.y, advance, rect.height);
RenderMath.Rect combined = new RenderMath.Rect(rect.x, rect.y, expander.width + label.width + spacing, rect.height);
if (state.click(combined)) {
expansion.open = !expansion.open;
}
boolean hovering = state.hover(combined);
this.text(plan, text, label, 0, 0, font, hovering ? highlight : normal);
float background = c(hovering ? 1313320 : 1313316);
plan.color(background, background, background, 1.0F).rect(expander.x, expander.y, expander.width, expander.height, c(1313324));
RenderMath.Rect indicator = expander.inset(c(1313328));
float foreground = c(hovering ? 1313336 : 1313332);
float half = c(1313340);
plan.color(foreground, foreground, foreground, 1.0F)
.lineWidth(c(1313344))
.line(indicator.x, indicator.height * half + indicator.y, indicator.x + indicator.width, indicator.height * half + indicator.y);
if (!expansion.open) {
float cx = half * indicator.width + indicator.x;
plan.line(cx, indicator.y, cx, indicator.y + indicator.height);
}
return combined.x + combined.width;
}
}
public strictfp void binding(
GuiMath.Runtime state, DrawPlan plan, GuiPresentation.Binding record, RenderMath.Rect rectangle, float[] accent, boolean modeAllowed
) {
float font = c(1313348);
boolean active = state.mode == 1 && state.identity == record.identity;
String label = active ? RenderConstants.text(1313462) : RenderModuleAccess.keyName(record.key);
float width;
if (active) {
width = NumericMath.ceiling(this.metrics.width(label, 1, font));
} else {
Float cached = this.keyWidths.get(record.key);
width = cached == null ? 0.0F : cached;
if (width == 0.0F) {
width = NumericMath.ceiling(this.metrics.width(label, 1, font));
this.keyWidths.put(record.key, width);
}
}
RenderMath.Rect button = new RenderMath.Rect(rectangle.x, rectangle.y, width + font, rectangle.height);
float idle = c(1313356);
float[] base = record.key != 0 ? accent : new float[]{idle, idle, idle, 1.0F};
plan.color(base[0], base[1], base[2], base[3] * c(1313352)).rect(button.x, button.y, button.width, button.height, c(1313360));
int color = state.hover(button) ? gray(c(1313364)) : rgba(base[0], base[1], base[2], base[3]);
this.text(plan, label, button, 1, 1, font, color);
if (state.click(button)) {
state.activateBinding(record.identity, key -> {
record.key = key;
record.changed.accept(key);
});
}
if (record.key == 0) {
if (modeAllowed) {
record.hold = false;
}
} else if (modeAllowed) {
String toggleLabel = RenderConstants.text(1313477);
float toggleWidth = NumericMath.ceiling(this.metrics.width(toggleLabel, 1, font));
RenderMath.Rect toggle = new RenderMath.Rect(button.x + button.width + c(1313360), button.y, toggleWidth + font, button.height);
if (record.hold || state.hover(rectangle)) {
float value = c(record.hold ? 1313368 : 1313356);
plan.color(value, value, value, c(1313352)).rect(toggle.x, toggle.y, toggle.width, toggle.height, c(1313360));
this.text(plan, toggleLabel, toggle, 1, 1, font, gray(c(state.hover(toggle) ? 1313368 : 1313356)));
if (state.click(toggle)) {
record.hold = !record.hold;
}
}
}
}
public static strictfp GuiPresentation.Icon icon(RenderMath.Rect rect, float[] atlasOrigins, int id, float textureWidth, float textureHeight) {
float sx = rect.width / c(1312816);
float sy = rect.height / c(1312816);
return new GuiPresentation.Icon(rect.x - atlasOrigins[id * 2] * sx, rect.y - atlasOrigins[id * 2 + 1] * sy, sx * textureWidth, sy * textureHeight);
}
public static strictfp float caretAlpha(float frequency, double now) {
float phase = (float)((double)frequency * now);
float half = c(1312856);
return half + FloatTrigonometry.sine(phase) * half;
}
public strictfp void caret(DrawPlan plan, RenderMath.Rect r, float[] color, float frequency, float width, double now) {
plan.color(color[0], color[1], color[2], color[3] * caretAlpha(frequency, now)).lineWidth(width).line(r.x, r.y, r.x, r.y + r.height);
}
public strictfp void textEntry(GuiMath.Runtime state, DrawPlan plan, RenderMath.Rect r, int alignment, float font, double now) {
float advance = this.text(plan, state.text.toString(), r, alignment, 0, font, -1) + c(alignment == 1 ? 1314324 : 1314336);
float gray = c(alignment == 1 ? 1314328 : 1314340);
this.caret(
plan, new RenderMath.Rect(advance, r.y, r.width, r.height), new float[]{gray, gray, gray, 1.0F}, c(alignment == 1 ? 1314332 : 1314344), 1.0F, now
);
}
public strictfp void tooltip(DrawPlan plan, GuiPresentation.Tooltip state, float elapsed) {
if (!state.requested) {
state.progress = 0.0F;
} else {
state.progress = (float)((double)state.progress + (double)elapsed / d(1313136));
plan.push().translate(state.x, state.y, 0.0F);
if (state.progress > c(1312976)) {
state.progress = 1.0F;
} else {
float smooth = RenderMath.smooth(state.progress);
plan.opacity(smooth).scale(smooth, smooth, 1.0F);
}
float font = c(1313088);
float width = this.metrics.width(state.text, 0, font);
RenderMath.Rect toast = new RenderMath.Rect((float)((double)width * d(1313144) + d(1313152)), c(1313164), width + c(1313160), 20.0F);
float bg = c(1313168);
plan.color(bg, bg, bg, 1.0F).rect(toast.x, toast.y, toast.width, toast.height, c(1313076));
this.text(plan, state.text, toast, 1, 0, font, gray(c(1313072)));
plan.pop();
state.requested = false;
}
}
public static strictfp float unsignedFloat(long value) {
if (value >= 0L) {
return (float)value;
} else {
long half = value >>> 1 | value & 1L;
float converted = (float)half;
return converted + converted;
}
}
public static strictfp float categoryHeight(float height) {
long signed = NumericMath.truncateLong(height);
long adjusted = NumericMath.truncateLong(height - c(1313308));
long sign = signed >> 63;
return unsignedFloat(signed | adjusted & sign);
}
public static final strictfp class Binding {
public int key;
public boolean hold;
public final Object identity;
public final IntConsumer changed;
public Binding(int key, boolean hold, Object identity, IntConsumer changed) {
this.key = key;
this.hold = hold;
this.identity = identity;
this.changed = changed;
}
}
public static final class Expansion {
public boolean open;
}
public static final strictfp class Icon {
public final float x;
public final float y;
public final float width;
public final float height;
public Icon(float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}
public interface Metrics {
float width(String var1, int var2, float var3);
}
public static final class Tooltip {
public String text;
public float x;
public float y;
public float progress;
public boolean requested;
public strictfp void request(String text, int x, int y) {
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
this.text = new String(bytes, 0, Math.min(bytes.length, 100), StandardCharsets.UTF_8);
this.x = (float)x;
this.y = (float)y;
this.requested = true;
}
}
}
@@ -0,0 +1,491 @@
package dev.slinky.client.gui;
import dev.slinky.client.numeric.NumericMath;
import dev.slinky.client.render.DrawPlan;
import dev.slinky.client.render.RenderConstants;
import dev.slinky.client.render.RenderMath;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
public final strictfp class GuiWidgets {
private final GuiPresentation view;
private final GuiPresentation.Tooltip tooltip;
private final GuiWidgets.Formatter formatter;
public GuiWidgets(GuiPresentation view, GuiPresentation.Tooltip tooltip, GuiWidgets.Formatter formatter) {
this.view = Objects.requireNonNull(view);
this.tooltip = Objects.requireNonNull(tooltip);
this.formatter = Objects.requireNonNull(formatter);
}
private static strictfp float c(int at) {
return RenderConstants.f(at);
}
private static strictfp double d(int at) {
return RenderConstants.d(at);
}
private static strictfp int gray(float value) {
int v = (int)(value * 255.0F);
return 0xFF000000 | (v & 0xFF) << 16 | (v & 0xFF) << 8 | v & 0xFF;
}
private static strictfp int rgba(float[] color) {
return (int)(color[3] * 255.0F) << 24
| ((int)(color[0] * 255.0F) & 0xFF) << 16
| ((int)(color[1] * 255.0F) & 0xFF) << 8
| (int)(color[2] * 255.0F) & 0xFF;
}
private static strictfp RenderMath.Rect height(RenderMath.Rect rect, float h) {
return new RenderMath.Rect(rect.x, rect.y, rect.width, h);
}
private strictfp void label(DrawPlan plan, String text, RenderMath.Rect rect, int shade, int size) {
this.view.text(plan, text, rect, 0, 0, c(size), gray(c(shade)));
}
private static strictfp void solid(DrawPlan plan, float[] color) {
plan.color(color[0], color[1], color[2], color[3]);
}
private static strictfp void stroke(DrawPlan plan, RenderMath.Rect rect, int shade, int width, int radius) {
float v = c(shade);
plan.color(v, v, v, 1.0F).lineWidth(c(width)).roundedStroke(rect.x, rect.y, rect.width, rect.height, c(radius));
}
public static strictfp float[] blend(float[] a, float[] b, float fraction) {
float amount = fraction < 0.0F ? 0.0F : RenderMath.min(c(2838932), fraction);
float complement = c(2838932) - amount;
float[] out = new float[4];
for (int i = 0; i < 4; i++) {
out[i] = complement * a[i] + amount * b[i];
}
return out;
}
private static strictfp void circle(DrawPlan plan, float x, float y, float radius) {
plan.op("circle", x, y, radius);
}
private static strictfp void close(DrawPlan plan, RenderMath.Rect rect, boolean hover, float normal, int red, int other, int inset) {
float r = hover ? c(red) : normal;
float g = hover ? c(other) : normal;
float amount = (float)((double)rect.height * d(inset));
float left = rect.x + amount;
float top = rect.y + amount;
float right = rect.height + rect.x - amount;
float bottom = rect.y + rect.height - amount;
plan.color(r, g, g, 1.0F).line(left, top, right, bottom).line(right, top, left, bottom);
}
private strictfp String formatted(String format, int defaultAddress, float scale, float... values) {
double[] args = new double[values.length];
for (int i = 0; i < args.length; i++) {
args[i] = (double)(scale != 0.0F ? scale * values[i] : values[i]);
}
return this.formatter.format(format == null ? RenderConstants.text(defaultAddress) : format, args);
}
private strictfp void tip(String text, float x, float y) {
this.tooltip.request(text, NumericMath.truncateInt(x), NumericMath.truncateInt(y));
}
public static strictfp boolean toggle(
GuiMath.Runtime state, DrawPlan plan, GuiMath.Toggle animation, RenderMath.Rect rectangle, boolean value, float[] accent, double now
) {
animation.animate(value, now);
float amount = animation.smooth();
float shade = c(state.hover(rectangle) ? 1313880 : 1313876);
float[] color = blend(new float[]{shade, shade, shade, 1.0F}, accent, amount);
solid(plan, color);
plan.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height, c(1313884));
if (state.click(rectangle)) {
value = !value;
}
RenderMath.Rect inset = rectangle.inset(c(1313888));
float white = c(1313892);
float integerHeight = (float)NumericMath.truncateInt(inset.height);
float half = integerHeight * c(1313896);
float x = RenderMath.lerp(half + inset.x, inset.x + inset.width - half, amount);
float y = half + inset.y;
plan.color(white, white, white, 1.0F);
circle(plan, x, y, integerHeight);
return value;
}
public strictfp boolean checkbox(
GuiMath.Runtime state,
DrawPlan plan,
GuiMath.Layout layout,
String text,
GuiMath.Toggle animation,
boolean value,
float[] accent,
double now
) {
RenderMath.Rect rect = layout.next(c(1313900));
this.label(plan, text, rect, 1313904, 1313908);
return toggle(state, plan, animation, new RenderMath.Rect(rect.x + rect.width + c(1313912), rect.y, c(1313916), rect.height), value, accent, now);
}
public strictfp void section(DrawPlan plan, GuiMath.Layout layout, String text) {
RenderMath.Rect rect = layout.next(c(1313920));
this.label(plan, text, new RenderMath.Rect(rect.x, rect.y + c(1313924), rect.width, rect.height), 1313928, 1313932);
}
public strictfp float number(
GuiMath.Runtime state,
DrawPlan plan,
GuiMath.Layout layout,
String text,
String format,
Object id,
GuiMath.Slider animation,
float minimum,
float maximum,
float step,
float displayScale,
float value,
float[] accent,
double now
) {
RenderMath.Rect rect = layout.next(c(1313936));
this.label(plan, text, rect, 1313940, 1313944);
double half = (double)rect.width * d(1313952);
RenderMath.Rect track = new RenderMath.Rect((float)((double)rect.x + half), rect.y + c(1313948) + c(1313960), (float)(half + d(1313968)), 4.0F);
float shade = c(state.hover(rect) ? 1313980 : 1313976);
float radius = c(1313984);
plan.color(shade, shade, shade, 1.0F).rect(track.x, track.y, track.width, track.height, radius);
float fraction = RenderMath.clamp(0.0F, c(1313988), (value - minimum) / (maximum - minimum));
float ratio = (float)((double)((float)(now - animation.stamp)) / d(1313992));
animation.animation = GuiMath.limited(animation.animation, fraction, ratio);
animation.stamp = now;
float end = RenderMath.lerp(track.x, track.x + track.width, animation.animation);
solid(plan, accent);
plan.rect(track.x, track.y, end - track.x, 4.0F, radius);
circle(plan, end, radius + track.y, c(1314000));
value = animation.action(state, id, track, rect, value, minimum, maximum, step, displayScale);
if (animation.active || state.hover(rect) && !state.down) {
this.tip(state.textActive(id) ? state.text.toString() : this.formatted(format, 1314387, displayScale, value), end, track.y);
}
return value;
}
public strictfp float[] range(
GuiMath.Runtime state,
DrawPlan plan,
GuiMath.Layout layout,
String text,
String format,
String pairFormat,
Object lowId,
Object highId,
GuiWidgets.Range animation,
float minimum,
float maximum,
float step,
float displayScale,
float lower,
float upper,
float[] accent,
double now
) {
RenderMath.Rect rect = layout.next(c(1314024));
this.label(plan, text, rect, 1314028, 1314032);
double half = (double)rect.width * d(1314040);
RenderMath.Rect track = new RenderMath.Rect((float)((double)rect.x + half), rect.y + c(1314036) + c(1314048), (float)(half + d(1314056)), 4.0F);
float shade = c(state.hover(rect) ? 1314068 : 1314064);
float radius = c(1314072);
plan.color(shade, shade, shade, 1.0F).rect(track.x, track.y, track.width, 4.0F, radius);
float ratio = (float)((double)((float)(now - animation.stamp)) / d(1314080));
float difference = maximum - minimum;
animation.lower.animation = GuiMath.limited(animation.lower.animation, RenderMath.clamp(0.0F, c(1314076), (lower - minimum) / difference), ratio);
animation.upper.animation = GuiMath.limited(animation.upper.animation, RenderMath.clamp(0.0F, c(1314076), (upper - minimum) / difference), ratio);
animation.stamp = now;
float lowX = RenderMath.lerp(track.x, track.x + track.width, animation.lower.animation);
float highX = RenderMath.lerp(track.x, track.x + track.width, animation.upper.animation);
solid(plan, accent);
plan.rect(lowX, track.y, highX - lowX, 4.0F, radius);
circle(plan, lowX, radius + track.y, c(1314088));
circle(plan, highX, radius + track.y, c(1314088));
RenderMath.Rect[] hits = rangeHits(track, rect, lowX, highX);
lower = animation.lower.action(state, lowId, track, hits[0], lower, minimum, maximum, step, displayScale);
if (animation.lower.active) {
if (lower > upper) {
upper = lower;
}
this.tip(state.textActive(lowId) ? state.text.toString() : this.formatted(format, 1314387, displayScale, lower), lowX, track.y);
} else {
upper = animation.upper.action(state, highId, track, hits[1], upper, minimum, maximum, step, displayScale);
if (animation.upper.active) {
if (lower > upper) {
lower = upper;
}
this.tip(state.textActive(highId) ? state.text.toString() : this.formatted(format, 1314387, displayScale, upper), highX, track.y);
} else if (state.hover(rect) && (!state.down || animation.lower.active || animation.upper.active)) {
float sum = hits[0].x + hits[0].width + hits[1].x;
this.tooltip
.request(
this.formatted(pairFormat, 1314348, displayScale, lower, upper),
NumericMath.truncateInt((double)sum * d(1314040)),
NumericMath.truncateInt(track.y)
);
}
}
return new float[]{lower, upper};
}
public static strictfp RenderMath.Rect[] rangeHits(RenderMath.Rect track, RenderMath.Rect row, float lowX, float highX) {
float center = (float)NumericMath.truncateInt((double)(lowX + highX) * d(1314040));
float distance = center - track.x;
float extra = c(1314096);
return new RenderMath.Rect[]{
new RenderMath.Rect(c(1314092) + track.x, row.y, distance + extra, row.height),
new RenderMath.Rect(center, row.y, track.width - distance + extra, row.height)
};
}
public strictfp int choice(
GuiMath.Runtime state,
DrawPlan plan,
GuiMath.Layout layout,
String text,
GuiWidgets.Choice animation,
List<String> options,
int[] current,
int flag,
float[] accent,
double now
) {
return this.choice(state, plan, layout, text, animation, options, current, flag, accent, now, index -> current[0] = index);
}
public strictfp int choice(
GuiMath.Runtime state,
DrawPlan plan,
GuiMath.Layout layout,
String text,
GuiWidgets.Choice animation,
List<String> options,
int[] current,
int flag,
float[] accent,
double now,
IntConsumer accept
) {
int count = options.size();
float target = animation.open ? (float)Integer.toUnsignedLong(count * 28) : c(1314104);
float ratio = (float)((double)((float)(now - animation.stamp)) / d(1314112));
animation.height = GuiMath.limited(animation.height, target, ratio);
animation.stamp = now;
RenderMath.Rect rect = layout.next(animation.height);
this.label(plan, text, height(rect, 20.0F), 1314120, 1314124);
RenderMath.Rect selection = new RenderMath.Rect((float)((double)rect.width * d(1314128) + (double)rect.x), rect.y, rect.width * c(1314136), rect.height);
stroke(plan, selection, 1314140, 1314144, 1314148);
float shade = c(1314140);
if (animation.open) {
if (count == 0) {
return 0;
} else {
float rowHeight = selection.height / (float)Integer.toUnsignedLong(count);
boolean selected = false;
for (int index = 0; index < count; index++) {
RenderMath.Rect row = new RenderMath.Rect(selection.x, (float)index * rowHeight + selection.y, selection.width, rowHeight);
boolean hover = state.hover(row);
int inverted = (flag ^ 1) & 0xFF;
float[] color;
if (index == current[0]) {
color = accent;
} else {
int at = hover ? (((index == 0 ? 1 : 0) | inverted) != 0 ? 1314168 : 1314176) : (((index != 0 ? 1 : 0) | inverted) != 0 ? 1314120 : 1314172);
float value = c(at);
color = new float[]{value, value, value, 1.0F};
}
this.view.text(plan, options.get(index), row, 1, 0, c(1314124), rgba(color));
if (!selected && state.click(row)) {
current[0] = index;
animation.open = false;
selected = true;
}
if (index != 0) {
plan.color(shade, shade, shade, c(1314136)).line(selection.x, row.y, selection.x + selection.width, row.y);
}
}
return selected ? 1 : 0;
}
} else {
boolean hoverx = state.hover(selection);
if (((flag ^ 1 | (count < 6 ? 1 : 0)) & 0xFF) == 0 && current[0] != 0) {
RenderMath.Rect clear = new RenderMath.Rect(selection.width - selection.height + selection.x, selection.y, selection.height, selection.height);
boolean clearHover = state.hover(clear);
close(plan, clear, clearHover, shade, 1314152, 1314156, 1314160);
if (state.click(clear)) {
current[0] = 0;
}
hoverx = hoverx && !clearHover;
}
int at = flag != 0 && current[0] == 0 ? (hoverx ? 1314176 : 1314172) : (hoverx ? 1314168 : 1314120);
this.view.text(plan, options.get(current[0]), selection, 1, 0, c(1314124), gray(c(at)));
if (state.click(selection)) {
if (count < 6) {
animation.open = true;
} else {
state.beginOptions(RenderConstants.text(1314362), options.subList(1, count), index -> {
if (index != null) {
current[0] = index + 1;
accept.accept(current[0]);
}
}, now);
}
}
return 0;
}
}
public strictfp boolean color(
GuiMath.Runtime state, DrawPlan plan, GuiMath.Layout layout, String text, float[] current, Consumer<float[]> accept, double now
) {
RenderMath.Rect rect = layout.next(c(1314184));
this.label(plan, text, height(rect, 20.0F), 1314188, 1314192);
RenderMath.Rect preview = new RenderMath.Rect(rect.x + rect.width + c(1314196), rect.y, c(1314200), 20.0F);
float radius = preview.height * 0.5F;
plan.color(current[0], current[1], current[2], 1.0F).rect(preview.x, preview.y, preview.width, preview.height, radius);
plan.color(0.33F, 0.33F, 0.33F, 1.0F).lineWidth(1.0F).roundedStroke(preview.x, preview.y, preview.width, preview.height, radius);
RenderMath.Rect hit = new RenderMath.Rect((float)((double)rect.width * d(1314216) + (double)rect.x), rect.y, rect.width * c(1314224), rect.height);
boolean clicked = state.click(hit);
if (clicked) {
state.beginColor(text, current, accept, now);
}
return clicked;
}
public strictfp boolean list(
GuiMath.Runtime state,
DrawPlan plan,
GuiMath.Layout layout,
String text,
String title,
GuiMath.Filter filter,
int kind,
GuiWidgets.ListData list,
List<String> suggestions,
double now
) {
long count = list.size();
long rows = count + 1L;
float rowCount = GuiPresentation.unsignedFloat(rows);
RenderMath.Rect rect = layout.next(GuiPresentation.unsignedFloat(rows * 28L));
this.label(plan, text, height(rect, 20.0F), 1314232, 1314236);
RenderMath.Rect selection = new RenderMath.Rect((float)((double)rect.width * d(1314240) + (double)rect.x), rect.y, rect.width * c(1314248), rect.height);
stroke(plan, selection, 1314252, 1314256, 1314260);
float rowHeight = selection.height / rowCount;
float shade = c(1314252);
long removed = -1L;
boolean result = false;
for (long index = 0L; Long.compareUnsigned(index, count) < 0; index++) {
RenderMath.Rect row = new RenderMath.Rect(selection.x, GuiPresentation.unsignedFloat(index) * rowHeight + selection.y, selection.width, rowHeight);
String name = list.name(index);
byte[] bytes = name.getBytes(StandardCharsets.UTF_8);
String shown = new String(bytes, 0, Math.min(bytes.length, 20), StandardCharsets.UTF_8);
this.view.text(plan, shown, row, 1, 0, c(1314236), gray(c(1314232)));
if (kind == 1) {
RenderMath.Rect preview = new RenderMath.Rect(row.x, row.y, row.height, row.height).inset(c(1314264));
float[] rgb = list.color(index);
plan.color(rgb[0], rgb[1], rgb[2], 1.0F).rect(preview.x, preview.y, preview.width, preview.height, c(1314268));
if (state.click(preview)) {
long selected = index;
state.beginColor(name, rgb, value -> list.color(selected, value), now);
result = true;
}
}
RenderMath.Rect remove = new RenderMath.Rect(row.width - row.height + row.x, row.y, row.height, row.height);
close(plan, remove, state.hover(remove), shade, 1314272, 1314276, 1314280);
if (state.click(remove)) {
removed = index;
}
plan.color(shade, shade, shade, c(1314248)).line(row.x, row.y + row.height, row.x + row.width, row.y + row.height);
}
if (removed != -1L) {
list.remove(removed);
result = true;
}
RenderMath.Rect add = new RenderMath.Rect(selection.x, GuiPresentation.unsignedFloat(count) * rowHeight + selection.y, selection.width, rowHeight);
this.view.text(plan, RenderConstants.text(1314374), add, 1, 0, c(1314236), gray(c(state.hover(add) ? 1314292 : 1314288)));
if (state.click(add)) {
if (suggestions != null) {
state.beginOptions(title, suggestions, index -> {
if (index != null) {
list.add(suggestions.get(index), new float[]{c(1314296), 0.0F, 0.0F});
}
}, now);
} else {
state.beginText(title, list, filter, value -> {
if (value != null) {
list.add(value, new float[]{c(1314300), 0.0F, 0.0F});
}
}, now);
}
result = true;
}
return result;
}
public static final class Choice {
public boolean open;
public float height;
public double stamp;
}
public interface Formatter {
String format(String var1, double... var2);
}
public interface ListData {
long size();
String name(long var1);
float[] color(long var1);
void color(long var1, float[] var3);
void add(String var1, float[] var2);
void remove(long var1);
}
public static final class Range {
public final GuiMath.Slider lower = new GuiMath.Slider();
public final GuiMath.Slider upper = new GuiMath.Slider();
public double stamp;
}
}
@@ -0,0 +1,64 @@
package dev.slinky.client.gui;
public final class HoldActivation {
public static final double ACTION_SECONDS = 1.0;
private Object identity;
private double start;
private boolean fired;
private boolean seen;
private float progress;
public void beginFrame() {
this.seen = false;
}
public boolean update(Object target, boolean hovering, boolean down, boolean available, boolean canStart, double now) {
if (this.identity != null && this.identity.equals(target)) {
this.seen = true;
}
if (available && hovering && down) {
if (this.identity == null || !this.identity.equals(target)) {
if (!canStart) {
return false;
}
this.identity = target;
this.start = now;
this.fired = false;
}
this.seen = true;
this.progress = (float)Math.max(0.0, Math.min(1.0, (now - this.start) / 1.0));
if (!(this.progress < 1.0F) && !this.fired) {
this.fired = true;
return true;
} else {
return false;
}
} else {
if (this.identity != null && this.identity.equals(target)) {
this.reset();
}
return false;
}
}
public float progress(Object target) {
return this.identity != null && this.identity.equals(target) ? this.progress : 0.0F;
}
public void endFrame() {
if (!this.seen) {
this.reset();
}
}
public void reset() {
this.identity = null;
this.progress = 0.0F;
this.fired = false;
this.seen = false;
}
}
@@ -0,0 +1,45 @@
package dev.slinky.client.gui;
import dev.slinky.client.input.KeyState;
import dev.slinky.module.Module;
import java.util.Objects;
import java.util.function.BooleanSupplier;
import java.util.function.IntFunction;
public final class RenderModuleAccess {
private static volatile IntFunction<String> keys = KeyState::displayName;
private static volatile BooleanSupplier guiInteraction = () -> false;
public static int category(Module module) {
return module.metadataCategory();
}
public static int observedFlags(Module module) {
return module.descriptorFlags();
}
public static String status(Module module) {
return module.statusText();
}
public static String keyName(int key) {
return keys.apply(key);
}
public static IntFunction<String> bindKeyNames(IntFunction<String> adapter) {
IntFunction<String> previous = keys;
keys = Objects.requireNonNull(adapter);
return previous;
}
public static boolean guiInteractionRequested() {
return guiInteraction.getAsBoolean();
}
public static void bindGuiInteraction(BooleanSupplier query) {
guiInteraction = Objects.requireNonNull(query);
}
private RenderModuleAccess() {
}
}
@@ -0,0 +1,67 @@
package dev.slinky.client.gui.profile;
import dev.slinky.client.render.DrawPlan;
import dev.slinky.client.render.RenderMath;
import dev.slinky.client.render.font.CanvasFonts;
import dev.slinky.inject.Platform;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public final class ProfileIcons {
private static final byte[] COVERAGE = coverage();
private static final int TEXTURE = CanvasFonts.allocateTextureIdentity();
private static byte[] coverage() {
byte[] result = new byte[6400];
try (InputStream input = Platform.resource("/assets/slinkysemantic/profile-icon-coverage.bin")) {
if (input == null) {
throw new IOException("Profile icon coverage is missing");
} else {
int position = 0;
while (position < result.length) {
int count = input.read(result, position, result.length - position);
if (count < 0) {
throw new IOException("Incomplete profile icon atlas");
}
position += count;
}
return result;
}
} catch (IOException var15) {
throw new IllegalStateException("Cannot load profile icons", var15);
}
}
public static void draw(DrawPlan plan, RenderMath.Rect button, int action, boolean enabled, boolean hover) {
float u0 = (float)action / 4.0F;
float u1 = (float)(action + 1) / 4.0F;
float x = button.x;
float y = button.y;
float right = x + button.width;
float bottom = y + button.height;
int color = action == 3 ? (!enabled ? -8901331 : (hover ? -1089697 : -2275513)) : (!enabled ? -11119018 : (hover ? -2368549 : -6710887));
plan.alphaSprite(
TEXTURE,
160,
40,
COVERAGE,
Arrays.asList(
new float[]{x, y, u0, 0.0F},
new float[]{right, bottom, u1, 1.0F},
new float[]{right, y, u1, 0.0F},
new float[]{x, y, u0, 0.0F},
new float[]{x, bottom, u0, 1.0F},
new float[]{right, bottom, u1, 1.0F}
),
color
);
}
private ProfileIcons() {
}
}
@@ -0,0 +1,127 @@
package dev.slinky.client.gui.profile;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import dev.slinky.client.numeric.FixedWidth;
import dev.slinky.inject.Platform;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public final class ProfileMath {
private static final Map<Integer, byte[]> LABELS = labels();
private static final ProfileMath.Formatter JAVA_FORMAT = (pattern, value, capacity) -> {
String format = new String(pattern, StandardCharsets.UTF_8).replace("%lld", "%d");
byte[] result = String.format(Locale.ROOT, format, value).getBytes(StandardCharsets.UTF_8);
return Arrays.copyOf(result, Math.min(result.length, capacity - 1));
};
private ProfileMath() {
}
private static Map<Integer, byte[]> labels() {
Map<Integer, byte[]> result = new HashMap<>();
InputStream stream = Platform.resource("/assets/slinkysemantic/ProfileLabels.json");
if (stream == null) {
throw new IllegalStateException("Missing immutable profile labels");
} else {
try (Reader reader = new InputStreamReader(stream, "UTF-8")) {
for (JsonElement element : new JsonParser().parse(reader).getAsJsonArray()) {
JsonObject row = element.getAsJsonObject();
String hex = row.get("bytes").getAsString();
byte[] bytes = new byte[hex.length() / 2];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte)Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
}
result.put(row.get("rva").getAsInt(), bytes);
}
return result;
} catch (IOException var20) {
throw new ExceptionInInitializerError(var20);
}
}
}
public static long ageSeconds(long nowFileTime, long modifiedFileTime) {
return Long.compareUnsigned(modifiedFileTime - 1L, nowFileTime) >= 0
? -1L
: FixedWidth.unsignedMultiplyHigh(nowFileTime - modifiedFileTime, -2972493582642298179L) >>> 23;
}
public static long days(long ageSeconds) {
long high = FixedWidth.signedMultiplyHigh(ageSeconds, 1749024623285053783L);
return (high >> 13) + (high >>> 63);
}
public static byte[] dateBytes(long ageSeconds, ProfileMath.Formatter formatter) {
byte[] buffer = new byte[32];
if (ageSeconds == -1L) {
System.arraycopy(LABELS.get(1310590), 0, buffer, 0, 16);
byte[] end = new byte[]{116, 105, 111, 110, 32, 100, 97, 116};
System.arraycopy(end, 0, buffer, 16, end.length);
} else {
long day = days(ageSeconds);
if (day == 1L) {
System.arraycopy(LABELS.get(1310641), 0, buffer, 0, 16);
buffer[16] = 103;
buffer[17] = 111;
buffer[18] = 46;
} else if (day == 0L) {
System.arraycopy(LABELS.get(1310665), 0, buffer, 0, 16);
} else {
byte[] text = formatter.format(cString(LABELS.get(1310617)), day, 25);
System.arraycopy(text, 0, buffer, 0, Math.min(text.length, 24));
}
}
return buffer;
}
public static String date(long ageSeconds) {
return new String(cString(dateBytes(ageSeconds, JAVA_FORMAT)), StandardCharsets.UTF_8);
}
private static byte[] cString(byte[] text) {
int length = 0;
while (length < text.length && text[length] != 0) {
length++;
}
return Arrays.copyOf(text, length);
}
public static int compareNames(String left, String right) {
byte[] a = left.getBytes(StandardCharsets.UTF_8);
byte[] b = right.getBytes(StandardCharsets.UTF_8);
int i = 0;
while (true) {
int x = i < a.length ? a[i] & 255 : 0;
int y = i < b.length ? b[i] & 255 : 0;
if (x != y) {
return x - y;
}
if (x == 0) {
return 0;
}
i++;
}
}
public interface Formatter {
byte[] format(byte[] var1, long var2, int var4);
}
}
@@ -0,0 +1,342 @@
package dev.slinky.client.gui.profile;
import dev.slinky.client.render.RenderConstants;
import dev.slinky.config.ConfigStore;
import dev.slinky.config.ConfigurationFiles;
import dev.slinky.config.ModuleConfiguration;
import dev.slinky.module.ModuleManager;
import java.awt.Desktop;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryIteratorException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import java.util.function.LongSupplier;
public final class ProfileServices {
private ProfileServices() {
}
public interface DirectoryScanner {
void scan(Path var1, LongSupplier var2, ProfileServices.RecordReceiver var3) throws IOException;
}
public static final class Failure extends IOException {
public final int code;
public Failure(int code, String message) {
super(message);
this.code = code;
}
}
public static final class FilesHost implements ProfileServices.Host {
private static final long FILETIME_EPOCH = 116444736000000000L;
private final ModuleManager manager;
private final Path directory;
private final ConfigStore configuration;
private final LongSupplier fileTime;
private final ProfileServices.DirectoryScanner scanner;
private List<ProfileServices.Record> rows = Collections.emptyList();
public FilesHost(ModuleManager manager, Path directory, ConfigStore configuration) {
this(manager, directory, configuration, () -> System.currentTimeMillis() * 10000L + 116444736000000000L);
}
public FilesHost(ModuleManager manager, Path directory, ConfigStore configuration, LongSupplier fileTime) {
this(manager, directory, configuration, fileTime, ProfileServices.FilesHost::scanDirectory);
}
public FilesHost(ModuleManager manager, Path directory, ConfigStore configuration, LongSupplier fileTime, ProfileServices.DirectoryScanner scanner) {
this.manager = Objects.requireNonNull(manager);
this.directory = directory.toAbsolutePath().normalize();
this.configuration = Objects.requireNonNull(configuration);
this.fileTime = Objects.requireNonNull(fileTime);
this.scanner = Objects.requireNonNull(scanner);
}
private Path path(String name) throws IOException {
if (name != null && !name.isEmpty()) {
try {
Path target = this.directory.resolve(name).normalize();
if (!this.directory.equals(target.getParent())) {
throw new ProfileServices.Failure(1012, "Invalid profile name");
} else {
return target;
}
} catch (InvalidPathException var3) {
throw new ProfileServices.Failure(1006, "Invalid profile filename");
}
} else {
throw new ProfileServices.Failure(1012, "A profile name is required");
}
}
@Override
public synchronized List<ProfileServices.Record> records() throws IOException {
Map<String, Integer> retained = new TreeMap<>(ProfileMath::compareNames);
for (ModuleConfiguration.ProfileBinding binding : this.configuration.profileBindings()) {
if (binding.binding != 0 && !retained.containsKey(binding.name)) {
retained.put(binding.name, binding.binding);
}
}
for (ProfileServices.Record row : this.rows) {
if (row.binding != 0) {
retained.put(row.name, row.binding);
}
}
List<ProfileServices.Record> next = new ArrayList<>();
this.rows = next;
try {
ensure(this.directory.getParent());
ensure(this.directory);
this.scanner.scan(this.directory, this.fileTime, (name, age) -> {
if (name.getBytes(StandardCharsets.UTF_8).length >= 260) {
throw new ProfileServices.Failure(1006, "Profile filename exceeds the narrow host buffer");
} else {
Integer bindingx = retained.get(name);
next.add(new ProfileServices.Record(name, age, bindingx == null ? 0 : bindingx));
}
});
} finally {
next.sort((left, right) -> {
int order = Long.compare(left.ageSeconds, right.ageSeconds);
return order != 0 ? order : ProfileMath.compareNames(left.name, right.name);
});
this.saveBindings();
}
return this.snapshot();
}
@Override
public synchronized List<ProfileServices.Record> snapshot() {
return Collections.unmodifiableList(new ArrayList<>(this.rows));
}
private static void ensure(Path directory) throws IOException {
ConfigurationFiles.WidePath path = new ConfigurationFiles.WidePath();
path.text = ConfigurationFiles.wide(directory.toString());
try (ConfigurationFiles.NioHost host = new ConfigurationFiles.NioHost(null)) {
int code = ConfigurationFiles.ensureDirectory(path, host);
if (code != 0) {
throw new ProfileServices.Failure(code, "Could not create profile directory");
}
}
}
private static void scanDirectory(Path directory, LongSupplier fileTime, ProfileServices.RecordReceiver receiver) throws IOException {
DirectoryStream<Path> files;
try {
files = Files.newDirectoryStream(directory);
} catch (NoSuchFileException var22) {
return;
} catch (IOException var23) {
throw new ProfileServices.Failure(1013, "Could not begin profile enumeration");
}
try {
DirectoryStream<Path> opened = files;
Throwable var5 = null;
try {
long now = fileTime.getAsLong();
for (Path file : opened) {
if (!Files.isDirectory(file)) {
long modified = Files.getLastModifiedTime(file).toMillis() * 10000L + 116444736000000000L;
receiver.record(file.getFileName().toString(), ProfileMath.ageSeconds(now, modified));
}
}
} catch (Throwable var24) {
var5 = var24;
throw var24;
} finally {
if (files != null) {
if (var5 != null) {
try {
opened.close();
} catch (Throwable var21) {
var5.addSuppressed(var21);
}
} else {
files.close();
}
}
}
} catch (DirectoryIteratorException var26) {
throw new ProfileServices.Failure(1015, "Could not continue profile enumeration");
}
}
@Override
public void load(String name) throws IOException {
if (name == null) {
ModuleConfiguration.resetProfile(this.manager);
} else {
ensure(this.directory.getParent());
ensure(this.directory);
Path target = this.path(name);
if (!Files.isRegularFile(target)) {
throw new ProfileServices.Failure(1008, "Profile does not exist");
}
try {
new ConfigStore(target).loadProfile(this.manager);
} catch (ConfigurationFiles.Failure var4) {
throw new ProfileServices.Failure(var4.code, var4.getMessage());
} catch (IOException var5) {
throw new ProfileServices.Failure(5001, var5.getMessage());
}
}
this.manager.configurationSession().profileApplied(name);
}
@Override
public void save(String name, boolean overwrite) throws IOException {
Path target = this.path(name);
try {
new ConfigStore(target).saveProfile(this.manager, overwrite);
} catch (ConfigurationFiles.Failure var5) {
throw new ProfileServices.Failure(var5.code, var5.getMessage());
}
this.manager.configurationSession().profileApplied(name);
}
@Override
public void delete(String name) throws IOException {
if (name == null) {
throw new ProfileServices.Failure(6004, RenderConstants.text(1313637));
} else {
try {
Files.delete(this.path(name));
} catch (IOException var3) {
throw new ProfileServices.Failure(1011, "Could not delete profile");
}
}
}
@Override
public void explore() throws IOException {
if (!Desktop.isDesktopSupported()) {
throw new ProfileServices.Failure(4000, "Directory opener unavailable");
} else {
Desktop.getDesktop().open(this.directory.toFile());
}
}
@Override
public void saveConfiguration() throws IOException {
try {
this.configuration.save(this.manager);
} catch (ConfigurationFiles.Failure var2) {
throw new ProfileServices.Failure(var2.code, var2.getMessage());
}
}
@Override
public synchronized void bind(String name, int key) {
if (key >= 0 && key <= 103) {
ProfileServices.Record found = null;
for (ProfileServices.Record row : this.rows) {
if (ProfileMath.compareNames(row.name, name) == 0) {
found = row;
break;
}
}
if (found == null) {
throw new IllegalArgumentException("Profile is absent from the current directory records");
} else {
found.binding = key;
this.saveBindings();
this.manager.persist();
}
} else {
throw new IllegalArgumentException("Binding ID outside the recovered key table");
}
}
private void saveBindings() {
List<ModuleConfiguration.ProfileBinding> bindings = new ArrayList<>();
for (ProfileServices.Record row : this.rows) {
if (row.binding != 0) {
bindings.add(new ModuleConfiguration.ProfileBinding(row.name, row.binding));
}
}
this.configuration.profileBindings(bindings);
}
@Override
public String current() {
return this.manager.configurationSession().currentProfile();
}
@Override
public boolean pending() {
return this.manager.configurationSession().pending();
}
}
public interface Host {
List<ProfileServices.Record> records() throws IOException;
default List<ProfileServices.Record> snapshot() {
throw new UnsupportedOperationException("Profile snapshot service is required after refresh failure");
}
void load(String var1) throws IOException;
void save(String var1, boolean var2) throws IOException;
void delete(String var1) throws IOException;
void explore() throws IOException;
void saveConfiguration() throws IOException;
void bind(String var1, int var2);
String current();
boolean pending();
}
public static final class Record {
public final String name;
public final String date;
public final long ageSeconds;
public int binding;
public Record(String name, long ageSeconds, int binding) {
this.name = name;
this.ageSeconds = ageSeconds;
this.date = ProfileMath.date(ageSeconds);
this.binding = binding;
}
}
public interface RecordReceiver {
void record(String var1, long var2) throws IOException;
}
}
@@ -0,0 +1,131 @@
package dev.slinky.client.gui.settings;
import dev.slinky.client.gui.GuiModuleList;
import dev.slinky.module.Module;
import dev.slinky.module.ModuleManager;
import dev.slinky.setting.Setting;
import java.io.IOException;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
public final class GuiModuleSettings extends GuiScreen {
private final ModuleManager modules;
private final Module module;
private GuiTextField value;
private int page;
private int selected = -1;
private String message = "";
public GuiModuleSettings(ModuleManager modules, Module module) {
this.modules = modules;
this.module = module;
}
public void initGui() {
this.buttonList.clear();
List<Setting<?>> visible = this.module.visibleSettings();
int rows = Math.max(1, (this.height - 120) / 24);
this.page = Math.max(0, Math.min(this.page, Math.max(0, (visible.size() - 1) / rows)));
for (int i = this.page * rows; i < Math.min(visible.size(), (this.page + 1) * rows); i++) {
Setting<?> setting = visible.get(i);
this.buttonList
.add(
new GuiButton(
100 + i,
this.width / 2 - 170,
35 + (i - this.page * rows) * 24,
340,
20,
setting.getLabel() + " = " + (setting.isConfigured() ? setting.format() : "Choose a value")
)
);
}
this.value = new GuiTextField(1, this.fontRendererObj, this.width / 2 - 170, this.height - 64, 270, 20);
this.value.setMaxStringLength(8192);
if (this.selected >= 0 && this.selected < visible.size()) {
this.value.setText(visible.get(this.selected).format());
}
this.buttonList.add(new GuiButton(1, this.width / 2 + 104, this.height - 65, 65, 20, "Save"));
this.buttonList.add(new GuiButton(2, this.width / 2 - 170, this.height - 36, 60, 20, "Back"));
this.buttonList.add(new GuiButton(3, this.width / 2 + 40, this.height - 36, 60, 20, "Previous"));
this.buttonList.add(new GuiButton(4, this.width / 2 + 110, this.height - 36, 60, 20, "Next"));
}
protected void actionPerformed(GuiButton button) throws IOException {
if (button.id >= 100) {
this.selected = button.id - 100;
this.value.setText(this.module.visibleSettings().get(this.selected).format());
this.value.setFocused(true);
} else if (button.id == 1 && this.selected >= 0) {
try {
Setting<?> edited = this.module.visibleSettings().get(this.selected);
edited.parseAndSet(this.value.getText());
this.module.afterSettingControl(edited.getKey(), this.modules.context());
this.modules.persist();
this.message = "Saved";
this.initGui();
this.modules.configurationSession().controlChanged();
} catch (IllegalArgumentException var3) {
this.message = var3.getMessage();
}
} else if (button.id == 2) {
this.mc.displayGuiScreen(new GuiModuleList(this.modules));
} else if (button.id == 3) {
this.page--;
this.selected = -1;
this.initGui();
} else if (button.id == 4) {
this.page++;
this.selected = -1;
this.initGui();
}
}
protected void keyTyped(char character, int key) throws IOException {
if (!this.value.textboxKeyTyped(character, key)) {
super.keyTyped(character, key);
}
}
protected void mouseClicked(int x, int y, int button) throws IOException {
super.mouseClicked(x, y, button);
this.value.mouseClicked(x, y, button);
}
public void drawScreen(int x, int y, float partial) {
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, this.module.getName(), this.width / 2, 12, 16777215);
List<Setting<?>> visible = this.module.visibleSettings();
boolean changed = false;
for (GuiButton button : this.buttonList) {
button.drawButton(this.mc, x, y);
if (button.id >= 100 && button.id - 100 < visible.size()) {
changed = this.module.afterSettingControl(visible.get(button.id - 100).getKey(), this.modules.context()) || changed;
}
}
if (changed) {
this.modules.persist();
for (GuiButton buttonx : this.buttonList) {
if (buttonx.id >= 100 && buttonx.id - 100 < visible.size()) {
Setting<?> setting = visible.get(buttonx.id - 100);
buttonx.displayString = setting.getLabel() + " = " + (setting.isConfigured() ? setting.format() : "Choose a value");
}
}
}
this.value.drawTextBox();
this.drawString(this.fontRendererObj, this.message, 12, this.height - 90, 16777215);
}
public boolean doesGuiPauseGame() {
return false;
}
}
@@ -0,0 +1,498 @@
package dev.slinky.client.gui.settings;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import dev.slinky.client.gui.GuiMath;
import dev.slinky.client.gui.GuiPresentation;
import dev.slinky.client.gui.GuiWidgets;
import dev.slinky.client.inventory.ItemPolicyService;
import dev.slinky.client.render.DrawPlan;
import dev.slinky.client.render.world.LoadedChunkAccess;
import dev.slinky.inject.Platform;
import dev.slinky.module.Module;
import dev.slinky.module.ModuleManager;
import dev.slinky.module.catalog.ModuleCatalog;
import dev.slinky.module.combat.WeaponsModule;
import dev.slinky.module.world.GhostHandModule;
import dev.slinky.setting.BooleanSetting;
import dev.slinky.setting.ChoiceSetting;
import dev.slinky.setting.ColorSetting;
import dev.slinky.setting.NamedColorListSetting;
import dev.slinky.setting.NumberSetting;
import dev.slinky.setting.RangeSetting;
import dev.slinky.setting.Setting;
import dev.slinky.setting.StringListSetting;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.Map;
import java.util.Set;
public final class InlineModuleSettings {
private static final JsonObject METADATA = readMetadata();
private static final Map<String, List<String>> ORDER = readOrder();
private static final List<String> ITEMS = readItems(false);
private static final List<String> BLOCKS = readItems(true);
private final ModuleManager manager;
private final GuiWidgets widgets;
private final Map<Setting<?>, InlineModuleSettings.Record> records = new IdentityHashMap<>();
private final GuiMath.Toggle sticks = new GuiMath.Toggle();
private final GuiMath.Toggle swordExcluded = new GuiMath.Toggle();
public InlineModuleSettings(ModuleManager manager, GuiPresentation presentation, GuiPresentation.Tooltip tooltip) {
this.manager = manager;
this.widgets = new GuiWidgets(presentation, tooltip, (format, values) -> {
Object[] args = new Object[values.length];
for (int i = 0; i < values.length; i++) {
args[i] = values[i];
}
return String.format(Locale.ROOT, format.replace("%0.", "%."), args);
});
}
private static JsonObject readMetadata() {
try (InputStreamReader reader = new InputStreamReader(Platform.resource("/assets/slinkysemantic/WidgetMetadata.json"), StandardCharsets.UTF_8)) {
return new JsonParser().parse(reader).getAsJsonObject();
} catch (IOException var14) {
throw new ExceptionInInitializerError(var14);
}
}
private static Map<String, List<String>> readOrder() {
Map<String, List<String>> result = new LinkedHashMap<>();
try (InputStreamReader reader = new InputStreamReader(Platform.resource("/assets/slinkysemantic/ModuleUi.json"), StandardCharsets.UTF_8)) {
for (JsonElement element : new JsonParser().parse(reader).getAsJsonObject().getAsJsonArray("modules")) {
JsonObject module = element.getAsJsonObject();
Map<String, Set<String>> edges = new LinkedHashMap<>();
for (JsonElement variant : module.getAsJsonArray("variants")) {
String previous = null;
Map<String, Integer> counts = new HashMap<>();
for (JsonElement control : variant.getAsJsonObject().getAsJsonArray("controls")) {
JsonObject row = control.getAsJsonObject();
String token;
if (row.has("section")) {
String label = row.get("section").getAsString();
int count = counts.containsKey(label) ? counts.get(label) : 0;
counts.put(label, count + 1);
token = "section:" + count + ":" + label;
} else {
token = row.get("key").getAsString();
}
if (!edges.containsKey(token)) {
edges.put(token, new LinkedHashSet<>());
}
if (previous != null) {
edges.get(previous).add(token);
}
previous = token;
}
}
List<String> order = new ArrayList<>();
while (order.size() < edges.size()) {
String next = null;
for (String tokenx : edges.keySet()) {
if (!order.contains(tokenx)) {
boolean incoming = false;
for (Entry<String, Set<String>> edge : edges.entrySet()) {
if (!order.contains(edge.getKey()) && edge.getValue().contains(tokenx)) {
incoming = true;
break;
}
}
if (!incoming) {
next = tokenx;
break;
}
}
}
if (next == null) {
throw new IllegalStateException("Contradictory recovered UI order " + module.get("module").getAsString());
}
order.add(next);
}
result.put(module.get("module").getAsString(), Collections.unmodifiableList(order));
}
return Collections.unmodifiableMap(result);
} catch (IOException var27) {
throw new ExceptionInInitializerError(var27);
}
}
private InlineModuleSettings.Record record(Setting<?> setting) {
InlineModuleSettings.Record record = this.records.get(setting);
if (record == null) {
record = new InlineModuleSettings.Record();
this.records.put(setting, record);
}
return record;
}
private static String text(JsonObject row, String key, String fallback) {
JsonElement value = row.get(key);
return value != null && !value.isJsonNull() ? value.getAsString() : fallback;
}
private static float parameter(JsonObject row, String key) {
JsonElement value = row.get(key);
return value == null ? 0.0F : value.getAsJsonObject().get("value").getAsFloat();
}
private static JsonObject schema(Module module, Setting<?> setting) {
for (JsonElement row : ModuleCatalog.module(module.getName()).getAsJsonArray("settings")) {
JsonObject value = row.getAsJsonObject();
if (value.get("key").getAsString().equals(setting.getKey())) {
return value;
}
}
throw new IllegalStateException("Missing widget schema");
}
private static JsonObject metadata(Module module, Setting<?> setting) {
return METADATA.getAsJsonObject(module.getName()).getAsJsonObject(setting.getKey());
}
public List<String> render(Module module, GuiMath.Runtime state, DrawPlan plan, GuiMath.Layout layout, float[] accent, double now) {
List<String> drawn = new ArrayList<>();
for (String token : ORDER.get(module.getName())) {
ModuleSettingsLayout.Control next = null;
Map<String, Integer> counts = new HashMap<>();
for (ModuleSettingsLayout.Control control : ModuleSettingsLayout.controls(module)) {
String candidate;
if (control.setting == null) {
int count = counts.containsKey(control.section) ? counts.get(control.section) : 0;
counts.put(control.section, count + 1);
candidate = "section:" + count + ":" + control.section;
} else {
candidate = control.setting.getKey();
}
if (token.equals(candidate)) {
next = control;
break;
}
}
if (next != null) {
drawn.add(token);
if (next.setting == null) {
this.widgets.section(plan, layout, next.section);
} else {
Setting<?> setting = next.setting;
if (module instanceof WeaponsModule && setting.getKey().equals("extra_items")) {
WeaponsModule weapons = (WeaponsModule)module;
boolean old = weapons.sticksEnabled();
boolean nextValue = this.widgets.checkbox(state, plan, layout, "Sticks", this.sticks, old, accent, now);
if (nextValue != old) {
weapons.setSticksEnabled(nextValue);
this.changed(module, setting, true);
}
drawn.add("derived:sticks");
}
this.draw(module, setting, state, plan, layout, accent, now);
if (module instanceof GhostHandModule && setting.getKey().equals("require_mouse_pressed")) {
GhostHandModule ghost = (GhostHandModule)module;
boolean old = ghost.swordExcluded();
boolean nextValue = this.widgets.checkbox(state, plan, layout, "Not holding a sword", this.swordExcluded, old, accent, now);
if (nextValue != old) {
ghost.setSwordExcluded(nextValue);
this.changed(module, module.findSetting("allow_using_sword"), true);
}
drawn.add("derived:sword_excluded");
}
}
}
}
return Collections.unmodifiableList(drawn);
}
private void changed(Module module, Setting<?> setting, boolean dirty) {
module.afterSettingControl(setting.getKey(), this.manager.context());
if (dirty) {
this.manager.configurationSession().controlChanged();
}
this.manager.persist();
}
private void draw(Module module, Setting<?> setting, GuiMath.Runtime state, DrawPlan plan, GuiMath.Layout layout, float[] accent, double now) {
JsonObject info = metadata(module, setting);
JsonObject schema = schema(module, setting);
String label = text(info, "label", setting.getLabel());
InlineModuleSettings.Record r = this.record(setting);
boolean dirty = false;
boolean mutated = false;
if (setting instanceof BooleanSetting) {
BooleanSetting value = (BooleanSetting)setting;
boolean next = this.widgets.checkbox(state, plan, layout, label, r.toggle, value.isEnabled(), accent, now);
if (next != value.isEnabled()) {
value.set(Boolean.valueOf(next));
mutated = true;
dirty = true;
}
} else if (setting instanceof NumberSetting) {
NumberSetting value = (NumberSetting)setting;
float next = this.widgets
.number(
state,
plan,
layout,
label,
text(info, "format", null),
r.lower,
r.number,
(float)value.getMinimum(),
(float)value.getMaximum(),
parameter(schema, "step_observation"),
parameter(schema, "extra_ui_parameter_observation"),
value.floatValue(),
accent,
now
);
dirty = r.number.active;
if (Float.floatToRawIntBits(next) != Float.floatToRawIntBits(value.floatValue())) {
value.set(Double.valueOf((double)next));
mutated = true;
}
} else if (setting instanceof RangeSetting) {
RangeSetting value = (RangeSetting)setting;
RangeSetting.Value old = value.get();
JsonObject extra = schema.getAsJsonObject("extra_ui_parameter_observations");
float step = extra == null ? 0.0F : parameter(extra, "0x30");
float scale = extra == null ? 0.0F : parameter(extra, "0x34");
float[] next = this.widgets
.range(
state,
plan,
layout,
label,
text(info, "format", null),
text(info, "pair_format", null),
r.lower,
r.upper,
r.range,
(float)value.minimum(),
(float)value.maximum(),
step,
scale,
(float)old.lower,
(float)old.upper,
accent,
now
);
dirty = r.range.lower.active || r.range.upper.active;
if (next[0] != (float)old.lower || next[1] != (float)old.upper) {
value.set(new RangeSetting.Value((double)next[0], (double)next[1]));
mutated = true;
}
} else if (setting instanceof ChoiceSetting) {
ChoiceSetting value = (ChoiceSetting)setting;
r.selected[0] = value.index();
dirty = (
this.widgets.choice(state, plan, layout, label, r.choice, value.getOptions(), r.selected, info.get("flag").getAsInt(), accent, now, index -> {
value.set(Integer.valueOf(index));
this.changed(module, setting, false);
}) & 0xFF
)
!= 0;
if (r.selected[0] != value.index()) {
value.set(Integer.valueOf(r.selected[0]));
mutated = true;
}
} else if (setting instanceof ColorSetting) {
ColorSetting value = (ColorSetting)setting;
ColorSetting.Value rgb = value.get();
dirty = this.widgets.color(state, plan, layout, label, new float[]{rgb.red, rgb.green, rgb.blue}, nextx -> {
value.set(new ColorSetting.Value(nextx[0], nextx[1], nextx[2]));
this.changed(module, setting, false);
}, now);
} else {
dirty = this.widgets
.list(
state,
plan,
layout,
label,
text(info, "title", label),
filter(module, setting),
setting instanceof NamedColorListSetting ? 1 : 0,
this.list(module, setting),
info.get("suggestions_endpoint_present").getAsBoolean() ? suggestions(module) : null,
now
);
}
boolean coupled = false;
if (!(setting instanceof NamedColorListSetting) && !(setting instanceof StringListSetting) || dirty || mutated) {
coupled = module.afterSettingControl(setting.getKey(), this.manager.context());
}
if (dirty) {
this.manager.configurationSession().controlChanged();
}
if (mutated || coupled) {
this.manager.persist();
}
}
private static GuiMath.Filter filter(Module module, Setting<?> setting) {
return module.getName().equals("Friends") ? (text, ch) -> {
if (text.length() < 16 && (ch >= 97 && ch <= 122 || ch >= 65 && ch <= 90 || ch >= 48 && ch <= 57 || ch == 95)) {
text.append((char)ch);
}
} : GuiMath::catalogFilter;
}
private static List<String> readItems(boolean blocks) {
try (InputStreamReader reader = new InputStreamReader(Platform.resource("/assets/slinkysemantic/ItemCatalog.json"), StandardCharsets.UTF_8)) {
List<String> names = new ArrayList<>();
for (JsonElement element : new JsonParser().parse(reader).getAsJsonArray()) {
JsonObject item = element.getAsJsonObject();
if (!blocks || item.get("id").getAsInt() < 256) {
names.add(item.get("name").getAsString());
}
}
return Collections.unmodifiableList(names);
} catch (IOException var17) {
throw new ExceptionInInitializerError(var17);
}
}
private static List<String> suggestions(Module module) {
return module.getName().equals("Block ESP") ? BLOCKS : ITEMS;
}
private GuiWidgets.ListData list(final Module module, final Setting<?> setting) {
return new GuiWidgets.ListData() {
@Override
public long size() {
return setting instanceof NamedColorListSetting
? (long)((NamedColorListSetting)setting).get().size()
: (long)((StringListSetting)setting).get().size();
}
@Override
public String name(long index) {
return setting instanceof NamedColorListSetting
? ((NamedColorListSetting)setting).get().get((int)index).name
: ((StringListSetting)setting).get().get((int)index);
}
@Override
public float[] color(long index) {
ColorSetting.Value value = ((NamedColorListSetting)setting).get().get((int)index).color;
return new float[]{value.red, value.green, value.blue};
}
@Override
public void color(long index, float[] rgb) {
NamedColorListSetting value = (NamedColorListSetting)setting;
List<NamedColorListSetting.Entry> rows = new ArrayList<>(value.get());
rows.set((int)index, new NamedColorListSetting.Entry(rows.get((int)index).name, new ColorSetting.Value(rgb[0], rgb[1], rgb[2])));
value.set(rows);
InlineModuleSettings.this.changed(module, setting, false);
}
@Override
public void add(String name, float[] rgb) {
if (setting instanceof NamedColorListSetting) {
int id = module.getName().equals("Block ESP") ? LoadedChunkAccess.blockIdentifier(name) : ItemPolicyService.identifier(name);
if (id < 0) {
return;
}
NamedColorListSetting value = (NamedColorListSetting)setting;
List<NamedColorListSetting.Entry> rows = new ArrayList<>(value.get());
for (NamedColorListSetting.Entry row : rows) {
if (row.name.equals(name)) {
return;
}
}
rows.add(new NamedColorListSetting.Entry(name, new ColorSetting.Value(rgb[0], rgb[1], rgb[2])));
rows.sort((a, b) -> Integer.compare(ItemPolicyService.identifier(a.name), ItemPolicyService.identifier(b.name)));
value.set(rows);
} else {
StringListSetting value = (StringListSetting)setting;
List<String> rows = new ArrayList<>(value.get());
if (rows.contains(name)) {
return;
}
rows.add(name);
value.set(rows);
}
InlineModuleSettings.this.changed(module, setting, false);
}
@Override
public void remove(long index) {
if (setting instanceof NamedColorListSetting) {
NamedColorListSetting value = (NamedColorListSetting)setting;
List<NamedColorListSetting.Entry> rows = new ArrayList<>(value.get());
rows.remove((int)index);
value.set(rows);
} else {
StringListSetting value = (StringListSetting)setting;
List<String> rows = new ArrayList<>(value.get());
rows.remove((int)index);
value.set(rows);
}
InlineModuleSettings.this.changed(module, setting, false);
}
};
}
private static final class Record {
final Object lower = new Object();
final Object upper = new Object();
final GuiMath.Toggle toggle = new GuiMath.Toggle();
final GuiMath.Slider number = new GuiMath.Slider();
final GuiWidgets.Range range = new GuiWidgets.Range();
final GuiWidgets.Choice choice = new GuiWidgets.Choice();
final int[] selected = new int[]{0};
private Record() {
}
}
}
@@ -0,0 +1,120 @@
package dev.slinky.client.gui.settings;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import dev.slinky.inject.Platform;
import dev.slinky.module.Module;
import dev.slinky.setting.BooleanSetting;
import dev.slinky.setting.ChoiceSetting;
import dev.slinky.setting.Setting;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public final class ModuleSettingsLayout {
private static final Map<String, JsonObject> LAYOUTS = read();
private ModuleSettingsLayout() {
}
private static Map<String, JsonObject> read() {
InputStream stream = Platform.resource("/assets/slinkysemantic/ModuleUi.json");
if (stream == null) {
throw new IllegalStateException("Missing recovered UI layouts");
} else {
try (Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
Map<String, JsonObject> result = new LinkedHashMap<>();
for (JsonElement row : new JsonParser().parse(reader).getAsJsonObject().getAsJsonArray("modules")) {
JsonObject layout = row.getAsJsonObject();
String name = layout.get("module").getAsString();
if (result.put(name, layout) != null) {
throw new IllegalStateException("Duplicate UI layout " + name);
}
}
return Collections.unmodifiableMap(result);
} catch (IOException var18) {
throw new IllegalStateException(var18);
}
}
}
public static List<ModuleSettingsLayout.Control> controls(Module module) {
JsonObject layout = LAYOUTS.get(module.getName());
if (layout == null) {
throw new IllegalStateException("Missing module UI " + module.getName());
} else {
JsonArray gates = layout.getAsJsonArray("gates");
for (JsonElement row : layout.getAsJsonArray("variants")) {
JsonObject variant = row.getAsJsonObject();
JsonArray values = variant.getAsJsonArray("values");
boolean match = true;
for (int i = 0; i < gates.size(); i++) {
Setting<?> setting = module.findSetting(gates.get(i).getAsString());
int value;
if (setting instanceof BooleanSetting) {
value = ((BooleanSetting)setting).isEnabled() ? 1 : 0;
} else {
if (!(setting instanceof ChoiceSetting)) {
throw new IllegalStateException("Invalid recovered UI gate");
}
value = ((ChoiceSetting)setting).index();
}
if (value != values.get(i).getAsInt()) {
match = false;
break;
}
}
if (match) {
List<ModuleSettingsLayout.Control> result = new ArrayList<>();
for (JsonElement element : variant.getAsJsonArray("controls")) {
JsonObject control = element.getAsJsonObject();
if (control.has("section")) {
result.add(new ModuleSettingsLayout.Control(control.get("section").getAsString(), null));
} else {
String key = control.get("key").getAsString();
Setting<?> settingx = module.findSetting(key);
if (settingx == null) {
throw new IllegalStateException("Missing recovered UI setting " + module.getName() + "." + key);
}
if (module.settingVisible(key)) {
result.add(new ModuleSettingsLayout.Control(null, settingx));
}
}
}
return Collections.unmodifiableList(result);
}
}
throw new IllegalStateException("No recovered UI variant for " + module.getName());
}
}
public static final class Control {
public final String section;
public final Setting<?> setting;
private Control(String section, Setting<?> setting) {
this.section = section;
this.setting = setting;
}
}
}