# f1ze/pvzcheater architecture

> Architecture diagram of the GitHub repository f1ze/pvzcheater, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/f1ze/pvzcheater
- Repository: https://github.com/f1ze/pvzcheater

## Overview

##### Main Components
- Frontend/Control Module (PVZCheater): This contains:
- The main application (main.cpp), GUI (gui.cpp and gui.h) using ImGui from the external/imgui folder.
- Supporting components for game objects, process utilities, and logging.
- DLL Injection Module (pvzdll): This part contains:
- DLL service code (DLLService.cpp/DLLService.h), logger, and the dllmain entry.
- External dependency MinHook for function hooking (external/minhook).
- Game Memory/Data Components:
- Code in both modules refer to functions that read/write in-game memory (structures for game objects, sun, plants, zombies, and bullets).
- Memory addresses and offsets documented in the README indicate the deep integration with game internals.
- External Dependencies:
- ImGui (for user interface) and MinHook (for API/hooking purposes).

##### Relationships and Interactions
- The PVZCheater module serves as the primary user interface and coordinator. It allows the user to trigger cheat functions.
- Upon launch, the application likely injects the pvzdll into the Plants vs. Zombies process.
- The DLL module uses MinHook to intercept relevant game functions (such as modifying sun count, plant actions, bullet spawning, and zombie behavior).
- Communication flows from the user (via the GUI) to the cheater module, which then directs the DLL to execute specific cheats or modifications.
- Both modules log activity (via the logger) and reference a common set of game memory structures (documented in detail in the README).

##### Architectural Patterns and Design Principles
- Separation of Concerns: There is a clear separation between the GUI/control logic (in PVZCheater) and the game hook code (in pvzdll).
- Modularity: The project is broken into distinct components (GUI, hooking DLL, process utilities, logging), which makes it easier to extend or maintain.
- External Library Integration: Use of ImGui and MinHook highlights reliance on well-established libraries to handle GUI and low-level API hooking.
- Direct Memory Interaction: The README details memory layout for game objects (plants, zombies, bullets), emphasizing low-level memory access and modification.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Cheater UI Module Subgraph
    subgraph "Cheater UI Module (PVZCheater)"
        CheaterMain["Main Application"]:::module
        CheaterGUI["GUI Implementation"]:::module
        CheaterGameObjects["Game Objects Handling"]:::module
        CheaterProcessUtil["Process Utilities"]:::module
        CheaterLogger["Logger"]:::module
        CheaterService["Support Logic"]:::module
        External_ImGui["ImGui Library"]:::external
    end

    %% DLL Injection Module Subgraph
    subgraph "DLL Injection Module (pvzdll)"
        DLLMain["DLL Entry & Initializer"]:::module
        DLLService["DLL Service Functions"]:::module
        DLLLogger["Internal Logger"]:::module
        CommonDefinitions["Common Definitions"]:::module
        External_MinHook["MinHook Library"]:::external
    end

    %% Game Target
    GameTarget["Plants vs. Zombies"]:::game

    %% Relationships in Cheater UI Module
    CheaterMain -->|"calls"| CheaterGUI
    CheaterGUI -->|"uses"| External_ImGui
    CheaterMain -->|"initiates"| CheaterService
    CheaterService -->|"manages"| CheaterGameObjects
    CheaterService -->|"manages"| CheaterProcessUtil
    CheaterService -->|"logs"| CheaterLogger

    %% Interaction between Cheater UI Module and DLL Injection Module
    CheaterService -->|"injects_DLL"| DLLMain

    %% Relationships in DLL Injection Module
    DLLMain -->|"calls"| DLLService
    DLLService -->|"hooks_using"| External_MinHook
    DLLService -->|"logs"| DLLLogger
    DLLService -->|"uses_def"| CommonDefinitions
    DLLService -->|"hooks"| GameTarget

    %% Click Events for Cheater UI Module Components
    click CheaterMain "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/main.cpp"
    click CheaterGUI "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/gui.cpp"
    click CheaterGUI "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/gui.h"
    click CheaterGameObjects "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/GameObjects.cpp"
    click CheaterGameObjects "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/GameObjects.h"
    click CheaterProcessUtil "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/ProcessUtil.cpp"
    click CheaterProcessUtil "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/ProcessUtil.h"
    click CheaterLogger "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/logger.cpp"
    click CheaterLogger "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/logger.h"
    click CheaterService "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/PVZService.cpp"
    click CheaterService "https://github.com/f1ze/pvzcheater/blob/main/PVZCheater/PVZService.h"
    click External_ImGui "https://github.com/f1ze/pvzcheater/tree/main/PVZCheater/external/imgui/"

    %% Click Events for DLL Injection Module Components
    click DLLMain "https://github.com/f1ze/pvzcheater/blob/main/pvzdll/dllmain.cpp"
    click DLLService "https://github.com/f1ze/pvzcheater/blob/main/pvzdll/DLLService.cpp"
    click DLLService "https://github.com/f1ze/pvzcheater/blob/main/pvzdll/DLLService.h"
    click DLLLogger "https://github.com/f1ze/pvzcheater/blob/main/pvzdll/logger.cpp"
    click DLLLogger "https://github.com/f1ze/pvzcheater/blob/main/pvzdll/logger.h"
    click CommonDefinitions "https://github.com/f1ze/pvzcheater/blob/main/pvzdll/common.h"
    click External_MinHook "https://github.com/f1ze/pvzcheater/tree/main/pvzdll/external/minhook/"

    %% Styles
    classDef module fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef game fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
