 part 2 of my Doom modification tutorials. Even if you're not interested in Doom, this is hopefully giving you an overview of how you can modify source code and later on we're going to get into using hex editors to modify binaries of files. But it's also just fun. Doom is a great game and I'm going to show you today how to create cheat codes. Again, this is part 2. Be sure to watch the previous video. Hopefully there's a link in this video to the full playlist. So go ahead and check that out because we've already installed the stuff we need to compile the game. We've actually already downloaded the source code, compiled it and have made some changes. But today, again, we're going to be looking at cheat codes. Again, I'm using Vim as my text editor. Use whatever text editor you prefer for editing. Just make sure it's text editor and not a word editor. So inside our source folder, there is a file called m underscore cheat dot c, which is where your cheat codes and their functions are stored. So let's go ahead and just have a quick look at this. So back up to the top here, including some header files, not going to really worry about those. But here we're defining all of our cheat functions. So we're we're creating them, but we're not we're not actually writing up the code for the functions yet because we want to have that because next down here. So for example, you know, there's a function called cheat God, cheat choppers, cheat must for changing the music kfa no clipping for walking through walls. So those are we're defining the functions without creating them yet here. We're going to create a little array of of the cheat. So we're saying we're calling a function called cheat. This is what you type to create to get that cheat function to happen. It's the name of that function. And I'm not really sure what always never are, but we're not going to modify that anyway. The next thing is the actual function, which we defined up here, we'll create below that. And that's why we had to define them up here, because if we create them after this, you would get to this point in the code and go, I don't know what function this is, it doesn't exist. You haven't created it yet. So the main things we want to look at is what you type, what it's called, and what the function is called. So for example, ID kfa is the happy animals and keys, it gives you all the keys, all the weapons, all the animals, think a bunch of armor up to the full and I think it might even give you full life too. So that function is called cheat kfa. If we come up here, cheat kfa is right here. And if we just search downward, we'll find a function called cheat kfa. So here, this function actually is calling two other functions. And it's also displaying a message. So in this particular file, when you see PLYR pointing to message, and then this, this is a variable. And if you remember last tutorial, we looked at the folder where or the file where a lot of strings are contained. This is a string that's defined. You can actually type the string right there or use a variable. So for example, before we get into the other functions, what I'm going to do is I'm going to just go into the game. And I'm going to type in ID kfa. And you can see up the top left of the corner, it says very happy ammo added. That's the message that displayed there. You can also see I've got all the keys and ammo and armor and all that stuff. You see my health is at 555 because we changed that in the last tutorial. So let me go back in here. So again, we can find where this string is defined. Like so I can say grep for that string in our source folder. Look at all the files. So right here, you can see that it's defined in that file that we were talking about last episode, last video. So I can come in here and search for that. Oops. Let me go back out. It's called that. So I'm coming here, search for that. I haven't already passed it. There it is. And it says very happy ammo added. So I can say very nice or whatever I want. So going back into our cheat code, so it's calling that variable and that variable just is defined in another file. So I can say make now. And once it's done compiling, I can come in here, start the game. If I type in ID kfa and look at the top left of the screen, it says very nice. So that's one way you can do that by changing the value of the variable. But I'm going to go back into the cheat here. I can also put the string directly in here. It's always good to use variables because if you want to change it, especially if that's used that strings used in more than one place. Variables are good. Plus, it's nice to have all your messages defined in that one file. But you can change the messages just like up here. They used a string. We can use a string too. I'll say ammo ammo happy. And I can make that. And then I can go into here. And if I type in ID kfa, it says ammo ammo happy. So you can do either you can you can change the variable or the string itself. Next, let's go back into our cheat codes here. And again, this is calling two other functions. So let's go ahead and look for this function. So I'm just going to go and search for that. It's defined there. It's called there, right there. TNT k a I'm not familiar with that sheet. I don't know if that's an original cheat or something added as added in 98. According to the comments there. So that that isn't from the original game. But here it looks like only prints message if last key added, however, overview. Oh, so that's that's a key, it looks like it's giving you all the keys. So again, our kfa function is calling a function called k. And that gives you all keys. So you have a cheat code that will give you all the keys. You also have a cheat code that will give you all the weapons and ammo. So instead of redefining all that in this function here, they're just calling the functions they already created. Since this function does what two other functions do, but you still might want to do those functions separately. I hope that makes sense. So that is that let's create our own cheat code now. So first thing we need to do is define a function for our cheat code. So let's come up here, let's go to the bottom of this list. And I'm going to say static void. Again, it doesn't have to be called cheat something just nice to define everything similarly. And I'll just call this my awesome cheat. So cheat awesome. So we're defining the function, but we haven't actually created it yet. Next, we're going to want to come in here. And I'll just I'm just going to copy and paste the lines that type in all this out. And I'm going to have it just so when you type the word awesome in the game, awesome in the game, we're going to call this the awesome cheat. And we're going to come over here and tell it to run the function. Awesome, which we've defined but not created. So now let's go down here, where all the cheat code functions start or wherever you want to put it. And I'm going to say, I'm going to say static void. And we called it cheat. Cheat. Awesome. And oh, actually, let me think about this. Awesome. Yep. And next, we're going to go here here. So our functions going to go between these brackets here. So now I'm going to say, plr, pl, why are saying player, we're going to point it to the players health. And we're going to say the players health is equal to so whatever the players health is currently at, it's going to change to 2%. And then we're going to say, let's change the players or to the player. We're going to display a message. We're going to say, you're so awesome. Again, it doesn't matter what the case sensitive because it's all going to be capitalized in the game. New line. And I say, I think you can beat the I don't want to be too long. That's why I put this on the line. I'll say this game or this just this with, I'm trying to keep it short. 2% health. So we're saying, you know, we're setting their their health to 2%. And then we're going to display message saying, you're so awesome. I think you can beat this game with 2% health. That's the awesome cheat. It's actually kind of the reverse of a cheat. So I'm going to say make, and I'm going to run doom. I'm going here and now at any time if I type in awesome, if I type it properly, okay, I must have typed something wrong in the code. Oh, no, there we go. I was just typing awesome wrong. You're so awesome. I think the game with 2% health and put our health to 2%. You can see my face is all bloody there. Let's go ahead and add something else to that just to make it so it does that. But anytime you get hurt, we should play a sound that you're getting hurt. So I'm gonna say s, I'm gonna say start sound. Now this is case sensitive. We're gonna say zero comma, and the sound of someone getting hurt, or the player getting hurt, which if you look at the list, if you look from the previous video I did, they're all inside that the header file, the sounds h file, and they all start with SFX. And I have it written down that the player pain sound is PL pain, although you can play whatever, play whatever sound you want from that list, or create your own, but you have to add it to a wad file. Don't forget your semi call in there at the end. So now we save that compile it and run the game. And we turn my volume up. And now if I type awesome, it's displays the message sets their health to percent, and plays that sound of the getting hurt. So that is the crash because I've tried changing the volume while I was in the game like that. Okay, so yeah, that's creating a cheat. So again, it's the m cheat.c file, you want to define it, and then set up what you want the cheat code to be, since such as awesome, call it whatever you want. And then here, you know, say what function you want to run. So I could even, you know, if I come in here and I say change this to God, like the line below it, which normally is ID, DQD. And that would run the God mode function. If I put that up here. Now if I type awesome, it'll run that same function. So you can also flip these all around. You know, if you want to mess with someone, they try to type in one cheat code, it runs a different cheat code, or sets their life to 2%. So now that I've done that, if I make the game, and I run the game. And now if I type in awesome, I'm in God mode instead. So that is creating a cheat code. Next week, we're going to look at creating or modifying the current weapons. So if you want to make take a weapon that's already there, and make it a bit cooler. That's what we're going to do next week. So I hope you're enjoying this again. It's just to give you a look at, you know, maybe you've been afraid to look at the code of a large project, because you think it's going to just be too much, because there is a lot of source code in a game like this, from the original game, and then all the modifications people have added to it. But hopefully you're getting an idea of how things work, how things are possibly defined, maybe how to search through and find what you're looking for. Grep is a very great tool for this. And just also just having fun with Doom, which is a game that I love, I still play fairly regularly, and it's always fun to modify. So that's it. Thanks for watching films by chris.com. That's Chris the case should be a link in the description. Also in the description notes to everything we did last week and this week and some notes for next week as well. So if you want to get ahead of the game, you can start looking at that. And I just thank you for watching and hope that you have a great day. Okay, this is an introduction to films by chris.com. I'm Chris. That's Chris the K. That's me right there. My daughter 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 ask 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.