Jump to content

  • Log In with Google      Sign In   
  • Create Account


Byproduct of Insomnia

  • You cannot reply to this topic
7 replies to this topic

#1 kd7tck   Members   -  Reputation: 715

Like
7Likes
Like

Posted 19 July 2013 - 01:25 AM

This one needs a little explaining. A while back I was in the middle of a major life crisis and things where looking real bad for me, in a nutshell I couldn't sleep. I was put on ambien by my doctor, and found I did not go to sleep while on it. Instead I turned into a zombie of a person that walked into walls ocassionally. This is something I coded while awake on ambien.

//-----Generate Self Extracting patch installer----->
	if(generatePatch && numDiffs > 0){//-b flag
		//construct base source files
		system("mkdir /tmp/builder");
		system("echo '#include <stdio.h>' > /tmp/builder/headers.c");
		system("echo '#include <stdlib.h>' >> /tmp/builder/headers.c");
		system("echo \" \" >> /tmp/builder/headers.c");//space

		system("echo \" \" > /tmp/builder/decompile.c");//space
		system("echo 'int main(){' >> /tmp/builder/decompile.c");
		system("echo 'FILE *fp = fopen(\"TMP.tar.gz\",\"wb\");' >> /tmp/builder/decompile.c");
		system("echo 'fwrite(xxx, sizeof(xxx[0]), sizeof xxx/sizeof(xxx[0]), fp);' >> /tmp/builder/decompile.c");
		system("echo 'fclose(fp);' >> /tmp/builder/decompile.c");

		//do any additional installation work here-->
		system("ST=\\\"\necho \"system(${ST}> .install.py${ST});//create installer script\" >> /tmp/builder/decompile.c");//create script file
			//write python install script here-->
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'from Tkinter import * ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'from tkFileDialog import askdirectory ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'import os ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'def askd(): ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '	dir1 = askdirectory() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '	if dir1: ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		print ${STT}Directory ${STT} + dir1 + ${STT} Will Be Patched.${STT}' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		os.system(${STT}tar -zxf ./TMP.tar.gz -C .${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		os.system(${STT}mv -f .gamepatch.diff* ${STT} + dir1) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		os.system(${STT}rm ./TMP.tar.gz${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		os.system(${STT}cd dir1\\\\\\\ngamepatch -p 10000${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//patch system to latest patch
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		quit() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//exit tkinter
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		exit() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//exit python
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top = Frame() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top.pack() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'Label(top, text=${STT}${STT}${STT}This patch is only designed for a specific game. ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'Do Not Use If Unsure What Game This Is For! ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '${STT}${STT}${STT}).pack(side=TOP) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'widget = Button(top, text=${STT}Choose Game Directory To Patch${STT}, command=askd) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'widget.pack(side=BOTTOM) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top.mainloop() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			//---------------------------------->
		system("ST=\\\"\necho \"system(${ST}gnome-terminal -e 'python ./.install.py'${ST});\" >> /tmp/builder/decompile.c");//run script file
		system("ST=\\\"\necho \"system(${ST}rm .install.py${ST});\" >> /tmp/builder/decompile.c");//remove script file
		//------------------------------------------>

		system("echo 'return 0;}' >> /tmp/builder/decompile.c");


		//build and merge source files
		system("tar -zcf /tmp/builder/TMP.tar.gz .gamepatch.diff*");
		system("cat /tmp/builder/TMP.tar.gz | ( echo \"unsigned char xxx[] = {\"; xxd -i; echo \"};\" ) > /tmp/builder/output_file.c");
		system("cat /tmp/builder/headers.c /tmp/builder/output_file.c /tmp/builder/decompile.c > /tmp/builder/builder.c");
		

		//compile source file
		if(path==NULL){
			system("gcc /tmp/builder/builder.c -o ./patcher");
		}
		else{
			sprintf(buffer, "%s%s","gcc /tmp/builder/builder.c -o ",path);
			system(buffer);
		}
		printf("\n-->Patch Installer Has Been Generated\n");
	}
	//-------------------------------------------------->


Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 7010

Like
3Likes
Like

Posted 19 July 2013 - 04:39 AM

Is that.. a system call in a system call in an interpreted system call via a spawned terminal? +_+


"The best comment is a deleted comment."


#3 HumanCatfood   Members   -  Reputation: 203

Like
0Likes
Like

Posted 19 July 2013 - 08:16 AM

Oh god. The escaping escape-escapes. They're escaped! Again!! .. it's literally making my eyes water..

 

I hope you're crisis improves soon! *man-hug*



#4 Paradigm Shifter   Crossbones+   -  Reputation: 4784

Like
2Likes
Like

Posted 19 July 2013 - 09:12 AM

Well that's a good use-case for a macro and the string literal concatenation which is done by the preprocessor.

 

#define PREAMBLE "STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '"

 

Then you can do system(PREAMBLE "rest of stuff");

 

You don't even need an operator!


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#5 Promit   Moderators   -  Reputation: 4673

Like
1Likes
Like

Posted 19 July 2013 - 09:50 AM

One of the mistakes people make with Ambien is not immediately going to and staying in bed. If you take it and stay up, most people go into crazy mode and start doing a lot of weird things. I saw a thread once about the stuff people have done while on ambien. It's an oddball.


Edited by Promit, 19 July 2013 - 09:50 AM.


#6 kd7tck   Members   -  Reputation: 715

Like
1Likes
Like

Posted 19 July 2013 - 11:02 AM

One of the mistakes people make with Ambien is not immediately going to and staying in bed. If you take it and stay up, most people go into crazy mode and start doing a lot of weird things. I saw a thread once about the stuff people have done while on ambien. It's an oddball.

 

Well that's a good use-case for a macro and the string literal concatenation which is done by the preprocessor.

 

#define PREAMBLE "STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '"

 

Then you can do system(PREAMBLE "rest of stuff");

 

You don't even need an operator!

 

Very true, now that I'm off the med, I realize how crazy most of my coding was during those couple of months. I am under the firm belief that most new game companies fail because they push their employees too hard and don't let them sleep enough.



#7 EricFinlay   Members   -  Reputation: 112

Like
1Likes
Like

Posted 23 July 2013 - 01:14 AM

Yo dawg, I heard you like escapes...

 

But seriously, personally I've made a commitment to 8 hours of sleep a night and my productivity has gone through the roof.  It can't be ignored.


Eric Finlay

http://www.foosler.com - Win Big.  On the Go.


#8 Bacterius   Crossbones+   -  Reputation: 7010

Like
1Likes
Like

Posted 23 July 2013 - 02:32 AM

Yo dawg, I heard you like escapes...

 

But seriously, personally I've made a commitment to 8 hours of sleep a night and my productivity has gone through the roof.  It can't be ignored.

 

Staying up late to get more done is so tempting though unsure.png


"The best comment is a deleted comment."






PARTNERS