SHO GTR2 Memory Operations Tool

From Simwiki.net
Jump to navigation Jump to search

What is SHO GTR2 Memory Operations Tool?

  • A Windows app that reads GTR2 memory, not just shared memory, in the hopes of being able to affect game operation in ways not possible otherwise
  • Made in Visual Studio with C#
  • Credit to T-Shirt's python memory operations scripts shared on the Simwiki Discord
  • Credit to The Iron Wolf for his open source CCGEP Monitor from which I was able to extract and port over the shared memory C# logic
  • My personal goal is to get to a place where I can create an algorithm that modifies AI weight penalties, or other AI difficulty values, to accomplish my Automatic AI - Performance-based Dynamic AI Scaling ideas.

Early Prototype Demonstration Video:

Status

  • Work In Progress
  • Early exploratory and proof of concept experiments
  • Successfully reading memory and values like grid, vehicles, driver names, weight penalties, etc.(Feb 2026)
  • Successfully writing memory for values like weight penalties - just a proof of concept bit of code (Feb 2026)
  • Moved from a Windows Console App to a Windows WPF GUI App and making good progress with reading and displaying GTR2 shared memory

Download

Resources

  • Gtr2MemGridVehicleSlot-memory-mapping.xlsx [Spreadsheet] - GTR2 Grid Vehicle Slots memory map
    • Columns: Name, Type, Type Size, Field Length, Field Size, Calculated Offset, Expected Offset Start, Expected Offset End, Comments

Release Notes

Coming when I have real releases

Plans

Short Term:

  • Get comfortable with Visual Studio and C# Windows Console Apps and Windows WPF GUI Apps
  • Learn how to read and write another process's memory

Mid Term:

  • Move from Windows Console App to Windows WPF GUI App
  • Port CCGEP Monitor's shared memory C# logic
  • Compare CCGEP Monitor's logic with T-Shirt's python scripts. See if there's any valuable differences.
  • Review Cheat Engine for its use in exploring GTR2 memory and enabling ways to discover where values are in memory

Long Term:

  • Dynamic AI Adjustment Algorithm
    • Based on Automatic AI - Performance-based Dynamic AI Scaling
    • AI adjustment might adjust AI Driver Strength (AI Difficulty), Race Ability, CorneringAdd, AIW Best/Mid/WorstAdjust, PLR AI Brake Power / Brake Grip / Corner Grip, and/or weight penalty
      • I'm leaning towards just relying on Weight Penalty since it's officially supported by the engine, itself, and because it's the way BOP Balance of Power is done in real life which is effectively what I want to do: BOP AI drivers around the Player.

Development Notes

  • 2026-02-27 and going forward
    • See git logs on GitHub or GitLab for development notes going forward. I just didn't want to duplicate effort posting in multiple places.
  • 2026-02-26
    • Learned how to make a Windows WPF GUI App with standard file menus and a tabbed interface. This puts me in a good spot to port the console app code over and begin an app that will be more interactive than a console app could be.
  • 2026-02-25
    • Improving the data structure list of values in memory so that in the future reading memory will be more dynamic rather than static kind of reads
    • Each day I wrap my head around the code and memory being read better, it helps to refactor the code to be more accurate about what I'm doing with regards to naming of constants, variables, functions, and classes.
      • Given that this code started from sketchy AI generated code, there's some code that is causing confusion. Anyway, much cleaner and makes more sense now.
      • One improvement I made over the original Python code is that the logic to find the base memory region, where all the data we want lives, is found more dynamically. That is, I loop through all the GTR2.EXE virtual memory regions and match signatures within those memory regions: If all the signature match in a single region, that is the base memory region. Then, handy memory offsets allow me to find the exact sub-regions that contain different categories of values.
    • Started a local git repo. Will put it up on github/gitlab at some point.
  • 2026-02-24
    • Started building out helper classes to contain memory regions and the fields within those regions
      • For example, the Grid Data region contains slots and each slot contains fields like slot id, pit group id, driver name, weight penalty, and many more
      • This will help to write later code that just consumes all the available fields and displays them all in a nice GUI. That will help in visually identifying and working with the memory data.
  • 2026-02-23
    • Now reading slot id, pit group id, driver name, weight penalty, car file path
    • Developing helpers functions to modularize reading memory (strings vs floats vs ints, etc.)
      • Higher level functions that find named values in memory
      • Higher level functions call lower level functions that specific value types in memory (strings, floats, ints, etc.)
      • Eg. FindSlowWeightPenalty() calls FindSlotFloatValue() calls ReadMemoryFloat() calls ReadProcessMemory()
      • The idea is to gradually build out helpers, utility functions, and high level functions that can then be used by higher level algorithms and presented in some kind of UI rather than just the console app it is now
    • To-dos:
      • Helpers for memory writing. Already have WriteFloat().
  • 2026-02-22
    • Console app
    • Working proof of concept code to connect to GTR2.EXE process, find grid data region of memory, find weight penalties, write weight penalties and read them back to prove writing worked
    • Used AI to help me convert static memory offsets into logic that dynamically finds the right region of memory based on 'signatures' of expected memory bytes data
    • All based on T-Shirt's python mem ops scripts shared on the Simwiki Discord
      • He has mapped out many named values in memory and tables of values and memory offsets are included in the scripts

Scratchpad

==
260226

Windows Console App vs GUI App:
- How far can I go with just the console app?
- I can build out functions to read the memory in bulk, structure things nicely for future display, etc.
- But it's not really serving the goal until I move to a GUI app
- So, probably time to move to a GUI app

==

Automatic AI Workpad

Todo

...

Automatic AI Notepad

These notes are generally tested and confirmed true

Lap Counting
- Practice: HUD outlap is Lap 1, HUD flying lap is lap 2; but Garage Timing screen shows 0 for outlap and 1+ for flying lap+
- Qualifying: ~ Same
- Warmup: ~ Same
- Race: ~ Same. Race start: HUD Lap 1 vs Timing Lap 0
- HUD vs Garage Timing Screen: HUD is the lap you are currently on vs Timing is the last completed lap

Shared Memory
- Total Laps
  - Matches Garage Timing screen
  - So because this is not the current lap, it is completed laps
  - When BOP'ing, we BOP off of the latest Total Laps lap (as opposed to something like Total Laps - 1 which is a bug I was doing).
- Session:
  - Loading into a track changes Session to Test Day and then once the grid is populated Session changes to Practice 1/2
    - Could be used as a 'ready' event 
    - I bet the 'ready' nature applies to subsequent prac/qual/warm/race sessions as you progress through them too
    - Maybe not. Session doesn't appear changed if previous session was the same kind.

Program Memory
- Weight Penalty
  - Edits to memory are reflected in realtime in the car's physics
  - This means there's no waiting for adjustments to take effect. Say, you might expect the car would have to go into the pits to get the new weight penalty before it was applied. No worries, weight penalty updates immediately.
  - Observations:
    - 1000kg: +30sec
    - 10000kg: +60sec 
    - 100000kg: glitches into the sky
    ^ Deltas are not precise and should not be used in formulas.
  - Sometimes unrealistically high weight penalties prevent AI from leaving pits (1000kg+) or they glitch in weird ways such spin on the pitch axis or glitch into the sky (10,000kg+)
  - Actual tests for kg/sec vary by a lot so it's good the AAI algo depends on realtime laptimes and not some baked constants in a formula
    - Example:
        48.256 - 31.318 = 16.938
        1000 / 16.938 = 59.0388475616956 kg/sec
        ...or...
        44.377 - 33.274 = 11.103
        1000 / 11.103 =  90.06574799603711 kg/sec

Sessions
- Open Practice: Test Day (Shared Memory), Open Practice (Garage)
- Time Trial: Test Day (Shared Memory), Open Practice (Garage)
- Practice 1 (Race): Practice 1 (Shared Memory), Practice 1 (Garage)
- Practice 2 (Race): Practice 2 (Shared Memory), Practice 2 (Garage)
- Qualifying 1 (Race): Qualifying 1 (Shared Memory), Qualifying 1 (Garage)
- Qualifying 2 (Race): Qualifying 2 (Shared Memory), Qualifying 2 (Garage)
- Warmup (Race): Warmup (Shared Memory), Warmup (Garage)
- Race: Race (Shared Memory), Race (Garage)

Automatic AI Scratchpad

These notes may not be tested or confirmed true