 welcome. Today we're going to be looking at a script I wrote yesterday just for fun. I actually wrote two of them. And it's this script right here. So let's talk about this. This is actually a shell script that has a video game ROM of Super Mario Bros. embedded into it that I put up on Pastebin. And why did I do it this way? So we have different options here, but let's quickly just look at this script. Let's look at other options and then see why I did it this way. And really most of this code, as far as lines of code, are not needed. They're just extra little features. So for example, all this, this is a variable called ROM, which is the ROM in base 64. And all this is actually one line. And it's Super Mario Bros. in ASCII in base 64. So I'm putting that in a variable called ROM. Here, we're decoding that base 64, putting in a file and then running it through an emulator and then removing it when we're done. Let's look at the top lines here. So the first part is a couple of variables, saying the name of the ROM, which is mainly used to just display messages to the user, where the file is, and where we're going to put our ROM temporarily while we run it. This section here checks to see if this ROM, or I'm sorry, this emulator exists. If it does not exist, well, then it's going to try, it's going to display a message to the user saying it doesn't exist. Wait one second just so they get to read that message. And then it will start to sudo apt install that emulator. So of course, this is only going to work on Debian based systems with apt. And yeah, this is normally a no no sudo inside a script. You know, that's, that's kind of iffy. But really, none of this is needed. It's just there mainly to give user information to the user and try to install the emulator if it doesn't already exist and if it can on that particular system. Obviously, you can change this to a different package manager if you're on a different system. So really, we can remove all this code. It's not needed. Then we got our ROM, which is obviously needed. And then we just using this echo, we could echo that ROM into base 64. Here, instead of using a variable, we could just give it a file name. And then we can run the emulator in the file name. And we don't even then this is just cleanup. So really, the only three lines of code in here needed, besides your shebang line, which isn't needed, but recommended, is the base 64 for the ROM into a variable, decoding that into a file, and then running the emulator. There's only three things that are needed. Let's go ahead and talk about this base 64 a little bit more. Let me go ahead and select the whole thing. Actually, let me grab the whole thing and the variable name. I'll go down like this. It's not very big. So again, the point of me doing this project was I wanted to see if I could put this up on a site like Pastebin and have it function. Let's go ahead and go to our shell here. And what I'm going to do is I'm just going to paste that. There we go. Now I have, let me clear a screen, echo, I can echo out this variable and it will give me that base 64. I can echo that into the command base 64, which is probably on your system if you're running any Linux system, even lightweight ones, it's just there, you know? So echo into base 64, I'm going to say dash D to decode and that will convert it back into a binary file, but it will output to the shell. So there you go. If you do something like this and your prompt is kind of messed up, just type reset and that should reset everything. But what we want to do is we want to run this command and put it into a file. I'll just call it Mario dot zip. Now, if I check that with file, which tells us what type of file something is Mario dot zip. It tells me right here, it's a zip archive. And of course I can run my emulator with the funny name Medna fan and that zip file. And it will start up the game. And as I mentioned in previous videos, someone's asking how you set the controls, I believe it's Alt Shift 1. Yeah, now at the bottom of the screen you see this is for player 1. What is that? So I'll hit up twice down is down twice left, right. I'm going to use space for select enter for start. I'm going to do S for B, X for rapid, A for A and Z for rapid. And I'm done. And now I just reconfigured and you would do the same thing. Alt Shift and two on the number pad or not on the number row for player 2. I'll escape to get out of that. So that was base 64. And again, I use base 64 so that I could paste it into a pay spin command and hopefully not have a file size limit, which luckily it did all fit. What's another option? So another option would be making a self extracting shell script, which I've talked about in the past. I've already started a script here. Let me go ahead. It's called Mario. Make sure that I'm clicked on this window. There we go. I'll use Vim as my text there, Mario.sh. And right here, what I have is, I have my shebang line and an empty line just because I like spacing there. And then we're going to create a variable called rom. I called it with a capital R, R-O-M. I don't know why I did that. But rom. And then we're using the awk command here. So what we're doing here, let me explain this. So $0 is the variable meaning look at this file. So we're running an awk command. We're using, we have back ticks here, which is saying that all this is a command and we're going to take the output of this command and put it into rom. We're saying awk. Look for a line that carrot symbol here says that begins with this, which we have in this particular file that we're in. And print the line number that it's on and then exit out of awk. And so we're doing that file. We're looking at the current file we're in and looking for this line and getting the line number, which in this case is 6. Then we're going to say tail, which means give me the end of this file. And we're going to say n plus and whatever number we got here. So we're going to take it and it's going to, and again, $0 means this current file. So it's going to say look at this file and grab everything after line 6. Okay. And we have dumped that into a zip file and then we're going to exit out before it continues down this. So what we're going to do here now it's very, very important. There's no extra lines in this. So like if I have this, I have that blank line there that will screw everything up. That's why good text editors like Vim will show you, see how we have the squiggly lines here? That means these aren't lines. But the fact that there's no squiggly line here means that's a line, which means I need to come down here and I need to delete that line because if any empty line there, it's going to mess things up. So we'll save that. And what do I need to do now? Well, now I just need to put that binary file into our shell script. So if I was to echo again, our Mario dot zip file, sorry not echo, cat it out. Of course, we get our binary again. If that messes things up for you, just type reset. What I'm going to do is I'm going to take that, I'm going to cat that out. And I'm just going to say greater than greater. That means append it to the file. We're going to append that to our Mario SH file. Now if I open up Mario SH, so our script file, you'll see that after our archive below is the binary for the Mario file. So that's that. Now I can quit out of this. And you would make this executable if you haven't already. And now if I dot slash that file, what it's done is it's created this m zip, because we dumped that with that the bottom of that files is and if we do file dot m zip, you'll see that it says it's a zip archive. If it doesn't, then you did something wrong. And of course, we can run our emulator pointed at that. Oops, zip. And there we go. We can quit out and we could probably even put that into our Mario dot SH file. So let's go back up here. Med Fenn, I think is the name of the file. So dot zip. Now if I run my shell script, it will extract it and run it. So why didn't I do that here? Because that actually gives you a smaller file. So for example, if I was to come here, and I was to W get, whoops, W get, that's a comment from my video, W get this URL, I'll put it to I'll just call it m dot SH. Now let's compare our two scripts. We'll just do let's just do list. Yeah, in a list format. So we have this script here, and this script here, and you'll see that the one from Payspin is bigger. And again, because that's because we used base 64, which is going to give you a larger file than the original binary. So if you're looking for file size, just embedding the zip file is going to save you some size. Let's do go ahead and do that in human readable. And you can see it's 42 kilobytes compared to 31 kilobytes. So definitely embedding it is going to give you, especially as the files get larger, small file. But why did I choose to do the base 64? Well, let me go ahead and you know, cat out our one that has the binary embedded in it. And I'll put that into my clipboard. And then I'll come over here to Payspin. Give a second, then I'll paste it in here. Look, that messes it up. So I can't just post that as text. If I was putting on GitHub or something like that, that'd be fine. But putting it here into a text thing, it's not going to work. That's corrupted file because we're looking at ASCII characters here and we're looking at things that are not ASCII. So that's why I decided to do the base 64. And that was the whole point of this project to see, you know, could I actually post a game into Payspin, you know, the game itself, embedded in it or the ROM itself. So those are two options that you could do. And yeah, that's pretty much it for this tutorial. Just talking about it, looking it over. And if you have any questions, let me know. I'll try to link to these scripts. Well, I'll try to link to the original, the base 64 script on Payspin in the description of this video. So I do thank you for watching. Please check out my website FilmsByChris.com. That's Chris the K. And as always, I hope that you have a great day.