1 /*
2 * Open Fodder
3 * ---------------
4 *
5 * Copyright (C) 2008-2018 Open Fodder
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23 #include <iostream>
24 #include <string>
25 #include <vector>
26 #include <fstream>
27 #include <sstream>
28 #include <algorithm>
29 #include <ctime>
30 #include <functional>
31 #include <memory>
32 #include <cstring>
33 #include <cassert>
34 #include <map>
35
36 #include <SDL.h>
37 #ifndef EMSCRIPTEN
38 #include <SDL_mixer.h>
39 #else
40 #include <emscripten.h>
41 #include <SDL/SDL_mixer.h>
42 #endif
43
44 #include "Types.hpp"
45
46 typedef std::shared_ptr<std::vector<uint8>> tSharedBuffer;
47
48 enum eDataType {
49 eData = 0,
50 eSave,
51 eCampaign,
52 eTest,
53 eRoot,
54 eScript,
55 eNone,
56 };
57
58 int start(int argc, char *argv[]);
59 void tool_EndianSwap( uint8* pBuffer, size_t pSize );
60 std::string tool_StripLeadingZero( const std::string& pValue );
61 uint16 tool_DecimalToBinaryCodedDecimal( uint16 pDecimal );
62
63 // Read a BE word from the buffer
readBEWord(const void * buffer)64 inline uint16 readBEWord( const void *buffer ) {
65 const uint8* bytes = (const uint8*) buffer;
66
67 return uint16((bytes[0] << 8) + bytes[1]);
68 }
69
70 // Write a LE word in BE
writeBEWord(const void * buffer,uint16 pValue)71 inline void writeBEWord( const void *buffer, uint16 pValue ) {
72 uint8* bytes = (uint8*) buffer;
73
74 bytes[0] = (uint8) (pValue >> 8);
75 bytes[1] = (uint8) (pValue & 0xFF);
76 }
77
78 // Read a LE DWord in BE
readBEDWord(const void * buffer)79 inline uint32 readBEDWord( const void *buffer ) {
80 const uint8* bytes = (const uint8*) buffer;
81
82 return uint32((bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + (bytes[3]));
83 }
84
85 // Read little endian from the buffer
readLE(const void * pBuffer)86 template <class tRet> inline tRet readLE(const void *pBuffer) {
87 const tRet* data = (const tRet*)pBuffer;
88 return *data;
89 }
90
writeLEWord(const void * buffer,uint16 pValue)91 inline void writeLEWord( const void *buffer, uint16 pValue ) {
92 uint16* wordBytes = (uint16 *) buffer;
93 *wordBytes = pValue;
94 }
95
96 #ifndef _WIN32
97 #include <unistd.h>
98 #define Sleep( a ) usleep( a * 1000 );
99
100 #define _stricmp( a, b ) strcmp(a, b)
101 #endif
102
103 #include "Debugger.hpp"
104 #include "Utils/pseudorand.hpp"
105
106 #include "Position.hpp"
107 #include "Dimension.hpp"
108 #include "Event.hpp"
109
110 #include "Surface.hpp"
111 #include "Version.hpp"
112 #include "Resources.hpp"
113
114 #include "Parameters.hpp"
115
116 #include "PC/Resource_PC_CD.hpp"
117 //#include "Amiga/Resource_Amiga_File.hpp"
118
119 #include "CopyProtection.hpp"
120 #include "IntroData.hpp"
121 #include "Tiles.hpp"
122
123 #include "Map/Map.hpp"
124 #include "Map/Original.hpp"
125 //#include "Map/Random.hpp"
126
127 #include "Campaign.hpp"
128 #include "FontData.hpp"
129 #include "Graphics.hpp"
130 #include "Recruits.hpp"
131 #include "Versions.hpp"
132 #include "ResourceMan.hpp"
133
134 #include "Window.hpp"
135 #include "Sound.hpp"
136 #include "GUI_Element.hpp"
137 #include "SpriteSheet.hpp"
138 #include "Fodder.hpp"
139
140 #include "Structures/Barracks.hpp"
141
142 #include "PC/Graphics_PC.hpp"
143 #include "PC/Sound_PC.hpp"
144 #include "PC/Sound_PC2.hpp"
145
146 #include "Amiga/paula.hpp"
147 #include "Amiga/rjp1.hpp"
148 #include "Amiga/Sound_Amiga.hpp"
149 #include "Amiga/Graphics_Amiga.hpp"
150 #include "Amiga/Graphics_Amiga2.hpp"
151
152 #include "About.hpp"
153 #include "UnitTesting.hpp"
154
155 #include "ScriptingEngine.hpp"
156
157 extern std::shared_ptr<cResources> g_Resource;
158 extern std::shared_ptr<cWindow> g_Window;
159 extern std::shared_ptr<cFodder> g_Fodder;
160 extern std::shared_ptr<cDebugger> g_Debugger;
161 extern std::shared_ptr<cResourceMan> g_ResourceMan;
162 extern std::shared_ptr<cScriptingEngine> g_ScriptingEngine;
163
164 extern const char gPathSeperator;
165
166 #define CANNON_BASED( pCF1, pCF2 ) (g_Fodder->mVersionCurrent->isCannonFodder1() ? pCF1 : pCF2 )
167 #define PLATFORM_BASED( pPC, pAmiga ) (g_Fodder->mVersionCurrent->isAmiga() ? pAmiga : pPC )
168