Skip to content
Merged
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
47 changes: 46 additions & 1 deletion src/main/java/dev/thoq/lua/LuaEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class LuaEngine {

Expand Down Expand Up @@ -114,8 +116,18 @@ public void loadAll() {
}

public void reload() {
final Map<String, ModuleSnapshot> snapshots = new HashMap<>();
new ArrayList<>(Alya.getInstance().getModuleManager().getModules()).stream()
.filter(module -> module instanceof dev.thoq.lua.api.LuaModule)
.map(module -> (dev.thoq.lua.api.LuaModule) module)
.forEach(module -> {
final Map<String, String> settingValues = new HashMap<>();
module.getSettings().forEach(s -> settingValues.put(s.getName(), s.getValueAsString()));
snapshots.put(module.getName(), new ModuleSnapshot(module.isEnabled(), module.getKeyCode(), settingValues));
});

eventApi.clearSubscriptions();
new java.util.ArrayList<>(Alya.getInstance().getModuleManager().getModules()).stream()
new ArrayList<>(Alya.getInstance().getModuleManager().getModules()).stream()
.filter(module -> module instanceof dev.thoq.lua.api.LuaModule)
.forEach(module -> {
if (module.isEnabled()) {
Expand All @@ -129,6 +141,39 @@ public void reload() {
loadedScripts.clear();

loadAll();

new ArrayList<>(Alya.getInstance().getModuleManager().getModules()).stream()
.filter(module -> module instanceof dev.thoq.lua.api.LuaModule)
.map(module -> (dev.thoq.lua.api.LuaModule) module)
.forEach(module -> {
final ModuleSnapshot snapshot = snapshots.get(module.getName());
if (snapshot == null) return;
module.setKeyCode(snapshot.keyCode);
module.getSettings().forEach(setting -> {
final String savedValue = snapshot.settingValues.get(setting.getName());
if (savedValue != null) {
try {
setting.setValueFromString(savedValue);
} catch (final Exception ignored) {
}
}
});
if (snapshot.enabled) {
module.setEnabled(true);
}
});
}

private static final class ModuleSnapshot {
final boolean enabled;
final int keyCode;
final Map<String, String> settingValues;

ModuleSnapshot(final boolean enabled, final int keyCode, final Map<String, String> settingValues) {
this.enabled = enabled;
this.keyCode = keyCode;
this.settingValues = settingValues;
}
}

public Globals getGlobals() {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/thoq/lua/api/LuaCombatApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ public Varargs invoke(Varargs args) {
}
});

set("getEntityById", new OneArgFunction() {
@Override
public LuaValue call(LuaValue idValue) {
if (mc.theWorld == null || mc.thePlayer == null) return LuaValue.NIL;
Entity entity = mc.theWorld.getEntityByID(idValue.toint());
if (!(entity instanceof EntityLivingBase)) return LuaValue.NIL;
return livingToTable((EntityLivingBase) entity);
}
});

set("setMoveForward", new OneArgFunction() {
@Override
public LuaValue call(LuaValue v) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/thoq/util/movement/MovementUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public static double getAllowedHDistNCP() {
}

public static void setSpeed(final double speed) {
final double yaw = getDirection();
if(!isMoving())
if (MC.thePlayer.movementInput.moveForward == 0F)
return;

final double yaw = getDirection();
MC.thePlayer.motionX = -MathHelper.sin((float) yaw) * speed;
MC.thePlayer.motionZ = MathHelper.cos((float) yaw) * speed;
}
Expand Down
37 changes: 30 additions & 7 deletions src/main/resources/lua/modules/combat/killaura.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ local moduleTable = alya.modules.register("KillAura", "Automatically attacks pla

local minCps = moduleTable.addNumberSetting("Minimum CPS", "", 10, 1, 100, 0.1)
local maxCps = moduleTable.addNumberSetting("Maximum CPS", "", 10, 1, 100, 0.1)
local reach = moduleTable.addNumberSetting("Reach", "", 4, 3, 8, 0.1)
local seekRange = moduleTable.addNumberSetting("Seek Range", "", 6, 1, 16, 0.1)
local swingRange = moduleTable.addNumberSetting("Swing Range", "", 4, 1, 8, 0.1)
local attackRange = moduleTable.addNumberSetting("Attack Range", "", 3.5, 1, 8, 0.1)
local rotate = moduleTable.addBooleanSetting("Rotate", "", true)
local rotMode = moduleTable.addModeSetting("Rotation Mode", "", "Blatant", "Blatant", "Legit", "Snap", "Spin")
local autoBlock = moduleTable.addBooleanSetting("Auto Block", "", false)
Expand All @@ -26,6 +28,7 @@ smoothness.setVisibility(function() return rotMode.is("Legit") end)
local timer = alya.timer.create()
local blocking = false
local wasBlocked = false
local lockedTargetId = nil
local lastYaw = alya.combat.getPlayerYaw()
local lastPitch = alya.combat.getPlayerPitch()
local lastRotTime = alya.mc.getCurrentTime()
Expand Down Expand Up @@ -86,9 +89,14 @@ local function snapRotation(yaw, pitch)
end

local function doAttack(target)
if enchPart.isEnabled() then alya.combat.onEnchantmentCritical(target.id) end
if critPart.isEnabled() then alya.combat.onCriticalHit(target.id) end
alya.combat.attackEntity(target.id)
if target.distance > attackRange.getValue() then return end
if target.distance <= swingRange.getValue() then
if enchPart.isEnabled() then alya.combat.onEnchantmentCritical(target.id) end
if critPart.isEnabled() then alya.combat.onCriticalHit(target.id) end
alya.combat.attackEntity(target.id)
else
alya.combat.swingItem()
end
end

local function shouldAttack()
Expand Down Expand Up @@ -126,15 +134,29 @@ alya.events.on("motion", function(event)
if not moduleTable.isEnabled() then return end
if not event.isPre() then return end

local targets = alya.combat.getEntities(reach.getValue(), raycast.isEnabled(), targetPlayers.isEnabled(), targetHostile.isEnabled(), targetPassive.isEnabled())
local targets = alya.combat.getEntities(seekRange.getValue(), raycast.isEnabled(), targetPlayers.isEnabled(), targetHostile.isEnabled(), targetPassive.isEnabled())

for i = #targets, 1, -1 do
if alya.combat.isFriend(targets[i].name) then
if alya.combat.isFriend(targets[i].name) or targets[i].health <= 0 then
table.remove(targets, i)
end
end

local primary = targets[1]
local primary = nil
if lockedTargetId ~= nil then
local locked = alya.combat.getEntityById(lockedTargetId)
if locked ~= nil and locked.distance <= seekRange.getValue() and locked.health > 0 and not alya.combat.isFriend(locked.name) then
primary = locked
else
lockedTargetId = nil
end
end
if primary == nil then
primary = targets[1]
if primary ~= nil then
lockedTargetId = primary.id
end
end

blocking = autoBlock.isEnabled() and primary ~= nil and alya.combat.isHoldingSword()

Expand Down Expand Up @@ -204,6 +226,7 @@ moduleTable.onDisable(function()
end
blocking = false
wasBlocked = false
lockedTargetId = nil
lastYaw = alya.combat.getPlayerYaw()
lastPitch = alya.combat.getPlayerPitch()
lastRotTime = alya.mc.getCurrentTime()
Expand Down
55 changes: 38 additions & 17 deletions src/main/resources/lua/modules/combat/targetstrafe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,37 @@ local targetHostile = moduleTable.addBooleanSetting("Target Hostile", "", false)
local targetPassive = moduleTable.addBooleanSetting("Target Passive", "", false)

local direction = 1
local lockedTargetId = nil

local function isValidTarget(entity)
if entity == nil then return false end
if entity.health <= 0 then return false end
if alya.combat.isFriend(entity.name) then return false end
return true
end

local function getTarget()
if lockedTargetId ~= nil then
local locked = alya.combat.getEntityById(lockedTargetId)
if locked ~= nil and locked.distance <= 32 and isValidTarget(locked) then
return locked
end
lockedTargetId = nil
end

local targets = alya.combat.getEntities(32, false, targetPlayers.isEnabled(), targetHostile.isEnabled(),
targetPassive.isEnabled())
for i = #targets, 1, -1 do
if alya.combat.isFriend(targets[i].name) then
if not isValidTarget(targets[i]) then
table.remove(targets, i)
end
end
return targets[1]

local best = targets[1]
if best ~= nil then
lockedTargetId = best.id
end
return best
end

alya.events.on("playerinput", function(event)
Expand Down Expand Up @@ -47,29 +68,28 @@ alya.events.on("playerinput", function(event)

local nx = dx / dist
local nz = dz / dist

local tx = -nz * direction
local tz = nx * direction
local r = radius.getValue()
local radialDelta = dist - r
local corrX = -nx * radialDelta * 0.5
local corrZ = -nz * radialDelta * 0.5
local moveX = tx + corrX
local moveZ = tz + corrZ

local moveLen = math.sqrt(moveX * moveX + moveZ * moveZ)
if moveLen > 1 then
moveX = moveX / moveLen
moveZ = moveZ / moveLen
end

local yawRad = math.rad(alya.combat.getPlayerYaw())
local fwdX = -math.sin(yawRad)
local fwdZ = math.cos(yawRad)
local rgtX = math.cos(yawRad)
local rgtZ = math.sin(yawRad)

local fwd = tx * fwdX + tz * fwdZ
local strafe = tx * rgtX + tz * rgtZ

local r = radius.getValue()
local radialDelta = dist - r
fwd = fwd + (-nx) * radialDelta * 0.3
strafe = strafe + (-nz) * radialDelta * 0.3

local len = math.sqrt(fwd * fwd + strafe * strafe)
if len > 1 then
fwd = fwd / len
strafe = strafe / len
end
local fwd = moveX * fwdX + moveZ * fwdZ
local strafe = moveX * rgtX + moveZ * rgtZ

event.setMoveForward(fwd)
event.setMoveStrafe(strafe)
Expand All @@ -96,4 +116,5 @@ end)

moduleTable.onDisable(function()
direction = 1
lockedTargetId = nil
end)
6 changes: 5 additions & 1 deletion src/main/resources/lua/modules/movement/speed.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local moduleTable = alya.modules.register("Speed", "F1 car", "MOVEMENT")

local mode = moduleTable.addModeSetting("Mode", "Speed mode", "BHop", "BHop", "Vanilla", "Verus")
local mode = moduleTable.addModeSetting("Mode", "Speed mode", "BHop", "BHop", "Vanilla", "Verus", "NCP")

local createBHopSpeedMode = loadScript("/lua/modules/movement/speed/bhop.lua")
local createVanillaSpeedMode = loadScript("/lua/modules/movement/speed/vanilla.lua")
Expand All @@ -9,3 +9,7 @@ local createVerusSpeedMode = loadScript("/lua/modules/movement/speed/verus.lua")
createBHopSpeedMode(moduleTable, mode)
createVanillaSpeedMode(moduleTable, mode)
createVerusSpeedMode(moduleTable, mode)

moduleTable.onDisable(function()
alya.mc.setTimerSpeed(1)
end)
Loading