Mercurial > mm7
changeset 1545:c4ab816fcc5e
assert, Abortf, AbortWithError -> Assert, Error
refactors here and there
line wrap: on
line diff
--- a/Actor.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Actor.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,9 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - - #include "mm7_data.h" #include "DecalBuilder.h" @@ -1826,7 +1823,7 @@ v41.vDirection.y = (signed __int64)(1.0 / v33 * v43 * 65536.0); v41.vDirection.z = (signed __int64)(1.0 / v33 * a4a * 65536.0); v41.uDistance = (signed __int64)v33; - v41.uDistanceXZ = (signed __int64)sqrt(outy2 + outx2); + v41.uDistanceXZ = sqrt(outy2 + outx2); v41.uYawAngle = stru_5C6E00->Atan2((signed __int64)v42, (signed __int64)v43); v41.uPitchAngle = stru_5C6E00->Atan2(v41.uDistanceXZ, (signed __int64)a4a); } @@ -4063,7 +4060,7 @@ //int v61; // [sp-14h] [bp-C4h]@168 //AIDirection *v62; // [sp-14h] [bp-C4h]@213 //signed int v63; // [sp-14h] [bp-C4h]@216 - unsigned int v64; // [sp-14h] [bp-C4h]@219 + //unsigned int v64; // [sp-14h] [bp-C4h]@219 unsigned int v65; // [sp-10h] [bp-C0h]@144 char v66; // [sp-10h] [bp-C0h]@147 //AIDirection *v67; // [sp-10h] [bp-C0h]@167 @@ -4194,19 +4191,19 @@ ++v14; } while ( v13 < 22 );*/ - if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime < 0 ) + if (pActor->pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime < 0) //&& SHIDWORD(pActor->pActorBuffs[3].uExpireTime) <= (signed int)v12 && (SHIDWORD(pActor->pActorBuffs[3].uExpireTime) < (signed int)v12 // || LODWORD(pActor->pActorBuffs[3].uExpireTime) <= v12) ) pActor->uActorHeight = pMonsterList->pMonsters[pActor->pMonsterInfo.uID - 1].uMonsterHeight; - if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0 ) + if (pActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0) pActor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly; // not sure - else if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime < 0 ) + else if (pActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime < 0) pActor->pMonsterInfo.uHostilityType = pMonsterStats->pInfos[pActor->pMonsterInfo.uID].uHostilityType; - if ((signed __int64)pActor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0 - || (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0) - continue; + if (pActor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0 || + pActor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0) + continue; //v15 = pMiscTimer->uTimeElapsed; //v16 = (char *)&pActor->pMonsterInfo.uRecoveryTime; @@ -4408,7 +4405,7 @@ pActor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; } - if ( (signed __int64)pActor->pActorBuffs[4].uExpireTime > 0 ) + if (pActor->pActorBuffs[4].uExpireTime > 0) { if ( (signed int)v36 >= 10240 ) { @@ -4430,7 +4427,7 @@ { if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - Actor::AI_Stand(actor_id, target_pid, (signed __int64)((double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333), &pDir); + Actor::AI_Stand(actor_id, target_pid, pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333, &pDir); } else { @@ -4477,21 +4474,19 @@ } else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; if ( v80 * 307.2 > (double)v81 ) { - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { - Actor::AI_Pursue1(actor_id, target_pid, actor_id, (signed __int64)v47, &pDir); + Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, &pDir); } } } @@ -4503,9 +4498,8 @@ { if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4515,9 +4509,8 @@ } else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4530,9 +4523,8 @@ } else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4559,14 +4551,13 @@ } else if ( v80 * 307.2 > (double)v81 || pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - Actor::AI_Pursue1(actor_id, target_pid, actor_id, (signed __int64)v47, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, &pDir); } } else @@ -4577,9 +4568,8 @@ { if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4588,9 +4578,8 @@ } else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4600,9 +4589,8 @@ } else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4638,8 +4626,7 @@ v58 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; memcpy(&v74, v57, sizeof(v74)); memcpy(&pDir, &v74, sizeof(pDir)); - v64 = (signed __int64)v58; - Actor::AI_Stand(actor_id, 4, v64, &pDir); + Actor::AI_Stand(actor_id, 4, v58, &pDir); } } else if ( !pActor->pMonsterInfo.uMissleAttack2Type ) @@ -4650,9 +4637,8 @@ { if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4661,9 +4647,8 @@ } else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4673,9 +4658,8 @@ } else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 ) { - v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); + v47 = pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); } else { @@ -4686,14 +4670,9 @@ { v47 = (double)(signed int)pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333; if ( v80 * 307.2 > (double)v81 || pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) - { - v64 = (signed __int64)v47; - Actor::AI_Stand(actor_id, target_pid, v64, &pDir); - } + Actor::AI_Stand(actor_id, target_pid, v47, &pDir); else - { - Actor::AI_Pursue1(actor_id, target_pid, actor_id, (signed __int64)v47, &pDir); - } + Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, &pDir); } else { @@ -4711,7 +4690,6 @@ int __fastcall IsActorAlive(unsigned int uType, unsigned int uParam, unsigned int uNumAlive) { unsigned int uAliveActors; // eax@6 - int v5; // ecx@10 unsigned int uTotalActors; // [sp+0h] [bp-4h]@1 uTotalActors = 0; @@ -4739,12 +4717,11 @@ { uAliveActors = SearchAliveActors(&uTotalActors); } - v5 = 0; - if ( uNumAlive ) - LOBYTE(v5) = (signed int)uAliveActors >= (signed int)uNumAlive; + + if (uNumAlive) + return uAliveActors >= uNumAlive; else - LOBYTE(v5) = uTotalActors == uAliveActors; - return v5; + return uTotalActors == uAliveActors; } //----- (00408B54) -------------------------------------------------------- unsigned int SearchActorByID(unsigned int *pTotalActors, unsigned int a2) @@ -5029,7 +5006,7 @@ if (pMonster->IsNotAlive()) return; - BYTE1(pMonster->uAttributes) |= 0xC0u; + pMonster->uAttributes |= 0xC000; if ( pMonster->uAIState == Fleeing ) pMonster->uAttributes |= 0x20000u; //v57 = 0; @@ -5424,7 +5401,7 @@ monster_id = a1; x_ = x; v15 = a1; - if ( (signed int)uNumActors < 500 + if (uNumActors < 500 && ((signed int)pAllocator->uBigBufferSizeAligned >> 10) - ((signed int)pAllocator->uNextFreeOffsetInBigBuffer >> 10) >= 2000 ) { v16 = 0;
--- a/Allocator.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Allocator.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -6,6 +6,7 @@ #include <stdio.h> #include "Allocator.h" +#include "ErrorHandling.h" #include "mm7_data.h" @@ -13,6 +14,7 @@ Allocator *pAllocator; // idb +int aborting_app = false; // weak @@ -24,9 +26,8 @@ //----- (00426755) -------------------------------------------------------- void *Allocator::AllocNamedChunk(const void *pPrevPtrValue, unsigned int uSize, const char *pName) { + Assert(!pPrevPtrValue, "PrevPtrValue != 0"); - if ( pPrevPtrValue && !aborting_app ) - AbortWithError(); if (!uSize) return 0; return malloc(uSize);
--- a/Arcomage.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Arcomage.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -3,7 +3,6 @@ #endif #include <string> -#include <assert.h> #include "Render.h" #include "Arcomage.h"
--- a/AudioPlayer.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/AudioPlayer.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -3,7 +3,6 @@ #endif #include <string> -#include <assert.h> #include "mm7_data.h" #include "VideoPlayer.h" @@ -22,6 +21,7 @@ #include "MapInfo.h" #include "GUIWindow.h" #include "Log.h" +#include "ErrorHandling.h" #include "Bink_Smacker.h" @@ -264,7 +264,8 @@ a2 = v14->uDecompressedSize; v16 = a2; if ( (signed int)a2 > uBufferSizeLeft ) - Abortf("Sound %s is size %i bytes, sound buffer size is %i bytes", Args, a2, uBufferSizeLeft); + Error("Sound %s is size %i bytes, sound buffer size is %i bytes", Args, a2, uBufferSizeLeft); + SetFilePointer(pAudioPlayer->hAudioSnd, v14->uFileOffset, 0, 0); v17 = v14->uCompressedSize; if ( (signed int)v17 >= (signed int)*v15 ) @@ -380,7 +381,8 @@ v2 = fopen("data\\dsounds.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dsounds.bin!"); + Error("Unable to save dsounds.bin!"); + fwrite(v1, 4u, 1u, v2); fwrite(v1->pSounds, 0x78u, v1->sNumSounds, v3); fclose(v3); @@ -441,7 +443,8 @@ v4 = fopen(Args, "r"); File = v4; if ( !v4 ) - Abortf("SoundListClass::load - Unable to open file: %s."); + Error("SoundListClass::load - Unable to open file: %s."); + v5 = 0; Argsa = 0; if ( fgets(&Buf, 490, v4) ) @@ -461,7 +464,8 @@ v6 = pAllocator->AllocNamedChunk(v2->pSounds, 120 * v5, "Snd Des."); v2->pSounds = (SoundDesc *)v6; if ( v6 == (void *)v3 ) - Abortf("SoundListClass::load - Out of Memory!"); + Error("SoundListClass::load - Out of Memory!"); + memset(v6, v3, 120 * v2->sNumSounds); v7 = File; v2->sNumSounds = v3;
--- a/CShow.h Sat Sep 07 15:20:57 2013 +0200 +++ b/CShow.h Sat Sep 07 20:05:20 2013 +0200 @@ -1,5 +1,6 @@ #pragma once #include "VideoPlayer.h" +#include "ErrorHandling.h" /* 302 */ @@ -31,7 +32,7 @@ case MOVIE_Outro: VideoPlayer::MovieLoop("end_seq1", 20, 1, 1); break; default: - assert(false && "Invalid movie requested in " __FUNCTION__); + Error("Invalid movie requested: %u", movie); break; } }
--- a/Chest.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Chest.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -3,7 +3,6 @@ #endif #include <stdio.h> -#include <assert.h> #include "BSPModel.h" #include "Items.h" @@ -617,7 +616,8 @@ v2 = fopen("data\\dchest.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dchest.bin!"); + Error("Unable to save dchest.bin!"); + fwrite(v1, 4u, 1u, v2); fwrite(v1->pChests, 0x24u, v1->uNumChests, v3); fclose(v3); @@ -671,7 +671,8 @@ v4 = fopen(Args, "r"); File = v4; if ( !v4 ) - Abortf("ChestDescriptionList::load - Unable to open file: %s."); + Error("ChestDescriptionList::load - Unable to open file: %s."); + v5 = 0; Argsa = 0; if ( fgets(&Buf, 490, v4) ) @@ -692,7 +693,8 @@ v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip"); v2->pChests = (ChestDesc *)v7; if ( v7 == (void *)v3 ) - Abortf("ChestDescriptionList::load - Out of Memory!"); + Error("ChestDescriptionList::load - Out of Memory!"); + memset(v7, v3, 36 * v2->uNumChests); v8 = File; v2->uNumChests = v3;
--- a/DecorationList.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/DecorationList.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -5,6 +5,7 @@ #include "FrameTableInc.h" #include "mm7_data.h" #include "Indoor.h" +#include "ErrorHandling.h" //----- (0045864C) -------------------------------------------------------- void DecorationList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) @@ -14,8 +15,8 @@ num_mm8_decs = data_mm8 ? *(int *)data_mm8 : 0; uNumDecorations = num_mm6_decs + num_mm7_decs + num_mm8_decs; - assert(uNumDecorations); - assert(!num_mm8_decs); + Assert(uNumDecorations); + Assert(!num_mm8_decs); pDecorations = (DecorationDesc *)pAllocator->AllocNamedChunk(pDecorations, uNumDecorations * sizeof(DecorationDesc), "Dec Descrip"); memcpy(pDecorations, (char *)data_mm7 + 4, num_mm7_decs * sizeof(DecorationDesc)); @@ -86,7 +87,8 @@ v3 = fopen(Args, "r"); File = v3; if ( !v3 ) - Abortf("DecorationDescriptionList::load - Unable to open file: %s."); + Error("DecorationDescriptionList::load - Unable to open file: %s."); + v4 = 0; Argsa = 0; if ( fgets(&Buf, 490, v3) ) @@ -105,7 +107,8 @@ v5 = pAllocator->AllocNamedChunk(v2->pDecorations, 84 * v4, "Dec Descrip"); v2->pDecorations = (DecorationDesc *)v5; if ( !v5 ) - Abortf("DecorationDescriptionList::load - Out of Memory!"); + Error("DecorationDescriptionList::load - Out of Memory!"); + v6 = File; v2->uNumDecorations = 0; fseek(v6, 0, 0); @@ -244,7 +247,8 @@ v2 = fopen("data\\ddeclist.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save ddeclist.bin!"); + Error("Unable to save ddeclist.bin!"); + fwrite(v1, 4u, 1u, v2); fwrite(v1->pDecorations, 0x54u, v1->uNumDecorations, v3); fclose(v3);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ErrorHandling.h Sat Sep 07 20:05:20 2013 +0200 @@ -0,0 +1,62 @@ +#pragma once + +#define Error(format, ...) Error_impl_(__FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__) +#define Assert(condition, format, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, format, __VA_ARGS__) +#define Assert(condition) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, nullptr) + + + + +#include <stdarg.h> +inline __declspec(noreturn) void Error_impl_(const char *filename, const char *functionname, int line, + const char *format, ...) +{ + va_list va; + va_start(va, format); + { + char header[4096]; + sprintf(header, "Error in %s: %u\n\t%s\n\n", filename, line, functionname); + + char msg_body[8192]; + vsprintf(msg_body, format, va); + + wchar_t msg[sizeof(header) + sizeof(msg_body)]; + swprintf(msg, L"%S %S", header, msg_body); + + extern void MsgBox(const wchar_t *, const wchar_t *); + MsgBox(msg, L"Error"); + } + va_end(va); + + __debugbreak(); +} + + +inline void Assert_impl_(const char *filename, const char *functionname, int line, + bool condition, const char *condition_string, const char *format, ...) +{ + if (condition) + return; + + va_list va; + va_start(va, format); + { + char header[4096]; + sprintf(header, "Assertion in %s: %u\n\t%s:\n%s\n\n", filename, line, functionname, condition_string); + + char msg_body[8192]; + vsprintf(msg_body, format, va); + + wchar_t msg[sizeof(header) + sizeof(msg_body)]; + if (format) + swprintf(msg, L"%S %S", header, msg_body); + else + swprintf(msg, L"%S", header); + + extern void MsgBox(const wchar_t *, const wchar_t *); + MsgBox(msg, L"Assertion"); + } + va_end(va); + + __debugbreak(); +} \ No newline at end of file
--- a/Events.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Events.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,7 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> #include <stdlib.h> #include "Weather.h" @@ -67,24 +66,23 @@ { FILE *pLodFile; // eax@1 unsigned int uTextureSize; // esi@3 - char Args[60]; // [sp+8h] [bp-B4h]@6 + //char Args[60]; // [sp+8h] [bp-B4h]@6 void *ptr; // [sp+B8h] [bp-4h]@1 Texture DstBuf; // [sp+6Ch] [bp-50h]@1 ptr = pEvents_LOD->LoadRaw(pContainerName, 0); pLodFile = pEvents_LOD->FindContainer(pContainerName, 0); if ( !pLodFile ) - Abortf("Unable to load %s", pContainerName); + Error("Unable to load %s", pContainerName); + fread(&DstBuf, 1, 48, pLodFile); uTextureSize = DstBuf.uDecompressedSize; if ( !DstBuf.uDecompressedSize ) uTextureSize = DstBuf.uTextureSize; memset(&DstBuf, 0, 72); if ( uTextureSize >= (signed int)uBufferSize ) - { - sprintf(Args, "File %s Size %lu - Buffer size %lu", pContainerName, uTextureSize, uBufferSize); - Abortf(Args); - } + Error("File %s Size %lu - Buffer size %lu", pContainerName, uTextureSize, uBufferSize); + memcpy(pBuffer, ptr, uTextureSize); pAllocator->FreeChunk(ptr); return uTextureSize;
--- a/GUIFont.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/GUIFont.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -3,7 +3,6 @@ #endif #include <string> -#include <assert.h> #include "LOD.h" #include "GUIFont.h" @@ -49,10 +48,8 @@ { pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE); if (pallete_index == -1) - { - wsprintfA(pTmpBuf.data(), "Unable to open %s", pFontPalette); - Abortf(pTmpBuf.data()); - } + Error("Unable to open %s", pFontPalette); + pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16; ++palletes_count; } @@ -285,7 +282,7 @@ } currentFont=pFontMain; // esi@3 uInStrLen = strlen(pString); - assert(uInStrLen < sizeof(pTmpBuf3)); + Assert(uInStrLen < sizeof(pTmpBuf3)); strcpy(pTmpBuf3.data(), pString); if (uInStrLen==0) return pTmpBuf3.data();
--- a/GUIProgressBar.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/GUIProgressBar.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "GUIProgressBar.h" #include "LOD.h" #include "Mouse.h" @@ -43,7 +41,7 @@ break; default: - assert(false && "Invalid GUIProgressBar type"); + Error("Invalid GUIProgressBar type: %u", type); } //v2 = this; @@ -110,7 +108,7 @@ case PartyAlignment_Good: pIcons_LOD->_410522(&pBardata, "bardata-b", 2); break; case PartyAlignment_Neutral: pIcons_LOD->_410522(&pBardata, "bardata", 2); break; case PartyAlignment_Evil: pIcons_LOD->_410522(&pBardata, "bardata-c", 2); break; - default: assert(false); + default: Error("Invalid alignment type: %u", pParty->alignment); } uProgressCurrent = 0;
--- a/Game.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Game.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "Vis.h" #include "LightmapBuilder.h" @@ -127,7 +125,7 @@ pIndoor->Draw(); else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) pOutdoor->Draw(); - else assert(false); + else Error("Invalid level type: %u", uCurrentlyLoadedLevelType); if (pRenderer->pRenderD3D) { @@ -543,7 +541,7 @@ if (num_conscious_players) { int idx = conscious_players_ids[rand() % num_conscious_players]; - assert(idx >= 0); + Assert(idx >= 0); pPlayers[idx + 1]->PlaySound(SPEECH_99, 0); } @@ -1178,7 +1176,7 @@ else face->uAttributes |= FACE_OUTLINED; } - else assert(false); + else Error("Invalid level type", uCurrentlyLoadedLevelType); } break;
--- a/IconFrameTable.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/IconFrameTable.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -105,7 +105,7 @@ v2 = fopen("data\\dift.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dift.bin!"); + Error("Unable to save dift.bin!"); fwrite(v1, 4u, 1u, v2); fwrite(v1->pIcons, 0x20u, v1->uNumIcons, v3); fclose(v3); @@ -119,8 +119,8 @@ num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0; uNumIcons = num_mm6_frames + num_mm7_frames + num_mm8_frames; - assert(uNumIcons); - assert(!num_mm8_frames); + Assert(uNumIcons); + Assert(!num_mm8_frames); pIcons = (IconFrame *)pAllocator->AllocNamedChunk(pIcons, uNumIcons * sizeof(IconFrame), "I Frames"); memcpy(pIcons, (char *)data_mm7 + 4, num_mm7_frames * sizeof(IconFrame)); @@ -160,7 +160,7 @@ v3 = fopen(Args, "r"); File = v3; if ( !v3 ) - Abortf("IconFrameTable::load - Unable to open file: %s.", Args); + Error("IconFrameTable::load - Unable to open file: %s.", Args); v4 = 0; v21 = 0; v22 = 1; @@ -173,7 +173,7 @@ if ( v20.uPropCount && *v20.pProperties[0] != 47 ) { if ( v20.uPropCount < 3 ) - Abortf("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22); + Error("IconFrameTable::loadText, too few arguments, %s line %i.", Args, v22); ++v21; } ++v22;
--- a/Indoor.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Indoor.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "LightmapBuilder.h" #include "DecalBuilder.h" #include "stru9.h" @@ -1749,7 +1747,7 @@ } if ( !pGames_LOD->DoesContainerExist(pFilename) ) - Abortf("Unable to find %s in Games.LOD", pFilename); + Error("Unable to find %s in Games.LOD", pFilename); //v238 = pFilename - 4; //v81 = strlen(pFilename); @@ -2971,7 +2969,7 @@ v25 = abs(v15->pFacePlane_old.vNormal.z); //v26 = v87; if ( v24 > v25 ) - Abortf("Door Error\ndoor id: %i\nfacet no: %i\n\nOverflow dividing facet->d [%i] by facet->nz [%i]", + Error("Door Error\ndoor id: %i\nfacet no: %i\n\nOverflow dividing facet->d [%i] by facet->nz [%i]", door->uDoorID, door->pFaceIDs[v88], v15->pFacePlane_old.dist, @@ -3670,7 +3668,7 @@ __int16 v29; // ax@85 signed int v30; // edi@94 int v31; // esi@94 - char Args; // [sp+350h] [bp-C4h]@16 + //char Args; // [sp+350h] [bp-C4h]@16 int v34[4]; // [sp+3E8h] [bp-2Ch]@96 int v35; // [sp+3F8h] [bp-1Ch]@1 //char b[4]; // [sp+3FCh] [bp-18h]@58 @@ -3727,21 +3725,17 @@ (char *)&pDest) - 1; if ( !v4 ) - { - sprintf(&Args, "Unable to open %s", pCurrentMapName); - Abortf(&Args); - } + Error("Unable to open %s", pCurrentMapName); + v5 = v4 - 1; if ( !v5 ) - { - sprintf(&Args, "File %s is not a BLV File", pCurrentMapName); - Abortf(&Args); - } + Error("File %s is not a BLV File", pCurrentMapName); + v6 = v5 - 1; if ( !v6 ) - Abortf("Attempt to open new level before clearing old"); + Error("Attempt to open new level before clearing old"); if ( v6 == 1 ) - Abortf("Out of memory loading indoor level"); + Error("Out of memory loading indoor level"); if ( !(dword_6BE364_game_settings_1 & 0x2000) ) { InitializeActors(); @@ -3836,21 +3830,6 @@ if (!pFace->uBitmapID != -1) pBitmaps_LOD->pTextures[pFace->uBitmapID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[pFace->uBitmapID].palette_id1); } - - /*i = 0; - if ( (signed int)pIndoor->uNumFaces > 0 ) - { - v12 = 0; - do - { - if ( pIndoor->pFaces[v12].uBitmapID != -1 ) - pBitmaps_LOD->pTextures[pIndoor->pFaces[v12].uBitmapID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[pIndoor->pFaces[v12].uBitmapID].palette_id1); - ++i; - ++v12; - } - while ( i < (signed int)pIndoor->uNumFaces ); - }*/ - pGameLoadingUI_ProgressBar->Progress();
--- a/IndoorCameraD3D.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/IndoorCameraD3D.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -710,7 +710,7 @@ void IndoorCameraD3D::DebugDrawPortal(BLVFace *pFace) { - assert(pFace->uNumVertices <= 32); + Assert(pFace->uNumVertices <= 32); RenderVertexSoft sw[32]; for (uint i = 0; i < pFace->uNumVertices; ++i)
--- a/Items.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Items.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -3,7 +3,6 @@ #endif #include <stdlib.h> -#include <assert.h> #include "Items.h" #include "MapInfo.h"
--- a/LOD.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/LOD.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1456,7 +1456,7 @@ //----- (00461F71) -------------------------------------------------------- bool LOD::File::AppendDirectory(LOD::Directory *pDir, const void *pData) { - assert(uNumSubDirs < 299); + Assert(uNumSubDirs < 299); memcpy(&pSubIndices[uNumSubDirs++], pDir, sizeof(LOD::Directory)); fwrite(pData, 1, pDir->uDataSize, pOutputFileHandle); @@ -1680,7 +1680,7 @@ uCurrentIndexDir = 0; uLODDataSize = lod_indx.uDataSize; uNumSubDirs = lod_indx.uNumSubIndices; - assert(uNumSubDirs <= 300); + Assert(uNumSubDirs <= 300); uOffsetToSubIndex = lod_indx.uOfsetFromSubindicesStart; fseek(pFile, uOffsetToSubIndex, SEEK_SET); @@ -2082,7 +2082,8 @@ v5 = v4; File = v4; if ( !v4 ) - Abortf("Unable to load %s", pContainer); + Error("Unable to load %s", pContainer); + fread(&DstBuf, 1u, 0x30u, v4); Argsa = DstBuf.uTextureSize; if ( DstBuf.uDecompressedSize ) @@ -2134,7 +2135,7 @@ int v20; // edx@15 signed int v21; // ecx@18 signed int v22; // ecx@23 - char Args[100]; // [sp+4h] [bp-68h]@3 + //char Args[100]; // [sp+4h] [bp-68h]@3 FILE *File; // [sp+68h] [bp-4h]@1 v4 = this; @@ -2143,10 +2144,8 @@ { File = FindContainer("pending", 0); if ( !File ) - { - sprintf(Args, "Can't find %s!", pContainer); - Abortf(Args); - } + Error("Can't find %s!", pContainer); + } v5 = pDst; fread(pDst, 1u, 0x30u, File); @@ -2835,7 +2834,7 @@ { uint id = LoadTexture(pContainer, uTextureType); - assert(id != -1 && L"Texture not found"); + Assert(id != -1 && L"Texture not found"); return &pTextures[id]; } @@ -2860,7 +2859,7 @@ // if (!uNumLoadedFiles) // { //LABEL_5: - assert(uNumLoadedFiles < 1000); + Assert(uNumLoadedFiles < 1000); /*if (uNumLoadedFiles >= 1000) { Log::Warning(L"Maximum texture number exceeded");
--- a/LOD.h Sat Sep 07 15:20:57 2013 +0200 +++ b/LOD.h Sat Sep 07 20:05:20 2013 +0200 @@ -1,9 +1,9 @@ #pragma once #include <stdio.h> #include <memory.h> -#include <assert.h> #include "Texture.h" +#include "ErrorHandling.h" class Sprite; @@ -166,7 +166,7 @@ inline struct Texture *GetTexture(int idx) { - assert(idx < 1000); + Assert(idx < 1000, "Texture index out of bounds (%u)", idx); if (idx == -1) return nullptr; // we need to return dummy texture here return &pTextures[idx];
--- a/Level/Decoration.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Level/Decoration.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1,5 +1,6 @@ #include "Decoration.h" #include "../Party.h" +#include "../ErrorHandling.h" //----- (004583B0) -------------------------------------------------------- LevelDecoration::LevelDecoration() @@ -106,7 +107,7 @@ case 225: case 226: case 227: return 0; - default: assert(false && "Invalid Decoration"); + default: Error("Invalid DecorationDescID: %u", uDecorationDescID); } }
--- a/LightmapBuilder.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/LightmapBuilder.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1,11 +1,10 @@ -#include <assert.h> - #include "LightmapBuilder.h" #include "Game.h" #include "stru314.h" #include "Outdoor.h" #include "Outdoor_stuff.h" #include "Log.h" +#include "ErrorHandling.h" #include "OutdoorCamera.h" #include "Lights.h" @@ -1655,7 +1654,7 @@ { v28 = &std__vector_000004[*i]; if ( !DrawLightmap(v28, &arg4, 0.0) ) - assert(false && "Invalid lightmap detected!"); + Error("Invalid lightmap detected! (%u)", *i); } } else
--- a/MM7.h Sat Sep 07 15:20:57 2013 +0200 +++ b/MM7.h Sat Sep 07 20:05:20 2013 +0200 @@ -12,19 +12,7 @@ typedef unsigned __int64 _QWORD; -/* 288 */ -/*#pragma pack(push, 1) -struct CheckHRESULT_stru0 -{ - void CheckHRESULT(HRESULT a2, const char *Str, int a4, unsigned int uType); - void *_466D09_xcpt_string(std::string a2, const char *Str, int a4); - void ShowMessageBox(std::string *a0, std::string lpCaption, UINT uType, std::string lpText, int line); - char ddraw_error(HRESULT hr, char *Str, size_t a3); - char dinput_error(int a1, const char *Str, int a3); - void ( ***vdestructor_ptr)(CheckHRESULT_stru0 *, bool); -}; -#pragma pack(pop)*/
--- a/Monsters.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Monsters.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -368,7 +368,8 @@ v3 = fopen(Args, "r"); File = v3; if ( !v3 ) - Abortf("MonsterRaceListStruct::load - Unable to open file: %s."); + Error("MonsterRaceListStruct::load - Unable to open file: %s."); + v4 = 0; Argsa = 0; if ( fgets(&Buf, 490, v3) ) @@ -387,7 +388,8 @@ v5 = pAllocator->AllocNamedChunk(v2->pMonsters, 152 * v4, "Mon Race"); v2->pMonsters = (MonsterDesc *)v5; if ( !v5 ) - Abortf("MonsterRaceListStruct::load - Out of Memory!"); + Error("MonsterRaceListStruct::load - Out of Memory!"); + v6 = File; v2->uNumMonsters = 0; fseek(v6, 0, 0); @@ -463,8 +465,8 @@ num_mm8_monsters = data_mm8 ? *(int *)data_mm8 : 0; uNumMonsters = num_mm6_monsters + num_mm7_monsters + num_mm8_monsters; - assert(uNumMonsters); - assert(!num_mm8_monsters); + Assert(uNumMonsters); + Assert(!num_mm8_monsters); pMonsters = (MonsterDesc *)pAllocator->AllocNamedChunk(pMonsters, sizeof(MonsterDesc) * uNumMonsters, "Mon Race"); memcpy(pMonsters, (char *)data_mm7 + 4, num_mm7_monsters * sizeof(MonsterDesc)); @@ -496,7 +498,7 @@ v2 = fopen("data\\dmonlist.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dmonlist.bin!"); + Error("Unable to save dmonlist.bin!"); fwrite(v1, 4u, 1u, v2); fwrite(v1->pMonsters, 0x98u, v1->uNumMonsters, v3); fclose(v3); @@ -1193,7 +1195,7 @@ if( (!_stricmp(pMonsters[i].pMonsterName, pMonsterName))) return i; } - assert(false && "Monster not found!"); + Error("Monster not found: %s", pMonsterName); } //----- (00438BDF) -------------------------------------------------------- bool MonsterStats::BelongsToSupertype(unsigned int uMonsterInfoID, enum MONSTER_SUPERTYPE eSupertype)
--- a/OSAPI.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/OSAPI.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -39,3 +39,11 @@ //__debugbreak(); return 0; } + + + + +void MsgBox(const wchar_t *msg, const wchar_t *title) +{ + MessageBoxW(nullptr, msg, title, 0); +} \ No newline at end of file
--- a/OSAPI.h Sat Sep 07 15:20:57 2013 +0200 +++ b/OSAPI.h Sat Sep 07 20:05:20 2013 +0200 @@ -1,5 +1,4 @@ #define WIN32_LEAN_AND_MEAN -#include <assert.h> #include <windows.h> #include <MMSystem.h>
--- a/ObjectList.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/ObjectList.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -3,6 +3,7 @@ #include "Sprites.h" #include "FrameTableInc.h" #include "Allocator.h" +#include "ErrorHandling.h" //----- (0042EB42) -------------------------------------------------------- __int16 ObjectList::ObjectIDByItemID(unsigned __int16 uItemID) @@ -49,7 +50,7 @@ v2 = fopen("data\\dobjlist.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dobjlist.bin!"); + Error("Unable to save dobjlist.bin!"); fwrite(v1, 4u, 1u, v2); fwrite(v1->pObjects, 0x38u, v1->uNumObjects, v3); fclose(v3); @@ -63,8 +64,8 @@ num_mm8_objs = data_mm8 ? *(int *)data_mm8 : 0; uNumObjects = num_mm6_objs + num_mm7_objs + num_mm8_objs; - assert(uNumObjects); - assert(!num_mm8_objs); + Assert(uNumObjects); + Assert(!num_mm8_objs); pObjects = (ObjectDesc *)pAllocator->AllocNamedChunk(pObjects, uNumObjects * sizeof(ObjectDesc), "Obj Descrip"); memcpy(pObjects, (char *)data_mm7 + 4, num_mm7_objs * sizeof(ObjectDesc)); @@ -148,7 +149,8 @@ v4 = fopen(Args, "r"); File = v4; if ( !v4 ) - Abortf("ObjectDescriptionList::load - Unable to open file: %s."); + Error("ObjectDescriptionList::load - Unable to open file: %s."); + v5 = 0; Argsa = 0; if ( fgets(&Buf, 490, v4) ) @@ -168,7 +170,8 @@ v6 = pAllocator->AllocNamedChunk(v2->pObjects, 56 * v5, "Obj Descrip"); v2->pObjects = (ObjectDesc *)v6; if ( v6 == (void *)v3 ) - Abortf("ObjectDescriptionList::load - Out of Memory!"); + Error("ObjectDescriptionList::load - Out of Memory!"); + memset(v6, v3, 56 * v2->uNumObjects); v7 = File; v2->uNumObjects = v3;
--- a/Outdoor.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Outdoor.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "stru6.h" #include "Weather.h" #include "Sprites.h" @@ -108,7 +106,6 @@ pIndoorCamera->pos.z = pParty->vPosition.z + pParty->sEyelevel; if (bRedraw || pRenderer->pRenderD3D) { - ResetPolygons(); pOutdoorCamera->RotationToInts(); sub_481ED9_MessWithOutdoorCamera(); } @@ -1158,7 +1155,7 @@ void *v5; // ST14_4@1 void *v6; // eax@1 unsigned int v7; // eax@1 - char v8; // zf@1 + //char v8; // zf@1 v1 = this; strcpy(this->pLevelFilename, "blank"); @@ -1199,12 +1196,13 @@ v1->uSky_TextureID = pBitmaps_LOD->LoadTexture(v1->pSkyTextureName); strcpy(v1->pGroundTileset, byte_6BE124_cfg_textures_DefaultGroundTexture.data()); v7 = pBitmaps_LOD->LoadTexture(v1->pGroundTileset); - v8 = v1->uSky_TextureID == -1; v1->uMainTile_BitmapID = v7; - if ( v8 ) - Abortf("Invalid Sky Tex Handle"); + + if ( v1->uSky_TextureID == -1 ) + Error("Invalid Sky Tex Handle"); + if ( v1->uMainTile_BitmapID == -1 ) - Abortf("Invalid Ground Tex Handle"); + Error("Invalid Ground Tex Handle"); } @@ -1714,7 +1712,7 @@ assert(sizeof(BSPModel) == 188); if (!pGames_LOD->DoesContainerExist(pFilename)) - Abortf("Unable to find %s in Games.LOD", pFilename); + Error("Unable to find %s in Games.LOD", pFilename); char pMinimapTextureFilename[1024];
--- a/Overlays.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Overlays.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -176,7 +176,7 @@ v2 = fopen("data\\doverlay.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save doverlay.bin!"); + Error("Unable to save doverlay.bin!"); fwrite(v1, 4u, 1u, v2); fwrite(v1->pOverlays, 8u, v1->uNumOverlays, v3); fclose(v3); @@ -190,8 +190,8 @@ num_mm8_overlays = data_mm8 ? *(int *)data_mm8 : 0; uNumOverlays = num_mm6_overlays + num_mm7_overlays + num_mm8_overlays; - assert(uNumOverlays); - assert(!num_mm8_overlays); + Assert(uNumOverlays); + Assert(!num_mm8_overlays); pOverlays = (OverlayDesc *)pAllocator->AllocNamedChunk(pOverlays, uNumOverlays * sizeof(OverlayDesc), "Ovl Des."); memcpy(pOverlays, (char *)data_mm7 + 4, num_mm7_overlays * sizeof(OverlayDesc)); @@ -230,7 +230,8 @@ v4 = fopen(Args, "r"); File = v4; if ( !v4 ) - Abortf("ObjectDescriptionList::load - Unable to open file: %s."); + Error("ObjectDescriptionList::load - Unable to open file: %s."); + v5 = 0; Argsa = 0; if ( fgets(&Buf, 490, v4) ) @@ -251,7 +252,8 @@ v7 = pAllocator->AllocNamedChunk(v6, 8 * v5, "Ovl Des."); v2->pOverlays = (OverlayDesc *)v7; if ( v7 == (void *)v3 ) - Abortf("OverlayDescriptionList::load - Out of Memory!"); + Error("OverlayDescriptionList::load - Out of Memory!"); + memset(v7, v3, 8 * v2->uNumOverlays); v8 = File; v2->uNumOverlays = v3;
--- a/PaletteManager.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/PaletteManager.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "PaletteManager.h" #include "Texture.h" #include "Game.h" @@ -423,7 +421,7 @@ } else if (v23 == 0) Log::Warning(L"Calling palette manager with num_target_bits == 0"); - else assert(false); + else Error("(%u)", v23); //v24 = (unsigned __int32)a3 | ((unsigned __int32)a2a << v2->uNumTargetBBits) | ((unsigned __int32)a1 << (v2->uNumTargetBBits + v2->uNumTargetGBits)); //v25 = v73; //v73 += 2; @@ -472,7 +470,7 @@ } else if (v23 == 0) Log::Warning(L"Calling palette manager with num_target_bits == 0"); - else assert(false); + else Error("(%u)", v23); //v29 = (unsigned __int64)(signed __int64)a3 | ((unsigned __int16)(signed __int64)a2a << v2->uNumTargetBBits) | (unsigned __int16)((unsigned __int16)(signed __int64)a1 << (v2->uNumTargetBBits + v28)); //v30 = (__int16 *)v73; @@ -517,7 +515,7 @@ } else if (v23 == 0) Log::Warning(L"Calling palette manager with num_target_bits == 0"); - else assert(false); + else Error("(%u)", v23); v36 = (signed __int64)((a1 + a2a + a3) * 0.3333333333333333 * 8.0); v37 = (signed int)v36 >> (8 - v2->uNumTargetRBits); @@ -593,7 +591,7 @@ } else if (v23 == 0) Log::Warning(L"Calling palette manager with num_target_bits == 0"); - else assert(false); + else Error("(%u)", v23); if (pPalette_mistColor[0] || pPalette_mistColor[1] || pPalette_mistColor[2]) {
--- a/Party.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Party.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "Party.h" #include "MapInfo.h" #include "Time.h" @@ -1022,7 +1020,7 @@ case Condition_Paralyzed: player->expression = CHARACTER_EXPRESSION_PARALYZED; break; case Condition_Unconcious: player->expression = CHARACTER_EXPRESSION_UNCONCIOUS; break; default: - assert(false); + Error("Invalid condition: %u", condition); } } } @@ -1041,7 +1039,7 @@ hireling->evt_B = 0; hireling->evt_C = 0; - assert(sizeof(NPCData) == 0x4C); + Assert(sizeof(NPCData) == 0x4C); memset(hireling, 0, sizeof(*hireling)); pParty->field_709 = 0;
--- a/Player.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Player.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,11 +2,8 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "stru6.h" - #include "Player.h" #include "PlayerFrameTable.h" #include "AudioPlayer.h" @@ -343,7 +340,7 @@ int Player::GetBuyingPrice(unsigned int uRealValue, float price_multiplier) { uint price = (uint)(((100 - GetMerchant()) * (uRealValue * price_multiplier)) / 100); - assert (price > 0); + Assert (price > 0); if (price < uRealValue) price = uRealValue; @@ -650,7 +647,7 @@ return(_449B57_test_bit((unsigned __int8 *)this->_achieved_awards_bits, 79)); break; default: - assert("Should not be able to get here" && false); + Error("Should not be able to get here (%u)", uClass); break; } return false; @@ -813,11 +810,8 @@ texture->Release(); pIcons_LOD->SyncLoadedFilesCount(); } - if ( slotHeight == 0 || slotWidth == 0) - { - assert("Items should have nonzero dimensions"); - return 1; - } + + Assert(slotHeight && slotWidth, "Items should have nonzero dimensions"); if ( (slotWidth + uSlot % INVETORYSLOTSWIDTH) <= INVETORYSLOTSWIDTH && (slotHeight + uSlot / INVETORYSLOTSWIDTH) <= INVETORYSLOTSHEIGHT ) { int startOfInnerLoop = uSlot; @@ -1091,7 +1085,7 @@ return 4; break; default: - assert(false); + Error("(%u)", building_type); break; } if (pItem->Stolen()) @@ -1116,7 +1110,7 @@ price = this->GetPriceRepair(itemValue, multiplier); break; default: - assert(false); + Assert("(%u)", ShopMenuType); break; } if ( merchantLevel ) @@ -3199,7 +3193,7 @@ } else { - assert(false && "Unknown armour type"); // what kind of armour is that? + Error("Unknown armour type"); // what kind of armour is that? armour_recovery_multipliers[0] = 1.0f; armour_recovery_multipliers[1] = 1.0f; armour_recovery_multipliers[2] = 1.0f; @@ -3593,7 +3587,7 @@ //----- (0048E96A) -------------------------------------------------------- void Player::SetRecoveryTime(signed int rec) { - assert(rec >= 0); + Assert(rec >= 0); if (rec > uTimeToRecovery) uTimeToRecovery = rec; @@ -5040,7 +5034,7 @@ case 3: return mult3; case 4: return mult4; } - assert(false); + Error("(%u)", masteryLvl); return 0; } //----- (00490109) -------------------------------------------------------- @@ -5123,7 +5117,7 @@ case 0x18u: return SEX_FEMALE; } - assert(false); + Error("(%u)", this->uVoiceID); return SEX_MALE; } @@ -5373,7 +5367,7 @@ } } - assert(false); + Error("(%u)", order); } @@ -5467,9 +5461,7 @@ case 6: statToChange = &this->uLuck; default: - assert(false); - return; - break; + Error("(%u)", eAttribute); } if ( *statToChange < baseValue ) { @@ -6777,7 +6769,8 @@ break; } } - assert(currPlayerId != -1); + + Assert(currPlayerId != -1); if ( var_type > VAR_AutoNotes ) { if ( var_type <= VAR_GoldInBank ) @@ -7228,14 +7221,14 @@ this->sResDarkBonus = (unsigned __int8)var_value; break; case VAR_PhysicalResistanceBonus: - assert("VAR_PhysicalResistanceBonus variable unsupported" && false); + Assert("VAR_PhysicalResistanceBonus variable unsupported" && false); return; break; case VAR_MagicResistanceBonus: this->sResMagicBonus = (unsigned __int8)var_value; break; default: - assert("Unexpected var_type" && false); + Assert("Unexpected var_type: %u", var_type); return; break; } @@ -7982,7 +7975,7 @@ pParty->uNumArenaLordWins -= (char)pValue; break; } - assert(false && "Function not returning any value!"); + Error("Function not returning any value! (%u)", VarNum); } else { @@ -8564,7 +8557,7 @@ //pPlayers = &::pPlayers[1]; //v5 = 604; //while ( 1 ) - assert ( a1 > 0 && a1 < 5 ); + Assert ( a1 > 0 && a1 < 5 ); for ( uint i = 1; i < 5; ++i ) { //item_flag = Player_has_item(604, *pPlayers, 0);
--- a/Render.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Render.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "Outdoor_stuff.h" #include "VideoPlayer.h" #include "Sprites.h" @@ -3185,13 +3183,15 @@ else { if ( !v7->bIsDeviceCompatible ) - Abortf("There aren't any D3D devices to create."); + Error("There aren't any D3D devices to create."); + v8 = pRenderD3D->CreateDevice(0, 0, hWnd); uAcquiredDirect3DDevice = 0; } } if ( !v8 ) - Abortf("D3Drend->Init failed."); + Error("D3Drend->Init failed."); + v9 = pRenderD3D; pBackBuffer4 = v9->pBackBuffer; pFrontBuffer4 = v9->pFrontBuffer; @@ -3208,7 +3208,7 @@ pBackBuffer4 = 0; pFrontBuffer4 = 0; pDirectDraw4 = 0; - Abortf("Direct3D renderer: The device failed to return capabilities."); + Error("Direct3D renderer: The device failed to return capabilities."); } if ( v10 & 0x3E ) { @@ -3222,7 +3222,7 @@ pBackBuffer4 = 0; pFrontBuffer4 = 0; pDirectDraw4 = 0; - Abortf("Direct3D renderer: The device doesn't support the necessary alpha blending modes."); + Error("Direct3D renderer: The device doesn't support the necessary alpha blending modes."); } if ( (v10 & 0x80u) != 0 ) { @@ -3235,7 +3235,7 @@ pBackBuffer4 = 0; pFrontBuffer4 = 0; pDirectDraw4 = 0; - Abortf("Direct3D renderer: The device doesn't support non-square textures."); + Error("Direct3D renderer: The device doesn't support non-square textures."); } LOBYTE(field_10365C) = ~(unsigned __int8)(v10 >> 6) & 1; bRequiredTextureStagesAvailable = CheckTextureStages(); @@ -3407,12 +3407,13 @@ else { if ( !pRenderD3D->pAvailableDevices[0].bIsDeviceCompatible ) - Abortf("There aren't any D3D devices to init."); + Error("There aren't any D3D devices to init."); + v7 = pRenderD3D->CreateDevice(0, 1, hWnd); uAcquiredDirect3DDevice = 0; } if ( !v7 ) - Abortf("D3Drend->Init failed."); + Error("D3Drend->Init failed."); //v8 = pRenderD3D; pColorKeySurface4 = 0; @@ -3431,7 +3432,7 @@ pBackBuffer4 = 0; pFrontBuffer4 = 0; pDirectDraw4 = 0; - Abortf("Direct3D renderer: The device failed to return capabilities."); + Error("Direct3D renderer: The device failed to return capabilities."); } if ( v9 & 0x3E ) { @@ -3445,7 +3446,7 @@ pBackBuffer4 = 0; pFrontBuffer4 = 0; pDirectDraw4 = 0; - Abortf("Direct3D renderer: The device doesn't support the necessary alpha blending modes."); + Error("Direct3D renderer: The device doesn't support the necessary alpha blending modes."); } if ( (v9 & 0x80u) != 0 ) { @@ -3458,7 +3459,7 @@ pBackBuffer4 = 0; pFrontBuffer4 = 0; pDirectDraw4 = 0; - Abortf("Direct3D renderer: The device doesn't support non-square textures."); + Error("Direct3D renderer: The device doesn't support non-square textures."); } LOBYTE(field_10365C) = ~(unsigned __int8)(v9 >> 6) & 1; bRequiredTextureStagesAvailable = CheckTextureStages(); @@ -6449,7 +6450,7 @@ true, bMipMaps, uMinDeviceTextureDim) ) - Abortf("HiScreen16::LoadTexture - D3Drend->CreateTexture() failed: %x", 0); + Error("HiScreen16::LoadTexture - D3Drend->CreateTexture() failed: %x", 0); //v10 = *pOutSurface; //v11 = 0; if ( bMipMaps ) @@ -6550,7 +6551,7 @@ //v6 = v3->uMinDeviceTextureDim; //v7 = v3->pRenderD3D; if (!pRenderD3D->CreateTexture(sprite_texture->uWidth, sprite_texture->uHeight, &pSprite->pTextureSurface, &pSprite->pTexture, 1u, 0, uMinDeviceTextureDim)) - Abortf("HiScreen16::LoadTexture - D3Drend->CreateTexture() failed: %x", 0); + Error("HiScreen16::LoadTexture - D3Drend->CreateTexture() failed: %x", 0); //pSprite = v2->pTextureSurface; //pSprite = (Sprite *)pSprite->pName; //v8 = pSprite;
--- a/SaveLoad.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/SaveLoad.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -4,7 +4,6 @@ #include <io.h> #include <direct.h> -#include <assert.h> #include "SaveLoad.h" #include "BSPModel.h" @@ -105,7 +104,7 @@ Log::Warning(L"%S", Str); MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:549", 0); } - assert(sizeof(SavegameHeader) == 100); + Assert(sizeof(SavegameHeader) == 100); fread(&header, sizeof(SavegameHeader), 1, f); f = pNew_LOD->FindContainer("party.bin", 1); @@ -211,10 +210,7 @@ sprintf(pTmpBuf.data(), "levels\\%s", header.pLocationName); v26 = _access(pTmpBuf.data(), 4) != -1; if ( !v25 && !v26 ) - { - sprintf(pTmpBuf.data(), "Unable to find: %s!", header.pLocationName); - Abortf(pTmpBuf.data()); - } + Error("Unable to find: %s!", header.pLocationName); strcpy(pCurrentMapName, header.pLocationName); dword_6BE364_game_settings_1 |= 0x2001; @@ -308,7 +304,7 @@ MessageBoxA(nullptr, work_string, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:773", 0); } - assert(sizeof(SavegameHeader) == 100); + Assert(sizeof(SavegameHeader) == 100); memset(save_header.pName, 0, 20); memset(save_header.pLocationName, 0, 20); memset(save_header.field_30, 0, 52); @@ -344,7 +340,7 @@ } strcpy(pLodDirectory.pFilename, "npcdata.bin"); pLodDirectory.uDataSize = 501 * sizeof(NPCData); - assert(pLodDirectory.uDataSize == 38076); + Assert(pLodDirectory.uDataSize == 38076); if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pNewNPCData, 0) ) { sprintf(work_string, pGlobalTXT_LocalizationStrings[612], 205); @@ -737,15 +733,15 @@ { //uint src_y = (game_viewport_y + y * v25) * (Dst.lPitch / sizeof(short)); uint src_y = game_viewport_y + y * v25; - assert(game_viewport_y + y * v25 < src_height); - assert(y < height); + Assert(game_viewport_y + y * v25 < src_height); + Assert(y < height); for (uint x = 0; x < width; ++x) { //uint src_x = game_viewport_x + x * v23; uint src_x = game_viewport_x + x * v23; - assert(src_x < src_width); - assert(x < width); + Assert(src_x < src_width); + Assert(x < width); dst[y * width + x] = (((63*y)/117) << 5) | 31*x/155;//31*y/117;//src[src_y * src_width + src_x]; }
--- a/SpriteObject.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/SpriteObject.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1,5 +1,3 @@ -#include <assert.h> - #include "BSPModel.h" #include "SpriteObject.h" #include "Party.h"
--- a/SpriteObject.h Sat Sep 07 15:20:57 2013 +0200 +++ b/SpriteObject.h Sat Sep 07 20:05:20 2013 +0200 @@ -3,7 +3,8 @@ enum { - OBJECT_ATTACHED_TO_ACTOR = 0x80, + OBJECT_40 = 0x40 + , OBJECT_ATTACHED_TO_ACTOR = 0x80 }; #define MAX_SPRITE_OBJECTS 1000
--- a/Sprites.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Sprites.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -351,7 +351,7 @@ v2 = fopen("data\\dsft.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dsft.bin!"); + Error("Unable to save dsft.bin!"); fwrite(v1, 4u, 1u, v2); fwrite(&v1->uNumEFrames, 4u, 1u, v3); fwrite(v1->pSpriteSFrames, 0x3Cu, v1->uNumSpriteFrames, v3); @@ -478,7 +478,8 @@ v3 = fopen(Args, "r"); File = v3; if ( !v3 ) - Abortf("CSpriteFrameTable::load - Unable to open file: %s.", Args); + Error("CSpriteFrameTable::load - Unable to open file: %s.", Args); + v4 = 0; Argsa = 0; if ( fgets(Buf, 490, v3) )
--- a/Texture.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Texture.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -257,7 +257,7 @@ v2 = fopen("data\\dtft.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dtft.bin!"); + Error("Unable to save dtft.bin!"); fwrite(v1, 4u, 1u, v2); fwrite(v1->pTextures, 0x14u, v1->sNumTextures, v3); fclose(v3); @@ -271,8 +271,8 @@ num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0; sNumTextures = num_mm6_frames + num_mm7_frames + num_mm8_frames; - assert(sNumTextures); - assert(!num_mm8_frames); + Assert(sNumTextures); + Assert(!num_mm8_frames); pTextures = (TextureFrame *)pAllocator->AllocNamedChunk(pTextures, sNumTextures * sizeof(TextureFrame), "Txt Frames"); @@ -453,10 +453,8 @@ v4 = v3; File = v3; if ( !v3 ) - { - sprintf(pTmpBuf.data(), "Unable to load %s", pContainer); - Abortf(pTmpBuf.data()); - } + Error("Unable to load %s", pContainer); + fread(&DstBuf, 1u, 0x30u, v3); Count = DstBuf.uTextureSize; if ( DstBuf.uDecompressedSize ) @@ -543,10 +541,8 @@ v5 = v4; File = v4; if ( !v4 ) - { - sprintf(pTmpBuf.data(), "Unable to load %s", pContainer); - Abortf(pTmpBuf.data()); - } + Error("Unable to load %s", pContainer); + fread(&DstBuf, 1u, 0x30u, v4); Count = DstBuf.uTextureSize; if ( DstBuf.uDecompressedSize ) @@ -1508,7 +1504,8 @@ fseek(File, 128, 0); ftell(File); if ( pcx_header2.planes == 1 ) - Abortf("24bit PCX Only!"); + Error("24bit PCX Only!"); + if ( pcx_header2.planes == 3 ) { v37 = 0; @@ -1680,7 +1677,8 @@ v3 = fopen(Args, "r"); File = v3; if ( !v3 ) - Abortf("CTextureFrameTable::load - Unable to open file: %s.", Args); + Error("CTextureFrameTable::load - Unable to open file: %s.", Args); + v4 = 0; v24 = 0; v25 = 1; @@ -1694,7 +1692,7 @@ if ( v21 && *Str1 != 47 ) { if ( v21 < 2 ) - Abortf("CTextureFrameTable::load, too few arguments, %s line %i.", Args, v25); + Error("CTextureFrameTable::load, too few arguments, %s line %i.", Args, v25); ++v24; } ++v25; @@ -1707,7 +1705,7 @@ v6 = pAllocator->AllocNamedChunk(v5, 20 * v4, "Txt Frames"); v2->pTextures = (TextureFrame *)v6; if ( !v6 ) - Abortf("CTextureFrameTable::load - Out of Memory!"); + Error("CTextureFrameTable::load - Out of Memory!"); v7 = File; v2->sNumTextures = 0; fseek(v7, 0, 0);
--- a/TileTable.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/TileTable.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,7 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -30,15 +29,7 @@ //----- (00487E3B) -------------------------------------------------------- TileDesc *TileTable::GetTileById(unsigned int uTileID) { - /*TileDesc *result; // eax@3 - - if ( (uTileID & 0x80000000u) != 0 || (signed int)uTileID > (signed int)(this->uNumTiles - 1) ) - result = this->pTiles; - else - result = &this->pTiles[uTileID]; - return result;*/ - - assert(uTileID < sNumTiles); + Assert(uTileID < sNumTiles); return &pTiles[uTileID]; } @@ -112,7 +103,7 @@ v2 = fopen("data\\dtile.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dtile.bin!"); + Error("Unable to save dtile.bin!"); fwrite(v1, 4u, 1u, v2); fwrite(v1->pTiles, 0x1Au, v1->sNumTiles, v3); fclose(v3); @@ -125,8 +116,8 @@ num_mm7_tiles = data_mm7 ? *(int *)data_mm7 : 0, num_mm8_tiles = data_mm8 ? *(int *)data_mm8 : 0; sNumTiles = num_mm6_tiles + num_mm7_tiles + num_mm8_tiles; - assert(sNumTiles); - assert(!num_mm8_tiles); + Assert(sNumTiles); + Assert(!num_mm8_tiles); pTiles = (TileDesc *)pAllocator->AllocNamedChunk(pTiles, sNumTiles * sizeof(TileDesc), "Tile Descrip"); memcpy(pTiles, (char *)data_mm7 + 4, num_mm7_tiles * sizeof(TileDesc)); @@ -226,7 +217,7 @@ v3 = fopen(pFilename, "r"); File = v3; if ( !v3 ) - Abortf("TileTable::load - Unable to open file: %s."); + Error("TileTable::load - Unable to open file: %s."); v4 = 0; for ( i = v3; fgets(&Buf, 490, i); i = File ) { @@ -239,7 +230,7 @@ v5 = pAllocator->AllocNamedChunk(v2->pTiles, 26 * v4, "Tile Descrip"); v2->pTiles = (TileDesc *)v5; if ( !v5 ) - Abortf("TileTable::Load - Out of Memory!"); + Error("TileTable::Load - Out of Memory!"); memset(v5, 0, 26 * v2->sNumTiles); v2->sNumTiles = 0; fseek(File, 0, 0);
--- a/UI/Books/UIMapBook.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/Books/UIMapBook.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "..\..\MM7.h" #include "..\..\Render.h" #include "..\..\Mouse.h"
--- a/UI/Books/UINotesBooks.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/Books/UINotesBooks.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1,9 +1,7 @@ - #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> #include "..\..\MM7.h" #include "..\..\Render.h" #include "..\..\Mouse.h"
--- a/UI/Books/UISpellBook.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/Books/UISpellBook.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,7 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> #include "..\..\MM7.h" #include "..\..\Render.h" #include "..\..\Mouse.h"
--- a/UI/UIBooks.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UIBooks.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,7 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> #include "..\MM7.h" #include "UIBooks.h" #include "..\Render.h"
--- a/UI/UICharacter.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UICharacter.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,7 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> #include <algorithm> #include "..\MM7.h" #include "..\MapInfo.h"
--- a/UI/UIHouses.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UIHouses.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -558,7 +558,7 @@ break; default: - assert(false && "Invalid enumeration value"); + Error("Invalid enumeration value: %u", type); } /* if ( a1 > 13 ) @@ -867,12 +867,12 @@ if ( !pIcons_LOD->uNumPrevLoadedFiles ) pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles; switch (pParty->alignment) - { + { case PartyAlignment_Good: sprintf(pContainer, "evt%02d-b", const_2()); break; case PartyAlignment_Neutral: sprintf(pContainer, "evt%02d", const_2()); break; case PartyAlignment_Evil: sprintf(pContainer, "evt%02d-c", const_2()); break; - default: assert(false); - } + default: Error("Invalid alignment type: %u", pParty->alignment); + } v17 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE); pDialogueNPCCount = 0;
--- a/UI/UIMainMenu.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UIMainMenu.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,9 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - - #include "..\Mouse.h" #include "..\Keyboard.h" @@ -278,7 +275,8 @@ ptr = v0; pFile = pEvents_LOD->FindContainer("credits.txt", 0); if ( !pFile ) - Abortf(pGlobalTXT_LocalizationStrings[63]); // "Might and Magic VII is having trouble loading files. + Error(pGlobalTXT_LocalizationStrings[63]); // "Might and Magic VII is having trouble loading files. + // Please re-install to fix this problem. Note: Re-installing will not destroy your save games." fread(&pTexture3, 1, 0x30, pFile); pSize = pTexture3.uDecompressedSize;
--- a/UI/UIOptions.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UIOptions.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1,5 +1,3 @@ -#include <assert.h> - #include "..\MM7.h" #include "..\Keyboard.h"
--- a/UI/UIPartyCreation.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UIPartyCreation.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,9 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - - #include "..\Mouse.h" #include "..\Keyboard.h" @@ -173,7 +170,7 @@ case 2: pX = 329; break; case 3: pX = 488; break; default: - assert(false && "Invalid selected character"); + Error("Invalid selected character"); } pTextCenter = pFontCChar->AlignText_Center(640, pGlobalTXT_LocalizationStrings[51]); @@ -811,7 +808,7 @@ case PLAYER_SKILL_SPEAR: player->AddItem(-1, 31); break; case PLAYER_SKILL_BOW: player->AddItem(-1, 47); break; case PLAYER_SKILL_MACE: player->AddItem(-1, 50); break; - case PLAYER_SKILL_BLASTER: assert(false); break; + case PLAYER_SKILL_BLASTER: Error("No blasters at startup :p"); case PLAYER_SKILL_SHIELD: player->AddItem(-1, 84); break; case PLAYER_SKILL_LEATHER: player->AddItem(-1, 66); break; case PLAYER_SKILL_CHAIN: player->AddItem(-1, 71); break; @@ -847,7 +844,7 @@ case PLAYER_SKILL_LIGHT: case PLAYER_SKILL_DARK: case PLAYER_SKILL_DIPLOMACY: - assert(false); + Error("No dimoplacy in mm7 (yet)"); break; case PLAYER_SKILL_ITEM_ID: case PLAYER_SKILL_REPAIR:
--- a/UI/UIPopup.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UIPopup.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "..\MM7.h" #include "..\Mouse.h"
--- a/UI/UIRest.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UIRest.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,9 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - - #include "..\GUIWindow.h" #include "..\GUIFont.h" #include "..\Party.h"
--- a/UI/UISaveLoad.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UISaveLoad.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,7 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> #include <io.h> #include "..\MM7.h" @@ -288,7 +287,7 @@ uLoadGameUI_SelectedSlot = 0; } pLODFile.AllocSubIndicesAndIO(0x12C, 0); - assert(sizeof(SavegameHeader) == 0x64); + Assert(sizeof(SavegameHeader) == 0x64); //v3 = 0; for (uint i = 0; i < uNumSavegameFiles; ++i) {
--- a/UI/UITransition.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UITransition.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,7 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> #include <io.h> #include "..\mm7_data.h" @@ -63,7 +62,7 @@ case PartyAlignment_Good: sprintfex(pContainer, "evt%02d-b", const_2()); break; case PartyAlignment_Neutral: sprintfex(pContainer, "evt%02d", const_2()); break; case PartyAlignment_Evil: sprintfex(pContainer, "evt%02d-c", const_2()); break; - default: assert(false); + default: Error("Invalid alignment: %u", pParty->alignment); } v12 = pIcons_LOD->LoadTexture(pContainer, TEXTURE_16BIT_PALETTE); @@ -129,7 +128,7 @@ case PartyAlignment_Good: sprintfex(pContainer, "evt%02d-b", const_2()); break; case PartyAlignment_Neutral: sprintfex(pContainer, "evt%02d", const_2()); break; case PartyAlignment_Evil: sprintfex(pContainer, "evt%02d-c", const_2()); break; - default: assert(false); + default: Error("Invalid alignment: %u", pParty->alignment); } pTexture_Dialogue_Background = pIcons_LOD->LoadTexturePtr(pContainer, TEXTURE_16BIT_PALETTE); @@ -248,7 +247,7 @@ v4 = (212 - pFontCreate->CalcTextHeight(pTmpBuf.data(), &v8, 0, 0)) / 2 + 101; v8.DrawTitleText(pFontCreate, 0, v4, 0, pTmpBuf.data(), 3); } - else assert(false); + else Error("Troubles in da house"); _unused_5B5924_is_travel_ui_drawn = true; }
--- a/UI/UiGame.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/UI/UiGame.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "..\Texture.h" #include "..\MM7.h"
--- a/Viewport.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Viewport.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -95,67 +95,72 @@ //----- (00443219) -------------------------------------------------------- void ViewingParams::_443219() - { - this->sViewCenterY += 512; - AdjustPosition(); - } + { + this->sViewCenterY += 512; + + AdjustPosition(); + } //----- (00443225) -------------------------------------------------------- void ViewingParams::_443225() - { - this->sViewCenterX -= 512; - AdjustPosition(); - } +{ + this->sViewCenterX -= 512; + + AdjustPosition(); +} //----- (00443231) -------------------------------------------------------- void ViewingParams::_443231() - { - this->sViewCenterY -= 512; - AdjustPosition(); - } +{ + this->sViewCenterY -= 512; + + AdjustPosition(); +} //----- (0044323D) -------------------------------------------------------- void ViewingParams::_44323D() - { - this->sViewCenterX += 512; - AdjustPosition(); - } +{ + this->sViewCenterX += 512; + + AdjustPosition(); +} //----- (00443249) -------------------------------------------------------- void ViewingParams::CenterOnParty() - { - int v1; // edx@1 +{ + this->field_2C = (32768 * (__int64)this->field_2C) >> 16; + if (this->field_2C < 384) + this->field_2C = 384; - v1 = (unsigned __int64)((signed __int64)this->field_2C << 15) >> 16; - this->field_2C = v1; - if ( v1 < 384 ) - this->field_2C = 384; - this->sViewCenterX = pParty->vPosition.x; - this->sViewCenterY = pParty->vPosition.y; - AdjustPosition(); - } + this->sViewCenterX = pParty->vPosition.x; + this->sViewCenterY = pParty->vPosition.y; + + AdjustPosition(); +} //----- (00443291) -------------------------------------------------------- void ViewingParams::CenterOnParty2() - { - int v1; // edx@1 +{ int v2; // eax@1 - v1 = 2 * this->field_2C; - v2 = 1536; - this->field_2C = v1; - if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor ) - v2 = 3072; - if ( v1 > v2 ) + if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) + v2 = 1536; + else if (uCurrentlyLoadedLevelType == LEVEL_Indoor) + v2 = 3072; + else assert(false); + + this->field_2C *= 2; + if (this->field_2C > v2 ) this->field_2C = v2; + this->sViewCenterX = pParty->vPosition.x; this->sViewCenterY = pParty->vPosition.y; AdjustPosition(); - } +} //----- (004432E7) -------------------------------------------------------- void ViewingParams::AdjustPosition() - { +{ ViewingParams *v1; // esi@1 int v2; // ebx@1 signed int v3; // edx@1 @@ -167,7 +172,7 @@ v1 = this; v2 = this->indoor_center_y; - v3 = 88 >> this->field_2C / 384; + v3 = 88 >> (this->field_2C / 384); v4 = (44 - v3) << 9; if ( v1->sViewCenterY > v2 + v4 ) v1->sViewCenterY = v2 + v4;
--- a/Vis.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/Vis.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1,5 +1,3 @@ -#include <assert.h> - #include "Vis.h" #include "Outdoor.h" #include "BSPModel.h" @@ -592,9 +590,9 @@ Intersection->vWorldPosition.y = pRayStart->vWorldPosition.y + t * ray_dir_x; Intersection->vWorldPosition.z = pRayStart->vWorldPosition.z + t * ray_dir_z; - IntersectPoint.x = (signed __int64)Intersection->vWorldPosition.x; - IntersectPoint.y = (signed __int64)Intersection->vWorldPosition.y; - IntersectPoint.z = (signed __int64)Intersection->vWorldPosition.z; + IntersectPoint.x = Intersection->vWorldPosition.x; + IntersectPoint.y = Intersection->vWorldPosition.y; + IntersectPoint.z = Intersection->vWorldPosition.z; if ( !CheckIntersectBModel(pFace, IntersectPoint, pBModelID) ) return false; @@ -883,11 +881,11 @@ int outz; // [sp+94h] [bp-Ch]@1 int outy; // [sp+98h] [bp-8h]@1 - pRotY = pIndoorCamera->sRotationY + UnprojectX((signed __int64)fMouseX); + pRotY = pIndoorCamera->sRotationY + UnprojectX(fMouseX); pStartR.z = pIndoorCamera->pos.z; pStartR.x = pIndoorCamera->pos.x; pStartR.y = pIndoorCamera->pos.y; - pRotX = pIndoorCamera->sRotationX + UnprojectY((signed __int64)fMouseY); + pRotX = pIndoorCamera->sRotationX + UnprojectY(fMouseY); pDepth = fixpoint_from_float(fPickDepth); Vec3_int_::Rotate(pDepth, pRotY, pRotX, pStartR, &outx, &outy, &outz);
--- a/_deleted.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/_deleted.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -12276,6 +12276,75 @@ while ( v16 != 1 ); } } +//----- (00481EB7) -------------------------------------------------------- +void ResetPolygons() +{ + for (auto i = 0; i < pOutdoorCamera->uNumPolygons; ++i) + { + array_77EC08[i].prolly_head = nullptr; + array_77EC08[i].prolly_tail = nullptr; + + array_77EC08[i].flags = 0; + array_77EC08[i].field_32 = 0; + } +} +//----- (00466BE5) -------------------------------------------------------- +void Abortf(const char *Format, ...) +{ + va_list va; // [sp+8h] [bp+8h]@1 + + va_start(va, Format); + if ( !pRenderer->bWindowMode ) + pRenderer->ChangeBetweenWinFullscreenModes(); + vsprintf(pTmpBuf.data(), Format, va); + if ( pMouse ) + pMouse->Activate(0); + ClipCursor(0); + MessageBoxA(0, pTmpBuf.data(), "Error", 0x30u); + Game_DeinitializeAndTerminate(1); +} +//----- (00466B8C) -------------------------------------------------------- +int AbortWithError() +{ + if ( !aborting_app ) + { + ClipCursor(0); + aborting_app = 1; + if ( !pRenderer->bWindowMode ) + pRenderer->ChangeBetweenWinFullscreenModes(); + if ( MessageBoxA(0, pGlobalTXT_LocalizationStrings[176], pGlobalTXT_LocalizationStrings[59], 0x34u) == 6 ) + SaveGame(1, 0); // "Internal Error" + // "Might and Magic VII has detected an internal error and will be forced to close. Would you like us to autosave your game before closing?" + Game_DeinitializeAndTerminate(1); + } + return 0; +} + +//----- (0046271C) -------------------------------------------------------- +void CreateDefaultBLVLevel() +{ + ofn.lStructSize = 0x4Cu; + ofn.hwndOwner = hWnd; + ofn.hInstance = 0; + ofn.lpstrFilter = "Indoor BLV Files (*.blv)"; + ofn.lpstrCustomFilter = 0; + ofn.nMaxCustFilter = 0; + ofn.nFilterIndex = 0; + ofn.lpstrFile = 0; + ofn.nMaxFile = 260; + ofn.nMaxFileTitle = 512; + ofn.lpstrInitialDir = "levels"; + ofn.lpstrTitle = "Might and Magic® VII - Load Which Level?"; + ofn.Flags = 4; + ofn.nFileOffset = 0; + ofn.nFileExtension = 0; + ofn.lpstrDefExt = "blv"; + ofn.lCustData = 0; + ofn.lpfnHook = 0; + ofn.lpTemplateName = 0; + ofn.lpstrFileTitle = pTmpBuf.data(); +} + const wchar_t *UIMessage2String(UIMessageType msg) { #define CASE(xxx) case xxx: swprintf(b, wcslen(L"%03X/%s"), L"%03X/%s", msg, L#xxx); return b;
--- a/mm7_1.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/mm7_1.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -9,7 +9,6 @@ */ //#include <defs.h> -#include <assert.h> #include "Texture.h" #include "mm7_data.h" @@ -407,7 +406,7 @@ v4 = 225; v6 = 255; } - else assert(false); + else Error("Invalid alignment type: %u", align); uGameUIFontMain = v3; uGameUIFontShadow = TargetColor(v5, v4, v6);
--- a/mm7_2.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/mm7_2.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -4,9 +4,8 @@ #include <io.h> #include <direct.h> -#include <assert.h> -#include <windows.h> - + +#include "OSAPI.h" #include "Texture.h" #include "mm7_data.h" @@ -3088,32 +3087,6 @@ event_triggers[num_event_triggers++] = i; } -OPENFILENAMEA ofn; -//----- (0046271C) -------------------------------------------------------- -void CreateDefaultBLVLevel() -{ - ofn.lStructSize = 0x4Cu; - ofn.hwndOwner = hWnd; - ofn.hInstance = 0; - ofn.lpstrFilter = "Indoor BLV Files (*.blv)"; - ofn.lpstrCustomFilter = 0; - ofn.nMaxCustFilter = 0; - ofn.nFilterIndex = 0; - ofn.lpstrFile = 0; - ofn.nMaxFile = 260; - ofn.nMaxFileTitle = 512; - ofn.lpstrInitialDir = "levels"; - ofn.lpstrTitle = "Might and Magic® VII - Load Which Level?"; - ofn.Flags = 4; - ofn.nFileOffset = 0; - ofn.nFileExtension = 0; - ofn.lpstrDefExt = "blv"; - ofn.lCustData = 0; - ofn.lpfnHook = 0; - ofn.lpTemplateName = 0; - ofn.lpstrFileTitle = pTmpBuf.data(); -} - //----- (004627B7) -------------------------------------------------------- void MainMenu_Loop() { @@ -3698,7 +3671,7 @@ int planes = GetDeviceCaps(hDC, PLANES); ReleaseDC(hWnd, hDC); if (bitsPerPixel != 16 || planes != 1) - Abortf(pGlobalTXT_LocalizationStrings[62]); + Error(pGlobalTXT_LocalizationStrings[62]); } BYTE1(dword_6BE364_game_settings_1) &= 0xFEu; @@ -5294,18 +5267,19 @@ pParty->Reset(); pParty->CreateDefaultParty(1); - - extern void CreateDefaultBLVLevel(); + + __debugbreak(); + /*extern void CreateDefaultBLVLevel(); CreateDefaultBLVLevel(); - extern OPENFILENAMEA ofn; + OPENFILENAMEA ofn; if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) ) { pMouse->Activate(1); break; } _chdir("..\\"); - strcpy(pCurrentMapName, ofn.lpstrFileTitle); + strcpy(pCurrentMapName, ofn.lpstrFileTitle);*/ pMouse->Activate(1); pGame->Loop(); } @@ -5539,40 +5513,6 @@ pOutdoorCamera->_485F64(); } -//----- (00466B8C) -------------------------------------------------------- -int AbortWithError() -{ - if ( !aborting_app ) - { - ClipCursor(0); - aborting_app = 1; - if ( !pRenderer->bWindowMode ) - pRenderer->ChangeBetweenWinFullscreenModes(); - if ( MessageBoxA(0, pGlobalTXT_LocalizationStrings[176], pGlobalTXT_LocalizationStrings[59], 0x34u) == 6 ) - SaveGame(1, 0); // "Internal Error" - // "Might and Magic VII has detected an internal error and will be forced to close. Would you like us to autosave your game before closing?" - Game_DeinitializeAndTerminate(1); - } - return 0; -} -// 720018: using guessed type int aborting_app; - -//----- (00466BE5) -------------------------------------------------------- -void Abortf(const char *Format, ...) -{ - va_list va; // [sp+8h] [bp+8h]@1 - - va_start(va, Format); - if ( !pRenderer->bWindowMode ) - pRenderer->ChangeBetweenWinFullscreenModes(); - vsprintf(pTmpBuf.data(), Format, va); - if ( pMouse ) - pMouse->Activate(0); - ClipCursor(0); - MessageBoxA(0, pTmpBuf.data(), "Error", 0x30u); - Game_DeinitializeAndTerminate(1); -} - //----- (00466C40) -------------------------------------------------------- const wchar_t *MENU_STATE_to_string(MENU_STATE m) {
--- a/mm7_3.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/mm7_3.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "Weather.h" #include "Texture.h" #include "mm7_data.h" @@ -801,22 +799,22 @@ v2->field_58.z = v6; if ( !a2 ) v7 = pEventTimer->dt_in_some_format; - v8 = ((unsigned __int64)(v7 * (signed __int64)v4) >> 16) - v2->field_70; + v8 = fixpoint_sub0(v7, v4) - v2->field_70; v2->field_6C = v8; if ( v8 > 0 ) { - v10 = ((unsigned __int64)(v8 * (signed __int64)v2->field_58.x) >> 16) + v2->normal.x; + v10 = fixpoint_sub0(v8, v2->field_58.x) + v2->normal.x; v2->field_4C = v10; v2->normal2.x = v10; - v11 = ((unsigned __int64)(v2->field_6C * (signed __int64)v2->field_58.y) >> 16) + v2->normal.y; + v11 = fixpoint_sub0(v2->field_6C, v2->field_58.y) + v2->normal.y; v2->field_50 = v11; v2->normal2.y = v11; - v2->normal2.z = ((unsigned __int64)(v2->field_6C * (signed __int64)v2->field_58.z) >> 16) + v2->normal.z; + v2->normal2.z = fixpoint_sub0(v2->field_6C, v2->field_58.z) + v2->normal.z; v12 = v2->field_34.z; v13 = v2->normal.x; v14 = v2->normal2.x; v15 = v2->prolly_normal_d; - v16 = v12 + ((unsigned __int64)(v2->field_6C * (signed __int64)v2->field_58.z) >> 16); + v16 = v12 + fixpoint_sub0(v2->field_6C, v2->field_58.z); v28 = v16; v2->field_54 = v16; v17 = v13; @@ -864,7 +862,7 @@ } //----- (004706C6) -------------------------------------------------------- -void UpdateActors_ODM() +void UpdateActors_ODM() { Actor *v0; // esi@2 AIState uAIState; // ax@2 @@ -878,19 +876,19 @@ //unsigned __int8 v9; // zf@17 unsigned __int8 v10; // sf@17 unsigned __int16 v11; // ax@21 - int v12; // eax@29 - unsigned __int64 v13; // qax@29 - int v14; // eax@30 - unsigned __int64 v15; // qax@30 + //int v12; // eax@29 + //unsigned __int64 v13; // qax@29 + //int v14; // eax@30 + //unsigned __int64 v15; // qax@30 int v16; // eax@33 //int v17; // edi@34 - int v18; // edx@42 - int v19; // ecx@42 + //int v18; // edx@42 + //int v19; // ecx@42 __int16 v20; // ax@42 - int v21; // ebx@42 - int v22; // edi@42 - int v23; // ecx@42 - __int16 v24; // ax@42 + //int v21; // ebx@42 + //int v22; // edi@42 + //int v23; // ecx@42 + //__int16 v24; // ax@42 int v25; // eax@45 signed int v26; // ecx@50 int v27; // eax@52 @@ -916,8 +914,8 @@ signed int v47; // ebx@85 int v48; // edi@85 int v49; // edi@85 - int v50; // eax@85 - unsigned __int64 v51; // qax@85 + //int v50; // eax@85 + //unsigned __int64 v51; // qax@85 //unsigned __int8 v52; // zf@87 //unsigned __int8 v53; // sf@87 // unsigned __int8 v54; // of@104 @@ -940,12 +938,12 @@ int v71; // [sp+38h] [bp-18h]@62 int uIsAboveFloor; // [sp+3Ch] [bp-14h]@10 int v72b; - int v73; // [sp+40h] [bp-10h]@17 + //int v73; // [sp+40h] [bp-10h]@17 int uIsFlying; // [sp+44h] [bp-Ch]@8 unsigned int v75; // [sp+48h] [bp-8h]@1 int uIsOnWater; // [sp+4Ch] [bp-4h]@10 - for(v75=0;(signed int)v75 < (signed int)uNumActors;++v75) + for (v75 = 0; v75 < uNumActors; ++v75) { v0 = &pActors[v75]; v66 = v0->vPosition.x; @@ -985,53 +983,34 @@ if ( v0->uCurrentActionAnimation == ANIM_Walking ) { v8 = v0->uMovementSpeed; - v73 = v0->uMovementSpeed; if ( (signed __int64)v0->pActorBuffs[7].uExpireTime > 0 ) { - v8 = (signed __int64)((double)v73 * 0.5); - v73 = (signed __int64)((double)v73 * 0.5); + v8 = (signed __int64)((double)v8 * 0.5); } if ( uAIState == Fleeing || uAIState == Pursuing ) { v8 *= 2; - v73 = v8; } if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->turn_stage == 1 ) - v8 = (signed __int64)((double)v73 * flt_6BE3AC_debug_recmod1_x_1_6); + v8 *= flt_6BE3AC_debug_recmod1_x_1_6; if ( v8 > 1000 ) v8 = 1000; - v12 = stru_5C6E00->Cos(v0->uYawAngle); - v13 = v12 * (signed __int64)v8; - v73 = v13 >> 16; - v0->vVelocity.x = WORD1(v13); - v69 = stru_5C6E00->Sin(v0->uYawAngle); - v73 = (unsigned __int64)((signed int)v69 * (signed __int64)v8) >> 16; - v0->vVelocity.y = v69 * v8 >> 16; + + v0->vVelocity.x = fixpoint_sub0(stru_5C6E00->Cos(v0->uYawAngle), v8); + v0->vVelocity.y = fixpoint_sub0(stru_5C6E00->Sin(v0->uYawAngle), v8); if ( uIsFlying ) { - v14 = stru_5C6E00->Sin(v0->uPitchAngle); - v69 = v14; - v15 = v14 * (signed __int64)v8; - v73 = v15 >> 16; - v0->vVelocity.z = WORD1(v15); + v0->vVelocity.z = fixpoint_sub0(stru_5C6E00->Sin(v0->uPitchAngle), v8); } //v7 = v68; } else { - v73 = v0->vVelocity.x; - v69 = 55000; - v73 = (unsigned __int64)(55000i64 * v73) >> 16; - v0->vVelocity.x = v73; - v73 = v0->vVelocity.y; - v73 = (unsigned __int64)((signed int)v69 * (signed __int64)v73) >> 16; - v0->vVelocity.y = v73; + v0->vVelocity.x = fixpoint_sub0(55000, v0->vVelocity.x); + v0->vVelocity.y = fixpoint_sub0(55000, v0->vVelocity.y); if ( uIsFlying ) { - v69 = 55000; - v73 = v0->vVelocity.z; - v73 = (unsigned __int64)(55000i64 * v73) >> 16; - v0->vVelocity.z = v73; + v0->vVelocity.z = fixpoint_sub0(55000, v0->vVelocity.z); } } if ( v0->vPosition.z < v5 ) @@ -1045,24 +1024,18 @@ { if ( v70 && !uIsAboveFloor && v67 ) { - v18 = v0->vPosition.y; - v19 = v0->vPosition.x; v0->vPosition.z = v5; - ODM_GetTerrainNormalAt(v19, v18, &v62); + ODM_GetTerrainNormalAt(v0->vPosition.x, v0->vPosition.y, &v62); v20 = GetGravityStrength(); - v21 = v62.y; - v22 = v62.z; - v23 = v62.y * v0->vVelocity.y; + //v21 = v62.y; + //v22 = v62.z; + //v23 = v62.y * v0->vVelocity.y; v0->vVelocity.z += -8 * LOWORD(pEventTimer->uTimeElapsed) * v20; - v73 = abs(v62.x * v0->vVelocity.x + v22 * v0->vVelocity.z + v23) >> 16; - v72b = v21; - v0->vVelocity.x += (unsigned int)(v73 * v62.x) >> 16; - v72b = (unsigned __int64)(v73 * (signed __int64)v72b) >> 16; - v24 = v72b; - v72b = v22; - v0->vVelocity.y += v24; - v72b = (unsigned __int64)(v73 * (signed __int64)v72b) >> 16; - v0->vVelocity.z += v72b; + int v73 = abs(v62.x * v0->vVelocity.x + v62.z * v0->vVelocity.z + v62.y * v0->vVelocity.y) >> 16; + //v72b = v21; + v0->vVelocity.x += fixpoint_sub0(v73, v62.x); + v0->vVelocity.y += fixpoint_sub0(v73, v62.y); + v0->vVelocity.z += fixpoint_sub0(v73, v62.z); //v17 = 0; } } @@ -1129,11 +1102,10 @@ } v71 = i > 1; if ( stru_721530.field_7C < stru_721530.field_6C ) - v70 = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.z) >> 16; + v70 = fixpoint_sub0(stru_721530.field_7C, stru_721530.field_58.z); //v34 = 0; v35 = stru_721530.normal2.z - stru_721530.prolly_normal_d - 1; - v36 = ODM_GetFloorLevel( - stru_721530.normal2.x, + v36 = ODM_GetFloorLevel(stru_721530.normal2.x, stru_721530.normal2.y, stru_721530.normal2.z - stru_721530.prolly_normal_d - 1, v0->uActorHeight, @@ -1163,13 +1135,13 @@ v0->vPosition.z = LOWORD(stru_721530.normal2.z) - LOWORD(stru_721530.prolly_normal_d) - 1; break; } - v72b = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.x) >> 16; - v0->vPosition.x += (unsigned int)(stru_721530.field_7C * stru_721530.field_58.x) >> 16; - v72b = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.y) >> 16; - v0->vPosition.y += (unsigned int)(stru_721530.field_7C * stru_721530.field_58.y) >> 16; - v72b = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.z) >> 16; + //v72b = fixpoint_sub0(stru_721530.field_7C, stru_721530.field_58.x); + v0->vPosition.x += fixpoint_sub0(stru_721530.field_7C, stru_721530.field_58.x); + //v72b = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.y) >> 16; + v0->vPosition.y += fixpoint_sub0(stru_721530.field_7C, stru_721530.field_58.y); + //v72b = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.z) >> 16; + v0->vPosition.z += fixpoint_sub0(stru_721530.field_7C, stru_721530.field_58.z); v38 = stru_721530.uFaceID; - v0->vPosition.z += (unsigned int)(stru_721530.field_7C * stru_721530.field_58.z) >> 16; stru_721530.field_70 += stru_721530.field_7C; v39 = PID_ID(v38); switch ( PID_TYPE(v38) ) @@ -1190,7 +1162,7 @@ Actor::AI_StandOrBored(v75, 4, 0, (AIDirection *)0); } } - else if ( v71 != 0 ) + else if ( v71 ) { Actor::AI_StandOrBored(v75, 4, 0, (AIDirection *)0); } @@ -1225,20 +1197,14 @@ v48 = stru_5C6E00->Atan2( v0->vPosition.x - pLevelDecorations[v39].vPosition.x, v0->vPosition.y - pLevelDecorations[v39].vPosition.y); - v71 = stru_5C6E00->Cos(v48); - v70 = (unsigned __int64)(v71 * (signed __int64)v47) >> 16; v49 = v48; - v0->vVelocity.x = (unsigned int)(v71 * v47) >> 16; - v50 = stru_5C6E00->Sin(v48); - v71 = v50; - v51 = v50 * (signed __int64)v47; - v70 = v51 >> 16; - v0->vVelocity.y = WORD1(v51); + v0->vVelocity.x = fixpoint_sub0(stru_5C6E00->Cos(v48), v47); + v0->vVelocity.y = fixpoint_sub0(stru_5C6E00->Sin(v48), v47); break; case OBJECT_BModel: v40 = &pOutdoor->pBModels[v38 >> 9]; v41 = &v40->pFaces[v39 & 0x3F]; - if ( !(BYTE3(v41->uAttributes) & 0x20) ) + if ( !(v41->uAttributes & 0x20000000) ) { v42 = v41->uPolygonType; if ( v42 == 3 ) @@ -1259,15 +1225,10 @@ + v41->pFacePlane.vNormal.x * v0->vVelocity.x) >> 16; if ( stru_721530.field_64 >> 3 > v72b ) v72b = stru_721530.field_64 >> 3; - v73 = v41->pFacePlane.vNormal.x; - v73 = (unsigned __int64)(v72b * (signed __int64)v73) >> 16; - v71 = v41->pFacePlane.vNormal.y; - v71 = (unsigned __int64)(v72b * (signed __int64)v71) >> 16; - v70 = v41->pFacePlane.vNormal.z; - v70 = (unsigned __int64)(v72b * (signed __int64)(signed int)v70) >> 16; - v0->vVelocity.x += v73; - v0->vVelocity.y += v71; - v0->vVelocity.z += v70; + + v0->vVelocity.x += fixpoint_sub0(v72b, v41->pFacePlane.vNormal.x); + v0->vVelocity.y += fixpoint_sub0(v72b, v41->pFacePlane.vNormal.y); + v0->vVelocity.z += fixpoint_sub0(v72b, v41->pFacePlane.vNormal.z); if ( v42 != 4 ) { v45 = v0->vPosition.z; @@ -1288,20 +1249,12 @@ } break; } - v70 = v0->vVelocity.x; - v71 = 58500; - v70 = (unsigned __int64)(58500i64 * (signed int)v70) >> 16; - v0->vVelocity.x = v70; - v70 = v0->vVelocity.y; - v70 = (unsigned __int64)(v71 * (signed __int64)(signed int)v70) >> 16; - v71 = 58500; - v0->vVelocity.y = v70; - v70 = v0->vVelocity.z; - v70 = (unsigned __int64)(v71 * (signed __int64)(signed int)v70) >> 16; + + v0->vVelocity.x = fixpoint_sub0(58500, v0->vVelocity.x); + v0->vVelocity.y = fixpoint_sub0(58500, v0->vVelocity.y); + v0->vVelocity.z = fixpoint_sub0(58500, v0->vVelocity.z); + ++v69; - //v54 = v69 < 100; - //v10 = (v69 - 100) < 0; - v0->vVelocity.z = v70; if ( v69 >= 100 ) break; v26 = stru_721530.prolly_normal_d; @@ -1368,8 +1321,8 @@ //do //{ //LOWORD(v0) = item->uAttributes; - if (item->uAttributes & 0x40) - item->uAttributes &= 0xFFBF; + if (item->uAttributes & OBJECT_40) + item->uAttributes &= ~OBJECT_40; else { //v3 = item->uObjectDescID; @@ -5940,19 +5893,6 @@ } -//----- (00481EB7) -------------------------------------------------------- -void ResetPolygons() -{ - for (auto i = 0; i < pOutdoorCamera->uNumPolygons; ++i) - { - array_77EC08[i].prolly_head = nullptr; - array_77EC08[i].prolly_tail = nullptr; - - array_77EC08[i].flags = 0; - array_77EC08[i].field_32 = 0; - } -} - //----- (00481ED9) -------------------------------------------------------- void sub_481ED9_MessWithOutdoorCamera() { @@ -6027,7 +5967,7 @@ int y_min = min(y1, min(y2, y3)), y_max = max(y1, max(y2, y3)); - return y_max - y_min > 512; + return (y_max - y_min) > 512; /*if ( y1 >= y2 ) { @@ -6631,10 +6571,7 @@ uLevelStrNumStrings = string_num - 1; if ( max_string_length > 800 ) - { - sprintf(Args, "MAX_EVENT_TEXT_LENGTH needs to be increased to %lu", max_string_length+1); - Abortf(Args); - } + Error("MAX_EVENT_TEXT_LENGTH needs to be increased to %lu", max_string_length+1); if ( uLevelStrNumStrings > 0 ) { @@ -7578,7 +7515,7 @@ unsigned int v7; // edx@18 signed int v8; // esi@19 int v9; // eax@19 - char Args; // [sp+Ch] [bp-78h]@6 + //char Args; // [sp+Ch] [bp-78h]@6 LOWORD(v2) = LOWORD(pIndoor->pDoors); v3 = a2; @@ -7596,8 +7533,7 @@ while ( v4 < 200 ); if ( v4 >= 200 ) { - sprintf(&Args, "Unable to find Door ID: %i!", uDoorID); - Abortf(&Args); + Error("Unable to find Door ID: %i!", uDoorID); } v6 = &pIndoor->pDoors[v4]; if ( v3 == 2 )
--- a/mm7_4.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/mm7_4.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "Texture.h" #include "mm7_data.h" #include "VideoPlayer.h" @@ -1558,7 +1556,7 @@ v2 = fopen("data\\dpft.bin", "wb"); v3 = v2; if ( !v2 ) - Abortf("Unable to save dpft.bin!"); + Error("Unable to save dpft.bin"); fwrite(v1, 4u, 1u, v2); fwrite(v1->pFrames, 0xAu, v1->uNumFrames, v3); fclose(v3); @@ -1615,7 +1613,7 @@ v3 = fopen(Args, "r"); File = v3; if ( !v3 ) - Abortf("PlayerFrameTable::load - Unable to open file: %s.", Args); + Error("PlayerFrameTable::load - Unable to open file: %s.", Args); v4 = 0; v25 = 0; v26 = 1; @@ -1628,7 +1626,7 @@ if ( v24.uPropCount && *v24.pProperties[0] != 47 ) { if ( v24.uPropCount < 3 ) - Abortf("PlayerFrameTable::load, too few arguments, %s line %i.", Args, v26); + Error("PlayerFrameTable::load, too few arguments, %s line %i.", Args, v26); ++v25; } ++v26; @@ -1640,7 +1638,7 @@ v5 = pAllocator->AllocNamedChunk(v2->pFrames, 10 * v4, "P Frames"); v2->pFrames = (PlayerFrame *)v5; if ( !v5 ) - Abortf("PlayerFrameTable::load - Out of Memory!"); + Error("PlayerFrameTable::load - Out of Memory!"); v6 = File; v2->uNumFrames = 0; fseek(v6, 0, 0);
--- a/mm7_5.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/mm7_5.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -2,8 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include <assert.h> - #include "Texture.h" #include "mm7_data.h" #include "VideoPlayer.h" @@ -4674,8 +4672,8 @@ int v21; // edi@20 signed int v22; // eax@22 signed __int64 v23; // qtt@22 - bool result; // eax@25 - int v25; // [sp+14h] [bp-8h]@14 + //bool result; // eax@25 + //int v25; // [sp+14h] [bp-8h]@14 int a4a; // [sp+28h] [bp+Ch]@2 signed int a5a; // [sp+2Ch] [bp+10h]@14 @@ -4725,23 +4723,24 @@ { if( dword_4F5BF4_xs[i + 2] >= a4a || dword_4F5BF4_xs[i] >= a4a) { - if ( (dword_4F5BF4_xs[i + 2] >= a4a && dword_4F5BF4_xs[i + 1] >= a4a) - || (v25 = dword_4F5BF4_xs[i + 2] - dword_4F5BF4_xs[i + 1], - LODWORD(v23) = v25 << 16, - HIDWORD(v23) = v25 >> 16, - dword_4F5BF4_xs[i + 1] - + ((signed int)(((unsigned __int64)(v23 - / (dword_4F5B24_ys[i + 2] - dword_4F5B24_ys[i + 1]) - * ((a3 - dword_4F5B24_ys[i + 1]) << 16)) >> 16) - + 32768) >> 16) >= a4a) ) - ++a5a; + if (dword_4F5BF4_xs[i + 2] >= a4a && dword_4F5BF4_xs[i + 1] >= a4a) + ++a5a; + else + { + v23 = (__int64)(dword_4F5BF4_xs[i + 2] - dword_4F5BF4_xs[i + 1]) << 16; + __int64 _a = dword_4F5B24_ys[i + 2] - dword_4F5B24_ys[i + 1]; + __int64 _b = (__int64)(a3 - dword_4F5B24_ys[i + 1]) << 16; + + if (dword_4F5BF4_xs[i + 1] + ((((v23 / _a * _b) >> 16) + 32768) >> 16) >= a4a) + ++a5a; + } } } } - result = 1; + if ( a5a != 1 ) - result = 0; - return result; + return false; + return true; }
--- a/mm7_data.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/mm7_data.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1236,7 +1236,6 @@ bool bNoLogo = false; bool bNoCD = false; bool bNoSound = false; -int aborting_app; // weak std::array<int, 100> dword_720020_zvalues; std::array<int, 299> dword_7201B0_zvalues; int uTextureID_720980; // weak
--- a/mm7_data.h Sat Sep 07 15:20:57 2013 +0200 +++ b/mm7_data.h Sat Sep 07 20:05:20 2013 +0200 @@ -888,7 +888,6 @@ extern bool bNoLogo; extern bool bNoCD; extern bool bNoSound; -extern int aborting_app; // weak extern std::array<int, 100> dword_720020_zvalues; extern std::array<int, 299> dword_7201B0_zvalues; extern int dword_7207F0[]; // idb @@ -1216,8 +1215,6 @@ void CreateAsyncKeyboard(); void MM6_Initialize(const wchar_t *pIniFilename); void MM7Initialization(); -int AbortWithError(); -void Abortf(const char *Format, ...); void SetCurrentMenuID(enum MENU_STATE); // idb enum MENU_STATE GetCurrentMenuID(); void CreateMsgScrollWindow(signed int mscroll_id); @@ -1260,7 +1257,6 @@ unsigned int WorldPosToGridCellZ(int); // weak int GridCellToWorldPosX(int); // weak int GridCellToWorldPosZ(int); // weak -void ResetPolygons(); void sub_481ED9_MessWithOutdoorCamera(); bool IsTerrainSlopeTooHigh(int pos_x, int pos_y); int __fastcall GetTerrainHeightsAroundParty2(int a1, int a2, int *a3, int a4);
--- a/mm7text_ru.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/mm7text_ru.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -5,9 +5,9 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> -#include <assert.h> #include "Log.h" +#include "ErrorHandling.h" struct GenderTableEntry @@ -1161,14 +1161,14 @@ return nullptr; } -int sprintfex_internal(char *str) +int sprintfex_internal(char *str) { auto p = strstr(str, "^"); if (!p) return strlen(str); char buf[8192]; - assert(strlen(str) < sizeof(buf)); + Assert(strlen(str) < sizeof(buf)); int next_integer_token = 0; bool integer_tokens_defined[10] = {false, false, false, false, false, false, false, false, false, false}; @@ -1190,7 +1190,7 @@ goto _invalid_token; src += 3; // ^I[ - assert(next_integer_token < 10); + Assert(next_integer_token < 10); if (sscanf(src, "%d", &integer_tokens[next_integer_token])) integer_tokens_defined[next_integer_token++] = true; @@ -1217,7 +1217,7 @@ else if (src[2] != '[') goto _invalid_token; - assert(integer_tokens_defined[integer_token_idx]); + Assert(integer_tokens_defined[integer_token_idx]); src += 3; // ^L[ auto ending1 = src; @@ -1256,7 +1256,7 @@ { if (src[2] != '[') goto _invalid_token; - assert(gender_token_defined); + Assert(gender_token_defined); src += 3; // ^R[ @@ -1285,7 +1285,7 @@ actual_ending = ending3; actual_ending_len = src - ending3 - 1; } - else assert(false); + else Error("Invalid gender token"); strncpy(dst, actual_ending, actual_ending_len); dst += actual_ending_len; @@ -1367,8 +1367,7 @@ strncpy(token, token_begin, token_len); token[token_len] = 0; - Log::Warning(L"Invalid format token: %S", token); - assert(false); + Error("Invalid format token: %s", token); } break; }
--- a/stru10.cpp Sat Sep 07 15:20:57 2013 +0200 +++ b/stru10.cpp Sat Sep 07 20:05:20 2013 +0200 @@ -1,10 +1,9 @@ -#include <assert.h> - #include "stru10.h" #include "Render.h" #include "Indoor.h" #include "Game.h" #include "Party.h" +#include "ErrorHandling.h" #include "mm7_data.h" @@ -81,7 +80,7 @@ //----- (0049CE9E) -------------------------------------------------------- void stru10::_49CE9E(BLVFace *pFace, RenderVertexSoft *pVertices, unsigned int uNumVertices, RenderVertexSoft *pOutLimits) { - assert(sizeof(RenderVertexSoft) == 0x30); + Assert(sizeof(RenderVertexSoft) == 0x30); RenderVertexSoft pLimits[64]; stru10::CalcPolygonLimits(pFace, pLimits); @@ -273,7 +272,7 @@ break; default: - assert(false); + Error("Invalid polygon type (%u)", pFace->uPolygonType); }