Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.42 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3. #include <iostream>
  4. #include <Windows.h>
  5. #include <cstdint>
  6.  
  7. int main() {
  8.     std::ofstream writeFile;
  9.     std::ofstream binaryWrite;
  10.     std::string fullPath = "C:/Users/Nick/Desktop/pongSDDK/x64/Release"; //set this differently per project of course
  11.     std::string programPath = "program.trash";
  12.     char* memblock;
  13.     int fullSize;
  14.     writeFile.open(programPath.c_str());
  15.     int sceneNum = 1;
  16.     writeFile << sceneNum << '\n';
  17.     int imageNum = 0;
  18.     writeFile << imageNum << '\n';
  19.     int soundNum = 0;
  20.     writeFile << soundNum << '\n';
  21.     int musicNum = 0;
  22.     writeFile << musicNum << '\n';
  23.     if(imageNum > 0) {
  24.         long long int* imageStart = new long long int[imageNum];
  25.         std::string* imagePath = new std::string[imageNum];
  26.         //image paths set here
  27.         for(int a = 0; a < imageNum; ++a) {
  28.             std::string getInput;
  29.             std::string arg = "python ";
  30.             arg += fullPath;
  31.             arg += "writeFile.py ";
  32.             arg += imagePath[a];
  33.             LPCTSTR argument = arg.c_str();
  34.             ShellExecute(NULL, "open", "cmd.exe", argument, NULL, SW_SHOWNORMAL);
  35.             while (getInput != "done") {
  36.                 std::cout << "input 'done' when finished: ";
  37.                 std::cin >> getInput;
  38.             }
  39.             imagePath[imagePath[a].size() - 3] = 'a';
  40.             imagePath[imagePath[a].size() - 2] = 'r';
  41.             imagePath[imagePath[a].size() - 1] = 't';
  42.         }
  43.         for(int a = 0; a < imageNum; ++a) {
  44.             imageStart[a] = 0;
  45.             for(int b = 0; b < a; ++b) {
  46.                 std::ifstream readFile(imagePath[b].c_str(), std::ios::ate | std::ios::binary);
  47.                 imageStart[a] += readFile.tellg();
  48.                 readFile.close();
  49.                 readFile.clear();
  50.             }
  51.         }
  52.         for(int a = 0; a < imageNum; ++a) {
  53.             writeFile << imageStart[a] << '\n';
  54.         }
  55.         //run image bundling function here
  56.         long long int* imageSize = new long long int[imageNum];
  57.         fullSize = 0;
  58.         for(int a = 0; a < imageNum; ++a) {
  59.             std::ifstream readFile(imagePath[a].c_str(), std::ios::ate | std::ios::binary);
  60.             imageSize[a] = readFile.tellg();
  61.             fullSize += imageSize[a];
  62.             readFile.close();
  63.             readFile.clear();
  64.         }
  65.         memblock = new char[fullSize];
  66.         int imagePos = 0;
  67.         for(int a = 0; a < imageNum; ++a) {
  68.             std::ifstream readFile(imagePath[a].c_str(), std::ios::beg | std::ios::binary);
  69.             char* imageBlock = new char[imageSize[a]];
  70.             readFile.read(imageBlock, imageSize[a]);
  71.             readFile.close();
  72.             readFile.clear();
  73.             for(int b = 0; b < imageSize[a]; ++b) {
  74.                 memblock[imagePos] = imageBlock[b];
  75.                 ++imagePos;
  76.             }
  77.             delete[] imageBlock;
  78.         }
  79.         binaryWrite.open("art.violent", std::ios::beg | std::ios::binary);
  80.         binaryWrite.write(memblock, fullSize);
  81.         binaryWrite.close();
  82.         binaryWrite.clear();
  83.         delete[] imageSize;
  84.         delete[] memblock;
  85.         delete[] imageStart;
  86.         delete[] imagePath;
  87.         fullSize = 0;
  88.     }
  89.     long long int* sceneStart = new long long int[sceneNum];
  90.     std::string* scenePath = new std::string[sceneNum];
  91.     scenePath[0] = "scene0.scene";
  92.     for (int a = 0; a < sceneNum; ++a) {
  93.         binaryWrite.open(scenePath[a].c_str(), std::ios::beg | std::ios::binary);
  94.         uint8_t sceneImageNum = 0;
  95.         binaryWrite.write((char*)sceneImageNum, sizeof(uint8_t));
  96.         uint8_t sceneSoundNum = 0;
  97.         binaryWrite.write((char*)sceneSoundNum, sizeof(uint8_t));
  98.         uint8_t sceneMusicNum = 0;
  99.         binaryWrite.write((char*)sceneMusicNum, sizeof(uint8_t));
  100.         uint8_t sceneFontNum = 0;
  101.         binaryWrite.write((char*)sceneFontNum, sizeof(uint8_t));
  102.         uint8_t sceneTextNum = 0;
  103.         binaryWrite.write((char*)sceneTextNum, sizeof(uint8_t));
  104.         uint8_t sceneSpriteNum = 0;
  105.         binaryWrite.write((char*)sceneSpriteNum, sizeof(uint8_t));
  106.         if(sceneImageNum > 0) {
  107.             std::string* sceneImageName = new std::string[sceneImageNum];
  108.             //fill in sceneImageName here
  109.             uint16_t* imageIndex = new uint16_t[sceneImageNum];
  110.             //fill in the index of where the images would be in the big bundle file
  111.             for(int b = 0; b < sceneImageNum; ++b) {
  112.                 binaryWrite.write(sceneImageName[b].c_str(), sizeof(std::string));
  113.                 binaryWrite.write((char*)imageIndex[b], sizeof(uint16_t));
  114.             }
  115.             delete[] sceneImageName;
  116.             delete[] imageIndex;
  117.         }
  118.         if(sceneSpriteNum > 0) {
  119.             std::string* spriteImageName = new std::string[sceneSpriteNum];
  120.             //fill in spriteImageName array here
  121.             for(int b = 0; b < sceneSpriteNum; ++b) {
  122.                 binaryWrite.write(spriteImageName[b].c_str(), sizeof(std::string));
  123.             }
  124.             delete[] spriteImageName;
  125.         }
  126.         if(sceneSoundNum > 0) {
  127.             uint16_t* soundIndex = new uint16_t[sceneSoundNum];
  128.             //fill in soundIndex here
  129.             for(int b = 0; b < sceneSoundNum; ++b) {
  130.                 binaryWrite.write((char*)soundIndex, sizeof(uint16_t));
  131.             }
  132.             delete[] soundIndex;
  133.         }
  134.         if(sceneMusicNum > 0) {
  135.             uint16_t* musicIndex = new uint16_t[sceneMusicNum];
  136.             //fill in musicIndex here
  137.             for(int b = 0; b < sceneMusicNum; ++b) {
  138.                 binaryWrite.write((char*)musicIndex, sizeof(uint16_t));
  139.             }
  140.             delete[] musicIndex;
  141.         }
  142.         if(sceneFontNum > 0) {
  143.             uint8_t* r = new uint8_t[sceneFontNum];
  144.             uint8_t* g = new uint8_t[sceneFontNum];
  145.             uint8_t* blue = new uint8_t[sceneFontNum];
  146.             uint8_t* charSize = new uint8_t[sceneFontNum];
  147.             std::string* fontPath = new std::string[sceneFontNum];
  148.             //fill in all of these arrays here
  149.             for(int b = 0; b < sceneFontNum; ++b) {
  150.                 binaryWrite.write((char*)r[b], sizeof(uint8_t));
  151.                 binaryWrite.write((char*)g[b], sizeof(uint8_t));
  152.                 binaryWrite.write((char*)blue[b], sizeof(uint8_t));
  153.                 binaryWrite.write((char*)charSize[b], sizeof(uint8_t));
  154.                 binaryWrite.write(fontPath[b].c_str(), sizeof(std::string));
  155.             }
  156.             delete[] r;
  157.             delete[] g;
  158.             delete[] blue;
  159.             delete[] charSize;
  160.             delete[] fontPath;
  161.         }
  162.         if(sceneTextNum > 0) {
  163.             uint8_t* textFontIndex = new uint8_t[sceneTextNum];
  164.             std::string* textLine = new std::string[sceneTextNum];
  165.             //fill in both arrays here
  166.             for(int b = 0; b < sceneTextNum; ++b) {
  167.                 binaryWrite.write((char*)textFontIndex[b], sizeof(uint8_t));
  168.                 binaryWrite.write(textLine[b].c_str(), sizeof(std::string));
  169.             }
  170.             delete[] textFontIndex;
  171.             delete[] textLine;
  172.         }
  173.         binaryWrite.close();
  174.         binaryWrite.clear();
  175.         sceneStart[a] = 0;
  176.         for (int b = 0; b < a; ++b) {
  177.             std::ifstream readFile(scenePath[b].c_str(), std::ios::ate | std::ios::binary);
  178.             sceneStart[a] += readFile.tellg();
  179.             readFile.close();
  180.             readFile.clear();
  181.         }
  182.     }
  183.     for (int a = 0; a < sceneNum; ++a) {
  184.         writeFile << sceneStart[a] << '\n';
  185.     }
  186.     //bundle scene files here
  187.     long long int* sceneSize = new long long int[sceneNum];
  188.     for(int a = 0; a < sceneNum; ++a) {
  189.         std::ifstream readFile(scenePath[a].c_str(), std::ios::ate | std::ios::binary);
  190.         sceneSize[a] = readFile.tellg();
  191.         fullSize += sceneSize[a];
  192.         readFile.close();
  193.         readFile.clear();
  194.     }
  195.     memblock = new char[fullSize];
  196.     int scenePos = 0;
  197.     for(int a = 0; a < sceneNum; ++a) {
  198.         std::ifstream readFile(scenePath[a].c_str(), std::ios::beg | std::ios::binary);
  199.         char* sceneBlock = new char[sceneSize[a]];
  200.         readFile.read(sceneBlock, sceneSize[a]);
  201.         readFile.close();
  202.         readFile.clear();
  203.         for(int b = 0; b < sceneSize[a]; ++b) {
  204.             memblock[scenePos] = sceneBlock[b];
  205.             ++scenePos;
  206.         }
  207.         delete[] sceneBlock;
  208.     }
  209.     binaryWrite.open("scene.violent", std::ios::beg | std::ios::binary);
  210.     binaryWrite.write(memblock, fullSize);
  211.     binaryWrite.close();
  212.     binaryWrite.clear();
  213.     delete[] sceneSize;
  214.     delete[] memblock;
  215.     delete[] sceneStart;
  216.     delete[] scenePath;
  217.     fullSize = 0;
  218.     if(soundNum > 0) {
  219.         long long int* soundStart = new long long int[soundNum];
  220.         long long int* soundSize = new long long int[soundNum];
  221.         std::string* soundPath = new std::string[soundNum];
  222.         //sound paths set here
  223.         for(int a = 0; a < soundNum; ++a) {
  224.             soundStart[a] = 0;
  225.             for(int b = 0; b < a; ++b) {
  226.                 std::ifstream readFile(soundPath[a].c_str(), std::ios::ate | std::ios::binary);
  227.                 soundSize[a] = readFile.tellg();
  228.                 soundStart[a] += soundSize[a];
  229.                 readFile.close();
  230.                 readFile.clear();
  231.             }
  232.         }
  233.         for(int a = 0; a < soundNum; ++a) {
  234.             writeFile << soundStart[a] << '\n';
  235.             writeFile << soundSize[a] << '\n';
  236.         }
  237.         //bundle sound files here
  238.         for(int a = 0; a < soundNum; ++a) {
  239.             fullSize += soundSize[a];
  240.         }
  241.         memblock = new char[fullSize];
  242.         int soundPos = 0;
  243.         for(int a = 0; a < soundNum; ++a) {
  244.             std::ifstream readFile(soundPath[a].c_str(), std::ios::beg | std::ios::binary);
  245.             char* soundBlock = new char[soundSize[a]];
  246.             readFile.read(soundBlock, soundSize[a]);
  247.             readFile.close();
  248.             readFile.clear();
  249.             for(int b = 0; b < soundSize[a]; ++b) {
  250.                 memblock[soundPos] = soundBlock[b];
  251.                 ++soundPos;
  252.             }
  253.             delete[] soundBlock;
  254.         }
  255.         binaryWrite.open("sound.violent", std::ios::beg | std::ios::binary);
  256.         binaryWrite.write(memblock, fullSize);
  257.         binaryWrite.close();
  258.         binaryWrite.clear();
  259.         delete[] memblock;
  260.         delete[] soundStart;
  261.         delete[] soundSize;
  262.         delete[] soundPath;
  263.         fullSize = 0;
  264.     }
  265.     if(musicNum > 0) {
  266.         long long int* musicStart = new long long int[musicNum];
  267.         long long int* musicSize = new long long int[musicNum];
  268.         std::string* musicPath = new std::string[musicNum];
  269.         //music paths set here
  270.         for(int a = 0; a < musicNum; ++a) {
  271.             musicStart[a] = 0;
  272.             for(int b = 0; b < a; ++b) {
  273.                 std::ifstream readFile(musicPath[a].c_str(), std::ios::ate | std::ios::binary);
  274.                 musicSize[a] = readFile.tellg();
  275.                 musicStart[a] += musicSize[a];
  276.                 readFile.close();
  277.                 readFile.clear();
  278.             }
  279.         }
  280.         for(int a = 0; a < musicNum; ++a) {
  281.             writeFile << musicStart[a] << '\n';
  282.             writeFile << musicSize[a] << '\n';
  283.         }
  284.         //bundle music files here
  285.         for(int a = 0; a < musicNum; ++a) {
  286.             fullSize += musicSize[a];
  287.         }
  288.         memblock = new char[fullSize];
  289.         int musicPos = 0;
  290.         for(int a = 0; a < musicNum; ++a) {
  291.             std::ifstream readFile(musicPath[a].c_str(), std::ios::beg | std::ios::binary);
  292.             char* musicBlock = new char[musicSize[a]];
  293.             readFile.read(musicBlock, musicSize[a]);
  294.             readFile.close();
  295.             readFile.clear();
  296.             for(int b = 0; b < musicSize[a]; ++b) {
  297.                 memblock[musicPos] = musicBlock[b];
  298.                 ++musicPos;
  299.             }
  300.             delete[] musicBlock;
  301.         }
  302.         binaryWrite.open("music.violent", std::ios::beg | std::ios::binary);
  303.         binaryWrite.write(memblock, fullSize);
  304.         binaryWrite.close();
  305.         binaryWrite.clear();
  306.         delete[] memblock;
  307.         delete[] musicPath;
  308.         delete[] musicStart;
  309.         delete[] musicSize;
  310.         fullSize = 0;
  311.     }
  312.     int functionNum = 1;
  313.     writeFile << functionNum << '\n';
  314.     std::string* functionID = new std::string[functionNum];
  315.     functionID[0] = "pong scene";
  316.     for(int a = 0; a < functionNum; ++a) {
  317.         writeFile << functionID[a] << '\n';
  318.     }
  319.     writeFile.close();
  320.     writeFile.clear();
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement