├── src ├── appicon.rc ├── Text.h ├── Input.cpp ├── Canvas.cpp ├── Player.cpp ├── Render.cpp ├── appicon.ico ├── appicon.png ├── MenuSystem.cpp ├── TGLVert.h ├── IDIB.h ├── IDIB.cpp ├── MenuItem.h ├── Image.h ├── DrivingGame.h ├── LerpSprite.h ├── TGLEdge.h ├── ZipFile.h ├── EntityDef.h ├── GameSprite.h ├── MenuItem.cpp ├── CombatEntity.h ├── CAppContainer.h ├── SDLGL.h ├── MayaCamera.h ├── CMakeLists.txt ├── EntityMonster.cpp ├── TGLEdge.cpp ├── ScriptThread.h ├── JavaStream.h ├── ParticleSystem.h ├── Utils.h ├── GLES.h ├── EntityDef.cpp ├── LerpSprite.cpp ├── Main.cpp ├── EntityMonster.h ├── Graphics.h ├── Sound.h ├── Span.h ├── Resource.h ├── Button.h ├── Sounds.h ├── TinyGL.h ├── CAppContainer.cpp ├── Input.h ├── Hud.h ├── Combat.h ├── Player.h ├── SDLGL.cpp ├── Image.cpp ├── CardGames.h ├── ZipFile.cpp └── JavaStream.cpp ├── assets ├── app_icon_128.png ├── app_icon_16.png ├── app_icon_160.png ├── app_icon_192.png ├── app_icon_20.png ├── app_icon_22.png ├── app_icon_24.png ├── app_icon_256.png ├── app_icon_28.png ├── app_icon_30.png ├── app_icon_32.png ├── app_icon_36.png ├── app_icon_384.png ├── app_icon_40.png ├── app_icon_42.png ├── app_icon_44.png ├── app_icon_48.png ├── app_icon_480.png ├── app_icon_512.png ├── app_icon_56.png ├── app_icon_60.png ├── app_icon_64.png ├── app_icon_72.png ├── app_icon_8.png ├── app_icon_80.png ├── app_icon_96.png └── app_icon_1024.png ├── third_party_libs └── hash-library │ ├── Version.txt │ ├── CMakeLists.txt │ └── hash-library │ ├── hash.h │ ├── LICENSE │ ├── readme.md │ ├── crc32.h │ ├── md5.h │ ├── sha1.h │ ├── sha256.h │ ├── sha3.h │ ├── keccak.h │ ├── hmac.h │ ├── digest.cpp │ ├── sha3.cpp │ └── keccak.cpp ├── CMakeLists.txt ├── cmake └── Modules │ ├── FindSDL2_mixer.cmake │ ├── FindSDL2.cmake │ └── Nueva carpeta │ └── FindSDL2_mixer.cmake ├── make-wolfenstein-rpg-linux-appimage.sh └── README.md /src/appicon.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "appicon.ico" -------------------------------------------------------------------------------- /src/Text.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/src/Text.h -------------------------------------------------------------------------------- /src/Input.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/src/Input.cpp -------------------------------------------------------------------------------- /src/Canvas.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/src/Canvas.cpp -------------------------------------------------------------------------------- /src/Player.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/src/Player.cpp -------------------------------------------------------------------------------- /src/Render.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/src/Render.cpp -------------------------------------------------------------------------------- /src/appicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/src/appicon.ico -------------------------------------------------------------------------------- /src/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/src/appicon.png -------------------------------------------------------------------------------- /src/MenuSystem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/src/MenuSystem.cpp -------------------------------------------------------------------------------- /assets/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_128.png -------------------------------------------------------------------------------- /assets/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_16.png -------------------------------------------------------------------------------- /assets/app_icon_160.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_160.png -------------------------------------------------------------------------------- /assets/app_icon_192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_192.png -------------------------------------------------------------------------------- /assets/app_icon_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_20.png -------------------------------------------------------------------------------- /assets/app_icon_22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_22.png -------------------------------------------------------------------------------- /assets/app_icon_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_24.png -------------------------------------------------------------------------------- /assets/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_256.png -------------------------------------------------------------------------------- /assets/app_icon_28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_28.png -------------------------------------------------------------------------------- /assets/app_icon_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_30.png -------------------------------------------------------------------------------- /assets/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_32.png -------------------------------------------------------------------------------- /assets/app_icon_36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_36.png -------------------------------------------------------------------------------- /assets/app_icon_384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_384.png -------------------------------------------------------------------------------- /assets/app_icon_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_40.png -------------------------------------------------------------------------------- /assets/app_icon_42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_42.png -------------------------------------------------------------------------------- /assets/app_icon_44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_44.png -------------------------------------------------------------------------------- /assets/app_icon_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_48.png -------------------------------------------------------------------------------- /assets/app_icon_480.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_480.png -------------------------------------------------------------------------------- /assets/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_512.png -------------------------------------------------------------------------------- /assets/app_icon_56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_56.png -------------------------------------------------------------------------------- /assets/app_icon_60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_60.png -------------------------------------------------------------------------------- /assets/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_64.png -------------------------------------------------------------------------------- /assets/app_icon_72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_72.png -------------------------------------------------------------------------------- /assets/app_icon_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_8.png -------------------------------------------------------------------------------- /assets/app_icon_80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_80.png -------------------------------------------------------------------------------- /assets/app_icon_96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_96.png -------------------------------------------------------------------------------- /assets/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/WolfensteinRPG-RE/HEAD/assets/app_icon_1024.png -------------------------------------------------------------------------------- /third_party_libs/hash-library/Version.txt: -------------------------------------------------------------------------------- 1 | Note: I have stripped out some stuff which is not needed to use this library. 2 | The full version is available at the link below. 3 | 4 | Commit: 5 | https://github.com/stbrumme/hash-library/tree/f77b5646ca29bc4cfaa433996139d7d1c37cf650 6 | (Feb 3rd, 2021) 7 | -------------------------------------------------------------------------------- /src/TGLVert.h: -------------------------------------------------------------------------------- 1 | #ifndef __TGLVERT_H__ 2 | #define __TGLVERT_H__ 3 | 4 | class TGLVert 5 | { 6 | private: 7 | 8 | public: 9 | static constexpr int MV_TC_ONE = 2048; 10 | 11 | int x; 12 | int y; 13 | int z; 14 | int w; 15 | int s; 16 | int t; 17 | int clipDist; 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /src/IDIB.h: -------------------------------------------------------------------------------- 1 | #ifndef __IDIB_H__ 2 | #define __IDIB_H__ 3 | 4 | class IDIB 5 | { 6 | private: 7 | 8 | public: 9 | uint8_t* pBmp; 10 | uint32_t* pRGB888; 11 | uint16_t* pRGB565; 12 | unsigned int cntRGB; 13 | unsigned int nColorScheme; 14 | unsigned int ncTransparent; 15 | int width; 16 | int height; 17 | int depth; 18 | unsigned int pitch; 19 | 20 | // Constructor 21 | IDIB(); 22 | // Destructor 23 | ~IDIB(); 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /src/IDIB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "IDIB.h" 4 | 5 | IDIB::IDIB() { 6 | } 7 | 8 | IDIB::~IDIB() { 9 | if (this) { 10 | if (this->pBmp) { 11 | free(this->pBmp); 12 | this->pBmp = nullptr; 13 | } 14 | if (this->pRGB888) { 15 | free(this->pRGB888); 16 | this->pRGB888 = nullptr; 17 | } 18 | if (this->pRGB565) { 19 | free(this->pRGB565); 20 | this->pRGB565 = nullptr; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SRC_DIR "hash-library") 2 | 3 | set(SOURCE_FILES 4 | "${SRC_DIR}/md5.cpp" 5 | "${SRC_DIR}/md5.h" 6 | ) 7 | 8 | set(OTHER_FILES 9 | ) 10 | 11 | add_library(${HASH_LIBRARY_TGT_NAME} ${SOURCE_FILES}) 12 | #setup_source_groups("${SOURCE_FILES}" "${OTHER_FILES}") 13 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Header Files" FILES ${HEADER_FILES}) 14 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Source Files" FILES ${SOURCE_FILES}) 15 | 16 | target_include_directories(${HASH_LIBRARY_TGT_NAME} INTERFACE ${SRC_DIR}) 17 | -------------------------------------------------------------------------------- /src/MenuItem.h: -------------------------------------------------------------------------------- 1 | #ifndef __MENUITEM_H__ 2 | #define __MENUITEM_H__ 3 | 4 | class Text; 5 | 6 | class MenuItem 7 | { 8 | private: 9 | 10 | public: 11 | int touchMe; 12 | int textField; 13 | int textField2; 14 | int helpField; 15 | int flags; 16 | int param; 17 | int action; 18 | 19 | // Constructor 20 | MenuItem(); 21 | // Destructor 22 | ~MenuItem(); 23 | 24 | void Set(int textField, int textField2, int flags); 25 | void Set(int textField, int textField2, int flags, int action, int param, int helpField); 26 | void WrapHelpText(Text* text); 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules") 3 | 4 | project(WolfensteinRPG) 5 | 6 | if(MSVC) 7 | add_definitions("/D_CRT_SECURE_NO_WARNINGS") 8 | endif() 9 | 10 | find_package(SDL2 REQUIRED) 11 | find_package(ZLIB REQUIRED) 12 | find_package(OpenAL REQUIRED) 13 | find_package(OpenGL REQUIRED) 14 | 15 | # Global identifiers for each project/target 16 | set(HASH_LIBRARY_TGT_NAME Hash-Library) 17 | 18 | add_subdirectory("${PROJECT_SOURCE_DIR}/src") 19 | add_subdirectory("${PROJECT_SOURCE_DIR}/third_party_libs/hash-library") -------------------------------------------------------------------------------- /src/Image.h: -------------------------------------------------------------------------------- 1 | #ifndef __IMAGE_H__ 2 | #define __IMAGE_H__ 3 | 4 | #include 5 | 6 | class IDIB; 7 | 8 | class Image 9 | { 10 | private: 11 | 12 | public: 13 | IDIB* piDIB; 14 | int width; 15 | int height; 16 | int depth; 17 | bool isTransparentMask; 18 | int texWidth; 19 | int texHeight; 20 | GLuint texture; 21 | 22 | // Constructor 23 | Image(); 24 | // Destructor 25 | ~Image(); 26 | 27 | void CreateTexture(uint16_t* data, uint32_t width, uint32_t height); 28 | void DrawTexture(int texX, int texY, int texW, int texH, int posX, int posY, int rotateMode, int renderMode); 29 | void setRenderMode(int renderMode); 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /src/DrivingGame.h: -------------------------------------------------------------------------------- 1 | #ifndef __DRIVINGGAME_H__ 2 | #define __DRIVINGGAME_H__ 3 | 4 | class Image; 5 | class Text; 6 | class Entity; 7 | class EntityDef; 8 | class ScriptThread; 9 | class Graphics; 10 | 11 | class fmButtonContainer; 12 | class fmScrollButton; 13 | class fmButton; 14 | class fmSwipeArea; 15 | 16 | class DrivingGame 17 | { 18 | private: 19 | 20 | public: 21 | int fireAngle; 22 | int fireTime; 23 | int fireCount; 24 | int monsterFireTime; 25 | int mode; 26 | int curIndex; 27 | 28 | // Constructor 29 | DrivingGame(); 30 | // Destructor 31 | ~DrivingGame(); 32 | 33 | void init(); 34 | void drivingState(); 35 | bool handleDrivingEvents(int key, int keyAction); 36 | 37 | }; 38 | #endif -------------------------------------------------------------------------------- /src/LerpSprite.h: -------------------------------------------------------------------------------- 1 | #ifndef __LERPSPRITE_H__ 2 | #define __LERPSPRITE_H__ 3 | 4 | class ScriptThread; 5 | class OutputStream; 6 | class InputStream; 7 | 8 | class LerpSprite 9 | { 10 | private: 11 | 12 | public: 13 | int touchMe; 14 | ScriptThread* thread; 15 | int travelTime; 16 | int startTime; 17 | int hSprite; 18 | int srcX; 19 | int srcY; 20 | int srcZ; 21 | int dstX; 22 | int dstY; 23 | int dstZ; 24 | int height; 25 | int dist; 26 | int srcScale; 27 | int dstScale; 28 | int flags; 29 | 30 | // Constructor 31 | LerpSprite(); 32 | // Destructor 33 | ~LerpSprite(); 34 | 35 | void saveState(OutputStream* OS); 36 | void calcDist(); 37 | void loadState(InputStream* IS); 38 | }; 39 | 40 | #endif -------------------------------------------------------------------------------- /src/TGLEdge.h: -------------------------------------------------------------------------------- 1 | #ifndef __TGLEDGE_H__ 2 | #define __TGLEDGE_H__ 3 | 4 | class TGLVert; 5 | 6 | class TGLEdge 7 | { 8 | private: 9 | 10 | static constexpr int SCREEN_SHIFT = 3; 11 | static constexpr int SCREEN_ONE = 8; 12 | static constexpr int SCREEN_PRESTEP = 7; 13 | static constexpr int INTERPOLATE_SHIFT = 16; 14 | static constexpr int INTERPOLATE_TO_PIXELS_SHIFT = 19; 15 | static constexpr int INTERPOLATE_PRESTEP = 524287; 16 | 17 | public: 18 | int stopY; 19 | int fracX; 20 | int fracZ; 21 | int fracS; 22 | int fracT; 23 | int stepX; 24 | int stepZ; 25 | int stepS; 26 | int stepT; 27 | 28 | // Constructor 29 | TGLEdge(); 30 | // Destructor 31 | ~TGLEdge(); 32 | 33 | bool startup(); 34 | void setFromVerts(TGLVert* tglVert, TGLVert* tglVert2); 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/hash.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // hash.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | /// abstract base class 12 | class Hash 13 | { 14 | public: 15 | /// compute hash of a memory block 16 | virtual std::string operator()(const void* data, size_t numBytes) = 0; 17 | /// compute hash of a string, excluding final zero 18 | virtual std::string operator()(const std::string& text) = 0; 19 | 20 | /// add arbitrary number of bytes 21 | virtual void add(const void* data, size_t numBytes) = 0; 22 | 23 | /// return latest hash as hex characters 24 | virtual std::string getHash() = 0; 25 | 26 | /// restart 27 | virtual void reset() = 0; 28 | }; 29 | -------------------------------------------------------------------------------- /src/ZipFile.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZIPFILE_H__ 2 | #define __ZIPFILE_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define ZIP_LOCAL_FILE_SIG 0x04034b50 9 | #define ZIP_CENTRAL_DIRECTORY_SIG 0x02014b50 10 | #define ZIP_END_OF_CENTRAL_DIRECTORY_SIG 0x06054b50 11 | #define ZIP_ENCRYPTED_FLAG 0x1 12 | 13 | typedef struct zip_entry_s 14 | { 15 | char* name; 16 | int offset; 17 | int csize, usize; 18 | }zip_entry_t; 19 | 20 | class ZipFile 21 | { 22 | private: 23 | FILE* file; 24 | int entry_count; 25 | zip_entry_t* entry; 26 | int page_count; 27 | int* page; 28 | public: 29 | 30 | // Constructor 31 | ZipFile(); 32 | // Destructor 33 | ~ZipFile(); 34 | 35 | void findAndReadZipDir(int startoffset); 36 | void openZipFile(const char* name); 37 | void closeZipFile(); 38 | uint8_t* readZipFileEntry(const char* name, int* sizep); 39 | }; 40 | 41 | #endif -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/LICENSE: -------------------------------------------------------------------------------- 1 | zlib License 2 | 3 | Copyright (c) 2014,2015 Stephan Brumme 4 | 5 | This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. 6 | Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 7 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. 8 | If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 9 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 10 | 3. This notice may not be removed or altered from any source distribution. 11 | -------------------------------------------------------------------------------- /src/EntityDef.h: -------------------------------------------------------------------------------- 1 | #ifndef __ENTITYDEF_H__ 2 | #define __ENTITYDEF_H__ 3 | 4 | class EntityDef; 5 | 6 | // ----------------------- 7 | // EntityDefManager Class 8 | // ----------------------- 9 | 10 | class EntityDefManager 11 | { 12 | private: 13 | EntityDef* list; 14 | int numDefs; 15 | public: 16 | 17 | // Constructor 18 | EntityDefManager(); 19 | // Destructor 20 | ~EntityDefManager(); 21 | 22 | bool startup(); 23 | EntityDef* find(int eType, int eSubType); 24 | EntityDef* find(int eType, int eSubType, int parm); 25 | EntityDef* lookup(int tileIndex); 26 | }; 27 | 28 | // ---------------- 29 | // EntityDef Class 30 | // ---------------- 31 | 32 | class EntityDef 33 | { 34 | private: 35 | 36 | public: 37 | int16_t tileIndex; 38 | int16_t name; 39 | int16_t longName; 40 | int16_t description; 41 | uint8_t eType; 42 | uint8_t eSubType; 43 | uint8_t parm; 44 | uint8_t touchMe; 45 | 46 | // Constructor 47 | EntityDef(); 48 | }; 49 | 50 | #endif -------------------------------------------------------------------------------- /src/GameSprite.h: -------------------------------------------------------------------------------- 1 | #ifndef __GAMESPRITE_H__ 2 | #define __GAMESPRITE_H__ 3 | 4 | class Entity; 5 | 6 | class GameSprite 7 | { 8 | private: 9 | 10 | public: 11 | static constexpr int FLAG_INUSE = 1; 12 | static constexpr int FLAG_PROPOGATE = 2; 13 | static constexpr int FLAG_NORELINK = 4; 14 | static constexpr int FLAG_NOREFRESH = 8; 15 | static constexpr int FLAG_ANIM = 64; 16 | static constexpr int FLAG_NOEXPIRE = 512; 17 | static constexpr int FLAG_SCALE = 1024; 18 | static constexpr int FLAG_UNLINK = 2048; 19 | static constexpr int FLAG_FACEPLAYER = 4096; 20 | static constexpr int FLAG_LERP_ENT = 8192; 21 | static constexpr int FLAG_LERP_PARABOLA = 16384; 22 | static constexpr int FLAG_LERP_TRUNC = 32768; 23 | 24 | int touchMe; 25 | int time; 26 | int flags; 27 | short pos[6]; 28 | int sprite; 29 | Entity* data; 30 | uint8_t startScale; 31 | uint8_t destScale; 32 | int duration; 33 | int vel[3]; 34 | int scaleStep; 35 | uint8_t numAnimFrames; 36 | }; 37 | 38 | #endif -------------------------------------------------------------------------------- /src/MenuItem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "CAppContainer.h" 4 | #include "App.h" 5 | #include "Canvas.h" 6 | #include "MenuItem.h" 7 | #include "MenuSystem.h" 8 | #include "Text.h" 9 | 10 | MenuItem::MenuItem() { 11 | } 12 | 13 | MenuItem::~MenuItem() { 14 | } 15 | 16 | void MenuItem::Set(int textField, int textField2, int flags) { 17 | this->Set(textField, textField2, flags, 0, 0, MenuSystem::EMPTY_TEXT); 18 | } 19 | 20 | void MenuItem::Set(int textField, int textField2, int flags, int action, int param, int helpField) { 21 | this->textField = textField; 22 | this->textField2 = textField2; 23 | this->flags = flags; 24 | this->helpField = helpField; 25 | this->param = param; 26 | this->action = action; 27 | } 28 | 29 | void MenuItem::WrapHelpText(Text* text) { 30 | Applet* app = CAppContainer::getInstance()->app; 31 | 32 | app->localization->composeTextField(this->helpField, text); 33 | text->length(); 34 | text->wrapText(app->canvas->menuHelpMaxChars, 8, '\n'); 35 | } 36 | -------------------------------------------------------------------------------- /src/CombatEntity.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMBATENTITY_H__ 2 | #define __COMBATENTITY_H__ 3 | 4 | class InputStream; 5 | class OutputStream; 6 | class Entity; 7 | 8 | class CombatEntity 9 | { 10 | private: 11 | 12 | public: 13 | int touchMe; 14 | int stats[8]; 15 | int weapon; 16 | 17 | // Constructor 18 | CombatEntity(); 19 | CombatEntity(int health, int armor, int defense, int strength, int accuracy, int agility); 20 | // Destructor 21 | ~CombatEntity(); 22 | 23 | void clone(CombatEntity* ce); 24 | int getStat(int i); 25 | int getStatPercent(int i); 26 | int addStat(int i, int i2); 27 | int setStat(int i, int i2); 28 | int calcXP(); 29 | void loadState(InputStream* inputStream, bool b); 30 | void saveState(OutputStream* outputStream, bool b); 31 | void calcCombat(CombatEntity* combatEntity, Entity* entity, bool b, int n, int n2); 32 | int calcHit(CombatEntity* ce, CombatEntity* ce2, bool b, int i, bool b2); 33 | int calcDamage(CombatEntity* ce, Entity* entity, CombatEntity* ce2, bool b, int n); 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /src/CAppContainer.h: -------------------------------------------------------------------------------- 1 | #ifndef __CAPPCONTAINER_H__ 2 | #define __CAPPCONTAINER_H__ 3 | #include "App.h" 4 | 5 | class ZipFile; 6 | class SDLGL; 7 | class Applet; 8 | 9 | class CAppContainer 10 | { 11 | private: 12 | 13 | public: 14 | Applet* app; 15 | SDLGL* sdlGL; // New 16 | ZipFile* zipFile; // New 17 | static CAppContainer* getInstance(); 18 | static int m_cheatEntry; 19 | float MoveX, MoveY, MoveAng; 20 | 21 | // Constructor 22 | CAppContainer(); 23 | // Destructor 24 | ~CAppContainer(); 25 | 26 | short* GetBackBuffer(); 27 | void DoLoop(int time); 28 | void suspendOpenAL(); 29 | void resumeOpenAL(); 30 | void userPressed(float pressX, float pressY); 31 | void userMoved(float pressX, float pressY); 32 | void userReleased(float pressX, float pressY); 33 | void unHighlightButtons(); 34 | uint32_t getTimeMS(); 35 | void saveGame(int i, int * i2); 36 | void TestCheatEntry(float pressX, float pressY); 37 | bool testCheatCode(int code); 38 | void UpdateAccelerometer(float x, float y, float z, bool useMouse); 39 | void Construct(SDLGL* sdlGL, ZipFile* zipFile); 40 | 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /src/SDLGL.h: -------------------------------------------------------------------------------- 1 | #ifndef __SDLGL_H__ 2 | #define __SDLGL_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | typedef struct SDLResVidModes_s { 11 | int width, height; 12 | } SDLResVidModes; 13 | extern SDLResVidModes sdlResVideoModes[18]; 14 | 15 | class SDLGL 16 | { 17 | private: 18 | bool initialized; 19 | SDL_GLContext glcontext; 20 | #ifdef __linux__ 21 | // Linux only: an icon to use for the window (SDL) 22 | SDL_Surface* gpSdlWindowIcon; 23 | #endif 24 | 25 | public: 26 | SDL_Window* window; 27 | int resolutionIndex; 28 | int oldResolutionIndex; 29 | int winVidWidth, winVidHeight; 30 | int vidWidth, vidHeight; 31 | int windowMode, oldWindowMode; 32 | bool vSync, oldVSync; 33 | 34 | SDLGL(); 35 | // Destructor 36 | ~SDLGL(); 37 | bool Initialize(); 38 | void Error(const char* fmt, ...); 39 | 40 | void transformCoord2f(float* x, float* y); 41 | void centerMouse(int x, int y); 42 | void updateWinVid(int w, int h); 43 | void updateVideo(); 44 | void restore(); 45 | }; 46 | 47 | #endif -------------------------------------------------------------------------------- /src/MayaCamera.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAYACAMERA_H__ 2 | #define __MAYACAMERA_H__ 3 | 4 | class ScriptThread; 5 | 6 | class MayaCamera 7 | { 8 | private: 9 | 10 | public: 11 | int keyOffset; 12 | int numKeys; 13 | int curTweenTime; 14 | int curTween; 15 | ScriptThread* cameraThread; 16 | ScriptThread* keyThread; 17 | int keyThreadResumeCount; 18 | bool complete; 19 | int x; 20 | int y; 21 | int z; 22 | int pitch; 23 | int yaw; 24 | int roll; 25 | short aggComponents[6]; 26 | int sampleRate; 27 | short keyOfs[6]; 28 | bool isTableCam; 29 | bool inheritYaw; 30 | bool inheritPitch; 31 | bool inheritX; 32 | bool inheritY; 33 | bool inheritZ; 34 | 35 | // Constructor 36 | MayaCamera(); 37 | // Destructor 38 | ~MayaCamera(); 39 | 40 | void NextKey(); 41 | void Update(int i, int i2); 42 | int getAngleDifference(int i, int i2); 43 | bool hasTweens(int i); 44 | int estNumTweens(int i); 45 | short* getTweenData(int8_t* array, int i, int i2); 46 | short* getKeyOfs(int16_t* array, int i); 47 | void Interpolate(int16_t* array, int i); 48 | void resetTweenBase(int i); 49 | void updateTweenBase(int i, int i2); 50 | void Render(); 51 | void Snap(int i); 52 | }; 53 | 54 | #endif -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Agrupar archivos por tipo 2 | file(GLOB_RECURSE HEADER_FILES 3 | "*.hpp" 4 | "*.h" 5 | ) 6 | 7 | file(GLOB_RECURSE SOURCE_FILES 8 | "*.cpp" 9 | "*.c" 10 | ) 11 | 12 | file(GLOB_RECURSE RESOURCES_FILES 13 | "*.rc" 14 | "*.ico" 15 | ) 16 | 17 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Header Files" FILES ${HEADER_FILES}) 18 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Source Files" FILES ${SOURCE_FILES}) 19 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Resources Files" FILES ${RESOURCES_FILES}) 20 | 21 | # Crear el ejecutable 22 | add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES} ${RESOURCES_FILES}) 23 | 24 | # Enlace de bibliotecas 25 | target_link_libraries(${PROJECT_NAME} SDL2::SDL2 ZLIB::ZLIB OpenGL::GL ${HASH_LIBRARY_TGT_NAME}) 26 | 27 | # Enlace de OpenAL según el sistema operativo 28 | if (CMAKE_SYSTEM_NAME STREQUAL "Windows") 29 | target_link_libraries(${PROJECT_NAME} OpenAL::OpenAL ${OPENGL_gl_LIBRARY}) 30 | elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") 31 | target_link_libraries(${PROJECT_NAME} OpenGL::GL ${OPENAL_LIBRARY}) 32 | # Verifica si realmente necesitas una compilación estática 33 | target_link_options(${PROJECT_NAME} PRIVATE -static-libgcc -static-libstdc++) 34 | endif() 35 | -------------------------------------------------------------------------------- /src/EntityMonster.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "EntityMonster.h" 5 | #include "JavaStream.h" 6 | #include "Enums.h" 7 | 8 | EntityMonster::EntityMonster() { 9 | memset(this, 0, sizeof(EntityMonster)); 10 | } 11 | 12 | void EntityMonster::clearEffects() { 13 | this->monsterEffects = EntityMonster::MFX_NONE; 14 | } 15 | 16 | void EntityMonster::reset() { 17 | this->prevOnList = nullptr; 18 | this->nextOnList = nullptr; 19 | this->target = nullptr; 20 | this->nextAttacker = nullptr; 21 | this->frameTime = 0; 22 | this->flags = Enums::MFLAG_NONE; 23 | this->clearEffects(); 24 | this->resetGoal(); 25 | } 26 | 27 | void EntityMonster::saveGoalState(OutputStream* OS) { 28 | OS->writeInt(this->goalType | this->goalFlags << 4 | this->goalTurns << 8 |this->goalX << 12 | this->goalY << 17 | this->goalParam << 22); 29 | } 30 | 31 | void EntityMonster::loadGoalState(InputStream* IS) { 32 | int args = IS->readInt(); 33 | this->goalType = (uint8_t)(args & 0xF); 34 | this->goalFlags = (uint8_t)(args >> 4 & 0xF); 35 | this->goalTurns = (uint8_t)(args >> 8 & 0xF); 36 | this->goalX = (args >> 12 & 0x1F); 37 | this->goalY = (args >> 17 & 0x1F); 38 | this->goalParam = (args >> 22 & 0x3FF); 39 | } 40 | 41 | void EntityMonster::resetGoal() { 42 | this->goalType = 0; 43 | this->goalFlags = 0; 44 | this->goalTurns = 0; 45 | this->goalY = 0; 46 | this->goalX = 0; 47 | this->goalParam = 0; 48 | } 49 | -------------------------------------------------------------------------------- /src/TGLEdge.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "TGLEdge.h" 4 | #include "TGLVert.h" 5 | 6 | TGLEdge::TGLEdge() { 7 | } 8 | 9 | TGLEdge::~TGLEdge() { 10 | } 11 | 12 | bool TGLEdge::startup() { 13 | //printf("TGLEdge::startup\n"); 14 | 15 | return false; 16 | } 17 | 18 | void TGLEdge::setFromVerts(TGLVert* tglVert, TGLVert* tglVert2) { 19 | this->stopY = tglVert2->y + 7 >> 3; 20 | int n = tglVert2->y - tglVert->y; 21 | if (n != 0) { 22 | this->stepX = ((tglVert2->x - tglVert->x) << 16) / n; 23 | this->stepZ = ((tglVert2->z - tglVert->z) << 16) / n; 24 | this->stepS = (tglVert2->s - tglVert->s) / n; 25 | this->stepT = (tglVert2->t - tglVert->t) / n; 26 | int n2 = (8 - (uint32_t)tglVert->y) & 0x7; 27 | this->fracX = (tglVert->x << 16) + n2 * this->stepX; 28 | this->fracZ = (tglVert->z << 16) + n2 * this->stepZ; 29 | this->fracS = tglVert->s + n2 * this->stepS; 30 | this->fracT = tglVert->t + n2 * this->stepT; 31 | this->stepX <<= 3; 32 | this->stepZ <<= 3; 33 | this->stepS <<= 3; 34 | this->stepT <<= 3; 35 | } 36 | else { 37 | this->fracX = tglVert->x << 16; 38 | this->fracZ = tglVert->z << 16; 39 | this->fracS = tglVert->s; 40 | this->fracT = tglVert->t; 41 | this->stepX = 0; 42 | this->stepZ = 0; 43 | this->stepS = 0; 44 | this->stepT = 0; 45 | } 46 | } -------------------------------------------------------------------------------- /src/ScriptThread.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCRIPTTHREAD_H__ 2 | #define __SCRIPTTHREAD_H__ 3 | 4 | class Text; 5 | class Applet; 6 | class OutputStream; 7 | class InputStream; 8 | class Entity; 9 | 10 | class ScriptThread 11 | { 12 | private: 13 | 14 | public: 15 | int unpauseTime; 16 | int state; 17 | bool inuse; 18 | int IP; 19 | int FP; 20 | int flags; 21 | int type; 22 | bool throwAwayLoot; 23 | int scriptStack[16]; 24 | int stackPtr; 25 | Text* debugString; 26 | Applet* app; 27 | 28 | // Constructor 29 | ScriptThread(); 30 | // Destructor 31 | ~ScriptThread(); 32 | 33 | void saveState(OutputStream* OS); 34 | void loadState(InputStream* IS); 35 | uint32_t executeTile(int x, int y, int flags, bool b); 36 | int queueTile(int x, int y, int flags); 37 | int queueTile(int x, int y, int flags, bool b); 38 | int evWait(int time); 39 | bool evReturn(); 40 | void alloc(int n, int type, bool b); 41 | void alloc(int ip); 42 | int peekNextCmd(); 43 | void setupCamera(int n); 44 | uint32_t run(); 45 | void init(); 46 | void reset(); 47 | int attemptResume(int n); 48 | int getIndex(); 49 | int pop(); 50 | void push(bool b); 51 | void push(int n); 52 | short getUByteArg(); 53 | uint8_t getByteArg(); 54 | int getUShortArg(); 55 | short getShortArg(); 56 | int getIntArg(); 57 | void composeLootDialog(); 58 | void setAIGoal(Entity* entity, int goalType, int goalParam); 59 | void corpsifyMonster(int x, int y, Entity* entity, bool b); 60 | void stripInventory(); 61 | void restoreInventory(); 62 | }; 63 | 64 | #endif -------------------------------------------------------------------------------- /src/JavaStream.h: -------------------------------------------------------------------------------- 1 | #ifndef __JAVASTREAM_H__ 2 | #define __JAVASTREAM_H__ 3 | 4 | #define LT_RESOURCE 5 5 | #define LT_FILE 6 6 | #define LT_SOUND_RESOURCE 7 // [GEC] 7 | static constexpr const char* dir = "WolfensteinRPG.app"; 8 | 9 | class Applet; 10 | 11 | // ------------------ 12 | // InputStream Class 13 | // ------------------ 14 | 15 | class InputStream 16 | { 17 | private: 18 | 19 | public: 20 | static constexpr int LOADTYPE_RESOURCE = 5; 21 | static constexpr int LOADTYPE_FILE = 6; 22 | 23 | int field_0x0; 24 | int field_0x4; 25 | uint8_t* data; 26 | int cursor; 27 | FILE* file; 28 | int fileSize; 29 | int field_0x28; 30 | 31 | // Constructor 32 | InputStream(); 33 | // Destructor 34 | ~InputStream(); 35 | 36 | bool startup(); 37 | bool loadResource(const char* fileName); 38 | bool loadFile(const char* fileName, int loadType); 39 | void close(); 40 | int readInt(); 41 | int readShort(); 42 | bool readBoolean(); 43 | uint8_t readByte(); 44 | uint8_t readUnsignedByte(); 45 | int readSignedByte(); 46 | void read(uint8_t* dest, int off, int size); 47 | }; 48 | 49 | // ------------------- 50 | // OutputStream Class 51 | // ------------------- 52 | 53 | class OutputStream 54 | { 55 | private: 56 | 57 | public: 58 | 59 | bool isOpen; 60 | FILE* file; 61 | uint8_t* buffer; 62 | int written; 63 | uint8_t* writeBuff; 64 | int field_0x24_; 65 | int fileSize; 66 | int flushCount; 67 | bool noWrite; 68 | Applet* App; 69 | 70 | // Constructor 71 | OutputStream(); 72 | // Destructor 73 | ~OutputStream(); 74 | 75 | int openFile(const char* fileName, int openMode); 76 | void close(); 77 | int flush(); 78 | void writeInt(int i); 79 | void writeShort(int16_t i); 80 | void writeByte(uint8_t i); 81 | void writeBoolean(bool b); 82 | void write(uint8_t* buff, int off, int size); 83 | }; 84 | 85 | #endif -------------------------------------------------------------------------------- /src/ParticleSystem.h: -------------------------------------------------------------------------------- 1 | #ifndef __PARTICLESYSTEM_H__ 2 | #define __PARTICLESYSTEM_H__ 3 | 4 | class ParticleSystem; 5 | class Image; 6 | class Graphics; 7 | class Entity; 8 | 9 | // ---------------------- 10 | // ParticleEmitter Class 11 | // ---------------------- 12 | 13 | class ParticleEmitter 14 | { 15 | private: 16 | 17 | public: 18 | ParticleSystem* systems; 19 | short pos[3]; 20 | int gravity; 21 | uint8_t gibType; 22 | int color; 23 | int startTime; 24 | 25 | // Constructor 26 | ParticleEmitter(); 27 | // Destructor 28 | ~ParticleEmitter(); 29 | 30 | bool startup(); 31 | void render(Graphics* graphics, int n); 32 | }; 33 | 34 | // --------------------- 35 | // ParticleSystem Class 36 | // --------------------- 37 | 38 | class ParticleSystem 39 | { 40 | private: 41 | 42 | public: 43 | static constexpr uint32_t levelColors[] = { 0xFFFFFFFF, 0xFF3A332E, 0xFF626262, 0xFF7F7F7F, 0xFFD1CF11, 0xFFFD8918, 0xFF20B00D }; 44 | static constexpr int32_t rotationSequence[] = { 0, 4, 2, 6 }; 45 | static constexpr int GIB_BONE_MASK = 0x8110; 46 | 47 | int systemIdx; 48 | ParticleEmitter particleEmitter[4]; 49 | Image* imgGibs[3]; 50 | uint8_t* monsterColors; 51 | uint8_t particleNext[64]; 52 | uint8_t particleStartX[64]; 53 | uint8_t particleStartY[64]; 54 | int16_t particleVelX[64]; 55 | int16_t particleVelY[64]; 56 | uint8_t particleSize[32]; 57 | int clipRect[4]; 58 | 59 | // Constructor 60 | ParticleSystem(); 61 | // Destructor 62 | ~ParticleSystem(); 63 | 64 | bool startup(); 65 | void freeAllParticles(); 66 | int unlinkParticle(int i); 67 | void linkParticle(int i, int i2); 68 | void freeSystem(int n); 69 | void renderSystems(Graphics* graphics); 70 | void spawnMonsterBlood(Entity* entity, bool b); 71 | void spawnParticles(int n, int n2, int n3); 72 | void spawnParticles(int n, int color, int n2, int n3, int n4); 73 | 74 | }; 75 | 76 | #endif -------------------------------------------------------------------------------- /src/Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILS_H__ 2 | #define __UTILS_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "Image.h" 8 | 9 | typedef unsigned char uint8_t; 10 | typedef unsigned long DWORD_PTR; 11 | #define BYTE uint8_t 12 | #define WORD uint16_t 13 | #define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff)) 14 | #define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff)) 15 | #define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff)) 16 | #define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff)) 17 | #define BYTEn(x, n) (*((BYTE*)&(x)+n)) 18 | #define WORDn(x, n) (*((WORD*)&(x)+n)) 19 | #define BYTE0(x) BYTEn(x, 0) // byte 0 (counting from 0) 20 | #define BYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0) 21 | #define BYTE2(x) BYTEn(x, 2) 22 | #define BYTE3(x) BYTEn(x, 3) 23 | #define BYTE4(x) BYTEn(x, 4) 24 | #define WORD1(x) WORDn(x, 1) 25 | #define WORD2(x) WORDn(x, 2) // third word of the object, unsigned 26 | #define WORD3(x) WORDn(x, 3) 27 | #define WORD4(x) WORDn(x, 4) 28 | #define WORD5(x) WORDn(x, 5) 29 | #define WORD6(x) WORDn(x, 6) 30 | #define WORD7(x) WORDn(x, 7) 31 | 32 | 33 | bool getFileMD5Hash(void* data, uint64_t numBytes, uint64_t& hashWord1, uint64_t& hashWord2); 34 | bool checkFileMD5Hash(void* data, uint64_t numBytes, uint64_t checkHashWord1, uint64_t checkHashWord2); 35 | bool pointInRectangle(int x, int y, int rectX, int rectY, int rectW, int rectH); 36 | float AxisHit(int aX, int aY, int x, int y, int w, int h, bool isXaxis, float activeFraction); 37 | void fixImage(Image* img); 38 | void enlargeButtonImage(Image* img); 39 | void enlargeVideoBOXImage(Image* img); 40 | void setPlaqueImage(Image* img); 41 | void setEmptyPlaqueImage(Image* img); 42 | void setEnlargePlaqueImage(Image* img); 43 | void setEnlargeEmptyPlaqueImage(Image* img); 44 | void setSliderBarImage(Image* img); 45 | 46 | void setPixel(uint8_t* data, uint8_t pix, int cnt); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/readme.md: -------------------------------------------------------------------------------- 1 | # Portable C++ Hashing Library 2 | 3 | This is a mirror of my library hosted at https://create.stephan-brumme.com/hash-library/ 4 | 5 | In a nutshell: 6 | 7 | - computes CRC32, MD5, SHA1 and SHA256 (most common member of the SHA2 functions), Keccak and its SHA3 sibling 8 | - optional HMAC (keyed-hash message authentication code) 9 | - no external dependencies, small code size 10 | - can work chunk-wise (for example when reading streams block-by-block) 11 | - portable: supports Windows and Linux, tested on Little Endian and Big Endian CPUs 12 | - roughly as fast as Linux core hashing functions 13 | - open source, zlib license 14 | 15 | You can find code examples, benchmarks and much more on my website https://create.stephan-brumme.com/hash-library/ 16 | 17 | # How to use 18 | 19 | This example computes SHA256 hashes but the API is more or less identical for all hash algorithms: 20 | 21 | ``` cpp 22 | // SHA2 test program 23 | #include "sha256.h" 24 | #include // for std::cout only, not needed for hashing library 25 | 26 | int main(int, char**) 27 | { 28 | // create a new hashing object 29 | SHA256 sha256; 30 | 31 | // hashing an std::string 32 | std::cout << sha256("Hello World") << std::endl; 33 | // => a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e 34 | 35 | // hashing a buffer of bytes 36 | const char* buffer = "How are you"; 37 | std::cout << sha256(buffer, 11) << std::endl; 38 | // => 9c7d5b046878838da72e40ceb3179580958df544b240869b80d0275cc07209cc 39 | 40 | // or in a streaming fashion (re-use "How are you") 41 | SHA256 sha256stream; 42 | const char* url = "create.stephan-brumme.com"; // 25 bytes 43 | int step = 5; 44 | for (int i = 0; i < 25; i += step) 45 | sha256stream.add(url + i, step); // add five bytes at a time 46 | std::cout << sha256stream.getHash() << std::endl; 47 | // => 82aa771f1183c52f973c798c9243a1c73833ea40961c73e55e12430ec77b69f6 48 | 49 | return 0; 50 | } 51 | ``` 52 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/crc32.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // crc32.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int32 uint32_t; 17 | #else 18 | // GCC 19 | #include 20 | #endif 21 | 22 | 23 | /// compute CRC32 hash, based on Intel's Slicing-by-8 algorithm 24 | /** Usage: 25 | CRC32 crc32; 26 | std::string myHash = crc32("Hello World"); // std::string 27 | std::string myHash2 = crc32("How are you", 11); // arbitrary data, 11 bytes 28 | 29 | // or in a streaming fashion: 30 | 31 | CRC32 crc32; 32 | while (more data available) 33 | crc32.add(pointer to fresh data, number of new bytes); 34 | std::string myHash3 = crc32.getHash(); 35 | 36 | Note: 37 | You can find code for the faster Slicing-by-16 algorithm on my website, too: 38 | http://create.stephan-brumme.com/crc32/ 39 | Its unrolled version is about twice as fast but its look-up table doubled in size as well. 40 | */ 41 | class CRC32 //: public Hash 42 | { 43 | public: 44 | /// hash is 4 bytes long 45 | enum { HashBytes = 4 }; 46 | 47 | /// same as reset() 48 | CRC32(); 49 | 50 | /// compute CRC32 of a memory block 51 | std::string operator()(const void* data, size_t numBytes); 52 | /// compute CRC32 of a string, excluding final zero 53 | std::string operator()(const std::string& text); 54 | 55 | /// add arbitrary number of bytes 56 | void add(const void* data, size_t numBytes); 57 | 58 | /// return latest hash as 8 hex characters 59 | std::string getHash(); 60 | /// return latest hash as bytes 61 | void getHash(unsigned char buffer[HashBytes]); 62 | 63 | /// restart 64 | void reset(); 65 | 66 | private: 67 | /// hash 68 | uint32_t m_hash; 69 | }; 70 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/md5.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // md5.h 3 | // Copyright (c) 2014 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int32 uint32_t; 17 | typedef unsigned __int64 uint64_t; 18 | #else 19 | // GCC 20 | #include 21 | #endif 22 | 23 | 24 | /// compute MD5 hash 25 | /** Usage: 26 | MD5 md5; 27 | std::string myHash = md5("Hello World"); // std::string 28 | std::string myHash2 = md5("How are you", 11); // arbitrary data, 11 bytes 29 | 30 | // or in a streaming fashion: 31 | 32 | MD5 md5; 33 | while (more data available) 34 | md5.add(pointer to fresh data, number of new bytes); 35 | std::string myHash3 = md5.getHash(); 36 | */ 37 | class MD5 //: public Hash 38 | { 39 | public: 40 | /// split into 64 byte blocks (=> 512 bits), hash is 16 bytes long 41 | enum { BlockSize = 512 / 8, HashBytes = 16 }; 42 | 43 | /// same as reset() 44 | MD5(); 45 | 46 | /// compute MD5 of a memory block 47 | std::string operator()(const void* data, size_t numBytes); 48 | /// compute MD5 of a string, excluding final zero 49 | std::string operator()(const std::string& text); 50 | 51 | /// add arbitrary number of bytes 52 | void add(const void* data, size_t numBytes); 53 | 54 | /// return latest hash as 32 hex characters 55 | std::string getHash(); 56 | /// return latest hash as bytes 57 | void getHash(unsigned char buffer[HashBytes]); 58 | 59 | /// restart 60 | void reset(); 61 | 62 | private: 63 | /// process 64 bytes 64 | void processBlock(const void* data); 65 | /// process everything left in the internal buffer 66 | void processBuffer(); 67 | 68 | /// size of processed data in bytes 69 | uint64_t m_numBytes; 70 | /// valid bytes in m_buffer 71 | size_t m_bufferSize; 72 | /// bytes not processed yet 73 | uint8_t m_buffer[BlockSize]; 74 | 75 | enum { HashValues = HashBytes / 4 }; 76 | /// hash, stored as integers 77 | uint32_t m_hash[HashValues]; 78 | }; 79 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/sha1.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // sha1.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int32 uint32_t; 17 | typedef unsigned __int64 uint64_t; 18 | #else 19 | // GCC 20 | #include 21 | #endif 22 | 23 | 24 | /// compute SHA1 hash 25 | /** Usage: 26 | SHA1 sha1; 27 | std::string myHash = sha1("Hello World"); // std::string 28 | std::string myHash2 = sha1("How are you", 11); // arbitrary data, 11 bytes 29 | 30 | // or in a streaming fashion: 31 | 32 | SHA1 sha1; 33 | while (more data available) 34 | sha1.add(pointer to fresh data, number of new bytes); 35 | std::string myHash3 = sha1.getHash(); 36 | */ 37 | class SHA1 //: public Hash 38 | { 39 | public: 40 | /// split into 64 byte blocks (=> 512 bits), hash is 20 bytes long 41 | enum { BlockSize = 512 / 8, HashBytes = 20 }; 42 | 43 | /// same as reset() 44 | SHA1(); 45 | 46 | /// compute SHA1 of a memory block 47 | std::string operator()(const void* data, size_t numBytes); 48 | /// compute SHA1 of a string, excluding final zero 49 | std::string operator()(const std::string& text); 50 | 51 | /// add arbitrary number of bytes 52 | void add(const void* data, size_t numBytes); 53 | 54 | /// return latest hash as 40 hex characters 55 | std::string getHash(); 56 | /// return latest hash as bytes 57 | void getHash(unsigned char buffer[HashBytes]); 58 | 59 | /// restart 60 | void reset(); 61 | 62 | private: 63 | /// process 64 bytes 64 | void processBlock(const void* data); 65 | /// process everything left in the internal buffer 66 | void processBuffer(); 67 | 68 | /// size of processed data in bytes 69 | uint64_t m_numBytes; 70 | /// valid bytes in m_buffer 71 | size_t m_bufferSize; 72 | /// bytes not processed yet 73 | uint8_t m_buffer[BlockSize]; 74 | 75 | enum { HashValues = HashBytes / 4 }; 76 | /// hash, stored as integers 77 | uint32_t m_hash[HashValues]; 78 | }; 79 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/sha256.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // sha256.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int32 uint32_t; 17 | typedef unsigned __int64 uint64_t; 18 | #else 19 | // GCC 20 | #include 21 | #endif 22 | 23 | 24 | /// compute SHA256 hash 25 | /** Usage: 26 | SHA256 sha256; 27 | std::string myHash = sha256("Hello World"); // std::string 28 | std::string myHash2 = sha256("How are you", 11); // arbitrary data, 11 bytes 29 | 30 | // or in a streaming fashion: 31 | 32 | SHA256 sha256; 33 | while (more data available) 34 | sha256.add(pointer to fresh data, number of new bytes); 35 | std::string myHash3 = sha256.getHash(); 36 | */ 37 | class SHA256 //: public Hash 38 | { 39 | public: 40 | /// split into 64 byte blocks (=> 512 bits), hash is 32 bytes long 41 | enum { BlockSize = 512 / 8, HashBytes = 32 }; 42 | 43 | /// same as reset() 44 | SHA256(); 45 | 46 | /// compute SHA256 of a memory block 47 | std::string operator()(const void* data, size_t numBytes); 48 | /// compute SHA256 of a string, excluding final zero 49 | std::string operator()(const std::string& text); 50 | 51 | /// add arbitrary number of bytes 52 | void add(const void* data, size_t numBytes); 53 | 54 | /// return latest hash as 64 hex characters 55 | std::string getHash(); 56 | /// return latest hash as bytes 57 | void getHash(unsigned char buffer[HashBytes]); 58 | 59 | /// restart 60 | void reset(); 61 | 62 | private: 63 | /// process 64 bytes 64 | void processBlock(const void* data); 65 | /// process everything left in the internal buffer 66 | void processBuffer(); 67 | 68 | /// size of processed data in bytes 69 | uint64_t m_numBytes; 70 | /// valid bytes in m_buffer 71 | size_t m_bufferSize; 72 | /// bytes not processed yet 73 | uint8_t m_buffer[BlockSize]; 74 | 75 | enum { HashValues = HashBytes / 4 }; 76 | /// hash, stored as integers 77 | uint32_t m_hash[HashValues]; 78 | }; 79 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/sha3.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // sha3.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int64 uint64_t; 17 | #else 18 | // GCC 19 | #include 20 | #endif 21 | 22 | 23 | /// compute SHA3 hash 24 | /** Usage: 25 | SHA3 sha3; 26 | std::string myHash = sha3("Hello World"); // std::string 27 | std::string myHash2 = sha3("How are you", 11); // arbitrary data, 11 bytes 28 | 29 | // or in a streaming fashion: 30 | 31 | SHA3 sha3; 32 | while (more data available) 33 | sha3.add(pointer to fresh data, number of new bytes); 34 | std::string myHash3 = sha3.getHash(); 35 | */ 36 | class SHA3 //: public Hash 37 | { 38 | public: 39 | /// algorithm variants 40 | enum Bits { Bits224 = 224, Bits256 = 256, Bits384 = 384, Bits512 = 512 }; 41 | 42 | /// same as reset() 43 | explicit SHA3(Bits bits = Bits256); 44 | 45 | /// compute hash of a memory block 46 | std::string operator()(const void* data, size_t numBytes); 47 | /// compute hash of a string, excluding final zero 48 | std::string operator()(const std::string& text); 49 | 50 | /// add arbitrary number of bytes 51 | void add(const void* data, size_t numBytes); 52 | 53 | /// return latest hash as hex characters 54 | std::string getHash(); 55 | 56 | /// restart 57 | void reset(); 58 | 59 | private: 60 | /// process a full block 61 | void processBlock(const void* data); 62 | /// process everything left in the internal buffer 63 | void processBuffer(); 64 | 65 | /// 1600 bits, stored as 25x64 bit, BlockSize is no more than 1152 bits (Keccak224) 66 | enum { StateSize = 1600 / (8 * 8), 67 | MaxBlockSize = 200 - 2 * (224 / 8) }; 68 | 69 | /// hash 70 | uint64_t m_hash[StateSize]; 71 | /// size of processed data in bytes 72 | uint64_t m_numBytes; 73 | /// block size (less or equal to MaxBlockSize) 74 | size_t m_blockSize; 75 | /// valid bytes in m_buffer 76 | size_t m_bufferSize; 77 | /// bytes not processed yet 78 | uint8_t m_buffer[MaxBlockSize]; 79 | /// variant 80 | Bits m_bits; 81 | }; 82 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/keccak.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // keccak.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int64 uint64_t; 17 | #else 18 | // GCC 19 | #include 20 | #endif 21 | 22 | 23 | /// compute Keccak hash (designated SHA3) 24 | /** Usage: 25 | Keccak keccak; 26 | std::string myHash = keccak("Hello World"); // std::string 27 | std::string myHash2 = keccak("How are you", 11); // arbitrary data, 11 bytes 28 | 29 | // or in a streaming fashion: 30 | 31 | Keccak keccak; 32 | while (more data available) 33 | keccak.add(pointer to fresh data, number of new bytes); 34 | std::string myHash3 = keccak.getHash(); 35 | */ 36 | class Keccak //: public Hash 37 | { 38 | public: 39 | /// algorithm variants 40 | enum Bits { Keccak224 = 224, Keccak256 = 256, Keccak384 = 384, Keccak512 = 512 }; 41 | 42 | /// same as reset() 43 | explicit Keccak(Bits bits = Keccak256); 44 | 45 | /// compute hash of a memory block 46 | std::string operator()(const void* data, size_t numBytes); 47 | /// compute hash of a string, excluding final zero 48 | std::string operator()(const std::string& text); 49 | 50 | /// add arbitrary number of bytes 51 | void add(const void* data, size_t numBytes); 52 | 53 | /// return latest hash as hex characters 54 | std::string getHash(); 55 | 56 | /// restart 57 | void reset(); 58 | 59 | private: 60 | /// process a full block 61 | void processBlock(const void* data); 62 | /// process everything left in the internal buffer 63 | void processBuffer(); 64 | 65 | /// 1600 bits, stored as 25x64 bit, BlockSize is no more than 1152 bits (Keccak224) 66 | enum { StateSize = 1600 / (8 * 8), 67 | MaxBlockSize = 200 - 2 * (224 / 8) }; 68 | 69 | /// hash 70 | uint64_t m_hash[StateSize]; 71 | /// size of processed data in bytes 72 | uint64_t m_numBytes; 73 | /// block size (less or equal to MaxBlockSize) 74 | size_t m_blockSize; 75 | /// valid bytes in m_buffer 76 | size_t m_bufferSize; 77 | /// bytes not processed yet 78 | uint8_t m_buffer[MaxBlockSize]; 79 | /// variant 80 | Bits m_bits; 81 | }; 82 | -------------------------------------------------------------------------------- /src/GLES.h: -------------------------------------------------------------------------------- 1 | #ifndef __GLES_H__ 2 | #define __GLES_H__ 3 | 4 | #include "SDLGL.h" 5 | 6 | typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); 7 | typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); 8 | 9 | class Render; 10 | class TinyGL; 11 | class TGLVert; 12 | 13 | typedef struct _glChain 14 | { 15 | _glChain* next; 16 | _glChain* prev; 17 | GLuint texnum; 18 | GLuint width; 19 | GLuint height; 20 | }glChain; 21 | 22 | typedef struct _Vertex 23 | { 24 | float xyzw[4]; 25 | float st[2]; 26 | }Vertex; 27 | 28 | typedef struct _GLVert 29 | { 30 | int x; 31 | int y; 32 | int z; 33 | int w; 34 | int s; 35 | int t; 36 | }GLVert; 37 | 38 | class gles 39 | { 40 | public: bool isInit; 41 | static constexpr int scale = 1; 42 | static constexpr int MAX_GLVERTS = 16; 43 | static constexpr int MAX_MEDIA = 1024; 44 | 45 | private: 46 | Render* render; 47 | TinyGL* tinyGL; 48 | int activeTexels; 49 | Vertex immediate[MAX_GLVERTS]; 50 | uint16_t quad_indexes[42]; 51 | glChain chains[MAX_MEDIA]; 52 | glChain activeChain; 53 | float fogScale; 54 | float modelViewMatrix[MAX_GLVERTS]; 55 | float projectionMatrix[MAX_GLVERTS]; 56 | int vPortRect[4]; 57 | int fogMode; 58 | int renderMode; 59 | int flags; 60 | float fogStart; 61 | float fogEnd; 62 | float fogColor[4]; 63 | float fogBlack[4]; 64 | public: 65 | 66 | // Constructor 67 | gles(); 68 | // Destructor 69 | ~gles(); 70 | 71 | void WindowInit(); 72 | void SwapBuffers(); 73 | void GLInit(Render* render); 74 | bool ClearBuffer(int color); 75 | void SetGLState(); 76 | void BeginFrame(int x, int y, int w, int h, int* mtxView, int* mtxProjection); 77 | void ResetGLState(); 78 | void CreateFadeTexture(int mediaID); 79 | void CreateAllActiveTextures(); 80 | bool RasterizeConvexPolygon(int numVerts, TGLVert* verts); 81 | bool RasterizeConvexPolygon(int numVerts, GLVert* verts); 82 | void UnloadSkyMap(); 83 | bool DrawWorldSpaceSpriteLine(TGLVert* vert1, TGLVert* vert2, TGLVert* vert3, int flags); 84 | bool DrawModelVerts(TGLVert* verts, int numVerts); 85 | void SetupTexture(int n, int n2, int renderMode, int flags); 86 | void CreateTextureForMediaID(int n, int mediaID, bool b); 87 | bool DrawSkyMap(); 88 | void DrawPortalTexture(Image* img, int x, int y, int w, int h, float tx, float ty, float scale, float angle, char mode); 89 | void TexCombineShift(int r, int g, int b); // [GEC] 90 | }; 91 | 92 | extern gles* _glesObj; 93 | 94 | #endif -------------------------------------------------------------------------------- /src/EntityDef.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "CAppContainer.h" 5 | #include "App.h" 6 | #include "EntityDef.h" 7 | #include "JavaStream.h" 8 | #include "Resource.h" 9 | 10 | // ----------------------- 11 | // EntityDefManager Class 12 | // ----------------------- 13 | 14 | EntityDefManager::EntityDefManager() { 15 | memset(this, 0, sizeof(EntityDefManager)); 16 | } 17 | 18 | EntityDefManager::~EntityDefManager() { 19 | } 20 | 21 | bool EntityDefManager::startup() { 22 | Applet* app = CAppContainer::getInstance()->app; 23 | InputStream IS; 24 | //printf("EntityDefManager::startup\n"); 25 | 26 | this->numDefs = 0; 27 | 28 | if (!IS.loadFile(Resources::RES_ENTITIES_BIN_GZ, InputStream::LOADTYPE_RESOURCE)) { 29 | app->Error("getResource(%s) failed\n", Resources::RES_ENTITIES_BIN_GZ); 30 | } 31 | 32 | app->resource->read(&IS, sizeof(short)); 33 | this->numDefs = (int)app->resource->shiftShort(); 34 | this->list = new EntityDef[this->numDefs]; 35 | 36 | for (int i = 0; i < this->numDefs; i++) { 37 | app->resource->read(&IS, 8); 38 | this->list[i].tileIndex = (int16_t)app->resource->shiftShort(); 39 | this->list[i].eType = (uint8_t)app->resource->shiftByte(); 40 | this->list[i].eSubType = (uint8_t)app->resource->shiftByte(); 41 | this->list[i].parm = (uint8_t)app->resource->shiftByte(); 42 | this->list[i].name = (int16_t)app->resource->shiftUByte(); 43 | this->list[i].longName = (int16_t)app->resource->shiftUByte(); 44 | this->list[i].description = (int16_t)app->resource->shiftUByte(); 45 | } 46 | 47 | IS.~InputStream(); 48 | 49 | /*for (int i = 0; i < this->numDefs; i++) { 50 | printf("list[%d]------------------------\n", i); 51 | printf("tileIndex %d\n", this->list[i].tileIndex); 52 | printf("eType %d\n", this->list[i].eType); 53 | printf("eSubType %d\n", this->list[i].eSubType); 54 | printf("parm %d\n", this->list[i].parm); 55 | printf("name %d\n", this->list[i].name); 56 | printf("longName %d\n", this->list[i].longName); 57 | printf("description %d\n", this->list[i].description); 58 | }*/ 59 | 60 | return true; 61 | } 62 | 63 | 64 | EntityDef* EntityDefManager::find(int eType, int eSubType) { 65 | return this->find(eType, eSubType, -1); 66 | } 67 | 68 | EntityDef* EntityDefManager::find(int eType, int eSubType, int parm) { 69 | for (int i = 0; i < this->numDefs; i++) { 70 | if (this->list[i].eType == eType && this->list[i].eSubType == eSubType && (parm == -1 || this->list[i].parm == parm)) { 71 | return &this->list[i]; 72 | } 73 | } 74 | return nullptr; 75 | } 76 | 77 | EntityDef* EntityDefManager::lookup(int tileIndex) { 78 | for (int i = 0; i < this->numDefs; ++i) { 79 | if (this->list[i].tileIndex == tileIndex) { 80 | return &this->list[i]; 81 | } 82 | } 83 | return nullptr; 84 | } 85 | 86 | // ---------------- 87 | // EntityDef Class 88 | // ---------------- 89 | 90 | EntityDef::EntityDef() { 91 | memset(this, 0, sizeof(EntityDef)); 92 | } 93 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/hmac.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // hmac.h 3 | // Copyright (c) 2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | // based on http://tools.ietf.org/html/rfc2104 10 | // see also http://en.wikipedia.org/wiki/Hash-based_message_authentication_code 11 | 12 | /** Usage: 13 | std::string msg = "The quick brown fox jumps over the lazy dog"; 14 | std::string key = "key"; 15 | std::string md5hmac = hmac< MD5 >(msg, key); 16 | std::string sha1hmac = hmac< SHA1 >(msg, key); 17 | std::string sha2hmac = hmac(msg, key); 18 | 19 | Note: 20 | To keep my code simple, HMAC computation currently needs the whole message at once. 21 | This is in contrast to the hashes MD5, SHA1, etc. where an add() method is available 22 | for incremental computation. 23 | You can use any hash for HMAC as long as it provides: 24 | - constant HashMethod::BlockSize (typically 64) 25 | - constant HashMethod::HashBytes (length of hash in bytes, e.g. 20 for SHA1) 26 | - HashMethod::add(buffer, bufferSize) 27 | - HashMethod::getHash(unsigned char buffer[HashMethod::BlockSize]) 28 | */ 29 | 30 | #include 31 | #include // memcpy 32 | 33 | /// compute HMAC hash of data and key using MD5, SHA1 or SHA256 34 | template 35 | std::string hmac(const void* data, size_t numDataBytes, const void* key, size_t numKeyBytes) 36 | { 37 | // initialize key with zeros 38 | unsigned char usedKey[HashMethod::BlockSize] = {0}; 39 | 40 | // adjust length of key: must contain exactly blockSize bytes 41 | if (numKeyBytes <= HashMethod::BlockSize) 42 | { 43 | // copy key 44 | memcpy(usedKey, key, numKeyBytes); 45 | } 46 | else 47 | { 48 | // shorten key: usedKey = hashed(key) 49 | HashMethod keyHasher; 50 | keyHasher.add(key, numKeyBytes); 51 | keyHasher.getHash(usedKey); 52 | } 53 | 54 | // create initial XOR padding 55 | for (size_t i = 0; i < HashMethod::BlockSize; i++) 56 | usedKey[i] ^= 0x36; 57 | 58 | // inside = hash((usedKey ^ 0x36) + data) 59 | unsigned char inside[HashMethod::HashBytes]; 60 | HashMethod insideHasher; 61 | insideHasher.add(usedKey, HashMethod::BlockSize); 62 | insideHasher.add(data, numDataBytes); 63 | insideHasher.getHash(inside); 64 | 65 | // undo usedKey's previous 0x36 XORing and apply a XOR by 0x5C 66 | for (size_t i = 0; i < HashMethod::BlockSize; i++) 67 | usedKey[i] ^= 0x5C ^ 0x36; 68 | 69 | // hash((usedKey ^ 0x5C) + hash((usedKey ^ 0x36) + data)) 70 | HashMethod finalHasher; 71 | finalHasher.add(usedKey, HashMethod::BlockSize); 72 | finalHasher.add(inside, HashMethod::HashBytes); 73 | 74 | return finalHasher.getHash(); 75 | } 76 | 77 | 78 | /// convenience function for std::string 79 | template 80 | std::string hmac(const std::string& data, const std::string& key) 81 | { 82 | return hmac(data.c_str(), data.size(), key.c_str(), key.size()); 83 | } 84 | -------------------------------------------------------------------------------- /src/LerpSprite.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "LerpSprite.h" 4 | #include "CAppContainer.h" 5 | #include "App.h" 6 | #include "Game.h" 7 | #include "Render.h" 8 | #include "JavaStream.h" 9 | #include "Enums.h" 10 | 11 | LerpSprite::LerpSprite() { 12 | } 13 | 14 | LerpSprite::~LerpSprite() { 15 | } 16 | 17 | void LerpSprite::saveState(OutputStream* OS) { 18 | Applet* app = CAppContainer::getInstance()->app; 19 | if (this->hSprite == 0) { 20 | return; 21 | } 22 | OS->writeInt(this->travelTime); 23 | OS->writeInt(app->gameTime - this->startTime); 24 | OS->writeShort((int16_t)this->hSprite); 25 | OS->writeShort((int16_t)app->render->mapSprites[app->render->S_X + this->hSprite - 1]); 26 | OS->writeShort((int16_t)app->render->mapSprites[app->render->S_Y + this->hSprite - 1]); 27 | OS->writeShort((int16_t)app->render->mapSprites[app->render->S_Z + this->hSprite - 1]); 28 | OS->writeShort((int16_t)this->srcX); 29 | OS->writeShort((int16_t)this->srcY); 30 | OS->writeShort((int16_t)this->srcZ); 31 | OS->writeShort((int16_t)this->dstX); 32 | OS->writeShort((int16_t)this->dstY); 33 | OS->writeShort((int16_t)this->dstZ); 34 | OS->writeShort((int16_t)this->height); 35 | OS->writeByte((uint8_t)this->srcScale); 36 | OS->writeByte((uint8_t)this->dstScale); 37 | OS->writeShort((int16_t)this->flags); 38 | if (this->thread != nullptr) { 39 | OS->writeByte((uint8_t)this->thread->getIndex()); 40 | } 41 | else { 42 | OS->writeByte((uint8_t)-1); 43 | } 44 | } 45 | 46 | void LerpSprite::calcDist() { 47 | Applet* app = CAppContainer::getInstance()->app; 48 | this->dist = (int)(app->game->FixedSqrt((this->dstX - this->srcX) * (this->dstX - this->srcX) + (this->dstY - this->srcY) * (this->dstY - this->srcY) << 8) >> 8); 49 | } 50 | 51 | void LerpSprite::loadState(InputStream* IS) { 52 | Applet* app = CAppContainer::getInstance()->app; 53 | this->travelTime = IS->readInt(); 54 | this->startTime = app->gameTime - IS->readInt(); 55 | this->hSprite = IS->readShort(); 56 | int n = this->hSprite - 1; 57 | app->render->mapSprites[app->render->S_X + n] = IS->readShort(); 58 | app->render->mapSprites[app->render->S_Y + n] = IS->readShort(); 59 | app->render->mapSprites[app->render->S_Z + n] = IS->readShort(); 60 | app->render->relinkSprite(n); 61 | this->srcX = IS->readShort(); 62 | this->srcY = IS->readShort(); 63 | this->srcZ = IS->readShort(); 64 | this->dstX = IS->readShort(); 65 | this->dstY = IS->readShort(); 66 | this->dstZ = IS->readShort(); 67 | this->height = IS->readShort(); 68 | this->srcScale = (int)IS->readByte(); 69 | this->dstScale = (int)IS->readByte(); 70 | this->flags = IS->readShort(); 71 | int index = IS->readSignedByte(); 72 | if (index == -1) { 73 | this->thread = nullptr; 74 | } 75 | else { 76 | this->thread = &app->game->scriptThreads[index]; 77 | } 78 | if (this->flags & Enums::LS_FLAG_ANIMATING_EFFECT) { 79 | ++app->game->animatingEffects; 80 | } 81 | this->calcDist(); 82 | } 83 | -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include "SDLGL.h" 7 | #include "ZipFile.h" 8 | 9 | #include "CAppContainer.h" 10 | #include "App.h" 11 | #include "Image.h" 12 | #include "Resource.h" 13 | #include "Render.h" 14 | #include "GLES.h" 15 | 16 | #include "Canvas.h" 17 | #include "Graphics.h" 18 | #include "Player.h" 19 | #include "Game.h" 20 | #include "Graphics.h" 21 | #include "Utils.h" 22 | #include "TinyGL.h" 23 | #include "Input.h" 24 | 25 | void drawView(SDLGL* sdlGL); 26 | 27 | int main(int argc, char* args[]) { 28 | int UpTime = 0; 29 | 30 | if (UpTime == 0) { 31 | UpTime = CAppContainer::getInstance()->getTimeMS(); 32 | } 33 | 34 | ZipFile zipFile; 35 | zipFile.openZipFile("Wolfenstein RPG.ipa"); 36 | 37 | SDLGL sdlGL; 38 | sdlGL.Initialize(); 39 | 40 | Input input; 41 | input.init(); // [GEC] Port: set default Binds 42 | 43 | CAppContainer::getInstance()->Construct(&sdlGL, &zipFile); 44 | sdlGL.updateVideo(); // [GEC] 45 | 46 | while (CAppContainer::getInstance()->app->closeApplet != true) { 47 | int currentTimeMillis = CAppContainer::getInstance()->getTimeMS(); 48 | if (currentTimeMillis > UpTime) { 49 | input.handleEvents(); 50 | UpTime = currentTimeMillis + 15; 51 | drawView(&sdlGL); 52 | input.consumeEvents(); 53 | } 54 | } 55 | 56 | printf("APP_QUIT\n"); 57 | CAppContainer::getInstance()->~CAppContainer(); 58 | zipFile.closeZipFile(); 59 | sdlGL.~SDLGL(); 60 | input.~Input(); 61 | return 0; 62 | } 63 | 64 | 65 | static uint32_t lastTimems = 0; 66 | 67 | void drawView(SDLGL *sdlGL) { 68 | 69 | int cx, cy; 70 | int w = sdlGL->vidWidth; 71 | int h = sdlGL->vidHeight; 72 | 73 | if (lastTimems == 0) { 74 | lastTimems = CAppContainer::getInstance()->getTimeMS(); 75 | } 76 | 77 | SDL_GetWindowSize(sdlGL->window, &cx, &cy); 78 | if (w != cx || h != cy) { 79 | w = cx; h = cy; 80 | } 81 | 82 | glViewport(0, 0, (GLsizei)w, (GLsizei)h); 83 | glDisable(GL_DEPTH_TEST); 84 | glDisable(GL_ALPHA_TEST); 85 | glMatrixMode(GL_PROJECTION); 86 | glLoadIdentity(); 87 | glOrtho(0.0, Applet::IOS_WIDTH, Applet::IOS_HEIGHT, 0.0, -1.0, 1.0); 88 | //glRotatef(90.0, 0.0, 0.0, 1.0); 89 | //glTranslatef(0.0, -320.0, 0.0); 90 | glMatrixMode(GL_MODELVIEW); 91 | glLoadIdentity(); 92 | glClearColor(0.0, 0.0, 0.0, 1.0); 93 | glClear(GL_COLOR_BUFFER_BIT); 94 | 95 | 96 | uint32_t startTime = CAppContainer::getInstance()->getTimeMS(); 97 | uint32_t passedTime = startTime - lastTimems; 98 | lastTimems = startTime; 99 | 100 | if (passedTime >= 125) { 101 | passedTime = 125; 102 | } 103 | //printf("passedTime %d\n", passedTime); 104 | 105 | CAppContainer::getInstance()->DoLoop(passedTime); 106 | 107 | SDL_GL_SwapWindow(sdlGL->window); // Swap the window/pBmp to display the result. 108 | 109 | } -------------------------------------------------------------------------------- /src/EntityMonster.h: -------------------------------------------------------------------------------- 1 | #ifndef __ENTITYMONSTER_H__ 2 | #define __ENTITYMONSTER_H__ 3 | 4 | #include "CombatEntity.h" 5 | class OutputStream; 6 | class InputStream; 7 | class CombatEntity; 8 | class Entity; 9 | 10 | class EntityMonster 11 | { 12 | private: 13 | 14 | public: 15 | 16 | static constexpr int GOAL_NONE = 0; 17 | static constexpr int GOAL_MOVE = 1; 18 | static constexpr int GOAL_MOVETOENTITY = 2; 19 | static constexpr int GOAL_FIGHT = 3; 20 | static constexpr int GOAL_FLEE = 4; 21 | static constexpr int GOAL_EVADE = 5; 22 | static constexpr int GOAL_STUN = 6; 23 | static constexpr int GFL_LERPING = 1; 24 | static constexpr int GFL_SPECIAL = 2; 25 | static constexpr int GFL_MOVE2ATTACK = 4; 26 | static constexpr int GFL_ATTACK2EVADE = 8; 27 | static constexpr int GFL_MOVEAGAIN = 16; 28 | static constexpr int GFL_STEALTHMOVE = 32; 29 | static constexpr int GFL_RAMBOMOVE = 64; 30 | static constexpr int MAX_GOAL_TURNS = 16; 31 | 32 | static constexpr int DEFAULT_PAIN_TIME = 250; 33 | 34 | static constexpr int MFX_COUNT = 5; 35 | static constexpr int MFX_NONE = 0; 36 | static constexpr int MFX_POISON = 1; 37 | static constexpr int MFX_FREEZE = 2; 38 | static constexpr int MFX_RAISE_TIMER = 4; 39 | static constexpr int MFX_FIRE = 8; 40 | static constexpr int MFX_SHIELD = 16; 41 | 42 | static constexpr int MFX_MAX = 16; 43 | static constexpr int MFX_MASK_ALL = (MFX_POISON | MFX_FREEZE | MFX_RAISE_TIMER | MFX_FIRE | MFX_SHIELD); // 31 44 | 45 | static constexpr int MFX_POISON_SHIFT = 5; // 1 << 5 = 32 46 | static constexpr int MFX_FREEZE_SHIFT = 7; // 1 << 7 = 128 47 | static constexpr int MFX_RAISE_SHIFT = 9; // 1 << 9 = 512 48 | static constexpr int MFX_FIRE_SHIFT = 11; // 1 << 11 = 2048 49 | static constexpr int MFX_SHIELD_SHIFT = 13; // 1 << 13 = 8192 50 | 51 | static constexpr int MFX_TURN_MASK = 3; 52 | static constexpr int MFX_POISON_REMOVE = ~((MFX_TURN_MASK << MFX_POISON_SHIFT) | MFX_POISON); // -98 53 | static constexpr int MFX_FREEZE_REMOVE = ~((MFX_TURN_MASK << MFX_FREEZE_SHIFT) | MFX_FREEZE); // -387 54 | static constexpr int MFX_RAISE_REMOVE = ~((MFX_TURN_MASK << MFX_RAISE_SHIFT) | MFX_RAISE_TIMER); // -1541 55 | static constexpr int MFX_FIRE_REMOVE = ~((MFX_TURN_MASK << MFX_FIRE_SHIFT) | MFX_FIRE); // -6153 56 | static constexpr int MFX_SHIELD_REMOVE = ~((MFX_TURN_MASK << MFX_SHIELD_SHIFT) | MFX_SHIELD); // -24593 57 | static constexpr int MFX_REMOVE_TURNS = ~((MFX_TURN_MASK << MFX_POISON_SHIFT) | (MFX_TURN_MASK << MFX_FREEZE_SHIFT) | (MFX_TURN_MASK << MFX_RAISE_SHIFT) | (MFX_TURN_MASK << MFX_FIRE_SHIFT) | (MFX_TURN_MASK << MFX_SHIELD_SHIFT)); // -32737 58 | static constexpr int MFX_ALL_ONE_TURNS = ((1 << MFX_POISON_SHIFT) | (1 << MFX_FREEZE_SHIFT) | (1 << MFX_FIRE_SHIFT) | (1 << MFX_SHIELD_SHIFT) /*| (1 << MFX_RAISE_SHIFT)*/); // 10400 59 | 60 | int touchMe; 61 | CombatEntity ce; 62 | Entity* nextOnList; 63 | Entity* prevOnList; 64 | Entity* nextAttacker; 65 | Entity* target; 66 | int frameTime; 67 | short flags; 68 | short monsterEffects; 69 | uint8_t goalType; 70 | uint8_t goalFlags; 71 | uint8_t goalTurns; 72 | int goalX; 73 | int goalY; 74 | int goalParam; 75 | 76 | // Constructor 77 | EntityMonster(); 78 | 79 | void clearEffects(); 80 | void reset(); 81 | void saveGoalState(OutputStream* OS); 82 | void loadGoalState(InputStream* IS); 83 | void resetGoal(); 84 | }; 85 | 86 | #endif -------------------------------------------------------------------------------- /src/Graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef __GRAPHICS_H__ 2 | #define __GRAPHICS_H__ 3 | 4 | class IDIB; 5 | class Image; 6 | class Text; 7 | 8 | class Graphics 9 | { 10 | private: 11 | 12 | public: 13 | 14 | static constexpr short ANCHORS_NONE = 0; 15 | static constexpr short ANCHORS_HCENTER = 1; 16 | static constexpr short ANCHORS_VCENTER = 2; 17 | static constexpr short ANCHORS_LEFT = 4; 18 | static constexpr short ANCHORS_RIGHT = 8; 19 | static constexpr short ANCHORS_TOP = 16; 20 | static constexpr short ANCHORS_BOTTOM = 32; 21 | static constexpr short ANCHORS_TOP_CENTER = 17; 22 | static constexpr short ANCHORS_CENTER = 3; 23 | static constexpr short ANCHORS_HORIZONTAL = 13; 24 | static constexpr short ANCHORS_VERTICAL = 50; 25 | 26 | static constexpr uint32_t charColors[12] = { 27 | 0xFFFFFFFF, 0xFFFF0000, 0xFF00FF00, 0xFF8BBC5D, 28 | 0xFF0000FF, 0xFF3180C3, 0xFFFFAFCC, 0xFFFF7F00, 29 | 0xFF7F7F7F, 0xFF000000, 0xFF3F3F3F, 0xFFBFBFBF }; 30 | 31 | int curColor; 32 | int currentCharColor; 33 | IDIB* backBuffer; 34 | int graphClipRect[4]; 35 | int transX; 36 | int transY; 37 | 38 | // Constructor 39 | Graphics(); 40 | // Destructor 41 | ~Graphics(); 42 | 43 | void setGraphics(); 44 | void setColor(int color); 45 | void fillCircle(int x, int y, int rad); 46 | void fillRect(int x, int y, int w, int h); 47 | void fillRect(int x, int y, int w, int h, int color); 48 | void FMGL_fillRect(int x, int y, int w, int h, float r, float g, float b, float a); 49 | void drawRect(int x, int y, int w, int h); 50 | void drawRect(int x, int y, int w, int h, int color); 51 | void eraseRgn(int x, int y, int w, int h); 52 | void eraseRgn(int* rect); 53 | void drawLine(int x1, int y1, int x2, int y2); 54 | void drawLine(int x1, int y1, int x2, int y2, int color); 55 | void drawImage(Image* img, int x, int y, int flags, int rotateMode, int renderMode); 56 | void drawRegion(Image* img, int texX, int texY, int texW, int texH, int posX, int posY, int flags, int rotateMode, int renderMode); 57 | void fillRegion(Image* img, int x, int y, int w, int h); 58 | void fillRegion(Image* img, int x, int y, int w, int h, int rotateMode); 59 | void fillRegion(Image* img, int texX, int texY, int texW, int texH, int x, int y, int w, int h, int rotateMode); 60 | void drawBevel(int color1, int color2, int x, int y, int w, int h); 61 | void drawString(Text* text, int x, int y, int flags); 62 | void drawString(Text* text, int x, int y, int flags, int strBeg, int strEnd); 63 | void drawString(Text* text, int x, int y, int h, int flags, int strBeg, int strEnd); 64 | void drawString(Image* img, Text* text, int x, int y, int h, int flags, int strBeg, int strEnd); 65 | void drawChar(Image* img, char c, int x, int y, int rotateMode); 66 | void drawBuffIcon(int texY, int posX, int posY, int flags); 67 | void drawBuffIconHelp(int texY, int posX, int posY, int flags); 68 | void drawBoxedString(Text* text, int n, int n2, int n3, int color, int color2); 69 | void drawCursor(int x, int y, int flags); 70 | void drawCursor(int x, int y, int flags, bool b); 71 | void clipRect(int x, int y, int w, int h); 72 | void setClipRect(int x, int y, int w, int h); 73 | void clearClipRect(); 74 | void setScreenSpace(int* rect); 75 | void setScreenSpace(int x, int y, int w, int h); 76 | void resetScreenSpace(); 77 | void fade(int* rect, int alpha, int color); 78 | void drawPixelPortal(int* rect, int x, int y, uint32_t color); 79 | }; 80 | 81 | #endif -------------------------------------------------------------------------------- /src/Sound.h: -------------------------------------------------------------------------------- 1 | #ifndef __SOUND_H__ 2 | #define __SOUND_H__ 3 | #ifdef _WIN32 4 | #include 5 | #include 6 | #else 7 | #include 8 | #include 9 | #endif 10 | 11 | typedef uint32_t AudioFormatID; 12 | typedef uint32_t AudioFormatFlags; 13 | typedef uint32_t AudioFileID; 14 | struct AudioStreamBasicDescription 15 | { 16 | uint32_t mSampleRate; 17 | AudioFormatID mFormatID; 18 | AudioFormatFlags mFormatFlags; 19 | uint32_t mBytesPerPacket; 20 | uint32_t mFramesPerPacket; 21 | uint32_t mBytesPerFrame; 22 | uint32_t mChannelsPerFrame; 23 | uint32_t mBitsPerChannel; 24 | uint32_t mReserved; 25 | }; 26 | 27 | struct wav_header_t { 28 | char chunkID[4]; // "RIFF" = 0x46464952 29 | uint32_t chunkSize; 30 | char format[4]; // "WAVE" = 0x45564157 31 | char subchunk1ID[4]; // "fmt " = 0x20746D66 32 | uint32_t subchunk1Size; 33 | uint16_t audioFormat; 34 | uint16_t numChannels; 35 | uint32_t sampleRate; 36 | uint32_t byteRate; 37 | uint16_t blockAlign; 38 | uint16_t bitsPerSample; 39 | }; 40 | 41 | class Applet; 42 | 43 | 44 | class Sound 45 | { 46 | private: 47 | 48 | public: 49 | 50 | class SoundStream 51 | { 52 | public: 53 | ALuint bufferId; 54 | ALuint sourceId; 55 | int16_t resID; 56 | int16_t priority; 57 | bool fadeInProgress; 58 | int volume; 59 | int fadeBeg; 60 | int fadetime; 61 | float fadeVolume; 62 | 63 | void StartFade(int volume, int fadeBeg, int fadeEnd); 64 | }; 65 | 66 | Applet* app; 67 | bool field_0x4; 68 | bool allowSounds; 69 | bool allowMusics; 70 | int soundFxVolume; 71 | int musicVolume; 72 | int field_0x10; 73 | SoundStream channel[10]; 74 | short resID; 75 | uint8_t flags; 76 | int priority; 77 | int field_0x15c; 78 | short field_0x160; 79 | uint8_t field_0x162; 80 | bool soundsLoaded; 81 | ALCcontext* alContext; 82 | ALCdevice* alDevice; 83 | 84 | // Constructor 85 | Sound(); 86 | // Destructor 87 | ~Sound(); 88 | 89 | bool startup(); 90 | void openAL_Init(); 91 | void openAL_Close(); 92 | void openAL_SetSystemVolume(int volume); 93 | void openAL_SetVolume(ALuint source, int volume); 94 | void openAL_Suspend(); 95 | void openAL_Resume(); 96 | bool openAL_IsPlaying(ALuint source); 97 | bool openAL_IsPaused(ALuint source); 98 | bool openAL_GetALFormat(AudioStreamBasicDescription aStreamBD, ALenum* format); 99 | void openAL_PlaySound(ALuint source, ALint loop); 100 | void openAL_LoadSound(int resID, Sound::SoundStream* channel); 101 | bool openAL_LoadWAVFromFile(ALuint bufferId, const char* fileName); 102 | bool openAL_LoadAudioFileData(const char* fileName, ALenum* format, ALvoid** data, ALsizei* size, ALsizei* freq); 103 | bool openAL_OpenAudioFile(const char* fileName, InputStream* IS); 104 | bool openAL_LoadAllSounds(); 105 | 106 | bool cacheSounds(); 107 | void playSound(int16_t resID, uint8_t flags, int priority, bool a5); 108 | int getFreeSlot(int a2); 109 | void soundStop(); 110 | void stopSound(int resID, bool fadeOut); 111 | bool isSoundPlaying(int16_t resID); 112 | void updateVolume(); 113 | void playCombatSound(int16_t resID, uint8_t flags, int priority); 114 | bool cacheCombatSound(int resID); 115 | void freeMonsterSounds(); 116 | 117 | void volumeUp(int volume); 118 | void volumeDown(int volume); 119 | void startFrame(); 120 | void endFrame(); 121 | void updateFades(); 122 | void musicVolumeUp(int volume); // [GEC] 123 | void musicVolumeDown(int volume); // [GEC] 124 | }; 125 | 126 | #endif -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/digest.cpp: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // digest.cpp 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | // g++ -O3 digest.cpp crc32.cpp md5.cpp sha1.cpp sha256.cpp keccak.cpp sha3.cpp -o digest 8 | 9 | #include "crc32.h" 10 | #include "md5.h" 11 | #include "sha1.h" 12 | #include "sha256.h" 13 | #include "keccak.h" 14 | #include "sha3.h" 15 | 16 | #include 17 | #include 18 | 19 | int main(int argc, char** argv) 20 | { 21 | // syntax check 22 | if (argc < 2 || argc > 3) 23 | { 24 | std::cout << "./digest filename [--crc|--md5|--sha1|--sha256|--keccak|--sha3]" << std::endl; 25 | return 1; 26 | } 27 | 28 | // parameters 29 | std::string filename = argv[1]; 30 | std::string algorithm = argc == 3 ? argv[2] : ""; 31 | bool computeCrc32 = algorithm.empty() || algorithm == "--crc"; 32 | bool computeMd5 = algorithm.empty() || algorithm == "--md5"; 33 | bool computeSha1 = algorithm.empty() || algorithm == "--sha1"; 34 | bool computeSha2 = algorithm.empty() || algorithm == "--sha2" || algorithm == "--sha256"; 35 | bool computeKeccak = algorithm.empty() || algorithm == "--keccak"; 36 | bool computeSha3 = algorithm.empty() || algorithm == "--sha3"; 37 | 38 | CRC32 digestCrc32; 39 | MD5 digestMd5; 40 | SHA1 digestSha1; 41 | SHA256 digestSha2; 42 | Keccak digestKeccak(Keccak::Keccak256); 43 | SHA3 digestSha3 (SHA3 ::Bits256); 44 | 45 | // each cycle processes about 1 MByte (divisible by 144 => improves Keccak/SHA3 performance) 46 | const size_t BufferSize = 144*7*1024; 47 | char* buffer = new char[BufferSize]; 48 | 49 | // select input source: either file or standard-in 50 | std::ifstream file; 51 | std::istream* input = NULL; 52 | // accept std::cin, syntax will be: "./digest - --sha3 < data" 53 | if (filename == "-") 54 | { 55 | input = &std::cin; 56 | } 57 | else 58 | { 59 | // open file 60 | file.open(filename.c_str(), std::ios::in | std::ios::binary); 61 | if (!file) 62 | { 63 | std::cerr << "Can't open '" << filename << "'" << std::endl; 64 | return 2; 65 | } 66 | 67 | input = &file; 68 | } 69 | 70 | // process file 71 | while (*input) 72 | { 73 | input->read(buffer, BufferSize); 74 | std::size_t numBytesRead = size_t(input->gcount()); 75 | 76 | if (computeCrc32) 77 | digestCrc32 .add(buffer, numBytesRead); 78 | if (computeMd5) 79 | digestMd5 .add(buffer, numBytesRead); 80 | if (computeSha1) 81 | digestSha1 .add(buffer, numBytesRead); 82 | if (computeSha2) 83 | digestSha2 .add(buffer, numBytesRead); 84 | if (computeKeccak) 85 | digestKeccak.add(buffer, numBytesRead); 86 | if (computeSha3) 87 | digestSha3 .add(buffer, numBytesRead); 88 | } 89 | 90 | // clean up 91 | file.close(); 92 | delete[] buffer; 93 | 94 | // show results 95 | if (computeCrc32) 96 | std::cout << "CRC32: " << digestCrc32 .getHash() << std::endl; 97 | if (computeMd5) 98 | std::cout << "MD5: " << digestMd5 .getHash() << std::endl; 99 | if (computeSha1) 100 | std::cout << "SHA1: " << digestSha1 .getHash() << std::endl; 101 | if (computeSha2) 102 | std::cout << "SHA2/256: " << digestSha2 .getHash() << std::endl; 103 | if (computeKeccak) 104 | std::cout << "Keccak/256: " << digestKeccak.getHash() << std::endl; 105 | if (computeSha3) 106 | std::cout << "SHA3/256: " << digestSha3 .getHash() << std::endl; 107 | 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /cmake/Modules/FindSDL2_mixer.cmake: -------------------------------------------------------------------------------- 1 | # - Locate SDL2_mixer library (modified from Cmake's FindSDL_mixer.cmake) 2 | # This module defines: 3 | # SDL2_MIXER_FOUND, if false, do not try to link against 4 | # SDL2::mixer, the import target for SDL2_mixer 5 | # 6 | # For backward compatiblity the following variables are also set: 7 | # SDL2MIXER_FOUND (same value as SDL2_MIXER_FOUND) 8 | # 9 | # $SDLDIR is an environment variable that would 10 | # correspond to the ./configure --prefix=$SDLDIR 11 | # used in building SDL. 12 | # 13 | #============================================================================= 14 | # Copyright 2014 Justin Jacobs 15 | # Copyright 2017 Alex Mayfield 16 | # 17 | # Distributed under the OSI-approved BSD License (the "License"); 18 | # see accompanying file Copyright.txt for details. 19 | # 20 | # This software is distributed WITHOUT ANY WARRANTY; without even the 21 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 | # See the License for more information. 23 | #============================================================================= 24 | 25 | add_library(SDL2::mixer UNKNOWN IMPORTED) 26 | 27 | if(NOT SDL2_MIXER_INCLUDE_DIR AND SDL2MIXER_INCLUDE_DIR) 28 | set(SDL2_MIXER_INCLUDE_DIR ${SDL2MIXER_INCLUDE_DIR} CACHE PATH "directory cache 29 | entry initialized from old variable name") 30 | endif() 31 | find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h 32 | HINTS 33 | ENV SDLMIXERDIR 34 | ENV SDLDIR 35 | PATH_SUFFIXES include/SDL2 include 36 | ) 37 | if(SDL2_MIXER_INCLUDE_DIR) 38 | set_property(TARGET SDL2::mixer PROPERTY INTERFACE_INCLUDE_DIRECTORIES 39 | ${SDL2_MIXER_INCLUDE_DIR}) 40 | endif() 41 | 42 | if(NOT SDL2_MIXER_LIBRARY AND SDL2MIXER_LIBRARY) 43 | set(SDL2_MIXER_LIBRARY ${SDL2MIXER_LIBRARY} CACHE FILEPATH "file cache entry 44 | initialized from old variable name") 45 | endif() 46 | find_library(SDL2_MIXER_LIBRARY 47 | NAMES SDL2_mixer 48 | HINTS 49 | ENV SDLMIXERDIR 50 | ENV SDLDIR 51 | PATH_SUFFIXES lib 52 | ) 53 | if(SDL2_MIXER_LIBRARY) 54 | set_property(TARGET SDL2::mixer PROPERTY IMPORTED_LOCATION ${SDL2_MIXER_LIBRARY}) 55 | endif() 56 | 57 | if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") 58 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") 59 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") 60 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") 61 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") 62 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") 63 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") 64 | set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) 65 | unset(SDL2_MIXER_VERSION_MAJOR_LINE) 66 | unset(SDL2_MIXER_VERSION_MINOR_LINE) 67 | unset(SDL2_MIXER_VERSION_PATCH_LINE) 68 | unset(SDL2_MIXER_VERSION_MAJOR) 69 | unset(SDL2_MIXER_VERSION_MINOR) 70 | unset(SDL2_MIXER_VERSION_PATCH) 71 | endif() 72 | 73 | include(FindPackageHandleStandardArgs) 74 | 75 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer 76 | REQUIRED_VARS SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR 77 | VERSION_VAR SDL2_MIXER_VERSION_STRING) 78 | 79 | # for backward compatiblity 80 | set(SDL2MIXER_FOUND ${SDL2_MIXER_FOUND}) 81 | 82 | -------------------------------------------------------------------------------- /src/Span.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPAN_H__ 2 | #define __SPAN_H__ 3 | #include 4 | 5 | class TinyGL; 6 | 7 | typedef void (*SpanFunc)(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 8 | typedef void (*SpanFuncStretch)(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 9 | 10 | typedef struct _SpanMode { 11 | SpanFunc Normal; 12 | SpanFunc DT; 13 | SpanFunc DS; 14 | SpanFuncStretch Stretch; 15 | }SpanMode; 16 | 17 | typedef struct _SpanType { 18 | SpanMode* Span; 19 | }SpanType; 20 | 21 | 22 | extern void spanNoDraw(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 23 | extern void spanNoDrawStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 24 | 25 | extern void spanTransparent(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 26 | extern void spanTransparentDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 27 | extern void spanTransparentDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 28 | extern void spanTransparentStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 29 | 30 | extern void spanBlend50Transparent(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 31 | extern void spanBlend50TransparentDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 32 | extern void spanBlend50TransparentDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 33 | extern void spanBlend50TransparentStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 34 | 35 | extern void spanAddTransparent(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 36 | extern void spanAddTransparentDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 37 | extern void spanAddTransparentDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 38 | extern void spanAddTransparentStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 39 | 40 | extern void spanSubTransparent(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 41 | extern void spanSubTransparentDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 42 | extern void spanSubTransparentDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 43 | extern void spanSubTransparentStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 44 | 45 | extern void spanPerfTexture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 46 | extern void spanPerfTextureStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 47 | 48 | extern void spanTexture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 49 | extern void spanTextureDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 50 | extern void spanTextureDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 51 | 52 | extern void spanBlend25Texture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 53 | extern void spanBlend25TextureDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 54 | extern void spanBlend25TextureDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 55 | 56 | extern void spanAddTexture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 57 | extern void spanAddTextureDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 58 | extern void spanAddTextureDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 59 | 60 | extern void spanSubTexture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 61 | extern void spanSubTextureDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 62 | extern void spanSubTextureDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 63 | 64 | 65 | 66 | #endif -------------------------------------------------------------------------------- /src/Resource.h: -------------------------------------------------------------------------------- 1 | #ifndef __RESOURCE_H__ 2 | #define __RESOURCE_H__ 3 | 4 | #include "JavaStream.h" 5 | 6 | class InputStream; 7 | 8 | class Resources 9 | { 10 | public: 11 | static constexpr char* RES_LOGO_BMP_GZ = "logo.bmp"; 12 | static constexpr char* RES_LOGO2_BMP_GZ = "logo2.bmp"; 13 | static constexpr char* RES_STRINGS_IDX_GZ = "strings.idx"; 14 | static constexpr char* RES_TABLES_BIN_GZ = "tables.bin"; 15 | static constexpr char* RES_STRINGS_ARRAY[] = { "strings00.bin", "strings01.bin", "strings02.bin", "strings03.bin", "strings04.bin", "strings05.bin", "strings06.bin", "strings07.bin" }; 16 | static constexpr char* RES_ENTITIES_BIN_GZ = "entities.bin"; 17 | static constexpr char* RES_MENUS_BIN_GZ = "menus.bin"; 18 | static constexpr char* RES_NEWMAPPINGS_BIN_GZ = "newMappings.bin"; 19 | static constexpr char* RES_MODEL_ARRAY[] = { "model_0000.bin" , "model_0001.bin", "model_0002.bin", "model_0003.bin", "model_0004.bin", "model_0005.bin", "model_0006.bin", "model_0007.bin", "model_0008.bin", "model_0009.bin" }; 20 | static constexpr char* RES_NEWPALETTES_BIN_GZ = "newPalettes.bin"; 21 | static constexpr char* RES_NEWTEXEL_FILE_ARRAY[] = { 22 | "newTexels000.bin", "newTexels001.bin", "newTexels002.bin", "newTexels003.bin", "newTexels004.bin", 23 | "newTexels005.bin", "newTexels006.bin", "newTexels007.bin", "newTexels008.bin", "newTexels009.bin", 24 | "newTexels010.bin", "newTexels011.bin", "newTexels012.bin", "newTexels013.bin", "newTexels014.bin", 25 | "newTexels015.bin", "newTexels016.bin", "newTexels017.bin", "newTexels018.bin", "newTexels019.bin", 26 | "newTexels020.bin", "newTexels021.bin", "newTexels022.bin", "newTexels023.bin", "newTexels024.bin", 27 | "newTexels025.bin", "newTexels026.bin", "newTexels027.bin", "newTexels028.bin", "newTexels029.bin", 28 | "newTexels030.bin", "newTexels031.bin", "newTexels032.bin", "newTexels033.bin", "newTexels034.bin", 29 | "newTexels035.bin", "newTexels036.bin", "newTexels037.bin", "newTexels038.bin" }; 30 | }; 31 | 32 | class Resource 33 | { 34 | private: 35 | 36 | public: 37 | static constexpr int IO_SIZE = 20480; 38 | 39 | int touchMe; 40 | int cursor; 41 | uint8_t* ioBuffer; 42 | int tableOffsets[32]; 43 | int prevOffset; 44 | InputStream prevIS; 45 | 46 | // Constructor 47 | Resource(); 48 | // Destructor 49 | ~Resource(); 50 | 51 | bool startup(); 52 | void readByteArray(InputStream* IS, uint8_t* dest, int off, int size); 53 | void readUByteArray(InputStream* IS, short* dest, int off, int size); 54 | void readCoordArray(InputStream* IS, short* dest, int off, int size); 55 | void readShortArray(InputStream* IS, short* dest, int off, int size); 56 | void readUShortArray(InputStream* IS, int* dest, int off, int size); 57 | void readIntArray(InputStream* IS, int* dest, int off, int size); 58 | void readMarker(InputStream* IS, int i); 59 | void readMarker(InputStream* IS); 60 | void writeMarker(OutputStream* OS, int i); 61 | void writeMarker(OutputStream* OS); 62 | void read(InputStream* IS, int i); 63 | void bufSkip(InputStream* IS, int off, bool updateLB); 64 | uint8_t byteAt(int i); 65 | uint8_t shiftByte(); 66 | short UByteAt(int i); 67 | short shiftUByte(); 68 | short shortAt(int i); 69 | short shiftShort(); 70 | int shiftUShort(); 71 | int shiftInt(); 72 | short shiftCoord(); 73 | int* readFileIndex(InputStream* IS); 74 | int* loadFileIndex(char* fileName); 75 | void initTableLoading(); 76 | void beginTableLoading(); 77 | void seekTable(int index); 78 | void finishTableLoading(); 79 | int getNumTableBytes(int index); 80 | int getNumTableShorts(int index); 81 | int getNumTableInts(int index); 82 | void loadByteTable(int8_t* array, int index); 83 | void loadShortTable(short* array, int index); 84 | void loadIntTable(int32_t* array, int index); 85 | void loadUByteTable(uint8_t* array, int index); 86 | void loadUShortTable(uint16_t* array, int index); 87 | }; 88 | 89 | #endif -------------------------------------------------------------------------------- /make-wolfenstein-rpg-linux-appimage.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | # This script packages up a Linux appimage for Wolfenstein RPG. 4 | # It will output the app image in the current directory along with some temporaries. 5 | # 6 | # It takes 4 arguments: 7 | # (1) The path to 'appimagetool'. 8 | # This can be downloaded from: https://github.com/AppImage/AppImageKit/releases 9 | # (2) The path to 'linuxdeploy'. 10 | # This can be downloaded from: https://github.com/linuxdeploy/linuxdeploy/releases 11 | # (3) The path to the Wolfenstein RPG source code (root folder). 12 | # (4) The path to the compiled binary for Wolfenstein RPG for the target architecture. 13 | # 14 | # Note: 'appimagetool' and 'linuxdeploy' might require various packages to be installed. 15 | # Run them and examine any errors to see what is missing. 16 | # 17 | # Install 18 | # wget -O appimagetool https://github.com/AppImage/AppImageKit/releases/latest/download/appimagetool-x86_64.AppImage 19 | # wget -O linuxdeploy https://github.com/linuxdeploy/linuxdeploy/releases/latest/download/linuxdeploy-x86_64.AppImage 20 | # 21 | # Make 22 | # sudo ./make-wolfenstein-rpg-linux-appimage.sh ./appimagetool ./linuxdeploy $(pwd) ./build/src/WolfensteinRPG 23 | # 24 | 25 | # Exit on any error 26 | set -e 27 | 28 | # Extract the input arguments 29 | if [ $# -ne 4 ]; then 30 | echo "Expected args: <'appimagetool' path> <'linuxdeploy' path> " 31 | exit 1 32 | fi 33 | 34 | export APP_IMAGE_TOOL_PATH="$1" 35 | export LINUX_DEPLOY_PATH="$2" 36 | export WOLFENSTEIN_RPG_ROOT_PATH="$3" 37 | export WOLFENSTEIN_RPG_BINARY_PATH="$4" 38 | 39 | # Various paths 40 | export APP_DIR_PATH="AppDir" 41 | export DESKTOP_FILE="WolfensteinRPG.desktop" 42 | export SRC_ICON_DIR="$WOLFENSTEIN_RPG_ROOT_PATH/assets" 43 | export SRC_MAIN_ICON_FILE_PATH="$SRC_ICON_DIR/app_icon_64.png" 44 | export DST_MAIN_ICON_FILE_PATH="WolfensteinRPG.png" 45 | 46 | # Ensure the WolfensteinRPG binary is executable 47 | chmod +x "$WOLFENSTEIN_RPG_BINARY_PATH" 48 | 49 | # Cleanup previous output and some temporaries 50 | rm -rf "$APP_DIR_PATH" 51 | rm -rf "$DESKTOP_FILE" 52 | rm -rf "$DST_MAIN_ICON_FILE_PATH" 53 | 54 | export BINARY_FILES=`find -type f -name "WolfensteinRPG*.AppImage"` 55 | 56 | for f in $BINARY_FILES; do 57 | rm "$f" 58 | done 59 | 60 | # Make the main icon accessible 61 | cp "$SRC_MAIN_ICON_FILE_PATH" "$DST_MAIN_ICON_FILE_PATH" 62 | 63 | # Generate the desktop file 64 | echo "[Desktop Entry]" > "$DESKTOP_FILE" 65 | echo "Name=WolfensteinRPG" >> "$DESKTOP_FILE" 66 | echo "Exec=WolfensteinRPG" >> "$DESKTOP_FILE" 67 | echo "Icon=WolfensteinRPG" >> "$DESKTOP_FILE" 68 | echo "Type=Application" >> "$DESKTOP_FILE" 69 | echo "Categories=Game" >> "$DESKTOP_FILE" 70 | 71 | # Use the 'linuxdeploy' tool to build the AppDir 72 | "$LINUX_DEPLOY_PATH" \ 73 | --appdir="$APP_DIR_PATH" \ 74 | --executable="$WOLFENSTEIN_RPG_BINARY_PATH" \ 75 | --desktop-file="$DESKTOP_FILE" \ 76 | --icon-filename="WolfensteinRPG" \ 77 | --icon-file="$DST_MAIN_ICON_FILE_PATH" \ 78 | --icon-file="$SRC_ICON_DIR/app_icon_8.png"\ 79 | --icon-file="$SRC_ICON_DIR/app_icon_16.png"\ 80 | --icon-file="$SRC_ICON_DIR/app_icon_20.png"\ 81 | --icon-file="$SRC_ICON_DIR/app_icon_22.png"\ 82 | --icon-file="$SRC_ICON_DIR/app_icon_24.png"\ 83 | --icon-file="$SRC_ICON_DIR/app_icon_28.png"\ 84 | --icon-file="$SRC_ICON_DIR/app_icon_32.png"\ 85 | --icon-file="$SRC_ICON_DIR/app_icon_36.png"\ 86 | --icon-file="$SRC_ICON_DIR/app_icon_42.png"\ 87 | --icon-file="$SRC_ICON_DIR/app_icon_48.png"\ 88 | --icon-file="$SRC_ICON_DIR/app_icon_64.png"\ 89 | --icon-file="$SRC_ICON_DIR/app_icon_72.png"\ 90 | --icon-file="$SRC_ICON_DIR/app_icon_96.png"\ 91 | --icon-file="$SRC_ICON_DIR/app_icon_128.png"\ 92 | --icon-file="$SRC_ICON_DIR/app_icon_160.png"\ 93 | --icon-file="$SRC_ICON_DIR/app_icon_192.png"\ 94 | --icon-file="$SRC_ICON_DIR/app_icon_256.png"\ 95 | --icon-file="$SRC_ICON_DIR/app_icon_384.png"\ 96 | --icon-file="$SRC_ICON_DIR/app_icon_480.png"\ 97 | --icon-file="$SRC_ICON_DIR/app_icon_512.png" 98 | 99 | # Generate the appimage from the AppDir, using 'appimagetool' 100 | "$APP_IMAGE_TOOL_PATH" "$APP_DIR_PATH" 101 | 102 | # Cleanup some temporaries (leave the AppDir for manual inspection however) 103 | rm -rf "$DESKTOP_FILE" 104 | rm -rf "$DST_MAIN_ICON_FILE_PATH" 105 | -------------------------------------------------------------------------------- /src/Button.h: -------------------------------------------------------------------------------- 1 | #ifndef __BUTTON_H__ 2 | #define __BUTTON_H__ 3 | 4 | class Image; 5 | class Graphics; 6 | 7 | // ------------------------ 8 | // GuiRect Class 9 | // ------------------------ 10 | 11 | class GuiRect 12 | { 13 | public: 14 | int x; 15 | int y; 16 | int w; 17 | int h; 18 | void Set(int x, int y, int w, int h); 19 | bool ContainsPoint(int x, int y); 20 | }; 21 | 22 | // --------------- 23 | // fmButton Class 24 | // --------------- 25 | 26 | class fmButton 27 | { 28 | private: 29 | 30 | public: 31 | fmButton* next; 32 | int buttonID; 33 | int selectedIndex; 34 | bool drawButton; 35 | bool highlighted; 36 | int normalRenderMode; 37 | int highlightRenderMode; 38 | bool drawTouchArea; 39 | Image* imgNormal; 40 | Image* imgHighlight; 41 | Image** ptrNormalImages; 42 | Image** ptrHighlightImages; 43 | int normalIndex; 44 | int highlightIndex; 45 | int centerX; 46 | int centerY; 47 | int highlightCenterX; 48 | int highlightCenterY; 49 | float normalRed; 50 | float normalGreen; 51 | float normalBlue; 52 | float normalAlpha; 53 | float highlightRed; 54 | float highlightGreen; 55 | float highlightBlue; 56 | float highlightAlpha; 57 | short soundResID; 58 | GuiRect touchArea; 59 | GuiRect touchAreaDrawing; // Port: New 60 | 61 | // Constructor 62 | fmButton(int buttonID, int x, int y, int w, int h, int soundResID); 63 | // Destructor 64 | ~fmButton(); 65 | 66 | void SetImage(Image* image, bool center); 67 | void SetImage(Image** ptrImages, int imgIndex, bool center); 68 | void SetHighlightImage(Image* imgHighlight, bool center); 69 | void SetHighlightImage(Image** ptrImgsHighlight, int imgHighlightIndex, bool center); 70 | void SetGraphic(int index); 71 | void SetTouchArea(int x, int y, int w, int h); 72 | void SetTouchArea(int x, int y, int w, int h, bool drawing); // Port: new 73 | void SetHighlighted(bool highlighted); 74 | void Render(Graphics* graphics); 75 | }; 76 | 77 | // ------------------------ 78 | // fmButtonContainer Class 79 | // ------------------------ 80 | 81 | class fmButtonContainer 82 | { 83 | private: 84 | 85 | public: 86 | fmButton* next; 87 | fmButton* prev; 88 | 89 | // Constructor 90 | fmButtonContainer(); 91 | // Destructor 92 | ~fmButtonContainer(); 93 | 94 | void AddButton(fmButton* button); 95 | fmButton* GetButton(int buttonID); 96 | fmButton* GetTouchedButton(int x, int y); 97 | int GetTouchedButtonID(int x, int y); 98 | int GetHighlightedButtonID(); 99 | void HighlightButton(int x, int y, bool highlighted); 100 | void SetGraphic(int index); 101 | void FlipButtons(); 102 | void Render(Graphics* graphics); 103 | }; 104 | 105 | // --------------------- 106 | // fmScrollButton Class 107 | // --------------------- 108 | 109 | class fmScrollButton 110 | { 111 | private: 112 | 113 | public: 114 | uint8_t field_0x0_; 115 | Image* imgBar; 116 | Image* imgBarTop; 117 | Image* imgBarMiddle; 118 | Image* imgBarBottom; 119 | uint8_t field_0x14_; 120 | bool field_0x15_; 121 | GuiRect barRect; 122 | GuiRect boxRect; 123 | uint8_t field_0x38_; 124 | int field_0x3c_; 125 | int field_0x40_; 126 | int field_0x44_; 127 | int field_0x48_; 128 | int field_0x4c_; 129 | float field_0x50_; 130 | int field_0x54_; 131 | int field_0x58_; 132 | int field_0x5c_; 133 | short soundResID; 134 | 135 | // Constructor 136 | fmScrollButton(int x, int y, int w, int h, bool b, int soundResID); 137 | // Destructor 138 | ~fmScrollButton(); 139 | 140 | //bool startup(); 141 | void SetScrollBarImages(Image* imgBar, Image* imgBarTop, Image* imgBarMiddle, Image* imgBarBottom); 142 | void SetScrollBox(int x, int y, int w, int h, int i); 143 | void SetScrollBox(int x, int y, int w, int h, int i, int i2); 144 | void SetContentTouchOffset(int x, int y); 145 | void UpdateContent(int x, int y); 146 | void SetTouchOffset(int x, int y); 147 | void Update(int x, int y); 148 | void Render(Graphics* graphics); 149 | }; 150 | 151 | // ------------------ 152 | // fmSwipeArea Class 153 | // ------------------ 154 | 155 | class fmSwipeArea 156 | { 157 | private: 158 | 159 | public: 160 | //typedef int SwipeDir; 161 | enum SwipeDir {Null = -1, Left, Right, Down, Up}; 162 | 163 | bool enable; 164 | bool touched; 165 | bool drawTouchArea; 166 | GuiRect rect; 167 | int begX; 168 | int begY; 169 | int curX; 170 | int curY; 171 | int field_0x22_; 172 | int endX; 173 | int endY; 174 | 175 | // Constructor 176 | fmSwipeArea(int x, int y, int w, int h, int endX, int endY); 177 | // Destructor 178 | ~fmSwipeArea(); 179 | 180 | int UpdateSwipe(int x, int y, SwipeDir* swDir); 181 | void Render(Graphics* graphics); 182 | }; 183 | 184 | #endif -------------------------------------------------------------------------------- /src/Sounds.h: -------------------------------------------------------------------------------- 1 | #ifndef __SOUNDS_H__ 2 | #define __SOUNDS_H__ 3 | 4 | class Sounds 5 | { 6 | public: 7 | static constexpr char* RESOURCE_FILE_NAMES[] = { 8 | "aiee.wav", // 0 9 | "Alarm.wav", 10 | "barFight.wav", 11 | "bridge_creak2.wav", 12 | "canals1.wav", 13 | "Chicken_Attack.wav", 14 | "Chicken_Death.wav", 15 | "Chicken_Idle.wav", 16 | "Chicken_Kicked.wav", 17 | "Dialog_Help.wav", 18 | "Dialog_Popup.wav", // 10 19 | "Door_Cell.wav", 20 | "Door_Close.wav", 21 | "Door_Locked.wav", 22 | "Door_Open.wav", 23 | "Door_Unlocked.wav", 24 | "Door_Wood_Close.wav", 25 | "Door_Wood_Open.wav", 26 | "dripping_r.wav", 27 | "earthquake.wav", 28 | "Elecrocute.wav", // 20 29 | "Elevator.wav", 30 | "EliteGuard_Alert.wav", 31 | "EliteGuard_Death.wav", 32 | "EliteGuard_Pain.wav", 33 | "fire1.wav", 34 | "firesoft.wav", 35 | "fl_fire.wav", 36 | "forest_amb_01.wav", 37 | "fuel.wav", 38 | "fuelmotor1.wav", // 30 39 | "Gib.wav", 40 | "Gib_Stone.wav", 41 | "Gib_Wood.wav", 42 | "gq_alarm_loop.wav", 43 | "growl1.wav", 44 | "growl2.wav", 45 | "growl3.wav", 46 | "gurp2.wav", 47 | "Guten_Tag.wav", 48 | "GYeah.wav", // 40 49 | "Harbinger_Alert.wav", 50 | "Harbinger_Charge.wav", 51 | "Harbinger_Claw.wav", 52 | "Harbinger_Death.wav", 53 | "Harbinger_Fireball.wav", 54 | "Harbinger_Laugh.wav", 55 | "Harbinger_Pain.wav", 56 | "Harbinger_Slurp.wav", 57 | "Harbinger_Vanquish.wav", 58 | "Item_Bookshelf.wav", // 50 59 | "Item_Food_Pickup.wav", 60 | "Item_Key_Pickup.wav", 61 | "Item_Mixing.wav", 62 | "Item_Pickup.wav", 63 | "Item_Sink.wav", 64 | "Item_Sink_Sparkle.wav", 65 | "Item_Treasure.wav", 66 | "Knight_Falling.wav", 67 | "leaves_rustle_loop1.wav", 68 | "me109_flight.wav", // 60 69 | "Meingut.wav", 70 | "Misc_Rumble.wav", 71 | "Monster_Alert1.wav", 72 | "Monster_Alert2.wav", 73 | "Monster_Alert3.wav", 74 | "Monster_Alert4.wav", 75 | "Monster_Pain1.wav", 76 | "Monster_Pain2.wav", 77 | "Monster_Pain3.wav", 78 | "Music_Boss1.wav", // 70 79 | "Music_Boss2.wav", 80 | "Music_Boss3.wav", 81 | "Music_Boss4.wav", 82 | "Music_Briefing.wav", 83 | "Music_Finale.wav", 84 | "Music_LevelUp.wav", 85 | "Music_Prologue.wav", 86 | "Music_Title.wav", 87 | "m_action.wav", 88 | "m_assault.wav", // 80 89 | "night_forest_amb.wav", 90 | "Olaric_Alert.wav", 91 | "Olaric_Attack1.wav", 92 | "Olaric_Attack2.wav", 93 | "Olaric_Death.wav", 94 | "Olaric_Pain.wav", 95 | "Player_Death.wav", 96 | "Player_Gasp.wav", 97 | "Player_Gurp.wav", 98 | "Player_Pain.wav", // 90 99 | "pool_drip.wav", 100 | "Skeleton_Alert.wav", 101 | "Skeleton_Attack.wav", 102 | "Skeleton_Death.wav", 103 | "Skeleton_Pain.wav", 104 | "Slap.wav", 105 | "snooper_reload.wav", 106 | "Soldat_Death.wav", 107 | "Soldier_Alert.wav", 108 | "Soldier_Death.wav", // 100 109 | "Soldier_Death2.wav", 110 | "Soldier_Pain.wav", 111 | "Spikes.wav", 112 | "splashes.wav", 113 | "Steam.wav", 114 | "SuperSoldier_Alert.wav", 115 | "SuperSoldier_Death.wav", 116 | "SuperSoldier_Pain.wav", 117 | "Switch_Jammed.wav", 118 | "Switch_Pull.wav", // 110 119 | "tankmove2.wav", 120 | "tesla_field_loop.wav", 121 | "thompson.wav", 122 | "Tormentor_Alert.wav", 123 | "Tormentor_Attack1.wav", 124 | "Tormentor_Attack2.wav", 125 | "Tormentor_Death.wav", 126 | "Tormentor_Pain.wav", 127 | "tortured_souls_loop.wav", 128 | "Trap_Trigger.wav", // 120 129 | "war_giant2.wav", 130 | "waterfall.wav", 131 | "Water_In.wav", 132 | "Water_Out.wav", 133 | "Weapon_Change.wav", 134 | "Weapon_Dynamite_Exp.wav", 135 | "Weapon_Dynamite_Place.wav", 136 | "Weapon_FG42.wav", 137 | "Weapon_Flamethrower.wav", 138 | "Weapon_Kick.wav", // 130 139 | "Weapon_MP40.wav", 140 | "Weapon_NoAmmo.wav", 141 | "Weapon_Paratrooper.wav", 142 | "Weapon_Pistol.wav", 143 | "Weapon_Rocket.wav", 144 | "Weapon_Rocket_Exp.wav", 145 | "Weapon_Slap.wav", 146 | "Weapon_Slap_Air.wav", 147 | "Weapon_Sniper.wav", 148 | "Weapon_Sniper_Scope.wav", // 140 149 | "Weapon_Spear.wav", 150 | "Weapon_Sten.wav", 151 | "Weapon_Tesla.wav", 152 | "Weapon_Toilet_Pull.wav", 153 | "Weapon_Toilet_Smash.wav", 154 | "Weapon_Toilet_Throw.wav", 155 | "Weapon_Underwater.wav", 156 | "Weapon_Underwater_Miss.wav", 157 | "Weapon_Venom.wav", 158 | "Weapon_Wrench.wav", // 150 159 | "wind1.wav", 160 | "windcave.wav", 161 | "wind_whistle.wav", 162 | "xchoir2.wav", 163 | "x_action.wav", 164 | "Zombie_Alert.wav", 165 | "Zombie_Attack.wav", 166 | "Zombie_Attack1.wav", 167 | "Zombie_Attack2.wav", // 160 168 | "Zombie_Death.wav", 169 | "Zombie_Pain.wav" 170 | }; 171 | }; 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /src/TinyGL.h: -------------------------------------------------------------------------------- 1 | #ifndef __TINYGL_H__ 2 | #define __TINYGL_H__ 3 | 4 | #include 5 | 6 | #include "Span.h" 7 | #include "TGLVert.h" 8 | #include "TGLEdge.h" 9 | 10 | class TGLVert; 11 | class TGLEdge; 12 | 13 | class TinyGL 14 | { 15 | private: 16 | 17 | public: 18 | 19 | static constexpr int SHIFT_STRETCH = 12; 20 | static constexpr int UNIT_SCALE = 65536; 21 | static constexpr int MATRIX_ONE_SHIFT = 14; 22 | static constexpr int MATRIX_ONE = 16384; 23 | static constexpr int SCREEN_SHIFT = 3; 24 | static constexpr int SCREEN_ONE = 8; 25 | static constexpr int INTERPOLATE_SHIFT = 16; 26 | static constexpr int INTERPOLATE_TO_PIXELS_SHIFT = 19; 27 | static constexpr int SCREEN_PRESTEP = 7; 28 | static constexpr int INTERPOLATE_PRESTEP = 524287; 29 | static constexpr bool CLAMP_TO_VIEWPORT = false; 30 | static constexpr int PIXEL_GUARD_SIZE = 1; 31 | static constexpr int MAX_PRIMITIVE_VERTS = 20; 32 | static constexpr int OE_SHIFT = 4; 33 | static constexpr int CULL_NONE = 0; 34 | static constexpr int CULL_CW = 1; 35 | static constexpr int CULL_CCW = 2; 36 | static constexpr int NEAR_CLIP = 256; 37 | static constexpr int CULL_EXTRA = NEAR_CLIP + 16; 38 | static constexpr int NUM_FOG_LEVELS = 16; 39 | static constexpr int COLUMN_SCALE_INIT = INT_MAX; 40 | static constexpr int COLUMN_SCALE_OCCLUDED = (INT_MAX - 1); 41 | 42 | int faceCull; 43 | SpanType* span; 44 | uint8_t* textureBase; 45 | int imageBounds[4]; 46 | uint16_t* spanPalette; 47 | uint16_t** paletteBase; 48 | uint16_t* scratchPalette; 49 | int sWidth; 50 | int sShift; 51 | int sMask; 52 | int tHeight; 53 | int tShift; 54 | int tMask; 55 | bool swapXY; 56 | int screenWidth; 57 | int screenHeight; 58 | uint16_t* pixels; 59 | int* columnScale; 60 | int view[16]; 61 | int view2D[16]; 62 | int projection[16]; 63 | int mvp[16]; 64 | int mvp2D[16]; 65 | TGLVert cv[32]; 66 | TGLVert mv[20]; 67 | TGLEdge edges[2]; 68 | int fogMin; 69 | int fogRange; 70 | int fogColor; 71 | int countBackFace; 72 | int countDrawn; 73 | int spanPixels; 74 | int spanCalls; 75 | int zeroDT; 76 | int zeroDS; 77 | int viewportX; 78 | int viewportY; 79 | int viewportWidth; 80 | int viewportHeight; 81 | int viewportClampX1; 82 | int viewportClampY1; 83 | int viewportClampX2; 84 | int viewportClampY2; 85 | int viewportX2; 86 | int viewportY2; 87 | int viewportXScale; 88 | int viewportXBias; 89 | int viewportYScale; 90 | int viewportYBias; 91 | int viewportZScale; 92 | int viewportZBias; 93 | int viewX; 94 | int viewY; 95 | int viewZ; 96 | int viewYaw; 97 | int viewPitch; 98 | int c_backFacedPolys; 99 | int c_frontFacedPolys; 100 | int c_totalQuad; 101 | int c_clippedQuad; 102 | int c_unclippedQuad; 103 | int c_rejectedQuad; 104 | int unk03; 105 | int unk04; 106 | uint32_t textureBaseSize; // [GEC] new 107 | uint32_t paletteBaseSize; // [GEC] new 108 | int16_t paletteTransparentMask;// [GEC] new 109 | uint32_t mediaID;// [GEC] new 110 | int colorBuffer;// [GEC] new 111 | 112 | // Constructor 113 | TinyGL(); 114 | // Destructor 115 | ~TinyGL(); 116 | 117 | bool startup(int screenWidth, int screenHeight); 118 | uint16_t* getFogPalette(int i); 119 | void clearColorBuffer(int color); 120 | void buildViewMatrix(int x, int y, int z, int yaw, int pitch, int roll, int* matrix); 121 | void buildProjectionMatrix(int fov, int aspect, int* matrix); 122 | void multMatrix(int* matrix1, int* matrix2, int* destMtx); 123 | void _setViewport(int viewportX, int viewportY, int viewportWidth, int viewportHeight); 124 | void setViewport(int x, int y, int w, int h); 125 | void resetViewPort(); 126 | void setView(int viewX, int viewY, int viewZ, int viewYaw, int viewPitch, int viewRoll, int viewFov, int viewAspect); 127 | void viewMtxMove(TGLVert* tglVert, int n, int n2, int n3); 128 | void drawModelVerts(TGLVert* array, int n); 129 | TGLVert* transform3DVerts(TGLVert* array, int n); 130 | TGLVert* transform2DVerts(TGLVert* array, int n); 131 | void ClipQuad(TGLVert* tglVert, TGLVert* tglVert2, TGLVert* tglVert3, TGLVert* tglVert4); 132 | void ClipPolygon(int i, int n); 133 | bool clipLine(TGLVert* array); 134 | void projectVerts(TGLVert* array, int n); 135 | void RasterizeConvexPolygon(int n); 136 | bool clippedLineVisCheck(TGLVert* tglVert, TGLVert* tglVert2, bool b); 137 | bool occludeClippedLine(TGLVert* tglVert, TGLVert* tglVert2); 138 | void drawClippedSpriteLine(TGLVert* tglVert, TGLVert* tglVert2, TGLVert* tglVert3, int n, bool b); 139 | void resetCounters(); 140 | void applyClearColorBuffer(); // [GEC] 141 | }; 142 | 143 | #endif -------------------------------------------------------------------------------- /src/CAppContainer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "SDLGL.h" 4 | #include "ZipFile.h" 5 | #include "App.h" 6 | #include "Canvas.h" 7 | #include "Game.h" 8 | #include "CAppContainer.h" 9 | #include "Utils.h" 10 | #include "MenuSystem.h" 11 | #include "Player.h" 12 | #include "Sound.h" 13 | #include "Menus.h" 14 | 15 | static CAppContainer _mContainer; 16 | int CAppContainer::m_cheatEntry = 0; 17 | 18 | CAppContainer::CAppContainer() { 19 | this->MoveX = 0.0; 20 | this->MoveY = 0.0; 21 | this->MoveAng = 0.0; 22 | } 23 | 24 | CAppContainer::~CAppContainer() { 25 | 26 | if (this->app) { 27 | 28 | if (this->app->sound) { 29 | this->app->sound->~Sound(); 30 | } 31 | delete this->app; 32 | this->app = nullptr; 33 | } 34 | 35 | if (this->sdlGL) { 36 | this->sdlGL->~SDLGL(); 37 | this->sdlGL = nullptr; 38 | } 39 | 40 | if (this->zipFile) { 41 | this->zipFile->closeZipFile(); 42 | this->zipFile = nullptr; 43 | } 44 | } 45 | 46 | CAppContainer* CAppContainer::getInstance() { 47 | return &_mContainer; 48 | } 49 | 50 | short* CAppContainer::GetBackBuffer() 51 | { 52 | return (short*)this->app->backBuffer->pBmp; 53 | } 54 | 55 | void CAppContainer::DoLoop(int time) { 56 | this->app->sound->startFrame(); 57 | this->app->canvas->staleView = true; 58 | this->app->canvas->run(); 59 | this->app->sound->endFrame(); 60 | this->app->upTimeMs += time; 61 | } 62 | 63 | void CAppContainer::suspendOpenAL() { 64 | 65 | } 66 | 67 | void CAppContainer::resumeOpenAL() { 68 | 69 | } 70 | 71 | void CAppContainer::userPressed(float pressX, float pressY) { 72 | int x = (int)(pressX * Applet::IOS_WIDTH); 73 | int y = (int)(pressY * Applet::IOS_HEIGHT); 74 | //printf("userPressed [x %d, y %d]\n", x, y); 75 | this->app->canvas->touchStart(x, /*Applet::IOS_HEIGHT - */y); 76 | } 77 | 78 | void CAppContainer::userMoved(float pressX, float pressY) { 79 | int x = (int)(pressX * Applet::IOS_WIDTH); 80 | int y = (int)(pressY * Applet::IOS_HEIGHT); 81 | //printf("userMoved [x %d, y %d]\n", x, y); 82 | this->app->canvas->touchMove(x, /*Applet::IOS_HEIGHT - */y); 83 | } 84 | 85 | void CAppContainer::userReleased(float pressX, float pressY) { 86 | int x = (int)(pressX * Applet::IOS_WIDTH); 87 | int y = (int)(pressY * Applet::IOS_HEIGHT); 88 | //printf("userReleased [x %d, y %d]\n", x, y); 89 | this->app->canvas->touchEnd(x, /*Applet::IOS_HEIGHT -*/ y); 90 | } 91 | 92 | void CAppContainer::unHighlightButtons() { 93 | this->app->canvas->touchEndUnhighlight(); 94 | } 95 | 96 | uint32_t CAppContainer::getTimeMS() { 97 | return SDL_GetTicks(); 98 | } 99 | 100 | void CAppContainer::saveGame(int i, int* i2) { 101 | 102 | } 103 | 104 | void CAppContainer::TestCheatEntry(float pressX, float pressY) { 105 | int x = (int)(pressX * Applet::IOS_WIDTH); 106 | int y = (int)(pressY * Applet::IOS_HEIGHT); 107 | 108 | if (pointInRectangle(x, y, 0, 0, 60, 60)) { 109 | m_cheatEntry *= 10; 110 | m_cheatEntry += 1; 111 | } 112 | else if (pointInRectangle(x, y, (Applet::IOS_WIDTH - 60), 0, 60, 60)) { 113 | m_cheatEntry *= 10; 114 | m_cheatEntry += 2; 115 | } 116 | else if (pointInRectangle(x, y, 0, (Applet::IOS_HEIGHT - 60), 60, 60)) { 117 | m_cheatEntry *= 10; 118 | m_cheatEntry += 3; 119 | } 120 | else if (pointInRectangle(x, y, (Applet::IOS_WIDTH - 60), (Applet::IOS_HEIGHT - 60), 60, 60)) { 121 | m_cheatEntry *= 10; 122 | m_cheatEntry += 4; 123 | } 124 | else { 125 | m_cheatEntry = 0; 126 | } 127 | 128 | if (m_cheatEntry > 100000) { 129 | m_cheatEntry %= 1000000; 130 | } 131 | 132 | if (this->testCheatCode(m_cheatEntry)) { 133 | m_cheatEntry = 0; 134 | } 135 | } 136 | 137 | bool CAppContainer::testCheatCode(int code) { 138 | switch (code) { 139 | case 123434: { 140 | this->app->menuSystem->scrollIndex = 0; 141 | this->app->menuSystem->selectedIndex = 0; 142 | this->app->menuSystem->gotoMenu(Menus::MENU_DEBUG); 143 | break; 144 | } 145 | case 123414: { 146 | this->app->canvas->loadMap(this->app->canvas->loadMapID, true, false); 147 | break; 148 | } 149 | case 123424: { 150 | this->app->player->giveAll(); 151 | break; 152 | } 153 | case 123432: { 154 | if (this->app->menuSystem->menu >= Menus::MENU_INGAME) { 155 | this->app->canvas->startSpeedTest(0); 156 | } 157 | break; 158 | } 159 | default: { 160 | return false; 161 | } 162 | } 163 | return true; 164 | } 165 | 166 | void CAppContainer::UpdateAccelerometer(float x, float y, float z, bool useMouse) { 167 | if (this->app) { 168 | if (useMouse) { 169 | int aX = (int)(x * Applet::IOS_WIDTH); 170 | int aY = (int)(y * Applet::IOS_HEIGHT); 171 | float axisX = -AxisHit(aX, aY, 0, 0, 480, 320, true, 1.0f); 172 | float axisY = -AxisHit(aX, aY, 0, 0, 480, 320, false, 1.0f); 173 | this->app->AccelerometerUpdated(axisX, axisY, z); 174 | } 175 | else { 176 | this->app->AccelerometerUpdated(x, y, z); 177 | } 178 | } 179 | } 180 | 181 | void CAppContainer::Construct(SDLGL* sdlGL, ZipFile* zipFile) { 182 | //printf("CAppContainer::Construct\n"); 183 | this->sdlGL = sdlGL; // New 184 | this->zipFile = zipFile; // New 185 | 186 | this->app = new Applet(); 187 | this->app->startup(); 188 | this->app->game->hasSeenIntro = true; 189 | } 190 | -------------------------------------------------------------------------------- /src/Input.h: -------------------------------------------------------------------------------- 1 | #ifndef __INPUT_H__ 2 | #define __INPUT_H__ 3 | 4 | 5 | //------------------------------------------------------------------------------------------------------------------------------------------ 6 | // Enum representing an input source on a non-generic game controller recognized by SDL (axis or button) 7 | //------------------------------------------------------------------------------------------------------------------------------------------ 8 | enum class GamepadInput : uint8_t { 9 | BTN_A, 10 | BTN_B, 11 | BTN_X, 12 | BTN_Y, 13 | BTN_BACK, 14 | BTN_GUIDE, 15 | BTN_START, 16 | BTN_LEFT_STICK, 17 | BTN_RIGHT_STICK, 18 | BTN_LEFT_SHOULDER, 19 | BTN_RIGHT_SHOULDER, 20 | BTN_DPAD_UP, 21 | BTN_DPAD_DOWN, 22 | BTN_DPAD_LEFT, 23 | BTN_DPAD_RIGHT, 24 | AXIS_LEFT_X, 25 | AXIS_LEFT_Y, 26 | AXIS_RIGHT_X, 27 | AXIS_RIGHT_Y, 28 | AXIS_TRIG_LEFT, 29 | AXIS_TRIG_RIGHT, 30 | BTN_LAXIS_UP, // L-Axis Up 31 | BTN_LAXIS_DOWN, // L-Axis Down 32 | BTN_LAXIS_LEFT, // L-Axis Left 33 | BTN_LAXIS_RIGHT, // L-Axis Right 34 | BTN_RAXIS_UP, // R-Axis Up 35 | BTN_RAXIS_DOWN, // R-Axis Down 36 | BTN_RAXIS_LEFT, // R-Axis Left 37 | BTN_RAXIS_RIGHT, // R-Axis Right 38 | // N.B: must keep last for 'NUM_GAMEPAD_INPUTS' constant! 39 | INVALID 40 | }; 41 | 42 | static constexpr uint8_t NUM_GAMEPAD_INPUTS = (uint32_t)GamepadInput::INVALID; 43 | 44 | // Direction for a joystick hat (d-pad) 45 | enum JoyHatDir : uint8_t { 46 | Up = 0, 47 | Down = 1, 48 | Left = 2, 49 | Right = 3 50 | }; 51 | 52 | // Holds a joystick hat (d-pad) direction and hat number 53 | union JoyHat { 54 | struct { 55 | JoyHatDir hatDir; 56 | uint8_t hatNum; 57 | } fields; 58 | 59 | uint16_t bits; 60 | 61 | inline JoyHat() noexcept : bits() {} 62 | inline JoyHat(const uint16_t bits) noexcept : bits(bits) {} 63 | 64 | inline JoyHat(const JoyHatDir dir, const uint8_t hatNum) noexcept : bits() { 65 | fields.hatDir = dir; 66 | fields.hatNum = hatNum; 67 | } 68 | 69 | inline operator uint16_t() const noexcept { return bits; } 70 | 71 | inline bool operator == (const JoyHat& other) const noexcept { return (bits == other.bits); } 72 | inline bool operator != (const JoyHat& other) const noexcept { return (bits != other.bits); } 73 | }; 74 | 75 | //static_assert(sizeof(JoyHat) == 2); 76 | 77 | // Holds the current state of a generic joystick axis 78 | struct JoystickAxis { 79 | uint32_t axis; 80 | float value; 81 | }; 82 | //--------------- 83 | 84 | extern char buttonNames[][NUM_GAMEPAD_INPUTS]; 85 | 86 | #define KEYBINDS_MAX 10 87 | #define IS_MOUSE_BUTTON 0x100000 88 | #define IS_CONTROLLER_BUTTON 0x200000 89 | typedef struct keyMapping_s { 90 | int avk_action; 91 | int keyBinds[KEYBINDS_MAX]; 92 | } keyMapping_t; 93 | 94 | #define KEY_MAPPIN_MAX 16 95 | extern keyMapping_t keyMapping[KEY_MAPPIN_MAX]; 96 | extern keyMapping_t keyMappingTemp[KEY_MAPPIN_MAX]; 97 | extern keyMapping_t keyMappingDefault[KEY_MAPPIN_MAX]; 98 | 99 | extern int gDeadZone; 100 | extern int gVibrationIntensity; 101 | extern float gBegMouseX; 102 | extern float gBegMouseY; 103 | extern float gCurMouseX; 104 | extern float gCurMouseY; 105 | 106 | enum _AVKType { 107 | AVK_UNDEFINED = -1, // hex 0xE010; dec 57360 108 | //AVK_FIRST = 1, // hex 0xE020; dec 57376 109 | 110 | AVK_0, // hex 0xE021; dec 57377 111 | AVK_1, // hex 0xE022; dec 57378 112 | AVK_2, // hex 0xE023; dec 57379 113 | AVK_3, // hex 0xE024; dec 57380 114 | AVK_4, // hex 0xE025; dec 57381 115 | AVK_5, // hex 0xE026; dec 57382 116 | AVK_6, // hex 0xE027; dec 57383 117 | AVK_7, // hex 0xE028; dec 57384 118 | AVK_8, // hex 0xE029; dec 57385 119 | AVK_9, // hex 0xE02A; dec 57386 120 | AVK_STAR, // hex 0xE02B; dec 57387 121 | AVK_POUND, // hex 0xE02C; dec 57388 122 | 123 | AVK_POWER, // hex 0xE02D; dec 57389 124 | AVK_SELECT, // hex 0xE02E; dec 57390 125 | //AVK_SEND, // hex 0xE02F; dec 57391 126 | 127 | AVK_UP, // hex 0xE031; dec 57393 128 | AVK_DOWN, // hex 0xE032; dec 57394 129 | AVK_LEFT, // hex 0xE033; dec 57395 130 | AVK_RIGHT, // hex 0xE034; dec 57396 131 | 132 | AVK_CLR, // hex 0xE030; dec 57392 133 | 134 | AVK_SOFT1, // hex 0xE036; dec 57398 135 | AVK_SOFT2, // hex 0xE037; dec 57399 136 | 137 | AVK_UNK = 26, // IOS 138 | AVK_VOLUME_UP = 27, // IOS 139 | AVK_VOLUME_DOWN = 28, // IOS 140 | 141 | // New Types Only on port 142 | AVK_MENUOPEN = 30, 143 | AVK_AUTOMAP, 144 | AVK_MOVELEFT, 145 | AVK_MOVERIGHT, 146 | AVK_PREVWEAPON, 147 | AVK_NEXTWEAPON, 148 | AVK_PASSTURN, 149 | 150 | 151 | // New Flags Menu Only on port 152 | AVK_MENU_UP = 0x40, 153 | AVK_MENU_DOWN = 0x80, 154 | AVK_MENU_PAGE_UP = 0x100, 155 | AVK_MENU_PAGE_DOWN = 0x200, 156 | AVK_MENU_SELECT = 0x400, 157 | AVK_MENU_OPEN = 0x800, 158 | AVK_MENU_NUMBER = 0x2000, 159 | AVK_ITEMS_INFO = 0x4000, 160 | AVK_SYRINGES = 0x8000, 161 | AVK_JOURNAL = 0x10000 162 | }; 163 | 164 | extern void controllerVibrate(int duration_ms) noexcept; 165 | 166 | class Input 167 | { 168 | private: 169 | 170 | public: 171 | 172 | // Constructor 173 | Input(); 174 | // Destructor 175 | ~Input(); 176 | 177 | void init(); 178 | void unBind(int* keyBinds, int keycode); 179 | void setBind(int* keyBinds, int keycode); 180 | void setInputBind(int scancode); 181 | void handleEvents() noexcept; 182 | void consumeEvents() noexcept; 183 | }; 184 | #endif -------------------------------------------------------------------------------- /src/Hud.h: -------------------------------------------------------------------------------- 1 | #ifndef __HUD_H__ 2 | #define __HUD_H__ 3 | 4 | class Image; 5 | class Text; 6 | class Entity; 7 | class fmButtonContainer; 8 | class Graphics; 9 | 10 | class Hud 11 | { 12 | private: 13 | 14 | public: 15 | static constexpr int MSG_DISPLAY_TIME = 700; 16 | static constexpr int MSG_FLASH_TIME = 100; 17 | static constexpr int SCROLL_START_DELAY = 750; 18 | static constexpr int MS_PER_CHAR = 64; 19 | static constexpr int MAX_MESSAGES = 5; 20 | static constexpr int REPAINT_EFFECTS = 1; 21 | static constexpr int REPAINT_TOP_BAR = 2; 22 | static constexpr int REPAINT_BOTTOM_BAR = 4; 23 | static constexpr int REPAINT_BUBBLE_TEXT = 8; 24 | static constexpr int REPAINT_SUBTITLES = 16; 25 | static constexpr int REPAINT_HUD_OVERDRAW = 32; 26 | static constexpr int REPAINT_DPAD = 64; 27 | static constexpr int REPAINT_PLAYING_FLAGS = 107; 28 | static constexpr int REPAINT_CAMERA_FLAGS = 24; 29 | static constexpr int MSG_FLAG_NONE = 0; 30 | static constexpr int MSG_FLAG_FORCE = 1; 31 | static constexpr int MSG_FLAG_CENTER = 2; 32 | static constexpr int MSG_FLAG_IMPORTANT = 4; 33 | static constexpr int STATUSBAR_ICON_PICKUP = 0; 34 | static constexpr int STATUSBAR_ICON_ATTACK = 1; 35 | static constexpr int STATUSBAR_ICON_CHAT = 2; 36 | static constexpr int STATUSBAR_ICON_USE = 3; 37 | static constexpr int HUDARROWS_SIZE = 12; 38 | static constexpr int BUBBLE_TEXT_TIME = 1500; 39 | static constexpr int SENTRY_BOT_ICONS_PADDING = 15; 40 | static constexpr int DAMAGE_OVERLAY_TIME = 1000; 41 | static constexpr int ACTION_ICON_SIZE = 18; 42 | 43 | static constexpr int MAX_WEAPON_BUTTONS = 18; 44 | 45 | 46 | int touchMe; 47 | int repaintFlags; 48 | Image* imgScope; 49 | Image* imgActions; 50 | Image* imgAttArrow; 51 | Image* imgDamageVignette; 52 | Image* imgDamageVignetteBot; 53 | Image* imgBottomBarIcons; 54 | Image* imgAmmoIcons; 55 | Image* imgSoftKeyFill; 56 | Image* imgPortraitsSM; 57 | Image* imgPlayerFaces; 58 | Image* imgPlayerActive; 59 | Image* imgPlayerFrameNormal; 60 | Image* imgPlayerFrameActive; 61 | Image* imgHudFill; 62 | Image* imgIce; 63 | Image* imgSentryBotFace; 64 | Image* imgSentryBotActive; 65 | bool isInWeaponSelect; 66 | Image* imgPanelTop; 67 | Image* imgPanelTopSentrybot; 68 | Image* imgWeaponNormal; 69 | Image* imgWeaponActive; 70 | Image* imgShieldNormal; 71 | Image* imgShieldButtonActive; 72 | Image* imgKeyNormal; 73 | Image* imgKeyActive; 74 | Image* imgHealthNormal; 75 | Image* imgHealthButtonActive; 76 | Image* imgSwitchRightNormal; 77 | Image* imgSwitchRightActive; 78 | Image* imgSwitchLeftNormal; 79 | Image* imgSwitchLeftActive; 80 | Image* imgVendingSoftkeyPressed; 81 | Image* imgVendingSoftkeyNormal; 82 | Image* imgInGameMenuSoftkey; 83 | Image* imgNumbers; 84 | Image* imgHudTest; 85 | Text* messages[Hud::MAX_MESSAGES]; 86 | int messageFlags[Hud::MAX_MESSAGES]; 87 | int msgCount; 88 | int msgTime; 89 | int msgDuration; 90 | int subTitleID; 91 | int subTitleTime; 92 | int cinTitleID; 93 | int cinTitleTime; 94 | Text* bubbleText; 95 | int bubbleTextTime; 96 | int bubbleColor; 97 | int damageTime; 98 | int damageCount; 99 | int damageDir; 100 | Entity* lastTarget; 101 | int monsterStartHealth; 102 | int monsterDestHealth; 103 | int playerStartHealth; 104 | int playerDestHealth; 105 | int monsterHealthChangeTime; 106 | int playerHealthChangeTime; 107 | bool showCinPlayer; 108 | int drawTime; 109 | fmButtonContainer* m_hudButtons; 110 | fmButtonContainer* m_weaponsButtons; 111 | int weaponPressTime; 112 | 113 | // Constructor 114 | Hud(); 115 | // Destructor 116 | ~Hud(); 117 | 118 | bool startup(); 119 | void shiftMsgs(); 120 | void calcMsgTime(); 121 | void addMessage(short i); 122 | void addMessage(short i, short i2); 123 | void addMessage(short i, int i2); 124 | void addMessage(short i, short i2, int i3); 125 | void addMessage(Text* text); 126 | void addMessage(Text* text, int flags); 127 | Text* getMessageBuffer(); 128 | Text* getMessageBuffer(int flags); 129 | void finishMessageBuffer(); 130 | bool isShiftingCenterMsg(); 131 | void drawTopBar(Graphics* graphics); 132 | void drawCenterMessage(Graphics* graphics, Text* text, int color); 133 | void drawCinematicText(Graphics* graphics); 134 | void drawEffects(Graphics* graphics); 135 | void drawDamageVignette(Graphics* graphics); 136 | void drawBottomBar(Graphics* graphics); 137 | void draw(Graphics* graphics); 138 | void drawMonsterHealth(Graphics* graphics); 139 | void showSpeechBubble(int i); 140 | void drawBubbleText(Graphics* graphics); 141 | void drawArrowControls(Graphics* graphics); 142 | void drawWeapon(Graphics* graphics, int x, int y, int weapon, bool highlighted); 143 | void drawNumbers(Graphics* graphics, int x, int y, int space, int num); 144 | void drawCurrentKeys(Graphics* graphics, int x, int y); 145 | void drawWeaponSelection(Graphics* graphics); 146 | void handleUserMoved(int pressX, int pressY); 147 | void handleUserTouch(int pressX, int pressY, bool highlighted); 148 | void update(); 149 | }; 150 | 151 | #endif -------------------------------------------------------------------------------- /src/Combat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMBAT_H__ 2 | #define __COMBAT_H__ 3 | 4 | class Entity; 5 | class EntityMonster; 6 | class GameSprite; 7 | class ScriptThread; 8 | class CombatEntity; 9 | class EntityDef; 10 | class Text; 11 | 12 | class Combat 13 | { 14 | private: 15 | 16 | public: 17 | static constexpr int SEQ_ENDATTACK = 1; 18 | static constexpr int OUTOFCOMBAT_TURNS = 4; 19 | static constexpr int MAX_TILEDISTANCES = 16; 20 | static constexpr int EXPLOSION_OFFSET2 = 38; 21 | static constexpr int MAX_ACTIVE_MISSILES = 8; 22 | static constexpr int EXPLOSION_OFFSET = 48; 23 | static constexpr int DEF_PLACING_BOMB_Z = 18; 24 | static constexpr int PLACING_BOMB_TIME = 750; 25 | static constexpr int BOMB_RECOVER_TIME = 500; 26 | 27 | static constexpr int WEAPON_FIELD_STRMIN = 0; 28 | static constexpr int WEAPON_FIELD_STRMAX = 1; 29 | static constexpr int WEAPON_FIELD_RANGEMIN = 2; 30 | static constexpr int WEAPON_FIELD_RANGEMAX = 3; 31 | static constexpr int WEAPON_FIELD_AMMOTYPE = 4; 32 | static constexpr int WEAPON_FIELD_AMMOUSAGE = 5; 33 | static constexpr int WEAPON_FIELD_PROJTYPE = 6; 34 | static constexpr int WEAPON_FIELD_NUMSHOTS = 7; 35 | static constexpr int WEAPON_FIELD_SHOTHOLD = 8; 36 | static constexpr int WEAPON_MAX_FIELDS = 9; 37 | static constexpr int WEAPON_STRIDE = 8; 38 | 39 | static constexpr int MONSTER_FIELD_ATTACK1 = 0; 40 | static constexpr int MONSTER_FIELD_ATTACK2 = 1; 41 | static constexpr int MONSTER_FIELD_CHANCE = 2; 42 | static constexpr int MAX_WRAITH_DRAIN = 45; 43 | static constexpr int MAP_03_BOOST = 9; 44 | static constexpr int PUNCH_PREP = 1; 45 | static constexpr int PUNCH_RIGHTHAND = 2; 46 | static constexpr int PUNCH_LEFTHAND = 3; 47 | static constexpr int ONE_FP = 65536; 48 | static constexpr int LOWEREDWEAPON_Y = 38; 49 | static constexpr int LOWERWEAPON_TIME = 200; 50 | static constexpr int WEAPON_SCALE = 131072; 51 | static constexpr int COMBAT_DONE = 0; 52 | static constexpr int COMBAT_CONTINUE = 1; 53 | static constexpr int REBOUNDOFFSET = 31; 54 | 55 | static constexpr int FIELD_COUNT = 6; 56 | static constexpr int FLD_WPIDLEX = 0; 57 | static constexpr int FLD_WPIDLEY = 1; 58 | static constexpr int FLD_WPATKX = 2; 59 | static constexpr int FLD_WPATKY = 3; 60 | static constexpr int FLD_WPFLASHX = 4; 61 | static constexpr int FLD_WPFLASHY = 5; 62 | 63 | int touchMe; 64 | int tileDistances[Combat::MAX_TILEDISTANCES]; 65 | int16_t*monsterAttacks; 66 | int field_0x50_; 67 | int drawLogo; 68 | int field_0x58_; 69 | int32_t* wpinfo; 70 | int8_t* monsterStats; 71 | Entity* curAttacker; 72 | Entity* curTarget; 73 | Entity* lastTarget; 74 | int dodgeDir; 75 | EntityMonster* targetMonster; 76 | EntityMonster* attackerMonster; 77 | int targetSubType; 78 | int targetType; 79 | int stage; 80 | int nextStageTime; 81 | int nextStage; 82 | GameSprite* activeMissiles[8]; 83 | int numActiveMissiles; 84 | int missileAnim; 85 | bool targetKilled; 86 | bool exploded; 87 | ScriptThread* explodeThread; 88 | int damage; 89 | int totalDamage; 90 | int deathAmt; 91 | int accumRoundDamage; 92 | int totalArmorDamage; 93 | int hitType; 94 | int animStartTime; 95 | int animTime; 96 | int animEndTime; 97 | int attackerWeaponId; 98 | int attackerWeaponProj; 99 | int attackerWeapon; 100 | int weaponDistance; 101 | bool lerpingWeapon; 102 | bool weaponDown; 103 | bool lerpWpDown; 104 | int lerpWpStartTime; 105 | int lerpWpDur; 106 | int field_0x110_; 107 | bool flashDone; 108 | int flashDoneTime; 109 | int flashTime; 110 | bool settingDynamite; 111 | bool dynamitePlaced; 112 | int settingDynamiteTime; 113 | int currentBombIndex; 114 | int placingBombZ; 115 | int attackFrame; 116 | int animLoopCount; 117 | bool gotCrit; 118 | bool gotHit; 119 | bool isGibbed; 120 | int reflectionDmg; 121 | int playerMissRepetition; 122 | int monsterMissRepetition; 123 | int renderTime; 124 | int attackX; 125 | int attackY; 126 | int8_t* weapons; 127 | int8_t* monsterWeakness; 128 | CombatEntity* monsters[45]; 129 | int worldDist; 130 | int tileDist; 131 | int crFlags; 132 | int crDamage; 133 | int crArmorDamage; 134 | int crCritChance; 135 | int crHitChance; 136 | int punchingMonster; 137 | bool punchMissed; 138 | bool oneShotCheat; 139 | int numThornParticleSystems; 140 | int32_t* tableCombatMasks; 141 | 142 | int32_t* weaponMasks; 143 | 144 | // Constructor 145 | Combat(); 146 | // Destructor 147 | ~Combat(); 148 | 149 | short getWeaponWeakness(int weapon, int n2, int n3); 150 | bool startup(); 151 | void performAttack(Entity* curAttacker, Entity* curTarget, int attackX, int attackY, bool b); 152 | void checkMonsterFX(); 153 | int playerSeq(); 154 | int monsterSeq(); 155 | void drawEffects(); 156 | void drawWeapon(int sx, int sy); 157 | void shiftWeapon(bool lerpWpDown); 158 | int runFrame(); 159 | int calcHit(Entity* entity); 160 | void explodeOnMonster(); 161 | void explodeOnPlayer(); 162 | int getMonsterField(EntityDef* entityDef, int n); 163 | void radiusHurtEntities(int n, int n2, int n3, int n4, Entity* entity); 164 | void hurtEntityAt(int n, int n2, int n3, int n4, int n5, int n6, Entity* entity); 165 | void hurtEntityAt(int n, int n2, int n3, int n4, int n5, int n6, Entity* entity, bool b); 166 | Text* getWeaponStatStr(int n); 167 | Text* getArmorStatStr(int n); 168 | int WorldDistToTileDist(int n); 169 | void cleanUpAttack(); 170 | void updateProjectile(); 171 | void launchProjectile(); 172 | GameSprite* allocMissile(int n, int n2, int n3, int n4, int n5, int n6, int duration, int n7); 173 | }; 174 | 175 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WolfensteinRPG-RE 2 | 3 | ![Imagen1](https://github.com/user-attachments/assets/cbfab4c2-5310-45cf-a694-7a74e0a299bd)
4 | 5 | https://www.doomworld.com/forum/topic/151475 6 | 7 | ## Español 8 | Wolfenstein RPG ingeniería inversa por [GEC]
9 | Creado por Erick Vásquez García. 10 | 11 | Versión actual 0.1 12 | 13 | ### **Requisitos** 14 | Requiere CMake para crear el proyecto.
15 | Requisitos para el projecto: 16 | * SDL2 17 | * Zlib 18 | * OpenAL 19 | 20 | ### 🔹 **Ubuntu** 21 | Antes de compilar, asegúrate de instalar las siguientes dependencias: 22 | ```sh 23 | sudo apt update && sudo apt install -y cmake g++ libsdl2-dev zlib1g-dev libopenal-dev libgl1-mesa-dev 24 | ``` 25 | 26 | ### ⚙️ **Compilación** 27 | Clona el repositorio y compila el proyecto con CMake: 28 | ```sh 29 | git clone https://github.com/Erick194/WolfensteinRPG-RE.git 30 | cd WolfensteinRPG-RE 31 | mkdir build && cd build 32 | cmake .. 33 | make -j$(nproc) 34 | ``` 35 | 36 | ### 🚀 **Ejecución** 37 | Después de compilar, ejecuta el juego con: 38 | ```sh 39 | ./build/src/WolfensteinRPG 40 | ``` 41 | 42 | ### 📦 **Creación del AppImage** 43 | 🔹 1. Descarga las herramientas necesarias 44 | ```sh 45 | wget -O appimagetool https://github.com/AppImage/AppImageKit/releases/latest/download/appimagetool-x86_64.AppImage 46 | wget -O linuxdeploy https://github.com/linuxdeploy/linuxdeploy/releases/latest/download/linuxdeploy-x86_64.AppImage 47 | chmod +x appimagetool linuxdeploy 48 | ``` 49 | 🔹 2. Generar el AppImage con el script 50 | ```sh 51 | chmod +x make-wolfenstein-rpg-linux-appimage.sh 52 | ./make-wolfenstein-rpg-linux-appimage.sh ./appimagetool ./linuxdeploy $(pwd) ./build/src/WolfensteinRPG 53 | ``` 54 | 55 | ### 🎮 **Configuración por defecto de las teclas.** 56 | 57 | Adelante: W, Up
58 | Atras: S, Down
59 | Mover Izquierda: A
60 | Mover Derecha: D
61 | Girar Izquierda: Left
62 | Girar Derecha: Right
63 | Atq/Habl/Usar: Return
64 | Arma Siguiente: Z
65 | Arma Anteriror: X
66 | Pasar Turno: C
67 | Automapa: Tab
68 | Menú: Escape
69 | Artículos/Info: I
70 | Jeringas: O
71 | Diario: P
72 | 73 | ### 🔑 **Trucos originales del juego:** 74 | 75 | Versión J2ME/BREW:
76 | Abres menu e ingresa los siguientes numeros.
77 | 3666 -> Abre el menú debug.
78 | 1666 -> Reinicia el nivel.
79 | 4332 -> Da al jugador todas las llaves, items y armas.
80 | 3366 -> Inicia el testeo de velocidad, "Benchmark".
81 | 82 | Versión iOS:
83 | Toca las esquinas en pantalla en el siguente orden:
84 | Superior izquerda, superior derecha, inferior izquerda, inferior derecha, inferior izquerda, inferior derecha -> Abre el menu debug.
85 | Superior izquerda, superior derecha, inferior izquerda, inferior derecha, superior izquerda, inferior derecha -> Reinicia el nivel.
86 | Superior izquerda, superior derecha, inferior izquerda, inferior derecha, superior derecha, inferior derecha -> Da al jugador todas las armas, items y las llaves.
87 | Superior izquerda, superior derecha, inferior izquerda, inferior derecha, inferior izquerda, superior derecha -> Inicia el testeo de velocidad, "Benchmark".
88 | 89 | ## English 90 | Wolfenstein RPG Reverse Engineering By [GEC]
91 | Created by Erick Vásquez García. 92 | 93 | Current version 0.1 94 | 95 | ### **Requirements** 96 | You need CMake to make the project.
97 | What you need for the project is: 98 | * SDL2 99 | * Zlib 100 | * OpenAL 101 | 102 | ### 🔹 **Ubuntu** 103 | Before compiling, make sure to install the following dependencies: 104 | ```sh 105 | sudo apt update && sudo apt install -y cmake g++ libsdl2-dev zlib1g-dev libopenal-dev libgl1-mesa-dev 106 | ``` 107 | 108 | ### ⚙️ **Compilation** 109 | Clone the repository and compile the project using CMake: 110 | ```sh 111 | git clone https://github.com/Erick194/WolfensteinRPG-RE.git 112 | cd WolfensteinRPG-RE 113 | mkdir build && cd build 114 | cmake .. 115 | make -j$(nproc) 116 | ``` 117 | 118 | ### 🚀 **Execution** 119 | After compiling, run the game with: 120 | ```sh 121 | ./build/src/WolfensteinRPG 122 | ``` 123 | 124 | ### 📦 **Creating the AppImage** 125 | 🔹 1. Download required tools 126 | ```sh 127 | wget -O appimagetool https://github.com/AppImage/AppImageKit/releases/latest/download/appimagetool-x86_64.AppImage 128 | wget -O linuxdeploy https://github.com/linuxdeploy/linuxdeploy/releases/latest/download/linuxdeploy-x86_64.AppImage 129 | chmod +x appimagetool linuxdeploy 130 | ``` 131 | 🔹 2. Generate the AppImage using the script 132 | ```sh 133 | chmod +x make-wolfenstein-rpg-linux-appimage.sh 134 | ./make-wolfenstein-rpg-linux-appimage.sh ./appimagetool ./linuxdeploy $(pwd) ./build/src/WolfensteinRPG 135 | ``` 136 | 137 | ### 🎮 **Default key configuration:** 138 | 139 | Move Forward: W, Up
140 | Move Backward: S, Down
141 | Move Left: A
142 | Move Right: D
143 | Turn Left: Left
144 | Turn Right: Right
145 | Atk/Talk/Use: Return
146 | Next Weapon: Z
147 | Prev Weapon: X
148 | Pass Turn: C
149 | Automap: Tab
150 | Menu Open/Back: Escape
151 | Items/Info: I
152 | Syringes: O
153 | Journal: P
154 | 155 | ### 🔑 **Original game cheat codes:** 156 | 157 | J2ME/BREW Version:
158 | 3666 -> Opens debug menu.
159 | 1666 -> Restarts level.
160 | 4332 -> Gives all keys, items and weapons to the player.
161 | 3366 -> Starts speed test "Benchmark".
162 | 163 | iOS Version:
164 | Tap the screen corners in the following order:
165 | Top left, top right, bottom left, bottom right, bottom left, bottom right -> Opens debug menu.
166 | Top left, top right, bottom left, bottom right, top left, bottom right -> Restarts level.
167 | Top left, top right, bottom left, bottom right, top right, bottom right -> Gives all keys, items and weapons to the player.
168 | Top left, top right, bottom left, bottom right, bottom left, top right -> Starts speed test "Benchmark".
169 | -------------------------------------------------------------------------------- /src/Player.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAYER_H__ 2 | #define __PLAYER_H__ 3 | 4 | #include "Enums.h" 5 | #include "Entity.h" 6 | #include "EntityDef.h" 7 | #include "CombatEntity.h" 8 | 9 | class Entity; 10 | class EntityDef; 11 | class CombatEntity; 12 | class Text; 13 | class InputStream; 14 | class OutputStream; 15 | class Graphics; 16 | class ScriptThread; 17 | class GameSprite; 18 | 19 | 20 | class Player 21 | { 22 | private: 23 | 24 | public: 25 | static constexpr int EXPIRE_DURATION = 5; 26 | static constexpr int MAX_DISPLAY_BUFFS = 6; 27 | static constexpr int ICE_FOG_DIST = 1024; 28 | static constexpr int MAX_NOTEBOOK_INDEXES = 8; 29 | static constexpr int NUMBER_OF_TARGET_PRACTICE_SHOTS = 8; 30 | static constexpr int HEAD_SHOT_POINTS = 30; 31 | static constexpr int BODY_SHOT_POINTS = 20; 32 | static constexpr int LEG_SHOT_POINTS = 10; 33 | static constexpr int NUMBER_OF_BITS_PER_VM_TRY = 3; 34 | static constexpr int BUFF_TURNS = 0; 35 | static constexpr int BUFF_AMOUNT = 15; 36 | static constexpr int DEF_STATUS_TURNS = 30; 37 | static constexpr int ANTI_FIRE_TURNS = 10; 38 | static constexpr int AGILITY_TURNS = 20; 39 | static constexpr int PURIFY_TURNS = 10; 40 | static constexpr int FEAR_TURNS = 6; 41 | static constexpr int COLD_TURNS = 5; 42 | static constexpr int BOX_X1 = 17; 43 | static constexpr int BOX_X2 = 31; 44 | static constexpr int BOX_X3 = 43; 45 | static constexpr int BOX_X4 = 55; 46 | 47 | static constexpr int WeaponSounds[18] = { 1137, 1137, 1137, 1130, 1134, 1134, 1113, 1142, 1149 , 1139, 1128, 1127, 1135, 1129, 1143, 1141, 1146, 1149 }; 48 | 49 | Entity* facingEntity; 50 | short inventory[Enums::INV_MAX]; 51 | short ammo[10]; 52 | int64_t weapons; 53 | short inventoryCopy[Enums::INV_MAX]; 54 | short ammoCopy[10]; 55 | int weaponsCopy; 56 | int disabledWeapons; 57 | int level; 58 | int currentXP; 59 | int nextLevelXP; 60 | int gold; 61 | CombatEntity* baseCe; 62 | CombatEntity* ce; 63 | EntityDef* activeWeaponDef; 64 | bool noclip; 65 | bool god; 66 | int playTime; 67 | int totalTime; 68 | int moves; 69 | int totalMoves; 70 | int completedLevels; 71 | int killedMonstersLevels; 72 | int foundSecretsLevels; 73 | int xpGained; 74 | int totalDeaths; 75 | short notebookIndexes[Player::MAX_NOTEBOOK_INDEXES]; 76 | short notebookPositions[Player::MAX_NOTEBOOK_INDEXES]; 77 | uint8_t questComplete; 78 | uint8_t questFailed; 79 | int numNotebookIndexes; 80 | int helpBitmask; 81 | int invHelpBitmask; 82 | int ammoHelpBitmask; 83 | int weaponHelpBitmask; 84 | int armorHelpBitmask; 85 | int cocktailDiscoverMask; 86 | int gamePlayedMask; 87 | int lastCombatTurn; 88 | bool inCombat; 89 | bool enableHelp; 90 | int turnTime; 91 | int highestMap; 92 | int prevWeapon; 93 | bool noDeathFlag; 94 | int numStatusEffects; 95 | int statusEffects[Enums::MAX_STATUS_EFFECTS]; 96 | short buffs[Enums::BUFF_MAX * 2]; 97 | int numbuffs; 98 | int purchasedWeapons; 99 | bool gameCompleted; 100 | GameSprite* playerSprite; 101 | int pickingStats; 102 | int oldPickingStats; 103 | int8_t* allMedals; 104 | int medals[2]; 105 | uint8_t medalInfo[22]; 106 | int8_t* bookMap; 107 | uint8_t foundBooks[4]; 108 | bool showBookStat; 109 | int bookIndex; 110 | int counters[8]; 111 | int monsterStats[2]; 112 | int pos[3]; 113 | bool soundFire; 114 | 115 | 116 | // Constructor 117 | Player(); 118 | // Destructor 119 | ~Player(); 120 | 121 | bool startup(); 122 | bool modifyCollision(Entity* entity); 123 | void advanceTurn(); 124 | void levelInit(); 125 | void fillMonsterStats(); 126 | void readyWeapon(); 127 | void selectWeapon(int i); 128 | void selectPrevWeapon(); 129 | void selectNextWeapon(); 130 | void modifyStat(int n, int n2); 131 | bool requireStat(int n, int n2); 132 | bool requireItem(int n, int n2, int n3, int n4); 133 | void addXP(int xp); 134 | void addLevel(); 135 | int calcLevelXP(int n); 136 | int calcScore(); 137 | bool addHealth(int i); 138 | bool addHealth(int i, bool b); 139 | void reset(); 140 | int calcDamageDir(int x1, int y1, int angle, int x2, int y2); 141 | void painEvent(Entity* entity, bool b); 142 | void pain(int n, Entity* entity, bool b); 143 | void died(); 144 | bool fireWeapon(Entity* entity, int n, int n2); 145 | bool useItem(int n); 146 | void giveGold(int n); 147 | bool give(int n, int n2, int n3); 148 | bool give(int n, int n2, int n3, bool b); 149 | void giveAmmoWeapon(int n, bool b); 150 | void updateQuests(short n, int n2); 151 | void setQuestTile(int n, int n2, int n3); 152 | bool isQuestDone(int n); 153 | bool isQuestFailed(int n); 154 | void formatTime(int n, Text* text); 155 | void showInvHelp(int n, bool b); 156 | void showAmmoHelp(int n, bool b); 157 | void showHelp(short n, bool b); 158 | void showWeaponHelp(int n, bool b); 159 | void showArmorHelp(int n, bool b); 160 | void drawBuffs(Graphics* graphics); 161 | bool loadState(InputStream* IS); 162 | bool saveState(OutputStream* OS); 163 | void unpause(int n); 164 | void relink(); 165 | void unlink(); 166 | void link(); 167 | void updateStats(); 168 | void updateStatusEffects(); 169 | void translateStatusEffects(); 170 | void removeStatusEffect(int effect); 171 | bool addStatusEffect(int effect, int amount, int turns); 172 | void drawStatusEffectIcon(Graphics* graphics, int n, int n2, int n3, int n4, int n5); 173 | void resetCounters(); 174 | int* GetPos(); 175 | Entity* getPlayerEnt(); 176 | void setPickUpWeapon(int n); 177 | void giveAll(); 178 | void equipForLevel(int mapID); 179 | void addArmor(int n); 180 | int distFrom(Entity* entity); 181 | void giveStandardMedal(int n, int n2); 182 | void giveMedal(int n, ScriptThread* scriptThread); 183 | void offerBook(int n, ScriptThread* scriptThread); 184 | void giveBook(int n, ScriptThread* scriptThread); 185 | uint8_t* getLevelMedalCount(); 186 | bool hasAllKills(int n); 187 | uint8_t* getLevelMedals(int n, bool b); 188 | void statusToString(int n, Text* text); 189 | bool hasPurifyEffect(); 190 | void checkForCloseSoundObjects(); 191 | }; 192 | 193 | #endif -------------------------------------------------------------------------------- /src/SDLGL.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "SDLGL.h" 5 | #include "App.h" 6 | 7 | 8 | SDLResVidModes sdlResVideoModes[18] = { 9 | {480, 320}, 10 | {640, 480}, 11 | {720, 400}, 12 | {720, 480}, 13 | {720, 576}, 14 | {800, 600}, 15 | {832, 624}, 16 | {960, 640}, 17 | {1024, 768}, 18 | {1152, 864}, 19 | {1152, 872}, 20 | {1280, 720}, 21 | {1280, 800}, 22 | {1280, 1024}, 23 | {1440, 900}, 24 | {1600, 1000}, 25 | {1680, 1050}, 26 | {1920, 1080} 27 | }; 28 | 29 | SDLGL::SDLGL() { 30 | this->initialized = false; 31 | } 32 | 33 | SDLGL::~SDLGL() { 34 | if (this) { 35 | if (this->initialized) { 36 | if (this->window) { 37 | SDL_SetWindowFullscreen(this->window, 0); 38 | if (this->glcontext) { 39 | SDL_GL_DeleteContext(this->glcontext); 40 | this->glcontext = nullptr; 41 | } 42 | SDL_DestroyWindow(this->window); 43 | this->window = nullptr; 44 | } 45 | 46 | #ifdef __linux__ 47 | if (this->gpSdlWindowIcon) { 48 | SDL_FreeSurface(this->gpSdlWindowIcon); 49 | this->gpSdlWindowIcon = nullptr; 50 | } 51 | #endif 52 | SDL_Quit(); 53 | } 54 | } 55 | } 56 | 57 | bool SDLGL::Initialize() { 58 | Uint32 flags; 59 | 60 | if (!this->initialized) { 61 | 62 | SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); 63 | if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { 64 | printf("Could not initialize SDL: %s", SDL_GetError()); 65 | } 66 | 67 | flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN /* | SDL_WINDOW_RESIZABLE*/; 68 | // Set the highdpi flags - this makes a big difference on Macs with 69 | // retina displays, especially when using small window sizes. 70 | flags |= SDL_WINDOW_ALLOW_HIGHDPI; 71 | 72 | this->oldResolutionIndex = -1; 73 | this->resolutionIndex = 0; 74 | this->winVidWidth = sdlResVideoModes[this->resolutionIndex].width;//Applet::IOS_WIDTH*2; 75 | this->winVidHeight = sdlResVideoModes[this->resolutionIndex].height;//Applet::IOS_HEIGHT*2; 76 | 77 | //this->winVidWidth = 1440; 78 | //this->winVidHeight = 900; 79 | 80 | // Linux: create the icon for the window 81 | #ifdef __linux__ 82 | this->gpSdlWindowIcon = SDL_CreateRGBSurfaceWithFormatFrom((void*)Applet::gIcon_64_raw_rgb888, 64, 64, 24, 64 * 3, SDL_PIXELFORMAT_RGB24); 83 | #endif 84 | 85 | this->window = SDL_CreateWindow("Wolfenstein RPG By [GEC] Version 0.1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, winVidWidth, winVidHeight, flags); 86 | if (!this->window) { 87 | printf("Could not set %dx%d video mode: %s", winVidWidth, winVidHeight, SDL_GetError()); 88 | } 89 | 90 | this->vidWidth = Applet::IOS_WIDTH; 91 | this->vidHeight = Applet::IOS_HEIGHT; 92 | this->oldWindowMode = -1; 93 | this->windowMode = 0; 94 | this->oldVSync = false; 95 | this->vSync = true; 96 | 97 | //SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2"); 98 | //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); 99 | //SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");//sdlVideo.vSync ? "1" : "0"); 100 | this->updateVideo(); 101 | 102 | // Linux: set the icon for the window 103 | #ifdef __linux__ 104 | if (this->gpSdlWindowIcon) { 105 | SDL_SetWindowIcon(this->window, this->gpSdlWindowIcon); 106 | } 107 | #endif 108 | 109 | this->glcontext = SDL_GL_CreateContext(window); 110 | 111 | // now you can make GL calls. 112 | glClearColor(0, 0, 0, 1); 113 | glClear(GL_COLOR_BUFFER_BIT); 114 | 115 | SDL_GL_SwapWindow(this->window); 116 | 117 | #ifdef _WIN32 118 | // Check for joysticks 119 | SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); 120 | #endif 121 | this->initialized = true; 122 | } 123 | 124 | return this->initialized; 125 | } 126 | 127 | 128 | #include //va_list|va_start|va_end 129 | 130 | void SDLGL::Error(const char* fmt, ...) 131 | { 132 | char errMsg[256]; 133 | va_list ap; 134 | va_start(ap, fmt); 135 | vsnprintf(errMsg, sizeof(errMsg), fmt, ap); 136 | va_end(ap); 137 | 138 | printf("%s", errMsg); 139 | 140 | const SDL_MessageBoxButtonData buttons[] = { 141 | { /* .flags, .buttonid, .text */ 0, 0, "Ok" }, 142 | }; 143 | const SDL_MessageBoxColorScheme colorScheme = { 144 | { /* .colors (.r, .g, .b) */ 145 | /* [SDL_MESSAGEBOX_COLOR_BACKGROUND] */ 146 | { 255, 0, 0 }, 147 | /* [SDL_MESSAGEBOX_COLOR_TEXT] */ 148 | { 0, 255, 0 }, 149 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER] */ 150 | { 255, 255, 0 }, 151 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND] */ 152 | { 0, 0, 255 }, 153 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED] */ 154 | { 255, 0, 255 } 155 | } 156 | }; 157 | const SDL_MessageBoxData messageboxdata = { 158 | SDL_MESSAGEBOX_ERROR, /* .flags */ 159 | NULL, /* .window */ 160 | "Doom II RPG Error", /* .title */ 161 | errMsg, /* .message */ 162 | SDL_arraysize(buttons), /* .numbuttons */ 163 | buttons, /* .buttons */ 164 | &colorScheme /* .colorScheme */ 165 | }; 166 | 167 | SDL_ShowMessageBox(&messageboxdata, NULL); 168 | //closeZipFile(&zipFile); 169 | //DoomRPG_FreeAppData(doomRpg); 170 | //SDL_CloseAudio(); 171 | //SDL_Close(); 172 | this->~SDLGL(); 173 | exit(0); 174 | } 175 | 176 | 177 | void SDLGL::transformCoord2f(float* x, float* y) { 178 | int w, h; 179 | SDL_GetWindowSize(this->window, &w, &h); 180 | *x *= (float)w / (float)Applet::IOS_WIDTH; 181 | *y *= (float)h / (float)Applet::IOS_HEIGHT; 182 | } 183 | 184 | void SDLGL::centerMouse(int x, int y) { 185 | float X = (float)((Applet::IOS_WIDTH / 2) + x); 186 | float Y = (float)((Applet::IOS_HEIGHT / 2) + y); 187 | this->transformCoord2f(&X, &Y); 188 | SDL_WarpMouseInWindow(this->window, (int)X, (int)Y); 189 | } 190 | 191 | void SDLGL::updateWinVid(int w, int h) { 192 | this->winVidWidth = w; 193 | this->winVidHeight = h; 194 | } 195 | 196 | void SDLGL::updateVideo() { 197 | if (this->vSync != this->oldVSync) { 198 | SDL_GL_SetSwapInterval(this->vSync ? 1 : 0); 199 | this->oldVSync = this->vSync; 200 | } 201 | 202 | if (this->windowMode != this->oldWindowMode) { 203 | SDL_SetWindowFullscreen(this->window, 0); 204 | SDL_SetWindowBordered(this->window, SDL_TRUE); 205 | 206 | if (this->windowMode == 1) { 207 | SDL_SetWindowBordered(this->window, SDL_FALSE); 208 | } 209 | else if (this->windowMode == 2) { 210 | SDL_SetWindowFullscreen(this->window, SDL_WINDOW_FULLSCREEN); 211 | } 212 | this->oldWindowMode = this->windowMode; 213 | } 214 | 215 | if (this->resolutionIndex != this->oldResolutionIndex) { 216 | SDL_SetWindowSize(this->window, sdlResVideoModes[this->resolutionIndex].width, sdlResVideoModes[this->resolutionIndex].height); 217 | SDL_SetWindowPosition(this->window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); 218 | this->updateWinVid(sdlResVideoModes[this->resolutionIndex].width, sdlResVideoModes[this->resolutionIndex].height); 219 | this->oldResolutionIndex = this->resolutionIndex; 220 | } 221 | 222 | int winVidWidth, winVidHeight; 223 | SDL_GetWindowSize(this->window, &winVidWidth, &winVidHeight); 224 | this->updateWinVid(winVidWidth, winVidHeight); 225 | } 226 | 227 | void SDLGL::restore() { 228 | if (this->vSync != this->oldVSync) { 229 | this->vSync = this->oldVSync; 230 | } 231 | 232 | if (this->windowMode != this->oldWindowMode) { 233 | this->windowMode = this->oldWindowMode; 234 | } 235 | 236 | if (this->resolutionIndex != this->oldResolutionIndex) { 237 | this->resolutionIndex = this->oldResolutionIndex; 238 | } 239 | } -------------------------------------------------------------------------------- /src/Image.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "CAppContainer.h" 4 | #include "App.h" 5 | #include "Canvas.h" 6 | #include "Image.h" 7 | #include "SDLGL.h" 8 | 9 | Image::Image() { 10 | } 11 | 12 | Image::~Image() { 13 | if (this) { 14 | if (this->piDIB) { 15 | this->piDIB->~IDIB(); 16 | free(this->piDIB); 17 | } 18 | this->piDIB = nullptr; 19 | glDeleteTextures(1, &this->texture); 20 | this->texture = -1; 21 | free(this); 22 | } 23 | } 24 | 25 | void Image::CreateTexture(uint16_t* data, uint32_t width, uint32_t height) { 26 | glEnable(GL_TEXTURE_2D); 27 | glGenTextures(1, &this->texture); 28 | glBindTexture(GL_TEXTURE_2D, this->texture); 29 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 30 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 31 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 32 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 33 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 34 | 35 | if (this->isTransparentMask == false) { 36 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data); 37 | } 38 | else { 39 | uint32_t i = 0; 40 | uint16_t* dat = data; 41 | while (i < height * width) { 42 | uint32_t pix = *dat; 43 | if (pix == 0xf81f) { 44 | pix = 0x0000; 45 | } 46 | else { 47 | pix = pix & 0xffc0 | (uint16_t)((pix & 0x1f) << 1) | 1; 48 | } 49 | *dat++ = pix; 50 | i++; 51 | } 52 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, data); 53 | } 54 | } 55 | 56 | void Image::DrawTexture(int texX, int texY, int texW, int texH, int posX, int posY, int rotateMode, int renderMode) { 57 | float scaleW, scaleH; 58 | float scaleTexW, scaleTexH; 59 | float scaleX, scaleY; 60 | float vp[12]; 61 | float st[8]; 62 | 63 | PFNGLACTIVETEXTUREPROC glActiveTexture = (PFNGLACTIVETEXTUREPROC)SDL_GL_GetProcAddress("glActiveTexture"); 64 | 65 | this->setRenderMode(renderMode); 66 | scaleW = (float)texW * 0.5f; 67 | scaleH = (float)texH * 0.5f; 68 | scaleX = (float)posX; 69 | scaleY = (float)posY; 70 | 71 | //CAppContainer::getInstance()->sdlGL->transformCoord2f(&scaleW, &scaleH); 72 | //CAppContainer::getInstance()->sdlGL->transformCoord2f(&scaleX, &scaleY); 73 | 74 | vp[2] = 0.5f; 75 | vp[5] = 0.5f; 76 | vp[0] = scaleW; 77 | vp[8] = 0.5f; 78 | vp[11] = 0.5f; 79 | vp[3] = -scaleW; 80 | vp[6] = scaleW; 81 | vp[7] = scaleH; 82 | vp[1] = -scaleH; 83 | vp[4] = -scaleH; 84 | vp[9] = -scaleW; 85 | vp[10] = scaleH; 86 | 87 | st[0] = 0.0f; 88 | st[1] = 0.0f; 89 | st[2] = 0.0f; 90 | st[3] = 0.0f; 91 | st[4] = 0.0f; 92 | st[5] = 0.0f; 93 | st[6] = 0.0f; 94 | st[7] = 0.0f; 95 | 96 | scaleTexW = 1.0f / (float)this->texWidth; 97 | scaleTexH = 1.0f / (float)this->texHeight; 98 | st[0] = scaleTexW * (float)(texW + texX); 99 | st[4] = st[0]; 100 | st[1] = scaleTexH * (float)texY; 101 | st[3] = st[1]; 102 | st[2] = scaleTexW * (float)texX; 103 | st[6] = st[2]; 104 | st[5] = scaleTexH * (float)(texH + texY); 105 | st[7] = st[5]; 106 | 107 | 108 | glEnable(GL_TEXTURE_2D); 109 | glActiveTexture(GL_TEXTURE0); 110 | glBindTexture(GL_TEXTURE_2D, this->texture); 111 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 112 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 113 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 114 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 115 | glVertexPointer(3, GL_FLOAT, 0, vp); 116 | glEnableClientState(GL_VERTEX_ARRAY); 117 | glTexCoordPointer(2, GL_FLOAT, 0, st); 118 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); 119 | glDisableClientState(GL_COLOR_ARRAY); 120 | glMatrixMode(GL_MODELVIEW); 121 | glPushMatrix(); 122 | glLoadIdentity(); 123 | glTranslatef(scaleW + (float)(scaleX), scaleH + (float)(scaleY), 0.0); 124 | switch (rotateMode) 125 | { 126 | case 1: 127 | glRotatef(90.0f, 0.0f, 0.0f, 1.0f); 128 | break; 129 | case 2: 130 | glRotatef(180.0f, 0.0f, 0.0f, 1.0f); 131 | break; 132 | case 3: 133 | glRotatef(270.0f, 0.0f, 0.0f, 1.0f); 134 | break; 135 | case 4: 136 | glScalef(-1.0f, 1.0f, 1.0f); 137 | break; 138 | case 5: 139 | glRotatef(90.0f, 0.0f, 0.0f, 1.0f); 140 | glScalef(-1.0f, 1.0f, 1.0f); 141 | break; 142 | case 6: 143 | glRotatef(180.0f, 0.0f, 0.0f, 1.0f); 144 | glScalef(-1.0f, 1.0f, 1.0f); 145 | break; 146 | case 7: 147 | glRotatef(270.0f, 0.0f, 0.0f, 1.0f); 148 | glScalef(-1.0f, 1.0f, 1.0f); 149 | break; 150 | 151 | case 8: // New 152 | glScalef(1.0f, -1.0f, 1.0f); 153 | break; 154 | default: 155 | break; 156 | } 157 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 158 | glPopMatrix(); 159 | } 160 | 161 | void Image::setRenderMode(int renderMode) { 162 | Applet* app = CAppContainer::getInstance()->app; 163 | int color; 164 | 165 | switch (renderMode) { 166 | case 0: 167 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 168 | if (this->isTransparentMask == false) { 169 | glDisable(GL_ALPHA_TEST); 170 | glDisable(GL_BLEND); 171 | return; 172 | } 173 | glEnable(GL_ALPHA_TEST); 174 | break; 175 | case 1: 176 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 177 | glColor4f(1.0f, 1.0f, 1.0f, 0.25f); 178 | glDisable(GL_ALPHA_TEST); 179 | break; 180 | case 2: 181 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 182 | glColor4f(1.0f, 1.0f, 1.0f, 0.5f); 183 | glDisable(GL_ALPHA_TEST); 184 | break; 185 | case 3: 186 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 187 | glEnable(GL_ALPHA_TEST); 188 | glAlphaFunc(GL_GREATER, 0); 189 | glEnable(GL_BLEND); 190 | glBlendFunc(GL_SRC_COLOR, GL_ONE); 191 | return; 192 | case 8: 193 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 194 | glEnable(GL_BLEND); 195 | color = Graphics::charColors[app->canvas->graphics.currentCharColor]; 196 | glColor4ub(color >> 0x10 & 0xff, color >> 8 & 0xff, color & 0xff, color >> 0x18); 197 | return; 198 | case 10: 199 | case 12: 200 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 201 | glColor4f(1.0f, 1.0f, 1.0f, 0.75f); 202 | glDisable(GL_ALPHA_TEST); 203 | break; 204 | case 11: 205 | case 13: 206 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 207 | glColor4f(1.0f, 1.0f, 1.0f, app->canvas->blendSpecialAlpha); 208 | glDisable(GL_ALPHA_TEST); 209 | break; 210 | case 14: // [GEC] Nuevo caso para multiplicar texturas 211 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 212 | glEnable(GL_BLEND); 213 | glBlendFunc(GL_DST_COLOR, GL_ZERO); 214 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 215 | glDisable(GL_ALPHA_TEST); 216 | return; 217 | default: 218 | return; 219 | } 220 | glAlphaFunc(GL_GREATER, 0); 221 | glEnable(GL_BLEND); 222 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 223 | } 224 | -------------------------------------------------------------------------------- /src/CardGames.h: -------------------------------------------------------------------------------- 1 | #ifndef __CARDGAMES_H__ 2 | #define __CARDGAMES_H__ 3 | 4 | class Image; 5 | class Text; 6 | class Entity; 7 | class EntityDef; 8 | class ScriptThread; 9 | class Graphics; 10 | 11 | class fmButtonContainer; 12 | class fmScrollButton; 13 | class fmButton; 14 | class fmSwipeArea; 15 | 16 | class CardGames 17 | { 18 | private: 19 | 20 | public: 21 | static constexpr int GRAVITY = 10; 22 | static constexpr int DEF_VELOCITY = 1024; 23 | static constexpr int NUM_POKER_CARDS = 51; 24 | static constexpr int CARD_W = 34; 25 | static constexpr int CARD_H = 50; 26 | static constexpr int SUITSTART = 112; 27 | 28 | static constexpr int CARD_ROT0 = 1; 29 | static constexpr int CARD_ROT90 = 2; 30 | static constexpr int CARD_ROT180 = 4; 31 | static constexpr int CARD_ROT270 = 8; 32 | static constexpr int CARD_FACE_UP = 16; 33 | static constexpr int CARD_LERPING = 32; 34 | static constexpr int CARD_EXLERP = 64; 35 | static constexpr int CARD_HIDDEN = 128; 36 | static constexpr int CARD_PLAYER = 256; 37 | static constexpr int CARD_DEALER = 512; 38 | static constexpr int CARD_DARKEN = 1024; 39 | 40 | static constexpr int CARD_DESC = 0; 41 | static constexpr int CARD_SRCX = 1; 42 | static constexpr int CARD_SRCY = 2; 43 | static constexpr int CARD_DSTX = 3; 44 | static constexpr int CARD_DSTY = 4; 45 | static constexpr int CARD_FLAGS = 5; 46 | static constexpr int CARD_START = 6; 47 | static constexpr int CARD_LERP_DUR = 7; 48 | static constexpr int CARD_FIELDS = 8; 49 | static constexpr int MAX_CARDS = 24; 50 | 51 | static constexpr int PART_X = 0; 52 | static constexpr int PART_Y = 1; 53 | static constexpr int PART_VX = 2; 54 | static constexpr int PART_VY = 3; 55 | static constexpr int PART_ALIVE = 4; 56 | static constexpr int PART_FIELDS = 5; 57 | 58 | static constexpr int CHIP_OWNER = 0; 59 | static constexpr int CHIP_SRCX = 1; 60 | static constexpr int CHIP_SRCY = 2; 61 | static constexpr int CHIP_DSTX = 3; 62 | static constexpr int CHIP_DSTY = 4; 63 | static constexpr int CHIP_START = 5; 64 | static constexpr int CHIP_DUR = 6; 65 | static constexpr int CHIP_FIELDS = 7; 66 | static constexpr int MAX_CHIPS = 20; 67 | 68 | static constexpr int GAME_STATE = 0; 69 | static constexpr int PREV_STATE = 1; 70 | static constexpr int STATE_TIME = 2; 71 | static constexpr int CUR_BET = 3; 72 | static constexpr int MSG_ID = 4; 73 | static constexpr int SUB_STATE = 5; 74 | static constexpr int CARD_SEL_IDX = 6; 75 | static constexpr int DEALER_SEL_IDX = 7; 76 | static constexpr int MSG_TIME = 8; 77 | 78 | static constexpr int INVALID_CARD = -1; 79 | static constexpr int DEFAULT_TREASURE = 100; 80 | static constexpr int NUM_WAR_CARDS = 6; 81 | static constexpr int NUM_CARD_ROWS = 3; 82 | 83 | static constexpr int BORDER_W = 175; 84 | static constexpr int BORDER_H = 70; 85 | static constexpr int CHIP_W = 34; 86 | static constexpr int CHIP_H = 20; 87 | static constexpr int CHIP_PART_H = 12; 88 | static constexpr int PORTRAIT_WH = 54; 89 | static constexpr int FONT_W = 9; 90 | static constexpr int FONT_H = 12; 91 | static constexpr int MAX_LERPING = 3; 92 | static constexpr int DEF_SPEED = 128; 93 | 94 | static constexpr int PLAYER_CHIP = 1; 95 | static constexpr int DEALER_CHIP = 2; 96 | 97 | static constexpr int WAR_BET = 0; 98 | static constexpr int WAR_TOSS_CHIPS = 1; 99 | static constexpr int WAR_DEAL = 2; 100 | static constexpr int WAR_PLAYERCHOOSE = 3; 101 | static constexpr int WAR_DEALERCHOOSE = 4; 102 | static constexpr int WAR_RESOLVE = 5; 103 | static constexpr int WAR_REDEAL = 6; 104 | static constexpr int WAR_PLAYERDISCARD = 7; 105 | static constexpr int WAR_DEALERDISCARD = 8; 106 | static constexpr int WAR_PICKWARCARD = 9; 107 | static constexpr int WAR_RESOLVEFINAL = 10; 108 | static constexpr int WAR_MESSAGE = 11; 109 | 110 | static constexpr int PLAYER_TURN = ((1 << WAR_BET) | (1 << WAR_PLAYERCHOOSE) | (1 << WAR_PLAYERDISCARD)); // 137 111 | static constexpr int DEALER_TURN = ((1 << WAR_DEALERCHOOSE) | (1 << WAR_DEALERDISCARD)); // 272 112 | static constexpr int DEALER_MOVE_TIMEOUT = 750; 113 | 114 | int touchMe; 115 | Image* imgOtherImgs; 116 | Image* imgTable; 117 | int numPlayerCards; 118 | int numDealerCards; 119 | short playersCards[12]; 120 | short dealersCards[12]; 121 | int cardsInPlay[CardGames::MAX_CARDS * CardGames::CARD_FIELDS]; 122 | int numCardsInPlay; 123 | long long deckMask; 124 | int numCardsLerping; 125 | int backgroundColor; 126 | ScriptThread* callingThread; 127 | bool savePlayer; 128 | int playerTreasure; 129 | int aiTreasure; 130 | int playerChips; 131 | int dealerChips; 132 | int startingChips; 133 | int chipAmount; 134 | int betPercentage; 135 | int CARDS_X; 136 | int CARDS_Y; 137 | int NUM_CARDS_W; 138 | int NUM_CARDS_H; 139 | int WAR_CARDS_X; 140 | int START_BTM_BG; 141 | int PORTRAIT_Y; 142 | int xMin; 143 | int xMaxW; 144 | int BJPortX; 145 | int BJChipsX; 146 | int GuntherPortX; 147 | int GuntherChipsX; 148 | int chipsY; 149 | int CARD_TEXT_Y; 150 | int CARD_WAR_TEXT_Y; 151 | int curCardsW; 152 | int curCardsH; 153 | Image* flakImg; 154 | bool animationDone; 155 | int cardsDiscarded; 156 | int particleFrameTime; 157 | int numParticles; 158 | short particles[CardGames::MAX_CARDS * CardGames::PART_FIELDS]; 159 | int numChipsLerping; 160 | int numChips; 161 | int chips[CardGames::MAX_CHIPS * CardGames::CHIP_FIELDS]; 162 | int* stateVars; 163 | Image* imgUpPointerNormal; 164 | Image* imgUpPointerPressed; 165 | Image* imgDownPointerNormal; 166 | Image* imgDownPointerPressed; 167 | Image* imgSwitchUp; 168 | Image* imgSwitchDown; 169 | fmButtonContainer* m_cardGamesButtons; 170 | bool touched; 171 | bool wasTouched; 172 | 173 | // Constructor 174 | CardGames(); 175 | // Destructor 176 | ~CardGames(); 177 | 178 | void initGame(int n, ScriptThread* callingThread, bool savePlayer); 179 | void resetHand(); 180 | void endGame(int n); 181 | bool giveTreasure(int n, int n2); 182 | void nextState(); 183 | void prevState(); 184 | void setState(int state); 185 | void updateGame(Graphics* graphics); 186 | void dealerPickCard(); 187 | bool dealerMoveSelector(); 188 | void handleInput(int n, int n2); 189 | void dealFullDeck(); 190 | void dealWarHand(); 191 | void reDealCard(int field, int flags, int n3); 192 | void dealCard(int n, int srcX, int srcY, int destX, int destY, int flags, int speed); 193 | void drawCardHud(Graphics* graphics); 194 | void drawChips(Graphics* graphics); 195 | void drawCards(Graphics* graphics); 196 | void drawCard(Graphics* graphics, int x, int y, int n3, int flags); 197 | void clearParticles(); 198 | void drawParticles(Graphics* graphics); 199 | bool updateParticle(int filed, int n2); 200 | void updateLerpingCard(int n, int* posX, int* posY); 201 | void allocChip(int srcX, int srcY, int dstX, int dstY, int start, int dur, int owner); 202 | void setChips(int n, int n2); 203 | void drawPlayingBG(Graphics* graphics); 204 | void updateWar(Graphics* graphics); 205 | void WAR_BET_FUNC(Graphics* graphics); 206 | void WAR_TOSS_CHIPS_FUNC(); 207 | void WAR_DEAL_FUNC(); 208 | void WAR_PLAYERCHOOSE_FUNC(Graphics* graphics); 209 | void WAR_PICKWARCARD_FUNC(Graphics* graphics, int n); 210 | void WAR_DEALERCHOOSE_FUNC(Graphics* graphics, int n); 211 | void WAR_DEALERDISCARD_FUNC(Graphics* graphics, int n); 212 | void WAR_REDEAL_FUNC(Graphics* graphics, int n); 213 | void WAR_PLAYERDISCARD_FUNC(Graphics* graphics); 214 | void WAR_RESOLVE_FUNC(Graphics* graphics, int n); 215 | void WAR_MESSAGE_FUNC(Graphics* graphics); 216 | void drawSelector(Graphics* graphics); 217 | int dealerAI(int n); 218 | void handleWarInput(int n, int n2); 219 | void updateBetPerc(); 220 | void explodeCards(); 221 | void shutdown(); 222 | void touchStart(int pressX, int pressY); 223 | void touchMove(int pressX, int pressY); 224 | int touchToKey(int pressX, int pressY); 225 | }; 226 | 227 | #endif -------------------------------------------------------------------------------- /cmake/Modules/FindSDL2.cmake: -------------------------------------------------------------------------------- 1 | 2 | # This module defines 3 | # SDL2_FOUND, if false, do not try to link to SDL2 4 | # SDL2::SDL2, the import target for SDL2 5 | # 6 | # This module responds to the the flag: 7 | # SDL2_BUILDING_LIBRARY 8 | # If this is defined, then no SDL2main will be linked in because 9 | # only applications need main(). 10 | # Otherwise, it is assumed you are building an application and this 11 | # module will attempt to locate and set the the proper link flags 12 | # as part of the returned SDL2_LIBRARY variable. 13 | # 14 | # Don't forget to include SDLmain.h and SDLmain.m your project for the 15 | # OS X framework based version. (Other versions link to -lSDL2main which 16 | # this module will try to find on your behalf.) Also for OS X, this 17 | # module will automatically add the -framework Cocoa on your behalf. 18 | # 19 | # $SDL2DIR is an environment variable that would 20 | # correspond to the ./configure --prefix=$SDL2DIR 21 | # used in building SDL2. 22 | # l.e.galup 9-20-02 23 | # 24 | # Modified by Eric Wing. 25 | # Added code to assist with automated building by using environmental variables 26 | # and providing a more controlled/consistent search behavior. 27 | # Added new modifications to recognize OS X frameworks and 28 | # additional Unix paths (FreeBSD, etc). 29 | # Also corrected the header search path to follow "proper" SDL guidelines. 30 | # Added a search for SDL2main which is needed by some platforms. 31 | # Added a search for threads which is needed by some platforms. 32 | # Added needed compile switches for MinGW. 33 | # 34 | # On OSX, this will prefer the Framework version (if found) over others. 35 | # People will have to manually change the cache values of 36 | # SDL2_LIBRARY to override this selection or set the CMake environment 37 | # CMAKE_INCLUDE_PATH to modify the search paths. 38 | # 39 | # Note that the header path has changed from SDL2/SDL.h to just SDL.h 40 | # This needed to change because "proper" SDL convention 41 | # is #include "SDL.h", not . This is done for portability 42 | # reasons because not all systems place things in SDL2/ (see FreeBSD). 43 | # 44 | # Modified by Alex Mayfield 45 | # Create an imported target. This approach is much cleaner. 46 | 47 | #============================================================================= 48 | # Copyright 2003-2009 Kitware, Inc. 49 | # 50 | # Distributed under the OSI-approved BSD License (the "License"); 51 | # see accompanying file Copyright.txt for details. 52 | # 53 | # This software is distributed WITHOUT ANY WARRANTY; without even the 54 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 55 | # See the License for more information. 56 | #============================================================================= 57 | # (To distribute this file outside of CMake, substitute the full 58 | # License text for the above reference.) 59 | 60 | add_library(SDL2::SDL2 UNKNOWN IMPORTED) 61 | 62 | SET(SDL2_SEARCH_PATHS 63 | ~/Library/Frameworks 64 | /Library/Frameworks 65 | /usr/local 66 | /usr 67 | /sw # Fink 68 | /opt/local # DarwinPorts 69 | /opt/csw # Blastwave 70 | /opt 71 | ${SDL2_PATH} 72 | ) 73 | 74 | FIND_PATH(SDL2_INCLUDE_DIR SDL.h 75 | HINTS 76 | $ENV{SDL2DIR} 77 | PATH_SUFFIXES include/SDL2 include 78 | PATHS ${SDL2_SEARCH_PATHS} 79 | ) 80 | 81 | if(SDL2_INCLUDE_DIR) 82 | set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES 83 | ${SDL2_INCLUDE_DIR}) 84 | if(EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") 85 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") 86 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") 87 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") 88 | string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}") 89 | string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}") 90 | string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}") 91 | set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}) 92 | unset(SDL2_VERSION_MAJOR_LINE) 93 | unset(SDL2_VERSION_MINOR_LINE) 94 | unset(SDL2_VERSION_PATCH_LINE) 95 | unset(SDL2_VERSION_MAJOR) 96 | unset(SDL2_VERSION_MINOR) 97 | unset(SDL2_VERSION_PATCH) 98 | endif() 99 | endif() 100 | 101 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 102 | set(PATH_SUFFIXES lib64 lib/x64 lib) 103 | else() 104 | set(PATH_SUFFIXES lib/x86 lib) 105 | endif() 106 | 107 | FIND_LIBRARY(SDL2_LIBRARY 108 | NAMES SDL2 109 | HINTS 110 | $ENV{SDL2DIR} 111 | PATH_SUFFIXES ${PATH_SUFFIXES} 112 | PATHS ${SDL2_SEARCH_PATHS} 113 | ) 114 | 115 | IF(NOT SDL2_BUILDING_LIBRARY) 116 | IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") 117 | # Non-OS X framework versions expect you to also dynamically link to 118 | # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms 119 | # seem to provide SDL2main for compatibility even though they don't 120 | # necessarily need it. 121 | 122 | # Backwards compatible with SDL2MAIN_LIBRARY 123 | if(NOT SDL2_MAIN_LIBRARY AND SDL2MAIN_LIBRARY) 124 | set(SDL2_MAIN_LIBRARY ${SDL2MAIN_LIBRARY} 125 | CACHE PATH "Path to a library.") 126 | endif() 127 | 128 | FIND_LIBRARY(SDL2_MAIN_LIBRARY 129 | NAMES SDL2main 130 | HINTS 131 | $ENV{SDL2DIR} 132 | PATH_SUFFIXES ${PATH_SUFFIXES} 133 | PATHS ${SDL2_SEARCH_PATHS} 134 | ) 135 | ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") 136 | ENDIF(NOT SDL2_BUILDING_LIBRARY) 137 | 138 | # SDL2 may require threads on your system. 139 | # The Apple build may not need an explicit flag because one of the 140 | # frameworks may already provide it. 141 | # But for non-OSX systems, I will use the CMake Threads package. 142 | IF(NOT APPLE) 143 | FIND_PACKAGE(Threads) 144 | IF(CMAKE_USE_PTHREADS_INIT) 145 | set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_COMPILE_DEFINITIONS 146 | "_REENTRANT" APPEND) 147 | ENDIF(CMAKE_USE_PTHREADS_INIT) 148 | ENDIF(NOT APPLE) 149 | 150 | IF(SDL2_LIBRARY) 151 | set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION ${SDL2_LIBRARY}) 152 | 153 | # In MinGW, -lmingw32 always comes first 154 | if(MINGW) 155 | set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES "mingw32" APPEND) 156 | endif() 157 | 158 | # For SDL2main 159 | IF(NOT SDL2_BUILDING_LIBRARY) 160 | IF(SDL2_MAIN_LIBRARY) 161 | set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES 162 | ${SDL2_MAIN_LIBRARY} APPEND) 163 | # Ensure proper link order by specifying the library twice 164 | set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES 165 | ${SDL2_LIBRARY} APPEND) 166 | ENDIF(SDL2_MAIN_LIBRARY) 167 | ENDIF(NOT SDL2_BUILDING_LIBRARY) 168 | 169 | # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. 170 | # CMake doesn't display the -framework Cocoa string in the UI even 171 | # though it actually is there if I modify a pre-used variable. 172 | # I think it has something to do with the CACHE STRING. 173 | # So I use a temporary variable until the end so I can set the 174 | # "real" variable in one-shot. 175 | IF(APPLE) 176 | set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES 177 | "-framework Cocoa" APPEND) 178 | ENDIF(APPLE) 179 | 180 | # For threads, as mentioned Apple doesn't need this. 181 | # In fact, there seems to be a problem if I used the Threads package 182 | # and try using this line, so I'm just skipping it entirely for OS X. 183 | IF(NOT APPLE) 184 | set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES 185 | ${CMAKE_THREAD_LIBS_INIT} APPEND) 186 | ENDIF(NOT APPLE) 187 | 188 | # For MinGW library 189 | IF(MINGW) 190 | set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES 191 | "-mwindows" APPEND) 192 | ENDIF(MINGW) 193 | ENDIF(SDL2_LIBRARY) 194 | 195 | INCLUDE(FindPackageHandleStandardArgs) 196 | 197 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR VERSION_VAR SDL2_VERSION_STRING) 198 | -------------------------------------------------------------------------------- /src/ZipFile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "ZipFile.h" 7 | #include "SDLGL.h" 8 | 9 | #define MIN(a,b) (((a)<(b))?(a):(b)) 10 | #define MAX(a,b) (((a)>(b))?(a):(b)) 11 | 12 | void Error(const char* fmt, ...) 13 | { 14 | char errMsg[256]; 15 | va_list ap; 16 | va_start(ap, fmt); 17 | vsnprintf(errMsg, sizeof(errMsg), fmt, ap); 18 | va_end(ap); 19 | 20 | printf("%s", errMsg); 21 | 22 | const SDL_MessageBoxButtonData buttons[] = { 23 | { /* .flags, .buttonid, .text */ 0, 0, "Ok" }, 24 | }; 25 | const SDL_MessageBoxColorScheme colorScheme = { 26 | { /* .colors (.r, .g, .b) */ 27 | /* [SDL_MESSAGEBOX_COLOR_BACKGROUND] */ 28 | { 255, 0, 0 }, 29 | /* [SDL_MESSAGEBOX_COLOR_TEXT] */ 30 | { 0, 255, 0 }, 31 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER] */ 32 | { 255, 255, 0 }, 33 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND] */ 34 | { 0, 0, 255 }, 35 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED] */ 36 | { 255, 0, 255 } 37 | } 38 | }; 39 | const SDL_MessageBoxData messageboxdata = { 40 | SDL_MESSAGEBOX_ERROR, /* .flags */ 41 | NULL, /* .window */ 42 | "Wolfenstein RPG Error", /* .title */ 43 | errMsg, /* .message */ 44 | SDL_arraysize(buttons), /* .numbuttons */ 45 | buttons, /* .buttons */ 46 | &colorScheme /* .colorScheme */ 47 | }; 48 | 49 | SDL_ShowMessageBox(&messageboxdata, NULL); 50 | exit(0); 51 | } 52 | 53 | static void* zip_alloc(void* ctx, unsigned int items, unsigned int size) 54 | { 55 | return malloc(items * size); 56 | } 57 | 58 | static void zip_free(void* ctx, void* ptr) 59 | { 60 | free(ptr); 61 | } 62 | 63 | static int16_t _ReadShort(FILE* fp) 64 | { 65 | int16_t sData = 0; 66 | 67 | if (fp) { 68 | fread(&sData, sizeof(int16_t), 1, fp); 69 | } 70 | 71 | return sData; 72 | } 73 | 74 | static int32_t _ReadInt(FILE* fp) 75 | { 76 | int32_t iData = 0; 77 | 78 | if (fp) { 79 | fread(&iData, sizeof(int32_t), 1, fp); 80 | } 81 | 82 | return iData; 83 | } 84 | 85 | ZipFile::ZipFile() { 86 | memset(this, 0, sizeof(ZipFile)); 87 | } 88 | 89 | ZipFile::~ZipFile() { 90 | } 91 | 92 | void ZipFile::findAndReadZipDir(int startoffset) { 93 | int sig, offset, count; 94 | int namesize, metasize, commentsize; 95 | int i; 96 | 97 | fseek(this->file, startoffset, SEEK_SET); 98 | 99 | sig = _ReadInt(this->file); 100 | if (sig != ZIP_END_OF_CENTRAL_DIRECTORY_SIG) { 101 | Error("wrong zip end of central directory signature (0x%x)", sig); 102 | } 103 | 104 | _ReadShort(this->file); // this disk 105 | _ReadShort(this->file); // start disk 106 | _ReadShort(this->file); // entries in this disk 107 | count = _ReadShort(this->file); // entries in central directory disk 108 | _ReadInt(this->file); // size of central directory 109 | offset = _ReadInt(this->file); // offset to central directory 110 | 111 | this->entry = (zip_entry_t*)calloc(count, sizeof(zip_entry_t)); 112 | this->entry_count = count; 113 | 114 | fseek(this->file, offset, SEEK_SET); 115 | 116 | for (i = 0; i < count; i++) 117 | { 118 | zip_entry_t* entry = this->entry + i; 119 | 120 | sig = _ReadInt(this->file); 121 | if (sig != ZIP_CENTRAL_DIRECTORY_SIG) { 122 | Error("wrong zip central directory signature (0x%x)", sig); 123 | } 124 | 125 | _ReadShort(this->file); // version made by 126 | _ReadShort(this->file); // version to extract 127 | _ReadShort(this->file); // general 128 | _ReadShort(this->file); // method 129 | _ReadShort(this->file); // last mod file time 130 | _ReadShort(this->file); // last mod file date 131 | _ReadInt(this->file); // crc-32 132 | entry->csize = _ReadInt(this->file); // csize 133 | entry->usize = _ReadInt(this->file); // usize 134 | namesize = _ReadShort(this->file); // namesize 135 | metasize = _ReadShort(this->file); // metasize 136 | commentsize = _ReadShort(this->file); // commentsize 137 | _ReadShort(this->file); // disk number start 138 | _ReadShort(this->file); // int file atts 139 | _ReadInt(this->file); // ext file atts 140 | entry->offset = _ReadInt(this->file); // offset 141 | 142 | entry->name = (char*)malloc(namesize + 1); 143 | fread(entry->name, sizeof(char), namesize, this->file); 144 | entry->name[namesize] = 0; 145 | 146 | fseek(this->file, metasize, SEEK_CUR); 147 | fseek(this->file, commentsize, SEEK_CUR); 148 | } 149 | } 150 | 151 | void ZipFile::openZipFile(const char* name) { 152 | 153 | uint8_t buf[512]; 154 | int filesize, back, maxback; 155 | int i, n; 156 | 157 | this->file = fopen(name, "rb"); 158 | if (this->file == NULL) { 159 | Error("openZipFile: cannot open file %s\n", name); 160 | } 161 | 162 | fseek(this->file, 0, SEEK_END); 163 | filesize = (int)ftell(this->file); 164 | fseek(this->file, 0, SEEK_SET); 165 | 166 | maxback = MIN(filesize, 0xFFFF + sizeof(buf)); 167 | back = MIN(maxback, sizeof(buf)); 168 | 169 | while (back < maxback) 170 | { 171 | fseek(this->file, filesize - back, SEEK_SET); 172 | n = sizeof(buf); 173 | fread(buf, sizeof(uint8_t), n, this->file); 174 | for (i = n - 4; i > 0; i--) 175 | { 176 | if (!memcmp(buf + i, "PK\5\6", 4)) { 177 | findAndReadZipDir(filesize - back + i); 178 | return; 179 | } 180 | } 181 | back += sizeof(buf) - 4; 182 | } 183 | 184 | Error("cannot find end of central directory\n"); 185 | } 186 | 187 | void ZipFile::closeZipFile() { 188 | if (this) { 189 | if (this->entry) { 190 | free(this->entry); 191 | this->entry = nullptr; 192 | } 193 | 194 | if (this->file) { 195 | fclose(this->file); 196 | this->file = nullptr; 197 | } 198 | } 199 | } 200 | 201 | uint8_t* ZipFile::readZipFileEntry(const char* name, int* sizep) { 202 | zip_entry_t* entry = nullptr; 203 | int i, sig, general, method, namelength, extralength; 204 | uint8_t* cdata; 205 | int code; 206 | 207 | for (i = 0; i < this->entry_count; i++) 208 | { 209 | zip_entry_t* entryTmp = this->entry + i; 210 | if (!SDL_strcasecmp(name, entryTmp->name)) { 211 | entry = this->entry + i; 212 | break; 213 | } 214 | } 215 | 216 | if (entry == NULL) { 217 | Error("did not find the %s file in the zip file", name); 218 | } 219 | 220 | fseek(this->file, entry->offset, SEEK_SET); 221 | 222 | sig = _ReadInt(this->file); 223 | if (sig != ZIP_LOCAL_FILE_SIG) { 224 | Error("wrong zip local file signature (0x%x)", sig); 225 | } 226 | 227 | _ReadShort(this->file); // version 228 | general = _ReadShort(this->file); // general 229 | if (general & ZIP_ENCRYPTED_FLAG) { 230 | Error("zipfile content is encrypted"); 231 | } 232 | 233 | method = _ReadShort(this->file); // method 234 | _ReadShort(this->file); // file time 235 | _ReadShort(this->file); // file date 236 | _ReadInt(this->file); // crc-32 237 | _ReadInt(this->file); // csize 238 | _ReadInt(this->file); // usize 239 | namelength = _ReadShort(this->file); // namelength 240 | extralength = _ReadShort(this->file); // extralength 241 | 242 | fseek(this->file, namelength + extralength, SEEK_CUR); 243 | 244 | cdata = (uint8_t*) malloc(entry->csize); 245 | fread(cdata, sizeof(uint8_t), entry->csize, this->file); 246 | 247 | if (method == 0) 248 | { 249 | *sizep = entry->usize; 250 | return cdata; 251 | } 252 | else if (method == 8) 253 | { 254 | uint8_t* udata = (uint8_t*) malloc(entry->usize); 255 | z_stream stream; 256 | 257 | memset(&stream, 0, sizeof stream); 258 | stream.zalloc = zip_alloc; 259 | stream.zfree = zip_free; 260 | stream.opaque = Z_NULL; 261 | stream.next_in = cdata; 262 | stream.avail_in = entry->csize; 263 | stream.next_out = udata; 264 | stream.avail_out = entry->usize; 265 | 266 | code = inflateInit2(&stream, -15); 267 | if (code != Z_OK) { 268 | Error("zlib inflateInit2 error: %s", stream.msg); 269 | } 270 | 271 | code = inflate(&stream, Z_FINISH); 272 | if (code != Z_STREAM_END) { 273 | inflateEnd(&stream); 274 | Error("zlib inflate error: %s", stream.msg); 275 | } 276 | 277 | code = inflateEnd(&stream); 278 | if (code != Z_OK) { 279 | inflateEnd(&stream); 280 | Error("zlib inflateEnd error: %s", stream.msg); 281 | } 282 | 283 | free(cdata); 284 | 285 | *sizep = entry->usize; 286 | return udata; 287 | } 288 | else { 289 | Error("unknown zip method: %d", method); 290 | } 291 | 292 | return nullptr; 293 | } -------------------------------------------------------------------------------- /cmake/Modules/Nueva carpeta/FindSDL2_mixer.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | # Copyright 2019 Amine Ben Hassouna 5 | # Copyright 2000-2019 Kitware, Inc. and Contributors 6 | # All rights reserved. 7 | 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | 19 | # * Neither the name of Kitware, Inc. nor the names of Contributors 20 | # may be used to endorse or promote products derived from this 21 | # software without specific prior written permission. 22 | 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #[=======================================================================[.rst: 36 | FindSDL2_mixer 37 | -------------- 38 | 39 | Locate SDL2_mixer library 40 | 41 | This module defines the following 'IMPORTED' target: 42 | 43 | :: 44 | 45 | SDL2::Mixer 46 | The SDL2_mixer library, if found. 47 | Have SDL2::Core as a link dependency. 48 | 49 | 50 | 51 | This module will set the following variables in your project: 52 | 53 | :: 54 | 55 | SDL2_MIXER_LIBRARIES, the name of the library to link against 56 | SDL2_MIXER_INCLUDE_DIRS, where to find the headers 57 | SDL2_MIXER_FOUND, if false, do not try to link against 58 | SDL2_MIXER_VERSION_STRING - human-readable string containing the 59 | version of SDL2_mixer 60 | 61 | This module responds to the following cache variables: 62 | 63 | :: 64 | 65 | SDL2_MIXER_PATH 66 | Set a custom SDL2_mixer Library path (default: empty) 67 | 68 | SDL2_MIXER_NO_DEFAULT_PATH 69 | Disable search SDL2_mixer Library in default path. 70 | If SDL2_MIXER_PATH (default: ON) 71 | Else (default: OFF) 72 | 73 | SDL2_MIXER_INCLUDE_DIR 74 | SDL2_mixer headers path. 75 | 76 | SDL2_MIXER_LIBRARY 77 | SDL2_mixer Library (.dll, .so, .a, etc) path. 78 | 79 | 80 | Additional Note: If you see an empty SDL2_MIXER_LIBRARY in your project 81 | configuration, it means CMake did not find your SDL2_mixer library 82 | (SDL2_mixer.dll, libsdl2_mixer.so, etc). Set SDL2_MIXER_LIBRARY to point 83 | to your SDL2_mixer library, and configure again. This value is used to 84 | generate the final SDL2_MIXER_LIBRARIES variable and the SDL2::Mixer target, 85 | but when this value is unset, SDL2_MIXER_LIBRARIES and SDL2::Mixer does not 86 | get created. 87 | 88 | 89 | $SDL2MIXERDIR is an environment variable that would correspond to the 90 | ./configure --prefix=$SDL2MIXERDIR used in building SDL2_mixer. 91 | 92 | $SDL2DIR is an environment variable that would correspond to the 93 | ./configure --prefix=$SDL2DIR used in building SDL2. 94 | 95 | 96 | 97 | Created by Amine Ben Hassouna: 98 | Adapt FindSDL_mixer.cmake to SDL2_mixer (FindSDL2_mixer.cmake). 99 | Add cache variables for more flexibility: 100 | SDL2_MIXER_PATH, SDL2_MIXER_NO_DEFAULT_PATH (for details, see doc above). 101 | Add SDL2 as a required dependency. 102 | Modernize the FindSDL2_mixer.cmake module by creating a specific target: 103 | SDL2::Mixer (for details, see doc above). 104 | 105 | Original FindSDL_mixer.cmake module: 106 | Created by Eric Wing. This was influenced by the FindSDL.cmake 107 | module, but with modifications to recognize OS X frameworks and 108 | additional Unix paths (FreeBSD, etc). 109 | #]=======================================================================] 110 | 111 | # SDL2 Library required 112 | find_package(SDL2 QUIET) 113 | if(NOT SDL2_FOUND) 114 | set(SDL2_MIXER_SDL2_NOT_FOUND "Could NOT find SDL2 (SDL2 is required by SDL2_mixer).") 115 | if(SDL2_mixer_FIND_REQUIRED) 116 | message(FATAL_ERROR ${SDL2_MIXER_SDL2_NOT_FOUND}) 117 | else() 118 | if(NOT SDL2_mixer_FIND_QUIETLY) 119 | message(STATUS ${SDL2_MIXER_SDL2_NOT_FOUND}) 120 | endif() 121 | return() 122 | endif() 123 | unset(SDL2_MIXER_SDL2_NOT_FOUND) 124 | endif() 125 | 126 | 127 | # Define options for searching SDL2_mixer Library in a custom path 128 | 129 | set(SDL2_MIXER_PATH "" CACHE STRING "Custom SDL2_mixer Library path") 130 | 131 | set(_SDL2_MIXER_NO_DEFAULT_PATH OFF) 132 | if(SDL2_MIXER_PATH) 133 | set(_SDL2_MIXER_NO_DEFAULT_PATH ON) 134 | endif() 135 | 136 | set(SDL2_MIXER_NO_DEFAULT_PATH ${_SDL2_MIXER_NO_DEFAULT_PATH} 137 | CACHE BOOL "Disable search SDL2_mixer Library in default path") 138 | unset(_SDL2_MIXER_NO_DEFAULT_PATH) 139 | 140 | set(SDL2_MIXER_NO_DEFAULT_PATH_CMD) 141 | if(SDL2_MIXER_NO_DEFAULT_PATH) 142 | set(SDL2_MIXER_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) 143 | endif() 144 | 145 | # Search for the SDL2_mixer include directory 146 | find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h 147 | HINTS 148 | ENV SDL2MIXERDIR 149 | ENV SDL2DIR 150 | ${SDL2_MIXER_NO_DEFAULT_PATH_CMD} 151 | PATH_SUFFIXES SDL2 152 | # path suffixes to search inside ENV{SDL2DIR} 153 | # and ENV{SDL2MIXERDIR} 154 | include/SDL2 include 155 | PATHS ${SDL2_MIXER_PATH} 156 | DOC "Where the SDL2_mixer headers can be found" 157 | ) 158 | 159 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 160 | set(VC_LIB_PATH_SUFFIX lib/x64) 161 | else() 162 | set(VC_LIB_PATH_SUFFIX lib/x86) 163 | endif() 164 | 165 | # Search for the SDL2_mixer library 166 | find_library(SDL2_MIXER_LIBRARY 167 | NAMES SDL2_mixer 168 | HINTS 169 | ENV SDL2MIXERDIR 170 | ENV SDL2DIR 171 | ${SDL2_MIXER_NO_DEFAULT_PATH_CMD} 172 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 173 | PATHS ${SDL2_MIXER_PATH} 174 | DOC "Where the SDL2_mixer Library can be found" 175 | ) 176 | 177 | # Read SDL2_mixer version 178 | if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") 179 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") 180 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") 181 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") 182 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") 183 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") 184 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") 185 | set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) 186 | unset(SDL2_MIXER_VERSION_MAJOR_LINE) 187 | unset(SDL2_MIXER_VERSION_MINOR_LINE) 188 | unset(SDL2_MIXER_VERSION_PATCH_LINE) 189 | unset(SDL2_MIXER_VERSION_MAJOR) 190 | unset(SDL2_MIXER_VERSION_MINOR) 191 | unset(SDL2_MIXER_VERSION_PATCH) 192 | endif() 193 | 194 | set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) 195 | set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) 196 | 197 | include(FindPackageHandleStandardArgs) 198 | 199 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer 200 | REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS 201 | VERSION_VAR SDL2_MIXER_VERSION_STRING) 202 | 203 | 204 | mark_as_advanced(SDL2_MIXER_PATH 205 | SDL2_MIXER_NO_DEFAULT_PATH 206 | SDL2_MIXER_LIBRARY 207 | SDL2_MIXER_INCLUDE_DIR) 208 | 209 | 210 | if(SDL2_MIXER_FOUND) 211 | 212 | # SDL2::Mixer target 213 | if(SDL2_MIXER_LIBRARY AND NOT TARGET SDL2::Mixer) 214 | add_library(SDL2::Mixer UNKNOWN IMPORTED) 215 | set_target_properties(SDL2::Mixer PROPERTIES 216 | IMPORTED_LOCATION "${SDL2_MIXER_LIBRARY}" 217 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIR}" 218 | INTERFACE_LINK_LIBRARIES SDL2::Core) 219 | endif() 220 | endif() -------------------------------------------------------------------------------- /src/JavaStream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "JavaStream.h" 6 | #include "CAppContainer.h" 7 | #include "App.h" 8 | #include "ZipFile.h" 9 | 10 | // ------------------ 11 | // InputStream Class 12 | // ------------------ 13 | 14 | InputStream::InputStream() { 15 | //printf("InputStream::init\n"); 16 | this->data = nullptr; 17 | this->field_0x4 = 0; 18 | this->cursor = 0; 19 | this->field_0x0 = 0; 20 | this->file = nullptr; 21 | this->field_0x28 = 0; 22 | } 23 | 24 | InputStream::~InputStream() { 25 | if (this->file) { 26 | fclose(this->file); 27 | this->file = nullptr; 28 | } 29 | 30 | if (this->data) { 31 | free(this->data); 32 | this->data = nullptr; 33 | } 34 | } 35 | 36 | bool InputStream::loadResource(const char* fileName) 37 | { 38 | return loadFile(fileName, LT_RESOURCE); 39 | } 40 | 41 | bool InputStream::loadFile(const char* fileName, int loadType) { 42 | char namePath[2048]; 43 | this->cursor = 0; 44 | 45 | if (loadType == LT_RESOURCE) { 46 | strncpy(namePath, "Payload/Wolf...RPG.app/Packages/", sizeof(namePath)); 47 | strncat(namePath, fileName, sizeof(namePath)); 48 | //printf("namePath %s\n", namePath); 49 | 50 | this->data = CAppContainer::getInstance()->zipFile->readZipFileEntry(namePath, &this->fileSize); 51 | if (this->data) { 52 | return true; 53 | } 54 | } 55 | else if (loadType == LT_SOUND_RESOURCE) { // [GEC] 56 | strncpy(namePath, "Payload/Wolf...RPG.app/Packages/sounds/", sizeof(namePath)); 57 | strncat(namePath, fileName, sizeof(namePath)); 58 | //printf("namePath %s\n", namePath); 59 | 60 | this->data = CAppContainer::getInstance()->zipFile->readZipFileEntry(namePath, &this->fileSize); 61 | if (this->data) { 62 | return true; 63 | } 64 | } 65 | else if (loadType == LT_FILE) { 66 | strcpy(namePath, dir); 67 | strcat(namePath, "/"); 68 | strcat(namePath, fileName); 69 | 70 | this->file = fopen(namePath, "rb"); 71 | 72 | if (this->file != nullptr) { 73 | fseek(this->file, 0, SEEK_END); 74 | this->fileSize = ftell(this->file); 75 | fseek(this->file, 0, SEEK_SET); 76 | this->data = (uint8_t*)malloc(this->fileSize); 77 | fread(this->data, sizeof(uint8_t), this->fileSize, this->file); 78 | 79 | if (ferror(this->file)) { 80 | CAppContainer::getInstance()->app->Error( "Error Reading File!\n"); 81 | return false; 82 | } 83 | 84 | if (this->file) { 85 | fclose(this->file); 86 | this->file = nullptr; 87 | } 88 | 89 | if (this->data) { 90 | return true; 91 | } 92 | } 93 | else { 94 | //CAppContainer::getInstance()->app->Error("Error Openeing File: %s\n", namePath); 95 | } 96 | } 97 | else { 98 | CAppContainer::getInstance()->app->Error("File does not exist\n"); 99 | } 100 | 101 | return false; 102 | } 103 | 104 | void InputStream::close() { 105 | if (this->file) { 106 | fclose(this->file); 107 | this->file = nullptr; 108 | } 109 | } 110 | 111 | int InputStream::readInt() 112 | { 113 | int ch1 = this->data[this->cursor + 3]; 114 | int ch2 = this->data[this->cursor + 2]; 115 | int ch3 = this->data[this->cursor + 1]; 116 | int ch4 = this->data[this->cursor + 0]; 117 | this->cursor += sizeof(int32_t); 118 | return (int) ((ch1 << 24 & 0xFF000000) + (ch2 << 16 & 0xFF0000) + (ch3 << 8 & 0xFF00) + (ch4 << 0 & 0xFF)); 119 | } 120 | 121 | int InputStream::readShort() 122 | { 123 | int ch1 = this->data[this->cursor + 1]; 124 | int ch2 = this->data[this->cursor + 0]; 125 | this->cursor += sizeof(int16_t); 126 | return (short)((ch1 << 8 & 0xFF00) + (ch2 << 0 & 0xFF)); 127 | } 128 | 129 | bool InputStream::readBoolean() 130 | { 131 | uint8_t ch1 = this->data[this->cursor + 0]; 132 | this->cursor += sizeof(int8_t); 133 | return (bool)((ch1 != 0) ? true : false); 134 | } 135 | 136 | uint8_t InputStream::readByte() 137 | { 138 | uint8_t ch1 = this->data[this->cursor + 0]; 139 | this->cursor += sizeof(int8_t); 140 | return ch1; 141 | } 142 | 143 | uint8_t InputStream::readUnsignedByte() 144 | { 145 | uint8_t ch1 = this->data[this->cursor + 0]; 146 | this->cursor += sizeof(int8_t); 147 | return ch1; 148 | } 149 | 150 | int InputStream::readSignedByte() 151 | { 152 | uint8_t ch1 = this->data[this->cursor + 0]; 153 | this->cursor += sizeof(int8_t); 154 | return (int)((char)ch1); 155 | } 156 | 157 | void InputStream::read(uint8_t* dest, int off, int size) { 158 | for (int i = 0; i < size; i++) { 159 | if (this->cursor >= this->fileSize) { 160 | break; 161 | } 162 | dest[off + i] = this->data[this->cursor + 0]; 163 | this->cursor++; 164 | } 165 | } 166 | 167 | 168 | // ------------------- 169 | // OutputStream Class 170 | // ------------------- 171 | 172 | OutputStream::OutputStream() { 173 | //printf("OutputStream::init\n"); 174 | this->buffer = nullptr; 175 | this->writeBuff = nullptr; 176 | this->file = nullptr; 177 | this->App = CAppContainer::getInstance()->app;; 178 | this->field_0x24_ = -1; 179 | this->written = 0; 180 | this->flushCount = 0; 181 | this->isOpen = false; 182 | this->noWrite = false; 183 | } 184 | 185 | OutputStream::~OutputStream() { 186 | this->close(); 187 | 188 | if (this->writeBuff) { 189 | free(this->writeBuff); 190 | this->writeBuff = nullptr; 191 | } 192 | 193 | if (this->buffer != nullptr) { 194 | free(this->buffer); 195 | this->buffer = nullptr; 196 | } 197 | } 198 | 199 | int OutputStream::openFile(const char* fileName, int openMode) { 200 | char namePath[2060]; 201 | 202 | struct stat sb; 203 | if (stat(dir, &sb)) { 204 | char command[128]; 205 | strcpy(command, "mkdir "); 206 | strcat(command, "\""); 207 | strcat(command, dir); 208 | strcat(command, "\""); 209 | //printf("command %s\n", command); 210 | system(command); 211 | } 212 | 213 | strcpy(namePath, dir); 214 | strcat(namePath, "/"); 215 | strcat(namePath, fileName); 216 | 217 | //printf("output file: %s\n", namePath); 218 | this->buffer = (uint8_t*)malloc(512); 219 | memset(this->buffer, 0, 512); 220 | 221 | if (this->file != nullptr) { 222 | this->isOpen = true; 223 | return 0; 224 | } 225 | 226 | this->isOpen = false; 227 | if (this->noWrite != false) { 228 | return 1; 229 | } 230 | 231 | switch (openMode) 232 | { 233 | case 1: 234 | this->file = fopen(namePath, "wb"); 235 | break; 236 | case 2: 237 | this->file = fopen(namePath, "rb"); 238 | break; 239 | case 3: 240 | this->file = fopen(namePath, "w+b"); 241 | break; 242 | default: 243 | return 0; 244 | } 245 | 246 | if (this->file != nullptr) { 247 | fseek(this->file, 0, SEEK_END); 248 | this->fileSize = ftell(this->file); 249 | fseek(this->file, 0, SEEK_SET); 250 | this->writeBuff = (uint8_t*)malloc(this->fileSize); 251 | return 1; 252 | } 253 | 254 | return 0; 255 | } 256 | 257 | void OutputStream::close() 258 | { 259 | this->flush(); 260 | if (this->file != nullptr) { 261 | fclose(this->file); 262 | this->file = nullptr; 263 | } 264 | 265 | if (this->buffer != nullptr) { 266 | free(this->buffer); 267 | this->buffer = nullptr; 268 | } 269 | } 270 | 271 | int OutputStream::flush() 272 | { 273 | if (this->written == 0) { 274 | return 1; 275 | } 276 | 277 | this->flushCount += this->written; 278 | 279 | if (!this->noWrite) { 280 | if (fwrite(this->buffer, sizeof(uint8_t), this->written, this->file) <= 0) { 281 | return 0; 282 | } 283 | } 284 | 285 | this->written = 0; 286 | return 1; 287 | } 288 | 289 | void OutputStream::writeInt(int i) 290 | { 291 | if ((256 - this->written) < sizeof(uint32_t)) { 292 | if (this->flush() == 0) { 293 | return; 294 | } 295 | } 296 | 297 | this->buffer[this->written++] = (uint8_t)(i & 0xFF); 298 | this->buffer[this->written++] = (uint8_t)(i >> 8 & 0xFF); 299 | this->buffer[this->written++] = (uint8_t)(i >> 16 & 0xFF); 300 | this->buffer[this->written++] = (uint8_t)(i >> 24 & 0xFF); 301 | } 302 | 303 | void OutputStream::writeShort(int16_t i) 304 | { 305 | if ((256U - this->written) < sizeof(uint16_t)) { 306 | if (this->flush() == 0) { 307 | return; 308 | } 309 | } 310 | 311 | this->buffer[this->written++] = (uint8_t)(i & 0xFF); 312 | this->buffer[this->written++] = (uint8_t)(i >> 8 & 0xFF); 313 | } 314 | 315 | void OutputStream::writeByte(uint8_t i) 316 | { 317 | if ((256U - this->written) < sizeof(uint8_t)) { 318 | if (this->flush() == 0) { 319 | return; 320 | } 321 | } 322 | 323 | this->buffer[this->written++] = (uint8_t)(i & 0xFF); 324 | } 325 | 326 | void OutputStream::writeBoolean(bool b) 327 | { 328 | if ((256U - this->written) < sizeof(uint8_t)) { 329 | if (this->flush() == 0) { 330 | return; 331 | } 332 | } 333 | 334 | this->buffer[this->written++] = (uint8_t)(b); 335 | } 336 | 337 | void OutputStream::write(uint8_t* buff, int off, int size) 338 | { 339 | int _written = this->written; 340 | if ((uint32_t)(_written + size) >= 256) { 341 | int count = 256 - _written; 342 | memcpy(&this->buffer[_written], &buff[off], count); 343 | this->written += count; 344 | size -= count; 345 | off += count; 346 | if (this->flush() == 0) { 347 | return; 348 | } 349 | } 350 | 351 | memcpy(&this->buffer[_written], &buff[off], size); 352 | this->written += size; 353 | } 354 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/sha3.cpp: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // sha3.cpp 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #include "sha3.h" 8 | 9 | // big endian architectures need #define __BYTE_ORDER __BIG_ENDIAN 10 | #ifndef _MSC_VER 11 | #include 12 | #endif 13 | 14 | #include 15 | 16 | 17 | /// same as reset() 18 | SHA3::SHA3(Bits bits) 19 | : m_blockSize(200 - 2 * (bits / 8)), 20 | m_bits(bits) 21 | { 22 | reset(); 23 | } 24 | 25 | 26 | /// restart 27 | void SHA3::reset() 28 | { 29 | for (size_t i = 0; i < StateSize; i++) 30 | m_hash[i] = 0; 31 | 32 | m_numBytes = 0; 33 | m_bufferSize = 0; 34 | } 35 | 36 | 37 | /// constants and local helper functions 38 | namespace 39 | { 40 | const unsigned int Rounds = 24; 41 | const uint64_t XorMasks[Rounds] = 42 | { 43 | 0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL, 44 | 0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL, 45 | 0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL, 46 | 0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL, 47 | 0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 48 | 0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL, 49 | 0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL, 50 | 0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL 51 | }; 52 | 53 | /// rotate left and wrap around to the right 54 | inline uint64_t rotateLeft(uint64_t x, uint8_t numBits) 55 | { 56 | return (x << numBits) | (x >> (64 - numBits)); 57 | } 58 | 59 | /// convert litte vs big endian 60 | inline uint64_t swap(uint64_t x) 61 | { 62 | #if defined(__GNUC__) || defined(__clang__) 63 | return __builtin_bswap64(x); 64 | #endif 65 | #ifdef _MSC_VER 66 | return _byteswap_uint64(x); 67 | #endif 68 | 69 | return (x >> 56) | 70 | ((x >> 40) & 0x000000000000FF00ULL) | 71 | ((x >> 24) & 0x0000000000FF0000ULL) | 72 | ((x >> 8) & 0x00000000FF000000ULL) | 73 | ((x << 8) & 0x000000FF00000000ULL) | 74 | ((x << 24) & 0x0000FF0000000000ULL) | 75 | ((x << 40) & 0x00FF000000000000ULL) | 76 | (x << 56); 77 | } 78 | 79 | 80 | /// return x % 5 for 0 <= x <= 9 81 | unsigned int mod5(unsigned int x) 82 | { 83 | if (x < 5) 84 | return x; 85 | 86 | return x - 5; 87 | } 88 | } 89 | 90 | 91 | /// process a full block 92 | void SHA3::processBlock(const void* data) 93 | { 94 | #if defined(__BYTE_ORDER) && (__BYTE_ORDER != 0) && (__BYTE_ORDER == __BIG_ENDIAN) 95 | #define LITTLEENDIAN(x) swap(x) 96 | #else 97 | #define LITTLEENDIAN(x) (x) 98 | #endif 99 | 100 | const uint64_t* data64 = (const uint64_t*) data; 101 | // mix data into state 102 | for (unsigned int i = 0; i < m_blockSize / 8; i++) 103 | m_hash[i] ^= LITTLEENDIAN(data64[i]); 104 | 105 | // re-compute state 106 | for (unsigned int round = 0; round < Rounds; round++) 107 | { 108 | // Theta 109 | uint64_t coefficients[5]; 110 | for (unsigned int i = 0; i < 5; i++) 111 | coefficients[i] = m_hash[i] ^ m_hash[i + 5] ^ m_hash[i + 10] ^ m_hash[i + 15] ^ m_hash[i + 20]; 112 | 113 | for (unsigned int i = 0; i < 5; i++) 114 | { 115 | uint64_t one = coefficients[mod5(i + 4)] ^ rotateLeft(coefficients[mod5(i + 1)], 1); 116 | m_hash[i ] ^= one; 117 | m_hash[i + 5] ^= one; 118 | m_hash[i + 10] ^= one; 119 | m_hash[i + 15] ^= one; 120 | m_hash[i + 20] ^= one; 121 | } 122 | 123 | // temporary 124 | uint64_t one; 125 | 126 | // Rho Pi 127 | uint64_t last = m_hash[1]; 128 | one = m_hash[10]; m_hash[10] = rotateLeft(last, 1); last = one; 129 | one = m_hash[ 7]; m_hash[ 7] = rotateLeft(last, 3); last = one; 130 | one = m_hash[11]; m_hash[11] = rotateLeft(last, 6); last = one; 131 | one = m_hash[17]; m_hash[17] = rotateLeft(last, 10); last = one; 132 | one = m_hash[18]; m_hash[18] = rotateLeft(last, 15); last = one; 133 | one = m_hash[ 3]; m_hash[ 3] = rotateLeft(last, 21); last = one; 134 | one = m_hash[ 5]; m_hash[ 5] = rotateLeft(last, 28); last = one; 135 | one = m_hash[16]; m_hash[16] = rotateLeft(last, 36); last = one; 136 | one = m_hash[ 8]; m_hash[ 8] = rotateLeft(last, 45); last = one; 137 | one = m_hash[21]; m_hash[21] = rotateLeft(last, 55); last = one; 138 | one = m_hash[24]; m_hash[24] = rotateLeft(last, 2); last = one; 139 | one = m_hash[ 4]; m_hash[ 4] = rotateLeft(last, 14); last = one; 140 | one = m_hash[15]; m_hash[15] = rotateLeft(last, 27); last = one; 141 | one = m_hash[23]; m_hash[23] = rotateLeft(last, 41); last = one; 142 | one = m_hash[19]; m_hash[19] = rotateLeft(last, 56); last = one; 143 | one = m_hash[13]; m_hash[13] = rotateLeft(last, 8); last = one; 144 | one = m_hash[12]; m_hash[12] = rotateLeft(last, 25); last = one; 145 | one = m_hash[ 2]; m_hash[ 2] = rotateLeft(last, 43); last = one; 146 | one = m_hash[20]; m_hash[20] = rotateLeft(last, 62); last = one; 147 | one = m_hash[14]; m_hash[14] = rotateLeft(last, 18); last = one; 148 | one = m_hash[22]; m_hash[22] = rotateLeft(last, 39); last = one; 149 | one = m_hash[ 9]; m_hash[ 9] = rotateLeft(last, 61); last = one; 150 | one = m_hash[ 6]; m_hash[ 6] = rotateLeft(last, 20); last = one; 151 | m_hash[ 1] = rotateLeft(last, 44); 152 | 153 | // Chi 154 | for (unsigned int j = 0; j < StateSize; j += 5) 155 | { 156 | // temporaries 157 | uint64_t one = m_hash[j]; 158 | uint64_t two = m_hash[j + 1]; 159 | 160 | m_hash[j] ^= m_hash[j + 2] & ~two; 161 | m_hash[j + 1] ^= m_hash[j + 3] & ~m_hash[j + 2]; 162 | m_hash[j + 2] ^= m_hash[j + 4] & ~m_hash[j + 3]; 163 | m_hash[j + 3] ^= one & ~m_hash[j + 4]; 164 | m_hash[j + 4] ^= two & ~one; 165 | } 166 | 167 | // Iota 168 | m_hash[0] ^= XorMasks[round]; 169 | } 170 | } 171 | 172 | 173 | /// add arbitrary number of bytes 174 | void SHA3::add(const void* data, size_t numBytes) 175 | { 176 | const uint8_t* current = (const uint8_t*) data; 177 | 178 | // copy data to buffer 179 | if (m_bufferSize > 0) 180 | { 181 | while (numBytes > 0 && m_bufferSize < m_blockSize) 182 | { 183 | m_buffer[m_bufferSize++] = *current++; 184 | numBytes--; 185 | } 186 | } 187 | 188 | // full buffer 189 | if (m_bufferSize == m_blockSize) 190 | { 191 | processBlock((void*)m_buffer); 192 | m_numBytes += m_blockSize; 193 | m_bufferSize = 0; 194 | } 195 | 196 | // no more data ? 197 | if (numBytes == 0) 198 | return; 199 | 200 | // process full blocks 201 | while (numBytes >= m_blockSize) 202 | { 203 | processBlock(current); 204 | current += m_blockSize; 205 | m_numBytes += m_blockSize; 206 | numBytes -= m_blockSize; 207 | } 208 | 209 | // keep remaining bytes in buffer 210 | while (numBytes > 0) 211 | { 212 | m_buffer[m_bufferSize++] = *current++; 213 | numBytes--; 214 | } 215 | } 216 | 217 | 218 | /// process everything left in the internal buffer 219 | void SHA3::processBuffer() 220 | { 221 | // add padding 222 | size_t offset = m_bufferSize; 223 | // add a "1" byte 224 | m_buffer[offset++] = 0x06; 225 | // fill with zeros 226 | while (offset < m_blockSize) 227 | m_buffer[offset++] = 0; 228 | 229 | // and add a single set bit 230 | m_buffer[offset - 1] |= 0x80; 231 | 232 | processBlock(m_buffer); 233 | } 234 | 235 | 236 | /// return latest hash as 16 hex characters 237 | std::string SHA3::getHash() 238 | { 239 | // save hash state 240 | uint64_t oldHash[StateSize]; 241 | for (unsigned int i = 0; i < StateSize; i++) 242 | oldHash[i] = m_hash[i]; 243 | 244 | // process remaining bytes 245 | processBuffer(); 246 | 247 | // convert hash to string 248 | static const char dec2hex[16 + 1] = "0123456789abcdef"; 249 | 250 | // number of significant elements in hash (uint64_t) 251 | unsigned int hashLength = m_bits / 64; 252 | 253 | std::string result; 254 | result.reserve(m_bits / 4); 255 | for (unsigned int i = 0; i < hashLength; i++) 256 | for (unsigned int j = 0; j < 8; j++) // 64 bits => 8 bytes 257 | { 258 | // convert a byte to hex 259 | unsigned char oneByte = (unsigned char) (m_hash[i] >> (8 * j)); 260 | result += dec2hex[oneByte >> 4]; 261 | result += dec2hex[oneByte & 15]; 262 | } 263 | 264 | // SHA3-224's last entry in m_hash provides only 32 bits instead of 64 bits 265 | unsigned int remainder = m_bits - hashLength * 64; 266 | unsigned int processed = 0; 267 | while (processed < remainder) 268 | { 269 | // convert a byte to hex 270 | unsigned char oneByte = (unsigned char) (m_hash[hashLength] >> processed); 271 | result += dec2hex[oneByte >> 4]; 272 | result += dec2hex[oneByte & 15]; 273 | 274 | processed += 8; 275 | } 276 | 277 | // restore state 278 | for (unsigned int i = 0; i < StateSize; i++) 279 | m_hash[i] = oldHash[i]; 280 | 281 | return result; 282 | } 283 | 284 | 285 | /// compute SHA3 of a memory block 286 | std::string SHA3::operator()(const void* data, size_t numBytes) 287 | { 288 | reset(); 289 | add(data, numBytes); 290 | return getHash(); 291 | } 292 | 293 | 294 | /// compute SHA3 of a string, excluding final zero 295 | std::string SHA3::operator()(const std::string& text) 296 | { 297 | reset(); 298 | add(text.c_str(), text.size()); 299 | return getHash(); 300 | } 301 | -------------------------------------------------------------------------------- /third_party_libs/hash-library/hash-library/keccak.cpp: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // keccak.cpp 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #include "keccak.h" 8 | 9 | // big endian architectures need #define __BYTE_ORDER __BIG_ENDIAN 10 | #ifndef _MSC_VER 11 | #include 12 | #endif 13 | 14 | 15 | /// same as reset() 16 | Keccak::Keccak(Bits bits) 17 | : m_blockSize(200 - 2 * (bits / 8)), 18 | m_bits(bits) 19 | { 20 | reset(); 21 | } 22 | 23 | 24 | /// restart 25 | void Keccak::reset() 26 | { 27 | for (size_t i = 0; i < StateSize; i++) 28 | m_hash[i] = 0; 29 | 30 | m_numBytes = 0; 31 | m_bufferSize = 0; 32 | } 33 | 34 | 35 | /// constants and local helper functions 36 | namespace 37 | { 38 | const unsigned int KeccakRounds = 24; 39 | const uint64_t XorMasks[KeccakRounds] = 40 | { 41 | 0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL, 42 | 0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL, 43 | 0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL, 44 | 0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL, 45 | 0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 46 | 0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL, 47 | 0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL, 48 | 0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL 49 | }; 50 | 51 | /// rotate left and wrap around to the right 52 | inline uint64_t rotateLeft(uint64_t x, uint8_t numBits) 53 | { 54 | return (x << numBits) | (x >> (64 - numBits)); 55 | } 56 | 57 | /// convert litte vs big endian 58 | inline uint64_t swap(uint64_t x) 59 | { 60 | #if defined(__GNUC__) || defined(__clang__) 61 | return __builtin_bswap64(x); 62 | #endif 63 | #ifdef _MSC_VER 64 | return _byteswap_uint64(x); 65 | #endif 66 | 67 | return (x >> 56) | 68 | ((x >> 40) & 0x000000000000FF00ULL) | 69 | ((x >> 24) & 0x0000000000FF0000ULL) | 70 | ((x >> 8) & 0x00000000FF000000ULL) | 71 | ((x << 8) & 0x000000FF00000000ULL) | 72 | ((x << 24) & 0x0000FF0000000000ULL) | 73 | ((x << 40) & 0x00FF000000000000ULL) | 74 | (x << 56); 75 | } 76 | 77 | 78 | /// return x % 5 for 0 <= x <= 9 79 | unsigned int mod5(unsigned int x) 80 | { 81 | if (x < 5) 82 | return x; 83 | 84 | return x - 5; 85 | } 86 | } 87 | 88 | 89 | /// process a full block 90 | void Keccak::processBlock(const void* data) 91 | { 92 | #if defined(__BYTE_ORDER) && (__BYTE_ORDER != 0) && (__BYTE_ORDER == __BIG_ENDIAN) 93 | #define LITTLEENDIAN(x) swap(x) 94 | #else 95 | #define LITTLEENDIAN(x) (x) 96 | #endif 97 | 98 | const uint64_t* data64 = (const uint64_t*) data; 99 | // mix data into state 100 | for (unsigned int i = 0; i < m_blockSize / 8; i++) 101 | m_hash[i] ^= LITTLEENDIAN(data64[i]); 102 | 103 | // re-compute state 104 | for (unsigned int round = 0; round < KeccakRounds; round++) 105 | { 106 | // Theta 107 | uint64_t coefficients[5]; 108 | for (unsigned int i = 0; i < 5; i++) 109 | coefficients[i] = m_hash[i] ^ m_hash[i + 5] ^ m_hash[i + 10] ^ m_hash[i + 15] ^ m_hash[i + 20]; 110 | 111 | for (unsigned int i = 0; i < 5; i++) 112 | { 113 | uint64_t one = coefficients[mod5(i + 4)] ^ rotateLeft(coefficients[mod5(i + 1)], 1); 114 | m_hash[i ] ^= one; 115 | m_hash[i + 5] ^= one; 116 | m_hash[i + 10] ^= one; 117 | m_hash[i + 15] ^= one; 118 | m_hash[i + 20] ^= one; 119 | } 120 | 121 | // temporary 122 | uint64_t one; 123 | 124 | // Rho Pi 125 | uint64_t last = m_hash[1]; 126 | one = m_hash[10]; m_hash[10] = rotateLeft(last, 1); last = one; 127 | one = m_hash[ 7]; m_hash[ 7] = rotateLeft(last, 3); last = one; 128 | one = m_hash[11]; m_hash[11] = rotateLeft(last, 6); last = one; 129 | one = m_hash[17]; m_hash[17] = rotateLeft(last, 10); last = one; 130 | one = m_hash[18]; m_hash[18] = rotateLeft(last, 15); last = one; 131 | one = m_hash[ 3]; m_hash[ 3] = rotateLeft(last, 21); last = one; 132 | one = m_hash[ 5]; m_hash[ 5] = rotateLeft(last, 28); last = one; 133 | one = m_hash[16]; m_hash[16] = rotateLeft(last, 36); last = one; 134 | one = m_hash[ 8]; m_hash[ 8] = rotateLeft(last, 45); last = one; 135 | one = m_hash[21]; m_hash[21] = rotateLeft(last, 55); last = one; 136 | one = m_hash[24]; m_hash[24] = rotateLeft(last, 2); last = one; 137 | one = m_hash[ 4]; m_hash[ 4] = rotateLeft(last, 14); last = one; 138 | one = m_hash[15]; m_hash[15] = rotateLeft(last, 27); last = one; 139 | one = m_hash[23]; m_hash[23] = rotateLeft(last, 41); last = one; 140 | one = m_hash[19]; m_hash[19] = rotateLeft(last, 56); last = one; 141 | one = m_hash[13]; m_hash[13] = rotateLeft(last, 8); last = one; 142 | one = m_hash[12]; m_hash[12] = rotateLeft(last, 25); last = one; 143 | one = m_hash[ 2]; m_hash[ 2] = rotateLeft(last, 43); last = one; 144 | one = m_hash[20]; m_hash[20] = rotateLeft(last, 62); last = one; 145 | one = m_hash[14]; m_hash[14] = rotateLeft(last, 18); last = one; 146 | one = m_hash[22]; m_hash[22] = rotateLeft(last, 39); last = one; 147 | one = m_hash[ 9]; m_hash[ 9] = rotateLeft(last, 61); last = one; 148 | one = m_hash[ 6]; m_hash[ 6] = rotateLeft(last, 20); last = one; 149 | m_hash[ 1] = rotateLeft(last, 44); 150 | 151 | // Chi 152 | for (unsigned int j = 0; j < StateSize; j += 5) 153 | { 154 | // temporaries 155 | uint64_t one = m_hash[j]; 156 | uint64_t two = m_hash[j + 1]; 157 | 158 | m_hash[j] ^= m_hash[j + 2] & ~two; 159 | m_hash[j + 1] ^= m_hash[j + 3] & ~m_hash[j + 2]; 160 | m_hash[j + 2] ^= m_hash[j + 4] & ~m_hash[j + 3]; 161 | m_hash[j + 3] ^= one & ~m_hash[j + 4]; 162 | m_hash[j + 4] ^= two & ~one; 163 | } 164 | 165 | // Iota 166 | m_hash[0] ^= XorMasks[round]; 167 | } 168 | } 169 | 170 | 171 | /// add arbitrary number of bytes 172 | void Keccak::add(const void* data, size_t numBytes) 173 | { 174 | const uint8_t* current = (const uint8_t*) data; 175 | 176 | if (m_bufferSize > 0) 177 | { 178 | while (numBytes > 0 && m_bufferSize < m_blockSize) 179 | { 180 | m_buffer[m_bufferSize++] = *current++; 181 | numBytes--; 182 | } 183 | } 184 | 185 | // full buffer 186 | if (m_bufferSize == m_blockSize) 187 | { 188 | processBlock((void*)m_buffer); 189 | m_numBytes += m_blockSize; 190 | m_bufferSize = 0; 191 | } 192 | 193 | // no more data ? 194 | if (numBytes == 0) 195 | return; 196 | 197 | // process full blocks 198 | while (numBytes >= m_blockSize) 199 | { 200 | processBlock(current); 201 | current += m_blockSize; 202 | m_numBytes += m_blockSize; 203 | numBytes -= m_blockSize; 204 | } 205 | 206 | // keep remaining bytes in buffer 207 | while (numBytes > 0) 208 | { 209 | m_buffer[m_bufferSize++] = *current++; 210 | numBytes--; 211 | } 212 | } 213 | 214 | 215 | /// process everything left in the internal buffer 216 | void Keccak::processBuffer() 217 | { 218 | unsigned int blockSize = 200 - 2 * (m_bits / 8); 219 | 220 | // add padding 221 | size_t offset = m_bufferSize; 222 | // add a "1" byte 223 | m_buffer[offset++] = 1; 224 | // fill with zeros 225 | while (offset < blockSize) 226 | m_buffer[offset++] = 0; 227 | 228 | // and add a single set bit 229 | m_buffer[blockSize - 1] |= 0x80; 230 | 231 | processBlock(m_buffer); 232 | } 233 | 234 | 235 | /// return latest hash as 16 hex characters 236 | std::string Keccak::getHash() 237 | { 238 | // save hash state 239 | uint64_t oldHash[StateSize]; 240 | for (unsigned int i = 0; i < StateSize; i++) 241 | oldHash[i] = m_hash[i]; 242 | 243 | // process remaining bytes 244 | processBuffer(); 245 | 246 | // convert hash to string 247 | static const char dec2hex[16 + 1] = "0123456789abcdef"; 248 | 249 | // number of significant elements in hash (uint64_t) 250 | unsigned int hashLength = m_bits / 64; 251 | 252 | std::string result; 253 | for (unsigned int i = 0; i < hashLength; i++) 254 | for (unsigned int j = 0; j < 8; j++) // 64 bits => 8 bytes 255 | { 256 | // convert a byte to hex 257 | unsigned char oneByte = (unsigned char) (m_hash[i] >> (8 * j)); 258 | result += dec2hex[oneByte >> 4]; 259 | result += dec2hex[oneByte & 15]; 260 | } 261 | 262 | // Keccak224's last entry in m_hash provides only 32 bits instead of 64 bits 263 | unsigned int remainder = m_bits - hashLength * 64; 264 | unsigned int processed = 0; 265 | while (processed < remainder) 266 | { 267 | // convert a byte to hex 268 | unsigned char oneByte = (unsigned char) (m_hash[hashLength] >> processed); 269 | result += dec2hex[oneByte >> 4]; 270 | result += dec2hex[oneByte & 15]; 271 | 272 | processed += 8; 273 | } 274 | 275 | // restore state 276 | for (unsigned int i = 0; i < StateSize; i++) 277 | m_hash[i] = oldHash[i]; 278 | 279 | return result; 280 | } 281 | 282 | 283 | /// compute Keccak hash of a memory block 284 | std::string Keccak::operator()(const void* data, size_t numBytes) 285 | { 286 | reset(); 287 | add(data, numBytes); 288 | return getHash(); 289 | } 290 | 291 | 292 | /// compute Keccak hash of a string, excluding final zero 293 | std::string Keccak::operator()(const std::string& text) 294 | { 295 | reset(); 296 | add(text.c_str(), text.size()); 297 | return getHash(); 298 | } 299 | --------------------------------------------------------------------------------