 Again, this is part of a series. This is video 7, I believe, on editing the video game DOOM, the first five or so videos. We were editing a source code last week. We started looking into a hex editor to modify strings, which is very easy to do. Now we're going to be looking at actually modifying, you know, in this case, we're going to look at the player's health, which is not just a plain string. So what I need to do is I need to figure out where in the binary file the health is. And this will vary depending on the source code, depending on the compiler, depending on your architecture, where you have 32-bit, 64-bit, if you're running an ARM processor. So when I do this, I just want to point out that I'm going to tell you, you know, we're going to this point in the file, it will most likely be different on your system, but I'm going to show you how to find it if you have the source code. You're probably going to ask at the end of this, well, how do I do this if the source code isn't available? And my answer is it's not something I've ever actually done. Basically I think you use a decompiler and then you find the point in the code and jump to it. But I'm going to show you by creating two different binary files comparing them, which is good things to know how to do, and then finding that point that we're looking for. So first thing I'm going to do is I'm going to just type in make. I've got a clean install of doom here and I'm going to now, I'm going to move, let's bring this up here, move the binary file we just created, which is called PR boom plus. And we're going to put it in that same folder. We'll call it doom one. We can run that just to have a look. Do one. And it's actually doomed to the game. I'm just calling the file doom one. If I come in here, you can see my default health is 100. We're going to change it to 1000. And doing so it will look like 0 0 0 in the health bar because the last digit will go off if you have more than three. So let's go into the source code and change where that is. We've did this in a previous tutorial. It's in this file. We're going to go to line 62 of the file p enter in dot C in the source folder. And here I'm just going to add a zero. We're going to make that the only change you make because more changes you make is going to make the binary file a lot different. We're looking for something in particular. We're looking for that point. So we don't want to change anything else at this point. So now I'm going to say make. And I'm going to move that that we just created. I'm going to call that doom two. Now if I source doom two and go into the game, you can see it says 0 0 0, which is actually 1000. If someone shoots me, you'll see I'll get 900 something. Shoot me. Thank you. Okay. So now we need to compare the file to find out where the differences are. And there are going to be differences other than the thing we just changed, but not very many. Probably going to get maybe 20 lines of code and there's going to be 20 lines of output from this command when we're all done. I'm just going to copy and paste this. CMP will compare binary files. There we go. We get that right there. And then we can also add a geoc command to that. So let me go ahead and do that. I'm just going to copy and paste it. This all is in the notes in the description of this video. If you click on the notes, hopefully I remember to put there. It'll bring you to a paste spin file that has the notes on this whole video there as well as last week's video. So basically here, we're getting the differences, but we want to see it in hex code. So there we go. We can do that. And now you can see right here, we got a bunch of different stuff, but we have differences. The last two lines are what we're looking for. They're right next to each other. You can see there's the location in the file and 6400 and this one's E803. Let me real quick show you here. If we bring up, I'm going to use Perl to do this, although there's online converters. I'm going to clear the screen. Oh, why did I clear the screen? Let's not clear the screen. Let's go ahead and I'm going to just paste this code here. And actually, that's what I wanted to show you. So we're using Perl and executing. It's telling it to print on pack and we're telling it just look at the notes. I'm not much of a Perl. I just look this up online. But if we do 6400 and hit enter, we get 100. If we change that to E803, we get 1000. There's our difference at these two points. So if we open up HexEdit, which again should be in your repositories, just use app to get to install that if you're on a Debian based system. And we're going to modify the original DOOM file, the DOOM 1 file to have 1000% health just like the DOOM 2 file at start. So we're going to go source DOOM 1 and I'm going to hit F4 and paste in this location. And I actually did that wrong. So let me real quick quit out of that. I paste in this location. If you don't do the geoc part of this, if you just do this first part, if we scroll up, you'll see right here it gives you a different number. So we can use this number, but you can see this value is different. That's why I converted it. So I could put in that value to jump to that spot. Or if I use this one, if I hit F4, you can see F4. You can see it puts 0x saying this is hex code. We'll paste after that. If we use the one without geoc, you would want to erase that. So hit enter. And there we are, 64 and 00. So as we said, if we change that to be, I believe it was E803, according to my notes, I'll hit control X, save that. And now we can run that DOOM 1 file that did have 100% health at the beginning. And now it is also at 1000. So we modified that. Now you might try to figure this out using an online converter. So let me find where I have that. So here's this example. I just googled this. So we want to convert hex to decimal converter is what we want. And if we run our code here again, so we were saying, using our pearl code here, that E803 is 1000. But if you put that in this hex editor, it gives you a much bigger number because you're 59,395. Because what we actually want is 03E8, which is 1000. And you can also write that leading 0 does not need to be there. We'll give you the same thing. I am not advanced enough on this topic to explain why that is. And it threw me off at first when I was trying to do this, that in this binary, it flip-flops those two digits, those two characters. I don't know are those two set of characters. I don't know why. If you know why, definitely comment below. This is not my strong suit. This is just me playing around and sharing what I've learned. Hopefully, my ignorance will allow me to explain it in a way that other ignorant people will understand. Ignorant people on the topic on that don't mean to call you ignorant. We'll understand it, because sometimes when you understand something really well, sometimes you don't explain it very well to someone who doesn't understand all the basics. So I just wanted to say that and hopefully I'm explaining that well. Now let's look at this a little bit more. So how does hex work? We have values 0 through 15. So there's 16 values all together, 0 through 15, and it goes 0123456789 ABCDEF. So if I was to just put F in here and convert, I get 15. So our code ended in 8. Like that, I'm sorry, our code actually ended in, yeah, so 8 there. So I had 3E8, I think was 1,000. Yes. So if we were to change this to 300, we get 768. Let's actually just put that up here, paste that plus I already see that I've done this from my history, but we'll say that. And then our next character was E. So if I do E0, we get 244. We'll add that in there. And again, if we just did 8, which was our last character, we get 8. And if we add that all up and hit Enter, we get 1,000. So again, the first column, as I started explaining, I don't want to get too much. You can definitely look up how hex works. But the first column, in this case, 8 will go through 16. And then the next column will be a multiplier of that. So if we were to 1,0, we should get 16. And then the last column, 1,00, is valued at 256. So if we change that to 3, it's going to be 3 times 256, which is 768 and so forth and so on. So basically, you multiply the first column, well, the first column is its value. It's up to 6 or 15. The next column, you will be a multiplier of that. So if it's just 1, it'll be 16. So if it's 1, 1, we're going to get 17. And if it's 2, 1, you're going to get 16 times 2, which is 32 plus 1. So we should get 33. Thank you. I'm glad I did that right. And if we do 1, that's 256. So we take 256 plus our 33. 256 plus 33 is 289. So that's just a quick rundown. Definitely look up and read more about hex values. But that's how those numbers work. And for some reason, they're flip-flop in this binary file. So again, I can go in there. Well, let's go here back to this website and say convert. I flipped it from decimal to here. So let's say we wanted the value to be 500. Convert. So it's 0, 1, f, 4, but flip-flopped in our code. So I'm going to pull this off the side. I'm going to go back into our hex editor here. Oh, you know, I need to get that location again. So ctrl X. And I'm not going to be able to scroll up that far. Let's go here. The file is different now. Oh, because the files are the same. I can't remember what that point was in the code. So we'll just, we'll recompile it. I wish I wrote down that point. See, the thing is it's showing the difference in the file and the difference before was those last two lines. Well, I made them the same now. So my comparing is not showing me that point. So what I'm going to do is I'm going to vim this again. And just for this, I'll change this to 100. Save it. Make it. And I'll move that back to one. So doom one, now set back to 100 health. If I run that again, doom one, you can see it's back to 100 health because we recompiled it. So now if I compare the two again, and I can see them right here, the differences, I can come in here and I can say now say ctrl hex bar, hex edit. And I'm going to modify that file f four in this program, paste that that I just copied from that output brings me to here 6400. And I was saying, if we wanted to be 500, it would be F four zero one. Hopefully I'm right on this. F four zero one should be 500. I'll hit ctrl X, Y to save. Now if I run doom one again, and I go in, our health is at 500. So again, in this particular case, we had two binaries to compare to find the differences. And we're going to look that up. So it'll be a little bit different if you only had one by your if you didn't have the source code on actually finding it. But it's good to know how to compare files. I gave you a quick rundown on on hex values. If you're familiar with with a binary, which is values of two powers of two, column one is zero one, then two, then four, then eight. This is, you know, through zero through 15, 16, 256, because it's powers of 16. So if you understand binary, you should understand hex value is basically the same just instead of counting by powers of two, you count by powers of 16. If you understand binary, I recommend looking into that before you look into hex. It's a little bit simpler, because you're just working with powers of two, you know, one, two, four, eight, 16, 32, 64. And these numbers should be looking familiar, 128, because they're what, you know, you work with a lot in computers. I think that's all I wanted to show you for this tutorial. I thank you for watching. And I hope it wasn't too confusing. I hope I explained things well. Again, look at the links in the description of this video. And the one link will bring you to my notes on this that will hopefully explain it all, because it's the notes that I wrote down, that I read from. And I hope that you have a great day. And again, my website's filmsbychrist.com. That's Chris the K. There's a link to that in the description as well. Again, have a great day. Okay, this is an introduction to filmsbychrist.com. I'm Chris. That's Chris the K. That's me right there. My daughter, Ember, and my wife, Jennifer. We pretty much live in the swamps of Florida. I'm a firefighter by day, as well as by night. We work long hours. But that's not why you're here. You're here about the videos I put up on YouTube. These videos are mainly about computers and programming, which means most of my videos look something like this. And if that's what you're interested in, great. If not, that's all right. I do videos on other topics too, such as video editing, special effects, photo editing, 3D design, and music creation. If you are one of my viewers and you enjoy my videos, my Patreon page is a place where you can go to help support my videos. So I asked that you take the time to go to my Patreon page and look at different levels of rewards you can receive for different levels of backing. There should be a link in the description of this video if you were watching it on YouTube. Otherwise, you can visit patreon.com forward slash metalx1000. And I thank you for your time and your support. Have a great day.