Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <fstream>
- #include <conio.h>
- #include <stdio.h>
- #include <direct.h>
- #include <string>
- #include "computercraft.h"
- #define GetCurrentDir _getcwd
- #include <sstream>
- Term *term = new Term;
- Color *colors = new Color;
- Paintutils *paintutils = new Paintutils();
- using namespace std;
- bool writeToConf(string file,string cont)
- {
- FILE *oFile;
- oFile = fopen((char*) &file[0],"w");
- if(oFile!=NULL)
- {
- fputs("[sdl] \n",oFile);
- fputs((char*) &cont[0],oFile);
- fclose(oFile);
- return 1;
- }
- return 0;
- }
- string getConf(string file,int line)
- {
- ifstream input( (char*) &file[0] );
- string online;
- int next = 0;
- while( getline( input, online ) ) {
- if(next == line-1) return online;
- next ++;
- }
- return "fail";
- }
- string getWorkingDir(string addto)
- {
- char cCurrentPath[FILENAME_MAX];
- if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
- {
- return "No path";
- }
- cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */
- return string("\"") + cCurrentPath + "\\" + addto + string("\"");
- }
- string getWorkingDir_NoFormat()
- {
- char cCurrentPath[FILENAME_MAX];
- if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
- {
- return "No path";
- }
- cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */
- return cCurrentPath;
- }
- string getWorkingDirSkipPer(string addto)
- {
- char cCurrentPath[FILENAME_MAX];
- if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
- {
- return "No path";
- }
- cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */
- return string(cCurrentPath) + "/" + addto + string("\"");
- }
- bool startdos(string args)
- {
- string fullpath = "Core/DOSbox.exe " + args;
- WinExec((char*) &fullpath[0],SW_NORMAL);
- }
- int opts(int num)
- {
- bool waiting = true;
- int input = 0;
- while (waiting)
- {
- getch();
- if(GetAsyncKeyState('1'))
- {
- waiting = false;
- input = 1;
- break;
- }
- else if(GetAsyncKeyState('2') && num > 1)
- {
- waiting = false;
- input = 2;
- break;
- }
- else if(GetAsyncKeyState('3') && num > 2)
- {
- waiting = false;
- input = 3;
- break;
- }
- else if(GetAsyncKeyState('4') && num > 3)
- {
- waiting = false;
- input = 4;
- break;
- }
- }
- return input;
- }
- bool yesno()
- {
- cout << "Y/n ?" << endl;
- bool waiting = true;
- bool yes = false;
- while (waiting)
- {
- getch();
- if(GetAsyncKeyState('Y') || GetAsyncKeyState('y'))
- {
- waiting = false;
- yes = true;
- break;
- }
- else if(GetAsyncKeyState('N') || GetAsyncKeyState('n'))
- {
- waiting = false;
- break;
- }
- }
- return yes;
- }
- /*
- -c MOUNT C getWorkingDir()\Games\MS-DOS
- -c C:
- -c CD SOFTWARE
- -c imgmount E MECHWA~3.CUE -t iso
- -c imgmount F MERCEN~2.CUE -t iso
- -c CD /
- -c CD MECHTR~1/INVERT~1/INVERTED
- -c CTMOUSEY.EXE
- -c CD /
- -c CD MECHTR~1/MW2-31ST
- -c MECH2.exe
- */
- string mechsupports[1] = {"MW2-31st"};
- bool drawScreen()
- {
- term->setBackgroundColor(colors->black);
- term->Clear();
- term->setBackgroundColor(colors->blue);
- term->setTextColor(colors->white);
- paintutils->drawBoxFilled(30,5,80,25,colors->gray,colors->gray);
- paintutils->drawBoxFilled(30,5,80,5,colors->blue,colors->blue);
- term->setCursorPos(30,5);
- cout << "Welcome to Mech2Dos!" << endl;
- term->setCursorPos(32,8);
- term->setBackgroundColor(colors->gray);
- term->setTextColor(colors->black);
- cout << "Current supported Mechwarrior version(s)" << endl;
- term->setCursorPos(32,10);
- cout << "1. " << mechsupports[0];
- term->setCursorPos(30,13);
- cout << " Options [1-3] " << endl;
- term->setCursorPos(35,14);
- cout << "1. Configure mouse sensitivity - [" << getConf(getWorkingDir_NoFormat() + "\\Core\\custom_sens.txt",2).substr(12) << "]" << endl;
- term->setCursorPos(35,15);
- cout << "2. Start game. " << endl;
- term->setCursorPos(35,16);
- cout << "3. Exit. " << endl;
- term->setCursorBlink(false);
- term->setCursorPos(33,25);
- term->setTextColor(colors->lightGray);
- cout << "Programmed by - Lewisk3 (Redxone, AKA Lewrish). ";
- }
- bool popupmessage(string title, string message)
- {
- term->setBackgroundColor(colors->gray);
- term->setTextColor(colors->white);
- paintutils->drawBoxFilled(42,11,72,17,colors->black,colors->black);
- paintutils->drawBoxFilled(40,11,70,16,colors->lightGray,colors->lightGray);
- paintutils->drawBoxFilled(40,11,70,11,colors->blue,colors->blue);
- term->setCursorPos(40,11);
- cout << "Message: " << title;
- term->setCursorPos(40,13);
- term->setBackgroundColor(colors->lightGray);
- term->setTextColor(colors->black);
- cout << message << endl;
- term->setTextColor(colors->gray);
- term->setCursorPos(40,16);
- cout << "Press any key. ";
- getch();
- return 1;
- }
- double getinput(string title)
- {
- double val;
- term->setBackgroundColor(colors->gray);
- term->setTextColor(colors->white);
- paintutils->drawBoxFilled(42,11,72,17,colors->black,colors->black);
- paintutils->drawBoxFilled(40,11,70,16,colors->lightGray,colors->lightGray);
- paintutils->drawBoxFilled(40,11,70,11,colors->blue,colors->blue);
- term->setCursorPos(40,11);
- cout << title;
- term->setCursorPos(40,13);
- term->setBackgroundColor(colors->lightGray);
- term->setTextColor(colors->black);
- cout << "Enter numeric value here below ";
- term->setCursorPos(42,15);
- term->setBackgroundColor(colors->gray);
- cout << " ";
- term->setTextColor(colors->white);
- term->setCursorPos(42,15);
- cin >> val;
- return val;
- }
- bool getopts()
- {
- switch(opts(3))
- {
- case 1:
- {
- double sens = getinput("Mouse sensitivity");
- if(sens != NULL && sens > 0)
- {
- std::stringstream sstm;
- sstm << "sensitivity=" << sens;
- string stringsens = sstm.str();
- writeToConf(getWorkingDir_NoFormat() + "\\Core\\custom_sens.txt", stringsens);
- popupmessage("Success","Added: " + stringsens);
- drawScreen();
- return getopts();
- }
- else
- {
- drawScreen();
- return getopts();
- }
- }
- break;
- case 2:
- {
- term->setCursorPos(32,18);
- term->setTextColor(colors->black);
- cout << "Start Mechwarrior, MW2_31ST? : ";
- if(yesno())
- {
- cout << "Getting DosBox ready..." << endl;
- string fullargs = "-conf " + getWorkingDir("Core/Default_Config.txt") + " -conf " + getWorkingDir("Core/custom_sens.txt") +
- " -c \"MOUNT C " + getWorkingDirSkipPer("/Games/MS-DOS") +
- " -c C: " + " -c \"CD SOFTWARE\" -c \"imgmount E MECHWA~3.CUE -t iso\" -c \"imgmount F MERCEN~2.CUE -t iso\" -c \"CD /\" -c \"CD MECHTR~1/MW2-31ST\" -c MECH2.exe";
- startdos(fullargs);
- return 1;
- }
- else
- {
- drawScreen();
- return getopts();
- }
- }
- break;
- case 3:
- return 0;
- break;
- default:
- popupmessage("Invalid","Invalid selection.");
- drawScreen();
- return getopts();
- break;
- }
- }
- int main()
- {
- paintutils->initialize(term);
- drawScreen();
- if(!getopts()){
- term->setBackgroundColor(colors->black);
- term->setTextColor(colors->white);
- term->Clear();
- popupmessage("Thank you.","Thank you for using Mech2Dos!");
- return 0;
- };
- cout << "Program has not exited properly, this could be an issue." << endl << "Please contact program developer Lewisk3 (on youtube)" << endl << "Thank you. ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement