Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <string>
- #include <iostream>
- #include <Windows.h>
- #include <cstdint>
- int main() {
- std::ofstream writeFile;
- std::ofstream binaryWrite;
- std::string fullPath = "C:/Users/Nick/Desktop/pongSDDK/x64/Release"; //set this differently per project of course
- std::string programPath = "program.trash";
- char* memblock;
- int fullSize;
- writeFile.open(programPath.c_str());
- int sceneNum = 1;
- writeFile << sceneNum << '\n';
- int imageNum = 0;
- writeFile << imageNum << '\n';
- int soundNum = 0;
- writeFile << soundNum << '\n';
- int musicNum = 0;
- writeFile << musicNum << '\n';
- if(imageNum > 0) {
- long long int* imageStart = new long long int[imageNum];
- std::string* imagePath = new std::string[imageNum];
- //image paths set here
- for(int a = 0; a < imageNum; ++a) {
- std::string getInput;
- std::string arg = "python ";
- arg += fullPath;
- arg += "writeFile.py ";
- arg += imagePath[a];
- LPCTSTR argument = arg.c_str();
- ShellExecute(NULL, "open", "cmd.exe", argument, NULL, SW_SHOWNORMAL);
- while (getInput != "done") {
- std::cout << "input 'done' when finished: ";
- std::cin >> getInput;
- }
- imagePath[imagePath[a].size() - 3] = 'a';
- imagePath[imagePath[a].size() - 2] = 'r';
- imagePath[imagePath[a].size() - 1] = 't';
- }
- for(int a = 0; a < imageNum; ++a) {
- imageStart[a] = 0;
- for(int b = 0; b < a; ++b) {
- std::ifstream readFile(imagePath[b].c_str(), std::ios::ate | std::ios::binary);
- imageStart[a] += readFile.tellg();
- readFile.close();
- readFile.clear();
- }
- }
- for(int a = 0; a < imageNum; ++a) {
- writeFile << imageStart[a] << '\n';
- }
- //run image bundling function here
- long long int* imageSize = new long long int[imageNum];
- fullSize = 0;
- for(int a = 0; a < imageNum; ++a) {
- std::ifstream readFile(imagePath[a].c_str(), std::ios::ate | std::ios::binary);
- imageSize[a] = readFile.tellg();
- fullSize += imageSize[a];
- readFile.close();
- readFile.clear();
- }
- memblock = new char[fullSize];
- int imagePos = 0;
- for(int a = 0; a < imageNum; ++a) {
- std::ifstream readFile(imagePath[a].c_str(), std::ios::beg | std::ios::binary);
- char* imageBlock = new char[imageSize[a]];
- readFile.read(imageBlock, imageSize[a]);
- readFile.close();
- readFile.clear();
- for(int b = 0; b < imageSize[a]; ++b) {
- memblock[imagePos] = imageBlock[b];
- ++imagePos;
- }
- delete[] imageBlock;
- }
- binaryWrite.open("art.violent", std::ios::beg | std::ios::binary);
- binaryWrite.write(memblock, fullSize);
- binaryWrite.close();
- binaryWrite.clear();
- delete[] imageSize;
- delete[] memblock;
- delete[] imageStart;
- delete[] imagePath;
- fullSize = 0;
- }
- long long int* sceneStart = new long long int[sceneNum];
- std::string* scenePath = new std::string[sceneNum];
- scenePath[0] = "scene0.scene";
- for (int a = 0; a < sceneNum; ++a) {
- binaryWrite.open(scenePath[a].c_str(), std::ios::beg | std::ios::binary);
- uint8_t sceneImageNum = 0;
- binaryWrite.write((char*)sceneImageNum, sizeof(uint8_t));
- uint8_t sceneSoundNum = 0;
- binaryWrite.write((char*)sceneSoundNum, sizeof(uint8_t));
- uint8_t sceneMusicNum = 0;
- binaryWrite.write((char*)sceneMusicNum, sizeof(uint8_t));
- uint8_t sceneFontNum = 0;
- binaryWrite.write((char*)sceneFontNum, sizeof(uint8_t));
- uint8_t sceneTextNum = 0;
- binaryWrite.write((char*)sceneTextNum, sizeof(uint8_t));
- uint8_t sceneSpriteNum = 0;
- binaryWrite.write((char*)sceneSpriteNum, sizeof(uint8_t));
- if(sceneImageNum > 0) {
- std::string* sceneImageName = new std::string[sceneImageNum];
- //fill in sceneImageName here
- uint16_t* imageIndex = new uint16_t[sceneImageNum];
- //fill in the index of where the images would be in the big bundle file
- for(int b = 0; b < sceneImageNum; ++b) {
- binaryWrite.write(sceneImageName[b].c_str(), sizeof(std::string));
- binaryWrite.write((char*)imageIndex[b], sizeof(uint16_t));
- }
- delete[] sceneImageName;
- delete[] imageIndex;
- }
- if(sceneSpriteNum > 0) {
- std::string* spriteImageName = new std::string[sceneSpriteNum];
- //fill in spriteImageName array here
- for(int b = 0; b < sceneSpriteNum; ++b) {
- binaryWrite.write(spriteImageName[b].c_str(), sizeof(std::string));
- }
- delete[] spriteImageName;
- }
- if(sceneSoundNum > 0) {
- uint16_t* soundIndex = new uint16_t[sceneSoundNum];
- //fill in soundIndex here
- for(int b = 0; b < sceneSoundNum; ++b) {
- binaryWrite.write((char*)soundIndex, sizeof(uint16_t));
- }
- delete[] soundIndex;
- }
- if(sceneMusicNum > 0) {
- uint16_t* musicIndex = new uint16_t[sceneMusicNum];
- //fill in musicIndex here
- for(int b = 0; b < sceneMusicNum; ++b) {
- binaryWrite.write((char*)musicIndex, sizeof(uint16_t));
- }
- delete[] musicIndex;
- }
- if(sceneFontNum > 0) {
- uint8_t* r = new uint8_t[sceneFontNum];
- uint8_t* g = new uint8_t[sceneFontNum];
- uint8_t* blue = new uint8_t[sceneFontNum];
- uint8_t* charSize = new uint8_t[sceneFontNum];
- std::string* fontPath = new std::string[sceneFontNum];
- //fill in all of these arrays here
- for(int b = 0; b < sceneFontNum; ++b) {
- binaryWrite.write((char*)r[b], sizeof(uint8_t));
- binaryWrite.write((char*)g[b], sizeof(uint8_t));
- binaryWrite.write((char*)blue[b], sizeof(uint8_t));
- binaryWrite.write((char*)charSize[b], sizeof(uint8_t));
- binaryWrite.write(fontPath[b].c_str(), sizeof(std::string));
- }
- delete[] r;
- delete[] g;
- delete[] blue;
- delete[] charSize;
- delete[] fontPath;
- }
- if(sceneTextNum > 0) {
- uint8_t* textFontIndex = new uint8_t[sceneTextNum];
- std::string* textLine = new std::string[sceneTextNum];
- //fill in both arrays here
- for(int b = 0; b < sceneTextNum; ++b) {
- binaryWrite.write((char*)textFontIndex[b], sizeof(uint8_t));
- binaryWrite.write(textLine[b].c_str(), sizeof(std::string));
- }
- delete[] textFontIndex;
- delete[] textLine;
- }
- binaryWrite.close();
- binaryWrite.clear();
- sceneStart[a] = 0;
- for (int b = 0; b < a; ++b) {
- std::ifstream readFile(scenePath[b].c_str(), std::ios::ate | std::ios::binary);
- sceneStart[a] += readFile.tellg();
- readFile.close();
- readFile.clear();
- }
- }
- for (int a = 0; a < sceneNum; ++a) {
- writeFile << sceneStart[a] << '\n';
- }
- //bundle scene files here
- long long int* sceneSize = new long long int[sceneNum];
- for(int a = 0; a < sceneNum; ++a) {
- std::ifstream readFile(scenePath[a].c_str(), std::ios::ate | std::ios::binary);
- sceneSize[a] = readFile.tellg();
- fullSize += sceneSize[a];
- readFile.close();
- readFile.clear();
- }
- memblock = new char[fullSize];
- int scenePos = 0;
- for(int a = 0; a < sceneNum; ++a) {
- std::ifstream readFile(scenePath[a].c_str(), std::ios::beg | std::ios::binary);
- char* sceneBlock = new char[sceneSize[a]];
- readFile.read(sceneBlock, sceneSize[a]);
- readFile.close();
- readFile.clear();
- for(int b = 0; b < sceneSize[a]; ++b) {
- memblock[scenePos] = sceneBlock[b];
- ++scenePos;
- }
- delete[] sceneBlock;
- }
- binaryWrite.open("scene.violent", std::ios::beg | std::ios::binary);
- binaryWrite.write(memblock, fullSize);
- binaryWrite.close();
- binaryWrite.clear();
- delete[] sceneSize;
- delete[] memblock;
- delete[] sceneStart;
- delete[] scenePath;
- fullSize = 0;
- if(soundNum > 0) {
- long long int* soundStart = new long long int[soundNum];
- long long int* soundSize = new long long int[soundNum];
- std::string* soundPath = new std::string[soundNum];
- //sound paths set here
- for(int a = 0; a < soundNum; ++a) {
- soundStart[a] = 0;
- for(int b = 0; b < a; ++b) {
- std::ifstream readFile(soundPath[a].c_str(), std::ios::ate | std::ios::binary);
- soundSize[a] = readFile.tellg();
- soundStart[a] += soundSize[a];
- readFile.close();
- readFile.clear();
- }
- }
- for(int a = 0; a < soundNum; ++a) {
- writeFile << soundStart[a] << '\n';
- writeFile << soundSize[a] << '\n';
- }
- //bundle sound files here
- for(int a = 0; a < soundNum; ++a) {
- fullSize += soundSize[a];
- }
- memblock = new char[fullSize];
- int soundPos = 0;
- for(int a = 0; a < soundNum; ++a) {
- std::ifstream readFile(soundPath[a].c_str(), std::ios::beg | std::ios::binary);
- char* soundBlock = new char[soundSize[a]];
- readFile.read(soundBlock, soundSize[a]);
- readFile.close();
- readFile.clear();
- for(int b = 0; b < soundSize[a]; ++b) {
- memblock[soundPos] = soundBlock[b];
- ++soundPos;
- }
- delete[] soundBlock;
- }
- binaryWrite.open("sound.violent", std::ios::beg | std::ios::binary);
- binaryWrite.write(memblock, fullSize);
- binaryWrite.close();
- binaryWrite.clear();
- delete[] memblock;
- delete[] soundStart;
- delete[] soundSize;
- delete[] soundPath;
- fullSize = 0;
- }
- if(musicNum > 0) {
- long long int* musicStart = new long long int[musicNum];
- long long int* musicSize = new long long int[musicNum];
- std::string* musicPath = new std::string[musicNum];
- //music paths set here
- for(int a = 0; a < musicNum; ++a) {
- musicStart[a] = 0;
- for(int b = 0; b < a; ++b) {
- std::ifstream readFile(musicPath[a].c_str(), std::ios::ate | std::ios::binary);
- musicSize[a] = readFile.tellg();
- musicStart[a] += musicSize[a];
- readFile.close();
- readFile.clear();
- }
- }
- for(int a = 0; a < musicNum; ++a) {
- writeFile << musicStart[a] << '\n';
- writeFile << musicSize[a] << '\n';
- }
- //bundle music files here
- for(int a = 0; a < musicNum; ++a) {
- fullSize += musicSize[a];
- }
- memblock = new char[fullSize];
- int musicPos = 0;
- for(int a = 0; a < musicNum; ++a) {
- std::ifstream readFile(musicPath[a].c_str(), std::ios::beg | std::ios::binary);
- char* musicBlock = new char[musicSize[a]];
- readFile.read(musicBlock, musicSize[a]);
- readFile.close();
- readFile.clear();
- for(int b = 0; b < musicSize[a]; ++b) {
- memblock[musicPos] = musicBlock[b];
- ++musicPos;
- }
- delete[] musicBlock;
- }
- binaryWrite.open("music.violent", std::ios::beg | std::ios::binary);
- binaryWrite.write(memblock, fullSize);
- binaryWrite.close();
- binaryWrite.clear();
- delete[] memblock;
- delete[] musicPath;
- delete[] musicStart;
- delete[] musicSize;
- fullSize = 0;
- }
- int functionNum = 1;
- writeFile << functionNum << '\n';
- std::string* functionID = new std::string[functionNum];
- functionID[0] = "pong scene";
- for(int a = 0; a < functionNum; ++a) {
- writeFile << functionID[a] << '\n';
- }
- writeFile.close();
- writeFile.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement