├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake └── Modules │ ├── FindSDL2.cmake │ ├── FindSDL2_mixer.cmake │ └── Nueva carpeta │ ├── FindSDL2.cmake │ └── FindSDL2_mixer.cmake ├── src ├── App.cpp ├── App.h ├── Button.cpp ├── Button.h ├── CAppContainer.cpp ├── CAppContainer.h ├── CMakeLists.txt ├── Canvas.cpp ├── Canvas.h ├── Combat.cpp ├── Combat.h ├── CombatEntity.cpp ├── CombatEntity.h ├── ComicBook.cpp ├── ComicBook.h ├── Entity.cpp ├── Entity.h ├── EntityDef.cpp ├── EntityDef.h ├── EntityMonster.cpp ├── EntityMonster.h ├── Enums.h ├── GLES.cpp ├── GLES.h ├── Game.cpp ├── Game.h ├── GameSprite.h ├── Graphics.cpp ├── Graphics.h ├── HackingGame.cpp ├── HackingGame.h ├── Hud.cpp ├── Hud.h ├── IDIB.cpp ├── IDIB.h ├── Image.cpp ├── Image.h ├── Input.cpp ├── Input.h ├── JavaStream.cpp ├── JavaStream.h ├── LerpSprite.cpp ├── LerpSprite.h ├── Main.cpp ├── MayaCamera.cpp ├── MayaCamera.h ├── MenuItem.cpp ├── MenuItem.h ├── MenuStrings.h ├── MenuSystem.cpp ├── MenuSystem.h ├── Menus.h ├── ParticleSystem.cpp ├── ParticleSystem.h ├── Player.cpp ├── Player.h ├── Render.cpp ├── Render.h ├── Resource.cpp ├── Resource.h ├── SDLGL.cpp ├── SDLGL.h ├── ScriptThread.cpp ├── ScriptThread.h ├── SentryBotGame.cpp ├── SentryBotGame.h ├── Sound.cpp ├── Sound.h ├── Sounds.h ├── Span.cpp ├── Span.h ├── TGLEdge.cpp ├── TGLEdge.h ├── TGLVert.h ├── Text.cpp ├── Text.h ├── TinyGL.cpp ├── TinyGL.h ├── Utils.cpp ├── Utils.h ├── VendingMachine.cpp ├── VendingMachine.h ├── ZipFile.cpp ├── ZipFile.h ├── appicon.ico └── appicon.rc └── third_party_libs └── hash-library ├── CMakeLists.txt ├── Version.txt └── hash-library ├── LICENSE ├── crc32.cpp ├── crc32.h ├── digest.cpp ├── hash.h ├── hmac.h ├── keccak.cpp ├── keccak.h ├── md5.cpp ├── md5.h ├── readme.md ├── sha1.cpp ├── sha1.h ├── sha256.cpp ├── sha256.h ├── sha3.cpp └── sha3.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules") 3 | 4 | project(DoomIIRPG) 5 | 6 | if(MSVC) 7 | add_definitions("/D_CRT_SECURE_NO_WARNINGS") 8 | endif() 9 | if(UNIX) 10 | add_definitions("-Wno-write-strings") 11 | endif() 12 | 13 | find_package(SDL2 REQUIRED) 14 | find_package(ZLIB REQUIRED) 15 | find_package(OpenAL REQUIRED) 16 | find_package(OpenGL REQUIRED) 17 | 18 | # Global identifiers for each project/target 19 | set(HASH_LIBRARY_TGT_NAME Hash-Library) 20 | 21 | add_subdirectory("${PROJECT_SOURCE_DIR}/src") 22 | add_subdirectory("${PROJECT_SOURCE_DIR}/third_party_libs/hash-library") -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DoomIIRPG-RE 2 | 3 | ![image](https://github.com/Erick194/DoomIIRPG-RE/assets/41172072/6249f7bd-18e6-4838-b1ec-8654d18cc1b4)
4 | https://www.doomworld.com/forum/topic/135602 5 | 6 | ## Español 7 | Doom II RPG ingeniería inversa por [GEC]
8 | Creado por Erick Vásquez García. 9 | 10 | Versión actual 0.1 11 | 12 | Requiere CMake para crear el proyecto.
13 | Requisitos para el projecto: 14 | * SDL2 15 | * Zlib 16 | * OpenAL 17 | 18 | Configuración por defecto de las teclas. 19 | 20 | Move Forward: W, Up
21 | Move Backward: S, Down
22 | Move Left: A
23 | Move Right: D
24 | Turn Left: Left
25 | Turn Right: Right
26 | Atk/Talk/Use: Return
27 | Next Weapon: Z
28 | Prev Weapon: X
29 | Pass Turn: C
30 | Automap: Tab
31 | Menu Open/Back: Escape
32 | Menu Items/Info: I
33 | Menu Drinks: O
34 | Menu PDA: P
35 | Bot Dis/Ret: B
36 | 37 | Trucos originales del juego: 38 | 39 | Versión J2ME/BREW:
40 | Abres menu e ingresa los siguientes numeros.
41 | 3666 -> Abre el menú debug.
42 | 1666 -> Reinicia el nivel.
43 | 4332 -> Da al jugador todas las llaves, items y armas.
44 | 3366 -> Inicia el testeo de velocidad, "Benchmark".
45 | 46 | ## English 47 | Doom II RPG Reverse Engineering By [GEC]
48 | Created by Erick Vásquez García. 49 | 50 | Current version 0.1 51 | 52 | You need CMake to make the project.
53 | What you need for the project is: 54 | * SDL2 55 | * Zlib 56 | * OpenAL 57 | 58 | Default key configuration: 59 | 60 | Move Forward: W, Up
61 | Move Backward: S, Down
62 | Move Left: A
63 | Move Right: D
64 | Turn Left: Left
65 | Turn Right: Right
66 | Atk/Talk/Use: Return
67 | Next Weapon: Z
68 | Prev Weapon: X
69 | Pass Turn: C
70 | Automap: Tab
71 | Menu Open/Back: Escape
72 | Menu Items/Info: I
73 | Menu Drinks: O
74 | Menu PDA: P
75 | Bot Dis/Ret: B
76 | 77 | Original game cheat codes: 78 | 79 | J2ME/BREW Version:
80 | 3666 -> Opens debug menu.
81 | 1666 -> Restarts level.
82 | 4332 -> Gives all keys, items and weapons to the player.
83 | 3366 -> Starts speed test "Benchmark".
84 | 85 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/App.h: -------------------------------------------------------------------------------- 1 | #ifndef __APP_H__ 2 | #define __APP_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "IDIB.h" 8 | 9 | class SDLGL; 10 | class ZipFile; 11 | class IDIB; 12 | class Image; 13 | 14 | class Localization; 15 | class Resource; 16 | class Render; 17 | class TinyGL; 18 | class Canvas; 19 | class Game; 20 | class MenuSystem; 21 | class Player; 22 | class Sound; 23 | class Combat; 24 | class Hud; 25 | class EntityDefManager; 26 | class ParticleSystem; 27 | class HackingGame; 28 | class SentryBotGame; 29 | class VendingMachine; 30 | class ComicBook; 31 | class InputStream; 32 | 33 | class Applet 34 | { 35 | private: 36 | 37 | public: 38 | // Defines 39 | static constexpr int MAXMEMORY = 1000000000; 40 | static constexpr int IOS_WIDTH = 480; 41 | static constexpr int IOS_HEIGHT = 320; 42 | 43 | static constexpr int FONT_HEIGHT[4] = { 16, 16, 18, 25 }; 44 | static constexpr int FONT_WIDTH[4] = { 12, 12, 13, 22 }; 45 | static constexpr int CHAR_SPACING[4] = { 11, 11, 12, 22 }; 46 | 47 | //------------------ 48 | IDIB* backBuffer; 49 | int upTimeMs; 50 | int lastTime; 51 | int time; 52 | int gameTime; 53 | int startupMemory; 54 | int imageMemory; 55 | char* peakMemoryDesc; 56 | int peakMemoryUsage; 57 | int idError; 58 | bool initLoadImages; 59 | 60 | int sysAdvTime; 61 | int osTime[8]; 62 | int codeTime[8]; 63 | int field_0x26c; 64 | int field_0x270; 65 | int field_0x278; 66 | int field_0x27c; 67 | int fontType; 68 | int accelerationIndex; 69 | bool field_0x290; 70 | bool field_0x291; 71 | int field_0x7c; 72 | int field_0x80; 73 | 74 | // Iphone Only 75 | float accelerationX[32]; 76 | float accelerationY[32]; 77 | float accelerationZ[32]; 78 | 79 | float field_0x414; 80 | float field_0x418; 81 | float field_0x41c; 82 | float field_0x420; 83 | float field_0x424; 84 | float field_0x428; 85 | bool closeApplet; 86 | 87 | //------------------------- 88 | Localization* localization; 89 | Resource* resource; 90 | Render* render; 91 | TinyGL* tinyGL; 92 | Canvas* canvas; 93 | Game* game; 94 | MenuSystem* menuSystem; 95 | Player* player; 96 | Sound* sound; 97 | Combat* combat; 98 | Hud* hud; 99 | EntityDefManager* entityDefManager; 100 | ParticleSystem* particleSystem; 101 | HackingGame* hackingGame; 102 | SentryBotGame* sentryBotGame; 103 | VendingMachine* vendingMachine; 104 | ComicBook* comicBook; 105 | //------------------------- 106 | Image* testImg; 107 | int seed; 108 | 109 | // Constructor 110 | Applet(); 111 | // Destructor 112 | ~Applet(); 113 | 114 | bool startup(); 115 | void loadConfig(); 116 | 117 | Image* createImage(InputStream* inputStream, bool isTransparentMask); 118 | Image* loadImage(char* fileName, bool isTransparentMask); 119 | 120 | void beginImageLoading(); 121 | void endImageLoading(); 122 | 123 | void Error(const char* fmt, ...); 124 | void Error(int id); 125 | void loadTables(); 126 | 127 | void loadRuntimeImages(); 128 | void freeRuntimeImages(); 129 | void setFont(int fontType); 130 | void shutdown(); 131 | uint32_t nextInt(); 132 | uint32_t nextByte(); 133 | void setFontRenderMode(int fontRenderMode); 134 | 135 | void AccelerometerUpdated(float x, float y, float z); 136 | void StartAccelerometer(); 137 | void StopAccelerometer(); 138 | void CalcAccelerometerAngles(); 139 | }; 140 | 141 | 142 | #endif -------------------------------------------------------------------------------- /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/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/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/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE HEADER_FILES 2 | "*.hpp" 3 | "*.h") 4 | 5 | file(GLOB_RECURSE SOURCE_FILES 6 | "*.cpp" 7 | "*.c") 8 | 9 | file(GLOB_RECURSE RESOURCES_FILES 10 | "*.rc" 11 | "*.ico") 12 | 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 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Resources Files" FILES ${RESOURCES_FILES}) 16 | 17 | add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES} ${RESOURCES_FILES}) 18 | target_include_directories(${PROJECT_NAME} PUBLIC ${OPENAL_INCLUDE_DIR}) 19 | target_link_libraries(${PROJECT_NAME} SDL2::SDL2 ZLIB::ZLIB ${OPENAL_LIBRARY} ${OPENGL_LIBRARIES} ${HASH_LIBRARY_TGT_NAME}) -------------------------------------------------------------------------------- /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 | static constexpr int WEAPON_FIELD_STRMIN = 0; 27 | static constexpr int WEAPON_FIELD_STRMAX = 1; 28 | static constexpr int WEAPON_FIELD_RANGEMIN = 2; 29 | static constexpr int WEAPON_FIELD_RANGEMAX = 3; 30 | static constexpr int WEAPON_FIELD_AMMOTYPE = 4; 31 | static constexpr int WEAPON_FIELD_AMMOUSAGE = 5; 32 | static constexpr int WEAPON_FIELD_PROJTYPE = 6; 33 | static constexpr int WEAPON_FIELD_NUMSHOTS = 7; 34 | static constexpr int WEAPON_FIELD_SHOTHOLD = 8; 35 | static constexpr int WEAPON_MAX_FIELDS = 9; 36 | static constexpr int WEAPON_STRIDE = 8; 37 | static constexpr int MONSTER_FIELD_ATTACK1 = 0; 38 | static constexpr int MONSTER_FIELD_ATTACK2 = 1; 39 | static constexpr int MONSTER_FIELD_CHANCE = 2; 40 | static constexpr int MAX_WRAITH_DRAIN = 45; 41 | static constexpr int MAP_03_BOOST = 9; 42 | static constexpr int PUNCH_PREP = 1; 43 | static constexpr int PUNCH_RIGHTHAND = 2; 44 | static constexpr int PUNCH_LEFTHAND = 3; 45 | static constexpr int ONE_FP = 65536; 46 | static constexpr int LOWEREDWEAPON_Y = 38; 47 | static constexpr int LOWERWEAPON_TIME = 200; 48 | static constexpr int WEAPON_SCALE = 131072; 49 | static constexpr int COMBAT_DONE = 0; 50 | static constexpr int COMBAT_CONTINUE = 1; 51 | static constexpr int REBOUNDOFFSET = 31; 52 | 53 | static constexpr int FIELD_COUNT = 6; 54 | static constexpr int FLD_WPIDLEX = 0; 55 | static constexpr int FLD_WPIDLEY = 1; 56 | static constexpr int FLD_WPATKX = 2; 57 | static constexpr int FLD_WPATKY = 3; 58 | static constexpr int FLD_WPFLASHX = 4; 59 | static constexpr int FLD_WPFLASHY = 5; 60 | 61 | int touchMe; 62 | int tileDistances[Combat::MAX_TILEDISTANCES]; 63 | int16_t*monsterAttacks; 64 | int field_0x50_; 65 | int drawLogo; 66 | int field_0x58_; 67 | int8_t* wpinfo; 68 | int8_t* monsterStats; 69 | Entity* curAttacker; 70 | Entity* curTarget; 71 | Entity* lastTarget; 72 | int dodgeDir; 73 | EntityMonster* targetMonster; 74 | EntityMonster* attackerMonster; 75 | int targetSubType; 76 | int targetType; 77 | int stage; 78 | int nextStageTime; 79 | int nextStage; 80 | GameSprite* activeMissiles[8]; 81 | int numActiveMissiles; 82 | int missileAnim; 83 | bool targetKilled; 84 | bool exploded; 85 | ScriptThread* explodeThread; 86 | int damage; 87 | int totalDamage; 88 | int deathAmt; 89 | int accumRoundDamage; 90 | int totalArmorDamage; 91 | int hitType; 92 | int animStartTime; 93 | int animTime; 94 | int animEndTime; 95 | int attackerWeaponId; 96 | int attackerWeaponProj; 97 | int attackerWeapon; 98 | int weaponDistance; 99 | bool lerpingWeapon; 100 | bool weaponDown; 101 | bool lerpWpDown; 102 | int lerpWpStartTime; 103 | int lerpWpDur; 104 | int field_0x110_; 105 | bool flashDone; 106 | int flashDoneTime; 107 | int flashTime; 108 | bool settingDynamite; 109 | bool dynamitePlaced; 110 | int settingDynamiteTime; 111 | int currentBombIndex; 112 | int placingBombZ; 113 | int attackFrame; 114 | int animLoopCount; 115 | bool gotCrit; 116 | bool gotHit; 117 | bool isGibbed; 118 | int reflectionDmg; 119 | int playerMissRepetition; 120 | int monsterMissRepetition; 121 | int renderTime; 122 | int attackX; 123 | int attackY; 124 | int8_t* weapons; 125 | int8_t* monsterWeakness; 126 | CombatEntity* monsters[51]; 127 | int worldDist; 128 | int tileDist; 129 | int crFlags; 130 | int crDamage; 131 | int crArmorDamage; 132 | int crCritChance; 133 | int crHitChance; 134 | int punchingMonster; 135 | bool punchMissed; 136 | bool oneShotCheat; 137 | int numThornParticleSystems; 138 | int32_t* tableCombatMasks; 139 | bool soulCubeIsAttacking; 140 | 141 | // Constructor 142 | Combat(); 143 | // Destructor 144 | ~Combat(); 145 | 146 | short getWeaponWeakness(int n, int n2, int n3); 147 | bool startup(); 148 | void performAttack(Entity* curAttacker, Entity* curTarget, int attackX, int attackY, bool b); 149 | void checkMonsterFX(); 150 | int playerSeq(); 151 | int monsterSeq(); 152 | void drawEffects(); 153 | void drawWeapon(int sx, int sy); 154 | void shiftWeapon(bool lerpWpDown); 155 | int runFrame(); 156 | int calcHit(Entity* entity); 157 | void explodeOnMonster(); 158 | void explodeOnPlayer(); 159 | int getMonsterField(EntityDef* entityDef, int n); 160 | void checkForBFGDeaths(int x, int y); 161 | void radiusHurtEntities(int n, int n2, int n3, int n4, Entity* entity, Entity* entity2); 162 | void hurtEntityAt(int n, int n2, int n3, int n4, int n5, int n6, Entity* entity, Entity* entity2); 163 | void hurtEntityAt(int n, int n2, int n3, int n4, int n5, int n6, Entity* entity, bool b, Entity* entity2); 164 | Text* getWeaponStatStr(int n); 165 | Text* getArmorStatStr(int n); 166 | int WorldDistToTileDist(int n); 167 | void cleanUpAttack(); 168 | void updateProjectile(); 169 | void launchProjectile(); 170 | GameSprite* allocMissile(int n, int n2, int n3, int n4, int n5, int n6, int duration, int n7); 171 | void launchSoulCube(); 172 | int getWeaponTileNum(int n); 173 | 174 | }; 175 | 176 | #endif -------------------------------------------------------------------------------- /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 getIQPercent(); 27 | int addStat(int i, int i2); 28 | int setStat(int i, int i2); 29 | int calcXP(); 30 | void loadState(InputStream* inputStream, bool b); 31 | void saveState(OutputStream* outputStream, bool b); 32 | void calcCombat(CombatEntity* combatEntity, Entity* entity, bool b, int n, int n2); 33 | int calcHit(CombatEntity* ce, CombatEntity* ce2, bool b, int i, bool b2); 34 | int calcDamage(CombatEntity* ce, Entity* entity, CombatEntity* ce2, bool b, int n); 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /src/ComicBook.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMICBOOK_H__ 2 | #define __COMICBOOK_H__ 3 | 4 | class Image; 5 | class Graphics; 6 | 7 | class ComicBook 8 | { 9 | private: 10 | 11 | public: 12 | int field_0x0; 13 | int field_0x4; 14 | int curX; 15 | int curY; 16 | bool field_0x10; 17 | bool isLoaded; 18 | uint8_t field_0x12; 19 | uint8_t field_0x13; 20 | int comicBookIndex; 21 | int iPhoneComicIndex; 22 | int field_0x1c; 23 | Image* imgComicBook[17]; 24 | Image* imgiPhoneComicBook[39]; 25 | int iPhonePage; 26 | int cur_iPhonePage; 27 | int page; 28 | int curPage; 29 | bool field_0x110; 30 | uint8_t field_0x111; 31 | uint8_t field_0x112; 32 | uint8_t field_0x113; 33 | int endPoint; 34 | bool field_0x118; 35 | uint8_t field_0x119; 36 | uint8_t field_0x11a; 37 | uint8_t field_0x11b; 38 | int field_0x11c; 39 | int begPoint; 40 | int midPoint; 41 | float accelerationX; 42 | float accelerationY; 43 | float accelerationZ; 44 | bool is_iPhoneComic; 45 | bool field_0x135; 46 | uint8_t field_0x136; 47 | uint8_t field_0x137; 48 | int field_0x138; 49 | bool field_0x13c; 50 | uint8_t field_0x13d; 51 | uint8_t field_0x13e; 52 | uint8_t field_0x13f; 53 | int field_0x140; 54 | float field_0x144; 55 | bool drawExitButton; 56 | uint8_t field_0x149; 57 | uint8_t field_0x14a; 58 | uint8_t field_0x14b; 59 | int field_0x14c; 60 | int exitBtnRect[4]; 61 | bool exitBtnHighlighted; 62 | uint8_t field_0x161; 63 | uint8_t field_0x162; 64 | uint8_t field_0x163; 65 | int field_0x164; 66 | int field_0x168; 67 | int field_0x16c; 68 | int field_0x170; 69 | bool field_0x174; 70 | uint8_t field_0x175; 71 | uint8_t field_0x176; 72 | uint8_t field_0x177; 73 | 74 | // Constructor 75 | ComicBook(); 76 | // Destructor 77 | ~ComicBook(); 78 | 79 | void Draw(Graphics* graphics); 80 | void DrawLoading(Graphics* graphics); 81 | void loadImage(int index, bool vComic); 82 | void CheckImageExistence(Image* image); 83 | void DrawImage(Image* image, int a3, int a4, char a5, float alpha, char a7); 84 | 85 | void UpdateMovement(); 86 | void UpdateTransition(); 87 | 88 | void Touch(int x, int y, bool b); 89 | bool ButtonTouch(int x, int y); 90 | void TouchMove(int x, int y); 91 | void DeleteImages(); 92 | void DrawExitButton(Graphics* graphics); 93 | void handleComicBookEvents(int key, int keyAction); 94 | }; 95 | 96 | #endif -------------------------------------------------------------------------------- /src/Entity.h: -------------------------------------------------------------------------------- 1 | #ifndef __ENTITY_H__ 2 | #define __ENTITY_H__ 3 | 4 | class EntityDef; 5 | class EntityMonster; 6 | class LerpSprite; 7 | class OutputStream; 8 | class InputStream; 9 | 10 | class Entity 11 | { 12 | private: 13 | 14 | public: 15 | int touchMe; 16 | EntityDef* def; 17 | EntityMonster* monster; 18 | Entity* nextOnTile; 19 | Entity* prevOnTile; 20 | short linkIndex; 21 | short name; 22 | int info; 23 | int param; 24 | int* lootSet; 25 | int32_t knockbackDelta[2]; 26 | Entity* raiseTargets[4]; 27 | int pos[2]; 28 | int tempSaveBuf[2]; 29 | 30 | // Constructor 31 | Entity(); 32 | // Destructor 33 | ~Entity(); 34 | 35 | bool startup(); 36 | void reset(); 37 | void initspawn(); 38 | int getSprite(); 39 | bool touched(); 40 | bool touchedItem(); 41 | bool pain(int n, Entity* entity); 42 | void checkMonsterDeath(bool b, bool b2); 43 | void died(bool b, Entity* entity); 44 | bool deathByExplosion(Entity* entity); 45 | void aiCalcSimpleGoal(bool b); 46 | bool aiCalcArchVileGoal(); 47 | void aiMoveToGoal(); 48 | void aiChooseNewGoal(bool b); 49 | bool aiIsValidGoal(); 50 | bool aiIsAttackValid(); 51 | void aiThink(bool b); 52 | static bool CheckWeaponMask(char n1, int n2) { 53 | return (1 << n1 & n2); 54 | } 55 | int aiWeaponForTarget(Entity* entity); 56 | LerpSprite* aiInitLerp(int travelTime); 57 | void aiFinishLerp(); 58 | bool checkLineOfSight(int n, int n2, int n3, int n4, int n5); 59 | bool calcPath(int n, int n2, int n3, int n4, int n5, bool b); 60 | bool aiGoal_MOVE(); 61 | void aiReachedGoal_MOVE(); 62 | int distFrom(int n, int n2); 63 | void attack(); 64 | void undoAttack(); 65 | void trimCorpsePile(int n, int n2); 66 | void knockback(int n, int n2, int n3); 67 | int getFarthestKnockbackDist(int n, int n2, int n3, int n4, Entity* entity, int n5, int n6, int n7); 68 | int findRaiseTarget(int n, int n2, int n3); 69 | void raiseTarget(int n); 70 | void resurrect(int n, int n2, int n3); 71 | int* calcPosition(); 72 | bool isBoss(); 73 | bool isHasteResistant(); 74 | bool isDroppedEntity(); 75 | bool isBinaryEntity(int* array); 76 | bool isNamedEntity(int* array); 77 | void saveState(OutputStream* OS, int n); 78 | void loadState(InputStream* IS, int n); 79 | int getSaveHandle(bool b); 80 | void restoreBinaryState(int n); 81 | short getIndex(); 82 | void updateMonsterFX(); 83 | void populateDefaultLootSet(); 84 | int findRandomJokeItem(); 85 | void addToLootSet(int n, int n2, int n3); 86 | bool hasEmptyLootSet(); 87 | 88 | 89 | 90 | 91 | 92 | }; 93 | 94 | #endif -------------------------------------------------------------------------------- /src/EntityDef.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "CAppContainer.h" 4 | #include "App.h" 5 | #include "EntityDef.h" 6 | #include "JavaStream.h" 7 | #include "Resource.h" 8 | 9 | // ----------------------- 10 | // EntityDefManager Class 11 | // ----------------------- 12 | 13 | EntityDefManager::EntityDefManager() { 14 | std::memset(this, 0, sizeof(EntityDefManager)); 15 | } 16 | 17 | EntityDefManager::~EntityDefManager() { 18 | } 19 | 20 | bool EntityDefManager::startup() { 21 | Applet* app = CAppContainer::getInstance()->app; 22 | InputStream IS; 23 | printf("EntityDefManager::startup\n"); 24 | 25 | this->numDefs = 0; 26 | 27 | if (!IS.loadFile(Resources::RES_ENTITIES_BIN_GZ, InputStream::LOADTYPE_RESOURCE)) { 28 | app->Error("getResource(%s) failed\n", Resources::RES_ENTITIES_BIN_GZ); 29 | } 30 | 31 | app->resource->read(&IS, sizeof(short)); 32 | this->numDefs = (int)app->resource->shiftShort(); 33 | this->list = new EntityDef[this->numDefs]; 34 | 35 | for (int i = 0; i < this->numDefs; i++) { 36 | app->resource->read(&IS, 8); 37 | this->list[i].tileIndex = (int16_t)app->resource->shiftShort(); 38 | this->list[i].eType = (uint8_t)app->resource->shiftByte(); 39 | this->list[i].eSubType = (uint8_t)app->resource->shiftByte(); 40 | this->list[i].parm = (uint8_t)app->resource->shiftByte(); 41 | this->list[i].name = (int16_t)app->resource->shiftUByte(); 42 | this->list[i].longName = (int16_t)app->resource->shiftUByte(); 43 | this->list[i].description = (int16_t)app->resource->shiftUByte(); 44 | } 45 | 46 | IS.~InputStream(); 47 | 48 | /*for (int i = 0; i < this->numDefs; i++) { 49 | printf("list[%d]------------------------\n", i); 50 | printf("tileIndex %d\n", this->list[i].tileIndex); 51 | printf("eType %d\n", this->list[i].eType); 52 | printf("eSubType %d\n", this->list[i].eSubType); 53 | printf("parm %d\n", this->list[i].parm); 54 | printf("name %d\n", this->list[i].name); 55 | printf("longName %d\n", this->list[i].longName); 56 | printf("description %d\n", this->list[i].description); 57 | }*/ 58 | 59 | return true; 60 | } 61 | 62 | 63 | EntityDef* EntityDefManager::find(int eType, int eSubType) { 64 | return this->find(eType, eSubType, -1); 65 | } 66 | 67 | EntityDef* EntityDefManager::find(int eType, int eSubType, int parm) { 68 | for (int i = 0; i < this->numDefs; i++) { 69 | if (this->list[i].eType == eType && this->list[i].eSubType == eSubType && (parm == -1 || this->list[i].parm == parm)) { 70 | return &this->list[i]; 71 | } 72 | } 73 | return nullptr; 74 | } 75 | 76 | EntityDef* EntityDefManager::lookup(int tileIndex) { 77 | for (int i = 0; i < this->numDefs; ++i) { 78 | if (this->list[i].tileIndex == tileIndex) { 79 | return &this->list[i]; 80 | } 81 | } 82 | return nullptr; 83 | } 84 | 85 | 86 | // ---------------- 87 | // EntityDef Class 88 | // ---------------- 89 | 90 | EntityDef::EntityDef() { 91 | std::memset(this, 0, sizeof(EntityDef)); 92 | } 93 | -------------------------------------------------------------------------------- /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/EntityMonster.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "EntityMonster.h" 4 | #include "JavaStream.h" 5 | 6 | EntityMonster::EntityMonster() { 7 | std::memset(this, 0, sizeof(EntityMonster)); 8 | } 9 | 10 | void EntityMonster::clearEffects() { 11 | this->monsterEffects = 0; 12 | } 13 | 14 | void EntityMonster::reset() { 15 | this->prevOnList = nullptr; 16 | this->nextOnList = nullptr; 17 | this->target = nullptr; 18 | this->nextAttacker = nullptr; 19 | this->frameTime = 0; 20 | this->flags = 0; 21 | this->clearEffects(); 22 | this->resetGoal(); 23 | } 24 | 25 | void EntityMonster::saveGoalState(OutputStream* OS) { 26 | OS->writeInt(this->goalType | this->goalFlags << 4 | this->goalTurns << 8 |this->goalX << 12 | this->goalY << 17 | this->goalParam << 22); 27 | } 28 | 29 | void EntityMonster::loadGoalState(InputStream* IS) { 30 | int args = IS->readInt(); 31 | this->goalType = (uint8_t)(args & 0xF); 32 | this->goalFlags = (uint8_t)(args >> 4 & 0xF); 33 | this->goalTurns = (uint8_t)(args >> 8 & 0xF); 34 | this->goalX = (args >> 12 & 0x1F); 35 | this->goalY = (args >> 17 & 0x1F); 36 | this->goalParam = (args >> 22 & 0x3FF); 37 | } 38 | 39 | void EntityMonster::resetGoal() { 40 | this->goalType = 0; 41 | this->goalFlags = 0; 42 | this->goalTurns = 0; 43 | this->goalY = 0; 44 | this->goalX = 0; 45 | this->goalParam = 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/EntityMonster.h: -------------------------------------------------------------------------------- 1 | #ifndef __ENTITYMONSTER_H__ 2 | #define __ENTITYMONSTER_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "CombatEntity.h" 8 | class OutputStream; 9 | class InputStream; 10 | class CombatEntity; 11 | class Entity; 12 | 13 | class EntityMonster 14 | { 15 | private: 16 | 17 | public: 18 | int touchMe; 19 | CombatEntity ce; 20 | Entity* nextOnList; 21 | Entity* prevOnList; 22 | Entity* nextAttacker; 23 | Entity* target; 24 | int frameTime; 25 | short flags; 26 | int monsterEffects; 27 | uint8_t goalType; 28 | uint8_t goalFlags; 29 | uint8_t goalTurns; 30 | int goalX; 31 | int goalY; 32 | int goalParam; 33 | 34 | // Constructor 35 | EntityMonster(); 36 | 37 | void clearEffects(); 38 | void reset(); 39 | void saveGoalState(OutputStream* OS); 40 | void loadGoalState(InputStream* IS); 41 | void resetGoal(); 42 | }; 43 | 44 | #endif -------------------------------------------------------------------------------- /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/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/Graphics.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/DoomIIRPG-RE/4ecf14341c9eeadb08acdede82813e660bc3b0a2/src/Graphics.cpp -------------------------------------------------------------------------------- /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 drawCursor(int x, int y, int flags); 68 | void drawCursor(int x, int y, int flags, bool b); 69 | void clipRect(int x, int y, int w, int h); 70 | void setClipRect(int x, int y, int w, int h); 71 | void clearClipRect(); 72 | void setScreenSpace(int* rect); 73 | void setScreenSpace(int x, int y, int w, int h); 74 | void resetScreenSpace(); 75 | void fade(int* rect, int alpha, int color); 76 | void drawPixelPortal(int* rect, int x, int y, uint32_t color); 77 | }; 78 | 79 | #endif -------------------------------------------------------------------------------- /src/HackingGame.h: -------------------------------------------------------------------------------- 1 | #ifndef __HACKINGGAME_H__ 2 | #define __HACKINGGAME_H__ 3 | 4 | class ScriptThread; 5 | class Image; 6 | class fmButtonContainer; 7 | 8 | class HackingGame 9 | { 10 | private: 11 | 12 | public: 13 | static int touchedColumn; 14 | 15 | int touchMe; 16 | ScriptThread* callingThread; 17 | Image* imgEnergyCore; 18 | Image* imgGameColors; 19 | Image* imgHelpScreenAssets; 20 | int columnCount; 21 | short selectedRow; 22 | short selectedColumn; 23 | bool selected; 24 | short turnsLeft; 25 | int confirmationCursor; 26 | int columnBlockCameFrom; 27 | bool gamePlayedFromMainMenu; 28 | short gameBoard[5][6]; 29 | uint8_t mostRecentSrc[6]; 30 | uint8_t mostRecentDest[6]; 31 | int CORE_WIDTH; 32 | int CORE_HEIGHT; 33 | int* stateVars; 34 | bool touched; 35 | int currentPress_x; 36 | int currentPress_y; 37 | int oldPress_x; 38 | int oldPress_y; 39 | fmButtonContainer* m_hackingButtons; 40 | 41 | // Constructor 42 | HackingGame(); 43 | // Destructor 44 | ~HackingGame(); 45 | 46 | void playFromMainMenu(); 47 | void setupGlobalData(); 48 | void initGame(ScriptThread* scriptThread, int i); 49 | void initGame(ScriptThread* scriptThread, int i, int i2); 50 | void fillGameBoardRandomly(short array[5][6], int n, int n2, int n3); 51 | void fillGameBoardRandomly(short array[5][6], int n, int n2, int n3, int n4); 52 | void handleInput(int action); 53 | void attemptToMove(short n); 54 | void updateGame(Graphics* graphics); 55 | void drawHelpScreen(Graphics* graphics); 56 | void drawGameScreen(Graphics* graphics); 57 | void drawGoalTextAndBars(Graphics* graphics, Text* text); 58 | void drawGamePieces(Graphics* graphics, int x, int y); 59 | bool gameIsSolved(short array[5][6]); 60 | void drawPiece(int i, int x, int y, Graphics* graphics); 61 | void forceWin(); 62 | void endGame(int n); 63 | void touchStart(int x, int y); 64 | void touchMove(int x, int y); 65 | void touchEnd(int x, int y); 66 | }; 67 | 68 | #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 = 15; 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* imgCockpitOverlay; 57 | bool cockpitOverlayRaw; 58 | Image* imgPortraitsSM; 59 | Image* imgPlayerFaces; 60 | Image* imgPlayerActive; 61 | Image* imgPlayerFrameNormal; 62 | Image* imgPlayerFrameActive; 63 | Image* imgHudFill; 64 | Image* imgIce; 65 | Image* imgSentryBotFace; 66 | Image* imgSentryBotActive; 67 | bool isInWeaponSelect; 68 | Image* imgPanelTop; 69 | Image* imgPanelTopSentrybot; 70 | Image* imgWeaponNormal; 71 | Image* imgWeaponActive; 72 | Image* imgShieldNormal; 73 | Image* imgShieldButtonActive; 74 | Image* imgKeyNormal; 75 | Image* imgKeyActive; 76 | Image* imgHealthNormal; 77 | Image* imgHealthButtonActive; 78 | Image* imgSwitchRightNormal; 79 | Image* imgSwitchRightActive; 80 | Image* imgSwitchLeftNormal; 81 | Image* imgSwitchLeftActive; 82 | Image* imgVendingSoftkeyPressed; 83 | Image* imgVendingSoftkeyNormal; 84 | Image* imgInGameMenuSoftkey; 85 | Image* imgNumbers; 86 | Image* imgHudTest; 87 | Text* messages[Hud::MAX_MESSAGES]; 88 | int messageFlags[Hud::MAX_MESSAGES]; 89 | int msgCount; 90 | int msgTime; 91 | int msgDuration; 92 | int subTitleID; 93 | int subTitleTime; 94 | int cinTitleID; 95 | int cinTitleTime; 96 | Text* bubbleText; 97 | int bubbleTextTime; 98 | int bubbleColor; 99 | int damageTime; 100 | int damageCount; 101 | int damageDir; 102 | Entity* lastTarget; 103 | int monsterStartHealth; 104 | int monsterDestHealth; 105 | int playerStartHealth; 106 | int playerDestHealth; 107 | int monsterHealthChangeTime; 108 | int playerHealthChangeTime; 109 | bool showCinPlayer; 110 | int drawTime; 111 | fmButtonContainer* m_hudButtons; 112 | fmButtonContainer* m_weaponsButtons; 113 | int weaponPressTime; 114 | 115 | // Constructor 116 | Hud(); 117 | // Destructor 118 | ~Hud(); 119 | 120 | bool startup(); 121 | void shiftMsgs(); 122 | void calcMsgTime(); 123 | void addMessage(short i); 124 | void addMessage(short i, short i2); 125 | void addMessage(short i, int i2); 126 | void addMessage(short i, short i2, int i3); 127 | void addMessage(Text* text); 128 | void addMessage(Text* text, int flags); 129 | Text* getMessageBuffer(); 130 | Text* getMessageBuffer(int flags); 131 | void finishMessageBuffer(); 132 | bool isShiftingCenterMsg(); 133 | void drawTopBar(Graphics* graphics); 134 | void drawImportantMessage(Graphics* graphics, Text* text, int color); 135 | void drawCenterMessage(Graphics* graphics, Text* text, int color); 136 | void drawCinematicText(Graphics* graphics); 137 | void drawEffects(Graphics* graphics); 138 | void drawDamageVignette(Graphics* graphics); 139 | void smackScreen(int vScrollVelocity); 140 | void stopScreenSmack(); 141 | void brightenScreen(int maxLocalBrightness, int brightnessInitialBoost); 142 | void stopBrightenScreen(); 143 | void drawOverlay(Graphics* graphics); 144 | void drawHudOverdraw(Graphics* graphics); 145 | void drawBottomBar(Graphics* graphics); 146 | void draw(Graphics* graphics); 147 | void drawMonsterHealth(Graphics* graphics); 148 | void showSpeechBubble(int i, int i2); 149 | void drawBubbleText(Graphics* graphics); 150 | void drawArrowControls(Graphics* graphics); 151 | void drawWeapon(Graphics* graphics, int x, int y, int weapon, bool highlighted); 152 | void drawNumbers(Graphics* graphics, int x, int y, int space, int num, int weapon); 153 | void drawCurrentKeys(Graphics* graphics, int x, int y); 154 | void drawWeaponSelection(Graphics* graphics); 155 | void handleUserMoved(int pressX, int pressY); 156 | void handleUserTouch(int pressX, int pressY, bool highlighted); 157 | void update(); 158 | }; 159 | 160 | #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 | std::free(this->pBmp); 12 | this->pBmp = nullptr; 13 | } 14 | if (this->pRGB888) { 15 | std::free(this->pRGB888); 16 | this->pRGB888 = nullptr; 17 | } 18 | if (this->pRGB565) { 19 | std::free(this->pRGB565); 20 | this->pRGB565 = nullptr; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/IDIB.h: -------------------------------------------------------------------------------- 1 | #ifndef __IDIB_H__ 2 | #define __IDIB_H__ 3 | 4 | #include 5 | 6 | class IDIB 7 | { 8 | private: 9 | 10 | public: 11 | uint8_t* pBmp; 12 | uint32_t* pRGB888; 13 | uint16_t* pRGB565; 14 | unsigned int cntRGB; 15 | unsigned int nColorScheme; 16 | unsigned int ncTransparent; 17 | int width; 18 | int height; 19 | int depth; 20 | unsigned int pitch; 21 | 22 | // Constructor 23 | IDIB(); 24 | // Destructor 25 | ~IDIB(); 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /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 | std::free(this->piDIB); 17 | } 18 | this->piDIB = nullptr; 19 | glDeleteTextures(1, &this->texture); 20 | this->texture = -1; 21 | std::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 | glEnable(GL_TEXTURE_2D); 108 | glActiveTexture(GL_TEXTURE0); 109 | glBindTexture(GL_TEXTURE_2D, this->texture); 110 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 111 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 112 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 113 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 114 | glVertexPointer(3, GL_FLOAT, 0, vp); 115 | glEnableClientState(GL_VERTEX_ARRAY); 116 | glTexCoordPointer(2, GL_FLOAT, 0, st); 117 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); 118 | glDisableClientState(GL_COLOR_ARRAY); 119 | glMatrixMode(GL_MODELVIEW); 120 | glPushMatrix(); 121 | glLoadIdentity(); 122 | glTranslatef(scaleW + (float)(scaleX), scaleH + (float)(scaleY), 0.0); 123 | switch (rotateMode) 124 | { 125 | case 1: 126 | glRotatef(90.0f, 0.0f, 0.0f, 1.0f); 127 | break; 128 | case 2: 129 | glRotatef(180.0f, 0.0f, 0.0f, 1.0f); 130 | break; 131 | case 3: 132 | glRotatef(270.0f, 0.0f, 0.0f, 1.0f); 133 | break; 134 | case 4: 135 | glScalef(-1.0f, 1.0f, 1.0f); 136 | break; 137 | case 5: 138 | glRotatef(90.0f, 0.0f, 0.0f, 1.0f); 139 | glScalef(-1.0f, 1.0f, 1.0f); 140 | break; 141 | case 6: 142 | glRotatef(180.0f, 0.0f, 0.0f, 1.0f); 143 | glScalef(-1.0f, 1.0f, 1.0f); 144 | break; 145 | case 7: 146 | glRotatef(270.0f, 0.0f, 0.0f, 1.0f); 147 | glScalef(-1.0f, 1.0f, 1.0f); 148 | break; 149 | 150 | case 8: // New 151 | glScalef(1.0f, -1.0f, 1.0f); 152 | break; 153 | default: 154 | break; 155 | } 156 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 157 | glPopMatrix(); 158 | } 159 | 160 | void Image::setRenderMode(int renderMode) { 161 | Applet* app = CAppContainer::getInstance()->app; 162 | int color; 163 | 164 | switch (renderMode) { 165 | case 0: 166 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 167 | if (this->isTransparentMask == false) { 168 | glDisable(GL_ALPHA_TEST); 169 | glDisable(GL_BLEND); 170 | return; 171 | } 172 | glEnable(GL_ALPHA_TEST); 173 | break; 174 | case 1: 175 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 176 | glColor4f(1.0f, 1.0f, 1.0f, 0.25f); 177 | glDisable(GL_ALPHA_TEST); 178 | break; 179 | case 2: 180 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 181 | glColor4f(1.0f, 1.0f, 1.0f, 0.5f); 182 | glDisable(GL_ALPHA_TEST); 183 | break; 184 | case 3: 185 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 186 | glEnable(GL_ALPHA_TEST); 187 | glAlphaFunc(GL_GREATER, 0); 188 | glEnable(GL_BLEND); 189 | glBlendFunc(GL_SRC_COLOR, GL_ONE); 190 | return; 191 | case 8: 192 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 193 | glEnable(GL_BLEND); 194 | color = Graphics::charColors[app->canvas->graphics.currentCharColor]; 195 | glColor4ub(color >> 0x10 & 0xff, color >> 8 & 0xff, color & 0xff, color >> 0x18); 196 | return; 197 | case 12: 198 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 199 | glColor4f(1.0f, 1.0f, 1.0f, 0.75f); 200 | glDisable(GL_ALPHA_TEST); 201 | break; 202 | case 13: 203 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 204 | glColor4f(1.0f, 1.0f, 1.0f, app->canvas->blendSpecialAlpha); 205 | glDisable(GL_ALPHA_TEST); 206 | break; 207 | default: 208 | return; 209 | } 210 | glAlphaFunc(GL_GREATER, 0); 211 | glEnable(GL_BLEND); 212 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 213 | } 214 | -------------------------------------------------------------------------------- /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/Input.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/DoomIIRPG-RE/4ecf14341c9eeadb08acdede82813e660bc3b0a2/src/Input.cpp -------------------------------------------------------------------------------- /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 | AVK_BOTDISCARD, 150 | 151 | 152 | // New Flags Menu Only on port 153 | AVK_MENU_UP = 0x40, 154 | AVK_MENU_DOWN = 0x80, 155 | AVK_MENU_PAGE_UP = 0x100, 156 | AVK_MENU_PAGE_DOWN = 0x200, 157 | AVK_MENU_SELECT = 0x400, 158 | AVK_MENU_OPEN = 0x800, 159 | AVK_MENU_NUMBER = 0x2000, 160 | AVK_ITEMS_INFO = 0x4000, 161 | AVK_DRINKS = 0x8000, 162 | AVK_PDA = 0x10000 163 | }; 164 | 165 | extern void controllerVibrate(int duration_ms) noexcept; 166 | 167 | class Input 168 | { 169 | private: 170 | 171 | public: 172 | 173 | // Constructor 174 | Input(); 175 | // Destructor 176 | ~Input(); 177 | 178 | void init(); 179 | void unBind(int* keyBinds, int keycode); 180 | void setBind(int* keyBinds, int keycode); 181 | void setInputBind(int scancode); 182 | void handleEvents() noexcept; 183 | void consumeEvents() noexcept; 184 | }; 185 | #endif -------------------------------------------------------------------------------- /src/JavaStream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "JavaStream.h" 4 | #include "CAppContainer.h" 5 | #include "App.h" 6 | #include "ZipFile.h" 7 | 8 | // ------------------ 9 | // InputStream Class 10 | // ------------------ 11 | 12 | InputStream::InputStream() { 13 | //printf("InputStream::init\n"); 14 | this->data = nullptr; 15 | this->field_0x4 = 0; 16 | this->cursor = 0; 17 | this->field_0x0 = 0; 18 | this->file = nullptr; 19 | this->field_0x28 = 0; 20 | } 21 | 22 | InputStream::~InputStream() { 23 | if (this->file) { 24 | std::fclose(this->file); 25 | this->file = nullptr; 26 | } 27 | 28 | if (this->data) { 29 | std::free(this->data); 30 | this->data = nullptr; 31 | } 32 | } 33 | 34 | bool InputStream::loadResource(const char* fileName) 35 | { 36 | return loadFile(fileName, LT_RESOURCE); 37 | } 38 | 39 | bool InputStream::loadFile(const char* fileName, int loadType) { 40 | char namePath[2048]; 41 | this->cursor = 0; 42 | 43 | if (loadType == LT_RESOURCE) { 44 | strncpy(namePath, "Payload/Doom2rpg.app/Packages/", sizeof(namePath)); 45 | strncat(namePath, fileName, sizeof(namePath)); 46 | //printf("namePath %s\n", namePath); 47 | 48 | this->data = CAppContainer::getInstance()->zipFile->readZipFileEntry(namePath, &this->fileSize); 49 | if (this->data) { 50 | return true; 51 | } 52 | } 53 | else if (loadType == LT_SOUND_RESOURCE) { // [GEC] 54 | strncpy(namePath, "Payload/Doom2rpg.app/Packages/sounds2/", sizeof(namePath)); 55 | strncat(namePath, fileName, sizeof(namePath)); 56 | //printf("namePath %s\n", namePath); 57 | 58 | this->data = CAppContainer::getInstance()->zipFile->readZipFileEntry(namePath, &this->fileSize); 59 | if (this->data) { 60 | return true; 61 | } 62 | } 63 | else if (loadType == LT_FILE) { 64 | std::strcpy(namePath, dir); 65 | std::strcat(namePath, "/"); 66 | std::strcat(namePath, fileName); 67 | 68 | this->file = std::fopen(namePath, "rb"); 69 | 70 | if (this->file != nullptr) { 71 | std::fseek(this->file, 0, SEEK_END); 72 | this->fileSize = ftell(this->file); 73 | std::fseek(this->file, 0, SEEK_SET); 74 | this->data = (uint8_t*)std::malloc(this->fileSize); 75 | std::fread(this->data, sizeof(uint8_t), this->fileSize, this->file); 76 | 77 | if (std::ferror(this->file)) { 78 | CAppContainer::getInstance()->app->Error( "Error Reading File!\n"); 79 | return false; 80 | } 81 | 82 | std::fclose(this->file); 83 | this->file = nullptr; 84 | return true; 85 | } 86 | else { 87 | //CAppContainer::getInstance()->app->Error("Error Openeing File: %s\n", namePath); 88 | } 89 | } 90 | else { 91 | CAppContainer::getInstance()->app->Error("File does not exist\n"); 92 | } 93 | 94 | return false; 95 | } 96 | 97 | void InputStream::close() { 98 | if (this->file) { 99 | std::fclose(this->file); 100 | this->file = nullptr; 101 | } 102 | } 103 | 104 | int InputStream::readInt() 105 | { 106 | int ch1 = this->data[this->cursor + 3]; 107 | int ch2 = this->data[this->cursor + 2]; 108 | int ch3 = this->data[this->cursor + 1]; 109 | int ch4 = this->data[this->cursor + 0]; 110 | this->cursor += sizeof(int32_t); 111 | return (int) ((ch1 << 24 & 0xFF000000) + (ch2 << 16 & 0xFF0000) + (ch3 << 8 & 0xFF00) + (ch4 << 0 & 0xFF)); 112 | } 113 | 114 | int InputStream::readShort() 115 | { 116 | int ch1 = this->data[this->cursor + 1]; 117 | int ch2 = this->data[this->cursor + 0]; 118 | this->cursor += sizeof(int16_t); 119 | return (int)((ch1 << 8 & 0xFF00) + (ch2 << 0 & 0xFF)); 120 | } 121 | 122 | bool InputStream::readBoolean() 123 | { 124 | uint8_t ch1 = this->data[this->cursor + 0]; 125 | this->cursor += sizeof(int8_t); 126 | return (bool)((ch1 != 0) ? true : false); 127 | } 128 | 129 | uint8_t InputStream::readByte() 130 | { 131 | uint8_t ch1 = this->data[this->cursor + 0]; 132 | this->cursor += sizeof(int8_t); 133 | return ch1; 134 | } 135 | 136 | uint8_t InputStream::readUnsignedByte() 137 | { 138 | uint8_t ch1 = this->data[this->cursor + 0]; 139 | this->cursor += sizeof(int8_t); 140 | return ch1; 141 | } 142 | 143 | int InputStream::readSignedByte() 144 | { 145 | uint8_t ch1 = this->data[this->cursor + 0]; 146 | this->cursor += sizeof(int8_t); 147 | return (int)((char)ch1); 148 | } 149 | 150 | void InputStream::read(uint8_t* dest, int off, int size) { 151 | for (int i = 0; i < size; i++) { 152 | if (this->cursor >= this->fileSize) { 153 | break; 154 | } 155 | dest[off + i] = this->data[this->cursor + 0]; 156 | this->cursor++; 157 | } 158 | } 159 | 160 | 161 | // ------------------- 162 | // OutputStream Class 163 | // ------------------- 164 | 165 | OutputStream::OutputStream() { 166 | //printf("OutputStream::init\n"); 167 | this->buffer = nullptr; 168 | this->writeBuff = nullptr; 169 | this->file = nullptr; 170 | this->App = CAppContainer::getInstance()->app;; 171 | this->field_0x24_ = -1; 172 | this->written = 0; 173 | this->flushCount = 0; 174 | this->isOpen = false; 175 | this->noWrite = false; 176 | } 177 | 178 | OutputStream::~OutputStream() { 179 | this->close(); 180 | 181 | if (this->writeBuff) { 182 | std::free(this->writeBuff); 183 | this->writeBuff = nullptr; 184 | } 185 | 186 | if (this->buffer != nullptr) { 187 | std::free(this->buffer); 188 | this->buffer = nullptr; 189 | } 190 | } 191 | 192 | #include 193 | 194 | int OutputStream::openFile(const char* fileName, int openMode) { 195 | char namePath[2060]; 196 | 197 | struct stat sb; 198 | if (stat(dir, &sb)) { 199 | char command[64]; 200 | std::strcpy(command, "mkdir "); 201 | std::strcat(command, "\""); 202 | std::strcat(command, dir); 203 | std::strcat(command, "\""); 204 | //printf("command %s\n", command); 205 | std::system(command); 206 | } 207 | 208 | std::strcpy(namePath, dir); 209 | std::strcat(namePath, "/"); 210 | std::strcat(namePath, fileName); 211 | 212 | //printf("output file: %s\n", namePath); 213 | this->buffer = (uint8_t*)std::malloc(512); 214 | std::memset(this->buffer, 0, 512); 215 | 216 | if (this->file != nullptr) { 217 | this->isOpen = true; 218 | return 0; 219 | } 220 | 221 | this->isOpen = false; 222 | if (this->noWrite != false) { 223 | return 1; 224 | } 225 | 226 | switch (openMode) 227 | { 228 | case 1: 229 | this->file = std::fopen(namePath, "wb"); 230 | break; 231 | case 2: 232 | this->file = std::fopen(namePath, "rb"); 233 | break; 234 | case 3: 235 | this->file = std::fopen(namePath, "w+b"); 236 | break; 237 | default: 238 | return 0; 239 | } 240 | 241 | if (this->file != nullptr) { 242 | std::fseek(this->file, 0, SEEK_END); 243 | this->fileSize = std::ftell(this->file); 244 | std::fseek(this->file, 0, SEEK_SET); 245 | this->writeBuff = (uint8_t*)std::malloc(this->fileSize); 246 | return 1; 247 | } 248 | 249 | return 0; 250 | } 251 | 252 | void OutputStream::close() 253 | { 254 | this->flush(); 255 | if (this->file != nullptr) { 256 | std::fclose(this->file); 257 | this->file = nullptr; 258 | } 259 | 260 | if (this->buffer != nullptr) { 261 | std::free(this->buffer); 262 | this->buffer = nullptr; 263 | } 264 | } 265 | 266 | int OutputStream::flush() 267 | { 268 | if (this->written == 0) { 269 | return 1; 270 | } 271 | 272 | this->flushCount += this->written; 273 | 274 | if (!this->noWrite) { 275 | if (std::fwrite(this->buffer, sizeof(uint8_t), this->written, this->file) <= 0) { 276 | return 0; 277 | } 278 | } 279 | 280 | this->written = 0; 281 | return 1; 282 | } 283 | 284 | void OutputStream::writeInt(int i) 285 | { 286 | if ((256 - this->written) < sizeof(uint32_t)) { 287 | if (this->flush() == 0) { 288 | return; 289 | } 290 | } 291 | 292 | this->buffer[this->written++] = (uint8_t)(i & 0xFF); 293 | this->buffer[this->written++] = (uint8_t)(i >> 8 & 0xFF); 294 | this->buffer[this->written++] = (uint8_t)(i >> 16 & 0xFF); 295 | this->buffer[this->written++] = (uint8_t)(i >> 24 & 0xFF); 296 | } 297 | 298 | void OutputStream::writeShort(int16_t i) 299 | { 300 | if ((256U - this->written) < sizeof(uint16_t)) { 301 | if (this->flush() == 0) { 302 | return; 303 | } 304 | } 305 | 306 | this->buffer[this->written++] = (uint8_t)(i & 0xFF); 307 | this->buffer[this->written++] = (uint8_t)(i >> 8 & 0xFF); 308 | } 309 | 310 | void OutputStream::writeByte(uint8_t i) 311 | { 312 | if ((256U - this->written) < sizeof(uint8_t)) { 313 | if (this->flush() == 0) { 314 | return; 315 | } 316 | } 317 | 318 | this->buffer[this->written++] = (uint8_t)(i & 0xFF); 319 | } 320 | 321 | void OutputStream::writeBoolean(bool b) 322 | { 323 | if ((256U - this->written) < sizeof(uint8_t)) { 324 | if (this->flush() == 0) { 325 | return; 326 | } 327 | } 328 | 329 | this->buffer[this->written++] = (uint8_t)(b); 330 | } 331 | 332 | void OutputStream::write(uint8_t* buff, int off, int size) 333 | { 334 | int _written = this->written; 335 | if ((uint32_t)(_written + size) >= 256) { 336 | int count = 256 - _written; 337 | std::memcpy(&this->buffer[_written], &buff[off], count); 338 | this->written += count; 339 | size -= count; 340 | off += count; 341 | if (this->flush() == 0) { 342 | return; 343 | } 344 | } 345 | 346 | std::memcpy(&this->buffer[_written], &buff[off], size); 347 | this->written += size; 348 | } 349 | -------------------------------------------------------------------------------- /src/JavaStream.h: -------------------------------------------------------------------------------- 1 | #ifndef __JAVASTREAM_H__ 2 | #define __JAVASTREAM_H__ 3 | 4 | #include 5 | 6 | #define LT_RESOURCE 5 7 | #define LT_FILE 6 8 | #define LT_SOUND_RESOURCE 7 // [GEC] 9 | static constexpr const char* dir = "Doom2rpg.app"; 10 | 11 | class Applet; 12 | 13 | // ------------------ 14 | // InputStream Class 15 | // ------------------ 16 | 17 | class InputStream 18 | { 19 | private: 20 | 21 | public: 22 | static constexpr int LOADTYPE_RESOURCE = 5; 23 | static constexpr int LOADTYPE_FILE = 6; 24 | 25 | int field_0x0; 26 | int field_0x4; 27 | uint8_t* data; 28 | int cursor; 29 | FILE* file; 30 | int fileSize; 31 | int field_0x28; 32 | 33 | // Constructor 34 | InputStream(); 35 | // Destructor 36 | ~InputStream(); 37 | 38 | bool startup(); 39 | bool loadResource(const char* fileName); 40 | bool loadFile(const char* fileName, int loadType); 41 | void close(); 42 | int readInt(); 43 | int readShort(); 44 | bool readBoolean(); 45 | uint8_t readByte(); 46 | uint8_t readUnsignedByte(); 47 | int readSignedByte(); 48 | void read(uint8_t* dest, int off, int size); 49 | }; 50 | 51 | // ------------------- 52 | // OutputStream Class 53 | // ------------------- 54 | 55 | class OutputStream 56 | { 57 | private: 58 | 59 | public: 60 | 61 | bool isOpen; 62 | FILE* file; 63 | uint8_t* buffer; 64 | int written; 65 | uint8_t* writeBuff; 66 | int field_0x24_; 67 | int fileSize; 68 | int flushCount; 69 | bool noWrite; 70 | Applet* App; 71 | 72 | // Constructor 73 | OutputStream(); 74 | // Destructor 75 | ~OutputStream(); 76 | 77 | int openFile(const char* fileName, int openMode); 78 | void close(); 79 | int flush(); 80 | void writeInt(int i); 81 | void writeShort(int16_t i); 82 | void writeByte(uint8_t i); 83 | void writeBoolean(bool b); 84 | void write(uint8_t* buff, int off, int size); 85 | }; 86 | 87 | #endif -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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/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 | 29 | int UpTime = 0; 30 | 31 | ZipFile zipFile; 32 | zipFile.openZipFile("Doom 2 RPG.ipa"); 33 | 34 | SDLGL sdlGL; 35 | sdlGL.Initialize(); 36 | 37 | Input input; 38 | input.init(); // [GEC] Port: set default Binds 39 | 40 | CAppContainer::getInstance()->Construct(&sdlGL, &zipFile); 41 | sdlGL.updateVideo(); // [GEC] 42 | 43 | SDL_Event ev; 44 | 45 | 46 | float x = 0.0f, y = 30.0f; 47 | int vp_cx = 480; 48 | int vp_cy = 320; 49 | 50 | 51 | Uint8 state; 52 | int mX, mY; /* mouse location*/ 53 | float mousePressX = 0.f, mousePressY = 0.f; /* mouse location float*/ 54 | int winVidWidth = sdlGL.winVidWidth; 55 | int winVidHeight = sdlGL.winVidHeight; 56 | bool useMouse = false; 57 | 58 | 59 | 60 | while (CAppContainer::getInstance()->app->closeApplet != true) { 61 | 62 | int currentTimeMillis = CAppContainer::getInstance()->getTimeMS(); 63 | 64 | //if (!useMouse) { 65 | //float ax = SDL_GameControllerGetAxis(sdlGL.accelerometer, SDL_CONTROLLER_AXIS_LEFTX); 66 | //float ay = SDL_GameControllerGetAxis(sdlGL.accelerometer, SDL_CONTROLLER_AXIS_LEFTY); 67 | //CAppContainer::getInstance()->UpdateAccelerometer((ax* (1.0f / 32767))/2, (ay* (1.0f / 32767))/2, 0.f, false); 68 | //} 69 | 70 | if (currentTimeMillis > UpTime) { 71 | input.handleEvents(); 72 | UpTime = currentTimeMillis + 15; 73 | drawView(&sdlGL); 74 | input.consumeEvents(); 75 | } 76 | } 77 | 78 | printf("APP_QUIT\n"); 79 | CAppContainer::getInstance()->~CAppContainer(); 80 | zipFile.closeZipFile(); 81 | sdlGL.~SDLGL(); 82 | input.~Input(); 83 | return 0; 84 | } 85 | 86 | 87 | static uint32_t lastTimems = 0; 88 | 89 | void drawView(SDLGL *sdlGL) { 90 | 91 | int cx, cy; 92 | int w = sdlGL->vidWidth; 93 | int h = sdlGL->vidHeight; 94 | 95 | if (lastTimems == 0) { 96 | lastTimems = CAppContainer::getInstance()->getTimeMS(); 97 | } 98 | 99 | SDL_GetWindowSize(sdlGL->window, &cx, &cy); 100 | if (w != cx || h != cy) { 101 | w = cx; h = cy; 102 | } 103 | 104 | glViewport(0, 0, (GLsizei)w, (GLsizei)h); 105 | glDisable(GL_DEPTH_TEST); 106 | glDisable(GL_ALPHA_TEST); 107 | glMatrixMode(GL_PROJECTION); 108 | glLoadIdentity(); 109 | glOrtho(0.0, Applet::IOS_WIDTH, Applet::IOS_HEIGHT, 0.0, -1.0, 1.0); 110 | //glRotatef(90.0, 0.0, 0.0, 1.0); 111 | //glTranslatef(0.0, -320.0, 0.0); 112 | glMatrixMode(GL_MODELVIEW); 113 | glLoadIdentity(); 114 | glClearColor(0.0, 0.0, 0.0, 1.0); 115 | glClear(GL_COLOR_BUFFER_BIT); 116 | 117 | 118 | uint32_t startTime = CAppContainer::getInstance()->getTimeMS(); 119 | uint32_t passedTime = startTime - lastTimems; 120 | lastTimems = startTime; 121 | 122 | if (passedTime >= 125) { 123 | passedTime = 125; 124 | } 125 | //printf("passedTime %d\n", passedTime); 126 | 127 | CAppContainer::getInstance()->DoLoop(passedTime); 128 | 129 | SDL_GL_SwapWindow(sdlGL->window); // Swap the window/pBmp to display the result. 130 | 131 | } -------------------------------------------------------------------------------- /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/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->wrapText(app->canvas->menuHelpMaxChars, 0xc, '\n'); 34 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /src/MenuSystem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/DoomIIRPG-RE/4ecf14341c9eeadb08acdede82813e660bc3b0a2/src/MenuSystem.cpp -------------------------------------------------------------------------------- /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 = 0x619; 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/Player.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAYER_H__ 2 | #define __PLAYER_H__ 3 | 4 | #include "Entity.h" 5 | #include "EntityDef.h" 6 | #include "CombatEntity.h" 7 | 8 | class Entity; 9 | class EntityDef; 10 | class CombatEntity; 11 | class Text; 12 | class InputStream; 13 | class OutputStream; 14 | class Graphics; 15 | class ScriptThread; 16 | 17 | class Player 18 | { 19 | private: 20 | 21 | public: 22 | static constexpr int EXPIRE_DURATION = 5; 23 | static constexpr int MAX_DISPLAY_BUFFS = 6; 24 | static constexpr int ICE_FOG_DIST = 1024; 25 | static constexpr int MAX_NOTEBOOK_INDEXES = 8; 26 | static constexpr int NUMBER_OF_TARGET_PRACTICE_SHOTS = 8; 27 | static constexpr int HEAD_SHOT_POINTS = 30; 28 | static constexpr int BODY_SHOT_POINTS = 20; 29 | static constexpr int LEG_SHOT_POINTS = 10; 30 | static constexpr int NUMBER_OF_BITS_PER_VM_TRY = 3; 31 | static constexpr int BUFF_TURNS = 0; 32 | static constexpr int BUFF_AMOUNT = 15; 33 | static constexpr int DEF_STATUS_TURNS = 30; 34 | static constexpr int ANTI_FIRE_TURNS = 10; 35 | static constexpr int AGILITY_TURNS = 20; 36 | static constexpr int PURIFY_TURNS = 10; 37 | static constexpr int FEAR_TURNS = 6; 38 | static constexpr int COLD_TURNS = 5; 39 | static constexpr int BOX_X1 = 17; 40 | static constexpr int BOX_X2 = 31; 41 | static constexpr int BOX_X3 = 43; 42 | static constexpr int BOX_X4 = 55; 43 | 44 | Entity* facingEntity; 45 | short inventory[26]; 46 | short ammo[9]; 47 | int weapons; 48 | short inventoryCopy[26]; 49 | short ammoCopy[9]; 50 | int weaponsCopy; 51 | int goldCopy; 52 | int currentWeaponCopy; 53 | bool tookBotsInventory; 54 | bool botReturnedDueToMonster; 55 | bool unsetFamiliarOnceOutOfCinematic; 56 | int disabledWeapons; 57 | int level; 58 | int currentXP; 59 | int nextLevelXP; 60 | CombatEntity* baseCe; 61 | CombatEntity* ce; 62 | EntityDef* activeWeaponDef; 63 | bool noclip; 64 | bool god; 65 | short characterChoice; 66 | bool isFamiliar; 67 | short familiarType; 68 | bool attemptingToSelfDestructFamiliar; 69 | int chainsawStrengthBonusCount; 70 | uint8_t lastSkipCode; 71 | bool inTargetPractice; 72 | int targetPracticeScore; 73 | int playTime; 74 | int totalTime; 75 | int moves; 76 | int totalMoves; 77 | int completedLevels; 78 | int killedMonstersLevels; 79 | int foundSecretsLevels; 80 | int xpGained; 81 | int currentLevelDeaths; 82 | int totalDeaths; 83 | int currentGrades; 84 | int bestGrades; 85 | short notebookIndexes[Player::MAX_NOTEBOOK_INDEXES]; 86 | short notebookPositions[Player::MAX_NOTEBOOK_INDEXES]; 87 | uint8_t questComplete; 88 | uint8_t questFailed; 89 | int hackedVendingMachines; 90 | int vendingMachineHackTriesLeft1; 91 | int vendingMachineHackTriesLeft2; 92 | int numNotebookIndexes; 93 | int helpBitmask; 94 | int invHelpBitmask; 95 | int ammoHelpBitmask; 96 | int weaponHelpBitmask; 97 | int armorHelpBitmask; 98 | int gamePlayedMask; 99 | int lastCombatTurn; 100 | bool inCombat; 101 | bool enableHelp; 102 | int turnTime; 103 | int highestMap; 104 | int prevWeapon; 105 | bool noDeathFlag; 106 | bool noFamiliarRemains; 107 | int numStatusEffects; 108 | int numStatusEffectsCopy; 109 | int statusEffects[54]; 110 | int statusEffectsCopy[54]; 111 | short buffs[30]; 112 | short buffsCopy[30]; 113 | int numbuffs; 114 | int numbuffsCopy; 115 | bool gameCompleted; 116 | int playerEntityCopyIndex; 117 | int counters[8]; 118 | int monsterStats[2]; 119 | 120 | // Constructor 121 | Player(); 122 | // Destructor 123 | ~Player(); 124 | 125 | bool startup(); 126 | bool modifyCollision(Entity* entity); 127 | void advanceTurn(); 128 | void levelInit(); 129 | void fillMonsterStats(); 130 | void readyWeapon(); 131 | void selectWeapon(int i); 132 | void selectPrevWeapon(); 133 | void selectNextWeapon(); 134 | int getHealth(); 135 | int modifyStat(int n, int n2); 136 | bool requireStat(int n, int n2); 137 | bool requireItem(int n, int n2, int n3, int n4); 138 | void addXP(int xp); 139 | void addLevel(); 140 | int calcLevelXP(int n); 141 | int calcScore(); 142 | bool addHealth(int i); 143 | bool addHealth(int i, bool b); 144 | void setStatsAccordingToCharacterChoice(); 145 | void reset(); 146 | int calcDamageDir(int x1, int y1, int angle, int x2, int y2); 147 | void painEvent(Entity* entity, bool b); 148 | void pain(int n, Entity* entity, bool b); 149 | void died(); 150 | void familiarDying(bool familiarSelfDestructed); 151 | bool fireWeapon(Entity* entity, int n, int n2); 152 | bool useItem(int n); 153 | bool give(int n, int n2, int n3); 154 | bool give(int n, int n2, int n3, bool b); 155 | bool give(int n, int n2, int n3, bool b, bool b2); 156 | void giveAmmoWeapon(int n, bool b); 157 | void updateQuests(short n, int n2); 158 | void setQuestTile(int n, int n2, int n3); 159 | bool isQuestDone(int n); 160 | bool isQuestFailed(int n); 161 | void formatTime(int n, Text* text); 162 | void showInvHelp(int n, bool b); 163 | void showAmmoHelp(int n, bool b); 164 | bool showHelp(short n, bool b); 165 | void showWeaponHelp(int n, bool b); 166 | void drawBuffs(Graphics* graphics); 167 | void setCharacterChoice(short i); 168 | bool loadState(InputStream* IS); 169 | bool saveState(OutputStream* OS); 170 | void unpause(int n); 171 | void relink(); 172 | void unlink(); 173 | void link(); 174 | void updateStats(); 175 | void updateStatusEffects(); 176 | void translateStatusEffects(); 177 | void removeStatusEffect(int n); 178 | bool addStatusEffect(int n, int n2, int n3); 179 | void drawStatusEffectIcon(Graphics* graphics, int n, int n2, int n3, int n4, int n5); 180 | void resetCounters(); 181 | Entity* getPlayerEnt(); 182 | void setPickUpWeapon(int n); 183 | void giveAll(); 184 | void equipForLevel(int highestMap); 185 | bool addArmor(int n); 186 | int distFrom(Entity* entity); 187 | void showAchievementMessage(int n); 188 | short gradeToString(int n); 189 | int levelGrade(bool b); 190 | int finalCurrentGrade(); 191 | int finalBestGrade(); 192 | int getCurrentGrade(int n); 193 | void setCurrentGrade(int n, int n2); 194 | int getBestGrade(int n); 195 | void setBestGrade(int n, int n2); 196 | bool hasPurifyEffect(); 197 | void setFamiliar(short familiarType); 198 | short unsetFamiliar(bool b); 199 | void clearOutFamiliarsStatusEffects(); 200 | void swapStatusEffects(); 201 | void familiarDied(); 202 | void explodeFamiliar(int n, int n2, int n3); 203 | void familiarReturnsToPlayer(bool b); 204 | bool stealFamiliarsInventory(); 205 | void handleBotRemains(int n, int n2, int n3); 206 | void forceFamiliarReturnDueToMonster(); 207 | void attemptToDeploySentryBot(); 208 | void attemptToDiscardFamiliar(int n); 209 | void startSelfDestructDialog(); 210 | bool vendingMachineIsHacked(int n); 211 | void setVendingMachineHack(int n); 212 | int getVendingMachineTriesLeft(int max); 213 | void removeOneVendingMachineTry(int max); 214 | bool weaponIsASentryBot(int n); 215 | bool hasASentryBot(); 216 | void setFamiliarType(short familiarType); 217 | void calcViewMode(); 218 | void enterTargetPractice(int n, int n2, int n3, ScriptThread* targetPracticeThread); 219 | void assessTargetPracticeShot(Entity* entity); 220 | void exitTargetPractice(); 221 | void usedChainsaw(bool b); 222 | bool hasANanoDrink(); 223 | void stripInventoryForViosBattle(); 224 | void stripInventoryForTargetPractice(); 225 | void restoreInventory(); 226 | void forceRemoveFromScopeZoom(); 227 | }; 228 | 229 | #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" }; 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_MAP_FILE_ARRAY[] = { "map00.bin" , "map01.bin", "map02.bin", "map03.bin", "map04.bin", "map05.bin", "map06.bin", "map07.bin", "map08.bin", "map09.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[20]; 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 | int 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 -------------------------------------------------------------------------------- /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 | initialized = false; 31 | } 32 | 33 | SDLGL::~SDLGL() { 34 | if (this) { 35 | if (initialized) { 36 | if (this->window) { 37 | SDL_SetWindowFullscreen(this->window, 0); 38 | } 39 | SDL_GL_DeleteContext(glcontext); 40 | SDL_DestroyWindow(window); 41 | SDL_Quit(); 42 | } 43 | } 44 | } 45 | 46 | bool SDLGL::Initialize() { 47 | Uint32 flags; 48 | 49 | if (!this->initialized) { 50 | 51 | SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); 52 | if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { 53 | printf("Could not initialize SDL: %s", SDL_GetError()); 54 | } 55 | 56 | flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN /* | SDL_WINDOW_RESIZABLE*/; 57 | // Set the highdpi flags - this makes a big difference on Macs with 58 | // retina displays, especially when using small window sizes. 59 | flags |= SDL_WINDOW_ALLOW_HIGHDPI; 60 | 61 | this->oldResolutionIndex = -1; 62 | this->resolutionIndex = 0; 63 | this->winVidWidth = sdlResVideoModes[this->resolutionIndex].width;//Applet::IOS_WIDTH*2; 64 | this->winVidHeight = sdlResVideoModes[this->resolutionIndex].height;//Applet::IOS_HEIGHT*2; 65 | 66 | //this->winVidWidth = 1440; 67 | //this->winVidHeight = 900; 68 | 69 | this->window = SDL_CreateWindow("Doom II RPG By [GEC] Version 0.1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, winVidWidth, winVidHeight, flags); 70 | if (!this->window) { 71 | printf("Could not set %dx%d video mode: %s", winVidWidth, winVidHeight, SDL_GetError()); 72 | } 73 | 74 | this->vidWidth = Applet::IOS_WIDTH; 75 | this->vidHeight = Applet::IOS_HEIGHT; 76 | this->oldWindowMode = -1; 77 | this->windowMode = 0; 78 | this->oldVSync = false; 79 | this->vSync = true; 80 | 81 | //SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2"); 82 | //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); 83 | //SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");//sdlVideo.vSync ? "1" : "0"); 84 | this->updateVideo(); 85 | 86 | this->glcontext = SDL_GL_CreateContext(window); 87 | 88 | // now you can make GL calls. 89 | glClearColor(0, 0, 0, 1); 90 | glClear(GL_COLOR_BUFFER_BIT); 91 | 92 | SDL_GL_SwapWindow(this->window); 93 | 94 | // Check for joysticks 95 | SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); 96 | this->initialized = true; 97 | } 98 | 99 | return this->initialized; 100 | } 101 | 102 | 103 | #include //va_list|va_start|va_end 104 | 105 | void SDLGL::Error(const char* fmt, ...) 106 | { 107 | char errMsg[256]; 108 | va_list ap; 109 | va_start(ap, fmt); 110 | #ifdef _WIN32 111 | vsprintf_s(errMsg, sizeof(errMsg), fmt, ap); 112 | #else 113 | vsnprintf(errMsg, sizeof(errMsg), fmt, ap); 114 | #endif 115 | va_end(ap); 116 | 117 | printf("%s", errMsg); 118 | 119 | const SDL_MessageBoxButtonData buttons[] = { 120 | { /* .flags, .buttonid, .text */ 0, 0, "Ok" }, 121 | }; 122 | const SDL_MessageBoxColorScheme colorScheme = { 123 | { /* .colors (.r, .g, .b) */ 124 | /* [SDL_MESSAGEBOX_COLOR_BACKGROUND] */ 125 | { 255, 0, 0 }, 126 | /* [SDL_MESSAGEBOX_COLOR_TEXT] */ 127 | { 0, 255, 0 }, 128 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER] */ 129 | { 255, 255, 0 }, 130 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND] */ 131 | { 0, 0, 255 }, 132 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED] */ 133 | { 255, 0, 255 } 134 | } 135 | }; 136 | const SDL_MessageBoxData messageboxdata = { 137 | SDL_MESSAGEBOX_ERROR, /* .flags */ 138 | NULL, /* .window */ 139 | "Doom II RPG Error", /* .title */ 140 | errMsg, /* .message */ 141 | SDL_arraysize(buttons), /* .numbuttons */ 142 | buttons, /* .buttons */ 143 | &colorScheme /* .colorScheme */ 144 | }; 145 | 146 | SDL_ShowMessageBox(&messageboxdata, NULL); 147 | //closeZipFile(&zipFile); 148 | //DoomRPG_FreeAppData(doomRpg); 149 | //SDL_CloseAudio(); 150 | //SDL_Close(); 151 | SDLGL::~SDLGL(); 152 | exit(0); 153 | } 154 | 155 | 156 | void SDLGL::transformCoord2f(float* x, float* y) { 157 | int w, h; 158 | SDL_GetWindowSize(this->window, &w, &h); 159 | *x *= (float)w / (float)Applet::IOS_WIDTH; 160 | *y *= (float)h / (float)Applet::IOS_HEIGHT; 161 | } 162 | 163 | void SDLGL::centerMouse(int x, int y) { 164 | float X = (float)((Applet::IOS_WIDTH / 2) + x); 165 | float Y = (float)((Applet::IOS_HEIGHT / 2) + y); 166 | this->transformCoord2f(&X, &Y); 167 | SDL_WarpMouseInWindow(this->window, (int)X, (int)Y); 168 | } 169 | 170 | void SDLGL::updateWinVid(int w, int h) { 171 | this->winVidWidth = w; 172 | this->winVidHeight = h; 173 | } 174 | 175 | void SDLGL::updateVideo() { 176 | if (this->vSync != this->oldVSync) { 177 | SDL_GL_SetSwapInterval(this->vSync ? SDL_TRUE : SDL_FALSE); 178 | this->oldVSync = this->vSync; 179 | } 180 | 181 | if (this->windowMode != this->oldWindowMode) { 182 | SDL_SetWindowFullscreen(this->window, 0); 183 | SDL_SetWindowBordered(this->window, SDL_TRUE); 184 | 185 | if (this->windowMode == 1) { 186 | SDL_SetWindowBordered(this->window, SDL_FALSE); 187 | } 188 | else if (this->windowMode == 2) { 189 | SDL_SetWindowFullscreen(this->window, SDL_WINDOW_FULLSCREEN); 190 | } 191 | this->oldWindowMode = this->windowMode; 192 | } 193 | 194 | if (this->resolutionIndex != this->oldResolutionIndex) { 195 | SDL_SetWindowSize(this->window, sdlResVideoModes[this->resolutionIndex].width, sdlResVideoModes[this->resolutionIndex].height); 196 | SDL_SetWindowPosition(this->window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); 197 | this->updateWinVid(sdlResVideoModes[this->resolutionIndex].width, sdlResVideoModes[this->resolutionIndex].height); 198 | this->oldResolutionIndex = this->resolutionIndex; 199 | } 200 | 201 | int winVidWidth, winVidHeight; 202 | SDL_GetWindowSize(this->window, &winVidWidth, &winVidHeight); 203 | this->updateWinVid(winVidWidth, winVidHeight); 204 | } 205 | 206 | void SDLGL::restore() { 207 | if (this->vSync != this->oldVSync) { 208 | this->vSync = this->oldVSync; 209 | } 210 | 211 | if (this->windowMode != this->oldWindowMode) { 212 | this->windowMode = this->oldWindowMode; 213 | } 214 | 215 | if (this->resolutionIndex != this->oldResolutionIndex) { 216 | this->resolutionIndex = this->oldResolutionIndex; 217 | } 218 | } -------------------------------------------------------------------------------- /src/SDLGL.h: -------------------------------------------------------------------------------- 1 | #ifndef __SDLGL_H__ 2 | #define __SDLGL_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | typedef struct SDLResVidModes_s { 10 | int width, height; 11 | } SDLResVidModes; 12 | extern SDLResVidModes sdlResVideoModes[18]; 13 | 14 | class SDLGL 15 | { 16 | private: 17 | bool initialized; 18 | SDL_GLContext glcontext; 19 | 20 | public: 21 | SDL_Window* window; 22 | int resolutionIndex; 23 | int oldResolutionIndex; 24 | int winVidWidth, winVidHeight; 25 | int vidWidth, vidHeight; 26 | int windowMode, oldWindowMode; 27 | bool vSync, oldVSync; 28 | 29 | SDLGL(); 30 | // Destructor 31 | ~SDLGL(); 32 | bool Initialize(); 33 | void Error(const char* fmt, ...); 34 | 35 | void transformCoord2f(float* x, float* y); 36 | void centerMouse(int x, int y); 37 | void updateWinVid(int w, int h); 38 | void updateVideo(); 39 | void restore(); 40 | }; 41 | 42 | #endif -------------------------------------------------------------------------------- /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 n, int goalParam); 59 | void corpsifyMonster(int x, int y, Entity* entity, bool b); 60 | }; 61 | 62 | #endif -------------------------------------------------------------------------------- /src/SentryBotGame.h: -------------------------------------------------------------------------------- 1 | #ifndef __SENTRYBOTGAME_H__ 2 | #define __SENTRYBOTGAME_H__ 3 | 4 | class ScriptThread; 5 | class Image; 6 | class fmButtonContainer; 7 | class Graphics; 8 | 9 | class SentryBotGame 10 | { 11 | private: 12 | static bool wasTouched; 13 | 14 | public: 15 | int touchMe; 16 | ScriptThread* callingThread; 17 | Image* imgHelpScreenAssets; 18 | Image* imgGameAssets; 19 | Image* imgMatrixSkip_BG; 20 | Image* imgButton; 21 | Image* imgButton2; 22 | Image* imgButton3; 23 | uint32_t skipCode; 24 | int gameBoard[16]; 25 | int solution[4]; 26 | int usersGuess[4]; 27 | int player_cursor; 28 | int answer_cursor; 29 | int bot_selection_cursor; 30 | int* stateVars; 31 | short botType; 32 | int timeSinceLastCursorMove; 33 | bool failedEarly; 34 | bool gamePlayedFromMainMenu; 35 | fmButtonContainer* m_sentryBotButtons; 36 | Image* imgSubmit; 37 | Image* imgUnk1; 38 | Image* imgDelete; 39 | bool touched; 40 | int currentPress_x; 41 | int currentPress_y; 42 | 43 | // Constructor 44 | SentryBotGame(); 45 | // Destructor 46 | ~SentryBotGame(); 47 | 48 | void playFromMainMenu(); 49 | void setupGlobalData(); 50 | void initGame(ScriptThread* scriptThread, short botType); 51 | void handleInput(int action); 52 | void updateGame(Graphics* graphics); 53 | void drawFailureScreen(Graphics* graphics); 54 | void drawSuccessScreen(Graphics* graphics); 55 | void drawHelpScreen(Graphics* graphics); 56 | void drawGameScreen(Graphics* graphics); 57 | 58 | void drawPlayersGuess(int n, int n2, bool b, Text* text, Graphics* graphics); 59 | void drawCursor(int n, int n2, bool b, Graphics* graphics); 60 | bool playerHasWon(); 61 | bool playerCouldStillWin(); 62 | void forceWin(); 63 | void awardSentryBot(int n); 64 | void endGame(int n); 65 | void touchStart(int pressX, int pressY); 66 | void touchMove(int pressX, int pressY); 67 | void touchEnd(int pressX, int pressY); 68 | void handleTouchForHelpScreen(int pressX, int pressY); 69 | void handleTouchForGame(int pressX, int pressY); 70 | }; 71 | 72 | #endif -------------------------------------------------------------------------------- /src/Sound.h: -------------------------------------------------------------------------------- 1 | #ifndef __SOUND_H__ 2 | #define __SOUND_H__ 3 | #include 4 | #include 5 | 6 | typedef uint32_t AudioFormatID; 7 | typedef uint32_t AudioFormatFlags; 8 | typedef uint32_t AudioFileID; 9 | struct AudioStreamBasicDescription 10 | { 11 | uint32_t mSampleRate; 12 | AudioFormatID mFormatID; 13 | AudioFormatFlags mFormatFlags; 14 | uint32_t mBytesPerPacket; 15 | uint32_t mFramesPerPacket; 16 | uint32_t mBytesPerFrame; 17 | uint32_t mChannelsPerFrame; 18 | uint32_t mBitsPerChannel; 19 | uint32_t mReserved; 20 | }; 21 | 22 | class Applet; 23 | 24 | 25 | class Sound 26 | { 27 | private: 28 | 29 | public: 30 | 31 | class SoundStream 32 | { 33 | public: 34 | ALuint bufferId; 35 | ALuint sourceId; 36 | int16_t resID; 37 | int16_t priority; 38 | bool fadeInProgress; 39 | uint8_t field_0xd; 40 | uint8_t field_0xe; 41 | uint8_t field_0xf; 42 | int volume; 43 | int fadeBeg; 44 | int fadetime; 45 | float fadeVolume; 46 | 47 | void StartFade(int volume, int fadeBeg, int fadeEnd); 48 | }; 49 | 50 | Applet* app; 51 | bool field_0x4; 52 | bool allowSounds; 53 | bool allowMusics; 54 | int soundFxVolume; 55 | int musicVolume; 56 | int field_0x10; 57 | SoundStream channel[10]; 58 | short resID; 59 | uint8_t flags; 60 | int priority; 61 | int field_0x15c; 62 | short field_0x160; 63 | uint8_t field_0x162; 64 | bool soundsLoaded; 65 | ALCcontext* alContext; 66 | ALCdevice* alDevice; 67 | 68 | // Constructor 69 | Sound(); 70 | // Destructor 71 | ~Sound(); 72 | 73 | bool startup(); 74 | void openAL_Init(); 75 | void openAL_Close(); 76 | void openAL_SetSystemVolume(int volume); 77 | void openAL_SetVolume(ALuint source, int volume); 78 | void openAL_Suspend(); 79 | void openAL_Resume(); 80 | bool openAL_IsPlaying(ALuint source); 81 | bool openAL_IsPaused(ALuint source); 82 | bool openAL_GetALFormat(AudioStreamBasicDescription aStreamBD, ALenum* format); 83 | void openAL_PlaySound(ALuint source, ALint loop); 84 | void openAL_LoadSound(int resID, Sound::SoundStream* channel); 85 | bool openAL_LoadWAVFromFile(ALuint bufferId, const char* fileName); 86 | bool openAL_LoadAudioFileData(const char* fileName, ALenum* format, ALvoid** data, ALsizei* size, ALsizei* freq); 87 | bool openAL_OpenAudioFile(const char* fileName, InputStream* IS); 88 | bool openAL_LoadAllSounds(); 89 | 90 | bool cacheSounds(); 91 | void playSound(int16_t resID, uint8_t flags, int priority, bool a5); 92 | int getFreeSlot(int a2); 93 | void soundStop(); 94 | void stopSound(int resID, bool fadeOut); 95 | bool isSoundPlaying(int16_t resID); 96 | void updateVolume(); 97 | void playCombatSound(int16_t resID, uint8_t flags, int priority); 98 | bool cacheCombatSound(int resID); 99 | void freeMonsterSounds(); 100 | 101 | void volumeUp(int volume); 102 | void volumeDown(int volume); 103 | void startFrame(); 104 | void endFrame(); 105 | void musicVolumeUp(int volume); // [GEC] 106 | void musicVolumeDown(int volume); // [GEC] 107 | }; 108 | 109 | #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 | "Arachnotron_active.wav", //0 9 | "Arachnotron_death.wav", 10 | "Arachnotron_sight.wav", 11 | "Arachnotron_walk.wav", 12 | "Archvile_active.wav", 13 | "Archvile_attack.wav", 14 | "Archvile_death.wav", 15 | "Archvile_pain.wav", 16 | "Archvile_sight.wav", 17 | "BFG.wav", 18 | "block_drop.wav", // 10 19 | "block_pick.wav", 20 | "Cacodemon_death.wav", 21 | "Cacodemon_sight.wav", 22 | "chaingun.wav", 23 | "chainsaw.wav", 24 | "ChainsawGoblin_attack.wav", 25 | "ChainsawGoblin_death.wav", 26 | "ChainsawGoblin_pain.wav", 27 | "ChainsawGoblin_sight.wav", 28 | "chime.wav", // 20 29 | "claw.wav", 30 | "Cyberdemon_death.wav", 31 | "Cyberdemon_sight.wav", 32 | "demon_active.wav", 33 | "demon_pain.wav", 34 | "demon_small_active.wav", 35 | "Dialog_Help.wav", 36 | "door_close.wav", 37 | "door_close_slow.wav", 38 | "door_open.wav", // 30 39 | "door_open_slow.wav", 40 | "explosion.wav", 41 | "fireball.wav", 42 | "fireball_impact.wav", 43 | "footstep1.wav", 44 | "footstep2.wav", 45 | "gib.wav", 46 | "glass.wav", 47 | "hack_clear.wav", 48 | "hack_fail.wav", // 40 49 | "hack_failed.wav", 50 | "hack_submit.wav", 51 | "hack_success.wav", 52 | "hack_successful.wav", 53 | "HolyWaterPistol.wav", 54 | "HolyWaterPistol_refill.wav", 55 | "hoof.wav", 56 | "impClaw.wav", 57 | "Imp_active.wav", 58 | "Imp_death1.wav", // 50 59 | "Imp_death2.wav", 60 | "Imp_sight1.wav", 61 | "Imp_sight2.wav", 62 | "item_pickup.wav", 63 | "loot.wav", 64 | "LostSoul_attack.wav", 65 | "Maglev_arrive.wav", 66 | "Maglev_depart.wav", 67 | "malfunction.wav", 68 | "Mancubus_attack.wav", // 60 69 | "Mancubus_death.wav", 70 | "Mancubus_pain.wav", 71 | "Mancubus_sight.wav", 72 | "menu_open.wav", 73 | "menu_scroll.wav", 74 | "monster_pain.wav", 75 | "Music_Boss.wav", 76 | "Music_General.wav", 77 | "Music_Level_End.wav", 78 | "Music_LevelUp.wav", // 70 79 | "Music_Title.wav", 80 | "no_use.wav", 81 | "no_use2.wav", 82 | "Pinkinator_attack.wav", 83 | "Pinkinator_death.wav", 84 | "Pinkinator_pain.wav", 85 | "Pinkinator_sight.wav", 86 | "Pinkinator_spawn.wav", 87 | "Pinky_attack.wav", 88 | "Pinky_death.wav", // 80 89 | "Pinky_sight.wav", 90 | "Pinky_small_attack.wav", 91 | "Pinky_small_death.wav", 92 | "Pinky_small_pain.wav", 93 | "Pinky_small_sight.wav", 94 | "pistol.wav", 95 | "plasma.wav", 96 | "platform_start.wav", 97 | "platform_stop.wav", 98 | "player_death1.wav", // 90 99 | "player_death2.wav", 100 | "player_death3.wav", 101 | "player_pain1.wav", 102 | "player_pain2.wav", 103 | "Revenant_active.wav", 104 | "Revenant_attack.wav", 105 | "Revenant_death.wav", 106 | "Revenant_punch.wav", 107 | "Revenant_sight.wav", 108 | "Revenant_swing.wav", // 100 109 | "rocketLauncher.wav", 110 | "rocket_explode.wav", 111 | "secret.wav", 112 | "Sentinel_attack.wav", 113 | "Sentinel_death.wav", 114 | "Sentinel_pain.wav", 115 | "Sentinel_sight.wav", 116 | "SentryBot_activate.wav", 117 | "SentryBot_death.wav", 118 | "SentryBot_discard.wav", // 110 119 | "SentryBot_pain.wav", 120 | "SentryBot_return.wav", 121 | "slider.wav", 122 | "Soulcube.wav", 123 | "SpiderMastermind_death.wav", 124 | "SpiderMastermind_sight.wav", 125 | "supershotgun.wav", 126 | "supershotgun_close.wav", 127 | "supershotgun_load.wav", 128 | "supershotgun_open.wav", // 120 129 | "switch.wav", 130 | "switch_exit.wav", 131 | "teleport.wav", 132 | "use_item.wav", 133 | "vending_sale.wav", 134 | "vent.wav", 135 | "VIOS_attack1.wav", 136 | "VIOS_attack2.wav", 137 | "VIOS_death.wav", 138 | "VIOS_pain.wav", // 130 139 | "VIOS_sight.wav", 140 | "weapon_pickup.wav", 141 | "Weapon_Sniper_Scope.wav", 142 | "Weapon_Toilet_Pull.wav", 143 | "Weapon_Toilet_Smash.wav", 144 | "Weapon_Toilet_Throw.wav", 145 | "Weapon_Toilet_Throw2.wav", 146 | "zombie_active.wav", 147 | "zombie_death1.wav", 148 | "zombie_death2.wav", // 140 149 | "zombie_death3.wav", 150 | "zombie_sight1.wav", 151 | "zombie_sight2.wav", 152 | "zombie_sight3.wav" 153 | }; 154 | }; 155 | 156 | #endif 157 | 158 | 159 | -------------------------------------------------------------------------------- /src/Span.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPAN_H__ 2 | #define __SPAN_H__ 3 | #include 4 | #include 5 | 6 | class TinyGL; 7 | 8 | typedef void (*SpanFunc)(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 9 | typedef void (*SpanFuncStretch)(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 10 | 11 | typedef struct _SpanMode { 12 | SpanFunc Normal; 13 | SpanFunc DT; 14 | SpanFunc DS; 15 | SpanFuncStretch Stretch; 16 | }SpanMode; 17 | 18 | typedef struct _SpanType { 19 | SpanMode* Span; 20 | }SpanType; 21 | 22 | 23 | extern void spanNoDraw(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 24 | extern void spanNoDrawStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 25 | 26 | extern void spanTransparent(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 27 | extern void spanTransparentDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 28 | extern void spanTransparentDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 29 | extern void spanTransparentStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 30 | 31 | extern void spanBlend50Transparent(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 32 | extern void spanBlend50TransparentDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 33 | extern void spanBlend50TransparentDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 34 | extern void spanBlend50TransparentStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 35 | 36 | extern void spanAddTransparent(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 37 | extern void spanAddTransparentDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 38 | extern void spanAddTransparentDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 39 | extern void spanAddTransparentStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 40 | 41 | extern void spanSubTransparent(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 42 | extern void spanSubTransparentDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 43 | extern void spanSubTransparentDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 44 | extern void spanSubTransparentStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 45 | 46 | extern void spanPerfTexture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 47 | extern void spanPerfTextureStretch(uint16_t*, int32_t, int32_t, int32_t, int32_t, TinyGL*); 48 | 49 | extern void spanTexture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 50 | extern void spanTextureDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 51 | extern void spanTextureDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 52 | 53 | extern void spanBlend25Texture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 54 | extern void spanBlend25TextureDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 55 | extern void spanBlend25TextureDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 56 | 57 | extern void spanAddTexture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 58 | extern void spanAddTextureDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 59 | extern void spanAddTextureDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 60 | 61 | extern void spanSubTexture(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 62 | extern void spanSubTextureDT(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 63 | extern void spanSubTextureDS(uint16_t*, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, TinyGL*); 64 | 65 | 66 | 67 | #endif -------------------------------------------------------------------------------- /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/TGLEdge.h: -------------------------------------------------------------------------------- 1 | #ifndef __TGLEDGE_H__ 2 | #define __TGLEDGE_H__ 3 | 4 | #include 5 | 6 | class TGLVert; 7 | 8 | class TGLEdge 9 | { 10 | private: 11 | 12 | static constexpr int SCREEN_SHIFT = 3; 13 | static constexpr int SCREEN_ONE = 8; 14 | static constexpr int SCREEN_PRESTEP = 7; 15 | static constexpr int INTERPOLATE_SHIFT = 16; 16 | static constexpr int INTERPOLATE_TO_PIXELS_SHIFT = 19; 17 | static constexpr int INTERPOLATE_PRESTEP = 524287; 18 | 19 | public: 20 | int stopY; 21 | int fracX; 22 | int fracZ; 23 | int fracS; 24 | int fracT; 25 | int stepX; 26 | int stepZ; 27 | int stepS; 28 | int stepT; 29 | 30 | // Constructor 31 | TGLEdge(); 32 | // Destructor 33 | ~TGLEdge(); 34 | 35 | bool startup(); 36 | void setFromVerts(TGLVert* tglVert, TGLVert* tglVert2); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /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/Text.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/DoomIIRPG-RE/4ecf14341c9eeadb08acdede82813e660bc3b0a2/src/Text.h -------------------------------------------------------------------------------- /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/Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILS_H__ 2 | #define __UTILS_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "Image.h" 8 | 9 | /* 10 | typedef unsigned char uint8_t; 11 | typedef unsigned long DWORD_PTR; 12 | #define BYTE uint8_t 13 | #define WORD uint16_t 14 | #define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff)) 15 | #define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff)) 16 | #define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff)) 17 | #define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff)) 18 | #define BYTEn(x, n) (*((BYTE*)&(x)+n)) 19 | #define WORDn(x, n) (*((WORD*)&(x)+n)) 20 | #define BYTE0(x) BYTEn(x, 0) // byte 0 (counting from 0) 21 | #define BYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0) 22 | #define BYTE2(x) BYTEn(x, 2) 23 | #define BYTE3(x) BYTEn(x, 3) 24 | #define BYTE4(x) BYTEn(x, 4) 25 | #define WORD1(x) WORDn(x, 1) 26 | #define WORD2(x) WORDn(x, 2) // third word of the object, unsigned 27 | #define WORD3(x) WORDn(x, 3) 28 | #define WORD4(x) WORDn(x, 4) 29 | #define WORD5(x) WORDn(x, 5) 30 | #define WORD6(x) WORDn(x, 6) 31 | #define WORD7(x) WORDn(x, 7) 32 | */ 33 | 34 | 35 | bool getFileMD5Hash(void* data, uint64_t numBytes, uint64_t& hashWord1, uint64_t& hashWord2); 36 | bool checkFileMD5Hash(void* data, uint64_t numBytes, uint64_t checkHashWord1, uint64_t checkHashWord2); 37 | bool pointInRectangle(int x, int y, int rectX, int rectY, int rectW, int rectH); 38 | float AxisHit(int aX, int aY, int x, int y, int w, int h, bool isXaxis, float activeFraction); 39 | void fixImage(Image* img); 40 | void enlargeButtonImage(Image* img); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/VendingMachine.h: -------------------------------------------------------------------------------- 1 | #ifndef __VENDINGMACHINE_H__ 2 | #define __VENDINGMACHINE_H__ 3 | 4 | class ScriptThread; 5 | class Image; 6 | class fmButtonContainer; 7 | class Graphics; 8 | 9 | class VendingMachine 10 | { 11 | private: 12 | 13 | public: 14 | int touchMe; 15 | ScriptThread* callingThread; 16 | int16_t* energyDrinkData; 17 | Image* imgVendingBG; 18 | Image* imgVendingGame; 19 | Image* imgHelpScreenAssets; 20 | Image* imgVending_BG; 21 | Image* imgVending_button_small; 22 | int mainTerminalCursor; 23 | int gameCursor; 24 | int solution[4]; 25 | int sliderPositions[4]; 26 | int playersGuess[4]; 27 | int minimums[4]; 28 | int maximums[4]; 29 | int chevronAnimationOffset[4]; 30 | int correctSum; 31 | int triesLeft; 32 | int currentMapNumber; 33 | int currentMachineNumber; 34 | bool machineHasBeenHacked; 35 | bool machineJustHacked; 36 | int currentItemQuantity; 37 | int currentItemPrice; 38 | int* stateVars; 39 | int widthOfContainingBox; 40 | int iqBonusAwarded; 41 | bool gamePlayedFromMainMenu; 42 | fmButtonContainer* m_vendingButtons; 43 | Image* imgSubmitButton; 44 | Image* imgVending_submit_pressed; 45 | Image* imgVending_arrow_up; 46 | Image* imgVending_arrow_down; 47 | Image* imgVending_arrow_up_pressed; 48 | Image* imgVending_arrow_down_pressed; 49 | bool touched; 50 | int currentPress_x; 51 | int currentPress_y; 52 | int gameCursor2; //[GEC] 53 | 54 | // Constructor 55 | VendingMachine(); 56 | // Destructor 57 | ~VendingMachine(); 58 | 59 | bool startup(); 60 | 61 | void playFromMainMenu(); 62 | void initGame(ScriptThread* callingThread, int a, int a2); 63 | void returnFromBuying(); 64 | bool machineCanBeHacked(); 65 | void randomizeGame(); 66 | void handleInput(int action); 67 | void handleInputForBasicVendingMachine(int action); 68 | void handleInputForHelpScreen(int action); 69 | void handleInputForGame(int action); 70 | void updateHighLowState(); 71 | void updateGame(Graphics* graphics); 72 | void drawGameResults(Graphics* graphics); 73 | void drawMainScreen(Graphics* graphics); 74 | void drawVendingMachineBackground(Graphics* graphics, bool b); 75 | void drawHelpScreen(Graphics* graphics); 76 | void drawGameScreen(Graphics* graphics); 77 | void drawGameTopBar(Graphics* graphics, Text* text); 78 | void drawGameMiddleBar(Graphics* graphics, Text* text); 79 | bool drinkInThisVendingMachine(int n); 80 | short getDrinkPrice(int n); 81 | bool buyDrink(int n); 82 | int getSnackPrice(); 83 | int numbersCorrect(); 84 | bool playerHasWon(); 85 | void forceWin(); 86 | void endGame(int n); 87 | void touchStart(int pressX, int pressY); 88 | void touchMove(int pressX, int pressY); 89 | void touchEnd(int pressX, int pressY); 90 | void handleTouchForHelpScreen(int pressX, int pressY); 91 | void handleTouchForGame(int pressX, int pressY); 92 | void handleTouchForBasicVendingMachine(int pressX, int pressY); 93 | }; 94 | 95 | #endif -------------------------------------------------------------------------------- /src/ZipFile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "ZipFile.h" 6 | #include "SDLGL.h" 7 | 8 | #define MIN(a,b) (((a)<(b))?(a):(b)) 9 | #define MAX(a,b) (((a)>(b))?(a):(b)) 10 | 11 | void Error(const char* fmt, ...) 12 | { 13 | char errMsg[256]; 14 | va_list ap; 15 | va_start(ap, fmt); 16 | #ifdef _WIN32 17 | vsprintf_s(errMsg, sizeof(errMsg), fmt, ap); 18 | #else 19 | vsnprintf(errMsg, sizeof(errMsg), fmt, ap); 20 | #endif 21 | va_end(ap); 22 | 23 | printf("%s", errMsg); 24 | 25 | const SDL_MessageBoxButtonData buttons[] = { 26 | { /* .flags, .buttonid, .text */ 0, 0, "Ok" }, 27 | }; 28 | const SDL_MessageBoxColorScheme colorScheme = { 29 | { /* .colors (.r, .g, .b) */ 30 | /* [SDL_MESSAGEBOX_COLOR_BACKGROUND] */ 31 | { 255, 0, 0 }, 32 | /* [SDL_MESSAGEBOX_COLOR_TEXT] */ 33 | { 0, 255, 0 }, 34 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER] */ 35 | { 255, 255, 0 }, 36 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND] */ 37 | { 0, 0, 255 }, 38 | /* [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED] */ 39 | { 255, 0, 255 } 40 | } 41 | }; 42 | const SDL_MessageBoxData messageboxdata = { 43 | SDL_MESSAGEBOX_ERROR, /* .flags */ 44 | NULL, /* .window */ 45 | "Doom II RPG Error", /* .title */ 46 | errMsg, /* .message */ 47 | SDL_arraysize(buttons), /* .numbuttons */ 48 | buttons, /* .buttons */ 49 | &colorScheme /* .colorScheme */ 50 | }; 51 | 52 | SDL_ShowMessageBox(&messageboxdata, NULL); 53 | exit(0); 54 | } 55 | 56 | static void* zip_alloc(void* ctx, unsigned int items, unsigned int size) 57 | { 58 | return std::malloc(items * size); 59 | } 60 | 61 | static void zip_free(void* ctx, void* ptr) 62 | { 63 | std::free(ptr); 64 | } 65 | 66 | static int16_t _ReadShort(FILE* fp) 67 | { 68 | int16_t sData = 0; 69 | 70 | if (fp) { 71 | fread(&sData, sizeof(int16_t), 1, fp); 72 | } 73 | 74 | return sData; 75 | } 76 | 77 | static int32_t _ReadInt(FILE* fp) 78 | { 79 | int32_t iData = 0; 80 | 81 | if (fp) { 82 | fread(&iData, sizeof(int32_t), 1, fp); 83 | } 84 | 85 | return iData; 86 | } 87 | 88 | ZipFile::ZipFile() { 89 | std::memset(this, 0, sizeof(ZipFile)); 90 | } 91 | 92 | ZipFile::~ZipFile() { 93 | } 94 | 95 | void ZipFile::findAndReadZipDir(int startoffset) { 96 | int sig, offset, count; 97 | int namesize, metasize, commentsize; 98 | int i; 99 | 100 | fseek(this->file, startoffset, SEEK_SET); 101 | 102 | sig = _ReadInt(this->file); 103 | if (sig != ZIP_END_OF_CENTRAL_DIRECTORY_SIG) { 104 | Error("wrong zip end of central directory signature (0x%x)", sig); 105 | } 106 | 107 | _ReadShort(this->file); // this disk 108 | _ReadShort(this->file); // start disk 109 | _ReadShort(this->file); // entries in this disk 110 | count = _ReadShort(this->file); // entries in central directory disk 111 | _ReadInt(this->file); // size of central directory 112 | offset = _ReadInt(this->file); // offset to central directory 113 | 114 | this->entry = (zip_entry_t*)calloc(count, sizeof(zip_entry_t)); 115 | this->entry_count = count; 116 | 117 | fseek(this->file, offset, SEEK_SET); 118 | 119 | for (i = 0; i < count; i++) 120 | { 121 | zip_entry_t* entry = this->entry + i; 122 | 123 | sig = _ReadInt(this->file); 124 | if (sig != ZIP_CENTRAL_DIRECTORY_SIG) { 125 | Error("wrong zip central directory signature (0x%x)", sig); 126 | } 127 | 128 | _ReadShort(this->file); // version made by 129 | _ReadShort(this->file); // version to extract 130 | _ReadShort(this->file); // general 131 | _ReadShort(this->file); // method 132 | _ReadShort(this->file); // last mod file time 133 | _ReadShort(this->file); // last mod file date 134 | _ReadInt(this->file); // crc-32 135 | entry->csize = _ReadInt(this->file); // csize 136 | entry->usize = _ReadInt(this->file); // usize 137 | namesize = _ReadShort(this->file); // namesize 138 | metasize = _ReadShort(this->file); // metasize 139 | commentsize = _ReadShort(this->file); // commentsize 140 | _ReadShort(this->file); // disk number start 141 | _ReadShort(this->file); // int file atts 142 | _ReadInt(this->file); // ext file atts 143 | entry->offset = _ReadInt(this->file); // offset 144 | 145 | entry->name = (char*)malloc(namesize + 1); 146 | fread(entry->name, sizeof(char), namesize, this->file); 147 | entry->name[namesize] = 0; 148 | 149 | fseek(this->file, metasize, SEEK_CUR); 150 | fseek(this->file, commentsize, SEEK_CUR); 151 | } 152 | } 153 | 154 | void ZipFile::openZipFile(const char* name) { 155 | 156 | uint8_t buf[512]; 157 | int filesize, back, maxback; 158 | int i, n; 159 | 160 | this->file = fopen(name, "rb"); 161 | if (this->file == NULL) { 162 | Error("openZipFile: cannot open file %s\n", name); 163 | } 164 | 165 | fseek(this->file, 0, SEEK_END); 166 | filesize = (int)ftell(this->file); 167 | fseek(this->file, 0, SEEK_SET); 168 | 169 | maxback = MIN(filesize, 0xFFFF + sizeof(buf)); 170 | back = MIN(maxback, sizeof(buf)); 171 | 172 | while (back < maxback) 173 | { 174 | fseek(this->file, filesize - back, SEEK_SET); 175 | n = sizeof(buf); 176 | fread(buf, sizeof(uint8_t), n, this->file); 177 | for (i = n - 4; i > 0; i--) 178 | { 179 | if (!std::memcmp(buf + i, "PK\5\6", 4)) { 180 | findAndReadZipDir(filesize - back + i); 181 | return; 182 | } 183 | } 184 | back += sizeof(buf) - 4; 185 | } 186 | 187 | Error("cannot find end of central directory\n"); 188 | } 189 | 190 | void ZipFile::closeZipFile() { 191 | if (this) { 192 | if (this->entry) { 193 | std::free(this->entry); 194 | this->entry = nullptr; 195 | } 196 | 197 | if (this->file) { 198 | fclose(this->file); 199 | this->file = nullptr; 200 | } 201 | } 202 | } 203 | 204 | uint8_t* ZipFile::readZipFileEntry(const char* name, int* sizep) { 205 | zip_entry_t* entry = nullptr; 206 | int i, sig, general, method, namelength, extralength; 207 | uint8_t* cdata; 208 | int code; 209 | 210 | for (i = 0; i < this->entry_count; i++) 211 | { 212 | zip_entry_t* entryTmp = this->entry + i; 213 | if (!SDL_strcasecmp(name, entryTmp->name)) { 214 | entry = this->entry + i; 215 | break; 216 | } 217 | } 218 | 219 | if (entry == NULL) { 220 | Error("did not find the %s file in the zip file", name); 221 | } 222 | 223 | fseek(this->file, entry->offset, SEEK_SET); 224 | 225 | sig = _ReadInt(this->file); 226 | if (sig != ZIP_LOCAL_FILE_SIG) { 227 | Error("wrong zip local file signature (0x%x)", sig); 228 | } 229 | 230 | _ReadShort(this->file); // version 231 | general = _ReadShort(this->file); // general 232 | if (general & ZIP_ENCRYPTED_FLAG) { 233 | Error("zipfile content is encrypted"); 234 | } 235 | 236 | method = _ReadShort(this->file); // method 237 | _ReadShort(this->file); // file time 238 | _ReadShort(this->file); // file date 239 | _ReadInt(this->file); // crc-32 240 | _ReadInt(this->file); // csize 241 | _ReadInt(this->file); // usize 242 | namelength = _ReadShort(this->file); // namelength 243 | extralength = _ReadShort(this->file); // extralength 244 | 245 | fseek(this->file, namelength + extralength, SEEK_CUR); 246 | 247 | cdata = (uint8_t*) malloc(entry->csize); 248 | fread(cdata, sizeof(uint8_t), entry->csize, this->file); 249 | 250 | if (method == 0) 251 | { 252 | *sizep = entry->usize; 253 | return cdata; 254 | } 255 | else if (method == 8) 256 | { 257 | uint8_t* udata = (uint8_t*) malloc(entry->usize); 258 | z_stream stream; 259 | 260 | std::memset(&stream, 0, sizeof stream); 261 | stream.zalloc = zip_alloc; 262 | stream.zfree = zip_free; 263 | stream.opaque = Z_NULL; 264 | stream.next_in = cdata; 265 | stream.avail_in = entry->csize; 266 | stream.next_out = udata; 267 | stream.avail_out = entry->usize; 268 | 269 | code = inflateInit2(&stream, -15); 270 | if (code != Z_OK) { 271 | Error("zlib inflateInit2 error: %s", stream.msg); 272 | } 273 | 274 | code = inflate(&stream, Z_FINISH); 275 | if (code != Z_STREAM_END) { 276 | inflateEnd(&stream); 277 | Error("zlib inflate error: %s", stream.msg); 278 | } 279 | 280 | code = inflateEnd(&stream); 281 | if (code != Z_OK) { 282 | inflateEnd(&stream); 283 | Error("zlib inflateEnd error: %s", stream.msg); 284 | } 285 | 286 | std::free(cdata); 287 | 288 | *sizep = entry->usize; 289 | return udata; 290 | } 291 | else { 292 | Error("unknown zip method: %d", method); 293 | } 294 | 295 | return nullptr; 296 | } -------------------------------------------------------------------------------- /src/ZipFile.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZIPFILE_H__ 2 | #define __ZIPFILE_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define ZIP_LOCAL_FILE_SIG 0x04034b50 11 | #define ZIP_CENTRAL_DIRECTORY_SIG 0x02014b50 12 | #define ZIP_END_OF_CENTRAL_DIRECTORY_SIG 0x06054b50 13 | #define ZIP_ENCRYPTED_FLAG 0x1 14 | 15 | typedef struct zip_entry_s 16 | { 17 | char* name; 18 | int offset; 19 | int csize, usize; 20 | }zip_entry_t; 21 | 22 | class ZipFile 23 | { 24 | private: 25 | FILE* file; 26 | int entry_count; 27 | zip_entry_t* entry; 28 | int page_count; 29 | int* page; 30 | public: 31 | 32 | // Constructor 33 | ZipFile(); 34 | // Destructor 35 | ~ZipFile(); 36 | 37 | void findAndReadZipDir(int startoffset); 38 | void openZipFile(const char* name); 39 | void closeZipFile(); 40 | uint8_t* readZipFileEntry(const char* name, int* sizep); 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /src/appicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Erick194/DoomIIRPG-RE/4ecf14341c9eeadb08acdede82813e660bc3b0a2/src/appicon.ico -------------------------------------------------------------------------------- /src/appicon.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "appicon.ico" -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/sha1.cpp: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // sha1.cpp 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #include "sha1.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 | SHA1::SHA1() 17 | { 18 | reset(); 19 | } 20 | 21 | 22 | /// restart 23 | void SHA1::reset() 24 | { 25 | m_numBytes = 0; 26 | m_bufferSize = 0; 27 | 28 | // according to RFC 1321 29 | m_hash[0] = 0x67452301; 30 | m_hash[1] = 0xefcdab89; 31 | m_hash[2] = 0x98badcfe; 32 | m_hash[3] = 0x10325476; 33 | m_hash[4] = 0xc3d2e1f0; 34 | } 35 | 36 | 37 | namespace 38 | { 39 | // mix functions for processBlock() 40 | inline uint32_t f1(uint32_t b, uint32_t c, uint32_t d) 41 | { 42 | return d ^ (b & (c ^ d)); // original: f = (b & c) | ((~b) & d); 43 | } 44 | 45 | inline uint32_t f2(uint32_t b, uint32_t c, uint32_t d) 46 | { 47 | return b ^ c ^ d; 48 | } 49 | 50 | inline uint32_t f3(uint32_t b, uint32_t c, uint32_t d) 51 | { 52 | return (b & c) | (b & d) | (c & d); 53 | } 54 | 55 | inline uint32_t rotate(uint32_t a, uint32_t c) 56 | { 57 | return (a << c) | (a >> (32 - c)); 58 | } 59 | 60 | inline uint32_t swap(uint32_t x) 61 | { 62 | #if defined(__GNUC__) || defined(__clang__) 63 | return __builtin_bswap32(x); 64 | #endif 65 | #ifdef MSC_VER 66 | return _byteswap_ulong(x); 67 | #endif 68 | 69 | return (x >> 24) | 70 | ((x >> 8) & 0x0000FF00) | 71 | ((x << 8) & 0x00FF0000) | 72 | (x << 24); 73 | } 74 | } 75 | 76 | 77 | /// process 64 bytes 78 | void SHA1::processBlock(const void* data) 79 | { 80 | // get last hash 81 | uint32_t a = m_hash[0]; 82 | uint32_t b = m_hash[1]; 83 | uint32_t c = m_hash[2]; 84 | uint32_t d = m_hash[3]; 85 | uint32_t e = m_hash[4]; 86 | 87 | // data represented as 16x 32-bit words 88 | const uint32_t* input = (uint32_t*) data; 89 | // convert to big endian 90 | uint32_t words[80]; 91 | for (int i = 0; i < 16; i++) 92 | #if defined(__BYTE_ORDER) && (__BYTE_ORDER != 0) && (__BYTE_ORDER == __BIG_ENDIAN) 93 | words[i] = input[i]; 94 | #else 95 | words[i] = swap(input[i]); 96 | #endif 97 | 98 | // extend to 80 words 99 | for (int i = 16; i < 80; i++) 100 | words[i] = rotate(words[i-3] ^ words[i-8] ^ words[i-14] ^ words[i-16], 1); 101 | 102 | // first round 103 | for (int i = 0; i < 4; i++) 104 | { 105 | int offset = 5*i; 106 | e += rotate(a,5) + f1(b,c,d) + words[offset ] + 0x5a827999; b = rotate(b,30); 107 | d += rotate(e,5) + f1(a,b,c) + words[offset+1] + 0x5a827999; a = rotate(a,30); 108 | c += rotate(d,5) + f1(e,a,b) + words[offset+2] + 0x5a827999; e = rotate(e,30); 109 | b += rotate(c,5) + f1(d,e,a) + words[offset+3] + 0x5a827999; d = rotate(d,30); 110 | a += rotate(b,5) + f1(c,d,e) + words[offset+4] + 0x5a827999; c = rotate(c,30); 111 | } 112 | 113 | // second round 114 | for (int i = 4; i < 8; i++) 115 | { 116 | int offset = 5*i; 117 | e += rotate(a,5) + f2(b,c,d) + words[offset ] + 0x6ed9eba1; b = rotate(b,30); 118 | d += rotate(e,5) + f2(a,b,c) + words[offset+1] + 0x6ed9eba1; a = rotate(a,30); 119 | c += rotate(d,5) + f2(e,a,b) + words[offset+2] + 0x6ed9eba1; e = rotate(e,30); 120 | b += rotate(c,5) + f2(d,e,a) + words[offset+3] + 0x6ed9eba1; d = rotate(d,30); 121 | a += rotate(b,5) + f2(c,d,e) + words[offset+4] + 0x6ed9eba1; c = rotate(c,30); 122 | } 123 | 124 | // third round 125 | for (int i = 8; i < 12; i++) 126 | { 127 | int offset = 5*i; 128 | e += rotate(a,5) + f3(b,c,d) + words[offset ] + 0x8f1bbcdc; b = rotate(b,30); 129 | d += rotate(e,5) + f3(a,b,c) + words[offset+1] + 0x8f1bbcdc; a = rotate(a,30); 130 | c += rotate(d,5) + f3(e,a,b) + words[offset+2] + 0x8f1bbcdc; e = rotate(e,30); 131 | b += rotate(c,5) + f3(d,e,a) + words[offset+3] + 0x8f1bbcdc; d = rotate(d,30); 132 | a += rotate(b,5) + f3(c,d,e) + words[offset+4] + 0x8f1bbcdc; c = rotate(c,30); 133 | } 134 | 135 | // fourth round 136 | for (int i = 12; i < 16; i++) 137 | { 138 | int offset = 5*i; 139 | e += rotate(a,5) + f2(b,c,d) + words[offset ] + 0xca62c1d6; b = rotate(b,30); 140 | d += rotate(e,5) + f2(a,b,c) + words[offset+1] + 0xca62c1d6; a = rotate(a,30); 141 | c += rotate(d,5) + f2(e,a,b) + words[offset+2] + 0xca62c1d6; e = rotate(e,30); 142 | b += rotate(c,5) + f2(d,e,a) + words[offset+3] + 0xca62c1d6; d = rotate(d,30); 143 | a += rotate(b,5) + f2(c,d,e) + words[offset+4] + 0xca62c1d6; c = rotate(c,30); 144 | } 145 | 146 | // update hash 147 | m_hash[0] += a; 148 | m_hash[1] += b; 149 | m_hash[2] += c; 150 | m_hash[3] += d; 151 | m_hash[4] += e; 152 | } 153 | 154 | 155 | /// add arbitrary number of bytes 156 | void SHA1::add(const void* data, size_t numBytes) 157 | { 158 | const uint8_t* current = (const uint8_t*) data; 159 | 160 | if (m_bufferSize > 0) 161 | { 162 | while (numBytes > 0 && m_bufferSize < BlockSize) 163 | { 164 | m_buffer[m_bufferSize++] = *current++; 165 | numBytes--; 166 | } 167 | } 168 | 169 | // full buffer 170 | if (m_bufferSize == BlockSize) 171 | { 172 | processBlock((void*)m_buffer); 173 | m_numBytes += BlockSize; 174 | m_bufferSize = 0; 175 | } 176 | 177 | // no more data ? 178 | if (numBytes == 0) 179 | return; 180 | 181 | // process full blocks 182 | while (numBytes >= BlockSize) 183 | { 184 | processBlock(current); 185 | current += BlockSize; 186 | m_numBytes += BlockSize; 187 | numBytes -= BlockSize; 188 | } 189 | 190 | // keep remaining bytes in buffer 191 | while (numBytes > 0) 192 | { 193 | m_buffer[m_bufferSize++] = *current++; 194 | numBytes--; 195 | } 196 | } 197 | 198 | 199 | /// process final block, less than 64 bytes 200 | void SHA1::processBuffer() 201 | { 202 | // the input bytes are considered as bits strings, where the first bit is the most significant bit of the byte 203 | 204 | // - append "1" bit to message 205 | // - append "0" bits until message length in bit mod 512 is 448 206 | // - append length as 64 bit integer 207 | 208 | // number of bits 209 | size_t paddedLength = m_bufferSize * 8; 210 | 211 | // plus one bit set to 1 (always appended) 212 | paddedLength++; 213 | 214 | // number of bits must be (numBits % 512) = 448 215 | size_t lower11Bits = paddedLength & 511; 216 | if (lower11Bits <= 448) 217 | paddedLength += 448 - lower11Bits; 218 | else 219 | paddedLength += 512 + 448 - lower11Bits; 220 | // convert from bits to bytes 221 | paddedLength /= 8; 222 | 223 | // only needed if additional data flows over into a second block 224 | unsigned char extra[BlockSize]; 225 | 226 | // append a "1" bit, 128 => binary 10000000 227 | if (m_bufferSize < BlockSize) 228 | m_buffer[m_bufferSize] = 128; 229 | else 230 | extra[0] = 128; 231 | 232 | size_t i; 233 | for (i = m_bufferSize + 1; i < BlockSize; i++) 234 | m_buffer[i] = 0; 235 | for (; i < paddedLength; i++) 236 | extra[i - BlockSize] = 0; 237 | 238 | // add message length in bits as 64 bit number 239 | uint64_t msgBits = 8 * (m_numBytes + m_bufferSize); 240 | // find right position 241 | unsigned char* addLength; 242 | if (paddedLength < BlockSize) 243 | addLength = m_buffer + paddedLength; 244 | else 245 | addLength = extra + paddedLength - BlockSize; 246 | 247 | // must be big endian 248 | *addLength++ = (unsigned char)((msgBits >> 56) & 0xFF); 249 | *addLength++ = (unsigned char)((msgBits >> 48) & 0xFF); 250 | *addLength++ = (unsigned char)((msgBits >> 40) & 0xFF); 251 | *addLength++ = (unsigned char)((msgBits >> 32) & 0xFF); 252 | *addLength++ = (unsigned char)((msgBits >> 24) & 0xFF); 253 | *addLength++ = (unsigned char)((msgBits >> 16) & 0xFF); 254 | *addLength++ = (unsigned char)((msgBits >> 8) & 0xFF); 255 | *addLength = (unsigned char)( msgBits & 0xFF); 256 | 257 | // process blocks 258 | processBlock(m_buffer); 259 | // flowed over into a second block ? 260 | if (paddedLength > BlockSize) 261 | processBlock(extra); 262 | } 263 | 264 | 265 | /// return latest hash as 40 hex characters 266 | std::string SHA1::getHash() 267 | { 268 | // compute hash (as raw bytes) 269 | unsigned char rawHash[HashBytes]; 270 | getHash(rawHash); 271 | 272 | // convert to hex string 273 | std::string result; 274 | result.reserve(2 * HashBytes); 275 | for (int i = 0; i < HashBytes; i++) 276 | { 277 | static const char dec2hex[16+1] = "0123456789abcdef"; 278 | result += dec2hex[(rawHash[i] >> 4) & 15]; 279 | result += dec2hex[ rawHash[i] & 15]; 280 | } 281 | 282 | return result; 283 | } 284 | 285 | 286 | /// return latest hash as bytes 287 | void SHA1::getHash(unsigned char buffer[SHA1::HashBytes]) 288 | { 289 | // save old hash if buffer is partially filled 290 | uint32_t oldHash[HashValues]; 291 | for (int i = 0; i < HashValues; i++) 292 | oldHash[i] = m_hash[i]; 293 | 294 | // process remaining bytes 295 | processBuffer(); 296 | 297 | unsigned char* current = buffer; 298 | for (int i = 0; i < HashValues; i++) 299 | { 300 | *current++ = (m_hash[i] >> 24) & 0xFF; 301 | *current++ = (m_hash[i] >> 16) & 0xFF; 302 | *current++ = (m_hash[i] >> 8) & 0xFF; 303 | *current++ = m_hash[i] & 0xFF; 304 | 305 | // restore old hash 306 | m_hash[i] = oldHash[i]; 307 | } 308 | } 309 | 310 | 311 | /// compute SHA1 of a memory block 312 | std::string SHA1::operator()(const void* data, size_t numBytes) 313 | { 314 | reset(); 315 | add(data, numBytes); 316 | return getHash(); 317 | } 318 | 319 | 320 | /// compute SHA1 of a string, excluding final zero 321 | std::string SHA1::operator()(const std::string& text) 322 | { 323 | reset(); 324 | add(text.c_str(), text.size()); 325 | return getHash(); 326 | } 327 | -------------------------------------------------------------------------------- /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.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/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 | --------------------------------------------------------------------------------