more savegames

General Modding Information/Questions; support/discussion/questions

Moderator: thunderchero

Forum rules
:idea: Please search before starting new topic. :idea:
There is a good chance it has already been asked.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7966
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Adding save folder

Post by thunderchero »

Spocks-cuddly-tribble wrote: Fri Oct 06, 2023 11:48 am
thunderchero wrote: Fri Oct 06, 2023 11:03 amfile name (written in file, not the actual file name) is loaded when game is loaded at unk_5A28D8
Yes, 5A28D8 is start of the loaded gameInfo file and first 0xC bytes is supposed file name, but BotF might never use this data?

When handling the actual files it might just compose the file names via dynamic strings for slot loops?
correct, code will use the dynamic strings for slot loops, I even moved all saved files to save folder by changing dynamic strings only.
but the 0C limit crashed game if game was saved (not auto or last?) but would load existing saved games from folder.
Spocks-cuddly-tribble wrote: Fri Oct 06, 2023 11:48 am
thunderchero wrote: Fri Oct 06, 2023 11:03 amthere is 2 other bytes that do not match, but would need to extract all files from saved files to figure out what the offset is of changed file. But from text in area I expect it is part of game info maybe time saved?
If your file names are longer than 0xC your code might also overwrite the start of the ingame save description @ 5A28E5 gameInfo_C_savename ?
Correct again, I noticed this loading in game and with UE. The description would have only overflow example; "av" or ".sav"
also if saved game went from 99 - 100 file name would overflow by 1 more byte into description.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1961
Joined: Sun Apr 27, 2008 2:00 am

Re: Adding save folder

Post by Spocks-cuddly-tribble »

thunderchero wrote: Fri Oct 06, 2023 12:06 pmthe 0C limit crashed game if game was saved (not auto or last?) but would load existing saved games from folder.
That's why I suggested just player empire abbreviation (c,h,f,k,r) plus turn number (without 'number'). :wink:

Would this fix the ingame save issue or must UE still edit the gameInfo filename to match the actual re-named file name :?:
(unless you find and fix the asm code for this)
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7966
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Adding save folder

Post by thunderchero »

Spocks-cuddly-tribble wrote: Fri Oct 06, 2023 2:24 pm Would this fix the ingame save issue or must UE still edit the gameInfo filename to match the actual re-named file name :?:
(unless you find and fix the asm code for this)
the in-file "file names" there are 2; 1 in archive header and 1 in gameinfo file. If both are manually 00 out, game file name will still display and load and play without issues.

when watching 5A28D8 in de-bugger;
with auto save turned off
new game will read all 00's until game is saved then at 5A28D8 will have game%d.sav (%d = slot saved on)
normal saved game at 5A28D8 will have game%d.sav (%d = slot saved on)
edited saved game with file name 00 out will read all 00's until game is saved then at 5A28D8 will have game%d.sav (%d = slot saved on)

with auto save turned on
new game will read all 00's until turn process then display auto.sav if saved will display game%d.sav (%d = slot saved on) then on turn process display auto.sav again
normal saved game at 5A28D8 will have game%d.sav (%d = slot saved on) until turn process then display auto.sav if saved will display game%d.sav (%d = slot saved on) then on turn process display auto.sav again
edited saved game with file name 00 out will read all 00's until turn process then display auto.sav if saved will display game%d.sav (%d = slot saved on) then on turn process display auto.sav again

de-bugger did not always update (no refresh)
But in my opinion internal file names have no effect in game play or loading/saving.
actual file name is used to fill load/save screen checking file for F3 FF FF FF (-13) ?
if F3 FF FF FF (-13) slot displays blank in load/save screen.

now I bet you are as confused as I am, so I am taking a nap now. :mrgreen:
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1961
Joined: Sun Apr 27, 2008 2:00 am

Re: more savegames

Post by Spocks-cuddly-tribble »

So there is no issue with your patch since it uses code for auto/last.sav, which isn't affected by the 0xC limit crash problem when saving. :wink: :up:
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7966
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: more savegames

Post by thunderchero »

Spocks-cuddly-tribble wrote: Fri Oct 06, 2023 6:40 pm So there is no issue with your patch
yes and no if save goes past 999 it will hit over run and not display description over 9999 description will display "v". :wink:
but even this will not cause crash.
it would be better if we just prevent any writing of file name to save file :wink: :up:
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1961
Joined: Sun Apr 27, 2008 2:00 am

Re: more savegames

Post by Spocks-cuddly-tribble »

thunderchero wrote: Fri Oct 06, 2023 7:12 pmit would be better if we just prevent any writing of file name to save file :wink: :up:
This should work for you (first 0xC bytes in gameInfo set to 0 when saving):
0043CF0E     EB 24             JMP SHORT 43CF34

0043CF34     8BC4              MOV EAX,ESP
0043CF36     8910              MOV [EAX],EDX
0043CF38     8950 04           MOV [EAX+4],EDX
0043CF3B     8950 08           MOV [EAX+8],EDX
0043CF3E    ^EB D0             JMP SHORT 43CF10
But will not prevent corruption of in-game descriptions due to over-length of your generated file names.
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7966
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: more savegames

Post by thunderchero »

Spocks-cuddly-tribble wrote: Fri Oct 06, 2023 8:26 pm
thunderchero wrote: Fri Oct 06, 2023 7:12 pmit would be better if we just prevent any writing of file name to save file :wink: :up:
This should work for you (first 0xC bytes in gameInfo set to 0 when saving):

But will not prevent corruption of in-game descriptions due to over-length of your generated file names.
I wonder if this location will remove file name from archive header
0051C9FB A1 E8 77 59 00          mov     eax, ds:dword_5977E8
this is right before archive.tmp is written then renamed and when checked 0C limit would conflict with version text?

then if we could move string location 5A28D8 -> ? and raise limits
longer file names could be possible?
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1961
Joined: Sun Apr 27, 2008 2:00 am

Re: more savegames

Post by Spocks-cuddly-tribble »

thunderchero wrote: Fri Oct 06, 2023 9:29 pmwe could move string location 5A28D8 -> ? and raise limits
longer file names could be possible?
Archive header arc needs this data to update the right sav file, but you can try to change the code here to any unused dynamic area:
0043868D         mov     edi, offset 5A28D8 gameInfo_0_filename

Try: (if this works you don't need my above "first 0xC bytes in gameInfo set to 0 when saving")

43868D         mov     edi, 5B4270
Requires this fix to free used dynamic area: viewtopic.php?p=32866#p32866

Here is an example from "Mod version fix for more than 6 letters registry keys": viewtopic.php?p=57814#p57814

Mod version fix will still used first 0x10 bytes @ 5B4260 for Mod version so we can use 5B4270+ :wink:
# edifbnft.bst supporting 49+ entries fix (to skip address map)
>> 0x0004fbdc 8b 04 85 60 42 5b 00 01 d0 5a c3 00
<< 0x0004fbdc c1 e0 02 03 02 8b 04 10 03 c2 5a c3

# free dynamic area 5B4260-5B431F (unused edifbnft.bst address map)
>> 0x0004fc53 40 8b 0a 83 c2 04 89 0c 85 5c 42 5b 00 83 f8 2d 7c ee
<< 0x0004fc53 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
But due to many mixed patch parts you new patch will show pseudo-conflicts in BotF patcher!
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7966
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: more savegames

Post by thunderchero »

I should only need the new location to push here
0051D887 push    edx             ; lpNewFileName
and at new offset location changed here
0043868D BF D8 28 5A 00          mov     edi, offset gameInfo_0_filename
from everything I have seen and after that with all new saves first 13 bytes at 5A28D8 would be 00's? (other changes above might not even be needed)
but still 0C limit changes would be needed as necessary.
the only other location I am even wondering about is at 004F0700 but expect if 00's no issue.(I think this is load info and 00's works)

and hoping this 0C is all that is needed
0043872C 83 C4 0C                add     esp, 0Ch
Edit; I still think with some re-sets after changes back to gameInfo_0_filename it still might work?
so many ??? here, note to self put away code after starting drinking. :idea:
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1961
Joined: Sun Apr 27, 2008 2:00 am

Re: more savegames

Post by Spocks-cuddly-tribble »

It should work with no issues. :wink: Just update your first/removed patch with changed pointer @ 43868D (5A28D8 gameInfo_0_filename -> 5B4270) and add my two codes to free the new dynamic area @ 5B4270.

thunderchero wrote: Fri Oct 06, 2023 11:11 pm I should only need the new location to push here
0051D887 push    edx             ; lpNewFileName
and at new offset location changed here
0043868D BF D8 28 5A 00          mov     edi, offset gameInfo_0_filename
from everything I have seen and after that with all new saves first 13 bytes at 5A28D8 would be 00's? (other changes above might not even be needed)
Copy vs update:

Above first is new file name for the copy of old auto.sav (default last.sav). -> No need to change this again.

The latter is name of the sav file to update (auto.sav and/or manual slot saving).

By default the code doesn't read the file name from gameInfo. So the dynamic location of the temporary string for the sav file to update can be changed (to any unused dynamic area to prevent conflicts).

thunderchero wrote: Fri Oct 06, 2023 11:11 pmbut still 0C limit changes would be needed as necessary.
No, @ 43868D (5A28D8 gameInfo_0_filename -> 5B4270) will take care of this.

thunderchero wrote: Fri Oct 06, 2023 11:11 pmthe only other location I am even wondering about is at 004F0700 but expect if 00's no issue.(I think this is load info and 00's works)
Correct, its just a pointer to start of loaded gameInfo, file name is not even read but composed via slot ID.

thunderchero wrote: Fri Oct 06, 2023 11:11 pmand hoping this 0C is all that is needed
0043872C 83 C4 0C                add     esp, 0Ch
Not even this is needed. 0XC (12) is for the 3 push (each esp -4):
0043871C         push    ecx
0043871D         push    offset aGameD_sav                 ; "game%d.sav"

00438726         push    ecx

0043872C         add     esp, 0Ch
thunderchero wrote: Fri Oct 06, 2023 11:11 pmI still think with some re-sets after changes back to gameInfo_0_filename it still might work?
Yes, just the pointer and two codes to free 5B4270 to prevent data conflicts.
thunderchero wrote: Fri Oct 06, 2023 11:11 pmnote to self put away code after starting drinking. :idea:
Creative way for code extensions, now you see each line twice...
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7966
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: more savegames

Post by thunderchero »

Spocks-cuddly-tribble wrote: Sat Oct 07, 2023 12:45 pm So the dynamic location of the temporary string for the sav file to update can be changed (to any unused dynamic area to prevent conflicts).
you know of any unused dynamic area of 30 bytes (1Eh)
Spocks-cuddly-tribble wrote: Sat Oct 07, 2023 12:45 pm
thunderchero wrote: Fri Oct 06, 2023 11:11 pmnote to self put away code after starting drinking. :idea:
Creative way for code extensions, now you see each line twice...
I might give this a try later this weekend (after I have a few drinks)
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1961
Joined: Sun Apr 27, 2008 2:00 am

Re: more savegames

Post by Spocks-cuddly-tribble »

thunderchero wrote: Sat Oct 07, 2023 4:43 pmyou know of any unused dynamic area of 30 bytes (1Eh)
Already prepared and provided for you (see end of this post).

But we shouldn't even need this if you leave the string at 5782DC aGameD_sav db 'game%d.sav' and all Xrefs unchanged/default?

Your new file name string is only needed once for sub_51D886 copy_file_EAX_to_name_EDX.

So unless I miss something (I need to see your code/approach):
438655 jump loc_relocation

@ loc relocation

call 51D886 copy_file_EAX_to_name_EDX  auto.sav -> last.sav // EDIT if sub_51D886 is rename and not copy then just leave this out

compose your new/extra file name string and mov start position pointer to edx

mov     edx, start location new composed file name string
mov     eax, offset aAuto_sav
call 51D886 copy_file_EAX_to_name_EDX auto.sav -> your new file name/location
jmp 43865A
---

Perhaps not even needed:

With this hex code dynamic area 5B4260 (length 0xC0 / 192 bytes) is unused. So 5B4270 has still 0xB0 (176 bytes) unused for max length of file name.
Spocks-cuddly-tribble wrote: Fri Oct 06, 2023 10:24 pmRequires this fix to free used dynamic area: viewtopic.php?p=32866#p32866

Here is an example from "Mod version fix for more than 6 letters registry keys": viewtopic.php?p=57814#p57814

Mod version fix will still used first 0x10 bytes @ 5B4260 for Mod version so we can use 5B4270+ :wink:
# edifbnft.bst supporting 49+ entries fix (to skip address map)
>> 0x0004fbdc 8b 04 85 60 42 5b 00 01 d0 5a c3 00
<< 0x0004fbdc c1 e0 02 03 02 8b 04 10 03 c2 5a c3

# free dynamic area 5B4260-5B431F (unused edifbnft.bst address map)
>> 0x0004fc53 40 8b 0a 83 c2 04 89 0c 85 5c 42 5b 00 83 f8 2d 7c ee
<< 0x0004fc53 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
But due to many mixed patch parts you new patch will show pseudo-conflicts in BotF patcher!
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7966
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: more savegames

Post by thunderchero »

Spocks-cuddly-tribble wrote: Sat Oct 07, 2023 5:44 pm
438655 jump loc_relocation

@ loc relocation

call 51D886 copy_file_EAX_to_name_EDX  auto.sav -> last.sav // EDIT if sub_51D886 is rename and not copy then just leave this out

compose your new/extra file name string and mov start position pointer to edx

mov     edx, start location new composed file name string
mov     eax, offset aAuto_sav
call 51D886 copy_file_EAX_to_name_EDX auto.sav -> your new file name/location
jmp 43865A
great idea, but once auto.sav -> last.sav there is no auto.sav -> your new file name/location.

so instead I went with;
last.sav -> new.sav
auto -> last
write new auto


I need to do more testing but so far working as expected with using "race name"_"turn#.sav format (Romulans_9.sav)
if file present in saves folder it is deleted before new file is moved
checks turn 1 and 2 (turn 1 vanilla last.sav bug)
if turn 1 jump to 0043865A (create auto.sav, on turn 1 last.sav would be from different game)
if turn 2 jump to 0068C48A (auto.sav -> last.sav, create auto.sav)
else (last.sav -> new.sav, auto.sav -> last.sav, create auto.sav)

here is code (current but may still change)
00438641 E9 0A 3E 25 00                          jmp     loc_68C450 //jump point to new code

0068C450                         loc_68C450:                             ; CODE XREF: sub_438630+11j
0068C450 A1 18 29 5A 00                          mov     eax, ds:dword_5A2918 //get current turn
0068C455 83 F8 01                                cmp     eax, 1 //if turn 1 jmp 43865A
0068C458 0F 84 FC C1 DA FF                       jz      loc_43865A
0068C45E 83 F8 02                                cmp     eax, 2 //if turn 2 jmp 68C4A1  
0068C461 74 3E                                   jz      short loc_68C4A1
0068C463 48                                      dec     eax //decrease turn by 1 to match in-game display
0068C464 50                                      push    eax
0068C465 36 A0 2A 2B 5A 00                       mov     al, ss:byte_5A2B2A // get player race id
0068C46B E8 00 E9 DA FF                          call    sub_43AD70 // call jump_lex_monster_majors
0068C470 50                                      push    eax
0068C471 68 A0 A3 68 00                          push    offset aSavesS_D_sav ; "Saves/%s_%d.sav"
0068C476 8D 44 24 0C                             lea     eax, [esp+9Ch+var_90]
0068C47A 50                                      push    eax
0068C47B E8 19 79 E8 FF                          call    sprintf_ //call sprintf__compose_string
0068C480 83 C4 10                                add     esp, 10h //align esp to string start
0068C483 8B F4                                   mov     esi, esp //move string to ESI
0068C485 56                                      push    esi
0068C486 8B C6                                   mov     eax, esi //move (esi) string to EAX
0068C488 8B D6                                   mov     edx, esi //move (esi) string to EDX
0068C48A E8 DC 13 E9 FF                          call    sub_51D86B //call delete_file_eax__last_sav
0068C48F B8 00 83 57 00                          mov     eax, offset aLast_sav ; "last.sav"
0068C494 90                                      nop
0068C495 E8 EC 13 E9 FF                          call    sub_51D886 //call move_file_eax__last_sav
0068C49A BA 02 01 00 00                          mov     edx, 102h //reset edx
0068C49F 8B E6                                   mov     esp, esi //reset esp
0068C4A1
0068C4A1                         loc_68C4A1:                             ; CODE XREF: sub_438630+253E31j
0068C4A1 B8 00 83 57 00                          mov     eax, offset aLast_sav ; "last.sav" //over written jump code
0068C4A6 E9 9B C1 DA FF                          jmp     loc_438646 //return to start point 438646

0068A3A0 53 61 76 65 73 2F 25 73 5F 25 64 2E 73 61 76 00 aSavesS_D_sav   db 'Saves/%s_%d.sav',0 //new string offset 
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7966
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: more savegames

Post by thunderchero »

Note if we ever figure a way to load these saved files I did find an entry point for strings at;
00438822 68 D0 82 57 00          push    offset asc_5782D0 ; "auto.sav" (continue button)
I changed offset for longer string changed string to "Saves/Ferengi_18.sav" and that game loaded from save folder with a string of 21. :roll: :idea:

Edit;
thoughts on how it might be done (very basic and no idea how to do it)
hijack continue button on opening.wdf
clone, rename and edit hsummary.wdf to use only 2 buttons (cancel and load) scroll bar/buttons and list box to be opened by continue button.
code to read "Saves" folder for %s.sav to create string array
list string array in new wdf listbox
if double clicked load array to 00438822
if selected and load button selected load array to 00438822
if cancel button selected return to opening.wdf
move all current .sav's to "Saves" folder also loadable/savable old way and though new wdf
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1961
Joined: Sun Apr 27, 2008 2:00 am

Re: more savegames

Post by Spocks-cuddly-tribble »

I see, so sub_51D886 (movefile) is rename_or_mov_file_EAX_to_name_or_location_EDX.
lpNewFileName = the new name for the file or directory. The new name must not already exist: https://learn.microsoft.com/en-us/windo ... e-movefile
So either rename and/or mov to new path? And same name twice to same directory = crash?
So Delete_file_EAX prevents issues if same name is already in the directory and has no issues if no file there to delete.

Best would be importing CopyFile to ASM pointer: https://learn.microsoft.com/en-us/windo ... e-copyfile
We only have CreateFileA and WriteFile listed in BotF (57448C Imports from KERNEL32.dll).
Trek.exe 0x173122 KERNEL32.dll / 0x17349A list of imported functions (list number + function name) but IDA doesn't show code to edit the ImportTable.:mad:
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
Post Reply

Return to “General Modding Information/Questions”