Author Topic: [Project For Developer Section Access] Custom Save Game Location  (Read 2219 times)

0 Members and 1 Guest are viewing this topic.

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9184
    • View Profile
    • http://www.tkc-community.net
[Project For Developer Section Access] Custom Save Game Location
« on: September 25, 2011, 07:03:49 pm »
I don't like when game developers limit your choice of save game location to "no choice at all". So let's change that.

M&B stores its save games in the "My Documents" folder, and like many other people I have that one on a separate disk, which happens to be external. This means that write times can be quite long. With frequent autosaves that becomes a nightmare.

So, there are two reasons to mod-app the save game "feature".
1. To save games where you want them to be saved.
2. To save time.


This is an ongoing project where newbies and others are encouraged to fill in things that are left in the work sequence. Successfully completing unfinished parts of the sequence will qualify you for developer section access. See it as practice, or as a tutorial, where you actually see that you can make use of your skills to do practically anything you want.










Work sequence:

The easiest way to solve this problem is likely to BP the write to file API in Windows (kernel32), but OllyDBG didn't work out for me when I attached it to M&B and as SoftICE doesn't work anymore normal memory editing techniques will have to do.

Play M&B in Windowed mode, or you will find yourself having to abort mid-way as M&B, while unfocused, sometimes covers the screen and hides everything on the desktop.

1. Search for "Autosaving" in Cheat Engine for example.

This message appears right before the save game process starts, and that's where we want to go.


2. We get a couple of alternatives. The lowest one 0FB15178 is usually the one we're looking for. See what accesses it.

We find 475150, let's put an access BP on it.

Then step over (F8 in Cheat Engine) until you hear your HD work (the debugger will stop briefly while the save game is written to file anyway).

3. You will find a call to the save game function (5FDFE0) at 5FE630.

Scroll down to find a reference to %s%s\new_game.sav at 5FE118. The string can be found at 8FA0DC.

A code cave where that string is overwritten by an absolute path will probably not solve the problem as some function will expect two %s later on (%s is a kind of C placeholder for variable text).

4. We got to find the place where the %s information is read and change it (or somewhat worse find the resulting string that gets sent to the write file function). So we need to find where the file is created. The new_game file pops up after the call to 44E010 at 5FE153.

Right before it we can see a parameter being sent to it (5FE14E: push ecx). Ecx contains a memory address that points to the full string, i.e. %s has already been replaced. We can choose to make a code cave here to read a static address with the path of our choice.


5. Write a code cave that does this.

6. Write a trainer that lets you enter the path.


7. The save game process involves three files. (i.e. finding the %s-location once will solve everything in "one hit"). The new save, the recent save, and the backup save.

New_game is created.
Backup is removed.
Recent is made backup.
New_game is made recent.

The paths have to be adjusted for all of those. The one-hit solution would probably have to find the right call to SHGetFolderPathW and disregard the output (i.e. set DriveLetter:\MyPath\ instead of C:\My Documents\ . Hint: Look right after 766D13A8, add 0x4C to ebp (seems to be related to SHGetFolderPathW).  If the same part of the code is used for more purposes a cmp-filter for the integer CSIDL_PERSONAL can be done. The multi-hit solution can target the location at 5B092F: push ecx . Ecx contains the file paths.


M&B Fire and Sword, 1.143
« Last Edit: September 26, 2011, 04:43:50 am by M. O. »
Heckling is an art, and game hacking a science.

sebacod3

  • Cheater Apprentice
  • *
  • Posts: 12
    • View Profile
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #1 on: September 26, 2011, 12:42:15 pm »
this is cool...... :icon_biggrin2
seba

MrMedic

  • MasstKer
  • ********
  • Posts: 8900
  • programmer/dev/software engineer
    • View Profile
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #2 on: September 26, 2011, 01:14:20 pm »
char rampentrabbits[] = "path\\to\\yoursavefile.sav";

detour it

cmp [ecx] with string \My Documents\

yes ?

mov ecx,rampentrabbits;

continue merrily on your way mr processor

done. psuedo code example.


« Last Edit: September 26, 2011, 01:21:02 pm by MrMedic »
EnCoded Message: i3iy9yl8kr2xf3g2Txs3pr6ye3ya7jg5ty2z

https://www.youtube.com/watch?v=62_7-AYfdkQ
you need a paypal account for the private versions.

Website:
http://bit.ly/medic101

Teamspeak 3: 85.236.101.5:10157

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9184
    • View Profile
    • http://www.tkc-community.net
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #3 on: September 26, 2011, 06:43:02 pm »
5/7 is done on a code-level. It won't be posted in public just to give other people a chance to practice/apply for dev section.

Additional work sequences:

8. Change the load folder. (I'm not going to complete this step).


Heckling is an art, and game hacking a science.

MrMedic

  • MasstKer
  • ********
  • Posts: 8900
  • programmer/dev/software engineer
    • View Profile
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #4 on: September 26, 2011, 06:47:20 pm »
5/7 is done on a code-level. It won't be posted in public just to give other people a chance to practice/apply for dev section.

Additional work sequences:

8. Change the load folder. (I'm not going to complete this step).



good luck gents hope you make it in.


EnCoded Message: i3iy9yl8kr2xf3g2Txs3pr6ye3ya7jg5ty2z

https://www.youtube.com/watch?v=62_7-AYfdkQ
you need a paypal account for the private versions.

Website:
http://bit.ly/medic101

Teamspeak 3: 85.236.101.5:10157

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9184
    • View Profile
    • http://www.tkc-community.net
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #5 on: September 26, 2011, 07:00:49 pm »
The easiest solution would be to use symbolic links but they aren't supported in XP, don't know about Vista or 7/8.

Another natural solution is to look for the save game file name in the exe (as it's static), but due to the different locations of the My documents folders (and due to different languages) you need to do some extra work.

Heckling is an art, and game hacking a science.

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9184
    • View Profile
    • http://www.tkc-community.net
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #6 on: September 27, 2011, 05:52:59 pm »
Here's the thing while the forum downloads don't work:

http://www.speed yshare.com/files/30497173/M_B_Save_Path_Changer.rar

I only implemented the most important features to make it work, I reduced the save game times from about 10 seconds to 0.5. It's still a public project though, so if you want to implement the rest of them in this post I'll continue to give you pointers.



Heckling is an art, and game hacking a science.

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9184
    • View Profile
    • http://www.tkc-community.net
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #7 on: September 28, 2011, 06:27:44 am »
Oh yea, I should also mention that the save directory must probably exist beforehand.

Format:
X:\Your_Choice\Mount&Blade With Fire and Sword\Savegames\Ogniem i Mieczema

The path always ends with the default internal structure, so all folders must exist up till Ogniem.

You don't type

\Mount&Blade With Fire and Sword\Savegames\Ogniem i Mieczema

in the app, it's added automatically.

Heckling is an art, and game hacking a science.

WiFFo

  • Poptart
  • *
  • Posts: 8
    • View Profile
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #8 on: July 06, 2015, 02:34:51 am »
 :icon_biggrin2

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9184
    • View Profile
    • http://www.tkc-community.net
Re: [Project For Developer Section Access] Custom Save Game Location
« Reply #9 on: August 30, 2015, 07:16:35 pm »
This is still up as a possible project if you have no other releases for this game, and want to access the section.
Heckling is an art, and game hacking a science.