Test Account Changer

This commit is contained in:
kirillsaint 2023-08-02 14:12:26 +06:00
parent ec7b131aa1
commit 3bc65a3eb0
7 changed files with 214 additions and 12 deletions

View File

@ -88,6 +88,7 @@ public class Client {
private MouseCursorHandler mouseCursorHandler;
private GlobalSettings globalSettings;
private File globalSettingsFile;
private AccountManager accountManager;
public static void memoryDebug(String paramString) {
LogManager.getLogger().info("-- Start Memory Debug -- " + paramString);
@ -242,6 +243,9 @@ public class Client {
EventManager.register(cpsTracker);
logger.info("STARTING > cosmetics");
cosmetics.init();
logger.info("STARTING > account-manager");
accountManager = new AccountManager();
accountManager.init();
logger.info("STARTING > entity-culling");
EventManager.register(new EntityCulling());
EntityCulling.SUPPORT_NEW_GL = GLContext.getCapabilities().OpenGL33;
@ -272,11 +276,6 @@ public class Client {
Minecraft.getMinecraft().displayGuiScreen(new GuiError("Authorization Error. Try restarting the game"));
return;
}
if(!Client.getInstance().getAccount().getUsername().equals(Minecraft.getMinecraft().getSession().getUsername().toLowerCase())) {
logger.info("STARTING > ERROR: " + "Usernames SC and MC account do not match");
Minecraft.getMinecraft().displayGuiScreen(new GuiError("Usernames SC and MC account do not match"));
return;
}
if(Client.getInstance().getAccount().isBanned()) {
logger.info("STARTING > ERROR: " + "Account is banned");
Minecraft.getMinecraft().displayGuiScreen(new GuiError("Your account is banned"));
@ -396,7 +395,7 @@ public class Client {
}
}
private PlayerResponse updateAccount() {
public PlayerResponse updateAccount() {
try {
URL url = new URL("https://api.silentclient.net/account");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
@ -520,6 +519,14 @@ public class Client {
}
// Instances
public String getApiUrl() {
return "http://localhost:" + getUserData().port;
}
public AccountManager getAccountManager() {
return accountManager;
}
public FriendsResponse getFriends() {
return friends;
}

View File

@ -1,6 +1,10 @@
package net.silentclient.client.gui.silentmainmenu.components;
import net.minecraft.client.Minecraft;
import net.silentclient.client.Client;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.utils.AccountManager;
public class AccountPicker {
private boolean open;
@ -14,10 +18,44 @@ public class AccountPicker {
}
public void draw(Minecraft mc, int mouseX, int mouseY) {
// Client.getInstance().getSilentFontRenderer().drawCenteredString(Client.getInstance().getAccount().original_username, x, y, 14, SilentFontRenderer.FontType.TITLE);
Client.getInstance().getSilentFontRenderer().drawCenteredString(Client.getInstance().getAccount().original_username, x, y, 14, SilentFontRenderer.FontType.TITLE);
if(this.open) {
int accountY = y + 15;
for(AccountManager.AccountType account : Client.getInstance().getAccountManager().getAccounts()) {
if(Client.getInstance().getAccount().getUsername().equalsIgnoreCase(account.username)) {
continue;
}
Client.getInstance().getSilentFontRenderer().drawCenteredString(account.username, x, accountY, 14, SilentFontRenderer.FontType.TITLE);
accountY += 15;
}
}
}
public void onClick(Minecraft mc, int mouseX, int mouseY) {
if(MouseUtils.isInside(mouseX, mouseY, x - (Client.getInstance().getSilentFontRenderer().getStringWidth(Client.getInstance().getAccount().original_username, 14, SilentFontRenderer.FontType.TITLE) / 2), y, Client.getInstance().getSilentFontRenderer().getStringWidth(Client.getInstance().getAccount().original_username, 14, SilentFontRenderer.FontType.TITLE), 14)) {
this.open = !this.open;
(new Thread(() -> {
Client.getInstance().getAccountManager().updateAccounts();
})).start();
return;
}
if(this.open) {
int accountY = y + 15;
int accountIndex = 0;
for(AccountManager.AccountType account : Client.getInstance().getAccountManager().getAccounts()) {
if(Client.getInstance().getAccount().getUsername().equalsIgnoreCase(account.username)) {
accountIndex += 1;
continue;
}
if(MouseUtils.isInside(mouseX, mouseY, x - (Client.getInstance().getSilentFontRenderer().getStringWidth(account.username, 14, SilentFontRenderer.FontType.TITLE) / 2), accountY, Client.getInstance().getSilentFontRenderer().getStringWidth(account.username, 14, SilentFontRenderer.FontType.TITLE), 14)) {
Client.getInstance().getAccountManager().setSelected(account, accountIndex, false);
this.open = false;
break;
}
accountY += 15;
accountIndex += 1;
}
}
}
}

View File

@ -0,0 +1,5 @@
package net.silentclient.client.mixin.ducks;
public interface MinecraftExt {
void setSession(Object session);
}

View File

@ -15,6 +15,7 @@ import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Session;
import net.minecraft.world.WorldSettings;
import net.silentclient.client.Client;
import net.silentclient.client.event.impl.*;
@ -22,6 +23,7 @@ import net.silentclient.client.gui.lite.LiteMainMenu;
import net.silentclient.client.gui.silentmainmenu.MainMenuConcept;
import net.silentclient.client.gui.util.BackgroundPanorama;
import net.silentclient.client.hooks.MinecraftHook;
import net.silentclient.client.mixin.ducks.MinecraftExt;
import net.silentclient.client.mods.player.ZoomMod;
import net.silentclient.client.mods.render.AnimationsMod;
import net.silentclient.client.mods.settings.FPSBoostMod;
@ -32,10 +34,7 @@ import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
@ -45,7 +44,7 @@ import java.io.File;
import java.io.IOException;
@Mixin(Minecraft.class)
public abstract class MinecraftMixin {
public abstract class MinecraftMixin implements MinecraftExt {
@Inject(method = "startGame", at = @At("HEAD"))
public void initClient(CallbackInfo callbackInfo) throws IOException {
Client.getInstance().init();
@ -67,6 +66,11 @@ public abstract class MinecraftMixin {
// }
}
@Override
public void setSession(Object session) {
this.session = (Session) session;
}
@Inject(method = "shutdownMinecraftApplet", at = @At("HEAD"))
public void shutdownClient(CallbackInfo callbackInfo) throws Throwable {
Client.getInstance().shutdown();
@ -121,6 +125,9 @@ public abstract class MinecraftMixin {
@Shadow public GameSettings gameSettings;
@Mutable
@Shadow @Final private Session session;
@Inject(method = "displayGuiScreen", at = @At("RETURN"), cancellable = true)
public void displayGuiScreenInject(GuiScreen guiScreenIn, CallbackInfo ci) {
if(Client.backgroundPanorama == null) {

View File

@ -0,0 +1,94 @@
package net.silentclient.client.utils;
import com.google.common.reflect.TypeToken;
import net.minecraft.client.Minecraft;
import net.minecraft.util.Session;
import net.silentclient.client.Client;
import net.silentclient.client.gui.silentmainmenu.MainMenuConcept;
import net.silentclient.client.mixin.ducks.MinecraftExt;
import net.silentclient.client.utils.types.PlayerResponse;
import org.json.JSONObject;
import java.lang.reflect.Type;
import java.util.ArrayList;
public class AccountManager {
private ArrayList<AccountType> accounts;
private AccountType selected;
public void init() {
Client.logger.info("[ACCOUNT-MANAGER]: Getting accounts");
updateAccounts();
Client.logger.info("[ACCOUNT-MANAGER]: Getting selected account");
String accountText = Requests.httpGet(Client.getInstance().getApiUrl() + "/selected");
if(accountText != null) {
try {
AccountType account = Client.getInstance().getGson().fromJson(accountText, AccountType.class);
Client.logger.info("[ACCOUNT-MANAGER]: Selected Account Username: " + account.username);
setSelected(account, 0, true);
} catch (Exception err) {
Client.logger.catching(err);
}
}
}
public void updateAccounts() {
String accountsText = Requests.httpGet(Client.getInstance().getApiUrl() + "/accounts");
if(accountsText != null) {
try {
Type listType = new TypeToken<ArrayList<AccountType>>(){}.getType();
accounts = Client.getInstance().getGson().fromJson(accountsText, listType);
} catch (Exception err) {
Client.logger.catching(err);
}
}
}
public void setSelected(AccountType account, int index, boolean force) {
if(!force) {
Requests.httpPost(Client.getInstance().getApiUrl() + "/set_selected", new JSONObject().put("selected", index).toString());
}
selected = account;
Session session = new Session(account.username, nameToUuid(account.username), account.mc_access_token != null ? account.mc_access_token : "0", account.mc_access_token != null ? "msa" : "legacy");
((MinecraftExt) Minecraft.getMinecraft()).setSession(session);
Client.getInstance().getUserData().setAccessToken(selected.access_token);
Client.getInstance().getSilentSocket().Disconnect();
Client.getInstance().getSilentSocket().Connect(selected.access_token);
PlayerResponse acc = Client.getInstance().updateAccount();
if(acc != null) {
Client.getInstance().setAccount(acc.getAccount());
}
MainMenuConcept.imageLocation = null;
MainMenuConcept.image = null;
MainMenuConcept.initSkin = false;
}
public static String nameToUuid(String username) {
try {
String content = Requests.httpGet(Client.getInstance().getApiUrl() + "/uuid?username="+username);
return Client.getInstance().getGson().fromJson(content, UuidResponse.class).uuid;
} catch (Exception err) {
Client.logger.catching(err);
return "0";
}
}
public ArrayList<AccountType> getAccounts() {
return accounts;
}
public class AccountType {
public String username;
public String access_token;
public String mc_access_token;
public String mc_refresh_token;
}
public class UuidResponse {
public String uuid;
}
}

View File

@ -7,6 +7,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class Requests {
@ -54,4 +55,49 @@ public class Requests {
return null;
}
}
public static String httpGet(String url) {
return httpRequest("GET", url, null);
}
public static String httpPost(String url, String data) {
return httpRequest("POST", url, data);
}
public static String httpPost(String url) {
return httpRequest("POST", url, null);
}
public static String httpRequest(String method, String urlOriginal, String data) {
try {
Client.logger.info("Sending a HTTP " + method + " Request to a URL: " + urlOriginal + " with data: " + data);
URL url = new URL(urlOriginal);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod(method);
con.setRequestProperty("User-Agent", "SilentClient");
con.setRequestProperty("Authorization", "Bearer " + Client.getInstance().getUserData().getAccessToken());
if(data != null) {
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
try(OutputStream os = con.getOutputStream()) {
byte[] input = data.getBytes("utf-8");
os.write(input, 0, input.length);
}
}
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
con.disconnect();
Client.logger.info("HTTP " + method + " Request ("+ urlOriginal +") Response: " + content.toString());
return content.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -2,6 +2,7 @@ package net.silentclient.client.utils.types;
public class UserData {
public String access_token;
public int port;
public UserData() {
this.access_token = "";
@ -14,4 +15,8 @@ public class UserData {
public String getAccessToken() {
return access_token;
}
public void setAccessToken(String access_token) {
this.access_token = access_token;
}
}