Jump to content
XCOMUFO & Xenocide

UFO AI patch


kyrub

Recommended Posts

An AI patch for UFO Enemy unknown, for both Windows CE and DOS 1.4 versions.

 

UFO AI patch

 

The patch does *not* change any game mechanics, alien or weapon stats. It changes the way the AI decides its actions.

 

Features

- Aliens use a lot more of autoshot and snapshots, aimed shots only on long distances

- Alien energy spending problem fixed

- Aliens more likely to use grenades with many targets

- melee aliens are no more shy of > 3 X-com soldiers

- melee aliens will be a lot more decisive

- AI psi targetting is more random

- AI may attempt to psi attack even a relatively psi strong unit

- non-aggressive Aliens will try to snipe you more often

- Aliens trying the base assault should be much more aggressive

- Aliens will pick up their rifles after panicking

Edited by kyrub
Link to comment
Share on other sites

Haven't seen this very often myself (too busy running around while scared witless to notice :D ), but Chryssalid sometimes tend to move so much that they end up unable to move very far because their energy isn't recharging fast enough to catch up with them.

 

I have noticed it a bit in a recent Superhuman TFTD game where I would use the MC Reader on Lobstermen and notice that they frequently try to push themselves so hard to move about that they've got no energy left.

 

- NKF

Link to comment
Share on other sites

I have noticed it a bit in a recent Superhuman TFTD game where I would use the MC Reader on Lobstermen and notice that they frequently try to push themselves so hard to move about that they've got no energy left.

So, there's a partial confirmation of the theoretical problem?! Great. I spotted "slow" Chrysalids before (it always feels like divine grace, when the Chrysalid is near, gets his turn... and nothing). Just never had any means to support it with mind readin

 

I am inclined to believe this was not meant, so it is more or less a bug in the game.

 

1) When alien UNITREF statistics are set up before the combat, the game puts UNITREF [29] to 0. Then it goes up, 2A, 2B, 2C, and sets them accordingly. When it is about to put a value into Unitref 2D (energy spending factor), it puts again UNITREF [29] to 0, without any reason. So energy spending factor is skipped, and any left-over value may appear there.

In Hobbes game, many aliens are 0 and all soldiers are 1, but a dozen aliens have higher values ranging all the way up to 112! Garbage and/or the game doesn't care if they are garbage?

 

2) If the left-over value is 00, the alien will spent 1 energy point per 1 movement point. This means Chrysalid has energy only for 1,5 x full movement (with energy replenishement). Then it is exhausted. Lobsterman soldier (you mentioned) has energy for 2 full movements, navigator 1,5 x only. Calcinite, Bio-drones are the other aliens most affected (both 1,5x). Note that with unitref [45] = 0, even turning around consumes energy. So the alien in question may be unable to reaction-fire.

Link to comment
Share on other sites

This patch seems like a good one. However, I wanted to ask what happens if I don't swap the executable file and only the OBDATA.DAT?

Reason being is that I have Mok's executable which slows down the clock. If I swap it with the executable from the zip file, the game won't be really playable for me.

 

In the past I tried other ways of slowing down the game clock (don't remember which one), but only Mok's UFO loader was able to properly address this.

Link to comment
Share on other sites

wow! Nice work! How in the world did you manage to get to the game's AI??? I just wonder since I like to mod my Xcom as well ;)

 

Thanks!

Edited by uncy
Link to comment
Share on other sites

Reason being is that I have Mok's executable which slows down the clock. If I swap it with the executable from the zip file, the game won't be really playable for me.

First, using only OBDATA gives you just the "Aliens pick up guns after panicking". Everything else is lost.

 

I have never experienced the quick clock problem myself, so I can hardly help you directly. Is the slowest clock too quick, or it touches only the quicklier levels?

I could show you the place in exe, to tweak it according to your wishes - do you have any idea about

a) reading an a assembler code? (best)

b ) hex editing (average)

c) or, if you point me towards Mok's exe (or upload it), I can hopefullly cook a mix of both exes for you.

 

How in the world did you manage to get to the game's AI???

By reading the machine code. It is uneasy to change unless you know the ins and outs of disassembling. I can point towards a largely disassembled code of TFTD but without the knowledge of coding you'll have very hard time to understand, let alone tweak anything.

Link to comment
Share on other sites

maybe this works:

For people who'd like to speed up the geomap, get a normal hex editor, open the file and go to offset 68EF7 hex. The current speed is 1000 ms (1 second = 5 seconds of game time), so the value there is E8, 03 (3E8 hex is 1000). If you want the game to be 5 times faster, just replace 1000 by 200, so change the E8, 03 to C8, 00 and that's all, the game is faster.
Link to comment
Share on other sites

Reason being is that I have Mok's executable which slows down the clock. If I swap it with the executable from the zip file, the game won't be really playable for me.

First, using only OBDATA gives you just the "Aliens pick up guns after panicking". Everything else is lost.

 

I have never experienced the quick clock problem myself, so I can hardly help you directly. Is the slowest clock too quick, or it touches only the quicklier levels?

I could show you the place in exe, to tweak it according to your wishes - do you have any idea about

a) reading an a assembler code? (best)

b ) hex editing (average)

c) or, if you point me towards Mok's exe (or upload it), I can hopefullly cook a mix of both exes for you.

 

How in the world did you manage to get to the game's AI???

By reading the machine code. It is uneasy to change unless you know the ins and outs of disassembling. I can point towards a largely disassembled code of TFTD but without the knowledge of coding you'll have very hard time to understand, let alone tweak anything.

Tried lots of stuff but couldn't make it slower - only Mok's .exe works.

If you can be so kind that would be great! (see attached)

UFO_Defense.exe

Link to comment
Share on other sites

maybe this works:
For people who'd like to speed up the geomap, get a normal hex editor, open the file and go to offset 68EF7 hex. The current speed is 1000 ms (1 second = 5 seconds of game time), so the value there is E8, 03 (3E8 hex is 1000). If you want the game to be 5 times faster, just replace 1000 by 200, so change the E8, 03 to C8, 00 and that's all, the game is faster.

Interesting - I might try that. But, perhaps with the changes introduced in this patch the offset will no longer be the same?

Link to comment
Share on other sites

Wow, Mok really knew his stuff. A lot of inside changes into that exe. Has anybody extended info about all things the MOK file changes?

 

 

@oldfan

Try the attached file, it should work. If not, we may look further into it, no panic.

Please, inform me about the result, so I can post it for anyone (if succesful).

Thanks! Will do later on today or tomorrow.

So I assume you added your changes into Mok's file?

Do you have any idea what other "many" changes he did?

At the time, I suggested "Mok for president" as I tried a zillion things to slow down my clock and his .exe was the only thing that worked. Having an entire day pass in 20-30 seconds makes the game unplayable, not to mention tactical missions.

Link to comment
Share on other sites

Wow, Mok really knew his stuff. A lot of inside changes into that exe. Has anybody extended info about all things the MOK file changes?

 

 

@oldfan

Try the attached file, it should work. If not, we may look further into it, no panic.

Please, inform me about the result, so I can post it for anyone (if succesful).

Tried it - it works.

So this is Mok's file + all of your fixes. Many thanks!

I don't have a save with Chrsyalids, but I'll watch out for them next time we meet.

:-)

Link to comment
Share on other sites

Tried it - it works.

So this is Mok's file + all of your fixes. Many thanks!

Nope. This is time fix + all of my changes, only.

You did not mention you'd like to conserve all of Mok's changes (we don't know them in the first place). And since I am unaware about the exact content of Mok's exe, it's better to stay careful and to leave both exe files apart. Otherwise, unexpected can happen.

 

Anyway, thanks for testing report.

Edited by kyrub
Link to comment
Share on other sites

Tried it - it works.

So this is Mok's file + all of your fixes. Many thanks!

Nope. This is time fix + all of my changes, only.

You did not mention you'd like to conserve all of Mok's changes (we don't know them in the first place). And since I am unaware about the exact content of Mok's exe, it's better to stay careful and to leave both exe files apart. Otherwise, unexpected can happen.

 

Anyway, thanks for testing report.

Aye, many thanks. I actually found this:

http://www.xcomufo.com/x1faq.html

"

...

There are two more solutions to this problem. The first is XCOMUTIL, written by Scott Jones, which uses F0dder's fix to correct the garbled video error and also fix a long list of small bugs that are present in UFO Defense. The second is Mok's patch (two-part download in the first two posts), which corrects the garbled video error in its own way and additionally corrects the alien death screams, fixes the game timer, plays music through DirectMusic, renders the game in 640x480x16mil(colors) (instead of the traditional 320x200x256), and adds sounds in the game intro, which are usually missing from the Collector's Edition.

"

 

Haven't tried playing the game yet so dunno about alien screams - hopefully all of these are fixed as part of the UFOExtender

Link to comment
Share on other sites

Hi guys, how could I ever be able to modify the executable and its assembly code? Is there a guide anywhere? you talk of changes I have been dreaming about for years! I just wish I could add them to my personal Visual Basic applications... Thanks
Link to comment
Share on other sites

Hi guys, how could I ever be able to modify the executable and its assembly code? Is there a guide anywhere? you talk of changes I have been dreaming about for years! I just wish I could add them to my personal Visual Basic applications... Thanks

 

This is how I think you may gradually learn to cope with machine code (assembler language). This requires rather big amount of time, but it's worth it.

 

1. You get IDA program. Very important, the best of the bunch there by far.

2. You find an assembler tutorial. I used this great manual: http://www.emu8086.com/assembler_tutorial/ - with great quick reference http://www.emu8086.com/assembler_tutorial/...uction_set.html

3. You get Terror from the deep.

4. You open TFTD exe with IDA, wait for analysis.

5. You get this idc file from Seb76/Xusilak: http://www.ufopaedia.org/index.php?title=File:TFTDIDC.zip

6. From IDA window (with analysis finished), you open the idc file.

7. The program is filled with massive amount of definitions and descriptions.

8. You run around happily, lurking inside the code, using the assembler reference, reading the tutorials, learning to understand the code.

...

39. You are now able to port your knowledge into Enemy unknown. (The both exes are ultra similar.)

...

57. You use your knowledge to combine it with Visual basic to create options etc.

...

...

189. You attempt to disassemble another game from the scratch.

Edited by kyrub
Link to comment
Share on other sites

LOL, I loved the jump from step 8 to 39, 57, 189! As you said, I think it must be worth it... Thanks kyrub!!! Let's hope I can offer some nice mod to the game in 3 years from now :P
Link to comment
Share on other sites

I used to do Assembler in college through the old Debug program that was part of the tools included in MS Dos . Learned the language through a book called "IBM Assembly Language and Programming". Was so complicated because you were working at such a minute level that it was easy to lose track of what you're trying to do. Was quite glad when we moved on to compiled and interpreted programming languages.

 

However if you know what you're doing (I didn't, but I didn't really stick with it long), you can do some simply amazing things with it. In this modern day and age, with all the tools available, it should be an easier experience to learn compared to the earlier days of computing.

 

- NKF

Link to comment
Share on other sites

However if you know what you're doing (I didn't, but I didn't really stick with it long), you can do some simply amazing things with it. In this modern day and age, with all the tools available, it should be an easier experience to learn compared to the earlier days of computing.

I guess I can imagine how tedious it was in those days. Really, reading the assembler code feels like looking with a microscope into a complexe structure, that is normally delt with on a higher level. For all the detail, one cannot see the big picture and feels lost.

 

Today, all this is much more simple (and amusing!) with IDA program. IDA is the deal. It organizes the code into big, interactive graphs, that allow you a much simpler orientation. You see the key points of program flow by simply looking at the graph structure itself. You may decipher adresses by adding data structure and applying them witha few clicks.

 

But, sometimes, the function becomes too big to create a graph in IDA. Then you are back in the point mentioned by NKF. I had this once in an AI structure in Alpha Centauri, and I simply had to get through that. It felt like a jungle all around, no orientation. Without previous experience, I would never cope, I'd give up.

Link to comment
Share on other sites

However if you know what you're doing (I didn't, but I didn't really stick with it long), you can do some simply amazing things with it. In this modern day and age, with all the tools available, it should be an easier experience to learn compared to the earlier days of computing.

I guess I can imagine how tedious it was in those days. Really, reading the assembler code feels like looking with a microscope into a complexe structure, that is normally delt with on a higher level. For all the detail, one cannot see the big picture and feels lost.

 

Today, all this is much more simple (and amusing!) with IDA program. IDA is the deal. It organizes the code into big, interactive graphs, that allow you a much simpler orientation. You see the key points of program flow by simply looking at the graph structure itself. You may decipher adresses by adding data structure and applying them witha few clicks.

 

But, sometimes, the function becomes too big to create a graph in IDA. Then you are back in the point mentioned by NKF. I had this once in an AI structure in Alpha Centauri, and I simply had to get through that. It felt like a jungle all around, no orientation. Without previous experience, I would never cope, I'd give up.

 

I didn't realize you possess the necessary capability or craft to go to Alpha Centauri. Lucky you!

Are there lots of AI structures there (I cannot see them using my telescope)?

^_^

Link to comment
Share on other sites

:D

 

Sid Meier's Alpha Centauri. (aka "Civilization" in space). That brings back memories of several weekends worth of building empires that I'll never get back again.

 

- NKF

Edited by NKF
Link to comment
Share on other sites

Wow, amazing. I don't think anyone could have modified the alien behavior in XCOM. Machine language! The only way. Outstanding!

 

I'm playing under DOS and I haven't really noticed any changes yet? The modified .EXEs are in place. I made an alien drop his weapon and he still didn't run pick it back up. Or does this only work when the alien is on the same square? Ethereals still attacked my weakest psi.

Link to comment
Share on other sites

I'm playing under DOS and I haven't really noticed any changes yet? The modified .EXEs are in place. I made an alien drop his weapon and he still didn't run pick it back up. Or does this only work when the alien is on the same square? Ethereals still attacked my weakest psi.

The most recognizable feature of the patch is the autofire. In the original, aliens use it only on the closest distance. After the patch, they will clutter your soldiers with bursts of plasma, from distance. If you don't see this, something's wrong. I will try to distinguish the patch by some sort of inscription or sound in the future; I'd do it already, but it's technically uneasy from various reasons.

 

Aliens can currently pick up only the weapons they're staying over (same square). I will try to extend the range in next version, but I'm rather cautious about some AI side effects. Psi attack may still target the weakest most of the time, but I increased the range (the odds). The intention is to avoid AI predictability, but not to cut the Psi threat by making the AI targetting blind to enemy psi strength.

 

I usually try to keep AI structure similar to conserve the basic feeling of the game. You may still try to guess who's the weak Psi link in your team by taking notice at the frequency. It is just harder, less obvious, more dangerous.

Edited by kyrub
Link to comment
Share on other sites

I'm playing under DOS and I haven't really noticed any changes yet? The modified .EXEs are in place. I made an alien drop his weapon and he still didn't run pick it back up. Or does this only work when the alien is on the same square? Ethereals still attacked my weakest psi.

The most recognizable feature of the patch is the autofire. In the original, aliens use it only on the closest distance. After the patch, they will clutter your soldiers with bursts of plasma, from distance. If you don't see this, something's wrong. I will try to distinguish the patch by some sort of inscription or sound in the future; I'd do it already, but it's technically uneasy from various reasons.

 

Aliens can currently pick up only the weapons they're staying over (same square). I will try to extend the range in next version, but I'm rather cautious about some AI side effects. Psi attack may still target the weakest most of the time, but I increased the range (the odds). The intention is to avoid AI predictability, but not to cut the Psi threat by making the AI targetting blind to enemy psi strength.

 

I usually try to keep AI structure similar to conserve the basic feeling of the game. You may still try to guess who's the weak Psi link in your team by taking notice at the frequency. It is just harder, less obvious, more dangerous.

Cool, that's awesome. What you really need is a mini-FAQ that says, the I changed the aliens to do this, that, and the other, so watch for it. That way, jaded players like me who have been suffering the "Reaper runs back and forth in front of my lasers and never chomps my helpless soldiers" syndrome can ooh and aah over your hard-won modifications.

 

If you like writing, it would be a landmark achievement to write some psuedocode that explains how the stock computer opponent makes decisions. I've always wondered that, and always thought that I'd need to know assembly to get anywhere.

Edited by rumbit
Link to comment
Share on other sites

If you like writing, it would be a landmark achievement to write some psuedocode that explains how the stock computer opponent makes decisions. I've always wondered that, and always thought that I'd need to know assembly to get anywhere.

As a general rule, I protect the info about the AI. The more you know about the AI, the more it is exploitable, the less fun is the game. I admit that UFO is now getting close to the state when it does not matter a lot, there are only few players still playing it. I could probably make an exception here. But then, I'm too lazy to write it all down. - Besides, I am not that good at understanding all of UFO's AI. So I could give you only a rough estimate on one part of AI, moving and shooting in battlescape.

Link to comment
Share on other sites

Hi Kyrup,

 

I am using IDA as you recommended with the idc file... I also follow the tutorial (also very hard for me to understand). I love the diagrams and I found some addresses regarding changes to the game. I still cannot figure out how to actually DO something :(

 

If you ever have the time could you please post how you implement 1 change, It would mean the world to me.

 

Uncy

Link to comment
Share on other sites

I still cannot figure out how to actually DO something :(

Sure, I totally forgot to instruct you on this.

The difficulty of implementations ranges from extra hard to simple. I'll give you an example with a simple change. Simple change is a numerical value change of some part of the game

 

Let's take the general USO detection % in TFTD, and see the change, step by step.

 

Steps:

1. you get a Hex editor. Some are better, some worse, some are freeware, some not. You search, you read reccomendations, you choose a good one (important). I use Winhex (great, not freeware, it has quick hexadecimal converter tool).

2. You open the exe you're working on (I usually create a copy so I can fiddle with it without corrupting the program).

3. You go to IDA, find the UpdateUFoVisibilityAndActivity fonction.

4. Now, look at the bottom frame. There is a hex address, the fonction starts at 0x61C20 (0x is a common convention to display hex adresses)

5. You find the random detection factor at address 0x61DCC. It reads: push 64h, call GetRandom_0_n. 64h = 100 (use Win scientific calculator to convert hexadecimal numbers if necessary). 100 stands for 100%, if the game rolls % over the max radar %, the UFO remains undetected.

6. You go to Hex editor. You go to the adress 61DCC (every solid hexeditor has a Go to function). You see "6A 64", which means "push 64". Let's say we want the USOs to be twice as hard to detect. We overwrite "6A 64" (100%) with "6A C8" (200%).

7. Save the exe.

8. ====> Every USO is now twice as hard to detect with radars.

9. You probably rename your exe to something like 200detectUSO.exe and store it somewhere. You may create diff files as well, that store the changes (not my way, but it is a good thing).

10. You make another conversion of another game thing.

....

38. You combine all your exe changes with a hexeditor into one file (If you need some info on this later, just ask).

 

 

You may want to use harder changes. For this, you need a very good skill in reading the code AND making small changes first.

Edited by kyrub
Link to comment
Share on other sites

Thanks kyrub! It is very nice of you.

 

I will give it a good try during the WE (got some exams hehe)

 

I really want to get to make those changes!

 

I ll be posting any cool change for sure!

 

Uncy

Link to comment
Share on other sites

  • 4 months later...

Bump

 

Thank you! Now, can you please do something about turn 20?

 

If it takes me 2-3 turns to safely deploy, and I'm doing a slow and safe "sweep" of the outer area, using smoke grenades and/or incendiaries, I am never even ready to begin entering the UFO by turn 20. So the winning strategy is always "reaction fire wall".

 

Although, I did find an amusing way to take on a battleship. Assuming no Psi, you sit around the entrance. Have a couple of people dance around, attempting to get "stuck" units to move. Each turn, have a relatively slow person armed with a stun rob open the door, and stun anyone there. Have more people with stun rods able to move in through the open door, and apply more stun.

 

Between the cost of moving onto the lift, and down, and then trying to open a door, no alien has (so far) enough movement left to attack you. And if you clear the lift out of "awake" units you'll never get attacked.

 

Finally, have some "red" units with stun rods whose purpose is, if you don't have the move to finish everyone and get out, to go in and make sure they are stunned. They'll die next turn, but they keep the rest of you alive.

 

Once you get small launchers, it's much easier ...

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

so far I like it.

 

Colonel got wasted by autoshot at 10 paces ( my bad ). Snakeman picked up a Stun Launcher (etc). MC'd aliens have stamina again ...

 

am playing an endgame right now so don't really have any Base attack/defense to check the rest out well,

 

 

In the DOS1.4 AI the Turn 20 reveal seems to still be in effect -- due to other quirks & tweaks I've done, i actually like it that way!

 

 

- noticing a peculiarity though: it seems as if an alien is standing on top of a weapon but already has a weapon he packs it up anyway. I just MC'd a sectoid soldier packing 2 heavy plasmas (one on the leg, hehe) -- which is really interesting, because if he ever panics and runs, mr Sectoid will still have a weapon at hand!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...