Skip to content

Commit

Permalink
各种更新,到时候再一点一点塞回正式版里
Browse files Browse the repository at this point in the history
  • Loading branch information
reserveword authored and reserveword committed Feb 25, 2024
1 parent 06ec55b commit 1a49605
Show file tree
Hide file tree
Showing 52 changed files with 517 additions and 797 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ build

# other
eclipse
run

# Files from Forge MDK
forge*changelog.txt
/forge/runs/
/fabric/run/
15 changes: 5 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ allprojects {
fabric_version : fabric_version,
yarn_mappings : yarn_mappings,
loader_version : loader_version,
forge_version : forge_version,
loader_version_range: loader_version_range,
mapping_channel : mapping_channel,
mapping_version : mapping_version
]

tasks.withType(ProcessResources).configureEach {
Expand All @@ -88,22 +85,20 @@ allprojects {

tasks.register('feedbackClass', Copy) {
dependsOn "jar"
mustRunAfter ":forge:reobfJar"
mustRunAfter ":fabric:remapJar"
from (zipTree(new File(buildDir, "libs/${project.name}.jar"))) {
from (zipTree(layout.buildDirectory.file("libs/${project.name}.jar"))) {
include '**/*.class'
}
into new File(rootProject.buildDir, 'classes/java/main')
into rootProject.layout.buildDirectory.file('classes/java/main')
}

tasks.register('feedbackResource', Copy) {
dependsOn "jar"
mustRunAfter ":forge:reobfJar"
mustRunAfter ":fabric:remapJar"
from (zipTree(new File(buildDir, "libs/${project.name}.jar"))) {
from (zipTree(layout.buildDirectory.file("libs/${project.name}.jar"))) {
exclude '**/*.class'
}
into new File(rootProject.buildDir, 'resources/main')
into rootProject.layout.buildDirectory.file('resources/main')
}

tasks.register('feedback') {
Expand All @@ -112,7 +107,7 @@ allprojects {
}
}

archivesBaseName "${rootProject.name}_${mod_version}+${minecraft_version}"
base.archivesName = "${rootProject.name}_${mod_version}+${minecraft_version}"

project.jar {
dependsOn ':common:feedback'
Expand Down
21 changes: 21 additions & 0 deletions common/src/main/java/io/github/reserveword/imblocker/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.regex.Pattern;

public class Common {
public static final String MODID = "imblocker";
public static final Logger LOGGER = LogManager.getLogger();
private static final Pattern textFieldPattern = Pattern.compile(".*(TextField|EditBox|EditText)[^.]*$", Pattern.CASE_INSENSITIVE);
private static final HashMap<Class<?>, Boolean> textFieldCache = new HashMap<>();

public static boolean classIsTextField(Class<?> c) {
if (textFieldCache.containsKey(c)) {
return textFieldCache.get(c);
}
boolean result;
if (c == null) {
result = false;
} else if (textFieldPattern.matcher(c.getName()).matches()) {
result = true;
} else {
result = classIsTextField(c.getSuperclass());
}
textFieldCache.put(c, result);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static void checkNonPrintable(ScreenInfo screen) {
try {
screen.charTyped(nonPrintable, 0); // charTyped
} catch (Exception e) {
e.printStackTrace();
Common.LOGGER.error("checkNonPrintable charTyped error:", e);
}
}
state.remove(IMState.NON_PRINTABLE_CHALLENGE_PENDING);
Expand Down Expand Up @@ -164,20 +164,27 @@ public static void captureClick(BooleanSupplier active) {
actives.add(active);
}

// connect rules above
private static long nextCheck = System.currentTimeMillis() + Config.INSTANCE.getCheckInterval();
private static boolean scheduled = false;

public static void clientTick(ScreenInfo screen) {
checkScreenList(screen);
checkSpecial();
if (count == 0) checkTick();
long now = System.currentTimeMillis();
if (nextCheck < now && (scheduled || screen.get() == null)) {
nextCheck = now + Config.INSTANCE.getCheckInterval();
scheduled = false;
checkTick();
}
checkNonPrintable(screen);
checkClick();
syncState();
// check interval
if (count > 0) count --;
else count = Config.INSTANCE.getCheckInterval();
}

// connect rules above
private static int count = Config.INSTANCE.getCheckInterval();
public static void scheduleTickCheck() {
scheduled = true;
}

public static void mouseEvent() {
state.add(IMState.NON_PRINTABLE_CHALLENGE_PENDING);
Expand Down
72 changes: 44 additions & 28 deletions common/src/main/java/io/github/reserveword/imblocker/IMManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;

@SuppressWarnings("unused")
public class IMManager {

private static native WinNT.HANDLE ImmGetContext(WinDef.HWND hwnd);
Expand All @@ -17,46 +18,59 @@ public class IMManager {

private static native boolean ImmDestroyContext(WinNT.HANDLE himc);

private static final boolean isWin;

static {
Native.register("imm32");
isWin = System.getProperty("os.name").toLowerCase().contains("win");
if (isWin) {
Native.register("imm32");
}
}

private static final User32 u = User32.INSTANCE;

private static boolean state = true;

private static void makeOnImp() {
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmGetContext(hwnd);
if (himc == null) {
himc = ImmCreateContext();
ImmAssociateContext(hwnd, himc);
if (isWin) {
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmGetContext(hwnd);
if (himc == null) {
himc = ImmCreateContext();
ImmAssociateContext(hwnd, himc);
}
ImmReleaseContext(hwnd, himc);
}
ImmReleaseContext(hwnd, himc);
}

private static void makeOffImp() {
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmAssociateContext(hwnd, null);
if (himc != null) {
ImmDestroyContext(himc);
if (isWin) {
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmAssociateContext(hwnd, null);
if (himc != null) {
ImmDestroyContext(himc);
}
ImmReleaseContext(hwnd, himc);
}
ImmReleaseContext(hwnd, himc);
}

private static boolean toggleImp() {
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmGetContext(hwnd);
if (himc == null) {
himc = ImmCreateContext();
ImmAssociateContext(hwnd, himc);
ImmReleaseContext(hwnd, himc);
return true;
if (isWin) {
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmGetContext(hwnd);
if (himc == null) {
himc = ImmCreateContext();
ImmAssociateContext(hwnd, himc);
ImmReleaseContext(hwnd, himc);
return true;
} else {
himc = ImmAssociateContext(hwnd, null);
ImmDestroyContext(himc);
ImmReleaseContext(hwnd, himc);
return false;
}
} else {
himc = ImmAssociateContext(hwnd, null);
ImmDestroyContext(himc);
ImmReleaseContext(hwnd, himc);
return false;
return true; // always make im on
}
}

Expand Down Expand Up @@ -86,11 +100,13 @@ public static void makeState(boolean on) {
}

public static void syncState() {
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmGetContext(hwnd);
if ((himc == null) == state) {
Common.LOGGER.warn("IM state inconsistent! state={}, im={}", state, himc != null);
toggle();
if (isWin) {
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmGetContext(hwnd);
if ((himc == null) == state) {
Common.LOGGER.warn("IM state inconsistent! state={}, im={}", state, himc != null);
toggle();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/src/main/resources/assets/imblocker/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"key.imblocker.checkInterval" : "Per how many ticks do we check text field once? Make sure checkDelay is an exact multiple of this.",
"key.imblocker.checkIntervalMilli" : "Per how many ms do we check text field once?",
"key.imblocker.screenBlacklist": "Matched screen would disable your IME",
"key.imblocker.screenWhitelist": "Matched screen would enable your IME",
"key.imblocker.inputBlacklist": "Matched input box would disable your IME",
Expand All @@ -8,7 +8,7 @@
"key.imblocker.recoveredScreens": "Here lists all Screens that is not in whitelist nor blacklist, so you may easily add those to whitelist/blacklist.",
"key.imblocker.useExperimental": "simulate inputting non-printable characters occasionally to detect active input box. Disable this and let me know if input or control is messed up.",
"key.imblocker.checkCommandChat": "Disable IME when typing commands",
"text.autoconfig.imblocker.option.checkInterval" : "Per how many ticks do we check text field once? Make sure checkDelay is an exact multiple of this.",
"text.autoconfig.imblocker.option.checkIntervalMilli" : "Per how many ticks do we check text field once? Make sure checkDelay is an exact multiple of this.",
"text.autoconfig.imblocker.option.screenBlacklist": "Matched screen would disable your IME",
"text.autoconfig.imblocker.option.screenWhitelist": "Matched screen would enable your IME",
"text.autoconfig.imblocker.option.inputBlacklist": "Matched input box would disable your IME",
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/resources/assets/imblocker/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"key.imblocker.checkInterval": "每多少tick检查一次文本框",
"key.imblocker.checkIntervalMilli": "每多少毫秒检查一次文本框",
"key.imblocker.screenBlacklist": "该列表中的GUI屏幕会禁用输入法",
"key.imblocker.screenWhitelist": "该列表中的GUI屏幕会激活输入法",
"key.imblocker.inputBlacklist": "该列表中的输入框会禁用输入法",
Expand All @@ -8,7 +8,7 @@
"key.imblocker.recoveredScreens": "列出显示过的GUI屏幕,方便编辑黑白名单",
"key.imblocker.useExperimental": "使用不可打印字符判别输入框,如有问题请关闭并咨询作者",
"key.imblocker.checkCommandChat": "输入命令时关闭输入法",
"text.autoconfig.imblocker.option.checkInterval": "每多少tick检查一次文本框",
"text.autoconfig.imblocker.option.checkIntervalMilli": "每多少tick检查一次文本框",
"text.autoconfig.imblocker.option.screenBlacklist": "该列表中的GUI屏幕会禁用输入法",
"text.autoconfig.imblocker.option.screenWhitelist": "该列表中的GUI屏幕会激活输入法",
"text.autoconfig.imblocker.option.inputBlacklist": "该列表中的输入框会禁用输入法",
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/resources/assets/imblocker/lang/zh_tw.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"key.imblocker.checkInterval" : "每隔多少刻檢查一次文字框?請確定 checkDelay 是此數的整數倍。",
"key.imblocker.checkIntervalMilli" : "每隔多少毫秒檢查一次文字框?",
"key.imblocker.screenBlacklist": "匹配的螢幕將停用您的輸入法",
"key.imblocker.screenWhitelist": "匹配的螢幕將啟用您的輸入法",
"key.imblocker.inputBlacklist": "匹配的輸入框將停用您的輸入法",
Expand All @@ -8,7 +8,7 @@
"key.imblocker.recoveredScreens": "這裡列出了不在白名單或黑名單中的所有螢幕,以便您可以輕鬆將其新增到白名單/黑名單中。",
"key.imblocker.useExperimental": "偶爾模擬輸入不可打印字符以檢測活動的輸入框。如果輸入或控件出現問題,請停用此功能並告訴我。",
"key.imblocker.checkCommandChat": "在輸入指令時停用輸入法",
"text.autoconfig.imblocker.option.checkInterval" : "每隔多少刻檢查一次文本框?請確定 checkDelay 是此數的整數倍。",
"text.autoconfig.imblocker.option.checkIntervalMilli" : "每隔多少刻檢查一次文本框?請確定 checkDelay 是此數的整數倍。",
"text.autoconfig.imblocker.option.screenBlacklist": "匹配的螢幕將停用您的輸入法",
"text.autoconfig.imblocker.option.screenWhitelist": "匹配的螢幕將啟用您的輸入法",
"text.autoconfig.imblocker.option.inputBlacklist": "匹配的輸入框將停用您的輸入法",
Expand Down
File renamed without changes
27 changes: 11 additions & 16 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'eclipse'
id 'idea'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.5-SNAPSHOT'
}

loom {
Expand All @@ -25,22 +25,18 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"

modApi "com.terraformersmc:modmenu:${modmenu_version}"
modApi "me.shedaniel.cloth:cloth-config-fabric:${clothconfig_version}" exclude group: "net.fabricmc.fabric-api"
// optional dependencies
modApi "com.terraformersmc:modmenu:$modmenu_version"
modApi "me.shedaniel.cloth:cloth-config-fabric:$clothconfig_version" exclude group: "net.fabricmc.fabric-api"

// REI API for Fabric
modCompileOnlyApi "me.shedaniel:RoughlyEnoughItems-api-fabric:$rei_version"
modCompileOnlyApi "me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:$rei_version"
// compile time reference
// none

// run time test
modRuntimeOnly "dev.emi:emi-fabric:$emi_version"
modRuntimeOnly "maven.modrinth:replaymod:$replaymod_version"
modRuntimeOnly "maven.modrinth:voxelmap-updated:$voxelmap_version"
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:$rei_version"
// compat
modCompileOnlyApi "maven.modrinth:replaymod:$replaymod_version"
modCompileOnlyApi "maven.modrinth:notebook:$notebook_version"
modCompileOnly "curse.maven:ftblib-$ftblib_version"
modLocalRuntime "maven.modrinth:voxelmap-updated:$voxelmap_version"
modCompileOnlyApi "dev.emi:emi-fabric:$emi_version:api"
modLocalRuntime "dev.emi:emi-fabric:$emi_version"
// modRuntimeOnly "curse.maven:ftbquest-$ftbquest_version"
modCompileOnly "io.github.cottonmc:LibGui:$cottonlibgui_version"

implementation project(':common')
}
Expand Down Expand Up @@ -68,5 +64,4 @@ project.jar {
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
exclude 'io/github/reserveword/imblocker/asmdummy'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.reserveword.imblocker;

import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
import net.minecraft.client.gui.screen.ingame.HangingSignEditScreen;
import net.minecraft.client.gui.screen.ingame.SignEditScreen;
Expand All @@ -11,6 +12,7 @@ public class FabricCommon {
BookEditScreen.class.getName(),
SignEditScreen.class.getName(),
HangingSignEditScreen.class.getName(),
TitleScreen.class.getName(),
"journeymap.client.ui.waypoint.WaypointEditor",
"com.ldtteam.blockout.BOScreen");
public static final List<String> defaultScreenBlacklist = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

@me.shedaniel.autoconfig.annotation.Config(name = Common.MODID)
public class FabricConfig extends Config implements ModMenuApi, ConfigData {
int checkInterval = 2;
int checkIntervalMilli = 100;
ArrayList<String> screenBlacklist = new ArrayList<>(FabricCommon.defaultScreenBlacklist);
ArrayList<String> screenWhitelist = new ArrayList<>(FabricCommon.defaultScreenWhitelist);
ArrayList<String> inputBlacklist = new ArrayList<>();
ArrayList<String> inputWhitelist = new ArrayList<>();
boolean enableScreenRecovering = false;
ArrayList<String> recoveredScreens = new ArrayList<>();
boolean useExperimental = true;
boolean useExperimental = false;
boolean checkCommandChat = true;

@Override
Expand Down Expand Up @@ -67,7 +67,7 @@ public boolean inInputWhitelist(Class<?> cls) {

@Override
public Integer getCheckInterval() {
return checkInterval;
return checkIntervalMilli;
}

@Override
Expand Down
Loading

0 comments on commit 1a49605

Please sign in to comment.