Skip to content

Commit

Permalink
Fix ESP, Tracer, Fullbright, Waypoints, and more.
Browse files Browse the repository at this point in the history
* Move kotlin classess to kotlin directory, move mixins to java directory & restored them back to java.

* Fix fly not behaving as expected

* Finish fullbright bug

* Fix missing implements for IClientPlayerEntity, add setting for FreeCam speed

* Switch Settings back to Java

* Make Waypoints work per-dimension

* Move waypoint settings to own category, add fix to put waypoints back into render in main menu

* Move waypoint settings to own category, add fix to put waypoints back into render in main menu

* Fix ESP's not showing when WorldRenderer.drawBox is overridden by other mods

* Change way to render esp's using planes instead.

* Waypoint Modifications (#56)

* Switch Settings back to Java

* Make Waypoints work per-dimension

* Move waypoint settings to own category, add fix to put waypoints back into render in main menu

* Move waypoint settings to own category, add fix to put waypoints back into render in main menu

* Fix ESP's not showing when WorldRenderer.drawBox is overridden by other mods

* Change way to render esp's using planes instead.

* Add dimension array to Waypoints to allow for user-configurable dimensions on the fly.

Made Tracers render at the same time as ESPs

* Cleanup waypoint classes

* Fix #59  - getVelocity not implemented

* Add better mob selection for tracer/esp's (#62)

* Add new UI page for rendering mob esp

* Add new UI page for rendering mob tracer

* Add java settings back?!

* Update doc comments

* Update gavui version
  • Loading branch information
GT3CH1 committed Apr 1, 2023
1 parent b4f585d commit d4263aa
Show file tree
Hide file tree
Showing 35 changed files with 1,299 additions and 468 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}
}
plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'maven-publish'
}
apply plugin: 'kotlin'
Expand Down
2 changes: 1 addition & 1 deletion gavui
187 changes: 187 additions & 0 deletions src/main/java/com/peasenet/main/Settings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright (c) 2022-2023. Gavin Pease and contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package com.peasenet.main;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.ToNumberPolicy;
import com.google.gson.stream.JsonReader;
import com.peasenet.config.*;
import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;

/**
* @author gt3ch1
* @version 7/5/2022
* A class that contains all the settings for the mod.
*/
public class Settings {

/**
* The list of all settings and their values.
*/
public static final HashMap<String, Config<?>> settings = new HashMap<>();
public static final HashMap<String, Config<?>> defaultSettings = new HashMap<>();

@SuppressWarnings("rawtypes")
public static Config getConfig(Class<? extends Config> clazz, String key) {
// open the settings file
var cfgFile = getFilePath();
var json = new GsonBuilder().create();
Object map;
try {
map = json.fromJson(new FileReader(cfgFile), HashMap.class).get(key);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
try {
JsonObject jsonObject = json.toJsonTree(map).getAsJsonObject();
return json.fromJson(jsonObject, clazz);
} catch (IllegalStateException e) {
settings.put(key, defaultSettings.get(key));
save();
return defaultSettings.get(key);
}
}

/**
* Initializes the settings.
*/
public static void initialize() {
settings.put("misc", new MiscConfig());
settings.put("radar", new RadarConfig());
settings.put("esp", new EspConfig());
settings.put("tracer", new TracerConfig());
settings.put("xray", new XrayConfig());
settings.put("fullbright", new FullbrightConfig());
settings.put("fpsColors", new FpsColorConfig());
settings.put("waypoints", new WaypointConfig());
defaultSettings.putAll(settings);
// check if the config file exists
var path = getFilePath();
var file = new File(path);
if (!file.exists()) {
save();
}
var json = new GsonBuilder().setPrettyPrinting().create();
try {
var reader = new JsonReader(new InputStreamReader(new FileInputStream(file)));
HashMap<String, Config<?>> data = json.fromJson(reader, HashMap.class);
if (data == null)
loadDefault();
reader.close();
} catch (Exception ignored) {
}
for (var entry : settings.entrySet()) {
var key = entry.getKey();
var value = entry.getValue();
settings.put(key, value.readFromSettings());
}
}

/**
* Saves the current settings to mods/gavinsmod/settings.json
*/
public static void save() {
// open the mods folder
var cfgFile = getFilePath();
// ensure the settings file exists
ensureCfgCreated(cfgFile);
var json = new GsonBuilder().setPrettyPrinting().setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE).create();
try {
var writer = Files.newBufferedWriter(Paths.get(cfgFile));
json.toJson(settings, writer);
writer.close();
} catch (Exception e) {
GavinsMod.LOGGER.error("Error writing settings to file.");
GavinsMod.LOGGER.error(e.getMessage());
}
}

/**
* Ensures that the configuration file is created.
*
* @param cfgFile - The path to the configuration file.
*/
private static void ensureCfgCreated(String cfgFile) {
Path cfg = Path.of(cfgFile);
if (!Files.exists(cfg)) {
try {
Files.createFile(cfg);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

/**
* Gets the file path to the settings file.
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
@NotNull
private static String getFilePath() {
var runDir = GavinsModClient.Companion.getMinecraftClient().getRunDirectory().getAbsolutePath();
var modsDir = runDir + "/mods";
// ensure the gavinsmod folder exists
var gavinsmodDir = modsDir + "/gavinsmod";
var cfgFile = gavinsmodDir + "/settings.json";
var gavinsModFile = new File(gavinsmodDir);
if (!gavinsModFile.exists()) {
GavinsMod.LOGGER.info("Creating gavinsmod folder.");
gavinsModFile.mkdir();
}
// convert cfgFile path to correct path separator
return Paths.get(cfgFile).toString();
}

/**
* Loads the default configuration.
*/
public static void loadDefault() {

GavinsMod.LOGGER.warn("Loading default settings.");
var cfgFile = getFilePath();
// rename settings file to settings.bak
var bakFile = cfgFile + ".bak";
int bakCount = 1;
// if bak file exists, rename it to settings.bak.1, settings.bak.2, etc.
var bFile = new File(bakFile);
var renamed = false;
while (bFile.exists()) {
bakFile = cfgFile + ".bak." + bakCount;
bakCount++;
renamed = true;
}
// move the settings file to the bak file
// check if the settings file exists
var cfg = new File(cfgFile);
if (cfg.exists() && renamed) {
var res = cfg.renameTo(bFile);
if (!res) throw new RuntimeException(String.format("Could not rename %s to %s", cfgFile, bakFile));
}
save();
}
}
22 changes: 19 additions & 3 deletions src/main/java/com/peasenet/mixins/MixinClientPlayerEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
package com.peasenet.mixins;

import com.mojang.authlib.GameProfile;
import com.peasenet.main.GavinsMod;
import com.peasenet.main.Mods;
import com.peasenet.mixinterface.IClientPlayerEntity;
import com.peasenet.mods.Type;
import com.peasenet.util.event.AirStrafeEvent;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
Expand All @@ -36,6 +38,8 @@
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -111,6 +115,11 @@ public boolean isNoClip() {
return super.noClip;
}

@Override
public @NotNull Vec3d getVelocity() {
return super.getVelocity();
}

@Override
public float getEyeHeight(EntityPose pose) {
return super.getEyeHeight(pose);
Expand Down Expand Up @@ -195,13 +204,20 @@ public double eyeHeight() {
return 0;
}

@Override
public double squaredDistanceTo(Entity e) {
return super.squaredDistanceTo(e);
}

@Override
public float getOffGroundSpeed() {
return super.getOffGroundSpeed();
var evt = new AirStrafeEvent(super.getOffGroundSpeed());
GavinsMod.eventManager.call(evt);
return evt.getSpeed();
}

@Override
public double squaredDistanceTo(Entity e) {
return super.squaredDistanceTo(e);
public @NotNull World getWorld() {
return super.world;
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/peasenet/mixins/MixinMinecraftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public abstract class MixinMinecraftClient implements IMinecraftClient {
public File runDirectory;
@Shadow
public HitResult crosshairTarget;
@Shadow
public ClientPlayerEntity player;
@Final
@Shadow
private EntityRenderDispatcher entityRenderDispatcher;
Expand Down Expand Up @@ -110,11 +112,6 @@ public int getFps() {
return currentFps;
}

@Override
public ClientPlayerEntity player() {
return MinecraftClient.getInstance().player;
}

@Override
public GameOptions getOptions() {
return options;
Expand Down Expand Up @@ -168,4 +165,8 @@ public EntityRenderDispatcher getEntityRenderDispatcher() {
return entityRenderDispatcher;
}

@Override
public ClientPlayerEntity getPlayer() {
return player;
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/com/peasenet/config/MiscConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class MiscConfig : Config<MiscConfig>() {
field = value
saveConfig()
}
var freeCamSpeed = 0.1f
set(value) {
field = value
saveConfig()
}

init {
key = "misc"
Expand Down
68 changes: 67 additions & 1 deletion src/main/kotlin/com/peasenet/config/TracerEspConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ package com.peasenet.config

import com.peasenet.gavui.color.Color
import com.peasenet.gavui.color.Colors
import net.minecraft.entity.EntityType
import net.minecraft.item.SpawnEggItem

/**
* @author gt3ch1
* @version 03-02-2023
* @version 04-01-2023
*/
open class TracerEspConfig<E> : Config<TracerEspConfig<E>>() {
var chestColor: Color = Colors.PURPLE
Expand Down Expand Up @@ -77,5 +79,69 @@ open class TracerEspConfig<E> : Config<TracerEspConfig<E>>() {
field = value
saveConfig()
}

var shownMobs: ArrayList<String> = ArrayList()
set(value) {
field = value
saveConfig()
}

/**
* Removes a mob from the shown mobs list.
* @param mob The mob to remove (EntityType)
*/
fun removeMob(mob: EntityType<*>) {
shownMobs.remove(mob.translationKey)
saveConfig()
}

/**
* Removes a mob from the shown mobs list.
* @param spawnEggItem The mob to remove (SpawnEggItem)
*/
fun removeMob(spawnEggItem: SpawnEggItem) {
removeMob(spawnEggItem.getEntityType(null))
}

/**
* Adds a mob to the shown mobs list.
* @param spawnEggItem The mob to add (SpawnEggItem)
*/
fun addMob(spawnEggItem: SpawnEggItem) {
addMob(spawnEggItem.getEntityType(null))
}

/**
* Adds a mob to the shown mobs list.
* @param mob The mob to add (EntityType)
*/
fun addMob(mob: EntityType<*>) {
shownMobs.add(mob.translationKey)
saveConfig()
}

/**
* Checks if a mob is shown.
* @param egg The mob to check (SpawnEggItem)
* @return Whether the mob is shown.
*/
fun mobIsShown(egg: SpawnEggItem): Boolean {
return mobIsShown(egg.getEntityType(null))
}


/**
* Checks if a mob is shown.
* @param mob The mob to check (EntityType)
* @return Whether the mob is shown.
*/
fun mobIsShown(mob: EntityType<*>): Boolean {
val inList = shownMobs.contains(mob.translationKey);
if (mob.spawnGroup.isPeaceful && showPeacefulMobs)
return inList
if (!mob.spawnGroup.isPeaceful && showHostileMobs)
return inList
return false
}
}

4 changes: 1 addition & 3 deletions src/main/kotlin/com/peasenet/config/XrayConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class XrayConfig : Config<XrayConfig>() {
init {
key = "xray"
blocks = HashSet()
for (b in defaultBlockList) {
blocks.add(getId(b))
}
defaultBlockList.forEach { b: Block -> blocks.add(getId(b)) }
}

/**
Expand Down
Loading

0 comments on commit d4263aa

Please sign in to comment.