| # Dynamic trace for the loading-tip cycle function |
|
|
| The static RE pass narrowed the candidate function to a small set of |
| VMAs in `0x141174xxx` (loading-screen construction) and a few call |
| targets. To confirm which one is the per-frame tip cycler, we use |
| hardware breakpoints to observe the running `eu4.exe`. |
|
|
| ## Why |
|
|
| Manual RE of a 38 MB binary without symbols is slow. The cycle |
| function is *not* the `0x141174F50` setup function (which runs only |
| once). The per-frame update is somewhere else, calling the same |
| `findChildByName` / `setText` virtuals, but with a Timer. Hardware |
| breakpoints on the candidates and a hit counter tell us which one |
| fires most often during the loading screen. |
|
|
| ## Tool |
|
|
| `bin/trace_tip_cycle.exe` (built with `x86_64-w64-mingw32-gcc`, |
| MinGW-w64 GCC 15.2.0). It: |
|
|
| 1. Finds the `eu4.exe` PID. |
| 2. Opens the main thread. |
| 3. Sets `DR0`–`DR3` hardware-execute breakpoints on the first 4 |
| candidate VMAs. |
| 4. Calls `DebugActiveProcess` to attach as a debugger. |
| 5. Loops on `WaitForDebugEvent`, logs every `EXCEPTION_SINGLE_STEP` |
| whose `ExceptionAddress` matches a candidate, and re-arms all 4 |
| breakpoints (Windows clears them on exception). |
| 6. Exits after 10000 hits or 5 minutes, whichever comes first. |
|
|
| The hit log is written to `trace_log.txt` next to the .exe. |
|
|
| ## Candidates currently traced |
|
|
| | VMA | Source | |
| |----------------|------------------------------------------------------------------------| |
| | `0x141174F50` | `load_screen_setup` (static RE confirmed, runs once) | |
| | `0x141174840` | `status_updater` (spinner — confirmed fires every frame) | |
| | `0x141175110` | `status_lookup` (helper, may or may not be per-frame) | |
| | `0x14117AD80` | call target — likely the GUI `addChild` path | |
| | (12 more) | See `src/trace_tip_cycle.cpp` for the full list | |
|
|
| Only the first 4 fit in the 4 HW debug registers. If the cycle |
| function is one of the others, expand the candidate list and |
| re-build. |
|
|
| ## How to run |
|
|
| 1. **Launch EU4** through Steam. (Or directly: |
| `"C:\Program Files (x86)\Steam\steamapps\common\Europa Universalis IV\eu4.exe"`.) |
| 2. **Trigger a loading screen** — start a new campaign, or load a save. |
| The loading screen must be on-screen for the tip cycler to run. |
| 3. In a second shell, run the tracer: |
| ```bash |
| cd tools/loading_tip_patcher |
| ./bin/trace_tip_cycle.exe |
| ``` |
| 4. **Wait 30–120 s** for the loading to finish and the tracer to |
| record enough hits. |
| 5. Open `trace_log.txt`. The VMA with the highest hit count is the |
| per-frame tip cycle function. Compare with the candidate list |
| to identify the exact symbol we should patch. |
|
|
| ## Expected output (illustrative) |
|
|
| ``` |
| [trace] target PID 12345, main thread TID 12350 |
| [trace] HW breakpoints set on first 4 candidates |
| [trace] Waiting for exceptions. Run the loading screen NOW. |
| [hit] #1 vma=0x141174840 count=1 prev_rip=0x141174812 +dt=12us |
| [hit] #1 vma=0x141174840 count=2 prev_rip=0x141174812 +dt=16543us |
| [hit] #1 vma=0x141174840 count=3 prev_rip=0x141174812 +dt=16601us |
| [hit] #0 vma=0x141174f50 count=1 prev_rip=0x141174e9f +dt=8us |
| [hit] #1 vma=0x141174840 count=4 prev_rip=0x141174812 +dt=16572us |
| ... |
| ``` |
|
|
| The expected pattern: `0x141174840` (status updater / spinner) |
| fires ~30 times per second while the loading screen is up. If a |
| *new* VMA fires every few seconds (~8 s interval), that is the |
| tip cycle function. |
|
|
| ## After the trace |
|
|
| 1. Identify the new VMA from the log. |
| 2. Add it to the static-RE notes in `RE_notes.md`. |
| 3. Add a `candidates[]` entry in `src/trace_tip_cycle.cpp` and |
| `src/main.cpp` (with a TODO marker for the actual byte-pattern |
| patch). |
| 4. Re-run with the new candidate list if necessary. |
|
|
| ## Caveats |
|
|
| - `DebugActiveProcess` will **freeze** the target until the trace |
| loop is running. If you set the breakpoint and then close the |
| tracer, the target will be left in a frozen state. Kill `eu4.exe` |
| with Task Manager to recover. |
| - x64 Windows only allows **4** HW execute breakpoints. The 5th and |
| later candidates in the list will not fire. If the cycle function |
| isn't in the first 4, you must narrow the list and re-run. |
| - The tracer is **not** stealthy — Paradox's anti-cheat (if it |
| runs in `eu4.exe`) will likely detect `DebugActiveProcess` on |
| the same process. Don't use this on an ironman / multiplayer |
| session. |
|
|