Moment For Technology

Java use the Desert plugin to make game background scripts

Posted on Dec. 2, 2022, 7:19 p.m. by Vanya Ramanathan
Category: The back-end Tag: The back-end java Java EE

Cabbage Java study room covers core knowledge

1. Install 32-bit JDK 1.8

For the record, JDK 1.8 must be 32-bit, not 64-bit (there are problems with the latest version of the Plugin).

Download the JDK 1.8 Huawei Cloud Image (select JDK-8u192-Windows-i586.exe).

2. Register and download the Desert plugin

Here to provide the desert plug-in official website address: the desert plug-in official website

The current time (see the author's article release time) to register the recharge desert plugin need to note:

  1. Due to official traffic restrictions, the current account registration time limit is only 1-3 days per month, of course, some forums can buy 20 yuan empty account;
  2. The minimum amount of recharging is 100 yuan, and the charge is 7 cents per machine (computer) per day. There is no need to be clever about the recharging amount of F12 page form. The background of the official website has been verified.
  3. The paid version provided by the author here is 100% stable available, if you really don't want to spend money, please baidu that cracked version, but please bear the risk;
  4. After all is done, go to the software menu to download the tool kit, below is the desert plug-in about some components, pay attention to 360 security guard poison report please add whitelist (rest assured really no poison);

3. Install the Desert plug-in to the system

The principle of the desert plug-in is the author uses VC6.0 written COM interface, support any language call, installation of the Desert plug-in means that the.dll dynamic link library file registered to the system.

Run the registry plugin to system.bat, the code content can be posted to see:

%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)exit
cd /d "%~dp0"
regsvr32 dm.dll
Copy the code

Now that we've done our homework, we're ready to start a new Java project.

4. Create a MAVEN project and import JACOB 1.9 in JDK

To create a new Maven project, you need to download a Jacob 1.9 JAR package. Here is the POM file:

? The XML version = "1.0" encoding = "utf-8"?   project XMLNS = "" XMLNS: xsi = "" Xsi: schemaLocation = ""   modelVersion  4.0.0  / modelVersion   groupId  com. The dm  / groupId   artifactId  drone  / artifactId   version  1.0 - the SNAPSHOT  / version   properties piler. Source  8  / piler source  maven.compiler.target8/ /properties dependencies dependency groupIdcom.jacob/groupId /dependencies /dependencies /dependencies /dependencies /dependenciesCopy the code

JACOB is a java-com connection component that can be downloaded from github

Download it to your computer, go to the directory where the JAR package is, and use the MVN command to import it to your repository:

MVN install: install-file-dgroupid =com. jak-dartifactid = jak-dversion = 1.19-dpackaging = jar-dfile = jak.jarCopy the code

Copy Jacob -1.19-x86. DLL to the 32-bit jdk1.8 installation directory under jre/bin:

5. Java code implementation (see The Desert plug-in interface description. CHM)

Here is the general structure of our project, idea must be run in administrator mode:

Note: We currently implement the background button mouse function, which is the background automatically capture the game progress, similar to the key Sprite input virtual signal (button Sprite window out of focus will not work), at this time you can minimize the game to watch a movie or play another game. Of course, the desert plug-in provides a very powerful API, the reader can go to research, the author compares the dish to use this first.

Open the interface description of the desert plug-in. CHM, you can view the API interface provided:

Below I paste Java code, the specific content is very simple, I believe that students with Java foundation can understand: (plug-in configuration)

import com.jacob.activeX.ActiveXComponent; import; import java.util.ResourceBundle; public class DmConfig { private final static String version = ""; private final static String license = ResourceBundle.getBundle("config").getString("license"); Private final ActiveXComponent dm = new ActiveXComponent("dm.dmsoft"); public DmConfig() { this.version(); this.register(); } public void version() {system.out.println (" plugin version: "+ dm.invoke("Ver").getString()); } public void register() { int success =, "Reg", license, version).getInt(); Println (" registering plugin: "+ (success == 1? "Registration succeeded" : "Registration failed ")); } public ActiveXComponent getDm() { return dm; }}Copy the code

TaskConfig (task Configuration)

import java.util.ResourceBundle; public class TaskConfig { private final String process; private final String[] vk_codes; private final long delay; public TaskConfig() { ResourceBundle bundle = ResourceBundle.getBundle("config"); this.process = bundle.getString("process"); this.vk_codes = bundle.getString("vk_codes").split(","); this.delay = Long.parseLong(bundle.getString("interval")); } public String getProcess() { return process; } public String[] getVk_codes() { return vk_codes; } public long getDelay() { return delay; }}Copy the code (timed thread pool)

import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; public class TimerService { private ScheduledFuture?  future = null; private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); public boolean start(Runnable command, long delay) { try { if (future ! = null) { future.cancel(false); } future = scheduler.scheduleWithFixedDelay(command, 0, delay, TimeUnit.MILLISECONDS); return true; } catch (Exception e) { return false; } } public boolean stop() { try { if (future ! = null) { future.cancel(true); } return true; } catch (Exception e) { return false; }}}Copy the code (virtual KeyboardTask)

import; import; import; Public Class KeyboardTask extends Thread {/** * Extends Thread */ Private final String[] vk_code; /** * private final DmConfig config; public KeyboardTask(DmConfig dmConfig, TaskConfig taskConfig) { this.config = dmConfig; this.vk_code = taskConfig.getVk_codes(); this.bindWindow(taskConfig.getProcess()); } @Override public void run() { for (String item : vk_code) {, "KeyDown", Integer.parseInt(item));, "KeyUp", Integer.parseInt(item)); } } public void bindWindow(String process_name) { int hwnd =, "FindWindowByProcess", process_name, "", "").getInt();, "BindWindow", hwnd, "normal", "windows", "windows", 0); System.out.println(" binding window: "+ process_name); System.out.println(" please enter valid instruction: \n startup script: 1\n end script: 0"); }}Copy the code (launch entry)

import; import; import; import; import java.util.Scanner; public class DroneApplication { public static void main(String[] args) { DmConfig dmConfig = new DmConfig(); TaskConfig taskConfig = new TaskConfig(); KeyboardTask task = new KeyboardTask(dmConfig, taskConfig); TimerService timerService = new TimerService(); Scanner scanner = new Scanner(; while (true) { try { if (scanner.hasNextLine()) { String str = scanner.nextLine(); if (str.equals("1")) { boolean done = timerService.start(task, taskConfig.getDelay()); If (done) system.out.println (" the script starts...") ); continue; } if (str.equals("0")) { boolean done = timerService.stop(); If (done) system.out.println (" exit...") ); continue; } system.out.println (" Please enter valid instruction: \n start script: 1\n end script: 0"); } } catch (Exception e) { e.printStackTrace(); break; }}}}Copy the code (configuration file)

# process=cmd.exe # vk_codes=68,69 # interval=2000Copy the code

Note: Windows mode keyboard virtual code itself Baidu, here is an example mapping: 68='d', 69='e'.

6. Running effect display (idea administrator mode)

The Maven project needs to be packaged and configured by the reader. The result of the package is about 7KB.

Start the project

Enter the script start command

Background window automatic signal

Enter the script end command

Summary: In fact, the Java language is not suitable for scripting, installation of cross-platform running environment is too heavy, for the computer cute new unfriendly, if readers have other scripting language basis, you can try to translate the code used in the past.

About (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.