• Topic Archived
You're browsing the GameFAQs Message Boards as a guest. Sign Up for free (or Log In if you already have an account) to be able to post messages, change how messages are displayed, and view media in posts.
  1. Boards
  2. Romance of the Three Kingdoms II
  3. Hex-editing generals: a review

User Info: ServantOfMagnus

5 years ago#1
I just finished writing some code for a mod I'm working on, so I thought it would be a good time to review how to hex-edit where and when officers appear, since many posters have asked.

The concept is that, for each scenario, the officers are chained together, from start to finish. Break one link and you'll mess up the whole thing. There are two chains (per scenario) - one for the officers who are available in the game at the very beginning, and one for those who will show up later.

The chunk of code that controls this is at 17D76 - 19BB5. There are 22 bytes for each officer, and they appear consecutively by officer number.

1st byte is the active date - the year, in hex, that the officer shows up. If you want an officer to appear eariler, change this date.

2nd byte is an autojoin code. The code is the portrait code of the officer whom the coded officer joins. For example, Cao Pi's code here is 67, because he autojoins the officer with portrait code 67 00, Cao Cao. Because this is only one byte, officers can only autojoin an officer with a unique portrait code (e.g. if you gave Cao Cao a generic portrait, no one could autojoin him.)

Bytes 3 thru 8 are the province the officer shows up in for each scenario, if he or she shows up in that scenario at all. Remember that in hex, the provinces are numbered 0 thru 28, not 1 - 41. So province 1 is 00, province 16 is 0F, province 17 is 10, province 32 is 1F, province 33 is 20, etc. FF will mean the officer doesn't show up at all.

Bytes 9 and 10 are the officer number! As far as I know, who gets what officer number doesn't matter that much, but it seems safer to keep it mostly chronological. When the mod I'm working on is done and gets play-tested, I'll let you know if I find otherwise.

Bytes 11 thru 22 are the code everyone asks about. Each officer gets two bytes per scenario (i.e. 11 & 12 are scenario 1, 13 & 14 are scenario 2, and so forth). This is where what I call the chains are coded. This is what an officer's code tells you:

The status of the current officer
Who the next officer is

If the officer is in the chain of those who show up later (i.e. he/she is NOT available immediately, either active or searchable, when the game starts), then this code is easy. The current officer has no status, because he/she is not in the game yet, so the code is just the officer number of the next officer after him/her. (I'm going to just use 'he' and 'him' from here on, but if you're hex-editing you'll most likely want to create female officers using the marriage-daughter and new ruler portraits available.)

What requires more care is the code for officers who ARE available at the start of the game, because the code is telling the game two things: status of the CURRENT officer, and the number of the NEXT officer.

The status is ALWAYS in the second of the two bytes. This is how it breaks down:

2 - last officer of the scenario. Obviously, only used once per scenario. Can't appear by itself (has to be in combination with another number); see below.

4 - start set. The first ACTIVE officer in each province MUST ALWAYS have this, as must the first HIDDEN officer in each province.

8 - end set. The last ACTIVE officer in each province MUST ALWAYS have this, as must the last HIDDEN officer in each province.

A - equals 2 + 8. Since the last officer in the scenario is also, by definition, the last in his set, he will always have this.

C - equals 4+8. If the officer is the ONLY one in his set, then he is BOTH the first AND the last and MUST have this.

E - equals C+2. If the last officer in the scenario is the also the only one in his set...you get the idea.

10 - governor. Each ruler is also governor of his province.

20 - hidden (at the start of the scenario. Do NOT use this for officers who show up later, who are in the other chain).

40 - advisor

80 - ruler

Continued in the next post.....

User Info: ServantOfMagnus

5 years ago#2
As I've alluded to, status codes combine. Governors always come first, so their code is 14. Unless they're also the advisor, in which case it's 54. (But you'd probably want the advisor in the ruler's home province, right?) Rulers are also governors and come first, so their code is 94. An officer who is alone in a province is 1C, because he's first, last, and the governor. An officer who is the only hidden officer in his province is 2C.

The point is, you won't actually use 04, 10, and 80 by themselves. At least, not if you want the game to run right : - )

The good news is not every officer needs any status code. If he's not first or last, not hidden and not the advisor, he'll just have a 00. (Well, almost.....see below).

But all this is only one part of the code. Remember, the code also has to tell the game who the next officer in the chain is.

That code is the officer number of the NEXT officer. While that's fairly straightforward, the confusion (or the mistakes you might make writing code) arises from the fact that this is combined with the status of the CURRENT officer.

This is not so bad when the officer numbers are ## 00, i.e. when working with the first 256 officers on the list. Then the first byte of your code is just the next officer, and the second byte is the status codes. But then the numbers go ## 01, which means it adds to the second byte of the code.

For example, in the second byte of the code, 09 = 08 + 01. Which means the CURRENT officer is the last in his set, and the NEXT officer has a 01 in the second byte of his officer number.

So sometimes you have to write 95 or 15 instead of 94 or 14, 09 rather than 08, 1D or 2D instead of 1C or 2C, etc.

The important thing to understand is that to write this code for any officer in any scenario, you really need to know (at least) two things: who comes before him, and who comes after him. Again, this is because it's a chain. Adding or removing anything from a chain affects both the link before it and the link after it.

Let's do an example. Someone pointed out that Fan Chou could be a Li Jue follower in scenario 2 instead of deactived.

The first thing you have to do is find his code. Fan Chou is officer # 75 00 in the original game. (7x16)+6=118, so he's 118th out of the 352 officers. If you're just eyeballing it, every 22 bytes you'll see the next officer #, so when you find consecutive officer #s you can tell where you are. After a while, you can get fairly good at it. I find his officer # at 1878C. That would be the 9th byte of his 22, so his code runs from 18784 to 18799.

This is how his code reads in the original game:


Okay, first off, the first two bytes here are FF FF. Officers who are available from the start of every scenario they are in may have FF as an active date (and autojoin code), instead of a regular year and a 00 for autojoin. I suppose this is because those two bytes are irrelevant since the officer is coded in the chain at the beginning of every scenario he is in. I haven't done that in the mod I'm working on; I've just used the year and 00 for autojoin, the same as you would for other generals. I'll let you know if for some reason that doesn't work. If you want to try it before I get to it : - ) change the FF FF to BD 00. (BD is 189)

The third byte is a 09. 09 is province 10 in hex, which is where Fan Chou is in scenario 1. The next five bytes are FF, because Fan Chou doesn't show up in scenarios 2 thru 6. We want to change that. So the FF after 09 should be a 0B (we want him in province 12 in scenario 2).

Bytes 11-12 are 81 00. That tells us that in scenario 1, the officer who comes after him is 81 00, Hu Zhen. We also can tell that Fan Chou is neither the first nor the last officer in that province, nor is he hidden. (He's also not the advisor : - )

More in the next post.......

User Info: ServantOfMagnus

5 years ago#3
But we don't care about scenario 1; we want to put him in scenario 2. So the FFs in bytes 13-14 need to be changed.

What do we change them to? Well, where do we want to put him? I have the code in a spreadsheet by officer and scenario, so I can take a look at province 12 in the second scenario. I can start by finding Li Jue. His 2nd scenario code is 2E 94. 94 means he's the ruler, and 2E means 2E 00, Jia Xue (sic), is next. Jia Xue's code is 52 40. 40 means he's the advisor, and 52 means 52 00, Guo Si, is next. Guo Si's code is 90 00. 90 00 is Zhang Ji (note that Guo Si didn't need any status coding), so he's next.

Zhang Ji's code is 94 08. 08 means we've found the last (active) officer in province 12. The next officer in the chain is 94 00, Huang Wan. Since the current set is ending, Huang Wan will be the first officer in the next set. The next set could be hidden officers in province 12, or, if there are none, active officers in province 13. If there are none of those, either, it could be hidden officers in a vacant province 13. If there is no set there, active officers in province 14 would be next. The point is that the game will jump ahead to the next province that has any active or hidden officers, and it could skip several empty provinces.

However, in this example, Huang Wan happens to be a hidden officer in province 12. His code is A3 2C. 2C tells us that he is hidden and is the only officer in his set. It doesn't necessarily tell us that he is in province 12; it could be that there are no hidden officers in province 12 but also no active officers in province 13, and Huang Wan is a hidden officer in province 13. We only know that he's in province 12 because his scenario 2 province code tells us that.

Although, we might also be able to figure it out by looking to see what the next set is, and I'm going through this to illustrate something odd. The next officer is A3 00, and that's Guo Huai. Huh? Guo Huai? But his active date is D7 - that's 215!! He shouldn't be in this chain, right? He should be in the future officers chain.

Actually, if he's coded in the starts-the-scenario chain, he'll be there. He is indeed hidden in province 13 at the start of the second scenario, despite his active date; I just confirmed it by playing. But if you look at the third and fourth scenarios, he's in the shows-up-later chain, meaning you can't get him until 215. Same with the first scenario. So, if you want to get Guo Huai 21 years early, play the second scenario. Crazy, eh? Why they did this, I have no idea.... But the point is, the chain that sets the officers up at the beginning of the scenario trumps everything else.

Back to Fan Chou. Let's put him at the bottom of the list in province 12. That is, we are inserting him into the chain between Zhang Ji and Huang Wan. So we need to change not only Fan Chou's code, but also Zhang Ji's code. Yes, we have to locate Zhang Ji's 2nd scenario code just like we had to locate Fan Chou's 2nd scenario code. We could put him somewhere else, but we're always going to have to change more than one officer's code even though we only want to add or remove a single officer, because, again, it's a chain.

Zhang Ji's 2nd scenario code must be changed from 94 08 to 75 00. 75 for Fan Chou, and 00 because Zhang Ji is no longer the last in the set. Fan Chou's 2nd scenario code must then be changed to 94 08, so that Huang Wan can be next in the chain.

Let's try something else (again, there's a reason : - ) Let's make Fan Chou the first hidden general in province 12 instead.

In the original coding we have Zhang Ji as the last active general in province 12, and his 2nd scenario code is 94 08. We have to change this to 75 08. 75 for Fan Chou, but the 08 stays because Zhang Ji is still the last in this set; we are making Fan Chou the first in the next set.

Keep reading in the next post because I want to demonstrate an easy way to make a mistake.

User Info: ServantOfMagnus

5 years ago#4
So Fan Chou is hidden, and he is the first in the set, so the second byte of his code has to be 24 (or 25, depending on who the next officer is). The first byte of his code is the officer number of the next officer. That's Huang Wan, and his # is 94 00. So the code to write for Fan Chou is 94 24.

We changed Zhang Ji's code, and we changed Fan Chou's code. Done? Not quite. In this instance, adding Fan Chou here changed the status of the officer after him, Huang Wan, so we have to change his code, too. Originally, Huang Wan's code read A3 2C. 2C = 20 + 4 + 8 = hidden + start + stop. We needed a 4 (start) in Fan Chou's code, and putting another 4 (start) in before the next 8 (stop) will mess things up. We need to change the 2C to 28. So Huang Wan's code must read A3 28.

It's true that we could have changed less code if we put Fan Chou after Huang Wan, instead of before him. Then we could have left Zhang Ji's code at 94 08, changed Huang Wan's code to 75 24, and made Fan Chou's code A3 28. But the important point is that you have to be aware that inserting, moving, or removing an officer might affect the status of the next officer. A good example of when this comes into play is if you make an officer whom you are adding the governor of his province. Besides writing his code and changing the code of the last officer in the set before him, you also have to remove the 10 (governor) from the officer who used to be governor. Otherwise you've designated two governors and have broken the chain.

So adding and removing officers, and even just moving officers around, is not as easy as you'd probably like it to be. However, in theory, you should be able to choose any 352 officers you want to populate the game with, choose portraits, write their stats, and put them anywhere in any combinations in any scenarios. You just have to write a lot of code.

You can also choose who your rulers are, how many clans will be in each scenario, and the starting date of each scenario (0F96C - 0F9DD), and which colors they will use (0FE3A - 0FEB1).

I don't know whether this thread is any clearer than the last one on this topic, but I hope it's starting to make sense. Getting out a pen and paper and writing out some chain code might help visualize it, too.

Next topic - portraits!

User Info: Cao_Bao

5 years ago#5
Sir, is this applies to PC version too?
Coz I hexedited too much on PC version, but I failed to do the chainlink officers.
I failed to move officers in the game (for example: historically Yuan Shu is in Huai Nan, it's province 18, not 19; and I failed to move them to 18)

I wish to add more officers within taiki.dat (file contains all future officers from all scenarios).

More than tens years ago, I also edited L'Empereur. Putting Napoleon as Russian general, and successfully capture all cities except 28 and 31 (coz everytime I captured those cities, the game crashes).
Later I put Napoleon as Venice general too. Also Holland too

User Info: ErikoChristy

5 years ago#6
I'm certain that the officer number 9-10 byte is all I need to edit for an auto join or search to work with that officer. I realize Zhang Lu and Yang Feng is FF FF which could mean they can't be searched for in the game. Most of those with Lu Bu in the 2nd scenario like Gao Shun, Xu Si, Hou Cheng, Wei Xu, and Hao Meng have the same. Now I see why I never could find Shang Long, Bu Zhi, Niou Jin, Meng Hou & generals in scenario 6 since I started with the first scenario all the way to 229. So long as the bytes at 9 and 10 are FF FF the officer cannot be searched for? There must be a way to do this without screwing it over.

User Info: ServantOfMagnus

5 years ago#7

The 9-10 byte is the officer number; editing that won't help you. In fact, it would mess it up because I assume the game expects the officers to be listed in order 1 thru 352.

I think what you mean are the bytes 11-12, 13-14, 15-16, 17-18, 19-20, and 21-22.

11-12 is scenario 1
13-14 is scenario 2
15-16 is scenario 3
17-18 is scenario 4
19-20 is scenario 5
21-22 is scenario 6

Yes, as long as those two bytes are FF FF, the officer will NEVER show up in that scenario. And yes, you need to edit those bytes to make him show up. But the important thing to understand is that you need to do MORE than just edit those bytes. Let's say you want Zhang Lu to show up when playing scenario 1. You've got to give him a province to appear in (for scenario 1, that's byte 3). And you'll need to put something in bytes 11-12 other than FF FF. But it is impossible to know what to put there until you determine where you want to locate him in the chain. It is true that it is more complicated to make him appear (either active or hidden) at the start of the scenario. That's what my posts try to explain how to do. But even if you just want to make him searchable in, say, 190, you still have to do a few things. First, he'll need an active date, because the FF in byte 1 will have him only show up at the start of scenarios. So, you'd put in BE (that's 190). I believe the autojoin code should be 00 (unless you want him to autojoin for someone in 190). But now, you've got to get him in the chain of officers who appear later. So, you'd find two consecutive officers who appear in 190, and put him between them. You absolutely HAVE TO change the code of the officer before him; there is NO OTHER way. So you will have to look at the code of officers other than Zhang Lu, too. If you want to do a lot of editing, but don't want to rewrite scenarios from scratch, it will be worthwhile to put everyone's byte 11 thru 22 code in a spreadsheet you can work with.

Since I have that, I will show you how to finish Zhang Lu. It shouldn't matter where you put him within the officers who show up in 190, but let's put him right before his buddy Yuan Pu (Yan Pu). Yan Pu's officer number is 99 00. To find out who is before Yan Pu, we need to know whose byte 11-12 code is 99 00. That happens to be Gong Zhi. So we're going to put him between Gong Zhi and Yan Pu in the queue.

We change Gong Zhi's byte 11-12 code from 99 00 to 96 00. 96 00 is Zhang Lu's officer number. Then we change Zhang Lu's byte 11-12 code from FF FF to 99 00, so that Yan Pu will come after him. Of course, we also make sure Zhang Lu's byte 1 code (active date) is now BE, that his byte 2 code (autojoin) is 00, and that his byte 3 code is a valid province, not FF. If you want province 29, that's 1C.

If you do all this, Zhang Lu should be searchable in province 29 in the first scenario from the year 190 on. But you HAVE TO do ALL these steps. There are no shortcuts; that's just how the game works. Computers, to the great frustration of humans, just don't "think" like people.

So you have to go through this process for each officer AND each scenario you want to edit. If you make a mistake and mess up the chain, it won't work. But if you're careful and understand how it works, you should be able to make any edits you want.

Hope this helps; it would be cool if there were lots of people making and sharing mods.

User Info: ServantOfMagnus

5 years ago#8
Mr. Honorable Cao_Bao,

I am sorry, but I do not have any experience with the PC version of this game. I probably should, because it seems like perhaps you can do more with the PC version than you can with the SNES version. I guess it is just that I grew up with the SNES version. So unfortunately, I am not qualified to answer any questions about the PC version. But if you know how the SNES version works, you could experiment with the PC version to see if the processes are similar.

User Info: Cao_Bao

5 years ago#9
I think PC version is far more easier to hex edit, coz PC version has separate the rotk2 program into several files: music file, opening intro file, portrait file, scenario data file, future officer data file, generic portrait file, ending into file, and many more files.
I think PC version of generals data almost similar to SNES, except koei split it into two files: scenario data file (scenario.dat) and future officer data file (taiki.dat). And I think the bytes for generals appearance in scenario 1,2,3,etc (you say byte 11-12 and forth) are valued "00" in PC version, so I have some difficulties to know about the generals number.

The great Cao Bao with int 13 can heavily hexedit the game, so you can do hexedit better than him if you wish to learn.

User Info: cute_fan

5 years ago#10
Nice finds ^.^ Thank you!

Happy new year everyone ^.^
cuteness ^.^
  1. Boards
  2. Romance of the Three Kingdoms II
  3. Hex-editing generals: a review
  • Topic Archived