Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CubeWhy committed Aug 1, 2023
1 parent dc56a84 commit 370fbeb
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 66 deletions.
29 changes: 25 additions & 4 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/main/java/org/cubewhy/lunarcn/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.cubewhy.lunarcn.event.EventManager;
import org.cubewhy.lunarcn.event.EventTarget;
import org.cubewhy.lunarcn.event.events.PacketEvent;
import org.cubewhy.lunarcn.event.events.SessionEvent;
import org.cubewhy.lunarcn.event.events.TickEvent;
import org.cubewhy.lunarcn.files.configs.*;
import org.cubewhy.lunarcn.gui.SplashProgress;
Expand Down Expand Up @@ -121,6 +122,8 @@ public void onStart() {
} else {
currentAccount.switchAccount();
}

new SessionEvent(mc.session).callEvent();
}

public void onStop() {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/cubewhy/lunarcn/gui/PCLWarning.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import org.cubewhy.lunarcn.Client;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.io.IOException;
Expand All @@ -12,15 +14,15 @@ public class PCLWarning extends GuiScreen {
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
drawCenteredString(fontRenderer, "PCL2警告", this.width / 2, 10, new Color(255, 255, 255).getRGB());
drawCenteredString(fontRenderer, "此客户端为完全开源的客户端, 不存在任何后门, 如果你分享了PCL2的错误报告而导致被盗号, 与本客户端无关", this.width / 2, 10 + fontRenderer.FONT_HEIGHT, new Color(255, 255, 255).getRGB());
drawCenteredString(fontRenderer, "点下面的确认继续游戏", this.width / 2, 10 + fontRenderer.FONT_HEIGHT * 2, new Color(255, 255, 255).getRGB());
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 2, "确认"));
drawCenteredString(fontRenderer, "PCL2 Warning", this.width / 2, 10, new Color(255, 255, 255).getRGB());
drawCenteredString(fontRenderer, String.format("PCL2 have a bug, hackers can hack your account via the bug, and %s isn't fully support PCL2, use your own risk", Client.clientName), this.width / 2, 10 + fontRenderer.FONT_HEIGHT, new Color(255, 255, 255).getRGB());
drawCenteredString(fontRenderer, "Click OK to continue playing", this.width / 2, 10 + fontRenderer.FONT_HEIGHT * 2, new Color(255, 255, 255).getRGB());
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 2, "OK"));
super.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
protected void actionPerformed(@NotNull GuiButton button) {
switch (button.id) {
case 1:
mc.displayGuiScreen(null);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cubewhy/lunarcn/gui/VerticalScroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class VerticalScroller extends Gui {
public final int width;
public final int height;
public int totalHeight;
public int current = 0;
public double current = 0;
public boolean hovered = false;

public VerticalScroller(int x, int y, int width, int height, int totalHeight) {
Expand All @@ -32,7 +32,7 @@ public void drawScroller() {
RenderUtils.drawRoundedRect(x, y, width, height, 2, new Color(0, 0, 0, 40));
if (hovered || status != 0) {
// progress
RenderUtils.drawRoundedRect(x, y + current * height, width, height / totalHeight, 2, new Color(0, 90, 0, 50));
RenderUtils.drawRoundedRect(x, (int) (y + current * height), width, height / totalHeight, 2, new Color(0, 90, 0, 50));
}

if (status > 0 && current < 1) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/cubewhy/lunarcn/gui/hud/HudDesigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.cubewhy.lunarcn.files.configs.PositionConfigFile;
import org.cubewhy.lunarcn.gui.clickgui.ClickGui;
import org.cubewhy.lunarcn.gui.elements.ClientButton;
import org.cubewhy.lunarcn.utils.ClientUtils;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;

Expand All @@ -18,6 +19,7 @@
import java.util.Optional;
import java.util.function.Predicate;

import static org.cubewhy.lunarcn.utils.ClientUtils.*;
import static org.cubewhy.lunarcn.utils.RenderUtils.drawHollowRect;

public class HudDesigner extends GuiScreen {
Expand All @@ -33,9 +35,6 @@ public HudDesigner(HudManager hudManager) {
Collection<IRenderer> registeredRenderers = hudManager.getRegisteredRenders();

for (IRenderer renderer : registeredRenderers) {
if (!renderer.isEnabled()) {
continue;
}
ScreenPosition position = renderer.load();

if (position == null) {
Expand Down Expand Up @@ -88,7 +87,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
}

@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
protected void keyTyped(char typedChar, int keyCode) {
if (keyCode == Keyboard.KEY_ESCAPE) {
renderers.forEach(IRenderConfig::save);
PositionConfigFile positionFile = PositionConfigFile.getInstance();
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/org/cubewhy/lunarcn/gui/hud/HudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,22 @@ public void onRender(RenderEvent event) {
@EventTarget
public void onRender2D(Render2DEvent event) {
this.updateNotifications();
if (currentNotification!= null) {
if (currentNotification != null) {
currentNotification.render();
}
}

private void callRenderer(@NotNull IRenderer renderer) {
if (!renderer.isEnabled()) {
return;
}
if (renderer.isRendererEnabled()) {
ScreenPosition position = renderer.load();

ScreenPosition position = renderer.load();
if (position == null) {
position = ScreenPosition.fromRelativePosition(0.5, 0.5);
}

if (position == null) {
position = ScreenPosition.fromRelativePosition(0.5, 0.5);
renderer.render(position);
}

renderer.render(position);
}

public void addNotification(Notification notification) {
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/org/cubewhy/lunarcn/gui/hud/IRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,34 @@

public interface IRenderer extends IRenderConfig {
/**
* 获取宽
* Get the width of the component
* @return width
* */
int getWidth();

/**
* 获取高
* Get the height of the component
* @return height
* */
int getHeight();

/**
* 绘制组件
* @param position 坐标
* Render in hub
* @param position where the component render
*/

void render(ScreenPosition position);


/**
* 在{@link HudDesigner}中绘制的样子
* 也就是预览
* Render in {@link HudDesigner}
* */
default void renderDummy(ScreenPosition position) {
render(position);
}

/**
* 获取是否渲染
* 如果要切换状态请使用{@link org.cubewhy.lunarcn.module.Module}中的state变量
* Control the renderer on the hub
* */
default boolean isEnabled() {
return true;
}
default boolean isRendererEnabled() { return true;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;
import org.cubewhy.lunarcn.utils.RenderUtils;
import org.jetbrains.annotations.NotNull;

import java.awt.*;

Expand All @@ -24,10 +25,10 @@ public class Notification {
/**
* 创建一个通知
*
* @param title 题目
* @param message 消息
* @param type 通知类型
* @param showTime 显示时间
* @param title title of the notification
* @param message message to show
* @param type type of the notification
* @param showTime time
*/

public Notification(String title, String message, Type type, int showTime) {
Expand Down Expand Up @@ -71,6 +72,21 @@ public void render() {

i = time / (fadedIn + fadeOut);

Color color = getColor(time);

RenderUtils.drawRoundedRect((int) (res.getScaledWidth() - offset), res.getScaledHeight() - 5 - height, res.getScaledWidth(), res.getScaledHeight() - 5, 2, color);
// RenderUtils.drawRoundedRect((int) (res.getScaledWidth() - offset), res.getScaledHeight() - 5 - height, (int) (res.getScaledWidth() - offset + 4), res.getScaledHeight() - 5, 2, color1);

RenderUtils.drawImage(this.type.icon, (int) (res.getScaledWidth() - offset + 10), res.getScaledHeight() - 5 - height, 25, 25);

fontRenderer.drawString(title, (int) (res.getScaledWidth() - offset + 28), res.getScaledHeight() - 2 - height, -1);
fontRenderer.drawString(message, (int) (res.getScaledWidth() - offset + 28), res.getScaledHeight() - 15, -1);

RenderUtils.drawLine(res.getScaledWidth(), (int) (res.getScaledWidth() - i), res.getScaledHeight() - 7, 1, new Color(0, 26, 169).getRGB(), false);
}

@NotNull
private Color getColor(long time) {
Color color = new Color(0, 0, 0, 60);
Color color1;

Expand All @@ -87,16 +103,7 @@ public void render() {
int i = Math.max(0, Math.min(255, (int) (Math.sin(time / 100.0) * 255.0 / 2 + 127.5)));
color = new Color(i, 0, 0, 220);
}

RenderUtils.drawRoundedRect((int) (res.getScaledWidth() - offset), res.getScaledHeight() - 5 - height, res.getScaledWidth(), res.getScaledHeight() - 5, 2, color);
// RenderUtils.drawRoundedRect((int) (res.getScaledWidth() - offset), res.getScaledHeight() - 5 - height, (int) (res.getScaledWidth() - offset + 4), res.getScaledHeight() - 5, 2, color1);

RenderUtils.drawImage(this.type.icon, (int) (res.getScaledWidth() - offset + 10), res.getScaledHeight() - 5 - height, 25, 25);

fontRenderer.drawString(title, (int) (res.getScaledWidth() - offset + 28), res.getScaledHeight() - 2 - height, -1);
fontRenderer.drawString(message, (int) (res.getScaledWidth() - offset + 28), res.getScaledHeight() - 15, -1);

RenderUtils.drawLine(res.getScaledWidth(), (int) (res.getScaledWidth() - i), res.getScaledHeight() - 7, 1, new Color(0, 26, 169).getRGB(), false);
return color;
}

public enum Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ public void drawChat(int updateCounter) {
drawRect(x, y - 9, x + l + 4, y, l1 / 2 << 24);
String text = chatline.getChatComponent().getFormattedText();
GlStateManager.enableBlend();
if (((ChatConfig) (ModuleManager.getInstance().getModule(ChatConfig.class))).getCopy().getValue()) {
CopyButton copyButton = new CopyButton(chatline.getChatComponent().getUnformattedText());
copyButton.drawButton(Mouse.getX(), Mouse.getY(), y - 8);
if (mc.ingameGUI.getChatGUI().getChatOpen() && ((ChatConfig) (ModuleManager.getInstance().getModule(ChatConfig.class))).getCopy().getValue()) {
new CopyButton(chatline.getChatComponent().getUnformattedText()).drawButton(Mouse.getX(), Mouse.getY(), y - 8);
// TODO why still copy the last message
}
this.mc.fontRendererObj.drawStringWithShadow(text, (float) x, (float) (y - 8), 16777215 + (l1 << 24));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.security.cert.CertificateException;
import java.util.Date;
import java.util.HashMap;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -84,20 +85,20 @@ public String getLoginUrl() {

public MicrosoftAccount loginWithToken(String token) throws IOException {
JsonElement tokenMicrosoft = MicrosoftAccountUtils.getInstance().authFromRefreshToken(token);
String accessToken = tokenMicrosoft.getAsJsonObject().get("access_token").getAsString();
String accessToken = Objects.requireNonNull(tokenMicrosoft).getAsJsonObject().get("access_token").getAsString();

JsonElement tokenXboxLive = MicrosoftAccountUtils.getInstance().authWithXboxLive(accessToken);
String xboxLiveToken = tokenXboxLive.getAsJsonObject().get("Token").getAsString();
String xboxLiveToken = Objects.requireNonNull(tokenXboxLive).getAsJsonObject().get("Token").getAsString();
String userHash = tokenXboxLive.getAsJsonObject().get("DisplayClaims").getAsJsonObject().get("xui").getAsJsonArray().get(0).getAsJsonObject().get("uhs").getAsString();

JsonElement tokenXSTS = MicrosoftAccountUtils.getInstance().authWithXSTS(xboxLiveToken);
String XSTSToken = tokenXSTS.getAsJsonObject().get("Token").getAsString();
String XSTSToken = Objects.requireNonNull(tokenXSTS).getAsJsonObject().get("Token").getAsString();

JsonElement tokenMinecraft = MicrosoftAccountUtils.getInstance().authWithMinecraft(userHash, XSTSToken);
String minecraftToken = tokenMinecraft.getAsJsonObject().get("access_token").getAsString();
String minecraftToken = Objects.requireNonNull(tokenMinecraft).getAsJsonObject().get("access_token").getAsString();

JsonElement storeInformation = MicrosoftAccountUtils.getInstance().getStoreInformation(minecraftToken);
JsonArray storeProducts = storeInformation.getAsJsonObject().get("items").getAsJsonArray();
JsonArray storeProducts = Objects.requireNonNull(storeInformation).getAsJsonObject().get("items").getAsJsonArray();
boolean haveGame = false;
for (JsonElement product : storeProducts) {
if (product.getAsJsonObject().get("name").getAsString().equals("game_minecraft")) {
Expand Down
Loading

0 comments on commit 370fbeb

Please sign in to comment.