Тёмный
No video :(

Reverse Engineering the AI of Age of Empires 

Nathan Baggs
Подписаться 45 тыс.
Просмотров 35 тыс.
50% 1

I reverse engineered the AI of the original Age Of Empires game.
Become a member to get early access to videos - / @nathanbaggs
Want to build cool stuff from scratch? app.codecrafte...
Tools:
🐉 - Ghidra - github.com/Nat...
🐛 - x64dbg - github.com/x64...
💭 All views are my own 💭

Опубликовано:

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 113   
@nathanbaggs
@nathanbaggs Месяц назад
Want early access to new videos and some behind the scenes content? Consider becoming a channel member ru-vid.com/show-UCQvW_89l7f-hCMP1pzGm4xwjoin Other videos you might enjoy: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-DvJLIWAGno4.html ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ILY7tYdIS2Y.html ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-_2GObcrrWq8.html
@user-rk2xi7iw9k
@user-rk2xi7iw9k Месяц назад
"i get outsmarted by a 26 year old program" bro fear 2005 ai is like alien technology AI compared to most modern triple A enemy AIs.
@AEGISAOE
@AEGISAOE Месяц назад
there is a open ai machine learning, but for aoe2
@nathanbaggs
@nathanbaggs Месяц назад
It doesn't help that I'm just bad at games
@luk3z861
@luk3z861 Месяц назад
You don't want to know alien tech - trust me.
@1AEGIS
@1AEGIS Месяц назад
@@luk3z861 what makes u think they are so advanced?
@luk3z861
@luk3z861 Месяц назад
@@1AEGIS Well something created this world you know... We live in matrix.
@wilfridtaylor
@wilfridtaylor Месяц назад
Wolololo indeed. Love this series keep up the good work.
@nathanbaggs
@nathanbaggs Месяц назад
Wololol
@michaelsmith7739
@michaelsmith7739 Месяц назад
The ending to this video just cracks me up. Good work!
@JerryThings
@JerryThings Месяц назад
Facinating to see an old game not using behavior trees, but instead it takes a dynamic approach. Love it!
@nathanbaggs
@nathanbaggs Месяц назад
I think one of the Halo games was the first to use behaviour trees (but I may be misremembering)
@jpgdallas
@jpgdallas Месяц назад
In 1996 I worked for Ensemble which was an IT consulting firm before Tony launched Ensemble Studios. So all the people listed in the Wiki page I knew back then. Angelo spent time explaining DirectX to me. Was fun to watch them make the game. Good times.
@akioasakura3624
@akioasakura3624 Месяц назад
underrated youtube legend. ive learnt so much. most ppl who try to teach reverse engineering programs, assembly thingies etc do an absolute crap job at it and expect you to "figure it out" and "practice". but u cant practice something u cant do!! seeing u do this for real and explaining/commenting all the way was invigorating for lack of a better word xd. thank u so much sir 🔥🔥
@nathanbaggs
@nathanbaggs Месяц назад
I'm really enjoying just sitting down, solving problems and then taking people on that journey
@burgtaro
@burgtaro Месяц назад
So bizarre that this series came up in my recommended, I’ve been trying to find any reverse engineering online for AOE 1 for ages (similar to how OpenRCT has been done) This is awesome, keep it up
@nathanbaggs
@nathanbaggs Месяц назад
Thanks! I've got some videos reverse engineering some other games you might find interesting
@burgtaro
@burgtaro Месяц назад
@@nathanbaggs The discovered the RCT one, amazing
@js-123
@js-123 Месяц назад
The statement "The entire game is written in 13k lines of assembly" must be wrong - that'd only be 13k instructions. That's by far not enough. Probably some tight loop was written in assembly and is 13k lines, that would make a lot more sense.
@nathanbaggs
@nathanbaggs Месяц назад
I am fully prepared to admit that my research stopped at Wikipedia: "Age of Empires was mostly written in x86 32-bit assembly code totalling approximately 13,000 lines". Might be fun to dig into the graphics and have a look though
@voodoo1094
@voodoo1094 Месяц назад
​@@nathanbaggs I remember reading an interview years ago where a dev stated that most of the rendering pipeline was written in assembly for performance reasons. So I imagine most of the rest of the game was written in C or C++ and they used inline assembly for specific parts.
@teracraged320
@teracraged320 Месяц назад
Imagine writing today a game pure in assembly this people are goats
@RandomUser2401
@RandomUser2401 Месяц назад
one could compare the number of lines for Rollercoaster Tycoon to do some sanity checks
@horsethi3f
@horsethi3f Месяц назад
I had fun modding StarCraft1 ai back in the day. You just give it a buildings list and unit list for it to build at each step. You can check for enemy composition and build specific counters by using goto commands. Fun stuff.
@mattmurphy7030
@mattmurphy7030 Месяц назад
My favorite kind of content about my favorite game? Yes please!
@JimNichols
@JimNichols Месяц назад
About 43 years ago I made a star trek game in Basic+ it was a test from my computer science teacher. Todays code is basically the same as the code then as we also programmed in assy. I remember so much but sitting down to learn C or Python at 64 I find that I don't have that spark that you have decompiling this game any longer. I love listening to your vids and you have a great oration skill, thanks for the many memories that return while watching your channel. :)
@nathanbaggs
@nathanbaggs Месяц назад
Thanks for anecdote (: glad you’re enjoying that videos!
@crypticsea
@crypticsea Месяц назад
I'm pretty sure most of the game was written in C++. and assembly was only used for certain graphics routines
@nathanbaggs
@nathanbaggs Месяц назад
I am fully prepared to admit that my research stopped at Wikipedia: "Age of Empires was mostly written in x86 32-bit assembly code totalling approximately 13,000 lines". Might be fun to dig into the graphics and have a look though
@GerinoMorn
@GerinoMorn Месяц назад
That's not a video I expected this evening, and I fully intended to click off after just checking what's the approach, but your narration is so good I stayed. Also had no idea AoE was written in assembly, I knew about the coaster and some other "big" (as in complexity) games. I guess I expected MS to just go with straight C.
@jrcarlsen
@jrcarlsen Месяц назад
Microsoft didn't develop AoE, it was developed by Ensemble Studios which was later bought by Microsoft.
@nathanbaggs
@nathanbaggs Месяц назад
It's nice when the RU-vid algorithm works
@brandonlittle6444
@brandonlittle6444 Месяц назад
There is a rather large following around the Game Command and Conquer, Kanes Wrath,. The members are active, I suggest working with that community for a place to make contributions that can be enjoyed actively by others!
@LosjuegosdeDani
@LosjuegosdeDani Месяц назад
4:59 The purple hue means that you are watching a function that ghidra couldn't find any direct references to from other functions, and so it doesn't know where the function begins This also explains the fact that picking one of the switch cases causes ghidra to reload the function showing that case, since it doesn't actually know that the function starts earlier Also, the "rubbish" from 5:25 is part of the switch case, those are values which represent the location of each case of the switch statement that the function jumps to Keep up your nice work! 😄
@nathanbaggs
@nathanbaggs Месяц назад
All makes sense, thanks for the insight
@HinkHall
@HinkHall Месяц назад
Love this series
@nathanbaggs
@nathanbaggs Месяц назад
Glad you're enjoying it (:
@Galic44
@Galic44 Месяц назад
I've just discovered your channel and saw only your two videos about Age of Empires, but they are absolutely brilliant. I really hope that this will be a regular series, it's interesting and really well done. Subscribed! Next up: cheating in UT99 followed by the Worms 2 videos!
@lor3
@lor3 Месяц назад
As a fellow reverse engineerer I salute your perseverance . Don’t give up! :)
@nathanbaggs
@nathanbaggs Месяц назад
Got to keep plugging away at these problems, can't let the computers win
@chrisdickens4862
@chrisdickens4862 Месяц назад
I really enjoy your editing, narrative style, and sense of humour. Another great video. Thanks!
@phitsf5475
@phitsf5475 Месяц назад
Could you compare it to the AI in AoE2? Aoe2 has original and upgraded AIs, and then extra difficult custom AI players have developed
@nathanbaggs
@nathanbaggs Месяц назад
I think that's an interesting idea for a video...
@petemc4190
@petemc4190 Месяц назад
that music is back, in pog form, learning me up good in why AoE is that good
@aeonitis
@aeonitis Месяц назад
Love your work 😁 On the ?? Sections of Assembly you referred to them as rubbish or caves. Can you please educate me on what they really are, and what their presence may indicate? I know they're called Mnemonics but not much else 😢
@nathanbaggs
@nathanbaggs Месяц назад
Honestly not sure what the nonsense was, probably some hand rolled optimisation. A code cave is just an unused section of a binary you can poke your own code
@Bobbias
@Bobbias Месяц назад
Mnemonics refers to the (often 3, but sometimes longer) letter assembly instruction names, like "mov", "adc", "xor", etc. "??" in the mnemonic area means that that ghidra isn't confident what that data is supposed to be, as it doesn't appear to be either intentional data or meaningful code. The "??" itself is not a defined mnemonic with any meaning, it's just an indicator that ghidra doesn't know what that data is. If you were to try to run the data there as code, it could do anything, because it's effectively completely random data. As you might imagine, treating random numbers as code is generally speaking not a good idea. Code caves are an informal name given to chunks of unused memory assigned to your process that don't contain actual code or data. They are usually a byproduct of something needing things to be aligned to some memory size. They're particularly useful for hacking or reverse engineering like this because nothing uses that data, so we're free to overwrite it with our own data. This lets us insert some instructions into the process that we might not otherwise be able to insert without breaking something else. If there was no free space in memory to insert your own code, you'd have to overwrite existing code, potentially completely breaking the game. Using code caves, you can insert your own code without overwriting things and make only a small edit somewhere to make execution jump into your code where appropriate.
@Artentus
@Artentus Месяц назад
My guess is it's some kind of lookup table the compiler inserted inline for the switch statement.
@mattmurphy7030
@mattmurphy7030 Месяц назад
@@Artentuscompiler? Its hand written assembly
@Artentus
@Artentus Месяц назад
@@mattmurphy7030 according to what I could find on the internet, it was mostly the graphics code that was written in assembly, everything else is C++.
@user-zo1kn8ob7h
@user-zo1kn8ob7h Месяц назад
2:00 ha ha lol
@bmqww223
@bmqww223 Месяц назад
EXcellent video, please do make a tutorial on how you do this... can i use this kind of knowledge to extract how a racing game implements its physics?or how a character controller is implrementd in a shooter game?
@nathanbaggs
@nathanbaggs Месяц назад
I live stream low level stuff most Sundays if you’re interested
@rodrigobogado653
@rodrigobogado653 Месяц назад
wololooooooo. Your videos are a mixture of nostalgia and learning, I came looking for copper and I found gold, I really like AOE, thanks to playing it I prevented them from breaking into my house. It turns out that as a teenager I always played it every morning and on one of those, I saw a thief trying to break in!
@nathanbaggs
@nathanbaggs Месяц назад
Glad you found the channel and are enjoying it (and thanks for becoming a member!)
@lsf3og
@lsf3og Месяц назад
Thanks for the follow-up
@nathanbaggs
@nathanbaggs Месяц назад
No worries
@imqqmi
@imqqmi Месяц назад
I wouldn't be surprised that the AI runs stuff faster than you, or needs lower resources so it can reach certain stages faster. I was wondering the same with Steel Empires and the manual actually gives a few clues. In that game the AI earns more money, about twice as much on the highest difficulty. I was only able to defeat it by saving state in the emulator each round and reload if I lost a battle and try again with a different strategy. There must be an optimum build order in AOE that it's using in order to defeat the human player, and it probably doesn't have to explore as much as it can look up where the resources and enemies are. Also AI can do stuff simultaneously where a human needs to divide the attention. The number of things it can do per 'turn' or 'tick' is probably a variable that relates to difficulty level. There's probably also lists for each unit and in what order it can be built and what the optimum numbers are resources vs time to build vs power etc. AI will be limited in how it can counteract different strategies and some just aren't covered and can be exploited. Interesting project!
@nathanbaggs
@nathanbaggs Месяц назад
I’ve seen no evidence of the AI cheating, it looks like it has a bunch of initial build orders (based on some files). I suspect the difficulty is just how aggressive it is in attacking you and pursuing victory conditions (like wonders)
@mitchlindgren
@mitchlindgren Месяц назад
I am almost certain that the AI cheats on higher difficulties in the original releases of AOE I and II. This is widely believed to be the case in the community, although I don’t know if anyone has provided proof via source code or disassembly. For AOE II DE, the new AIs were lauded for being very skilled despite not cheating, which also implies that the original AI did cheat. Will be interesting to see if you can confirm this for AOE I via your analysis.
@araarathisyomama787
@araarathisyomama787 Месяц назад
@@mitchlindgren I vividly remember spawning an "Impossible" difficulty AI in AoE2 editor like 20 years ago on a map where the AI did not have any means of producing anything, TC, nor vills, just military and other buildings or some similar condition where it's impossible to grow and I reached it after a few minutes and it randomly had all of those things.
@kkolakowski
@kkolakowski Месяц назад
I don't think the article said that ENTIRE AoE was written in hand-written assembly, but mostly sprites rendering code. Which would make sense, given that 13k loc, especially assembly - is not really enough IMO for a game such complex like AoE 😅 I think they wrote most of the game in regular C/C++ using Visual C++ with parts hand-optimized in assembly. That would explain vtables and __thiscall right? 🙂
@nathanbaggs
@nathanbaggs Месяц назад
I am fully prepared to admit that I did not do a lot of research on that part, I pretty much stopped at the Wikipedia article
@kumaravelviswanath3553
@kumaravelviswanath3553 Месяц назад
Great video. Keep up this series. Also can you work your magic on Soldiers of fortune. Thanks a lot
@nathanbaggs
@nathanbaggs Месяц назад
I’ve got some more games in the pipeline
@heyimflowers
@heyimflowers Месяц назад
This game has ruined me so many times! Fantastic video!
@theexplosionist2019
@theexplosionist2019 Месяц назад
SN means strategic number. Those are values set by the AI script that dictate how the "tactical AI" behaves.
@nathanbaggs
@nathanbaggs Месяц назад
Interesting, thanks!
@Exotic69420
@Exotic69420 Месяц назад
Great video!
@teamruddy611
@teamruddy611 Месяц назад
This is a great way to learn how to play a new game. You also learn how the game works at the same time.
@nathanbaggs
@nathanbaggs Месяц назад
I’m still terrible at it though (:
@ButtonBashOfficial
@ButtonBashOfficial Месяц назад
Next stop: Age Of Empires 2 for the 25th anniversary!
@nathanbaggs
@nathanbaggs Месяц назад
There's still more to figure out in AoE, but I would like to look at 2 at some point
@AEGISAOE
@AEGISAOE Месяц назад
USERPATCH FOR AOE1 WHEN?
@nathanbaggs
@nathanbaggs Месяц назад
I'd rather spend the time making more videos (:
@1AEGIS
@1AEGIS Месяц назад
@@nathanbaggs w userpatch
@SivakD
@SivakD Месяц назад
13,000 lines of assembly? I wonder if that's instructions only and other things like assets and directives are separate. Still, it's interesting. I wonder if all the AI code is in the same spot in the binary or spread out all over the place. Luckily you don't have to deal with bank switching.
@nathanbaggs
@nathanbaggs Месяц назад
Something I want to dig more into, some people have suggested that the assembly is just for the rendering code
@bjduncc
@bjduncc Месяц назад
Could reverse engineering the multiplayer next?
@nathanbaggs
@nathanbaggs Месяц назад
What an interesting idea...
@AgentM124
@AgentM124 Месяц назад
If the game is written in assembly and you assemble it and then disassemble it. Does it closely match the original source code? Or does it still completely destroy the structure like it would with higher level languages getting compiled down, therefore being a one way function?
@donpalmera
@donpalmera Месяц назад
I think it would look similar but you'd lose all of the stuff assembly source contains like macros.
@nathanbaggs
@nathanbaggs Месяц назад
Depends if there's any transformative process (like macro expansion) along the way
@AgentM124
@AgentM124 Месяц назад
@@nathanbaggs sure, Macros are lost, comments are lost. Formatting if you can really call that important is lost. Names of labels is probably lost? Since it converts to addresses and offsets. I don't know if assemblers have any optimizations in them like compilers do, but that might also affect it.
@gunnarbradvik8169
@gunnarbradvik8169 Месяц назад
Interesting!
@JohnAlanWoods
@JohnAlanWoods Месяц назад
Another banger. Great content.
@mrboblox4444
@mrboblox4444 Месяц назад
Hello Dearest Sirs, enjoy the video :D
@tmbarral664
@tmbarral664 Месяц назад
Oh oh ! Brilliant ;) I did some reverse a few years ago… to … hum…. Cheat 😇 But that’s another level ! Love it !
@nathanbaggs
@nathanbaggs Месяц назад
Glad you found and enjoyed this! (I have other videos on cheating...)
@DOOM-Videos
@DOOM-Videos Месяц назад
can u reverse doom AI?
@user36583658
@user36583658 Месяц назад
i sugest the game "Total Annihilation" cavedog 1997 ,
@GGRS
@GGRS Месяц назад
Always interesting stuff 👍
@Ayymoss
@Ayymoss Месяц назад
Nice thumbnail!
@nathanbaggs
@nathanbaggs Месяц назад
Thanks!
@ericdanielski4802
@ericdanielski4802 Месяц назад
Nice video.
@nathanbaggs
@nathanbaggs Месяц назад
You must be watching this on 100x speed (:
@ericdanielski4802
@ericdanielski4802 Месяц назад
@@nathanbaggs I reverse engineered your video.
@user-zo1kn8ob7h
@user-zo1kn8ob7h Месяц назад
10:30
@RubenKelevra
@RubenKelevra Месяц назад
2:15 friendly reminder to register your Sublime text editor, mate. :)
@ToTheGAMES
@ToTheGAMES Месяц назад
Why?
@RubenKelevra
@RubenKelevra Месяц назад
@@ToTheGAMES to pay the devs?
@chainbreaker
@chainbreaker Месяц назад
playing AoE in 'programmer' difficulty, lol. this is awesome content
@nathanbaggs
@nathanbaggs Месяц назад
More fun than actually playing the game
@katyk9483
@katyk9483 Месяц назад
So....if the game was written in assembly, why are you trying to Ghidra it? Shouldn't you be reading the disassembly instead? This actually seems like a stroke of luck since there really ISN'T another source you can't see (other than labels etc) and hand-written 32-bit x86 is usually way easier to read than compiled code. I'm just thinking that trying to render a program as C that was never really C might mangle some common assembly techniques and lead to confusion.
@nathanbaggs
@nathanbaggs Месяц назад
You’re right and I was surprised how well ghidra handled it. I guess the developers chose to stick to a well known ABI, which helps with RE
@minirop
@minirop Месяц назад
@@nathanbaggs the game wasn't 100% assembly, there was some C++, hence thiscall. Most of the assembly was for rendering.
@RubenKelevra
@RubenKelevra Месяц назад
Weird, I always thought the AI is super easy to defeat. Do I remember this wrongly, or was I just good as a kid? 🤔
@nathanbaggs
@nathanbaggs Месяц назад
I think maybe I'm just bad at the game
@RubenKelevra
@RubenKelevra Месяц назад
@@nathanbaggs maybe it helps if you know how the AI is thinking 😏
Далее
Reverse Engineering Age Of Empires
12:32
Просмотров 213 тыс.
Средневековый киборг
00:39
Просмотров 534 тыс.
Throwing Swords From My Blue Cybertruck
00:32
Просмотров 11 млн
I ranked EVERY terminal emulator. It was nuts
20:35
Просмотров 61 тыс.
The Free Version Of StarCraft Is NOT What It Seems...
12:17
Was starting a product business a mistake?
15:20
Просмотров 821 тыс.
Software Reverse Engineering with Ghidra
31:08
Просмотров 14 тыс.
10 Historically Accurate AoE2 units
14:00
Просмотров 122 тыс.
EA Won't Let Me Play This Game - So I Hacked It
8:49
Просмотров 314 тыс.
Real-Time Air Traffic Control Game! // Code Review
36:50
How a Clever 1960s Memory Trick Changed Computing
20:05
Средневековый киборг
00:39
Просмотров 534 тыс.