-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove GuiServerSpoof
- Loading branch information
Showing
34 changed files
with
1,536 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package cc.paimonmc.viamcp; | ||
|
||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import com.viaversion.viaversion.ViaManagerImpl; | ||
import com.viaversion.viaversion.api.Via; | ||
import com.viaversion.viaversion.api.data.MappingDataLoader; | ||
import io.netty.channel.EventLoop; | ||
import io.netty.channel.local.LocalEventLoopGroup; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.client.gui.ScaledResolution; | ||
import org.apache.logging.log4j.LogManager; | ||
import cc.paimonmc.viamcp.gui.AsyncVersionSlider; | ||
import cc.paimonmc.viamcp.loader.MCPBackwardsLoader; | ||
import cc.paimonmc.viamcp.loader.MCPRewindLoader; | ||
import cc.paimonmc.viamcp.loader.MCPViaLoader; | ||
import cc.paimonmc.viamcp.platform.MCPViaInjector; | ||
import cc.paimonmc.viamcp.platform.MCPViaPlatform; | ||
import cc.paimonmc.viamcp.utils.JLoggerToLog4j; | ||
import java.io.File; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.logging.Logger; | ||
import net.ccbluex.liquidbounce.utils.MinecraftInstance; | ||
|
||
import static net.ccbluex.liquidbounce.utils.MinecraftInstance.mc; | ||
|
||
public class ViaMCP { | ||
public final static int PROTOCOL_VERSION = 47; | ||
private static final ViaMCP instance = new ViaMCP(); | ||
|
||
public static ViaMCP getInstance() { | ||
return instance; | ||
} | ||
|
||
private final Logger jLogger = new JLoggerToLog4j(LogManager.getLogger("ViaMCP")); | ||
private final CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>(); | ||
|
||
private ExecutorService ASYNC_EXEC; | ||
private EventLoop EVENT_LOOP; | ||
|
||
private File file; | ||
private int version; | ||
private String lastServer; | ||
|
||
public static boolean hidden; | ||
|
||
public static void staticInit() { | ||
getInstance().start(); | ||
} | ||
|
||
/** | ||
* Version Slider that works Asynchronously with the Version GUI | ||
* Please initialize this before usage with initAsyncSlider() or initAsyncSlider(x, y, width (min. 110), height) | ||
*/ | ||
public AsyncVersionSlider asyncSlider; | ||
|
||
public void start() { | ||
try { | ||
final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ViaMCP-%d").build(); | ||
ASYNC_EXEC = Executors.newFixedThreadPool(8, factory); | ||
|
||
EVENT_LOOP = new LocalEventLoopGroup(1, factory).next(); | ||
EVENT_LOOP.submit(INIT_FUTURE::join); | ||
|
||
setVersion(PROTOCOL_VERSION); | ||
this.file = new File("ViaMCP"); | ||
if (this.file.mkdir()) { | ||
this.getjLogger().info("Creating ViaMCP Folder"); | ||
} | ||
|
||
Via.init(ViaManagerImpl.builder().injector(new MCPViaInjector()).loader(new MCPViaLoader()).platform(new MCPViaPlatform(file)).build()); | ||
|
||
MappingDataLoader.enableMappingsCache(); | ||
((ViaManagerImpl) Via.getManager()).init(); | ||
|
||
new MCPBackwardsLoader(file); | ||
new MCPRewindLoader(file); | ||
|
||
INIT_FUTURE.complete(null); | ||
|
||
//ViaMCP.getInstance().initAsyncSlider(); | ||
} catch (final Exception exception) { | ||
exception.printStackTrace(); | ||
} | ||
} | ||
|
||
public Logger getjLogger() { | ||
return jLogger; | ||
} | ||
|
||
public CompletableFuture<Void> getInitFuture() { | ||
return INIT_FUTURE; | ||
} | ||
|
||
public ExecutorService getAsyncExecutor() { | ||
return ASYNC_EXEC; | ||
} | ||
|
||
public EventLoop getEventLoop() { | ||
return EVENT_LOOP; | ||
} | ||
|
||
public File getFile() { | ||
return file; | ||
} | ||
|
||
public String getLastServer() { | ||
return lastServer; | ||
} | ||
|
||
public int getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(final int version) { | ||
this.version = version; | ||
} | ||
|
||
public void setFile(final File file) { | ||
this.file = file; | ||
} | ||
|
||
public void setLastServer(final String lastServer) { | ||
this.lastServer = lastServer; | ||
} | ||
|
||
public static boolean isHidden() { | ||
return hidden; | ||
} | ||
|
||
public static void setHidden(boolean hidden) { | ||
ViaMCP.hidden = hidden; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/cc/paimonmc/viamcp/gui/AsyncVersionSlider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cc.paimonmc.viamcp.gui; | ||
|
||
import cc.paimonmc.viamcp.ViaMCP; | ||
import cc.paimonmc.viamcp.protocols.ProtocolCollection; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.util.MathHelper; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
public class AsyncVersionSlider extends GuiButton { | ||
private float dragValue = (float) (ProtocolCollection.values().length - Arrays.asList(ProtocolCollection.values()).indexOf(ProtocolCollection.getProtocolCollectionById(ViaMCP.PROTOCOL_VERSION))) / ProtocolCollection.values().length; | ||
|
||
private final ProtocolCollection[] values; | ||
private float sliderValue; | ||
public boolean dragging; | ||
|
||
public AsyncVersionSlider(final int buttonId, final int x, final int y, final int widthIn, final int heightIn) { | ||
super(buttonId, x, y, Math.max(widthIn, 110), heightIn, ""); | ||
this.values = ProtocolCollection.values(); | ||
Collections.reverse(Arrays.asList(values)); | ||
this.sliderValue = dragValue; | ||
this.displayString = values[(int) (this.sliderValue * (values.length - 1))].getVersion().getName(); | ||
} | ||
|
||
public void drawButton(final Minecraft mc, final int mouseX, final int mouseY) { | ||
super.drawButton(mc, mouseX, mouseY); | ||
} | ||
|
||
/** | ||
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over | ||
* this button. | ||
*/ | ||
public int getHoverState(final boolean mouseOver) { | ||
return 0; | ||
} | ||
|
||
/** | ||
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e). | ||
*/ | ||
public void mouseDragged(final Minecraft mc, final int mouseX, final int mouseY) { | ||
if (this.visible) { | ||
if (this.dragging) { | ||
this.sliderValue = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8); | ||
this.sliderValue = MathHelper.clamp_float(this.sliderValue, 0.0F, 1.0F); | ||
this.dragValue = sliderValue; | ||
this.displayString = values[(int) (this.sliderValue * (values.length - 1))].getVersion().getName(); | ||
ViaMCP.getInstance().setVersion(values[(int) (this.sliderValue * (values.length - 1))].getVersion().getVersion()); | ||
} | ||
|
||
mc.getTextureManager().bindTexture(buttonTextures); | ||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); | ||
this.drawTexturedModalRect(this.xPosition + (int) (this.sliderValue * (float) (this.width - 8)), this.yPosition, 0, 66, 4, 20); | ||
this.drawTexturedModalRect(this.xPosition + (int) (this.sliderValue * (float) (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent | ||
* e). | ||
*/ | ||
public boolean mousePressed(final Minecraft mc, final int mouseX, final int mouseY) { | ||
if (super.mousePressed(mc, mouseX, mouseY)) { | ||
this.sliderValue = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8); | ||
this.sliderValue = MathHelper.clamp_float(this.sliderValue, 0.0F, 1.0F); | ||
this.dragValue = sliderValue; | ||
this.displayString = values[(int) (this.sliderValue * (values.length - 1))].getVersion().getName(); | ||
ViaMCP.getInstance().setVersion(values[(int) (this.sliderValue * (values.length - 1))].getVersion().getVersion()); | ||
this.dragging = true; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e). | ||
*/ | ||
public void mouseReleased(final int mouseX, final int mouseY) { | ||
this.dragging = false; | ||
} | ||
|
||
public void setVersion(final int protocol) { | ||
this.dragValue = (float) (ProtocolCollection.values().length - Arrays.asList(ProtocolCollection.values()).indexOf(ProtocolCollection.getProtocolCollectionById(protocol))) / ProtocolCollection.values().length; | ||
this.sliderValue = this.dragValue; | ||
this.displayString = values[(int) (this.sliderValue * (values.length - 1))].getVersion().getName(); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/main/java/cc/paimonmc/viamcp/gui/GuiProtocolSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package cc.paimonmc.viamcp.gui; | ||
|
||
import cc.paimonmc.viamcp.ViaMCP; | ||
import cc.paimonmc.viamcp.protocols.ProtocolCollection; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.client.gui.GuiSlot; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.util.EnumChatFormatting; | ||
|
||
import java.io.IOException; | ||
|
||
public class GuiProtocolSelector extends GuiScreen { | ||
private final GuiScreen parent; | ||
public SlotList list; | ||
|
||
public GuiProtocolSelector(final GuiScreen parent) { | ||
this.parent = parent; | ||
} | ||
|
||
@Override | ||
public void initGui() { | ||
super.initGui(); | ||
buttonList.add(new GuiButton(1, width / 2 - 100, height - 25, 200, 20, "Back")); | ||
buttonList.add(new GuiButton(2, width / 2 - 180, height - 25, 75, 20, "Credits")); | ||
list = new SlotList(mc, width, height, 32, height - 32, 10); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(final GuiButton guiButton){ | ||
list.actionPerformed(guiButton); | ||
|
||
if (guiButton.id == 1) { | ||
mc.displayGuiScreen(parent); | ||
} | ||
} | ||
|
||
@Override | ||
public void handleMouseInput() throws IOException { | ||
list.handleMouseInput(); | ||
super.handleMouseInput(); | ||
} | ||
|
||
@Override | ||
public void drawScreen(final int mouseX, final int mouseY, final float partialTicks) { | ||
list.drawScreen(mouseX, mouseY, partialTicks); | ||
GlStateManager.pushMatrix(); | ||
GlStateManager.scale(2.0, 2.0, 2.0); | ||
final String title = EnumChatFormatting.BOLD + "ViaMCP Reborn"; | ||
drawString(this.fontRendererObj, title, (this.width - (this.fontRendererObj.getStringWidth(title) * 2)) / 4, 5, -1); | ||
GlStateManager.popMatrix(); | ||
|
||
final String versionName = ProtocolCollection.getProtocolById(ViaMCP.getInstance().getVersion()).getName(); | ||
final String versionCodeName = ProtocolCollection.getProtocolInfoById(ViaMCP.getInstance().getVersion()).getName(); | ||
final String versionReleaseDate = ProtocolCollection.getProtocolInfoById(ViaMCP.getInstance().getVersion()).getReleaseDate(); | ||
final String versionTitle = "Version: " + versionName + " - " + versionCodeName; | ||
final String versionReleased = "Released: " + versionReleaseDate; | ||
|
||
final int fixedHeight = ((5 + this.fontRendererObj.FONT_HEIGHT) * 2) + 2; | ||
|
||
drawString(this.fontRendererObj, EnumChatFormatting.GRAY + (EnumChatFormatting.BOLD + "Version Information"), (width - this.fontRendererObj.getStringWidth("Version Information")) / 2, fixedHeight, -1); | ||
drawString(this.fontRendererObj, versionTitle, (width - this.fontRendererObj.getStringWidth(versionTitle)) / 2, fixedHeight + this.fontRendererObj.FONT_HEIGHT, -1); | ||
drawString(this.fontRendererObj, versionReleased, (width - this.fontRendererObj.getStringWidth(versionReleased)) / 2, fixedHeight + this.fontRendererObj.FONT_HEIGHT * 2, -1); | ||
|
||
super.drawScreen(mouseX, mouseY, partialTicks); | ||
} | ||
|
||
class SlotList extends GuiSlot { | ||
public SlotList(final Minecraft mc, final int width, final int height, final int top, final int bottom, final int slotHeight) { | ||
super(mc, width, height, top + 30, bottom, 18); | ||
} | ||
|
||
@Override | ||
public int getSize() { | ||
return ProtocolCollection.values().length; | ||
} | ||
|
||
@Override | ||
public void elementClicked(final int i, final boolean b, final int i1, final int i2) { | ||
final int protocolVersion = ProtocolCollection.values()[i].getVersion().getVersion(); | ||
ViaMCP.getInstance().setVersion(protocolVersion); | ||
ViaMCP.getInstance().asyncSlider.setVersion(protocolVersion); | ||
} | ||
|
||
@Override | ||
public boolean isSelected(final int i) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void drawBackground() { | ||
drawDefaultBackground(); | ||
} | ||
|
||
@Override | ||
public void drawSlot(final int i, final int i1, final int i2, final int i3, final int i4, final int i5) { | ||
drawCenteredString(mc.fontRendererObj, (ViaMCP.getInstance().getVersion() == ProtocolCollection.values()[i].getVersion().getVersion() ? EnumChatFormatting.GREEN.toString() + EnumChatFormatting.BOLD : EnumChatFormatting.GRAY.toString()) + ProtocolCollection.getProtocolById(ProtocolCollection.values()[i].getVersion().getVersion()).getName(), width / 2, i2 + 2, -1); | ||
GlStateManager.pushMatrix(); | ||
GlStateManager.scale(0.5, 0.5, 0.5); | ||
drawCenteredString(mc.fontRendererObj, "PVN: " + ProtocolCollection.getProtocolById(ProtocolCollection.values()[i].getVersion().getVersion()).getVersion(), width, (i2 + 2) * 2 + 20, -1); | ||
GlStateManager.popMatrix(); | ||
} | ||
} | ||
} |
Oops, something went wrong.