Skip to content

Commit

Permalink
Fix Build
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoShui committed Jul 9, 2024
1 parent c1abea8 commit 7104ab6
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Made by UnlegitMC
run: echo "##########Made by UnlegitMC!!!##########"
- name: Build
run: ./gradlew setupCiWorkspace && ./gradlew build
run: chmod +x ./gradlew && ./gradlew setupCiWorkspace && ./gradlew build
- name: Rename build artifacts
run: mv build/libs/FDPClient-*.jar build/libs/FDPCNClient-${{ steps.vars.outputs.sha_short }}.jar
- name: Upload build artifacts
Expand Down
6 changes: 1 addition & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
maven { url = "https://repo.spongepowered.org/repository/maven-public/" }
maven { url = "https://jitpack.io/" }
maven { url = "https://fdpclient.club/" }
maven { url = "https://lss233.littleservice.cn/repositories/minecraft/" }
maven { url = "http://lss233.littleservice.cn/repositories/minecraft/" }
maven { url = "https://maven.minecraftforge.net/" }
}

Expand Down Expand Up @@ -63,10 +63,6 @@ dependencies {
exclude module: "jogl-all" // we use lwjgl
exclude module: "gluegen-rt" // this is the library for joal
}
include("com.github.UnlegitMinecraft:FuckPCL:2.0") {
exclude module: "kotlin-stdlib-jdk8"
exclude module: "jna-platform"
}
include("com.jagrosh:DiscordIPC:0.4")
include("com.github.CCBlueX:Elixir:1.2.4") {
exclude module: "kotlin-stdlib"
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/com/guimc/fuckpcl/PCLChecker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.guimc.fuckpcl

import com.guimc.fuckpcl.utils.WindowUtils
import java.io.File
import java.util.*

/**
* A library checks Plain Craft Launcher
* @author guimc, liuli (The UnlegitMC Team)
*/
object PCLChecker {
/**
* This method will delete in next version and this can only check PCL title because the minecraft folder path not given
* @return check result
*/
@Deprecated("This method will delete in next version", ReplaceWith("fullCheck(mcDir, deleteFolder)", "com.guimc.fuckpcl.PCLChecker.fullCheck"))
fun runCheck(): Boolean {
return titleCheck()
}

/**
* run full PCL check
* @param mcDir minecraft folder path
* @param deleteFolder delete PCL data folder for next PCL deleted check
* @return check result
*/
@JvmOverloads
fun fullCheck(mcDir: File, deleteFolder: Boolean = true): Boolean {
// check if there is a window named PCL
if (titleCheck())
return true

// maybe the window not exists like close the window after launched , so we need to check the PCL data folder
if (folderCheck(mcDir, deleteFolder))
return true

// PCL is not exists in the PC
return false
}

/**
* run PCL title check
* check if there exists a title name contained "Plain Craft Launcher"
* @return check result
*/
fun titleCheck(): Boolean {
return if (!WindowUtils.isWindows()) {
false // PCL and the native file only support windows
} else {
WindowUtils.findWindow("Plain Craft Launcher") // PCL Title "Plain Craft Launcher 2"
}
}

/**
* run PCL data folder check
* @param mcDir minecraft folder path
* @param deleteFolder delete PCL data folder for next PCL deleted check
* @return check result
*/
fun folderCheck(mcDir: File, deleteFolder: Boolean): Boolean {
require(mcDir.exists()) { "Argument \"mcDir\" is not exists" }
require(mcDir.isDirectory) { "Argument \"mcDir\" should be a folder" }

var exists = false
val pclDataDir = File(mcDir, "PCL")
if (pclDataDir.exists()) {
if (deleteFolder)
deleteFolder(pclDataDir)
exists=true
} // me need to delete all folders

val mcVersionDir = File(mcDir, "versions")
if (mcVersionDir.exists()) { // I think this should be existed but ...
Arrays.stream(mcVersionDir.listFiles()).forEach { folder: File? ->
val pclVersionDataDir = File(folder, "PCL")
if (pclVersionDataDir.exists()) {
if (deleteFolder)
deleteFolder(pclVersionDataDir)
exists = true
}
}
}
if(exists)
return true

return false
}

private fun deleteFolder(folder: File){
require(folder.exists()) { "Argument \"folder\" is not exists" }
require(folder.isDirectory) { "Argument \"folder\" should be a folder" }

folder.listFiles().forEach {
if(it.isFile){
it.delete()
}else if(it.isDirectory){
deleteFolder(it)
}
}

folder.delete()
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/guimc/fuckpcl/utils/WindowUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.guimc.fuckpcl.utils;

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.win32.StdCallLibrary;

public class WindowUtils {
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg);
int GetWindowTextA(HWND hWnd, byte[] lpString, int nMaxCount);
}

public static boolean isWindows() {
String OS = System.getProperty("os.name").toLowerCase();
return OS.contains("windows");
}

public static Boolean findWindow(String Text) {
final User32 user32 = User32.INSTANCE;
final Boolean[] windowFunded = new Boolean[1];

windowFunded[0] = false;

user32.EnumWindows((hwnd, arg1) -> {
byte[] windowText = new byte[512];
user32.GetWindowTextA(hwnd, windowText, 512);
String wText = Native.toString(windowText);
if(wText.contains(Text)) {
windowFunded[0] = true;
}
return true;
}, null);

return windowFunded[0];
}
}

0 comments on commit 7104ab6

Please sign in to comment.