From a258f0ede93a6b2de808d1db1316693f0e864225 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 19 Jan 2019 00:20:40 +0100 Subject: [PATCH 1/6] Enable 64bit builds --- CMake/32bit.cmake | 25 ---- CMake/CodeCoverage.cmake | 303 --------------------------------------- CMake/absolute.cmake | 26 ---- CMake/sanitize.cmake | 18 --- CMakeLists.txt | 95 +----------- 5 files changed, 7 insertions(+), 460 deletions(-) delete mode 100644 CMake/32bit.cmake delete mode 100644 CMake/CodeCoverage.cmake delete mode 100644 CMake/absolute.cmake delete mode 100644 CMake/sanitize.cmake diff --git a/CMake/32bit.cmake b/CMake/32bit.cmake deleted file mode 100644 index 4b88ca3cc..000000000 --- a/CMake/32bit.cmake +++ /dev/null @@ -1,25 +0,0 @@ -message(STATUS "Using 32-bit toolchain") - -set(CMAKE_CXX_FLAGS -m32 CACHE STRING "") - -# Affects pkg-config -set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE) -# Used by pkg-config on Debian -set(CMAKE_LIBRARY_ARCHITECTURE i386-linux-gnu) -# Silly hack required to get the pkg-config path code to activate -list(APPEND CMAKE_PREFIX_PATH /usr) - -# Find where 32-bit CMake modules are stored -find_path(DIR NAMES cmake PATHS /usr/lib32 /usr/lib/i386-linux-gnu NO_DEFAULT_PATH) - -if(DIR) - message(STATUS "Using 32-bit libraries from ${DIR}") - # Read CMake modules from 32-bit packages - set(CMAKE_FIND_ROOT_PATH ${DIR}) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -endif() - -# 32-bit NASM -set(CMAKE_ASM_NASM_OBJECT_FORMAT elf) diff --git a/CMake/CodeCoverage.cmake b/CMake/CodeCoverage.cmake deleted file mode 100644 index b17bc05b3..000000000 --- a/CMake/CodeCoverage.cmake +++ /dev/null @@ -1,303 +0,0 @@ -# Copyright (c) 2012 - 2017, Lars Bilke -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# CHANGES: -# -# 2012-01-31, Lars Bilke -# - Enable Code Coverage -# -# 2013-09-17, Joakim Söderberg -# - Added support for Clang. -# - Some additional usage instructions. -# -# 2016-02-03, Lars Bilke -# - Refactored functions to use named parameters -# -# 2017-06-02, Lars Bilke -# - Merged with modified version from github.com/ufz/ogs -# -# -# USAGE: -# -# 1. Copy this file into your cmake modules path. -# -# 2. Add the following line to your CMakeLists.txt: -# include(CodeCoverage) -# -# 3. Append necessary compiler flags: -# APPEND_COVERAGE_COMPILER_FLAGS() -# -# 4. If you need to exclude additional directories from the report, specify them -# using the COVERAGE_LCOV_EXCLUDES variable before calling SETUP_TARGET_FOR_COVERAGE_LCOV. -# Example: -# set(COVERAGE_LCOV_EXCLUDES 'dir1/*' 'dir2/*') -# -# 5. Use the functions described below to create a custom make target which -# runs your test executable and produces a code coverage report. -# -# 6. Build a Debug build: -# cmake -DCMAKE_BUILD_TYPE=Debug .. -# make -# make my_coverage_target -# - -include(CMakeParseArguments) - -# Check prereqs -find_program( GCOV_PATH gcov ) -find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl) -find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat ) -find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) -find_program( SIMPLE_PYTHON_EXECUTABLE python ) - -if(NOT GCOV_PATH) - message(WARNING "gcov not found") - return() -endif() # NOT GCOV_PATH - -if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") - if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) - message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") - endif() -elseif(NOT CMAKE_COMPILER_IS_GNUCXX) - message(WARNING "Compiler is not GNU gcc") - return() -endif() - -set(COVERAGE_COMPILER_FLAGS --coverage -fprofile-arcs -ftest-coverage - CACHE INTERNAL "") - -set(CMAKE_CXX_FLAGS_COVERAGE - ${COVERAGE_COMPILER_FLAGS} - CACHE STRING "Flags used by the C++ compiler during coverage builds." - FORCE ) -set(CMAKE_C_FLAGS_COVERAGE - ${COVERAGE_COMPILER_FLAGS} - CACHE STRING "Flags used by the C compiler during coverage builds." - FORCE ) -set(CMAKE_EXE_LINKER_FLAGS_COVERAGE - "" - CACHE STRING "Flags used for linking binaries during coverage builds." - FORCE ) -set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE - "" - CACHE STRING "Flags used by the shared libraries linker during coverage builds." - FORCE ) - -mark_as_advanced( - CMAKE_CXX_FLAGS_COVERAGE - CMAKE_C_FLAGS_COVERAGE - CMAKE_EXE_LINKER_FLAGS_COVERAGE - CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) - -if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") -endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" - -# Defines a target for running and collection code coverage information -# Builds dependencies, runs the given executable and outputs reports. -# NOTE! The executable should always have a ZERO as exit code otherwise -# the coverage generation will not complete. -# -# SETUP_TARGET_FOR_COVERAGE_LCOV( -# NAME testrunner_coverage # New target name -# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR -# DEPENDENCIES testrunner # Dependencies to build first -# ) -function(SETUP_TARGET_FOR_COVERAGE_LCOV) - - set(options NONE) - set(oneValueArgs NAME) - set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT LCOV_PATH) - message(FATAL_ERROR "lcov not found! Aborting...") - endif() # NOT LCOV_PATH - - if(NOT GENHTML_PATH) - message(FATAL_ERROR "genhtml not found! Aborting...") - endif() # NOT GENHTML_PATH - - # Setup target - add_custom_target(${Coverage_NAME} - - # Cleanup lcov - COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -directory . --zerocounters - # Create baseline to make sure untouched files show up in the report - COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -c -i -d . -o ${Coverage_NAME}.base - - # Run tests - COMMAND ${Coverage_EXECUTABLE} - - # Capturing lcov counters and generating report - COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} --directory . --capture --output-file ${Coverage_NAME}.info - # add baseline counters - COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -a ${Coverage_NAME}.base -a ${Coverage_NAME}.info --output-file ${Coverage_NAME}.total - COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} --remove ${Coverage_NAME}.total ${COVERAGE_LCOV_EXCLUDES} --output-file ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned - COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned - COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.base ${Coverage_NAME}.total ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned - - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS ${Coverage_DEPENDENCIES} - COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." - ) - - # Show where to find the lcov info report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ; - COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info." - ) - - # Show info where to find the report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ; - COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." - ) - -endfunction() # SETUP_TARGET_FOR_COVERAGE_LCOV - -# Defines a target for running and collection code coverage information -# Builds dependencies, runs the given executable and outputs reports. -# NOTE! The executable should always have a ZERO as exit code otherwise -# the coverage generation will not complete. -# -# SETUP_TARGET_FOR_COVERAGE_GCOVR_XML( -# NAME ctest_coverage # New target name -# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR -# DEPENDENCIES executable_target # Dependencies to build first -# ) -function(SETUP_TARGET_FOR_COVERAGE_GCOVR_XML) - - set(options NONE) - set(oneValueArgs NAME) - set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT SIMPLE_PYTHON_EXECUTABLE) - message(FATAL_ERROR "python not found! Aborting...") - endif() # NOT SIMPLE_PYTHON_EXECUTABLE - - if(NOT GCOVR_PATH) - message(FATAL_ERROR "gcovr not found! Aborting...") - endif() # NOT GCOVR_PATH - - # Combine excludes to several -e arguments - set(GCOVR_EXCLUDES "") - foreach(EXCLUDE ${COVERAGE_GCOVR_EXCLUDES}) - list(APPEND GCOVR_EXCLUDES "-e") - list(APPEND GCOVR_EXCLUDES "${EXCLUDE}") - endforeach() - - add_custom_target(${Coverage_NAME} - # Run tests - ${Coverage_EXECUTABLE} - - # Running gcovr - COMMAND ${GCOVR_PATH} --xml - -r ${PROJECT_SOURCE_DIR} ${GCOVR_EXCLUDES} - --object-directory=${PROJECT_BINARY_DIR} - -o ${Coverage_NAME}.xml - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS ${Coverage_DEPENDENCIES} - COMMENT "Running gcovr to produce Cobertura code coverage report." - ) - - # Show info where to find the report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ; - COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml." - ) - -endfunction() # SETUP_TARGET_FOR_COVERAGE_GCOVR_XML - -# Defines a target for running and collection code coverage information -# Builds dependencies, runs the given executable and outputs reports. -# NOTE! The executable should always have a ZERO as exit code otherwise -# the coverage generation will not complete. -# -# SETUP_TARGET_FOR_COVERAGE_GCOVR_HTML( -# NAME ctest_coverage # New target name -# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR -# DEPENDENCIES executable_target # Dependencies to build first -# ) -function(SETUP_TARGET_FOR_COVERAGE_GCOVR_HTML) - - set(options NONE) - set(oneValueArgs NAME) - set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT SIMPLE_PYTHON_EXECUTABLE) - message(WARNING "python not found! Aborting...") - return() - endif() # NOT SIMPLE_PYTHON_EXECUTABLE - - if(NOT GCOVR_PATH) - message(WARNING "gcovr not found! Aborting...") - return() - endif() # NOT GCOVR_PATH - - # Combine excludes to several -e arguments - set(GCOVR_EXCLUDES "") - foreach(EXCLUDE ${COVERAGE_GCOVR_EXCLUDES}) - list(APPEND GCOVR_EXCLUDES "-e") - list(APPEND GCOVR_EXCLUDES "${EXCLUDE}") - endforeach() - - add_custom_target(${Coverage_NAME} - # Run tests - ${Coverage_EXECUTABLE} - - # Create folder - COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/${Coverage_NAME} - - # Running gcovr - COMMAND ${GCOVR_PATH} --html --html-details - --delete - -r ${PROJECT_SOURCE_DIR} ${GCOVR_EXCLUDES} - --object-directory=${PROJECT_BINARY_DIR} - -o ${Coverage_NAME}/index.html - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS ${Coverage_DEPENDENCIES} - COMMENT "Running gcovr to produce HTML code coverage report." - ) - - # Show info where to find the report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD - COMMAND ; - COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." - ) - -endfunction() # SETUP_TARGET_FOR_COVERAGE_GCOVR_HTML - -function(APPEND_COVERAGE_COMPILER_FLAGS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) - message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}") -endfunction() # APPEND_COVERAGE_COMPILER_FLAGS diff --git a/CMake/absolute.cmake b/CMake/absolute.cmake deleted file mode 100644 index 5edff2894..000000000 --- a/CMake/absolute.cmake +++ /dev/null @@ -1,26 +0,0 @@ -set(ORIGINAL_EXE "${CMAKE_SOURCE_DIR}/Diablo.exe") - -if(EXISTS "${ORIGINAL_EXE}") - message(STATUS "Using EXE at ${ORIGINAL_EXE}") - - file(MD5 ${ORIGINAL_EXE} MD5SUM) - if(NOT MD5SUM STREQUAL "da62d5cd8bd71a0b66e6d4ef7a111233") - message(FATAL_ERROR "MD5 of EXE is not correct (${MD5SUM})") - endif() - - enable_language(ASM_NASM) - - set(HARNESS_ASM "${CMAKE_SOURCE_DIR}/Absolute/harness.asm") - - # This can not be an OBJECT library since those can not have link flags on older versions of cmake - add_library(harness STATIC ${HARNESS_ASM}) - target_compile_options(harness PRIVATE -f elf -DEXE=\"${ORIGINAL_EXE}\") - - target_compile_options(harness INTERFACE -fno-pie -fno-pic) - target_compile_definitions(harness INTERFACE -DNO_GLOBALS) - target_link_libraries(harness INTERFACE - -L${CMAKE_SOURCE_DIR}/Absolute -Tdefault.ld - ) -else() - message(STATUS "Original .exe not found at ${ORIGINAL_EXE}") -endif() diff --git a/CMake/sanitize.cmake b/CMake/sanitize.cmake deleted file mode 100644 index 2cde7b136..000000000 --- a/CMake/sanitize.cmake +++ /dev/null @@ -1,18 +0,0 @@ -include(CheckCXXCompilerFlag) -include(CMakePushCheckState) - -set(SANITIZE_OPTIONS -fsanitize=null -fsanitize=return) -# TODO: use "-fsanitize=object-size" -# "-fsanitize=bounds" not enabled because the code often generates temporary pointers out-of-bounds of arrays - -# Note: The compiler must always support recovery because the decompiled code is not ASAN-clean -set(SANITIZE_ADDRESS_FLAGS -fsanitize=address -fsanitize-recover=address) - -cmake_push_check_state() -set(CMAKE_REQUIRED_LIBRARIES ${SANITIZE_ADDRESS_FLAGS}) -check_cxx_compiler_flag("${SANITIZE_ADDRESS_FLAGS}" HAS_SANITIZE_ADDRESS) -cmake_pop_check_state() - -if(HAS_SANITIZE_ADDRESS) - list(APPEND SANITIZE_OPTIONS ${SANITIZE_ADDRESS_FLAGS}) -endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index ecbbbf865..33adf0dd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,30 +10,21 @@ endif() include(CMake/out_of_tree.cmake) -# This *must* be included before calling `project()`, due to setting early compiler flags. -include(CMake/32bit.cmake) - set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -project(devil-miniwin +project(devilutionX VERSION 0.0.1 LANGUAGES C CXX ) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${devilutionX_SOURCE_DIR}/CMake") -if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4) - message(WARNING "sizeof(void*) == ${CMAKE_SIZEOF_VOID_P}.") - message(FATAL_ERROR [[This project can only be compiled in 32-bit mode.]]) -endif() +find_package(SDL2 REQUIRED) +find_package(SDL2_mixer REQUIRED) # Note: In Debug mode, GCC generates spurious memory references that upset Valgrind, # these options fix that. string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fno-omit-frame-pointer") -if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Clang/LLVM optimizations break everything -# string(APPEND CMAKE_CXX_FLAGS_DEBUG " -Og") -# string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fvar-tracking-assignments -ggdb -gdwarf-4") -endif() set(SOURCES Source/automap.cpp @@ -151,11 +142,9 @@ set(STUB_SOURCES ) include(CMake/SDL2_fixed.cmake) -include(CMake/sanitize.cmake) -include(CMake/absolute.cmake) -include(CMake/CodeCoverage.cmake) -include_directories(${SDL2_INCLUDE_DIRS}) +include_directories(${SDL2_INCLUDE_DIR} + ${SDL2_MIXER_INCLUDE_DIR}) include_directories(. Stub) @@ -181,7 +170,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-fms-extensions) endif() -# Vanilla build add_executable(devilution ${SOURCES} ${STUB_SOURCES} @@ -191,80 +179,11 @@ add_executable(devilution target_link_libraries(devilution PUBLIC m ${SDL2_LIBRARIES} + ${SDL2_MIXER_LIBRARIES} ) -# Coverage tracing library (compiled separately so it itself is not traced & can be optimized) -add_library(sanitize_coverage STATIC Stub/sanitize_coverage.cpp) -target_compile_options(sanitize_coverage PRIVATE -O2 -fno-pie -fno-pic) - -cmake_push_check_state() -set(SANITIZE_COVERAGE_FLAGS -fsanitize-coverage=trace-pc) -set(CMAKE_REQUIRED_FLAGS ${SANITIZE_COVERAGE_FLAGS}) -check_cxx_source_compiles([[extern "C" void __sanitizer_cov_trace_pc(void) {} int main() { return 0; }]] HAS_SANITIZE_COVERAGE) -cmake_pop_check_state() - - # xxhash fast hashing library add_library(xxhash STATIC 3rdParty/xxhash/xxhash.c) set_source_files_properties(3rdParty/xxhash/xxhash.c PROPERTIES LANGUAGE CXX) target_include_directories(xxhash PUBLIC 3rdParty/xxhash) target_compile_options(xxhash PRIVATE -O3 -fno-pie -fno-pic) - -# Build with harness enabled (conflicts with sanitizers) -if(TARGET harness) - add_executable(devil-harness - ${SOURCES} - ${STUB_SOURCES} - # Stub/main_harness.cpp - Stub/main_test.cpp - Absolute/absolute.cpp - Absolute/hook.cpp - Stub/test_utils.cpp - ) - - if(HAS_SANITIZE_COVERAGE) - target_compile_options(devil-harness PRIVATE ${SANITIZE_COVERAGE_FLAGS}) - target_compile_definitions(devil-harness PRIVATE -DHAVE_SANITIZE_COVERGE) - endif() - - target_compile_definitions(devil-harness PUBLIC -DHAVE_HARNESS) - - target_link_libraries(devil-harness PUBLIC - m - harness - xxhash - sanitize_coverage - ${SDL2_LIBRARIES} - ) -endif() - -# Build with sanitizers enabled -add_executable(devil-sanitize - ${SOURCES} - ${STUB_SOURCES} - Stub/main_test.cpp - Stub/test_utils.cpp - Stub/sanitize.cpp -) - -target_compile_options(devil-sanitize PRIVATE - ${SANITIZE_OPTIONS} - ${COVERAGE_COMPILER_FLAGS} -) - -target_link_libraries(devil-sanitize PUBLIC - m - xxhash - sanitize_coverage - ${SDL2_LIBRARIES} - ${SANITIZE_OPTIONS} - ${COVERAGE_COMPILER_FLAGS} -) - -if(COVERAGE_COMPILER_FLAGS) - SETUP_TARGET_FOR_COVERAGE_GCOVR_HTML( - NAME devil-sanitize-coverage - EXECUTABLE devil-sanitize - DEPENDENCIES devil-sanitize - ) -endif() From d4d5683d5b234f6cbf72ff8a4a4aedcf6e3e5e64 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 19 Jan 2019 01:01:05 +0100 Subject: [PATCH 2/6] Fix compiling on 64bit (only menu works) --- CMakeLists.txt | 3 +- Source/gmenu.cpp | 4 +- Source/multi.cpp | 780 ++++++++++++++++----------------------------- Source/multi.h | 40 +-- Stub/sdlrender.cpp | 4 +- defs.h | 1 + structs.h | 5 + 7 files changed, 299 insertions(+), 538 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33adf0dd8..b4860e552 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,8 @@ set(STUB_SOURCES Stub/miniwin_io.cpp Stub/miniwin_msg_sdl.cpp Stub/storm_net.cpp - Stub/validate.cpp + #Stub/validate.cpp + Stub/effects.cpp Stub/sdlrender.cpp Stub/diablo.cpp Stub/gamemenu.cpp diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 47ca9e1c1..0dca836d3 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -360,7 +360,7 @@ void __cdecl gmenu_init_menu() gdwCursorWidth = dwData[0]; gdwCursorHeight = dwData[1]; - LoadArtImage("ui_art\\logo.pcx", &pPcxLogoImage, 15, dwData); + LoadArtImage("ui_art\\smlogo.pcx", &pPcxLogoImage, 15, dwData); gdwLogoWidth = dwData[0]; gdwLogoHeight = dwData[1]; @@ -389,8 +389,6 @@ void __cdecl gmenu_init_menu() LoadArtImage("ui_art\\font42g.pcx", &pPcxFont42gImage, 256, dwData); gdwFont42Width = dwData[0]; gdwFont42Height = dwData[1]; - - } // 634464: using guessed type char byte_634464; // 634478: using guessed type char byte_634478; diff --git a/Source/multi.cpp b/Source/multi.cpp index a9449b1f4..8236922a8 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -2,110 +2,80 @@ #include "../types.h" -#ifndef NO_GLOBALS char gbSomebodyWonGameKludge; // weak -char pkdata_6761C0[4100]; +TBuffer sgHiPriBuf; char szPlayerDescript[128]; short sgwPackPlrOffsetTbl[MAX_PLRS]; PkPlayerStruct netplr[MAX_PLRS]; char sgbPlayerTurnBitTbl[MAX_PLRS]; char sgbPlayerLeftGameTbl[MAX_PLRS]; -int multi_cpp_init_value; // weak int sgbSentThisCycle; // idb -int dword_678628; // weak -char gbActivePlayers; // weak +int dword_678628; // weak +BYTE gbActivePlayers; // weak char gbGameDestroyed; // weak char sgbSendDeltaTbl[MAX_PLRS]; _gamedata sgGameInitInfo; -char byte_678640; // weak +char byte_678640; // weak int sglTimeoutStart; // weak int sgdwPlayerLeftReasonTbl[MAX_PLRS]; -char pkdata_678658[4100]; +TBuffer sgLoPriBuf; unsigned int sgdwGameLoops; // idb -UCHAR gbMaxPlayers; // weak +BYTE gbMaxPlayers; char sgbTimeout; // weak char szPlayerName[128]; -char gbDeltaSender; // weak +BYTE gbDeltaSender; int sgbNetInited; // weak int player_state[MAX_PLRS]; -#endif -const int multi_inf = 0x7F800000; // weak -const int event_types[3] = -{ - EVENT_TYPE_PLAYER_LEAVE_GAME, - EVENT_TYPE_PLAYER_CREATE_GAME, - EVENT_TYPE_PLAYER_MESSAGE +const int event_types[3] = { + EVENT_TYPE_PLAYER_LEAVE_GAME, + EVENT_TYPE_PLAYER_CREATE_GAME, + EVENT_TYPE_PLAYER_MESSAGE }; -struct multi_cpp_init -{ - multi_cpp_init() - { - multi_cpp_init_value = multi_inf; - } -} _multi_cpp_init; -// 47F154: using guessed type int multi_inf; -// 678620: using guessed type int multi_cpp_init_value; - -void __fastcall multi_msg_add(unsigned char *a1, unsigned char a2) +void __fastcall multi_msg_add(BYTE *a1, unsigned char a2) { - if ( a1 ) - { - if ( a2 ) + if (a1) { + if (a2) tmsg_add(a1, a2); } } -void __fastcall NetSendLoPri(unsigned char *pbMsg, unsigned char bLen) +void __fastcall NetSendLoPri(BYTE *pbMsg, BYTE bLen) { - unsigned char *v2; // esi - unsigned char v3; // bl - int v4; // edx - - v2 = pbMsg; - v3 = bLen; - if ( pbMsg ) - { - if ( bLen ) - { - multi_copy_packet(pkdata_678658, pbMsg, bLen); - _LOBYTE(v4) = v3; - multi_send_packet(v2, v4); + if (pbMsg) { + if (bLen) { + multi_copy_packet(&sgLoPriBuf, pbMsg, bLen); + multi_send_packet(pbMsg, bLen); } } } -void __fastcall multi_copy_packet(void *a1, void *packet, int size) +void __fastcall multi_copy_packet(TBuffer *a1, void *packet, BYTE size) { - int v3; // eax - int v4; // ebx - char *v5; // esi + DWORD v3; // eax + DWORD v4; // ebx + BYTE *v5; // esi - v3 = *(_DWORD *)a1; - v4 = *(_DWORD *)a1 + (unsigned char)size; - if ( (unsigned int)(v4 + 2) <= 0x1000 ) - { - *(_DWORD *)a1 = v4 + 1; - *((_BYTE *)a1 + v3 + 4) = size; - v5 = (char *)a1 + v3 + 5; - memcpy(v5, packet, (unsigned char)size); - v5[(unsigned char)size] = 0; + v3 = a1->dwNextWriteOffset; + v4 = a1->dwNextWriteOffset + size; + if (v4 + 2 <= 0x1000) { + a1->dwNextWriteOffset = v4 + 1; + a1->bData[v3] = size; + v5 = &a1->bData[v3 + 1]; + memcpy(v5, packet, size); + v5[size] = 0; } } -void __fastcall multi_send_packet(void *packet, int dwSize) +void __fastcall multi_send_packet(void *packet, BYTE dwSize) { - void *v2; // esi - unsigned char v3; // bl - TPkt pkt; // [esp+8h] [ebp-200h] + TPkt pkt; - v2 = packet; - v3 = dwSize; NetRecvPlrData(&pkt); - pkt.hdr.wLen = v3 + 19; - memcpy(pkt.body, v2, v3); - if ( !SNetSendMessage(myplr, &pkt.hdr, (unsigned short)pkt.hdr.wLen) ) + pkt.hdr.wLen = dwSize + 19; + memcpy(pkt.body, packet, dwSize); + if (!SNetSendMessage(myplr, &pkt.hdr, pkt.hdr.wLen)) nthread_terminate_game("SNetSendMessage0"); } @@ -123,84 +93,73 @@ void __fastcall NetRecvPlrData(TPkt *pkt) pkt->hdr.bdex = plr[myplr]._pBaseDex; } -void __fastcall NetSendHiPri(unsigned char *pbMsg, unsigned char bLen) +void __fastcall NetSendHiPri(BYTE *pbMsg, BYTE bLen) { - unsigned char *v2; // edi - unsigned char v3; // bl - int v4; // edx unsigned char *v5; // eax - TSyncHeader *v6; // eax - int v7; // eax - int v8; // eax - TPkt pkt; // [esp+Ch] [ebp-204h] - int size; // [esp+20Ch] [ebp-4h] - - v2 = pbMsg; - v3 = bLen; - if ( pbMsg && bLen ) - { - multi_copy_packet(pkdata_6761C0, pbMsg, bLen); - _LOBYTE(v4) = v3; - multi_send_packet(v2, v4); + TSyncHeader *v6; // eax + int v7; // eax + int v8; // eax + TPkt pkt; // [esp+Ch] [ebp-204h] + int size; // [esp+20Ch] [ebp-4h] + + if (pbMsg && bLen) { + multi_copy_packet(&sgHiPriBuf, pbMsg, bLen); + multi_send_packet(pbMsg, bLen); } - if ( !dword_678628 ) - { + if (!dword_678628) { dword_678628 = 1; NetRecvPlrData(&pkt); size = gdwNormalMsgSize - 19; - v5 = multi_recv_packet(pkdata_6761C0, pkt.body, &size); - v6 = (TSyncHeader *)multi_recv_packet(pkdata_678658, v5, &size); + v5 = multi_recv_packet(&sgHiPriBuf, pkt.body, &size); + v6 = (TSyncHeader *)multi_recv_packet(&sgLoPriBuf, v5, &size); v7 = sync_all_monsters(v6, size); - size = v7; v8 = gdwNormalMsgSize - v7; pkt.hdr.wLen = v8; - if ( !SNetSendMessage(-2, &pkt.hdr, v8) ) + if (!SNetSendMessage(-2, &pkt.hdr, v8)) nthread_terminate_game("SNetSendMessage"); } } // 678628: using guessed type int dword_678628; // 679760: using guessed type int gdwNormalMsgSize; -unsigned char *__fastcall multi_recv_packet(void *packet, unsigned char *a2, int *a3) +unsigned char *__fastcall multi_recv_packet(TBuffer *packet, unsigned char *a2, int *a3) { - char *v3; // esi + TBuffer *v3; // esi unsigned char *result; // eax - char *v5; // ebx - size_t v6; // edi - char *v7; // ebx - unsigned char *v8; // [esp+4h] [ebp-4h] + BYTE *v5; // ebx + size_t v6; // edi + char *v7; // ebx + unsigned char *v8; // [esp+4h] [ebp-4h] - v3 = (char *)packet; + v3 = packet; result = a2; v8 = a2; - if ( *(_DWORD *)packet ) - { - v5 = (char *)packet + 4; - while ( *v5 ) - { - v6 = (unsigned char)*v5; - if ( v6 > *a3 ) + if (packet->dwNextWriteOffset) { + v5 = packet->bData; + while (*v5) { + v6 = *v5; + if (v6 > *a3) break; - v7 = v5 + 1; + v7 = (char *)(v5 + 1); memcpy(v8, v7, v6); v8 += v6; - v5 = &v7[v6]; + v5 = (BYTE *)&v7[v6]; *a3 -= v6; } - memcpy(v3 + 4, v5, (size_t)&v3[*(_DWORD *)v3 - (_DWORD)v5 + 5]); - *(_DWORD *)v3 += v3 - v5 + 4; + memcpy(v3->bData, v5, (size_t)&v3->bData[v3->dwNextWriteOffset - (_DWORD)v5 + 1]); /* memcpy_0 */ + v3->dwNextWriteOffset += (char *)v3 - (char *)v5 + 4; result = v8; } return result; } -void __fastcall multi_send_msg_packet(int a1, unsigned char *a2, unsigned char len) +void __fastcall multi_send_msg_packet(int a1, BYTE *a2, BYTE len) { //const void *v3; // edx - signed int v4; // ebx + signed int v4; // ebx unsigned int v5; // edi - TPkt pkt; // [esp+Ch] [ebp-204h] - int v8; // [esp+20Ch] [ebp-4h] + TPkt pkt; // [esp+Ch] [ebp-204h] + int v8; // [esp+20Ch] [ebp-4h] v8 = a1; NetRecvPlrData(&pkt); @@ -208,16 +167,14 @@ void __fastcall multi_send_msg_packet(int a1, unsigned char *a2, unsigned char l memcpy(pkt.body, a2, len); v4 = 1; v5 = 0; - while ( 1 ) - { - if ( v4 & v8 ) - { - if ( !SNetSendMessage(v5, &pkt.hdr, len + 19) && SErrGetLastError() != STORM_ERROR_INVALID_PLAYER ) + while (1) { + if (v4 & v8) { + if (!SNetSendMessage(v5, &pkt.hdr, len + 19) && SErrGetLastError() != STORM_ERROR_INVALID_PLAYER) break; } ++v5; v4 *= 2; - if ( v5 >= 4 ) + if (v5 >= 4) return; } nthread_terminate_game("SNetSendMessage"); @@ -228,30 +185,26 @@ void __cdecl multi_msg_countdown() int v0; // esi v0 = 0; - do - { - if ( player_state[v0] & 0x20000 ) - { - if ( gdwMsgLenTbl[v0] == 4 ) + do { + if (player_state[v0] & 0x20000) { + if (gdwMsgLenTbl[v0] == 4) multi_parse_turn(v0, *(_DWORD *)glpMsgTbl[v0]); } ++v0; - } - while ( v0 < MAX_PLRS ); + } while (v0 < MAX_PLRS); } void __fastcall multi_parse_turn(int pnum, int turn) { - int v2; // esi + int v2; // esi unsigned int v3; // esi v2 = turn; - if ( turn < 0 ) + if (turn < 0) multi_handle_turn_upper_bit(pnum); v3 = v2 & 0x7FFFFFFF; - if ( sgbSentThisCycle < gdwTurnsInTransit + v3 ) - { - if ( v3 >= 0x7FFFFFFF ) + if (sgbSentThisCycle < gdwTurnsInTransit + v3) { + if (v3 >= 0x7FFFFFFF) v3 = (unsigned short)v3; sgbSentThisCycle = v3 + gdwTurnsInTransit; sgdwGameLoops = 4 * v3 * (unsigned char)byte_679704; @@ -265,19 +218,14 @@ void __fastcall multi_handle_turn_upper_bit(int pnum) signed int v1; // eax v1 = 0; - do - { - if ( player_state[v1] & 0x10000 && v1 != pnum ) + do { + if (player_state[v1] & 0x10000 && v1 != pnum) break; ++v1; - } - while ( v1 < MAX_PLRS ); - if ( myplr == v1 ) - { + } while (v1 < MAX_PLRS); + if (myplr == v1) { sgbSendDeltaTbl[pnum] = 1; - } - else if ( myplr == pnum ) - { + } else if (myplr == pnum) { gbDeltaSender = v1; } } @@ -295,11 +243,9 @@ void __cdecl multi_clear_left_tbl() int v0; // esi v0 = 0; - do - { - if ( sgbPlayerLeftGameTbl[v0] ) - { - if ( gbBufferMsgs == 1 ) + do { + if (sgbPlayerLeftGameTbl[v0]) { + if (gbBufferMsgs == 1) msg_send_drop_pkt(v0, sgdwPlayerLeftReasonTbl[v0]); else multi_player_left_msg(v0, 1); @@ -307,40 +253,34 @@ void __cdecl multi_clear_left_tbl() sgdwPlayerLeftReasonTbl[v0] = 0; } ++v0; - } - while ( v0 < MAX_PLRS ); + } while (v0 < MAX_PLRS); } // 676194: using guessed type char gbBufferMsgs; void __fastcall multi_player_left_msg(int pnum, int left) { - int v2; // edi - int v3; // ebx - int v4; // esi + int v2; // edi + int v3; // ebx + int v4; // esi char *v5; // eax - int v6; // edi + int v6; // edi v2 = pnum; v3 = left; v4 = pnum; - if ( plr[pnum].plractive ) - { + if (plr[pnum].plractive) { RemovePlrFromMap(pnum); RemovePortalMissile(v2); DeactivatePortal(v2); RemovePlrPortal(v2); RemovePlrMissiles(v2); - if ( v3 ) - { + if (v3) { v5 = "Player '%s' just left the game"; v6 = sgdwPlayerLeftReasonTbl[v2] - 0x40000004; - if ( v6 ) - { - if ( v6 == 2 ) + if (v6) { + if (v6 == 2) v5 = "Player '%s' dropped due to timeout"; - } - else - { + } else { v5 = "Player '%s' killed Diablo and left the game!"; gbSomebodyWonGameKludge = 1; } @@ -352,7 +292,6 @@ void __fastcall multi_player_left_msg(int pnum, int left) } } // 6761B8: using guessed type char gbSomebodyWonGameKludge; -// 67862C: using guessed type char gbActivePlayers; void __cdecl multi_net_ping() { @@ -364,42 +303,33 @@ void __cdecl multi_net_ping() int __cdecl multi_handle_delta() { - int v0; // esi + int v0; // esi int recieved; // [esp+4h] [ebp-4h] - if ( gbGameDestroyed ) - { - gbRunGame = 0; + if (gbGameDestroyed) { + gbRunGame = FALSE; return 0; } v0 = 0; - do - { - if ( sgbSendDeltaTbl[v0] ) - { + do { + if (sgbSendDeltaTbl[v0]) { sgbSendDeltaTbl[v0] = 0; DeltaExportData(v0); } ++v0; - } - while ( v0 < MAX_PLRS ); + } while (v0 < MAX_PLRS); sgbSentThisCycle = nthread_send_and_recv_turn(sgbSentThisCycle, 1); - if ( !nthread_recv_turns(&recieved) ) - { + if (!nthread_recv_turns(&recieved)) { multi_begin_timeout(); return 0; } sgbTimeout = 0; - if ( recieved ) - { - if ( dword_678628 ) - { + if (recieved) { + if (dword_678628) { dword_678628 = 0; - if ( !multi_check_pkt_valid(pkdata_6761C0) ) + if (!multi_check_pkt_valid(&sgHiPriBuf)) NetSendHiPri(0, 0); - } - else - { + } else { NetSendHiPri(0, 0); dword_678628 = 0; } @@ -407,101 +337,84 @@ int __cdecl multi_handle_delta() multi_mon_seeds(); return 1; } -// 525650: using guessed type int gbRunGame; // 678628: using guessed type int dword_678628; // 67862D: using guessed type char gbGameDestroyed; // 679661: using guessed type char sgbTimeout; // Microsoft VisualC 2-11/net runtime -int __fastcall multi_check_pkt_valid(char *a1) +int __fastcall multi_check_pkt_valid(TBuffer *a1) { - return *(_DWORD *)a1 == 0; + return a1->dwNextWriteOffset == 0; } void __cdecl multi_mon_seeds() { unsigned int v0; // eax - int v1; // edx - int *v2; // ecx - int v3; // esi + int v1; // edx + int *v2; // ecx + int v3; // esi v0 = _rotr(++sgdwGameLoops, 8); v1 = 0; v2 = &monster[0]._mAISeed; - do - { + do { v3 = v1++ + v0; *v2 = v3; v2 += 57; - } - while ( (signed int)v2 < (signed int)&monster[MAXMONSTERS]._mAISeed ); + } while ((signed int)v2 < (signed int)&monster[MAXMONSTERS]._mAISeed); } void __cdecl multi_begin_timeout() { unsigned char bGroupPlayers; // bl - signed int v1; // eax - signed int nLowestActive; // esi - signed int nLowestPlayer; // edi - signed int v4; // eax - int v5; // edx - unsigned char v6; // [esp+Fh] [ebp-1h] + signed int v1; // eax + signed int nLowestActive; // esi + signed int nLowestPlayer; // edi + signed int v4; // eax + int v5; // edx + unsigned char v6; // [esp+Fh] [ebp-1h] bGroupPlayers = 0; #ifdef _DEBUG - if ( sgbTimeout && !debug_mode_key_i ) + if (sgbTimeout && !debug_mode_key_i) #else - if ( sgbTimeout ) + if (sgbTimeout) #endif { v1 = GetTickCount() - sglTimeoutStart; - if ( v1 <= 20000 ) - { - if ( v1 >= 10000 ) - { + if (v1 <= 20000) { + if (v1 >= 10000) { v6 = 0; nLowestActive = -1; nLowestPlayer = -1; v4 = 0; - do - { + do { v5 = player_state[v4]; - if ( v5 & 0x10000 ) - { - if ( nLowestPlayer == -1 ) + if (v5 & 0x10000) { + if (nLowestPlayer == -1) nLowestPlayer = v4; - if ( v5 & 0x40000 ) - { + if (v5 & 0x40000) { ++bGroupPlayers; - if ( nLowestActive == -1 ) + if (nLowestActive == -1) nLowestActive = v4; - } - else - { + } else { ++v6; } } ++v4; - } - while ( v4 < MAX_PLRS ); - if ( bGroupPlayers >= v6 && (bGroupPlayers != v6 || nLowestPlayer == nLowestActive) ) - { - if ( nLowestActive == myplr ) + } while (v4 < MAX_PLRS); + if (bGroupPlayers >= v6 && (bGroupPlayers != v6 || nLowestPlayer == nLowestActive)) { + if (nLowestActive == myplr) multi_check_drop_player(); - } - else - { + } else { gbGameDestroyed = 1; } } - } - else - { - gbRunGame = 0; + } else { + gbRunGame = FALSE; } } } -// 525650: using guessed type int gbRunGame; // 67862D: using guessed type char gbGameDestroyed; // 678644: using guessed type int sglTimeoutStart; // 679661: using guessed type char sgbTimeout; @@ -512,136 +425,32 @@ void __cdecl multi_check_drop_player() int v1; // eax v0 = 0; - do - { + do { v1 = player_state[v0]; - if ( !(v1 & 0x40000) ) - { - if ( v1 & 0x10000 ) + if (!(v1 & 0x40000)) { + if (v1 & 0x10000) SNetDropPlayer(v0, 0x40000006); } ++v0; - } - while ( v0 < MAX_PLRS ); + } while (v0 < MAX_PLRS); } void __cdecl multi_process_network_packets() { - //int v0; // eax - TPktHdr *v1; // ecx - TPktHdr *v2; // edi - int v3; // eax - bool v4; // zf - unsigned char *v5; // esi - int v6; // ebx - int v7; // eax - int v8; // ecx - int v9; // eax - int v10; // eax - int v11; // esi - int v12; // eax - int v13; // ecx - int v14; // eax - //int v15; // eax - TPktHdr *pkt; // [esp+0h] [ebp-Ch] - int len; // [esp+4h] [ebp-8h] - char arglist[4]; // [esp+8h] [ebp-4h] /* fix, int */ - - multi_clear_left_tbl(); - multi_process_tmsgs(); - //_LOBYTE(v0) = SNetReceiveMessage((int *)arglist, (char **)&pkt, &len); - if ( SNetReceiveMessage((int *)arglist, (char **)&pkt, &len) ) - { - do - { - ++dword_676198; - multi_clear_left_tbl(); - v1 = pkt; - v2 = pkt; - if ( (unsigned int)len >= 0x13 - && *(_DWORD *)arglist < 4u - && pkt->wCheck == 'ip' - && (unsigned short)pkt->wLen == len ) - { - v3 = *(_DWORD *)arglist; - v4 = *(_DWORD *)arglist == myplr; - plr[v3]._pownerx = (unsigned char)pkt->px; - v5 = &v1->py; - plr[v3]._pownery = (unsigned char)v1->py; - if ( !v4 ) - { - v4 = gbBufferMsgs == 1; - plr[v3]._pHitPoints = v1->php; - plr[v3]._pMaxHP = v1->pmhp; - plr[v3]._pBaseStr = (unsigned char)v1->bstr; - plr[v3]._pBaseMag = (unsigned char)v1->bmag; - plr[v3]._pBaseDex = (unsigned char)v1->bdex; - if ( !v4 && plr[v3].plractive && plr[v3]._pHitPoints ) - { - if ( currlevel != plr[v3].plrlevel || plr[v3]._pLvlChanging ) - { - plr[v3].WorldX = (unsigned char)v1->px; - plr[v3].WorldY = (unsigned char)*v5; - plr[v3]._px = (unsigned char)v1->px; - plr[v3]._py = (unsigned char)*v5; - plr[v3]._ptargx = (unsigned char)v1->targx; - plr[v3]._ptargy = (unsigned char)v1->targy; - } - else - { - v6 = abs(plr[v3].WorldX - (unsigned char)v1->px); - v7 = abs(plr[*(_DWORD *)arglist].WorldY - (unsigned char)*v5); - if ( (v6 > 3 || v7 > 3) && !dPlayer[(unsigned char)v2->px][(unsigned char)*v5] ) - { - FixPlrWalkTags(*(int *)arglist); - v8 = *(_DWORD *)arglist; - v9 = *(_DWORD *)arglist; - plr[v9]._poldx = plr[*(_DWORD *)arglist].WorldX; - plr[v9]._poldy = plr[v9].WorldY; - FixPlrWalkTags(v8); - v10 = *(_DWORD *)arglist; - plr[v10].WorldX = (unsigned char)v2->px; - plr[v10].WorldY = (unsigned char)*v5; - plr[v10]._px = (unsigned char)v2->px; - plr[v10]._py = (unsigned char)*v5; - dPlayer[plr[v10].WorldX][plr[v10].WorldY] = arglist[0] + 1; - } - v11 = abs(plr[*(_DWORD *)arglist]._px - plr[*(_DWORD *)arglist].WorldX); - v12 = abs(plr[*(_DWORD *)arglist]._py - plr[*(_DWORD *)arglist].WorldY); - v13 = *(_DWORD *)arglist; - if ( v11 > 1 || v12 > 1 ) - { - v14 = *(_DWORD *)arglist; - plr[v14]._px = plr[*(_DWORD *)arglist].WorldX; - plr[v14]._py = plr[v13].WorldY; - } - MakePlrPath(v13, (unsigned char)v2->targx, (unsigned char)v2->targy, 1u); - } - } - } - multi_handle_all_packets(*(int *)arglist, (TPkt *)&v2[1], len - 19); - } - //_LOBYTE(v15) = SNetReceiveMessage((int *)arglist, (char **)&pkt, &len); - } - while ( SNetReceiveMessage((int *)arglist, (char **)&pkt, &len) ); - } - if ( SErrGetLastError() != STORM_ERROR_NO_MESSAGES_WAITING ) - nthread_terminate_game("SNetReceiveMsg"); } // 676194: using guessed type char gbBufferMsgs; -// 676198: using guessed type int dword_676198; +// 676198: using guessed type int pkt_counter; void __fastcall multi_handle_all_packets(int players, TPkt *packet, int a3) { TCmd *v3; // esi - int i; // edi - int v5; // eax + int i; // edi + int v5; // eax v3 = (TCmd *)packet; - for ( i = players; a3; a3 -= v5 ) - { + for (i = players; a3; a3 -= v5) { v5 = ParseCmd(i, v3); - if ( !v5 ) + if (!v5) break; v3 += v5; } @@ -649,13 +458,12 @@ void __fastcall multi_handle_all_packets(int players, TPkt *packet, int a3) void __cdecl multi_process_tmsgs() { - int v0; // eax + int v0; // eax TPkt pkt; // [esp+0h] [ebp-200h] - while ( 1 ) - { - v0 = tmsg_get((unsigned char *)&pkt, 512); - if ( !v0 ) + while (1) { + v0 = tmsg_get((BYTE *)&pkt, 512); + if (!v0) break; multi_handle_all_packets(myplr, &pkt, v0); } @@ -663,19 +471,18 @@ void __cdecl multi_process_tmsgs() void __fastcall multi_send_zero_packet(int pnum, char a2, void *pbSrc, int dwLen) { - unsigned int v4; // edi - short v5; // si + unsigned int v4; // edi + short v5; // si unsigned short dwBody; // ax - TPkt pkt; // [esp+Ch] [ebp-208h] - int pnuma; // [esp+20Ch] [ebp-8h] - int v10; // [esp+210h] [ebp-4h] + TPkt pkt; // [esp+Ch] [ebp-208h] + int pnuma; // [esp+20Ch] [ebp-8h] + int v10; // [esp+210h] [ebp-4h] v4 = dwLen; _LOBYTE(v10) = a2; pnuma = pnum; v5 = 0; - while ( v4 ) - { + while (v4) { pkt.hdr.wCheck = 'ip'; pkt.body[0] = v10; dwBody = gdwLargestMsgSize - 24; @@ -689,13 +496,12 @@ void __fastcall multi_send_zero_packet(int pnum, char a2, void *pbSrc, int dwLen pkt.hdr.bmag = 0; pkt.hdr.bdex = 0; *(_WORD *)&pkt.body[1] = v5; - if ( v4 < gdwLargestMsgSize - 24 ) + if (v4 < gdwLargestMsgSize - 24) dwBody = v4; *(_WORD *)&pkt.body[3] = dwBody; memcpy(&pkt.body[5], pbSrc, dwBody); pkt.hdr.wLen = *(_WORD *)&pkt.body[3] + 24; - if ( !SNetSendMessage(pnuma, &pkt.hdr, *(unsigned short *)&pkt.body[3] + 24) ) - { + if (!SNetSendMessage(pnuma, &pkt.hdr, *(unsigned short *)&pkt.body[3] + 24)) { nthread_terminate_game("SNetSendMessage2"); return; } @@ -708,8 +514,7 @@ void __fastcall multi_send_zero_packet(int pnum, char a2, void *pbSrc, int dwLen void __cdecl NetClose() { - if ( sgbNetInited ) - { + if (sgbNetInited) { sgbNetInited = 0; nthread_cleanup(); dthread_cleanup(); @@ -717,7 +522,7 @@ void __cdecl NetClose() multi_event_handler(0); SNetLeaveGame(3); msgcmd_cmd_cleanup(); - if ( (unsigned char)gbMaxPlayers > 1u ) + if ((unsigned char)gbMaxPlayers > 1u) Sleep(2000); } } @@ -726,63 +531,59 @@ void __cdecl NetClose() char __fastcall multi_event_handler(int a1) { - int v1; // edi - void *(__stdcall *v2)(int, void (__stdcall *)(_SNETEVENT *)); // ebx - unsigned int v3; // esi - int v4; // eax - char *v5; // eax + int v1; // edi + void *(__stdcall * v2)(int, void(__stdcall *)(_SNETEVENT *)); // ebx + unsigned int v3; // esi + int v4; // eax + char *v5; // eax v1 = a1; v2 = SNetRegisterEventHandler; - if ( !a1 ) + if (!a1) v2 = SNetUnregisterEventHandler; v3 = 0; - do - { + do { v4 = (int)v2(event_types[v3], multi_handle_events); - if ( !v4 && v1 ) - { + if (!v4 && v1) { v5 = TraceLastError(); TermMsg("SNetRegisterEventHandler:\n%s", v5); } ++v3; - } - while ( v3 < 3 ); + } while (v3 < 3); return v4; } void __stdcall multi_handle_events(_SNETEVENT *pEvt) { - int v1; // ecx + int v1; // ecx int *v2; // eax int *v3; // eax - switch ( pEvt->eventid ) - { - case EVENT_TYPE_PLAYER_CREATE_GAME: - v3 = (int *)pEvt->data; - sgGameInitInfo.dwSeed = *v3; - _LOBYTE(sgGameInitInfo.bDiff) = *((_BYTE *)v3 + 4); - sgbPlayerTurnBitTbl[pEvt->playerid] = 1; - break; - case EVENT_TYPE_PLAYER_LEAVE_GAME: - v1 = 0; - sgbPlayerLeftGameTbl[pEvt->playerid] = 1; - sgbPlayerTurnBitTbl[pEvt->playerid] = 0; - v2 = (int *)pEvt->data; - if ( v2 && pEvt->databytes >= 4u ) - v1 = *v2; - sgdwPlayerLeftReasonTbl[pEvt->playerid] = v1; - if ( v1 == 0x40000004 ) - gbSomebodyWonGameKludge = 1; - sgbSendDeltaTbl[pEvt->playerid] = 0; - dthread_remove_player(pEvt->playerid); - if ( (unsigned char)gbDeltaSender == pEvt->playerid ) - gbDeltaSender = 4; - break; - case EVENT_TYPE_PLAYER_MESSAGE: - ErrorPlrMsg((char *)pEvt->data); - break; + switch (pEvt->eventid) { + case EVENT_TYPE_PLAYER_CREATE_GAME: + v3 = (int *)pEvt->data; + sgGameInitInfo.dwSeed = *v3; + _LOBYTE(sgGameInitInfo.bDiff) = *((_BYTE *)v3 + 4); + sgbPlayerTurnBitTbl[pEvt->playerid] = 1; + break; + case EVENT_TYPE_PLAYER_LEAVE_GAME: + v1 = 0; + sgbPlayerLeftGameTbl[pEvt->playerid] = 1; + sgbPlayerTurnBitTbl[pEvt->playerid] = 0; + v2 = (int *)pEvt->data; + if (v2 && pEvt->databytes >= 4u) + v1 = *v2; + sgdwPlayerLeftReasonTbl[pEvt->playerid] = v1; + if (v1 == 0x40000004) + gbSomebodyWonGameKludge = 1; + sgbSendDeltaTbl[pEvt->playerid] = 0; + dthread_remove_player(pEvt->playerid); + if (gbDeltaSender == pEvt->playerid) + gbDeltaSender = 4; + break; + case EVENT_TYPE_PLAYER_MESSAGE: + ErrorPlrMsg((char *)pEvt->data); + break; } } // 6761B8: using guessed type char gbSomebodyWonGameKludge; @@ -793,21 +594,20 @@ int __fastcall NetInit(int bSinglePlayer, int *pfExitProgram) int v2; // ebx int v4; // eax //int v5; // ecx - bool v7; // zf + BOOLEAN v7; // zf //int v9; // eax //int v10; // eax _SNETPROGRAMDATA ProgramData; // [esp+8h] [ebp-A8h] - _SNETUIDATA UiData; // [esp+44h] [ebp-6Ch] - _SNETPLAYERDATA a2; // [esp+94h] [ebp-1Ch] - int v14; // [esp+A4h] [ebp-Ch] - unsigned int len; // [esp+A8h] [ebp-8h] - int *a4; // [esp+ACh] [ebp-4h] + _SNETUIDATA UiData; // [esp+44h] [ebp-6Ch] + _SNETPLAYERDATA a2; // [esp+94h] [ebp-1Ch] + int v14; // [esp+A4h] [ebp-Ch] + unsigned int len; // [esp+A8h] [ebp-8h] + int *a4; // [esp+ACh] [ebp-4h] a4 = pfExitProgram; v14 = bSinglePlayer; v2 = 0; - while ( 1 ) - { + while (1) { *a4 = 0; SetRndSeed(0); sgGameInitInfo.dwSeed = time(NULL); @@ -827,17 +627,17 @@ int __fastcall NetInit(int bSinglePlayer, int *pfExitProgram) a2.size = 16; memset(&UiData, 0, 0x50u); UiData.size = 80; - UiData.parentwindow = SDrawGetFrameWindow(0); - UiData.artcallback = (void (__cdecl *)())UiArtCallback; - UiData.createcallback = (void (__cdecl *)())UiCreateGameCallback; - UiData.drawdesccallback = (void (__cdecl *)())UiDrawDescCallback; - UiData.messageboxcallback = (void (__cdecl *)())UiMessageBoxCallback; - UiData.soundcallback = (void (__cdecl *)())UiSoundCallback; - UiData.authcallback = (void (__cdecl *)())UiAuthCallback; - UiData.getdatacallback = (void (__cdecl *)())UiGetDataCallback; - UiData.categorycallback = (void (__cdecl *)())UiCategoryCallback; + UiData.parentwindow = SDrawGetFrameWindow(NULL); + UiData.artcallback = (void(__cdecl *)())UiArtCallback; + UiData.createcallback = (void(__cdecl *)())UiCreateGameCallback; + UiData.drawdesccallback = (void(__cdecl *)())UiDrawDescCallback; + UiData.messageboxcallback = (void(__cdecl *)())UiMessageBoxCallback; + UiData.soundcallback = (void(__cdecl *)())UiSoundCallback; + UiData.authcallback = (void(__cdecl *)())UiAuthCallback; + UiData.getdatacallback = (void(__cdecl *)())UiGetDataCallback; + UiData.categorycallback = (void(__cdecl *)())UiCategoryCallback; UiData.selectnamecallback = mainmenu_select_hero_dialog; - UiData.changenamecallback = (void (__cdecl *)())mainmenu_create_hero; + UiData.changenamecallback = (void(__cdecl *)())mainmenu_create_hero; UiData.profilebitmapcallback = UiProfileDraw; UiData.profilecallback = UiProfileCallback; UiData.profilefields = UiProfileGetString(); @@ -849,18 +649,18 @@ int __fastcall NetInit(int bSinglePlayer, int *pfExitProgram) memset(plr, 0, 0x15360u); memset(sgwPackPlrOffsetTbl, 0, 8u); SNetSetBasePlayer(0); - if ( v14 ) + if (v14) v4 = multi_init_single(&ProgramData, &a2, &UiData); else v4 = multi_init_multi(&ProgramData, &a2, &UiData, a4); - if ( !v4 ) + if (!v4) return 0; sgbNetInited = 1; sgbTimeout = 0; delta_init(); InitPlrMsg(); - multi_clear_pkt(pkdata_6761C0); - multi_clear_pkt(pkdata_678658); + buffer_init(&sgHiPriBuf); + buffer_init(&sgLoPriBuf); dword_678628 = 0; sync_clear_pkt(); nthread_start(sgbPlayerTurnBitTbl[myplr]); @@ -876,47 +676,46 @@ int __fastcall NetInit(int bSinglePlayer, int *pfExitProgram) gbActivePlayers = 1; v7 = sgbPlayerTurnBitTbl[myplr] == 0; plr[myplr].plractive = 1; - if ( v7 || msg_wait_resync() ) + if (v7 || msg_wait_resync()) break; NetClose(); byte_678640 = 0; } gnDifficulty = _LOBYTE(sgGameInitInfo.bDiff); SetRndSeed(sgGameInitInfo.dwSeed); - do - { + do { glSeedTbl[v2] = GetRndSeed(); gnLevelTypeTbl[v2] = InitNewSeed(v2); ++v2; - } - while ( v2 < 17 ); + } while (v2 < 17); //_LOBYTE(v9) = SNetGetGameInfo(GAMEINFO_NAME, szPlayerName, 128, len); - if ( !SNetGetGameInfo(GAMEINFO_NAME, szPlayerName, 128, &len) ) + /* + if (!SNetGetGameInfo(GAMEINFO_NAME, szPlayerName, 128, &len)) nthread_terminate_game("SNetGetGameInfo1"); //_LOBYTE(v10) = SNetGetGameInfo(GAMEINFO_PASSWORD, szPlayerDescript, 128, len); - if ( !SNetGetGameInfo(GAMEINFO_PASSWORD, szPlayerDescript, 128, &len) ) + if (!SNetGetGameInfo(GAMEINFO_PASSWORD, szPlayerDescript, 128, &len)) nthread_terminate_game("SNetGetGameInfo2"); + * */ return 1; } // 6761B8: using guessed type char gbSomebodyWonGameKludge; // 678628: using guessed type int dword_678628; -// 67862C: using guessed type char gbActivePlayers; // 67862D: using guessed type char gbGameDestroyed; // 678640: using guessed type char byte_678640; // 679661: using guessed type char sgbTimeout; // 6796E4: using guessed type char gbDeltaSender; // 6796E8: using guessed type int sgbNetInited; -void __fastcall multi_clear_pkt(char *a1) +void __fastcall buffer_init(TBuffer *pBuf) { - *(_DWORD *)a1 = 0; - a1[4] = 0; + pBuf->dwNextWriteOffset = 0; + pBuf->bData[0] = 0; } void __fastcall multi_send_pinfo(int pnum, char cmd) { - char v2; // bl - int v3; // esi + char v2; // bl + int v3; // esi PkPlayerStruct pkplr; // [esp+8h] [ebp-4F4h] v2 = cmd; @@ -930,20 +729,15 @@ int __fastcall InitNewSeed(int newseed) int result; // eax result = 0; - if ( newseed ) - { + if (newseed) { result = 1; - if ( newseed < 1 || newseed > 4 ) - { - if ( newseed < 5 || newseed > 8 ) - { - if ( newseed < 9 || newseed > 12 ) + if (newseed < 1 || newseed > 4) { + if (newseed < 5 || newseed > 8) { + if (newseed < 9 || newseed > 12) result = 4; else result = 3; - } - else - { + } else { result = 2; } } @@ -956,8 +750,7 @@ void __cdecl SetupLocalCoords() int x; // ecx int y; // edx - if ( !leveldebug || (unsigned char)gbMaxPlayers > 1u ) - { + if (!leveldebug || (unsigned char)gbMaxPlayers > 1u) { currlevel = 0; leveltype = 0; setlevel = 0; @@ -965,8 +758,7 @@ void __cdecl SetupLocalCoords() x = 75; y = 68; #ifdef _DEBUG - if ( debug_mode_key_inverted_v || debug_mode_key_d ) - { + if (debug_mode_key_inverted_v || debug_mode_key_d) { x = 49; y = 23; } @@ -986,7 +778,6 @@ void __cdecl SetupLocalCoords() plr[myplr].destAction = ACTION_NONE; } // 52572C: using guessed type int leveldebug; -// 5BB1ED: using guessed type char leveltype; // 5CF31D: using guessed type char setlevel; // 679660: using guessed type char gbMaxPlayers; @@ -998,21 +789,17 @@ int __fastcall multi_init_single(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA char *v6; // eax //_LOBYTE(v3) = SNetInitializeProvider(0, client_info, user_info, ui_info, &fileinfo); - if ( SNetInitializeProvider(0, client_info, user_info, ui_info, &fileinfo) ) - { + if (SNetInitializeProvider(0, client_info, user_info, ui_info, &fileinfo)) { ui_info = 0; //_LOBYTE(v5) = SNetCreateGame("local", "local", "local", 0, (char *)&sgGameInitInfo.dwSeed, 8, 1, "local", "local", (int *)&ui_info); - if ( !SNetCreateGame("local", "local", "local", 0, (char *)&sgGameInitInfo.dwSeed, 8, 1, "local", "local", (int *)&ui_info) ) - { + if (!SNetCreateGame("local", "local", "local", 0, (char *)&sgGameInitInfo.dwSeed, 8, 1, "local", "local", (int *)&ui_info)) { v6 = TraceLastError(); TermMsg("SNetCreateGame1:\n%s", v6); } myplr = 0; gbMaxPlayers = 1; result = 1; - } - else - { + } else { SErrGetLastError(); result = 0; } @@ -1023,37 +810,34 @@ int __fastcall multi_init_single(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA int __fastcall multi_init_multi(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info, _SNETUIDATA *ui_info, int *a4) { _SNETPLAYERDATA *v4; // ebx - signed int i; // edi - int a6; // [esp+Ch] [ebp-Ch] - int a2; // [esp+10h] [ebp-8h] - int type; // [esp+14h] [ebp-4h] + signed int i; // edi + int a6; // [esp+Ch] [ebp-Ch] + int a2; // [esp+10h] [ebp-8h] + int type; // [esp+14h] [ebp-4h] v4 = user_info; a2 = (int)client_info; - for ( i = 1; ; i = 0 ) - { + for (i = 1;; i = 0) { type = 0; - if ( byte_678640 ) - { - if ( !UiSelectProvider(0, (_SNETPROGRAMDATA *)a2, v4, ui_info, &fileinfo, &type) - && (!i || SErrGetLastError() != STORM_ERROR_REQUIRES_UPGRADE || !multi_upgrade(a4)) ) - { + if (byte_678640) { + if (!UiSelectProvider(0, (_SNETPROGRAMDATA *)a2, v4, ui_info, &fileinfo, &type) + && (!i || SErrGetLastError() != STORM_ERROR_REQUIRES_UPGRADE || !multi_upgrade(a4))) { return 0; } - if ( type == 'BNET' ) + if (type == 'BNET') plr[0].pBattleNet = 1; } multi_event_handler(1); - if ( UiSelectGame(1, (_SNETPROGRAMDATA *)a2, v4, ui_info, &fileinfo, &a6) ) + if (UiSelectGame(1, (_SNETPROGRAMDATA *)a2, v4, ui_info, &fileinfo, &a6)) break; byte_678640 = 1; } - if ( (unsigned int)a6 >= MAX_PLRS ) + if ((unsigned int)a6 >= MAX_PLRS) return 0; myplr = a6; gbMaxPlayers = MAX_PLRS; pfile_read_player_from_save(); - if ( type == 'BNET' ) + if (type == 'BNET') plr[myplr].pBattleNet = 1; return 1; } @@ -1062,21 +846,17 @@ int __fastcall multi_init_multi(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA * int __fastcall multi_upgrade(int *a1) { - int *v1; // esi + int *v1; // esi int result; // eax int status; // [esp+4h] [ebp-4h] v1 = a1; SNetPerformUpgrade((unsigned long *)&status); result = 1; - if ( status && status != 1 ) - { - if ( status == 2 ) - { + if (status && status != 1) { + if (status == 2) { *v1 = 1; - } - else if ( status == -1 ) - { + } else if (status == -1) { DrawDlg("Network upgrade failed"); } result = 0; @@ -1086,53 +866,46 @@ int __fastcall multi_upgrade(int *a1) void __fastcall multi_player_joins(int pnum, TCmdPlrInfoHdr *cmd, int a3) { - int v3; // ebx + int v3; // ebx TCmdPlrInfoHdr *v4; // edi - short *v5; // esi - int v6; // esi - bool v7; // zf - char *v8; // eax - int v9; // ST08_4 + short *v5; // esi + int v6; // esi + BOOLEAN v7; // zf + char *v8; // eax + int v9; // ST08_4 unsigned char *v10; // edx - int v11; // eax - int v12; // ecx - int v13; // eax + int v11; // eax + int v12; // ecx + int v13; // eax v3 = pnum; v4 = cmd; - if ( myplr != pnum ) - { + if (myplr != pnum) { v5 = &sgwPackPlrOffsetTbl[pnum]; - if ( *v5 == cmd->wOffset || (*v5 = 0, !cmd->wOffset) ) - { - if ( !a3 && !*v5 ) - { + if (*v5 == cmd->wOffset || (*v5 = 0, !cmd->wOffset)) { + if (!a3 && !*v5) { multi_send_pinfo(pnum, CMD_ACK_PLRINFO); } memcpy((char *)&netplr[v3] + (unsigned short)v4->wOffset, &v4[1], (unsigned short)v4->wBytes); *v5 += v4->wBytes; - if ( *v5 == 1266 ) - { + if (*v5 == 1266) { *v5 = 0; multi_player_left_msg(v3, 0); v6 = v3; plr[v3]._pGFXLoad = 0; UnPackPlayer(&netplr[v3], v3, 1); - if ( a3 ) - { + if (a3) { ++gbActivePlayers; v7 = sgbPlayerTurnBitTbl[v3] == 0; plr[v6].plractive = 1; v8 = "Player '%s' (level %d) just joined the game"; - if ( v7 ) + if (v7) v8 = "Player '%s' (level %d) is already in the game"; EventPlrMsg(v8, plr[v6]._pName, plr[v6]._pLevel); LoadPlrGFX(v3, PFILE_STAND); SyncInitPlr(v3); - if ( plr[v6].plrlevel == currlevel ) - { - if ( (signed int)(plr[v6]._pHitPoints & 0xFFFFFFC0) <= 0 ) - { + if (plr[v6].plrlevel == currlevel) { + if (plr[v6]._pHitPoints >> 6 <= 0) { plr[v6]._pgfxnum = 0; LoadPlrGFX(v3, PFILE_DEATH); v9 = plr[v6]._pDWidth; @@ -1145,9 +918,7 @@ void __fastcall multi_player_joins(int pnum, TCmdPlrInfoHdr *cmd, int a3) v13 = plr[v6].WorldX; plr[v6]._pAnimFrame = v12; dFlags[v13][plr[v6].WorldY] |= DFLAG_DEAD_PLAYER; - } - else - { + } else { StartStand(v3, 0); } } @@ -1156,4 +927,3 @@ void __fastcall multi_player_joins(int pnum, TCmdPlrInfoHdr *cmd, int a3) } } } -// 67862C: using guessed type char gbActivePlayers; diff --git a/Source/multi.h b/Source/multi.h index 4f95bbcbf..f13643506 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -3,40 +3,26 @@ #define __MULTI_H__ extern char gbSomebodyWonGameKludge; // weak -extern char pkdata_6761C0[4100]; extern char szPlayerDescript[128]; extern short sgwPackPlrOffsetTbl[MAX_PLRS]; extern PkPlayerStruct netplr[MAX_PLRS]; -extern char sgbPlayerTurnBitTbl[MAX_PLRS]; -extern char sgbPlayerLeftGameTbl[MAX_PLRS]; -extern int multi_cpp_init_value; // weak -extern int sgbSentThisCycle; // idb extern int dword_678628; // weak -extern char gbActivePlayers; // weak +extern BYTE gbActivePlayers; extern char gbGameDestroyed; // weak -extern char sgbSendDeltaTbl[MAX_PLRS]; -extern _gamedata sgGameInitInfo; -extern char byte_678640; // weak -extern int sglTimeoutStart; // weak -extern int sgdwPlayerLeftReasonTbl[MAX_PLRS]; -extern char pkdata_678658[4100]; -extern unsigned int sgdwGameLoops; // idb -extern UCHAR gbMaxPlayers; -extern char sgbTimeout; // weak +extern char byte_678640; // weak +extern BYTE gbMaxPlayers; extern char szPlayerName[128]; -extern char gbDeltaSender; // weak -extern int sgbNetInited; // weak +extern BYTE gbDeltaSender; // weak extern int player_state[MAX_PLRS]; -void __cdecl multi_cpp_init(); -void __fastcall multi_msg_add(unsigned char *a1, unsigned char a2); -void __fastcall NetSendLoPri(unsigned char *pbMsg, unsigned char bLen); -void __fastcall multi_copy_packet(void *a1, void *packet, int size); -void __fastcall multi_send_packet(void *packet, int dwSize); +void __fastcall multi_msg_add(BYTE *a1, unsigned char a2); +void __fastcall NetSendLoPri(BYTE *pbMsg, BYTE bLen); +void __fastcall multi_copy_packet(TBuffer *a1, void *packet, BYTE size); +void __fastcall multi_send_packet(void *packet, BYTE dwSize); void __fastcall NetRecvPlrData(TPkt *pkt); -void __fastcall NetSendHiPri(unsigned char *pbMsg, unsigned char bLen); -unsigned char *__fastcall multi_recv_packet(void *packet, unsigned char *a2, int *a3); -void __fastcall multi_send_msg_packet(int a1, unsigned char *a2, unsigned char len); +void __fastcall NetSendHiPri(BYTE *pbMsg, BYTE bLen); +unsigned char *__fastcall multi_recv_packet(TBuffer *packet, unsigned char *a2, int *a3); +void __fastcall multi_send_msg_packet(int a1, BYTE *a2, BYTE len); void __cdecl multi_msg_countdown(); void __fastcall multi_parse_turn(int pnum, int turn); void __fastcall multi_handle_turn_upper_bit(int pnum); @@ -45,7 +31,7 @@ void __cdecl multi_clear_left_tbl(); void __fastcall multi_player_left_msg(int pnum, int left); void __cdecl multi_net_ping(); int __cdecl multi_handle_delta(); -int __fastcall multi_check_pkt_valid(char *a1); +int __fastcall multi_check_pkt_valid(TBuffer *a1); void __cdecl multi_mon_seeds(); void __cdecl multi_begin_timeout(); void __cdecl multi_check_drop_player(); @@ -57,7 +43,7 @@ void __cdecl NetClose(); char __fastcall multi_event_handler(int a1); void __stdcall multi_handle_events(_SNETEVENT *pEvt); int __fastcall NetInit(int bSinglePlayer, int *pfExitProgram); -void __fastcall multi_clear_pkt(char *a1); +void __fastcall buffer_init(TBuffer *pBuf); void __fastcall multi_send_pinfo(int pnum, char cmd); int __fastcall InitNewSeed(int newseed); void __cdecl SetupLocalCoords(); diff --git a/Stub/sdlrender.cpp b/Stub/sdlrender.cpp index 241420b2d..5d4e4ab4f 100644 --- a/Stub/sdlrender.cpp +++ b/Stub/sdlrender.cpp @@ -909,8 +909,8 @@ void SDL_RenderDiabloMainPage() PrintText16Silver(17, 444, gszProductName); - ADD_PlrStringXY(0, 600 - 150, 640, "DedicaTed To David Brevik, Erich Schaefer, Max Schaefer,", COL_BLUE);// Red isn't red - ADD_PlrStringXY(0, 600 - 130, 640, " MaTT Uelman, and The Blizzard North Team ThaT Gave Us A Childhood.", COL_BLUE); + //ADD_PlrStringXY(0, 600 - 150, 640, "DedicaTed To David Brevik, Erich Schaefer, Max Schaefer,", COL_BLUE);// Red isn't red + //ADD_PlrStringXY(0, 600 - 130, 640, " MaTT Uelman, and The Blizzard North Team ThaT Gave Us A Childhood.", COL_BLUE); } void SDL_RenderDiabloSinglePlayerPage() diff --git a/defs.h b/defs.h index 3489bd732..37148c89e 100644 --- a/defs.h +++ b/defs.h @@ -118,6 +118,7 @@ typedef ull uint64; #define _WORD uint16 #define _DWORD uint32 #define _QWORD uint64 +#define BOOLEAN bool // Some convenience macros to make partial accesses nicer #define LAST_IND(x,part_type) (sizeof(x)/sizeof(part_type) - 1) diff --git a/structs.h b/structs.h index 0b0be4be8..4a7bbc082 100644 --- a/structs.h +++ b/structs.h @@ -1008,6 +1008,11 @@ struct TMegaPkt unsigned char data[32000]; }; +typedef struct TBuffer { + DWORD dwNextWriteOffset; + BYTE bData[4096]; +} TBuffer; + ////////////////////////////////////////////////// // quests ////////////////////////////////////////////////// From c0f0e2d25bab4ede539342a435348d6625087865 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 19 Jan 2019 02:40:11 +0100 Subject: [PATCH 3/6] Add missing build files --- CMake/FindSDL2_mixer.cmake | 88 ++++++++++++++++++++++++++++++++++++++ build/.gitkeep | 0 2 files changed, 88 insertions(+) create mode 100644 CMake/FindSDL2_mixer.cmake create mode 100644 build/.gitkeep diff --git a/CMake/FindSDL2_mixer.cmake b/CMake/FindSDL2_mixer.cmake new file mode 100644 index 000000000..913765b70 --- /dev/null +++ b/CMake/FindSDL2_mixer.cmake @@ -0,0 +1,88 @@ +# - Locate SDL2_mixer library +# This module defines: +# SDL2_MIXER_LIBRARIES, the name of the library to link against +# SDL2_MIXER_INCLUDE_DIRS, where to find the headers +# SDL2_MIXER_FOUND, if false, do not try to link against +# SDL2_MIXER_VERSION_STRING - human-readable string containing the version of SDL2_mixer +# +# For backward compatiblity the following variables are also set: +# SDLMIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES) +# SDLMIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS) +# SDLMIXER_FOUND (same value as SDL2_MIXER_FOUND) +# +# $SDLDIR is an environment variable that would +# correspond to the ./configure --prefix=$SDLDIR +# used in building SDL. +# +# Created by Eric Wing. This was influenced by the FindSDL.cmake +# module, but with modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). + +#============================================================================= +# Copyright 2005-2009 Kitware, Inc. +# Copyright 2012 Benjamin Eikel +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(NOT SDL2_MIXER_INCLUDE_DIR AND SDLMIXER_INCLUDE_DIR) + set(SDL2_MIXER_INCLUDE_DIR ${SDLMIXER_INCLUDE_DIR} CACHE PATH "directory cache +entry initialized from old variable name") +endif() +find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h + HINTS + ENV SDLMIXERDIR + ENV SDLDIR + PATH_SUFFIXES include/SDL2 include/SDL2.0 include +) + +if(NOT SDL2_MIXER_LIBRARY AND SDLMIXER_LIBRARY) + set(SDL2_MIXER_LIBRARY ${SDLMIXER_LIBRARY} CACHE FILEPATH "file cache entry +initialized from old variable name") +endif() +find_library(SDL2_MIXER_LIBRARY + NAMES SDL2_mixer + HINTS + ENV SDLMIXERDIR + ENV SDLDIR + PATH_SUFFIXES lib +) + +if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL2_mixer.h") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL2_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL2_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL2_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_MIXER_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL2_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_MIXER_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") + set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) + unset(SDL2_MIXER_VERSION_MAJOR_LINE) + unset(SDL2_MIXER_VERSION_MINOR_LINE) + unset(SDL2_MIXER_VERSION_PATCH_LINE) + unset(SDL2_MIXER_VERSION_MAJOR) + unset(SDL2_MIXER_VERSION_MINOR) + unset(SDL2_MIXER_VERSION_PATCH) +endif() + +set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) +set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer + REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS + VERSION_VAR SDL2_MIXER_VERSION_STRING) + +# for backward compatiblity +set(SDLMIXER_LIBRARY ${SDL2_MIXER_LIBRARIES}) +set(SDLMIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS}) +set(SDLMIXER_FOUND ${SDL2_MIXER_FOUND}) + +mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 000000000..e69de29bb From 238a6d6c2a9cf17f89315a55d4d00516e9a56e53 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 20 Jan 2019 16:19:56 +0100 Subject: [PATCH 4/6] Move all menu code to stub files Lets us much more easily merge upstream --- CMakeLists.txt | 1 - Source/gmenu.cpp | 402 ++++++--------------------------------------- Source/gmenu.h | 16 +- Stub/diabloui.cpp | 45 +++++ Stub/init.cpp | 1 - Stub/miniwin_sdl.h | 119 -------------- Stub/sdlrender.cpp | 267 ++++++++++++++++++++++++++++-- Stub/sdlrender.h | 96 +++++++++-- types.h | 4 - 9 files changed, 442 insertions(+), 509 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4860e552..f403f2bd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,7 +124,6 @@ set(STUB_SOURCES Stub/miniwin_msg_sdl.cpp Stub/storm_net.cpp #Stub/validate.cpp - Stub/effects.cpp Stub/sdlrender.cpp Stub/diablo.cpp Stub/gamemenu.cpp diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 0dca836d3..0bd757ac9 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -1,84 +1,19 @@ //HEADER_GOES_HERE #include "../types.h" -#include "miniwin_sdl.h" -#include "sdlrender.h" -#ifndef NO_GLOBALS -bool byte_634464; // weak +void *optbar_cel; +BOOLEAN byte_634464; // weak +void *PentSpin_cel; TMenuItem *sgpCurrItem; - +void *BigTGold_cel; int dword_634474; // weak char byte_634478; // weak void(__cdecl *dword_63447C)(); TMenuItem *dword_634480; // idb -int dword_63448C; // weak - -void *pPentSmall; -void *BigTGold_cel; - -//int gb_Lfont_pix_width; -//int gb_Lfont_str_len; - -int gdwLogoWidth; -int gdwLogoHeight; -void *pPcxLogoImage; - -int gdwTitleWidth; -int gdwTitleHeight; -void *pPcxTitleImage; - -int gdwCursorWidth; -int gdwCursorHeight; -void *pPcxCursorImage; - -int gdwHeroHeight; -int gdwHeroWidth; -void *pPcxHeroImage; - -int gdwSHeroHeight; -int gdwSHeroWidth; - -int gdwFont16Width; -int gdwFont16Height; -void *pPcxFont16sImage; -void *pPcxFont16gImage; -unsigned char *pFont16; - -int gdwFont24Width; -int gdwFont24Height; -void *pPcxFont24gImage; -unsigned char *pFont24; - -int gdwFont30Width; -int gdwFont30Height; -void *pPcxFont30sImage; -void *pPcxFont30gImage; -unsigned char *pFont30; - -int gdwFont42Width; -int gdwFont42Height; -void *pPcxFont42gImage; -void *pPcxFont42yImage; -unsigned char *pFont42; - - -void *GameTitle; -int GameTitleHeight; -int GameTitleWidth; - -void *TitleMenuText; -void *MenuPentegram16; -void *MenuPentegram42; - -void *optbar_cel; -void *PentSpin_cel; void *option_cel; void *sgpLogo; -void *pTitlgrayCel_sgpBackCel; -void *pDiabfrCel; - -#endif +int dword_63448C; // weak const unsigned char lfontframe[127] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -115,202 +50,6 @@ void __cdecl gmenu_draw_pause() } // 69BEF8: using guessed type int light_table_index; -PALETTEENTRY pcxPal[256]; - -void __fastcall LoadPalInMem(PALETTEENTRY *pPal) -{ - int i; // eax - - for (i = 0; i < 256; i++) { - orig_palette[i].peFlags = 0; - orig_palette[i].peRed = pPal[i].peRed; - orig_palette[i].peGreen = pPal[i].peGreen; - orig_palette[i].peBlue = pPal[i].peBlue; - } -} - -BOOL __cdecl LoadArtImage(char *pszFile, void **pBuffer, int frames, DWORD *data) -{ - DWORD width; // [esp+44h] [ebp-8h] - DWORD height; // [esp+48h] [ebp-4h] MAPDST - - *pBuffer = NULL; - - if (!SBmpLoadImage(pszFile, 0, 0, 0, &width, &height, 0)) - return 0; - *pBuffer = SMemAlloc(height * width, "U:\\DiabloUI\\Ui\\local.cpp", 88); - if (!SBmpLoadImage(pszFile, NULL, *pBuffer, height * width, 0, 0, 0)) - return 0; - if (pBuffer && data) { - data[0] = width; - data[1] = height / frames; - } - return 1; -} - -BOOL __cdecl LoadArtWithPal(char *pszFile, void **pBuffer, int frames, DWORD *data) -{ - DWORD width; // [esp+44h] [ebp-8h] - DWORD height; // [esp+48h] [ebp-4h] MAPDST - - *pBuffer = NULL; - - if (!SBmpLoadImage(pszFile, 0, 0, 0, &width, &height, 0)) - return 0; - *pBuffer = SMemAlloc(height * width, "U:\\DiabloUI\\Ui\\local.cpp", 88); - if (!SBmpLoadImage(pszFile, pcxPal, *pBuffer, height * width, 0, 0, 0)) - return 0; - - LoadPalInMem(pcxPal); - - //lpDDPalette->SetEntries(0, 0, 256, orig_palette); - - if (pBuffer && data) { - data[0] = width; - data[1] = height / frames; - } - return 1; -} - -BOOL __stdcall SBmpLoadImage(const char *pszFileName, PALETTEENTRY *pPalette, void *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *dwHeight, DWORD *pdwBpp) -{ - char *v7; // ebx - unsigned char *v8; // edi - PALETTEENTRY *v9; // esi - int v10; // esi - signed int v11; // ebx - int v12; // ebp - size_t v13; // ebp - unsigned char *v14; // eax - unsigned char *v15; // edx - int v16; // ebp - unsigned char v17; // cl - unsigned char v18; // al - int v19; // ecx - bool v20; // zf - bool v21; // sf - unsigned char(*v22)[3]; // eax - BYTE v23; // cl - unsigned char *Memory; // [esp+14h] [ebp-38Ch] - HANDLE hFile; // [esp+18h] [ebp-388h] MAPDST - DWORD v28; // [esp+1Ch] [ebp-384h] - PCXHeader pcxhdr; // [esp+20h] [ebp-380h] - unsigned char paldata[256][3]; // [esp+A0h] [ebp-300h] - int z; - - if (pdwWidth) - *pdwWidth = 0; - if (dwHeight) - *dwHeight = 0; - if (pdwBpp) - *pdwBpp = 0; - v7 = (char *)pszFileName; - if (pszFileName) { - if (*pszFileName) { - v8 = (unsigned char *)pBuffer; - if (!pBuffer || dwBuffersize) { - v9 = pPalette; - if (pPalette || pBuffer || pdwWidth || dwHeight) { - if (SFileOpenFile(pszFileName, &hFile)) { - if (strchr(pszFileName, 92)) { - do - v7 = strchr(v7, 92) + 1; - while (strchr(v7, 92)); - } - for (; strchr(v7 + 1, 46); v7 = strchr(v7, 46)) - ; - if (!v7 || _strcmpi(v7, ".pcx")) // omit all types except PCX - { - return 0; - //v10 = sub_15001C70(hFile, pPalette, pBuffer, dwBuffersize, pdwWidth, dwHeight, pdwBpp); - //goto LABEL_51; - } - if (!SFileReadFile(hFile, &pcxhdr, 128u, 0, 0)) { - v10 = 0; - LABEL_51: - SFileCloseFile(hFile); - return v10; - } - *(_DWORD *)&paldata[0][0] = pcxhdr.xmax - pcxhdr.xmin + 1; - v11 = pcxhdr.ymax - pcxhdr.ymin + 1; - v28 = pcxhdr.bitsPerPixel; - if (pdwWidth) - *pdwWidth = *(_DWORD *)&paldata[0][0]; - if (dwHeight) - *dwHeight = v11; - if (pdwBpp) - *pdwBpp = v28; - if (!pBuffer) { - SFileSetFilePointer(hFile, 0, 0, 2); - goto LABEL_45; - } - v12 = SFileGetFileSize(hFile, 0); - v13 = v12 - SFileSetFilePointer(hFile, 0, 0, 1); - v14 = (unsigned char *)SMemAlloc(v13, "SBMP.CPP", 171); - Memory = v14; - if (!v14) { - LABEL_45: - if (pPalette && v28 == 8) { - SFileSetFilePointer(hFile, -768, 0, 1); - SFileReadFile(hFile, paldata, 768u, 0, 0); - v22 = paldata; - for (z = 0; z < 256; z++) { - v23 = *(_BYTE *)v22; - ++v9; - ++v22; - v9[-1].peRed = v23; - v9[-1].peGreen = (*v22)[-2]; - v9[-1].peBlue = (*v22)[-1]; - v9[-1].peFlags = 0; - } - } - v10 = 1; - goto LABEL_51; - } - SFileReadFile(hFile, v14, v13, 0, 0); - v15 = Memory; - if (v11 <= 0) - goto LABEL_43; - LABEL_33: - v16 = *(_DWORD *)&paldata[0][0]; - while (1) { - v17 = *v15++; - if (v17 < 0xC0u) { - *v8++ = v17; - --v16; - } else { - v18 = *v15; - v19 = v17 & 0x3F; - ++v15; - for (; v19; --v16) { - v20 = v16 == 0; - v21 = v16 < 0; - if (!v16) - goto LABEL_41; - *v8++ = v18; - --v19; - } - } - v20 = v16 == 0; - v21 = v16 < 0; - LABEL_41: - if (v21 || v20) { - if (!--v11) { - LABEL_43: - SMemFree(Memory, "SBMP.CPP", 178); - goto LABEL_45; - } - goto LABEL_33; - } - } - } - } - } - } - } - return 0; -} - void __fastcall gmenu_print_text(int x, int y, char *pszStr) { char *v3; // edi @@ -319,82 +58,62 @@ void __fastcall gmenu_print_text(int x, int y, char *pszStr) unsigned char i; // al unsigned char v7; // bl - //printf("X:%d Y: %d \n", x, y ); v3 = pszStr; v4 = y; v5 = x; - for (i = *pszStr; *v3; i = *v3) { ++v3; v7 = lfontframe[fontidx[i]]; if (v7) - if (gbRunGame == 1) { - //CelDecodeLightOnly(v5, v4, (char *)BigTGold_cel, v7, 46); - DrawArtWithMask(v5 - 90, v4 - 250, 42, 42, 0, 242, pPcxFont42gImage); - } else { - DrawArtWithMask(v5 - 90, v4 - 250, 42, 42, 0, 242, pPcxFont42gImage); - } - + CelDecodeLightOnly(v5, v4, (char *)BigTGold_cel, v7, 46); v5 += lfontkern[v7] + 2; } } void __cdecl FreeGMenu() { + void *v0; // ecx + void *v1; // ecx + void *v2; // ecx + void *v3; // ecx + void *v4; // ecx + + v0 = sgpLogo; + sgpLogo = 0; + mem_free_dbg(v0); + v1 = BigTGold_cel; + BigTGold_cel = 0; + mem_free_dbg(v1); + v2 = PentSpin_cel; + PentSpin_cel = 0; + mem_free_dbg(v2); + v3 = option_cel; + option_cel = 0; + mem_free_dbg(v3); + v4 = optbar_cel; + optbar_cel = 0; + mem_free_dbg(v4); } void __cdecl gmenu_init_menu() { - DWORD dwData[2]; byte_634478 = 1; dword_634480 = 0; sgpCurrItem = 0; dword_63447C = 0; dword_63448C = 0; byte_634464 = 0; - - LoadArtImage("ui_art\\focus16.pcx", &MenuPentegram16, 8, dwData); - LoadArtImage("ui_art\\focus42.pcx", &MenuPentegram42, 8, dwData); - - LoadArtImage("ui_art\\cursor.pcx", &pPcxCursorImage, 1, dwData); - gdwCursorWidth = dwData[0]; - gdwCursorHeight = dwData[1]; - - LoadArtImage("ui_art\\smlogo.pcx", &pPcxLogoImage, 15, dwData); - gdwLogoWidth = dwData[0]; - gdwLogoHeight = dwData[1]; - - LoadArtImage("ui_art\\heros.pcx", &pPcxHeroImage, 4, dwData); - gdwHeroWidth = dwData[0]; - gdwHeroHeight = dwData[1]; - - pFont16 = LoadFileInMem("ui_art\\font16.bin", 0); - LoadArtImage("ui_art\\font16s.pcx", &pPcxFont16sImage, 256, NULL); - LoadArtImage("ui_art\\font16g.pcx", &pPcxFont16gImage, 256, dwData); - gdwFont16Width = dwData[0]; - gdwFont16Height = dwData[1]; - - pFont24 = LoadFileInMem("ui_art\\font24.bin", 0); - LoadArtImage("ui_art\\font24g.pcx", &pPcxFont24gImage, 256, dwData); - gdwFont24Width = dwData[0]; - gdwFont24Height = dwData[1]; - - pFont30 = LoadFileInMem("ui_art\\font30.bin", 0); - LoadArtImage("ui_art\\font30s.pcx", &pPcxFont30sImage, 256, NULL); - LoadArtImage("ui_art\\font30g.pcx", &pPcxFont30gImage, 256, dwData); - gdwFont30Width = dwData[0]; - gdwFont30Height = dwData[1]; - - pFont42 = LoadFileInMem("ui_art\\font42.bin", 0); - LoadArtImage("ui_art\\font42g.pcx", &pPcxFont42gImage, 256, dwData); - gdwFont42Width = dwData[0]; - gdwFont42Height = dwData[1]; + sgpLogo = LoadFileInMem("Data\\Diabsmal.CEL", 0); + BigTGold_cel = LoadFileInMem("Data\\BigTGold.CEL", 0); + PentSpin_cel = LoadFileInMem("Data\\PentSpin.CEL", 0); + option_cel = LoadFileInMem("Data\\option.CEL", 0); + optbar_cel = LoadFileInMem("Data\\optbar.CEL", 0); } // 634464: using guessed type char byte_634464; // 634478: using guessed type char byte_634478; // 63448C: using guessed type int dword_63448C; -bool __cdecl gmenu_exception() +BOOL __cdecl gmenu_exception() { return dword_634480 != 0; } @@ -475,7 +194,7 @@ void __cdecl gmenu_draw() if (dword_634480) { if (dword_63447C) dword_63447C(); - // CelDecodeOnly(236, 262, sgpLogo, 1, 296); + CelDecodeOnly(236, 262, sgpLogo, 1, 296); v0 = 320; for (i = dword_634480; i->fnMenu; v0 += 45) { gmenu_draw_menu_item(i, v0); @@ -508,15 +227,6 @@ void __fastcall gmenu_draw_menu_item(TMenuItem *pItem, int a2) int v13; // edi unsigned int v14; // [esp+10h] [ebp-4h] - int MyPcxDelay = 60; - int MyPcxFRAME = (SDL_GetTicks() / MyPcxDelay) % 15; - MyPcxFRAME++; - if (MyPcxFRAME == 15) { - MyPcxFRAME = 0; - } - - DrawArtWithMask(GetCenterOffset(gdwLogoWidth), -50, gdwLogoWidth, gdwLogoHeight, MyPcxFRAME, 250, pPcxLogoImage); - v2 = a2; v3 = pItem; v4 = gmenu_get_lfont(pItem); @@ -524,7 +234,7 @@ void __fastcall gmenu_draw_menu_item(TMenuItem *pItem, int a2) v14 = v4; if (v3->dwFlags & 0x40000000) { v6 = (v4 >> 1) + 80; - //CelDecodeOnly(v6, v2 - 10, optbar_cel, 1, 287); + CelDecodeOnly(v6, v2 - 10, optbar_cel, 1, 287); v7 = (v3->dwFlags >> 12) & 0xFFF; if (v7 < 2) v7 = 2; @@ -532,7 +242,7 @@ void __fastcall gmenu_draw_menu_item(TMenuItem *pItem, int a2) v9 = (v5 >> 1) + 82; v10 = v8; gmenu_clear_buffer(v9, v2 - 12, v8 + 13, 28); - //CelDecodeOnly(v6 + v10 + 2, v2 - 12, option_cel, 1, 27); + CelDecodeOnly(v6 + v10 + 2, v2 - 12, option_cel, 1, 27); v5 = v14; } v11 = 384 - (v5 >> 1); @@ -542,9 +252,8 @@ void __fastcall gmenu_draw_menu_item(TMenuItem *pItem, int a2) gmenu_print_text(384 - (v5 >> 1), v2, v3->pszStr); if (v3 == sgpCurrItem) { v13 = v2 + 1; - - //CelDecodeOnly(v11 - 54, v13, PentSpin_cel, (unsigned char)byte_634478, 48); - //CelDecodeOnly(v11 + v5 + 4, v13, PentSpin_cel, (unsigned char)byte_634478, 48); + CelDecodeOnly(v11 - 54, v13, PentSpin_cel, (unsigned char)byte_634478, 48); + CelDecodeOnly(v11 + v5 + 4, v13, PentSpin_cel, (unsigned char)byte_634478, 48); } } // 634478: using guessed type char byte_634478; @@ -580,11 +289,8 @@ int __fastcall gmenu_get_lfont(TMenuItem *pItem) return i - 2; } -int __fastcall gmenu_presskeys(int a1) +BOOL __fastcall gmenu_presskeys(int a1) { - int v1; // ecx - int v2; // ecx - if (!dword_634480) return 0; switch (a1) { @@ -593,31 +299,27 @@ int __fastcall gmenu_presskeys(int a1) PlaySFX(IS_TITLEMOV); ((void(__fastcall *)(signed int))sgpCurrItem->fnMenu)(1); } - return 1; + break; case VK_ESCAPE: PlaySFX(IS_TITLEMOV); gmenu_call_proc(0, 0); - return 1; + break; case VK_SPACE: - return 0; + return FALSE; case VK_LEFT: - v2 = 0; - goto LABEL_12; - case VK_UP: - v1 = 0; - goto LABEL_10; + gmenu_left_right(0); + break; case VK_RIGHT: - v2 = 1; - LABEL_12: - gmenu_left_right(v2); - return 1; + gmenu_left_right(1); + break; + case VK_UP: + gmenu_up_down(0); + break; case VK_DOWN: - v1 = 1; - LABEL_10: - gmenu_up_down(v1); + gmenu_up_down(1); break; } - return 1; + return TRUE; } void __fastcall gmenu_left_right(int a1) @@ -664,7 +366,7 @@ int __fastcall gmenu_on_mouse_move(LPARAM lParam) // 41A37A: could not find valid save-restore pair for esi // 634464: using guessed type char byte_634464; -bool __fastcall gmenu_valid_mouse_pos(int *plOffset) +BOOLEAN __fastcall gmenu_valid_mouse_pos(int *plOffset) { *plOffset = 282; if (MouseX < 282) { diff --git a/Source/gmenu.h b/Source/gmenu.h index 791524b19..f719a819d 100644 --- a/Source/gmenu.h +++ b/Source/gmenu.h @@ -2,34 +2,32 @@ #ifndef __GMENU_H__ #define __GMENU_H__ -extern bool byte_634464; // weak +extern void *optbar_cel; +extern BOOLEAN byte_634464; // weak extern void *PentSpin_cel; -extern TMenuItem *sgpCurrItem; extern void *BigTGold_cel; -extern void *GameTitle; extern int dword_634474; // weak extern char byte_634478; // weak -extern void (__cdecl *dword_63447C)(); +extern void(__cdecl *dword_63447C)(); extern TMenuItem *dword_634480; // idb extern void *option_cel; -extern void *sgpLogo; extern int dword_63448C; // weak void __cdecl gmenu_draw_pause(); void __fastcall gmenu_print_text(int x, int y, char *pszStr); void __cdecl FreeGMenu(); void __cdecl gmenu_init_menu(); -bool __cdecl gmenu_exception(); -void __fastcall gmenu_call_proc(TMenuItem *pItem, void (__cdecl *gmFunc)()); +BOOL __cdecl gmenu_exception(); +void __fastcall gmenu_call_proc(TMenuItem *pItem, void(__cdecl *gmFunc)()); void __fastcall gmenu_up_down(int a1); void __cdecl gmenu_draw(); void __fastcall gmenu_draw_menu_item(TMenuItem *pItem, int a2); void __fastcall gmenu_clear_buffer(int x, int y, int width, int height); int __fastcall gmenu_get_lfont(TMenuItem *pItem); -int __fastcall gmenu_presskeys(int a1); +BOOL __fastcall gmenu_presskeys(int a1); void __fastcall gmenu_left_right(int a1); int __fastcall gmenu_on_mouse_move(LPARAM lParam); -bool __fastcall gmenu_valid_mouse_pos(int *plOffset); +BOOLEAN __fastcall gmenu_valid_mouse_pos(int *plOffset); int __fastcall gmenu_left_mouse(int a1); void __fastcall gmenu_enable(TMenuItem *pMenuItem, BOOL enable); void __fastcall gmenu_slider_1(TMenuItem *pItem, int min, int max, int gamma); diff --git a/Stub/diabloui.cpp b/Stub/diabloui.cpp index cfd345ccb..8f6a690c2 100644 --- a/Stub/diabloui.cpp +++ b/Stub/diabloui.cpp @@ -3,6 +3,7 @@ #include "../types.h" #include "sdlrender.h" #include "stubs.h" + int menu = 0; int SelectedItem = 1; int SelectedItemMax = 1; @@ -11,6 +12,7 @@ int MenuItem[10] = { 5, 0, 1, 0, 0, 0, 0, 0, 0, 0 }; void __cdecl UiDestroy() { DUMMY(); + FreeMenuItems(); } BOOL __stdcall UiTitleDialog(int a1) @@ -82,11 +84,54 @@ BOOL IsInsideRect(int x, int y, SDL_Rect rect) return IsInside(x, y, rect.x, rect.y, rect.w, rect.h); } +void LoadUiGFX() // I anticipate to move this later. +{ + DWORD dwData[2]; + + LoadArtImage("ui_art\\focus16.pcx", &MenuPentegram16, 8, dwData); + LoadArtImage("ui_art\\focus42.pcx", &MenuPentegram42, 8, dwData); + + LoadArtImage("ui_art\\cursor.pcx", &pPcxCursorImage, 1, dwData); + gdwCursorWidth = dwData[0]; + gdwCursorHeight = dwData[1]; + + LoadArtImage("ui_art\\smlogo.pcx", &pPcxLogoImage, 15, dwData); + gdwLogoWidth = dwData[0]; + gdwLogoHeight = dwData[1]; + + LoadArtImage("ui_art\\heros.pcx", &pPcxHeroImage, 4, dwData); + gdwHeroWidth = dwData[0]; + gdwHeroHeight = dwData[1]; + + pFont16 = LoadFileInMem("ui_art\\font16.bin", 0); + LoadArtImage("ui_art\\font16s.pcx", &pPcxFont16sImage, 256, NULL); + LoadArtImage("ui_art\\font16g.pcx", &pPcxFont16gImage, 256, dwData); + gdwFont16Width = dwData[0]; + gdwFont16Height = dwData[1]; + + pFont24 = LoadFileInMem("ui_art\\font24.bin", 0); + LoadArtImage("ui_art\\font24g.pcx", &pPcxFont24gImage, 256, dwData); + gdwFont24Width = dwData[0]; + gdwFont24Height = dwData[1]; + + pFont30 = LoadFileInMem("ui_art\\font30.bin", 0); + LoadArtImage("ui_art\\font30s.pcx", &pPcxFont30sImage, 256, NULL); + LoadArtImage("ui_art\\font30g.pcx", &pPcxFont30gImage, 256, dwData); + gdwFont30Width = dwData[0]; + gdwFont30Height = dwData[1]; + + pFont42 = LoadFileInMem("ui_art\\font42.bin", 0); + LoadArtImage("ui_art\\font42g.pcx", &pPcxFont42gImage, 256, dwData); + gdwFont42Width = dwData[0]; + gdwFont42Height = dwData[1]; +} + void UiInitialize() // I anticipate to move this later. { //SDL_SetRelativeMouseMode(SDL_TRUE); // WNDPROC saveProc; + LoadUiGFX(); snd_init(0); music_start(5); diff --git a/Stub/init.cpp b/Stub/init.cpp index 29b764794..a1eb0ec34 100644 --- a/Stub/init.cpp +++ b/Stub/init.cpp @@ -15,7 +15,6 @@ int gbActive; char gszVersionNumber[260] = "internal version unknown"; char gszProductName[260] = "Diablo v1.09"; -char HeroUndecidedName[17] = { 0 }; bool StartNewGame; bool CreateSinglePlayerChar; int HeroChosen = 0; diff --git a/Stub/miniwin_sdl.h b/Stub/miniwin_sdl.h index 46bb8690d..074df8cd5 100644 --- a/Stub/miniwin_sdl.h +++ b/Stub/miniwin_sdl.h @@ -17,8 +17,6 @@ extern SDL_Surface *surface; extern SDL_Palette *palette; extern SDL_Surface *pal_surface; -extern bool TitleImageLoaded; - void sdl_present_surface(); #ifdef __WINDOWS__ @@ -29,121 +27,4 @@ void sdl_present_surface(); #define GetCurrentDir getcwd #endif -extern unsigned char *pFont16; -extern int gdwFont16Width; -extern int gdwFont16Height; -extern void *pPcxFont16sImage; -extern void *pPcxFont16gImage; - -extern int gdwFont24Width; -extern int gdwFont24Height; -extern void *pPcxFont24gImage; -extern unsigned char *pFont24; - -extern unsigned char *pFont30; -extern int gdwFont30Width; -extern int gdwFont30Height; -extern void *pPcxFont30sImage; -extern void *pPcxFont30gImage; - -extern unsigned char *pFont42; -extern int gdwFont42Width; -extern int gdwFont42Height; -extern void *pPcxFont42gImage; - void sdl_update_entire_surface(); - -//My SDL inclusions // - -extern bool SorcerorCreateSelected; -extern bool WarriorCreateSelected; -extern bool RogueCreateSelected; - -extern int totalFrames; -//extern SDL_Texture* spriteSheet; -extern SDL_Surface *DiabloTitle; -extern SDL_Event input; - -extern int SCREEN_WIDTH; -extern int SCREEN_HEIGHT; -extern int TotalPlayers; - -extern SDL_Rect textureRect; -extern SDL_Rect windowRect; - -//Menu0 //Main Menu rects -extern SDL_Rect SinglePlrBox; -extern SDL_Rect MultiPlrBox; -extern SDL_Rect ReplayIntroBox; -extern SDL_Rect ShowCreditsBox; -extern SDL_Rect ExitBox; - -// - -//CEL Gobals ?? Doesn't work? -extern void *BigTGold_cel; -extern void *pTitlqtxtCel; -extern void *pDiabfrCel; -extern void *BigTGold_cel; -extern int gdwLogoWidth; -extern int gdwLogoHeight; -extern void *pPcxLogoImage; -extern void *pTitlgrayCel_sgpBackCel; -extern int gdwTitleWidth; -extern int gdwTitleHeight; -extern void *pPcxTitleImage; -extern int gdwCursorHeight; -extern int gdwCursorWidth; -extern void *pPcxCursorImage; -extern int gdwHeroHeight; -extern int gdwHeroWidth; -extern void *pPcxHeroImage; -extern int gdwSHeroHeight; -extern int gdwSHeroWidth; -extern void *pPcxSHeroImage; -extern void *pMedTextCels; - -extern void *pPcxGameImage; -extern void *pPcxCreditsImage; -extern int gdwCreditsWidth; -extern int gdwCreditsHeight; - -extern char HeroUndecidedName[17]; -extern bool StartNewGame; -extern bool CreateSinglePlayerChar; -extern int HeroChosen; - -extern void *TitleMenuText; - -extern void *MenuPentegram16; -extern void *MenuPentegram42; - -//Menu2 // Single player menu rects -//extern static std::vector<_uiheroinfo> hero_infos; -extern SDL_Rect SinglePlayerMenuCancelBox; -extern SDL_Rect CreateHeroBox; -void CreateMenuDialogBox(); -void CreateDiabloMainMenuz(); -void SdlDiabloMainWindow(); -void SDL_RenderDiabloMainPage(); -char *GetWorkingDirectory(); -void CreateMainDiabloMenu(); -void SDLCreateDiabloCursor(); -void SDL_RenderDiabloSinglePlayerPage(); -void ShowCredts(); -void RenderCharNames(); -void SDL_Diablo_UI(); -void FreeMenuItems(); -void DrawMouse(); -void DrawCursor(int mx, int my); -void CreateHeroMenu(); -void DrawNewHeroImage(int image, int ShowClasses); -void RenderUndecidedHeroName(); -void LoadHeroStats(); -void RenderDefaultStats(int HeroChosen); -void DrawPreGameOptions(int image, int ShowClasses); -void DrawPreGameDifficultySelection(int image, int ShowClasses); - -typedef unsigned char BYTE; -void DrawPCXString(int x, int y, int w, int h, char *str, BYTE *font, void *pBuff); -void DrawArtWithMask(int SX, int SY, int SW, int SH, int nFrame, BYTE bMask, void *pBuffer); diff --git a/Stub/sdlrender.cpp b/Stub/sdlrender.cpp index 5d4e4ab4f..635cf5747 100644 --- a/Stub/sdlrender.cpp +++ b/Stub/sdlrender.cpp @@ -35,6 +35,60 @@ bool DiabloImageLoaded = 0; bool DiabloMainMenuListLoaded = 0; bool TitleImageLoaded = false; +int gdwLogoWidth; +int gdwLogoHeight; +void *pPcxLogoImage; + +int gdwTitleWidth; +int gdwTitleHeight; +void *pPcxTitleImage; + +int gdwCursorWidth; +int gdwCursorHeight; +void *pPcxCursorImage; + +int gdwHeroHeight; +int gdwHeroWidth; +void *pPcxHeroImage; + +int gdwSHeroHeight; +int gdwSHeroWidth; + +int gdwFont16Width; +int gdwFont16Height; +void *pPcxFont16sImage; +void *pPcxFont16gImage; +unsigned char *pFont16; + +int gdwFont24Width; +int gdwFont24Height; +void *pPcxFont24gImage; +unsigned char *pFont24; + +int gdwFont30Width; +int gdwFont30Height; +void *pPcxFont30sImage; +void *pPcxFont30gImage; +unsigned char *pFont30; + +int gdwFont42Width; +int gdwFont42Height; +void *pPcxFont42gImage; +void *pPcxFont42yImage; +unsigned char *pFont42; + +void *GameTitle; +int GameTitleHeight; +int GameTitleWidth; + +void *TitleMenuText; +void *MenuPentegram16; +void *MenuPentegram42; + +void *pDiabfrCel; + +char HeroUndecidedName[17]; + _uiheroinfo heroarray[10]; struct timespec ts; @@ -564,24 +618,209 @@ int linecount = 24; int nottheend = 1; ///////////////////////////////////////// +PALETTEENTRY pcxPal[256]; + +void __fastcall LoadPalInMem(PALETTEENTRY *pPal) +{ + int i; // eax + + for (i = 0; i < 256; i++) { + orig_palette[i].peFlags = 0; + orig_palette[i].peRed = pPal[i].peRed; + orig_palette[i].peGreen = pPal[i].peGreen; + orig_palette[i].peBlue = pPal[i].peBlue; + } +} + +BOOL __cdecl LoadArtImage(char *pszFile, void **pBuffer, int frames, DWORD *data) +{ + DWORD width; // [esp+44h] [ebp-8h] + DWORD height; // [esp+48h] [ebp-4h] MAPDST + + *pBuffer = NULL; + + if (!SBmpLoadImage(pszFile, 0, 0, 0, &width, &height, 0)) + return 0; + *pBuffer = SMemAlloc(height * width, "U:\\DiabloUI\\Ui\\local.cpp", 88); + if (!SBmpLoadImage(pszFile, NULL, *pBuffer, height * width, 0, 0, 0)) + return 0; + if (pBuffer && data) { + data[0] = width; + data[1] = height / frames; + } + return 1; +} + +BOOL __cdecl LoadArtWithPal(char *pszFile, void **pBuffer, int frames, DWORD *data) +{ + DWORD width; // [esp+44h] [ebp-8h] + DWORD height; // [esp+48h] [ebp-4h] MAPDST + + *pBuffer = NULL; + + if (!SBmpLoadImage(pszFile, 0, 0, 0, &width, &height, 0)) + return 0; + *pBuffer = SMemAlloc(height * width, "U:\\DiabloUI\\Ui\\local.cpp", 88); + if (!SBmpLoadImage(pszFile, pcxPal, *pBuffer, height * width, 0, 0, 0)) + return 0; + + LoadPalInMem(pcxPal); + + //lpDDPalette->SetEntries(0, 0, 256, orig_palette); + + if (pBuffer && data) { + data[0] = width; + data[1] = height / frames; + } + return 1; +} + +BOOL __stdcall SBmpLoadImage(const char *pszFileName, PALETTEENTRY *pPalette, void *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *dwHeight, DWORD *pdwBpp) +{ + char *v7; // ebx + unsigned char *v8; // edi + PALETTEENTRY *v9; // esi + int v10; // esi + signed int v11; // ebx + int v12; // ebp + size_t v13; // ebp + unsigned char *v14; // eax + unsigned char *v15; // edx + int v16; // ebp + unsigned char v17; // cl + unsigned char v18; // al + int v19; // ecx + bool v20; // zf + bool v21; // sf + unsigned char(*v22)[3]; // eax + BYTE v23; // cl + unsigned char *Memory; // [esp+14h] [ebp-38Ch] + HANDLE hFile; // [esp+18h] [ebp-388h] MAPDST + DWORD v28; // [esp+1Ch] [ebp-384h] + PCXHeader pcxhdr; // [esp+20h] [ebp-380h] + unsigned char paldata[256][3]; // [esp+A0h] [ebp-300h] + int z; + + if (pdwWidth) + *pdwWidth = 0; + if (dwHeight) + *dwHeight = 0; + if (pdwBpp) + *pdwBpp = 0; + v7 = (char *)pszFileName; + if (pszFileName) { + if (*pszFileName) { + v8 = (unsigned char *)pBuffer; + if (!pBuffer || dwBuffersize) { + v9 = pPalette; + if (pPalette || pBuffer || pdwWidth || dwHeight) { + if (SFileOpenFile(pszFileName, &hFile)) { + if (strchr(pszFileName, 92)) { + do + v7 = strchr(v7, 92) + 1; + while (strchr(v7, 92)); + } + for (; strchr(v7 + 1, 46); v7 = strchr(v7, 46)) + ; + if (!v7 || _strcmpi(v7, ".pcx")) // omit all types except PCX + { + return 0; + //v10 = sub_15001C70(hFile, pPalette, pBuffer, dwBuffersize, pdwWidth, dwHeight, pdwBpp); + //goto LABEL_51; + } + if (!SFileReadFile(hFile, &pcxhdr, 128u, 0, 0)) { + v10 = 0; + LABEL_51: + SFileCloseFile(hFile); + return v10; + } + *(_DWORD *)&paldata[0][0] = pcxhdr.xmax - pcxhdr.xmin + 1; + v11 = pcxhdr.ymax - pcxhdr.ymin + 1; + v28 = pcxhdr.bitsPerPixel; + if (pdwWidth) + *pdwWidth = *(_DWORD *)&paldata[0][0]; + if (dwHeight) + *dwHeight = v11; + if (pdwBpp) + *pdwBpp = v28; + if (!pBuffer) { + SFileSetFilePointer(hFile, 0, 0, 2); + goto LABEL_45; + } + v12 = SFileGetFileSize(hFile, 0); + v13 = v12 - SFileSetFilePointer(hFile, 0, 0, 1); + v14 = (unsigned char *)SMemAlloc(v13, "SBMP.CPP", 171); + Memory = v14; + if (!v14) { + LABEL_45: + if (pPalette && v28 == 8) { + SFileSetFilePointer(hFile, -768, 0, 1); + SFileReadFile(hFile, paldata, 768u, 0, 0); + v22 = paldata; + for (z = 0; z < 256; z++) { + v23 = *(_BYTE *)v22; + ++v9; + ++v22; + v9[-1].peRed = v23; + v9[-1].peGreen = (*v22)[-2]; + v9[-1].peBlue = (*v22)[-1]; + v9[-1].peFlags = 0; + } + } + v10 = 1; + goto LABEL_51; + } + SFileReadFile(hFile, v14, v13, 0, 0); + v15 = Memory; + if (v11 <= 0) + goto LABEL_43; + LABEL_33: + v16 = *(_DWORD *)&paldata[0][0]; + while (1) { + v17 = *v15++; + if (v17 < 0xC0u) { + *v8++ = v17; + --v16; + } else { + v18 = *v15; + v19 = v17 & 0x3F; + ++v15; + for (; v19; --v16) { + v20 = v16 == 0; + v21 = v16 < 0; + if (!v16) + goto LABEL_41; + *v8++ = v18; + --v19; + } + } + v20 = v16 == 0; + v21 = v16 < 0; + LABEL_41: + if (v21 || v20) { + if (!--v11) { + LABEL_43: + SMemFree(Memory, "SBMP.CPP", 178); + goto LABEL_45; + } + goto LABEL_33; + } + } + } + } + } + } + } + return 0; +} void FreeMenuItems() { + void *tmp; - SDL_FreeSurface(MainMenuItemsSurface); - SDL_FreeSurface(MenuSelectNewHeroSurface); - SDL_FreeSurface(CreateHeroDialogSurface); - SDL_FreeSurface(CreateHeroDialogSurface); - SDL_FreeSurface(CursorImg); - SDL_FreeSurface(DiabloTitle); - - SDL_DestroyTexture(MainMenuItemsTexture); - SDL_DestroyTexture(DiablologoAnimT); - SDL_DestroyTexture(CursorTexture); - SDL_DestroyTexture(MenuSelectNewHeroTexture); - SDL_DestroyTexture(CreateHeroDialogTextureW); - SDL_DestroyTexture(CreateHeroDialogTextureR); - SDL_DestroyTexture(CreateHeroDialogTextureS); + tmp = pPcxFont42yImage; + pPcxFont42yImage = NULL; + mem_free_dbg(tmp); } char gLDirectory[FILENAME_MAX]; diff --git a/Stub/sdlrender.h b/Stub/sdlrender.h index 967760b97..d6591bbe5 100644 --- a/Stub/sdlrender.h +++ b/Stub/sdlrender.h @@ -1,22 +1,72 @@ #pragma once -int GetCenterOffset(int w, int bw = 0); +#include "miniwin.h" + +extern unsigned char *pFont16; +extern int gdwFont16Width; +extern int gdwFont16Height; +extern void *pPcxFont16sImage; +extern void *pPcxFont16gImage; + +extern int gdwFont24Width; +extern int gdwFont24Height; +extern void *pPcxFont24gImage; +extern unsigned char *pFont24; + +extern unsigned char *pFont30; +extern int gdwFont30Width; +extern int gdwFont30Height; +extern void *pPcxFont30sImage; +extern void *pPcxFont30gImage; + +extern unsigned char *pFont42; +extern int gdwFont42Width; +extern int gdwFont42Height; +extern void *pPcxFont42gImage; + +extern void *pTitlqtxtCel; +extern void *pDiabfrCel; +extern int gdwLogoWidth; +extern int gdwLogoHeight; +extern void *pPcxLogoImage; +extern int gdwTitleWidth; +extern int gdwTitleHeight; +extern void *pPcxTitleImage; +extern int gdwCursorHeight; +extern int gdwCursorWidth; +extern void *pPcxCursorImage; +extern int gdwHeroHeight; +extern int gdwHeroWidth; +extern void *pPcxHeroImage; +extern int gdwSHeroHeight; +extern int gdwSHeroWidth; +extern void *pPcxSHeroImage; +extern void *pMedTextCels; + +extern void *pPcxGameImage; +extern void *pPcxCreditsImage; +extern int gdwCreditsWidth; +extern int gdwCreditsHeight; + +extern bool TitleImageLoaded; + +//My SDL inclusions // +extern bool SorcerorCreateSelected; +extern bool WarriorCreateSelected; +extern bool RogueCreateSelected; -/* extern int totalFrames; //extern SDL_Texture* spriteSheet; -extern SDL_Surface* DiabloTitle; +extern SDL_Surface *DiabloTitle; extern SDL_Event input; -extern FC_Font* font; + extern int SCREEN_WIDTH; extern int SCREEN_HEIGHT; extern int TotalPlayers; - extern SDL_Rect textureRect; extern SDL_Rect windowRect; - //Menu0 //Main Menu rects extern SDL_Rect SinglePlrBox; extern SDL_Rect MultiPlrBox; @@ -24,17 +74,41 @@ extern SDL_Rect ReplayIntroBox; extern SDL_Rect ShowCreditsBox; extern SDL_Rect ExitBox; -//Menu2 // Single player menu rects -extern SDL_Rect SinglePlayerMenuCancelBox; +extern bool StartNewGame; +extern bool CreateSinglePlayerChar; +extern int HeroChosen; + +extern void *TitleMenuText; +extern void *MenuPentegram16; +extern void *MenuPentegram42; +extern char HeroUndecidedName[17]; + +extern SDL_Rect SinglePlayerMenuCancelBox; +extern SDL_Rect CreateHeroBox; +void CreateMenuDialogBox(); void CreateDiabloMainMenuz(); void SdlDiabloMainWindow(); void SDL_RenderDiabloMainPage(); char *GetWorkingDirectory(); -void CreateMainDiabloMenu(); +void CreateMainDiabloMenu(); void SDLCreateDiabloCursor(); void SDL_RenderDiabloSinglePlayerPage(); +void ShowCredts(); void RenderCharNames(); - -*/ +void SDL_Diablo_UI(); +void FreeMenuItems(); +BOOL __cdecl LoadArtImage(char *pszFile, void **pBuffer, int frames, DWORD *data); +void DrawMouse(); +void DrawCursor(int mx, int my); +void CreateHeroMenu(); +void DrawNewHeroImage(int image, int ShowClasses); +void RenderUndecidedHeroName(); +void LoadHeroStats(); +void RenderDefaultStats(int HeroChosen); +void DrawPreGameOptions(int image, int ShowClasses); +void DrawPreGameDifficultySelection(int image, int ShowClasses); +int GetCenterOffset(int w, int bw = 0); +void DrawPCXString(int x, int y, int w, int h, char *str, BYTE *font, void *pBuff); +void DrawArtWithMask(int SX, int SY, int SW, int SH, int nFrame, BYTE bMask, void *pBuffer); diff --git a/types.h b/types.h index 2756c5f95..6e73afa76 100644 --- a/types.h +++ b/types.h @@ -3,8 +3,6 @@ #ifndef _TYPES_H #define _TYPES_H - - #include "resource.h" #ifdef MINIWIN @@ -19,8 +17,6 @@ #include #endif - - #ifdef __WIN32__ #define WIN32_LEAN_AND_MEAN From 75301e3cac7ddd26e2315adb8dc90d3cc7ea1e1c Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 20 Jan 2019 18:24:27 +0100 Subject: [PATCH 5/6] Load mpq in read only mode This solves issues for people that have the mpq on read only media. --- 3rdParty/Storm/Source/storm.h | 2 ++ Stub/init.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/3rdParty/Storm/Source/storm.h b/3rdParty/Storm/Source/storm.h index 4e1c032c6..278f2e9c0 100644 --- a/3rdParty/Storm/Source/storm.h +++ b/3rdParty/Storm/Source/storm.h @@ -393,6 +393,8 @@ SNetSendMessage( #define SNPLAYER_ALL -1 #define SNPLAYER_OTHERS -2 +#define MPQ_FLAG_READ_ONLY 1 + /* SNetSendTurn @ 128 * diff --git a/Stub/init.cpp b/Stub/init.cpp index a1eb0ec34..c9d7d8502 100644 --- a/Stub/init.cpp +++ b/Stub/init.cpp @@ -86,10 +86,10 @@ void __cdecl init_archives() { DUMMY(); // We will need to remove the find_file_in_std_directories funct when it comes to mobile - SFileOpenArchive(find_file_in_std_directories("diabdat.mpq").c_str(), 1000, 0, &diabdat_mpq); + SFileOpenArchive(find_file_in_std_directories("diabdat.mpq").c_str(), 1000, MPQ_FLAG_READ_ONLY, &diabdat_mpq); assert(diabdat_mpq); - SFileOpenArchive("patch_rt.mpq", 1000, 0, &patch_rt_mpq); + SFileOpenArchive("patch_rt.mpq", 1000, MPQ_FLAG_READ_ONLY, &patch_rt_mpq); } void GetAvailableHeroes() From 3d392fc0f84ab726b1f10a828f4d65cc39011688 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 20 Jan 2019 19:26:27 +0100 Subject: [PATCH 6/6] Implement splash screen --- Stub/diabloui.cpp | 203 +++++++++++++++++++++++++++------------------ Stub/dx.cpp | 13 ++- Stub/sdlrender.cpp | 84 ++++++++++++------- Stub/sdlrender.h | 9 +- enums.h | 15 ++++ 5 files changed, 204 insertions(+), 120 deletions(-) diff --git a/Stub/diabloui.cpp b/Stub/diabloui.cpp index 8f6a690c2..b765eb8b5 100644 --- a/Stub/diabloui.cpp +++ b/Stub/diabloui.cpp @@ -4,10 +4,11 @@ #include "sdlrender.h" #include "stubs.h" -int menu = 0; -int SelectedItem = 1; -int SelectedItemMax = 1; -int MenuItem[10] = { 5, 0, 1, 0, 0, 0, 0, 0, 0, 0 }; +int menu = SPLASH; +int SelectedItem = 0; +int SelectedItemMax = 0; +int MenuItem[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +int PreviousItem[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; void __cdecl UiDestroy() { @@ -44,7 +45,7 @@ void LoadCharNamesintoMemory() } for (int i = 0; i < MAX_CHARACTERS; i++) { - strcpy(p_hero_names, "32as1d"); + strcpy(p_hero_names, "32as1d"); p_hero_names += 32; } @@ -84,7 +85,28 @@ BOOL IsInsideRect(int x, int y, SDL_Rect rect) return IsInside(x, y, rect.x, rect.y, rect.w, rect.h); } -void LoadUiGFX() // I anticipate to move this later. +void InitHiracy() +{ + MenuItem[MAINMENU] = 5; + MenuItem[SINGLEPLAYER_CLASSES] = 3; + MenuItem[MULTIPLAYER_CONNECTIONS] = 4; + MenuItem[MULTIPLAYER_LOBBY] = 2; + MenuItem[MULTIPLAYER_DIFFICULTY] = 3; + MenuItem[MULTIPLAYER_BNET_GATEWAYS] = 3; + + PreviousItem[SPLASH] = MAINMENU; + PreviousItem[SINGLEPLAYER_LOAD] = MAINMENU; + PreviousItem[SINGLEPLAYER_CLASSES] = SINGLEPLAYER_LOAD; + PreviousItem[SINGLEPLAYER_NAME] = SINGLEPLAYER_CLASSES; + PreviousItem[MULTIPLAYER_CONNECTIONS] = MAINMENU; + PreviousItem[MULTIPLAYER_LOBBY] = MULTIPLAYER_CONNECTIONS; + PreviousItem[MULTIPLAYER_DIFFICULTY] = MULTIPLAYER_LOBBY; + PreviousItem[MULTIPLAYER_BNET_GATEWAYS] = MULTIPLAYER_CONNECTIONS; + PreviousItem[MULTIPLAYER_ERROR] = MAINMENU; + PreviousItem[CREDIT] = MAINMENU; +} + +void LoadUiGFX() { DWORD dwData[2]; @@ -95,10 +117,15 @@ void LoadUiGFX() // I anticipate to move this later. gdwCursorWidth = dwData[0]; gdwCursorHeight = dwData[1]; - LoadArtImage("ui_art\\smlogo.pcx", &pPcxLogoImage, 15, dwData); + printf("logo\n"); + LoadArtImage("ui_art\\logo.pcx", &pPcxLogoImage, 15, dwData); gdwLogoWidth = dwData[0]; gdwLogoHeight = dwData[1]; + LoadArtImage("ui_art\\smlogo.pcx", &pPcxLogoSmImage, 15, dwData); + gdwLogoSmWidth = dwData[0]; + gdwLogoSmHeight = dwData[1]; + LoadArtImage("ui_art\\heros.pcx", &pPcxHeroImage, 4, dwData); gdwHeroWidth = dwData[0]; gdwHeroHeight = dwData[1]; @@ -110,6 +137,7 @@ void LoadUiGFX() // I anticipate to move this later. gdwFont16Height = dwData[1]; pFont24 = LoadFileInMem("ui_art\\font24.bin", 0); + LoadArtImage("ui_art\\font24s.pcx", &pPcxFont24sImage, 256, NULL); LoadArtImage("ui_art\\font24g.pcx", &pPcxFont24gImage, 256, dwData); gdwFont24Width = dwData[0]; gdwFont24Height = dwData[1]; @@ -126,11 +154,13 @@ void LoadUiGFX() // I anticipate to move this later. gdwFont42Height = dwData[1]; } -void UiInitialize() // I anticipate to move this later. +void UiInitialize() { + printf("UiInitialize"); //SDL_SetRelativeMouseMode(SDL_TRUE); // WNDPROC saveProc; + InitHiracy(); LoadUiGFX(); snd_init(0); music_start(5); @@ -139,7 +169,7 @@ void UiInitialize() // I anticipate to move this later. signed int NewHeroNameIndex = 0; - SetMenu(0); + SelectedItemMax = MenuItem[menu]; SDL_Event event; int x, y; bool quit = false; @@ -163,36 +193,39 @@ void UiInitialize() // I anticipate to move this later. PaletteFadeIn(32); switch (menu) { - case 0: + case SPLASH: + SDL_RenderDiabloSplashPage(); + break; + case MAINMENU: SDL_RenderDiabloMainPage(); break; - case 2: + case SINGLEPLAYER_LOAD: SDL_RenderDiabloSinglePlayerPage(); gbMaxPlayers = 1; DrawMouse(); break; - case 3: - CreateHeroMenu(); + case SINGLEPLAYER_CLASSES: + CreateHeroMenu(); // TODO crashes DrawNewHeroImage(HeroPortrait, 1); DrawMouse(); break; - case 4: + case SINGLEPLAYER_NAME: DrawNewHeroImage(HeroPortrait, 0); RenderDefaultStats(HeroPortrait); RenderUndecidedHeroName(); DrawMouse(); break; - case 5: + case MULTIPLAYER_LOBBY: DrawPreGameOptions(HeroPortrait, 1); RenderDefaultStats(HeroPortrait); DrawMouse(); break; - case 6: + case MULTIPLAYER_DIFFICULTY: DrawPreGameDifficultySelection(HeroPortrait, 1); RenderDefaultStats(HeroPortrait); DrawMouse(); break; - case 10: + case CREDIT: ShowCredts(); break; } @@ -202,8 +235,8 @@ void UiInitialize() // I anticipate to move this later. case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: - if (menu != 0) { - SetMenu(0); + if (PreviousItem[menu]) { + SetMenu(PreviousItem[menu]); break; } quit = true; @@ -234,22 +267,31 @@ void UiInitialize() // I anticipate to move this later. break; case SDLK_RETURN: - switch (SelectedItem) { - case MAINMENU_SINGLE_PLAYER: - SetMenu(2); // TODO skip to choose class if no valid saves - break; - case MAINMENU_MULTIPLAYER: - printf("Multi Player\n"); - break; - case MAINMENU_REPLAY_INTRO: - printf("Replay Intro\n"); - break; - case MAINMENU_SHOW_CREDITS: - SetMenu(10); + switch (menu) { + case MAINMENU: + switch (SelectedItem) { + case MAINMENU_SINGLE_PLAYER: + SetMenu(SINGLEPLAYER_LOAD); // TODO skip to choose class if no valid saves + break; + case MAINMENU_MULTIPLAYER: + printf("Multi Player\n"); + break; + case MAINMENU_REPLAY_INTRO: + printf("Replay Intro\n"); + break; + case MAINMENU_SHOW_CREDITS: + SetMenu(CREDIT); + break; + case MAINMENU_EXIT_DIABLO: + quit = true; + ExitDiablo(); + break; + } break; - case MAINMENU_EXIT_DIABLO: - quit = true; - ExitDiablo(); + case SINGLEPLAYER_LOAD: + if (SelectedItem == SelectedItemMax) { + SetMenu(SINGLEPLAYER_NAME); + } break; } break; @@ -302,38 +344,38 @@ void UiInitialize() // I anticipate to move this later. SDL_Rect SorcerorSelectBox; SorcerorSelectBox.y = 428; SorcerorSelectBox.x = 280; - SorcerorSelectBox.w = SorcerorSelectBox.x + 100; - SorcerorSelectBox.h = SorcerorSelectBox.y + 30; + SorcerorSelectBox.w = 100; + SorcerorSelectBox.h = 30; SDL_Rect CreateHeroCancelBox; CreateHeroCancelBox.y = 550; CreateHeroCancelBox.x = 675; - CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100; - CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30; + CreateHeroCancelBox.w = 100; + CreateHeroCancelBox.h = 30; clock_t start, end; double cpu_time_used; switch (menu) { - case 0: + case MAINMENU: ItemTop = 191; ItemHeight = 42; ItemWidth = 515; ItemLeft = GetCenterOffset(ItemWidth); if (IsInside(x, y, ItemLeft, ItemTop, ItemWidth, ItemHeight)) { - SetMenu(2); // TODO skip to choose class if no valid saves + SetMenu(SINGLEPLAYER_LOAD); // TODO skip to choose class if no valid saves } else if (IsInside(x, y, ItemLeft, ItemTop + ItemHeight + 1, ItemWidth, ItemHeight)) { printf("Multi Player\n"); } else if (IsInside(x, y, ItemLeft, ItemTop + ItemHeight * 2 + 1, ItemWidth, ItemHeight)) { printf("Replay Intro\n"); } else if (IsInside(x, y, ItemLeft, ItemTop + ItemHeight * 3 + 2, ItemWidth, ItemHeight)) { - SetMenu(10); + SetMenu(CREDIT); } else if (IsInside(x, y, ItemLeft, ItemTop + ItemHeight * 4 + 3, ItemWidth, ItemHeight)) { quit = true; ExitDiablo(); } break; - case 2: + case SINGLEPLAYER_LOAD: ItemLeft = 440; ItemTop = 315; ItemHeight = 30; @@ -346,49 +388,49 @@ void UiInitialize() // I anticipate to move this later. if (TotalPlayers >= 1 && IsInside(x, y, ItemLeft, ItemTop, ItemWidth, ItemHeight)) { strcpy(chr_name_str, hero_names[0]); printf("Player %s\n", chr_name_str); - SetMenu(5); + SetMenu(MULTIPLAYER_LOBBY); // break; } else if (TotalPlayers >= 2 && IsInside(x, y, ItemLeft, ItemTop + ItemHeight, ItemWidth, ItemHeight)) { printf("Player 2 Diablo\n"); strcpy(chr_name_str, hero_names[1]); printf("Player %s\n", chr_name_str); - SetMenu(5); + SetMenu(MULTIPLAYER_LOBBY); // break; } else if (TotalPlayers >= 3 && IsInside(x, y, ItemLeft, ItemTop + ItemHeight * 2, ItemWidth, ItemHeight)) { printf("Player 3 Diablo\n"); strcpy(chr_name_str, hero_names[2]); printf("Player %s\n", chr_name_str); - SetMenu(5); + SetMenu(MULTIPLAYER_LOBBY); // break; } else if (TotalPlayers >= 4 && IsInside(x, y, ItemLeft, ItemTop + ItemHeight * 3, ItemWidth, ItemHeight)) { printf("Player 4 Diablo\n"); strcpy(chr_name_str, hero_names[3]); printf("Player %s\n", chr_name_str); - SetMenu(5); + SetMenu(MULTIPLAYER_LOBBY); // break; } else if (TotalPlayers >= 5 && IsInside(x, y, ItemLeft, ItemTop + ItemHeight * 4, ItemWidth, ItemHeight)) { printf("Player 5 Diablo\n"); strcpy(chr_name_str, hero_names[4]); printf("Player %s\n", chr_name_str); - SetMenu(5); + SetMenu(MULTIPLAYER_LOBBY); // break; } else if (TotalPlayers >= 6 && IsInside(x, y, ItemLeft, ItemTop + ItemHeight * 5, ItemWidth, ItemHeight)) { printf("Player 6 Diablo\n"); strcpy(chr_name_str, hero_names[5]); printf("Player %s\n", chr_name_str); - SetMenu(5); + SetMenu(MULTIPLAYER_LOBBY); // break; } else if (TotalPlayers >= 6 && IsInsideRect(x, y, CreateHeroCancelBox)) { HeroPortrait = 3; printf("Cancel\n\n\n"); - SetMenu(0); + SetMenu(MAINMENU); } else if (TotalPlayers >= 6 && IsInside(x, y, CreateHeroX + ItemWidth, CreateHeroY, ItemWidth, ItemHeight)) { printf("Clicked Create Hero Box\n"); - SetMenu(3); + SetMenu(SINGLEPLAYER_CLASSES); } break; - case 3: + case SINGLEPLAYER_CLASSES: // SinglePlayerMenuItemsLoaded = 0; printf("\n\nmenu3 X%d Y%d \n ", x, y); @@ -407,14 +449,14 @@ void UiInitialize() // I anticipate to move this later. SDL_Rect WarriorSelectBox; WarriorSelectBox.y = 350; WarriorSelectBox.x = 280; - WarriorSelectBox.w = WarriorSelectBox.x + 100; - WarriorSelectBox.h = WarriorSelectBox.y + 30; + WarriorSelectBox.w = 100; + WarriorSelectBox.h = 30; SDL_Rect RogueSelectBox; RogueSelectBox.y = 392; RogueSelectBox.x = 280; - RogueSelectBox.w = RogueSelectBox.x + 100; - RogueSelectBox.h = RogueSelectBox.y + 30; + RogueSelectBox.w = 100; + RogueSelectBox.h = 30; // X450 Y 392 ; // X 447 Y 428 @@ -422,33 +464,32 @@ void UiInitialize() // I anticipate to move this later. printf(" warrior I was hit\n\n\n"); HeroPortrait = 0; HeroChosen = 0; - SetMenu(4); + SetMenu(SINGLEPLAYER_NAME); } else if (IsInsideRect(x, y, RogueSelectBox)) { printf(" rogue I was hit\n\n\n"); HeroPortrait = 1; HeroChosen = 1; - SetMenu(4); + SetMenu(SINGLEPLAYER_NAME); } else if (IsInsideRect(x, y, SorcerorSelectBox)) { HeroPortrait = 2; printf("sorceror I was hit\n\n\n"); HeroChosen = 2; - SetMenu(4); + SetMenu(SINGLEPLAYER_NAME); } else if (IsInsideRect(x, y, CreateHeroCancelBox)) { HeroPortrait = 3; printf("Cancel\n\n\n"); - SetMenu(3); + SetMenu(SINGLEPLAYER_CLASSES); } break; - case 4: + case SINGLEPLAYER_NAME: printf("Create hero"); - // X 549 , Y 551 SDL_Rect ClickOkBox; - ClickOkBox.y = 550; - ClickOkBox.x = 550; - ClickOkBox.w = ClickOkBox.x + 30; - ClickOkBox.h = ClickOkBox.y + 30; + ClickOkBox.x = 324; + ClickOkBox.y = 430; + ClickOkBox.w = 48; + ClickOkBox.h = 30; if (IsInsideRect(x, y, CreateHeroCancelBox)) { memset(HeroUndecidedName, 0, 17); @@ -457,7 +498,7 @@ void UiInitialize() // I anticipate to move this later. printf("Cancel\n\n\n"); HeroPortrait = 3; - SetMenu(3); + SetMenu(SINGLEPLAYER_CLASSES); } else if (IsInsideRect(x, y, ClickOkBox)) { printf("Ok\n"); CreateSinglePlayerChar = 1; @@ -481,20 +522,20 @@ void UiInitialize() // I anticipate to move this later. SDL_Rect NewGameBox; NewGameBox.y = 350; NewGameBox.x = 280; - NewGameBox.w = NewGameBox.x + 300; - NewGameBox.h = NewGameBox.y + 30; + NewGameBox.w = 300; + NewGameBox.h = 30; SDL_Rect LoadGameBox; LoadGameBox.y = 392; LoadGameBox.x = 280; - LoadGameBox.w = LoadGameBox.x + 300; - LoadGameBox.h = LoadGameBox.y + 30; + LoadGameBox.w = 300; + LoadGameBox.h = 30; // X450 Y 392 ; // X 447 Y 428 if (cpu_time_used > 0.5 && IsInsideRect(x, y, NewGameBox)) { printf(" New Game I was hit\n\n\n"); - SetMenu(6); + SetMenu(MULTIPLAYER_DIFFICULTY); cpu_time_used = 0; timestart = 0; start = 0; @@ -512,12 +553,10 @@ void UiInitialize() // I anticipate to move this later. printf("Cancel\n\n\n"); - SetMenu(2); // TODO skip to main menu if no valid saves + SetMenu(SINGLEPLAYER_CLASSES); // TODO skip to main menu if no valid saves } break; - case 6: - // Choose difficulty - + case MULTIPLAYER_DIFFICULTY: if (timestart == 0) { start = clock(); timestart = 1; @@ -532,21 +571,21 @@ void UiInitialize() // I anticipate to move this later. SDL_Rect NormalSelectBox; NormalSelectBox.y = 350; NormalSelectBox.x = 280; - NormalSelectBox.w = NormalSelectBox.x + 300; - NormalSelectBox.h = NormalSelectBox.y + 30; + NormalSelectBox.w = 300; + NormalSelectBox.h = 30; SDL_Rect NightmareSelectBox; NightmareSelectBox.y = 392; NightmareSelectBox.x = 280; - NightmareSelectBox.w = NightmareSelectBox.x + 300; - NightmareSelectBox.h = NightmareSelectBox.y + 30; + NightmareSelectBox.w = 300; + NightmareSelectBox.h = 30; // X450 Y 392 ; SDL_Rect HellSelectBox; HellSelectBox.y = 428; HellSelectBox.x = 280; - HellSelectBox.w = HellSelectBox.x + 300; - HellSelectBox.h = HellSelectBox.y + 30; + HellSelectBox.w = 300; + HellSelectBox.h = 30; // X 447 Y 428 if (cpu_time_used > 0.5 && IsInsideRect(x, y, NormalSelectBox)) { @@ -570,7 +609,7 @@ void UiInitialize() // I anticipate to move this later. cpu_time_used = 0; printf("Cancel\n\n\n"); - SetMenu(5); + SetMenu(MULTIPLAYER_LOBBY); } break; } diff --git a/Stub/dx.cpp b/Stub/dx.cpp index 1cb8f5310..21b9908b2 100644 --- a/Stub/dx.cpp +++ b/Stub/dx.cpp @@ -293,12 +293,11 @@ void sdl_present_surface() void __cdecl lock_buf_priv() { - if (!gpBuffer) { - printf(" GpBuffer Created\n "); + printf("GpBuffer Created\n"); const int pitch = 640 + 64 + 64; gpBuffer = (Screen *)malloc(sizeof(Screen)); - printf("SIZE OF SCREEN %d", sizeof(Screen)); + printf("SIZE OF SCREEN %d\n", sizeof(Screen)); gpBufEnd += (unsigned int)gpBuffer; @@ -310,15 +309,13 @@ void __cdecl lock_buf_priv() } unlock_buf_priv(); - - } void __cdecl unlock_buf_priv() { - + gpBufEnd -= (unsigned int)gpBufEnd; - + if (!surface_dirty) { @@ -399,4 +396,4 @@ WINBOOL WINAPI TextOutA(HDC hdc, int x, int y, LPCSTR lpString, int c) SDL_SetWindowTitle(window, lpString); return TRUE; -} \ No newline at end of file +} diff --git a/Stub/sdlrender.cpp b/Stub/sdlrender.cpp index 635cf5747..b339fab43 100644 --- a/Stub/sdlrender.cpp +++ b/Stub/sdlrender.cpp @@ -2,12 +2,9 @@ #include "miniwin_sdl.h" #include "stubs.h" -int SCREEN_WIDTH = 640; // 1024×768 +int SCREEN_WIDTH = 640; int SCREEN_HEIGHT = 480; -int Window_Width = 640; -int Window_Height = 480; - int LogoWidth; int LogoHeight; @@ -35,9 +32,12 @@ bool DiabloImageLoaded = 0; bool DiabloMainMenuListLoaded = 0; bool TitleImageLoaded = false; +void *pPcxLogoImage; int gdwLogoWidth; int gdwLogoHeight; -void *pPcxLogoImage; +void *pPcxLogoSmImage; +int gdwLogoSmWidth; +int gdwLogoSmHeight; int gdwTitleWidth; int gdwTitleHeight; @@ -62,6 +62,7 @@ unsigned char *pFont16; int gdwFont24Width; int gdwFont24Height; +void *pPcxFont24sImage; void *pPcxFont24gImage; unsigned char *pFont24; @@ -85,8 +86,8 @@ void *TitleMenuText; void *MenuPentegram16; void *MenuPentegram42; -void *pDiabfrCel; - +void *pDiabfrCel; + char HeroUndecidedName[17]; _uiheroinfo heroarray[10]; @@ -848,8 +849,7 @@ void SdlDiabloMainWindow() SDL_Init(SDL_INIT_EVERYTHING); SDL_Init(SDL_INIT_VIDEO); - window = SDL_CreateWindow("Diablo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Window_Width, Window_Height, - 0); + window = SDL_CreateWindow("Diablo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, 0); renderer = SDL_CreateRenderer(window, -1, 0); printf("Window And Renderer Created!\n"); @@ -913,7 +913,7 @@ int GetCenterOffset(int w, int bw = 0) return bw / 2 - w / 2; } -void DrawPCXString(int x, int y, int w, int h, char *str, BYTE *font, void *pBuff) +void DrawPCXString(int x, int y, int w, int h, BYTE *str, BYTE *font, void *pBuff) { int i; int len = 0; @@ -979,6 +979,13 @@ void PrintText24Gold(int x, int y, char *text, TXT_JUST align = JustLeft, int bw DrawPCXString(x, y, gdwFont24Width, gdwFont24Height, text, pFont24, pPcxFont24gImage); } +void PrintText24Silver(int x, int y, char *text, TXT_JUST align = JustLeft, int bw = 0) +{ + x += TextAlignment(text, align, bw, pFont24); + + DrawPCXString(x, y, gdwFont24Width, gdwFont24Height, text, pFont24, pPcxFont24sImage); +} + void PrintText30Gold(int x, int y, char *text, TXT_JUST align = JustLeft, int bw = 0) { x += TextAlignment(text, align, bw, pFont30); @@ -1042,18 +1049,28 @@ void ShowCredts() } } -///////////////////////////Renders - -void RenderDiabloLogo() -{ - int MyPcxDelay = 60; - int MyPcxFRAME = (SDL_GetTicks() / MyPcxDelay) % 15; // This is not how this should be done... - MyPcxFRAME++; - if (MyPcxFRAME == 15) { - MyPcxFRAME = 0; - } - - DrawArtWithMask(GetCenterOffset(gdwLogoWidth), 0, gdwLogoWidth, gdwLogoHeight, MyPcxFRAME, 250, pPcxLogoImage); +///////////////////////////Renders + +void AnimateDiabloLogo(int t, int w, int h, void *pBuffer) +{ + int MyPcxDelay = 60; + int MyPcxFRAME = (SDL_GetTicks() / MyPcxDelay) % 15; + MyPcxFRAME++; + if (MyPcxFRAME == 15) { + MyPcxFRAME = 0; + } + + DrawArtWithMask(GetCenterOffset(w), t, w, h, MyPcxFRAME, 250, pBuffer); +} + +void RenderDiabloLogo() +{ + AnimateDiabloLogo(182, gdwLogoWidth, gdwLogoHeight, pPcxLogoImage); +} + +void RenderDiabloLogoSm() +{ + AnimateDiabloLogo(0, gdwLogoSmWidth, gdwLogoSmHeight, pPcxLogoSmImage); } void DrawCursor(int mx, int my) @@ -1114,6 +1131,15 @@ void DrawSelector42(int x, int y, int width, int padding, int spacing) DrawSelector(x, y, width, padding, spacing, 42, MenuPentegram42); } +void SDL_RenderDiabloSplashPage() +{ + LoadTitelArt("ui_art\\title.pcx"); + DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); + + PrintText24Silver(-1, 410, "Copyright \xA9 1996-2001 Blizzard Entertainment", JustCentre); + RenderDiabloLogo(); +} + void SDL_RenderDiabloMainPage() { char *pszFile = "ui_art\\mainmenu.pcx"; @@ -1125,11 +1151,11 @@ void SDL_RenderDiabloMainPage() // scrollrt_draw_cursor_back_buffer(); // Doesn't work? - char *MENIITEMS[5] = { "Single Player", "Multi Player", "Replay Intro", "Show Credits", "Exit Diablo" }; - RenderDiabloLogo(); + RenderDiabloLogoSm(); int menuTop = 192; + char *MENIITEMS[5] = { "Single Player", "Multi Player", "Replay Intro", "Show Credits", "Exit Diablo" }; for (int i = 0; i < 5; i++) { int y = menuTop + i * 43; @@ -1156,7 +1182,7 @@ void SDL_RenderDiabloSinglePlayerPage() { LoadTitelArt("ui_art\\selhero.pcx"); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); - RenderDiabloLogo(); + RenderDiabloLogoSm(); DrawArtImage(30, 211, gdwHeroWidth, gdwHeroHeight, 0, pPcxHeroImage); @@ -1235,7 +1261,7 @@ void DrawNewHeroImage(int image, int ShowClasses) { LoadTitelArt("ui_art\\selhero.pcx"); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); - RenderDiabloLogo(); + RenderDiabloLogoSm(); DrawArtImage(30, 211, gdwHeroWidth, gdwHeroHeight, 0, pPcxHeroImage); @@ -1256,7 +1282,7 @@ void DrawPreGameOptions(int image, int ShowClasses) { LoadTitelArt("ui_art\\selhero.pcx"); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); - RenderDiabloLogo(); + RenderDiabloLogoSm(); DrawArtImage(30, 211, gdwHeroWidth, gdwHeroHeight, 0, pPcxHeroImage); @@ -1278,7 +1304,7 @@ void DrawPreGameDifficultySelection(int image, int ShowClasses) { LoadTitelArt("ui_art\\selhero.pcx"); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); - RenderDiabloLogo(); + RenderDiabloLogoSm(); DrawArtImage(30, 211, gdwHeroWidth, gdwHeroHeight, 0, pPcxHeroImage); @@ -1369,5 +1395,5 @@ void LoadCreateHeroDialogMenu() void CreateHeroMenu() { DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); - RenderDiabloLogo(); + RenderDiabloLogoSm(); } diff --git a/Stub/sdlrender.h b/Stub/sdlrender.h index d6591bbe5..d8d36ed94 100644 --- a/Stub/sdlrender.h +++ b/Stub/sdlrender.h @@ -10,6 +10,7 @@ extern void *pPcxFont16gImage; extern int gdwFont24Width; extern int gdwFont24Height; +extern void *pPcxFont24sImage; extern void *pPcxFont24gImage; extern unsigned char *pFont24; @@ -26,9 +27,14 @@ extern void *pPcxFont42gImage; extern void *pTitlqtxtCel; extern void *pDiabfrCel; + +extern void *pPcxLogoImage; extern int gdwLogoWidth; extern int gdwLogoHeight; -extern void *pPcxLogoImage; +extern void *pPcxLogoSmImage; +extern int gdwLogoSmWidth; +extern int gdwLogoSmHeight; + extern int gdwTitleWidth; extern int gdwTitleHeight; extern void *pPcxTitleImage; @@ -90,6 +96,7 @@ extern SDL_Rect CreateHeroBox; void CreateMenuDialogBox(); void CreateDiabloMainMenuz(); void SdlDiabloMainWindow(); +void SDL_RenderDiabloSplashPage(); void SDL_RenderDiabloMainPage(); char *GetWorkingDirectory(); void CreateMainDiabloMenu(); diff --git a/enums.h b/enums.h index 0e54f1dca..9a0c72662 100644 --- a/enums.h +++ b/enums.h @@ -2158,6 +2158,21 @@ enum _mainmenu_selections MAINMENU_ATTRACT_MODE = 6, }; +enum menus +{ + SPLASH, + MAINMENU, + SINGLEPLAYER_LOAD, + SINGLEPLAYER_CLASSES, + SINGLEPLAYER_NAME, + MULTIPLAYER_CONNECTIONS, + MULTIPLAYER_LOBBY, + MULTIPLAYER_DIFFICULTY, + MULTIPLAYER_BNET_GATEWAYS, + MULTIPLAYER_ERROR, + CREDIT, +}; + enum TXT_JUST { JustLeft = 0, JustCentre = 1,