Skip to content
Merged

Dev #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"diagnostics.disable": [
"undefined-global",
"lowercase-global",
"unused-local"
]
}
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

// GraalVM JavaScript for scripting (replacement for Nashorn)
// GraalVM JavaScript for core (replacement for Nashorn)
include(implementation('org.graalvm.js:js:22.3.1'))
include(implementation('org.graalvm.js:js-scriptengine:22.3.1'))
include(implementation('org.graalvm.regex:regex:22.3.1'))
Expand All @@ -92,6 +92,9 @@ dependencies {

// i do not want to make a renderer
include(modImplementation("io.github.0x3c50.renderer:renderer-fabric:2.1.1"))

// LuaJ for Lua core
include(implementation("org.luaj:luaj-jse:3.0.1"))
}

processResources {
Expand Down
7 changes: 6 additions & 1 deletion src/client/java/works/alya/AlyaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import works.alya.module.impl.world.TimerModule;
import works.alya.module.impl.visual.clickgui.ClickGUIModule;
import works.alya.module.impl.visual.esp.ESPModule;
import works.alya.script.core.ScriptManager;
import works.alya.utilities.misc.IconLoader;
import works.alya.utilities.misc.AlyaConstants;
import net.fabricmc.api.ClientModInitializer;
Expand Down Expand Up @@ -87,6 +88,8 @@ public void onInitializeClient() {
KeybindManager.getInstance().initialize();
VisualManager.getInstance().initialize();

ScriptManager.getInstance().init();

CommandRegistrationCallback.EVENT.register((
dispatcher,
registryAccess,
Expand Down Expand Up @@ -178,7 +181,9 @@ private static void initializeCommands() {
new ConfigCommand(),
new BindCommand(),
new SettingsCommand(),
new VClipCommand()
new VClipCommand(),
new ScriptCommand(),
new NameCommand()
);
}

Expand Down
48 changes: 48 additions & 0 deletions src/client/java/works/alya/command/impl/NameCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) Alya Client 2024-2025.
*
* This file belongs to Alya Client,
* an open-source Fabric injection client.
* Rye GitHub: https://github.com/AlyaClient/alya-beta.git
*
* THIS PROJECT DOES NOT HAVE A WARRANTY.
*
* Alya (and subsequently, its files) are all licensed under the MIT License.
* Alya should have come with a copy of the MIT License.
* If it did not, you may obtain a copy here:
* MIT License: https://opensource.org/license/mit
*
*/

package works.alya.command.impl;

import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import works.alya.command.AbstractCommand;
import works.alya.utilities.misc.AlyaConstants;
import works.alya.utilities.misc.ChatUtility;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;

public class NameCommand extends AbstractCommand {
public NameCommand() {
super("name");
}

@Override
protected void build(LiteralArgumentBuilder<ServerCommandSource> builder) {
builder
.then(CommandManager.argument("name", StringArgumentType.word())
.executes(context -> {
AlyaConstants.NAME = StringArgumentType.getString(context, "name");
return 1;
}))
.executes(this::usage);
}

private int usage(CommandContext<ServerCommandSource> serverCommandSourceCommandContext) {
ChatUtility.sendInfo("Usage: .name <name>");
return 1;
}
}
59 changes: 59 additions & 0 deletions src/client/java/works/alya/command/impl/ScriptCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) Alya Client 2024-2025.
*
* This file belongs to Alya Client,
* an open-source Fabric injection client.
* Rye GitHub: https://github.com/AlyaClient/alya-beta.git
*
* THIS PROJECT DOES NOT HAVE A WARRANTY.
*
* Alya (and subsequently, its files) are all licensed under the MIT License.
* Alya should have come with a copy of the MIT License.
* If it did not, you may obtain a copy here:
* MIT License: https://opensource.org/license/mit
*
*/

package works.alya.command.impl;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.ServerCommandSource;
import works.alya.AlyaClient;
import works.alya.command.AbstractCommand;
import works.alya.module.Module;
import works.alya.module.ModuleCategory;
import works.alya.script.core.ScriptManager;
import works.alya.utilities.misc.ChatUtility;

/**
* Command for managing scripts in the Alya Client.
*/
public class ScriptCommand extends AbstractCommand {

public ScriptCommand() {
super("scripts");
}

@Override
protected void build(LiteralArgumentBuilder<ServerCommandSource> builder) {
builder
.then(literal("reload")
.executes(context -> {
for(Module module : AlyaClient.INSTANCE.getModuleRepository().getModules()) {
if(module.getCategory().equals(ModuleCategory.SCRIPTS)) {
module.setEnabled(false);
}
}

ScriptManager.getInstance().loadScripts();
ChatUtility.sendSuccess("§aScripts reloaded successfully!");
return 1;
}));
}

private static LiteralArgumentBuilder<ServerCommandSource> literal(String name) {
if(name.isEmpty()) throw new IllegalArgumentException("Name cannot be empty!");

return LiteralArgumentBuilder.literal(name);
}
}
38 changes: 36 additions & 2 deletions src/client/java/works/alya/config/VisualManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public void updateVisualModuleData(Module module) {
LOGGER.error("Failed to get DragUtility from module {}: {}", moduleName, e.getMessage());
}

Map<String, Object> settingValues = new HashMap<>();
for(works.alya.config.setting.Setting<?> setting : module.getSettings()) {
if(!setting.getValue().equals(setting.getDefaultValue())) {
settingValues.put(setting.getName(), setting.getValue());
}
}
data.setSettingValues(settingValues);

visualModulesData.put(moduleName, data);
}

Expand Down Expand Up @@ -177,7 +185,22 @@ public void applyVisualDataToModule(Module module) {
VisualModuleData data = visualModulesData.get(moduleName);

if(data != null) {
module.setEnabled(data.isEnabled());
Map<String, Object> settingValues = data.getSettingValues();
if(settingValues != null && !settingValues.isEmpty()) {
for(works.alya.config.setting.Setting<?> setting : module.getSettings()) {
Object value = settingValues.get(setting.getName());
if(value != null) {
try {
if(!value.equals(setting.getDefaultValue())) {
setting.setValueFromObject(value);
}
} catch(Exception e) {
LOGGER.error("Failed to set value for setting {} in module {}: {}",
setting.getName(), moduleName, e.getMessage());
}
}
}
}

try {
for(Field field : module.getClass().getDeclaredFields()) {
Expand All @@ -194,6 +217,8 @@ public void applyVisualDataToModule(Module module) {
} catch(Exception e) {
LOGGER.error("Failed to set DragUtility for module {}: {}", moduleName, e.getMessage());
}

module.setEnabled(data.isEnabled());
}
}

Expand All @@ -204,6 +229,7 @@ private static class VisualModuleData {
private boolean enabled = false;
private int x = 4;
private int y = 4;
private Map<String, Object> settingValues = new HashMap<>();

public boolean isEnabled() {
return enabled;
Expand All @@ -228,5 +254,13 @@ public int getY() {
public void setY(int y) {
this.y = y;
}

public Map<String, Object> getSettingValues() {
return settingValues;
}

public void setSettingValues(Map<String, Object> settingValues) {
this.settingValues = settingValues;
}
}
}
}
19 changes: 17 additions & 2 deletions src/client/java/works/alya/config/setting/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package works.alya.config.setting;

import works.alya.config.VisibilityCondition;
import java.util.function.Consumer;

public class Setting<T> {
private final String name;
Expand All @@ -26,6 +27,7 @@ public class Setting<T> {
private final T minValue;
private final T maxValue;
private VisibilityCondition visibilityCondition = () -> true;
private Consumer<Setting<T>> changeCallback = null;

@SuppressWarnings("unused")
public Setting(String name, String description, T defaultValue) {
Expand All @@ -35,8 +37,8 @@ public Setting(String name, String description, T defaultValue) {
public Setting(String name, String description, T defaultValue, T minValue, T maxValue) {
this.name = name;
this.description = description;
this.value = defaultValue;
this.defaultValue = defaultValue;
this.value = defaultValue;
this.minValue = minValue;
this.maxValue = maxValue;
}
Expand Down Expand Up @@ -73,6 +75,19 @@ public void setValue(T value) {
}

this.value = value;

if(this.changeCallback != null) {
this.changeCallback.accept(this);
}
}

/**
* Sets a callback to be called when the setting value changes.
*
* @param callback The callback to call when the value changes
*/
public void setChangeCallback(Consumer<Setting<T>> callback) {
this.changeCallback = callback;
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -137,4 +152,4 @@ public Setting<T> setVisibilityCondition(VisibilityCondition condition) {
public boolean isVisible() {
return visibilityCondition.isVisible();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public class ModeSetting extends Setting<String> {
public ModeSetting(String name, String description, String defaultValue, String... modes) {
super(name, description, defaultValue);
this.modes = new ArrayList<>(Arrays.asList(modes));

// if(!this.modes.contains(defaultValue)) {
// throw new IllegalArgumentException("Default value must be one of the modes");
// }
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/client/java/works/alya/event/EventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

package works.alya.event;

import works.alya.AlyaClient;
import works.alya.event.pool.EventSubscriberPool;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("unchecked")
public final class EventBus {
private List<IEventListener<?>> listeners = new ArrayList<>();
private final List<IEventListener<?>> listeners = new ArrayList<>();

public <T> void register(IEventListener<T> listener) {
listeners.add(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package works.alya.mixin.client.misc;

import com.mojang.blaze3d.buffers.GpuBufferSlice;
import org.spongepowered.asm.mixin.Unique;
import works.alya.AlyaClient;
import works.alya.config.VisualManager;
import works.alya.event.impl.Render3DEvent;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.RenderTickCounter;
Expand Down Expand Up @@ -49,4 +51,4 @@ private void onRender(
new Render3DEvent(tickCounter.getFixedDeltaTicks())
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ScreenMixin {
@Inject(method = "renderPanoramaBackground", at = @At("HEAD"), cancellable = true)
private void interceptPanoramaBackground(DrawContext context, float deltaTicks, CallbackInfo ci) {
if(!Settings.SHOW_PANORAMA) {
BackgroundUtility.drawBackground(context);
BackgroundUtility.drawStarField(context);

ci.cancel();
}
Expand Down
Loading