Is the game too difficult to beat? Teach you to use CE and Python to write your own Plants vs. Zombies modifier (unlimited sunlight, unlimited gold coins, no cooling time)

renderings

Within 1 minute of the start, all the plants have been planted. It can be clearly seen that the number of sunlight is 92074, which is almost endless. It directly makes the zombies have no sense of experience. The zombie: "Are you polite?".

Table of contents

renderings

I. Introduction

2. Tools and game installation

1. Tool installation

2. Game download

3. Implementation ideas 

4. Practical combat: Modify the sunlight value

1. CE modifies sunlight value

2. Code implementation to obtain window handle

3. Code implementation to modify data

4. Implement the modification of Sunshine Video Tutorial

5. Practical Combat: CE Modifies Cooling Value

1. Video tutorial

2. Tutorial for all plants without cooling

6. Resource download 

7. Conclusion


I. Introduction

Friends who have played computer games should be familiar with plug-ins, but have you ever thought about making a plug-in one day? C/C++ language is most suitable for writing this type of project, but as the mainstream Python language today, it is not to be outdone, so let’s take a look at how to use python to make a plug-in for Plants vs. Zombies.


2. Tools and game installation

1. Tool installation

First you need to download a tool that can view program handles

链接:https://pan.baidu.com/s/1922Peza1vTFHL73pVE2PdA
提取码:ghi2

Then we need to download the modification tool. There are many modification tools. Here we choose a more convenient and simple modification tool CE (see the introduction below for what CE is). I have Chineseized the CE tool in the link below. (the original version is in English). If you want to re-download the new version, you can go to the official website to have a look: Cheat Engine

CE Modifier (Cheat Engine) is a memory modification and editing tool. CE allows you to modify the game. It includes hexadecimal editor, disassembler, and memory search tools. Compared with similar modification tools, it has powerful disassembly functions and comes with its own auxiliary tool creation tool, which can be used to directly generate auxiliary tools.

链接:https://pan.baidu.com/s/1j5KO3hPli2Y3A6wRfWevcg
提取码:9hpq

2. Game download

For everyone's convenience, it is best to download the "Plants vs. Zombies" game from the link below , so as to avoid differences caused by different versions.

Link: https://pan.baidu.com/s/1TOmj_Lg5emB9ecw813Zzjg
Extraction code: ykgp


3. Implementation ideas 

What is the nature of the game? I think game = program = data = data address (a collection of variables and values)

Theoretically we can modify these variables and values. For example, if we play a game, the character level is level 10 and the blood volume is 100. Because they are not stored in a variable, we only need to find the variables of 10 and 100 and make them equal to what we want. Numerical value realizes the plug-in function!

All in all, we only need to use the program to find the data address of the game, and then modify it.


4. Practical combat: Modify the sunlight value

1. CE modifies sunlight value

First open the Plants vs. Zombies game, click "Start Adventure" in the game to enter the level, then open the downloaded CE, then click "Computer Icon" to find the Plants vs. Zombies process, and then open it.

 Fill in the current game sun value into the "Value" line of CE, then select "Advanced Scan" in the "Scan Type", and finally click "First Scan" 

After planting the plant, fill in the current game sun value into the "Value" line of CE, and then click " Scan Again " (do not click "New Scan" on the left, otherwise you will have to search for the value again)

Find the address in "Results", double-click the address, then double-click "50" under the value in the "Address Bar" below, and finally modify the value

2. Code implementation to obtain window handle

Open the downloaded "LookHandles" handle search tool and drag the "magnifying glass" in the tool to the game window

Code:

First download the pywin32 library

pip install pywin32

Fill in the second parameter in line 16 of the code to change the obtained window handle.

import win32gui  # 界面模块
import win32process  # 进程模块

kernel32 = ctypes.windll.LoadLibrary(r"kernel32.dll")  # 核心文件
PROCESS_ALL_ACCESS = (0x000F0000 | 0x00100000 | 0xFFF)  # 调用最高权限执行
window_handle = win32gui.FindWindow(None, "Plants vs. Zombies GOTY ")  # 找到窗口句柄
process_id = win32process.GetWindowThreadProcessId(window_handle)[1]  # 获取进程ID
process_handle = win32api.OpenProcess(PROCESS_ALL_ACCESS, False, process_id)  # 得到进程句柄

3. Code implementation to modify data

Code:

data1 = ctypes.c_long()
kernel32.ReadProcessMemory(int(process_handle), 0x0077959c, ctypes.byref(data1), 4, None)
data2 = ctypes.c_long()
kernel32.ReadProcessMemory(int(process_handle), data1.value + 0x950, ctypes.byref(data2),4, None)
kernel32.WriteProcessMemory(int(process_handle), data2.value + 0x50, ctypes.byref(ctypes.c_long(int(money_num))), 4,None)

4. Implement the modification of Sunshine Video Tutorial

Use Python to create plug-ins for the Plants vs. Zombies game, the all-purpose Python


5. Practical Combat: CE Modifies Cooling Value

1. Video tutorial

Because this function is a bit difficult and it is difficult to understand using pictures and text to teach, I recommend the video tutorial below. It is recommended that you watch from 6 minutes and 47 seconds to 12 minutes and 41 seconds of the video , because the teacher's version is different from ours. . I will take you through the tutorial on how to make all plants non-cooling later, so I recommend that you watch the video below first.

Tutorial on modifying sunlight and card slot cooling in Plants vs. Zombies CE

2. Tutorial for all plants without cooling

Friends who have not watched the video above must watch it, so that I can teach you how to make all plants non-cooling

According to the video above, after finding the cooldown value address, right-click the address and click "Find out what overrides..."

Click "Yes" or "Yes" in the pop-up window 

 After planting a plant, you can see 3 more data on the window that just popped up. Double-click the data in the red box.

 Find the data in the red box in the pop-up window and double-click it

 After double-clicking it, don't do the operation first. Just follow the steps in the picture. First click "Tools" and then find "Automatic Assembly" and click

Click "Template" in the pop-up window and then click "CT..." 

How to click "Template" and then "Code Injection"

Then click OK or OK in the pop-up window

Scroll down and look for the code in the red box in the picture. Change ",00" to ",01"

Swipe down again and find the code in the red box in the picture. Change ",00" to ",01" 

When finished click "File" then "Assign to..."

Finally, I closed all windows and found an extra line of "automation script"

Finally, click "Activate" and wait until it changes to "X". All plants will no longer need to cool down, and they will be invincible when equipped with unlimited sunlight!


6. Resource download 

链接:https://pan.baidu.com/s/1yj1HFI7iYuA6F5zAiCoCAw
提取码:uyha

Note:

Modifying the cooling.CT file in the resource can only be run in CE. All friends are asked to download the CE tool first. After opening the modified cooling.CT file, you must first click on the computer icon with a colored halo, find the Plants vs. Zombies process, and then open it. , can be used.

In the window that will pop up after opening the process, be sure to click "Yes" or "Yes" , otherwise it will not work.

Do not open both at the same time! ! ! Do not open both at the same time! ! ! Do not open both at the same time! ! !

You can only open one and close one

The picture below is an error demonstration!


7. Conclusion

At this point, you have completed the implementation of Plants vs. Zombies function in Python!

Are the friends who have successfully made plug-ins a little excited? If you encounter any problems during the operation, you are welcome to give me feedback. If you like it, you can like it and save it. In the future, the editor will update some blogs from time to time and share his own procedures and experiences.

Guess you like

Origin blog.csdn.net/python_sy/article/details/121576803