Export player Values live in text format

Tetahydril

Terrarian
Hello!
I am trying to make a mod for the community to export certain player values (especially health and mana stats) live from ingame values in order to use them in outside projects (for example an LED Health or mana bar).
I have already tried different methods, especially Tesseract OCR in order to read health values directly by looking at the numbers displayed by the health bar and converting them to external values, making it cross-compatible with other games that display numbers with a health bar. I also tried to read the color values of the health bar, but both turned out to be failures since

1. the OCR had a high rate of failure to properly read the characters and produced a lot of lag
2. Some mods and the life fruit upgrades change the color of the health bar which produced nonsense values. (I could hardcode the color values but that doesn't really solve the problem in hindsight)

Right now I am looking into .plr files to see if they contain only the static health and mana values or the usable temporary health values.

But heres the problem: I tried to open player files with notepad++ and tried every programming language installed including C but I couldn't gather any usable data from there. Also sadly, I tried using online and offline character editors but most don't display current health and are not compadible with modded items.

Therefore I ask:

1) Is the temporary player health and mana stored in the player files (if so, in which? the .bak files; the .tplr files or the .plr files?)
1.5) Is there a reliable and fast way to convert those files into a readable text file?
2) is there a way to generate a temporary text file containing the Health and mana data of the character in real time?
3) Can somebody give me Ideas that I have missed / Is there another way?

I would really appreciate any help and thank you for taking your time!
 
Temporary health is not stored in player files in the way you want it - think how unfeasible it would be to be writing/reading to some files on disk every game tick.
I think your best bet is with the text-recognition approach - there should be lots of languages that have libraries you can use that are reasonable efficient. I know python seems to be a current favorite for that sort of thing, and is good at controlling LEDs etc too - maybe that's somewhere to look?
 
Temporary health is not stored in player files in the way you want it - think how unfeasible it would be to be writing/reading to some files on disk every game tick.
I think your best bet is with the text-recognition approach - there should be lots of languages that have libraries you can use that are reasonable efficient. I know python seems to be a current favorite for that sort of thing, and is good at controlling LEDs etc too - maybe that's somewhere to look?

Hmm it would be the most convenient, though I have a lot of problems with teaching tesseract to actually read some of these numbers since the text format is pretty unique and is mod dependand; do you know if there is some kind of repository or folder for all the fonts terraria and it's mods uses? That would be of great help!
 
So, you'd like to somehow expose the players health in a way that can be read by other processes? How about using some form of IPC, like named pipes? You could make a pretty simple mod to just take a bunch of player stats and dump em into a pipe every so often.

you know if there is some kind of repository or folder for all the fonts terraria and it's mods uses? That would be of great help!
Terraria uses a font called Andy.
 
Last edited:
So, you'd like to somehow expose the players health in a way that can be read by other processes? How about using some form of IPC, like named pipes? You could make a pretty simple mod to just take a bunch of player stats and dump em into a pipe every so often.


Terraria uses a font called Andy.
Thanks for the tip! I'll look into it!
 
So, you'd like to somehow expose the players health in a way that can be read by other processes? How about using some form of IPC, like named pipes? You could make a pretty simple mod to just take a bunch of player stats and dump em into a pipe every so often.


Terraria uses a font called Andy.

Thanks for the tip! I'll look into it!
Andy MT Bold to be specific.
IMO it's a much cleaner solution if it works without tModloader, as then it can also be applied to other games.
As with any recognition AI, you'll need some training data; images containing text/numbers in the andy font that you generate, with the text within as the filename. Train the AI on that data, then it should be able to read the ingame text.
 
Andy MT Bold to be specific.
IMO it's a much cleaner solution if it works without tModloader, as then it can also be applied to other games.
As with any recognition AI, you'll need some training data; images containing text/numbers in the andy font that you generate, with the text within as the filename. Train the AI on that data, then it should be able to read the ingame text.

You are right, cross-plattform is nice. I wrote a rudimentary Python program on how it could work; and it seems to me that the displayed health numbers don't look too bad. Tesseract is even giving a constant output, but here is where another problem starts.

It isn't putting out any usefull information, it's more like gibberish of what it has interpreted, and I can't seem to solve that problem.
I have included a demonstration video and the .py file, any help or suggestions would be greatly appreciated because I'm very new to programming (which is also why I can't really do what DRKV said since I never actually made a mod in terraria and have even less knowledge about constructing named pipes and such ;()
 

Attachments

  • Test Program + Video.zip
    13.9 MB · Views: 78
Although the program is still mostly unstable, I got it to spit out some usable values (in Percent; see the .txt). The Program itself has some bugs, for example it will crash at health values lower than 174 (?) and will occasionally throw exception errors. I beleive that I have come to a point where I can't really change much without modding the font of terraria into something more readable and making the Health display non transparent so that the OCR has an easyer time. I will still try to look into what DRKV said since the method I use now is very resource intensive, but other than that the program should work on other games too that have 2 comparable health values (Maxhealth and Playerhealth).
 

Attachments

  • Test.2.Python.zip
    1.5 KB · Views: 70
  • Healthstats.txt
    2.1 KB · Views: 78
Does anyone know the commands to request health and mana values? I can't see them in the tModloader Github, I only find "Modify nurse Heal" in player Hooks
 
Does anyone know the commands to request health and mana values? I can't see them in the tModloader Github, I only find "Modify nurse Heal" in player Hooks
This part of the code is part of vanilla terraria, so you won't find it on github. (For legal reasons.) I'd say the best way to look at these, is by decompiling the tModLoader executable with a tool such as dnSpy.
In this particular case, you should look at the various fields in Terraria.Player, namely, Terraria.Player.statLife, Terraria.Player.statLifeMax2, Terraria.Player.statMana and Terraria.Player.statManaMax2. You can get the Player instance that belongs to the currently running client from the Main.LocalPlayer static property, or Main.player[Main.myPlayer] , which is the same thing.
 
Back
Top Bottom