// File: /workspace/github_cpp_makefile_star2_O2/UltiRTS[P]gameLauncher/launcher.cpp
// Function: main
int main(int argc,char* argv[]) {
	SDL_Init(SDL_INIT_AUDIO);
	Windows = SDL_CreateWindow("TestString",100,100,600,350,SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS);
	WindowRen = SDL_CreateRenderer(Windows,-1,0);
	// SDL_Event event;
	SDL_SetRenderDrawColor(WindowRen, 0, 255, 255, 255);
	SDL_RenderFillRect(WindowRen, &rect);
/*
	while(true) {
		while (SDL_PollEvent(&event)) {
			if (event.type == SDL_QUIT) {
				SDL_Quit();
				return 0;
			}
		}
	SDL_Delay(2);
	}
	return 0;
*/
	string basePath = getPath(argc, argv);
	string busyboxPath = basePath + "busybox.exe";
	string launcherPath = basePath + "launcher.exe";
	string enginePath = basePath + "Current_Engine-master/spring --menu 'Chobby $VERSION'";
	rollLowerRightCMD("Prob_path active");

	cout << "Checking for update" << endl;
	string updateCMD = busyboxPath + " rm -rf /dev/shm/version.zip &&" + busyboxPath +
		" wget -P /dev/shm http://files.ultirts.net/newrelease/version.zip";
	//get the newest version and avoid writing to the actual disk if possible
	system(updateCMD.c_str());
	//using some simple compression to prevent little hackers
	string readRemoteVerCMD = busyboxPath + " zcat /dev/shm/version.zip";
	//need to get the actual output, risky but have to
	string version = exec(readRemoteVerCMD.c_str());
	//using some simple compression to prevent little hackers
	string readLocalVerCMD = busyboxPath + " zcat " + basePath + "localver";
	//need to get the actual output, risky but have to
	string lVersion = exec(readLocalVerCMD.c_str());
	string localVerPath = basePath + "localver";
	rollLowerRightCMD("Prob_version active");
	//check first run
	if (!exists(localVerPath.c_str())) {
		rollLowerRightCMD("Prob_init_run active");
		string initVer = busyboxPath + " touch " + basePath + "localver";
		system(initVer.c_str()); //initialize the version pool
	}
	if (lVersion.compare(version) != 0) {
		string cpCMD = busyboxPath+" rm "+basePath+"localver &&" + busyboxPath + " mv /dev/shm/version.zip " + basePath + "localver";
		system(cpCMD.c_str()); //get the newest version and avoid writing to the actual disk if possible
		isUpdated = true;
	}
	//isUpdated is from version query
	if (isUpdated) {
		rollLowerRightCMD("Update active");
		string updater = busyboxPath + " wget -P " + basePath +
			" http://files.ultirts.net/newrelease/updater && cd " + basePath +
			" && chmod +Xx * &&" + basePath + "updater";
		system(updater.c_str()); //get the newest version and avoid writing to the actual disk if possible
		cout << "Updated, running new launcher"<<endl;
		system(launcherPath.c_str());
		return 0;
	} else {
		rollLowerRightCMD("Querying default engine");
		cout << "launcher path is "<< basePath<<endl;
		cout << "infering engine path "<< enginePath<<endl;
		SDL_Quit();
		system(enginePath.c_str());
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rsi, %rbx
pushq $0x10
popq %rdi
callq 0x2200
leaq 0x1520(%rip), %rdi      # 0x402c
pushq $0x64
popq %rdx
pushq $0x14
popq %r9
movl %edx, %esi
movl $0x258, %ecx            # imm = 0x258
movl $0x15e, %r8d            # imm = 0x15E
callq 0x2050
movq %rax, 0x3f2c(%rip)      # 0x6a58
pushq $-0x1
popq %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x2040
movq %rax, 0x3f10(%rip)      # 0x6a50
movq %rax, %rdi
xorl %esi, %esi
movl $0xff, %edx
movl $0xff, %ecx
movl $0xff, %r8d
callq 0x22e0
movq 0x3eef(%rip), %rdi      # 0x6a50
leaq 0x36a8(%rip), %rsi      # 0x6210
callq 0x2140
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rdx
callq 0x25dc
leaq 0x14b4(%rip), %rdx      # 0x4037
leaq -0xb0(%rbp), %rdi
movq %r14, %rsi
callq 0x3532
leaq 0x14aa(%rip), %rdx      # 0x4043
leaq -0x2d0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3532
leaq 0x14a0(%rip), %rdx      # 0x4050
leaq -0x1f0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3532
leaq 0x14bf(%rip), %rsi      # 0x4086
leaq -0x2b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x33cc
leaq -0x2b0(%rbp), %rdi
callq 0x27fa
leaq -0x2b0(%rbp), %rdi
callq 0x2100
movq 0x33cf(%rip), %rdi      # 0x5fc8
leaq 0x1497(%rip), %rsi      # 0x4097
callq 0x2230
movq %rax, %rdi
callq 0x2120
leaq 0x1497(%rip), %rdx      # 0x40ab
leaq -0x190(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3532
leaq -0x1b0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x3593
leaq 0x1483(%rip), %rdx      # 0x40cb
leaq -0x1d0(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x356a
leaq -0x1b0(%rbp), %rdi
callq 0x2100
leaq -0x190(%rbp), %rdi
callq 0x2100
movq -0x1d0(%rbp), %rdi
callq 0x21d0
leaq 0x1487(%rip), %rdx      # 0x410d
leaq -0x1b0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3532
movq -0x1b0(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x26c3
leaq 0x1475(%rip), %rdx      # 0x4128
leaq -0x150(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3532
leaq -0x170(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x3593
leaq 0x144b(%rip), %rdx      # 0x412f
leaq -0x290(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x356a
leaq -0x170(%rbp), %rdi
callq 0x2100
leaq -0x150(%rbp), %rdi
callq 0x2100
movq -0x290(%rbp), %rsi
leaq -0x170(%rbp), %rdi
callq 0x26c3
leaq 0x1406(%rip), %rdx      # 0x412f
leaq -0x150(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3532
leaq 0x13f8(%rip), %rsi      # 0x4138
leaq -0x270(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x33cc
leaq -0x270(%rbp), %rdi
callq 0x27fa
leaq -0x270(%rbp), %rdi
callq 0x2100
movq -0x150(%rbp), %rdi
callq 0x2676
testb %al, %al
jne 0x2e14
leaq 0x13c9(%rip), %rsi      # 0x414c
leaq -0x250(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x33cc
leaq -0x250(%rbp), %rdi
callq 0x27fa
leaq -0x250(%rbp), %rdi
callq 0x2100
leaq 0x13af(%rip), %rdx      # 0x4161
leaq -0x70(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3532
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x3593
leaq 0x1352(%rip), %rdx      # 0x412f
leaq -0x30(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x356a
leaq -0x90(%rbp), %rdi
callq 0x2100
leaq -0x70(%rbp), %rdi
callq 0x2100
movq -0x30(%rbp), %rdi
callq 0x21d0
leaq -0x30(%rbp), %rdi
callq 0x2100
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x2030
testl %eax, %eax
je 0x2f34
leaq 0x1333(%rip), %rdx      # 0x4169
leaq -0xd0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3532
leaq -0xf0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x3593
leaq 0x1307(%rip), %rdx      # 0x416e
leaq -0x110(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x356a
leaq -0x130(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x3593
leaq 0x12df(%rip), %rdx      # 0x417a
leaq -0x70(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x356a
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x3593
leaq 0x1269(%rip), %rdx      # 0x412f
leaq -0x30(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x356a
leaq -0x90(%rbp), %rdi
callq 0x2100
leaq -0x70(%rbp), %rdi
callq 0x2100
leaq -0x130(%rbp), %rdi
callq 0x2100
leaq -0x110(%rbp), %rdi
callq 0x2100
leaq -0xf0(%rbp), %rdi
callq 0x2100
leaq -0xd0(%rbp), %rdi
callq 0x2100
movq -0x30(%rbp), %rdi
callq 0x21d0
movb $0x1, 0x3b1e(%rip)      # 0x6a49
leaq -0x30(%rbp), %rdi
callq 0x2100
cmpb $0x1, 0x3b0e(%rip)      # 0x6a49
jne 0x3097
leaq 0x124c(%rip), %rsi      # 0x4194
leaq -0x230(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x33cc
leaq -0x230(%rbp), %rdi
callq 0x27fa
leaq -0x230(%rbp), %rdi
callq 0x2100
leaq 0x122b(%rip), %rdx      # 0x41a2
leaq -0xd0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3532
leaq -0xf0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x3593
leaq 0x1204(%rip), %rdx      # 0x41ac
leaq -0x110(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x356a
leaq -0x130(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x3593
leaq 0x1207(%rip), %rdx      # 0x41e0
leaq -0x70(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x356a
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x3593
leaq 0x11ef(%rip), %rdx      # 0x41f3
leaq -0x30(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x356a
leaq -0x90(%rbp), %rdi
callq 0x2100
leaq -0x70(%rbp), %rdi
callq 0x2100
leaq -0x130(%rbp), %rdi
callq 0x2100
leaq -0x110(%rbp), %rdi
callq 0x2100
leaq -0xf0(%rbp), %rdi
callq 0x2100
leaq -0xd0(%rbp), %rdi
callq 0x2100
movq -0x30(%rbp), %rdi
callq 0x21d0
movq 0x2f5f(%rip), %rdi      # 0x5fc8
leaq 0x118b(%rip), %rsi      # 0x41fb
callq 0x2230
movq %rax, %rdi
callq 0x2120
movq -0x2d0(%rbp), %rdi
callq 0x21d0
leaq -0x30(%rbp), %rdi
callq 0x2100
jmp 0x3128
leaq 0x117b(%rip), %rsi      # 0x4219
leaq -0x210(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x33cc
leaq -0x210(%rbp), %rdi
callq 0x27fa
leaq -0x210(%rbp), %rdi
callq 0x2100
movq 0x2efb(%rip), %rdi      # 0x5fc8
leaq 0x115d(%rip), %rsi      # 0x4231
callq 0x2230
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2120
movq 0x2ed4(%rip), %rdi      # 0x5fc8
leaq 0x1148(%rip), %rsi      # 0x4243
callq 0x2230
leaq -0x1f0(%rbp), %rsi
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x2120
callq 0x2060
movq -0x1f0(%rbp), %rdi
callq 0x21d0
leaq -0x150(%rbp), %rdi
callq 0x2100
leaq -0x170(%rbp), %rdi
callq 0x2100
leaq -0x290(%rbp), %rdi
callq 0x2100
leaq -0x190(%rbp), %rdi
callq 0x2100
leaq -0x1b0(%rbp), %rdi
callq 0x2100
leaq -0x1d0(%rbp), %rdi
callq 0x2100
leaq -0x1f0(%rbp), %rdi
callq 0x2100
leaq -0x2d0(%rbp), %rdi
callq 0x2100
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0x50(%rbp), %rdi
callq 0x2100
xorl %eax, %eax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x3236
jmp 0x3247
jmp 0x3255
jmp 0x3266
jmp 0x3277
jmp 0x3292
jmp 0x334c
movq %rax, %rbx
leaq -0x210(%rbp), %rdi
jmp 0x3340
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
jmp 0x3340
jmp 0x334c
jmp 0x334c
jmp 0x3339
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x2100
jmp 0x320f
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x3340
jmp 0x334c
movq %rax, %rbx
leaq -0x250(%rbp), %rdi
jmp 0x3340
jmp 0x334c
jmp 0x3339
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x2100
jmp 0x324a
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2100
jmp 0x3258
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x2100
jmp 0x3269
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x2100
jmp 0x327a
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x2100
leaq -0xd0(%rbp), %rdi
jmp 0x3340
movq %rax, %rbx
jmp 0x3286
jmp 0x334c
movq %rax, %rbx
leaq -0x270(%rbp), %rdi
jmp 0x3340
jmp 0x334c
movq %rax, %rbx
jmp 0x335b
movq %rax, %rbx
jmp 0x3367
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
callq 0x2100
jmp 0x32d4
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
jmp 0x336e
movq %rax, %rbx
jmp 0x3373
movq %rax, %rbx
jmp 0x337f
jmp 0x32f2
movq %rax, %rbx
jmp 0x338b
movq %rax, %rbx
leaq -0x1b0(%rbp), %rdi
callq 0x2100
jmp 0x330e
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
jmp 0x3392
jmp 0x3347
movq %rax, %rbx
leaq -0x2b0(%rbp), %rdi
jmp 0x3392
jmp 0x3347
movq %rax, %rbx
jmp 0x33a3
movq %rax, %rbx
jmp 0x33af
movq %rax, %rbx
jmp 0x33bb
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x2100
jmp 0x334f
movq %rax, %rbx
jmp 0x3397
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0x2100
leaq -0x170(%rbp), %rdi
callq 0x2100
leaq -0x290(%rbp), %rdi
callq 0x2100
leaq -0x190(%rbp), %rdi
callq 0x2100
leaq -0x1b0(%rbp), %rdi
callq 0x2100
leaq -0x1d0(%rbp), %rdi
callq 0x2100
leaq -0x1f0(%rbp), %rdi
callq 0x2100
leaq -0x2d0(%rbp), %rdi
callq 0x2100
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0x50(%rbp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2360