Skip to content

Commit

Permalink
Bug hunting and readme changes. Force-multiplier for polygon mesh ren…
Browse files Browse the repository at this point in the history
…derer.
  • Loading branch information
tanishisherewithhh committed Sep 10, 2024
1 parent 16c34fb commit dc3ee15
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 56 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ To submit a bug open an issue in this repository. Before doing so please assure

## Known issues
- Buggy modules like Tick-Shift, PacketMine.
- Incomplete modules like Phase.
- Incomplete modules like Phase, Fucker, InventoryTweaks.
- ~~HudElements don't resize to their proper locations sometimes.~~
- Scripting System (WIP).
- Lack of combat and some important utility modules.
- No Baritone Integration
- No AltManager
- ~~No AltManager~~ No AltManager GUI
- Lack of commands
- Lack of shaders (Neither of the current contributors know much good about GLSL)

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/dev/heliosclient/HeliosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ public void onInitialize() {

registerListeners();

LOGGER.info("Downloading and extracting Discord Native Library-2.5.6...");
DiscordRPC.INSTANCE.init();
LOGGER.info("Downloading Completed...");

LuaScriptManager.getScripts();

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/heliosclient/hud/hudelements/SpeedHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ public SpeedHud() {
super(DATA);
this.width = 40;
this.height = Math.round(Renderer2D.getStringHeight());
} public static HudElementData<SpeedHud> DATA = new HudElementData<>("Player Speed", "Shows player speed in blocks per second", SpeedHud::new);
}
public static HudElementData<SpeedHud> DATA = new HudElementData<>("Player Speed", "Shows player speed in blocks per second", SpeedHud::new);

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
super.renderElement(drawContext, textRenderer);
String text = "Speed: ";
String value = ColorUtils.gray + MathUtils.round(moveSpeed(), 2);
this.width = Math.round(Renderer2D.getStringWidth(text + value));
Renderer2D.drawString(drawContext.getMatrices(), text + value, this.x + 1, this.y, ColorManager.INSTANCE.hudColor);
Renderer2D.drawString(drawContext.getMatrices(), text + value, this.x, this.y, ColorManager.INSTANCE.hudColor);
}

private double moveSpeed() {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/dev/heliosclient/module/modules/render/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public class GUI extends Module_ {
.defaultValue(new Color(17, 18, 19, 100))
.build()
);
public BooleanSetting textHighlight = sgColors.add(new BooleanSetting.Builder()
.name("Module text highlight when active")
.description("If this is on, then instead of the whole button, only the text will be highlighted with a glow if the module is on.")
.value(false)
.onSettingChange(this)
.build()
);
public BooleanSetting categoryBorder = sgColors.add(new BooleanSetting.Builder()
.name("Category Border")
.description("Render the border around category")
Expand Down Expand Up @@ -133,6 +140,7 @@ public class GUI extends Module_ {
.description("Number of points")
.min(10)
.max(400)
.value(75d)
.defaultValue(75)
.roundingPlace(0)
.shouldRender(()->coolVisuals.value)
Expand Down Expand Up @@ -161,6 +169,17 @@ public class GUI extends Module_ {
.onSettingChange(this)
.build()
);
public DoubleSetting mouseForce = sgVisuals.add(new DoubleSetting.Builder()
.name("Force Multiplier of the mouse")
.description("The force multiplier applied by the mouse on the mesh so they move faster")
.min(0)
.max(5)
.defaultValue(1.3)
.roundingPlace(1)
.shouldRender(()->coolVisuals.value)
.onSettingChange(this)
.build()
);

public GUI() {
super("GUI", "The HeliosClient GUI settings.", Categories.RENDER);
Expand All @@ -183,6 +202,7 @@ public void onSettingChange(Setting<?> setting) {
PolygonMeshPatternRenderer.INSTANCE.maskGradient = gradientType.get();
PolygonMeshPatternRenderer.INSTANCE.radius = (float) dotRadius.value;
PolygonMeshPatternRenderer.INSTANCE.MAX_DISTANCE = (float) lineMaxLength.value;
PolygonMeshPatternRenderer.INSTANCE.MOUSE_FORCE_MULTIPLIER = mouseForce.getFloat();

if(setting == polygonPoints){
PolygonMeshPatternRenderer.INSTANCE.setNumOfPoints(polygonPoints.getInt());
Expand All @@ -198,6 +218,7 @@ public void onLoad() {
PolygonMeshPatternRenderer.INSTANCE.maskGradient = gradientType.get();
PolygonMeshPatternRenderer.INSTANCE.radius = (float) dotRadius.value;
PolygonMeshPatternRenderer.INSTANCE.MAX_DISTANCE = (float) lineMaxLength.value;
PolygonMeshPatternRenderer.INSTANCE.MOUSE_FORCE_MULTIPLIER = mouseForce.getFloat();
PolygonMeshPatternRenderer.INSTANCE.setNumOfPoints(polygonPoints.getInt());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public class ClickGUI extends Module_ {
.name("ModuleButton Height")
.description("ModuleButton Height for the ClickGUI")
.onSettingChange(this)
.defaultValue(16)
.max(50)
.min(1)
.defaultValue(16)
.value(16d)
.roundingPlace(0)
.build()
);
Expand Down Expand Up @@ -413,7 +414,7 @@ public void onSettingChange(Setting<?> setting) {
}

//Config changes
if (setting == switchConfigs) {
if (setting == switchConfigs && switchConfigs.getOption() != null) {
// Change the file name we want to load
HeliosClient.CONFIG.writeModuleConfig();
HeliosClient.CONFIG.moduleConfigManager.switchConfig(switchConfigs.getOption().toString(), true);
Expand Down
86 changes: 40 additions & 46 deletions src/main/java/dev/heliosclient/system/DiscordRPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,98 +33,92 @@ public class DiscordRPC {
private Core discordCore;
private Activity activity;

public void init() {
try {
File sdkFile = this.getSDKLibrary();

// Initialize the Core with the existing or downloaded file

File tempJNIDir = new File(System.getProperty("java.io.tmpdir") + "/java", "jni");

if (!tempJNIDir.isDirectory() && !tempJNIDir.mkdir())
throw new RuntimeException(new IOException("Cannot create temporary JNI directory"));

tempJNIDir.deleteOnExit();

initInternal(sdkFile, tempJNIDir);

} catch (IOException | RuntimeException e) {
AnimationUtils.addErrorToast("Discord Core init failed. Check logs for details.", false, 1500);
HeliosClient.LOGGER.error("Discord Core init failed.", e);
}
}

/**
* The {@link Core#init(File, File)} is not memory efficient and creates stores new "discord_game_sdk_jni" for every run.
* It builds up space really fast and I got to `80mb` in 40 runs.
*<p>
* <p>
* So in here, we are returning if the file in the temp directory already exists.
*/
private static void initInternal(File discordLibrary, File tempDir)
{
private static void initInternal(File discordLibrary, File tempDir) {
String name = "discord_game_sdk_jni";
String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT);
String arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT);

String objectName;

if(osName.contains("windows"))
{
if (osName.contains("windows")) {
osName = "windows";
objectName = name + ".dll";

// the Discord native library needs to be loaded before our JNI library on Windows
System.load(discordLibrary.getAbsolutePath());
}
else if(osName.contains("linux"))
{
} else if (osName.contains("linux")) {
osName = "linux";
objectName = "lib" + name + ".so";
}
else if(osName.contains("mac os"))
{
} else if (osName.contains("mac os")) {
osName = "macos";
objectName = "lib" + name + ".dylib";
}
else
{
throw new RuntimeException("cannot determine OS type: "+osName);
} else {
throw new RuntimeException("cannot determine OS type: " + osName);
}

/*
Some systems (e.g. Mac OS X) might report the architecture as "x86_64" instead of "amd64".
While it would be possible to store the MacOS dylib as "x86_x64" instead of "amd64",
I personally prefer to keep the system architecture consistent.
*/
if(arch.equals("x86_64"))
if (arch.equals("x86_64"))
arch = "amd64";

File temp = new File(tempDir, objectName);
if(temp.exists()){
if (temp.exists()) {
System.load(temp.getAbsolutePath());
Core.initDiscordNative(discordLibrary.getAbsolutePath());
LOGGER.info("(DiscordRPC) JNI directory exists");
temp.deleteOnExit();
return;
}

String path = "/native/"+osName+"/"+arch+"/"+objectName;
String path = "/native/" + osName + "/" + arch + "/" + objectName;
InputStream in = Core.class.getResourceAsStream(path);
if(in == null)
throw new RuntimeException(new FileNotFoundException("cannot find native library at "+path));
if (in == null)
throw new RuntimeException(new FileNotFoundException("cannot find native library at " + path));

try
{
try {
Files.copy(in, temp.toPath());
}
catch(IOException e)
{
} catch (IOException e) {
throw new RuntimeException(e);
}

System.load(temp.getAbsolutePath());
Core.initDiscordNative(discordLibrary.getAbsolutePath());
}

public void init() {
HeliosExecutor.execute(() -> {
LOGGER.info("Downloading and extracting Discord Native Library-2.5.6... on a separate thread");
try {
File sdkFile = this.getSDKLibrary();

// Initialize the Core with the existing or downloaded file

File tempJNIDir = new File(System.getProperty("java.io.tmpdir") + "/java", "jni");

if (!tempJNIDir.isDirectory() && !tempJNIDir.mkdir())
throw new RuntimeException(new IOException("Cannot create temporary JNI directory"));

tempJNIDir.deleteOnExit();

initInternal(sdkFile, tempJNIDir);

LOGGER.info("Downloading Completed...");
} catch (IOException | RuntimeException e) {
AnimationUtils.addErrorToast("Discord Core init failed. Check logs for details.", false, 1500);
HeliosClient.LOGGER.error("Discord Core init failed.", e);
}
});
}

/**
* This is the modified version of {@link Core#downloadDiscordLibrary()}
* In this version, it checks if the required file already exists in the Temp folder,
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/dev/heliosclient/ui/clickgui/ModuleButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float x, int

if (!shouldRender) return;

GUI gui = ModuleManager.get(GUI.class);
if (hitBox.contains(mouseX, mouseY)) {
hoverAnimationTimer = Math.min(hoverAnimationTimer + 1, 20);
} else {
Expand All @@ -85,8 +86,8 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float x, int
// Get the width and height of the module name
int moduleNameHeight = (int) Renderer2D.getFxStringHeight(module.name) - 1;

Color fillColorStart = module.isActive() ? ColorManager.INSTANCE.primaryGradientStart : ColorUtils.changeAlpha(ModuleManager.get(GUI.class).buttonColor.getColor(), 100);
Color fillColorEnd = module.isActive() ? ColorManager.INSTANCE.primaryGradientEnd : ColorUtils.changeAlpha(ModuleManager.get(GUI.class).buttonColor.getColor(), 100);
Color fillColorStart = module.isActive() && !gui.textHighlight.value? ColorManager.INSTANCE.primaryGradientStart : ColorUtils.changeAlpha(gui.buttonColor.getColor(), 100);
Color fillColorEnd = module.isActive() && !gui.textHighlight.value ? ColorManager.INSTANCE.primaryGradientEnd : ColorUtils.changeAlpha(gui.buttonColor.getColor(), 100);
Color blendedColor = ColorUtils.blend(fillColorStart, fillColorEnd, 1 / 2f);

int textY = y + (height - moduleNameHeight) / 2;
Expand All @@ -102,6 +103,10 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float x, int
drawGradientRectangle(drawContext.getMatrices().peek().getPositionMatrix(), fillColorStart, fillColorEnd, fillColorEnd, fillColorStart, x + 1, y + height, width, boxHeight + 2, HeliosClient.CLICKGUI.guiRoundness.getInt());
Renderer2D.stopScaling(drawContext.getMatrices());
}

if(module.isActive() && gui.textHighlight.value) {
Renderer2D.drawBlurredShadow(drawContext.getMatrices(), x + 2, textY, Renderer2D.getFxStringWidth(module.name) + 1, moduleNameHeight, 9, ColorManager.INSTANCE.primaryGradientStart);
}

Renderer2D.drawFixedString(drawContext.getMatrices(), module.name, x + 3, textY, ColorManager.INSTANCE.defaultTextColor());
if (hitBox.contains(mouseX, mouseY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class PolygonMeshPatternRenderer {
private int NUM_POINTS = 75;
private Point[] points = new Point[NUM_POINTS];
public float MAX_DISTANCE = 75.0f;
public float MOUSE_FORCE_MULTIPLIER = 1f;
public float radius = 2f;
public GradientManager.Gradient maskGradient = GradientManager.getGradient("Linear2D");

Expand Down Expand Up @@ -80,6 +81,7 @@ void move(int mouseX, int mouseY) {
float dy = y - mouseY;
float distance = (float) Math.sqrt(dx * dx + dy * dy);
float force = Math.max(0, 100 - distance) / 5000;
force *= MOUSE_FORCE_MULTIPLIER;

xSpeed += force * dx / distance;
ySpeed += force * dy / distance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
super.renderBackgroundTexture(drawContext);
}

adjustWindowHeight();

if(GUI.coolVisuals()){
PolygonMeshPatternRenderer.INSTANCE.render(drawContext.getMatrices(),mouseX,mouseY);
}
Expand Down

0 comments on commit dc3ee15

Please sign in to comment.