Saved Game Structure

Discuss all aspects of editing the data and databases in EHM here. Have a question about the EHM Editor, EHM Assistant, editing the .cfg files, hex editing the .dat or .db files? Want to tweak the EHM exe file to change league rules/structure, start date etc? This is the place!
Forum rules
This is the forum to discuss all aspects of editing the EHM data and tweaking the game.

Have a bug or feature request for the EHM Editor? Post them in the EHM Editor thread. Please start a new thread or post in another thread if you have a question about how to use the EHM Editor.

Given the large number of questions on similar topics, we ask that you start a new thread for a new question unless you can locate a similar question in an existing thread. This will hopefully ensure that similar questions do not get buried in large threads.

Useful links: EHM 1 Assistant (Download) | EHM 1 Editor (Download) | EHM 1 Editor Tutorials | Editing Rules & Structures Guide | Converting EHM 2004 / 2005 DBs to EHM 1 | Converting an EHM 2007 DB to EHM 1 | Extra_config.cfg | Import_config.cfg | Player Roles
User avatar
YZG
Second Line
Posts: 682
Joined: Mon Aug 16, 2010 11:17 pm
Custom Rank: DHM Head Researcher
Location: Canada

Re: Saved Game Structure

Post by YZG »

archibalduk wrote:Wow, nice! $1.1bn a year is very generous! :D
Yeah, and I love how he still feels he deserves to be paid more :-D

Good job gentlemen, keep it up. I look at your hex screenshots and don't get anything, just managing to get some sense out of this is brilliant. :thup:
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: Saved Game Structure

Post by archibalduk »

I was going to upload the Saved Game Explorer last night, but when I built the exe, it didn't quite work correctly (it works fine in my compiler). I'll find some time in the next 2 weeks or so to try and get that bit to work.
YZG wrote:
archibalduk wrote:Wow, nice! $1.1bn a year is very generous! :D
Yeah, and I love how he still feels he deserves to be paid more :-D

Good job gentlemen, keep it up. I look at your hex screenshots and don't get anything, just managing to get some sense out of this is brilliant. :thup:
I'm sure Laz will agree with me when I say: Thanks for your kind words. :)
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: Saved Game Structure

Post by archibalduk »

I had a request in the C++ Programming Thread to post some more info about the saved game structure. Here's what I've garnered so far:

The Saved Game File
The .sav file is simply a lot of files joined together. It is very easy to split up a .sav file into its constituent sub-files by using the index located at the top of the .sav file.

* The first 8 bytes in the .sav file can be skipped. My guess is that it might relate to version-checking (e.g. to check what version of EHM the game was created or last saved with).
* The following 4 bytes indicate how many sub-files are stored (the number of sub-files varies by saved game depending on what is going on in-game at the time and how many leagues you have loaded on Enhanced/Selected).
* There are then index entries for each sub-file (the number of entries is indicated by the 2 byte number mentioned in the point above). Each entry is 268 bytes long and is structured like this:

Code: Select all

int _pos_start; // This first 4 bytes indicates at what offset in the file the sub-file begins
int _length; // This second 4 bytes tells you how many bytes long the sub-file is
char _name[260]; // The final 260 bytes is a character array with the name of the sub-file - e.g. players.dat
* By using the data in the index entries, you can extract the sub-files. For example, if there is any entry for staff.dat and the entry indicates that it begins at offset 0000 1001 and it is 4 bytes long, you can extract the data from the .sav file from offsets 0000 1001 to 0000 1004 inclusive and save it as staff.dat.


.TMP File Structures
Some of the sub-files are .tmp files whereas others are .dat files. I haven't taken a look at many of the .tmp files so far, but I have figured out the size of each record in some of these files:

Code: Select all

player_stats_hist.tmp = 166 bytes per record
staff_history_tmp = 52 bytes per record

.DAT File Structures
It looks like the structures of the .dat sub-files are very similar to the structures of the .dat files used in the database. Some look like they have additional fields here and there, though.

Here are the size per record of the .dat files I've looked at so far:

Code: Select all

club.dat = 733 bytes per record
club_comp.dat = 219 bytes per record
names.dat = 60 bytes per record
player.dat = 73 bytes per record
staff.dat = 116 bytes per record
staff_comp_history = 58 bytes per record
staff_history = 37 bytes per record
NingDynasty
Junior League
Posts: 27
Joined: Wed Feb 08, 2012 10:36 pm

Re: 1974 db - Mario Lemieux as an 8 year old

Post by NingDynasty »

archibalduk wrote:The way I see it, there are potentially two solutions:

1) Have an EHM Updater style of spreadsheet which you can use to set players' heights, weights, attributes, etc.
2) Have a spreadsheet which states year-by-year what heights and weights to assign a player. The tool would detect what year it is in-game and apply the correct heights and weights for that year. Essentially, you'd be able to set how a player's height and weight develops over the years.

#1 is more feasible than #2, but I don't see #2 being totally out of the question. If I can find where in the saved game the current date is stored, it'd be very possible... :-k

I remember a long time back there was something you were recommending that when we first start a game with your DB that we use the Saved Game Editor to change certain things on starting up the game (was it reputation or something?). I can't remember exactly what it was (and I don't particularly want to read back through all 880+ posts in this thread!!) - can you remember what it was? The reason I ask is that it'd be neat to write some sort of saved game patch that could make all of these changes when you first start your game.

Another interesting thing is that Lazion has figured out here how to potentially modify contract details for players - for example by adding/removing NTCs and NHL release clauses.
Just did a quick look around for the location of the game date. If it's in the standard SI Date format there are 8 references to August 30th 2006 (first day) when using an absolutely minimal game file. Looks like 1 was in the staff.dat (highly unlikely), 6 were in transfer_manager.dat and the final one was in transfer_rules.dat. Unforunately when I tried changing all of these they seemed to have no affect whatsoever. I also tried searching for a standard dos date 1E 35 for august 30th 2006 but of the 16 found none had any affect when changed. Standard m/dd/yyyy and dd/m/yyyy using short 2 byte types also didn't return any hits. What can you say about the date info that you found for the change start date patch? Was it using the SI_Date format or something different?
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: Saved Game Structure

Post by archibalduk »

I was banking on being able to do exactly what you did - searching for an SI DATE corresponding to the in-game date... :-k

Finding the start date for the CSD Patch was very different. I was searching for references to 2006 in the memory before the game loads the database or a saved game. I was essentially searching within the exe whilst it was running in the RAM. I didn't know of the DB format at the time of writing the patch - I was looking simply for any integers or shorts.

P.s. I've moved your post here so we can keep the saved game discussion in one place. :)
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: 1974 db - Mario Lemieux as an 8 year old

Post by archibalduk »

I've been making quite a lot of progress with my Saved Game Tool. I'm able to extract a saved game into its constituent sub-files and then recompile it back into the saved game. As the staff.dat and club.dat sub-files are the same structure as the staff.dat and club.dat DB files, I'm able to extract the sub-files and then make contract changes to them using the EHM Updater - and then recompiling them back into the saved game file. Just as a quick test, I extracted a saved game, used the Updater to move Sidney Crosby from the Pens to Manchester Phoenix, and then recompiled the saved game.

The saved game loads up fine and sure enough Sidney Crosby is on Manchester's roster. However, he still comes up on Pittsburgh's Finances/Contract screen rather than Manchester's (and it seems Manchester isn't taking any hit from his $7m salary). His game log has been wiped clear but the stats he acquired over the first 30 games with the Pens now appear in his career history as having been achieved with Manchester - but only the stats he's acquired since being on Manchester's roster are actually contributing to his EPL stats.

I'm sure the reason for Crosby still appearing on Pittsburgh's payroll is because contract.dat needs to be updated (Laz posted almost all of the structure here). I'm not sure where the player stats are stored yet - this is one of the things I'm most interested in because I want to be able to export player stats en masse to help with evaluating roster re-rating, etc.
NingDynasty wrote:Just did a quick look around for the location of the game date. If it's in the standard SI Date format there are 8 references to August 30th 2006 (first day) when using an absolutely minimal game file. Looks like 1 was in the staff.dat (highly unlikely), 6 were in transfer_manager.dat and the final one was in transfer_rules.dat. Unforunately when I tried changing all of these they seemed to have no affect whatsoever. I also tried searching for a standard dos date 1E 35 for august 30th 2006 but of the 16 found none had any affect when changed. Standard m/dd/yyyy and dd/m/yyyy using short 2 byte types also didn't return any hits. What can you say about the date info that you found for the change start date patch? Was it using the SI_Date format or something different?
Did you take into account byte-swapping when you did your search? For example 2006 in hex is 07 D6 - however, because the bytes are swapped, it is stored in the dat files as D6 07. Another example is that 100,000 as an int in hex is 00 01 86 A0 but because the bytes are swapped in the dat files, this appears as A0 86 01 00.

30 August is the 242nd day of a standard year. Because day 1 = 0 in EHM, the SI DATE day number for 30 August is 241 (or F1 in hex). 2006 isn't a leap year and so the leap_year bool is 0 and, as mentioned the hex for 2006 is 07D6. Taking into the account the aforementioned byte-swapping, the SI DATE for 30 Aug 2006 should be: F1 00 00 D6 07.

I've been trying to the find the date in the saved game, but can't find it anywhere. It's got to be somewhere, though! Like you say, maybe it is stored in another format. I would have thought that in addition to storing the date, it has to store whether it is AM or PM because the game always resume at the correct part of the day. I can't see any sub-file names that really stand out as possible locations for the date - except perhaps general.dat?
User avatar
nino33
Mr. Goalie
Posts: 6088
Joined: Sat Aug 07, 2010 3:37 am
Custom Rank: Retro Rosters Specialist
Favourite Team: 1970s hockey

Re: Saved Game Structure

Post by nino33 »

archibalduk wrote:I've been making quite a lot of progress with my Saved Game Tool.
Good to hear! 8-)
NingDynasty
Junior League
Posts: 27
Joined: Wed Feb 08, 2012 10:36 pm

Re: Saved Game Structure

Post by NingDynasty »

Is it just dates that are byte swapped because none of the other data seems swapped at all when comparing it to the saved game editor... :-?
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: Saved Game Structure

Post by archibalduk »

NingDynasty wrote:Is it just dates that are byte swapped because none of the other data seems swapped at all when comparing it to the saved game editor... :-?
All data in all of the files is byte-swapped. Its because Windows (I think) is little endian. Its just the way bytes are stored in Windows. Its the same with data in the RAM. This is why editing FHM is a bit of a pain - it is big endian (is not byte swapped) and so have to swap around the bytes to make it little endian. If you look for endianess on Wikipedia, it might explain better than i can.
NingDynasty
Junior League
Posts: 27
Joined: Wed Feb 08, 2012 10:36 pm

Re: Saved Game Structure

Post by NingDynasty »

Looks like my hex editor has little endian as the default so when the inspector is showing me potential values they are calculated in little endian.

Image
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: Saved Game Structure

Post by archibalduk »

In which case you can ignore my last couple of posts! :-D

I've never tried using the endian swap function before because I'm so used to seeing it as big endian. But perhaps it's easier to use the little endian view in the long run. The only thing I don't understand is how it swaps the bytes without knowing the structure of the data - is it just assuming that the file is full of ints? In which case the bytes won't be swapped correctly - unless there is something I've misunderstood. :-k
NingDynasty
Junior League
Posts: 27
Joined: Wed Feb 08, 2012 10:36 pm

Re: Saved Game Structure

Post by NingDynasty »

The bytes don't swap, the values do. The file doesn't change at all it's just interpreted differently. For instance D6 07 = 2006 (signed short) in little endian, however in big endian D6 07 = -10745 (signed short). The only time you need to swap bytes is if you want to change a little endian to a big endian or vise versa... Say if we wanted to convert the EHM data base to FHM 14 we'd swap bytes (of course that wouldn't work because it would have the wrong structure). As per your post above little endian D6 07 = big endian 07 D6 = 2006 signed short.
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: Saved Game Structure

Post by archibalduk »

NingDynasty wrote:The bytes don't swap, the values do.
Ah I see! That makes a lot more sense!! :thup:
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: Saved Game Structure

Post by archibalduk »

I've figured out bits and pieces of some of the sub-file structures. Once I've tidied things up a bit more, I'll post the details here. I've been messing around with the IIHF rankings and have figured out how to edit them (I haven't yet checked to see if it'll alter the World Championship teams). It looks like it's possible to change a league from Not Selected to Standard (I haven't yet tried Enhanced) mid-game. The game comes up with some errors when you first load, but then the scores and stats seem to start appearing in game. I haven't given it a full test yet though.

I've also found where the host nations data is stored. I haven't tried editing the hosts yet, but I'm going to see if I can edit them. If it works, I'll be able write a patch that sets the correct hosts for the different international tournaments. However, my first aim is to write a regen fix and a height/weight editor.

Also it's possible to change the team the user is coaching. I tried changing myself to a French Magnus team and an ECAC team. It worked, but I didn't have a schedule or a league table! Also, I couldn't renew players' contracts (it comes up with Approach to Transfer and Approach to Loan) and the Board Confidence screen flickers closed very quickly. It's kind of like being in a limbo - on paper you're the coach, but you can't quite do anything! :D

Image

Image
User avatar
archibalduk
TBL Admin Team
Posts: 20372
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: Saved Game Structure

Post by archibalduk »

In working on the Regen Patch I've been taking a look at the player attributes. My hope was to create a set of profiles that could be randomly assigned to regens so that they would get realistic physical attributes. The profiles would be preset sets of physical attributes which could be randomly varied realistically (i.e. so you don't end up with players having 20 Speed and 1 Acceleration). However, I've run into a problem in that, as has been mentioned elsewhere, the attributes in the saved game are stored in a weird format. Presumably this is so that the players can incrementally improve whilst keeping the same attribute number (kind of like having say a 10 Wristshot but progressively increasing to 10.1, 10.2, etc until they reach 11). Panfork figured out a lot here but I need to figure out the exact formula if I'm to be able to correctly alter attributes. I think in the meantime I'll just concentrate on modifying the player PAs, heights and weights.

On another note, I've figured out enough of the schedule data to modify (and possibly add) individual games. Unfortunately the changes don't "stick" to the next season and so it seems there's little point in me pursuing that. It's a shame because I was able to introduce an 83 game NHL season (thereby giving the possibility to update schedules for leagues that have changed dramatically - but there's no point if the schedules revert to the default every season).
NingDynasty
Junior League
Posts: 27
Joined: Wed Feb 08, 2012 10:36 pm

Re: Saved Game Structure

Post by NingDynasty »

I'd rather be able to run the patch july 1st of each year and get real schedules than not... Perhaps you can set an in game news reminder set to a random player to notify that you should rerun the patch.

Since you are doing all the work I'd intended at least I'll see if there is a formula I can come up with to calculate the attribute ratings.
Post Reply