Skip to content

Commit

Permalink
Merge pull request #29 from Utility-Client/crosshair-recode
Browse files Browse the repository at this point in the history
New Crosshairs
  • Loading branch information
sam302rk committed Dec 10, 2021
2 parents d7ba64a + 74743ec commit 1cd1c82
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 175 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -22,4 +22,5 @@ workspace/
log.txt
!/workspace/libaries/
!/workspace/versions/
!/workspace/assets/
!/workspace/assets/
bundle_with_jar/
4 changes: 1 addition & 3 deletions src/main/java/de/gamingcraft/UtilityClient.java
Expand Up @@ -17,9 +17,8 @@
public class UtilityClient extends Thread {
public static final CPSThread CPS_THREAD_INSTANCE = new CPSThread();
public static final DiscordRP DISCORD_INSTANCE = new DiscordRP();
public static final CrosshairManager CROSSHAIR_MANAGER_INSTANCE = new CrosshairManager();
private static final String CLIENT_NAME = "Utility Client";
private static final String CLIENT_VERSION = "2.7";
private static final String CLIENT_VERSION = "2.8";
private static final UtilityClient CLIENT_INSTANCE = new UtilityClient();
public static float fovModifier = 1.0f;
public static ArrayList<KeyBinding> keyBinds = new ArrayList<>();
Expand Down Expand Up @@ -66,7 +65,6 @@ public void run() {
addKeyBind("Toggle Overlay", ConfigManager.config.getOverlay(), false);
DISCORD_INSTANCE.start();
CPS_THREAD_INSTANCE.start();
CROSSHAIR_MANAGER_INSTANCE.start();
}

public void loop() {
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/de/gamingcraft/config/Config.java
@@ -1,14 +1,16 @@
package de.gamingcraft.config;

public class Config {
private int selectedTheme, hotkeyZoom, hotkeyFulbright, crosshair, overlay;
private int selectedTheme, hotkeyZoom, hotkeyFulbright, overlay, crosshairSize;
private String crosshair;

public Config(int _selectedTheme, int _hotkeyZoom, int _hotkeyFulbright, int _crosshair, int _overlay) {
public Config(int _selectedTheme, int _hotkeyZoom, int _hotkeyFulbright, String _crosshair, int _crosshairSize, int _overlay) {
selectedTheme = _selectedTheme;
hotkeyZoom = _hotkeyZoom;
hotkeyFulbright = _hotkeyFulbright;
crosshair = _crosshair;
overlay = _overlay;
crosshairSize = _crosshairSize;
}

public int getSelectedTheme() {
Expand All @@ -23,11 +25,19 @@ public int getHotkeyFulbright() {
return hotkeyFulbright;
}

public int getCrosshair() {
public String getCrosshair() {
return crosshair;
}

public void setCrosshair(int crosshair) {
public int getCrosshairSize() {
return crosshairSize;
}

public void setCrosshairSize(int crosshairSize) {
this.crosshairSize = crosshairSize;
}

public void setCrosshair(String crosshair) {
this.crosshair = crosshair;
}

Expand Down
19 changes: 13 additions & 6 deletions src/main/java/de/gamingcraft/config/ConfigManager.java
Expand Up @@ -17,29 +17,35 @@ public static void start() throws IOException {
setup();
if (!configFile.exists()) save();
load();
overrideConfig(config.getSelectedTheme(), config.getHotkeyZoom(), config.getHotkeyFulbright(), config.getCrosshair(), config.getOverlay());
overrideConfig(config.getSelectedTheme(), config.getHotkeyZoom(), config.getHotkeyFulbright(), config.getCrosshair(), config.getCrosshairSize(), config.getOverlay());
}

public static void setup() {
conf.setProperty("selectedTheme", "0");
conf.setProperty("hotkeyZoom", "46");
conf.setProperty("hotkeyFulbright", "50");
conf.setProperty("selectedCrosshair", "0");
conf.setProperty("crosshairData", "0");
conf.setProperty("crosshairSize", "9");
conf.setProperty("hotkeyToggleOverlay", "22");
}

public static void overrideConfig(int selTheme, int hotKeyZoom, int hotkeyFulbright, int crosshair, int overlay) throws IOException {
public static void overrideConfig(int selTheme, int hotKeyZoom, int hotkeyFulbright, String crosshair, int crosshairSize, int overlay) throws IOException {
setEntry("selectedTheme", selTheme);
setEntry("hotkeyZoom", hotKeyZoom);
setEntry("hotkeyFulbright", hotkeyFulbright);
setEntry("selectedCrosshair", crosshair);
setEntry("crosshairData", crosshair);
setEntry("crosshairSize", crosshairSize);
setEntry("hotkeyToggleOverlay", overlay);
save();
load();
}

public static void setEntry(String key, int value) throws IOException {
conf.setProperty(key, value + "");
setEntry(key, value + "");
}

public static void setEntry(String key, String value) throws IOException {
conf.setProperty(key, value);
save();
load();
}
Expand All @@ -51,7 +57,8 @@ public static void load() throws IOException {
Integer.parseInt(conf.getProperty("selectedTheme")),
Integer.parseInt(conf.getProperty("hotkeyZoom")),
Integer.parseInt(conf.getProperty("hotkeyFulbright")),
Integer.parseInt(conf.getProperty("selectedCrosshair")),
conf.getProperty("crosshairData"),
Integer.parseInt(conf.getProperty("crosshairSize")),
Integer.parseInt(conf.getProperty("hotkeyToggleOverlay"))
);
}
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/de/gamingcraft/crosshair/Crosshair.java

This file was deleted.

38 changes: 21 additions & 17 deletions src/main/java/de/gamingcraft/crosshair/CrosshairManager.java
@@ -1,28 +1,32 @@
package de.gamingcraft.crosshair;

import de.gamingcraft.config.ConfigManager;
import de.gamingcraft.crosshair.crosshairs.*;
import de.gamingcraft.utils.SerializationUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;

import java.util.ArrayList;
import java.util.HashMap;

public class CrosshairManager extends Thread {
public ArrayList<Crosshair> crosshairs = new ArrayList<Crosshair>();
public class CrosshairManager {

@Override
public void run() {
crosshairs.add(new DefaultCrosshair());
crosshairs.add(new PointCross());
crosshairs.add(new PointCrosshair());
super.run();
}

public void loop(int offsetY) {
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
int centerX = sr.getScaledWidth() / 2;
int centerY = sr.getScaledHeight() / 2 + offsetY;
public static void loop(ScaledResolution sr) throws Exception {
GlStateManager.disableDepth();
GlStateManager.disableAlpha();
HashMap<Integer, Boolean> pixels = (HashMap<Integer, Boolean>) SerializationUtils.deserialize(ConfigManager.config.getCrosshair());
int size = ConfigManager.config.getCrosshairSize();

crosshairs.get(ConfigManager.config.getCrosshair()).updateRender(sr, centerX, centerY, sr.getScaleFactor());
int f = 0;
for (int i = 0; i < size; i++) {
for (int e = 0; e < size; e++) {
int x = sr.getScaledWidth() / 2 + i * 2 - size;
int y = sr.getScaledHeight() / 2 + e * 2 - size;
if(!pixels.getOrDefault(f, true)) Gui.drawRect(x, y, x + 2, y + 2, 2164260863L);
f++;
}
}
GlStateManager.enableDepth();
GlStateManager.enableAlpha();
}
}

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/java/de/gamingcraft/crosshair/crosshairs/PointCross.java

This file was deleted.

This file was deleted.

84 changes: 42 additions & 42 deletions src/main/java/de/gamingcraft/gui/GuiCrosshairOptions.java
Expand Up @@ -2,85 +2,85 @@

import de.gamingcraft.UtilityClient;
import de.gamingcraft.config.ConfigManager;
import de.gamingcraft.overlay.Theme;
import de.gamingcraft.utils.SerializationUtils;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;

import java.io.IOException;
import java.util.HashMap;

public class GuiCrosshairOptions extends GuiScreen
{
/** The parent GUI for this GUI */
private final GuiScreen parentScreen;

/** The title of the GUI. */
private String title;

private int size = 9;
HashMap<Integer, Boolean> pixels = new HashMap<>();
public GuiCrosshairOptions(GuiScreen parentScreenIn)
{
this.parentScreen = parentScreenIn;
}

/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
int i = 0;
this.title = UtilityClient.getClientName() + " Crosshair Options";

this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height/2 - 40, 98, 20, "Previous Crosshair"));
this.buttonList.add(new GuiButton(2, this.width / 2 + 2, this.height/2 - 40, 98, 20, "Next Crosshair"));

this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height/2, I18n.format("gui.done")));
this.title = "Crosshair Editor";
try {
// Please ignore the dirty code, it should just work.
size = ConfigManager.config.getCrosshairSize();
pixels = (HashMap<Integer, Boolean>) SerializationUtils.deserialize(ConfigManager.config.getCrosshair());
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if(button.id < 200) pixels.put(button.id, !pixels.getOrDefault(button.id, true));

if (button.enabled)
{
if (button.id == 200) {
ConfigManager.config.setCrosshair(SerializationUtils.serialize(pixels));

if(button.id == 1) {
if(ConfigManager.config.getCrosshair()-1 < 0) {
ConfigManager.config.setCrosshair(UtilityClient.CROSSHAIR_MANAGER_INSTANCE.crosshairs.size()-1);
} else {
ConfigManager.config.setCrosshair(ConfigManager.config.getCrosshair() - 1);
}
ConfigManager.overrideConfig(UtilityClient.CURRENT_THEME.getId(), ConfigManager.config.getHotkeyZoom(), ConfigManager.config.getHotkeyFulbright(), ConfigManager.config.getCrosshair(), size, ConfigManager.config.getOverlay());
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(this.parentScreen);
}

if(button.id == 2) {
if((ConfigManager.config.getCrosshair()+1) > (UtilityClient.CROSSHAIR_MANAGER_INSTANCE.crosshairs.size()-1)) {
ConfigManager.config.setCrosshair(0);
} else {
ConfigManager.config.setCrosshair(ConfigManager.config.getCrosshair() + 1);
}
if (button.id == 201) if(size > 1) {
size--;
pixels.clear();
}

if (button.id == 200)
{
ConfigManager.overrideConfig(UtilityClient.CURRENT_THEME.getId(), ConfigManager.config.getHotkeyZoom(), ConfigManager.config.getHotkeyFulbright(), ConfigManager.config.getCrosshair(), ConfigManager.config.getOverlay());
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(this.parentScreen);
if (button.id == 202) if(size < 12) {
size++;
pixels.clear();
}

// Button Ifs here
}
}

/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 20, 16777215);
this.drawCenteredString(this.fontRendererObj, size + "x" + size, this.width / 2, this.height / 4 * 3 + 5, 16777215);

buttonList.clear();
int f = 0;
for (int i = 0; i < size; i++) {
for (int e = 0; e < size; e++) {
buttonList.add(new GuiButton(f,
this.width / 2 + i * 20 - size * 10,
this.height / 2 + e * 20 - size * 10,
20, 20,
"", !pixels.getOrDefault(f, true)));
f++;
}
}

UtilityClient.CROSSHAIR_MANAGER_INSTANCE.loop(-70);
this.buttonList.add(new GuiButton(201, this.width / 2 - 100, this.height / 4 * 3, 20, 20, "-"));
this.buttonList.add(new GuiButton(202, this.width / 2 + 80, this.height / 4 * 3, 20, 20, "+"));
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 8 * 7, I18n.format("gui.done")));

super.drawScreen(mouseX, mouseY, partialTicks);
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/de/gamingcraft/utils/SerializationUtils.java
@@ -0,0 +1,24 @@
package de.gamingcraft.utils;

import java.io.*;
import java.util.Base64;

public class SerializationUtils {
public static String serialize(Serializable o) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(o);
oos.close();
return Base64.getEncoder().encodeToString(baos.toByteArray());
}

public static Object deserialize(String s) throws IOException,
ClassNotFoundException {
byte[] data = Base64.getDecoder().decode(s);
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream(data));
Object o = ois.readObject();
ois.close();
return o;
}
}

0 comments on commit 1cd1c82

Please sign in to comment.