Skip to content

Commit

Permalink
Migrating to JSON config system. Bugs included
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Jul 3, 2024
1 parent fda7b0c commit 5dad609
Show file tree
Hide file tree
Showing 36 changed files with 970 additions and 572 deletions.
57 changes: 36 additions & 21 deletions src/main/java/dev/heliosclient/HeliosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
import dev.heliosclient.module.modules.misc.NotificationModule;
import dev.heliosclient.module.sysmodules.ClickGUI;
import dev.heliosclient.scripting.LuaScriptManager;
import dev.heliosclient.system.*;
import dev.heliosclient.system.ConsoleAppender;
import dev.heliosclient.system.DiscordRPC;
import dev.heliosclient.system.HeliosExecutor;
import dev.heliosclient.system.TickRate;
import dev.heliosclient.system.config.Config;
import dev.heliosclient.ui.clickgui.ConsoleScreen;
import dev.heliosclient.ui.notification.notifications.InfoNotification;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.SoundUtils;
import dev.heliosclient.util.TimerUtils;
import dev.heliosclient.util.fontutils.FontRenderers;
import dev.heliosclient.util.player.DamageUtils;
import dev.heliosclient.util.player.RotationSimulator;
import dev.heliosclient.util.render.Renderer2D;
import me.x150.renderer.font.FontRenderer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
Expand All @@ -34,8 +36,8 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.function.Consumer;

import static dev.heliosclient.managers.FontManager.fontSize;
import static dev.heliosclient.managers.FontManager.fonts;

public class HeliosClient implements ModInitializer, Listener {
Expand All @@ -48,40 +50,52 @@ public class HeliosClient implements ModInitializer, Listener {
private static final TimerUtils configTimer = new TimerUtils();
public static Config CONFIG = new Config();
public static AddonManager ADDONMANAGER = new AddonManager();
public static ClickGUI CLICKGUI = new ClickGUI();
public static ClickGUI CLICKGUI;
public volatile static ConsoleScreen CONSOLE = new ConsoleScreen();
public static File SAVE_FOLDER = new File(MC.runDirectory.getPath() + "/heliosclient");

public static void loadConfig() {
load(config -> {
CONFIG.loadEverything();
LOGGER.info("Loading Config complete in: {}s", configTimer.getElapsedTime());
});
}

private static void load(Consumer<Config> consumer) {
configTimer.startTimer();
CONFIG.loadConfig();
CONFIG.loadClientConfigModules();

CONFIG.loadHudElements();
CONFIG.loadModules();
LOGGER.info("Loading Config complete in: {}s", configTimer.getElapsedTime());
if (ModuleManager.get(NotificationModule.class).clientNotification.value && shouldSendNotification()) {
consumer.accept(CONFIG);

configTimer.resetTimer();

if (shouldSendNotification() && ModuleManager.get(NotificationModule.class).clientNotification.value) {
NotificationManager.addNotification(new InfoNotification("Loading Done", "in: " + configTimer.getElapsedTime() + "s", 1000, SoundUtils.TING_SOUNDEVENT));
}
configTimer.resetTimer();

// Font event is posted to allow the GUI to reset its calculation for the new font by the config.
if (fonts != null)
EventManager.postEvent(new FontChangeEvent(fonts));
}

public static void loadModulesOnly() {
load(config -> {
CONFIG.getModuleConfigManager().load();
CONFIG.load();

LOGGER.info("Loading Module config complete in: {}s", configTimer.getElapsedTime());
});
}

public static void saveConfig() {
HeliosExecutor.execute(HeliosClient::saveConfigHook);
}

public static void saveConfigHook() {
LOGGER.info("Saving config... \t Module Config being saved: {}", Config.MODULES);
LOGGER.info("Saving all configs... \t Info: Current module config being saved \"{}\"", CONFIG.moduleConfigManager.getCurrentConfig().getName());
configTimer.startTimer();
CONFIG.getModuleConfig();
CONFIG.getClientConfig();
CONFIG.save();
CONFIG.saveEverything();
LOGGER.info("Saving Config complete in: {}s", configTimer.getElapsedTime());
if (ModuleManager.get(NotificationModule.class).clientNotification.value && shouldSendNotification()) {
if (shouldSendNotification() && ModuleManager.get(NotificationModule.class).clientNotification.value) {
NotificationManager.addNotification(new InfoNotification("Saving Done", "in: " + configTimer.getElapsedTime() + "s", 1000, SoundUtils.TING_SOUNDEVENT));
}
configTimer.resetTimer();
Expand Down Expand Up @@ -118,9 +132,9 @@ public void onInitialize() {
LOGGER.info("Initialising Helios Client...");

CONFIG.init();
CLICKGUI = new ClickGUI();

EventManager.register(this);
registerEvents();
registerListeners();

LOGGER.info("Downloading and extracting Discord Native Library-2.5.6...");
DiscordRPC.INSTANCE.init();
Expand All @@ -137,9 +151,9 @@ public void onInitialize() {
SoundUtils.registerSounds();
HudElementList.INSTANCE = new HudElementList();


CapeManager.CAPE_NAMES = CapeManager.loadCapes();


HeliosExecutor.execute(HeliosClient::loadConfig);

// Save
Expand Down Expand Up @@ -168,7 +182,8 @@ public void onInitialize() {
EventManager.postEvent(new FontChangeEvent(fonts));
}

public void registerEvents() {
public void registerListeners() {
EventManager.register(this);
EventManager.register(FontManager.INSTANCE);
EventManager.register(NotificationManager.INSTANCE);
EventManager.register(Renderer2D.INSTANCE);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/command/commands/Reset.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Reset() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
HeliosClient.CONFIG.getDefaultModuleConfig();
HeliosClient.CONFIG.writeDefaultModuleConfig();

ChatUtils.sendHeliosMsg("Reset config.");

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/heliosclient/hud/HudElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public void onFontChange(FontChangeEvent event) {
}

@Override
public Object saveToToml(List<Object> objects) {
public Object saveToFile(List<Object> objects) {
Map<String, Object> map = new HashMap<>();

map.put("name", name);
Expand All @@ -469,7 +469,7 @@ public Object saveToToml(List<Object> objects) {
for (SettingGroup settingGroup : settingGroups) {
for (Setting<?> setting : settingGroup.getSettings()) {
if (setting.name != null) {
map.put(setting.name.replace(" ", ""), setting.saveToToml(new ArrayList<>()));
map.put(setting.name.replace(" ", ""), setting.saveToFile(new ArrayList<>()));
}
}
}
Expand All @@ -478,8 +478,8 @@ public Object saveToToml(List<Object> objects) {
}

@Override
public void loadFromToml(Map<String, Object> map, Toml toml) {
List<Object> obj = toml.getList("positions");
public void loadFromFile(Map<String, Object> MAP) {
List<Object> obj = (List<Object>) MAP.get("positions");
this.x = Integer.parseInt(obj.get(0).toString());
this.y = Integer.parseInt(obj.get(1).toString());
this.width = Integer.parseInt(obj.get(2).toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CoordinatesHud extends HudElement {
);
private final BooleanSetting cameraEntity = sgSettings.add(new BooleanSetting.Builder()
.name("Camera Coords")
.description("Shows the coordinates of camera instead of player")
.description("Shows the coordinates of camera instead of player. Works with Freecam and other camera manipulating modules")
.onSettingChange(this)
.defaultValue(false)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.math.MathHelper;

import java.awt.*;

Expand Down
9 changes: 0 additions & 9 deletions src/main/java/dev/heliosclient/hud/hudelements/Radar.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,4 @@ private int getColor(Entity entity) {
}
return color;
}

@Override
public void loadFromToml(Map<String, Object> map, Toml toml) {
super.loadFromToml(map, toml);
}




}
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/mixin/MixinCrashReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public abstract class MixinCrashReport {
//Save our config when a crash occurs via the create method.
@Inject(method = "create", at = @At("HEAD"))
private static void onCreateCrashReport(Throwable cause, String title, CallbackInfoReturnable<CrashReport> cir) {
HeliosClient.saveConfigHook();
HeliosClient.saveConfigHook();
}
}
14 changes: 7 additions & 7 deletions src/main/java/dev/heliosclient/module/Module_.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void onSettingChange(Setting<?> setting) {
}

@Override
public Object saveToToml(List<Object> list) {
public Object saveToFile(List<Object> list) {
Map<String, Object> ModuleConfig = new HashMap<>();
// Map for storing the values of each module
if (this.settingGroups == null) return ModuleConfig;
Expand All @@ -270,28 +270,28 @@ public Object saveToToml(List<Object> list) {
if (!setting.shouldSaveAndLoad()) continue;

if (setting.name != null) {
// Put the value of each setting into the map. Call the setting saveToToml method to get the value of the setting.
ModuleConfig.put(setting.name.replace(" ", ""), setting.saveToToml(new ArrayList<>()));
// Put the value of each setting into the map. Call the setting saveToFile method to get the value of the setting.
ModuleConfig.put(setting.name.replace(" ", ""), setting.saveToFile(new ArrayList<>()));
}
}
}
return ModuleConfig;
}

@Override
public void loadFromToml(Map<String, Object> MAP, Toml toml) {
public void loadFromFile(Map<String, Object> MAP) {
for (SettingGroup settingGroup : this.settingGroups) {
for (Setting<?> setting : settingGroup.getSettings()) {
if (!setting.shouldSaveAndLoad()) break;


Toml settingTable = toml.getTable(this.name.replace(" ", ""));
Map<String ,Object> settingTable = HeliosClient.CONFIG.cast(MAP.get(this.name.replace(" ", "")));
if (settingTable != null) {

//Any error caught should not cause the whole config system to fail to load.

//Hopefully
try {
setting.loadFromToml(settingTable.toMap(), settingTable);
setting.loadFromFile(settingTable);
}catch (Exception e){
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import dev.heliosclient.util.player.PlayerUtils;
import dev.heliosclient.util.player.RotationSimulator;
import dev.heliosclient.util.player.RotationUtils;
import dev.heliosclient.util.player.TargetUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
Expand Down Expand Up @@ -192,12 +193,10 @@ public void simulateRotationLook(double range, boolean ignoreTeammate, LivingEnt
LivingEntity targetEntity = entity;

if(targetEntity == null) {
targetEntity = (LivingEntity) EntityUtils.getNearestEntity(
mc.world,
mc.player, range,
entity1 -> entity1 instanceof LivingEntity && !isBlackListed(entity1) && entity1.distanceTo(mc.player) < range && isEntityVisible(entity1),
(SortMethod) sort.getOption());
TargetUtils.getInstance().setRange(range);
targetEntity = (LivingEntity) TargetUtils.getInstance().getNewTargetIfNull(entity1 -> entity1 instanceof LivingEntity && !isBlackListed(entity1) && entity1.distanceTo(mc.player) < range && isEntityVisible(entity1),true);
}

if (ignoreTeammate && ModuleManager.get(Teams.class).isInMyTeam(targetEntity)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,4 @@ public class ScriptModule extends Module_ {
public ScriptModule() {
super("Lua-Scripts", "Placeholder to save/load script binds", Categories.MISC);
}

@Override
public Object saveToToml(List<Object> list) {
Map<String, Object> config = (Map<String, Object>) super.saveToToml(list);

for (int i = 0; i < LuaScriptManager.luaFiles.size(); i++) {
LuaFile file = LuaScriptManager.luaFiles.get(i);
config.put(file.getScriptName(), file.bindKey);
}

return config;
}

@Override
public void loadFromToml(Map<String, Object> MAP, Toml toml) {
super.loadFromToml(MAP, toml);
for (int i = 0; i < LuaScriptManager.luaFiles.size(); i++) {
LuaFile file = LuaScriptManager.luaFiles.get(i);
if (MAP.containsKey(file.getScriptName())) {
file.bindKey = (int) MAP.get(file.getScriptName());
}
}
this.MAP = MAP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import dev.heliosclient.util.player.PlayerUtils;
import dev.heliosclient.util.player.RotationSimulator;
import dev.heliosclient.util.player.RotationUtils;
import dev.heliosclient.util.player.TargetUtils;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -154,11 +155,8 @@ public void onDisable() {

@SubscribeEvent
public void onTicks(TickEvent.PLAYER event) {
LivingEntity entity = (LivingEntity) EntityUtils.getNearestEntity(
mc.world,
mc.player, range.value,
entity1 -> entity1 instanceof LivingEntity && !isBlackListed(entity1) && entity1.distanceTo(mc.player) < range.value && isEntityVisible(entity1) ,
(SortMethod) sort.getOption());
TargetUtils.getInstance().setRange(range.value);
LivingEntity entity = (LivingEntity) TargetUtils.getInstance().getNewTargetIfNull(true);

if (ignoreTeammate.value && ModuleManager.get(Teams.class).isInMyTeam(entity)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CustomFov extends Module_ {
.onSettingChange(this)
.value(140.0)
.defaultValue(140.0)
.min(1)
.min(20)
.max(240)
.roundingPlace(0)
.build()
Expand All @@ -42,7 +42,7 @@ public void onTick(TickEvent.CLIENT event) {
@Override
public void onEnable() {
super.onEnable();
if (mc.options == null && mc.options.getFov().getValue() <= 110) return;
if (mc.options == null || mc.options.getFov().getValue() <= 110) return;

previousFov = mc.options.getFov().getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ public void mouseClicked(double mouseX, double mouseY, int button) {
}

@Override
public Object saveToToml(List<Object> objectList) {
public Object saveToFile(List<Object> objectList) {
return value;
}

@Override
public void loadFromToml(Map<String, Object> MAP, Toml toml) {
super.loadFromToml(MAP, toml);
public void loadFromFile(Map<String, Object> MAP) {
if (MAP.get(getSaveName()) == null) {
value = defaultValue;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,12 @@ public void mouseReleased(double mouseX, double mouseY, int button) {
}

@Override
public Object saveToToml(List<Object> objectList) {
public Object saveToFile(List<Object> objectList) {
return value;
}

@Override
public void loadFromToml(Map<String, Object> MAP, Toml toml) {
super.loadFromToml(MAP, toml);
public void loadFromFile(Map<String, Object> MAP) {
if (MAP.get(getSaveName()) == null) {
value = defaultValue;
return;
Expand Down
Loading

0 comments on commit 5dad609

Please sign in to comment.