SEN:P-AI

From Rigged Wiki
Jump to: navigation, search
SEN:P-AI logo, chosen cause I thought it was funny. Feel free to suggest something better.

Stats and Events for Nerds: PES - Autism Incarnate (SEN:P-AI) is a program that reaches into PES memory and finds, extracts, and records real-time changes to PES's internal player stats table, all with little to no user intervention required.

The latest release can be found here: https://github.com/Two-Scoops/SEN_P-AI/releases

What is it good for?

The powerful ability to read PES memory brings many potential use cases including but not limited to:

  • Detecting important events such as goals and relaying them to other programs such as Rigdio
  • Automatically recording all player stats for use in Fantasy Sports and other such autism
  • Automatically updating the cup wiki page and creating detailed stats pages
  • Automatically splitting stream recordings into matches (for archiving) and highlights (for hyp material) using recorded event timestamps
  • Driving an IRC/Discord bot which provide live updates to filthy mobile users people stuck at work or with 3rd world internet
  • Providing a better way to view and analyze players and matches when testing tactics or rule changes
  • Driving an IRC rigging bot which can report useful information to live-managers and potentially do automated rigging via commands

It currently works with Pro_Evolution_Soccer_2017

How the fuck do I use this shit?

SEN P-AI Screenshot1.png

Running

Once you download and extract the file, you will have a single file "SEN_P-AI.exe" that should work out of the box with no installation or extra files required.

Every time you run SEN:P-AI it will open the Windows Admin Permissions prompt, this is necessary to get the ability to read the memory of another process, otherwise SEN:P-AI will not open. (I may make this optional in the future)

Recording Stats and Events

  • Once SEN:P-AI is running, it will begin searching the process list for a program with the name "PES2017.exe". It does not matter if you start SEN:P-AI before or after you start PES, in fact you may open and close PES multiple times at any time and SEN:P-AI will just revert back to its process search and continue to work.
SEN P-AI Screenshot2.jpg
  • After SEN:P-AI has found PES2017.exe, it will start searching through its memory for the Team Data Table (TDT). The TDT should be detected by SEN:P-AI as soon as you select two teams and enter the pre-match setup screen, at which point SEN:P-AI will create a new tab with an empty match for the two teams you just selected, as well as every new set of teams you select from then on.
Note: SEN:P-AI makes some assumptions about the TDT's location that have a small/rare chance to be wrong and make the table unfindable. However, the TDT stays in the same place for the entire time PES is running, which means that it only has to be found once, but if it's not you will need to restart PES to get things to work.
SEN P-AI Screenshot3.png
  • From this point on to until PES is closed, SEN:P-AI will be searching for the Player Stats Table (PST) using the player IDs it got from the TDT. The PST appears in memory the instant before the first touch of the match. Once SEN:P-AI detects the PST, it will fill the cells in the table of the previously created empty match with the current stat values (mostly zeros). If there is no empty match (because you selected the same two teams as the previous match) it will create a new one and use that instead.
  • All of the above requires no user interaction with SEN:P-AI but understanding how it behaves should allow you to see if anything has gone wrong.
For the same reasons as the note above there is a small chance that SEN:P-AI will not find the PST on its own. Except unlike the TDT, the PST is being removed and reallocated with every new match, increasing the chances that the search will fail the longer PES is running. Since restarting PES at this point would be a pain in the ass, if you notice that SEN:P-AI does not fill a table with numbers after a match starts then you can press the button labeled Try Harder at the top of the window next to the status message. This will activate a brute force search of PES's entire memory space to find the PST.

Additional note about the Try Harder button: since the stats table isn't in memory until the first touch, clicking the button before then will not work. However, if you're running the same teams multiple times in a row, the brute force search might find a fake copy of the stats table from the previous match that PES keeps around until the next match for some reason. This isn't a huge problem since SEN:P-AI will just stop the fake match and resume searching once PES overwrites the table with unrelated garbage, but if you're running in a streaming environment this will cause false information to be reported to other programs, you'll also have a garbage match sitting in your tabs.

NumbersNUMBERS.gif

Numbers NUMBERS

  • Current Stats: During a match, SEN:P-AI will be continually reading PES memory and interpreting its changes. In the stats table each row will be highlighted with the color of the corresponding player's team (since there's currently no way get the appropriate team colors, I just use the same Home/Away colors that Rigdio uses) recently updated stats will flash to red and then fade back to black. You can select a rectangular range of table cells and copy them into your clipboard using "Crtl+C" formatted for pasting into spreadsheets.
  • Match Events: Important events such as goals and cards will be reported in the text box in the bottom left, which can be resized (vertically). You can use this to see who was actually credited for goals, assists, and cards instead of trying to guess before the name is flashed on screen after the cutscene and without having to go to the match events screen.
  • Benched Players: A typical two 4CC teams playing each other have 46 players total, but only 22-30 will actually play in a match. To hide/show benched players who never stepped on the pitch, you can toggle the Show Benched Players checkbox near the top right. If hidden, SEN:P-AI will automatically make newly subbed players visible during the match. The checkbox applies to all tabs
SEN P-AI Screenshot.png
  • Stat Columns: If there are TOO MANY NUMBERS or NOT ENOUGH NUMBERS or you need DIFFERENT NUMBERS in a DIFFERENT ORDER you can click the Columns button near the top right to open a dialog where you can toggle individual stat visibility, as well as reorder them by dragging the label up and down. The checkboxes on the right in the "Log" column currently serve no purpose as I've disabled the statlog functionality I used in testing. While there are many useful stats in this list, there are even more stats in the table that have yet to be conclusively identified (they're not displayed anywhere in PES). If you wish to see them in this list, you can check the Show Unknown Stats box at the top of the dialog. These settings apply to all tabs. Changes will only be applied if you click OK.
  • The Clock: In the top right of the main window, inside the "Memory Reader" box, there is a real-time UTC clock along with a small QR Code containing the corresponding timestamp. This is intended to be used for synchronizing the stream recording with automated archiving processes. If it bothers you for whatever reason, you can hide it by unchecking the adjacent show time checkbox. The QR timestamp encodes a UTC Unix Timestamp with Numeric mode, ECC set to High, version fixed at 1, and an automatically selected mask pattern, all rendered at 1 pixel per module.
    If a streamer intends to use this feature they can capture a sub-region of the SEN:P-AI window, scale up the QR code (with scale filtering set to "Point" in OBS), and stick it in one or more corners at the very beginning of their stream (maybe even make some kind of test card out of it). Currently there is not yet any automated stream archiving functionality to use this with, but you can still set up as if there was so maybe we can test some shit using your stream.

Matches, Saving, and Loading

SEN P-AI Screenshot4.png
  • Current Match: Whenever SEN:P-AI detects a new match (when either two new teams or a new stats table is detected) it will insert a tab labeled "Current Match" at position 0 of your match tabs. Once the match has ended (you exit the postmatch screen and SEN:P-AI no longer detects the stat table) the tab will be renamed to /[home team]/ vs /[away team]/. You can press the X on any tab except the one labeled "Current Match" to close it.
  • Unsaved Indicator: Both during a match and after it has ended, a * will appear before the tab name to indicate that it is unsaved in its current state. If you close a tab that starts with * or close SEN:P-AI with any of these tabs, the collected stat and event data for that match will be lost forever.
  • Saving: To save this data into a ".sen" file where it can be reloaded, click the Save or Save as button near the top left of the window and the match in the currently selected tab will be saved and the * will disappear from the tab name. The Save as button will always open a file save dialog for selecting the location and name of the file, while the Save button will only open the file dialog if there is not already a filename stored for this match. Invalid filenames will result in unsaved files.
  • Loading: The Open button can be used to load one or more saved matches to be viewed in the SEN:P-AI window. Once you have selected your file(s) and accepted the dialog, SEN:P-AI will load each match and add a tab for it. The tab text will be set to the name of the file (without any of the file path) and you can use any of the features listed above with it.

Autosaving and other Settings

SEN P-AI Screenshot5.jpg

Near the top of the window, to the far right is the Settings button, which will open the settings dialog. Changes to the settings will only be applied if you click OK.

  • Event Log File: At the top of the dialog is the name and location of the Event Log File. This is where SEN:P-AI records important match events whenever they occur, encoded as JSON.
  • Autosave Matches: Next are the autosave settings. You can choose to autosave At Match End and/or Every X seconds (if you're worried everything is going to crash and burn). In either case, the "(autosave) As" text box below specifies the name and location of the autosaved file (if it doesn't end in ".sen" that will be fixed when the file is saved). Unfortunately, invalid filenames/paths are only silent errors right now, so check to see if the file actually saved to verify that the path is correct.
  • Filename Format: Anywhere in the filename/path you can insert %HOME or %AWAY and it will be replaced with the name of the corresponding team (without slashes or other URI-incompatible characters). You can also insert the time the match was created using the syntax for the strftime function. This is also works for the log file.
  • Match Update Interval: The final option is the Match Update Interval which is how often SEN:P-AI pulls data from PES memory and processes it. Lower values mean higher stat/event recording accuracy while higher values mean less CPU usage. I feel that 100ms (10 times per second) is a good value for keeping CPU reasonable without sacrificing too much accuracy.

Using with Rigdio

(Work In Progress)

Is it Rigged?

No

Despite its powerful memory reading capabilities, SEN:P-AI has absolutely no way to rig the game. I do not wish to write such a program.
The fact that anybody would willingly just grant admin privileges to an unsigned binary program made by some guy on 4chan displays a level of trust I do not wish to betray, especially that of the people in charge here. That includes both user security AND not rigging PES.

The one and only single line of code in the entire program that you need to read to know that SEN:P-AI is not fucking with PES is at line 127 of src/StatTableReader.cpp, which is the only file in the program that uses Windows headers:

processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,pesID);

Cross-reference with the documentation for OpenProcess and the list of access rights and you can figure out what it does:

  • PROCESS_QUERY_INFORMATION gives us access to PES's memory map and exit code (to see if it's closed)
  • PROCESS_VM_READ which allows the program to actually read PES's memory through ReadProcessMemory, but not write to it.
  • FALSE telling Windows not to give this same access to child processes (there aren't any, but whatever)
  • and pesID which is just the variable where I stored the process ID of the process named "PES2017.exe"

The other WinAPI functions in that file are used only to do what the above function gave us access to.

Of course, there's always the possibility that the 4CC streamer could use a program compiled from different code and use that to rig the game. Ultimately, the whole concept of an unrigged 4chan Cup relies on trusting the streamer and other people in charge. In reality there have always been less advanced ways to rig the game. Up to this point every viewer of the cup has just had to trust that the streamer wasn't secretly rigging the game and nothing about this has changed that.

Unless there is a compelling, acceptable, and 4CCC-approved reason to do so, I actively refuse to write any program that modifies PES memory in any way because:

  1. It would make it much harder to verify that the code I've written is rig-free (as you could see above).
  2. I absolutely do not want to be responsible for crashing the game if there's a bug in my code.

No amount of love or disgust I could have for any team is going to compel me to rig it for/against them and violate these principles.

Development Feedback

The actual latest release can be found here: https://drive.google.com/open?id=0B0TBhP8367nfV01YN1FsLU5kcms
You can browse the source code and report bugs here: https://github.com/Two-Scoops/SEN_P-AI

You can also contact me (User:Two_Scoops) wherever if you'd like to suggest something or report a bug and I'll add it to my continually growing list of things I might do.
If SEN:P-AI crashes, you'll need to send me the debug log (SEN_P-AI_debug.log) so I can diagnose the error. It gets overwritten every time you start SEN:P-AI so be sure to save/rename it before restarting the program.

See Also