Modify code in a civ4 saved game

kristof123

Chieftain
Joined
Nov 1, 2014
Messages
27
Hi guys. I am trying to edit the program code of a saved civ4 game.

What I am attempting is to change the leader and civilisation I initially chose on that specific save. For example I chose Asoka and saved the initial 4000BC first round before settling my first settler. I would love to replace Asoka with Shaka for example, just to see how Shaka and the Zulu empire fare on this specific map that has been generated.

I tried editing the said save in notepad++ but I cant change those strange characters to UTF-8 characters.Because of that I cant the correct code area to modify. Perhaps if I save the notepad++ vfile as a txt
file I could open it in python or something. But the thing is that I am new to this and need some please.

If anyone got any suggestions please feel free to share them.

Thanks guys.
 

Attachments

Below is an example of the characters that are displaed when I try to edit the saved game in notepad++. I tried clicking convert to UTF-8 and then convert to something else and so on and so forth. But nothing helped. I then saved the code in a python file and tried opening it in spyder and anaconda but still those characters remain.

I know the basics of programing like for loops and variables. So please if any suggestions are forth coming, please explain them in laymans terms.






ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ؁ xœìÝœ-E™7þ§ºOšÎäœsÎ9ç ^.á^ JÁ «(¬A@ÀQ ‚«‚E×k@ÅÙÕ5àØ5òúªË¿ªûœ;gfNŸ®®é{îïåoÕ§æÞ¹s¾]]]]Ý]OÑötâÿ¼ôÒQ}è{FÖé?øÏ½U'Zá?ÔÃÌŸÍæÅ·í§˜ù/ñÔú*RŒß«œ¼¼xB î"-b2xIç%—T^RxIæ%‰—D^x ðâý¼/â÷é¿GSø]I¡.¹¡’ñ÷m”JþˆÿO}Õ0íÒ^þ[)ÙþGþ™Âûa?ÿ}ý=ý=¹“^KVNƘQŽŒ:¬ÐŽ‘R™½åHü»ß}®ôW —¾åÿ5·£&¿®Q2Gb„!FbÄ!FþÐ犑„Qˆ„èqÅHCŒ8ÄÈCŒ@Ä"“— /Yd1sÈ]äñ’ÏK/…¼ñRÌK /¥æfP9/¼TòRÅK5/5¼ÔòRGæP·—F^šxi楅—V^Úxi祃—N^ºx鿥‡—^^úx£Ú^yâe˜—^Fyãeœ— ^&y™âeš—^fy™ãež—^yYâe™—^VyYãe—
^6yy/Gñr4/¯äå^Žåå8^ŽçåU¼ìãå^öór"/'ñr2/§ðr*/§ñr:/gðòj^Îäå,^ðr6/çðr./¯áå /¯åå<^Îçå^.äåu¼¼ž—‹x¹˜—Kx¹”—Ëxy/—óòF^®àåJ^ÞÄË›yy/oåå*^®æåxy/oçå^ÞÁË;y¹–—ëxùG^ÞÅË»yy/ïååz^ÞÇË
¼ÜÈËûy¹‰—›y¹…—ðr+/·ñr;/äåŸxù/wðòa^îäå#¼|”—»x¹›—ñr
 
The savegame is in a binary format. This mean if it say saves an int, it will save 4 bytes containing the binary data from that int. You can figure out where each variable is saved, but to do that you need to really dig into the DLL code and being in the code, which is reachable to modders, it differs from mod to mod, or at least it can. Also it saves indexes in xml files, meaning what you want to do is to find the int where the leader of a specific player is saved and then change it to Shaka's index.

No offense, but if your coding skills is on the level where you start with notepad++ and don't catch that it's a binary format, then I wouldn't hold my breath that you manage to edit savegames like this. There is a reason why we don't have a savegame editor. It's a very complex task to make one and I will not even attempt to make one, even though I have the skills because it would be rather time consuming to do so. Also I can imagine more interesting tasks to work on.
 
The savegame is in a binary format. This mean if it say saves an int, it will save 4 bytes containing the binary data from that int. You can figure out where each variable is saved, but to do that you need to really dig into the DLL code and being in the code, which is reachable to modders, it differs from mod to mod, or at least it can. Also it saves indexes in xml files, meaning what you want to do is to find the int where the leader of a specific player is saved and then change it to Shaka's index.

No offense, but if your coding skills is on the level where you start with notepad++ and don't catch that it's a binary format, then I wouldn't hold my breath that you manage to edit savegames like this. There is a reason why we don't have a savegame editor. It's a very complex task to make one and I will not even attempt to make one, even though I have the skills because it would be rather time consuming to do so. Also I can imagine more interesting tasks to work on.




Thanks alot for the reply, I really apreciate that you took the time to reply. Based on your advice I will download dotPeek to see if I can access the DLL code.

You are pointing me in the right direction and that is enough so thanks a ton. Even though I have no experience in this area, I will still attempt to edit the code. I am not in a hurry, so when I finally achieve this task I will be content. As they say, slow and steady wins the race.

I appreciate your criticism, I am not upset about it, infact I like it because through it you have shown me the first steps I need to take:thumbsup:

Once I know which steps to take, google can take over and give me the info I need to move to the next step.
 
Thanks alot for the reply, I really apreciate that you took the time to reply. Based on your advice I will download dotPeek to see if I can access the DLL code.
You really should look at the C++ source code itself. It's released and is included in most gamedirs as CvGameCoreDLL or something like that. If you lack this folder, it should be in the download section as well.
 
You really should look at the C++ source code itself. It's released and is included in most gamedirs as CvGameCoreDLL or something like that. If you lack this folder, it should be in the download section as well.



Thanks bro. I located the said file and browsed down to ----->CvReplayInfo.cpp, opened it in text editor and I am sure this is the file is relaed to the DLL I need to access. Because by looking at the code contained within, for example :


int CvReplayInfo::getNumPlayers() const
{
return (int)m_listPlayerScoreHistory.size();
}


bool CvReplayInfo::isVictoryCondition(VictoryTypes eVictory) const
{
for (uint i = 0; i < m_listVictoryTypes.size(); i++)
{
if (m_listVictoryTypes == eVictory)
{
return true;
}
}
return false;
}



it seems I am on the right track. But this is simply code fist and foremost. Which Dll coresponds to this code file? Because I need only that one specific save at 4000BC in that specific saved game and not the other games I have saved on my harddrive.
 
What you need to look at is the write functions. The exe calls them in this order:
  1. CvInitCore
  2. CvGameAI
  3. CvMap
  4. CvTeamAI
  5. CvPlayerAI
You need to follow through write in each of those and that way figure out what each byte represents.
pStream->Write(m_iLandPlots);
m_iLandPlots is int, meaning it's 4 bytes.
pStream->Write(GC.getNumBonusInfos(), m_paiNumBonus);
GC.getNumBonusInfos() tells the number of elements in the bonus xml file and it saves an array of that length. m_paiNumBonus is an int array, meaning each time it saves an array element, it saves 4 bytes.
Remember this is an x86 program, meaning it saves data in little endian format.
Step 4 and 5 loops for each player/team.

That's all the help I will provide. If that's not enough (it most likely isn't), then you are on your own. You have decided on working on what is actually a massive task.
 
If you open up the save in-game and use world builder to save the map. Then it will be easily possible to switch civs in the map file.
 
I agree, for what you are trying to accomplish it does not make sense to delve into the DLL sources or savegames themselves. You can always edit the game using world builder or using console commands, and then either save to a new saved game or world builder scenario, depending on your goal.
 
Back
Top Bottom