[
  {
    "path": ".gitignore",
    "content": "*.exe\n*.dll\n*.lib\n*.exp\n*.gch\n*.layout\n*.depend\n*.cscope_file_list\ncscope.out\n\nobj/\nbin/\ndoc/"
  },
  {
    "path": "3dsystem/3d_gen.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"3dsystem/3d_out.h\"\n#include \"3dsystem/3dinsert.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"3dsystem/scalespr.h\"\n#include \"specific/hwr.h\"\n#include \"global/vars.h\"\n\n// related to POLYTYPE enum\nstatic void (__cdecl *PolyDrawRoutines[])(__int16 *) = {\n\tdraw_poly_gtmap,\t\t// gouraud shaded poly (texture)\n\tdraw_poly_wgtmap,\t\t// gouraud shaded poly (texture + colorkey)\n\tdraw_poly_gtmap_persp,\t// gouraud shaded poly (texture + perspective)\n\tdraw_poly_wgtmap_persp,\t// gouraud shaded poly (texture + colorkey + perspective)\n\tdraw_poly_line,\t\t\t// line (color)\n\tdraw_poly_flat,\t\t\t// flat shaded poly (color)\n\tdraw_poly_gouraud,\t\t// gouraud shaded poly (color)\n\tdraw_poly_trans,\t\t// shadow poly (color + semitransparent)\n\tdraw_scaled_spriteC\t\t// scaled sprite (texture + colorkey)\n};\n\n#if defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_VIEW_IMPROVED)\nSORT_ITEM SortBuffer[16000];\n__int16 Info3dBuffer[480000];\n#endif // defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_VIEW_IMPROVED)\n\n#ifdef FEATURE_EXTENDED_LIMITS\nPHD_SPRITE PhdSpriteInfo[2048];\nD3DTLVERTEX HWR_VertexBuffer[0x8000];\n#endif // FEATURE_EXTENDED_LIMITS\n\n#ifdef FEATURE_VIEW_IMPROVED\nbool PsxFovEnabled;\n\n// view distance\ndouble ViewDistanceFactor = 6.0;\n\n// regular fog\ndouble FogBeginFactor = 1.0;\ndouble FogEndFactor = 6.0;\nint FogBeginDepth = DEPTHQ_START;\nint FogEndDepth = DEPTHQ_END;\n\n// underwater fog\ndouble WaterFogBeginFactor = 0.6;\ndouble WaterFogEndFactor = 1.0;\nint WaterFogBeginDepth = DEPTHQ_START;\nint WaterFogEndDepth = DEPTHQ_END;\n\n// fog formula\nint CalculateFogShade(int depth) {\n\tint fogBegin, fogEnd;\n\n\tif( IsWaterEffect ) {\n\t\tfogBegin = WaterFogBeginDepth;\n\t\tfogEnd = WaterFogEndDepth;\n\t} else {\n\t\tfogBegin = FogBeginDepth;\n\t\tfogEnd = FogEndDepth;\n\t}\n\n\tif( depth < fogBegin )\n\t\treturn 0;\n\tif( depth >= fogEnd )\n\t\treturn 0x1FFF;\n\n\treturn (depth - fogBegin) * 0x1FFF / (fogEnd - fogBegin);\n}\n#endif // FEATURE_VIEW_IMPROVED\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n#include \"modding/mod_utils.h\"\n\nextern DWORD ReflectionMode;\nstatic POLYFILTER ReflectFilter;\nstatic D3DCOLOR ReflectTint = 0;\nstatic bool IsReflect = false;\n\nvoid ClearMeshReflectState() {\n\tmemset(&ReflectFilter, 0 , sizeof(ReflectFilter));\n\tReflectTint = RGBA_MAKE(0xFF,0xFF,0xFF,0x80);\n\tIsReflect = false;\n}\n\nvoid SetMeshReflectState(int objID, int meshIdx) {\n\t// Clear poly filters and disable reflection by default\n\tClearMeshReflectState();\n\tif( TextureFormat.bpp < 16 || !ReflectionMode ) return;\n\n\tif( objID == ID_NONE ) {\n\t\t// Reflect all meshes with custom tint instead of mesh index\n\t\tReflectTint = meshIdx;\n\t\tIsReflect = true;\n\t\treturn;\n\t}\n\n#ifdef FEATURE_MOD_CONFIG\n\t// Check if config is presented\n\tif( IsModReflectConfigLoaded() ) {\n\t\tPOLYFILTER_NODE *node = NULL;\n\t\tif( meshIdx < 0 ) {\n\t\t\tfor( node = GetModReflectStaticsFilter(); node != NULL; node = node->next ) {\n\t\t\t\tif( node->id == objID ) {\n\t\t\t\t\tReflectFilter = node->filter;\n\t\t\t\t\tIsReflect = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if( objID >= 0 && objID < ID_NUMBER_OBJECTS ) {\n\t\t\tPOLYFILTER_NODE **obj = GetModReflectObjectsFilter();\n\t\t\tfor( node = obj[objID]; node != NULL; node = node->next ) {\n\t\t\t\tif( node->id == meshIdx ) {\n\t\t\t\t\tReflectFilter = node->filter;\n\t\t\t\t\tIsReflect = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n#endif // FEATURE_MOD_CONFIG\n\n\t// If config is absent or disabled, use hardcoded params\n\tif( objID >= 0 && meshIdx < 0 ) {\n\t\t// This is static object mesh\n\t\treturn;\n\t}\n\n\t// This is animated object mesh\n\tswitch( objID ) {\n\tcase ID_SKIDOO_FAST :\n\t\t// This one is a fast showmobile from the Golden Mask\n\t\t// Reflect the windshield only (skidoo body is mesh #0)\n\t\tif( meshIdx == 0 ) {\n\t\t\t// Set filter conditions\n\t\t\tReflectFilter.n_vtx = 59;\n\t\t\tReflectFilter.n_gt4 = 14;\n\t\t\tReflectFilter.n_gt3 = 73;\n\t\t\tReflectFilter.n_g4 = 0;\n\t\t\tReflectFilter.n_g3 = 17;\n\t\t\t// All colored triangles are reflective\n\t\t\t// The only reflective textured triangle is 48\n\t\t\tReflectFilter.gt3[0].idx = 48;\n\t\t\tReflectFilter.gt3[0].num = 1;\n\t\t\t// Quads are not reflective\n\t\t\tReflectFilter.gt4[0].idx = ~0;\n\t\t\tReflectFilter.g4[0].idx = ~0;\n\t\t\tIsReflect = true;\n\t\t}\n\t\tbreak;\n\tcase ID_SKIDOO_ARMED :\n\t\t// This one is an armed showmobile\n\t\t// Reflect the windshield only (skidoo body is mesh #0)\n\t\tif( meshIdx == 0 ) {\n\t\t\t// Set filter conditions\n\t\t\tReflectFilter.n_vtx = 88;\n\t\t\tReflectFilter.n_gt4 = 45;\n\t\t\tReflectFilter.n_gt3 = 60;\n\t\t\tReflectFilter.n_g4 = 0;\n\t\t\tReflectFilter.n_g3 = 0;\n\t\t\t// The reflective textured quads are 21..22, 34..47\n\t\t\tReflectFilter.gt4[0].idx = 21;\n\t\t\tReflectFilter.gt4[0].num = 2;\n\t\t\tReflectFilter.gt3[0].idx = 34;\n\t\t\tReflectFilter.gt3[0].num = 14;\n\t\t\t// Other polys are not reflective\n\t\t\tReflectFilter.g4[0].idx = ~0;\n\t\t\tReflectFilter.g3[0].idx = ~0;\n\t\t\tIsReflect = true;\n\t\t}\n\t\tbreak;\n\tcase ID_WORKER5 :\n\t\t// Reflect the black glass mask of flamethrower buddy (his head is mesh #15)\n\t\tif( meshIdx == 15 ) {\n\t\t\t// Set filter conditions\n\t\t\tReflectFilter.n_vtx = 38;\n\t\t\tReflectFilter.n_gt4 = 30;\n\t\t\tReflectFilter.n_gt3 = 12;\n\t\t\tReflectFilter.n_g4 = 0;\n\t\t\tReflectFilter.n_g3 = 0;\n\t\t\t// The reflective textured quads are 22..26\n\t\t\tReflectFilter.gt4[0].idx = 22;\n\t\t\tReflectFilter.gt4[0].num = 5;\n\t\t\t// Other polys are not reflective\n\t\t\tReflectFilter.gt3[0].idx = ~0;\n\t\t\tReflectFilter.g4[0].idx = ~0;\n\t\t\tReflectFilter.g3[0].idx = ~0;\n\t\t\tIsReflect = true;\n\t\t}\n\t\tbreak;\n\tcase ID_SPINNING_BLADE :\n\t\tif( meshIdx == 0 ) {\n\t\t\t// Reflect only quads, not triangles\n\t\t\tReflectFilter.gt3[0].idx = ~0;\n\t\t\tReflectFilter.g3[0].idx = ~0;\n\t\t\tIsReflect = true;\n\t\t}\n\t\tbreak;\n\tcase ID_BLADE :\n\t\t// Reflect the blade only (mesh #1)\n\t\tif( meshIdx == 1 ) {\n\t\t\tIsReflect = true;\n\t\t}\n\t\tbreak;\n\tcase ID_KILLER_STATUE :\n\t\t// Reflect the sword only (mesh #7)\n\t\tif( meshIdx == 7 ) {\n\t\t\tIsReflect = true;\n\t\t}\n\t\tbreak;\n\t}\n}\n\nstatic bool InsertEnvmap(__int16 *ptrObj, int vtxCount, bool colored, LPVOID param) {\n\tInsertObjectEM(ptrObj, vtxCount, ReflectTint, (PHD_UV *)param);\n\treturn true;\n}\n\nstatic void phd_PutEnvmapPolygons(__int16 *ptrEnv) {\n\tif( ptrEnv == NULL || !IsReflect\n\t\t|| SavedAppSettings.RenderMode != RM_Hardware ) return;\n\t__int16 *ptrObj = ptrEnv;\n\n\tptrObj += 5; // skip x, y, z, radius, flags\n\t__int16 num = *(ptrObj++); // get vertex counter\n\tptrObj += num * 3; // skip vertices\n\n\tint vtxCount = *ptrObj++;\n\tif( vtxCount <= 0 ) return;\n\n\tPHD_UV *uv = new PHD_UV[vtxCount];\n\n\tfor( int i = 0; i < vtxCount; ++i ) {\n\t\t// make sure that reflection will be drawn after normal poly\n\t\tPhdVBuf[i].zv -= (double)(W2V_SCALE/2);\n\t\t// set lighting that depends only from fog distance\n\t\tPhdVBuf[i].g = 0x1000;\n\t\tint depth = PhdMatrixPtr->_23 >> W2V_SHIFT;\n#ifdef FEATURE_VIEW_IMPROVED\n\t\tPhdVBuf[i].g += CalculateFogShade(depth);\n#else // !FEATURE_VIEW_IMPROVED\n\t\tif( depth > DEPTHQ_START ) // fog begin\n\t\t\tPhdVBuf[i].g += depth - DEPTHQ_START;\n#endif // FEATURE_VIEW_IMPROVED\n\t\tCLAMP(PhdVBuf[i].g, 0x1000, 0x1FFF); // reflection can be darker but not brighter\n\n\t\t// rotate normal vectors for X/Y, no translation\n\t\tint x = (PhdMatrixPtr->_00 * ptrObj[0] +\n\t\t\t\t PhdMatrixPtr->_01 * ptrObj[1] +\n\t\t\t\t PhdMatrixPtr->_02 * ptrObj[2]) >> W2V_SHIFT;\n\n\t\tint y = (PhdMatrixPtr->_10 * ptrObj[0] +\n\t\t\t\t PhdMatrixPtr->_11 * ptrObj[1] +\n\t\t\t\t PhdMatrixPtr->_12 * ptrObj[2]) >> W2V_SHIFT;\n\n\t\tCLAMP(x, -PHD_IONE, PHD_IONE);\n\t\tCLAMP(y, -PHD_IONE, PHD_IONE);\n\t\tuv[i].u = PHD_ONE/PHD_IONE * (x + PHD_IONE)/2;\n\t\tuv[i].v = PHD_ONE/PHD_IONE * (y + PHD_IONE)/2;\n\t\tptrObj += 3;\n\t}\n\n\tEnumeratePolys(ptrEnv, false, InsertEnvmap, &ReflectFilter, (LPVOID)uv);\n\tdelete[] uv;\n}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\nvoid phd_GenerateW2V(PHD_3DPOS *viewPos) {\n\tint sx = phd_sin(viewPos->rotX);\n\tint cx = phd_cos(viewPos->rotX);\n\tint sy = phd_sin(viewPos->rotY);\n\tint cy = phd_cos(viewPos->rotY);\n\tint sz = phd_sin(viewPos->rotZ);\n\tint cz = phd_cos(viewPos->rotZ);\n\n\tPhdMatrixPtr = &MatrixStack[0]; // set matrix stack pointer to W2V\n\n\tMatrixW2V._00 = PhdMatrixPtr->_00 = TRIGMULT3(sx, sy, sz) + TRIGMULT2(cy, cz);\n\tMatrixW2V._01 = PhdMatrixPtr->_01 = TRIGMULT2(cx, sz);\n\tMatrixW2V._02 = PhdMatrixPtr->_02 = TRIGMULT3(sx, cy, sz) - TRIGMULT2(sy, cz);\n\n\tMatrixW2V._10 = PhdMatrixPtr->_10 = (int)(FltViewAspect * (double)(TRIGMULT3(sx, sy, cz) - TRIGMULT2(cy, sz)));\n\tMatrixW2V._11 = PhdMatrixPtr->_11 = (int)(FltViewAspect * (double)(TRIGMULT2(cx, cz)));\n\tMatrixW2V._12 = PhdMatrixPtr->_12 = (int)(FltViewAspect * (double)(TRIGMULT3(sx, cy, cz) + TRIGMULT2(sy, sz)));\n\n\tMatrixW2V._20 = PhdMatrixPtr->_20 = TRIGMULT2(cx, sy);\n\tMatrixW2V._21 = PhdMatrixPtr->_21 = -(sx);\n\tMatrixW2V._22 = PhdMatrixPtr->_22 = TRIGMULT2(cx, cy);\n\n\tMatrixW2V._03 = PhdMatrixPtr->_03 = viewPos->x;;\n\tMatrixW2V._13 = PhdMatrixPtr->_13 = viewPos->y;\n\tMatrixW2V._23 = PhdMatrixPtr->_23 = viewPos->z;\n}\n\nvoid __cdecl phd_LookAt(int xsrc, int ysrc, int zsrc, int xtar, int ytar, int ztar, __int16 roll) {\n\tPHD_3DPOS viewPos;\n\tVECTOR_ANGLES angles;\n\n\tphd_GetVectorAngles(xtar - xsrc, ytar - ysrc, ztar - zsrc, &angles);\n\tviewPos.x = xsrc;\n\tviewPos.y = ysrc;\n\tviewPos.z = zsrc;\n\tviewPos.rotX = angles.pitch;\n\tviewPos.rotY = angles.yaw;\n\tviewPos.rotZ = roll;\n\tphd_GenerateW2V(&viewPos);\n}\n\nvoid __cdecl phd_GetVectorAngles(int x, int y, int z, VECTOR_ANGLES *angles) {\n\t__int16 pitch;\n\n\tangles->yaw = phd_atan(z, x);\n\n\twhile( (__int16)x != x || (__int16)y != y || (__int16)z != z ) {\n\t\tx >>= 2;\n\t\ty >>= 2;\n\t\tz >>= 2;\n\t}\n\tpitch = phd_atan(phd_sqrt(SQR(x) + SQR(z)), y);\n\n\tif( (y > 0 && pitch > 0) || (y < 0 && pitch < 0) )\n\t\tpitch = -pitch;\n\n\tangles->pitch = pitch;\n}\n\nvoid __cdecl phd_RotX(__int16 angle) {\n\tif( angle != 0 ) {\n\t\tint m0, m1;\n\t\tint sx = phd_sin(angle);\n\t\tint cx = phd_cos(angle);\n\n\t\tm0 = PhdMatrixPtr->_01 * cx + PhdMatrixPtr->_02 * sx;\n\t\tm1 = PhdMatrixPtr->_02 * cx - PhdMatrixPtr->_01 * sx;\n\t\tPhdMatrixPtr->_01 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_02 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_11 * cx + PhdMatrixPtr->_12 * sx;\n\t\tm1 = PhdMatrixPtr->_12 * cx - PhdMatrixPtr->_11 * sx;\n\t\tPhdMatrixPtr->_11 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_12 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_21 * cx + PhdMatrixPtr->_22 * sx;\n\t\tm1 = PhdMatrixPtr->_22 * cx - PhdMatrixPtr->_21 * sx;\n\t\tPhdMatrixPtr->_21 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_22 = m1 >> W2V_SHIFT;\n\t}\n}\n\nvoid __cdecl phd_RotY(__int16 angle) {\n\tif( angle != 0 ) {\n\t\tint m0, m1;\n\t\tint sy = phd_sin(angle);\n\t\tint cy = phd_cos(angle);\n\n\t\tm0 = PhdMatrixPtr->_00 * cy - PhdMatrixPtr->_02 * sy;\n\t\tm1 = PhdMatrixPtr->_02 * cy + PhdMatrixPtr->_00 * sy;\n\t\tPhdMatrixPtr->_00 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_02 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_10 * cy - PhdMatrixPtr->_12 * sy;\n\t\tm1 = PhdMatrixPtr->_12 * cy + PhdMatrixPtr->_10 * sy;\n\t\tPhdMatrixPtr->_10 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_12 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_20 * cy - PhdMatrixPtr->_22 * sy;\n\t\tm1 = PhdMatrixPtr->_22 * cy + PhdMatrixPtr->_20 * sy;\n\t\tPhdMatrixPtr->_20 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_22 = m1 >> W2V_SHIFT;\n\t}\n}\n\nvoid __cdecl phd_RotZ(__int16 angle) {\n\tif( angle != 0 ) {\n\t\tint m0, m1;\n\t\tint sz = phd_sin(angle);\n\t\tint cz = phd_cos(angle);\n\n\t\tm0 = PhdMatrixPtr->_00 * cz + PhdMatrixPtr->_01 * sz;\n\t\tm1 = PhdMatrixPtr->_01 * cz - PhdMatrixPtr->_00 * sz;\n\t\tPhdMatrixPtr->_00 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_01 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_10 * cz + PhdMatrixPtr->_11 * sz;\n\t\tm1 = PhdMatrixPtr->_11 * cz - PhdMatrixPtr->_10 * sz;\n\t\tPhdMatrixPtr->_10 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_11 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_20 * cz + PhdMatrixPtr->_21 * sz;\n\t\tm1 = PhdMatrixPtr->_21 * cz - PhdMatrixPtr->_20 * sz;\n\t\tPhdMatrixPtr->_20 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_21 = m1 >> W2V_SHIFT;\n\t}\n}\n\nvoid __cdecl phd_RotYXZ(__int16 ry, __int16 rx, __int16 rz) {\n\tint sx, cx;\n\tint sy, cy;\n\tint sz, cz;\n\tint m0, m1;\n\n\tif( ry != 0 ) {\n\t\tsy = phd_sin(ry);\n\t\tcy = phd_cos(ry);\n\t\tm0 = PhdMatrixPtr->_00 * cy - PhdMatrixPtr->_02 * sy;\n\t\tm1 = PhdMatrixPtr->_02 * cy + PhdMatrixPtr->_00 * sy;\n\t\tPhdMatrixPtr->_00 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_02 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_10 * cy - PhdMatrixPtr->_12 * sy;\n\t\tm1 = PhdMatrixPtr->_12 * cy + PhdMatrixPtr->_10 * sy;\n\t\tPhdMatrixPtr->_10 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_12 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_20 * cy - PhdMatrixPtr->_22 * sy;\n\t\tm1 = PhdMatrixPtr->_22 * cy + PhdMatrixPtr->_20 * sy;\n\t\tPhdMatrixPtr->_20 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_22 = m1 >> W2V_SHIFT;\n\t}\n\tif( rx != 0 ) {\n\t\tsx = phd_sin(rx);\n\t\tcx = phd_cos(rx);\n\t\tm0 = PhdMatrixPtr->_01 * cx + PhdMatrixPtr->_02 * sx;\n\t\tm1 = PhdMatrixPtr->_02 * cx - PhdMatrixPtr->_01 * sx;\n\t\tPhdMatrixPtr->_01 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_02 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_11 * cx + PhdMatrixPtr->_12 * sx;\n\t\tm1 = PhdMatrixPtr->_12 * cx - PhdMatrixPtr->_11 * sx;\n\t\tPhdMatrixPtr->_11 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_12 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_21 * cx + PhdMatrixPtr->_22 * sx;\n\t\tm1 = PhdMatrixPtr->_22 * cx - PhdMatrixPtr->_21 * sx;\n\t\tPhdMatrixPtr->_21 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_22 = m1 >> W2V_SHIFT;\n\t}\n\tif( rz != 0 ) {\n\t\tsz = phd_sin(rz);\n\t\tcz = phd_cos(rz);\n\t\tm0 = PhdMatrixPtr->_00 * cz + PhdMatrixPtr->_01 * sz;\n\t\tm1 = PhdMatrixPtr->_01 * cz - PhdMatrixPtr->_00 * sz;\n\t\tPhdMatrixPtr->_00 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_01 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_10 * cz + PhdMatrixPtr->_11 * sz;\n\t\tm1 = PhdMatrixPtr->_11 * cz - PhdMatrixPtr->_10 * sz;\n\t\tPhdMatrixPtr->_10 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_11 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_20 * cz + PhdMatrixPtr->_21 * sz;\n\t\tm1 = PhdMatrixPtr->_21 * cz - PhdMatrixPtr->_20 * sz;\n\t\tPhdMatrixPtr->_20 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_21 = m1 >> W2V_SHIFT;\n\t}\n}\n\nvoid __cdecl phd_RotYXZpack(DWORD rpack) {\n\tint sx, cx;\n\tint sy, cy;\n\tint sz, cz;\n\tint m0, m1;\n\t__int16 rx = ((rpack >> 20) & 0x3FF) << 6;\n\t__int16 ry = ((rpack >> 10) & 0x3FF) << 6;\n\t__int16 rz = ((rpack >> 00) & 0x3FF) << 6;\n\n\tif( ry != 0 ) {\n\t\tsy = phd_sin(ry);\n\t\tcy = phd_cos(ry);\n\t\tm0 = PhdMatrixPtr->_00 * cy - PhdMatrixPtr->_02 * sy;\n\t\tm1 = PhdMatrixPtr->_02 * cy + PhdMatrixPtr->_00 * sy;\n\t\tPhdMatrixPtr->_00 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_02 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_10 * cy - PhdMatrixPtr->_12 * sy;\n\t\tm1 = PhdMatrixPtr->_12 * cy + PhdMatrixPtr->_10 * sy;\n\t\tPhdMatrixPtr->_10 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_12 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_20 * cy - PhdMatrixPtr->_22 * sy;\n\t\tm1 = PhdMatrixPtr->_22 * cy + PhdMatrixPtr->_20 * sy;\n\t\tPhdMatrixPtr->_20 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_22 = m1 >> W2V_SHIFT;\n\t}\n\tif( rx != 0 ) {\n\t\tsx = phd_sin(rx);\n\t\tcx = phd_cos(rx);\n\t\tm0 = PhdMatrixPtr->_01 * cx + PhdMatrixPtr->_02 * sx;\n\t\tm1 = PhdMatrixPtr->_02 * cx - PhdMatrixPtr->_01 * sx;\n\t\tPhdMatrixPtr->_01 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_02 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_11 * cx + PhdMatrixPtr->_12 * sx;\n\t\tm1 = PhdMatrixPtr->_12 * cx - PhdMatrixPtr->_11 * sx;\n\t\tPhdMatrixPtr->_11 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_12 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_21 * cx + PhdMatrixPtr->_22 * sx;\n\t\tm1 = PhdMatrixPtr->_22 * cx - PhdMatrixPtr->_21 * sx;\n\t\tPhdMatrixPtr->_21 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_22 = m1 >> W2V_SHIFT;\n\t}\n\tif( rz != 0 ) {\n\t\tsz = phd_sin(rz);\n\t\tcz = phd_cos(rz);\n\t\tm0 = PhdMatrixPtr->_00 * cz + PhdMatrixPtr->_01 * sz;\n\t\tm1 = PhdMatrixPtr->_01 * cz - PhdMatrixPtr->_00 * sz;\n\t\tPhdMatrixPtr->_00 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_01 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_10 * cz + PhdMatrixPtr->_11 * sz;\n\t\tm1 = PhdMatrixPtr->_11 * cz - PhdMatrixPtr->_10 * sz;\n\t\tPhdMatrixPtr->_10 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_11 = m1 >> W2V_SHIFT;\n\t\tm0 = PhdMatrixPtr->_20 * cz + PhdMatrixPtr->_21 * sz;\n\t\tm1 = PhdMatrixPtr->_21 * cz - PhdMatrixPtr->_20 * sz;\n\t\tPhdMatrixPtr->_20 = m0 >> W2V_SHIFT;\n\t\tPhdMatrixPtr->_21 = m1 >> W2V_SHIFT;\n\t}\n}\n\nBOOL __cdecl phd_TranslateRel(int x, int y, int z) {\n\tPhdMatrixPtr->_03 += PhdMatrixPtr->_00 * x + PhdMatrixPtr->_01 * y + PhdMatrixPtr->_02 * z;\n\tPhdMatrixPtr->_13 += PhdMatrixPtr->_10 * x + PhdMatrixPtr->_11 * y + PhdMatrixPtr->_12 * z;\n\tPhdMatrixPtr->_23 += PhdMatrixPtr->_20 * x + PhdMatrixPtr->_21 * y + PhdMatrixPtr->_22 * z;\n\n\tif( ABS(PhdMatrixPtr->_03) > PhdFarZ ||\n\t\tABS(PhdMatrixPtr->_13) > PhdFarZ ||\n\t\tABS(PhdMatrixPtr->_23) > PhdFarZ )\n\t{\n\t\treturn FALSE;\n\t}\n\treturn TRUE;\n}\n\nvoid __cdecl phd_TranslateAbs(int x, int y, int z) {\n\tx -= MatrixW2V._03;\n\ty -= MatrixW2V._13;\n\tz -= MatrixW2V._23;\n\n\tPhdMatrixPtr->_03 = x * PhdMatrixPtr->_00 + y * PhdMatrixPtr->_01 + z * PhdMatrixPtr->_02;\n\tPhdMatrixPtr->_13 = x * PhdMatrixPtr->_10 + y * PhdMatrixPtr->_11 + z * PhdMatrixPtr->_12;\n\tPhdMatrixPtr->_23 = x * PhdMatrixPtr->_20 + y * PhdMatrixPtr->_21 + z * PhdMatrixPtr->_22;\n}\n\nvoid __cdecl phd_PutPolygons(__int16 *ptrObj, int clip) {\n\tFltWinLeft = (float)PhdWinMinX;\n\tFltWinTop = (float)PhdWinMinY;\n\tFltWinRight = (float)(PhdWinMinX + PhdWinMaxX + 1);\n\tFltWinBottom = (float)(PhdWinMinY + PhdWinMaxY + 1);\n\tFltWinCenterX = (float)(PhdWinMinX + PhdWinCenterX);\n\tFltWinCenterY = (float)(PhdWinMinY + PhdWinCenterY);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t__int16 *ptrEnv = ptrObj;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tptrObj += 4; // skip x, y, z, radius\n\tptrObj = calc_object_vertices(ptrObj);\n\tif( ptrObj != NULL ) {\n\t\tptrObj = calc_vertice_light(ptrObj);\n\t\tptrObj = ins_objectGT4(ptrObj+1, *ptrObj, ST_AvgZ);\n\t\tptrObj = ins_objectGT3(ptrObj+1, *ptrObj, ST_AvgZ);\n\t\tptrObj = ins_objectG4(ptrObj+1, *ptrObj, ST_AvgZ);\n\t\tptrObj = ins_objectG3(ptrObj+1, *ptrObj, ST_AvgZ);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tphd_PutEnvmapPolygons(ptrEnv);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t}\n}\n\nvoid __cdecl S_InsertRoom(__int16 *ptrObj, BOOL isOutside) {\n\tFltWinLeft = (float)(PhdWinMinX + PhdWinLeft);\n\tFltWinTop = (float)(PhdWinMinY + PhdWinTop);\n\tFltWinRight = (float)(PhdWinMinX + PhdWinRight + 1);\n\tFltWinBottom = (float)(PhdWinMinY + PhdWinBottom + 1);\n\tFltWinCenterX = (float)(PhdWinMinX + PhdWinCenterX);\n\tFltWinCenterY = (float)(PhdWinMinY + PhdWinCenterY);\n\n\tptrObj = calc_roomvert(ptrObj, isOutside?0x00:0x10);\n\tptrObj = ins_objectGT4(ptrObj+1, *ptrObj, ST_MaxZ);\n\tptrObj = ins_objectGT3(ptrObj+1, *ptrObj, ST_MaxZ);\n\tptrObj = ins_room_sprite(ptrObj+1, *ptrObj);\n}\n\n__int16 *__cdecl calc_background_light(__int16 *ptrObj) {\n\tint vtxCount = *ptrObj++;\n\n\tif( vtxCount > 0 ) {\n\t\tptrObj += 3 * vtxCount;\n\t}\n\telse if( vtxCount < 0 ) {\n\t\tvtxCount = -vtxCount;\n\t\tptrObj += vtxCount;\n\t}\n\n\t// Skybox has normal brightness\n\tint shade = 0x0FFF;\n\n\t// NOTE: Sunset did not change the skybox brightness in the original game\n\tif( GF_SunsetEnabled )\n\t\tshade += 0x400 * SunsetTimer / SUNSET_TIMEOUT;\n\n\tfor( int i = 0; i < vtxCount; ++i )\n\t\tPhdVBuf[i].g = shade;\n\n\treturn ptrObj;\n}\n\nvoid __cdecl S_InsertBackground(__int16 *ptrObj) {\n\tFltWinLeft = (float)(PhdWinMinX + PhdWinLeft);\n\tFltWinTop = (float)(PhdWinMinY + PhdWinTop);\n\tFltWinRight = (float)(PhdWinMinX + PhdWinRight + 1);\n\tFltWinBottom = (float)(PhdWinMinY + PhdWinBottom + 1);\n\tFltWinCenterX = (float)(PhdWinMinX + PhdWinCenterX);\n\tFltWinCenterY = (float)(PhdWinMinY + PhdWinCenterY);\n\n\tptrObj += 4; // skip x, y, z, radius\n\tptrObj = calc_object_vertices(ptrObj);\n\tif( ptrObj == NULL ) {\n\t\treturn;\n\t}\n\tptrObj = calc_background_light(ptrObj);\n\n#ifdef FEATURE_VIEW_IMPROVED\n\tMidSort = 0xFFFF;\n#endif // FEATURE_VIEW_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tHWR_EnableZBuffer(false, false);\n\t}\n\tptrObj = ins_objectGT4(ptrObj+1, *ptrObj, ST_FarZ);\n\tptrObj = ins_objectGT3(ptrObj+1, *ptrObj, ST_FarZ);\n\tptrObj = ins_objectG4(ptrObj+1, *ptrObj, ST_FarZ);\n\tptrObj = ins_objectG3(ptrObj+1, *ptrObj, ST_FarZ);\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tHWR_EnableZBuffer(true, true);\n\t}\n#ifdef FEATURE_VIEW_IMPROVED\n\tMidSort = 0;\n#endif // FEATURE_VIEW_IMPROVED\n}\n\nvoid __cdecl S_InsertInvBgnd(__int16 *ptrObj) {\n\t// NOTE: Null function in the PC version.\n\t// But there is waving inventory function in the PlayStation version.\n\t// Main S_InsertInvBgnd() logic is similar to S_InsertBackground();\n}\n\n__int16 *__cdecl calc_object_vertices(__int16 *ptrObj) {\n\tdouble xv, yv, zv, persp, baseZ;\n\tint vtxCount;\n\tBYTE totalClip, clipFlags;\n\n\tbaseZ = 0.0;\n#ifndef FEATURE_VIEW_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Software || !SavedAppSettings.ZBuffer ) {\n\t\tbaseZ = (double)(MidSort << (W2V_SHIFT + 8));\n\t}\n#endif // !FEATURE_VIEW_IMPROVED\n\n\ttotalClip = 0xFF;\n\n\tptrObj++; // skip poly counter\n\tvtxCount = *(ptrObj++); // get vertex counter\n\n\tif( vtxCount < 0 ) {\n\t\tprintf(\"vtxCount=%d\", vtxCount);\n\t}\n\n\tfor( int i = 0; i < vtxCount; ++i ) {\n\t\txv = (double)(PhdMatrixPtr->_00 * ptrObj[0] +\n\t\t\t\t\t  PhdMatrixPtr->_01 * ptrObj[1] +\n\t\t\t\t\t  PhdMatrixPtr->_02 * ptrObj[2] +\n\t\t\t\t\t  PhdMatrixPtr->_03);\n\n\t\tyv = (double)(PhdMatrixPtr->_10 * ptrObj[0] +\n\t\t\t\t\t  PhdMatrixPtr->_11 * ptrObj[1] +\n\t\t\t\t\t  PhdMatrixPtr->_12 * ptrObj[2] +\n\t\t\t\t\t  PhdMatrixPtr->_13);\n\n\t\tzv = (double)(PhdMatrixPtr->_20 * ptrObj[0] +\n\t\t\t\t\t  PhdMatrixPtr->_21 * ptrObj[1] +\n\t\t\t\t\t  PhdMatrixPtr->_22 * ptrObj[2] +\n\t\t\t\t\t  PhdMatrixPtr->_23);\n\n\t\tPhdVBuf[i].xv = xv;\n\t\tPhdVBuf[i].yv = yv;\n\n\t\tif( zv < FltNearZ ) {\n\t\t\tclipFlags = 0x80;\n\t\t\tPhdVBuf[i].zv = zv;\n\t\t} else {\n\t\t\tclipFlags = 0;\n\n\t\t\tif( zv >= FltFarZ ) {\n\t\t\t\tzv = FltFarZ;\n\t\t\t\tPhdVBuf[i].zv = zv;\n\t\t\t} else {\n\t\t\t\tPhdVBuf[i].zv = zv + baseZ;\n\t\t\t}\n\n\t\t\tpersp = FltPersp / zv;\n\n\t\t\tPhdVBuf[i].xs  = persp * xv + FltWinCenterX;\n\t\t\tPhdVBuf[i].ys  = persp * yv + FltWinCenterY;\n\t\t\tPhdVBuf[i].rhw = persp * FltRhwOPersp;\n\n\t\t\tif( PhdVBuf[i].xs < FltWinLeft )\n\t\t\t\tclipFlags |= 0x01;\n\t\t\telse if( PhdVBuf[i].xs > FltWinRight )\n\t\t\t\tclipFlags |= 0x02;\n\n\t\t\tif( PhdVBuf[i].ys < FltWinTop )\n\t\t\t\tclipFlags |= 0x04;\n\t\t\telse if( PhdVBuf[i].ys > FltWinBottom )\n\t\t\t\tclipFlags |= 0x08;\n\t\t}\n\n\t\tPhdVBuf[i].clip = clipFlags;\n\t\ttotalClip &= clipFlags;\n\t\tptrObj += 3;\n\t}\n\treturn ( totalClip == 0 ) ? ptrObj : NULL;\n}\n\n__int16 *__cdecl calc_vertice_light(__int16 *ptrObj) {\n\tint i, xv, yv, zv;\n\t__int16 shade;\n\tint vtxCount = *ptrObj++;\n\n\tif( vtxCount > 0 ) {\n\t\tif( LsDivider != 0 ) {\n\t\t\txv = (PhdMatrixPtr->_00 * LsVectorView.x +\n\t\t\t\t  PhdMatrixPtr->_10 * LsVectorView.y +\n\t\t\t\t  PhdMatrixPtr->_20 * LsVectorView.z) / LsDivider;\n\t\t\tyv = (PhdMatrixPtr->_01 * LsVectorView.x +\n\t\t\t\t  PhdMatrixPtr->_11 * LsVectorView.y +\n\t\t\t\t  PhdMatrixPtr->_21 * LsVectorView.z) / LsDivider;\n\t\t\tzv = (PhdMatrixPtr->_02 * LsVectorView.x +\n\t\t\t\t  PhdMatrixPtr->_12 * LsVectorView.y +\n\t\t\t\t  PhdMatrixPtr->_22 * LsVectorView.z) / LsDivider;\n\n\t\t\tfor( i = 0; i < vtxCount; ++i ) {\n\t\t\t\tshade = LsAdder + ((ptrObj[0]*xv + ptrObj[1]*yv + ptrObj[2]*zv) >> 16);\n\t\t\t\tCLAMP(shade, 0, 0x1FFF);\n\t\t\t\tPhdVBuf[i].g = shade;\n\t\t\t\tptrObj += 3;\n\t\t\t}\n\t\t} else {\n\t\t\tshade = LsAdder;\n\t\t\tCLAMP(shade, 0, 0x1FFF);\n\t\t\tfor( i = 0; i < vtxCount; ++i ) {\n\t\t\t\tPhdVBuf[i].g = shade;\n\t\t\t}\n\t\t\tptrObj += 3*vtxCount;\n\t\t}\n\t} else {\n\t\tfor( i = 0; i < -vtxCount; ++i ) {\n\t\t\tshade = LsAdder + *ptrObj;\n\t\t\tCLAMP(shade, 0, 0x1FFF);\n\t\t\tPhdVBuf[i].g = shade;\n\t\t\t++ptrObj;\n\t\t}\n\t}\n\treturn ptrObj;\n}\n\n__int16 *__cdecl calc_roomvert(__int16 *ptrObj, BYTE farClip) {\n\tdouble xv, yv, zv, persp, baseZ, depth;\n\tint vtxCount, zv_int;\n\n\tbaseZ = 0.0;\n#ifndef FEATURE_VIEW_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Software || !SavedAppSettings.ZBuffer ) {\n\t\tbaseZ = (double)(MidSort << (W2V_SHIFT + 8));\n\t}\n#endif // !FEATURE_VIEW_IMPROVED\n\n\tvtxCount = *(ptrObj++);\n\n\tfor( int i = 0; i < vtxCount; ++i ) {\n\t\txv = (double)(PhdMatrixPtr->_00 * ptrObj[0] +\n\t\t\t\t\t  PhdMatrixPtr->_01 * ptrObj[1] +\n\t\t\t\t\t  PhdMatrixPtr->_02 * ptrObj[2] +\n\t\t\t\t\t  PhdMatrixPtr->_03);\n\n\t\tyv = (double)(PhdMatrixPtr->_10 * ptrObj[0] +\n\t\t\t\t\t  PhdMatrixPtr->_11 * ptrObj[1] +\n\t\t\t\t\t  PhdMatrixPtr->_12 * ptrObj[2] +\n\t\t\t\t\t  PhdMatrixPtr->_13);\n\n\t\tzv_int =\t (PhdMatrixPtr->_20 * ptrObj[0] +\n\t\t\t\t\t  PhdMatrixPtr->_21 * ptrObj[1] +\n\t\t\t\t\t  PhdMatrixPtr->_22 * ptrObj[2] +\n\t\t\t\t\t  PhdMatrixPtr->_23);\n\n\t\tzv = (double)zv_int;\n\t\tPhdVBuf[i].xv = xv;\n\t\tPhdVBuf[i].yv = yv;\n\n\t\tPhdVBuf[i].g = ptrObj[5];\n\t\tif( IsWaterEffect != 0 )\n\t\t\tPhdVBuf[i].g += ShadesTable[(WibbleOffset + (BYTE)RandomTable[(vtxCount - i) % WIBBLE_SIZE]) % WIBBLE_SIZE];\n\n\t\tif( zv < FltNearZ ) {\n\t\t\tPhdVBuf[i].clip = 0xFF80;\n\t\t\tPhdVBuf[i].zv = zv;\n\t\t} else {\n\t\t\tpersp = FltPersp / zv;\n\t\t\tdepth = zv_int >> W2V_SHIFT;\n\n#ifdef FEATURE_VIEW_IMPROVED\n\t\t\tif( depth >= PhdViewDistance ) {\n\t\t\t\tPhdVBuf[i].rhw = persp * FltRhwOPersp;\n\t\t\t\tPhdVBuf[i].zv = zv + baseZ;\n#else // !FEATURE_VIEW_IMPROVED\n\t\t\tif( depth >= DEPTHQ_END ) { // fog end\n\t\t\t\tPhdVBuf[i].rhw = 0.0; // NOTE: zero RHW is an invalid value, but the original game sets it.\n\t\t\t\tPhdVBuf[i].zv = FltFarZ;\n#endif // FEATURE_VIEW_IMPROVED\n\t\t\t\tPhdVBuf[i].g = 0x1FFF;\n\t\t\t\tPhdVBuf[i].clip = farClip;\n\t\t\t} else {\n#ifdef FEATURE_VIEW_IMPROVED\n\t\t\t\tPhdVBuf[i].g += CalculateFogShade(depth);\n#else // !FEATURE_VIEW_IMPROVED\n\t\t\t\tif( depth > DEPTHQ_START ) { // fog begin\n\t\t\t\t\tPhdVBuf[i].g += depth - DEPTHQ_START;\n\t\t\t\t}\n#endif // FEATURE_VIEW_IMPROVED\n\t\t\t\tPhdVBuf[i].rhw = persp * FltRhwOPersp;\n\t\t\t\tPhdVBuf[i].clip = 0;\n\t\t\t\tPhdVBuf[i].zv = zv + baseZ;\n\t\t\t}\n\n\t\t\tPhdVBuf[i].xs = persp * xv + FltWinCenterX;\n\t\t\tPhdVBuf[i].ys = persp * yv + FltWinCenterY;\n\n\t\t\tif( IsWibbleEffect && ptrObj[4] >= 0 ) {\n\t\t\t\tPhdVBuf[i].xs += WibbleTable[(WibbleOffset + (BYTE)PhdVBuf[i].ys) % WIBBLE_SIZE];\n\t\t\t\tPhdVBuf[i].ys += WibbleTable[(WibbleOffset + (BYTE)PhdVBuf[i].xs) % WIBBLE_SIZE];\n\t\t\t}\n\n\t\t\tif( PhdVBuf[i].xs < FltWinLeft )\n\t\t\t\tPhdVBuf[i].clip |= 0x01;\n\t\t\telse if( PhdVBuf[i].xs > FltWinRight )\n\t\t\t\tPhdVBuf[i].clip |= 0x02;\n\n\t\t\tif( PhdVBuf[i].ys < FltWinTop )\n\t\t\t\tPhdVBuf[i].clip |= 0x04;\n\t\t\telse if( PhdVBuf[i].ys > FltWinBottom )\n\t\t\t\tPhdVBuf[i].clip |= 0x08;\n\n\t\t\tPhdVBuf[i].clip |= ~(BYTE)(PhdVBuf[i].zv / 0x155555.p0) << 8;\n\t\t}\n\t\tCLAMP(PhdVBuf[i].g, 0, 0x1FFF);\n\t\tptrObj += 6;\n\t}\n\treturn ptrObj;\n}\n\nvoid __cdecl phd_RotateLight(__int16 pitch, __int16 yaw) {\n\tint xcos, ysin, wcos, wsin;\n\tint ls_x, ls_y, ls_z;\n\n\tPhdLsYaw = yaw;\n\tPhdLsPitch = pitch;\n\n\txcos = phd_cos(pitch);\n\tysin = phd_sin(pitch);\n\n\twcos = phd_cos(yaw);\n\twsin = phd_sin(yaw);\n\n\tls_x = TRIGMULT2(xcos, wsin);\n\tls_y = -ysin;\n\tls_z = TRIGMULT2(xcos, wcos);\n\n\tLsVectorView.x = (MatrixW2V._00 * ls_x + MatrixW2V._01 * ls_y + MatrixW2V._02 * ls_z) >> W2V_SHIFT;\n\tLsVectorView.y = (MatrixW2V._10 * ls_x + MatrixW2V._11 * ls_y + MatrixW2V._12 * ls_z) >> W2V_SHIFT;\n\tLsVectorView.z = (MatrixW2V._20 * ls_x + MatrixW2V._21 * ls_y + MatrixW2V._22 * ls_z) >> W2V_SHIFT;\n}\n\nvoid __cdecl phd_InitPolyList() {\n\tSurfaceCount = 0;\n\tSort3dPtr = SortBuffer;\n\tInfo3dPtr = Info3dBuffer;\n\tif( SavedAppSettings.RenderMode == RM_Hardware )\n\t\tHWR_VertexPtr = HWR_VertexBuffer;\n}\n\nvoid __cdecl phd_SortPolyList() {\n\tif( SurfaceCount ) {\n\t\tfor( DWORD i=0; i<SurfaceCount; ++i ) {\n#ifdef FEATURE_VIEW_IMPROVED\n\t\t\tSortBuffer[i]._1 <<= 16;\n#endif // FEATURE_VIEW_IMPROVED\n\t\t\tSortBuffer[i]._1 += i;\n\t\t}\n\t\tdo_quickysorty(0, SurfaceCount-1);\n\t}\n}\n\nvoid __cdecl do_quickysorty(int left, int right) {\n#ifdef FEATURE_VIEW_IMPROVED\n\tUINT64 swapBuf;\n\tUINT64 compare = SortBuffer[(left + right) / 2]._1;\n#else // FEATURE_VIEW_IMPROVED\n\tDWORD swapBuf;\n\tDWORD compare = SortBuffer[(left + right) / 2]._1;\n#endif // FEATURE_VIEW_IMPROVED\n\tint i = left;\n\tint j = right;\n\n\tdo {\n\t\twhile( (i < right) && (SortBuffer[i]._1 > compare) ) ++i;\n\t\twhile( (left <  j) && (compare > SortBuffer[j]._1) ) --j;\n\t\tif( i > j ) break;\n\n\t\tSWAP(SortBuffer[i]._0, SortBuffer[j]._0, swapBuf);\n\t\tSWAP(SortBuffer[i]._1, SortBuffer[j]._1, swapBuf);\n\t} while( ++i <= --j );\n\n\tif( left < j )\n\t\tdo_quickysorty(left, j);\n\tif( i < right )\n\t\tdo_quickysorty(i, right);\n}\n\nvoid __cdecl phd_PrintPolyList(BYTE *surfacePtr) {\n\t__int16 polyType, *bufPtr;\n\tPrintSurfacePtr = surfacePtr;\n\n\tfor( DWORD i=0; i<SurfaceCount; ++i ) {\n\t\tbufPtr = (__int16 *)SortBuffer[i]._0;\n\t\tpolyType = *(bufPtr++); // poly has type as routine index in first word\n\t\tPolyDrawRoutines[polyType](bufPtr); // send poly data as parameter to routine\n\t}\n}\n\nvoid __cdecl AlterFOV(__int16 fov) {\n\tfov /= 2; // half fov angle\n\n#ifdef FEATURE_VIEW_IMPROVED\n\tint fovWidth = PhdWinHeight*320/(PsxFovEnabled ? 200 : 240);\n\tFltViewAspect = 1.0; // must always be 1.0 for unstretched view\n\tPhdPersp = (fovWidth / 2) * phd_cos(fov) / phd_sin(fov);\n#else // !FEATURE_VIEW_IMPROVED\n\tPhdPersp = (PhdWinWidth / 2) * phd_cos(fov) / phd_sin(fov);\n#endif // FEATURE_VIEW_IMPROVED\n\n\tFltPersp = (float)PhdPersp;\n\tFltRhwOPersp = RhwFactor / FltPersp;\n\tFltPerspONearZ = FltPersp / FltNearZ;\n\n#ifndef FEATURE_VIEW_IMPROVED // if feature is not defined!!!\n\tdouble windowAspect = 4.0 / 3.0;\n\tif( !SavedAppSettings.FullScreen && SavedAppSettings.AspectMode == AM_16_9 ) {\n\t\twindowAspect = 16.0 / 9.0;\n\t}\n\tFltViewAspect = windowAspect / ((double)PhdWinWidth / (double)PhdWinHeight);\n#endif // !FEATURE_VIEW_IMPROVED\n}\n\nvoid __cdecl phd_SetNearZ(int nearZ) {\n\tPhdNearZ = nearZ;\n\tFltNearZ = (float)nearZ;\n\tFltRhwONearZ = RhwFactor / FltNearZ;\n\tFltPerspONearZ = FltPersp / FltNearZ;\n\n\tdouble resZ = 0.99 * FltFarZ * FltNearZ / (FltFarZ - FltNearZ);\n\n\tFltResZ = resZ;\n\tFltResZORhw = resZ / RhwFactor;\n\tFltResZBuf = 0.005 + resZ / FltNearZ;\n}\n\nvoid __cdecl phd_SetFarZ(int farZ) {\n\tPhdFarZ = farZ;\n\tFltFarZ = (float)farZ;\n\n\tdouble resZ = 0.99 * FltFarZ * FltNearZ / (FltFarZ - FltNearZ);\n\n\tFltResZ = resZ;\n\tFltResZORhw = resZ / RhwFactor;\n\tFltResZBuf = 0.005 + resZ / FltNearZ;\n\n}\n\nvoid __cdecl phd_InitWindow(__int16 x, __int16 y, int width, int height, int nearZ, int farZ, __int16 viewAngle, int screenWidth, int screenHeight) {\n\tPhdWinMinX = x;\n\tPhdWinMinY = y;\n\tPhdWinMaxX = width - 1;\n\tPhdWinMaxY = height - 1;\n\n\tPhdWinWidth = width;\n\tPhdWinHeight = height;\n\n\tPhdWinCenterX = width / 2;\n\tPhdWinCenterY = height / 2;\n\tFltWinCenterX = (float)PhdWinCenterX;\n\tFltWinCenterY = (float)PhdWinCenterY;\n\n\tPhdWinLeft = 0;\n\tPhdWinTop = 0;\n\tPhdWinRight = PhdWinMaxX;\n\tPhdWinBottom = PhdWinMaxY;\n\n\tPhdWinRect.left = PhdWinMinX;\n\tPhdWinRect.bottom = PhdWinMinY + PhdWinHeight;\n\tPhdWinRect.top = PhdWinMinY;\n\tPhdWinRect.right = PhdWinMinX + PhdWinWidth;\n\n\tPhdScreenWidth = screenWidth;\n\tPhdScreenHeight = screenHeight;\n\n#ifdef FEATURE_VIEW_IMPROVED\n\tdouble baseDistance = (double)farZ;\n\tfarZ\t\t\t\t= (int)(baseDistance * ViewDistanceFactor);\n\tFogBeginDepth\t\t= (int)(baseDistance * FogBeginFactor);\n\tFogEndDepth\t\t\t= (int)(baseDistance * FogEndFactor);\n\tWaterFogBeginDepth\t= (int)(baseDistance * WaterFogBeginFactor);\n\tWaterFogEndDepth\t= (int)(baseDistance * WaterFogEndFactor);\n#endif // FEATURE_VIEW_IMPROVED\n\n\tPhdNearZ = nearZ << W2V_SHIFT;\n\tPhdFarZ = farZ << W2V_SHIFT;\n\tPhdViewDistance = farZ;\n\n\tAlterFOV(PHD_DEGREE * viewAngle); // convert degrees to PHD angle\n\tphd_SetNearZ(PhdNearZ);\n\tphd_SetFarZ(PhdFarZ);\n\n\tPhdMatrixPtr = MatrixStack; // reset matrix stack pointer\n\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\tPerspectiveDistance = SavedAppSettings.PerspectiveCorrect ? SW_DETAIL_HIGH : SW_DETAIL_MEDIUM;\n\n\t\tins_objectGT3\t= InsertObjectGT3;\n\t\tins_objectGT4\t= InsertObjectGT4;\n\t\tins_objectG3\t= InsertObjectG3;\n\t\tins_objectG4\t= InsertObjectG4;\n\t\tins_flat_rect\t= InsertFlatRect;\n\t\tins_line\t\t= InsertLine;\n\n\t\tins_sprite\t\t= InsertSprite;\n\t\tins_poly_trans8\t= InsertTrans8;\n\t\tins_trans_quad\t= InsertTransQuad;\n\t}\n\telse if( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tif( SavedAppSettings.ZBuffer ) {\n\t\t\tins_objectGT3\t= InsertObjectGT3_ZBuffered;\n\t\t\tins_objectGT4\t= InsertObjectGT4_ZBuffered;\n\t\t\tins_objectG3\t= InsertObjectG3_ZBuffered;\n\t\t\tins_objectG4\t= InsertObjectG4_ZBuffered;\n\t\t\tins_flat_rect\t= InsertFlatRect_ZBuffered;\n\t\t\tins_line\t\t= InsertLine_ZBuffered;\n\t\t} else {\n\t\t\tins_objectGT3\t= InsertObjectGT3_Sorted;\n\t\t\tins_objectGT4\t= InsertObjectGT4_Sorted;\n\t\t\tins_objectG3\t= InsertObjectG3_Sorted;\n\t\t\tins_objectG4\t= InsertObjectG4_Sorted;\n\t\t\tins_flat_rect\t= InsertFlatRect_Sorted;\n\t\t\tins_line\t\t= InsertLine_Sorted;\n\t\t}\n\t\tins_sprite\t\t= InsertSprite_Sorted;\n\t\tins_poly_trans8\t= InsertTrans8_Sorted;\n\t\tins_trans_quad\t= InsertTransQuad_Sorted;\n\t}\n}\n\nvoid __cdecl phd_PopMatrix() {\n\t--PhdMatrixPtr;\n}\n\nvoid __cdecl phd_PushMatrix() {\n\tPhdMatrixPtr[1] = PhdMatrixPtr[0]; // copy the last matrix\n\t++PhdMatrixPtr;\n}\n\nvoid __cdecl phd_PushUnitMatrix() {\n\t++PhdMatrixPtr;\n\tmemset(PhdMatrixPtr, 0, sizeof(PHD_MATRIX));\n\tPhdMatrixPtr->_00 = W2V_SCALE;\n\tPhdMatrixPtr->_11 = W2V_SCALE;\n\tPhdMatrixPtr->_22 = W2V_SCALE;\n}\n\n/*\n * Inject function\n */\nvoid Inject_3Dgen() {\n\tINJECT(0x00401000, phd_GenerateW2V);\n\tINJECT(0x004011D0, phd_LookAt);\n\tINJECT(0x00401250, phd_GetVectorAngles);\n\tINJECT(0x004012D0, phd_RotX);\n\tINJECT(0x00401380, phd_RotY);\n\tINJECT(0x00401430, phd_RotZ);\n\tINJECT(0x004014E0, phd_RotYXZ);\n\tINJECT(0x004016C0, phd_RotYXZpack);\n\tINJECT(0x004018B0, phd_TranslateRel);\n\tINJECT(0x00401960, phd_TranslateAbs);\n\tINJECT(0x004019E0, phd_PutPolygons);\n\tINJECT(0x00401AE0, S_InsertRoom);\n\tINJECT(0x00401BD0, calc_background_light);\n\tINJECT(0x00401C10, S_InsertBackground);\n//\tINJECT(----------, S_InsertInvBgnd); // NOTE: this is null in the original code\n\tINJECT(0x00401D50, calc_object_vertices);\n\tINJECT(0x00401F30, calc_vertice_light);\n\tINJECT(0x004020A0, calc_roomvert);\n\tINJECT(0x00402320, phd_RotateLight);\n\tINJECT(0x004023F0, phd_InitPolyList);\n\tINJECT(0x00402420, phd_SortPolyList);\n\tINJECT(0x00402460, do_quickysorty);\n\tINJECT(0x00402530, phd_PrintPolyList);\n\tINJECT(0x00402570, AlterFOV);\n\tINJECT(0x00402680, phd_SetNearZ);\n\tINJECT(0x004026D0, phd_SetFarZ);\n\tINJECT(0x004026F0, phd_InitWindow);\n//\tINJECT(----------, phd_PopMatrix); // NOTE: this is inline or macro in the original code\n\tINJECT(0x00457510, phd_PushMatrix);\n\tINJECT(0x0045752E, phd_PushUnitMatrix);\n}\n"
  },
  {
    "path": "3dsystem/3d_gen.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef _3DGEN_H_INCLUDED\n#define _3DGEN_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#ifdef FEATURE_VIDEOFX_IMPROVED\nvoid ClearMeshReflectState();\nvoid SetMeshReflectState(int objID, int meshIdx);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\nvoid phd_GenerateW2V(PHD_3DPOS *viewPos); // 0x00401000\nvoid __cdecl phd_LookAt(int xsrc, int ysrc, int zsrc, int xtar, int ytar, int ztar, __int16 roll); // 0x004011D0\nvoid __cdecl phd_GetVectorAngles(int x, int y, int z, VECTOR_ANGLES *angles); // 0x00401250\nvoid __cdecl phd_RotX(__int16 angle); // 0x004012D0\nvoid __cdecl phd_RotY(__int16 angle); // 0x00401380\nvoid __cdecl phd_RotZ(__int16 angle); // 0x00401430\nvoid __cdecl phd_RotYXZ(__int16 ry, __int16 rx, __int16 rz); // 0x004014E0\nvoid __cdecl phd_RotYXZpack(DWORD rpack); // 0x004016C0\nBOOL __cdecl phd_TranslateRel(int x, int y, int z); // 0x004018B0\nvoid __cdecl phd_TranslateAbs(int x, int y, int z); // 0x00401960\nvoid __cdecl phd_PutPolygons(__int16 *ptrObj, int clip); // 0x004019E0\nvoid __cdecl S_InsertRoom(__int16 *ptrObj, BOOL isOutside); // 0x00401AE0\n__int16 *__cdecl calc_background_light(__int16 *ptrObj); // 0x00401BD0\nvoid __cdecl S_InsertBackground(__int16 *ptrObj); // 0x00401C10\nvoid __cdecl S_InsertInvBgnd(__int16 *ptrObj); // ----------\n__int16 *__cdecl calc_object_vertices(__int16 *ptrObj); // 0x00401D50\n__int16 *__cdecl calc_vertice_light(__int16 *ptrObj); // 0x00401F30\n__int16 *__cdecl calc_roomvert(__int16 *ptrObj, BYTE farClip); // 0x004020A0\nvoid __cdecl phd_RotateLight(__int16 pitch, __int16 yaw); // 0x00402320\nvoid __cdecl phd_InitPolyList(); // 0x004023F0\nvoid __cdecl phd_SortPolyList(); // 0x00402420\nvoid __cdecl do_quickysorty(int left, int right); // 0x00402460\nvoid __cdecl phd_PrintPolyList(BYTE *surfacePtr); // 0x00402530\nvoid __cdecl AlterFOV(__int16 fov); // 0x00402570\nvoid __cdecl phd_SetNearZ(int nearZ); // 0x00402680\nvoid __cdecl phd_SetFarZ(int farZ); // 0x004026D0\nvoid __cdecl phd_InitWindow(__int16 x, __int16 y, int width, int height, int nearZ, int farZ, __int16 viewAngle, int screenWidth, int screenHeight); // 0x004026F0\nvoid __cdecl phd_PopMatrix(); // ----------\nvoid __cdecl phd_PushMatrix(); // 0x00457510\nvoid __cdecl phd_PushUnitMatrix(); // 0x0045752E\n\n#endif // _3DGEN_H_INCLUDED\n"
  },
  {
    "path": "3dsystem/3d_out.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"3dsystem/3d_out.h\"\n#include \"global/vars.h\"\n\n#pragma pack(push, 1)\n\ntypedef struct {\n\tUINT16 x;\n\tUINT16 y;\n} XGEN_X;\n\ntypedef struct {\n\tUINT16 x;\n\tUINT16 y;\n\tUINT16 g;\n} XGEN_XG;\n\ntypedef struct {\n\tUINT16 x;\n\tUINT16 y;\n\tUINT16 g;\n\tUINT16 u;\n\tUINT16 v;\n} XGEN_XGUV;\n\ntypedef struct {\n\tUINT16 x;\n\tUINT16 y;\n\tUINT16 g;\n\tfloat rhw;\n\tfloat u;\n\tfloat v;\n} XGEN_XGUVP;\n\ntypedef struct {\n\tint x0;\n\tint x1;\n} XBUF_X;\n\ntypedef struct {\n\tint x0;\n\tint g0;\n\tint x1;\n\tint g1;\n} XBUF_XG;\n\ntypedef struct {\n\tint x0;\n\tint g0;\n\tint u0;\n\tint v0;\n\tint x1;\n\tint g1;\n\tint u1;\n\tint v1;\n} XBUF_XGUV;\n\ntypedef struct {\n\tint x0;\n\tint g0;\n\tfloat u0;\n\tfloat v0;\n\tfloat rhw0;\n\tint x1;\n\tint g1;\n\tfloat u1;\n\tfloat v1;\n\tfloat rhw1;\n} XBUF_XGUVP;\n\n#pragma pack(pop)\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\nstatic int SwrPitch = 0;\nstatic int SwrHeight = 0;\nstatic void *XBuffer = NULL;\n\nint GetPitchSWR() {\n    return SwrPitch;\n}\n\nvoid PrepareSWR(int pitch, int height) {\n\tif( pitch != 0 ) {\n\t\tSwrPitch = pitch;\n\t}\n    if( height != 0 && (XBuffer == NULL || SwrHeight != height) ) {\n\t\tSwrHeight = height;\n\t\tif( XBuffer != NULL ) free(XBuffer);\n\t\tXBuffer = malloc(sizeof(XBUF_XGUVP) * height);\n\t}\n}\n#else // FEATURE_NOLEGACY_OPTIONS\n#define SwrPitch PhdScreenWidth // NOTE: this is the original game bug!\nstatic int XBuffer[1200 * sizeof(XBUF_XGUVP) / sizeof(int)]; // maximum safe resolution is 1200 pixels\n#endif // FEATURE_NOLEGACY_OPTIONS\n\nvoid __cdecl draw_poly_line(__int16 *bufPtr) {\n\tint i, j;\n\tint x0, y0, x1, y1;\n\tint xSize, ySize, xAdd, yAdd, colAdd, rowAdd;\n\tint swapBuf, part, partTotal;\n\tBYTE colorIdx;\n\tBYTE *drawPtr;\n\n\tx0 = *(bufPtr++);\n\ty0 = *(bufPtr++);\n\tx1 = *(bufPtr++);\n\ty1 = *(bufPtr++);\n\tcolorIdx = (BYTE)*bufPtr;\n\n\tif( x1 < x0 ) {\n\t\tSWAP(x0, x1, swapBuf);\n\t\tSWAP(y0, y1, swapBuf);\n\t}\n\n\tif( x1 < 0 || x0 > PhdWinMaxX )\n\t\treturn;\n\n\tif( x0 < 0 ) {\n\t\ty0 -= x0 * (y1 - y0) / (x1 - x0);\n\t\tx0 = 0;\n\t}\n\n\tif( x1 > PhdWinMaxX ) {\n\t\ty1 = y0 + (y1 - y0) * (PhdWinMaxX - x0) / (x1 - x0);\n\t\tx1 = PhdWinMaxX;\n\t}\n\n\tif( y1 < y0 ) {\n\t\tSWAP(x0, x1, swapBuf);\n\t\tSWAP(y0, y1, swapBuf);\n\t}\n\n\tif( y1 < 0 || y0 > PhdWinMaxY )\n\t\treturn;\n\n\tif( y0 < 0 ) {\n\t\tx0 -= y0 * (x1 - x0) / (y1 - y0);\n\t\ty0 = 0;\n\t}\n\n\tif( y1 > PhdWinMaxY ) {\n\t\tx1 = x0 + (x1 - x0) * (PhdWinMaxY - y0) / (y1 - y0);\n\t\ty1 = PhdWinMaxY;\n\t}\n\n\tdrawPtr = PrintSurfacePtr + (SwrPitch * y0 + x0);\n\n\txSize = x1 - x0;\n\tySize = y1 - y0;\n\n\tif( (xSize|ySize) == 0 ) {\n\t\t*drawPtr = colorIdx;\n\t\treturn;\n\t}\n\n\tif( xSize < 0 ) {\n\t\txSize = -xSize;\n\t\txAdd = -1;\n\t} else {\n\t\txAdd = 1;\n\t}\n\n\tif( ySize < 0 ) {\n\t\tySize = -ySize;\n\t\tyAdd = -SwrPitch;\n\t} else {\n\t\tyAdd = SwrPitch;\n\t}\n\n\tif( xSize >= ySize ) {\n\t\ti = xSize + 1;\n\t\tj = ySize + 1;\n\t\tcolAdd = xAdd;\n\t\trowAdd = yAdd;\n\t} else {\n\t\ti = ySize + 1;\n\t\tj = xSize + 1;\n\t\tcolAdd = yAdd;\n\t\trowAdd = xAdd;\n\t}\n\n\tpartTotal = 0;\n\tpart = PHD_ONE * j / i;\n\n\twhile( i-- ) {\n\t\tpartTotal += part;\n\t\t*drawPtr = colorIdx;\n\t\tdrawPtr += colAdd;\n\t\tif( partTotal >= PHD_ONE ) {\n\t\t\tdrawPtr += rowAdd;\n\t\t\tpartTotal -= PHD_ONE;\n\t\t}\n\t}\n}\n\nvoid __cdecl draw_poly_flat(__int16 *bufPtr) {\n\tif( xgen_x(bufPtr + 1) )\n\t\tflatA(XGen_y0, XGen_y1, *bufPtr);\n}\n\nvoid __cdecl draw_poly_trans(__int16 *bufPtr) {\n\tif( xgen_x(bufPtr + 1) )\n\t\ttransA(XGen_y0, XGen_y1, *bufPtr);\n}\n\nvoid __cdecl draw_poly_gouraud(__int16 *bufPtr) {\n\tif( xgen_xg(bufPtr + 1) )\n\t\tgourA(XGen_y0, XGen_y1, *bufPtr);\n}\n\nvoid __cdecl draw_poly_gtmap(__int16 *bufPtr) {\n\tif( xgen_xguv(bufPtr + 1) )\n\t\tgtmapA(XGen_y0, XGen_y1, TexturePageBuffer8[*bufPtr]);\n}\n\nvoid __cdecl draw_poly_wgtmap(__int16 *bufPtr) {\n\tif( xgen_xguv(bufPtr + 1) )\n\t\twgtmapA(XGen_y0, XGen_y1, TexturePageBuffer8[*bufPtr]);\n}\n\nBOOL __cdecl xgen_x(__int16 *bufPtr) {\n\tint ptCount;\n\tXGEN_X *pt1, *pt2;\n\tint yMin, yMax;\n\tint x1, y1, x2, y2;\n\tint xSize, ySize;\n\tint x, xAdd;\n\tXBUF_X *xPtr;\n\n\tptCount = *bufPtr++;\n\tpt2 = (XGEN_X *)bufPtr;\n\tpt1 = pt2 + (ptCount - 1);\n\n\tyMin = yMax = pt1->y;\n\n\twhile( ptCount-- ) {\n\t\tx1 = pt1->x;\n\t\ty1 = pt1->y;\n\t\tx2 = pt2->x;\n\t\ty2 = pt2->y;\n\t\tpt1 = pt2++;\n\n\t\tif( y1 < y2 ) {\n\t\t\tCLAMPG(yMin, y1);\n\t\t\txSize = x2 - x1;\n\t\t\tySize = y2 - y1;\n\n\t\t\txPtr = (XBUF_X *)XBuffer + y1;\n\t\t\txAdd = PHD_ONE * xSize / ySize;\n\t\t\tx = x1 * PHD_ONE + (PHD_ONE - 1);\n\n\t\t\tdo {\n\t\t\t\t(xPtr++)->x1 = (x += xAdd);\n\t\t\t} while( --ySize );\n\t\t}\n\t\telse if( y2 < y1 ) {\n\t\t\tCLAMPL(yMax, y1);\n\t\t\txSize = x1 - x2;\n\t\t\tySize = y1 - y2;\n\n\t\t\txPtr = (XBUF_X *)XBuffer + y2;\n\t\t\txAdd = PHD_ONE * xSize / ySize;\n\t\t\tx = x2 * PHD_ONE + 1;\n\n\t\t\tdo {\n\t\t\t\t(xPtr++)->x0 = (x += xAdd);\n\t\t\t} while( --ySize );\n\t\t}\n\t}\n\n\tif( yMin == yMax )\n\t\treturn FALSE;\n\n\tXGen_y0 = yMin;\n\tXGen_y1 = yMax;\n\treturn TRUE;\n}\n\nBOOL __cdecl xgen_xg(__int16 *bufPtr) {\n\tint ptCount;\n\tXGEN_XG *pt1, *pt2;\n\tint yMin, yMax;\n\tint x1, y1, g1, x2, y2, g2;\n\tint xSize, ySize, gSize;\n\tint x, g, xAdd, gAdd;\n\tXBUF_XG *xgPtr;\n\n\tptCount = *bufPtr++;\n\tpt2 = (XGEN_XG *)bufPtr;\n\tpt1 = pt2 + (ptCount - 1);\n\n\tyMin = yMax = pt1->y;\n\n\twhile( ptCount-- ) {\n\t\tx1 = pt1->x;\n\t\ty1 = pt1->y;\n\t\tg1 = pt1->g;\n\t\tx2 = pt2->x;\n\t\ty2 = pt2->y;\n\t\tg2 = pt2->g;\n\t\tpt1 = pt2++;\n\n\t\tif( y1 < y2 ) {\n\t\t\tCLAMPG(yMin, y1);\n\t\t\txSize = x2 - x1;\n\t\t\tySize = y2 - y1;\n\t\t\tgSize = g2 - g1;\n\n\t\t\txgPtr = (XBUF_XG *)XBuffer + y1;\n\t\t\txAdd = PHD_ONE * xSize / ySize;\n\t\t\tgAdd = PHD_HALF * gSize / ySize;\n\t\t\tx = x1 * PHD_ONE + (PHD_ONE - 1);\n\t\t\tg = g1 * PHD_HALF;\n\n\t\t\tdo {\n\t\t\t\txgPtr->x1 = (x += xAdd);\n\t\t\t\txgPtr->g1 = (g += gAdd);\n\t\t\t\txgPtr++;\n\t\t\t} while( --ySize );\n\t\t}\n\t\telse if( y2 < y1 ) {\n\t\t\tCLAMPL(yMax, y1);\n\t\t\txSize = x1 - x2;\n\t\t\tySize = y1 - y2;\n\t\t\tgSize = g1 - g2;\n\n\t\t\txgPtr = (XBUF_XG *)XBuffer + y2;\n\t\t\txAdd = PHD_ONE * xSize / ySize;\n\t\t\tgAdd = PHD_HALF * gSize / ySize;\n\t\t\tx = x2 * PHD_ONE + 1;\n\t\t\tg = g2 * PHD_HALF;\n\n\t\t\tdo {\n\t\t\t\txgPtr->x0 = (x += xAdd);\n\t\t\t\txgPtr->g0 = (g += gAdd);\n\t\t\t\txgPtr++;\n\t\t\t} while( --ySize );\n\t\t}\n\t}\n\n\tif( yMin == yMax )\n\t\treturn FALSE;\n\n\tXGen_y0 = yMin;\n\tXGen_y1 = yMax;\n\treturn TRUE;\n}\n\nBOOL __cdecl xgen_xguv(__int16 *bufPtr) {\n\tint ptCount;\n\tXGEN_XGUV *pt1, *pt2;\n\tint yMin, yMax;\n\tint x1, y1, g1, u1, v1, x2, y2, g2, u2, v2;\n\tint xSize, ySize, gSize, uSize, vSize;\n\tint x, g, u, v, xAdd, gAdd, uAdd, vAdd;\n\tXBUF_XGUV *xguvPtr;\n\n\tptCount = *bufPtr++;\n\tpt2 = (XGEN_XGUV *)bufPtr;\n\tpt1 = pt2 + (ptCount - 1);\n\n\tyMin = yMax = pt1->y;\n\n\twhile( ptCount-- ) {\n\t\tx1 = pt1->x;\n\t\ty1 = pt1->y;\n\t\tg1 = pt1->g;\n\t\tu1 = pt1->u;\n\t\tv1 = pt1->v;\n\t\tx2 = pt2->x;\n\t\ty2 = pt2->y;\n\t\tg2 = pt2->g;\n\t\tu2 = pt2->u;\n\t\tv2 = pt2->v;\n\t\tpt1 = pt2++;\n\n\t\tif( y1 < y2 ) {\n\t\t\tCLAMPG(yMin, y1);\n\t\t\txSize = x2 - x1;\n\t\t\tySize = y2 - y1;\n\t\t\tgSize = g2 - g1;\n\t\t\tuSize = u2 - u1;\n\t\t\tvSize = v2 - v1;\n\n\t\t\txguvPtr = (XBUF_XGUV *)XBuffer + y1;\n\t\t\txAdd = PHD_ONE * xSize / ySize;\n\t\t\tgAdd = PHD_HALF * gSize / ySize;\n\t\t\tuAdd = PHD_HALF * uSize / ySize;\n\t\t\tvAdd = PHD_HALF * vSize / ySize;\n\t\t\tx = x1 * PHD_ONE + (PHD_ONE - 1);\n\t\t\tg = g1 * PHD_HALF;\n\t\t\tu = u1 * PHD_HALF;\n\t\t\tv = v1 * PHD_HALF;\n\n\t\t\tdo {\n\t\t\t\txguvPtr->x1 = (x += xAdd);\n\t\t\t\txguvPtr->g1 = (g += gAdd);\n\t\t\t\txguvPtr->u1 = (u += uAdd);\n\t\t\t\txguvPtr->v1 = (v += vAdd);\n\t\t\t\txguvPtr++;\n\t\t\t} while( --ySize );\n\t\t}\n\t\telse if( y2 < y1 ) {\n\t\t\tCLAMPL(yMax, y1);\n\t\t\txSize = x1 - x2;\n\t\t\tySize = y1 - y2;\n\t\t\tgSize = g1 - g2;\n\t\t\tuSize = u1 - u2;\n\t\t\tvSize = v1 - v2;\n\n\t\t\txguvPtr = (XBUF_XGUV *)XBuffer + y2;\n\t\t\txAdd = PHD_ONE * xSize / ySize;\n\t\t\tgAdd = PHD_HALF * gSize / ySize;\n\t\t\tuAdd = PHD_HALF * uSize / ySize;\n\t\t\tvAdd = PHD_HALF * vSize / ySize;\n\t\t\tx = x2 * PHD_ONE + 1;\n\t\t\tg = g2 * PHD_HALF;\n\t\t\tu = u2 * PHD_HALF;\n\t\t\tv = v2 * PHD_HALF;\n\n\t\t\tdo {\n\t\t\t\txguvPtr->x0 = (x += xAdd);\n\t\t\t\txguvPtr->g0 = (g += gAdd);\n\t\t\t\txguvPtr->u0 = (u += uAdd);\n\t\t\t\txguvPtr->v0 = (v += vAdd);\n\t\t\t\txguvPtr++;\n\t\t\t} while( --ySize );\n\t\t}\n\t}\n\n\tif( yMin == yMax )\n\t\treturn FALSE;\n\n\tXGen_y0 = yMin;\n\tXGen_y1 = yMax;\n\treturn TRUE;\n}\n\nBOOL __cdecl xgen_xguvpersp_fp(__int16 *bufPtr) {\n\tint ptCount;\n\tXGEN_XGUVP *pt1, *pt2;\n\tint yMin, yMax;\n\tint x1, y1, g1, x2, y2, g2;\n\tfloat u1, v1, rhw1, u2, v2, rhw2;\n\tint xSize, ySize, gSize;\n\tfloat uSize, vSize, rhwSize;\n\tint x, g, xAdd, gAdd;\n\tfloat u, v, rhw, uAdd, vAdd, rhwAdd;\n\tXBUF_XGUVP *xguvPtr;\n\n\tptCount = *bufPtr++;\n\tpt2 = (XGEN_XGUVP *)bufPtr;\n\tpt1 = pt2 + (ptCount - 1);\n\n\tyMin = yMax = pt1->y;\n\n\twhile( ptCount-- ) {\n\t\tx1 = pt1->x;\n\t\ty1 = pt1->y;\n\t\tg1 = pt1->g;\n\t\tu1 = pt1->u;\n\t\tv1 = pt1->v;\n\t\trhw1 = pt1->rhw;\n\t\tx2 = pt2->x;\n\t\ty2 = pt2->y;\n\t\tg2 = pt2->g;\n\t\tu2 = pt2->u;\n\t\tv2 = pt2->v;\n\t\trhw2 = pt2->rhw;\n\t\tpt1 = pt2++;\n\n\t\tif( y1 < y2 ) {\n\t\t\tCLAMPG(yMin, y1);\n\t\t\txSize = x2 - x1;\n\t\t\tySize = y2 - y1;\n\t\t\tgSize = g2 - g1;\n\t\t\tuSize = u2 - u1;\n\t\t\tvSize = v2 - v1;\n\t\t\trhwSize = rhw2 - rhw1;\n\n\t\t\txguvPtr = (XBUF_XGUVP *)XBuffer + y1;\n\t\t\txAdd = PHD_ONE * xSize / ySize;\n\t\t\tgAdd = PHD_HALF * gSize / ySize;\n\t\t\tuAdd = uSize / (float)ySize;\n\t\t\tvAdd = vSize / (float)ySize;\n\t\t\trhwAdd = rhwSize / (float)ySize;\n\t\t\tx = x1 * PHD_ONE + (PHD_ONE - 1);\n\t\t\tg = g1 * PHD_HALF;\n\t\t\tu = u1;\n\t\t\tv = v1;\n\t\t\trhw = rhw1;\n\n\t\t\tdo {\n \t\t\t\txguvPtr->x1 = (x += xAdd);\n\t\t\t\txguvPtr->g1 = (g += gAdd);\n\t\t\t\txguvPtr->u1 = (u += uAdd);\n\t\t\t\txguvPtr->v1 = (v += vAdd);\n\t\t\t\txguvPtr->rhw1 = (rhw += rhwAdd);\n\t\t\t\txguvPtr++;\n\t\t\t} while( --ySize );\n\t\t}\n\t\telse if( y2 < y1 ) {\n\t\t\tCLAMPL(yMax, y1);\n\t\t\txSize = x1 - x2;\n\t\t\tySize = y1 - y2;\n\t\t\tgSize = g1 - g2;\n\t\t\tuSize = u1 - u2;\n\t\t\tvSize = v1 - v2;\n\t\t\trhwSize = rhw1 - rhw2;\n\n\t\t\txguvPtr = (XBUF_XGUVP *)XBuffer + y2;\n\t\t\txAdd = PHD_ONE * xSize / ySize;\n\t\t\tgAdd = PHD_HALF * gSize / ySize;\n\t\t\tuAdd = (float)uSize / (float)ySize;\n\t\t\tvAdd = (float)vSize / (float)ySize;\n\t\t\trhwAdd = (float)rhwSize / (float)ySize;\n\t\t\tx = x2 * PHD_ONE + 1;\n\t\t\tg = g2 * PHD_HALF;\n\t\t\tu = (float)u2;\n\t\t\tv = (float)v2;\n\t\t\trhw = (float)rhw2;\n\n\t\t\tdo {\n\t\t\t\txguvPtr->x0 = (x += xAdd);\n\t\t\t\txguvPtr->g0 = (g += gAdd);\n\t\t\t\txguvPtr->u0 = (u += uAdd);\n\t\t\t\txguvPtr->v0 = (v += vAdd);\n\t\t\t\txguvPtr->rhw0 = (rhw += rhwAdd);\n\t\t\t\txguvPtr++;\n\t\t\t} while( --ySize );\n\t\t}\n\t}\n\n\tif( yMin == yMax )\n\t\treturn FALSE;\n\n\tXGen_y0 = yMin;\n\tXGen_y1 = yMax;\n\treturn TRUE;\n}\n\nvoid __cdecl gtmap_persp32_fp(int y0, int y1, BYTE *texPage) {\n\tint batchSize, batchCounter;\n\tint x, xSize, ySize;\n\tint g, u0, u1, v0, v1, gAdd, u0Add, v0Add;\n\tdouble u, v, rhw, uAdd, vAdd, rhwAdd;\n\tBYTE *drawPtr, *linePtr;\n\tXBUF_XGUVP *xbuf;\n\tBYTE colorIdx;\n\n\tySize = y1 - y0;\n\tif( ySize <= 0 )\n\t\treturn;\n\n\txbuf = (XBUF_XGUVP *)XBuffer + y0;\n\tdrawPtr = PrintSurfacePtr + y0 * SwrPitch;\n\n\tfor( ; ySize > 0; --ySize, ++xbuf, drawPtr += SwrPitch ) {\n\t\tx = xbuf->x0 / PHD_ONE;\n\t\txSize = (xbuf->x1 / PHD_ONE) - x;\n\t\tif( xSize <= 0 )\n\t\t\tcontinue;\n\n\t\tg = xbuf->g0;\n\t\tu = xbuf->u0;\n\t\tv = xbuf->v0;\n\t\trhw = xbuf->rhw0;\n\n\t\tgAdd = (xbuf->g1 - g) / xSize;\n\n\t\tu0 = (int)(PHD_HALF * u / rhw);\n\t\tv0 = (int)(PHD_HALF * v / rhw);\n\n\t\tlinePtr = drawPtr + x;\n\t\tbatchSize = 32;\n\n\t\tif( xSize >= batchSize ) {\n\t\t\tuAdd = (xbuf->u1 - u) / (double)xSize * double(batchSize);\n\t\t\tvAdd = (xbuf->v1 - v) / (double)xSize * double(batchSize);\n\t\t\trhwAdd = (xbuf->rhw1 - rhw) / (double)xSize * double(batchSize);\n\n\t\t\tdo {\n\t\t\t\tu += uAdd;\n\t\t\t\tv += vAdd;\n\t\t\t\trhw += rhwAdd;\n\n\t\t\t\tu1 = (int)(PHD_HALF * u / rhw);\n\t\t\t\tv1 = (int)(PHD_HALF * v / rhw);\n\n\t\t\t\tu0Add = (u1 - u0) / batchSize;\n\t\t\t\tv0Add = (v1 - v0) / batchSize;\n\n\t\t\t\tif( (ABS(u0Add) + ABS(v0Add)) < (PHD_ONE / 2) ) {\n\t\t\t\t\tbatchCounter = batchSize / 2;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t\t\t\tcolorIdx = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t\t\t\t*(linePtr++) = colorIdx;\n\t\t\t\t\t\t*(linePtr++) = colorIdx;\n\t\t\t\t\t\tg += gAdd * 2;\n\t\t\t\t\t\tu0 += u0Add * 2;\n\t\t\t\t\t\tv0 += v0Add * 2;\n\t\t\t\t\t} while( --batchCounter );\n\t\t\t\t} else {\n\t\t\t\t\tbatchCounter = batchSize;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t\t\t\t*(linePtr++) = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t\t\t\tg += gAdd;\n\t\t\t\t\t\tu0 += u0Add;\n\t\t\t\t\t\tv0 += v0Add;\n\t\t\t\t\t} while( --batchCounter );\n\t\t\t\t}\n\n\t\t\t\tu0 = u1;\n\t\t\t\tv0 = v1;\n\t\t\t\txSize -= batchSize;\n\t\t\t} while( xSize >= batchSize );\n\t\t}\n\n\t\tif( xSize > 1 ) {\n\t\t\tu1 = (int)(PHD_HALF * xbuf->u1 / xbuf->rhw1);\n\t\t\tv1 = (int)(PHD_HALF * xbuf->v1 / xbuf->rhw1);\n\t\t\tu0Add = (u1 - u0) / xSize;\n\t\t\tv0Add = (v1 - v0) / xSize;\n\n\t\t\tbatchSize = xSize & ~1;\n\t\t\txSize -= batchSize;\n\n\t\t\tif( (ABS(u0Add) + ABS(v0Add)) < (PHD_ONE / 2) ) {\n\t\t\t\tbatchCounter = batchSize / 2;\n\t\t\t\tdo {\n\t\t\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t\t\tcolorIdx = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t\t\t*(linePtr++) = colorIdx;\n\t\t\t\t\t*(linePtr++) = colorIdx;\n\t\t\t\t\tg += gAdd * 2;\n\t\t\t\t\tu0 += u0Add * 2;\n\t\t\t\t\tv0 += v0Add * 2;\n\t\t\t\t} while( --batchCounter );\n\t\t\t} else {\n\t\t\t\tbatchCounter = batchSize;\n\t\t\t\tdo {\n\t\t\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t\t\t*(linePtr++) = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t\t\tg += gAdd;\n\t\t\t\t\tu0 += u0Add;\n\t\t\t\t\tv0 += v0Add;\n\t\t\t\t} while( --batchCounter );\n\t\t\t}\n\t\t}\n\n\t\tif( xSize != 0 ) { // xSize == 1\n\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t*linePtr = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t}\n\t}\n}\n\nvoid __cdecl wgtmap_persp32_fp(int y0, int y1, BYTE *texPage) {\n\tint batchSize, batchCounter;\n\tint x, xSize, ySize;\n\tint g, u0, u1, v0, v1, gAdd, u0Add, v0Add;\n\tdouble u, v, rhw, uAdd, vAdd, rhwAdd;\n\tBYTE *drawPtr, *linePtr;\n\tXBUF_XGUVP *xbuf;\n\tBYTE colorIdx;\n\n\tySize = y1 - y0;\n\tif( ySize <= 0 )\n\t\treturn;\n\n\txbuf = (XBUF_XGUVP *)XBuffer + y0;\n\tdrawPtr = PrintSurfacePtr + y0 * SwrPitch;\n\n\tfor( ; ySize > 0; --ySize, ++xbuf, drawPtr += SwrPitch ) {\n\t\tx = xbuf->x0 / PHD_ONE;\n\t\txSize = (xbuf->x1 / PHD_ONE) - x;\n\t\tif( xSize <= 0 )\n\t\t\tcontinue;\n\n\t\tg = xbuf->g0;\n\t\tu = xbuf->u0;\n\t\tv = xbuf->v0;\n\t\trhw = xbuf->rhw0;\n\n\t\tgAdd = (xbuf->g1 - g) / xSize;\n\n\t\tu0 = (int)(PHD_HALF * u / rhw);\n\t\tv0 = (int)(PHD_HALF * v / rhw);\n\n\t\tlinePtr = drawPtr + x;\n\t\tbatchSize = 32;\n\n\t\tif( xSize >= batchSize ) {\n\t\t\tuAdd = (xbuf->u1 - u) / (double)xSize * double(batchSize);\n\t\t\tvAdd = (xbuf->v1 - v) / (double)xSize * double(batchSize);\n\t\t\trhwAdd = (xbuf->rhw1 - rhw) / (double)xSize * double(batchSize);\n\n\t\t\tdo {\n\t\t\t\tu += uAdd;\n\t\t\t\tv += vAdd;\n\t\t\t\trhw += rhwAdd;\n\n\t\t\t\tu1 = (int)(PHD_HALF * u / rhw);\n\t\t\t\tv1 = (int)(PHD_HALF * v / rhw);\n\n\t\t\t\tu0Add = (u1 - u0) / batchSize;\n\t\t\t\tv0Add = (v1 - v0) / batchSize;\n\n\t\t\t\tif( (ABS(u0Add) + ABS(v0Add)) < (PHD_ONE / 2) ) {\n\t\t\t\t\tbatchCounter = batchSize / 2;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t\t\t\tif( colorIdx != 0 ) {\n\t\t\t\t\t\t\tcolorIdx = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t\t\t\t\tlinePtr[0] = colorIdx;\n\t\t\t\t\t\t\tlinePtr[1] = colorIdx;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlinePtr += 2;\n\t\t\t\t\t\tg += gAdd * 2;\n\t\t\t\t\t\tu0 += u0Add * 2;\n\t\t\t\t\t\tv0 += v0Add * 2;\n\t\t\t\t\t} while( --batchCounter );\n\t\t\t\t} else {\n\t\t\t\t\tbatchCounter = batchSize;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t\t\t\tif( colorIdx != 0 ) {\n\t\t\t\t\t\t\t*linePtr = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlinePtr++;\n\t\t\t\t\t\tg += gAdd;\n\t\t\t\t\t\tu0 += u0Add;\n\t\t\t\t\t\tv0 += v0Add;\n\t\t\t\t\t} while( --batchCounter );\n\t\t\t\t}\n\n\t\t\t\tu0 = u1;\n\t\t\t\tv0 = v1;\n\t\t\t\txSize -= batchSize;\n\t\t\t} while( xSize >= batchSize );\n\t\t}\n\n\t\tif( xSize > 1 ) {\n\t\t\tu1 = (int)(PHD_HALF * xbuf->u1 / xbuf->rhw1);\n\t\t\tv1 = (int)(PHD_HALF * xbuf->v1 / xbuf->rhw1);\n\t\t\tu0Add = (u1 - u0) / xSize;\n\t\t\tv0Add = (v1 - v0) / xSize;\n\n\t\t\tbatchSize = xSize & ~1;\n\t\t\txSize -= batchSize;\n\n\t\t\tif( (ABS(u0Add) + ABS(v0Add)) < (PHD_ONE / 2) ) {\n\t\t\t\tbatchCounter = batchSize / 2;\n\t\t\t\tdo {\n\t\t\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t\t\tif( colorIdx != 0 ) {\n\t\t\t\t\t\tcolorIdx = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t\t\t\tlinePtr[0] = colorIdx;\n\t\t\t\t\t\tlinePtr[1] = colorIdx;\n\t\t\t\t\t}\n\t\t\t\t\tlinePtr += 2;\n\t\t\t\t\tg += gAdd * 2;\n\t\t\t\t\tu0 += u0Add * 2;\n\t\t\t\t\tv0 += v0Add * 2;\n\t\t\t\t} while( --batchCounter );\n\t\t\t} else {\n\t\t\t\tbatchCounter = batchSize;\n\t\t\t\tdo {\n\t\t\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\t\t\tif( colorIdx != 0 ) {\n\t\t\t\t\t\t*linePtr = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t\t\t}\n\t\t\t\t\tlinePtr++;\n\t\t\t\t\tg += gAdd;\n\t\t\t\t\tu0 += u0Add;\n\t\t\t\t\tv0 += v0Add;\n\t\t\t\t} while( --batchCounter );\n\t\t\t}\n\t\t}\n\n\t\tif( xSize != 0 ) { // xSize == 1\n\t\t\tcolorIdx = texPage[BYTE2(v0)*256 + BYTE2(u0)];\n\t\t\tif( colorIdx != 0 ) {\n\t\t\t\t*linePtr = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid __cdecl draw_poly_gtmap_persp(__int16 *bufPtr) {\n\tif( xgen_xguvpersp_fp(bufPtr + 1) )\n\t\tgtmap_persp32_fp(XGen_y0, XGen_y1, TexturePageBuffer8[*bufPtr]);\n}\n\nvoid __cdecl draw_poly_wgtmap_persp(__int16 *bufPtr) {\n\tif( xgen_xguvpersp_fp(bufPtr + 1) )\n\t\twgtmap_persp32_fp(XGen_y0, XGen_y1, TexturePageBuffer8[*bufPtr]);\n}\n\nvoid __fastcall flatA(int y0, int y1, BYTE colorIdx) {\n\tint x, xSize, ySize;\n\tBYTE *drawPtr;\n\tXBUF_X *xbuf;\n\n\tySize = y1 - y0;\n\tif( ySize <= 0 )\n\t\treturn;\n\n\txbuf = (XBUF_X *)XBuffer + y0;\n\tdrawPtr = PrintSurfacePtr + y0 * SwrPitch;\n\n\tfor( ; ySize > 0; --ySize, ++xbuf, drawPtr += SwrPitch ) {\n\t\tx = xbuf->x0 / PHD_ONE;\n\t\txSize = (xbuf->x1 / PHD_ONE) - x;\n\t\tif( xSize > 0 ) {\n\t\t\tmemset(drawPtr + x, colorIdx, xSize);\n\t\t}\n\t}\n}\n\nvoid __fastcall transA(int y0, int y1, BYTE depthQ) {\n\tint x, xSize, ySize;\n\tBYTE *drawPtr, *linePtr;\n\tXBUF_X *xbuf;\n\tDEPTHQ_ENTRY *qt;\n\n\tySize = y1 - y0;\n\tif( ySize <= 0 || depthQ >= 32 ) // NOTE: depthQ check was ( > 32) in the original code\n\t\treturn;\n\n\txbuf = (XBUF_X *)XBuffer + y0;\n\tdrawPtr = PrintSurfacePtr + y0 * SwrPitch;\n\tqt = DepthQTable + depthQ;\n\n\tfor( ; ySize > 0; --ySize, ++xbuf, drawPtr += SwrPitch ) {\n\t\tx = xbuf->x0 / PHD_ONE;\n\t\txSize = (xbuf->x1 / PHD_ONE) - x;\n\t\tif( xSize <= 0 )\n\t\t\tcontinue;\n\n\t\tlinePtr = drawPtr + x;\n\t\tdo {\n\t\t\t*linePtr = qt->index[*linePtr];\n\t\t\t++linePtr;\n\t\t} while( --xSize );\n\t}\n}\n\nvoid __fastcall gourA(int y0, int y1, BYTE colorIdx) {\n\tint x, xSize, ySize;\n\tint g, gAdd;\n\tBYTE *drawPtr, *linePtr;\n\tXBUF_XG *xbuf;\n\tGOURAUD_ENTRY *gt;\n\n\tySize = y1 - y0;\n\tif( ySize <= 0 )\n\t\treturn;\n\n\txbuf = (XBUF_XG *)XBuffer + y0;\n\tdrawPtr = PrintSurfacePtr + y0 * SwrPitch;\n\tgt = GouraudTable + colorIdx;\n\n\tfor( ; ySize > 0; --ySize, ++xbuf, drawPtr += SwrPitch ) {\n\t\tx = xbuf->x0 / PHD_ONE;\n\t\txSize = (xbuf->x1 / PHD_ONE) - x;\n\t\tif( xSize <= 0 )\n\t\t\tcontinue;\n\n\t\tg = xbuf->g0;\n\t\tgAdd = (xbuf->g1 - g) / xSize;\n\n\t\tlinePtr = drawPtr + x;\n\t\tdo {\n\t\t\t*(linePtr++) = gt->index[BYTE2(g)];\n\t\t\tg += gAdd;\n\t\t} while( --xSize );\n\t}\n}\n\nvoid __fastcall gtmapA(int y0, int y1, BYTE *texPage) {\n\tint x, xSize, ySize;\n\tint g, u, v, gAdd, uAdd, vAdd;\n\tBYTE *drawPtr, *linePtr;\n\tXBUF_XGUV *xbuf;\n\tBYTE colorIdx;\n\n\tySize = y1 - y0;\n\tif( ySize <= 0 )\n\t\treturn;\n\n\txbuf = (XBUF_XGUV *)XBuffer + y0;\n\tdrawPtr = PrintSurfacePtr + y0 * SwrPitch;\n\n\tfor( ; ySize > 0; --ySize, ++xbuf, drawPtr += SwrPitch ) {\n\t\tx = xbuf->x0 / PHD_ONE;\n\t\txSize = (xbuf->x1 / PHD_ONE) - x;\n\t\tif( xSize <= 0 )\n\t\t\tcontinue;\n\n\t\tg = xbuf->g0;\n\t\tu = xbuf->u0;\n\t\tv = xbuf->v0;\n\t\tgAdd = (xbuf->g1 - g) / xSize;\n\t\tuAdd = (xbuf->u1 - u) / xSize;\n\t\tvAdd = (xbuf->v1 - v) / xSize;\n\n\t\tlinePtr = drawPtr + x;\n\t\tdo {\n\t\t\tcolorIdx = texPage[BYTE2(v)*256 + BYTE2(u)];\n\t\t\t*(linePtr++) = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\tg += gAdd;\n\t\t\tu += uAdd;\n\t\t\tv += vAdd;\n\t\t} while( --xSize );\n\t}\n}\n\nvoid __fastcall wgtmapA(int y0, int y1, BYTE *texPage) {\n\tint x, xSize, ySize;\n\tint g, u, v, gAdd, uAdd, vAdd;\n\tBYTE *drawPtr, *linePtr;\n\tXBUF_XGUV *xbuf;\n\tBYTE colorIdx;\n\n\tySize = y1 - y0;\n\tif( ySize <= 0 )\n\t\treturn;\n\n\txbuf = (XBUF_XGUV *)XBuffer + y0;\n\tdrawPtr = PrintSurfacePtr + y0 * SwrPitch;\n\n\tfor( ; ySize > 0; --ySize, ++xbuf, drawPtr += SwrPitch ) {\n\t\tx = xbuf->x0 / PHD_ONE;\n\t\txSize = (xbuf->x1 / PHD_ONE) - x;\n\t\tif( xSize <= 0 )\n\t\t\tcontinue;\n\n\t\tg = xbuf->g0;\n\t\tu = xbuf->u0;\n\t\tv = xbuf->v0;\n\t\tgAdd = (xbuf->g1 - g) / xSize;\n\t\tuAdd = (xbuf->u1 - u) / xSize;\n\t\tvAdd = (xbuf->v1 - v) / xSize;\n\n\t\tlinePtr = drawPtr + x;\n\t\tdo {\n\t\t\tcolorIdx = texPage[BYTE2(v)*256 + BYTE2(u)];\n\t\t\tif( colorIdx != 0 ) {\n\t\t\t\t*linePtr = DepthQTable[BYTE2(g)].index[colorIdx];\n\t\t\t}\n\t\t\t++linePtr;\n\t\t\tg += gAdd;\n\t\t\tu += uAdd;\n\t\t\tv += vAdd;\n\t\t} while( --xSize );\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_3Dout() {\n\tINJECT(0x00402960, draw_poly_line);\n\tINJECT(0x00402B00, draw_poly_flat);\n\tINJECT(0x00402B40, draw_poly_trans);\n\tINJECT(0x00402B80, draw_poly_gouraud);\n\tINJECT(0x00402BC0, draw_poly_gtmap);\n\tINJECT(0x00402C00, draw_poly_wgtmap);\n\tINJECT(0x00402C40, xgen_x);\n\tINJECT(0x00402D20, xgen_xg);\n\tINJECT(0x00402E70, xgen_xguv);\n\tINJECT(0x00403090, xgen_xguvpersp_fp);\n\tINJECT(0x00403320, gtmap_persp32_fp);\n\tINJECT(0x004042F0, wgtmap_persp32_fp);\n\tINJECT(0x004057C0, draw_poly_gtmap_persp);\n\tINJECT(0x00405800, draw_poly_wgtmap_persp);\n//\tNOTE: asm functions below use Watcom register calling convention so they incompatible\n//\tINJECT(0x00457564, flatA);\n//\tINJECT(0x004575C5, transA);\n//\tINJECT(0x004576FF, gourA);\n//\tINJECT(0x0045785F, gtmapA);\n//\tINJECT(0x00457B5C, wgtmapA);\n}\n"
  },
  {
    "path": "3dsystem/3d_out.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef _3DOUT_H_INCLUDED\n#define _3DOUT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl draw_poly_line(__int16 *bufPtr); // 0x00402960\nvoid __cdecl draw_poly_flat(__int16 *bufPtr); // 0x00402B00\nvoid __cdecl draw_poly_trans(__int16 *bufPtr); // 0x00402B40\nvoid __cdecl draw_poly_gouraud(__int16 *bufPtr); // 0x00402B80\nvoid __cdecl draw_poly_gtmap(__int16 *bufPtr); // 0x00402BC0\nvoid __cdecl draw_poly_wgtmap(__int16 *bufPtr); // 0x00402C00\nBOOL __cdecl xgen_x(__int16 *bufPtr); // 0x00402C40\nBOOL __cdecl xgen_xg(__int16 *bufPtr); // 0x00402D20\nBOOL __cdecl xgen_xguv(__int16 *bufPtr); // 0x00402E70\nBOOL __cdecl xgen_xguvpersp_fp(__int16 *bufPtr); // 0x00403090\nvoid __cdecl gtmap_persp32_fp(int y0, int y1, BYTE *texPage); // 0x00403320\nvoid __cdecl wgtmap_persp32_fp(int y0, int y1, BYTE *texPage); // 0x004042F0\nvoid __cdecl draw_poly_gtmap_persp(__int16 *bufPtr); // 0x004057C0\nvoid __cdecl draw_poly_wgtmap_persp(__int16 *bufPtr); // 0x00405800\nvoid __fastcall flatA(int y0, int y1, BYTE colorIdx); // 0x00457564\nvoid __fastcall transA(int y0, int y1, BYTE depthQ); // 0x004575C5\nvoid __fastcall gourA(int y0, int y1, BYTE colorIdx); // 0x004576FF\nvoid __fastcall gtmapA(int y0, int y1, BYTE *texPage); // 0x0045785F\nvoid __fastcall wgtmapA(int y0, int y1, BYTE *texPage); // 0x00457B5C\n\n#endif // _3DOUT_H_INCLUDED\n"
  },
  {
    "path": "3dsystem/3dinsert.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"3dsystem/3dinsert.h\"\n#include \"specific/hwr.h\"\n#include \"global/vars.h\"\n\n#if defined(FEATURE_HUD_IMPROVED) || (DIRECT3D_VERSION >= 0x900)\n#include \"modding/texture_utils.h\"\n#endif // defined(FEATURE_HUD_IMPROVED) || (DIRECT3D_VERSION >= 0x900)\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n#include \"specific/texture.h\"\n#include \"modding/mod_utils.h\"\n\nextern DWORD ShadowMode;\nextern DWORD AlphaBlendMode;\n\nbool CustomWaterColorEnabled = true;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\nstatic VERTEX_INFO VBuffer[40]; // NOTE: original size was 20\nstatic D3DTLVERTEX VBufferD3D[32];\nstatic D3DCOLOR GlobalTint = 0; // NOTE: not presented in the original code\n\n#ifdef FEATURE_VIEW_IMPROVED\nbool RoomSortEnabled = false;\n#define MAKE_ZSORT(z) (RoomSortEnabled && (SavedAppSettings.RenderMode == RM_Software || !SavedAppSettings.ZBuffer) ? (((UINT64)MidSort)<<32)+(DWORD)(z) : (DWORD)(z))\n#else // FEATURE_VIEW_IMPROVED\n#define MAKE_ZSORT(z) ((DWORD)(z))\n#endif // FEATURE_VIEW_IMPROVED\n\nstatic D3DCOLOR shadeColor(DWORD red, DWORD green, DWORD blue, DWORD alpha, DWORD shade, bool isTextured) {\n\tCLAMPG(shade, 0x1FFF);\n\n\tif( GlobalTint ) {\n\t\tred = RGBA_GETRED(GlobalTint);\n\t\tgreen = RGBA_GETGREEN(GlobalTint);\n\t\tblue = RGBA_GETBLUE(GlobalTint);\n\t\talpha = RGBA_GETALPHA(GlobalTint);\n\t}\n\n#if defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.LightingMode == 1 ) CLAMPL(shade, 0x800);\n\tif( SavedAppSettings.LightingMode && isTextured ) shade = 0x1000 + shade/2;\n\tif( !SavedAppSettings.LightingMode && !isTextured ) CLAMPL(shade, 0x1000);\n#else // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t// NOTE: The original game bugfix. We need to limit brightness of untextured faces for DirectX 5\n\t// because brightness of textured faces is limited by D3DTBLEND_MODULATEALPHA or D3DTBLEND_MODULATE\n\tif( !isTextured ) CLAMPL(shade, 0x1000);\n#endif // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\n\tif( shade != 0x1000 ) {\n\t\tDWORD brightness = 0x2000 - shade;\n\t\tred   = red   * brightness >> 12;\n\t\tgreen = green * brightness >> 12;\n\t\tblue  = blue  * brightness >> 12;\n\t}\n\n\tCLAMPG(red,   0xFF);\n\tCLAMPG(green, 0xFF);\n\tCLAMPG(blue,  0xFF);\n\tCLAMPG(alpha, 0xFF);\n\n\tif( IsShadeEffect ) {\n#if defined(FEATURE_VIDEOFX_IMPROVED) && defined(FEATURE_MOD_CONFIG)\n\t\tD3DCOLOR water = GetModWaterColor();\n\t\tif( CustomWaterColorEnabled && water ) {\n\t\t\tred   = red   * RGB_GETRED(water) / 256;\n\t\t\tgreen = green * RGB_GETGREEN(water) / 256;\n\t\t\tblue  = blue  * RGB_GETBLUE(water) / 256;\n\t\t} else {\n\t\t\tred   = red   * 128 / 256;\n\t\t\tgreen = green * 224 / 256;\n\t\t}\n#else // defined(FEATURE_VIDEOFX_IMPROVED) && defined(FEATURE_MOD_CONFIG)\n\t\tred   = red   * 128 / 256;\n\t\tgreen = green * 224 / 256;\n#endif // defined(FEATURE_VIDEOFX_IMPROVED) && defined(FEATURE_MOD_CONFIG)\n\t}\n\treturn RGBA_MAKE(red, green, blue, alpha);\n}\n\nstatic double CalculatePolyZ(SORTTYPE sortType, double z0, double z1, double z2, double z3 = -1.0) {\n\tdouble zv = 0.0;\n\n\tswitch( sortType ) {\n\t\tcase ST_AvgZ :\n\t\t\tzv = ( z3 > 0.0 ) ? (z0+z1+z2+z3)/4.0 : (z0+z1+z2)/3.0;\n\t\t\tbreak;\n\n\t\tcase ST_MaxZ :\n\t\t\tzv = z0;\n\t\t\tCLAMPL(zv, z1);\n\t\t\tCLAMPL(zv, z2);\n\t\t\tif( z3 > 0.0 ) CLAMPL(zv, z3);\n\t\t\tbreak;\n\n\t\tcase ST_FarZ :\n\t\tdefault :\n\t\t\tzv = 4000000000.0; // the original game value was 1000000000.0\n\t\t\tbreak;\n\t}\n\treturn zv;\n}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nstatic POLYTYPE GetPolyType(UINT16 drawtype) {\n\tswitch( drawtype ) {\n\t\tcase DRAW_Opaque:\n\t\t\treturn POLY_HWR_GTmap;\n\t\tcase DRAW_Semitrans:\n\t\t\treturn AlphaBlendMode ? POLY_HWR_WGTmapHalf : POLY_HWR_WGTmap;\n\t\tcase DRAW_ColorKey:\n\t\t\treturn POLY_HWR_WGTmap;\n\t}\n\treturn POLY_HWR_WGTmap;\n}\n\nbool InsertObjectEM(__int16 *ptrObj, int vtxCount, D3DCOLOR tint, PHD_UV *em_uv) {\n\tPHD_VBUF *vtx[4];\n\tPHD_TEXTURE texture;\n\tPHD_UV *uv = texture.uv;\n\n\tif( ptrObj == NULL || em_uv == NULL || vtxCount < 3 || vtxCount > 4 ) {\n\t\treturn false;\n\t}\n\n\ttexture.drawtype = DRAW_ColorKey;\n\ttexture.tpage = (UINT16)~0;\n\tfor( int i = 0; i < vtxCount; ++ i ) {\n\t\tvtx[i] = &PhdVBuf[ptrObj[i]];\n\t\ttexture.uv[i] = em_uv[ptrObj[i]];\n\t}\n\n\tGlobalTint = tint;\n\tif( vtxCount == 4 ) {\n\t\tInsertGT4_Sorted(vtx[0], vtx[1], vtx[2], vtx[3], &texture, ST_AvgZ);\n\t} else {\n\t\tInsertGT3_Sorted(vtx[0], vtx[1], vtx[2], &texture, &uv[0], &uv[1], &uv[2], ST_AvgZ);\n\t}\n\tGlobalTint = 0;\n\treturn true;\n}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n// NOTE: this function is not presented in the original game\nvoid __cdecl InsertGourQuad(int x0, int y0, int x1, int y1, int z, D3DCOLOR color0, D3DCOLOR color1, D3DCOLOR color2, D3DCOLOR color3) {\n\tdouble rhw, sz;\n\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_HWR_trans;\n\t*(Info3dPtr++) = 4; //  vertex count\n\t*(D3DTLVERTEX **)Info3dPtr = HWR_VertexPtr;\n\tInfo3dPtr += sizeof(D3DTLVERTEX *)/sizeof(__int16);\n\n\trhw = RhwFactor / (double)z;\n\tsz = FltResZBuf - rhw * FltResZORhw;\n\n\tHWR_VertexPtr[0].sx = (float)x1;\n\tHWR_VertexPtr[0].sy = (float)y0;\n\tHWR_VertexPtr[0].color = color1;\n\n\tHWR_VertexPtr[1].sx = (float)x1;\n\tHWR_VertexPtr[1].sy = (float)y1;\n\tHWR_VertexPtr[1].color = color2;\n\n\tHWR_VertexPtr[2].sx = (float)x0;\n\tHWR_VertexPtr[2].sy = (float)y1;\n\tHWR_VertexPtr[2].color = color3;\n\n\tHWR_VertexPtr[3].sx = (float)x0;\n\tHWR_VertexPtr[3].sy = (float)y0;\n\tHWR_VertexPtr[3].color = color0;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tHWR_VertexPtr[i].sz = sz;\n\t\tHWR_VertexPtr[i].rhw = rhw;\n\t}\n\n\tHWR_VertexPtr += 4;\n\t++SurfaceCount;\n}\n\nBOOL __cdecl visible_zclip(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2) {\n\treturn ( (vtx0->yv * vtx2->zv - vtx0->zv * vtx2->yv) * vtx1->xv +\n\t\t\t (vtx0->zv * vtx2->xv - vtx0->xv * vtx2->zv) * vtx1->yv +\n\t\t\t (vtx0->xv * vtx2->yv - vtx0->yv * vtx2->xv) * vtx1->zv < 0.0 );\n}\n\nint __cdecl ZedClipper(int vtxCount, POINT_INFO *pts, VERTEX_INFO *vtx) {\n\tint i, j, diff0, diff1;\n\tdouble clip;\n\tPOINT_INFO *pts0, *pts1;\n\n\tif( vtxCount == 0 )\n\t\treturn 0;\n\n\tj = 0;\n\tpts0 = pts;\n\tpts1 = &pts[vtxCount-1];\n\n\tfor( i = 0; i < vtxCount; ++i ) {\n\t\tdiff0 = (int)(FltNearZ - pts0->zv);\n\t\tdiff1 = (int)(FltNearZ - pts1->zv);\n\t\tif( (diff0|diff1) < 0 ) {\n\t\t\tif( (diff0^diff1) < 0 ) {\n\t\t\t\tclip = (FltNearZ - pts0->zv) / (pts1->zv - pts0->zv);\n\t\t\t\tvtx[j].x = ((pts1->xv - pts0->xv) * clip + pts0->xv) * FltPerspONearZ + FltWinCenterX;\n\t\t\t\tvtx[j].y = ((pts1->yv - pts0->yv) * clip + pts0->yv) * FltPerspONearZ + FltWinCenterY;\n\t\t\t\tvtx[j].rhw = FltRhwONearZ;\n\t\t\t\tvtx[j].u = ((pts1->u - pts0->u) * clip + pts0->u) * FltRhwONearZ;\n\t\t\t\tvtx[j].v = ((pts1->v - pts0->v) * clip + pts0->v) * FltRhwONearZ;\n\t\t\t\tvtx[j].g = ((pts1->g - pts0->g) * clip + pts0->g);\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tif( diff0 < 0 ) {\n\t\t\t\tvtx[j].x = pts0->xs;\n\t\t\t\tvtx[j].y = pts0->ys;\n\t\t\t\tvtx[j].rhw = pts0->rhw;\n\t\t\t\tvtx[j].u = pts0->u * pts0->rhw;\n\t\t\t\tvtx[j].v = pts0->v * pts0->rhw;\n\t\t\t\tvtx[j].g = pts0->g;\n\t\t\t\t++j;\n\t\t\t}\n\t\t}\n\t\tpts1 = pts0++;\n\t}\n\n\treturn ( j < 3 ) ? 0 : j;\n}\n\nstatic inline void clipGUV(VERTEX_INFO *buf, VERTEX_INFO *vtx1, VERTEX_INFO *vtx2, float clip) {\n\tbuf->rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\tbuf->u   = vtx2->u   + (vtx1->u   - vtx2->u)   * clip;\n\tbuf->v   = vtx2->v   + (vtx1->v   - vtx2->v)   * clip;\n\tbuf->g   = vtx2->g   + (vtx1->g   - vtx2->g)   * clip;\n}\n\nint __cdecl XYGUVClipper(int vtxCount, VERTEX_INFO *vtx) {\n\tVERTEX_INFO vtx_buf[8];\n\tVERTEX_INFO *vtx1, *vtx2;\n\tfloat clip;\n\tint i, j;\n\n\tif( vtxCount < 3 )\n\t\treturn 0;\n\n\t// horizontal clip\n\tvtx2 = &vtx[vtxCount - 1];\n\tj = 0;\n\tfor( i = 0; i < vtxCount; ++i ) {\n\t\tvtx1 = vtx2;\n\t\tvtx2 = &vtx[i];\n\n\t\tif( vtx1->x < FltWinLeft ) {\n\t\t\tif( vtx2->x < FltWinLeft ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinLeft - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinLeft;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tclipGUV(&vtx_buf[j++], vtx1, vtx2, clip);\n\t\t}\n\t\telse if( vtx1->x > FltWinRight) {\n\t\t\tif( vtx2->x > FltWinRight ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinRight - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinRight;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tclipGUV(&vtx_buf[j++], vtx1, vtx2, clip);\n\t\t}\n\n\t\tif( vtx2->x < FltWinLeft ) {\n\t\t\tclip = (FltWinLeft - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinLeft;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tclipGUV(&vtx_buf[j++], vtx1, vtx2, clip);\n\t\t}\n\t\telse if( vtx2->x > FltWinRight ) {\n\t\t\tclip = (FltWinRight - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinRight;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tclipGUV(&vtx_buf[j++], vtx1, vtx2, clip);\n\t\t} else {\n\t\t\tvtx_buf[j++] = *vtx2;\n\t\t}\n\t}\n\tvtxCount = j;\n\n\tif( vtxCount < 3 )\n\t\treturn 0;\n\n\t// vertical clip\n\tvtx2 = &vtx_buf[vtxCount-1];\n\tj = 0;\n\tfor( i = 0; i < vtxCount; ++i ) {\n\t\tvtx1 = vtx2;\n\t\tvtx2 = &vtx_buf[i];\n\n\t\tif( vtx1->y < FltWinTop ) {\n\t\t\tif( vtx2->y < FltWinTop ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinTop - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinTop;\n\t\t\tclipGUV(&vtx[j++], vtx1, vtx2, clip);\n\t\t}\n\t\telse if( vtx1->y > FltWinBottom ) {\n\t\t\tif( vtx2->y > FltWinBottom ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinBottom - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinBottom;\n\t\t\tclipGUV(&vtx[j++], vtx1, vtx2, clip);\n\t\t}\n\n\t\tif( vtx2->y < FltWinTop ) {\n\t\t\tclip = (FltWinTop - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinTop;\n\t\t\tclipGUV(&vtx[j++], vtx1, vtx2, clip);\n\t\t}\n\t\telse if( vtx2->y > FltWinBottom ) {\n\t\t\tclip = (FltWinBottom - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinBottom;\n\t\t\tclipGUV(&vtx[j++], vtx1, vtx2, clip);\n\t\t} else {\n\t\t\tvtx[j++] = *vtx2;\n\t\t}\n\t}\n\treturn ( j < 3 ) ? 0 : j;\n}\n\n__int16 *__cdecl InsertObjectGT4(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tPHD_VBUF *vtx0, *vtx1, *vtx2, *vtx3;\n\tint i, j, nPoints;\n\tfloat zv;\n\t__int16 textureIdx;\n\tPHD_TEXTURE *texture;\n\tPHD_UV *uv;\n\tPOINT_INFO points[4];\n\n\tfor( i = 0; i < number; ++i ) {\n\t\tvtx0 = &PhdVBuf[*ptrObj++];\n\t\tvtx1 = &PhdVBuf[*ptrObj++];\n\t\tvtx2 = &PhdVBuf[*ptrObj++];\n\t\tvtx3 = &PhdVBuf[*ptrObj++];\n\t\ttextureIdx = *ptrObj++;\n\t\ttexture = &PhdTextureInfo[textureIdx];\n\t\tuv = texture->uv;\n\t\tnPoints = 4;\n\n\t\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip | vtx3->clip);\n\t\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip & vtx3->clip);\n\n\t\tif( clipAND != 0 )\n\t\t\tcontinue;\n\n\t\tif( clipOR >= 0 ) {\n\t\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tif( clipOR == 0 ) {\n\t\t\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv, vtx3->zv);\n\t\t\t\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\t\t\t\tSort3dPtr->_1 = MAKE_ZSORT(zv);\n\t\t\t\t++Sort3dPtr;\n\n\t\t\t\tif( zv >= (double)PerspectiveDistance ) {\n\t\t\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_GTmap : POLY_WGTmap;\n\t\t\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t\t\t*Info3dPtr++ = 4;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->g;\n\t\t\t\t\t*Info3dPtr++ = uv[0].u;\n\t\t\t\t\t*Info3dPtr++ = uv[0].v;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->g;\n\t\t\t\t\t*Info3dPtr++ = uv[1].u;\n\t\t\t\t\t*Info3dPtr++ = uv[1].v;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->g;\n\t\t\t\t\t*Info3dPtr++ = uv[2].u;\n\t\t\t\t\t*Info3dPtr++ = uv[2].v;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx3->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx3->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx3->g;\n\t\t\t\t\t*Info3dPtr++ = uv[3].u;\n\t\t\t\t\t*Info3dPtr++ = uv[3].v;\n\t\t\t\t} else {\n\t\t\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_GTmap_persp : POLY_WGTmap_persp;\n\t\t\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t\t\t*Info3dPtr++ = 4;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->g;\n\t\t\t\t\t*(float *)Info3dPtr = vtx0->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[0].u * vtx0->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[0].v * vtx0->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->g;\n\t\t\t\t\t*(float *)Info3dPtr = vtx1->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[1].u * vtx1->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[1].v * vtx1->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->g;\n\t\t\t\t\t*(float *)Info3dPtr = vtx2->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[2].u * vtx2->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[2].v * vtx2->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx3->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx3->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx3->g;\n\t\t\t\t\t*(float *)Info3dPtr = vtx3->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[3].u * vtx3->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[3].v * vtx3->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t}\n\t\t\t\t++SurfaceCount;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tVBuffer[0].x = vtx0->xs;\n\t\t\tVBuffer[0].y = vtx0->ys;\n\t\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\t\tVBuffer[0].g = (float)vtx0->g;\n\t\t\tVBuffer[0].u = (double)uv[0].u * vtx0->rhw;\n\t\t\tVBuffer[0].v = (double)uv[0].v * vtx0->rhw;\n\n\t\t\tVBuffer[1].x = vtx1->xs;\n\t\t\tVBuffer[1].y = vtx1->ys;\n\t\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\t\tVBuffer[1].g = (float)vtx1->g;\n\t\t\tVBuffer[1].u = (double)uv[1].u * vtx1->rhw;\n\t\t\tVBuffer[1].v = (double)uv[1].v * vtx1->rhw;\n\n\t\t\tVBuffer[2].x = vtx2->xs;\n\t\t\tVBuffer[2].y = vtx2->ys;\n\t\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\t\tVBuffer[2].g = (float)vtx2->g;\n\t\t\tVBuffer[2].u = (double)uv[2].u * vtx2->rhw;\n\t\t\tVBuffer[2].v = (double)uv[2].v * vtx2->rhw;\n\n\t\t\tVBuffer[3].x = vtx3->xs;\n\t\t\tVBuffer[3].y = vtx3->ys;\n\t\t\tVBuffer[3].rhw = vtx3->rhw;\n\t\t\tVBuffer[3].g = (float)vtx3->g;\n\t\t\tVBuffer[3].u = (double)uv[3].u * vtx3->rhw;\n\t\t\tVBuffer[3].v = (double)uv[3].v * vtx3->rhw;\n\t\t} else {\n\n\t\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tpoints[0].xv\t= vtx0->xv;\n\t\t\tpoints[0].yv\t= vtx0->yv;\n\t\t\tpoints[0].zv\t= vtx0->zv;\n\t\t\tpoints[0].rhw\t= vtx0->rhw;\n\t\t\tpoints[0].xs\t= vtx0->xs;\n\t\t\tpoints[0].ys\t= vtx0->ys;\n\t\t\tpoints[0].u\t\t= (float)uv[0].u;\n\t\t\tpoints[0].v\t\t= (float)uv[0].v;\n\t\t\tpoints[0].g\t\t= (float)vtx0->g;\n\n\t\t\tpoints[1].yv\t= vtx1->yv;\n\t\t\tpoints[1].xv\t= vtx1->xv;\n\t\t\tpoints[1].zv\t= vtx1->zv;\n\t\t\tpoints[1].rhw\t= vtx1->rhw;\n\t\t\tpoints[1].xs\t= vtx1->xs;\n\t\t\tpoints[1].ys\t= vtx1->ys;\n\t\t\tpoints[1].u\t\t= (float)uv[1].u;\n\t\t\tpoints[1].v\t\t= (float)uv[1].v;\n\t\t\tpoints[1].g\t\t= (float)vtx1->g;\n\n\t\t\tpoints[2].xv\t= vtx2->xv;\n\t\t\tpoints[2].yv\t= vtx2->yv;\n\t\t\tpoints[2].zv\t= vtx2->zv;\n\t\t\tpoints[2].rhw\t= vtx2->rhw;\n\t\t\tpoints[2].xs\t= vtx2->xs;\n\t\t\tpoints[2].ys\t= vtx2->ys;\n\t\t\tpoints[2].u\t\t= (float)uv[2].u;\n\t\t\tpoints[2].v\t\t= (float)uv[2].v;\n\t\t\tpoints[2].g\t\t= (float)vtx2->g;\n\n\t\t\tpoints[3].xv\t= vtx3->xv;\n\t\t\tpoints[3].yv\t= vtx3->yv;\n\t\t\tpoints[3].zv\t= vtx3->zv;\n\t\t\tpoints[3].rhw\t= vtx3->rhw;\n\t\t\tpoints[3].xs\t= vtx3->xs;\n\t\t\tpoints[3].ys\t= vtx3->ys;\n\t\t\tpoints[3].u\t\t= (float)uv[3].u;\n\t\t\tpoints[3].v\t\t= (float)uv[3].v;\n\t\t\tpoints[3].g\t\t= (float)vtx3->g;\n\n\t\t\tnPoints = ZedClipper(nPoints, points, VBuffer);\n\t\t\tif( nPoints == 0 ) continue;\n\t\t}\n\n\t\tnPoints = XYGUVClipper(nPoints, VBuffer);\n\t\tif( nPoints == 0 ) continue;\n\n\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv, vtx3->zv);\n\t\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\t\tSort3dPtr->_1 = MAKE_ZSORT(zv);\n\t\t++Sort3dPtr;\n\n\t\tif( zv >= (double)PerspectiveDistance ) {\n\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_GTmap : POLY_WGTmap;\n\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t*Info3dPtr++ = nPoints;\n\n\t\t\tfor( j = 0; j < nPoints; ++j ) {\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].x;\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].y;\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].g;\n\t\t\t\t*Info3dPtr++ = (int)(VBuffer[j].u / VBuffer[j].rhw);\n\t\t\t\t*Info3dPtr++ = (int)(VBuffer[j].v / VBuffer[j].rhw);\n\t\t\t}\n\t\t} else {\n\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_GTmap_persp : POLY_WGTmap_persp;\n\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t*Info3dPtr++ = nPoints;\n\n\t\t\tfor( j = 0; j < nPoints; ++j ) {\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].x;\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].y;\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].g;\n\t\t\t\t*(float *)Info3dPtr = VBuffer[j].rhw;\n\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t*(float *)Info3dPtr = VBuffer[j].u;\n\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t*(float *)Info3dPtr = VBuffer[j].v;\n\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t}\n\t\t}\n\t\t++SurfaceCount;\n\t}\n\n\treturn ptrObj;\n}\n\n__int16 *__cdecl InsertObjectGT3(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tPHD_VBUF *vtx0, *vtx1, *vtx2;\n\tint i, j, nPoints;\n\tfloat zv;\n\t__int16 textureIdx;\n\tPHD_TEXTURE *texture;\n\tPHD_UV *uv;\n\tPOINT_INFO points[3];\n\n\tfor( i = 0; i < number; ++i ) {\n\t\tvtx0 = &PhdVBuf[*ptrObj++];\n\t\tvtx1 = &PhdVBuf[*ptrObj++];\n\t\tvtx2 = &PhdVBuf[*ptrObj++];\n\t\ttextureIdx = *ptrObj++;\n\t\ttexture = &PhdTextureInfo[textureIdx];\n\t\tuv = texture->uv;\n\t\tnPoints = 3;\n\n\t\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip);\n\t\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip);\n\n\t\tif( clipAND != 0 )\n\t\t\tcontinue;\n\n\t\tif( clipOR >= 0 ) {\n\t\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tif( clipOR == 0 ) {\n\t\t\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv);\n\t\t\t\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\t\t\t\tSort3dPtr->_1 = MAKE_ZSORT(zv);\n\t\t\t\t++Sort3dPtr;\n\n\t\t\t\tif( zv >= (double)PerspectiveDistance ) {\n\t\t\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_GTmap : POLY_WGTmap;\n\t\t\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t\t\t*Info3dPtr++ = 3;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->g;\n\t\t\t\t\t*Info3dPtr++ = uv[0].u;\n\t\t\t\t\t*Info3dPtr++ = uv[0].v;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->g;\n\t\t\t\t\t*Info3dPtr++ = uv[1].u;\n\t\t\t\t\t*Info3dPtr++ = uv[1].v;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->g;\n\t\t\t\t\t*Info3dPtr++ = uv[2].u;\n\t\t\t\t\t*Info3dPtr++ = uv[2].v;\n\t\t\t\t} else {\n\t\t\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_GTmap_persp : POLY_WGTmap_persp;\n\t\t\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t\t\t*Info3dPtr++ = 3;\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx0->g;\n\t\t\t\t\t*(float *)Info3dPtr = vtx0->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[0].u * vtx0->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[0].v * vtx0->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx1->g;\n\t\t\t\t\t*(float *)Info3dPtr = vtx1->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[1].u * vtx1->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[1].v * vtx1->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->xs;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->ys;\n\t\t\t\t\t*Info3dPtr++ = (int)vtx2->g;\n\t\t\t\t\t*(float *)Info3dPtr = vtx2->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[2].u * vtx2->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t\t*(float *)Info3dPtr = (double)uv[2].v * vtx2->rhw;\n\t\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t}\n\t\t\t\t++SurfaceCount;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tVBuffer[0].x = vtx0->xs;\n\t\t\tVBuffer[0].y = vtx0->ys;\n\t\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\t\tVBuffer[0].g = (float)vtx0->g;\n\t\t\tVBuffer[0].u = (double)uv[0].u * vtx0->rhw;\n\t\t\tVBuffer[0].v = (double)uv[0].v * vtx0->rhw;\n\n\t\t\tVBuffer[1].x = vtx1->xs;\n\t\t\tVBuffer[1].y = vtx1->ys;\n\t\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\t\tVBuffer[1].g = (float)vtx1->g;\n\t\t\tVBuffer[1].u = (double)uv[1].u * vtx1->rhw;\n\t\t\tVBuffer[1].v = (double)uv[1].v * vtx1->rhw;\n\n\t\t\tVBuffer[2].x = vtx2->xs;\n\t\t\tVBuffer[2].y = vtx2->ys;\n\t\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\t\tVBuffer[2].g = (float)vtx2->g;\n\t\t\tVBuffer[2].u = (double)uv[2].u * vtx2->rhw;\n\t\t\tVBuffer[2].v = (double)uv[2].v * vtx2->rhw;\n\t\t} else {\n\n\t\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tpoints[0].xv\t= vtx0->xv;\n\t\t\tpoints[0].yv\t= vtx0->yv;\n\t\t\tpoints[0].zv\t= vtx0->zv;\n\t\t\tpoints[0].rhw\t= vtx0->rhw;\n\t\t\tpoints[0].xs\t= vtx0->xs;\n\t\t\tpoints[0].ys\t= vtx0->ys;\n\t\t\tpoints[0].u\t\t= (float)uv[0].u;\n\t\t\tpoints[0].v\t\t= (float)uv[0].v;\n\t\t\tpoints[0].g\t\t= (float)vtx0->g;\n\n\t\t\tpoints[1].yv\t= vtx1->yv;\n\t\t\tpoints[1].xv\t= vtx1->xv;\n\t\t\tpoints[1].zv\t= vtx1->zv;\n\t\t\tpoints[1].rhw\t= vtx1->rhw;\n\t\t\tpoints[1].xs\t= vtx1->xs;\n\t\t\tpoints[1].ys\t= vtx1->ys;\n\t\t\tpoints[1].u\t\t= (float)uv[1].u;\n\t\t\tpoints[1].v\t\t= (float)uv[1].v;\n\t\t\tpoints[1].g\t\t= (float)vtx1->g;\n\n\t\t\tpoints[2].xv\t= vtx2->xv;\n\t\t\tpoints[2].yv\t= vtx2->yv;\n\t\t\tpoints[2].zv\t= vtx2->zv;\n\t\t\tpoints[2].rhw\t= vtx2->rhw;\n\t\t\tpoints[2].xs\t= vtx2->xs;\n\t\t\tpoints[2].ys\t= vtx2->ys;\n\t\t\tpoints[2].u\t\t= (float)uv[2].u;\n\t\t\tpoints[2].v\t\t= (float)uv[2].v;\n\t\t\tpoints[2].g\t\t= (float)vtx2->g;\n\n\t\t\tnPoints = ZedClipper(nPoints, points, VBuffer);\n\t\t\tif( nPoints == 0 ) continue;\n\t\t}\n\n\t\tnPoints = XYGUVClipper(nPoints, VBuffer);\n\t\tif( nPoints == 0 ) continue;\n\n\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv);\n\t\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\t\tSort3dPtr->_1 = MAKE_ZSORT(zv);\n\t\t++Sort3dPtr;\n\n\t\tif( zv >= (double)PerspectiveDistance ) {\n\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_GTmap : POLY_WGTmap;\n\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t*Info3dPtr++ = nPoints;\n\n\t\t\tfor( j = 0; j < nPoints; ++j ) {\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].x;\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].y;\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].g;\n\t\t\t\t*Info3dPtr++ = (int)(VBuffer[j].u / VBuffer[j].rhw);\n\t\t\t\t*Info3dPtr++ = (int)(VBuffer[j].v / VBuffer[j].rhw);\n\t\t\t}\n\t\t} else {\n\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_GTmap_persp : POLY_WGTmap_persp;\n\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t*Info3dPtr++ = nPoints;\n\n\t\t\tfor( j = 0; j < nPoints; ++j ) {\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].x;\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].y;\n\t\t\t\t*Info3dPtr++ = (int)VBuffer[j].g;\n\t\t\t\t*(float *)Info3dPtr = VBuffer[j].rhw;\n\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t*(float *)Info3dPtr = VBuffer[j].u;\n\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t\t*(float *)Info3dPtr = VBuffer[j].v;\n\t\t\t\tInfo3dPtr += sizeof(float)/sizeof(__int16);\n\t\t\t}\n\t\t}\n\t\t++SurfaceCount;\n\t}\n\n\treturn ptrObj;\n}\n\nstatic inline void clipG(VERTEX_INFO *buf, VERTEX_INFO *vtx1, VERTEX_INFO *vtx2, float clip) {\n\tbuf->rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\tbuf->g   = vtx2->g   + (vtx1->g   - vtx2->g)   * clip;\n}\n\nint __cdecl XYGClipper(int vtxCount, VERTEX_INFO *vtx) {\n\tVERTEX_INFO vtx_buf[8];\n\tVERTEX_INFO *vtx1, *vtx2;\n\tfloat clip;\n\tint i, j;\n\n\tif( vtxCount < 3 )\n\t\treturn 0;\n\n\t// horizontal clip\n\tvtx2 = &vtx[vtxCount - 1];\n\tj = 0;\n\tfor( i = 0; i < vtxCount; ++i ) {\n\t\tvtx1 = vtx2;\n\t\tvtx2 = &vtx[i];\n\n\t\tif( vtx1->x < FltWinLeft ) {\n\t\t\tif( vtx2->x < FltWinLeft ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinLeft - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinLeft;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tclipG(&vtx_buf[j++], vtx1, vtx2, clip);\n\t\t}\n\t\telse if( vtx1->x > FltWinRight) {\n\t\t\tif( vtx2->x > FltWinRight ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinRight - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinRight;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tclipG(&vtx_buf[j++], vtx1, vtx2, clip);\n\t\t}\n\n\t\tif( vtx2->x < FltWinLeft ) {\n\t\t\tclip = (FltWinLeft - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinLeft;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tclipG(&vtx_buf[j++], vtx1, vtx2, clip);\n\t\t}\n\t\telse if( vtx2->x > FltWinRight ) {\n\t\t\tclip = (FltWinRight - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinRight;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tclipG(&vtx_buf[j++], vtx1, vtx2, clip);\n\t\t} else {\n\t\t\tvtx_buf[j++] = *vtx2;\n\t\t}\n\t}\n\tvtxCount = j;\n\n\tif( vtxCount < 3 )\n\t\treturn 0;\n\n\t// vertical clip\n\tvtx2 = &vtx_buf[vtxCount-1];\n\tj = 0;\n\tfor( i = 0; i < vtxCount; ++i ) {\n\t\tvtx1 = vtx2;\n\t\tvtx2 = &vtx_buf[i];\n\n\t\tif( vtx1->y < FltWinTop ) {\n\t\t\tif( vtx2->y < FltWinTop ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinTop - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinTop;\n\t\t\tclipG(&vtx[j++], vtx1, vtx2, clip);\n\t\t}\n\t\telse if( vtx1->y > FltWinBottom ) {\n\t\t\tif( vtx2->y > FltWinBottom ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinBottom - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinBottom;\n\t\t\tclipG(&vtx[j++], vtx1, vtx2, clip);\n\t\t}\n\n\t\tif( vtx2->y < FltWinTop ) {\n\t\t\tclip = (FltWinTop - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinTop;\n\t\t\tclipG(&vtx[j++], vtx1, vtx2, clip);\n\t\t}\n\t\telse if( vtx2->y > FltWinBottom ) {\n\t\t\tclip = (FltWinBottom - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinBottom;\n\t\t\tclipG(&vtx[j++], vtx1, vtx2, clip);\n\t\t} else {\n\t\t\tvtx[j++] = *vtx2;\n\t\t}\n\t}\n\treturn ( j < 3 ) ? 0 : j;\n}\n\n__int16 *__cdecl InsertObjectG4(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tPHD_VBUF *vtx0, *vtx1, *vtx2, *vtx3;\n\tint i, j, nPoints;\n\tfloat zv;\n\tBYTE colorIdx;\n\tPOINT_INFO pts[4];\n\n\tfor( i = 0; i < number; ++i ) {\n\t\tvtx0 = &PhdVBuf[*ptrObj++];\n\t\tvtx1 = &PhdVBuf[*ptrObj++];\n\t\tvtx2 = &PhdVBuf[*ptrObj++];\n\t\tvtx3 = &PhdVBuf[*ptrObj++];\n\t\tcolorIdx = *ptrObj++;\n\t\tnPoints = 4;\n\n\t\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip | vtx3->clip);\n\t\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip & vtx3->clip);\n\n\t\tif( clipAND != 0 )\n\t\t\tcontinue;\n\n\t\tif( clipOR >= 0 ) {\n\t\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tVBuffer[0].x = vtx0->xs;\n\t\t\tVBuffer[0].y = vtx0->ys;\n\t\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\t\tVBuffer[0].g = (float)vtx0->g;\n\n\t\t\tVBuffer[1].x = vtx1->xs;\n\t\t\tVBuffer[1].y = vtx1->ys;\n\t\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\t\tVBuffer[1].g = (float)vtx1->g;\n\n\t\t\tVBuffer[2].x = vtx2->xs;\n\t\t\tVBuffer[2].y = vtx2->ys;\n\t\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\t\tVBuffer[2].g = (float)vtx2->g;\n\n\t\t\tVBuffer[3].x = vtx3->xs;\n\t\t\tVBuffer[3].y = vtx3->ys;\n\t\t\tVBuffer[3].rhw = vtx3->rhw;\n\t\t\tVBuffer[3].g = (float)vtx3->g;\n\n\t\t\tif( clipOR > 0 ) {\n\t\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t\t}\n\t\t} else {\n\t\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tpts[0].xv = vtx0->xv;\n\t\t\tpts[0].yv = vtx0->yv;\n\t\t\tpts[0].zv = vtx0->zv;\n\t\t\tpts[0].rhw = vtx0->rhw;\n\t\t\tpts[0].xs = vtx0->xs;\n\t\t\tpts[0].ys = vtx0->ys;\n\t\t\tpts[0].g = (float)vtx0->g;\n\n\t\t\tpts[1].xv = vtx1->xv;\n\t\t\tpts[1].yv = vtx1->yv;\n\t\t\tpts[1].zv = vtx1->zv;\n\t\t\tpts[1].rhw = vtx1->rhw;\n\t\t\tpts[1].xs = vtx1->xs;\n\t\t\tpts[1].ys = vtx1->ys;\n\t\t\tpts[1].g = (float)vtx1->g;\n\n\t\t\tpts[2].xv = vtx2->xv;\n\t\t\tpts[2].yv = vtx2->yv;\n\t\t\tpts[2].zv = vtx2->zv;\n\t\t\tpts[2].rhw = vtx2->rhw;\n\t\t\tpts[2].xs = vtx2->xs;\n\t\t\tpts[2].ys = vtx2->ys;\n\t\t\tpts[2].g = (float)vtx2->g;\n\n\t\t\tpts[3].xv = vtx3->xv;\n\t\t\tpts[3].yv = vtx3->yv;\n\t\t\tpts[3].zv = vtx3->zv;\n\t\t\tpts[3].rhw = vtx3->rhw;\n\t\t\tpts[3].xs = vtx3->xs;\n\t\t\tpts[3].ys = vtx3->ys;\n\t\t\tpts[3].g = (float)vtx3->g;\n\n\t\t\tnPoints = ZedClipper(nPoints, pts, VBuffer);\n\t\t\tif( nPoints == 0 ) continue;\n\n\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t}\n\n\t\tif( nPoints == 0 )\n\t\t\tcontinue;\n\n\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv, vtx3->zv);\n\t\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\t\tSort3dPtr->_1 = MAKE_ZSORT(zv);\n\t\t++Sort3dPtr;\n\n\t\t*Info3dPtr++ = POLY_gouraud;\n\t\t*Info3dPtr++ = colorIdx;\n\t\t*Info3dPtr++ = nPoints;\n\n\t\tfor( j = 0; j < nPoints; ++j ) {\n\t\t\t*Info3dPtr++ = VBuffer[j].x;\n\t\t\t*Info3dPtr++ = VBuffer[j].y;\n\t\t\t*Info3dPtr++ = VBuffer[j].g;\n\t\t}\n\t\t++SurfaceCount;\n\t}\n\n\treturn ptrObj;\n}\n\n__int16 *__cdecl InsertObjectG3(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tPHD_VBUF *vtx0, *vtx1, *vtx2;\n\tint i, j, nPoints;\n\tfloat zv;\n\tBYTE colorIdx;\n\tPOINT_INFO pts[3];\n\n\tfor( i = 0; i < number; ++i ) {\n\t\tvtx0 = &PhdVBuf[*ptrObj++];\n\t\tvtx1 = &PhdVBuf[*ptrObj++];\n\t\tvtx2 = &PhdVBuf[*ptrObj++];\n\t\tcolorIdx = *ptrObj++;\n\t\tnPoints = 3;\n\n\t\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip);\n\t\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip);\n\n\t\tif( clipAND != 0 )\n\t\t\tcontinue;\n\n\t\tif( clipOR >= 0 ) {\n\t\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tVBuffer[0].x = vtx0->xs;\n\t\t\tVBuffer[0].y = vtx0->ys;\n\t\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\t\tVBuffer[0].g = (float)vtx0->g;\n\n\t\t\tVBuffer[1].x = vtx1->xs;\n\t\t\tVBuffer[1].y = vtx1->ys;\n\t\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\t\tVBuffer[1].g = (float)vtx1->g;\n\n\t\t\tVBuffer[2].x = vtx2->xs;\n\t\t\tVBuffer[2].y = vtx2->ys;\n\t\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\t\tVBuffer[2].g = (float)vtx2->g;\n\n\t\t\tif( clipOR > 0 ) {\n\t\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t\t}\n\t\t} else {\n\t\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tpts[0].xv = vtx0->xv;\n\t\t\tpts[0].yv = vtx0->yv;\n\t\t\tpts[0].zv = vtx0->zv;\n\t\t\tpts[0].rhw = vtx0->rhw;\n\t\t\tpts[0].xs = vtx0->xs;\n\t\t\tpts[0].ys = vtx0->ys;\n\t\t\tpts[0].g = (float)vtx0->g;\n\n\t\t\tpts[1].xv = vtx1->xv;\n\t\t\tpts[1].yv = vtx1->yv;\n\t\t\tpts[1].zv = vtx1->zv;\n\t\t\tpts[1].rhw = vtx1->rhw;\n\t\t\tpts[1].xs = vtx1->xs;\n\t\t\tpts[1].ys = vtx1->ys;\n\t\t\tpts[1].g = (float)vtx1->g;\n\n\t\t\tpts[2].xv = vtx2->xv;\n\t\t\tpts[2].yv = vtx2->yv;\n\t\t\tpts[2].zv = vtx2->zv;\n\t\t\tpts[2].rhw = vtx2->rhw;\n\t\t\tpts[2].xs = vtx2->xs;\n\t\t\tpts[2].ys = vtx2->ys;\n\t\t\tpts[2].g = (float)vtx2->g;\n\n\t\t\tnPoints = ZedClipper(nPoints, pts, VBuffer);\n\t\t\tif( nPoints == 0 ) continue;\n\n\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t}\n\n\t\tif( nPoints == 0 )\n\t\t\tcontinue;\n\n\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv);\n\t\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\t\tSort3dPtr->_1 = MAKE_ZSORT(zv);\n\t\t++Sort3dPtr;\n\n\t\t*Info3dPtr++ = POLY_gouraud;\n\t\t*Info3dPtr++ = colorIdx;\n\t\t*Info3dPtr++ = nPoints;\n\n\t\tfor( j = 0; j < nPoints; ++j ) {\n\t\t\t*Info3dPtr++ = (int)VBuffer[j].x;\n\t\t\t*Info3dPtr++ = (int)VBuffer[j].y;\n\t\t\t*Info3dPtr++ = (int)VBuffer[j].g;\n\t\t}\n\t\t++SurfaceCount;\n\t}\n\n\treturn ptrObj;\n}\n\nint __cdecl XYClipper(int vtxCount, VERTEX_INFO *vtx) {\n\t// NOTE: the original function ignores rhw clipping that produces bugs for Z Buffer\n\tstatic VERTEX_INFO vtx_buf[40]; // NOTE: original size was 20\n\tVERTEX_INFO *vtx1, *vtx2;\n\tfloat clip;\n\tint i, j;\n\n\tif( vtxCount < 3 )\n\t\treturn 0;\n\n\t// horizontal clip\n\tvtx2 = &vtx[vtxCount - 1];\n\tj = 0;\n\tfor( i = 0; i < vtxCount; ++i ) {\n\t\tvtx1 = vtx2;\n\t\tvtx2 = &vtx[i];\n\n\t\tif( vtx1->x < FltWinLeft ) {\n\t\t\tif( vtx2->x < FltWinLeft ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinLeft - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinLeft;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tvtx_buf[j++].rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\t\t}\n\t\telse if( vtx1->x > FltWinRight) {\n\t\t\tif( vtx2->x > FltWinRight ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinRight - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinRight;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tvtx_buf[j++].rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\t\t}\n\n\t\tif( vtx2->x < FltWinLeft ) {\n\t\t\tclip = (FltWinLeft - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinLeft;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tvtx_buf[j++].rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\t\t}\n\t\telse if( vtx2->x > FltWinRight ) {\n\t\t\tclip = (FltWinRight - vtx2->x) / (vtx1->x - vtx2->x);\n\t\t\tvtx_buf[j].x = FltWinRight;\n\t\t\tvtx_buf[j].y = vtx2->y + (vtx1->y - vtx2->y) * clip;\n\t\t\tvtx_buf[j++].rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\t\t} else {\n\t\t\tvtx_buf[j].x = vtx2->x;\n\t\t\tvtx_buf[j].y = vtx2->y;\n\t\t\tvtx_buf[j++].rhw = vtx2->rhw;\n\t\t}\n\t}\n\tvtxCount = j;\n\n\tif( vtxCount < 3 )\n\t\treturn 0;\n\n\t// vertical clip\n\tvtx2 = &vtx_buf[vtxCount-1];\n\tj = 0;\n\tfor( i = 0; i < vtxCount; ++i ) {\n\t\tvtx1 = vtx2;\n\t\tvtx2 = &vtx_buf[i];\n\n\t\tif( vtx1->y < FltWinTop ) {\n\t\t\tif( vtx2->y < FltWinTop ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinTop - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinTop;\n\t\t\tvtx[j++].rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\t\t}\n\t\telse if( vtx1->y > FltWinBottom ) {\n\t\t\tif( vtx2->y > FltWinBottom ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tclip = (FltWinBottom - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinBottom;\n\t\t\tvtx[j++].rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\t\t}\n\n\t\tif( vtx2->y < FltWinTop ) {\n\t\t\tclip = (FltWinTop - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinTop;\n\t\t\tvtx[j++].rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\t\t}\n\t\telse if( vtx2->y > FltWinBottom ) {\n\t\t\tclip = (FltWinBottom - vtx2->y) / (vtx1->y - vtx2->y);\n\t\t\tvtx[j].x = vtx2->x + (vtx1->x - vtx2->x) * clip;\n\t\t\tvtx[j].y = FltWinBottom;\n\t\t\tvtx[j++].rhw = vtx2->rhw + (vtx1->rhw - vtx2->rhw) * clip;\n\t\t} else {\n\t\t\tvtx[j].x = vtx2->x;\n\t\t\tvtx[j].y = vtx2->y;\n\t\t\tvtx[j++].rhw = vtx2->rhw;\n\t\t}\n\t}\n\n\treturn ( j < 3 ) ? 0 : j;\n}\n\nvoid __cdecl InsertTrans8(PHD_VBUF *vbuf, __int16 shade) {\n\tint i, nPoints, polyZ;\n\tchar clipOR = 0x00;\n\tchar clipAND = 0xFF;\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tint nVtx = ( ShadowMode == 1 ) ? 32 : 8;\n#else // FEATURE_VIDEOFX_IMPROVED\n\tint nVtx = 8;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tfor( i = 0; i < nVtx; ++i ) {\n\t\tclipOR  |= LOBYTE(vbuf[i].clip);\n\t\tclipAND &= LOBYTE(vbuf[i].clip);\n\t}\n\n\tif( (clipOR < 0) || (clipAND != 0) || !VBUF_VISIBLE(vbuf[0], vbuf[1], vbuf[2]) )\n\t\treturn;\n\n\tfor( i = 0; i < nVtx; ++i ) {\n\t\tVBuffer[i].x = vbuf[i].xs;\n\t\tVBuffer[i].y = vbuf[i].ys;\n\t}\n\n\tnPoints = nVtx;\n\n\tif( clipOR != 0 ) {\n\t\tFltWinLeft = 0.0;\n\t\tFltWinTop  = 0.0;\n\t\tFltWinRight  = (float)PhdWinMaxX;\n\t\tFltWinBottom = (float)PhdWinMaxY;\n\n\t\tnPoints = XYClipper(nPoints, VBuffer);\n\t\tif( nPoints == 0) return;\n\t}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tdouble polyZflt = 0.0;\n\tfor( i = 0; i < nVtx; ++i ) {\n\t\tpolyZflt += (double)vbuf[i].zv / (double)nVtx;\n\t}\n\tpolyZ = polyZflt;\n#else // FEATURE_VIDEOFX_IMPROVED\n\tpolyZ = 0;\n\tfor( i = 0; i < nVtx; ++i ) {\n\t\tpolyZ += vbuf[i].zv;\n\t}\n\tpolyZ /= nVtx;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(polyZ);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_trans;\n\t*(Info3dPtr++) = shade;\n\t*(Info3dPtr++) = nPoints; // number of vertices\n\n\tfor( i = 0; i < nPoints; ++i ) {\n\t\t*(Info3dPtr++) = (int)VBuffer[i].x;\n\t\t*(Info3dPtr++) = (int)VBuffer[i].y;\n\t}\n\n\t++SurfaceCount;\n}\n\nvoid __cdecl InsertTransQuad(int x, int y, int width, int height, int z) {\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(PhdNearZ + 8*z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_trans;\n\t// NOTE: Here 24 is DepthQ index (shade factor).\n\t// 0 lightest, 15 no shade, 31 darkest (pitch black).\n\t// But original code has value 32 supposed to be interpreted as 24 (which means 50% darker)\n\t// Also 32 is maximum valid value in the original code, though it is DepthQTable range violation.\n\t// This trick worked because DepthQIndex array was right after DepthQ array in the memory\n\t// (DepthQIndex is equal to &DepthQ[24].index).This allocation is not guaranteed on some systems, so it was fixed\n\t*(Info3dPtr++) = 24;\n\t*(Info3dPtr++) = 4;  // number of vertices\n\t*(Info3dPtr++) = x;\n\t*(Info3dPtr++) = y;\n\t*(Info3dPtr++) = x + width;\n\t*(Info3dPtr++) = y;\n\t*(Info3dPtr++) = x + width;\n\t*(Info3dPtr++) = y + height;\n\t*(Info3dPtr++) = x;\n\t*(Info3dPtr++) = y + height;\n\n\t++SurfaceCount;\n}\n\nvoid __cdecl InsertFlatRect(int x0, int y0, int x1, int y1, int z, BYTE colorIdx) {\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_flat;\n\t*(Info3dPtr++) = colorIdx;\n\t*(Info3dPtr++) = 4; // number of vertices\n\t*(Info3dPtr++) = x0;\n\t*(Info3dPtr++) = y0;\n\t*(Info3dPtr++) = x1;\n\t*(Info3dPtr++) = y0;\n\t*(Info3dPtr++) = x1;\n\t*(Info3dPtr++) = y1;\n\t*(Info3dPtr++) = x0;\n\t*(Info3dPtr++) = y1;\n\n\t++SurfaceCount;\n}\n\nvoid __cdecl InsertLine(int x0, int y0, int x1, int y1, int z, BYTE colorIdx) {\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_line;\n\t*(Info3dPtr++) = PhdWinMinX + x0;\n\t*(Info3dPtr++) = PhdWinMinY + y0;\n\t*(Info3dPtr++) = PhdWinMinX + x1;\n\t*(Info3dPtr++) = PhdWinMinY + y1;\n\t*(Info3dPtr++) = colorIdx;\n\n\t++SurfaceCount;\n}\n\nvoid __cdecl InsertGT3_ZBuffered(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2, PHD_TEXTURE *texture, PHD_UV *uv0, PHD_UV *uv1, PHD_UV *uv2) {\n\tchar clipOR, clipAND;\n\tPOINT_INFO points[3];\n\tint nPoints = 3;\n\n\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip);\n\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip);\n\n\tif( clipAND != 0 )\n\t\treturn;\n\n\tif( clipOR >= 0 ) {\n\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\treturn;\n\n\t\tif( clipOR == 0 ) {\n\t\t\tVBufferD3D[0].sx = vtx0->xs;\n\t\t\tVBufferD3D[0].sy = vtx0->ys;\n\t\t\tVBufferD3D[0].sz = FltResZBuf - FltResZORhw * vtx0->rhw;\n\t\t\tVBufferD3D[0].rhw = vtx0->rhw;\n\t\t\tVBufferD3D[0].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx0->g, true);\n\t\t\tVBufferD3D[0].tu = (double)uv0->u / (double)PHD_ONE;\n\t\t\tVBufferD3D[0].tv = (double)uv0->v / (double)PHD_ONE;\n\n\t\t\tVBufferD3D[1].sx = vtx1->xs;\n\t\t\tVBufferD3D[1].sy = vtx1->ys;\n\t\t\tVBufferD3D[1].sz = FltResZBuf - FltResZORhw * vtx1->rhw;\n\t\t\tVBufferD3D[1].rhw = vtx1->rhw;\n\t\t\tVBufferD3D[1].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx1->g, true);\n\t\t\tVBufferD3D[1].tu = (double)uv1->u / (double)PHD_ONE;\n\t\t\tVBufferD3D[1].tv = (double)uv1->v / (double)PHD_ONE;\n\n\t\t\tVBufferD3D[2].sx = vtx2->xs;\n\t\t\tVBufferD3D[2].sy = vtx2->ys;\n\t\t\tVBufferD3D[2].sz = FltResZBuf - FltResZORhw * vtx2->rhw;\n\t\t\tVBufferD3D[2].rhw = vtx2->rhw;\n\t\t\tVBufferD3D[2].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx2->g, true);\n\t\t\tVBufferD3D[2].tu = (double)uv2->u / (double)PHD_ONE;\n\t\t\tVBufferD3D[2].tv = (double)uv2->v / (double)PHD_ONE;\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tHWR_TexSource(texture->tpage == (UINT16)~0 ? GetEnvmapTextureHandle() : HWR_PageHandles[texture->tpage]);\n#else // !FEATURE_VIDEOFX_IMPROVED\n\t\t\tHWR_TexSource(HWR_PageHandles[texture->tpage]);\n#endif // !FEATURE_VIDEOFX_IMPROVED\n\t\t\tHWR_EnableColorKey(texture->drawtype != DRAW_Opaque);\n\n\t\t\tHWR_DrawPrimitive(D3DPT_TRIANGLELIST, VBufferD3D, 3, true);\n\t\t\treturn;\n\t\t}\n\n\t\tVBuffer[0].x = vtx0->xs;\n\t\tVBuffer[0].y = vtx0->ys;\n\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\tVBuffer[0].g = (double)vtx0->g;\n\t\tVBuffer[0].u = (double)uv0->u * vtx0->rhw;\n\t\tVBuffer[0].v = (double)uv0->v * vtx0->rhw;\n\n\t\tVBuffer[1].x = vtx1->xs;\n\t\tVBuffer[1].y = vtx1->ys;\n\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\tVBuffer[1].g = (double)vtx1->g;\n\t\tVBuffer[1].u = (double)uv1->u * vtx1->rhw;\n\t\tVBuffer[1].v = (double)uv1->v * vtx1->rhw;\n\n\t\tVBuffer[2].x = vtx2->xs;\n\t\tVBuffer[2].y = vtx2->ys;\n\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\tVBuffer[2].g = (double)vtx2->g;\n\t\tVBuffer[2].u = (double)uv2->u * vtx2->rhw;\n\t\tVBuffer[2].v = (double)uv2->v * vtx2->rhw;\n\t} else {\n\n\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\treturn;\n\n\t\tpoints[0].xv\t= vtx0->xv;\n\t\tpoints[0].yv\t= vtx0->yv;\n\t\tpoints[0].zv\t= vtx0->zv;\n\t\tpoints[0].rhw\t= vtx0->rhw;\n\t\tpoints[0].xs\t= vtx0->xs;\n\t\tpoints[0].ys\t= vtx0->ys;\n\t\tpoints[0].u\t\t= (float)uv0->u;\n\t\tpoints[0].v\t\t= (float)uv0->v;\n\t\tpoints[0].g\t\t= (float)vtx0->g;\n\n\t\tpoints[1].yv\t= vtx1->yv;\n\t\tpoints[1].xv\t= vtx1->xv;\n\t\tpoints[1].zv\t= vtx1->zv;\n\t\tpoints[1].rhw\t= vtx1->rhw;\n\t\tpoints[1].xs\t= vtx1->xs;\n\t\tpoints[1].ys\t= vtx1->ys;\n\t\tpoints[1].u\t\t= (float)uv1->u;\n\t\tpoints[1].v\t\t= (float)uv1->v;\n\t\tpoints[1].g\t\t= (float)vtx1->g;\n\n\t\tpoints[2].xv\t= vtx2->xv;\n\t\tpoints[2].yv\t= vtx2->yv;\n\t\tpoints[2].zv\t= vtx2->zv;\n\t\tpoints[2].rhw\t= vtx2->rhw;\n\t\tpoints[2].xs\t= vtx2->xs;\n\t\tpoints[2].ys\t= vtx2->ys;\n\t\tpoints[2].u\t\t= (float)uv2->u;\n\t\tpoints[2].v\t\t= (float)uv2->v;\n\t\tpoints[2].g\t\t= (float)vtx2->g;\n\n\t\tnPoints = ZedClipper(nPoints, points, VBuffer);\n\t\tif( nPoints == 0 ) return;\n\t}\n\n\tnPoints = XYGUVClipper(nPoints, VBuffer);\n\tif( nPoints == 0 ) return;\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tHWR_TexSource(texture->tpage == (UINT16)~0 ? GetEnvmapTextureHandle() : HWR_PageHandles[texture->tpage]);\n#else // !FEATURE_VIDEOFX_IMPROVED\n\tHWR_TexSource(HWR_PageHandles[texture->tpage]);\n#endif // !FEATURE_VIDEOFX_IMPROVED\n\tHWR_EnableColorKey(texture->drawtype != DRAW_Opaque);\n\tDrawClippedPoly_Textured(nPoints);\n}\n\nvoid __cdecl DrawClippedPoly_Textured(int vtxCount) {\n\tD3DCOLOR color;\n\tdouble tu, tv;\n\n\tif( vtxCount == 0 )\n\t\treturn;\n\n\tfor( int i = 0; i < vtxCount; ++i ) {\n\t\tcolor = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, (DWORD)VBuffer[i].g, true);\n\n\t\ttu = VBuffer[i].u / VBuffer[i].rhw / (double)PHD_ONE;\n\t\ttv = VBuffer[i].v / VBuffer[i].rhw / (double)PHD_ONE;\n\t\tCLAMP(tu, 0.0, 1.0);\n\t\tCLAMP(tv, 0.0, 1.0);\n\n\t\tVBufferD3D[i].sx = VBuffer[i].x;\n\t\tVBufferD3D[i].sy = VBuffer[i].y;\n\t\tVBufferD3D[i].sz = FltResZBuf - FltResZORhw * VBuffer[i].rhw;\n\t\tVBufferD3D[i].rhw = VBuffer[i].rhw;\n\t\tVBufferD3D[i].color = color;\n\t\tVBufferD3D[i].tu = tu;\n\t\tVBufferD3D[i].tv = tv;\n\t}\n\n\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, VBufferD3D, vtxCount, true);\n}\n\nvoid __cdecl InsertGT4_ZBuffered(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2, PHD_VBUF *vtx3, PHD_TEXTURE *texture) {\n\tchar clipOR, clipAND;\n\n\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip | vtx3->clip);\n\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip & vtx3->clip);\n\n\tif( clipAND != 0 )\n\t\treturn;\n\n\tif( clipOR == 0 && VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) ) {\n\t\tVBufferD3D[0].sx = vtx0->xs;\n\t\tVBufferD3D[0].sy = vtx0->ys;\n\t\tVBufferD3D[0].sz = FltResZBuf - FltResZORhw * vtx0->rhw;\n\t\tVBufferD3D[0].rhw = vtx0->rhw;\n\t\tVBufferD3D[0].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx0->g, true);\n\t\tVBufferD3D[0].tu = (double)texture->uv[0].u / (double)PHD_ONE;\n\t\tVBufferD3D[0].tv = (double)texture->uv[0].v / (double)PHD_ONE;\n\n\t\tVBufferD3D[1].sx = vtx1->xs;\n\t\tVBufferD3D[1].sy = vtx1->ys;\n\t\tVBufferD3D[1].sz = FltResZBuf - FltResZORhw * vtx1->rhw;\n\t\tVBufferD3D[1].rhw = vtx1->rhw;\n\t\tVBufferD3D[1].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx1->g, true);\n\t\tVBufferD3D[1].tu = (double)texture->uv[1].u / (double)PHD_ONE;\n\t\tVBufferD3D[1].tv = (double)texture->uv[1].v / (double)PHD_ONE;\n\n\t\tVBufferD3D[2].sx = vtx2->xs;\n\t\tVBufferD3D[2].sy = vtx2->ys;\n\t\tVBufferD3D[2].sz = FltResZBuf - FltResZORhw * vtx2->rhw;\n\t\tVBufferD3D[2].rhw = vtx2->rhw;\n\t\tVBufferD3D[2].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx2->g, true);\n\t\tVBufferD3D[2].tu = (double)texture->uv[2].u / (double)PHD_ONE;\n\t\tVBufferD3D[2].tv = (double)texture->uv[2].v / (double)PHD_ONE;\n\n\t\tVBufferD3D[3].sx = vtx3->xs;\n\t\tVBufferD3D[3].sy = vtx3->ys;\n\t\tVBufferD3D[3].sz = FltResZBuf - FltResZORhw * vtx3->rhw;\n\t\tVBufferD3D[3].rhw = vtx3->rhw;\n\t\tVBufferD3D[3].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx3->g, true);\n\t\tVBufferD3D[3].tu = (double)texture->uv[3].u / (double)PHD_ONE;\n\t\tVBufferD3D[3].tv = (double)texture->uv[3].v / (double)PHD_ONE;\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tHWR_TexSource(texture->tpage == (UINT16)~0 ? GetEnvmapTextureHandle() : HWR_PageHandles[texture->tpage]);\n#else // !FEATURE_VIDEOFX_IMPROVED\n\t\tHWR_TexSource(HWR_PageHandles[texture->tpage]);\n#endif // !FEATURE_VIDEOFX_IMPROVED\n\t\tHWR_EnableColorKey(texture->drawtype != DRAW_Opaque);\n\n\t\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, VBufferD3D, 4, true);\n\t}\n\telse if( (clipOR < 0 && visible_zclip(vtx0, vtx1, vtx2)) ||\n\t\t\t (clipOR > 0 && VBUF_VISIBLE(*vtx0, *vtx1, *vtx2)) )\n\t{\n\t\tInsertGT3_ZBuffered(vtx0, vtx1, vtx2, texture, texture->uv, &texture->uv[1], &texture->uv[2]);\n\t\tInsertGT3_ZBuffered(vtx0, vtx2, vtx3, texture, texture->uv, &texture->uv[2], &texture->uv[3]);\n\t}\n}\n\n__int16 *__cdecl InsertObjectGT4_ZBuffered(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tPHD_VBUF *vtx0, *vtx1, *vtx2, *vtx3;\n\tPHD_TEXTURE *texture;\n\n\tfor( int i = 0; i < number; ++i ) {\n\t\tvtx0 = &PhdVBuf[ptrObj[0]];\n\t\tvtx1 = &PhdVBuf[ptrObj[1]];\n\t\tvtx2 = &PhdVBuf[ptrObj[2]];\n\t\tvtx3 = &PhdVBuf[ptrObj[3]];\n\t\ttexture = &PhdTextureInfo[ptrObj[4]];\n\n\t\tif( texture->drawtype != DRAW_Opaque )\n\t\t\tInsertGT4_Sorted(vtx0, vtx1, vtx2, vtx3, texture, sortType);\n\t\telse\n\t\t\tInsertGT4_ZBuffered(vtx0, vtx1, vtx2, vtx3, texture);\n\n\t\tptrObj += 5;\n\t}\n\treturn ptrObj;\n}\n\n__int16 *__cdecl InsertObjectGT3_ZBuffered(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tPHD_VBUF *vtx0, *vtx1, *vtx2;\n\tPHD_TEXTURE *texture;\n\tPHD_UV *uv;\n\n\tfor( int i = 0; i < number; ++i ) {\n\t\tvtx0 = &PhdVBuf[ptrObj[0]];\n\t\tvtx1 = &PhdVBuf[ptrObj[1]];\n\t\tvtx2 = &PhdVBuf[ptrObj[2]];\n\t\ttexture = &PhdTextureInfo[ptrObj[3]];\n\t\tuv = texture->uv;\n\n\t\tif( texture->drawtype != DRAW_Opaque )\n\t\t\tInsertGT3_Sorted(vtx0, vtx1, vtx2, texture, &uv[0], &uv[1], &uv[2], sortType);\n\t\telse\n\t\t\tInsertGT3_ZBuffered(vtx0, vtx1, vtx2, texture, &uv[0], &uv[1], &uv[2]);\n\n\t\tptrObj += 4;\n\t}\n\treturn ptrObj;\n}\n\n__int16 *__cdecl InsertObjectG4_ZBuffered(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tPHD_VBUF *vtx0, *vtx1, *vtx2, *vtx3;\n\tint i, nPoints;\n\t__int16 colorIdx;\n\tPOINT_INFO pts[4];\n\n\tHWR_TexSource(0);\n\tHWR_EnableColorKey(false);\n\n\tfor( i = 0; i < number; ++i ) {\n\t\tvtx0 = &PhdVBuf[*ptrObj++];\n\t\tvtx1 = &PhdVBuf[*ptrObj++];\n\t\tvtx2 = &PhdVBuf[*ptrObj++];\n\t\tvtx3 = &PhdVBuf[*ptrObj++];\n\t\tcolorIdx = *ptrObj++;\n\t\tnPoints = 4;\n\n\t\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip | vtx3->clip);\n\t\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip & vtx3->clip);\n\n\t\tif( clipAND != 0 )\n\t\t\tcontinue;\n\n\t\tif( clipOR >= 0 ) {\n\t\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tVBuffer[0].x = vtx0->xs;\n\t\t\tVBuffer[0].y = vtx0->ys;\n\t\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\t\tVBuffer[0].g = (float)vtx0->g;\n\n\t\t\tVBuffer[1].x = vtx1->xs;\n\t\t\tVBuffer[1].y = vtx1->ys;\n\t\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\t\tVBuffer[1].g = (float)vtx1->g;\n\n\t\t\tVBuffer[2].x = vtx2->xs;\n\t\t\tVBuffer[2].y = vtx2->ys;\n\t\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\t\tVBuffer[2].g = (float)vtx2->g;\n\n\t\t\tVBuffer[3].x = vtx3->xs;\n\t\t\tVBuffer[3].y = vtx3->ys;\n\t\t\tVBuffer[3].rhw = vtx3->rhw;\n\t\t\tVBuffer[3].g = (float)vtx3->g;\n\n\t\t\tif( clipOR > 0 ) {\n\t\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t\t}\n\t\t} else {\n\t\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tpts[0].xv = vtx0->xv;\n\t\t\tpts[0].yv = vtx0->yv;\n\t\t\tpts[0].zv = vtx0->zv;\n\t\t\tpts[0].rhw = vtx0->rhw;\n\t\t\tpts[0].xs = vtx0->xs;\n\t\t\tpts[0].ys = vtx0->ys;\n\t\t\tpts[0].g = (float)vtx0->g;\n\n\t\t\tpts[1].xv = vtx1->xv;\n\t\t\tpts[1].yv = vtx1->yv;\n\t\t\tpts[1].zv = vtx1->zv;\n\t\t\tpts[1].rhw = vtx1->rhw;\n\t\t\tpts[1].xs = vtx1->xs;\n\t\t\tpts[1].ys = vtx1->ys;\n\t\t\tpts[1].g = (float)vtx1->g;\n\n\t\t\tpts[2].xv = vtx2->xv;\n\t\t\tpts[2].yv = vtx2->yv;\n\t\t\tpts[2].zv = vtx2->zv;\n\t\t\tpts[2].rhw = vtx2->rhw;\n\t\t\tpts[2].xs = vtx2->xs;\n\t\t\tpts[2].ys = vtx2->ys;\n\t\t\tpts[2].g = (float)vtx2->g;\n\n\t\t\tpts[3].xv = vtx3->xv;\n\t\t\tpts[3].yv = vtx3->yv;\n\t\t\tpts[3].zv = vtx3->zv;\n\t\t\tpts[3].rhw = vtx3->rhw;\n\t\t\tpts[3].xs = vtx3->xs;\n\t\t\tpts[3].ys = vtx3->ys;\n\t\t\tpts[3].g = (float)vtx3->g;\n\n\t\t\tnPoints = ZedClipper(nPoints, pts, VBuffer);\n\t\t\tif( nPoints == 0 ) continue;\n\n\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t}\n\n\t\tif( nPoints != 0 ) {\n\t\t\tPALETTEENTRY *color = &GamePalette16[colorIdx >> 8];\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tif( AlphaBlendMode && color->peFlags > 0 && color->peFlags <= 4 ) {\n\t\t\t\tfloat zv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv, vtx3->zv);\n\t\t\t\tshort blend[4] = {POLY_HWR_half, POLY_HWR_add, POLY_HWR_sub, POLY_HWR_qrt};\n\t\t\t\tInsertPoly_Gouraud(nPoints, zv, color->peRed, color->peGreen, color->peBlue, blend[color->peFlags - 1]);\n\t\t\t} else {\n\t\t\t\tDrawPoly_Gouraud(nPoints, color->peRed, color->peGreen, color->peBlue);\n\t\t\t}\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\t\tDrawPoly_Gouraud(nPoints, color->peRed, color->peGreen, color->peBlue);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t}\n\t}\n\n\treturn ptrObj;\n}\n\nvoid __cdecl DrawPoly_Gouraud(int vtxCount, int red, int green, int blue) {\n\tD3DCOLOR color;\n\n\tif( vtxCount == 0 )\n\t\treturn;\n\n\tfor( int i = 0; i < vtxCount; ++i ) {\n\t\tcolor = shadeColor(red, green, blue, 0xFF, (DWORD)VBuffer[i].g, false);\n\n\t\tVBufferD3D[i].sx = VBuffer[i].x;\n\t\tVBufferD3D[i].sy = VBuffer[i].y;\n\t\tVBufferD3D[i].sz = FltResZBuf - FltResZORhw * VBuffer[i].rhw;\n\t\tVBufferD3D[i].rhw = VBuffer[i].rhw;\n\t\tVBufferD3D[i].color = color;\n\t}\n\n\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, VBufferD3D, vtxCount, true);\n}\n\n__int16 *__cdecl InsertObjectG3_ZBuffered(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tPHD_VBUF *vtx0, *vtx1, *vtx2;\n\tint i, nPoints;\n\t__int16 colorIdx;\n\tPOINT_INFO pts[3];\n\n\tHWR_TexSource(0);\n\tHWR_EnableColorKey(false);\n\n\tfor( i = 0; i < number; ++i ) {\n\t\tvtx0 = &PhdVBuf[*ptrObj++];\n\t\tvtx1 = &PhdVBuf[*ptrObj++];\n\t\tvtx2 = &PhdVBuf[*ptrObj++];\n\t\tcolorIdx = *ptrObj++;\n\t\tnPoints = 3;\n\n\t\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip);\n\t\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip);\n\n\t\tif( clipAND != 0 )\n\t\t\tcontinue;\n\n\t\tif( clipOR >= 0 ) {\n\t\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tVBuffer[0].x = vtx0->xs;\n\t\t\tVBuffer[0].y = vtx0->ys;\n\t\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\t\tVBuffer[0].g = (float)vtx0->g;\n\n\t\t\tVBuffer[1].x = vtx1->xs;\n\t\t\tVBuffer[1].y = vtx1->ys;\n\t\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\t\tVBuffer[1].g = (float)vtx1->g;\n\n\t\t\tVBuffer[2].x = vtx2->xs;\n\t\t\tVBuffer[2].y = vtx2->ys;\n\t\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\t\tVBuffer[2].g = (float)vtx2->g;\n\n\t\t\tif( clipOR > 0 ) {\n\t\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t\t}\n\t\t} else {\n\t\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tpts[0].xv = vtx0->xv;\n\t\t\tpts[0].yv = vtx0->yv;\n\t\t\tpts[0].zv = vtx0->zv;\n\t\t\tpts[0].rhw = vtx0->rhw;\n\t\t\tpts[0].xs = vtx0->xs;\n\t\t\tpts[0].ys = vtx0->ys;\n\t\t\tpts[0].g = (float)vtx0->g;\n\n\t\t\tpts[1].xv = vtx1->xv;\n\t\t\tpts[1].yv = vtx1->yv;\n\t\t\tpts[1].zv = vtx1->zv;\n\t\t\tpts[1].rhw = vtx1->rhw;\n\t\t\tpts[1].xs = vtx1->xs;\n\t\t\tpts[1].ys = vtx1->ys;\n\t\t\tpts[1].g = (float)vtx1->g;\n\n\t\t\tpts[2].xv = vtx2->xv;\n\t\t\tpts[2].yv = vtx2->yv;\n\t\t\tpts[2].zv = vtx2->zv;\n\t\t\tpts[2].rhw = vtx2->rhw;\n\t\t\tpts[2].xs = vtx2->xs;\n\t\t\tpts[2].ys = vtx2->ys;\n\t\t\tpts[2].g = (float)vtx2->g;\n\n\t\t\tnPoints = ZedClipper(nPoints, pts, VBuffer);\n\t\t\tif( nPoints == 0 ) continue;\n\n\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t}\n\n\t\tif( nPoints != 0 ) {\n\t\t\tPALETTEENTRY *color = &GamePalette16[colorIdx >> 8];\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tif( AlphaBlendMode && color->peFlags > 0 && color->peFlags <= 4 ) {\n\t\t\t\tfloat zv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv);\n\t\t\t\tshort blend[4] = {POLY_HWR_half, POLY_HWR_add, POLY_HWR_sub, POLY_HWR_qrt};\n\t\t\t\tInsertPoly_Gouraud(nPoints, zv, color->peRed, color->peGreen, color->peBlue, blend[color->peFlags - 1]);\n\t\t\t} else {\n\t\t\t\tDrawPoly_Gouraud(nPoints, color->peRed, color->peGreen, color->peBlue);\n\t\t\t}\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\t\tDrawPoly_Gouraud(nPoints, color->peRed, color->peGreen, color->peBlue);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t}\n\t}\n\n\treturn ptrObj;\n}\n\nvoid __cdecl InsertFlatRect_ZBuffered(int x0, int y0, int x1, int y1, int z, BYTE colorIdx) {\n\tdouble sz, rhw;\n\tD3DCOLOR color;\n\n\tif( x0 >= x1 || y0 >= y1 )\n\t\treturn;\n\n\tif( x0 < PhdWinMinX )\n\t\tx0 = PhdWinMinX;\n\tif( y0 < PhdWinMinY )\n\t\ty0 = PhdWinMinY;\n\tif( x1 > PhdWinMinX + PhdWinWidth )\n\t\tx1 = PhdWinMinX + PhdWinWidth;\n\tif( y1 > PhdWinMinY + PhdWinHeight )\n\t\tx1 = PhdWinMinY + PhdWinHeight;\n\n\tCLAMP(z, PhdNearZ, PhdFarZ);\n\n\tcolor = shadeColor(GamePalette8[colorIdx].red, GamePalette8[colorIdx].green, GamePalette8[colorIdx].blue, 0xFF, 0, false);\n\trhw = RhwFactor / (double)z;\n\tsz = FltResZBuf - rhw * FltResZORhw;\n\n\tVBufferD3D[0].sx = (float)x0;\n\tVBufferD3D[0].sy = (float)y0;\n\tVBufferD3D[1].sx = (float)x1;\n\tVBufferD3D[1].sy = (float)y0;\n\tVBufferD3D[2].sx = (float)x0;\n\tVBufferD3D[2].sy = (float)y1;\n\tVBufferD3D[3].sx = (float)x1;\n\tVBufferD3D[3].sy = (float)y1;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tVBufferD3D[i].sz = sz;\n\t\tVBufferD3D[i].rhw = rhw;\n\t\tVBufferD3D[i].color = color;\n\t}\n\n\tHWR_TexSource(0);\n\tHWR_EnableColorKey(false);\n\tHWR_DrawPrimitive(D3DPT_TRIANGLESTRIP, VBufferD3D, 4, true);\n}\n\nvoid __cdecl InsertLine_ZBuffered(int x0, int y0, int x1, int y1, int z, BYTE colorIdx) {\n\tdouble sz, rhw;\n\tD3DCOLOR color;\n\n\tif( z > PhdFarZ ) {\n\t\treturn;\n\t}\n\tif( z < PhdNearZ ) {\n\t\tz = PhdNearZ;\n\t}\n\n\tcolor = shadeColor(GamePalette8[colorIdx].red, GamePalette8[colorIdx].green, GamePalette8[colorIdx].blue, 0xFF, 0, false);\n\trhw = RhwFactor / (double)z;\n\tsz = FltResZBuf - rhw * FltResZORhw;\n\n\tVBufferD3D[0].sx = (float)(PhdWinMinX + x0);\n\tVBufferD3D[0].sy = (float)(PhdWinMinY + y0);\n\tVBufferD3D[1].sx = (float)(PhdWinMinX + x1);\n\tVBufferD3D[1].sy = (float)(PhdWinMinY + y1);\n\n\tfor( int i=0; i<2; ++i ) {\n\t\tVBufferD3D[i].sz = sz;\n\t\tVBufferD3D[i].rhw = rhw;\n\t\tVBufferD3D[i].color = color;\n\t}\n\n\tHWR_TexSource(0);\n\tHWR_EnableColorKey(false);\n\tHWR_DrawPrimitive(D3DPT_LINESTRIP, VBufferD3D, 2, true);\n}\n\nvoid __cdecl InsertGT3_Sorted(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2, PHD_TEXTURE *texture, PHD_UV *uv0, PHD_UV *uv1, PHD_UV *uv2, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tfloat zv;\n\tPOINT_INFO points[3];\n\tint nPoints = 3;\n\n\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip);\n\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip);\n\n\tif( clipAND != 0 )\n\t\treturn;\n\n\tif( clipOR >= 0 ) {\n\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\treturn;\n\n\t\tif( clipOR == 0 ) {\n\t\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv);\n\t\t\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\t\t\tSort3dPtr->_1 = MAKE_ZSORT(zv);\n\t\t\t++Sort3dPtr;\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t*Info3dPtr++ = GetPolyType(texture->drawtype);\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_HWR_GTmap : POLY_HWR_WGTmap;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t*Info3dPtr++ = texture->tpage;\n\t\t\t*Info3dPtr++ = 3;\n\t\t\t*(D3DTLVERTEX **)Info3dPtr = HWR_VertexPtr;\n\t\t\tInfo3dPtr += sizeof(D3DTLVERTEX *)/sizeof(__int16);\n\n\t\t\tHWR_VertexPtr[0].sx = vtx0->xs;\n\t\t\tHWR_VertexPtr[0].sy = vtx0->ys;\n\t\t\tHWR_VertexPtr[0].sz = FltResZBuf - FltResZORhw * vtx0->rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\t\tHWR_VertexPtr[0].rhw = vtx0->rhw;\n\t\t\tHWR_VertexPtr[0].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx0->g, true);\n\t\t\tHWR_VertexPtr[0].tu = (double)uv0->u / (double)PHD_ONE;\n\t\t\tHWR_VertexPtr[0].tv = (double)uv0->v / (double)PHD_ONE;\n\n\t\t\tHWR_VertexPtr[1].sx = vtx1->xs;\n\t\t\tHWR_VertexPtr[1].sy = vtx1->ys;\n\t\t\tHWR_VertexPtr[1].sz = FltResZBuf - FltResZORhw * vtx1->rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\t\tHWR_VertexPtr[1].rhw = vtx1->rhw;\n\t\t\tHWR_VertexPtr[1].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx1->g, true);\n\t\t\tHWR_VertexPtr[1].tu = (double)uv1->u / (double)PHD_ONE;\n\t\t\tHWR_VertexPtr[1].tv = (double)uv1->v / (double)PHD_ONE;\n\n\t\t\tHWR_VertexPtr[2].sx = vtx2->xs;\n\t\t\tHWR_VertexPtr[2].sy = vtx2->ys;\n\t\t\tHWR_VertexPtr[2].sz = FltResZBuf - FltResZORhw * vtx2->rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\t\tHWR_VertexPtr[2].rhw = vtx2->rhw;\n\t\t\tHWR_VertexPtr[2].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx2->g, true);\n\t\t\tHWR_VertexPtr[2].tu = (double)uv2->u / (double)PHD_ONE;\n\t\t\tHWR_VertexPtr[2].tv = (double)uv2->v / (double)PHD_ONE;\n\n\t\t\tHWR_VertexPtr += 3;\n\t\t\t++SurfaceCount;\n\t\t\treturn;\n\t\t}\n\n\t\tVBuffer[0].x = vtx0->xs;\n\t\tVBuffer[0].y = vtx0->ys;\n\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\tVBuffer[0].g = (double)vtx0->g;\n\t\tVBuffer[0].u = (double)uv0->u * vtx0->rhw;\n\t\tVBuffer[0].v = (double)uv0->v * vtx0->rhw;\n\n\t\tVBuffer[1].x = vtx1->xs;\n\t\tVBuffer[1].y = vtx1->ys;\n\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\tVBuffer[1].g = (double)vtx1->g;\n\t\tVBuffer[1].u = (double)uv1->u * vtx1->rhw;\n\t\tVBuffer[1].v = (double)uv1->v * vtx1->rhw;\n\n\t\tVBuffer[2].x = vtx2->xs;\n\t\tVBuffer[2].y = vtx2->ys;\n\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\tVBuffer[2].g = (double)vtx2->g;\n\t\tVBuffer[2].u = (double)uv2->u * vtx2->rhw;\n\t\tVBuffer[2].v = (double)uv2->v * vtx2->rhw;\n\t} else {\n\n\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\treturn;\n\n\t\tpoints[0].xv\t= vtx0->xv;\n\t\tpoints[0].yv\t= vtx0->yv;\n\t\tpoints[0].zv\t= vtx0->zv;\n\t\tpoints[0].rhw\t= vtx0->rhw;\n\t\tpoints[0].xs\t= vtx0->xs;\n\t\tpoints[0].ys\t= vtx0->ys;\n\t\tpoints[0].u\t\t= (float)uv0->u;\n\t\tpoints[0].v\t\t= (float)uv0->v;\n\t\tpoints[0].g\t\t= (float)vtx0->g;\n\n\t\tpoints[1].yv\t= vtx1->yv;\n\t\tpoints[1].xv\t= vtx1->xv;\n\t\tpoints[1].zv\t= vtx1->zv;\n\t\tpoints[1].rhw\t= vtx1->rhw;\n\t\tpoints[1].xs\t= vtx1->xs;\n\t\tpoints[1].ys\t= vtx1->ys;\n\t\tpoints[1].u\t\t= (float)uv1->u;\n\t\tpoints[1].v\t\t= (float)uv1->v;\n\t\tpoints[1].g\t\t= (float)vtx1->g;\n\n\t\tpoints[2].xv\t= vtx2->xv;\n\t\tpoints[2].yv\t= vtx2->yv;\n\t\tpoints[2].zv\t= vtx2->zv;\n\t\tpoints[2].rhw\t= vtx2->rhw;\n\t\tpoints[2].xs\t= vtx2->xs;\n\t\tpoints[2].ys\t= vtx2->ys;\n\t\tpoints[2].u\t\t= (float)uv2->u;\n\t\tpoints[2].v\t\t= (float)uv2->v;\n\t\tpoints[2].g\t\t= (float)vtx2->g;\n\n\t\tnPoints = ZedClipper(nPoints, points, VBuffer);\n\t\tif( nPoints == 0 ) return;\n\t}\n\n\tnPoints = XYGUVClipper(nPoints, VBuffer);\n\tif( nPoints == 0 ) return;\n\n\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tInsertClippedPoly_Textured(nPoints, zv, GetPolyType(texture->drawtype), texture->tpage);\n#else // FEATURE_VIDEOFX_IMPROVED\n\tInsertClippedPoly_Textured(nPoints, zv, ( texture->drawtype == DRAW_Opaque ) ? POLY_HWR_GTmap : POLY_HWR_WGTmap, texture->tpage);\n#endif // FEATURE_VIDEOFX_IMPROVED\n}\n\nvoid __cdecl InsertClippedPoly_Textured(int vtxCount, float z, __int16 polyType, __int16 texPage) {\n\tdouble tu, tv;\n\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = polyType;\n\t*(Info3dPtr++) = texPage;\n\t*(Info3dPtr++) = vtxCount;\n\t*(D3DTLVERTEX **)Info3dPtr = HWR_VertexPtr;\n\tInfo3dPtr += sizeof(D3DTLVERTEX *)/sizeof(__int16);\n\n\tfor( int i = 0; i < vtxCount; ++i ) {\n\t\ttu = VBuffer[i].u / double(PHD_ONE) / VBuffer[i].rhw;\n\t\ttv = VBuffer[i].v / double(PHD_ONE) / VBuffer[i].rhw;\n\t\tCLAMP(tu, 0.0, 1.0);\n\t\tCLAMP(tv, 0.0, 1.0);\n\n\t\tHWR_VertexPtr[i].sx = VBuffer[i].x;\n\t\tHWR_VertexPtr[i].sy = VBuffer[i].y;\n\t\tHWR_VertexPtr[i].sz = FltResZBuf - FltResZORhw * VBuffer[i].rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[i].rhw = VBuffer[i].rhw;\n\t\tHWR_VertexPtr[i].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, VBuffer[i].g, true);\n\t\tHWR_VertexPtr[i].tu = tu;\n\t\tHWR_VertexPtr[i].tv = tv;\n\t}\n\n\tHWR_VertexPtr += vtxCount;\n\t++SurfaceCount;\n}\n\nvoid __cdecl InsertGT4_Sorted(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2, PHD_VBUF *vtx3, PHD_TEXTURE *texture, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tfloat zv;\n\n\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip | vtx3->clip);\n\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip & vtx3->clip);\n\n\tif( clipAND != 0 )\n\t\treturn;\n\n\tif( clipOR == 0 && VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) ) {\n\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv, vtx3->zv);\n\t\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\t\tSort3dPtr->_1 = MAKE_ZSORT(zv);\n\t\t++Sort3dPtr;\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t*Info3dPtr++ = GetPolyType(texture->drawtype);\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\t*Info3dPtr++ = ( texture->drawtype == DRAW_Opaque ) ? POLY_HWR_GTmap : POLY_HWR_WGTmap;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t*Info3dPtr++ = texture->tpage;\n\t\t*Info3dPtr++ = 4;\n\t\t*(D3DTLVERTEX **)Info3dPtr = HWR_VertexPtr;\n\t\tInfo3dPtr += sizeof(D3DTLVERTEX *)/sizeof(__int16);\n\n\t\tHWR_VertexPtr[0].sx = vtx0->xs;\n\t\tHWR_VertexPtr[0].sy = vtx0->ys;\n\t\tHWR_VertexPtr[0].sz = FltResZBuf - FltResZORhw * vtx0->rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[0].rhw = vtx0->rhw;\n\t\tHWR_VertexPtr[0].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx0->g, true);\n\t\tHWR_VertexPtr[0].tu = (double)texture->uv[0].u / (double)PHD_ONE;\n\t\tHWR_VertexPtr[0].tv = (double)texture->uv[0].v / (double)PHD_ONE;\n\n\t\tHWR_VertexPtr[1].sx = vtx1->xs;\n\t\tHWR_VertexPtr[1].sy = vtx1->ys;\n\t\tHWR_VertexPtr[1].sz = FltResZBuf - FltResZORhw * vtx1->rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[1].rhw = vtx1->rhw;\n\t\tHWR_VertexPtr[1].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx1->g, true);\n\t\tHWR_VertexPtr[1].tu = (double)texture->uv[1].u / (double)PHD_ONE;\n\t\tHWR_VertexPtr[1].tv = (double)texture->uv[1].v / (double)PHD_ONE;\n\n\t\tHWR_VertexPtr[2].sx = vtx2->xs;\n\t\tHWR_VertexPtr[2].sy = vtx2->ys;\n\t\tHWR_VertexPtr[2].sz = FltResZBuf - FltResZORhw * vtx2->rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[2].rhw = vtx2->rhw;\n\t\tHWR_VertexPtr[2].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx2->g, true);\n\t\tHWR_VertexPtr[2].tu = (double)texture->uv[2].u / (double)PHD_ONE;\n\t\tHWR_VertexPtr[2].tv = (double)texture->uv[2].v / (double)PHD_ONE;\n\n\t\tHWR_VertexPtr[3].sx = vtx3->xs;\n\t\tHWR_VertexPtr[3].sy = vtx3->ys;\n\t\tHWR_VertexPtr[3].sz = FltResZBuf - FltResZORhw * vtx3->rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[3].rhw = vtx3->rhw;\n\t\tHWR_VertexPtr[3].color = shadeColor(0xFF, 0xFF, 0xFF, 0xFF, vtx3->g, true);\n\t\tHWR_VertexPtr[3].tu = (double)texture->uv[3].u / (double)PHD_ONE;\n\t\tHWR_VertexPtr[3].tv = (double)texture->uv[3].v / (double)PHD_ONE;\n\n\t\tHWR_VertexPtr += 4;\n\t\t++SurfaceCount;\n\t}\n\telse if( (clipOR < 0 && visible_zclip(vtx0, vtx1, vtx2)) ||\n\t\t\t (clipOR > 0 && VBUF_VISIBLE(*vtx0, *vtx1, *vtx2)) )\n\t{\n\t\tInsertGT3_Sorted(vtx0, vtx1, vtx2, texture, texture->uv, &texture->uv[1], &texture->uv[2], sortType);\n\t\tInsertGT3_Sorted(vtx0, vtx2, vtx3, texture, texture->uv, &texture->uv[2], &texture->uv[3], sortType);\n\t}\n}\n\n__int16 *__cdecl InsertObjectGT4_Sorted(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tPHD_VBUF *vtx0, *vtx1, *vtx2, *vtx3;\n\tPHD_TEXTURE *texture;\n\n\tfor( int i = 0; i < number; ++i ) {\n\t\tif( HWR_VertexBufferFull() ) {\n\t\t\tptrObj += (number - i) * 5;\n\t\t\tbreak;\n\t\t}\n\n\t\tvtx0 = &PhdVBuf[ptrObj[0]];\n\t\tvtx1 = &PhdVBuf[ptrObj[1]];\n\t\tvtx2 = &PhdVBuf[ptrObj[2]];\n\t\tvtx3 = &PhdVBuf[ptrObj[3]];\n\t\ttexture = &PhdTextureInfo[ptrObj[4]];\n\t\tptrObj += 5;\n\n\t\tInsertGT4_Sorted(vtx0, vtx1, vtx2, vtx3, texture, sortType);\n\t}\n\treturn ptrObj;\n}\n\n__int16 *__cdecl InsertObjectGT3_Sorted(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tPHD_VBUF *vtx0, *vtx1, *vtx2;\n\tPHD_TEXTURE *texture;\n\tPHD_UV *uv;\n\n\tfor( int i = 0; i < number; ++i ) {\n\t\tif( HWR_VertexBufferFull() ) {\n\t\t\tptrObj += (number - i) * 4;\n\t\t\tbreak;\n\t\t}\n\n\t\tvtx0 = &PhdVBuf[ptrObj[0]];\n\t\tvtx1 = &PhdVBuf[ptrObj[1]];\n\t\tvtx2 = &PhdVBuf[ptrObj[2]];\n\t\ttexture = &PhdTextureInfo[ptrObj[3]];\n\t\tuv = texture->uv;\n\t\tptrObj += 4;\n\n\t\tInsertGT3_Sorted(vtx0, vtx1, vtx2, texture, &uv[0], &uv[1], &uv[2], sortType);\n\t}\n\treturn ptrObj;\n}\n\n__int16 *__cdecl InsertObjectG4_Sorted(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tPHD_VBUF *vtx0, *vtx1, *vtx2, *vtx3;\n\tint i, nPoints;\n\tfloat zv;\n\t__int16 colorIdx;\n\tPALETTEENTRY *color;\n\tPOINT_INFO pts[4];\n\n\tfor( i = 0; i < number; ++i ) {\n\t\tif( HWR_VertexBufferFull() ) {\n\t\t\tptrObj += number - i;\n\t\t\tbreak;\n\t\t}\n\n\t\tvtx0 = &PhdVBuf[*ptrObj++];\n\t\tvtx1 = &PhdVBuf[*ptrObj++];\n\t\tvtx2 = &PhdVBuf[*ptrObj++];\n\t\tvtx3 = &PhdVBuf[*ptrObj++];\n\t\tcolorIdx = *ptrObj++;\n\t\tnPoints = 4;\n\n\t\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip | vtx3->clip);\n\t\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip & vtx3->clip);\n\n\t\tif( clipAND != 0 )\n\t\t\tcontinue;\n\n\t\tif( clipOR >= 0 ) {\n\t\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tVBuffer[0].x = vtx0->xs;\n\t\t\tVBuffer[0].y = vtx0->ys;\n\t\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\t\tVBuffer[0].g = (float)vtx0->g;\n\n\t\t\tVBuffer[1].x = vtx1->xs;\n\t\t\tVBuffer[1].y = vtx1->ys;\n\t\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\t\tVBuffer[1].g = (float)vtx1->g;\n\n\t\t\tVBuffer[2].x = vtx2->xs;\n\t\t\tVBuffer[2].y = vtx2->ys;\n\t\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\t\tVBuffer[2].g = (float)vtx2->g;\n\n\t\t\tVBuffer[3].x = vtx3->xs;\n\t\t\tVBuffer[3].y = vtx3->ys;\n\t\t\tVBuffer[3].rhw = vtx3->rhw;\n\t\t\tVBuffer[3].g = (float)vtx3->g;\n\n\t\t\tif( clipOR > 0 ) {\n\t\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t\t}\n\t\t} else {\n\t\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tpts[0].xv = vtx0->xv;\n\t\t\tpts[0].yv = vtx0->yv;\n\t\t\tpts[0].zv = vtx0->zv;\n\t\t\tpts[0].rhw = vtx0->rhw;\n\t\t\tpts[0].xs = vtx0->xs;\n\t\t\tpts[0].ys = vtx0->ys;\n\t\t\tpts[0].g = (float)vtx0->g;\n\n\t\t\tpts[1].xv = vtx1->xv;\n\t\t\tpts[1].yv = vtx1->yv;\n\t\t\tpts[1].zv = vtx1->zv;\n\t\t\tpts[1].rhw = vtx1->rhw;\n\t\t\tpts[1].xs = vtx1->xs;\n\t\t\tpts[1].ys = vtx1->ys;\n\t\t\tpts[1].g = (float)vtx1->g;\n\n\t\t\tpts[2].xv = vtx2->xv;\n\t\t\tpts[2].yv = vtx2->yv;\n\t\t\tpts[2].zv = vtx2->zv;\n\t\t\tpts[2].rhw = vtx2->rhw;\n\t\t\tpts[2].xs = vtx2->xs;\n\t\t\tpts[2].ys = vtx2->ys;\n\t\t\tpts[2].g = (float)vtx2->g;\n\n\t\t\tpts[3].xv = vtx3->xv;\n\t\t\tpts[3].yv = vtx3->yv;\n\t\t\tpts[3].zv = vtx3->zv;\n\t\t\tpts[3].rhw = vtx3->rhw;\n\t\t\tpts[3].xs = vtx3->xs;\n\t\t\tpts[3].ys = vtx3->ys;\n\t\t\tpts[3].g = (float)vtx3->g;\n\n\t\t\tnPoints = ZedClipper(nPoints, pts, VBuffer);\n\t\t\tif( nPoints == 0 ) continue;\n\n\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t}\n\n\t\tif( nPoints == 0 )\n\t\t\tcontinue;\n\n\t\tcolor = &GamePalette16[colorIdx >> 8];\n\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv, vtx3->zv);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tif( AlphaBlendMode && color->peFlags > 0 && color->peFlags <= 4 ) {\n\t\t\tshort blend[4] = {POLY_HWR_half, POLY_HWR_add, POLY_HWR_sub, POLY_HWR_qrt};\n\t\t\tInsertPoly_Gouraud(nPoints, zv, color->peRed, color->peGreen, color->peBlue, blend[color->peFlags - 1]);\n\t\t} else {\n\t\t\tInsertPoly_Gouraud(nPoints, zv, color->peRed, color->peGreen, color->peBlue, POLY_HWR_gouraud);\n\t\t}\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\tInsertPoly_Gouraud(nPoints, zv, color->peRed, color->peGreen, color->peBlue, POLY_HWR_gouraud);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t}\n\n\treturn ptrObj;\n}\n\nvoid __cdecl InsertPoly_Gouraud(int vtxCount, float z, int red, int green, int blue, __int16 polyType) {\n\tBYTE alpha = ( polyType == POLY_HWR_trans ) ? 0x80 : 0xFF;\n\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = polyType;\n\t*(Info3dPtr++) = vtxCount;\n\t*(D3DTLVERTEX **)Info3dPtr = HWR_VertexPtr;\n\tInfo3dPtr += sizeof(D3DTLVERTEX *)/sizeof(__int16);\n\n\tfor( int i = 0; i < vtxCount; ++i ) {\n\t\tHWR_VertexPtr[i].sx = VBuffer[i].x;\n\t\tHWR_VertexPtr[i].sy = VBuffer[i].y;\n\t\tHWR_VertexPtr[i].sz = FltResZBuf - FltResZORhw * VBuffer[i].rhw; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[i].rhw = VBuffer[i].rhw;\n\t\tHWR_VertexPtr[i].color = shadeColor(red, green, blue, alpha, VBuffer[i].g, false);\n\t}\n\n\tHWR_VertexPtr += vtxCount;\n\t++SurfaceCount;\n}\n\n__int16 *__cdecl InsertObjectG3_Sorted(__int16 *ptrObj, int number, SORTTYPE sortType) {\n\tchar clipOR, clipAND;\n\tPHD_VBUF *vtx0, *vtx1, *vtx2;\n\tint i, nPoints;\n\tfloat zv;\n\t__int16 colorIdx;\n\tPALETTEENTRY *color;\n\tPOINT_INFO pts[3];\n\n\tfor( i = 0; i < number; ++i ) {\n\t\tif( HWR_VertexBufferFull() ) {\n\t\t\tptrObj += number - i;\n\t\t\tbreak;\n\t\t}\n\n\t\tvtx0 = &PhdVBuf[*ptrObj++];\n\t\tvtx1 = &PhdVBuf[*ptrObj++];\n\t\tvtx2 = &PhdVBuf[*ptrObj++];\n\t\tcolorIdx = *ptrObj++;\n\t\tnPoints = 3;\n\n\t\tclipOR  = LOBYTE(vtx0->clip | vtx1->clip | vtx2->clip);\n\t\tclipAND = LOBYTE(vtx0->clip & vtx1->clip & vtx2->clip);\n\n\t\tif( clipAND != 0 )\n\t\t\tcontinue;\n\n\t\tif( clipOR >= 0 ) {\n\t\t\tif( !VBUF_VISIBLE(*vtx0, *vtx1, *vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tVBuffer[0].x = vtx0->xs;\n\t\t\tVBuffer[0].y = vtx0->ys;\n\t\t\tVBuffer[0].rhw = vtx0->rhw;\n\t\t\tVBuffer[0].g = (float)vtx0->g;\n\n\t\t\tVBuffer[1].x = vtx1->xs;\n\t\t\tVBuffer[1].y = vtx1->ys;\n\t\t\tVBuffer[1].rhw = vtx1->rhw;\n\t\t\tVBuffer[1].g = (float)vtx1->g;\n\n\t\t\tVBuffer[2].x = vtx2->xs;\n\t\t\tVBuffer[2].y = vtx2->ys;\n\t\t\tVBuffer[2].rhw = vtx2->rhw;\n\t\t\tVBuffer[2].g = (float)vtx2->g;\n\n\t\t\tif( clipOR > 0 ) {\n\t\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t\t}\n\t\t} else {\n\t\t\tif( !visible_zclip(vtx0, vtx1, vtx2) )\n\t\t\t\tcontinue;\n\n\t\t\tpts[0].xv = vtx0->xv;\n\t\t\tpts[0].yv = vtx0->yv;\n\t\t\tpts[0].zv = vtx0->zv;\n\t\t\tpts[0].rhw = vtx0->rhw;\n\t\t\tpts[0].xs = vtx0->xs;\n\t\t\tpts[0].ys = vtx0->ys;\n\t\t\tpts[0].g = (float)vtx0->g;\n\n\t\t\tpts[1].xv = vtx1->xv;\n\t\t\tpts[1].yv = vtx1->yv;\n\t\t\tpts[1].zv = vtx1->zv;\n\t\t\tpts[1].rhw = vtx1->rhw;\n\t\t\tpts[1].xs = vtx1->xs;\n\t\t\tpts[1].ys = vtx1->ys;\n\t\t\tpts[1].g = (float)vtx1->g;\n\n\t\t\tpts[2].xv = vtx2->xv;\n\t\t\tpts[2].yv = vtx2->yv;\n\t\t\tpts[2].zv = vtx2->zv;\n\t\t\tpts[2].rhw = vtx2->rhw;\n\t\t\tpts[2].xs = vtx2->xs;\n\t\t\tpts[2].ys = vtx2->ys;\n\t\t\tpts[2].g = (float)vtx2->g;\n\n\t\t\tnPoints = ZedClipper(nPoints, pts, VBuffer);\n\t\t\tif( nPoints == 0 ) continue;\n\n\t\t\tnPoints = XYGClipper(nPoints, VBuffer);\n\t\t}\n\n\t\tif( nPoints == 0 )\n\t\t\tcontinue;\n\n\t\tcolor = &GamePalette16[colorIdx >> 8];\n\t\tzv = CalculatePolyZ(sortType, vtx0->zv, vtx1->zv, vtx2->zv);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tif( AlphaBlendMode && color->peFlags > 0 && color->peFlags <= 4 ) {\n\t\t\tshort blend[4] = {POLY_HWR_half, POLY_HWR_add, POLY_HWR_sub, POLY_HWR_qrt};\n\t\t\tInsertPoly_Gouraud(nPoints, zv, color->peRed, color->peGreen, color->peBlue, blend[color->peFlags - 1]);\n\t\t} else {\n\t\t\tInsertPoly_Gouraud(nPoints, zv, color->peRed, color->peGreen, color->peBlue, POLY_HWR_gouraud);\n\t\t}\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\tInsertPoly_Gouraud(nPoints, zv, color->peRed, color->peGreen, color->peBlue, POLY_HWR_gouraud);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t}\n\n\treturn ptrObj;\n}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertSprite_Sorted(int z, int x0, int y0, int x1, int y1, int spriteIdx, __int16 shade, DWORD flags) {\n\tif( TextureFormat.bpp < 16 && CHK_ANY(flags, SPR_TINT) ) return; // tinted sprites are not supported for 8 bit textured mode\n#else // FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertSprite_Sorted(int z, int x0, int y0, int x1, int y1, int spriteIdx, __int16 shade) {\n#endif // FEATURE_VIDEOFX_IMPROVED\n\tdouble rhw, u0, v0, u1, v1;\n\tint uOffset, vOffset, nPoints;\n\n\tif( HWR_VertexBufferFull() || x0 >= x1 || y0 >= y1 || x1 <= 0 || y1 <= 0  || x0 >= PhdWinMaxX || y0 >= PhdWinMaxY || z >= PhdFarZ )\n\t\treturn;\n\n\tx0 += PhdWinMinX;\n\ty0 += PhdWinMinY;\n\tx1 += PhdWinMinX;\n\ty1 += PhdWinMinY;\n\n\tif( z < PhdNearZ )\n\t\tz = PhdNearZ;\n\n\trhw = RhwFactor / (double)z;\n\n\tuOffset = LOBYTE(PhdSpriteInfo[spriteIdx].offset) * 256;\n\tvOffset = HIBYTE(PhdSpriteInfo[spriteIdx].offset) * 256;\n\n\t// NOTE: page side is not counted in the original game, but we need it for HD textures\n\tint adjustment = UvAdd * 256 / GetTextureSideByPage(PhdSpriteInfo[spriteIdx].texPage);\n#if (DIRECT3D_VERSION >= 0x900)\n\tdouble forcedAdjust = GetTexPagesAdjustment();\n\tif( forcedAdjust > 0.0) {\n\t\tadjustment = (int)(forcedAdjust * 256.0);\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n#ifdef FEATURE_HUD_IMPROVED\n\tif( spriteIdx >= (int)ARRAY_SIZE(PhdSpriteInfo) - HUD_SPRITE_RESERVED ) {\n\t\tadjustment = 0;\n\t}\n#endif // FEATURE_HUD_IMPROVED\n\tCLAMPL(adjustment, 1);\n\n\tu0 = rhw * (double)(uOffset - adjustment + PhdSpriteInfo[spriteIdx].width);\n\tv0 = rhw * (double)(vOffset + adjustment);\n\n\tu1 = rhw * (double)(uOffset + adjustment);\n\tv1 = rhw * (double)(vOffset - adjustment + PhdSpriteInfo[spriteIdx].height);\n\n\tVBuffer[0].x = (float)x0;\n\tVBuffer[0].y = (float)y0;\n\tVBuffer[0].u = u1;\n\tVBuffer[0].v = v0;\n\tVBuffer[1].x = (float)x1;\n\tVBuffer[1].y = (float)y0;\n\tVBuffer[1].u = u0;\n\tVBuffer[1].v = v0;\n\tVBuffer[2].x = (float)x1;\n\tVBuffer[2].y = (float)y1;\n\tVBuffer[2].u = u0;\n\tVBuffer[2].v = v1;\n\tVBuffer[3].x = (float)x0;\n\tVBuffer[3].y = (float)y1;\n\tVBuffer[3].u = u1;\n\tVBuffer[3].v = v1;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tVBuffer[i].rhw = rhw;\n\t\tVBuffer[i].g = (float)shade;\n\t}\n\n\tnPoints = 4;\n\n\tif( x0 < PhdWinMinX || y0 < PhdWinMinY || x1 > PhdWinWidth + PhdWinMinX || y1 > PhdWinHeight + PhdWinMinY ) {\n\t\tFltWinLeft = (float)PhdWinMinX;\n\t\tFltWinTop  = (float)PhdWinMinY;\n\t\tFltWinRight  = (float)(PhdWinMinX + PhdWinWidth);\n\t\tFltWinBottom = (float)(PhdWinMinY + PhdWinHeight);\n\t\tnPoints = XYGUVClipper(nPoints, VBuffer);\n\t\tif( nPoints == 0 ) return;\n\t}\n\n\tbool isShadeEffectBackup = IsShadeEffect;\n\tIsShadeEffect = false;\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tshort polyType = POLY_HWR_WGTmap;\n\tif( CHK_ANY(flags, SPR_TINT) ) {\n\t\tGlobalTint = RGBA_SETALPHA(flags, 0xFF);\n\t}\n\tif( AlphaBlendMode && CHK_ANY(flags, SPR_SEMITRANS) ) {\n\t\tshort blend[4] = {\n\t\t\tPOLY_HWR_WGTmapHalf,\n\t\t\tPOLY_HWR_WGTmapAdd,\n\t\t\tPOLY_HWR_WGTmapSub,\n\t\t\tPOLY_HWR_WGTmapQrt,\n\t\t};\n\t\tpolyType = blend[(flags & SPR_BLEND) >> 29];\n\t}\n\tInsertClippedPoly_Textured(nPoints, (float)z, polyType, PhdSpriteInfo[spriteIdx].texPage);\n\tGlobalTint = 0;\n#else // FEATURE_VIDEOFX_IMPROVED\n\tInsertClippedPoly_Textured(nPoints, (float)z, POLY_HWR_WGTmap, PhdSpriteInfo[spriteIdx].texPage);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\tIsShadeEffect = isShadeEffectBackup;\n}\n\nvoid __cdecl InsertFlatRect_Sorted(int x0, int y0, int x1, int y1, int z, BYTE colorIdx) {\n\tdouble rhw, sz;\n\tD3DCOLOR color;\n\n\tif( x0 >= x1 || y0 >= y1 )\n\t\treturn;\n\n\tif( x0 < PhdWinMinX )\n\t\tx0 = PhdWinMinX;\n\tif( y0 < PhdWinMinY )\n\t\ty0 = PhdWinMinY;\n\tif( x1 > PhdWinMinX + PhdWinWidth )\n\t\tx1 = PhdWinMinX + PhdWinWidth;\n\tif( y1 > PhdWinMinY + PhdWinHeight )\n\t\tx1 = PhdWinMinY + PhdWinHeight;\n\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_HWR_gouraud;\n\t*(Info3dPtr++) = 4; //  vertex count\n\t*(D3DTLVERTEX **)Info3dPtr = HWR_VertexPtr;\n\tInfo3dPtr += sizeof(D3DTLVERTEX *)/sizeof(__int16);\n\n\tcolor = shadeColor(GamePalette8[colorIdx].red, GamePalette8[colorIdx].green, GamePalette8[colorIdx].blue, 0xFF, 0, false);\n\trhw = RhwFactor / (double)z;\n\tsz = FltResZBuf - rhw * FltResZORhw;\n\n\tHWR_VertexPtr[0].sx = (float)x0;\n\tHWR_VertexPtr[0].sy = (float)y0;\n\tHWR_VertexPtr[1].sx = (float)x1;\n\tHWR_VertexPtr[1].sy = (float)y0;\n\tHWR_VertexPtr[2].sx = (float)x1;\n\tHWR_VertexPtr[2].sy = (float)y1;\n\tHWR_VertexPtr[3].sx = (float)x0;\n\tHWR_VertexPtr[3].sy = (float)y1;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tHWR_VertexPtr[i].color = color;\n\t\tHWR_VertexPtr[i].sz = sz; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[i].rhw = rhw;\n\t}\n\n\tHWR_VertexPtr += 4;\n\t++SurfaceCount;\n}\n\nvoid __cdecl InsertLine_Sorted(int x0, int y0, int x1, int y1, int z, BYTE colorIdx) {\n\tdouble rhw, sz;\n\tD3DCOLOR color;\n\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_HWR_line;\n\t*(Info3dPtr++) = 2; //  vertex count\n\t*(D3DTLVERTEX **)Info3dPtr = HWR_VertexPtr;\n\tInfo3dPtr += sizeof(D3DTLVERTEX *)/sizeof(__int16);\n\n\tcolor = shadeColor(GamePalette8[colorIdx].red, GamePalette8[colorIdx].green, GamePalette8[colorIdx].blue, 0xFF, 0, false);\n\trhw = RhwFactor / (double)z;\n\tsz = FltResZBuf - rhw * FltResZORhw;\n\n\tHWR_VertexPtr[0].sx = (float)(PhdWinMinX + x0);\n\tHWR_VertexPtr[0].sy = (float)(PhdWinMinY + y0);\n\tHWR_VertexPtr[1].sx = (float)(PhdWinMinX + x1);\n\tHWR_VertexPtr[1].sy = (float)(PhdWinMinY + y1);\n\n\tfor( int i=0; i<2; ++i ) {\n\t\tHWR_VertexPtr[i].color = color;\n\t\tHWR_VertexPtr[i].sz = sz; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[i].rhw = rhw;\n\t}\n\n\tHWR_VertexPtr += 2;\n\t++SurfaceCount;\n}\n\nvoid __cdecl InsertTrans8_Sorted(PHD_VBUF *vbuf, __int16 shade) {\n\tint i, nPoints, polyZ;\n\tchar clipOR = 0x00;\n\tchar clipAND = 0xFF;\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tint nVtx = ( ShadowMode == 1 ) ? 32 : 8;\n#else // FEATURE_VIDEOFX_IMPROVED\n\tint nVtx = 8;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tfor( i = 0; i < nVtx; ++i ) {\n\t\tclipOR  |= LOBYTE(vbuf[i].clip);\n\t\tclipAND &= LOBYTE(vbuf[i].clip);\n\t}\n\n\tif( (clipOR < 0) || (clipAND != 0) || !VBUF_VISIBLE(vbuf[0], vbuf[1], vbuf[2]) )\n\t\treturn;\n\n\tfor( i = 0; i < nVtx; ++i ) {\n\t\tVBuffer[i].x = vbuf[i].xs;\n\t\tVBuffer[i].y = vbuf[i].ys;\n\t\tVBuffer[i].rhw = RhwFactor / (double)(vbuf[i].zv - 0x20000);\n\t}\n\n\tnPoints = nVtx;\n\n\tif( clipOR != 0 ) {\n\t\tFltWinLeft = 0.0;\n\t\tFltWinTop = 0.0;\n\t\tFltWinRight = (float)PhdWinMaxX;\n\t\tFltWinBottom = (float)PhdWinMaxY;\n\n\t\tnPoints = XYClipper(nPoints, VBuffer);\n\t\tif( nPoints == 0) return;\n\t}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tdouble polyZflt = 0.0;\n\tfor( i = 0; i < nVtx; ++i ) {\n\t\tpolyZflt += (double)vbuf[i].zv / (double)nVtx;\n\t}\n\tpolyZ = polyZflt;\n#else // FEATURE_VIDEOFX_IMPROVED\n\tpolyZ = 0;\n\tfor( i = 0; i < nVtx; ++i ) {\n\t\tpolyZ += vbuf[i].zv;\n\t}\n\tpolyZ /= nVtx;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tInsertPoly_Gouraud(nPoints, (float)(polyZ - 0x20000), 0, 0, 0, POLY_HWR_trans);\n}\n\nvoid __cdecl InsertTransQuad_Sorted(int x, int y, int width, int height, int z) {\n\tfloat x0, y0, x1, y1;\n\tdouble rhw, sz;\n\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_HWR_trans;\n\t*(Info3dPtr++) = 4; //  vertex count\n\t*(D3DTLVERTEX **)Info3dPtr = HWR_VertexPtr;\n\tInfo3dPtr += sizeof(D3DTLVERTEX *)/sizeof(__int16);\n\n\tx0 = (float)x;\n\ty0 = (float)y;\n\tx1 = (float)(x + width);\n\ty1 = (float)(y + height);\n\n\trhw = RhwFactor / (double)z;\n\tsz = FltResZBuf - rhw * FltResZORhw;\n\n\tHWR_VertexPtr[0].sx = x0;\n\tHWR_VertexPtr[0].sy = y0;\n\tHWR_VertexPtr[1].sx = x1;\n\tHWR_VertexPtr[1].sy = y0;\n\tHWR_VertexPtr[2].sx = x1;\n\tHWR_VertexPtr[2].sy = y1;\n\tHWR_VertexPtr[3].sx = x0;\n\tHWR_VertexPtr[3].sy = y1;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tHWR_VertexPtr[i].color = 0x80000000; // half transparent black\n\t\tHWR_VertexPtr[i].sz = sz; // NOTE: there was bug because of uninitialized sz and rhw\n\t\tHWR_VertexPtr[i].rhw = rhw;\n\t}\n\n\tHWR_VertexPtr += 4;\n\t++SurfaceCount;\n}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertSprite(int z, int x0, int y0, int x1, int y1, int spriteIdx, __int16 shade, DWORD flags) {\n\tif( CHK_ANY(flags, SPR_TINT) ) return; // tinted sprites are not supported by software renderer yet\n#else // FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertSprite(int z, int x0, int y0, int x1, int y1, int spriteIdx, __int16 shade) {\n#endif // FEATURE_VIDEOFX_IMPROVED\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = MAKE_ZSORT(z);\n\t++Sort3dPtr;\n\n\t*(Info3dPtr++) = POLY_sprite;\n\t*(Info3dPtr++) = x0;\n\t*(Info3dPtr++) = y0;\n\t*(Info3dPtr++) = x1;\n\t*(Info3dPtr++) = y1;\n\t*(Info3dPtr++) = spriteIdx;\n\t*(Info3dPtr++) = shade;\n\n\t++SurfaceCount;\n}\n\n/*\n * Inject function\n */\nvoid Inject_3Dinsert() {\n\tINJECT(0x00405840, visible_zclip);\n\tINJECT(0x004058B0, ZedClipper);\n\tINJECT(0x004059F0, XYGUVClipper);\n\tINJECT(0x00405F10, InsertObjectGT4);\n\tINJECT(0x00406970, InsertObjectGT3);\n\tINJECT(0x004071F0, XYGClipper);\n\tINJECT(0x00407620, InsertObjectG4);\n\tINJECT(0x00407A00, InsertObjectG3);\n\tINJECT(0x00407D20, XYClipper);\n\tINJECT(0x00407FF0, InsertTrans8);\n\tINJECT(0x004084A0, InsertTransQuad);\n\tINJECT(0x00408580, InsertFlatRect);\n\tINJECT(0x00408650, InsertLine);\n\tINJECT(0x00408710, InsertGT3_ZBuffered);\n\tINJECT(0x00408D60, DrawClippedPoly_Textured);\n\tINJECT(0x00408EA0, InsertGT4_ZBuffered);\n\tINJECT(0x004092E0, InsertObjectGT4_ZBuffered);\n\tINJECT(0x00409380, InsertObjectGT3_ZBuffered);\n\tINJECT(0x00409430, InsertObjectG4_ZBuffered);\n\tINJECT(0x004097D0, DrawPoly_Gouraud);\n\tINJECT(0x004098D0, InsertObjectG3_ZBuffered);\n\tINJECT(0x00409BB0, InsertFlatRect_ZBuffered);\n\tINJECT(0x00409D80, InsertLine_ZBuffered);\n\tINJECT(0x00409EC0, InsertGT3_Sorted);\n\tINJECT(0x0040A5D0, InsertClippedPoly_Textured);\n\tINJECT(0x0040A780, InsertGT4_Sorted);\n\tINJECT(0x0040AC60, InsertObjectGT4_Sorted);\n\tINJECT(0x0040ACF0, InsertObjectGT3_Sorted);\n\tINJECT(0x0040AD90, InsertObjectG4_Sorted);\n\tINJECT(0x0040B1D0, InsertPoly_Gouraud);\n\tINJECT(0x0040B350, InsertObjectG3_Sorted);\n\tINJECT(0x0040B6A0, InsertSprite_Sorted);\n\tINJECT(0x0040B9F0, InsertFlatRect_Sorted);\n\tINJECT(0x0040BB70, InsertLine_Sorted);\n\tINJECT(0x0040BCA0, InsertTrans8_Sorted);\n\tINJECT(0x0040BE40, InsertTransQuad_Sorted);\n\tINJECT(0x0040BF80, InsertSprite);\n}\n"
  },
  {
    "path": "3dsystem/3dinsert.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef _3DINSERT_H_INCLUDED\n#define _3DINSERT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#ifdef FEATURE_VIDEOFX_IMPROVED\nbool InsertObjectEM(__int16 *ptrObj, int vtxCount, D3DCOLOR tint, PHD_UV *em_uv);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n// NOTE: this function is not presented in the original game\nvoid InsertGourQuad(int x0, int y0, int x1, int y1, int z, D3DCOLOR color0, D3DCOLOR color1, D3DCOLOR color2, D3DCOLOR color3);\n\nBOOL __cdecl visible_zclip(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2); // 0x00405840\nint __cdecl ZedClipper(int vtxCount, POINT_INFO *pts, VERTEX_INFO *vtx); // 0x004058B0\nint __cdecl XYGUVClipper(int vtxCount, VERTEX_INFO *vtx); // 0x004059F0\n__int16 *__cdecl InsertObjectGT4(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x00405F10\n__int16 *__cdecl InsertObjectGT3(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x00406970\nint __cdecl XYGClipper(int vtxCount, VERTEX_INFO *vtx); // 0x004071F0\n__int16 *__cdecl InsertObjectG4(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x00407620\n__int16 *__cdecl InsertObjectG3(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x00407A00\nint __cdecl XYClipper(int vtxCount, VERTEX_INFO *vtx); // 0x00407D20\nvoid __cdecl InsertTrans8(PHD_VBUF *vbuf, __int16 shade); // 0x00407FF0\nvoid __cdecl InsertTransQuad(int x, int y, int width, int height, int z); // 0x004084A0\nvoid __cdecl InsertFlatRect(int x0, int y0, int x1, int y1, int z, BYTE colorIdx); // 0x00408580\nvoid __cdecl InsertLine(int x0, int y0, int x1, int y1, int z, BYTE colorIdx); // 0x00408650\nvoid __cdecl InsertGT3_ZBuffered(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2, PHD_TEXTURE *texture, PHD_UV *uv0, PHD_UV *uv1, PHD_UV *uv2); // 0x00408710\nvoid __cdecl DrawClippedPoly_Textured(int vtxCount); // 0x00408D60\nvoid __cdecl InsertGT4_ZBuffered(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2, PHD_VBUF *vtx3, PHD_TEXTURE *texture); // 0x00408EA0\n__int16 *__cdecl InsertObjectGT4_ZBuffered(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x004092E0\n__int16 *__cdecl InsertObjectGT3_ZBuffered(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x00409380\n__int16 *__cdecl InsertObjectG4_ZBuffered(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x00409430\nvoid __cdecl DrawPoly_Gouraud(int vtxCount, int red, int green, int blue); // 0x004097D0\n__int16 *__cdecl InsertObjectG3_ZBuffered(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x004098D0\nvoid __cdecl InsertFlatRect_ZBuffered(int x0, int y0, int x1, int y1, int z, BYTE colorIdx); // 0x00409BB0\nvoid __cdecl InsertLine_ZBuffered(int x0, int y0, int x1, int y1, int z, BYTE colorIdx); // 0x00409D80\nvoid __cdecl InsertGT3_Sorted(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2, PHD_TEXTURE *texture, PHD_UV *uv0, PHD_UV *uv1, PHD_UV *uv2, SORTTYPE sortType); // 0x00409EC0\nvoid __cdecl InsertClippedPoly_Textured(int vtxCount, float z, __int16 polyType, __int16 texPage); // 0x0040A5D0\nvoid __cdecl InsertGT4_Sorted(PHD_VBUF *vtx0, PHD_VBUF *vtx1, PHD_VBUF *vtx2, PHD_VBUF *vtx3, PHD_TEXTURE *texture, SORTTYPE sortType); // 0x0040A780\n__int16 *__cdecl InsertObjectGT4_Sorted(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x0040AC60\n__int16 *__cdecl InsertObjectGT3_Sorted(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x0040ACF0\n__int16 *__cdecl InsertObjectG4_Sorted(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x0040AD90\nvoid __cdecl InsertPoly_Gouraud(int vtxCount, float z, int red, int green, int blue, __int16 polyType); // 0x0040B1D0\n__int16 *__cdecl InsertObjectG3_Sorted(__int16 *ptrObj, int number, SORTTYPE sortType); // 0x0040B350\n#ifdef FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertSprite_Sorted(int z, int x0, int y0, int x1, int y1, int spriteIdx, __int16 shade, DWORD flags); // 0x0040B6A0\n#else // FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertSprite_Sorted(int z, int x0, int y0, int x1, int y1, int spriteIdx, __int16 shade); // 0x0040B6A0\n#endif // FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertFlatRect_Sorted(int x0, int y0, int x1, int y1, int z, BYTE colorIdx); // 0x0040B9F0\nvoid __cdecl InsertLine_Sorted(int x0, int y0, int x1, int y1, int z, BYTE colorIdx); // 0x0040BB70\nvoid __cdecl InsertTrans8_Sorted(PHD_VBUF *vbuf, __int16 shade); // 0x0040BCA0\nvoid __cdecl InsertTransQuad_Sorted(int x, int y, int width, int height, int z); // 0x0040BE40\n#ifdef FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertSprite(int z, int x0, int y0, int x1, int y1, int spriteIdx, __int16 shade, DWORD flags); // 0x0040BF80\n#else // FEATURE_VIDEOFX_IMPROVED\nvoid __cdecl InsertSprite(int z, int x0, int y0, int x1, int y1, int spriteIdx, __int16 shade); // 0x0040BF80\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n#endif // _3DINSERT_H_INCLUDED\n"
  },
  {
    "path": "3dsystem/phd_math.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"global/vars.h\"\n\n// Arctan base table\nstatic int AtanBaseTable[8] = {\n\t 0x0000,\n\t-0x4000,\n\t-0xFFFF,\n\t 0xC000,\n\t-0x8000,\n\t 0x4000,\n\t 0x8000,\n\t-0xC000,\n};\n\n// Arctan angle table\nstatic __int16 AtanAngleTable[0x802] = {\n\t0x0000, 0x0005, 0x000A, 0x000F, 0x0014, 0x0019, 0x001F, 0x0024,\n\t0x0029, 0x002E, 0x0033, 0x0038, 0x003D, 0x0042, 0x0047, 0x004C,\n\t0x0051, 0x0057, 0x005C, 0x0061, 0x0066, 0x006B, 0x0070, 0x0075,\n\t0x007A, 0x007F, 0x0084, 0x008A, 0x008F, 0x0094, 0x0099, 0x009E,\n\t0x00A3, 0x00A8, 0x00AD, 0x00B2, 0x00B7, 0x00BC, 0x00C2, 0x00C7,\n\t0x00CC, 0x00D1, 0x00D6, 0x00DB, 0x00E0, 0x00E5, 0x00EA, 0x00EF,\n\t0x00F4, 0x00FA, 0x00FF, 0x0104, 0x0109, 0x010E, 0x0113, 0x0118,\n\t0x011D, 0x0122, 0x0127, 0x012C, 0x0131, 0x0137, 0x013C, 0x0141,\n\t0x0146, 0x014B, 0x0150, 0x0155, 0x015A, 0x015F, 0x0164, 0x0169,\n\t0x016F, 0x0174, 0x0179, 0x017E, 0x0183, 0x0188, 0x018D, 0x0192,\n\t0x0197, 0x019C, 0x01A1, 0x01A6, 0x01AC, 0x01B1, 0x01B6, 0x01BB,\n\t0x01C0, 0x01C5, 0x01CA, 0x01CF, 0x01D4, 0x01D9, 0x01DE, 0x01E3,\n\t0x01E9, 0x01EE, 0x01F3, 0x01F8, 0x01FD, 0x0202, 0x0207, 0x020C,\n\t0x0211, 0x0216, 0x021B, 0x0220, 0x0226, 0x022B, 0x0230, 0x0235,\n\t0x023A, 0x023F, 0x0244, 0x0249, 0x024E, 0x0253, 0x0258, 0x025D,\n\t0x0262, 0x0268, 0x026D, 0x0272, 0x0277, 0x027C, 0x0281, 0x0286,\n\t0x028B, 0x0290, 0x0295, 0x029A, 0x029F, 0x02A4, 0x02A9, 0x02AF,\n\t0x02B4, 0x02B9, 0x02BE, 0x02C3, 0x02C8, 0x02CD, 0x02D2, 0x02D7,\n\t0x02DC, 0x02E1, 0x02E6, 0x02EB, 0x02F0, 0x02F6, 0x02FB, 0x0300,\n\t0x0305, 0x030A, 0x030F, 0x0314, 0x0319, 0x031E, 0x0323, 0x0328,\n\t0x032D, 0x0332, 0x0337, 0x033C, 0x0341, 0x0347, 0x034C, 0x0351,\n\t0x0356, 0x035B, 0x0360, 0x0365, 0x036A, 0x036F, 0x0374, 0x0379,\n\t0x037E, 0x0383, 0x0388, 0x038D, 0x0392, 0x0397, 0x039C, 0x03A2,\n\t0x03A7, 0x03AC, 0x03B1, 0x03B6, 0x03BB, 0x03C0, 0x03C5, 0x03CA,\n\t0x03CF, 0x03D4, 0x03D9, 0x03DE, 0x03E3, 0x03E8, 0x03ED, 0x03F2,\n\t0x03F7, 0x03FC, 0x0401, 0x0407, 0x040C, 0x0411, 0x0416, 0x041B,\n\t0x0420, 0x0425, 0x042A, 0x042F, 0x0434, 0x0439, 0x043E, 0x0443,\n\t0x0448, 0x044D, 0x0452, 0x0457, 0x045C, 0x0461, 0x0466, 0x046B,\n\t0x0470, 0x0475, 0x047A, 0x047F, 0x0484, 0x0489, 0x048E, 0x0494,\n\t0x0499, 0x049E, 0x04A3, 0x04A8, 0x04AD, 0x04B2, 0x04B7, 0x04BC,\n\t0x04C1, 0x04C6, 0x04CB, 0x04D0, 0x04D5, 0x04DA, 0x04DF, 0x04E4,\n\t0x04E9, 0x04EE, 0x04F3, 0x04F8, 0x04FD, 0x0502, 0x0507, 0x050C,\n\t0x0511, 0x0516, 0x051B, 0x0520, 0x0525, 0x052A, 0x052F, 0x0534,\n\t0x0539, 0x053E, 0x0543, 0x0548, 0x054D, 0x0552, 0x0557, 0x055C,\n\t0x0561, 0x0566, 0x056B, 0x0570, 0x0575, 0x057A, 0x057F, 0x0584,\n\t0x0589, 0x058E, 0x0593, 0x0598, 0x059D, 0x05A2, 0x05A7, 0x05AC,\n\t0x05B1, 0x05B6, 0x05BB, 0x05C0, 0x05C5, 0x05CA, 0x05CF, 0x05D4,\n\t0x05D9, 0x05DE, 0x05E3, 0x05E8, 0x05ED, 0x05F2, 0x05F7, 0x05FC,\n\t0x0601, 0x0606, 0x060B, 0x0610, 0x0615, 0x061A, 0x061F, 0x0624,\n\t0x0629, 0x062E, 0x0633, 0x0638, 0x063D, 0x0642, 0x0647, 0x064C,\n\t0x0651, 0x0656, 0x065B, 0x0660, 0x0665, 0x066A, 0x066E, 0x0673,\n\t0x0678, 0x067D, 0x0682, 0x0687, 0x068C, 0x0691, 0x0696, 0x069B,\n\t0x06A0, 0x06A5, 0x06AA, 0x06AF, 0x06B4, 0x06B9, 0x06BE, 0x06C3,\n\t0x06C8, 0x06CD, 0x06D2, 0x06D7, 0x06DC, 0x06E1, 0x06E5, 0x06EA,\n\t0x06EF, 0x06F4, 0x06F9, 0x06FE, 0x0703, 0x0708, 0x070D, 0x0712,\n\t0x0717, 0x071C, 0x0721, 0x0726, 0x072B, 0x0730, 0x0735, 0x0739,\n\t0x073E, 0x0743, 0x0748, 0x074D, 0x0752, 0x0757, 0x075C, 0x0761,\n\t0x0766, 0x076B, 0x0770, 0x0775, 0x077A, 0x077E, 0x0783, 0x0788,\n\t0x078D, 0x0792, 0x0797, 0x079C, 0x07A1, 0x07A6, 0x07AB, 0x07B0,\n\t0x07B5, 0x07B9, 0x07BE, 0x07C3, 0x07C8, 0x07CD, 0x07D2, 0x07D7,\n\t0x07DC, 0x07E1, 0x07E6, 0x07EB, 0x07EF, 0x07F4, 0x07F9, 0x07FE,\n\t0x0803, 0x0808, 0x080D, 0x0812, 0x0817, 0x081C, 0x0820, 0x0825,\n\t0x082A, 0x082F, 0x0834, 0x0839, 0x083E, 0x0843, 0x0848, 0x084C,\n\t0x0851, 0x0856, 0x085B, 0x0860, 0x0865, 0x086A, 0x086F, 0x0873,\n\t0x0878, 0x087D, 0x0882, 0x0887, 0x088C, 0x0891, 0x0896, 0x089A,\n\t0x089F, 0x08A4, 0x08A9, 0x08AE, 0x08B3, 0x08B8, 0x08BD, 0x08C1,\n\t0x08C6, 0x08CB, 0x08D0, 0x08D5, 0x08DA, 0x08DF, 0x08E3, 0x08E8,\n\t0x08ED, 0x08F2, 0x08F7, 0x08FC, 0x0901, 0x0905, 0x090A, 0x090F,\n\t0x0914, 0x0919, 0x091E, 0x0922, 0x0927, 0x092C, 0x0931, 0x0936,\n\t0x093B, 0x093F, 0x0944, 0x0949, 0x094E, 0x0953, 0x0958, 0x095C,\n\t0x0961, 0x0966, 0x096B, 0x0970, 0x0975, 0x0979, 0x097E, 0x0983,\n\t0x0988, 0x098D, 0x0992, 0x0996, 0x099B, 0x09A0, 0x09A5, 0x09AA,\n\t0x09AE, 0x09B3, 0x09B8, 0x09BD, 0x09C2, 0x09C6, 0x09CB, 0x09D0,\n\t0x09D5, 0x09DA, 0x09DE, 0x09E3, 0x09E8, 0x09ED, 0x09F2, 0x09F6,\n\t0x09FB, 0x0A00, 0x0A05, 0x0A0A, 0x0A0E, 0x0A13, 0x0A18, 0x0A1D,\n\t0x0A22, 0x0A26, 0x0A2B, 0x0A30, 0x0A35, 0x0A39, 0x0A3E, 0x0A43,\n\t0x0A48, 0x0A4D, 0x0A51, 0x0A56, 0x0A5B, 0x0A60, 0x0A64, 0x0A69,\n\t0x0A6E, 0x0A73, 0x0A77, 0x0A7C, 0x0A81, 0x0A86, 0x0A8B, 0x0A8F,\n\t0x0A94, 0x0A99, 0x0A9E, 0x0AA2, 0x0AA7, 0x0AAC, 0x0AB1, 0x0AB5,\n\t0x0ABA, 0x0ABF, 0x0AC4, 0x0AC8, 0x0ACD, 0x0AD2, 0x0AD7, 0x0ADB,\n\t0x0AE0, 0x0AE5, 0x0AE9, 0x0AEE, 0x0AF3, 0x0AF8, 0x0AFC, 0x0B01,\n\t0x0B06, 0x0B0B, 0x0B0F, 0x0B14, 0x0B19, 0x0B1E, 0x0B22, 0x0B27,\n\t0x0B2C, 0x0B30, 0x0B35, 0x0B3A, 0x0B3F, 0x0B43, 0x0B48, 0x0B4D,\n\t0x0B51, 0x0B56, 0x0B5B, 0x0B60, 0x0B64, 0x0B69, 0x0B6E, 0x0B72,\n\t0x0B77, 0x0B7C, 0x0B80, 0x0B85, 0x0B8A, 0x0B8F, 0x0B93, 0x0B98,\n\t0x0B9D, 0x0BA1, 0x0BA6, 0x0BAB, 0x0BAF, 0x0BB4, 0x0BB9, 0x0BBD,\n\t0x0BC2, 0x0BC7, 0x0BCB, 0x0BD0, 0x0BD5, 0x0BD9, 0x0BDE, 0x0BE3,\n\t0x0BE7, 0x0BEC, 0x0BF1, 0x0BF5, 0x0BFA, 0x0BFF, 0x0C03, 0x0C08,\n\t0x0C0D, 0x0C11, 0x0C16, 0x0C1B, 0x0C1F, 0x0C24, 0x0C29, 0x0C2D,\n\t0x0C32, 0x0C37, 0x0C3B, 0x0C40, 0x0C45, 0x0C49, 0x0C4E, 0x0C53,\n\t0x0C57, 0x0C5C, 0x0C60, 0x0C65, 0x0C6A, 0x0C6E, 0x0C73, 0x0C78,\n\t0x0C7C, 0x0C81, 0x0C86, 0x0C8A, 0x0C8F, 0x0C93, 0x0C98, 0x0C9D,\n\t0x0CA1, 0x0CA6, 0x0CAB, 0x0CAF, 0x0CB4, 0x0CB8, 0x0CBD, 0x0CC2,\n\t0x0CC6, 0x0CCB, 0x0CCF, 0x0CD4, 0x0CD9, 0x0CDD, 0x0CE2, 0x0CE6,\n\t0x0CEB, 0x0CF0, 0x0CF4, 0x0CF9, 0x0CFD, 0x0D02, 0x0D07, 0x0D0B,\n\t0x0D10, 0x0D14, 0x0D19, 0x0D1E, 0x0D22, 0x0D27, 0x0D2B, 0x0D30,\n\t0x0D34, 0x0D39, 0x0D3E, 0x0D42, 0x0D47, 0x0D4B, 0x0D50, 0x0D54,\n\t0x0D59, 0x0D5E, 0x0D62, 0x0D67, 0x0D6B, 0x0D70, 0x0D74, 0x0D79,\n\t0x0D7D, 0x0D82, 0x0D87, 0x0D8B, 0x0D90, 0x0D94, 0x0D99, 0x0D9D,\n\t0x0DA2, 0x0DA6, 0x0DAB, 0x0DAF, 0x0DB4, 0x0DB9, 0x0DBD, 0x0DC2,\n\t0x0DC6, 0x0DCB, 0x0DCF, 0x0DD4, 0x0DD8, 0x0DDD, 0x0DE1, 0x0DE6,\n\t0x0DEA, 0x0DEF, 0x0DF3, 0x0DF8, 0x0DFC, 0x0E01, 0x0E05, 0x0E0A,\n\t0x0E0F, 0x0E13, 0x0E18, 0x0E1C, 0x0E21, 0x0E25, 0x0E2A, 0x0E2E,\n\t0x0E33, 0x0E37, 0x0E3C, 0x0E40, 0x0E45, 0x0E49, 0x0E4E, 0x0E52,\n\t0x0E56, 0x0E5B, 0x0E5F, 0x0E64, 0x0E68, 0x0E6D, 0x0E71, 0x0E76,\n\t0x0E7A, 0x0E7F, 0x0E83, 0x0E88, 0x0E8C, 0x0E91, 0x0E95, 0x0E9A,\n\t0x0E9E, 0x0EA3, 0x0EA7, 0x0EAC, 0x0EB0, 0x0EB4, 0x0EB9, 0x0EBD,\n\t0x0EC2, 0x0EC6, 0x0ECB, 0x0ECF, 0x0ED4, 0x0ED8, 0x0EDC, 0x0EE1,\n\t0x0EE5, 0x0EEA, 0x0EEE, 0x0EF3, 0x0EF7, 0x0EFC, 0x0F00, 0x0F04,\n\t0x0F09, 0x0F0D, 0x0F12, 0x0F16, 0x0F1B, 0x0F1F, 0x0F23, 0x0F28,\n\t0x0F2C, 0x0F31, 0x0F35, 0x0F3A, 0x0F3E, 0x0F42, 0x0F47, 0x0F4B,\n\t0x0F50, 0x0F54, 0x0F58, 0x0F5D, 0x0F61, 0x0F66, 0x0F6A, 0x0F6E,\n\t0x0F73, 0x0F77, 0x0F7C, 0x0F80, 0x0F84, 0x0F89, 0x0F8D, 0x0F91,\n\t0x0F96, 0x0F9A, 0x0F9F, 0x0FA3, 0x0FA7, 0x0FAC, 0x0FB0, 0x0FB5,\n\t0x0FB9, 0x0FBD, 0x0FC2, 0x0FC6, 0x0FCA, 0x0FCF, 0x0FD3, 0x0FD7,\n\t0x0FDC, 0x0FE0, 0x0FE5, 0x0FE9, 0x0FED, 0x0FF2, 0x0FF6, 0x0FFA,\n\t0x0FFF, 0x1003, 0x1007, 0x100C, 0x1010, 0x1014, 0x1019, 0x101D,\n\t0x1021, 0x1026, 0x102A, 0x102E, 0x1033, 0x1037, 0x103B, 0x1040,\n\t0x1044, 0x1048, 0x104D, 0x1051, 0x1055, 0x105A, 0x105E, 0x1062,\n\t0x1067, 0x106B, 0x106F, 0x1073, 0x1078, 0x107C, 0x1080, 0x1085,\n\t0x1089, 0x108D, 0x1092, 0x1096, 0x109A, 0x109E, 0x10A3, 0x10A7,\n\t0x10AB, 0x10B0, 0x10B4, 0x10B8, 0x10BC, 0x10C1, 0x10C5, 0x10C9,\n\t0x10CE, 0x10D2, 0x10D6, 0x10DA, 0x10DF, 0x10E3, 0x10E7, 0x10EB,\n\t0x10F0, 0x10F4, 0x10F8, 0x10FD, 0x1101, 0x1105, 0x1109, 0x110E,\n\t0x1112, 0x1116, 0x111A, 0x111F, 0x1123, 0x1127, 0x112B, 0x1130,\n\t0x1134, 0x1138, 0x113C, 0x1140, 0x1145, 0x1149, 0x114D, 0x1151,\n\t0x1156, 0x115A, 0x115E, 0x1162, 0x1166, 0x116B, 0x116F, 0x1173,\n\t0x1177, 0x117C, 0x1180, 0x1184, 0x1188, 0x118C, 0x1191, 0x1195,\n\t0x1199, 0x119D, 0x11A1, 0x11A6, 0x11AA, 0x11AE, 0x11B2, 0x11B6,\n\t0x11BB, 0x11BF, 0x11C3, 0x11C7, 0x11CB, 0x11CF, 0x11D4, 0x11D8,\n\t0x11DC, 0x11E0, 0x11E4, 0x11E9, 0x11ED, 0x11F1, 0x11F5, 0x11F9,\n\t0x11FD, 0x1202, 0x1206, 0x120A, 0x120E, 0x1212, 0x1216, 0x121A,\n\t0x121F, 0x1223, 0x1227, 0x122B, 0x122F, 0x1233, 0x1237, 0x123C,\n\t0x1240, 0x1244, 0x1248, 0x124C, 0x1250, 0x1254, 0x1259, 0x125D,\n\t0x1261, 0x1265, 0x1269, 0x126D, 0x1271, 0x1275, 0x127A, 0x127E,\n\t0x1282, 0x1286, 0x128A, 0x128E, 0x1292, 0x1296, 0x129A, 0x129F,\n\t0x12A3, 0x12A7, 0x12AB, 0x12AF, 0x12B3, 0x12B7, 0x12BB, 0x12BF,\n\t0x12C3, 0x12C7, 0x12CC, 0x12D0, 0x12D4, 0x12D8, 0x12DC, 0x12E0,\n\t0x12E4, 0x12E8, 0x12EC, 0x12F0, 0x12F4, 0x12F8, 0x12FC, 0x1301,\n\t0x1305, 0x1309, 0x130D, 0x1311, 0x1315, 0x1319, 0x131D, 0x1321,\n\t0x1325, 0x1329, 0x132D, 0x1331, 0x1335, 0x1339, 0x133D, 0x1341,\n\t0x1345, 0x1349, 0x134D, 0x1351, 0x1355, 0x135A, 0x135E, 0x1362,\n\t0x1366, 0x136A, 0x136E, 0x1372, 0x1376, 0x137A, 0x137E, 0x1382,\n\t0x1386, 0x138A, 0x138E, 0x1392, 0x1396, 0x139A, 0x139E, 0x13A2,\n\t0x13A6, 0x13AA, 0x13AE, 0x13B2, 0x13B6, 0x13BA, 0x13BE, 0x13C2,\n\t0x13C6, 0x13CA, 0x13CE, 0x13D2, 0x13D6, 0x13DA, 0x13DE, 0x13E2,\n\t0x13E6, 0x13E9, 0x13ED, 0x13F1, 0x13F5, 0x13F9, 0x13FD, 0x1401,\n\t0x1405, 0x1409, 0x140D, 0x1411, 0x1415, 0x1419, 0x141D, 0x1421,\n\t0x1425, 0x1429, 0x142D, 0x1431, 0x1435, 0x1439, 0x143D, 0x1440,\n\t0x1444, 0x1448, 0x144C, 0x1450, 0x1454, 0x1458, 0x145C, 0x1460,\n\t0x1464, 0x1468, 0x146C, 0x1470, 0x1473, 0x1477, 0x147B, 0x147F,\n\t0x1483, 0x1487, 0x148B, 0x148F, 0x1493, 0x1497, 0x149B, 0x149E,\n\t0x14A2, 0x14A6, 0x14AA, 0x14AE, 0x14B2, 0x14B6, 0x14BA, 0x14BE,\n\t0x14C1, 0x14C5, 0x14C9, 0x14CD, 0x14D1, 0x14D5, 0x14D9, 0x14DD,\n\t0x14E0, 0x14E4, 0x14E8, 0x14EC, 0x14F0, 0x14F4, 0x14F8, 0x14FB,\n\t0x14FF, 0x1503, 0x1507, 0x150B, 0x150F, 0x1513, 0x1516, 0x151A,\n\t0x151E, 0x1522, 0x1526, 0x152A, 0x152D, 0x1531, 0x1535, 0x1539,\n\t0x153D, 0x1541, 0x1544, 0x1548, 0x154C, 0x1550, 0x1554, 0x1558,\n\t0x155B, 0x155F, 0x1563, 0x1567, 0x156B, 0x156E, 0x1572, 0x1576,\n\t0x157A, 0x157E, 0x1581, 0x1585, 0x1589, 0x158D, 0x1591, 0x1594,\n\t0x1598, 0x159C, 0x15A0, 0x15A4, 0x15A7, 0x15AB, 0x15AF, 0x15B3,\n\t0x15B7, 0x15BA, 0x15BE, 0x15C2, 0x15C6, 0x15C9, 0x15CD, 0x15D1,\n\t0x15D5, 0x15D8, 0x15DC, 0x15E0, 0x15E4, 0x15E8, 0x15EB, 0x15EF,\n\t0x15F3, 0x15F7, 0x15FA, 0x15FE, 0x1602, 0x1606, 0x1609, 0x160D,\n\t0x1611, 0x1614, 0x1618, 0x161C, 0x1620, 0x1623, 0x1627, 0x162B,\n\t0x162F, 0x1632, 0x1636, 0x163A, 0x163E, 0x1641, 0x1645, 0x1649,\n\t0x164C, 0x1650, 0x1654, 0x1658, 0x165B, 0x165F, 0x1663, 0x1666,\n\t0x166A, 0x166E, 0x1671, 0x1675, 0x1679, 0x167D, 0x1680, 0x1684,\n\t0x1688, 0x168B, 0x168F, 0x1693, 0x1696, 0x169A, 0x169E, 0x16A1,\n\t0x16A5, 0x16A9, 0x16AC, 0x16B0, 0x16B4, 0x16B7, 0x16BB, 0x16BF,\n\t0x16C2, 0x16C6, 0x16CA, 0x16CD, 0x16D1, 0x16D5, 0x16D8, 0x16DC,\n\t0x16E0, 0x16E3, 0x16E7, 0x16EB, 0x16EE, 0x16F2, 0x16F6, 0x16F9,\n\t0x16FD, 0x1700, 0x1704, 0x1708, 0x170B, 0x170F, 0x1713, 0x1716,\n\t0x171A, 0x171D, 0x1721, 0x1725, 0x1728, 0x172C, 0x1730, 0x1733,\n\t0x1737, 0x173A, 0x173E, 0x1742, 0x1745, 0x1749, 0x174C, 0x1750,\n\t0x1754, 0x1757, 0x175B, 0x175E, 0x1762, 0x1766, 0x1769, 0x176D,\n\t0x1770, 0x1774, 0x1778, 0x177B, 0x177F, 0x1782, 0x1786, 0x1789,\n\t0x178D, 0x1791, 0x1794, 0x1798, 0x179B, 0x179F, 0x17A2, 0x17A6,\n\t0x17AA, 0x17AD, 0x17B1, 0x17B4, 0x17B8, 0x17BB, 0x17BF, 0x17C2,\n\t0x17C6, 0x17C9, 0x17CD, 0x17D1, 0x17D4, 0x17D8, 0x17DB, 0x17DF,\n\t0x17E2, 0x17E6, 0x17E9, 0x17ED, 0x17F0, 0x17F4, 0x17F7, 0x17FB,\n\t0x17FE, 0x1802, 0x1806, 0x1809, 0x180D, 0x1810, 0x1814, 0x1817,\n\t0x181B, 0x181E, 0x1822, 0x1825, 0x1829, 0x182C, 0x1830, 0x1833,\n\t0x1837, 0x183A, 0x183E, 0x1841, 0x1845, 0x1848, 0x184C, 0x184F,\n\t0x1853, 0x1856, 0x185A, 0x185D, 0x1860, 0x1864, 0x1867, 0x186B,\n\t0x186E, 0x1872, 0x1875, 0x1879, 0x187C, 0x1880, 0x1883, 0x1887,\n\t0x188A, 0x188E, 0x1891, 0x1894, 0x1898, 0x189B, 0x189F, 0x18A2,\n\t0x18A6, 0x18A9, 0x18AD, 0x18B0, 0x18B3, 0x18B7, 0x18BA, 0x18BE,\n\t0x18C1, 0x18C5, 0x18C8, 0x18CC, 0x18CF, 0x18D2, 0x18D6, 0x18D9,\n\t0x18DD, 0x18E0, 0x18E3, 0x18E7, 0x18EA, 0x18EE, 0x18F1, 0x18F5,\n\t0x18F8, 0x18FB, 0x18FF, 0x1902, 0x1906, 0x1909, 0x190C, 0x1910,\n\t0x1913, 0x1917, 0x191A, 0x191D, 0x1921, 0x1924, 0x1928, 0x192B,\n\t0x192E, 0x1932, 0x1935, 0x1938, 0x193C, 0x193F, 0x1943, 0x1946,\n\t0x1949, 0x194D, 0x1950, 0x1953, 0x1957, 0x195A, 0x195D, 0x1961,\n\t0x1964, 0x1968, 0x196B, 0x196E, 0x1972, 0x1975, 0x1978, 0x197C,\n\t0x197F, 0x1982, 0x1986, 0x1989, 0x198C, 0x1990, 0x1993, 0x1996,\n\t0x199A, 0x199D, 0x19A0, 0x19A4, 0x19A7, 0x19AA, 0x19AE, 0x19B1,\n\t0x19B4, 0x19B8, 0x19BB, 0x19BE, 0x19C2, 0x19C5, 0x19C8, 0x19CC,\n\t0x19CF, 0x19D2, 0x19D5, 0x19D9, 0x19DC, 0x19DF, 0x19E3, 0x19E6,\n\t0x19E9, 0x19ED, 0x19F0, 0x19F3, 0x19F6, 0x19FA, 0x19FD, 0x1A00,\n\t0x1A04, 0x1A07, 0x1A0A, 0x1A0D, 0x1A11, 0x1A14, 0x1A17, 0x1A1B,\n\t0x1A1E, 0x1A21, 0x1A24, 0x1A28, 0x1A2B, 0x1A2E, 0x1A31, 0x1A35,\n\t0x1A38, 0x1A3B, 0x1A3E, 0x1A42, 0x1A45, 0x1A48, 0x1A4B, 0x1A4F,\n\t0x1A52, 0x1A55, 0x1A58, 0x1A5C, 0x1A5F, 0x1A62, 0x1A65, 0x1A69,\n\t0x1A6C, 0x1A6F, 0x1A72, 0x1A76, 0x1A79, 0x1A7C, 0x1A7F, 0x1A83,\n\t0x1A86, 0x1A89, 0x1A8C, 0x1A8F, 0x1A93, 0x1A96, 0x1A99, 0x1A9C,\n\t0x1A9F, 0x1AA3, 0x1AA6, 0x1AA9, 0x1AAC, 0x1AB0, 0x1AB3, 0x1AB6,\n\t0x1AB9, 0x1ABC, 0x1AC0, 0x1AC3, 0x1AC6, 0x1AC9, 0x1ACC, 0x1ACF,\n\t0x1AD3, 0x1AD6, 0x1AD9, 0x1ADC, 0x1ADF, 0x1AE3, 0x1AE6, 0x1AE9,\n\t0x1AEC, 0x1AEF, 0x1AF2, 0x1AF6, 0x1AF9, 0x1AFC, 0x1AFF, 0x1B02,\n\t0x1B05, 0x1B09, 0x1B0C, 0x1B0F, 0x1B12, 0x1B15, 0x1B18, 0x1B1C,\n\t0x1B1F, 0x1B22, 0x1B25, 0x1B28, 0x1B2B, 0x1B2E, 0x1B32, 0x1B35,\n\t0x1B38, 0x1B3B, 0x1B3E, 0x1B41, 0x1B44, 0x1B48, 0x1B4B, 0x1B4E,\n\t0x1B51, 0x1B54, 0x1B57, 0x1B5A, 0x1B5D, 0x1B61, 0x1B64, 0x1B67,\n\t0x1B6A, 0x1B6D, 0x1B70, 0x1B73, 0x1B76, 0x1B79, 0x1B7D, 0x1B80,\n\t0x1B83, 0x1B86, 0x1B89, 0x1B8C, 0x1B8F, 0x1B92, 0x1B95, 0x1B98,\n\t0x1B9C, 0x1B9F, 0x1BA2, 0x1BA5, 0x1BA8, 0x1BAB, 0x1BAE, 0x1BB1,\n\t0x1BB4, 0x1BB7, 0x1BBA, 0x1BBD, 0x1BC1, 0x1BC4, 0x1BC7, 0x1BCA,\n\t0x1BCD, 0x1BD0, 0x1BD3, 0x1BD6, 0x1BD9, 0x1BDC, 0x1BDF, 0x1BE2,\n\t0x1BE5, 0x1BE8, 0x1BEB, 0x1BEE, 0x1BF2, 0x1BF5, 0x1BF8, 0x1BFB,\n\t0x1BFE, 0x1C01, 0x1C04, 0x1C07, 0x1C0A, 0x1C0D, 0x1C10, 0x1C13,\n\t0x1C16, 0x1C19, 0x1C1C, 0x1C1F, 0x1C22, 0x1C25, 0x1C28, 0x1C2B,\n\t0x1C2E, 0x1C31, 0x1C34, 0x1C37, 0x1C3A, 0x1C3D, 0x1C40, 0x1C43,\n\t0x1C46, 0x1C49, 0x1C4C, 0x1C4F, 0x1C52, 0x1C55, 0x1C58, 0x1C5B,\n\t0x1C5E, 0x1C61, 0x1C64, 0x1C67, 0x1C6A, 0x1C6D, 0x1C70, 0x1C73,\n\t0x1C76, 0x1C79, 0x1C7C, 0x1C7F, 0x1C82, 0x1C85, 0x1C88, 0x1C8B,\n\t0x1C8E, 0x1C91, 0x1C94, 0x1C97, 0x1C9A, 0x1C9D, 0x1CA0, 0x1CA3,\n\t0x1CA6, 0x1CA9, 0x1CAC, 0x1CAF, 0x1CB2, 0x1CB5, 0x1CB8, 0x1CBB,\n\t0x1CBE, 0x1CC1, 0x1CC3, 0x1CC6, 0x1CC9, 0x1CCC, 0x1CCF, 0x1CD2,\n\t0x1CD5, 0x1CD8, 0x1CDB, 0x1CDE, 0x1CE1, 0x1CE4, 0x1CE7, 0x1CEA,\n\t0x1CED, 0x1CF0, 0x1CF3, 0x1CF5, 0x1CF8, 0x1CFB, 0x1CFE, 0x1D01,\n\t0x1D04, 0x1D07, 0x1D0A, 0x1D0D, 0x1D10, 0x1D13, 0x1D16, 0x1D18,\n\t0x1D1B, 0x1D1E, 0x1D21, 0x1D24, 0x1D27, 0x1D2A, 0x1D2D, 0x1D30,\n\t0x1D33, 0x1D35, 0x1D38, 0x1D3B, 0x1D3E, 0x1D41, 0x1D44, 0x1D47,\n\t0x1D4A, 0x1D4D, 0x1D4F, 0x1D52, 0x1D55, 0x1D58, 0x1D5B, 0x1D5E,\n\t0x1D61, 0x1D64, 0x1D66, 0x1D69, 0x1D6C, 0x1D6F, 0x1D72, 0x1D75,\n\t0x1D78, 0x1D7B, 0x1D7D, 0x1D80, 0x1D83, 0x1D86, 0x1D89, 0x1D8C,\n\t0x1D8E, 0x1D91, 0x1D94, 0x1D97, 0x1D9A, 0x1D9D, 0x1DA0, 0x1DA2,\n\t0x1DA5, 0x1DA8, 0x1DAB, 0x1DAE, 0x1DB1, 0x1DB3, 0x1DB6, 0x1DB9,\n\t0x1DBC, 0x1DBF, 0x1DC2, 0x1DC4, 0x1DC7, 0x1DCA, 0x1DCD, 0x1DD0,\n\t0x1DD3, 0x1DD5, 0x1DD8, 0x1DDB, 0x1DDE, 0x1DE1, 0x1DE3, 0x1DE6,\n\t0x1DE9, 0x1DEC, 0x1DEF, 0x1DF1, 0x1DF4, 0x1DF7, 0x1DFA, 0x1DFD,\n\t0x1DFF, 0x1E02, 0x1E05, 0x1E08, 0x1E0B, 0x1E0D, 0x1E10, 0x1E13,\n\t0x1E16, 0x1E19, 0x1E1B, 0x1E1E, 0x1E21, 0x1E24, 0x1E26, 0x1E29,\n\t0x1E2C, 0x1E2F, 0x1E32, 0x1E34, 0x1E37, 0x1E3A, 0x1E3D, 0x1E3F,\n\t0x1E42, 0x1E45, 0x1E48, 0x1E4A, 0x1E4D, 0x1E50, 0x1E53, 0x1E55,\n\t0x1E58, 0x1E5B, 0x1E5E, 0x1E60, 0x1E63, 0x1E66, 0x1E69, 0x1E6B,\n\t0x1E6E, 0x1E71, 0x1E74, 0x1E76, 0x1E79, 0x1E7C, 0x1E7F, 0x1E81,\n\t0x1E84, 0x1E87, 0x1E8A, 0x1E8C, 0x1E8F, 0x1E92, 0x1E94, 0x1E97,\n\t0x1E9A, 0x1E9D, 0x1E9F, 0x1EA2, 0x1EA5, 0x1EA8, 0x1EAA, 0x1EAD,\n\t0x1EB0, 0x1EB2, 0x1EB5, 0x1EB8, 0x1EBA, 0x1EBD, 0x1EC0, 0x1EC3,\n\t0x1EC5, 0x1EC8, 0x1ECB, 0x1ECD, 0x1ED0, 0x1ED3, 0x1ED5, 0x1ED8,\n\t0x1EDB, 0x1EDE, 0x1EE0, 0x1EE3, 0x1EE6, 0x1EE8, 0x1EEB, 0x1EEE,\n\t0x1EF0, 0x1EF3, 0x1EF6, 0x1EF8, 0x1EFB, 0x1EFE, 0x1F00, 0x1F03,\n\t0x1F06, 0x1F08, 0x1F0B, 0x1F0E, 0x1F10, 0x1F13, 0x1F16, 0x1F18,\n\t0x1F1B, 0x1F1E, 0x1F20, 0x1F23, 0x1F26, 0x1F28, 0x1F2B, 0x1F2E,\n\t0x1F30, 0x1F33, 0x1F36, 0x1F38, 0x1F3B, 0x1F3D, 0x1F40, 0x1F43,\n\t0x1F45, 0x1F48, 0x1F4B, 0x1F4D, 0x1F50, 0x1F53, 0x1F55, 0x1F58,\n\t0x1F5A, 0x1F5D, 0x1F60, 0x1F62, 0x1F65, 0x1F68, 0x1F6A, 0x1F6D,\n\t0x1F6F, 0x1F72, 0x1F75, 0x1F77, 0x1F7A, 0x1F7C, 0x1F7F, 0x1F82,\n\t0x1F84, 0x1F87, 0x1F8A, 0x1F8C, 0x1F8F, 0x1F91, 0x1F94, 0x1F97,\n\t0x1F99, 0x1F9C, 0x1F9E, 0x1FA1, 0x1FA4, 0x1FA6, 0x1FA9, 0x1FAB,\n\t0x1FAE, 0x1FB0, 0x1FB3, 0x1FB6, 0x1FB8, 0x1FBB, 0x1FBD, 0x1FC0,\n\t0x1FC3, 0x1FC5, 0x1FC8, 0x1FCA, 0x1FCD, 0x1FCF, 0x1FD2, 0x1FD5,\n\t0x1FD7, 0x1FDA, 0x1FDC, 0x1FDF, 0x1FE1, 0x1FE4, 0x1FE6, 0x1FE9,\n\t0x1FEC, 0x1FEE, 0x1FF1, 0x1FF3, 0x1FF6, 0x1FF8, 0x1FFB, 0x1FFD,\n\t0x2000, 0x2000,\n};\n\n// Sines integer representation table for angle 0..90 degrees\nstatic const __int16 PhdSinTable[0x402] = {\n\t0x0000, 0x0019, 0x0032, 0x004B, 0x0065, 0x007E, 0x0097, 0x00B0,\n\t0x00C9, 0x00E2, 0x00FB, 0x0114, 0x012E, 0x0147, 0x0160, 0x0179,\n\t0x0192, 0x01AB, 0x01C4, 0x01DD, 0x01F7, 0x0210, 0x0229, 0x0242,\n\t0x025B, 0x0274, 0x028D, 0x02A6, 0x02C0, 0x02D9, 0x02F2, 0x030B,\n\t0x0324, 0x033D, 0x0356, 0x036F, 0x0388, 0x03A1, 0x03BB, 0x03D4,\n\t0x03ED, 0x0406, 0x041F, 0x0438, 0x0451, 0x046A, 0x0483, 0x049C,\n\t0x04B5, 0x04CE, 0x04E7, 0x0500, 0x051A, 0x0533, 0x054C, 0x0565,\n\t0x057E, 0x0597, 0x05B0, 0x05C9, 0x05E2, 0x05FB, 0x0614, 0x062D,\n\t0x0646, 0x065F, 0x0678, 0x0691, 0x06AA, 0x06C3, 0x06DC, 0x06F5,\n\t0x070E, 0x0727, 0x0740, 0x0759, 0x0772, 0x078B, 0x07A4, 0x07BD,\n\t0x07D6, 0x07EF, 0x0807, 0x0820, 0x0839, 0x0852, 0x086B, 0x0884,\n\t0x089D, 0x08B6, 0x08CF, 0x08E8, 0x0901, 0x0919, 0x0932, 0x094B,\n\t0x0964, 0x097D, 0x0996, 0x09AF, 0x09C7, 0x09E0, 0x09F9, 0x0A12,\n\t0x0A2B, 0x0A44, 0x0A5C, 0x0A75, 0x0A8E, 0x0AA7, 0x0AC0, 0x0AD8,\n\t0x0AF1, 0x0B0A, 0x0B23, 0x0B3B, 0x0B54, 0x0B6D, 0x0B85, 0x0B9E,\n\t0x0BB7, 0x0BD0, 0x0BE8, 0x0C01, 0x0C1A, 0x0C32, 0x0C4B, 0x0C64,\n\t0x0C7C, 0x0C95, 0x0CAE, 0x0CC6, 0x0CDF, 0x0CF8, 0x0D10, 0x0D29,\n\t0x0D41, 0x0D5A, 0x0D72, 0x0D8B, 0x0DA4, 0x0DBC, 0x0DD5, 0x0DED,\n\t0x0E06, 0x0E1E, 0x0E37, 0x0E4F, 0x0E68, 0x0E80, 0x0E99, 0x0EB1,\n\t0x0ECA, 0x0EE2, 0x0EFB, 0x0F13, 0x0F2B, 0x0F44, 0x0F5C, 0x0F75,\n\t0x0F8D, 0x0FA5, 0x0FBE, 0x0FD6, 0x0FEE, 0x1007, 0x101F, 0x1037,\n\t0x1050, 0x1068, 0x1080, 0x1099, 0x10B1, 0x10C9, 0x10E1, 0x10FA,\n\t0x1112, 0x112A, 0x1142, 0x115A, 0x1173, 0x118B, 0x11A3, 0x11BB,\n\t0x11D3, 0x11EB, 0x1204, 0x121C, 0x1234, 0x124C, 0x1264, 0x127C,\n\t0x1294, 0x12AC, 0x12C4, 0x12DC, 0x12F4, 0x130C, 0x1324, 0x133C,\n\t0x1354, 0x136C, 0x1384, 0x139C, 0x13B4, 0x13CC, 0x13E4, 0x13FB,\n\t0x1413, 0x142B, 0x1443, 0x145B, 0x1473, 0x148B, 0x14A2, 0x14BA,\n\t0x14D2, 0x14EA, 0x1501, 0x1519, 0x1531, 0x1549, 0x1560, 0x1578,\n\t0x1590, 0x15A7, 0x15BF, 0x15D7, 0x15EE, 0x1606, 0x161D, 0x1635,\n\t0x164C, 0x1664, 0x167C, 0x1693, 0x16AB, 0x16C2, 0x16DA, 0x16F1,\n\t0x1709, 0x1720, 0x1737, 0x174F, 0x1766, 0x177E, 0x1795, 0x17AC,\n\t0x17C4, 0x17DB, 0x17F2, 0x180A, 0x1821, 0x1838, 0x184F, 0x1867,\n\t0x187E, 0x1895, 0x18AC, 0x18C3, 0x18DB, 0x18F2, 0x1909, 0x1920,\n\t0x1937, 0x194E, 0x1965, 0x197C, 0x1993, 0x19AA, 0x19C1, 0x19D8,\n\t0x19EF, 0x1A06, 0x1A1D, 0x1A34, 0x1A4B, 0x1A62, 0x1A79, 0x1A90,\n\t0x1AA7, 0x1ABE, 0x1AD4, 0x1AEB, 0x1B02, 0x1B19, 0x1B30, 0x1B46,\n\t0x1B5D, 0x1B74, 0x1B8A, 0x1BA1, 0x1BB8, 0x1BCE, 0x1BE5, 0x1BFC,\n\t0x1C12, 0x1C29, 0x1C3F, 0x1C56, 0x1C6C, 0x1C83, 0x1C99, 0x1CB0,\n\t0x1CC6, 0x1CDD, 0x1CF3, 0x1D0A, 0x1D20, 0x1D36, 0x1D4D, 0x1D63,\n\t0x1D79, 0x1D90, 0x1DA6, 0x1DBC, 0x1DD3, 0x1DE9, 0x1DFF, 0x1E15,\n\t0x1E2B, 0x1E42, 0x1E58, 0x1E6E, 0x1E84, 0x1E9A, 0x1EB0, 0x1EC6,\n\t0x1EDC, 0x1EF2, 0x1F08, 0x1F1E, 0x1F34, 0x1F4A, 0x1F60, 0x1F76,\n\t0x1F8C, 0x1FA2, 0x1FB7, 0x1FCD, 0x1FE3, 0x1FF9, 0x200F, 0x2024,\n\t0x203A, 0x2050, 0x2065, 0x207B, 0x2091, 0x20A6, 0x20BC, 0x20D1,\n\t0x20E7, 0x20FD, 0x2112, 0x2128, 0x213D, 0x2153, 0x2168, 0x217D,\n\t0x2193, 0x21A8, 0x21BE, 0x21D3, 0x21E8, 0x21FE, 0x2213, 0x2228,\n\t0x223D, 0x2253, 0x2268, 0x227D, 0x2292, 0x22A7, 0x22BC, 0x22D2,\n\t0x22E7, 0x22FC, 0x2311, 0x2326, 0x233B, 0x2350, 0x2365, 0x237A,\n\t0x238E, 0x23A3, 0x23B8, 0x23CD, 0x23E2, 0x23F7, 0x240B, 0x2420,\n\t0x2435, 0x244A, 0x245E, 0x2473, 0x2488, 0x249C, 0x24B1, 0x24C5,\n\t0x24DA, 0x24EF, 0x2503, 0x2518, 0x252C, 0x2541, 0x2555, 0x2569,\n\t0x257E, 0x2592, 0x25A6, 0x25BB, 0x25CF, 0x25E3, 0x25F8, 0x260C,\n\t0x2620, 0x2634, 0x2648, 0x265C, 0x2671, 0x2685, 0x2699, 0x26AD,\n\t0x26C1, 0x26D5, 0x26E9, 0x26FD, 0x2711, 0x2724, 0x2738, 0x274C,\n\t0x2760, 0x2774, 0x2788, 0x279B, 0x27AF, 0x27C3, 0x27D6, 0x27EA,\n\t0x27FE, 0x2811, 0x2825, 0x2838, 0x284C, 0x2860, 0x2873, 0x2886,\n\t0x289A, 0x28AD, 0x28C1, 0x28D4, 0x28E7, 0x28FB, 0x290E, 0x2921,\n\t0x2935, 0x2948, 0x295B, 0x296E, 0x2981, 0x2994, 0x29A7, 0x29BB,\n\t0x29CE, 0x29E1, 0x29F4, 0x2A07, 0x2A1A, 0x2A2C, 0x2A3F, 0x2A52,\n\t0x2A65, 0x2A78, 0x2A8B, 0x2A9D, 0x2AB0, 0x2AC3, 0x2AD6, 0x2AE8,\n\t0x2AFB, 0x2B0D, 0x2B20, 0x2B33, 0x2B45, 0x2B58, 0x2B6A, 0x2B7D,\n\t0x2B8F, 0x2BA1, 0x2BB4, 0x2BC6, 0x2BD8, 0x2BEB, 0x2BFD, 0x2C0F,\n\t0x2C21, 0x2C34, 0x2C46, 0x2C58, 0x2C6A, 0x2C7C, 0x2C8E, 0x2CA0,\n\t0x2CB2, 0x2CC4, 0x2CD6, 0x2CE8, 0x2CFA, 0x2D0C, 0x2D1E, 0x2D2F,\n\t0x2D41, 0x2D53, 0x2D65, 0x2D76, 0x2D88, 0x2D9A, 0x2DAB, 0x2DBD,\n\t0x2DCF, 0x2DE0, 0x2DF2, 0x2E03, 0x2E15, 0x2E26, 0x2E37, 0x2E49,\n\t0x2E5A, 0x2E6B, 0x2E7D, 0x2E8E, 0x2E9F, 0x2EB0, 0x2EC2, 0x2ED3,\n\t0x2EE4, 0x2EF5, 0x2F06, 0x2F17, 0x2F28, 0x2F39, 0x2F4A, 0x2F5B,\n\t0x2F6C, 0x2F7D, 0x2F8D, 0x2F9E, 0x2FAF, 0x2FC0, 0x2FD0, 0x2FE1,\n\t0x2FF2, 0x3002, 0x3013, 0x3024, 0x3034, 0x3045, 0x3055, 0x3066,\n\t0x3076, 0x3087, 0x3097, 0x30A7, 0x30B8, 0x30C8, 0x30D8, 0x30E8,\n\t0x30F9, 0x3109, 0x3119, 0x3129, 0x3139, 0x3149, 0x3159, 0x3169,\n\t0x3179, 0x3189, 0x3199, 0x31A9, 0x31B9, 0x31C8, 0x31D8, 0x31E8,\n\t0x31F8, 0x3207, 0x3217, 0x3227, 0x3236, 0x3246, 0x3255, 0x3265,\n\t0x3274, 0x3284, 0x3293, 0x32A3, 0x32B2, 0x32C1, 0x32D0, 0x32E0,\n\t0x32EF, 0x32FE, 0x330D, 0x331D, 0x332C, 0x333B, 0x334A, 0x3359,\n\t0x3368, 0x3377, 0x3386, 0x3395, 0x33A3, 0x33B2, 0x33C1, 0x33D0,\n\t0x33DF, 0x33ED, 0x33FC, 0x340B, 0x3419, 0x3428, 0x3436, 0x3445,\n\t0x3453, 0x3462, 0x3470, 0x347F, 0x348D, 0x349B, 0x34AA, 0x34B8,\n\t0x34C6, 0x34D4, 0x34E2, 0x34F1, 0x34FF, 0x350D, 0x351B, 0x3529,\n\t0x3537, 0x3545, 0x3553, 0x3561, 0x356E, 0x357C, 0x358A, 0x3598,\n\t0x35A5, 0x35B3, 0x35C1, 0x35CE, 0x35DC, 0x35EA, 0x35F7, 0x3605,\n\t0x3612, 0x3620, 0x362D, 0x363A, 0x3648, 0x3655, 0x3662, 0x366F,\n\t0x367D, 0x368A, 0x3697, 0x36A4, 0x36B1, 0x36BE, 0x36CB, 0x36D8,\n\t0x36E5, 0x36F2, 0x36FF, 0x370C, 0x3718, 0x3725, 0x3732, 0x373F,\n\t0x374B, 0x3758, 0x3765, 0x3771, 0x377E, 0x378A, 0x3797, 0x37A3,\n\t0x37B0, 0x37BC, 0x37C8, 0x37D5, 0x37E1, 0x37ED, 0x37F9, 0x3805,\n\t0x3812, 0x381E, 0x382A, 0x3836, 0x3842, 0x384E, 0x385A, 0x3866,\n\t0x3871, 0x387D, 0x3889, 0x3895, 0x38A1, 0x38AC, 0x38B8, 0x38C3,\n\t0x38CF, 0x38DB, 0x38E6, 0x38F2, 0x38FD, 0x3909, 0x3914, 0x391F,\n\t0x392B, 0x3936, 0x3941, 0x394C, 0x3958, 0x3963, 0x396E, 0x3979,\n\t0x3984, 0x398F, 0x399A, 0x39A5, 0x39B0, 0x39BB, 0x39C5, 0x39D0,\n\t0x39DB, 0x39E6, 0x39F0, 0x39FB, 0x3A06, 0x3A10, 0x3A1B, 0x3A25,\n\t0x3A30, 0x3A3A, 0x3A45, 0x3A4F, 0x3A59, 0x3A64, 0x3A6E, 0x3A78,\n\t0x3A82, 0x3A8D, 0x3A97, 0x3AA1, 0x3AAB, 0x3AB5, 0x3ABF, 0x3AC9,\n\t0x3AD3, 0x3ADD, 0x3AE6, 0x3AF0, 0x3AFA, 0x3B04, 0x3B0E, 0x3B17,\n\t0x3B21, 0x3B2A, 0x3B34, 0x3B3E, 0x3B47, 0x3B50, 0x3B5A, 0x3B63,\n\t0x3B6D, 0x3B76, 0x3B7F, 0x3B88, 0x3B92, 0x3B9B, 0x3BA4, 0x3BAD,\n\t0x3BB6, 0x3BBF, 0x3BC8, 0x3BD1, 0x3BDA, 0x3BE3, 0x3BEC, 0x3BF5,\n\t0x3BFD, 0x3C06, 0x3C0F, 0x3C17, 0x3C20, 0x3C29, 0x3C31, 0x3C3A,\n\t0x3C42, 0x3C4B, 0x3C53, 0x3C5B, 0x3C64, 0x3C6C, 0x3C74, 0x3C7D,\n\t0x3C85, 0x3C8D, 0x3C95, 0x3C9D, 0x3CA5, 0x3CAD, 0x3CB5, 0x3CBD,\n\t0x3CC5, 0x3CCD, 0x3CD5, 0x3CDD, 0x3CE4, 0x3CEC, 0x3CF4, 0x3CFB,\n\t0x3D03, 0x3D0B, 0x3D12, 0x3D1A, 0x3D21, 0x3D28, 0x3D30, 0x3D37,\n\t0x3D3F, 0x3D46, 0x3D4D, 0x3D54, 0x3D5B, 0x3D63, 0x3D6A, 0x3D71,\n\t0x3D78, 0x3D7F, 0x3D86, 0x3D8D, 0x3D93, 0x3D9A, 0x3DA1, 0x3DA8,\n\t0x3DAF, 0x3DB5, 0x3DBC, 0x3DC2, 0x3DC9, 0x3DD0, 0x3DD6, 0x3DDD,\n\t0x3DE3, 0x3DE9, 0x3DF0, 0x3DF6, 0x3DFC, 0x3E03, 0x3E09, 0x3E0F,\n\t0x3E15, 0x3E1B, 0x3E21, 0x3E27, 0x3E2D, 0x3E33, 0x3E39, 0x3E3F,\n\t0x3E45, 0x3E4A, 0x3E50, 0x3E56, 0x3E5C, 0x3E61, 0x3E67, 0x3E6C,\n\t0x3E72, 0x3E77, 0x3E7D, 0x3E82, 0x3E88, 0x3E8D, 0x3E92, 0x3E98,\n\t0x3E9D, 0x3EA2, 0x3EA7, 0x3EAC, 0x3EB1, 0x3EB6, 0x3EBB, 0x3EC0,\n\t0x3EC5, 0x3ECA, 0x3ECF, 0x3ED4, 0x3ED8, 0x3EDD, 0x3EE2, 0x3EE7,\n\t0x3EEB, 0x3EF0, 0x3EF4, 0x3EF9, 0x3EFD, 0x3F02, 0x3F06, 0x3F0A,\n\t0x3F0F, 0x3F13, 0x3F17, 0x3F1C, 0x3F20, 0x3F24, 0x3F28, 0x3F2C,\n\t0x3F30, 0x3F34, 0x3F38, 0x3F3C, 0x3F40, 0x3F43, 0x3F47, 0x3F4B,\n\t0x3F4F, 0x3F52, 0x3F56, 0x3F5A, 0x3F5D, 0x3F61, 0x3F64, 0x3F68,\n\t0x3F6B, 0x3F6E, 0x3F72, 0x3F75, 0x3F78, 0x3F7B, 0x3F7F, 0x3F82,\n\t0x3F85, 0x3F88, 0x3F8B, 0x3F8E, 0x3F91, 0x3F94, 0x3F97, 0x3F99,\n\t0x3F9C, 0x3F9F, 0x3FA2, 0x3FA4, 0x3FA7, 0x3FAA, 0x3FAC, 0x3FAF,\n\t0x3FB1, 0x3FB4, 0x3FB6, 0x3FB8, 0x3FBB, 0x3FBD, 0x3FBF, 0x3FC1,\n\t0x3FC4, 0x3FC6, 0x3FC8, 0x3FCA, 0x3FCC, 0x3FCE, 0x3FD0, 0x3FD2,\n\t0x3FD4, 0x3FD5, 0x3FD7, 0x3FD9, 0x3FDB, 0x3FDC, 0x3FDE, 0x3FE0,\n\t0x3FE1, 0x3FE3, 0x3FE4, 0x3FE6, 0x3FE7, 0x3FE8, 0x3FEA, 0x3FEB,\n\t0x3FEC, 0x3FED, 0x3FEF, 0x3FF0, 0x3FF1, 0x3FF2, 0x3FF3, 0x3FF4,\n\t0x3FF5, 0x3FF6, 0x3FF7, 0x3FF7, 0x3FF8, 0x3FF9, 0x3FFA, 0x3FFA,\n\t0x3FFB, 0x3FFC, 0x3FFC, 0x3FFD, 0x3FFD, 0x3FFE, 0x3FFE, 0x3FFE,\n\t0x3FFF, 0x3FFF, 0x3FFF, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000,\n\t0x4000, 0x4000,\n};\n\nint __fastcall phd_atan(int x, int y) {\n\tint result;\n\tint swapBuf;\n\tint flags = 0;\n\n\tif( x == 0 && y == 0 )\n\t\treturn 0;\n\n\tif( x < 0 ) {\n\t\tflags |= 4;\n\t\tx = -x;\n\t}\n\n\tif( y < 0 ) {\n\t\tflags |= 2;\n\t\ty = -y;\n\t}\n\n\tif( y > x ) {\n\t\tflags |= 1;\n\t\tSWAP(x, y, swapBuf);\n\t}\n\n\tresult = AtanBaseTable[flags] + AtanAngleTable[0x800*y/x];\n\tif ( result < 0 )\n\t\tresult = -result;\n\n\treturn result;\n}\n\nint __fastcall phd_cos(__int16 angle) {\n\treturn phd_sin(angle + PHD_90);\n}\n\nint __fastcall phd_sin(__int16 angle) {\n\tUINT16 sector = (UINT16)angle & (PHD_180-1); // sector range will be: 0..0x7FFF (0..179.99 degrees)\n\n\tif( sector > PHD_90 )\n\t\tsector = PHD_180 - sector; // sector range will be: 0x0000..0x4000 (0..90 degrees)\n\n\tint result = PhdSinTable[sector/16];\n\n\tif( (UINT16)angle >= PHD_180 )\n\t\tresult = -result;\n\n\treturn result;\n}\n\nDWORD __fastcall phd_sqrt(DWORD n) {\n\tDWORD result = 0;\n\tDWORD base = 0x40000000;\n\tDWORD basedResult;\n\n\tfor( ; base != 0; base >>= 2 ) {\n\t\tfor( ; base != 0; base >>= 2 ) {\n\n\t\t\tbasedResult = base + result;\n\t\t\tresult >>= 1;\n\n\t\t\tif( basedResult > n ) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tn -= basedResult;\n\t\t\tresult |= base;\n\t\t}\n\t}\n\treturn result;\n}\n\n/*\n * Inject function\n */\nvoid Inject_PhdMath() {\n\tINJECT(0x00457EA0, phd_atan);\n\tINJECT(0x00457EE8, phd_cos);\n\tINJECT(0x00457EEE, phd_sin);\n\tINJECT(0x00457F23, phd_sqrt);\n}\n"
  },
  {
    "path": "3dsystem/phd_math.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef PHD_MATH_H_INCLUDED\n#define PHD_MATH_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nint __fastcall phd_atan(int x, int y); // 0x00457EA0\nint __fastcall phd_cos(__int16 angle); // 0x00457EE8\nint __fastcall phd_sin(__int16 angle); // 0x00457EEE\nDWORD __fastcall phd_sqrt(DWORD n); // 0x00457F23\n\n#endif // PHD_MATH_H_INCLUDED\n"
  },
  {
    "path": "3dsystem/scalespr.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"3dsystem/scalespr.h\"\n#include \"specific/output.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_VIEW_IMPROVED\nextern int CalculateFogShade(int depth);\n#endif // FEATURE_VIEW_IMPROVED\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nDWORD PickupItemMode = 1;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\nvoid __cdecl S_DrawSprite(DWORD flags, int x, int y, int z, __int16 spriteIdx, __int16 shade, __int16 scale) {\n\tint xv, yv, zv, zp, depth;\n\tint x1, y1, x2, y2;\n\n\tif( CHK_ANY(flags, SPR_ABS) ) { // absolute coords\n\t\tx -= MatrixW2V._03;\n\t\ty -= MatrixW2V._13;\n\t\tz -= MatrixW2V._23;\n\n\t\tif( x < -PhdViewDistance || x > PhdViewDistance )\n\t\t\treturn;\n\t\tif( y < -PhdViewDistance || y > PhdViewDistance)\n\t\t\treturn;\n\t\tif( z < -PhdViewDistance || z > PhdViewDistance)\n\t\t\treturn;\n\n\t\tzv = MatrixW2V._20 * x + MatrixW2V._21 * y + MatrixW2V._22 * z;\n\t\tif( zv < PhdNearZ || zv >= PhdFarZ )\n\t\t\treturn;\n\t\tyv = MatrixW2V._10 * x + MatrixW2V._11 * y + MatrixW2V._12 * z;\n\t\txv = MatrixW2V._00 * x + MatrixW2V._01 * y + MatrixW2V._02 * z;\n\n\t} else if( (x|y|z) == 0 ) { // zero point coords\n\t\tzv = PhdMatrixPtr->_23;\n\t\tif( zv < PhdNearZ || zv > PhdFarZ )\n\t\t\treturn;\n\t\tyv = PhdMatrixPtr->_13;\n\t\txv = PhdMatrixPtr->_03;\n\n\t} else { // relative coords\n\t\tzv = PhdMatrixPtr->_20 * x + PhdMatrixPtr->_21 * y + PhdMatrixPtr->_22 * z + PhdMatrixPtr->_23;\n\t\tif( zv < PhdNearZ || zv > PhdFarZ )\n\t\t\treturn;\n\t\tyv = PhdMatrixPtr->_10 * x + PhdMatrixPtr->_11 * y + PhdMatrixPtr->_12 * z + PhdMatrixPtr->_13;\n\t\txv = PhdMatrixPtr->_00 * x + PhdMatrixPtr->_01 * y + PhdMatrixPtr->_02 * z + PhdMatrixPtr->_03;\n\t}\n\n\tx1 = PhdSpriteInfo[spriteIdx].x1;\n\ty1 = PhdSpriteInfo[spriteIdx].y1;\n\tx2 = PhdSpriteInfo[spriteIdx].x2;\n\ty2 = PhdSpriteInfo[spriteIdx].y2;\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tif( PickupItemMode == 1 && CHK_ALL(flags, SPR_ITEM|SPR_ABS) ) {\n\t\tif( y1 < y2 ) {\n\t\t\ty1 -= y2;\n\t\t\ty2 = 0;\n\t\t} else {\n\t\t\ty2 -= y1;\n\t\t\ty1 = 0;\n\t\t}\n\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tif( CHK_ANY(flags, SPR_SCALE) ) { // scaling required\n\t\tx1 = (x1 * scale) << (W2V_SHIFT - 8);\n\t\ty1 = (y1 * scale) << (W2V_SHIFT - 8);\n\t\tx2 = (x2 * scale) << (W2V_SHIFT - 8);\n\t\ty2 = (y2 * scale) << (W2V_SHIFT - 8);\n\t} else { // default scale\n\t\tx1 <<= W2V_SHIFT;\n\t\ty1 <<= W2V_SHIFT;\n\t\tx2 <<= W2V_SHIFT;\n\t\ty2 <<= W2V_SHIFT;\n\t}\n\n\tzp = zv / PhdPersp;\n\n\tx1 = (x1 + xv) / zp + PhdWinCenterX;\n\tif( x1 >= PhdWinWidth )\n\t\treturn;\n\n\ty1 = (y1 + yv) / zp + PhdWinCenterY;\n\tif( y1 >= PhdWinHeight )\n\t\treturn;\n\n\tx2 = (x2 + xv) / zp + PhdWinCenterX;\n\tif( x2 < 0 )\n\t\treturn;\n\n\ty2 = (y2 + yv) / zp + PhdWinCenterY;\n\tif( y2 < 0 )\n\t\treturn;\n\n\tif( CHK_ANY(flags, SPR_SHADE) ) { // shading required\n\t\tdepth = zv >> W2V_SHIFT;\n#ifdef FEATURE_VIEW_IMPROVED\n\t\tif( depth > PhdViewDistance )\n\t\t\treturn;\n\n\t\tshade += CalculateFogShade(depth);\n\t\tCLAMP(shade, 0, 0x1FFF);\n#else // !FEATURE_VIEW_IMPROVED\n\t\tif( depth > DEPTHQ_START ) {\n\t\t\tshade += depth - DEPTHQ_START;\n\t\t\tif( shade > 0x1FFF ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n#endif // FEATURE_VIEW_IMPROVED\n\t} else {\n\t\tshade = 0x1000;\n\t}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tif( CHK_ANY(flags, SPR_TINT) && !CHK_ANY(flags, SPR_SHADE) ) {\n\t\t// NOTE: PS1 tint color brightness must be multiplied by 2 in this case\n\t\tshade = (shade > 0x1000) ? (shade-0x1000)*2 : 0;\n\t}\n\tins_sprite(zv, x1, y1, x2, y2, spriteIdx, shade, flags);\n#else // FEATURE_VIDEOFX_IMPROVED\n\tins_sprite(zv, x1, y1, x2, y2, spriteIdx, shade);\n#endif // FEATURE_VIDEOFX_IMPROVED\n}\n\nvoid __cdecl S_DrawPickup(int sx, int sy, int scale, __int16 spriteIdx, __int16 shade) {\n\tint x1, x2, y1, y2;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tscale = GetRenderScale(scale);\n#endif // FEATURE_HUD_IMPROVED\n\n\tx1 = sx + (PhdSpriteInfo[spriteIdx].x1 * scale / PHD_ONE);\n\tx2 = sx + (PhdSpriteInfo[spriteIdx].x2 * scale / PHD_ONE);\n\ty1 = sy + (PhdSpriteInfo[spriteIdx].y1 * scale / PHD_ONE);\n\ty2 = sy + (PhdSpriteInfo[spriteIdx].y2 * scale / PHD_ONE);\n\n\tif( x2 >= 0 && y2 >= 0 && x1 < PhdWinWidth && y1 < PhdWinHeight ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tins_sprite(200, x1, y1, x2, y2, spriteIdx, shade, 0);\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\tins_sprite(200, x1, y1, x2, y2, spriteIdx, shade);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t}\n}\n\n__int16 *__cdecl ins_room_sprite(__int16 *ptrObj, int vtxCount) {\n\tPHD_VBUF *vbuf;\n\tPHD_SPRITE *sprite;\n\tdouble zp;\n\tint x1, y1, x2, y2;\n\n\tfor( int i = 0; i < vtxCount; ++i ) {\n\t\tvbuf = &PhdVBuf[*ptrObj];\n\t\tif( (vbuf->clip & 0x80) == 0 ) {\n\t\t\tsprite = &PhdSpriteInfo[ptrObj[1]];\n\t\t\tzp = (double)vbuf->zv / (double)PhdPersp;\n\n\t\t\tx1 = (int)((vbuf->xv + (double)((int)sprite->x1 << W2V_SHIFT)) / zp) + PhdWinCenterX;\n\t\t\ty1 = (int)((vbuf->yv + (double)((int)sprite->y1 << W2V_SHIFT)) / zp) + PhdWinCenterY;\n\t\t\tx2 = (int)((vbuf->xv + (double)((int)sprite->x2 << W2V_SHIFT)) / zp) + PhdWinCenterX;\n\t\t\ty2 = (int)((vbuf->yv + (double)((int)sprite->y2 << W2V_SHIFT)) / zp) + PhdWinCenterY;\n\n\t\t\tif( x2 >= PhdWinLeft && y2 >= PhdWinTop && x1 < PhdWinRight && y1 < PhdWinBottom ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tins_sprite((int)vbuf->zv, x1, y1, x2, y2, ptrObj[1], vbuf->g, 0);\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tins_sprite((int)vbuf->zv, x1, y1, x2, y2, ptrObj[1], vbuf->g);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t}\n\t\t}\n\t\tptrObj += 2;\n\t}\n\treturn ptrObj;\n}\n\nvoid __cdecl S_DrawScreenSprite2d(int sx, int sy, int sz, int scaleH, int scaleV, __int16 spriteIdx, __int16 shade, UINT16 flags) {\n\tint x1, y1, x2, y2, z;\n\tPHD_SPRITE *sprite = &PhdSpriteInfo[spriteIdx];\n\n\tx1 = sx + sprite->x1 * scaleH / PHD_ONE;\n\ty1 = sy + sprite->y1 * scaleV / PHD_ONE;\n\tx2 = sx + sprite->x2 * scaleH / PHD_ONE;\n\ty2 = sy + sprite->y2 * scaleV / PHD_ONE;\n\tz = PhdNearZ + sz * 8;\n\n\tif( x2 >= 0 && y2 >= 0 && x1 < PhdWinWidth && y1 < PhdWinHeight ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tins_sprite(z, x1, y1, x2, y2, spriteIdx, shade, 0);\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\tins_sprite(z, x1, y1, x2, y2, spriteIdx, shade);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t}\n}\n\nvoid __cdecl S_DrawScreenSprite(int sx, int sy, int sz, int scaleH, int scaleV, __int16 spriteIdx, __int16 shade, UINT16 flags) {\n\tint x1, y1, x2, y2, z;\n\tPHD_SPRITE *sprite = &PhdSpriteInfo[spriteIdx];\n\n\tx1 = sx + (sprite->x1 / 8) * scaleH / PHD_ONE;\n\ty1 = sy + (sprite->y1 / 8) * scaleV / PHD_ONE;\n\tx2 = sx + (sprite->x2 / 8) * scaleH / PHD_ONE;\n\ty2 = sy + (sprite->y2 / 8) * scaleV / PHD_ONE;\n\tz = sz * 8;\n\n\tif( x2 >= 0 && y2 >= 0 && x1 < PhdWinWidth && y1 < PhdWinHeight ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tins_sprite(z, x1, y1, x2, y2, spriteIdx, shade, 0);\n#else // FEATURE_VIDEOFX_IMPROVED\n\t\tins_sprite(z, x1, y1, x2, y2, spriteIdx, shade);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t}\n}\n\nvoid __cdecl draw_scaled_spriteC(__int16 *ptrObj) {\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\textern int GetPitchSWR();\n\tint pitch = GetPitchSWR();\n#else // FEATURE_NOLEGACY_OPTIONS\n\tint pitch = PhdScreenWidth; // NOTE: this is the original game bug!\n#endif // FEATURE_NOLEGACY_OPTIONS\n\tint i, j;\n\tint x1, y1, x2, y2, width, height;\n\tint u, uBase, vBase, uAdd, vAdd;\n\t__int16 sprIdx, shade;\n\tBYTE *srcBase, *src, *dst;\n\tBYTE pix;\n\tint dstAdd;\n\tbool isDepthQ;\n\tPHD_SPRITE *sprite;\n\tDEPTHQ_ENTRY *depthQ;\n\n\tx1 = ptrObj[0];\n\ty1 = ptrObj[1];\n\tx2 = ptrObj[2];\n\ty2 = ptrObj[3];\n\tsprIdx = ptrObj[4];\n\tshade = ptrObj[5];\n\n\tif( x1 >= x2 || y1 >= y2 || x2 <= 0 || y2 <= 0 || x1 >= PhdWinMaxX || y1 >= PhdWinMaxY )\n\t\treturn;\n\n\tsprite = &PhdSpriteInfo[sprIdx];\n\tdepthQ = &DepthQTable[shade >> 8];\n\n\tuBase = vBase = 0x4000;\n\n\tuAdd = (sprite->width - 64) * 256 / (x2 - x1);\n\tvAdd = (sprite->height - 64) * 256 / (y2 - y1);\n\n\tif( x1 < 0 ) {\n\t\tuBase -= uAdd * x1;\n\t\tx1 = 0;\n\t}\n\n\tif( y1 < 0 ) {\n\t\tvBase -= vAdd * y1;\n\t\ty1 = 0;\n\t}\n\n\tCLAMPG(x2, PhdWinMaxX + 1);\n\tCLAMPG(y2, PhdWinMaxY + 1);\n\n\twidth = x2 - x1;\n\theight = y2 - y1;\n\n\tsrcBase = (BYTE *)TexturePageBuffer8[sprite->texPage] + sprite->offset;\n\tdst = PrintSurfacePtr + (PhdWinMinY + y1) * pitch + (PhdWinMinX + x1);\n\tdstAdd = pitch - width;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tisDepthQ = (depthQ != &DepthQTable[15]);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tisDepthQ = (GameVid_IsWindowedVga || depthQ != &DepthQTable[15]); // NOTE: index was 16 in the original code, this was wrong\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tfor( i = 0; i < height; ++i ) {\n\t\tu = uBase;\n\t\tsrc = srcBase + (vBase >> 16) * 256;\n\t\tfor( j = 0; j < width; ++j ) {\n\t\t\tpix = src[u >> 16];\n\t\t\tif( pix != 0 ) {\n\t\t\t\t*dst = ( isDepthQ ) ? depthQ->index[pix] : pix;\n\t\t\t}\n\t\t\tu += uAdd;\n\t\t\t++dst;\n\t\t}\n\t\tdst += dstAdd;\n\t\tvBase += vAdd;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_ScaleSpr() {\n\tINJECT(0x0040C030, S_DrawSprite);\n\tINJECT(0x0040C300, S_DrawPickup);\n\tINJECT(0x0040C390, ins_room_sprite);\n\tINJECT(0x0040C4F0, S_DrawScreenSprite2d);\n\tINJECT(0x0040C590, S_DrawScreenSprite);\n\tINJECT(0x0040C630, draw_scaled_spriteC);\n}\n"
  },
  {
    "path": "3dsystem/scalespr.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SCALESPR_H_INCLUDED\n#define SCALESPR_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl S_DrawSprite(DWORD flags, int x, int y, int z, __int16 spriteIdx, __int16 shade, __int16 scale); // 0x0040C030\nvoid __cdecl S_DrawPickup(int sx, int sy, int scale, __int16 spriteIdx, __int16 shade); // 0x0040C300\n__int16 *__cdecl ins_room_sprite(__int16 *ptrObj, int vtxCount); // 0x0040C390\nvoid __cdecl S_DrawScreenSprite2d(int sx, int sy, int sz, int scaleH, int scaleV, __int16 spriteIdx, __int16 shade, UINT16 flags); // 0x0040C4F0\nvoid __cdecl S_DrawScreenSprite(int sx, int sy, int sz, int scaleH, int scaleV, __int16 spriteIdx, __int16 shade, UINT16 flags); // 0x0040C590\nvoid __cdecl draw_scaled_spriteC(__int16 *ptrObj); // 0x0040C630\n\n#endif // SCALESPR_H_INCLUDED\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "\n# Changelog\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [Unreleased]\n\n## [0.9.0] - 2023-06-05\n### New features\n- The Golden Mask game is included into a release pack, since it's freeware. The original game level files must be officially obtained via Steam/GOG/CD/whatever.\n- Added DirectX 9 support. However, TR2Main can be compiled for DirectX 5 too.\n- Into TR2Main.dll added information about the current version. Now it will be easier to find out which DLL is which version.\n- The number of secrets in the script is taken into account when calculating the total number of secrets in the final statistics. Now it is calculated correctly, regardless of the total number of levels, bonus levels, and even mod levels.\n- Additional checks have been implemented to prevent Lara from getting weapons that are not supported by current level. Thus, a number of problems associated with the \"Nightmare in Vegas\" level are fixed.\n- Now *\"New Game+\"* is activated after the completion of the latest level in the script, and not any in which the final statistics appear. This allows you to activate this mode after the \"Nightmare in Vegas\" level, and not before.\n- Now you can start the game in Gold mode, specifying the option *\"-gold\"* on the command line or shortcut properties (in the same way as the *\"-setup\"* option).\n- For the Gold mode, Spider and Big Spider AI replaced by Wolf and Bear AI. Also Monk Spirits have no shadow.\n- For the Gold mode, the credits slideshow starts from *CREDIT00.PCX*. For the original game mode, it starts from *CREDIT01.PCX*.\n- For the Gold mode, the selection of any levels (including bonus levels) is activated after collecting all the secrets (available before the final statistics). The ability to select levels remains even after relaunching the game.\n- For the Gold mode, pictures with \"g\" filename suffix (TITLEg.PCX, LEGALg.PCX, etc.) have higher priority than pictures without \"g\" filename suffix (TITLE.PCX, LEGAL.PCX, etc.)\n- For the Gold mode, instead of the files *\"TOMBPC.DAT\"* and *\"MAIN.SFX\"*, the files *\"TOMBPCg.DAT\"* and *\"MAINg.SFX\"* are used. However, for both Gold and the original game, *\"MAIN.SFX\"* is still used for the *\"TITLE.TR2\"* and *\"ASSAULT.TR2\"* levels.\n- Added separate subfolders for saved games of Gold and the original game.\n- Added PlayStation reflection visual effect.\n- Z-Buffer is no longer required for PlayStation styled gradient health/air bars.\n- Added basic/advanced alpha blending for PlayStation styled semitransparent effects.\n- Added glow effect for gunfire/flare (alpha blending required).\n- Most sprites, gunfire/flare effects, sunglasses lens, the dragon spheres of doom are made semitransparent (alpha blending required). This is how they look in the PlayStation version.\n- Rolling wheel blades, wall mounted blades, swords of statues and flamethrower masks are made reflective. This is how they look in the PlayStation version.\n- The armed snowmobile windshield is made reflective. This is not presented in the PlayStation version, but probably it was supposed to be. Anyway it looks cool!\n- The original game fast snowmobile windshield is made semitransparent (alpha blending required). This is how it looks in the PlayStation version.\n- The Golden Mask fast snowmobile windshield is made reflective. In the Golden Mask it has the same windshield model as the armed snowmobile.\n- Boathouse Key and Library Key from Venice levels are made reflective. This is how they look in the PlayStation version.\n- The water surfaces and the glass on the sink in Lara's bathroom are made semitransparent (alpha blending required). This is how they look in the PlayStation version.\n- Chain-link fence texture from Venice levels and stained glass texture from \"Wreck of the Maria Doria\" level are made semitransparent (alpha blending required). This is how they look in the PlayStation version.\n- The glass on the sink in the \"Nightmare in Vegas\" level is made semitransparent (alpha blending required).\n- Added support for loading screens from the script.\n- Added TR2Main.json configuration file for easy game modding in the future.\n- Added support for loading screens from TR2Main.json configuration file.\n- Added support for custom water color from TR2Main.json configuration file.\n- Added support for barefoot steps SFX from TR2Main.json configuration file (BAREFOOT.SFX in the DATA folder required).\n- Added support for Legal/Title pictures with both US/EU logo (just a simple option to toggle between logo versions).\n- Remastered pictures (PNG/JPG/BMP) support can be disabled now. In this case the game will use only PCX pictures.\n- Custom HUD scale can be set to any value in 0.5 - 2.0 (previously it was limited by 1.0 - 2.0).\n- Added support for display resolutions higher than 2048x2048.\n- Background picture code is redesigned to support resolutions higher than 2048x2048.\n- The limitations of the game engine (textures, polygons) are expanded by 4 times for future TR2 mods.\n- Added music mute settings for inventory/underwater.\n- The music and cut scenes are paused when the game window is not active.\n- Added options for level statistics background mode (hardware renderer required).\n- Added full inventory cheat on *I* key (cheat flag in *\"TOMBPC.DAT\"* file required). It gives full health, all weapons, ammo, medipacks, flares and all keys.\n- Added Dozy cheat on *O* key (cheat flag in *\"TOMBPC.DAT\"* file required). It gives fly mode and full health, use *Shift* key to disable it.\n- Lara has golden skin while in Dozy mode (hardware renderer and reflection feature required).\n- SFX number limit increased from 256 to 370.\n- Added automatic cdaudio.dat fix for PaulD's CD Audio solution, if some track has wrong parameters (like in the Steam version).\n- Added possibility to customize semitransparent/reflective polygons via TR2Main.json configuration file.\n- Added the ability to side step hitting the *Left*/*Right* key while holding *Walk* key (optional feature).\n- Added possibility to hold up/down keys to quickly scroll through game menus.\n- Added a configurable number of saved game slots (16-24).\n- Joystick support completely migrated from WinAPI to DirectInput. Added XInput controllers support. Added DualShock 4 / DualSense support.\n- Joystick controls redesigned to use thumb sticks and D-Pad at the same time.\n- Added vibration feedback support for XInput gamepads and DualShock 4 / DualSense.\n- Added the light bar color feedback support for DualShock 4 / DualSense. The color changes depending from health and oxygen.\n- Passport text box height is adjusted depending from HUD scale.\n- Some legacy options are removed (Triple Buffer, Dither, Perspective Correction, Texel Adjustment, Disable 16 bit textures, Don't sort transparent polys).\n- Screen resolution settings reworked, now the game automatically selects between True Color / High Color.\n- Now the game correctly keeps proper resolutions when it switches between Windowed / Full Screen.\n- Implemented embedded textures for Keyboard/Joystick button sprites. There are 3 styles for Joystick buttons: Numeric, XBox, PlayStation.\n- Added arrows to PlayStation styled inventory text boxes.\n- Sound/Music volumes presented as gradient bars if PlayStation styled inventory text boxes are enabled. Also there are PlayStation styled SFX for changing volume.\n- Added PlayStation styled Joystick button hints for inventory (optional feature).\n- Added Pause feature (P key). Two styles are available: transparent and 50% darkened.\n- Controls text box completely redesigned. Now you can view both default and custom keyboard layouts on the same page. Joystick layout is now independent from the custom keyboard layout.\n- Fade out to black implemented for levels, demos, cut scenes and statistics.\n- Added an option to select Demo Mode text style: none, PC or PlayStation.\n- Now the inventory stopwatch (statistics item) position depends from HUD scale and Field of View options. So it looks both PlayStation and PC authentic.\n- The message is displayed when Bilinear Filter or Z-Buffer is toggled with F7/F8 hotkey (DirectX 9 only).\n- Added high contrast lighting (PlayStation style) for Hardware Renderer (DirectX 9 only).\n- Added low contrast lighting (Classic PC Hardware style) for Software Renderer.\n- Added F11 hotkey to toggle low/high contrast lighting (in the original game F11 was used to toggle Dither).\n- Sunset effect in Bartoli's Hideout now makes skybox a little darker.\n- Added \"Restart Level\" option (available only in case of Lara's death).\n- The inventory pattern (both static and animated) is seamless now for Bilinear Filter.\n- Added external HD textures support (DirectX 9 only).\n- Added iOS/Android texture pack full support (DirectX 9 only).\n- Added ffmpeg based FMV player.\n- Added loading screens by Lito Perezito for The Golden Mask.\n\n### The original game bugfixes\n- Fixed a bug that prevented the display of the save counter until the game relaunch, if the game was saved in an empty slot.\n- Fixed a bug that allowed the player to interfere with the control of the demo level.\n- Demo levels are excluded from the *\"New Game\"* menu, if the *\"Select Level\"* option is active.\n- Fixed the statistics reset in case of *\"New Game+\"*, if the *\"Select Level\"* option is active.\n- Fixed a bug that does not happen in the official levels (this situation is not in the script). Suppose a shotgun and shotgun ammo are set as a bonus for collecting all the secrets in the level. If Lara does not have a shotgun at the moment of picking the last secret, she receives the relying bonus, but the ammo items are not displayed on the screen. This is fixed now.\n- Fixed a bug that does not happen in the official levels (this situation is not in the script). Suppose a magnum and magnum ammo are set as a bonus for collecting all the secrets in the level. If Lara does not have a magnum at the moment of picking the last secret, she receives the magnum only, but not the magnum ammo. This is fixed now.\n- Fixed a bug that hid the ammo indicator in demo levels if *\"New Game+\"* is activated.\n- Fixed a bug that produced black triangles originating from the top left of the screen on some laptop graphic adapters.\n- Fixed a bug that produced traces of previous textures in untextured areas.\n- If \"Disable 16 bit textures\" option is unsupported, it's disabled automatically instead of breaking the textures.\n- Fixed a bug that changed the music volume incorrectly when leaving inventory while the camera is underwater.\n- Fixed a rare game crash occurring when you explode an enemy with a grenade launcher.\n- Fixed incorrect sorting of 3D polygons if Z-Buffer is turned off or the software renderer is used.\n- Fixed a bug due to which the skybox was not drawn in some rooms.\n- Fixed a bug where pickup sprites were cropped by the floor if Z-Buffer is enabled. Some pickup items are slightly raised (optional fix).\n- Fixed a bug due to which the last pressed key was accidentally assigned when redefining keys.\n- \"Run Control Panel\" button in the setup dialog now opens the current DirectInput joystick configuration from Control Panel instead of Control Panel itself.\n- Fixed a bug that caused the harpoon gun to reload every single shot in *\"New Game+\"* after a weapon cheat was used.\n- Fixed a bug due to which none of the joystick buttons allowed returning to the previous menu. Now the button assigned to \"Draw weapon\" is used for this.\n- Fixed a bug due to which the accuracy of the M16 did not decrease while running (optional fix).\n- Fixed a wrong inventory text position if the game window size is changed. \n- Fixed a flashing \"Demo Mode\" text while demo is playing. \n- The *low ceiling jump* bugfix is optional now.\n- Fixed a bug due to which non-textured surfaces could appear brighter than textured ones with the same lighting settings.\n- Fixed a bug that reset timer of sunset effect in Bartoli's Hideout after saved game is loaded.\n\n### TR2Main bugfixes\n- Background capture is optimized even more, now it is 3-4 times faster than v0.8.2. No lags anymore (broken since v0.8.0).\n- Fixed game crash in Software Rendered mode with PlayStation styled inventory text box enabled (broken since v0.8.0).\n- Fixed a rare game crash occurring when launching the game (broken since v0.1.0).\n- Fixed sunset effect in Bartoli's Hideout level (broken since v0.1.0).\n- Fixed texel adjustment if the filtering is changed by *F8* hotkey while \"Adjust when bilinear filtering\" option is enabled (broken since v0.1.0).\n- Now the PaulD's CD Audio is paused when the music volume is set to 0. This is how real CD Audio works (broken since v0.2.0).\n- Fixed \"Gosh! That was my best time yet!\" phrase in the case if it's a first try after game launch, but the time is not the best at all (broken since v0.5.0).\n- Fixed a bug when some underwater objects were untinted (broken since v0.1.0).\n- Fixed camera stabilization in some cut scenes (broken since v0.1.0).\n- Fixed the \"Microphone Position at Lara\" setting (broken since v0.1.0).\n- Changed randomizer formula to be less correct, but consistent with the original game (broken since v0.1.0).\n\n## [0.8.2] - 2019-05-26\n### TR2Main bugfixes\n- Background capture is redesigned, now it's fast again (broken since v0.8.0).\n- Background capture is processed only when required (broken since v0.8.0).\n- Fixed PlayStation styled field of view (broken since v0.8.0).\n\n## [0.8.1] - 2018-10-21\n### The original game bugfixes\n- Fixed texture corruption after FMV scenes.\n- Fixed the game hangup if the game window is closed on the statistics screen.\n### TR2Main bugfixes\n- Level statistics background properly fades out now (broken since v0.8.0).\n\n## [0.8.0] - 2018-09-25\n### New features\n- Added automatic blocking of incompatible video modes that caused the game to crash.\n- The resolution limit is set to 2048x2048, since DirectX 5 cannot handle more.\n- Changed the default aspect ratio from 1:1 to 4:3 for the windowed mode with the \"any aspect\" in the setup dialog.\n- Added possibility to use up to 99 images in the credits slideshow. The original game limit is 9 images.\n- Added support for HD PCX images (up to 2048x2048). The original game supported only 640x480 images.\n- Added stretch limit control for background picture (optional feature).\n- Added PNG/JPEG/BMP images support (hardware renderer required).\n- Added *PIX* folder for automatic management of pictures with different aspect ratios.\n- Added PNG screenshots with date-time filename format (optional feature). TGA/PCX screenshots retained the sequential filename format.\n- Added setting to specify a user directory for saving screenshots files.\n- Added edge padding instead of UV adjustment for background textures.\n- Now *\"end\"* picture is used for the final statistics background.\n- Added fade in/out between scenes.\n- Added TR1 styled transparent inventory background for hardware renderer (optional feature). This background is also used for level statistics like in the PlayStation version even if not set as inventory background.\n- Text box requester line height is slightly reduced to be more compact.\n- Added PlayStation styled inventory text box (optional feature).\n### The original game bugfixes\n- Fixed the original game bug when the health bar is visible at the beginning of the final bath scene.\n- Screenshots now work properly in the windowed mode in modern Windows systems.\n- Screen tearing does not affect screenshots for the windowed mode anymore.\n- Fixed an issue where the final bath scene is cut off. Now it fades out like in the PlayStation version.\n- Text box frame is slightly adjusted to fill gaps in the corners.\n### TR2Main bugfixes\n- Fixed incorrect underwater fog settings (broken since v0.4.0).\n- Fixed a minor issue related with clipping of round shadows (broken since v0.7.0).\n- Fixed clipping of animated background textures (broken since v0.3.0).\n\n## [0.7.0] - 2018-07-28\n### New features\n- Added round shadows instead of octagonal (optional feature).\n### The original game bugfixes\n- Fixed shadow clipping if the Z-Buffer is turned on.\n- Fixed a rare bug that caused black sprites to appear in bright rooms.\n### TR2Main bugfixes\n- Fixed a bug that caused invisibility of pitch black sprites (broken since v0.4.0).\n\n## [0.6.0] - 2018-02-24\n### New features\n- Custom HUD scaling options separated for the inventory and in-game (optional feature).\n### The original game bugfixes\n- The size of the active screen area should always be 1.0 for credits and final statistics.\n### TR2Main bugfixes\n- Health bar coordinates slightly corrected in the inventory for the PlayStation position style (broken since v0.5.0).\n\n## [0.5.0] - 2018-02-17\n### New features\n- Improved optimization of the perspective correction for the software renderer (up to 2x faster than the original game code)\n- Text is unstretched for any display modes.\n- Added automatic scaling of text box borders depending on the current screen resolution.\n- Added automatic scaling of the assault course timer depending on the current screen resolution.\n- The best results of assault course are saved in the registry and are not reset after relaunching the game.\n- The health/air bar accuracy increased for higher resolutions.\n- Added PlayStation styled health bar position (optional feature).\n- Added custom HUD scaling options (optional feature).\n- Added simplified gradient health/air bars (optional feature; hardware renderer and Z-Buffer required).\n### The original game bugfixes\n- Fixed texel adjustment if the renderer is changed by *Shift+F12* hotkey.\n- Fixed untextured polygon sorting for the software renderer.\n- Other minor bugfixes of the renderer.\n### TR2Main bugfixes\n- Fixed cheat sequences (broken since v0.1.0).\n\n## [0.4.0] - 2018-01-05\n### New features\n- Added draw distance and fog settings (optional feature).\n### TR2Main bugfixes\n- Fixed texture minification filtering (broken since v0.1.0).\n- Fixed Z-Buffer for animated background of the inventory (broken since v0.3.0).\n- Fixed *\"Select level\"* option (broken since v0.1.0).\n\n## [0.3.0] - 2018-01-03\n### New features\n- Added PlayStation styled field of view (optional feature).\n- Added PlayStation styled gradient health/air bars (optional feature; hardware renderer and Z-Buffer required).\n- Added PlayStation styled (animated) background of the inventory (optional feature; hardware renderer required).\n- Tiled static background of the inventory is unstretched for any display modes.\n### The original game bugfixes\n- Fixed a rare game crash occurring when exiting the game while playing CD Audio.\n### TR2Main bugfixes\n- Fixed back-face culling if the Z-Buffer is turned on (broken since v0.1.0).\n- Fixed a bug that prevented collecting more than one item of each type in the inventory (broken since v0.1.0).\n- Fixed a minor bug with looped tracks in the PaulD's CD Audio solution code (broken since v0.2.0).\n\n## [0.2.0] - 2017-12-31\n### New features\n- The TGA screenshot captures the game window instead of the whole screen in the case of windowed mode.\n- Added PaulD's CD Audio solution. Now the game supports *cdaudio.mp3* / *cdaudio.dat* music package. Just put it into *audio* folder in the game installation directory.\n### The original game bugfixes\n- Fixed default/custom keyboard layout conflicts when starting the game without visiting the controls menu.\n### TR2Main bugfixes\n- Z-Buffer depth priority reverted to original 16/24/32/8 due to the *\"CreateZBuffer\"* errors on some systems (broken since v0.1.0).\n- Screenshot key is set to *BackSpace* (previously it was *PrintScreen*) to fix problems on some systems (broken since v0.1.0).\n- Fixed CD Audio synchronization bug (broken since v0.1.0).\n\n## [0.1.0] - 2017-12-25\n### New features\n- Added NoCD patch. It is required that the *DATA* and *FMV* folders are located in the game installation folder, and not on the CD.\n- Added automatic adjustment of aspect ratio and field of view, depending on the current screen resolution.\n- Added automatic scaling of picked up items depending on the current screen resolution.\n- Added automatic scaling of secrets (dragons) in the level statistics menu depending on the current screen resolution.\n- Added automatic scaling of the health/air bars depending on the current screen resolution.\n- Video modes in the setup dialog are now sorted by depth, width and height.\n- Screenshot files are now created in the *screenshots* subfolder, not the game installation folder itself.\n- TGA screenshots are now available for 24/32-bit video modes. Not just for 16-bit video modes, as it was in the original game.\n- Screenshot key is set to *PrintScreen*. In the original game, it's set to the *S* key, which makes it unacceptable to map *S* key with another action.\n- ~~Z-Buffer depth priority set to 32/24/16/8 bits to improve rendering quality if a 32-bit Z-Buffer is available. In the original game, it is 16/24/32/8~~ (reverted in v0.2.0).\n### The original game bugfixes\n- Fixed incorrect parameters of the game window, leading to the appearance of unwanted borders in full screen mode.\n- The default music volume level is set to 10/10.  In the original game, the default value is 165/10, which leads to the absence of music until the volume level is adjusted in the game menu.\n- Fixed the *low ceiling jump* bug that was present in the early releases of the Tomb Raider II.  In later versions, Core Design fixed it.\n- Fixed a bug that caused some graphic objects to disappear or flicker if the Z-Buffer is turned off.\n- Fixed a bug leading to a non-responsive keyboard when switching to another Windows application or launching a game using Wine under Linux.\n- Removed repeating actions caused by a single hotkey keystroke (F1, F2, F12, Screenshot key). One keystroke - one action!\n- Fixed the problem when the game overwrites the screenshot files made in previous launches of the game.\n- Fixed unsafe memory management in the screenshot function, which caused the game to crash at higher screen resolutions.\n- Fixed incorrect TGA screenshot creation. In the original game, the bottom line of pixels is filled with junk.\n\n[Unreleased]: https://github.com/Arsunt/TR2Main/compare/v0.9.0...HEAD\n[0.9.0]: https://github.com/Arsunt/TR2Main/compare/v0.8.2...v0.9.0\n[0.8.2]: https://github.com/Arsunt/TR2Main/compare/v0.8.1...v0.8.2\n[0.8.1]: https://github.com/Arsunt/TR2Main/compare/v0.8.0...v0.8.1\n[0.8.0]: https://github.com/Arsunt/TR2Main/compare/v0.7.0...v0.8.0\n[0.7.0]: https://github.com/Arsunt/TR2Main/compare/v0.6.0...v0.7.0\n[0.6.0]: https://github.com/Arsunt/TR2Main/compare/v0.5.0...v0.6.0\n[0.5.0]: https://github.com/Arsunt/TR2Main/compare/v0.4.0...v0.5.0\n[0.4.0]: https://github.com/Arsunt/TR2Main/compare/v0.3.0...v0.4.0\n[0.3.0]: https://github.com/Arsunt/TR2Main/compare/v0.2.0...v0.3.0\n[0.2.0]: https://github.com/Arsunt/TR2Main/compare/v0.1.0...v0.2.0\n[0.1.0]: https://github.com/Arsunt/TR2Main/releases/tag/v0.1.0"
  },
  {
    "path": "COPYING.md",
    "content": "GNU GENERAL PUBLIC LICENSE\n==========================\nVersion 3, 29 June 2007\n==========================\n\n> Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>  \n  Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.\n\n# Preamble\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n# TERMS AND CONDITIONS\n\n## 0. Definitions.\n\n  _\"This License\"_ refers to version 3 of the GNU General Public License.\n\n  _\"Copyright\"_ also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  _\"The Program\"_ refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as _\"you\"_.  _\"Licensees\"_ and\n\"recipients\" may be individuals or organizations.\n\n  To _\"modify\"_ a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a _\"modified version\"_ of the\nearlier work or a work _\"based on\"_ the earlier work.\n\n  A _\"covered work\"_ means either the unmodified Program or a work based\non the Program.\n\n  To _\"propagate\"_ a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To _\"convey\"_ a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n## 1. Source Code.\n\n  The _\"source code\"_ for a work means the preferred form of the work\nfor making modifications to it. _\"Object code\"_ means any non-source\nform of a work.\n\n  A _\"Standard Interface\"_ means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The _\"System Libraries\"_ of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The _\"Corresponding Source\"_ for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n## 2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n## 3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n## 4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n## 5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n## 6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A _\"User Product\"_ is either (1) a _\"consumer product\"_, which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  _\"Installation Information\"_ for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n## 7. Additional Terms.\n\n  _\"Additional permissions\"_ are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n## 8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n## 9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n## 10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An _\"entity transaction\"_ is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n## 11. Patents.\n\n  A _\"contributor\"_ is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's _\"essential patent claims\"_ are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n## 12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n## 13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n## 14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n## 15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n## 16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n## 17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n# END OF TERMS AND CONDITIONS\n--------------------------------------------------------------------------\n\n\n# How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type 'show c' for details.\n\n  The hypothetical commands _'show w'_ and _'show c'_ should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n"
  },
  {
    "path": "Doxyfile",
    "content": "# Doxyfile 1.8.13\n\n# This file describes the settings to be used by the documentation system\n# doxygen (www.doxygen.org) for a project.\n#\n# All text after a double hash (##) is considered a comment and is placed in\n# front of the TAG it is preceding.\n#\n# All text after a single hash (#) is considered a comment and will be ignored.\n# The format is:\n# TAG = value [value, ...]\n# For lists, items can also be appended using:\n# TAG += value [value, ...]\n# Values that contain spaces should be placed between quotes (\\\" \\\").\n\n#---------------------------------------------------------------------------\n# Project related configuration options\n#---------------------------------------------------------------------------\n\n# This tag specifies the encoding used for all characters in the config file\n# that follow. The default is UTF-8 which is also the encoding used for all text\n# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv\n# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv\n# for the list of possible encodings.\n# The default value is: UTF-8.\n\nDOXYFILE_ENCODING      = UTF-8\n\n# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by\n# double-quotes, unless you are using Doxywizard) that should identify the\n# project for which the documentation is generated. This name is used in the\n# title of most generated pages and in a few other places.\n# The default value is: My Project.\n\nPROJECT_NAME           = \"TR2Main by Arsunt\"\n\n# The PROJECT_NUMBER tag can be used to enter a project or revision number. This\n# could be handy for archiving the generated documentation or if some version\n# control system is used.\n\nPROJECT_NUMBER         = \n\n# Using the PROJECT_BRIEF tag one can provide an optional one line description\n# for a project that appears at the top of each page and should give viewer a\n# quick idea about the purpose of the project. Keep the description short.\n\nPROJECT_BRIEF          = \"Dynamic Linked Library implementing Tomb Raider 2 graphics\"\n\n# With the PROJECT_LOGO tag one can specify a logo or an icon that is included\n# in the documentation. The maximum height of the logo should not exceed 55\n# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy\n# the logo to the output directory.\n\nPROJECT_LOGO           = ./logo.png\n\n# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path\n# into which the generated documentation will be written. If a relative path is\n# entered, it will be relative to the location where doxygen was started. If\n# left blank the current directory will be used.\n\nOUTPUT_DIRECTORY       = ./doc\n\n# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-\n# directories (in 2 levels) under the output directory of each output format and\n# will distribute the generated files over these directories. Enabling this\n# option can be useful when feeding doxygen a huge amount of source files, where\n# putting all generated files in the same directory would otherwise causes\n# performance problems for the file system.\n# The default value is: NO.\n\nCREATE_SUBDIRS         = NO\n\n# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII\n# characters to appear in the names of generated files. If set to NO, non-ASCII\n# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode\n# U+3044.\n# The default value is: NO.\n\nALLOW_UNICODE_NAMES    = NO\n\n# The OUTPUT_LANGUAGE tag is used to specify the language in which all\n# documentation generated by doxygen is written. Doxygen will use this\n# information to generate all constant output in the proper language.\n# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,\n# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),\n# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,\n# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),\n# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,\n# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,\n# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,\n# Ukrainian and Vietnamese.\n# The default value is: English.\n\nOUTPUT_LANGUAGE        = English\n\n# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member\n# descriptions after the members that are listed in the file and class\n# documentation (similar to Javadoc). Set to NO to disable this.\n# The default value is: YES.\n\nBRIEF_MEMBER_DESC      = YES\n\n# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief\n# description of a member or function before the detailed description\n#\n# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the\n# brief descriptions will be completely suppressed.\n# The default value is: YES.\n\nREPEAT_BRIEF           = YES\n\n# This tag implements a quasi-intelligent brief description abbreviator that is\n# used to form the text in various listings. Each string in this list, if found\n# as the leading text of the brief description, will be stripped from the text\n# and the result, after processing the whole list, is used as the annotated\n# text. Otherwise, the brief description is used as-is. If left blank, the\n# following values are used ($name is automatically replaced with the name of\n# the entity):The $name class, The $name widget, The $name file, is, provides,\n# specifies, contains, represents, a, an and the.\n\nABBREVIATE_BRIEF       = \"The $name class\" \\\n                         \"The $name widget\" \\\n                         \"The $name file\" \\\n                         is \\\n                         provides \\\n                         specifies \\\n                         contains \\\n                         represents \\\n                         a \\\n                         an \\\n                         the\n\n# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then\n# doxygen will generate a detailed section even if there is only a brief\n# description.\n# The default value is: NO.\n\nALWAYS_DETAILED_SEC    = NO\n\n# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all\n# inherited members of a class in the documentation of that class as if those\n# members were ordinary class members. Constructors, destructors and assignment\n# operators of the base classes will not be shown.\n# The default value is: NO.\n\nINLINE_INHERITED_MEMB  = NO\n\n# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path\n# before files name in the file list and in the header files. If set to NO the\n# shortest path that makes the file name unique will be used\n# The default value is: YES.\n\nFULL_PATH_NAMES        = YES\n\n# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.\n# Stripping is only done if one of the specified strings matches the left-hand\n# part of the path. The tag can be used to show relative paths in the file list.\n# If left blank the directory from which doxygen is run is used as the path to\n# strip.\n#\n# Note that you can specify absolute paths here, but also relative paths, which\n# will be relative from the directory where doxygen is started.\n# This tag requires that the tag FULL_PATH_NAMES is set to YES.\n\nSTRIP_FROM_PATH        = \n\n# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the\n# path mentioned in the documentation of a class, which tells the reader which\n# header file to include in order to use a class. If left blank only the name of\n# the header file containing the class definition is used. Otherwise one should\n# specify the list of include paths that are normally passed to the compiler\n# using the -I flag.\n\nSTRIP_FROM_INC_PATH    = \n\n# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but\n# less readable) file names. This can be useful is your file systems doesn't\n# support long names like on DOS, Mac, or CD-ROM.\n# The default value is: NO.\n\nSHORT_NAMES            = NO\n\n# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the\n# first line (until the first dot) of a Javadoc-style comment as the brief\n# description. If set to NO, the Javadoc-style will behave just like regular Qt-\n# style comments (thus requiring an explicit @brief command for a brief\n# description.)\n# The default value is: NO.\n\nJAVADOC_AUTOBRIEF      = NO\n\n# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first\n# line (until the first dot) of a Qt-style comment as the brief description. If\n# set to NO, the Qt-style will behave just like regular Qt-style comments (thus\n# requiring an explicit \\brief command for a brief description.)\n# The default value is: NO.\n\nQT_AUTOBRIEF           = NO\n\n# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a\n# multi-line C++ special comment block (i.e. a block of //! or /// comments) as\n# a brief description. This used to be the default behavior. The new default is\n# to treat a multi-line C++ comment block as a detailed description. Set this\n# tag to YES if you prefer the old behavior instead.\n#\n# Note that setting this tag to YES also means that rational rose comments are\n# not recognized any more.\n# The default value is: NO.\n\nMULTILINE_CPP_IS_BRIEF = NO\n\n# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the\n# documentation from any documented member that it re-implements.\n# The default value is: YES.\n\nINHERIT_DOCS           = YES\n\n# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new\n# page for each member. If set to NO, the documentation of a member will be part\n# of the file/class/namespace that contains it.\n# The default value is: NO.\n\nSEPARATE_MEMBER_PAGES  = NO\n\n# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen\n# uses this value to replace tabs by spaces in code fragments.\n# Minimum value: 1, maximum value: 16, default value: 4.\n\nTAB_SIZE               = 4\n\n# This tag can be used to specify a number of aliases that act as commands in\n# the documentation. An alias has the form:\n# name=value\n# For example adding\n# \"sideeffect=@par Side Effects:\\n\"\n# will allow you to put the command \\sideeffect (or @sideeffect) in the\n# documentation, which will result in a user-defined paragraph with heading\n# \"Side Effects:\". You can put \\n's in the value part of an alias to insert\n# newlines.\n\nALIASES                = \n\n# This tag can be used to specify a number of word-keyword mappings (TCL only).\n# A mapping has the form \"name=value\". For example adding \"class=itcl::class\"\n# will allow you to use the command class in the itcl::class meaning.\n\nTCL_SUBST              = \n\n# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources\n# only. Doxygen will then generate output that is more tailored for C. For\n# instance, some of the names that are used will be different. The list of all\n# members will be omitted, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_FOR_C  = YES\n\n# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or\n# Python sources only. Doxygen will then generate output that is more tailored\n# for that language. For instance, namespaces will be presented as packages,\n# qualified scopes will look different, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_JAVA   = NO\n\n# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran\n# sources. Doxygen will then generate output that is tailored for Fortran.\n# The default value is: NO.\n\nOPTIMIZE_FOR_FORTRAN   = NO\n\n# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL\n# sources. Doxygen will then generate output that is tailored for VHDL.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_VHDL   = NO\n\n# Doxygen selects the parser to use depending on the extension of the files it\n# parses. With this tag you can assign which parser to use for a given\n# extension. Doxygen has a built-in mapping, but you can override or extend it\n# using this tag. The format is ext=language, where ext is a file extension, and\n# language is one of the parsers supported by doxygen: IDL, Java, Javascript,\n# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran:\n# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran:\n# Fortran. In the later case the parser tries to guess whether the code is fixed\n# or free formatted code, this is the default for Fortran type files), VHDL. For\n# instance to make doxygen treat .inc files as Fortran files (default is PHP),\n# and .f files as C (default is Fortran), use: inc=Fortran f=C.\n#\n# Note: For files without extension you can use no_extension as a placeholder.\n#\n# Note that for custom extensions you also need to set FILE_PATTERNS otherwise\n# the files are not read by doxygen.\n\nEXTENSION_MAPPING      = \n\n# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments\n# according to the Markdown format, which allows for more readable\n# documentation. See http://daringfireball.net/projects/markdown/ for details.\n# The output of markdown processing is further processed by doxygen, so you can\n# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in\n# case of backward compatibilities issues.\n# The default value is: YES.\n\nMARKDOWN_SUPPORT       = YES\n\n# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up\n# to that level are automatically included in the table of contents, even if\n# they do not have an id attribute.\n# Note: This feature currently applies only to Markdown headings.\n# Minimum value: 0, maximum value: 99, default value: 0.\n# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.\n\nTOC_INCLUDE_HEADINGS   = 0\n\n# When enabled doxygen tries to link words that correspond to documented\n# classes, or namespaces to their corresponding documentation. Such a link can\n# be prevented in individual cases by putting a % sign in front of the word or\n# globally by setting AUTOLINK_SUPPORT to NO.\n# The default value is: YES.\n\nAUTOLINK_SUPPORT       = YES\n\n# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want\n# to include (a tag file for) the STL sources as input, then you should set this\n# tag to YES in order to let doxygen match functions declarations and\n# definitions whose arguments contain STL classes (e.g. func(std::string);\n# versus func(std::string) {}). This also make the inheritance and collaboration\n# diagrams that involve STL classes more complete and accurate.\n# The default value is: NO.\n\nBUILTIN_STL_SUPPORT    = NO\n\n# If you use Microsoft's C++/CLI language, you should set this option to YES to\n# enable parsing support.\n# The default value is: NO.\n\nCPP_CLI_SUPPORT        = NO\n\n# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:\n# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen\n# will parse them like normal C++ but will assume all classes use public instead\n# of private inheritance when no explicit protection keyword is present.\n# The default value is: NO.\n\nSIP_SUPPORT            = NO\n\n# For Microsoft's IDL there are propget and propput attributes to indicate\n# getter and setter methods for a property. Setting this option to YES will make\n# doxygen to replace the get and set methods by a property in the documentation.\n# This will only work if the methods are indeed getting or setting a simple\n# type. If this is not the case, or you want to show the methods anyway, you\n# should set this option to NO.\n# The default value is: YES.\n\nIDL_PROPERTY_SUPPORT   = YES\n\n# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC\n# tag is set to YES then doxygen will reuse the documentation of the first\n# member in the group (if any) for the other members of the group. By default\n# all members of a group must be documented explicitly.\n# The default value is: NO.\n\nDISTRIBUTE_GROUP_DOC   = NO\n\n# If one adds a struct or class to a group and this option is enabled, then also\n# any nested class or struct is added to the same group. By default this option\n# is disabled and one has to add nested compounds explicitly via \\ingroup.\n# The default value is: NO.\n\nGROUP_NESTED_COMPOUNDS = NO\n\n# Set the SUBGROUPING tag to YES to allow class member groups of the same type\n# (for instance a group of public functions) to be put as a subgroup of that\n# type (e.g. under the Public Functions section). Set it to NO to prevent\n# subgrouping. Alternatively, this can be done per class using the\n# \\nosubgrouping command.\n# The default value is: YES.\n\nSUBGROUPING            = YES\n\n# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions\n# are shown inside the group in which they are included (e.g. using \\ingroup)\n# instead of on a separate page (for HTML and Man pages) or section (for LaTeX\n# and RTF).\n#\n# Note that this feature does not work in combination with\n# SEPARATE_MEMBER_PAGES.\n# The default value is: NO.\n\nINLINE_GROUPED_CLASSES = NO\n\n# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions\n# with only public data fields or simple typedef fields will be shown inline in\n# the documentation of the scope in which they are defined (i.e. file,\n# namespace, or group documentation), provided this scope is documented. If set\n# to NO, structs, classes, and unions are shown on a separate page (for HTML and\n# Man pages) or section (for LaTeX and RTF).\n# The default value is: NO.\n\nINLINE_SIMPLE_STRUCTS  = NO\n\n# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or\n# enum is documented as struct, union, or enum with the name of the typedef. So\n# typedef struct TypeS {} TypeT, will appear in the documentation as a struct\n# with name TypeT. When disabled the typedef will appear as a member of a file,\n# namespace, or class. And the struct will be named TypeS. This can typically be\n# useful for C code in case the coding convention dictates that all compound\n# types are typedef'ed and only the typedef is referenced, never the tag name.\n# The default value is: NO.\n\nTYPEDEF_HIDES_STRUCT   = NO\n\n# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This\n# cache is used to resolve symbols given their name and scope. Since this can be\n# an expensive process and often the same symbol appears multiple times in the\n# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small\n# doxygen will become slower. If the cache is too large, memory is wasted. The\n# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range\n# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536\n# symbols. At the end of a run doxygen will report the cache usage and suggest\n# the optimal cache size from a speed point of view.\n# Minimum value: 0, maximum value: 9, default value: 0.\n\nLOOKUP_CACHE_SIZE      = 0\n\n#---------------------------------------------------------------------------\n# Build related configuration options\n#---------------------------------------------------------------------------\n\n# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in\n# documentation are documented, even if no documentation was available. Private\n# class members and static file members will be hidden unless the\n# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.\n# Note: This will also disable the warnings about undocumented members that are\n# normally produced when WARNINGS is set to YES.\n# The default value is: NO.\n\nEXTRACT_ALL            = NO\n\n# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will\n# be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PRIVATE        = NO\n\n# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal\n# scope will be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PACKAGE        = NO\n\n# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be\n# included in the documentation.\n# The default value is: NO.\n\nEXTRACT_STATIC         = NO\n\n# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined\n# locally in source files will be included in the documentation. If set to NO,\n# only classes defined in header files are included. Does not have any effect\n# for Java sources.\n# The default value is: YES.\n\nEXTRACT_LOCAL_CLASSES  = YES\n\n# This flag is only useful for Objective-C code. If set to YES, local methods,\n# which are defined in the implementation section but not in the interface are\n# included in the documentation. If set to NO, only methods in the interface are\n# included.\n# The default value is: NO.\n\nEXTRACT_LOCAL_METHODS  = NO\n\n# If this flag is set to YES, the members of anonymous namespaces will be\n# extracted and appear in the documentation as a namespace called\n# 'anonymous_namespace{file}', where file will be replaced with the base name of\n# the file that contains the anonymous namespace. By default anonymous namespace\n# are hidden.\n# The default value is: NO.\n\nEXTRACT_ANON_NSPACES   = NO\n\n# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all\n# undocumented members inside documented classes or files. If set to NO these\n# members will be included in the various overviews, but no documentation\n# section is generated. This option has no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_MEMBERS     = NO\n\n# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all\n# undocumented classes that are normally visible in the class hierarchy. If set\n# to NO, these classes will be included in the various overviews. This option\n# has no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_CLASSES     = NO\n\n# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend\n# (class|struct|union) declarations. If set to NO, these declarations will be\n# included in the documentation.\n# The default value is: NO.\n\nHIDE_FRIEND_COMPOUNDS  = NO\n\n# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any\n# documentation blocks found inside the body of a function. If set to NO, these\n# blocks will be appended to the function's detailed documentation block.\n# The default value is: NO.\n\nHIDE_IN_BODY_DOCS      = NO\n\n# The INTERNAL_DOCS tag determines if documentation that is typed after a\n# \\internal command is included. If the tag is set to NO then the documentation\n# will be excluded. Set it to YES to include the internal documentation.\n# The default value is: NO.\n\nINTERNAL_DOCS          = NO\n\n# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file\n# names in lower-case letters. If set to YES, upper-case letters are also\n# allowed. This is useful if you have classes or files whose names only differ\n# in case and if your file system supports case sensitive file names. Windows\n# and Mac users are advised to set this option to NO.\n# The default value is: system dependent.\n\nCASE_SENSE_NAMES       = NO\n\n# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with\n# their full class and namespace scopes in the documentation. If set to YES, the\n# scope will be hidden.\n# The default value is: NO.\n\nHIDE_SCOPE_NAMES       = YES\n\n# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will\n# append additional text to a page's title, such as Class Reference. If set to\n# YES the compound reference will be hidden.\n# The default value is: NO.\n\nHIDE_COMPOUND_REFERENCE= NO\n\n# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of\n# the files that are included by a file in the documentation of that file.\n# The default value is: YES.\n\nSHOW_INCLUDE_FILES     = YES\n\n# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each\n# grouped member an include statement to the documentation, telling the reader\n# which file to include in order to use the member.\n# The default value is: NO.\n\nSHOW_GROUPED_MEMB_INC  = NO\n\n# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include\n# files with double quotes in the documentation rather than with sharp brackets.\n# The default value is: NO.\n\nFORCE_LOCAL_INCLUDES   = NO\n\n# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the\n# documentation for inline members.\n# The default value is: YES.\n\nINLINE_INFO            = YES\n\n# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the\n# (detailed) documentation of file and class members alphabetically by member\n# name. If set to NO, the members will appear in declaration order.\n# The default value is: YES.\n\nSORT_MEMBER_DOCS       = YES\n\n# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief\n# descriptions of file, namespace and class members alphabetically by member\n# name. If set to NO, the members will appear in declaration order. Note that\n# this will also influence the order of the classes in the class list.\n# The default value is: NO.\n\nSORT_BRIEF_DOCS        = NO\n\n# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the\n# (brief and detailed) documentation of class members so that constructors and\n# destructors are listed first. If set to NO the constructors will appear in the\n# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.\n# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief\n# member documentation.\n# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting\n# detailed member documentation.\n# The default value is: NO.\n\nSORT_MEMBERS_CTORS_1ST = NO\n\n# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy\n# of group names into alphabetical order. If set to NO the group names will\n# appear in their defined order.\n# The default value is: NO.\n\nSORT_GROUP_NAMES       = NO\n\n# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by\n# fully-qualified names, including namespaces. If set to NO, the class list will\n# be sorted only by class name, not including the namespace part.\n# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.\n# Note: This option applies only to the class list, not to the alphabetical\n# list.\n# The default value is: NO.\n\nSORT_BY_SCOPE_NAME     = NO\n\n# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper\n# type resolution of all parameters of a function it will reject a match between\n# the prototype and the implementation of a member function even if there is\n# only one candidate or it is obvious which candidate to choose by doing a\n# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still\n# accept a match between prototype and implementation in such cases.\n# The default value is: NO.\n\nSTRICT_PROTO_MATCHING  = NO\n\n# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo\n# list. This list is created by putting \\todo commands in the documentation.\n# The default value is: YES.\n\nGENERATE_TODOLIST      = YES\n\n# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test\n# list. This list is created by putting \\test commands in the documentation.\n# The default value is: YES.\n\nGENERATE_TESTLIST      = YES\n\n# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug\n# list. This list is created by putting \\bug commands in the documentation.\n# The default value is: YES.\n\nGENERATE_BUGLIST       = YES\n\n# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)\n# the deprecated list. This list is created by putting \\deprecated commands in\n# the documentation.\n# The default value is: YES.\n\nGENERATE_DEPRECATEDLIST= YES\n\n# The ENABLED_SECTIONS tag can be used to enable conditional documentation\n# sections, marked by \\if <section_label> ... \\endif and \\cond <section_label>\n# ... \\endcond blocks.\n\nENABLED_SECTIONS       = \n\n# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the\n# initial value of a variable or macro / define can have for it to appear in the\n# documentation. If the initializer consists of more lines than specified here\n# it will be hidden. Use a value of 0 to hide initializers completely. The\n# appearance of the value of individual variables and macros / defines can be\n# controlled using \\showinitializer or \\hideinitializer command in the\n# documentation regardless of this setting.\n# Minimum value: 0, maximum value: 10000, default value: 30.\n\nMAX_INITIALIZER_LINES  = 30\n\n# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at\n# the bottom of the documentation of classes and structs. If set to YES, the\n# list will mention the files that were used to generate the documentation.\n# The default value is: YES.\n\nSHOW_USED_FILES        = YES\n\n# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This\n# will remove the Files entry from the Quick Index and from the Folder Tree View\n# (if specified).\n# The default value is: YES.\n\nSHOW_FILES             = YES\n\n# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces\n# page. This will remove the Namespaces entry from the Quick Index and from the\n# Folder Tree View (if specified).\n# The default value is: YES.\n\nSHOW_NAMESPACES        = YES\n\n# The FILE_VERSION_FILTER tag can be used to specify a program or script that\n# doxygen should invoke to get the current version for each file (typically from\n# the version control system). Doxygen will invoke the program by executing (via\n# popen()) the command command input-file, where command is the value of the\n# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided\n# by doxygen. Whatever the program writes to standard output is used as the file\n# version. For an example see the documentation.\n\nFILE_VERSION_FILTER    = \n\n# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed\n# by doxygen. The layout file controls the global structure of the generated\n# output files in an output format independent way. To create the layout file\n# that represents doxygen's defaults, run doxygen with the -l option. You can\n# optionally specify a file name after the option, if omitted DoxygenLayout.xml\n# will be used as the name of the layout file.\n#\n# Note that if you run doxygen from a directory containing a file called\n# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE\n# tag is left empty.\n\nLAYOUT_FILE            = \n\n# The CITE_BIB_FILES tag can be used to specify one or more bib files containing\n# the reference definitions. This must be a list of .bib files. The .bib\n# extension is automatically appended if omitted. This requires the bibtex tool\n# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.\n# For LaTeX the style of the bibliography can be controlled using\n# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the\n# search path. See also \\cite for info how to create references.\n\nCITE_BIB_FILES         = \n\n#---------------------------------------------------------------------------\n# Configuration options related to warning and progress messages\n#---------------------------------------------------------------------------\n\n# The QUIET tag can be used to turn on/off the messages that are generated to\n# standard output by doxygen. If QUIET is set to YES this implies that the\n# messages are off.\n# The default value is: NO.\n\nQUIET                  = NO\n\n# The WARNINGS tag can be used to turn on/off the warning messages that are\n# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES\n# this implies that the warnings are on.\n#\n# Tip: Turn warnings on while writing the documentation.\n# The default value is: YES.\n\nWARNINGS               = YES\n\n# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate\n# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag\n# will automatically be disabled.\n# The default value is: YES.\n\nWARN_IF_UNDOCUMENTED   = YES\n\n# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for\n# potential errors in the documentation, such as not documenting some parameters\n# in a documented function, or documenting parameters that don't exist or using\n# markup commands wrongly.\n# The default value is: YES.\n\nWARN_IF_DOC_ERROR      = YES\n\n# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that\n# are documented, but have no documentation for their parameters or return\n# value. If set to NO, doxygen will only warn about wrong or incomplete\n# parameter documentation, but not about the absence of documentation.\n# The default value is: NO.\n\nWARN_NO_PARAMDOC       = NO\n\n# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when\n# a warning is encountered.\n# The default value is: NO.\n\nWARN_AS_ERROR          = NO\n\n# The WARN_FORMAT tag determines the format of the warning messages that doxygen\n# can produce. The string should contain the $file, $line, and $text tags, which\n# will be replaced by the file and line number from which the warning originated\n# and the warning text. Optionally the format may contain $version, which will\n# be replaced by the version of the file (if it could be obtained via\n# FILE_VERSION_FILTER)\n# The default value is: $file:$line: $text.\n\nWARN_FORMAT            = \"$file:$line: $text\"\n\n# The WARN_LOGFILE tag can be used to specify a file to which warning and error\n# messages should be written. If left blank the output is written to standard\n# error (stderr).\n\nWARN_LOGFILE           = \n\n#---------------------------------------------------------------------------\n# Configuration options related to the input files\n#---------------------------------------------------------------------------\n\n# The INPUT tag is used to specify the files and/or directories that contain\n# documented source files. You may enter file names like myfile.cpp or\n# directories like /usr/src/myproject. Separate the files or directories with\n# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING\n# Note: If this tag is empty the current directory is searched.\n\nINPUT                  = ./src \\\n                         ./inc \\\n                         README.md \\\n                         COPYING.md\n\n# This tag can be used to specify the character encoding of the source files\n# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses\n# libiconv (or the iconv built into libc) for the transcoding. See the libiconv\n# documentation (see: http://www.gnu.org/software/libiconv) for the list of\n# possible encodings.\n# The default value is: UTF-8.\n\nINPUT_ENCODING         = UTF-8\n\n# If the value of the INPUT tag contains directories, you can use the\n# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and\n# *.h) to filter out the source-files in the directories.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# read by doxygen.\n#\n# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,\n# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,\n# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,\n# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,\n# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf.\n\nFILE_PATTERNS          = *.c \\\n                         *.cc \\\n                         *.cxx \\\n                         *.cpp \\\n                         *.c++ \\\n                         *.java \\\n                         *.ii \\\n                         *.ixx \\\n                         *.ipp \\\n                         *.i++ \\\n                         *.inl \\\n                         *.idl \\\n                         *.ddl \\\n                         *.odl \\\n                         *.h \\\n                         *.hh \\\n                         *.hxx \\\n                         *.hpp \\\n                         *.h++ \\\n                         *.cs \\\n                         *.d \\\n                         *.php \\\n                         *.php4 \\\n                         *.php5 \\\n                         *.phtml \\\n                         *.inc \\\n                         *.m \\\n                         *.markdown \\\n                         *.md \\\n                         *.mm \\\n                         *.dox \\\n                         *.py \\\n                         *.pyw \\\n                         *.f90 \\\n                         *.f95 \\\n                         *.f03 \\\n                         *.f08 \\\n                         *.f \\\n                         *.for \\\n                         *.tcl \\\n                         *.vhd \\\n                         *.vhdl \\\n                         *.ucf \\\n                         *.qsf\n\n# The RECURSIVE tag can be used to specify whether or not subdirectories should\n# be searched for input files as well.\n# The default value is: NO.\n\nRECURSIVE              = NO\n\n# The EXCLUDE tag can be used to specify files and/or directories that should be\n# excluded from the INPUT source files. This way you can easily exclude a\n# subdirectory from a directory tree whose root is specified with the INPUT tag.\n#\n# Note that relative paths are relative to the directory from which doxygen is\n# run.\n\nEXCLUDE                = \n\n# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or\n# directories that are symbolic links (a Unix file system feature) are excluded\n# from the input.\n# The default value is: NO.\n\nEXCLUDE_SYMLINKS       = NO\n\n# If the value of the INPUT tag contains directories, you can use the\n# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude\n# certain files from those directories.\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories for example use the pattern */test/*\n\nEXCLUDE_PATTERNS       = \n\n# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names\n# (namespaces, classes, functions, etc.) that should be excluded from the\n# output. The symbol name can be a fully qualified name, a word, or if the\n# wildcard * is used, a substring. Examples: ANamespace, AClass,\n# AClass::ANamespace, ANamespace::*Test\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories use the pattern */test/*\n\nEXCLUDE_SYMBOLS        = \n\n# The EXAMPLE_PATH tag can be used to specify one or more files or directories\n# that contain example code fragments that are included (see the \\include\n# command).\n\nEXAMPLE_PATH           = \n\n# If the value of the EXAMPLE_PATH tag contains directories, you can use the\n# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and\n# *.h) to filter out the source-files in the directories. If left blank all\n# files are included.\n\nEXAMPLE_PATTERNS       = *\n\n# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be\n# searched for input files to be used with the \\include or \\dontinclude commands\n# irrespective of the value of the RECURSIVE tag.\n# The default value is: NO.\n\nEXAMPLE_RECURSIVE      = NO\n\n# The IMAGE_PATH tag can be used to specify one or more files or directories\n# that contain images that are to be included in the documentation (see the\n# \\image command).\n\nIMAGE_PATH             = \n\n# The INPUT_FILTER tag can be used to specify a program that doxygen should\n# invoke to filter for each input file. Doxygen will invoke the filter program\n# by executing (via popen()) the command:\n#\n# <filter> <input-file>\n#\n# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the\n# name of an input file. Doxygen will then use the output that the filter\n# program writes to standard output. If FILTER_PATTERNS is specified, this tag\n# will be ignored.\n#\n# Note that the filter must not add or remove lines; it is applied before the\n# code is scanned, but not when the output code is generated. If lines are added\n# or removed, the anchors will not be placed correctly.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# properly processed by doxygen.\n\nINPUT_FILTER           = \n\n# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern\n# basis. Doxygen will compare the file name with each pattern and apply the\n# filter if there is a match. The filters are a list of the form: pattern=filter\n# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how\n# filters are used. If the FILTER_PATTERNS tag is empty or if none of the\n# patterns match the file name, INPUT_FILTER is applied.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# properly processed by doxygen.\n\nFILTER_PATTERNS        = \n\n# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using\n# INPUT_FILTER) will also be used to filter the input files that are used for\n# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).\n# The default value is: NO.\n\nFILTER_SOURCE_FILES    = NO\n\n# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file\n# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and\n# it is also possible to disable source filtering for a specific pattern using\n# *.ext= (so without naming a filter).\n# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.\n\nFILTER_SOURCE_PATTERNS = \n\n# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that\n# is part of the input, its contents will be placed on the main page\n# (index.html). This can be useful if you have a project on for instance GitHub\n# and want to reuse the introduction page also for the doxygen output.\n\nUSE_MDFILE_AS_MAINPAGE = README.md\n\n#---------------------------------------------------------------------------\n# Configuration options related to source browsing\n#---------------------------------------------------------------------------\n\n# If the SOURCE_BROWSER tag is set to YES then a list of source files will be\n# generated. Documented entities will be cross-referenced with these sources.\n#\n# Note: To get rid of all source code in the generated output, make sure that\n# also VERBATIM_HEADERS is set to NO.\n# The default value is: NO.\n\nSOURCE_BROWSER         = NO\n\n# Setting the INLINE_SOURCES tag to YES will include the body of functions,\n# classes and enums directly into the documentation.\n# The default value is: NO.\n\nINLINE_SOURCES         = NO\n\n# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any\n# special comment blocks from generated source code fragments. Normal C, C++ and\n# Fortran comments will always remain visible.\n# The default value is: YES.\n\nSTRIP_CODE_COMMENTS    = YES\n\n# If the REFERENCED_BY_RELATION tag is set to YES then for each documented\n# function all documented functions referencing it will be listed.\n# The default value is: NO.\n\nREFERENCED_BY_RELATION = NO\n\n# If the REFERENCES_RELATION tag is set to YES then for each documented function\n# all documented entities called/used by that function will be listed.\n# The default value is: NO.\n\nREFERENCES_RELATION    = NO\n\n# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set\n# to YES then the hyperlinks from functions in REFERENCES_RELATION and\n# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will\n# link to the documentation.\n# The default value is: YES.\n\nREFERENCES_LINK_SOURCE = YES\n\n# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the\n# source code will show a tooltip with additional information such as prototype,\n# brief description and links to the definition and documentation. Since this\n# will make the HTML file larger and loading of large files a bit slower, you\n# can opt to disable this feature.\n# The default value is: YES.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nSOURCE_TOOLTIPS        = YES\n\n# If the USE_HTAGS tag is set to YES then the references to source code will\n# point to the HTML generated by the htags(1) tool instead of doxygen built-in\n# source browser. The htags tool is part of GNU's global source tagging system\n# (see http://www.gnu.org/software/global/global.html). You will need version\n# 4.8.6 or higher.\n#\n# To use it do the following:\n# - Install the latest version of global\n# - Enable SOURCE_BROWSER and USE_HTAGS in the config file\n# - Make sure the INPUT points to the root of the source tree\n# - Run doxygen as normal\n#\n# Doxygen will invoke htags (and that will in turn invoke gtags), so these\n# tools must be available from the command line (i.e. in the search path).\n#\n# The result: instead of the source browser generated by doxygen, the links to\n# source code will now point to the output of htags.\n# The default value is: NO.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nUSE_HTAGS              = NO\n\n# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a\n# verbatim copy of the header file for each class for which an include is\n# specified. Set to NO to disable this.\n# See also: Section \\class.\n# The default value is: YES.\n\nVERBATIM_HEADERS       = YES\n\n# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the\n# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the\n# cost of reduced performance. This can be particularly helpful with template\n# rich C++ code for which doxygen's built-in parser lacks the necessary type\n# information.\n# Note: The availability of this option depends on whether or not doxygen was\n# generated with the -Duse-libclang=ON option for CMake.\n# The default value is: NO.\n\nCLANG_ASSISTED_PARSING = NO\n\n# If clang assisted parsing is enabled you can provide the compiler with command\n# line options that you would normally use when invoking the compiler. Note that\n# the include paths will already be set by doxygen for the files and directories\n# specified with INPUT and INCLUDE_PATH.\n# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.\n\nCLANG_OPTIONS          = \n\n#---------------------------------------------------------------------------\n# Configuration options related to the alphabetical class index\n#---------------------------------------------------------------------------\n\n# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all\n# compounds will be generated. Enable this if the project contains a lot of\n# classes, structs, unions or interfaces.\n# The default value is: YES.\n\nALPHABETICAL_INDEX     = YES\n\n# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in\n# which the alphabetical index list will be split.\n# Minimum value: 1, maximum value: 20, default value: 5.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nCOLS_IN_ALPHA_INDEX    = 5\n\n# In case all classes in a project start with a common prefix, all classes will\n# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag\n# can be used to specify a prefix (or a list of prefixes) that should be ignored\n# while generating the index headers.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nIGNORE_PREFIX          = \n\n#---------------------------------------------------------------------------\n# Configuration options related to the HTML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output\n# The default value is: YES.\n\nGENERATE_HTML          = YES\n\n# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_OUTPUT            = html\n\n# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each\n# generated HTML page (for example: .htm, .php, .asp).\n# The default value is: .html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FILE_EXTENSION    = .html\n\n# The HTML_HEADER tag can be used to specify a user-defined HTML header file for\n# each generated HTML page. If the tag is left blank doxygen will generate a\n# standard header.\n#\n# To get valid HTML the header file that includes any scripts and style sheets\n# that doxygen needs, which is dependent on the configuration options used (e.g.\n# the setting GENERATE_TREEVIEW). It is highly recommended to start with a\n# default header using\n# doxygen -w html new_header.html new_footer.html new_stylesheet.css\n# YourConfigFile\n# and then modify the file new_header.html. See also section \"Doxygen usage\"\n# for information on how to generate the default header that doxygen normally\n# uses.\n# Note: The header is subject to change so you typically have to regenerate the\n# default header when upgrading to a newer version of doxygen. For a description\n# of the possible markers and block names see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_HEADER            = \n\n# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each\n# generated HTML page. If the tag is left blank doxygen will generate a standard\n# footer. See HTML_HEADER for more information on how to generate a default\n# footer and what special commands can be used inside the footer. See also\n# section \"Doxygen usage\" for information on how to generate the default footer\n# that doxygen normally uses.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FOOTER            = \n\n# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style\n# sheet that is used by each HTML page. It can be used to fine-tune the look of\n# the HTML output. If left blank doxygen will generate a default style sheet.\n# See also section \"Doxygen usage\" for information on how to generate the style\n# sheet that doxygen normally uses.\n# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as\n# it is more robust and this tag (HTML_STYLESHEET) will in the future become\n# obsolete.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_STYLESHEET        = \n\n# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined\n# cascading style sheets that are included after the standard style sheets\n# created by doxygen. Using this option one can overrule certain style aspects.\n# This is preferred over using HTML_STYLESHEET since it does not replace the\n# standard style sheet and is therefore more robust against future updates.\n# Doxygen will copy the style sheet files to the output directory.\n# Note: The order of the extra style sheet files is of importance (e.g. the last\n# style sheet in the list overrules the setting of the previous ones in the\n# list). For an example see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_STYLESHEET  = \n\n# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the HTML output directory. Note\n# that these files will be copied to the base HTML output directory. Use the\n# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these\n# files. In the HTML_STYLESHEET file, use the file name only. Also note that the\n# files will be copied as-is; there are no commands or markers available.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_FILES       = \n\n# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen\n# will adjust the colors in the style sheet and background images according to\n# this color. Hue is specified as an angle on a colorwheel, see\n# http://en.wikipedia.org/wiki/Hue for more information. For instance the value\n# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300\n# purple, and 360 is red again.\n# Minimum value: 0, maximum value: 359, default value: 220.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_HUE    = 220\n\n# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors\n# in the HTML output. For a value of 0 the output will use grayscales only. A\n# value of 255 will produce the most vivid colors.\n# Minimum value: 0, maximum value: 255, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_SAT    = 100\n\n# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the\n# luminance component of the colors in the HTML output. Values below 100\n# gradually make the output lighter, whereas values above 100 make the output\n# darker. The value divided by 100 is the actual gamma applied, so 80 represents\n# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not\n# change the gamma.\n# Minimum value: 40, maximum value: 240, default value: 80.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_GAMMA  = 80\n\n# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML\n# page will contain the date and time when the page was generated. Setting this\n# to YES can help to show when doxygen was last run and thus if the\n# documentation is up to date.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_TIMESTAMP         = NO\n\n# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML\n# documentation will contain sections that can be hidden and shown after the\n# page has loaded.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_DYNAMIC_SECTIONS  = NO\n\n# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries\n# shown in the various tree structured indices initially; the user can expand\n# and collapse entries dynamically later on. Doxygen will expand the tree to\n# such a level that at most the specified number of entries are visible (unless\n# a fully collapsed tree already exceeds this amount). So setting the number of\n# entries 1 will produce a full collapsed tree by default. 0 is a special value\n# representing an infinite number of entries and will result in a full expanded\n# tree by default.\n# Minimum value: 0, maximum value: 9999, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_INDEX_NUM_ENTRIES = 100\n\n# If the GENERATE_DOCSET tag is set to YES, additional index files will be\n# generated that can be used as input for Apple's Xcode 3 integrated development\n# environment (see: http://developer.apple.com/tools/xcode/), introduced with\n# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a\n# Makefile in the HTML output directory. Running make will produce the docset in\n# that directory and running make install will install the docset in\n# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at\n# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html\n# for more information.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_DOCSET        = NO\n\n# This tag determines the name of the docset feed. A documentation feed provides\n# an umbrella under which multiple documentation sets from a single provider\n# (such as a company or product suite) can be grouped.\n# The default value is: Doxygen generated docs.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_FEEDNAME        = \"Doxygen generated docs\"\n\n# This tag specifies a string that should uniquely identify the documentation\n# set bundle. This should be a reverse domain-name style string, e.g.\n# com.mycompany.MyDocSet. Doxygen will append .docset to the name.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_BUNDLE_ID       = org.doxygen.Project\n\n# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify\n# the documentation publisher. This should be a reverse domain-name style\n# string, e.g. com.mycompany.MyDocSet.documentation.\n# The default value is: org.doxygen.Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_ID    = org.doxygen.Publisher\n\n# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.\n# The default value is: Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_NAME  = Publisher\n\n# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three\n# additional HTML index files: index.hhp, index.hhc, and index.hhk. The\n# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop\n# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on\n# Windows.\n#\n# The HTML Help Workshop contains a compiler that can convert all HTML output\n# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML\n# files are now used as the Windows 98 help format, and will replace the old\n# Windows help format (.hlp) on all Windows platforms in the future. Compressed\n# HTML files also contain an index, a table of contents, and you can search for\n# words in the documentation. The HTML workshop also contains a viewer for\n# compressed HTML files.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_HTMLHELP      = NO\n\n# The CHM_FILE tag can be used to specify the file name of the resulting .chm\n# file. You can add a path in front of the file if the result should not be\n# written to the html output directory.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_FILE               = \n\n# The HHC_LOCATION tag can be used to specify the location (absolute path\n# including file name) of the HTML help compiler (hhc.exe). If non-empty,\n# doxygen will try to run the HTML help compiler on the generated index.hhp.\n# The file has to be specified with full path.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nHHC_LOCATION           = \n\n# The GENERATE_CHI flag controls if a separate .chi index file is generated\n# (YES) or that it should be included in the master .chm file (NO).\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nGENERATE_CHI           = NO\n\n# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)\n# and project file content.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_INDEX_ENCODING     = \n\n# The BINARY_TOC flag controls whether a binary table of contents is generated\n# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it\n# enables the Previous and Next buttons.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nBINARY_TOC             = NO\n\n# The TOC_EXPAND flag can be set to YES to add extra items for group members to\n# the table of contents of the HTML help documentation and to the tree view.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nTOC_EXPAND             = NO\n\n# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and\n# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that\n# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help\n# (.qch) of the generated HTML documentation.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_QHP           = NO\n\n# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify\n# the file name of the resulting .qch file. The path specified is relative to\n# the HTML output folder.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQCH_FILE               = \n\n# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help\n# Project output. For more information please see Qt Help Project / Namespace\n# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_NAMESPACE          = org.doxygen.Project\n\n# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt\n# Help Project output. For more information please see Qt Help Project / Virtual\n# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-\n# folders).\n# The default value is: doc.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_VIRTUAL_FOLDER     = doc\n\n# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom\n# filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_NAME   = \n\n# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the\n# custom filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_ATTRS  = \n\n# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this\n# project's filter section matches. Qt Help Project / Filter Attributes (see:\n# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_SECT_FILTER_ATTRS  = \n\n# The QHG_LOCATION tag can be used to specify the location of Qt's\n# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the\n# generated .qhp file.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHG_LOCATION           = \n\n# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be\n# generated, together with the HTML files, they form an Eclipse help plugin. To\n# install this plugin and make it available under the help contents menu in\n# Eclipse, the contents of the directory containing the HTML and XML files needs\n# to be copied into the plugins directory of eclipse. The name of the directory\n# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.\n# After copying Eclipse needs to be restarted before the help appears.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_ECLIPSEHELP   = NO\n\n# A unique identifier for the Eclipse help plugin. When installing the plugin\n# the directory name containing the HTML and XML files should also have this\n# name. Each documentation set should have its own identifier.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.\n\nECLIPSE_DOC_ID         = org.doxygen.Project\n\n# If you want full control over the layout of the generated HTML pages it might\n# be necessary to disable the index and replace it with your own. The\n# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top\n# of each HTML page. A value of NO enables the index and the value YES disables\n# it. Since the tabs in the index contain the same information as the navigation\n# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nDISABLE_INDEX          = NO\n\n# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index\n# structure should be generated to display hierarchical information. If the tag\n# value is set to YES, a side panel will be generated containing a tree-like\n# index structure (just like the one that is generated for HTML Help). For this\n# to work a browser that supports JavaScript, DHTML, CSS and frames is required\n# (i.e. any modern browser). Windows users are probably better off using the\n# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can\n# further fine-tune the look of the index. As an example, the default style\n# sheet generated by doxygen has an example that shows how to put an image at\n# the root of the tree instead of the PROJECT_NAME. Since the tree basically has\n# the same information as the tab index, you could consider setting\n# DISABLE_INDEX to YES when enabling this option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_TREEVIEW      = NO\n\n# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that\n# doxygen will group on one line in the generated HTML documentation.\n#\n# Note that a value of 0 will completely suppress the enum values from appearing\n# in the overview section.\n# Minimum value: 0, maximum value: 20, default value: 4.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nENUM_VALUES_PER_LINE   = 4\n\n# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used\n# to set the initial width (in pixels) of the frame in which the tree is shown.\n# Minimum value: 0, maximum value: 1500, default value: 250.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nTREEVIEW_WIDTH         = 250\n\n# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to\n# external symbols imported via tag files in a separate window.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nEXT_LINKS_IN_WINDOW    = NO\n\n# Use this tag to change the font size of LaTeX formulas included as images in\n# the HTML documentation. When you change the font size after a successful\n# doxygen run you need to manually remove any form_*.png images from the HTML\n# output directory to force them to be regenerated.\n# Minimum value: 8, maximum value: 50, default value: 10.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_FONTSIZE       = 10\n\n# Use the FORMULA_TRANPARENT tag to determine whether or not the images\n# generated for formulas are transparent PNGs. Transparent PNGs are not\n# supported properly for IE 6.0, but are supported on all modern browsers.\n#\n# Note that when changing this option you need to delete any form_*.png files in\n# the HTML output directory before the changes have effect.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_TRANSPARENT    = YES\n\n# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see\n# http://www.mathjax.org) which uses client side Javascript for the rendering\n# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX\n# installed or if you want to formulas look prettier in the HTML output. When\n# enabled you may also need to install MathJax separately and configure the path\n# to it using the MATHJAX_RELPATH option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nUSE_MATHJAX            = NO\n\n# When MathJax is enabled you can set the default output format to be used for\n# the MathJax output. See the MathJax site (see:\n# http://docs.mathjax.org/en/latest/output.html) for more details.\n# Possible values are: HTML-CSS (which is slower, but has the best\n# compatibility), NativeMML (i.e. MathML) and SVG.\n# The default value is: HTML-CSS.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_FORMAT         = HTML-CSS\n\n# When MathJax is enabled you need to specify the location relative to the HTML\n# output directory using the MATHJAX_RELPATH option. The destination directory\n# should contain the MathJax.js script. For instance, if the mathjax directory\n# is located at the same level as the HTML output directory, then\n# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax\n# Content Delivery Network so you can quickly see the result without installing\n# MathJax. However, it is strongly recommended to install a local copy of\n# MathJax from http://www.mathjax.org before deployment.\n# The default value is: http://cdn.mathjax.org/mathjax/latest.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_RELPATH        = http://cdn.mathjax.org/mathjax/latest\n\n# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax\n# extension names that should be enabled during MathJax rendering. For example\n# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_EXTENSIONS     = \n\n# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces\n# of code that will be used on startup of the MathJax code. See the MathJax site\n# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an\n# example see the documentation.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_CODEFILE       = \n\n# When the SEARCHENGINE tag is enabled doxygen will generate a search box for\n# the HTML output. The underlying search engine uses javascript and DHTML and\n# should work on any modern browser. Note that when using HTML help\n# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)\n# there is already a search function so this one should typically be disabled.\n# For large projects the javascript based search engine can be slow, then\n# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to\n# search using the keyboard; to jump to the search box use <access key> + S\n# (what the <access key> is depends on the OS and browser, but it is typically\n# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down\n# key> to jump into the search results window, the results can be navigated\n# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel\n# the search. The filter options can be selected when the cursor is inside the\n# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>\n# to select a filter and <Enter> or <escape> to activate or cancel the filter\n# option.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nSEARCHENGINE           = YES\n\n# When the SERVER_BASED_SEARCH tag is enabled the search engine will be\n# implemented using a web server instead of a web client using Javascript. There\n# are two flavors of web server based searching depending on the EXTERNAL_SEARCH\n# setting. When disabled, doxygen will generate a PHP script for searching and\n# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing\n# and searching needs to be provided by external tools. See the section\n# \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSERVER_BASED_SEARCH    = NO\n\n# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP\n# script for searching. Instead the search results are written to an XML file\n# which needs to be processed by an external indexer. Doxygen will invoke an\n# external search engine pointed to by the SEARCHENGINE_URL option to obtain the\n# search results.\n#\n# Doxygen ships with an example indexer (doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: http://xapian.org/).\n#\n# See the section \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH        = NO\n\n# The SEARCHENGINE_URL should point to a search engine hosted by a web server\n# which will return the search results when EXTERNAL_SEARCH is enabled.\n#\n# Doxygen ships with an example indexer (doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: http://xapian.org/). See the section \"External Indexing and\n# Searching\" for details.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHENGINE_URL       = \n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed\n# search data is written to a file for indexing by an external tool. With the\n# SEARCHDATA_FILE tag the name of this file can be specified.\n# The default file is: searchdata.xml.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHDATA_FILE        = searchdata.xml\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the\n# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is\n# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple\n# projects and redirect the results back to the right project.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH_ID     = \n\n# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen\n# projects other than the one defined by this configuration file, but that are\n# all added to the same external search index. Each project needs to have a\n# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of\n# to a relative location where the documentation can be found. The format is:\n# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTRA_SEARCH_MAPPINGS  = \n\n#---------------------------------------------------------------------------\n# Configuration options related to the LaTeX output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.\n# The default value is: YES.\n\nGENERATE_LATEX         = YES\n\n# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: latex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_OUTPUT           = latex\n\n# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be\n# invoked.\n#\n# Note that when enabling USE_PDFLATEX this option is only used for generating\n# bitmaps for formulas in the HTML output, but not in the Makefile that is\n# written to the output directory.\n# The default file is: latex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_CMD_NAME         = latex\n\n# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate\n# index for LaTeX.\n# The default file is: makeindex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nMAKEINDEX_CMD_NAME     = makeindex\n\n# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nCOMPACT_LATEX          = NO\n\n# The PAPER_TYPE tag can be used to set the paper type that is used by the\n# printer.\n# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x\n# 14 inches) and executive (7.25 x 10.5 inches).\n# The default value is: a4.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPAPER_TYPE             = a4\n\n# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names\n# that should be included in the LaTeX output. The package can be specified just\n# by its name or with the correct syntax as to be used with the LaTeX\n# \\usepackage command. To get the times font for instance you can specify :\n# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}\n# To use the option intlimits with the amsmath package you can specify:\n# EXTRA_PACKAGES=[intlimits]{amsmath}\n# If left blank no extra packages will be included.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nEXTRA_PACKAGES         = \n\n# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the\n# generated LaTeX document. The header should contain everything until the first\n# chapter. If it is left blank doxygen will generate a standard header. See\n# section \"Doxygen usage\" for information on how to let doxygen write the\n# default header to a separate file.\n#\n# Note: Only use a user-defined header if you know what you are doing! The\n# following commands have a special meaning inside the header: $title,\n# $datetime, $date, $doxygenversion, $projectname, $projectnumber,\n# $projectbrief, $projectlogo. Doxygen will replace $title with the empty\n# string, for the replacement values of the other commands the user is referred\n# to HTML_HEADER.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HEADER           = \n\n# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the\n# generated LaTeX document. The footer should contain everything after the last\n# chapter. If it is left blank doxygen will generate a standard footer. See\n# LATEX_HEADER for more information on how to generate a default footer and what\n# special commands can be used inside the footer.\n#\n# Note: Only use a user-defined footer if you know what you are doing!\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_FOOTER           = \n\n# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined\n# LaTeX style sheets that are included after the standard style sheets created\n# by doxygen. Using this option one can overrule certain style aspects. Doxygen\n# will copy the style sheet files to the output directory.\n# Note: The order of the extra style sheet files is of importance (e.g. the last\n# style sheet in the list overrules the setting of the previous ones in the\n# list).\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EXTRA_STYLESHEET = \n\n# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the LATEX_OUTPUT output\n# directory. Note that the files will be copied as-is; there are no commands or\n# markers available.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EXTRA_FILES      = \n\n# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is\n# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will\n# contain links (just like the HTML output) instead of page references. This\n# makes the output suitable for online browsing using a PDF viewer.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPDF_HYPERLINKS         = YES\n\n# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate\n# the PDF file directly from the LaTeX files. Set this option to YES, to get a\n# higher quality PDF documentation.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nUSE_PDFLATEX           = YES\n\n# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode\n# command to the generated LaTeX files. This will instruct LaTeX to keep running\n# if errors occur, instead of asking the user for help. This option is also used\n# when generating formulas in HTML.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BATCHMODE        = NO\n\n# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the\n# index chapters (such as File Index, Compound Index, etc.) in the output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HIDE_INDICES     = NO\n\n# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source\n# code with syntax highlighting in the LaTeX output.\n#\n# Note that which sources are shown also depends on other settings such as\n# SOURCE_BROWSER.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_SOURCE_CODE      = NO\n\n# The LATEX_BIB_STYLE tag can be used to specify the style to use for the\n# bibliography, e.g. plainnat, or ieeetr. See\n# http://en.wikipedia.org/wiki/BibTeX and \\cite for more info.\n# The default value is: plain.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BIB_STYLE        = plain\n\n# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated\n# page will contain the date and time when the page was generated. Setting this\n# to NO can help when comparing the output of multiple runs.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_TIMESTAMP        = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the RTF output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The\n# RTF output is optimized for Word 97 and may not look too pretty with other RTF\n# readers/editors.\n# The default value is: NO.\n\nGENERATE_RTF           = NO\n\n# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: rtf.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_OUTPUT             = rtf\n\n# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nCOMPACT_RTF            = NO\n\n# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will\n# contain hyperlink fields. The RTF file will contain links (just like the HTML\n# output) instead of page references. This makes the output suitable for online\n# browsing using Word or some other Word compatible readers that support those\n# fields.\n#\n# Note: WordPad (write) and others do not support links.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_HYPERLINKS         = NO\n\n# Load stylesheet definitions from file. Syntax is similar to doxygen's config\n# file, i.e. a series of assignments. You only have to provide replacements,\n# missing definitions are set to their default value.\n#\n# See also section \"Doxygen usage\" for information on how to generate the\n# default style sheet that doxygen normally uses.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_STYLESHEET_FILE    = \n\n# Set optional variables used in the generation of an RTF document. Syntax is\n# similar to doxygen's config file. A template extensions file can be generated\n# using doxygen -e rtf extensionFile.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_EXTENSIONS_FILE    = \n\n# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code\n# with syntax highlighting in the RTF output.\n#\n# Note that which sources are shown also depends on other settings such as\n# SOURCE_BROWSER.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_SOURCE_CODE        = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the man page output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for\n# classes and files.\n# The default value is: NO.\n\nGENERATE_MAN           = NO\n\n# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it. A directory man3 will be created inside the directory specified by\n# MAN_OUTPUT.\n# The default directory is: man.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_OUTPUT             = man\n\n# The MAN_EXTENSION tag determines the extension that is added to the generated\n# man pages. In case the manual section does not start with a number, the number\n# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is\n# optional.\n# The default value is: .3.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_EXTENSION          = .3\n\n# The MAN_SUBDIR tag determines the name of the directory created within\n# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by\n# MAN_EXTENSION with the initial . removed.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_SUBDIR             = \n\n# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it\n# will generate one additional man file for each entity documented in the real\n# man page(s). These additional files only source the real man page, but without\n# them the man command would be unable to find the correct page.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_LINKS              = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the XML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that\n# captures the structure of the code including all documentation.\n# The default value is: NO.\n\nGENERATE_XML           = NO\n\n# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: xml.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_OUTPUT             = xml\n\n# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program\n# listings (including syntax highlighting and cross-referencing information) to\n# the XML output. Note that enabling this will significantly increase the size\n# of the XML output.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_PROGRAMLISTING     = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to the DOCBOOK output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files\n# that can be used to generate PDF.\n# The default value is: NO.\n\nGENERATE_DOCBOOK       = NO\n\n# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.\n# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in\n# front of it.\n# The default directory is: docbook.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_OUTPUT         = docbook\n\n# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the\n# program listings (including syntax highlighting and cross-referencing\n# information) to the DOCBOOK output. Note that enabling this will significantly\n# increase the size of the DOCBOOK output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_PROGRAMLISTING = NO\n\n#---------------------------------------------------------------------------\n# Configuration options for the AutoGen Definitions output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an\n# AutoGen Definitions (see http://autogen.sf.net) file that captures the\n# structure of the code including all documentation. Note that this feature is\n# still experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_AUTOGEN_DEF   = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the Perl module output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module\n# file that captures the structure of the code including all documentation.\n#\n# Note that this feature is still experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_PERLMOD       = NO\n\n# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary\n# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI\n# output from the Perl module output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_LATEX          = NO\n\n# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely\n# formatted so it can be parsed by a human reader. This is useful if you want to\n# understand what is going on. On the other hand, if this tag is set to NO, the\n# size of the Perl module output will be much smaller and Perl will parse it\n# just the same.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_PRETTY         = YES\n\n# The names of the make variables in the generated doxyrules.make file are\n# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful\n# so different doxyrules.make files included by the same Makefile don't\n# overwrite each other's variables.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_MAKEVAR_PREFIX = \n\n#---------------------------------------------------------------------------\n# Configuration options related to the preprocessor\n#---------------------------------------------------------------------------\n\n# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all\n# C-preprocessor directives found in the sources and include files.\n# The default value is: YES.\n\nENABLE_PREPROCESSING   = YES\n\n# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names\n# in the source code. If set to NO, only conditional compilation will be\n# performed. Macro expansion can be done in a controlled way by setting\n# EXPAND_ONLY_PREDEF to YES.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nMACRO_EXPANSION        = NO\n\n# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then\n# the macro expansion is limited to the macros specified with the PREDEFINED and\n# EXPAND_AS_DEFINED tags.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_ONLY_PREDEF     = NO\n\n# If the SEARCH_INCLUDES tag is set to YES, the include files in the\n# INCLUDE_PATH will be searched if a #include is found.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSEARCH_INCLUDES        = YES\n\n# The INCLUDE_PATH tag can be used to specify one or more directories that\n# contain include files that are not input files but should be processed by the\n# preprocessor.\n# This tag requires that the tag SEARCH_INCLUDES is set to YES.\n\nINCLUDE_PATH           = \n\n# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard\n# patterns (like *.h and *.hpp) to filter out the header-files in the\n# directories. If left blank, the patterns specified with FILE_PATTERNS will be\n# used.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nINCLUDE_FILE_PATTERNS  = \n\n# The PREDEFINED tag can be used to specify one or more macro names that are\n# defined before the preprocessor is started (similar to the -D option of e.g.\n# gcc). The argument of the tag is a list of macros of the form: name or\n# name=definition (no spaces). If the definition and the \"=\" are omitted, \"=1\"\n# is assumed. To prevent a macro definition from being undefined via #undef or\n# recursively expanded use the := operator instead of the = operator.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nPREDEFINED             = \n\n# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this\n# tag can be used to specify a list of macro names that should be expanded. The\n# macro definition that is found in the sources will be used. Use the PREDEFINED\n# tag if you want to use a different macro definition that overrules the\n# definition found in the source code.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_AS_DEFINED      = \n\n# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will\n# remove all references to function-like macros that are alone on a line, have\n# an all uppercase name, and do not end with a semicolon. Such function macros\n# are typically used for boiler-plate code, and will confuse the parser if not\n# removed.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSKIP_FUNCTION_MACROS   = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to external references\n#---------------------------------------------------------------------------\n\n# The TAGFILES tag can be used to specify one or more tag files. For each tag\n# file the location of the external documentation should be added. The format of\n# a tag file without this location is as follows:\n# TAGFILES = file1 file2 ...\n# Adding location for the tag files is done as follows:\n# TAGFILES = file1=loc1 \"file2 = loc2\" ...\n# where loc1 and loc2 can be relative or absolute paths or URLs. See the\n# section \"Linking to external documentation\" for more information about the use\n# of tag files.\n# Note: Each tag file must have a unique name (where the name does NOT include\n# the path). If a tag file is not located in the directory in which doxygen is\n# run, you must also specify the path to the tagfile here.\n\nTAGFILES               = \n\n# When a file name is specified after GENERATE_TAGFILE, doxygen will create a\n# tag file that is based on the input files it reads. See section \"Linking to\n# external documentation\" for more information about the usage of tag files.\n\nGENERATE_TAGFILE       = \n\n# If the ALLEXTERNALS tag is set to YES, all external class will be listed in\n# the class index. If set to NO, only the inherited external classes will be\n# listed.\n# The default value is: NO.\n\nALLEXTERNALS           = NO\n\n# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed\n# in the modules index. If set to NO, only the current project's groups will be\n# listed.\n# The default value is: YES.\n\nEXTERNAL_GROUPS        = YES\n\n# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in\n# the related pages index. If set to NO, only the current project's pages will\n# be listed.\n# The default value is: YES.\n\nEXTERNAL_PAGES         = YES\n\n# The PERL_PATH should be the absolute path and name of the perl script\n# interpreter (i.e. the result of 'which perl').\n# The default file (with absolute path) is: /usr/bin/perl.\n\nPERL_PATH              = /usr/bin/perl\n\n#---------------------------------------------------------------------------\n# Configuration options related to the dot tool\n#---------------------------------------------------------------------------\n\n# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram\n# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to\n# NO turns the diagrams off. Note that this option also works with HAVE_DOT\n# disabled, but it is recommended to install and use dot, since it yields more\n# powerful graphs.\n# The default value is: YES.\n\nCLASS_DIAGRAMS         = YES\n\n# You can define message sequence charts within doxygen comments using the \\msc\n# command. Doxygen will then run the mscgen tool (see:\n# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the\n# documentation. The MSCGEN_PATH tag allows you to specify the directory where\n# the mscgen tool resides. If left empty the tool is assumed to be found in the\n# default search path.\n\nMSCGEN_PATH            = \n\n# You can include diagrams made with dia in doxygen documentation. Doxygen will\n# then run dia to produce the diagram and insert it in the documentation. The\n# DIA_PATH tag allows you to specify the directory where the dia binary resides.\n# If left empty dia is assumed to be found in the default search path.\n\nDIA_PATH               = \n\n# If set to YES the inheritance and collaboration graphs will hide inheritance\n# and usage relations if the target is undocumented or is not a class.\n# The default value is: YES.\n\nHIDE_UNDOC_RELATIONS   = YES\n\n# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is\n# available from the path. This tool is part of Graphviz (see:\n# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent\n# Bell Labs. The other options in this section have no effect if this option is\n# set to NO\n# The default value is: NO.\n\nHAVE_DOT               = NO\n\n# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed\n# to run in parallel. When set to 0 doxygen will base this on the number of\n# processors available in the system. You can set it explicitly to a value\n# larger than 0 to get control over the balance between CPU load and processing\n# speed.\n# Minimum value: 0, maximum value: 32, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_NUM_THREADS        = 0\n\n# When you want a differently looking font in the dot files that doxygen\n# generates you can specify the font name using DOT_FONTNAME. You need to make\n# sure dot is able to find the font, which can be done by putting it in a\n# standard location or by setting the DOTFONTPATH environment variable or by\n# setting DOT_FONTPATH to the directory containing the font.\n# The default value is: Helvetica.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTNAME           = Helvetica\n\n# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of\n# dot graphs.\n# Minimum value: 4, maximum value: 24, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTSIZE           = 10\n\n# By default doxygen will tell dot to use the default font as specified with\n# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set\n# the path where dot can find it using this tag.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTPATH           = \n\n# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for\n# each documented class showing the direct and indirect inheritance relations.\n# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCLASS_GRAPH            = YES\n\n# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a\n# graph for each documented class showing the direct and indirect implementation\n# dependencies (inheritance, containment, and class references variables) of the\n# class with other documented classes.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCOLLABORATION_GRAPH    = YES\n\n# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for\n# groups, showing the direct groups dependencies.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGROUP_GRAPHS           = YES\n\n# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and\n# collaboration diagrams in a style similar to the OMG's Unified Modeling\n# Language.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LOOK               = NO\n\n# If the UML_LOOK tag is enabled, the fields and methods are shown inside the\n# class node. If there are many fields or methods and many nodes the graph may\n# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the\n# number of items for each type to make the size more manageable. Set this to 0\n# for no limit. Note that the threshold may be exceeded by 50% before the limit\n# is enforced. So when you set the threshold to 10, up to 15 fields may appear,\n# but if the number exceeds 15, the total amount of fields shown is limited to\n# 10.\n# Minimum value: 0, maximum value: 100, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LIMIT_NUM_FIELDS   = 10\n\n# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and\n# collaboration graphs will show the relations between templates and their\n# instances.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nTEMPLATE_RELATIONS     = NO\n\n# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to\n# YES then doxygen will generate a graph for each documented file showing the\n# direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDE_GRAPH          = YES\n\n# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are\n# set to YES then doxygen will generate a graph for each documented file showing\n# the direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDED_BY_GRAPH      = YES\n\n# If the CALL_GRAPH tag is set to YES then doxygen will generate a call\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable call graphs for selected\n# functions only using the \\callgraph command. Disabling a call graph can be\n# accomplished by means of the command \\hidecallgraph.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALL_GRAPH             = NO\n\n# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable caller graphs for selected\n# functions only using the \\callergraph command. Disabling a caller graph can be\n# accomplished by means of the command \\hidecallergraph.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALLER_GRAPH           = NO\n\n# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical\n# hierarchy of all classes instead of a textual one.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGRAPHICAL_HIERARCHY    = YES\n\n# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the\n# dependencies a directory has on other directories in a graphical way. The\n# dependency relations are determined by the #include relations between the\n# files in the directories.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDIRECTORY_GRAPH        = YES\n\n# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images\n# generated by dot. For an explanation of the image formats see the section\n# output formats in the documentation of the dot tool (Graphviz (see:\n# http://www.graphviz.org/)).\n# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order\n# to make the SVG files visible in IE 9+ (other browsers do not have this\n# requirement).\n# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo,\n# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and\n# png:gdiplus:gdiplus.\n# The default value is: png.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_IMAGE_FORMAT       = png\n\n# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to\n# enable generation of interactive SVG images that allow zooming and panning.\n#\n# Note that this requires a modern browser other than Internet Explorer. Tested\n# and working are Firefox, Chrome, Safari, and Opera.\n# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make\n# the SVG files visible. Older versions of IE do not have SVG support.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINTERACTIVE_SVG        = NO\n\n# The DOT_PATH tag can be used to specify the path where the dot tool can be\n# found. If left blank, it is assumed the dot tool can be found in the path.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_PATH               = \n\n# The DOTFILE_DIRS tag can be used to specify one or more directories that\n# contain dot files that are included in the documentation (see the \\dotfile\n# command).\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOTFILE_DIRS           = \n\n# The MSCFILE_DIRS tag can be used to specify one or more directories that\n# contain msc files that are included in the documentation (see the \\mscfile\n# command).\n\nMSCFILE_DIRS           = \n\n# The DIAFILE_DIRS tag can be used to specify one or more directories that\n# contain dia files that are included in the documentation (see the \\diafile\n# command).\n\nDIAFILE_DIRS           = \n\n# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the\n# path where java can find the plantuml.jar file. If left blank, it is assumed\n# PlantUML is not used or called during a preprocessing step. Doxygen will\n# generate a warning when it encounters a \\startuml command in this case and\n# will not generate output for the diagram.\n\nPLANTUML_JAR_PATH      = \n\n# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a\n# configuration file for plantuml.\n\nPLANTUML_CFG_FILE      = \n\n# When using plantuml, the specified paths are searched for files specified by\n# the !include statement in a plantuml block.\n\nPLANTUML_INCLUDE_PATH  = \n\n# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes\n# that will be shown in the graph. If the number of nodes in a graph becomes\n# larger than this value, doxygen will truncate the graph, which is visualized\n# by representing a node as a red box. Note that doxygen if the number of direct\n# children of the root node in a graph is already larger than\n# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that\n# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.\n# Minimum value: 0, maximum value: 10000, default value: 50.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_GRAPH_MAX_NODES    = 50\n\n# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs\n# generated by dot. A depth value of 3 means that only nodes reachable from the\n# root by following a path via at most 3 edges will be shown. Nodes that lay\n# further from the root node will be omitted. Note that setting this option to 1\n# or 2 may greatly reduce the computation time needed for large code bases. Also\n# note that the size of a graph can be further restricted by\n# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.\n# Minimum value: 0, maximum value: 1000, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nMAX_DOT_GRAPH_DEPTH    = 0\n\n# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent\n# background. This is disabled by default, because dot on Windows does not seem\n# to support this out of the box.\n#\n# Warning: Depending on the platform used, enabling this option may lead to\n# badly anti-aliased labels on the edges of a graph (i.e. they become hard to\n# read).\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_TRANSPARENT        = NO\n\n# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output\n# files in one run (i.e. multiple -o and -T options on the command line). This\n# makes dot run faster, but since only newer versions of dot (>1.8.10) support\n# this, this feature is disabled by default.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_MULTI_TARGETS      = NO\n\n# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page\n# explaining the meaning of the various boxes and arrows in the dot generated\n# graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGENERATE_LEGEND        = YES\n\n# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot\n# files that are used to generate the various graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_CLEANUP            = YES\n"
  },
  {
    "path": "README.md",
    "content": "# TR2Main\n\nThis is an open source implementation of the classic Tomb Raider II game (1997), made by reverse engineering of the original game for PC and PS1. Right now it's a dynamic library injecting the original game EXE to allow step-by-step decompilation, fixing, and improvement, but someday it will become single EXE file.\n\nThe goal of the project is to make 1:1 clone of the original PC game, to fix all its bugs, and to add more features from non-PC official ports (for example from PS1). So TR2Main is some sort of unofficial modern PC port of Tomb Raider II.\n\n## Getting Started\n\nYou may download patched Tomb2.exe, TR2Main.dll from [releases](https://github.com/Arsunt/TR2Main/releases), put them in your game folder and just launch. Also you may build TR2Main.dll yourself and use it with patched Tomb2.exe from [here](/binaries).\n\nThe Golden Mask game is included into a [release pack](https://github.com/Arsunt/TR2Main/releases), since it's freeware. The original game level files must be officially obtained via Steam/GOG/CD/whatever.\n\n## Changelog\n\nLearn about [the latest improvements](CHANGELOG.md).\n\n## Built With\n\n* [Code::Blocks](http://www.codeblocks.org) - C/C++ IDE used\n* [GCC](https://gcc.gnu.org) - C/C++ compiler\n* [Doxygen](http://www.doxygen.org) - documentation\n\n## Authors\n\n* **Michael Chaban** \\([Arsunt](https://github.com/Arsunt)\\). Author of the project. E-mail: <arsunt@gmail.com>\n* [**ChocolateFan**](https://github.com/asasas9500). Decompilation.\n* [**TokyoSU**](https://github.com/TokyoSU). Decompilation and features development.\n* **PaulD**. Author of [CD audio solution](modding/cd_pauld.cpp) used now by Steam.\n* [**Lito Perezito**](https://litoperezito.com). The artist who created loading screens for The Golden Mask.\n\n## License\n\nThis project is licensed under the GNU General Public License - see the [COPYING.md](COPYING.md) file for details\n\n## Acknowledgments\n\nIf you are inspired by my project and decided to borrow some of the ideas found in the code, do not forget provide a link to this project. It took me years to decompile and understand the details required for this project.\n\n## Copyright\n(c) 2017-2023 Michael Chaban. All rights reserved.\nOriginal game is created by Core Design Ltd. in 1997.\nLara Croft and Tomb Raider are trademarks of Embracer Group AB."
  },
  {
    "path": "TR2Main.cbp",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n<CodeBlocks_project_file>\n\t<FileVersion major=\"1\" minor=\"6\" />\n\t<Project>\n\t\t<Option title=\"TR2Main\" />\n\t\t<Option compiler=\"gcc\" />\n\t\t<Build>\n\t\t\t<Target title=\"DX5-Debug\">\n\t\t\t\t<Option output=\"bin/DX5-Debug/TR2Main\" prefix_auto=\"1\" extension_auto=\"1\" />\n\t\t\t\t<Option working_dir=\"%TR2_DIR%/\" />\n\t\t\t\t<Option object_output=\"obj/DX5-Debug/\" />\n\t\t\t\t<Option type=\"3\" />\n\t\t\t\t<Option compiler=\"gcc\" />\n\t\t\t\t<Option host_application=\"%TR2_DIR%/tomb2.exe\" />\n\t\t\t\t<Option run_host_application_in_terminal=\"0\" />\n\t\t\t\t<Option createDefFile=\"1\" />\n\t\t\t\t<Option createStaticLib=\"1\" />\n\t\t\t\t<Compiler>\n\t\t\t\t\t<Add option=\"-g\" />\n\t\t\t\t\t<Add option=\"-Wall\" />\n\t\t\t\t\t<Add option=\"-D_DEBUG\" />\n\t\t\t\t\t<Add option=\"-DDIRECTDRAW_VERSION=0x500\" />\n\t\t\t\t\t<Add option=\"-DDIRECT3D_VERSION=0x500\" />\n\t\t\t\t\t<Add option=\"-DDIRECTINPUT_VERSION=0x500\" />\n\t\t\t\t\t<Add option=\"-DDIRECTSOUND_VERSION=0x500\" />\n\t\t\t\t\t<Add directory=\"../DX7_SDK/include\" />\n\t\t\t\t</Compiler>\n\t\t\t\t<Linker>\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/dxguid.lib\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/ddraw.lib\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/d3dx.lib\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/dinput.lib\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/dsound.lib\" />\n\t\t\t\t</Linker>\n\t\t\t</Target>\n\t\t\t<Target title=\"DX5-Release\">\n\t\t\t\t<Option output=\"bin/DX5-Release/TR2Main\" prefix_auto=\"1\" extension_auto=\"1\" />\n\t\t\t\t<Option working_dir=\"%TR2_DIR%/\" />\n\t\t\t\t<Option object_output=\"obj/DX5-Release/\" />\n\t\t\t\t<Option type=\"3\" />\n\t\t\t\t<Option compiler=\"gcc\" />\n\t\t\t\t<Option host_application=\"%TR2_DIR%/tomb2.exe\" />\n\t\t\t\t<Option run_host_application_in_terminal=\"0\" />\n\t\t\t\t<Option createDefFile=\"1\" />\n\t\t\t\t<Option createStaticLib=\"1\" />\n\t\t\t\t<Compiler>\n\t\t\t\t\t<Add option=\"-O3\" />\n\t\t\t\t\t<Add option=\"-Wall\" />\n\t\t\t\t\t<Add option=\"-Wextra\" />\n\t\t\t\t\t<Add option=\"-Wno-unused-parameter\" />\n\t\t\t\t\t<Add option=\"-D_RELEASE\" />\n\t\t\t\t\t<Add option=\"-DDIRECTDRAW_VERSION=0x500\" />\n\t\t\t\t\t<Add option=\"-DDIRECT3D_VERSION=0x500\" />\n\t\t\t\t\t<Add option=\"-DDIRECTINPUT_VERSION=0x500\" />\n\t\t\t\t\t<Add option=\"-DDIRECTSOUND_VERSION=0x500\" />\n\t\t\t\t\t<Add directory=\"../DX7_SDK/include\" />\n\t\t\t\t</Compiler>\n\t\t\t\t<Linker>\n\t\t\t\t\t<Add option=\"-s\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/dxguid.lib\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/ddraw.lib\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/d3dx.lib\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/dinput.lib\" />\n\t\t\t\t\t<Add library=\"../DX7_SDK/lib/dsound.lib\" />\n\t\t\t\t</Linker>\n\t\t\t</Target>\n\t\t\t<Target title=\"DX9-Debug\">\n\t\t\t\t<Option output=\"bin/DX9-Debug/TR2Main\" prefix_auto=\"1\" extension_auto=\"1\" />\n\t\t\t\t<Option working_dir=\"%TR2_DIR%/\" />\n\t\t\t\t<Option object_output=\"obj/DX9-Debug/\" />\n\t\t\t\t<Option type=\"3\" />\n\t\t\t\t<Option compiler=\"gcc\" />\n\t\t\t\t<Option host_application=\"%TR2_DIR%/tomb2.exe\" />\n\t\t\t\t<Option run_host_application_in_terminal=\"0\" />\n\t\t\t\t<Option createDefFile=\"1\" />\n\t\t\t\t<Option createStaticLib=\"1\" />\n\t\t\t\t<Compiler>\n\t\t\t\t\t<Add option=\"-g\" />\n\t\t\t\t\t<Add option=\"-Wall\" />\n\t\t\t\t\t<Add option=\"-D_DEBUG\" />\n\t\t\t\t\t<Add option=\"-DDIRECT3D_VERSION=0x900\" />\n\t\t\t\t\t<Add option=\"-DDIRECTINPUT_VERSION=0x900\" />\n\t\t\t\t\t<Add option=\"-DDIRECTSOUND_VERSION=0x900\" />\n\t\t\t\t</Compiler>\n\t\t\t\t<Linker>\n\t\t\t\t\t<Add library=\"dxguid\" />\n\t\t\t\t\t<Add library=\"d3d9\" />\n\t\t\t\t\t<Add library=\"d3dx9\" />\n\t\t\t\t\t<Add library=\"dinput8\" />\n\t\t\t\t\t<Add library=\"dsound\" />\n\t\t\t\t</Linker>\n\t\t\t</Target>\n\t\t\t<Target title=\"DX9-Release\">\n\t\t\t\t<Option output=\"bin/DX9-Release/TR2Main\" prefix_auto=\"1\" extension_auto=\"1\" />\n\t\t\t\t<Option working_dir=\"%TR2_DIR%/\" />\n\t\t\t\t<Option object_output=\"obj/DX9-Release/\" />\n\t\t\t\t<Option type=\"3\" />\n\t\t\t\t<Option compiler=\"gcc\" />\n\t\t\t\t<Option host_application=\"%TR2_DIR%/tomb2.exe\" />\n\t\t\t\t<Option run_host_application_in_terminal=\"0\" />\n\t\t\t\t<Option createDefFile=\"1\" />\n\t\t\t\t<Option createStaticLib=\"1\" />\n\t\t\t\t<Compiler>\n\t\t\t\t\t<Add option=\"-O3\" />\n\t\t\t\t\t<Add option=\"-Wall\" />\n\t\t\t\t\t<Add option=\"-Wextra\" />\n\t\t\t\t\t<Add option=\"-Wno-unused-parameter\" />\n\t\t\t\t\t<Add option=\"-D_RELEASE\" />\n\t\t\t\t\t<Add option=\"-DDIRECT3D_VERSION=0x900\" />\n\t\t\t\t\t<Add option=\"-DDIRECTINPUT_VERSION=0x900\" />\n\t\t\t\t\t<Add option=\"-DDIRECTSOUND_VERSION=0x900\" />\n\t\t\t\t</Compiler>\n\t\t\t\t<Linker>\n\t\t\t\t\t<Add option=\"-s\" />\n\t\t\t\t\t<Add library=\"dxguid\" />\n\t\t\t\t\t<Add library=\"d3d9\" />\n\t\t\t\t\t<Add library=\"d3dx9\" />\n\t\t\t\t\t<Add library=\"dinput8\" />\n\t\t\t\t\t<Add library=\"dsound\" />\n\t\t\t\t</Linker>\n\t\t\t</Target>\n\t\t</Build>\n\t\t<Compiler>\n\t\t\t<Add option=\"-m32\" />\n\t\t\t<Add option=\"-Winvalid-pch\" />\n\t\t\t<Add option=\"-Wno-unknown-pragmas\" />\n\t\t\t<Add option=\"-DBUILD_DLL\" />\n\t\t\t<Add option=\"-D_WIN32_WINNT=0x501\" />\n\t\t\t<Add option=\"-DFEATURE_ASSAULT_SAVE\" />\n\t\t\t<Add option=\"-DFEATURE_AUDIO_IMPROVED\" />\n\t\t\t<Add option=\"-DFEATURE_BACKGROUND_IMPROVED\" />\n\t\t\t<Add option=\"-DFEATURE_CHEAT\" />\n\t\t\t<Add option=\"-DFEATURE_EXTENDED_LIMITS\" />\n\t\t\t<Add option=\"-DFEATURE_FFPLAY\" />\n\t\t\t<Add option=\"-DFEATURE_GAMEPLAY_FIXES\" />\n\t\t\t<Add option=\"-DFEATURE_GOLD\" />\n\t\t\t<Add option=\"-DFEATURE_HUD_IMPROVED\" />\n\t\t\t<Add option=\"-DFEATURE_INPUT_IMPROVED\" />\n\t\t\t<Add option=\"-DFEATURE_MOD_CONFIG\" />\n\t\t\t<Add option=\"-DFEATURE_NOCD_DATA\" />\n\t\t\t<Add option=\"-DFEATURE_NOLEGACY_OPTIONS\" />\n\t\t\t<Add option=\"-DFEATURE_PAULD_CDAUDIO\" />\n\t\t\t<Add option=\"-DFEATURE_SCREENSHOT_IMPROVED\" />\n\t\t\t<Add option=\"-DFEATURE_SUBFOLDERS\" />\n\t\t\t<Add option=\"-DFEATURE_VIDEOFX_IMPROVED\" />\n\t\t\t<Add option=\"-DFEATURE_VIEW_IMPROVED\" />\n\t\t\t<Add option=\"-DFEATURE_WINDOW_STYLE_FIX\" />\n\t\t</Compiler>\n\t\t<Linker>\n\t\t\t<Add option=\"-static-libstdc++\" />\n\t\t\t<Add option=\"-static-libgcc\" />\n\t\t\t<Add option=\"-static\" />\n\t\t\t<Add option=\"-m32\" />\n\t\t\t<Add option=\"-Wl,--kill-at\" />\n\t\t\t<Add library=\"user32\" />\n\t\t\t<Add library=\"shell32\" />\n\t\t\t<Add library=\"gdi32\" />\n\t\t\t<Add library=\"gdiplus\" />\n\t\t\t<Add library=\"comctl32\" />\n\t\t\t<Add library=\"shlwapi\" />\n\t\t\t<Add library=\"winmm\" />\n\t\t\t<Add library=\"hid\" />\n\t\t\t<Add library=\"ole32\" />\n\t\t\t<Add library=\"oleaut32\" />\n\t\t\t<Add library=\"setupapi\" />\n\t\t</Linker>\n\t\t<ExtraCommands>\n\t\t\t<Add after='cmd /c copy &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(TR2_DIR)&quot;' />\n\t\t</ExtraCommands>\n\t\t<Unit filename=\"TR2Main.cpp\" />\n\t\t<Unit filename=\"TR2Main.rc\">\n\t\t\t<Option compilerVar=\"WINDRES\" />\n\t\t</Unit>\n\n\t\t<Unit filename=\"global/precompiled.h\">\n\t\t\t<Option compile=\"1\" />\n\t\t\t<Option weight=\"0\" />\n\t\t</Unit>\n\n\t\t<Unit filename=\"global/types.h\" />\n\t\t<Unit filename=\"global/resource.h\" />\n\t\t<Unit filename=\"global/vars.h\" />\n\t\t<Unit filename=\"global/md5.c\" />\n\t\t<Unit filename=\"global/md5.h\" />\n\t\t<Unit filename=\"global/memmem.c\" />\n\t\t<Unit filename=\"global/memmem.h\" />\n\n\t\t<Unit filename=\"3dsystem/3d_gen.cpp\" />\n\t\t<Unit filename=\"3dsystem/3d_gen.h\" />\n\n\t\t<Unit filename=\"3dsystem/3d_out.cpp\" />\n\t\t<Unit filename=\"3dsystem/3d_out.h\" />\n\n\t\t<Unit filename=\"3dsystem/3dinsert.cpp\" />\n\t\t<Unit filename=\"3dsystem/3dinsert.h\" />\n\n\t\t<Unit filename=\"3dsystem/phd_math.cpp\" />\n\t\t<Unit filename=\"3dsystem/phd_math.h\" />\n\n\t\t<Unit filename=\"3dsystem/scalespr.cpp\" />\n\t\t<Unit filename=\"3dsystem/scalespr.h\" />\n\n\t\t<Unit filename=\"game/bear.cpp\" />\n\t\t<Unit filename=\"game/bear.h\" />\n\n\t\t<Unit filename=\"game/bird.cpp\" />\n\t\t<Unit filename=\"game/bird.h\" />\n\n\t\t<Unit filename=\"game/boat.cpp\" />\n\t\t<Unit filename=\"game/boat.h\" />\n\n\t\t<Unit filename=\"game/box.cpp\" />\n\t\t<Unit filename=\"game/box.h\" />\n\n\t\t<Unit filename=\"game/camera.cpp\" />\n\t\t<Unit filename=\"game/camera.h\" />\n\n\t\t<Unit filename=\"game/cinema.cpp\" />\n\t\t<Unit filename=\"game/cinema.h\" />\n\n\t\t<Unit filename=\"game/collide.cpp\" />\n\t\t<Unit filename=\"game/collide.h\" />\n\n\t\t<Unit filename=\"game/control.cpp\" />\n\t\t<Unit filename=\"game/control.h\" />\n\n\t\t<Unit filename=\"game/demo.cpp\" />\n\t\t<Unit filename=\"game/demo.h\" />\n\n\t\t<Unit filename=\"game/diver.cpp\" />\n\t\t<Unit filename=\"game/diver.h\" />\n\n\t\t<Unit filename=\"game/dog.cpp\" />\n\t\t<Unit filename=\"game/dog.h\" />\n\n\t\t<Unit filename=\"game/dragon.cpp\" />\n\t\t<Unit filename=\"game/dragon.h\" />\n\n\t\t<Unit filename=\"game/draw.cpp\" />\n\t\t<Unit filename=\"game/draw.h\" />\n\n\t\t<Unit filename=\"game/eel.cpp\" />\n\t\t<Unit filename=\"game/eel.h\" />\n\n\t\t<Unit filename=\"game/effects.cpp\" />\n\t\t<Unit filename=\"game/effects.h\" />\n\n\t\t<Unit filename=\"game/enemies.cpp\" />\n\t\t<Unit filename=\"game/enemies.h\" />\n\n\t\t<Unit filename=\"game/gameflow.cpp\" />\n\t\t<Unit filename=\"game/gameflow.h\" />\n\n\t\t<Unit filename=\"game/hair.cpp\" />\n\t\t<Unit filename=\"game/hair.h\" />\n\n\t\t<Unit filename=\"game/health.cpp\" />\n\t\t<Unit filename=\"game/health.h\" />\n\n\t\t<Unit filename=\"game/inventory.cpp\" />\n\t\t<Unit filename=\"game/inventory.h\" />\n\n\t\t<Unit filename=\"game/invfunc.cpp\" />\n\t\t<Unit filename=\"game/invfunc.h\" />\n\n\t\t<Unit filename=\"game/invtext.cpp\" />\n\t\t<Unit filename=\"game/invtext.h\" />\n\n\t\t<Unit filename=\"game/items.cpp\" />\n\t\t<Unit filename=\"game/items.h\" />\n\n\t\t<Unit filename=\"game/lara.cpp\" />\n\t\t<Unit filename=\"game/lara.h\" />\n\n\t\t<Unit filename=\"game/lara1gun.cpp\" />\n\t\t<Unit filename=\"game/lara1gun.h\" />\n\n\t\t<Unit filename=\"game/lara2gun.cpp\" />\n\t\t<Unit filename=\"game/lara2gun.h\" />\n\n\t\t<Unit filename=\"game/laraclimb.cpp\" />\n\t\t<Unit filename=\"game/laraclimb.h\" />\n\n\t\t<Unit filename=\"game/larafire.cpp\" />\n\t\t<Unit filename=\"game/larafire.h\" />\n\n\t\t<Unit filename=\"game/laraflare.cpp\" />\n\t\t<Unit filename=\"game/laraflare.h\" />\n\n\t\t<Unit filename=\"game/laramisc.cpp\" />\n\t\t<Unit filename=\"game/laramisc.h\" />\n\n\t\t<Unit filename=\"game/larasurf.cpp\" />\n\t\t<Unit filename=\"game/larasurf.h\" />\n\n\t\t<Unit filename=\"game/laraswim.cpp\" />\n\t\t<Unit filename=\"game/laraswim.h\" />\n\n\t\t<Unit filename=\"game/lot.cpp\" />\n\t\t<Unit filename=\"game/lot.h\" />\n\n\t\t<Unit filename=\"game/missile.cpp\" />\n\t\t<Unit filename=\"game/missile.h\" />\n\n\t\t<Unit filename=\"game/moveblock.cpp\" />\n\t\t<Unit filename=\"game/moveblock.h\" />\n\n\t\t<Unit filename=\"game/objects.cpp\" />\n\t\t<Unit filename=\"game/objects.h\" />\n\n\t\t<Unit filename=\"game/people.cpp\" />\n\t\t<Unit filename=\"game/people.h\" />\n\n\t\t<Unit filename=\"game/pickup.cpp\" />\n\t\t<Unit filename=\"game/pickup.h\" />\n\n\t\t<Unit filename=\"game/rat.cpp\" />\n\t\t<Unit filename=\"game/rat.h\" />\n\n\t\t<Unit filename=\"game/savegame.cpp\" />\n\t\t<Unit filename=\"game/savegame.h\" />\n\n\t\t<Unit filename=\"game/setup.cpp\" />\n\t\t<Unit filename=\"game/setup.h\" />\n\n\t\t<Unit filename=\"game/shark.cpp\" />\n\t\t<Unit filename=\"game/shark.h\" />\n\n\t\t<Unit filename=\"game/skidoo.cpp\" />\n\t\t<Unit filename=\"game/skidoo.h\" />\n\n\t\t<Unit filename=\"game/sound.cpp\" />\n\t\t<Unit filename=\"game/sound.h\" />\n\n\t\t<Unit filename=\"game/sphere.cpp\" />\n\t\t<Unit filename=\"game/sphere.h\" />\n\n\t\t<Unit filename=\"game/spider.cpp\" />\n\t\t<Unit filename=\"game/spider.h\" />\n\n\t\t<Unit filename=\"game/text.cpp\" />\n\t\t<Unit filename=\"game/text.h\" />\n\n\t\t<Unit filename=\"game/traps.cpp\" />\n\t\t<Unit filename=\"game/traps.h\" />\n\n\t\t<Unit filename=\"game/wolf.cpp\" />\n\t\t<Unit filename=\"game/wolf.h\" />\n\n\t\t<Unit filename=\"game/yeti.cpp\" />\n\t\t<Unit filename=\"game/yeti.h\" />\n\n\t\t<Unit filename=\"specific/background.cpp\" />\n\t\t<Unit filename=\"specific/background.h\" />\n\n\t\t<Unit filename=\"specific/display.cpp\" />\n\t\t<Unit filename=\"specific/display.h\" />\n\n\t\t<Unit filename=\"specific/file.cpp\" />\n\t\t<Unit filename=\"specific/file.h\" />\n\n\t\t<Unit filename=\"specific/fmv.cpp\" />\n\t\t<Unit filename=\"specific/fmv.h\" />\n\n\t\t<Unit filename=\"specific/frontend.cpp\" />\n\t\t<Unit filename=\"specific/frontend.h\" />\n\n\t\t<Unit filename=\"specific/game.cpp\" />\n\t\t<Unit filename=\"specific/game.h\" />\n\n\t\t<Unit filename=\"specific/hwr.cpp\" />\n\t\t<Unit filename=\"specific/hwr.h\" />\n\n\t\t<Unit filename=\"specific/init.cpp\" />\n\t\t<Unit filename=\"specific/init.h\" />\n\n\t\t<Unit filename=\"specific/init_3d.cpp\" />\n\t\t<Unit filename=\"specific/init_3d.h\" />\n\n\t\t<Unit filename=\"specific/init_display.cpp\" />\n\t\t<Unit filename=\"specific/init_display.h\" />\n\n\t\t<Unit filename=\"specific/init_input.cpp\" />\n\t\t<Unit filename=\"specific/init_input.h\" />\n\n\t\t<Unit filename=\"specific/init_sound.cpp\" />\n\t\t<Unit filename=\"specific/init_sound.h\" />\n\n\t\t<Unit filename=\"specific/input.cpp\" />\n\t\t<Unit filename=\"specific/input.h\" />\n\n\t\t<Unit filename=\"specific/option.cpp\" />\n\t\t<Unit filename=\"specific/option.h\" />\n\n\t\t<Unit filename=\"specific/output.cpp\" />\n\t\t<Unit filename=\"specific/output.h\" />\n\n\t\t<Unit filename=\"specific/registry.cpp\" />\n\t\t<Unit filename=\"specific/registry.h\" />\n\n\t\t<Unit filename=\"specific/screenshot.cpp\" />\n\t\t<Unit filename=\"specific/screenshot.h\" />\n\n\t\t<Unit filename=\"specific/setupdlg.cpp\" />\n\t\t<Unit filename=\"specific/setupdlg.h\" />\n\n\t\t<Unit filename=\"specific/setupwnd.cpp\" />\n\t\t<Unit filename=\"specific/setupwnd.h\" />\n\n\t\t<Unit filename=\"specific/smain.cpp\" />\n\t\t<Unit filename=\"specific/smain.h\" />\n\n\t\t<Unit filename=\"specific/sndpc.cpp\" />\n\t\t<Unit filename=\"specific/sndpc.h\" />\n\n\t\t<Unit filename=\"specific/texture.cpp\" />\n\t\t<Unit filename=\"specific/texture.h\" />\n\n\t\t<Unit filename=\"specific/utils.cpp\" />\n\t\t<Unit filename=\"specific/utils.h\" />\n\n\t\t<Unit filename=\"specific/winmain.cpp\" />\n\t\t<Unit filename=\"specific/winmain.h\" />\n\n\t\t<Unit filename=\"specific/winvid.cpp\" />\n\t\t<Unit filename=\"specific/winvid.h\" />\n\n\t\t<Unit filename=\"modding/background_new.cpp\" />\n\t\t<Unit filename=\"modding/background_new.h\" />\n\n\t\t<Unit filename=\"modding/cd_pauld.cpp\" />\n\t\t<Unit filename=\"modding/cd_pauld.h\" />\n\n\t\t<Unit filename=\"modding/file_utils.cpp\" />\n\t\t<Unit filename=\"modding/file_utils.h\" />\n\n\t\t<Unit filename=\"modding/gdi_utils.cpp\" />\n\t\t<Unit filename=\"modding/gdi_utils.h\" />\n\n\t\t<Unit filename=\"modding/joy_output.cpp\" />\n\t\t<Unit filename=\"modding/joy_output.h\" />\n\n\t\t<Unit filename=\"modding/json_utils.cpp\" />\n\t\t<Unit filename=\"modding/json_utils.h\" />\n\n\t\t<Unit filename=\"modding/mod_utils.cpp\" />\n\t\t<Unit filename=\"modding/mod_utils.h\" />\n\n\t\t<Unit filename=\"modding/pause.cpp\" />\n\t\t<Unit filename=\"modding/pause.h\" />\n\n\t\t<Unit filename=\"modding/psx_bar.cpp\" />\n\t\t<Unit filename=\"modding/psx_bar.h\" />\n\n\t\t<Unit filename=\"modding/raw_input.cpp\" />\n\t\t<Unit filename=\"modding/raw_input.h\" />\n\n\t\t<Unit filename=\"modding/texture_utils.cpp\" />\n\t\t<Unit filename=\"modding/texture_utils.h\" />\n\n\t\t<Unit filename=\"modding/xinput_ex.cpp\" />\n\t\t<Unit filename=\"modding/xinput_ex.h\" />\n\n\t\t<Unit filename=\"json-parser/json.c\" />\n\t\t<Unit filename=\"json-parser/json.h\" />\n\n\t\t<Extensions>\n\t\t\t<code_completion />\n\t\t\t<envvars />\n\t\t\t<debugger />\n\t\t\t<lib_finder disable_auto=\"1\" />\n\t\t</Extensions>\n\t</Project>\n</CodeBlocks_project_file>\n"
  },
  {
    "path": "TR2Main.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n/**\n * @file\n * @brief TR2Main interface\n *\n * This file implements TR2Main.DLL exported functions and interfaces\n */\n\n/**\n * @defgroup TR2MAIN TR2Main\n * @brief TR2Main interface\n *\n * This module contains TR2Main.DLL exported functions and interfaces\n *\n * @{\n */\n\n#include <windows.h>\n\n/** @cond Doxygen_Suppress */\n#ifdef BUILD_DLL\n#define DLL_EXPORT __declspec(dllexport)\n#else\n#define DLL_EXPORT __declspec(dllimport)\n#endif\n/** @endcond */\n\nHINSTANCE hInstance = NULL;\n\n// 3d system\nextern void Inject_3Dgen();\nextern void Inject_3Dout();\nextern void Inject_3Dinsert();\nextern void Inject_PhdMath();\nextern void Inject_ScaleSpr();\n// game\nextern void Inject_Bird();\nextern void Inject_Boat();\nextern void Inject_Box();\nextern void Inject_Camera();\nextern void Inject_Cinema();\nextern void Inject_Collide();\nextern void Inject_Control();\nextern void Inject_Demo();\nextern void Inject_Diver();\nextern void Inject_Dog();\nextern void Inject_Dragon();\nextern void Inject_Draw();\nextern void Inject_Eel();\nextern void Inject_Effects();\nextern void Inject_Enemies();\nextern void Inject_Gameflow();\nextern void Inject_Hair();\nextern void Inject_Health();\nextern void Inject_Inventory();\nextern void Inject_InvFunc();\nextern void Inject_InvText();\nextern void Inject_Items();\nextern void Inject_Lara();\nextern void Inject_Lara1Gun();\nextern void Inject_Lara2Gun();\nextern void Inject_LaraClimb();\nextern void Inject_LaraFire();\nextern void Inject_LaraFlare();\nextern void Inject_LaraMisc();\nextern void Inject_LaraSurf();\nextern void Inject_LaraSwim();\nextern void Inject_Lot();\nextern void Inject_Missile();\nextern void Inject_MoveBlock();\nextern void Inject_Objects();\nextern void Inject_People();\nextern void Inject_Pickup();\nextern void Inject_Rat();\nextern void Inject_SaveGame();\nextern void Inject_Setup();\nextern void Inject_Shark();\nextern void Inject_Skidoo();\nextern void Inject_Sound();\nextern void Inject_Sphere();\nextern void Inject_Spider();\nextern void Inject_Text();\nextern void Inject_Traps();\nextern void Inject_Yeti();\n// specific\nextern void Inject_Background();\nextern void Inject_Display();\nextern void Inject_File();\nextern void Inject_Fmv();\nextern void Inject_Frontend();\nextern void Inject_Game();\nextern void Inject_HWR();\nextern void Inject_Init();\nextern void Inject_Init3d();\nextern void Inject_InitDisplay();\nextern void Inject_InitInput();\nextern void Inject_InitSound();\nextern void Inject_Input();\nextern void Inject_Option();\nextern void Inject_Output();\nextern void Inject_Registry();\nextern void Inject_Screenshot();\nextern void Inject_SetupDlg();\nextern void Inject_SetupWnd();\nextern void Inject_SMain();\nextern void Inject_SndPC();\nextern void Inject_Texture();\nextern void Inject_Utils();\nextern void Inject_WinMain();\nextern void Inject_WinVid();\n\nstatic void Inject() {\n// 3d system\n\tInject_3Dgen();\n\tInject_3Dout();\n\tInject_3Dinsert();\n\tInject_PhdMath();\n\tInject_ScaleSpr();\n// game\n\tInject_Bird();\n\tInject_Boat();\n\tInject_Box();\n\tInject_Camera();\n\tInject_Cinema();\n\tInject_Collide();\n\tInject_Control();\n\tInject_Demo();\n\tInject_Diver();\n\tInject_Dog();\n\tInject_Dragon();\n\tInject_Draw();\n\tInject_Eel();\n\tInject_Effects();\n\tInject_Enemies();\n\tInject_Gameflow();\n\tInject_Hair();\n\tInject_Health();\n\tInject_Inventory();\n\tInject_InvFunc();\n\tInject_InvText();\n\tInject_Items();\n\tInject_Lara();\n\tInject_Lara1Gun();\n\tInject_Lara2Gun();\n\tInject_LaraClimb();\n\tInject_LaraFire();\n\tInject_LaraFlare();\n\tInject_LaraMisc();\n\tInject_LaraSurf();\n\tInject_LaraSwim();\n\tInject_Lot();\n\tInject_Missile();\n\tInject_MoveBlock();\n\tInject_Objects();\n\tInject_People();\n\tInject_Pickup();\n\tInject_Rat();\n\tInject_SaveGame();\n\tInject_Setup();\n\tInject_Shark();\n\tInject_Skidoo();\n\tInject_Sound();\n\tInject_Sphere();\n\tInject_Spider();\n\tInject_Text();\n\tInject_Traps();\n\tInject_Yeti();\n// specific\n\tInject_Background();\n\tInject_Display();\n\tInject_File();\n\tInject_Fmv();\n\tInject_Frontend();\n\tInject_Game();\n\tInject_HWR();\n\tInject_Init();\n\tInject_Init3d();\n\tInject_InitDisplay();\n\tInject_InitInput();\n\tInject_InitSound();\n\tInject_Input();\n\tInject_Option();\n\tInject_Output();\n\tInject_Registry();\n\tInject_Screenshot();\n\tInject_SetupDlg();\n\tInject_SetupWnd();\n\tInject_SMain();\n\tInject_SndPC();\n\tInject_Texture();\n\tInject_Utils();\n\tInject_WinMain();\n\tInject_WinVid();\n}\n\nextern \"C\" DLL_EXPORT int DummyFunction() {\n\treturn 0;\n}\n\n/**\n * An optional entry point into a dynamic-link library (DLL)\n * @param[in] hinstDLL A handle to the DLL module\n * @param[in] fdwReason The reason code that indicates why the DLL\n * entry-point function is being called\n * @param[in] lpvReserved used if fdwReason is DLL_PROCESS_ATTACH or DLL_PROCESS_DETACH\n * @return TRUE if it succeeds or FALSE if it fails\n * @note See the MSDN for more information\n */\nextern \"C\" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {\n\tswitch( fdwReason ) {\n\t\tcase DLL_PROCESS_ATTACH :\n\t\t\t// attach to process\n\t\t\thInstance = hinstDLL;\n\t\t\tInject();\n\t\t\tbreak;\n\n\t\tcase DLL_PROCESS_DETACH :\n\t\t\t// detach from process\n\t\t\tbreak;\n\n\t\tcase DLL_THREAD_ATTACH :\n\t\t\t// attach to thread\n\t\t\tbreak;\n\n\t\tcase DLL_THREAD_DETACH :\n\t\t\t// detach from thread\n\t\t\tbreak;\n\t}\n\treturn TRUE; // successful\n}\n\n/** @} */\n"
  },
  {
    "path": "TR2Main.rc",
    "content": "/*\n * Copyright (c) 2017-2023 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include <windows.h>\n\n#define VER_MAJOR\t0\n#define VER_MINOR\t9\n#define VER_PATCH\t0\n#define VER_BUILD\t0\n\n#define STR_(x) #x\n#define STR(x) STR_(x)\n\n#define VER_FULL\tSTR(VER_MAJOR) \".\" STR(VER_MINOR) \".\" STR(VER_PATCH) \".\" STR(VER_BUILD) \"\\0\"\n#define VER_SHORT\tSTR(VER_MAJOR) \".\" STR(VER_MINOR) \"\\0\"\n\n// DLL version information.\nVS_VERSION_INFO\t\tVERSIONINFO\nFILEVERSION\t\t\tVER_MAJOR,VER_MINOR,VER_PATCH,VER_BUILD\nPRODUCTVERSION\t\tVER_MAJOR,VER_MINOR,VER_PATCH,VER_BUILD\nFILEFLAGSMASK\t\tVS_FFI_FILEFLAGSMASK\n#ifdef _DEBUG\n\tFILEFLAGS\t\tVS_FF_DEBUG | VS_FF_PRERELEASE\n#else\n\tFILEFLAGS\t\t0\n#endif\nFILEOS\t\t\t\tVOS_NT_WINDOWS32\nFILETYPE\t\t\tVFT_DLL\nFILESUBTYPE\t\t\tVFT2_UNKNOWN\nBEGIN\n\tBLOCK \"StringFileInfo\"\n\tBEGIN\n\t\tBLOCK \"080904b0\"\n\t\tBEGIN\n\t\t\tVALUE \"Comments\", \"https://github.com/Arsunt/TR2Main\"\n\t\t\tVALUE \"CompanyName\", \"Michael Chaban (arsunt@gmail.com)\"\n\t\t\tVALUE \"FileDescription\", \"Tomb Raider II Main Library\"\n\t\t\tVALUE \"FileVersion\", VER_FULL\n\t\t\tVALUE \"InternalName\", \"TR2Main\"\n\t\t\tVALUE \"LegalCopyright\", \" 2017-2023 Michael Chaban\"\n\t\t\tVALUE \"LegalTrademarks\", \"Original game is created by Core Design Ltd. in 1997. Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\"\n\t\t\tVALUE \"OriginalFilename\", \"TR2Main.dll\"\n\t\t\tVALUE \"ProductName\", \"Tomb Raider II Community Edition\"\n\t\t\tVALUE \"ProductVersion\", VER_SHORT\n\t\tEND\n\tEND\n\tBLOCK \"VarFileInfo\"\n\tBEGIN\n\t\tVALUE \"Translation\", 0x809, 1200\n\tEND\nEND\n\n// Embedded resources\nBUTTONS.JSON RCDATA \"embedded/BUTTONS.JSON\"\nBUTTONS.PCX RCDATA \"embedded/BUTTONS.PCX\"\n"
  },
  {
    "path": "TR2_progress.txt",
    "content": "x function is unused / included in another function\n+ function is reimplemented in DLL\n* function used by DLL from EXE\n\n// ======================================\n// 3D SYSTEM\n// ======================================\n\n\t3dsystem/3d_gen.cpp\n0x00401000:\t+\tphd_GenerateW2V\n0x004011D0:\t+\tphd_LookAt\n0x00401250:\t+\tphd_GetVectorAngles\n0x004012D0:\t+\tphd_RotX\n0x00401380:\t+\tphd_RotY\n0x00401430:\t+\tphd_RotZ\n0x004014E0:\t+\tphd_RotYXZ\n0x004016C0:\t+\tphd_RotYXZpack\n0x004018B0:\t+\tphd_TranslateRel\n0x00401960:\t+\tphd_TranslateAbs\n0x004019E0:\t+\tphd_PutPolygons\n0x00401AE0:\t+\tS_InsertRoom\n0x00401BD0:\t+\tcalc_background_light\n0x00401C10:\t+\tS_InsertBackground\n----------:\t+\tS_InsertInvBgnd\n0x00401D50:\t+\tcalc_object_vertices\n0x00401F30:\t+\tcalc_vertice_light\n0x004020A0:\t+\tcalc_roomvert\n0x00402320:\t+\tphd_RotateLight\n0x004023F0:\t+\tphd_InitPolyList\n0x00402420:\t+\tphd_SortPolyList\n0x00402460:\t+\tdo_quickysorty\n0x00402530:\t+\tphd_PrintPolyList\n0x00402570:\t+\tAlterFOV\n0x00402680:\t+\tphd_SetNearZ\n0x004026D0:\t+\tphd_SetFarZ\n0x004026F0:\t+\tphd_InitWindow\n----------:\t+\tphd_PopMatrix\n---asm----:\t+\tphd_PushMatrix\n---asm----:\t+\tphd_PushUnitMatrix\n\n\t3dsystem/3d_out.cpp\n0x00402960:\t+\tdraw_poly_line\n0x00402B00:\t+\tdraw_poly_flat\n0x00402B40:\t+\tdraw_poly_trans\n0x00402B80:\t+\tdraw_poly_gouraud\n0x00402BC0:\t+\tdraw_poly_gtmap\n0x00402C00:\t+\tdraw_poly_wgtmap\n0x00402C40:\t+\txgen_x\n0x00402D20:\t+\txgen_xg\n0x00402E70:\t+\txgen_xguv\n0x00403090:\t+\txgen_xguvpersp_fp\n0x00403320:\t+\tgtmap_persp32_fp\n0x004042F0:\t+\twgtmap_persp32_fp\n0x004057C0:\t+\tdraw_poly_gtmap_persp\n0x00405800:\t+\tdraw_poly_wgtmap_persp\n---asm----:\t+\tflatA\n---asm----:\t+\ttransA\n---asm----:\t+\tgourA\n---asm----:\t+\tgtmapA\n---asm----:\t+\twgtmapA\n\n\t3dsystem/3dinsert.cpp\n0x00405840:\t+\tvisible_zclip\n0x004058B0:\t+\tZedClipper\n0x004059F0:\t+\tXYGUVClipper\n0x00405F10:\t+\tInsertObjectGT4\n0x00406970:\t+\tInsertObjectGT3\n0x004071F0:\t+\tXYGClipper\n0x00407620:\t+\tInsertObjectG4\n0x00407A00:\t+\tInsertObjectG3\n0x00407D20:\t+\tXYClipper\n0x00407FF0:\t+\tInsertTrans8\n0x004084A0:\t+\tInsertTransQuad\n0x00408580:\t+\tInsertFlatRect\n0x00408650:\t+\tInsertLine\n0x00408710:\t+\tInsertGT3_ZBuffered\n0x00408D60:\t+\tDrawClippedPoly_Textured\n0x00408EA0:\t+\tInsertGT4_ZBuffered\n0x004092E0:\t+\tInsertObjectGT4_ZBuffered\n0x00409380:\t+\tInsertObjectGT3_ZBuffered\n0x00409430:\t+\tInsertObjectG4_ZBuffered\n0x004097D0:\t+\tDrawPoly_Gouraud\n0x004098D0:\t+\tInsertObjectG3_ZBuffered\n0x00409BB0:\t+\tInsertFlatRect_ZBuffered\n0x00409D80:\t+\tInsertLine_ZBuffered\n0x00409EC0:\t+\tInsertGT3_Sorted\n0x0040A5D0:\t+\tInsertClippedPoly_Textured\n0x0040A780:\t+\tInsertGT4_Sorted\n0x0040AC60:\t+\tInsertObjectGT4_Sorted\n0x0040ACF0:\t+\tInsertObjectGT3_Sorted\n0x0040AD90:\t+\tInsertObjectG4_Sorted\n0x0040B1D0:\t+\tInsertPoly_Gouraud\n0x0040B350:\t+\tInsertObjectG3_Sorted\n0x0040B6A0:\t+\tInsertSprite_Sorted\n0x0040B9F0:\t+\tInsertFlatRect_Sorted\n0x0040BB70:\t+\tInsertLine_Sorted\n0x0040BCA0:\t+\tInsertTrans8_Sorted\n0x0040BE40:\t+\tInsertTransQuad_Sorted\n0x0040BF80:\t+\tInsertSprite\n\n\t3dsystem/phd_math.cpp\n---asm----:\t+\tphd_atan\n---asm----:\t+\tphd_cos\n---asm----:\t+\tphd_sin\n---asm----:\t+\tphd_sqrt\n\n\t3dsystem/scalespr.cpp\n0x0040C030:\t+\tS_DrawSprite\n0x0040C300:\t+\tS_DrawPickup\n0x0040C390:\t+\tins_room_sprite\n0x0040C4F0:\t+\tS_DrawScreenSprite2d\n0x0040C590:\t+\tS_DrawScreenSprite\n0x0040C630:\t+\tdraw_scaled_spriteC\n\n// ======================================\n// GAME\n// ======================================\n\n\tgame/bird.cpp\n0x0040C860:\t *\tInitialiseEagle\n0x0040C8F0:\t *\tEagleControl\n\n\tgame/boat.cpp\n0x0040CB10:\t\tInitialiseBoat\n0x0040CB50:\t\tBoatCheckGeton\n0x0040CCC0:\t\tBoatCollision\n0x0040CE20:\t\tTestWaterHeight\n0x0040CF20:\t\tDoBoatShift\n0x0040D0F0:\t+\tDoWakeEffect\n0x0040D270:\t\tDoBoatDynamics\n0x0040D2C0:\t\tBoatDynamics\n0x0040D7A0:\t\tBoatUserControl\n0x0040D930:\t\tBoatAnimation\n0x0040DAA0:\t\tBoatControl\n0x0040E0D0:\t+\tGondolaControl\n\n\tgame/box.cpp\n0x0040E190:\t *\tInitialiseCreature\n0x0040E1C0:\t\tCreatureActive\n0x0040E210:\t *\tCreatureAIInfo\n0x0040E470:\t\tSearchLOT\n0x0040E670:\t\tUpdateLOT\n0x0040E6E0:\t\tTargetBox\n0x0040E780:\t\tStalkBox\n0x0040E880:\t\tEscapeBox\n0x0040E930:\t\tValidBox\n0x0040E9E0:\t *\tCreatureMood\n0x0040EE50:\t\tCalculateTarget\n0x0040F2B0:\t\tCreatureCreature\n0x0040F3B0:\t\tBadFloor\n0x0040F440:\t+\tCreatureDie\n0x0040F500:\t *\tCreatureAnimation\n0x0040FDD0:\t *\tCreatureTurn\n0x0040FEB0:\t *\tCreatureTilt\n0x0040FEF0:\t *\tCreatureHead\n0x0040FF40:\t\tCreatureNeck\n0x0040FF90:\t\tCreatureFloat\n0x00410040:\t\tCreatureUnderwater\n0x00410090:\t *\tCreatureEffect\n0x004100F0:\t\tCreatureVault\n0x00410230:\t+\tCreatureKill\n0x004103A0:\t\tGetBaddieTarget\n\n\tgame/camera.cpp\n0x00410580:\t+\tInitialiseCamera\n0x00410630:\t+\tMoveCamera\n0x004109B0:\t *\tClipCamera\n0x00410A90:\t *\tShiftCamera\n0x00410BF0:\t *\tGoodPosition\n0x00410C40:\t *\tSmartShift\n0x004113D0:\t *\tChaseCamera\n0x004114C0:\t *\tShiftClamp\n0x00411660:\t *\tCombatCamera\n0x004117F0:\t+\tLookCamera\n0x004119E0:\t+\tFixedCamera\n0x00411A80:\t+\tCalculateCamera\n\n\tgame/cinema.cpp\n0x00411F30:\t+\tSetCutsceneTrack\n0x00411F40:\t+\tStartCinematic\n0x00412060:\t+\tInitCinematicRooms\n0x00412100:\t+\tDoCinematic\n0x00412270:\t *\tCalculateCinematicCamera\n0x004123B0:\t *\tGetCinematicRoom\n0x00412430:\t *\tControlCinematicPlayer\n0x00412510:\t *\tLaraControlCinematic\n0x004125B0:\t *\tInitialisePlayer1\n0x00412640:\t *\tInitialiseGenPlayer\n0x00412680:\t *\tInGameCinematicCamera\n\n\tgame/collide.cpp\n0x004128D0:\t\tGetCollisionInfo\n0x00412F90:\t\tFindGridShift\n0x00412FC0:\t+\tCollideStaticObjects\n0x004133B0:\t+\tGetNearByRooms\n0x00413480:\t+\tGetNewRoom\n0x004134E0:\t\tShiftItem\n0x00413520:\t *\tUpdateLaraRoom\n0x00413580:\t\tGetTiltType\n0x00413620:\t\tLaraBaddieCollision\n0x004137C0:\t\tEffectSpaz\n0x00413840:\t *\tCreatureCollision\n0x004138C0:\t *\tObjectCollision\n0x00413920:\t\tDoorCollision\n0x004139A0:\t\tTrapCollision\n0x00413A10:\t\tItemPushLara\n0x00413D20:\t\tTestBoundsCollide\n0x00413DF0:\t\tTestLaraPosition\n0x00413F30:\t\tAlignLaraPosition\n0x00414070:\t\tMoveLaraPosition\n0x00414200:\t\tMove3DPosTo3DPos\n\n\tgame/control.cpp\n0x00414370:\t+\tControlPhase\n0x004146C0:\t *\tAnimateItem\n0x00414A30:\t\tGetChange\n0x00414AE0:\t\tTranslateItem\n0x00414B40:\t *\tGetFloor\n0x00414CE0:\t *\tGetWaterHeight\n0x00414E50:\t *\tGetHeight\n0x004150D0:\t\tRefreshCamera\n0x004151C0:\t *\tTestTriggers\n0x004158A0:\t *\tTriggerActive\n0x00415900:\t *\tGetCeiling\n0x00415B60:\t\tGetDoor\n0x00415BB0:\t *\tLOS\n0x00415C50:\t\tzLOS\n0x00415F40:\t\txLOS\n0x00416230:\t\tClipTarget\n0x00416310:\t\tObjectOnLOS\n0x00416610:\t *\tFlipMap\n0x004166D0:\t\tRemoveRoomFlipItems\n0x00416770:\t\tAddRoomFlipItems\n0x004167D0:\t+\tTriggerCDTrack\n0x00416800:\t+\tTriggerNormalCDTrack\n\n\tgame/demo.cpp\n0x004168E0:\t *\tDoDemoSequence\n0x00416940:\t+\tStartDemo\n0x00416AF0:\t *\tLoadLaraDemoPos\n0x00416BC0:\t *\tGetDemoInput\n\n\tgame/diver.cpp\n0x00416BF0:\t\tHarpoon\n0x00416C70:\t\tGetWaterSurface\n0x00416D80:\t *\tDiverControl\n\n\tgame/dog.cpp\n0x00417130:\t *\tDogControl\n0x004174E0:\t *\tTigerControl\n\n\tgame/dragon.cpp\n0x00417780:\t\tControlTwinkle\n0x00417900:\t\tCreateBartoliLight\n0x004179E0:\t\tDragonFire\n0x00417A90:\t *\tDragonCollision\n0x00417D80:\t *\tDragonBones\n0x00417E60:\t *\tDragonControl\n0x004183B0:\t *\tInitialiseBartoli\n0x004184D0:\t *\tBartoliControl\n0x00418670:\t *\tDinoControl\n\n\tgame/draw.cpp\n0x00418920:\t *\tDrawPhaseCinematic\n0x00418960:\t *\tDrawPhaseGame\n0x004189A0:\t+\tDrawRooms\n0x00418C50:\t+\tGetRoomBounds\n0x00418E20:\t+\tSetRoomBounds\n0x004191A0:\t+\tClipRoom\n0x00419580:\t+\tPrintRooms\n0x00419640:\t+\tPrintObjects\n0x00419870:\t+\tDrawEffect\n0x004199C0:\t+\tDrawSpriteItem\n----------:\t+\tDrawDummyItem\n0x00419A50:\t+\tDrawAnimatingItem\n0x00419DD0:\t *\tDrawLara\n0x0041AB00:\t+\tDrawLaraInt\n0x0041B6F0:\t *\tInitInterpolate\n0x0041B730:\t *\tphd_PopMatrix_I\n0x0041B760:\t *\tphd_PushMatrix_I\n0x0041B790:\t *\tphd_RotY_I\n0x0041B7D0:\t *\tphd_RotX_I\n0x0041B810:\t *\tphd_RotZ_I\n0x0041B850:\t *\tphd_TranslateRel_I\n0x0041B8A0:\t *\tphd_TranslateRel_ID\n0x0041B8F0:\t *\tphd_RotYXZ_I\n0x0041B940:\t *\tphd_RotYXZsuperpack_I\n0x0041B980:\t+\tphd_RotYXZsuperpack\n0x0041BA30:\t+\tphd_PutPolygons_I\n0x0041BA60:\t *\tInterpolateMatrix\n0x0041BC10:\t *\tInterpolateArmMatrix\n0x0041BD10:\t+\tDrawGunFlash\n0x0041BE80:\t *\tCalculateObjectLighting\n0x0041BF70:\t *\tGetFrames\n0x0041C010:\t *\tGetBoundsAccurate\n0x0041C090:\t *\tGetBestFrame\n0x0041C0D0:\t+\tAddDynamicLight\n\n\tgame/eel.cpp\n0x0041C120:\t *\tBigEelControl\n0x0041C2C0:\t *\tEelControl\n\n\tgame/effects.cpp\n0x0041C4B0:\t+\tItemNearLara\n0x0041C540:\t+\tSoundEffects\n0x0041C5B0:\t+\tDoBloodSplat\n0x0041C610:\t+\tDoLotsOfBlood\n0x0041C6C0:\t+\tControlBlood1\n0x0041C750:\t+\tControlExplosion1\n0x0041C7D0:\t+\tRichochet\n0x0041C850:\t+\tControlRichochet1\n0x0041C880:\t+\tCreateBubble\n0x0041C8F0:\t+\tLaraBubbles\n0x0041C970:\t+\tControlBubble1\n0x0041CA70:\t+\tSplash\n----------:\t+\tWadeSplash\n0x0041CB40:\t+\tControlSplash1\n0x0041CBC0:\t+\tControlWaterSprite\n0x0041CC70:\t+\tControlSnowSprite\n0x0041CD00:\t+\tControlHotLiquid\n0x0041CDE0:\t+\tWaterFall\n0x0041CF20:\t+\tfinish_level_effect\n0x0041CF30:\t+\tturn180_effect\n0x0041CF50:\t+\tfloor_shake_effect\n0x0041CFF0:\t+\tlara_normal_effect\n0x0041D030:\t+\tBoilerFX\n0x0041D050:\t+\tFloodFX\n0x0041D0E0:\t+\tRubbleFX\n0x0041D110:\t+\tChandelierFX\n0x0041D140:\t+\tExplosionFX\n0x0041D170:\t+\tPistonFX\n0x0041D190:\t+\tCurtainFX\n0x0041D1B0:\t+\tStatueFX\n0x0041D1D0:\t+\tSetChangeFX\n0x0041D1F0:\t+\tControlDingDong\n0x0041D230:\t+\tControlLaraAlarm\n0x0041D270:\t+\tControlAlarmSound\n0x0041D2E0:\t+\tControlBirdTweeter\n0x0041D340:\t+\tDoChimeSound\n0x0041D3A0:\t+\tControlClockChimes\n0x0041D410:\t+\tSphereOfDoomCollision\n0x0041D540:\t+\tSphereOfDoom\n0x0041D630:\t+\tDrawSphereOfDoom\n0x0041D760:\t+\tlara_hands_free\n0x0041D770:\t+\tflip_map_effect\n0x0041D780:\t+\tdraw_right_gun\n0x0041D7D0:\t+\tdraw_left_gun\n----------:\t\tshoot_right_gun\n----------:\t\tshoot_left_gun\n0x0041D820:\t+\tswap_meshes_with_meshswap1\n0x0041D890:\t+\tswap_meshes_with_meshswap2\n0x0041D900:\t+\tswap_meshes_with_meshswap3\n0x0041D9A0:\t+\tinvisibility_on\n0x0041D9B0:\t+\tinvisibility_off\n0x0041D9D0:\t+\tdynamic_light_on\n0x0041D9E0:\t+\tdynamic_light_off\n0x0041D9F0:\t+\treset_hair\n0x0041DA00:\t+\tAssaultStart\n0x0041DA30:\t+\tAssaultStop\n0x0041DA50:\t+\tAssaultReset\n0x0041DA70:\t+\tAssaultFinished\n\n\tgame/enemies.cpp\n0x0041DB30:\t\tKnife\n0x0041DBB0:\t *\tCult2Control\n0x0041DFE0:\t *\tMonkControl\n0x0041E4B0:\t *\tWorker3Control\n0x0041EAC0:\t *\tDrawXianLord\n0x0041EEC0:\t\tXianDamage\n0x0041EF70:\t *\tInitialiseXianLord\n0x0041EFD0:\t *\tXianLordControl\n0x0041F5B0:\t\tWarriorSparkleTrail\n0x0041F650:\t *\tWarriorControl\n\n\tgame/gameflow.cpp\n0x0041FA40:\t+\tGF_LoadScriptFile\n0x0041FC30:\t+\tGF_DoFrontEndSequence\n0x0041FC50:\t+\tGF_DoLevelSequence\n0x0041FCC0:\t+\tGF_InterpretSequence\n0x004201A0:\t+\tGF_ModifyInventory\n\n\tgame/hair.cpp\n0x00420E80:\t *\tInitialiseHair\n0x00420F00:\t *\tHairControl\n0x00421900:\t *\tDrawHair\n\n\tgame/health.cpp\n0x00421980:\t+\tFlashIt\n0x004219B0:\t+\tDrawAssaultTimer\n0x00421B00:\t+\tDrawGameInfo\n0x00421B50:\t+\tDrawHealthBar\n0x00421C00:\t+\tDrawAirBar\n0x00421CA0:\t+\tMakeAmmoString\n0x00421CD0:\t+\tDrawAmmoInfo\n0x00421E20:\t+\tInitialisePickUpDisplay\n0x00421E40:\t+\tDrawPickups\n0x00421F40:\t+\tAddDisplayPickup\n0x00421FB0:\t+\tDisplayModeInfo\n0x00422030:\t+\tDrawModeInfo\n\n\tgame/inventory.cpp\n0x00422060:\t+\tDisplay_Inventory\n0x004232F0:\t+\tConstruct_Inventory\n0x00423450:\t+\tSelectMeshes\n0x004234E0:\t+\tAnimateInventoryItem\n0x00423570:\t+\tDrawInventoryItem\n0x004239A0:\t+\tGetDebouncedInput\n0x004239C0:\t+\tDoInventoryPicture\n0x004239D0:\t+\tDoInventoryBackground\n\n\tgame/invfunc.cpp\n0x00423B10:\t+\tInitColours\n0x00423C20:\t+\tRingIsOpen\n0x00423D90:\t+\tRingIsNotOpen\n0x00423E20:\t+\tRingNotActive\n0x00424290:\t+\tRingActive\n0x004242D0:\t+\tInv_AddItem\n0x00424AE0:\t+\tInv_InsertItem\n0x00424C10:\t+\tInv_RequestItem\n0x00424C90:\t+\tInv_RemoveAllItems\n0x00424CB0:\t+\tInv_RemoveItem\n0x00424DC0:\t+\tInv_GetItemOption\n0x00424FB0:\t+\tRemoveInventoryText\n0x00424FE0:\t+\tInv_RingInit\n0x004250F0:\t+\tInv_RingGetView\n0x00425150:\t+\tInv_RingLight\n0x00425190:\t+\tInv_RingCalcAdders\n0x004251C0:\t+\tInv_RingDoMotions\n0x00425300:\t+\tInv_RingRotateLeft\n0x00425330:\t+\tInv_RingRotateRight\n0x00425360:\t+\tInv_RingMotionInit\n0x004253D0:\t+\tInv_RingMotionSetup\n0x00425400:\t+\tInv_RingMotionRadius\n0x00425430:\t+\tInv_RingMotionRotation\n0x00425460:\t+\tInv_RingMotionCameraPos\n0x00425490:\t+\tInv_RingMotionCameraPitch\n0x004254B0:\t+\tInv_RingMotionItemSelect\n0x00425510:\t+\tInv_RingMotionItemDeselect\n\n\tgame/invtext.cpp\n0x00425580:\t+\tInit_Requester\n0x00425610:\t+\tRemove_Requester\n0x004256C0:\t+\tReqItemCentreAlign\n0x004256E0:\t+\tReqItemLeftAlign\n0x00425740:\t+\tReqItemRightAlign\n0x004257A0:\t+\tDisplay_Requester\n0x00426010:\t+\tSetRequesterHeading\n0x004260C0:\t+\tRemoveAllReqItems\n0x004260E0:\t+\tChangeRequesterItem\n0x004261A0:\t+\tAddRequesterItem\n0x00426250:\t+\tSetPCRequesterSize\n0x00426290:\t+\tAddAssaultTime\n0x00426320:\t+\tShowGymStatsText\n0x00426500:\t+\tShowStatsText\n0x004268A0:\t+\tShowEndStatsText\n\n\tgame/items.cpp\n0x00426CD0:\t+\tInitialiseItemArray\n0x00426D30:\t *\tKillItem\n0x00426E50:\t *\tCreateItem\n0x00426E90:\t+\tInitialiseItem\n0x00427050:\t *\tRemoveActiveItem\n0x004270E0:\t *\tRemoveDrawnItem\n0x00427150:\t+\tAddActiveItem\n0x004271B0:\t *\tItemNewRoom\n0x00427250:\t+\tGlobalItemReplace\n0x004272D0:\t *\tInitialiseFXArray\n0x00427300:\t *\tCreateEffect\n0x00427370:\t *\tKillEffect\n0x00427460:\t *\tEffectNewRoom\n0x00427500:\t *\tClearBodyBag\n\n\tgame/lara.cpp\n0x00427560:\t *\tLaraAboveWater\n0x00427700:\t\tLookUpDown\n0x00427770:\t\tLookLeftRight\n0x004277F0:\t\tResetLook\n0x00427880:\t\tlara_as_walk\n0x00427910:\t\tlara_as_run\n0x00427A60:\t\tlara_as_stop\n0x00427BB0:\t\tlara_as_forwardjump\n----------:\t\tlara_as_pose\n0x00427C90:\t\tlara_as_fastback\n0x00427CF0:\t\tlara_as_turn_r\n0x00427D80:\t\tlara_as_turn_l\n0x00427E10:\t\tlara_as_death\n0x00427E30:\t\tlara_as_fastfall\n0x00427E70:\t\tlara_as_hang\n0x00427ED0:\t\tlara_as_reach\n0x00427EF0:\t\tlara_as_splat\n----------:\t\tlara_as_land\n0x00427F00:\t\tlara_as_compress\n0x00428010:\t\tlara_as_back\n0x004280A0:\t\tlara_as_null\n0x004280B0:\t\tlara_as_fastturn\n0x00428100:\t\tlara_as_stepright\n0x00428180:\t\tlara_as_stepleft\n0x00428200:\t\tlara_as_slide\n0x00428230:\t\tlara_as_backjump\n0x00428280:\t\tlara_as_rightjump\n0x004282C0:\t\tlara_as_leftjump\n0x00428300:\t\tlara_as_upjump\n0x00428320:\t\tlara_as_fallback\n0x00428350:\t\tlara_as_hangleft\n0x00428390:\t\tlara_as_hangright\n0x004283D0:\t\tlara_as_slideback\n0x004283F0:\t\tlara_as_pushblock\n----------:\t\tlara_as_pullblock\n0x00428420:\t\tlara_as_ppready\n0x00428450:\t\tlara_as_pickup\n0x00428480:\t\tlara_as_pickupflare\n0x004284E0:\t\tlara_as_switchon\n----------:\t\tlara_as_switchoff\n0x00428520:\t\tlara_as_usekey\n----------:\t\tlara_as_usepuzzle\n----------:\t\tlara_as_roll\n----------:\t\tlara_as_roll2\n0x00428550:\t\tlara_as_special\n----------:\t\tlara_as_usemidas\n----------:\t\tlara_as_diemidas\n0x00428570:\t\tlara_as_swandive\n0x004285A0:\t\tlara_as_fastdive\n----------:\t\tlara_as_gymnast\n0x00428600:\t\tlara_as_waterout\n----------:\t\tlara_as_laratest1\n----------:\t\tlara_as_laratest2\n----------:\t\tlara_as_laratest3\n0x00428620:\t\tlara_as_wade\n----------:\t\tlara_as_twist\n----------:\t\tlara_as_kick\n0x004286F0:\t\tlara_as_deathslide\n0x00428790:\t\textra_as_breath\n----------:\t\textra_as_plunger\n0x004287E0:\t\textra_as_yetikill\n0x00428830:\t\textra_as_sharkkill\n0x004288D0:\t\textra_as_airlock\n0x004288F0:\t\textra_as_gongbong\n0x00428910:\t\textra_as_dinokill\n0x00428970:\t\textra_as_pulldagger\n0x00428A30:\t\textra_as_startanim\n0x00428A80:\t\textra_as_starthouse\n0x00428B30:\t\textra_as_finalanim\n0x00428BE0:\t\tLaraFallen\n0x00428C40:\t\tLaraCollideStop\n0x00428D00:\t\tlara_col_walk\n0x00428EA0:\t\tlara_col_run\n0x00429020:\t\tlara_col_stop\n0x004290B0:\t\tlara_col_forwardjump\n----------:\t\tlara_col_pose\n0x00429190:\t\tlara_col_fastback\n0x00429250:\t\tlara_col_turn_r\n0x004292F0:\t\tlara_col_turn_l\n0x00429310:\t\tlara_col_death\n0x00429380:\t\tlara_col_fastfall\n0x00429420:\t\tlara_col_hang\n0x00429550:\t\tlara_col_reach\n0x004295E0:\t\tlara_col_splat\n----------:\t\tlara_col_land\n0x00429640:\t\tlara_col_compress\n0x004296E0:\t\tlara_col_back\n----------:\t\tlara_col_null\n0x004297E0:\t\tlara_col_fastturn\n0x00429800:\t\tlara_col_stepright\n0x004298C0:\t\tlara_col_stepleft\n0x004298E0:\t\tlara_col_slide\n0x00429900:\t\tlara_col_backjump\n0x00429930:\t\tlara_col_rightjump\n0x00429960:\t\tlara_col_leftjump\n0x00429990:\t\tlara_col_upjump\n0x00429AD0:\t\tlara_col_fallback\n0x00429B60:\t\tlara_col_hangleft\n0x00429BA0:\t\tlara_col_hangright\n0x00429BE0:\t\tlara_col_slideback\n----------:\t\tlara_col_pushblock\n----------:\t\tlara_col_pullblock\n----------:\t\tlara_col_ppready\n----------:\t\tlara_col_pickup\n----------:\t\tlara_col_switchon\n----------:\t\tlara_col_switchoff\n----------:\t\tlara_col_usekey\n----------:\t\tlara_col_usepuzzle\n0x00429C10:\t\tlara_col_roll\n0x00429CB0:\t\tlara_col_roll2\n0x00429D80:\t\tlara_col_special\n----------:\t\tlara_col_usemidas\n----------:\t\tlara_col_diemidas\n0x00429DA0:\t\tlara_col_swandive\n0x00429E10:\t\tlara_col_fastdive\n----------:\t\tlara_col_gymnast\n----------:\t\tlara_col_waterout\n----------:\t\tlara_col_laratest1\n----------:\t\tlara_col_laratest2\n----------:\t\tlara_col_laratest3\n0x00429E90:\t\tlara_col_wade\n----------:\t\tlara_col_twist\n0x0042A000:\t\tlara_default_col\n0x0042A040:\t+\tlara_col_jumper\n0x0042A120:\t\tlara_col_kick\n----------:\t\tlara_col_deathslide\n0x0042A130:\t *\tGetLaraCollisionInfo\n0x0042A170:\t\tlara_slide_slope\n0x0042A260:\t\tLaraHitCeiling\n0x0042A2D0:\t\tLaraDeflectEdge\n0x0042A350:\t *\tLaraDeflectEdgeJump\n0x0042A4D0:\t\tLaraSlideEdgeJump\n0x0042A5C0:\t\tTestWall\n0x0042A6D0:\t\tLaraTestHangOnClimbWall\n0x0042A7E0:\t\tLaraTestClimbStance\n0x0042A8A0:\t\tLaraHangTest\n0x0042AC00:\t\tLaraTestEdgeCatch\n0x0042ACB0:\t\tLaraTestHangJumpUp\n0x0042AE20:\t\tLaraTestHangJump\n0x0042AFC0:\t\tTestHangSwingIn\n0x0042B080:\t\tTestLaraVault\n0x0042B370:\t\tTestLaraSlide\n0x0042B4A0:\t\tLaraFloorFront\n0x0042B520:\t *\tLaraLandedBad\n0x0042B5E0:\t *\tGetLaraJointAbsPosition\n0x0042B970:\t\tGetLJAInt\n\n\tgame/lara1gun.cpp\n0x0042BC90:\t\tdraw_shotgun_meshes\n0x0042BCD0:\t\tundraw_shotgun_meshes\n0x0042BD00:\t\tready_shotgun\n0x0042BD70:\t+\tRifleHandler\n0x0042BE70:\t+\tFireShotgun\n0x0042BF70:\t+\tFireM16\n0x0042BFF0:\t+\tFireHarpoon\n0x0042C180:\t\tControlHarpoonBolt\n0x0042C4D0:\t+\tFireRocket\n0x0042C5C0:\t+\tControlRocket\n0x0042C9D0:\t\tdraw_shotgun\n0x0042CB40:\t\tundraw_shotgun\n0x0042CC50:\t *\tAnimateShotgun\n\n\tgame/lara2gun.cpp\n0x0042D000:\t\tset_pistol_arm\n0x0042D050:\t\tdraw_pistols\n0x0042D0D0:\t\tundraw_pistols\n0x0042D300:\t\tready_pistols\n0x0042D360:\t\tdraw_pistol_meshes\n0x0042D3B0:\t\tundraw_pistol_mesh_left\n0x0042D3F0:\t\tundraw_pistol_mesh_right\n0x0042D430:\t+\tPistolHandler\n0x0042D5C0:\t *\tAnimatePistols\n\n\tgame/laraclimb.cpp\n0x0042D8F0:\t\tlara_as_climbleft\n0x0042D930:\t\tlara_as_climbright\n0x0042D970:\t\tlara_as_climbstnc\n0x0042D9F0:\t\tlara_as_climbing\n0x0042DA10:\t\tlara_as_climbend\n0x0042DA30:\t\tlara_as_climbdown\n0x0042DA50:\t\tlara_col_climbleft\n0x0042DAB0:\t\tlara_col_climbright\n0x0042DB10:\t\tlara_col_climbstnc\n0x0042DD20:\t\tlara_col_climbing\n----------:\t\tlara_col_climbend\n0x0042DE70:\t\tlara_col_climbdown\n0x0042E010:\t\tLaraCheckForLetGo\n0x0042E0C0:\t\tLaraTestClimb\n0x0042E330:\t\tLaraTestClimbPos\n0x0042E400:\t\tLaraDoClimbLeftRight\n0x0042E4F0:\t\tLaraTestClimbUpPos\n\n\tgame/larafire.cpp\n0x0042E740:\t *\tLaraGun\n0x0042ECB0:\t *\tCheckForHoldingState\n0x0042ECF0:\t *\tInitialiseNewWeapon\n0x0042EE30:\t *\tLaraTargetInfo\n0x0042EFD0:\t *\tLaraGetNewTarget\n0x0042F1F0:\t *\tfind_target_point\n0x0042F2A0:\t *\tAimWeapon\n0x0042F370:\t *\tFireWeapon\n0x0042F6E0:\t *\tHitTarget\n0x0042F780:\t *\tSmashItem\n0x0042F7E0:\t *\tWeaponObject\n\n\tgame/laraflare.cpp\n0x0042F840:\t\tDoFlareLight\n0x0042F8E0:\t\tDoFlareInHand\n0x0042F9C0:\t+\tDrawFlareInAir\n0x0042FAC0:\t\tCreateFlare\n0x0042FCA0:\t\tset_flare_arm\n0x0042FCF0:\t\tdraw_flare\n0x0042FE60:\t\tundraw_flare\n0x00430090:\t\tdraw_flare_meshes\n0x004300B0:\t\tundraw_flare_meshes\n0x004300D0:\t\tready_flare\n0x00430110:\t\tFlareControl\n\n\tgame/laramisc.cpp\n0x00430380:\t+\tLaraControl\n0x00430A10:\t *\tAnimateLara\n0x00430D10:\t+\tUseItem\n0x00430ED0:\t+\tLaraCheatGetStuff\n0x00430F90:\t+\tControlLaraExtra\n0x00430FB0:\t+\tInitialiseLaraLoad\n0x00430FE0:\t *\tInitialiseLara\n0x004312A0:\t+\tInitialiseLaraInventory\n0x00431610:\t *\tLaraInitialiseMeshes\n\n\tgame/larasurf.cpp\n0x00431710:\t *\tLaraSurface\n0x00431870:\t\tlara_as_surfswim\n0x004318E0:\t\tlara_as_surfback\n0x00431940:\t\tlara_as_surfleft\n0x004319A0:\t\tlara_as_surfright\n0x00431A00:\t\tlara_as_surftread\n0x00431AC0:\t\tlara_col_surfswim\n0x00431B00:\t\tlara_col_surfback\n0x00431B30:\t\tlara_col_surfleft\n0x00431B60:\t\tlara_col_surfright\n0x00431B90:\t\tlara_col_surftread\n0x00431BF0:\t\tLaraSurfaceCollision\n0x00431CF0:\t\tLaraTestWaterStepOut\n0x00431DE0:\t\tLaraTestWaterClimbOut\n\n\tgame/laraswim.cpp\n0x00432000:\t *\tLaraUnderWater\n0x00432230:\t+\tSwimTurn\n0x004322C0:\t+\tlara_as_swim\n0x00432330:\t\tlara_as_glide\n0x004323B0:\t\tlara_as_tread\n0x00432440:\t\tlara_as_dive\n0x00432460:\t\tlara_as_uwdeath\n0x004324C0:\t\tlara_as_waterroll\n0x004324D0:\t\tlara_col_swim\n----------:\t\tlara_col_glide\n----------:\t\tlara_col_tread\n----------:\t\tlara_col_dive\n0x004324F0:\t\tlara_col_uwdeath\n----------:\t\tlara_col_waterroll\n0x00432550:\t *\tGetWaterDepth\n0x004326F0:\t\tLaraTestWaterDepth\n0x004327C0:\t\tLaraSwimCollision\n0x00432920:\t\tLaraWaterCurrent\n\n\tgame/lot.cpp\n0x00432B10:\t\tInitialiseLOTarray\n0x00432B70:\t *\tDisableBaddieAI\n0x00432BC0:\t *\tEnableBaddieAI\n0x00432D70:\t\tInitialiseSlot\n0x00432F80:\t\tCreateZone\n0x00433040:\t\tClearLOT\n\n\tgame/missile.cpp\n0x00433090:\t+\tControlMissile\n0x00433360:\t\tShootAtLara\n0x00433410:\t *\tExplodingDeath\n0x004337A0:\t\tControlBodyPart\n\n\tgame/moveblock.cpp\n0x004339A0:\t\tInitialiseMovingBlock\n0x004339D0:\t *\tMovableBlock\n0x00433B20:\t\tMovableBlockCollision\n0x00433D80:\t\tTestBlockMovable\n0x00433DD0:\t\tTestBlockPush\n0x00433F20:\t\tTestBlockPull\n0x00434160:\t *\tAlterFloorHeight\n0x00434220:\t\tDrawMovableBlock\n0x00434250:\t *\tDrawUnclippedItem\n\n\tgame/objects.cpp\n0x004342C0:\t\tEarthQuake\n0x004343A0:\t\tControlCutShotgun\n0x004343E0:\t\tInitialiseFinalLevel\n0x004344B0:\t\tFinalLevelCounter\n0x004346C0:\t\tMiniCopterControl\n0x004347A0:\t\tInitialiseDyingMonk\n0x00434820:\t\tDyingMonk\n0x004348B0:\t\tControlGongBonger\n0x00434970:\t\tDeathSlideCollision\n0x00434A30:\t\tControlDeathSlide\n0x00434CC0:\t\tBigBowlControl\n0x00434DB0:\t\tBellControl\n0x00434E30:\t\tInitialiseWindow\n0x00434EB0:\t *\tSmashWindow\n0x00434F80:\t\tWindowControl\n0x00435020:\t\tSmashIceControl\n0x00435100:\t\tShutThatDoor\n0x00435150:\t\tOpenThatDoor\n0x00435190:\t\tInitialiseDoor\n0x00435570:\t\tDoorControl\n0x00435640:\t\tOnDrawBridge\n0x00435700:\t\tDrawBridgeFloor\n0x00435740:\t\tDrawBridgeCeiling\n0x00435780:\t\tDrawBridgeCollision\n0x004357B0:\t\tInitialiseLift\n0x004357F0:\t\tLiftControl\n0x004358D0:\t\tLiftFloorCeiling\n0x00435A50:\t\tLiftFloor\n0x00435A90:\t\tLiftCeiling\n0x00435AD0:\t\tBridgeFlatFloor\n0x00435AF0:\t\tBridgeFlatCeiling\n0x00435B10:\t\tGetOffset\n0x00435B50:\t\tBridgeTilt1Floor\n0x00435B80:\t\tBridgeTilt1Ceiling\n0x00435BC0:\t\tBridgeTilt2Floor\n0x00435BF0:\t\tBridgeTilt2Ceiling\n0x00435C30:\t\tCopterControl\n0x00435D40:\t\tGeneralControl\n0x00435E20:\t\tDetonatorControl\n\n\tgame/people.cpp\n0x00435EB0:\t\tTargetable\n0x00435F40:\t\tControlGlow\n0x00435F80:\t\tControlGunShot\n0x00435FD0:\t+\tGunShot\n0x00436040:\t+\tGunHit\n0x00436100:\t\tGunMiss\n0x004361B0:\t\tShotLara\n0x00436380:\t *\tInitialiseCult1\n0x004363D0:\t *\tCult1Control\n0x00436800:\t *\tInitialiseCult3\n0x00436850:\t *\tCult3Control\n0x00436DC0:\t *\tWorker1Control\n0x004371C0:\t *\tWorker2Control\n0x00437620:\t *\tBanditControl\n0x00437960:\t *\tBandit2Control\n0x00437DA0:\t *\tWinstonControl\n\n\tgame/pickup.cpp\n0x00437F20:\t *\tPickUpCollision\n0x004383A0:\t\tSwitchCollision\n0x004385B0:\t\tSwitchCollision2\n0x004386B0:\t\tDetonatorCollision\n0x004388F0:\t\tKeyHoleCollision\n0x00438B30:\t *\tPuzzleHoleCollision\n0x00438DF0:\t\tSwitchControl\n0x00438E30:\t\tSwitchTrigger\n0x00438EF0:\t\tKeyTrigger\n0x00438F30:\t\tPickupTrigger\n0x00438F70:\t\tSecretControl\n\n\tgame/rat.cpp\n0x00438FA0:\t *\tMouseControl\n\n\tgame/savegame.cpp\n0x00439190:\t+\tInitialiseStartInfo\n0x00439200:\t+\tModifyStartInfo\n0x004392E0:\t+\tCreateStartInfo\n0x004394F0:\t+\tCreateSaveGameInfo\n0x00439A20:\t+\tExtractSaveGameInfo\n0x0043A280:\t+\tResetSG\n0x0043A2A0:\t+\tWriteSG\n0x0043A2F0:\t+\tReadSG\n\n\tgame/setup.cpp\n0x0043A330:\t *\tInitialiseLevel\n0x0043A490:\t\tInitialiseGameFlags\n0x0043A500:\t+\tInitialiseLevelFlags\n0x0043A530:\t+\tBaddyObjects\n0x0043B570:\t *\tTrapObjects\n0x0043BB70:\t *\tObjectObjects\n0x0043C7C0:\t+\tInitialiseObjects\n0x0043C830:\t\tGetCarriedItems\n\n\tgame/shark.cpp\n0x0043C900:\t *\tJellyControl\n0x0043CA20:\t *\tBaracuddaControl\n0x0043CC50:\t *\tSharkControl\n\n\tgame/skidoo.cpp\n0x0043CEE0:\t *\tInitialiseSkidoo\n0x0043CF20:\t\tSkidooCheckGeton\n0x0043D010:\t\tSkidooCollision\n0x0043D110:\t\tSkidooBaddieCollision\n0x0043D310:\t\tTestHeight\n0x0043D3D0:\t\tDoShift\n0x0043D650:\t\tDoDynamics\n0x0043D6B0:\t\tGetCollisionAnim\n0x0043D740:\t+\tDoSnowEffect\n0x0043D880:\t\tSkidooDynamics\n0x0043DD20:\t\tSkidooUserControl\n0x0043DEE0:\t\tSkidooCheckGetOffOK\n0x0043DFF0:\t\tSkidooAnimation\n0x0043E2D0:\t+\tSkidooExplode\n0x0043E350:\t\tSkidooCheckGetOff\n0x0043E590:\t+\tSkidooGuns\n0x0043E6B0:\t\tSkidooControl\n0x0043EB10:\t+\tDrawSkidoo\n0x0043EDF0:\t *\tInitialiseSkidman\n0x0043EE80:\t *\tSkidManControl\n0x0043F280:\t\tSkidmanPush\n0x0043F3A0:\t *\tSkidmanCollision\n\n\tgame/sound.cpp\n0x0043F430:\t+\tGetRealTrack\n0x0043F470:\t *\tPlaySoundEffect\n0x0043F910:\t *\tStopSoundEffect\n0x0043F970:\t *\tSOUND_EndScene\n0x0043FA00:\t *\tSOUND_Stop\n0x0043FA30:\t+\tSOUND_Init\n\n\tgame/sphere.cpp\n0x0043FA60:\t\tTestCollision\n0x0043FB90:\t\tGetSpheres\n0x0043FE70:\t *\tGetJointAbsPosition\n0x00440010:\t *\tBaddieBiteEffect\n\n\tgame/spider.cpp\n0x00440070:\t\tSpiderLeap\n0x00440120:\t *\tSpiderControl\n0x00440340:\t *\tBigSpiderControl\n\n\tgame/text.cpp\n0x00440500:\t+\tT_InitPrint\n0x00440530:\t+\tT_Print\n0x00440640:\t+\tT_ChangeText\n0x00440680:\t+\tT_SetScale\n0x004406A0:\t+\tT_FlashText\n0x004406D0:\t+\tT_AddBackground\n0x00440760:\t+\tT_RemoveBackground\n0x00440770:\t+\tT_AddOutline\n0x004407A0:\t+\tT_RemoveOutline\n0x004407B0:\t+\tT_CentreH\n0x004407D0:\t+\tT_CentreV\n0x004407F0:\t+\tT_RightAlign\n0x00440810:\t+\tT_BottomAlign\n0x00440830:\t+\tT_GetTextWidth\n0x00440940:\t+\tT_RemovePrint\n0x00440970:\t+\tT_GetStringLen\n0x004409A0:\t+\tT_DrawText\n0x004409D0:\t+\tT_DrawTextBox\n0x00440B60:\t+\tT_DrawThisText\n0x00440F40:\t+\tGetTextScaleH\n0x00440F80:\t+\tGetTextScaleV\n\n\tgame/traps.cpp\n0x00440FC0:\t+\tMineControl\n0x004411C0:\t+\tControlSpikeWall\n0x00441300:\t+\tControlCeilingSpikes\n0x00441420:\t+\tHookControl\n0x004414B0:\t\tPropellerControl\n0x00441640:\t+\tSpinningBlade\n0x004417C0:\t+\tIcicleControl\n0x004418C0:\t+\tInitialiseBlade\n0x00441900:\t+\tBladeControl\n0x004419A0:\t+\tInitialiseKillerStatue\n0x004419F0:\t+\tKillerStatueControl\n0x00441B00:\t\tSpringBoardControl\n0x00441BE0:\t\tInitialiseRollingBall\n0x00441C20:\t\tRollingBallControl\n0x00441F70:\t\tRollingBallCollision\n0x004421C0:\t\tSpikeCollision\n0x00442320:\t\tTrapDoorControl\n0x00442370:\t\tTrapDoorFloor\n0x004423B0:\t\tTrapDoorCeiling\n0x004423F0:\t\tOnTrapDoor\n0x004424A0:\t+\tPendulum\n0x004425B0:\t\tFallingBlock\n0x004426C0:\t\tFallingBlockFloor\n0x00442700:\t\tFallingBlockCeiling\n0x00442750:\t+\tTeethTrap\n0x00442810:\t+\tFallingCeiling\n0x004428F0:\t+\tDartEmitterControl\n0x00442A30:\t+\tDartsControl\n0x00442B90:\t+\tDartEffectControl\n0x00442BE0:\t+\tFlameEmitterControl\n0x00442C70:\t+\tFlameControl\n0x00442DE0:\t+\tLaraBurn\n0x00442E30:\t+\tLavaBurn\n0x00442F20:\t\tLavaSpray\n0x00442FF0:\t\tControlLavaBlob\n\n\tgame/yeti.cpp\n0x00443100:\t *\tGiantYetiControl\n0x00443400:\t *\tYetiControl\n\n// ======================================\n// SPECIFIC\n// ======================================\n\n\tspecific/background.cpp\n0x00443A40:\t+\tBGND_Make640x480\n0x00443C00:\t+\tBGND_AddTexture\n0x00443CC0:\t+\tBGND_GetPageHandles\n0x00443D00:\t+\tBGND_DrawInGameBlack\n0x00443D60:\t+\tDrawQuad\n0x00443E40:\t+\tBGND_DrawInGameBackground\n0x00444060:\t+\tDrawTextureTile\n0x004442C0:\t+\tBGND_CenterLighting\n0x00444570:\t+\tBGND_Free\n0x004445C0:\t+\tBGND_Init\n\n\tspecific/init_3d.cpp\n0x004445F0:\t+\tEnumerate3DDevices\n0x00444620:\t+\tD3DCreate\n0x00444640:\t+\tD3DRelease\n0x00444660:\t+\tEnum3DDevicesCallback\n0x00444720:\t+\tD3DIsSupported\n0x00444760:\t+\tD3DSetViewport\n0x00444820:\t+\tD3DDeviceCreate\n0x004449E0:\t+\tDirect3DRelease\n0x00444A30:\t+\tDirect3DInit\n0x00444A40:\t  x\tunused\n0x00444A50:\t  x\tunused\n0x00444A80:\t  x\tunused\n0x00444B50:\t  x\tunused\n0x00444B60:\t  x\tunused\n0x00444BC0:\t  x\tunused\n0x00444BD0:\t  x\tunused\n0x00444C60:\t  x\tunused\n0x00444C70:\t  x\tunused\n\n\tspecific/winvid.cpp\n0x00444C80:\t+\tDDrawCreate\n0x00444CE0:\t+\tDDrawRelease\n0x00444D20:\t+\tGameWindowCalculateSizeFromClient\n0x00444DA0:\t+\tGameWindowCalculateSizeFromClientByZero\n0x00444E10:\t+\tWinVidSetMinWindowSize\n0x00444E60:\t+\tWinVidClearMinWindowSize\n0x00444E70:\t+\tWinVidSetMaxWindowSize\n0x00444EC0:\t+\tWinVidClearMaxWindowSize\n0x00444ED0:\t+\tCalculateWindowWidth\n0x00444F20:\t+\tCalculateWindowHeight\n0x00444F50:\t+\tWinVidGetMinMaxInfo\n0x00445060:\t+\tWinVidFindGameWindow\n0x00445080:\t+\tWinVidSpinMessageLoop\n0x00445170:\t+\tWinVidShowGameWindow\n0x004451C0:\t+\tWinVidHideGameWindow\n0x00445200:\t+\tWinVidSetGameWindowSize\n0x00445240:\t+\tShowDDrawGameWindow\n0x004452F0:\t+\tHideDDrawGameWindow\n0x00445380:\t+\tDDrawSurfaceCreate\n0x004453D0:\t+\tDDrawSurfaceRestoreLost\n0x00445420:\t+\tWinVidClearBuffer\n0x00445470:\t+\tWinVidBufferLock\n0x004454B0:\t+\tWinVidBufferUnlock\n0x004454E0:\t+\tWinVidCopyBitmapToBuffer\n0x00445570:\t+\tGetRenderBitDepth\n0x00445600:\t+\tWinVidGetColorBitMasks\n0x00445680:\t+\tBitMaskGetNumberOfBits\n0x004456D0:\t+\tCalculateCompatibleColor\n0x00445740:\t+\tWinVidGetDisplayMode\n0x004457D0:\t+\tWinVidGoFullScreen\n0x00445860:\t+\tWinVidGoWindowed\n0x00445970:\t+\tWinVidSetDisplayAdapter\n0x00445A50:\t+\tCompareVideoModes\n0x00445AA0:\t+\tWinVidGetDisplayModes\n0x00445B00:\t+\tEnumDisplayModesCallback\n0x00445EC0:\t+\tWinVidInit\n0x00445F00:\t+\tWinVidGetDisplayAdapters\n0x00445FB0:\t+\tFlaggedStringDelete\n0x00445FD0:\t+\tEnumerateDisplayAdapters\n0x00445FF0:\t+\tEnumDisplayAdaptersCallback\n0x004461B0:\t+\tFlaggedStringsCreate\n0x004461F0:\t+\tWinVidRegisterGameWindowClass\n0x00446260:\t+\tWinVidGameWindowProc\n0x00446870:\t+\tWinVidResizeGameWindow\n0x00446A50:\t+\tWinVidCheckGameWindowPalette\n0x00446B10:\t+\tWinVidCreateGameWindow\n0x00446BE0:\t+\tWinVidFreeWindow\n0x00446C10:\t+\tWinVidExitMessage\n0x00446C60:\t+\tWinVidGetDisplayAdapter\n0x00446CB0:\t+\tWinVidStart\n0x00447030:\t+\tWinVidFinish\n0x00447050:\t+\tDisplayModeListInit\n0x00447060:\t+\tDisplayModeListDelete\n0x004470A0:\t+\tInsertDisplayMode\n0x004470C0:\t+\tInsertDisplayModeInListHead\n0x00447110:\t+\tInsertDisplayModeInListTail\n0x00447160:\t  x\tunused\n0x00447170:\t  x\tunused\n0x00447190:\t  x\tunused\n0x004471A0:\t  x\tunused\n0x00447210:\t  x\tunused\n0x00447220:\t  x\tunused\n0x00447260:\t  x\tunused\n0x00447270:\t  x\tunused\n\n\tspecific/init_input.cpp\n0x004472A0:\t+\tDInputCreate\n0x004472D0:\t+\tDInputRelease\n0x004472F0:\t+\tWinInReadKeyboard\n0x00447350:\t+\tWinInReadJoystick\n0x00447450:\t  x\tj_WinInputInit\n0x00447460:\t+\tWinInputInit\n0x004474E0:\t+\tDInputEnumDevices\n0x00447510:\t+\tDInputEnumDevicesCallback\n0x00447600:\t+\tFlaggedStringCreate\n0x00447620:\t+\tGetJoystick\n0x00447670:\t+\tDInputKeyboardCreate\n0x00447740:\t+\tDInputKeyboardRelease\n0x00447770:\t+\tDInputJoystickCreate\n----------:\t\tDInputJoystickRelease\n0x00447860:\t+\tWinInStart\n0x00447890:\t+\tWinInFinish\n0x004478A0:\t+\tWinInRunControlPanel\n\n\tspecific/display.cpp\n0x004478C0:\t+\tIncreaseScreenSize\n0x00447930:\t+\tDecreaseScreenSize\n0x004479A0:\t+\tsetup_screen_size\n0x00447A40:\t+\tTempVideoAdjust\n0x00447A80:\t+\tTempVideoRemove\n0x00447AC0:\t+\tS_FadeInInventory\n0x00447B00:\t+\tS_FadeOutInventory\n0x00447B30:\t  x\tunused\n0x00447B40:\t  x\tunused\n0x00447B60:\t  x\tunused\n0x00447B70:\t  x\tunused\n0x00447BE0:\t  x\tunused\n0x00447BF0:\t  x\tunused\n0x00447C30:\t  x\tunused\n0x00447C40:\t  x\tunused\n\n\tspecific/init_sound.cpp\n0x00447C70:\t+\tGetSoundAdapter\n0x00447CC0:\t+\tWinSndFreeAllSamples\n0x00447CF0:\t+\tWinSndMakeSample\n0x00447E00:\t+\tWinSndIsChannelPlaying\n0x00447E50:\t+\tWinSndPlaySample\n0x00447F40:\t+\tWinSndGetFreeChannelIndex\n0x00447F80:\t+\tWinSndAdjustVolumeAndPan\n0x00447FB0:\t+\tWinSndAdjustPitch\n0x00447FF0:\t+\tWinSndStopSample\n0x00448050:\t  x\tj_WinSndInit\n0x00448060:\t+\tWinSndInit\n0x00448100:\t+\tDSoundEnumerate\n0x00448120:\t+\tDSoundEnumCallback\n0x00448210:\t+\tWinSndStart\n0x00448390:\t+\tDSoundCreate\n0x004483B0:\t+\tDSoundBufferTest\n0x00448480:\t+\tWinSndFinish\n0x004484B0:\t+\tWinSndIsSoundEnabled\n0x004484C0:\t  x\tj_nullsub_3\n0x004484D0:\t  x\tnullsub_3\n\n\tspecific/init_display.cpp\n0x004484E0:\t+\tCreateScreenBuffers\n0x00448620:\t+\tCreatePrimarySurface\n0x004486C0:\t+\tCreateBackBuffer\n0x00448760:\t+\tCreateClipper\n0x00448800:\t+\tCreateWindowPalette\n0x004488E0:\t+\tCreateZBuffer\n0x004489A0:\t+\tGetZBufferDepth\n0x004489D0:\t+\tCreateRenderBuffer\n0x00448A80:\t+\tCreatePictureBuffer\n0x00448AF0:\t+\tClearBuffers\n0x00448CA0:\t+\tRestoreLostBuffers\n0x00448DE0:\t+\tUpdateFrame\n0x00448EB0:\t+\tWaitPrimaryBufferFlip\n0x00448EF0:\t+\tRenderInit\n0x00448F00:\t+\tRenderStart\n0x004492B0:\t+\tRenderFinish\n0x004493A0:\t+\tApplySettings\n0x004495B0:\t+\tFmvBackToGame\n0x004496C0:\t+\tGameApplySettings\n0x00449900:\t+\tUpdateGameResolution\n0x00449970:\t+\tDecodeErrorMessage\n\n\tspecific/file.cpp\n0x00449980:\t+\tReadFileSync\n0x004499D0:\t+\tLoadTexturePages\n0x00449B60:\t+\tLoadRooms\n0x00449F00:\t+\tAdjustTextureUVs\n0x00449FA0:\t+\tLoadObjects\n0x0044A520:\t+\tLoadSprites\n0x0044A660:\t+\tLoadItems\n0x0044A840:\t+\tLoadDepthQ\n0x0044A9D0:\t+\tLoadPalettes\n0x0044AA50:\t+\tLoadCameras\n0x0044AAB0:\t+\tLoadSoundEffects\n0x0044AB10:\t+\tLoadBoxes\n0x0044AD40:\t+\tLoadAnimatedTextures\n0x0044ADA0:\t+\tLoadCinematic\n0x0044AE20:\t+\tLoadDemo\n0x0044AEB0:\t+\tLoadDemoExternal\n0x0044AF50:\t\tLoadSamples\n0x0044B1C0:\t+\tChangeFileNameExtension\n0x0044B200:\t+\tGetFullPath\n0x0044B230:\t+\tSelectDrive\n0x0044B310:\t+\tLoadLevel\n0x0044B560:\t+\tS_LoadLevelFile\n0x0044B580:\t+\tS_UnloadLevelFile\n0x0044B5B0:\t+\tS_AdjustTexelCoordinates\n0x0044B5D0:\t+\tS_ReloadLevelGraphics\n0x0044B6A0:\t+\tRead_Strings\n0x0044B770:\t+\tS_LoadGameFlow\n\n\tspecific/fmv.cpp\n0x0044BE50:\t+\tPlayFMV\n0x0044BED0:\t+\tWinPlayFMV\n0x0044C1B0:\t+\tWinStopFMV\n0x0044C200:\t+\tIntroFMV\n\n\tspecific/frontend.cpp\n0x0044C2A0:\t+\tS_COLOUR\n0x0044C2D0:\t+\tS_DrawScreenLine\n0x0044C310:\t+\tS_DrawScreenBox\n0x0044C430:\t+\tS_DrawScreenFBox\n0x0044C460:\t+\tS_FinishInventory\n0x0044C470:\t+\tS_FadeToBlack\n0x0044C4C0:\t+\tS_Wait\n0x0044C520:\t+\tS_PlayFMV\n0x0044C530:\t+\tS_IntroFMV\n\n\tspecific/game.cpp\n0x0044C550:\t+\tStartGame\n0x0044C6A0:\t+\tGameLoop\n0x0044C740:\t+\tLevelCompleteSequence\n0x0044C750:\t+\tLevelStats\n0x0044C920:\t+\tGameStats\n0x0044CA40:\t+\tGetRandomControl\n0x0044CA60:\t+\tSeedRandomControl\n0x0044CA70:\t+\tGetRandomDraw\n0x0044CA90:\t+\tSeedRandomDraw\n0x0044CAA0:\t+\tGetValidLevelsList\n0x0044CAF0:\t+\tGetSavedGamesList\n0x0044CB40:\t+\tDisplayCredits\n0x0044CD80:\t+\tS_FrontEndCheck\n0x0044CEF0:\t+\tS_SaveGame\n0x0044D010:\t+\tS_LoadGame\n\n\tspecific/hwr.cpp\n0x0044D0B0:\t+\tHWR_InitState\n0x0044D1E0:\t+\tHWR_ResetTexSource\n0x0044D210:\t+\tHWR_ResetColorKey\n0x0044D240:\t+\tHWR_ResetZBuffer\n0x0044D2A0:\t+\tHWR_TexSource\n0x0044D2D0:\t+\tHWR_EnableColorKey\n0x0044D320:\t+\tHWR_EnableZBuffer\n0x0044D3B0:\t+\tHWR_BeginScene\n0x0044D3E0:\t+\tHWR_DrawPolyList\n0x0044D560:\t+\tHWR_LoadTexturePages\n0x0044D5F0:\t+\tHWR_FreeTexturePages\n0x0044D640:\t+\tHWR_GetPageHandles\n0x0044D680:\t+\tHWR_VertexBufferFull\n0x0044D6B0:\t+\tHWR_Init\n\n\tspecific/init.cpp\n0x0044D6E0:\t+\tS_InitialiseSystem\n0x0044D730:\t+\tShutdownGame\n0x0044D750:\t+\tinit_game_malloc\n0x0044D780:\t+\tgame_malloc\n0x0044D800:\t+\tgame_free\n0x0044D840:\t+\tCalculateWibbleTable\n0x0044D930:\t+\tS_SeedRandom\n\n\tspecific/input.cpp\n0x0044D9B0:\t+\tKey\n0x0044DAD0:\t+\tS_UpdateInput\n\n\tspecific/winmain.cpp\n0x0044E5A0:\t+\tRenderErrorBox\n0x0044E5E0:\t+\tWinMain\n0x0044E7A0:\t  x\tnullsub_4\n0x0044E7B0:\t+\tInit\n0x0044E830:\t+\tWinCleanup\n0x0044E860:\t+\tWinGameStart\n0x0044E8E0:\t+\tWinGameFinish\n0x0044E920:\t  x\tThrowException\n0x0044E940:\t  x\ttype_info::operator=(type_infoconst&)\n0x0044E950:\t+\tS_ExitSystem\n\n\tspecific/screenshot.cpp\n0x0044E9A0:\t+\tScreenShotPCX\n0x0044EAB0:\t+\tCompPCX\n0x0044EB60:\t+\tEncodeLinePCX\n0x0044EC40:\t+\tEncodePutPCX\n0x0044EC80:\t+\tScreenShot\n\n\tspecific/option.cpp\n0x0044EE80:\t+\tdo_inventory_options\n0x0044EF90:\t+\tdo_passport_option\n----------:\t+\tdo_gamma_option\n0x0044F5E0:\t+\tdo_detail_option\n0x0044F8C0:\t+\tdo_sound_option\n0x0044FD60:\t+\tdo_compass_option\n0x0044FE20:\t+\tFlashConflicts\n0x0044FEA0:\t+\tDefaultConflict\n0x0044FEE0:\t+\tdo_control_option\n0x004505F0:\t+\tS_ShowControls\n0x00450AC0:\t+\tS_ChangeCtrlText\n0x00450B60:\t+\tS_RemoveCtrlText\n\n\tspecific/output.cpp\n0x00450BA0:\t+\tGetRenderHeight\n0x00450BB0:\t+\tGetRenderWidth\n0x00450BC0:\t+\tS_InitialisePolyList\n0x00450CB0:\t+\tS_DumpScreen\n0x00450CF0:\t+\tS_ClearScreen\n0x00450D00:\t+\tS_InitialiseScreen\n0x00450D40:\t+\tS_OutputPolyList\n0x00450D80:\t+\tS_GetObjectBounds\n0x00450FF0:\t+\tS_InsertBackPolygon\n0x00451040:\t+\tS_PrintShadow\n0x00451240:\t+\tS_CalculateLight\n0x00451540:\t+\tS_CalculateStaticLight\n0x00451580:\t+\tS_CalculateStaticMeshLight\n0x004516B0:\t+\tS_LightRoom\n0x004518C0:\t+\tS_DrawHealthBar\n0x00451A90:\t+\tS_DrawAirBar\n0x00451C90:\t+\tAnimateTextures\n0x00451D50:\t+\tS_SetupBelowWater\n0x00451DB0:\t+\tS_SetupAboveWater\n0x00451DE0:\t+\tS_AnimateTextures\n0x00451EA0:\t+\tS_DisplayPicture\n0x00451FB0:\t+\tS_SyncPictureBufferPalette\n0x00452030:\t+\tS_DontDisplayPicture\n0x00452040:\t+\tScreenDump\n0x00452050:\t+\tScreenPartialDump\n0x00452060:\t+\tFadeToPal\n0x00452230:\t+\tScreenClear\n0x00452260:\t+\tS_CopyScreenToBuffer\n0x00452310:\t+\tS_CopyBufferToScreen\n0x00452360:\t+\tDecompPCX\n0x00452460:\t  x\tj_nullsub_6\n0x00452470:\t  x\tnullsub_6\n\n\tspecific/setupdlg.cpp\n0x00452480:\t+\tOpenGameRegistryKey\n0x004524D0:\t+\tCloseGameRegistryKey\n0x004524E0:\t+\tSE_WriteAppSettings\n0x00452760:\t+\tSE_ReadAppSettings\n0x00452AC0:\t+\tSE_GraphicsTestStart\n0x00452B90:\t+\tSE_GraphicsTestFinish\n0x00452BB0:\t+\tSE_GraphicsTestExecute\n0x00452BC0:\t+\tSE_GraphicsTest\n0x00452C20:\t+\tSE_DefaultGraphicsSettings\n0x00452D70:\t+\tSE_SoundTestStart\n0x00452E30:\t+\tSE_SoundTestFinish\n0x00452E40:\t+\tSE_SoundTestExecute\n0x00452E80:\t+\tSE_SoundTest\n0x00452EE0:\t+\tSE_PropSheetCallback\n0x00452F20:\t+\tSE_NewPropSheetWndProc\n0x00452F80:\t+\tSE_ShowSetupDialog\n0x00453150:\t+\tSE_GraphicsDlgProc\n0x00453560:\t+\tSE_GraphicsDlgFullScreenModesUpdate\n0x00453750:\t+\tSE_GraphicsAdapterSet\n0x00453770:\t+\tSE_GraphicsDlgUpdate\n0x00453EB0:\t+\tSE_GraphicsDlgInit\n0x00454030:\t+\tSE_SoundDlgProc\n0x004541C0:\t+\tSE_SoundAdapterSet\n0x004541D0:\t+\tSE_SoundDlgUpdate\n0x004542F0:\t+\tSE_SoundDlgInit\n0x004543B0:\t+\tSE_ControlsDlgProc\n0x004544C0:\t+\tSE_ControlsJoystickSet\n0x004544D0:\t+\tSE_ControlsDlgUpdate\n0x00454540:\t+\tSE_ControlsDlgInit\n0x00454600:\t+\tSE_OptionsDlgProc\n0x00454690:\t+\tSE_OptionsDlgUpdate\n0x004548D0:\t+\tSE_OptionsStrCat\n0x00454920:\t+\tSE_AdvancedDlgProc\n0x00454A30:\t+\tSE_AdvancedDlgUpdate\n0x00454AE0:\t+\tSE_AdvancedDlgInit\n0x00454AF0:\t+\tSE_FindSetupDialog\n\n\tspecific/smain.cpp\n0x00454B10:\t+\tGameMain\n0x00454DE0:\t+\tTitleSequence\n0x00454EF0:\t+\tCheckCheatMode\n0x00455250:\t+\tS_SaveSettings\n0x004552D0:\t+\tS_LoadSettings\n\n\tspecific/sndpc.cpp\n0x004553B0:\t+\tS_SoundPlaySample\n0x00455400:\t+\tS_Sound_CalculateSampleVolume\n0x00455430:\t+\tS_Sound_CalculateSamplePan\n0x00455460:\t+\tS_SoundPlaySampleLooped\n0x004554B0:\t+\tS_SoundSetPanAndVolume\n0x004554F0:\t+\tS_SoundSetPitch\n0x00455510:\t+\tS_SoundSetMasterVolume\n0x00455520:\t+\tS_SoundStopSample\n0x00455540:\t+\tS_SoundStopAllSamples\n0x00455550:\t+\tS_SoundSampleIsPlaying\n0x00455570:\t+\tCD_Init\n0x00455600:\t+\tCD_Cleanup\n0x00455640:\t+\tS_CDLoop\n0x004556E0:\t+\tS_CDPlay\n0x00455760:\t+\tS_CDStop\n0x004557A0:\t+\tStartSyncedAudio\n0x00455830:\t+\tS_CDGetLoc\n0x004558A0:\t+\tS_CDVolume\n\n\tspecific/texture.cpp\n0x00455990:\t+\tCopyBitmapPalette\n0x00455AD0:\t+\tFindNearestPaletteEntry\n0x00455BA0:\t+\tSyncSurfacePalettes\n0x00455C50:\t+\tCreateTexturePalette\n0x00455CE0:\t+\tGetFreePaletteIndex\n0x00455D00:\t+\tFreePalette\n0x00455D30:\t+\tSafeFreePalette\n0x00455D80:\t+\tCreateTexturePage\n0x00455DF0:\t+\tGetFreeTexturePageIndex\n0x00455E10:\t+\tCreateTexturePageSurface\n0x00455EB0:\t+\tTexturePageInit\n0x00456030:\t+\tCreate3DTexture\n0x00456060:\t+\tSafeFreeTexturePage\n0x00456080:\t+\tFreeTexturePage\n0x004560C0:\t+\tTexturePageReleaseVidMemSurface\n0x00456100:\t+\tFreeTexturePages\n0x00456130:\t+\tLoadTexturePage\n0x004561E0:\t+\tReloadTextures\n0x00456220:\t+\tGetTexturePageHandle\n0x00456260:\t+\tAddTexturePage8\n0x00456360:\t+\tAddTexturePage16\n0x00456500:\t+\tEnumTextureFormatsCallback\n0x00456620:\t+\tEnumerateTextureFormats\n0x00456650:\t+\tCleanupTextures\n0x00456660:\t+\tInitTextures\n\n\tspecific/utils.cpp\n0x00456680:\t+\tUpdateTicks\n0x004566C0:\t+\tTIME_Init\n0x00456720:\t+\tSync\n0x00456780:\t+\tLoadResource\n0x004567C0:\t+\tUT_InitAccurateTimer\n0x00456820:\t+\tUT_Microseconds\n0x00456870:\t+\tUT_CenterWindow\n0x004568E0:\t+\tUT_FindArg\n0x00456910:\t+\tUT_MessageBox\n0x00456930:\t+\tUT_ErrorBox\n0x00456980:\t+\tCD_NoteAlert\n0x004569B0:\t+\tDialogBoxProc\n\n\tspecific/registry.cpp\n0x00456A20:\t+\tGuidBinaryToString\n0x00456A80:\t+\tGuidStringToBinary\n0x00456B30:\t+\tOpenRegistryKey\n0x00456B60:\t+\tIsNewRegistryKeyCreated\n0x00456B70:\t+\tCloseRegistryKey\n0x00456B80:\t+\tSetRegistryDwordValue\n0x00456BA0:\t+\tSetRegistryBoolValue\n0x00456BD0:\t+\tSetRegistryFloatValue\n0x00456C10:\t+\tSetRegistryBinaryValue\n0x00456C50:\t+\tSetRegistryStringValue\n0x00456CA0:\t+\tDeleteRegistryValue\n0x00456CC0:\t+\tGetRegistryDwordValue\n0x00456D20:\t+\tGetRegistryBoolValue\n0x00456DA0:\t+\tGetRegistryFloatValue\n0x00456E00:\t+\tGetRegistryBinaryValue\n0x00456E80:\t+\tGetRegistryStringValue\n0x00456F20:\t+\tGetRegistryGuidValue\n\n\tspecific/setupwnd.cpp\n0x00456FC0:\t+\tSE_ReleaseBitmapResource\n0x00457000:\t+\tSE_LoadBitmapResource\n0x004570D0:\t+\tSE_DrawBitmap\n0x00457140:\t+\tSE_UpdateBitmapPalette\n0x00457160:\t+\tSE_ChangeBitmapPalette\n0x004571C0:\t+\tSE_RegisterSetupWindowClass\n0x00457230:\t+\tSE_SetupWindowProc\n0x00457470:\t+\tSE_PassMessageToImage\n\n\tspecific/utils.cpp\n0x004574A0:\t+\tUT_MemBlt\n\n// ======================================\n// ASM\n// ======================================\n\n\tasm/3d_gen_a.s -> 3dsystem/3d_gen.cpp\n----------:\t+\tphd_PopMatrix\n0x00457510:\t+\tphd_PushMatrix\n0x0045752E:\t+\tphd_PushUnitMatrix\n\n\tasm/3d_xouta.s -> 3dsystem/3d_out.cpp\n0x00457564:\t+\tflatA\n0x004575C5:\t+\ttransA\n0x004576FF:\t+\tgourA\n0x0045785F:\t+\tgtmapA\n0x00457B5C:\t+\twgtmapA\n\n\tasm/phd_math.s -> 3dsystem/3dinsert.cpp\n0x00457EA0:\t+\tphd_atan\n0x00457EE8:\t+\tphd_cos\n0x00457EEE:\t+\tphd_sin\n0x00457F09:\t  x\tphd_sin_quadrant1\n0x00457F23:\t+\tphd_sqrt\n\n0x00457F50:"
  },
  {
    "path": "binaries/README.md",
    "content": "# Tomb Raider 2 binaries\n\nHere are few binary files that are taken from the original game and slightly modified to work with TR2Main.\n\n- [Tomb2_original](Tomb2_original.zip) is the original executable build on December 1, 1997 by Core Design (though file timestamp is 2:36pm, December 10, 1997). It does not use *TRMain.dll*. This one is uploaded only so that you can **compare what has changed** in the patched versions.\n- [Tomb2_legacy](Tomb2_legacy.zip) is based on the original executable, but it has a slightly enlarged *.text* section with *write* permission. The entry point is redirected to a function that links with *TRMain.dll*, and then jumps to a common entry point. This executable can be run with or without *TRMain.dll*. Recommended for **debugging and unit testing**.\n- [Tomb2_clean](Tomb2_clean.zip) is based on the original executable, it has an original entry point and *.text* section, but with *write* permission. It links with *TRMain.dll* through *.import* table. *Winplay.dll* dependency removed. Also it has the compatibility manifest and XP manifest in the *.rsrc* section. This executable requires *TRMain.dll*. Recommended for **release builds**.\n\nAlso you can find here some additional media files\n\n- [BAREFOOT.SFX](BAREFOOT.SFX.zip) is an SFX package with 4 sound effects of barefoot steps. These effects are taken from the PlayStation version of the game and slightly remastered by me (only the high-frequency range was restored).\n\nIf you are looking for a complete package with the *Tomb2.exe*, *TR2Main.dll* and other stuff, then you should go to [releases](https://github.com/Arsunt/TR2Main/releases)."
  },
  {
    "path": "configs/TR2Main.json",
    "content": "{\n    \"comment\": [\n        \"                                                                     \",\n        \" This is mod configuration file for TR2Main. You can edit it,        \",\n        \" if you want to create your own mod of the Tomb Raider II game.      \",\n        \" This is JSON format, it's very simple. Here is info about fields:   \",\n        \"                                                                     \",\n        \" - 'comment' is used for comments only and it's ignored by the game. \",\n        \"   You can write some notes inside it, like this one.                \",\n        \"                                                                     \",\n        \" - 'default' stores a set of default parameters for all levels.      \",\n        \"                                                                     \",\n        \" - 'levels' stores sets of parameters for each of the levels.        \",\n        \"   If some parameter is set both in the 'default' and the 'levels',  \",\n        \"   the parameter from 'levels' is applied.                           \",\n        \"                                                                     \",\n        \" - 'filename' is used to set the name of the level file for which    \",\n        \"   this set of parameters will be used. Just a filename with no path \",\n        \"   and no extension.                                                 \",\n        \"                                                                     \",\n        \" - 'picture' is used to set the name of the image file for the level \",\n        \"   loading screen. Just a filename with no path and no extension.    \",\n        \"                                                                     \",\n        \" - 'watercolor' is used to set the water color for the level.        \",\n        \"   It must be in hexadecimal format: RRGGBB (red, green, blue).      \",\n        \"   PC HW Renderer uses '80C0FF', and PC SW renderer uses 'AAAAFF'.   \",\n        \"   PS1 colors: '80FFFF', 'B2E6E6', 'CCFFCC', 'CCFF98', 'CCFF80'.     \",\n        \"   This setting affects only hardware renderer mode.                 \",\n        \"                                                                     \",\n        \" - 'barefoot' is used to indicate levels where Lara does not wear    \",\n        \"   boots. It is used for alternative sound effects of Lara's steps.  \",\n        \"   The parameter can be true or false. Default value is false.       \",\n        \"                                                                     \",\n        \" - 'semitransparent' is used for semitransparency parameters.        \",\n        \"   It can contain: 'animtex', 'objects', 'statics', 'rooms'          \",\n        \"                                                                     \",\n        \" - 'animtex' is used to mark animated textures as semitransparent.   \",\n        \"   The field must be inside 'semitransparent' section.               \",\n        \"   It can be one of the values: 'auto', 'none', 'all'. Or you can    \",\n        \"   mark specific animated texture ranges, if you set it as list.     \",\n        \"   For example, if you want to mark as semitransparent animated      \",\n        \"   texture ranges [0,1,2,5], just set 'animtex' to '0-2, 5'.         \",\n        \"   Default value is 'auto'. This means if some room texture is       \",\n        \"   animated and it has some transparent pixels, it's automatically   \",\n        \"   marked as semitransparent. If texture is opaque, it stays opaque. \",\n        \"   Almost all animated textures of the original game affected by     \",\n        \"   'auto' are water surfaces, so it's recommended to use this mode.  \",\n        \"                                                                     \",\n        \" - 'objects' is used to mark object textures as semitransparent      \",\n        \"   or to mark object polygons as reflective. The field must be       \",\n        \"   inside 'semitransparent' or 'reflective' section accordingly.     \",\n        \"   It must contain 'object' and 'meshes' subfields.                  \",\n        \"   'object' contains the object ID (from 0 to 264),                  \",\n        \"   'meshes' contains the list of meshes, each contains 'mesh' field  \",\n        \"   (counts inside the object, starting from zero). Optionally, mesh  \",\n        \"   contains fields 'filter', 't4list', 't3list', 'c4list', 'c3list'. \",\n        \"   'filter' is used to check that this mesh is really the one that   \",\n        \"   supposed to be patched. Fields 'v', 't4', 't3', 'c4', 'c3' set    \",\n        \"   vertices count, textured quads/triangles, colored quads/triangles \",\n        \"   numbers accordingly. If some of these fields is not set, it is    \",\n        \"   considered as zero. If there is no 'filter' or 'v' is zero, the   \",\n        \"   mesh check is disabled. 't4list', 't3list', 'c4list', 'c3list'    \",\n        \"   stores lists of polygons for textured quads/triangles, colored    \",\n        \"   quads/triangles accordingly. Format is the same as for 'animtex', \",\n        \"   but there is no 'auto' option. If there are no lists in the mesh, \",\n        \"   then every list considered as 'all'. If there are some lists, but \",\n        \"   some absent, every missing list considered as 'none'. The listed  \",\n        \"   polygons become semitransparent or reflective.                    \",\n        \"                                                                     \",\n        \" - 'statics' is used to mark static mesh textures as semitransparent \",\n        \"   or to mark static polygons as reflective. The field must be       \",\n        \"   inside 'semitransparent' or 'reflective' section accordingly.     \",\n        \"   It must contain 'static' subfield for static ID (counts from 0).  \",\n        \"   All other subfields are identical to 'meshes' described in the    \",\n        \"   'objects', but 'mesh' subfield is not used, because every static  \",\n        \"   is a single mesh itself. Note that most static objects meshes     \",\n        \"   don't have normal vectors, required for reflections, so even if   \",\n        \"   you set them reflective, they won't become reflective.            \",\n        \"                                                                     \",\n        \" - 'rooms' is used to mark room mesh textures as semitransparent.    \",\n        \"   The field must be inside 'semitransparent' section.               \",\n        \"   It must contain 'room' subfield for room ID (counts from 0).      \",\n        \"   All other subfields are identical to 'meshes' described in the    \",\n        \"   'objects', but 'mesh' subfield is not used, because every room    \",\n        \"   is a single mesh itself. Note that it is not necessary to list    \",\n        \"   all semitransparent polygons for all rooms if they refer to the   \",\n        \"   same texture. Just specify a few polygons in several rooms.       \",\n        \"   Room meshes have no normal vectors, so they cannot be reflective. \",\n        \"                                                                     \"\n    ],\n    \"default\": {\n        \"comment\": \"Default settings for all levels\",\n        \"watercolor\": \"80FFFF\",\n        \"semitransparent\": {\n            \"animtex\": \"auto\",\n            \"objects\": [{\n                \"comment\": \"Windshield of a red fast snowmobile\",\n                \"object\": 13,\n                \"meshes\": [{\n                    \"mesh\": 0,\n                    \"filter\": {\"v\":59, \"t4\":14, \"t3\":104},\n                    \"t3list\": \"48-51, 54-71, 73-78\"\n                }]\n            }, {\n                \"comment\": \"Sunglasses lenses in the menu (Details option)\",\n                \"object\": 153,\n                \"meshes\": [{\n                    \"mesh\": 0,\n                    \"filter\": {\"v\":80, \"t4\":66, \"t3\":4, \"c4\":2},\n                    \"t4list\": \"23-30, 44-51\",\n                    \"t3list\": \"all\"\n                }]\n            }, {\n                \"comment\": \"Sphere of Doom 1 (Dragon transformation)\",\n                \"object\": 209,\n                \"meshes\": [{\"mesh\": 0}]\n            }, {\n                \"comment\": \"Sphere of Doom 2 (Dragon transformation)\",\n                \"object\": 210,\n                \"meshes\": [{\"mesh\": 0}]\n            }, {\n                \"comment\": \"Flare fire\",\n                \"object\": 235,\n                \"meshes\": [{\"mesh\": 0}]\n            }, {\n                \"comment\": \"Pistols/uzi/magnums gunfire flash\",\n                \"object\": 240,\n                \"meshes\": [{\"mesh\": 0}]\n            }, {\n                \"comment\": \"M16 gunfire flash\",\n                \"object\": 241,\n                \"meshes\": [{\"mesh\": 0}]\n            }]\n        },\n        \"reflective\": {\n            \"objects\": [{\n                \"comment\": \"Windshield of a gray fast snowmobile (The Golden Mask)\",\n                \"object\": 13,\n                \"meshes\": [{\n                    \"mesh\": 0,\n                    \"filter\": {\"v\":59, \"t4\":14, \"t3\":73, \"c3\":17},\n                    \"t3list\": \"48\",\n                    \"c3list\": \"all\"\n                }]\n            }, {\n                \"comment\": \"Flamethrower mask\",\n                \"object\": 34,\n                \"meshes\": [{\n                    \"mesh\": 15,\n                    \"filter\": {\"v\":38, \"t4\":30, \"t3\":12},\n                    \"t4list\": \"22-26\"\n                }]\n            }, {\n                \"comment\": \"Windshield of an armed snowmobile\",\n                \"object\": 51,\n                \"meshes\": [{\n                    \"mesh\": 0,\n                    \"filter\": {\"v\":88, \"t4\":45, \"t3\":60},\n                    \"t4list\": \"21-22\",\n                    \"t3list\": \"34-47\"\n                }]\n            }, {\n                \"comment\": \"Rolling wheel blade\",\n                \"object\": 80,\n                \"meshes\": [{\n                    \"mesh\": 0,\n                    \"t4list\": \"all\",\n                    \"c4list\": \"all\"\n                }]\n            }, {\n                \"comment\": \"Wall mounted blade\",\n                \"object\": 81,\n                \"meshes\": [{\"mesh\": 1}]\n            }, {\n                \"comment\": \"Sword of killing statue\",\n                \"object\": 82,\n                \"meshes\": [{\"mesh\": 7}]\n            }]\n        }\n    },\n    \"levels\": [{\n        \"comment\": \"Title\",\n        \"filename\": \"TITLE\"\n    }, {\n        \"comment\": \"Lara's Home\",\n        \"filename\": \"ASSAULT\",\n        \"picture\": \"MANSION\",\n        \"semitransparent\": {\n            \"statics\": [{\n                \"comment\": \"Glass on the sink in the bathroom\",\n                \"static\": 21,\n                \"filter\": {\"v\":46, \"t4\":41},\n                \"t4list\": \"17-25\"\n            }]\n        }\n    }, {\n        \"comment\": \"The Great Wall\",\n        \"filename\": \"WALL\",\n        \"picture\": \"CHINA\",\n        \"watercolor\": \"B2E6E6\"\n    }, {\n        \"comment\": \"Venice\",\n        \"filename\": \"BOAT\",\n        \"picture\": \"VENICE\",\n        \"watercolor\": \"CCFF80\",\n        \"semitransparent\": {\n            \"rooms\": [{\n                \"comment\": \"Chain-link fence\",\n                \"room\": 0,\n                \"filter\": {\"v\":112, \"t4\":91},\n                \"t4list\": \"3\"\n            }]\n        },\n        \"reflective\": {\n            \"objects\": [{\n                \"comment\": \"Boathouse key\",\n                \"object\": 197,\n                \"meshes\": [{\n                    \"mesh\": 0,\n                    \"filter\": {\"v\":66, \"t4\":53},\n                    \"t4list\": \"0-9, 11-21, 24-38, 44-51\"\n                }]\n            }]\n        }\n    }, {\n        \"comment\": \"Bartoli's Hideout\",\n        \"filename\": \"VENICE\",\n        \"picture\": \"VENICE\",\n        \"watercolor\": \"CCFF80\",\n        \"semitransparent\": {\n            \"rooms\": [{\n                \"comment\": \"Chain-link fence\",\n                \"room\": 15,\n                \"filter\": {\"v\":30, \"t4\":22},\n                \"t4list\": \"19, 21\"\n            }]\n        },\n        \"reflective\": {\n            \"objects\": [{\n                \"comment\": \"Library key\",\n                \"object\": 197,\n                \"meshes\": [{\n                    \"mesh\": 0,\n                    \"filter\": {\"v\":66, \"t4\":53},\n                    \"t4list\": \"0-9, 11-21, 24-38, 44-51\"\n                }]\n            }]\n        }\n    }, {\n        \"comment\": \"Opera House\",\n        \"filename\": \"OPERA\",\n        \"picture\": \"VENICE\",\n        \"watercolor\": \"CCFF80\",\n        \"semitransparent\": {\n            \"rooms\": [{\n                \"comment\": \"Chain-link fence\",\n                \"room\": 104,\n                \"filter\": {\"v\":43, \"t4\":29},\n                \"t4list\": \"2, 4, 6, 8\"\n            }]\n        }\n    }, {\n        \"comment\": \"Offshore Rig\",\n        \"filename\": \"RIG\",\n        \"picture\": \"RIG\"\n    }, {\n        \"comment\": \"Diving Area\",\n        \"filename\": \"PLATFORM\",\n        \"picture\": \"RIG\"\n    }, {\n        \"comment\": \"40 Fathoms\",\n        \"filename\": \"UNWATER\",\n        \"picture\": \"TITAN\",\n        \"barefoot\": true\n    }, {\n        \"comment\": \"Wreck of the Maria Doria\",\n        \"filename\": \"KEEL\",\n        \"picture\": \"TITAN\",\n        \"barefoot\": true,\n        \"semitransparent\": {\n            \"rooms\": [{\n                \"comment\": \"Stained glass\",\n                \"room\": 83,\n                \"filter\": {\"v\":331, \"t4\":303, \"t3\":12},\n                \"t4list\": \"212-216\"\n            }]\n        }\n    }, {\n        \"comment\": \"Living Quarters\",\n        \"filename\": \"LIVING\",\n        \"picture\": \"TITAN\",\n        \"barefoot\": true\n    }, {\n        \"comment\": \"The Deck\",\n        \"filename\": \"DECK\",\n        \"picture\": \"TITAN\",\n        \"barefoot\": true\n    }, {\n        \"comment\": \"Tibetan Foothills\",\n        \"filename\": \"SKIDOO\",\n        \"picture\": \"TIBET\",\n        \"watercolor\": \"B2E6E6\"\n    }, {\n        \"comment\": \"Barkhang Monastery\",\n        \"filename\": \"MONASTRY\",\n        \"picture\": \"TIBET\"\n    }, {\n        \"comment\": \"Catacombs of the Talion\",\n        \"filename\": \"CATACOMB\",\n        \"picture\": \"TIBET\"\n    }, {\n        \"comment\": \"Ice Palace\",\n        \"filename\": \"ICECAVE\",\n        \"picture\": \"TIBET\"\n    }, {\n        \"comment\": \"Temple of Xian\",\n        \"filename\": \"EMPRTOMB\",\n        \"picture\": \"CHINA\",\n        \"watercolor\": \"CCFF98\"\n    }, {\n        \"comment\": \"Floating Islands\",\n        \"filename\": \"FLOATING\",\n        \"picture\": \"CHINA\",\n        \"watercolor\": \"CCFFCC\"\n    }, {\n        \"comment\": \"The Dragon's Lair\",\n        \"filename\": \"XIAN\",\n        \"picture\": \"CHINA\",\n        \"watercolor\": \"CCFFCC\"\n    }, {\n        \"comment\": \"Home Sweet Home\",\n        \"filename\": \"HOUSE\",\n        \"picture\": \"MANSION\",\n        \"barefoot\": true,\n        \"semitransparent\": {\n            \"statics\": [{\n                \"comment\": \"Glass on the sink in the bathroom\",\n                \"static\": 21,\n                \"filter\": {\"v\":46, \"t4\":41},\n                \"t4list\": \"17-25\"\n            }]\n        }\n    }, {\n        \"comment\": \"Cutscene after The Great Wall\",\n        \"filename\": \"CUT1\",\n        \"watercolor\": \"B2E6E6\"\n    }, {\n        \"comment\": \"Cutscene after Opera House\",\n        \"filename\": \"CUT2\"\n    }, {\n        \"comment\": \"Cutscene after Diving Area\",\n        \"filename\": \"CUT3\"\n    }, {\n        \"comment\": \"Cutscene after Temple of Xian\",\n        \"filename\": \"CUT4\"\n    }, {\n        \"comment\": \"The Cold War\",\n        \"filename\": \"LEVEL1\",\n        \"picture\": \"LEVEL1\"\n    }, {\n        \"comment\": \"Fool's Gold\",\n        \"filename\": \"LEVEL2\",\n        \"picture\": \"LEVEL2\"\n    }, {\n        \"comment\": \"Furnace of the Gods\",\n        \"filename\": \"LEVEL3\",\n        \"picture\": \"LEVEL3\"\n    }, {\n        \"comment\": \"Kingdom\",\n        \"filename\": \"LEVEL4\",\n        \"picture\": \"LEVEL4\"\n    }, {\n        \"comment\": \"Nightmare in Vegas\",\n        \"filename\": \"LEVEL5\",\n        \"picture\": \"LEVEL5\",\n        \"semitransparent\": {\n            \"statics\": [{\n                \"comment\": \"Glass on the sink in the bathroom\",\n                \"static\": 0,\n                \"filter\": {\"v\":46, \"t4\":60},\n                \"t4list\": \"23-32\"\n            }]\n        }\n    }]\n}"
  },
  {
    "path": "configs/textures/texpages/README.md",
    "content": "# Tomb Raider 2 texture pages configuration\n\nHere is [configuration](config.json) file for the official iOS/Android port texture package. Developers used few dirty tricks to make textures fit. If you create your own texture package properly, you don't need this configuration.\n"
  },
  {
    "path": "configs/textures/texpages/config.json",
    "content": "{\n    \"comment\": [\n        \"                                                                     \",\n        \" This is texture pages configuration file for TR2Main. You can use   \",\n        \" it, if texture pages have wrong design like ones for iOS/Android.   \",\n        \" This is JSON format, it's very simple. Here is info about fields:   \",\n        \"                                                                     \",\n        \" - 'comment' is used for comments only and it's ignored by the game. \",\n        \"   You can write some notes inside it, like this one.                \",\n        \"                                                                     \",\n        \" - 'default' stores a set of default parameters for all levels.      \",\n        \"                                                                     \",\n        \" - 'levels' stores sets of parameters for each of the levels.        \",\n        \"   If some parameter is set both in the 'default' and the 'levels',  \",\n        \"   the parameter from 'levels' is applied.                           \",\n        \"                                                                     \",\n        \" - 'filename' is used to set the name of the level file for which    \",\n        \"   this set of parameters will be used. Just a filename with no path \",\n        \"   and no extension.                                                 \",\n        \"                                                                     \",\n        \" - 'legacy_colors' is used to prevent improvement of untextured      \",\n        \"   polygons colors.                                                  \",\n        \"                                                                     \",\n        \" - 'uv_adjust' is used to force UV adjustment if textures are        \",\n        \"   misplaced and produce texture bleeding. You can set it to value   \",\n        \"   between 0.0 and 1.0. Don't use it if your textures are OK.        \",\n        \"                                                                     \",\n        \" - 'glyphs' is used to modify some font sprites parameters.          \",\n        \"   'id' contains the glyph ID (from 0 to 109),                       \",\n        \"   'x_offset' contains the integer value of glyph X adjustment,      \",\n        \"   'y_offset' contains the integer value of glyph Y adjustment,      \",\n        \"   'x_stretch' contains the float value of glyph horizontal stretch, \",\n        \"   'y_stretch' contains the float value of glyph vertical stretch,   \",\n        \"   'spacing' contains the integer value of glyph spacing.            \",\n        \"                                                                     \"\n     ],\n    \"default\": {\n        \"comment\": \"Default settings for all levels\",\n        \"legacy_colors\": false,\n        \"uv_adjust\": 1.0,\n        \"glyphs\": [{\n            \"comment\": \"A\",\n            \"id\": 0,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"B\",\n            \"id\": 1,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"C\",\n            \"id\": 2,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"D\",\n            \"id\": 3,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"E\",\n            \"id\": 4,\n            \"spacing\": 8\n        }, {\n            \"comment\": \"F\",\n            \"id\": 5,\n            \"spacing\": 8\n        }, {\n            \"comment\": \"G\",\n            \"id\": 6,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"H\",\n            \"id\": 7,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"I\",\n            \"id\": 8,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"J\",\n            \"id\": 9,\n            \"spacing\": 8\n        }, {\n            \"comment\": \"K\",\n            \"id\": 10,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"L\",\n            \"id\": 11,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"M\",\n            \"id\": 12,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"N\",\n            \"id\": 13,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"O\",\n            \"id\": 14,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"P\",\n            \"id\": 15,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"Q\",\n            \"id\": 16,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"R\",\n            \"id\": 17,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"S\",\n            \"id\": 18,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"T\",\n            \"id\": 19,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"U\",\n            \"id\": 20,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"V\",\n            \"id\": 21,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"W\",\n            \"id\": 22,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"X\",\n            \"id\": 23,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"Y\",\n            \"id\": 24,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"Z\",\n            \"id\": 25,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"a\",\n            \"id\": 26,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"b\",\n            \"id\": 27,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"c\",\n            \"id\": 28,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"d\",\n            \"id\": 29,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"e\",\n            \"id\": 30,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"f\",\n            \"id\": 31,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"g\",\n            \"id\": 32,\n            \"y_offset\": -6,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"h\",\n            \"id\": 33,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"i\",\n            \"id\": 34,\n            \"x_stretch\": 2.0,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"j\",\n            \"id\": 35,\n            \"y_offset\": -6,\n            \"spacing\": 8\n        }, {\n            \"comment\": \"k\",\n            \"id\": 36,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"l\",\n            \"id\": 37,\n            \"x_stretch\": 2.0,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"m\",\n            \"id\": 38,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"n\",\n            \"id\": 39,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"o\",\n            \"id\": 40,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"p\",\n            \"id\": 41,\n            \"y_offset\": -6,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"q\",\n            \"id\": 42,\n            \"y_offset\": -6,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"r\",\n            \"id\": 43,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"s\",\n            \"id\": 44,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"t\",\n            \"id\": 45,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"u\",\n            \"id\": 46,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"v\",\n            \"id\": 47,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"w\",\n            \"id\": 48,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"x\",\n            \"id\": 49,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"y\",\n            \"id\": 50,\n            \"y_offset\": -6,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"z\",\n            \"id\": 51,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"0\",\n            \"id\": 52,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"1\",\n            \"id\": 53,\n            \"x_stretch\": 2.0,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"2\",\n            \"id\": 54,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"3\",\n            \"id\": 55,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"4\",\n            \"id\": 56,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"5\",\n            \"id\": 57,\n            \"spacing\": 9\n        }, {\n            \"comment\": \"6\",\n            \"id\": 58,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"7\",\n            \"id\": 59,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"8\",\n            \"id\": 60,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"9\",\n            \"id\": 61,\n            \"spacing\": 10\n        }, {\n            \"comment\": \".\",\n            \"id\": 62,\n            \"spacing\": 5\n        }, {\n            \"comment\": \",\",\n            \"id\": 63,\n            \"spacing\": 6\n        }, {\n            \"comment\": \"!\",\n            \"id\": 64,\n            \"spacing\": 5\n        }, {\n            \"comment\": \"?\",\n            \"id\": 65,\n            \"spacing\": 8\n        }, {\n            \"comment\": \"[ / double quote\",\n            \"id\": 66,\n            \"spacing\": 6\n        }, {\n            \"comment\": \"diaeresis diacritic\",\n            \"id\": 67,\n            \"spacing\": 8\n        }, {\n            \"comment\": \"/\",\n            \"id\": 68,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"circumflex diacritic\",\n            \"id\": 69,\n            \"x_offset\": 4,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"acute diacritic\",\n            \"id\": 70,\n            \"x_offset\": 4,\n            \"spacing\": 6\n        }, {\n            \"comment\": \"-\",\n            \"id\": 71,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"+ / =\",\n            \"id\": 72,\n            \"spacing\": 10\n        }, {\n            \"comment\": \":\",\n            \"id\": 73,\n            \"spacing\": 5\n        }, {\n            \"comment\": \"eszett\",\n            \"id\": 74,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"] / +\",\n            \"id\": 75,\n            \"spacing\": 6\n        }, {\n            \"comment\": \"backslash / copyright\",\n            \"id\": 76,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"grave diacritic\",\n            \"id\": 77,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"# / &\",\n            \"id\": 78,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"'\",\n            \"id\": 79,\n            \"spacing\": 6\n        }, {\n            \"comment\": \"ring menu arrow: Up\",\n            \"id\": 80,\n            \"spacing\": 13\n        }, {\n            \"comment\": \"ring menu arrow: Down\",\n            \"id\": 81,\n            \"spacing\": 13\n        }, {\n            \"comment\": \"ammo digit: 0\",\n            \"id\": 82,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 1\",\n            \"id\": 83,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 2\",\n            \"id\": 84,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 3\",\n            \"id\": 85,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 4\",\n            \"id\": 86,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 5\",\n            \"id\": 87,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 6\",\n            \"id\": 88,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 7\",\n            \"id\": 89,\n            \"y_offset\": -2,\n            \"y_stretch\": 0.7,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 8\",\n            \"id\": 90,\n            \"y_offset\": -2,\n            \"y_stretch\": 0.7,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo digit: 9\",\n            \"id\": 91,\n            \"y_offset\": -2,\n            \"y_stretch\": 0.7,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"button: Unknown\",\n            \"id\": 92,\n            \"spacing\": 15\n        }, {\n            \"comment\": \"button: Triangle\",\n            \"id\": 93,\n            \"spacing\": 14\n        }, {\n            \"comment\": \"button: Circle\",\n            \"id\": 94,\n            \"spacing\": 14\n        }, {\n            \"comment\": \"button: Cross\",\n            \"id\": 95,\n            \"spacing\": 14\n        }, {\n            \"comment\": \"button: Square\",\n            \"id\": 96,\n            \"spacing\": 14\n        }, {\n            \"comment\": \"button: L1\",\n            \"id\": 97,\n            \"spacing\": 15\n        }, {\n            \"comment\": \"button: R1\",\n            \"id\": 98,\n            \"spacing\": 15\n        }, {\n            \"comment\": \"button: L2\",\n            \"id\": 99,\n            \"spacing\": 15\n        }, {\n            \"comment\": \"button: R2\",\n            \"id\": 100,\n            \"spacing\": 15\n        }, {\n            \"comment\": \"volume icon: Music\",\n            \"id\": 101,\n            \"spacing\": 11\n        }, {\n            \"comment\": \"volume icon: SFX\",\n            \"id\": 102,\n            \"spacing\": 13\n        }, {\n            \"comment\": \"ammo icon: Shotgun\",\n            \"id\": 103,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo icon: Magnum\",\n            \"id\": 104,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"ammo icon: Uzi\",\n            \"id\": 105,\n            \"spacing\": 7\n        }, {\n            \"comment\": \"arrow down\",\n            \"id\": 106,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"arrow up\",\n            \"id\": 107,\n            \"spacing\": 10\n        }, {\n            \"comment\": \"arrow left\",\n            \"id\": 108,\n            \"spacing\": 12\n        }, {\n            \"comment\": \"arrow right\",\n            \"id\": 109,\n            \"spacing\": 12\n        }]\n    }\n}"
  },
  {
    "path": "embedded/BUTTONS.JSON",
    "content": "{\n    \"esc\": {\"u\": 0, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"f1\": {\"u\": 25, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f2\": {\"u\": 44, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f3\": {\"u\": 63, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f4\": {\"u\": 82, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f5\": {\"u\": 101, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f6\": {\"u\": 120, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f7\": {\"u\": 139, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f8\": {\"u\": 158, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f9\": {\"u\": 177, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f10\": {\"u\": 196, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f11\": {\"u\": 215, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n    \"f12\": {\"u\": 234, \"v\": 0, \"x\": 0, \"y\": -15, \"spacing\": 19, \"width\": 19, \"height\": 15},\n\n    \"tab\": {\"u\": 0, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"1\": {\"u\": 32, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"2\": {\"u\": 48, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"3\": {\"u\": 64, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"4\": {\"u\": 80, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"5\": {\"u\": 96, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"6\": {\"u\": 112, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"7\": {\"u\": 128, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"8\": {\"u\": 144, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"9\": {\"u\": 160, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"0\": {\"u\": 176, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"-\": {\"u\": 192, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"=\": {\"u\": 208, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"backspace\": {\"u\": 224, \"v\": 16, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n\n    \"capslock\": {\"u\": 0, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"q\": {\"u\": 32, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"w\": {\"u\": 48, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"e\": {\"u\": 64, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"r\": {\"u\": 80, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"t\": {\"u\": 96, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"y\": {\"u\": 112, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"u\": {\"u\": 128, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"i\": {\"u\": 144, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"o\": {\"u\": 160, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"p\": {\"u\": 176, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"[\": {\"u\": 192, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"]\": {\"u\": 208, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"return\": {\"u\": 224, \"v\": 32, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n\n    \"ctrl\": {\"u\": 0, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"a\": {\"u\": 32, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"s\": {\"u\": 48, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"d\": {\"u\": 64, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"f\": {\"u\": 80, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"g\": {\"u\": 96, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"h\": {\"u\": 112, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"j\": {\"u\": 128, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"k\": {\"u\": 144, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"l\": {\"u\": 160, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \";\": {\"u\": 176, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"'\": {\"u\": 192, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"`\": {\"u\": 208, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"shift\": {\"u\": 224, \"v\": 48, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n\n    \"alt\": {\"u\": 0, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"\\\\\": {\"u\": 32, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"z\": {\"u\": 48, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"x\": {\"u\": 64, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"c\": {\"u\": 80, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"v\": {\"u\": 96, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"b\": {\"u\": 112, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"n\": {\"u\": 128, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"m\": {\"u\": 144, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \",\": {\"u\": 160, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \".\": {\"u\": 176, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"/\": {\"u\": 192, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"<\": {\"u\": 208, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"space\": {\"u\": 224, \"v\": 64, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n\n    \"printscreen\": {\"u\": 0, \"v\": 96, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"scrolllock\": {\"u\": 32, \"v\": 96, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pause\": {\"u\": 64, \"v\": 96, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"insert\": {\"u\": 0, \"v\": 112, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"home\": {\"u\": 32, \"v\": 112, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pageup\": {\"u\": 64, \"v\": 112, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"delete\": {\"u\": 0, \"v\": 128, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"end\": {\"u\": 32, \"v\": 128, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pagedown\": {\"u\": 64, \"v\": 128, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"left\": {\"u\": 0, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"right\": {\"u\": 16, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"up\": {\"u\": 32, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"down\": {\"u\": 48, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 15, \"width\": 15, \"height\": 15},\n    \"numlock\": {\"u\": 64, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n\n    \"pad7\": {\"u\": 128, \"v\": 96, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad8\": {\"u\": 160, \"v\": 96, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad9\": {\"u\": 192, \"v\": 96, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad/\": {\"u\": 224, \"v\": 96, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad4\": {\"u\": 128, \"v\": 112, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad5\": {\"u\": 160, \"v\": 112, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad6\": {\"u\": 192, \"v\": 112, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad*\": {\"u\": 224, \"v\": 112, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad1\": {\"u\": 128, \"v\": 128, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad2\": {\"u\": 160, \"v\": 128, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad3\": {\"u\": 192, \"v\": 128, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad-\": {\"u\": 224, \"v\": 128, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad0\": {\"u\": 128, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad.\": {\"u\": 160, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"enter\": {\"u\": 192, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n    \"pad+\": {\"u\": 224, \"v\": 144, \"x\": 0, \"y\": -15, \"spacing\": 25, \"width\": 25, \"height\": 15},\n\n    \"di1\": {\"u\": 0, \"v\": 160, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"di2\": {\"u\": 32, \"v\": 160, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"di3\": {\"u\": 64, \"v\": 160, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"di4\": {\"u\": 96, \"v\": 160, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"di5\": {\"u\": 128, \"v\": 160, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di6\": {\"u\": 160, \"v\": 160, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di7\": {\"u\": 192, \"v\": 160, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di8\": {\"u\": 224, \"v\": 160, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di9\": {\"u\": 0, \"v\": 176, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di10\": {\"u\": 32, \"v\": 176, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di11\": {\"u\": 64, \"v\": 176, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di12\": {\"u\": 96, \"v\": 176, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di13\": {\"u\": 128, \"v\": 176, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di14\": {\"u\": 160, \"v\": 176, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di15\": {\"u\": 192, \"v\": 176, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"di16\": {\"u\": 224, \"v\": 176, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n\n    \"ps1\": {\"u\": 0, \"v\": 192, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"ps2\": {\"u\": 32, \"v\": 192, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"ps3\": {\"u\": 64, \"v\": 192, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"ps4\": {\"u\": 96, \"v\": 192, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"ps5\": {\"u\": 128, \"v\": 192, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps6\": {\"u\": 160, \"v\": 192, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps7\": {\"u\": 192, \"v\": 192, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps8\": {\"u\": 224, \"v\": 192, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps9\": {\"u\": 0, \"v\": 208, \"x\": 0, \"y\": -15, \"spacing\": 26, \"width\": 26, \"height\": 15},\n    \"ps10\": {\"u\": 32, \"v\": 208, \"x\": 0, \"y\": -15, \"spacing\": 26, \"width\": 26, \"height\": 15},\n    \"ps11\": {\"u\": 64, \"v\": 208, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps12\": {\"u\": 96, \"v\": 208, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps13\": {\"u\": 128, \"v\": 208, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps14\": {\"u\": 160, \"v\": 208, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps15\": {\"u\": 192, \"v\": 208, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"ps16\": {\"u\": 224, \"v\": 208, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n\n    \"xi1\": {\"u\": 0, \"v\": 224, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"xi2\": {\"u\": 32, \"v\": 224, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"xi3\": {\"u\": 64, \"v\": 224, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"xi4\": {\"u\": 96, \"v\": 224, \"x\": 0, \"y\": -15, \"spacing\": 17, \"width\": 17, \"height\": 15},\n    \"xi5\": {\"u\": 128, \"v\": 224, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"xi6\": {\"u\": 160, \"v\": 224, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"xi7\": {\"u\": 192, \"v\": 224, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"xi8\": {\"u\": 224, \"v\": 224, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"xi9\": {\"u\": 0, \"v\": 240, \"x\": 0, \"y\": -15, \"spacing\": 26, \"width\": 26, \"height\": 15},\n    \"xi10\": {\"u\": 32, \"v\": 240, \"x\": 0, \"y\": -15, \"spacing\": 26, \"width\": 26, \"height\": 15},\n    \"xi11\": {\"u\": 64, \"v\": 240, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"xi12\": {\"u\": 96, \"v\": 240, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"xi13\": {\"u\": 128, \"v\": 240, \"x\": 0, \"y\": -15, \"spacing\": 26, \"width\": 26, \"height\": 15},\n    \"xi14\": {\"u\": 160, \"v\": 240, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"xi15\": {\"u\": 192, \"v\": 240, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15},\n    \"xi16\": {\"u\": 224, \"v\": 240, \"x\": 0, \"y\": -15, \"spacing\": 18, \"width\": 18, \"height\": 15}\n}"
  },
  {
    "path": "game/bear.cpp",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/bear.h\"\n#include \"game/box.h\"\n#include \"game/effects.h\"\n#include \"game/lot.h\"\n#include \"specific/game.h\"\n#include \"global/vars.h\"\n\n#define BEAR_TOUCH (0x2406C)\n\ntypedef enum {\n\tBEAR_STROLL,\n\tBEAR_STOP,\n\tBEAR_WALK,\n\tBEAR_RUN,\n\tBEAR_REAR,\n\tBEAR_ROAR,\n\tBEAR_ATTACK1,\n\tBEAR_ATTACK2,\n\tBEAR_EAT,\n\tBEAR_DEATH\n} BEAR_ANIMS;\n\nstatic const BITE_INFO BearBite = {\n\t0, 96, 335, 14\n};\n\nvoid __cdecl BearControl(__int16 itemID) {\n\tITEM_INFO *item = &Items[itemID];\n\n\tif( item->status == ITEM_INVISIBLE ) {\n\t\tif( !EnableBaddieAI(itemID, FALSE) ) {\n\t\t\treturn;\n\t\t}\n\t\titem->status = ITEM_ACTIVE;\n\t}\n\n\tCREATURE_INFO *bear = (CREATURE_INFO *)item->data;\n\tif( bear == NULL ) return; // NOTE: additional check not presented in the original game\n\n\t__int16 angle = 0;\n\t__int16 head = 0;\n\n\tif( item->hitPoints <= 0 ) {\n\t\tangle = CreatureTurn(item, 1*PHD_DEGREE);\n\t\tswitch ( item->currentAnimState ) {\n\t\t\tcase BEAR_STROLL :\n\t\t\tcase BEAR_RUN :\n\t\t\t\titem->goalAnimState = BEAR_STOP;\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_REAR :\n\t\t\t\tbear->flags = 1;\n\t\t\t\titem->goalAnimState = BEAR_DEATH;\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_STOP :\n\t\t\t\tbear->flags = 0;\n\t\t\t\titem->goalAnimState = BEAR_DEATH;\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_DEATH :\n\t\t\t\tif( bear->flags && CHK_ANY(item->touchBits, BEAR_TOUCH) ) {\n\t\t\t\t\tLaraItem->hitPoints -= 200;\n\t\t\t\t\tLaraItem->hit_status = 1;\n\t\t\t\t\tbear->flags = 0;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_WALK :\n\t\t\t\titem->goalAnimState = BEAR_REAR;\n\t\t\t\tbreak;\n\n\t\t\tdefault :\n\t\t\t\tbreak;\n\t\t}\n\t} else {\n\t\tAI_INFO info;\n\t\tBOOL isLaraDead;\n\n\t\tCreatureAIInfo(item, &info);\n\t\tif( info.ahead ) {\n\t\t\thead = info.angle;\n\t\t}\n\n\t\tCreatureMood(item, &info, TRUE);\n\t\tangle = CreatureTurn(item, bear->maximum_turn);\n\t\tisLaraDead = ( LaraItem->hitPoints < 0 );\n\n\t\tif( item->hit_status ) {\n\t\t\tbear->flags = 1;\n\t\t}\n\n\t\tswitch ( item->currentAnimState ) {\n\t\t\tcase BEAR_STOP :\n\t\t\t\tif( isLaraDead ) {\n\t\t\t\t\tif( info.bite && info.distance < 0x90000 ) {\n\t\t\t\t\t\titem->goalAnimState = BEAR_EAT;\n\t\t\t\t\t} else {\n\t\t\t\t\t\titem->goalAnimState = BEAR_STROLL;\n\t\t\t\t\t}\n\t\t\t\t} else if( item->requiredAnimState != BEAR_STROLL ) {\n\t\t\t\t\titem->goalAnimState = item->requiredAnimState;\n\t\t\t\t} else if( bear->mood != MOOD_BORED ) {\n\t\t\t\t\titem->goalAnimState = BEAR_RUN;\n\t\t\t\t} else {\n\t\t\t\t\titem->goalAnimState = BEAR_STROLL;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_STROLL :\n\t\t\t\tbear->maximum_turn = 2*PHD_DEGREE;\n\t\t\t\tif( isLaraDead && CHK_ANY(item->touchBits, BEAR_TOUCH) && info.ahead ) {\n\t\t\t\t\titem->goalAnimState = BEAR_STOP;\n\t\t\t\t} else if( bear->mood != MOOD_BORED ) {\n\t\t\t\t\titem->goalAnimState = BEAR_STOP;\n\t\t\t\t\tif( bear->mood == MOOD_ESCAPE ) {\n\t\t\t\t\t\titem->requiredAnimState = BEAR_STROLL;\n\t\t\t\t\t}\n\t\t\t\t} else if( GetRandomControl() < 0x50 ) {\n\t\t\t\t\titem->requiredAnimState = BEAR_ROAR;\n\t\t\t\t\titem->goalAnimState = BEAR_STOP;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_RUN :\n\t\t\t\tbear->maximum_turn = 910;\n\t\t\t\tif( CHK_ANY(item->touchBits, BEAR_TOUCH) ) {\n\t\t\t\t\tLaraItem->hitPoints -= 3;\n\t\t\t\t\tLaraItem->hit_status = 1;\n\t\t\t\t}\n\n\t\t\t\tif( bear->mood == MOOD_BORED || isLaraDead ) {\n\t\t\t\t\titem->goalAnimState = BEAR_STOP;\n\t\t\t\t} else if( info.ahead && item->requiredAnimState == BEAR_STROLL ) {\n\t\t\t\t\tif( !bear->flags && info.distance < 0x400000 && GetRandomControl() < 0x300 ) {\n\t\t\t\t\t\titem->requiredAnimState = BEAR_REAR;\n\t\t\t\t\t\titem->goalAnimState = BEAR_STOP;\n\t\t\t\t\t}\n\t\t\t\t\telse if( info.distance < 0x100000 ) {\n\t\t\t\t\t\titem->goalAnimState = BEAR_ATTACK1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_REAR :\n\t\t\t\tif( bear->flags ) {\n\t\t\t\t\titem->requiredAnimState = BEAR_STROLL;\n\t\t\t\t\titem->goalAnimState = BEAR_STOP;\n\t\t\t\t} else if( item->requiredAnimState != BEAR_STROLL ) {\n\t\t\t\t\titem->goalAnimState = item->requiredAnimState;\n\t\t\t\t} else if( bear->mood == MOOD_BORED || bear->mood == MOOD_ESCAPE ) {\n\t\t\t\t\titem->goalAnimState = BEAR_STOP;\n\t\t\t\t} else if( info.bite && info.distance < 360000 ) {\n\t\t\t\t\titem->goalAnimState = BEAR_ATTACK2;\n\t\t\t\t} else {\n\t\t\t\t\titem->goalAnimState = BEAR_WALK;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_WALK :\n\t\t\t\tif( bear->flags ) {\n\t\t\t\t\titem->requiredAnimState = BEAR_STROLL;\n\t\t\t\t\titem->goalAnimState = BEAR_REAR;\n\t\t\t\t} else if( info.ahead && CHK_ANY(item->touchBits, BEAR_TOUCH) ) {\n\t\t\t\t\titem->goalAnimState = BEAR_REAR;\n\t\t\t\t} else if( bear->mood == MOOD_ESCAPE ) {\n\t\t\t\t\titem->goalAnimState = BEAR_REAR;\n\t\t\t\t\titem->requiredAnimState = BEAR_STROLL;\n\t\t\t\t} else if( bear->mood == MOOD_BORED || GetRandomControl() < 0x50 ) {\n\t\t\t\t\titem->requiredAnimState = BEAR_ROAR;\n\t\t\t\t\titem->goalAnimState = BEAR_REAR;\n\t\t\t\t} else if( info.distance > 0x400000 || GetRandomControl() < 0x600 ) {\n\t\t\t\t\titem->requiredAnimState = BEAR_STOP;\n\t\t\t\t\titem->goalAnimState = BEAR_REAR;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_ATTACK2 :\n\t\t\t\tif( item->requiredAnimState == BEAR_STROLL && CHK_ANY(item->touchBits, BEAR_TOUCH) ) {\n\t\t\t\t\tLaraItem->hitPoints -= 400;\n\t\t\t\t\tLaraItem->hit_status = 1;\n\t\t\t\t\titem->requiredAnimState = BEAR_REAR;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase BEAR_ATTACK1 :\n\t\t\t\tif( item->requiredAnimState == BEAR_STROLL && CHK_ANY(item->touchBits, BEAR_TOUCH) )\n\t\t\t\t{\n\t\t\t\t\tCreatureEffect(item, &BearBite, DoBloodSplat);\n\t\t\t\t\tLaraItem->hitPoints -= 200;\n\t\t\t\t\tLaraItem->hit_status = 1;\n\t\t\t\t\titem->requiredAnimState = BEAR_STOP;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tdefault :\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tCreatureHead(item, head);\n\tCreatureAnimation(itemID, angle, 0);\n}\n\n/*\n * NOTE: there is no inject function for tomb2gold code\n */\n"
  },
  {
    "path": "game/bear.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef BEAR_H_INCLUDED\n#define BEAR_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n// NOTE: this function is presented in the \"Golden Mask\" only\nvoid __cdecl BearControl(__int16 itemID); // tomb2gold:0x0040C860\n\n#endif // BEAR_H_INCLUDED\n"
  },
  {
    "path": "game/bird.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/bird.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Bird() {\n//\tINJECT(0x0040C860, InitialiseEagle);\n//\tINJECT(0x0040C8F0, EagleControl);\n}\n"
  },
  {
    "path": "game/bird.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef BIRD_H_INCLUDED\n#define BIRD_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define InitialiseEagle ((void(__cdecl*)(__int16)) 0x0040C860)\n#define EagleControl ((void(__cdecl*)(__int16)) 0x0040C8F0)\n\n#endif // BIRD_H_INCLUDED\n"
  },
  {
    "path": "game/boat.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/boat.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/control.h\"\n#include \"game/items.h\"\n#include \"game/missile.h\"\n#include \"specific/game.h\"\n#include \"specific/output.h\"\n#include \"global/vars.h\"\n\nvoid __cdecl DoWakeEffect(ITEM_INFO *item) {\n\t__int16 frame_number, fxID;\n\tint i;\n\tFX_INFO *fx;\n\n\tPhdMatrixPtr->_23 = 0;\n\tS_CalculateLight(item->pos.x, item->pos.y, item->pos.z, item->roomNumber);\n\tframe_number = Objects[ID_WATER_SPRITE].nMeshes * GetRandomDraw() >> 15;\n\tfor (i = 0; i < 3; ++i) {\n\t\tfxID = CreateEffect(item->roomNumber);\n\t\tif (fxID != -1) {\n\t\t\tfx = &Effects[fxID];\n\t\t\tfx->pos.x = item->pos.x + ((-700 * phd_sin(item->pos.rotY) + 300 * (i - 1) * phd_cos(item->pos.rotY)) >> W2V_SHIFT);\n\t\t\tfx->pos.y = item->pos.y;\n\t\t\tfx->pos.z = item->pos.z + ((-700 * phd_cos(item->pos.rotY) - 300 * (i - 1) * phd_sin(item->pos.rotY)) >> W2V_SHIFT);\n\t\t\tfx->pos.rotY = PHD_90 * (i - 1) + item->pos.rotY;\n\t\t\tfx->room_number = item->roomNumber;\n\t\t\tfx->frame_number = frame_number;\n\t\t\tfx->counter = 20;\n\t\t\tfx->object_number = ID_WATER_SPRITE;\n\t\t\tfx->speed = item->speed >> 2;\n\t\t\tif (item->speed < 64) {\n\t\t\t\tfx->fallspeed = (ABS(item->speed) - 64) * GetRandomDraw() >> 15;\n\t\t\t} else {\n\t\t\t\tfx->fallspeed = 0;\n\t\t\t}\n\t\t\tfx->shade = LsAdder - 768;\n\t\t\tCLAMPL(fx->shade, 0);\n\t\t}\n\t}\n}\n\nvoid __cdecl GondolaControl(__int16 itemID) {\n\tITEM_INFO *item;\n\t__int16 roomID;\n\n\titem = &Items[itemID];\n\tswitch (item->currentAnimState) {\n\t\tcase 1:\n\t\t\tif (item->goalAnimState == 2) {\n\t\t\t\titem->meshBits = 0xFF;\n\t\t\t\tExplodingDeath(itemID, 0xF0, 0);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\titem->pos.y += 50;\n\t\t\troomID = item->roomNumber;\n\t\t\titem->floor = GetHeight(GetFloor(item->pos.x, item->pos.y, item->pos.z, &roomID), item->pos.x, item->pos.y, item->pos.z);\n\t\t\tif (item->pos.y >= item->floor) {\n\t\t\t\titem->goalAnimState = 4;\n\t\t\t\titem->pos.y = item->floor;\n\t\t\t}\n\t\t\tbreak;\n\t}\n\tAnimateItem(item);\n\tif (item->status == ITEM_DISABLED)\n\t\tRemoveActiveItem(itemID);\n}\n\n/*\n * Inject function\n */\nvoid Inject_Boat() {\n//\tINJECT(0x0040CB10, InitialiseBoat);\n//\tINJECT(0x0040CB50, BoatCheckGeton);\n//\tINJECT(0x0040CCC0, BoatCollision);\n//\tINJECT(0x0040CE20, TestWaterHeight);\n//\tINJECT(0x0040CF20, DoBoatShift);\n\n\tINJECT(0x0040D0F0, DoWakeEffect);\n\n//\tINJECT(0x0040D270, DoBoatDynamics);\n//\tINJECT(0x0040D2C0, BoatDynamics);\n//\tINJECT(0x0040D7A0, BoatUserControl);\n//\tINJECT(0x0040D930, BoatAnimation);\n//\tINJECT(0x0040DAA0, BoatControl);\n\n\tINJECT(0x0040E0D0, GondolaControl);\n}\n"
  },
  {
    "path": "game/boat.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef BOAT_H_INCLUDED\n#define BOAT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x0040CB10:\t\tInitialiseBoat\n//\t0x0040CB50:\t\tBoatCheckGeton\n//\t0x0040CCC0:\t\tBoatCollision\n//\t0x0040CE20:\t\tTestWaterHeight\n//\t0x0040CF20:\t\tDoBoatShift\n\nvoid __cdecl DoWakeEffect(ITEM_INFO *item); // 0x0040D0F0\n\n//\t0x0040D270:\t\tDoBoatDynamics\n//\t0x0040D2C0:\t\tBoatDynamics\n//\t0x0040D7A0:\t\tBoatUserControl\n//\t0x0040D930:\t\tBoatAnimation\n//\t0x0040DAA0:\t\tBoatControl\n\nvoid __cdecl GondolaControl(__int16 itemID); // 0x0040E0D0\n\n#endif // BOAT_H_INCLUDED\n"
  },
  {
    "path": "game/box.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/box.h\"\n#include \"game/control.h\"\n#include \"game/items.h\"\n#include \"game/lot.h\"\n#include \"game/missile.h\"\n#include \"global/vars.h\"\n\nvoid __cdecl CreatureDie(__int16 itemID, BOOL explode) {\n\tITEM_INFO *item = &Items[itemID];\n\titem->collidable = 0;\n\titem->hitPoints = HP_DONT_TARGET;\n\n\tif( explode ) {\n\t\tExplodingDeath(itemID, ~0, 0);\n\t\tKillItem(itemID);\n\t} else {\n\t\tRemoveActiveItem(itemID);\n\t}\n\n\tDisableBaddieAI(itemID);\n\titem->flags |= IFL_INVISIBLE;\n\tif( item->clear_body ) {\n\t\titem->nextActive = PrevItemActive;\n\t\tPrevItemActive = itemID;\n\t}\n\n\tITEM_INFO *pickup = NULL;\n\tfor( int i = item->carriedItem; i != -1; i = pickup->carriedItem ) {\n\t\tpickup = &Items[i];\n\t\tpickup->pos.x = item->pos.x;\n\t\tpickup->pos.y = item->pos.y;\n\t\tpickup->pos.z = item->pos.z;\n\t\tItemNewRoom(i, item->roomNumber);\n\t}\n}\n\nvoid __cdecl CreatureKill(ITEM_INFO *item, int killAnim, int killState, int laraKillState) {\n#ifdef FEATURE_CHEAT\n\t// Return Lara to normal state if Dozy cheat enabled\n\tif( Lara.water_status == LWS_Cheat ) {\n\t\tLara.water_status = LWS_AboveWater;\n\t\tLara.mesh_effects = 0;\n\t}\n#endif // FEATURE_CHEAT\n\titem->animNumber = killAnim + Objects[item->objectID].animIndex;\n\titem->frameNumber = Anims[item->animNumber].frameBase;\n\titem->currentAnimState = killState;\n\tLaraItem->animNumber = Objects[ID_LARA_EXTRA].animIndex;\n\tLaraItem->frameNumber = Anims[LaraItem->animNumber].frameBase;\n\tLaraItem->currentAnimState = 0;\n\tLaraItem->goalAnimState = laraKillState;\n\tLaraItem->pos.x = item->pos.x;\n\tLaraItem->pos.y = item->pos.y;\n\tLaraItem->pos.z = item->pos.z;\n\tLaraItem->pos.rotY = item->pos.rotY;\n\tLaraItem->pos.rotX = item->pos.rotX;\n\tLaraItem->pos.rotZ = item->pos.rotZ;\n\tLaraItem->fallSpeed = 0;\n\tLaraItem->gravity = 0;\n\tLaraItem->speed = 0;\n\tif( LaraItem->roomNumber != item->roomNumber ) {\n\t\tItemNewRoom(Lara.item_number, item->roomNumber);\n\t}\n\tAnimateItem(LaraItem);\n\tLaraItem->goalAnimState = laraKillState;\n\tLaraItem->currentAnimState = laraKillState;\n\tLara.extra_anim = 1;\n\tLara.hit_direction = -1;\n\tLara.air = -1;\n\tLara.gun_status = LGS_HandBusy;\n\tLara.gun_type = LGT_Unarmed;\n\tCamera.pos.roomNumber = LaraItem->roomNumber;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Box() {\n//\tINJECT(0x0040E190, InitialiseCreature);\n//\tINJECT(0x0040E1C0, CreatureActive);\n//\tINJECT(0x0040E210, CreatureAIInfo);\n//\tINJECT(0x0040E470, SearchLOT);\n//\tINJECT(0x0040E670, UpdateLOT);\n//\tINJECT(0x0040E6E0, TargetBox);\n//\tINJECT(0x0040E780, StalkBox);\n//\tINJECT(0x0040E880, EscapeBox);\n//\tINJECT(0x0040E930, ValidBox);\n//\tINJECT(0x0040E9E0, CreatureMood);\n//\tINJECT(0x0040EE50, CalculateTarget);\n//\tINJECT(0x0040F2B0, CreatureCreature);\n//\tINJECT(0x0040F3B0, BadFloor);\n\n\tINJECT(0x0040F440, CreatureDie);\n\n//\tINJECT(0x0040F500, CreatureAnimation);\n//\tINJECT(0x0040FDD0, CreatureTurn);\n//\tINJECT(0x0040FEB0, CreatureTilt);\n//\tINJECT(0x0040FEF0, CreatureHead);\n//\tINJECT(0x0040FF40, CreatureNeck);\n//\tINJECT(0x0040FF90, CreatureFloat);\n//\tINJECT(0x00410040, CreatureUnderwater);\n//\tINJECT(0x00410090, CreatureEffect);\n//\tINJECT(0x004100F0, CreatureVault);\n\n\tINJECT(0x00410230, CreatureKill);\n\n//\tINJECT(0x004103A0, GetBaddieTarget);\n}\n"
  },
  {
    "path": "game/box.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef BOX_H_INCLUDED\n#define BOX_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define InitialiseCreature ((void(__cdecl*)(__int16)) 0x0040E190)\n\n//\t0x0040E1C0:\t\tCreatureActive\n\n#define CreatureAIInfo ((void(__cdecl*)(ITEM_INFO *, AI_INFO *)) 0x0040E210)\n\n//\t0x0040E470:\t\tSearchLOT\n//\t0x0040E670:\t\tUpdateLOT\n//\t0x0040E6E0:\t\tTargetBox\n//\t0x0040E780:\t\tStalkBox\n//\t0x0040E880:\t\tEscapeBox\n//\t0x0040E930:\t\tValidBox\n\n#define CreatureMood ((void(__cdecl*)(ITEM_INFO *, AI_INFO *, BOOL)) 0x0040E9E0)\n\n//\t0x0040EE50:\t\tCalculateTarget\n//\t0x0040F2B0:\t\tCreatureCreature\n//\t0x0040F3B0:\t\tBadFloor\n\nvoid __cdecl CreatureDie(__int16 itemID, BOOL explode); // 0x0040F440\n\n#define CreatureAnimation ((int(__cdecl*)(__int16, __int16, __int16)) 0x0040F500)\n#define CreatureTurn ((__int16(__cdecl*)(ITEM_INFO *, __int16)) 0x0040FDD0)\n#define CreatureTilt ((void(__cdecl*)(ITEM_INFO *, __int16)) 0x0040FEB0)\n#define CreatureHead ((void(__cdecl*)(ITEM_INFO *, __int16)) 0x0040FEF0)\n\n//\t0x0040FF40:\t\tCreatureNeck\n//\t0x0040FF90:\t\tCreatureFloat\n//\t0x00410040:\t\tCreatureUnderwater\n\n#define CreatureEffect ((__int16(__cdecl*)(ITEM_INFO *, const BITE_INFO *, __int16(__cdecl*)(int, int, int, __int16, __int16, __int16))) 0x00410090)\n\n//\t0x004100F0:\t\tCreatureVault\n\nvoid __cdecl CreatureKill(ITEM_INFO *item, int killAnim, int killState, int laraKillState); // 0x00410230\n\n//\t0x004103A0:\t\tGetBaddieTarget\n\n#endif // BOX_H_INCLUDED\n"
  },
  {
    "path": "game/camera.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/camera.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/cinema.h\"\n#include \"game/control.h\"\n#include \"game/draw.h\"\n#include \"game/sound.h\"\n#include \"specific/game.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\n#define CAM_DISTANCE (0x600)\n\nvoid __cdecl InitialiseCamera() {\n\tCamera.shift = LaraItem->pos.y - 0x400;\n\tCamera.target.x = LaraItem->pos.x;\n\tCamera.target.y = Camera.shift;\n\tCamera.target.z = LaraItem->pos.z;\n\tCamera.target.roomNumber = LaraItem->roomNumber;\n\n\tCamera.pos.x = Camera.target.x;\n\tCamera.pos.y = Camera.target.y;\n\tCamera.pos.z = Camera.target.z - 100;\n\tCamera.pos.roomNumber = Camera.target.roomNumber;\n\n\tCamera.targetDistance = CAM_DISTANCE;\n\tCamera.item = NULL;\n\tCamera.numberFrames = 1;\n\tif ( !(Lara.extra_anim) ) {\n\t\tCamera.type = CAM_Chase;\n\t}\n\tCamera.speed = 1;\n\tCamera.flags = 0;\n\tCamera.bounce = 0;\n\tCamera.number = -1;\n\tCamera.fixedCamera = 0;\n\tAlterFOV(80 * PHD_DEGREE);\n\tCalculateCamera();\n}\n\nvoid __cdecl MoveCamera(GAME_VECTOR *destination, int speed) {\n\tCamera.pos.x += (destination->x - Camera.pos.x) / speed;\n\tCamera.pos.z += (destination->z - Camera.pos.z) / speed;\n\tCamera.pos.y += (destination->y - Camera.pos.y) / speed;\n\tCamera.pos.roomNumber = destination->roomNumber;\n\n\tIsChunkyCamera = FALSE;\n\tFLOOR_INFO *floor = GetFloor(Camera.pos.x, Camera.pos.y, Camera.pos.z, &Camera.pos.roomNumber);\n\n\tint height = GetHeight(floor, Camera.pos.x, Camera.pos.y, Camera.pos.z) - 0x100;\n\tif( Camera.pos.y >= height && destination->y >= height ) {\n\t\tLOS(&Camera.target, &Camera.pos);\n\t\tfloor = GetFloor(Camera.pos.x, Camera.pos.y, Camera.pos.z, &Camera.pos.roomNumber);\n\t\theight = GetHeight(floor, Camera.pos.x, Camera.pos.y, Camera.pos.z) - 0x100;\n\t}\n\n\tint ceiling = GetCeiling(floor, Camera.pos.x, Camera.pos.y, Camera.pos.z) + 0x100;\n\tif( height < ceiling ) {\n\t\theight = ceiling = (height + ceiling) / 2;\n\t}\n\n\tif( Camera.bounce ) {\n\t\tint shake;\n#ifdef FEATURE_INPUT_IMPROVED\n\t\tshake = 0xFFFF*(UINT64)(ABS(Camera.bounce)+50)/250;\n\t\tJoyRumble(shake, shake, 6, shake/6, 12, true);\n#endif // FEATURE_INPUT_IMPROVED\n\t\tif( Camera.bounce > 0 ) {\n\t\t\tCamera.pos.y += Camera.bounce;\n\t\t\tCamera.target.y += Camera.bounce;\n\t\t\tCamera.bounce = 0;\n\t\t} else {\n\t\t\tshake = Camera.bounce * (GetRandomControl() - 0x4000) / 0x7FFF;\n\t\t\tCamera.pos.x += shake;\n\t\t\tCamera.target.y += shake;\n\t\t\tshake = Camera.bounce * (GetRandomControl() - 0x4000) / 0x7FFF;\n\t\t\tCamera.pos.y += shake;\n\t\t\tCamera.target.y += shake;\n\t\t\tshake = Camera.bounce * (GetRandomControl() - 0x4000);\n\t\t\tCamera.pos.z += shake / 0x7FFF;\n\t\t\tCamera.target.z += shake / 0x7FFF;\n\t\t\tCamera.bounce += 5;\n\t\t}\n\t}\n\n\tif( Camera.pos.y <= height ) {\n\t\tif ( Camera.pos.y >= ceiling ) {\n\t\t\tCamera.shift = 0;\n\t\t} else {\n\t\t\tCamera.shift = ceiling - Camera.pos.y;\n\t\t}\n\t} else {\n\t\tCamera.shift = height - Camera.pos.y;\n\t}\n\n\tGetFloor(Camera.pos.x, Camera.shift + Camera.pos.y, Camera.pos.z, &Camera.pos.roomNumber);\n\tphd_LookAt(Camera.pos.x, Camera.pos.y + Camera.shift, Camera.pos.z,\n\t\t\t\tCamera.target.x, Camera.target.y, Camera.target.z, 0);\n\n\tif( Camera.isLaraMic ) {\n\t\tCamera.actualAngle = Lara.torso_y_rot + Lara.head_y_rot + LaraItem->pos.rotY;\n\t\tCamera.micPos.x = LaraItem->pos.x;\n\t\tCamera.micPos.y = LaraItem->pos.y;\n\t\tCamera.micPos.z = LaraItem->pos.z;\n\t} else {\n\t\tCamera.actualAngle = phd_atan(Camera.target.z - Camera.pos.z, Camera.target.x - Camera.pos.x);\n\t\tCamera.micPos.x = Camera.pos.x + ((phd_sin(Camera.actualAngle) * PhdPersp) >> W2V_SHIFT);\n\t\tCamera.micPos.z = Camera.pos.z + ((phd_cos(Camera.actualAngle) * PhdPersp) >> W2V_SHIFT);\n\t\tCamera.micPos.y = Camera.pos.y;\n\t}\n}\n\nvoid __cdecl LookCamera(ITEM_INFO *item) {\n\tint zOld = Camera.target.z;\n\tint xOld = Camera.target.x;\n\tCamera.target.z = item->pos.z;\n\tCamera.target.x = item->pos.x;\n\tCamera.targetAngle = item->pos.rotY + Lara.torso_y_rot + Lara.head_y_rot;\n\tCamera.targetDistance = CAM_DISTANCE;\n\tCamera.targetElevation = item->pos.rotX + Lara.torso_x_rot + Lara.head_x_rot;\n\tCamera.shift = (-0x200 * phd_sin(Camera.targetElevation)) >> W2V_SHIFT;\n\tCamera.target.z += Camera.shift * phd_cos(item->pos.rotY) >> W2V_SHIFT;\n\tCamera.target.x += Camera.shift * phd_sin(item->pos.rotY) >> W2V_SHIFT;\n\n\tif( !GoodPosition(Camera.target.x, Camera.target.y, Camera.target.z, Camera.target.roomNumber) ) {\n\t\tCamera.target.x = item->pos.x;\n\t\tCamera.target.z = item->pos.z;\n\t}\n\tCamera.target.y += ShiftClamp(&Camera.target, 306);\n\n\tGAME_VECTOR goal;\n\tint dist = Camera.targetDistance * phd_cos(Camera.targetElevation) >> W2V_SHIFT;\n\tgoal.x = Camera.target.x - (dist * phd_sin(Camera.targetAngle) >> W2V_SHIFT);\n\tgoal.y = Camera.target.y + (Camera.targetDistance * phd_sin(Camera.targetElevation) >> W2V_SHIFT);\n\tgoal.z = Camera.target.z - (dist * phd_cos(Camera.targetAngle) >> W2V_SHIFT);\n\tgoal.roomNumber = Camera.pos.roomNumber;\n\n\tSmartShift(&goal, ClipCamera);\n\tCamera.target.z = zOld + (Camera.target.z - zOld) / Camera.speed;\n\tCamera.target.x = xOld + (Camera.target.x - xOld) / Camera.speed;\n\tMoveCamera(&goal, Camera.speed);\n}\n\nvoid __cdecl FixedCamera() {\n\tGAME_VECTOR goal;\n\tOBJECT_VECTOR *fixed = &Camera.fixed[Camera.number];\n\tgoal.x = fixed->x;\n\tgoal.y = fixed->y;\n\tgoal.z = fixed->z;\n\tgoal.roomNumber = fixed->data;\n\tif( !LOS(&Camera.target, &goal) ) {\n\t\tShiftClamp(&goal, 0x100);\n\t}\n\tCamera.fixedCamera = 1;\n\tMoveCamera(&goal, Camera.speed);\n\tif( Camera.timer && !--Camera.timer ) {\n\t\tCamera.timer = -1;\n\t}\n}\n\nvoid __cdecl CalculateCamera() {\n\tITEM_INFO *item;\n\t__int16 *bounds;\n\tFLOOR_INFO *floor;\n\tint y, shift, fixedCamera;\n\t__int16 angle, tilt, rot;\n\n\tif( CHK_ANY(RoomInfo[Camera.pos.roomNumber].flags, ROOM_UNDERWATER) ) {\n\t\tPlaySoundEffect(60, 0, SFX_ALWAYS);\n\t\tif( !Camera.underwater ) {\n#ifdef FEATURE_AUDIO_IMPROVED\n\t\t\textern double UnderwaterMusicMute;\n\t\t\tdouble volume = (1.0 - UnderwaterMusicMute) * (double)(MusicVolume * 25 + 5);\n\t\t\tif( MusicVolume > 0 && volume >= 1.0 ) {\n\t\t\t\tS_CDVolume((DWORD)volume);\n\t\t\t} else {\n\t\t\t\tS_CDVolume(0);\n\t\t\t}\n#else // FEATURE_AUDIO_IMPROVED\n\t\t\tS_CDVolume(0); // NOTE: Core supposed to pause CD Audio this way\n#endif // FEATURE_AUDIO_IMPROVED\n\t\t\tCamera.underwater = 1;\n\t\t}\n\t} else if ( Camera.underwater ) {\n\t\tif( MusicVolume ) {\n\t\t\tS_CDVolume(MusicVolume * 25 + 5);\n\t\t}\n\t\tCamera.underwater = 0;\n\t}\n\tif( Camera.type == CAM_Cinematic ) {\n\t\tInGameCinematicCamera();\n\t\treturn;\n\t}\n\n\tif( Camera.flags != CFL_NoChunky ) {\n\t\tIsChunkyCamera = 1;\n\t}\n\n\tfixedCamera = (Camera.item && (Camera.type == CAM_Fixed || Camera.type == CAM_Heavy)) ? 1 : 0;\n\titem = fixedCamera ? Camera.item : LaraItem;\n\tbounds = GetBoundsAccurate(item);\n\ty = item->pos.y;\n\tif( fixedCamera ) {\n\t\ty += (bounds[2] + bounds[3]) / 2;\n\t} else {\n\t\ty += bounds[3] + (bounds[2] - bounds[3]) * 3 / 4;\n\t}\n\n\tif( Camera.item && !fixedCamera ) {\n\t\tshift = phd_sqrt(SQR(Camera.item->pos.x - item->pos.x) + SQR(Camera.item->pos.z - item->pos.z));\n\t\tangle = phd_atan(Camera.item->pos.z - item->pos.z, Camera.item->pos.x - item->pos.x) - item->pos.rotY;\n\t\tbounds = GetBoundsAccurate(Camera.item);\n\t\ttilt = phd_atan(shift, y - Camera.item->pos.y - (bounds[2] + bounds[3]) / 2);\n\t\tangle /= 2;\n\t\ttilt  /= 2;\n\t\tif( angle > -50*PHD_DEGREE && angle < 50*PHD_DEGREE && tilt > -85*PHD_DEGREE && tilt < 85*PHD_DEGREE ) {\n\t\t\trot = angle - Lara.head_y_rot;\n\t\t\tCLAMP(rot, -4*PHD_DEGREE, 4*PHD_DEGREE);\n\t\t\tLara.head_y_rot += rot;\n\t\t\tLara.torso_y_rot += rot;\n\t\t\trot = tilt - Lara.head_x_rot;\n\t\t\tCLAMP(rot, -4*PHD_DEGREE, 4*PHD_DEGREE);\n\t\t\tLara.head_x_rot += rot;\n\t\t\tLara.torso_x_rot += rot;\n\t\t\tCamera.type = CAM_Look;\n\t\t\tCamera.item->looked_at = 1;\n\t\t}\n\t}\n\n\tif( Camera.type == CAM_Look || Camera.type == CAM_Combat ) {\n\t\ty -= 0x100;\n\t\tCamera.target.roomNumber = item->roomNumber;\n\t\tif( Camera.fixedCamera ) {\n\t\t\tCamera.target.y = y;\n\t\t\tCamera.speed = 1;\n\t\t} else {\n\t\t\tCamera.target.y += (y - Camera.target.y) / 4;\n\t\t\tCamera.speed = (Camera.type != CAM_Look) ? 8 : 4;\n\t\t}\n\t\tCamera.fixedCamera = 0;\n\t\tif ( Camera.type == CAM_Look ) {\n\t\t\tLookCamera(item);\n\t\t} else {\n\t\t\tCombatCamera(item);\n\t\t}\n\t} else {\n\t\tCamera.target.x = item->pos.x;\n\t\tCamera.target.z = item->pos.z;\n\t\tif( Camera.flags == CFL_FollowCenter ) {\n\t\t\tshift = (bounds[4] + bounds[5]) / 2;\n\t\t\tCamera.target.z += shift * phd_cos(item->pos.rotY) >> W2V_SHIFT;\n\t\t\tCamera.target.x += shift * phd_sin(item->pos.rotY) >> W2V_SHIFT;\n\t\t}\n\t\tCamera.target.roomNumber = item->roomNumber;\n\t\tif ( Camera.fixedCamera == fixedCamera ) {\n\t\t\tCamera.fixedCamera = 0;\n\t\t\tCamera.target.y += (y - Camera.target.y) / 4;\n\t\t} else {\n\t\t\tCamera.target.y = y;\n\t\t\tCamera.fixedCamera = 1;\n\t\t\tCamera.speed = 1;\n\t\t}\n\t\tfloor = GetFloor(Camera.target.x, Camera.target.y, Camera.target.z, &Camera.target.roomNumber);\n\t\tif( Camera.target.y > GetHeight(floor, Camera.target.x, Camera.target.y, Camera.target.z) ) {\n\t\t\tIsChunkyCamera = 0;\n\t\t}\n\t\tif( Camera.type == CAM_Chase || Camera.flags == CFL_ChaseObject ) {\n\t\t\tChaseCamera(item);\n\t\t} else {\n\t\t\tFixedCamera();\n\t\t}\n\t}\n\n\tCamera.last = Camera.number;\n\tCamera.fixedCamera = fixedCamera;\n\tif( Camera.type != CAM_Heavy || Camera.timer == -1 ) {\n\t\tCamera.type = CAM_Chase;\n\t\tCamera.speed = 10;\n\t\tCamera.number = -1;\n\t\tCamera.last_item = Camera.item;\n\t\tCamera.item = NULL;\n\t\tCamera.targetElevation = 0;\n\t\tCamera.targetAngle = 0;\n\t\tCamera.targetDistance = CAM_DISTANCE;\n\t\tCamera.flags = CFL_None;\n\t}\n\tIsChunkyCamera = 0;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Camera() {\n\tINJECT(0x00410580, InitialiseCamera);\n\tINJECT(0x00410630, MoveCamera);\n\n//\tINJECT(0x004109B0, ClipCamera);\n//\tINJECT(0x00410A90, ShiftCamera);\n//\tINJECT(0x00410BF0, BadPosition);\n//\tINJECT(0x00410C40, SmartShift);\n//\tINJECT(0x004113D0, ChaseCamera);\n//\tINJECT(0x004114C0, ShiftClamp);\n//\tINJECT(0x00411660, CombatCamera);\n\n\tINJECT(0x004117F0, LookCamera);\n\tINJECT(0x004119E0, FixedCamera);\n\tINJECT(0x00411A80, CalculateCamera);\n}\n"
  },
  {
    "path": "game/camera.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef CAMERA_H_INCLUDED\n#define CAMERA_H_INCLUDED\n\n#include \"global/types.h\"\n\ntypedef void(__cdecl *CB_SMARTCAM)(int*, int*, int*, int, int, int, int, int, int, int);\n\n/*\n * Function list\n */\nvoid __cdecl InitialiseCamera(); // 0x00410580\nvoid __cdecl MoveCamera(GAME_VECTOR *destination, int speed); // 0x00410630\n\n#define ClipCamera ((void(__cdecl*)(int*, int*, int*, int, int, int, int, int, int, int)) 0x004109B0)\n#define ShiftCamera ((void(__cdecl*)(int*, int*, int*, int, int, int, int, int, int, int)) 0x00410A90)\n#define GoodPosition ((FLOOR_INFO*(__cdecl*)(int, int, int, __int16)) 0x00410BF0)\n#define SmartShift ((void(__cdecl*)(GAME_VECTOR*, CB_SMARTCAM)) 0x00410C40)\n#define ChaseCamera ((void(__cdecl*)(ITEM_INFO*)) 0x004113D0)\n#define ShiftClamp ((int(__cdecl*)(GAME_VECTOR*, int)) 0x004114C0)\n#define CombatCamera ((void(__cdecl*)(ITEM_INFO*)) 0x00411660)\n\nvoid __cdecl LookCamera(ITEM_INFO *item); // 0x004117F0\nvoid __cdecl FixedCamera(); // 0x004119E0\nvoid __cdecl CalculateCamera(); // 0x00411A80\n\n#endif // CAMERA_H_INCLUDED\n"
  },
  {
    "path": "game/cinema.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/cinema.h\"\n#include \"game/draw.h\"\n#include \"game/hair.h\"\n#include \"game/setup.h\"\n#include \"specific/frontend.h\"\n#include \"specific/input.h\"\n#include \"specific/output.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\nvoid __cdecl SetCutsceneTrack(int track) {\n\tCineTrackID = track;\n}\n\nint __cdecl StartCinematic(int levelID) {\n\tint result;\n\tBOOL soundWasActive;\n\tint nTicks;\n\n\tCineLevelID = levelID;\n\tIsTitleLoaded = FALSE;\n\tS_FadeToBlack();\n\n\tif( !InitialiseLevel(levelID, GFL_CUTSCENE) ) {\n\t\treturn 2;\n\t}\n\n\tInitCinematicRooms();\n\tInitialisePlayer1(Lara.item_number);\n\tCamera.targetAngle = CineTargetAngle;\n\n\tsoundWasActive = SoundIsActive;\n\tSoundIsActive = FALSE;\n\n\tCineFrameIdx = 0;\n\tS_ClearScreen();\n\n\tif( !StartSyncedAudio(CineTrackID) ) {\n\t\treturn 1;\n\t}\n\n\tS_CDVolume(255);\n\tCineCurrentFrame = 0;\n\n\tdo {\n\t\tDrawPhaseCinematic();\n\t\tnTicks = CineCurrentFrame - TICKS_PER_FRAME * (CineFrameIdx - 4);\n\t\tif( nTicks < TICKS_PER_FRAME ) {\n\t\t\tnTicks = TICKS_PER_FRAME;\n\t\t}\n\t\tresult = DoCinematic(nTicks);\n\t} while( !result );\n\n\tS_CDVolume((MusicVolume > 0) ? (25 * MusicVolume + 5) : 0);\n\tS_CDStop();\n\tSoundIsActive = soundWasActive;\n\tS_SoundStopAllSamples();\n\n\tIsLevelComplete = TRUE;\n\treturn result;\n}\n\nvoid __cdecl InitCinematicRooms() {\n\tfor( int i=0; i<RoomCount; ++i ) {\n\t\tif( RoomInfo[i].flippedRoom >= 0 ) {\n\t\t\tRoomInfo[RoomInfo[i].flippedRoom].boundActive = 1;\n\t\t}\n\t\tRoomInfo[i].flags |= ROOM_OUTSIDE;\n\t}\n\tDrawRoomsCount = 0;\n\tfor( int i=0; i<RoomCount; ++i ) {\n\t\tif( !RoomInfo[i].boundActive ) {\n\t\t\tDrawRoomsArray[DrawRoomsCount++] = i;\n\t\t}\n\t}\n}\n\nint __cdecl DoCinematic(int nTicks) {\n\tstatic int tickCount = 0;\n\tint id = -1;\n\tint next = -1;\n\n\tfor( tickCount += CineTickRate*nTicks; tickCount >= 0; tickCount -= PHD_ONE ) {\n\t\tif( S_UpdateInput() ) {\n\t\t\treturn 3;\n\t\t}\n\t\tif( CHK_ANY(InputStatus, IN_ACTION) ) {\n\t\t\treturn 1;\n\t\t}\n\t\tif( CHK_ANY(InputStatus, IN_OPTION) ) {\n\t\t\treturn 2;\n\t\t}\n\n\t\tDynamicLightCount = 0;\n\n\t\tfor( id = NextItemActive; id >= 0; id = next ) {\n\t\t\tnext = Items[id].nextActive;\n\t\t\tif( Objects[Items[id].objectID].control ) {\n\t\t\t\tObjects[Items[id].objectID].control(id);\n\t\t\t}\n\t\t}\n\n\t\tfor( id = NextEffectActive; id >= 0; id = next ) {\n\t\t\tnext = Effects[id].next_active;\n\t\t\tif( Objects[Effects[id].object_number].control ) {\n\t\t\t\tObjects[Effects[id].object_number].control(id);\n\t\t\t}\n\t\t}\n\n\t\tHairControl(1);\n\t\tCalculateCinematicCamera();\n\n\t\tif( ++CineFrameIdx >= CineFramesCount ) {\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\tCineCurrentFrame = S_CDGetLoc()*4/5;\n#ifdef FEATURE_INPUT_IMPROVED\n\tUpdateJoyOutput(false);\n#endif // FEATURE_INPUT_IMPROVED\n\treturn 0;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Cinema() {\n\tINJECT(0x00411F30, SetCutsceneTrack);\n\tINJECT(0x00411F40, StartCinematic);\n\tINJECT(0x00412060, InitCinematicRooms);\n\tINJECT(0x00412100, DoCinematic);\n\n//\tINJECT(0x00412270, CalculateCinematicCamera);\n//\tINJECT(0x004123B0, GetCinematicRoom);\n//\tINJECT(0x00412430, ControlCinematicPlayer);\n//\tINJECT(0x00412510, LaraControlCinematic);\n//\tINJECT(0x004125B0, InitialisePlayer1);\n//\tINJECT(0x00412640, InitialiseGenPlayer);\n//\tINJECT(0x00412680, InGameCinematicCamera);\n}\n"
  },
  {
    "path": "game/cinema.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef CINEMA_H_INCLUDED\n#define CINEMA_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl SetCutsceneTrack(int track); // 0x00411F30\nint __cdecl StartCinematic(int levelID); // 0x00411F40\nvoid __cdecl InitCinematicRooms(); // 0x00412060\nint __cdecl DoCinematic(int nTicks); // 0x00412100\n\n#define CalculateCinematicCamera ((void(__cdecl*)(void)) 0x00412270)\n#define GetCinematicRoom ((int(__cdecl*)(int, int, int)) 0x004123B0)\n#define ControlCinematicPlayer ((void(__cdecl*)(__int16)) 0x00412430)\n#define LaraControlCinematic ((void(__cdecl*)(__int16)) 0x00412510)\n#define InitialisePlayer1 ((void(__cdecl*)(__int16)) 0x004125B0)\n#define InitialiseGenPlayer ((void(__cdecl*)(__int16)) 0x00412640)\n#define InGameCinematicCamera ((void(__cdecl*)(void)) 0x00412680)\n\n#endif // CINEMA_H_INCLUDED\n"
  },
  {
    "path": "game/collide.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/collide.h\"\n#include \"game/control.h\"\n#include \"global/vars.h\"\n\nint __cdecl CollideStaticObjects(COLL_INFO *coll, int x, int y, int z, __int16 roomID, int hite) {\n\tint rxMin = x - coll->radius;\n\tint rxMax = x + coll->radius;\n\tint ryMin = y - hite;\n\tint ryMax = y;\n\tint rzMin = z - coll->radius;\n\tint rzMax = z + coll->radius;\n\n\tcoll->hitStatic = 0;\n\tGetNearByRooms(x, y, z, coll->radius + 50, hite + 50, roomID);\n\n\t// outer loop\n\tfor( int i = 0; i < DrawRoomsCount; ++i ) {\n\t\tROOM_INFO *room = &RoomInfo[DrawRoomsArray[i]];\n\t\tfor( int j = 0; j < room->numMeshes; ++j ) {\n\t\t\tMESH_INFO *mesh = &room->mesh[j];\n\t\t\tif( CHK_ANY(StaticObjects[mesh->staticNumber].flags, 1) ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tSTATIC_BOUNDS *bounds = &StaticObjects[mesh->staticNumber].collisionBounds;\n\t\t\tint yMin = mesh->y + bounds->yMin;\n\t\t\tint yMax = mesh->y + bounds->yMax;\n\t\t\tint xMin = mesh->x;\n\t\t\tint xMax = mesh->x;\n\t\t\tint zMin = mesh->z;\n\t\t\tint zMax = mesh->z;\n\n\t\t\tswitch( mesh->yRot ) {\n\t\t\t\tcase -PHD_90: // west\n\t\t\t\t\txMin -= bounds->zMax;\n\t\t\t\t\txMax -= bounds->zMin;\n\t\t\t\t\tzMin += bounds->xMin;\n\t\t\t\t\tzMax += bounds->xMax;\n\t\t\t\t\tbreak;\n\t\t\t\tcase -PHD_180: // south\n\t\t\t\t\txMin -= bounds->xMax;\n\t\t\t\t\txMax -= bounds->xMin;\n\t\t\t\t\tzMin -= bounds->zMax;\n\t\t\t\t\tzMax -= bounds->zMin;\n\t\t\t\t\tbreak;\n\t\t\t\tcase PHD_90: // east\n\t\t\t\t\txMin += bounds->zMin;\n\t\t\t\t\txMax += bounds->zMax;\n\t\t\t\t\tzMin -= bounds->xMax;\n\t\t\t\t\tzMax -= bounds->xMin;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault: // north\n\t\t\t\t\txMin += bounds->xMin;\n\t\t\t\t\txMax += bounds->xMax;\n\t\t\t\t\tzMin += bounds->zMin;\n\t\t\t\t\tzMax += bounds->zMax;\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif( rxMax <= xMin || rxMin >= xMax ||\n\t\t\t\tryMax <= yMin || ryMin >= yMax ||\n\t\t\t\trzMax <= zMin || rzMin >= zMax )\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint shift[2];\n\n\t\t\tshift[0] = rxMax - xMin;\n\t\t\tshift[1] = xMax - rxMin;\n\t\t\tint xShift = (shift[0] < shift[1]) ? -shift[0] : shift[1];\n\n\t\t\tshift[0] = rzMax - zMin;\n\t\t\tshift[1] = zMax - rzMin;\n\t\t\tint zShift = (shift[0] < shift[1]) ? -shift[0] : shift[1];\n\n\t\t\tswitch ( coll->quadrant ) {\n\t\t\t\tcase 0: // north\n\t\t\t\t\tif( xShift > coll->radius || xShift < -coll->radius ) {\n\t\t\t\t\t\tcoll->shift.x = coll->old.x - x;\n\t\t\t\t\t\tcoll->shift.z = zShift;\n\t\t\t\t\t\tcoll->collType = COLL_FRONT;\n\t\t\t\t\t} else if( xShift > 0 ) {\n\t\t\t\t\t\tcoll->shift.x = xShift;\n\t\t\t\t\t\tcoll->shift.z = 0;\n\t\t\t\t\t\tcoll->collType = COLL_LEFT;\n\t\t\t\t\t} else if( xShift < 0 ) {\n\t\t\t\t\t\tcoll->shift.x = xShift;\n\t\t\t\t\t\tcoll->shift.z = 0;\n\t\t\t\t\t\tcoll->collType = COLL_RIGHT;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase 1: // east\n\t\t\t\t\tif( zShift > coll->radius || zShift < -coll->radius ) {\n\t\t\t\t\t\tcoll->shift.x = xShift;\n\t\t\t\t\t\tcoll->shift.z = coll->old.z - z;\n\t\t\t\t\t\tcoll->collType = COLL_FRONT;\n\t\t\t\t\t} else if( zShift > 0 ) {\n\t\t\t\t\t\tcoll->shift.x = 0;\n\t\t\t\t\t\tcoll->shift.z = zShift;\n\t\t\t\t\t\tcoll->collType = COLL_RIGHT;\n\t\t\t\t\t} else if( zShift < 0 ) {\n\t\t\t\t\t\tcoll->shift.x = 0;\n\t\t\t\t\t\tcoll->shift.z = zShift;\n\t\t\t\t\t\tcoll->collType = COLL_LEFT;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase 2: // south\n\t\t\t\t\tif( xShift > coll->radius || xShift < -coll->radius ) {\n\t\t\t\t\t\tcoll->shift.x = coll->old.x - x;\n\t\t\t\t\t\tcoll->shift.z = zShift;\n\t\t\t\t\t\tcoll->collType = COLL_FRONT;\n\t\t\t\t\t} else if( xShift > 0 ) {\n\t\t\t\t\t\tcoll->shift.x = xShift;\n\t\t\t\t\t\tcoll->shift.z = 0;\n\t\t\t\t\t\tcoll->collType = COLL_RIGHT;\n\t\t\t\t\t} else if( xShift < 0 )  {\n\t\t\t\t\t\tcoll->shift.x = xShift;\n\t\t\t\t\t\tcoll->shift.z = 0;\n\t\t\t\t\t\tcoll->collType = COLL_LEFT;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase 3: // west\n\t\t\t\t\tif( zShift > coll->radius || zShift < -coll->radius ) {\n\t\t\t\t\t\tcoll->shift.x = xShift;\n\t\t\t\t\t\tcoll->shift.z = coll->old.z - z;\n\t\t\t\t\t\tcoll->collType = COLL_FRONT;\n\t\t\t\t\t} else if( zShift > 0 ) {\n\t\t\t\t\t\tcoll->shift.x = 0;\n\t\t\t\t\t\tcoll->shift.z = zShift;\n\t\t\t\t\t\tcoll->collType = COLL_LEFT;\n\t\t\t\t\t} else if( zShift < 0 ) {\n\t\t\t\t\t\tcoll->shift.x = 0;\n\t\t\t\t\t\tcoll->shift.z = zShift;\n\t\t\t\t\t\tcoll->collType = COLL_RIGHT;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcoll->hitStatic = 1;\n\t\t\treturn 1;\n\t\t}\n\t}\n\treturn 0;\n}\n\nvoid __cdecl GetNearByRooms(int x, int y, int z, int r, int h, __int16 roomID) {\n\tDrawRoomsArray[0] = roomID;\n\tDrawRoomsCount = 1;\n\tGetNewRoom(x + r, y,     z + r, roomID);\n\tGetNewRoom(x - r, y,     z + r, roomID);\n\tGetNewRoom(x + r, y,     z - r, roomID);\n\tGetNewRoom(x - r, y,     z - r, roomID);\n\tGetNewRoom(x + r, y - h, z + r, roomID);\n\tGetNewRoom(x - r, y - h, z + r, roomID);\n\tGetNewRoom(x + r, y - h, z - r, roomID);\n\tGetNewRoom(x - r, y - h, z - r, roomID);\n}\n\nvoid __cdecl GetNewRoom(int x, int y, int z, __int16 roomID) {\n\tGetFloor(x, y, z, &roomID);\n\tfor( int i = 0; i < DrawRoomsCount; ++i ) {\n\t\tif( DrawRoomsArray[i] == roomID ) {\n\t\t\treturn;\n\t\t}\n\t}\n\tDrawRoomsArray[DrawRoomsCount++] = roomID;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Collide() {\n//\tINJECT(0x004128D0, GetCollisionInfo);\n//\tINJECT(0x00412F90, FindGridShift);\n\n\tINJECT(0x00412FC0, CollideStaticObjects);\n\tINJECT(0x004133B0, GetNearByRooms);\n\tINJECT(0x00413480, GetNewRoom);\n\n//\tINJECT(0x004134E0, ShiftItem);\n//\tINJECT(0x00413520, UpdateLaraRoom);\n//\tINJECT(0x00413580, GetTiltType);\n//\tINJECT(0x00413620, LaraBaddieCollision);\n//\tINJECT(0x004137C0, EffectSpaz);\n//\tINJECT(0x00413840, CreatureCollision);\n//\tINJECT(0x004138C0, ObjectCollision);\n//\tINJECT(0x00413920, DoorCollision);\n//\tINJECT(0x004139A0, TrapCollision);\n//\tINJECT(0x00413A10, ItemPushLara);\n//\tINJECT(0x00413D20, TestBoundsCollide);\n//\tINJECT(0x00413DF0, TestLaraPosition);\n//\tINJECT(0x00413F30, AlignLaraPosition);\n//\tINJECT(0x00414070, MoveLaraPosition);\n//\tINJECT(0x00414200, Move3DPosTo3DPos);\n}\n"
  },
  {
    "path": "game/collide.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef COLLIDE_H_INCLUDED\n#define COLLIDE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x004128D0:\t\tGetCollisionInfo\n//\t0x00412F90:\t\tFindGridShift\n\nint __cdecl CollideStaticObjects(COLL_INFO *coll, int x, int y, int z, __int16 roomID, int hite); // 0x00412FC0\nvoid __cdecl GetNearByRooms(int x, int y, int z, int r, int h, __int16 roomID); // 0x004133B0\nvoid __cdecl GetNewRoom(int x, int y, int z, __int16 roomID); // 0x00413480\n\n//\t0x004134E0:\t\tShiftItem\n\n#define UpdateLaraRoom ((void(__cdecl*)(ITEM_INFO*, int)) 0x00413520)\n\n//\t0x00413580:\t\tGetTiltType\n//\t0x00413620:\t\tLaraBaddieCollision\n//\t0x004137C0:\t\tEffectSpaz\n\n#define CreatureCollision ((void(__cdecl*)(__int16, ITEM_INFO *, COLL_INFO *)) 0x00413840)\n#define ObjectCollision ((void(__cdecl*)(__int16, ITEM_INFO *, COLL_INFO *)) 0x004138C0)\n\n//\t0x00413920:\t\tDoorCollision\n//\t0x004139A0:\t\tTrapCollision\n//\t0x00413A10:\t\tItemPushLara\n//\t0x00413D20:\t\tTestBoundsCollide\n//\t0x00413DF0:\t\tTestLaraPosition\n//\t0x00413F30:\t\tAlignLaraPosition\n//\t0x00414070:\t\tMoveLaraPosition\n//\t0x00414200:\t\tMove3DPosTo3DPos\n\n#endif // COLLIDE_H_INCLUDED\n"
  },
  {
    "path": "game/control.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/control.h\"\n#include \"game/camera.h\"\n#include \"game/demo.h\"\n#include \"game/effects.h\"\n#include \"game/hair.h\"\n#include \"game/inventory.h\"\n#include \"game/laramisc.h\"\n#include \"game/savegame.h\"\n#include \"specific/game.h\"\n#include \"specific/input.h\"\n#include \"specific/smain.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/pause.h\"\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\nint __cdecl ControlPhase(int nTicks, BOOL demoMode) {\n\tstatic int tickCount = 0;\n\tint id = -1;\n\tint next = -1;\n\tint result = 0;\n\n\tCLAMPG(nTicks, 5 * TICKS_PER_FRAME);\n\tfor( tickCount += nTicks; tickCount > 0; tickCount -= TICKS_PER_FRAME ) {\n\t\tif( CD_TrackID > 0 ) {\n\t\t\tS_CDLoop();\n\t\t}\n\t\tif( !CHK_ANY(GF_GameFlow.flags, GFF_CheatModeCheckDisabled) ) {\n\t\t\tCheckCheatMode();\n\t\t}\n\t\tif( IsLevelComplete ) {\n\t\t\treturn 1;\n\t\t}\n\t\tS_UpdateInput();\n\t\tif( IsResetFlag ) {\n\t\t\treturn GF_EXIT_TO_TITLE;\n\t\t}\n\t\tif( demoMode ) {\n\t\t\tif( InputStatus ) {\n\t\t\t\treturn GF_GameFlow.onDemo_Interrupt;\n\t\t\t}\n\t\t\tGetDemoInput();\n\t\t\tif( InputStatus == (DWORD)~0 ) {\n\t\t\t\tInputStatus = 0;\n\t\t\t\treturn GF_GameFlow.onDemo_End;\n\t\t\t}\n\t\t} else {\n\t\t\tif( CHK_ANY(GF_GameFlow.flags, GFF_NoInputTimeout) ) {\n\t\t\t\tif( InputStatus ) {\n\t\t\t\t\tNoInputCounter = 0;\n\t\t\t\t} else if( ++NoInputCounter > GF_GameFlow.noInput_Time ) {\n\t\t\t\t\treturn GF_START_DEMO;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif( OverlayStatus == 2 || Lara.death_count > 10*30 || (Lara.death_count > 2*30 && InputStatus) ) {\n\t\t\tif( demoMode ) {\n\t\t\t\treturn GF_GameFlow.onDeath_DemoMode;\n\t\t\t}\n\t\t\tif( CurrentLevel == 0 ) { // Lara's Home\n\t\t\t\treturn GF_EXIT_TO_TITLE;\n\t\t\t}\n\t\t\tif( OverlayStatus == 2 ) {\n\t\t\t\tOverlayStatus = 1;\n\t\t\t\tresult = Display_Inventory(INV_DeathMode);\n\t\t\t\tif( result ) {\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tOverlayStatus = 2;\n\t\t\t}\n\t\t}\n\t\tif( !Lara.death_count && !Lara.extra_anim && (CHK_ANY(InputStatus, IN_OPTION|IN_LOAD|IN_SAVE) || OverlayStatus <= 0) ) {\n\t\t\tif( OverlayStatus > 0 ) {\n\t\t\t\tif( CHK_ANY(GF_GameFlow.flags, GFF_LoadSaveDisabled) ) {\n\t\t\t\t\tOverlayStatus = 0;\n\t\t\t\t} else if( CHK_ANY(InputStatus, IN_LOAD) ) {\n\t\t\t\t\tOverlayStatus = -1;\n\t\t\t\t} else if( CHK_ANY(InputStatus, IN_SAVE) ) {\n\t\t\t\t\tOverlayStatus = -2;\n\t\t\t\t} else {\n\t\t\t\t\tOverlayStatus = 0;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif( OverlayStatus == -1 ) {\n\t\t\t\t\tresult = Display_Inventory(INV_LoadMode);\n\t\t\t\t} else if( OverlayStatus == -2 ) {\n\t\t\t\t\tresult = Display_Inventory(INV_SaveMode);\n\t\t\t\t} else {\n\t\t\t\t\tresult = Display_Inventory(INV_GameMode);\n\t\t\t\t}\n\t\t\t\tOverlayStatus = 1;\n\t\t\t\tif( result ) {\n\t\t\t\t\tif( InventoryExtraData[0] != 1 ) {\n\t\t\t\t\t\treturn result;\n\n\t\t\t\t\t}\n\t\t\t\t\tif( CurrentLevel == 0 ) { // Lara's Home\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t\tCreateSaveGameInfo();\n\t\t\t\t\tS_SaveGame(&SaveGame, sizeof(SaveGame), InventoryExtraData[1]);\n\t\t\t\t\tS_SaveSettings();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t\tif( !Lara.death_count && !Lara.extra_anim && CHK_ANY(InputStatus, IN_PAUSE) && S_Pause() ) {\n\t\t\treturn 1;\n\t\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\t\tDynamicLightCount = 0;\n\n\t\tfor( id = NextItemActive; id >= 0; id = next ) {\n\t\t\tnext = Items[id].nextActive;\n\t\t\t// NOTE: there is no IFL_CLEARBODY check in the original code\n\t\t\tif( Objects[Items[id].objectID].control && !CHK_ANY(Items[id].flags, IFL_CLEARBODY) ) {\n\t\t\t\tObjects[Items[id].objectID].control(id);\n\t\t\t}\n\t\t}\n\n\t\tfor( id = NextEffectActive; id >= 0; id = next ) {\n\t\t\tnext = Effects[id].next_active;\n\t\t\tif( Objects[Effects[id].object_number].control ) {\n\t\t\t\tObjects[Effects[id].object_number].control(id);\n\t\t\t}\n\t\t}\n\n\t\tLaraControl(0);\n\t\tHairControl(0);\n\t\tCalculateCamera();\n\t\tSoundEffects();\n\t\t--HealthBarTimer;\n\n\t\t// Update statistics timer for normal levels\n\t\tif( CurrentLevel != 0 || IsAssaultTimerActive ) {\n\t\t\t++SaveGame.statistics.timer;\n\t\t}\n\t}\n#ifdef FEATURE_INPUT_IMPROVED\n\tUpdateJoyOutput(!IsDemoLevelType);\n#endif // FEATURE_INPUT_IMPROVED\n\treturn 0;\n}\n\nvoid __cdecl TriggerCDTrack(__int16 value, UINT16 flags, __int16 type) {\n\tif( value > 1 && value < 64 ) {\n\t\tTriggerNormalCDTrack(value, flags, type);\n\t}\n}\n\nvoid __cdecl TriggerNormalCDTrack(__int16 value, UINT16 flags, __int16 type) {\n\tif( type != 2 ) {\n\t\tUINT16 codebits = flags & IFL_CODEBITS;\n\t\tif( CHK_ANY(codebits, CD_Flags[value]) ){\n\t\t\treturn;\n\t\t}\n\t\tif( CHK_ANY(flags, IFL_INVISIBLE) ) {\n\t\t\tCD_Flags[value] |= codebits;\n\t\t}\n\t}\n\n\tif( value == CD_TrackID ) {\n\t\tUINT8 timer = CD_Flags[value] & 0xFF;\n\t\tif( timer ) {\n\t\t\tif( !--timer ) {\n\t\t\t\tCD_TrackID = -1;\n\t\t\t\tS_CDPlay(value, FALSE);\n\t\t\t}\n\t\t\tCD_Flags[value] = (CD_Flags[value] & ~0xFF) | timer;\n\t\t}\n\t} else {\n\t\tUINT8 timer = flags & 0xFF;\n\t\tif( timer ) {\n\t\t\tCD_TrackID = value;\n\t\t\tCD_Flags[value] = (CD_Flags[value] & ~0xFF) | ((timer * 30) & 0xFF);\n\t\t} else {\n\t\t\tS_CDPlay(value, FALSE);\n\t\t}\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Control() {\n\tINJECT(0x00414370, ControlPhase);\n//\tINJECT(0x004146C0, AnimateItem);\n//\tINJECT(0x00414A30, GetChange);\n//\tINJECT(0x00414AE0, TranslateItem);\n//\tINJECT(0x00414B40, GetFloor);\n//\tINJECT(0x00414CE0, GetWaterHeight);\n//\tINJECT(0x00414E50, GetHeight);\n//\tINJECT(0x004150D0, RefreshCamera);\n//\tINJECT(0x004151C0, TestTriggers);\n//\tINJECT(0x004158A0, TriggerActive);\n//\tINJECT(0x00415900, GetCeiling);\n//\tINJECT(0x00415B60, GetDoor);\n//\tINJECT(0x00415BB0, LOS);\n//\tINJECT(0x00415C50, zLOS);\n//\tINJECT(0x00415F40, xLOS);\n//\tINJECT(0x00416230, ClipTarget);\n//\tINJECT(0x00416310, ObjectOnLOS);\n//\tINJECT(0x00416610, FlipMap);\n//\tINJECT(0x004166D0, RemoveRoomFlipItems);\n//\tINJECT(0x00416770, AddRoomFlipItems);\n\n\tINJECT(0x004167D0, TriggerCDTrack);\n\tINJECT(0x00416800, TriggerNormalCDTrack);\n}\n"
  },
  {
    "path": "game/control.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef CONTROL_H_INCLUDED\n#define CONTROL_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nint __cdecl ControlPhase(int nTicks, BOOL demoMode);\n\n#define AnimateItem ((void(__cdecl*)(ITEM_INFO*)) 0x004146C0)\n\n// 0x00414A30:\t\tGetChange\n// 0x00414AE0:\t\tTranslateItem\n\n#define GetFloor ((FLOOR_INFO*(__cdecl*)(int, int, int, __int16*)) 0x00414B40)\n#define GetWaterHeight ((int(__cdecl*)(int, int, int, __int16)) 0x00414CE0)\n#define GetHeight ((int(__cdecl*)(FLOOR_INFO*, int, int, int)) 0x00414E50)\n\n// 0x004150D0:\t\tRefreshCamera\n\n#define TestTriggers ((void(__cdecl*)(__int16*, BOOL)) 0x004151C0)\n#define TriggerActive ((int(__cdecl*)(ITEM_INFO*)) 0x004158A0)\n#define GetCeiling ((int(__cdecl*)(FLOOR_INFO*, int, int, int)) 0x00415900)\n\n// 0x00415B60:\t\tGetDoor\n\n#define LOS ((int(__cdecl*)(GAME_VECTOR*, GAME_VECTOR*)) 0x00415BB0)\n\n// 0x00415C50:\t\tzLOS\n// 0x00415F40:\t\txLOS\n// 0x00416230:\t\tClipTarget\n// 0x00416310:\t\tObjectOnLOS\n\n#define FlipMap ((void(__cdecl*)(void)) 0x00416610)\n\n// 0x004166D0:\t\tRemoveRoomFlipItems\n// 0x00416770:\t\tAddRoomFlipItems\n\nvoid __cdecl TriggerCDTrack(__int16 value, UINT16 flags, __int16 type); // 0x004167D0\nvoid __cdecl TriggerNormalCDTrack(__int16 value, UINT16 flags, __int16 type); // 0x00416800;\n\n#endif // CONTROL_H_INCLUDED\n"
  },
  {
    "path": "game/demo.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/demo.h\"\n#include \"game/laramisc.h\"\n#include \"game/setup.h\"\n#include \"game/text.h\"\n#include \"specific/frontend.h\"\n#include \"specific/game.h\"\n#include \"specific/winmain.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_HUD_IMPROVED\nextern bool PsxBarPosEnabled;\nDWORD DemoTextMode = 0;\n#endif // FEATURE_HUD_IMPROVED\n\nint __cdecl StartDemo(int levelID) {\n\tstatic int DemoLevelID = 0;\n\n\tif( levelID < 0 && !GF_GameFlow.num_Demos ) {\n\t\treturn GF_EXIT_TO_TITLE;\n\t}\n\n\tif( levelID < 0 ) {\n\t\tif( DemoLevelID >= GF_GameFlow.num_Demos ) {\n\t\t\tDemoLevelID = 0;\n\t\t}\n\t\tlevelID = GF_DemoLevels[DemoLevelID++];\n\t} else {\n\t\tDemoLevelID = levelID;\n\t}\n\n\tSTART_INFO *start = &SaveGame.start[levelID];\n\tSTART_INFO startBackup = *start;\n\tstart->available = 1;\n\tstart->pistolAmmo = 1000;\n\tstart->gunStatus = LGS_Armless;\n\tstart->gunType = LGT_Pistols;\n\tSeedRandomDraw(RANDOM_SEED);\n\tSeedRandomControl(RANDOM_SEED);\n\tIsTitleLoaded = FALSE;\n\n\tif( !InitialiseLevel(levelID, GFL_DEMO) ) {\n\t\treturn GF_EXIT_GAME;\n\t}\n\n\tIsLevelComplete = FALSE;\n\n\tif( !IsDemoLoaded ) {\n\t\tchar str[64];\n\t\tsprintf(str, \"Level '%s' has no demo data!\", GF_LevelFilesStringTable[levelID]);\n\t\tS_ExitSystem(str);\n\t}\n\n\tLoadLaraDemoPos();\n\tLaraCheatGetStuff();\n\tSeedRandomDraw(RANDOM_SEED);\n\tSeedRandomControl(RANDOM_SEED);\n\n#ifdef FEATURE_HUD_IMPROVED\n\tTEXT_STR_INFO *bottomText = NULL;\n\tTEXT_STR_INFO *topText = NULL;\n\tif( DemoTextMode == 1 ) {\n\t\tbottomText = T_Print(0, -16, 0, GF_SpecificStringTable[SSI_DemoMode]);\n\t} else if( DemoTextMode == 2 ) {\n\t\tbottomText = T_Print(0, -16, 0, \"Press any button to quit\");\n\t\ttopText = T_Print(16, PsxBarPosEnabled ? 26 : 32, 0, \"DEMO MODE\");\n\t}\n#else // FEATURE_HUD_IMPROVED\n\t// NOTE: here was the bug in the original game, wrong y coordinate and wrong align\n\tTEXT_STR_INFO *bottomText = T_Print(0, -16, 0, GF_SpecificStringTable[SSI_DemoMode]);\n#endif // FEATURE_HUD_IMPROVED\n\tT_FlashText(bottomText, 1, 20);\n\tT_BottomAlign(bottomText, 1);\n\tT_CentreH(bottomText, 1);\n\n\tInvDemoMode = TRUE;\n\tint result = GameLoop(1);\n\tInvDemoMode = FALSE;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tT_RemovePrint(topText);\n#endif // FEATURE_HUD_IMPROVED\n\tT_RemovePrint(bottomText);\n\tS_FadeToBlack();\n\n\t*start = startBackup;\n\treturn result;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Demo() {\n//\tINJECT(0x004168E0, DoDemoSequence);\n\n\tINJECT(0x00416940, StartDemo);\n\n//\tINJECT(0x00416AF0, LoadLaraDemoPos);\n//\tINJECT(0x00416BC0, GetDemoInput);\n}\n"
  },
  {
    "path": "game/demo.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef DEMO_H_INCLUDED\n#define DEMO_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define DoDemoSequence ((int(__cdecl*)(int)) 0x004168E0)\n\nint __cdecl StartDemo(int levelID); // 0x00416940\n\n#define LoadLaraDemoPos ((void(__cdecl*)(void)) 0x00416AF0)\n#define GetDemoInput ((void(__cdecl*)(void)) 0x00416BC0)\n\n#endif // DEMO_H_INCLUDED\n"
  },
  {
    "path": "game/diver.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/diver.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Diver() {\n//\tINJECT(0x00416BF0, Harpoon);\n//\tINJECT(0x00416C70, GetWaterSurface);\n//\tINJECT(0x00416D80, DiverControl);\n}\n"
  },
  {
    "path": "game/diver.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef DIVER_H_INCLUDED\n#define DIVER_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x00416BF0:\t\tHarpoon\n//\t0x00416C70:\t\tGetWaterSurface\n\n#define DiverControl ((void(__cdecl*)(__int16)) 0x00416D80)\n\n#endif // DIVER_H_INCLUDED\n"
  },
  {
    "path": "game/dog.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/dog.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Dog() {\n//\tINJECT(0x00417130, DogControl);\n//\tINJECT(0x004174E0, TigerControl);\n}\n"
  },
  {
    "path": "game/dog.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef DOG_H_INCLUDED\n#define DOG_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define DogControl ((void(__cdecl*)(__int16)) 0x00417130)\n#define TigerControl ((void(__cdecl*)(__int16)) 0x004174E0)\n\n#endif // DOG_H_INCLUDED\n"
  },
  {
    "path": "game/dragon.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/dragon.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Dragon() {\n//\tINJECT(0x00417780, ControlTwinkle);\n//\tINJECT(0x00417900, CreateBartoliLight);\n//\tINJECT(0x004179E0, DragonFire);\n//\tINJECT(0x00417A90, DragonCollision);\n//\tINJECT(0x00417D80, DragonBones);\n//\tINJECT(0x00417E60, DragonControl);\n//\tINJECT(0x004183B0, InitialiseBartoli);\n//\tINJECT(0x004184D0, BartoliControl);\n//\tINJECT(0x00418670, DinoControl);\n}\n"
  },
  {
    "path": "game/dragon.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef DRAGON_H_INCLUDED\n#define DRAGON_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x00417780:\t\tControlTwinkle\n//\t0x00417900:\t\tCreateBartoliLight\n//\t0x004179E0:\t\tDragonFire\n\n#define DragonCollision ((void(__cdecl*)(__int16, ITEM_INFO *, COLL_INFO *)) 0x00417A90)\n#define DragonBones ((void(__cdecl*)(__int16)) 0x00417D80)\n#define DragonControl ((void(__cdecl*)(__int16)) 0x00417E60)\n#define InitialiseBartoli ((void(__cdecl*)(__int16)) 0x004183B0)\n#define BartoliControl ((void(__cdecl*)(__int16)) 0x004184D0)\n#define DinoControl ((void(__cdecl*)(__int16)) 0x00418670)\n\n#endif // DRAGON_H_INCLUDED\n"
  },
  {
    "path": "game/draw.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/draw.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"3dsystem/scalespr.h\"\n#include \"game/hair.h\"\n#include \"specific/game.h\"\n#include \"specific/output.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_EXTENDED_LIMITS\nLIGHT_INFO DynamicLights[64];\nint BoundRooms[1024];\n__int16 DrawRoomsArray[1024];\nSTATIC_INFO StaticObjects[256];\n#endif // FEATURE_EXTENDED_LIMITS\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nextern DWORD AlphaBlendMode;\nstatic int GoldenLaraAlpha = 0;\n\nvoid ResetGoldenLaraAlpha() {\n\tGoldenLaraAlpha = ( Lara.water_status == LWS_Cheat ) ? 0xFF : 0;\n}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\nvoid __cdecl DrawRooms(__int16 currentRoom) {\n\tROOM_INFO *room = &RoomInfo[currentRoom];\n\n\tPhdWinLeft = room->left = 0;\n\tPhdWinTop = room->top = 0;\n\tPhdWinRight = room->right = PhdWinMaxX;\n\tPhdWinBottom = room->bottom = PhdWinMaxY;\n\n\troom->boundActive = 2;\n\tBoundRooms[0] = currentRoom;\n\tBoundStart = 0;\n\tBoundEnd = 1;\n\tDrawRoomsCount = 0;\n\tOutsideCamera = room->flags & ROOM_OUTSIDE;\n\n\tif( OutsideCamera ) {\n\t\tOutsideLeft = 0;\n\t\tOutsideTop = 0;\n\t\tOutsideRight = PhdWinMaxX;\n\t\tOutsideBottom = PhdWinMaxY;\n\t} else {\n\t\tOutsideLeft = PhdWinMaxX;\n\t\tOutsideTop = PhdWinMaxY;\n\t\tOutsideRight = 0;\n\t\tOutsideBottom = 0;\n\t}\n\n\tUnderwaterCamera = room->flags & ROOM_UNDERWATER;\n\tGetRoomBounds();\n\tMidSort = 0;\n\n\tif( OutsideCamera ) {\n\t\tPhdWinLeft = OutsideLeft;\n\t\tPhdWinRight = OutsideRight;\n\t\tPhdWinBottom = OutsideBottom;\n\t\tPhdWinTop = OutsideTop;\n\t\tif( Objects[ID_SKYBOX].loaded ) {\n\t\t\t// Draw skybox background\n\t\t\tS_SetupAboveWater(UnderwaterCamera);\n\t\t\tphd_PushMatrix();\n\t\t\tPhdMatrixPtr->_03 = PhdMatrixPtr->_13 = PhdMatrixPtr->_23 = 0;\n\n\t\t\tUINT16 *ptr = (UINT16 *)&Anims[Objects[ID_SKYBOX].animIndex].framePtr[9];\n\t\t\tphd_RotYXZsuperpack(&ptr, 0);\n#ifdef FEATURE_VIEW_IMPROVED\n\t\t\tS_InitialisePolyList(1); // Fill backbuffer with black\n#else // !FEATURE_VIEW_IMPROVED\n\t\t\tS_InitialisePolyList(0); // Leave backbuffer uncleaned\n#endif // FEATURE_VIEW_IMPROVED\n\t\t\tS_InsertBackground(MeshPtr[Objects[ID_SKYBOX].meshIndex]);\n\t\t\tphd_PopMatrix();\n\t\t} else {\n\t\t\tS_InitialisePolyList(1); // Fill backbuffer with black\n\t\t\tOutsideCamera = -1;\n\t\t}\n\t} else {\n#ifdef FEATURE_VIEW_IMPROVED\n\t\tS_InitialisePolyList(1); // Fill backbuffer with black\n#else // !FEATURE_VIEW_IMPROVED\n\t\tS_InitialisePolyList(0); // Leave backbuffer uncleaned\n#endif // FEATURE_VIEW_IMPROVED\n\t}\n\n\t// Draw Lara\n\tif( Objects[ID_LARA].loaded && !(LaraItem->flags & IFL_INVISIBLE) ) {\n\t\tif( RoomInfo[LaraItem->roomNumber].flags & ROOM_UNDERWATER ) {\n\t\t\tS_SetupBelowWater(UnderwaterCamera);\n\t\t} else {\n\t\t\tS_SetupAboveWater(UnderwaterCamera);\n\t\t}\n\t\tMidSort = RoomInfo[LaraItem->roomNumber].boundActive >> 8;\n\t\tif( MidSort ) --MidSort;\n#if defined(FEATURE_VIDEOFX_IMPROVED)\n\t\tif( Lara.mesh_effects ) {\n\t\t\tif( GoldenLaraAlpha < 0xFF ) GoldenLaraAlpha += 8;\n\t\t\tCLAMPG(GoldenLaraAlpha, 0xFF);\n\t\t} else {\n\t\t\tif( GoldenLaraAlpha > 0 ) GoldenLaraAlpha -= 8;\n\t\t\tCLAMPL(GoldenLaraAlpha, 0);\n\t\t}\n\t\tif( GoldenLaraAlpha ) {\n\t\t\t// NOTE: this is dirty trick for Golden Lara while Dozy cheat mode.\n\t\t\t// In TR1 there is bit mask in mesh_effects for distinct meshes,\n\t\t\t// but whole Lara must be golden here, including braid and weapons.\n\t\t\t// The original TR1 gold color is #A09860, but it Midas room walls\n\t\t\t// were orange tinted and bright, so to compensate all of this\n\t\t\t// and to make gold more sweet here used different tint color.\n\t\t\tSetMeshReflectState(ID_NONE, RGBA_MAKE(0xFF,0xC0,0x40,GoldenLaraAlpha));\n\t\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\tDrawLara(LaraItem);\n#if defined(FEATURE_VIDEOFX_IMPROVED)\n\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t}\n\n\t// Draw rooms\n\tfor( int i = 0; i < DrawRoomsCount; ++i ) {\n\t\tPrintRooms(DrawRoomsArray[i]);\n\t}\n\n\t// Draw movable and static objects\n\tfor( int i = 0; i < DrawRoomsCount; ++i ) {\n\t\tPrintObjects(DrawRoomsArray[i]);\n\t}\n#ifdef FEATURE_VIEW_IMPROVED\n\tfor( int i = 0; i < DrawRoomsCount; ++i ) {\n\t\tRoomInfo[DrawRoomsArray[i]].boundActive = 0;\n\t}\n\tMidSort = 0;\n#endif // FEATURE_VIEW_IMPROVED\n}\n\nvoid __cdecl GetRoomBounds() {\n\twhile( BoundStart != BoundEnd ) {\n\t\tint roomNumber = BoundRooms[BoundStart++ % ARRAY_SIZE(BoundRooms)];\n\t\tROOM_INFO *room = &RoomInfo[roomNumber];\n\t\troom->boundActive &= ~2;\n\t\tMidSort = (room->boundActive >> 8) + 1;\n\n\t\tCLAMPG(room->boundLeft, room->left)\n\t\tCLAMPG(room->boundTop, room->top)\n\t\tCLAMPL(room->boundRight, room->right)\n\t\tCLAMPL(room->boundBottom, room->bottom)\n\n\t\tif( !CHK_ANY(room->boundActive, 1) ) {\n\t\t\tDrawRoomsArray[DrawRoomsCount++] = roomNumber;\n\t\t\troom->boundActive |= 1;\n\t\t\tif( CHK_ANY(room->flags, ROOM_OUTSIDE) ) {\n\t\t\t\tOutsideCamera = ROOM_OUTSIDE;\n\t\t\t}\n\t\t}\n\n\t\t// NOTE: The original game checks just ROOM_INSIDE flag here\n\t\tif( CHK_ANY(room->flags, ROOM_OUTSIDE) || !CHK_ANY(room->flags, ROOM_INSIDE) ) {\n\t\t\tCLAMPG(OutsideLeft, room->boundLeft)\n\t\t\tCLAMPG(OutsideTop, room->boundTop)\n\t\t\tCLAMPL(OutsideRight, room->boundRight)\n\t\t\tCLAMPL(OutsideBottom, room->boundBottom)\n\t\t}\n\n\t\tif( !room->doors ) continue;\n\t\tphd_PushMatrix();\n\t\tphd_TranslateAbs(room->x, room->y, room->z);\n\n\t\tfor( int i = 0; i < room->doors->wCount; ++i ) {\n\t\t\tDOOR_INFO *door = &room->doors->door[i];\n\t\t\tif( door->x * (room->x + door->vertex[0].x - MatrixW2V._03)\n\t\t\t\t+ door->y * (room->y + door->vertex[0].y - MatrixW2V._13)\n\t\t\t\t+ door->z * (room->z + door->vertex[0].z - MatrixW2V._23) < 0 )\n\t\t\t{\n\t\t\t\tSetRoomBounds((__int16 *)&door->x, door->room, room);\n\t\t\t}\n\t\t}\n\t\tphd_PopMatrix();\n\t}\n}\n\nvoid __cdecl SetRoomBounds(__int16 *ptrObj, int roomNumber, ROOM_INFO *parent) {\n\tROOM_INFO *room = &RoomInfo[roomNumber];\n\tif( room->boundLeft <= parent->left\n\t\t&& room->boundRight >= parent->right\n\t\t&& room->boundTop <= parent->top\n\t\t&& room->boundBottom >= parent->bottom )\n\t{\n\t\treturn;\n\t}\n\n\tPHD_VECTOR view[4];\n\tint left = parent->right;\n\tint right = parent->left;\n\tint top = parent->bottom;\n\tint bottom = parent->top;\n\tint tooFar = 0;\n\tint tooNear = 0;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tptrObj += 3;\n\t\tPHD_MATRIX *m = PhdMatrixPtr;\n\t\tint x = view[i].x = ptrObj[0] * m->_00 + ptrObj[1] * m->_01 + ptrObj[2] * m->_02 + m->_03;\n\t\tint y = view[i].y = ptrObj[0] * m->_10 + ptrObj[1] * m->_11 + ptrObj[2] * m->_12 + m->_13;\n\t\tint z = view[i].z = ptrObj[0] * m->_20 + ptrObj[1] * m->_21 + ptrObj[2] * m->_22 + m->_23;\n\t\tif( z <= 0 ) {\n\t\t\t++tooNear;\n\t\t\tcontinue;\n\t\t}\n\t\tif( z > PhdFarZ ) {\n\t\t\t++tooFar;\n\t\t}\n\t\tz /= PhdPersp;\n\t\tif( z ) {\n\t\t\tx = PhdWinCenterX + x / z;\n\t\t\ty = PhdWinCenterY + y / z;\n\t\t} else {\n\t\t\tx = ( x < 0 ) ? PhdWinLeft : PhdWinRight;\n\t\t\ty = ( y < 0 ) ? PhdWinTop : PhdWinBottom;\n\t\t}\n\t\tCLAMPG(left, x - 1);\n\t\tCLAMPG(top, y - 1);\n\t\tCLAMPL(right, x + 1);\n\t\tCLAMPL(bottom, y + 1);\n\t}\n\n\tif( tooNear == 4 || tooFar == 4 ) {\n\t\treturn;\n\t}\n\n\tif( tooNear > 0 ) {\n\t\tfor( int i=0; i<4; ++i ) {\n\t\t\tint j=(i+3)%4;\n\t\t\tif( (view[i].z < 0) == (view[j].z < 0) ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif( view[i].x <= 0 || view[j].x <= 0 ) {\n\t\t\t\tleft = 0;\n\t\t\t}\n\t\t\tif( view[i].x >= 0 || view[j].x >= 0 ) {\n\t\t\t\tright = PhdWinMaxX;\n\t\t\t}\n\t\t\tif( view[i].y <= 0 || view[j].y <= 0 ) {\n\t\t\t\ttop = 0;\n\t\t\t}\n\t\t\tif( view[i].y >= 0 || view[j].y >= 0 ) {\n\t\t\t\tbottom = PhdWinMaxY;\n\t\t\t}\n\t\t}\n\t}\n\n\tCLAMPL(left, parent->left);\n\tCLAMPL(top, parent->top);\n\tCLAMPG(right, parent->right);\n\tCLAMPG(bottom, parent->bottom);\n\n\tif( left >= right || top >= bottom ) {\n\t\treturn;\n\t}\n\n\tif( CHK_ANY(room->boundActive, 2) ) {\n\t\tCLAMPG(room->left, left);\n\t\tCLAMPG(room->top, top);\n\t\tCLAMPL(room->right, right);\n\t\tCLAMPL(room->bottom, bottom);\n\t} else {\n\t\tBoundRooms[BoundEnd++ % ARRAY_SIZE(BoundRooms)] = roomNumber;\n\t\troom->boundActive |= 2;\n#ifdef FEATURE_VIEW_IMPROVED\n\t\tif( !CHK_ANY(room->boundActive, 1) ) {\n\t\t\troom->boundActive += MidSort << 8;\n\t\t}\n#else // FEATURE_VIEW_IMPROVED\n\t\troom->boundActive += MidSort << 8;\n#endif // FEATURE_VIEW_IMPROVED\n\t\troom->left = left;\n\t\troom->right = right;\n\t\troom->top = top;\n\t\troom->bottom = bottom;\n\t}\n}\n\nvoid __cdecl ClipRoom(ROOM_INFO *room) {\n\tstatic const int p[12][2] = {\n\t\t{0, 1}, {1, 2}, {2, 3}, {3, 0},\n\t\t{4, 5}, {5, 6}, {6, 7}, {7, 4},\n\t\t{0, 4}, {1, 5}, {2, 6}, {3, 7},\n\t};\n\tint xv[8], yv[8], zv[8], clip[8];\n\tint xMin, yMin, xMax, yMax;\n\tint clipRoom = 0;\n\n\txv[0] = xv[3] = xv[4] = xv[7] = 0x400;\n\tyv[0] = yv[1] = yv[2] = yv[3] = room->maxCeiling - room->y;\n\tzv[0] = zv[1] = zv[4] = zv[5] = 0x400;\n\n\txv[1] = xv[2] = xv[5] = xv[6] = (room->ySize - 1) * 0x400;\n\tyv[4] = yv[5] = yv[6] = yv[7] = room->minFloor - room->y;\n\tzv[2] = zv[3] = zv[6] = zv[7] = (room->xSize - 1) * 0x400;\n\n\tfor( int i=0; i<8; ++i ) {\n\t\tPHD_MATRIX *m = PhdMatrixPtr;\n\t\tint x = xv[i];\n\t\tint y = yv[i];\n\t\tint z = zv[i];\n\t\txv[i] = (x * m->_00) + (y * m->_01) + (z * m->_02) + m->_03;\n\t\tyv[i] = (x * m->_10) + (y * m->_11) + (z * m->_12) + m->_13;\n\t\tzv[i] = (x * m->_20) + (y * m->_21) + (z * m->_22) + m->_23;\n\t\tif( zv[i] > PhdFarZ ) {\n\t\t\tclip[i] = 1;\n\t\t\tclipRoom = 1;\n\t\t} else {\n\t\t\tclip[i] = 0;\n\t\t}\n\t}\n\tif( !clipRoom ) {\n\t\treturn;\n\t}\n\n\txMin = yMin = 0x10000000;\n\txMax = yMax = -0x10000000;\n\tfor( int i=0; i<12; ++i ) {\n\t\tint p1 = p[i][0];\n\t\tint p2 = p[i][1];\n\t\tif( clip[p1] ^ clip[p2] ) {\n\t\t\tint zDiv = (zv[p2] - zv[p1]) >> W2V_SHIFT;\n\t\t\tif( zDiv ) {\n\t\t\t\tint zNom = (PhdFarZ - zv[p1]) >> W2V_SHIFT;\n\t\t\t\tint x = xv[p1] + ((((xv[p2] - xv[p1]) >> W2V_SHIFT) * zNom / zDiv) << W2V_SHIFT);\n\t\t\t\tint y = yv[p1] + ((((yv[p2] - yv[p1]) >> W2V_SHIFT) * zNom / zDiv) << W2V_SHIFT);\n\t\t\t\tCLAMPG(xMin, x);\n\t\t\t\tCLAMPG(yMin, y);\n\t\t\t\tCLAMPL(xMax, x);\n\t\t\t\tCLAMPL(yMax, y);\n\t\t\t} else {\n\t\t\t\tCLAMPG(xMin, xv[p1]);\n\t\t\t\tCLAMPG(xMin, xv[p2]);\n\t\t\t\tCLAMPG(yMin, yv[p1]);\n\t\t\t\tCLAMPG(yMin, yv[p2]);\n\t\t\t\tCLAMPL(xMax, xv[p1]);\n\t\t\t\tCLAMPL(xMax, xv[p2]);\n\t\t\t\tCLAMPL(yMax, yv[p1]);\n\t\t\t\tCLAMPL(yMax, yv[p2]);\n\t\t\t}\n\t\t}\n\t}\n\txMin = PhdWinCenterX + xMin / (PhdFarZ / PhdPersp);\n\tyMin = PhdWinCenterY + yMin / (PhdFarZ / PhdPersp);\n\txMax = PhdWinCenterX + xMax / (PhdFarZ / PhdPersp);\n\tyMax = PhdWinCenterY + yMax / (PhdFarZ / PhdPersp);\n\tif( xMin <= PhdWinRight && yMin <= PhdWinBottom && xMax >= PhdWinLeft && yMax >= PhdWinTop ) {\n\t\tCLAMPL(xMin, PhdWinLeft);\n\t\tCLAMPL(yMin, PhdWinTop);\n\t\tCLAMPG(xMax, PhdWinRight);\n\t\tCLAMPG(yMax, PhdWinBottom);\n\t\tS_InsertBackPolygon(xMin, yMin, xMax, yMax);\n\t}\n}\n\nvoid __cdecl PrintRooms(__int16 roomNumber) {\n\tROOM_INFO *room = &RoomInfo[roomNumber];\n#ifdef FEATURE_VIEW_IMPROVED\n\tif( CHK_ANY(room->boundActive, 4) ) {\n\t\treturn;\n\t}\n#endif // FEATURE_VIEW_IMPROVED\n\tif( CHK_ANY(room->flags, ROOM_UNDERWATER) ) {\n\t\tS_SetupBelowWater(UnderwaterCamera);\n\t} else {\n\t\tS_SetupAboveWater(UnderwaterCamera);\n\t}\n\tMidSort = room->boundActive >> 8;\n\tphd_TranslateAbs(room->x, room->y, room->z);\n\tPhdWinLeft = room->boundLeft;\n\tPhdWinRight = room->boundRight;\n\tPhdWinTop = room->boundTop;\n\tPhdWinBottom = room->boundBottom;\n\tS_LightRoom(room);\n\tif( OutsideCamera > 0 && !CHK_ANY(room->flags, ROOM_INSIDE) ) {\n\t\tS_InsertRoom(room->data, 1);\n\t} else {\n\t\tif( OutsideCamera >= 0 ) {\n\t\t\tClipRoom(room);\n\t\t}\n\t\tS_InsertRoom(room->data, 0);\n\t}\n#ifdef FEATURE_VIEW_IMPROVED\n\troom->boundActive |= 4;\n#endif // FEATURE_VIEW_IMPROVED\n}\n\nvoid __cdecl PrintObjects(__int16 roomNumber) {\n\tROOM_INFO *room = &RoomInfo[roomNumber];\n\tif( CHK_ANY(room->flags, ROOM_UNDERWATER) ) {\n\t\tS_SetupBelowWater(UnderwaterCamera);\n\t} else {\n\t\tS_SetupAboveWater(UnderwaterCamera);\n\t}\n\n\tMidSort = room->boundActive >> 8;\n#ifndef FEATURE_VIEW_IMPROVED\n\troom->boundActive = 0;\n#endif // FEATURE_VIEW_IMPROVED\n\n\tphd_PushMatrix();\n\tphd_TranslateAbs(room->x, room->y, room->z);\n\tPhdWinLeft = room->boundLeft;\n\tPhdWinTop = room->boundTop;\n\tPhdWinRight = room->boundRight;\n\tPhdWinBottom = room->boundBottom;\n\n\tMESH_INFO *mesh = room->mesh;\n\tfor( int i = 0; i < room->numMeshes; ++i ) {\n\t\tif( !CHK_ANY(StaticObjects[mesh[i].staticNumber].flags, 2) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tphd_PushMatrix();\n\t\tphd_TranslateAbs(mesh[i].x, mesh[i].y, mesh[i].z);\n\t\tphd_RotY(mesh[i].yRot);\n\t\t__int16 clip = S_GetObjectBounds((__int16 *)&StaticObjects[mesh[i].staticNumber].drawBounds);\n\t\tif( clip ) {\n\t\t\tS_CalculateStaticMeshLight(mesh[i].x, mesh[i].y, mesh[i].z, mesh[i].shade1, mesh[i].shade2, room);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tSetMeshReflectState(mesh[i].staticNumber, -1);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\tphd_PutPolygons(MeshPtr[StaticObjects[mesh[i].staticNumber].meshIndex], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t}\n\t\tphd_PopMatrix();\n\t}\n\n\tPhdWinLeft = 0;\n\tPhdWinTop = 0;\n\tPhdWinRight = PhdWinMaxX + 1;\n\tPhdWinBottom = PhdWinMaxY + 1;\n\n\tfor( __int16 id = room->itemNumber; id >= 0; id = Items[id].nextItem ) {\n\t\tif( Items[id].status != ITEM_INVISIBLE ) {\n\t\t\tObjects[Items[id].objectID].drawRoutine(&Items[id]);\n\t\t}\n\t}\n\n\tfor( __int16 id = room->fxNumber; id >= 0; id = Effects[id].next_fx ) {\n\t\tDrawEffect(id);\n\t}\n\n\tphd_PopMatrix();\n\troom->boundLeft = PhdWinMaxX;\n\troom->boundTop = PhdWinMaxY;\n\troom->boundRight = 0;\n\troom->boundBottom = 0;\n}\n\nvoid __cdecl DrawEffect(__int16 fx_id) {\n\tFX_INFO *fx = &Effects[fx_id];\n\tOBJECT_INFO *obj = &Objects[fx->object_number];\n\tif( !obj->loaded ) return;\n\tif( fx->object_number == ID_GLOW ) {\n\t\t// NOTE: Core's hacky way to store the sprite flags in the rotation fields\n\t\tS_DrawSprite((fx->pos.rotY << 16)|(fx->pos.rotX), // flags\n\t\t\t\t\tfx->pos.x, fx->pos.y, fx->pos.z, // coordinates\n\t\t\t\t\tObjects[ID_GLOW].meshIndex, // sprite id\n\t\t\t\t\tfx->shade, fx->frame_number); // shade, scale\n\t} else if( obj->nMeshes < 0 ) {\n\t\tS_DrawSprite(SPR_ABS | SPR_SHADE | (obj->semi_transparent ? SPR_SEMITRANS : 0), // flags\n\t\t\t\t\tfx->pos.x, fx->pos.y, fx->pos.z, // coordinates\n\t\t\t\t\tobj->meshIndex - fx->frame_number, // sprite id\n\t\t\t\t\tfx->shade, 0);  // shade, scale\n\t} else {\n\t\tphd_PushMatrix();\n\t\tphd_TranslateAbs(fx->pos.x, fx->pos.y, fx->pos.z);\n\t\tif( PhdMatrixPtr->_23 > PhdNearZ && PhdMatrixPtr->_23 < PhdFarZ ) {\n\t\t\t__int16 *meshPtr = NULL;\n\t\t\tphd_RotYXZ(fx->pos.rotY, fx->pos.rotX, fx->pos.rotZ);\n\t\t\tS_CalculateStaticLight(fx->shade);\n\t\t\tif( obj->nMeshes ) {\n\t\t\t\tmeshPtr = MeshPtr[obj->meshIndex];\n\t\t\t} else {\n\t\t\t\tmeshPtr = MeshPtr[fx->frame_number];\n\t\t\t}\n\t\t\tphd_PutPolygons(meshPtr, -1);\n\t\t}\n\t\tphd_PopMatrix();\n\t}\n}\n\nvoid __cdecl DrawSpriteItem(ITEM_INFO *item) {\n\tOBJECT_INFO *obj;\n\n\tphd_PushUnitMatrix(); // NOTE: this push is workaround for sprites with no matrix\n\tS_CalculateStaticMeshLight(item->pos.x, item->pos.y, item->pos.z,\n\t\titem->shade1, item->shade2, &RoomInfo[item->roomNumber]);\n\tphd_PopMatrix(); // NOTE: this pop is workaround for sprites with no matrix\n\n\tobj = &Objects[item->objectID];\n\n\t// NOTE: SPR_ITEM is not presented in the original game\n\tS_DrawSprite(SPR_ITEM | SPR_ABS | SPR_SHADE | (obj->semi_transparent ? SPR_SEMITRANS : 0),\n\t\t\t\t item->pos.x, item->pos.y, item->pos.z,\n\t\t\t\t obj->meshIndex - item->frameNumber,\n\t\t\t\t LsAdder + 0x1000, 0);\n}\n\nvoid __cdecl DrawDummyItem(ITEM_INFO *item) {\n}\n\nvoid __cdecl DrawAnimatingItem(ITEM_INFO *item) {\n\tstatic __int16 no_rotation[12] = {0};\n\t__int16 *frames[2] = {0};\n\tint rate = 0;\n\tDWORD bit = 1;\n\tint frac = GetFrames(item, frames, &rate);\n\tOBJECT_INFO *obj = &Objects[item->objectID];\n\n\tif( obj->shadowSize ) {\n\t\tS_PrintShadow(obj->shadowSize, frames[0], item);\n\t}\n\n\tphd_PushMatrix();\n\tphd_TranslateAbs(item->pos.x, item->pos.y, item->pos.z);\n\tphd_RotYXZ(item->pos.rotY, item->pos.rotX, item->pos.rotZ);\n\tint clip = S_GetObjectBounds(frames[0]);\n\n\tif( clip ) {\n\t\tCalculateObjectLighting(item, frames[0]);\n\n\t\t__int16 *rots = item->data ? (__int16 *)item->data : no_rotation;\n\t\t__int16 **meshPtr = &MeshPtr[obj->meshIndex];\n\t\tint *bonePtr = &AnimBones[obj->boneIndex];\n\t\tif( frac ) {\n\t\t\tInitInterpolate(frac, rate);\n\t\t\tphd_TranslateRel_ID(frames[0][6], frames[0][7], frames[0][8], frames[1][6], frames[1][7], frames[1][8]);\n\t\t\tUINT16 *rot1 = (UINT16 *)&frames[0][9];\n\t\t\tUINT16 *rot2 = (UINT16 *)&frames[1][9];\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\n\t\t\tif( CHK_ANY(item->meshBits, 1) ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tSetMeshReflectState(item->objectID, 0);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tphd_PutPolygons_I(meshPtr[0], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t}\n\n\t\t\tfor( int i = 1; i < obj->nMeshes; ++i ) {\n\t\t\t\tDWORD state = *bonePtr;\n\t\t\t\tif( CHK_ANY(state, 1) ) {\n\t\t\t\t\tphd_PopMatrix_I();\n\t\t\t\t}\n\t\t\t\tif( CHK_ANY(state, 2) ) {\n\t\t\t\t\tphd_PushMatrix_I();\n\t\t\t\t}\n\t\t\t\tphd_TranslateRel_I(bonePtr[1], bonePtr[2], bonePtr[3]);\n\t\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\t\tif( CHK_ANY(state, 0x1C) ) {\n\t\t\t\t\tif( CHK_ANY(state, 0x08) ) {\n\t\t\t\t\t\tphd_RotY_I(*(rots++));\n\t\t\t\t\t}\n\t\t\t\t\tif( CHK_ANY(state, 0x04) ) {\n\t\t\t\t\t\tphd_RotX_I(*(rots++));\n\t\t\t\t\t}\n\t\t\t\t\tif( CHK_ANY(state, 0x10) ) {\n\t\t\t\t\t\tphd_RotZ_I(*(rots++));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbonePtr+=4;\n\t\t\t\tbit <<= 1;\n\t\t\t\tif( CHK_ANY(item->meshBits, bit) ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tSetMeshReflectState(item->objectID, i);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tphd_PutPolygons_I(meshPtr[i], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tphd_TranslateRel(frames[0][6], frames[0][7], frames[0][8]);\n\t\t\tUINT16 *rot = (UINT16 *)&frames[0][9];\n\t\t\tphd_RotYXZsuperpack(&rot, 0);\n\n\t\t\tif( CHK_ANY(item->meshBits, 1) ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tSetMeshReflectState(item->objectID, 0);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tphd_PutPolygons(meshPtr[0], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t}\n\n\t\t\tfor( int i = 1; i < obj->nMeshes; ++i) {\n\t\t\t\tDWORD state = *bonePtr;\n\t\t\t\tif( CHK_ANY(state, 1) ) {\n\t\t\t\t\tphd_PopMatrix();\n\t\t\t\t}\n\t\t\t\tif( CHK_ANY(state, 2) ) {\n\t\t\t\t\tphd_PushMatrix();\n\t\t\t\t}\n\t\t\t\tphd_TranslateRel(bonePtr[1], bonePtr[2], bonePtr[3]);\n\t\t\t\tphd_RotYXZsuperpack(&rot, 0);\n\t\t\t\tif( CHK_ANY(state, 0x1C) ) {\n\t\t\t\t\tif( CHK_ANY(state, 0x08) ) {\n\t\t\t\t\t\tphd_RotY(*(rots++));\n\t\t\t\t\t}\n\t\t\t\t\tif( CHK_ANY(state, 0x04) ) {\n\t\t\t\t\t\tphd_RotX(*(rots++));\n\t\t\t\t\t}\n\t\t\t\t\tif( CHK_ANY(state, 0x10) ) {\n\t\t\t\t\t\tphd_RotZ(*(rots++));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbonePtr += 4;\n\t\t\t\tbit <<= 1;\n\t\t\t\tif( CHK_ANY(item->meshBits, bit) ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tSetMeshReflectState(item->objectID, i);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tphd_PutPolygons(meshPtr[i], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tphd_PopMatrix();\n}\n\nvoid __cdecl DrawLaraInt(ITEM_INFO *item, __int16 *frame1, __int16 *frame2, int frac, int rate) {\n\tPHD_MATRIX matrix;\n\tUINT16 *rot1, *rot2, *rot1copy, *rot2copy;\n\tint frame, *bones;\n\n\tOBJECT_INFO *obj = &Objects[item->objectID];\n\t__int16 *bounds = GetBoundsAccurate(item);\n\tif( Lara.skidoo == -1 ) {\n\t\tS_PrintShadow(obj->shadowSize, bounds, item);\n\t}\n\tmatrix = *PhdMatrixPtr;\n\tphd_PushMatrix();\n\tphd_TranslateAbs(item->pos.x, item->pos.y, item->pos.z);\n\tphd_RotYXZ(item->pos.rotY, item->pos.rotX, item->pos.rotZ);\n\n\tint clip = S_GetObjectBounds(frame1);\n\tif( !clip ) {\n\t\tphd_PopMatrix();\n\t\treturn;\n\t}\n\n\tphd_PushMatrix();\n\tCalculateObjectLighting(item, frame1);\n\tbones = &AnimBones[obj->boneIndex];\n\n\trot1 = (UINT16 *)frame1 + 9;\n\trot2 = (UINT16 *)frame2 + 9;\n\n\tInitInterpolate(frac, rate);\n\tphd_TranslateRel_ID(frame1[6], frame1[7], frame1[8], frame2[6], frame2[7], frame2[8]);\n\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[0], clip);\n\n\tphd_PushMatrix_I();\n\tphd_TranslateRel_I(bones[1], bones[2], bones[3]);\n\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[1], clip);\n\tphd_TranslateRel_I(bones[5], bones[6], bones[7]);\n\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[2], clip);\n\tphd_TranslateRel_I(bones[9], bones[10], bones[11]);\n\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[3], clip);\n\tphd_PopMatrix_I();\n\n\tphd_PushMatrix_I();\n\tphd_TranslateRel_I(bones[13], bones[14], bones[15]);\n\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[4], clip);\n\tphd_TranslateRel_I(bones[17], bones[18], bones[19]);\n\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[5], clip);\n\tphd_TranslateRel_I(bones[21], bones[22], bones[23]);\n\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[6], clip);\n\tphd_PopMatrix_I();\n\n\tphd_TranslateRel_I(bones[25], bones[26], bones[27]);\n\tif ( Lara.weapon_item != -1 && Lara.gun_type == LGT_M16\n\t\t&& (Items[Lara.weapon_item].currentAnimState == 0\n\t\t|| Items[Lara.weapon_item].currentAnimState == 2\n\t\t|| Items[Lara.weapon_item].currentAnimState == 4) )\n\t{\n\t\tframe = Lara.right_arm.frame_number * (Anims[Lara.right_arm.anim_number].interpolation >> 8) + 9;\n\t\trot1 = rot2 = (UINT16 *)&Lara.right_arm.frame_base[frame];\n\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 7);\n\t} else {\n\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t}\n\tphd_RotYXZ_I(Lara.torso_y_rot, Lara.torso_x_rot, Lara.torso_z_rot);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[7], clip);\n\n\tphd_PushMatrix_I();\n\tphd_TranslateRel_I(bones[53], bones[54], bones[55]);\n\trot1copy = rot1;\n\trot2copy = rot2;\n\tphd_RotYXZsuperpack_I(&rot1, &rot2, 6);\n\trot1 = rot1copy;\n\trot2 = rot2copy;\n\tphd_RotYXZ_I(Lara.head_y_rot, Lara.head_x_rot, Lara.head_z_rot);\n\tphd_PutPolygons_I(Lara.mesh_ptrs[14], clip);\n\t*PhdMatrixPtr = matrix;\n\tDrawHair();\n\tphd_PopMatrix_I();\n\n\tif( Lara.back_gun ) {\n\t\tphd_PushMatrix_I();\n\t\tint *bone = &AnimBones[Objects[Lara.back_gun].boneIndex];\n\t\tphd_TranslateRel_I(bone[53], bone[54], bone[55]);\n\t\trot2copy = (UINT16 *)Objects[Lara.back_gun].frameBase + 9;\n\t\trot1copy = (UINT16 *)Objects[Lara.back_gun].frameBase + 9;\n\t\tphd_RotYXZsuperpack_I(&rot1copy, &rot2copy, 14);\n\t\tphd_PutPolygons_I(MeshPtr[Objects[Lara.back_gun].meshIndex + 14], clip);\n\t\tphd_PopMatrix_I();\n\t}\n\n\tint gunType = LGT_Unarmed;\n\tif( Lara.gun_status == LGS_Ready\n\t\t|| Lara.gun_status == LGS_Special\n\t\t|| Lara.gun_status == LGS_Draw\n\t\t|| Lara.gun_status == LGS_Undraw )\n\t{\n\t\tgunType = Lara.gun_type;\n\t}\n\n\tswitch( gunType ) {\n\t\tcase LGT_Unarmed:\n\t\tcase LGT_Flare:\n\t\t\tphd_PushMatrix_I();\n\t\t\tphd_TranslateRel_I(bones[29], bones[30], bones[31]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[8], clip);\n\t\t\tphd_TranslateRel_I(bones[33], bones[34], bones[35]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[9], clip);\n\t\t\tphd_TranslateRel_I(bones[37], bones[38], bones[39]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[10], clip);\n\t\t\tphd_PopMatrix_I();\n\t\t\tphd_PushMatrix_I();\n\t\t\tphd_TranslateRel_I(bones[41], bones[42], bones[43]);\n\t\t\tif( Lara.flare_control_left ) {\n\t\t\t\tframe = (Anims[Lara.left_arm.anim_number].interpolation >> 8) * (Lara.left_arm.frame_number - Anims[Lara.left_arm.anim_number].frameBase) + 9;\n\t\t\t\trot1 = rot2 = (UINT16 *)&Lara.left_arm.frame_base[frame];\n\t\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 11);\n\t\t\t} else {\n\t\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\t}\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[11], clip);\n\t\t\tphd_TranslateRel_I(bones[45], bones[46], bones[47]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[12], clip);\n\t\t\tphd_TranslateRel_I(bones[49], bones[50], bones[51]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[13], clip);\n\t\t\tif( Lara.gun_type == LGT_Flare ) {\n\t\t\t\tif( Lara.left_arm.flash_gun ) {\n\t\t\t\t\tphd_TranslateRel_I(11, 32, 80);\n\t\t\t\t\tphd_RotX_I(-90 * PHD_DEGREE);\n\t\t\t\t\tphd_RotY_I(2 * GetRandomDraw());\n\t\t\t\t\tS_CalculateStaticLight(0x800);\n\t\t\t\t\tphd_PutPolygons_I(MeshPtr[Objects[ID_FLARE_FIRE].meshIndex], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tif( AlphaBlendMode ) {\n\t\t\t\t\t\tint shade = (GetRandomDraw() & 0xFFF) + 0x1000;\n\t\t\t\t\t\tDWORD flags = GLOW_FLARE_COLOR;\n\t\t\t\t\t\tflags |= SPR_BLEND_ADD|SPR_TINT|SPR_SHADE|SPR_SEMITRANS;\n\t\t\t\t\t\tS_DrawSprite(flags, 0, 0, 0, Objects[ID_GLOW].meshIndex, shade, 0);\n\t\t\t\t\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase LGT_Pistols:\n\t\tcase LGT_Magnums:\n\t\tcase LGT_Uzis:\n\t\t\tphd_PushMatrix_I();\n\t\t\tphd_TranslateRel_I(bones[29], bones[30], bones[31]);\n\t\t\tInterpolateArmMatrix();\n\t\t\tphd_RotYXZ(Lara.right_arm.y_rot, Lara.right_arm.x_rot, Lara.right_arm.z_rot);\n\t\t\tframe = (Anims[Lara.right_arm.anim_number].interpolation >> 8) * (Lara.right_arm.frame_number - Anims[Lara.right_arm.anim_number].frameBase) + 9;\n\t\t\trot1 = (UINT16 *)&Lara.right_arm.frame_base[frame];\n\t\t\tphd_RotYXZsuperpack(&rot1, 8);\n\t\t\tphd_PutPolygons(Lara.mesh_ptrs[8], clip);\n\t\t\tphd_TranslateRel(bones[33], bones[34], bones[35]);\n\t\t\tphd_RotYXZsuperpack(&rot1, 0);\n\t\t\tphd_PutPolygons(Lara.mesh_ptrs[9], clip);\n\t\t\tphd_TranslateRel(bones[37], bones[38], bones[39]);\n\t\t\tphd_RotYXZsuperpack(&rot1, 0);\n\t\t\tphd_PutPolygons(Lara.mesh_ptrs[10], clip);\n\t\t\tif( Lara.right_arm.flash_gun ) {\n\t\t\t\tmatrix = *PhdMatrixPtr;\n\t\t\t}\n\t\t\tphd_PopMatrix_I();\n\t\t\tphd_PushMatrix_I();\n\t\t\tphd_TranslateRel_I(bones[41], bones[42], bones[43]);\n\t\t\tInterpolateArmMatrix();\n\t\t\tphd_RotYXZ(Lara.left_arm.y_rot, Lara.left_arm.x_rot, Lara.left_arm.z_rot);\n\t\t\tframe = (Anims[Lara.left_arm.anim_number].interpolation >> 8) * (Lara.left_arm.frame_number - Anims[Lara.left_arm.anim_number].frameBase) + 9;\n\t\t\trot1 = (UINT16 *)&Lara.left_arm.frame_base[frame];\n\t\t\tphd_RotYXZsuperpack(&rot1, 11);\n\t\t\tphd_PutPolygons(Lara.mesh_ptrs[11], clip);\n\t\t\tphd_TranslateRel(bones[45], bones[46], bones[47]);\n\t\t\tphd_RotYXZsuperpack(&rot1, 0);\n\t\t\tphd_PutPolygons(Lara.mesh_ptrs[12], clip);\n\t\t\tphd_TranslateRel(bones[49], bones[50], bones[51]);\n\t\t\tphd_RotYXZsuperpack(&rot1, 0);\n\t\t\tphd_PutPolygons(Lara.mesh_ptrs[13], clip);\n\t\t\tif( Lara.left_arm.flash_gun ) {\n\t\t\t\tDrawGunFlash(gunType, clip);\n\t\t\t}\n\t\t\tif( Lara.right_arm.flash_gun ) {\n\t\t\t\t*PhdMatrixPtr = matrix;\n\t\t\t\tDrawGunFlash(gunType, clip);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase LGT_Shotgun:\n\t\tcase LGT_M16:\n\t\tcase LGT_Grenade:\n\t\tcase LGT_Harpoon:\n\t\t\tphd_PushMatrix_I();\n\t\t\tphd_TranslateRel_I(bones[29], bones[30], bones[31]);\n\t\t\tframe = Lara.right_arm.frame_number * (Anims[Lara.right_arm.anim_number].interpolation >> 8) + 9;\n\t\t\trot1 = rot2 = (UINT16 *)&Lara.right_arm.frame_base[frame];\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 8);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[8], clip);\n\t\t\tphd_TranslateRel_I(bones[33], bones[34], bones[35]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[9], clip);\n\t\t\tphd_TranslateRel_I(bones[37], bones[38], bones[39]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[10], clip);\n\t\t\tif( Lara.right_arm.flash_gun ) {\n\t\t\t\tmatrix = *PhdMatrixPtr;\n\t\t\t}\n\t\t\tphd_PopMatrix_I();\n\t\t\tphd_PushMatrix_I();\n\t\t\tphd_TranslateRel_I(bones[41], bones[42], bones[43]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[11], clip);\n\t\t\tphd_TranslateRel_I(bones[45], bones[46], bones[47]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[12], clip);\n\t\t\tphd_TranslateRel_I(bones[49], bones[50], bones[51]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\tphd_PutPolygons_I(Lara.mesh_ptrs[13], clip);\n\t\t\tif( Lara.right_arm.flash_gun ) {\n\t\t\t\t*PhdMatrixPtr = matrix;\n\t\t\t\tDrawGunFlash(gunType, clip);\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\tphd_PopMatrix();\n\tphd_PopMatrix();\n\tphd_PopMatrix();\n}\n\nvoid __cdecl phd_RotYXZsuperpack(UINT16 **pptr, int index) {\n\tfor( int i = 0; i < index; ++i ) {\n\t\tif( (**pptr >> 14) == 0 )\n\t\t\t*pptr += 2;\n\t\telse\n\t\t\t++*pptr;\n\t}\n\n\tswitch( **pptr >> 14 ) {\n\t\tcase 0 :\n\t\t\tphd_RotYXZpack(((UINT16)(*pptr)[0] << 16) + (UINT16)(*pptr)[1]);\n\t\t\t*pptr += 2;\n\t\t\tbreak;\n\t\tcase 1 :\n\t\t\tphd_RotX(**pptr << 6);\n\t\t\t++*pptr;\n\t\t\tbreak;\n\t\tcase 2 :\n\t\t\tphd_RotY(**pptr << 6);\n\t\t\t++*pptr;\n\t\t\tbreak;\n\t\tcase 3 :\n\t\t\tphd_RotZ(**pptr << 6);\n\t\t\t++*pptr;\n\t\t\tbreak;\n\t}\n}\n\nvoid __cdecl phd_PutPolygons_I(__int16 *ptrObj, int clip) {\n\tphd_PushMatrix();\n\tInterpolateMatrix();\n\tphd_PutPolygons(ptrObj, clip);\n\tphd_PopMatrix();\n}\n\nvoid __cdecl DrawGunFlash(int weapon, int clip) {\n\t__int16 light;\n\tint len;\n\tint off;\n\n\tswitch( weapon ) {\n\t\tcase LGT_Shotgun:\n\t\t\treturn;\n\t\tcase LGT_Flare:\n\t\t\tphd_TranslateRel(11, 32, 80);\n\t\t\tphd_RotX(-90 * PHD_DEGREE);\n\t\t\tphd_RotY(2 * GetRandomDraw());\n\t\t\tS_CalculateStaticLight(0x800);\n\t\t\tphd_PutPolygons(MeshPtr[Objects[ID_FLARE_FIRE].meshIndex], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tif( AlphaBlendMode ) {\n\t\t\t\tint shade = (GetRandomDraw() & 0xFFF) + 0x1000;\n\t\t\t\tDWORD flags = GLOW_FLARE_COLOR;\n\t\t\t\tflags |= SPR_BLEND_ADD|SPR_TINT|SPR_SHADE|SPR_SEMITRANS;\n\t\t\t\tS_DrawSprite(flags, 0, 0, 0, Objects[ID_GLOW].meshIndex, shade, 0);\n\t\t\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\treturn;\n\t\tcase LGT_M16:\n\t\t\tphd_TranslateRel(0, 400, 99);\n\t\t\tphd_RotYXZ(0, -85 * PHD_DEGREE, (2 * GetRandomDraw() & 0x4000) + 0x2000);\n\t\t\tS_CalculateStaticLight(0xA00);\n\t\t\tphd_PutPolygons(MeshPtr[Objects[ID_M16_FLASH].meshIndex], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tif( AlphaBlendMode ) {\n\t\t\t\tDWORD flags = GLOW_M16_COLOR;\n\t\t\t\tflags |= SPR_BLEND_ADD|SPR_TINT|SPR_SCALE|SPR_SEMITRANS;\n\t\t\t\tS_DrawSprite(flags, 0, 0, -65, Objects[ID_GLOW].meshIndex, 0, 0x200);\n\t\t\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\treturn;\n\t\tcase LGT_Magnums:\n\t\t\tlight = 0x1000;\n\t\t\tlen = 215;\n\t\t\toff = 65;\n\t\t\tbreak;\n\t\tcase LGT_Uzis:\n\t\t\tlight = 0xA00;\n\t\t\tlen = 200;\n\t\t\toff = 50;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tlight = 0x1400;\n\t\t\tlen = 185;\n\t\t\toff = 40;\n\t\t\tbreak;\n\t}\n\tphd_TranslateRel(0, len, off);\n\tphd_RotYXZ(0, -90 * PHD_DEGREE, 2 * GetRandomDraw());\n\tS_CalculateStaticLight(light);\n\tphd_PutPolygons(MeshPtr[Objects[ID_GUN_FLASH].meshIndex], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tif( AlphaBlendMode ) {\n\t\tDWORD flags = GLOW_PISTOL_COLOR;\n\t\tflags |= SPR_BLEND_ADD|SPR_TINT|SPR_SCALE|SPR_SEMITRANS;\n\t\tS_DrawSprite(flags, 0, 0, 0, Objects[ID_GLOW].meshIndex, 0, 0x200);\n\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n}\n\nvoid __cdecl AddDynamicLight(int x, int y, int z, int intensity, int falloff) {\n\tint idx = ( DynamicLightCount < ARRAY_SIZE(DynamicLights) ) ? DynamicLightCount++ : 0;\n\tDynamicLights[idx].x = x;\n\tDynamicLights[idx].y = y;\n\tDynamicLights[idx].z = z;\n\tDynamicLights[idx].intensity1 = intensity;\n\tDynamicLights[idx].fallOff1 = falloff;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Draw() {\n//\tINJECT(0x00418920, DrawPhaseCinematic);\n//\tINJECT(0x00418960, DrawPhaseGame);\n\n\tINJECT(0x004189A0, DrawRooms);\n\tINJECT(0x00418C50, GetRoomBounds);\n\tINJECT(0x00418E20, SetRoomBounds);\n\tINJECT(0x004191A0, ClipRoom);\n\tINJECT(0x00419580, PrintRooms);\n\tINJECT(0x00419640, PrintObjects);\n\tINJECT(0x00419870, DrawEffect);\n\tINJECT(0x004199C0, DrawSpriteItem);\n\n//\tINJECT(----------, DrawDummyItem);\n\tINJECT(0x00419A50, DrawAnimatingItem);\n\n//\tINJECT(0x00419DD0, DrawLara);\n\n\tINJECT(0x0041AB00, DrawLaraInt);\n\n//\tINJECT(0x0041B6F0, InitInterpolate);\n//\tINJECT(0x0041B730, phd_PopMatrix_I);\n//\tINJECT(0x0041B760, phd_PushMatrix_I);\n//\tINJECT(0x0041B790, phd_RotY_I);\n//\tINJECT(0x0041B7D0, phd_RotX_I);\n//\tINJECT(0x0041B810, phd_RotZ_I);\n//\tINJECT(0x0041B850, phd_TranslateRel_I);\n//\tINJECT(0x0041B8A0, phd_TranslateRel_ID);\n//\tINJECT(0x0041B8F0, phd_RotYXZ_I);\n//\tINJECT(0x0041B940, phd_RotYXZsuperpack_I);\n\n\tINJECT(0x0041B980, phd_RotYXZsuperpack);\n\tINJECT(0x0041BA30, phd_PutPolygons_I);\n\n//\tINJECT(0x0041BA60, InterpolateMatrix);\n//\tINJECT(0x0041BC10, InterpolateArmMatrix);\n\n\tINJECT(0x0041BD10, DrawGunFlash);\n\n//\tINJECT(0x0041BE80, CalculateObjectLighting);\n//\tINJECT(0x0041BF70, GetFrames);\n//\tINJECT(0x0041C010, GetBoundsAccurate);\n//\tINJECT(0x0041C090, GetBestFrame);\n\n\tINJECT(0x0041C0D0, AddDynamicLight);\n}\n"
  },
  {
    "path": "game/draw.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef DRAW_H_INCLUDED\n#define DRAW_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define DrawPhaseCinematic ((int(__cdecl*)(void)) 0x00418920)\n#define DrawPhaseGame ((int(__cdecl*)(void)) 0x00418960)\n\nvoid __cdecl DrawRooms(__int16 currentRoom); // 0x004189A0\nvoid __cdecl GetRoomBounds(); // 0x00418C50\nvoid __cdecl SetRoomBounds(__int16 *ptrObj, int roomNumber, ROOM_INFO *parent); // 0x00418E20\nvoid __cdecl ClipRoom(ROOM_INFO *room); // 0x004191A0\nvoid __cdecl PrintRooms(__int16 roomNumber); // 0x00419580\nvoid __cdecl PrintObjects(__int16 roomNumber); // 0x00419640\nvoid __cdecl DrawEffect(__int16 fx_id); // 0x00419870\nvoid __cdecl DrawSpriteItem(ITEM_INFO *item); // 0x004199C0\nvoid __cdecl DrawDummyItem(ITEM_INFO *item);\nvoid __cdecl DrawAnimatingItem(ITEM_INFO *item); // 0x00419A50\n\n#define DrawLara ((void(__cdecl*)(ITEM_INFO*)) 0x00419DD0)\n\nvoid __cdecl DrawLaraInt(ITEM_INFO *item, __int16 *frame1, __int16 *frame2, int frac, int rate);\n\n#define InitInterpolate ((void(__cdecl*)(int, int)) 0x0041B6F0)\n#define phd_PopMatrix_I ((void(__cdecl*)(void)) 0x0041B730)\n#define phd_PushMatrix_I ((void(__cdecl*)(void)) 0x0041B760)\n#define phd_RotY_I ((void(__cdecl*)(__int16)) 0x0041B790)\n#define phd_RotX_I ((void(__cdecl*)(__int16)) 0x0041B7D0)\n#define phd_RotZ_I ((void(__cdecl*)(__int16)) 0x0041B810)\n#define phd_TranslateRel_I ((void(__cdecl*)(int, int, int)) 0x0041B850)\n#define phd_TranslateRel_ID ((void(__cdecl*)(int, int, int, int, int, int)) 0x0041B8A0)\n#define phd_RotYXZ_I ((void(__cdecl*)(int, int, int)) 0x0041B8F0)\n#define phd_RotYXZsuperpack_I ((void(__cdecl*)(UINT16**, UINT16**, int)) 0x0041B940)\n\nvoid __cdecl phd_RotYXZsuperpack(UINT16 **pptr, int index); // 0x0041B980\nvoid __cdecl phd_PutPolygons_I(__int16 *ptrObj, int clip); // 0x0041BA30\n\n#define InterpolateMatrix ((void(__cdecl*)(void)) 0x0041BA60)\n#define InterpolateArmMatrix ((void(__cdecl*)(void)) 0x0041BC10)\n\nvoid __cdecl DrawGunFlash(int weapon, int clip);\n\n#define CalculateObjectLighting ((void(__cdecl*)(ITEM_INFO*, __int16*)) 0x0041BE80)\n#define GetFrames ((int(__cdecl*)(ITEM_INFO*, __int16**, int*)) 0x0041BF70)\n#define GetBoundsAccurate ((__int16*(__cdecl*)(ITEM_INFO*)) 0x0041C010)\n#define GetBestFrame ((__int16*(__cdecl*)(ITEM_INFO*)) 0x0041C090)\n\nvoid __cdecl AddDynamicLight(int x, int y, int z, int intensity, int falloff); // 0x0041C0D0\n\n#endif // DRAW_H_INCLUDED\n"
  },
  {
    "path": "game/eel.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/eel.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Eel() {\n//\tINJECT(0x0041C120, BigEelControl);\n//\tINJECT(0x0041C2C0, EelControl);\n}\n"
  },
  {
    "path": "game/eel.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef EEL_H_INCLUDED\n#define EEL_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define BigEelControl ((void(__cdecl*)(__int16)) 0x0041C120)\n#define EelControl ((void(__cdecl*)(__int16)) 0x0041C2C0)\n\n#endif // EEL_H_INCLUDED\n"
  },
  {
    "path": "game/effects.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Copyright (c) 2020 ChocolateFan <asasas9500@gmail.com>\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/effects.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/control.h\"\n#include \"game/draw.h\"\n#include \"game/hair.h\"\n#include \"game/invtext.h\"\n#include \"game/items.h\"\n#include \"game/sound.h\"\n#include \"game/sphere.h\"\n#include \"specific/game.h\"\n#include \"specific/output.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\nint __cdecl ItemNearLara(PHD_3DPOS *pos, int distance) {\n\tint dx, dy, dz;\n\t__int16 *frame;\n\n\tdx = pos->x - LaraItem->pos.x;\n\tdy = pos->y - LaraItem->pos.y;\n\tdz = pos->z - LaraItem->pos.z;\n\tif (ABS(dx) <= distance && ABS(dz) <= distance && ABS(dy) <= 3072 && SQR(dx) + SQR(dz) <= SQR(distance)) {\n\t\tframe = GetBoundsAccurate(LaraItem);\n\t\tif (dy >= frame[2] && dy <= frame[3] + 100)\n\t\t\treturn 1;\n\t}\n\treturn 0;\n}\n\nvoid __cdecl SoundEffects() {\n\tDWORD i;\n\n\tfor (i = 0; i < SoundFxCount; ++i) {\n\t\tif ((FlipStatus && CHK_ANY(SoundFx[i].flags, 0x40)) || (!FlipStatus && CHK_ANY(SoundFx[i].flags, 0x80)))\n\t\t\tPlaySoundEffect(SoundFx[i].data, (PHD_3DPOS *) &SoundFx[i].x, 0);\n\t}\n\tif (FlipEffect != -1)\n\t\t(*SfxFunctions[FlipEffect])(NULL);\n\tSOUND_EndScene();\n}\n\n__int16 __cdecl DoBloodSplat(int x, int y, int z, __int16 speed, __int16 direction, __int16 roomID) {\n\t__int16 fxID;\n\tFX_INFO *fx;\n\n\tfxID = CreateEffect(roomID);\n\tif (fxID != -1) {\n\t\tfx = &Effects[fxID];\n\t\tfx->pos.x = x;\n\t\tfx->pos.y = y;\n\t\tfx->pos.z = z;\n\t\tfx->pos.rotY = direction;\n\t\tfx->speed = speed;\n\t\tfx->frame_number = 0;\n\t\tfx->object_number = ID_BLOOD;\n\t\tfx->counter = 0;\n\t}\n\treturn fxID;\n}\n\nvoid __cdecl DoLotsOfBlood(int x, int y, int z, __int16 speed, __int16 direction, __int16 roomID, int number) {\n\tint i;\n\n\tfor (i = 0; i < number; ++i)\n\t\tDoBloodSplat(x - 512 * GetRandomDraw() / 32768 + 256,\n\t\t\t\t\ty - 512 * GetRandomDraw() / 32768 + 256,\n\t\t\t\t\tz - 512 * GetRandomDraw() / 32768 + 256,\n\t\t\t\t\tspeed,\n\t\t\t\t\tdirection,\n\t\t\t\t\troomID);\n}\n\nvoid __cdecl ControlBlood1(__int16 fxID) {\n\tFX_INFO *fx;\n\n\tfx = &Effects[fxID];\n\tfx->pos.x += fx->speed * phd_sin(fx->pos.rotY) >> W2V_SHIFT;\n\tfx->pos.z += fx->speed * phd_cos(fx->pos.rotY) >> W2V_SHIFT;\n\t++fx->counter;\n\tif (fx->counter == 4) {\n\t\t--fx->frame_number;\n\t\tfx->counter = 0;\n\t\tif (fx->frame_number <= Objects[fx->object_number].nMeshes)\n\t\t\tKillEffect(fxID);\n\t}\n}\n\nvoid __cdecl ControlExplosion1(__int16 fxID) {\n\tFX_INFO *fx;\n\n\tfx = &Effects[fxID];\n\t++fx->counter;\n\tif (fx->counter == 2) {\n\t\t--fx->frame_number;\n\t\tfx->counter = 0;\n\t\tif (fx->frame_number <= Objects[fx->object_number].nMeshes) {\n\t\t\tKillEffect(fxID);\n\t\t} else {\n\t\t\tAddDynamicLight(fx->pos.x, fx->pos.y, fx->pos.z, 13, 11);\n\t\t}\n\t} else {\n\t\tAddDynamicLight(fx->pos.x, fx->pos.y, fx->pos.z, 12, 10);\n\t}\n}\n\nvoid __cdecl Richochet(GAME_VECTOR *pos) {\n\t__int16 fxID = CreateEffect(pos->roomNumber);\n\tif( fxID < 0 ) {\n\t\treturn;\n\t}\n\tFX_INFO *fx = &Effects[fxID];\n\tfx->pos.x = pos->x;\n\tfx->pos.y = pos->y;\n\tfx->pos.z = pos->z;\n\tfx->counter = 4;\n\tfx->object_number = ID_RICOCHET;\n\tfx->frame_number = -3 * GetRandomDraw() / 0x8000;\n\tPlaySoundEffect(10, &fx->pos, 0);\n}\n\nvoid __cdecl ControlRichochet1(__int16 fxID) {\n\tFX_INFO *fx;\n\n\tfx = &Effects[fxID];\n\t--fx->counter;\n\tif (!fx->counter)\n\t\tKillEffect(fxID);\n}\n\nvoid __cdecl CreateBubble(PHD_3DPOS *pos, __int16 roomNumber) {\n\t__int16 fxID = CreateEffect(roomNumber);\n\tif( fxID < 0 ) return;\n\tFX_INFO *fx = &Effects[fxID];\n\tfx->pos = *pos;\n\tfx->speed = ((GetRandomDraw() * 6) >> 15) + 10;\n\tfx->frame_number = -((GetRandomDraw() * 3) >> 15);\n\tfx->object_number = ID_BUBBLES;\n}\n\nvoid __cdecl LaraBubbles(ITEM_INFO *item) {\n#ifdef FEATURE_CHEAT\n\tif( Lara.water_status == LWS_Cheat ) {\n\t\treturn;\n\t}\n#endif // FEATURE_CHEAT\n\tint counter = GetRandomDraw() * 3 / 0x8000;\n\tif( !counter ) return;\n\tPHD_VECTOR pos;\n\tpos.x = 0;\n\tpos.y = 0;\n\tpos.z = 50;\n\tPlaySoundEffect(37, &item->pos, SFX_UNDERWATER);\n\tGetJointAbsPosition(item, &pos, 14);\n\twhile( counter-- > 0 ) CreateBubble((PHD_3DPOS *)&pos, item->roomNumber);\n}\n\nvoid __cdecl ControlBubble1(__int16 fxID) {\n\tFX_INFO *fx;\n\tint x, y, z, ceiling;\n\t__int16 roomID;\n\tFLOOR_INFO *floor;\n\n\tfx = &Effects[fxID];\n\tfx->pos.rotY += 9 * PHD_DEGREE;\n\tfx->pos.rotX += 13 * PHD_DEGREE;\n\tx = fx->pos.x + (11 * phd_sin(fx->pos.rotY) >> W2V_SHIFT);\n\ty = fx->pos.y - fx->speed;\n\tz = fx->pos.z + (8 * phd_cos(fx->pos.rotX) >> W2V_SHIFT);\n\troomID = fx->room_number;\n\tfloor = GetFloor(x, y, z, &roomID);\n\tif (floor && CHK_ANY(RoomInfo[roomID].flags, ROOM_UNDERWATER)) {\n\t\tceiling = GetCeiling(floor, x, y, z);\n\t\tif (ceiling != -32512 && y > ceiling) {\n\t\t\tif (fx->room_number != roomID)\n\t\t\t\tEffectNewRoom(fxID, roomID);\n\t\t\tfx->pos.x = x;\n\t\t\tfx->pos.y = y;\n\t\t\tfx->pos.z = z;\n\t\t\treturn;\n\t\t}\n\t}\n\tKillEffect(fxID);\n}\n\nvoid __cdecl Splash(ITEM_INFO *item) {\n\tint y, i;\n\t__int16 roomID, fxID;\n\tFX_INFO *fx;\n\n\ty = GetWaterHeight(item->pos.x, item->pos.y, item->pos.z, item->roomNumber);\n\troomID = item->roomNumber;\n\tGetFloor(item->pos.x, item->pos.y, item->pos.z, &roomID);\n\tfor (i = 0; i < 10; ++i) {\n\t\tfxID = CreateEffect(roomID);\n\t\tif (fxID != -1) {\n\t\t\tfx = &Effects[fxID];\n\t\t\tfx->pos.x = item->pos.x;\n\t\t\tfx->pos.y = y;\n\t\t\tfx->pos.z = item->pos.z;\n\t\t\tfx->pos.rotY = 2 * GetRandomDraw() - 32768;\n\t\t\tfx->frame_number = 0;\n\t\t\tfx->object_number = ID_SPLASH;\n\t\t\tfx->speed = GetRandomDraw() / 256;\n\t\t}\n\t}\n}\n\nvoid WadeSplash(ITEM_INFO *item, int height) {\n\treturn; // NULL function\n}\n\nvoid __cdecl ControlSplash1(__int16 fxID) {\n\tFX_INFO *fx;\n\n\tfx = &Effects[fxID];\n\t--fx->frame_number;\n\tif (fx->frame_number <= Objects[fx->object_number].nMeshes) {\n\t\tKillEffect(fxID);\n\t} else {\n\t\tfx->pos.z += fx->speed * phd_cos(fx->pos.rotY) >> W2V_SHIFT;\n\t\tfx->pos.x += fx->speed * phd_sin(fx->pos.rotY) >> W2V_SHIFT;\n\t}\n}\n\nvoid __cdecl ControlWaterSprite(__int16 fxID) {\n\tFX_INFO *fx;\n\n\tfx = &Effects[fxID];\n\t--fx->counter;\n\tif (!CHK_ANY(fx->counter, 3)) {\n\t\t--fx->frame_number;\n\t\tif (fx->frame_number <= Objects[fx->object_number].nMeshes)\n\t\t\tfx->frame_number = 0;\n\t}\n\tif (fx->counter && fx->fallspeed <= 0) {\n\t\tfx->pos.z += fx->speed * phd_cos(fx->pos.rotY) >> W2V_SHIFT;\n\t\tfx->pos.x += fx->speed * phd_sin(fx->pos.rotY) >> W2V_SHIFT;\n\t\tif (fx->fallspeed) {\n\t\t\tfx->pos.y += fx->fallspeed;\n\t\t\tfx->fallspeed += 6;\n\t\t}\n\t} else {\n\t\tKillEffect(fxID);\n\t}\n}\n\nvoid __cdecl ControlSnowSprite(__int16 fxID) {\n\tFX_INFO *fx;\n\n\tfx = &Effects[fxID];\n\t--fx->frame_number;\n\tif (fx->frame_number <= Objects[fx->object_number].nMeshes) {\n\t\tKillEffect(fxID);\n\t} else {\n\t\tfx->pos.z += fx->speed * phd_cos(fx->pos.rotY) >> W2V_SHIFT;\n\t\tfx->pos.x += fx->speed * phd_sin(fx->pos.rotY) >> W2V_SHIFT;\n\t\tif (fx->fallspeed) {\n\t\t\tfx->pos.y += fx->fallspeed;\n\t\t\tfx->fallspeed += 6;\n\t\t}\n\t}\n}\n\nvoid __cdecl ControlHotLiquid(__int16 fxID) {\n\tFX_INFO *fx;\n\t__int16 roomID;\n\tint height;\n\n\tfx = &Effects[fxID];\n\t--fx->frame_number;\n\tif (fx->frame_number <= Objects[ID_HOT_LIQUID].nMeshes)\n\t\tfx->frame_number = 0;\n\tfx->pos.y += fx->fallspeed;\n\tfx->fallspeed += 6;\n\troomID = fx->room_number;\n\theight = GetHeight(GetFloor(fx->pos.x, fx->pos.y, fx->pos.z, &roomID), fx->pos.x, fx->pos.y, fx->pos.z);\n\tif (fx->pos.y >= height) {\n\t\tPlaySoundEffect(285, &fx->pos, 0);\n\t\tfx->object_number = ID_SPLASH;\n\t\tfx->pos.y = height;\n\t\tfx->pos.rotY = 2 * GetRandomDraw();\n\t\tfx->fallspeed = 0;\n\t\tfx->speed = 50;\n\t} else {\n\t\tif (fx->room_number != roomID)\n\t\t\tEffectNewRoom(fxID, roomID);\n\t\tPlaySoundEffect(284, &fx->pos, 0);\n\t}\n}\n\nvoid __cdecl WaterFall(__int16 itemID) {\n\tITEM_INFO *item;\n\t__int16 fxID;\n\tFX_INFO *fx;\n\n\titem = &Items[itemID];\n\tif (ABS(item->pos.x - LaraItem->pos.x) <= 10240 &&\n\t\tABS(item->pos.z - LaraItem->pos.z) <= 10240 &&\n\t\tABS(item->pos.y - LaraItem->pos.y) <= 10240)\n\t{\n\t\tS_CalculateLight(item->pos.x, item->pos.y, item->pos.z, item->roomNumber);\n\t\tfxID = CreateEffect(item->roomNumber);\n\t\tif (fxID != -1) {\n\t\t\tfx = &Effects[fxID];\n\t\t\tfx->pos.x = item->pos.x + 1024 * (GetRandomDraw() - 16384) / 32767;\n\t\t\tfx->pos.z = item->pos.z + 1024 * (GetRandomDraw() - 16384) / 32767;\n\t\t\tfx->pos.y = item->pos.y;\n\t\t\tfx->speed = 0;\n\t\t\tfx->frame_number = 0;\n\t\t\tfx->shade = LsAdder;\n\t\t\tfx->object_number = ID_SPLASH;\n\t\t}\n\t\tPlaySoundEffect(79, &item->pos, 0);\n\t}\n}\n\nvoid __cdecl finish_level_effect(ITEM_INFO *item) {\n\tIsLevelComplete = TRUE;\n}\n\nvoid __cdecl turn180_effect(ITEM_INFO *item) {\n\titem->pos.rotX = -item->pos.rotX;\n\titem->pos.rotY += PHD_180;\n}\n\nvoid __cdecl floor_shake_effect(ITEM_INFO *item) {\n\tint dx, dy, dz;\n\n\tdx = item->pos.x - Camera.pos.x;\n\tdy = item->pos.y - Camera.pos.y;\n\tdz = item->pos.z - Camera.pos.z;\n\tif (ABS(dx) < 16384 && ABS(dy) < 16384 && ABS(dz) < 16384)\n\t\tCamera.bounce = 100 * (SQR(1024) - (SQR(dx) + SQR(dy) + SQR(dz)) / 256) / SQR(1024);\n}\n\nvoid __cdecl lara_normal_effect(ITEM_INFO *item) {\n\titem->currentAnimState = AS_STOP;\n\titem->goalAnimState = AS_STOP;\n\titem->animNumber = 11;\n\titem->frameNumber = Anims[item->animNumber].frameBase;\n\tCamera.type = CAM_Chase;\n\tAlterFOV(80 * PHD_DEGREE);\n}\n\nvoid __cdecl BoilerFX(ITEM_INFO *item) {\n\tPlaySoundEffect(338, NULL, 0);\n\tFlipEffect = -1;\n}\n\nvoid __cdecl FloodFX(ITEM_INFO *item) {\n\tPHD_3DPOS pos;\n\n\tif (FlipTimer > 120) {\n\t\tFlipEffect = -1;\n\t} else {\n\t\tpos.x = LaraItem->pos.x;\n\t\tif (FlipTimer < 30) {\n\t\t\tpos.y = 100 * (30 - FlipTimer) + Camera.target.y;\n\t\t} else {\n\t\t\tpos.y = 100 * (FlipTimer - 30) + Camera.target.y;\n\t\t}\n\t\tpos.z = LaraItem->pos.z;\n\t\tPlaySoundEffect(79, &pos, 0);\n\t}\n\t++FlipTimer;\n}\n\nvoid __cdecl RubbleFX(ITEM_INFO *item) {\n\tPlaySoundEffect(24, NULL, 0);\n\tCamera.bounce = -350;\n\tFlipEffect = -1;\n}\n\nvoid __cdecl ChandelierFX(ITEM_INFO *item) {\n\tPlaySoundEffect(278, NULL, 0);\n\t++FlipTimer;\n\tif (FlipTimer > 30)\n\t\tFlipEffect = -1;\n}\n\nvoid __cdecl ExplosionFX(ITEM_INFO *item) {\n\tPlaySoundEffect(105, NULL, 0);\n\tCamera.bounce = -75;\n\tFlipEffect = -1;\n}\n\nvoid __cdecl PistonFX(ITEM_INFO *item) {\n\tPlaySoundEffect(190, NULL, 0);\n\tFlipEffect = -1;\n}\n\nvoid __cdecl CurtainFX(ITEM_INFO *item) {\n\tPlaySoundEffect(191, NULL, 0);\n\tFlipEffect = -1;\n}\n\nvoid __cdecl StatueFX(ITEM_INFO *item) {\n\tPlaySoundEffect(331, NULL, 0);\n\tFlipEffect = -1;\n}\n\nvoid __cdecl SetChangeFX(ITEM_INFO *item) {\n\tPlaySoundEffect(330, NULL, 0);\n\tFlipEffect = -1;\n}\n\nvoid __cdecl ControlDingDong(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\tif (CHK_ALL(item->flags, IFL_CODEBITS)) {\n\t\tPlaySoundEffect(334, &item->pos, 0);\n\t\titem->flags -= IFL_CODEBITS;\n\t}\n}\n\nvoid __cdecl ControlLaraAlarm(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\tif (CHK_ALL(item->flags, IFL_CODEBITS))\n\t\tPlaySoundEffect(335, &item->pos, 0);\n}\n\nvoid __cdecl ControlAlarmSound(__int16 itemID) {\n\tITEM_INFO *item;\n\tint counter;\n\n\titem = &Items[itemID];\n\tif (CHK_ALL(item->flags, IFL_CODEBITS)) {\n\t\tPlaySoundEffect(332, &item->pos, 0);\n\t\tcounter = (int) item->data + 1;\n\t\tif (counter > 6) {\n\t\t\tAddDynamicLight(item->pos.x, item->pos.y, item->pos.z, 12, 11);\n\t\t\tif (counter > 12)\n\t\t\t\tcounter = 0;\n\t\t}\n\t\titem->data = (LPVOID) counter;\n\t}\n}\n\nvoid __cdecl ControlBirdTweeter(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\tif (item->objectID == ID_BIRD_TWEETER2) {\n\t\tif (GetRandomDraw() < 1024)\n\t\t\tPlaySoundEffect(316, &item->pos, 0);\n\t} else {\n\t\tif (GetRandomDraw() < 256)\n\t\t\tPlaySoundEffect(329, &item->pos, 0);\n\t}\n}\n\nvoid __cdecl DoChimeSound(ITEM_INFO *item) {\n\tPHD_3DPOS pos;\n\n\tpos.x = LaraItem->pos.x + ((item->pos.x - LaraItem->pos.x) >> 6);\n\tpos.y = LaraItem->pos.y + ((item->pos.y - LaraItem->pos.y) >> 6);\n\tpos.z = LaraItem->pos.z + ((item->pos.z - LaraItem->pos.z) >> 6);\n\tPlaySoundEffect(208, &pos, 0);\n}\n\nvoid __cdecl ControlClockChimes(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\tif (item->timer) {\n\t\tif (item->timer % 60 == 59)\n\t\t\tDoChimeSound(item);\n\t\t--item->timer;\n\t\tif (!item->timer) {\n\t\t\tDoChimeSound(item);\n\t\t\titem->timer = -1;\n\t\t\tRemoveActiveItem(itemID);\n\t\t\titem->status = ITEM_INACTIVE;\n\t\t\titem->flags &= ~IFL_CODEBITS;\n\t\t}\n\t}\n}\n\nvoid __cdecl SphereOfDoomCollision(__int16 itemID, ITEM_INFO *laraItem, COLL_INFO *coll) {\n\tITEM_INFO *item;\n\tint dx, dz, distance, angle;\n\n\tif (!CHK_ANY(RoomInfo[laraItem->roomNumber].flags, ROOM_UNDERWATER)) {\n\t\titem = &Items[itemID];\n\t\tdx = laraItem->pos.x - item->pos.x;\n\t\tdz = laraItem->pos.z - item->pos.z;\n\t\tdistance = 5 * item->timer >> 1;\n\t\tif (SQR(dx) + SQR(dz) < SQR(distance)) {\n\t\t\tangle = phd_atan(dz, dx);\n\t\t\tif (ABS(laraItem->pos.rotY - angle) < PHD_90) {\n\t\t\t\tlaraItem->speed = 150;\n\t\t\t\tlaraItem->pos.rotY = angle;\n\t\t\t} else {\n\t\t\t\tlaraItem->speed = -150;\n\t\t\t\tlaraItem->pos.rotY = angle + PHD_180;\n\t\t\t}\n\t\t\tlaraItem->gravity = 1;\n\t\t\tlaraItem->fallSpeed = -50;\n\t\t\tlaraItem->pos.z = item->pos.z + (phd_cos(angle) * (distance + 50) >> W2V_SHIFT);\n\t\t\tlaraItem->pos.x = item->pos.x + (phd_sin(angle) * (distance + 50) >> W2V_SHIFT);\n\t\t\tlaraItem->pos.rotZ = 0;\n\t\t\tlaraItem->pos.rotX = 0;\n\t\t\tLaraItem->animNumber = 34;\n\t\t\tLaraItem->frameNumber = Anims[LaraItem->animNumber].frameBase;\n\t\t\tLaraItem->currentAnimState = AS_FORWARDJUMP;\n\t\t\tLaraItem->goalAnimState = AS_FORWARDJUMP;\n\t\t}\n\t}\n}\n\nvoid __cdecl SphereOfDoom(__int16 itemID) {\n\tITEM_INFO *item;\n\tint dx, dy, dz, distance, difference;\n\tPHD_3DPOS pos;\n\n\titem = &Items[itemID];\n\titem->timer += 64;\n\titem->pos.rotY += item->objectID == ID_SPHERE_OF_DOOM2 ? 10 * PHD_DEGREE : -10 * PHD_DEGREE;\n\tdx = item->pos.x - LaraItem->pos.x;\n\tdy = item->pos.y - LaraItem->pos.y;\n\tdz = item->pos.z - LaraItem->pos.z;\n\tdistance = 5 * item->timer >> 1;\n\tdifference = phd_sqrt(SQR(dx) + SQR(dy) + SQR(dz)) - distance;\n\tpos.x = LaraItem->pos.x + difference * dx / distance;\n\tpos.y = LaraItem->pos.y + difference * dy / distance;\n\tpos.z = LaraItem->pos.z + difference * dz / distance;\n\tPlaySoundEffect(341, &pos, 0);\n\tif (item->timer > 3840)\n\t\tKillItem(itemID);\n}\n\nvoid __cdecl DrawSphereOfDoom(ITEM_INFO *item) {\n\tint clip;\n\n\tphd_PushMatrix();\n\tphd_TranslateAbs(item->pos.x, item->pos.y, item->pos.z);\n\tphd_RotY(item->pos.rotY);\n\tPhdMatrixPtr->_00 = item->timer * PhdMatrixPtr->_00 >> 8;\n\tPhdMatrixPtr->_01 = item->timer * PhdMatrixPtr->_01 >> 8;\n\tPhdMatrixPtr->_02 = item->timer * PhdMatrixPtr->_02 >> 8;\n\tPhdMatrixPtr->_10 = item->timer * PhdMatrixPtr->_10 >> 8;\n\tPhdMatrixPtr->_11 = item->timer * PhdMatrixPtr->_11 >> 8;\n\tPhdMatrixPtr->_12 = item->timer * PhdMatrixPtr->_12 >> 8;\n\tPhdMatrixPtr->_20 = item->timer * PhdMatrixPtr->_20 >> 8;\n\tPhdMatrixPtr->_21 = item->timer * PhdMatrixPtr->_21 >> 8;\n\tPhdMatrixPtr->_22 = item->timer * PhdMatrixPtr->_22 >> 8;\n\tclip = S_GetObjectBounds(Anims[item->animNumber].framePtr);\n\tif (clip) {\n\t\tCalculateObjectLighting(item, Anims[item->animNumber].framePtr);\n\t\tphd_PutPolygons(MeshPtr[Objects[item->objectID].meshIndex], clip);\n\t}\n\tphd_PopMatrix();\n}\n\nvoid __cdecl lara_hands_free(ITEM_INFO *item) {\n\tLara.gun_status = LGS_Armless;\n}\n\nvoid __cdecl flip_map_effect(ITEM_INFO *item) {\n\tFlipMap();\n}\n\nvoid __cdecl draw_right_gun(ITEM_INFO *item) {\n\t__int16 *tmp;\n\n\tSWAP(Lara.mesh_ptrs[4], MeshPtr[Objects[ID_LARA_PISTOLS].meshIndex + 4], tmp);\n\tSWAP(Lara.mesh_ptrs[10], MeshPtr[Objects[ID_LARA_PISTOLS].meshIndex + 10], tmp);\n}\n\nvoid __cdecl draw_left_gun(ITEM_INFO *item) {\n\t__int16 *tmp;\n\n\tSWAP(Lara.mesh_ptrs[1], MeshPtr[Objects[ID_LARA_PISTOLS].meshIndex + 1], tmp);\n\tSWAP(Lara.mesh_ptrs[13], MeshPtr[Objects[ID_LARA_PISTOLS].meshIndex + 13], tmp);\n}\n\nvoid __cdecl swap_meshes_with_meshswap1(ITEM_INFO *item) {\n\tint i;\n\t__int16 *tmp;\n\n\tfor (i = 0; i < Objects[item->objectID].nMeshes; ++i)\n\t\tSWAP(MeshPtr[Objects[item->objectID].meshIndex + i], MeshPtr[Objects[ID_MESH_SWAP1].meshIndex + i], tmp);\n}\n\nvoid __cdecl swap_meshes_with_meshswap2(ITEM_INFO *item) {\n\tint i;\n\t__int16 *tmp;\n\n\tfor (i = 0; i < Objects[item->objectID].nMeshes; ++i)\n\t\tSWAP(MeshPtr[Objects[item->objectID].meshIndex + i], MeshPtr[Objects[ID_MESH_SWAP2].meshIndex + i], tmp);\n}\n\nvoid __cdecl swap_meshes_with_meshswap3(ITEM_INFO *item) {\n\tint i;\n\t__int16 *tmp;\n\n\tfor (i = 0; i < Objects[item->objectID].nMeshes; ++i) {\n\t\tif (item == LaraItem)\n\t\t\tLara.mesh_ptrs[i] = MeshPtr[Objects[ID_LARA_SWAP].meshIndex + i];\n\t\tSWAP(MeshPtr[Objects[item->objectID].meshIndex + i], MeshPtr[Objects[ID_LARA_SWAP].meshIndex + i], tmp);\n\t}\n}\n\nvoid __cdecl invisibility_on(ITEM_INFO *item) {\n\titem->status = ITEM_INVISIBLE;\n}\n\nvoid __cdecl invisibility_off(ITEM_INFO *item) {\n\titem->status = ITEM_ACTIVE;\n}\n\nvoid __cdecl dynamic_light_on(ITEM_INFO *item) {\n\titem->dynamic_light = 1;\n}\n\nvoid __cdecl dynamic_light_off(ITEM_INFO *item) {\n\titem->dynamic_light = 0;\n}\n\nvoid __cdecl reset_hair(ITEM_INFO *item) {\n\tInitialiseHair();\n}\n\nvoid __cdecl AssaultStart(ITEM_INFO *item) {\n\tSaveGame.statistics.timer = 0;\n\tIsAssaultTimerActive = TRUE;\n\tIsAssaultTimerDisplay = TRUE;\n\tFlipEffect = -1;\n}\n\nvoid __cdecl AssaultStop(ITEM_INFO *item) {\n\tIsAssaultTimerActive = FALSE;\n\tIsAssaultTimerDisplay = TRUE;\n\tFlipEffect = -1;\n}\n\nvoid __cdecl AssaultReset(ITEM_INFO *item) {\n\tIsAssaultTimerActive = FALSE;\n\tIsAssaultTimerDisplay = FALSE;\n\tFlipEffect = -1;\n}\n\nvoid __cdecl AssaultFinished(ITEM_INFO *item) {\n\tif (IsAssaultTimerActive) {\n\t\tAddAssaultTime(SaveGame.statistics.timer);\n\t\tif (AssaultBestTime < 0) {\n\t\t\tif (SaveGame.statistics.timer < 3000) {\n\t\t\t\tS_CDPlay(22, FALSE);\n\t\t\t\tAssaultBestTime = SaveGame.statistics.timer;\n\t\t\t} else {\n\t\t\t\tS_CDPlay(24, FALSE);\n\t\t\t\tAssaultBestTime = 3000;\n\t\t\t}\n\t\t} else {\n\t\t\tif (SaveGame.statistics.timer < (DWORD) AssaultBestTime) {\n\t\t\t\tS_CDPlay(22, FALSE);\n\t\t\t\tAssaultBestTime = SaveGame.statistics.timer;\n\t\t\t} else {\n\t\t\t\tS_CDPlay(SaveGame.statistics.timer >= (DWORD) AssaultBestTime + 150 ? 21 : 23, FALSE);\n\t\t\t}\n\t\t}\n\t\tIsAssaultTimerActive = FALSE;\n\t}\n\tFlipEffect = -1;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Effects() {\n\tINJECT(0x0041C4B0, ItemNearLara);\n\tINJECT(0x0041C540, SoundEffects);\n\tINJECT(0x0041C5B0, DoBloodSplat);\n\tINJECT(0x0041C610, DoLotsOfBlood);\n\tINJECT(0x0041C6C0, ControlBlood1);\n\tINJECT(0x0041C750, ControlExplosion1);\n\tINJECT(0x0041C7D0, Richochet);\n\tINJECT(0x0041C850, ControlRichochet1);\n\tINJECT(0x0041C880, CreateBubble);\n\tINJECT(0x0041C8F0, LaraBubbles);\n\tINJECT(0x0041C970, ControlBubble1);\n\tINJECT(0x0041CA70, Splash);\n\n//\tINJECT(----------, WadeSplash);\n\n\tINJECT(0x0041CB40, ControlSplash1);\n\tINJECT(0x0041CBC0, ControlWaterSprite);\n\tINJECT(0x0041CC70, ControlSnowSprite);\n\tINJECT(0x0041CD00, ControlHotLiquid);\n\tINJECT(0x0041CDE0, WaterFall);\n\tINJECT(0x0041CF20, finish_level_effect);\n\tINJECT(0x0041CF30, turn180_effect);\n\tINJECT(0x0041CF50, floor_shake_effect);\n\tINJECT(0x0041CFF0, lara_normal_effect);\n\tINJECT(0x0041D030, BoilerFX);\n\tINJECT(0x0041D050, FloodFX);\n\tINJECT(0x0041D0E0, RubbleFX);\n\tINJECT(0x0041D110, ChandelierFX);\n\tINJECT(0x0041D140, ExplosionFX);\n\tINJECT(0x0041D170, PistonFX);\n\tINJECT(0x0041D190, CurtainFX);\n\tINJECT(0x0041D1B0, StatueFX);\n\tINJECT(0x0041D1D0, SetChangeFX);\n\tINJECT(0x0041D1F0, ControlDingDong);\n\tINJECT(0x0041D230, ControlLaraAlarm);\n\tINJECT(0x0041D270, ControlAlarmSound);\n\tINJECT(0x0041D2E0, ControlBirdTweeter);\n\tINJECT(0x0041D340, DoChimeSound);\n\tINJECT(0x0041D3A0, ControlClockChimes);\n\tINJECT(0x0041D410, SphereOfDoomCollision);\n\tINJECT(0x0041D540, SphereOfDoom);\n\tINJECT(0x0041D630, DrawSphereOfDoom);\n\tINJECT(0x0041D760, lara_hands_free);\n\tINJECT(0x0041D770, flip_map_effect);\n\tINJECT(0x0041D780, draw_right_gun);\n\tINJECT(0x0041D7D0, draw_left_gun);\n\n//\tINJECT(----------, shoot_right_gun);\n//\tINJECT(----------, shoot_left_gun);\n\n\tINJECT(0x0041D820, swap_meshes_with_meshswap1);\n\tINJECT(0x0041D890, swap_meshes_with_meshswap2);\n\tINJECT(0x0041D900, swap_meshes_with_meshswap3);\n\tINJECT(0x0041D9A0, invisibility_on);\n\tINJECT(0x0041D9B0, invisibility_off);\n\tINJECT(0x0041D9D0, dynamic_light_on);\n\tINJECT(0x0041D9E0, dynamic_light_off);\n\tINJECT(0x0041D9F0, reset_hair);\n\tINJECT(0x0041DA00, AssaultStart);\n\tINJECT(0x0041DA30, AssaultStop);\n\tINJECT(0x0041DA50, AssaultReset);\n\tINJECT(0x0041DA70, AssaultFinished);\n}\n"
  },
  {
    "path": "game/effects.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef EFFECTS_H_INCLUDED\n#define EFFECTS_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nint __cdecl ItemNearLara(PHD_3DPOS *pos, int distance); // 0x0041C4B0\nvoid __cdecl SoundEffects(); // 0x0041C540\n__int16 __cdecl DoBloodSplat(int x, int y, int z, __int16 speed, __int16 direction, __int16 roomID); // 0x0041C5B0\nvoid __cdecl DoLotsOfBlood(int x, int y, int z, __int16 speed, __int16 direction, __int16 roomID, int number); // 0x0041C610\nvoid __cdecl ControlBlood1(__int16 fxID); // 0x0041C6C0\nvoid __cdecl ControlExplosion1(__int16 fxID); // 0x0041C750\nvoid __cdecl Richochet(GAME_VECTOR *pos); // 0x0041C7D0\nvoid __cdecl ControlRichochet1(__int16 fxID); // 0x0041C850\nvoid __cdecl CreateBubble(PHD_3DPOS *pos, __int16 roomNumber); // 0x0041C880\nvoid __cdecl LaraBubbles(ITEM_INFO *item); // 0x0041C8F0\nvoid __cdecl ControlBubble1(__int16 fxID); // 0x0041C970\nvoid __cdecl Splash(ITEM_INFO *item); // 0x0041CA70\nvoid WadeSplash(ITEM_INFO *item, int height);\nvoid __cdecl ControlSplash1(__int16 fxID); // 0x0041CB40\nvoid __cdecl ControlWaterSprite(__int16 fxID); // 0x0041CBC0\nvoid __cdecl ControlSnowSprite(__int16 fxID); // 0x0041CC70\nvoid __cdecl ControlHotLiquid(__int16 fxID); // 0x0041CD00\nvoid __cdecl WaterFall(__int16 itemID); // 0x0041CDE0\nvoid __cdecl finish_level_effect(ITEM_INFO *item); // 0x0041CF20\nvoid __cdecl turn180_effect(ITEM_INFO *item); // 0x0041CF30\nvoid __cdecl floor_shake_effect(ITEM_INFO *item); // 0x0041CF50\nvoid __cdecl lara_normal_effect(ITEM_INFO *item); // 0x0041CFF0\nvoid __cdecl BoilerFX(ITEM_INFO *item); // 0x0041D030\nvoid __cdecl FloodFX(ITEM_INFO *item); // 0x0041D050\nvoid __cdecl RubbleFX(ITEM_INFO *item); // 0x0041D0E0\nvoid __cdecl ChandelierFX(ITEM_INFO *item); // 0x0041D110\nvoid __cdecl ExplosionFX(ITEM_INFO *item); // 0x0041D140\nvoid __cdecl PistonFX(ITEM_INFO *item); // 0x0041D170\nvoid __cdecl CurtainFX(ITEM_INFO *item); // 0x0041D190\nvoid __cdecl StatueFX(ITEM_INFO *item); // 0x0041D1B0\nvoid __cdecl SetChangeFX(ITEM_INFO *item); // 0x0041D1D0\nvoid __cdecl ControlDingDong(__int16 itemID); // 0x0041D1F0\nvoid __cdecl ControlLaraAlarm(__int16 itemID); // 0x0041D230\nvoid __cdecl ControlAlarmSound(__int16 itemID); // 0x0041D270\nvoid __cdecl ControlBirdTweeter(__int16 itemID); // 0x0041D2E0\nvoid __cdecl DoChimeSound(ITEM_INFO *item); // 0x0041D340\nvoid __cdecl ControlClockChimes(__int16 itemID); // 0x0041D3A0\nvoid __cdecl SphereOfDoomCollision(__int16 itemID, ITEM_INFO *laraItem, COLL_INFO *coll); // 0x0041D410\nvoid __cdecl SphereOfDoom(__int16 itemID); // 0x0041D540\nvoid __cdecl DrawSphereOfDoom(ITEM_INFO *item); // 0x0041D630\nvoid __cdecl lara_hands_free(ITEM_INFO *item); // 0x0041D760\nvoid __cdecl flip_map_effect(ITEM_INFO *item); // 0x0041D770\nvoid __cdecl draw_right_gun(ITEM_INFO *item); // 0x0041D780\nvoid __cdecl draw_left_gun(ITEM_INFO *item); // 0x0041D7D0\n\n//\t----------:\t\tshoot_right_gun\n//\t----------:\t\tshoot_left_gun\n\nvoid __cdecl swap_meshes_with_meshswap1(ITEM_INFO *item); // 0x0041D820\nvoid __cdecl swap_meshes_with_meshswap2(ITEM_INFO *item); // 0x0041D890\nvoid __cdecl swap_meshes_with_meshswap3(ITEM_INFO *item); // 0x0041D900\nvoid __cdecl invisibility_on(ITEM_INFO *item); // 0x0041D9A0\nvoid __cdecl invisibility_off(ITEM_INFO *item); // 0x0041D9B0\nvoid __cdecl dynamic_light_on(ITEM_INFO *item); // 0x0041D9D0\nvoid __cdecl dynamic_light_off(ITEM_INFO *item); // 0x0041D9E0\nvoid __cdecl reset_hair(ITEM_INFO *item); // 0x0041D9F0\nvoid __cdecl AssaultStart(ITEM_INFO *item); // 0x0041DA00\nvoid __cdecl AssaultStop(ITEM_INFO *item); // 0x0041DA30\nvoid __cdecl AssaultReset(ITEM_INFO *item); // 0x0041DA50\nvoid __cdecl AssaultFinished(ITEM_INFO *item); // 0x0041DA70\n\n#endif // EFFECTS_H_INCLUDED\n"
  },
  {
    "path": "game/enemies.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/enemies.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Enemies() {\n//\tINJECT(0x0041DB30, Knife);\n//\tINJECT(0x0041DBB0, Cult2Control);\n//\tINJECT(0x0041DFE0, MonkControl);\n//\tINJECT(0x0041E4B0, Worker3Control);\n//\tINJECT(0x0041EAC0, DrawXianLord);\n//\tINJECT(0x0041EEC0, XianDamage);\n//\tINJECT(0x0041EF70, InitialiseXianLord);\n//\tINJECT(0x0041EFD0, XianLordControl);\n//\tINJECT(0x0041F5B0, WarriorSparkleTrail);\n//\tINJECT(0x0041F650, WarriorControl);\n}\n"
  },
  {
    "path": "game/enemies.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef ENEMIES_H_INCLUDED\n#define ENEMIES_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x0041DB30:\t\tKnife\n\n#define Cult2Control ((void(__cdecl*)(__int16)) 0x0041DBB0)\n#define MonkControl ((void(__cdecl*)(__int16)) 0x0041DFE0)\n#define Worker3Control ((void(__cdecl*)(__int16)) 0x0041E4B0)\n#define DrawXianLord ((void(__cdecl*)(ITEM_INFO *)) 0x0041EAC0)\n\n//\t0x0041EEC0:\t\tXianDamage\n\n#define InitialiseXianLord ((void(__cdecl*)(__int16)) 0x0041EF70)\n#define XianLordControl ((void(__cdecl*)(__int16)) 0x0041EFD0)\n\n//\t0x0041F5B0:\t\tWarriorSparkleTrail\n\n#define WarriorControl ((void(__cdecl*)(__int16)) 0x0041F650)\n\n#endif // ENEMIES_H_INCLUDED\n"
  },
  {
    "path": "game/gameflow.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/cinema.h\"\n#include \"game/demo.h\"\n#include \"game/gameflow.h\"\n#include \"game/health.h\"\n#include \"game/invfunc.h\"\n#include \"game/invtext.h\"\n#include \"specific/file.h\"\n#include \"specific/frontend.h\"\n#include \"specific/game.h\"\n#include \"specific/output.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/background_new.h\"\n\nbool LoadingScreensEnabled = true;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\nstatic int CurrentEvent = GFE_END_SEQ; // NOTE: not presented in the original game\n\n// NOTE: there is no such function in the original code\nstatic bool GF_GetSequenceValue(DWORD levelID, GF_EVENTS event, __int16 *pValue, __int16 defValue) {\n\tif( levelID >= GF_GameFlow.num_Levels ) {\n\t\treturn false;\n\t}\n\t__int16 *seq = GF_ScriptTable[levelID];\n\t__int16 operand = 0;\n\tbool result = false;\n\n\tif( pValue != NULL) {\n\t\t*pValue = defValue; // set default value just in case\n\t}\n\n\twhile( *seq != GFE_END_SEQ ) {\n\t\t__int16 seqCode = *seq;\n\t\tswitch( seqCode ) {\n\t\t\tcase GFE_STARTLEVEL :\n\t\t\tcase GFE_LOADINGPIC :\n\t\t\tcase GFE_DEMOPLAY :\n\t\t\tcase GFE_CUTANGLE :\n\t\t\tcase GFE_CUTSCENE :\n\t\t\tcase GFE_PLAYFMV :\n\t\t\tcase GFE_PICTURE :\n\t\t\tcase GFE_JUMPTO_SEQ :\n\t\t\tcase GFE_SETTRACK :\n\t\t\tcase GFE_NOFLOOR :\n\t\t\tcase GFE_STARTANIM :\n\t\t\tcase GFE_NUMSECRETS :\n\t\t\tcase GFE_ADD2INV :\n\t\t\t\toperand = seq[1];\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\t\t\tcase GFE_LEVCOMPLETE :\n\t\t\tcase GFE_GAMECOMPLETE :\n\t\t\tcase GFE_SUNSET :\n\t\t\tcase GFE_DEADLY_WATER :\n\t\t\tcase GFE_REMOVE_WEAPONS :\n\t\t\tcase GFE_REMOVE_AMMO :\n\t\t\tcase GFE_KILL2COMPLETE :\n\t\t\tcase GFE_LIST_START :\n\t\t\tcase GFE_LIST_END :\n\t\t\t\toperand = 0;\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\treturn result;\n\t\t}\n\n\t\tif( seqCode == event ) {\n\t\t\t// the event is found in the sequence\n\t\t\tif( pValue == NULL) {\n\t\t\t\t// if we don't need operand value, just return here\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\t// if we need the value, search until the end, the last value is correct one\n\t\t\t\tresult = true;\n\t\t\t\t*pValue = operand;\n\t\t\t}\n\t\t}\n\t}\n\treturn result;\n}\n\n// NOTE: there is no such function in the original code\nint GF_GetNumSecrets(DWORD levelID) {\n\t__int16 result = 3;\n\tGF_GetSequenceValue(levelID, GFE_NUMSECRETS, &result, result);\n\treturn result;\n}\n\n// NOTE: there is no such function in the original code\nbool GF_IsFinalLevel(DWORD levelID) {\n\treturn GF_GetSequenceValue(levelID, GFE_GAMECOMPLETE, NULL, 0);\n}\n\nBOOL __cdecl GF_LoadScriptFile(LPCTSTR fileName) {\n\tGF_SunsetEnabled = 0;\n\n\tif( !S_LoadGameFlow(fileName) )\n\t\treturn FALSE;\n\n\tGF_GameFlow.levelCompleteTrack = 41; // \"level complete\" track is hardcoded for some reason\n\n\tInvCompassOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_Statistics];\n\n\tInvPistolOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_Pistols];\n\tInvShotgunOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_Shotgun];\n\tInvMagnumOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_Magnums];\n\tInvUziOption.lpString\t\t\t= GF_GameStringTable[GSI_InvItem_Uzis];\n\tInvHarpoonOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_Harpoon];\n\tInvM16Option.lpString\t\t\t= GF_GameStringTable[GSI_InvItem_M16];\n\tInvGrenadeOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_Grenade];\n\n\tInvFlareOption.lpString\t\t\t= GF_GameStringTable[GSI_InvItem_Flare];\n\n\tInvPistolAmmoOption.lpString\t= GF_GameStringTable[GSI_InvItem_PistolAmmo];\n\tInvShotgunAmmoOption.lpString\t= GF_GameStringTable[GSI_InvItem_ShotgunAmmo];\n\tInvMagnumAmmoOption.lpString\t= GF_GameStringTable[GSI_InvItem_MagnumAmmo];\n\tInvUziAmmoOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_UziAmmo];\n\tInvHarpoonAmmoOption.lpString\t= GF_GameStringTable[GSI_InvItem_HarpoonAmmo];\n\tInvM16AmmoOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_M16Ammo];\n\tInvGrenadeAmmoOption.lpString\t= GF_GameStringTable[GSI_InvItem_GrenadeAmmo];\n\n\tInvSmallMedipackOption.lpString\t= GF_GameStringTable[GSI_InvItem_SmallMedipack];\n\tInvLargeMedipackOption.lpString\t= GF_GameStringTable[GSI_InvItem_LargeMedipack];\n\n\tInvPickup1Option.lpString\t\t= GF_GameStringTable[GSI_InvItem_Pickup];\n\tInvPickup2Option.lpString\t\t= GF_GameStringTable[GSI_InvItem_Pickup];\n\n\tInvPuzzle1Option.lpString\t\t= GF_GameStringTable[GSI_InvItem_Puzzle];\n\tInvPuzzle2Option.lpString\t\t= GF_GameStringTable[GSI_InvItem_Puzzle];\n\tInvPuzzle3Option.lpString\t\t= GF_GameStringTable[GSI_InvItem_Puzzle];\n\tInvPuzzle4Option.lpString\t\t= GF_GameStringTable[GSI_InvItem_Puzzle];\n\n\tInvKey1Option.lpString\t\t\t= GF_GameStringTable[GSI_InvItem_Key];\n\tInvKey2Option.lpString\t\t\t= GF_GameStringTable[GSI_InvItem_Key];\n\tInvKey3Option.lpString\t\t\t= GF_GameStringTable[GSI_InvItem_Key];\n\tInvKey4Option.lpString\t\t\t= GF_GameStringTable[GSI_InvItem_Key];\n\n\tInvPassportOption.lpString\t\t= GF_GameStringTable[GSI_InvItem_Game];\n\tInvPhotoOption.lpString\t\t\t= GF_GameStringTable[GSI_InvItem_LaraHome];\n\n\tInvDetailOption.lpString\t\t= GF_SpecificStringTable[SSI_DetailLevels];\n\tInvSoundOption.lpString\t\t\t= GF_SpecificStringTable[SSI_Sound];\n\tInvControlOption.lpString\t\t= GF_SpecificStringTable[SSI_Controls];\n\n\tSetRequesterHeading(&LoadGameRequester, GF_GameStringTable[GSI_Passport_SelectLevel], 0, NULL, 0);\n\tSetRequesterHeading(&SaveGameRequester, GF_GameStringTable[GSI_Passport_SelectLevel], 0, NULL, 0);\n\n\treturn TRUE;\n}\n\nBOOL __cdecl GF_DoFrontEndSequence() {\n\treturn ( GF_EXIT_GAME == GF_InterpretSequence(GF_ScriptBuffer, GFL_NORMAL, 1) );\n}\n\nint __cdecl GF_DoLevelSequence(DWORD levelID, GF_LEVEL_TYPE levelType) {\n\tfor( DWORD i = levelID; i < GF_GameFlow.num_Levels; ++i ) {\n\t\tint direction = GF_InterpretSequence(GF_ScriptTable[i], levelType, 0);\n\n\t\tif( GF_GameFlow.singleLevel >= 0 ||\n\t\t\t(direction & ~0xFFu) != GF_LEVEL_COMPLETE )\n\t\t{\n\t\t\treturn direction;\n\t\t}\n\t}\n\tIsTitleLoaded = FALSE;\n\treturn GF_EXIT_TO_TITLE;\n}\n\nint __cdecl GF_InterpretSequence(__int16 *seq, GF_LEVEL_TYPE levelType, int seqType) {\n\tint result = GF_EXIT_TO_TITLE;\n\tint trackIndex = 0;\n\tchar str[80];\n\n\tGF_NoFloor = 0;\n\tGF_DeadlyWater = 0;\n\tGF_SunsetEnabled = 0;\n\tGF_LaraStartAnim = 0;\n\tGF_Kill2Complete = 0;\n\tGF_RemoveAmmo = 0;\n\tGF_RemoveWeapons = 0;\n\n\tmemset(GF_Add2InvItems, 0, sizeof(GF_Add2InvItems));\n\tmemset(GF_SecretInvItems, 0, sizeof(GF_SecretInvItems));\n\n\tTrackIDs[0] = 2;\n\tCineTargetAngle = 0x4000;\n\tGF_NumSecrets = 3;\n\n\twhile( *seq != GFE_END_SEQ ) {\n\t\tCurrentEvent = *seq;\n\t\tswitch( *seq ) {\n\t\t\tcase GFE_STARTLEVEL :\n\t\t\t\tif( seq[1] > GF_GameFlow.num_Levels ) {\n\t\t\t\t\tsprintf(str, \"INVALID LEVEL %d\", seq[1]);\n\t\t\t\t\tresult = GF_EXIT_TO_TITLE;\n\t\t\t\t} else if( levelType != GFL_STORY ) {\n\t\t\t\t\tif( levelType == GFL_MIDSTORY ) {\n\t\t\t\t\t\treturn GF_EXIT_TO_TITLE;\n\t\t\t\t\t}\n\t\t\t\t\tresult = StartGame(seq[1], levelType);\n\t\t\t\t\tGF_StartGame = false;\n\t\t\t\t\tif( levelType == GFL_SAVED ) {\n\t\t\t\t\t\tlevelType = GFL_NORMAL;\n\t\t\t\t\t}\n\t\t\t\t\tif( (result & ~0xff) != GF_LEVEL_COMPLETE ) {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_LOADINGPIC :\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_DEMOPLAY :\n\t\t\t\tif( levelType != GFL_SAVED && levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\treturn StartDemo(seq[1]);\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_CUTANGLE :\n\t\t\t\tif( levelType != GFL_SAVED ) {\n\t\t\t\t\tCineTargetAngle = seq[1];\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_CUTSCENE :\n\t\t\t\tif( levelType != GFL_SAVED ) {\n\t\t\t\t\tsprintf(str, \"CUTSCENE %d %s\", seq[1], GF_CutsFilesStringTable[seq[1]]);\n\t\t\t\t\t__int16 storedLevel = CurrentLevel;\n\t\t\t\t\tint cine_ret = StartCinematic(seq[1]);\n\t\t\t\t\tCurrentLevel = storedLevel;\n\t\t\t\t\tif( cine_ret == 2 && (levelType == GFL_STORY || levelType == GFL_MIDSTORY) ) {\n\t\t\t\t\t\treturn GF_EXIT_TO_TITLE;\n\t\t\t\t\t}\n\t\t\t\t\tif( cine_ret == 3 ) {\n\t\t\t\t\t\treturn GF_EXIT_GAME;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_PLAYFMV :\n\t\t\t\tif( levelType != GFL_SAVED ) {\n\t\t\t\t\tif( seq[2] == GFE_PLAYFMV ) {\n\t\t\t\t\t\tif( S_IntroFMV(GF_FmvFilesStringTable[seq[1]], GF_FmvFilesStringTable[seq[3]]) ) {\n\t\t\t\t\t\t\treturn GF_EXIT_GAME;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tseq += 2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif( S_PlayFMV(GF_FmvFilesStringTable[seq[1]]) ) {\n\t\t\t\t\t\t\treturn GF_EXIT_GAME;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_LEVCOMPLETE :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\tif( LevelStats(CurrentLevel) ) {\n\t\t\t\t\t\treturn GF_EXIT_TO_TITLE;\n\t\t\t\t\t}\n\t\t\t\t\tresult = GF_START_GAME | (CurrentLevel + 1);\n\t\t\t\t}\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_GAMECOMPLETE :\n\t\t\t\tDisplayCredits();\n\t\t\t\tif( GameStats(CurrentLevel) ) {\n\t\t\t\t\treturn GF_EXIT_TO_TITLE;\n\t\t\t\t}\n\t\t\t\tresult = GF_EXIT_TO_TITLE;\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_PICTURE :\n\t\t\t\tif( levelType != GFL_SAVED ) {\n\t\t\t\t\tsprintf(str, \"PICTURE %s\", GF_PictureFilesStringTable[seq[1]]);\n\t\t\t\t}\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t\t\t\tif( LoadingScreensEnabled && seq[1] < GF_GameFlow.num_Pictures && (levelType == GFL_NORMAL || levelType == GFL_SAVED) ) {\n\t\t\t\t\tRGB888 palette[256];\n\t\t\t\t\tmemcpy(palette, GamePalette8, sizeof(GamePalette8));\n\t\t\t\t\tif( !BGND2_LoadPicture(GF_PictureFilesStringTable[seq[1]], FALSE, FALSE) ) {\n\t\t\t\t\t\tBGND2_ShowPicture(30, 90, 10, 2, TRUE);\n\t\t\t\t\t\tS_DontDisplayPicture();\n\t\t\t\t\t}\n\t\t\t\t\tmemcpy(GamePalette8, palette, sizeof(GamePalette8));\n\t\t\t\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_JUMPTO_SEQ :\n\t\t\t\tsprintf(str, \"JUMPSEQ %d\", seq[1]);\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_SETTRACK :\n\t\t\t\tTrackIDs[trackIndex++] = seq[1];\n\t\t\t\tSetCutsceneTrack(seq[1]);\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_SUNSET :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\tGF_SunsetEnabled = 1;\n\t\t\t\t}\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_DEADLY_WATER :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\tGF_DeadlyWater = 1;\n\t\t\t\t}\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_NOFLOOR :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\tGF_NoFloor = seq[1];\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_STARTANIM :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\tGF_LaraStartAnim = seq[1];\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_NUMSECRETS :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\tGF_NumSecrets = seq[1];\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_ADD2INV :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\tif( seq[1] < 1000 ) {\n\t\t\t\t\t\t++GF_SecretInvItems[seq[1]];\n\t\t\t\t\t} else if( levelType != GFL_SAVED ) {\n\t\t\t\t\t\t++GF_Add2InvItems[seq[1] - 1000];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tseq += 2;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_REMOVE_WEAPONS :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY && levelType != GFL_SAVED ) {\n\t\t\t\t\tGF_RemoveWeapons = 1;\n\t\t\t\t}\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_REMOVE_AMMO :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY && levelType != GFL_SAVED ) {\n\t\t\t\t\tGF_RemoveAmmo = 1;\n\t\t\t\t}\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_KILL2COMPLETE :\n\t\t\t\tif( levelType != GFL_STORY && levelType != GFL_MIDSTORY ) {\n\t\t\t\t\tGF_Kill2Complete = 1;\n\t\t\t\t}\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\n\t\t\tcase GFE_LIST_START :\n\t\t\tcase GFE_LIST_END :\n\t\t\t\t++seq;\n\t\t\t\tbreak;\n\n\t\t\tdefault :\n\t\t\t\treturn GF_EXIT_GAME;\n\t\t}\n\t}\n\tCurrentEvent = GFE_END_SEQ;\n\n\tif( levelType == GFL_STORY || levelType == GFL_MIDSTORY ) {\n\t\tresult = GF_START_GAME;\n\t}\n\treturn result;\n}\n\nvoid __cdecl GF_ModifyInventory(int levelID, BOOL isSecret) {\n\tint i;\n\tSTART_INFO *start = &SaveGame.start[levelID];\n\n\t// NOTE: additional weapon availability checks not presented in the original game\n\tif( !Objects[ID_PISTOL_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_PISTOL] = 0;\n\t\tGF_SecretInvItems[ADDINV_PISTOL] = 0;\n\t}\n\tif( !Objects[ID_UZI_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_UZI] = 0;\n\t\tGF_SecretInvItems[ADDINV_UZI] = 0;\n\t}\n\tif( !Objects[ID_MAGNUM_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_MAGNUM] = 0;\n\t\tGF_SecretInvItems[ADDINV_MAGNUM] = 0;\n\t}\n\tif( !Objects[ID_SHOTGUN_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_SHOTGUN] = 0;\n\t\tGF_SecretInvItems[ADDINV_SHOTGUN] = 0;\n\t}\n\tif( !Objects[ID_GRENADE_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_GRENADE] = 0;\n\t\tGF_SecretInvItems[ADDINV_GRENADE] = 0;\n\t}\n\tif( !Objects[ID_M16_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_M16] = 0;\n\t\tGF_SecretInvItems[ADDINV_M16] = 0;\n\t}\n\tif( !Objects[ID_HARPOON_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_HARPOON] = 0;\n\t\tGF_SecretInvItems[ADDINV_HARPOON] = 0;\n\t}\n\n\t// NOTE: additional ammo availability checks not presented in the original game\n\tif( !start->has_pistols && !Objects[ID_PISTOL_AMMO_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_PISTOL_AMMO] = 0;\n\t\tGF_SecretInvItems[ADDINV_PISTOL_AMMO] = 0;\n\t}\n\tif( !start->has_uzis && !Objects[ID_UZI_AMMO_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_UZI_AMMO] = 0;\n\t\tGF_SecretInvItems[ADDINV_UZI_AMMO] = 0;\n\t}\n\tif( !start->has_magnums && !Objects[ID_MAGNUM_AMMO_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_MAGNUM_AMMO] = 0;\n\t\tGF_SecretInvItems[ADDINV_MAGNUM_AMMO] = 0;\n\t}\n\tif( !start->has_shotgun && !Objects[ID_SHOTGUN_AMMO_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_SHOTGUN_AMMO] = 0;\n\t\tGF_SecretInvItems[ADDINV_SHOTGUN_AMMO] = 0;\n\t}\n\tif( !start->has_grenade && !Objects[ID_GRENADE_AMMO_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_GRENADE_AMMO] = 0;\n\t\tGF_SecretInvItems[ADDINV_GRENADE_AMMO] = 0;\n\t}\n\tif( !start->has_m16 && !Objects[ID_M16_AMMO_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_M16_AMMO] = 0;\n\t\tGF_SecretInvItems[ADDINV_M16_AMMO] = 0;\n\t}\n\tif( !start->has_harpoon && !Objects[ID_HARPOON_AMMO_OPTION].loaded ) {\n\t\tGF_Add2InvItems[ADDINV_HARPOON_AMMO] = 0;\n\t\tGF_SecretInvItems[ADDINV_HARPOON_AMMO] = 0;\n\t}\n\n\t// Pistols\n\tif( !start->has_pistols && GF_Add2InvItems[ADDINV_PISTOL] ) {\n\t\tstart->has_pistols = 1;\n\t\tInv_AddItem(ID_PISTOL_ITEM);\n\t}\n\n\t// Shotgun\n\tif( Inv_RequestItem(ID_SHOTGUN_ITEM) ) {\n\t\tif( isSecret ) {\n\t\t\tLara.shotgun_ammo += 12 * GF_SecretInvItems[ADDINV_SHOTGUN_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_SHOTGUN_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_SHOTGUN_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.shotgun_ammo += 12 * GF_Add2InvItems[ADDINV_SHOTGUN_AMMO];\n\t\t}\n\t} else if( (!isSecret && GF_Add2InvItems[ADDINV_SHOTGUN]) || (isSecret && GF_SecretInvItems[ADDINV_SHOTGUN]) ) {\n\t\tstart->has_shotgun = 1;\n\t\tInv_AddItem(ID_SHOTGUN_ITEM);\n\t\tif( isSecret ) {\n\t\t\tAddDisplayPickup(ID_SHOTGUN_ITEM);\n\t\t\tLara.shotgun_ammo += 12 * GF_SecretInvItems[ADDINV_SHOTGUN_AMMO];\n\t\t\t// NOTE: This loop is absent in the original code\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_SHOTGUN_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_SHOTGUN_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.shotgun_ammo += 12 * GF_Add2InvItems[ADDINV_SHOTGUN_AMMO];\n\t\t}\n\t} else {\n\t\tif( isSecret ) {\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_SHOTGUN_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_SHOTGUN_AMMO_ITEM);\n\t\t\t\tAddDisplayPickup(ID_SHOTGUN_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_SHOTGUN_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_SHOTGUN_AMMO_ITEM);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Magnums\n\tif( Inv_RequestItem(ID_MAGNUM_ITEM) ) {\n\t\tif( isSecret ) {\n\t\t\tLara.magnum_ammo += 40 * GF_SecretInvItems[ADDINV_MAGNUM_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_MAGNUM_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_MAGNUM_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.magnum_ammo += 40 * GF_Add2InvItems[ADDINV_MAGNUM_AMMO];\n\t\t}\n\t} else if( (!isSecret && GF_Add2InvItems[ADDINV_MAGNUM]) || (isSecret && GF_SecretInvItems[ADDINV_MAGNUM]) ) {\n\t\tstart->has_magnums = 1;\n\t\tInv_AddItem(ID_MAGNUM_ITEM);\n\t\tif( isSecret ) {\n\t\t\tAddDisplayPickup(ID_MAGNUM_ITEM);\n\t\t\t// NOTE: here was GF_Add2InvItems instead of GF_SecretInvItems in the original code. This is fixed\n\t\t\tLara.magnum_ammo += 40 * GF_SecretInvItems[ADDINV_MAGNUM_AMMO];\n\t\t\t// NOTE: here was ADDINV_MAGNUM instead of ADDINV_MAGNUM_AMMO in the original code. This is fixed\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_MAGNUM_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_MAGNUM_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.magnum_ammo += 40 * GF_Add2InvItems[ADDINV_MAGNUM_AMMO];\n\t\t}\n\t} else {\n\t\tif( isSecret ) {\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_MAGNUM_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_MAGNUM_AMMO_ITEM);\n\t\t\t\tAddDisplayPickup(ID_MAGNUM_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_MAGNUM_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_MAGNUM_AMMO_ITEM);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Uzis\n\tif( Inv_RequestItem(ID_UZI_ITEM) ) {\n\t\tif( isSecret ) {\n\t\t\tLara.uzi_ammo += 80 * GF_SecretInvItems[ADDINV_UZI_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_UZI_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_UZI_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.uzi_ammo += 80 * GF_Add2InvItems[ADDINV_UZI_AMMO];\n\t\t}\n\t} else if( (!isSecret && GF_Add2InvItems[ADDINV_UZI]) || (isSecret && GF_SecretInvItems[ADDINV_UZI]) ) {\n\t\tstart->has_uzis = 1;\n\t\tInv_AddItem(ID_UZI_ITEM);\n\t\tif( isSecret ) {\n\t\t\tAddDisplayPickup(ID_UZI_ITEM);\n\t\t\tLara.uzi_ammo += 80 * GF_SecretInvItems[ADDINV_UZI_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_UZI_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_UZI_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.uzi_ammo += 80 * GF_Add2InvItems[ADDINV_UZI_AMMO];\n\t\t}\n\t} else {\n\t\tif( isSecret ) {\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_UZI_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_UZI_AMMO_ITEM);\n\t\t\t\tAddDisplayPickup(ID_UZI_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_UZI_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_UZI_AMMO_ITEM);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Harpoon\n\tif( Inv_RequestItem(ID_HARPOON_ITEM) ) {\n\t\tif( isSecret ) {\n\t\t\tLara.harpoon_ammo += 3 * GF_SecretInvItems[ADDINV_HARPOON_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_HARPOON_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_HARPOON_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.harpoon_ammo += 3 * GF_Add2InvItems[ADDINV_HARPOON_AMMO];\n\t\t}\n\t} else if( (!isSecret && GF_Add2InvItems[ADDINV_HARPOON]) || (isSecret && GF_SecretInvItems[ADDINV_HARPOON]) ) {\n\t\tstart->has_harpoon = 1;\n\t\tInv_AddItem(ID_HARPOON_ITEM);\n\t\tif( isSecret ) {\n\t\t\tAddDisplayPickup(ID_HARPOON_ITEM);\n\t\t\tLara.harpoon_ammo += 3 * GF_SecretInvItems[ADDINV_HARPOON_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_HARPOON_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_HARPOON_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.harpoon_ammo += 3 * GF_Add2InvItems[ADDINV_HARPOON_AMMO];\n\t\t}\n\t} else {\n\t\tif( isSecret ) {\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_HARPOON_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_HARPOON_AMMO_ITEM);\n\t\t\t\tAddDisplayPickup(ID_HARPOON_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_HARPOON_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_HARPOON_AMMO_ITEM);\n\t\t\t}\n\t\t}\n\t}\n\n\t// M16\n\tif( Inv_RequestItem(ID_M16_ITEM) ) {\n\t\tif( isSecret ) {\n\t\t\tLara.m16_ammo += 40 * GF_SecretInvItems[ADDINV_M16_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_M16_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_M16_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.m16_ammo += 40 * GF_Add2InvItems[ADDINV_M16_AMMO];\n\t\t}\n\t} else if( (!isSecret && GF_Add2InvItems[ADDINV_M16]) || (isSecret && GF_SecretInvItems[ADDINV_M16]) ) {\n\t\tstart->has_m16 = 1;\n\t\tInv_AddItem(ID_M16_ITEM);\n\t\tif( isSecret ) {\n\t\t\tAddDisplayPickup(ID_M16_ITEM);\n\t\t\tLara.m16_ammo += 40 * GF_SecretInvItems[ADDINV_M16_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_M16_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_M16_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.m16_ammo += 40 * GF_Add2InvItems[ADDINV_M16_AMMO];\n\t\t}\n\t} else {\n\t\tif( isSecret ) {\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_M16_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_M16_AMMO_ITEM);\n\t\t\t\tAddDisplayPickup(ID_M16_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_M16_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_M16_AMMO_ITEM);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Grenade\n\tif( Inv_RequestItem(ID_GRENADE_ITEM) ) {\n\t\tif( isSecret ) {\n\t\t\tLara.grenade_ammo += 2 * GF_SecretInvItems[ADDINV_GRENADE_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_GRENADE_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_GRENADE_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.grenade_ammo += 2 * GF_Add2InvItems[ADDINV_GRENADE_AMMO];\n\t\t}\n\t} else if( (!isSecret && GF_Add2InvItems[ADDINV_GRENADE]) || (isSecret && GF_SecretInvItems[ADDINV_GRENADE]) ) {\n\t\tstart->has_grenade = 1;\n\t\tInv_AddItem(ID_GRENADE_ITEM);\n\t\tif( isSecret ) {\n\t\t\tAddDisplayPickup(ID_GRENADE_ITEM);\n\t\t\tLara.grenade_ammo += 2 * GF_SecretInvItems[ADDINV_GRENADE_AMMO];\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_GRENADE_AMMO]; ++i ) {\n\t\t\t\tAddDisplayPickup(ID_GRENADE_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tLara.grenade_ammo += 2 * GF_Add2InvItems[ADDINV_GRENADE_AMMO];\n\t\t}\n\t} else {\n\t\tif( isSecret ) {\n\t\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_GRENADE_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_GRENADE_AMMO_ITEM);\n\t\t\t\tAddDisplayPickup(ID_GRENADE_AMMO_ITEM);\n\t\t\t}\n\t\t} else {\n\t\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_GRENADE_AMMO]; ++i ) {\n\t\t\t\tInv_AddItem(ID_GRENADE_AMMO_ITEM);\n\t\t\t}\n\t\t}\n\t}\n\n\tif( isSecret ) {\n\t\t// Flares (secret bonus)\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_FLARE]; ++i ) {\n\t\t\tInv_AddItem(ID_FLARE_ITEM);\n\t\t\tAddDisplayPickup(ID_FLARE_ITEM);\n\t\t}\n\t\t// Medipacks (secret bonus)\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_SMALL_MEDIPACK]; ++i ) {\n\t\t\tInv_AddItem(ID_SMALL_MEDIPACK_ITEM);\n\t\t\tAddDisplayPickup(ID_SMALL_MEDIPACK_ITEM);\n\t\t}\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_LARGE_MEDIPACK]; ++i ) {\n\t\t\tInv_AddItem(ID_LARGE_MEDIPACK_ITEM);\n\t\t\tAddDisplayPickup(ID_LARGE_MEDIPACK_ITEM);\n\t\t}\n\t\t// Pickups (secret bonus)\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_PICKUP1]; ++i ) {\n\t\t\tInv_AddItem(ID_PICKUP_ITEM1);\n\t\t\tAddDisplayPickup(ID_PICKUP_ITEM1);\n\t\t}\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_PICKUP2]; ++i ) {\n\t\t\tInv_AddItem(ID_PICKUP_ITEM2);\n\t\t\tAddDisplayPickup(ID_PICKUP_ITEM2);\n\t\t}\n\t\t// Puzzles (secret bonus)\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_PUZZLE1]; ++i ) {\n\t\t\tInv_AddItem(ID_PUZZLE_ITEM1);\n\t\t\tAddDisplayPickup(ID_PUZZLE_ITEM1);\n\t\t}\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_PUZZLE2]; ++i ) {\n\t\t\tInv_AddItem(ID_PUZZLE_ITEM2);\n\t\t\tAddDisplayPickup(ID_PUZZLE_ITEM2);\n\t\t}\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_PUZZLE3]; ++i ) {\n\t\t\tInv_AddItem(ID_PUZZLE_ITEM3);\n\t\t\tAddDisplayPickup(ID_PUZZLE_ITEM3);\n\t\t}\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_PUZZLE4]; ++i ) {\n\t\t\tInv_AddItem(ID_PUZZLE_ITEM4);\n\t\t\tAddDisplayPickup(ID_PUZZLE_ITEM4);\n\t\t}\n\t\t// Keys (secret bonus)\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_KEY1]; ++i ) {\n\t\t\tInv_AddItem(ID_KEY_ITEM1);\n\t\t\tAddDisplayPickup(ID_KEY_ITEM1);\n\t\t}\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_KEY2]; ++i ) {\n\t\t\tInv_AddItem(ID_KEY_ITEM2);\n\t\t\tAddDisplayPickup(ID_KEY_ITEM2);\n\t\t}\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_KEY3]; ++i ) {\n\t\t\tInv_AddItem(ID_KEY_ITEM3);\n\t\t\tAddDisplayPickup(ID_KEY_ITEM3);\n\t\t}\n\t\tfor( i = 0; i < GF_SecretInvItems[ADDINV_KEY4]; ++i ) {\n\t\t\tInv_AddItem(ID_KEY_ITEM4);\n\t\t\tAddDisplayPickup(ID_KEY_ITEM4);\n\t\t}\n\t\t// Clear the array (secret bonus)\n\t\tmemset(GF_SecretInvItems, 0, sizeof(GF_SecretInvItems));\n\t} else {\n\t\t// Flares (level start)\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_FLARE]; ++i ) {\n\t\t\tInv_AddItem(ID_FLARE_ITEM);\n\t\t}\n\t\t// Medipacks (level start)\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_SMALL_MEDIPACK]; ++i ) {\n\t\t\tInv_AddItem(ID_SMALL_MEDIPACK_ITEM);\n\t\t}\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_LARGE_MEDIPACK]; ++i ) {\n\t\t\tInv_AddItem(ID_LARGE_MEDIPACK_ITEM);\n\t\t}\n\t\t// Pickups (level start)\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_PICKUP1]; ++i ) {\n\t\t\tInv_AddItem(ID_PICKUP_ITEM1);\n\t\t}\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_PICKUP2]; ++i ) {\n\t\t\tInv_AddItem(ID_PICKUP_ITEM2);\n\t\t}\n\t\t// Puzzles (level start)\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_PUZZLE1]; ++i ) {\n\t\t\tInv_AddItem(ID_PUZZLE_ITEM1);\n\t\t}\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_PUZZLE2]; ++i ) {\n\t\t\tInv_AddItem(ID_PUZZLE_ITEM2);\n\t\t}\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_PUZZLE3]; ++i ) {\n\t\t\tInv_AddItem(ID_PUZZLE_ITEM3);\n\t\t}\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_PUZZLE4]; ++i ) {\n\t\t\tInv_AddItem(ID_PUZZLE_ITEM4);\n\t\t}\n\t\t// Keys (level start)\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_KEY1]; ++i ) {\n\t\t\tInv_AddItem(ID_KEY_ITEM1);\n\t\t}\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_KEY2]; ++i ) {\n\t\t\tInv_AddItem(ID_KEY_ITEM2);\n\t\t}\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_KEY3]; ++i ) {\n\t\t\tInv_AddItem(ID_KEY_ITEM3);\n\t\t}\n\t\tfor( i = 0; i < GF_Add2InvItems[ADDINV_KEY4]; ++i ) {\n\t\t\tInv_AddItem(ID_KEY_ITEM4);\n\t\t}\n\t\t// Clear the array (level start)\n\t\tmemset(GF_Add2InvItems, 0, sizeof(GF_Add2InvItems));\n\t}\n}\n\n// NOTE: not presented in the original game\nint __cdecl GF_CurrentEvent() {\n\treturn CurrentEvent;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Gameflow() {\n\tINJECT(0x0041FA40, GF_LoadScriptFile);\n\tINJECT(0x0041FC30, GF_DoFrontEndSequence);\n\tINJECT(0x0041FC50, GF_DoLevelSequence);\n\tINJECT(0x0041FCC0, GF_InterpretSequence);\n\tINJECT(0x004201A0, GF_ModifyInventory);\n}\n"
  },
  {
    "path": "game/gameflow.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef GAMEFLOW_H_INCLUDED\n#define GAMEFLOW_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nBOOL __cdecl GF_LoadScriptFile(LPCTSTR fileName); // 0x0041FA40\nBOOL __cdecl GF_DoFrontEndSequence(); // 0x0041FC30\nint __cdecl GF_DoLevelSequence(DWORD levelID, GF_LEVEL_TYPE levelType); // 0x0041FC50\nint __cdecl GF_InterpretSequence(__int16 *seq, GF_LEVEL_TYPE levelType, int seqType); // 0x0041FCC0\nvoid __cdecl GF_ModifyInventory(int levelID, BOOL isSecret); // 0x004201A0\nint __cdecl GF_CurrentEvent(); // NOTE: not presented in the original game\n\n#endif // GAMEFLOW_H_INCLUDED\n"
  },
  {
    "path": "game/hair.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/hair.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Hair() {\n//\tINJECT(0x00420E80, InitialiseHair);\n//\tINJECT(0x00420F00, HairControl);\n//\tINJECT(0x00421900, DrawHair);\n}\n"
  },
  {
    "path": "game/hair.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef HAIR_H_INCLUDED\n#define HAIR_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define InitialiseHair ((void(__cdecl*)(void)) 0x00420E80)\n#define HairControl ((void(__cdecl*)(int)) 0x00420F00)\n#define DrawHair ((void(__cdecl*)(void)) 0x00421900)\n\n#endif // HAIR_H_INCLUDED\n"
  },
  {
    "path": "game/health.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/health.h\"\n#include \"3dsystem/scalespr.h\"\n#include \"game/text.h\"\n#include \"specific/output.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\n#define AMMO_XPOS_PC\t(-10)\n#define AMMO_YPOS_PC\t(35)\n\n#define AMMO_XPOS_PS\t(-16)\n#define AMMO_YPOS_PS\t(64)\n\n#ifdef FEATURE_HUD_IMPROVED\nextern bool PsxBarPosEnabled;\n#endif // FEATURE_HUD_IMPROVED\n\nBOOL __cdecl FlashIt() {\n\tstatic int counter = 0;\n\tstatic BOOL state = FALSE;\n\n\tif( counter > 0 ) {\n\t\t--counter;\n\t} else {\n\t\tcounter = 5;\n\t\tstate = !state;\n\t}\n\treturn state;\n}\n\nvoid __cdecl DrawAssaultTimer() {\n\tint xPos, yPos, d0, d1, d2;\n\tint minutes, seconds, deciseconds;\n\tDWORD scaleH, scaleV;\n\tchar timeString[16]; // NOTE: the original buffer was 8\n\n\t// Exit if current level is not Assault or the timer is hidden\n\tif( CurrentLevel != 0 || !IsAssaultTimerDisplay )\n\t\treturn;\n\n\tdeciseconds = SaveGame.statistics.timer % 30 / 3;\n\tseconds = SaveGame.statistics.timer / 30 % 60;\n\tminutes = SaveGame.statistics.timer / 30 / 60;\n\tsprintf(timeString, \"%d:%02d.%d\", minutes, seconds, deciseconds);\n\n#ifdef FEATURE_HUD_IMPROVED\n\tscaleH = GetRenderScale(PHD_ONE);\n\tscaleV = GetRenderScale(PHD_ONE);\n\txPos = PhdWinMaxX / 2 - GetRenderScale(50);\n\tyPos = GetRenderScale(36);\n\td0 = GetRenderScale(20);\n\td1 = GetRenderScale(-6);\n\td2 = GetRenderScale(14);\n#else // !FEATURE_HUD_IMPROVED\n\tscaleH = PHD_ONE;\n\tscaleV = PHD_ONE;\n\txPos = PhdWinMaxX / 2 - 50;\n\tyPos = 36;\n\td0 = 20;\n\td1 = -6;\n\td2 = 14;\n#endif // FEATURE_HUD_IMPROVED\n\n\tfor( char *str = timeString; *str != 0; ++str ) {\n\t\tswitch( *str ) {\n\t\t\tcase ':' : // colon\n\t\t\t\txPos += d1;\n\t\t\t\tS_DrawScreenSprite2d(xPos, yPos, 0, scaleH, scaleV, (Objects[ID_ASSAULT_DIGITS].meshIndex + 10), 0x1000, 0);\n\t\t\t\txPos += d2;\n\t\t\t\tbreak;\n\n\t\t\tcase '.' : // period\n\t\t\t\txPos += d1;\n\t\t\t\tS_DrawScreenSprite2d(xPos, yPos, 0, scaleH, scaleV, (Objects[ID_ASSAULT_DIGITS].meshIndex + 11), 0x1000, 0);\n\t\t\t\txPos += d2;\n\t\t\t\tbreak;\n\n\t\t\tdefault : // any digit\n\t\t\t\tS_DrawScreenSprite2d(xPos, yPos, 0, scaleH, scaleV, (Objects[ID_ASSAULT_DIGITS].meshIndex + (*str - '0')), 0x1000, 0);\n\t\t\t\txPos += d0;\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nvoid __cdecl DrawGameInfo(BOOL pickupState) {\n\tBOOL flashState;\n\n\tDrawAmmoInfo();\n\tDrawModeInfo();\n\n\tif( OverlayStatus > 0 ) {\n\t\tflashState = FlashIt();\n\t\tDrawHealthBar(flashState);\n\t\tDrawAirBar(flashState);\n\t\tDrawPickups(pickupState);\n\t\tDrawAssaultTimer();\n\t}\n\tT_DrawText();\n}\n\nvoid __cdecl DrawHealthBar(BOOL flashState) {\n\tstatic int oldHitPoints;\n\tint hitPoints;\n\n\t// NOTE: fixes original game bug when health bar is visible while final cut scene\n\tif( Lara.extra_anim && LaraItem->currentAnimState == EXTRA_FINALANIM ) {\n\t\treturn;\n\t}\n\n\thitPoints = LaraItem->hitPoints;\n\tCLAMP(hitPoints, 0, 1000);\n\n\tif( oldHitPoints != hitPoints ){\n\t\toldHitPoints = hitPoints;\n\t\tHealthBarTimer = 40; // 1.33 seconds\n\t}\n\tCLAMPL(HealthBarTimer, 0);\n\n\tif( hitPoints <= 250 ) {\n\t\tif( flashState == 0 ) {\n\t\t\tS_DrawHealthBar(0);\n\t\t} else {\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tS_DrawHealthBar(PHD_ONE * hitPoints / 1000);\n#else // !FEATURE_HUD_IMPROVED\n\t\t\tS_DrawHealthBar(hitPoints / 10);\n#endif // FEATURE_HUD_IMPROVED\n\t\t}\n\t}\n\telse if( HealthBarTimer > 0 || hitPoints <= 0 || Lara.gun_status == LGS_Ready ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tS_DrawHealthBar(PHD_ONE * hitPoints / 1000);\n#else // !FEATURE_HUD_IMPROVED\n\t\tS_DrawHealthBar(hitPoints / 10);\n#endif // FEATURE_HUD_IMPROVED\n\t}\n}\n\nvoid __cdecl DrawAirBar(BOOL flashState) {\n\tint air;\n\n\tif( Lara.water_status != LWS_Underwater && Lara.water_status != LWS_Surface )\n\t\treturn;\n\n\tair = Lara.air;\n\tCLAMP(air, 0, 1800);\n\n\tif( air <= 450 && flashState == 0 ) {\n\t\tS_DrawAirBar(0);\n\t} else {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tS_DrawAirBar(PHD_ONE * air / 1800);\n#else // !FEATURE_HUD_IMPROVED\n\t\tS_DrawAirBar(100 * air / 1800);\n#endif // FEATURE_HUD_IMPROVED\n\t}\n}\n\nvoid __cdecl MakeAmmoString(char *str) {\n\tfor( ; *str != 0; ++str ) {\n\t\tif( *str == 0x20 ) {\n\t\t\tcontinue; // space chars\n\t\t}\n\t\tif( (BYTE)*str < 'A' ) {\n\t\t\t*str += 1 - '0'; // ammo digit chars\n\t\t} else {\n\t\t\t*str += 0xC - 'A'; // ammo special chars\n\t\t}\n\t}\n}\n\nvoid __cdecl DrawAmmoInfo() {\n\tchar ammoString[80] = \"\";\n\n\tif( Lara.gun_status != LGS_Ready || OverlayStatus <= 0 || SaveGame.bonusFlag ) {\n\t\tif( AmmoTextInfo != NULL ) {\n\t\t\tT_RemovePrint(AmmoTextInfo);\n\t\t\tAmmoTextInfo = NULL;\n\t\t}\n\t\treturn;\n\t}\n\n\tswitch( Lara.gun_type ) {\n\t\tcase LGT_Magnums :\n\t\t\tsprintf(ammoString, \"%5d\", (int)Lara.magnum_ammo);\n\t\t\tbreak;\n\n\t\tcase LGT_Uzis :\n\t\t\tsprintf(ammoString, \"%5d\", (int)Lara.uzi_ammo);\n\t\t\tbreak;\n\n\t\tcase LGT_Shotgun :\n\t\t\tsprintf(ammoString, \"%5d\", (int)(Lara.shotgun_ammo / 6));\n\t\t\tbreak;\n\n\t\tcase LGT_Harpoon :\n\t\t\tsprintf(ammoString, \"%5d\", (int)Lara.harpoon_ammo);\n\t\t\tbreak;\n\n\t\tcase LGT_M16 :\n\t\t\tsprintf(ammoString, \"%5d\", (int)Lara.m16_ammo);\n\t\t\tbreak;\n\n\t\tcase LGT_Grenade :\n\t\t\tsprintf(ammoString, \"%5d\", (int)Lara.grenade_ammo);\n\t\t\tbreak;\n\n\t\tdefault :\n\t\t\treturn;\n\t}\n\n\tMakeAmmoString(ammoString);\n\n\tif( AmmoTextInfo == NULL ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( PsxBarPosEnabled ) {\n\t\t\tAmmoTextInfo = T_Print(AMMO_XPOS_PS, AMMO_YPOS_PS, 0, ammoString);\n\t\t} else {\n\t\t\tAmmoTextInfo = T_Print(AMMO_XPOS_PC, AMMO_YPOS_PC, 0, ammoString);\n\t\t}\n#else // !FEATURE_HUD_IMPROVED\n\t\tAmmoTextInfo = T_Print(AMMO_XPOS_PC, AMMO_YPOS_PC, 0, ammoString);\n#endif // FEATURE_HUD_IMPROVED\n\t\tT_RightAlign(AmmoTextInfo, 1);\n\t} else {\n\t\tT_ChangeText(AmmoTextInfo, ammoString);\n\t}\n}\n\nvoid __cdecl DrawPickups(BOOL pickupState) {\n\tstatic int oldGameTimer = 0;\n\tint time;\n\tint x, y;\n\tint cellH, cellV;\n\tint column = 0;\n\n\ttime = SaveGame.statistics.timer - oldGameTimer;\n\toldGameTimer = SaveGame.statistics.timer;\n\tif( time <= 0 || time >= 60 ) // 0..2 seconds\n\t\treturn;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tcellH = MIN(PhdWinWidth, PhdWinHeight*320/200) / 10;\n#else // !FEATURE_HUD_IMPROVED\n\tcellH = PhdWinWidth / 10;\n#endif // FEATURE_HUD_IMPROVED\n\tcellV = cellH * 2 / 3;\n\n\tx = PhdWinWidth - cellH;\n\ty = PhdWinHeight - cellH;\n\n\tfor( int i = 0; i < 12; ++i ) {\n\t\tif( pickupState ) {\n\t\t\tPickupInfos[i].timer -= time;\n\t\t\tCLAMPL(PickupInfos[i].timer, 0);\n\t\t}\n\n\t\tif( PickupInfos[i].timer > 0 ) {\n\t\t\tif( ++column > 4 ) {\n\t\t\t\tcolumn = 1;\n\t\t\t\tx = PhdWinWidth - cellH;\n\t\t\t\ty -= cellV;\n\t\t\t}\n\t\t\tS_DrawPickup(x, y, 0x3000, PickupInfos[i].sprite, 0x1000);\n\t\t\tx -= cellH;\n\t\t}\n\t}\n}\n\nvoid __cdecl AddDisplayPickup(__int16 itemID) {\n\tif( itemID == ID_SECRET1 || itemID == ID_SECRET2 || itemID == ID_SECRET3 ) {\n\t\tS_CDPlay(GF_GameFlow.secretTrack, FALSE);\n\t}\n\n\tfor( int i = 0; i < 12; ++i ) {\n\t\tif( PickupInfos[i].timer <= 0 ) {\n\t\t\tPickupInfos[i].timer = 75; // 2.5 seconds\n\t\t\tPickupInfos[i].sprite = Objects[itemID].meshIndex;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nvoid __cdecl DisplayModeInfo(char *modeString) {\n\tif( modeString == NULL ) {\n\t\tT_RemovePrint(DisplayModeTextInfo);\n\t\tDisplayModeTextInfo = NULL;\n\t\treturn;\n\t}\n\n\tif( DisplayModeTextInfo != NULL ) {\n\t\tT_ChangeText(DisplayModeTextInfo, modeString);\n\t} else {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tDisplayModeTextInfo = T_Print(-8, -8, 0, modeString);\n#else // FEATURE_HUD_IMPROVED\n\t\tDisplayModeTextInfo = T_Print(-16, -16, 0, modeString);\n#endif // FEATURE_HUD_IMPROVED\n\t\tT_RightAlign(DisplayModeTextInfo, 1);\n\t\tT_BottomAlign(DisplayModeTextInfo, 1);\n\t}\n\tDisplayModeInfoTimer = 75; // 2.5 seconds\n#ifdef FEATURE_HUD_IMPROVED\n\tT_HideText(DisplayModeTextInfo, (OverlayStatus <= 0));\n#endif // FEATURE_HUD_IMPROVED\n}\n\nvoid __cdecl DrawModeInfo() {\n\tif( DisplayModeTextInfo != NULL && --DisplayModeInfoTimer == 0 ) {\n\t\tT_RemovePrint(DisplayModeTextInfo);\n\t\tDisplayModeTextInfo = NULL;\n\t}\n#ifdef FEATURE_HUD_IMPROVED\n\tT_HideText(DisplayModeTextInfo, (OverlayStatus <= 0));\n#endif // FEATURE_HUD_IMPROVED\n}\n\nvoid __cdecl InitialisePickUpDisplay() {\n\tfor( int i = 0; i < 12; ++i ) {\n\t\tPickupInfos[i].timer = 0;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Health() {\n\tINJECT(0x00421980, FlashIt);\n\tINJECT(0x004219B0, DrawAssaultTimer);\n\tINJECT(0x00421B00, DrawGameInfo);\n\tINJECT(0x00421B50, DrawHealthBar);\n\tINJECT(0x00421C00, DrawAirBar);\n\tINJECT(0x00421CA0, MakeAmmoString);\n\tINJECT(0x00421CD0, DrawAmmoInfo);\n\tINJECT(0x00421E20, InitialisePickUpDisplay);\n\tINJECT(0x00421E40, DrawPickups);\n\tINJECT(0x00421F40, AddDisplayPickup);\n\tINJECT(0x00421FB0, DisplayModeInfo);\n\tINJECT(0x00422030, DrawModeInfo);\n}\n"
  },
  {
    "path": "game/health.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef HEALTH_H_INCLUDED\n#define HEALTH_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nBOOL __cdecl FlashIt(); // 0x00421980\nvoid __cdecl DrawAssaultTimer(); // 0x004219B0\nvoid __cdecl DrawGameInfo(BOOL pickupState); // 0x00421B00\nvoid __cdecl DrawHealthBar(BOOL flashState); // 0x00421B50\nvoid __cdecl DrawAirBar(BOOL flashState); // 0x00421C00\nvoid __cdecl MakeAmmoString(char *str); // 0x00421CA0\nvoid __cdecl DrawAmmoInfo(); // 0x00421CD0\nvoid __cdecl InitialisePickUpDisplay(); // 0x00421E20\nvoid __cdecl DrawPickups(BOOL pickupState); // 0x00421E40\nvoid __cdecl AddDisplayPickup(__int16 itemID); // 0x00421F40\nvoid __cdecl DisplayModeInfo(char *modeString); // 0x00421FB0\nvoid __cdecl DrawModeInfo(); // 0x00422030\n\n#endif // HEALTH_H_INCLUDED\n"
  },
  {
    "path": "game/inventory.cpp",
    "content": "/*\r\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\r\n * Copyright (c) 2019 TokyoSU <vlevasseur5@gmail.com>\r\n * Original game is created by Core Design Ltd. in 1997.\r\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\r\n *\r\n * This file is part of TR2Main.\r\n *\r\n * TR2Main is free software: you can redistribute it and/or modify\r\n * it under the terms of the GNU General Public License as published by\r\n * the Free Software Foundation, either version 3 of the License, or\r\n * (at your option) any later version.\r\n *\r\n * TR2Main is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n * GNU General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU General Public License\r\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\r\n */\r\n\r\n#include \"global/precompiled.h\"\r\n#include \"game/inventory.h\"\r\n#include \"3dsystem/3d_gen.h\"\r\n#include \"3dsystem/scalespr.h\"\r\n#include \"game/demo.h\"\r\n#include \"game/draw.h\"\r\n#include \"game/health.h\"\r\n#include \"game/invfunc.h\"\r\n#include \"game/laramisc.h\"\r\n#include \"game/sound.h\"\r\n#include \"game/text.h\"\r\n#include \"specific/display.h\"\r\n#include \"specific/frontend.h\"\r\n#include \"specific/input.h\"\r\n#include \"specific/option.h\"\r\n#include \"specific/output.h\"\r\n#include \"specific/sndpc.h\"\r\n#include \"global/vars.h\"\r\n\r\n#ifdef FEATURE_INPUT_IMPROVED\r\n#include \"modding/joy_output.h\"\r\n#endif // FEATURE_INPUT_IMPROVED\r\n\r\n#ifdef FEATURE_HUD_IMPROVED\r\nextern void RemoveJoystickHintText(bool isSelect, bool isContinue, bool isDeselect);\r\nextern void DisplayJoystickHintText(bool isSelect, bool isContinue, bool isDeselect);\r\nextern void DisplayVolumeBars(bool isSmooth);\r\n\r\nextern bool PsxFovEnabled;\r\nextern DWORD InvTextBoxMode;\r\n#endif // FEATURE_HUD_IMPROVED\r\n\r\ntypedef enum {\r\n\tRINGSTATE_OPENING,\r\n\tRINGSTATE_OPEN,\r\n\tRINGSTATE_CLOSING,\r\n\tRINGSTATE_MAIN2OPTION,\r\n\tRINGSTATE_MAIN2KEYS,\r\n\tRINGSTATE_KEYS2MAIN,\r\n\tRINGSTATE_OPTION2MAIN,\r\n\tRINGSTATE_SELECTING,\r\n\tRINGSTATE_SELECTED,\r\n\tRINGSTATE_DESELECTING,\r\n\tRINGSTATE_DESELECT,\r\n\tRINGSTATE_CLOSING_ITEM,\r\n\tRINGSTATE_EXITING_INVENTORY,\r\n\tRINGSTATE_DONE\r\n} RING_STATES;\r\n\r\n#define PASS_SPINE\t\t(0x01)\r\n#define PASS_FRONT\t\t(0x02)\r\n#define PASS_INFRONT\t(0x04)\r\n#define PASS_PAGE2\t\t(0x08)\r\n#define PASS_BACK\t\t(0x10)\r\n#define PASS_INBACK\t\t(0x20)\r\n#define PASS_PAGE1\t\t(0x40)\r\n#define PASS_BASE\t\t(PASS_FRONT|PASS_SPINE|PASS_BACK)\r\n\r\nint __cdecl Display_Inventory(INVENTORY_MODE invMode) {\r\n\tBOOL isDemoNeeded = FALSE;\r\n\tBOOL isPassOpen = FALSE;\r\n\tint itemAnimateFrame = 0;\r\n\t__int16 itemRotation = 0;\r\n\tINVENTORY_ITEM *item = NULL;\r\n\tRING_INFO ring;\r\n\tPHD_3DPOS viewPos;\r\n\tINV_MOTION_INFO motion;\r\n\r\n\tmemset(&ring, 0, sizeof(RING_INFO));\r\n\tmemset(&motion, 0, sizeof(INV_MOTION_INFO));\r\n\r\n\tif( invMode == INV_KeysMode && !InvKeyObjectsCount ) {\r\n\t\tInventoryChosen = -1;\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tT_RemovePrint(AmmoTextInfo);\r\n\tAmmoTextInfo = NULL;\r\n\tAlterFOV(80*PHD_DEGREE);\r\n\tInventoryMode = invMode;\r\n\tint nTicks = TICKS_PER_FRAME;\r\n\tConstruct_Inventory();\r\n\r\n\tif( InventoryMode == INV_TitleMode ) {\r\n\t\tS_FadeInInventory(0);\r\n\t} else {\r\n\t\tS_FadeInInventory(1);\r\n\t}\r\n\r\n\tSOUND_Stop();\r\n\r\n\tif( InventoryMode != INV_TitleMode ) {\r\n#ifdef FEATURE_AUDIO_IMPROVED\r\n\t\textern double InventoryMusicMute;\r\n\t\tdouble volume = (1.0 - InventoryMusicMute) * (double)(MusicVolume * 25 + 5);\r\n\t\tif( volume >= 1.0 ) {\r\n\t\t\tS_CDVolume((DWORD)volume);\r\n\t\t} else {\r\n\t\t\tS_CDVolume(0);\r\n\t\t}\r\n#else // FEATURE_AUDIO_IMPROVED\r\n\t\tS_CDVolume(0); // NOTE: Core supposed to pause CD Audio this way\r\n#endif // FEATURE_AUDIO_IMPROVED\r\n\t}\r\n\r\n\tswitch( InventoryMode ) {\r\n\t\tcase INV_TitleMode :\r\n\t\tcase INV_SaveMode :\r\n\t\tcase INV_LoadMode :\r\n\t\tcase INV_DeathMode :\r\n\t\t\tInv_RingInit(&ring, RING_Option, InvOptionList, InvOptionObjectsCount, InvOptionCurrent, &motion);\r\n\t\t\tbreak;\r\n\r\n\t\tcase INV_KeysMode :\r\n\t\t\tInv_RingInit(&ring, RING_Keys, InvKeysList, InvKeyObjectsCount, InvMainCurrent, &motion);\r\n\t\t\tbreak;\r\n\r\n\t\tdefault :\r\n\t\t\tif (InvMainObjectsCount) {\r\n\t\t\t\tInv_RingInit(&ring, RING_Main, InvMainList, InvMainObjectsCount, InvMainCurrent, &motion);\r\n\t\t\t} else {\r\n\t\t\t\tInv_RingInit(&ring, RING_Option, InvOptionList, InvOptionObjectsCount, InvOptionCurrent, &motion);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t}\r\n\r\n\tPlaySoundEffect(111, NULL, SFX_ALWAYS);\r\n\tnTicks = TICKS_PER_FRAME;\r\n\r\n\tdo {\r\n\t\tif( InventoryMode == INV_TitleMode && CD_TrackID > 0 ) {\r\n\t\t\tS_CDLoop();\r\n\t\t}\r\n\r\n\t\tInv_RingCalcAdders(&ring, 24);\r\n\t\tS_UpdateInput();\r\n\r\n\t\tif( InvDemoMode ) {\r\n\t\t\tif( InputStatus ) {\r\n\t\t\t\treturn GF_GameFlow.onDemo_Interrupt;\r\n\t\t\t}\r\n\t\t\tGetDemoInput();\r\n\r\n\t\t\tif( InputStatus == (DWORD)-1 ) {\r\n\t\t\t\treturn GF_GameFlow.onDemo_End;\r\n\t\t\t}\r\n\t\t} else if( InputStatus ) {\r\n\t\t\tNoInputCounter = 0;\r\n\t\t}\r\n\r\n\t\tInputDB = GetDebouncedInput(InputStatus);\r\n\r\n\t\tif( InventoryMode != INV_TitleMode || InputStatus || InputDB ) {\r\n\t\t\tNoInputCounter = 0;\r\n\t\t\tIsResetFlag = FALSE;\r\n\t\t} else if( GF_GameFlow.num_Demos || CHK_ANY(GF_GameFlow.flags, GFF_NoInputTimeout) ) {\r\n\t\t\tif( ++NoInputCounter > GF_GameFlow.noInput_Time ) {\r\n\t\t\t\tisDemoNeeded = TRUE;\r\n\t\t\t\tIsResetFlag = TRUE;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif( StopInventory ) {\r\n\t\t\treturn GF_EXIT_TO_TITLE;\r\n\t\t}\r\n\r\n\t\tif( (InventoryMode == INV_SaveMode ||\r\n\t\t\t InventoryMode == INV_LoadMode ||\r\n\t\t\t InventoryMode == INV_DeathMode) && !isPassOpen )\r\n\t\t{\r\n\t\t\tInputStatus = 0;\r\n\t\t\tInputDB = IN_SELECT;\r\n\t\t}\r\n\r\n\t\tfor( int i = 0; i < nTicks; ++i ) {\r\n\t\t\tif( IsInvOptionsDelay ) {\r\n\t\t\t\tif( InvOptionsDelayCounter ) {\r\n\t\t\t\t\t--InvOptionsDelayCounter;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tIsInvOptionsDelay = FALSE;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tInv_RingDoMotions(&ring);\r\n\t\t}\r\n\r\n\t\tring.camera.z = (ring.radius + 0x256);\r\n\t\tS_InitialisePolyList(0);\r\n\r\n\t\tif( InventoryMode == INV_TitleMode ) {\r\n\t\t\tDoInventoryPicture();\r\n\t\t} else {\r\n\t\t\tDoInventoryBackground();\r\n\t\t}\r\n\r\n\t\tS_AnimateTextures(nTicks);\r\n\t\tInv_RingGetView(&ring, &viewPos);\r\n\t\tphd_GenerateW2V(&viewPos);\r\n\t\tInv_RingLight(&ring);\r\n\r\n\t\tphd_PushMatrix();\r\n\t\tphd_TranslateAbs(ring.ringPos.x, ring.ringPos.y, ring.ringPos.z);\r\n\t\tphd_RotYXZ(ring.ringPos.rotY, ring.ringPos.rotX, ring.ringPos.rotZ);\r\n\r\n\t\titemRotation = 0;\r\n\r\n\t\tfor( int i = 0; i < ring.objCount; ++i ) {\r\n\t\t\titem = ring.itemList[i];\r\n\r\n\t\t\tif( i == ring.currentObj ) {\r\n\t\t\t\tfor( int j = 0; j < nTicks; ++j ) {\r\n\t\t\t\t\tif( ring.isRotating ) {\r\n\t\t\t\t\t\tLsAdder = 0x1400;\r\n\t\t\t\t\t\tif( item->zRot > 0 ) {\r\n\t\t\t\t\t\t\titem->zRot -= 0x200;\r\n\t\t\t\t\t\t} else if( item->zRot < 0 ) {\r\n\t\t\t\t\t\t\titem->zRot += 0x200;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t} else if( motion.status == RINGSTATE_SELECTED\r\n\t\t\t\t\t\t|| motion.status == RINGSTATE_DESELECTING\r\n\t\t\t\t\t\t|| motion.status == RINGSTATE_SELECTING\r\n\t\t\t\t\t\t|| motion.status == RINGSTATE_DESELECT\r\n\t\t\t\t\t\t|| motion.status == RINGSTATE_CLOSING_ITEM )\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tLsAdder = 0x1000;\r\n\t\t\t\t\t\tif( item->zRot != item->yRot ) {\r\n\t\t\t\t\t\t\tif( item->yRot <= item->zRot || item->yRot >= item->zRot + PHD_180 ) {\r\n\t\t\t\t\t\t\t\titem->zRot -= 0x400;\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\titem->zRot += 0x400;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\titem->zRot &= 0xFC00;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t} else if( ring.objCount == 1 || !CHK_ANY(InputStatus, IN_LEFT|IN_RIGHT) ) {\r\n\t\t\t\t\t\tLsAdder = 0x1000;\r\n\t\t\t\t\t\titem->zRot += 0x100;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif( (motion.status == RINGSTATE_OPEN\r\n\t\t\t\t\t|| motion.status == RINGSTATE_SELECTING\r\n\t\t\t\t\t|| motion.status == RINGSTATE_SELECTED\r\n\t\t\t\t\t|| motion.status == RINGSTATE_DESELECTING\r\n\t\t\t\t\t|| motion.status == RINGSTATE_DESELECT\r\n\t\t\t\t\t|| motion.status == RINGSTATE_CLOSING_ITEM)\r\n\t\t\t\t\t&& !ring.isRotating\r\n\t\t\t\t\t&& !CHK_ANY(InputStatus, IN_LEFT|IN_RIGHT) )\r\n\t\t\t\t{\r\n\t\t\t\t\tRingNotActive(item);\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tLsAdder = 0x1400;\r\n\t\t\t\tfor( int i = 0; i < nTicks; ++i ) {\r\n\t\t\t\t\tif( item->zRot > 0 ) {\r\n\t\t\t\t\t\titem->zRot -= 0x100;\r\n\t\t\t\t\t} else if( item->zRot < 0 ) {\r\n\t\t\t\t\t\titem->zRot += 0x100;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif( motion.status == RINGSTATE_OPEN\r\n\t\t\t\t|| motion.status == RINGSTATE_SELECTING\r\n\t\t\t\t|| motion.status == RINGSTATE_SELECTED\r\n\t\t\t\t|| motion.status == RINGSTATE_DESELECTING\r\n\t\t\t\t|| motion.status == RINGSTATE_DESELECT\r\n\t\t\t\t|| motion.status == RINGSTATE_CLOSING_ITEM )\r\n\t\t\t{\r\n\t\t\t\tRingIsOpen(&ring);\r\n\t\t\t} else {\r\n\t\t\t\tRingIsNotOpen();\r\n\t\t\t}\r\n\r\n\t\t\tif( motion.status == RINGSTATE_OPENING\r\n\t\t\t\t|| motion.status == RINGSTATE_CLOSING\r\n\t\t\t\t|| motion.status == RINGSTATE_MAIN2OPTION\r\n\t\t\t\t|| motion.status == RINGSTATE_OPTION2MAIN\r\n\t\t\t\t|| motion.status == RINGSTATE_EXITING_INVENTORY\r\n\t\t\t\t|| motion.status == RINGSTATE_DONE\r\n\t\t\t\t|| ring.isRotating )\r\n\t\t\t{\r\n\t\t\t\tRingActive();\r\n\t\t\t}\r\n\r\n\t\t\tphd_PushMatrix();\r\n\t\t\tphd_RotYXZ(itemRotation, 0, 0);\r\n\t\t\tphd_TranslateRel(ring.radius, 0, 0);\r\n\t\t\tphd_RotYXZ(PHD_90, item->xRotPt, 0);\r\n\t\t\tDrawInventoryItem(item);\r\n\t\t\tphd_PopMatrix();\r\n\t\t\titemRotation += ring.angleAdder;\r\n\t\t}\r\n\t\tphd_PopMatrix();\r\n\r\n\t\tDrawModeInfo();\r\n\t\tT_DrawText();\r\n#ifdef FEATURE_HUD_IMPROVED\r\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode &&\r\n\t\t\tring.itemList[ring.currentObj]->objectID == ID_SOUND_OPTION )\r\n\t\t{\r\n\t\t\tstatic bool isSoundSelected = false;\r\n\t\t\tif( motion.status == RINGSTATE_SELECTING && isSoundSelected ) {\r\n\t\t\t\tisSoundSelected = false;\r\n\t\t\t}\r\n\t\t\tif( motion.status == RINGSTATE_SELECTED ) {\r\n\t\t\t\tDisplayVolumeBars(isSoundSelected);\r\n\t\t\t\tif( !isSoundSelected ) isSoundSelected = true;\r\n\t\t\t}\r\n\t\t}\r\n#endif // FEATURE_HUD_IMPROVED\r\n\t\tS_OutputPolyList();\r\n\t\tSOUND_EndScene();\r\n\r\n\t\tCamera.numberFrames = nTicks = S_DumpScreen();\r\n\r\n\t\tif( CurrentLevel != 0 ) { // not Lara home\r\n\t\t\tSaveGame.statistics.timer += nTicks / TICKS_PER_FRAME;\r\n\t\t}\r\n\r\n\t\tif( !ring.isRotating ) {\r\n\t\t\tswitch( motion.status ) {\r\n\t\t\t\tcase RINGSTATE_OPEN :\r\n#ifdef FEATURE_HUD_IMPROVED\r\n\t\t\t\t\tDisplayJoystickHintText(true, false, InventoryMode != INV_TitleMode && InventoryMode != INV_DeathMode);\r\n#endif // FEATURE_HUD_IMPROVED\r\n\r\n\t\t\t\t\tif( CHK_ANY(InputStatus, IN_RIGHT) && ring.objCount > 1 ) {\r\n\t\t\t\t\t\tInv_RingRotateLeft(&ring);\r\n\t\t\t\t\t\tPlaySoundEffect(108, 0, SFX_ALWAYS);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif( CHK_ANY(InputStatus, IN_LEFT) && ring.objCount > 1 ) {\r\n\t\t\t\t\t\tInv_RingRotateRight(&ring);\r\n\t\t\t\t\t\tPlaySoundEffect(108, 0, SFX_ALWAYS);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif( IsResetFlag || (InventoryMode != INV_TitleMode && CHK_ANY(InputDB, IN_DESELECT|IN_OPTION)) ) {\r\n\t\t\t\t\t\tPlaySoundEffect(112, 0, SFX_ALWAYS);\r\n\t\t\t\t\t\tInventoryChosen = -1;\r\n\r\n\t\t\t\t\t\tif( ring.type != RING_Main ) {\r\n\t\t\t\t\t\t\tInvOptionCurrent = ring.currentObj;\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tInvMainCurrent = ring.currentObj;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (InventoryMode == INV_TitleMode) {\r\n\t\t\t\t\t\t\tS_FadeOutInventory(FALSE);\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tS_FadeOutInventory(TRUE);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING, RINGSTATE_DONE, 32);\r\n\t\t\t\t\t\tInv_RingMotionRadius(&ring, 0);\r\n\t\t\t\t\t\tInv_RingMotionCameraPos(&ring, -0x600);\r\n\t\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, ring.ringPos.rotY + PHD_180);\r\n\t\t\t\t\t\tInputStatus = 0;\r\n\t\t\t\t\t\tInputDB = 0;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif( CHK_ANY(InputDB, IN_SELECT) ) {\r\n\t\t\t\t\t\tif( (InventoryMode == INV_SaveMode || InventoryMode == INV_LoadMode || InventoryMode == INV_DeathMode) && !isPassOpen ) {\r\n\t\t\t\t\t\t\tisPassOpen = TRUE;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tSoundOptionLine = 0;\r\n\r\n\t\t\t\t\t\tswitch (ring.type) {\r\n\t\t\t\t\t\t\tcase RING_Main :\r\n\t\t\t\t\t\t\t\tInvMainCurrent = ring.currentObj;\r\n\t\t\t\t\t\t\t\titem = InvMainList[ring.currentObj];\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tcase RING_Option :\r\n\t\t\t\t\t\t\t\tInvOptionCurrent = ring.currentObj;\r\n\t\t\t\t\t\t\t\titem = InvOptionList[ring.currentObj];\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tcase RING_Keys :\r\n\t\t\t\t\t\t\tdefault :\r\n\t\t\t\t\t\t\t\tInvKeysCurrent = ring.currentObj;\r\n\t\t\t\t\t\t\t\titem = InvKeysList[ring.currentObj];\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\titem->goalFrame = item->openFrame;\r\n\t\t\t\t\t\titem->animDirection = 1;\r\n\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_SELECTING, RINGSTATE_SELECTED, 16);\r\n\t\t\t\t\t\tInv_RingMotionRotation(&ring, 0, -PHD_90 - ring.angleAdder * ring.currentObj);\r\n\t\t\t\t\t\tInv_RingMotionItemSelect(&ring, item);\r\n\t\t\t\t\t\tInputStatus = 0;\r\n\t\t\t\t\t\tInputDB = 0;\r\n\r\n\t\t\t\t\t\tswitch (item->objectID) {\r\n\t\t\t\t\t\t\tcase ID_COMPASS_OPTION :\r\n\t\t\t\t\t\t\t\tPlaySoundEffect(113, 0, SFX_ALWAYS);\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tcase ID_PHOTO_OPTION :\r\n\t\t\t\t\t\t\t\tPlaySoundEffect(109, 0, SFX_ALWAYS);\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tcase ID_PISTOL_OPTION :\r\n\t\t\t\t\t\t\tcase ID_SHOTGUN_OPTION :\r\n\t\t\t\t\t\t\tcase ID_MAGNUM_OPTION :\r\n\t\t\t\t\t\t\tcase ID_UZI_OPTION :\r\n\t\t\t\t\t\t\tcase ID_HARPOON_OPTION :\r\n\t\t\t\t\t\t\tcase ID_M16_OPTION :\r\n\t\t\t\t\t\t\tcase ID_GRENADE_OPTION :\r\n\t\t\t\t\t\t\t\tPlaySoundEffect(114, 0, SFX_ALWAYS);\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tdefault :\r\n\t\t\t\t\t\t\t\tPlaySoundEffect(111, 0, SFX_ALWAYS);\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif( CHK_ANY(InputDB, IN_FORWARD) && InventoryMode != INV_TitleMode && InventoryMode != INV_KeysMode ) {\r\n\t\t\t\t\t\tif( ring.type == RING_Main ) {\r\n\t\t\t\t\t\t\tif( InvKeyObjectsCount ) {\r\n\t\t\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING, RINGSTATE_MAIN2KEYS, 24);\r\n\t\t\t\t\t\t\t\tInv_RingMotionRadius(&ring, 0);\r\n\t\t\t\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, ring.ringPos.rotY - PHD_180);\r\n\t\t\t\t\t\t\t\tInv_RingMotionCameraPitch(&ring, 0x2000);\r\n\t\t\t\t\t\t\t\tmotion.misc = 0x2000;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tInputStatus = 0;\r\n\t\t\t\t\t\t\tInputDB = 0;\r\n\t\t\t\t\t\t} else if( ring.type == RING_Option ) {\r\n\t\t\t\t\t\t\tif( InvMainObjectsCount ) {\r\n\t\t\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING, RINGSTATE_OPTION2MAIN, 24);\r\n\t\t\t\t\t\t\t\tInv_RingMotionRadius(&ring, 0);\r\n\t\t\t\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, ring.ringPos.rotY - PHD_180);\r\n\t\t\t\t\t\t\t\tInv_RingMotionCameraPitch(&ring, 0x2000);\r\n\t\t\t\t\t\t\t\tmotion.misc = 0x2000;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tInputDB = 0;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t} else if( InputDB & IN_BACK && InventoryMode != INV_TitleMode && InventoryMode != INV_KeysMode ) {\r\n\t\t\t\t\t\tif( ring.type == RING_Keys ) {\r\n\t\t\t\t\t\t\tif (InvMainObjectsCount) {\r\n\t\t\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING, RINGSTATE_KEYS2MAIN, 24);\r\n\t\t\t\t\t\t\t\tInv_RingMotionRadius(&ring, 0);\r\n\t\t\t\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, ring.ringPos.rotY - PHD_180);\r\n\t\t\t\t\t\t\t\tInv_RingMotionCameraPitch(&ring, -0x2000);\r\n\t\t\t\t\t\t\t\tmotion.misc = -0x2000;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tInputStatus = 0;\r\n\t\t\t\t\t\t\tInputDB = 0;\r\n\t\t\t\t\t\t} else if( ring.type == RING_Main ) {\r\n\t\t\t\t\t\t\tif( InvOptionObjectsCount || !(GF_GameFlow.flags & GFF_LockoutOptionRing) ) {\r\n\t\t\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING, RINGSTATE_MAIN2OPTION, 24);\r\n\t\t\t\t\t\t\t\tInv_RingMotionRadius(&ring, 0);\r\n\t\t\t\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, ring.ringPos.rotY - PHD_180);\r\n\t\t\t\t\t\t\t\tInv_RingMotionCameraPitch(&ring, -0x2000);\r\n\t\t\t\t\t\t\t\tmotion.misc = -0x2000;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tInputDB = 0;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_MAIN2OPTION:\r\n\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_OPENING, RINGSTATE_OPEN, 24);\r\n\t\t\t\t\tInv_RingMotionRadius(&ring, 0x2B0);\r\n\t\t\t\t\tring.cameraPitch = -motion.misc;\r\n\r\n\t\t\t\t\tmotion.cameraTarget_pitch = 0;\r\n\t\t\t\t\tmotion.cameraRate_pitch = motion.misc / 24;\r\n\r\n\t\t\t\t\tring.itemList = InvOptionList;\r\n\t\t\t\t\tring.type = RING_Option;\r\n\t\t\t\t\tInvMainCurrent = ring.currentObj;\r\n\t\t\t\t\tring.objCount = InvOptionObjectsCount;\r\n\t\t\t\t\tring.currentObj = InvOptionCurrent;\r\n\r\n\t\t\t\t\tInv_RingCalcAdders(&ring, 24);\r\n\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, -PHD_90 - ring.angleAdder * ring.currentObj);\r\n\t\t\t\t\tring.ringPos.rotY = motion.rotateTarget - PHD_180;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_MAIN2KEYS :\r\n\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_OPENING, RINGSTATE_OPEN, 24);\r\n\t\t\t\t\tInv_RingMotionRadius(&ring, 0x2B0);\r\n\r\n\t\t\t\t\tring.cameraPitch = -motion.misc;\r\n\t\t\t\t\tmotion.cameraRate_pitch = motion.misc / 24;\r\n\t\t\t\t\tmotion.cameraTarget_pitch = 0;\r\n\r\n\t\t\t\t\tInvMainCurrent = ring.currentObj;\r\n\t\t\t\t\tInvMainObjectsCount = ring.objCount;\r\n\t\t\t\t\tring.itemList = InvKeysList;\r\n\t\t\t\t\tring.type = RING_Keys;\r\n\t\t\t\t\tring.objCount = InvKeyObjectsCount;\r\n\t\t\t\t\tring.currentObj = InvKeysCurrent;\r\n\r\n\t\t\t\t\tInv_RingCalcAdders(&ring, 24);\r\n\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, -PHD_90 - ring.angleAdder * ring.currentObj);\r\n\t\t\t\t\tring.ringPos.rotY = motion.rotateTarget - PHD_180;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_KEYS2MAIN :\r\n\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_OPENING, RINGSTATE_OPEN, 24);\r\n\t\t\t\t\tInv_RingMotionRadius(&ring, 0x2B0);\r\n\r\n\t\t\t\t\tring.cameraPitch = -motion.misc;\r\n\t\t\t\t\tmotion.cameraRate_pitch = motion.misc / 24;\r\n\t\t\t\t\tmotion.cameraTarget_pitch = 0;\r\n\r\n\t\t\t\t\tring.itemList = InvMainList;\r\n\t\t\t\t\tring.type = RING_Main;\r\n\t\t\t\t\tInvKeyObjectsCount = ring.objCount;\r\n\t\t\t\t\tInvKeysCurrent = ring.currentObj;\r\n\t\t\t\t\tring.objCount = InvMainObjectsCount;\r\n\t\t\t\t\tring.currentObj = InvMainCurrent;\r\n\r\n\t\t\t\t\tInv_RingCalcAdders(&ring, 24);\r\n\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, -PHD_90 - ring.angleAdder * ring.currentObj);\r\n\t\t\t\t\tring.ringPos.rotY = motion.rotateTarget - PHD_180;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_OPTION2MAIN :\r\n\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_OPENING, RINGSTATE_OPEN, 24);\r\n\t\t\t\t\tInv_RingMotionRadius(&ring, 0x2B0);\r\n\r\n\t\t\t\t\tring.cameraPitch = -motion.misc;\r\n\t\t\t\t\tmotion.cameraRate_pitch = motion.misc / 24;\r\n\t\t\t\t\tmotion.cameraTarget_pitch = 0;\r\n\r\n\t\t\t\t\tring.itemList = InvMainList;\r\n\t\t\t\t\tring.type = RING_Main;\r\n\t\t\t\t\tInvOptionObjectsCount = ring.objCount;\r\n\t\t\t\t\tInvOptionCurrent = ring.currentObj;\r\n\t\t\t\t\tring.objCount = InvMainObjectsCount;\r\n\t\t\t\t\tring.currentObj = InvMainCurrent;\r\n\r\n\t\t\t\t\tInv_RingCalcAdders(&ring, 24);\r\n\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, -PHD_90 - ring.angleAdder * ring.currentObj);\r\n\t\t\t\t\tring.ringPos.rotY = motion.rotateTarget - PHD_180;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_SELECTED :\r\n#ifdef FEATURE_HUD_IMPROVED\r\n\t\t\t\t\tDisplayJoystickHintText(true, false, InventoryMode != INV_DeathMode);\r\n#endif // FEATURE_HUD_IMPROVED\r\n\t\t\t\t\titem = ring.itemList[ring.currentObj];\r\n\r\n\t\t\t\t\tif( item->objectID == ID_PASSPORT_CLOSED ) {\r\n\t\t\t\t\t\titem->objectID = ID_PASSPORT_OPTION;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor( int i = 0; i < nTicks; ++i ) {\r\n\t\t\t\t\t\titemAnimateFrame = 0;\r\n\t\t\t\t\t\tif( item->zRot == item->yRot ) {\r\n\t\t\t\t\t\t\titemAnimateFrame = AnimateInventoryItem(item);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif( !itemAnimateFrame && !IsInvOptionsDelay ) {\r\n\t\t\t\t\t\tdo_inventory_options(item);\r\n\r\n\t\t\t\t\t\tif( CHK_ANY(InputDB, IN_DESELECT) ) {\r\n\t\t\t\t\t\t\titem->sprites = NULL;\r\n\t\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING_ITEM, RINGSTATE_DESELECT, 0);\r\n\t\t\t\t\t\t\tInputStatus = 0;\r\n\t\t\t\t\t\t\tInputDB = 0;\r\n\r\n\t\t\t\t\t\t\tif( InventoryMode == INV_SaveMode || InventoryMode == INV_LoadMode ) {\r\n\t\t\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING_ITEM, RINGSTATE_EXITING_INVENTORY, 0);\r\n\t\t\t\t\t\t\t\tInputDB = 0;\r\n\t\t\t\t\t\t\t\tInputStatus = 0;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif( CHK_ANY(InputDB, IN_SELECT) ) {\r\n\t\t\t\t\t\t\titem->sprites = NULL;\r\n\t\t\t\t\t\t\tInventoryChosen = item->objectID;\r\n\r\n\t\t\t\t\t\t\tif( ring.type == RING_Main ) {\r\n\t\t\t\t\t\t\t\tInvMainCurrent = ring.currentObj;\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\tInvOptionCurrent = ring.currentObj;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif( InventoryMode == INV_TitleMode\r\n\t\t\t\t\t\t\t\t&& (item->objectID == ID_DETAIL_OPTION\r\n\t\t\t\t\t\t\t\t||  item->objectID == ID_SOUND_OPTION\r\n\t\t\t\t\t\t\t\t||  item->objectID == ID_CONTROL_OPTION\r\n\t\t\t\t\t\t\t\t||  item->objectID == ID_GAMMA_OPTION) )\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING_ITEM, RINGSTATE_DESELECT, 0);\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING_ITEM, RINGSTATE_EXITING_INVENTORY, 0);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tInputStatus = 0;\r\n\t\t\t\t\t\t\tInputDB = 0;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_DESELECT :\r\n#ifdef FEATURE_HUD_IMPROVED\r\n\t\t\t\t\tRemoveJoystickHintText(false, false, InventoryMode == INV_TitleMode || InventoryMode == INV_DeathMode);\r\n#endif // FEATURE_HUD_IMPROVED\r\n\t\t\t\t\tPlaySoundEffect(112, 0, SFX_ALWAYS);\r\n\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_DESELECTING, RINGSTATE_OPEN, 16);\r\n\t\t\t\t\tInv_RingMotionRotation(&ring, 0, -PHD_90 - ring.angleAdder * ring.currentObj);\r\n\t\t\t\t\tInputStatus = 0;\r\n\t\t\t\t\tInputDB = 0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_CLOSING_ITEM :\r\n\t\t\t\t\titem = ring.itemList[ring.currentObj];\r\n\t\t\t\t\tfor( int i = 0; i < nTicks; ++i ) {\r\n\t\t\t\t\t\tif( !AnimateInventoryItem(item) ) {\r\n\t\t\t\t\t\t\tif( item->objectID == ID_PASSPORT_OPTION ) {\r\n\t\t\t\t\t\t\t\titem->objectID = ID_PASSPORT_CLOSED;\r\n\t\t\t\t\t\t\t\titem->currentFrame = 0;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmotion.framesCount = 16;\r\n\t\t\t\t\t\t\tmotion.status = motion.statusTarget;\r\n\t\t\t\t\t\t\tInv_RingMotionItemDeselect(&ring, item);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_CLOSING :\r\n#ifdef FEATURE_HUD_IMPROVED\r\n\t\t\t\t\tRemoveJoystickHintText(true, false, true);\r\n#endif // FEATURE_HUD_IMPROVED\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase RINGSTATE_EXITING_INVENTORY :\r\n#ifdef FEATURE_HUD_IMPROVED\r\n\t\t\t\t\tRemoveJoystickHintText(true, false, true);\r\n#endif // FEATURE_HUD_IMPROVED\r\n\t\t\t\t\tif( !motion.framesCount ) {\r\n\t\t\t\t\t\tif( InventoryMode == INV_TitleMode ) {\r\n\t\t\t\t\t\t\tS_FadeOutInventory(FALSE);\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tS_FadeOutInventory(TRUE);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tInv_RingMotionSetup(&ring, RINGSTATE_CLOSING, RINGSTATE_DONE, 32);\r\n\t\t\t\t\t\tInv_RingMotionRadius(&ring, 0);\r\n\t\t\t\t\t\tInv_RingMotionCameraPos(&ring, -0x600);\r\n\t\t\t\t\t\tInv_RingMotionRotation(&ring, -PHD_180, ring.ringPos.rotY - PHD_180);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n#ifdef FEATURE_INPUT_IMPROVED\r\n\t\tUpdateJoyOutput(false);\r\n#endif // FEATURE_INPUT_IMPROVED\r\n\t} while( motion.status != RINGSTATE_DONE );\r\n\r\n#ifdef FEATURE_HUD_IMPROVED\r\n\tRemoveJoystickHintText(true, false, true);\r\n#endif // FEATURE_HUD_IMPROVED\r\n\tRemoveInventoryText();\r\n\tS_FinishInventory();\r\n\tIsInventoryActive = 0;\r\n\r\n\tif( IsResetFlag ) {\r\n\t\treturn GF_EXIT_TO_TITLE;\r\n\t}\r\n\r\n\tif( isDemoNeeded ) {\r\n\t\treturn GF_START_DEMO;\r\n\t}\r\n\r\n\tswitch( InventoryChosen ) {\r\n\t\tcase ID_PASSPORT_OPTION :\r\n\t\t\tif( MusicVolume && InventoryExtraData[0] == 1 ) {\r\n\t\t\t\tS_CDVolume(25 * MusicVolume + 5);\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\tcase ID_PHOTO_OPTION :\r\n\t\t\tif( CHK_ANY(GF_GameFlow.flags, GFF_GymEnabled) ) {\r\n\t\t\t\tInventoryExtraData[1] = 0;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase ID_PISTOL_OPTION :\r\n\t\t\tUseItem(ID_PISTOL_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_SHOTGUN_OPTION :\r\n\t\t\tUseItem(ID_SHOTGUN_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_MAGNUM_OPTION :\r\n\t\t\tUseItem(ID_MAGNUM_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_UZI_OPTION :\r\n\t\t\tUseItem(ID_UZI_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_HARPOON_OPTION :\r\n\t\t\tUseItem(ID_HARPOON_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_M16_OPTION :\r\n\t\t\tUseItem(ID_M16_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_GRENADE_OPTION :\r\n\t\t\tUseItem(ID_GRENADE_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_SMALL_MEDIPACK_OPTION :\r\n\t\t\tUseItem(ID_SMALL_MEDIPACK_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_LARGE_MEDIPACK_OPTION :\r\n\t\t\tUseItem(ID_LARGE_MEDIPACK_OPTION);\r\n\t\t\tbreak;\r\n\t\tcase ID_FLARES_OPTION :\r\n\t\t\tUseItem(ID_FLARES_OPTION);\r\n\t\t\tbreak;\r\n\t}\r\n\r\n\tif( MusicVolume && InventoryMode != INV_TitleMode ) {\r\n#ifdef FEATURE_AUDIO_IMPROVED\r\n\t\tif( Camera.underwater ) {\r\n\t\t\textern double UnderwaterMusicMute;\r\n\t\t\tdouble volume = (1.0 - UnderwaterMusicMute) * (double)(MusicVolume * 25 + 5);\r\n\t\t\tif( volume >= 1.0 ) {\r\n\t\t\t\tS_CDVolume((DWORD)volume);\r\n\t\t\t} else {\r\n\t\t\t\tS_CDVolume(0);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tS_CDVolume(MusicVolume * 25 + 5);\r\n\t\t}\r\n#else // FEATURE_AUDIO_IMPROVED\r\n\t\tS_CDVolume(MusicVolume * 25 + 5);\r\n#endif // FEATURE_AUDIO_IMPROVED\r\n\t}\r\n\treturn 0;\r\n}\r\n\r\nvoid __cdecl Construct_Inventory() {\r\n\tS_SetupAboveWater(FALSE);\r\n\r\n\tif( InventoryMode != INV_TitleMode ) {\r\n\t\tTempVideoAdjust(HiRes, 1.0);\r\n\t}\r\n\r\n\tmemset(InventoryExtraData, 0, sizeof(InventoryExtraData));\r\n\r\n\tPhdWinLeft = 0;\r\n\tPhdWinTop = 0;\r\n\tPhdWinRight = PhdWinMaxX;\r\n\tPhdWinBottom = PhdWinMaxY;\r\n\r\n\tIsInventoryActive = 1;\r\n\tInventoryChosen = 0;\r\n\tInvOptionObjectsCount = ARRAY_SIZE(InvOptionList) - ((InventoryMode == INV_TitleMode) ? 0 : 1);\r\n\r\n\tfor( int i = 0; i < InvMainObjectsCount; ++i ) {\r\n\t\tInvMainList[i]->currentFrame = 0;\r\n\t\tInvMainList[i]->meshesDrawn = InvMainList[i]->meshesSel;\r\n\t\tInvMainList[i]->goalFrame = 0;\r\n\t\tInvMainList[i]->animCount = 0;\r\n\t\tInvMainList[i]->zRot = 0;\r\n\t}\r\n\r\n\tfor( int i = 0; i < InvOptionObjectsCount; ++i ) {\r\n\t\tInvOptionList[i]->currentFrame = 0;\r\n\t\tInvOptionList[i]->goalFrame = 0;\r\n\t\tInvOptionList[i]->animCount = 0;\r\n\t\tInvOptionList[i]->zRot = 0;\r\n\t}\r\n\r\n\tInvMainCurrent = 0;\r\n\tif( GymInvOpenEnabled && InventoryMode == INV_TitleMode && !CHK_ANY(GF_GameFlow.flags, GFF_LoadSaveDisabled) && CHK_ANY(GF_GameFlow.flags, GFF_GymEnabled) ) {\r\n\t\tInvOptionCurrent = ARRAY_SIZE(InvOptionList) - 1;\r\n\t} else {\r\n\t\tInvOptionCurrent = 0;\r\n\t\tGymInvOpenEnabled = FALSE;\r\n\t}\r\n\r\n\tSoundOptionLine = 0;\r\n\r\n#ifdef FEATURE_HUD_IMPROVED\r\n\tdouble scale = (double)GetRenderScale(480) / (double)GetRenderHeight();\r\n\tif( scale < 1.5 ) {\r\n\t\tInvCompassOption.yTransSel = PsxFovEnabled ? -140 : -170;\r\n\t} else if( scale < 1.7) {\r\n\t\tInvCompassOption.yTransSel = -15 - (scale - 1.5) * 35.0;\r\n\t} else {\r\n\t\tInvCompassOption.yTransSel = -22 - (scale - 1.7) / 0.0075;\r\n\t}\r\n#endif // FEATURE_HUD_IMPROVED\r\n}\r\n\r\nvoid __cdecl SelectMeshes(INVENTORY_ITEM *invItem) {\r\n\tif( invItem->objectID == ID_PASSPORT_OPTION ) {\r\n\t\tif (invItem->currentFrame < 4) {\r\n\t\t\tinvItem->meshesDrawn = PASS_BASE | PASS_INFRONT;\r\n\t\t} else if (invItem->currentFrame <= 16) {\r\n\t\t\tinvItem->meshesDrawn = PASS_BASE | PASS_INFRONT | PASS_PAGE1;\r\n\t\t} else if (invItem->currentFrame < 19) {\r\n\t\t\tinvItem->meshesDrawn = PASS_BASE | PASS_INFRONT | PASS_PAGE1 | PASS_PAGE2;\r\n\t\t} else if (invItem->currentFrame == 19) {\r\n\t\t\tinvItem->meshesDrawn = PASS_BASE | PASS_PAGE1 | PASS_PAGE2;\r\n\t\t} else if (invItem->currentFrame < 24) {\r\n\t\t\tinvItem->meshesDrawn = PASS_BASE | PASS_PAGE1 | PASS_PAGE2 | PASS_INBACK;\r\n\t\t} else if (invItem->currentFrame < 29) {\r\n\t\t\tinvItem->meshesDrawn = PASS_BASE | PASS_PAGE2 | PASS_INBACK;\r\n\t\t} else if (invItem->currentFrame == 29) {\r\n\t\t\tinvItem->meshesDrawn = PASS_BASE;\r\n\t\t}\r\n\t} else if (invItem->objectID != ID_GAMMA_OPTION) {\r\n\t\tinvItem->meshesDrawn = ~0;\r\n\t}\r\n}\r\n\r\nint __cdecl AnimateInventoryItem(INVENTORY_ITEM *invItem) {\r\n\tint frame = invItem->currentFrame;\r\n\tint animID = invItem->animCount;\r\n\r\n\tif( frame == invItem->goalFrame ) {\r\n\t\tSelectMeshes(invItem);\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tif( animID ) {\r\n\t\tinvItem->animCount = (animID - 1);\r\n\t\tSelectMeshes(invItem);\r\n\t\treturn 1;\r\n\t}\r\n\r\n\tinvItem->animCount = invItem->animSpeed;\r\n\tinvItem->currentFrame = (frame + invItem->animDirection);\r\n\r\n\tif( invItem->currentFrame >= invItem->framesTotal ) {\r\n\t\tinvItem->currentFrame = 0;\r\n\t} else if( invItem->currentFrame < 0 ) {\r\n\t\tinvItem->currentFrame = invItem->framesTotal - 1;\r\n\t}\r\n\r\n\tSelectMeshes(invItem);\r\n\treturn 1;\r\n}\r\n\r\nvoid __cdecl DrawInventoryItem(INVENTORY_ITEM* invItem) {\r\n\tint hours=0, minutes=0, seconds=0, totsec=0, clip=0;\r\n\tshort* frame[2] = {0};\r\n\r\n\tif( invItem->objectID == ID_COMPASS_OPTION ) {\r\n\t\ttotsec = SaveGame.statistics.timer/30;\r\n\t\tseconds = totsec%60;\r\n\t\tminutes = ((totsec%3600)*-91)/5;\r\n\t\thours = ((totsec/12)*-91)/5;\r\n\t\tseconds *= -1092;\r\n\t}\r\n\r\n\tphd_TranslateRel(0, invItem->yTrans, invItem->zTrans);\r\n\tphd_RotYXZ(invItem->zRot, invItem->yRotSel, 0);\r\n\tOBJECT_INFO *obj = &Objects[invItem->objectID];\r\n\r\n\tif( !obj->loaded ) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tif( obj->nMeshes < 0 ) {\r\n\t\tS_DrawSprite(0, 0, 0, 0, obj->meshIndex, 0, 0);\r\n\t\treturn;\r\n\t}\r\n\r\n\tif( invItem->sprites ) {\r\n\t\tclip = PhdMatrixPtr->_23;\r\n\t\tint sx = PhdWinCenterX + PhdMatrixPtr->_03 / (clip / PhdPersp);\r\n\t\tint sy = PhdWinCenterY + PhdMatrixPtr->_13 / (clip / PhdPersp);\r\n\t\tINVENTORY_SPRITE *sprite = (INVENTORY_SPRITE*)invItem->sprites;\r\n\r\n\t\tfor( int i = sprite->y; sprite->shape != 0; i += 4) {\r\n\t\t\tif (clip < PhdNearZ || clip > PhdFarZ) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tfor( int j = sprite->shape; j != 0; j++ ) {\r\n\t\t\t\tswitch( j ) {\r\n\t\t\t\t\tcase 1 :\r\n\t\t\t\t\t\tS_DrawScreenSprite(sx+sprite->x, sy+sprite->y,sprite->z,sprite->param1,sprite->param2,StaticObjects[ID_ALPHABET].meshIndex+sprite->invColour,0x1000,0);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 2 :\r\n\t\t\t\t\t\tS_DrawScreenLine(sx+sprite->x, sy+sprite->y,sprite->z,sprite->param1,sprite->param2,sprite->invColour,(D3DCOLOR*)sprite->gour,0);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 3 :\r\n\t\t\t\t\t\tS_DrawScreenBox(sx+sprite->x, sy+sprite->y,sprite->z,sprite->param1,sprite->param2,sprite->invColour,(GOURAUD_OUTLINE*)sprite->gour,0);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 4 :\r\n\t\t\t\t\t\tS_DrawScreenFBox(sx+sprite->x, sy+sprite->y,sprite->z,sprite->param1,sprite->param2,sprite->invColour,(GOURAUD_FILL*)sprite->gour,0);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tphd_PushMatrix();\r\n\tframe[0] = (&obj->frameBase[invItem->currentFrame * (Anims[obj->animIndex].interpolation >> 8)]);\r\n\tclip = S_GetObjectBounds(frame[0]);\r\n\tif( clip ) {\r\n\t\tphd_TranslateRel((int)*(frame[0] + 6), (int)*(frame[0] + 7), (int)*(frame[0] + 8));\r\n\t\tUINT16 *rotation = (UINT16 *)(frame[0] + 9);\r\n\t\tphd_RotYXZsuperpack(&rotation, 0);\r\n\t\t__int16 mesh = obj->meshIndex;\r\n\t\tint *bones = &AnimBones[obj->boneIndex];\r\n\t\t__int16 mesh_num = 1;\r\n\r\n\t\tif( mesh_num & invItem->meshesDrawn ) {\r\n#ifdef FEATURE_VIDEOFX_IMPROVED\r\n\t\t\tSetMeshReflectState(invItem->objectID, 0);\r\n#endif // FEATURE_VIDEOFX_IMPROVED\r\n\t\t\tphd_PutPolygons(MeshPtr[mesh], clip);\r\n#ifdef FEATURE_VIDEOFX_IMPROVED\r\n\t\t\tClearMeshReflectState();\r\n#endif // FEATURE_VIDEOFX_IMPROVED\r\n\t\t}\r\n\r\n\t\tfor( int i = obj->nMeshes-1; i > 0; --i ) {\r\n\t\t\t++mesh;\r\n\t\t\tmesh_num <<= 1;\r\n\r\n\t\t\tint pushpop = *(bones++);\r\n\t\t\tif( CHK_ANY(pushpop, 1) ) {\r\n\t\t\t\tphd_PopMatrix();\r\n\t\t\t}\r\n\t\t\tif( CHK_ANY(pushpop, 2) ) {\r\n\t\t\t\tphd_PushMatrix();\r\n\t\t\t}\r\n\r\n\t\t\tphd_TranslateRel(bones[0], bones[1], bones[2]);\r\n\t\t\tphd_RotYXZsuperpack(&rotation, 0);\r\n\r\n\t\t\tif( invItem->objectID == ID_COMPASS_OPTION ) {\r\n\t\t\t\tswitch( i ) {\r\n\t\t\t\t\tcase 2 :\r\n\t\t\t\t\t\tphd_RotZ(seconds);\r\n\t\t\t\t\t\tinvItem->reserved2 = invItem->reserved1;\r\n\t\t\t\t\t\tinvItem->reserved1 = seconds;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 3 :\r\n\t\t\t\t\t\tphd_RotZ(minutes);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 4 :\r\n\t\t\t\t\t\tphd_RotZ(hours);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif( CHK_ANY(mesh_num, invItem->meshesDrawn) ) {\r\n#ifdef FEATURE_VIDEOFX_IMPROVED\r\n\t\t\t\tSetMeshReflectState(invItem->objectID, obj->nMeshes-i);\r\n#endif // FEATURE_VIDEOFX_IMPROVED\r\n\t\t\t\tphd_PutPolygons(MeshPtr[mesh], clip);\r\n#ifdef FEATURE_VIDEOFX_IMPROVED\r\n\t\t\t\tClearMeshReflectState();\r\n#endif // FEATURE_VIDEOFX_IMPROVED\r\n\t\t\t}\r\n\t\t\tbones += 3;\r\n\t\t}\r\n\t}\r\n\tphd_PopMatrix();\r\n}\r\n\r\nDWORD __cdecl GetDebouncedInput(DWORD input) {\r\n\tstatic DWORD oldInput = 0;\r\n\tDWORD result = input & ~oldInput;\r\n#ifdef FEATURE_INPUT_IMPROVED\r\n\tstatic int holdBack = -12;\r\n\tstatic int holdForward = -12;\r\n\r\n\tif( !CHK_ANY(input, IN_BACK) || CHK_ANY(input, IN_FORWARD) ) {\r\n\t\tholdBack = -12;\r\n\t} else if( CHK_ANY(input, IN_BACK) && ++holdBack >= 3 ) {\r\n\t\tresult |= IN_BACK;\r\n\t\tholdBack = 0;\r\n\t}\r\n\r\n\tif( !CHK_ANY(input, IN_FORWARD) || CHK_ANY(input, IN_BACK) ) {\r\n\t\tholdForward = -12;\r\n\t} else if( CHK_ANY(input, IN_FORWARD) && ++holdForward >= 3 ) {\r\n\t\tresult |= IN_FORWARD;\r\n\t\tholdForward = 0;\r\n\t}\r\n#endif // FEATURE_INPUT_IMPROVED\r\n\toldInput = input;\r\n\treturn result;\r\n}\r\n\r\nvoid __cdecl DoInventoryPicture() {\r\n\tS_CopyBufferToScreen();\r\n}\r\n\r\nvoid __cdecl DoInventoryBackground() {\r\n\tVECTOR_ANGLES angles;\r\n\tPHD_3DPOS viewPos;\r\n\tUINT16 *ptr;\r\n\r\n\tS_CopyBufferToScreen();\r\n\r\n\tif( Objects[ID_INV_BACKGROUND].loaded ) {\r\n\t\t// set view\r\n\t\tphd_GetVectorAngles(0, 0x1000, 0, &angles);\r\n\t\tviewPos.x = 0;\r\n\t\tviewPos.y = -0x200;\r\n\t\tviewPos.z = 0;\r\n\t\tviewPos.rotX = angles.pitch;\r\n\t\tviewPos.rotY = angles.yaw;\r\n\t\tviewPos.rotZ = 0;\r\n\t\tphd_GenerateW2V(&viewPos);\r\n\r\n\t\t// set lighting\r\n\t\tLsDivider = 0x6000;\r\n\t\tphd_GetVectorAngles(-0x600, 0x100, 0x400, &angles);\r\n\t\tphd_RotateLight(angles.pitch, angles.yaw);\r\n\r\n\t\t// transform and insert the mesh\r\n\t\tphd_PushMatrix();\r\n\t\tptr = (UINT16 *)&Anims[Objects[ID_INV_BACKGROUND].animIndex].framePtr[9];\r\n\t\tphd_TranslateAbs(0, 0x3000, 0);\r\n\t\tphd_RotYXZ(0, PHD_90, PHD_180);\r\n\t\tphd_RotYXZsuperpack(&ptr, 0);\r\n\t\tphd_RotYXZ(PHD_180, 0, 0);\r\n\t\tS_InsertInvBgnd(MeshPtr[Objects[ID_INV_BACKGROUND].meshIndex]);\r\n\t\tphd_PopMatrix();\r\n\t}\r\n}\r\n\r\n/*\r\n * Inject function\r\n */\r\nvoid Inject_Inventory() {\r\n\tINJECT(0x00422060, Display_Inventory);\r\n\tINJECT(0x004232F0, Construct_Inventory);\r\n\tINJECT(0x00423450, SelectMeshes);\r\n\tINJECT(0x004234E0, AnimateInventoryItem);\r\n\tINJECT(0x00423570, DrawInventoryItem);\r\n\tINJECT(0x004239A0, GetDebouncedInput);\r\n\tINJECT(0x004239C0, DoInventoryPicture);\r\n\tINJECT(0x004239D0, DoInventoryBackground);\r\n}\r\n"
  },
  {
    "path": "game/inventory.h",
    "content": "/*\r\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\r\n * Original game is created by Core Design Ltd. in 1997.\r\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\r\n *\r\n * This file is part of TR2Main.\r\n *\r\n * TR2Main is free software: you can redistribute it and/or modify\r\n * it under the terms of the GNU General Public License as published by\r\n * the Free Software Foundation, either version 3 of the License, or\r\n * (at your option) any later version.\r\n *\r\n * TR2Main is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n * GNU General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU General Public License\r\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\r\n */\r\n\r\n#ifndef INVENTORY_H_INCLUDED\r\n#define INVENTORY_H_INCLUDED\r\n\r\n#include \"global/types.h\"\r\n\r\n/*\r\n * Function list\r\n */\r\nint __cdecl Display_Inventory(INVENTORY_MODE invMode); // 0x00422060\r\nvoid __cdecl Construct_Inventory(); // 0x004232F0\r\nvoid __cdecl SelectMeshes(INVENTORY_ITEM *invItem); // 0x00423450\r\nint __cdecl AnimateInventoryItem(INVENTORY_ITEM *invItem); // 0x004234E0\r\nvoid __cdecl DrawInventoryItem(INVENTORY_ITEM *invItem); // 0x00423570\r\nDWORD __cdecl GetDebouncedInput(DWORD input); // 0x004239A0\r\nvoid __cdecl DoInventoryPicture(); //0x004239C0\r\nvoid __cdecl DoInventoryBackground(); // 0x004239D0\r\n\r\n#endif // INVENTORY_H_INCLUDED\r\n"
  },
  {
    "path": "game/invfunc.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/invfunc.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"game/health.h\"\n#include \"game/items.h\"\n#include \"game/text.h\"\n#include \"specific/frontend.h\"\n#include \"global/vars.h\"\n\n// X coordinates relative to the center of the screen\n// Y coordinates relative to the bottom of the screen\n#define ITEMNAME_X_POS\t\t(0)\n#define ITEMNAME_Y_POS\t\t(-16)\n#define ITEMCOUNT_X_POS\t\t(64)\n#define ITEMCOUNT_Y_POS\t\t(-56)\n\nvoid __cdecl InitColours() {\n\tInvColours[ICLR_Black]\t\t= S_COLOUR(0x00, 0x00, 0x00);\n\tInvColours[ICLR_Gray]\t\t= S_COLOUR(0x40, 0x40, 0x40);\n\tInvColours[ICLR_White]\t\t= S_COLOUR(0xFF, 0xFF, 0xFF);\n\tInvColours[ICLR_Red]\t\t= S_COLOUR(0xFF, 0x00, 0x00);\n\tInvColours[ICLR_Orange]\t\t= S_COLOUR(0xFF, 0x80, 0x00);\n\tInvColours[ICLR_Yellow]\t\t= S_COLOUR(0xFF, 0xFF, 0x00);\n\tInvColours[ICLR_DarkGreen]\t= S_COLOUR(0x00, 0x80, 0x00);\n\tInvColours[ICLR_Green]\t\t= S_COLOUR(0x00, 0xFF, 0x00);\n\tInvColours[ICLR_Cyan]\t\t= S_COLOUR(0x00, 0xFF, 0xFF);\n\tInvColours[ICLR_Blue]\t\t= S_COLOUR(0x00, 0x00, 0xFF);\n\tInvColours[ICLR_Magenta]\t= S_COLOUR(0xFF, 0x00, 0xFF);\n}\n\nvoid __cdecl RingIsOpen(RING_INFO *ring) {\n\tGAME_STRING_ID strID;\n\n\tif( InventoryMode == INV_TitleMode )\n\t\treturn;\n\n\tif( InvRingText == NULL ) {\n\t\tswitch( ring->type ) {\n\t\t\tcase RING_Main :\n\t\t\t\tstrID = GSI_Heading_Inventory;\n\t\t\t\tbreak;\n\n\t\t\tcase RING_Option :\n\t\t\t\tstrID = (InventoryMode == INV_DeathMode) ? GSI_Heading_GameOver : GSI_Heading_Option;\n\t\t\t\tbreak;\n\n\t\t\tcase RING_Keys :\n\t\t\t\tstrID = GSI_Heading_Items;\n\t\t\t\tbreak;\n\n\t\t\tdefault :\n\t\t\t\treturn;\n\t\t}\n\t\tInvRingText = T_Print(0, 26, 0, GF_GameStringTable[strID]);\n\t\tT_CentreH(InvRingText, 1);\n\t}\n\n\tif( InventoryMode == INV_KeysMode || InventoryMode == INV_DeathMode )\n\t\treturn;\n\n\tif( InvUpArrow1 == NULL ) {\n\t\tif( ring->type == RING_Option || (ring->type == RING_Main && InvKeyObjectsCount != 0) ) {\n\t\t\tInvUpArrow1 = T_Print(20, 28, 0, \"[\"); // '[' is Up Arrow Sprite here\n\t\t\tInvUpArrow2 = T_Print(-20, 28, 0, \"[\");\n\t\t\tT_RightAlign(InvUpArrow2, 1);\n\t\t}\n\t}\n\n\tif( InvDownArrow1 == NULL ) {\n\t\tif( ring->type == RING_Keys || (ring->type == RING_Main && !CHK_ANY(GF_GameFlow.flags, GFF_LockoutOptionRing)) ) {\n\t\t\tInvDownArrow1 = T_Print(20, -15, 0, \"]\"); // ']' is Down Arrow Sprite here\n\t\t\tInvDownArrow2 = T_Print(-20, -15, 0, \"]\");\n\t\t\tT_BottomAlign(InvDownArrow1, 1);\n\t\t\tT_BottomAlign(InvDownArrow2, 1);\n\t\t\tT_RightAlign(InvDownArrow2, 1);\n\t\t}\n\t}\n}\n\nvoid __cdecl RingIsNotOpen() {\n\tT_RemovePrint(InvRingText);\n\tInvRingText = NULL;\n\tT_RemovePrint(InvUpArrow1);\n\tInvUpArrow1 = NULL;\n\tT_RemovePrint(InvUpArrow2);\n\tInvUpArrow2 = NULL;\n\tT_RemovePrint(InvDownArrow1);\n\tInvDownArrow1 = NULL;\n\tT_RemovePrint(InvDownArrow2);\n\tInvDownArrow2 = NULL;\n}\n\nvoid __cdecl RingNotActive(INVENTORY_ITEM *item) {\n\tint itemCount;\n\tchar strBuf[64];\n\n\t// Keys\n\tif( InvItemText[0] == NULL ) {\n\t\tswitch( item->objectID ) {\n\t\t\tcase ID_PASSPORT_OPTION:\n\t\t\t\tbreak;\n\n\t\t\tcase ID_PUZZLE_OPTION1:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Puzzle1StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_PUZZLE_OPTION2:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Puzzle2StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_PUZZLE_OPTION3:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Puzzle3StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_PUZZLE_OPTION4:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Puzzle4StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_PICKUP_OPTION1:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Pickup1StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_PICKUP_OPTION2:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Pickup2StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_KEY_OPTION1:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Key1StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_KEY_OPTION2:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Key2StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_KEY_OPTION3:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Key3StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tcase ID_KEY_OPTION4:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, GF_Key4StringTable[CurrentLevel]);\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tInvItemText[0] = T_Print(ITEMNAME_X_POS, ITEMNAME_Y_POS, 0, item->lpString);\n\t\t\t\tbreak;\n\t\t}\n\n\t\tif( InvItemText[0] != NULL ) {\n\t\t\tT_BottomAlign(InvItemText[0], 1);\n\t\t\tT_CentreH(InvItemText[0], 1);\n\t\t}\n\t}\n\n\t// Normal items\n\titemCount = Inv_RequestItem((GAME_OBJECT_ID)item->objectID);\n\tswitch( item->objectID ) {\n\t\tcase ID_PISTOL_OPTION:\n\t\t\treturn;\n\n\t\tcase ID_SHOTGUN_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%5d\", (int)(Lara.shotgun_ammo / 6));\n\t\t\tbreak;\n\n\t\tcase ID_MAGNUM_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%5d\", (int)Lara.magnum_ammo);\n\t\t\tbreak;\n\n\t\tcase ID_UZI_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%5d\", (int)Lara.uzi_ammo);\n\t\t\tbreak;\n\n\t\tcase ID_HARPOON_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%5d\", (int)Lara.harpoon_ammo);\n\t\t\tbreak;\n\n\t\tcase ID_M16_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%5d\", (int)Lara.m16_ammo);\n\t\t\tbreak;\n\n\t\tcase ID_GRENADE_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%5d\", (int)Lara.grenade_ammo);\n\t\t\tbreak;\n\n\t\tcase ID_PISTOL_AMMO_OPTION:\n\t\t\treturn;\n\n\t\tcase ID_SHOTGUN_AMMO_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%d\", itemCount * 2);\n\t\t\tbreak;\n\n\t\tcase ID_MAGNUM_AMMO_OPTION:\n\t\tcase ID_UZI_AMMO_OPTION:\n\t\tcase ID_HARPOON_AMMO_OPTION:\n\t\tcase ID_M16_AMMO_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%d\", itemCount * 2);\n\t\t\tbreak;\n\n\t\tcase ID_GRENADE_AMMO_OPTION:\n\t\tcase ID_FLARES_OPTION:\n\t\t\tif( InvItemText[1] != NULL || SaveGame.bonusFlag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%d\", itemCount);\n\t\t\tbreak;\n\n\t\tcase ID_SMALL_MEDIPACK_OPTION:\n\t\tcase ID_LARGE_MEDIPACK_OPTION:\n\t\t\tHealthBarTimer = 40; // 1.33 seconds\n\t\t\tDrawHealthBar(FlashIt());\n\t\t\t// fall through\n\t\tcase ID_PUZZLE_OPTION1:\n\t\tcase ID_PUZZLE_OPTION2:\n\t\tcase ID_PUZZLE_OPTION3:\n\t\tcase ID_PUZZLE_OPTION4:\n\t\tcase ID_KEY_OPTION1:\n\t\tcase ID_KEY_OPTION2:\n\t\tcase ID_KEY_OPTION3:\n\t\tcase ID_KEY_OPTION4:\n\t\tcase ID_PICKUP_OPTION1:\n\t\tcase ID_PICKUP_OPTION2:\n\t\t\tif( InvItemText[1] != NULL || itemCount <= 1 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsprintf(strBuf, \"%d\", itemCount);\n\t\t\tbreak;\n\n\t\tdefault:\n\t\t\treturn;\n\t}\n\n\tif( InvItemText[1] == NULL ) {\n\t\tMakeAmmoString(strBuf);\n\t\tInvItemText[1] = T_Print(ITEMCOUNT_X_POS, ITEMCOUNT_Y_POS, 0, strBuf);\n\t\tT_BottomAlign(InvItemText[1], 1);\n\t\tT_CentreH(InvItemText[1], 1);\n\t}\n}\n\nvoid __cdecl RingActive() {\n\tT_RemovePrint(InvItemText[0]);\n\tInvItemText[0] = NULL;\n\tT_RemovePrint(InvItemText[1]);\n\tInvItemText[1] = NULL;\n}\n\nBOOL __cdecl Inv_AddItem(GAME_OBJECT_ID itemID) {\n\tint i, j, items;\n\tint found = 0;\n\tGAME_OBJECT_ID optionID = Inv_GetItemOption(itemID);\n\n\tfor( i = 0; i < InvMainObjectsCount; ++i ) {\n\t\tif( InvMainList[i]->objectID == optionID ) {\n\t\t\tfound = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor( j = 0; j < InvKeyObjectsCount; ++j ) {\n\t\tif( InvKeysList[j]->objectID == optionID ) {\n\t\t\tfound = 2;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif( found == 1 ) {\n\t\tif( itemID == ID_FLARES_ITEM )\n\t\t\tInvMainQtys[i] += 6;\n\t\telse\n\t\t\t++InvMainQtys[i];\n\n\t\treturn TRUE;\n\t}\n\n\tif( found == 2 ) {\n\t\t++InvKeysQtys[j];\n\t\treturn TRUE;\n\t}\n\n\tswitch( itemID ) {\n\n\t\tcase ID_COMPASS_ITEM :\n\t\tcase ID_COMPASS_OPTION :\n\t\t\tInv_InsertItem(&InvCompassOption);\n\t\t\treturn TRUE;\n\n\t\tcase ID_PISTOL_ITEM :\n\t\tcase ID_PISTOL_OPTION :\n\t\t\tInv_InsertItem(&InvPistolOption);\n\t\t\tif( Lara.last_gun_type == LGT_Unarmed )\n\t\t\t\tLara.last_gun_type = LGT_Pistols;\n\t\t\treturn TRUE;\n\n\t\tcase ID_SHOTGUN_ITEM :\n\t\tcase ID_SHOTGUN_OPTION :\n\t\t\titems = Inv_RequestItem(ID_SHOTGUN_AMMO_ITEM);\n\t\t\tfor( i = 0; i < items; ++i ) {\n\t\t\t\tInv_RemoveItem(ID_SHOTGUN_AMMO_ITEM);\n\t\t\t\tLara.shotgun_ammo += 12;\n\t\t\t}\n\t\t\tLara.shotgun_ammo += 12;\n\t\t\tInv_InsertItem(&InvShotgunOption);\n\t\t\tif( Lara.last_gun_type == LGT_Unarmed )\n\t\t\t\tLara.last_gun_type = LGT_Shotgun;\n\t\t\tif( Lara.back_gun == ID_LARA )\n\t\t\t\tLara.back_gun = ID_LARA_SHOTGUN;\n\t\t\tGlobalItemReplace(ID_SHOTGUN_ITEM, ID_SHOTGUN_AMMO_ITEM);\n\t\t\treturn FALSE;\n\n\t\tcase ID_MAGNUM_ITEM :\n\t\tcase ID_MAGNUM_OPTION :\n\t\t\titems = Inv_RequestItem(ID_MAGNUM_AMMO_ITEM);\n\t\t\tfor( i = 0; i < items; ++i ) {\n\t\t\t\tInv_RemoveItem(ID_MAGNUM_AMMO_ITEM);\n\t\t\t\tLara.magnum_ammo += 40;\n\t\t\t}\n\t\t\tLara.magnum_ammo += 40;\n\t\t\tInv_InsertItem(&InvMagnumOption);\n\t\t\tGlobalItemReplace(ID_MAGNUM_ITEM, ID_MAGNUM_AMMO_ITEM);\n\t\t\treturn FALSE;\n\n\t\tcase ID_UZI_ITEM :\n\t\tcase ID_UZI_OPTION :\n\t\t\titems = Inv_RequestItem(ID_UZI_AMMO_ITEM);\n\t\t\tfor( i = 0; i < items; ++i ) {\n\t\t\t\tInv_RemoveItem(ID_UZI_AMMO_ITEM);\n\t\t\t\tLara.uzi_ammo += 80;\n\t\t\t}\n\t\t\tLara.uzi_ammo += 80;\n\t\t\tInv_InsertItem(&InvUziOption);\n\t\t\tGlobalItemReplace(ID_UZI_ITEM, ID_UZI_AMMO_ITEM);\n\t\t\treturn FALSE;\n\n\t\tcase ID_HARPOON_ITEM :\n\t\tcase ID_HARPOON_OPTION :\n\t\t\titems = Inv_RequestItem(ID_HARPOON_AMMO_ITEM);\n\t\t\tfor( i = 0; i < items; ++i ) {\n\t\t\t\tInv_RemoveItem(ID_HARPOON_AMMO_ITEM);\n\t\t\t\tLara.harpoon_ammo += 3;\n\t\t\t}\n\t\t\tLara.harpoon_ammo += 3;\n\t\t\tInv_InsertItem(&InvHarpoonOption);\n\t\t\tGlobalItemReplace(ID_HARPOON_ITEM, ID_HARPOON_AMMO_ITEM);\n\t\t\treturn FALSE;\n\n\t\tcase ID_M16_ITEM :\n\t\tcase ID_M16_OPTION :\n\t\t\titems = Inv_RequestItem(ID_M16_AMMO_ITEM);\n\t\t\tfor( i = 0; i < items; ++i ) {\n\t\t\t\tInv_RemoveItem(ID_M16_AMMO_ITEM);\n\t\t\t\tLara.m16_ammo += 40;\n\t\t\t}\n\t\t\tLara.m16_ammo += 40;\n\t\t\tInv_InsertItem(&InvM16Option);\n\t\t\tGlobalItemReplace(ID_M16_ITEM, ID_M16_AMMO_ITEM);\n\t\t\treturn FALSE;\n\n\t\tcase ID_GRENADE_ITEM :\n\t\tcase ID_GRENADE_OPTION :\n\t\t\titems = Inv_RequestItem(ID_GRENADE_AMMO_ITEM);\n\t\t\tfor( i = 0; i < items; ++i ) {\n\t\t\t\tInv_RemoveItem(ID_GRENADE_AMMO_ITEM);\n\t\t\t\tLara.grenade_ammo += 2;\n\t\t\t}\n\t\t\tLara.grenade_ammo += 2;\n\t\t\tInv_InsertItem(&InvGrenadeOption);\n\t\t\tGlobalItemReplace(ID_GRENADE_ITEM, ID_GRENADE_AMMO_ITEM);\n\t\t\treturn FALSE;\n\n\t\tcase ID_SHOTGUN_AMMO_ITEM :\n\t\tcase ID_SHOTGUN_AMMO_OPTION :\n\t\t\tif( Inv_RequestItem(ID_SHOTGUN_ITEM) != 0 )\n\t\t\t\tLara.shotgun_ammo += 12;\n\t\t\telse\n\t\t\t\tInv_InsertItem(&InvShotgunAmmoOption);\n\t\t\treturn FALSE;\n\n\t\tcase ID_MAGNUM_AMMO_ITEM :\n\t\tcase ID_MAGNUM_AMMO_OPTION :\n\t\t\tif( Inv_RequestItem(ID_MAGNUM_ITEM) != 0 )\n\t\t\t\tLara.magnum_ammo += 40;\n\t\t\telse\n\t\t\t\tInv_InsertItem(&InvMagnumAmmoOption);\n\t\t\treturn FALSE;\n\n\t\tcase ID_UZI_AMMO_ITEM :\n\t\tcase ID_UZI_AMMO_OPTION :\n\t\t\tif( Inv_RequestItem(ID_UZI_ITEM) != 0 )\n\t\t\t\tLara.uzi_ammo += 80;\n\t\t\telse\n\t\t\t\tInv_InsertItem(&InvUziAmmoOption);\n\t\t\treturn FALSE;\n\n\t\tcase ID_HARPOON_AMMO_ITEM :\n\t\tcase ID_HARPOON_AMMO_OPTION :\n\t\t\tif( Inv_RequestItem(ID_HARPOON_ITEM) != 0 )\n\t\t\t\tLara.harpoon_ammo += 3;\n\t\t\telse\n\t\t\t\tInv_InsertItem(&InvHarpoonAmmoOption);\n\t\t\treturn FALSE;\n\n\t\tcase ID_M16_AMMO_ITEM :\n\t\tcase ID_M16_AMMO_OPTION :\n\t\t\tif( Inv_RequestItem(ID_M16_ITEM) != 0 )\n\t\t\t\tLara.m16_ammo += 40;\n\t\t\telse\n\t\t\t\tInv_InsertItem(&InvM16AmmoOption);\n\t\t\treturn FALSE;\n\n\t\tcase ID_GRENADE_AMMO_ITEM :\n\t\tcase ID_GRENADE_AMMO_OPTION :\n\t\t\tif( Inv_RequestItem(ID_GRENADE_ITEM) != 0 )\n\t\t\t\tLara.grenade_ammo += 2;\n\t\t\telse\n\t\t\t\tInv_InsertItem(&InvGrenadeAmmoOption);\n\t\t\treturn FALSE;\n\n\t\tcase ID_FLARES_ITEM :\n\t\tcase ID_FLARES_OPTION :\n\t\t\tInv_InsertItem(&InvFlareOption);\n\t\t\tfor( i=0; i<5; ++i ) {\n\t\t\t\tInv_AddItem(ID_FLARE_ITEM);\n\t\t\t}\n\t\t\treturn TRUE;\n\n\t\tcase ID_FLARE_ITEM :\n\t\t\tInv_InsertItem(&InvFlareOption);\n\t\t\treturn TRUE;\n\n\t\tcase ID_SMALL_MEDIPACK_ITEM :\n\t\tcase ID_SMALL_MEDIPACK_OPTION :\n\t\t\tInv_InsertItem(&InvSmallMedipackOption);\n\t\t\treturn TRUE;\n\n\t\tcase ID_LARGE_MEDIPACK_ITEM :\n\t\tcase ID_LARGE_MEDIPACK_OPTION :\n\t\t\tInv_InsertItem(&InvLargeMedipackOption);\n\t\t\treturn TRUE;\n\n\t\tcase ID_SECRET1 :\n\t\t\tSaveGame.statistics.secrets |= 1;\n\t\t\treturn TRUE;\n\n\t\tcase ID_SECRET2 :\n\t\t\tSaveGame.statistics.secrets |= 2;\n\t\t\treturn TRUE;\n\n\t\tcase ID_SECRET3 :\n\t\t\tSaveGame.statistics.secrets |= 4;\n\t\t\treturn TRUE;\n\n\t\tcase ID_PICKUP_ITEM1 :\n\t\tcase ID_PICKUP_OPTION1 :\n\t\t\tInv_InsertItem(&InvPickup1Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_PICKUP_ITEM2 :\n\t\tcase ID_PICKUP_OPTION2 :\n\t\t\tInv_InsertItem(&InvPickup2Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_PUZZLE_ITEM1 :\n\t\tcase ID_PUZZLE_OPTION1 :\n\t\t\tInv_InsertItem(&InvPuzzle1Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_PUZZLE_ITEM2 :\n\t\tcase ID_PUZZLE_OPTION2 :\n\t\t\tInv_InsertItem(&InvPuzzle2Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_PUZZLE_ITEM3 :\n\t\tcase ID_PUZZLE_OPTION3 :\n\t\t\tInv_InsertItem(&InvPuzzle3Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_PUZZLE_ITEM4 :\n\t\tcase ID_PUZZLE_OPTION4 :\n\t\t\tInv_InsertItem(&InvPuzzle4Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_KEY_ITEM1 :\n\t\tcase ID_KEY_OPTION1 :\n\t\t\tInv_InsertItem(&InvKey1Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_KEY_ITEM2 :\n\t\tcase ID_KEY_OPTION2 :\n\t\t\tInv_InsertItem(&InvKey2Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_KEY_ITEM3 :\n\t\tcase ID_KEY_OPTION3 :\n\t\t\tInv_InsertItem(&InvKey3Option);\n\t\t\treturn TRUE;\n\n\t\tcase ID_KEY_ITEM4 :\n\t\tcase ID_KEY_OPTION4 :\n\t\t\tInv_InsertItem(&InvKey4Option);\n\t\t\treturn TRUE;\n\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\treturn FALSE;\n}\n\nvoid __cdecl Inv_InsertItem(INVENTORY_ITEM *item) {\n\tint i, j;\n\n\tif( item->invPos < 100 ) {\n\t\tfor( i = 0; i < InvMainObjectsCount; ++i ) {\n\t\t\tif( InvMainList[i]->invPos > item->invPos ) {\n\t\t\t\tfor( j = InvMainObjectsCount; j >= i; --j ) {\n\t\t\t\t\tInvMainList[j+1] = InvMainList[j];\n\t\t\t\t\tInvMainQtys[j+1] = InvMainQtys[j];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tInvMainList[i] = item;\n\t\tInvMainQtys[i] = 1;\n\t\t++InvMainObjectsCount;\n\t} else {\n\t\tfor( i = 0; i < InvKeyObjectsCount; ++i ) {\n\t\t\tif( InvKeysList[i]->invPos > item->invPos ) {\n\t\t\t\tfor( j = InvKeyObjectsCount; j >= i; --j ) {\n\t\t\t\t\tInvKeysList[j+1] = InvKeysList[j];\n\t\t\t\t\tInvKeysQtys[j+1] = InvKeysQtys[j];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tInvKeysList[i] = item;\n\t\tInvKeysQtys[i] = 1;\n\t\t++InvKeyObjectsCount;\n\t}\n}\n\nint __cdecl Inv_RequestItem(GAME_OBJECT_ID itemID) {\n\tint i;\n\tint optionID = Inv_GetItemOption(itemID);\n\n\tfor( i = 0; i < InvMainObjectsCount; ++i )\n\t\tif( InvMainList[i]->objectID == optionID )\n\t\t\treturn InvMainQtys[i];\n\n\tfor( i = 0; i < InvKeyObjectsCount; ++i )\n\t\tif( InvKeysList[i]->objectID == optionID )\n\t\t\treturn InvKeysQtys[i];\n\n\treturn 0;\n}\n\n\nvoid __cdecl Inv_RemoveAllItems() {\n\tInvMainObjectsCount = 0;\n\tInvMainCurrent = 0;\n\tInvKeyObjectsCount = 0;\n\tInvKeysCurrent = 0;\n}\n\n\nBOOL __cdecl Inv_RemoveItem(GAME_OBJECT_ID itemID) {\n\tint i, j;\n\tGAME_OBJECT_ID optionID = Inv_GetItemOption(itemID);\n\n\tfor( i = 0; i < InvMainObjectsCount; ++i ) {\n\t\tif( InvMainList[i]->objectID == optionID ) {\n\t\t\tif( --InvMainQtys[i] <= 0 ) {\n\t\t\t\t--InvMainObjectsCount;\n\n\t\t\t\tfor( j = i; j < InvMainObjectsCount; ++j ) {\n\t\t\t\t\tInvMainList[j] = InvMainList[j+1];\n\t\t\t\t\tInvMainQtys[j] = InvMainQtys[j+1];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn TRUE;\n\t\t}\n\t}\n\n\tfor( i = 0; i < InvKeyObjectsCount; ++i ) {\n\t\tif( InvKeysList[i]->objectID == optionID ) {\n\t\t\tif( --InvKeysQtys[i] <= 0 ) {\n\t\t\t\t--InvKeyObjectsCount;\n\n\t\t\t\tfor( j = i; j < InvKeyObjectsCount; ++j ) {\n\t\t\t\t\tInvKeysList[j] = InvKeysList[j+1];\n\t\t\t\t\tInvKeysQtys[j] = InvKeysQtys[j+1];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn TRUE;\n\t\t}\n\t}\n\n\treturn FALSE;\n}\n\n\nGAME_OBJECT_ID __cdecl Inv_GetItemOption(GAME_OBJECT_ID itemID) {\n\tswitch( itemID ) {\n\t// Weapons\n\t\tcase ID_PISTOL_ITEM :\n\t\tcase ID_PISTOL_OPTION :\n\t\t\treturn ID_PISTOL_OPTION;\n\t\tcase ID_SHOTGUN_ITEM :\n\t\tcase ID_SHOTGUN_OPTION :\n\t\t\treturn ID_SHOTGUN_OPTION;\n\t\tcase ID_MAGNUM_ITEM :\n\t\tcase ID_MAGNUM_OPTION :\n\t\t\treturn ID_MAGNUM_OPTION;\n\t\tcase ID_UZI_ITEM :\n\t\tcase ID_UZI_OPTION :\n\t\t\treturn ID_UZI_OPTION;\n\t\tcase ID_HARPOON_ITEM :\n\t\tcase ID_HARPOON_OPTION :\n\t\t\treturn ID_HARPOON_OPTION;\n\t\tcase ID_M16_ITEM :\n\t\tcase ID_M16_OPTION :\n\t\t\treturn ID_M16_OPTION;\n\t\tcase ID_GRENADE_ITEM :\n\t\tcase ID_GRENADE_OPTION :\n\t\t\treturn ID_GRENADE_OPTION;\n\t// Ammo\n\t\t// NOTE: It seems here could be Pistol Ammo Option, but it was deleted or commented by CORE\n\t/*\tcase ID_PISTOL_AMMO_ITEM :\n\t\tcase ID_PISTOL_AMMO_OPTION :\n\t\t\treturn ID_PISTOL_AMMO_OPTION; */\n\t\tcase ID_SHOTGUN_AMMO_ITEM :\n\t\tcase ID_SHOTGUN_AMMO_OPTION :\n\t\t\treturn ID_SHOTGUN_AMMO_OPTION;\n\t\tcase ID_MAGNUM_AMMO_ITEM :\n\t\tcase ID_MAGNUM_AMMO_OPTION :\n\t\t\treturn ID_MAGNUM_AMMO_OPTION;\n\t\tcase ID_UZI_AMMO_ITEM :\n\t\tcase ID_UZI_AMMO_OPTION :\n\t\t\treturn ID_UZI_AMMO_OPTION;\n\t\tcase ID_HARPOON_AMMO_ITEM :\n\t\tcase ID_HARPOON_AMMO_OPTION :\n\t\t\treturn ID_HARPOON_AMMO_OPTION;\n\t\tcase ID_M16_AMMO_ITEM :\n\t\tcase ID_M16_AMMO_OPTION :\n\t\t\treturn ID_M16_AMMO_OPTION;\n\t\tcase ID_GRENADE_AMMO_ITEM :\n\t\tcase ID_GRENADE_AMMO_OPTION :\n\t\t\treturn ID_GRENADE_AMMO_OPTION;\n\t// Flares, Medipacks\n\t\tcase ID_SMALL_MEDIPACK_ITEM :\n\t\tcase ID_SMALL_MEDIPACK_OPTION :\n\t\t\treturn ID_SMALL_MEDIPACK_OPTION;\n\t\tcase ID_LARGE_MEDIPACK_ITEM :\n\t\tcase ID_LARGE_MEDIPACK_OPTION :\n\t\t\treturn ID_LARGE_MEDIPACK_OPTION;\n\t\tcase ID_FLARE_ITEM :\n\t\tcase ID_FLARES_ITEM :\n\t\tcase ID_FLARES_OPTION :\n\t\t\treturn ID_FLARES_OPTION;\n\t// Puzzles\n\t\tcase ID_PUZZLE_ITEM1 :\n\t\tcase ID_PUZZLE_OPTION1 :\n\t\t\treturn ID_PUZZLE_OPTION1;\n\t\tcase ID_PUZZLE_ITEM2 :\n\t\tcase ID_PUZZLE_OPTION2 :\n\t\t\treturn ID_PUZZLE_OPTION2;\n\t\tcase ID_PUZZLE_ITEM3 :\n\t\tcase ID_PUZZLE_OPTION3 :\n\t\t\treturn ID_PUZZLE_OPTION3;\n\t\tcase ID_PUZZLE_ITEM4 :\n\t\tcase ID_PUZZLE_OPTION4 :\n\t\t\treturn ID_PUZZLE_OPTION4;\n\t// Pickups\n\t\tcase ID_PICKUP_ITEM1 :\n\t\tcase ID_PICKUP_OPTION1 :\n\t\t\treturn ID_PICKUP_OPTION1;\n\t\tcase ID_PICKUP_ITEM2 :\n\t\tcase ID_PICKUP_OPTION2 :\n\t\t\treturn ID_PICKUP_OPTION2;\n\t// Keys\n\t\tcase ID_KEY_ITEM1 :\n\t\tcase ID_KEY_OPTION1 :\n\t\t\treturn ID_KEY_OPTION1;\n\t\tcase ID_KEY_ITEM2 :\n\t\tcase ID_KEY_OPTION2 :\n\t\t\treturn ID_KEY_OPTION2;\n\t\tcase ID_KEY_ITEM3 :\n\t\tcase ID_KEY_OPTION3 :\n\t\t\treturn ID_KEY_OPTION3;\n\t\tcase ID_KEY_ITEM4 :\n\t\tcase ID_KEY_OPTION4 :\n\t\t\treturn ID_KEY_OPTION4;\n\t\tdefault :\n\t\t\tbreak;\n\t}\n\treturn ID_NONE;\n}\n\nvoid __cdecl RemoveInventoryText() {\n\tfor( int i=0; i<2; ++i ) {\n\t\tT_RemovePrint(InvItemText[i]);\n\t\tInvItemText[i] = NULL;\n\t}\n}\n\nvoid __cdecl Inv_RingInit(RING_INFO *ring, __int16 type, INVENTORY_ITEM **itemList, __int16 objCount, __int16 currentObj, INV_MOTION_INFO *motionInfo) {\n\tring->type = type;\n\tring->itemList = itemList;\n\tring->objCount = objCount;\n\tring->currentObj = currentObj;\n\tring->radius = 0;\n\tring->angleAdder = PHD_360/ objCount;\n\tring->cameraPitch = ( InventoryMode == INV_TitleMode ) ? 0x400 : 0;\n\tring->isRotating = 0;\n\tring->rotCount = 0;\n\tring->targetObj = 0;\n\tring->rotAdder = 0;\n\tring->rotAdderL = 0;\n\tring->rotAdderR = 0;\n\tring->motionInfo = motionInfo;\n\tring->camera.x = 0;\n\tring->camera.y = -0x600;\n\tring->camera.z = 0x380;\n\tring->camera.rotX = 0;\n\tring->camera.rotY = 0;\n\tring->camera.rotZ = 0;\n\tInv_RingMotionInit(ring, 32, 0, 1);\n\tInv_RingMotionRadius(ring, 0x2B0);\n\tInv_RingMotionCameraPos(ring, -0x100);\n\tInv_RingMotionRotation(ring, PHD_180, (-PHD_90) - (ring->currentObj * ring->angleAdder));\n\tring->ringPos.x = 0;\n\tring->ringPos.y = 0;\n\tring->ringPos.z = 0;\n\tring->ringPos.rotX = 0;\n\tring->ringPos.rotZ = 0;\n\tring->ringPos.rotY = motionInfo->rotateTarget + PHD_180;\n\tring->light.x = -0x600;\n\tring->light.y = 0x100;\n\tring->light.z = 0x400;\n}\n\nvoid __cdecl Inv_RingGetView(RING_INFO *ring, PHD_3DPOS *view) {\n\tVECTOR_ANGLES angles;\n\n\tphd_GetVectorAngles((0 - ring->camera.x), (-96 - ring->camera.y), (ring->radius - ring->camera.z), &angles);\n\tview->x = ring->camera.x;\n\tview->y = ring->camera.y;\n\tview->z = ring->camera.z;\n\tview->rotX = angles.pitch + ring->cameraPitch;\n\tview->rotY = angles.yaw;\n\tview->rotZ = 0;\n}\n\nvoid __cdecl Inv_RingLight(RING_INFO *ring) {\n\tVECTOR_ANGLES angles;\n\n\tLsDivider = 0x6000;\n\tphd_GetVectorAngles(ring->light.x, ring->light.y, ring->light.z, &angles);\n\tphd_RotateLight(angles.pitch, angles.yaw);\n}\n\nvoid __cdecl Inv_RingCalcAdders(RING_INFO *ring, __int16 rotDuration) {\n\tring->angleAdder = PHD_360 / ring->objCount;\n\tring->rotAdderL = ring->angleAdder / rotDuration;\n\tring->rotAdderR = -ring->rotAdderL;\n}\n\nvoid __cdecl Inv_RingDoMotions(RING_INFO *ring) {\n\tINVENTORY_ITEM *item;\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tif( mi->framesCount != 0 ) {\n\t\tring->radius += mi->radiusRate;\n\t\tring->camera.y += mi->cameraRate_y;\n\t\tring->ringPos.rotY += mi->rotateRate;\n\t\tring->cameraPitch += mi->cameraRate_pitch;\n\n\t\titem = ring->itemList[ring->currentObj];\n\t\titem->xRotPt += mi->itemRate_xRotPt;\n\t\titem->yRotSel += mi->itemRate_xRot;\n\t\titem->yTrans += mi->itemRate_yTrans;\n\t\titem->zTrans += mi->itemRate_zTrans;\n\n\t\tif( --mi->framesCount == 0 ) {\n\t\t\tmi->status = mi->statusTarget;\n\n\t\t\tif( mi->radiusRate != 0 ) {\n\t\t\t\tmi->radiusRate = 0;\n\t\t\t\tring->radius = mi->radiusTarget;\n\t\t\t}\n\t\t\tif( mi->cameraRate_y != 0 ) {\n\t\t\t\tmi->cameraRate_y = 0;\n\t\t\t\tring->camera.y = mi->cameraTarget_y;\n\t\t\t}\n\t\t\tif( mi->rotateRate != 0 ) {\n\t\t\t\tmi->rotateRate = 0;\n\t\t\t\tring->ringPos.rotY = mi->rotateTarget;\n\t\t\t}\n\t\t\tif( mi->itemRate_xRotPt != 0 ) {\n\t\t\t\tmi->itemRate_xRotPt = 0;\n\t\t\t\titem->xRotPt = mi->itemTarget_xRotPt;\n\t\t\t}\n\t\t\tif( mi->itemRate_xRot != 0 ) {\n\t\t\t\tmi->itemRate_xRot = 0;\n\t\t\t\titem->yRotSel = mi->itemTarget_xRot;\n\t\t\t}\n\t\t\tif( mi->itemRate_yTrans != 0 ) {\n\t\t\t\tmi->itemRate_yTrans = 0;\n\t\t\t\titem->yTrans = mi->itemTarget_yTrans;\n\t\t\t}\n\t\t\tif( mi->itemRate_zTrans != 0 ) {\n\t\t\t\tmi->itemRate_zTrans = 0;\n\t\t\t\titem->zTrans = mi->itemTarget_zTrans;\n\t\t\t}\n\t\t\tif( mi->cameraRate_pitch != 0 ) {\n\t\t\t\tmi->cameraRate_pitch = 0;\n\t\t\t\tring->cameraPitch = mi->cameraTarget_pitch;\n\t\t\t}\n\t\t}\n\t}\n\n\tif( ring->isRotating != 0 ) {\n\t\tring->ringPos.rotY += ring->rotAdder;\n\t\tif( --ring->rotCount == 0 ) {\n\t\t\tring->currentObj = ring->targetObj;\n\t\t\tring->ringPos.rotY =  (-PHD_90) - (ring->currentObj * ring->angleAdder);\n\t\t\tring->isRotating = 0;\n\t\t}\n\t}\n}\n\nvoid __cdecl Inv_RingRotateLeft(RING_INFO *ring) {\n\tring->isRotating = 1;\n\tring->targetObj = ring->currentObj - 1;\n\tif( ring->targetObj < 0 ) {\n\t\tring->targetObj = ring->objCount - 1;\n\t}\n\tring->rotCount = 24;\n\tring->rotAdder = ring->rotAdderL;\n}\n\nvoid __cdecl Inv_RingRotateRight(RING_INFO *ring) {\n\tring->isRotating = 1;\n\tring->targetObj = ring->currentObj + 1;\n\tif( ring->targetObj >= ring->objCount ) {\n\t\tring->targetObj = 0;\n\t}\n\tring->rotCount = 24;\n\tring->rotAdder = ring->rotAdderR;\n}\n\nvoid __cdecl Inv_RingMotionInit(RING_INFO *ring, __int16 framesCount, __int16 status, __int16 statusTarget) {\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tmi->framesCount = framesCount;\n\tmi->status = status;\n\tmi->statusTarget = statusTarget;\n\tmi->radiusTarget = 0;\n\tmi->radiusRate = 0;\n\tmi->cameraTarget_y = 0;\n\tmi->cameraRate_y = 0;\n\tmi->cameraTarget_pitch = 0;\n\tmi->cameraRate_pitch = 0;\n\tmi->rotateTarget = 0;\n\tmi->rotateRate = 0;\n\tmi->itemTarget_xRotPt = 0;\n\tmi->itemRate_xRotPt = 0;\n\tmi->itemTarget_xRot = 0;\n\tmi->itemRate_xRot = 0;\n\tmi->itemTarget_yTrans = 0;\n\tmi->itemRate_yTrans = 0;\n\tmi->itemTarget_zTrans = 0;\n\tmi->itemRate_zTrans = 0;\n\tmi->misc = 0;\n}\n\nvoid __cdecl Inv_RingMotionSetup(RING_INFO *ring, __int16 status, __int16 statusTarget, __int16 framesCount) {\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tmi->framesCount = framesCount;\n\tmi->statusTarget = statusTarget;\n\tmi->status = status;\n\tmi->radiusRate = 0;\n\tmi->cameraRate_y = 0;\n}\n\nvoid __cdecl Inv_RingMotionRadius(RING_INFO *ring, __int16 target) {\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tmi->radiusTarget = target;\n\tmi->radiusRate = (target - ring->radius) / mi->framesCount;\n}\n\nvoid __cdecl Inv_RingMotionRotation(RING_INFO *ring, __int16 rotation, __int16 target) {\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tmi->rotateTarget = target;\n\tmi->rotateRate = rotation / mi->framesCount;\n}\n\nvoid __cdecl Inv_RingMotionCameraPos(RING_INFO *ring, __int16 target) {\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tmi->cameraTarget_y = target;\n\tmi->cameraRate_y = (target - ring->camera.y) / mi->framesCount;\n}\n\nvoid __cdecl Inv_RingMotionCameraPitch(RING_INFO *ring, __int16 target) {\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tmi->cameraTarget_pitch = target;\n\tmi->cameraRate_pitch = target / mi->framesCount;\n}\n\nvoid __cdecl Inv_RingMotionItemSelect(RING_INFO *ring, INVENTORY_ITEM *item) {\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tmi->itemTarget_xRotPt = item->xRotPtSel;\n\tmi->itemRate_xRotPt = item->xRotPtSel / mi->framesCount;\n\tmi->itemTarget_xRot = item->xRotSel;\n\tmi->itemRate_xRot = (item->xRotSel - item->xRot) / mi->framesCount;\n\tmi->itemTarget_yTrans = item->yTransSel;\n\tmi->itemRate_yTrans = item->yTransSel / mi->framesCount;\n\tmi->itemTarget_zTrans = item->zTransSel;\n\tmi->itemRate_zTrans = item->zTransSel / mi->framesCount;\n}\n\nvoid __cdecl Inv_RingMotionItemDeselect(RING_INFO *ring, INVENTORY_ITEM *item) {\n\tINV_MOTION_INFO *mi = ring->motionInfo;\n\n\tmi->itemTarget_xRotPt = 0;\n\tmi->itemRate_xRotPt = -(item->xRotPtSel / mi->framesCount);\n\tmi->itemTarget_xRot = item->xRot;\n\tmi->itemRate_xRot = (item->xRot - item->xRotSel) / mi->framesCount;\n\tmi->itemTarget_yTrans = 0;\n\tmi->itemRate_yTrans = -(item->yTransSel / mi->framesCount);\n\tmi->itemTarget_zTrans = 0;\n\tmi->itemRate_zTrans = -(item->zTransSel / mi->framesCount);\n}\n\n/*\n * Inject function\n */\nvoid Inject_InvFunc() {\n\tINJECT(0x00423B10, InitColours);\n\tINJECT(0x00423C20, RingIsOpen);\n\tINJECT(0x00423D90, RingIsNotOpen);\n\tINJECT(0x00423E20, RingNotActive);\n\tINJECT(0x00424290, RingActive);\n\tINJECT(0x004242D0, Inv_AddItem);\n\tINJECT(0x00424AE0, Inv_InsertItem);\n\tINJECT(0x00424C10, Inv_RequestItem);\n\tINJECT(0x00424C90, Inv_RemoveAllItems);\n\tINJECT(0x00424CB0, Inv_RemoveItem);\n\tINJECT(0x00424DC0, Inv_GetItemOption);\n\tINJECT(0x00424FB0, RemoveInventoryText);\n\tINJECT(0x00424FE0, Inv_RingInit);\n\tINJECT(0x004250F0, Inv_RingGetView);\n\tINJECT(0x00425150, Inv_RingLight);\n\tINJECT(0x00425190, Inv_RingCalcAdders);\n\tINJECT(0x004251C0, Inv_RingDoMotions);\n\tINJECT(0x00425300, Inv_RingRotateLeft);\n\tINJECT(0x00425330, Inv_RingRotateRight);\n\tINJECT(0x00425360, Inv_RingMotionInit);\n\tINJECT(0x004253D0, Inv_RingMotionSetup);\n\tINJECT(0x00425400, Inv_RingMotionRadius);\n\tINJECT(0x00425430, Inv_RingMotionRotation);\n\tINJECT(0x00425460, Inv_RingMotionCameraPos);\n\tINJECT(0x00425490, Inv_RingMotionCameraPitch);\n\tINJECT(0x004254B0, Inv_RingMotionItemSelect);\n\tINJECT(0x00425510, Inv_RingMotionItemDeselect);\n}\n"
  },
  {
    "path": "game/invfunc.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef INVFUNC_H_INCLUDED\n#define INVFUNC_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl InitColours(); // 0x00423B10\nvoid __cdecl RingIsOpen(RING_INFO *ring); // 0x00423C20\nvoid __cdecl RingIsNotOpen(); // 0x00423D90\nvoid __cdecl RingNotActive(INVENTORY_ITEM *item); // 0x00423E20\nvoid __cdecl RingActive(); // 0x00424290\nBOOL __cdecl Inv_AddItem(GAME_OBJECT_ID itemID); // 0x004242D0\nvoid __cdecl Inv_InsertItem(INVENTORY_ITEM *item); // 0x00424AE0\nint __cdecl Inv_RequestItem(GAME_OBJECT_ID itemID); // 0x00424C10\nvoid __cdecl Inv_RemoveAllItems(); // 0x00424C90\nBOOL __cdecl Inv_RemoveItem(GAME_OBJECT_ID itemID); // 0x00424CB0\nGAME_OBJECT_ID __cdecl Inv_GetItemOption(GAME_OBJECT_ID itemID); // 0x00424DC0\nvoid __cdecl RemoveInventoryText(); // 0x00424FB0\nvoid __cdecl Inv_RingInit(RING_INFO *ring, __int16 type, INVENTORY_ITEM **itemList, __int16 objCount, __int16 currentObj, INV_MOTION_INFO *motionInfo); // 0x00424FE0\nvoid __cdecl Inv_RingGetView(RING_INFO *ring, PHD_3DPOS *view); // 0x004250F0\nvoid __cdecl Inv_RingLight(RING_INFO *ring); // 0x00425150\nvoid __cdecl Inv_RingCalcAdders(RING_INFO *ring, __int16 rotDuration); // 0x00425190\nvoid __cdecl Inv_RingDoMotions(RING_INFO *ring); // 0x004251C0\nvoid __cdecl Inv_RingRotateLeft(RING_INFO *ring); // 0x00425300\nvoid __cdecl Inv_RingRotateRight(RING_INFO *ring); // 0x00425330\nvoid __cdecl Inv_RingMotionInit(RING_INFO *ring, __int16 framesCount, __int16 status, __int16 statusTarget); // 0x00425360\nvoid __cdecl Inv_RingMotionSetup(RING_INFO *ring, __int16 status, __int16 statusTarget, __int16 framesCount); // 0x004253D0\nvoid __cdecl Inv_RingMotionRadius(RING_INFO *ring, __int16 target); // 0x00425400\nvoid __cdecl Inv_RingMotionRotation(RING_INFO *ring, __int16 rotation, __int16 target); // 0x00425430\nvoid __cdecl Inv_RingMotionCameraPos(RING_INFO *ring, __int16 target); // 0x00425460\nvoid __cdecl Inv_RingMotionCameraPitch(RING_INFO *ring, __int16 target); // 0x00425490\nvoid __cdecl Inv_RingMotionItemSelect(RING_INFO *ring, INVENTORY_ITEM *item); // 0x004254B0\nvoid __cdecl Inv_RingMotionItemDeselect(RING_INFO *ring, INVENTORY_ITEM *item); // 0x00425510\n\n#endif // INVFUNC_H_INCLUDED\n"
  },
  {
    "path": "game/invtext.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/invtext.h\"\n#include \"game/text.h\"\n#include \"specific/output.h\"\n#include \"specific/smain.h\"\n#include \"global/vars.h\"\n\n#define REQ_NEARZ\t\t(8)\n#define REQ_MIDZ\t\t(16)\n#define REQ_FARZ\t\t(48)\n\n#define STATS_LN_COUNT\t(7)\n#define STATS_WIDTH\t\t(304)\n\n// Y coordinates relative to the bottom of the screen\n#ifdef FEATURE_HUD_IMPROVED\n#define STATS_Y_POS\t\t(-44)\n#define REQ_LN_HEIGHT (15)\n\nextern DWORD InvTextBoxMode;\n\nstatic const char MoreDownString[]\t= \" \\x0F                                        \\x0F \";\nstatic const char MoreUpString[]\t= \" \\x10                                        \\x10 \";\n#else // FEATURE_HUD_IMPROVED\n#define STATS_Y_POS\t\t(-32)\n#define REQ_LN_HEIGHT\t(18)\n#endif // FEATURE_HUD_IMPROVED\n\n// NOTE: gouraud arrays have been taken from PlayStation version of the game.\n// These arrays are not used in the original PC version of the game.\n\nGOURAUD_FILL ReqBgndGour1 = {{\n\t{0x80002000, 0x80002000, 0x80006000, 0x80002000},\n\t{0x80002000, 0x80002000, 0x80002000, 0x80006000},\n\t{0x80006000, 0x80002000, 0x80002000, 0x80002000},\n\t{0x80002000, 0x80006000, 0x80002000, 0x80002000},\n}};\nGOURAUD_OUTLINE ReqBgndGour2 = {\n\t0xFF606060, 0xFF808080, 0xFF202020,\n\t0xFF000000, 0xFF000000, 0xFF202020,\n\t0xFF404040, 0xFF404040, 0xFF606060,\n};\n\nGOURAUD_FILL ReqMainGour1 = {{\n\t{0x80000000, 0x80000000, 0x80108038, 0x80000000},\n\t{0x80000000, 0x80000000, 0x80000000, 0x80108038},\n\t{0x80108038, 0x80000000, 0x80000000, 0x80000000},\n\t{0x80000000, 0x80108038, 0x80000000, 0x80000000},\n}};\nGOURAUD_OUTLINE ReqMainGour2 = {\n\t0xFF000000, 0xFF000000, 0xFF000000,\n\t0xFF000000, 0xFF000000, 0xFF000000,\n\t0xFF000000, 0xFF000000, 0xFF000000,\n};\n\nGOURAUD_FILL ReqSelGour1 = {{\n\t{0x80000000, 0x80000000, 0x8038F080, 0x80000000},\n\t{0x80000000, 0x80000000, 0x80000000, 0x8038F080},\n\t{0x8038F080, 0x80000000, 0x80000000, 0x80000000},\n\t{0x80000000, 0x8038F080, 0x80000000, 0x80000000},\n}};\nGOURAUD_OUTLINE ReqSelGour2 = {\n\t0xFF000000, 0xFFFFFFFF, 0xFF000000,\n\t0xFF38F080, 0xFF000000, 0xFFFFFFFF,\n\t0xFF000000, 0xFF38F080, 0xFF000000,\n};\n\nextern int GF_GetNumSecrets(DWORD levelID);\n\n#ifdef FEATURE_ASSAULT_SAVE\nextern void SaveAssault();\n#endif // FEATURE_ASSAULT_SAVE\n\nvoid __cdecl Init_Requester(REQUEST_INFO *req) {\n\treq->headingText1  = NULL;\n\treq->headingText2  = NULL;\n\treq->headingFlags1 = 0;\n\treq->headingFlags2 = 0;\n\n\treq->backgroundText = NULL;\n\treq->backgroundFlags = 1;\n\treq->moreupText = NULL;\n\treq->moreupFlags = 1;\n\treq->moredownText = NULL;\n\treq->moredownFlags = 1;\n\n\tfor( int i=0; i<24; ++i ) {\n\t\treq->itemTexts1[i] = NULL;\n\t\treq->itemFlags1[i] = 0;\n\t\treq->itemTexts2[i] = NULL;\n\t\treq->itemFlags2[i] = 0;\n\t}\n\treq->itemsCount = 0;\n\n\treq->lpItemFlags1 = RequesterItemFlags1;\n\treq->lpItemFlags2 = RequesterItemFlags2;\n#ifdef FEATURE_HUD_IMPROVED\n\treq->renderWidth  = GetRenderWidthDownscaled();\n\treq->renderHeight = GetRenderHeightDownscaled();\n#else // !FEATURE_HUD_IMPROVED\n\treq->renderWidth  = GetRenderWidth();\n\treq->renderHeight = GetRenderHeight();\n#endif // FEATURE_HUD_IMPROVED\n}\n\nvoid __cdecl Remove_Requester(REQUEST_INFO *req) {\n\tT_RemovePrint(req->headingText1);\n\treq->headingText1 = NULL;\n\tT_RemovePrint(req->headingText2);\n\treq->headingText2 = NULL;\n\tT_RemovePrint(req->backgroundText);\n\treq->backgroundText = NULL;\n\tT_RemovePrint(req->moreupText);\n\treq->moreupText = NULL;\n\tT_RemovePrint(req->moredownText);\n\treq->moredownText = NULL;\n\n\tfor( int i=0; i<24; ++i ) {\n\t\tT_RemovePrint(req->itemTexts1[i]);\n\t\treq->itemTexts1[i] = NULL;\n\t\tT_RemovePrint(req->itemTexts2[i]);\n\t\treq->itemTexts2[i] = NULL;\n\t}\n}\n\nvoid __cdecl ReqItemCentreAlign(REQUEST_INFO *req, TEXT_STR_INFO *textInfo) {\n\tif( textInfo != NULL ) {\n\t\ttextInfo->xPos = req->xPos;\n\t\ttextInfo->bgndOffX = 0;\n\t}\n}\n\nvoid __cdecl ReqItemLeftAlign(REQUEST_INFO *req, TEXT_STR_INFO *textInfo) {\n\tint bgndOffX;\n\n\tif( textInfo == NULL )\n\t\treturn;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tbgndOffX = (req->pixWidth - T_GetTextWidth(textInfo)) / 2 - 8;\n#else // FEATURE_HUD_IMPROVED\n\tDWORD scaleH = GetTextScaleH(textInfo->scaleH);\n\tbgndOffX = (req->pixWidth * scaleH / PHD_ONE) / 2 - T_GetTextWidth(textInfo) / 2 - (8 * scaleH / PHD_ONE);\n#endif // FEATURE_HUD_IMPROVED\n\ttextInfo->xPos = req->xPos - bgndOffX;\n\ttextInfo->bgndOffX = bgndOffX;\n}\n\nvoid __cdecl ReqItemRightAlign(REQUEST_INFO *req, TEXT_STR_INFO *textInfo) {\n\tint bgndOffX;\n\n\tif( textInfo == NULL )\n\t\treturn;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tbgndOffX = (req->pixWidth - T_GetTextWidth(textInfo)) / 2 - 8;\n#else // FEATURE_HUD_IMPROVED\n\tDWORD scaleH = GetTextScaleH(textInfo->scaleH);\n\tbgndOffX = (req->pixWidth * scaleH / PHD_ONE) / 2 - T_GetTextWidth(textInfo) / 2 - (8 * scaleH / PHD_ONE);\n#endif // FEATURE_HUD_IMPROVED\n\ttextInfo->xPos = req->xPos + bgndOffX;\n\ttextInfo->bgndOffX = -bgndOffX;\n}\n\nint __cdecl Display_Requester(REQUEST_INFO *req, BOOL removeOnDeselect, BOOL isBackground) {\n\tint i, linesCount, boxHeight, boxOff, linesOff;\n\tDWORD renderWidth, renderHeight;\n\n\tlinesCount = req->visibleCount;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\tboxHeight = req->lineHeight * linesCount + 42;\n\t\tboxOff = req->yPos - boxHeight + 2;\n\t\tlinesOff = boxOff + 30;\n\t} else {\n\t\tboxHeight = req->lineHeight * (linesCount + 1) + 22;\n\t\tboxOff = req->yPos - boxHeight + 2;\n\t\tlinesOff = boxOff + req->lineHeight + 10;\n\t}\n\n\trenderWidth = GetRenderWidthDownscaled();\n\trenderHeight = GetRenderHeightDownscaled();\n#else // !FEATURE_HUD_IMPROVED\n\tboxHeight = req->lineHeight * (linesCount + 1) + 22;\n\tboxOff = req->yPos - boxHeight + 2;\n\tlinesOff = boxOff + req->lineHeight + 10;\n\n\trenderWidth = GetRenderWidth();\n\trenderHeight = GetRenderHeight();\n#endif // FEATURE_HUD_IMPROVED\n\n\tif( renderWidth != req->renderWidth || renderHeight != req->renderHeight ) {\n\t\tRemove_Requester(req);\n\t\treq->renderWidth = renderWidth;\n\t\treq->renderHeight = renderHeight;\n\t}\n\n\treq->lpItemFlags1 = RequesterItemFlags1;\n\treq->lpItemFlags2 = RequesterItemFlags2;\n\n\tif( req->itemsCount < req->visibleCount ) {\n\t\tlinesCount = req->itemsCount;\n\t}\n\n\t// Heading 1\n\tif( CHK_ANY(req->headingFlags1, REQFLAG_ACTIVE) ) {\n\t\tif( req->headingText1 == NULL ) {\n\t\t\treq->headingText1 = T_Print(req->xPos, boxOff, req->zPos, req->headingString1);\n\t\t\tT_CentreH(req->headingText1, 1);\n\t\t\tT_BottomAlign(req->headingText1, 1);\n\t\t\tif( isBackground ) {\n\t\t\t\tT_AddBackground(req->headingText1, (req->pixWidth - 4), 0, 0, 0, REQ_NEARZ, ICLR_Black, &ReqMainGour1, 2);\n\t\t\t\tT_AddOutline(req->headingText1, TRUE, ICLR_Orange, &ReqMainGour2, 0);\n\t\t\t}\n\t\t}\n\t\tif( CHK_ANY(req->headingFlags1, REQFLAG_LEFT) ) {\n\t\t\tReqItemLeftAlign(req, req->headingText1);\n\t\t}\n\t\tif( CHK_ANY(req->headingFlags1, REQFLAG_RIGHT) ) {\n\t\t\tReqItemRightAlign(req, req->headingText1);\n\t\t}\n\t}\n\n\t// Heading 2\n\tif( CHK_ANY(req->headingFlags2, REQFLAG_ACTIVE) ) {\n\t\tif( req->headingText2 == NULL ) {\n\t\t\treq->headingText2 = T_Print(req->xPos, boxOff, req->zPos, req->headingString2);\n\t\t\tT_CentreH(req->headingText2, 1);\n\t\t\tT_BottomAlign(req->headingText2, 1);\n\t\t\tif( isBackground ) {\n\t\t\t\tT_AddBackground(req->headingText2, (req->pixWidth - 4), 0, 0, 0, REQ_NEARZ, ICLR_Black, &ReqMainGour1, 2);\n\t\t\t\tT_AddOutline(req->headingText2, TRUE, ICLR_Orange, &ReqMainGour2, 0);\n\t\t\t}\n\t\t}\n\t\tif( CHK_ANY(req->headingFlags2, REQFLAG_LEFT) ) {\n\t\t\tReqItemLeftAlign(req, req->headingText2);\n\t\t}\n\t\tif( CHK_ANY(req->headingFlags2, REQFLAG_RIGHT) ) {\n\t\t\tReqItemRightAlign(req, req->headingText2);\n\t\t}\n\t}\n\n\t// Background\n\tif( isBackground && req->backgroundText == NULL && CHK_ANY(req->backgroundFlags, REQFLAG_ACTIVE) ) {\n\t\treq->backgroundText = T_Print(req->xPos, boxOff - 2, 0, \" \");\n\t\tT_CentreH(req->backgroundText, 1);\n\t\tT_BottomAlign(req->backgroundText, 1);\n\t\tT_AddBackground(req->backgroundText, req->pixWidth, boxHeight, 0, 0, REQ_FARZ, ICLR_Black, &ReqBgndGour1, 1);\n\t\tT_AddOutline(req->backgroundText, TRUE, ICLR_Blue, &ReqBgndGour2, 0);\n\t}\n\n\t// More up\n\tif( req->lineOffset == 0 ) {\n\t\tT_RemovePrint(req->moreupText);\n\t\treq->moreupText = NULL;\n\t}\n\telse if( req->moreupText == NULL && CHK_ANY(req->moreupFlags, REQFLAG_ACTIVE) ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\t\treq->moreupText = T_Print(req->xPos, boxOff + 15, 0, MoreUpString);\n\t\t}\n#endif // FEATURE_HUD_IMPROVED\n\t\tT_CentreH(req->moreupText, 1);\n\t\tT_BottomAlign(req->moreupText, 1);\n\t}\n\n\t// More down\n\tif( req->itemsCount <= (req->visibleCount + req->lineOffset) ) {\n\t\tT_RemovePrint(req->moredownText);\n\t\treq->moredownText = 0;\n\t}\n\telse if( req->moredownText == NULL && CHK_ANY(req->moredownFlags, REQFLAG_ACTIVE) ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\t\treq->moredownText = T_Print(req->xPos, req->yPos - 12, 0, MoreDownString);\n\t\t}\n#endif // FEATURE_HUD_IMPROVED\n\t\tT_CentreH(req->moredownText, 1);\n\t\tT_BottomAlign(req->moredownText, 1);\n\t}\n\n\t// Lines init\n\tfor( i = 0; i < linesCount; ++i ) {\n\t\tif( CHK_ANY(req->lpItemFlags1[req->lineOffset + i], REQFLAG_ACTIVE) ) {\n\t\t\tif( req->itemTexts1[i] == NULL ) {\n\t\t\t\t// NOTE: here was 0 instead of REQ_NEARZ in the original game\n\t\t\t\treq->itemTexts1[i] = T_Print(0, (linesOff + req->lineHeight * i), REQ_NEARZ, &req->lpItemStrings1[(req->lineOffset + i) * req->itemStringLen]);\n\t\t\t\tT_CentreH(req->itemTexts1[i], 1);\n\t\t\t\tT_BottomAlign(req->itemTexts1[i], 1);\n\t\t\t}\n\n\t\t\tif( CHK_ANY(req->reqFlags, REQFLAG_NOCURSOR) || (req->lineOffset + i != req->selected) ) {\n\t\t\t\treq->itemTexts1[i]->zPos = REQ_NEARZ; // NOTE: this line is absent in the original game\n\t\t\t\tT_RemoveBackground(req->itemTexts1[i]);\n\t\t\t\tT_RemoveOutline(req->itemTexts1[i]);\n\t\t\t} else {\n\t\t\t\treq->itemTexts1[i]->zPos = 0; // NOTE: this line is absent in the original game\n\t\t\t\tT_AddBackground(req->itemTexts1[i], (req->pixWidth - 12), 0, 0, 0, REQ_MIDZ, ICLR_Black, &ReqSelGour1, 1);\n\t\t\t\tT_AddOutline(req->itemTexts1[i], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n\t\t\t}\n\n\t\t\tif( CHK_ANY(req->lpItemFlags1[req->lineOffset + i], REQFLAG_LEFT) ) {\n\t\t\t\tReqItemLeftAlign(req, req->itemTexts1[i]);\n\t\t\t}\n\t\t\telse if( CHK_ANY(req->lpItemFlags1[req->lineOffset + i], REQFLAG_RIGHT) ) {\n\t\t\t\tReqItemRightAlign(req, req->itemTexts1[i]);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tReqItemCentreAlign(req, req->itemTexts1[i]);\n\t\t\t}\n\t\t} else {\n\t\t\tT_RemovePrint(req->itemTexts1[i]);\n\t\t\tT_RemoveBackground(req->itemTexts1[i]);\n\t\t\tT_RemoveOutline(req->itemTexts1[i]);\n\t\t\treq->itemTexts1[i] = NULL;\n\t\t}\n\n\t\tif( CHK_ANY(req->lpItemFlags2[req->lineOffset + i], REQFLAG_ACTIVE) ) {\n\t\t\tif( req->itemTexts2[i] == NULL ) {\n\t\t\t\t// NOTE: here was 0 instead of REQ_NEARZ in the original game\n\t\t\t\treq->itemTexts2[i] = T_Print(0, (linesOff + req->lineHeight * i), REQ_NEARZ, &req->lpItemStrings2[(req->lineOffset + i) * req->itemStringLen]);\n\t\t\t\tT_CentreH(req->itemTexts2[i], 1);\n\t\t\t\tT_BottomAlign(req->itemTexts2[i], 1);\n\t\t\t}\n\n\t\t\t// NOTE: this code block is absent in the original game\n\t\t\tif( CHK_ANY(req->reqFlags, REQFLAG_NOCURSOR) || (req->lineOffset + i != req->selected) ) {\n\t\t\t\treq->itemTexts2[i]->zPos = REQ_NEARZ;\n\t\t\t} else {\n\t\t\t\treq->itemTexts2[i]->zPos = 0;\n\t\t\t}\n\n\t\t\tif( CHK_ANY(req->lpItemFlags2[req->lineOffset + i], REQFLAG_LEFT) ) {\n\t\t\t\tReqItemLeftAlign(req, req->itemTexts2[i]);\n\t\t\t}\n\t\t\telse if( CHK_ANY(req->lpItemFlags2[req->lineOffset + i], REQFLAG_RIGHT) ) {\n\t\t\t\tReqItemRightAlign(req, req->itemTexts2[i]);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tReqItemCentreAlign(req, req->itemTexts2[i]);\n\t\t\t}\n\t\t} else {\n\t\t\tT_RemovePrint(req->itemTexts2[i]);\n\t\t\tT_RemoveBackground(req->itemTexts2[i]);\n\t\t\tT_RemoveOutline(req->itemTexts2[i]);\n\t\t\treq->itemTexts2[i] = NULL;\n\t\t}\n\t}\n\n\t// Lines change\n\tif( req->lineOffset != req->lineOldOffset ) {\n\t\tfor( i = 0; i < linesCount; ++i ) {\n\t\t\tif( req->itemTexts1[i] != NULL && CHK_ANY(req->lpItemFlags1[req->lineOffset + i], REQFLAG_ACTIVE) ) {\n\t\t\t\tT_ChangeText(req->itemTexts1[i], &req->lpItemStrings1[(req->lineOffset + i) * req->itemStringLen]);\n\t\t\t}\n\n\t\t\tif( CHK_ANY(req->lpItemFlags1[req->lineOffset + i], REQFLAG_LEFT) ) {\n\t\t\t\tReqItemLeftAlign(req, req->itemTexts1[i]);\n\t\t\t}\n\t\t\telse if( CHK_ANY(req->lpItemFlags1[req->lineOffset + i], REQFLAG_RIGHT) ) {\n\t\t\t\tReqItemRightAlign(req, req->itemTexts1[i]);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tReqItemCentreAlign(req, req->itemTexts1[i]);\n\t\t\t}\n\n\t\t\tif( req->itemTexts2[i] != NULL && CHK_ANY(req->lpItemFlags2[req->lineOffset + i], REQFLAG_ACTIVE) ) {\n\t\t\t\tT_ChangeText(req->itemTexts2[i], &req->lpItemStrings2[(req->lineOffset + i) * req->itemStringLen]);\n\t\t\t}\n\n\t\t\tif( CHK_ANY(req->lpItemFlags2[req->lineOffset + i], REQFLAG_LEFT) ) {\n\t\t\t\tReqItemLeftAlign(req, req->itemTexts2[i]);\n\t\t\t}\n\t\t\telse if( CHK_ANY(req->lpItemFlags2[req->lineOffset + i], REQFLAG_RIGHT) ) {\n\t\t\t\tReqItemRightAlign(req, req->itemTexts2[i]);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tReqItemCentreAlign(req, req->itemTexts2[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Menu down\n\tif( CHK_ANY(InputDB, IN_BACK) ) {\n\t\tif( CHK_ANY(req->reqFlags, REQFLAG_NOCURSOR) ) { // Cursor is disabled. Move the list\n\t\t\treq->lineOldOffset = req->lineOffset;\n\t\t\tif( req->lineOffset < (req->itemsCount - req->visibleCount) ) {\n\t\t\t\t++req->lineOffset;\n\t\t\t}\n\t\t}\n\t\telse { // Cursor is enabled. Move the cursor\n\t\t\tif( req->selected < (req->itemsCount - 1) ) {\n\t\t\t\t++req->selected;\n\t\t\t}\n\t\t\treq->lineOldOffset = req->lineOffset;\n\t\t\tif( req->lineOffset <= (req->selected - req->visibleCount) ) {\n\t\t\t\t++req->lineOffset;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\n\t// Menu Up\n\tif( CHK_ANY(InputDB, IN_FORWARD) ) {\n\t\tif( CHK_ANY(req->reqFlags, REQFLAG_NOCURSOR) ) { // Cursor is disabled. Move the list\n\t\t\treq->lineOldOffset = req->lineOffset;\n\t\t\tif( req->lineOffset > 0 ) {\n\t\t\t\t--req->lineOffset;\n\t\t\t}\n\t\t}\n\t\telse { // Cursor is enabled. Move the cursor\n\t\t\tif( req->selected > 0 ) {\n\t\t\t\t--req->selected;\n\t\t\t}\n\n\t\t\treq->lineOldOffset = req->lineOffset;\n\t\t\tif( req->lineOffset > req->selected ) {\n\t\t\t\t--req->lineOffset;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\n\t// Menu Select\n\tif( CHK_ANY(InputDB, IN_SELECT) ) {\n\t\t// This check prevents from loading an empty saved game slot\n\t\t// NOTE: there was an ugly strcmp check in the original game\n\t\tif( req == &LoadGameRequester && InventoryExtraData[0] == 0 && !SaveSlotFlags[req->selected] ) {\n\t\t\tInputStatus = 0;\n\t\t\treturn 0;\n\t\t} else {\n\t\t\tRemove_Requester(req);\n\t\t\treturn (req->selected + 1);\n\t\t}\n\t}\n\n\t// Menu Deselect\n\tif( CHK_ANY(InputDB, IN_DESELECT) && removeOnDeselect ) {\n\t\tRemove_Requester(req);\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\nvoid __cdecl SetRequesterHeading(REQUEST_INFO *req, const char *string1, DWORD flags1, const char *string2, DWORD flags2) {\n\tT_RemovePrint(req->headingText1);\n\treq->headingText1 = NULL;\n\tT_RemovePrint(req->headingText2);\n\treq->headingText2 = NULL;\n\n\tif( string1 != NULL ) {\n\t\tstrcpy(req->headingString1, string1);\n\t\treq->headingFlags1 = flags1 | REQFLAG_ACTIVE;\n\t} else {\n\t\tstrcpy(req->headingString1, \"u\");\n\t\treq->headingFlags1 = 0;\n\t}\n\n\tif( string2 != NULL ) {\n\t\tstrcpy(req->headingString2, string2);\n\t\treq->headingFlags2 = flags2 | REQFLAG_ACTIVE;\n\t} else {\n\t\tstrcpy(req->headingString2, \"u\");\n\t\treq->headingFlags2 = 0;\n\t}\n}\n\nvoid __cdecl RemoveAllReqItems(REQUEST_INFO *req) {\n\treq->itemsCount = 0;\n\treq->lineOffset = 0;\n\treq->selected = 0;\n}\n\nvoid __cdecl ChangeRequesterItem(REQUEST_INFO *req, DWORD itemIdx, const char *string1, DWORD flags1, const char *string2, DWORD flags2) {\n\tT_RemovePrint(req->itemTexts1[itemIdx]);\n\treq->itemTexts1[itemIdx] = NULL;\n\tT_RemovePrint(req->itemTexts2[itemIdx]);\n\treq->itemTexts2[itemIdx] = NULL;\n\n\tif( string1 != NULL ) {\n\t\tstrcpy(&req->lpItemStrings1[itemIdx * req->itemStringLen], string1);\n\t\treq->lpItemFlags1[itemIdx] = flags1 | REQFLAG_ACTIVE;\n\t} else {\n\t\treq->lpItemFlags1[itemIdx] = 0;\n\t}\n\n\tif( string2 != NULL ) {\n\t\tstrcpy(&req->lpItemStrings2[itemIdx * req->itemStringLen], string2);\n\t\treq->lpItemFlags2[itemIdx] = flags2 | REQFLAG_ACTIVE;\n\t} else {\n\t\treq->lpItemFlags2[itemIdx] = 0;\n\t}\n}\n\nvoid __cdecl AddRequesterItem(REQUEST_INFO *req, const char *string1, DWORD flags1, const char *string2, DWORD flags2) {\n\treq->lpItemFlags1 = RequesterItemFlags1;\n\treq->lpItemFlags2 = RequesterItemFlags2;\n\n\tif( string1 != NULL ) {\n\t\tstrcpy(&req->lpItemStrings1[req->itemsCount * req->itemStringLen], string1);\n\t\treq->lpItemFlags1[req->itemsCount] = flags1 | REQFLAG_ACTIVE;\n\t} else {\n\t\treq->lpItemFlags1[req->itemsCount] = 0;\n\t}\n\n\tif( string2 != NULL ) {\n\t\tstrcpy(&req->lpItemStrings2[req->itemsCount * req->itemStringLen], string2);\n\t\treq->lpItemFlags2[req->itemsCount] = flags2 | REQFLAG_ACTIVE;\n\t} else {\n\t\treq->lpItemFlags2[req->itemsCount] = 0;\n\t}\n\n\t++req->itemsCount;\n}\n\nvoid __cdecl SetPCRequesterSize(REQUEST_INFO *req, int maxLines, __int16 yPos) {\n\treq->yPos = yPos;\n#ifdef FEATURE_HUD_IMPROVED\n\treq->visibleCount = GetRenderHeightDownscaled() / 2 / REQ_LN_HEIGHT;\n#else // !FEATURE_HUD_IMPROVED\n\treq->visibleCount = GetRenderHeight() / 2 / REQ_LN_HEIGHT;\n#endif // FEATURE_HUD_IMPROVED\n\tif( req->visibleCount > maxLines )\n\t\treq->visibleCount = maxLines;\n}\n\nBOOL __cdecl AddAssaultTime(DWORD newTime) {\n\tint i, j;\n\n\tfor( i = 0; i < 10; ++i ) {\n\t\tif( Assault.bestTime[i] == 0 || newTime < Assault.bestTime[i] ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif( i > 9 ) { // Not best time at all\n\t\t// NOTE: finishCount is not incremented in the original code in case of bad time\n\t\t// but in my opinion, bad finish should be counted here, as well as good.\n\t\t++Assault.finishCount;\n\t\treturn FALSE;\n\t}\n\n\t// Insertion required if the finish slot is not the last one\n\tfor( j = 9; j > i; --j ) {\n\t\tAssault.bestTime[j] = Assault.bestTime[j - 1];\n\t\tAssault.bestFinish[j] = Assault.bestFinish[j - 1];\n\t}\n\n\tAssault.bestTime[i] = newTime;\n\tAssault.bestFinish[i] = ++Assault.finishCount;\n\n#ifdef FEATURE_ASSAULT_SAVE\n\tSaveAssault();\n#endif // FEATURE_ASSAULT_SAVE\n\treturn TRUE;\n}\n\nvoid __cdecl ShowGymStatsText() {\n\tstatic bool isStatsTextReady = false;\n\tint minutes, seconds, deciseconds;\n\tchar statStr1[32];\n\tchar statStr2[32];\n\n\tif( !isStatsTextReady ) {\n\t\tStatsRequester.reqFlags |= REQFLAG_NOCURSOR;\n\t\tSetPCRequesterSize(&StatsRequester, STATS_LN_COUNT, STATS_Y_POS);\n\n\t\tStatsRequester.lineHeight = REQ_LN_HEIGHT;\n\t\tStatsRequester.itemsCount = 0;\n\t\tStatsRequester.selected = 0;\n\t\tStatsRequester.lineOffset = 0;\n\t\tStatsRequester.lineOldOffset = 0;\n\t\tStatsRequester.pixWidth = STATS_WIDTH;\n\t\tStatsRequester.xPos = 0;\n\t\tStatsRequester.zPos = 0;\n\t\tStatsRequester.lpItemStrings1 = (char *)SaveGameStrings1;\n\t\tStatsRequester.lpItemStrings2 = (char *)SaveGameStrings2;\n\t\tStatsRequester.itemStringLen = 50;\n\n\t\tInit_Requester(&StatsRequester);\n\t\tSetRequesterHeading(&StatsRequester, GF_GameStringTable[GSI_String_BestTimes], 0, NULL, 0);\n\n\t\tfor( int i = 0; i < 10; ++i ) {\n\t\t\tif( Assault.bestTime[i] == 0 ) {\n\t\t\t\tif( i == 0 ) {\n\t\t\t\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_NoTimesSet], 0, NULL, 0);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdeciseconds = Assault.bestTime[i] % 30 / 3;\n\t\t\tseconds = Assault.bestTime[i] / 30 % 60;\n\t\t\tminutes = Assault.bestTime[i] / 30 / 60;\n\t\t\tsprintf(statStr1, \"%2d: %s %d\", (i + 1), GF_GameStringTable[GSI_String_Finish], (int)Assault.bestFinish[i]);\n\t\t\tsprintf(statStr2, \"%02d:%02d.%-2d\", minutes, seconds, deciseconds);\n\t\t\tAddRequesterItem(&StatsRequester, statStr1, REQFLAG_LEFT, statStr2, REQFLAG_RIGHT);\n\t\t}\n\n\t\tisStatsTextReady = true;\n\t}\n\telse if( Display_Requester(&StatsRequester, TRUE, TRUE) ) {\n\t\tisStatsTextReady = false;\n\t}\n\telse {\n\t\tInputDB = 0;\n\t\tInputStatus = 0;\n\t}\n}\n\nvoid __cdecl ShowStatsText(char *timeString, BOOL removeOnDeselect) {\n\tstatic bool isStatsTextReady = false;\n\tbool isSecret1, isSecret2, isSecret3;\n\tint bufLen, distance;\n\tchar bufStr[32];\n\n\tif( !isStatsTextReady ) {\n\t\tStatsRequester.reqFlags |= REQFLAG_NOCURSOR;\n\t\tSetPCRequesterSize(&StatsRequester, STATS_LN_COUNT, STATS_Y_POS);\n\n\t\tStatsRequester.lineHeight = REQ_LN_HEIGHT;\n\t\tStatsRequester.itemsCount = 0;\n\t\tStatsRequester.selected = 0;\n\t\tStatsRequester.lineOffset = 0;\n\t\tStatsRequester.lineOldOffset = 0;\n\t\tStatsRequester.pixWidth = STATS_WIDTH;\n\t\tStatsRequester.xPos = 0;\n\t\tStatsRequester.zPos = 0;\n\t\tStatsRequester.lpItemStrings1 = (char *)SaveGameStrings1;\n\t\tStatsRequester.lpItemStrings2 = (char *)SaveGameStrings2;\n\t\tStatsRequester.itemStringLen = 50;\n\n\t\tInit_Requester(&StatsRequester);\n\t\tSetRequesterHeading(&StatsRequester, GF_LevelNamesStringTable[CurrentLevel], 0, NULL, 0);\n\n\t\t// Time taken\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_TimeTaken], REQFLAG_LEFT, timeString, REQFLAG_RIGHT);\n\n\t\t// Secrets found\n\t\tif( GF_NumSecrets > 0 ) {\n\t\t\tisSecret1 = CHK_ANY(SaveGame.statistics.secrets, 1);\n\t\t\tisSecret2 = CHK_ANY(SaveGame.statistics.secrets, 2);\n\t\t\tisSecret3 = CHK_ANY(SaveGame.statistics.secrets, 4);\n\n\t\t\tif( isSecret1 || isSecret2 || isSecret3 ) {\n\t\t\t\tbufLen = 0;\n\n\t\t\t\tif( isSecret1 ) {\n\t\t\t\t\tbufStr[bufLen++] = CHAR_SECRET1;\n\t\t\t\t} else {\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t}\n\n\t\t\t\tif( isSecret2 ) {\n\t\t\t\t\tbufStr[bufLen++] = CHAR_SECRET2;\n\t\t\t\t} else {\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t}\n\n\t\t\t\tif( isSecret3 ) {\n\t\t\t\t\tbufStr[bufLen++] = CHAR_SECRET3;\n\t\t\t\t} else {\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t\tbufStr[bufLen++] = ' ';\n\t\t\t\t}\n\n\t\t\t\tbufStr[bufLen] = 0;\n\t\t\t} else {\n\t\t\t\tsprintf(bufStr, GF_GameStringTable[GSI_String_None]);\n\t\t\t}\n\t\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_SecretsFound], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\t\t}\n\n\t\t// Kills\n\t\tsprintf(bufStr, \"%d\", (int)SaveGame.statistics.kills);\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_Kills], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// Ammo used\n\t\tsprintf(bufStr, \"%d\", (int)SaveGame.statistics.shots);\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_AmmoUsed], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// Hits\n\t\tsprintf(bufStr, \"%d\", (int)SaveGame.statistics.hits);\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_Hits], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// HealthPacks used\n\t\tif( (SaveGame.statistics.mediPacks % 2) == 0 ) {\n\t\t\tsprintf(bufStr, \"%d.0\", (int)(SaveGame.statistics.mediPacks / 2) );\n\t\t} else {\n\t\t\tsprintf(bufStr, \"%d.5\", (int)(SaveGame.statistics.mediPacks / 2) );\n\t\t}\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_HealthPacksUsed], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// Distance travelled\n\t\tdistance = SaveGame.statistics.distance / 445;\n\t\tif( distance < 1000 ) {\n\t\t\tsprintf(bufStr, \"%dm\", distance);\n\t\t} else {\n\t\t\tsprintf(bufStr, \"%d.%02dkm\", (distance / 1000), (distance % 100));\n\t\t}\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_DistanceTravelled], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\tisStatsTextReady = true;\n\t} else {\n\t\tChangeRequesterItem(&StatsRequester, 0, GF_GameStringTable[GSI_String_TimeTaken], REQFLAG_LEFT, timeString, REQFLAG_RIGHT);\n\t\tif( Display_Requester(&StatsRequester, removeOnDeselect, TRUE) ) {\n\t\t\tisStatsTextReady = false;\n\t\t} else {\n\t\t\tInputDB = 0;\n\t\t\tInputStatus = 0;\n\t\t}\n\t}\n}\n\nvoid __cdecl ShowEndStatsText() {\n\tstatic bool isStatsTextReady = false;\n\tint i, numLevels;\n\tint total, maxTotal;\n\tint hours, minutes, seconds;\n\tchar bufStr[32];\n\n\tnumLevels = GF_GameFlow.num_Levels - GF_GameFlow.num_Demos;\n\tCLAMPG(numLevels, CurrentLevel+1); // NOTE: Fix for Gold. Don't count statistics for bonus levels!\n\n\tif( !isStatsTextReady ) {\n\t\tStatsRequester.reqFlags |= REQFLAG_NOCURSOR;\n\t\tSetPCRequesterSize(&StatsRequester, STATS_LN_COUNT, STATS_Y_POS);\n\n\t\tStatsRequester.lineHeight = REQ_LN_HEIGHT;\n\t\tStatsRequester.itemsCount = 0;\n\t\tStatsRequester.selected = 0;\n\t\tStatsRequester.lineOffset = 0;\n\t\tStatsRequester.lineOldOffset = 0;\n\t\tStatsRequester.pixWidth = STATS_WIDTH;\n\t\tStatsRequester.xPos = 0;\n\t\tStatsRequester.zPos = 0;\n\t\tStatsRequester.lpItemStrings1 = (char *)SaveGameStrings1;\n\t\tStatsRequester.lpItemStrings2 = (char *)SaveGameStrings2;\n\t\tStatsRequester.itemStringLen = 50;\n\n\t\tInit_Requester(&StatsRequester);\n\t\tSetRequesterHeading(&StatsRequester, GF_GameStringTable[GSI_String_FinalStatistics], 0, NULL, 0);\n\n\t\t// Time taken\n\t\ttotal = 0;\n\t\tfor( i = 1; i < numLevels; ++i ) {\n\t\t\ttotal += SaveGame.start[i].statistics.timer;\n\t\t}\n\t\tseconds = total / 30 % 60;\n\t\tminutes = total / 30 / 60 % 60;\n\t\thours   = total / 30 / 60 / 60;\n\t\tsprintf(bufStr, \"%02d:%02d:%02d\", hours, minutes, seconds);\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_TimeTaken], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// Secrets found\n\t\ttotal = 0;\n\t\tmaxTotal = 0;\n\t\t// NOTE: In the original code there was hardcode for secrets: for( i = 1; i < (numLevels - 2); ++i )\n\t\tfor( i = 1; i < numLevels; ++i ) {\n\t\t\ttotal += CHK_ANY(SaveGame.start[i].statistics.secrets, 1) ? 1 : 0;\n\t\t\ttotal += CHK_ANY(SaveGame.start[i].statistics.secrets, 2) ? 1 : 0;\n\t\t\ttotal += CHK_ANY(SaveGame.start[i].statistics.secrets, 4) ? 1 : 0;\n\t\t\tmaxTotal += GF_GetNumSecrets(i); // In the original code there is 3 instead of GF_GetNumSecrets function\n\t\t}\n\t\tsprintf(bufStr, \"%d %s %d\", total, GF_GameStringTable[GSI_String_Of], maxTotal);\n#ifdef FEATURE_GOLD\n\t\t// NOTE: this check is presented in the \"Golden Mask\" only\n\t\tif( total == maxTotal ) {\n\t\t\tEnableLevelSelect();\n\t\t}\n#endif // FEATURE_GOLD\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_SecretsFound], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// Kills\n\t\ttotal = 0;\n\t\tfor( i = 1; i < numLevels; ++i ) {\n\t\t\ttotal += SaveGame.start[i].statistics.kills;\n\t\t}\n\t\tsprintf(bufStr, \"%d\", total);\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_Kills], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// Ammo used\n\t\ttotal = 0;\n\t\tfor( i = 1; i < numLevels; ++i ) {\n\t\t\ttotal += SaveGame.start[i].statistics.shots;\n\t\t}\n\t\tsprintf(bufStr, \"%d\", total);\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_AmmoUsed], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// Hits\n\t\ttotal = 0;\n\t\tfor( i = 1; i < numLevels; ++i ) {\n\t\t\ttotal += SaveGame.start[i].statistics.hits;\n\t\t}\n\t\tsprintf(bufStr, \"%d\", total);\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_Hits], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// HealthPacks used\n\t\ttotal = 0;\n\t\tfor( i = 1; i < numLevels; ++i ) {\n\t\t\ttotal += SaveGame.start[i].statistics.mediPacks;\n\t\t}\n\t\tif( (total % 2) == 0 ) {\n\t\t\tsprintf(bufStr, \"%d.0\", (total / 2));\n\t\t} else {\n\t\t\tsprintf(bufStr, \"%d.5\", (total / 2));\n\t\t}\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_HealthPacksUsed], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\t// Distance travelled\n\t\ttotal = 0;\n\t\tfor( i = 1; i < numLevels; ++i ) {\n\t\t\ttotal += SaveGame.start[i].statistics.distance;\n\t\t}\n\t\ttotal /= 445;\n\t\tif( total < 1000 )\n\t\t\tsprintf(bufStr, \"%dm\", total);\n\t\telse\n\t\t\tsprintf(bufStr, \"%d.%02dkm\", total / 1000, total % 100);\n\t\tAddRequesterItem(&StatsRequester, GF_GameStringTable[GSI_String_DistanceTravelled], REQFLAG_LEFT, bufStr, REQFLAG_RIGHT);\n\n\t\tisStatsTextReady = true;\n\t}\n\telse if( Display_Requester(&StatsRequester, FALSE, TRUE) ) {\n\t\tisStatsTextReady = false;\n\t} else {\n\t\tInputDB = 0;\n\t\tInputStatus = 0;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_InvText() {\n\tINJECT(0x00425580, Init_Requester);\n\tINJECT(0x00425610, Remove_Requester);\n\tINJECT(0x004256C0, ReqItemCentreAlign);\n\tINJECT(0x004256E0, ReqItemLeftAlign);\n\tINJECT(0x00425740, ReqItemRightAlign);\n\tINJECT(0x004257A0, Display_Requester);\n\tINJECT(0x00426010, SetRequesterHeading);\n\tINJECT(0x004260C0, RemoveAllReqItems);\n\tINJECT(0x004260E0, ChangeRequesterItem);\n\tINJECT(0x004261A0, AddRequesterItem);\n\tINJECT(0x00426250, SetPCRequesterSize);\n\tINJECT(0x00426290, AddAssaultTime);\n\tINJECT(0x00426320, ShowGymStatsText);\n\tINJECT(0x00426500, ShowStatsText);\n\tINJECT(0x004268A0, ShowEndStatsText);\n}\n"
  },
  {
    "path": "game/invtext.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef INVTEXT_H_INCLUDED\n#define INVTEXT_H_INCLUDED\n\n#include \"global/types.h\"\n\n// Requester flags\n#define REQFLAG_NOCURSOR\t(1)\n\n// Requester item flags\n#define REQFLAG_ACTIVE\t\t(1)\n#define REQFLAG_LEFT\t\t(2)\n#define REQFLAG_RIGHT\t\t(4)\n\n/*\n * Function list\n */\nvoid __cdecl Init_Requester(REQUEST_INFO *req); // 0x00425580\nvoid __cdecl Remove_Requester(REQUEST_INFO *req); // 0x00425610\nvoid __cdecl ReqItemCentreAlign(REQUEST_INFO *req, TEXT_STR_INFO *textInfo); // 0x004256C0\nvoid __cdecl ReqItemLeftAlign(REQUEST_INFO *req, TEXT_STR_INFO *textInfo); // 0x004256E0\nvoid __cdecl ReqItemRightAlign(REQUEST_INFO *req, TEXT_STR_INFO *textInfo); // 0x00425740\nint __cdecl Display_Requester(REQUEST_INFO *req, BOOL removeOnDeselect, BOOL isBackground); // 0x004257A0\nvoid __cdecl SetRequesterHeading(REQUEST_INFO *req, const char *string1, DWORD flags1, const char *string2, DWORD flags2); // 0x00426010\nvoid __cdecl RemoveAllReqItems(REQUEST_INFO *req); // 0x004260C0\nvoid __cdecl ChangeRequesterItem(REQUEST_INFO *req, DWORD itemIdx, const char *string1, DWORD flags1, const char *string2, DWORD flags2); // 0x004260E0\nvoid __cdecl AddRequesterItem(REQUEST_INFO *req, const char *string1, DWORD flags1, const char *string2, DWORD flags2); // 0x004261A0\nvoid __cdecl SetPCRequesterSize(REQUEST_INFO *req, int maxLines, __int16 yPos); // 0x00426250\nBOOL __cdecl AddAssaultTime(DWORD newTime); // 0x00426290\nvoid __cdecl ShowGymStatsText(); // 0x00426320\nvoid __cdecl ShowStatsText(char *timeString, BOOL removeOnDeselect); // 0x00426500\nvoid __cdecl ShowEndStatsText(); // 0x004268A0\n\n#endif // INVTEXT_H_INCLUDED\n"
  },
  {
    "path": "game/items.cpp",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/items.h\"\n#include \"global/vars.h\"\n\nvoid __cdecl InitialiseItemArray(int itemCount) {\n\tint i;\n\n\tNextItemFree = LevelItemCount;\n\tPrevItemActive = -1;\n\tNextItemActive = -1;\n\n\tfor( i = LevelItemCount; i+1 < itemCount; ++i ) {\n\t\tItems[i].active = 0;\n\t\tItems[i].nextItem = i+1;\n\t}\n\tItems[i].nextItem = -1;\n}\n\nvoid __cdecl InitialiseItem(__int16 itemIndex) {\n\tITEM_INFO *item;\n\tROOM_INFO *room;\n\tFLOOR_INFO *floor;\n\n\titem = &Items[itemIndex];\n\titem->animNumber = Objects[item->objectID].animIndex;\n\titem->frameNumber = Anims[item->animNumber].frameBase;\n\titem->goalAnimState = Anims[item->animNumber].currentAnimState;\n\titem->currentAnimState = item->goalAnimState;\n\titem->requiredAnimState = 0;\n\titem->pos.rotX = 0;\n\titem->pos.rotZ = 0;\n\titem->speed = 0;\n\titem->fallSpeed = 0;\n\titem->hitPoints = Objects[item->objectID].hitPoints;\n\titem->timer = 0;\n\titem->meshBits = 0xFFFFFFFF;\n\titem->touchBits = 0;\n\titem->data = NULL;\n\n\titem->active = 0;\n\titem->status = ITEM_INACTIVE;\n\titem->gravity = 0;\n\titem->hit_status = 0;\n\titem->collidable = 1;\n\titem->looked_at = 0;\n\titem->clear_body = 0;\n\n\tif( CHK_ALL(item->flags, IFL_INVISIBLE) ) {\n\t\titem->status = ITEM_INVISIBLE;\n\t\titem->flags &= ~IFL_INVISIBLE;\n\t} else if ( Objects[item->objectID].intelligent ) {\n\t\titem->status = ITEM_INVISIBLE;\n\t}\n\n\tif( CHK_ALL(item->flags, IFL_CLEARBODY) ) {\n\t\titem->clear_body = 1;\n\t\titem->flags &= ~IFL_CLEARBODY;\n\t}\n\n\tif ( CHK_ALL(item->flags, IFL_CODEBITS) ) {\n\t\titem->flags &= ~IFL_CODEBITS;\n\t\titem->flags |= IFL_REVERSE;\n\t\tAddActiveItem(itemIndex);\n\t\titem->status = ITEM_ACTIVE;\n\t}\n\n\troom = &RoomInfo[item->roomNumber];\n\titem->nextItem = room->itemNumber;\n\troom->itemNumber = itemIndex;\n\n\tfloor = &room->floor[((item->pos.z - room->z) >> WALL_SHIFT) + room->xSize * ((item->pos.x - room->x) >> WALL_SHIFT)];\n\titem->floor = floor->floor << 8;\n\n\tif ( SaveGame.bonusFlag && !IsDemoLevelType )\n\t\titem->hitPoints *= 2;\n\n\tif( Objects[item->objectID].initialise != NULL )\n\t\tObjects[item->objectID].initialise(itemIndex);\n}\n\nvoid __cdecl AddActiveItem(__int16 itemIndex) {\n\tITEM_INFO *item = &Items[itemIndex];\n\n\tif( Objects[item->objectID].control == NULL ) {\n\t\titem->status = ITEM_INACTIVE;\n\t}\n\telse if( item->active == 0 ) {\n\t\titem->active = 1;\n\t\titem->nextActive = NextItemActive;\n\t\tNextItemActive = itemIndex;\n\t}\n}\n\nint __cdecl GlobalItemReplace(int oldItemID, int newItemID) {\n\tint i, j;\n\tint result = 0;\n\n\tfor( i = 0; i < RoomCount; ++i ) {\n\t\tfor( j = RoomInfo[i].itemNumber; j != -1; j = Items[j].nextItem ) {\n\t\t\tif( Items[j].objectID == oldItemID ) {\n\t\t\t\tItems[j].objectID = newItemID;\n\t\t\t\t++result;\n\t\t\t}\n\t\t}\n\t}\n\treturn result;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Items() {\n\tINJECT(0x00426CD0, InitialiseItemArray);\n\n//\tINJECT(0x00426D30, KillItem);\n//\tINJECT(0x00426E50, CreateItem);\n\n\tINJECT(0x00426E90, InitialiseItem);\n\n//\tINJECT(0x00427050, RemoveActiveItem);\n//\tINJECT(0x004270E0, RemoveDrawnItem);\n\n\tINJECT(0x00427150, AddActiveItem);\n\n//\tINJECT(0x004271B0, ItemNewRoom);\n\n\tINJECT(0x00427250, GlobalItemReplace);\n\n//\tINJECT(0x004272D0, InitialiseFXArray);\n//\tINJECT(0x00427300, CreateEffect);\n//\tINJECT(0x00427370, KillEffect);\n//\tINJECT(0x00427460, EffectNewRoom);\n//\tINJECT(0x00427500, ClearBodyBag);\n}\n"
  },
  {
    "path": "game/items.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef ITEMS_H_INCLUDED\n#define ITEMS_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl InitialiseItemArray(int itemCount); // 0x00426CD0\n\n#define KillItem ((void(__cdecl*)(__int16)) 0x00426D30)\n#define CreateItem ((__int16(__cdecl*)(void)) 0x00426E50)\n\nvoid __cdecl InitialiseItem(__int16 itemIndex); // 0x00426E90\n\n#define RemoveActiveItem ((void(__cdecl*)(__int16)) 0x00427050)\n#define RemoveDrawnItem ((void(__cdecl*)(__int16)) 0x004270E0)\n\nvoid __cdecl AddActiveItem(__int16 itemIndex); // 0x00427150\n\n#define ItemNewRoom ((void(__cdecl*)(__int16, __int16)) 0x004271B0)\n\nint __cdecl GlobalItemReplace(int oldItemID, int newItemID); // 0x00427250\n\n#define InitialiseFXArray ((void(__cdecl*)(void)) 0x004272D0)\n#define CreateEffect ((__int16(__cdecl*)(__int16)) 0x00427300)\n#define KillEffect ((void(__cdecl*)(__int16)) 0x00427370)\n#define EffectNewRoom ((void(__cdecl*)(__int16, __int16)) 0x00427460)\n#define ClearBodyBag ((void(__cdecl*)(void)) 0x00427500)\n\n#endif // ITEMS_H_INCLUDED\n"
  },
  {
    "path": "game/lara.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/lara.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_GAMEPLAY_FIXES\nbool IsLowCeilingJumpFix = true;\n#endif // FEATURE_GAMEPLAY_FIXES\n\nvoid __cdecl lara_col_jumper(ITEM_INFO *item, COLL_INFO *coll) {\n\tcoll->badPos = 0x7F00;\n\tcoll->badNeg = -0x0180;\n\tcoll->badCeiling = 0x00C0;\n\n\tGetLaraCollisionInfo(item, coll);\n\tLaraDeflectEdgeJump(item, coll);\n\n\tif( item->fallSpeed > 0 && coll->sideMid.floor <= 0 ) {\n\t\titem->goalAnimState = LaraLandedBad(item, coll) ? AS_DEATH : AS_STOP;\n\t\titem->fallSpeed = 0;\n\t\titem->gravity = 0;\n\t\titem->pos.y += coll->sideMid.floor;\n\t}\n\n\t// NOTE: Low ceiling check must be skipped because it produces the bug\n\t// Core Design removed this check in later game releases\n#ifdef FEATURE_GAMEPLAY_FIXES\n\tif( IsLowCeilingJumpFix ) return;\n#endif // FEATURE_GAMEPLAY_FIXES\n\tif( ABS(coll->sideMid.ceiling - coll->sideMid.floor) < 0x02FA ) {\n\t\titem->currentAnimState = AS_FASTFALL;\n\t\titem->goalAnimState = AS_FASTFALL;\n\t\titem->animNumber = 32;\n\t\titem->frameNumber = Anims[item->animNumber].frameBase + 1;\n\t\titem->speed /= 4;\n\t\tLara.move_angle += PHD_180;\n\t\tif( item->fallSpeed <= 0 )\n\t\t\titem->fallSpeed = 1;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Lara() {\n//\tINJECT(0x00427560, LaraAboveWater);\n//\tINJECT(0x00427700, LookUpDown);\n//\tINJECT(0x00427770, LookLeftRight);\n//\tINJECT(0x004277F0, ResetLook);\n//\tINJECT(0x00427880, lara_as_walk);\n//\tINJECT(0x00427910, lara_as_run);\n//\tINJECT(0x00427A60, lara_as_stop);\n//\tINJECT(0x00427BB0, lara_as_forwardjump);\n//\tINJECT(----------, lara_as_pose);\n//\tINJECT(0x00427C90, lara_as_fastback);\n//\tINJECT(0x00427CF0, lara_as_turn_r);\n//\tINJECT(0x00427D80, lara_as_turn_l);\n//\tINJECT(0x00427E10, lara_as_death);\n//\tINJECT(0x00427E30, lara_as_fastfall);\n//\tINJECT(0x00427E70, lara_as_hang);\n//\tINJECT(0x00427ED0, lara_as_reach);\n//\tINJECT(0x00427EF0, lara_as_splat);\n//\tINJECT(----------, lara_as_land);\n//\tINJECT(0x00427F00, lara_as_compress);\n//\tINJECT(0x00428010, lara_as_back);\n//\tINJECT(0x004280A0, lara_as_null);\n//\tINJECT(0x004280B0, lara_as_fastturn);\n//\tINJECT(0x00428100, lara_as_stepright);\n//\tINJECT(0x00428180, lara_as_stepleft);\n//\tINJECT(0x00428200, lara_as_slide);\n//\tINJECT(0x00428230, lara_as_backjump);\n//\tINJECT(0x00428280, lara_as_rightjump);\n//\tINJECT(0x004282C0, lara_as_leftjump);\n//\tINJECT(0x00428300, lara_as_upjump);\n//\tINJECT(0x00428320, lara_as_fallback);\n//\tINJECT(0x00428350, lara_as_hangleft);\n//\tINJECT(0x00428390, lara_as_hangright);\n//\tINJECT(0x004283D0, lara_as_slideback);\n//\tINJECT(0x004283F0, lara_as_pushblock);\n//\tINJECT(----------, lara_as_pullblock);\n//\tINJECT(0x00428420, lara_as_ppready);\n//\tINJECT(0x00428450, lara_as_pickup);\n//\tINJECT(0x00428480, lara_as_pickupflare);\n//\tINJECT(0x004284E0, lara_as_switchon);\n//\tINJECT(----------, lara_as_switchoff);\n//\tINJECT(0x00428520, lara_as_usekey);\n//\tINJECT(----------, lara_as_usepuzzle);\n//\tINJECT(----------, lara_as_roll);\n//\tINJECT(----------, lara_as_roll2);\n//\tINJECT(0x00428550, lara_as_special);\n//\tINJECT(----------, lara_as_usemidas);\n//\tINJECT(----------, lara_as_diemidas);\n//\tINJECT(0x00428570, lara_as_swandive);\n//\tINJECT(0x004285A0, lara_as_fastdive);\n//\tINJECT(----------, lara_as_gymnast);\n//\tINJECT(0x00428600, lara_as_waterout);\n//\tINJECT(----------, lara_as_laratest1);\n//\tINJECT(----------, lara_as_laratest2);\n//\tINJECT(----------, lara_as_laratest3);\n//\tINJECT(0x00428620, lara_as_wade);\n//\tINJECT(----------, lara_as_twist);\n//\tINJECT(----------, lara_as_kick);\n//\tINJECT(0x004286F0, lara_as_deathslide);\n//\tINJECT(0x00428790, extra_as_breath);\n//\tINJECT(----------, extra_as_plunger);\n//\tINJECT(0x004287E0, extra_as_yetikill);\n//\tINJECT(0x00428830, extra_as_sharkkill);\n//\tINJECT(0x004288D0, extra_as_airlock);\n//\tINJECT(0x004288F0, extra_as_gongbong);\n//\tINJECT(0x00428910, extra_as_dinokill);\n//\tINJECT(0x00428970, extra_as_pulldagger);\n//\tINJECT(0x00428A30, extra_as_startanim);\n//\tINJECT(0x00428A80, extra_as_starthouse);\n//\tINJECT(0x00428B30, extra_as_finalanim);\n//\tINJECT(0x00428BE0, LaraFallen);\n//\tINJECT(0x00428C40, LaraCollideStop);\n//\tINJECT(0x00428D00, lara_col_walk);\n//\tINJECT(0x00428EA0, lara_col_run);\n//\tINJECT(0x00429020, lara_col_stop);\n//\tINJECT(0x004290B0, lara_col_forwardjump);\n//\tINJECT(----------, lara_col_pose);\n//\tINJECT(0x00429190, lara_col_fastback);\n//\tINJECT(0x00429250, lara_col_turn_r);\n//\tINJECT(0x004292F0, lara_col_turn_l);\n//\tINJECT(0x00429310, lara_col_death);\n//\tINJECT(0x00429380, lara_col_fastfall);\n//\tINJECT(0x00429420, lara_col_hang);\n//\tINJECT(0x00429550, lara_col_reach);\n//\tINJECT(0x004295E0, lara_col_splat);\n//\tINJECT(----------, lara_col_land);\n//\tINJECT(0x00429640, lara_col_compress);\n//\tINJECT(0x004296E0, lara_col_back);\n//\tINJECT(----------, lara_col_null);\n//\tINJECT(0x004297E0, lara_col_fastturn);\n//\tINJECT(0x00429800, lara_col_stepright);\n//\tINJECT(0x004298C0, lara_col_stepleft);\n//\tINJECT(0x004298E0, lara_col_slide);\n//\tINJECT(0x00429900, lara_col_backjump);\n//\tINJECT(0x00429930, lara_col_rightjump);\n//\tINJECT(0x00429960, lara_col_leftjump);\n//\tINJECT(0x00429990, lara_col_upjump);\n//\tINJECT(0x00429AD0, lara_col_fallback);\n//\tINJECT(0x00429B60, lara_col_hangleft);\n//\tINJECT(0x00429BA0, lara_col_hangright);\n//\tINJECT(0x00429BE0, lara_col_slideback);\n//\tINJECT(----------, lara_col_pushblock);\n//\tINJECT(----------, lara_col_pullblock);\n//\tINJECT(----------, lara_col_ppready);\n//\tINJECT(----------, lara_col_pickup);\n//\tINJECT(----------, lara_col_switchon);\n//\tINJECT(----------, lara_col_switchoff);\n//\tINJECT(----------, lara_col_usekey);\n//\tINJECT(----------, lara_col_usepuzzle);\n//\tINJECT(0x00429C10, lara_col_roll);\n//\tINJECT(0x00429CB0, lara_col_roll2);\n//\tINJECT(0x00429D80, lara_col_special);\n//\tINJECT(----------, lara_col_usemidas);\n//\tINJECT(----------, lara_col_diemidas);\n//\tINJECT(0x00429DA0, lara_col_swandive);\n//\tINJECT(0x00429E10, lara_col_fastdive);\n//\tINJECT(----------, lara_col_gymnast);\n//\tINJECT(----------, lara_col_waterout);\n//\tINJECT(----------, lara_col_laratest1);\n//\tINJECT(----------, lara_col_laratest2);\n//\tINJECT(----------, lara_col_laratest3);\n//\tINJECT(0x00429E90, lara_col_wade);\n//\tINJECT(----------, lara_col_twist);\n//\tINJECT(0x0042A000, lara_default_col);\n\n\tINJECT(0x0042A040, lara_col_jumper);\n\n//\tINJECT(0x0042A120, lara_col_kick);\n//\tINJECT(----------, lara_col_deathslide);\n//\tINJECT(0x0042A130, GetLaraCollisionInfo);\n//\tINJECT(0x0042A170, lara_slide_slope);\n//\tINJECT(0x0042A260, LaraHitCeiling);\n//\tINJECT(0x0042A2D0, LaraDeflectEdge);\n//\tINJECT(0x0042A350, LaraDeflectEdgeJump);\n//\tINJECT(0x0042A4D0, LaraSlideEdgeJump);\n//\tINJECT(0x0042A5C0, TestWall);\n//\tINJECT(0x0042A6D0, LaraTestHangOnClimbWall);\n//\tINJECT(0x0042A7E0, LaraTestClimbStance);\n//\tINJECT(0x0042A8A0, LaraHangTest);\n//\tINJECT(0x0042AC00, LaraTestEdgeCatch);\n//\tINJECT(0x0042ACB0, LaraTestHangJumpUp);\n//\tINJECT(0x0042AE20, LaraTestHangJump);\n//\tINJECT(0x0042AFC0, TestHangSwingIn);\n//\tINJECT(0x0042B080, TestLaraVault);\n//\tINJECT(0x0042B370, TestLaraSlide);\n//\tINJECT(0x0042B4A0, LaraFloorFront);\n//\tINJECT(0x0042B520, LaraLandedBad);\n//\tINJECT(0x0042B5E0, GetLaraJointAbsPosition);\n//\tINJECT(0x0042B970, GetLJAInt);\n}\n"
  },
  {
    "path": "game/lara.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARA_H_INCLUDED\n#define LARA_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define LaraAboveWater ((void(__cdecl*)(ITEM_INFO*, COLL_INFO*)) 0x00427560)\n\n// 0x00427700:\t\tLookUpDown\n// 0x00427770:\t\tLookLeftRight\n// 0x004277F0:\t\tResetLook\n// 0x00427880:\t\tlara_as_walk\n// 0x00427910:\t\tlara_as_run\n// 0x00427A60:\t\tlara_as_stop\n// 0x00427BB0:\t\tlara_as_forwardjump\n// ----------:\t\tlara_as_pose\n// 0x00427C90:\t\tlara_as_fastback\n// 0x00427CF0:\t\tlara_as_turn_r\n// 0x00427D80:\t\tlara_as_turn_l\n// 0x00427E10:\t\tlara_as_death\n// 0x00427E30:\t\tlara_as_fastfall\n// 0x00427E70:\t\tlara_as_hang\n// 0x00427ED0:\t\tlara_as_reach\n// 0x00427EF0:\t\tlara_as_splat\n// ----------:\t\tlara_as_land\n// 0x00427F00:\t\tlara_as_compress\n// 0x00428010:\t\tlara_as_back\n// 0x004280A0:\t\tlara_as_null\n// 0x004280B0:\t\tlara_as_fastturn\n// 0x00428100:\t\tlara_as_stepright\n// 0x00428180:\t\tlara_as_stepleft\n// 0x00428200:\t\tlara_as_slide\n// 0x00428230:\t\tlara_as_backjump\n// 0x00428280:\t\tlara_as_rightjump\n// 0x004282C0:\t\tlara_as_leftjump\n// 0x00428300:\t\tlara_as_upjump\n// 0x00428320:\t\tlara_as_fallback\n// 0x00428350:\t\tlara_as_hangleft\n// 0x00428390:\t\tlara_as_hangright\n// 0x004283D0:\t\tlara_as_slideback\n// 0x004283F0:\t\tlara_as_pushblock\n// ----------:\t\tlara_as_pullblock\n// 0x00428420:\t\tlara_as_ppready\n// 0x00428450:\t\tlara_as_pickup\n// 0x00428480:\t\tlara_as_pickupflare\n// 0x004284E0:\t\tlara_as_switchon\n// ----------:\t\tlara_as_switchoff\n// 0x00428520:\t\tlara_as_usekey\n// ----------:\t\tlara_as_usepuzzle\n// ----------:\t\tlara_as_roll\n// ----------:\t\tlara_as_roll2\n// 0x00428550:\t\tlara_as_special\n// ----------:\t\tlara_as_usemidas\n// ----------:\t\tlara_as_diemidas\n// 0x00428570:\t\tlara_as_swandive\n// 0x004285A0:\t\tlara_as_fastdive\n// ----------:\t\tlara_as_gymnast\n// 0x00428600:\t\tlara_as_waterout\n// ----------:\t\tlara_as_laratest1\n// ----------:\t\tlara_as_laratest2\n// ----------:\t\tlara_as_laratest3\n// 0x00428620:\t\tlara_as_wade\n// ----------:\t\tlara_as_twist\n// ----------:\t\tlara_as_kick\n// 0x004286F0:\t\tlara_as_deathslide\n// 0x00428790:\t\textra_as_breath\n// ----------:\t\textra_as_plunger\n// 0x004287E0:\t\textra_as_yetikill\n// 0x00428830:\t\textra_as_sharkkill\n// 0x004288D0:\t\textra_as_airlock\n// 0x004288F0:\t\textra_as_gongbong\n// 0x00428910:\t\textra_as_dinokill\n// 0x00428970:\t\textra_as_pulldagger\n// 0x00428A30:\t\textra_as_startanim\n// 0x00428A80:\t\textra_as_starthouse\n// 0x00428B30:\t\textra_as_finalanim\n// 0x00428BE0:\t\tLaraFallen\n// 0x00428C40:\t\tLaraCollideStop\n// 0x00428D00:\t\tlara_col_walk\n// 0x00428EA0:\t\tlara_col_run\n// 0x00429020:\t\tlara_col_stop\n// 0x004290B0:\t\tlara_col_forwardjump\n// ----------:\t\tlara_col_pose\n// 0x00429190:\t\tlara_col_fastback\n// 0x00429250:\t\tlara_col_turn_r\n// 0x004292F0:\t\tlara_col_turn_l\n// 0x00429310:\t\tlara_col_death\n// 0x00429380:\t\tlara_col_fastfall\n// 0x00429420:\t\tlara_col_hang\n// 0x00429550:\t\tlara_col_reach\n// 0x004295E0:\t\tlara_col_splat\n// ----------:\t\tlara_col_land\n// 0x00429640:\t\tlara_col_compress\n// 0x004296E0:\t\tlara_col_back\n// ----------:\t\tlara_col_null\n// 0x004297E0:\t\tlara_col_fastturn\n// 0x00429800:\t\tlara_col_stepright\n// 0x004298C0:\t\tlara_col_stepleft\n// 0x004298E0:\t\tlara_col_slide\n// 0x00429900:\t\tlara_col_backjump\n// 0x00429930:\t\tlara_col_rightjump\n// 0x00429960:\t\tlara_col_leftjump\n// 0x00429990:\t\tlara_col_upjump\n// 0x00429AD0:\t\tlara_col_fallback\n// 0x00429B60:\t\tlara_col_hangleft\n// 0x00429BA0:\t\tlara_col_hangright\n// 0x00429BE0:\t\tlara_col_slideback\n// ----------:\t\tlara_col_pushblock\n// ----------:\t\tlara_col_pullblock\n// ----------:\t\tlara_col_ppready\n// ----------:\t\tlara_col_pickup\n// ----------:\t\tlara_col_switchon\n// ----------:\t\tlara_col_switchoff\n// ----------:\t\tlara_col_usekey\n// ----------:\t\tlara_col_usepuzzle\n// 0x00429C10:\t\tlara_col_roll\n// 0x00429CB0:\t\tlara_col_roll2\n// 0x00429D80:\t\tlara_col_special\n// ----------:\t\tlara_col_usemidas\n// ----------:\t\tlara_col_diemidas\n// 0x00429DA0:\t\tlara_col_swandive\n// 0x00429E10:\t\tlara_col_fastdive\n// ----------:\t\tlara_col_gymnast\n// ----------:\t\tlara_col_waterout\n// ----------:\t\tlara_col_laratest1\n// ----------:\t\tlara_col_laratest2\n// ----------:\t\tlara_col_laratest3\n// 0x00429E90:\t\tlara_col_wade\n// ----------:\t\tlara_col_twist\n// 0x0042A000:\t\tlara_default_col\n\nvoid __cdecl lara_col_jumper(ITEM_INFO *item, COLL_INFO *coll); // 0x0042A040\n\n// 0x0042A120:\t\tlara_col_kick\n// ----------:\t\tlara_col_deathslide\n\n#define GetLaraCollisionInfo ((void (__cdecl*)(ITEM_INFO *item, COLL_INFO *coll)) 0x0042A130)\n\n// 0x0042A170:\t\tlara_slide_slope\n// 0x0042A260:\t\tLaraHitCeiling\n// 0x0042A2D0:\t\tLaraDeflectEdge\n\n#define LaraDeflectEdgeJump ((void (__cdecl*)(ITEM_INFO *item, COLL_INFO *coll)) 0x0042A350)\n\n// 0x0042A4D0:\t\tLaraSlideEdgeJump\n// 0x0042A5C0:\t\tTestWall\n// 0x0042A6D0:\t\tLaraTestHangOnClimbWall\n// 0x0042A7E0:\t\tLaraTestClimbStance\n// 0x0042A8A0:\t\tLaraHangTest\n// 0x0042AC00:\t\tLaraTestEdgeCatch\n// 0x0042ACB0:\t\tLaraTestHangJumpUp\n// 0x0042AE20:\t\tLaraTestHangJump\n// 0x0042AFC0:\t\tTestHangSwingIn\n// 0x0042B080:\t\tTestLaraVault\n// 0x0042B370:\t\tTestLaraSlide\n// 0x0042B4A0:\t\tLaraFloorFront\n\n#define LaraLandedBad ((bool (__cdecl*)(ITEM_INFO *item, COLL_INFO *coll)) 0x0042B520)\n#define GetLaraJointAbsPosition ((void(__cdecl*)(PHD_VECTOR*,int)) 0x0042B5E0)\n\n// 0x0042B970:\t\tGetLJAInt\n\n#endif // LARA_H_INCLUDED\n"
  },
  {
    "path": "game/lara1gun.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Copyright (c) 2020 ChocolateFan <asasas9500@gmail.com>\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/lara1gun.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/box.h\"\n#include \"game/control.h\"\n#include \"game/draw.h\"\n#include \"game/items.h\"\n#include \"game/lara.h\"\n#include \"game/larafire.h\"\n#include \"game/objects.h\"\n#include \"game/sound.h\"\n#include \"specific/game.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\n#ifdef FEATURE_GAMEPLAY_FIXES\nbool IsRunningM16fix = true;\n#endif // FEATURE_GAMEPLAY_FIXES\n\nvoid __cdecl RifleHandler(int weaponType) {\n\tWEAPON_INFO *weapon = &Weapons[weaponType];\n\n\tif( CHK_ANY(InputStatus, IN_ACTION) )\n\t\tLaraTargetInfo(&Weapons[weaponType]);\n\telse {\n\t\tLara.target = 0;\n\t}\n\n\tif( !Lara.target ) {\n\t\tLaraGetNewTarget(weapon);\n\t}\n\n\tAimWeapon(weapon, &Lara.left_arm);\n\n\tif( Lara.left_arm.lock ) {\n\t\tLara.torso_x_rot = Lara.left_arm.x_rot;\n\t\tLara.torso_y_rot = Lara.left_arm.y_rot;\n\t\tLara.head_x_rot = Lara.head_y_rot = 0;\n\t}\n\n\tAnimateShotgun(weaponType);\n\n\tif( Lara.right_arm.flash_gun && (weaponType == LGT_Shotgun || weaponType == LGT_M16) ) {\n\t\tint x = LaraItem->pos.x + (phd_sin(LaraItem->pos.rotY) >> (W2V_SHIFT-10));\n\t\tint y = LaraItem->pos.y - 0x200;\n\t\tint z = LaraItem->pos.z + (phd_cos(LaraItem->pos.rotY) >> (W2V_SHIFT-10));\n\t\tAddDynamicLight(x, y, z, 12, 11);\n\t}\n}\n\nvoid __cdecl FireShotgun() {\n\t__int16 base[2], angles[2];\n\tBOOL isFired = FALSE;\n\tbase[0] = Lara.left_arm.y_rot + LaraItem->pos.rotY;\n\tbase[1] = Lara.left_arm.x_rot;\n\n\tfor( int i=0; i<6; ++i ) {\n\t\tangles[0] = base[0] + 20*PHD_DEGREE * (GetRandomControl() - PHD_ONE/4) / PHD_ONE;\n\t\tangles[1] = base[1] + 20*PHD_DEGREE * (GetRandomControl() - PHD_ONE/4) / PHD_ONE;\n\t\tif( FireWeapon(LGT_Shotgun, Lara.target, LaraItem, angles) ) {\n\t\t\tisFired = TRUE;\n\t\t}\n\t}\n\n\tif( isFired ) {\n\t\tLara.right_arm.flash_gun = Weapons[LGT_Shotgun].flashTime;\n\t\tPlaySoundEffect(Weapons[LGT_Shotgun].sampleNum, &LaraItem->pos, 0);\n#ifdef FEATURE_INPUT_IMPROVED\n\t\tJoyVibrate(0x2000, 0x2000, 2, 0x800, 5, false);\n#endif // FEATURE_INPUT_IMPROVED\n\t}\n}\n\nvoid __cdecl FireM16(BOOL isRunning) {\n\t__int16 angles[2];\n\n\tangles[0] = Lara.left_arm.y_rot + LaraItem->pos.rotY;\n\tangles[1] = Lara.left_arm.x_rot;\n\n\t// NOTE: Ther was a bug in the original game - ID_LARA_M16 instead of LGT_M16\n#ifdef FEATURE_GAMEPLAY_FIXES\n\tif( IsRunningM16fix && isRunning ) {\n\t\tWeapons[LGT_M16].shotAccuracy = 12*PHD_DEGREE;\n\t\tWeapons[LGT_M16].damage = 1;\n\t} else {\n\t\tWeapons[LGT_M16].shotAccuracy = 4*PHD_DEGREE;\n\t\tWeapons[LGT_M16].damage = 3;\n\t}\n#endif // FEATURE_GAMEPLAY_FIXES\n\n\tif( FireWeapon(LGT_M16, Lara.target, LaraItem, angles) ) {\n\t\tLara.right_arm.flash_gun = Weapons[LGT_M16].flashTime;\n#ifdef FEATURE_INPUT_IMPROVED\n\t\tJoyVibrate(0x400, 0x400, 2, 0x80, 4, false);\n#endif // FEATURE_INPUT_IMPROVED\n\t}\n}\n\nvoid __cdecl FireHarpoon() {\n\tGAME_VECTOR pos;\n\tif( Lara.harpoon_ammo <= 0 ) return;\n\t__int16 itemID = CreateItem();\n\tif( itemID < 0 ) return;\n\n\tITEM_INFO *item = &Items[itemID];\n\titem->objectID = ID_HARPOON_BOLT;\n\titem->roomNumber = LaraItem->roomNumber;\n\tpos.x = -2;\n\tpos.y = 373;\n\tpos.z = 77;\n\tGetLaraJointAbsPosition((PHD_VECTOR *)&pos, 10);\n\titem->pos.x = pos.x;\n\titem->pos.y = pos.y;\n\titem->pos.z = pos.z;\n\tInitialiseItem(itemID);\n\tif( Lara.target ) {\n\t\tfind_target_point(Lara.target, &pos);\n\t\titem->pos.rotY = phd_atan(pos.z - item->pos.z, pos.x - item->pos.x);\n\t\tint distance = phd_sqrt(SQR(pos.x - item->pos.x) + SQR(pos.z - item->pos.z));\n\t\titem->pos.rotX = -phd_atan(distance, pos.y - item->pos.y);\n\t} else {\n\t\titem->pos.rotX = Lara.left_arm.x_rot + LaraItem->pos.rotX;\n\t\titem->pos.rotY = Lara.left_arm.y_rot + LaraItem->pos.rotY;\n\t}\n\titem->pos.rotZ = 0;\n\titem->fallSpeed = -150 * phd_sin(item->pos.rotX) >> W2V_SHIFT;\n\titem->speed = 150 * phd_cos(item->pos.rotX) >> W2V_SHIFT;\n\tAddActiveItem(itemID);\n\tif( !SaveGame.bonusFlag ) {\n\t\t--Lara.harpoon_ammo;\n\t}\n\t++SaveGame.statistics.shots;\n#ifdef FEATURE_INPUT_IMPROVED\n\tJoyVibrate(0xC00, 0xC00, 2, 0x400, 4, false);\n#endif // FEATURE_INPUT_IMPROVED\n}\n\nvoid __cdecl FireRocket() {\n\t__int16 itemID;\n\tITEM_INFO *item;\n\tPHD_VECTOR pos;\n\n\tif (Lara.grenade_ammo > 0) {\n\t\titemID = CreateItem();\n\t\tif (itemID != -1) {\n\t\t\titem = &Items[itemID];\n\t\t\titem->objectID = ID_ROCKET;\n\t\t\titem->roomNumber = LaraItem->roomNumber;\n\t\t\tpos.x = -2;\n\t\t\tpos.y = 373;\n\t\t\tpos.z = 77;\n\t\t\tGetLaraJointAbsPosition(&pos, 10);\n\t\t\titem->pos.x = pos.x;\n\t\t\titem->pos.y = pos.y;\n\t\t\titem->pos.z = pos.z;\n\t\t\tInitialiseItem(itemID);\n\t\t\titem->pos.rotX = LaraItem->pos.rotX + Lara.left_arm.x_rot;\n\t\t\titem->pos.rotZ = 0;\n\t\t\titem->speed = 200;\n\t\t\titem->fallSpeed = 0;\n\t\t\titem->pos.rotY = LaraItem->pos.rotY + Lara.left_arm.y_rot;\n\t\t\tAddActiveItem(itemID);\n\t\t\tif (!SaveGame.bonusFlag)\n\t\t\t\t--Lara.grenade_ammo;\n\t\t\t++SaveGame.statistics.shots;\n#ifdef FEATURE_INPUT_IMPROVED\n\t\t\tJoyVibrate(0x1000, 0x1000, 2, 0x400, 4, false);\n#endif // FEATURE_INPUT_IMPROVED\n\t\t}\n\t}\n}\n\nvoid __cdecl ControlRocket(__int16 itemID) {\n\tITEM_INFO *item, *link;\n\tint oldX, oldY, oldZ, displacement, c, s, r, oldR;\n\t__int16 room, linkID, *frame, fxID;\n\tFLOOR_INFO *floor;\n\tBOOL collision;\n\tFX_INFO *fx;\n\n\titem = &Items[itemID];\n\toldX = item->pos.x;\n\toldY = item->pos.y;\n\toldZ = item->pos.z;\n\tif (item->speed < 190)\n\t\t++item->fallSpeed;\n\t--item->speed;\n\titem->pos.y += item->fallSpeed - (item->speed * phd_sin(item->pos.rotX) >> W2V_SHIFT);\n\titem->pos.z += phd_cos(item->pos.rotY) * (item->speed * phd_cos(item->pos.rotX) >> W2V_SHIFT) >> W2V_SHIFT;\n\titem->pos.x += phd_sin(item->pos.rotY) * (item->speed * phd_cos(item->pos.rotX) >> W2V_SHIFT) >> W2V_SHIFT;\n\troom = item->roomNumber;\n\tfloor = GetFloor(item->pos.x, item->pos.y, item->pos.z, &room);\n\titem->floor = GetHeight(floor, item->pos.x, item->pos.y, item->pos.z);\n\tif (item->roomNumber != room)\n\t\tItemNewRoom(itemID, room);\n\tif (item->pos.y < item->floor && item->pos.y > GetCeiling(floor, item->pos.x, item->pos.y, item->pos.z)) {\n\t\tcollision = FALSE;\n\t\tdisplacement = 0;\n\t} else {\n\t\tdisplacement = 512;\n\t\tcollision = TRUE;\n\t}\n\tfor (linkID = RoomInfo[item->roomNumber].itemNumber; linkID != -1; linkID = link->nextItem) {\n\t\tlink = &Items[linkID];\n\t\tif (link != LaraItem &&\n\t\t\tlink->collidable &&\n\t\t\t(link->objectID == ID_WINDOW1 ||\n\t\t\t(Objects[link->objectID].intelligent &&\n\t\t\tlink->status != ITEM_INVISIBLE &&\n\t\t\tObjects[link->objectID].collision)))\n\t\t{\n\t\t\tframe = GetBestFrame(link);\n\t\t\tif (item->pos.y + displacement >= link->pos.y + frame[2] && item->pos.y - displacement <= link->pos.y + frame[3]) {\n\t\t\t\tc = phd_cos(link->pos.rotY);\n\t\t\t\ts = phd_sin(link->pos.rotY);\n\t\t\t\tr = (c * (item->pos.x - link->pos.x) - s * (item->pos.z - link->pos.z)) >> W2V_SHIFT;\n\t\t\t\toldR = (c * (oldX - link->pos.x) - s * (oldZ - link->pos.z)) >> W2V_SHIFT;\n\t\t\t\tif ((r + displacement >= frame[0] ||\n\t\t\t\t\toldR + displacement >= frame[0]) &&\n\t\t\t\t\t(r - displacement <= frame[1] ||\n\t\t\t\t\toldR - displacement <= frame[1]))\n\t\t\t\t{\n\t\t\t\t\tr = (s * (item->pos.x - link->pos.x) + c * (item->pos.z - link->pos.z)) >> W2V_SHIFT;\n\t\t\t\t\toldR = (s * (oldX - link->pos.x) + c * (oldZ - link->pos.z)) >> W2V_SHIFT;\n\t\t\t\t\tif ((r + displacement >= frame[4] ||\n\t\t\t\t\t\toldR + displacement >= frame[4]) &&\n\t\t\t\t\t\t(r - displacement <= frame[5] ||\n\t\t\t\t\t\toldR - displacement <= frame[5]))\n\t\t\t\t\t{\n\t\t\t\t\t\tif (link->objectID == ID_WINDOW1) {\n\t\t\t\t\t\t\tSmashWindow(linkID);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (link->status == ITEM_ACTIVE) {\n\t\t\t\t\t\t\t\tHitTarget(link, NULL, 30);\n\t\t\t\t\t\t\t\t++SaveGame.statistics.hits;\n\t\t\t\t\t\t\t\tif (link->hitPoints <= 0) {\n\t\t\t\t\t\t\t\t\t++SaveGame.statistics.kills;\n\t\t\t\t\t\t\t\t\tif (link->objectID != ID_DRAGON_FRONT && link->objectID != ID_GIANT_YETI)\n\t\t\t\t\t\t\t\t\t\tCreatureDie(linkID, TRUE);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcollision = TRUE;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (collision) {\n\t\tfxID = CreateEffect(item->roomNumber);\n\t\tif (fxID != -1) {\n\t\t\tfx = &Effects[fxID];\n\t\t\tfx->pos.x = oldX;\n\t\t\tfx->pos.y = oldY;\n\t\t\tfx->pos.z = oldZ;\n\t\t\tfx->speed = 0;\n\t\t\tfx->frame_number = 0;\n\t\t\tfx->counter = 0;\n\t\t\tfx->object_number = ID_EXPLOSION;\n\t\t}\n\t\tPlaySoundEffect(105, NULL, 0);\n\t\tKillItem(itemID);\n#ifdef FEATURE_INPUT_IMPROVED\n\t\tJoyRumbleExplode(oldX, oldY, oldZ, 0x1400, true);\n#endif // FEATURE_INPUT_IMPROVED\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Lara1Gun() {\n//\tINJECT(0x0042BC90, draw_shotgun_meshes);\n//\tINJECT(0x0042BCD0, undraw_shotgun_meshes);\n//\tINJECT(0x0042BD00, ready_shotgun);\n\n\tINJECT(0x0042BD70, RifleHandler);\n\tINJECT(0x0042BE70, FireShotgun);\n\tINJECT(0x0042BF70, FireM16);\n\tINJECT(0x0042BFF0, FireHarpoon);\n\n//\tINJECT(0x0042C180, ControlHarpoonBolt);\n\n\tINJECT(0x0042C4D0, FireRocket);\n\tINJECT(0x0042C5C0, ControlRocket);\n\n//\tINJECT(0x0042C9D0, draw_shotgun);\n//\tINJECT(0x0042CB40, undraw_shotgun);\n//\tINJECT(0x0042CC50, AnimateShotgun);\n}\n"
  },
  {
    "path": "game/lara1gun.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARA1GUN_H_INCLUDED\n#define LARA1GUN_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x0042BC90:\t\tdraw_shotgun_meshes\n//\t0x0042BCD0:\t\tundraw_shotgun_meshes\n//\t0x0042BD00:\t\tready_shotgun\n\nvoid __cdecl RifleHandler(int weaponType); // 0x0042BD70\nvoid __cdecl FireShotgun(); // 0x0042BE70\nvoid __cdecl FireM16(BOOL isRunning); // 0x0042BF70\nvoid __cdecl FireHarpoon(); // 0x0042BFF0\n\n//\t0x0042C180:\t\tControlHarpoonBolt\n\nvoid __cdecl FireRocket(); // 0x0042C4D0\nvoid __cdecl ControlRocket(__int16 itemID); // 0x0042C5C0\n\n//\t0x0042C9D0:\t\tdraw_shotgun\n//\t0x0042CB40:\t\tundraw_shotgun\n\n#define AnimateShotgun ((void(__cdecl*)(int)) 0x0042CC50)\n\n#endif // LARA1GUN_H_INCLUDED\n"
  },
  {
    "path": "game/lara2gun.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/lara2gun.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/draw.h\"\n#include \"game/larafire.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\nvoid __cdecl PistolHandler(int weaponType) {\n\tWEAPON_INFO *weapon = &Weapons[weaponType];\n\n\tif( CHK_ANY(InputStatus, IN_ACTION) ) {\n\t\tLaraTargetInfo(weapon);\n\t} else {\n\t\tLara.target = 0;\n\t}\n\n\tif( !Lara.target ) {\n\t\tLaraGetNewTarget(weapon);\n\t}\n\n\tAimWeapon(weapon, &Lara.left_arm);\n\tAimWeapon(weapon, &Lara.right_arm);\n\n\tif( Lara.left_arm.lock && !Lara.right_arm.lock ) {\n\t\tLara.head_y_rot = Lara.torso_y_rot = Lara.left_arm.y_rot / 2;\n\t\tLara.head_x_rot = Lara.torso_x_rot = Lara.left_arm.x_rot / 2;\n\t} else if( !Lara.left_arm.lock && Lara.right_arm.lock ) {\n\t\tLara.head_y_rot = Lara.torso_y_rot = Lara.right_arm.y_rot / 2;\n\t\tLara.head_x_rot = Lara.torso_x_rot = Lara.right_arm.x_rot / 2;\n\t} else if ( Lara.left_arm.lock && Lara.right_arm.lock ) {\n\t\tLara.head_y_rot = Lara.torso_y_rot = (Lara.right_arm.y_rot + Lara.left_arm.y_rot) / 4;\n\t\tLara.head_x_rot = Lara.torso_x_rot = (Lara.right_arm.x_rot + Lara.left_arm.x_rot) / 4;\n\t}\n\n\tAnimatePistols(weaponType);\n\n\tif( Lara.left_arm.flash_gun || Lara.right_arm.flash_gun ) {\n\t\tint x = LaraItem->pos.x + (phd_sin(LaraItem->pos.rotY) >> (W2V_SHIFT-10));\n\t\tint y = LaraItem->pos.y - 0x200;\n\t\tint z = LaraItem->pos.z + (phd_cos(LaraItem->pos.rotY) >> (W2V_SHIFT-10));\n\t\tAddDynamicLight(x, y, z, 12, 11);\n#ifdef FEATURE_INPUT_IMPROVED\n\t\tif( weaponType == LGT_Uzis ) {\n\t\t\tJoyVibrate(0x400, 0x400, 1, 0x100, 2, false);\n\t\t} else if( Lara.left_arm.flash_gun && Lara.right_arm.flash_gun ) {\n\t\t\tJoyVibrate(0x600, 0x600, 1, 0x300, 2, false);\n\t\t} else {\n\t\t\tJoyVibrate(0x400, 0x400, 1, 0x100, 2, false);\n\t\t}\n#endif // FEATURE_INPUT_IMPROVED\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Lara2Gun() {\n//\tINJECT(0x0042D000, set_pistol_arm);\n//\tINJECT(0x0042D050, draw_pistols);\n//\tINJECT(0x0042D0D0, undraw_pistols);\n//\tINJECT(0x0042D300, ready_pistols);\n//\tINJECT(0x0042D360, draw_pistol_meshes);\n//\tINJECT(0x0042D3B0, undraw_pistol_mesh_left);\n//\tINJECT(0x0042D3F0, undraw_pistol_mesh_right);\n\n\tINJECT(0x0042D430, PistolHandler);\n\n//\tINJECT(0x0042D5C0, AnimatePistols);\n}\n"
  },
  {
    "path": "game/lara2gun.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARA2GUN_H_INCLUDED\n#define LARA2GUN_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x0042D000:\t\tset_pistol_arm\n//\t0x0042D050:\t\tdraw_pistols\n//\t0x0042D0D0:\t\tundraw_pistols\n//\t0x0042D300:\t\tready_pistols\n//\t0x0042D360:\t\tdraw_pistol_meshes\n//\t0x0042D3B0:\t\tundraw_pistol_mesh_left\n//\t0x0042D3F0:\t\tundraw_pistol_mesh_right\n\nvoid __cdecl PistolHandler(int weaponType); // 0x0042D430\n\n#define AnimatePistols ((void(__cdecl*)(int)) 0x0042D5C0)\n\n#endif // LARA2GUN_H_INCLUDED\n"
  },
  {
    "path": "game/laraclimb.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/laraclimb.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_LaraClimb() {\n//\tINJECT(0x0042D8F0, lara_as_climbleft);\n//\tINJECT(0x0042D930, lara_as_climbright);\n//\tINJECT(0x0042D970, lara_as_climbstnc);\n//\tINJECT(0x0042D9F0, lara_as_climbing);\n//\tINJECT(0x0042DA10, lara_as_climbend);\n//\tINJECT(0x0042DA30, lara_as_climbdown);\n//\tINJECT(0x0042DA50, lara_col_climbleft);\n//\tINJECT(0x0042DAB0, lara_col_climbright);\n//\tINJECT(0x0042DB10, lara_col_climbstnc);\n//\tINJECT(0x0042DD20, lara_col_climbing);\n//\tINJECT(----------, lara_col_climbend);\n//\tINJECT(0x0042DE70, lara_col_climbdown);\n//\tINJECT(0x0042E010, LaraCheckForLetGo);\n//\tINJECT(0x0042E0C0, LaraTestClimb);\n//\tINJECT(0x0042E330, LaraTestClimbPos);\n//\tINJECT(0x0042E400, LaraDoClimbLeftRight);\n//\tINJECT(0x0042E4F0, LaraTestClimbUpPos);\n}\n"
  },
  {
    "path": "game/laraclimb.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARA_CLIMB_H_INCLUDED\n#define LARA_CLIMB_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x0042D8F0:\t\tlara_as_climbleft\n//\t0x0042D930:\t\tlara_as_climbright\n//\t0x0042D970:\t\tlara_as_climbstnc\n//\t0x0042D9F0:\t\tlara_as_climbing\n//\t0x0042DA10:\t\tlara_as_climbend\n//\t0x0042DA30:\t\tlara_as_climbdown\n//\t0x0042DA50:\t\tlara_col_climbleft\n//\t0x0042DAB0:\t\tlara_col_climbright\n//\t0x0042DB10:\t\tlara_col_climbstnc\n//\t0x0042DD20:\t\tlara_col_climbing\n//\t----------:\t\tlara_col_climbend\n//\t0x0042DE70:\t\tlara_col_climbdown\n//\t0x0042E010:\t\tLaraCheckForLetGo\n//\t0x0042E0C0:\t\tLaraTestClimb\n//\t0x0042E330:\t\tLaraTestClimbPos\n//\t0x0042E400:\t\tLaraDoClimbLeftRight\n//\t0x0042E4F0:\t\tLaraTestClimbUpPos\n\n#endif // _H_INCLUDED\n"
  },
  {
    "path": "game/larafire.cpp",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/larafire.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_LaraFire() {\n//\tINJECT(0x0042E740, LaraGun);\n//\tINJECT(0x0042ECB0, CheckForHoldingState);\n//\tINJECT(0x0042ECF0, InitialiseNewWeapon);\n//\tINJECT(0x0042EE30, LaraTargetInfo);\n//\tINJECT(0x0042EFD0, LaraGetNewTarget);\n//\tINJECT(0x0042F1F0, find_target_point);\n//\tINJECT(0x0042F2A0, AimWeapon);\n//\tINJECT(0x0042F370, FireWeapon);\n//\tINJECT(0x0042F6E0, HitTarget);\n//\tINJECT(0x0042F780, SmashItem);\n//\tINJECT(0x0042F7E0, WeaponObject);\n}"
  },
  {
    "path": "game/larafire.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARA_FIRE_H_INCLUDED\n#define LARA_FIRE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define LaraGun ((void(__cdecl*)(void)) 0x0042E740)\n#define CheckForHoldingState ((int(__cdecl*)(int)) 0x0042ECB0)\n#define InitialiseNewWeapon ((void(__cdecl*)(void)) 0x0042ECF0)\n#define LaraTargetInfo ((void(__cdecl*)(WEAPON_INFO*)) 0x0042EE30)\n#define LaraGetNewTarget ((void(__cdecl*)(WEAPON_INFO*)) 0x0042EFD0)\n#define find_target_point ((void(__cdecl*)(ITEM_INFO*,GAME_VECTOR*)) 0x0042F1F0)\n#define AimWeapon ((void(__cdecl*)(WEAPON_INFO*,LARA_ARM*)) 0x0042F2A0)\n#define FireWeapon ((int(__cdecl*)(int,ITEM_INFO*,ITEM_INFO*,__int16*)) 0x0042F370)\n#define HitTarget ((void(__cdecl*)(ITEM_INFO*,GAME_VECTOR*,int)) 0x0042F6E0)\n#define SmashItem ((void(__cdecl*)(__int16,int)) 0x0042F780)\n#define WeaponObject ((int(__cdecl*)(int)) 0x0042F7E0)\n\n#endif // LARA_FIRE_H_INCLUDED\n"
  },
  {
    "path": "game/laraflare.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/laraflare.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"3dsystem/scalespr.h\"\n#include \"game/draw.h\"\n#include \"specific/game.h\"\n#include \"specific/output.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nextern DWORD AlphaBlendMode;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\nvoid __cdecl DrawFlareInAir(ITEM_INFO *item) {\n\tint rate;\n\t__int16 *ptr[2];\n\tGetFrames(item, ptr, &rate);\n\tphd_PushMatrix();\n\tphd_TranslateAbs(item->pos.x, item->pos.y, item->pos.z);\n\tphd_RotYXZ(item->pos.rotY, item->pos.rotX, item->pos.rotZ);\n\tint clip = S_GetObjectBounds(ptr[0]);\n\tif( clip ) {\n\t\tCalculateObjectLighting(item, ptr[0]);\n\t\tphd_PutPolygons(MeshPtr[Objects[ID_FLARE_ITEM].meshIndex], clip);\n\t\tif( CHK_ANY((DWORD)item->data, 0x8000) ) {\n\t\t\tphd_TranslateRel(-6, 6, 80);\n\t\t\tphd_RotX(-90 * PHD_DEGREE);\n\t\t\tphd_RotY(2 * GetRandomDraw());\n\t\t\tS_CalculateStaticLight(0x800);\n\t\t\tphd_PutPolygons(MeshPtr[Objects[ID_FLARE_FIRE].meshIndex], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tif( AlphaBlendMode ) {\n\t\t\t\tint shade = (GetRandomDraw() & 0xFFF) + 0x1000;\n\t\t\t\tDWORD flags = GLOW_FLARE_COLOR;\n\t\t\t\tflags |= SPR_BLEND_ADD|SPR_TINT|SPR_SHADE|SPR_SEMITRANS;\n\t\t\t\tS_DrawSprite(flags, 0, 0, 0, Objects[ID_GLOW].meshIndex, shade, 0);\n\t\t\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t}\n\t}\n\tphd_PopMatrix();\n}\n\n/*\n * Inject function\n */\nvoid Inject_LaraFlare() {\n//\tINJECT(0x0042F840, DoFlareLight);\n//\tINJECT(0x0042F8E0, DoFlareInHand);\n\n\tINJECT(0x0042F9C0, DrawFlareInAir);\n\n//\tINJECT(0x0042FAC0, CreateFlare);\n//\tINJECT(0x0042FCA0, set_flare_arm);\n//\tINJECT(0x0042FCF0, draw_flare);\n//\tINJECT(0x0042FE60, undraw_flare);\n//\tINJECT(0x00430090, draw_flare_meshes);\n//\tINJECT(0x004300B0, undraw_flare_meshes);\n//\tINJECT(0x004300D0, ready_flare);\n//\tINJECT(0x00430110, FlareControl);\n}\n"
  },
  {
    "path": "game/laraflare.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARA_FLARE_H_INCLUDED\n#define LARA_FLARE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x0042F840:\t\tDoFlareLight\n//\t0x0042F8E0:\t\tDoFlareInHand\n\nvoid __cdecl DrawFlareInAir(ITEM_INFO *item);\n\n//\t0x0042FAC0:\t\tCreateFlare\n//\t0x0042FCA0:\t\tset_flare_arm\n//\t0x0042FCF0:\t\tdraw_flare\n//\t0x0042FE60:\t\tundraw_flare\n//\t0x00430090:\t\tdraw_flare_meshes\n//\t0x004300B0:\t\tundraw_flare_meshes\n//\t0x004300D0:\t\tready_flare\n//\t0x00430110:\t\tFlareControl\n\n#endif // LARA_FLARE_H_INCLUDED\n"
  },
  {
    "path": "game/laramisc.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/laramisc.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/collide.h\"\n#include \"game/control.h\"\n#include \"game/effects.h\"\n#include \"game/lara.h\"\n#include \"game/larasurf.h\"\n#include \"game/laraswim.h\"\n#include \"game/invfunc.h\"\n#include \"game/items.h\"\n#include \"game/larafire.h\"\n#include \"game/sound.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\nvoid __cdecl LaraControl(__int16 itemID) {\n\tCOLL_INFO coll;\n\tITEM_INFO *item = LaraItem;\n\n#ifdef FEATURE_CHEAT\n\tif( CHK_ANY(GF_GameFlow.flags, GFF_EnableCheatCode|GFF_DozyCheatEnabled) ) {\n\t\t// Recover health + get inventory stuff\n\t\tif( CHK_ANY(InputStatus, IN_STUFFCHEAT) ) {\n\t\t\tLaraCheatGetStuff();\n\t\t\titem->hitPoints = 1000;\n\t\t}\n\t\t// Enable dozy cheat (flying with full health). It is allowed for boat, but not for skidoo\n\t\tif( !Lara.extra_anim && (Lara.skidoo < 0 || Items[Lara.skidoo].objectID == ID_BOAT)\n\t\t\t&& Lara.water_status != LWS_Cheat && CHK_ANY(InputStatus, IN_DOZYCHEAT) )\n\t\t{\n\t\t\tif( Lara.water_status != LWS_Underwater || item->hitPoints <= 0 ) {\n\t\t\t\titem->pos.y -= 0x80;\n\t\t\t\titem->animNumber = 87;\n\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;\n\t\t\t\titem->currentAnimState = AS_SWIM;\n\t\t\t\titem->goalAnimState = AS_SWIM;\n\t\t\t\titem->gravity = 0;\n\t\t\t\titem->pos.rotX = 30*PHD_DEGREE;\n\t\t\t\titem->fallSpeed = 30;\n\t\t\t\tLara.torso_x_rot = Lara.torso_y_rot = 0;\n\t\t\t\tLara.head_x_rot = Lara.head_y_rot = 0;\n\t\t\t\tif( item->hitPoints <= 0 && Lara.gun_type != LGT_Flare ) {\n\t\t\t\t\tBYTE backupGunType = SaveGame.start[CurrentLevel].gunType;\n\t\t\t\t\tSaveGame.start[CurrentLevel].gunType = Lara.request_gun_type;\n\t\t\t\t\tLaraInitialiseMeshes(CurrentLevel);\n\t\t\t\t\tSaveGame.start[CurrentLevel].gunType = backupGunType;\n\t\t\t\t\tLara.gun_status = LGS_Armless;\n\t\t\t\t\tLara.target = NULL;\n\t\t\t\t\tmemset(&Lara.left_arm, 0, sizeof(Lara.left_arm));\n\t\t\t\t\tmemset(&Lara.right_arm, 0, sizeof(Lara.right_arm));\n\t\t\t\t\tif( Lara.weapon_item >= 0 ) {\n\t\t\t\t\t\tKillItem(Lara.weapon_item);\n\t\t\t\t\t\tLara.weapon_item = -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\t\t\tLara.water_status = LWS_Cheat;\n\t\t\tLara.skidoo = -1; // get off from vehicle\n\t\t\tLara.spaz_effect_count = 0;\n\t\t\tLara.spaz_effect = NULL;\n\t\t\tLara.hit_frame = 0;\n\t\t\tLara.hit_direction = -1;\n\t\t\tLara.air = 1800;\n\t\t\tLara.death_count = 0;\n\t\t\tLara.mesh_effects = 0x7FFF; // Lara has golden skin\n\t\t}\n\t}\n#endif // FEATURE_CHEAT\n\n\tBOOL isRoomUnderwater = CHK_ANY(RoomInfo[item->roomNumber].flags, ROOM_UNDERWATER);\n\tint depth = GetWaterDepth(item->pos.x, item->pos.y, item->pos.z, item->roomNumber);\n\tint height = GetWaterHeight(item->pos.x, item->pos.y, item->pos.z, item->roomNumber);\n\tint water_surface_dist = ( height == NO_HEIGHT ) ? NO_HEIGHT : item->pos.y - height;\n\n\tLara.water_surface_dist = -water_surface_dist;\n\tWadeSplash(item, height);\n\n\tif( Lara.skidoo == -1 && !Lara.extra_anim ) {\n\t\tswitch( Lara.water_status ) {\n\t\t\tcase LWS_AboveWater:\n\t\t\t\tif( water_surface_dist != NO_HEIGHT && water_surface_dist >= 0x180 ) {\n\t\t\t\t\tif( depth <= (0x2DA-0x100) ) {\n\t\t\t\t\t\tif( water_surface_dist > 0x180 ) {\n\t\t\t\t\t\t\tLara.water_status = LWS_Wade;\n\t\t\t\t\t\t\tif( !item->gravity ) {\n\t\t\t\t\t\t\t\titem->goalAnimState = AS_STOP;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if( isRoomUnderwater ) {\n\t\t\t\t\t\tLara.air = 1800;\n\t\t\t\t\t\tLara.water_status = LWS_Underwater;\n\t\t\t\t\t\titem->gravity = 0;\n\t\t\t\t\t\titem->pos.y += 100;\n\t\t\t\t\t\tUpdateLaraRoom(item, 0);\n\t\t\t\t\t\tStopSoundEffect(30);\n\t\t\t\t\t\tswitch( item->currentAnimState ) {\n\t\t\t\t\t\t\tcase AS_SWANDIVE:\n\t\t\t\t\t\t\t\titem->pos.rotX = -45*PHD_DEGREE;\n\t\t\t\t\t\t\t\titem->goalAnimState = AS_DIVE;\n\t\t\t\t\t\t\t\tAnimateLara(item);\n\t\t\t\t\t\t\t\titem->fallSpeed *= 2;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase AS_FASTDIVE:\n\t\t\t\t\t\t\t\titem->pos.rotX = -85*PHD_DEGREE;\n\t\t\t\t\t\t\t\titem->goalAnimState = AS_DIVE;\n\t\t\t\t\t\t\t\tAnimateLara(item);\n\t\t\t\t\t\t\t\titem->fallSpeed *= 2;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\titem->pos.rotX = -45*PHD_DEGREE;\n\t\t\t\t\t\t\t\titem->animNumber = 112;\n\t\t\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;\n\t\t\t\t\t\t\t\titem->currentAnimState = AS_DIVE;\n\t\t\t\t\t\t\t\titem->goalAnimState = AS_SWIM;\n\t\t\t\t\t\t\t\titem->fallSpeed = item->fallSpeed * 3 / 2;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tLara.torso_x_rot = Lara.torso_y_rot = 0;\n\t\t\t\t\t\tLara.head_x_rot = Lara.head_y_rot = 0;\n\t\t\t\t\t\tSplash(item);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase LWS_Wade:\n\t\t\t\tCamera.targetElevation = -22*PHD_DEGREE;\n\t\t\t\tif( water_surface_dist >= 0x180 ) {\n\t\t\t\t\tif( water_surface_dist > 0x2DA ) {\n\t\t\t\t\t\tLara.water_status = LWS_Surface;\n\t\t\t\t\t\titem->pos.y += 1 - water_surface_dist;\n\t\t\t\t\t\tswitch( item->currentAnimState ) {\n\t\t\t\t\t\t\tcase AS_BACK:\n\t\t\t\t\t\t\t\titem->currentAnimState = AS_SURFBACK;\n\t\t\t\t\t\t\t\titem->animNumber = 140;\n\t\t\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase AS_STEPRIGHT:\n\t\t\t\t\t\t\t\titem->currentAnimState = AS_SURFRIGHT;\n\t\t\t\t\t\t\t\titem->animNumber = 144;\n\t\t\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase AS_STEPLEFT:\n\t\t\t\t\t\t\t\titem->currentAnimState = AS_SURFLEFT;\n\t\t\t\t\t\t\t\titem->animNumber = 143;\n\t\t\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\titem->currentAnimState = AS_SURFSWIM;\n\t\t\t\t\t\t\t\titem->animNumber = 116;\n\t\t\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\titem->gravity = 0;\n\t\t\t\t\t\titem->goalAnimState = item->currentAnimState;\n\t\t\t\t\t\titem->fallSpeed = 0;\n\t\t\t\t\t\tLara.dive_count = 0;\n\t\t\t\t\t\titem->pos.rotX = item->pos.rotZ = 0;\n\t\t\t\t\t\tLara.torso_x_rot = Lara.torso_y_rot = 0;\n\t\t\t\t\t\tLara.head_x_rot = Lara.head_y_rot = 0;\n\t\t\t\t\t\tUpdateLaraRoom(item, -0x17D);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tLara.water_status = LWS_AboveWater;\n\t\t\t\t\tif( item->currentAnimState == AS_WADE )\n\t\t\t\t\t\titem->goalAnimState = AS_RUN;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase LWS_Surface:\n\t\t\t\tif( !isRoomUnderwater ) {\n\t\t\t\t\tif( water_surface_dist <= 0x180 ) {\n\t\t\t\t\t\tLara.water_status = LWS_AboveWater;\n\t\t\t\t\t\titem->animNumber = 34;\n\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;;\n\t\t\t\t\t\titem->goalAnimState = AS_FORWARDJUMP;\n\t\t\t\t\t\titem->currentAnimState = AS_FORWARDJUMP;\n\t\t\t\t\t\titem->gravity = 1;\n\t\t\t\t\t\titem->speed = item->fallSpeed / 4;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tLara.water_status = LWS_Wade;\n\t\t\t\t\t\titem->animNumber = 103;\n\t\t\t\t\t\titem->currentAnimState = AS_STOP;\n\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;;\n\t\t\t\t\t\titem->goalAnimState = AS_WADE;\n\t\t\t\t\t\tAnimateItem(item);\n\t\t\t\t\t}\n\t\t\t\t\titem->fallSpeed = 0;\n\t\t\t\t\titem->pos.rotX = item->pos.rotZ = 0;\n\t\t\t\t\tLara.torso_x_rot = Lara.torso_y_rot = 0;\n\t\t\t\t\tLara.head_x_rot = Lara.head_y_rot = 0;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase LWS_Underwater:\n\t\t\t\tif( !isRoomUnderwater ) {\n\t\t\t\t\tif( depth == NO_HEIGHT || ABS(water_surface_dist) >= 0x100 ) {\n\t\t\t\t\t\tLara.water_status = LWS_AboveWater;\n\t\t\t\t\t\titem->animNumber = 34;\n\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;;\n\t\t\t\t\t\titem->goalAnimState = AS_FORWARDJUMP;\n\t\t\t\t\t\titem->currentAnimState = AS_FORWARDJUMP;\n\t\t\t\t\t\titem->speed = item->fallSpeed / 4;\n\t\t\t\t\t\titem->gravity = 1;\n\t\t\t\t\t\titem->fallSpeed = 0;\n\t\t\t\t\t\titem->pos.rotX = item->pos.rotZ = 0;\n\t\t\t\t\t\tLara.torso_x_rot = Lara.torso_y_rot = 0;\n\t\t\t\t\t\tLara.head_x_rot = Lara.head_y_rot = 0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tLara.water_status = LWS_Surface;\n\t\t\t\t\t\titem->pos.y += 1 - water_surface_dist;\n\t\t\t\t\t\titem->animNumber = 114;\n\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;;\n\t\t\t\t\t\titem->goalAnimState = AS_SURFTREAD;\n\t\t\t\t\t\titem->currentAnimState = AS_SURFTREAD;\n\t\t\t\t\t\titem->fallSpeed = 0;\n\t\t\t\t\t\tLara.dive_count = 11;\n\t\t\t\t\t\titem->pos.rotX = item->pos.rotZ = 0;\n\t\t\t\t\t\tLara.torso_x_rot = Lara.torso_y_rot = 0;\n\t\t\t\t\t\tLara.head_x_rot = Lara.head_y_rot = 0;\n\t\t\t\t\t\tUpdateLaraRoom(item, -0x17D);\n\t\t\t\t\t\tPlaySoundEffect(36, &item->pos, SFX_ALWAYS);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tif( item->hitPoints > 0 ) {\n\t\tif( GF_NoFloor && item->pos.y >= GF_NoFloor ) {\n\t\t\titem->hitPoints = -1;\n\t\t\tLara.death_count = 9*30; // let's skip 9 seconds to death\n\t\t}\n\t} else {\n\t\titem->hitPoints = -1;\n\t\tif( !Lara.death_count ) {\n\t\t\tS_CDStop();\n\t\t}\n\t\t++Lara.death_count;\n\t\tif( CHK_ANY(item->flags, IFL_INVISIBLE) ) { // Nothing left from Lara?\n\t\t\t++Lara.death_count; // In this case death timer ticks twice faster\n\t\t\treturn;\n\t\t}\n\t}\n\n\tswitch( Lara.water_status ) {\n\t\tcase LWS_AboveWater:\n\t\tcase LWS_Wade:\n\t\t\tLara.air = 1800;\n\t\t\tLaraAboveWater(item, &coll);\n\t\t\tbreak;\n\t\tcase LWS_Underwater:\n\t\t\tif( item->hitPoints >= 0 && --Lara.air < 0 ) {\n\t\t\t\tLara.air = -1;\n\t\t\t\titem->hitPoints -= 5;\n\t\t\t}\n\t\t\tLaraUnderWater(item, &coll);\n\t\t\tbreak;\n\t\tcase LWS_Surface:\n\t\t\tif( item->hitPoints >= 0 ) {\n\t\t\t\tLara.air += 10;\n\t\t\t\tCLAMPG(Lara.air, 1800)\n\t\t\t}\n\t\t\tLaraSurface(item, &coll);\n\t\t\tbreak;\n#ifdef FEATURE_CHEAT\n\t\tcase LWS_Cheat:\n\t\t\tif( CHK_ANY(GF_GameFlow.flags, GFF_EnableCheatCode|GFF_DozyCheatEnabled) ) {\n\t\t\t\t// Update Dozy state just in case\n\t\t\t\titem->hitPoints = 1000;\n\t\t\t\tLara.death_count = 0; // NOTE: if died already, forget about death\n\t\t\t\tLaraUnderWater(item, &coll);\n\t\t\t\t// Return Lara to normal state if Walk is pressed without Look\n\t\t\t\tif( !Lara.extra_anim && CHK_ANY(InputStatus, IN_SLOW) && !CHK_ANY(InputStatus, IN_LOOK) ) {\n\t\t\t\t\tif( isRoomUnderwater || (water_surface_dist != NO_HEIGHT && water_surface_dist > 0) ) {\n\t\t\t\t\t\tLara.water_status = LWS_Underwater;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tLara.water_status = LWS_AboveWater;\n\t\t\t\t\t\titem->animNumber = 11;\n\t\t\t\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;\n\t\t\t\t\t\titem->pos.rotX = item->pos.rotZ = 0;\n\t\t\t\t\t\tLara.torso_x_rot = Lara.torso_y_rot = 0;\n\t\t\t\t\t\tLara.head_x_rot = Lara.head_y_rot = 0;\n\t\t\t\t\t}\n\t\t\t\t\tLara.mesh_effects = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n#endif // FEATURE_CHEAT\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\n\tSaveGame.statistics.distance += phd_sqrt((item->pos.z - Lara.last_pos.z) * (item->pos.z - Lara.last_pos.z)\n\t\t\t\t\t\t\t\t\t\t\t+ (item->pos.y - Lara.last_pos.y) * (item->pos.y - Lara.last_pos.y)\n\t\t\t\t\t\t\t\t\t\t\t+ (item->pos.x - Lara.last_pos.x) * (item->pos.x - Lara.last_pos.x));\n\tLara.last_pos.x = item->pos.x;\n\tLara.last_pos.y = item->pos.y;\n\tLara.last_pos.z = item->pos.z;\n}\n\nvoid __cdecl UseItem(__int16 itemID) {\n\tif( itemID <= ID_NONE || itemID >= ID_NUMBER_OBJECTS )\n\t\treturn;\n\n\tswitch( itemID ) {\n\t\tcase ID_PISTOL_ITEM:\n\t\tcase ID_PISTOL_OPTION:\n\t\t\tLara.request_gun_type = LGT_Pistols;\n\t\t\tbreak;\n\n\t\tcase ID_MAGNUM_ITEM:\n\t\tcase ID_MAGNUM_OPTION:\n\t\t\tLara.request_gun_type = LGT_Magnums;\n\t\t\tbreak;\n\n\t\tcase ID_UZI_ITEM:\n\t\tcase ID_UZI_OPTION:\n\t\t\tLara.request_gun_type = LGT_Uzis;\n\t\t\tbreak;\n\n\t\tcase ID_SHOTGUN_ITEM:\n\t\tcase ID_SHOTGUN_OPTION:\n\t\t\tLara.request_gun_type = LGT_Shotgun;\n\t\t\tbreak;\n\n\t\tcase ID_HARPOON_ITEM:\n\t\tcase ID_HARPOON_OPTION:\n\t\t\tLara.request_gun_type = LGT_Harpoon;\n\t\t\tbreak;\n\n\t\tcase ID_M16_ITEM:\n\t\tcase ID_M16_OPTION:\n\t\t\tLara.request_gun_type = LGT_M16;\n\t\t\tbreak;\n\n\t\tcase ID_GRENADE_ITEM:\n\t\tcase ID_GRENADE_OPTION:\n\t\t\tLara.request_gun_type = LGT_Grenade;\n\t\t\tbreak;\n\n\t\tcase ID_FLARES_ITEM:\n\t\tcase ID_FLARES_OPTION:\n\t\t\tLara.request_gun_type = LGT_Flare;\n\t\t\tbreak;\n\n\t\tcase ID_SMALL_MEDIPACK_ITEM:\n\t\tcase ID_SMALL_MEDIPACK_OPTION:\n\t\t\tif( LaraItem->hitPoints > 0 && LaraItem->hitPoints < 1000 ) {\n\t\t\t\tLaraItem->hitPoints += 500;\n\t\t\t\tif( LaraItem->hitPoints > 1000 )\n\t\t\t\t\tLaraItem->hitPoints = 1000;\n\t\t\t\tInv_RemoveItem(ID_SMALL_MEDIPACK_ITEM);\n\t\t\t\tPlaySoundEffect(116, NULL, 2);\n\t\t\t\t++SaveGame.statistics.mediPacks;\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase ID_LARGE_MEDIPACK_ITEM:\n\t\tcase ID_LARGE_MEDIPACK_OPTION:\n\t\t\tif( LaraItem->hitPoints > 0 && LaraItem->hitPoints < 1000 ) {\n\t\t\t\tLaraItem->hitPoints += 1000;\n\t\t\t\tif( LaraItem->hitPoints > 1000 )\n\t\t\t\t\tLaraItem->hitPoints = 1000;\n\t\t\t\tInv_RemoveItem(ID_LARGE_MEDIPACK_ITEM);\n\t\t\t\tPlaySoundEffect(116, NULL, 2);\n\t\t\t\tSaveGame.statistics.mediPacks += 2;\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nvoid __cdecl LaraCheatGetStuff() {\n\t// NOTE: there is no availability checks in the original code\n\tif( Objects[ID_PISTOL_OPTION].loaded ) {\n\t\tif( !Inv_RequestItem(ID_PISTOL_ITEM) ) {\n\t\t\tInv_AddItem(ID_PISTOL_ITEM);\n\t\t}\n\t}\n\tif( Objects[ID_MAGNUM_OPTION].loaded ) {\n\t\tif( !Inv_RequestItem(ID_MAGNUM_ITEM) ) {\n\t\t\tInv_AddItem(ID_MAGNUM_ITEM);\n\t\t}\n\t\tLara.magnum_ammo = (SaveGame.bonusFlag && !IsDemoLevelType) ? 10001 : 1000;\n\t}\n\tif( Objects[ID_UZI_OPTION].loaded ) {\n\t\tif( !Inv_RequestItem(ID_UZI_ITEM) ) {\n\t\t\tInv_AddItem(ID_UZI_ITEM);\n\t\t}\n\t\tLara.uzi_ammo = (SaveGame.bonusFlag && !IsDemoLevelType) ? 10001 : 2000;\n\t}\n\tif( Objects[ID_SHOTGUN_OPTION].loaded ) {\n\t\tif( !Inv_RequestItem(ID_SHOTGUN_ITEM) ) {\n\t\t\tInv_AddItem(ID_SHOTGUN_ITEM);\n\t\t}\n\t\tLara.shotgun_ammo = (SaveGame.bonusFlag && !IsDemoLevelType) ? 10001 : 300;\n\t}\n\tif( Objects[ID_HARPOON_OPTION].loaded ) {\n\t\tif( !Inv_RequestItem(ID_HARPOON_ITEM) ) {\n\t\t\tInv_AddItem(ID_HARPOON_ITEM);\n\t\t}\n\t\tLara.harpoon_ammo = (SaveGame.bonusFlag && !IsDemoLevelType) ? 10001 : 300;\n\t}\n\tif( Objects[ID_M16_OPTION].loaded ) {\n\t\tif( !Inv_RequestItem(ID_M16_ITEM) ) {\n\t\t\tInv_AddItem(ID_M16_ITEM);\n\t\t}\n\t\tLara.m16_ammo = (SaveGame.bonusFlag && !IsDemoLevelType) ? 10001 : 300;\n\t}\n\tif( Objects[ID_GRENADE_OPTION].loaded ) {\n\t\tif( !Inv_RequestItem(ID_GRENADE_ITEM) ) {\n\t\t\tInv_AddItem(ID_GRENADE_ITEM);\n\t\t}\n\t\tLara.grenade_ammo = (SaveGame.bonusFlag && !IsDemoLevelType) ? 10001 : 300;\n\t}\n\n\tfor( int i = 0; i < 10; ++i ) {\n\t\t// NOTE: there are no limits in the original code, but it works wrong without limits\n\t\tif( Objects[ID_FLARES_OPTION].loaded && Inv_RequestItem(ID_FLARE_ITEM) < 240 ) {\n\t\t\tInv_AddItem(ID_FLARES_ITEM);\n\t\t}\n\t\tif( Objects[ID_SMALL_MEDIPACK_OPTION].loaded && Inv_RequestItem(ID_SMALL_MEDIPACK_ITEM) < 240 ) {\n\t\t\tInv_AddItem(ID_SMALL_MEDIPACK_ITEM);\n\t\t}\n\t\tif( Objects[ID_LARGE_MEDIPACK_OPTION].loaded && Inv_RequestItem(ID_LARGE_MEDIPACK_ITEM) < 240 ) {\n\t\t\tInv_AddItem(ID_LARGE_MEDIPACK_ITEM);\n\t\t}\n\t}\n\n#ifdef FEATURE_CHEAT\n\t// NOTE: there is no cheat for keys/puzzles in the original code\n\tif( Objects[ID_KEY_OPTION1].loaded && !Inv_RequestItem(ID_KEY_ITEM1) ) {\n\t\tInv_AddItem(ID_KEY_ITEM1);\n\t}\n\tif( Objects[ID_KEY_OPTION2].loaded && !Inv_RequestItem(ID_KEY_ITEM2) ) {\n\t\tInv_AddItem(ID_KEY_ITEM2);\n\t}\n\tif( Objects[ID_KEY_OPTION3].loaded && !Inv_RequestItem(ID_KEY_ITEM3) ) {\n\t\tInv_AddItem(ID_KEY_ITEM3);\n\t}\n\tif( Objects[ID_KEY_OPTION4].loaded && !Inv_RequestItem(ID_KEY_ITEM4) ) {\n\t\tInv_AddItem(ID_KEY_ITEM4);\n\t}\n\tif( Objects[ID_PUZZLE_OPTION1].loaded && !Inv_RequestItem(ID_PUZZLE_ITEM1) ) {\n\t\tInv_AddItem(ID_PUZZLE_ITEM1);\n\t}\n\tif( Objects[ID_PUZZLE_OPTION2].loaded && !Inv_RequestItem(ID_PUZZLE_ITEM2) ) {\n\t\tInv_AddItem(ID_PUZZLE_ITEM2);\n\t}\n\tif( Objects[ID_PUZZLE_OPTION3].loaded && !Inv_RequestItem(ID_PUZZLE_ITEM3) ) {\n\t\tInv_AddItem(ID_PUZZLE_ITEM3);\n\t}\n\tif( Objects[ID_PUZZLE_OPTION4].loaded && !Inv_RequestItem(ID_PUZZLE_ITEM4) ) {\n\t\tInv_AddItem(ID_PUZZLE_ITEM4);\n\t}\n\tif( Objects[ID_PICKUP_OPTION1].loaded && !Inv_RequestItem(ID_PICKUP_ITEM1) ) {\n\t\tInv_AddItem(ID_PICKUP_ITEM1);\n\t}\n\tif( Objects[ID_PICKUP_OPTION2].loaded && !Inv_RequestItem(ID_PICKUP_ITEM2) ) {\n\t\tInv_AddItem(ID_PICKUP_ITEM2);\n\t}\n#endif // FEATURE_CHEAT\n}\n\nvoid __cdecl ControlLaraExtra(__int16 itemID) {\n\tAnimateItem(&Items[itemID]);\n}\n\nvoid __cdecl InitialiseLaraLoad(__int16 itemID) {\n\tLara.item_number = itemID;\n\tLaraItem = &Items[itemID];\n}\n\nvoid __cdecl InitialiseLaraInventory(int levelID) {\n\tint i;\n\tSTART_INFO *start = &SaveGame.start[levelID];\n\n\tInv_RemoveAllItems();\n\n\tif( GF_RemoveWeapons ) {\n\t\tstart->has_pistols = 0;\n\t\tstart->has_magnums = 0;\n\t\tstart->has_uzis = 0;\n\t\tstart->has_shotgun = 0;\n\t\tstart->has_m16 = 0;\n\t\tstart->has_grenade = 0;\n\t\tstart->has_harpoon = 0;\n\t\tstart->gunType = LGT_Unarmed;\n\t\tstart->gunStatus = LGS_Armless;\n\t\tGF_RemoveWeapons = 0;\n\t}\n\n\tif( GF_RemoveAmmo ) {\n\t\tstart->m16Ammo = 0;\n\t\tstart->grenadeAmmo = 0;\n\t\tstart->harpoonAmmo = 0;\n\t\tstart->shotgunAmmo = 0;\n\t\tstart->uziAmmo = 0;\n\t\tstart->magnumAmmo = 0;\n\t\tstart->pistolAmmo = 0;\n\t\tstart->flares = 0;\n\t\tstart->largeMedipacks = 0;\n\t\tstart->smallMedipacks = 0;\n\t\tGF_RemoveAmmo = 0;\n\t}\n\n\t// NOTE: additional weapon availability checks not presented in the original game\n\tif( !Objects[ID_PISTOL_OPTION].loaded ) {\n\t\tstart->has_pistols = 0;\n\t}\n\tif( !Objects[ID_UZI_OPTION].loaded ) {\n\t\tstart->has_uzis = 0;\n\t}\n\tif( !Objects[ID_MAGNUM_OPTION].loaded ) {\n\t\tstart->has_magnums = 0;\n\t}\n\tif( !Objects[ID_SHOTGUN_OPTION].loaded ) {\n\t\tstart->has_shotgun = 0;\n\t}\n\tif( !Objects[ID_GRENADE_OPTION].loaded ) {\n\t\tstart->has_grenade = 0;\n\t}\n\tif( !Objects[ID_M16_OPTION].loaded ) {\n\t\tstart->has_m16 = 0;\n\t}\n\tif( !Objects[ID_HARPOON_OPTION].loaded ) {\n\t\tstart->has_harpoon = 0;\n\t}\n\n\t// NOTE: additional ammo availability checks not presented in the original game\n\tif( !start->has_pistols && !Objects[ID_PISTOL_AMMO_OPTION].loaded ) {\n\t\tstart->pistolAmmo = 0;\n\t}\n\tif( !start->has_uzis && !Objects[ID_UZI_AMMO_OPTION].loaded ) {\n\t\tstart->uziAmmo = 0;\n\t}\n\tif( !start->has_magnums && !Objects[ID_MAGNUM_AMMO_OPTION].loaded ) {\n\t\tstart->magnumAmmo = 0;\n\t}\n\tif( !start->has_shotgun && !Objects[ID_SHOTGUN_AMMO_OPTION].loaded ) {\n\t\tstart->shotgunAmmo = 0;\n\t}\n\tif( !start->has_grenade && !Objects[ID_GRENADE_AMMO_OPTION].loaded ) {\n\t\tstart->grenadeAmmo = 0;\n\t}\n\tif( !start->has_m16 && !Objects[ID_M16_AMMO_OPTION].loaded ) {\n\t\tstart->m16Ammo = 0;\n\t}\n\tif( !start->has_harpoon && !Objects[ID_HARPOON_AMMO_OPTION].loaded ) {\n\t\tstart->harpoonAmmo = 0;\n\t}\n\n\t// NOTE: additional start gun type availability checks not presented in the original game\n\tswitch( start->gunType ) {\n\t\t// if the current weapon is absent then fall through\n\t\tcase LGT_Pistols\t: if( start->has_pistols ) break; // fall through\n\t\tcase LGT_Magnums\t: if( start->has_magnums ) break; // fall through\n\t\tcase LGT_Uzis\t\t: if( start->has_uzis\t ) break; // fall through\n\t\tcase LGT_Shotgun\t: if( start->has_shotgun ) break; // fall through\n\t\tcase LGT_M16\t\t: if( start->has_m16\t ) break; // fall through\n\t\tcase LGT_Grenade\t: if( start->has_grenade ) break; // fall through\n\t\tcase LGT_Harpoon\t: if( start->has_harpoon ) break; // fall through\n\t\t\tstart->gunType = start->has_pistols ? LGT_Pistols : LGT_Unarmed;\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tbreak;\n\t}\n\n\t// Statistics\n\tInv_AddItem(ID_COMPASS_ITEM);\n\n\t// Pistols\n\tLara.pistol_ammo = 1000;\n\tif( start->has_pistols ) {\n\t\tInv_AddItem(ID_PISTOL_ITEM);\n\t}\n\n\t// Magnums\n\tif( start->has_magnums ) {\n\t\tInv_AddItem(ID_MAGNUM_ITEM);\n\t\tLara.magnum_ammo = start->magnumAmmo;\n\t\tGlobalItemReplace(ID_MAGNUM_ITEM, ID_MAGNUM_AMMO_ITEM);\n\t} else {\n\t\tfor( i = 0; i < start->magnumAmmo / 40; ++i ) {\n\t\t\tInv_AddItem(ID_MAGNUM_AMMO_ITEM);\n\t\t}\n\t\tLara.magnum_ammo = 0;\n\t}\n\n\t// Uzis\n\tif( start->has_uzis ) {\n\t\tInv_AddItem(ID_UZI_ITEM);\n\t\tLara.uzi_ammo = start->uziAmmo;\n\t\tGlobalItemReplace(ID_UZI_ITEM, ID_UZI_AMMO_ITEM);\n\t} else {\n\t\tfor( i = 0; i < start->uziAmmo / 80; ++i ) {\n\t\t\tInv_AddItem(ID_UZI_AMMO_ITEM);\n\t\t}\n\t\tLara.uzi_ammo = 0;\n\t}\n\n\t// Shotgun\n\tif( start->has_shotgun ) {\n\t\tInv_AddItem(ID_SHOTGUN_ITEM);\n\t\tLara.shotgun_ammo = start->shotgunAmmo;\n\t\tGlobalItemReplace(ID_SHOTGUN_ITEM, ID_SHOTGUN_AMMO_ITEM);\n\t} else {\n\t\tfor( i = 0; i < start->shotgunAmmo / 12; ++i ) {\n\t\t\tInv_AddItem(ID_SHOTGUN_AMMO_ITEM);\n\t\t}\n\t\tLara.shotgun_ammo = 0;\n\t}\n\n\t// Grenade\n\tif( start->has_grenade ) {\n\t\tInv_AddItem(ID_GRENADE_ITEM);\n\t\tLara.grenade_ammo = start->grenadeAmmo;\n\t\tGlobalItemReplace(ID_GRENADE_ITEM, ID_GRENADE_AMMO_ITEM);\n\t} else {\n\t\tfor( i = 0; i < start->grenadeAmmo / 2; ++i ) {\n\t\t\tInv_AddItem(ID_GRENADE_AMMO_ITEM);\n\t\t}\n\t\tLara.grenade_ammo = 0;\n\t}\n\n\t// M16\n\tif( start->has_m16 ) {\n\t\tInv_AddItem(ID_M16_ITEM);\n\t\tLara.m16_ammo = start->m16Ammo;\n\t\tGlobalItemReplace(ID_M16_ITEM, ID_M16_AMMO_ITEM);\n\t} else {\n\t\tfor( i = 0; i < start->m16Ammo / 40; ++i ) {\n\t\t\tInv_AddItem(ID_M16_AMMO_ITEM);\n\t\t}\n\t\tLara.m16_ammo = 0;\n\t}\n\n\t// Harpoon\n\tif( start->has_harpoon ) {\n\t\tInv_AddItem(ID_HARPOON_ITEM);\n\t\tLara.harpoon_ammo = start->harpoonAmmo;\n\t\tGlobalItemReplace(ID_HARPOON_ITEM, ID_HARPOON_AMMO_ITEM);\n\t} else {\n\t\tfor( i = 0; i < start->harpoonAmmo / 3; ++i ) {\n\t\t\tInv_AddItem(ID_HARPOON_AMMO_ITEM);\n\t\t}\n\t\tLara.harpoon_ammo = 0;\n\t}\n\n\t// Flares\n\tfor( i = 0; i < start->flares; ++i ) {\n\t\tInv_AddItem(ID_FLARE_ITEM);\n\t}\n\n\t// Small medipacks\n\tfor( i = 0; i < start->smallMedipacks; ++i ) {\n\t\tInv_AddItem(ID_SMALL_MEDIPACK_ITEM);\n\t}\n\n\t// Large medipacks\n\tfor( i = 0; i < start->largeMedipacks; ++i ) {\n\t\tInv_AddItem(ID_LARGE_MEDIPACK_ITEM);\n\t}\n\n\tLara.gun_status = LGS_Armless;\n\tLara.last_gun_type = start->gunType;\n\tLara.gun_type = start->gunType;\n\tLara.request_gun_type = start->gunType;\n\tLaraInitialiseMeshes(levelID);\n\tInitialiseNewWeapon();\n}\n\n/*\n * Inject function\n */\nvoid Inject_LaraMisc() {\n\tINJECT(0x00430380, LaraControl);\n\n//\tINJECT(0x00430A10, AnimateLara);\n\n\tINJECT(0x00430D10, UseItem);\n\tINJECT(0x00430ED0, LaraCheatGetStuff);\n\tINJECT(0x00430F90, ControlLaraExtra);\n\tINJECT(0x00430FB0, InitialiseLaraLoad);\n\n//\tINJECT(0x00430FE0, InitialiseLara);\n\n\tINJECT(0x004312A0, InitialiseLaraInventory);\n\n//\tINJECT(0x00431610, LaraInitialiseMeshes);\n}\n"
  },
  {
    "path": "game/laramisc.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARAMISC_H_INCLUDED\n#define LARAMISC_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl LaraControl(__int16 itemID);\n\n#define AnimateLara ((void(__cdecl*)(ITEM_INFO*)) 0x00430A10)\n\nvoid __cdecl UseItem(__int16 itemID); // 0x00430D10\nvoid __cdecl LaraCheatGetStuff(); // 0x00430ED0\nvoid __cdecl ControlLaraExtra(__int16 itemID); // 0x00430F90\nvoid __cdecl InitialiseLaraLoad(__int16 itemID); // 0x00430FB0\n\n#define InitialiseLara ((void(__cdecl*)(int)) 0x00430FE0)\n\nvoid __cdecl InitialiseLaraInventory(int levelID); // 0x004312A0\n\n#define LaraInitialiseMeshes ((void(__cdecl*)(int)) 0x00431610)\n\n#endif // LARAMISC_H_INCLUDED\n"
  },
  {
    "path": "game/larasurf.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/larasurf.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_LaraSurf() {\n//\tINJECT(0x00431710, LaraSurface);\n//\tINJECT(0x00431870, lara_as_surfswim);\n//\tINJECT(0x004318E0, lara_as_surfback);\n//\tINJECT(0x00431940, lara_as_surfleft);\n//\tINJECT(0x004319A0, lara_as_surfright);\n//\tINJECT(0x00431A00, lara_as_surftread);\n//\tINJECT(0x00431AC0, lara_col_surfswim);\n//\tINJECT(0x00431B00, lara_col_surfback);\n//\tINJECT(0x00431B30, lara_col_surfleft);\n//\tINJECT(0x00431B60, lara_col_surfright);\n//\tINJECT(0x00431B90, lara_col_surftread);\n//\tINJECT(0x00431BF0, LaraSurfaceCollision);\n//\tINJECT(0x00431CF0, LaraTestWaterStepOut);\n//\tINJECT(0x00431DE0, LaraTestWaterClimbOut);\n}\n"
  },
  {
    "path": "game/larasurf.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARA_SURF_H_INCLUDED\n#define LARA_SURF_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define LaraSurface ((void(__cdecl*)(ITEM_INFO*, COLL_INFO*)) 0x00431710)\n\n//\t0x00431870:\t\tlara_as_surfswim\n//\t0x004318E0:\t\tlara_as_surfback\n//\t0x00431940:\t\tlara_as_surfleft\n//\t0x004319A0:\t\tlara_as_surfright\n//\t0x00431A00:\t\tlara_as_surftread\n//\t0x00431AC0:\t\tlara_col_surfswim\n//\t0x00431B00:\t\tlara_col_surfback\n//\t0x00431B30:\t\tlara_col_surfleft\n//\t0x00431B60:\t\tlara_col_surfright\n//\t0x00431B90:\t\tlara_col_surftread\n//\t0x00431BF0:\t\tLaraSurfaceCollision\n//\t0x00431CF0:\t\tLaraTestWaterStepOut\n//\t0x00431DE0:\t\tLaraTestWaterClimbOut\n\n#endif // LARA_SURF_H_INCLUDED\n"
  },
  {
    "path": "game/laraswim.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/laraswim.h\"\n#include \"global/vars.h\"\n\nvoid __cdecl SwimTurn(ITEM_INFO *item) {\n\tif( CHK_ANY(InputStatus, IN_FORWARD) ) {\n\t\titem->pos.rotX -= 2*PHD_DEGREE;\n\t} else if( CHK_ANY(InputStatus, IN_BACK) ) {\n\t\titem->pos.rotX += 2*PHD_DEGREE;\n\t}\n\n\tif( CHK_ANY(InputStatus, IN_LEFT) ) {\n\t\tLara.turn_rate -= PHD_DEGREE*9/4;\n\t\tCLAMPL(Lara.turn_rate, -6*PHD_DEGREE);\n\t\titem->pos.rotZ -= 3*PHD_DEGREE;\n\t} else if( CHK_ANY(InputStatus, IN_RIGHT) ) {\n\t\tLara.turn_rate += PHD_DEGREE*9/4;\n\t\tCLAMPG(Lara.turn_rate, 6*PHD_DEGREE);\n\t\titem->pos.rotZ += 3*PHD_DEGREE;\n\t}\n}\n\nvoid __cdecl lara_as_swim(ITEM_INFO *item, COLL_INFO *coll) {\n\tif( item->hitPoints <= 0 ) {\n\t\titem->goalAnimState = AS_UWDEATH;\n\t\treturn;\n\t}\n\n\tif( CHK_ANY(InputStatus, IN_ROLL) ) {\n\t\titem->currentAnimState = AS_WATERROLL;\n\t\titem->animNumber = 203;\n\t\titem->frameNumber = Anims[item->animNumber].frameBase;\n\t} else {\n\t\tSwimTurn(item);\n\t\titem->fallSpeed += 8;\n#ifdef FEATURE_CHEAT\n\t\tif( Lara.water_status == LWS_Cheat ) {\n\t\t\tCLAMPG(item->fallSpeed, 400);\n\t\t} else {\n\t\t\tCLAMPG(item->fallSpeed, 200);\n\t\t}\n#else // FEATURE_CHEAT\n\t\tCLAMPG(item->fallSpeed, 200);\n#endif // FEATURE_CHEAT\n\t\tif( !CHK_ANY(InputStatus, IN_JUMP) ) {\n\t\t\titem->goalAnimState = AS_GLIDE;\n\t\t}\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_LaraSwim() {\n//\tINJECT(0x00432000, LaraUnderWater);\n\n\tINJECT(0x00432230, SwimTurn);\n\tINJECT(0x004322C0, lara_as_swim);\n\n//\tINJECT(0x00432330, lara_as_glide);\n//\tINJECT(0x004323B0, lara_as_tread);\n//\tINJECT(0x00432440, lara_as_dive);\n//\tINJECT(0x00432460, lara_as_uwdeath);\n//\tINJECT(0x004324C0, lara_as_waterroll);\n//\tINJECT(0x004324D0, lara_col_swim);\n//\tINJECT(----------, lara_col_glide);\n//\tINJECT(----------, lara_col_tread);\n//\tINJECT(----------, lara_col_dive);\n//\tINJECT(0x004324F0, lara_col_uwdeath);\n//\tINJECT(----------, lara_col_waterroll);\n//\tINJECT(0x00432550, GetWaterDepth);\n//\tINJECT(0x004326F0, LaraTestWaterDepth);\n//\tINJECT(0x004327C0, LaraSwimCollision);\n//\tINJECT(0x00432920, LaraWaterCurrent);\n}\n"
  },
  {
    "path": "game/laraswim.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LARA_SWIM_H_INCLUDED\n#define LARA_SWIM_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define LaraUnderWater ((void(__cdecl*)(ITEM_INFO*, COLL_INFO*)) 0x00432000)\n\nvoid __cdecl SwimTurn(ITEM_INFO *item); // 0x00432230\nvoid __cdecl lara_as_swim(ITEM_INFO *item, COLL_INFO *coll); // 0x004322C0\n\n//\t0x00432330:\t\tlara_as_glide\n//\t0x004323B0:\t\tlara_as_tread\n//\t0x00432440:\t\tlara_as_dive\n//\t0x00432460:\t\tlara_as_uwdeath\n//\t0x004324C0:\t\tlara_as_waterroll\n//\t0x004324D0:\t\tlara_col_swim\n//\t----------:\t\tlara_col_glide\n//\t----------:\t\tlara_col_tread\n//\t----------:\t\tlara_col_dive\n//\t0x004324F0:\t\tlara_col_uwdeath\n//\t----------:\t\tlara_col_waterroll\n\n#define GetWaterDepth ((int(__cdecl*)(int, int, int, __int16)) 0x00432550)\n\n//\t0x004326F0:\t\tLaraTestWaterDepth\n//\t0x004327C0:\t\tLaraSwimCollision\n//\t0x00432920:\t\tLaraWaterCurrent\n\n#endif // LARA_SWIM_H_INCLUDED\n"
  },
  {
    "path": "game/lot.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/lot.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Lot() {\n//\tINJECT(0x00432B10, InitialiseLOTarray);\n//\tINJECT(0x00432B70, DisableBaddieAI);\n//\tINJECT(0x00432BC0, EnableBaddieAI);\n//\tINJECT(0x00432D70, InitialiseSlot);\n//\tINJECT(0x00432F80, CreateZone);\n//\tINJECT(0x00433040, ClearLOT);\n}\n"
  },
  {
    "path": "game/lot.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef LOT_H_INCLUDED\n#define LOT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x00432B10:\t\tInitialiseLOTarray\n\n#define DisableBaddieAI ((void(__cdecl*)(__int16)) 0x00432B70)\n#define EnableBaddieAI ((int(__cdecl*)(__int16, BOOL)) 0x00432BC0)\n\n//\t0x00432D70:\t\tInitialiseSlot\n//\t0x00432F80:\t\tCreateZone\n//\t0x00433040:\t\tClearLOT\n\n#endif // LOT_H_INCLUDED\n"
  },
  {
    "path": "game/missile.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/missile.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/control.h\"\n#include \"game/draw.h\"\n#include \"game/effects.h\"\n#include \"game/items.h\"\n#include \"game/sound.h\"\n#include \"game/traps.h\"\n#include \"specific/game.h\"\n#include \"global/vars.h\"\n\nvoid __cdecl ControlMissile(__int16 fxID) {\n\tFX_INFO *fx = &Effects[fxID];\n\n\tif( Effects[fxID].object_number == ID_MISSILE_HARPOON\n\t\t&& !CHK_ANY(RoomInfo[fx->room_number].flags, ROOM_UNDERWATER)\n\t\t&& fx->pos.rotX > -PHD_90*3/4 )\n\t{\n\t\tfx->pos.rotX -= PHD_DEGREE;\n\t}\n\tint speed = fx->speed * phd_cos(fx->pos.rotX) >> W2V_SHIFT;\n\tfx->pos.y += fx->speed * phd_sin(-fx->pos.rotX) >> W2V_SHIFT;\n\tfx->pos.z += speed * phd_cos(fx->pos.rotY) >> W2V_SHIFT;\n\tfx->pos.x += speed * phd_sin(fx->pos.rotY) >> W2V_SHIFT;\n\n\t__int16 roomNumber = fx->room_number;\n\tFLOOR_INFO *floor = GetFloor(fx->pos.x, fx->pos.y, fx->pos.z, &roomNumber);\n\tif( fx->pos.y >= GetHeight(floor, fx->pos.x, fx->pos.y, fx->pos.z)\n\t\t|| (fx->pos.y <= GetCeiling(floor, fx->pos.x, fx->pos.y, fx->pos.z)) )\n\t{\n\t\tif( fx->object_number == ID_MISSILE_KNIFE || fx->object_number == ID_MISSILE_HARPOON ) {\n\t\t\tfx->speed = 0;\n\t\t\tfx->frame_number = -GetRandomControl()/11000;\n\t\t\tfx->counter = 6;\n\t\t\tfx->object_number = ID_RICOCHET;\n\t\t\tPlaySoundEffect(258, &fx->pos, 0);\n\t\t} else if( fx->object_number == ID_MISSILE_FLAME ) {\n\t\t\tAddDynamicLight(fx->pos.x, fx->pos.y, fx->pos.z, 14, 11);\n\t\t\tKillEffect(fxID);\n\t\t}\n\t\treturn;\n\t}\n\n\tif( roomNumber != fx->room_number ) {\n\t\tEffectNewRoom(fxID, roomNumber);\n\t}\n\tif( fx->object_number == ID_MISSILE_FLAME ) {\n\t\tif( ItemNearLara(&fx->pos, 350) ) {\n\t\t\tLaraItem->hitPoints -= 3;\n\t\t\tLaraItem->hit_status = 1;\n\t\t\tLaraBurn();\n\t\t\treturn;\n\t\t}\n\t} else if( ItemNearLara(&fx->pos, 200) ) {\n\t\tLaraItem->hit_status = 1;\n\t\tfx->pos.rotY = LaraItem->pos.rotY;\n\t\tfx->counter = 0;\n\t\tfx->speed = LaraItem->speed;\n\t\tfx->frame_number = 0;\n\t\tif( fx->object_number == ID_MISSILE_KNIFE || fx->object_number == ID_MISSILE_HARPOON ) {\n\t\t\tLaraItem->hitPoints -= 50;\n#ifdef FEATURE_CHEAT\n\t\t\tif( Lara.water_status == LWS_Cheat ) {\n\t\t\t\tfx->frame_number = -GetRandomControl()/11000;\n\t\t\t\tfx->counter = 6;\n\t\t\t\tfx->object_number = ID_RICOCHET;\n\t\t\t\tPlaySoundEffect(258, &fx->pos, 0);\n\t\t\t} else {\n\t\t\t\tfx->object_number = ID_BLOOD;\n\t\t\t\tPlaySoundEffect(317, &fx->pos, 0);\n\t\t\t}\n#else // FEATURE_CHEAT\n\t\t\tfx->object_number = ID_BLOOD;\n\t\t\tPlaySoundEffect(317, &fx->pos, 0);\n#endif // FEATURE_CHEAT\n\t\t}\n\t}\n\n\tif( fx->object_number == ID_MISSILE_HARPOON && CHK_ANY(RoomInfo[fx->room_number].flags, ROOM_UNDERWATER) ) {\n\t\tCreateBubble(&fx->pos, fx->room_number);\n\t} else if( fx->object_number == ID_MISSILE_FLAME && !fx->counter-- ) {\n\t\tAddDynamicLight(fx->pos.x, fx->pos.y, fx->pos.z, 14, 11);\n\t\tPlaySoundEffect(305, &fx->pos, 0);\n\t\tKillEffect(fxID);\n\t} else if( fx->object_number == ID_MISSILE_KNIFE ) {\n\t\tfx->pos.rotZ += 30*PHD_DEGREE;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Missile() {\n\tINJECT(0x00433090, ControlMissile);\n\n//\tINJECT(0x00433360, ShootAtLara);\n//\tINJECT(0x00433410, ExplodingDeath);\n//\tINJECT(0x004337A0, ControlBodyPart);\n}\n"
  },
  {
    "path": "game/missile.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef MISSILE_H_INCLUDED\n#define MISSILE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n\nvoid __cdecl ControlMissile(__int16 fxID); // 0x00433090\n\n// 0x00433360:\t\tShootAtLara\n\n#define ExplodingDeath ((BOOL(__cdecl*)(__int16, DWORD, __int16)) 0x00433410)\n\n// 0x004337A0:\t\tControlBodyPart\n\n#endif // MISSILE_H_INCLUDED\n"
  },
  {
    "path": "game/moveblock.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/moveblock.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_MoveBlock() {\n//\tINJECT(0x004339A0, InitialiseMovingBlock);\n//\tINJECT(0x004339D0, MovableBlock);\n//\tINJECT(0x00433B20, MovableBlockCollision);\n//\tINJECT(0x00433D80, TestBlockMovable);\n//\tINJECT(0x00433DD0, TestBlockPush);\n//\tINJECT(0x00433F20, TestBlockPull);\n//\tINJECT(0x00434160, AlterFloorHeight);\n//\tINJECT(0x00434220, DrawMovableBlock);\n//\tINJECT(0x00434250, DrawUnclippedItem);\n}\n"
  },
  {
    "path": "game/moveblock.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef MOVE_BLOCK_H_INCLUDED\n#define MOVE_BLOCK_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x004339A0:\t\tInitialiseMovingBlock\n\n#define MovableBlock ((void(__cdecl*)(__int16)) 0x004339D0)\n\n//\t0x00433B20:\t\tMovableBlockCollision\n//\t0x00433D80:\t\tTestBlockMovable\n//\t0x00433DD0:\t\tTestBlockPush\n//\t0x00433F20:\t\tTestBlockPull\n\n#define AlterFloorHeight ((void(__cdecl*)(ITEM_INFO *, int)) 0x00434160)\n\n//\t0x00434220:\t\tDrawMovableBlock\n\n#define DrawUnclippedItem ((void(__cdecl*)(ITEM_INFO *)) 0x00434250)\n\n#endif // MOVE_BLOCK_H_INCLUDED\n"
  },
  {
    "path": "game/objects.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/objects.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Objects() {\n//\tINJECT(0x004342C0, EarthQuake);\n//\tINJECT(0x004343A0, ControlCutShotgun);\n//\tINJECT(0x004343E0, InitialiseFinalLevel);\n//\tINJECT(0x004344B0, FinalLevelCounter);\n//\tINJECT(0x004346C0, MiniCopterControl);\n//\tINJECT(0x004347A0, InitialiseDyingMonk);\n//\tINJECT(0x00434820, DyingMonk);\n//\tINJECT(0x004348B0, ControlGongBonger);\n//\tINJECT(0x00434970, DeathSlideCollision);\n//\tINJECT(0x00434A30, ControlDeathSlide);\n//\tINJECT(0x00434CC0, BigBowlControl);\n//\tINJECT(0x00434DB0, BellControl);\n//\tINJECT(0x00434E30, InitialiseWindow);\n//\tINJECT(0x00434EB0, SmashWindow);\n//\tINJECT(0x00434F80, WindowControl);\n//\tINJECT(0x00435020, SmashIceControl);\n//\tINJECT(0x00435100, ShutThatDoor);\n//\tINJECT(0x00435150, OpenThatDoor);\n//\tINJECT(0x00435190, InitialiseDoor);\n//\tINJECT(0x00435570, DoorControl);\n//\tINJECT(0x00435640, OnDrawBridge);\n//\tINJECT(0x00435700, DrawBridgeFloor);\n//\tINJECT(0x00435740, DrawBridgeCeiling);\n//\tINJECT(0x00435780, DrawBridgeCollision);\n//\tINJECT(0x004357B0, InitialiseLift);\n//\tINJECT(0x004357F0, LiftControl);\n//\tINJECT(0x004358D0, LiftFloorCeiling);\n//\tINJECT(0x00435A50, LiftFloor);\n//\tINJECT(0x00435A90, LiftCeiling);\n//\tINJECT(0x00435AD0, BridgeFlatFloor);\n//\tINJECT(0x00435AF0, BridgeFlatCeiling);\n//\tINJECT(0x00435B10, GetOffset);\n//\tINJECT(0x00435B50, BridgeTilt1Floor);\n//\tINJECT(0x00435B80, BridgeTilt1Ceiling);\n//\tINJECT(0x00435BC0, BridgeTilt2Floor);\n//\tINJECT(0x00435BF0, BridgeTilt2Ceiling);\n//\tINJECT(0x00435C30, CopterControl);\n//\tINJECT(0x00435D40, GeneralControl);\n//\tINJECT(0x00435E20, DetonatorControl);\n}\n"
  },
  {
    "path": "game/objects.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef OBJECTS_H_INCLUDED\n#define OBJECTS_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x004342C0:\t\tEarthQuake\n//\t0x004343A0:\t\tControlCutShotgun\n//\t0x004343E0:\t\tInitialiseFinalLevel\n//\t0x004344B0:\t\tFinalLevelCounter\n//\t0x004346C0:\t\tMiniCopterControl\n//\t0x004347A0:\t\tInitialiseDyingMonk\n//\t0x00434820:\t\tDyingMonk\n//\t0x004348B0:\t\tControlGongBonger\n//\t0x00434970:\t\tDeathSlideCollision\n//\t0x00434A30:\t\tControlDeathSlide\n//\t0x00434CC0:\t\tBigBowlControl\n//\t0x00434DB0:\t\tBellControl\n//\t0x00434E30:\t\tInitialiseWindow\n\n#define SmashWindow ((void(__cdecl*)(__int16)) 0x00434EB0)\n\n//\t0x00434F80:\t\tWindowControl\n//\t0x00435020:\t\tSmashIceControl\n//\t0x00435100:\t\tShutThatDoor\n//\t0x00435150:\t\tOpenThatDoor\n//\t0x00435190:\t\tInitialiseDoor\n//\t0x00435570:\t\tDoorControl\n//\t0x00435640:\t\tOnDrawBridge\n//\t0x00435700:\t\tDrawBridgeFloor\n//\t0x00435740:\t\tDrawBridgeCeiling\n//\t0x00435780:\t\tDrawBridgeCollision\n//\t0x004357B0:\t\tInitialiseLift\n//\t0x004357F0:\t\tLiftControl\n//\t0x004358D0:\t\tLiftFloorCeiling\n//\t0x00435A50:\t\tLiftFloor\n//\t0x00435A90:\t\tLiftCeiling\n//\t0x00435AD0:\t\tBridgeFlatFloor\n//\t0x00435AF0:\t\tBridgeFlatCeiling\n//\t0x00435B10:\t\tGetOffset\n//\t0x00435B50:\t\tBridgeTilt1Floor\n//\t0x00435B80:\t\tBridgeTilt1Ceiling\n//\t0x00435BC0:\t\tBridgeTilt2Floor\n//\t0x00435BF0:\t\tBridgeTilt2Ceiling\n//\t0x00435C30:\t\tCopterControl\n//\t0x00435D40:\t\tGeneralControl\n//\t0x00435E20:\t\tDetonatorControl\n\n#endif // OBJECTS_H_INCLUDED\n"
  },
  {
    "path": "game/people.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/people.h\"\n#include \"game/effects.h\"\n#include \"game/items.h\"\n#include \"game/sound.h\"\n#include \"game/sphere.h\"\n#include \"specific/game.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nextern DWORD AlphaBlendMode;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n__int16 __cdecl GunShot(int x, int y, int z, __int16 speed, __int16 rotY, __int16 roomNumber) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tif( AlphaBlendMode ) {\n\t\t__int16 fx_id = CreateEffect(roomNumber);\n\t\tif( fx_id >= 0) {\n\t\t\tFX_INFO *fx = &Effects[fx_id];\n\t\t\tfx->pos.x = x;\n\t\t\tfx->pos.y = y;\n\t\t\tfx->pos.z = z;\n\t\t\tfx->room_number = roomNumber;\n\t\t\tfx->counter = 4;\n\t\t\tfx->speed = 0x400;\n\t\t\tfx->frame_number = 0x200; // this is sprite scale\n\t\t\tfx->fallspeed = 0;\n\t\t\tfx->object_number = ID_GLOW;\n\t\t\tfx->shade = 0x800;\n\t\t\t// NOTE: Core's hacky way to store the sprite flags in the rotation fields\n\t\t\tDWORD flags = GLOW_GUNSHOT_COLOR;\n\t\t\tflags |= SPR_BLEND_ADD|SPR_TINT|SPR_SHADE|SPR_SCALE|SPR_SEMITRANS|SPR_ABS;\n\t\t\tfx->pos.rotX=(UINT16)flags;\n\t\t\tfx->pos.rotY=(UINT16)(flags >> 16);\n\t\t}\n\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t__int16 fx_id = CreateEffect(roomNumber);\n\tif( fx_id >= 0 ) {\n\t\tFX_INFO *fx = &Effects[fx_id];\n\t\tfx->pos.x = x;\n\t\tfx->pos.y = y;\n\t\tfx->pos.z = z;\n\t\tfx->room_number = roomNumber;\n\t\tfx->pos.rotZ = 0;\n\t\tfx->pos.rotX = 0;\n\t\tfx->pos.rotY = rotY;\n\t\tfx->counter = 3;\n\t\tfx->frame_number = 0;\n\t\tfx->object_number = ID_GUN_FLASH;\n\t\tfx->shade = 0x1000;\n\t}\n\treturn fx_id;\n}\n\n__int16 __cdecl GunHit(int x, int y, int z, __int16 speed, __int16 rotY, __int16 roomNumber) {\n\tPHD_VECTOR pos = {0, 0, 0};\n\tGetJointAbsPosition(LaraItem, &pos, GetRandomControl() * 25 / 0x7FFF);\n#ifdef FEATURE_CHEAT\n\tif( Lara.water_status == LWS_Cheat ) {\n\t\t__int16 fxID = CreateEffect(roomNumber);\n\t\tif( fxID >= 0 ) {\n\t\t\tFX_INFO *fx = &Effects[fxID];\n\t\t\tfx->pos.x = pos.x;\n\t\t\tfx->pos.y = pos.y;\n\t\t\tfx->pos.z = pos.z;\n\t\t\tfx->counter = 4;\n\t\t\tfx->object_number = ID_RICOCHET;\n\t\t\tfx->pos.rotY = LaraItem->pos.rotY;\n\t\t\tfx->speed = LaraItem->speed;\n\t\t\tfx->frame_number = -3 * GetRandomDraw() / 0x8000;\n\t\t}\n\t\tPlaySoundEffect(10, &LaraItem->pos, 0);\n\t} else {\n\t\tDoBloodSplat(pos.x, pos.y, pos.z, LaraItem->speed, LaraItem->pos.rotY, LaraItem->roomNumber);\n\t\tPlaySoundEffect(50, &LaraItem->pos, 0);\n\t}\n#else // FEATURE_CHEAT\n\tDoBloodSplat(pos.x, pos.y, pos.z, LaraItem->speed, LaraItem->pos.rotY, LaraItem->roomNumber);\n\tPlaySoundEffect(50, &LaraItem->pos, 0);\n#endif // FEATURE_CHEAT\n\treturn GunShot(x, y, z, speed, rotY, roomNumber);\n}\n\n__int16 __cdecl GunMiss(int x, int y, int z, __int16 speed, __int16 rotY, __int16 roomNumber) {\n\tGAME_VECTOR pos;\n\tpos.x = LaraItem->pos.x + (GetRandomDraw() - 0x4000) * 0x200 / 0x7FFF;\n\tpos.y = LaraItem->floor;\n\tpos.z = LaraItem->pos.z + (GetRandomDraw() - 0x4000) * 0x200 / 0x7FFF;\n\tpos.roomNumber = LaraItem->roomNumber;\n\tRichochet(&pos);\n\treturn GunShot(x, y, z, speed, rotY, roomNumber);\n}\n\n/*\n * Inject function\n */\nvoid Inject_People() {\n//\tINJECT(0x00435EB0, Targetable);\n//\tINJECT(0x00435F40, ControlGlow);\n//\tINJECT(0x00435F80, ControlGunShot);\n\n\tINJECT(0x00435FD0, GunShot);\n\tINJECT(0x00436040, GunHit);\n\tINJECT(0x00436100, GunMiss);\n\n//\tINJECT(0x004361B0, ShotLara);\n//\tINJECT(0x00436380, InitialiseCult1);\n//\tINJECT(0x004363D0, Cult1Control);\n//\tINJECT(0x00436800, InitialiseCult3);\n//\tINJECT(0x00436850, Cult3Control);\n//\tINJECT(0x00436DC0, Worker1Control);\n//\tINJECT(0x004371C0, Worker2Control);\n//\tINJECT(0x00437620, BanditControl);\n//\tINJECT(0x00437960, Bandit2Control);\n//\tINJECT(0x00437DA0, WinstonControl);\n}\n"
  },
  {
    "path": "game/people.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef PEOPLE_H_INCLUDED\n#define PEOPLE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x00435EB0:\t\tTargetable\n//\t0x00435F40:\t\tControlGlow\n//\t0x00435F80:\t\tControlGunShot\n\n__int16 __cdecl GunShot(int x, int y, int z, __int16 speed, __int16 rotY, __int16 roomNumber); // 0x00435FD0\n__int16 __cdecl GunHit(int x, int y, int z, __int16 speed, __int16 rotY, __int16 roomNumber); // 0x00436040\n__int16 __cdecl GunMiss(int x, int y, int z, __int16 speed, __int16 rotY, __int16 roomNumber); // 0x00436100\n\n//\t0x004361B0:\t\tShotLara\n\n#define InitialiseCult1 ((void(__cdecl*)(__int16)) 0x00436380)\n#define Cult1Control ((void(__cdecl*)(__int16)) 0x004363D0)\n#define InitialiseCult3 ((void(__cdecl*)(__int16)) 0x00436800)\n#define Cult3Control ((void(__cdecl*)(__int16)) 0x00436850)\n#define Worker1Control ((void(__cdecl*)(__int16)) 0x00436DC0)\n#define Worker2Control ((void(__cdecl*)(__int16)) 0x004371C0)\n#define BanditControl ((void(__cdecl*)(__int16)) 0x00437620)\n#define Bandit2Control ((void(__cdecl*)(__int16)) 0x00437960)\n#define WinstonControl ((void(__cdecl*)(__int16)) 0x00437DA0)\n\n#endif // PEOPLE_H_INCLUDED\n"
  },
  {
    "path": "game/pickup.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/pickup.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Pickup() {\n//\tINJECT(0x00437F20, PickUpCollision);\n//\tINJECT(0x004383A0, SwitchCollision);\n//\tINJECT(0x004385B0, SwitchCollision2);\n//\tINJECT(0x004386B0, DetonatorCollision);\n//\tINJECT(0x004388F0, KeyHoleCollision);\n//\tINJECT(0x00438B30, PuzzleHoleCollision);\n//\tINJECT(0x00438DF0, SwitchControl);\n//\tINJECT(0x00438E30, SwitchTrigger);\n//\tINJECT(0x00438EF0, KeyTrigger);\n//\tINJECT(0x00438F30, PickupTrigger);\n//\tINJECT(0x00438F70, SecretControl);\n}\n"
  },
  {
    "path": "game/pickup.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef PICKUP_H_INCLUDED\n#define PICKUP_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n\n#define PickUpCollision ((void(__cdecl*)(__int16, ITEM_INFO *, COLL_INFO *)) 0x00437F20)\n\n//\t0x004383A0:\t\tSwitchCollision\n//\t0x004385B0:\t\tSwitchCollision2\n//\t0x004386B0:\t\tDetonatorCollision\n//\t0x004388F0:\t\tKeyHoleCollision\n\n#define PuzzleHoleCollision ((void(__cdecl*)(__int16, ITEM_INFO *, COLL_INFO *)) 0x00438B30)\n\n//\t0x00438DF0:\t\tSwitchControl\n//\t0x00438E30:\t\tSwitchTrigger\n//\t0x00438EF0:\t\tKeyTrigger\n//\t0x00438F30:\t\tPickupTrigger\n//\t0x00438F70:\t\tSecretControl\n\n#endif // PICKUP_H_INCLUDED\n"
  },
  {
    "path": "game/rat.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/rat.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Rat() {\n//\tINJECT(0x00438FA0, MouseControl);\n}\n"
  },
  {
    "path": "game/rat.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef RAT_H_INCLUDED\n#define RAT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define MouseControl ((void(__cdecl*)(__int16)) 0x00438FA0)\n\n#endif // RAT_H_INCLUDED\n"
  },
  {
    "path": "game/savegame.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/savegame.h\"\n#include \"game/control.h\"\n#include \"game/dragon.h\"\n#include \"game/invfunc.h\"\n#include \"game/items.h\"\n#include \"game/laramisc.h\"\n#include \"game/moveblock.h\"\n#include \"game/lot.h\"\n#include \"game/pickup.h\"\n#include \"game/skidoo.h\"\n#include \"game/traps.h\"\n#include \"specific/winmain.h\"\n#include \"global/vars.h\"\n\n#define SGF_CREATURE (0x80)\n\nvoid __cdecl InitialiseStartInfo() {\n#if 0 // NOTE: this original check is removed, because it breaks game+ logic in case of any level selection\n\t// skip initialise if bonus game started\n\tif( SaveGame.bonusFlag )\n\t\treturn;\n#endif\n\n\tfor( int i=0; i<24; ++i ) {\n\t\tSTART_INFO *start = &SaveGame.start[i];\n\n\t\tModifyStartInfo(i);\n\t\tstart->available = 0; // make level not available\n\t\tmemset(&start->statistics, 0, sizeof(STATISTICS_INFO));\n\t}\n\n\tSaveGame.start[0].available = 1; // make assault available\n\tSaveGame.start[1].available = 1; // make new game available\n}\n\nvoid __cdecl ModifyStartInfo(int levelIdx) {\n\tSTART_INFO *start = &SaveGame.start[levelIdx];\n\n\tstart->has_pistols = 1; // Lara has pistols\n\tstart->gunType = LGT_Pistols; // current weapon is pistols\n\tstart->pistolAmmo = 1000; // infinite pistols ammo\n\n\tswitch( levelIdx ) {\n\t\tcase 0 : // Assault (Lara's Home)\n\t\t\tstart->available = 1; // make level available\n\t\t\tstart->has_pistols = 0; // Lara has no weapons\n\t\t\tstart->has_magnums = 0;\n\t\t\tstart->has_uzis = 0;\n\t\t\tstart->has_shotgun = 0;\n\t\t\tstart->has_m16 = 0;\n\t\t\tstart->has_grenade = 0;\n\t\t\tstart->has_harpoon = 0;\n\t\t\tstart->gunType = LGT_Unarmed; // Lara doesn't have weapons\n\t\t\tstart->gunStatus = LGS_Armless; // Lara has no weapons in hands\n\n\t\t\tstart->pistolAmmo\t= 0;\n\t\t\tstart->magnumAmmo\t= 0;\n\t\t\tstart->uziAmmo\t\t= 0;\n\t\t\tstart->shotgunAmmo\t= 0;\n\t\t\tstart->m16Ammo\t\t= 0;\n\t\t\tstart->grenadeAmmo\t= 0;\n\t\t\tstart->harpoonAmmo\t= 0;\n\n\t\t\tstart->flares = 0;\n\t\t\tstart->smallMedipacks = 0;\n\t\t\tstart->largeMedipacks = 0;\n\t\t\tbreak;\n\n\t\tcase 1 : // Regular New Game\n\t\t\tstart->available = 1; // make level available\n\t\t\tstart->has_pistols = 1; // Lara has pistols and shotgun\n\t\t\tstart->has_magnums = 0;\n\t\t\tstart->has_uzis = 0;\n\t\t\tstart->has_shotgun = 1;\n\t\t\tstart->has_m16 = 0;\n\t\t\tstart->has_grenade = 0;\n\t\t\tstart->has_harpoon = 0;\n\t\t\tstart->gunStatus = LGS_Armless; // Lara has no weapons in hands\n\n\t\t\tstart->magnumAmmo\t= 0;\n\t\t\tstart->uziAmmo\t\t= 0;\n\t\t\tstart->shotgunAmmo\t= 12;\n\t\t\tstart->m16Ammo\t\t= 0;\n\t\t\tstart->grenadeAmmo\t= 0;\n\t\t\tstart->harpoonAmmo\t= 0;\n\n\t\t\tstart->flares = 2;\n\t\t\tstart->smallMedipacks = 1;\n\t\t\tstart->largeMedipacks = 1;\n\t\t\tbreak;\n\n\t\t// NOTE: there was no 'default' in the original game, so new game with level selection was broken\n\t\tdefault : // New Game from any other level\n\t\t\tif( SaveGame.start[levelIdx-1].statistics.timer ) break; // no reset if it's not a new game\n\t\t\tstart->available = 1; // make level available\n\t\t\tstart->has_pistols = 1; // Lara has just pistols\n\t\t\tstart->has_magnums = 0;\n\t\t\tstart->has_uzis = 0;\n\t\t\tstart->has_shotgun = 0;\n\t\t\tstart->has_m16 = 0;\n\t\t\tstart->has_grenade = 0;\n\t\t\tstart->has_harpoon = 0;\n\t\t\tstart->gunStatus = LGS_Armless; // Lara has no weapons in hands\n\n\t\t\tstart->magnumAmmo\t= 0;\n\t\t\tstart->uziAmmo\t\t= 0;\n\t\t\tstart->shotgunAmmo\t= 0;\n\t\t\tstart->m16Ammo\t\t= 0;\n\t\t\tstart->grenadeAmmo\t= 0;\n\t\t\tstart->harpoonAmmo\t= 0;\n\n\t\t\tstart->flares = 0;\n\t\t\tstart->smallMedipacks = 0;\n\t\t\tstart->largeMedipacks = 0;\n\t\t\tbreak;\n\t}\n\n\t// Bonus game activated and level is not Assault\n\tif( SaveGame.bonusFlag && levelIdx != 0 ) {\n\t\tstart->available = 1; // make level available\n\t\tstart->has_pistols = 1; // Lara has all weapons\n\t\tstart->has_magnums = 1;\n\t\tstart->has_uzis = 1;\n\t\tstart->has_shotgun = 1;\n\t\tstart->has_m16 = 1;\n\t\tstart->has_grenade = 1;\n\t\tstart->has_harpoon = 1;\n\t\tstart->gunType = LGT_Grenade; // current weapon is grenade launcher\n\n\t\tstart->uziAmmo\t\t= 10001;\n\t\tstart->magnumAmmo\t= 10001;\n\t\tstart->shotgunAmmo\t= 10001;\n\t\tstart->m16Ammo\t\t= 10001;\n\t\tstart->grenadeAmmo\t= 10001;\n\t\tstart->harpoonAmmo\t= 10001;\n\n\t\tstart->flares = 255;\n\t}\n}\n\nvoid __cdecl CreateStartInfo(int levelID) {\n\tSTART_INFO *start = &SaveGame.start[levelID];\n\n\tstart->available = 1;\n\tstart->pistolAmmo = 1000;\n\tstart->has_pistols = Inv_RequestItem(ID_PISTOL_ITEM) ? 1 : 0;\n\n\tif( Inv_RequestItem(ID_MAGNUM_ITEM) ) {\n\t\tstart->magnumAmmo = Lara.magnum_ammo;;\n\t\tstart->has_magnums = 1;\n\t} else {\n\t\tstart->magnumAmmo = 40 * Inv_RequestItem(ID_MAGNUM_AMMO_ITEM);\n\t\tstart->has_magnums = 0;\n\t}\n\n\tif( Inv_RequestItem(ID_UZI_ITEM) ) {\n\t\tstart->uziAmmo = Lara.uzi_ammo;\n\t\tstart->has_uzis = 1;\n\t} else {\n\t\tstart->uziAmmo = 80 * Inv_RequestItem(ID_UZI_AMMO_ITEM);\n\t\tstart->has_uzis = 0;\n\t}\n\n\tif( Inv_RequestItem(ID_SHOTGUN_ITEM) ) {\n\t\tstart->shotgunAmmo = Lara.shotgun_ammo;\n\t\tstart->has_shotgun = 1;\n\t} else {\n\t\tstart->shotgunAmmo = 12 * Inv_RequestItem(ID_SHOTGUN_AMMO_ITEM);\n\t\tstart->has_shotgun = 0;\n\t}\n\n\tif( Inv_RequestItem(ID_HARPOON_ITEM) ) {\n\t\tstart->harpoonAmmo = Lara.harpoon_ammo;\n\t\tstart->has_harpoon = 1;\n\t} else {\n\t\tstart->harpoonAmmo = 3 * Inv_RequestItem(ID_HARPOON_AMMO_ITEM);\n\t\tstart->has_harpoon = 0;\n\t}\n\n\tif( Inv_RequestItem(ID_M16_ITEM) ) {\n\t\tstart->m16Ammo = Lara.m16_ammo;\n\t\tstart->has_m16 = 1;\n\t} else {\n\t\tstart->m16Ammo = 40 * Inv_RequestItem(ID_M16_AMMO_ITEM);\n\t\tstart->has_m16 = 0;\n\t}\n\n\tif( Inv_RequestItem(ID_GRENADE_ITEM) ) {\n\t\tstart->grenadeAmmo = Lara.grenade_ammo;\n\t\tstart->has_grenade = 1;\n\t} else {\n\t\tstart->grenadeAmmo = 2 * Inv_RequestItem(ID_GRENADE_AMMO_ITEM);\n\t\tstart->has_grenade = 0;\n\t}\n\n\tstart->flares = Inv_RequestItem(ID_FLARE_ITEM);\n\tstart->smallMedipacks = Inv_RequestItem(ID_SMALL_MEDIPACK_ITEM);\n\tstart->largeMedipacks = Inv_RequestItem(ID_LARGE_MEDIPACK_ITEM);\n\n\tstart->gunType = ( Lara.gun_type == LGT_Flare ) ? Lara.last_gun_type : Lara.gun_type;\n\tstart->gunStatus = LGS_Armless;\n}\n\nvoid __cdecl CreateSaveGameInfo() {\n\tITEM_INFO *item = NULL;\n\tSaveGame.currentLevel = CurrentLevel;\n\tCreateStartInfo(CurrentLevel);\n\n\tSaveGame.numPickup[0] = Inv_RequestItem(ID_PICKUP_ITEM1);\n\tSaveGame.numPickup[1] = Inv_RequestItem(ID_PICKUP_ITEM2);\n\tSaveGame.numPuzzle[0] = Inv_RequestItem(ID_PUZZLE_ITEM1);\n\tSaveGame.numPuzzle[1] = Inv_RequestItem(ID_PUZZLE_ITEM2);\n\tSaveGame.numPuzzle[2] = Inv_RequestItem(ID_PUZZLE_ITEM3);\n\tSaveGame.numPuzzle[3] = Inv_RequestItem(ID_PUZZLE_ITEM4);\n\tSaveGame.numKey[0] = Inv_RequestItem(ID_KEY_ITEM1);\n\tSaveGame.numKey[1] = Inv_RequestItem(ID_KEY_ITEM2);\n\tSaveGame.numKey[2] = Inv_RequestItem(ID_KEY_ITEM3);\n\tSaveGame.numKey[3] = Inv_RequestItem(ID_KEY_ITEM4);\n\n\tResetSG();\n\tmemset(SaveGame.buffer, 0, sizeof(SaveGame.buffer));\n\n\tWriteSG(&FlipStatus, sizeof(FlipStatus));\n\tfor( DWORD i=0; i<ARRAY_SIZE(FlipMaps); ++i ) {\n\t\tchar flip = FlipMaps[i] >> 8;\n\t\tWriteSG(&flip, sizeof(flip));\n\t}\n\n\tWriteSG(CD_Flags, sizeof(CD_Flags));\n\n\tfor( DWORD i=0; i<CameraCount; ++i ) {\n\t\tWriteSG(&Camera.fixed[i].flags, sizeof(Camera.fixed[i].flags));\n\t}\n\n\tfor( int i=0; i<LevelItemCount; ++i ) {\n\t\titem = &Items[i];\n\t\tOBJECT_INFO *obj = &Objects[item->objectID];\n\t\tif( obj->save_position ) {\n\t\t\tWriteSG(&item->pos, sizeof(item->pos));\n\t\t\tWriteSG(&item->roomNumber, sizeof(item->roomNumber));\n\t\t\tWriteSG(&item->speed, sizeof(item->speed));\n\t\t\tWriteSG(&item->fallSpeed, sizeof(item->fallSpeed));\n\t\t}\n\t\tif( obj->save_anim ) {\n\t\t\tWriteSG(&item->currentAnimState, sizeof(item->currentAnimState));\n\t\t\tWriteSG(&item->goalAnimState, sizeof(item->goalAnimState));\n\t\t\tWriteSG(&item->requiredAnimState, sizeof(item->requiredAnimState));\n\t\t\tWriteSG(&item->animNumber, sizeof(item->animNumber));\n\t\t\tWriteSG(&item->frameNumber, sizeof(item->frameNumber));\n\t\t}\n\t\tif( obj->save_hitpoints ) {\n\t\t\tWriteSG(&item->hitPoints, sizeof(item->hitPoints));\n\t\t}\n\t\tif( obj->save_flags ) {\n\t\t\t__int16 flags = item->flags;\n\t\t\tflags |= item->active | (item->status << 1) | (item->gravity << 3) | (item->collidable << 4);\n\t\t\tif( obj->intelligent && item->data != NULL ) {\n\t\t\t\tflags |= SGF_CREATURE;\n\t\t\t}\n\t\t\tWriteSG(&flags, sizeof(flags));\n\t\t\tif( obj->intelligent ) {\n\t\t\t\tWriteSG(&item->carriedItem, sizeof(item->carriedItem));\n\t\t\t}\n\t\t\tWriteSG(&item->timer, sizeof(item->timer));\n\t\t\tif( CHK_ANY(flags, SGF_CREATURE) ) {\n\t\t\t\tCREATURE_INFO *creature = (CREATURE_INFO *)item->data;\n\t\t\t\tWriteSG(&creature->head_rotation, sizeof(creature->head_rotation));\n\t\t\t\tWriteSG(&creature->neck_rotation, sizeof(creature->neck_rotation));\n\t\t\t\tWriteSG(&creature->maximum_turn, sizeof(creature->maximum_turn));\n\t\t\t\tWriteSG(&creature->flags, sizeof(creature->flags));\n\t\t\t\tWriteSG(&creature->mood, sizeof(creature->mood));\n\t\t\t}\n\t\t}\n\t\tswitch( item->objectID ) {\n\t\t\tcase ID_BOAT:\n\t\t\t\tWriteSG(item->data, sizeof(BOAT_INFO));\n\t\t\t\tbreak;\n\t\t\tcase ID_SKIDOO_FAST:\n\t\t\t\tWriteSG(item->data, sizeof(SKIDOO_INFO));\n\t\t\t\tbreak;\n\t\t\tcase ID_LIFT:\n\t\t\t\tWriteSG(item->data, sizeof(int) * 2);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor( DWORD i=0; i<ARRAY_SIZE(Lara.mesh_ptrs); ++i ) {\n\t\tLara.mesh_ptrs[i] = (__int16 *)((long)Lara.mesh_ptrs[i] - (long)Meshes);\n\t}\n\tLara.left_arm.frame_base = (__int16 *)((long)Lara.left_arm.frame_base - (long)AnimFrames);\n\tLara.right_arm.frame_base = (__int16 *)((long)Lara.right_arm.frame_base - (long)AnimFrames);\n\n\tWriteSG(&Lara, sizeof(Lara));\n\n\tfor( DWORD i=0; i<ARRAY_SIZE(Lara.mesh_ptrs); ++i ) {\n\t\tLara.mesh_ptrs[i] = (__int16 *)((long)Lara.mesh_ptrs[i] + (long)Meshes);\n\t}\n\tLara.left_arm.frame_base = (__int16 *)((long)Lara.left_arm.frame_base + (long)AnimFrames);\n\tLara.right_arm.frame_base = (__int16 *)((long)Lara.right_arm.frame_base + (long)AnimFrames);\n\n\tif( Lara.weapon_item >= 0 ) {\n\t\titem = &Items[Lara.weapon_item];\n\t\tWriteSG(&item->objectID, sizeof(item->objectID));\n\t\tWriteSG(&item->animNumber, sizeof(item->animNumber));\n\t\tWriteSG(&item->frameNumber, sizeof(item->frameNumber));\n\t\tWriteSG(&item->currentAnimState, sizeof(item->currentAnimState));\n\t\tWriteSG(&item->goalAnimState, sizeof(item->goalAnimState));\n\t}\n\n\tWriteSG(&FlipEffect, sizeof(FlipEffect));\n\tWriteSG(&FlipTimer, sizeof(FlipTimer));\n\tWriteSG(&IsMonkAngry, sizeof(IsMonkAngry));\n\n\tint numFlares = 0;\n\tfor( int i=LevelItemCount; i<256; ++i ) {\n\t\titem = &Items[i];\n\t\tif( item->active && item->objectID == ID_FLARE_ITEM ) {\n\t\t\t++numFlares;\n\t\t}\n\t}\n\n\tWriteSG(&numFlares, sizeof(numFlares));\n\n\tfor( int i=LevelItemCount; i<256; ++i ) {\n\t\titem = &Items[i];\n\t\tif( item->active && item->objectID == ID_FLARE_ITEM ) {\n\t\t\tWriteSG(&item->pos, sizeof(item->pos));\n\t\t\tWriteSG(&item->roomNumber, sizeof(item->roomNumber));\n\t\t\tWriteSG(&item->speed,  sizeof(item->speed));\n\t\t\tWriteSG(&item->fallSpeed,  sizeof(item->fallSpeed));\n\t\t\tint flareAge = (int)item->data;\n\t\t\tWriteSG(&flareAge,  sizeof(flareAge));\n\t\t}\n\t}\n}\n\nvoid __cdecl ExtractSaveGameInfo() {\n\tITEM_INFO *item = NULL;\n\tInitialiseLaraInventory(CurrentLevel);\n\tfor( int i=0; i<2; ++i ) {\n\t\tGAME_OBJECT_ID id[] = {ID_PICKUP_ITEM1, ID_PICKUP_ITEM2};\n\t\tfor( int j=0; j<SaveGame.numPickup[i]; ++j ) {\n\t\t\tInv_AddItem(id[i]);\n\t\t}\n\t}\n\tfor( int i=0; i<4; ++i ) {\n\t\tGAME_OBJECT_ID id[] = {ID_PUZZLE_ITEM1, ID_PUZZLE_ITEM2, ID_PUZZLE_ITEM3, ID_PUZZLE_ITEM4};\n\t\tfor( int j=0; j<SaveGame.numPuzzle[i]; ++j ) {\n\t\t\tInv_AddItem(id[i]);\n\t\t}\n\t}\n\tfor( int i=0; i<4; ++i ) {\n\t\tGAME_OBJECT_ID id[] = {ID_KEY_ITEM1, ID_KEY_ITEM2, ID_KEY_ITEM3, ID_KEY_ITEM4};\n\t\tfor( int j=0; j<SaveGame.numKey[i]; ++j ) {\n\t\t\tInv_AddItem(id[i]);\n\t\t}\n\t}\n\n\tResetSG();\n\n\tint flipStatus;\n\tReadSG(&flipStatus, sizeof(flipStatus));\n\tif( flipStatus ) FlipMap();\n\tfor( DWORD i=0; i<ARRAY_SIZE(FlipMaps); ++i ) {\n\t\tchar flip;\n\t\tReadSG(&flip, sizeof(flip));\n\t\tFlipMaps[i] = flip << 8;\n\t}\n\n\tReadSG(CD_Flags, sizeof(CD_Flags));\n\n\tfor( DWORD i=0; i<CameraCount; ++i ) {\n\t\tReadSG(&Camera.fixed[i].flags, sizeof(Camera.fixed[i].flags));\n\t}\n\n\tfor( int i=0; i<LevelItemCount; ++i ) {\n\t\titem = &Items[i];\n\t\tOBJECT_INFO *obj = &Objects[item->objectID];\n\n\t\tif( obj->control == MovableBlock ) {\n\t\t\tAlterFloorHeight(item, 0x400);\n\t\t}\n\t\tif( obj->save_position ) {\n\t\t\t__int16 roomNumber;\n\t\t\tReadSG(&item->pos, sizeof(item->pos));\n\t\t\tReadSG(&roomNumber, sizeof(roomNumber));\n\t\t\tReadSG(&item->speed, sizeof(item->speed));\n\t\t\tReadSG(&item->fallSpeed, sizeof(item->fallSpeed));\n\t\t\tif( item->roomNumber != roomNumber ) {\n\t\t\t\tItemNewRoom(i, roomNumber);\n\t\t\t}\n\t\t\tif( obj->shadowSize ) {\n\t\t\t\tFLOOR_INFO *floor = GetFloor(item->pos.x, item->pos.y, item->pos.z, &roomNumber);\n\t\t\t\titem->floor = GetHeight(floor, item->pos.x, item->pos.y, item->pos.z);\n\t\t\t}\n\t\t}\n\t\tif( obj->save_anim ) {\n\t\t\tReadSG(&item->currentAnimState, sizeof(item->currentAnimState));\n\t\t\tReadSG(&item->goalAnimState, sizeof(item->goalAnimState));\n\t\t\tReadSG(&item->requiredAnimState, sizeof(item->requiredAnimState));\n\t\t\tReadSG(&item->animNumber, sizeof(item->animNumber));\n\t\t\tReadSG(&item->frameNumber, sizeof(item->frameNumber));\n\t\t}\n\t\tif( obj->save_hitpoints ) {\n\t\t\tReadSG(&item->hitPoints, sizeof(item->hitPoints));\n\t\t}\n\t\tif( obj->save_flags ) {\n\t\t\tReadSG(&item->flags, sizeof(item->flags));\n\t\t\tif( obj->intelligent ) {\n\t\t\t\tReadSG(&item->carriedItem, sizeof(item->carriedItem));\n\t\t\t}\n\t\t\tReadSG(&item->timer, sizeof(item->timer));\n\n\t\t\tif( CHK_ANY(item->flags, IFL_CLEARBODY) ) {\n\t\t\t\tKillItem(i);\n\t\t\t\titem->status = ITEM_DISABLED;\n\t\t\t} else {\n\t\t\t\tif( CHK_ANY(item->flags, 0x01) && !item->active ) {\n\t\t\t\t\tAddActiveItem(i);\n\t\t\t\t}\n\t\t\t\titem->status = (item->flags >> 1) & 3;\n\t\t\t\tif( CHK_ANY(item->flags, 0x08) ) {\n\t\t\t\t\titem->gravity = 1;\n\t\t\t\t}\n\t\t\t\tif( !CHK_ANY(item->flags, 0x10) ) {\n\t\t\t\t\titem->collidable = 0;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif( CHK_ANY(item->flags, SGF_CREATURE) ) {\n\t\t\t\tEnableBaddieAI(i, 1);\n\t\t\t\tCREATURE_INFO *creature = (CREATURE_INFO *)item->data;\n\t\t\t\tif( creature != NULL ) {\n\t\t\t\t\tReadSG(&creature->head_rotation, sizeof(creature->head_rotation));\n\t\t\t\t\tReadSG(&creature->neck_rotation, sizeof(creature->neck_rotation));\n\t\t\t\t\tReadSG(&creature->maximum_turn, sizeof(creature->maximum_turn));\n\t\t\t\t\tReadSG(&creature->flags, sizeof(creature->flags));\n\t\t\t\t\tReadSG(&creature->mood, sizeof(creature->mood));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tSG_Point += sizeof(__int16) * 4 + sizeof(MOOD_TYPE);\n\t\t\t\t}\n\t\t\t} else if( obj->intelligent ) {\n\t\t\t\titem->data = NULL;\n\t\t\t\tif( item->clear_body && item->hitPoints <= 0 && !CHK_ANY(item->flags, IFL_CLEARBODY) ) {\n\t\t\t\t\titem->nextActive = PrevItemActive;\n\t\t\t\t\tPrevItemActive = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\titem->flags &= ~0xFF;\n\n\t\t\tif( obj->collision == PuzzleHoleCollision && (item->status == ITEM_ACTIVE || item->status == ITEM_DISABLED) ) {\n\t\t\t\titem->objectID += ID_PUZZLE_DONE1 - ID_PUZZLE_HOLE1;\n\t\t\t}\n\t\t\tif( obj->collision == PickUpCollision && item->status == ITEM_DISABLED ) {\n\t\t\t\tRemoveDrawnItem(i);\n\t\t\t}\n\t\t\tif( (item->objectID == ID_WINDOW1 || item->objectID == ID_WINDOW2) && CHK_ANY(item->flags, IFL_INVISIBLE) ) {\n\t\t\t\titem->meshBits = 0x100;\n\t\t\t}\n\t\t\tif( item->objectID == ID_MINE && CHK_ANY(item->flags, IFL_INVISIBLE) ) {\n\t\t\t\titem->meshBits = 1;\n\t\t\t}\n\t\t}\n\n\t\tif( obj->control == MovableBlock && item->status == ITEM_INACTIVE ) {\n\t\t\tAlterFloorHeight(item, -0x400u);\n\t\t}\n\n\t\tswitch( item->objectID ) {\n\t\t\tcase ID_BOAT:\n\t\t\t\tReadSG(item->data, sizeof(BOAT_INFO));\n\t\t\t\tbreak;\n\t\t\tcase ID_SKIDOO_FAST:\n\t\t\t\tReadSG(item->data, sizeof(SKIDOO_INFO));\n\t\t\t\tbreak;\n\t\t\tcase ID_LIFT:\n\t\t\t\tReadSG(item->data, sizeof(int) * 2);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t\tif( item->objectID == ID_SKIDMAN && item->status == ITEM_DISABLED ) {\n\t\t\tItems[(int)item->data].objectID = ID_SKIDOO_FAST;\n\t\t\tInitialiseSkidoo((int)item->data);\n\t\t}\n\n\t\tif( item->objectID == ID_DRAGON_FRONT && item->status == ITEM_DISABLED ) {\n\t\t\titem->pos.y -= 1010;\n\t\t\tDragonBones(i);\n\t\t\titem->pos.y += 1010;\n\t\t}\n\t}\n\n\tReadSG(&Lara, sizeof(Lara));\n\tLara.creature = NULL;\n\tLara.spaz_effect = NULL;\n\tLara.target = NULL;\n\n\tfor( DWORD i=0; i<ARRAY_SIZE(Lara.mesh_ptrs); ++i ) {\n\t\tLara.mesh_ptrs[i] = (__int16 *)((long)Lara.mesh_ptrs[i] + (long)Meshes);\n\t}\n\tLara.left_arm.frame_base = (__int16 *)((long)Lara.left_arm.frame_base + (long)AnimFrames);\n\tLara.right_arm.frame_base = (__int16 *)((long)Lara.right_arm.frame_base + (long)AnimFrames);\n\n\tif( Lara.weapon_item >= 0 ) {\n\t\tLara.weapon_item = CreateItem();\n\t\titem = &Items[Lara.weapon_item];\n\t\tReadSG(&item->objectID, sizeof(item->objectID));\n\t\tReadSG(&item->animNumber, sizeof(item->animNumber));\n\t\tReadSG(&item->frameNumber, sizeof(item->frameNumber));\n\t\tReadSG(&item->currentAnimState, sizeof(item->currentAnimState));\n\t\tReadSG(&item->goalAnimState, sizeof(item->goalAnimState));\n\t\titem->status = ITEM_ACTIVE;\n\t\titem->roomNumber = 0xFF;\n\t}\n\n\tif( Lara.burn ) {\n\t\tLara.burn = 0;\n\t\tLaraBurn();\n\t}\n\n\tReadSG(&FlipEffect, sizeof(FlipEffect));\n\tReadSG(&FlipTimer, sizeof(FlipTimer));\n\tReadSG(&IsMonkAngry, sizeof(IsMonkAngry));\n\n\tint numFlares = 0;\n\tReadSG(&numFlares, sizeof(numFlares));\n\tfor( int i=0; i<numFlares; ++i ) {\n\t\t__int16 itemID = CreateItem();\n\t\titem = &Items[itemID];\n\t\titem->objectID = ID_FLARE_ITEM;\n\t\tReadSG(&item->pos, sizeof(item->pos));\n\t\tReadSG(&item->roomNumber, sizeof(item->roomNumber));\n\t\tReadSG(&item->speed,  sizeof(item->speed));\n\t\tReadSG(&item->fallSpeed,  sizeof(item->fallSpeed));\n\t\tInitialiseItem(itemID);\n\t\tAddActiveItem(itemID);\n\t\tint flareAge;\n\t\tReadSG(&flareAge, sizeof(flareAge));\n\t\titem->data = (LPVOID)flareAge;\n\t}\n}\n\nvoid __cdecl ResetSG() {\n\tSG_Count = 0;\n\tSG_Point = SaveGame.buffer;\n}\n\nvoid __cdecl WriteSG(void *ptr, int len) {\n\tSG_Count += len;\n\tif( SG_Count >= sizeof(SaveGame.buffer) ) {\n\t\tS_ExitSystem(\"FATAL: Savegame is too big to fit in buffer\");\n\t}\n\tmemcpy(SG_Point, ptr, len);\n\tSG_Point += len;\n}\n\nvoid __cdecl ReadSG(void *ptr, int len) {\n\tSG_Count += len;\n\tmemcpy(ptr, SG_Point, len);\n\tSG_Point += len;\n}\n\n/*\n * Inject function\n */\nvoid Inject_SaveGame() {\n\tINJECT(0x00439190, InitialiseStartInfo);\n\tINJECT(0x00439200, ModifyStartInfo);\n\tINJECT(0x004392E0, CreateStartInfo);\n\tINJECT(0x004394F0, CreateSaveGameInfo);\n\tINJECT(0x00439A20, ExtractSaveGameInfo);\n\tINJECT(0x0043A280, ResetSG);\n\tINJECT(0x0043A2A0, WriteSG);\n\tINJECT(0x0043A2F0, ReadSG);\n}\n"
  },
  {
    "path": "game/savegame.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SAVEGAME_H_INCLUDED\n#define SAVEGAME_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl InitialiseStartInfo(); // 0x00439190\nvoid __cdecl ModifyStartInfo(int levelIdx); // 0x00439200\nvoid __cdecl CreateStartInfo(int levelID); // 0x004392E0\nvoid __cdecl CreateSaveGameInfo(); // 0x004394F0\nvoid __cdecl ExtractSaveGameInfo(); // 0x00439A20\nvoid __cdecl ResetSG(); // 0x0043A280\nvoid __cdecl WriteSG(void *ptr, int len); // 0x0043A2A0\nvoid __cdecl ReadSG(void *ptr, int len); // 0x0043A2F0\n\n#endif // SAVEGAME_H_INCLUDED\n"
  },
  {
    "path": "game/setup.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/setup.h\"\n#include \"game/bear.h\"\n#include \"game/bird.h\"\n#include \"game/collide.h\"\n#include \"game/diver.h\"\n#include \"game/dog.h\"\n#include \"game/dragon.h\"\n#include \"game/draw.h\"\n#include \"game/eel.h\"\n#include \"game/enemies.h\"\n#include \"game/hair.h\"\n#include \"game/laramisc.h\"\n#include \"game/moveblock.h\"\n#include \"game/people.h\"\n#include \"game/rat.h\"\n#include \"game/shark.h\"\n#include \"game/skidoo.h\"\n#include \"game/spider.h\"\n#include \"game/wolf.h\"\n#include \"game/yeti.h\"\n#include \"specific/winmain.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_GOLD\nextern bool IsGold();\n#endif\n\nvoid __cdecl InitialiseLevelFlags() {\n\tmemset(&SaveGame.statistics, 0, sizeof(STATISTICS_INFO));\n}\n\nvoid __cdecl InitialiseObjects() {\n\tfor( int i = 0; i < ID_NUMBER_OBJECTS; ++i ) {\n\t\tObjects[i].intelligent = 0;\n\t\tObjects[i].save_position = 0;\n\t\tObjects[i].save_hitpoints = 0;\n\t\tObjects[i].save_flags = 0;\n\t\tObjects[i].save_anim = 0;\n\t\tObjects[i].water_creature = 0;\n\t\tObjects[i].initialise = NULL;\n\t\tObjects[i].collision = NULL;\n\t\tObjects[i].control = NULL;\n\t\tObjects[i].drawRoutine = DrawAnimatingItem;\n\t\tObjects[i].ceiling = NULL;\n\t\tObjects[i].floor = NULL;\n\t\tObjects[i].pivotLength = 0;\n\t\tObjects[i].radius = 10;\n\t\tObjects[i].shadowSize = 0;\n\t\tObjects[i].hitPoints = HP_DONT_TARGET;\n\t}\n\tBaddyObjects();\n\tTrapObjects();\n\tObjectObjects();\n\tInitialiseHair();\n}\n\nvoid __cdecl BaddyObjects() {\n\tOBJECT_INFO *obj;\n\n\t// Lara object is mandatory\n\tobj = &Objects[ID_LARA];\n\tobj->initialise = InitialiseLaraLoad;\n\tobj->shadowSize = 160;\n\tobj->hitPoints = 1000;\n\tobj->drawRoutine = DrawDummyItem;\n\tobj->save_position = 1;\n\tobj->save_hitpoints = 1;\n\tobj->save_flags = 1;\n\tobj->save_anim = 1;\n\tobj->control = ControlLaraExtra;\n\n\t// Other objects are optional\n\tobj = &Objects[ID_DOG];\n\tif( obj->loaded ) {\n\t\tobj->control = DogControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 10;\n\t\tobj->pivotLength = 300;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->radius = 341;\n\t\tAnimBones[obj->boneIndex + 19*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_MOUSE];\n\tif( obj->loaded ) {\n\t\tobj->control = MouseControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 4;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 50;\n\t\tobj->radius = 102;\n\t\tAnimBones[obj->boneIndex + 3*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_CULT1];\n\tif( obj->loaded ) {\n\t\tobj->initialise = InitialiseCult1;\n\t\tobj->control = Cult1Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->hitPoints = 25;\n\t\tobj->pivotLength = 50;\n\t\tobj->radius = 102;\n\t\tAnimBones[obj->boneIndex + 0*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_CULT1A];\n\tif( obj->loaded ) {\n\t\tif( !Objects[ID_CULT1].loaded ) {\n\t\t\tS_ExitSystem(\"FATAL: CULT1A requires CULT1\"); // NOTE: there was a typo: CULT1B instead of CULT1A\n\t\t}\n\t\tobj->frameBase = Objects[ID_CULT1].frameBase;\n\t\tobj->animIndex = Objects[ID_CULT1].animIndex;\n\t\tobj->initialise = InitialiseCult1;\n\t\tobj->control = Cult1Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 25;\n\t\tobj->pivotLength = 50;\n\t\tobj->radius = 102;\n\t\tAnimBones[obj->boneIndex + 0*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_CULT1B];\n\tif( obj->loaded ) {\n\t\tif( !Objects[ID_CULT1].loaded ) {\n\t\t\tS_ExitSystem(\"FATAL: CULT1B requires CULT1\");\n\t\t}\n\t\tobj->frameBase = Objects[ID_CULT1].frameBase;\n\t\tobj->animIndex = Objects[ID_CULT1].animIndex;\n\t\tobj->initialise = InitialiseCult1;\n\t\tobj->control = Cult1Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 25;\n\t\tobj->pivotLength = 50;\n\t\tobj->radius = 102;\n\t\tAnimBones[obj->boneIndex + 0*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_CULT2];\n\tif( obj->loaded ) {\n\t\tobj->control = Cult2Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 60;\n\t\tobj->pivotLength = 50;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->radius = 102;\n\t\tAnimBones[obj->boneIndex + 0*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 8*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_SHARK];\n\tif( obj->loaded ) {\n\t\tobj->control = SharkControl;\n\t\tobj->drawRoutine = DrawUnclippedItem;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 30;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->water_creature = 1;\n\t\tobj->pivotLength = 200;\n\t\tobj->radius = 341;\n\t\tAnimBones[obj->boneIndex + 9*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_TIGER];\n\tif( obj->loaded ) {\n\t\tobj->control = TigerControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 20;\n\t\tobj->pivotLength = 200;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->radius = 341;\n\t\tAnimBones[obj->boneIndex + 21*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_BARRACUDA];\n\tif( obj->loaded ) {\n\t\tobj->control = BaracuddaControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 12;\n\t\tobj->pivotLength = 200;\n\t\tobj->radius = 204;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->water_creature = 1;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_SPIDER_or_WOLF];\n\tif( obj->loaded ) {\n#ifdef FEATURE_GOLD\n\t\tobj->initialise = IsGold() ? InitialiseWolf : NULL;\n\t\tobj->control = IsGold() ? WolfControl : SpiderControl;\n\t\tobj->hitPoints = IsGold() ? 10 : 5;\n\t\tobj->radius = IsGold() ? 341 : 102;\n#else\n\t\tobj->control = SpiderControl;\n\t\tobj->hitPoints = 5;\n\t\tobj->radius = 102;\n#endif\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t}\n\tobj = &Objects[ID_BIG_SPIDER_or_BEAR];\n\tif( obj->loaded ) {\n#ifdef FEATURE_GOLD\n\t\tobj->control = IsGold() ? BearControl : BigSpiderControl;\n\t\tobj->hitPoints = IsGold() ? 30 : 40;\n#else\n\t\tobj->control = BigSpiderControl;\n\t\tobj->hitPoints = 40;\n#endif\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->radius = 341;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t}\n\tobj = &Objects[ID_YETI];\n\tif( obj->loaded ) {\n\t\tobj->control = YetiControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 30;\n\t\tobj->radius = 128;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 100;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 14*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_JELLY];\n\tif( obj->loaded ) {\n\t\tobj->control = JellyControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 10;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->water_creature = 1;\n\t}\n\tobj = &Objects[ID_DIVER];\n\tif( obj->loaded ) {\n\t\tobj->control = DiverControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 20;\n\t\tobj->radius = 341;\n\t\tobj->pivotLength = 50;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->water_creature = 1;\n\t\tAnimBones[obj->boneIndex + 10*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 14*4] |= 0x10;\n\t}\n\tobj = &Objects[ID_WORKER1];\n\tif( obj->loaded ) {\n\t\tobj->control = Worker1Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 25;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 4*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 13*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_WORKER2];\n\tif( obj->loaded ) {\n\t\tobj->control = Worker2Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 20;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 4*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 13*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_WORKER3];\n\tif( obj->loaded ) {\n\t\tobj->control = Worker3Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 27;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 0*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 4*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_WORKER4];\n\tif( obj->loaded ) {\n\t\tobj->hitPoints = 27;\n\t\tobj->control = Worker3Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->radius = 102;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 0*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 4*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_WORKER5];\n\tif( obj->loaded ) {\n\t\tobj->control = Worker2Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 20;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 4*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 13*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_CULT3];\n\tif( obj->loaded ) {\n\t\tobj->initialise = InitialiseCult3;\n\t\tobj->control = Cult3Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 150;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t}\n\tobj = &Objects[ID_MONK1];\n\tif( obj->loaded ) {\n\t\tobj->control = MonkControl;\n\t\tobj->collision = CreatureCollision;\n#ifdef FEATURE_GOLD\n\t\tobj->shadowSize = IsGold() ? 0 : 128;\n#else\n\t\tobj->shadowSize = 128;\n#endif\n\t\tobj->hitPoints = 30;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_MONK2];\n\tif( obj->loaded ) {\n\t\tobj->control = MonkControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 30;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_EAGLE];\n\tif( obj->loaded ) {\n\t\tobj->initialise = InitialiseEagle;\n\t\tobj->control = EagleControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 20;\n\t\tobj->radius = 204;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t}\n\tobj = &Objects[ID_CROW];\n\tif( obj->loaded ) {\n\t\tobj->initialise = InitialiseEagle;\n\t\tobj->control = EagleControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 15;\n\t\tobj->radius = 204;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t}\n\tobj = &Objects[ID_BIG_EEL];\n\tif( obj->loaded ) {\n\t\tobj->control = BigEelControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->hitPoints = 20;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->water_creature = 1;\n\t}\n\tobj = &Objects[ID_EEL];\n\tif( obj->loaded ) {\n\t\tobj->control = EelControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->hitPoints = 5;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->water_creature = 1;\n\t}\n\tobj = &Objects[ID_BANDIT1];\n\tif( obj->loaded ) {\n\t\tobj->control = BanditControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 45;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 8*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_BANDIT2];\n\tif( obj->loaded ) {\n\t\tobj->control = Bandit2Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 50;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 8*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_BANDIT2B];\n\tif( obj->loaded ) {\n\t\tif( !Objects[ID_BANDIT2].loaded ) {\n\t\t\tS_ExitSystem(\"FATAL: BANDIT2B requires BANDIT2\");\n\t\t}\n\t\tobj->frameBase = Objects[ID_BANDIT2].frameBase;\n\t\tobj->animIndex = Objects[ID_BANDIT2].animIndex;\n\t\tobj->control = Bandit2Control;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->hitPoints = 50;\n\t\tobj->radius = 102;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 8*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_SKIDOO_ARMED];\n\tif( obj->loaded ) {\n\t\tobj->drawRoutine = DrawSkidoo;\n\t\tobj->collision = SkidmanCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->hitPoints = 100;\n\t\tobj->radius = 341;\n\t\tobj->pivotLength = 0;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t}\n\tobj = &Objects[ID_SKIDMAN];\n\tif( obj->loaded ) {\n\t\tobj->initialise = InitialiseSkidman;\n\t\tobj->control = SkidManControl;\n\t\tobj->hitPoints = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t}\n\tobj = &Objects[ID_XIAN_LORD];\n\tif( obj->loaded ) {\n\t\tif( !Objects[ID_CHINESE2].loaded ) {\n\t\t\tS_ExitSystem(\"FATAL: XianLord requires CHINESE2 (statue)\");\n\t\t}\n\t\tobj->initialise = InitialiseXianLord;\n\t\tobj->drawRoutine = DrawXianLord;\n\t\tobj->control = XianLordControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->hitPoints = 100;\n\t\tobj->radius = 204;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 12*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_WARRIOR];\n\tif( obj->loaded ) {\n\t\tif( !Objects[ID_CHINESE4].loaded ) {\n\t\t\tS_ExitSystem(\"FATAL: Warrior requires CHINESE4 (statue)\");\n\t\t}\n\t\tobj->drawRoutine = DrawXianLord;\n\t\tobj->initialise = InitialiseXianLord;\n\t\tobj->control = WarriorControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->shadowSize = 128;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->hitPoints = 80;\n\t\tobj->radius = 204;\n\t\tobj->pivotLength = 0;\n\t\tAnimBones[obj->boneIndex + 6*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 16*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_DRAGON_FRONT];\n\tif( obj->loaded ) {\n\t\tif( !Objects[ID_DRAGON_BACK].loaded ) {\n\t\t\tS_ExitSystem(\"FATAL: Dragon front needs back\");\n\t\t}\n\t\tobj->hitPoints = 300;\n\t\tobj->pivotLength = 300;\n\t\tobj->control = DragonControl;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->collision = DragonCollision;\n\t\tobj->radius = 341;\n\t\tAnimBones[obj->boneIndex + 10*4] |= 0x10;\n\t}\n\tobj = &Objects[ID_DRAGON_BACK];\n\tif( obj->loaded ) {\n\t\tobj->control = DragonControl;\n\t\tobj->collision = DragonCollision;\n\t\tobj->radius = 341;\n\t\tobj->save_position = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t}\n\tobj = &Objects[ID_BARTOLI];\n\tif( obj->loaded ) {\n\t\tobj->initialise = InitialiseBartoli;\n\t\tobj->control = BartoliControl;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t}\n\tobj = &Objects[ID_GIANT_YETI];\n\tif( obj->loaded ) {\n\t\tobj->control = GiantYetiControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->hitPoints = 200;\n\t\tobj->radius = 341;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tAnimBones[obj->boneIndex + 14*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_DINO];\n\tif( obj->loaded ) {\n\t\tobj->control = DinoControl;\n\t\tobj->collision = CreatureCollision;\n\t\tobj->hitPoints = 100;\n\t\tobj->shadowSize = 64;\n\t\tobj->pivotLength = 1800;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_hitpoints = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t\tobj->radius = 341;\n\t\tAnimBones[obj->boneIndex + 10*4] |= 0x08;\n\t\tAnimBones[obj->boneIndex + 11*4] |= 0x08;\n\t}\n\tobj = &Objects[ID_WINSTON];\n\tif( obj->loaded ) {\n\t\tobj->control = WinstonControl;\n\t\tobj->collision = ObjectCollision;\n\t\tobj->hitPoints = HP_DONT_TARGET;\n\t\tobj->shadowSize = 64;\n\t\tobj->radius = 102;\n\t\tobj->intelligent = 1;\n\t\tobj->save_position = 1;\n\t\tobj->save_flags = 1;\n\t\tobj->save_anim = 1;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Setup() {\n//\tINJECT(0x0043A330, InitialiseLevel);\n//\tINJECT(0x0043A490, InitialiseGameFlags);\n\n\tINJECT(0x0043A500, InitialiseLevelFlags);\n\tINJECT(0x0043A530, BaddyObjects);\n\n//\tINJECT(0x0043B570, TrapObjects);\n//\tINJECT(0x0043BB70, ObjectObjects);\n\n\tINJECT(0x0043C7C0, InitialiseObjects);\n\n//\tINJECT(0x0043C830, GetCarriedItems);\n}\n"
  },
  {
    "path": "game/setup.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SETUP_H_INCLUDED\n#define SETUP_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define InitialiseLevel ((BOOL(__cdecl*)(int,int)) 0x0043A330)\n\n// 0x0043A490:\t\tInitialiseGameFlags\n\nvoid __cdecl InitialiseLevelFlags(); // 0x0043A500\nvoid __cdecl BaddyObjects(); // 0x0043A530\n\n#define TrapObjects ((void(__cdecl*)(void)) 0x0043B570)\n#define ObjectObjects ((void(__cdecl*)(void)) 0x0043BB70)\n\nvoid __cdecl InitialiseObjects(); // 0x0043C7C0\n\n// 0x0043C830:\t\tGetCarriedItems\n\n#endif // SETUP_H_INCLUDED\n"
  },
  {
    "path": "game/shark.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/shark.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Shark() {\n//\tINJECT(0x0043C900, JellyControl);\n//\tINJECT(0x0043CA20, BaracuddaControl);\n//\tINJECT(0x0043CC50, SharkControl);\n}\n"
  },
  {
    "path": "game/shark.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SHARK_H_INCLUDED\n#define SHARK_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define JellyControl ((void(__cdecl*)(__int16)) 0x0043C900)\n#define BaracuddaControl ((void(__cdecl*)(__int16)) 0x0043CA20)\n#define SharkControl ((void(__cdecl*)(__int16)) 0x0043CC50)\n\n#endif // SHARK_H_INCLUDED\n"
  },
  {
    "path": "game/skidoo.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/skidoo.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/box.h\"\n#include \"game/draw.h\"\n#include \"game/items.h\"\n#include \"game/larafire.h\"\n#include \"game/missile.h\"\n#include \"game/people.h\"\n#include \"game/sound.h\"\n#include \"specific/game.h\"\n#include \"specific/output.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\nstatic BITE_INFO SkidooLeftGun = {219, -71, 550, 0};\nstatic BITE_INFO SkidooRightGun = {-235, -71, 550, 0};\n\nvoid __cdecl DoSnowEffect(ITEM_INFO *item) {\n\t__int16 fxID;\n\tFX_INFO *fx;\n\tint displacement;\n\n\tfxID = CreateEffect(item->roomNumber);\n\tif (fxID != -1) {\n\t\tfx = &Effects[fxID];\n\t\tdisplacement = 260 * (GetRandomDraw() - 16384) >> 14;\n\t\tfx->pos.x = item->pos.x - ((500 * phd_sin(item->pos.rotY) + displacement * phd_cos(item->pos.rotY)) >> W2V_SHIFT);\n\t\tfx->pos.y = item->pos.y + (500 * phd_sin(item->pos.rotX) >> W2V_SHIFT);\n\t\tfx->pos.z = item->pos.z - ((500 * phd_cos(item->pos.rotY) - displacement * phd_sin(item->pos.rotY)) >> W2V_SHIFT);\n\t\tfx->room_number = item->roomNumber;\n\t\tfx->frame_number = 0;\n\t\tfx->object_number = ID_SNOW_SPRITE;\n\t\tfx->speed = 0;\n\t\tif (item->speed < 64) {\n\t\t\tfx->fallspeed = (ABS(item->speed) - 64) * GetRandomDraw() >> 15;\n\t\t} else {\n\t\t\tfx->fallspeed = 0;\n\t\t}\n\t\tPhdMatrixPtr->_23 = 0;\n\t\tS_CalculateLight(fx->pos.x, fx->pos.y, fx->pos.z, fx->room_number);\n\t\tfx->shade = LsAdder - 512;\n\t\tCLAMPL(fx->shade, 0);\n\t}\n}\n\nvoid __cdecl SkidooExplode(ITEM_INFO *item) {\n\t__int16 fxID;\n\tFX_INFO *fx;\n\n\tfxID = CreateEffect(item->roomNumber);\n\tif (fxID != -1) {\n\t\tfx = &Effects[fxID];\n\t\tfx->pos.x = item->pos.x;\n\t\tfx->pos.y = item->pos.y;\n\t\tfx->pos.z = item->pos.z;\n\t\tfx->speed = 0;\n\t\tfx->frame_number = 0;\n\t\tfx->counter = 0;\n\t\tfx->object_number = ID_EXPLOSION;\n\t}\n\tExplodingDeath(Lara.skidoo, ~3, 0);\n\tPlaySoundEffect(105, NULL, 0);\n\tLara.skidoo = -1;\n#ifdef FEATURE_INPUT_IMPROVED\n\tJoyRumbleExplode(LaraItem->pos.x, LaraItem->pos.y, LaraItem->pos.z, 0x1400, true);\n#endif // FEATURE_INPUT_IMPROVED\n}\n\nvoid __cdecl SkidooGuns() {\n\tWEAPON_INFO *weapon = &Weapons[LGT_Skidoo];\n\tLaraGetNewTarget(weapon);\n\tAimWeapon(weapon, &Lara.right_arm);\n\n\tif( CHK_ANY(InputStatus, IN_ACTION) ) {\n\t\t__int16 angles[2];\n\t\tangles[0] = Lara.right_arm.y_rot + LaraItem->pos.rotY;\n\t\tangles[1] = Lara.right_arm.x_rot;\n\t\tif( FireWeapon(LGT_Skidoo, Lara.target, LaraItem, angles) ) {\n\t\t\tLara.right_arm.flash_gun = weapon->flashTime;\n\t\t\tPlaySoundEffect(weapon->sampleNum, &LaraItem->pos, 0);\n\t\t\tint x = LaraItem->pos.x + (phd_sin(LaraItem->pos.rotY) >> (W2V_SHIFT-10));\n\t\t\tint y = LaraItem->pos.y - 0x200;\n\t\t\tint z = LaraItem->pos.z + (phd_cos(LaraItem->pos.rotY) >> (W2V_SHIFT-10));\n\t\t\tAddDynamicLight(x, y, z, 12, 11);\n\t\t\tCreatureEffect(&Items[Lara.skidoo], &SkidooLeftGun, GunShot);\n\t\t\tCreatureEffect(&Items[Lara.skidoo], &SkidooRightGun, GunShot);\n#ifdef FEATURE_INPUT_IMPROVED\n\t\t\tJoyVibrate(0x400, 0x400, 2, 0x80, 4, false);\n#endif // FEATURE_INPUT_IMPROVED\n\t\t}\n\t}\n}\n\nvoid __cdecl DrawSkidoo(ITEM_INFO *item) {\n\t__int16 *frames[2];\n\tint rate = 0;\n\tUINT16 flags = 0;\n\tOBJECT_INFO *obj;\n\n\tint frac = GetFrames(item, frames, &rate);\n\tif( item->data ) {\n\t\tflags = *(UINT16 *)item->data;\n\t}\n\tif( CHK_ANY(flags, 4) ) {\n\t\tobj = &Objects[ID_SKIDOO_ARMED];\n\t} else {\n\t\tobj = &Objects[item->objectID];\n\t}\n\n\tphd_PushMatrix();\n\tphd_TranslateAbs(item->pos.x, item->pos.y, item->pos.z);\n\tphd_RotYXZ(item->pos.rotY, item->pos.rotX, item->pos.rotZ);\n\tint clip = S_GetObjectBounds(frames[0]);\n\n\tif( clip ) {\n\t\tCalculateObjectLighting(item, frames[0]);\n\n\t\t__int16 **track = 0;\n\t\t__int16 **meshPtr = &MeshPtr[obj->meshIndex];\n\t\tint *bonePtr = &AnimBones[obj->boneIndex];\n\t\tif( (flags & 3) == 1 ) {\n\t\t\ttrack = &MeshPtr[Objects[ID_SKIDOO_LARA].meshIndex + 1];\n\t\t} else if( (flags & 3) == 2 ) {\n\t\t\ttrack = &MeshPtr[Objects[ID_SKIDOO_LARA].meshIndex + 7];\n\t\t}\n\n\t\tif( frac ) {\n\t\t\tUINT16 *rot1 = (UINT16 *)&frames[0][9];\n\t\t\tUINT16 *rot2 = (UINT16 *)&frames[1][9];\n\t\t\tInitInterpolate(frac, rate);\n\t\t\tphd_TranslateRel_ID(frames[0][6], frames[0][7], frames[0][8], frames[1][6], frames[1][7], frames[1][8]);\n\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tSetMeshReflectState(CHK_ANY(flags, 4) ? (int)ID_SKIDOO_ARMED : item->objectID, 0);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\tphd_PutPolygons_I(meshPtr[0], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\t\t\tfor( int i = 1; i < obj->nMeshes; ++i ) {\n\t\t\t\tDWORD state = *bonePtr;\n\t\t\t\tif( CHK_ANY(state, 1) ) {\n\t\t\t\t\tphd_PopMatrix_I();\n\t\t\t\t}\n\t\t\t\tif( CHK_ANY(state, 2) ) {\n\t\t\t\t\tphd_PushMatrix_I();\n\t\t\t\t}\n\t\t\t\tphd_TranslateRel_I(bonePtr[1], bonePtr[2], bonePtr[3]);\n\t\t\t\tphd_RotYXZsuperpack_I(&rot1, &rot2, 0);\n\t\t\t\tif( track ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tSetMeshReflectState(ID_SKIDOO_LARA, (flags & 3) == 1 ? 1 : 7);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tphd_PutPolygons_I(*track, clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\ttrack = NULL;\n\t\t\t\t} else {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tSetMeshReflectState(CHK_ANY(flags, 4) ? (int)ID_SKIDOO_ARMED : item->objectID, i);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tphd_PutPolygons_I(meshPtr[i], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t}\n\t\t\t\tbonePtr += 4;\n\t\t\t}\n\t\t} else {\n\t\t\tUINT16 *rot = (UINT16 *)&frames[0][9];\n\t\t\tphd_TranslateRel(frames[0][6], frames[0][7], frames[0][8]);\n\t\t\tphd_RotYXZsuperpack(&rot, 0);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tSetMeshReflectState(CHK_ANY(flags, 4) ? (int)ID_SKIDOO_ARMED : item->objectID, 0);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\tphd_PutPolygons(meshPtr[0], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\t\t\tfor( int i = 1; i < obj->nMeshes; ++i ) {\n\t\t\t\tDWORD state = *bonePtr;\n\t\t\t\tif( CHK_ANY(state, 1) ) {\n\t\t\t\t\tphd_PopMatrix();\n\t\t\t\t}\n\t\t\t\tif( CHK_ANY(state, 2) ) {\n\t\t\t\t\tphd_PushMatrix();\n\t\t\t\t}\n\t\t\t\tphd_TranslateRel(bonePtr[1], bonePtr[2], bonePtr[3]);\n\t\t\t\tphd_RotYXZsuperpack(&rot, 0);\n\t\t\t\tif( track ) {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tSetMeshReflectState(ID_SKIDOO_LARA, (flags & 3) == 1 ? 1 : 7);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tphd_PutPolygons(*track, clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\ttrack = NULL;\n\t\t\t\t} else {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tSetMeshReflectState(CHK_ANY(flags, 4) ? (int)ID_SKIDOO_ARMED : item->objectID, i);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tphd_PutPolygons(meshPtr[i], clip);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t\tClearMeshReflectState();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t\t\t}\n\t\t\t\tbonePtr += 4;\n\t\t\t}\n\t\t}\n\t}\n\tphd_PopMatrix();\n}\n\n/*\n * Inject function\n */\nvoid Inject_Skidoo() {\n//\tINJECT(0x0043CEE0, InitialiseSkidoo);\n//\tINJECT(0x0043CF20, SkidooCheckGeton);\n//\tINJECT(0x0043D010, SkidooCollision);\n//\tINJECT(0x0043D110, SkidooBaddieCollision);\n//\tINJECT(0x0043D310, TestHeight);\n//\tINJECT(0x0043D3D0, DoShift);\n//\tINJECT(0x0043D650, DoDynamics);\n//\tINJECT(0x0043D6B0, GetCollisionAnim);\n\n\tINJECT(0x0043D740, DoSnowEffect);\n\n//\tINJECT(0x0043D880, SkidooDynamics);\n//\tINJECT(0x0043DD20, SkidooUserControl);\n//\tINJECT(0x0043DEE0, SkidooCheckGetOffOK);\n//\tINJECT(0x0043DFF0, SkidooAnimation);\n\n\tINJECT(0x0043E2D0, SkidooExplode);\n\n//\tINJECT(0x0043E350, SkidooCheckGetOff);\n\n\tINJECT(0x0043E590, SkidooGuns);\n\n//\tINJECT(0x0043E6B0, SkidooControl);\n\n\tINJECT(0x0043EB10, DrawSkidoo);\n\n//\tINJECT(0x0043EDF0, InitialiseSkidman);\n//\tINJECT(0x0043EE80, SkidManControl);\n//\tINJECT(0x0043F280, SkidmanPush);\n//\tINJECT(0x0043F3A0, SkidmanCollision);\n}\n"
  },
  {
    "path": "game/skidoo.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SKIDOO_H_INCLUDED\n#define SKIDOO_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define InitialiseSkidoo ((void(__cdecl*)(__int16)) 0x0043CEE0)\n\n//\t0x0043CF20:\t\tSkidooCheckGeton\n//\t0x0043D010:\t\tSkidooCollision\n//\t0x0043D110:\t\tSkidooBaddieCollision\n//\t0x0043D310:\t\tTestHeight\n//\t0x0043D3D0:\t\tDoShift\n//\t0x0043D650:\t\tDoDynamics\n//\t0x0043D6B0:\t\tGetCollisionAnim\n\nvoid __cdecl DoSnowEffect(ITEM_INFO *item); // 0x0043D740\n\n//\t0x0043D880:\t\tSkidooDynamics\n//\t0x0043DD20:\t\tSkidooUserControl\n//\t0x0043DEE0:\t\tSkidooCheckGetOffOK\n//\t0x0043DFF0:\t\tSkidooAnimation\n\nvoid __cdecl SkidooExplode(ITEM_INFO *item); // 0x0043E2D0\n\n//\t0x0043E350:\t\tSkidooCheckGetOff\n\nvoid __cdecl SkidooGuns(); // 0x0043E590\n\n//\t0x0043E6B0:\t\tSkidooControl\n\nvoid __cdecl DrawSkidoo(ITEM_INFO *item);\n\n#define InitialiseSkidman ((void(__cdecl*)(__int16)) 0x0043EDF0)\n#define SkidManControl ((void(__cdecl*)(__int16)) 0x0043EE80)\n\n//\t0x0043F280:\t\tSkidmanPush\n\n#define SkidmanCollision ((void(__cdecl*)(__int16, ITEM_INFO *, COLL_INFO *)) 0x0043F3A0)\n\n#endif // SKIDOO_H_INCLUDED\n"
  },
  {
    "path": "game/sound.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/sound.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\nint __cdecl GetRealTrack(int trackID) {\n\tstatic char vtracks[] = {2, 19, 20, 26, -1};\n\tint idx = 0;\n\tint track = 2;\n\n\tfor( int i = 2; i < trackID; ++i ) {\n\t\tif( (vtracks[idx] >= 0) && (i == vtracks[idx]) )\n\t\t\t++idx;\n\t\telse\n\t\t\t++track;\n\t}\n\treturn track;\n}\n\nvoid __cdecl SOUND_Init() {\n\tS_SoundSetMasterVolume(32); // 50% sfx volume\n\n\tfor( int i=0; i<32; ++i )\n\t\tSfxInfos[i].sampleIdx = -1;\n\n\tSoundIsActive = TRUE;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Sound() {\n\tINJECT(0x0043F430, GetRealTrack);\n\n//\tINJECT(0x0043F470, PlaySoundEffect);\n//\tINJECT(0x0043F910, StopSoundEffect);\n//\tINJECT(0x0043F970, SOUND_EndScene);\n//\tINJECT(0x0043FA00, SOUND_Stop);\n\n\tINJECT(0x0043FA30, SOUND_Init);\n}\n"
  },
  {
    "path": "game/sound.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SOUND_H_INCLUDED\n#define SOUND_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nint __cdecl GetRealTrack(int trackID); // 0x0043F430\n\n#define PlaySoundEffect ((void(__cdecl*)(DWORD, PHD_3DPOS *, DWORD)) 0x0043F470)\n#define StopSoundEffect ((void(__cdecl*)(int)) 0x0043F910)\n#define SOUND_EndScene ((void(__cdecl*)(void)) 0x0043F970)\n#define SOUND_Stop ((void(__cdecl*)(void)) 0x0043FA00)\n\nvoid __cdecl SOUND_Init(); // 0x0043FA30\n\n#endif // SOUND_H_INCLUDED\n"
  },
  {
    "path": "game/sphere.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/sphere.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Sphere() {\n//\tINJECT(0x0043FA60, TestCollision);\n//\tINJECT(0x0043FB90, GetSpheres);\n//\tINJECT(0x0043FE70, GetJointAbsPosition);\n//\tINJECT(0x00440010, BaddieBiteEffect);\n}\n"
  },
  {
    "path": "game/sphere.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SPHERE_H_INCLUDED\n#define SPHERE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x0043FA60:\t\tTestCollision\n//\t0x0043FB90:\t\tGetSpheres\n\n#define GetJointAbsPosition ((void(__cdecl*)(ITEM_INFO*, PHD_VECTOR*, int)) 0x0043FE70)\n#define BaddieBiteEffect ((void(__cdecl*)(ITEM_INFO*,BITE_INFO*)) 0x00440010)\n\n#endif // SPHERE_H_INCLUDED\n"
  },
  {
    "path": "game/spider.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/spider.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Spider() {\n//\tINJECT(0x00440070, SpiderLeap);\n//\tINJECT(0x00440120, SpiderControl);\n//\tINJECT(0x00440340, BigSpiderControl);\n}\n"
  },
  {
    "path": "game/spider.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SPIDER_H_INCLUDED\n#define SPIDER_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n//\t0x00440070:\t\tSpiderLeap\n\n#define SpiderControl ((void(__cdecl*)(__int16)) 0x00440120)\n#define BigSpiderControl ((void(__cdecl*)(__int16)) 0x00440340)\n\n#endif // SPIDER_H_INCLUDED\n"
  },
  {
    "path": "game/text.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/text.h\"\n#include \"3dsystem/scalespr.h\"\n#include \"game/health.h\"\n#include \"specific/frontend.h\"\n#include \"specific/output.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_HUD_IMPROVED\n#include \"modding/texture_utils.h\"\n\nextern DWORD InvTextBoxMode;\n#endif // FEATURE_HUD_IMPROVED\n\n#define IS_CHAR_SECRET(x)\t\t((x) >= CHAR_SECRET1 && (x) <= CHAR_SECRET3)\n#define IS_CHAR_LEGAL(x)\t\t((x) <= 0x12 || ((x) >= 0x20 && (x) <= 0x7F) || IS_CHAR_SECRET(x))\n#define IS_CHAR_DIACRITIC(x)\t((x) == '(' || (x) == ')' || (x) == '$' || (x) == '~')\n\nstatic const BYTE T_TextSpacing[0x6E] = {\n//\tA\tB\tC\tD\tE\tF\tG\tH\n\t14, 11, 11, 11, 11, 11, 11, 13,\n//\tI\tJ\tK\tL\tM\tN\tO\tP\n\t 8, 11, 12, 11, 13, 13, 12, 11,\n//\tQ\tR\tS\tT\tU\tV\tW\tX\n\t12, 12, 11, 12, 13, 13, 13, 12,\n//\tY\tZ\ta\tb\tc\td\te\tf\n\t12, 11,  9,  9,  9,  9,  9,  9,\n//\tg\th\ti\tj\tk\tl\tm\tn\n\t 9,  9,  5,  9,  9,  5, 12, 10,\n//\to\tp\tq\tr\ts\tt\tu\tv\n\t 9,  9,  9,  8,  9,  8,  9,  9,\n//\tw\tx\ty\tz\t0\t1\t2\t3\n\t11,  9,  9,  9, 12,  8, 10, 10,\n//\t4\t5\t6\t7\t8\t9\t.\t,\n\t10, 10, 10,  9, 10, 10,  5,  5,\n//\t!\t?\t[\tdi\"\t/\tdi^\tdi'\t-\n\t 5, 11,  9, 10,  8,  6,  6,  7,\n//\t+\t:\t\t]\t\\\t`\t#\t'\n\t 7,  3, 11,  8, 13, 16,  9,  4,\n//\tarU\tarD\tdg0\tdg1\tdg2\tdg3\tdg4\tdg5\n\t12, 12,  7,  5,  7,  7,  7,  7,\n//\tdg6\tdg7\tdg8\tdg9\tjs1\tjs2\tjs3\tjs4\n\t 7,  7,  7,  7, 16, 14, 14, 14,\n//\tjs5\tjs6\tjs7\tjs8\tjs9\tsc0\tsc1\tsc2\n\t16, 16, 16, 16, 16, 12, 14,  8,\n//\tsc3\tsc4\tdwn\tup\tlft\trht\n\t 8,  8,  8,  8,  8,  8,\n};\n\nstatic const BYTE T_RemapASCII[0x5F] = {\n//\tnop\t\t\t!\t\"to [\t\t#\t$to di`\t%to \t&to #\t\t'\n\t0x00,\t0x40,\t0x42,\t0x4E,\t0x4D,\t0x4A,\t0x4E,\t0x4F,\n//\t(to di^\t)to di'\t*to js1  \t+\t\t,\t\t-\t\t.\t\t/\n\t0x45,\t0x46,\t0x5C,\t0x48,\t0x3F,\t0x47,\t0x3E,\t0x44,\n//\t\t0\t\t1\t\t2\t\t3\t\t4\t\t5\t\t6\t\t7\n\t0x34,\t0x35,\t0x36,\t0x37,\t0x38,\t0x39,\t0x3A,\t0x3B,\n//\t\t8\t\t9\t\t:\t;to :\t<to [\t=to \t>to\t]\t\t?\n\t0x3C,\t0x3D,\t0x49,\t0x49,\t0x42,\t0x4A,\t0x4B,\t0x41,\n//\t@to\tA\t\tA\t\tB\t\tC\t\tD\t\tE\t\tF\t\tG\n\t0x00,\t0x00,\t0x01,\t0x02,\t0x03,\t0x04,\t0x05,\t0x06,\n//\t\tH\t\tI\t\tJ\t\tK\t\tL\t\tM\t\tN\t\tO\n\t0x07,\t0x08,\t0x09,\t0x0A,\t0x0B,\t0x0C,\t0x0D,\t0x0E,\n//\t\tP\t\tQ\t\tR\t\tS\t\tT\t\tU\t\tV\t\tW\n\t0x0F,\t0x10,\t0x11,\t0x12,\t0x13,\t0x14,\t0x15,\t0x16,\n//\t\tX\t\tY\t\tZ\t[to arU\t\t\\\t]to\tarD ^to js6\t_to js7\n\t0x17,\t0x18,\t0x19,\t0x50,\t0x4C,\t0x51,\t0x61,\t0x62,\n//\t\t`\t\ta\t\tb\t\tc\t\td\t\te\t\tf\t\tg\n\t0x4D,\t0x1A,\t0x1B,\t0x1C,\t0x1D,\t0x1E,\t0x1F,\t0x20,\n//\t\th\t\ti\t\tj\t\tk\t\tl\t\tm\t\tn\t\to\n\t0x21,\t0x22,\t0x23,\t0x24,\t0x25,\t0x26,\t0x27,\t0x28,\n//\t\tp\t\tq\t\tr\t\ts\t\tt\t\tu\t\tv\t\tw\n\t0x29,\t0x2A,\t0x2B,\t0x2C,\t0x2D,\t0x2E,\t0x2F,\t0x30,\n//\t\tx\t\ty\t\tz\t{to js9\t|to sc0\t}to sc1\t~to di\"\n\t0x31,\t0x32,\t0x33,\t0x64,\t0x65,\t0x66,\t0x43,\n};\n\nvoid __cdecl T_InitPrint() {\n\tDisplayModeInfo(NULL);\n\n\tfor( int i=0; i<64; ++i )\n\t\tTextInfoTable[i].flags = 0;\n\n\tTextStringCount = 0;\n}\n\nTEXT_STR_INFO *__cdecl T_Print(int x, int y, __int16 z, const char *str) {\n\tif( str == NULL || TextStringCount >= 64 )\n\t\treturn NULL;\n\n\tfor( int i=0; i<64; ++i ) {\n\t\tif( !CHK_ANY(TextInfoTable[i].flags, TIF_Active) ) {\n\t\t\tint stringLen = T_GetStringLen(str);\n\t\t\tCLAMPG(stringLen, 64); // NOTE: useless check, but decided to leave it here\n\n\t\t\tTextInfoTable[i].scaleH = PHD_ONE;\n\t\t\tTextInfoTable[i].scaleV = PHD_ONE;\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tTextInfoTable[i].xPos = x;\n\t\t\tTextInfoTable[i].yPos = y;\n#else // FEATURE_HUD_IMPROVED\n\t\t\tTextInfoTable[i].xPos = x * GetTextScaleH(PHD_ONE) / PHD_ONE;\n\t\t\tTextInfoTable[i].yPos = y * GetTextScaleV(PHD_ONE) / PHD_ONE;\n#endif // FEATURE_HUD_IMPROVED\n\t\t\tTextInfoTable[i].zPos = z;\n\t\t\tTextInfoTable[i].letterSpacing = 1;\n\t\t\tTextInfoTable[i].wordSpacing   = 6;\n\n\t\t\tTextInfoTable[i].textFlags = 0;\n\t\t\tTextInfoTable[i].outlFlags  = 0;\n\t\t\tTextInfoTable[i].bgndFlags = 0;\n\t\t\tTextInfoTable[i].bgndSizeX = 0;\n\t\t\tTextInfoTable[i].bgndSizeY = 0;\n\t\t\tTextInfoTable[i].bgndOffX  = 0;\n\t\t\tTextInfoTable[i].bgndOffY  = 0;\n\t\t\tTextInfoTable[i].bgndOffZ  = 0;\n\n\t\t\tTextInfoTable[i].flags = TIF_Active;\n\t\t\tTextInfoTable[i].pString = TheStrings[i].str;\n\n\t\t\tmemcpy(TheStrings[i].str, str, stringLen);\n\t\t\t++TextStringCount;\n\n\t\t\treturn &TextInfoTable[i];\n\t\t}\n\t}\n\treturn NULL;\n}\n\nvoid __cdecl T_ChangeText(TEXT_STR_INFO *textInfo, const char *newString) {\n\tif( newString == NULL || textInfo == NULL || !CHK_ANY(textInfo->flags, TIF_Active) )\n\t\treturn;\n\n\t// NOTE: the original code was unsafe crap. Reimplemented it a little safer\n\tstrncpy(textInfo->pString, newString, 64);\n\tif( T_GetStringLen(newString) >= 64 )\n\t\ttextInfo->pString[63] = 0;\n}\n\nvoid __cdecl T_SetScale(TEXT_STR_INFO *textInfo, int scaleH, int scaleV) {\n\tif( textInfo != NULL ) {\n\t\ttextInfo->scaleH = scaleH;\n\t\ttextInfo->scaleV = scaleV;\n\t}\n}\n\nvoid __cdecl T_FlashText(TEXT_STR_INFO *textInfo, __int16 state, __int16 rate) {\n\tif( textInfo == NULL)\n\t\treturn;\n\n\tif( state == 0 ) {\n\t\ttextInfo->flags &= ~TIF_Flash;\n\t} else {\n\t\ttextInfo->flags |= TIF_Flash;\n\t\ttextInfo->flashRate = rate;\n\t\ttextInfo->flashCount = rate;\n\t}\n}\n\nvoid __cdecl T_AddBackground(TEXT_STR_INFO *textInfo, __int16 xSize, __int16 ySize, __int16 xOff, __int16 yOff, __int16 zOff, INV_COLOURS invColour, GOURAUD_FILL *gour, UINT16 flags) {\n\tif( textInfo == NULL )\n\t\treturn;\n\n\ttextInfo->flags |= TIF_Bgnd;\n#ifdef FEATURE_HUD_IMPROVED\n\ttextInfo->bgndSizeX = xSize;\n\ttextInfo->bgndSizeY = ySize;\n\ttextInfo->bgndOffX = xOff;\n\ttextInfo->bgndOffY = yOff;\n#else // FEATURE_HUD_IMPROVED\n\tDWORD scaleH = GetTextScaleH(textInfo->scaleH);\n\tDWORD scaleV = GetTextScaleV(textInfo->scaleV);\n\ttextInfo->bgndSizeX = scaleH * xSize / PHD_ONE;\n\ttextInfo->bgndSizeY = scaleV * ySize / PHD_ONE;\n\ttextInfo->bgndOffX = scaleH * xOff / PHD_ONE;\n\ttextInfo->bgndOffY = scaleV * yOff / PHD_ONE;\n#endif // FEATURE_HUD_IMPROVED\n\ttextInfo->bgndOffZ = zOff;\n\ttextInfo->bgndColor = invColour;\n\ttextInfo->bgndGour = gour;\n\ttextInfo->bgndFlags = flags;\n}\n\nvoid __cdecl T_RemoveBackground(TEXT_STR_INFO *textInfo) {\n\tif( textInfo != NULL )\n\t\ttextInfo->flags &= ~TIF_Bgnd;\n}\n\nvoid __cdecl T_AddOutline(TEXT_STR_INFO *textInfo, BOOL state, INV_COLOURS invColour, GOURAUD_OUTLINE *gour, UINT16 flags) {\n\tif( textInfo != NULL ) {\n\t\ttextInfo->flags |= TIF_Outline;\n\t\ttextInfo->outlColour = invColour;\n\t\ttextInfo->outlGour = gour;\n\t\ttextInfo->outlFlags = flags;\n\t}\n}\n\nvoid __cdecl T_RemoveOutline(TEXT_STR_INFO *textInfo) {\n\tif( textInfo != NULL )\n\t\ttextInfo->flags &= ~TIF_Outline;\n}\n\nvoid __cdecl T_CentreH(TEXT_STR_INFO *textInfo, UINT16 state) {\n\tif( textInfo != NULL ) {\n\t\tif( state )\n\t\t\ttextInfo->flags |= TIF_CentreH;\n\t\telse\n\t\t\ttextInfo->flags &= ~TIF_CentreH;\n\t}\n}\n\nvoid __cdecl T_CentreV(TEXT_STR_INFO *textInfo, UINT16 state) {\n\tif( textInfo != NULL ) {\n\t\tif( state )\n\t\t\ttextInfo->flags |= TIF_CentreV;\n\t\telse\n\t\t\ttextInfo->flags &= ~TIF_CentreV;\n\t}\n}\n\nvoid __cdecl T_RightAlign(TEXT_STR_INFO *textInfo, bool state) {\n\tif( textInfo == NULL)\n\t\treturn;\n\n\tif( state ) {\n\t\ttextInfo->flags |= TIF_Right;\n\t} else {\n\t\ttextInfo->flags &= ~TIF_Right;\n\t}\n}\n\nvoid __cdecl T_BottomAlign(TEXT_STR_INFO *textInfo, bool state) {\n\tif( textInfo == NULL)\n\t\treturn;\n\n\tif( state ) {\n\t\ttextInfo->flags |= TIF_Bottom;\n\t} else {\n\t\ttextInfo->flags &= ~TIF_Bottom;\n\t}\n}\n\nvoid __cdecl T_DrawTextBox(int sx, int sy, int z, int width, int height) {\n\tint x0, y0, x1, y1, offset;\n\tint scaleH, scaleV;\n\tint meshIdx = Objects[ID_TEXT_BOX].meshIndex;\n\n#ifdef FEATURE_HUD_IMPROVED\n\toffset = GetRenderScale(4);\n\tscaleH = GetRenderScale(PHD_ONE);\n\tscaleV = GetRenderScale(PHD_ONE);\n#else // !FEATURE_HUD_IMPROVED\n\toffset = 4;\n\tscaleH = PHD_ONE;\n\tscaleV = PHD_ONE;\n#endif // FEATURE_HUD_IMPROVED\n\n\tx0 = sx + offset;\n\ty0 = sy + offset;\n\tx1 = sx - offset + width;\n\ty1 = sy - offset + height;\n\n\twidth = PHD_ONE * (width  - offset * 2) / 8;\n\theight = PHD_ONE * (height - offset * 2) / 8;\n\n\tS_DrawScreenSprite2d(x0, y0, z, scaleH, scaleV, (meshIdx + 0), 0x1000, 0);\n\tS_DrawScreenSprite2d(x1, y0, z, scaleH, scaleV, (meshIdx + 1), 0x1000, 0);\n\tS_DrawScreenSprite2d(x1, y1, z, scaleH, scaleV, (meshIdx + 2), 0x1000, 0);\n\tS_DrawScreenSprite2d(x0, y1, z, scaleH, scaleV, (meshIdx + 3), 0x1000, 0);\n\n\tS_DrawScreenSprite2d(x0, y0, z, width,  scaleV, (meshIdx + 4), 0x1000, 0);\n\tS_DrawScreenSprite2d(x1, y0, z, scaleH, height, (meshIdx + 5), 0x1000, 0);\n\tS_DrawScreenSprite2d(x0, y1, z, width,  scaleV, (meshIdx + 6), 0x1000, 0);\n\tS_DrawScreenSprite2d(x0, y0, z, scaleH, height, (meshIdx + 7), 0x1000, 0);\n}\n\nDWORD __cdecl T_GetTextWidth(TEXT_STR_INFO *textInfo) {\n\tint spacing;\n\tDWORD width, scaleH, sprite;\n\n\twidth = 0;\n#ifdef FEATURE_HUD_IMPROVED\n\tscaleH = textInfo->scaleH;\n#else // FEATURE_HUD_IMPROVED\n\tscaleH = GetTextScaleH(textInfo->scaleH);\n#endif // FEATURE_HUD_IMPROVED\n\n\tfor( BYTE *str = (BYTE *)textInfo->pString; *str != 0; str++ ) {\n\t\tif( !IS_CHAR_LEGAL(*str) || IS_CHAR_DIACRITIC(*str) ) {\n\t\t\tcontinue; // if char code is illegal or not required for width measuring, go to next char\n\t\t}\n\n\t\tif( *str == 0x20 ) { // Check if char is \"Space\"\n\t\t\t// \"Space\" uses wordSpacing value instead of sprite width\n\t\t\tspacing = textInfo->wordSpacing;\n\t\t}\n\t\telse if( IS_CHAR_SECRET(*str) ) { // Check if \"Secret\" sprite\n\t\t\t// \"Secret\" sprites have spacing=16\n\t\t\tspacing = 16;\n#ifdef FEATURE_HUD_IMPROVED\n\t\t} else if( *str == 0x7F ) { // Check if it's the opening code of the named sprite sequence\n\t\t\tBYTE *ptr = (BYTE *)strchr((const char *)str+1, 0x1F);\n\t\t\tif( ptr == NULL ) break; // Closing code is not found, break now!\n\t\t\tif( !GetTextSpriteByName((const char *)str+1, ptr-str-1, &sprite, &spacing) ) {\n\t\t\t\tspacing = 0;\n\t\t\t}\n\t\t\tstr = ptr; // move pointer to the sequence end\n#endif // FEATURE_HUD_IMPROVED\n\t\t} else {\n\t\t\tif( *str < 0x0B ) { // Check if \"Digit\" sprite\n\t\t\t\tsprite = *str + 0x51; // We have (*str >= 0x01) here. \"Digit\" sprite codes start from (0x52 = 0x01 + 0x51)\n\t\t\t}\n\t\t\telse if( *str <= 0x12 ) { // Check if \"Special\" sprite. NOTE: original code was (*str < 0x10) but this was wrong\n\t\t\t\t// Check if normal *str or \"Special\" sprite\n\t\t\t\tsprite = *str + 0x5B;  // We have (*str >= 0x0B) here. \"Special\" sprite codes start from (0x66 = 0x0B + 0x5B)\n\t\t\t} else { // here (*str > 0x20)\n\t\t\t\tsprite = T_RemapASCII[*str - 0x20]; // For normal letters we have sprite code table\n\t\t\t}\n\n\t\t\t// Check if normal letter sprite has digit representation\n\t\t\tif( *str >= '0' && *str <= '9' ) { // NOTE: original code was (sprite >= '0' && sprite <= '9') but this was wrong\n\t\t\t\t// Normal letter sprites with digits have spacing=12\n\t\t\t\tspacing = 12;\n\t\t\t} else {\n\t\t\t\t// For \"Digit\", \"Special\" and normal letter sprites we use spacing table + letterSpacing\n#if defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tspacing = GetTexPagesGlyphSpacing(sprite);\n\t\t\t\tif( !spacing ) spacing = T_TextSpacing[sprite];\n#else // defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tspacing = T_TextSpacing[sprite];\n#endif // defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\t\t// NOTE: this condition was added instead of returned value recalculation (see below).\n\t\t\t\t// In the original code spacing addition was unconditional\n\t\t\t\tif( str[1] != 0 ) { // If this letter is not last, add letterSpacing\n\t\t\t\t\tspacing += textInfo->letterSpacing;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twidth += spacing * scaleH / PHD_ONE;\n\t}\n\t// NOTE: original code was ((width - textInfo->letterSpacing) & ~1) but this was wrong, because letterSpacing is not scaled\n\t// And also we calculate width of any string, there may not be letterSpacing at all (i.e. digit letter sprites )\n\treturn width;\n}\n\nBOOL __cdecl T_RemovePrint(TEXT_STR_INFO *textInfo) {\n\tif( textInfo == NULL || !CHK_ANY(textInfo->flags, TIF_Active) )\n\t\treturn false;\n\n\ttextInfo->flags &= ~TIF_Active;\n\t--TextStringCount;\n\treturn true;\n}\n\n__int16 __cdecl T_GetStringLen(const char *str) {\n\t// Calculates string length up to 64 chars including null terminator\n\tfor( int i=0; i<64; ++i ) {\n\t\tif( str[i] == 0 )\n\t\t\treturn i+1;\n\t}\n\treturn 64;\n}\n\nvoid __cdecl T_DrawText() {\n\tfor( int i=0; i<64; ++i ) {\n\t\tif( CHK_ANY(TextInfoTable[i].flags, TIF_Active) )\n\t\t\tT_DrawThisText(&TextInfoTable[i]);\n\t}\n}\n\nvoid __cdecl T_DrawThisText(TEXT_STR_INFO *textInfo) {\n\tint x, y, z, xOff, spacing;\n\tint boxX, boxY, boxZ, boxW, boxH;\n\tDWORD textWidth, scaleH, scaleV, sprite;\n#ifdef FEATURE_HUD_IMPROVED\n\tint sx, sy, sh, sv;\n\n\tif( CHK_ANY(textInfo->flags, TIF_Hide) ) {\n\t\treturn;\n\t}\n\n\tscaleH = textInfo->scaleH;\n\tscaleV = textInfo->scaleV;\n#else // FEATURE_HUD_IMPROVED\n\tscaleH = GetTextScaleH(textInfo->scaleH);\n\tscaleV = GetTextScaleV(textInfo->scaleV);\n#endif // FEATURE_HUD_IMPROVED\n\n\t// Do text flashing if required\n\tif( CHK_ANY(textInfo->flags, TIF_Flash) ) {\n\t\ttextInfo->flashCount -= (__int16)Camera.numberFrames;\n\n\t\tif( textInfo->flashCount <= -textInfo->flashRate ) {\n\t\t\ttextInfo->flashCount = textInfo->flashRate;\n\t\t}\n\t\telse if ( textInfo->flashCount < 0 ) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tx = textInfo->xPos;\n\ty = textInfo->yPos;\n\tz = textInfo->zPos;\n\ttextWidth = T_GetTextWidth(textInfo);\n\n#ifdef FEATURE_HUD_IMPROVED\n\t// Horizontal alignment\n\tif( CHK_ANY(textInfo->flags, TIF_CentreH) ) {\n\t\tx += (GetRenderWidthDownscaled() - textWidth) / 2;\n\t}\n\telse if( CHK_ANY(textInfo->flags, TIF_Right) ) {\n\t\tx += GetRenderWidthDownscaled() - textWidth;\n\t}\n\n\t// Vertical alignment\n\tif( CHK_ANY(textInfo->flags, TIF_CentreV) ) {\n\t\ty += GetRenderHeightDownscaled() / 2;\n\t}\n\telse if ( CHK_ANY(textInfo->flags, TIF_Bottom) ) {\n\t\ty += GetRenderHeightDownscaled();\n\t}\n#else // FEATURE_HUD_IMPROVED\n\t// Horizontal alignment\n\tif( CHK_ANY(textInfo->flags, TIF_CentreH) ) {\n\t\tx += (GetRenderWidth() - textWidth) / 2;\n\t}\n\telse if( CHK_ANY(textInfo->flags, TIF_Right) ) {\n\t\tx += GetRenderWidth() - textWidth;\n\t}\n\n\t// Vertical alignment\n\tif( CHK_ANY(textInfo->flags, TIF_CentreV) ) {\n\t\ty += GetRenderHeight() / 2;\n\t}\n\telse if ( CHK_ANY(textInfo->flags, TIF_Bottom) ) {\n\t\ty += GetRenderHeight();\n\t}\n#endif // FEATURE_HUD_IMPROVED\n\n\tboxX = x + textInfo->bgndOffX - (2 * scaleH / PHD_ONE);\n\tboxY = y + textInfo->bgndOffY - (4 * scaleV / PHD_ONE) - (11 * scaleV / PHD_ONE);\n\tboxZ = z + textInfo->bgndOffZ + 2;\n\n\tfor( BYTE *str = (BYTE *)textInfo->pString; *str != 0; str++ ) {\n\t\t// Check if char code is in illegal range\n\t\tif( !IS_CHAR_LEGAL(*str) )\n\t\t\tcontinue;\n\n\t\tif( *str == 0x20 ) { // Check if char is \"Space\"\n\t\t\t// \"Space\" uses wordSpacing value instead of sprite width\n\t\t\tx += textInfo->wordSpacing * scaleH / PHD_ONE;\n\t\t}\n\t\telse if( IS_CHAR_SECRET(*str) ) { // Check if \"Secret\" sprite\n\t\t\t// Draw \"Secret\" sprite\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tsx = GetTextScaleH(x + 10);\n\t\t\tsy = GetTextScaleV(y);\n\t\t\tS_DrawPickup(sx, sy, 0x1BE8, Objects[ID_SECRET1 + (*str - CHAR_SECRET1)].meshIndex, 0x1000);\n#else // FEATURE_HUD_IMPROVED\n\t\t\tS_DrawPickup(x + 10, y, 0x1BE8, Objects[ID_SECRET1 + (*str - CHAR_SECRET1)].meshIndex, 0x1000);\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t// \"Secret\" sprites have spacing=16\n\t\t\tx += 16 * scaleH / PHD_ONE;\n#ifdef FEATURE_HUD_IMPROVED\n\t\t} else if( *str == 0x7F ) { // Check if it's the opening code of the named sprite sequence\n\t\t\tBYTE *ptr = (BYTE *)strchr((const char *)str+1, 0x1F);\n\t\t\tif( ptr == NULL ) break; // Closing code is not found, break now!\n\t\t\tif( GetTextSpriteByName((const char *)str+1, ptr-str-1, &sprite, &xOff) ) {\n\t\t\t\tif( x > 0 && x < GetRenderWidthDownscaled() && y > 0 && y < GetRenderHeightDownscaled() ) {\n\t\t\t\t\tsx = GetTextScaleH(x);\n\t\t\t\t\tsy = GetTextScaleV(y);\n\t\t\t\t\tsh = GetTextScaleH(scaleH);\n\t\t\t\t\tsv = GetTextScaleV(scaleV);\n\t\t\t\t\tS_DrawScreenSprite2d(sx, sy, z, sh, sv, sprite, 0x1000, textInfo->textFlags);\n\t\t\t\t}\n\t\t\t\tx += xOff * scaleH / PHD_ONE;\n\t\t\t}\n\t\t\tstr = ptr; // move pointer to the sequence end\n#endif // FEATURE_HUD_IMPROVED\n\t\t} else {\n\t\t\tif( *str < 0x0B ) { // Check if \"Digit\" sprite\n\t\t\t\tsprite = *str + 0x51; // We have (*str >= 0x01) here. \"Digit\" sprite codes start from (0x52 = 0x01 + 0x51)\n\t\t\t}\n\t\t\telse if( *str <= 0x12 ) { // Check if \"Special\" sprite. NOTE: original code was (*str < 0x10) but this was wrong\n\t\t\t\t// Check if normal *str or \"Special\" sprite\n\t\t\t\tsprite = *str + 0x5B;  // We have (*str >= 0x0B) here. \"Special\" sprite codes start from (0x66 = 0x0B + 0x5B)\n\t\t\t} else { // here (*str > 0x20)\n\t\t\t\tsprite = T_RemapASCII[*str - 0x20]; // For normal letters we have sprite code table\n\t\t\t}\n\n\t\t\t// Check if normal letter sprite is digit representation\n\t\t\t// Normal letter sprites with digits have spacing=12\n\t\t\t// But sprite itself is center aligned in this space\n\t\t\tif( *str >= '0' && *str <= '9' ) {\n\t\t\t\t// !!! Here we do LEFT spacing part for digit letters !!!\n#if defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tspacing = GetTexPagesGlyphSpacing(sprite);\n\t\t\t\tif( !spacing ) spacing = T_TextSpacing[sprite];\n#else // defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tspacing = T_TextSpacing[sprite];\n#endif // defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\t\txOff = (12 - spacing) / 2;\n\t\t\t\tx += xOff * scaleH / PHD_ONE;\n\t\t\t}\n\n\t\t\t// Draw letter sprite\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tif( x > 0 && x < GetRenderWidthDownscaled() && y > 0 && y < GetRenderHeightDownscaled() ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tsx = GetTextScaleH(x + GetTexPagesGlyphXOffset(sprite));\n\t\t\t\tsy = GetTextScaleV(y + GetTexPagesGlyphYOffset(sprite));\n\t\t\t\tsh = GetTextScaleH(scaleH * GetTexPagesGlyphXStretch(sprite));\n\t\t\t\tsv = GetTextScaleV(scaleV * GetTexPagesGlyphYStretch(sprite));\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tsx = GetTextScaleH(x);\n\t\t\t\tsy = GetTextScaleV(y);\n\t\t\t\tsh = GetTextScaleH(scaleH);\n\t\t\t\tsv = GetTextScaleV(scaleV);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tS_DrawScreenSprite2d(sx, sy, z, sh, sv, (Objects[ID_ALPHABET].meshIndex + sprite), 0x1000, textInfo->textFlags);\n\t\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\t\tif( x > 0 && x < GetRenderWidth() && y > 0 && y < GetRenderHeight() ) {\n\t\t\t\tS_DrawScreenSprite2d(x, y, z, scaleH, scaleV, (Objects[ID_ALPHABET].meshIndex + sprite), 0x1000, textInfo->textFlags);\n\t\t\t}\n#endif // FEATURE_HUD_IMPROVED\n\n\t\t\t// Check if letter is diacritic\n\t\t\t// Diacritics are drawn right on the next letter sprite, so there is no spacing for them\n\t\t\tif( IS_CHAR_DIACRITIC(*str) )\n\t\t\t\tcontinue;\n\n\t\t\t// Check if normal letter sprite is digit representation\n#if defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\tspacing = GetTexPagesGlyphSpacing(sprite);\n\t\t\tif( !spacing ) spacing = T_TextSpacing[sprite];\n#else // defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\tspacing = T_TextSpacing[sprite];\n#endif // defined(FEATURE_HUD_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\tif( *str >= '0' && *str <= '9' ) {\n\t\t\t\t// !!! Here we do RIGHT spacing part for digit letters !!!\n\t\t\t\txOff = (12 - spacing) / 2;\n\t\t\t\tx += (12 - xOff) * scaleH / PHD_ONE;\n\t\t\t} else {\n\t\t\t\t// For \"Digit\", \"Special\" and normal letter sprites we use spacing table + letterSpacing\n\t\t\t\txOff = spacing;\n\t\t\t\txOff += textInfo->letterSpacing;\n\t\t\t\tx += xOff * scaleH / PHD_ONE;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Draw background/outline if required\n\tif( CHK_ANY(textInfo->flags, TIF_Bgnd|TIF_Outline) ) {\n\t\tif( textInfo->bgndSizeX != 0 ) {\n\t\t\tboxX += ((int)textWidth - textInfo->bgndSizeX) / 2;\n\t\t\tboxW = textInfo->bgndSizeX + 4;\n\t\t} else {\n\t\t\tboxW = textWidth + 4;\n\t\t}\n\n\t\tif( textInfo->bgndSizeY != 0 ) {\n\t\t\tboxH = textInfo->bgndSizeY;\n\t\t} else {\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tboxH = (SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ? 14 : 16) * scaleV / PHD_ONE;\n#else // !FEATURE_HUD_IMPROVED\n\t\t\tboxH = 16 * scaleV / PHD_ONE;\n#endif // FEATURE_HUD_IMPROVED\n\t\t}\n\n#ifdef FEATURE_HUD_IMPROVED\n\t\tsx = GetTextScaleH(boxX);\n\t\tsy = GetTextScaleV(boxY);\n\t\tsh = GetTextScaleH(boxW);\n\t\tsv = GetTextScaleV(boxH);\n\n\t\t// Draw background\n\t\tif( CHK_ANY(textInfo->flags, TIF_Bgnd) ) {\n\t\t\tS_DrawScreenFBox(sx, sy, boxZ, sh, sv, textInfo->bgndColor, textInfo->bgndGour, textInfo->bgndFlags);\n\t\t}\n\n\t\t// Draw outline\n\t\tif( CHK_ANY(textInfo->flags, TIF_Outline) ) {\n\t\t\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\t\t\tS_DrawScreenBox(sx, sy, boxZ, sh, sv, textInfo->outlColour, textInfo->outlGour, textInfo->outlFlags);\n\t\t\t} else {\n\t\t\t\tT_DrawTextBox(sx, sy, z, sh, sv);\n\t\t\t}\n\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\t// Draw background\n\t\tif( CHK_ANY(textInfo->flags, TIF_Bgnd) ) {\n\t\t\tS_DrawScreenFBox(boxX, boxY, boxZ, boxW, boxH, textInfo->bgndColor, textInfo->bgndGour, textInfo->bgndFlags);\n\t\t}\n\n\t\t// Draw outline\n\t\tif( CHK_ANY(textInfo->flags, TIF_Outline) ) {\n\t\t\tT_DrawTextBox(boxX, boxY, z, boxW, boxH);\n\t\t}\n#endif // FEATURE_HUD_IMPROVED\n\t}\n}\n\nDWORD __cdecl GetTextScaleH(DWORD baseScale) {\n#ifdef FEATURE_HUD_IMPROVED\n\treturn GetRenderScale(baseScale);\n#else // !FEATURE_HUD_IMPROVED\n\tDWORD renderWidth, renderScale;\n\n\trenderWidth = GetRenderWidth();\n\tCLAMPL(renderWidth, 640)\n\n\trenderScale = renderWidth * PHD_ONE / 640;\n\treturn (baseScale / PHD_HALF) * (renderScale / PHD_HALF);\n#endif // FEATURE_HUD_IMPROVED\n}\n\nDWORD __cdecl GetTextScaleV(DWORD baseScale) {\n#ifdef FEATURE_HUD_IMPROVED\n\treturn GetRenderScale(baseScale);\n#else // !FEATURE_HUD_IMPROVED\n\tDWORD renderHeight, renderScale;\n\n\trenderHeight = GetRenderHeight();\n\tCLAMPL(renderHeight, 480)\n\n\trenderScale = renderHeight * PHD_ONE / 480;\n\treturn (baseScale / PHD_HALF) * (renderScale / PHD_HALF);\n#endif // FEATURE_HUD_IMPROVED\n}\n\n#ifdef FEATURE_HUD_IMPROVED\nvoid T_HideText(TEXT_STR_INFO *textInfo, __int16 state) {\n\tif( textInfo == NULL)\n\t\treturn;\n\n\tif( state == 0 ) {\n\t\ttextInfo->flags &= ~TIF_Hide;\n\t} else {\n\t\ttextInfo->flags |= TIF_Hide;\n\t}\n}\n#endif // FEATURE_HUD_IMPROVED\n\n/*\n * Inject function\n */\nvoid Inject_Text() {\n\tINJECT(0x00440500, T_InitPrint);\n\tINJECT(0x00440530, T_Print);\n\tINJECT(0x00440640, T_ChangeText);\n\tINJECT(0x00440680, T_SetScale);\n\tINJECT(0x004406A0, T_FlashText);\n\tINJECT(0x004406D0, T_AddBackground);\n\tINJECT(0x00440760, T_RemoveBackground);\n\tINJECT(0x00440770, T_AddOutline);\n\tINJECT(0x004407A0, T_RemoveOutline);\n\tINJECT(0x004407B0, T_CentreH);\n\tINJECT(0x004407D0, T_CentreV);\n\tINJECT(0x004407F0, T_RightAlign);\n\tINJECT(0x00440810, T_BottomAlign);\n\tINJECT(0x00440830, T_GetTextWidth);\n\tINJECT(0x00440940, T_RemovePrint);\n\tINJECT(0x00440970, T_GetStringLen);\n\tINJECT(0x004409A0, T_DrawText);\n\tINJECT(0x004409D0, T_DrawTextBox);\n\tINJECT(0x00440B60, T_DrawThisText);\n\tINJECT(0x00440F40, GetTextScaleH);\n\tINJECT(0x00440F80, GetTextScaleV);\n}\n"
  },
  {
    "path": "game/text.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef TEXT_H_INCLUDED\n#define TEXT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl T_InitPrint(); // 0x00440500\nTEXT_STR_INFO *__cdecl T_Print(int x, int y, __int16 z, const char *str); // 0x00440530\nvoid __cdecl T_ChangeText(TEXT_STR_INFO *textInfo, const char *newString); // 0x00440640\nvoid __cdecl T_SetScale(TEXT_STR_INFO *textInfo, int scaleH, int scaleV); // 0x00440680\nvoid __cdecl T_FlashText(TEXT_STR_INFO *textInfo, __int16 state, __int16 rate); // 0x004406A0\nvoid __cdecl T_AddBackground(TEXT_STR_INFO *textInfo, __int16 xSize, __int16 ySize, __int16 xOff, __int16 yOff, __int16 zOff, INV_COLOURS invColour, GOURAUD_FILL *gour, UINT16 flags); // 0x004406D0\nvoid __cdecl T_RemoveBackground(TEXT_STR_INFO *textInfo); // 0x00440760\nvoid __cdecl T_AddOutline(TEXT_STR_INFO *textInfo, BOOL state, INV_COLOURS invColour, GOURAUD_OUTLINE *gour, UINT16 flags); // 0x00440770\nvoid __cdecl T_RemoveOutline(TEXT_STR_INFO *textInfo); // 0x004407A0\nvoid __cdecl T_CentreH(TEXT_STR_INFO *textInfo, UINT16 state); // 0x004407B0\nvoid __cdecl T_CentreV(TEXT_STR_INFO *textInfo, UINT16 state); // 0x004407D0\nvoid __cdecl T_RightAlign(TEXT_STR_INFO *textInfo, bool state); // 0x004407F0\nvoid __cdecl T_BottomAlign(TEXT_STR_INFO *textInfo, bool state); // 0x00440810\nDWORD __cdecl T_GetTextWidth(TEXT_STR_INFO *textInfo); // 0x00440830\nBOOL __cdecl T_RemovePrint(TEXT_STR_INFO *textInfo); // 0x00440940\n__int16 __cdecl T_GetStringLen(const char *str); // 0x00440970\nvoid __cdecl T_DrawText(); // 0x004409A0\nvoid __cdecl T_DrawTextBox(int sx, int sy, int z, int width, int height); // 0x004409D0\nvoid __cdecl T_DrawThisText(TEXT_STR_INFO *textInfo); // 0x00440B60\nDWORD __cdecl GetTextScaleH(DWORD baseScale); // 0x00440F40\nDWORD __cdecl GetTextScaleV(DWORD baseScale); // 0x00440F80\n\n#ifdef FEATURE_HUD_IMPROVED\nvoid T_HideText(TEXT_STR_INFO *textInfo, __int16 state);\n#endif // FEATURE_HUD_IMPROVED\n\n#endif // TEXT_H_INCLUDED\n"
  },
  {
    "path": "game/traps.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Copyright (c) 2020 ChocolateFan <asasas9500@gmail.com>\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/traps.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/control.h\"\n#include \"game/effects.h\"\n#include \"game/items.h\"\n#include \"game/missile.h\"\n#include \"game/sound.h\"\n#include \"game/sphere.h\"\n#include \"specific/game.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\nvoid __cdecl MineControl(__int16 mineID) {\n\tITEM_INFO *mine = &Items[mineID];\n\tif( CHK_ANY(mine->flags, IFL_INVISIBLE) ) {\n\t\treturn;\n\t}\n\n\tif( !MinesDetonated ) {\n\t\t__int16 roomNumber = mine->roomNumber;\n\t\tGetFloor(mine->pos.x, mine->pos.y - 0x800, mine->pos.z, &roomNumber);\n\n\t\tITEM_INFO *item = NULL;\n\t\t__int16 itemID = RoomInfo[roomNumber].itemNumber;\n\t\tfor( ; itemID >= 0; itemID = item->nextItem ) {\n\t\t\titem = &Items[itemID];\n\t\t\tif( item->objectID == ID_BOAT ) {\n\t\t\t\tint x = item->pos.x - mine->pos.x;\n\t\t\t\tint y = item->pos.z - mine->pos.z;\n\t\t\t\tif( SQR(x) + SQR(y) < SQR(0x200) ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif( itemID < 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif( Lara.skidoo == itemID ) {\n\t\t\tExplodingDeath(Lara.item_number, ~0, 0);\n\t\t\tLaraItem->hitPoints = 0;\n\t\t\tLaraItem->flags |= IFL_INVISIBLE;\n\t\t}\n\t\titem->objectID = ID_BOAT_BITS;\n\t\tExplodingDeath(itemID, ~0, 0);\n\t\tKillItem(itemID);\n\t\titem->objectID = ID_BOAT;\n\n\t\tFLOOR_INFO *floor = GetFloor(mine->pos.x, mine->pos.y, mine->pos.z, &roomNumber);\n\t\tGetHeight(floor, mine->pos.x, mine->pos.y, mine->pos.z);\n\t\tTestTriggers(TriggerPtr, 1);\n\t\tMinesDetonated = 1;\n\t} else if ( GetRandomControl() < 0x7800 ) {\n\t\treturn;\n\t}\n\n\t__int16 fxID = CreateEffect(mine->roomNumber);\n\tif ( fxID != -1 )\n\t{\n\t\tFX_INFO *fx = &Effects[fxID];\n\t\tfx->pos.x = mine->pos.x;\n\t\tfx->pos.y = mine->pos.y - 0x400;\n\t\tfx->pos.z = mine->pos.z;\n\t\tfx->speed = 0;\n\t\tfx->frame_number = 0;\n\t\tfx->counter = 0;\n\t\tfx->object_number = ID_EXPLOSION;\n\t}\n\n\tSplash(mine);\n\tPlaySoundEffect(105, &mine->pos, 0);\n\tmine->flags |= IFL_INVISIBLE;\n\tmine->collidable = 0;\n\tmine->meshBits = 1;\n#ifdef FEATURE_INPUT_IMPROVED\n\tJoyRumbleExplode(mine->pos.x, mine->pos.y, mine->pos.z, 0x2800, false);\n#endif // FEATURE_INPUT_IMPROVED\n}\n\nvoid __cdecl ControlSpikeWall(__int16 itemID) {\n\tITEM_INFO *item;\n\tint x, z;\n\t__int16 roomID;\n\n\titem = &Items[itemID];\n\tif (TriggerActive(item) && item->status != ITEM_DISABLED) {\n\t\tz = item->pos.z + (16 * phd_cos(item->pos.rotY) >> W2V_SHIFT);\n\t\tx = item->pos.x + (16 * phd_sin(item->pos.rotY) >> W2V_SHIFT);\n\t\troomID = item->roomNumber;\n\t\tif (GetHeight(GetFloor(x, item->pos.y, z, &roomID), x, item->pos.y, z) != item->pos.y) {\n\t\t\titem->status = ITEM_DISABLED;\n\t\t} else {\n\t\t\titem->pos.z = z;\n\t\t\titem->pos.x = x;\n\t\t\tif (roomID != item->roomNumber)\n\t\t\t\tItemNewRoom(itemID, roomID);\n\t\t}\n\t\tPlaySoundEffect(204, &item->pos, 0);\n\t}\n\tif (item->touchBits) {\n\t\tLaraItem->hitPoints -= 20;\n\t\tLaraItem->hit_status = 1;\n\t\tDoLotsOfBlood(LaraItem->pos.x, LaraItem->pos.y - 512, LaraItem->pos.z, 1, item->pos.rotY, LaraItem->roomNumber, 3);\n\t\titem->touchBits = 0;\n\t\tPlaySoundEffect(205, &item->pos, 0);\n\t}\n}\n\nvoid __cdecl ControlCeilingSpikes(__int16 itemID) {\n\tITEM_INFO *item;\n\tint y;\n\t__int16 roomID;\n\n\titem = &Items[itemID];\n\tif (TriggerActive(item) && item->status != ITEM_DISABLED) {\n\t\ty = item->pos.y + 5;\n\t\troomID = item->roomNumber;\n\t\tif (GetHeight(GetFloor(item->pos.x, y, item->pos.z, &roomID), item->pos.x, y, item->pos.z) < y + 1024) {\n\t\t\titem->status = ITEM_DISABLED;\n\t\t} else {\n\t\t\titem->pos.y = y;\n\t\t\tif (roomID != item->roomNumber)\n\t\t\t\tItemNewRoom(itemID, roomID);\n\t\t}\n\t\tPlaySoundEffect(204, &item->pos, 0);\n\t}\n\tif (item->touchBits) {\n\t\tLaraItem->hitPoints -= 20;\n\t\tLaraItem->hit_status = 1;\n\t\tDoLotsOfBlood(LaraItem->pos.x, LaraItem->pos.y + 768, LaraItem->pos.z, 1, item->pos.rotY, LaraItem->roomNumber, 3);\n\t\titem->touchBits = 0;\n\t\tPlaySoundEffect(205, &item->pos, 0);\n\t}\n}\n\nvoid __cdecl HookControl(__int16 itemID) {\n\tITEM_INFO *item;\n\tstatic BOOL IsHookHit = FALSE;\n\n\titem = &Items[itemID];\n\tif (item->touchBits && !IsHookHit) {\n\t\tLaraItem->hitPoints -= 50;\n\t\tLaraItem->hit_status = 1;\n\t\tDoLotsOfBlood(LaraItem->pos.x, LaraItem->pos.y - 512, LaraItem->pos.z, LaraItem->speed, LaraItem->pos.rotY, LaraItem->roomNumber, 3);\n\t} else {\n\t\tIsHookHit = FALSE;\n\t}\n\tAnimateItem(item);\n}\n\nvoid __cdecl SpinningBlade(__int16 itemID) {\n\tITEM_INFO *item;\n\tint x, z;\n\t__int16 roomID;\n\tBOOL reverse;\n\n\titem = &Items[itemID];\n\tif (item->currentAnimState == 2) {\n\t\tif (item->goalAnimState != 1) {\n\t\t\tz = item->pos.z + (1536 * phd_cos(item->pos.rotY) >> W2V_SHIFT);\n\t\t\tx = item->pos.x + (1536 * phd_sin(item->pos.rotY) >> W2V_SHIFT);\n\t\t\troomID = item->roomNumber;\n\t\t\tif (GetHeight(GetFloor(x, item->pos.y, z, &roomID), x, item->pos.y, z) == NO_HEIGHT)\n\t\t\t\titem->goalAnimState = 1;\n\t\t}\n\t\treverse = TRUE;\n\t\tif (item->touchBits) {\n\t\t\tLaraItem->hit_status = 1;\n\t\t\tLaraItem->hitPoints -= 100;\n\t\t\tDoLotsOfBlood(LaraItem->pos.x, LaraItem->pos.y - 512, LaraItem->pos.z, 2 * item->speed, LaraItem->pos.rotY, LaraItem->roomNumber, 2);\n\t\t}\n\t\tPlaySoundEffect(231, &item->pos, 0);\n\t} else {\n\t\tif (TriggerActive(item))\n\t\t\titem->goalAnimState = 2;\n\t\treverse = FALSE;\n\t}\n\tAnimateItem(item);\n\troomID = item->roomNumber;\n\titem->pos.y = GetHeight(GetFloor(item->pos.x, item->pos.y, item->pos.z, &roomID), item->pos.x, item->pos.y, item->pos.z);\n\titem->floor = item->pos.y;\n\tif (roomID != item->roomNumber)\n\t\tItemNewRoom(itemID, roomID);\n\tif (reverse && item->currentAnimState == 1)\n\t\titem->pos.rotY += PHD_180;\n}\n\nvoid __cdecl IcicleControl(__int16 itemID) {\n\tITEM_INFO *item;\n\t__int16 roomID;\n\tFLOOR_INFO *floor;\n\n\titem = &Items[itemID];\n\tswitch (item->currentAnimState) {\n\t\tcase 1:\n\t\t\titem->goalAnimState = 2;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tif (!item->gravity) {\n\t\t\t\titem->fallSpeed = 50;\n\t\t\t\titem->gravity = 1;\n\t\t\t}\n\t\t\tif (item->touchBits) {\n\t\t\t\tLaraItem->hitPoints -= 200;\n\t\t\t\tLaraItem->hit_status = 1;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\titem->gravity = 0;\n\t\t\tbreak;\n\t}\n\tAnimateItem(item);\n\tif (item->status == ITEM_DISABLED) {\n\t\tRemoveActiveItem(itemID);\n\t} else {\n\t\troomID = item->roomNumber;\n\t\tfloor = GetFloor(item->pos.x, item->pos.y, item->pos.z, &roomID);\n\t\tif (item->roomNumber != roomID)\n\t\t\tItemNewRoom(itemID, roomID);\n\t\titem->floor = GetHeight(floor, item->pos.x, item->pos.y, item->pos.z);\n\t\tif (item->currentAnimState == 2 && item->pos.y >= item->floor) {\n\t\t\titem->gravity = 0;\n\t\t\titem->goalAnimState = 3;\n\t\t\titem->pos.y = item->floor;\n\t\t\titem->fallSpeed = 0;\n\t\t\titem->meshBits = 0x2B;\n\t\t}\n\t}\n}\n\nvoid __cdecl InitialiseBlade(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\titem->animNumber = Objects[ID_BLADE].animIndex + 2;\n\titem->currentAnimState = 1;\n\titem->frameNumber = Anims[item->animNumber].frameBase;\n}\n\nvoid __cdecl BladeControl(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\tif (TriggerActive(item) && item->currentAnimState == 1) {\n\t\titem->goalAnimState = 2;\n\t} else {\n\t\titem->goalAnimState = 1;\n\t}\n\tif (CHK_ANY(item->touchBits, 2) && item->currentAnimState == 2) {\n\t\tLaraItem->hit_status = 1;\n\t\tLaraItem->hitPoints -= 100;\n\t\tDoLotsOfBlood(LaraItem->pos.x, item->pos.y - 256, LaraItem->pos.z, LaraItem->speed, LaraItem->pos.rotY, LaraItem->roomNumber, 2);\n\t}\n\tAnimateItem(item);\n}\n\nvoid __cdecl InitialiseKillerStatue(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\titem->animNumber = Objects[item->objectID].animIndex + 3;\n\titem->currentAnimState = 1;\n\titem->frameNumber = Anims[item->animNumber].frameBase;\n}\n\nvoid __cdecl KillerStatueControl(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\tif (TriggerActive(item) && item->currentAnimState == 1) {\n\t\titem->goalAnimState = 2;\n\t} else {\n\t\titem->goalAnimState = 1;\n\t}\n\tif (CHK_ANY(item->touchBits, 0x80) && item->currentAnimState == 2) {\n\t\tLaraItem->hit_status = 1;\n\t\tLaraItem->hitPoints -= 20;\n\t\tDoBloodSplat(LaraItem->pos.x + (GetRandomControl() - 16384) / 256,\n\t\t\t\t\tLaraItem->pos.y - GetRandomControl() / 44,\n\t\t\t\t\tLaraItem->pos.z + (GetRandomControl() - 16384) / 256,\n\t\t\t\t\tLaraItem->speed,\n\t\t\t\t\tLaraItem->pos.rotY + (GetRandomControl() - 16384) / 8,\n\t\t\t\t\tLaraItem->roomNumber);\n\t}\n\tAnimateItem(item);\n}\n\nvoid __cdecl Pendulum(__int16 itemID) {\n\tITEM_INFO *item;\n\n\titem = &Items[itemID];\n\tif (item->touchBits) {\n\t\tLaraItem->hitPoints -= 50;\n\t\tLaraItem->hit_status = 1;\n\t\tDoBloodSplat(LaraItem->pos.x + (GetRandomControl() - 16384) / 256,\n\t\t\t\t\tLaraItem->pos.y - GetRandomControl() / 44,\n\t\t\t\t\tLaraItem->pos.z + (GetRandomControl() - 16384) / 256,\n\t\t\t\t\tLaraItem->speed,\n\t\t\t\t\tLaraItem->pos.rotY + (GetRandomControl() - 16384) / 8,\n\t\t\t\t\tLaraItem->roomNumber);\n\t}\n\titem->floor = GetHeight(GetFloor(item->pos.x, item->pos.y, item->pos.z, &item->roomNumber), item->pos.x, item->pos.y, item->pos.z);\n\tAnimateItem(item);\n}\n\nvoid __cdecl TeethTrap(__int16 itemID) {\n\tITEM_INFO *item;\n\tstatic BITE_INFO Teeth[3][2] = {\n\t\t{{-23, 0, -1718, 0}, {71, 0, -1718, 1}},\n\t\t{{-23, 10, -1718, 0}, {71, 10, -1718, 1}},\n\t\t{{-23, -10, -1718, 0}, {71, -10, -1718, 1}}\n\t};\n\n\titem = &Items[itemID];\n\tif (TriggerActive(item)) {\n\t\titem->goalAnimState = 1;\n\t\tif (item->touchBits && item->currentAnimState == 1) {\n\t\t\tLaraItem->hitPoints -= 400;\n\t\t\tLaraItem->hit_status = 1;\n\t\t\tBaddieBiteEffect(item, &Teeth[0][0]);\n\t\t\tBaddieBiteEffect(item, &Teeth[0][1]);\n\t\t\tBaddieBiteEffect(item, &Teeth[1][0]);\n\t\t\tBaddieBiteEffect(item, &Teeth[1][1]);\n\t\t\tBaddieBiteEffect(item, &Teeth[2][0]);\n\t\t\tBaddieBiteEffect(item, &Teeth[2][1]);\n\t\t}\n\t} else {\n\t\titem->goalAnimState = 0;\n\t}\n\tAnimateItem(item);\n}\n\nvoid __cdecl FallingCeiling(__int16 itemID) {\n\tITEM_INFO *item;\n\t__int16 roomID;\n\n\titem = &Items[itemID];\n\tif (!item->currentAnimState) {\n\t\titem->gravity = 1;\n\t\titem->goalAnimState = 1;\n\t} else {\n\t\tif (item->currentAnimState == 1 && item->touchBits) {\n\t\t\tLaraItem->hitPoints -= 300;\n\t\t\tLaraItem->hit_status = 1;\n\t\t}\n\t}\n\tAnimateItem(item);\n\tif (item->status == ITEM_DISABLED) {\n\t\tRemoveActiveItem(itemID);\n\t} else {\n\t\troomID = item->roomNumber;\n\t\titem->floor = GetHeight(GetFloor(item->pos.x, item->pos.y, item->pos.z, &roomID), item->pos.x, item->pos.y, item->pos.z);\n\t\tif (roomID != item->roomNumber)\n\t\t\tItemNewRoom(itemID, roomID);\n\t\tif (item->currentAnimState == 1 && item->pos.y >= item->floor) {\n\t\t\titem->gravity = 0;\n\t\t\titem->goalAnimState = 2;\n\t\t\titem->pos.y = item->floor;\n\t\t\titem->fallSpeed = 0;\n\t\t}\n\t}\n}\n\nvoid __cdecl DartEmitterControl(__int16 itemID) {\n\tITEM_INFO *item, *dynamic;\n\t__int16 dynamicID;\n\tint dx, dz;\n\n\titem = &Items[itemID];\n\tif (TriggerActive(item)) {\n\t\tif (!item->currentAnimState)\n\t\t\titem->goalAnimState = 1;\n\t} else {\n\t\tif (item->currentAnimState == 1)\n\t\t\titem->goalAnimState = 0;\n\t}\n\tif (item->currentAnimState == 1 && item->frameNumber == Anims[item->animNumber].frameBase) {\n\t\tdynamicID = CreateItem();\n\t\tif (dynamicID != -1) {\n\t\t\tdynamic = &Items[dynamicID];\n\t\t\tdynamic->objectID = ID_DARTS;\n\t\t\tdynamic->roomNumber = item->roomNumber;\n\t\t\tdynamic->shade1 = -1;\n\t\t\tdynamic->pos.rotY = item->pos.rotY;\n\t\t\tdynamic->pos.y = item->pos.y - 512;\n\t\t\tdz = 0;\n\t\t\tdx = 0;\n\t\t\tif (dynamic->pos.rotY <= -PHD_90) {\n\t\t\t\tif (dynamic->pos.rotY == -PHD_90) {\n\t\t\t\t\tdx = 412;\n\t\t\t\t} else {\n\t\t\t\t\tif (dynamic->pos.rotY == -PHD_180)\n\t\t\t\t\t\tdz = 412;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (!dynamic->pos.rotY) {\n\t\t\t\t\tdz = -412;\n\t\t\t\t} else {\n\t\t\t\t\tif (dynamic->pos.rotY == PHD_90)\n\t\t\t\t\t\tdx = -412;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdynamic->pos.x = item->pos.x + dx;\n\t\t\tdynamic->pos.z = item->pos.z + dz;\n\t\t\tInitialiseItem(dynamicID);\n\t\t\tAddActiveItem(dynamicID);\n\t\t\tdynamic->status = ITEM_ACTIVE;\n\t\t\tPlaySoundEffect(254, &dynamic->pos, 0);\n\t\t}\n\t}\n\tAnimateItem(item);\n}\n\nvoid __cdecl DartsControl(__int16 itemID) {\n\tITEM_INFO *item;\n\t__int16 roomID, fxID;\n\tFLOOR_INFO *floor;\n\tFX_INFO *fx;\n\n\titem = &Items[itemID];\n\tif (item->touchBits) {\n\t\tLaraItem->hitPoints -= 50;\n\t\tLaraItem->hit_status = 1;\n\t\tDoBloodSplat(item->pos.x, item->pos.y, item->pos.z, LaraItem->speed, LaraItem->pos.rotY, LaraItem->roomNumber);\n\t}\n\tAnimateItem(item);\n\troomID = item->roomNumber;\n\tfloor = GetFloor(item->pos.x, item->pos.y, item->pos.z, &roomID);\n\tif (item->roomNumber != roomID)\n\t\tItemNewRoom(itemID, roomID);\n\titem->floor = GetHeight(floor, item->pos.x, item->pos.y, item->pos.z);\n\titem->pos.rotX += PHD_45 / 2;\n\tif (item->pos.y >= item->floor) {\n\t\tKillItem(itemID);\n\t\tfxID = CreateEffect(item->roomNumber);\n\t\tif (fxID != -1) {\n\t\t\tfx = &Effects[fxID];\n\t\t\tfx->pos = item->pos;\n\t\t\tfx->speed = 0;\n\t\t\tfx->counter = 6;\n\t\t\tfx->object_number = ID_RICOCHET;\n\t\t\tfx->frame_number = -3 * GetRandomControl() / 32768;\n\t\t}\n\t\tPlaySoundEffect(258, &item->pos, 0);\n\t}\n}\n\nvoid __cdecl DartEffectControl(__int16 fxID) {\n\tFX_INFO *fx;\n\n\tfx = &Effects[fxID];\n\t++fx->counter;\n\tif (fx->counter >= 3) {\n\t\t--fx->frame_number;\n\t\tfx->counter = 0;\n\t\tif (fx->frame_number <= Objects[fx->object_number].nMeshes)\n\t\t\tKillEffect(fxID);\n\t}\n}\n\nvoid __cdecl FlameEmitterControl(__int16 item_id) {\n\tITEM_INFO *item;\n\t__int16 fxID;\n\tFX_INFO *fx;\n\n\titem = &Items[item_id];\n\tif (TriggerActive(item)) {\n\t\tif (!item->data) {\n\t\t\tfxID = CreateEffect(item->roomNumber);\n\t\t\tif (fxID != -1) {\n\t\t\t\tfx = &Effects[fxID];\n\t\t\t\tfx->pos.x = item->pos.x;\n\t\t\t\tfx->pos.y = item->pos.y;\n\t\t\t\tfx->pos.z = item->pos.z;\n\t\t\t\tfx->frame_number = 0;\n\t\t\t\tfx->object_number = ID_FLAME;\n\t\t\t\tfx->counter = 0;\n\t\t\t}\n\t\t\titem->data = (LPVOID) (fxID + 1);\n\t\t}\n\t} else {\n\t\tif (item->data) {\n\t\t\tKillEffect((int) item->data - 1);\n\t\t\titem->data = (LPVOID) 0;\n\t\t}\n\t}\n}\n\nvoid __cdecl FlameControl(__int16 fx_id) {\n\tFX_INFO *fx = &Effects[fx_id];\n\tif( --fx->frame_number <= Objects[ID_FLAME].nMeshes ) {\n\t\tfx->frame_number = 0;\n\t}\n\tif( fx->counter < 0 ) {\n#ifdef FEATURE_CHEAT\n\t\tif( Lara.water_status == LWS_Cheat ) {\n\t\t\tfx->counter = 0;\n\t\t\tKillEffect(fx_id);\n\t\t\tLara.burn = 0;\n\t\t\treturn;\n\t\t}\n#endif // FEATURE_CHEAT\n\t\tfx->pos.x = 0;\n\t\tfx->pos.y = 0;\n\t\tfx->pos.z = ( fx->counter == -1 ) ? -100 : 0;\n\t\tGetJointAbsPosition(LaraItem, (PHD_VECTOR *)&fx->pos, -1 - fx->counter);\n\t\tif( LaraItem->roomNumber != fx->room_number ) {\n\t\t\tEffectNewRoom(fx_id, LaraItem->roomNumber);\n\t\t}\n\t\tint height = GetWaterHeight(fx->pos.x, fx->pos.y, fx->pos.z, fx->room_number);\n\t\tif( height != NO_HEIGHT && fx->pos.y > height ) {\n\t\t\tfx->counter = 0;\n\t\t\tKillEffect(fx_id);\n\t\t\tLara.burn = 0;\n\t\t} else {\n\t\t\tPlaySoundEffect(150, &fx->pos, 0);\n\t\t\tLaraItem->hitPoints -= 7;\n\t\t\tLaraItem->hit_status = 1;\n\t\t}\n\t} else {\n\t\tPlaySoundEffect(150, &fx->pos, 0);\n\t\tif( fx->counter ) {\n\t\t\t--fx->counter;\n\t\t} else if( ItemNearLara(&fx->pos, 600) ) {\n\t\t\tLaraItem->hitPoints -= 5;\n\t\t\tLaraItem->hit_status = 1;\n\t\t\tint dx = LaraItem->pos.x - fx->pos.x;\n\t\t\tint dz = LaraItem->pos.z - fx->pos.z;\n\t\t\tif( SQR(dx) + SQR(dz) < SQR(450) ) {\n\t\t\t\tfx->counter = 100;\n\t\t\t\tLaraBurn();\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid __cdecl LaraBurn() {\n#ifdef FEATURE_CHEAT\n\tif( Lara.water_status == LWS_Cheat ) {\n\t\treturn;\n\t}\n#endif // FEATURE_CHEAT\n\tif( Lara.burn ) {\n\t\treturn;\n\t}\n\n\t__int16 fx_id = CreateEffect(LaraItem->roomNumber);\n\tif( fx_id < 0 ) {\n\t\treturn;\n\t}\n\tFX_INFO *fx = &Effects[fx_id];\n\tfx->object_number = ID_FLAME;\n\tfx->frame_number = 0;\n\tfx->counter = -1;\n\tLara.burn = 1;\n}\n\nvoid __cdecl LavaBurn(ITEM_INFO *item) {\n#ifdef FEATURE_CHEAT\n\tif( Lara.water_status == LWS_Cheat ) {\n\t\treturn;\n\t}\n#endif // FEATURE_CHEAT\n\tif( item->hitPoints < 0 ) {\n\t\treturn;\n\t}\n\n\t__int16 room_number = item->roomNumber;\n\tFLOOR_INFO *floor = GetFloor(item->pos.x, 32000, item->pos.z, &room_number);\n\tif( item->floor != GetHeight(floor, item->pos.x, 32000, item->pos.z) ) {\n\t\treturn;\n\t}\n\n\titem->hit_status = 1;\n\titem->hitPoints = -1;\n\tfor( int i = 0; i < 10; ++i ) {\n\t\t__int16 fx_id = CreateEffect(item->roomNumber);\n\t\tif( fx_id < 0 ) continue;\n\t\tFX_INFO *fx = &Effects[fx_id];\n\t\tfx->object_number = ID_FLAME;\n\t\tfx->frame_number = Objects[ID_FLAME].nMeshes * GetRandomControl() / 0x7FFF;\n\t\tfx->counter = -1 - 24 * GetRandomControl() / 0x7FFF;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Traps() {\n\tINJECT(0x00440FC0, MineControl);\n\tINJECT(0x004411C0, ControlSpikeWall);\n\tINJECT(0x00441300, ControlCeilingSpikes);\n\tINJECT(0x00441420, HookControl);\n\n//\tINJECT(0x004414B0, PropellerControl);\n\n\tINJECT(0x00441640, SpinningBlade);\n\tINJECT(0x004417C0, IcicleControl);\n\tINJECT(0x004418C0, InitialiseBlade);\n\tINJECT(0x00441900, BladeControl);\n\tINJECT(0x004419A0, InitialiseKillerStatue);\n\tINJECT(0x004419F0, KillerStatueControl);\n\n//\tINJECT(0x00441B00, SpringBoardControl);\n//\tINJECT(0x00441BE0, InitialiseRollingBall);\n//\tINJECT(0x00441C20, RollingBallControl);\n//\tINJECT(0x00441F70, RollingBallCollision);\n//\tINJECT(0x004421C0, SpikeCollision);\n//\tINJECT(0x00442320, TrapDoorControl);\n//\tINJECT(0x00442370, TrapDoorFloor);\n//\tINJECT(0x004423B0, TrapDoorCeiling);\n//\tINJECT(0x004423F0, OnTrapDoor);\n\n\tINJECT(0x004424A0, Pendulum);\n\n//\tINJECT(0x004425B0, FallingBlock);\n//\tINJECT(0x004426C0, FallingBlockFloor);\n//\tINJECT(0x00442700, FallingBlockCeiling);\n\n\tINJECT(0x00442750, TeethTrap);\n\tINJECT(0x00442810, FallingCeiling);\n\tINJECT(0x004428F0, DartEmitterControl);\n\tINJECT(0x00442A30, DartsControl);\n\tINJECT(0x00442B90, DartEffectControl);\n\tINJECT(0x00442BE0, FlameEmitterControl);\n\tINJECT(0x00442C70, FlameControl);\n\tINJECT(0x00442DE0, LaraBurn);\n\tINJECT(0x00442E30, LavaBurn);\n\n//\tINJECT(0x00442F20, LavaSpray);\n//\tINJECT(0x00442FF0, ControlLavaBlob);\n}\n"
  },
  {
    "path": "game/traps.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef TRAPS_H_INCLUDED\n#define TRAPS_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n\nvoid __cdecl MineControl(__int16 mineID); // 0x00440FC0\nvoid __cdecl ControlSpikeWall(__int16 itemID); // 0x004411C0\nvoid __cdecl ControlCeilingSpikes(__int16 itemID); // 0x00441300\nvoid __cdecl HookControl(__int16 itemID); // 0x00441420\n\n//\t0x004414B0:\t\tPropellerControl\n\nvoid __cdecl SpinningBlade(__int16 itemID); // 0x00441640\nvoid __cdecl IcicleControl(__int16 itemID); // 0x004417C0\nvoid __cdecl InitialiseBlade(__int16 itemID); // 0x004418C0\nvoid __cdecl BladeControl(__int16 itemID); // 0x00441900\nvoid __cdecl InitialiseKillerStatue(__int16 itemID); // 0x004419A0\nvoid __cdecl KillerStatueControl(__int16 itemID); // 0x004419F0\n\n//\t0x00441B00:\t\tSpringBoardControl\n//\t0x00441BE0:\t\tInitialiseRollingBall\n//\t0x00441C20:\t\tRollingBallControl\n//\t0x00441F70:\t\tRollingBallCollision\n//\t0x004421C0:\t\tSpikeCollision\n//\t0x00442320:\t\tTrapDoorControl\n//\t0x00442370:\t\tTrapDoorFloor\n//\t0x004423B0:\t\tTrapDoorCeiling\n//\t0x004423F0:\t\tOnTrapDoor\n\nvoid __cdecl Pendulum(__int16 itemID); // 0x004424A0\n\n//\t0x004425B0:\t\tFallingBlock\n//\t0x004426C0:\t\tFallingBlockFloor\n//\t0x00442700:\t\tFallingBlockCeiling\n\nvoid __cdecl TeethTrap(__int16 itemID); // 0x00442750\nvoid __cdecl FallingCeiling(__int16 itemID); // 0x00442810\nvoid __cdecl DartEmitterControl(__int16 itemID); // 0x004428F0\nvoid __cdecl DartsControl(__int16 itemID); // 0x00442A30\nvoid __cdecl DartEffectControl(__int16 fxID); // 0x00442B90\nvoid __cdecl FlameEmitterControl(__int16 item_id); // 0x00442BE0\nvoid __cdecl FlameControl(__int16 fx_id); // 0x00442C70\nvoid __cdecl LaraBurn(); // 0x00442DE0\nvoid __cdecl LavaBurn(ITEM_INFO *item); // 0x00442E30\n\n//\t0x00442F20:\t\tLavaSpray\n//\t0x00442FF0:\t\tControlLavaBlob\n\n#endif // TRAPS_H_INCLUDED\n"
  },
  {
    "path": "game/wolf.cpp",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/wolf.h\"\n#include \"game/box.h\"\n#include \"game/effects.h\"\n#include \"game/lot.h\"\n#include \"specific/game.h\"\n#include \"global/vars.h\"\n\n#define WOLF_TOUCH (0x774F)\n\ntypedef enum {\n\tWOLF_EMPTY,\n\tWOLF_STOP,\n\tWOLF_WALK,\n\tWOLF_RUN,\n\tWOLF_JUMP,\n\tWOLF_STALK,\n\tWOLF_ATTACK,\n\tWOLF_HOWL,\n\tWOLF_SLEEP,\n\tWOLF_CROUCH,\n\tWOLF_FASTTURN,\n\tWOLF_DEATH,\n\tWOLF_BITE\n} WOLF_ANIMS;\n\nstatic const BITE_INFO WolfBite = {\n\t0, -14, 174, 6\n};\n\nvoid __cdecl InitialiseWolf(__int16 itemID) {\n\tItems[itemID].frameNumber = 96; // lying wolf frame (hardcoded thing)\n\tInitialiseCreature(itemID);\n}\n\nvoid __cdecl WolfControl(__int16 itemID) {\n\tITEM_INFO *item = &Items[itemID];\n\n\tif( item->status == ITEM_INVISIBLE ) {\n\t\tif( !EnableBaddieAI(itemID, FALSE) ) {\n\t\t\treturn;\n\t\t}\n\t\titem->status = ITEM_ACTIVE;\n\t}\n\n\tCREATURE_INFO *wolf = (CREATURE_INFO *)item->data;\n\tif( wolf == NULL ) return; // NOTE: additional check not presented in the original game\n\n\t__int16 angle = 0;\n\t__int16 head = 0;\n\t__int16 tilt = 0;\n\n\tif( item->hitPoints <= 0 ) {\n\t\tif( item->currentAnimState != WOLF_DEATH ) {\n\t\t\t// some hardcoded death animation start\n\t\t\titem->animNumber = Objects[ID_SPIDER_or_WOLF].animIndex + GetRandomControl() / 11000 + 20;\n\t\t\titem->frameNumber = Anims[item->animNumber].frameBase;\n\t\t\titem->currentAnimState = WOLF_DEATH;\n\t\t}\n\t} else {\n\t\tAI_INFO info;\n\n\t\tCreatureAIInfo(item, &info);\n\t\tif( info.ahead ) {\n\t\t\thead = info.angle;\n\t\t}\n\t\tCreatureMood(item, &info, FALSE);\n\t\tangle = CreatureTurn(item, wolf->maximum_turn);\n\n\t\tswitch ( item->currentAnimState ) {\n\t\t\tcase WOLF_SLEEP :\n\t\t\t\thead = 0;\n\t\t\t\tif( wolf->mood == MOOD_ESCAPE || info.zone_number == info.enemy_zone ) {\n\t\t\t\t\titem->requiredAnimState = WOLF_CROUCH;\n\t\t\t\t\titem->goalAnimState = WOLF_STOP;\n\t\t\t\t} else if( GetRandomControl() < 0x20 ) {\n\t\t\t\t\titem->requiredAnimState = WOLF_WALK;\n\t\t\t\t\titem->goalAnimState = WOLF_STOP;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase WOLF_STOP :\n\t\t\t\tif( item->requiredAnimState != WOLF_EMPTY ) {\n\t\t\t\t\titem->goalAnimState = item->requiredAnimState;\n\t\t\t\t} else {\n\t\t\t\t\titem->goalAnimState = WOLF_WALK;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase WOLF_WALK :\n\t\t\t\twolf->maximum_turn = 2*PHD_DEGREE;\n\t\t\t\tif( wolf->mood != MOOD_BORED ) {\n\t\t\t\t\titem->goalAnimState = WOLF_STALK;\n\t\t\t\t\titem->requiredAnimState = WOLF_EMPTY;\n\t\t\t\t} else if( GetRandomControl() < 0x20 ) {\n\t\t\t\t\titem->requiredAnimState = WOLF_SLEEP;\n\t\t\t\t\titem->goalAnimState = WOLF_STOP;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase WOLF_CROUCH :\n\t\t\t\tif( item->requiredAnimState != WOLF_EMPTY ) {\n\t\t\t\t\titem->goalAnimState = item->requiredAnimState;\n\t\t\t\t} else if( wolf->mood == MOOD_ESCAPE ) {\n\t\t\t\t\titem->goalAnimState = WOLF_RUN;\n\t\t\t\t} else if( info.distance < 0x1D0F1 && info.bite ) {\n\t\t\t\t\titem->goalAnimState = WOLF_BITE;\n\t\t\t\t} else if( wolf->mood == MOOD_STALK ) {\n\t\t\t\t\titem->goalAnimState = WOLF_STALK;\n\t\t\t\t} else if( wolf->mood == MOOD_BORED ) {\n\t\t\t\t\titem->goalAnimState = WOLF_STOP;\n\t\t\t\t} else {\n\t\t\t\t\titem->goalAnimState = WOLF_RUN;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase WOLF_STALK :\n\t\t\t\twolf->maximum_turn = 2*PHD_DEGREE;\n\t\t\t\tif( wolf->mood == MOOD_ESCAPE ) {\n\t\t\t\t\titem->goalAnimState = WOLF_RUN;\n\t\t\t\t} else if( info.distance < 0x1D0F1 && info.bite ) {\n\t\t\t\t\titem->goalAnimState = WOLF_BITE;\n\t\t\t\t} else if( info.distance > 0x900000 ) {\n\t\t\t\t\titem->goalAnimState = WOLF_RUN;\n\t\t\t\t} else if( wolf->mood == MOOD_ATTACK ) {\n\t\t\t\t\tif( !info.ahead || info.distance > 0x240000 ||\n\t\t\t\t\t\t(info.enemy_facing < 0x4000 && info.enemy_facing > -0x4000) )\n\t\t\t\t\t{\n\t\t\t\t\t\titem->goalAnimState = WOLF_RUN;\n\t\t\t\t\t}\n\t\t\t\t} else if( GetRandomControl() < 0x180 ) {\n\t\t\t\t\titem->requiredAnimState = WOLF_HOWL;\n\t\t\t\t\titem->goalAnimState = WOLF_CROUCH;\n\t\t\t\t}\n\t\t\t\telse if( wolf->mood == MOOD_BORED ) {\n\t\t\t\t\titem->goalAnimState = WOLF_CROUCH;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase WOLF_RUN :\n\t\t\t\twolf->maximum_turn = 5*PHD_DEGREE;\n\t\t\t\ttilt = angle;\n\t\t\t\tif( info.ahead && info.distance < 0x240000 ) {\n\t\t\t\t\tif( info.distance > 0x120000 &&\n\t\t\t\t\t\t(info.enemy_facing > 0x4000 || info.enemy_facing < -0x4000) )\n\t\t\t\t\t{\n\t\t\t\t\t\titem->requiredAnimState = WOLF_STALK;\n\t\t\t\t\t\titem->goalAnimState = WOLF_CROUCH;\n\t\t\t\t\t} else {\n\t\t\t\t\t\titem->goalAnimState = WOLF_ATTACK;\n\t\t\t\t\t\titem->requiredAnimState = WOLF_EMPTY;\n\t\t\t\t\t}\n\t\t\t\t} else if( wolf->mood == MOOD_STALK && info.distance < 0x900000 ) {\n\t\t\t\t\titem->requiredAnimState = WOLF_STALK;\n\t\t\t\t\titem->goalAnimState = WOLF_CROUCH;\n\t\t\t\t} else if( wolf->mood == MOOD_BORED ) {\n\t\t\t\t\titem->goalAnimState = WOLF_CROUCH;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase WOLF_ATTACK :\n\t\t\t\ttilt = angle;\n\t\t\t\tif( item->requiredAnimState == WOLF_EMPTY &&\n\t\t\t\t\tCHK_ANY(item->touchBits, WOLF_TOUCH) )\n\t\t\t\t{\n\t\t\t\t\tCreatureEffect(item, &WolfBite, DoBloodSplat);\n\t\t\t\t\tLaraItem->hitPoints -= 50;\n\t\t\t\t\tLaraItem->hit_status = 1;\n\t\t\t\t\titem->requiredAnimState = WOLF_RUN;\n\t\t\t\t}\n\t\t\t\titem->goalAnimState = WOLF_RUN;\n\t\t\t\tbreak;\n\n\t\t\tcase WOLF_BITE :\n\t\t\t\tif( info.ahead &&\n\t\t\t\t\titem->requiredAnimState == WOLF_EMPTY &&\n\t\t\t\t\tCHK_ANY(item->touchBits, WOLF_TOUCH) )\n\t\t\t\t{\n\t\t\t\t\tCreatureEffect(item, &WolfBite, DoBloodSplat);\n\t\t\t\t\tLaraItem->hitPoints -= 100;\n\t\t\t\t\tLaraItem->hit_status = 1;\n\t\t\t\t\titem->requiredAnimState = WOLF_CROUCH;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tdefault :\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tCreatureTilt(item, tilt);\n\tCreatureHead(item, head);\n\tCreatureAnimation(itemID, angle, tilt);\n}\n\n/*\n * NOTE: there is no inject function for tomb2gold code\n */\n"
  },
  {
    "path": "game/wolf.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef WOLF_H_INCLUDED\n#define WOLF_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n// NOTE: these functions are presented in the \"Golden Mask\" only\nvoid __cdecl InitialiseWolf(__int16 itemID); // tomb2gold:0x004431C0\nvoid __cdecl WolfControl(__int16 itemID); // tomb2gold:0x004431F0\n\n#endif // WOLF_H_INCLUDED\n"
  },
  {
    "path": "game/yeti.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/yeti.h\"\n#include \"global/vars.h\"\n\n\n\n/*\n * Inject function\n */\nvoid Inject_Yeti() {\n//\tINJECT(0x00443100, GiantYetiControl);\n//\tINJECT(0x00443400, YetiControl);\n}\n"
  },
  {
    "path": "game/yeti.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef YETI_H_INCLUDED\n#define YETI_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#define GiantYetiControl ((void(__cdecl*)(__int16)) 0x00443100)\n#define YetiControl ((void(__cdecl*)(__int16)) 0x00443400)\n\n#endif // YETI_H_INCLUDED\n"
  },
  {
    "path": "global/md5.c",
    "content": "/*\n **********************************************************************\n ** md5.c                                                            **\n ** RSA Data Security, Inc. MD5 Message Digest Algorithm             **\n ** Created: 2/17/90 RLR                                             **\n ** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version                  **\n **********************************************************************\n */\n\n/*\n **********************************************************************\n ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **\n **                                                                  **\n ** License to copy and use this software is granted provided that   **\n ** it is identified as the \"RSA Data Security, Inc. MD5 Message     **\n ** Digest Algorithm\" in all material mentioning or referencing this **\n ** software or this function.                                       **\n **                                                                  **\n ** License is also granted to make and use derivative works         **\n ** provided that such works are identified as \"derived from the RSA **\n ** Data Security, Inc. MD5 Message Digest Algorithm\" in all         **\n ** material mentioning or referencing the derived work.             **\n **                                                                  **\n ** RSA Data Security, Inc. makes no representations concerning      **\n ** either the merchantability of this software or the suitability   **\n ** of this software for any particular purpose.  It is provided \"as **\n ** is\" without express or implied warranty of any kind.             **\n **                                                                  **\n ** These notices must be retained in any copies of any part of this **\n ** documentation and/or software.                                   **\n **********************************************************************\n */\n\n#include \"md5.h\"\n\n/* forward declaration */\nstatic void Transform (UINT4 *buf, UINT4 *in);\n\nstatic unsigned char PADDING[64] = {\n  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n};\n\n/* F, G and H are basic MD5 functions: selection, majority, parity */\n#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))\n#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))\n#define H(x, y, z) ((x) ^ (y) ^ (z))\n#define I(x, y, z) ((y) ^ ((x) | (~z)))\n\n/* ROTATE_LEFT rotates x left n bits */\n#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))\n\n/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */\n/* Rotation is separate from addition to prevent recomputation */\n#define FF(a, b, c, d, x, s, ac) \\\n  {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define GG(a, b, c, d, x, s, ac) \\\n  {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define HH(a, b, c, d, x, s, ac) \\\n  {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define II(a, b, c, d, x, s, ac) \\\n  {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n\nvoid MD5Init (MD5_CTX *mdContext)\n{\n  mdContext->i[0] = mdContext->i[1] = (UINT4)0;\n\n  /* Load magic initialization constants.\n   */\n  mdContext->buf[0] = (UINT4)0x67452301;\n  mdContext->buf[1] = (UINT4)0xefcdab89;\n  mdContext->buf[2] = (UINT4)0x98badcfe;\n  mdContext->buf[3] = (UINT4)0x10325476;\n}\n\nvoid MD5Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen)\n{\n  UINT4 in[16];\n  int mdi;\n  unsigned int i, ii;\n\n  /* compute number of bytes mod 64 */\n  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);\n\n  /* update number of bits */\n  if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])\n    mdContext->i[1]++;\n  mdContext->i[0] += ((UINT4)inLen << 3);\n  mdContext->i[1] += ((UINT4)inLen >> 29);\n\n  while (inLen--) {\n    /* add new character to buffer, increment mdi */\n    mdContext->in[mdi++] = *inBuf++;\n\n    /* transform if necessary */\n    if (mdi == 0x40) {\n      for (i = 0, ii = 0; i < 16; i++, ii += 4)\n        in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |\n                (((UINT4)mdContext->in[ii+2]) << 16) |\n                (((UINT4)mdContext->in[ii+1]) << 8) |\n                ((UINT4)mdContext->in[ii]);\n      Transform (mdContext->buf, in);\n      mdi = 0;\n    }\n  }\n}\n\nvoid MD5Final (MD5_CTX *mdContext)\n{\n  UINT4 in[16];\n  int mdi;\n  unsigned int i, ii;\n  unsigned int padLen;\n\n  /* save number of bits */\n  in[14] = mdContext->i[0];\n  in[15] = mdContext->i[1];\n\n  /* compute number of bytes mod 64 */\n  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);\n\n  /* pad out to 56 mod 64 */\n  padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);\n  MD5Update (mdContext, PADDING, padLen);\n\n  /* append length in bits and transform */\n  for (i = 0, ii = 0; i < 14; i++, ii += 4)\n    in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |\n            (((UINT4)mdContext->in[ii+2]) << 16) |\n            (((UINT4)mdContext->in[ii+1]) << 8) |\n            ((UINT4)mdContext->in[ii]);\n  Transform (mdContext->buf, in);\n\n  /* store buffer in digest */\n  for (i = 0, ii = 0; i < 4; i++, ii += 4) {\n    mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);\n    mdContext->digest[ii+1] =\n      (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);\n    mdContext->digest[ii+2] =\n      (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);\n    mdContext->digest[ii+3] =\n      (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);\n  }\n}\n\n/* Basic MD5 step. Transform buf based on in.\n */\nstatic void Transform (UINT4 *buf, UINT4 *in)\n{\n  UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];\n\n  /* Round 1 */\n#define S11 7\n#define S12 12\n#define S13 17\n#define S14 22\n  FF ( a, b, c, d, in[ 0], S11, 3614090360); /* 1 */\n  FF ( d, a, b, c, in[ 1], S12, 3905402710); /* 2 */\n  FF ( c, d, a, b, in[ 2], S13,  606105819); /* 3 */\n  FF ( b, c, d, a, in[ 3], S14, 3250441966); /* 4 */\n  FF ( a, b, c, d, in[ 4], S11, 4118548399); /* 5 */\n  FF ( d, a, b, c, in[ 5], S12, 1200080426); /* 6 */\n  FF ( c, d, a, b, in[ 6], S13, 2821735955); /* 7 */\n  FF ( b, c, d, a, in[ 7], S14, 4249261313); /* 8 */\n  FF ( a, b, c, d, in[ 8], S11, 1770035416); /* 9 */\n  FF ( d, a, b, c, in[ 9], S12, 2336552879); /* 10 */\n  FF ( c, d, a, b, in[10], S13, 4294925233); /* 11 */\n  FF ( b, c, d, a, in[11], S14, 2304563134); /* 12 */\n  FF ( a, b, c, d, in[12], S11, 1804603682); /* 13 */\n  FF ( d, a, b, c, in[13], S12, 4254626195); /* 14 */\n  FF ( c, d, a, b, in[14], S13, 2792965006); /* 15 */\n  FF ( b, c, d, a, in[15], S14, 1236535329); /* 16 */\n\n  /* Round 2 */\n#define S21 5\n#define S22 9\n#define S23 14\n#define S24 20\n  GG ( a, b, c, d, in[ 1], S21, 4129170786); /* 17 */\n  GG ( d, a, b, c, in[ 6], S22, 3225465664); /* 18 */\n  GG ( c, d, a, b, in[11], S23,  643717713); /* 19 */\n  GG ( b, c, d, a, in[ 0], S24, 3921069994); /* 20 */\n  GG ( a, b, c, d, in[ 5], S21, 3593408605); /* 21 */\n  GG ( d, a, b, c, in[10], S22,   38016083); /* 22 */\n  GG ( c, d, a, b, in[15], S23, 3634488961); /* 23 */\n  GG ( b, c, d, a, in[ 4], S24, 3889429448); /* 24 */\n  GG ( a, b, c, d, in[ 9], S21,  568446438); /* 25 */\n  GG ( d, a, b, c, in[14], S22, 3275163606); /* 26 */\n  GG ( c, d, a, b, in[ 3], S23, 4107603335); /* 27 */\n  GG ( b, c, d, a, in[ 8], S24, 1163531501); /* 28 */\n  GG ( a, b, c, d, in[13], S21, 2850285829); /* 29 */\n  GG ( d, a, b, c, in[ 2], S22, 4243563512); /* 30 */\n  GG ( c, d, a, b, in[ 7], S23, 1735328473); /* 31 */\n  GG ( b, c, d, a, in[12], S24, 2368359562); /* 32 */\n\n  /* Round 3 */\n#define S31 4\n#define S32 11\n#define S33 16\n#define S34 23\n  HH ( a, b, c, d, in[ 5], S31, 4294588738); /* 33 */\n  HH ( d, a, b, c, in[ 8], S32, 2272392833); /* 34 */\n  HH ( c, d, a, b, in[11], S33, 1839030562); /* 35 */\n  HH ( b, c, d, a, in[14], S34, 4259657740); /* 36 */\n  HH ( a, b, c, d, in[ 1], S31, 2763975236); /* 37 */\n  HH ( d, a, b, c, in[ 4], S32, 1272893353); /* 38 */\n  HH ( c, d, a, b, in[ 7], S33, 4139469664); /* 39 */\n  HH ( b, c, d, a, in[10], S34, 3200236656); /* 40 */\n  HH ( a, b, c, d, in[13], S31,  681279174); /* 41 */\n  HH ( d, a, b, c, in[ 0], S32, 3936430074); /* 42 */\n  HH ( c, d, a, b, in[ 3], S33, 3572445317); /* 43 */\n  HH ( b, c, d, a, in[ 6], S34,   76029189); /* 44 */\n  HH ( a, b, c, d, in[ 9], S31, 3654602809); /* 45 */\n  HH ( d, a, b, c, in[12], S32, 3873151461); /* 46 */\n  HH ( c, d, a, b, in[15], S33,  530742520); /* 47 */\n  HH ( b, c, d, a, in[ 2], S34, 3299628645); /* 48 */\n\n  /* Round 4 */\n#define S41 6\n#define S42 10\n#define S43 15\n#define S44 21\n  II ( a, b, c, d, in[ 0], S41, 4096336452); /* 49 */\n  II ( d, a, b, c, in[ 7], S42, 1126891415); /* 50 */\n  II ( c, d, a, b, in[14], S43, 2878612391); /* 51 */\n  II ( b, c, d, a, in[ 5], S44, 4237533241); /* 52 */\n  II ( a, b, c, d, in[12], S41, 1700485571); /* 53 */\n  II ( d, a, b, c, in[ 3], S42, 2399980690); /* 54 */\n  II ( c, d, a, b, in[10], S43, 4293915773); /* 55 */\n  II ( b, c, d, a, in[ 1], S44, 2240044497); /* 56 */\n  II ( a, b, c, d, in[ 8], S41, 1873313359); /* 57 */\n  II ( d, a, b, c, in[15], S42, 4264355552); /* 58 */\n  II ( c, d, a, b, in[ 6], S43, 2734768916); /* 59 */\n  II ( b, c, d, a, in[13], S44, 1309151649); /* 60 */\n  II ( a, b, c, d, in[ 4], S41, 4149444226); /* 61 */\n  II ( d, a, b, c, in[11], S42, 3174756917); /* 62 */\n  II ( c, d, a, b, in[ 2], S43,  718787259); /* 63 */\n  II ( b, c, d, a, in[ 9], S44, 3951481745); /* 64 */\n\n  buf[0] += a;\n  buf[1] += b;\n  buf[2] += c;\n  buf[3] += d;\n}\n\n/*\n **********************************************************************\n ** End of md5.c                                                     **\n ******************************* (cut) ********************************\n */\n"
  },
  {
    "path": "global/md5.h",
    "content": "/*\n **********************************************************************\n ** md5.h -- Header file for implementation of MD5                   **\n ** RSA Data Security, Inc. MD5 Message Digest Algorithm             **\n ** Created: 2/17/90 RLR                                             **\n ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version              **\n ** Revised (for MD5): RLR 4/27/91                                   **\n **   -- G modified to have y&~z instead of y&z                      **\n **   -- FF, GG, HH modified to add in last register done            **\n **   -- Access pattern: round 2 works mod 5, round 3 works mod 3    **\n **   -- distinct additive constant for each step                    **\n **   -- round 4 added, working mod 7                                **\n **********************************************************************\n */\n\n/*\n **********************************************************************\n ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **\n **                                                                  **\n ** License to copy and use this software is granted provided that   **\n ** it is identified as the \"RSA Data Security, Inc. MD5 Message     **\n ** Digest Algorithm\" in all material mentioning or referencing this **\n ** software or this function.                                       **\n **                                                                  **\n ** License is also granted to make and use derivative works         **\n ** provided that such works are identified as \"derived from the RSA **\n ** Data Security, Inc. MD5 Message Digest Algorithm\" in all         **\n ** material mentioning or referencing the derived work.             **\n **                                                                  **\n ** RSA Data Security, Inc. makes no representations concerning      **\n ** either the merchantability of this software or the suitability   **\n ** of this software for any particular purpose.  It is provided \"as **\n ** is\" without express or implied warranty of any kind.             **\n **                                                                  **\n ** These notices must be retained in any copies of any part of this **\n ** documentation and/or software.                                   **\n **********************************************************************\n */\n#ifndef MD5_H_INCLUDED\n#define MD5_H_INCLUDED\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/* typedef a 32 bit type */\ntypedef unsigned long int UINT4;\n\n/* Data structure for MD5 (Message Digest) computation */\ntypedef struct {\n  UINT4 i[2];                   /* number of _bits_ handled mod 2^64 */\n  UINT4 buf[4];                                    /* scratch buffer */\n  unsigned char in[64];                              /* input buffer */\n  unsigned char digest[16];     /* actual digest after MD5Final call */\n} MD5_CTX;\n\nvoid MD5Init (MD5_CTX *mdContext);\nvoid MD5Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen);\nvoid MD5Final (MD5_CTX *mdContext);\n\n#ifdef __cplusplus\n} /* extern \"C\" */\n#endif\n\n#endif // MD5_H_INCLUDED\n/*\n **********************************************************************\n ** End of md5.h                                                     **\n ******************************* (cut) ********************************\n */\n"
  },
  {
    "path": "global/memmem.c",
    "content": "/*-\n * Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n * 3. The name of the author may not be used to endorse or promote\n *    products derived from this software without specific prior written\n *    permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n */\n\n#include <string.h>\n\n/*\n * Find the first occurrence of the byte string s in byte string l.\n */\n\nvoid *\nmemmem(const void *l, size_t l_len, const void *s, size_t s_len)\n{\n\tregister char *cur, *last;\n\tconst char *cl = (const char *)l;\n\tconst char *cs = (const char *)s;\n\n\t/* we need something to compare */\n\tif (l_len == 0 || s_len == 0)\n\t\treturn NULL;\n\n\t/* \"s\" must be smaller or equal to \"l\" */\n\tif (l_len < s_len)\n\t\treturn NULL;\n\n\t/* special case where s_len == 1 */\n\tif (s_len == 1)\n\t\treturn memchr(l, (int)*cs, l_len);\n\n\t/* the last position where its possible to find \"s\" in \"l\" */\n\tlast = (char *)cl + l_len - s_len;\n\n\tfor (cur = (char *)cl; cur <= last; cur++)\n\t\tif (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)\n\t\t\treturn cur;\n\n\treturn NULL;\n}\n"
  },
  {
    "path": "global/memmem.h",
    "content": "/*-\n * Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n * 3. The name of the author may not be used to endorse or promote\n *    products derived from this software without specific prior written\n *    permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n */\n\n#ifndef MEMMEM_H_INCLUDED\n#define MEMMEM_H_INCLUDED\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*\n * Find the first occurrence of the byte string s in byte string l.\n */\nvoid *memmem(const void *l, size_t l_len, const void *s, size_t s_len);\n\n#ifdef __cplusplus\n} /* extern \"C\" */\n#endif\n\n#endif // MEMMEM_H_INCLUDED\n"
  },
  {
    "path": "global/precompiled.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef TR2MAIN_PRECOMPILED_HEADER\n#define TR2MAIN_PRECOMPILED_HEADER\n\n// There is no DirectInput above 8.0\n#if (DIRECTINPUT_VERSION > 0x800)\n#undef DIRECTINPUT_VERSION\n#define DIRECTINPUT_VERSION (0x800)\n#endif // (DIRECTINPUT_VERSION > 0x800)\n\n// There is no DirectSound above 9.0\n#if (DIRECTSOUND_VERSION > 0x900)\n#undef DIRECTSOUND_VERSION\n#define DIRECTSOUND_VERSION (0x900)\n#endif // (DIRECTSOUND_VERSION > 0x900)\n\n// Some defines are required for DX9 and above\n#if (DIRECT3D_VERSION >= 0x900)\n#ifndef FEATURE_NOLEGACY_OPTIONS\n#define FEATURE_NOLEGACY_OPTIONS\n#endif // !FEATURE_NOLEGACY_OPTIONS\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n#include <stdio.h>\n#include <windows.h>\n#include <shlobj.h>\n#include <shlwapi.h>\n#include <dinput.h>\n#include <dsound.h>\n\n#if (DIRECT3D_VERSION >= 0x900)\n#include <d3d9.h>\n#include <d3dx9.h>\n#else // (DIRECT3D_VERSION >= 0x900)\n#include <ddraw.h>\n#include <d3d.h>\n#endif // (DIRECT3D_VERSION >= 0x900)\n#endif // TR2MAIN_PRECOMPILED_HEADER\n"
  },
  {
    "path": "global/resource.h",
    "content": "/*\r\n * Copyright (c) 2017 Michael Chaban. All rights reserved.\r\n * Original game is created by Core Design Ltd. in 1997.\r\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\r\n *\r\n * This file is part of TR2Main.\r\n *\r\n * TR2Main is free software: you can redistribute it and/or modify\r\n * it under the terms of the GNU General Public License as published by\r\n * the Free Software Foundation, either version 3 of the License, or\r\n * (at your option) any later version.\r\n *\r\n * TR2Main is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n * GNU General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU General Public License\r\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\r\n */\r\n\r\n#ifndef RESOURCE_H_INCLUDED\r\n#define RESOURCE_H_INCLUDED\r\n\r\n#define RESOURCE_H_INCLUDED\r\n\r\n// String table\r\n#define IDS_DX5_REQUIRED\t\t\t\t1\r\n\r\n// Icon groups\r\n#define IDI_MAINICON\t\t\t\t\t100\r\n#define IDI_ICON_01\t\t\t\t\t\t133\r\n#define IDI_ICON_02\t\t\t\t\t\t146\r\n#define IDI_ICON_03\t\t\t\t\t\t147\r\n#define IDI_ICON_04\t\t\t\t\t\t148\r\n#define IDI_ICON_05\t\t\t\t\t\t149\r\n#define IDI_ICON_06\t\t\t\t\t\t150\r\n#define IDI_ICON_07\t\t\t\t\t\t151\r\n#define IDI_ICON_08\t\t\t\t\t\t152\r\n#define IDI_ICON_09\t\t\t\t\t\t153\r\n#define IDI_ICON_10\t\t\t\t\t\t154\r\n#define IDI_ICON_11\t\t\t\t\t\t155\r\n#define IDI_ICON_12\t\t\t\t\t\t156\r\n\r\n// General resources\r\n#define IDR_WAVESAMPLE\t\t\t\t\t163\r\n\r\n// Options Dialog\r\n#define IDD_OPTIONS\t\t\t\t\t\t110\r\n#define ID_OPTNS_WINDOW_IMAGE\t\t\t1073\r\n#define ID_OPTNS_STATIC_GRAPHICS\t\t1077\r\n#define ID_OPTNS_STATIC_USING\t\t\t1078\r\n#define ID_OPTNS_STATIC_DISPLAY\t\t\t1079\r\n#define ID_OPTNS_STATIC_OPTIONS\t\t\t1080\r\n#define ID_OPTNS_STATIC_SOUND\t\t\t1081\r\n#define ID_OPTNS_STATIC_SFX\t\t\t\t1082\r\n#define ID_OPTNS_STATIC_JOYSTICK\t\t1084\r\n#define ID_OPTNS_STATIC_MIC\t\t\t\t1085\r\n\r\n// Graphics Dialog\r\n#define IDD_GRAPHICS\t\t\t\t\t107\r\n#define ID_GRAPH_COMBOBOX_ADAPTER\t\t1025\r\n#define ID_GRAPH_BUTTON_SWRENDER\t\t1045\r\n#define ID_GRAPH_BUTTON_HWRENDER\t\t1047\r\n#define ID_GRAPH_BUTTON_ZBUFFER\t\t\t1017\r\n#define ID_GRAPH_BUTTON_BILINEAR\t\t1018\r\n#define ID_GRAPH_BUTTON_DITHER\t\t\t1058\r\n#define ID_GRAPH_BUTTON_TRIPLEBUFFER\t1048\r\n#define ID_GRAPH_BUTTON_PERSPECTIVE\t\t1015\r\n#define ID_GRAPH_BUTTON_FULLSCREEN\t\t1030\r\n#define ID_GRAPH_BUTTON_WINDOWED\t\t1031\r\n#define ID_GRAPH_COMBOBOX_FULLSCREEN\t1000\r\n#define ID_GRAPH_SLIDER_WINDOWED\t\t1034\r\n#define ID_GRAPH_BUTTON_ASPECT_4_3\t\t1060\r\n#define ID_GRAPH_BUTTON_ASPECT_16_9\t\t1061\r\n#define ID_GRAPH_BUTTON_ASPECT_ANY\t\t1062\r\n#define ID_GRAPH_BUTTON_TEST\t\t\t1029\r\n#define ID_GRAPH_GROUPBOX_ADAPTER\t\t1041\r\n#define ID_GRAPH_GROUPBOX_RENDER\t\t1049\r\n#define ID_GRAPH_GROUPBOX_OPTIONS\t\t1051\r\n#define ID_GRAPH_GROUPBOX_DISPLAY\t\t1050\r\n#define ID_GRAPH_GROUPBOX_FULLSCREEN\t1038\r\n#define ID_GRAPH_GROUPBOX_WINDOWED\t\t1037\r\n#define ID_GRAPH_STATIC_RES_SMALL\t\t1039\r\n#define ID_GRAPH_STATIC_RESOLUTION\t\t1035\r\n#define ID_GRAPH_STATIC_RES_LARGE\t\t1040\r\n#define ID_GRAPH_GROUPBOX_TEST\t\t\t1044\r\n#define ID_GRAPH_STATIC_TESTRESULT\t\t1043\r\n#define ID_GRAPH_STATIC_TESTDETAIL\t\t1046\r\n#define ID_GRAPH_BUTTON_DEFAULT\t\t\t1112\r\n\r\n// Sound Dialog\r\n#define IDD_SOUND\t\t\t\t\t\t108\r\n#define ID_SOUND_COMBOBOX_ADAPTER\t\t1052\r\n#define ID_SOUND_BUTTON_MIC_CAMERA\t\t1086\r\n#define ID_SOUND_BUTTON_MIC_LARA\t\t1087\r\n#define ID_SOUND_BUTTON_SFX_ENABLE\t\t1057\r\n#define ID_SOUND_GROUPBOX_ADAPTER\t\t1053\r\n#define ID_SOUND_GROUPBOX_MIC\t\t\t1097\r\n#define ID_SOUND_GROUPBOX_OUTPUT\t\t1098\r\n#define ID_SOUND_WINDOW_IMAGE\t\t\t1074\r\n#define ID_SOUND_BUTTON_TEST\t\t\t1089\r\n\r\n// Controls Dialog\r\n#define IDD_CONTROLS\t\t\t\t\t109\r\n#define ID_CTRLS_COMBOBOX_JOYSTICK\t\t1055\r\n#define ID_CTRLS_GROUPBOX_JOYSTICK\t\t1053\r\n#define ID_CTRLS_WINDOW_IMAGE\t\t\t1075\r\n#define ID_CTRLS_BUTTON_JOYSTICK_ENABLE\t1099\r\n#define ID_CTRLS_BUTTON_CTL_PANEL\t\t1100\r\n\r\n// Advanced Dialog\r\n#define IDD_ADVANCED\t\t\t\t\t144\r\n#define ID_ADVNC_BUTTON_16BIT_DISABLE\t1103\r\n#define ID_ADVNC_BUTTON_SORT_DISABLE\t1104\r\n#define ID_ADVNC_BUTTON_ADJUST_DISABLE\t1107\r\n#define ID_ADVNC_BUTTON_ADJUST_BILINEAR\t1108\r\n#define ID_ADVNC_BUTTON_ADJUST_ALWAYS\t1109\r\n#define ID_ADVNC_WINDOW_IMAGE\t\t\t1110\r\n#define ID_ADVNC_BUTTON_FMV_DISABLE\t\t1111\r\n\r\n// CD Prompt Dialog\r\n#define IDD_CD_PROMPT\t\t\t\t\t165\r\n\r\n// Demo Dialog\r\n#define IDD_DEMO\t\t\t\t\t\t129\r\n#define ID_DEMO_WINDOW_IMAGE\t\t\t1096\r\n\r\n#endif // RESOURCE_H_INCLUDED\r\n"
  },
  {
    "path": "global/types.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef GLOBAL_TYPES_H_INCLUDED\n#define GLOBAL_TYPES_H_INCLUDED\n\n/*\n * Inject macro\n */\n\n#pragma pack(push, 1)\ntypedef struct {\n\tBYTE opCode;\t// must be 0xE9;\n\tDWORD offset;\t// jump offset\n} JMP;\n#pragma pack(pop)\n\n#define INJECT(from,to) { \\\n\t((JMP*)(from))->opCode = 0xE9; \\\n\t((JMP*)(from))->offset = (DWORD)(to) - ((DWORD)(from) + sizeof(JMP)); \\\n}\n\n#ifdef _DEBUG\n#define TRACE(func,line) { \\\n\tprintf(\"%s: line %d\\n\", func, line); \\\n\tfflush(stdout); \\\n}\n#else\n#define TRACE(func,line)\n#endif\n\n/*\n * Defined values\n */\n// General values\n#define REQ_LEVEL_VERSION\t(45)\n#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))\n\n// FPS values\n#define FRAMES_PER_SECOND\t(30)\n#define TICKS_PER_FRAME\t\t(2)\n#define TICKS_PER_SECOND\t(TICKS_PER_FRAME * FRAMES_PER_SECOND)\n\n// Formula values\n#define W2V_SHIFT\t\t\t(14) // World to View shift value\n#define W2V_SCALE\t\t\t(1<<W2V_SHIFT) // World to View scale value\n#define PHD_ONE\t\t\t\t(0x10000) // unsigned short int equivalent of 1.0\n#define PHD_IONE\t\t\t(PHD_ONE/4) // signed short int equivalent of 1.0\n#define PHD_HALF\t\t\t(0x100) // half size of PHD_ONE\n\n// Flag check macros\n#define CHK_ALL(a,b)\t(((a)&(b))==(b))\n#define CHK_ANY(a,b)\t(((a)&(b))!=0)\n\n// Geometry values\n#define WALL_SHIFT\t\t\t(10)\n#define NO_HEIGHT\t\t\t(-0x7F00)\n\n// AI values\n#define HP_DONT_TARGET\t\t(0xC000)\n#define RANDOM_SEED\t\t\t(0xD371F947)\n#define SUNSET_TIMEOUT\t\t(TICKS_PER_SECOND*60*20) // sunset sets in 20 minutes\n\n// Angle values\n#define PHD_360\t\t\t\t(PHD_ONE)\n#define PHD_180\t\t\t\t(PHD_ONE/2)\n#define PHD_90\t\t\t\t(PHD_ONE/4)\n#define PHD_45\t\t\t\t(PHD_ONE/8)\n#define PHD_DEGREE\t\t\t(PHD_ONE/360)\n\n// String macros\n#ifdef FEATURE_HUD_IMPROVED\n#define K(a) \"\\x7F\" a \"\\x1F\"\n#endif // FEATURE_HUD_IMPROVED\n\n// Math macros\n#define MIN(a,b)\t\t\t(((a)<(b))?(a):(b))\n#define MAX(a,b)\t\t\t(((a)>(b))?(a):(b))\n#define ABS(a)\t\t\t\t(((a)<0)?-(a):(a))\n#define SQR(a)\t\t\t\t((a)*(a))\n#define CLAMPL(a,b)\t\t\t{if((a)<(b)) (a)=(b);}\n#define CLAMPG(a,b)\t\t\t{if((a)>(b)) (a)=(b);}\n#define CLAMP(a,b,c)\t\t{if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c);}\n#define SWAP(a,b,c)\t\t\t{(c)=(a); (a)=(b); (b)=(c);}\n#define\tTRIGMULT2(a,b)\t\t(((a)*(b))>>W2V_SHIFT)\n#define\tTRIGMULT3(a,b,c)\t(TRIGMULT2((TRIGMULT2(a,b)),c))\n#define\tVBUF_VISIBLE(a,b,c)\t(((a).ys-(b).ys)*((c).xs-(b).xs)>=((c).ys-(b).ys)*((a).xs-(b).xs))\n\n// Fast conversion macros\n#define BYTEn(a,b)\t\t\t(*((BYTE*)&(a)+b))\n#define BYTE0(a)\t\t\t(LOBYTE(a))\n#define BYTE1(a)\t\t\t(BYTEn(a,1))\n#define BYTE2(a)\t\t\t(BYTEn(a,2))\n#define BYTE3(a)\t\t\t(BYTEn(a,3))\n\n// View distance values\n#define VIEW_NEAR\t\t\t(0x14 * 0x001)\n#define VIEW_FAR\t\t\t(0x14 * 0x400)\n\n// DepthQ fog values\n#define DEPTHQ_END\t\t\t(VIEW_FAR)\n#define DEPTHQ_RANGE\t\t(DEPTHQ_END * 2/5)\n#define DEPTHQ_START\t\t(DEPTHQ_END - DEPTHQ_RANGE)\n\n// Water effect table parameters\n#define WIBBLE_SIZE\t\t\t(32)\n#define MAX_WIBBLE\t\t\t(2)\n#define MAX_SHADE\t\t\t(0x300)\n#define MAX_ROOMLIGHT_UNIT\t(0x2000 / (WIBBLE_SIZE/2))\n\n// SW Renderer Detail Settings\n#define SW_DETAIL_LOW\t\t(0 * 0x400 * W2V_SCALE)\n#define SW_DETAIL_MEDIUM\t(3 * 0x400 * W2V_SCALE)\n#define SW_DETAIL_HIGH\t\t(6 * 0x400 * W2V_SCALE)\n#define SW_DETAIL_ULTRA\t\t(20* 0x400 * W2V_SCALE)\n\n// ClearBuffers flags\n#define CLRB_PrimaryBuffer\t\t\t(0x0001)\n#define CLRB_BackBuffer\t\t\t\t(0x0002)\n#define CLRB_ThirdBuffer\t\t\t(0x0004)\n#define CLRB_ZBuffer\t\t\t\t(0x0008)\n#define CLRB_RenderBuffer\t\t\t(0x0010)\n#define CLRB_PictureBuffer\t\t\t(0x0020)\n#define CLRB_WindowedPrimaryBuffer\t(0x0040)\n#define CLRB_Reserved\t\t\t\t(0x0080)\n#define CLRB_PhdWinSize\t\t\t\t(0x0100)\n\n// TextStrInfo flags\n#define TIF_Active\t\t\t\t\t(0x0001)\n#define TIF_Flash\t\t\t\t\t(0x0002)\n#define TIF_RotateH\t\t\t\t\t(0x0004)\n#define TIF_RotateV\t\t\t\t\t(0x0008)\n#define TIF_CentreH\t\t\t\t\t(0x0010)\n#define TIF_CentreV\t\t\t\t\t(0x0020)\n#define TIF_Hide\t\t\t\t\t(0x0040)\n#define TIF_Right\t\t\t\t\t(0x0080)\n#define TIF_Bottom\t\t\t\t\t(0x0100)\n#define TIF_Bgnd\t\t\t\t\t(0x0200)\n#define TIF_Outline\t\t\t\t\t(0x0400)\n#define TIF_Multiline\t\t\t\t(0x0800)\n\n// GameFlow flags\n#define GFF_DemoVersion\t\t\t\t(0x0001)\n#define GFF_TitleDisabled\t\t\t(0x0002)\n#define GFF_CheatModeCheckDisabled\t(0x0004)\n#define GFF_NoInputTimeout\t\t\t(0x0008)\n#define GFF_LoadSaveDisabled\t\t(0x0010)\n#define GFF_ScreenSizingDisabled\t(0x0020)\n#define GFF_LockoutOptionRing\t\t(0x0040)\n#define GFF_DozyCheatEnabled\t\t(0x0080)\n#define GFF_UseSecurityTag\t\t\t(0x0100)\n#define GFF_GymEnabled\t\t\t\t(0x0200)\n#define GFF_SelectAnyLevel\t\t\t(0x0400)\n#define GFF_EnableCheatCode\t\t\t(0x0800)\n\n// Input Status Flags\n#define IN_FORWARD\t\t\t(0x00000001)\n#define IN_BACK\t\t\t\t(0x00000002)\n#define IN_LEFT\t\t\t\t(0x00000004)\n#define IN_RIGHT\t\t\t(0x00000008)\n#define IN_JUMP\t\t\t\t(0x00000010)\n#define IN_DRAW\t\t\t\t(0x00000020)\n#define IN_ACTION\t\t\t(0x00000040)\n#define IN_SLOW\t\t\t\t(0x00000080)\n#define IN_OPTION\t\t\t(0x00000100)\n#define IN_LOOK\t\t\t\t(0x00000200)\n#define IN_STEPL\t\t\t(0x00000400)\n#define IN_STEPR\t\t\t(0x00000800)\n#define IN_ROLL\t\t\t\t(0x00001000)\n#define IN_PAUSE\t\t\t(0x00002000)\n#define IN_RESERVED1\t\t(0x00004000)\n#define IN_RESERVED2\t\t(0x00008000)\n#define IN_DOZYCHEAT\t\t(0x00010000)\n#define IN_STUFFCHEAT\t\t(0x00020000)\n#define IN_DEBUGINFO\t\t(0x00040000)\n#define IN_FLARE\t\t\t(0x00080000)\n#define IN_SELECT\t\t\t(0x00100000)\n#define IN_DESELECT\t\t\t(0x00200000)\n#define IN_SAVE\t\t\t\t(0x00400000)\n#define IN_LOAD\t\t\t\t(0x00800000)\n\n// Gameflow directions\n#define GF_START_GAME\t\t(0x0000)\n#define GF_START_SAVEDGAME\t(0x0100)\n#define GF_START_CINE\t\t(0x0200)\n#define GF_START_FMV\t\t(0x0300)\n#define GF_START_DEMO\t\t(0x0400)\n#define GF_EXIT_TO_TITLE\t(0x0500)\n#define GF_LEVEL_COMPLETE\t(0x0600)\n#define GF_EXIT_GAME\t\t(0x0700)\n#define GF_EXIT_TO_OPTION\t(0x0800)\n#define GF_TITLE_DESELECT\t(0x0900)\n#define GF_ERROR\t\t\t(-1)\n\n// Room flags\n#define ROOM_UNDERWATER\t\t(0x01)\n#define ROOM_OUTSIDE\t\t(0x08)\n#define ROOM_INSIDE\t\t\t(0x40)\n\n// SFX flags\n#define SFX_UNDERWATER\t\t(1)\n#define SFX_ALWAYS\t\t\t(2)\n\n// Sprite flags\n#define SPR_RGB\t\t\t(0x00FFFFFF)\n#define SPR_ABS\t\t\t(0x01000000)\n#define SPR_SEMITRANS\t(0x02000000)\n#define SPR_SCALE\t\t(0x04000000)\n#define SPR_SHADE\t\t(0x08000000)\n#define SPR_TINT\t\t(0x10000000)\n#define SPR_BLEND_ADD\t(0x20000000)\n#define SPR_BLEND_SUB\t(0x40000000)\n#define SPR_BLEND_QRT\t(SPR_BLEND_ADD|SPR_BLEND_SUB)\n#define SPR_BLEND\t\t(SPR_BLEND_QRT)\n#define SPR_ITEM\t\t(0x80000000)\n\n// Item flags\n#define IFL_INVISIBLE\t(0x0100)\n#define IFL_CODEBITS\t(0x3E00)\n#define IFL_REVERSE\t\t(0x4000)\n#define IFL_CLEARBODY\t(0x8000)\n\n// Glow tint colors\n#define GLOW_FLARE_COLOR\t(0xFF8080) // Flare\n#define GLOW_PISTOL_COLOR\t(0x3F380F) // Pistol/Magnums/Uzi gunfire\n#define GLOW_M16_COLOR\t\t(0x7F701F) // M16 gunfire\n#define GLOW_GUNSHOT_COLOR\t(0x7F701F) // Skidoo/Enemy gunfire\n\n// Collision types\n#define COLL_FRONT\t(0x01)\n#define COLL_LEFT\t(0x02)\n#define COLL_RIGHT\t(0x04)\n#define COLL_TOP\t(0x08)\n\n/*\n * DirectX type definitions\n */\n\n#if (DIRECT3D_VERSION >= 0x900)\n#ifndef RGB_MAKE\n#define RGBA_SETALPHA(rgba, x)\t(((x) << 24) | ((rgba) & 0x00ffffff))\n#define RGBA_GETALPHA(rgb)\t\t((rgb) >> 24)\n#define RGBA_GETRED(rgb)\t\t(((rgb) >> 16) & 0xff)\n#define RGBA_GETGREEN(rgb)\t\t(((rgb) >> 8) & 0xff)\n#define RGBA_GETBLUE(rgb)\t\t((rgb) & 0xff)\n#define RGBA_MAKE(r, g, b, a)\t((D3DCOLOR) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))\n#define RGB_GETRED(rgb)\t\t\t(((rgb) >> 16) & 0xff)\n#define RGB_GETGREEN(rgb)\t\t(((rgb) >> 8) & 0xff)\n#define RGB_GETBLUE(rgb)\t\t((rgb) & 0xff)\n#define RGB_MAKE(r, g, b)\t\t((D3DCOLOR) (((r) << 16) | ((g) << 8) | (b)))\n#endif // RGB_MAKE\n\n#ifndef D3DFVF_TLVERTEX\n#define D3DFVF_TLVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_SPECULAR|D3DFVF_TEX1)\n#endif // D3DFVF_TLVERTEX\n\ntypedef struct {\n\tD3DVALUE sx, sy, sz, rhw;\n\tD3DCOLOR color, specular;\n\tD3DVALUE tu, tv;\n} D3DTLVERTEX, *LPD3DTLVERTEX;\n\ntypedef D3DLOCKED_RECT DDSDESC, *LPDDSDESC;\ntypedef LPDIRECT3DSURFACE9 LPDDS;\ntypedef LPDIRECT3DTEXTURE9 HWR_TEXHANDLE;\n#else // (DIRECT3D_VERSION >= 0x900)\ntypedef DDSURFACEDESC DDSDESC, *LPDDSDESC;\ntypedef LPDIRECTDRAWSURFACE3 LPDDS;\ntypedef D3DTEXTUREHANDLE HWR_TEXHANDLE;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n#if (DIRECT3D_VERSION >= 0x900)\n#define VTXBUF_LEN (256)\n\ntypedef struct {\n\tDWORD width;\n\tDWORD height;\n\tLPBYTE bitmap;\n} SWR_BUFFER;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n/*\n * Enums\n */\n\ntypedef enum {\n\tID_NONE = -1,\n\tID_LARA = 0,\n\tID_LARA_PISTOLS,\n\tID_LARA_HAIR,\n\tID_LARA_SHOTGUN,\n\tID_LARA_MAGNUMS,\n\tID_LARA_UZIS,\n\tID_LARA_M16,\n\tID_LARA_GRENADE,\n\tID_LARA_HARPOON,\n\tID_LARA_FLARE,\n\tID_LARA_SKIDOO,\n\tID_LARA_BOAT,\n\tID_LARA_EXTRA,\n\tID_SKIDOO_FAST,\n\tID_BOAT,\n\tID_DOG,\n\tID_CULT1,\n\tID_CULT1A,\n\tID_CULT1B,\n\tID_CULT2,\n\tID_CULT3,\n\tID_MOUSE,\n\tID_DRAGON_FRONT,\n\tID_DRAGON_BACK,\n\tID_GONDOLA,\n\tID_SHARK,\n\tID_EEL,\n\tID_BIG_EEL,\n\tID_BARRACUDA,\n\tID_DIVER,\n\tID_WORKER1,\n\tID_WORKER2,\n\tID_WORKER3,\n\tID_WORKER4,\n\tID_WORKER5,\n\tID_JELLY,\n\tID_SPIDER_or_WOLF,\n\tID_BIG_SPIDER_or_BEAR,\n\tID_CROW,\n\tID_TIGER,\n\tID_BARTOLI,\n\tID_XIAN_LORD,\n\tID_CHINESE2,\n\tID_WARRIOR,\n\tID_CHINESE4,\n\tID_YETI,\n\tID_GIANT_YETI,\n\tID_EAGLE,\n\tID_BANDIT1,\n\tID_BANDIT2,\n\tID_BANDIT2B,\n\tID_SKIDOO_ARMED,\n\tID_SKIDMAN,\n\tID_MONK1,\n\tID_MONK2,\n\tID_FALLING_BLOCK1,\n\tID_FALLING_BLOCK2,\n\tID_FALLING_BLOCK3,\n\tID_PENDULUM1,\n\tID_SPIKES,\n\tID_ROLLING_BALL1,\n\tID_DARTS,\n\tID_DART_EMITTER,\n\tID_DRAW_BRIDGE,\n\tID_TEETH_TRAP,\n\tID_LIFT,\n\tID_GENERAL,\n\tID_MOVABLE_BLOCK1,\n\tID_MOVABLE_BLOCK2,\n\tID_MOVABLE_BLOCK3,\n\tID_MOVABLE_BLOCK4,\n\tID_BIG_BOWL,\n\tID_WINDOW1,\n\tID_WINDOW2,\n\tID_WINDOW3,\n\tID_WINDOW4,\n\tID_PROPELLER1,\n\tID_PROPELLER2,\n\tID_HOOK,\n\tID_FALLING_CEILING,\n\tID_SPINNING_BLADE,\n\tID_BLADE,\n\tID_KILLER_STATUE,\n\tID_ROLLING_BALL2,\n\tID_ICICLE,\n\tID_SPIKE_WALL,\n\tID_SPRING_BOARD,\n\tID_CEILING_SPIKES,\n\tID_BELL,\n\tID_WATER_SPRITE,\n\tID_SNOW_SPRITE,\n\tID_SKIDOO_LARA,\n\tID_SWITCH_TYPE1,\n\tID_SWITCH_TYPE2,\n\tID_PROPELLER3,\n\tID_PROPELLER4,\n\tID_PENDULUM2,\n\tID_MESH_SWAP1,\n\tID_MESH_SWAP2,\n\tID_LARA_SWAP,\n\tID_TEXT_BOX,\n\tID_ROLLING_BALL3,\n\tID_DEATH_SLIDE,\n\tID_SWITCH_TYPE3,\n\tID_SWITCH_TYPE4,\n\tID_SWITCH_TYPE5,\n\tID_DOOR_TYPE1,\n\tID_DOOR_TYPE2,\n\tID_DOOR_TYPE3,\n\tID_DOOR_TYPE4,\n\tID_DOOR_TYPE5,\n\tID_DOOR_TYPE6,\n\tID_DOOR_TYPE7,\n\tID_DOOR_TYPE8,\n\tID_TRAPDOOR_TYPE1,\n\tID_TRAPDOOR_TYPE2,\n\tID_TRAPDOOR_TYPE3,\n\tID_BRIDGE_FLAT,\n\tID_BRIDGE_TILT1,\n\tID_BRIDGE_TILT2,\n\tID_PASSPORT_OPTION,\n\tID_COMPASS_OPTION,\n\tID_PHOTO_OPTION,\n\tID_PLAYER1,\n\tID_PLAYER2,\n\tID_PLAYER3,\n\tID_PLAYER4,\n\tID_PLAYER5,\n\tID_PLAYER6,\n\tID_PLAYER7,\n\tID_PLAYER8,\n\tID_PLAYER9,\n\tID_PLAYER10,\n\tID_PASSPORT_CLOSED,\n\tID_COMPASS_ITEM,\n\tID_PISTOL_ITEM,\n\tID_SHOTGUN_ITEM,\n\tID_MAGNUM_ITEM,\n\tID_UZI_ITEM,\n\tID_HARPOON_ITEM,\n\tID_M16_ITEM,\n\tID_GRENADE_ITEM,\n\tID_PISTOL_AMMO_ITEM,\n\tID_SHOTGUN_AMMO_ITEM,\n\tID_MAGNUM_AMMO_ITEM,\n\tID_UZI_AMMO_ITEM,\n\tID_HARPOON_AMMO_ITEM,\n\tID_M16_AMMO_ITEM,\n\tID_GRENADE_AMMO_ITEM,\n\tID_SMALL_MEDIPACK_ITEM,\n\tID_LARGE_MEDIPACK_ITEM,\n\tID_FLARES_ITEM,\n\tID_FLARE_ITEM,\n\tID_DETAIL_OPTION,\n\tID_SOUND_OPTION,\n\tID_CONTROL_OPTION,\n\tID_GAMMA_OPTION,\n\tID_PISTOL_OPTION,\n\tID_SHOTGUN_OPTION,\n\tID_MAGNUM_OPTION,\n\tID_UZI_OPTION,\n\tID_HARPOON_OPTION,\n\tID_M16_OPTION,\n\tID_GRENADE_OPTION,\n\tID_PISTOL_AMMO_OPTION,\n\tID_SHOTGUN_AMMO_OPTION,\n\tID_MAGNUM_AMMO_OPTION,\n\tID_UZI_AMMO_OPTION,\n\tID_HARPOON_AMMO_OPTION,\n\tID_M16_AMMO_OPTION,\n\tID_GRENADE_AMMO_OPTION,\n\tID_SMALL_MEDIPACK_OPTION,\n\tID_LARGE_MEDIPACK_OPTION,\n\tID_FLARES_OPTION,\n\tID_PUZZLE_ITEM1,\n\tID_PUZZLE_ITEM2,\n\tID_PUZZLE_ITEM3,\n\tID_PUZZLE_ITEM4,\n\tID_PUZZLE_OPTION1,\n\tID_PUZZLE_OPTION2,\n\tID_PUZZLE_OPTION3,\n\tID_PUZZLE_OPTION4,\n\tID_PUZZLE_HOLE1,\n\tID_PUZZLE_HOLE2,\n\tID_PUZZLE_HOLE3,\n\tID_PUZZLE_HOLE4,\n\tID_PUZZLE_DONE1,\n\tID_PUZZLE_DONE2,\n\tID_PUZZLE_DONE3,\n\tID_PUZZLE_DONE4,\n\tID_SECRET1,\n\tID_SECRET2,\n\tID_SECRET3,\n\tID_KEY_ITEM1,\n\tID_KEY_ITEM2,\n\tID_KEY_ITEM3,\n\tID_KEY_ITEM4,\n\tID_KEY_OPTION1,\n\tID_KEY_OPTION2,\n\tID_KEY_OPTION3,\n\tID_KEY_OPTION4,\n\tID_KEY_HOLE1,\n\tID_KEY_HOLE2,\n\tID_KEY_HOLE3,\n\tID_KEY_HOLE4,\n\tID_PICKUP_ITEM1,\n\tID_PICKUP_ITEM2,\n\tID_PICKUP_OPTION1,\n\tID_PICKUP_OPTION2,\n\tID_SPHERE_OF_DOOM1,\n\tID_SPHERE_OF_DOOM2,\n\tID_SPHERE_OF_DOOM3,\n\tID_ALARM_SOUND,\n\tID_BIRD_TWEETER1,\n\tID_DINO,\n\tID_BIRD_TWEETER2,\n\tID_CLOCK_CHIMES,\n\tID_DRAGON_BONES1,\n\tID_DRAGON_BONES2,\n\tID_DRAGON_BONES3,\n\tID_HOT_LIQUID,\n\tID_BOAT_BITS,\n\tID_MINE,\n\tID_INV_BACKGROUND,\n\tID_FX_RESERVED,\n\tID_GONG_BONGER,\n\tID_DETONATOR1,\n\tID_DETONATOR2,\n\tID_COPTER,\n\tID_EXPLOSION,\n\tID_SPLASH,\n\tID_BUBBLES,\n\tID_BUBBLE_EMITTER,\n\tID_BLOOD,\n\tID_DART_EFFECT,\n\tID_FLARE_FIRE,\n\tID_GLOW,\n\tID_GLOW_RESERVED,\n\tID_RICOCHET,\n\tID_TWINKLE,\n\tID_GUN_FLASH,\n\tID_M16_FLASH,\n\tID_BODY_PART,\n\tID_CAMERA_TARGET,\n\tID_WATERFALL,\n\tID_MISSILE_HARPOON,\n\tID_MISSILE_FLAME,\n\tID_MISSILE_KNIFE,\n\tID_ROCKET,\n\tID_HARPOON_BOLT,\n\tID_LAVA,\n\tID_LAVA_EMITTER,\n\tID_FLAME,\n\tID_FLAME_EMITTER,\n\tID_SKYBOX,\n\tID_ALPHABET,\n\tID_DYING_MONK,\n\tID_DING_DONG,\n\tID_LARA_ALARM,\n\tID_MINI_COPTER,\n\tID_WINSTON,\n\tID_ASSAULT_DIGITS,\n\tID_FINAL_LEVEL_COUNTER,\n\tID_CUT_SHOTGUN,\n\tID_EARTHQUAKE,\n\tID_NUMBER_OBJECTS,\n} GAME_OBJECT_ID;\n\ntypedef enum {\n\tAS_WALK,\n\tAS_RUN,\n\tAS_STOP,\n\tAS_FORWARDJUMP,\n\tAS_POSE,\n\tAS_FASTBACK,\n\tAS_TURN_R,\n\tAS_TURN_L,\n\tAS_DEATH,\n\tAS_FASTFALL,\n\tAS_HANG,\n\tAS_REACH,\n\tAS_SPLAT,\n\tAS_TREAD,\n\tAS_LAND,\n\tAS_COMPRESS,\n\tAS_BACK,\n\tAS_SWIM,\n\tAS_GLIDE,\n\tAS_NULL,\n\tAS_FASTTURN,\n\tAS_STEPRIGHT,\n\tAS_STEPLEFT,\n\tAS_HIT,\n\tAS_SLIDE,\n\tAS_BACKJUMP,\n\tAS_RIGHTJUMP,\n\tAS_LEFTJUMP,\n\tAS_UPJUMP,\n\tAS_FALLBACK,\n\tAS_HANGLEFT,\n\tAS_HANGRIGHT,\n\tAS_SLIDEBACK,\n\tAS_SURFTREAD,\n\tAS_SURFSWIM,\n\tAS_DIVE,\n\tAS_PUSHBLOCK,\n\tAS_PULLBLOCK,\n\tAS_PPREADY,\n\tAS_PICKUP,\n\tAS_SWITCHON,\n\tAS_SWITCHOFF,\n\tAS_USEKEY,\n\tAS_USEPUZZLE,\n\tAS_UWDEATH,\n\tAS_ROLL,\n\tAS_SPECIAL,\n\tAS_SURFBACK,\n\tAS_SURFLEFT,\n\tAS_SURFRIGHT,\n\tAS_USEMIDAS,\n\tAS_DIEMIDAS,\n\tAS_SWANDIVE,\n\tAS_FASTDIVE,\n\tAS_GYMNAST,\n\tAS_WATEROUT,\n\tAS_CLIMBSTNC,\n\tAS_CLIMBING,\n\tAS_CLIMBLEFT,\n\tAS_CLIMBEND,\n\tAS_CLIMBRIGHT,\n\tAS_CLIMBDOWN,\n\tAS_LARATEST1,\n\tAS_LARATEST2,\n\tAS_LARATEST3,\n\tAS_WADE,\n\tAS_WATERROLL,\n\tAS_FLAREPICKUP,\n\tAS_TWIST,\n\tAS_KICK,\n\tAS_DEATHSLIDE,\n\tAS_LAST,\n} LARA_ANIM_STATES;\n\ntypedef enum {\n\tEXTRA_BREATH,\n\tEXTRA_PLUNGER,\n\tEXTRA_YETIKILL,\n\tEXTRA_SHARKKILL,\n\tEXTRA_AIRLOCK,\n\tEXTRA_GONGBONG,\n\tEXTRA_DINOKILL,\n\tEXTRA_PULLDAGGER,\n\tEXTRA_STARTANIM,\n\tEXTRA_STARTHOUSE,\n\tEXTRA_FINALANIM,\n} LARA_EXTRA_STATES;\n\ntypedef enum {\n\tVGA_NoVga,\n\tVGA_256Color,\n\tVGA_ModeX,\n\tVGA_Standard,\n} VGA_MODE;\n\ntypedef enum {\n\tRM_Unknown,\n\tRM_Software,\n\tRM_Hardware,\n} RENDER_MODE;\n\ntypedef enum {\n\tAM_4_3,\n\tAM_16_9,\n\tAM_Any,\n} ASPECT_MODE;\n\ntypedef enum {\n\tTAM_Disabled,\n\tTAM_BilinearOnly,\n\tTAM_Always,\n} TEX_ADJUST_MODE;\n\n#ifdef FEATURE_INPUT_IMPROVED\ntypedef enum {\n\tJOY_DirectInput,\n\tJOY_XInput,\n\tJOY_RawInput,\n} JOY_INTERFACE;\n#endif // FEATURE_INPUT_IMPROVED\n\ntypedef enum {\n#ifdef FEATURE_HUD_IMPROVED\n\tCTRL_Joystick,\n\tCTRL_Custom,\n\tCTRL_Default,\n#else // FEATURE_HUD_IMPROVED\n\tCTRL_Default,\n\tCTRL_Custom,\n#endif // FEATURE_HUD_IMPROVED\n} CONTROL_LAYOUT_PAGE;\n\ntypedef enum {\n\tINV_GameMode,\n\tINV_TitleMode,\n\tINV_KeysMode,\n\tINV_SaveMode,\n\tINV_LoadMode,\n\tINV_DeathMode,\n\tINV_PauseMode, // NOTE: not presented in the original game\n} INVENTORY_MODE;\n\ntypedef enum {\n\tLGS_Armless,\n\tLGS_HandBusy,\n\tLGS_Draw,\n\tLGS_Undraw,\n\tLGS_Ready,\n\tLGS_Special,\n} LARA_GUN_STATUS;\n\ntypedef enum {\n\tLGT_Unarmed,\n\tLGT_Pistols,\n\tLGT_Magnums,\n\tLGT_Uzis,\n\tLGT_Shotgun,\n\tLGT_M16,\n\tLGT_Grenade,\n\tLGT_Harpoon,\n\tLGT_Flare,\n\tLGT_Skidoo,\n} LARA_GUN_TYPE;\n\ntypedef enum {\n\tCAM_Chase,\n\tCAM_Fixed,\n\tCAM_Look,\n\tCAM_Combat,\n\tCAM_Cinematic,\n\tCAM_Heavy,\n} CAMERA_TYPE;\n\ntypedef enum {\n\tCFL_None,\n\tCFL_FollowCenter,\n\tCFL_NoChunky,\n\tCFL_ChaseObject,\n} CAMERA_FLAG;\n\ntypedef enum {\n\tKM_Forward,\n\tKM_Back,\n\tKM_Left,\n\tKM_Right,\n\tKM_StepLeft,\n\tKM_StepRight,\n#ifdef FEATURE_HUD_IMPROVED\n\tKM_Step,\n#endif // FEATURE_HUD_IMPROVED\n\tKM_Slow,\n\tKM_Jump,\n\tKM_Action,\n#ifdef FEATURE_HUD_IMPROVED\n\tKM_Roll,\n\tKM_WeaponDraw,\n\tKM_Flare,\n\tKM_Look,\n\tKM_Option,\n\tKM_Pause,\n#else // FEATURE_HUD_IMPROVED\n\tKM_WeaponDraw,\n\tKM_Flare,\n\tKM_Look,\n\tKM_Roll,\n\tKM_Option,\n#endif // FEATURE_HUD_IMPROVED\n} KEYMAP;\n\ntypedef enum {\n\tST_AvgZ,\n\tST_MaxZ,\n\tST_FarZ,\n} SORTTYPE;\n\ntypedef enum {\n\tDRAW_Opaque,\n\tDRAW_ColorKey,\n\tDRAW_Semitrans, // NOTE: semitrans is not presented in the original code\n} DRAWTYPE;\n\ntypedef enum {\n// Software renderer\n\tPOLY_GTmap,\t\t\t// gouraud shaded poly (texture)\n\tPOLY_WGTmap,\t\t// gouraud shaded poly (texture + colorkey)\n\tPOLY_GTmap_persp,\t// gouraud shaded poly (texture + perspective)\n\tPOLY_WGTmap_persp,\t// gouraud shaded poly (texture + colorkey + perspective)\n\tPOLY_line,\t\t\t// line (color)\n\tPOLY_flat,\t\t\t// flat shaded poly (color)\n\tPOLY_gouraud,\t\t// gouraud shaded poly (color)\n\tPOLY_trans,\t\t\t// shadow poly (color + semitransparent)\n\tPOLY_sprite,\t\t// scaled sprite (texture + colorkey)\n// Hardware renderer\n\tPOLY_HWR_GTmap,\t\t// gouraud shaded poly (texture)\n\tPOLY_HWR_WGTmap,\t// gouraud shaded poly (texture + colorkey)\n\tPOLY_HWR_gouraud,\t// gouraud shaded poly (color)\n\tPOLY_HWR_line,\t\t// line (color)\n\tPOLY_HWR_trans,\t\t// shadow poly (color + semitransparent)\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tPOLY_HWR_WGTmapHalf,// semitransparent gouraud shaded poly (texture + colorkey)\n\tPOLY_HWR_WGTmapAdd,\t// additive blended gouraud shaded poly (texture + colorkey)\n\tPOLY_HWR_WGTmapSub,\t// subtractive blended gouraud shaded poly (texture + colorkey)\n\tPOLY_HWR_WGTmapQrt,\t// quarter blended gouraud shaded poly (texture + colorkey)\n\tPOLY_HWR_half,\t\t// semitransparent gouraud shaded poly (color)\n\tPOLY_HWR_add,\t\t// additive blended gouraud shaded poly (color)\n\tPOLY_HWR_sub,\t\t// subtractive blended gouraud shaded poly (color)\n\tPOLY_HWR_qrt,\t\t// quarter blended gouraud shaded poly (color)\n#endif // FEATURE_VIDEOFX_IMPROVED\n#ifdef FEATURE_HUD_IMPROVED\n\tPOLY_HWR_healthbar,\t// health bar\n\tPOLY_HWR_airbar,\t// air bar\n#endif // FEATURE_HUD_IMPROVED\n} POLYTYPE;\n\ntypedef enum {\n\tERR_OK,\n\tERR_PreferredAdapterNotFound,\n\tERR_CantCreateWindow,\n\tERR_CantCreateDirectDraw,\n\tERR_CantInitRenderer,\n\tERR_CantCreateDirectInput,\n\tERR_CantCreateKeyboardDevice,\n\tERR_CantSetKBCooperativeLevel,\n\tERR_CantSetKBDataFormat,\n\tERR_CantAcquireKeyboard,\n\tERR_CantSetDSCooperativeLevel,\n\tERR_DD_SetExclusiveMode,\n\tERR_DD_ClearExclusiveMode,\n\tERR_SetDisplayMode,\n\tERR_CreateScreenBuffers,\n\tERR_GetBackBuffer,\n\tERR_CreatePalette,\n\tERR_SetPalette,\n\tERR_CreatePrimarySurface,\n\tERR_CreateBackBuffer,\n\tERR_CreateClipper,\n\tERR_SetClipperHWnd,\n\tERR_SetClipper,\n\tERR_CreateZBuffer,\n\tERR_AttachZBuffer,\n\tERR_CreateRenderBuffer,\n\tERR_CreatePictureBuffer,\n\tERR_D3D_Create,\n\tERR_CreateDevice,\n\tERR_CreateViewport,\n\tERR_AddViewport,\n\tERR_SetViewport2,\n\tERR_SetCurrentViewport,\n\tERR_ClearRenderBuffer,\n\tERR_UpdateRenderInfo,\n\tERR_GetThirdBuffer,\n\tERR_GoFullScreen,\n\tERR_GoWindowed,\n\tERR_WrongBitDepth,\n\tERR_GetPixelFormat,\n\tERR_GetDisplayMode,\n} ERROR_CODE;\n\ntypedef enum {\n\tGBUF_TempAlloc,\n\tGBUF_TexturePages,\n\tGBUF_MeshPointers,\n\tGBUF_Meshes,\n\tGBUF_Anims,\n\tGBUF_Structs,\n\tGBUF_Ranges,\n\tGBUF_Commands,\n\tGBUF_Bones,\n\tGBUF_Frames,\n\tGBUF_RoomTextures,\n\tGBUF_RoomInfos,\n\tGBUF_RoomMesh,\n\tGBUF_RoomDoor,\n\tGBUF_RoomFloor,\n\tGBUF_RoomLights,\n\tGBUF_RoomStaticMeshInfos,\n\tGBUF_FloorData,\n\tGBUF_Items,\n\tGBUF_Cameras,\n\tGBUF_SoundFX,\n\tGBUF_Boxes,\n\tGBUF_Overlaps,\n\tGBUF_GroundZone,\n\tGBUF_FlyZone,\n\tGBUF_AnimatingTextureRanges,\n\tGBUF_CinematicFrames,\n\tGBUF_LoadDemoBuffer,\n\tGBUF_SaveDemoBuffer,\n\tGBUF_CinematicEffects,\n\tGBUF_MummyHeadTurn,\n\tGBUF_ExtraDoorstuff,\n\tGBUF_EffectsArray,\n\tGBUF_CreatureData,\n\tGBUF_CreatureLOT,\n\tGBUF_SampleInfos,\n\tGBUF_Samples,\n\tGBUF_SampleOffsets,\n\tGBUF_RollingBallStuff,\n\tGBUF_SkidooStuff,\n\tGBUF_LoadPiccyBuffer,\n\tGBUF_FMVBuffers,\n\tGBUF_PolygonBuffers,\n\tGBUF_OrderTables,\n\tGBUF_CLUTs,\n\tGBUF_TextureInfos,\n\tGBUF_SpriteInfos,\n} GAMEALLOC_BUFFER;\n\ntypedef enum {\n\tGSI_Heading_Inventory,\n\tGSI_Heading_Option,\n\tGSI_Heading_Items,\n\tGSI_Heading_GameOver,\n\n\tGSI_Passport_LoadGame,\n\tGSI_Passport_SaveGame,\n\tGSI_Passport_NewGame,\n\tGSI_Passport_RestartLevel,\n\tGSI_Passport_ExitToTitle,\n\tGSI_Passport_ExitDemo,\n\tGSI_Passport_ExitGame,\n\tGSI_Passport_SelectLevel,\n\tGSI_Passport_SavePosition,\n\n\tGSI_Detail_SelectDetail,\n\tGSI_Detail_High,\n\tGSI_Detail_Medium,\n\tGSI_Detail_Low,\n\n\tGSI_Keymap_Walk,\n\tGSI_Keymap_Roll,\n\tGSI_Keymap_Run,\n\tGSI_Keymap_Left,\n\tGSI_Keymap_Right,\n\tGSI_Keymap_Back,\n\tGSI_Keymap_StepLeft,\n\tGSI_Keymap_Reserved1,\n\tGSI_Keymap_StepRight,\n\tGSI_Keymap_Reserved2,\n\tGSI_Keymap_Look,\n\tGSI_Keymap_Jump,\n\tGSI_Keymap_Action,\n\tGSI_Keymap_DrawWeapon,\n\tGSI_Keymap_Reserved3,\n\tGSI_Keymap_Inventory,\n\tGSI_Keymap_Flare,\n\tGSI_Keymap_Step,\n\n\tGSI_InvItem_Statistics,\n\tGSI_InvItem_Pistols,\n\tGSI_InvItem_Shotgun,\n\tGSI_InvItem_Magnums,\n\tGSI_InvItem_Uzis,\n\tGSI_InvItem_Harpoon,\n\tGSI_InvItem_M16,\n\tGSI_InvItem_Grenade,\n\tGSI_InvItem_Flare,\n\tGSI_InvItem_PistolAmmo,\n\tGSI_InvItem_ShotgunAmmo,\n\tGSI_InvItem_MagnumAmmo,\n\tGSI_InvItem_UziAmmo,\n\tGSI_InvItem_HarpoonAmmo,\n\tGSI_InvItem_M16Ammo,\n\tGSI_InvItem_GrenadeAmmo,\n\tGSI_InvItem_SmallMedipack,\n\tGSI_InvItem_LargeMedipack,\n\tGSI_InvItem_Pickup,\n\tGSI_InvItem_Puzzle,\n\tGSI_InvItem_Key,\n\tGSI_InvItem_Game,\n\tGSI_InvItem_LaraHome,\n\n\tGSI_String_Loading,\n\tGSI_String_TimeTaken,\n\tGSI_String_SecretsFound,\n\tGSI_String_Location,\n\tGSI_String_Kills,\n\tGSI_String_AmmoUsed,\n\tGSI_String_Hits,\n\tGSI_String_SavesPerformed,\n\tGSI_String_DistanceTravelled,\n\tGSI_String_HealthPacksUsed,\n\tGSI_String_ReleaseVersion,\n\tGSI_String_None,\n\tGSI_String_Finish,\n\tGSI_String_BestTimes,\n\tGSI_String_NoTimesSet,\n\tGSI_String_NA,\n\tGSI_String_CurrentPosition,\n\tGSI_String_FinalStatistics,\n\tGSI_String_Of,\n\tGSI_String_StorySoFar,\n} GAME_STRING_ID;\n\ntypedef enum {\n\tSSI_DetailLevels,\n\tSSI_DemoMode,\n\tSSI_Sound,\n\tSSI_Controls,\n\tSSI_Gamma,\n\tSSI_SetVolumes,\n\tSSI_UserKeys,\n\tSSI_SaveFileWarning,\n\tSSI_TryAgainQuestion,\n\tSSI_Yes,\n\tSSI_No,\n\tSSI_SaveComplete,\n\tSSI_NoSaveGames,\n\tSSI_NoneValid,\n\tSSI_SaveGameQuestion,\n\tSSI_EmptySlot,\n\tSSI_Off,\n\tSSI_On,\n\tSSI_SetupSoundCard,\n\tSSI_DefaultKeys,\n\tSSI_Dozy,\n} SPECIFIC_STRING_ID;\n\ntypedef enum {\n\tICLR_Black,\n\tICLR_Gray,\n\tICLR_White,\n\tICLR_Red,\n\tICLR_Orange,\n\tICLR_Yellow,\n\tICLR_Reserved1,\n\tICLR_Reserved2,\n\tICLR_Reserved3,\n\tICLR_Reserved4,\n\tICLR_Reserved5,\n\tICLR_Reserved6,\n\tICLR_DarkGreen,\n\tICLR_Green,\n\tICLR_Cyan,\n\tICLR_Blue,\n\tICLR_Magenta,\n} INV_COLOURS;\n\ntypedef enum {\n\tLWS_AboveWater,\n\tLWS_Underwater,\n\tLWS_Surface,\n\tLWS_Cheat,\n\tLWS_Wade,\n} LARA_WATER_STATES;\n\ntypedef enum {\n\tRING_Main,\n\tRING_Option,\n\tRING_Keys,\n} RING_TYPE;\n\ntypedef enum {\n\tGFL_NOLEVEL = -1,\n\tGFL_TITLE,\n\tGFL_NORMAL,\n\tGFL_SAVED,\n\tGFL_DEMO,\n\tGFL_CUTSCENE,\n\tGFL_STORY,\n\tGFL_QUIET,\n\tGFL_MIDSTORY,\n} GF_LEVEL_TYPE;\n\ntypedef enum {\n\tGFE_PICTURE,\n\tGFE_LIST_START,\n\tGFE_LIST_END,\n\tGFE_PLAYFMV,\n\tGFE_STARTLEVEL,\n\tGFE_CUTSCENE,\n\tGFE_LEVCOMPLETE,\n\tGFE_DEMOPLAY,\n\tGFE_JUMPTO_SEQ,\n\tGFE_END_SEQ,\n\tGFE_SETTRACK,\n\tGFE_SUNSET,\n\tGFE_LOADINGPIC,\n\tGFE_DEADLY_WATER,\n\tGFE_REMOVE_WEAPONS,\n\tGFE_GAMECOMPLETE,\n\tGFE_CUTANGLE,\n\tGFE_NOFLOOR,\n\tGFE_ADD2INV,\n\tGFE_STARTANIM,\n\tGFE_NUMSECRETS,\n\tGFE_KILL2COMPLETE,\n\tGFE_REMOVE_AMMO,\n} GF_EVENTS;\n\ntypedef enum {\n\tMOOD_BORED,\n\tMOOD_ATTACK,\n\tMOOD_ESCAPE,\n\tMOOD_STALK,\n} MOOD_TYPE;\n\ntypedef enum {\n\tITEM_INACTIVE,\n\tITEM_ACTIVE,\n\tITEM_DISABLED,\n\tITEM_INVISIBLE,\n} ITEM_STATUS;\n\ntypedef enum {\n\tADDINV_PISTOL,\n\tADDINV_SHOTGUN,\n\tADDINV_MAGNUM,\n\tADDINV_UZI,\n\tADDINV_HARPOON,\n\tADDINV_M16,\n\tADDINV_GRENADE,\n\tADDINV_PISTOL_AMMO,\n\tADDINV_SHOTGUN_AMMO,\n\tADDINV_MAGNUM_AMMO,\n\tADDINV_UZI_AMMO,\n\tADDINV_HARPOON_AMMO,\n\tADDINV_M16_AMMO,\n\tADDINV_GRENADE_AMMO,\n\tADDINV_FLARE,\n\tADDINV_SMALL_MEDIPACK,\n\tADDINV_LARGE_MEDIPACK,\n\tADDINV_PICKUP1,\n\tADDINV_PICKUP2,\n\tADDINV_PUZZLE1,\n\tADDINV_PUZZLE2,\n\tADDINV_PUZZLE3,\n\tADDINV_PUZZLE4,\n\tADDINV_KEY1,\n\tADDINV_KEY2,\n\tADDINV_KEY3,\n\tADDINV_KEY4,\n} ADDINV_TYPES;\n\ntypedef enum {\n#ifdef FEATURE_HUD_IMPROVED\n\tCHAR_SECRET1 = 0x13,\n#else\n\tCHAR_SECRET1 = 0x7F,\n#endif\n\tCHAR_SECRET2,\n\tCHAR_SECRET3,\n} CHAR_SECRETS;\n\n/*\n * Structs\n */\n#pragma pack(push, 1)\n\n// NOTE: there were int items in the original code,\n// but it's more important to have wider range\n// since negative numbers are not used anyway\ntypedef struct SortItem_t {\n#ifdef FEATURE_VIEW_IMPROVED\n\tUINT64 _0;\n\tUINT64 _1;\n#else // FEATURE_VIEW_IMPROVED\n\tDWORD _0;\n\tDWORD _1;\n#endif // FEATURE_VIEW_IMPROVED\n} SORT_ITEM;\n\ntypedef struct RGB888_t {\n\tBYTE red;\n\tBYTE green;\n\tBYTE blue;\n} RGB888;\n\ntypedef struct GouraudFill_t {\n\tD3DCOLOR clr[4][4];\n} GOURAUD_FILL;\n\ntypedef struct GouraudOutline_t {\n\tD3DCOLOR clr[9];\n} GOURAUD_OUTLINE;\n\ntypedef struct DepthQEntry_t {\n\tBYTE index[256];\n} DEPTHQ_ENTRY;\n\ntypedef struct GouraudEntry_t {\n\tBYTE index[32];\n} GOURAUD_ENTRY;\n\ntypedef struct DisplayMode_t {\n\tint width;\n\tint height;\n\tint bpp;\n\tVGA_MODE vga;\n} DISPLAY_MODE;\n\ntypedef struct DisplayModeNode_t {\n\tstruct DisplayModeNode_t *next;\n\tstruct DisplayModeNode_t *previous;\n\tstruct DisplayMode_t body;\n} DISPLAY_MODE_NODE;\n\ntypedef struct DisplayModeList_t {\n\tstruct DisplayModeNode_t *head;\n\tstruct DisplayModeNode_t *tail;\n\tDWORD dwCount;\n} DISPLAY_MODE_LIST;\n\ntypedef struct StringFlagged_t {\n\tLPTSTR lpString;\n\tbool isPresented;\n} STRING_FLAGGED;\n\ntypedef struct DisplayAdapter_t {\n\tLPGUID lpAdapterGuid;\n\tGUID adapterGuid;\n\tSTRING_FLAGGED driverDescription;\n\tSTRING_FLAGGED driverName;\n#if (DIRECT3D_VERSION >= 0x900)\n\tUINT index;\n\tD3DCAPS9 caps;\n\tDISPLAY_MODE_LIST hwDispModeList;\n\tDISPLAY_MODE_LIST swDispModeList;\n\tDWORD screenWidth;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tDDCAPS driverCaps;\n\tDDCAPS helCaps;\n\tGUID deviceGuid;\n\tD3DDEVICEDESC D3DHWDeviceDesc;\n\tDISPLAY_MODE_LIST hwDispModeList;\n\tDISPLAY_MODE_LIST swDispModeList;\n\tDISPLAY_MODE vgaMode1;\n\tDISPLAY_MODE vgaMode2;\n\tDWORD screenWidth;\n\tbool hwRenderSupported;\n\tbool swWindowedSupported;\n\tbool hwWindowedSupported;\n\tbool isVgaMode1Presented;\n\tbool isVgaMode2Presented;\n\tbool perspectiveCorrectSupported;\n\tbool ditherSupported;\n\tbool zBufferSupported;\n\tbool linearFilterSupported;\n\tbool shadeRestricted;\n#endif // (DIRECT3D_VERSION >= 0x900)\n} DISPLAY_ADAPTER;\n\ntypedef struct DisplayAdapterNode_t {\n\tstruct DisplayAdapterNode_t *next;\n\tstruct DisplayAdapterNode_t *previous;\n\tstruct DisplayAdapter_t body;\n} DISPLAY_ADAPTER_NODE;\n\ntypedef struct DisplayAdapterList_t {\n\tstruct DisplayAdapterNode_t *head;\n\tstruct DisplayAdapterNode_t *tail;\n\tDWORD dwCount;\n} DISPLAY_ADAPTER_LIST;\n\ntypedef struct SoundAdapter_t {\n\tGUID *lpAdapterGuid;\n\tGUID adapterGuid;\n\tSTRING_FLAGGED description;\n\tSTRING_FLAGGED module;\n} SOUND_ADAPTER;\n\ntypedef struct SoundAdapterNode_t {\n\tstruct SoundAdapterNode_t *next;\n\tstruct SoundAdapterNode_t *previous;\n\tSOUND_ADAPTER body;\n} SOUND_ADAPTER_NODE;\n\ntypedef struct SoundAdapterList_t {\n\tstruct SoundAdapterNode_t *head;\n\tstruct SoundAdapterNode_t *tail;\n\tDWORD dwCount;\n} SOUND_ADAPTER_LIST;\n\ntypedef struct Joystick_t {\n\tGUID *lpJoystickGuid;\n\tGUID joystickGuid;\n\tSTRING_FLAGGED productName;\n\tSTRING_FLAGGED instanceName;\n#ifdef FEATURE_INPUT_IMPROVED\n\tJOY_INTERFACE iface;\n#endif // FEATURE_INPUT_IMPROVED\n} JOYSTICK;\n\ntypedef struct JoystickNode_t {\n\tstruct JoystickNode_t *next;\n\tstruct JoystickNode_t *previous;\n\tJOYSTICK body;\n} JOYSTICK_NODE;\n\ntypedef struct JoystickList_t {\n\tstruct JoystickNode_t *head;\n\tstruct JoystickNode_t *tail;\n\tDWORD dwCount;\n} JOYSTICK_LIST;\n\ntypedef struct AppSettings_t {\n\tDISPLAY_ADAPTER_NODE *PreferredDisplayAdapter;\n\tSOUND_ADAPTER_NODE *PreferredSoundAdapter;\n\tJOYSTICK_NODE *PreferredJoystick;\n\tDISPLAY_MODE_NODE *VideoMode;\n\tRENDER_MODE RenderMode;\n\tint WindowWidth;\n\tint WindowHeight;\n\tASPECT_MODE AspectMode;\n\tbool PerspectiveCorrect;\n\tbool Dither;\n\tbool ZBuffer;\n\tbool BilinearFiltering;\n\tbool TripleBuffering;\n\tbool FullScreen;\n\tbool SoundEnabled;\n\tbool LaraMic;\n\tbool JoystickEnabled;\n\tbool Disable16BitTextures;\n\tbool DontSortPrimitives;\n\tbool FlipBroken;\n\tbool DisableFMV;\n\tTEX_ADJUST_MODE TexelAdjustMode;\n\tint NearestAdjustment;\n\tint LinearAdjustment;\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tint LightingMode;\n#endif // FEATURE_VIDEOFX_IMPROVED\n} APP_SETTINGS;\n\nstruct TEXPAGE_DESC {\n#if (DIRECT3D_VERSION >= 0x900)\n\tLPDIRECT3DTEXTURE9 texture;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tLPDDS sysMemSurface;\n\tLPDDS vidMemSurface;\n\tLPDIRECTDRAWPALETTE palette;\n\tLPDIRECT3DTEXTURE2 texture3d;\n\tHWR_TEXHANDLE texHandle;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\tint width;\n\tint height;\n\tint status;\n};\n\ntypedef struct PhdUV_t {\n\tUINT16 u;\n\tUINT16 v;\n} PHD_UV;\n\ntypedef struct PhdTexture_t {\n\tUINT16 drawtype;\n\tUINT16 tpage;\n\tPHD_UV uv[4];\n} PHD_TEXTURE;\n\ntypedef struct ColorBitMasks_t {\n\tDWORD dwRBitMask;\n\tDWORD dwGBitMask;\n\tDWORD dwBBitMask;\n\tDWORD dwRGBAlphaBitMask;\n\tDWORD dwRBitDepth;\n\tDWORD dwGBitDepth;\n\tDWORD dwBBitDepth;\n\tDWORD dwRGBAlphaBitDepth;\n\tDWORD dwRBitOffset;\n\tDWORD dwGBitOffset;\n\tDWORD dwBBitOffset;\n\tDWORD dwRGBAlphaBitOffset;\n} COLOR_BIT_MASKS;\n\ntypedef struct TextureFormat_t {\n#if (DIRECT3D_VERSION < 0x900)\n\tDDPIXELFORMAT pixelFmt;\n\tCOLOR_BIT_MASKS colorBitMasks;\n#endif // (DIRECT3D_VERSION < 0x900)\n\tDWORD bpp;\n} TEXTURE_FORMAT;\n\ntypedef struct TextStrInfo_t {\n\tDWORD flags;\n\tUINT16 textFlags;\n\tUINT16 bgndFlags;\n\tUINT16 outlFlags;\n\t__int16 xPos;\n\t__int16 yPos;\n\t__int16 zPos;\n\t__int16 letterSpacing;\n\t__int16 wordSpacing;\n\t__int16 flashRate;\n\t__int16 flashCount;\n\t__int16 bgndColor;\n\tGOURAUD_FILL *bgndGour;\n\t__int16 outlColour;\n\tGOURAUD_OUTLINE *outlGour;\n\t__int16 bgndSizeX;\n\t__int16 bgndSizeY;\n\t__int16 bgndOffX;\n\t__int16 bgndOffY;\n\t__int16 bgndOffZ;\n\tint scaleH;\n\tint scaleV;\n\tchar *pString;\n} TEXT_STR_INFO;\n\ntypedef struct StringFixed4_t {\n\tchar str[4];\n} STRING_FIXED4;\n\ntypedef struct StringFixed50_t {\n\tchar str[50];\n} STRING_FIXED50;\n\ntypedef struct StringFixed64_t {\n\tchar str[64];\n} STRING_FIXED64;\n\ntypedef struct PcxHeader_t {\n\tBYTE manufacturer;\n\tBYTE version;\n\tBYTE rle;\n\tBYTE bpp;\n\tUINT16 xMin;\n\tUINT16 yMin;\n\tUINT16 xMax;\n\tUINT16 yMax;\n\tUINT16 h_dpi;\n\tUINT16 v_dpi;\n\tRGB888 headerPalette[16];\n\tBYTE reserved;\n\tBYTE planes;\n\tUINT16 bytesPerLine;\n\tUINT16 palInterpret;\n\tUINT16 h_res;\n\tUINT16 v_res;\n\tBYTE reservedData[54];\n} PCX_HEADER;\n\ntypedef struct TgaHeader_t {\n\tUINT8 idLength;\n\tUINT8 colorMapType;\n\tUINT8 dataTypeCode;\n\tUINT16 colorMapOrigin;\n\tUINT16 colorMapLength;\n\tUINT8 colorMapDepth;\n\tUINT16 xOrigin;\n\tUINT16 yOrigin;\n\tUINT16 width;\n\tUINT16 height;\n\tUINT8 bpp;\n\tUINT8 imageDescriptor;\n} TGA_HEADER;\n\ntypedef struct BitmapResource_t {\n\tLPBITMAPINFO bmpInfo;\n\tvoid *bmpData;\n\tHPALETTE hPalette;\n\tDWORD flags;\n} BITMAP_RESOURCE;\n\ntypedef struct RoomLightTable_t {\n\tint table[32];\n} ROOM_LIGHT_TABLE;\n\ntypedef struct WavePcmHeader_t {\n\tDWORD dwRiffChunkID;\n\tDWORD dwRiffChunkSize;\n\tDWORD dwFormat;\n\tDWORD dwFmtSubchunkID;\n\tDWORD dwFmtSubchunkSize;\n\tUINT16 wFormatTag;\n\t__int16 nChannels;\n\tint nSamplesPerSec;\n\tint nAvgBytesPerSec;\n\t__int16 nBlockAlign;\n\tUINT16 wBitsPerSample;\n\tDWORD dwDataSubchunkID;\n\tDWORD dwDataSubchunkSize;\n} WAVEPCM_HEADER;\n\ntypedef struct SampleInfo_t {\n\t__int16 sfxID;\n\t__int16 volume;\n\t__int16 randomness;\n\tUINT16 flags;\n} SAMPLE_INFO;\n\ntypedef struct SfxInfo_t {\n\tint volume;\n\tint pan;\n\tint sampleIdx;\n\tint freqFactor;\n} SFX_INFO;\n\ntypedef struct GameFlow_t {\n\tint firstOption;\n\tint titleReplace;\n\tint onDeath_DemoMode;\n\tint onDeath_InGame;\n\tint noInput_Time;\n\tint onDemo_Interrupt;\n\tint onDemo_End;\n\tUINT16 reserved1[18];\n\tUINT16 num_Levels;\n\tUINT16 num_Pictures;\n\tUINT16 num_Titles;\n\tUINT16 num_Fmvs;\n\tUINT16 num_Cutscenes;\n\tUINT16 num_Demos;\n\tUINT16 titleTrack;\n\t__int16 singleLevel;\n\tUINT16 reserved2[16];\n\tUINT16 flags;\n\tUINT16 reserved3[3];\n\tBYTE cypherCode;\n\tBYTE language;\n\tBYTE secretTrack;\n\tBYTE levelCompleteTrack;\n\tUINT16 reserved4[2];\n} GAME_FLOW;\n\ntypedef struct RequestInfo_t {\n\tUINT16 reqFlags;\n\tUINT16 itemsCount;\n\tUINT16 selected;\n\tUINT16 visibleCount;\n\tUINT16 lineOffset;\n\tUINT16 lineOldOffset;\n\tUINT16 pixWidth;\n\tUINT16 lineHeight;\n\t__int16 xPos;\n\t__int16 yPos;\n\t__int16 zPos;\n\tUINT16 itemStringLen;\n\tchar *lpItemStrings1;\n\tchar *lpItemStrings2;\n\tDWORD *lpItemFlags1;\n\tDWORD *lpItemFlags2;\n\tDWORD headingFlags1;\n\tDWORD headingFlags2;\n\tDWORD backgroundFlags;\n\tDWORD moreupFlags;\n\tDWORD moredownFlags;\n\tDWORD itemFlags1[24];\n\tDWORD itemFlags2[24];\n\tTEXT_STR_INFO *headingText1;\n\tTEXT_STR_INFO *headingText2;\n\tTEXT_STR_INFO *backgroundText;\n\tTEXT_STR_INFO *moreupText;\n\tTEXT_STR_INFO *moredownText;\n\tTEXT_STR_INFO *itemTexts1[24];\n\tTEXT_STR_INFO *itemTexts2[24];\n\tchar headingString1[32];\n\tchar headingString2[32];\n\tDWORD renderWidth;\n\tDWORD renderHeight;\n\n} REQUEST_INFO;\n\ntypedef struct InventoryItem_t {\n\tchar *lpString;\n\t__int16 objectID;\n\t__int16 framesTotal;\n\t__int16 currentFrame;\n\t__int16 goalFrame;\n\t__int16 openFrame;\n\t__int16 animDirection;\n\t__int16 animSpeed;\n\t__int16 animCount;\n\t__int16 xRotPtSel;\n\t__int16 xRotPt;\n\t__int16 xRotSel;\n\t__int16 xRot;\n\t__int16 yRotSel;\n\t__int16 yRot;\n\t__int16 zRot;\n\tint yTransSel;\n\tint yTrans;\n\tint zTransSel;\n\tint zTrans;\n\tint meshesSel;\n\tint meshesDrawn;\n\t__int16 invPos;\n\tvoid *sprites;\n\tDWORD reserved1;\n\tDWORD reserved2;\n\tDWORD reserved3;\n\tDWORD reserved4;\n} INVENTORY_ITEM;\n\ntypedef struct StatisticsInfo_t {\n\tDWORD timer;\n\tDWORD shots;\n\tDWORD hits;\n\tDWORD distance;\n\tUINT16 kills;\n\tBYTE secrets;\n\tBYTE mediPacks;\n} STATISTICS_INFO;\n\ntypedef struct StartInfo_t {\n\tUINT16 pistolAmmo;\n\tUINT16 magnumAmmo;\n\tUINT16 uziAmmo;\n\tUINT16 shotgunAmmo;\n\tUINT16 m16Ammo;\n\tUINT16 grenadeAmmo;\n\tUINT16 harpoonAmmo;\n\tBYTE smallMedipacks;\n\tBYTE largeMedipacks;\n\tBYTE unused;\n\tBYTE flares;\n\tBYTE gunStatus;\n\tBYTE gunType;\n\tUINT16 available : 1;\n\tUINT16 has_pistols : 1;\n\tUINT16 has_magnums : 1;\n\tUINT16 has_uzis : 1;\n\tUINT16 has_shotgun : 1;\n\tUINT16 has_m16 : 1;\n\tUINT16 has_grenade : 1;\n\tUINT16 has_harpoon : 1;\n\tUINT16 pad : 8;\n\tUINT16 reserved;\n\tSTATISTICS_INFO statistics;\n} START_INFO;\n\ntypedef struct SaveGame_t {\n\tSTART_INFO start[24];\n\tSTATISTICS_INFO statistics;\n\t__int16 currentLevel;\n\tbool bonusFlag;\n\tBYTE numPickup[2];\n\tBYTE numPuzzle[4];\n\tBYTE numKey[4];\n\tUINT16 reserved;\n\tBYTE buffer[6272];\n} SAVEGAME_INFO;\n\ntypedef struct Pos2D_t {\n\t__int16 x;\n\t__int16 y;\n} POS_2D;\n\ntypedef struct Pos3D_t {\n\t__int16 x;\n\t__int16 y;\n\t__int16 z;\n} POS_3D;\n\ntypedef struct PhdVector_t {\n\tint x;\n\tint y;\n\tint z;\n} PHD_VECTOR;\n\ntypedef struct GameVector_t {\n\tint x;\n\tint y;\n\tint z;\n\t__int16 roomNumber;\n\t__int16 boxNumber;\n} GAME_VECTOR;\n\ntypedef struct ObjectVector_t {\n\tint x;\n\tint y;\n\tint z;\n\tUINT16 data;\n\tUINT16 flags;\n} OBJECT_VECTOR;\n\ntypedef struct VectorAngles_t {\n\t__int16 yaw;\n\t__int16 pitch;\n} VECTOR_ANGLES;\n\ntypedef struct Phd3dPos_t {\n\tint x;\n\tint y;\n\tint z;\n\t__int16 rotX;\n\t__int16 rotY;\n\t__int16 rotZ;\n} PHD_3DPOS;\n\ntypedef struct ItemInfo_t {\n\tint floor;\n\tDWORD touchBits;\n\tDWORD meshBits;\n\t__int16 objectID;\n\t__int16 currentAnimState;\n\t__int16 goalAnimState;\n\t__int16 requiredAnimState;\n\t__int16 animNumber;\n\t__int16 frameNumber;\n\t__int16 roomNumber;\n\t__int16 nextItem;\n\t__int16 nextActive;\n\t__int16 speed;\n\t__int16 fallSpeed;\n\t__int16 hitPoints;\n\t__int16 boxNumber;\n\t__int16 timer;\n\tUINT16 flags; // see IFL_* defines\n\t__int16 shade1;\n\t__int16 shade2;\n\t__int16 carriedItem;\n\tLPVOID data;\n\tPHD_3DPOS pos;\n\tUINT16 active : 1;\n\tUINT16 status : 2; // see ITEM_STATUS enum\n\tUINT16 gravity : 1;\n\tUINT16 hit_status : 1;\n\tUINT16 collidable : 1;\n\tUINT16 looked_at : 1;\n\tUINT16 dynamic_light : 1;\n\tUINT16 clear_body : 1;\n\tUINT16 pad : 7;\n} ITEM_INFO;\n\ntypedef struct CameraInfo_t {\n\tGAME_VECTOR pos;\n\tGAME_VECTOR target;\n\tCAMERA_TYPE type;\n\tint shift;\n\tDWORD flags;\n\tint fixedCamera;\n\tint numberFrames;\n\tint bounce;\n\tint underwater;\n\tint targetDistance;\n\tint targetSquare;\n\t__int16 targetAngle;\n\t__int16 actualAngle;\n\t__int16 targetElevation;\n\t__int16 box;\n\t__int16 number;\n\t__int16 last;\n\t__int16 timer;\n\t__int16 speed;\n\tITEM_INFO *item;\n\tITEM_INFO *last_item;\n\tOBJECT_VECTOR *fixed;\n\tBOOL isLaraMic;\n\tPHD_VECTOR micPos;\n} CAMERA_INFO;\n\ntypedef struct CollSide_t {\n\tint floor;\n\tint ceiling;\n\tint type;\n} COLL_SIDE;\n\ntypedef struct CollInfo_t {\n\tCOLL_SIDE sideMid;\n\tCOLL_SIDE sideFront;\n\tCOLL_SIDE sideLeft;\n\tCOLL_SIDE sideRight;\n\tint radius;\n\tint badPos;\n\tint badNeg;\n\tint badCeiling;\n\tPHD_VECTOR shift;\n\tPHD_VECTOR old;\n\t__int16 oldAnimState;\n\t__int16 oldAnimNumber;\n\t__int16 oldFrameNumber;\n\t__int16 facing;\n\t__int16 quadrant;\n\t__int16 collType;\n\t__int16 *trigger;\n\tchar xTilt;\n\tchar zTilt;\n\tchar hitByBaddie;\n\tchar hitStatic;\n\tUINT16 flags;\n} COLL_INFO;\n\ntypedef struct ObjectInfo_t {\n\t__int16 nMeshes;\n\t__int16 meshIndex;\n\tint boneIndex;\n\t__int16 *frameBase;\n\tvoid (__cdecl *initialise)(__int16 itemNumber);\n\tvoid (__cdecl *control)(__int16 itemNumber);\n\tvoid (__cdecl *floor)(ITEM_INFO *item, int x, int y, int z, __int16 *height);\n\tvoid (__cdecl *ceiling)(ITEM_INFO *item, int x, int y, int z, __int16 *height);\n\tvoid (__cdecl *drawRoutine)(ITEM_INFO *item);\n\tvoid (__cdecl *collision)(__int16 itemNum, ITEM_INFO *laraItem, COLL_INFO *coll);\n\t__int16 animIndex;\n\t__int16 hitPoints;\n\t__int16 pivotLength;\n\t__int16 radius;\n\t__int16 shadowSize;\n\tUINT16 loaded : 1;\n\tUINT16 intelligent : 1;\n\tUINT16 save_position : 1;\n\tUINT16 save_hitpoints : 1;\n\tUINT16 save_flags : 1;\n\tUINT16 save_anim : 1;\n\tUINT16 semi_transparent : 1;\n\tUINT16 water_creature : 1;\n\tUINT16 pad : 8;\n} OBJECT_INFO;\n\ntypedef struct PhdMatrix_t {\n\tint _00, _01, _02, _03;\n\tint _10, _11, _12, _13;\n\tint _20, _21, _22, _23;\n} PHD_MATRIX;\n\ntypedef struct DoorInfo_t {\n\t__int16 room;\n\t__int16 x;\n\t__int16 y;\n\t__int16 z;\n\tPOS_3D vertex[4];\n} DOOR_INFO;\n\ntypedef struct DoorInfos_t {\n\t__int16 wCount;\n\tDOOR_INFO door[];\n} DOOR_INFOS;\n\ntypedef struct FloorInfo_t {\n\t__int16 index;\n\t__int16 box;\n\tchar pitRoom;\n\tchar floor;\n\tchar skyRoom;\n\tchar ceiling;\n} FLOOR_INFO;\n\ntypedef struct LightInfo_t {\n\tint x;\n\tint y;\n\tint z;\n\t__int16 intensity1;\n\t__int16 intensity2;\n\tint fallOff1;\n\tint fallOff2;\n} LIGHT_INFO;\n\ntypedef struct MeshInfo_t {\n\tint x;\n\tint y;\n\tint z;\n\t__int16 yRot;\n\t__int16 shade1;\n\t__int16 shade2;\n\t__int16 staticNumber;\n} MESH_INFO;\n\ntypedef struct RoomInfo_t {\n\t__int16 *data;\n\tDOOR_INFOS *doors;\n\tFLOOR_INFO *floor;\n\tLIGHT_INFO *light;\n\tMESH_INFO *mesh;\n\tint x;\n\tint y;\n\tint z;\n\tint minFloor;\n\tint maxCeiling;\n\t__int16 xSize;\n\t__int16 ySize;\n\t__int16 ambient1;\n\t__int16 ambient2;\n\t__int16 lightMode;\n\t__int16 numLights;\n\t__int16 numMeshes;\n\t__int16 boundLeft;\n\t__int16 boundRight;\n\t__int16 boundTop;\n\t__int16 boundBottom;\n\tUINT16 boundActive;\n\t__int16 left;\n\t__int16 right;\n\t__int16 top;\n\t__int16 bottom;\n\t__int16 itemNumber;\n\t__int16 fxNumber;\n\t__int16 flippedRoom;\n\tUINT16 flags;\n} ROOM_INFO;\n\ntypedef struct PhdVBuf_t {\n\tfloat xv;\n\tfloat yv;\n\tfloat zv;\n\tfloat rhw;\n\tfloat xs;\n\tfloat ys;\n\t__int16 clip;\n\t__int16 g;\n\t__int16 u;\n\t__int16 v;\n} PHD_VBUF;\n\ntypedef struct PointInfo_t {\n\tfloat xv;\n\tfloat yv;\n\tfloat zv;\n\tfloat rhw;\n\tfloat xs;\n\tfloat ys;\n\tfloat u;\n\tfloat v;\n\tfloat g;\n} POINT_INFO;\n\ntypedef struct VertexInfo_t {\n\tfloat x;\n\tfloat y;\n\tfloat rhw;\n\tfloat u;\n\tfloat v;\n\tfloat g;\n} VERTEX_INFO;\n\ntypedef struct RoomVertexInfo_t {\n\t__int16 x;\n\t__int16 y;\n\t__int16 z;\n\t__int16 lightBase;\n\tBYTE lightTableValue;\n\tBYTE flags;\n\t__int16 lightAdder;\n} ROOM_VERTEX_INFO;\n\ntypedef struct AnimStruct_t {\n\t__int16 *framePtr;\n\t__int16 interpolation;\n\t__int16 currentAnimState;\n\tint velocity;\n\tint acceleration;\n\t__int16 frameBase;\n\t__int16 frameEnd;\n\t__int16 jumpAnimNum;\n\t__int16 jumpFrameNum;\n\t__int16 numberChanges;\n\t__int16 changeIndex;\n\t__int16 numberCommands;\n\t__int16 commandIndex;\n} ANIM_STRUCT;\n\ntypedef struct ChangeStruct_t {\n\t__int16 goalAnimState;\n\t__int16 numberRanges;\n\t__int16 rangeIndex;\n} CHANGE_STRUCT;\n\ntypedef struct RangeStruct_t {\n\t__int16 startFrame;\n\t__int16 endFrame;\n\t__int16 linkAnimNum;\n\t__int16 linkFrameNum;\n} RANGE_STRUCT;\n\ntypedef struct StaticBounds_t {\n\t__int16 xMin;\n\t__int16 xMax;\n\t__int16 yMin;\n\t__int16 yMax;\n\t__int16 zMin;\n\t__int16 zMax;\n} STATIC_BOUNDS;\n\ntypedef struct StaticInfo_t {\n\t__int16 meshIndex;\n\tUINT16 flags;\n\tSTATIC_BOUNDS drawBounds;\n\tSTATIC_BOUNDS collisionBounds;\n} STATIC_INFO;\n\ntypedef struct PhdSprite_t {\n\tUINT16 texPage;\n\tUINT16 offset;\n\tUINT16 width;\n\tUINT16 height;\n\t__int16 x1;\n\t__int16 y1;\n\t__int16 x2;\n\t__int16 y2;\n} PHD_SPRITE;\n\ntypedef struct BoxInfo_t {\n\tBYTE left;\n\tBYTE right;\n\tBYTE top;\n\tBYTE bottom;\n\tUINT16 height;\n\tUINT16 overlapIndex;\n} BOX_INFO;\n\ntypedef struct CineFrameInfo_t {\n\t__int16 xTarget;\n\t__int16 yTarget;\n\t__int16 zTarget;\n\t__int16 zPos;\n\t__int16 yPos;\n\t__int16 xPos;\n\t__int16 fov;\n\t__int16 roll;\n} CINE_FRAME_INFO;\n\ntypedef struct ControlLayout_t {\n#ifdef FEATURE_HUD_IMPROVED\n\tBYTE key[16];\n#else // FEATURE_HUD_IMPROVED\n\tUINT16 key[14];\n#endif // FEATURE_HUD_IMPROVED\n} CONTROL_LAYOUT;\n\ntypedef struct InventorySprite_t {\n\t__int16 shape;\n\t__int16 x;\n\t__int16 y;\n\t__int16 z;\n\tint param1;\n\tint param2;\n\tLPVOID gour;\n\tUINT16 invColour;\n} INVENTORY_SPRITE;\n\ntypedef struct AssaultStats_t {\n\tDWORD bestTime[10];\n\tDWORD bestFinish[10];\n\tDWORD finishCount;\n} ASSAULT_STATS;\n\ntypedef struct PickupInfo_t {\n\t__int16 timer;\n\t__int16 sprite;\n} PICKUP_INFO;\n\ntypedef struct InvMotionInfo_t {\n\t__int16 framesCount;\n\t__int16 status;\n\t__int16 statusTarget;\n\t__int16 radiusTarget;\n\t__int16 radiusRate;\n\t__int16 cameraTarget_y;\n\t__int16 cameraRate_y;\n\t__int16 cameraTarget_pitch;\n\t__int16 cameraRate_pitch;\n\t__int16 rotateTarget;\n\t__int16 rotateRate;\n\t__int16 itemTarget_xRotPt;\n\t__int16 itemRate_xRotPt;\n\t__int16 itemTarget_xRot;\n\t__int16 itemRate_xRot;\n\tint itemTarget_yTrans;\n\tint itemRate_yTrans;\n\tint itemTarget_zTrans;\n\tint itemRate_zTrans;\n\tint misc;\n} INV_MOTION_INFO;\n\ntypedef struct RingInfo_t {\n\tINVENTORY_ITEM **itemList;\n\t__int16 type;\n\t__int16 radius;\n\t__int16 cameraPitch;\n\t__int16 isRotating;\n\t__int16 rotCount;\n\t__int16 currentObj;\n\t__int16 targetObj;\n\t__int16 objCount;\n\t__int16 angleAdder;\n\t__int16 rotAdder;\n\t__int16 rotAdderL;\n\t__int16 rotAdderR;\n\tPHD_3DPOS ringPos;\n\tPHD_3DPOS camera;\n\tPHD_VECTOR light;\n\tINV_MOTION_INFO *motionInfo;\n} RING_INFO;\n\ntypedef struct BoxNode_t {\n\t__int16 exit_box;\n\tUINT16 search_number;\n\t__int16 next_expansion;\n\t__int16 box_number;\n} BOX_NODE;\n\ntypedef struct LotInfo_t {\n\tBOX_NODE *node;\n\t__int16 head;\n\t__int16 tail;\n\tUINT16 search_number;\n\tUINT16 block_mask;\n\t__int16 step;\n\t__int16 drop;\n\t__int16 fly;\n\t__int16 zone_count;\n\t__int16 target_box;\n\t__int16 required_box;\n\tPHD_VECTOR target;\n} LOT_INFO;\n\ntypedef struct FxInfo_t {\n\tPHD_3DPOS pos;\n\t__int16 room_number;\n\t__int16 object_number;\n\t__int16 next_fx;\n\t__int16 next_active;\n\t__int16 speed;\n\t__int16 fallspeed;\n\t__int16 frame_number;\n\t__int16 counter;\n\t__int16 shade;\n} FX_INFO;\n\ntypedef struct CreatureInfo_t {\n\t__int16 head_rotation;\n\t__int16 neck_rotation;\n\t__int16 maximum_turn;\n\tUINT16 flags;\n\t__int16 item_num;\n\tMOOD_TYPE mood;\n\tLOT_INFO LOT;\n\tPHD_VECTOR target;\n\tITEM_INFO *enemy;\n} CREATURE_INFO;\n\ntypedef struct BoatInfo_t {\n\tint turn;\n\tint leftFallspeed;\n\tint rightFallspeed;\n\t__int16 tiltAngle;\n\t__int16 extraRotation;\n\tint water;\n\tint pitch;\n} BOAT_INFO;\n\ntypedef struct SkidooInfo_t {\n\t__int16 trackMesh;\n\tint turn;\n\tint leftFallspeed;\n\tint rightFallspeed;\n\t__int16 tiltAngle;\n\t__int16 extraRotation;\n\tint pitch;\n} SKIDOO_INFO;\n\ntypedef struct LaraArm_t {\n\t__int16 *frame_base;\n\t__int16 frame_number;\n\t__int16 anim_number;\n\t__int16 lock;\n\t__int16 y_rot;\n\t__int16 x_rot;\n\t__int16 z_rot;\n\t__int16 flash_gun;\n} LARA_ARM;\n\ntypedef struct LaraInfo_t {\n\t__int16 item_number;\n\t__int16 gun_status;\n\t__int16 gun_type;\n\t__int16 request_gun_type;\n\t__int16 last_gun_type;\n\t__int16 calc_fallspeed;\n\t__int16 water_status;\n\t__int16 climb_status;\n\t__int16 pose_count;\n\t__int16 hit_frame;\n\t__int16 hit_direction;\n\t__int16 air;\n\t__int16 dive_count;\n\t__int16 death_count;\n\t__int16 current_active;\n\t__int16 spaz_effect_count;\n\t__int16 flare_age;\n\t__int16 skidoo;\n\t__int16 weapon_item;\n\t__int16 back_gun;\n\t__int16 flare_frame;\n\tUINT16 flare_control_left : 1;\n\tUINT16 flare_control_right : 1;\n\tUINT16 extra_anim : 1;\n\tUINT16 look : 1;\n\tUINT16 burn : 1;\n\tUINT16 keep_ducked : 1;\n\tUINT16 CanMonkeySwing : 1;\n\tUINT16 pad : 9;\n\tint water_surface_dist;\n\tPHD_VECTOR last_pos;\n\tFX_INFO *spaz_effect;\n\tDWORD mesh_effects;\n\t__int16 *mesh_ptrs[15];\n\tITEM_INFO *target;\n\t__int16 target_angles[2];\n\t__int16 turn_rate;\n\t__int16 move_angle;\n\t__int16 head_y_rot;\n\t__int16 head_x_rot;\n\t__int16 head_z_rot;\n\t__int16 torso_y_rot;\n\t__int16 torso_x_rot;\n\t__int16 torso_z_rot;\n\tLARA_ARM left_arm;\n\tLARA_ARM right_arm;\n\tDWORD pistol_ammo;\n\tDWORD magnum_ammo;\n\tDWORD uzi_ammo;\n\tDWORD shotgun_ammo;\n\tDWORD harpoon_ammo;\n\tDWORD grenade_ammo;\n\tDWORD m16_ammo;\n\tCREATURE_INFO *creature;\n} LARA_INFO;\n\ntypedef struct BiteInfo_t {\n\tint x;\n\tint y;\n\tint z;\n\tint meshIndex;\n} BITE_INFO;\n\n\ntypedef struct AIInfo_t {\n\t__int16 zone_number;\n\t__int16 enemy_zone;\n\tint distance;\n\tint ahead;\n\tint bite;\n\t__int16 angle;\n\t__int16 enemy_facing;\n} AI_INFO;\n\ntypedef struct WeaponInfo_t {\n\t__int16 lockAngles[4];\n\t__int16 leftAngles[4];\n\t__int16 rightAngles[4];\n\t__int16 aimSpeed;\n\t__int16 shotAccuracy;\n\tint gunHeight;\n\tint damage;\n\tint targetDist;\n\t__int16 recoilFrame;\n\t__int16 flashTime;\n\t__int16 sampleNum;\n} WEAPON_INFO;\n\n#pragma pack(pop)\n\n#endif // GLOBAL_TYPES_H_INCLUDED\n"
  },
  {
    "path": "global/vars.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef GLOBAL_VARS_H_INCLUDED\n#define GLOBAL_VARS_H_INCLUDED\n\n/*\n * String Constants\n */\n\n#define GameWindowName\t\t\"Tomb Raider II\"\n#define GameClassName\t\t\"Dude:TombRaiderII:DDWndClass\"\n\n#define GameDialogName\t\t\"Tomb Raider II\"\n#define DialogClassName\t\t\"Dude:TombRaiderII:DWWndClass\"\n\n#define MessageBoxName\t\t\"Tomb Raider II\"\n\n// Variable macros\n#define VAR_U_(address, type)\t\t\t(*(type*)(address)) // uninitialized variable\n#define VAR_I_(address, type, value)\t(*(type*)(address)) // initialized variable (value is just for info)\n#define ARRAY_(address, type, length)\t(*(type(*)length)(address)) // array (can be multidimensional)\n\n/*\n * General Variables\n */\n// 3D insert function variables\n#define ins_trans_quad\t\t(*(void(__cdecl **)(int,int,int,int,int))\t\t\t\t0x00470318)\n#define ins_poly_trans8\t\t(*(void(__cdecl **)(PHD_VBUF*,__int16))\t\t\t\t\t0x0047032C)\n#define ins_flat_rect\t\t(*(void(__cdecl **)(int,int,int,int,int,BYTE))\t\t\t0x0047805C)\n#ifdef FEATURE_VIDEOFX_IMPROVED\n#define ins_sprite\t\t\t(*(void(__cdecl **)(int,int,int,int,int,int,__int16,DWORD))\t0x004B2A10)\n#else // FEATURE_VIDEOFX_IMPROVED\n#define ins_sprite\t\t\t(*(void(__cdecl **)(int,int,int,int,int,int,__int16))\t0x004B2A10)\n#endif // FEATURE_VIDEOFX_IMPROVED\n#define ins_objectGT3\t\t(*(__int16*(__cdecl **)(__int16*,int,SORTTYPE))\t\t\t0x004B2A1C)\n#define ins_objectGT4\t\t(*(__int16*(__cdecl **)(__int16*,int,SORTTYPE))\t\t\t0x004B2A20)\n#define ins_line\t\t\t(*(void(__cdecl **)(int,int,int,int,int,BYTE))\t\t\t0x004B2AE8)\n#define ins_objectG4\t\t(*(__int16*(__cdecl **)(__int16*,int,SORTTYPE))\t\t\t0x004BCAF8)\n#define ins_objectG3\t\t(*(__int16*(__cdecl **)(__int16*,int,SORTTYPE))\t\t\t0x004BCB40)\n\n#define SfxFunctions\t\t(*(void(__cdecl *(*)[32])(ITEM_INFO*))\t\t0x004641F8)\n\n// Initialized variables\n#define PerspectiveDistance\t\t\tVAR_I_(0x00464060, DWORD,\t\t\t0x3000000)\n#define RhwFactor \t\t\t\t\tVAR_I_(0x0046408C, float,\t\t\t0x14000000.p0)\n#define CineTrackID\t\t\t\t\tVAR_I_(0x004640B0, int,\t\t\t\t1)\n#define CineTickRate\t\t\t\tVAR_I_(0x004640B8, int,\t\t\t\t0x8000) // 0x8000 = PHD_ONE/TICKS_PER_FRAME\n#define CD_TrackID\t\t\t\t\tVAR_I_(0x004640BC, __int16,\t\t\t-1)\n#define FlipEffect\t\t\t\t\tVAR_I_(0x004640C4, int,\t\t\t\t-1)\n#define AssaultBestTime\t\t\t\tVAR_I_(0x004641F0, int,\t\t\t\t-1)\n#define GF_NumSecrets\t\t\t\tVAR_I_(0x004642E8, __int16,\t\t\t3)\n#define CineTargetAngle\t\t\t\tVAR_I_(0x00464310, __int16,\t\t\tPHD_90)\n#define OverlayStatus\t\t\t\tVAR_I_(0x004644E0, int,\t\t\t\t1)\n#define InvMainObjectsCount\t\t\tVAR_I_(0x004654E0, __int16,\t\t\t8)\n#ifdef FEATURE_HUD_IMPROVED\nextern __int16 InvOptionObjectsCount;\n#else // FEATURE_HUD_IMPROVED\n#define InvOptionObjectsCount\t\tVAR_I_(0x00465604, __int16,\t\t\t4)\n#endif // FEATURE_HUD_IMPROVED\n#define GymInvOpenEnabled\t\t\tVAR_I_(0x00465618, BOOL,\t\t\tTRUE)\n#define InventoryChosen\t\t\t\tVAR_I_(0x00465A50, __int16,\t\t\t-1)\n#define InventoryMode\t\t\t\tVAR_I_(0x00465A54, INVENTORY_MODE,\tINV_TitleMode)\n#define SoundVolume\t\t\t\t\tVAR_I_(0x00465A5C, __int16,\t\t\t165) // NOTE: value should be 10\n#define MusicVolume\t\t\t\t\tVAR_I_(0x00465A60, __int16,\t\t\t255) // NOTE: value should be 10\n#define BGND_PaletteIndex\t\t\tVAR_I_(0x00466400, int,\t\t\t\t-1)\n#define ScreenSizer \t\t\t\tVAR_I_(0x00466480, double,\t\t\t1.0)\n#define GameSizer \t\t\t\t\tVAR_I_(0x00466488, double,\t\t\t1.0)\n#define FadeValue\t\t\t\t\tVAR_I_(0x00466490, int,\t\t\t\t0x100000)\n#define FadeLimit\t\t\t\t\tVAR_I_(0x00466494, int,\t\t\t\t0x100000)\n#define FadeAdder\t\t\t\t\tVAR_I_(0x00466498, int,\t\t\t\t0x8000)\n#define RandomControl\t\t\t\tVAR_I_(0x00466BB0, int,\t\t\t\tRANDOM_SEED)\n#define RandomDraw\t\t\t\t\tVAR_I_(0x00466BB4, int,\t\t\t\tRANDOM_SEED)\n#define PaletteIndex\t\t\t\tVAR_I_(0x00466BDC, int,\t\t\t\t-1)\n#define DumpX\t\t\t\t\t\tVAR_I_(0x00466BE4, __int16,\t\t\t25)\n#define DumpY\t\t\t\t\t\tVAR_I_(0x00466BE6, __int16,\t\t\t25)\n#define DumpWidth\t\t\t\t\tVAR_I_(0x00466BE8, __int16,\t\t\t50)\n#define DumpHeight\t\t\t\t\tVAR_I_(0x00466BEA, __int16,\t\t\t0)\n#define DetailLevel\t\t\t\t\tVAR_I_(0x00467724, DWORD,\t\t\t1)\n#define MidSort\t\t\t\t\t\tVAR_I_(0x0046C2F0, DWORD,\t\t\t0)\n#define FltViewAspect\t\t\t\tVAR_I_(0x0046C2F4, float,\t\t\t0.0)\n#define XGen_y0\t\t\t\t\t\tVAR_I_(0x0046C2F8, int,\t\t\t\t0)\n#define XGen_y1\t\t\t\t\t\tVAR_I_(0x0046C2FC, int,\t\t\t\t0)\n\n// Uninitialized variables\n#define PhdWinTop\t\t\t\t\tVAR_U_(0x0046E300, int)\n#define LsAdder\t\t\t\t\t\tVAR_U_(0x00470308, int)\n#define FltWinBottom\t\t\t\tVAR_U_(0x0047030C, float)\n#define FltResZBuf\t\t\t\t\tVAR_U_(0x00470310, float)\n#define FltResZ\t\t\t\t\t\tVAR_U_(0x00470314, float)\n#define PhdWinHeight\t\t\t\tVAR_U_(0x0047031C, int)\n#define PhdWinCenterX\t\t\t\tVAR_U_(0x00470320, int)\n#define PhdWinCenterY\t\t\t\tVAR_U_(0x00470324, int)\n#define PhdLsYaw\t\t\t\t\tVAR_U_(0x00470328, __int16)\n#define FltWinTop\t\t\t\t\tVAR_U_(0x00470330, float)\n#define FltWinLeft\t\t\t\t\tVAR_U_(0x00478038, float)\n#define PhdWinMinY\t\t\t\t\tVAR_U_(0x0047803C, __int16)\n#define PhdFarZ \t\t\t\t\tVAR_U_(0x00478048, int)\n#define FltRhwOPersp\t\t\t\tVAR_U_(0x0047804C, float)\n#define PhdWinBottom\t\t\t\tVAR_U_(0x00478050, int)\n#define PhdPersp\t\t\t\t\tVAR_U_(0x00478054, int)\n#define PhdWinLeft \t\t\t\t\tVAR_U_(0x00478058, int)\n#define PhdWinMaxX \t\t\t\t\tVAR_U_(0x004B29E0, __int16)\n#define PhdNearZ \t\t\t\t\tVAR_U_(0x004B29E4, int)\n#define FltResZORhw \t\t\t\tVAR_U_(0x004B29E8, float)\n#define FltFarZ \t\t\t\t\tVAR_U_(0x004B29EC, float)\n#define FltWinCenterX\t\t\t\tVAR_U_(0x004B29F0, float)\n#define FltWinCenterY\t\t\t\tVAR_U_(0x004B29F4, float)\n#define PhdScreenHeight\t\t\t\tVAR_U_(0x004B29F8, int)\n#define PrintSurfacePtr\t\t\t\tVAR_U_(0x004B29FC, BYTE*)\n#define PhdWinMinX\t\t\t\t\tVAR_U_(0x004B2A00, __int16)\n#define FltPerspONearZ\t\t\t\tVAR_U_(0x004B2A04, float)\n#define FltRhwONearZ\t\t\t\tVAR_U_(0x004B2A08, float)\n#define PhdWinMaxY\t\t\t\t\tVAR_U_(0x004B2A0C, __int16)\n#define FltNearZ\t\t\t\t\tVAR_U_(0x004B2A14, float)\n#define PhdMatrixPtr\t\t\t\tVAR_U_(0x004B2A18, PHD_MATRIX*)\n#define FltPersp\t\t\t\t\tVAR_U_(0x004B2AA8, float)\n#define MatrixW2V\t\t\t\t\tVAR_U_(0x004B2AB0, PHD_MATRIX)\n#define Info3dPtr\t\t\t\t\tVAR_U_(0x004B2AE0, __int16*)\n#define PhdWinWidth\t\t\t\t\tVAR_U_(0x004B2AE4, int)\n#define PhdViewDistance\t\t\t\tVAR_U_(0x004BCAF0, int)\n#define PhdLsPitch\t\t\t\t\tVAR_U_(0x004BCAF4, __int16)\n#define PhdScreenWidth\t\t\t\tVAR_U_(0x004BF3C8, int)\n#define LsDivider\t\t\t\t\tVAR_U_(0x004BF3CC, int)\n#define FltWinRight\t\t\t\t\tVAR_U_(0x004D6B50, float)\n#define LsVectorView\t\t\t\tVAR_U_(0x004D6B58, PHD_VECTOR)\n#define PhdWinRight\t\t\t\t\tVAR_U_(0x004D6BE8, int)\n#define SurfaceCount\t\t\t\tVAR_U_(0x004D6BEC, DWORD)\n#define Sort3dPtr\t\t\t\t\tVAR_U_(0x004D6BF0, SORT_ITEM*)\n#define WibbleOffset\t\t\t\tVAR_U_(0x004D6BFC, int)\n#define IsWibbleEffect\t\t\t\tVAR_U_(0x004D6C00, BOOL)\n#define IsWaterEffect\t\t\t\tVAR_U_(0x004D6C04, BOOL)\n#define IsShadeEffect\t\t\t\tVAR_U_(0x004D6F68, bool)\n#define CineCurrentFrame\t\t\tVAR_U_(0x004D7770, int)\n#define IsChunkyCamera\t\t\t\tVAR_U_(0x004D777C, BOOL)\n#define NoInputCounter\t\t\t\tVAR_U_(0x004D7784, int)\n#define IsResetFlag\t\t\t\t\tVAR_U_(0x004D7788, BOOL)\n#define FlipTimer\t\t\t\t\tVAR_U_(0x004D778C, int)\n#define StopInventory\t\t\t\tVAR_U_(0x004D7794, BOOL)\n#define IsDemoLevelType\t\t\t\tVAR_U_(0x004D779C, BOOL)\n#define IsDemoLoaded\t\t\t\tVAR_U_(0x004D77A0, BOOL)\n#define BoundStart\t\t\t\t\tVAR_U_(0x004D77B0, int)\n#define BoundEnd\t\t\t\t\tVAR_U_(0x004D77B4, int)\n#define IsAssaultTimerDisplay\t\tVAR_U_(0x004D77D0, BOOL)\n#define IsAssaultTimerActive\t\tVAR_U_(0x004D77D4, BOOL)\n#define IsMonkAngry\t\t\t\t\tVAR_U_(0x004D77D8, BOOL)\n#define AmmoTextInfo\t\t\t\tVAR_U_(0x004D791C, TEXT_STR_INFO*)\n#define DisplayModeTextInfo\t\t\tVAR_U_(0x004D7920, TEXT_STR_INFO*)\n#define DisplayModeInfoTimer\t\tVAR_U_(0x004D7924, DWORD)\n#define InvMainCurrent\t\t\t\tVAR_U_(0x004D7928, UINT16)\n#define InvKeyObjectsCount\t\t\tVAR_U_(0x004D792C, UINT16)\n#define InvKeysCurrent\t\t\t\tVAR_U_(0x004D7930, UINT16)\n#define InvOptionCurrent\t\t\tVAR_U_(0x004D7934, UINT16)\n#define InvRingText\t\t\t\t\tVAR_U_(0x004D7944, TEXT_STR_INFO*)\n#define InvUpArrow1\t\t\t\t\tVAR_U_(0x004D794C, TEXT_STR_INFO*)\n#define InvUpArrow2\t\t\t\t\tVAR_U_(0x004D7950, TEXT_STR_INFO*)\n#define InvDownArrow1\t\t\t\tVAR_U_(0x004D7954, TEXT_STR_INFO*)\n#define InvDownArrow2\t\t\t\tVAR_U_(0x004D7958, TEXT_STR_INFO*)\n#define InputDB\t\t\t\t\t\tVAR_U_(0x004D795C, DWORD)\n#define IsInventoryActive\t\t\tVAR_U_(0x004D7968, UINT16)\n#define InvDemoMode\t\t\t\t\tVAR_U_(0x004D7990, BOOL)\n#define IsInvOptionsDelay\t\t\tVAR_U_(0x004D79A4, BOOL)\n#define InvOptionsDelayCounter\t\tVAR_U_(0x004D79A8, int)\n#define SoundOptionLine\t\t\t\tVAR_U_(0x004D79AC, UINT16)\n#define StatsRequester\t\t\t\tVAR_U_(0x004D79B0, REQUEST_INFO)\n#define Assault\t\t\t\t\t\tVAR_U_(0x004D7BC8, ASSAULT_STATS)\n#define LevelItemCount\t\t\t\tVAR_U_(0x004D7C28, int)\n#define HealthBarTimer\t\t\t\tVAR_U_(0x004D7C2C, int)\n#define CameraCount\t\t\t\t\tVAR_U_(0x004D7C64, DWORD)\n#define MinesDetonated\t\t\t\tVAR_U_(0x004D7E6C, BOOL)\n#define BGND_PictureIsReady\t\t\tVAR_U_(0x004D7E78, bool)\n#if (DIRECT3D_VERSION >= 0x900)\n#define D3DDev\t\t\t\t\t\tVAR_U_(0x004D7EAC, LPDIRECT3DDEVICE9)\n#define D3D\t\t\t\t\t\t\tVAR_U_(0x004D7EB0, LPDIRECT3D9)\n#else // (DIRECT3D_VERSION >= 0x900)\n#define D3DDev\t\t\t\t\t\tVAR_U_(0x004D7EAC, LPDIRECT3DDEVICE2)\n#define D3D\t\t\t\t\t\t\tVAR_U_(0x004D7EB0, LPDIRECT3D2)\n#define D3DView\t\t\t\t\t\tVAR_U_(0x004D7EB4, LPDIRECT3DVIEWPORT2)\n#define D3DMaterial\t\t\t\t\tVAR_U_(0x004D7EB8, LPDIRECT3DMATERIAL2)\n#endif // (DIRECT3D_VERSION >= 0x900)\n#define MinWindowClientHeight\t\tVAR_U_(0x004D7EC0, int)\n#if (DIRECT3D_VERSION < 0x900)\n#define DDrawInterface\t\t\t\tVAR_U_(0x004D7EC4, LPDIRECTDRAW)\n#endif // (DIRECT3D_VERSION < 0x900)\n#define IsGameWindowChanging\t\tVAR_U_(0x004D7EC8, bool)\n#define MaxWindowHeight\t\t\t\tVAR_U_(0x004D7ECC, int)\n#if (DIRECT3D_VERSION < 0x900)\n#define DDraw\t\t\t\t\t\tVAR_U_(0x004D7ED0, LPDIRECTDRAW2)\n#endif // (DIRECT3D_VERSION < 0x900)\n#define IsGameWindowCreated\t\t\tVAR_U_(0x004D7ED4, bool)\n#define IsGameWindowUpdating\t\tVAR_U_(0x004D7ED8, bool)\n#define IsDDrawGameWindowShow\t\tVAR_U_(0x004D7EDC, bool)\n#define MinWindowClientWidth\t\tVAR_U_(0x004D7EE0, int)\n#define IsGameWindowShow\t\t\tVAR_U_(0x004D7EE4, bool)\n#define IsMinWindowSizeSet\t\t\tVAR_U_(0x004D7EE8, bool)\n#define MaxWindowClientWidth\t\tVAR_U_(0x004D7EEC, int)\n#define GameWindowWidth\t\t\t\tVAR_U_(0x004D7EF0, int)\n#define IsMinMaxInfoSpecial\t\t\tVAR_U_(0x004D7EF4, bool)\n#define IsGameFullScreen\t\t\tVAR_U_(0x004D7EF8, bool)\n#define IsGameWindowMaximized\t\tVAR_U_(0x004D7EFC, bool)\n#define HGameWindow\t\t\t\t\tVAR_U_(0x004D7F00, HWND)\n#define GameWindowHeight\t\t\tVAR_U_(0x004D7F04, int)\n#define PrimaryDisplayAdapter\t\tVAR_U_(0x004D7F08, DISPLAY_ADAPTER_NODE*)\n#if (DIRECT3D_VERSION > 0x500)\nextern DISPLAY_ADAPTER CurrentDisplayAdapter;\n#else // (DIRECT3D_VERSION > 0x500)\n#define CurrentDisplayAdapter\t\tVAR_U_(0x004D7F10, DISPLAY_ADAPTER)\n#endif // (DIRECT3D_VERSION > 0x500)\n#define LockedBufferCount\t\t\tVAR_U_(0x004D8328, DWORD)\n#define GameWindowPositionX\t\t\tVAR_U_(0x004D832C, int)\n#define GameWindowPositionY\t\t\tVAR_U_(0x004D8330, int)\n#define DisplayAdapterList\t\t\tVAR_U_(0x004D8338, DISPLAY_ADAPTER_LIST)\n#define MaxWindowClientHeight\t\tVAR_U_(0x004D8344, int)\n#define IsMessageLoopClosed\t\t\tVAR_U_(0x004D8348, bool)\n#define MaxWindowWidth\t\t\t\tVAR_U_(0x004D834C, int)\n#define IsMaxWindowSizeSet\t\t\tVAR_U_(0x004D8350, bool)\n#define AppResultCode\t\t\t\tVAR_U_(0x004D8354, DWORD)\n#define FullScreenWidth\t\t\t\tVAR_U_(0x004D8358, int)\n#define FullScreenHeight\t\t\tVAR_U_(0x004D835C, int)\n#define FullScreenBPP\t\t\t\tVAR_U_(0x004D8360, int)\n#define FullScreenVGA\t\t\t\tVAR_U_(0x004D8364, int)\n#define IsGameToExit\t\t\t\tVAR_U_(0x004D8368, bool)\n#define GameWindow_Y\t\t\t\tVAR_U_(0x004D836C, int)\n#define GameWindow_X\t\t\t\tVAR_U_(0x004D8370, int)\n#define IsGameWindowMinimized\t\tVAR_U_(0x004D8374, bool)\n#define MinWindowWidth\t\t\t\tVAR_U_(0x004D8378, int)\n#define MinWindowHeight\t\t\t\tVAR_U_(0x004D837C, int)\n#define IsGameWindowActive\t\t\tVAR_U_(0x004D8380, bool)\n#define CurrentJoystick\t\t\t\tVAR_U_(0x004D8388, JOYSTICK)\n#define JoystickList\t\t\t\tVAR_U_(0x004D8540, JOYSTICK_LIST)\n#if (DIRECTINPUT_VERSION >= 0x800)\n#define DInput\t\t\t\t\t\tVAR_U_(0x004D854C, LPDIRECTINPUT8)\n#define IDID_SysKeyboard\t\t\tVAR_U_(0x004D8550, LPDIRECTINPUTDEVICE8)\n#define IDID_SysJoystick\t\t\tVAR_U_(0x004D8554, LPDIRECTINPUTDEVICE8)\n#else // (DIRECTINPUT_VERSION >= 0x800)\n#define DInput\t\t\t\t\t\tVAR_U_(0x004D854C, LPDIRECTINPUT)\n#define IDID_SysKeyboard\t\t\tVAR_U_(0x004D8550, LPDIRECTINPUTDEVICE)\n#define IDID_SysJoystick\t\t\tVAR_U_(0x004D8554, LPDIRECTINPUTDEVICE)\n#endif // (DIRECTINPUT_VERSION >= 0x800)\n#define IsVidSizeLock\t\t\t\tVAR_U_(0x004D855C, BOOL)\n#define SoundAdapterList\t\t\tVAR_U_(0x004D8960, SOUND_ADAPTER_LIST)\n#define IsSoundEnabled\t\t\t\tVAR_U_(0x004D8D70, bool)\n#if (DIRECTSOUND_VERSION >= 0x800)\n#define DSound\t\t\t\t\t\tVAR_U_(0x004D8D74, LPDIRECTSOUND8)\n#else // (DIRECTSOUND_VERSION >= 0x800)\n#define DSound\t\t\t\t\t\tVAR_U_(0x004D8D74, LPDIRECTSOUND)\n#endif // (DIRECTSOUND_VERSION >= 0x800)\n#define CurrentSoundAdapter\t\t\tVAR_U_(0x004D8E78, SOUND_ADAPTER)\n#define PrimarySoundAdapter\t\t\tVAR_U_(0x004D8E9C, SOUND_ADAPTER_NODE*)\n#if (DIRECT3D_VERSION >= 0x900)\nextern SWR_BUFFER RenderBuffer;\nextern SWR_BUFFER PictureBuffer;\n#else // (DIRECT3D_VERSION >= 0x900)\n#define RenderBufferSurface\t\t\tVAR_U_(0x004D8EA0, LPDDS)\n#define DDrawClipper\t\t\t\tVAR_U_(0x004D8EA4, LPDIRECTDRAWCLIPPER)\n#define ThirdBufferSurface\t\t\tVAR_U_(0x004D92A8, LPDDS)\n#define PictureBufferSurface\t\tVAR_U_(0x004D92AC, LPDDS)\n#define ZBufferSurface\t\t\t\tVAR_U_(0x004D92B0, LPDDS)\n#define DDrawPalette\t\t\t\tVAR_U_(0x004D92B4, LPDIRECTDRAWPALETTE)\n#define PrimaryBufferSurface\t\tVAR_U_(0x004D92B8, LPDDS)\n#define ColorBitMasks\t\t\t\tVAR_U_(0x004D92D8, COLOR_BIT_MASKS)\n#define GameVidBufRect\t\t\t\tVAR_U_(0x004D9308, RECT)\n#endif // (DIRECT3D_VERSION >= 0x900)\n#define GameVidRect\t\t\t\t\tVAR_U_(0x004D9318, RECT)\n#define GameVidWidth\t\t\t\tVAR_U_(0x004D9328, int)\n#define GameVidHeight\t\t\t\tVAR_U_(0x004D932C, int)\n#define GameVidBPP\t\t\t\t\tVAR_U_(0x004D9330, int)\n#if (DIRECT3D_VERSION < 0x900)\n#define GameVidBufWidth\t\t\t\tVAR_U_(0x004D9334, int)\n#define GameVidBufHeight\t\t\tVAR_U_(0x004D9338, int)\n#endif // (DIRECT3D_VERSION < 0x900)\n#define UvAdd\t\t\t\t\t\tVAR_U_(0x004D933C, int)\n#if (DIRECT3D_VERSION < 0x900)\n#define GameVid_IsVga\t\t\t\tVAR_U_(0x004D9340, bool)\n#define GameVid_IsWindowedVga\t\tVAR_U_(0x004D9341, bool)\n#define GameVid_IsFullscreenVga\t\tVAR_U_(0x004D9342, bool)\n#define IsWindowedVGA\t\t\t\tVAR_U_(0x004D9343, bool)\n#define Is16bitTextures\t\t\t\tVAR_U_(0x004D9344, bool)\n#define NeedToReloadTextures\t\tVAR_U_(0x004D9345, bool)\n#define BackBufferSurface\t\t\tVAR_U_(0x004D9348, LPDDS)\n#endif // (DIRECT3D_VERSION < 0x900)\n#define HwrTexturePagesCount\t\tVAR_U_(0x004D9350, DWORD)\n#define ReadFileBytesCounter\t\tVAR_U_(0x004D9BE0, DWORD)\n#define LevelFilePalettesOffset\t\tVAR_U_(0x004D9BE4, LONG)\n#define LevelFileTexPagesOffset\t\tVAR_U_(0x004D9BE8, LONG)\n#define Meshes\t\t\t\t\t\tVAR_U_(0x004D9D80, __int16*)\n#define FloorData\t\t\t\t\tVAR_U_(0x004D9D84, __int16*)\n#define TextureInfoCount\t\t\tVAR_U_(0x004D9E88, DWORD)\n#define LevelFileDepthQOffset\t\tVAR_U_(0x004D9E8C, LONG)\n#define DriveLetter\t\t\t\t\tVAR_U_(0x004D9E98, char)\n#define IsFmvPlaying\t\t\t\tVAR_U_(0x004D9E9C, BOOL)\n#define MovieContext\t\t\t\tVAR_U_(0x004D9EA0, LPVOID)\n#define FmvContext\t\t\t\t\tVAR_U_(0x004D9EA4, LPVOID)\n#define FmvSoundContext\t\t\t\tVAR_U_(0x004D9EA8, LPVOID)\n#define SavedGamesCount\t\t\t\tVAR_U_(0x004D9EAC, DWORD)\n#define CurrentLevel\t\t\t\tVAR_U_(0x004D9EB0, int)\n#define IsLevelComplete\t\t\t\tVAR_U_(0x004D9EB4, BOOL)\n#define SaveCounter\t\t\t\t\tVAR_U_(0x004D9EB8, DWORD)\n#define CurrentTexSource\t\t\tVAR_U_(0x00519EC8, HWR_TEXHANDLE)\n#define HWR_VertexPtr\t\t\t\tVAR_U_(0x00519F50, D3DTLVERTEX*)\n#define ZEnableState\t\t\t\tVAR_U_(0x00519F54, bool)\n#define AlphaBlendEnabler\t\t\tVAR_U_(0x00519F58, D3DRENDERSTATETYPE)\n#define ColorKeyState\t\t\t\tVAR_U_(0x00519F5C, bool)\n#define ZWriteEnableState\t\t\tVAR_U_(0x00519F60, bool)\n#define GameMemorySize\t\t\t\tVAR_U_(0x00519FF0, DWORD)\n#define GameAllocMemPointer\t\t\tVAR_U_(0x00519FF4, BYTE*)\n#define GameAllocMemUsed\t\t\tVAR_U_(0x00519FF8, DWORD)\n#define GameAllocMemFree\t\t\tVAR_U_(0x00519FFC, DWORD)\n#define GameMemoryPointer\t\t\tVAR_U_(0x0051A0BC, BYTE*)\n#define InputStatus\t\t\t\t\tVAR_U_(0x0051A1F8, DWORD)\n#define IsVidModeLock\t\t\t\tVAR_U_(0x0051A1FC, bool)\n#define JoyKeys\t\t\t\t\t\tVAR_U_(0x0051A200, DWORD)\n#define GameModule\t\t\t\t\tVAR_U_(0x0051A228, HINSTANCE)\n#define CommandLinePtr\t\t\t\tVAR_U_(0x0051A22C, LPTSTR)\n#define KeyCursor\t\t\t\t\tVAR_U_(0x0051A238, int)\n#define PassportTextInfo\t\t\tVAR_U_(0x0051A2BC, TEXT_STR_INFO*)\n#define PhdWinRect\t\t\t\t\tVAR_U_(0x0051B908, RECT)\n#define HiRes\t\t\t\t\t\tVAR_U_(0x0051B918, int)\n#define AnimatedTextureRanges\t\tVAR_U_(0x0051B91C, __int16*)\n#define WinVidNeedToResetBuffers\tVAR_U_(0x0051BC20, bool)\n#define IsWet\t\t\t\t\t\tVAR_U_(0x0051BC28, BOOL)\n#if defined(FEATURE_NOLEGACY_OPTIONS) || defined(FEATURE_VIDEOFX_IMPROVED)\nextern APP_SETTINGS ChangedAppSettings;\n#else // defined(FEATURE_NOLEGACY_OPTIONS) || defined(FEATURE_VIDEOFX_IMPROVED)\n#define ChangedAppSettings\t\t\tVAR_U_(0x0051BC40, APP_SETTINGS)\n#endif // defined(FEATURE_NOLEGACY_OPTIONS) || defined(FEATURE_VIDEOFX_IMPROVED)\n#define SE_PropSheetWndHandle\t\tVAR_U_(0x0051BC7C, HWND)\n#define SE_OldPropSheetWndProc\t\tVAR_U_(0x0051BC80, WNDPROC)\n#define SE_DisplayAdapter\t\t\tVAR_U_(0x0051BC8C, DISPLAY_ADAPTER_NODE*)\n#define SoundDialogHandle\t\t\tVAR_U_(0x0051BC90, HWND)\n#define GraphicsDialogHandle\t\tVAR_U_(0x0051BC9C, HWND)\n#define SE_FullScreenMode\t\t\tVAR_U_(0x0051BCA0, DISPLAY_MODE)\n#if defined(FEATURE_NOLEGACY_OPTIONS) || defined(FEATURE_VIDEOFX_IMPROVED)\nextern APP_SETTINGS SavedAppSettings;\n#else // defined(FEATURE_NOLEGACY_OPTIONS) || defined(FEATURE_VIDEOFX_IMPROVED)\n#define SavedAppSettings\t\t\tVAR_U_(0x0051BCB0, APP_SETTINGS)\n#endif // defined(FEATURE_NOLEGACY_OPTIONS) || defined(FEATURE_VIDEOFX_IMPROVED)\n#define IsSetupDialogCentered\t\tVAR_U_(0x0051BCF0, bool)\n#define IsTitleLoaded\t\t\t\tVAR_U_(0x0051BD90, BOOL)\n#define S_MasterVolume\t\t\t\tVAR_U_(0x0051BD98, DWORD)\n#define MciDeviceID\t\t\t\t\tVAR_U_(0x0051BD9C, MCIDEVICEID)\n#define CD_LoopTrack\t\t\t\tVAR_U_(0x0051BDA0, int)\n#define CD_LoopCounter\t\t\t\tVAR_U_(0x0051BDA4, int)\n#define TextureFormat\t\t\t\tVAR_U_(0x0051C1A8, TEXTURE_FORMAT)\n#define TexturesAlphaChannel\t\tVAR_U_(0x0051C1FC, bool)\n#define TexturesHaveCompatibleMasks\tVAR_U_(0x0051C1FD, bool)\n#define HKey\t\t\t\t\t\tVAR_U_(0x0051C290, HKEY)\n#define RegKeyDisposition\t\t\tVAR_U_(0x0051C294, DWORD)\n#define TextStringCount\t\t\t\tVAR_U_(0x0051D6A0, __int16)\n#define SampleInfoCount\t\t\t\tVAR_U_(0x0051E6C0, DWORD)\n#define SoundIsActive\t\t\t\tVAR_U_(0x0051E6C4, BOOL)\n#define SampleInfos\t\t\t\t\tVAR_U_(0x0051E9C4, SAMPLE_INFO*)\n#define SG_Point\t\t\t\t\tVAR_U_(0x0051E9C8, BYTE*)\n#define SaveGame\t\t\t\t\tVAR_U_(0x0051E9E0, SAVEGAME_INFO)\n#define SG_Count\t\t\t\t\tVAR_U_(0x005206A4, DWORD)\n#define Lara\t\t\t\t\t\tVAR_U_(0x005206E0, LARA_INFO)\n#define LaraItem\t\t\t\t\tVAR_U_(0x005207BC, ITEM_INFO*)\n#define Effects\t\t\t\t\t\tVAR_U_(0x005207C0, FX_INFO *)\n#define NextItemFree\t\t\t\tVAR_U_(0x005207C6, __int16)\n#define NextItemActive\t\t\t\tVAR_U_(0x005207C8, __int16)\n#define NextEffectActive\t\t\tVAR_U_(0x005207CA, __int16)\n#define PrevItemActive\t\t\t\tVAR_U_(0x005207CC, __int16)\n#define SoundFxCount\t\t\t\tVAR_U_(0x00521FDC, DWORD)\n#define SoundFx\t\t\t\t\t\tVAR_U_(0x00521FE0, OBJECT_VECTOR*)\n#define AnimFrames\t\t\t\t\tVAR_U_(0x005251B0, __int16*)\n#define MeshPtr\t\t\t\t\t\tVAR_U_(0x005252B0, __int16**)\n#define OutsideCamera\t\t\t\tVAR_U_(0x005252B4, int)\n#define DrawRoomsCount\t\t\t\tVAR_U_(0x005252B8, int)\n#define Anims\t\t\t\t\t\tVAR_U_(0x005258F4, ANIM_STRUCT*)\n#define OutsideBottom\t\t\t\tVAR_U_(0x00525B00, int)\n#define AnimRanges\t\t\t\t\tVAR_U_(0x00525B04, RANGE_STRUCT*)\n#define AnimCommands\t\t\t\tVAR_U_(0x00525B08, __int16*)\n#define AnimBones\t\t\t\t\tVAR_U_(0x00525BE8, int*)\n#define DynamicLightCount\t\t\tVAR_U_(0x00525BEC, DWORD)\n#define OutsideLeft\t\t\t\t\tVAR_U_(0x00526178, int)\n#define AnimChanges\t\t\t\t\tVAR_U_(0x0052617C, CHANGE_STRUCT*)\n#define RoomCount\t\t\t\t\tVAR_U_(0x00526180, __int16)\n#define RoomInfo\t\t\t\t\tVAR_U_(0x0052618C, ROOM_INFO*)\n#define UnderwaterCamera\t\t\tVAR_U_(0x00526190, int)\n#define SunsetTimer\t\t\t\t\tVAR_U_(0x00526194, DWORD)\n#define OutsideRight\t\t\t\tVAR_U_(0x00526198, int)\n#define OutsideTop\t\t\t\t\tVAR_U_(0x005261AC, int)\n#define DemoPtr\t\t\t\t\t\tVAR_U_(0x005261B0, LPVOID)\n#define DemoCount\t\t\t\t\tVAR_U_(0x005261B4, int)\n#define FlipStatus\t\t\t\t\tVAR_U_(0x00526240, int)\n#define TriggerPtr\t\t\t\t\tVAR_U_(0x00526288, __int16*)\n#define Items\t\t\t\t\t\tVAR_U_(0x005262F0, ITEM_INFO*)\n#define IsCinematicLoaded\t\t\tVAR_U_(0x005262F4, __int16)\n#define CineFramesCount\t\t\t\tVAR_U_(0x005262F6, __int16)\n#define CineFrames\t\t\t\t\tVAR_U_(0x005262F8, CINE_FRAME_INFO*)\n#define CineLevelID\t\t\t\t\tVAR_U_(0x00526312, __int16)\n#define CineFrameIdx\t\t\t\tVAR_U_(0x00526314, __int16)\n#define Camera\t\t\t\t\t\tVAR_U_(0x00526320, CAMERA_INFO)\n#define Overlaps\t\t\t\t\tVAR_U_(0x005263C8, UINT16*)\n#define Boxes\t\t\t\t\t\tVAR_U_(0x005263CC, BOX_INFO*)\n#define BoxesCount\t\t\t\t\tVAR_U_(0x005263D0, DWORD)\n\n// Initialized arrays\n#define TrackIDs\t\t\t\t\tARRAY_(0x004642F0, __int16, [16]) /* = {2, 0}; */\n#define InvSpriteMusicVolume\t\tARRAY_(0x00464718, INVENTORY_SPRITE, [9]) /* = {\n\t{2, -66, -80, 32, 132,  0, 0x004645DC, ICLR_Gray},\n\t{2, -66, -65, 32, 132,  0, 0x004645E0, ICLR_Gray},\n\t{2, -66, -80, 32,   0, 16, 0x004645DC, ICLR_Gray},\n\t{2,  66, -80, 32,   0, 16, 0x004645E0, ICLR_Gray},\n\t{3, -65, -79, 32, 131, 14, 0x004645E8, ICLR_Gray},\n\t{3, -64, -78, 32, 129, 12, 0x004645E8, ICLR_Gray},\n\t{4, -63, -77, 32, 126, 10, 0x004645F8, ICLR_Red},\n\t{4, -63, -77, 33, 127, 10, NULL, 0},\n\t{0,   0,   0,  0,   0,  0, NULL, 0},\n}; */\n#define InvSpriteSoundVolume\t\tARRAY_(0x004647E0, INVENTORY_SPRITE, [9]) /* = {\n\t{2, -66, -56, 32, 132,  0, 0x004645DC, ICLR_Gray},\n\t{2, -66, -41, 32, 132,  0, 0x004645E0, ICLR_Gray},\n\t{2, -66, -56, 32,   0, 16, 0x004645DC, ICLR_Gray},\n\t{2,  66, -56, 32,   0, 16, 0x004645E0, ICLR_Gray},\n\t{3, -65, -55, 32, 131, 14, 0x004645E8, ICLR_Gray},\n\t{3, -64, -54, 32, 129, 12, 0x004645E8, ICLR_Gray},\n\t{4, -63, -53, 32, 126, 10, 0x00464600, ICLR_Blue},\n\t{4, -63, -53, 33, 127, 10, NULL, 0},\n\t{0,   0,   0,  0,   0,  0, NULL, 0},\n}; */\n#define InvSpriteMusicVolumeLow\t\tARRAY_(0x004648A8, INVENTORY_SPRITE, [9]) /* = {\n\t{2, -66, -80, 32, 132,  0, 0x00464610, ICLR_Gray},\n\t{2, -66, -65, 32, 132,  0, 0x00464614, ICLR_Gray},\n\t{2, -66, -80, 32,   0, 16, 0x00464610, ICLR_Gray},\n\t{2,  66, -80, 32,   0, 16, 0x00464614, ICLR_Gray},\n\t{3, -65, -79, 32, 131, 14, 0x00464618, ICLR_Gray},\n\t{3, -64, -78, 32, 129, 12, 0x00464618, ICLR_Gray},\n\t{4, -63, -77, 32, 126, 10, 0x00464620, ICLR_Red},\n\t{4, -63, -77, 33, 127, 10, NULL, 0},\n\t{0,   0,   0,  0,   0,  0, NULL, 0},\n}; */\n#define InvSpriteSoundVolumeLow\t\tARRAY_(0x00464970, INVENTORY_SPRITE, [9]) /* = {\n\t{2, -66, -56, 32, 132,  0, 0x00464610, ICLR_Gray},\n\t{2, -66, -41, 32, 132,  0, 0x00464614, ICLR_Gray},\n\t{2, -66, -56, 32,   0, 16, 0x00464610, ICLR_Gray},\n\t{2,  66, -56, 32,   0, 16, 0x00464614, ICLR_Gray},\n\t{3, -65, -55, 32, 131, 14, 0x00464618, ICLR_Gray},\n\t{3, -64, -54, 32, 129, 12, 0x00464618, ICLR_Gray},\n\t{4, -63, -53, 32, 126, 10, 0x00464628, ICLR_Blue},\n\t{4, -63, -53, 33, 127, 10, NULL, 0},\n\t{0,   0,   0,  0,   0,  0, NULL, 0},\n}; */\n#define Weapons\t\tARRAY_(0x00465AE0, WEAPON_INFO, [10]) /* = {\n\t{ // LGT_Unarmed\n\t\t{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0,\n\t},\n\t{ // LGT_Pistols\n\t\t{ -60*PHD_DEGREE,  60*PHD_DEGREE, -60*PHD_DEGREE, 60*PHD_DEGREE},\n\t\t{-170*PHD_DEGREE,  60*PHD_DEGREE, -80*PHD_DEGREE, 80*PHD_DEGREE},\n\t\t{ -60*PHD_DEGREE, 170*PHD_DEGREE, -80*PHD_DEGREE, 80*PHD_DEGREE},\n\t\t10*PHD_DEGREE, 8*PHD_DEGREE, 650, 1, 0x2000, 9, 3, 8,\n\t},\n\t{ // LGT_Magnums\n\t\t{ -60*PHD_DEGREE,  60*PHD_DEGREE, -60*PHD_DEGREE, 60*PHD_DEGREE},\n\t\t{-170*PHD_DEGREE,  60*PHD_DEGREE, -80*PHD_DEGREE, 80*PHD_DEGREE},\n\t\t{ -60*PHD_DEGREE, 170*PHD_DEGREE, -80*PHD_DEGREE, 80*PHD_DEGREE},\n\t\t10*PHD_DEGREE, 8*PHD_DEGREE, 650, 2, 0x2000, 9, 3, 21,\n\t},\n\t{ // LGT_Uzis\n\t\t{ -60*PHD_DEGREE,  60*PHD_DEGREE, -60*PHD_DEGREE, 60*PHD_DEGREE},\n\t\t{-170*PHD_DEGREE,  60*PHD_DEGREE, -80*PHD_DEGREE, 80*PHD_DEGREE},\n\t\t{ -60*PHD_DEGREE, 170*PHD_DEGREE, -80*PHD_DEGREE, 80*PHD_DEGREE},\n\t\t10*PHD_DEGREE, 8*PHD_DEGREE, 650, 1, 0x2000, 3, 3, 43,\n\t},\n\t{ // LGT_Shotgun\n\t\t{-60*PHD_DEGREE, 60*PHD_DEGREE, -55*PHD_DEGREE, 55*PHD_DEGREE},\n\t\t{-80*PHD_DEGREE, 80*PHD_DEGREE, -65*PHD_DEGREE, 65*PHD_DEGREE},\n\t\t{-80*PHD_DEGREE, 80*PHD_DEGREE, -65*PHD_DEGREE, 65*PHD_DEGREE},\n\t\t10*PHD_DEGREE, 0, 500, 3, 0x2000, 9, 3, 45,\n\t},\n\t{ // LGT_M16\n\t\t{-60*PHD_DEGREE, 60*PHD_DEGREE, -55*PHD_DEGREE, 55*PHD_DEGREE},\n\t\t{-80*PHD_DEGREE, 80*PHD_DEGREE, -65*PHD_DEGREE, 65*PHD_DEGREE},\n\t\t{-80*PHD_DEGREE, 80*PHD_DEGREE, -65*PHD_DEGREE, 65*PHD_DEGREE},\n\t\t10*PHD_DEGREE, 4*PHD_DEGREE, 500, 3, 0x3000, 0, 3, 0,\n\t},\n\t{ // LGT_Grenade\n\t\t{-60*PHD_DEGREE, 60*PHD_DEGREE, -55*PHD_DEGREE, 55*PHD_DEGREE},\n\t\t{-80*PHD_DEGREE, 80*PHD_DEGREE, -65*PHD_DEGREE, 65*PHD_DEGREE},\n\t\t{-80*PHD_DEGREE, 80*PHD_DEGREE, -65*PHD_DEGREE, 65*PHD_DEGREE},\n\t\t10*PHD_DEGREE, 8*PHD_DEGREE, 500, 30, 0x2000, 0, 2, 0,\n\t},\n\t{ // LGT_Harpoon\n\t\t{-60*PHD_DEGREE, 60*PHD_DEGREE, -65*PHD_DEGREE, 65*PHD_DEGREE},\n\t\t{-80*PHD_DEGREE, 80*PHD_DEGREE, -75*PHD_DEGREE, 75*PHD_DEGREE},\n\t\t{-80*PHD_DEGREE, 80*PHD_DEGREE, -75*PHD_DEGREE, 75*PHD_DEGREE},\n\t\t10*PHD_DEGREE, 8*PHD_DEGREE, 500, 4, 0x2000, 0, 2, 0,\n\t},\n\t{ // LGT_Flare\n\t\t{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0,\n\t},\n\t{ // LGT_Skidoo\n\t\t{-30*PHD_DEGREE, 30*PHD_DEGREE, -55*PHD_DEGREE, 55*PHD_DEGREE},\n\t\t{-30*PHD_DEGREE, 30*PHD_DEGREE, -55*PHD_DEGREE, 55*PHD_DEGREE},\n\t\t{-30*PHD_DEGREE, 30*PHD_DEGREE, -55*PHD_DEGREE, 55*PHD_DEGREE},\n\t\t10*PHD_DEGREE, 8*PHD_DEGREE, 400, 3, 0x2000, 0, 2, 43,\n\t},\n}; */\n#define SaveSlotFlags\t\t\t\tARRAY_(0x00466B80, __int16, [16]) /* = {-1, 0}; */\n#ifdef FEATURE_HUD_IMPROVED\nextern CONTROL_LAYOUT Layout[3];\n#else // FEATURE_HUD_IMPROVED\n#define Layout\t\t\t\t\t\tARRAY_(0x00466F58, CONTROL_LAYOUT, [2]) /* = {\n\t{\t// Default Layout\n\t\tDIK_UP,\n\t\tDIK_DOWN,\n\t\tDIK_LEFT,\n\t\tDIK_RIGHT,\n\t\tDIK_DELETE,\n\t\tDIK_NEXT,\n\t\tDIK_RSHIFT,\n\t\tDIK_RMENU,\n\t\tDIK_RCONTROL,\n\t\tDIK_SPACE,\n\t\tDIK_SLASH,\n\t\tDIK_NUMPAD0,\n\t\tDIK_END,\n\t\tDIK_ESCAPE,\n\t},\n\t{\t// User Layout\n\t\tDIK_NUMPAD8,\n\t\tDIK_NUMPAD2,\n\t\tDIK_NUMPAD4,\n\t\tDIK_NUMPAD6,\n\t\tDIK_NUMPAD7,\n\t\tDIK_NUMPAD9,\n\t\tDIK_NUMPAD1,\n\t\tDIK_ADD,\n\t\tDIK_NUMPADENTER,\n\t\tDIK_NUMPAD3,\n\t\tDIK_SUBTRACT,\n\t\tDIK_NUMPAD0,\n\t\tDIK_NUMPAD5,\n\t\tDIK_DECIMAL,\n\t},\n}; */\n#endif // FEATURE_HUD_IMPROVED\n\n// Uninitialized arrays\n#define GouraudTable\t\t\t\tARRAY_(0x0046C300, GOURAUD_ENTRY, [256])\n#ifdef FEATURE_EXTENDED_LIMITS\nextern PHD_SPRITE PhdSpriteInfo[2048];\n#else // FEATURE_EXTENDED_LIMITS\n#define PhdSpriteInfo\t\t\t\tARRAY_(0x0046E308, PHD_SPRITE, [512])\n#endif // FEATURE_EXTENDED_LIMITS\n#if defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_VIEW_IMPROVED)\nextern SORT_ITEM SortBuffer[16000];\nextern __int16 Info3dBuffer[480000];\n#else // defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_VIEW_IMPROVED)\n#define SortBuffer\t\t\t\t\tARRAY_(0x00470338, SORT_ITEM, [4000])\n#define Info3dBuffer\t\t\t\tARRAY_(0x00478060, __int16, [120000])\n#endif // defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_VIEW_IMPROVED)\n#define RandomTable\t\t\t\t\tARRAY_(0x004B2A28, int, [32])\n#ifdef FEATURE_EXTENDED_LIMITS\nextern PHD_TEXTURE PhdTextureInfo[0x2000];\n#else // FEATURE_EXTENDED_LIMITS\n#define PhdTextureInfo\t\t\t\tARRAY_(0x004B2AF0, PHD_TEXTURE, [0x800])\n#endif // FEATURE_EXTENDED_LIMITS\n#define ShadesTable\t\t\t\t\tARRAY_(0x004BCB00, __int16, [32])\n#define MatrixStack\t\t\t\t\tARRAY_(0x004BCB48, PHD_MATRIX, [40])\n#define DepthQTable\t\t\t\t\tARRAY_(0x004BD2C8, DEPTHQ_ENTRY, [32])\n#define DepthQIndex\t\t\t\t\tARRAY_(0x004BF2C8, BYTE, [256])\n#define PhdVBuf\t\t\t\t\t\tARRAY_(0x004BF3D0, PHD_VBUF, [1500])\n#ifdef FEATURE_EXTENDED_LIMITS\nextern BYTE *TexturePageBuffer8[128];\n#else // FEATURE_EXTENDED_LIMITS\n#define TexturePageBuffer8\t\t\tARRAY_(0x004D6AD0, BYTE*, [32])\n#endif // FEATURE_EXTENDED_LIMITS\n#define WibbleTable\t\t\t\t\tARRAY_(0x004D6B68, float, [32])\n#define GamePalette16\t\t\t\tARRAY_(0x004D7370, PALETTEENTRY, [256])\n#define InvItemText\t\t\t\t\tARRAY_(0x004D7938, TEXT_STR_INFO*, [2])\n#define InventoryExtraData\t\t\tARRAY_(0x004D7970, int, [8])\n#define SfxInfos\t\t\t\t\tARRAY_(0x004D7C68, SFX_INFO, [32])\n#ifdef FEATURE_BACKGROUND_IMPROVED\nextern int BGND_TexturePageIndexes[64];\nextern HWR_TEXHANDLE BGND_PageHandles[64];\n#else // FEATURE_BACKGROUND_IMPROVED\n#define BGND_TexturePageIndexes\t\tARRAY_(0x004D7E80, int, [5])\n#define BGND_PageHandles\t\t\tARRAY_(0x004D7E98, HWR_TEXHANDLE, [5])\n#endif // FEATURE_BACKGROUND_IMPROVED\n#ifdef FEATURE_EXTENDED_LIMITS\nextern DWORD SampleFreqs[370];\nextern LPDIRECTSOUNDBUFFER SampleBuffers[370];\n#else // FEATURE_EXTENDED_LIMITS\n#define SampleFreqs\t\t\t\t\tARRAY_(0x004D8560, DWORD, [256])\n#define SampleBuffers\t\t\t\tARRAY_(0x004D8970, LPDIRECTSOUNDBUFFER, [256])\n#endif // FEATURE_EXTENDED_LIMITS\n#define ChannelSamples\t\t\t\tARRAY_(0x004D8D78, DWORD, [32])\n#define ChannelBuffers\t\t\t\tARRAY_(0x004D8DF8, LPDIRECTSOUNDBUFFER, [32])\n#define WinVidPalette\t\t\t\tARRAY_(0x004D8EA8, PALETTEENTRY, [256])\n#ifdef FEATURE_EXTENDED_LIMITS\nextern BYTE LabTextureUVFlags[0x2000];\n#else // FEATURE_EXTENDED_LIMITS\n#define LabTextureUVFlags\t\t\tARRAY_(0x004D93E0, BYTE, [0x800])\n#endif // FEATURE_EXTENDED_LIMITS\n#define LevelFileName\t\t\t\tARRAY_(0x004D9D88, char, [256])\n#ifdef FEATURE_EXTENDED_LIMITS\nextern D3DTLVERTEX HWR_VertexBuffer[0x8000];\nextern HWR_TEXHANDLE HWR_PageHandles[128];\nextern int HWR_TexturePageIndexes[128];\n#else // FEATURE_EXTENDED_LIMITS\n#define HWR_VertexBuffer\t\t\tARRAY_(0x004D9EC8, D3DTLVERTEX, [0x2000])\n#define HWR_PageHandles\t\t\t\tARRAY_(0x00519ED0, HWR_TEXHANDLE, [32])\n#define HWR_TexturePageIndexes\t\tARRAY_(0x00519F68, int, [32])\n#endif // FEATURE_EXTENDED_LIMITS\n#ifdef FEATURE_HUD_IMPROVED\nextern bool ConflictLayout[ARRAY_SIZE(Layout->key)];\n#else // FEATURE_HUD_IMPROVED\n#define ConflictLayout\t\t\t\tARRAY_(0x0051A0C0, BOOL, [14])\n#endif // FEATURE_HUD_IMPROVED\n#define DIKeys\t\t\t\t\t\tARRAY_(0x0051A0F8, BYTE, [256])\n#define ControlTextInfo\t\t\t\tARRAY_(0x0051A2F0, TEXT_STR_INFO*, [2])\n#define RoomLightTables\t\t\t\tARRAY_(0x0051A2F8, ROOM_LIGHT_TABLE, [32])\n#define WaterPalette\t\t\t\tARRAY_(0x0051B2F8, RGB888, [256])\n#define PicPalette\t\t\t\t\tARRAY_(0x0051B5F8, RGB888, [256])\n#define RoomLightShades\t\t\t\tARRAY_(0x0051B8F8, int, [4])\n#define GamePalette8\t\t\t\tARRAY_(0x0051B920, RGB888, [256])\n#define StringToShow\t\t\t\tARRAY_(0x0051BD10, char, [128])\n#define TextInfoTable\t\t\t\tARRAY_(0x0051C820, TEXT_STR_INFO, [64])\n#define TheStrings\t\t\t\t\tARRAY_(0x0051D6C0, STRING_FIXED64, [64])\n#define SampleLut\t\t\t\t\tARRAY_(0x0051E6E0, __int16, [370])\n#define SaveGameStrings1\t\t\tARRAY_(0x005207E0, STRING_FIXED50, [24])\n#define RequesterItemFlags2\t\t\tARRAY_(0x00520CA0, DWORD, [24])\n#define RequesterItemFlags1\t\t\tARRAY_(0x00520D00, DWORD, [24])\n#define InvColours\t\t\t\t\tARRAY_(0x005216E0, UINT16, [17])\n#define SaveGameStrings2\t\t\tARRAY_(0x00521720, STRING_FIXED50, [24])\n#define SaveGameItemFlags2\t\t\tARRAY_(0x00521BE0, DWORD, [24])\n#define SaveGameItemFlags1\t\t\tARRAY_(0x00521C40, DWORD, [24])\n#define PickupInfos\t\t\t\t\tARRAY_(0x00521CA0, PICKUP_INFO, [12])\n#define Objects\t\t\t\t\t\tARRAY_(0x00522000, OBJECT_INFO, [265])\n#ifdef FEATURE_EXTENDED_LIMITS\nextern LIGHT_INFO DynamicLights[64];\nextern int BoundRooms[1024];\nextern __int16 DrawRoomsArray[1024];\nextern STATIC_INFO StaticObjects[256];\n#else // FEATURE_EXTENDED_LIMITS\n#define DynamicLights\t\t\t\tARRAY_(0x005251C0, LIGHT_INFO, [10])\n#define BoundRooms\t\t\t\t\tARRAY_(0x00525900, int, [128])\n#define DrawRoomsArray\t\t\t\tARRAY_(0x00525B20, __int16, [100])\n#define StaticObjects\t\t\t\tARRAY_(0x00525C00, STATIC_INFO, [50])\n#endif // FEATURE_EXTENDED_LIMITS\n#define CD_Flags\t\t\t\t\tARRAY_(0x005261C0, __int16, [64])\n#define FlipMaps\t\t\t\t\tARRAY_(0x00526260, int, [10])\n#define GroundZones\t\t\t\t\tARRAY_(0x005263A0, __int16*, [8])\n#define FlyZones\t\t\t\t\tARRAY_(0x005263C0, __int16*, [2])\n\n/*\n * GameFlow/Inventory Variables\n */\n// GameFlow/Inventory initialized variables\n#define LoadGameRequester\t\t\tVAR_I_(0x00465620, REQUEST_INFO,\t\"...\")\n#define SaveGameRequester\t\t\tVAR_I_(0x00465838, REQUEST_INFO,\t\"...\")\n#define InvCompassOption\t\t\tVAR_I_(0x00464A90, INVENTORY_ITEM,\t\"...\")\n#define InvPistolOption\t\t\t\tVAR_I_(0x00464AE0, INVENTORY_ITEM,\t\"...\")\n#define InvFlareOption\t\t\t\tVAR_I_(0x00464B30, INVENTORY_ITEM,\t\"...\")\n#define InvShotgunOption\t\t\tVAR_I_(0x00464B80, INVENTORY_ITEM,\t\"...\")\n#define InvMagnumOption\t\t\t\tVAR_I_(0x00464BD0, INVENTORY_ITEM,\t\"...\")\n#define InvUziOption\t\t\t\tVAR_I_(0x00464C20, INVENTORY_ITEM,\t\"...\")\n#define InvHarpoonOption\t\t\tVAR_I_(0x00464C70, INVENTORY_ITEM,\t\"...\")\n#define InvM16Option\t\t\t\tVAR_I_(0x00464CC0, INVENTORY_ITEM,\t\"...\")\n#define InvGrenadeOption\t\t\tVAR_I_(0x00464D10, INVENTORY_ITEM,\t\"...\")\n#define InvPistolAmmoOption\t\t\tVAR_I_(0x00464D60, INVENTORY_ITEM,\t\"...\")\n#define InvShotgunAmmoOption\t\tVAR_I_(0x00464DB0, INVENTORY_ITEM,\t\"...\")\n#define InvMagnumAmmoOption\t\t\tVAR_I_(0x00464E00, INVENTORY_ITEM,\t\"...\")\n#define InvUziAmmoOption\t\t\tVAR_I_(0x00464E50, INVENTORY_ITEM,\t\"...\")\n#define InvHarpoonAmmoOption\t\tVAR_I_(0x00464EA0, INVENTORY_ITEM,\t\"...\")\n#define InvM16AmmoOption\t\t\tVAR_I_(0x00464EF0, INVENTORY_ITEM,\t\"...\")\n#define InvGrenadeAmmoOption\t\tVAR_I_(0x00464F40, INVENTORY_ITEM,\t\"...\")\n#define InvSmallMedipackOption\t\tVAR_I_(0x00464F90, INVENTORY_ITEM,\t\"...\")\n#define InvLargeMedipackOption\t\tVAR_I_(0x00464FE0, INVENTORY_ITEM,\t\"...\")\n#define InvPickup1Option\t\t\tVAR_I_(0x00465030, INVENTORY_ITEM,\t\"...\")\n#define InvPickup2Option\t\t\tVAR_I_(0x00465080, INVENTORY_ITEM,\t\"...\")\n#define InvPuzzle1Option\t\t\tVAR_I_(0x004650D0, INVENTORY_ITEM,\t\"...\")\n#define InvPuzzle2Option\t\t\tVAR_I_(0x00465120, INVENTORY_ITEM,\t\"...\")\n#define InvPuzzle3Option\t\t\tVAR_I_(0x00465170, INVENTORY_ITEM,\t\"...\")\n#define InvPuzzle4Option\t\t\tVAR_I_(0x004651C0, INVENTORY_ITEM,\t\"...\")\n#define InvKey1Option\t\t\t\tVAR_I_(0x00465210, INVENTORY_ITEM,\t\"...\")\n#define InvKey2Option\t\t\t\tVAR_I_(0x00465260, INVENTORY_ITEM,\t\"...\")\n#define InvKey3Option\t\t\t\tVAR_I_(0x004652B0, INVENTORY_ITEM,\t\"...\")\n#define InvKey4Option\t\t\t\tVAR_I_(0x00465300, INVENTORY_ITEM,\t\"...\")\n#define InvPassportOption\t\t\tVAR_I_(0x00465350, INVENTORY_ITEM,\t\"...\")\n#define InvDetailOption\t\t\t\tVAR_I_(0x004653A0, INVENTORY_ITEM,\t\"...\")\n#define InvSoundOption\t\t\t\tVAR_I_(0x004653F0, INVENTORY_ITEM,\t\"...\")\n#define InvControlOption\t\t\tVAR_I_(0x00465440, INVENTORY_ITEM,\t\"...\")\n#define InvPhotoOption\t\t\t\tVAR_I_(0x00465490, INVENTORY_ITEM,\t\"...\")\n\n// GameFlow/Inventory uninitialized variables\n#define GF_LaraStartAnim\t\t\tVAR_U_(0x004D77E0, int)\n#define GF_SunsetEnabled\t\t\tVAR_U_(0x004D77E4, UINT16)\n#define GF_DeadlyWater\t\t\t\tVAR_U_(0x004D77E8, UINT16)\n#define GF_NoFloor\t\t\t\t\tVAR_U_(0x004D77EC, UINT16)\n#define GF_RemoveWeapons\t\t\tVAR_U_(0x004D77F0, UINT16)\n#define GF_RemoveAmmo\t\t\t\tVAR_U_(0x004D77F4, UINT16)\n#define GF_Kill2Complete\t\t\tVAR_U_(0x004D77F8, bool)\n#define GF_StartGame\t\t\t\tVAR_U_(0x004D77FC, bool)\n#define GF_GameFlow\t\t\t\t\tVAR_U_(0x00521DE0, GAME_FLOW)\n#define GF_ScriptBuffer\t\t\t\tVAR_U_(0x00521E70, __int16*)\n#define GF_LevelNamesStringTable\tVAR_U_(0x00521EC4, char**)\n#define GF_PictureFilesStringTable\tVAR_U_(0x00521EA0, char**)\n#define GF_TitleFilesStringTable\tVAR_U_(0x00521F48, char**)\n#define GF_FmvFilesStringTable\t\tVAR_U_(0x00521F94, char**)\n#define GF_LevelFilesStringTable\tVAR_U_(0x00521F54, char**)\n#define GF_CutsFilesStringTable\t\tVAR_U_(0x00521DC4, char**)\n#define GF_GameStringTable\t\t\tVAR_U_(0x00521EB0, char**)\n#define GF_SpecificStringTable\t\tVAR_U_(0x00521F50, char**)\n#define GF_Puzzle1StringTable\t\tVAR_U_(0x00521DC0, char**)\n#define GF_Puzzle2StringTable\t\tVAR_U_(0x00521E98, char**)\n#define GF_Puzzle3StringTable\t\tVAR_U_(0x00521EC0, char**)\n#define GF_Puzzle4StringTable\t\tVAR_U_(0x00521E60, char**)\n#define GF_Pickup1StringTable\t\tVAR_U_(0x00521E94, char**)\n#define GF_Pickup2StringTable\t\tVAR_U_(0x00521F44, char**)\n#define GF_Key1StringTable\t\t\tVAR_U_(0x00521EA4, char**)\n#define GF_Key2StringTable\t\t\tVAR_U_(0x00521E74, char**)\n#define GF_Key3StringTable\t\t\tVAR_U_(0x00521EBC, char**)\n#define GF_Key4StringTable\t\t\tVAR_U_(0x00521E90, char**)\n#define GF_LevelNamesStringBuffer\tVAR_U_(0x00521EAC, char*)\n#define GF_PictureFilesStringBuffer\tVAR_U_(0x00521E8C, char*)\n#define GF_TitleFilesStringBuffer\tVAR_U_(0x00521F4C, char*)\n#define GF_FmvFilesStringBuffer\t\tVAR_U_(0x00521E68, char*)\n#define GF_LevelFilesStringBuffer\tVAR_U_(0x00521E9C, char*)\n#define GF_CutsFilesStringBuffer\tVAR_U_(0x00521E78, char*)\n#define GF_GameStringBuffer\t\t\tVAR_U_(0x00521EB8, char*)\n#define GF_SpecificStringBuffer\t\tVAR_U_(0x00521EB4, char*)\n#define GF_Puzzle1StringBuffer\t\tVAR_U_(0x00521EA8, char*)\n#define GF_Puzzle2StringBuffer\t\tVAR_U_(0x00521F40, char*)\n#define GF_Puzzle3StringBuffer\t\tVAR_U_(0x00521F98, char*)\n#define GF_Puzzle4StringBuffer\t\tVAR_U_(0x00521F90, char*)\n#define GF_Pickup1StringBuffer\t\tVAR_U_(0x00521E64, char*)\n#define GF_Pickup2StringBuffer\t\tVAR_U_(0x00521E88, char*)\n#define GF_Key1StringBuffer\t\t\tVAR_U_(0x00521E6C, char*)\n#define GF_Key2StringBuffer\t\t\tVAR_U_(0x00521E84, char*)\n#define GF_Key3StringBuffer\t\t\tVAR_U_(0x00521F9C, char*)\n#define GF_Key4StringBuffer\t\t\tVAR_U_(0x00521E7C, char*)\n\n// GameFlow/Inventory arrays\n#define InvMainQtys\t\t\t\t\tARRAY_(0x004654E8, UINT16, [23]) /* = {1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; */\n#define InvMainList\t\t\t\t\tARRAY_(0x00465518, INVENTORY_ITEM*, [23]) /* = {\n\t&InvCompassOption,\n\t&InvFlareOption,\n\t&InvPistolOption,\n\t&InvShotgunOption,\n\t&InvMagnumOption,\n\t&InvUziOption,\n\t&InvM16Option,\n\t&InvGrenadeOption,\n\t&InvHarpoonOption,\n\t&InvLargeMedipackOption,\n\t&InvSmallMedipackOption,\n\tNULL,\n}; */\n#define InvKeysQtys\t\t\t\t\tARRAY_(0x00465578, UINT16, [23]) /* = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; */\n#define InvKeysList\t\t\t\t\tARRAY_(0x004655A8, INVENTORY_ITEM*, [23]) /* = {\n\t&InvPuzzle1Option,\n\t&InvPuzzle2Option,\n\t&InvPuzzle3Option,\n\t&InvPuzzle4Option,\n\t&InvKey1Option,\n\t&InvKey2Option,\n\t&InvKey3Option,\n\t&InvKey4Option,\n\t&InvPickup1Option,\n\t&InvPickup2Option,\n\tNULL,\n}; */\n#ifdef FEATURE_HUD_IMPROVED\nextern INVENTORY_ITEM *InvOptionList[5];\nextern TEXT_STR_INFO *CtrlTextA[ARRAY_SIZE(Layout->key)];\nextern TEXT_STR_INFO *CtrlTextB[ARRAY_SIZE(Layout->key)];\n#else // FEATURE_HUD_IMPROVED\n#define InvOptionList\t\t\t\tARRAY_(0x00465608, INVENTORY_ITEM*, [4]) /* = {\n\t&InvPassportOption,\n\t&InvControlOption,\n\t&InvSoundOption,\n\t&InvPhotoOption\n}; */\n#define CtrlTextA\t\t\t\t\tARRAY_(0x0051A248, TEXT_STR_INFO*, [14])\n#define CtrlTextB\t\t\t\t\tARRAY_(0x0051A280, TEXT_STR_INFO*, [14])\n#endif // FEATURE_HUD_IMPROVED\n#define GF_ScriptTable\t\t\t\tARRAY_(0x00521EE0, __int16*, [24])\n#define GF_DemoLevels\t\t\t\tARRAY_(0x00521F60, UINT16, [24])\n#define GF_SecretInvItems\t\t\tARRAY_(0x00521FA0, char, [27])\n#define GF_Add2InvItems\t\t\t\tARRAY_(0x00521FC0, char, [27])\n\n#endif // GLOBAL_VARS_H_INCLUDED\n"
  },
  {
    "path": "json-parser/LICENSE",
    "content": "\n  Copyright (C) 2012, 2013 James McLaughlin et al.  All rights reserved.\n \n  Redistribution and use in source and binary forms, with or without\n  modification, are permitted provided that the following conditions\n  are met:\n \n  1. Redistributions of source code must retain the above copyright\n     notice, this list of conditions and the following disclaimer.\n \n  2. Redistributions in binary form must reproduce the above copyright\n     notice, this list of conditions and the following disclaimer in the\n     documentation and/or other materials provided with the distribution.\n \n  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n  SUCH DAMAGE.\n\n"
  },
  {
    "path": "json-parser/README.md",
    "content": "Very low footprint JSON parser written in portable ANSI C.\n\n* BSD licensed with no dependencies (i.e. just drop the C file into your project)\n* Never recurses or allocates more memory than it needs\n* Very simple API with operator sugar for C++\n\n[![Build Status](https://secure.travis-ci.org/udp/json-parser.png)](http://travis-ci.org/udp/json-parser)\n\n_Want to serialize?  Check out [json-builder](https://github.com/udp/json-builder)!_\n\nInstalling\n----------\n\nThere is now a makefile which will produce a libjsonparser static and dynamic library.  However, this\nis _not_ required to build json-parser, and the source files (`json.c` and `json.h`) should be happy\nin any build system you already have in place.\n\n\nAPI\n---\n\n    json_value * json_parse (const json_char * json,\n                             size_t length);\n\n    json_value * json_parse_ex (json_settings * settings,\n                                const json_char * json,\n                                size_t length,\n                                char * error);\n\n    void json_value_free (json_value *);\n\nThe `type` field of `json_value` is one of:\n\n* `json_object` (see `u.object.length`, `u.object.values[x].name`, `u.object.values[x].value`)\n* `json_array` (see `u.array.length`, `u.array.values`)\n* `json_integer` (see `u.integer`)\n* `json_double` (see `u.dbl`)\n* `json_string` (see `u.string.ptr`, `u.string.length`)\n* `json_boolean` (see `u.boolean`)\n* `json_null`\n\n\nCompile-Time Options\n--------------------\n\n    -DJSON_TRACK_SOURCE\n\nStores the source location (line and column number) inside each `json_value`.\n\nThis is useful for application-level error reporting.\n\n\nRuntime Options\n---------------\n\n    settings |= json_enable_comments;\n\nEnables C-style `// line` and `/* block */` comments.\n\n    size_t value_extra\n\nThe amount of space (if any) to allocate at the end of each `json_value`, in\norder to give the application space to add metadata.\n\n    void * (* mem_alloc) (size_t, int zero, void * user_data);\n    void (* mem_free) (void *, void * user_data);\n\nCustom allocator routines.  If NULL, the default `malloc` and `free` will be used.\n\nThe `user_data` pointer will be forwarded from `json_settings` to allow application\ncontext to be passed.\n\n\nChanges in version 1.1.0\n------------------------\n\n* UTF-8 byte order marks are now skipped if present\n\n* Allows cross-compilation by honoring --host if given (@wkz)\n\n* Maximum size for error buffer is now exposed in header (@LB--)\n\n* GCC warning for `static` after `const` fixed (@batrick)\n\n* Optional support for C-style line and block comments added (@Jin-W-FS)\n\n* `name_length` field added to object values \n\n* It is now possible to retrieve the source line/column number of a parsed `json_value` when `JSON_TRACK_SOURCE` is enabled\n\n* The application may now extend `json_value` using the `value_extra` setting\n\n* Un-ambiguate pow call in the case of C++ overloaded pow (@fcartegnie)\n\n* Fix null pointer de-reference when a non-existing array is closed and no root value is present\n\n\n"
  },
  {
    "path": "json-parser/json.c",
    "content": "/* vim: set et ts=3 sw=3 sts=3 ft=c:\n *\n * Copyright (C) 2012, 2013, 2014 James McLaughlin et al.  All rights reserved.\n * https://github.com/udp/json-parser\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n *\n * 1. Redistributions of source code must retain the above copyright\n *   notice, this list of conditions and the following disclaimer.\n *\n * 2. Redistributions in binary form must reproduce the above copyright\n *   notice, this list of conditions and the following disclaimer in the\n *   documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n */\n\n#include \"json.h\"\n\n#ifdef _MSC_VER\n   #ifndef _CRT_SECURE_NO_WARNINGS\n      #define _CRT_SECURE_NO_WARNINGS\n   #endif\n   #include <stdint.h>\n#endif\n\nconst struct _json_value json_value_none;\n\n#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <math.h>\n\ntypedef unsigned int json_uchar;\n\n/* There has to be a better way to do this */\nstatic const json_int_t JSON_INT_MAX = sizeof(json_int_t) == 1\n                                       ? INT8_MAX\n                                       : (sizeof(json_int_t) == 2\n                                         ? INT16_MAX\n                                         : (sizeof(json_int_t) == 4\n                                           ? INT32_MAX\n                                           : INT64_MAX));\n\nstatic unsigned char hex_value (json_char c)\n{\n   if (isdigit(c))\n      return c - '0';\n\n   switch (c) {\n      case 'a': case 'A': return 0x0A;\n      case 'b': case 'B': return 0x0B;\n      case 'c': case 'C': return 0x0C;\n      case 'd': case 'D': return 0x0D;\n      case 'e': case 'E': return 0x0E;\n      case 'f': case 'F': return 0x0F;\n      default: return 0xFF;\n   }\n}\n\nstatic int would_overflow (json_int_t value, json_char b)\n{\n   return ((JSON_INT_MAX - (b - '0')) / 10 ) < value;\n}\n\ntypedef struct\n{\n   unsigned long used_memory;\n\n   unsigned int uint_max;\n   unsigned long ulong_max;\n\n   json_settings settings;\n   int first_pass;\n\n   const json_char * ptr;\n   unsigned int cur_line, cur_col;\n\n} json_state;\n\nstatic void * default_alloc (size_t size, int zero, void * user_data)\n{\n   return zero ? calloc (1, size) : malloc (size);\n}\n\nstatic void default_free (void * ptr, void * user_data)\n{\n   free (ptr);\n}\n\nstatic void * json_alloc (json_state * state, unsigned long size, int zero)\n{\n   if ((state->ulong_max - state->used_memory) < size)\n      return 0;\n\n   if (state->settings.max_memory\n         && (state->used_memory += size) > state->settings.max_memory)\n   {\n      return 0;\n   }\n\n   return state->settings.mem_alloc (size, zero, state->settings.user_data);\n}\n\nstatic int new_value (json_state * state,\n                      json_value ** top, json_value ** root, json_value ** alloc,\n                      json_type type)\n{\n   json_value * value;\n   int values_size;\n\n   if (!state->first_pass)\n   {\n      value = *top = *alloc;\n      *alloc = (*alloc)->_reserved.next_alloc;\n\n      if (!*root)\n         *root = value;\n\n      switch (value->type)\n      {\n         case json_array:\n\n            if (value->u.array.length == 0)\n               break;\n\n            if (! (value->u.array.values = (json_value **) json_alloc\n               (state, value->u.array.length * sizeof (json_value *), 0)) )\n            {\n               return 0;\n            }\n\n            value->u.array.length = 0;\n            break;\n\n         case json_object:\n\n            if (value->u.object.length == 0)\n               break;\n\n            values_size = sizeof (*value->u.object.values) * value->u.object.length;\n\n            if (! (value->u.object.values = (json_object_entry *) json_alloc\n                  (state, values_size + ((unsigned long) value->u.object.values), 0)) )\n            {\n               return 0;\n            }\n\n            value->_reserved.object_mem = (*(void **) &value->u.object.values) + values_size;\n\n            value->u.object.length = 0;\n            break;\n\n         case json_string:\n\n            if (! (value->u.string.ptr = (json_char *) json_alloc\n               (state, (value->u.string.length + 1) * sizeof (json_char), 0)) )\n            {\n               return 0;\n            }\n\n            value->u.string.length = 0;\n            break;\n\n         default:\n            break;\n      };\n\n      return 1;\n   }\n\n   if (! (value = (json_value *) json_alloc\n         (state, sizeof (json_value) + state->settings.value_extra, 1)))\n   {\n      return 0;\n   }\n\n   if (!*root)\n      *root = value;\n\n   value->type = type;\n   value->parent = *top;\n\n   #ifdef JSON_TRACK_SOURCE\n      value->line = state->cur_line;\n      value->col = state->cur_col;\n   #endif\n\n   if (*alloc)\n      (*alloc)->_reserved.next_alloc = value;\n\n   *alloc = *top = value;\n\n   return 1;\n}\n\n#define whitespace \\\n   case '\\n': ++ state.cur_line;  state.cur_col = 0; \\\n   case ' ': case '\\t': case '\\r'\n\n#define string_add(b)  \\\n   do { if (!state.first_pass) string [string_length] = b;  ++ string_length; } while (0);\n\n#define line_and_col \\\n   state.cur_line, state.cur_col\n\nstatic const long\n   flag_next             = 1 << 0,\n   flag_reproc           = 1 << 1,\n   flag_need_comma       = 1 << 2,\n   flag_seek_value       = 1 << 3,\n   flag_escaped          = 1 << 4,\n   flag_string           = 1 << 5,\n   flag_need_colon       = 1 << 6,\n   flag_done             = 1 << 7,\n   flag_num_negative     = 1 << 8,\n   flag_num_zero         = 1 << 9,\n   flag_num_e            = 1 << 10,\n   flag_num_e_got_sign   = 1 << 11,\n   flag_num_e_negative   = 1 << 12,\n   flag_line_comment     = 1 << 13,\n   flag_block_comment    = 1 << 14,\n   flag_num_got_decimal  = 1 << 15;\n\njson_value * json_parse_ex (json_settings * settings,\n                            const json_char * json,\n                            size_t length,\n                            char * error_buf)\n{\n   json_char error [json_error_max];\n   const json_char * end;\n   json_value * top, * root, * alloc = 0;\n   json_state state = { 0 };\n   long flags = 0;\n   double num_digits = 0, num_e = 0;\n   double num_fraction = 0;\n\n   /* Skip UTF-8 BOM\n    */\n   if (length >= 3 && ((unsigned char) json [0]) == 0xEF\n                   && ((unsigned char) json [1]) == 0xBB\n                   && ((unsigned char) json [2]) == 0xBF)\n   {\n      json += 3;\n      length -= 3;\n   }\n\n   error[0] = '\\0';\n   end = (json + length);\n\n   memcpy (&state.settings, settings, sizeof (json_settings));\n\n   if (!state.settings.mem_alloc)\n      state.settings.mem_alloc = default_alloc;\n\n   if (!state.settings.mem_free)\n      state.settings.mem_free = default_free;\n\n   memset (&state.uint_max, 0xFF, sizeof (state.uint_max));\n   memset (&state.ulong_max, 0xFF, sizeof (state.ulong_max));\n\n   state.uint_max -= 8; /* limit of how much can be added before next check */\n   state.ulong_max -= 8;\n\n   for (state.first_pass = 1; state.first_pass >= 0; -- state.first_pass)\n   {\n      json_uchar uchar;\n      unsigned char uc_b1, uc_b2, uc_b3, uc_b4;\n      json_char * string = 0;\n      unsigned int string_length = 0;\n\n      top = root = 0;\n      flags = flag_seek_value;\n\n      state.cur_line = 1;\n\n      for (state.ptr = json ;; ++ state.ptr)\n      {\n         json_char b = (state.ptr == end ? 0 : *state.ptr);\n\n         if (flags & flag_string)\n         {\n            if (!b)\n            {  sprintf (error, \"Unexpected EOF in string (at %d:%d)\", line_and_col);\n               goto e_failed;\n            }\n\n            if (string_length > state.uint_max)\n               goto e_overflow;\n\n            if (flags & flag_escaped)\n            {\n               flags &= ~ flag_escaped;\n\n               switch (b)\n               {\n                  case 'b':  string_add ('\\b');  break;\n                  case 'f':  string_add ('\\f');  break;\n                  case 'n':  string_add ('\\n');  break;\n                  case 'r':  string_add ('\\r');  break;\n                  case 't':  string_add ('\\t');  break;\n                  case 'u':\n\n                    if (end - state.ptr <= 4 ||\n                        (uc_b1 = hex_value (*++ state.ptr)) == 0xFF ||\n                        (uc_b2 = hex_value (*++ state.ptr)) == 0xFF ||\n                        (uc_b3 = hex_value (*++ state.ptr)) == 0xFF ||\n                        (uc_b4 = hex_value (*++ state.ptr)) == 0xFF)\n                    {\n                        sprintf (error, \"Invalid character value `%c` (at %d:%d)\", b, line_and_col);\n                        goto e_failed;\n                    }\n\n                    uc_b1 = (uc_b1 << 4) | uc_b2;\n                    uc_b2 = (uc_b3 << 4) | uc_b4;\n                    uchar = (uc_b1 << 8) | uc_b2;\n\n                    if ((uchar & 0xF800) == 0xD800) {\n                        json_uchar uchar2;\n\n                        if (end - state.ptr <= 6 || (*++ state.ptr) != '\\\\' || (*++ state.ptr) != 'u' ||\n                            (uc_b1 = hex_value (*++ state.ptr)) == 0xFF ||\n                            (uc_b2 = hex_value (*++ state.ptr)) == 0xFF ||\n                            (uc_b3 = hex_value (*++ state.ptr)) == 0xFF ||\n                            (uc_b4 = hex_value (*++ state.ptr)) == 0xFF)\n                        {\n                            sprintf (error, \"Invalid character value `%c` (at %d:%d)\", b, line_and_col);\n                            goto e_failed;\n                        }\n\n                        uc_b1 = (uc_b1 << 4) | uc_b2;\n                        uc_b2 = (uc_b3 << 4) | uc_b4;\n                        uchar2 = (uc_b1 << 8) | uc_b2;\n\n                        uchar = 0x010000 | ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF);\n                    }\n\n                    if (sizeof (json_char) >= sizeof (json_uchar) || (uchar <= 0x7F))\n                    {\n                       string_add ((json_char) uchar);\n                       break;\n                    }\n\n                    if (uchar <= 0x7FF)\n                    {\n                        if (state.first_pass)\n                           string_length += 2;\n                        else\n                        {  string [string_length ++] = 0xC0 | (uchar >> 6);\n                           string [string_length ++] = 0x80 | (uchar & 0x3F);\n                        }\n\n                        break;\n                    }\n\n                    if (uchar <= 0xFFFF) {\n                        if (state.first_pass)\n                           string_length += 3;\n                        else\n                        {  string [string_length ++] = 0xE0 | (uchar >> 12);\n                           string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F);\n                           string [string_length ++] = 0x80 | (uchar & 0x3F);\n                        }\n\n                        break;\n                    }\n\n                    if (state.first_pass)\n                       string_length += 4;\n                    else\n                    {  string [string_length ++] = 0xF0 | (uchar >> 18);\n                       string [string_length ++] = 0x80 | ((uchar >> 12) & 0x3F);\n                       string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F);\n                       string [string_length ++] = 0x80 | (uchar & 0x3F);\n                    }\n\n                    break;\n\n                  default:\n                     string_add (b);\n               };\n\n               continue;\n            }\n\n            if (b == '\\\\')\n            {\n               flags |= flag_escaped;\n               continue;\n            }\n\n            if (b == '\"')\n            {\n               if (!state.first_pass)\n                  string [string_length] = 0;\n\n               flags &= ~ flag_string;\n               string = 0;\n\n               switch (top->type)\n               {\n                  case json_string:\n\n                     top->u.string.length = string_length;\n                     flags |= flag_next;\n\n                     break;\n\n                  case json_object:\n\n                     if (state.first_pass)\n                        *(void **) &top->u.object.values += string_length + 1;\n                     else\n                     {\n                        top->u.object.values [top->u.object.length].name\n                           = (json_char *) top->_reserved.object_mem;\n\n                        top->u.object.values [top->u.object.length].name_length\n                           = string_length;\n\n                        (*(json_char **) &top->_reserved.object_mem) += string_length + 1;\n                     }\n\n                     flags |= flag_seek_value | flag_need_colon;\n                     continue;\n\n                  default:\n                     break;\n               };\n            }\n            else\n            {\n               string_add (b);\n               continue;\n            }\n         }\n\n         if (state.settings.settings & json_enable_comments)\n         {\n            if (flags & (flag_line_comment | flag_block_comment))\n            {\n               if (flags & flag_line_comment)\n               {\n                  if (b == '\\r' || b == '\\n' || !b)\n                  {\n                     flags &= ~ flag_line_comment;\n                     -- state.ptr;  /* so null can be reproc'd */\n                  }\n\n                  continue;\n               }\n\n               if (flags & flag_block_comment)\n               {\n                  if (!b)\n                  {  sprintf (error, \"%d:%d: Unexpected EOF in block comment\", line_and_col);\n                     goto e_failed;\n                  }\n\n                  if (b == '*' && state.ptr < (end - 1) && state.ptr [1] == '/')\n                  {\n                     flags &= ~ flag_block_comment;\n                     ++ state.ptr;  /* skip closing sequence */\n                  }\n\n                  continue;\n               }\n            }\n            else if (b == '/')\n            {\n               if (! (flags & (flag_seek_value | flag_done)) && top->type != json_object)\n               {  sprintf (error, \"%d:%d: Comment not allowed here\", line_and_col);\n                  goto e_failed;\n               }\n\n               if (++ state.ptr == end)\n               {  sprintf (error, \"%d:%d: EOF unexpected\", line_and_col);\n                  goto e_failed;\n               }\n\n               switch (b = *state.ptr)\n               {\n                  case '/':\n                     flags |= flag_line_comment;\n                     continue;\n\n                  case '*':\n                     flags |= flag_block_comment;\n                     continue;\n\n                  default:\n                     sprintf (error, \"%d:%d: Unexpected `%c` in comment opening sequence\", line_and_col, b);\n                     goto e_failed;\n               };\n            }\n         }\n\n         if (flags & flag_done)\n         {\n            if (!b)\n               break;\n\n            switch (b)\n            {\n               whitespace:\n                  continue;\n\n               default:\n\n                  sprintf (error, \"%d:%d: Trailing garbage: `%c`\",\n                           state.cur_line, state.cur_col, b);\n\n                  goto e_failed;\n            };\n         }\n\n         if (flags & flag_seek_value)\n         {\n            switch (b)\n            {\n               whitespace:\n                  continue;\n\n               case ']':\n\n                  if (top && top->type == json_array)\n                     flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next;\n                  else\n                  {  sprintf (error, \"%d:%d: Unexpected ]\", line_and_col);\n                     goto e_failed;\n                  }\n\n                  break;\n\n               default:\n\n                  if (flags & flag_need_comma)\n                  {\n                     if (b == ',')\n                     {  flags &= ~ flag_need_comma;\n                        continue;\n                     }\n                     else\n                     {\n                        sprintf (error, \"%d:%d: Expected , before %c\",\n                                 state.cur_line, state.cur_col, b);\n\n                        goto e_failed;\n                     }\n                  }\n\n                  if (flags & flag_need_colon)\n                  {\n                     if (b == ':')\n                     {  flags &= ~ flag_need_colon;\n                        continue;\n                     }\n                     else\n                     {\n                        sprintf (error, \"%d:%d: Expected : before %c\",\n                                 state.cur_line, state.cur_col, b);\n\n                        goto e_failed;\n                     }\n                  }\n\n                  flags &= ~ flag_seek_value;\n\n                  switch (b)\n                  {\n                     case '{':\n\n                        if (!new_value (&state, &top, &root, &alloc, json_object))\n                           goto e_alloc_failure;\n\n                        continue;\n\n                     case '[':\n\n                        if (!new_value (&state, &top, &root, &alloc, json_array))\n                           goto e_alloc_failure;\n\n                        flags |= flag_seek_value;\n                        continue;\n\n                     case '\"':\n\n                        if (!new_value (&state, &top, &root, &alloc, json_string))\n                           goto e_alloc_failure;\n\n                        flags |= flag_string;\n\n                        string = top->u.string.ptr;\n                        string_length = 0;\n\n                        continue;\n\n                     case 't':\n\n                        if ((end - state.ptr) < 3 || *(++ state.ptr) != 'r' ||\n                            *(++ state.ptr) != 'u' || *(++ state.ptr) != 'e')\n                        {\n                           goto e_unknown_value;\n                        }\n\n                        if (!new_value (&state, &top, &root, &alloc, json_boolean))\n                           goto e_alloc_failure;\n\n                        top->u.boolean = 1;\n\n                        flags |= flag_next;\n                        break;\n\n                     case 'f':\n\n                        if ((end - state.ptr) < 4 || *(++ state.ptr) != 'a' ||\n                            *(++ state.ptr) != 'l' || *(++ state.ptr) != 's' ||\n                            *(++ state.ptr) != 'e')\n                        {\n                           goto e_unknown_value;\n                        }\n\n                        if (!new_value (&state, &top, &root, &alloc, json_boolean))\n                           goto e_alloc_failure;\n\n                        flags |= flag_next;\n                        break;\n\n                     case 'n':\n\n                        if ((end - state.ptr) < 3 || *(++ state.ptr) != 'u' ||\n                            *(++ state.ptr) != 'l' || *(++ state.ptr) != 'l')\n                        {\n                           goto e_unknown_value;\n                        }\n\n                        if (!new_value (&state, &top, &root, &alloc, json_null))\n                           goto e_alloc_failure;\n\n                        flags |= flag_next;\n                        break;\n\n                     default:\n\n                        if (isdigit (b) || b == '-')\n                        {\n                           if (!new_value (&state, &top, &root, &alloc, json_integer))\n                              goto e_alloc_failure;\n\n                           if (!state.first_pass)\n                           {\n                              while (isdigit (b) || b == '+' || b == '-'\n                                        || b == 'e' || b == 'E' || b == '.')\n                              {\n                                 if ( (++ state.ptr) == end)\n                                 {\n                                    b = 0;\n                                    break;\n                                 }\n\n                                 b = *state.ptr;\n                              }\n\n                              flags |= flag_next | flag_reproc;\n                              break;\n                           }\n\n                           flags &= ~ (flag_num_negative | flag_num_e |\n                                        flag_num_e_got_sign | flag_num_e_negative |\n                                           flag_num_zero);\n\n                           num_digits = 0;\n                           num_fraction = 0;\n                           num_e = 0;\n\n                           if (b != '-')\n                           {\n                              flags |= flag_reproc;\n                              break;\n                           }\n\n                           flags |= flag_num_negative;\n                           continue;\n                        }\n                        else\n                        {  sprintf (error, \"%d:%d: Unexpected %c when seeking value\", line_and_col, b);\n                           goto e_failed;\n                        }\n                  };\n            };\n         }\n         else\n         {\n            switch (top->type)\n            {\n            case json_object:\n\n               switch (b)\n               {\n                  whitespace:\n                     continue;\n\n                  case '\"':\n\n                     if (flags & flag_need_comma)\n                     {  sprintf (error, \"%d:%d: Expected , before \\\"\", line_and_col);\n                        goto e_failed;\n                     }\n\n                     flags |= flag_string;\n\n                     string = (json_char *) top->_reserved.object_mem;\n                     string_length = 0;\n\n                     break;\n\n                  case '}':\n\n                     flags = (flags & ~ flag_need_comma) | flag_next;\n                     break;\n\n                  case ',':\n\n                     if (flags & flag_need_comma)\n                     {\n                        flags &= ~ flag_need_comma;\n                        break;\n                     }\n                     // fall through\n\n                  default:\n                     sprintf (error, \"%d:%d: Unexpected `%c` in object\", line_and_col, b);\n                     goto e_failed;\n               };\n\n               break;\n\n            case json_integer:\n            case json_double:\n\n               if (isdigit (b))\n               {\n                  ++ num_digits;\n\n                  if (top->type == json_integer || flags & flag_num_e)\n                  {\n                     if (! (flags & flag_num_e))\n                     {\n                        if (flags & flag_num_zero)\n                        {  sprintf (error, \"%d:%d: Unexpected `0` before `%c`\", line_and_col, b);\n                           goto e_failed;\n                        }\n\n                        if (num_digits == 1 && b == '0')\n                           flags |= flag_num_zero;\n                     }\n                     else\n                     {\n                        flags |= flag_num_e_got_sign;\n                        num_e = (num_e * 10) + (b - '0');\n                        continue;\n                     }\n\n                     if (would_overflow(top->u.integer, b))\n                     {  -- num_digits;\n                        -- state.ptr;\n                        top->type = json_double;\n                        top->u.dbl = (double)top->u.integer;\n                        continue;\n                     }\n\n                     top->u.integer = (top->u.integer * 10) + (b - '0');\n                     continue;\n                  }\n\n                  if (flags & flag_num_got_decimal)\n                     num_fraction = (num_fraction * 10) + (b - '0');\n                  else\n                     top->u.dbl = (top->u.dbl * 10) + (b - '0');\n\n                  continue;\n               }\n\n               if (b == '+' || b == '-')\n               {\n                  if ( (flags & flag_num_e) && !(flags & flag_num_e_got_sign))\n                  {\n                     flags |= flag_num_e_got_sign;\n\n                     if (b == '-')\n                        flags |= flag_num_e_negative;\n\n                     continue;\n                  }\n               }\n               else if (b == '.' && top->type == json_integer)\n               {\n                  if (!num_digits)\n                  {  sprintf (error, \"%d:%d: Expected digit before `.`\", line_and_col);\n                     goto e_failed;\n                  }\n\n                  top->type = json_double;\n                  top->u.dbl = (double) top->u.integer;\n\n                  flags |= flag_num_got_decimal;\n                  num_digits = 0;\n                  continue;\n               }\n\n               if (! (flags & flag_num_e))\n               {\n                  if (top->type == json_double)\n                  {\n                     if (!num_digits)\n                     {  sprintf (error, \"%d:%d: Expected digit after `.`\", line_and_col);\n                        goto e_failed;\n                     }\n\n                     top->u.dbl += num_fraction / pow (10.0, num_digits);\n                  }\n\n                  if (b == 'e' || b == 'E')\n                  {\n                     flags |= flag_num_e;\n\n                     if (top->type == json_integer)\n                     {\n                        top->type = json_double;\n                        top->u.dbl = (double) top->u.integer;\n                     }\n\n                     num_digits = 0;\n                     flags &= ~ flag_num_zero;\n\n                     continue;\n                  }\n               }\n               else\n               {\n                  if (!num_digits)\n                  {  sprintf (error, \"%d:%d: Expected digit after `e`\", line_and_col);\n                     goto e_failed;\n                  }\n\n                  top->u.dbl *= pow (10.0, (flags & flag_num_e_negative ? - num_e : num_e));\n               }\n\n               if (flags & flag_num_negative)\n               {\n                  if (top->type == json_integer)\n                     top->u.integer = - top->u.integer;\n                  else\n                     top->u.dbl = - top->u.dbl;\n               }\n\n               flags |= flag_next | flag_reproc;\n               break;\n\n            default:\n               break;\n            };\n         }\n\n         if (flags & flag_reproc)\n         {\n            flags &= ~ flag_reproc;\n            -- state.ptr;\n         }\n\n         if (flags & flag_next)\n         {\n            flags = (flags & ~ flag_next) | flag_need_comma;\n\n            if (!top->parent)\n            {\n               /* root value done */\n\n               flags |= flag_done;\n               continue;\n            }\n\n            if (top->parent->type == json_array)\n               flags |= flag_seek_value;\n\n            if (!state.first_pass)\n            {\n               json_value * parent = top->parent;\n\n               switch (parent->type)\n               {\n                  case json_object:\n\n                     parent->u.object.values\n                        [parent->u.object.length].value = top;\n\n                     break;\n\n                  case json_array:\n\n                     parent->u.array.values\n                           [parent->u.array.length] = top;\n\n                     break;\n\n                  default:\n                     break;\n               };\n            }\n\n            if ( (++ top->parent->u.array.length) > state.uint_max)\n               goto e_overflow;\n\n            top = top->parent;\n\n            continue;\n         }\n      }\n\n      alloc = root;\n   }\n\n   return root;\n\ne_unknown_value:\n\n   sprintf (error, \"%d:%d: Unknown value\", line_and_col);\n   goto e_failed;\n\ne_alloc_failure:\n\n   strcpy (error, \"Memory allocation failure\");\n   goto e_failed;\n\ne_overflow:\n\n   sprintf (error, \"%d:%d: Too long (caught overflow)\", line_and_col);\n   goto e_failed;\n\ne_failed:\n\n   if (error_buf)\n   {\n      if (*error)\n         strcpy (error_buf, error);\n      else\n         strcpy (error_buf, \"Unknown error\");\n   }\n\n   if (state.first_pass)\n      alloc = root;\n\n   while (alloc)\n   {\n      top = alloc->_reserved.next_alloc;\n      state.settings.mem_free (alloc, state.settings.user_data);\n      alloc = top;\n   }\n\n   if (!state.first_pass)\n      json_value_free_ex (&state.settings, root);\n\n   return 0;\n}\n\njson_value * json_parse (const json_char * json, size_t length)\n{\n   json_settings settings = { 0 };\n   return json_parse_ex (&settings, json, length, 0);\n}\n\nvoid json_value_free_ex (json_settings * settings, json_value * value)\n{\n   json_value * cur_value;\n\n   if (!value)\n      return;\n\n   value->parent = 0;\n\n   while (value)\n   {\n      switch (value->type)\n      {\n         case json_array:\n\n            if (!value->u.array.length)\n            {\n               settings->mem_free (value->u.array.values, settings->user_data);\n               break;\n            }\n\n            value = value->u.array.values [-- value->u.array.length];\n            continue;\n\n         case json_object:\n\n            if (!value->u.object.length)\n            {\n               settings->mem_free (value->u.object.values, settings->user_data);\n               break;\n            }\n\n            value = value->u.object.values [-- value->u.object.length].value;\n            continue;\n\n         case json_string:\n\n            settings->mem_free (value->u.string.ptr, settings->user_data);\n            break;\n\n         default:\n            break;\n      };\n\n      cur_value = value;\n      value = value->parent;\n      settings->mem_free (cur_value, settings->user_data);\n   }\n}\n\nvoid json_value_free (json_value * value)\n{\n   json_settings settings = { 0 };\n   settings.mem_free = default_free;\n   json_value_free_ex (&settings, value);\n}\n\n"
  },
  {
    "path": "json-parser/json.h",
    "content": "\n/* vim: set et ts=3 sw=3 sts=3 ft=c:\n *\n * Copyright (C) 2012, 2013, 2014 James McLaughlin et al.  All rights reserved.\n * https://github.com/udp/json-parser\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n *\n * 1. Redistributions of source code must retain the above copyright\n *   notice, this list of conditions and the following disclaimer.\n *\n * 2. Redistributions in binary form must reproduce the above copyright\n *   notice, this list of conditions and the following disclaimer in the\n *   documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n */\n\n#ifndef _JSON_H\n#define _JSON_H\n\n#ifndef json_char\n   #define json_char char\n#endif\n\n#ifndef json_int_t\n   #ifndef _MSC_VER\n      #include <inttypes.h>\n      #define json_int_t int64_t\n   #else\n      #define json_int_t __int64\n   #endif\n#endif\n\n#include <stdlib.h>\n\n#ifdef __cplusplus\n\n   #include <string.h>\n\n   extern \"C\"\n   {\n\n#endif\n\ntypedef struct\n{\n   unsigned long max_memory;\n   int settings;\n\n   /* Custom allocator support (leave null to use malloc/free)\n    */\n\n   void * (* mem_alloc) (size_t, int zero, void * user_data);\n   void (* mem_free) (void *, void * user_data);\n\n   void * user_data;  /* will be passed to mem_alloc and mem_free */\n\n   size_t value_extra;  /* how much extra space to allocate for values? */\n\n} json_settings;\n\n#define json_enable_comments  0x01\n\ntypedef enum\n{\n   json_none,\n   json_object,\n   json_array,\n   json_integer,\n   json_double,\n   json_string,\n   json_boolean,\n   json_null\n\n} json_type;\n\nextern const struct _json_value json_value_none;\n       \ntypedef struct _json_object_entry\n{\n    json_char * name;\n    unsigned int name_length;\n    \n    struct _json_value * value;\n    \n} json_object_entry;\n\ntypedef struct _json_value\n{\n   struct _json_value * parent;\n\n   json_type type;\n\n   union\n   {\n      int boolean;\n      json_int_t integer;\n      double dbl;\n\n      struct\n      {\n         unsigned int length;\n         json_char * ptr; /* null terminated */\n\n      } string;\n\n      struct\n      {\n         unsigned int length;\n\n         json_object_entry * values;\n\n         #if defined(__cplusplus) && __cplusplus >= 201103L\n         decltype(values) begin () const\n         {  return values;\n         }\n         decltype(values) end () const\n         {  return values + length;\n         }\n         #endif\n\n      } object;\n\n      struct\n      {\n         unsigned int length;\n         struct _json_value ** values;\n\n         #if defined(__cplusplus) && __cplusplus >= 201103L\n         decltype(values) begin () const\n         {  return values;\n         }\n         decltype(values) end () const\n         {  return values + length;\n         }\n         #endif\n\n      } array;\n\n   } u;\n\n   union\n   {\n      struct _json_value * next_alloc;\n      void * object_mem;\n\n   } _reserved;\n\n   #ifdef JSON_TRACK_SOURCE\n\n      /* Location of the value in the source JSON\n       */\n      unsigned int line, col;\n\n   #endif\n\n\n   /* Some C++ operator sugar */\n\n   #ifdef __cplusplus\n\n      public:\n\n         inline _json_value ()\n         {  memset (this, 0, sizeof (_json_value));\n         }\n\n         inline const struct _json_value &operator [] (int index) const\n         {\n            if (type != json_array || index < 0\n                     || ((unsigned int) index) >= u.array.length)\n            {\n               return json_value_none;\n            }\n\n            return *u.array.values [index];\n         }\n\n         inline const struct _json_value &operator [] (const char * index) const\n         { \n            if (type != json_object)\n               return json_value_none;\n\n            for (unsigned int i = 0; i < u.object.length; ++ i)\n               if (!strcmp (u.object.values [i].name, index))\n                  return *u.object.values [i].value;\n\n            return json_value_none;\n         }\n\n         inline operator const char * () const\n         {  \n            switch (type)\n            {\n               case json_string:\n                  return u.string.ptr;\n\n               default:\n                  return \"\";\n            };\n         }\n\n         inline operator json_int_t () const\n         {  \n            switch (type)\n            {\n               case json_integer:\n                  return u.integer;\n\n               case json_double:\n                  return (json_int_t) u.dbl;\n\n               default:\n                  return 0;\n            };\n         }\n\n         inline operator bool () const\n         {  \n            if (type != json_boolean)\n               return false;\n\n            return u.boolean != 0;\n         }\n\n         inline operator double () const\n         {  \n            switch (type)\n            {\n               case json_integer:\n                  return (double) u.integer;\n\n               case json_double:\n                  return u.dbl;\n\n               default:\n                  return 0;\n            };\n         }\n\n   #endif\n\n} json_value;\n       \njson_value * json_parse (const json_char * json,\n                         size_t length);\n\n#define json_error_max 128\njson_value * json_parse_ex (json_settings * settings,\n                            const json_char * json,\n                            size_t length,\n                            char * error);\n\nvoid json_value_free (json_value *);\n\n\n/* Not usually necessary, unless you used a custom mem_alloc and now want to\n * use a custom mem_free.\n */\nvoid json_value_free_ex (json_settings * settings,\n                         json_value *);\n\n\n#ifdef __cplusplus\n   } /* extern \"C\" */\n#endif\n\n#endif\n\n\n"
  },
  {
    "path": "modding/background_new.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/background_new.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"specific/background.h\"\n#include \"specific/file.h\"\n#include \"specific/frontend.h\"\n#include \"specific/hwr.h\"\n#include \"specific/init_display.h\"\n#include \"specific/input.h\"\n#include \"specific/output.h\"\n#include \"specific/texture.h\"\n#include \"specific/winvid.h\"\n#include \"modding/file_utils.h\"\n#include \"modding/gdi_utils.h\"\n#include \"modding/texture_utils.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\nextern LPDDS CaptureBufferSurface;\nextern TEXPAGE_DESC TexturePages[256];\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\n#ifdef FEATURE_GOLD\nextern bool IsGold();\n#endif\n\nstatic int BGND_CapturePageIndexes[64];\nint BGND_TexturePageIndexes[64];\nHWR_TEXHANDLE BGND_PageHandles[64];\n\nDWORD BGND_PictureWidth  = 640;\nDWORD BGND_PictureHeight = 480;\nbool BGND_IsCaptured = false;\n\nDWORD PictureStretchLimit = 10;\nbool RemasteredPixEnabled = true;\n\nstatic DWORD BGND_TextureSide  = 1024;\nstatic DWORD BGND_TextureAlpha = 255;\n\n/// Short wave horizontal pattern step\n#define SHORT_WAVE_X_STEP\t(0x3000)\n/// Short wave vertical pattern step\n#define SHORT_WAVE_Y_STEP\t(0x33E7)\n/// Short wave horizontal pattern offset\n#define SHORT_WAVE_X_OFFSET\t(SHORT_WAVE_X_STEP * 2)\n/// Short wave vertical pattern offset\n#define SHORT_WAVE_Y_OFFSET\t(SHORT_WAVE_Y_STEP * 1)\n/// Long wave horizontal pattern step\n#define LONG_WAVE_X_STEP\t(0x1822)\n/// Long wave vertical pattern step\n#define LONG_WAVE_Y_STEP\t(0x1422)\n/// Long wave horizontal pattern offset\n#define LONG_WAVE_X_OFFSET\t(LONG_WAVE_X_STEP * 2)\n/// Long wave vertical pattern offset\n#define LONG_WAVE_Y_OFFSET\t(LONG_WAVE_Y_STEP * 1)\n\n/// Pixel accuracy factor (for more exact integer computations)\n#define PIXEL_ACCURACY\t(4)\n/// Animated pattern detail level (Increases the smoothness of the curve)\n#define PATTERN_DETAIL\t(2)\n\n/// 2D vertex (no Z coordinate) structure\ntypedef struct {\n\tD3DVALUE x; ///< Vertex X coordinate (pixels)\n\tD3DVALUE y; ///< Vertex Y coordinate (pixels)\n\tD3DCOLOR color; ///< Vertex color (ARGB)\n} VERTEX2D;\n\n/// Texture data structure\ntypedef struct {\n\tHWR_TEXHANDLE handle; ///< Handle of texture\n\tint u; ///< Texture U coordinate (pixels)\n\tint v; ///< Texture V coordinate (pixels)\n\tint width;\t///< Texture width (pixels)\n\tint height;\t///< Texture height (pixels)\n} TEXTURE;\n\n/**\n * Draws flat textured quad polygon (two triangles) at far Z coordinate\n * @param[in] vtx0,vtx1,vtx2,vtx3 Pointers to the Vertex structures\n * @param[in] txr Pointer to the Texture structure\n */\nvoid RenderTexturedFarQuad(VERTEX2D *vtx0, VERTEX2D *vtx1, VERTEX2D *vtx2, VERTEX2D *vtx3, TEXTURE *txr) {\n\textern int PatternTexPage;\n\tD3DTLVERTEX vtx[4];\n\n\tfloat tu0 = (double)txr->u / 256.0;\n\tfloat tv0 = (double)txr->v / 256.0;\n\tfloat tu1 = (double)(txr->u + txr->width)  / 256.0;\n\tfloat tv1 = (double)(txr->v + txr->height) / 256.0;\n\tif( PatternTexPage < 0 ) {\n\t\tdouble uvAdjust = (double)UvAdd / (double)(256 * GetTextureSideByHandle(txr->handle));\n\t\tCLAMPL(uvAdjust, 1.0/double(PHD_ONE));\n\t\ttu0 += uvAdjust;\n\t\ttv0 += uvAdjust;\n\t\ttu1 -= uvAdjust;\n\t\ttv1 -= uvAdjust;\n\t}\n\n\tfloat rhw = RhwFactor / FltFarZ;\n\n\tvtx[0].sx = vtx0->x;\n\tvtx[0].sy = vtx0->y;\n\tvtx[0].color = vtx0->color;\n\tvtx[0].tu = tu0;\n\tvtx[0].tv = tv0;\n\n\tvtx[1].sx = vtx1->x;\n\tvtx[1].sy = vtx1->y;\n\tvtx[1].color = vtx1->color;\n\tvtx[1].tu = tu1;\n\tvtx[1].tv = tv0;\n\n\tvtx[2].sx = vtx2->x;\n\tvtx[2].sy = vtx2->y;\n\tvtx[2].color = vtx2->color;\n\tvtx[2].tu = tu0;\n\tvtx[2].tv = tv1;\n\n\tvtx[3].sx = vtx3->x;\n\tvtx[3].sy = vtx3->y;\n\tvtx[3].color = vtx3->color;\n\tvtx[3].tu = tu1;\n\tvtx[3].tv = tv1;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tvtx[i].sz = 0.995;\n\t\tvtx[i].rhw = rhw;\n\t\tvtx[i].specular = 0;\n\t}\n\n\tHWR_TexSource(txr->handle);\n\tHWR_EnableColorKey(false);\n\tHWR_DrawPrimitive(D3DPT_TRIANGLESTRIP, &vtx, 4, false);\n}\n\n/**\n * Draws animated pattern wallpaper (TR2 PlayStation inventory style)\n * @param[in] texSource Handle of texture\n * @param[in] tu Texture U coordinate (pixels)\n * @param[in] tv Texture V coordinate (pixels)\n * @param[in] t_width Texture width (pixels)\n * @param[in] t_height Texture height (pixels)\n * @param[in] halfRowCount Half number of vertical rows of the wallpaper pattern\n * @param[in] amplitude Percent value of the deformation amplitude (vertex rotation radius)\n * @param[in] deformWavePhase Deformation wave phase in Integer representation\n * @param[in] shortWavePhase Lighting short wave phase in Integer representation\n * @param[in] longWavePhase Lighting long wave phase in Integer representation\n */\nvoid PSX_Background(HWR_TEXHANDLE texSource, int tu, int tv, int t_width, int t_height, int halfRowCount,\n\t\t\t\t\t__int16 amplitude, __int16 deformWavePhase, __int16 shortWavePhase, __int16 longWavePhase)\n{\n\tint halfColCount = MulDiv(halfRowCount, PhdWinWidth*3, PhdWinHeight*4) + 1;\n\n\thalfRowCount *= PATTERN_DETAIL;\n\thalfColCount *= PATTERN_DETAIL;\n\n\tint light;\n\tint countY = halfRowCount*2+1;\n\tint countX = halfColCount*2+1;\n\tint tileSize = MulDiv(PhdWinHeight, PIXEL_ACCURACY*2, halfRowCount*3);\n\tint tileRadius = MulDiv(tileSize, amplitude*PATTERN_DETAIL, 100);\n\tint baseY = PhdWinHeight * PIXEL_ACCURACY/2 - halfRowCount*tileSize;\n\tint baseX = PhdWinWidth  * PIXEL_ACCURACY/2  - halfColCount*tileSize;\n\tVERTEX2D *vertices = (VERTEX2D *)malloc(sizeof(VERTEX2D)*countX*countY);\n\tTEXTURE subTxr;\n\n\tdeformWavePhase += SHORT_WAVE_X_OFFSET;\n\tshortWavePhase  += SHORT_WAVE_X_OFFSET;\n\tlongWavePhase   += LONG_WAVE_X_OFFSET;\n\n\tfor( int i=0; i<countX; ++i ) {\n\t\tshort deformWaveRowPhase = deformWavePhase + SHORT_WAVE_Y_OFFSET;\n\t\tshort shortWaveRowPhase  = shortWavePhase  + SHORT_WAVE_Y_OFFSET;\n\t\tshort longWaveRowPhase   = longWavePhase   + LONG_WAVE_Y_OFFSET;\n\n\t\tfor( int j=0; j<countY; ++j ) {\n\t\t\tVERTEX2D *vtx = &vertices[i*countY+j];\n\t\t\tint shortWave = phd_sin(shortWaveRowPhase)*32/0x4000;\n\t\t\tint longWave = phd_sin(longWaveRowPhase)*32/0x4000;\n\t\t\tlight = 128 + shortWave + longWave;\n#if defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\tif( SavedAppSettings.LightingMode ) light /= 2;\n#endif // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\tvtx->color = RGBA_MAKE(light, light, light, 0xFFu);\n\t\t\tvtx->y = ((float)(baseY + tileSize*j + phd_sin(deformWaveRowPhase)*tileRadius/0x4000)) / PIXEL_ACCURACY;\n\t\t\tvtx->x = ((float)(baseX + tileSize*i + phd_cos(deformWaveRowPhase)*tileRadius/0x4000)) / PIXEL_ACCURACY;\n\n\t\t\tdeformWaveRowPhase += SHORT_WAVE_Y_STEP / PATTERN_DETAIL;\n\t\t\tshortWaveRowPhase  += SHORT_WAVE_Y_STEP / PATTERN_DETAIL;\n\t\t\tlongWaveRowPhase   += LONG_WAVE_Y_STEP  / PATTERN_DETAIL;\n\t\t}\n\t\tdeformWavePhase += SHORT_WAVE_X_STEP / PATTERN_DETAIL;\n\t\tshortWavePhase  += SHORT_WAVE_X_STEP / PATTERN_DETAIL;\n\t\tlongWavePhase   += LONG_WAVE_X_STEP  / PATTERN_DETAIL;\n\t}\n\n\tsubTxr.handle = texSource;\n\tsubTxr.width  = t_width  / PATTERN_DETAIL;\n\tsubTxr.height = t_height / PATTERN_DETAIL;\n\n\tfor( int i=0; i<halfColCount*2; ++i ) {\n\t\tfor( int j=0; j<halfRowCount*2; ++j ) {\n\t\t\tVERTEX2D *vtx0 = &vertices[(i+0)*countY+(j+0)];\n\t\t\tVERTEX2D *vtx1 = &vertices[(i+1)*countY+(j+0)];\n\t\t\tVERTEX2D *vtx2 = &vertices[(i+0)*countY+(j+1)];\n\t\t\tVERTEX2D *vtx3 = &vertices[(i+1)*countY+(j+1)];\n\t\t\tsubTxr.u = tu + (i%PATTERN_DETAIL)*subTxr.width;\n\t\t\tsubTxr.v = tv + (j%PATTERN_DETAIL)*subTxr.height;\n\t\t\tRenderTexturedFarQuad(vtx0, vtx1, vtx2, vtx3, &subTxr);\n\t\t}\n\t}\n\tfree(vertices);\n}\n\nstatic int CreateCaptureTexture(DWORD index, int side) {\n\tint pageIndex = BGND_CapturePageIndexes[index];\n\tif( pageIndex >= 0 && TexturePages[pageIndex].width != side ) {\n\t\tSafeFreeTexturePage(pageIndex);\n\t\tpageIndex = -1;\n\t}\n\tif( pageIndex < 0 || !CHK_ANY(TexturePages[pageIndex].status, 1) ) {\n\t\tDDSDESC desc;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tpageIndex = CreateTexturePage(side, side, false);\n\t\tif( pageIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t\tif SUCCEEDED(TexturePages[pageIndex].texture->LockRect(0, &desc, NULL, 0)) {\n\t\t\tTexturePages[pageIndex].texture->UnlockRect(0);\n\t\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tpageIndex = CreateTexturePage(side, side, NULL);\n\t\tif SUCCEEDED(WinVidBufferLock(TexturePages[pageIndex].sysMemSurface, &desc, DDLOCK_WRITEONLY|DDLOCK_WAIT)) {\n\t\t\tWinVidBufferUnlock(TexturePages[pageIndex].sysMemSurface, &desc);\n\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tif( pageIndex < 0 ) {\n\t\t\treturn -1;\n\t\t}\n\t\tBGND_CapturePageIndexes[index] = pageIndex;\n\t}\n\treturn pageIndex;\n}\n\nvoid BGND2_CleanupCaptureTextures() {\n\tfor( DWORD i=0; i<ARRAY_SIZE(BGND_CapturePageIndexes); ++i ) {\n\t\tBGND_CapturePageIndexes[i] = -1;\n\t}\n}\n\nint BGND2_PrepareCaptureTextures() {\n\tstatic bool once = false;\n\tif( !once ) {\n\t\tBGND2_CleanupCaptureTextures();\n\t\tonce = true;\n\t}\n\tDWORD side = MIN(2048, GetMaxTextureSize());\n\tDWORD nx = (GameVidWidth + side - 1) / side;\n\tDWORD ny = (GameVidHeight + side - 1) / side;\n\tfor( DWORD i=0; i<ARRAY_SIZE(BGND_CapturePageIndexes); ++i ) {\n\t\tif( i < nx*ny ) {\n\t\t\tCreateCaptureTexture(i, side);\n\t\t} else {\n\t\t\tSafeFreeTexturePage(BGND_CapturePageIndexes[i]);\n\t\t\tBGND_CapturePageIndexes[i] = -1;\n\t\t}\n\t}\n\treturn 0;\n}\n\nstatic int MakeBgndTextures(DWORD width, DWORD height, DWORD bpp, BYTE *bitmap, RGB888 *bmpPal) {\n\tDWORD side = MIN(2048, GetMaxTextureSize());\n\tS_DontDisplayPicture(); // clean up previous textures\n\n\tif( bmpPal != NULL && (SavedAppSettings.RenderMode != RM_Hardware || TextureFormat.bpp < 16) ) {\n\t\tBGND_PaletteIndex = CreateTexturePalette(bmpPal);\n\t} else {\n\t\tBGND_PaletteIndex = -1;\n\t}\n\n\tDWORD nx = (width + side - 1) / side;\n\tDWORD ny = (height + side - 1) / side;\n\n\tif( nx*ny >= ARRAY_SIZE(BGND_TexturePageIndexes) ) {\n\t\treturn -1; // It seems image is too big\n\t}\n\n\tfor( DWORD j = 0; j < ny; ++j ) {\n\t\tfor( DWORD i = 0; i < nx; ++i ) {\n\t\t\tDWORD w = side;\n\t\t\tDWORD h = side;\n\t\t\tif( i == nx - 1 && width % side ) w = width % side;\n\t\t\tif( j == ny - 1 && height % side ) h = height % side;\n\t\t\tint pageIndex = MakeCustomTexture(i*side, j*side, w, h, width, side, bpp, bitmap, bmpPal, BGND_PaletteIndex, NULL, false);\n\t\t\tif( pageIndex < 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tBGND_TexturePageIndexes[i + j*nx] = pageIndex;\n\t\t}\n\t}\n\n\tBGND_PictureWidth = width;\n\tBGND_PictureHeight = height;\n\tBGND_TextureSide = side;\n\tBGND_GetPageHandles();\n\tBGND_PictureIsReady = true;\n\treturn 0;\n}\n\nstatic int PickBestPictureFile(LPTSTR fileName, LPCTSTR modDir) {\n\tstatic const STRING_FIXED4 exts[] = {\"PNG\", \"JPG\", \"BMP\"};\n\tstatic const BYTE numAspects = 7;\n\tstatic const BYTE aspects[numAspects][2] = {\n\t\t{5,4}, {4,3}, {3,2}, {16,10}, {16,9}, {21,9}, {32,9} // common display aspect ratios\n\t};\n\tif( fileName == NULL || !*fileName || modDir == NULL || !*modDir ) {\n\t\treturn -1;\n\t}\n\n\tDWORD i, j;\n\tfloat winAspect = (float)PhdWinWidth / (float)PhdWinHeight;\n\tfloat stretch[numAspects];\n\tBYTE tmp, idx[numAspects];\n\tfor( i = 0; i < numAspects; ++i ) {\n\t\tfloat imgAspect = (float)aspects[i][0] / (float)aspects[i][1];\n\t\tidx[i] = i;\n\t\tstretch[i] = (imgAspect > winAspect) ? (imgAspect / winAspect) : (winAspect / imgAspect);\n\t}\n\n\tfor( i = 0; i < (numAspects - 1); ++i ) {\n\t\tfor( j = (i + 1); j < numAspects; ++j ) {\n\t\t\tif( stretch[idx[i]] > stretch[idx[j]] ) {\n\t\t\t\tSWAP(idx[i], idx[j], tmp); // sort stretch values\n\t\t\t}\n\t\t}\n\t}\n\n\tbool isRemasterEnabled = RemasteredPixEnabled && SavedAppSettings.RenderMode == RM_Hardware && TextureFormat.bpp >= 16;\n\tchar altPath[256];\n\tfor( i = 0; i < numAspects; ++i ) {\n\t\tsnprintf(altPath, sizeof(altPath), \".\\\\%s\\\\%dx%d\", modDir, aspects[idx[i]][0], aspects[idx[i]][1]);\n\t\tif( 0 < AutoSelectPathAndExtension(fileName, altPath, exts, isRemasterEnabled ? ARRAY_SIZE(exts) : 0) ) {\n\t\t\treturn 2;\n\t\t}\n\t}\n\n\tsnprintf(altPath, sizeof(altPath), \".\\\\%s\", modDir);\n\treturn AutoSelectPathAndExtension(fileName, altPath, exts, isRemasterEnabled ? ARRAY_SIZE(exts) : 0);\n}\n\n\nint __cdecl BGND2_FadeTo(int target, int delta) {\n\tint current = BGND_TextureAlpha;\n\n\tif( target > current && delta > 0 )\t{\n\t\tcurrent += delta;\n\t\tCLAMPG(current, target);\n\t} else if( target < current && delta < 0 ) {\n\t\tcurrent += delta;\n\t\tCLAMPL(current, target);\n\t} else {\n\t\treturn current;\n\t}\n\n\tCLAMP(current, 0, 255);\n\tBGND_TextureAlpha = current;\n\treturn current;\n}\n\nstatic int __cdecl BGND2_FadeToPal(int fadeValue, RGB888 *palette, int inputCheck) {\n\tint i, j;\n\tint palStartIdx = 0;\n\tint palEndIdx = 256;\n#if (DIRECT3D_VERSION < 0x900)\n\tint palSize = 256;\n#endif // (DIRECT3D_VERSION < 0x900)\n\tbool fadeFaster = false;\n\tPALETTEENTRY fadePal[256];\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.RenderMode != RM_Software )\n\t\treturn fadeValue;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( !GameVid_IsVga )\n\t\treturn fadeValue;\n\n\tif( GameVid_IsWindowedVga ) {\n\t\tpalStartIdx += 10;\n\t\tpalEndIdx -= 10;\n\t\tpalSize -= 20;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( fadeValue <= 1 ) {\n\t\tfor( i=palStartIdx; i<palEndIdx; ++i ) {\n\t\t\tWinVidPalette[i].peRed   = palette[i].red;\n\t\t\tWinVidPalette[i].peGreen = palette[i].green;\n\t\t\tWinVidPalette[i].peBlue  = palette[i].blue;\n\t\t}\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tS_InitialisePolyList(FALSE);\n\t\tS_OutputPolyList();\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tDDrawPalette->SetEntries(0, palStartIdx, palSize, &WinVidPalette[palStartIdx]);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\treturn fadeValue;\n\t}\n\n\tfor( i=palStartIdx; i<palEndIdx; ++i ) {\n\t\tfadePal[i] = WinVidPalette[i];\n\t}\n\n\tfor( j=0; j<=fadeValue; ++j ) {\n\t\tif( S_UpdateInput() ) return fadeValue;\n\t\tif( inputCheck && InputStatus ) {\n\t\t\tif( inputCheck == 1 ) {\n\t\t\t\treturn fadeValue - j + 1;\n\t\t\t} else if( inputCheck == 2 ) {\n\t\t\t\tfadeFaster = true;\n\t\t\t}\n\t\t\tif( fadeFaster && j < fadeValue ) ++j;\n\t\t}\n\t\tfor( i=palStartIdx; i<palEndIdx; ++i ) {\n\t\t\tWinVidPalette[i].peRed   = fadePal[i].peRed   + (palette[i].red   - fadePal[i].peRed)   * j / fadeValue;\n\t\t\tWinVidPalette[i].peGreen = fadePal[i].peGreen + (palette[i].green - fadePal[i].peGreen) * j / fadeValue;\n\t\t\tWinVidPalette[i].peBlue  = fadePal[i].peBlue  + (palette[i].blue  - fadePal[i].peBlue)  * j / fadeValue;\n\t\t}\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tS_InitialisePolyList(FALSE);\n\t\tS_OutputPolyList();\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tDDrawPalette->SetEntries(0, palStartIdx, palSize, &WinVidPalette[palStartIdx]);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tS_DumpScreen();\n\t}\n\treturn fadeFaster ? 1 : 0;\n}\n\nstatic void BGND2_CustomBlt(LPDDSDESC dst, DWORD dstX, DWORD dstY, LPDDSDESC src, LPRECT srcRect) {\n\tDWORD srcX = srcRect->left;\n\tDWORD srcY = srcRect->top;\n\tDWORD width = srcRect->right - srcRect->left;\n\tDWORD height = srcRect->bottom - srcRect->top;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tBYTE *srcLine = (BYTE *)src->pBits + srcY * src->Pitch  + srcX * 4;\n\tBYTE *dstLine = (BYTE *)dst->pBits + dstY * dst->Pitch  + dstX * 4;\n\n\tfor( DWORD j = 0; j < height; ++j ) {\n\t\tmemcpy(dstLine, srcLine, sizeof(DWORD) * width);\n\t\tsrcLine += src->Pitch;\n\t\tdstLine += dst->Pitch;\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tDWORD srcBpp = src->ddpfPixelFormat.dwRGBBitCount/8;\n\tDWORD dstBpp = dst->ddpfPixelFormat.dwRGBBitCount/8;\n\tCOLOR_BIT_MASKS srcMask, dstMask;\n\n\tWinVidGetColorBitMasks(&srcMask, &src->ddpfPixelFormat);\n\tWinVidGetColorBitMasks(&dstMask, &dst->ddpfPixelFormat);\n\n\tBYTE *srcLine = (BYTE *)src->lpSurface + srcY * src->lPitch  + srcX * srcBpp;\n\tBYTE *dstLine = (BYTE *)dst->lpSurface + dstY * dst->lPitch  + dstX * dstBpp;\n\tfor( DWORD j = 0; j < height; ++j ) {\n\t\tBYTE *srcPtr = srcLine;\n\t\tBYTE *dstPtr = dstLine;\n\t\tfor( DWORD i = 0; i < width; ++i ) {\n\t\t\tDWORD color = 0;\n\t\t\tmemcpy(&color, srcPtr, srcBpp);\n\t\t\tDWORD red   = ((color & srcMask.dwRBitMask) >> srcMask.dwRBitOffset);\n\t\t\tDWORD green = ((color & srcMask.dwGBitMask) >> srcMask.dwGBitOffset);\n\t\t\tDWORD blue  = ((color & srcMask.dwBBitMask) >> srcMask.dwBBitOffset);\n\t\t\tif( srcMask.dwRBitDepth < dstMask.dwRBitDepth ) {\n\t\t\t\tDWORD high = dstMask.dwRBitDepth - srcMask.dwRBitDepth;\n\t\t\t\tDWORD low = (srcMask.dwRBitDepth > high) ? srcMask.dwRBitDepth - high : 0;\n\t\t\t\tred = (red << high) | (red >> low);\n\t\t\t} else if( srcMask.dwRBitDepth > dstMask.dwRBitDepth ) {\n\t\t\t\tred >>= srcMask.dwRBitDepth - dstMask.dwRBitDepth;\n\t\t\t}\n\t\t\tif( srcMask.dwGBitDepth < dstMask.dwGBitDepth ) {\n\t\t\t\tDWORD high = dstMask.dwGBitDepth - srcMask.dwGBitDepth;\n\t\t\t\tDWORD low = (srcMask.dwGBitDepth > high) ? srcMask.dwGBitDepth - high : 0;\n\t\t\t\tgreen = (green << high) | (green >> low);\n\t\t\t} else if( srcMask.dwGBitDepth > dstMask.dwGBitDepth ) {\n\t\t\t\tgreen >>= srcMask.dwGBitDepth - dstMask.dwGBitDepth;\n\t\t\t}\n\t\t\tif( srcMask.dwBBitDepth < dstMask.dwBBitDepth ) {\n\t\t\t\tDWORD high = dstMask.dwBBitDepth - srcMask.dwBBitDepth;\n\t\t\t\tDWORD low = (srcMask.dwBBitDepth > high) ? srcMask.dwBBitDepth - high : 0;\n\t\t\t\tblue = (blue << high) | (blue >> low);\n\t\t\t} else if( srcMask.dwBBitDepth > dstMask.dwBBitDepth ) {\n\t\t\t\tblue >>= srcMask.dwBBitDepth - dstMask.dwBBitDepth;\n\t\t\t}\n\t\t\tcolor = dst->ddpfPixelFormat.dwRGBAlphaBitMask; // destination is opaque\n\t\t\tcolor |= red   << dstMask.dwRBitOffset;\n\t\t\tcolor |= green << dstMask.dwGBitOffset;\n\t\t\tcolor |= blue  << dstMask.dwBBitOffset;\n\t\t\tmemcpy(dstPtr, &color, dstBpp);\n\t\t\tsrcPtr += srcBpp;\n\t\t\tdstPtr += dstBpp;\n\t\t}\n\t\tsrcLine += src->lPitch;\n\t\tdstLine += dst->lPitch;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nint __cdecl BGND2_CapturePicture() {\n\tbool isSrcLock = false;\n\tint ret = 0;\n\tDDSDESC srcDesc, dstDesc;\n\tDWORD width = 0;\n\tDWORD height = 0;\n\tRECT rect = {0, 0, 0, 0};\n\n\tif( SavedAppSettings.RenderMode != RM_Hardware || TextureFormat.bpp < 16 ) {\n\t\treturn -1;\n\t}\n\n\tBGND_PictureIsReady = false;\n\tBGND_IsCaptured = false;\n\n\t// do game window capture, not the whole screen\n\tif( !GetClientRect(HGameWindow, &rect) ) {\n\t\treturn -1;\n\t}\n\n#if (DIRECT3D_VERSION < 0x900)\n\tLPDDS surface = CaptureBufferSurface ? CaptureBufferSurface : PrimaryBufferSurface;\n#endif // (DIRECT3D_VERSION < 0x900)\n\tif( CaptureBufferSurface == NULL ) {\n\t\tMapWindowPoints(HGameWindow, GetParent(HGameWindow), (LPPOINT)&rect, 2);\n\t}\n\twidth = ABS(rect.right - rect.left);\n\theight = ABS(rect.bottom - rect.top);\n\n\tDWORD side = MIN(2048, GetMaxTextureSize());\n\n\tDWORD nx = (width + side - 1) / side;\n\tDWORD ny = (height + side - 1) / side;\n\n\tif( nx*ny >= ARRAY_SIZE(BGND_CapturePageIndexes) ) {\n\t\treturn -1; // It seems image is too big\n\t}\n\n\tint x[ARRAY_SIZE(BGND_CapturePageIndexes) + 1];\n\tx[nx] = rect.right - rect.left;\n\tfor( DWORD i = 0; i < nx; ++i ) {\n\t\tx[i] = i * side * x[nx] / width;\n\t}\n\n\tint y[ARRAY_SIZE(BGND_CapturePageIndexes) + 1];\n\ty[ny] = rect.bottom - rect.top;\n\tfor( DWORD i = 0; i < ny; ++i ) {\n\t\ty[i] = i * side * y[ny] / height;\n\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tDISPLAY_MODE mode;\n\tLPDDS surface = NULL;\n\tif( CaptureBufferSurface != NULL ) {\n\t\tsurface = CaptureBufferSurface;\n\t} else if( !WinVidGetDisplayMode(&mode)\n\t\t|| FAILED(D3DDev->CreateOffscreenPlainSurface(mode.width, mode.height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL))\n\t\t|| FAILED(D3DDev->GetFrontBufferData(0, surface)) )\n\t{\n\t\tret = -1;\n\t\tgoto CLEANUP;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tfor( DWORD j = 0; j < ny; ++j ) {\n\t\tfor( DWORD i = 0; i < nx; ++i ) {\n\t\t\tRECT r = {x[i], y[j], x[i+1], y[j+1]};\n\t\t\tint pageIndex = CreateCaptureTexture(i + j*nx, side);\n\t\t\tif( pageIndex < 0 ) {\n\t\t\t\tret = -1;\n\t\t\t\tgoto CLEANUP;\n\t\t\t}\n\n\t\t\t// NOTE: On some system default Blt/BltFast is unsupported here but returns no error, so failsafe custom blitter is used instead\n\t\t\tif( !isSrcLock ) {\n\t\t\t\tHRESULT rc;\n\t\t\t\tmemset(&srcDesc, 0, sizeof(srcDesc));\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\t\trc = surface->LockRect(&srcDesc, &rect, D3DLOCK_READONLY);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tsrcDesc.dwSize = sizeof(srcDesc);\n\t\t\t\tdo {\n\t\t\t\t\trc = surface->Lock(&rect, &srcDesc, DDLOCK_READONLY|DDLOCK_WAIT, NULL);\n\t\t\t\t} while( rc == DDERR_WASSTILLDRAWING );\n\t\t\t\tif( rc == DDERR_SURFACELOST ) {\n\t\t\t\t\trc = surface->Restore();\n\t\t\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tif FAILED(rc) {\n\t\t\t\t\tret = -1;\n\t\t\t\t\tgoto CLEANUP;\n\t\t\t\t}\n\t\t\t\tisSrcLock = true;\n\t\t\t}\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\tif FAILED(TexturePages[pageIndex].texture->LockRect(0, &dstDesc, NULL, 0)) {\n\t\t\t\tret = -1;\n\t\t\t\tgoto CLEANUP;\n\t\t\t}\n\t\t\tBGND2_CustomBlt(&dstDesc, 0, 0, &srcDesc, &r);\n\t\t\tTexturePages[pageIndex].texture->UnlockRect(0);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\t\tif FAILED(WinVidBufferLock(TexturePages[pageIndex].sysMemSurface, &dstDesc, DDLOCK_WRITEONLY|DDLOCK_WAIT)) {\n\t\t\t\tret = -1;\n\t\t\t\tgoto CLEANUP;\n\t\t\t}\n\t\t\tBGND2_CustomBlt(&dstDesc, 0, 0, &srcDesc, &r);\n\t\t\tWinVidBufferUnlock(TexturePages[pageIndex].sysMemSurface, &dstDesc);\n\n\t\t\tif( !LoadTexturePage(pageIndex, false) ) {\n\t\t\t\tret = -1;\n\t\t\t\tgoto CLEANUP;\n\t\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t}\n\t}\n\n\tBGND_TextureSide = side;\n\tBGND_TextureAlpha = 255;\n\tBGND_PictureWidth = width;\n\tBGND_PictureHeight = height;\n\tBGND_PictureIsReady = true;\n\tBGND_IsCaptured = true;\n\nCLEANUP :\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( surface != NULL ) {\n\t\tif( isSrcLock ) {\n\t\t\tsurface->UnlockRect();\n\t\t}\n\t\tif( surface != CaptureBufferSurface ) {\n\t\t\tsurface->Release();\n\t\t}\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( isSrcLock ) {\n\t\tsurface->Unlock(srcDesc.lpSurface);\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\treturn ret;\n}\n\n\nint __cdecl BGND2_LoadPicture(LPCTSTR fileName, BOOL isTitle, BOOL isReload) {\n\tstatic char lastFileName[256] = {0};\n\tstatic char lastFullPath[256] = {0};\n\tstatic int lastWinWidth = 0;\n\tstatic int lastWinHeight = 0;\n\tstatic BOOL lastTitleState = 0;\n\tDWORD bytesRead;\n\tHANDLE hFile;\n\tDWORD fileSize, bitmapSize;\n\tBYTE *fileData = NULL;\n\tBYTE *bitmapData = NULL;\n\tDWORD width, height, bpp = 8;\n\tchar fullPath[256] = {0};\n\tbool isPCX;\n\tint pickResult = -1;\n\n\tBGND_IsCaptured = false; // captured screen is not valid since we want picture file now\n\n\tif( isReload ) {\n\t\tif( IsGameWindowChanging || IsGameWindowUpdating ||\n\t\t\t(lastWinWidth == PhdWinWidth && lastWinHeight == PhdWinHeight) )\n\t\t{\n\t\t\treturn 0; // same dimensions - no need to reload picture\n\t\t}\n\t\tfileName = lastFileName; // assign last fileName pointer as parameter\n\t\tisTitle = lastTitleState; // copy last isTitle state\n\t} else {\n\t\tBGND_TextureAlpha = 255;\n\t\tif( fileName == NULL || *fileName == 0 ) {\n\t\t\tgoto FAIL;\n\t\t}\n\t\tstrncpy(lastFileName, fileName, sizeof(lastFileName)-1); // backup filename string\n\t\tlastTitleState = isTitle; // backup isTitle state\n\t}\n\n\tlastWinWidth = PhdWinWidth;\n\tlastWinHeight = PhdWinHeight;\n\n#ifdef FEATURE_GOLD\n\tif( IsGold() ) {\n\t\tAddFilenameSuffix(fullPath, sizeof(fullPath), GetFullPath(fileName), \"g\");\n\t\tpickResult = PickBestPictureFile(fullPath, \"pix\");\n\t}\n\tif( !IsGold() || pickResult < 0 ) {\n\t\tstrncpy(fullPath, GetFullPath(fileName), sizeof(fullPath)-1);\n\t\tpickResult = PickBestPictureFile(fullPath, \"pix\");\n\t}\n#else // !FEATURE_GOLD\n\tstrncpy(fullPath, GetFullPath(fileName), sizeof(fullPath));\n\tpickResult = PickBestPictureFile(fullPath, \"pix\");\n#endif // FEATURE_GOLD\n\n\tif( pickResult < 0 ) {\n\t\tif( isReload ) {\n\t\t\tif( !strncmp(lastFullPath, fullPath, sizeof(lastFullPath)) ) {\n\t\t\t\treturn 0; // same filepath - no need to reload picture\n\t\t\t}\n\t\t\tstrncpy(lastFullPath, fullPath, sizeof(lastFullPath));\n\t\t} else {\n\t\t\tgoto FAIL;\n\t\t}\n\t}\n\n\tif( INVALID_FILE_ATTRIBUTES == GetFileAttributes(fullPath) ) {\n\t\tgoto FAIL;\n\t}\n\n\tif( !stricmp(PathFindExtension(fullPath), \".pcx\") ) {\n\t\thFile = CreateFile(fullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\t\tif( hFile == INVALID_HANDLE_VALUE ) {\n\t\t\tgoto FAIL;\n\t\t}\n\t\tfileSize = GetFileSize(hFile, NULL);\n\t\tfileData = (BYTE *)malloc(fileSize);\n\t\tReadFile(hFile, fileData, fileSize, &bytesRead, NULL);\n\t\tCloseHandle(hFile);\n\n\t\tif( GetPcxResolution(fileData, fileSize, &width, &height) ) {\n\t\t\tgoto FAIL;\n\t\t}\n\t\tbitmapSize = width * height;\n\t\tbitmapData = (BYTE *)malloc(bitmapSize);\n\t\tDecompPCX(fileData, fileSize, bitmapData, PicPalette);\n\t\tisPCX = true;\n\t} else if( SavedAppSettings.RenderMode == RM_Hardware && TextureFormat.bpp >= 16 ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tbpp = 32;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tbpp = 16;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tif( GDI_LoadImageFile(fullPath, &bitmapData, &width, &height, bpp) ) {\n\t\t\tgoto FAIL;\n\t\t}\n\t\tbitmapSize = width * height * 2;\n\t\tisPCX = false;\n\t} else {\n\t\tgoto FAIL;\n\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( PictureBuffer.bitmap == NULL ||\n\t\tPictureBuffer.width != width ||\n\t\tPictureBuffer.height != height )\n\t{\n\t\tBGND_PictureWidth = width;\n\t\tBGND_PictureHeight = height;\n\t\ttry {\n\t\t\tCreatePictureBuffer();\n\t\t} catch(...) {\n\t\t\tgoto FAIL;\n\t\t}\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( PictureBufferSurface != NULL &&\n\t\t(BGND_PictureWidth != width || BGND_PictureHeight != height) )\n\t{\n\t\tBGND_PictureWidth = width;\n\t\tBGND_PictureHeight = height;\n\t\tPictureBufferSurface->Release();\n\t\tPictureBufferSurface = NULL;\n\t}\n\tif( PictureBufferSurface == NULL ) {\n\t\ttry {\n\t\t\tCreatePictureBuffer();\n\t\t} catch(...) {\n\t\t\tgoto FAIL;\n\t\t}\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tif( PictureBuffer.bitmap != NULL)\n\t\t\tmemcpy(PictureBuffer.bitmap, bitmapData, PictureBuffer.width * PictureBuffer.height);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tWinVidCopyBitmapToBuffer(PictureBufferSurface, bitmapData);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t} else {\n\t\tMakeBgndTextures(width, height, bpp, bitmapData, isPCX ? PicPalette : NULL);\n\t}\n\n\tif( !isTitle && isPCX ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tmemcpy(GamePalette8, PicPalette, sizeof(GamePalette8));\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tCopyBitmapPalette(PicPalette, bitmapData, bitmapSize, GamePalette8);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n\tif( bitmapData != NULL ) {\n\t\tfree(bitmapData);\n\t}\n\tif( fileData != NULL ) {\n\t\tfree(fileData);\n\t}\n\n\treturn 0;\n\nFAIL :\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( PictureBuffer.bitmap != NULL ) {\n\t\tfree(PictureBuffer.bitmap);\n\t\tPictureBuffer.bitmap = NULL;\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( PictureBufferSurface != NULL ) {\n\t\tPictureBufferSurface->Release();\n\t\tPictureBufferSurface = NULL;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\tif( bitmapData != NULL ) {\n\t\tfree(bitmapData);\n\t}\n\tif( fileData != NULL ) {\n\t\tfree(fileData);\n\t}\n\n\tS_DontDisplayPicture();\n\treturn -1;\n}\n\nint __cdecl BGND2_ShowPicture(DWORD fadeIn, DWORD waitIn, DWORD fadeOut, DWORD waitOut, BOOL inputCheck) {\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\tint skip = 0;\n\t\tRGB888 blackPal[256];\n\t\tmemset(blackPal, 0, sizeof(blackPal));\n\n\t\t// output picture\n\t\tS_InitialisePolyList(FALSE);\n\t\tS_CopyBufferToScreen();\n\t\tS_OutputPolyList();\n\n\t\t// fade in\n\t\tif( fadeIn > 0 ) {\n\t\t\tmemset(WinVidPalette, 0, sizeof(WinVidPalette));\n\t\t\tskip = BGND2_FadeToPal(fadeIn, GamePalette8, inputCheck ? 1 : 0);\n\t\t}\n\t\tif( IsGameToExit ) {\n\t\t\treturn -1;\n\t\t}\n\t\tif( skip ) {\n\t\t\tinputCheck = FALSE;\n\t\t\tfadeOut /= 2;\n\t\t\twaitOut /= 2;\n\t\t} else if( waitIn > 0 ) {\n\t\t\tS_Wait(waitIn * TICKS_PER_FRAME, inputCheck);\n\t\t}\n\t\tif( IsGameToExit ) {\n\t\t\treturn -1;\n\t\t}\n\n\t\t// fade out\n\t\tif( fadeOut > 0 ) {\n\t\t\tskip = BGND2_FadeToPal(fadeOut, blackPal, inputCheck ? 2 : 0);\n\t\t\tif( skip ) waitOut /= 2;\n\t\t}\n\t\tif( IsGameToExit ) {\n\t\t\treturn -1;\n\t\t}\n\t\tif( fadeOut > 0 || waitOut > 0 ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\tScreenClear(false);\n\t\t\tS_Wait(2 * TICKS_PER_FRAME, FALSE);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\t\tScreenClear(false); ScreenDump();\n\t\t\tScreenClear(false); ScreenDump();\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t}\n\t\tif( waitOut > 2 ) {\n\t\t\tS_Wait((waitOut - 2) * TICKS_PER_FRAME, inputCheck);\n\t\t}\n\t\tif( IsGameToExit ) {\n\t\t\treturn -1;\n\t\t}\n\t} else {\n\t\tDWORD i = fadeIn + waitIn + fadeOut + waitOut;\n\t\tDWORD phase = 0;\n\t\tDWORD frame = 0;\n\t\tBGND_TextureAlpha = 255;\n\t\twhile( i-- ) {\n\t\t\tswitch( phase ) {\n\t\t\t\tcase 0 :\n\t\t\t\t\tif( frame < fadeIn ) {\n\t\t\t\t\t\tBGND_TextureAlpha = 255 * frame / (fadeIn - 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t++phase;\n\t\t\t\t\tframe = 0;\n\t\t\t\t\t// fall through\n\t\t\t\tcase 1 :\n\t\t\t\t\tif( frame < waitIn ) {\n\t\t\t\t\t\tBGND_TextureAlpha = 255;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t++phase;\n\t\t\t\t\tframe = 0;\n\t\t\t\t\t// fall through\n\t\t\t\tcase 2 :\n\t\t\t\t\tif( frame < fadeOut ) {\n\t\t\t\t\t\tBGND_TextureAlpha = 255 * (fadeOut - frame - 1) / fadeOut;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t++phase;\n\t\t\t\t\tframe = 0;\n\t\t\t\t\t// fall through\n\t\t\t\tcase 3 :\n\t\t\t\t\tif( frame < waitOut ) {\n\t\t\t\t\t\tBGND_TextureAlpha = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t++phase;\n\t\t\t\t\tframe = 0;\n\t\t\t\t\t// fall through\n\t\t\t\tdefault :\n\t\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tS_InitialisePolyList(FALSE);\n\t\t\tS_CopyBufferToScreen();\n\t\t\tS_OutputPolyList();\n\t\t\tS_DumpScreen();\n\t\t\tS_UpdateInput();\n\t\t\tif( IsGameToExit ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif( inputCheck && InputStatus != 0 ) {\n\t\t\t\t// fade out faster if key pressed\n\t\t\t\tinputCheck = FALSE;\n\t\t\t\tfadeOut /= 2;\n\t\t\t\twaitOut /= 2;\n\t\t\t\tphase = 2;\n\t\t\t\tfor( frame = 0; frame < fadeOut; ++frame ) {\n\t\t\t\t\tif( BGND_TextureAlpha > 255 * (fadeOut - frame - 1) / fadeOut ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t++frame;\n#ifdef FEATURE_INPUT_IMPROVED\n\t\t\tUpdateJoyOutput(false);\n#endif // FEATURE_INPUT_IMPROVED\n\t\t}\n\t}\n\treturn 0;\n}\n\nstatic void __cdecl BGND2_DrawTexture(RECT *rect, HWR_TEXHANDLE texSource,\n\t\t\t\t\t\t\t\t\t  int tu, int tv, int t_width, int t_height, int t_side,\n\t\t\t\t\t\t\t\t\t  D3DCOLOR color0, D3DCOLOR color1, D3DCOLOR color2, D3DCOLOR color3)\n{\n\tfloat sx0, sy0, sx1, sy1;\n\tfloat tu0, tv0, tu1, tv1;\n\tDWORD alphaState;\n\tD3DTLVERTEX vertex[4];\n\n\tif( rect == NULL ) {\n\t\treturn;\n\t}\n\n\tsx0 = (double)rect->left;\n\tsy0 = (double)rect->top;\n\tsx1 = (double)rect->right;\n\tsy1 = (double)rect->bottom;\n\n\ttu0 = (double)tu / (double)t_side;\n\ttv0 = (double)tv / (double)t_side;\n\ttu1 = (double)(tu + t_width)  / (double)t_side;\n\ttv1 = (double)(tv + t_height) / (double)t_side;\n\n\tvertex[0].sx = sx0;\n\tvertex[0].sy = sy0;\n\tvertex[0].color = RGBA_SETALPHA(color0, BGND_TextureAlpha);\n\tvertex[0].tu = tu0;\n\tvertex[0].tv = tv0;\n\n\tvertex[1].sx = sx1;\n\tvertex[1].sy = sy0;\n\tvertex[1].color = RGBA_SETALPHA(color1, BGND_TextureAlpha);\n\tvertex[1].tu = tu1;\n\tvertex[1].tv = tv0;\n\n\tvertex[2].sx = sx0;\n\tvertex[2].sy = sy1;\n\tvertex[2].color = RGBA_SETALPHA(color2, BGND_TextureAlpha);\n\tvertex[2].tu = tu0;\n\tvertex[2].tv = tv1;\n\n\tvertex[3].sx = sx1;\n\tvertex[3].sy = sy1;\n\tvertex[3].color = RGBA_SETALPHA(color3, BGND_TextureAlpha);\n\tvertex[3].tu = tu1;\n\tvertex[3].tv = tv1;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tvertex[i].sz = 0.995;\n\t\tvertex[i].rhw = RhwFactor / FltFarZ;\n\t\tvertex[i].specular = 0;\n\t}\n\n\tHWR_TexSource(texSource);\n\tHWR_EnableColorKey(false);\n\tD3DDev->GetRenderState(AlphaBlendEnabler, &alphaState);\n\tD3DDev->SetRenderState(AlphaBlendEnabler, TRUE);\n\tHWR_DrawPrimitive(D3DPT_TRIANGLESTRIP, &vertex, 4, true);\n\tD3DDev->SetRenderState(AlphaBlendEnabler, alphaState);\n}\n\nvoid __cdecl BGND2_DrawTextures(RECT *rect, D3DCOLOR color) {\n\tif( !BGND_PictureIsReady || !BGND_TextureSide ) {\n\t\treturn;\n\t}\n\n\tDWORD width = BGND_PictureWidth;\n\tDWORD height = BGND_PictureHeight;\n\tDWORD side = BGND_TextureSide;\n\tDWORD nx = (width + side - 1) / side;\n\tDWORD ny = (height + side - 1) / side;\n\n\tif( nx*ny >= ARRAY_SIZE(BGND_TexturePageIndexes) ) {\n\t\treturn; // It seems image is too big\n\t}\n\n\tint x[ARRAY_SIZE(BGND_TexturePageIndexes) + 1];\n\tfor( DWORD i = 0; i < nx; ++i ) {\n\t\tx[i] = i * side * (rect->right - rect->left) / width + rect->left;\n\t}\n\tx[nx] = rect->right;\n\n\tint y[ARRAY_SIZE(BGND_TexturePageIndexes) + 1];\n\tfor( DWORD i = 0; i < ny; ++i ) {\n\t\ty[i] = i * side * (rect->bottom - rect->top) / height + rect->top;\n\t}\n\ty[ny] = rect->bottom;\n\n\tfor( DWORD j = 0; j < ny; ++j ) {\n\t\tfor( DWORD i = 0; i < nx; ++i ) {\n\t\t\tDWORD w = side;\n\t\t\tDWORD h = side;\n\t\t\tif( i == nx - 1 && width % side ) w = width % side;\n\t\t\tif( j == ny - 1 && height % side ) h = height % side;\n\t\t\tRECT r = {x[i], y[j], x[i+1], y[j+1]};\n\n\t\t\tint *index = BGND_IsCaptured ? BGND_CapturePageIndexes : BGND_TexturePageIndexes;\n\t\t\tBGND2_DrawTexture(&r, GetTexturePageHandle(index[i + j*nx]), 0, 0, w, h, side, color, color, color, color);\n\t\t}\n\t}\n}\n\nint __cdecl BGND2_CalculatePictureRect(RECT *rect) {\n\tif( rect == NULL || !PhdWinWidth || !PhdWinHeight || !BGND_PictureWidth || !BGND_PictureHeight )\n\t\treturn -1;\n\n\tif( PictureStretchLimit >= 100 ) {\n\t\t*rect = PhdWinRect;\n\t\treturn 1;\n\t}\n\n\tDWORD stretch;\n\tint x, y, w, h;\n\tdouble windowAspect = (double)PhdWinWidth / (double)PhdWinHeight;\n\tdouble pictureAspect = (double)BGND_PictureWidth / (double)BGND_PictureHeight;\n\n\tif( windowAspect > pictureAspect ) {\n\t\tw = (double)PhdWinHeight * pictureAspect;\n\t\th = PhdWinHeight;\n\t\tx = (PhdWinWidth - w) / 2;\n\t\ty = 0;\n\t\tstretch = 100 * PhdWinWidth / w - 100;\n\t} else {\n\t\tw = PhdWinWidth;\n\t\th = (double)PhdWinWidth / pictureAspect;\n\t\tx = 0;\n\t\ty = (PhdWinHeight - h) / 2;\n\t\tstretch = 100 * PhdWinHeight / h - 100;\n\t}\n\n\tif( stretch <= PictureStretchLimit ) {\n\t\t*rect = PhdWinRect;\n\t\treturn 1;\n\t}\n\n\trect->left = x;\n\trect->top = y;\n\trect->right = x + w;\n\trect->bottom = y + h;\n\treturn 0;\n}\n\n#endif // FEATURE_BACKGROUND_IMPROVED\n"
  },
  {
    "path": "modding/background_new.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef BACKGROUND_NEW_H_INCLUDED\n#define BACKGROUND_NEW_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid PSX_Background(HWR_TEXHANDLE texSource, int tu, int tv, int t_width, int t_height, int halfRowCount,\n\t\t\t\t\t__int16 amplitude, __int16 deformWavePhase, __int16 shortWavePhase, __int16 longWavePhase);\n\nvoid BGND2_CleanupCaptureTextures();\n\nint BGND2_PrepareCaptureTextures();\n\nint __cdecl BGND2_FadeTo(int target, int delta);\n\nint __cdecl BGND2_CapturePicture();\n\nint __cdecl BGND2_LoadPicture(LPCTSTR fileName, BOOL isTitle, BOOL isReload);\n\nint __cdecl BGND2_ShowPicture(DWORD fadeIn, DWORD waitIn, DWORD fadeOut, DWORD waitOut, BOOL inputCheck);\n\nvoid __cdecl BGND2_DrawTextures(RECT *rect, D3DCOLOR color);\n\nint __cdecl BGND2_CalculatePictureRect(RECT *rect);\n\n#endif // BACKGROUND_NEW_H_INCLUDED\n"
  },
  {
    "path": "modding/cd_pauld.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * CD Audio solution in this file was designed by PaulD.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/sound.h\"\n#include \"modding/cd_pauld.h\"\n#include \"global/vars.h\"\n\n#define CD_ALIAS \"T2\"\n\ntypedef struct TrackInfo_t {\n\tDWORD from;\n\tDWORD to;\n\tbool active;\n} TRACK_INFO;\n\nstatic TRACK_INFO Tracks[60];\nstatic bool isCDAudioEnabled = false;\n\nbool __cdecl PaulD_CD_Init() {\n\tstatic LPCTSTR audioFiles[2] = {\n\t\t\"audio\\\\cdaudio.mp3\",\n\t\t\"audio\\\\cdaudio.wav\", // MCI volume control doesn't work with waveaudio. Wave option added just in case\n\t};\n\tstatic LPCTSTR audioTypes[2] = {\n\t\t\"mpegvideo\",\n\t\t\"waveaudio\",\n\t};\n\tHANDLE hFile;\n\tDWORD fileSize, bytesRead, offset;\n\tchar cmdString[256];\n\tchar *buf;\n\tint rc;\n\tint audioType = -1;\n\n\tif( isCDAudioEnabled )\n\t\treturn true;\n\n\tfor( int i=0; i<2; ++i ) {\n\t\thFile = CreateFile(audioFiles[i], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\t\tif( hFile != INVALID_HANDLE_VALUE ) {\n\t\t\taudioType = i;\n\t\t\tCloseHandle(hFile);\n\t\t\tbreak;\n\t\t}\n\t}\n\tif( audioType < 0 )\n\t\treturn false;\n\n\thFile = CreateFile(\"audio\\\\cdaudio.dat\", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile == INVALID_HANDLE_VALUE )\n\t\treturn false;\n\n\tfileSize = GetFileSize(hFile, NULL);\n\tbuf = (char *)malloc(fileSize);\n\tif( buf == NULL ) {\n\t\tCloseHandle(hFile);\n\t\treturn false;\n\t}\n\trc = ReadFile(hFile, buf, fileSize, &bytesRead, NULL);\n\tCloseHandle(hFile);\n\tif( !rc || bytesRead == 0 ) return false;\n\n\tmemset(Tracks, 0, sizeof(Tracks));\n\toffset = 0;\n\n\twhile( offset < bytesRead ) {\n\t\tDWORD index, from, to;\n\n\t\twhile( buf[offset] == 0x0A || buf[offset] == 0x0D ) {\n\t\t\tif( ++offset >= bytesRead ) goto PARSE_END; // skip empty lines\n\t\t}\n\t\trc = sscanf(&buf[offset], \"%lu %lu %lu\", &index, &from, &to); // track comment is ignored\n\t\tif( rc == 3 && index > 0 && index <= 60 ) {\n\t\t\tTracks[index-1].active = true;\n\t\t\tTracks[index-1].from = from;\n\t\t\tTracks[index-1].to = to;\n\t\t}\n\t\twhile( buf[offset] != 0x0A && buf[offset] != 0x0D ) {\n\t\t\tif( ++offset >= bytesRead ) goto PARSE_END; // skip until newline\n\t\t}\n\t}\nPARSE_END :\n\tfree(buf);\n\n\t// Fix cdaudio.dat if it's broken (like the one from the Steam version)\n\tfor( DWORD i=0; i<ARRAY_SIZE(Tracks); ++i ) {\n\t\tif( !Tracks[i].active ) continue;\n\t\tif( Tracks[i].from >= Tracks[i].to && i < ARRAY_SIZE(Tracks)-1 ) {\n\t\t\t// Trying to fix data using the next track\n\t\t\tfor( DWORD j=i+1; j<ARRAY_SIZE(Tracks); ++j ) {\n\t\t\t\tif( Tracks[j].active ) {\n\t\t\t\t\tTracks[i].to = Tracks[j].from;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif( Tracks[i].from >= Tracks[i].to && i > 0 ) {\n\t\t\t// Trying to fix data using the previous track\n\t\t\tfor( int j=i-1; j>=0; --j ) {\n\t\t\t\tif( Tracks[j].active ) {\n\t\t\t\t\tTracks[i].from = Tracks[j].to;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\twsprintf(cmdString, \"open %s type %s alias \" CD_ALIAS, audioFiles[audioType], audioTypes[audioType]);\n\trc = mciSendString(cmdString, NULL, 0, 0);\n\tif( rc == 0 ) {\n\t\tmciSendString(\"set \" CD_ALIAS \" time format ms\", NULL, 0, 0);\n\t\tisCDAudioEnabled = true;\n\t}\n\treturn true;\n}\n\nvoid __cdecl PaulD_CD_Cleanup() {\n\tif( isCDAudioEnabled ) {\n\t\tPaulD_CDStop();\n\t\tmciSendString(\"close \" CD_ALIAS, NULL, 0, 0);\n\t\tisCDAudioEnabled = false;\n\t}\n}\n\nvoid __cdecl PaulD_CDLoop() {\n\tint rc;\n\tchar statusString[32];\n\tchar cmdString[256];\n\n\tif( CD_LoopTrack == 0 || ++CD_LoopCounter < 150 )\n\t\treturn;\n\n\tCD_LoopCounter = 0;\n\trc = mciSendString(\"status \" CD_ALIAS \" mode\", statusString, sizeof(statusString), 0);\n\n\tif( (rc == 0) && !strncmp(statusString, \"stopped\", sizeof(statusString)) ) {\n\t\twsprintf(cmdString, \"play \" CD_ALIAS \" from %lu to %lu\", Tracks[CD_LoopTrack-1].from, Tracks[CD_LoopTrack-1].to);\n\t\tmciSendString(cmdString, NULL, 0, 0);\n\t}\n}\n\nvoid __cdecl PaulD_CDPlay(__int16 trackID, BOOL isLooped) {\n\t__int16 track;\n\tchar cmdString[256];\n\n\tif( MusicVolume == 0 )\n\t\treturn;\n\n\ttrack = GetRealTrack(trackID);\n\tif( track < 1 || !Tracks[track-1].active )\n\t\treturn;\n\n\tCD_TrackID = trackID;\n\n\twsprintf(cmdString, \"play \" CD_ALIAS \" from %lu to %lu\", Tracks[track-1].from, Tracks[track-1].to);\n\tmciSendString(cmdString, NULL, 0, 0);\n\n\tif( isLooped ) {\n\t\tCD_LoopTrack = track;\n\t\tCD_LoopCounter = 120;\n\t}\n}\n\nvoid __cdecl PaulD_CDStop() {\n\tif( CD_TrackID > 0 ) {\n\t\tmciSendString(\"stop \" CD_ALIAS, NULL, 0, 0);\n\t\tCD_TrackID = 0;\n\t\tCD_LoopTrack = 0;\n\t}\n}\n\nBOOL __cdecl PaulD_StartSyncedAudio(int trackID) {\n\t__int16 track;\n\tchar cmdString[256];\n\n\ttrack = GetRealTrack(trackID);\n\tif( track < 1 || !Tracks[track-1].active )\n\t\treturn FALSE;\n\n\tCD_TrackID = trackID;\n\tif( 0 != mciSendString(\"set \" CD_ALIAS \" time format ms\", NULL, 0, 0) )\n\t\treturn FALSE;\n\n\twsprintf(cmdString, \"play \" CD_ALIAS \" from %lu to %lu\", Tracks[track-1].from, Tracks[track-1].to);\n\treturn ( 0 == mciSendString(cmdString, NULL, 0, 0) );\n}\n\nDWORD __cdecl PaulD_CDGetLoc() {\n\t__int16 track;\n\tchar statusString[32];\n\n\tif( 0 != mciSendString(\"status \" CD_ALIAS \" position\", statusString, sizeof(statusString), 0) )\n\t\treturn 0;\n\n\ttrack = GetRealTrack(CD_TrackID);\n\t// calculate audio frames position (75 audio frames per second)\n\treturn (atol(statusString) - Tracks[track-1].from) * 75 / 1000;\n}\n\nvoid __cdecl PaulD_CDVolume(DWORD volume) {\n\tchar cmdString[256];\n\n\tif( volume > 0 )\n\t\tvolume = (volume - 5) * 4; // 0..255 -> 0..1000\n\n\twsprintf(cmdString, \"setaudio \" CD_ALIAS \" volume to %lu\", volume);\n\tmciSendString(cmdString, NULL, 0, 0);\n\n\tchar statusString[32];\n\tif( 0 == mciSendString(\"status \" CD_ALIAS \" mode\", statusString, sizeof(statusString), 0) ) {\n\t\tif( volume > 0 ) {\n\t\t\tif( !strncmp(statusString, \"paused\", sizeof(statusString)) ) {\n\t\t\t\tmciSendString(\"resume \" CD_ALIAS, NULL, 0, 0);\n\t\t\t}\n\t\t} else {\n\t\t\tif( !strncmp(statusString, \"playing\", sizeof(statusString)) ) {\n\t\t\t\tmciSendString(\"pause \" CD_ALIAS, NULL, 0, 0);\n\t\t\t}\n\t\t}\n\t}\n}\n\n"
  },
  {
    "path": "modding/cd_pauld.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * CD Audio solution in this file was designed by PaulD.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef CD_PAULD_H_INCLUDED\n#define CD_PAULD_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nbool __cdecl PaulD_CD_Init();\nvoid __cdecl PaulD_CD_Cleanup();\nvoid __cdecl PaulD_CDLoop();\nvoid __cdecl PaulD_CDPlay(__int16 trackID, BOOL isLooped);\nvoid __cdecl PaulD_CDStop();\nBOOL __cdecl PaulD_StartSyncedAudio(int trackID);\nDWORD __cdecl PaulD_CDGetLoc();\nvoid __cdecl PaulD_CDVolume(DWORD volume);\n\n#endif // CD_PAULD_H_INCLUDED\n"
  },
  {
    "path": "modding/file_utils.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/file_utils.h\"\n#include \"global/vars.h\"\n\nint PathStringCombine(LPSTR destPath, DWORD destSize, LPCSTR filePath, LPCSTR fileName) {\n\tif( destPath == NULL || destSize == 0 || fileName == NULL || *fileName == 0 ) {\n\t\treturn -1;\n\t}\n\tchar *tmpPath = new char[destSize];\n\n\tif( filePath == NULL || *filePath == 0 ) {\n\t\tstrncpy(tmpPath, \".\", destSize);\n\t} else {\n\t\tstrncpy(tmpPath, filePath, destSize);\n\t\tPathRemoveBackslash(tmpPath);\n\t}\n\tsnprintf(destPath, destSize, \"%s\\\\%s\", tmpPath, fileName);\n\n\tdelete[] tmpPath;\n\treturn 0;\n}\n\nint AutoSelectExtension(LPSTR fileName, const STRING_FIXED4 *exts, DWORD num_exts) {\n\tif( fileName == NULL ) {\n\t\treturn -1;\n\t}\n\n\tif( exts != NULL && num_exts > 0 ) {\n\t\tchar extFileName[256] = {0};\n\t\tchar *extension;\n\n\t\tstrncpy(extFileName, fileName, sizeof(extFileName)-1);\n\t\textension = PathFindExtension(extFileName);\n\n\t\tif( extension == NULL ) {\n\t\t\textension = strchr(extFileName, 0);\n\t\t\t*extension = '.';\n\t\t}\n\n\t\tfor( DWORD i = 0; i < num_exts; ++i ) {\n\t\t\tmemcpy(extension + 1, &exts[i], sizeof(STRING_FIXED4));\n\t\t\tif( PathFileExists(extFileName) ) {\n\t\t\t\tstrcpy(fileName, extFileName);\n\t\t\t\treturn (i + 1);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn ( PathFileExists(fileName) ) ? 0 : -1;\n}\n\nint AutoSelectPathAndExtension(LPSTR fileName, LPCSTR path, const STRING_FIXED4 *exts, DWORD num_exts) {\n\tchar checkFileName[MAX_PATH] = {0};\n\tint ext;\n\n\tif( fileName == NULL || !*fileName ) {\n\t\treturn -1;\n\t}\n\n\tif( path != NULL && *path ) {\n\t\tLPCSTR fname = PathFindFileName(fileName);\n\t\tPathStringCombine(checkFileName, sizeof(checkFileName), path, fname);\n\n\t\text = AutoSelectExtension(checkFileName, exts, num_exts);\n\n\t\tif( ext >= 0 ) {\n\t\t\tstrcpy(fileName, checkFileName);\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\text = AutoSelectExtension(fileName, exts, num_exts);\n\treturn ( ext >= 0 ) ? 0 : -1;\n}\n\nint CreateDirectories(LPCSTR path, bool isFileName) {\n\tchar shortPath[MAX_PATH];\n\tchar fullPath[MAX_PATH];\n\n\tstrncpy(shortPath, path, sizeof(shortPath)-1);\n\tif( isFileName ) {\n\t\tPathRemoveFileSpec(shortPath);\n\t}\n\tGetFullPathName(shortPath, MAX_PATH, fullPath, NULL);\n\n\tswitch( SHCreateDirectoryExA(NULL, fullPath, NULL) ) {\n\t\tcase ERROR_ALREADY_EXISTS :\n\t\tcase ERROR_FILE_EXISTS :\n\t\tcase ERROR_SUCCESS :\n\t\t\treturn 0;\n\t\tdefault :\n\t\t\tbreak;\n\t}\n\treturn -1;\n}\n\nint CreateSequenceFilename(LPSTR destName, DWORD destSize, LPCSTR filePath, LPCSTR fileExt, LPCSTR nameBase, int seqDigits, int seqNumber) {\n\tchar shortName[32] = {0};\n\tint i;\n\n\tif( destName == NULL || seqNumber < 0 || seqDigits <= 0 ) {\n\t\treturn -1;\n\t}\n\tif( filePath == NULL ) filePath = \"\";\n\tif( nameBase == NULL ) nameBase = \"\";\n\tif( fileExt  == NULL ) fileExt  = \"\";\n\n\tint seqMax = 1;\n\tfor( i = 0; i < seqDigits; ++i ) {\n\t\tseqMax *= 10;\n\t}\n\n\tfor( i = seqNumber; i < seqMax; ++i ) { // search first free screenshot slot\n\t\tsnprintf(shortName, sizeof(shortName), \"%s%0*d%s\", nameBase, seqDigits, i, fileExt);\n\t\tPathStringCombine(destName, destSize, filePath, shortName);\n\t\tif( INVALID_FILE_ATTRIBUTES == GetFileAttributes(destName) ) {\n\t\t\treturn i; // no file with such name - we have found the free slot\n\t\t}\n\t}\n\treturn -2;\n}\n\nint CreateDateTimeFilename(LPSTR destName, DWORD destSize, LPCSTR filePath, LPCSTR fileExt, SYSTEMTIME *lastTime, int *lastIndex) {\n\tchar shortName[32] = {0};\n\tchar fileName[32] = {0};\n\tSYSTEMTIME sysTime;\n\n\tif( destName == NULL ) {\n\t\treturn -1;\n\t}\n\tif( filePath == NULL ) filePath = \"\";\n\tif( fileExt  == NULL ) fileExt  = \"\";\n\n\tGetLocalTime(&sysTime);\n\tsysTime.wMilliseconds = 0; // we don't use milliseconds\n\n\tsnprintf(shortName, sizeof(shortName), \"%04d%02d%02d_%02d%02d%02d\",\n\t\t\tsysTime.wYear, sysTime.wMonth,  sysTime.wDay,\n\t\t\tsysTime.wHour, sysTime.wMinute, sysTime.wSecond);\n\n\tif( lastTime != NULL && lastIndex != NULL && !memcmp(&sysTime, lastTime, sizeof(SYSTEMTIME)) ) {\n\t\tsnprintf(fileName, sizeof(fileName), \"%s_%d%s\", shortName, ++*lastIndex, fileExt);\n\t} else {\n\t\tif( lastTime != NULL && lastIndex != NULL ) {\n\t\t\t*lastIndex = 0;\n\t\t\t*lastTime = sysTime;\n\t\t}\n\t\tsnprintf(fileName, sizeof(fileName), \"%s%s\", shortName, fileExt);\n\t}\n\n\tPathStringCombine(destName, destSize, filePath, fileName);\n\treturn 0;\n}\n\nint AddFilenameSuffix(LPSTR destName, DWORD destSize, LPCSTR fileName, LPCSTR suffix) {\n\t\tif( destName == NULL || !destSize || fileName == NULL || suffix == NULL ) {\n\t\t\treturn -1;\n\t\t}\n\n\t\tLPCSTR extension = PathFindExtension(fileName);\n\t\tint nameLen = (DWORD)extension - (DWORD)fileName;\n\n\t\tsnprintf(destName, destSize, \"%.*s%s%s\", nameLen, fileName, suffix, extension);\n\t\treturn 0;\n}\n\nLPCVOID GetResourceData(LPCTSTR resName, LPDWORD resSize) {\n\textern HINSTANCE hInstance;\n\n\tHRSRC resInfo = FindResource(hInstance, resName, RT_RCDATA);\n\tif( !resInfo ) return NULL;\n\tif( resSize ) *resSize = SizeofResource(hInstance, resInfo);\n\n\tHGLOBAL resHandle = LoadResource(hInstance, resInfo);\n\tif( !resHandle ) return NULL;\n\treturn LockResource(resHandle);\n}\n"
  },
  {
    "path": "modding/file_utils.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef FILE_UTILS_H_INCLUDED\n#define FILE_UTILS_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nint PathStringCombine(LPSTR destPath, DWORD destSize, LPCSTR filePath, LPCSTR fileName);\n\nint AutoSelectExtension(LPSTR fileName, const STRING_FIXED4 *exts, DWORD num_exts);\n\nint AutoSelectPathAndExtension(LPSTR fileName, LPCSTR path, const STRING_FIXED4 *exts, DWORD num_exts);\n\nint CreateDirectories(LPCSTR path, bool isFileName);\n\nint CreateSequenceFilename(LPSTR destName, DWORD destSize, LPCSTR filePath, LPCSTR fileExt, LPCSTR nameBase, int seqDigits, int seqNumber);\n\nint CreateDateTimeFilename(LPSTR fileName, DWORD destSize, LPCSTR filePath, LPCSTR fileExt, SYSTEMTIME *lastTime, int *lastIndex);\n\nint AddFilenameSuffix(LPSTR destName, DWORD destSize, LPCSTR fileName, LPCSTR suffix);\n\nLPCVOID GetResourceData(LPCTSTR resName, LPDWORD resSize);\n\n#endif // FILE_UTILS_H_INCLUDED\n"
  },
  {
    "path": "modding/gdi_utils.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/gdi_utils.h\"\n#include \"global/vars.h\"\n#include <gdiplus.h>\n\nusing namespace Gdiplus;\n\nstatic const WCHAR *GDI_Encoders[] = {\n\tL\"image/bmp\",\n\tL\"image/jpeg\",\n\tL\"image/png\",\n};\n\nstatic ULONG_PTR GDI_Token = 0;\n\nstatic int GetEncoderClsid(const WCHAR *format, CLSID *pClsid) {\n\tunsigned int num = 0, nSize = 0;\n\tGetImageEncodersSize(&num, &nSize);\n\tif( nSize == 0 ) {\n\t\treturn -1;\n\t}\n\tImageCodecInfo *pImageCodecInfo = (ImageCodecInfo *)malloc(nSize);\n\tif( pImageCodecInfo == NULL ) {\n\t\treturn -1;\n\t}\n\tGetImageEncoders(num, nSize, pImageCodecInfo);\n\n\tfor( DWORD j = 0; j < num; ++j) {\n\t\tif(wcscmp(pImageCodecInfo[j].MimeType, format) == 0) {\n\t\t\t*pClsid = pImageCodecInfo[j].Clsid;\n\t\t\tfree(pImageCodecInfo);\n\t\t\treturn j;\n\t\t}\n\t}\n\tfree(pImageCodecInfo);\n\treturn -1;\n}\n\nHBITMAP CreateBitmapFromDC(HDC dc, RECT *rect, LPVOID *lpBits, PALETTEENTRY *pal) {\n\tif( dc == NULL || rect == NULL || lpBits == NULL ) {\n\t\treturn NULL; // wrong parameters\n\t}\n\n\tWORD nBPP = GetDeviceCaps(dc, BITSPIXEL);\n\tint width  = ABS(rect->right  - rect->left);\n\tint height = ABS(rect->bottom - rect->top);\n\n\tHDC hdcDestination = CreateCompatibleDC(dc);\n\tDWORD infoSize = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);\n\tBITMAPINFO *info = (BITMAPINFO *)malloc(infoSize);\n\n\tif( info == NULL ) {\n\t\tDeleteDC(hdcDestination);\n\t\treturn NULL; // failed to create bitmap info\n\t}\n\n\tmemset(info, 0, infoSize);\n\tinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);\n\tinfo->bmiHeader.biWidth = width;\n\tinfo->bmiHeader.biHeight = -height;\n\tinfo->bmiHeader.biPlanes = 1;\n\tinfo->bmiHeader.biBitCount = nBPP;\n\tinfo->bmiHeader.biCompression = BI_RGB;\n\n\tif( pal != NULL ) {\n\t\tfor( int i = 0; i < 256; ++i ) {\n\t\t\tinfo->bmiColors[i].rgbRed   = pal[i].peRed;\n\t\t\tinfo->bmiColors[i].rgbGreen = pal[i].peGreen;\n\t\t\tinfo->bmiColors[i].rgbBlue  = pal[i].peBlue;\n\t\t}\n\t}\n\n\tHBITMAP hbmDestination = CreateDIBSection(dc, info, DIB_RGB_COLORS, lpBits, NULL, 0);\n\tfree(info);\n\n\tif( hbmDestination == NULL ) {\n\t\tDeleteDC(hdcDestination);\n\t\treturn NULL; // failed to create bitmap\n\t}\n\n\tint stateDestination = SaveDC(hdcDestination);\n\tSelectObject(hdcDestination, hbmDestination);\n\tBitBlt(hdcDestination, 0, 0, width, height, dc, rect->left, rect->top, SRCCOPY);\n\tRestoreDC(hdcDestination, stateDestination);\n\tDeleteDC(hdcDestination);\n\n\treturn hbmDestination;\n}\n\nbool __cdecl GDI_Init() {\n\tif( !GDI_Token ) {\n\t\tGdiplusStartupInput gdiplusStartupInput;\n\t\tGdiplusStartup(&GDI_Token, &gdiplusStartupInput, NULL);\n\t}\n\treturn ( GDI_Token != 0 );\n}\n\nvoid __cdecl GDI_Cleanup() {\n\tif( GDI_Token ) {\n\t\tGdiplusShutdown(GDI_Token);\n\t\tGDI_Token = 0;\n\t}\n}\n\nint GDI_SaveImageFile(LPCSTR filename, GDI_FILEFMT format, DWORD quality, HBITMAP hbmBitmap) {\n\tif( filename == NULL || !*filename || hbmBitmap == NULL ) {\n\t\treturn -1; // wrong parameters\n\t}\n\n\tif( format < 0 || format >= ARRAY_SIZE(GDI_Encoders) ) {\n\t\treturn -1; // wrong format\n\t}\n\n\tStatus status = Ok;\n\n\tCLSID imageCLSID;\n\tBitmap *gdi_bitmap = new Bitmap(hbmBitmap, (HPALETTE)NULL);\n\tif( gdi_bitmap == NULL ) {\n\t\treturn -1;\n\t}\n\n\tEncoderParameters encoderParams;\n\tencoderParams.Count = 1;\n\tencoderParams.Parameter[0].NumberOfValues = 1;\n\tencoderParams.Parameter[0].Guid  = EncoderQuality;\n\tencoderParams.Parameter[0].Type  = EncoderParameterValueTypeLong;\n\tencoderParams.Parameter[0].Value = &quality;\n\tGetEncoderClsid(GDI_Encoders[format], &imageCLSID);\n\n#ifdef UNICODE\n\tstatus = gdi_bitmap->Save(filename, &imageCLSID, &encoderParams);\n#else // !UNICODE\n\t{\n\t\tWCHAR wc_fname[MAX_PATH] = {0};\n\t\tif( !MultiByteToWideChar(CP_ACP, 0, filename, strlen(filename), wc_fname, MAX_PATH) ) {\n\t\t\tdelete gdi_bitmap;\n\t\t\treturn -1;\n\t\t}\n\t\tstatus = gdi_bitmap->Save(wc_fname, &imageCLSID, &encoderParams);\n\t}\n#endif // UNICODE\n\n\tdelete gdi_bitmap;\n\treturn ( status == Ok ) ? 0 : -1;\n}\n\n\nint GDI_LoadImageFile(LPCSTR filename, BYTE **bmPtr, DWORD *width, DWORD *height, DWORD bpp) {\n\tif( filename == NULL || !*filename || bmPtr == NULL || width == NULL || height == NULL ) {\n\t\treturn -1; // wrong parameters\n\t}\n\n\tDWORD i;\n\tint result = 0;\n\tDWORD bmSize = 0;\n\tBYTE *src = NULL;\n\tBYTE *dst = NULL;\n\tBitmap *gdi_bitmap = NULL;\n\tBitmapData bmData;\n\tStatus status;\n\tPixelFormat pixelFmt;\n\n\tswitch( bpp ) {\n\t\tcase 32 :\n\t\t\tpixelFmt = PixelFormat32bppARGB;\n\t\t\tbreak;\n\t\tcase 16 :\n\t\t\tpixelFmt = PixelFormat16bppARGB1555;\n\t\t\tbreak;\n\t\tdefault :\n\t\t\t// unsupported pixel format;\n\t\t\treturn -1;\n\t\t\tbreak;\n\t}\n\n#ifdef UNICODE\n\tgdi_bitmap = new Bitmap(filename);\n#else // !UNICODE\n\t{\n\t\tWCHAR wc_fname[MAX_PATH] = {0};\n\t\tif( !MultiByteToWideChar(CP_ACP, 0, filename, strlen(filename), wc_fname, MAX_PATH) ) {\n\t\t\t// failed to get UNICODE filename\n\t\t\tresult = -1;\n\t\t\tgoto CLEANUP;\n\t\t}\n\t\tgdi_bitmap = new Bitmap(wc_fname);\n\t}\n#endif // UNICODE\n\n\tif( gdi_bitmap == NULL ) {\n\t\t// failed to create gdi_bitmap\n\t\tresult = -1;\n\t\tgoto CLEANUP;\n\t}\n\n\t*width = gdi_bitmap->GetWidth();\n\t*height = gdi_bitmap->GetHeight();\n\n\tbmSize = (*width) * (*height) * (bpp/8);\n\t*bmPtr = (BYTE *)malloc(bmSize * (bpp/8));\n\tif( *bmPtr == NULL ) {\n\t\t// failed to allocate output bitmap\n\t\tresult = -1;\n\t\tgoto CLEANUP;\n\t}\n\n\t{ // rect is temporary here\n\t\tRect rect(0, 0, *width, *height);\n\t\tstatus = gdi_bitmap->LockBits(&rect, ImageLockModeRead, pixelFmt, &bmData);\n\t}\n\n\tif( status != Ok ) {\n\t\t// failed to lock the bitmap\n\t\tfree(bmPtr);\n\t\tresult = -1;\n\t\tgoto CLEANUP;\n\t}\n\n\tsrc = (BYTE *)bmData.Scan0;\n\tif( bmData.Stride < 0 ) {\n\t\tsrc += ABS(bmData.Stride) * (*height - 1);\n\t}\n\n\tdst = *bmPtr;\n\tfor( i = 0; i < *height; ++i ) {\n\t\tmemcpy(dst, src, (*width) * (bpp/8));\n\t\tdst += (*width) * (bpp/8);\n\t\tsrc += bmData.Stride;\n\t}\n\n\tgdi_bitmap->UnlockBits(&bmData);\n\nCLEANUP :\n\tif( gdi_bitmap != NULL ) {\n\t\tdelete gdi_bitmap;\n\t\tgdi_bitmap = NULL;\n\t}\n\treturn result;\n}\n"
  },
  {
    "path": "modding/gdi_utils.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef GDI_UTILS_H_INCLUDED\n#define GDI_UTILS_H_INCLUDED\n\n#include \"global/types.h\"\n\ntypedef enum {\n\tGDI_BMP,\n\tGDI_JPG,\n\tGDI_PNG,\n} GDI_FILEFMT;\n\n/*\n * Function list\n */\nHBITMAP CreateBitmapFromDC(HDC dc, RECT *rect, LPVOID *lpBits, PALETTEENTRY *pal);\n\nbool __cdecl GDI_Init();\n\nvoid __cdecl GDI_Cleanup();\n\nint GDI_SaveImageFile(LPCSTR filename, GDI_FILEFMT format, DWORD quality, HBITMAP hbmBitmap);\n\nint GDI_LoadImageBitmap(HBITMAP hbmBitmap, BYTE **bmPtr, DWORD *width, DWORD *height, DWORD bpp);\n\nint GDI_LoadImageFile(LPCSTR filename, BYTE **bmPtr, DWORD *width, DWORD *height, DWORD bpp);\n\n#endif // GDI_UTILS_H_INCLUDED\n"
  },
  {
    "path": "modding/joy_output.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/joy_output.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#define NUM_MOTORS (2)\n#define NUM_VIBS (16)\n\n#define HP_100 (1000)\n#define HP_50 (HP_100/2)\n\n#define AIR_100 (1800)\n#define AIR_75 (AIR_100*3/4)\n#define AIR_50 (AIR_100/2)\n#define AIR_25 (AIR_100/4)\n\nextern void SetJoystickOutput(WORD leftMotor, WORD rightMotor, DWORD ledColor);\nextern bool IsJoyVibrationEnabled();\nextern bool IsJoyLedColorEnabled();\n\ntypedef struct {\n\tint inc, val, sus, dec, len, stage, value;\n} VIBRATION;\n\nstatic VIBRATION Vib[NUM_MOTORS][NUM_VIBS];\nstatic DWORD LedColor = 0;\n\nstatic int BlendLedColor(int c1, int c2) {\n\tif( c1 < c2 ) {\n\t\tc1 += 16;\n\t\tCLAMPG(c1 ,c2);\n\t} else if( c1 > c2 ) {\n\t\tc1 -= 16;\n\t\tCLAMPL(c1 ,c2);\n\t}\n\treturn c1;\n}\n\nstatic void SetupVibration(int motor, int inc, int val, int sus, int dec, int len, bool isCamera) {\n\tint id = 0;\n\tif( !isCamera ) {\n\t\tint id = 1;\n\t\tfor( int i=1; i<NUM_VIBS; ++i ) {\n\t\t\tif( Vib[motor][i].len <= 0 ) {\n\t\t\t\tid = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif( Vib[motor][i].len < Vib[motor][id].len ) {\n\t\t\t\tid = i;\n\t\t\t}\n\t\t}\n\t}\n\tCLAMP(inc, 0, 0xFFFF);\n\tCLAMP(val, 0, 0xFFFF);\n\tCLAMP(dec, 0, 0xFFFF);\n\tVib[motor][id].inc = inc;\n\tVib[motor][id].val = val;\n\tVib[motor][id].sus = len-sus;\n\tVib[motor][id].dec = dec;\n\tVib[motor][id].len = len;\n\tVib[motor][id].stage = 0;\n\tVib[motor][id].value = 0;\n}\n\nvoid JoyOutputReset() {\n\tmemset(Vib, 0, sizeof(Vib));\n\tJoyVibrationMute();\n}\n\nvoid JoyVibrationMute() {\n\tSetJoystickOutput(0, 0, LedColor);\n}\n\nvoid JoyVibrate(int inc, int val, int sus, int dec, int len, bool isCamera) {\n\tSetupVibration(1, inc, val, sus, dec, len, isCamera);\n}\n\nvoid JoyRumble(int inc, int val, int sus, int dec, int len, bool isCamera) {\n\tSetupVibration(0, inc, val, sus, dec, len, isCamera);\n}\n\nvoid JoyRumbleExplode(int x, int y, int z, DWORD range, bool fromLara) {\n\tx -= fromLara ? LaraItem->pos.x : Camera.pos.x;\n\ty -= fromLara ? LaraItem->pos.y : Camera.pos.y;\n\tz -= fromLara ? LaraItem->pos.z : Camera.pos.z;\n\tDWORD dist = SQR(x) + SQR(y) + SQR(z);\n\tif( dist < SQR(range) ) {\n\t\t// it is intended to be non-linear\n\t\tdist = 0xFFFF - (UINT64)dist*0xFFFF/SQR(range);\n\t\tJoyRumble(dist/8, dist, 20, dist/32, 40, false);\n\t}\n}\n\nvoid UpdateJoyOutput(bool isInGame) {\n\tWORD motor[2] = {0, 0};\n\tfor( int i=0; i<NUM_MOTORS; ++i ) {\n\t\tfor( int j=0; j<NUM_VIBS; ++j ) {\n\t\t\tif( !IsJoyVibrationEnabled() || !isInGame || Vib[i][j].len <= 0 ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tswitch( Vib[i][j].stage ) {\n\t\t\tcase 0:\n\t\t\t\tVib[i][j].value += Vib[i][j].inc;\n\t\t\t\tif( Vib[i][j].value < Vib[i][j].val ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tVib[i][j].value = Vib[i][j].val;\n\t\t\t\tVib[i][j].stage = 1;\n\t\t\t\t// fall through\n\t\t\tcase 1:\n\t\t\t\tif( Vib[i][j].len > Vib[i][j].sus) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tVib[i][j].stage = 2;\n\t\t\t\t// fall through\n\t\t\tcase 2:\n\t\t\t\tVib[i][j].value -= Vib[i][j].dec;\n\t\t\t\tif( Vib[i][j].value > 0 ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tVib[i][j].value = 0;\n\t\t\t\tVib[i][j].stage = 3;\n\t\t\t\t// fall through\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tCLAMP(Vib[i][j].value, 0, 0xFFFF);\n\t\t\tCLAMPL(motor[i], Vib[i][j].value);\n\t\t\t--Vib[i][j].len;\n\t\t}\n\t}\n\n\tint r=0, g=0, b=0;\n\tbool isInjured = false;\n\tif( !IsJoyLedColorEnabled() || !isInGame || LaraItem == NULL ) {\n\t\tr = RGB_GETRED  (DEFAULT_JOYSTICK_LED_COLOR);\n\t\tg = RGB_GETGREEN(DEFAULT_JOYSTICK_LED_COLOR);\n\t\tb = RGB_GETBLUE (DEFAULT_JOYSTICK_LED_COLOR);\n\t} else {\n\t\tstatic __int16 hitPoints = 0;\n\t\tisInjured = (LaraItem->hitPoints < hitPoints && Lara.air > 0);\n\t\thitPoints = LaraItem->hitPoints;\n\t\tif( isInjured ) {\n\t\t\tr = 255;\n\t\t\tif( hitPoints > HP_50 ) {\n\t\t\t\tg = 255 * (hitPoints - HP_50) / HP_50;\n\t\t\t}\n\t\t} else {\n\t\t\tif( Lara.water_status == LWS_Underwater ) {\n\t\t\t\tif( hitPoints > 0 && Lara.air > 0 ) {\n\t\t\t\t\tif( Lara.air > AIR_75 ) {\n\t\t\t\t\t\tg = 255;\n\t\t\t\t\t\tb = 128 + 127 * (AIR_100 - Lara.air) / AIR_25;\n\t\t\t\t\t} else if( Lara.air > AIR_25 ) {\n\t\t\t\t\t\tg = 255 * (Lara.air - AIR_25) / AIR_50;\n\t\t\t\t\t\tb = 255;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tr = 127 * (AIR_25 - Lara.air) / AIR_25;\n\t\t\t\t\t\tb = 255;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tr = 128 + 127 * (HP_100 - hitPoints) / HP_100;\n\t\t\t\t\tb = 255 * hitPoints / HP_100;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif( hitPoints > HP_50 ) {\n\t\t\t\t\tr = 255 * (HP_100 - hitPoints) / HP_50;\n\t\t\t\t\tg = 255;\n\t\t\t\t} else {\n\t\t\t\t\tr = 255;\n\t\t\t\t\tg = 255 * hitPoints / HP_50;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif( hitPoints > 0 && Lara.air > 0 && Lara.gun_status != LGS_Ready ) {\n\t\t\t\tr /= 3;\n\t\t\t\tg /= 3;\n\t\t\t\tb /= 3;\n\t\t\t} else {\n\t\t\t\tr = r*2/3;\n\t\t\t\tg = g*2/3;\n\t\t\t\tb = b*2/3;\n\t\t\t}\n\t\t}\n\t}\n\tif( isInjured ) {\n\t\tLedColor = RGB_MAKE(r, g, b);\n\t} else if( LedColor != RGB_MAKE(r, g, b) ) {\n\t\tr = BlendLedColor(RGB_GETRED(LedColor), r);\n\t\tg = BlendLedColor(RGB_GETGREEN(LedColor), g);\n\t\tb = BlendLedColor(RGB_GETBLUE(LedColor), b);\n\t\tLedColor = RGB_MAKE(r, g, b);\n\t}\n\n\tSetJoystickOutput(motor[0], motor[1], LedColor);\n}\n\n#endif // FEATURE_INPUT_IMPROVED\n"
  },
  {
    "path": "modding/joy_output.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef JOY_OUTPUT_H_INCLUDED\n#define JOY_OUTPUT_H_INCLUDED\n\n#include \"global/types.h\"\n#define DEFAULT_JOYSTICK_LED_COLOR (0x303030)\n\n/*\n * Function list\n */\nvoid JoyOutputReset();\nvoid JoyVibrationMute();\nvoid JoyVibrate(int acc, int lev, int sus, int dec, int len, bool isCamera);\nvoid JoyRumble(int acc, int lev, int sus, int dec, int len, bool isCamera);\nvoid JoyRumbleExplode(int x, int y, int z, DWORD range, bool fromLara);\nvoid UpdateJoyOutput(bool isInGame);\n\n#endif // JOY_OUTPUT_H_INCLUDED\n"
  },
  {
    "path": "modding/json_utils.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/json_utils.h\"\n#include \"global/vars.h\"\n\njson_value *GetJsonField(json_value *root, json_type fieldType, const char *name, DWORD *pIndex) {\n\tif( root == NULL || root->type != json_object ) {\n\t\treturn NULL;\n\t}\n\tjson_value *result = NULL;\n\tDWORD len = name ? strlen(name) : 0;\n\tDWORD i = pIndex ? *pIndex : 0;\n\tfor( ; i < root->u.object.length; ++i ) {\n\t\tif( root->u.object.values[i].value->type == fieldType ) {\n\t\t\tif( !name || (len == root->u.object.values[i].name_length\n\t\t\t\t&& !strncmp(root->u.object.values[i].name, name, len)) )\n\t\t\t{\n\t\t\t\tresult = root->u.object.values[i].value;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif( pIndex ) *pIndex = i;\n\treturn result;\n}\n\njson_value *GetJsonObjectByStringField(json_value *root, const char *name, const char *str, bool caseSensitive, DWORD *pIndex) {\n\tif( root == NULL || root->type != json_array || !name || !*name || !str ) {\n\t\treturn NULL;\n\t}\n\tjson_value *result = NULL;\n\tDWORD len = strlen(str);\n\tDWORD i = pIndex ? *pIndex : 0;\n\tfor( ; i < root->u.array.length; ++i ) {\n\t\tjson_value *key = GetJsonField(root->u.array.values[i], json_string, name, NULL);\n\t\tif( key && len == key->u.string.length &&\n\t\t\t(caseSensitive ? strncmp(key->u.string.ptr, str, len) : !strncasecmp(key->u.string.ptr, str, len)) )\n\t\t{\n\t\t\tresult = root->u.array.values[i];\n\t\t\tbreak;\n\t\t}\n\t}\n\tif( pIndex ) *pIndex = i;\n\treturn result;\n}\n\nint GetJsonIntegerFieldValue(json_value *root, const char *name, int defaultValue) {\n\tjson_value *field = GetJsonField(root, json_integer, name, NULL);\n\treturn field ? field->u.integer : defaultValue;\n}\n\ndouble GetJsonFloatFieldValue(json_value *root, const char *name, double defaultValue) {\n\tjson_value *field = GetJsonField(root, json_double, name, NULL);\n\treturn field ? field->u.dbl : defaultValue;\n}\n"
  },
  {
    "path": "modding/json_utils.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef JSON_UTILS_H_INCLUDED\n#define JSON_UTILS_H_INCLUDED\n\n#include \"global/types.h\"\n#include \"json-parser/json.h\"\n\njson_value *GetJsonField(json_value *root, json_type fieldType, const char *name, DWORD *pIndex);\njson_value *GetJsonObjectByStringField(json_value *root, const char *name, const char *str, bool caseSensitive, DWORD *pIndex);\nint GetJsonIntegerFieldValue(json_value *root, const char *name, int defaultValue);\ndouble GetJsonFloatFieldValue(json_value *root, const char *name, double defaultValue);\n\n#endif // JSON_UTILS_H_INCLUDED\n"
  },
  {
    "path": "modding/mod_utils.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/mod_utils.h\"\n#include \"modding/json_utils.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_MOD_CONFIG\n#define MOD_CONFIG_NAME \"TR2Main.json\"\n\ntypedef struct {\n\tbool isLoaded;\n\tPOLYINDEX *animtex;\n\tPOLYFILTER_NODE *rooms;\n\tPOLYFILTER_NODE *statics;\n\tPOLYFILTER_NODE *objects[ID_NUMBER_OBJECTS];\n} SEMITRANS_CONFIG;\n\ntypedef struct {\n\tbool isLoaded;\n\tPOLYFILTER_NODE *statics;\n\tPOLYFILTER_NODE *objects[ID_NUMBER_OBJECTS];\n} REFLECT_CONFIG;\n\ntypedef struct {\n\tbool isLoaded;\n\tbool isBarefoot;\n\tchar loadingPix[256];\n\tDWORD waterColor;\n\tSEMITRANS_CONFIG semitrans;\n\tREFLECT_CONFIG reflect;\n} MOD_CONFIG;\n\nstatic MOD_CONFIG ModConfig;\n\nstatic POLYFILTER *CreatePolyfilterNode(POLYFILTER_NODE **root, int id) {\n\tif( root == NULL ) return NULL;\n\tPOLYFILTER_NODE *node = (POLYFILTER_NODE *)malloc(sizeof(POLYFILTER_NODE));\n\tif( node == NULL ) return NULL;\n\tnode->id = id;\n\tnode->next = *root;\n\tmemset(&node->filter, 0, sizeof(node->filter));\n\t*root = node;\n\treturn &node->filter;\n}\n\nstatic void FreePolyfilterNodes(POLYFILTER_NODE **root) {\n\tif( root == NULL ) return;\n\tPOLYFILTER_NODE *node = *root;\n\twhile( node ) {\n\t\tPOLYFILTER_NODE *next = node->next;\n\t\tfree(node);\n\t\tnode = next;\n\t}\n\t*root = NULL;\n}\n#endif // FEATURE_MOD_CONFIG\n\nstatic bool IsCompatibleFilter(__int16 *ptrObj, bool isRoomMesh, POLYFILTER *filter) {\n\tif( !ptrObj || !filter || !filter->n_vtx ) return true;\n\tif( !isRoomMesh ) {\n\t\tptrObj += 5; // skip x, y, z, radius, flags\n\t}\n\t__int16 num = *(ptrObj++); // get vertex counter\n\tif( num != filter->n_vtx ) return false;\n\tptrObj += num * (isRoomMesh ? 6 : 3); // skip vertices\n\tif( !isRoomMesh ) {\n\t\tnum = *(ptrObj++); // get normal counter\n\t\tptrObj += (num > 0) ? num * 3 : ABS(num); // skip normals/shades\n\t}\n\tnum = *(ptrObj++); // get gt4 number\n\tif( num != filter->n_gt4 ) return false;\n\tptrObj += num * 5; // skip gt4 polys\n\tnum = *(ptrObj++); // get gt3 number\n\tif( num != filter->n_gt3 ) return false;\n\tif( !isRoomMesh ) {\n\t\tptrObj += num * 4; // skip gt3 polys\n\t\tnum = *(ptrObj++); // get g4 number\n\t\tif( num != filter->n_g4 ) return false;\n\t\tptrObj += num * 5; // skip g4 polys\n\t\tnum = *(ptrObj++); // get g3 number\n\t\tif( num != filter->n_g3 ) return false;\n\t}\n\treturn true;\n}\n\nstatic __int16 *EnumeratePolysSpecific(__int16 *ptrObj, int vtxCount, bool colored, ENUM_POLYS_CB callback, POLYINDEX *filter, LPVOID param) {\n\tint polyNumber = *ptrObj++;\n\tif( filter == NULL || (!filter[0].idx && !filter[0].num) ) {\n\t\tfor( int i = 0; i < polyNumber; ++i ) {\n\t\t\tif( !callback(ptrObj, vtxCount, colored, param) ) return NULL;\n\t\t\tptrObj += vtxCount + 1;\n\t\t}\n\t} else {\n\t\tint polyIndex = 0;\n\t\tfor( int i=0; i<POLYFILTER_SIZE; i++ ) {\n\t\t\tif( filter[i].idx < polyIndex || filter[i].idx >= polyNumber ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint skip = filter[i].idx - polyIndex;\n\t\t\tif( skip > 0 ) {\n\t\t\t\tptrObj += skip*(vtxCount+1);\n\t\t\t\tpolyIndex += skip;\n\t\t\t}\n\t\t\tint number = MIN(filter[i].num, polyNumber - polyIndex);\n\t\t\tfor( int j = 0; j < number; ++j ) {\n\t\t\t\tif( !callback(ptrObj, vtxCount, colored, param) ) return NULL;\n\t\t\t\tptrObj += vtxCount + 1;\n\t\t\t}\n\t\t\tpolyIndex += number;\n\t\t}\n\t\tptrObj += (polyNumber-polyIndex)*(vtxCount+1);\n\t}\n\treturn ptrObj;\n}\n\nbool EnumeratePolys(__int16 *ptrObj, bool isRoomMesh, ENUM_POLYS_CB callback, POLYFILTER *filter, LPVOID param) {\n\tif( ptrObj == NULL || callback == NULL ) return false; // wrong parameters\n\tif( !IsCompatibleFilter(ptrObj, isRoomMesh, filter) ) return false; // filter is not compatible\n\n\t__int16 num;\n\tif( !isRoomMesh ) {\n\t\tptrObj += 5; // skip x, y, z, radius, flags\n\t}\n\tnum = *(ptrObj++); // get vertex counter\n\tptrObj += num * (isRoomMesh ? 6 : 3); // skip vertices\n\tif( !isRoomMesh ) {\n\t\tnum = *(ptrObj++); // get normal counter\n\t\tptrObj += (num > 0) ? num * 3 : ABS(num); // skip normals/shades\n\t}\n\tptrObj = EnumeratePolysSpecific(ptrObj, 4, false, callback, filter ? filter->gt4 : NULL, param); // enumerate textured quads\n\tif( ptrObj == NULL ) return true;\n\tptrObj = EnumeratePolysSpecific(ptrObj, 3, false, callback, filter ? filter->gt3 : NULL, param); // enumerate textured triangles\n\tif( !isRoomMesh ) {\n\t\tif( ptrObj == NULL ) return true;\n\t\tptrObj = EnumeratePolysSpecific(ptrObj, 4, true, callback, filter ? filter->g4 : NULL, param); // enumerate colored quads\n\t\tif( ptrObj == NULL ) return true;\n\t\tptrObj = EnumeratePolysSpecific(ptrObj, 3, true, callback, filter ? filter->g3 : NULL, param); // enumerate colored triangles\n\t}\n\treturn true;\n}\n\n#ifdef FEATURE_MOD_CONFIG\nbool IsModConfigLoaded() {\n\treturn ModConfig.isLoaded;\n}\n\nbool IsModBarefoot() {\n\treturn ModConfig.isBarefoot;\n}\n\nconst char *GetModLoadingPix() {\n\treturn *ModConfig.loadingPix ? ModConfig.loadingPix : NULL;\n}\n\nDWORD GetModWaterColor() {\n\treturn ModConfig.waterColor;\n}\n\nbool IsModSemitransConfigLoaded() {\n\treturn ModConfig.semitrans.isLoaded;\n}\n\nPOLYINDEX *GetModSemitransAnimtexFilter() {\n\treturn ModConfig.semitrans.animtex;\n}\n\nPOLYFILTER_NODE *GetModSemitransRoomsFilter() {\n\treturn ModConfig.semitrans.rooms;\n}\n\nPOLYFILTER_NODE *GetModSemitransStaticsFilter() {\n\treturn ModConfig.semitrans.statics;\n}\n\nPOLYFILTER_NODE **GetModSemitransObjectsFilter() {\n\treturn ModConfig.semitrans.objects;\n}\n\nbool IsModReflectConfigLoaded() {\n\treturn ModConfig.reflect.isLoaded;\n}\n\nPOLYFILTER_NODE *GetModReflectStaticsFilter() {\n\treturn ModConfig.reflect.statics;\n}\n\nPOLYFILTER_NODE **GetModReflectObjectsFilter() {\n\treturn ModConfig.reflect.objects;\n}\n\nstatic int ParsePolyString(const char *str, POLYINDEX *lst, DWORD lstLen){\n\tif( !lst || !lstLen ) {\n\t\treturn -1;\n\t}\n\n\tlst[0].idx = ~0;\n\tlst[0].num = ~0;\n\n\tPOLYINDEX *lstBuf = (POLYINDEX *)malloc(lstLen * sizeof(POLYINDEX));\n\tif( lstBuf == NULL ) {\n\t\treturn -2;\n\t}\n\n\tchar *strBuf = strdup(str);\n\tif( strBuf == NULL ) {\n\t\tfree(lstBuf);\n\t\treturn -2;\n\t}\n\n\tDWORD bufLen = 0;\n\tchar *token = strtok(strBuf, \",\");\n\twhile( token != NULL ) {\n\t\tchar *range = strchr(token, '-');\n\t\tif( range ) {\n\t\t\tint from = atoi(token);\n\t\t\tint to = atoi(range + 1);\n\t\t\tlstBuf[bufLen].idx = MIN(to, from);\n\t\t\tlstBuf[bufLen].num = ABS(to - from) + 1;\n\t\t} else {\n\t\t\tlstBuf[bufLen].idx = atoi(token);\n\t\t\tlstBuf[bufLen].num = 1;\n\t\t}\n\t\tif( ++bufLen >= lstLen ) {\n\t\t\tbreak;\n\t\t}\n\t\ttoken = strtok(NULL, \",\");\n\t}\n\n\tfree(strBuf);\n\tif( !bufLen ) {\n\t\tfree(lstBuf);\n\t\treturn 0;\n\t}\n\n\tfor( DWORD i = 0; i < bufLen-1; ++i ) {\n\t\tfor( DWORD j = i+1; j < bufLen; ++j ) {\n\t\t\tif( lstBuf[i].idx > lstBuf[j].idx ) {\n\t\t\t\tPOLYINDEX t;\n\t\t\t\tSWAP(lstBuf[i], lstBuf[j], t);\n\t\t\t}\n\t\t}\n\t}\n\n\tlst[0] = lstBuf[0];\n\tDWORD resLen = 1;\n\n\tfor( DWORD i = 1; i < bufLen; ++i ) {\n\t\tint bound = lst[resLen-1].idx + lst[resLen-1].num;\n\t\tif( lstBuf[i].idx > bound ) {\n\t\t\tlst[resLen] = lstBuf[i];\n\t\t\t++resLen;\n\t\t} else {\n\t\t\tint ext = lstBuf[i].idx + lstBuf[i].num;\n\t\t\tif( ext > bound ) {\n\t\t\t\tlst[resLen-1].num += ext - bound;\n\t\t\t}\n\t\t}\n\t}\n\tif( resLen < lstLen ) {\n\t\tlst[resLen].idx = 0;\n\t\tlst[resLen].num = 0;\n\t}\n\n\tfree(lstBuf);\n\treturn resLen;\n}\n\nstatic int ParsePolyValue(json_value *value, POLYINDEX *lst, DWORD lstLen) {\n\tif( !lst || !lstLen ) {\n\t\treturn -1;\n\t}\n\n\tlst[0].idx = ~0;\n\tlst[0].num = ~0;\n\tif( value == NULL ) {\n\t\treturn 0;\n\t}\n\n\tconst char *str = value->u.string.ptr;\n\tif( !str || !*str || !strcasecmp(str, \"none\") ) {\n\t\treturn 0;\n\t}\n\tif( !strcasecmp(str, \"all\") ) {\n\t\tlst[0].idx = 0;\n\t\tlst[0].num = 0;\n\t\treturn 1;\n\t}\n\treturn ParsePolyString(str, lst, lstLen);\n}\n\nstatic bool ParsePolyfilterConfiguration(json_value *root, const char *name, POLYFILTER_NODE **pNodes) {\n\tFreePolyfilterNodes(pNodes);\n\tif( root == NULL || root->type != json_array || !name || !*name ) {\n\t\treturn false;\n\t}\n\tfor( DWORD i = 0; i < root->u.array.length; ++i ) {\n\t\tjson_value *item = root->u.array.values[i];\n\t\tjson_value *field = GetJsonField(item, json_integer, name, NULL);\n\t\tif( !field || field->u.integer < 0 ) continue;\n\t\tPOLYFILTER *filter = CreatePolyfilterNode(pNodes, field->u.integer);\n\t\tif( !filter ) continue;\n\t\tfield = GetJsonField(item, json_object, \"filter\", NULL);\n\t\tif( field ) {\n\t\t\tfilter->n_vtx = GetJsonIntegerFieldValue(field, \"v\",  0);\n\t\t\tfilter->n_gt4 = GetJsonIntegerFieldValue(field, \"t4\", 0);\n\t\t\tfilter->n_gt3 = GetJsonIntegerFieldValue(field, \"t3\", 0);\n\t\t\tfilter->n_g4  = GetJsonIntegerFieldValue(field, \"c4\", 0);\n\t\t\tfilter->n_g3  = GetJsonIntegerFieldValue(field, \"c3\", 0);\n\t\t}\n\t\tjson_value *t4list = GetJsonField(item, json_string, \"t4list\", NULL);\n\t\tjson_value *t3list = GetJsonField(item, json_string, \"t3list\", NULL);\n\t\tjson_value *c4list = GetJsonField(item, json_string, \"c4list\", NULL);\n\t\tjson_value *c3list = GetJsonField(item, json_string, \"c3list\", NULL);\n\t\t// If no lists presented, consider that lists set to \"all\"\n\t\tif( t4list || t3list || c4list || c3list ) {\n\t\t\tParsePolyValue(t4list, filter->gt4, ARRAY_SIZE(filter->gt4));\n\t\t\tParsePolyValue(t3list, filter->gt3, ARRAY_SIZE(filter->gt3));\n\t\t\tParsePolyValue(c4list, filter->g4,  ARRAY_SIZE(filter->g4));\n\t\t\tParsePolyValue(c3list, filter->g3,  ARRAY_SIZE(filter->g3));\n\t\t}\n\t}\n\treturn true;\n}\n\nstatic bool ParseSemitransConfiguration(json_value *root) {\n\tif( root == NULL || root->type != json_object ) {\n\t\treturn false;\n\t}\n\tjson_value* field = NULL;\n\n\tfield = GetJsonField(root, json_string, \"animtex\", NULL);\n\tif( field ) {\n\t\tif( ModConfig.semitrans.animtex ) {\n\t\t\tfree(ModConfig.semitrans.animtex);\n\t\t\tModConfig.semitrans.animtex = NULL;\n\t\t}\n\t\tif( strcasecmp(field->u.string.ptr, \"auto\") ) {\n\t\t\tModConfig.semitrans.animtex = (POLYINDEX *)malloc(sizeof(POLYINDEX) * POLYFILTER_SIZE);\n\t\t\tif( ModConfig.semitrans.animtex ) {\n\t\t\t\tParsePolyValue(field, ModConfig.semitrans.animtex, POLYFILTER_SIZE);\n\t\t\t}\n\t\t}\n\t}\n\tjson_value* objects = GetJsonField(root, json_array, \"objects\", NULL);\n\tif( objects ) {\n\t\tfor( DWORD i = 0; i < objects->u.array.length; ++i ) {\n\t\t\tjson_value *object = objects->u.array.values[i];\n\t\t\tfield = GetJsonField(object, json_integer, \"object\", NULL);\n\t\t\tif( !field || field->u.integer < 0 || field->u.integer >= ARRAY_SIZE(ModConfig.semitrans.objects) ) continue;\n\t\t\tParsePolyfilterConfiguration(GetJsonField(object, json_array, \"meshes\", NULL), \"mesh\", &ModConfig.semitrans.objects[field->u.integer]);\n\t\t}\n\t}\n\tParsePolyfilterConfiguration(GetJsonField(root, json_array, \"statics\", NULL), \"static\", &ModConfig.semitrans.statics);\n\tParsePolyfilterConfiguration(GetJsonField(root, json_array, \"rooms\", NULL), \"room\", &ModConfig.semitrans.rooms);\n\tModConfig.semitrans.isLoaded = true;\n\treturn true;\n}\n\nstatic bool ParseReflectConfiguration(json_value *root) {\n\tif( root == NULL || root->type != json_object ) {\n\t\treturn false;\n\t}\n\tjson_value* field = NULL;\n\n\tjson_value* objects = GetJsonField(root, json_array, \"objects\", NULL);\n\tif( objects ) {\n\t\tfor( DWORD i = 0; i < objects->u.array.length; ++i ) {\n\t\t\tjson_value *object = objects->u.array.values[i];\n\t\t\tfield = GetJsonField(object, json_integer, \"object\", NULL);\n\t\t\tif( !field || field->u.integer < 0 || field->u.integer >= ARRAY_SIZE(ModConfig.reflect.objects) ) continue;\n\t\t\tParsePolyfilterConfiguration(GetJsonField(object, json_array, \"meshes\", NULL), \"mesh\", &ModConfig.reflect.objects[field->u.integer]);\n\t\t}\n\t}\n\tParsePolyfilterConfiguration(GetJsonField(root, json_array, \"statics\", NULL), \"static\", &ModConfig.reflect.statics);\n\tModConfig.reflect.isLoaded = true;\n\treturn true;\n}\n\nstatic bool ParseLevelConfiguration(json_value *root) {\n\tif( root == NULL || root->type != json_object ) {\n\t\treturn false;\n\t}\n\tjson_value* field = NULL;\n\n\tfield = GetJsonField(root, json_string, \"picture\", NULL);\n\tif( field ) {\n\t\tsnprintf(ModConfig.loadingPix, sizeof(ModConfig.loadingPix), \"data\\\\%.*s.pcx\", field->u.string.length, field->u.string.ptr);\n\t}\n\tfield = GetJsonField(root, json_string, \"watercolor\", NULL);\n\tif( field && field->u.string.length == 6 ) {\n\t\tModConfig.waterColor = strtol(field->u.string.ptr, NULL, 16);\n\t}\n\tfield = GetJsonField(root, json_boolean, \"barefoot\", NULL);\n\tif( field ) {\n\t\tModConfig.isBarefoot = field->u.boolean;\n\t}\n\tParseSemitransConfiguration(GetJsonField(root, json_object, \"semitransparent\", NULL));\n\tParseReflectConfiguration(GetJsonField(root, json_object, \"reflective\", NULL));\n\treturn true;\n}\n\nstatic bool ParseModConfiguration(char *levelName, json_value *root) {\n\tif( root == NULL || root->type != json_object ) {\n\t\treturn false;\n\t}\n\t// parsing default configs\n\tParseLevelConfiguration(GetJsonField(root, json_object, \"default\", NULL));\n\t// parsing level specific configs\n\tjson_value* levels = GetJsonField(root, json_array, \"levels\", NULL);\n\tif( levels ) ParseLevelConfiguration(GetJsonObjectByStringField(levels, \"filename\", levelName, false, NULL));\n\treturn true;\n}\n\nvoid UnloadModConfiguration() {\n\tif( ModConfig.semitrans.animtex ) {\n\t\tfree(ModConfig.semitrans.animtex);\n\t\tModConfig.semitrans.animtex = NULL;\n\t}\n\tFreePolyfilterNodes(&ModConfig.semitrans.rooms);\n\tFreePolyfilterNodes(&ModConfig.semitrans.statics);\n\tFreePolyfilterNodes(&ModConfig.reflect.statics);\n\tfor( DWORD i=0; i<ARRAY_SIZE(ModConfig.semitrans.objects); ++i ) {\n\t\tFreePolyfilterNodes(&ModConfig.semitrans.objects[i]);\n\t\tFreePolyfilterNodes(&ModConfig.reflect.objects[i]);\n\t}\n\tmemset(&ModConfig, 0, sizeof(ModConfig));\n}\n\nbool LoadModConfiguration(LPCTSTR levelFilePath) {\n\tUnloadModConfiguration();\n\tif( !PathFileExists(MOD_CONFIG_NAME) ) {\n\t\treturn false;\n\t}\n\tchar levelName[256] = {0};\n\tstrncpy(levelName, PathFindFileName(levelFilePath), sizeof(levelName)-1);\n\tchar *ext = PathFindExtension(levelName);\n\tif( ext != NULL ) *ext = 0;\n\n\tDWORD bytesRead = 0;\n\tHANDLE hFile = CreateFile(MOD_CONFIG_NAME, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN|FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile == INVALID_HANDLE_VALUE ) {\n\t\treturn false;\n\t}\n\tDWORD cfgSize = GetFileSize(hFile, NULL);\n\tvoid *cfgData = malloc(cfgSize);\n\tReadFile(hFile, cfgData, cfgSize, &bytesRead, NULL);\n\tCloseHandle(hFile);\n\n\tjson_value* json = json_parse((const json_char *)cfgData, cfgSize);\n\tif( json != NULL ) {\n\t\tModConfig.isLoaded = ParseModConfiguration(levelName, json);\n\t}\n\tjson_value_free(json);\n\tfree(cfgData);\n\treturn ModConfig.isLoaded;\n}\n#endif // FEATURE_MOD_CONFIG\n"
  },
  {
    "path": "modding/mod_utils.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef MOD_UTILS_H_INCLUDED\n#define MOD_UTILS_H_INCLUDED\n\n#include \"global/types.h\"\n\n// Filter is presented by an array of poly index and polys number (starting from the index).\n// The filter must be always terminated by an index 0.\n// If the first item has index=~0 then there are no polys of such type to process.\n// If the first item has index=0 and number=0 then all polys of such type must be processed.\n#define POLYFILTER_SIZE 256\n\ntypedef struct {__int16 idx; __int16 num;} POLYINDEX;\n\ntypedef struct {\n\t__int16 n_vtx, n_gt4, n_gt3, n_g4, n_g3;\n\tPOLYINDEX gt4[POLYFILTER_SIZE];\n\tPOLYINDEX gt3[POLYFILTER_SIZE];\n\tPOLYINDEX g4[POLYFILTER_SIZE];\n\tPOLYINDEX g3[POLYFILTER_SIZE];\n} POLYFILTER;\n\ntypedef struct PolyfilterNode_t {\n\tint id;\n\tPOLYFILTER filter;\n\tstruct PolyfilterNode_t *next;\n} POLYFILTER_NODE;\n\ntypedef bool (*ENUM_POLYS_CB) (__int16 *ptrObj, int vtxCount, bool colored, LPVOID param);\n\n/*\n * Function list\n */\nbool EnumeratePolys(__int16 *ptrObj, bool isRoomMesh, ENUM_POLYS_CB callback, POLYFILTER *filter, LPVOID param);\n\n#ifdef FEATURE_MOD_CONFIG\nbool IsModConfigLoaded();\nbool IsModBarefoot();\nconst char *GetModLoadingPix();\nDWORD GetModWaterColor();\nbool IsModSemitransConfigLoaded();\nPOLYINDEX *GetModSemitransAnimtexFilter();\nPOLYFILTER_NODE *GetModSemitransRoomsFilter();\nPOLYFILTER_NODE *GetModSemitransStaticsFilter();\nPOLYFILTER_NODE **GetModSemitransObjectsFilter();\nbool IsModReflectConfigLoaded();\nPOLYFILTER_NODE *GetModReflectStaticsFilter();\nPOLYFILTER_NODE **GetModReflectObjectsFilter();\n\nvoid UnloadModConfiguration();\nbool LoadModConfiguration(LPCTSTR levelFilePath);\n#endif // FEATURE_MOD_CONFIG\n\n#endif // MOD_UTILS_H_INCLUDED\n"
  },
  {
    "path": "modding/pause.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/pause.h\"\n#include \"game/health.h\"\n#include \"game/inventory.h\"\n#include \"game/invtext.h\"\n#include \"game/sound.h\"\n#include \"game/text.h\"\n#include \"specific/display.h\"\n#include \"specific/input.h\"\n#include \"specific/output.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\nstatic TEXT_STR_INFO *PausedText = NULL;\n\nstatic void RemovePausedText() {\n\tT_RemovePrint(PausedText);\n\tPausedText = NULL;\n}\n\nstatic void DisplayPausedText() {\n\tif( PausedText == NULL ) {\n\t\tPausedText = T_Print(0, -24, 5, \"Paused\");\n\t\tT_CentreH(PausedText, 1);\n\t\tT_BottomAlign(PausedText, 1);\n\t}\n}\n\nstatic int DisplayPauseRequester(const char *header, const char *option1, const char *option2, UINT16 selected) {\n\tstatic bool isPauseTextReady = false;\n\tif( !isPauseTextReady ) {\n\t\tStatsRequester.reqFlags &= ~REQFLAG_NOCURSOR;\n\t\tSetPCRequesterSize(&StatsRequester, 2, -48);\n\n\t\tStatsRequester.lineHeight = 18;\n\t\tStatsRequester.itemsCount = 0;\n\t\tStatsRequester.selected = selected;\n\t\tStatsRequester.lineOffset = 0;\n\t\tStatsRequester.lineOldOffset = 0;\n\t\tStatsRequester.pixWidth = 100;\n\t\tStatsRequester.xPos = 0;\n\t\tStatsRequester.zPos = 0;\n\t\tStatsRequester.lpItemStrings1 = (char *)SaveGameStrings1;\n\t\tStatsRequester.lpItemStrings2 = (char *)SaveGameStrings2;\n\t\tStatsRequester.itemStringLen = 50;\n\n\t\tInit_Requester(&StatsRequester);\n\t\tSetRequesterHeading(&StatsRequester, header, 0, NULL, 0);\n\n\t\tmemset(SaveGameStrings1, 0, sizeof(SaveGameStrings1));\n\t\tmemset(SaveGameStrings2, 0, sizeof(SaveGameStrings2));\n\t\tAddRequesterItem(&StatsRequester, option1, 0, NULL, 0);\n\t\tAddRequesterItem(&StatsRequester, option2, 0, NULL, 0);\n\n\t\tisPauseTextReady = true;\n\t\tInputDB = 0;\n\t\tInputStatus = 0;\n\t}\n\n\tint select = Display_Requester(&StatsRequester, 0, 0);\n\tif( select > 0 ) {\n\t\tisPauseTextReady = false;\n\t} else {\n\t\tInputDB = 0;\n\t\tInputStatus = 0;\n\t}\n\treturn select;\n}\n\nstatic int PauseRequester() {\n\tstatic int state = 0;\n\tint select = 0;\n\n\tInputDB = GetDebouncedInput(InputStatus);\n\tswitch( state ) {\n\t\tcase 0:\n\t\t\tif( CHK_ANY(InputDB, IN_PAUSE) ) {\n\t\t\t\tselect = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif( CHK_ANY(InputDB, IN_OPTION) ) {\n\t\t\t\tstate = 1;\n\t\t\t}\n\t\t\tif( state != 1 ) break;\n\t\t\t// fall through\n\t\tcase 1:\n\t\t\tswitch( DisplayPauseRequester(CHK_ANY(GF_GameFlow.flags, GFF_DemoVersion)? \"Exit Demo?\" : \"Exit to title?\", \"Continue\", \"Quit\", 0) ) {\n\t\t\t\tcase 1: select = 1; break;\n\t\t\t\tcase 2: state = 2; break;\n\t\t\t};\n\t\t\tif( state != 2 ) break;\n\t\t\t// fall through\n\t\tcase 2:\n\t\t\tswitch( DisplayPauseRequester(\"Are you sure?\", \"Yes\", \"No\", 1) ) {\n\t\t\t\tcase 1: select = -1; break;\n\t\t\t\tcase 2: select = 1; break;\n\t\t\t};\n\t\t\tbreak;\n\t}\n\tif( select ) state = 0;\n\treturn select;\n}\n\nbool S_Pause() {\n\tint oldOverlayStatus = OverlayStatus;\n\tOverlayStatus = -3;\n\tInventoryMode = INV_PauseMode;\n\tT_RemovePrint(AmmoTextInfo);\n\tAmmoTextInfo = NULL;\n\tS_FadeInInventory(TRUE);\n\tSOUND_Stop();\n\tS_CDVolume(0);\n\tTempVideoAdjust(HiRes, 1.0);\n\tIsVidModeLock = true;\n\tS_SetupAboveWater(FALSE);\n\n\tint select = 0;\n\tdo {\n\t\tS_InitialisePolyList(FALSE);\n\t\tDoInventoryBackground();\n\t\tDisplayPausedText();\n\t\tDrawModeInfo();\n\t\tT_DrawText();\n\t\tS_OutputPolyList();\n\t\tSOUND_EndScene();\n\t\tS_DumpScreen();\n#ifdef FEATURE_INPUT_IMPROVED\n\t\tUpdateJoyOutput(false);\n#endif // FEATURE_INPUT_IMPROVED\n\t} while( !S_UpdateInput() && 0 == (select=PauseRequester()) );\n\n\tRemove_Requester(&StatsRequester);\n\tRemovePausedText();\n\tIsVidModeLock = false;\n\tTempVideoRemove();\n#ifdef FEATURE_AUDIO_IMPROVED\n\tif( Camera.underwater ) {\n\t\textern double UnderwaterMusicMute;\n\t\tdouble volume = (1.0 - UnderwaterMusicMute) * (double)(MusicVolume * 25 + 5);\n\t\tif( volume >= 1.0 ) {\n\t\t\tS_CDVolume((DWORD)volume);\n\t\t} else {\n\t\t\tS_CDVolume(0);\n\t\t}\n\t} else {\n\t\tS_CDVolume(MusicVolume * 25 + 5);\n\t}\n#else // FEATURE_AUDIO_IMPROVED\n\tS_CDVolume(MusicVolume * 25 + 5);\n#endif // FEATURE_AUDIO_IMPROVED\n\tS_FadeOutInventory(TRUE);\n\tInventoryChosen = ID_PASSPORT_OPTION;\n\tInventoryExtraData[0] = 2; // set the last passport page in case if \"Exit to Title\" is selected\n\tInventoryMode = INV_GameMode;\n\tOverlayStatus = oldOverlayStatus;\n\treturn (select < 0);\n}\n#endif // FEATURE_BACKGROUND_IMPROVED\n"
  },
  {
    "path": "modding/pause.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef PAUSE_H_INCLUDED\n#define PAUSE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#ifdef FEATURE_BACKGROUND_IMPROVED\nbool S_Pause();\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#endif // PAUSE_H_INCLUDED\n"
  },
  {
    "path": "modding/psx_bar.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/psx_bar.h\"\n#include \"specific/hwr.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_HUD_IMPROVED\nextern DWORD HealthBarMode;\n\nstatic D3DCOLOR InterpolateColor(D3DCOLOR color0, D3DCOLOR color1, DWORD value, DWORD range) {\n\tif( value == 0 )\n\t\treturn color0;\n\n\tif( value == range )\n\t\treturn color1;\n\n\tD3DCOLOR result = 0;\n\tBYTE *c0  = (BYTE *)&color0;\n\tBYTE *c1  = (BYTE *)&color1;\n\tBYTE *res = (BYTE *)&result;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tres[i] = (DWORD)c0[i]*(range-value)/range + (DWORD)c1[i]*value/range;\n\t}\n\treturn result;\n}\n\nstatic void __cdecl DrawCololoredRect(float sx0, float sy0, float sx1, float sy1, float z, D3DCOLOR color0, D3DCOLOR color1, D3DCOLOR color2, D3DCOLOR color3, BYTE alpha) {\n\tdouble sz, rhw;\n\tD3DTLVERTEX vertex[4];\n\n\tif( z > PhdFarZ ) {\n\t\treturn;\n\t}\n\tif( z < PhdNearZ ) {\n\t\tz = PhdNearZ;\n\t}\n\n\trhw = RhwFactor / (double)z;\n\tsz = FltResZBuf - rhw * FltResZORhw;\n\n\tvertex[0].sx = sx0;\n\tvertex[0].sy = sy0;\n\tvertex[0].color = RGBA_SETALPHA(color0, alpha);\n\n\tvertex[1].sx = sx1;\n\tvertex[1].sy = sy0;\n\tvertex[1].color = RGBA_SETALPHA(color1, alpha);\n\n\tvertex[2].sx = sx0;\n\tvertex[2].sy = sy1;\n\tvertex[2].color = RGBA_SETALPHA(color2, alpha);\n\n\tvertex[3].sx = sx1;\n\tvertex[3].sy = sy1;\n\tvertex[3].color = RGBA_SETALPHA(color3, alpha);\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tvertex[i].sz = sz;\n\t\tvertex[i].rhw = rhw;\n\t\tvertex[i].specular = 0;\n\t}\n\n\tHWR_TexSource(0);\n\tHWR_EnableColorKey(true);\n\tHWR_DrawPrimitive(D3DPT_TRIANGLESTRIP, &vertex, 4, true);\n}\n\nstatic void PSX_DrawBar(int x0, int y0, int x1, int y1, int bar, int pixel, D3DCOLOR *left, D3DCOLOR *right, D3DCOLOR *frame, BYTE alpha) {\n\t// Extra frame (dark gray)\n\tif( HealthBarMode != 1 ) // skip extra frame if required\n\t\tDrawCololoredRect(x0-pixel*3, y0-pixel*1, x1+pixel*3, y1+pixel*1, PhdNearZ + 40, frame[4], frame[5], frame[5], frame[4], 255);\n\t// Outer frame (light gray)\n\tDrawCololoredRect(x0-pixel*2, y0-pixel*2, x1+pixel*2, y1+pixel*2, PhdNearZ + 30, frame[2], frame[3], frame[3], frame[2], 255);\n\t// Inner frame (black)\n\tDrawCololoredRect(x0-pixel*1, y0-pixel*1, x1+pixel*1, y1+pixel*1, PhdNearZ + 20, frame[0], frame[1], frame[1], frame[0], 255);\n\n\t// The bar\n\tif( bar > 0 ) {\n\t\tint i;\n\t\tint dy[4];\n\t\tD3DCOLOR dl[4], dr[4];\n\t\tint dh = (y1 - y0) - pixel * 2;\n\n\t\tfor( i=0; i<4; ++i ) {\n\t\t\tdy[i] = dh * i / 3;\n\t\t\tif( i>0 && i<3 ) {\n\t\t\t\tdl[i] = InterpolateColor(left[i-1],  left[i],  dy[i], dh);\n\t\t\t\tdr[i] = InterpolateColor(right[i-1], right[i], dy[i], dh);\n\t\t\t} else {\n\t\t\t\tdl[i] = left[i];\n\t\t\t\tdr[i] = right[i];\n\t\t\t}\n\t\t}\n\n\t\tfor( i=0; i<3; ++i ) {\n\t\t\tDrawCololoredRect(x0, y1-dy[i+1], x0+bar, y1-dy[i], PhdNearZ + 10, dl[i+1], dr[i+1], dl[i], dr[i], alpha);\n\t\t}\n\n\t\tDrawCololoredRect(x0, y0+pixel*0, x0+bar, y0+pixel*1, PhdNearZ + 10, left[2], right[2], left[3], right[3], alpha);\n\t\tDrawCololoredRect(x0, y0+pixel*1, x0+bar, y0+pixel*2, PhdNearZ + 10, left[5], right[5], left[4], right[4], alpha);\n\t}\n}\n\nvoid __cdecl PSX_DrawHealthBar(int x0, int y0, int x1, int y1, int bar, int pixel, int alpha) {\n\tD3DCOLOR left[6]  = {0xFF680000, 0xFF700000, 0xFF980000, 0xFFD80000, 0xFFE40000, 0xFFF00000};\n\tD3DCOLOR right[6] = {0xFF004400, 0xFF007400, 0xFF009C00, 0xFF00D400, 0xFF00E800, 0xFF00FC00};\n\tD3DCOLOR frame[6] = {0xFF000000, 0xFF000000, 0xFF508484, 0xFFA0A0A0, 0xFF284242, 0xFF505050};\n\n\tfor( int i=0; i<6; ++i )\n\t\tright[i] = InterpolateColor(left[i], right[i], bar, x1-x0);\n\n\tCLAMP(alpha, 0, 255);\n\tPSX_DrawBar(x0, y0, x1, y1, bar, pixel, left, right, frame, alpha);\n}\n\nvoid __cdecl PSX_DrawAirBar(int x0, int y0, int x1, int y1, int bar, int pixel, int alpha) {\n\tD3DCOLOR left[6]  = {0xFF004054, 0xFF005064, 0xFF006874, 0xFF007884, 0xFF00848E, 0xFF009098};\n\tD3DCOLOR right[6] = {0xFF004000, 0xFF005000, 0xFF006800, 0xFF007800, 0xFF008400, 0xFF009000};\n\tD3DCOLOR frame[6] = {0xFF000000, 0xFF000000, 0xFF508484, 0xFFA0A0A0, 0xFF284242, 0xFF505050};\n\n\tfor( int i=0; i<6; ++i )\n\t\tright[i] = InterpolateColor(left[i], right[i], bar, x1-x0);\n\n\tCLAMP(alpha, 0, 255);\n\tPSX_DrawBar(x0, y0, x1, y1, bar, pixel, left, right, frame, alpha);\n}\n\nstatic void PSX_InsertBar(int polytype, int x0, int y0, int x1, int y1, int bar, int pixel, int alpha) {\n\tCLAMP(alpha, 0, 255);\n\tSort3dPtr->_0 = (DWORD)Info3dPtr;\n\tSort3dPtr->_1 = (DWORD)PhdNearZ;\n\t++Sort3dPtr;\n\t++SurfaceCount;\n\n\t*(Info3dPtr++) = polytype;\n\t*(Info3dPtr++) = x0;\n\t*(Info3dPtr++) = y0;\n\t*(Info3dPtr++) = x1;\n\t*(Info3dPtr++) = y1;\n\t*(Info3dPtr++) = bar;\n\t*(Info3dPtr++) = pixel;\n\t*(Info3dPtr++) = alpha;\n}\n\nvoid __cdecl PSX_InsertHealthBar(int x0, int y0, int x1, int y1, int bar, int pixel, int alpha) {\n\tPSX_InsertBar(POLY_HWR_healthbar, x0, y0, x1, y1, bar, pixel, alpha);\n}\n\nvoid __cdecl PSX_InsertAirBar(int x0, int y0, int x1, int y1, int bar, int pixel, int alpha) {\n\tPSX_InsertBar(POLY_HWR_airbar, x0, y0, x1, y1, bar, pixel, alpha);\n}\n\n#endif // FEATURE_HUD_IMPROVED\n"
  },
  {
    "path": "modding/psx_bar.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef PSX_BAR_H_INCLUDED\n#define PSX_BAR_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n\nvoid __cdecl PSX_DrawHealthBar(int x0, int y0, int x1, int y1, int bar, int pixel, int alpha);\nvoid __cdecl PSX_DrawAirBar(int x0, int y0, int x1, int y1, int bar, int pixel, int alpha);\nvoid __cdecl PSX_InsertHealthBar(int x0, int y0, int x1, int y1, int bar, int pixel, int alpha);\nvoid __cdecl PSX_InsertAirBar(int x0, int y0, int x1, int y1, int bar, int pixel, int alpha);\n\n#endif // PSX_BAR_H_INCLUDED\n"
  },
  {
    "path": "modding/raw_input.cpp",
    "content": "/*\n * Copyright (c) 2017-2023 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/raw_input.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include <hidusage.h>\n#include <hidpi.h>\n#include <hidsdi.h>\n#include <setupapi.h>\n\n#ifdef __cplusplus\n} /* extern \"C\" */\n#endif\n\n#include \"global/md5.h\"\n\n#define SONY_BT_REPORT_SIZE (78)\n\n#define VID_SONY (0x054C)\n#define PID_DUALSHOCK4_1 (0x05C4)\n#define PID_DUALSHOCK4_2 (0x09CC)\n#define PID_DUALSHOCK4_W (0x0BA0)\n#define PID_DUALSENSE (0x0CE6)\n\n#define VIA_USB \" - USB\"\n#define VIA_BLUETOOTH \" - Bluetooth\"\n\n#define NAME_DUALSHOCK4_1 \"Sony DualShock 4 (1st gen)\"\n#define NAME_DUALSHOCK4_2 \"Sony DualShock 4 (2nd gen)\"\n#define NAME_DUALSHOCK4_W \"Sony DualShock 4 (adaptor)\"\n#define NAME_DUALSENSE \"Sony DualSense\"\n\ntypedef struct {\n\tUINT numButtons;\n\tbool buttons[32];\n\tLONG rangeX,  valueX;\n\tLONG rangeY,  valueY;\n\tLONG rangeZ,  valueZ;\n\tLONG rangeRX, valueRX;\n\tLONG rangeRY, valueRY;\n\tLONG rangeRZ, valueRZ;\n\tLONG rangeDP, valueDP;\n} RAW_STATE;\n\ntypedef struct {\n\tWORD leftMotor;\n\tWORD rightMotor;\n\tDWORD color;\n\tbool updated;\n} RAW_REPORT;\n\nstatic DWORD SonyBluetoothCRC(LPCBYTE buf, DWORD len, DWORD crc) {\n\tstatic const DWORD lut[] = {\n\t\t0xD202EF8D, 0xA505DF1B, 0x3C0C8EA1, 0x4B0BBE37, 0xD56F2B94, 0xA2681B02, 0x3B614AB8, 0x4C667A2E,\n\t\t0xDCD967BF, 0xABDE5729, 0x32D70693, 0x45D03605, 0xDBB4A3A6, 0xACB39330, 0x35BAC28A, 0x42BDF21C,\n\t\t0xCFB5FFE9, 0xB8B2CF7F, 0x21BB9EC5, 0x56BCAE53, 0xC8D83BF0, 0xBFDF0B66, 0x26D65ADC, 0x51D16A4A,\n\t\t0xC16E77DB, 0xB669474D, 0x2F6016F7, 0x58672661, 0xC603B3C2, 0xB1048354, 0x280DD2EE, 0x5F0AE278,\n\t\t0xE96CCF45, 0x9E6BFFD3, 0x0762AE69, 0x70659EFF, 0xEE010B5C, 0x99063BCA, 0x000F6A70, 0x77085AE6,\n\t\t0xE7B74777, 0x90B077E1, 0x09B9265B, 0x7EBE16CD, 0xE0DA836E, 0x97DDB3F8, 0x0ED4E242, 0x79D3D2D4,\n\t\t0xF4DBDF21, 0x83DCEFB7, 0x1AD5BE0D, 0x6DD28E9B, 0xF3B61B38, 0x84B12BAE, 0x1DB87A14, 0x6ABF4A82,\n\t\t0xFA005713, 0x8D076785, 0x140E363F, 0x630906A9, 0xFD6D930A, 0x8A6AA39C, 0x1363F226, 0x6464C2B0,\n\t\t0xA4DEAE1D, 0xD3D99E8B, 0x4AD0CF31, 0x3DD7FFA7, 0xA3B36A04, 0xD4B45A92, 0x4DBD0B28, 0x3ABA3BBE,\n\t\t0xAA05262F, 0xDD0216B9, 0x440B4703, 0x330C7795, 0xAD68E236, 0xDA6FD2A0, 0x4366831A, 0x3461B38C,\n\t\t0xB969BE79, 0xCE6E8EEF, 0x5767DF55, 0x2060EFC3, 0xBE047A60, 0xC9034AF6, 0x500A1B4C, 0x270D2BDA,\n\t\t0xB7B2364B, 0xC0B506DD, 0x59BC5767, 0x2EBB67F1, 0xB0DFF252, 0xC7D8C2C4, 0x5ED1937E, 0x29D6A3E8,\n\t\t0x9FB08ED5, 0xE8B7BE43, 0x71BEEFF9, 0x06B9DF6F, 0x98DD4ACC, 0xEFDA7A5A, 0x76D32BE0, 0x01D41B76,\n\t\t0x916B06E7, 0xE66C3671, 0x7F6567CB, 0x0862575D, 0x9606C2FE, 0xE101F268, 0x7808A3D2, 0x0F0F9344,\n\t\t0x82079EB1, 0xF500AE27, 0x6C09FF9D, 0x1B0ECF0B, 0x856A5AA8, 0xF26D6A3E, 0x6B643B84, 0x1C630B12,\n\t\t0x8CDC1683, 0xFBDB2615, 0x62D277AF, 0x15D54739, 0x8BB1D29A, 0xFCB6E20C, 0x65BFB3B6, 0x12B88320,\n\t\t0x3FBA6CAD, 0x48BD5C3B, 0xD1B40D81, 0xA6B33D17, 0x38D7A8B4, 0x4FD09822, 0xD6D9C998, 0xA1DEF90E,\n\t\t0x3161E49F, 0x4666D409, 0xDF6F85B3, 0xA868B525, 0x360C2086, 0x410B1010, 0xD80241AA, 0xAF05713C,\n\t\t0x220D7CC9, 0x550A4C5F, 0xCC031DE5, 0xBB042D73, 0x2560B8D0, 0x52678846, 0xCB6ED9FC, 0xBC69E96A,\n\t\t0x2CD6F4FB, 0x5BD1C46D, 0xC2D895D7, 0xB5DFA541, 0x2BBB30E2, 0x5CBC0074, 0xC5B551CE, 0xB2B26158,\n\t\t0x04D44C65, 0x73D37CF3, 0xEADA2D49, 0x9DDD1DDF, 0x03B9887C, 0x74BEB8EA, 0xEDB7E950, 0x9AB0D9C6,\n\t\t0x0A0FC457, 0x7D08F4C1, 0xE401A57B, 0x930695ED, 0x0D62004E, 0x7A6530D8, 0xE36C6162, 0x946B51F4,\n\t\t0x19635C01, 0x6E646C97, 0xF76D3D2D, 0x806A0DBB, 0x1E0E9818, 0x6909A88E, 0xF000F934, 0x8707C9A2,\n\t\t0x17B8D433, 0x60BFE4A5, 0xF9B6B51F, 0x8EB18589, 0x10D5102A, 0x67D220BC, 0xFEDB7106, 0x89DC4190,\n\t\t0x49662D3D, 0x3E611DAB, 0xA7684C11, 0xD06F7C87, 0x4E0BE924, 0x390CD9B2, 0xA0058808, 0xD702B89E,\n\t\t0x47BDA50F, 0x30BA9599, 0xA9B3C423, 0xDEB4F4B5, 0x40D06116, 0x37D75180, 0xAEDE003A, 0xD9D930AC,\n\t\t0x54D13D59, 0x23D60DCF, 0xBADF5C75, 0xCDD86CE3, 0x53BCF940, 0x24BBC9D6, 0xBDB2986C, 0xCAB5A8FA,\n\t\t0x5A0AB56B, 0x2D0D85FD, 0xB404D447, 0xC303E4D1, 0x5D677172, 0x2A6041E4, 0xB369105E, 0xC46E20C8,\n\t\t0x72080DF5, 0x050F3D63, 0x9C066CD9, 0xEB015C4F, 0x7565C9EC, 0x0262F97A, 0x9B6BA8C0, 0xEC6C9856,\n\t\t0x7CD385C7, 0x0BD4B551, 0x92DDE4EB, 0xE5DAD47D, 0x7BBE41DE, 0x0CB97148, 0x95B020F2, 0xE2B71064,\n\t\t0x6FBF1D91, 0x18B82D07, 0x81B17CBD, 0xF6B64C2B, 0x68D2D988, 0x1FD5E91E, 0x86DCB8A4, 0xF1DB8832,\n\t\t0x616495A3, 0x1663A535, 0x8F6AF48F, 0xF86DC419, 0x660951BA, 0x110E612C, 0x88073096, 0xFF000000,\n\t};\n\tfor( DWORD i = 0; i < len; ++i ) {\n\t\tcrc = lut[((BYTE)crc) ^ ((BYTE)buf[i])] ^ (crc >> 8);\n\t}\n\treturn crc;\n}\n\nstatic bool IsRawBluetooth(PHIDD_ATTRIBUTES pAttr, PHIDP_CAPS pCaps) {\n\tif( !pAttr || !pCaps ) return false;\n\tswitch( pAttr->VendorID ) {\n\tcase VID_SONY:\n\t\tswitch( pAttr->ProductID ) {\n\t\tcase PID_DUALSHOCK4_1:\n\t\tcase PID_DUALSHOCK4_2:\n\t\tcase PID_DUALSHOCK4_W:\n\t\tcase PID_DUALSENSE:\n\t\t\tif( pCaps->InputReportByteLength >= SONY_BT_REPORT_SIZE &&\n\t\t\t\tpCaps->OutputReportByteLength >= SONY_BT_REPORT_SIZE )\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n\treturn false;\n}\n\nstatic bool CalculateRawGUID(LPCTSTR lpString, LPGUID lpGuid) {\n\tif( !lpString || !*lpString || !lpGuid ) return false;\n\t// use MD5 hash as RawInput Device GUID\n\tMD5_CTX mdContext;\n\tMD5Init(&mdContext);\n\tMD5Update(&mdContext, (unsigned char *)lpString, sizeof(TCHAR)*strlen(lpString));\n\tMD5Final(&mdContext);\n\tmemcpy(lpGuid, mdContext.digest, sizeof(GUID));\n\treturn true;\n}\n\nLPCTSTR GetRawInputName(WORD vid, WORD pid, BOOL bt) {\n\tswitch( vid ) {\n\tcase VID_SONY:\n\t\tswitch( pid ) {\n\t\tcase PID_DUALSHOCK4_1:\n\t\t\treturn bt ? NAME_DUALSHOCK4_1 VIA_BLUETOOTH : NAME_DUALSHOCK4_1 VIA_USB;\n\t\tcase PID_DUALSHOCK4_2:\n\t\t\treturn bt ? NAME_DUALSHOCK4_2 VIA_BLUETOOTH : NAME_DUALSHOCK4_2 VIA_USB;\n\t\tcase PID_DUALSHOCK4_W:\n\t\t\treturn bt ? NAME_DUALSHOCK4_W VIA_BLUETOOTH : NAME_DUALSHOCK4_W VIA_USB;\n\t\tcase PID_DUALSENSE:\n\t\t\treturn bt ? NAME_DUALSENSE VIA_BLUETOOTH : NAME_DUALSENSE VIA_USB;\n\t\tdefault:\n\t\t\tbreak;\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n\treturn NULL;\n}\n\nbool RawInputEnumerate(BOOL(CALLBACK *callback)(LPGUID, LPCTSTR, LPCTSTR, WORD, WORD, LPVOID), LPVOID lpContext) {\n\tif( callback == NULL ) return false;\n\tGUID hidGuid;\n\tHidD_GetHidGuid(&hidGuid);\n\tHANDLE hDevs = SetupDiGetClassDevs(&hidGuid, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);\n\tif( hDevs == INVALID_HANDLE_VALUE ) return false;\n\tDWORD devIndex = 0;\n\tSP_DEVINFO_DATA devInfo;\n\tdevInfo.cbSize = sizeof(SP_DEVINFO_DATA);\n\twhile( SetupDiEnumDeviceInfo(hDevs, devIndex++, &devInfo) ) {\n\t\tDWORD ifaceIndex = 0;\n\t\tSP_DEVICE_INTERFACE_DATA ifaceInfo;\n\t\tifaceInfo.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);\n\t\twhile( SetupDiEnumDeviceInterfaces(hDevs, &devInfo, &hidGuid, ifaceIndex++, &ifaceInfo) ) {\n\t\t\tDWORD detailSize = 0;\n\t\t\tSetupDiGetDeviceInterfaceDetail(hDevs, &ifaceInfo, NULL, 0, &detailSize, NULL);\n\t\t\tPSP_DEVICE_INTERFACE_DETAIL_DATA pDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(detailSize);\n\t\t\tpDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);\n\t\t\tSetupDiGetDeviceInterfaceDetail(hDevs, &ifaceInfo, pDetail, detailSize, NULL, NULL);\n\t\t\tHANDLE hDevice = CreateFile(pDetail->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);\n\t\t\tif( hDevice != INVALID_HANDLE_VALUE ) {\n\t\t\t\tPHIDP_PREPARSED_DATA pPreparsed = NULL;\n\t\t\t\tHIDD_ATTRIBUTES attr;\n\t\t\t\tHIDP_CAPS caps;\n\t\t\t\tbool fetched = (HidD_GetAttributes(hDevice, &attr)\n\t\t\t\t\t&& HidD_GetPreparsedData(hDevice, &pPreparsed)\n\t\t\t\t\t&& HIDP_STATUS_SUCCESS == HidP_GetCaps(pPreparsed, &caps));\n\t\t\t\tif( pPreparsed != NULL ) HidD_FreePreparsedData(pPreparsed);\n\t\t\t\tCloseHandle(hDevice);\n\t\t\t\tif( fetched && caps.UsagePage == HID_USAGE_PAGE_GENERIC\n\t\t\t\t\t&& (caps.Usage == HID_USAGE_GENERIC_JOYSTICK || caps.Usage == HID_USAGE_GENERIC_GAMEPAD) )\n\t\t\t\t{\n\t\t\t\t\tGUID deviceGuid;\n\t\t\t\t\tLPCTSTR productName = GetRawInputName(attr.VendorID, attr.ProductID, IsRawBluetooth(&attr, &caps));\n\t\t\t\t\tif( productName != NULL && CalculateRawGUID(pDetail->DevicePath, &deviceGuid) ) {\n\t\t\t\t\t\tcallback(&deviceGuid, pDetail->DevicePath, productName, attr.VendorID, attr.ProductID, lpContext);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfree(pDetail);\n\t\t}\n\t}\n\tSetupDiDestroyDeviceInfoList(hDevs);\n\treturn true;\n}\n\n// --------------------\n// RAW HID Device class\n// --------------------\n\nclass RawHidDevice {\n\tprivate:\n\t\t// fields\n\t\tbool isStop = false;\n\t\tbool isInit = false;\n\t\tbool isConnected = false;\n\t\tbool isBluetooth = false;\n\t\tHANDLE hMutex = NULL;\n\t\tHANDLE hThread = NULL;\n\t\tLPTSTR lpDeviceName = NULL;\n\t\tHANDLE hDeviceFile = INVALID_HANDLE_VALUE;\n\t\tPHIDP_PREPARSED_DATA pPreparsedData = NULL;\n\t\tPHIDP_BUTTON_CAPS pButtonCaps = NULL;\n\t\tPHIDP_VALUE_CAPS pValueCaps = NULL;\n\t\tHIDD_ATTRIBUTES HidAttr;\n\t\tHIDP_CAPS HidCaps;\n\t\tLPBYTE pRawInput = NULL;\n\t\tRAW_STATE RawState;\n\t\tRAW_REPORT RawReport;\n\t\t// methods\n\t\tstatic DWORD WINAPI StaticTask(CONST LPVOID lpParam) {\n\t\t\tRawHidDevice *This = (RawHidDevice *)lpParam;\n\t\t\treturn This->Task();\n\t\t}\n\t\tDWORD Task();\n\t\tbool Connect();\n\t\tvoid Disconnect(bool release=false);\n\t\tbool Reconnect();\n\t\tbool Send(LPCVOID lpBuffer, DWORD nSize);\n\t\tbool Receive(LPVOID lpBuffer, DWORD nSize);\n\t\tbool Calibrate();\n\t\tbool SonyDualSenseRumbleAdjust(int *pLeftMotor, int *pRightMotor, int *pIntensity);\n\t\tbool SonyControllerReport(LPBYTE buf, DWORD bufLen, DWORD productId, RAW_REPORT *pReport);\n\t\tbool ParseRawInputStandard(LPBYTE buf, DWORD bufLen, RAW_STATE *pState);\n\t\tbool ParseRawInputSonyDualShock4(LPBYTE buf, DWORD bufLen, RAW_STATE *pState);\n\t\tbool ParseRawInputSonyDualSense(LPBYTE buf, DWORD bufLen, RAW_STATE *pState);\n\t\tbool SendRawReport(bool clean=false);\n\t\tbool ReceiveRawInput();\n\tpublic:\n\t\tbool IsRunning();\n\t\tbool Start(LPCTSTR lpName);\n\t\tvoid Stop();\n\t\tbool SetState(WORD leftMotor, WORD rightMotor, DWORD colors);\n\t\tbool GetState(RINPUT_STATE *pState);\n};\n\nDWORD RawHidDevice::Task() {\n\tConnect();\n\twhile( !isStop ) {\n\t\tif( isConnected ) {\n\t\t\tReceiveRawInput();\n\t\t\tSendRawReport();\n\t\t} else if( !Reconnect() )  {\n\t\t\tSleep(100);\n\t\t}\n\t}\n\tDisconnect(true);\n\treturn 0;\n}\n\nbool RawHidDevice::Connect() {\n\tif( hDeviceFile == INVALID_HANDLE_VALUE ) {\n\t\thDeviceFile = CreateFile(lpDeviceName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);\n\t}\n\tisConnected = (hDeviceFile != INVALID_HANDLE_VALUE);\n\tif( isConnected && !isInit ) {\n\t\tHANDLE hHeap = GetProcessHeap();\n\t\tif( !HidD_GetAttributes(hDeviceFile, &HidAttr) ||\n\t\t\t!HidD_GetPreparsedData(hDeviceFile, &pPreparsedData) ||\n\t\t\tHIDP_STATUS_SUCCESS != HidP_GetCaps(pPreparsedData, &HidCaps) )\n\t\t{\n\t\t\tDisconnect(true);\n\t\t\treturn false;\n\t\t}\n\t\tisBluetooth = IsRawBluetooth(&HidAttr, &HidCaps);\n\t\tpRawInput = (LPBYTE)HeapAlloc(hHeap, 0, HidCaps.InputReportByteLength);\n\t\tpButtonCaps = (PHIDP_BUTTON_CAPS)HeapAlloc(hHeap, 0, sizeof(HIDP_BUTTON_CAPS) * HidCaps.NumberInputButtonCaps);\n\t\tpValueCaps = (PHIDP_VALUE_CAPS)HeapAlloc(hHeap, 0, sizeof(HIDP_VALUE_CAPS) * HidCaps.NumberInputValueCaps);\n\t\tisInit = true;\n\t}\n\tif( !isConnected ) {\n\t\treturn false;\n\t}\n\tCalibrate();\n\tif( isBluetooth ) {\n\t\tSendRawReport(true);\n\t}\n\treturn true;\n}\n\nvoid RawHidDevice::Disconnect(bool release) {\n\tif( release ) {\n\t\tHANDLE hHeap = GetProcessHeap();\n\t\tif( pPreparsedData != NULL ) {\n\t\t\tHidD_FreePreparsedData(pPreparsedData);\n\t\t\tpPreparsedData = NULL;\n\t\t}\n\t\tif( pButtonCaps != NULL ) {\n\t\t\tHeapFree(hHeap, 0, pButtonCaps);\n\t\t\tpButtonCaps = NULL;\n\t\t}\n\t\tif( pValueCaps != NULL ) {\n\t\t\tHeapFree(hHeap, 0, pValueCaps);\n\t\t\tpValueCaps = NULL;\n\t\t}\n\t\tif( pRawInput != NULL ) {\n\t\t\tHeapFree(hHeap, 0, pRawInput);\n\t\t\tpRawInput = NULL;\n\t\t}\n\t\tmemset(&HidAttr, 0, sizeof(HidAttr));\n\t\tmemset(&HidCaps, 0, sizeof(HidCaps));\n\t\tisInit = false;\n\t}\n\tif( hDeviceFile != INVALID_HANDLE_VALUE ) {\n\t\tCloseHandle(hDeviceFile);\n\t\thDeviceFile = INVALID_HANDLE_VALUE;\n\t}\n\tisConnected = false;\n}\n\nbool RawHidDevice::Reconnect() {\n\tCalibrate(); // kick OS to refresh lost device state\n\tDisconnect();\n\treturn Connect();\n}\n\nbool RawHidDevice::Send(LPCVOID lpBuffer, DWORD nSize) {\n\tOVERLAPPED overlapped;\n\tmemset(&overlapped, 0, sizeof(overlapped));\n\tWriteFile(hDeviceFile, lpBuffer, nSize, NULL, &overlapped);\n\tfor( int i=0; i<50; ++i ) {\n\t\tSleep(1);\n\t\tDWORD bytesWritten = 0;\n\t\tBOOL res = GetOverlappedResult(hDeviceFile, &overlapped, &bytesWritten, FALSE);\n\t\tif( res && bytesWritten >= nSize ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\tisConnected = false;\n\treturn false;\n}\n\nbool RawHidDevice::Receive(LPVOID lpBuffer, DWORD nSize) {\n\tOVERLAPPED overlapped;\n\tmemset(&overlapped, 0, sizeof(overlapped));\n\tReadFile(hDeviceFile, lpBuffer, nSize, NULL, &overlapped);\n\tfor( int i=0; i<50; ++i ) {\n\t\tSleep(1);\n\t\tDWORD bytesRead = 0;\n\t\tBOOL res = GetOverlappedResult(hDeviceFile, &overlapped, &bytesRead, FALSE);\n\t\tif( res && bytesRead >= nSize ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\tisConnected = false;\n\treturn false;\n}\n\nbool RawHidDevice::Calibrate() {\n\tif( !isInit || hDeviceFile == INVALID_HANDLE_VALUE ) return false;\n\t// We don't need the feature data itself, we need this to unlock advanced controls\n\tbool result = true;\n\tswitch( HidAttr.VendorID ) {\n\tcase VID_SONY:\n\t\tswitch( HidAttr.ProductID ) {\n\t\tcase PID_DUALSHOCK4_1:\n\t\tcase PID_DUALSHOCK4_2:\n\t\tcase PID_DUALSHOCK4_W:\n\t\t\t{\n\t\t\t\tBYTE buf[41] = {0x02};\n\t\t\t\tresult = HidD_GetFeature(hDeviceFile, buf, sizeof(buf));\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PID_DUALSENSE:\n\t\t\t{\n\t\t\t\tBYTE buf[41] = {0x05};\n\t\t\t\tresult = HidD_GetFeature(hDeviceFile, buf, sizeof(buf));\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n\treturn result;\n}\n\nbool RawHidDevice::SonyDualSenseRumbleAdjust(int *pLeftMotor, int *pRightMotor, int *pIntensity) {\n\t// Sony DualSense uses haptics instead of regular vibration motors.\n\t// For legacy rumble emulation it scales rumble intensity very very bad,\n\t// so you feel no difference between weak and strong vibrations.\n\t// But there is a workaround with global intensity parameter which affects\n\t// both motors, so this function decides how to scale every motor force\n\t// and overall intensity.\n\tif( pLeftMotor == NULL || pRightMotor == NULL || pIntensity == NULL ) {\n\t\treturn false;\n\t}\n\tint lrange = 0, lforce = 0;\n\tint rrange = 0, rforce = 0;\n\tif( *pLeftMotor ) {\r\n\t\t// make left motor to be fully scaled\r\n\t\tint motor = *pLeftMotor * 4;\r\n\t\tlrange = (motor - 1) / 128;\r\n\t\tCLAMPG(lrange, 6);\r\n\t\tlforce = motor - lrange * 128;\r\n\t\tCLAMP(lforce, 1, 255);\r\n\t}\r\n\tif( *pRightMotor ) {\r\n\t\t// make right motor to be 3/4 scaled (minimum range is 2)\r\n\t\tint motor = *pRightMotor * 3;\r\n\t\trrange = (motor - 1) / 128;\r\n\t\tCLAMPG(rrange, 4);\r\n\t\trforce = motor - rrange * 128;\r\n\t\tCLAMP(rforce, 1, 255);\r\n\t\trrange += 2;\r\n\t}\r\n\tif( lforce && rforce ) {\r\n\t\t// don't use 'else if' here, it is supposed to be sequential 'if'\r\n\t\tif( rrange > lrange && rforce < 128 ) {\r\n\t\t\trrange--;\r\n\t\t\trforce += 128;\r\n\t\t}\r\n\t\tif( lrange < rrange && lforce >= 128 ) {\r\n\t\t\tlrange++;\r\n\t\t\tlforce -= 127;\r\n\t\t}\r\n\t\tif( lrange > rrange && lforce < 128 ) {\r\n\t\t\tlrange--;\r\n\t\t\tlforce += 128;\r\n\t\t}\r\n\t\tif( rrange < lrange && rforce >= 128 ) {\r\n\t\t\trrange++;\r\n\t\t\trforce -= 127;\r\n\t\t}\r\n\t\tif( rrange != lrange ) {\r\n\t\t\t// left (heavy) motor is leading\r\n\t\t\t// fit the right (light) motor\r\n\t\t\trforce = rrange < lrange ? 1 : 255;\r\n\t\t\trrange = lrange;\r\n\t\t}\r\n\t}\r\n\t*pLeftMotor = lforce;\n\t*pRightMotor = rforce;\n\t*pIntensity = 6 - (lforce > 0 ? lrange : rrange);\n\treturn true;\n}\n\nbool RawHidDevice::SonyControllerReport(LPBYTE buf, DWORD bufLen, DWORD productId, RAW_REPORT *pReport) {\n\tLPBYTE data = NULL;\n\tmemset(buf, 0, bufLen);\n\tswitch( productId ) {\n\tcase PID_DUALSHOCK4_1:\n\tcase PID_DUALSHOCK4_2:\n\tcase PID_DUALSHOCK4_W:\n\t\tif( isBluetooth ) {\n\t\t\tbuf[0] = 0x11;\n\t\t\tbuf[1] = 0xC0;\n\t\t\tbuf[2] = 0xA0;\n\t\t\tdata = buf+3;\n\t\t} else if( bufLen == 32 ) {\n\t\t\tbuf[0] = 0x05;\n\t\t\tdata = buf+1;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t\tif( pReport == NULL ) {\n\t\t\tdata[0] = 0xF4;\n\t\t} else {\n\t\t\tdata[0] = 0xF7;\n\t\t\tdata[3] = (BYTE)(pReport->rightMotor>>8);\n\t\t\tdata[4] = (BYTE)(pReport->leftMotor>>8);\n\t\t\tdata[5] = (BYTE)(RGB_GETRED(pReport->color));\n\t\t\tdata[6] = (BYTE)(RGB_GETGREEN(pReport->color));\n\t\t\tdata[7] = (BYTE)(RGB_GETBLUE(pReport->color));\n\t\t}\n\t\tbreak;\n\tcase PID_DUALSENSE:\n\t\tif( isBluetooth ) {\n\t\t\tbuf[0] = 0x31;\n\t\t\tbuf[1] = 0x02;\n\t\t\tdata = buf+2;\n\t\t} else if( bufLen == 48 ) {\n\t\t\tbuf[0] = 0x02;\n\t\t\tdata = buf+1;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t\tif( pReport == NULL ) {\n\t\t\tdata[1] = 0x15;\n\t\t} else {\n\t\t\tint leftMotor = pReport->leftMotor>>8;\n\t\t\tint rightMotor = pReport->rightMotor>>8;\n\t\t\tint intensity = 2;\n\t\t\tSonyDualSenseRumbleAdjust(&leftMotor, &rightMotor, &intensity);\n\t\t\tdata[0] = 0x0F;\n\t\t\tdata[1] = 0x55;\n\t\t\tdata[2] = (BYTE)rightMotor;\n\t\t\tdata[3] = (BYTE)leftMotor;\n\t\t\tdata[8] = 0x00; // Mute LED: [Off]=0, [On]=1, [Pulse]=2\n\t\t\t// 10 - 19: right trigger feedback\n\t\t\t// 21 - 30: left trigger feedback\n\t\t\tdata[36] = (BYTE)intensity; // Haptic intensity: [High]=0, [Medium]=2, [Low]=5, [Tiny]=7\n\t\t\tdata[38] = 0x02; // LED mode: [LED static brightness in 42]=1,  [Blue LED fade in 41]=2\n\t\t\tdata[41] = 0x02; // LED fade: [Fade in]=1, [Fade out]=2\n\t\t\tdata[42] = 0x02; // LED brightness: [High]=0, [Medium]=1, [Low]=2\n\t\t\tdata[43] = 0x00; // Player LED mask\n\t\t\tdata[44] = (BYTE)(RGB_GETRED(pReport->color));\n\t\t\tdata[45] = (BYTE)(RGB_GETGREEN(pReport->color));\n\t\t\tdata[46] = (BYTE)(RGB_GETBLUE(pReport->color));\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\treturn false;\n\t}\n\tif( isBluetooth ) {\n\t\tDWORD crc = 0;\n\t\tBYTE btheader[] = {0xA2}; // (format 4:2:2) transaction_type=0xA (data), parameters=0x0 (none), report_type=0x2 (output)\n\t\tcrc = SonyBluetoothCRC(btheader, sizeof(btheader), crc);\n\t\tcrc = SonyBluetoothCRC(buf, SONY_BT_REPORT_SIZE-4, crc);\n\t\tfor( int i=4; i>=1; --i ) {\n\t\t\tbuf[SONY_BT_REPORT_SIZE - i] = (BYTE)crc;\n\t\t\tcrc >>= 8;\n\t\t}\n\t}\n\treturn true;\n}\n\nbool RawHidDevice::ParseRawInputStandard(LPBYTE buf, DWORD bufLen, RAW_STATE *pState) {\n\tWORD capsLen;\n\tDWORD value;\n\tUSAGE usage[128];\n\n\tif( pState == NULL || pPreparsedData == NULL || pButtonCaps == NULL || pValueCaps == NULL ) return false;\n\n\t// Button caps\n\tcapsLen = HidCaps.NumberInputButtonCaps;\n\tif( HIDP_STATUS_SUCCESS != HidP_GetButtonCaps(HidP_Input, pButtonCaps, &capsLen, pPreparsedData) ) return false;\n\tpState->numButtons = pButtonCaps->Range.UsageMax - pButtonCaps->Range.UsageMin + 1;\n\n\t// Button states\n\tvalue = pState->numButtons;\n\tif( HIDP_STATUS_SUCCESS != HidP_GetUsages(HidP_Input, pButtonCaps->UsagePage,\n\t\t0, usage, &value, pPreparsedData, (PCHAR)buf, bufLen) ) return false;\n\tmemset(pState->buttons, 0, sizeof(pState->buttons));\n\tfor( UINT i = 0; i < MIN(value, 32); ++i ) {\n\t\tpState->buttons[usage[i] - pButtonCaps->Range.UsageMin] = true;\n\t}\n\n\t// Axes and D-Pad caps\n\tcapsLen = HidCaps.NumberInputValueCaps;\n\tif( HIDP_STATUS_SUCCESS != HidP_GetValueCaps(HidP_Input, pValueCaps, &capsLen, pPreparsedData) ) return false;\n\n\t// Axes and D-Pad values\n\tfor( UINT i = 0; i < HidCaps.NumberInputValueCaps; ++i ) {\n\t\tif( HIDP_STATUS_SUCCESS != HidP_GetUsageValue(HidP_Input, pValueCaps[i].UsagePage,\n\t\t\t0, pValueCaps[i].Range.UsageMin, &value, pPreparsedData, (PCHAR)buf, bufLen) ) continue;\n\n\t\tswitch( pValueCaps[i].Range.UsageMin ) {\n\t\tcase '0': // X-axis\n\t\t\tpState->valueX = (UWORD)value - pValueCaps[i].LogicalMin;\n\t\t\tpState->rangeX = 1 + (UWORD)pValueCaps[i].LogicalMax - pValueCaps[i].LogicalMin;\n\t\t\tbreak;\n\t\tcase '1': // Y-axis\n\t\t\tpState->valueY = (UWORD)value - pValueCaps[i].LogicalMin;\n\t\t\tpState->rangeY = 1 + (UWORD)pValueCaps[i].LogicalMax - pValueCaps[i].LogicalMin;\n\t\t\tbreak;\n\t\tcase '2': // Z-axis\n\t\t\tpState->valueZ = (UWORD)value - pValueCaps[i].LogicalMin;\n\t\t\tpState->rangeZ = 1 + (UWORD)pValueCaps[i].LogicalMax - pValueCaps[i].LogicalMin;\n\t\t\tbreak;\n\t\tcase '3': // RX-axis\n\t\t\tpState->valueRX = (UWORD)value - pValueCaps[i].LogicalMin;\n\t\t\tpState->rangeRX = 1 + (UWORD)pValueCaps[i].LogicalMax - pValueCaps[i].LogicalMin;\n\t\t\tbreak;\n\t\tcase '4': // RY-axis\n\t\t\tpState->valueRY = (UWORD)value - pValueCaps[i].LogicalMin;\n\t\t\tpState->rangeRY = 1 + (UWORD)pValueCaps[i].LogicalMax - pValueCaps[i].LogicalMin;\n\t\t\tbreak;\n\t\tcase '5': // RZ-axis\n\t\t\tpState->valueRZ = (UWORD)value - pValueCaps[i].LogicalMin;\n\t\t\tpState->rangeRZ = 1 + (UWORD)pValueCaps[i].LogicalMax - pValueCaps[i].LogicalMin;\n\t\t\tbreak;\n\t\tcase '9': // D-Pad\n\t\t\tif( value < (UWORD)pValueCaps[i].LogicalMin || value > (UWORD)pValueCaps[i].LogicalMax ) {\n\t\t\t\tpState->valueDP = -1;\n\t\t\t} else {\n\t\t\t\tpState->valueDP = (UWORD)value - pValueCaps[i].LogicalMin;\n\t\t\t}\n\t\t\tpState->rangeDP = 1 + (UWORD)pValueCaps[i].LogicalMax - pValueCaps[i].LogicalMin;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn true;\n}\n\nbool RawHidDevice::ParseRawInputSonyDualShock4(LPBYTE buf, DWORD bufLen, RAW_STATE *pState) {\n\tif( buf == NULL || bufLen < 16 || pState == NULL ) return false;\n\tmemset(pState, 0, sizeof(RAW_STATE));\n\n\t// Axes\n\tpState->rangeX = pState->rangeY = pState->rangeZ = 0x100;\n\tpState->rangeRX = pState->rangeRY = pState->rangeRZ = 0x100;\n\tpState->valueX = buf[1];\n\tpState->valueY = buf[2];\n\tpState->valueZ = buf[3];\n\tpState->valueRZ = buf[4];\n\tpState->valueRX = buf[8];\n\tpState->valueRY = buf[9];\n\n\t// D-Pad\n\tpState->rangeDP = 8;\n\tpState->valueDP = (buf[5] & 0x0F);\n\tif( pState->valueDP >= pState->rangeDP ) {\n\t\tpState->valueDP = -1;\n\t}\n\n\t// Buttons\n\tpState->numButtons = 14;\n\tWORD mask = ((WORD)buf[5] >> 4) | ((WORD)buf[6] << 4) | ((WORD)buf[7] << 12);\n\tfor( UINT i = 0; i < pState->numButtons; ++i ) {\n\t\tpState->buttons[i] = ((mask & (1<<i)) != 0);\n\t}\n\treturn true;\n}\n\nbool RawHidDevice::ParseRawInputSonyDualSense(LPBYTE buf, DWORD bufLen, RAW_STATE *pState) {\n\tif( buf == NULL || bufLen < 16 || pState == NULL ) return false;\n\tmemset(pState, 0, sizeof(RAW_STATE));\n\n\t// Axes\n\tpState->rangeX = pState->rangeY = pState->rangeZ = 0x100;\n\tpState->rangeRX = pState->rangeRY = pState->rangeRZ = 0x100;\n\tpState->valueX = buf[1];\n\tpState->valueY = buf[2];\n\tpState->valueZ = buf[3];\n\tpState->valueRZ = buf[4];\n\tpState->valueRX = buf[5];\n\tpState->valueRY = buf[6];\n\n\t// D-Pad\n\tpState->rangeDP = 8;\n\tpState->valueDP = (buf[8] & 0x0F);\n\tif( pState->valueDP >= pState->rangeDP ) {\n\t\tpState->valueDP = -1;\n\t}\n\n\t// Buttons\n\tpState->numButtons = 14;\n\tWORD mask = ((WORD)buf[8] >> 4) | ((WORD)buf[9] << 4) | ((WORD)buf[10] << 12);\n\tfor( UINT i = 0; i < pState->numButtons; ++i ) {\n\t\tpState->buttons[i] = ((mask & (1<<i)) != 0);\n\t}\n\treturn true;\n}\n\nbool RawHidDevice::SendRawReport(bool clean) {\n\tif( !isConnected ) return false;\n\tbool result = false;\n\tBYTE buf[HidCaps.OutputReportByteLength];\n\tswitch( HidAttr.VendorID ) {\n\tcase VID_SONY:\n\t\tWaitForSingleObject(hMutex, INFINITE);\n\t\tif( clean ) {\n\t\t\tresult = SonyControllerReport(buf, sizeof(buf), HidAttr.ProductID, NULL);\n\t\t\tRawReport.updated = true;\n\t\t} else if( RawReport.updated ) {\n\t\t\tresult = SonyControllerReport(buf, sizeof(buf), HidAttr.ProductID, &RawReport);\n\t\t\tRawReport.updated = false;\n\t\t}\n\t\tReleaseMutex(hMutex);\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n\tif( !result || !Send(buf, sizeof(buf)) ) {\n\t\tif( !isConnected ) {\n\t\t\tWaitForSingleObject(hMutex, INFINITE);\n\t\t\tmemset(&RawState, 0, sizeof(RawState));\n\t\t\tRawReport.updated = true;\n\t\t\tReleaseMutex(hMutex);\n\t\t}\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nbool RawHidDevice::ReceiveRawInput() {\n\tif( !isConnected || !Receive(pRawInput, HidCaps.InputReportByteLength) ) {\n\t\tif( !isConnected ) {\n\t\t\tWaitForSingleObject(hMutex, INFINITE);\n\t\t\tmemset(&RawState, 0, sizeof(RawState));\n\t\t\tRawReport.updated = true;\n\t\t\tReleaseMutex(hMutex);\n\t\t}\n\t\treturn false;\n\t}\n\tif( isBluetooth && HidAttr.VendorID == VID_SONY ) {\n\t\tDWORD readCRC = 0;\n\t\tDWORD calcCRC = 0;\n\t\tif( pRawInput[0] == ((HidAttr.ProductID == PID_DUALSENSE) ? 0x31 : 0x11) ) {\n\t\t\tfor( int i=1; i<=4; ++i ) {\n\t\t\t\treadCRC <<= 8;\n\t\t\t\treadCRC |= pRawInput[SONY_BT_REPORT_SIZE - i];\n\t\t\t}\n\t\t\tBYTE btheader[] = {0xA1}; // (format 4:2:2) transaction_type=0xA (data), parameters=0x0 (none), report_type=0x1 (input)\n\t\t\tcalcCRC = SonyBluetoothCRC(btheader, sizeof(btheader), calcCRC);\n\t\t\tcalcCRC = SonyBluetoothCRC(pRawInput, SONY_BT_REPORT_SIZE-4, calcCRC);\n\t\t}\n\t\tif( calcCRC != readCRC ) {\n\t\t\t// just skip this packet\n\t\t\treturn false;\n\t\t}\n\t}\n\tbool result = false;\n\tRAW_STATE state;\n\tmemset(&state, 0, sizeof(state));\n\tswitch( HidAttr.VendorID ) {\n\tcase VID_SONY:\n\t\tswitch( HidAttr.ProductID ) {\n\t\tcase PID_DUALSHOCK4_1:\n\t\tcase PID_DUALSHOCK4_2:\n\t\tcase PID_DUALSHOCK4_W:\n\t\t\tif( isBluetooth ) {\n\t\t\t\tDWORD offset = (pRawInput[0] == 0x11) ? 2 : 0;\n\t\t\t\tresult = ParseRawInputSonyDualShock4(pRawInput + offset, HidCaps.InputReportByteLength, &state);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PID_DUALSENSE:\n\t\t\tif( isBluetooth ) {\n\t\t\t\tDWORD offset = (pRawInput[0] == 0x31) ? 1 : 0;\n\t\t\t\tresult = ParseRawInputSonyDualSense(pRawInput + offset, HidCaps.InputReportByteLength-1, &state);\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n\tif( !result ) {\n\t\tresult = ParseRawInputStandard(pRawInput, HidCaps.InputReportByteLength, &state);\n\t}\n\tWaitForSingleObject(hMutex, INFINITE);\n\tRawState = state;\n\tReleaseMutex(hMutex);\n\treturn result;\n}\n\nbool RawHidDevice::IsRunning() {\n\tDWORD status;\n\treturn ((hThread != NULL) && GetExitCodeThread(hThread, &status) && (status == STILL_ACTIVE));\n}\n\nbool RawHidDevice::Start(LPCTSTR lpName) {\n\tif( !lpName || !*lpName ) {\n\t\treturn false;\n\t}\n\tif( IsRunning() ) {\n\t\treturn !strcasecmp(lpDeviceName, lpName);\n\t}\n\thMutex = CreateMutex(NULL, FALSE, NULL);\n\tif( hMutex != NULL ) {\n\t\tlpDeviceName = strdup(lpName);\n\t\tif( lpDeviceName != NULL ) {\n\t\t\tmemset(&RawReport, 0, sizeof(RawReport));\n\t\t\tisStop = false;\n\t\t\thThread = CreateThread(NULL, 0, StaticTask, this, 0, NULL);\n\t\t\tif( hThread != NULL ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\tStop();\n\treturn false;\n}\n\nvoid RawHidDevice::Stop() {\n\tif( IsRunning() ) {\n\t\tisStop = true;\n\t\tWaitForSingleObject(hThread, INFINITE);\n\t\tCloseHandle(hThread);\n\t\thThread = NULL;\n\t}\n\tif( lpDeviceName != NULL ) {\n\t\tfree(lpDeviceName);\n\t\tlpDeviceName = NULL;\n\t}\n\tif( hMutex != NULL ) {\n\t\tCloseHandle(hMutex);\n\t\thMutex = NULL;\n\t}\n}\n\nbool RawHidDevice::SetState(WORD leftMotor, WORD rightMotor, DWORD color) {\n\tif( !IsRunning() ) return false;\n\tWaitForSingleObject(hMutex, INFINITE);\n\tif( leftMotor != RawReport.leftMotor ||\n\t\trightMotor != RawReport.rightMotor ||\n\t\tcolor != RawReport.color )\n\t{\n\t\tRawReport.leftMotor = leftMotor;\n\t\tRawReport.rightMotor = rightMotor;\n\t\tRawReport.color = color;\n\t\tRawReport.updated = true;\n\t}\n\tReleaseMutex(hMutex);\n\treturn true;\n}\n\nbool RawHidDevice::GetState(RINPUT_STATE *pState) {\n\tif( !pState || !IsRunning() ) return false;\n\n\tWaitForSingleObject(hMutex, INFINITE);\n\tmemset(pState, 0, sizeof(RINPUT_STATE));\n\n\tif( RawState.rangeDP && RawState.valueDP >= 0 ) {\n\t\tpState->dPad = 36000 * RawState.valueDP / RawState.rangeDP;\n\t} else {\n\t\tpState->dPad = -1;\n\t}\n\n\tpState->btnSquare = RawState.buttons[0];\n\tpState->btnCross = RawState.buttons[1];\n\tpState->btnCircle = RawState.buttons[2];\n\tpState->btnTriangle = RawState.buttons[3];\n\tpState->btnL1 = RawState.buttons[4];\n\tpState->btnR1 = RawState.buttons[5];\n\tpState->btnL2 = RawState.buttons[6];\n\tpState->btnR2 = RawState.buttons[7];\n\tpState->btnShare = RawState.buttons[8];\n\tpState->btnOptions = RawState.buttons[9];\n\tpState->btnL3 = RawState.buttons[10];\n\tpState->btnR3 = RawState.buttons[11];\n\tpState->btnPS = RawState.buttons[12];\n\tpState->btnTouch = RawState.buttons[13];\n\n\tif( RawState.rangeX  ) pState->axisLX = (float)(RawState.valueX*2 - RawState.rangeX) / (float)RawState.rangeX;\n\tif( RawState.rangeY  ) pState->axisLY = (float)(RawState.rangeY - RawState.valueY*2) / (float)RawState.rangeY;\n\tif( RawState.rangeZ  ) pState->axisRX = (float)(RawState.valueZ*2 - RawState.rangeZ) / (float)RawState.rangeZ;\n\tif( RawState.rangeRZ ) pState->axisRY = (float)(RawState.rangeRZ - RawState.valueRZ*2) / (float)RawState.rangeRZ;\n\tif( RawState.rangeRX ) pState->axisL2 = (float)RawState.valueRX / (float)RawState.rangeRX;\n\tif( RawState.rangeRY ) pState->axisR2 = (float)RawState.valueRY / (float)RawState.rangeRY;\n\n\tReleaseMutex(hMutex);\n\treturn true;\n}\n\nstatic RawHidDevice RawInput;\n\nbool RawInputStart(LPCTSTR lpName) {\n\treturn RawInput.Start(lpName);\n}\n\nvoid RawInputStop() {\n\tRawInput.Stop();\n}\n\nbool RawInputSetState(WORD leftMotor, WORD rightMotor, DWORD color) {\n\treturn RawInput.SetState(leftMotor, rightMotor, color);\n}\n\nbool RawInputGetState(RINPUT_STATE *pState) {\n\treturn RawInput.GetState(pState);\n}\n\n#endif // FEATURE_INPUT_IMPROVED\n"
  },
  {
    "path": "modding/raw_input.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef RAW_INPUT_H_INCLUDED\n#define RAW_INPUT_H_INCLUDED\n\n#include \"global/types.h\"\n/*\n * This whole RawInput implementation is created for Sony DualShock 4 / DualSense, so it uses PlayStation button names\n */\ntypedef struct {\n\tLONG dPad; // -1 if unpressed, and 0-36000 if pressed\n\tfloat axisLX, axisLY, axisRX, axisRY, axisL2, axisR2;\n\tWORD btnSquare:1, btnCross:1, btnCircle:1, btnTriangle:1;\n\tWORD btnL1:1, btnR1:1, btnL2:1, btnR2:1, btnL3:1, btnR3:1;\n\tWORD btnShare:1, btnOptions:1, btnPS:1, btnTouch:1, btnReserved:2;\n} RINPUT_STATE;\n\n/*\n * Function list\n */\nLPCTSTR GetRawInputName(WORD vid, WORD pid, BOOL bt);\nbool RawInputEnumerate(BOOL(CALLBACK *callback)(LPGUID, LPCTSTR, LPCTSTR, WORD, WORD, LPVOID), LPVOID lpContext);\nbool RawInputStart(LPCTSTR lpName);\nvoid RawInputStop();\nbool RawInputSetState(WORD leftMotor, WORD rightMotor, DWORD color);\nbool RawInputGetState(RINPUT_STATE *pState);\n\n#endif // RAW_INPUT_H_INCLUDED\n"
  },
  {
    "path": "modding/texture_utils.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/texture_utils.h\"\n#include \"specific/init_input.h\"\n#include \"specific/output.h\"\n#include \"specific/texture.h\"\n#include \"specific/utils.h\"\n#include \"modding/file_utils.h\"\n#include \"modding/json_utils.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_HUD_IMPROVED\n#define BTN_SPR_IDX (ARRAY_SIZE(PhdSpriteInfo) - 256)\n\nDWORD JoystickButtonStyle = 0;\n\ntypedef enum {\n\tkbd_esc,\n\tkbd_f1,\n\tkbd_f2,\n\tkbd_f3,\n\tkbd_f4,\n\tkbd_f5,\n\tkbd_f6,\n\tkbd_f7,\n\tkbd_f8,\n\tkbd_f9,\n\tkbd_f10,\n\tkbd_f11,\n\tkbd_f12,\n\n\tkbd_tab,\n\tkbd_1,\n\tkbd_2,\n\tkbd_3,\n\tkbd_4,\n\tkbd_5,\n\tkbd_6,\n\tkbd_7,\n\tkbd_8,\n\tkbd_9,\n\tkbd_0,\n\tkbd_minus,\n\tkbd_equals,\n\tkbd_backspace,\n\n\tkbd_capslock,\n\tkbd_q,\n\tkbd_w,\n\tkbd_e,\n\tkbd_r,\n\tkbd_t,\n\tkbd_y,\n\tkbd_u,\n\tkbd_i,\n\tkbd_o,\n\tkbd_p,\n\tkbd_lbracket,\n\tkbd_rbracket,\n\tkbd_return,\n\n\tkbd_ctrl,\n\tkbd_a,\n\tkbd_s,\n\tkbd_d,\n\tkbd_f,\n\tkbd_g,\n\tkbd_h,\n\tkbd_j,\n\tkbd_k,\n\tkbd_l,\n\tkbd_semicolon,\n\tkbd_apostrophe,\n\tkbd_grave,\n\tkbd_shift,\n\n\tkbd_alt,\n\tkbd_backslash,\n\tkbd_z,\n\tkbd_x,\n\tkbd_c,\n\tkbd_v,\n\tkbd_b,\n\tkbd_n,\n\tkbd_m,\n\tkbd_comma,\n\tkbd_period,\n\tkbd_slash,\n\tkbd_oem102,\n\tkbd_space,\n\n\tkbd_printscreen,\n\tkbd_scrolllock,\n\tkbd_pause,\n\tkbd_insert,\n\tkbd_home,\n\tkbd_pageup,\n\tkbd_delete,\n\tkbd_end,\n\tkbd_pagedown,\n\tkbd_left,\n\tkbd_right,\n\tkbd_up,\n\tkbd_down,\n\tkbd_numlock,\n\n\tkbd_pad7,\n\tkbd_pad8,\n\tkbd_pad9,\n\tkbd_divide,\n\tkbd_pad4,\n\tkbd_pad5,\n\tkbd_pad6,\n\tkbd_multiply,\n\tkbd_pad1,\n\tkbd_pad2,\n\tkbd_pad3,\n\tkbd_subtract,\n\tkbd_pad0,\n\tkbd_decimal,\n\tkbd_enter,\n\tkbd_add,\n\n\tjoy_di1,  joy_di2,  joy_di3,  joy_di4,  joy_di5,  joy_di6,  joy_di7,  joy_di8,\n\tjoy_di9,  joy_di10, joy_di11, joy_di12, joy_di13, joy_di14, joy_di15, joy_di16,\n\n\tjoy_ps1,  joy_ps2,  joy_ps3,  joy_ps4,  joy_ps5,  joy_ps6,  joy_ps7,  joy_ps8,\n\tjoy_ps9,  joy_ps10, joy_ps11, joy_ps12, joy_ps13, joy_ps14, joy_ps15, joy_ps16,\n\n\tjoy_xi1,  joy_xi2,  joy_xi3,  joy_xi4,  joy_xi5,  joy_xi6,  joy_xi7,  joy_xi8,\n\tjoy_xi9,  joy_xi10, joy_xi11, joy_xi12, joy_xi13, joy_xi14, joy_xi15, joy_xi16,\n\n\tbutton_sprites_number,\n} SPR_BUTTONS;\n\ntypedef struct {\n\tint id;\n\tconst char *name;\n} MAP;\n\nstatic MAP btnMap[] = {\n\t{kbd_esc, \"esc\"},\n\t{kbd_f1, \"f1\"},\n\t{kbd_f2, \"f2\"},\n\t{kbd_f3, \"f3\"},\n\t{kbd_f4, \"f4\"},\n\t{kbd_f5, \"f5\"},\n\t{kbd_f6, \"f6\"},\n\t{kbd_f7, \"f7\"},\n\t{kbd_f8, \"f8\"},\n\t{kbd_f9, \"f9\"},\n\t{kbd_f10, \"f10\"},\n\t{kbd_f11, \"f11\"},\n\t{kbd_f12, \"f12\"},\n\t{kbd_tab, \"tab\"},\n\t{kbd_capslock, \"capslock\"},\n\t{kbd_shift, \"shift\"},\n\t{kbd_ctrl, \"ctrl\"},\n\t{kbd_alt, \"alt\"},\n\t{kbd_space, \"space\"},\n\t{kbd_backspace, \"backspace\"},\n\t{kbd_return, \"return\"},\n\t{kbd_1, \"1\"},\n\t{kbd_2, \"2\"},\n\t{kbd_3, \"3\"},\n\t{kbd_4, \"4\"},\n\t{kbd_5, \"5\"},\n\t{kbd_6, \"6\"},\n\t{kbd_7, \"7\"},\n\t{kbd_8, \"8\"},\n\t{kbd_9, \"9\"},\n\t{kbd_0, \"0\"},\n\t{kbd_minus, \"-\"},\n\t{kbd_equals, \"=\"},\n\t{kbd_q, \"q\"},\n\t{kbd_w, \"w\"},\n\t{kbd_e, \"e\"},\n\t{kbd_r, \"r\"},\n\t{kbd_t, \"t\"},\n\t{kbd_y, \"y\"},\n\t{kbd_u, \"u\"},\n\t{kbd_i, \"i\"},\n\t{kbd_o, \"o\"},\n\t{kbd_p, \"p\"},\n\t{kbd_lbracket, \"[\"},\n\t{kbd_rbracket, \"]\"},\n\t{kbd_a, \"a\"},\n\t{kbd_s, \"s\"},\n\t{kbd_d, \"d\"},\n\t{kbd_f, \"f\"},\n\t{kbd_g, \"g\"},\n\t{kbd_h, \"h\"},\n\t{kbd_j, \"j\"},\n\t{kbd_k, \"k\"},\n\t{kbd_l, \"l\"},\n\t{kbd_semicolon, \";\"},\n\t{kbd_apostrophe, \"'\"},\n\t{kbd_grave, \"`\"},\n\t{kbd_backslash, \"\\\\\"},\n\t{kbd_z, \"z\"},\n\t{kbd_x, \"x\"},\n\t{kbd_c, \"c\"},\n\t{kbd_v, \"v\"},\n\t{kbd_b, \"b\"},\n\t{kbd_n, \"n\"},\n\t{kbd_m, \"m\"},\n\t{kbd_comma, \",\"},\n\t{kbd_period, \".\"},\n\t{kbd_slash, \"/\"},\n\t{kbd_oem102, \"<\"},\n\t{kbd_printscreen, \"printscreen\"},\n\t{kbd_scrolllock, \"scrolllock\"},\n\t{kbd_pause, \"pause\"},\n\t{kbd_insert, \"insert\"},\n\t{kbd_home, \"home\"},\n\t{kbd_pageup, \"pageup\"},\n\t{kbd_delete, \"delete\"},\n\t{kbd_end, \"end\"},\n\t{kbd_pagedown, \"pagedown\"},\n\t{kbd_left, \"left\"},\n\t{kbd_right, \"right\"},\n\t{kbd_up, \"up\"},\n\t{kbd_down, \"down\"},\n\t{kbd_numlock, \"numlock\"},\n\t{kbd_pad7, \"pad7\"},\n\t{kbd_pad8, \"pad8\"},\n\t{kbd_pad9, \"pad9\"},\n\t{kbd_divide, \"pad/\"},\n\t{kbd_pad4, \"pad4\"},\n\t{kbd_pad5, \"pad5\"},\n\t{kbd_pad6, \"pad6\"},\n\t{kbd_multiply, \"pad*\"},\n\t{kbd_pad1, \"pad1\"},\n\t{kbd_pad2, \"pad2\"},\n\t{kbd_pad3, \"pad3\"},\n\t{kbd_subtract, \"pad-\"},\n\t{kbd_pad0, \"pad0\"},\n\t{kbd_decimal, \"pad.\"},\n\t{kbd_enter, \"enter\"},\n\t{kbd_add, \"pad+\"},\n\n\t{joy_di1,  \"di1\"},  {joy_di2,  \"di2\"},  {joy_di3,  \"di3\"},  {joy_di4,  \"di4\"},\n\t{joy_di5,  \"di5\"},  {joy_di6,  \"di6\"},  {joy_di7,  \"di7\"},  {joy_di8,  \"di8\"},\n\t{joy_di9,  \"di9\"},  {joy_di10, \"di10\"}, {joy_di11, \"di11\"}, {joy_di12, \"di12\"},\n\t{joy_di13, \"di13\"}, {joy_di14, \"di14\"}, {joy_di15, \"di15\"}, {joy_di16, \"di16\"},\n\n\t{joy_ps1,  \"ps1\"},  {joy_ps2,  \"ps2\"},  {joy_ps3,  \"ps3\"},  {joy_ps4,  \"ps4\"},\n\t{joy_ps5,  \"ps5\"},  {joy_ps6,  \"ps6\"},  {joy_ps7,  \"ps7\"},  {joy_ps8,  \"ps8\"},\n\t{joy_ps9,  \"ps9\"},  {joy_ps10, \"ps10\"}, {joy_ps11, \"ps11\"}, {joy_ps12, \"ps12\"},\n\t{joy_ps13, \"ps13\"}, {joy_ps14, \"ps14\"}, {joy_ps15, \"ps15\"}, {joy_ps16, \"ps16\"},\n\n\t{joy_xi1,  \"xi1\"},  {joy_xi2,  \"xi2\"},  {joy_xi3,  \"xi3\"},  {joy_xi4,  \"xi4\"},\n\t{joy_xi5,  \"xi5\"},  {joy_xi6,  \"xi6\"},  {joy_xi7,  \"xi7\"},  {joy_xi8,  \"xi8\"},\n\t{joy_xi9,  \"xi9\"},  {joy_xi10, \"xi10\"}, {joy_xi11, \"xi11\"}, {joy_xi12, \"xi12\"},\n\t{joy_xi13, \"xi13\"}, {joy_xi14, \"xi14\"}, {joy_xi15, \"xi15\"}, {joy_xi16, \"xi16\"},\n};\n\nstatic MAP joyMapDI[] = {\n\t{joy_di1,  \"joy1\"},  {joy_di2,  \"joy2\"},  {joy_di3,  \"joy3\"},  {joy_di4,  \"joy4\"},\n\t{joy_di5,  \"joy5\"},  {joy_di6,  \"joy6\"},  {joy_di7,  \"joy7\"},  {joy_di8,  \"joy8\"},\n\t{joy_di9,  \"joy9\"},  {joy_di10, \"joy10\"}, {joy_di11, \"joy11\"}, {joy_di12, \"joy12\"},\n\t{joy_di13, \"joy13\"}, {joy_di14, \"joy14\"}, {joy_di15, \"joy15\"}, {joy_di16, \"joy16\"},\n};\n\nstatic MAP joyMapPS[] = {\n\t{joy_ps1,  \"joy1\"},  {joy_ps2,  \"joy2\"},  {joy_ps3,  \"joy3\"},  {joy_ps4,  \"joy4\"},\n\t{joy_ps5,  \"joy5\"},  {joy_ps6,  \"joy6\"},  {joy_ps7,  \"joy7\"},  {joy_ps8,  \"joy8\"},\n\t{joy_ps9,  \"joy9\"},  {joy_ps10, \"joy10\"}, {joy_ps11, \"joy11\"}, {joy_ps12, \"joy12\"},\n\t{joy_ps13, \"joy13\"}, {joy_ps14, \"joy14\"}, {joy_ps15, \"joy15\"}, {joy_ps16, \"joy16\"},\n};\n\nstatic MAP joyMapXI[] = {\n\t{joy_xi1,  \"joy1\"},  {joy_xi2,  \"joy2\"},  {joy_xi3,  \"joy3\"},  {joy_xi4,  \"joy4\"},\n\t{joy_xi5,  \"joy5\"},  {joy_xi6,  \"joy6\"},  {joy_xi7,  \"joy7\"},  {joy_xi8,  \"joy8\"},\n\t{joy_xi9,  \"joy9\"},  {joy_xi10, \"joy10\"}, {joy_xi11, \"joy11\"}, {joy_xi12, \"joy12\"},\n\t{joy_xi13, \"joy13\"}, {joy_xi14, \"joy14\"}, {joy_xi15, \"joy15\"}, {joy_xi16, \"joy16\"},\n};\n\nstatic bool ButtonSpriteLoaded = false;\nstatic BYTE ButtonSpriteSpacing[256] = {0};\nstatic BYTE ButtonSpriteSWR[256*256] = {0};\n\nstatic int compareMap(const void *a, const void *b) {\n\treturn strcmp(((const MAP *)a)->name, ((const MAP *)b)->name);\n}\n\nstatic void sortMaps() {\n\tstatic bool once = false;\n\tif( !once ) {\n\t\tqsort(btnMap,   ARRAY_SIZE(btnMap),   sizeof(MAP), compareMap);\n\t\tqsort(joyMapDI, ARRAY_SIZE(joyMapDI), sizeof(MAP), compareMap);\n\t\tqsort(joyMapPS, ARRAY_SIZE(joyMapPS), sizeof(MAP), compareMap);\n\t\tqsort(joyMapXI, ARRAY_SIZE(joyMapXI), sizeof(MAP), compareMap);\n\t\tonce = true;\n\t}\n}\n\nstatic int searchMap(const char *name, MAP *mapArray, DWORD mapCount) {\n\tif( !name || !*name ) return -1;\n\tMAP keyItem = {0, name};\n\tMAP *foundItem = (MAP *)bsearch(&keyItem, mapArray, mapCount, sizeof(MAP), compareMap);\n\treturn foundItem ? foundItem->id : -1;\n}\n\nstatic bool ParseSpriteInfo(json_value *root, int id) {\n\tif( root == NULL || root->type != json_object || id < 0 || id >= button_sprites_number ) {\n\t\treturn false;\n\t}\n\tPHD_SPRITE *info = &PhdSpriteInfo[BTN_SPR_IDX + id];\n\n\tBYTE u = GetJsonIntegerFieldValue(root, \"u\", 0);\n\tBYTE v = GetJsonIntegerFieldValue(root, \"v\", 0);\n\tint x = GetJsonIntegerFieldValue(root, \"x\", 0);\n\tint y = GetJsonIntegerFieldValue(root, \"y\", 0);\n\tint width = GetJsonIntegerFieldValue(root, \"width\", 0);\n\tint height = GetJsonIntegerFieldValue(root, \"height\", 0);\n\tButtonSpriteSpacing[id] = GetJsonIntegerFieldValue(root, \"spacing\", 0);\n\n\tinfo->offset = (v << 8) | u;\n\tinfo->width = ABS(width)*256;\n\tinfo->height = ABS(height)*256;\n\tinfo->x1 = x;\n\tinfo->y1 = y;\n\tinfo->x2 = x + width;\n\tinfo->y2 = y + height;\n\n\treturn true;\n}\n\nstatic bool ParseButtonSprites(json_value *root) {\n\tif( root == NULL || root->type != json_object ) {\n\t\treturn false;\n\t}\n\tsortMaps();\n\tfor( DWORD i = 0; i < root->u.object.length; ++i ) {\n\t\tif( root->u.object.values[i].value->type != json_object ) continue;\n\t\tint id = searchMap(root->u.object.values[i].name, btnMap, ARRAY_SIZE(btnMap));\n\t\tParseSpriteInfo(root->u.object.values[i].value, id);\n\t}\n\treturn true;\n}\n\nstatic BYTE FindPaletteEntry(RGB888 *palette, int red, int green, int blue) {\n\tUINT16 result = 0;\n\tint diffMin = INT_MAX;\n\t// skip index 0 as it is reserved as semitransparent\n\tfor( int i=1; i<256; ++i ) {\n\t\tint diffRed   = red   - GamePalette8[i].red;\n\t\tint diffGreen = green - GamePalette8[i].green;\n\t\tint diffBlue  = blue  - GamePalette8[i].blue;\n\t\tint diffTotal = SQR(diffRed) + SQR(diffGreen) + SQR(diffBlue);\n\t\tif( diffTotal < diffMin ) {\n\t\t\tdiffMin = diffTotal;\n\t\t\tresult = i;\n\t\t}\n\t}\n\treturn result;\n}\n\nstatic void AdaptToPalette(void *srcData, int width, int height, int srcPitch, RGB888 *srcPalette, void *dstData, int dstPitch, RGB888 *dstPalette) {\n\tint i, j;\n\tBYTE *src, *dst;\n\tBYTE bufPalette[256] = {0};\n\n\t// skip index 0 as it is reserved as semitransparent\n\tfor( i=1; i<256; ++i ) {\n\t\tbufPalette[i] = FindPaletteEntry(dstPalette, srcPalette[i].red, srcPalette[i].green, srcPalette[i].blue);\n\t}\n\n\tsrc = (BYTE *)srcData;\n\tdst = (BYTE *)dstData;\n\tfor( i=0; i<height; ++i ) {\n\t\tfor( j=0; j<width; ++j ) {\n\t\t\t*(dst++) = bufPalette[*(src++)];\n\t\t}\n\t\tsrc += srcPitch - width;\n\t\tdst += dstPitch - width;\n\t}\n}\n\nstatic int LoadButtonSpriteTexturePage(bool *isExternal) {\n\tint pageIndex = -1;\n\tDWORD width, height, pcxSize = 0;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.RenderMode == RM_Hardware && PathFileExists(\"textures/buttons.png\") ) {\n\t\tpageIndex = AddExternalTexture(\"textures/buttons.png\", true);\n\t\tif( pageIndex >= 0 ) {\n\t\t\tHWR_TexturePageIndexes[HwrTexturePagesCount] = pageIndex;\n\t\t\tHWR_PageHandles[HwrTexturePagesCount] = GetTexturePageHandle(pageIndex);\n\t\t\tpageIndex = HwrTexturePagesCount++;\n\t\t\tif( isExternal ) *isExternal = true;\n\t\t\treturn pageIndex;\n\t\t}\n\t}\n\tif( isExternal ) *isExternal = false;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tLPCBYTE pcxData = (LPCBYTE)GetResourceData(\"BUTTONS.PCX\", &pcxSize);\n\tif( !pcxData || !pcxSize || GetPcxResolution(pcxData, pcxSize, &width, &height)\n\t\t|| width != height || (SavedAppSettings.RenderMode != RM_Hardware && width != 256) )\n\t{\n\t\treturn -1;\n\t}\n\n\tRGB888 bmpPal[256] = {{0,0,0}};\n\tBYTE *bitmap = (BYTE *)malloc(width * height);\n\tif( bitmap != NULL ) {\n\t\tif( DecompPCX(pcxData, pcxSize, bitmap, bmpPal) ) {\n\t\t\tif( SavedAppSettings.RenderMode != RM_Hardware || TextureFormat.bpp < 16 ) {\n\t\t\t\tAdaptToPalette(bitmap, width, height, width, bmpPal, bitmap, width, GamePalette8);\n\t\t\t\tmemcpy(bmpPal, GamePalette8, sizeof(bmpPal));\n\t\t\t}\n\t\t\tpageIndex = MakeCustomTexture(0, 0, width, height, width, width, 8, bitmap, bmpPal, PaletteIndex, ButtonSpriteSWR, true);\n\t\t\tif( pageIndex >= 0 && SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\t\tHWR_TexturePageIndexes[HwrTexturePagesCount] = pageIndex;\n\t\t\t\tHWR_PageHandles[HwrTexturePagesCount] = GetTexturePageHandle(pageIndex);\n\t\t\t\tpageIndex = HwrTexturePagesCount++;\n\t\t\t}\n\t\t}\n\t\tfree(bitmap);\n\t}\n\n\treturn pageIndex;\n}\n\nbool LoadButtonSprites() {\n\tButtonSpriteLoaded = false;\n\tmemset(&PhdSpriteInfo[BTN_SPR_IDX], 0, sizeof(PHD_SPRITE) * button_sprites_number);\n\tbool isExternalTexture = false;\n\tint pageIndex = LoadButtonSpriteTexturePage(&isExternalTexture);\n\tif( pageIndex >= 0 ) {\n\t\tfor( int i = 0; i < button_sprites_number; ++i ) {\n\t\t\tPhdSpriteInfo[BTN_SPR_IDX + i].texPage = pageIndex;\n\t\t}\n\t\tDWORD jsonSize = 0;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tbool isExternalJson = false;\n\t\tLPVOID jsonData = NULL;\n\t\tif( isExternalTexture && PathFileExists(\"textures/buttons.json\") ) {\n\t\t\tDWORD bytesRead = 0;\n\t\t\tHANDLE hFile = CreateFile(\"textures/buttons.json\", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN|FILE_ATTRIBUTE_NORMAL, NULL);\n\t\t\tif( hFile != INVALID_HANDLE_VALUE ) {\n\t\t\t\tisExternalJson = true;\n\t\t\t\tjsonSize = GetFileSize(hFile, NULL);\n\t\t\t\tjsonData = malloc(jsonSize);\n\t\t\t\tReadFile(hFile, jsonData, jsonSize, &bytesRead, NULL);\n\t\t\t\tCloseHandle(hFile);\n\t\t\t}\n\t\t}\n\t\tif( !isExternalJson ) {\n\t\t\tjsonData = (LPVOID)GetResourceData(\"BUTTONS.JSON\", &jsonSize);\n\t\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tLPCVOID jsonData = GetResourceData(\"BUTTONS.JSON\", &jsonSize);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tif( jsonData && jsonSize ) {\n\t\t\tjson_value* json = json_parse((const json_char *)jsonData, jsonSize);\n\t\t\tif( json != NULL ) {\n\t\t\t\tButtonSpriteLoaded = ParseButtonSprites(json);\n\t\t\t\tjson_value_free(json);\n\t\t\t}\n\t\t}\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tif( isExternalJson && jsonData ) {\n\t\t\tfree(jsonData);\n\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n\treturn ButtonSpriteLoaded;\n}\n\nbool GetTextSpriteByName(const char *name, int nameLen, DWORD *sprite, int *spacing) {\n\tint id = -1;\n\tchar mapName[64] = {0};\n\tif( !ButtonSpriteLoaded || name == NULL || nameLen <= 0 || (DWORD)nameLen >= sizeof(mapName) ) {\n\t\treturn false;\n\t}\n\tmemcpy(mapName, name, nameLen);\n\n\tDWORD buttonStyle = JoystickButtonStyle;\n#ifdef FEATURE_INPUT_IMPROVED\n\tif( buttonStyle == 0 ) {\n\t\tswitch( GetJoystickType() ) {\n\t\t\tcase JT_XINPUT:\n\t\t\t\tbuttonStyle = 3;\n\t\t\t\tbreak;\n\t\t\tcase JT_PLAYSTATION:\n\t\t\t\tbuttonStyle = 2;\n\t\t\t\tbreak;\n\t\t\tcase JT_DIRECTINPUT:\n\t\t\tcase JT_NONE:\n\t\t\t\tbuttonStyle = 1;\n\t\t\t\tbreak;\n\t\t}\n\t}\n#endif // FEATURE_INPUT_IMPROVED\n\tswitch( buttonStyle ) {\n\t\tcase 0:\n\t\tcase 1:\n\t\t\tid = searchMap(mapName, joyMapDI, ARRAY_SIZE(joyMapDI));\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tid = searchMap(mapName, joyMapPS, ARRAY_SIZE(joyMapPS));\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tid = searchMap(mapName, joyMapXI, ARRAY_SIZE(joyMapXI));\n\t\t\tbreak;\n\t}\n\tif( id < 0 || id >= button_sprites_number ) {\n\t\tid = searchMap(mapName, btnMap, ARRAY_SIZE(btnMap));\n\t}\n\tif( id < 0 || id >= button_sprites_number ) {\n\t\treturn false;\n\t}\n\tif( sprite ) *sprite = BTN_SPR_IDX + id;\n\tif( spacing ) *spacing = ButtonSpriteSpacing[id];\n\treturn true;\n}\n#endif // FEATURE_HUD_IMPROVED\n\n// This prevents texture bleeding instead of UV adjustment\nstatic int FillEdgePadding(DWORD width, DWORD height, DWORD side, BYTE *bitmap, DWORD bpp) {\n\tif( !width || !height || width > side || height > side || bitmap == NULL ) {\n\t\treturn -1;\n\t}\n\tswitch( bpp ) {\n\t\tcase  8 :\n\t\tcase 16 :\n\t\tcase 32 :\n\t\t\tbreak;\n\t\tdefault :\n\t\t\treturn -1;\n\t}\n\n\tDWORD i;\n\tDWORD padRight = side - width;\n\tDWORD padBottom = side - height;\n\n\tif( padRight > 0 ) {\n\t\tswitch( bpp ) {\n\t\t\tcase  8 : {\n\t\t\t\tBYTE *p = (BYTE *)bitmap;\n\t\t\t\tfor( i = 0; i < height ; ++i ) {\n\t\t\t\t\tp += width;\n\t\t\t\t\tp[0] = p[-1];\n\t\t\t\t\tp += padRight;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 16 : {\n\t\t\t\tUINT16 *p = (UINT16 *)bitmap;\n\t\t\t\tfor( i = 0; i < height ; ++i ) {\n\t\t\t\t\tp += width;\n\t\t\t\t\tp[0] = p[-1];\n\t\t\t\t\tp += padRight;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 32 : {\n\t\t\t\tDWORD *p = (DWORD *)bitmap;\n\t\t\t\tfor( i = 0; i < height ; ++i ) {\n\t\t\t\t\tp += width;\n\t\t\t\t\tp[0] = p[-1];\n\t\t\t\t\tp += padRight;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault :\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tif( padBottom > 0 ) {\n\t\tDWORD pitch = (width + padRight?1:0) * (bpp/8);\n\t\tBYTE *p = bitmap + height * pitch;\n\t\tmemcpy(p, p - pitch, pitch);\n\t\tp += pitch;\n\t}\n\n\treturn 0;\n}\n\nint MakeCustomTexture(DWORD x, DWORD y, DWORD width, DWORD height, DWORD pitch, DWORD side, DWORD bpp, BYTE *bitmap, RGB888 *bmpPal, int hwrPal, BYTE *swrBuf, bool keyColor) {\n\tint pageIndex = -1;\n\tif( bpp == 16 ) {\n\t\tif( SavedAppSettings.RenderMode != RM_Hardware || TextureFormat.bpp < 16 ) { // texture cannot be indexed in this case\n\t\t\treturn -1;\n\t\t}\n\t\tUINT16 *tmpBmp = (UINT16 *)calloc(2, SQR(side));\n\t\tUINT16 *bmpDst = tmpBmp;\n\t\tUINT16 *bmpSrc = (UINT16 *)bitmap + x + y * pitch;\n\n\t\tfor( DWORD j = 0; j < height; ++j ) {\n\t\t\tmemcpy(bmpDst, bmpSrc, sizeof(UINT16) * width);\n\t\t\tbmpSrc += pitch;\n\t\t\tbmpDst += side;\n\t\t}\n\t\tFillEdgePadding(width, height, side, (BYTE *)tmpBmp, bpp);\n\t\tpageIndex = AddTexturePage16(side, side, (BYTE *)tmpBmp);\n\t\tfree(tmpBmp);\n#if (DIRECT3D_VERSION >= 0x900)\n\t} else if( bpp == 32 ) {\n\t\tif( SavedAppSettings.RenderMode != RM_Hardware || TextureFormat.bpp < 16 ) { // texture cannot be indexed in this case\n\t\t\treturn -1;\n\t\t}\n\t\tDWORD *tmpBmp = (DWORD *)calloc(4, SQR(side));\n\t\tDWORD *bmpDst = tmpBmp;\n\t\tDWORD *bmpSrc = (DWORD *)bitmap + x + y * pitch;\n\n\t\tfor( DWORD j = 0; j < height; ++j ) {\n\t\t\tmemcpy(bmpDst, bmpSrc, sizeof(DWORD) * width);\n\t\t\tbmpSrc += pitch;\n\t\t\tbmpDst += side;\n\t\t}\n\t\tFillEdgePadding(width, height, side, (BYTE *)tmpBmp, bpp);\n\t\tpageIndex = AddTexturePage32(side, side, (BYTE *)tmpBmp, false);\n\t\tfree(tmpBmp);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t} else if( SavedAppSettings.RenderMode == RM_Hardware && TextureFormat.bpp >= 16 ) {\n\t\tUINT16 *tmpBmp = (UINT16 *)calloc(2, SQR(side));\n\t\tUINT16 *bmpDst = tmpBmp;\n\t\tBYTE *bmpSrc = bitmap + x + y * pitch;\n\n\t\t// Translating bitmap data from 8 bit bitmap to 16 bit bitmap\n\t\tfor( DWORD j = 0; j < height; ++j ) {\n\t\t\tfor( DWORD i = 0; i < width; ++i ) {\n\t\t\t\tif( !keyColor || bmpSrc[i] ) {\n\t\t\t\t\tRGB888 *color = &bmpPal[bmpSrc[i]]; // get RGB color from palette\n\t\t\t\t\tbmpDst[i] = (1 << 15) // convert RGB to 16 bit\n\t\t\t\t\t\t\t| (((UINT16)color->red   >> 3) << 10)\n\t\t\t\t\t\t\t| (((UINT16)color->green >> 3) << 5)\n\t\t\t\t\t\t\t| (((UINT16)color->blue  >> 3));\n\t\t\t\t} else {\n\t\t\t\t\tbmpDst[i] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbmpSrc += pitch;\n\t\t\tbmpDst += side;\n\t\t}\n\t\tFillEdgePadding(width, height, side, (BYTE *)tmpBmp, 16);\n\t\tpageIndex = AddTexturePage16(side, side, (BYTE *)tmpBmp);\n\t\tfree(tmpBmp);\n\t} else if( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tBYTE *tmpBmp = (BYTE *)calloc(1, SQR(side));\n\t\tUT_MemBlt(tmpBmp, 0, 0, width, height, side, bitmap, x, y, pitch);\n\t\tFillEdgePadding(width, height, side, tmpBmp, 8);\n\t\tpageIndex = AddTexturePage8(side, side, tmpBmp, hwrPal);\n\t\tfree(tmpBmp);\n\t} else if( swrBuf != NULL && width == 256 && height == 256 && side == 256 ) {\n\t\tfor( DWORD i=0; i<ARRAY_SIZE(TexturePageBuffer8); ++i ) {\n\t\t\tif( TexturePageBuffer8[i] == NULL || TexturePageBuffer8[i] == swrBuf ) {\n\t\t\t\tUT_MemBlt(swrBuf, 0, 0, width, height, side, bitmap, x, y, pitch);\n\t\t\t\tTexturePageBuffer8[i] = swrBuf;\n\t\t\t\tpageIndex = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn pageIndex;\n}\n\n#if (DIRECT3D_VERSION >= 0x900)\n#define TEXPAGE_CONFIG_NAME \"textures/texpages/config.json\"\n\ntypedef struct {\n\tbool isLoaded;\n\tbool isLegacyColors;\n\tdouble adjustment;\n#ifdef FEATURE_HUD_IMPROVED\n\tstruct {\n\t\tint spacing;\n\t\tint xOffset;\n\t\tint yOffset;\n\t\tdouble xStretch;\n\t\tdouble yStretch;\n\t} glyphs[110];\n#endif // FEATURE_HUD_IMPROVED\n} TEXPAGES_CONFIG;\n\nstatic TEXPAGES_CONFIG TexPagesConfig;\n\nbool IsTexPagesConfigLoaded() {\n\treturn TexPagesConfig.isLoaded;\n}\n\nbool IsTexPagesLegacyColors() {\n\treturn TexPagesConfig.isLegacyColors;\n}\n\ndouble GetTexPagesAdjustment() {\n\treturn TexPagesConfig.adjustment;\n}\n\n#ifdef FEATURE_HUD_IMPROVED\nint GetTexPagesGlyphSpacing(int id) {\n\tif( id < 0 || id >= (int)ARRAY_SIZE(TexPagesConfig.glyphs)\n\t\t|| SavedAppSettings.RenderMode == RM_Software )\n\t{\n\t\treturn 0;\n\t}\n\treturn TexPagesConfig.glyphs[id].spacing;\n}\n\nint GetTexPagesGlyphXOffset(int id) {\n\tif( id < 0 || id >= (int)ARRAY_SIZE(TexPagesConfig.glyphs)\n\t\t|| SavedAppSettings.RenderMode == RM_Software )\n\t{\n\t\treturn 0;\n\t}\n\treturn TexPagesConfig.glyphs[id].xOffset;\n}\n\nint GetTexPagesGlyphYOffset(int id) {\n\tif( id < 0 || id >= (int)ARRAY_SIZE(TexPagesConfig.glyphs)\n\t\t|| SavedAppSettings.RenderMode == RM_Software )\n\t{\n\t\treturn 0;\n\t}\n\treturn TexPagesConfig.glyphs[id].yOffset;\n}\n\ndouble GetTexPagesGlyphXStretch(int id) {\n\tif( id < 0 || id >= (int)ARRAY_SIZE(TexPagesConfig.glyphs)\n\t\t|| SavedAppSettings.RenderMode == RM_Software\n\t\t|| TexPagesConfig.glyphs[id].xStretch <= 0.0 )\n\t{\n\t\treturn 1.0;\n\t}\n\treturn TexPagesConfig.glyphs[id].xStretch;\n}\n\ndouble GetTexPagesGlyphYStretch(int id) {\n\tif( id < 0 || id >= (int)ARRAY_SIZE(TexPagesConfig.glyphs)\n\t\t|| SavedAppSettings.RenderMode == RM_Software\n\t\t|| TexPagesConfig.glyphs[id].yStretch <= 0.0 )\n\t{\n\t\treturn 1.0;\n\t}\n\treturn TexPagesConfig.glyphs[id].yStretch;\n}\n#endif // FEATURE_HUD_IMPROVED\n\nstatic bool ParseLevelTexPagesConfiguration(json_value *root) {\n\tif( root == NULL || root->type != json_object ) {\n\t\treturn false;\n\t}\n\tjson_value* field = NULL;\n\n\tfield = GetJsonField(root, json_boolean, \"legacy_colors\", NULL);\n\tif( field ) {\n\t\tTexPagesConfig.isLegacyColors = field->u.boolean;\n\t}\n\n\tfield = GetJsonField(root, json_double, \"uv_adjust\", NULL);\n\tif( field ) {\n\t\tTexPagesConfig.adjustment = field->u.dbl;\n\t}\n\n#ifdef FEATURE_HUD_IMPROVED\n\tjson_value* glyphs = GetJsonField(root, json_array, \"glyphs\", NULL);\n\tif( glyphs ) {\n\t\tfor( DWORD i = 0; i < glyphs->u.array.length; ++i ) {\n\t\t\tjson_value *glyph = glyphs->u.array.values[i];\n\t\t\tint id = GetJsonIntegerFieldValue(glyph, \"id\", -1);\n\t\t\tif( id < 0 || id >= (int)ARRAY_SIZE(TexPagesConfig.glyphs) ) continue;\n\t\t\tTexPagesConfig.glyphs[id].spacing = GetJsonIntegerFieldValue(glyph, \"spacing\", 0);\n\t\t\tTexPagesConfig.glyphs[id].xOffset = GetJsonIntegerFieldValue(glyph, \"x_offset\", 0);\n\t\t\tTexPagesConfig.glyphs[id].yOffset = GetJsonIntegerFieldValue(glyph, \"y_offset\", 0);\n\t\t\tTexPagesConfig.glyphs[id].xStretch = GetJsonFloatFieldValue(glyph, \"x_stretch\", 1.0);\n\t\t\tTexPagesConfig.glyphs[id].yStretch = GetJsonFloatFieldValue(glyph, \"y_stretch\", 1.0);\n\t\t}\n\t}\n#endif // FEATURE_HUD_IMPROVED\n\n\treturn true;\n}\n\nstatic bool ParseTexPagesConfiguration(char *levelName, json_value *root) {\n\tif( root == NULL || root->type != json_object ) {\n\t\treturn false;\n\t}\n\t// parsing default configs\n\tParseLevelTexPagesConfiguration(GetJsonField(root, json_object, \"default\", NULL));\n\t// parsing level specific configs\n\tjson_value* levels = GetJsonField(root, json_array, \"levels\", NULL);\n\tif( levels ) ParseLevelTexPagesConfiguration(GetJsonObjectByStringField(levels, \"filename\", levelName, false, NULL));\n\treturn true;\n}\n\nvoid UnloadTexPagesConfiguration() {\n\tmemset(&TexPagesConfig, 0, sizeof(TexPagesConfig));\n}\n\nbool LoadTexPagesConfiguration(LPCTSTR levelFilePath) {\n\tUnloadTexPagesConfiguration();\n\tif( !PathFileExists(TEXPAGE_CONFIG_NAME) ) {\n\t\treturn false;\n\t}\n\tchar levelName[256] = {0};\n\tstrncpy(levelName, PathFindFileName(levelFilePath), sizeof(levelName)-1);\n\tchar *ext = PathFindExtension(levelName);\n\tif( ext != NULL ) *ext = 0;\n\n\tDWORD bytesRead = 0;\n\tHANDLE hFile = CreateFile(TEXPAGE_CONFIG_NAME, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN|FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile == INVALID_HANDLE_VALUE ) {\n\t\treturn false;\n\t}\n\tDWORD cfgSize = GetFileSize(hFile, NULL);\n\tvoid *cfgData = malloc(cfgSize);\n\tReadFile(hFile, cfgData, cfgSize, &bytesRead, NULL);\n\tCloseHandle(hFile);\n\n\tjson_value* json = json_parse((const json_char *)cfgData, cfgSize);\n\tif( json != NULL ) {\n\t\tTexPagesConfig.isLoaded = ParseTexPagesConfiguration(levelName, json);\n\t}\n\tjson_value_free(json);\n\tfree(cfgData);\n\treturn TexPagesConfig.isLoaded;\n}\n#endif // (DIRECT3D_VERSION >= 0x900)\n"
  },
  {
    "path": "modding/texture_utils.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef TEXTURE_UTILS_H_INCLUDED\n#define TEXTURE_UTILS_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#ifdef FEATURE_HUD_IMPROVED\n#define HUD_SPRITE_RESERVED (256)\n\nbool LoadButtonSprites();\nbool GetTextSpriteByName(const char *name, int nameLen, DWORD *sprite, int *spacing);\n#endif // FEATURE_HUD_IMPROVED\n\nint MakeCustomTexture(DWORD x, DWORD y, DWORD width, DWORD height, DWORD pitch, DWORD side, DWORD bpp, BYTE *bitmap, RGB888 *bmpPal, int hwrPal, BYTE *swrBuf, bool keyColor);\n\n#if (DIRECT3D_VERSION >= 0x900)\nbool IsTexPagesConfigLoaded();\nbool IsTexPagesLegacyColors();\ndouble GetTexPagesAdjustment();\n#ifdef FEATURE_HUD_IMPROVED\nint GetTexPagesGlyphSpacing(int id);\nint GetTexPagesGlyphXOffset(int id);\nint GetTexPagesGlyphYOffset(int id);\ndouble GetTexPagesGlyphXStretch(int id);\ndouble GetTexPagesGlyphYStretch(int id);\n#endif // FEATURE_HUD_IMPROVED\n\nvoid UnloadTexPagesConfiguration();\nbool LoadTexPagesConfiguration(LPCTSTR levelFilePath);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n#endif // TEXTURE_UTILS_H_INCLUDED\n"
  },
  {
    "path": "modding/xinput_ex.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"modding/xinput_ex.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n\n// Imports from xinput*.dll\nstatic HMODULE hXInput = NULL;\nstatic void (WINAPI *_XInputEnable)(WINBOOL) = NULL;\nstatic DWORD (WINAPI *_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES*) = NULL;\nstatic DWORD (WINAPI *_XInputSetState)(DWORD, XINPUT_VIBRATION*) = NULL;\nstatic DWORD (WINAPI *_XInputGetState)(DWORD, XINPUT_STATE*) = NULL;\n\nstatic void XInputLibUnlink() {\n\t_XInputEnable = NULL;\n\t_XInputSetState = NULL;\n\t_XInputGetState = NULL;\n\t_XInputGetCapabilities = NULL;\n\tif( hXInput != NULL ) {\n\t\tFreeLibrary(hXInput);\n\t\thXInput = NULL;\n\t}\n}\n\nstatic bool XInputLibLink(LPCSTR lpLibFileName, bool advanced) {\n\tHMODULE hXInput = LoadLibrary(lpLibFileName);\n\tif( hXInput == NULL ) {XInputLibUnlink(); return false;}\n\n\t// XInputEnable is optional, so don't check if it's NULL\n\t*(FARPROC *)&_XInputEnable = GetProcAddress(hXInput, \"XInputEnable\");\n\n\t*(FARPROC *)&_XInputGetCapabilities = GetProcAddress(hXInput, \"XInputGetCapabilities\");\n\tif( _XInputGetCapabilities == NULL ) {XInputLibUnlink(); return false;}\n\n\t*(FARPROC *)&_XInputSetState = GetProcAddress(hXInput, \"XInputSetState\");\n\tif( _XInputSetState == NULL ) {XInputLibUnlink(); return false;}\n\n\tif( advanced ) {\n\t\t// The hack to get XInput Guide button state, works for some xinput*.dll versions\n\t\t*(FARPROC *)&_XInputGetState = GetProcAddress(hXInput, MAKEINTRESOURCE(100));\n\t}\n\tif( _XInputGetState == NULL ) {\n\t\t*(FARPROC *)&_XInputGetState = GetProcAddress(hXInput, \"XInputGetState\");\n\t}\n\tif( _XInputGetState == NULL ) {XInputLibUnlink(); return false;}\n\n\treturn true;\n}\n\nstatic bool XInputLibInit() {\n\tstatic const struct {\n\t\tLPCSTR name; bool advanced;\n\t} libs[] = {\n\t\t{\"xinput1_4.dll\", true},\n\t\t{\"xinput1_3.dll\", true},\n\t\t{\"xinput9_1_0.dll\", false},\n\t\t{\"xinput1_2.dll\", false},\n\t\t{\"xinput1_1.dll\", false},\n\t};\n\tstatic bool failed = false;\n\tif( hXInput != NULL ) {\n\t\treturn true;\n\t} else if( failed ) {\n\t\treturn false;\n\t}\n\tfor( DWORD i=0; i<ARRAY_SIZE(libs); ++i ) {\n\t\tif( XInputLibLink(libs[i].name, libs[i].advanced) ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\tfailed = true;\n\treturn false;\n}\n\nvoid WINAPI XInputEnable(BOOL enable) {\n\tif( !XInputLibInit() || _XInputEnable == NULL ) {\n\t\treturn;\n\t}\n\t_XInputEnable(enable);\n}\n\nDWORD WINAPI XInputGetCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES *pCapabilities) {\n\tif( !XInputLibInit() || _XInputGetCapabilities == NULL ) {\n\t\treturn ERROR_DEVICE_NOT_CONNECTED;\n\t}\n\treturn _XInputGetCapabilities(dwUserIndex, dwFlags, pCapabilities);\n}\n\nDWORD WINAPI XInputSetState(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration) {\n\tif( !XInputLibInit() || _XInputSetState == NULL ) {\n\t\treturn ERROR_DEVICE_NOT_CONNECTED;\n\t}\n\treturn _XInputSetState(dwUserIndex, pVibration);\n}\n\nDWORD WINAPI XInputGetState(DWORD dwUserIndex, XINPUT_STATE *pState) {\n\tif( !XInputLibInit() || _XInputGetState == NULL ) {\n\t\treturn ERROR_DEVICE_NOT_CONNECTED;\n\t}\n\treturn _XInputGetState(dwUserIndex, pState);\n}\n\n// ----------------------- The ugly function by Microsoft -----------------------\n// Enum each PNP device using WMI and check each device ID to see if it contains\n// \"IG_\" (ex. \"VID_045E&PID_028E&IG_00\").  If it does, then it's an XInput device\n// Unfortunately this information can not be found by just using DirectInput\n// ------------------------------------------------------------------------------\n#include <wbemidl.h>\n#include <oleauto.h>\n\nBOOL IsXInputDevice(DWORD dwVendorId, DWORD dwProductId) {\n\tIWbemLocator* pIWbemLocator = NULL;\n\tIEnumWbemClassObject* pEnumDevices = NULL;\n\tIWbemClassObject* pDevices[20] = {0};\n\tIWbemServices* pIWbemServices = NULL;\n\tBSTR bstrNamespace = NULL;\n\tBSTR bstrDeviceID = NULL;\n\tBSTR bstrClassName = NULL;\n\tDWORD uReturned = 0;\n\tbool bIsXinputDevice = false;\n\tUINT iDevice = 0;\n\tVARIANT var;\n\tHRESULT hr;\n\n\t// CoInit if needed\n\thr = CoInitialize(NULL);\n\tbool bCleanupCOM = SUCCEEDED(hr);\n\n\t// Create WMI\n\thr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER,\n\t\t\t\t\t\t\t__uuidof(IWbemLocator), (LPVOID*) &pIWbemLocator);\n\tif( FAILED(hr) || pIWbemLocator == NULL ) goto LCleanup;\n\n\tbstrNamespace = SysAllocString(L\"\\\\\\\\.\\\\root\\\\cimv2\");\n\tif( bstrNamespace == NULL ) goto LCleanup;\n\n\tbstrClassName = SysAllocString(L\"Win32_PNPEntity\");\n\tif( bstrClassName == NULL ) goto LCleanup;\n\n\tbstrDeviceID = SysAllocString(L\"DeviceID\");\n\tif( bstrDeviceID == NULL ) goto LCleanup;\n\n\t// Connect to WMI\n\thr = pIWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices);\n\tif( FAILED(hr) || pIWbemServices == NULL ) goto LCleanup;\n\n\t// Switch security level to IMPERSONATE.\n\tCoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,\n\t\t\t\t\t\tRPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);\n\n\thr = pIWbemServices->CreateInstanceEnum(bstrClassName, 0, NULL, &pEnumDevices);\n\tif( FAILED(hr) || pEnumDevices == NULL ) goto LCleanup;\n\n\t// Loop over all devices\n\tfor( ;; ) {\n\t\t// Get 20 at a time\n\t\thr = pEnumDevices->Next(10000, 20, pDevices, &uReturned);\n\t\tif( FAILED(hr) ) goto LCleanup;\n\t\tif( uReturned == 0 ) break;\n\n\t\tfor( iDevice=0; iDevice<uReturned; iDevice++ ) {\n\t\t\t// For each device, get its device ID\n\t\t\thr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL);\n\t\t\tif( SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL ) {\n\t\t\t\t// Check if the device ID contains \"IG_\".  If it does, then it's an XInput device\n\t\t\t\tif( wcsstr(var.bstrVal, L\"IG_\") ) {\n\t\t\t\t\t// If it does, then get the VID/PID from var.bstrVal\n\t\t\t\t\tDWORD dwPid = 0, dwVid = 0;\n\t\t\t\t\tWCHAR* strVid = wcsstr( var.bstrVal, L\"VID_\" );\n\t\t\t\t\tif( strVid && swscanf( strVid, L\"VID_%4X\", &dwVid ) != 1 )\n\t\t\t\t\t\tdwVid = 0;\n\t\t\t\t\tWCHAR* strPid = wcsstr( var.bstrVal, L\"PID_\" );\n\t\t\t\t\tif( strPid && swscanf( strPid, L\"PID_%4X\", &dwPid ) != 1 )\n\t\t\t\t\t\tdwPid = 0;\n\n\t\t\t\t\t// Compare the VID/PID to the DInput device\n\t\t\t\t\tif( dwVendorId == dwVid && dwProductId == dwPid )\n\t\t\t\t\t{\n\t\t\t\t\t\tbIsXinputDevice = true;\n\t\t\t\t\t\tgoto LCleanup;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif( pDevices[iDevice] ) {\n\t\t\t\tpDevices[iDevice]->Release();\n\t\t\t\tpDevices[iDevice] = NULL;\n\t\t\t}\n\t\t}\n\t}\n\nLCleanup:\n\tif( bstrNamespace ) SysFreeString(bstrNamespace);\n\tif( bstrDeviceID ) SysFreeString(bstrDeviceID);\n\tif( bstrClassName ) SysFreeString(bstrClassName);\n\tfor( iDevice=0; iDevice<20; iDevice++ ) {\n\t\tif( pDevices[iDevice] ) pDevices[iDevice]->Release();\n\t}\n\tif( pEnumDevices ) pEnumDevices->Release();\n\tif( pIWbemLocator ) pIWbemLocator->Release();\n\tif( pIWbemServices ) pIWbemServices->Release();\n\tif( bCleanupCOM ) CoUninitialize();\n\treturn bIsXinputDevice;\n}\n\n#endif // FEATURE_INPUT_IMPROVED\n"
  },
  {
    "path": "modding/xinput_ex.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef XINPUT_EX_H_INCLUDED\n#define XINPUT_EX_H_INCLUDED\n\n#include \"global/types.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n// all essential definitions are inside XInput.h, but no static lib linked here\n#include <XInput.h>\n\n#ifndef XINPUT_GAMEPAD_GUIDE\n#define XINPUT_GAMEPAD_GUIDE (0x400)\n#endif // XINPUT_GAMEPAD_GUIDE\n\n#define XINPUT_DPAD(x) (CHK_ALL((x), XINPUT_GAMEPAD_DPAD_UP|XINPUT_GAMEPAD_DPAD_DOWN|XINPUT_GAMEPAD_DPAD_LEFT|XINPUT_GAMEPAD_DPAD_RIGHT))\n\nBOOL IsXInputDevice(DWORD dwVendorId, DWORD dwProductId);\n#endif // FEATURE_INPUT_IMPROVED\n\n#endif // XINPUT_EX_H_INCLUDED\n"
  },
  {
    "path": "specific/background.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/background.h\"\n#include \"specific/hwr.h\"\n#include \"specific/init.h\"\n#include \"specific/texture.h\"\n#include \"specific/utils.h\"\n#include \"global/vars.h\"\n#include <math.h>\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/background_new.h\"\n\nextern int PatternTexPage;\n\nDWORD InvBackgroundMode = 2;\nDWORD StatsBackgroundMode = 0;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\nvoid __cdecl BGND_Make640x480(BYTE *bitmap, RGB888 *palette) {\n\t// NOTE: 8 bit bitmap may be converted to 16 bit right in the tmpBuffer\n\t// so we need to allocate memory for 16 bit bitmap anyway\n\tDWORD tmpBufSize = 256*256*2;\n\tBYTE *tmpBuffer = (BYTE *)game_malloc(tmpBufSize, GBUF_TempAlloc);\n\n\tBGND_PaletteIndex = (TextureFormat.bpp < 16) ? CreateTexturePalette(palette) : -1;\n\n\tUT_MemBlt(tmpBuffer, 0, 0, 256, 256, 256, bitmap, 0, 0, 640);\n\tBGND_AddTexture(0, tmpBuffer, BGND_PaletteIndex, palette);\n\n\tUT_MemBlt(tmpBuffer, 0, 0, 256, 256, 256, bitmap, 256, 0, 640);\n\tBGND_AddTexture(1, tmpBuffer, BGND_PaletteIndex, palette);\n\n\tUT_MemBlt(tmpBuffer, 0,   0, 128, 256, 256, bitmap, 512, 0,   640);\n\tUT_MemBlt(tmpBuffer, 128, 0, 128, 224, 256, bitmap, 512, 256, 640);\n\tBGND_AddTexture(2, tmpBuffer, BGND_PaletteIndex, palette);\n\n\tUT_MemBlt(tmpBuffer, 0, 0, 256, 224, 256, bitmap, 0, 256, 640);\n\tBGND_AddTexture(3, tmpBuffer, BGND_PaletteIndex, palette);\n\n\tUT_MemBlt(tmpBuffer, 0, 0, 256, 224, 256, bitmap, 256, 256, 640);\n\tBGND_AddTexture(4, tmpBuffer, BGND_PaletteIndex, palette);\n\n\tgame_free(tmpBufSize);\n\tBGND_GetPageHandles();\n\tBGND_PictureIsReady = true;\n}\n\nint __cdecl BGND_AddTexture(int tileIndex, BYTE *bitmap, int palIndex, RGB888 *bmpPal) {\n\tint pageIndex;\n\tBYTE *bmpSrc;\n\tUINT16 *bmpDst;\n\n\t// If destination palette is absent we convert 8 bit to 16 bit right in the buffer\n\tif( palIndex < 0 ) {\n\t\tbmpDst = (UINT16 *)&bitmap[256*256*2]; // (16 bit bitmap end)\n\t\tbmpSrc = (BYTE *)&bitmap[256*256*1]; // (8 bit bitmap end / 16 bit bitmap center)\n\n\t\t// Translating bitmap data from 8 bit bitmap end to 16 bit bitmap end\n\t\tfor( int i=256*256; i>0; --i ) {\n\t\t\tRGB888 *color = &bmpPal[*(--bmpSrc)]; // get RGB color from palette\n\t\t\t*(--bmpDst) = (1 << 15) // convert RGB to 16 bit\n\t\t\t\t\t\t| (((UINT16)color->red   >> 3) << 10)\n\t\t\t\t\t\t| (((UINT16)color->green >> 3) << 5)\n\t\t\t\t\t\t| (((UINT16)color->blue  >> 3));\n\t\t}\n\n\t\t// Now both bmpSrc and bmpDst pointers = bitmap pointer\n\t\tpageIndex = AddTexturePage16(256, 256, bitmap);\n\t} else {\n\t\tpageIndex = AddTexturePage8(256, 256, bitmap, palIndex);\n\t}\n\n\tBGND_TexturePageIndexes[tileIndex] = ( pageIndex >= 0 ) ? pageIndex : -1;\n\treturn pageIndex;\n}\n\nvoid __cdecl BGND_GetPageHandles() {\n\tfor( DWORD i=0; i<ARRAY_SIZE(BGND_TexturePageIndexes); ++i ) {\n\t\tif( BGND_TexturePageIndexes[i] < 0 )\n\t\t\tBGND_PageHandles[i] = 0;\n\t\telse\n\t\t\tBGND_PageHandles[i] = GetTexturePageHandle(BGND_TexturePageIndexes[i]);\n\t}\n}\n\nvoid __cdecl BGND_DrawInGameBlack() {\n\tHWR_EnableZBuffer(false, false);\n\tDrawQuad((float)PhdWinMinX, (float)PhdWinMinY, (float)PhdWinWidth, (float)PhdWinHeight, 0); // black colored screen sized quad\n\tHWR_EnableZBuffer(true, true);\n}\n\nvoid __cdecl DrawQuad(float sx, float sy, float width, float height, D3DCOLOR color) {\n\tD3DTLVERTEX vertex[4];\n\n\tvertex[0].sx = sx;\n\tvertex[0].sy = sy;\n\n\tvertex[1].sx = sx + width;\n\tvertex[1].sy = sy;\n\n\tvertex[2].sx = sx;\n\tvertex[2].sy = sy + height;\n\n\tvertex[3].sx = sx + width;\n\tvertex[3].sy = sy + height;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tvertex[i].sz = 0;\n\t\tvertex[i].rhw = FltRhwONearZ;\n\t\tvertex[i].color = RGBA_SETALPHA(color, 0xFF);\n\t\tvertex[i].specular = 0;\n\t}\n\n\tHWR_TexSource(0);\n\tHWR_EnableColorKey(false);\n\tHWR_DrawPrimitive(D3DPT_TRIANGLESTRIP, &vertex, 4, true);\n}\n\nvoid __cdecl BGND_DrawInGameBackground() {\n\t__int16 *meshPtr;\n\tint numVertices, numNormals, numQuads;\n\tDWORD textureIndex;\n\tPHD_TEXTURE *textureInfo;\n\tint x0, y0, x1, y1;\n\tint x_current, y_current, x_next, y_next;\n\tint x_count, y_count;\n\tint y0_pos, y1_pos;\n\tint tu, tv, twidth, theight;\n\tHWR_TEXHANDLE texSource;\n\tD3DCOLOR color[4];\n\n\tif( !Objects[ID_INV_BACKGROUND].loaded ) {\n\t\t// NOTE: some additional checks are absent in the original code, so I've added few\n\t\tBGND_DrawInGameBlack();\n\t\treturn;\n\t}\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tDWORD bgndMode = IsInventoryActive ? InvBackgroundMode : StatsBackgroundMode;\n\tif( bgndMode != 1 && bgndMode != 2 ) {\n\t\tBGND_DrawInGameBlack();\n\t\treturn;\n\t}\n\n\tif( PatternTexPage >= 0 ) {\n\t\ttu = tv = 0;\n\t\ttwidth = theight = 256;\n\t\ttexSource = HWR_PageHandles[PatternTexPage];\n\t} else {\n\t\tmeshPtr = MeshPtr[Objects[ID_INV_BACKGROUND].meshIndex];\n\t\tmeshPtr += 3+2; // skip mesh coords (3*INT16) and radius (1*INT32)\n\n\t\tnumVertices = *(meshPtr++);\n\t\tmeshPtr += numVertices*3; // skip vertices (each one is 3xINT16)\n\n\t\tnumNormals = *(meshPtr++);\n\t\tif( numNormals >= 0 ) // negative num means lights instead of normals\n\t\t\tmeshPtr += numNormals*3; // skip normals (each is 3xINT16)\n\t\telse\n\t\t\tmeshPtr -= numNormals; // skip lights (each one is INT16)\n\n\t\tnumQuads = *(meshPtr++);\n\t\tif( numQuads < 1 ) {\n\t\t\tBGND_DrawInGameBlack();\n\t\t\treturn;\n\t\t}\n\t\tmeshPtr += 4; // skip 4 vertice indices of 1st textured quad (each one is INT16)\n\t\ttextureIndex = *(meshPtr++); // get texture index of 1st textured quad.\n\n\t\ttextureInfo = &PhdTextureInfo[textureIndex];\n\t\ttexSource = HWR_PageHandles[textureInfo->tpage];\n\n\t\ttu = textureInfo->uv[0].u / PHD_HALF;\n\t\ttv = textureInfo->uv[0].v / PHD_HALF;\n\t\ttwidth  = textureInfo->uv[2].u / PHD_HALF - tu + 1;\n\t\ttheight = textureInfo->uv[2].v / PHD_HALF - tv + 1;\n\t}\n\n\tHWR_EnableZBuffer(false, false);\n\tif( PatternTexPage >= 0 ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);\n\t\tD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREADDRESS, D3DTADDRESS_WRAP);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n\n\tif( bgndMode == 2 ) {\n\t\tstatic const int shortWaveStep = -0x0267; // minus 3.92 degrees\n\t\tstatic const int longWaveStep  = -0x0200; // minus 2.81 degrees\n\n\t\tstatic UINT16 deformWavePhase = 0x0000; // 0 degrees\n\t\tstatic UINT16 shortWavePhase = 0x4000; // 90 degrees\n\t\tstatic UINT16 longWavePhase = 0xA000; // 225 degrees\n\n\t\tPSX_Background(texSource, tu, tv, twidth, theight, 3, 10, deformWavePhase, shortWavePhase, longWavePhase);\n\n\t\tdeformWavePhase += shortWaveStep;\n\t\tshortWavePhase  += shortWaveStep;\n\t\tlongWavePhase   += longWaveStep;\n\n\t\tgoto CLEANUP;\n\t}\n\n\ty_count = 6;\n\tx_count = MulDiv(y_count, PhdWinWidth, PhdWinHeight);\n\n#else // !FEATURE_BACKGROUND_IMPROVED\n\tmeshPtr = MeshPtr[Objects[ID_INV_BACKGROUND].meshIndex];\n\tmeshPtr += 3+2; // skip mesh coords (3*INT16) and radius (1*INT32)\n\n\tnumVertices = *(meshPtr++);\n\tmeshPtr += numVertices*3; // skip vertices (each one is 3xINT16)\n\n\tnumNormals = *(meshPtr++);\n\tif( numNormals >= 0 ) // negative num means lights instead of normals\n\t\tmeshPtr += numNormals*3; // skip normals (each is 3xINT16)\n\telse // NOTE: additional check. Absent in the original code\n\t\tmeshPtr -= numNormals; // skip lights (each one is INT16)\n\n\tnumQuads = *(meshPtr++);\n\tif( numQuads < 1 ) {\n\t\t// NOTE: additional check. Absent in the original code\n\t\tBGND_DrawInGameBlack();\n\t\treturn;\n\t}\n\tmeshPtr += 4; // skip 4 vertice indices of 1st textured quad (each one is INT16)\n\ttextureIndex = *(meshPtr++); // get texture index of 1st textured quad.\n\n\ttextureInfo = &PhdTextureInfo[textureIndex];\n\ttexSource = HWR_PageHandles[textureInfo->tpage];\n\n\ttu = textureInfo->uv[0].u / PHD_HALF;\n\ttv = textureInfo->uv[0].v / PHD_HALF;\n\ttwidth  = textureInfo->uv[2].u / PHD_HALF - tu + 1;\n\ttheight = textureInfo->uv[2].v / PHD_HALF - tv + 1;\n\n\tHWR_EnableZBuffer(false, false);\n\n\tx_count = 8;\n\ty_count = 6;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\ty_current = 0;\n\tfor( int i=0; i<y_count; ++i ) {\n\t\ty_next = y_current + PhdWinHeight;\n\n\t\ty0_pos = y_current / y_count;\n\t\ty1_pos = y_next / y_count;\n\n\t\tx_current = 0;\n\t\tfor( int j=0; j<x_count; ++j ) {\n\t\t\tx_next = x_current + PhdWinWidth;\n\n\t\t\tx0 = PhdWinMinX + x_current / x_count;\n\t\t\ty0 = y0_pos + PhdWinMinY;\n\t\t\tx1 = PhdWinMinX + x_next / x_count;\n\t\t\ty1 = y1_pos + PhdWinMinY;\n\n\t\t\tcolor[0] = BGND_CenterLighting(x0, y0, PhdWinWidth, PhdWinHeight);\n\t\t\tcolor[1] = BGND_CenterLighting(x1, y0, PhdWinWidth, PhdWinHeight);\n\t\t\tcolor[2] = BGND_CenterLighting(x0, y1, PhdWinWidth, PhdWinHeight);\n\t\t\tcolor[3] = BGND_CenterLighting(x1, y1, PhdWinWidth, PhdWinHeight);\n\n\t\t\tDrawTextureTile(x0, y0, x1-x0, y1-y0, texSource, tu, tv, twidth, theight,\n\t\t\t\t\t\t\tcolor[0], color[1], color[2], color[3]);\n\n\t\t\tx_current = x_next;\n\t\t}\n\t\ty_current = y_next;\n\t}\n#ifdef FEATURE_BACKGROUND_IMPROVED\nCLEANUP:\n\tif( PatternTexPage >= 0 ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);\n\t\tD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREADDRESS, D3DTADDRESS_CLAMP);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tHWR_EnableZBuffer(true, true);\n}\n\nvoid __cdecl DrawTextureTile(int sx, int sy, int width, int height, HWR_TEXHANDLE texSource,\n\t\t\t\t\t\t\t int tu, int tv, int t_width, int t_height,\n\t\t\t\t\t\t\t D3DCOLOR color0, D3DCOLOR color1, D3DCOLOR color2, D3DCOLOR color3)\n{\n\tfloat sx0, sy0, sx1, sy1;\n\tfloat tu0, tv0, tu1, tv1;\n\tdouble uvAdjust;\n\tD3DTLVERTEX vertex[4];\n\n\tsx0 = (double)sx;\n\tsy0 = (double)sy;\n\tsx1 = (double)(sx + width);\n\tsy1 = (double)(sy + height);\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\ttu0 = (double)tu / 256.0;\n\ttv0 = (double)tv / 256.0;\n\ttu1 = (double)(tu + t_width)  / 256.0;\n\ttv1 = (double)(tv + t_height) / 256.0;\n\n\tif( PatternTexPage < 0 ) {\n\t\tuvAdjust = (double)UvAdd / (double)(256 * GetTextureSideByHandle(texSource));\n\t\tCLAMPL(uvAdjust, 1.0/double(PHD_ONE));\n\t\ttu0 += uvAdjust;\n\t\ttv0 += uvAdjust;\n\t\ttu1 -= uvAdjust;\n\t\ttv1 -= uvAdjust;\n\t}\n#else // FEATURE_BACKGROUND_IMPROVED\n\t// NOTE: page side is not counted in the original game, but we need it for HD textures\n\tuvAdjust = (double)UvAdd / (double)(256 * GetTextureSideByHandle(texSource));\n\tCLAMPL(uvAdjust, 1.0/double(PHD_ONE));\n\ttu0 = (double)tu / 256.0 + uvAdjust;\n\ttv0 = (double)tv / 256.0 + uvAdjust;\n\ttu1 = (double)(tu + t_width)  / 256.0 - uvAdjust;\n\ttv1 = (double)(tv + t_height) / 256.0 - uvAdjust;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\tvertex[0].sx = sx0;\n\tvertex[0].sy = sy0;\n\tvertex[0].color = color0;\n\tvertex[0].tu = tu0;\n\tvertex[0].tv = tv0;\n\n\tvertex[1].sx = sx1;\n\tvertex[1].sy = sy0;\n\tvertex[1].color = color1;\n\tvertex[1].tu = tu1;\n\tvertex[1].tv = tv0;\n\n\tvertex[2].sx = sx0;\n\tvertex[2].sy = sy1;\n\tvertex[2].color = color2;\n\tvertex[2].tu = tu0;\n\tvertex[2].tv = tv1;\n\n\tvertex[3].sx = sx1;\n\tvertex[3].sy = sy1;\n\tvertex[3].color = color3;\n\tvertex[3].tu = tu1;\n\tvertex[3].tv = tv1;\n\n\tfor( int i=0; i<4; ++i ) {\n\t\tvertex[i].sz = 0.995;\n\t\tvertex[i].rhw = RhwFactor / FltFarZ;\n\t\tvertex[i].specular = 0;\n\t}\n\n\tHWR_TexSource(texSource);\n\tHWR_EnableColorKey(false);\n\tHWR_DrawPrimitive(D3DPT_TRIANGLESTRIP, &vertex, 4, true);\n}\n\nD3DCOLOR __cdecl BGND_CenterLighting(int x, int y, int width, int height) {\n\tdouble xDist, yDist;\n\tint light;\n\n\txDist = (double)(x - (width/2)) / (double)width; // xDist range will be: -0.5..0.5\n\tyDist = (double)(y - (height/2)) / (double)height; // yDist range will be: -0.5..0.5\n\tlight = 256 - (sqrt(xDist * xDist + yDist * yDist) * 300.0); // light range will be: 44..256\n\n#if defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.LightingMode ) light /= 2;\n#endif // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\n\t// Do light range checks just in case\n\tCLAMP(light, 0, 255);\n\t// combine gray color using light value\n\treturn RGBA_MAKE(light, light, light, 0xFFu);\n}\n\nvoid __cdecl BGND_Free() {\n\tfor( DWORD i=0; i<ARRAY_SIZE(BGND_TexturePageIndexes); ++i ) {\n\t\tif( BGND_TexturePageIndexes[i] >= 0 ) {\n\t\t\tSafeFreeTexturePage(BGND_TexturePageIndexes[i]);\n\t\t\tBGND_TexturePageIndexes[i] = -1;\n\t\t}\n\t\tBGND_PageHandles[i] = 0;\n\t}\n\n\tif( BGND_PaletteIndex >= 0 ) {\n\t\tSafeFreePalette(BGND_PaletteIndex);\n\t\tBGND_PaletteIndex = -1;\n\t}\n}\n\nbool __cdecl BGND_Init() {\n\tBGND_PictureIsReady = false;\n\tBGND_PaletteIndex = -1;\n\n\tfor( DWORD i=0; i<ARRAY_SIZE(BGND_TexturePageIndexes); ++i )\n\t\tBGND_TexturePageIndexes[i] = -1;\n\n\treturn true;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Background() {\n\tINJECT(0x00443A40, BGND_Make640x480);\n\tINJECT(0x00443C00, BGND_AddTexture);\n\tINJECT(0x00443CC0, BGND_GetPageHandles);\n\tINJECT(0x00443D00, BGND_DrawInGameBlack);\n\tINJECT(0x00443D60, DrawQuad);\n\tINJECT(0x00443E40, BGND_DrawInGameBackground);\n\tINJECT(0x00444060, DrawTextureTile);\n\tINJECT(0x004442C0, BGND_CenterLighting);\n\tINJECT(0x00444570, BGND_Free);\n\tINJECT(0x004445C0, BGND_Init);\n}\n"
  },
  {
    "path": "specific/background.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef BACKGROUND_H_INCLUDED\n#define BACKGROUND_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl BGND_Make640x480(BYTE *bitmap, RGB888 *palette); // 0x00443A40\nint __cdecl BGND_AddTexture(int tileIndex, BYTE *bitmap, int palIndex, RGB888 *bmpPal); // 0x00443C00\nvoid __cdecl BGND_GetPageHandles(); // 0x00443CC0\nvoid __cdecl BGND_DrawInGameBlack(); // 0x00443D00\nvoid __cdecl DrawQuad(float sx, float sy, float width, float height, D3DCOLOR color); // 0x00443D60\nvoid __cdecl BGND_DrawInGameBackground(); // 0x00443E40\nvoid __cdecl DrawTextureTile(int sx, int sy, int width, int height, HWR_TEXHANDLE texSource,\n\t\t\t\t\t\t\t int tu, int tv, int t_width, int t_height,\n\t\t\t\t\t\t\t D3DCOLOR color0, D3DCOLOR color1, D3DCOLOR color2, D3DCOLOR color3); // 0x00444060\nD3DCOLOR __cdecl BGND_CenterLighting(int x, int y, int width, int height); // 0x004442C0\nvoid __cdecl BGND_Free(); // 0x00444570\nbool __cdecl BGND_Init(); // 0x004445C0\n\n#endif // BACKGROUND_H_INCLUDED\n"
  },
  {
    "path": "specific/display.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/display.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"specific/output.h\"\n#include \"global/vars.h\"\n\nvoid __cdecl IncreaseScreenSize() {\n\tif( ScreenSizer < 1.0 ) {\n\t\tScreenSizer += 0.08;\n\t\tif( ScreenSizer > 1.0 ) {\n\t\t\tScreenSizer = 1.0;\n\t\t}\n\t\tGameSizer = ScreenSizer;\n\t\tsetup_screen_size();\n\t}\n}\n\nvoid __cdecl DecreaseScreenSize() {\n\tif( ScreenSizer > 0.44 ) {\n\t\tScreenSizer -= 0.08;\n\t\tif( ScreenSizer < 0.44 ) {\n\t\t\tScreenSizer = 0.44;\n\t\t}\n\t\tGameSizer = ScreenSizer;\n\t\tsetup_screen_size();\n\t}\n}\n\nvoid __cdecl setup_screen_size() {\n\tint wwidth, wheight;\n\tint xoff, yoff;\n\n\twwidth = (int)((double)GameVidWidth * ScreenSizer);\n\twheight = (int)((double)GameVidHeight * ScreenSizer);\n\n\tif( wwidth > GameVidWidth )\n\t\twwidth = GameVidWidth;\n\n\tif( wheight > GameVidHeight )\n\t\twheight = GameVidHeight;\n\n\txoff = (GameVidWidth - wwidth) / 2;\n\tyoff = (GameVidHeight - wheight) / 2;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tphd_InitWindow(xoff, yoff, wwidth, wheight, VIEW_NEAR, VIEW_FAR, 80, GameVidWidth, GameVidHeight);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tphd_InitWindow(xoff, yoff, wwidth, wheight, VIEW_NEAR, VIEW_FAR, 80, GameVidBufWidth, GameVidBufHeight);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tDumpX = xoff;\n\tDumpY = yoff;\n\tDumpWidth = wwidth;\n\tDumpHeight = wheight;\n\n\tWinVidNeedToResetBuffers = true;\n}\n\nvoid __cdecl TempVideoAdjust(int hires, double sizer) {\n\tIsVidSizeLock = TRUE;\n\tif( ScreenSizer != sizer ) {\n\t\tScreenSizer = sizer;\n\t\tsetup_screen_size();\n\t}\n}\n\nvoid __cdecl TempVideoRemove() {\n\tIsVidSizeLock = FALSE;\n\tif( ScreenSizer != GameSizer ) {\n\t\tScreenSizer = GameSizer;\n\t\tsetup_screen_size();\n\t}\n}\n\nvoid __cdecl S_FadeInInventory(BOOL isFade) {\n\tif( InventoryMode != INV_TitleMode )\n\t\tS_CopyScreenToBuffer();\n\n\tif( isFade ) {\n\t\tFadeValue = 0x100000;\n\t\tFadeLimit = 0x180000;\n\t\tFadeAdder = +0x08000;\n\t}\n}\n\nvoid __cdecl S_FadeOutInventory(BOOL isFade) {\n\tif( isFade ) {\n\t\tFadeValue = 0x180000;\n\t\tFadeLimit = 0x100000;\n\t\tFadeAdder = -0x08000;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Display() {\n\tINJECT(0x004478C0, IncreaseScreenSize);\n\tINJECT(0x00447930, DecreaseScreenSize);\n\tINJECT(0x004479A0, setup_screen_size);\n\tINJECT(0x00447A40, TempVideoAdjust);\n\tINJECT(0x00447A80, TempVideoRemove);\n\tINJECT(0x00447AC0, S_FadeInInventory);\n\tINJECT(0x00447B00, S_FadeOutInventory);\n}\n"
  },
  {
    "path": "specific/display.h",
    "content": "/*\n * Copyright (c) 2017 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef DISPLAY_H_INCLUDED\n#define DISPLAY_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl IncreaseScreenSize(); // 0x004478C0\nvoid __cdecl DecreaseScreenSize(); // 0x00447930\nvoid __cdecl setup_screen_size(); // 0x004479A0\nvoid __cdecl TempVideoAdjust(int hires, double sizer); // 0x00447A40\nvoid __cdecl TempVideoRemove(); // 0x00447A80\nvoid __cdecl S_FadeInInventory(BOOL isFade); // 0x00447AC0\nvoid __cdecl S_FadeOutInventory(BOOL isFade); // 0x00447B00\n\n#endif // DISPLAY_H_INCLUDED\n"
  },
  {
    "path": "specific/file.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/file.h\"\n#include \"game/invfunc.h\"\n#include \"game/items.h\"\n#include \"game/setup.h\"\n#include \"specific/frontend.h\"\n#include \"specific/hwr.h\"\n#include \"specific/init.h\"\n#include \"specific/init_sound.h\"\n#include \"specific/output.h\"\n#include \"specific/texture.h\"\n#include \"specific/winvid.h\"\n#include \"global/vars.h\"\n\n#define REQ_SCRIPT_VERSION\t(3)\n#define DESCRIPTION_LENGTH\t(256)\n#define REQ_GAME_STR_COUNT\t(89)\n#define SPECIFIC_STR_COUNT\t(41)\n\n#define READ_STRINGS(count, lpTable, lpBuffer, lpRead, hFile, failLabel) { \\\n\tif( NULL == ((lpTable)=(char **)GlobalAlloc(GMEM_FIXED, sizeof(char*) * (count))) || \\\n\t\t!Read_Strings((count), (lpTable), (lpBuffer), (lpRead), (hFile)) ) goto failLabel; \\\n}\n\n#ifdef FEATURE_GOLD\nextern bool IsGold();\n#endif\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/background_new.h\"\n\nextern bool LoadingScreensEnabled;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#if defined(FEATURE_MOD_CONFIG) || defined(FEATURE_VIDEOFX_IMPROVED)\n#include \"modding/mod_utils.h\"\n#endif // defined(FEATURE_MOD_CONFIG) || defined(FEATURE_VIDEOFX_IMPROVED)\n\n#ifdef FEATURE_HUD_IMPROVED\n#include \"modding/texture_utils.h\"\n#endif // FEATURE_HUD_IMPROVED\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nstatic bool MarkSemitransPoly(__int16 *ptrObj, int vtxCount, bool colored, LPVOID param) {\n\tUINT16 index = ptrObj[vtxCount];\n\tif( colored ) {\n\t\tGamePalette16[index >> 8].peFlags = 1; // semitransparent blending mode 1\n\t} else {\n\t\tPhdTextureInfo[index].drawtype = DRAW_Semitrans;\n\t}\n\treturn true;\n}\n\nstatic bool MarkSemitransMesh(int objID, int meshIdx, POLYFILTER *filter) {\n\tif( objID < 0 ) return false;\n\t__int16 *ptrObj = NULL;\n\t// if mesh index is negative, then it's a static mesh\n\tif( meshIdx < 0 ) {\n\t\tif( (DWORD)objID >= ARRAY_SIZE(StaticObjects) ) return false;\n\t\tSTATIC_INFO *obj = &StaticObjects[objID];\n\t\tif( !CHK_ANY(obj->flags, 2) ) return false; // no such drawable static for patching\n\t\tptrObj = MeshPtr[obj->meshIndex];\n\t} else {\n\t\tif( (DWORD)objID >= ARRAY_SIZE(Objects) ) return false;\n\t\tOBJECT_INFO *obj = &Objects[objID];\n\t\tif( !obj->loaded || meshIdx >= obj->nMeshes ) return false; // no such object/mesh for patching\n\t\tptrObj = MeshPtr[obj->meshIndex + meshIdx];\n\t}\n\treturn EnumeratePolys(ptrObj, false, MarkSemitransPoly, filter, NULL);\n}\n\nstatic void MarkSemitransObjects() {\n#ifdef FEATURE_MOD_CONFIG\n\t// Check if config is presented\n\tif( IsModSemitransConfigLoaded() ) {\n\t\tPOLYFILTER_NODE *node = NULL;\n\t\tPOLYFILTER_NODE **obj = GetModSemitransObjectsFilter();\n\t\tfor( int i=0; i<ID_NUMBER_OBJECTS; ++i ) {\n\t\t\tfor( node = obj[i]; node != NULL; node = node->next ) {\n\t\t\t\tMarkSemitransMesh(i, node->id, &node->filter);\n\t\t\t}\n\t\t}\n\t\tfor( node = GetModSemitransStaticsFilter(); node != NULL; node = node->next ) {\n\t\t\tMarkSemitransMesh(node->id, -1, &node->filter);\n\t\t}\n\t\tfor( node = GetModSemitransRoomsFilter(); node != NULL; node = node->next ) {\n\t\t\tif( node->id >= 0 && node->id < RoomCount ) {\n\t\t\t\tEnumeratePolys(RoomInfo[node->id].data, true, MarkSemitransPoly, &node->filter, NULL);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n#endif // FEATURE_MOD_CONFIG\n\n\t// If config is absent or disabled, use hardcoded params\n\tstatic POLYFILTER SkidooFastFilter = {\n\t\t.n_vtx = 59, .n_gt4 = 14, .n_gt3 = 104, .n_g4 = 0, .n_g3 = 0,\n\t\t.gt4 = {{~0,~0}}, // no semitrans textured quads\n\t\t.gt3 = {{48, 4}, {54, 18}, {73, 6}, {0, 0}},\n\t\t.g4 = {{~0,~0}}, // no semitrans colored quads\n\t\t.g3 = {{~0,~0}}, // no semitrans colored triangles\n\t};\n\tstatic POLYFILTER DetailOptionFilter = {\n\t\t.n_vtx = 80, .n_gt4 = 66, .n_gt3 = 4, .n_g4 = 2, .n_g3 = 0,\n\t\t.gt4 = {{23, 8}, {44, 8}, {0, 0}},\n\t\t.gt3 = {{0, 0}}, // all textured triangles are semitrans\n\t\t.g4 = {{~0,~0}}, // no semitrans colored quads\n\t\t.g3 = {{~0,~0}}, // no semitrans colored triangles\n\t};\n\tstatic POLYFILTER GlassOnSinkFilter_Home = {\n\t\t.n_vtx = 46, .n_gt4 = 41, .n_gt3 = 0, .n_g4 = 0, .n_g3 = 0,\n\t\t.gt4 = {{17, 9}, {0, 0}},\n\t\t.gt3 = {{~0,~0}}, // no semitrans textured triangles\n\t\t.g4 = {{~0,~0}}, // no semitrans colored quads\n\t\t.g3 = {{~0,~0}}, // no semitrans colored triangles\n\t};\n\tstatic POLYFILTER GlassOnSinkFilter_Vegas = {\n\t\t.n_vtx = 46, .n_gt4 = 60, .n_gt3 = 0, .n_g4 = 0, .n_g3 = 0,\n\t\t.gt4 = {{23, 10}, {0, 0}},\n\t\t.gt3 = {{~0,~0}}, // no semitrans textured triangles\n\t\t.g4 = {{~0,~0}}, // no semitrans colored quads\n\t\t.g3 = {{~0,~0}}, // no semitrans colored triangles\n\t};\n\tMarkSemitransMesh(ID_SKIDOO_FAST, 0, &SkidooFastFilter);\n\tMarkSemitransMesh(ID_DETAIL_OPTION, 0, &DetailOptionFilter);\n\tMarkSemitransMesh(ID_SPHERE_OF_DOOM1, 0, NULL);\n\tMarkSemitransMesh(ID_SPHERE_OF_DOOM2, 0, NULL);\n\tMarkSemitransMesh(ID_FLARE_FIRE, 0, NULL);\n\tMarkSemitransMesh(ID_GUN_FLASH, 0, NULL);\n\tMarkSemitransMesh(ID_M16_FLASH, 0, NULL);\n\tMarkSemitransMesh(21, -1, &GlassOnSinkFilter_Home); // Lara's Home / Home Sweet Home\n\tMarkSemitransMesh(0, -1, &GlassOnSinkFilter_Vegas); // Nightmare in Vegas\n}\n\nstatic void MarkSemitransTextureRanges() {\n\tPOLYINDEX *filter = NULL;\n\t__int16 *ptr = AnimatedTextureRanges;\n\n#ifdef FEATURE_MOD_CONFIG\n\tfilter = GetModSemitransAnimtexFilter();\n\t// Check if filter is presented\n\tif( filter != NULL && (filter[0].idx || filter[0].num) ) {\n\t\tint polyIndex = 0;\n\t\tint polyNumber = *(ptr++);\n\t\tfor( int i=0; i<POLYFILTER_SIZE; ++i ) {\n\t\t\tif( filter[i].idx < polyIndex || filter[i].idx >= polyNumber ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint skip = filter[i].idx - polyIndex;\n\t\t\tpolyIndex += skip;\n\t\t\tif( polyIndex >= polyNumber ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\twhile( skip-- > 0 ) {\n\t\t\t\tint len = 1 + *(ptr++);\n\t\t\t\tptr += len;\n\t\t\t}\n\t\t\tint number = MIN(filter[i].num, polyNumber - polyIndex);\n\t\t\tpolyIndex += number;\n\t\t\twhile( number-- > 0 ) {\n\t\t\t\tfor( int j = *(ptr++); j>=0; --j, ++ptr ) {\n\t\t\t\t\tPhdTextureInfo[*ptr].drawtype = DRAW_Semitrans;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n#endif // FEATURE_MOD_CONFIG\n\n\t// If filter is absent or disabled, do it in automatic mode\n\tfor( int i = *(ptr++); i>0; --i ) {\n\t\tfor( int j = *(ptr++); j>=0; --j, ++ptr ) {\n\t\t\tif( filter != NULL || PhdTextureInfo[*ptr].drawtype == DRAW_ColorKey ) {\n\t\t\t\t// all animated room textures with colorkey are supposed to be semitransparent\n\t\t\t\tPhdTextureInfo[*ptr].drawtype = DRAW_Semitrans;\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid UpdateDepthQ(bool isReset) {\n\tstatic DEPTHQ_ENTRY depthQBackup[15];\n\tif( isReset ) {\n\t\tmemcpy(depthQBackup, DepthQTable, sizeof(DEPTHQ_ENTRY) * 15);\n\t\treturn;\n\t}\n\tswitch( SavedAppSettings.LightingMode ) {\n\tcase 0:\n\t\tfor( DWORD i = 0; i < 15; ++i ) {\n\t\t\tDepthQTable[i] = DepthQTable[15];\n\t\t}\n\t\tbreak;\n\tcase 1:\n\t\tmemcpy(&DepthQTable[7], &depthQBackup[7], sizeof(DEPTHQ_ENTRY) * 8);\n\t\tfor( DWORD i = 0; i < 7; ++i ) {\n\t\t\tDepthQTable[i] = DepthQTable[7];\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tmemcpy(DepthQTable, depthQBackup, sizeof(DEPTHQ_ENTRY) * 15);\n\t\tbreak;\n\t}\n}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n#if defined(FEATURE_MOD_CONFIG)\nbool BarefootSfxEnabled = true;\n\nstatic void LoadBareFootSFX(int *sampleIndexes, int sampleCount) {\n\tif( !BarefootSfxEnabled || !IsModBarefoot() || !sampleIndexes || sampleCount < 1 ) return;\n\n\tLPCTSTR sfxFileName = GetFullPath(\"data\\\\barefoot.sfx\");\n\tif( !PathFileExists(sfxFileName) ) return;\n\n\tHANDLE hSfxFile = CreateFile(sfxFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hSfxFile == INVALID_HANDLE_VALUE ) return;\n\n\tint i, j;\n\tfor( i=0, j=0; i < sampleCount; ++j ) {\n\t\tDWORD bytesRead;\n\t\tWAVEPCM_HEADER waveHeader;\n\t\tReadFileSync(hSfxFile, &waveHeader, sizeof(WAVEPCM_HEADER), &bytesRead, NULL);\n\n\t\tif( waveHeader.dwRiffChunkID != 0x46464952 || // \"RIFF\"\n\t\t\twaveHeader.dwFormat != 0x45564157 || // \"WAVE\"\n\t\t\twaveHeader.dwDataSubchunkID != 0x61746164 ) // \"data\"\n\t\t{\n\t\t\tCloseHandle(hSfxFile);\n\t\t\treturn;\n\t\t}\n\n\t\tDWORD dataSize = (waveHeader.dwDataSubchunkSize + 1) & ~1; // aligned data size\n\t\tLPWAVEFORMATEX waveFormat = (LPWAVEFORMATEX)&waveHeader.wFormatTag;\n\t\twaveFormat->cbSize = 0;\n\n\t\tif( sampleIndexes[i] == j ) {\n\t\t\tLPVOID waveData = game_malloc(dataSize, GBUF_Samples);\n\t\t\tReadFileSync(hSfxFile, waveData, dataSize, &bytesRead, NULL);\n\t\t\tWinSndMakeSample(i, waveFormat, waveData, dataSize);\n\t\t\tgame_free(dataSize);\n\t\t\t++i;\n\t\t} else {\n\t\t\tSetFilePointer(hSfxFile, dataSize, NULL, FILE_CURRENT);\n\t\t}\n\t}\n\tfor( i=0; i<4; ++i ) { // there are no more than 4 barefoot step samples\n\t\tif( SampleInfos[i].sfxID >= 4 ) break;\n\t\t// SFX parameters are taken from the PlayStation version\n\t\tSampleInfos[i].volume = 0x3332;\n\t\tSampleInfos[i].randomness = 0;\n\t\tSampleInfos[i].flags = 0x6010;\n\t}\n\tCloseHandle(hSfxFile);\n}\n#endif // FEATURE_MOD_CONFIG\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\nint PatternTexPage = -1;\n\nstatic struct {\n\tint x, y, side, page;\n} BgndPattern = {0, 0, 0, -1};\n\nstatic bool GetBgndPatternInfo() {\n\tmemset(&BgndPattern, 0, sizeof(BgndPattern));\n\tif( !Objects[ID_INV_BACKGROUND].loaded ) {\n\t\treturn false;\n\t}\n\n\t__int16 *meshPtr = MeshPtr[Objects[ID_INV_BACKGROUND].meshIndex];\n\tmeshPtr += 3+2; // skip mesh coords (3*INT16) and radius (1*INT32)\n\n\tint num = *(meshPtr++);\n\tmeshPtr += num*3; // skip vertices (each one is 3xINT16)\n\n\tnum = *(meshPtr++);\n\tif( num >= 0 ) // negative num means lights instead of normals\n\t\tmeshPtr += num*3; // skip normals (each is 3xINT16)\n\telse\n\t\tmeshPtr -= num; // skip lights (each one is INT16)\n\n\tnum = *(meshPtr++); // get quads number (we need at least one)\n\tif( num < 1 ) return false;\n\n\tmeshPtr += 4; // skip 4 vertex indices of 1st textured quad (each one is INT16)\n\tDWORD textureIndex = *(meshPtr++); // get texture index of 1st textured quad.\n\n\tPHD_TEXTURE *texture = &PhdTextureInfo[textureIndex];\n\tPHD_UV *uv = texture->uv;\n\tif( uv[0].u != uv[3].u && uv[1].u != uv[2].u && uv[0].u >= uv[2].u &&\n\t\tuv[0].v != uv[1].v && uv[2].v != uv[3].v && uv[0].v >= uv[2].v )\n\t{\n\t\treturn false;\n\t}\n\n\tint x = (uv[0].u % 0x100 + uv[0].u) / 0x100;\n\tint y = (uv[0].v % 0x100 + uv[0].v) / 0x100;\n\tint w = (uv[2].u % 0x100 + uv[2].u) / 0x100 - x;\n\tint h = (uv[2].v % 0x100 + uv[2].v) / 0x100 - y;\n\tif( w != h ) return false;\n\n\twhile( h%2 == 0 ) h /= 2;\n\tif( h != 1 ) return false;\n\n\tBgndPattern.x = x;\n\tBgndPattern.y = y;\n\tBgndPattern.side = w;\n\tBgndPattern.page = texture->tpage;\n\treturn true;\n}\n\nstatic int CreateBgndPatternTexture(HANDLE hFile) {\n\tif( hFile == INVALID_HANDLE_VALUE || SavedAppSettings.RenderMode != RM_Hardware || BgndPattern.side <= 0 ) {\n\t\treturn -1;\n\t}\n\tint pageIndex = -1;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( PathFileExists(\"textures/background.png\") ) {\n\t\tpageIndex = AddExternalTexture(\"textures/background.png\", true);\n\t\tif( pageIndex >= 0 ) {\n\t\t\tHWR_TexturePageIndexes[HwrTexturePagesCount] = pageIndex;\n\t\t\tHWR_PageHandles[HwrTexturePagesCount] = GetTexturePageHandle(pageIndex);\n\t\t\tpageIndex = HwrTexturePagesCount++;\n\t\t\treturn pageIndex;\n\t\t}\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tDWORD bytesRead;\n\tint pageCount = 0;\n\tSetFilePointer(hFile, LevelFileTexPagesOffset, NULL, FILE_BEGIN);\n\tReadFileSync(hFile, &pageCount, sizeof(pageCount), &bytesRead, NULL);\n\tif( BgndPattern.page >= pageCount ) {\n\t\treturn -1;\n\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( IsExternalTexture(BgndPattern.page) ) {\n\t\treturn -1;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tDWORD pageSize = ( TextureFormat.bpp < 16 ) ? 256*256*1 : 256*256*2;\n\tBYTE *bitmap = (BYTE *)GlobalAlloc(GMEM_FIXED, pageSize);\n\tif( TextureFormat.bpp < 16 ) {\n\t\tSetFilePointer(hFile, BgndPattern.page*(256*256*1), NULL, FILE_CURRENT);\n\t\tReadFileSync(hFile, bitmap, pageSize, &bytesRead, NULL);\n\t\tpageIndex = MakeCustomTexture(BgndPattern.x, BgndPattern.y, BgndPattern.side, BgndPattern.side,\n\t\t\t\t\t\t\t\t\t256, BgndPattern.side, 8, bitmap, GamePalette8, PaletteIndex, NULL, false);\n\t} else {\n\t\tSetFilePointer(hFile, pageCount*(256*256*1) + BgndPattern.page*(256*256*2), NULL, FILE_CURRENT);\n\t\tReadFileSync(hFile, bitmap, pageSize, &bytesRead, NULL);\n\t\tpageIndex = MakeCustomTexture(BgndPattern.x, BgndPattern.y, BgndPattern.side, BgndPattern.side,\n\t\t\t\t\t\t\t\t\t256, BgndPattern.side, 16, bitmap, NULL, -1, NULL, false);\n\t}\n\n\tif( pageIndex >= 0 ) {\n\t\tHWR_TexturePageIndexes[HwrTexturePagesCount] = pageIndex;\n\t\tHWR_PageHandles[HwrTexturePagesCount] = GetTexturePageHandle(pageIndex);\n\t\tpageIndex = HwrTexturePagesCount++;\n\t}\n\n\tGlobalFree(bitmap);\n\treturn pageIndex;\n}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\nstatic GF_LEVEL_TYPE LoadLevelType = GFL_NOLEVEL;\n\nBOOL __cdecl ReadFileSync(HANDLE hFile, LPVOID lpBuffer, DWORD nBytesToRead, LPDWORD lpnBytesRead, LPOVERLAPPED lpOverlapped) {\n\tReadFileBytesCounter += nBytesToRead;\n\n\tif( ReadFileBytesCounter > 0x4000 ) {\n\t\tReadFileBytesCounter = 0;\n\t\tWinVidSpinMessageLoop(false);\n\t}\n\treturn ReadFile(hFile, lpBuffer, nBytesToRead, lpnBytesRead, lpOverlapped);\n}\n\nBOOL __cdecl LoadTexturePages(HANDLE hFile) {\n\tint i, pageCount;\n\tDWORD bytesRead;\n\tDWORD pageSize;\n\tLPVOID texPageBuffer;\n\tBYTE *texPagePtr;\n\n\tReadFileSync(hFile, &pageCount, sizeof(pageCount), &bytesRead, NULL);\n\n\t// for software renderer read 8bit texture pages to GAME allocated buffer and skip 16bit pages\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\tfor( i=0; i<pageCount; ++i ) {\n\t\t\tif( TexturePageBuffer8[i] == NULL ) {\n\t\t\t\tTexturePageBuffer8[i] = (BYTE *)game_malloc(256*256*1, GBUF_TexturePages);\n\t\t\t}\n\t\t\tReadFileSync(hFile, TexturePageBuffer8[i], 256*256*1, &bytesRead, NULL);\n\t\t}\n\t\tSetFilePointer(hFile, pageCount*(256*256*2), NULL, FILE_CURRENT);\n\t} else {\n\t\t// for hardware renderer do BPP check and load 8 bit or 16 bit texture pages to GLOBAL allocated memory and skip others\n\t\tpageSize = ( TextureFormat.bpp < 16 ) ? 256*256*1 : 256*256*2;\n\t\ttexPageBuffer = GlobalAlloc(GMEM_FIXED, pageCount*pageSize);\n\n\t\tif( texPageBuffer == NULL )\n\t\t\treturn FALSE;\n\n\t\ttexPagePtr = (BYTE *)texPageBuffer;\n\n\t\tif( TextureFormat.bpp < 16 ) {\n\t\t\t// load 8 bit texture pages and skip 16 bit texture pages\n\t\t\tfor( i=0; i<pageCount; ++i ) {\n\t\t\t\tReadFileSync(hFile, texPagePtr, pageSize, &bytesRead, NULL);\n\t\t\t\ttexPagePtr += pageSize;\n\t\t\t}\n\t\t\tSetFilePointer(hFile, pageCount*(256*256*2), NULL, FILE_CURRENT);\n\t\t\tHWR_LoadTexturePages(pageCount, texPageBuffer, GamePalette8);\n\t\t} else {\n\t\t\t// skip 8 bit texture pages and load 16 bit texture pages\n\t\t\tSetFilePointer(hFile, pageCount*(256*256*1), NULL, FILE_CURRENT);\n\t\t\tfor( i=0; i<pageCount; ++i ) {\n\t\t\t\tReadFileSync(hFile, texPagePtr, pageSize, &bytesRead, NULL);\n\t\t\t\ttexPagePtr += pageSize;\n\t\t\t}\n\t\t\tHWR_LoadTexturePages(pageCount, texPageBuffer, NULL);\n\t\t}\n\n\t\t// for hardware renderer textures stored in videomemory so we may clean up system memory\n\t\tGlobalFree(texPageBuffer);\n\t\tHwrTexturePagesCount = pageCount;\n\t}\n#ifdef FEATURE_HUD_IMPROVED\n\tLoadButtonSprites();\n#endif // FEATURE_HUD_IMPROVED\n\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadRooms(HANDLE hFile) {\n\tDWORD bytesRead;\n\tDWORD dwCount;\n\t__int16 wCount;\n\n\t// Get number of rooms\n\tReadFileSync(hFile, &RoomCount, sizeof(__int16), &bytesRead, NULL);\n\tif( RoomCount < 0 || RoomCount > 0x400 ) {\n\t\tlstrcpy(StringToShow, \"LoadRoom(): Too many rooms\");\n\t\treturn FALSE;\n\t}\n\n\t// Allocate memory for room info\n\tRoomInfo = (ROOM_INFO *)game_malloc(sizeof(ROOM_INFO)*RoomCount, GBUF_RoomInfos);\n\tif( RoomInfo == NULL ) {\n\t\tlstrcpy(StringToShow, \"LoadRoom(): Could not allocate memory for rooms\");\n\t\treturn FALSE;\n\t}\n\n\t// For every room read info\n\tfor( int i = 0; i < RoomCount; ++i ) {\n\n\t\t// Room position\n\t\tReadFileSync(hFile, &RoomInfo[i].x, sizeof(int), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &RoomInfo[i].z, sizeof(int), &bytesRead, NULL);\n\t\tRoomInfo[i].y = 0;\n\n\t\t// Room floor/ceiling\n\t\tReadFileSync(hFile, &RoomInfo[i].minFloor, sizeof(int), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &RoomInfo[i].maxCeiling, sizeof(int), &bytesRead, NULL);\n\n\t\t// Room mesh\n\t\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\t\tRoomInfo[i].data = (__int16 *)game_malloc(sizeof(__int16)*dwCount, GBUF_RoomMesh);\n\t\tReadFileSync(hFile, RoomInfo[i].data, sizeof(__int16)*dwCount, &bytesRead, NULL);\n\n\t\t// Doors\n\t\tReadFileSync(hFile, &wCount, sizeof(__int16), &bytesRead, NULL);\n\t\tif( wCount == 0 ) {\n\t\t\tRoomInfo[i].doors = NULL;\n\t\t} else {\n\t\t\tRoomInfo[i].doors = (DOOR_INFOS *)game_malloc(sizeof(__int16) + sizeof(DOOR_INFO)*wCount, GBUF_RoomDoor);\n\t\t\tRoomInfo[i].doors->wCount = wCount;\n\t\t\tReadFileSync(hFile, &RoomInfo[i].doors->door, sizeof(DOOR_INFO)*wCount, &bytesRead, NULL);\n\t\t}\n\n\t\t// Room floor\n\t\tReadFileSync(hFile, &RoomInfo[i].xSize, sizeof(__int16), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &RoomInfo[i].ySize, sizeof(__int16), &bytesRead, NULL);\n\t\tdwCount = RoomInfo[i].xSize * RoomInfo[i].ySize;\n\t\tRoomInfo[i].floor = (FLOOR_INFO *)game_malloc(sizeof(FLOOR_INFO)*dwCount, GBUF_RoomFloor);\n\t\tReadFileSync(hFile, RoomInfo[i].floor, sizeof(FLOOR_INFO)*dwCount, &bytesRead, NULL);\n\n\t\t// Room lights\n\t\tReadFileSync(hFile, &RoomInfo[i].ambient1, sizeof(__int16), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &RoomInfo[i].ambient2, sizeof(__int16), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &RoomInfo[i].lightMode, sizeof(__int16), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &RoomInfo[i].numLights, sizeof(__int16), &bytesRead, NULL);\n\t\tif( RoomInfo[i].numLights == 0 ) {\n\t\t\tRoomInfo[i].light = NULL;\n\t\t} else {\n\t\t\tRoomInfo[i].light = (LIGHT_INFO *)game_malloc(sizeof(LIGHT_INFO)*RoomInfo[i].numLights, GBUF_RoomLights);\n\t\t\tReadFileSync(hFile, RoomInfo[i].light, sizeof(LIGHT_INFO)*RoomInfo[i].numLights, &bytesRead, NULL);\n\t\t}\n\n\t\t// Static mesh infos\n\t\tReadFileSync(hFile, &RoomInfo[i].numMeshes, sizeof(__int16), &bytesRead, NULL);\n\t\tif( RoomInfo[i].numMeshes == 0 ) {\n\t\t\tRoomInfo[i].mesh = NULL;\n\t\t} else {\n\t\t\tRoomInfo[i].mesh = (MESH_INFO *)game_malloc(sizeof(MESH_INFO)*RoomInfo[i].numMeshes, GBUF_RoomStaticMeshInfos);\n\t\t\tReadFileSync(hFile, RoomInfo[i].mesh, sizeof(MESH_INFO)*RoomInfo[i].numMeshes, &bytesRead, NULL);\n\t\t}\n\n\t\t// Flipped (alternative) room\n\t\tReadFileSync(hFile, &RoomInfo[i].flippedRoom, sizeof(__int16), &bytesRead, NULL);\n\n\t\t// Room flags\n\t\tReadFileSync(hFile, &RoomInfo[i].flags, sizeof(__int16), &bytesRead, NULL);\n\n\t\t// Initialise some variables\n\t\tRoomInfo[i].boundActive = 0;\n\t\tRoomInfo[i].boundLeft = PhdWinMaxX;\n\t\tRoomInfo[i].boundTop = PhdWinMaxY;\n\t\tRoomInfo[i].boundRight = 0;\n\t\tRoomInfo[i].boundBottom = 0;\n\t\tRoomInfo[i].itemNumber = -1;\n\t\tRoomInfo[i].fxNumber = -1;\n\t}\n\n\t// Read floor data\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tFloorData = (__int16 *)game_malloc(sizeof(__int16)*dwCount, GBUF_FloorData);\n\tReadFileSync(hFile, FloorData, sizeof(__int16)*dwCount, &bytesRead, NULL);\n\treturn TRUE;\n}\n\nvoid __cdecl AdjustTextureUVs(bool resetUvAdd) {\n\tDWORD i, j;\n\tint offset;\n\tBYTE uvFlags;\n\tPHD_UV *pUV, *pBackup;\n\t// NOTE: there was no such backup in the original game\n\textern PHD_TEXTURE TextureBackupUV[ARRAY_SIZE(PhdTextureInfo)];\n\tif( resetUvAdd ) {\n\t\tmemcpy(TextureBackupUV, PhdTextureInfo, TextureInfoCount * sizeof(PHD_TEXTURE));\n\t}\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tdouble forcedAdjust = GetTexPagesAdjustment();\n\t\tif( forcedAdjust > 0.0) {\n\t\t\tUvAdd = (int)(forcedAdjust * 256.0);\n\t\t\tfor( i=0; i<TextureInfoCount; ++i ) {\n\t\t\t\tuvFlags = LabTextureUVFlags[i];\n\t\t\t\tpUV = PhdTextureInfo[i].uv;\n\t\t\t\tpBackup = TextureBackupUV[i].uv;\n\n\t\t\t\tfor( j=0; j<4; ++j ) {\n\t\t\t\t\tpUV[j].u = pBackup[j].u + ((uvFlags & 1) ? -UvAdd : UvAdd);\n\t\t\t\t\tpUV[j].v = pBackup[j].v + ((uvFlags & 2) ? -UvAdd : UvAdd);\n\t\t\t\t\tuvFlags >>= 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( SavedAppSettings.RenderMode == RM_Hardware && (SavedAppSettings.TexelAdjustMode == TAM_Always ||\n\t\t(SavedAppSettings.TexelAdjustMode == TAM_BilinearOnly && SavedAppSettings.BilinearFiltering)) )\n\t{\n\t\tUvAdd = SavedAppSettings.LinearAdjustment;\n\t} else {\n\t\tUvAdd = SavedAppSettings.NearestAdjustment;\n\t}\n\n\tfor( i=0; i<TextureInfoCount; ++i ) {\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\t// NOTE: page side is not counted in the original game, but we need it for HD textures\n\t\t\toffset = UvAdd * 256 / GetTextureSideByPage(PhdTextureInfo[i].tpage);\n\t\t\tCLAMPL(offset, 1);\n\t\t} else {\n\t\t\toffset = UvAdd;\n\t\t}\n\n\t\tuvFlags = LabTextureUVFlags[i];\n\t\tpUV = PhdTextureInfo[i].uv;\n\t\tpBackup = TextureBackupUV[i].uv;\n\n\t\tfor( j=0; j<4; ++j ) {\n\t\t\tpUV[j].u = pBackup[j].u + ((uvFlags & 1) ? -offset : offset);\n\t\t\tpUV[j].v = pBackup[j].v + ((uvFlags & 2) ? -offset : offset);\n\t\t\tuvFlags >>= 2;\n\t\t}\n\t}\n}\n\nBOOL __cdecl LoadObjects(HANDLE hFile) {\n\tDWORD i, j;\n\tDWORD bytesRead;\n\tDWORD dwCount;\n\tDWORD animCount;\n\tDWORD animOffset;\n\tDWORD objNumber;\n\tUINT16 *uv;\n\n\t// Load mesh base data\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tMeshes = (__int16 *)game_malloc(sizeof(__int16)*dwCount, GBUF_Meshes);\n\tReadFileSync(hFile, Meshes, sizeof(__int16)*dwCount, &bytesRead, NULL);\n\n\t// Load mesh pointers\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tMeshPtr = (__int16 **)game_malloc(sizeof(__int16 *)*dwCount, GBUF_MeshPointers);\n\tReadFileSync(hFile, MeshPtr, sizeof(__int16 *)*dwCount, &bytesRead, NULL);\n\n\t// Remap mesh pointers\n\tfor( i = 0; i < dwCount; ++i )\n\t\tMeshPtr[i] = (__int16 *)((DWORD)Meshes + (DWORD)MeshPtr[i]);\n\n\t// Load anims\n\tReadFileSync(hFile, &animCount, sizeof(DWORD), &bytesRead, NULL);\n\tAnims = (ANIM_STRUCT *)game_malloc(sizeof(ANIM_STRUCT)*animCount, GBUF_Anims);\n\tReadFileSync(hFile, Anims, sizeof(ANIM_STRUCT)*animCount, &bytesRead, NULL);\n\n\t// Load changes\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tAnimChanges = (CHANGE_STRUCT *)game_malloc(sizeof(CHANGE_STRUCT)*dwCount, GBUF_Structs);\n\tReadFileSync(hFile, AnimChanges, sizeof(CHANGE_STRUCT)*dwCount, &bytesRead, NULL);\n\n\t// Load ranges\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tAnimRanges = (RANGE_STRUCT *)game_malloc(sizeof(RANGE_STRUCT)*dwCount, GBUF_Ranges);\n\tReadFileSync(hFile, AnimRanges, sizeof(RANGE_STRUCT)*dwCount, &bytesRead, NULL);\n\n\t// Load commands\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tAnimCommands = (__int16 *)game_malloc(sizeof(__int16)*dwCount, GBUF_Commands);\n\tReadFileSync(hFile, AnimCommands, sizeof(__int16)*dwCount, &bytesRead, NULL);\n\n\t// Load bones\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tAnimBones = (int *)game_malloc(sizeof(int)*dwCount, GBUF_Bones);\n\tReadFileSync(hFile, AnimBones, sizeof(int)*dwCount, &bytesRead, NULL);\n\n\t// Load frames\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tAnimFrames = (__int16 *)game_malloc(sizeof(__int16)*dwCount, GBUF_Frames);\n\tReadFileSync(hFile, AnimFrames, sizeof(__int16)*dwCount, &bytesRead, NULL);\n\n\t// Remap anim pointers\n\tfor( i = 0; i < animCount; ++i )\n\t\tAnims[i].framePtr = (__int16 *)((DWORD)AnimFrames + (DWORD)Anims[i].framePtr);\n\n\t// Load animated objects\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tfor( i = 0; i < dwCount; ++i ) {\n\t\tReadFileSync(hFile, &objNumber, sizeof(DWORD), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &Objects[objNumber].nMeshes, sizeof(__int16), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &Objects[objNumber].meshIndex, sizeof(__int16), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &Objects[objNumber].boneIndex, sizeof(int), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &animOffset, sizeof(DWORD), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &Objects[objNumber].animIndex, sizeof(__int16), &bytesRead, NULL);\n\t\tObjects[objNumber].frameBase = (__int16 *)((DWORD)AnimFrames + animOffset);\n\t\tObjects[objNumber].loaded = 1;\n\t}\n\n\t// Initialise animated objects\n\tInitialiseObjects();\n\n\t// Load static objects\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tmemset(&StaticObjects, 0, sizeof(StaticObjects)); // NOTE: we need to be sure that a static object is really loaded\n#endif // FEATURE_VIDEOFX_IMPROVED\n\tfor( i = 0; i < dwCount; ++i ) {\n\t\tReadFileSync(hFile, &objNumber, sizeof(DWORD), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &StaticObjects[objNumber].meshIndex, sizeof(__int16), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &StaticObjects[objNumber].drawBounds, sizeof(STATIC_BOUNDS), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &StaticObjects[objNumber].collisionBounds, sizeof(STATIC_BOUNDS), &bytesRead, NULL);\n\t\tReadFileSync(hFile, &StaticObjects[objNumber].flags, sizeof(UINT16), &bytesRead, NULL);\n\t}\n\n\t// Load textures info\n\tReadFileSync(hFile, &TextureInfoCount, sizeof(DWORD), &bytesRead, NULL);\n\tif( TextureInfoCount > ARRAY_SIZE(PhdTextureInfo) ) {\n\t\tlstrcpy(StringToShow, \"Too many Textures in level\");\n\t\treturn FALSE;\n\t}\n\tReadFileSync(hFile, PhdTextureInfo, sizeof(PHD_TEXTURE)*TextureInfoCount, &bytesRead, NULL);\n\tfor( i = 0; i < TextureInfoCount; ++i ) {\n\t\tLabTextureUVFlags[i] = 0;\n\t\tuv = &PhdTextureInfo[i].uv[0].u;\n\t\tfor( j = 0; j < 8; ++j ) {\n\t\t\tif( (uv[j] & 0x0080) != 0 ) {\n\t\t\t\tuv[j] |= 0x00FF;\n\t\t\t\tLabTextureUVFlags[i] |= (1 << j);\n\t\t\t} else {\n\t\t\t\tuv[j] &= 0xFF00;\n\t\t\t}\n\t\t}\n\t}\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t// get background pattern info before UV adjustment\n\tGetBgndPatternInfo();\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tAdjustTextureUVs(true);\n\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadSprites(HANDLE hFile) {\n\tDWORD bytesRead;\n\tDWORD objNumber;\n\tDWORD dwCount;\n\n\t// Load sprite infos\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tReadFileSync(hFile, PhdSpriteInfo, sizeof(PHD_SPRITE)*dwCount, &bytesRead, NULL);\n\n\t// Assign sprites to objects\n\tReadFileSync(hFile, &dwCount, sizeof(DWORD), &bytesRead, NULL);\n\tfor( DWORD i = 0; i < dwCount; ++i ) {\n\t\tReadFileSync(hFile, &objNumber, sizeof(DWORD), &bytesRead, NULL);\n\t\tif ( objNumber < ID_NUMBER_OBJECTS ) {\n\t\t\tReadFileSync(hFile, &Objects[objNumber].nMeshes, sizeof(__int16), &bytesRead, NULL);\n\t\t\tReadFileSync(hFile, &Objects[objNumber].meshIndex,  sizeof(__int16), &bytesRead, NULL);\n\t\t\tObjects[objNumber].loaded = 1;\n\t\t} else {\n\t\t\tobjNumber -= ID_NUMBER_OBJECTS;\n\t\t\tSetFilePointer(hFile, sizeof(__int16), NULL, FILE_CURRENT); // StaticObjects don't have nMeshes (just one mesh)\n\t\t\tReadFileSync(hFile, &StaticObjects[objNumber].meshIndex, sizeof(__int16), &bytesRead, NULL);\n\t\t}\n\t}\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadItems(HANDLE hFile) {\n\tDWORD itemsCount, bytesRead;\n\n\tReadFileSync(hFile, &itemsCount, sizeof(DWORD), &bytesRead, NULL);\n\tif( itemsCount == 0 )\n\t\treturn TRUE;\n\n\tif( itemsCount > 256 ) {\n\t\tlstrcpy(StringToShow, \"LoadItems(): Too Many Items being Loaded!!\");\n\t\treturn FALSE;\n\t}\n\n\tItems = (ITEM_INFO *)game_malloc(sizeof(ITEM_INFO)*256, GBUF_Items);\n\tif( Items == NULL ) {\n\t\tlstrcpy(StringToShow, \"LoadItems(): Unable to allocate memory for 'items'\");\n\t\treturn FALSE;\n\t}\n\tLevelItemCount = itemsCount;\n\tInitialiseItemArray(256);\n\n\tfor( DWORD i = 0; i < itemsCount; ++i ) {\n\t\tReadFileSync(hFile, &Items[i].objectID,\t\tsizeof(__int16),\t&bytesRead, NULL);\n\t\tReadFileSync(hFile, &Items[i].roomNumber,\tsizeof(__int16),\t&bytesRead, NULL);\n\t\tReadFileSync(hFile, &Items[i].pos.x,\t\tsizeof(int),\t\t&bytesRead, NULL);\n\t\tReadFileSync(hFile, &Items[i].pos.y,\t\tsizeof(int),\t\t&bytesRead, NULL);\n\t\tReadFileSync(hFile, &Items[i].pos.z,\t\tsizeof(int),\t\t&bytesRead, NULL);\n\t\tReadFileSync(hFile, &Items[i].pos.rotY,\t\tsizeof(__int16),\t&bytesRead, NULL);\n\t\tReadFileSync(hFile, &Items[i].shade1,\t\tsizeof(__int16),\t&bytesRead, NULL);\n\t\tReadFileSync(hFile, &Items[i].shade2,\t\tsizeof(__int16),\t&bytesRead, NULL);\n\t\tReadFileSync(hFile, &Items[i].flags,\t\tsizeof(UINT16),\t\t&bytesRead, NULL);\n\n\t\tif( Items[i].objectID < 0 || Items[i].objectID >= ID_NUMBER_OBJECTS ) {\n\t\t\twsprintf(StringToShow, \"LoadItems(): Bad Object number (%d) on Item %d\", Items[i].objectID, i);\n\t\t\treturn FALSE;\n\t\t}\n\t\tInitialiseItem(i);\n\t}\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadDepthQ(HANDLE hFile) {\n\tint i, j;\n\tDWORD bytesRead;\n#if (DIRECT3D_VERSION < 0x900)\n\tRGB888 paletteBuffer[256];\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\tReadFileSync(hFile, DepthQTable, 32*sizeof(DEPTHQ_ENTRY), &bytesRead, NULL);\n\n\tfor( i=0; i<32; ++i )\n\t\tDepthQTable[i].index[0] = 0;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tmemcpy(DepthQIndex, &DepthQTable[24], sizeof(DEPTHQ_ENTRY));\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( GameVid_IsWindowedVga ) {\n\t\tCopyBitmapPalette(GamePalette8, DepthQTable[0].index, 32*sizeof(DEPTHQ_ENTRY), paletteBuffer);\n\t\tSyncSurfacePalettes(DepthQTable, 256, 32, 256, GamePalette8, DepthQTable, 256, paletteBuffer, true);\n\t\tmemcpy(GamePalette8, paletteBuffer, sizeof(GamePalette8));\n\t\tfor( i=0; i<256; ++i ) {\n\t\t\tDepthQIndex[i] = S_COLOUR(GamePalette8[i].red, GamePalette8[i].green, GamePalette8[i].blue);\n\t\t}\n\t} else {\n\t\tmemcpy(DepthQIndex, &DepthQTable[24], sizeof(DEPTHQ_ENTRY));\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tUpdateDepthQ(true);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tfor( i=0; i<32; ++i ) {\n\t\tfor( j=0; j<256; ++j ) {\n\t\t\tGouraudTable[j].index[i] = DepthQTable[i].index[j];\n\t\t}\n\t}\n\n\tIsWet = 0;\n\tfor( i=0; i<256; ++i ) {\n\t\tWaterPalette[i].red   = GamePalette8[i].red   * 2 / 3;\n\t\tWaterPalette[i].green = GamePalette8[i].green * 2 / 3;\n\t\tWaterPalette[i].blue  = GamePalette8[i].blue;\n\t}\n\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadPalettes(HANDLE hFile) {\n\tDWORD bytesRead;\n\n\tReadFileSync(hFile, GamePalette8, 256*sizeof(RGB888), &bytesRead, NULL);\n\n\tGamePalette8[0].red = 0;\n\tGamePalette8[0].green = 0;\n\tGamePalette8[0].blue = 0;\n\n\tfor( int i=1; i<256; ++i ) {\n\t\t// NOTE: the original code just shifts left 2 bits. But this way is slightly better\n\t\tGamePalette8[i].red   = (GamePalette8[i].red   << 2) | (GamePalette8[i].red   >> 4);\n\t\tGamePalette8[i].green = (GamePalette8[i].green << 2) | (GamePalette8[i].green >> 4);\n\t\tGamePalette8[i].blue  = (GamePalette8[i].blue  << 2) | (GamePalette8[i].blue  >> 4);\n\t}\n\n\tReadFileSync(hFile, GamePalette16, 256*sizeof(PALETTEENTRY), &bytesRead, NULL);\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( !IsTexPagesLegacyColors() ) {\n\t\tfor( int i=0; i<256; ++i ) {\n\t\t\tPALETTEENTRY *pal = &GamePalette16[i];\n\t\t\tpal->peRed   = (pal->peRed   & 0xF8) | (pal->peRed   >> 5);\n\t\t\tpal->peGreen = (pal->peGreen & 0xF8) | (pal->peGreen >> 5);\n\t\t\tpal->peBlue  = (pal->peBlue  & 0xF8) | (pal->peBlue  >> 5);\n\t\t}\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadCameras(HANDLE hFile) {\n\tDWORD bytesRead;\n\n\tReadFileSync(hFile, &CameraCount, sizeof(DWORD), &bytesRead, NULL);\n\tif( CameraCount != 0 ) {\n\t\tCamera.fixed = (OBJECT_VECTOR *)game_malloc(sizeof(OBJECT_VECTOR)*CameraCount, GBUF_Cameras);\n\t\tif ( Camera.fixed == NULL ) {\n\t\t\treturn FALSE;\n\t\t}\n\t\tReadFileSync(hFile, Camera.fixed, sizeof(OBJECT_VECTOR)*CameraCount, &bytesRead, NULL);\n\t}\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadSoundEffects(HANDLE hFile) {\n\tDWORD bytesRead;\n\n\tReadFileSync(hFile, &SoundFxCount, sizeof(DWORD), &bytesRead, NULL);\n\tif( SoundFxCount != 0 ) {\n\t\tSoundFx = (OBJECT_VECTOR *)game_malloc(sizeof(OBJECT_VECTOR)*SoundFxCount, GBUF_SoundFX);\n\t\tif( SoundFx == NULL ) {\n\t\t\treturn FALSE;\n\t\t}\n\t\tReadFileSync(hFile, SoundFx, sizeof(OBJECT_VECTOR)*SoundFxCount, &bytesRead, NULL);\n\t}\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadBoxes(HANDLE hFile) {\n\tDWORD overlapsCount, bytesRead;\n\n\t// Load Boxes\n\tReadFileSync(hFile, &BoxesCount, sizeof(DWORD), &bytesRead, NULL);\n\tBoxes = (BOX_INFO *)game_malloc(sizeof(BOX_INFO)*BoxesCount, GBUF_Boxes);\n\tReadFileSync(hFile, Boxes, sizeof(BOX_INFO)*BoxesCount, &bytesRead, NULL);\n\tif( bytesRead != sizeof(BOX_INFO)*BoxesCount ) {\n\t\tlstrcpy(StringToShow, \"LoadBoxes(): Unable to load boxes\");\n\t\treturn FALSE;\n\t}\n\n\t// Load Overlaps\n\tReadFileSync(hFile, &overlapsCount, sizeof(DWORD), &bytesRead, NULL);\n\tOverlaps = (UINT16 *)game_malloc(sizeof(UINT16)*overlapsCount, GBUF_Overlaps);\n\tReadFileSync(hFile, Overlaps, sizeof(UINT16)*overlapsCount, &bytesRead, NULL);\n\tif( bytesRead != sizeof(UINT16)*overlapsCount ) {\n\t\tlstrcpy(StringToShow, \"LoadBoxes(): Unable to load box overlaps\");\n\t\treturn FALSE;\n\t}\n\n\t// Load GroundZones and FlyZones\n\tfor( int i=0; i<2; ++i ) {\n\t\tfor( int j=0; j<4; ++j ) {\n\t\t\tif( (j == 2) ||\n\t\t\t\t(j == 1 && !Objects[ID_SPIDER_or_WOLF].loaded && !Objects[ID_SKIDOO_ARMED].loaded) ||\n\t\t\t\t(j == 3 && !Objects[ID_YETI].loaded && !Objects[ID_WORKER3].loaded) )\n\t\t\t{\n\t\t\t\tSetFilePointer(hFile, sizeof(__int16)*BoxesCount, NULL, FILE_CURRENT); // skip some GroundZones\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tGroundZones[j*2+i] = (__int16 *)game_malloc(sizeof(__int16)*BoxesCount, GBUF_GroundZone);\n\t\t\tReadFileSync(hFile, GroundZones[j*2+i], sizeof(__int16)*BoxesCount, &bytesRead, NULL);\n\t\t\tif( bytesRead != sizeof(__int16)*BoxesCount ) {\n\t\t\t\tlstrcpy(StringToShow, \"LoadBoxes(): Unable to load 'ground_zone'\");\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t}\n\t\tFlyZones[i] = (__int16 *)game_malloc(sizeof(__int16)*BoxesCount, GBUF_FlyZone);\n\t\tReadFileSync(hFile, FlyZones[i], sizeof(__int16)*BoxesCount, &bytesRead, NULL);\n\t\tif( bytesRead != sizeof(__int16)*BoxesCount ) {\n\t\t\tlstrcpy(StringToShow, \"LoadBoxes(): Unable to load 'fly_zone'\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadAnimatedTextures(HANDLE hFile) {\n\tDWORD animTexCount, bytesRead;\n\n\tReadFileSync(hFile, &animTexCount, sizeof(DWORD), &bytesRead, NULL);\n\tAnimatedTextureRanges = (__int16 *)game_malloc(sizeof(__int16)*animTexCount, GBUF_AnimatingTextureRanges);\n\tReadFileSync(hFile, AnimatedTextureRanges, sizeof(__int16)*animTexCount, &bytesRead, NULL);\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadCinematic(HANDLE hFile) {\n\tDWORD bytesRead;\n\n\tReadFileSync(hFile, &CineFramesCount, sizeof(__int16), &bytesRead, NULL);\n\tif( CineFramesCount != 0 ) {\n\t\tCineFrames = (CINE_FRAME_INFO *)game_malloc(sizeof(CINE_FRAME_INFO)*CineFramesCount, GBUF_CinematicFrames);\n\t\tReadFileSync(hFile, CineFrames, sizeof(CINE_FRAME_INFO)*CineFramesCount, &bytesRead, NULL);\n\t\tIsCinematicLoaded = TRUE;\n\t} else {\n\t\tIsCinematicLoaded = FALSE;\n\t}\n\treturn TRUE;\n}\n\nBOOL __cdecl LoadDemo(HANDLE hFile) {\n\tDWORD bytesRead;\n\t__int16 demoSize;\n\n\tDemoCount = 0;\n\tDemoPtr = game_malloc(36000, GBUF_LoadDemoBuffer);\n\tReadFileSync(hFile, &demoSize, sizeof(__int16), &bytesRead, NULL);\n\tif( demoSize != 0 ) {\n\t\tReadFileSync(hFile, DemoPtr, demoSize, &bytesRead, NULL);\n\t\tIsDemoLoaded = TRUE;\n\t} else {\n\t\tIsDemoLoaded = FALSE;\n\t}\n\treturn TRUE;\n}\n\nvoid __cdecl LoadDemoExternal(LPCTSTR levelName) {\n\tHANDLE hFile;\n\tDWORD bytesRead = 0;\n\tchar fileName[80] = {0};\n\n\tstrcpy(fileName, levelName);\n\tChangeFileNameExtension(fileName, \"DEM\");\n\thFile = CreateFile(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile != INVALID_HANDLE_VALUE ) {\n\t\tReadFileSync(hFile, DemoPtr, 36000, &bytesRead, NULL);\n\t\tIsDemoLoaded = ( bytesRead > 0 );\n\t\tCloseHandle(hFile);\n\t}\n}\n\nBOOL __cdecl LoadSamples(HANDLE hFile) {\n\tint i, j;\n\tDWORD bytesRead;\n\tHANDLE hSfxFile;\n\tLPCTSTR sfxFileName;\n\tDWORD dataSize;\n\tLPVOID waveData;\n\tint sampleCount;\n\tWAVEPCM_HEADER waveHeader;\n\tLPWAVEFORMATEX waveFormat;\n\tint sampleIndexes[500];\n\n\tSoundIsActive = FALSE;\n\tif( !WinSndIsSoundEnabled() ) {\n\t\treturn TRUE;\n\t}\n\tWinSndFreeAllSamples();\n\n\t// Load Sample Lut\n\tReadFileSync(hFile, SampleLut, sizeof(SampleLut), &bytesRead, NULL);\n\n\t// Load Sample Infos\n\tReadFileSync(hFile, &SampleInfoCount, sizeof(DWORD), &bytesRead, NULL);\n\tif( SampleInfoCount == 0 ) {\n\t\treturn FALSE;\n\t}\n\tSampleInfos = (SAMPLE_INFO *)game_malloc(sizeof(SAMPLE_INFO)*SampleInfoCount, GBUF_SampleInfos);\n\tReadFileSync(hFile, SampleInfos, sizeof(SAMPLE_INFO)*SampleInfoCount, &bytesRead, NULL);\n\n\t// Load Samples Count\n\tReadFileSync(hFile, &sampleCount, sizeof(int), &bytesRead, NULL);\n\tif( sampleCount == 0 ) {\n\t\treturn FALSE;\n\t}\n\n\t// Load Samples Indexes\n\tReadFileSync(hFile, sampleIndexes, sizeof(DWORD)*sampleCount, &bytesRead, NULL);\n\n\t// Open SFX file\n\tsfxFileName = \"data\\\\main.sfx\";\n#ifdef FEATURE_GOLD\n\t// For the Gold mode use the Gold SFX, if the level is not Title and not Lara's Home\n\tif( IsGold() && LoadLevelType != GFL_TITLE && CurrentLevel != 0 ) {\n\t\tsfxFileName = \"data\\\\maing.sfx\";\n\t}\n#endif // FEATURE_GOLD\n\tsfxFileName = GetFullPath(sfxFileName);\n\thSfxFile = CreateFile(sfxFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hSfxFile == INVALID_HANDLE_VALUE ) {\n\t\twsprintf(StringToShow, \"Could not open MAIN.SFX file\");\n\t\treturn FALSE;\n\t}\n\n\tfor( i=0, j=0; i < sampleCount; ++j ) {\n\t\tReadFileSync(hSfxFile, &waveHeader, sizeof(WAVEPCM_HEADER), &bytesRead, NULL);\n\n\t\tif( waveHeader.dwRiffChunkID != 0x46464952 || // \"RIFF\"\n\t\t\twaveHeader.dwFormat != 0x45564157 || // \"WAVE\"\n\t\t\twaveHeader.dwDataSubchunkID != 0x61746164 ) // \"data\"\n\t\t{\n\t\t\tCloseHandle(hSfxFile);\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tdataSize = (waveHeader.dwDataSubchunkSize + 1) & ~1; // aligned data size\n\t\twaveFormat = (LPWAVEFORMATEX)&waveHeader.wFormatTag;\n\t\twaveFormat->cbSize = 0;\n\n\t\tif( sampleIndexes[i] == j ) {\n\t\t\twaveData = game_malloc(dataSize, GBUF_Samples);\n\t\t\tReadFileSync(hSfxFile, waveData, dataSize, &bytesRead, NULL);\n\t\t\tif( !WinSndMakeSample(i, waveFormat, waveData, dataSize) ) {\n\t\t\t\tCloseHandle(hSfxFile);\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t\tgame_free(dataSize);\n\t\t\t++i;\n\t\t} else {\n\t\t\tSetFilePointer(hSfxFile, dataSize, NULL, FILE_CURRENT);\n\t\t}\n\t}\n\tCloseHandle(hSfxFile);\n\tSoundIsActive = TRUE;\n#if defined(FEATURE_MOD_CONFIG)\n\tLoadBareFootSFX(sampleIndexes, sampleCount);\n#endif // FEATURE_MOD_CONFIG\n\treturn TRUE;\n}\n\nvoid __cdecl ChangeFileNameExtension(char *fileName, const char *fileExt) {\n\tchar *fileNamePtr = fileName;\n\n\tfor( ; *fileNamePtr; ++fileNamePtr ) {\n\t\tif( *fileNamePtr == '.' )\n\t\t\tbreak;\n\t}\n\n\tfileNamePtr[0] = '.';\n\tfileNamePtr[1] = fileExt[0];\n\tfileNamePtr[2] = fileExt[1];\n\tfileNamePtr[3] = fileExt[2];\n\tfileNamePtr[4] = 0;\n}\n\nLPCTSTR __cdecl GetFullPath(LPCTSTR fileName) {\n\tstatic char fullPathBuffer[136];\n#if defined FEATURE_NOCD_DATA\n\twsprintf(fullPathBuffer, \".\\\\%s\", fileName);\n#else // !FEATURE_NOCD_DATA\n\twsprintf(fullPathBuffer, \"%c:\\\\%s\", DriveLetter, fileName);\n#endif // FEATURE_NOCD_DATA\n\treturn fullPathBuffer;\n}\n\nBOOL __cdecl SelectDrive() {\n\tHANDLE hFile;\n\tDWORD driveBitMask;\n\tchar fileName[] = \"D:\\\\data\\\\legal.pcx\";\n\tchar driveName[] = \"A:\\\\\";\n\n\tDriveLetter = 'A';\n\tfor( driveBitMask = GetLogicalDrives(); driveBitMask; driveBitMask >>= 1 ) {\n\t\tif( (driveBitMask & 1) != 0 ) {\n\t\t\tdriveName[0] = DriveLetter;\n\t\t\tif( GetDriveType(driveName) == DRIVE_CDROM ) {\n\t\t\t\tfileName[0] = DriveLetter;\n\t\t\t\thFile = CreateFile(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\t\t\t\tif( hFile != INVALID_HANDLE_VALUE ) {\n\t\t\t\t\tCloseHandle(hFile);\n\t\t\t\t\treturn TRUE;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t++DriveLetter;\n\t}\n\treturn FALSE;\n}\n\nBOOL __cdecl LoadLevel(LPCTSTR fileName, int levelID) {\n\tBOOL result = FALSE;\n\tLPCTSTR fullPath;\n\tHANDLE hFile;\n\tDWORD reserved;\n\tDWORD bytesRead;\n\tint levelVersion;\n\n\tfullPath = GetFullPath(fileName);\n\tstrcpy(LevelFileName, fullPath);\n\tinit_game_malloc();\n\n\thFile = CreateFile(fullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN|FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile == INVALID_HANDLE_VALUE ) {\n\t\twsprintf(StringToShow, \"LoadLevel(): Could not open %s (level %d)\", fullPath, levelID);\n\t\treturn FALSE;\n\t}\n\n\tReadFileSync(hFile, &levelVersion, sizeof(levelVersion), &bytesRead, NULL);\n\tif( levelVersion != REQ_LEVEL_VERSION ) {\n\t\tif( levelVersion < REQ_LEVEL_VERSION )\n\t\t\twsprintf(StringToShow, \"FATAL: Level %d (%s) is OUT OF DATE (version %d). COPY NEW EDITOR\", levelID, fullPath, fileName);\n\t\telse\n\t\t\twsprintf(StringToShow, \"FATAL: Level %d (%s) requires a new TOMB2.EXE (version %d) to run\", levelID, fullPath, fileName);\n\t\tgoto EXIT;\n\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tLoadTexPagesConfiguration(LevelFileName);\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tLevelFilePalettesOffset = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);\n\tif( !LoadPalettes(hFile) ) {\n\t\tgoto EXIT;\n\t}\n\n\tLevelFileTexPagesOffset = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);\n\tif( !LoadTexturePages(hFile) ) {\n\t\tgoto EXIT;\n\t}\n\n\tReadFileSync(hFile, &reserved, sizeof(reserved), &bytesRead, NULL);\n\tif( !LoadRooms(hFile) ||\n\t\t!LoadObjects(hFile) ||\n\t\t!LoadSprites(hFile) ||\n\t\t!LoadCameras(hFile) ||\n\t\t!LoadSoundEffects(hFile) ||\n\t\t!LoadBoxes(hFile) ||\n\t\t!LoadAnimatedTextures(hFile) ||\n\t\t!LoadItems(hFile) )\n\t{\n\t\tgoto EXIT;\n\t}\n\n\tLevelFileDepthQOffset = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);\n\tif( !LoadDepthQ(hFile) ||\n\t\t!LoadCinematic(hFile) ||\n\t\t!LoadDemo(hFile) ||\n\t\t!LoadSamples(hFile) )\n\t{\n\t\tgoto EXIT;\n\t}\n\n\tLoadDemoExternal(fullPath);\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tMarkSemitransObjects();\n\tMarkSemitransTextureRanges();\n#endif // FEATURE_VIDEOFX_IMPROVED\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tPatternTexPage = CreateBgndPatternTexture(hFile);\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tresult = TRUE;\n\nEXIT :\n\tCloseHandle(hFile);\n\treturn result;\n}\n\nBOOL __cdecl S_LoadLevelFile(LPCTSTR fileName, int levelID, GF_LEVEL_TYPE levelType) {\n\tS_UnloadLevelFile();\n\tLoadLevelType = levelType; // NOTE: this line is not presented in the original game\n#ifdef FEATURE_MOD_CONFIG\n\tLoadModConfiguration(fileName);\n\tBOOL result = LoadLevel(fileName, levelID);\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tif( LoadingScreensEnabled && GetModLoadingPix() && (levelType == GFL_NORMAL || levelType == GFL_SAVED) ) {\n\t\tRGB888 palette[256];\n\t\tmemcpy(palette, GamePalette8, sizeof(GamePalette8));\n\t\tif( !BGND2_LoadPicture(GetModLoadingPix(), FALSE, FALSE) ) {\n\t\t\tBGND2_ShowPicture(30, 90, 10, 2, TRUE);\n\t\t\tS_DontDisplayPicture();\n\t\t\tInputStatus = 0;\n\t\t}\n\t\tmemcpy(GamePalette8, palette, sizeof(GamePalette8));\n\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\treturn result;\n#else // FEATURE_MOD_CONFIG\n\treturn LoadLevel(fileName, levelID);\n#endif // FEATURE_MOD_CONFIG\n}\n\nvoid __cdecl S_UnloadLevelFile() {\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tHWR_FreeTexturePages();\n\t}\n\tmemset(TexturePageBuffer8, 0, sizeof(TexturePageBuffer8));\n\t*LevelFileName = 0;\n\tTextureInfoCount = 0;\n#ifdef FEATURE_MOD_CONFIG\n\tUnloadModConfiguration();\n#endif // FEATURE_MOD_CONFIG\n#if (DIRECT3D_VERSION >= 0x900)\n\tUnloadTexPagesConfiguration();\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl S_AdjustTexelCoordinates() {\n\tif( TextureInfoCount != 0 ) {\n\t\tAdjustTextureUVs(false);\n\t}\n}\n\nBOOL __cdecl S_ReloadLevelGraphics(BOOL reloadPalettes, BOOL reloadTexPages) {\n\tHANDLE hFile;\n\n\tif( *LevelFileName ) {\n\t\thFile = CreateFile(LevelFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\t\tif( hFile == INVALID_HANDLE_VALUE )\n\t\t\treturn FALSE;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\tLoadTexPagesConfiguration(LevelFileName);\n\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\t\tif( reloadPalettes && SavedAppSettings.RenderMode == RM_Software ) {\n\t\t\tSetFilePointer(hFile, LevelFilePalettesOffset, NULL, FILE_BEGIN);\n\t\t\tLoadPalettes(hFile);\n\t\t\tSetFilePointer(hFile, LevelFileDepthQOffset, NULL, FILE_BEGIN);\n\t\t\tLoadDepthQ(hFile);\n\t\t}\n\n\t\tif( reloadTexPages ) {\n\t\t\tif( SavedAppSettings.RenderMode == RM_Hardware )\n\t\t\t\tHWR_FreeTexturePages();\n\t\t\tSetFilePointer(hFile, LevelFileTexPagesOffset, NULL, FILE_BEGIN);\n\t\t\tLoadTexturePages(hFile);\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t\t\tPatternTexPage = CreateBgndPatternTexture(hFile);\n#endif // FEATURE_BACKGROUND_IMPROVED\n\t\t}\n\t\tCloseHandle(hFile);\n\t}\n\n\tif( reloadPalettes )\n\t\tInitColours();\n\n\treturn TRUE;\n}\n\nBOOL __cdecl Read_Strings(DWORD dwCount, char **stringTable, char **stringBuffer, LPDWORD lpBufferSize, HANDLE hFile) {\n\tDWORD i, bytesRead;\n\tUINT16 bufferSize;\n\tUINT16 offsets[200]; // buffer for offsets\n\n\tReadFileSync(hFile, offsets, sizeof(UINT16) * dwCount, &bytesRead, NULL);\n\tReadFileSync(hFile, &bufferSize, sizeof(bufferSize), &bytesRead, NULL);\n\n\t*lpBufferSize = bufferSize;\n\t*stringBuffer = (char *)GlobalAlloc(GMEM_FIXED, bufferSize);\n\n\tif( *stringBuffer == NULL )\n\t\treturn FALSE;\n\n\tReadFileSync(hFile, *stringBuffer, bufferSize, &bytesRead, NULL);\n\tif( (GF_GameFlow.flags & GFF_UseSecurityTag) != 0 ) {\n\t\tfor( i = 0; i < bufferSize; ++i )\n\t\t\t(*stringBuffer)[i] ^= GF_GameFlow.cypherCode;\n\t}\n\n\tfor( i=0; i < dwCount; ++i ) {\n\t\tstringTable[i] = &(*stringBuffer)[offsets[i]];\n\t}\n\treturn TRUE;\n}\n\nBOOL __cdecl S_LoadGameFlow(LPCTSTR fileName) {\n\tDWORD scriptVersion;\n\tchar scriptDescription[DESCRIPTION_LENGTH];\n\tUINT16 offsets[200]; // buffer for offsets\n\tDWORD bytesRead;\n\tUINT16 flowSize, scriptSize, gameStringsCount;\n\tBOOL result = FALSE;\n\tLPCTSTR filePath = GetFullPath(fileName);\n\tHANDLE hFile = CreateFile(filePath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\n\tif( hFile == INVALID_HANDLE_VALUE )\n\t\treturn FALSE;\n\n\tReadFileSync(hFile, &scriptVersion, sizeof(DWORD), &bytesRead, NULL);\n\tif( scriptVersion != REQ_SCRIPT_VERSION )\n\t\tgoto CLEANUP;\n\n\tReadFileSync(hFile, &scriptDescription, DESCRIPTION_LENGTH, &bytesRead, NULL);\n\tReadFileSync(hFile, &flowSize, sizeof(flowSize), &bytesRead, NULL);\n\tif( flowSize != sizeof(GAME_FLOW) )\n\t\tgoto CLEANUP;\n\n\tReadFileSync(hFile, &GF_GameFlow, flowSize, &bytesRead, NULL);\n\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_LevelNamesStringTable,\t&GF_LevelNamesStringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Pictures,\tGF_PictureFilesStringTable,\t&GF_PictureFilesStringBuffer,\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Titles,\tGF_TitleFilesStringTable,\t&GF_TitleFilesStringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Fmvs,\t\tGF_FmvFilesStringTable,\t\t&GF_FmvFilesStringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_LevelFilesStringTable,\t&GF_LevelFilesStringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Cutscenes,\tGF_CutsFilesStringTable,\t&GF_CutsFilesStringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\n\tReadFileSync(hFile, offsets, sizeof(UINT16) * (GF_GameFlow.num_Levels + 1), &bytesRead, NULL);\n\tReadFileSync(hFile, &scriptSize, sizeof(scriptSize), &bytesRead, NULL);\n\n\tGF_ScriptBuffer = (__int16 *)GlobalAlloc(GMEM_FIXED, scriptSize);\n\tif( GF_ScriptBuffer == NULL )\n\t\tgoto CLEANUP;\n\n\tReadFileSync(hFile, GF_ScriptBuffer, scriptSize, &bytesRead, NULL);\n\tfor( int i=0; i < (GF_GameFlow.num_Levels + 1); ++i ) {\n\t\tGF_ScriptTable[i] = &GF_ScriptBuffer[offsets[i+1]/2];\n\t}\n\n\tif( GF_GameFlow.num_Demos > 0 )\n\t\tReadFileSync(hFile, GF_DemoLevels, sizeof(UINT16) * GF_GameFlow.num_Demos, &bytesRead, NULL);\n\n\tReadFileSync(hFile, &gameStringsCount, sizeof(gameStringsCount), &bytesRead, NULL);\n\tif( gameStringsCount != REQ_GAME_STR_COUNT )\n\t\tgoto CLEANUP;\n\n\t// game and platform specific strings\n\tREAD_STRINGS(gameStringsCount,\t\t\tGF_GameStringTable,\t\t\t&GF_GameStringBuffer,\t\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(SPECIFIC_STR_COUNT,\t\tGF_SpecificStringTable,\t\t&GF_SpecificStringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\t// puzzle strings\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Puzzle1StringTable,\t\t&GF_Puzzle1StringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Puzzle2StringTable,\t\t&GF_Puzzle2StringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Puzzle3StringTable,\t\t&GF_Puzzle3StringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Puzzle4StringTable,\t\t&GF_Puzzle4StringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\t// pickup strings\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Pickup1StringTable,\t\t&GF_Pickup1StringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Pickup2StringTable,\t\t&GF_Pickup2StringBuffer,\t\t&bytesRead, hFile, CLEANUP);\n\t// key strings\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Key1StringTable,\t\t\t&GF_Key1StringBuffer,\t\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Key2StringTable,\t\t\t&GF_Key2StringBuffer,\t\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Key3StringTable,\t\t\t&GF_Key3StringBuffer,\t\t\t&bytesRead, hFile, CLEANUP);\n\tREAD_STRINGS(GF_GameFlow.num_Levels,\tGF_Key4StringTable,\t\t\t&GF_Key4StringBuffer,\t\t\t&bytesRead, hFile, CLEANUP);\n\n\tresult = TRUE;\n\nCLEANUP:\n\tCloseHandle(hFile);\n\treturn result;\n}\n\n/*\n * Inject function\n */\nvoid Inject_File() {\n\tINJECT(0x00449980, ReadFileSync);\n\tINJECT(0x004499D0, LoadTexturePages);\n\tINJECT(0x00449B60, LoadRooms);\n\tINJECT(0x00449F00, AdjustTextureUVs);\n\tINJECT(0x00449FA0, LoadObjects);\n\tINJECT(0x0044A520, LoadSprites);\n\tINJECT(0x0044A660, LoadItems);\n\tINJECT(0x0044A840, LoadDepthQ);\n\tINJECT(0x0044A9D0, LoadPalettes);\n\tINJECT(0x0044AA50, LoadCameras);\n\tINJECT(0x0044AAB0, LoadSoundEffects);\n\tINJECT(0x0044AB10, LoadBoxes);\n\tINJECT(0x0044AD40, LoadAnimatedTextures);\n\tINJECT(0x0044ADA0, LoadCinematic);\n\tINJECT(0x0044AE20, LoadDemo);\n\tINJECT(0x0044AEB0, LoadDemoExternal);\n\tINJECT(0x0044AF50, LoadSamples);\n\tINJECT(0x0044B1C0, ChangeFileNameExtension);\n\tINJECT(0x0044B200, GetFullPath);\n\tINJECT(0x0044B230, SelectDrive);\n\tINJECT(0x0044B310, LoadLevel);\n\tINJECT(0x0044B560, S_LoadLevelFile);\n\tINJECT(0x0044B580, S_UnloadLevelFile);\n\tINJECT(0x0044B5B0, S_AdjustTexelCoordinates);\n\tINJECT(0x0044B5D0, S_ReloadLevelGraphics);\n\tINJECT(0x0044B6A0, Read_Strings);\n\tINJECT(0x0044B770, S_LoadGameFlow);\n}\n"
  },
  {
    "path": "specific/file.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef FILE_H_INCLUDED\n#define FILE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nBOOL __cdecl ReadFileSync(HANDLE hFile, LPVOID lpBuffer, DWORD nBytesToRead, LPDWORD lpnBytesRead, LPOVERLAPPED lpOverlapped); // 0x00449980\nBOOL __cdecl LoadTexturePages(HANDLE hFile); // 0x004499D0\nBOOL __cdecl LoadRooms(HANDLE hFile); // 0x00449B60\nvoid __cdecl AdjustTextureUVs(bool resetUvFix); // 0x00449F00\nBOOL __cdecl LoadObjects(HANDLE hFile); // 0x00449FA0\nBOOL __cdecl LoadSprites(HANDLE hFile); // 0x0044A520\nBOOL __cdecl LoadItems(HANDLE hFile); // 0x0044A660\nBOOL __cdecl LoadDepthQ(HANDLE hFile); // 0x0044A840\nBOOL __cdecl LoadPalettes(HANDLE hFile); // 0x0044A9D0\nBOOL __cdecl LoadCameras(HANDLE hFile); // 0x0044AA50\nBOOL __cdecl LoadSoundEffects(HANDLE hFile); // 0x0044AAB0\nBOOL __cdecl LoadBoxes(HANDLE hFile); // 0x0044AB10\nBOOL __cdecl LoadAnimatedTextures(HANDLE hFile); // 0x0044AD40\nBOOL __cdecl LoadCinematic(HANDLE hFile); // 0x0044ADA0\nBOOL __cdecl LoadDemo(HANDLE hFile); // 0x0044AE20\nvoid __cdecl LoadDemoExternal(LPCSTR levelName); // 0x0044AEB0\nBOOL __cdecl LoadSamples(HANDLE hFile); // 0x0044AF50\nvoid __cdecl ChangeFileNameExtension(char *fileName, const char *fileExt); // 0x0044B1C0\nLPCTSTR __cdecl GetFullPath(LPCTSTR path); // 0x0044B200\nBOOL __cdecl SelectDrive(); // 0x0044B230\nBOOL __cdecl LoadLevel(LPCTSTR fileName, int levelID); // 0x0044B310\nBOOL __cdecl S_LoadLevelFile(LPCTSTR fileName, int levelID, GF_LEVEL_TYPE levelType); // 0x0044B560\nvoid __cdecl S_UnloadLevelFile(); // 0x0044B580\nvoid __cdecl S_AdjustTexelCoordinates(); // 0x0044B5B0\nBOOL __cdecl S_ReloadLevelGraphics(BOOL reloadPalettes, BOOL reloadTexPages); // 0x0044B5D0\nBOOL __cdecl Read_Strings(DWORD dwCount, char **stringTable, char **stringBuffer, LPDWORD lpBufferSize, HANDLE hFile); // 0x0044B6A0\nBOOL __cdecl S_LoadGameFlow(LPCTSTR fileName); // 0x0044B770\n\n#endif // FILE_H_INCLUDED\n"
  },
  {
    "path": "specific/fmv.cpp",
    "content": "/*\n * Copyright (c) 2017-2023 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/fmv.h\"\n#include \"specific/file.h\"\n#include \"specific/init_display.h\"\n#include \"specific/input.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\n// GetProcAddress Macro\n#define GET_DLL_PROC(dll, proc) { \\\n\t*(FARPROC *)&(proc) = GetProcAddress((dll), #proc); \\\n\tif( proc == NULL ) throw #proc; \\\n}\n\n#if (DIRECT3D_VERSION <= 0x500)\n// The original FMV playback supports DirectX 5 only\n// It does not support any newer version of DirectX\n#define ESCAPE_DLL_NAME \"winplay.dll\"\nstatic HMODULE hEscapePlay = NULL;\n\n// Imports from winplay.dll\nstatic int (__cdecl *Movie_GetCurrentFrame)(LPVOID);\nstatic int (__cdecl *Movie_GetFormat)(LPVOID);\nstatic int (__cdecl *Movie_GetSoundChannels)(LPVOID);\nstatic int (__cdecl *Movie_GetSoundPrecision)(LPVOID);\nstatic int (__cdecl *Movie_GetSoundRate)(LPVOID);\nstatic int (__cdecl *Movie_GetTotalFrames)(LPVOID);\nstatic int (__cdecl *Movie_GetXSize)(LPVOID);\nstatic int (__cdecl *Movie_GetYSize)(LPVOID);\nstatic int (__cdecl *Movie_SetSyncAdjust)(LPVOID, LPVOID, DWORD);\nstatic int (__cdecl *Player_BlankScreen)(DWORD, DWORD, DWORD, DWORD);\nstatic int (__cdecl *Player_GetDSErrorCode)();\nstatic int (__cdecl *Player_InitMovie)(LPVOID, DWORD, DWORD, LPCTSTR, DWORD);\nstatic int (__cdecl *Player_InitMoviePlayback)(LPVOID, LPVOID, LPVOID);\nstatic int (__cdecl *Player_InitPlaybackMode)(HWND, LPVOID, DWORD, DWORD);\nstatic int (__cdecl *Player_InitSound)(LPVOID, DWORD, DWORD, BOOL, DWORD, DWORD, DWORD, DWORD, DWORD);\nstatic int (__cdecl *Player_InitSoundSystem)(HWND);\nstatic int (__cdecl *Player_InitVideo)(LPVOID, LPVOID, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD);\nstatic int (__cdecl *Player_PassInDirectDrawObject)(LPDIRECTDRAW2);\nstatic int (__cdecl *Player_PlayFrame)(LPVOID, LPVOID, LPVOID, DWORD, LPRECT, DWORD, DWORD, DWORD);\nstatic int (__cdecl *Player_ReturnPlaybackMode)(BOOL);\nstatic int (__cdecl *Player_ShutDownMovie)(LPVOID);\nstatic int (__cdecl *Player_ShutDownSound)(LPVOID);\nstatic int (__cdecl *Player_ShutDownSoundSystem)();\nstatic int (__cdecl *Player_ShutDownVideo)(LPVOID);\nstatic int (__cdecl *Player_StartTimer)(LPVOID);\nstatic int (__cdecl *Player_StopTimer)(LPVOID);\n#endif // (DIRECT3D_VERSION <= 0x500)\n\n#ifdef FEATURE_FFPLAY\n#define FFPLAY_DLL_NAME \"ffplay.dll\"\nstatic HMODULE hFFplay = NULL;\n\n// Imports from ffplay.dll\nstatic int (__stdcall *ffplay_init)(HWND, int, const char*);\nstatic int (__stdcall *ffplay_play_video)(const char*, int, int, int, int);\nstatic int (__stdcall *ffplay_cleanup)(void);\n\nstatic const char videoExts[][4] = {\n\t\"MP4\",\n\t\"BIK\",\n\t\"RPL\",\n};\n\nstatic bool FFplayInit() {\n\tif( hFFplay != NULL ) {\n\t\treturn true;\n\t}\n\n\thFFplay = LoadLibrary(FFPLAY_DLL_NAME);\n\tif( hFFplay == NULL ) {\n\t\t// failed to load DLL\n\t\treturn false;\n\t}\n\n\ttry {\n\t\tGET_DLL_PROC(hFFplay, ffplay_init);\n\t\tGET_DLL_PROC(hFFplay, ffplay_play_video);\n\t\tGET_DLL_PROC(hFFplay, ffplay_cleanup);\n\t} catch (LPCTSTR procName) {\n\t\t// failed to load one of the procs\n\t\tFreeLibrary(hFFplay);\n\t\thFFplay = NULL;\n\t\treturn false;\n\t}\n\n\tif( 0 != ffplay_init(HGameWindow, 2, \"winmm\") ) {\n\t\t// failed to init FFplay\n\t\tFreeLibrary(hFFplay);\n\t\thFFplay = NULL;\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nvoid __cdecl FFplayCleanup() {\n\tif( hFFplay != NULL ) {\n\t\tffplay_cleanup();\n\t\tFreeLibrary(hFFplay);\n\t\thFFplay = NULL;\n\t}\n}\n#endif // FEATURE_FFPLAY\n\nbool __cdecl FMV_Init() {\n#ifdef FEATURE_FFPLAY\n\tif( FFplayInit() ) {\n\t\treturn true;\n\t}\n#endif // FEATURE_FFPLAY\n#if (DIRECT3D_VERSION > 0x500)\n\treturn false;\n#else // (DIRECT3D_VERSION > 0x500)\n\tif( hEscapePlay != NULL ) {\n\t\treturn true;\n\t}\n\n\thEscapePlay = LoadLibrary(ESCAPE_DLL_NAME);\n\tif( hEscapePlay == NULL ) {\n\t\t// failed to load DLL\n\t\treturn false;\n\t}\n\n\ttry {\n\t\tGET_DLL_PROC(hEscapePlay, Movie_GetCurrentFrame);\n\t\tGET_DLL_PROC(hEscapePlay, Movie_GetFormat);\n\t\tGET_DLL_PROC(hEscapePlay, Movie_GetSoundChannels);\n\t\tGET_DLL_PROC(hEscapePlay, Movie_GetSoundPrecision);\n\t\tGET_DLL_PROC(hEscapePlay, Movie_GetSoundRate);\n\t\tGET_DLL_PROC(hEscapePlay, Movie_GetTotalFrames);\n\t\tGET_DLL_PROC(hEscapePlay, Movie_GetXSize);\n\t\tGET_DLL_PROC(hEscapePlay, Movie_GetYSize);\n\t\tGET_DLL_PROC(hEscapePlay, Movie_SetSyncAdjust);\n\t\tGET_DLL_PROC(hEscapePlay, Player_BlankScreen);\n\t\tGET_DLL_PROC(hEscapePlay, Player_GetDSErrorCode);\n\t\tGET_DLL_PROC(hEscapePlay, Player_InitMovie);\n\t\tGET_DLL_PROC(hEscapePlay, Player_InitMoviePlayback);\n\t\tGET_DLL_PROC(hEscapePlay, Player_InitPlaybackMode);\n\t\tGET_DLL_PROC(hEscapePlay, Player_InitSound);\n\t\tGET_DLL_PROC(hEscapePlay, Player_InitSoundSystem);\n\t\tGET_DLL_PROC(hEscapePlay, Player_InitVideo);\n\t\tGET_DLL_PROC(hEscapePlay, Player_PassInDirectDrawObject);\n\t\tGET_DLL_PROC(hEscapePlay, Player_PlayFrame);\n\t\tGET_DLL_PROC(hEscapePlay, Player_ReturnPlaybackMode);\n\t\tGET_DLL_PROC(hEscapePlay, Player_ShutDownMovie);\n\t\tGET_DLL_PROC(hEscapePlay, Player_ShutDownSound);\n\t\tGET_DLL_PROC(hEscapePlay, Player_ShutDownSoundSystem);\n\t\tGET_DLL_PROC(hEscapePlay, Player_ShutDownVideo);\n\t\tGET_DLL_PROC(hEscapePlay, Player_StartTimer);\n\t\tGET_DLL_PROC(hEscapePlay, Player_StopTimer);\n\t} catch (LPCTSTR procName) {\n\t\t// failed to load one of the procs\n\t\tFreeLibrary(hEscapePlay);\n\t\thEscapePlay = NULL;\n\t\treturn false;\n\t}\n\n\treturn true;\n#endif // (DIRECT3D_VERSION > 0x500)\n}\n\nvoid __cdecl FMV_Cleanup() {\n#ifdef FEATURE_FFPLAY\n\tFFplayCleanup();\n#endif // FEATURE_FFPLAY\n#if (DIRECT3D_VERSION <= 0x500)\n\tif( hEscapePlay != NULL ) {\n\t\tFreeLibrary(hEscapePlay);\n\t\thEscapePlay = NULL;\n\t}\n#endif // (DIRECT3D_VERSION <= 0x500)\n}\n\nbool __cdecl PlayFMV(LPCTSTR fileName) {\n\tLPCTSTR fullPath;\n\n\tif( SavedAppSettings.DisableFMV )\n\t\treturn IsGameToExit;\n\n\tS_CDStop();\n\tShowCursor(FALSE);\n\tRenderFinish(true);\n\tIsFmvPlaying = TRUE;\n\n\tfullPath = GetFullPath(fileName);\n\tWinPlayFMV(fullPath, true);\n\tWinStopFMV(true);\n\n\tIsFmvPlaying = FALSE;\n\tif( !IsGameToExit )\n\t\tFmvBackToGame();\n\tShowCursor(TRUE);\n\n\treturn IsGameToExit;\n}\n\nvoid __cdecl WinPlayFMV(LPCTSTR fileName, bool isPlayback) {\n#ifdef FEATURE_FFPLAY\n\tif( hFFplay != NULL ) {\n\t\tchar extFileName[256] = {0};\n\t\tchar *extension;\n\n\t\tstrncpy(extFileName, fileName, sizeof(extFileName)-1);\n\t\textension = PathFindExtension(extFileName);\n\t\tif( extension == NULL ) {\n\t\t\textension = strchr(extFileName, 0);\n\t\t\t*extension = '.';\n\t\t}\n\t\tfor( unsigned int i = 0; i < sizeof(videoExts)/4; ++i ) {\n\t\t\tmemcpy(extension + 1, videoExts[i], 4);\n\t\t\tif( INVALID_FILE_ATTRIBUTES != GetFileAttributes(extFileName) ) {\n\t\t\t\tffplay_play_video(extFileName, 0, 0, 0, 100);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tffplay_play_video(fileName, 0, 0, 0, 100);\n\t\treturn;\n\t}\n#endif // FEATURE_FFPLAY\n#if (DIRECT3D_VERSION <= 0x500)\n\tint xSize, ySize, xOffset, yOffset;\n\tint soundPrecision, soundRate, soundChannels, soundFormat;\n\tbool isUncompressed;\n\tRECT rect = {0, 0, 640, 480};\n\n\tif( hEscapePlay == NULL ) {\n\t\treturn;\n\t}\n\n\tif( 0 != Player_PassInDirectDrawObject(DDraw) ||\n\t\t0 != Player_InitMovie(&MovieContext, 0, 0, fileName, 0x200000) ||\n\t\t130 != Movie_GetFormat(MovieContext) )\n\t{\n\t\treturn;\n\t}\n\n\txSize = Movie_GetXSize(MovieContext); // RPL movie width is always 320\n\tySize = Movie_GetYSize(MovieContext); // maximum possible value for RPL movie height is 240\n\txOffset = 320 - xSize;\n\tyOffset = 240 - ySize;\n\n\tif( 0 != Player_InitVideo(&FmvContext, MovieContext, xSize, ySize, xOffset, yOffset, 0, 0, 640, 480, 0, 1, 13) ||\n\t\t(isPlayback && 0 != Player_InitPlaybackMode(HGameWindow, FmvContext, 1, 0)) )\n\t{\n\t\treturn;\n\t}\n\n\tPlayer_BlankScreen(rect.left, rect.top, rect.right, rect.bottom);\n\n\tif( 0 != Player_InitSoundSystem(HGameWindow) ||\n\t\tPlayer_GetDSErrorCode() < 0 )\n\t{\n\t\treturn;\n\t}\n\n\tsoundPrecision = Movie_GetSoundPrecision(MovieContext);\n\tsoundRate = Movie_GetSoundRate(MovieContext);\n\tsoundChannels = Movie_GetSoundChannels(MovieContext);\n\tisUncompressed = ( soundPrecision != 4 );\n\tsoundFormat = isUncompressed ? 1 : 4;\n\tif( 0 != Player_InitSound(&FmvSoundContext, 16384, soundFormat, isUncompressed, 4096, soundChannels, soundRate, soundPrecision, 2) ) {\n\t\treturn;\n\t}\n\n\tMovie_SetSyncAdjust(MovieContext, FmvSoundContext, 4);\n\n\tif( 0 != Player_InitMoviePlayback(MovieContext, FmvContext, FmvSoundContext) ) {\n\t\treturn;\n\t}\n\n\tS_UpdateInput(); // NOTE: should use WinVidSpinMessageLoop(false) instead\n\tPlayer_StartTimer(MovieContext);\n\tPlayer_BlankScreen(rect.left, rect.top, rect.right, rect.bottom);\n\tS_UpdateInput(); // NOTE: should use WinVidSpinMessageLoop(false) instead\n\n\twhile( Movie_GetCurrentFrame(MovieContext) < Movie_GetTotalFrames(MovieContext) ) {\n\t\tif( 0 != Player_PlayFrame(MovieContext, FmvContext, FmvSoundContext, 0, &rect, 0, 0, 0) )\n\t\t\treturn;\n\t\tif( S_UpdateInput() || CHK_ANY(InputStatus, IN_OPTION) )\n\t\t\tbreak;\n\t}\n#endif // (DIRECT3D_VERSION <= 0x500)\n}\n\nvoid __cdecl WinStopFMV(bool isPlayback) {\n#if (DIRECT3D_VERSION <= 0x500)\n\tif( hEscapePlay == NULL ) {\n\t\treturn;\n\t}\n\tPlayer_StopTimer(MovieContext);\n\tPlayer_ShutDownSound(&FmvSoundContext);\n\tPlayer_ShutDownVideo(&FmvContext);\n\tPlayer_ShutDownMovie(&MovieContext);\n\tPlayer_ShutDownSoundSystem();\n\tif( isPlayback ) {\n\t\tPlayer_ReturnPlaybackMode(isPlayback);\n\t}\n#endif // (DIRECT3D_VERSION <= 0x500)\n}\n\nbool __cdecl IntroFMV(LPCTSTR fileName1, LPCTSTR fileName2) {\n\tLPCTSTR fullPath;\n\n\tif( SavedAppSettings.DisableFMV )\n\t\treturn IsGameToExit;\n\n\tShowCursor(FALSE);\n\tRenderFinish(true);\n\tIsFmvPlaying = TRUE;\n\n\tfullPath = GetFullPath(fileName1);\n\tWinPlayFMV(fullPath, true);\n\tWinStopFMV(true);\n\n\tfullPath = GetFullPath(fileName2);\n\tWinPlayFMV(fullPath, true);\n\tWinStopFMV(true);\n\n\tIsFmvPlaying = FALSE;\n\tif( !IsGameToExit )\n\t\tFmvBackToGame();\n\tShowCursor(TRUE);\n\n\treturn IsGameToExit;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Fmv() {\n\tINJECT(0x0044BE50, PlayFMV);\n\tINJECT(0x0044BED0, WinPlayFMV);\n\tINJECT(0x0044C1B0, WinStopFMV);\n\tINJECT(0x0044C200, IntroFMV);\n}\n"
  },
  {
    "path": "specific/fmv.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef FMV_H_INCLUDED\n#define FMV_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nbool __cdecl FMV_Init();\nvoid __cdecl FMV_Cleanup();\nbool __cdecl PlayFMV(LPCTSTR fileName); // 0x0044BE50\nvoid __cdecl WinPlayFMV(LPCSTR fileName, bool isPlayback); // 0x0044BED0\nvoid __cdecl WinStopFMV(bool isPlayback); // 0x0044C1B0\nbool __cdecl IntroFMV(LPCTSTR fileName1, LPCTSTR fileName2); // 0x0044C200\n\n#endif // FMV_H_INCLUDED\n"
  },
  {
    "path": "specific/frontend.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/frontend.h\"\n#include \"specific/display.h\"\n#include \"specific/fmv.h\"\n#include \"specific/input.h\"\n#include \"specific/output.h\"\n#include \"specific/texture.h\"\n#include \"specific/utils.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/background_new.h\"\nbool IsFadeToBlack = false;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#ifdef FEATURE_HUD_IMPROVED\n#include \"3dsystem/3dinsert.h\"\n\nDWORD InvTextBoxMode = 1;\n#endif // FEATURE_HUD_IMPROVED\n\nstatic void FadeWait() {\n\t// Null function\n}\n\nUINT16 __cdecl S_COLOUR(int red, int green, int blue) {\n\treturn FindNearestPaletteEntry(GamePalette8, red, green, blue, false);\n}\n\nvoid __cdecl S_DrawScreenLine(int x, int y, int z, int xLen, int yLen, BYTE colorIdx, D3DCOLOR *gour, UINT16 flags) {\n\tins_line(x, y, x + xLen, y + yLen, PhdNearZ + z * 8, colorIdx);\n}\n\nvoid __cdecl S_DrawScreenBox(int sx, int sy, int z, int width, int height, BYTE colorIdx, GOURAUD_OUTLINE *gour, UINT16 flags) {\n\tint adder;\n#ifdef FEATURE_HUD_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\tadder = GetRenderScale(1);\n\t\tsx += adder;\n\t\tsy += adder;\n\t} else {\n\t\tadder = GetRenderScale(2);\n\t}\n#else // !FEATURE_HUD_IMPROVED\n\t// NOTE: in the original code there was no adder at all for this function\n\tadder = 2;\n#endif // FEATURE_HUD_IMPROVED\n\twidth += adder;\n\theight += adder;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode && gour != NULL ) {\n\t\tint x[3], y[3], lw;\n\t\tint sz = PhdNearZ + z * 8;\n\n\t\tlw = GetRenderScale(1);\n\t\tx[0] = sx;\n\t\ty[0] = sy;\n\t\tx[2] = sx + width;\n\t\ty[2] = sy + height;\n\t\tx[1] = (x[0] + x[2]) / 2;\n\t\ty[1] = (y[0] + y[2]) / 2;\n\n\t\tInsertGourQuad(x[0]-lw, y[0]-lw, x[1], y[0], sz,\n\t\t\t\t\t\tgour->clr[0], gour->clr[1],\n\t\t\t\t\t\tgour->clr[1], gour->clr[0]);\n\t\tInsertGourQuad(x[1], y[0]-lw, x[2], y[0], sz,\n\t\t\t\t\t\tgour->clr[1], gour->clr[2],\n\t\t\t\t\t\tgour->clr[2], gour->clr[1]);\n\n\t\tInsertGourQuad(x[2], y[0]-lw, x[2]+lw, y[1], sz,\n\t\t\t\t\t\tgour->clr[2], gour->clr[2],\n\t\t\t\t\t\tgour->clr[3], gour->clr[3]);\n\t\tInsertGourQuad(x[2], y[1], x[2]+lw, y[2], sz,\n\t\t\t\t\t\tgour->clr[3], gour->clr[3],\n\t\t\t\t\t\tgour->clr[4], gour->clr[4]);\n\n\t\tInsertGourQuad(x[1], y[2], x[2]+lw, y[2]+lw, sz,\n\t\t\t\t\t\tgour->clr[5], gour->clr[4],\n\t\t\t\t\t\tgour->clr[4], gour->clr[5]);\n\t\tInsertGourQuad(x[0], y[2], x[1], y[2]+lw, sz,\n\t\t\t\t\t\tgour->clr[6], gour->clr[5],\n\t\t\t\t\t\tgour->clr[5], gour->clr[6]);\n\n\t\tInsertGourQuad(x[0]-lw, y[1], x[0], y[2]+lw, sz,\n\t\t\t\t\t\tgour->clr[7], gour->clr[7],\n\t\t\t\t\t\tgour->clr[6], gour->clr[6]);\n\t\tInsertGourQuad(x[0]-lw, y[0], x[0], y[1], sz,\n\t\t\t\t\t\tgour->clr[8], gour->clr[8],\n\t\t\t\t\t\tgour->clr[7], gour->clr[7]);\n\t\treturn;\n\t}\n#endif // FEATURE_HUD_IMPROVED\n\tconst BYTE colorIdx1 = 15;\n\tconst BYTE colorIdx2 = 31;\n\tint sx1 = sx + width;\n\tint sy1 = sy + height;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tint pixel = GetRenderScale(1);\n\n\tins_flat_rect(sx+pixel*0, sy-pixel*1, sx1+pixel*2, sy-pixel*0, z, colorIdx1);\n\tins_flat_rect(sx+pixel*1, sy-pixel*0, sx1+pixel*1, sy+pixel*1, z, colorIdx2);\n\n\tins_flat_rect(sx1+pixel*0, sy+pixel*1, sx1+pixel*1, sy1+pixel*1, z, colorIdx1);\n\tins_flat_rect(sx1+pixel*1, sy+pixel*0, sx1+pixel*2, sy1+pixel*2, z, colorIdx2);\n\n\tins_flat_rect(sx-pixel*1, sy-pixel*1, sx+pixel*0, sy1+pixel*1, z, colorIdx1);\n\tins_flat_rect(sx-pixel*0, sy-pixel*0, sx+pixel*1, sy1+pixel*0, z, colorIdx2);\n\n\tins_flat_rect(sx-pixel*0, sy1+pixel*0, sx1+pixel*0, sy1+pixel*1, z, colorIdx1);\n\tins_flat_rect(sx-pixel*1, sy1+pixel*1, sx1+pixel*1, sy1+pixel*2, z, colorIdx2);\n#else // !FEATURE_HUD_IMPROVED\n\t// NOTE: line coordinates slightly adjusted to fill gaps in the box corners (original game HWR bug)\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t++width;\n\t\t++height;\n\t}\n\tS_DrawScreenLine(sx,\tsy-1,\tz,\twidth+1,\t0,\t\t\tcolorIdx1, NULL, flags);\n\tS_DrawScreenLine(sx+1,\tsy,\t\tz,\twidth-1,\t0,\t\t\tcolorIdx2, NULL, flags);\n\n\tS_DrawScreenLine(sx1,\tsy+1,\tz,\t0,\t\t\theight-1,\tcolorIdx1, NULL, flags);\n\tS_DrawScreenLine(sx1+1,\tsy,\t\tz,\t0,\t\t\theight+1,\tcolorIdx2, NULL, flags);\n\n\tS_DrawScreenLine(sx-1,\tsy-1,\tz,\t0,\t\t\theight+1,\tcolorIdx1, NULL, flags);\n\tS_DrawScreenLine(sx,\tsy,\t\tz,\t0,\t\t\theight-1,\tcolorIdx2, NULL, flags);\n\n\tS_DrawScreenLine(sx,\tsy1,\tz,\twidth-1,\t0,\t\t\tcolorIdx1, NULL, flags);\n\tS_DrawScreenLine(sx-1,\tsy1+1,\tz,\twidth+1,\t0,\t\t\tcolorIdx2, NULL, flags);\n#endif // !FEATURE_HUD_IMPROVED\n}\n\nvoid __cdecl S_DrawScreenFBox(int sx, int sy, int z, int width, int height, BYTE colorIdx, GOURAUD_FILL *gour, UINT16 flags) {\n\tint adder;\n\tint sz = PhdNearZ + z * 8;\n#ifdef FEATURE_HUD_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\tadder = GetRenderScale(1);\n\t\tsx += adder;\n\t\tsy += adder;\n\t} else {\n\t\tadder = GetRenderScale(2);\n\t}\n#else // !FEATURE_HUD_IMPROVED\n\t// NOTE: in the original code the adder was 1, but 1 is insufficient,\n\t// because there was visible gap between FBox and bottom/right Frame\n\tadder = 2;\n#endif // FEATURE_HUD_IMPROVED\n\twidth += adder;\n\theight += adder;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode && gour != NULL ) {\n\t\tint x[3], y[3];\n\n\t\tx[0] = sx;\n\t\ty[0] = sy;\n\t\tx[2] = sx + width;\n\t\ty[2] = sy + height;\n\t\tx[1] = (x[0] + x[2]) / 2;\n\t\ty[1] = (y[0] + y[2]) / 2;\n\n\t\tInsertGourQuad(x[0], y[0], x[1], y[1], sz,\n\t\t\t\t\t\tgour->clr[0][0], gour->clr[0][1],\n\t\t\t\t\t\tgour->clr[0][2], gour->clr[0][3]);\n\t\tInsertGourQuad(x[1], y[0], x[2], y[1], sz,\n\t\t\t\t\t\tgour->clr[1][0], gour->clr[1][1],\n\t\t\t\t\t\tgour->clr[1][2], gour->clr[1][3]);\n\t\tInsertGourQuad(x[1], y[1], x[2], y[2], sz,\n\t\t\t\t\t\tgour->clr[2][0], gour->clr[2][1],\n\t\t\t\t\t\tgour->clr[2][2], gour->clr[2][3]);\n\t\tInsertGourQuad(x[0], y[1], x[1], y[2], sz,\n\t\t\t\t\t\tgour->clr[3][0], gour->clr[3][1],\n\t\t\t\t\t\tgour->clr[3][2], gour->clr[3][3]);\n\t\treturn;\n\t}\n#endif // FEATURE_HUD_IMPROVED\n\tins_trans_quad(sx, sy, width, height, sz);\n}\n\nvoid __cdecl S_FinishInventory() {\n\tif( InventoryMode != INV_TitleMode )\n\t\tTempVideoRemove();\n}\n\nvoid __cdecl S_FadeToBlack() {\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tIsFadeToBlack = true;\n\t\tS_CopyScreenToBuffer();\n\t\tBGND2_ShowPicture(0, 0, 10, 2, FALSE);\n\t\tIsFadeToBlack = false;\n\t\treturn;\n\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tmemset(GamePalette8, 0, sizeof(GamePalette8));\n\tFadeToPal(10, GamePalette8);\n\tFadeWait();\n\n\t// make two blank frames\n#if (DIRECT3D_VERSION >= 0x900)\n\tScreenClear(false);\n\tS_Wait(2 * TICKS_PER_FRAME, FALSE);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tScreenClear(false); ScreenDump();\n\tScreenClear(false); ScreenDump();\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl S_Wait(int timeout, BOOL inputCheck) {\n\t// Wait for key event to clear or timeout\n\tfor( ; timeout > 0; --timeout ) {\n\t\tif( !inputCheck || InputStatus == 0 )\n\t\t\tbreak;\n\t\tS_UpdateInput();\n\t\tif( IsGameToExit ) return; // NOTE: this line is not in the original game\n\t\tSyncTicks(1); // NOTE: there was another code in the original game\n\t}\n\n\t// Wait for key event to set or timeout\n\tfor( ; timeout > 0; --timeout ) {\n\t\tS_UpdateInput();\n\t\tif( IsGameToExit ) return; // NOTE: this line is not in the original game\n\t\tif( inputCheck && InputStatus != 0 )\n\t\t\tbreak;\n\t\tSyncTicks(1); // NOTE: there was another code in the original game\n\t}\n}\n\nbool __cdecl S_PlayFMV(LPCTSTR fileName) {\n\treturn PlayFMV(fileName);\n}\n\nbool __cdecl S_IntroFMV(LPCTSTR fileName1, LPCTSTR fileName2) {\n\treturn IntroFMV(fileName1, fileName2);\n}\n\n/*\n * Inject function\n */\nvoid Inject_Frontend() {\n\tINJECT(0x0044C2A0, S_COLOUR);\n\tINJECT(0x0044C2D0, S_DrawScreenLine);\n\tINJECT(0x0044C310, S_DrawScreenBox);\n\tINJECT(0x0044C430, S_DrawScreenFBox);\n\tINJECT(0x0044C460, S_FinishInventory);\n\tINJECT(0x0044C470, S_FadeToBlack);\n\tINJECT(0x0044C4C0, S_Wait);\n\tINJECT(0x0044C520, S_PlayFMV);\n\tINJECT(0x0044C530, S_IntroFMV);\n}\n"
  },
  {
    "path": "specific/frontend.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef FRONTEND_H_INCLUDED\n#define FRONTEND_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nUINT16 __cdecl S_COLOUR(int red, int green, int blue); // 0x0044C2A0\nvoid __cdecl S_DrawScreenLine(int x, int y, int z, int xLen, int yLen, BYTE colorIdx, D3DCOLOR *gour, UINT16 flags); // 0x0044C2D0\nvoid __cdecl S_DrawScreenBox(int sx, int sy, int z, int width, int height, BYTE colorIdx, GOURAUD_OUTLINE *gour, UINT16 flags); // 0x0044C310\nvoid __cdecl S_DrawScreenFBox(int sx, int sy, int z, int width, int height, BYTE colorIdx, GOURAUD_FILL *gour, UINT16 flags); // 0x0044C430\nvoid __cdecl S_FinishInventory(); // 0x0044C460\nvoid __cdecl S_FadeToBlack(); // 0x0044C470\nvoid __cdecl S_Wait(int timeout, BOOL inputCheck); // 0x0044C4C0\nbool __cdecl S_PlayFMV(LPCTSTR fileName); // 0x0044C520\nbool __cdecl S_IntroFMV(LPCTSTR fileName1, LPCTSTR fileName2); // 0x0044C530\n\n#endif // FRONTEND_H_INCLUDED\n"
  },
  {
    "path": "specific/game.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/game.h\"\n#include \"game/camera.h\"\n#include \"game/control.h\"\n#include \"game/draw.h\"\n#include \"game/inventory.h\"\n#include \"game/invtext.h\"\n#include \"game/savegame.h\"\n#include \"game/setup.h\"\n#include \"game/text.h\"\n#include \"specific/background.h\"\n#include \"specific/display.h\"\n#include \"specific/file.h\"\n#include \"specific/frontend.h\"\n#include \"specific/init.h\"\n#include \"specific/input.h\"\n#include \"specific/output.h\"\n#include \"specific/sndpc.h\"\n#include \"specific/winvid.h\"\n#include \"specific/texture.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/background_new.h\"\nextern DWORD StatsBackgroundMode;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\n#ifdef FEATURE_GOLD\nextern bool IsGold();\n#endif // FEATURE_GOLD\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nextern void ResetGoldenLaraAlpha();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n#ifdef FEATURE_HUD_IMPROVED\nextern bool GF_IsFinalLevel(DWORD levelID);\nextern void RemoveJoystickHintText(bool isSelect, bool isContinue, bool isDeselect);\nextern void DisplayJoystickHintText(bool isSelect, bool isContinue, bool isDeselect);\n#endif // FEATURE_HUD_IMPROVED\n\n#ifdef FEATURE_SUBFOLDERS\n#include \"modding/file_utils.h\"\n\nstatic int GetSaveFileName(LPSTR destName, DWORD destSize, int slotNumber) {\n\tif( destName == NULL || destSize == 0 || slotNumber < 0 ) {\n\t\treturn -1;\n\t}\n#ifdef FEATURE_GOLD\n\tsnprintf(destName, destSize, \".\\\\saves%s\\\\savegame.%d\", IsGold()?\"Gold\":\"\", slotNumber);\n#else // !FEATURE_GOLD\n\tsnprintf(destName, destSize, \".\\\\saves\\\\savegame.%d\", slotNumber);\n#endif // !FEATURE_GOLD\n\treturn 0;\n}\n#endif // FEATURE_SUBFOLDERS\n\nDWORD SavegameSlots = 16;\n\n__int16 __cdecl StartGame(int levelID, GF_LEVEL_TYPE levelType) {\n\tif( levelType == GFL_NORMAL || levelType == GFL_SAVED || levelType == GFL_DEMO )\n\t\tCurrentLevel = levelID;\n\n\tif( levelType != GFL_SAVED )\n\t\tModifyStartInfo(levelID);\n\n\tIsTitleLoaded = FALSE;\n\n\tif( levelType != GFL_SAVED )\n\t\tInitialiseLevelFlags();\n\n\tif( !InitialiseLevel(levelID, levelType) ) {\n\t\tCurrentLevel = 0;\n\t\treturn GF_EXIT_GAME;\n\t}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tResetGoldenLaraAlpha();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tint res = GameLoop(FALSE);\n#ifdef FEATURE_INPUT_IMPROVED\n\tJoyOutputReset();\n#endif // FEATURE_INPUT_IMPROVED\n\tswitch( res ) {\n\t\tcase GF_EXIT_GAME :\n\t\t\tCurrentLevel = 0;\n\t\t\treturn GF_EXIT_GAME;\n\n\t\tcase GF_START_DEMO :\n\t\tcase GF_EXIT_TO_TITLE :\n\t\t\treturn res;\n\t}\n\n\tif( IsLevelComplete ) {\n\t\tif( (GF_GameFlow.flags & GFF_DemoVersion) != 0 && GF_GameFlow.singleLevel )\n\t\t\treturn GF_EXIT_TO_TITLE;\n\n\t\tif( CurrentLevel == 0 ) { // Assault (Lara Home)\n\t\t\tS_FadeToBlack();\n\t\t\treturn GF_EXIT_TO_TITLE;\n\t\t} else { // Normal level\n\t\t\tS_FadeInInventory(TRUE);\n\t\t\treturn GF_LEVEL_COMPLETE | CurrentLevel;\n\t\t}\n\t}\n\n\tS_FadeToBlack();\n\tif( !InventoryChosen )\n\t\treturn GF_EXIT_TO_TITLE;\n\n\tif( InventoryExtraData[0] == 0 ) { // passport page (Load game)\n\t\tS_LoadGame(&SaveGame, sizeof(SAVEGAME_INFO), InventoryExtraData[1]);\n\t\treturn GF_START_SAVEDGAME | InventoryExtraData[1]; // saveGame slot\n\t}\n\n\tif( InventoryExtraData[0] == 1 ) { // passport page (New game | Restart Level)\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( InventoryMode == INV_DeathMode ) {\n\t\t\t// check if previous level is not Assault and not a final one (before bonus level)\n\t\t\tif( CurrentLevel > 1 && !GF_IsFinalLevel(CurrentLevel-1) ) {\n\t\t\t\tSaveGame.start[CurrentLevel] = SaveGame.start[CurrentLevel-1];\n\t\t\t} else {\n\t\t\t\tModifyStartInfo(CurrentLevel);\n\t\t\t}\n\t\t\treturn GF_START_GAME | CurrentLevel;\n\t\t}\n#endif // FEATURE_HUD_IMPROVED\n\t\tif( (GF_GameFlow.flags & GFF_SelectAnyLevel) != 0 )\n\t\t\treturn GF_START_GAME | (InventoryExtraData[1] + 1); // selected level\n\t\telse\n\t\t\treturn GF_START_GAME | 1; // first level\n\t}\n\treturn GF_EXIT_TO_TITLE;\n}\n\nint __cdecl GameLoop(BOOL demoMode) {\n\tint result;\n\tint nTicks;\n\n\tOverlayStatus = 1;\n\tInitialiseCamera();\n\tNoInputCounter = 0;\n\n\tresult = ControlPhase(1, demoMode);\n\twhile( result == 0 ) {\n\t\tnTicks = DrawPhaseGame();\n\t\tresult = IsGameToExit ? GF_EXIT_GAME : ControlPhase(nTicks, demoMode);\n\t}\n\n\tS_SoundStopAllSamples();\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t// this fixes issue when the final \"bath\" cut scene is cut off\n\tif( Lara.extra_anim && LaraItem->currentAnimState == EXTRA_FINALANIM ) {\n\t\tS_CopyScreenToBuffer();\n\t\tBGND2_ShowPicture(0, 0, 20, 70, FALSE);\n\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tS_CDStop();\n\tif( MusicVolume > 0 ) {\n\t\tS_CDVolume(MusicVolume * 25 + 5);\n\t}\n\treturn result;\n}\n\nint __cdecl LevelCompleteSequence() {\n\treturn GF_EXIT_TO_TITLE;\n}\n\nint __cdecl LevelStats(int levelID) {\n\tint hours, minutes, seconds;\n\tchar timeString[100] = {0};\n\n\tCreateStartInfo(levelID); // NOTE: this line is absent in the original code, but it's required for \"Restart Level\" feature\n\tSaveGame.start[levelID].statistics = SaveGame.statistics;\n\n\tseconds = SaveGame.statistics.timer / 30 % 60;\n\tminutes = SaveGame.statistics.timer / 30 / 60 % 60;\n\thours   = SaveGame.statistics.timer / 30 / 60 / 60;\n\tsprintf(timeString, \"%02d:%02d:%02d\", hours, minutes, seconds);\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tTempVideoAdjust(HiRes, 1.0);\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\tS_CopyScreenToBuffer();\n\t\tRGB888 gamePal[256];\n\t\tmemcpy(gamePal, GamePalette8, sizeof(gamePal));\n\t\tfor( int i = 0; i<256; ++i ) {\n\t\t\tGamePalette8[i] = gamePal[DepthQIndex[i]];\n\t\t}\n\t\tFadeToPal(10, GamePalette8);\n\t\tmemcpy(GamePalette8, gamePal, sizeof(gamePal));\n\t\tFadeToPal(0, GamePalette8);\n\t} else if( !StatsBackgroundMode ) {\n\t\tS_CopyScreenToBuffer();\n\t\twhile( !IsGameToExit && BGND2_FadeTo(128, 0) > 128 ) {\n\t\t\tS_InitialisePolyList(FALSE);\n\t\t\tS_CopyBufferToScreen();\n\t\t\tif( S_UpdateInput() || IsResetFlag ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tS_OutputPolyList();\n\t\t\tS_DumpScreen();\n\t\t}\n\t} else {\n\t\tS_FadeToBlack();\n\t}\n\tT_InitPrint();\n\n\tS_CDPlay(GF_GameFlow.levelCompleteTrack, FALSE);\n#else // // FEATURE_BACKGROUND_IMPROVED\n\tS_CDPlay(GF_GameFlow.levelCompleteTrack, FALSE);\n\n\tTempVideoAdjust(HiRes, 1.0);\n\tFadeToPal(30, GamePalette8);\n\tT_InitPrint();\n\tS_CopyScreenToBuffer();\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\twhile( CHK_ANY(InputStatus, IN_SELECT) )\n\t\tS_UpdateInput();\n\n#ifdef FEATURE_HUD_IMPROVED\n\tDisplayJoystickHintText(false, true, false);\n#endif // FEATURE_HUD_IMPROVED\n\twhile( !CHK_ANY(InputStatus, IN_SELECT) ) {\n\t\tS_InitialisePolyList(FALSE);\n\t\tS_CopyBufferToScreen();\n\t\tS_UpdateInput();\n\t\t// NOTE: this check is absent in the original game\n\t\tif( IsGameToExit ) {\n\t\t\tbreak;\n\t\t}\n\t\tif( IsResetFlag ) {\n\t\t\tInputStatus = IN_SELECT;\n\t\t}\n\t\tInputDB = GetDebouncedInput(InputStatus);\n\t\tShowStatsText(timeString, FALSE);\n\t\tT_DrawText();\n\t\tS_OutputPolyList();\n\t\tS_DumpScreen();\n\t}\n#ifdef FEATURE_HUD_IMPROVED\n\tRemoveJoystickHintText(false, true, false);\n#endif // FEATURE_HUD_IMPROVED\n\n\t// NOTE: This LevelStats bonusFlag activation is not presented in the original game.\n\t// If the level is final, but there no GFE_GAMECOMPLETE in the script, just activate Game+ here.\n\tif( levelID == GF_GameFlow.num_Levels-GF_GameFlow.num_Demos-1 ) {\n\t\tSaveGame.bonusFlag = true;\n\t}\n\n\t++levelID;\n\tCreateStartInfo(levelID);\n\tSaveGame.currentLevel = levelID;\n\tSaveGame.start[CurrentLevel].available = 0; // make level not available\n\tS_FadeToBlack();\n\tTempVideoRemove();\n\treturn 0;\n}\n\nint __cdecl GameStats(int levelID) {\n\tSaveGame.start[CurrentLevel].statistics = SaveGame.statistics;\n\n\tTempVideoAdjust(HiRes, 1.0); // NOTE: this line was not in the original code\n\tT_InitPrint();\n\n\twhile( CHK_ANY(InputStatus, IN_SELECT) )\n\t\tS_UpdateInput();\n\n#ifdef FEATURE_HUD_IMPROVED\n\tDisplayJoystickHintText(false, true, false);\n#endif // FEATURE_HUD_IMPROVED\n\twhile( !CHK_ANY(InputStatus, IN_SELECT) ) {\n\t\tS_InitialisePolyList(FALSE);\n\t\tS_CopyBufferToScreen();\n\t\tS_UpdateInput();\n\t\t// NOTE: this check is absent in the original game\n\t\tif( IsGameToExit ) {\n\t\t\tbreak;\n\t\t}\n\t\tif( IsResetFlag ) {\n\t\t\tInputStatus = IN_SELECT;\n\t\t}\n\t\tInputDB = GetDebouncedInput(InputStatus);\n\t\tShowEndStatsText();\n\t\tT_DrawText();\n\t\tS_OutputPolyList();\n\t\tS_DumpScreen();\n\t}\n#ifdef FEATURE_HUD_IMPROVED\n\tRemoveJoystickHintText(false, true, false);\n#endif // FEATURE_HUD_IMPROVED\n\n\t// NOTE: in the original game, there is slightly different bonusFlag activation.\n\t// Here removed bonuses initialization, and added the check that the level is final\n\tif( CurrentLevel == GF_GameFlow.num_Levels-GF_GameFlow.num_Demos-1 ) {\n\t\tSaveGame.bonusFlag = true;\n\t}\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tBGND2_ShowPicture(0, 0, 10, 2, FALSE);\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tS_DontDisplayPicture();\n\tTempVideoRemove(); // NOTE: this line was not in the original code\n\treturn 0;\n}\n\nint __cdecl GetRandomControl() {\n\tRandomControl = RandomControl * 1103515245 + 12345;\n\treturn (RandomControl >> 10) & 0x7FFF;\n\t// NOTE: the shift value should be 0x10, but the original game has 10,\n\t// it left \"as is\" to save consistency with the original game.\n}\n\nvoid __cdecl SeedRandomControl(int seed) {\n\tRandomControl = seed;\n}\n\nint __cdecl GetRandomDraw() {\n\tRandomDraw = RandomDraw * 1103515245 + 12345;\n\treturn (RandomDraw >> 10) & 0x7FFF;\n\t// NOTE: the shift value should be 0x10, but the original game has 10,\n\t// it left \"as is\" to save consistency with the original game.\n}\n\nvoid __cdecl SeedRandomDraw(int seed) {\n\tRandomDraw = seed;\n}\n\nvoid __cdecl GetValidLevelsList(REQUEST_INFO *req) {\n\tRemoveAllReqItems(req);\n\n\t// NOTE: this check fixes original game bug.\n\t// Now demo levels are excluded from the *\"New Game\"* menu,\n\t// if the *\"Select Level\"* option is active.\n\tDWORD numLevels = GF_GameFlow.num_Levels - GF_GameFlow.num_Demos;\n\n\tfor( DWORD i = 1; i < numLevels; ++i )\n\t\tAddRequesterItem(req, GF_LevelNamesStringTable[i], 0, NULL, 0);\n}\n\nvoid __cdecl GetSavedGamesList(REQUEST_INFO *req) {\n\textern void SetPassportRequesterSize(REQUEST_INFO *req);\n\tSetPassportRequesterSize(req);\n\n\tif( req->selected >= req->visibleCount ) {\n\t\treq->lineOffset = req->selected - req->visibleCount + 1;\n\t}\n\tmemcpy(RequesterItemFlags1, SaveGameItemFlags1, sizeof(RequesterItemFlags1));\n\tmemcpy(RequesterItemFlags2, SaveGameItemFlags2, sizeof(RequesterItemFlags2));\n}\n\nvoid __cdecl DisplayCredits() {\n\tint i;\n\tRGB888 palette[256];\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tchar fileName[64] = {0};\n#else // !FEATURE_BACKGROUND_IMPROVED\n\tDWORD bytesRead;\n\tHANDLE hFile;\n#ifdef FEATURE_GOLD\n\tDWORD fileSize[10];\n\tBYTE *fileData[10];\n#else // !FEATURE_GOLD\n\tDWORD fileSize[9];\n\tBYTE *fileData[9];\n#endif // !FEATURE_GOLD\n\tDWORD bitmapSize;\n\tBYTE *bitmapData;\n\tLPCSTR fullPath;\n\tchar fileName[64] = \"data\\\\credit0?.pcx\";\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\tS_FadeToBlack(); // fade out 12 frames / 0.4 seconds\n\tS_UnloadLevelFile();\n\tTempVideoAdjust(HiRes, 1.0); // NOTE: this line was not in the original code\n\n\tif( !InitialiseLevel(0, 0) ) // init title level\n\t\treturn;\n\n\tmemcpy(palette, GamePalette8, sizeof(GamePalette8));\n\tmemset(GamePalette8, 0, sizeof(GamePalette8));\n\n\tIsVidModeLock = true;\n\tFadeToPal(0, GamePalette8); // fade in instantly\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tS_CDPlay(52, FALSE);\n\n\t// slideshow loop\n#ifdef FEATURE_GOLD\n\tfor( i=IsGold()?0:1; i<100; ++i ) {\n#else // !FEATURE_GOLD\n\tfor( i=1; i<100; ++i ) {\n#endif // !FEATURE_GOLD\n\t\tsnprintf(fileName, sizeof(fileName), \"data\\\\credit%02d.pcx\", i);\n\t\tif( !BGND2_LoadPicture(fileName, FALSE, FALSE) ) {\n\t\t\tBGND2_ShowPicture(30, 225, 10, 2, FALSE);\n\t\t}\n\t\tS_DontDisplayPicture();\n\n\t\tif( IsGameToExit ) {\n\t\t\treturn;\n\t\t}\n\t}\n\tmemcpy(GamePalette8, palette, sizeof(GamePalette8));\n\t// NOTE: background for final statistics (picture is presented but not used in the original game)\n\tif( !BGND2_LoadPicture(\"data\\\\end.pcx\", TRUE, FALSE) ) {\n\t\tBGND2_ShowPicture(30, 0, 0, 0, FALSE);\n\t}\n\tIsVidModeLock = false;\n\tTempVideoRemove();\n\n#else // !FEATURE_BACKGROUND_IMPROVED\n\t// credit files load loop (preload all files may be reasonable because of CDAudio issues, since PCX are on CD too)\n#ifdef FEATURE_GOLD\n\tfor( i=0; i<(IsGold()?10:9); ++i ) {\n\t\tfileName[12] = '0'+i+(IsGold()?0:1);\n#else // !FEATURE_GOLD\n\tfor( i=0; i<9; ++i ) {\n\t\tfileName[12] = '0'+i+1;\n#endif // !FEATURE_GOLD\n\t\tfullPath = GetFullPath(fileName);\n\t\thFile = CreateFile(fullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\t\tif( hFile != INVALID_HANDLE_VALUE ) {\n\t\t\tfileSize[i] = GetFileSize(hFile, 0);\n\t\t\tfileData[i] = (BYTE *)game_malloc(fileSize[i], GBUF_LoadPiccyBuffer);\n\t\t\tReadFile(hFile, fileData[i], fileSize[i], &bytesRead, 0);\n\t\t\tCloseHandle(hFile);\n\t\t}\n\t}\n\n\tbitmapSize = 640*480;\n\tbitmapData = (BYTE *)game_malloc(bitmapSize, GBUF_LoadPiccyBuffer);\n\tS_CDPlay(52, FALSE);\n\n\t// slideshow loop\n#ifdef FEATURE_GOLD\n\tfor( i=0; i<(IsGold()?10:9); ++i ) {\n#else // !FEATURE_GOLD\n\tfor( i=0; i<9; ++i ) {\n#endif // !FEATURE_GOLD\n\t\tDecompPCX(fileData[i], fileSize[i], bitmapData, PicPalette);\n\n\t\tif( SavedAppSettings.RenderMode == RM_Software ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\tif( PictureBuffer.bitmap != NULL)\n\t\t\t\tmemcpy(PictureBuffer.bitmap, bitmapData, PictureBuffer.width * PictureBuffer.height);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\t\tWinVidCopyBitmapToBuffer(PictureBufferSurface, bitmapData);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t} else {\n\t\t\tBGND_Make640x480(bitmapData, PicPalette);\n\t\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tmemcpy(GamePalette8, PicPalette, sizeof(GamePalette8));\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tCopyBitmapPalette(PicPalette, bitmapData, bitmapSize, GamePalette8);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tS_InitialisePolyList(FALSE);\n\t\tS_CopyBufferToScreen();\n\t\tS_OutputPolyList();\n\t\tS_DumpScreen();\n\n\t\tFadeToPal(30, GamePalette8); // fade in 30 frames / 1.0 seconds (software renderer only)\n\t\tS_Wait(225 * TICKS_PER_FRAME, FALSE); // wait 225 frames / 7.5 seconds (disable keyboard)\n\t\tS_FadeToBlack(); // fade out 12 frames / 0.4 seconds (software renderer only)\n\t\tS_DontDisplayPicture();\n\n\t\tif( IsGameToExit )\n\t\t\tbreak;\n\t}\n\n\tmemcpy(GamePalette8, palette, sizeof(GamePalette8));\n\tS_Wait(150 * TICKS_PER_FRAME, FALSE); // wait 150 frames / 5 seconds (disable keyboard)\n\tFadeToPal(30, GamePalette8); // fade in 30 frames / 1.0 seconds (software renderer only)\n\tIsVidModeLock = false;\n\tTempVideoRemove(); // NOTE: this line was not in the original code\n\n\t// NOTE: here is no game_free for game_malloc. Memory will be free in S_DisplayPicture by init_game_malloc call\n#endif // FEATURE_BACKGROUND_IMPROVED\n}\n\nBOOL __cdecl S_FrontEndCheck() {\n\tHANDLE hFile;\n\tDWORD bytesRead;\n\tDWORD saveCounter;\n\tchar levelName[80] = {0};\n\tchar saveCountStr[16] = {0};\n#ifdef FEATURE_SUBFOLDERS\n\tchar fileName[256] = {0};\n#else // !FEATURE_SUBFOLDERS\n\tchar fileName[16] = {0};\n#endif // !FEATURE_SUBFOLDERS\n\n\tInit_Requester(&LoadGameRequester);\n\tSavedGamesCount = 0;\n\n\tfor( DWORD i=0; i<SavegameSlots; ++i ) {\n#ifdef FEATURE_SUBFOLDERS\n\t\tGetSaveFileName(fileName, sizeof(fileName), i);\n#else // !FEATURE_SUBFOLDERS\n\t\twsprintf(fileName, \"savegame.%d\", i);\n#endif // !FEATURE_SUBFOLDERS\n\t\thFile = CreateFile(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\n\t\tif( hFile == INVALID_HANDLE_VALUE ) {\n\t\t\tAddRequesterItem(&LoadGameRequester, GF_SpecificStringTable[SSI_EmptySlot], 0, NULL, 0);\n\t\t\tSaveSlotFlags[i] = 0;\n\t\t\tcontinue;\n\t\t}\n\n\t\tReadFile(hFile, levelName, 75, &bytesRead, NULL);\n\t\tReadFile(hFile, &saveCounter, sizeof(DWORD), &bytesRead, NULL);\n\t\tCloseHandle(hFile);\n\n\t\twsprintf(saveCountStr, \"%d\", saveCounter);\n\t\tAddRequesterItem(&LoadGameRequester, levelName, REQFLAG_LEFT, saveCountStr, REQFLAG_RIGHT);\n\n\t\tif( saveCounter > SaveCounter ) {\n\t\t\tSaveCounter = saveCounter;\n\t\t\tLoadGameRequester.selected = i;\n\t\t}\n\n\t\tSaveSlotFlags[i] = 1;\n\t\t++SavedGamesCount;\n\t}\n\tmemcpy(SaveGameItemFlags1, RequesterItemFlags1, sizeof(SaveGameItemFlags1));\n\tmemcpy(SaveGameItemFlags2, RequesterItemFlags2, sizeof(SaveGameItemFlags2));\n\n\t++SaveCounter;\n\treturn 1;\n}\n\nBOOL __cdecl S_SaveGame(LPCVOID saveData, DWORD saveSize, int slotNumber) {\n\tHANDLE hFile;\n\tDWORD bytesWritten;\n\tchar levelName[80] = {0};\n\tchar saveCountStr[16] = {0};\n\n#ifdef FEATURE_SUBFOLDERS\n\tchar fileName[256] = {0};\n\tGetSaveFileName(fileName, sizeof(fileName), slotNumber);\n\tif( CreateDirectories(fileName, true) ) {\n\t\treturn FALSE;\n\t}\n#else // !FEATURE_SUBFOLDERS\n\tchar fileName[16] = {0};\n\twsprintf(fileName, \"savegame.%d\", slotNumber);\n#endif // !FEATURE_SUBFOLDERS\n\n\thFile = CreateFile(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile == INVALID_HANDLE_VALUE )\n\t\treturn FALSE;\n\n\twsprintf(levelName, \"%s\", GF_LevelNamesStringTable[SaveGame.currentLevel]);\n\tWriteFile(hFile, levelName, 75, &bytesWritten, NULL);\n\tWriteFile(hFile, &SaveCounter, sizeof(DWORD), &bytesWritten, NULL);\n\tWriteFile(hFile, saveData, saveSize, &bytesWritten, NULL);\n\tCloseHandle(hFile);\n\n\twsprintf(saveCountStr, \"%d\", SaveCounter);\n\tChangeRequesterItem(&LoadGameRequester, slotNumber, levelName, REQFLAG_LEFT, saveCountStr, REQFLAG_RIGHT);\n\t// NOTE: the next two lines fix a bug in the original game:\n\t// When player saves the game to EMPTY SLOT, save counter won't appear until the game relaunch\n\tSaveGameItemFlags1[slotNumber] = RequesterItemFlags1[slotNumber];\n\tSaveGameItemFlags2[slotNumber] = RequesterItemFlags2[slotNumber];\n\t++SaveCounter;\n\n\t// NOTE: There was no such check in the original code. Save files counter incremented anyway\n\tif( SaveSlotFlags[slotNumber] == 0 ) {\n\t\tSaveSlotFlags[slotNumber] = 1;\n\t\t++SavedGamesCount;\n\t}\n\n\treturn TRUE;\n}\n\nBOOL __cdecl S_LoadGame(LPVOID saveData, DWORD saveSize, int slotNumber) {\n\tHANDLE hFile;\n\tDWORD bytesRead;\n\tDWORD saveCounter;\n\tchar levelName[80] = {0};\n\n#ifdef FEATURE_SUBFOLDERS\n\tchar fileName[256] = {0};\n\tGetSaveFileName(fileName, sizeof(fileName), slotNumber);\n#else // !FEATURE_SUBFOLDERS\n\tchar fileName[16] = {0};\n\twsprintf(fileName, \"savegame.%d\", slotNumber);\n#endif // !FEATURE_SUBFOLDERS\n\n\thFile = CreateFile(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile == INVALID_HANDLE_VALUE )\n\t\treturn FALSE;\n\n\tReadFile(hFile, levelName, 75, &bytesRead, NULL);\n\tReadFile(hFile, &saveCounter, sizeof(DWORD), &bytesRead, NULL);\n\tReadFile(hFile, saveData, saveSize, &bytesRead, NULL);\n\tCloseHandle(hFile);\n\treturn TRUE;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Game() {\n\tINJECT(0x0044C550, StartGame);\n\tINJECT(0x0044C6A0, GameLoop);\n\tINJECT(0x0044C740, LevelCompleteSequence);\n\tINJECT(0x0044C750, LevelStats);\n\tINJECT(0x0044C920, GameStats);\n\tINJECT(0x0044CA40, GetRandomControl);\n\tINJECT(0x0044CA60, SeedRandomControl);\n\tINJECT(0x0044CA70, GetRandomDraw);\n\tINJECT(0x0044CA90, SeedRandomDraw);\n\tINJECT(0x0044CAA0, GetValidLevelsList);\n\tINJECT(0x0044CAF0, GetSavedGamesList);\n\tINJECT(0x0044CB40, DisplayCredits);\n\tINJECT(0x0044CD80, S_FrontEndCheck);\n\tINJECT(0x0044CEF0, S_SaveGame);\n\tINJECT(0x0044D010, S_LoadGame);\n}\n"
  },
  {
    "path": "specific/game.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef GAME_H_INCLUDED\n#define GAME_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n__int16 __cdecl StartGame(int levelID, GF_LEVEL_TYPE levelType); // 0x0044C550\nint __cdecl GameLoop(BOOL demoMode); // 0x0044C6A0\nint __cdecl LevelCompleteSequence(); // 0x0044C740\nint __cdecl LevelStats(int levelID); // 0x0044C750\nint __cdecl GameStats(int levelID); // 0x0044C920\nint __cdecl GetRandomControl(); // 0x0044CA40\nvoid __cdecl SeedRandomControl(int seed); // 0x0044CA60\nint __cdecl GetRandomDraw(); // 0x0044CA70\nvoid __cdecl SeedRandomDraw(int seed); // 0x0044CA90\nvoid __cdecl GetValidLevelsList(REQUEST_INFO *req); // 0x0044CAA0\nvoid __cdecl GetSavedGamesList(REQUEST_INFO *req); // 0x0044CAF0\nvoid __cdecl DisplayCredits(); // 0x0044CB40\nBOOL __cdecl S_FrontEndCheck(); // 0x0044CD80\nBOOL __cdecl S_SaveGame(LPCVOID saveData, DWORD saveSize, int slotNumber); // 0x0044CEF0\nBOOL __cdecl S_LoadGame(LPVOID saveData, DWORD saveSize, int saveNumber); // 0x0044D010\n\n#endif // GAME_H_INCLUDED\n"
  },
  {
    "path": "specific/hwr.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/hwr.h\"\n#include \"specific/init_display.h\"\n#include \"specific/texture.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_HUD_IMPROVED\n#include \"modding/psx_bar.h\"\n#endif // FEATURE_HUD_IMPROVED\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nDWORD AlphaBlendMode = 2;\n\ntypedef struct {\n\tD3DBLEND src;\n\tD3DBLEND dst;\n\tBYTE alpha;\n} BLEND_PARAM;\n\nstatic BLEND_PARAM Blend[4] = {\n\t{D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, 128},\n\t{D3DBLEND_ONE, D3DBLEND_ONE, 255},\n\t{D3DBLEND_ZERO, D3DBLEND_INVSRCCOLOR, 255},\n\t{D3DBLEND_INVSRCALPHA, D3DBLEND_ONE, 192},\n};\n\nstatic void SetBlendMode(D3DTLVERTEX *vtxPtr, DWORD vtxCount, DWORD mode) {\n\tif( !vtxPtr || !vtxCount || mode >= 4 ) return;\n\tfor( DWORD i = 0; i < vtxCount; ++i ) {\n\t\tvtxPtr[i].color = RGBA_SETALPHA(vtxPtr[i].color, Blend[mode].alpha);\n\t}\n#if (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRS_SRCBLEND, Blend[mode].src);\n\tD3DDev->SetRenderState(D3DRS_DESTBLEND, Blend[mode].dst);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRENDERSTATE_SRCBLEND, Blend[mode].src);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_DESTBLEND, Blend[mode].dst);\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nstatic void DrawAlphaBlended(D3DTLVERTEX *vtxPtr, DWORD vtxCount, DWORD mode) {\n\t// do basic blending\n\tSetBlendMode(vtxPtr, vtxCount, mode);\n\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtxPtr, vtxCount, true);\n\t// do advanced blending\n\tif( AlphaBlendMode == 2 && mode == 0 ) {\n\t\tSetBlendMode(vtxPtr, vtxCount, 3); // additional quarter-additive blending pass\n\t\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtxPtr, vtxCount, true);\n\t}\n\t// return render states to default values\n#if (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);\n\tD3DDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n// NOTE: this function is absent in the original code\nHRESULT HWR_DrawPrimitive(D3DPRIMITIVETYPE primitiveType, LPVOID vertices, DWORD vertexCount, bool isNoClip) {\n#if (DIRECT3D_VERSION >= 0x900)\n\textern LPDIRECT3DVERTEXBUFFER9 D3DVtx;\n\tint primitiveCount = 0;\n\tswitch( primitiveType ) {\n\t\tcase D3DPT_POINTLIST:\t\tprimitiveCount = vertexCount;   break;\n\t\tcase D3DPT_LINELIST:\t\tprimitiveCount = vertexCount/2; break;\n\t\tcase D3DPT_LINESTRIP:\t\tprimitiveCount = vertexCount-1; break;\n\t\tcase D3DPT_TRIANGLELIST:\tprimitiveCount = vertexCount/3; break;\n\t\tcase D3DPT_TRIANGLESTRIP:\tprimitiveCount = vertexCount-2; break;\n\t\tcase D3DPT_TRIANGLEFAN:\t\tprimitiveCount = vertexCount-2; break;\n\t\tdefault: break;\n\t}\n\tif( primitiveCount <= 0 ) {\n\t\treturn D3DERR_INVALIDCALL;\n\t}\n\tstatic DWORD vertexIndex = 0;\n\tDWORD flags = D3DLOCK_NOOVERWRITE;\n\tif( vertexIndex + vertexCount > VTXBUF_LEN ) {\n\t\tvertexIndex = 0;\n\t\tflags = D3DLOCK_DISCARD;\n\t}\n\tLPVOID ptr = NULL;\n\tHRESULT res = D3DVtx->Lock(sizeof(D3DTLVERTEX) * vertexIndex, sizeof(D3DTLVERTEX) * vertexCount, &ptr, flags);\n\tif FAILED(res) return res;\n\tmemcpy(ptr, vertices, sizeof(D3DTLVERTEX) * vertexCount);\n\tD3DVtx->Unlock();\n\tres = D3DDev->DrawPrimitive(primitiveType, vertexIndex, primitiveCount);\n\tvertexIndex += vertexCount;\n\treturn res;\n#else // (DIRECT3D_VERSION >= 0x900)\n\treturn D3DDev->DrawPrimitive(primitiveType, D3DVT_TLVERTEX, vertices, vertexCount, isNoClip ? D3DDP_DONOTUPDATEEXTENTS|D3DDP_DONOTCLIP : 0);\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl HWR_InitState() {\n#if (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRS_CLIPPING, FALSE);\n\tD3DDev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);\n\tD3DDev->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);\n\tD3DDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);\n\tD3DDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);\n\tD3DDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);\n\n\tD3DDev->SetRenderState(D3DRS_DITHERENABLE, SavedAppSettings.Dither ? TRUE : FALSE);\n\tAlphaBlendEnabler = D3DRS_ALPHABLENDENABLE;\n\n#if defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetTextureStageState(0, D3DTSS_COLOROP, SavedAppSettings.LightingMode ? D3DTOP_MODULATE2X : D3DTOP_MODULATE);\n#else // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);\n#endif // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);\n\tD3DDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);\n\tD3DDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);\n\tD3DDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);\n\tD3DDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);\n\n\tDWORD filter = SavedAppSettings.BilinearFiltering ? D3DTEXF_LINEAR : D3DTEXF_POINT;\n\tD3DDev->SetSamplerState(0, D3DSAMP_MAGFILTER, filter);\n\tD3DDev->SetSamplerState(0, D3DSAMP_MINFILTER, filter);\n\tD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);\n\tD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);\n\n\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, SavedAppSettings.PerspectiveCorrect ? TRUE : FALSE);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_DITHERENABLE, SavedAppSettings.Dither ? TRUE : FALSE);\n\tAlphaBlendEnabler = CurrentDisplayAdapter.shadeRestricted ? D3DRENDERSTATE_STIPPLEDALPHA : D3DRENDERSTATE_ALPHABLENDENABLE;\n\n\tDWORD filter = SavedAppSettings.BilinearFiltering ? D3DFILTER_LINEAR : D3DFILTER_NEAREST;\n\tDWORD blend = (CurrentDisplayAdapter.D3DHWDeviceDesc.dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATEALPHA) ? D3DTBLEND_MODULATEALPHA : D3DTBLEND_MODULATE;\n\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREMAG, filter);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREMIN, filter);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, blend);\n\t// NOTE: the next line is absent in the original game, but it fixes a texture bleeding in some cases\n\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREADDRESS, D3DTADDRESS_CLAMP);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tHWR_ResetTexSource();\n\tHWR_ResetColorKey();\n\tHWR_ResetZBuffer();\n}\n\nvoid __cdecl HWR_ResetTexSource() {\n\tCurrentTexSource = 0;\n#if (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetTexture(0, NULL);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE, 0);\n\tD3DDev->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl HWR_ResetColorKey() {\n\tColorKeyState = FALSE;\n#if (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(TexturesAlphaChannel ? D3DRENDERSTATE_ALPHABLENDENABLE : D3DRENDERSTATE_COLORKEYENABLE, FALSE);\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl HWR_ResetZBuffer() {\n\tZEnableState = FALSE;\n\tZWriteEnableState = FALSE;\n#if (DIRECT3D_VERSION >= 0x900)\n\tD3DDev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);\n\tD3DDev->SetRenderState(D3DRS_ZWRITEENABLE, D3DZB_FALSE);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( ZBufferSurface != NULL ) {\n\t\tD3DDev->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS);\n\t\tD3DDev->SetRenderState(D3DRENDERSTATE_ZENABLE, SavedAppSettings.ZBuffer ? TRUE : FALSE);\n\t} else {\n\t\tD3DDev->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);\n\t\tD3DDev->SetRenderState(D3DRENDERSTATE_ZENABLE, FALSE);\n\t}\n\tD3DDev->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE);\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl HWR_TexSource(HWR_TEXHANDLE texSource) {\n\tif( CurrentTexSource != texSource ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetTexture(0, texSource);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE, texSource);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tCurrentTexSource = texSource;\n\t}\n}\n\nvoid __cdecl HWR_EnableColorKey(bool state) {\n\tif( ColorKeyState != state ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetRenderState(D3DRS_ALPHABLENDENABLE, state ? TRUE : FALSE);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetRenderState(TexturesAlphaChannel ? D3DRENDERSTATE_ALPHABLENDENABLE : D3DRENDERSTATE_COLORKEYENABLE, state ? TRUE : FALSE);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tColorKeyState = state;\n\t}\n}\n\nvoid __cdecl HWR_EnableZBuffer(bool ZWriteEnable, bool ZEnable) {\n\tif( !SavedAppSettings.ZBuffer )\n\t\treturn;\n\n\tif( ZWriteEnableState != ZWriteEnable ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetRenderState(D3DRS_ZWRITEENABLE, ZWriteEnable ? D3DZB_TRUE : D3DZB_FALSE);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, ZWriteEnable ? TRUE : FALSE);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tZWriteEnableState = ZWriteEnable;\n\t}\n\n\tif( ZEnableState != ZEnable ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tD3DDev->SetRenderState(D3DRS_ZENABLE, ZEnable ? D3DZB_TRUE : D3DZB_FALSE);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tif( ZBufferSurface != NULL )\n\t\t\tD3DDev->SetRenderState(D3DRENDERSTATE_ZFUNC, ZEnable ? D3DCMP_LESSEQUAL : D3DCMP_ALWAYS);\n\t\telse\n\t\t\tD3DDev->SetRenderState(D3DRENDERSTATE_ZENABLE, ZEnable ? TRUE : FALSE);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tZEnableState = ZEnable;\n\t}\n}\n\nvoid __cdecl HWR_BeginScene() {\n\tHWR_GetPageHandles();\n#if (DIRECT3D_VERSION < 0x900)\n\tWaitPrimaryBufferFlip();\n#endif // (DIRECT3D_VERSION < 0x900)\n\tD3DDev->BeginScene();\n}\n\nvoid __cdecl HWR_DrawPolyList() {\n\tDWORD alphaState;\n\tUINT16 *bufPtr;\n\tUINT16 polyType, texPage, vtxCount;\n\tD3DTLVERTEX *vtxPtr;\n\n\tHWR_EnableZBuffer(false, true);\n\tfor( DWORD i=0; i<SurfaceCount; ++i ) {\n\t\tbufPtr = (UINT16 *)SortBuffer[i]._0;\n\n\t\tpolyType = *(bufPtr++);\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( polyType == POLY_HWR_healthbar || polyType == POLY_HWR_airbar ) {\n\t\t\tUINT16 x0 = *(bufPtr++);\n\t\t\tUINT16 y0 = *(bufPtr++);\n\t\t\tUINT16 x1 = *(bufPtr++);\n\t\t\tUINT16 y1 = *(bufPtr++);\n\t\t\tUINT16 bar = *(bufPtr++);\n\t\t\tUINT16 pixel = *(bufPtr++);\n\t\t\tUINT16 alpha = *(bufPtr++);\n\t\t\tif( polyType == POLY_HWR_healthbar ) {\n\t\t\t\tPSX_DrawHealthBar(x0, y0, x1, y1, bar, pixel, alpha);\n\t\t\t} else {\n\t\t\t\tPSX_DrawAirBar(x0, y0, x1, y1, bar, pixel, alpha);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n#endif // FEATURE_HUD_IMPROVED\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tswitch( polyType ) {\n\t\t\tcase POLY_HWR_GTmap:\n\t\t\tcase POLY_HWR_WGTmap:\n\t\t\tcase POLY_HWR_WGTmapHalf:\n\t\t\tcase POLY_HWR_WGTmapAdd:\n\t\t\tcase POLY_HWR_WGTmapSub:\n\t\t\tcase POLY_HWR_WGTmapQrt:\n\t\t\t\ttexPage = *(bufPtr++);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\ttexPage = 0;\n\t\t\t\tbreak;\n\t\t}\n#else // !FEATURE_VIDEOFX_IMPROVED\n\t\ttexPage = ( polyType == POLY_HWR_GTmap || polyType == POLY_HWR_WGTmap ) ? *(bufPtr++) : 0;\n#endif // !FEATURE_VIDEOFX_IMPROVED\n\t\tvtxCount = *(bufPtr++);\n\t\tvtxPtr = *(D3DTLVERTEX **)bufPtr;\n\n\t\tswitch( polyType ) {\n\t\t\tcase POLY_HWR_GTmap: // triangle fan (texture)\n\t\t\tcase POLY_HWR_WGTmap: // triangle fan (texture + colorkey)\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tcase POLY_HWR_WGTmapHalf: // triangle fan (texture + colorkey + PSX half blend)\n\t\t\tcase POLY_HWR_WGTmapAdd: // triangle fan (texture + colorkey + PSX additive blend)\n\t\t\tcase POLY_HWR_WGTmapSub: // triangle fan (texture + colorkey + PSX subtractive blend)\n\t\t\tcase POLY_HWR_WGTmapQrt: // triangle fan (texture + colorkey + PSX quarter blend)\n\t\t\t\tHWR_TexSource(texPage == (UINT16)~0 ? GetEnvmapTextureHandle() : HWR_PageHandles[texPage]);\n\t\t\t\tHWR_EnableColorKey(polyType != POLY_HWR_GTmap);\n\t\t\t\tif( TextureFormat.bpp < 16 || AlphaBlendMode == 0 || polyType == POLY_HWR_GTmap || polyType == POLY_HWR_WGTmap ) {\n\t\t\t\t\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtxPtr, vtxCount, true);\n\t\t\t\t} else {\n\t\t\t\t\tDrawAlphaBlended(vtxPtr, vtxCount, polyType-POLY_HWR_WGTmapHalf);\n\t\t\t\t}\n#else // !FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tHWR_TexSource(HWR_PageHandles[texPage]);\n\t\t\t\tHWR_EnableColorKey(polyType == POLY_HWR_WGTmap);\n\t\t\t\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtxPtr, vtxCount, true);\n#endif // !FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tbreak;\n\n\t\t\tcase POLY_HWR_gouraud: // triangle fan (color)\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t\tcase POLY_HWR_half: // triangle fan (color + PSX half blend)\n\t\t\tcase POLY_HWR_add: // triangle fan (color + PSX additive blend)\n\t\t\tcase POLY_HWR_sub: // triangle fan (color + PSX subtractive blend)\n\t\t\tcase POLY_HWR_qrt: // triangle fan (color + PSX quarter blend)\n\t\t\t\tHWR_TexSource(0);\n\t\t\t\tHWR_EnableColorKey(polyType != POLY_HWR_gouraud);\n\t\t\t\tif( TextureFormat.bpp < 16 || AlphaBlendMode == 0 || polyType == POLY_HWR_gouraud ) {\n\t\t\t\t\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtxPtr, vtxCount, true);\n\t\t\t\t} else {\n\t\t\t\t\tDrawAlphaBlended(vtxPtr, vtxCount, polyType-POLY_HWR_half);\n\t\t\t\t}\n#else // !FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tHWR_TexSource(0);\n\t\t\t\tHWR_EnableColorKey(false);\n\t\t\t\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtxPtr, vtxCount, true);\n#endif // !FEATURE_VIDEOFX_IMPROVED\n\t\t\t\tbreak;\n\n\t\t\tcase POLY_HWR_line: // line strip (color)\n\t\t\t\tHWR_TexSource(0);\n\t\t\t\tHWR_EnableColorKey(false);\n\t\t\t\tHWR_DrawPrimitive(D3DPT_LINESTRIP, vtxPtr, vtxCount, true);\n\t\t\t\tbreak;\n\n\t\t\tcase POLY_HWR_trans: // triangle fan (color + semitransparent)\n\t\t\t\tHWR_TexSource(0);\n\t\t\t\tD3DDev->GetRenderState(AlphaBlendEnabler, &alphaState);\n\t\t\t\tD3DDev->SetRenderState(AlphaBlendEnabler, TRUE);\n\t\t\t\tHWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtxPtr, vtxCount, true);\n\t\t\t\tD3DDev->SetRenderState(AlphaBlendEnabler, alphaState);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nvoid __cdecl HWR_LoadTexturePages(int pagesCount, LPVOID pagesBuffer, RGB888 *palette) {\n\tint pageIndex = -1;\n\tBYTE *bufferPtr = (BYTE *)pagesBuffer;\n\n\tHWR_FreeTexturePages();\n\n\tif( palette != NULL )\n\t\tPaletteIndex = CreateTexturePalette(palette);\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tchar levelName[256] = {0};\n\tchar texName[256] = {0};\n\tstrncpy(levelName, PathFindFileName(LevelFileName), sizeof(levelName)-1);\n\tchar *ext = PathFindExtension(levelName);\n\tif( ext != NULL ) *ext = 0;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tfor( int i=0; i<pagesCount; ++i ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tsnprintf(texName, sizeof(texName), \"./textures/texpages/%s_%d.png\", levelName, i);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tif( palette != NULL ) {\n\t\t\tpageIndex = AddTexturePage8(256, 256, bufferPtr, PaletteIndex);\n\t\t\tbufferPtr += 256*256*1;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t} else if( PathFileExists(texName) ) {\n\t\t\tpageIndex = AddExternalTexture(texName, true);\n\t\t\tbufferPtr += 256*256*2;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t} else {\n\t\t\tpageIndex = AddTexturePage16(256, 256, bufferPtr);\n\t\t\tbufferPtr += 256*256*2;\n\t\t}\n\t\tHWR_TexturePageIndexes[i] = (pageIndex < 0) ? -1 : pageIndex;\n\t}\n\tHWR_GetPageHandles();\n}\n\nvoid __cdecl HWR_FreeTexturePages() {\n\n\tfor( DWORD i=0; i<ARRAY_SIZE(HWR_TexturePageIndexes); ++i ) {\n\t\tif( HWR_TexturePageIndexes[i] >= 0 ) {\n\t\t\tSafeFreeTexturePage(HWR_TexturePageIndexes[i]);\n\t\t\tHWR_TexturePageIndexes[i] = -1;\n\t\t}\n\t\tHWR_PageHandles[i] = 0;\n\t}\n\tif( PaletteIndex >= 0 ) {\n\t\tSafeFreePalette(PaletteIndex);\n\t}\n}\n\nvoid __cdecl HWR_GetPageHandles() {\n\tfor( DWORD i=0; i<ARRAY_SIZE(HWR_TexturePageIndexes); ++i ) {\n\t\tif( HWR_TexturePageIndexes[i] < 0 )\n\t\t\tHWR_PageHandles[i] = 0;\n\t\telse\n\t\t\tHWR_PageHandles[i] = GetTexturePageHandle(HWR_TexturePageIndexes[i]);\n\t}\n}\n\nbool __cdecl HWR_VertexBufferFull() {\n\tDWORD index = ((DWORD)HWR_VertexPtr - (DWORD)HWR_VertexBuffer) / sizeof(D3DTLVERTEX);\n\treturn (index >= ARRAY_SIZE(HWR_VertexBuffer) - 0x200);\n}\n\nbool __cdecl HWR_Init() {\n\tmemset(HWR_VertexBuffer, 0, sizeof(HWR_VertexBuffer));\n\tmemset(HWR_TexturePageIndexes, 0xFF, sizeof(HWR_TexturePageIndexes)); // fill indexes by -1\n\treturn true;\n}\n\n/*\n * Inject function\n */\nvoid Inject_HWR() {\n\tINJECT(0x0044D0B0, HWR_InitState);\n\tINJECT(0x0044D1E0, HWR_ResetTexSource);\n\tINJECT(0x0044D210, HWR_ResetColorKey);\n\tINJECT(0x0044D240, HWR_ResetZBuffer);\n\tINJECT(0x0044D2A0, HWR_TexSource);\n\tINJECT(0x0044D2D0, HWR_EnableColorKey);\n\tINJECT(0x0044D320, HWR_EnableZBuffer);\n\tINJECT(0x0044D3B0, HWR_BeginScene);\n\tINJECT(0x0044D3E0, HWR_DrawPolyList);\n\tINJECT(0x0044D560, HWR_LoadTexturePages);\n\tINJECT(0x0044D5F0, HWR_FreeTexturePages);\n\tINJECT(0x0044D640, HWR_GetPageHandles);\n\tINJECT(0x0044D680, HWR_VertexBufferFull);\n\tINJECT(0x0044D6B0, HWR_Init);\n}\n"
  },
  {
    "path": "specific/hwr.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef HWR_H_INCLUDED\n#define HWR_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n// NOTE: this function is absent in the original code\nHRESULT HWR_DrawPrimitive(D3DPRIMITIVETYPE primitiveType, LPVOID vertices, DWORD vertexCount, bool isNoClip);\n\nvoid __cdecl HWR_InitState(); // 0x0044D0B0\nvoid __cdecl HWR_ResetTexSource(); // 0x0044D1E0\nvoid __cdecl HWR_ResetColorKey(); // 0x0044D210\nvoid __cdecl HWR_ResetZBuffer(); // 0x0044D240\nvoid __cdecl HWR_TexSource(HWR_TEXHANDLE texSource); // 0x0044D2A0\nvoid __cdecl HWR_EnableColorKey(bool state); // 0x0044D2D0\nvoid __cdecl HWR_EnableZBuffer(bool ZWriteEnable, bool ZEnable); // 0x0044D320\nvoid __cdecl HWR_BeginScene(); // 0x0044D3B0\nvoid __cdecl HWR_DrawPolyList(); // 0x0044D3E0\nvoid __cdecl HWR_LoadTexturePages(int pagesCount, LPVOID pagesBuffer, RGB888 *palette); // 0x0044D560\nvoid __cdecl HWR_FreeTexturePages(); // 0x0044D5F0\nvoid __cdecl HWR_GetPageHandles(); // 0x0044D640\nbool __cdecl HWR_VertexBufferFull(); // 0x0044D680\nbool __cdecl HWR_Init(); // 0x0044D6B0\n\n#endif // HWR_INCLUDED\n"
  },
  {
    "path": "specific/init.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/init.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"specific/game.h\"\n#include \"specific/winmain.h\"\n#include \"global/vars.h\"\n#include <time.h>\n\n// related to GAMEALLOC_BUFFER enum\nstatic LPCTSTR BufferNames[] = {\n\t\"Temp Alloc\",\n\t\"Texture Pages\",\n\t\"Mesh Pointers\",\n\t\"Meshes\",\n\t\"Anims\",\n\t\"Structs\",\n\t\"Ranges\",\n\t\"Commands\",\n\t\"Bones\",\n\t\"Frames\",\n\t\"Room Textures\",\n\t\"Room Infos\",\n\t\"Room Mesh\",\n\t\"Room Door\",\n\t\"Room Floor\",\n\t\"Room Lights\",\n\t\"Room Static Mesh Infos\",\n\t\"Floor Data\",\n\t\"ITEMS!!\",\n\t\"Cameras\",\n\t\"Sound FX\",\n\t\"Boxes\",\n\t\"Overlaps\",\n\t\"GroundZone\",\n\t\"FlyZone\",\n\t\"Animating Texture Ranges\",\n\t\"Cinematic Frames\",\n\t\"LoadDemo Buffer\",\n\t\"SaveDemo Buffer\",\n\t\"Cinematic Effects\",\n\t\"Mummy Head Turn\",\n\t\"Extra Door stuff\",\n\t\"Effects_Array\",\n\t\"Creature Data\",\n\t\"Creature LOT\",\n\t\"Sample Infos\",\n\t\"Samples\",\n\t\"Sample Offsets\",\n\t\"Rolling Ball Stuff\",\n\t\"Skidoo Stuff\",\n\t\"Load Piccy Buffer\",\n\t\"FMV Buffers\",\n\t\"Polygon Buffers\",\n\t\"Order Tables\",\n\t\"CLUTs\",\n\t\"Texture Infos\",\n\t\"Sprite Infos\",\n};\n\nBOOL __cdecl S_InitialiseSystem() {\n\tS_SeedRandom();\n\tDumpX = 0;\n\tDumpY = 0;\n\tDumpWidth = GameVidWidth;\n\tDumpHeight = GameVidHeight;\n\tCalculateWibbleTable();\n#ifdef FEATURE_EXTENDED_LIMITS\n\tGameMemorySize = 0x1000000; // 16 MB\n#else // FEATURE_EXTENDED_LIMITS\n\tGameMemorySize = 0x380000; // 3.5 MB\n#endif // FEATURE_EXTENDED_LIMITS\n\treturn TRUE;\n}\n\nvoid __cdecl ShutdownGame() {\n\tif( GameMemoryPointer != NULL ) {\n\t\tGlobalFree(GameMemoryPointer);\n\t\tGameMemoryPointer = NULL;\n\t}\n}\n\nvoid __cdecl init_game_malloc() {\n\tGameAllocMemPointer = GameMemoryPointer;\n\tGameAllocMemFree = GameMemorySize;\n\tGameAllocMemUsed = 0;\n}\n\nvoid *__cdecl game_malloc(DWORD allocSize, DWORD bufIndex) {\n\tDWORD alignedSize = (allocSize + 3) & ~3;\n\tif( alignedSize > GameAllocMemFree ) {\n\t\twsprintf(StringToShow, \"game_malloc(): OUT OF MEMORY %s %d\", BufferNames[bufIndex], alignedSize);\n\t\tS_ExitSystem(StringToShow);\n\t\treturn NULL; // the app is terminated here\n\t}\n\n\tvoid *result = GameAllocMemPointer;\n\tGameAllocMemFree -= alignedSize;\n\tGameAllocMemUsed += alignedSize;\n\tGameAllocMemPointer += alignedSize;\n\treturn result;\n}\n\nvoid __cdecl game_free(DWORD freeSize) {\n\tDWORD alignedSize = (freeSize + 3) & ~3;\n\n\tGameAllocMemPointer -= alignedSize;\n\tGameAllocMemFree += alignedSize;\n\tGameAllocMemUsed -= alignedSize;\n}\n\nvoid __cdecl CalculateWibbleTable() {\n\t// This function calculates water effect tables\n\tfor( int i=0; i < WIBBLE_SIZE; ++i ) {\n\t\tint sine = phd_sin(i * PHD_360 / WIBBLE_SIZE); // 360 degrees divided by wibble number\n\t\tWibbleTable[i] = sine * MAX_WIBBLE >> W2V_SHIFT;\n\t\tShadesTable[i] = sine * MAX_SHADE  >> W2V_SHIFT;\n\t\tRandomTable[i] = (GetRandomDraw() >> 5) - 0x01FF;\n\t\tfor( int j=0; j < WIBBLE_SIZE; ++j )\n\t\t\tRoomLightTables[i].table[j] = (j - (WIBBLE_SIZE/2)) * i * MAX_ROOMLIGHT_UNIT / (WIBBLE_SIZE-1);\n\t}\n}\n\nvoid __cdecl S_SeedRandom() {\n\ttime_t t = time(NULL);\n\tstruct tm *ltm = localtime(&t);\n\n\tSeedRandomControl(ltm->tm_sec + 57 * ltm->tm_min + 3543 * ltm->tm_hour);\n\tSeedRandomDraw(ltm->tm_sec + 43 * ltm->tm_min + 3477 * ltm->tm_hour);\n}\n\n/*\n * Inject function\n */\nvoid Inject_Init() {\n\tINJECT(0x0044D6E0, S_InitialiseSystem);\n\tINJECT(0x0044D730, ShutdownGame);\n\tINJECT(0x0044D750, init_game_malloc);\n\tINJECT(0x0044D780, game_malloc);\n\tINJECT(0x0044D800, game_free);\n\tINJECT(0x0044D840, CalculateWibbleTable);\n\tINJECT(0x0044D930, S_SeedRandom);\n}\n"
  },
  {
    "path": "specific/init.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef INIT_H_INCLUDED\n#define INIT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nBOOL __cdecl S_InitialiseSystem(); // 0x0044D6E0\nvoid __cdecl ShutdownGame(); // 0x0044D730\nvoid __cdecl init_game_malloc(); // 0x0044D750\nvoid *__cdecl game_malloc(DWORD allocSize, DWORD bufIndex); // 0x0044D780\nvoid __cdecl game_free(DWORD freeSize); // 0x0044D800\nvoid __cdecl CalculateWibbleTable(); // 0x0044D840\nvoid __cdecl S_SeedRandom(); // 0x0044D930\n\n#endif // INIT_H_INCLUDED\n"
  },
  {
    "path": "specific/init_3d.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/init_3d.h\"\n#include \"global/vars.h\"\n\n#if (DIRECT3D_VERSION >= 0x900)\nLPDIRECT3DVERTEXBUFFER9 D3DVtx = NULL;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl Enumerate3DDevices(DISPLAY_ADAPTER *adapter) {\n\tif( D3DCreate() ) {\n\t\tD3D->EnumDevices(Enum3DDevicesCallback, (LPVOID)adapter);\n\t\tD3DRelease();\n\t}\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nbool __cdecl D3DCreate() {\n#if (DIRECT3D_VERSION >= 0x900)\n\tD3D = Direct3DCreate9(D3D_SDK_VERSION);\n\treturn ( D3D != NULL );\n#else // (DIRECT3D_VERSION >= 0x900)\n\treturn SUCCEEDED(DDraw->QueryInterface(IID_IDirect3D2, (LPVOID *)&D3D));\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl D3DRelease() {\n\tif( D3D ) {\n\t\tD3D->Release();\n\t\tD3D = NULL;\n\t}\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nHRESULT CALLBACK Enum3DDevicesCallback(GUID FAR* lpGuid, LPTSTR lpDeviceDescription, LPTSTR lpDeviceName, LPD3DDEVICEDESC lpD3DHWDeviceDesc, LPD3DDEVICEDESC lpD3DHELDeviceDesc, LPVOID lpContext) {\n\tDISPLAY_ADAPTER *adapter = (DISPLAY_ADAPTER *)lpContext;\n\n\tif( lpD3DHWDeviceDesc && D3DIsSupported(lpD3DHWDeviceDesc) ) {\n\t\tadapter->hwRenderSupported = true;\n\t\tadapter->deviceGuid = *lpGuid;\n\t\tadapter->D3DHWDeviceDesc = *lpD3DHWDeviceDesc;\n\n\t\tadapter->perspectiveCorrectSupported = (lpD3DHWDeviceDesc->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE)? true:false;\n\t\tadapter->ditherSupported = (lpD3DHWDeviceDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_DITHER)? true:false;\n\t\tadapter->zBufferSupported = (lpD3DHWDeviceDesc->dwDeviceZBufferBitDepth)? true:false;\n\t\tadapter->linearFilterSupported = (lpD3DHWDeviceDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR)? true:false;\n\t\tadapter->shadeRestricted = (lpD3DHWDeviceDesc->dpcTriCaps.dwShadeCaps & (D3DPSHADECAPS_ALPHAGOURAUDBLEND|D3DPSHADECAPS_ALPHAFLATBLEND))? false:true;\n\t}\n\treturn D3DENUMRET_OK;\n}\n\nbool __cdecl D3DIsSupported(LPD3DDEVICEDESC desc) {\n\tif( (desc->dwFlags & D3DDD_COLORMODEL) &&\n\t\t(desc->dcmColorModel & D3DCOLOR_RGB) &&\n\t\t(desc->dwFlags & D3DDD_TRICAPS) &&\n\t\t(desc->dpcTriCaps.dwShadeCaps & D3DPSHADECAPS_COLORGOURAUDRGB) &&\n\t\t(desc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATE) )\n\t{\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nbool __cdecl D3DSetViewport() {\n\tD3DVIEWPORT2 viewPort;\n\n\tviewPort.dwSize = sizeof(D3DVIEWPORT2);\n\tviewPort.dvClipX = 0.0;\n\tviewPort.dvClipY = 0.0;\n\tviewPort.dvClipWidth = (float)GameVidWidth;\n\tviewPort.dvClipHeight = (float)GameVidHeight;\n\n\tviewPort.dwX = 0;\n\tviewPort.dwY = 0;\n\tviewPort.dwWidth = GameVidWidth;\n\tviewPort.dwHeight = GameVidHeight;\n\n\tviewPort.dvMinZ = 0.0;\n\tviewPort.dvMaxZ = 1.0;\n\n\tif FAILED(D3DView->SetViewport2(&viewPort)) {\n\t\tD3DView->GetViewport2(&viewPort);\n\t\treturn false;\n\t}\n\n\treturn SUCCEEDED(D3DDev->SetCurrentViewport(D3DView));\n\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nvoid __cdecl D3DDeviceCreate(LPDDS lpBackBuffer) {\n\tif( D3D == NULL && !D3DCreate() )\n\t\tthrow ERR_D3D_Create;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tD3DPRESENT_PARAMETERS d3dpp;\n\tmemset(&d3dpp, 0, sizeof(d3dpp));\n\n\td3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;\n\td3dpp.hDeviceWindow = HGameWindow;\n\td3dpp.EnableAutoDepthStencil = TRUE;\n\n\tD3DCAPS9 *caps = &SavedAppSettings.PreferredDisplayAdapter->body.caps;\n\tif SUCCEEDED(D3D->CheckDepthStencilMatch(caps->AdapterOrdinal, caps->DeviceType, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_D16)) {\n\t\td3dpp.AutoDepthStencilFormat = D3DFMT_D16;\n\t} else if SUCCEEDED(D3D->CheckDepthStencilMatch(caps->AdapterOrdinal, caps->DeviceType, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_D24X8)) {\n\t\td3dpp.AutoDepthStencilFormat = D3DFMT_D24X8;\n\t} else {\n\t\tthrow ERR_CreateDevice;\n\t}\n\n\td3dpp.Windowed = !SavedAppSettings.FullScreen;\n\tif( SavedAppSettings.FullScreen ) {\n\t\td3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;\n\t\td3dpp.BackBufferWidth = FullScreenWidth;\n\t\td3dpp.BackBufferHeight = FullScreenHeight;\n\t}\n\n\tif( D3DDev ) {\n\t\tif( D3DVtx != NULL ) {\n\t\t\tD3DVtx->Release();\n\t\t\tD3DVtx = NULL;\n\t\t}\n\t\tHRESULT res = D3D_OK;\n\t\tdo {\n\t\t\tres = D3DDev->TestCooperativeLevel();\n\t\t} while( res == D3DERR_DEVICELOST );\n\t\tif( (res != D3D_OK && res != D3DERR_DEVICENOTRESET) || FAILED(D3DDev->Reset(&d3dpp)) ) {\n\t\t\tthrow ERR_CreateDevice;\n\t\t}\n\t} else {\n\t\tDWORD flags = CHK_ANY(caps->DevCaps, D3DDEVCAPS_HWTRANSFORMANDLIGHT) ? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING;\n\t\tif FAILED(D3D->CreateDevice(CurrentDisplayAdapter.index, D3DDEVTYPE_HAL, HGameWindow, flags, &d3dpp, &D3DDev)) {\n\t\t\tthrow ERR_CreateDevice;\n\t\t}\n\t}\n\n\tif( !D3DVtx && FAILED(D3DDev->CreateVertexBuffer(sizeof(D3DTLVERTEX) * VTXBUF_LEN, D3DUSAGE_WRITEONLY|D3DUSAGE_DONOTCLIP|D3DUSAGE_DYNAMIC, D3DFVF_TLVERTEX, D3DPOOL_DEFAULT, &D3DVtx, NULL)) )\n\t\tthrow ERR_CreateDevice;\n\n\tD3DDev->SetStreamSource(0, D3DVtx, 0, sizeof(D3DTLVERTEX));\n\tD3DDev->SetFVF(D3DFVF_TLVERTEX);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif FAILED(D3D->CreateDevice(IID_IDirect3DHALDevice, (LPDIRECTDRAWSURFACE)lpBackBuffer, &D3DDev))\n\t\tthrow ERR_CreateDevice;\n\n\tif FAILED(D3D->CreateViewport(&D3DView, NULL))\n\t\tthrow ERR_CreateViewport;\n\n\tif FAILED(D3DDev->AddViewport(D3DView))\n\t\tthrow ERR_AddViewport;\n\n\tif FAILED(!D3DSetViewport())\n\t\tthrow ERR_SetViewport2;\n\n\tif FAILED(D3D->CreateMaterial(&D3DMaterial, NULL))\n\t\tthrow ERR_CreateViewport;\n\n\tD3DMATERIAL matData;\n\tD3DMATERIALHANDLE matHandle;\n\tmemset(&matData, 0, sizeof(matData));\n\tmatData.dwSize = sizeof(matData);\n\n\tif FAILED(D3DMaterial->SetMaterial(&matData))\n\t\tthrow ERR_CreateViewport;\n\n\tif FAILED(D3DMaterial->GetHandle(D3DDev, &matHandle))\n\t\tthrow ERR_CreateViewport;\n\n\tif FAILED(D3DView->SetBackground(matHandle))\n\t\tthrow ERR_CreateViewport;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl Direct3DRelease() {\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( D3DVtx != NULL ) {\n\t\tD3DVtx->Release();\n\t\tD3DVtx = NULL;\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( D3DMaterial != NULL ) {\n\t\tD3DMaterial->Release();\n\t\tD3DMaterial = NULL;\n\t}\n\tif( D3DView != NULL ) {\n\t\tD3DView->Release();\n\t\tD3DView = NULL;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\tif( D3DDev != NULL ) {\n\t\tD3DDev->Release();\n\t\tD3DDev = NULL;\n\t}\n\tD3DRelease();\n}\n\nbool __cdecl Direct3DInit() {\n\treturn true;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Init3d() {\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x004445F0, Enumerate3DDevices);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00444620, D3DCreate);\n\tINJECT(0x00444640, D3DRelease);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00444660, Enum3DDevicesCallback);\n\tINJECT(0x00444720, D3DIsSupported);\n\tINJECT(0x00444760, D3DSetViewport);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00444820, D3DDeviceCreate);\n\tINJECT(0x004449E0, Direct3DRelease);\n\tINJECT(0x00444A30, Direct3DInit);\n}\n"
  },
  {
    "path": "specific/init_3d.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef INIT_3D_H_INCLUDED\n#define INIT_3D_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl Enumerate3DDevices(DISPLAY_ADAPTER *adapter); // 0x004445F0\n#endif // (DIRECT3D_VERSION < 0x900)\nbool __cdecl D3DCreate(); // 0x00444620\nvoid __cdecl D3DRelease(); // 0x00444640\n#if (DIRECT3D_VERSION < 0x900)\nHRESULT CALLBACK Enum3DDevicesCallback(GUID FAR* lpGuid, LPTSTR lpDeviceDescription, LPTSTR lpDeviceName, LPD3DDEVICEDESC lpD3DHWDeviceDesc, LPD3DDEVICEDESC lpD3DHELDeviceDesc, LPVOID lpContext); // 0x00444660\nbool __cdecl D3DIsSupported(LPD3DDEVICEDESC desc); // 0x00444720\nbool __cdecl D3DSetViewport(); // 0x00444760\n#endif // (DIRECT3D_VERSION < 0x900)\nvoid __cdecl D3DDeviceCreate(LPDDS lpBackBuffer); // 0x00444820\nvoid __cdecl Direct3DRelease(); // 0x004449E0\nbool __cdecl Direct3DInit(); // 0x00444A30\n\n#endif // INIT_3D_H_INCLUDED\n"
  },
  {
    "path": "specific/init_display.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"game/health.h\"\n#include \"specific/display.h\"\n#include \"specific/init_display.h\"\n#include \"specific/file.h\"\n#include \"specific/hwr.h\"\n#include \"specific/init_3d.h\"\n#include \"specific/output.h\"\n#include \"specific/texture.h\"\n#include \"specific/winmain.h\"\n#include \"specific/winvid.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/background_new.h\"\n\nextern DWORD BGND_PictureWidth;\nextern DWORD BGND_PictureHeight;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n// Related to ERROR_CODE enum\nstatic LPCTSTR ErrorStringTable[] = {\n\t\"OK\",\n\t\"PreferredAdapterNotFound\",\n\t\"CantCreateWindow\",\n\t\"CantCreateDirectDraw\",\n\t\"CantInitRenderer\",\n\t\"CantCreateDirectInput\",\n\t\"CantCreateKeyboardDevice\",\n\t\"CantSetKBCooperativeLevel\",\n\t\"CantSetKBDataFormat\",\n\t\"CantAcquireKeyboard\",\n\t\"CantSetDSCooperativeLevel\",\n\t\"DD_SetExclusiveMode\",\n\t\"DD_ClearExclusiveMode\",\n\t\"SetDisplayMode\",\n\t\"CreateScreenBuffers\",\n\t\"GetBackBuffer\",\n\t\"CreatePalette\",\n\t\"SetPalette\",\n\t\"CreatePrimarySurface\",\n\t\"CreateBackBuffer\",\n\t\"CreateClipper\",\n\t\"SetClipperHWnd\",\n\t\"SetClipper\",\n\t\"CreateZBuffer\",\n\t\"AttachZBuffer\",\n\t\"CreateRenderBuffer\",\n\t\"CreatePictureBuffer\",\n\t\"D3D_Create\",\n\t\"CreateDevice\",\n\t\"CreateViewport\",\n\t\"AddViewport\",\n\t\"SetViewport2\",\n\t\"SetCurrentViewport\",\n\t\"ClearRenderBuffer\",\n\t\"UpdateRenderInfo\",\n\t\"GetThirdBuffer\",\n\t\"GoFullScreen\",\n\t\"GoWindowed\",\n\t\"WrongBitDepth\",\n\t\"GetPixelFormat\",\n\t\"GetDisplayMode\",\n};\n\n#if (DIRECT3D_VERSION >= 0x900)\n#ifdef FEATURE_VIDEOFX_IMPROVED\nextern DWORD ReflectionMode;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\nSWR_BUFFER RenderBuffer = {0, 0, NULL};\nSWR_BUFFER PictureBuffer = {0, 0, NULL};\n\nstatic bool SWRBufferCreate(SWR_BUFFER *buffer, DWORD width, DWORD height) {\n\tif( !buffer || !width || !height ) return false;\n\tbuffer->width = width;\n\tbuffer->height = height;\n\tbuffer->bitmap = (LPBYTE)calloc(1, width*height);\n\treturn ( buffer->bitmap != NULL );\n}\n\nstatic void SWRBufferFree(SWR_BUFFER *buffer) {\n\tif( !buffer || !buffer->bitmap ) return;\n\tfree(buffer->bitmap);\n\tbuffer->bitmap = NULL;\n}\n\nstatic bool SWRBufferClear(SWR_BUFFER *buffer, BYTE value) {\n\tif( !buffer || !buffer->bitmap || !buffer->width || !buffer->height ) return false;\n\tmemset(buffer->bitmap, value, buffer->width * buffer->height);\n\treturn true;\n}\n\nLPDDS CaptureBufferSurface = NULL;\n\nstatic void FreeCaptureBuffer() {\n\tif( CaptureBufferSurface != NULL) {\n\t\tCaptureBufferSurface->Release();\n\t\tCaptureBufferSurface = NULL;\n\t}\n}\n\nstatic int CreateCaptureBuffer() {\n\tFreeCaptureBuffer();\n\n\tif FAILED(D3DDev->CreateRenderTarget(GameVidWidth, GameVidHeight, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &CaptureBufferSurface, NULL))\n\t\treturn -1;\n\n\tD3DDev->ColorFill(CaptureBufferSurface, NULL, 0);\n\n\tDDSDESC desc;\n\tif FAILED(CaptureBufferSurface->LockRect(&desc, NULL, 0)) {\n\t\tFreeCaptureBuffer();\n\t\treturn -1;\n\t}\n\n\tCaptureBufferSurface->UnlockRect();\n\treturn 0;\n}\n#else // (DIRECT3D_VERSION >= 0x900)\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\nLPDDS CaptureBufferSurface = NULL; // used for screen capture in windowed mode\nLPDDS EnvmapBufferSurface = NULL; // used as environment map for the reflection effect\n\nstatic int CreateCaptureBuffer() {\n\tDDSDESC dsp;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS;\n\tdsp.dwWidth = GameVidBufWidth;\n\tdsp.dwHeight = GameVidBufHeight;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_3DDEVICE|DDSCAPS_OFFSCREENPLAIN;\n\n\tif( SavedAppSettings.RenderMode == RM_Hardware )\n\t\tdsp.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;\n\n\tif FAILED(DDrawSurfaceCreate(&dsp, &CaptureBufferSurface))\n\t\treturn -1;\n\n\tWinVidClearBuffer(CaptureBufferSurface, NULL, 0);\n\treturn 0;\n}\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\nvoid __cdecl CreateScreenBuffers() {\n\tDDSCAPS ddsCaps;\n\tDDSDESC dsp;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_BACKBUFFERCOUNT|DDSD_CAPS;\n\tdsp.dwBackBufferCount = (SavedAppSettings.TripleBuffering) ? 2 : 1;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;\n\tif( SavedAppSettings.RenderMode == RM_Hardware )\n\t\tdsp.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;\n\n\tif FAILED(DDrawSurfaceCreate(&dsp, &PrimaryBufferSurface))\n\t\tthrow ERR_CreateScreenBuffers;\n\n\tWinVidClearBuffer(PrimaryBufferSurface, NULL, 0);\n\n\tmemset(&ddsCaps, 0, sizeof(ddsCaps));\n\tddsCaps.dwCaps = DDSCAPS_BACKBUFFER;\n\tif FAILED(PrimaryBufferSurface->GetAttachedSurface(&ddsCaps, &BackBufferSurface))\n\t\tthrow ERR_GetBackBuffer;\n\n\tWinVidClearBuffer(BackBufferSurface, NULL, 0);\n\n\tif( SavedAppSettings.TripleBuffering ) {\n\t\tmemset(&ddsCaps, 0, sizeof(ddsCaps));\n\t\tddsCaps.dwCaps = DDSCAPS_FLIP;\n\t\tif FAILED(BackBufferSurface->GetAttachedSurface(&ddsCaps, &ThirdBufferSurface))\n\t\t\tthrow ERR_GetThirdBuffer;\n\n\t\tWinVidClearBuffer(ThirdBufferSurface, NULL, 0);\n\t}\n}\n\nvoid __cdecl CreatePrimarySurface() {\n\tDDSDESC dsp;\n\n\tif( ( GameVid_IsVga && SavedAppSettings.RenderMode == RM_Hardware) ||\n\t\t(!GameVid_IsVga && SavedAppSettings.RenderMode == RM_Software) )\n\t\tthrow ERR_WrongBitDepth;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_CAPS;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;\n\n\tif FAILED(DDrawSurfaceCreate(&dsp, &PrimaryBufferSurface))\n\t\tthrow ERR_CreatePrimarySurface;\n}\n\nvoid __cdecl CreateBackBuffer() {\n\tDDSDESC dsp;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS;\n\tdsp.dwWidth = GameVidBufWidth;\n\tdsp.dwHeight = GameVidBufHeight;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_3DDEVICE|DDSCAPS_OFFSCREENPLAIN;\n\n\tif( SavedAppSettings.RenderMode == RM_Hardware )\n\t\tdsp.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;\n\n\tif FAILED(DDrawSurfaceCreate(&dsp, &BackBufferSurface))\n\t\tthrow ERR_CreateBackBuffer;\n\n\tWinVidClearBuffer(BackBufferSurface, NULL, 0);\n}\n\nvoid __cdecl CreateClipper() {\n\n\tif FAILED(DDraw->CreateClipper(0, &DDrawClipper, NULL))\n\t\tthrow ERR_CreateClipper;\n\n\tif FAILED(DDrawClipper->SetHWnd(0, HGameWindow))\n\t\tthrow ERR_SetClipperHWnd;\n\n\tif FAILED(PrimaryBufferSurface->SetClipper(DDrawClipper))\n\t\tthrow ERR_SetClipper;\n}\n\nvoid __cdecl CreateWindowPalette() {\n\tint i;\n\tDWORD dwFlags = DDPCAPS_8BIT;\n\n\tmemset(WinVidPalette, 0, sizeof(WinVidPalette));\n\n\tif( GameVid_IsWindowedVga ) {\n\t\tfor( i=0; i<10; ++i ) {\n\t\t\tWinVidPalette[i].peFlags = PC_EXPLICIT;\n\t\t\tWinVidPalette[i].peRed   = i;\n\t\t}\n\t\tfor( i=10; i<246; ++i ) {\n\t\t\tWinVidPalette[i].peFlags = PC_NOCOLLAPSE | PC_RESERVED;\n\t\t}\n\t\tfor( i=246; i<256; ++i ) {\n\t\t\tWinVidPalette[i].peFlags = PC_EXPLICIT;\n\t\t\tWinVidPalette[i].peRed   = i;\n\t\t}\n\t} else {\n\t\tfor( i=0; i<256; ++i ) {\n\t\t\tWinVidPalette[i].peFlags = PC_RESERVED;\n\t\t}\n\t\tdwFlags |= DDPCAPS_ALLOW256;\n\t}\n\n\tif FAILED(DDraw->CreatePalette(dwFlags, WinVidPalette, &DDrawPalette, NULL))\n\t\tthrow ERR_CreatePalette;\n\n\tif FAILED(PrimaryBufferSurface->SetPalette(DDrawPalette))\n\t\tthrow ERR_SetPalette;\n}\n\nvoid __cdecl CreateZBuffer() {\n\tDDSDESC dsp;\n\n\tif( (CurrentDisplayAdapter.D3DHWDeviceDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBUFFERLESSHSR) != 0 )\n\t\treturn;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwWidth = GameVidBufWidth;\n\tdsp.dwHeight = GameVidBufHeight;\n\tdsp.dwFlags = DDSD_ZBUFFERBITDEPTH|DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS;\n\tdsp.dwZBufferBitDepth = GetZBufferDepth();\n\tdsp.ddsCaps.dwCaps = DDSCAPS_ZBUFFER|DDSCAPS_VIDEOMEMORY;\n\n\tif FAILED(DDrawSurfaceCreate(&dsp, &ZBufferSurface))\n\t\tthrow ERR_CreateZBuffer;\n\n\tif FAILED(BackBufferSurface->AddAttachedSurface(ZBufferSurface))\n\t\tthrow ERR_AttachZBuffer;\n}\n\nDWORD __cdecl GetZBufferDepth() {\n\tDWORD bitDepthMask = CurrentDisplayAdapter.D3DHWDeviceDesc.dwDeviceZBufferBitDepth;\n\tif( (bitDepthMask & DDBD_16) != 0 ) return 16;\n\tif( (bitDepthMask & DDBD_24) != 0 ) return 24;\n\tif( (bitDepthMask & DDBD_32) != 0 ) return 32;\n\treturn 8;\n}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\nvoid __cdecl CreateRenderBuffer() {\n#if (DIRECT3D_VERSION >= 0x900)\n\tSWRBufferFree(&RenderBuffer);\n\tif( !SWRBufferCreate(&RenderBuffer, GameVidWidth, GameVidHeight) )\n\t\tthrow ERR_CreateRenderBuffer;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tDDSDESC dsp;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS;\n\tdsp.dwWidth = GameVidBufWidth;\n\tdsp.dwHeight = GameVidBufHeight;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY|DDSCAPS_OFFSCREENPLAIN;\n\n\tif FAILED(DDrawSurfaceCreate(&dsp, &RenderBufferSurface))\n\t\tthrow ERR_CreateRenderBuffer;\n\n\tif( !WinVidClearBuffer(RenderBufferSurface, NULL, 0) )\n\t\tthrow ERR_ClearRenderBuffer;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl CreatePictureBuffer() {\n#if (DIRECT3D_VERSION >= 0x900)\n\tSWRBufferFree(&PictureBuffer);\n\tif( !SWRBufferCreate(&PictureBuffer, BGND_PictureWidth, BGND_PictureHeight) )\n\t\tthrow ERR_CreatePictureBuffer;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tDDSDESC dsp;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY|DDSCAPS_OFFSCREENPLAIN;\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tdsp.dwWidth = BGND_PictureWidth;\n\tdsp.dwHeight = BGND_PictureHeight;\n#else // !FEATURE_BACKGROUND_IMPROVED\n\tdsp.dwWidth = 640;\n\tdsp.dwHeight = 480;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\tif FAILED(DDrawSurfaceCreate(&dsp, &PictureBufferSurface))\n\t\tthrow ERR_CreatePictureBuffer;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl ClearBuffers(DWORD flags, DWORD fillColor) {\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( CHK_ANY(flags, CLRB_RenderBuffer) )\n\t\tSWRBufferClear(&RenderBuffer, 0);\n\n\tif( CHK_ANY(flags, CLRB_PictureBuffer) )\n\t\tSWRBufferClear(&PictureBuffer, 0);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tDWORD d3dClearFlags = 0;\n\tD3DRECT d3dRect;\n\tRECT winRect;\n\n\tif( (flags & CLRB_PhdWinSize) != 0 ) {\n\t\twinRect.left = PhdWinMinX;\n\t\twinRect.top  = PhdWinMinY;\n\t\twinRect.right  = PhdWinMinX + PhdWinWidth;\n\t\twinRect.bottom = PhdWinMinY + PhdWinHeight;\n\t} else {\n\t\twinRect.left = 0;\n\t\twinRect.top  = 0;\n\t\twinRect.right  = GameVidWidth;\n\t\twinRect.bottom = GameVidHeight;\n\t}\n\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t// Hardware Renderer Checks\n\t\tif( (flags & CLRB_BackBuffer) != 0 )\n\t\t\td3dClearFlags |= D3DCLEAR_TARGET;\n\n\t\tif( (flags & CLRB_ZBuffer) != 0 )\n\t\t\td3dClearFlags |= D3DCLEAR_ZBUFFER;\n\n\t\tif( d3dClearFlags ) {\n\t\t\td3dRect.x1 = winRect.left;\n\t\t\td3dRect.y1 = winRect.top;\n\t\t\td3dRect.x2 = winRect.right;\n\t\t\td3dRect.y2 = winRect.bottom;\n\t\t\tD3DView->Clear(1, &d3dRect, d3dClearFlags);\n\t\t}\n\t} else {\n\t// Software Renderer Checks\n\t\tif( (flags & CLRB_BackBuffer) != 0 )\n\t\t\tWinVidClearBuffer(BackBufferSurface, &winRect, fillColor);\n\t}\n\n\t// Common checks\n\tif( (flags & CLRB_PrimaryBuffer) != 0 ) {\n\t\tWinVidClearBuffer(PrimaryBufferSurface, &winRect, fillColor);\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\t\tif( CaptureBufferSurface != NULL ) {\n\t\t\tWinVidClearBuffer(CaptureBufferSurface, &winRect, fillColor);\n\t\t}\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\t}\n\n\tif( (flags & CLRB_ThirdBuffer) != 0 )\n\t\tWinVidClearBuffer(ThirdBufferSurface, &winRect, fillColor);\n\n\tif( (flags & CLRB_RenderBuffer) != 0 ) {\n\t\tWinVidClearBuffer(RenderBufferSurface, &winRect, fillColor);\n\t}\n\n\tif( (flags & CLRB_PictureBuffer) != 0 ) {\n\t\twinRect.left = 0;\n\t\twinRect.top  = 0;\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t\twinRect.right = BGND_PictureWidth;\n\t\twinRect.bottom = BGND_PictureHeight;\n#else // !FEATURE_BACKGROUND_IMPROVED\n\t\twinRect.right = 640;\n\t\twinRect.bottom = 480;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\t\tWinVidClearBuffer(PictureBufferSurface, &winRect, fillColor);\n\t}\n\n\tif( (flags & CLRB_WindowedPrimaryBuffer) != 0 ) {\n\t\twinRect.left = GameWindowPositionX;\n\t\twinRect.top  = GameWindowPositionY;\n\t\twinRect.right  = GameWindowPositionX + GameWindowWidth;\n\t\twinRect.bottom = GameWindowPositionY + GameWindowHeight;\n\t\tWinVidClearBuffer(PrimaryBufferSurface, &winRect, fillColor);\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl RestoreLostBuffers() {\n\tif( !PrimaryBufferSurface ) {\n\t\tS_ExitSystem(\"Oops... no front buffer\");\n\t\treturn; // the app is terminated here\n\t}\n\tif FAILED(DDrawSurfaceRestoreLost(PrimaryBufferSurface, NULL, SavedAppSettings.FullScreen)) {\n\t\tgoto REBUILD;\n\t}\n\tif( SavedAppSettings.FullScreen || SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tif FAILED(DDrawSurfaceRestoreLost(BackBufferSurface, PrimaryBufferSurface, true))\n\t\t\tgoto REBUILD;\n\t}\n\tif( SavedAppSettings.TripleBuffering ) {\n\t\tif FAILED(DDrawSurfaceRestoreLost(ThirdBufferSurface, PrimaryBufferSurface, true))\n\t\t\tgoto REBUILD;\n\t}\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\tif FAILED(DDrawSurfaceRestoreLost(RenderBufferSurface, NULL, false))\n\t\t\tgoto REBUILD;\n\t}\n\tif( ZBufferSurface ) {\n\t\tif FAILED(DDrawSurfaceRestoreLost(ZBufferSurface, NULL, false))\n\t\t\tgoto REBUILD;\n\t}\n\tif( PictureBufferSurface ) {\n\t\tif FAILED(DDrawSurfaceRestoreLost(PictureBufferSurface, NULL, false))\n\t\t\tgoto REBUILD;\n\t}\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\tif( CaptureBufferSurface ) {\n\t\tif FAILED(DDrawSurfaceRestoreLost(CaptureBufferSurface, PrimaryBufferSurface, true))\n\t\t\tgoto REBUILD;\n\t}\n\tif( EnvmapBufferSurface ) {\n\t\tif FAILED(DDrawSurfaceRestoreLost(EnvmapBufferSurface, NULL, false))\n\t\t\tgoto REBUILD;\n\t}\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\treturn;\n\nREBUILD:\n\tif( !IsGameToExit ) {\n\t\tApplySettings(&SavedAppSettings);\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\tHWR_GetPageHandles();\n\t\t}\n\t}\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nvoid __cdecl UpdateFrame(bool needRunMessageLoop, LPRECT rect) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t// This method is pretty fast, so we can do it every frame\n\tLPDDS backBuffer = NULL;\n\tif SUCCEEDED(D3DDev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer)) {\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\tD3DDev->StretchRect(backBuffer, NULL, CaptureBufferSurface, NULL, D3DTEXF_NONE);\n#if FEATURE_VIDEOFX_IMPROVED\n\t\t\tif( ReflectionMode != 0 ) SetEnvmapTexture(backBuffer);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\t} else {\n\t\t\tD3DDev->StretchRect(CaptureBufferSurface, NULL, backBuffer, NULL, D3DTEXF_NONE);\n\t\t}\n\t\tbackBuffer->Release();\n\t}\n\tHRESULT res = D3DDev->Present(NULL, NULL, NULL, NULL);\n\tif( res == D3DERR_DEVICELOST && !IsGameToExit ) {\n\t\tFreeCaptureBuffer();\n#if FEATURE_VIDEOFX_IMPROVED\n\t\tFreeEnvmapTexture();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t\tD3DDeviceCreate(NULL);\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\tHWR_InitState();\n\t\t}\n\t\tCreateCaptureBuffer();\n\t}\n\tD3DDev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0, 0);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tRECT dstRect;\n\tLPRECT pSrcRect = rect ? rect : &GameVidRect;\n\n\tRestoreLostBuffers();\n\tif( SavedAppSettings.FullScreen ) {\n\t\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\t\tBackBufferSurface->Blt(pSrcRect, RenderBufferSurface, pSrcRect, DDBLT_WAIT, NULL);\n\t\t}\n\t\tPrimaryBufferSurface->Flip(NULL, DDFLIP_WAIT);\n\t} else {\n\t\tdstRect.left = GameWindowPositionX + pSrcRect->left;\n\t\tdstRect.top = GameWindowPositionY + pSrcRect->top;\n\t\tdstRect.right = GameWindowPositionX + pSrcRect->right;\n\t\tdstRect.bottom = GameWindowPositionY + pSrcRect->bottom;\n\n\t\tLPDDS surface = ( SavedAppSettings.RenderMode == RM_Software ) ? RenderBufferSurface : BackBufferSurface;\n\t\tPrimaryBufferSurface->Blt(&dstRect, surface, pSrcRect, DDBLT_WAIT, NULL);\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\t\tif( CaptureBufferSurface != NULL ) {\n\t\t\tCaptureBufferSurface->Blt(pSrcRect, BackBufferSurface, pSrcRect, DDBLT_WAIT, NULL);\n\t\t}\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( needRunMessageLoop ) {\n\t\tWinVidSpinMessageLoop(false);\n\t}\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl WaitPrimaryBufferFlip() {\n\tif( SavedAppSettings.FlipBroken && SavedAppSettings.FullScreen ) {\n\t\twhile( PrimaryBufferSurface->GetFlipStatus(DDGFS_ISFLIPDONE) == DDERR_WASSTILLDRAWING )\n\t\t\t/* just wait */;\n\t}\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nbool __cdecl RenderInit() {\n\treturn true;\n}\n\nvoid __cdecl RenderStart(bool isReset) {\n\tint minWidth;\n\tint minHeight;\n\tDISPLAY_MODE dispMode;\n#if (DIRECT3D_VERSION < 0x900)\n\tbool is16bitTextures;\n\tDDPIXELFORMAT pixelFormat;\n\n\tif( isReset )\n\t\tNeedToReloadTextures = false;\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\tif( SavedAppSettings.FullScreen ) {\n\t\t// FullScreen mode\n\n\t\tif( SavedAppSettings.VideoMode == NULL )\n\t\t\tthrow ERR_GoFullScreen;\n\n\t\tdispMode.width  = SavedAppSettings.VideoMode->body.width;\n\t\tdispMode.height = SavedAppSettings.VideoMode->body.height;\n\t\tdispMode.bpp = SavedAppSettings.VideoMode->body.bpp;\n\t\tdispMode.vga = SavedAppSettings.VideoMode->body.vga;\n\n\t\tif( !WinVidGoFullScreen(&dispMode) )\n\t\t\tthrow ERR_GoFullScreen;\n\n#if (DIRECT3D_VERSION < 0x900)\n\t\tCreateScreenBuffers();\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\t\tGameVidWidth  = dispMode.width;\n\t\tGameVidHeight = dispMode.height;\n\t\tGameVidBPP = dispMode.bpp;\n#if (DIRECT3D_VERSION < 0x900)\n\t\tGameVidBufWidth  = dispMode.width;\n\t\tGameVidBufHeight = dispMode.height;\n\t\tGameVid_IsVga = ( dispMode.vga != VGA_NoVga );\n\t\tGameVid_IsWindowedVga = false;\n\t\tGameVid_IsFullscreenVga = ( dispMode.vga == VGA_Standard );\n#endif // (DIRECT3D_VERSION < 0x900)\n\t} else {\n\t\t// Windowed mode\n\n\t\tminWidth = 320;\n\t\tminHeight = CalculateWindowHeight(320, 200);\n\t\tif( minHeight < 200 ) {\n\t\t\tminWidth = CalculateWindowWidth(320, 200);\n\t\t\tminHeight = 200;\n\t\t}\n\n\t\tWinVidSetMinWindowSize(minWidth, minHeight);\n\t\tif( !WinVidGoWindowed(SavedAppSettings.WindowWidth, SavedAppSettings.WindowHeight, &dispMode) )\n\t\t\tthrow ERR_GoWindowed;\n\n\t\tGameVidWidth  = dispMode.width;\n\t\tGameVidHeight = dispMode.height;\n\t\tGameVidBPP = dispMode.bpp;\n\n#if (DIRECT3D_VERSION < 0x900)\n\t\tGameVidBufWidth  = (dispMode.width  + 0x1F) & ~0x1F;\n\t\tGameVidBufHeight = (dispMode.height + 0x1F) & ~0x1F;\n\t\tGameVid_IsVga = ( dispMode.vga != 0 );\n\t\tGameVid_IsWindowedVga = ( dispMode.vga != VGA_NoVga );\n\t\tGameVid_IsFullscreenVga = false;\n\n\t\tCreatePrimarySurface();\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\tCreateBackBuffer();\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\t\t\tCreateCaptureBuffer();\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\t\t}\n\n\t\tCreateClipper();\n#endif // (DIRECT3D_VERSION < 0x900)\n\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n\tFreeCaptureBuffer();\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n#if FEATURE_VIDEOFX_IMPROVED\n\tFreeEnvmapTexture();\n#endif // FEATURE_VIDEOFX_IMPROVED\n\tD3DDeviceCreate(NULL);\n\tTextureFormat.bpp = 32;\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n\tCreateCaptureBuffer();\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n#if defined(FEATURE_BACKGROUND_IMPROVED)\n\t\tBGND2_PrepareCaptureTextures();\n#endif // defined(FEATURE_BACKGROUND_IMPROVED)\n\t} else {\n\t\tCreateRenderBuffer();\n\t\tif( !PictureBuffer.bitmap ) {\n\t\t\tCreatePictureBuffer();\n\t\t}\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tmemset(&pixelFormat, 0, sizeof(DDPIXELFORMAT));\n\tpixelFormat.dwSize = sizeof(DDPIXELFORMAT);\n\tif FAILED(PrimaryBufferSurface->GetPixelFormat(&pixelFormat))\n\t\tthrow ERR_GetPixelFormat;\n\n\tWinVidGetColorBitMasks(&ColorBitMasks, &pixelFormat);\n\tif( GameVid_IsVga )\n\t\tCreateWindowPalette();\n\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tif( SavedAppSettings.ZBuffer ) {\n\t\t\tCreateZBuffer();\n\t\t}\n\t\tD3DDeviceCreate(BackBufferSurface);\n\t\tEnumerateTextureFormats();\n#if defined(FEATURE_BACKGROUND_IMPROVED)\n\t\tBGND2_PrepareCaptureTextures();\n#endif // defined(FEATURE_BACKGROUND_IMPROVED)\n\t} else {\n\t\tCreateRenderBuffer();\n\t\tif( PictureBufferSurface == NULL ) {\n\t\t\tCreatePictureBuffer();\n\t\t}\n\t}\n\n\tif( NeedToReloadTextures ) {\n\t\tis16bitTextures = ( TextureFormat.bpp >= 16 );\n\t\tif( IsWindowedVGA != GameVid_IsWindowedVga || Is16bitTextures != is16bitTextures ) {\n\t\t\tS_ReloadLevelGraphics(IsWindowedVGA != GameVid_IsWindowedVga, Is16bitTextures != is16bitTextures );\n\t\t\tIsWindowedVGA = GameVid_IsWindowedVga;\n\t\t\tIs16bitTextures = is16bitTextures;\n\t\t} else if( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\tReloadTextures(true);\n\t\t\tHWR_GetPageHandles();\n\t\t}\n\t} else {\n\t\tIsWindowedVGA = GameVid_IsWindowedVga;\n\t\tIs16bitTextures = ( TextureFormat.bpp >= 16 );\n\t}\n\n\tGameVidBufRect.left = 0;\n\tGameVidBufRect.top  = 0;\n\tGameVidBufRect.right  = GameVidBufWidth;\n\tGameVidBufRect.bottom = GameVidBufHeight;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tGameVidRect.left = 0;\n\tGameVidRect.top  = 0;\n\tGameVidRect.right  = GameVidWidth;\n\tGameVidRect.bottom = GameVidHeight;\n\n\tDumpWidth  = GameVidWidth;\n\tDumpHeight = GameVidHeight;\n\n\tsetup_screen_size();\n#if (DIRECT3D_VERSION < 0x900)\n\tNeedToReloadTextures = true;\n#endif // (DIRECT3D_VERSION < 0x900)\n}\n\nvoid __cdecl RenderFinish(bool needToClearTextures) {\n#if (DIRECT3D_VERSION >= 0x900)\n\tS_DontDisplayPicture();\n\tHWR_FreeTexturePages();\n\tCleanupTextures();\n\tSWRBufferFree(&PictureBuffer);\n\tSWRBufferFree(&RenderBuffer);\n\tFreeCaptureBuffer();\n\tDirect3DRelease();\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t// Hardware Renderer\n\t\tif( needToClearTextures ) {\n\t\t\tS_DontDisplayPicture(); // NOTE: this line was absent in the original game\n\t\t\tHWR_FreeTexturePages();\n\t\t\tCleanupTextures();\n\t\t}\n\t\tDirect3DRelease();\n\n\t\tif( ZBufferSurface != NULL ) {\n\t\t\tZBufferSurface->Release();\n\t\t\tZBufferSurface = NULL;\n\t\t}\n\t} else {\n\t\t// Software Renderer\n\t\tif( needToClearTextures && PictureBufferSurface != NULL ) {\n\t\t\tPictureBufferSurface->Release();\n\t\t\tPictureBufferSurface = NULL;\n\t\t}\n\n\t\tif( RenderBufferSurface != NULL ) {\n\t\t\tRenderBufferSurface->Release();\n\t\t\tRenderBufferSurface = NULL;\n\t\t}\n\t}\n\n\tif( DDrawPalette != NULL ) {\n\t\tDDrawPalette->Release();\n\t\tDDrawPalette = NULL;\n\t}\n\n\tif( DDrawClipper != NULL ) {\n\t\tDDrawClipper->Release();\n\t\tDDrawClipper = NULL;\n\t}\n\n\tif( ThirdBufferSurface != NULL ) {\n\t\tThirdBufferSurface->Release();\n\t\tThirdBufferSurface = NULL;\n\t}\n\n\tif( BackBufferSurface != NULL ) {\n\t\tBackBufferSurface->Release();\n\t\tBackBufferSurface = NULL;\n\t}\n\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\tif( CaptureBufferSurface != NULL ) {\n\t\tCaptureBufferSurface->Release();\n\t\tCaptureBufferSurface = NULL;\n\t}\n\tif( EnvmapBufferSurface != NULL ) {\n\t\tEnvmapBufferSurface->Release();\n\t\tEnvmapBufferSurface = NULL;\n\t}\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED) || defined(FEATURE_VIDEOFX_IMPROVED)\n\n\tif( PrimaryBufferSurface != NULL ) {\n\t\tPrimaryBufferSurface->Release();\n\t\tPrimaryBufferSurface = NULL;\n\t}\n\n\tif( needToClearTextures )\n\t\tNeedToReloadTextures = false;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nbool __cdecl ApplySettings(APP_SETTINGS *newSettings) {\n\tchar modeString[64] = {0};\n\tAPP_SETTINGS oldSettings = SavedAppSettings;\n\n#if (DIRECT3D_VERSION < 0x900)\n\tRenderFinish(false);\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\tif( newSettings != &SavedAppSettings )\n\t\tSavedAppSettings = *newSettings;\n\n\ttry {\n\t\tRenderStart(false);\n\t}\n\tcatch(...) {\n#if (DIRECT3D_VERSION < 0x900)\n\t\tRenderFinish(false);\n#endif // (DIRECT3D_VERSION < 0x900)\n\t\tSavedAppSettings = oldSettings;\n\t\ttry {\n\t\t\tRenderStart(false);\n\t\t}\n\t\tcatch(...) {\n\t\t\tDISPLAY_MODE_LIST *modeList;\n\t\t\tDISPLAY_MODE_NODE *mode;\n\t\t\tDISPLAY_MODE targetMode;\n\n#if (DIRECT3D_VERSION < 0x900)\n\t\t\tRenderFinish(false);\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\t\t\tSavedAppSettings.PreferredDisplayAdapter = PrimaryDisplayAdapter;\n\t\t\tSavedAppSettings.RenderMode = RM_Software;\n\t\t\tSavedAppSettings.FullScreen = true;\n\t\t\tSavedAppSettings.TripleBuffering = false;\n\n\t\t\ttargetMode.width = 640;\n\t\t\ttargetMode.height = 480;\n\t\t\ttargetMode.bpp = 0;\n#if (DIRECT3D_VERSION < 0x900)\n\t\t\ttargetMode.vga = VGA_NoVga;\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\t\t\tmodeList = &PrimaryDisplayAdapter->body.swDispModeList;\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\t\tif( modeList->head ) {\n\t\t\t\ttargetMode.bpp = modeList->head->body.bpp;\n#if (DIRECT3D_VERSION < 0x900)\n\t\t\t\ttargetMode.vga = modeList->head->body.vga;\n#endif // (DIRECT3D_VERSION < 0x900)\n\t\t\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\tfor( mode = modeList->head; mode; mode = mode->next ) {\n\t\t\t\tif( !CompareVideoModes(&mode->body, &targetMode) )\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tSavedAppSettings.VideoMode = mode ? mode : modeList->tail;\n\t\t\ttry {\n\t\t\t\tRenderStart(false);\n\t\t\t}\n\t\t\tcatch(...) {\n\t\t\t\tS_ExitSystem(\"Can't reinitialise renderer\");\n\t\t\t\treturn false; // the app is terminated here\n\t\t\t}\n\t\t}\n\t}\n\tS_InitialiseScreen(GFL_NOLEVEL);\n\n\tif( SavedAppSettings.RenderMode != oldSettings.RenderMode ) {\n\t\tS_ReloadLevelGraphics(1, 1);\n\t}\n#if (DIRECT3D_VERSION < 0x900)\n\telse if( SavedAppSettings.RenderMode == RM_Software &&\n\t\tSavedAppSettings.FullScreen != oldSettings.FullScreen )\n\t{\n\t\tS_ReloadLevelGraphics(1, 0);\n\t}\n#endif // (DIRECT3D_VERSION < 0x900)\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tsnprintf(modeString, sizeof(modeString), \"%dx%d\", GameVidWidth, GameVidHeight);\n#else // FEATURE_NOLEGACY_OPTIONS\n\tif( SavedAppSettings.FullScreen )\n\t\tsprintf(modeString, \"%dx%dx%d\", GameVidWidth, GameVidHeight, GameVidBPP);\n\telse\n\t\tsprintf(modeString, \"%dx%d\", GameVidWidth, GameVidHeight);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\tDisplayModeInfo(modeString);\n\treturn true;\n}\n\nvoid __cdecl FmvBackToGame() {\n\ttry {\n\t\tRenderStart(true);\n\t}\n\tcatch(...) {\n\t\tDISPLAY_MODE_LIST *modeList;\n\t\tDISPLAY_MODE_NODE *mode;\n\t\tDISPLAY_MODE targetMode;\n\n#if (DIRECT3D_VERSION < 0x900)\n\t\tRenderFinish(false);\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\t\tSavedAppSettings.PreferredDisplayAdapter = PrimaryDisplayAdapter;\n\t\tSavedAppSettings.RenderMode = RM_Software;\n\t\tSavedAppSettings.FullScreen = true;\n\t\tSavedAppSettings.TripleBuffering = false;\n\n\t\ttargetMode.width = 640;\n\t\ttargetMode.height = 480;\n\t\ttargetMode.bpp = 0;\n#if (DIRECT3D_VERSION < 0x900)\n\t\ttargetMode.vga = VGA_NoVga;\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\t\tmodeList = &PrimaryDisplayAdapter->body.swDispModeList;\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\tif( modeList->head ) {\n\t\t\ttargetMode.bpp = modeList->head->body.bpp;\n#if (DIRECT3D_VERSION < 0x900)\n\t\t\ttargetMode.vga = modeList->head->body.vga;\n#endif // (DIRECT3D_VERSION < 0x900)\n\t\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\tfor( mode = modeList->head; mode; mode = mode->next ) {\n\t\t\tif( !CompareVideoModes(&mode->body, &targetMode) )\n\t\t\t\tbreak;\n\t\t}\n\t\tSavedAppSettings.VideoMode = mode ? mode : modeList->tail;\n\t\ttry {\n\t\t\tRenderStart(false);\n\t\t}\n\t\tcatch(...) {\n\t\t\tS_ExitSystem(\"Can't reinitialise renderer\");\n\t\t\treturn; // the app is terminated here\n\t\t}\n\t}\n\t// NOTE: this HWR init was absent in the original code, but must be done here\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tHWR_InitState();\n\t}\n}\n\nvoid __cdecl GameApplySettings(APP_SETTINGS *newSettings) {\n\tbool needInitRenderState = false;\n\tbool needRebuildBuffers = false;\n\tbool needAdjustTexel = false;\n\tDISPLAY_MODE dispMode;\n\n\tif( newSettings->PreferredDisplayAdapter != SavedAppSettings.PreferredDisplayAdapter||\n\t\tnewSettings->PreferredSoundAdapter != SavedAppSettings.PreferredSoundAdapter ||\n\t\tnewSettings->PreferredJoystick != SavedAppSettings.PreferredJoystick )\n\t{\n\t\treturn;\n\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( newSettings->ZBuffer != SavedAppSettings.ZBuffer ||\n\t\tnewSettings->BilinearFiltering != SavedAppSettings.BilinearFiltering )\n\t{\n\t\tchar msg[32] = {0};\n\t\tif( newSettings->ZBuffer != SavedAppSettings.ZBuffer ) {\n\t\t\tsnprintf(msg, sizeof(msg), \"Z Buffer: %s\",\n\t\t\t\tnewSettings->ZBuffer ? GF_SpecificStringTable[SSI_On] : GF_SpecificStringTable[SSI_Off]);\n\t\t} else if( newSettings->BilinearFiltering != SavedAppSettings.BilinearFiltering ) {\n\t\t\tsnprintf(msg, sizeof(msg), \"Bilinear Filter: %s\",\n\t\t\t\tnewSettings->BilinearFiltering ? GF_SpecificStringTable[SSI_On] : GF_SpecificStringTable[SSI_Off]);\n\t\t}\n\t\tif( *msg ) DisplayModeInfo(msg);\n\t\tneedInitRenderState = true;\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( newSettings->PerspectiveCorrect != SavedAppSettings.PerspectiveCorrect ||\n\t\tnewSettings->Dither != SavedAppSettings.Dither ||\n\t\tnewSettings->BilinearFiltering != SavedAppSettings.BilinearFiltering )\n\t{\n\t\tneedInitRenderState = true;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( newSettings->BilinearFiltering != SavedAppSettings.BilinearFiltering ) {\n\t\tneedAdjustTexel = true;\n\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( newSettings->RenderMode != SavedAppSettings.RenderMode ||\n\t\tnewSettings->VideoMode  != SavedAppSettings.VideoMode ||\n\t\tnewSettings->FullScreen != SavedAppSettings.FullScreen )\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( newSettings->RenderMode != SavedAppSettings.RenderMode ||\n\t\tnewSettings->VideoMode  != SavedAppSettings.VideoMode ||\n\t\tnewSettings->FullScreen != SavedAppSettings.FullScreen ||\n\t\tnewSettings->ZBuffer    != SavedAppSettings.ZBuffer ||\n\t\tnewSettings->TripleBuffering != SavedAppSettings.TripleBuffering )\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t{\n\t\tApplySettings(newSettings);\n\t\tS_AdjustTexelCoordinates();\n\t\treturn;\n\t}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tif( newSettings->LightingMode != SavedAppSettings.LightingMode ) {\n\t\tconst char *levels[3] = {\n\t\t\t\"Low\",\n\t\t\t\"Medium\",\n\t\t\t\"High\",\n\t\t};\n\t\tchar msg[32] = {0};\n\t\tsnprintf(msg, sizeof(msg), \"Lighting Contrast: %s\", levels[newSettings->LightingMode]);\n\t\tDisplayModeInfo(msg);\n\t\tneedInitRenderState = true;\n\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\n\tif( !newSettings->FullScreen ) {\n\t\tif( newSettings->WindowWidth != SavedAppSettings.WindowWidth || newSettings->WindowHeight != SavedAppSettings.WindowHeight ) {\n\t\t\tif( !WinVidGoWindowed(newSettings->WindowWidth, newSettings->WindowHeight, &dispMode) ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tnewSettings->WindowWidth  = dispMode.width;\n\t\t\tnewSettings->WindowHeight = dispMode.height;\n\t\t\tif( dispMode.width != SavedAppSettings.WindowWidth || dispMode.height != SavedAppSettings.WindowHeight ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tneedRebuildBuffers = true;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\t\t\tif( GameVidBufWidth < dispMode.width || GameVidBufWidth - dispMode.width > 0x40 ||\n\t\t\t\t\tGameVidBufHeight < dispMode.height || GameVidBufHeight - dispMode.height > 0x40 )\n\t\t\t\t{\n\t\t\t\t\tneedRebuildBuffers = true;\n\t\t\t\t} else {\n\t\t\t\t\tSavedAppSettings.WindowWidth  = dispMode.width;\n\t\t\t\t\tSavedAppSettings.WindowHeight = dispMode.height;\n\t\t\t\t\tGameVidWidth  = dispMode.width;\n\t\t\t\t\tGameVidHeight = dispMode.height;\n\t\t\t\t\tGameVidRect.right  = dispMode.width;\n\t\t\t\t\tGameVidRect.bottom = dispMode.height;\n\t\t\t\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\t\t\t\tD3DSetViewport();\n\t\t\t\t\t}\n\t\t\t\t\tsetup_screen_size();\n\t\t\t\t\tWinVidNeedToResetBuffers = false;\n\t\t\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t\t}\n\t\t}\n\t}\n\n\tif( needInitRenderState ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tSavedAppSettings.ZBuffer = newSettings->ZBuffer;\n\t\tSavedAppSettings.BilinearFiltering = newSettings->BilinearFiltering;\n\t\tsetup_screen_size();\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tSavedAppSettings.PerspectiveCorrect = newSettings->PerspectiveCorrect;\n\t\tSavedAppSettings.Dither = newSettings->Dither;\n\t\tSavedAppSettings.BilinearFiltering = newSettings->BilinearFiltering;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\tSavedAppSettings.LightingMode = newSettings->LightingMode;\n\t\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\t\textern void UpdateDepthQ(bool isReset);\n\t\t\tUpdateDepthQ(false);\n\t\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\tHWR_InitState();\n\t\t}\n\t}\n\n\tif( needRebuildBuffers ) {\n\t\tClearBuffers(CLRB_WindowedPrimaryBuffer, 0);\n\t\tApplySettings(newSettings);\n\t}\n\n\tif( needAdjustTexel ) {\n\t\tS_AdjustTexelCoordinates();\n\t}\n}\n\nvoid __cdecl UpdateGameResolution() {\n\tAPP_SETTINGS newSettings = SavedAppSettings;\n\tchar modeString[64] = {0};\n\n\tnewSettings.WindowWidth  = GameWindowWidth;\n\tnewSettings.WindowHeight = GameWindowHeight;\n\tGameApplySettings(&newSettings);\n\n\tsprintf(modeString, \"%dx%d\", GameVidWidth, GameVidHeight);\n\tDisplayModeInfo(modeString);\n}\n\nLPCTSTR __cdecl DecodeErrorMessage(DWORD errorCode) {\n\treturn ErrorStringTable[errorCode];\n}\n\n/*\n * Inject function\n */\nvoid Inject_InitDisplay() {\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x004484E0, CreateScreenBuffers);\n\tINJECT(0x00448620, CreatePrimarySurface);\n\tINJECT(0x004486C0, CreateBackBuffer);\n\tINJECT(0x00448760, CreateClipper);\n\tINJECT(0x00448800, CreateWindowPalette);\n\tINJECT(0x004488E0, CreateZBuffer);\n\tINJECT(0x004489A0, GetZBufferDepth);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x004489D0, CreateRenderBuffer);\n\tINJECT(0x00448A80, CreatePictureBuffer);\n\tINJECT(0x00448AF0, ClearBuffers);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00448CA0, RestoreLostBuffers);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00448DE0, UpdateFrame);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00448EB0, WaitPrimaryBufferFlip);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00448EF0, RenderInit);\n\tINJECT(0x00448F00, RenderStart);\n\tINJECT(0x004492B0, RenderFinish);\n\tINJECT(0x004493A0, ApplySettings);\n\tINJECT(0x004495B0, FmvBackToGame);\n\tINJECT(0x004496C0, GameApplySettings);\n\tINJECT(0x00449900, UpdateGameResolution);\n\tINJECT(0x00449970, DecodeErrorMessage);\n}\n"
  },
  {
    "path": "specific/init_display.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef INIT_DISPLAY_H_INCLUDED\n#define INIT_DISPLAY_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl CreateScreenBuffers(); // 0x004484E0\nvoid __cdecl CreatePrimarySurface(); // 0x00448620\nvoid __cdecl CreateBackBuffer(); // 0x004486C0\nvoid __cdecl CreateClipper(); // 0x00448760\nvoid __cdecl CreateWindowPalette(); // 0x00448800\nvoid __cdecl CreateZBuffer(); // 0x004488E0\nDWORD __cdecl GetZBufferDepth(); // 0x004489A0\n#endif // (DIRECT3D_VERSION < 0x900)\nvoid __cdecl CreateRenderBuffer(); // 0x004489D0\nvoid __cdecl CreatePictureBuffer(); // 0x00448A80\nvoid __cdecl ClearBuffers(DWORD flags, DWORD fillColor); // 0x00448AF0\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl RestoreLostBuffers(); // 0x00448CA0\n#endif // (DIRECT3D_VERSION < 0x900)\nvoid __cdecl UpdateFrame(bool needRunMessageLoop, LPRECT rect); // 0x00448DE0\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl WaitPrimaryBufferFlip(); // 0x00448EB0\n#endif // (DIRECT3D_VERSION < 0x900)\nbool __cdecl RenderInit(); // 0x00448EF0\nvoid __cdecl RenderStart(bool isReset); // 0x00448F00\nvoid __cdecl RenderFinish(bool needToClearTextures); // 0x004492B0\nbool __cdecl ApplySettings(APP_SETTINGS *newSettings); // 0x004493A0\nvoid __cdecl FmvBackToGame(); // 0x004495B0\nvoid __cdecl GameApplySettings(APP_SETTINGS *newSettings); // 0x004496C0\nvoid __cdecl UpdateGameResolution(); // 0x00449900\nLPCTSTR __cdecl DecodeErrorMessage(DWORD errorCode); // 0x00449970\n\n#endif // INIT_DISPLAY_H_INCLUDED\n"
  },
  {
    "path": "specific/init_input.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/init_input.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/xinput_ex.h\"\n#include \"modding/raw_input.h\"\n#include \"modding/joy_output.h\"\n#define HAS_AXIS(x) (JoyRanges[x].lMax != JoyRanges[x].lMin)\n\ntypedef enum {\n\tJoyX,\n\tJoyY,\n\tJoyZ,\n\tJoyRX,\n\tJoyRY,\n\tJoyRZ,\n\tJoyAxisNumber,\n} JOY_AXIS_ENUM;\n\ntypedef struct {\n\tlong lMin;\n\tlong lMax;\n} JOY_AXIS_RANGE;\n\nstatic bool IsRawInput = false;\nstatic int XInputIndex = -1;\nstatic XINPUT_CAPABILITIES XInputCaps;\nstatic DIDEVCAPS JoyCaps;\nstatic JOY_AXIS_RANGE JoyRanges[JoyAxisNumber];\n\nbool JoystickVibrationEnabled = true;\nbool JoystickLedColorEnabled = true;\n\nBOOL CALLBACK DInputEnumJoystickAxisCallback(LPCDIDEVICEOBJECTINSTANCE pdidoi, LPVOID pContext) {\n\tif( !pdidoi || !pContext ) {\n\t\treturn DIENUM_CONTINUE;\n\t}\n\n\tDIPROPRANGE prop;\n\tprop.diph.dwSize = sizeof(prop);\n\tprop.diph.dwHeaderSize = sizeof(prop.diph);\n\tprop.diph.dwHow = DIPH_BYOFFSET;\n\tprop.diph.dwObj = pdidoi->dwOfs;\n\tif( FAILED( IDID_SysJoystick->GetProperty(DIPROP_RANGE, &prop.diph) ) ) {\n\t\treturn DIENUM_CONTINUE;\n\t}\n\n\tDWORD axisOfs[JoyAxisNumber] = {\n\t\tDIJOFS_X, DIJOFS_Y, DIJOFS_Z,\n\t\tDIJOFS_RX, DIJOFS_RY, DIJOFS_RZ,\n\t};\n\n\tJOY_AXIS_RANGE *axisRanges = (JOY_AXIS_RANGE *)pContext;\n\tfor( int i=0; i<JoyAxisNumber; ++i ) {\n\t\tif( pdidoi->dwOfs == axisOfs[i] ) {\n\t\t\taxisRanges[i].lMin = prop.lMin;\n\t\t\taxisRanges[i].lMax = prop.lMax;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn DIENUM_CONTINUE;\n}\n\nstatic BOOL CALLBACK RawInputCallBack(LPGUID lpGuid, LPCTSTR lpDeviceName, LPCTSTR lpProductName, WORD vid, WORD pid, LPVOID lpContext) {\n\tif( lpGuid == NULL || lpDeviceName == NULL || lpProductName == NULL || lpContext == NULL || IsXInputDevice(vid, pid) )\n\t\treturn TRUE;\n\n\tJOYSTICK_LIST *joyList = (JOYSTICK_LIST *)lpContext;\n\tJOYSTICK_NODE *joyNode = new JOYSTICK_NODE;\n\n\tif( joyNode == NULL )\n\t\treturn TRUE;\n\n\tjoyNode->next = NULL;\n\tjoyNode->previous = joyList->tail;\n\n\tif( !joyList->head )\n\t\tjoyList->head = joyNode;\n\n\tif( joyList->tail )\n\t\tjoyList->tail->next = joyNode;\n\n\tjoyList->tail = joyNode;\n\tjoyList->dwCount++;\n\n\tjoyNode->body.joystickGuid = *lpGuid;\n\tjoyNode->body.lpJoystickGuid = &joyNode->body.joystickGuid;\n\tFlaggedStringCreate(&joyNode->body.productName, strlen(lpProductName)+1);\n\tFlaggedStringCreate(&joyNode->body.instanceName, strlen(lpDeviceName)+1);\n\tlstrcpy(joyNode->body.productName.lpString, lpProductName);\n\tlstrcpy(joyNode->body.instanceName.lpString, lpDeviceName);\n\tjoyNode->body.iface = JOY_RawInput;\n\treturn TRUE;\n}\n\nvoid SetJoystickOutput(WORD leftMotor, WORD rightMotor, DWORD ledColor) {\n\tstatic DWORD leftMotorOld = ~0;\n\tstatic DWORD rightMotorOld = ~0;\n\tstatic DWORD ledColorOld = ~0;\n\tif( !SavedAppSettings.JoystickEnabled\n\t\t|| (leftMotor == leftMotorOld && rightMotor == rightMotorOld && ledColor == ledColorOld) )\n\t{\n\t\treturn;\n\t}\n\tbool result = true;\n\n\tif( XInputIndex >= 0 ) {\n\t\tXINPUT_VIBRATION vibration;\n\t\tvibration.wLeftMotorSpeed  = leftMotor;\n\t\tvibration.wRightMotorSpeed = rightMotor;\n\t\tXInputEnable(TRUE);\n\t\tresult = (ERROR_SUCCESS == XInputSetState(XInputIndex, &vibration));\n\t} else if( IsRawInput ) {\n\t\tresult = RawInputSetState(leftMotor, rightMotor, ledColor);\n\t}\n\n\tif( result ) {\n\t\tleftMotorOld = leftMotor;\n\t\trightMotorOld = rightMotor;\n\t\tledColorOld = ledColor;\n\t}\n}\n\nJOYTYPE GetJoystickType() {\n\tif( SavedAppSettings.JoystickEnabled && SavedAppSettings.PreferredJoystick ) {\n\t\tif( IsRawInput ) {\n\t\t\treturn JT_PLAYSTATION;\n\t\t}\n\t\tif( XInputIndex >= 0 ) {\n\t\t\treturn JT_XINPUT;\n\t\t}\n\t\tif( IDID_SysJoystick != NULL ) {\n\t\t\treturn JT_DIRECTINPUT;\n\t\t}\n\t}\n\treturn JT_NONE;\n}\n\nbool IsJoyVibrationSupported() {\n\tif( IsRawInput ) {\n\t\treturn true;\n\t}\n\tif( XInputIndex >= 0 ) {\n\t\treturn( XInputCaps.Vibration.wLeftMotorSpeed || XInputCaps.Vibration.wLeftMotorSpeed );\n\t}\n\treturn false;\n}\n\nbool IsJoyLedColorSupported() {\n\treturn IsRawInput;\n}\n\nbool IsJoyVibrationEnabled() {\n\treturn SavedAppSettings.JoystickEnabled && JoystickVibrationEnabled && IsJoyVibrationSupported();\n}\n\nbool IsJoyLedColorEnabled() {\n\treturn SavedAppSettings.JoystickEnabled && JoystickLedColorEnabled && IsJoyLedColorSupported();\n}\n#endif // FEATURE_INPUT_IMPROVED\n\nextern void __thiscall FlaggedStringDelete(STRING_FLAGGED *item);\nextern bool FlaggedStringCopy(STRING_FLAGGED *dst, STRING_FLAGGED *src);\n\nbool __cdecl DInputCreate() {\n#if (DIRECTINPUT_VERSION >= 0x800)\n\treturn SUCCEEDED(DirectInput8Create(GameModule, DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID *)&DInput, NULL));\n#else // (DIRECTINPUT_VERSION >= 0x800)\n\treturn SUCCEEDED(DirectInputCreate(GameModule, DIRECTINPUT_VERSION, &DInput, NULL));\n#endif // (DIRECTINPUT_VERSION >= 0x800)\n}\n\nvoid __cdecl DInputRelease() {\n\tif( DInput != NULL ) {\n\t\tDInput->Release();\n\t\tDInput = NULL;\n\t}\n}\n\nvoid __cdecl WinInReadKeyboard(LPVOID lpInputData) {\n\t// NOTE: the original code did check only DIERR_INPUTLOST. Any FAILED state must be check to call Acquire\n\twhile FAILED(IDID_SysKeyboard->GetDeviceState(256, lpInputData)) {\n\t\tif FAILED(IDID_SysKeyboard->Acquire()) {\n\t\t\tmemset(lpInputData, 0, 256);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\n#ifdef FEATURE_INPUT_IMPROVED\nstatic void PovToPos(int *xPos, int *yPos, DWORD pov) {\n\tint x=0, y=0;\n\t// Check if D-PAD is not centered\n\tif( LOWORD(pov) != 0xFFFF ) {\n\t\t// We need here cyclic quadrilateral with a side 32.\n\t\t// The radius of circumscribed circle is approx 23 = 16 * SQRT(2)\n\t\tx = +23 * phd_sin(pov * PHD_360 / 36000) / PHD_IONE;\n\t\ty = -23 * phd_cos(pov * PHD_360 / 36000) / PHD_IONE;\n\t\tCLAMP(x, -16, 16);\n\t\tCLAMP(y, -16, 16);\n\t}\n\tif( xPos ) *xPos = x;\n\tif( yPos ) *yPos = y;\n}\n\nstatic int SelectJoyDirection(int dp, int ls, int rs, int threshold) {\n\t// D-Pad has priority\n\tif( ABS(dp) > threshold ) return dp;\n\t// if sticks have opposite directions, just sum them\n\tif( (ls^rs) < 0 ) return ls + rs;\n\t// or just select the one with max value\n\tif( ABS(rs) > ABS(ls) ) return rs;\n\treturn ls;\n}\n\nstatic DWORD XInputReadJoystick(int *xPos, int *yPos) {\n\tif( !xPos || !yPos || XInputIndex < 0 ) return 0;\n\t*xPos = *yPos = 0;\n\tDWORD buttonStatus = 0;\n\tXINPUT_STATE state;\n\n\tXInputEnable(TRUE);\n\tif( ERROR_SUCCESS != XInputGetState(XInputIndex, &state) ) {\n\t\treturn 0;\n\t}\n\n\tint dx=0, dy=0, lx=0, ly=0, rx=0, ry=0;\n\tif( XINPUT_DPAD(XInputCaps.Gamepad.wButtons) ) {\n\t\tdx += CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_RIGHT) ? 16 : 0;\n\t\tdx -= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_LEFT) ? 16 : 0;\n\t\tdy += CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_DOWN) ? 16 : 0;\n\t\tdy -= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_DPAD_UP) ? 16 : 0;\n\t}\n\tif( XInputCaps.Gamepad.sThumbLX && XInputCaps.Gamepad.sThumbLY ) {\n\t\tlx = 16 * state.Gamepad.sThumbLX / 0x8000;\n\t\tly = -16 * state.Gamepad.sThumbLY / 0x8000;\n\t}\n\tif( XInputCaps.Gamepad.sThumbRX && XInputCaps.Gamepad.sThumbRY ) {\n\t\trx = 16 * state.Gamepad.sThumbRX / 0x8000;\n\t\try = -16 * state.Gamepad.sThumbRY / 0x8000;\n\t}\n\t*xPos = SelectJoyDirection(dx, lx, rx, 8);\n\t*yPos = SelectJoyDirection(dy, ly, ry, 8);\n\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_Y) ? 0x001 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_B) ? 0x002 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_A) ? 0x004 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_X) ? 0x008 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_LEFT_SHOULDER) ? 0x010 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_RIGHT_SHOULDER) ? 0x020 : 0;\n\tbuttonStatus |= (state.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) ? 0x040 : 0;\n\tbuttonStatus |= (state.Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) ? 0x080 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_BACK) ? 0x100 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_START) ? 0x200 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_LEFT_THUMB) ? 0x400 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_RIGHT_THUMB) ? 0x800 : 0;\n\tbuttonStatus |= CHK_ANY(state.Gamepad.wButtons, XINPUT_GAMEPAD_GUIDE) ? 0x1000 : 0;\n\treturn buttonStatus;\n}\n\nstatic DWORD RawInputReadJoystick(int *xPos, int *yPos) {\n\tif( !xPos || !yPos || !IsRawInput ) return 0;\n\t*xPos = *yPos = 0;\n\tDWORD buttonStatus = 0;\n\tRINPUT_STATE state;\n\n\tif( !RawInputGetState(&state) ) {\n\t\treturn 0;\n\t}\n\n\tint dx=0, dy=0, lx=0, ly=0, rx=0, ry=0;\n\tPovToPos(&dx, &dy, state.dPad);\n\tlx = (int)(+16.0 * state.axisLX);\n\tly = (int)(-16.0 * state.axisLY);\n\trx = (int)(+16.0 * state.axisRX);\n\try = (int)(-16.0 * state.axisRY);\n\t*xPos = SelectJoyDirection(dx, lx, rx, 8);\n\t*yPos = SelectJoyDirection(dy, ly, ry, 8);\n\n\tbuttonStatus |= state.btnTriangle ? 0x0001 : 0;\n\tbuttonStatus |= state.btnCircle ? 0x0002 : 0;\n\tbuttonStatus |= state.btnCross ? 0x0004 : 0;\n\tbuttonStatus |= state.btnSquare ? 0x0008 : 0;\n\tbuttonStatus |= state.btnL1 ? 0x0010 : 0;\n\tbuttonStatus |= state.btnR1 ? 0x0020 : 0;\n\tbuttonStatus |= state.btnL2 ? 0x0040 : 0;\n\tbuttonStatus |= state.btnR2 ? 0x0080 : 0;\n\tbuttonStatus |= state.btnShare ? 0x0100 : 0;\n\tbuttonStatus |= state.btnOptions ? 0x0200 : 0;\n\tbuttonStatus |= state.btnL3 ? 0x0400 : 0;\n\tbuttonStatus |= state.btnR3 ? 0x0800 : 0;\n\tbuttonStatus |= state.btnPS ? 0x1000 : 0;\n\tbuttonStatus |= state.btnTouch ? 0x2000 : 0;\n\treturn buttonStatus;\n}\n\nstatic DWORD DInputReadJoystick(int *xPos, int *yPos) {\n\tif( !xPos || !yPos || !IDID_SysJoystick ) return 0;\n\t*xPos = *yPos = 0;\n\tDWORD buttonStatus = 0;\n\tDIJOYSTATE joyState;\n\n#if (DIRECTINPUT_VERSION >= 0x800)\n\twhile( FAILED(IDID_SysJoystick->Poll()) || FAILED(IDID_SysJoystick->GetDeviceState(sizeof(joyState), &joyState)) )\n#else // (DIRECTINPUT_VERSION >= 0x800)\n\twhile( FAILED(IDID_SysJoystick->GetDeviceState(sizeof(joyState), &joyState)) )\n#endif // (DIRECTINPUT_VERSION >= 0x800)\n\t{\n\t\tif FAILED(IDID_SysJoystick->Acquire()) return 0;\n\t}\n\n\tint dx=0, dy=0, lx=0, ly=0, rx=0, ry=0;\n\tif( JoyCaps.dwPOVs ) {\n\t\tPovToPos(&dx, &dy, joyState.rgdwPOV[0]);\n\t}\n\tif( HAS_AXIS(JoyX) && HAS_AXIS(JoyY) ) {\n\t\tlx = 32 * joyState.lX / (JoyRanges[JoyX].lMax - JoyRanges[JoyX].lMin) - 16;\n\t\tly = 32 * joyState.lY / (JoyRanges[JoyY].lMax - JoyRanges[JoyY].lMin) - 16;\n\t}\n\tif( HAS_AXIS(JoyZ) && HAS_AXIS(JoyRZ) ) {\n\t\trx = 32 * joyState.lZ  / (JoyRanges[JoyZ].lMax  - JoyRanges[JoyZ].lMin)  - 16;\n\t\try = 32 * joyState.lRz / (JoyRanges[JoyRZ].lMax - JoyRanges[JoyRZ].lMin) - 16;\n\t} else if( HAS_AXIS(JoyRX) && HAS_AXIS(JoyRY) ) {\n\t\trx = 32 * joyState.lRx / (JoyRanges[JoyRX].lMax - JoyRanges[JoyRX].lMin) - 16;\n\t\try = 32 * joyState.lRy / (JoyRanges[JoyRY].lMax - JoyRanges[JoyRY].lMin) - 16;\n\t}\n\t*xPos = SelectJoyDirection(dx, lx, rx, 8);\n\t*yPos = SelectJoyDirection(dy, ly, ry, 8);\n\n\tfor( DWORD i=0; i<MIN(JoyCaps.dwButtons, 32); ++i ) {\n\t\tbuttonStatus |= CHK_ANY(joyState.rgbButtons[i], 0x80) ? 1<<i : 0;\n\t}\n\treturn buttonStatus;\n}\n#endif // FEATURE_INPUT_IMPROVED\n\nDWORD __cdecl WinInReadJoystick(int *xPos, int *yPos) {\n#ifdef FEATURE_INPUT_IMPROVED\n\t*yPos = 0;\n\t*xPos = 0;\n\tif( !SavedAppSettings.JoystickEnabled ) return 0;\n\tswitch( GetJoystickType() ) {\n\t\tcase JT_XINPUT:\n\t\t\treturn XInputReadJoystick(xPos, yPos);\n\t\tcase JT_PLAYSTATION:\n\t\t\treturn RawInputReadJoystick(xPos, yPos);\n\t\tcase JT_DIRECTINPUT:\n\t\t\treturn DInputReadJoystick(xPos, yPos);\n\t\tcase JT_NONE:\n\t\t\tbreak;\n\t}\n\treturn 0;\n#else // FEATURE_INPUT_IMPROVED\n\tstatic bool joyNeedCaps = true;\n\tstatic JOYCAPS joyCaps;\n\n\tif( SavedAppSettings.JoystickEnabled ) {\n\t\tif( joyNeedCaps && JOYERR_NOERROR == joyGetDevCaps(0, &joyCaps, sizeof(JOYCAPS)) ) {\n\t\t\tjoyNeedCaps = false;\n\t\t}\n\n\t\tif( !joyNeedCaps ) {\n\t\t\tJOYINFOEX joyInfo;\n\n\t\t\tjoyInfo.dwSize = sizeof(JOYINFOEX);\n\t\t\tjoyInfo.dwFlags = JOY_RETURNBUTTONS|JOY_RETURNX|JOY_RETURNY;\n\n\t\t\tif( JOYERR_NOERROR == joyGetPosEx(0, &joyInfo) ) {\n\t\t\t\t*xPos = 32 * joyInfo.dwXpos / (joyCaps.wXmax - joyCaps.wXmin) - 16;\n\t\t\t\t*yPos = 32 * joyInfo.dwYpos / (joyCaps.wYmax - joyCaps.wYmin) - 16;\n\t\t\t\treturn joyInfo.dwButtons;\n\t\t\t}\n\n\t\t\tjoyNeedCaps = true;\n\t\t}\n\t}\n\t*yPos = 0;\n\t*xPos = 0;\n#endif // FEATURE_INPUT_IMPROVED\n\treturn 0;\n}\n\nbool __cdecl WinInputInit() {\n\tJOYSTICK_NODE *node, *nextNode;\n\tbool result;\n\n\tfor( node = JoystickList.head; node; node = nextNode ) {\n\t\tnextNode = node->next;\n\t\tFlaggedStringDelete(&node->body.productName);\n\t\tFlaggedStringDelete(&node->body.instanceName);\n\t\tdelete(node);\n\t}\n\n\tJoystickList.head = NULL;\n\tJoystickList.tail = NULL;\n\tJoystickList.dwCount = 0;\n\n\tif( !DInputCreate() )\n\t\treturn false;\n\n\tresult = DInputEnumDevices(&JoystickList);\n\tDInputRelease();\n\n\treturn result;\n}\n\nbool __cdecl DInputEnumDevices(JOYSTICK_LIST *joystickList) {\n#ifdef FEATURE_INPUT_IMPROVED\n\tfor( DWORD i = 0; i < XUSER_MAX_COUNT; ++i ) {\n\t\tXINPUT_STATE state;\n\t\tmemset(&state, 0, sizeof(state));\n\t\tif( ERROR_SUCCESS != XInputGetState(i, &state) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tJOYSTICK_NODE *joyNode = new JOYSTICK_NODE;\n\t\tif( joyNode == NULL ) {\n\t\t\tcontinue;\n\t\t}\n\t\tjoyNode->next = NULL;\n\t\tjoyNode->previous = joystickList->tail;\n\t\tif( !joystickList->head ) {\n\t\t\tjoystickList->head = joyNode;\n\t\t}\n\t\tif( joystickList->tail ) {\n\t\t\tjoystickList->tail->next = joyNode;\n\t\t}\n\t\tjoystickList->tail = joyNode;\n\t\tjoystickList->dwCount++;\n\t\tmemset(&joyNode->body.joystickGuid, 0, sizeof(GUID));\n\t\tjoyNode->body.joystickGuid.Data4[7] = i;\n\t\tjoyNode->body.lpJoystickGuid = &joyNode->body.joystickGuid;\n\t\tFlaggedStringCreate(&joyNode->body.productName, 256);\n\t\tFlaggedStringCreate(&joyNode->body.instanceName, 256);\n\t\tsnprintf(joyNode->body.productName.lpString, 256, \"XInput Controller %lu\", i+1);\n\t\tjoyNode->body.iface = JOY_XInput;\n\t}\n\tRawInputEnumerate(RawInputCallBack, (LPVOID)joystickList);\n#endif // FEATURE_INPUT_IMPROVED\n\treturn SUCCEEDED(DInput->EnumDevices(DIDEVTYPE_JOYSTICK, DInputEnumDevicesCallback, (LPVOID)joystickList, DIEDFL_ATTACHEDONLY));\n}\n\nBOOL CALLBACK DInputEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) {\n\tif( lpddi == NULL || pvRef == NULL ) {\n\t\treturn DIENUM_CONTINUE;\n\t}\n\n#ifdef FEATURE_INPUT_IMPROVED\n\tDWORD vid = LOWORD(lpddi->guidProduct.Data1);\n\tDWORD pid = HIWORD(lpddi->guidProduct.Data1);\n\tif( GetRawInputName(vid, pid, FALSE) || IsXInputDevice(vid, pid) ) {\n\t\treturn DIENUM_CONTINUE;\n\t}\n#endif // FEATURE_INPUT_IMPROVED\n\n\tJOYSTICK_LIST *joyList = (JOYSTICK_LIST *)pvRef;\n\tJOYSTICK_NODE *joyNode = new JOYSTICK_NODE;\n\n\tif( joyNode == NULL )\n\t\treturn DIENUM_CONTINUE;\n\n\tjoyNode->next = NULL;\n\tjoyNode->previous = joyList->tail;\n\n\tif( !joyList->head )\n\t\tjoyList->head = joyNode;\n\n\tif( joyList->tail )\n\t\tjoyList->tail->next = joyNode;\n\n\tjoyList->tail = joyNode;\n\tjoyList->dwCount++;\n\n\tjoyNode->body.joystickGuid = lpddi->guidInstance;\n\tjoyNode->body.lpJoystickGuid = &joyNode->body.joystickGuid;\n\tFlaggedStringCreate(&joyNode->body.productName, 256);\n\tFlaggedStringCreate(&joyNode->body.instanceName, 256);\n\tlstrcpy(joyNode->body.productName.lpString, lpddi->tszProductName);\n\tlstrcpy(joyNode->body.instanceName.lpString, lpddi->tszInstanceName);\n#ifdef FEATURE_INPUT_IMPROVED\n\tjoyNode->body.iface = JOY_DirectInput;\n#endif // FEATURE_INPUT_IMPROVED\n\n\treturn DIENUM_CONTINUE;\n}\n\nvoid __thiscall FlaggedStringCreate(STRING_FLAGGED *item, DWORD dwSize) {\n\titem->lpString = new char[dwSize];\n\n\tif( item->lpString != NULL ) {\n\t\t*item->lpString = 0;\n\t\titem->isPresented = true;\n\t}\n}\n\nJOYSTICK_NODE *__cdecl GetJoystick(GUID *lpGuid) {\n\tJOYSTICK_NODE *joystick;\n\n\tif( JoystickList.dwCount == 0 )\n\t\treturn NULL;\n\n\tif( lpGuid != NULL ) {\n\t\tfor( joystick = JoystickList.head; joystick; joystick = joystick->next ) {\n\t\t\tif( !memcmp(&joystick->body.joystickGuid, lpGuid, sizeof(GUID)) )\n\t\t\t\treturn joystick;\n\t\t}\n\t}\n\treturn JoystickList.head;\n}\n\nvoid __cdecl DInputKeyboardCreate() {\n\tif FAILED(DInput->CreateDevice(GUID_SysKeyboard, &IDID_SysKeyboard, NULL))\n\t\tthrow ERR_CantCreateKeyboardDevice;\n\tif FAILED(IDID_SysKeyboard->SetCooperativeLevel(HGameWindow, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE))\n\t\tthrow ERR_CantSetKBCooperativeLevel;\n\tif FAILED(IDID_SysKeyboard->SetDataFormat(&c_dfDIKeyboard))\n\t\tthrow ERR_CantSetKBDataFormat;\n\n\t// NOTE: there is no DIERR_OTHERAPPHASPRIO check in the original code\n\tHRESULT res = IDID_SysKeyboard->Acquire();\n\tif( !SUCCEEDED(res) && res != DIERR_OTHERAPPHASPRIO )\n\t\tthrow ERR_CantAcquireKeyboard;\n}\n\nvoid __cdecl DInputKeyboardRelease() {\n\tif( IDID_SysKeyboard != NULL ) {\n\t\tIDID_SysKeyboard->Unacquire();\n\t\tIDID_SysKeyboard->Release();\n\t\tIDID_SysKeyboard = NULL;\n\t}\n}\n\nbool __cdecl DInputJoystickCreate() {\n\tif( SavedAppSettings.PreferredJoystick == NULL )\n\t\treturn true;\n\n\tJOYSTICK *preferred = &SavedAppSettings.PreferredJoystick->body;\n\tCurrentJoystick = *preferred;\n\n\tFlaggedStringCopy(&CurrentJoystick.productName, &preferred->productName);\n\tFlaggedStringCopy(&CurrentJoystick.instanceName, &preferred->instanceName);\n#ifdef FEATURE_INPUT_IMPROVED\n\tXInputIndex = -1;\n\tmemset(&XInputCaps, 0, sizeof(XInputCaps));\n\tGUID *guid = &CurrentJoystick.joystickGuid;\n\tif( CurrentJoystick.iface == JOY_XInput ) {\n\t\tif( ERROR_SUCCESS != XInputGetCapabilities(guid->Data4[7], 0, &XInputCaps) ) {\n\t\t\treturn false;\n\t\t}\n\t\tXInputIndex = guid->Data4[7];\n\t\treturn true;\n\t}\n\tif( CurrentJoystick.iface == JOY_RawInput ) {\n\t\tIsRawInput = RawInputStart(CurrentJoystick.instanceName.lpString);\n\t\treturn IsRawInput;\n\t}\n\tmemset(JoyRanges, 0, sizeof(JoyRanges));\n\tmemset(&JoyCaps, 0, sizeof(JoyCaps));\n\tJoyCaps.dwSize = sizeof(JoyCaps);\n\tif FAILED(DInput->CreateDevice(CurrentJoystick.joystickGuid, &IDID_SysJoystick, NULL))\n\t\treturn false;\n\tif FAILED(IDID_SysJoystick->SetCooperativeLevel(HGameWindow, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE))\n\t\treturn false;\n\tif FAILED(IDID_SysJoystick->SetDataFormat(&c_dfDIJoystick))\n\t\treturn false;\n\tif FAILED(IDID_SysJoystick->GetCapabilities(&JoyCaps))\n\t\treturn false;\n\tif FAILED(IDID_SysJoystick->EnumObjects(DInputEnumJoystickAxisCallback, (LPVOID)JoyRanges, DIDFT_AXIS))\n\t\treturn false;\n\n\tHRESULT res = IDID_SysJoystick->Acquire();\n\tif( !SUCCEEDED(res) && res != DIERR_OTHERAPPHASPRIO )\n\t\treturn false;\n#endif // FEATURE_INPUT_IMPROVED\n\n\treturn true;\n}\n\nvoid __cdecl DInputJoystickRelease() {\n#ifdef FEATURE_INPUT_IMPROVED\n\tSetJoystickOutput(0, 0, DEFAULT_JOYSTICK_LED_COLOR);\n\tRawInputStop();\n\tIsRawInput = false;\n\tXInputEnable(FALSE);\n\tXInputIndex = -1;\n#endif // FEATURE_INPUT_IMPROVED\n\tif( IDID_SysJoystick != NULL ) {\n\t\tIDID_SysJoystick->Unacquire();\n\t\tIDID_SysJoystick->Release();\n\t\tIDID_SysJoystick = NULL;\n\t}\n}\n\nvoid __cdecl WinInStart() {\n\tif( !DInputCreate() )\n\t\tthrow ERR_CantCreateDirectInput;\n\n\tDInputKeyboardCreate();\n\tDInputJoystickCreate();\n}\n\nvoid __cdecl WinInFinish() {\n\tDInputJoystickRelease();\n\tDInputKeyboardRelease();\n\tDInputRelease();\n}\n\nvoid __cdecl WinInRunControlPanel(HWND hWnd) {\n\tif( DInput != NULL ) {\n#ifdef FEATURE_INPUT_IMPROVED\n\t\tJOYSTICK *preferred = &ChangedAppSettings.PreferredJoystick->body;\n\t\tif SUCCEEDED(DInput->CreateDevice(preferred->joystickGuid, &IDID_SysJoystick, NULL))\n\t\t{\n\t\t\tIDID_SysJoystick->RunControlPanel(hWnd, 0);\n\t\t\tIDID_SysJoystick->Release();\n\t\t\tIDID_SysJoystick = NULL;\n\t\t\treturn;\n\t\t}\n#endif // FEATURE_INPUT_IMPROVED\n\t\tDInput->RunControlPanel(hWnd, 0);\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_InitInput() {\n\tINJECT(0x004472A0, DInputCreate);\n\tINJECT(0x004472D0, DInputRelease);\n\tINJECT(0x004472F0, WinInReadKeyboard);\n\tINJECT(0x00447350, WinInReadJoystick);\n\tINJECT(0x00447460, WinInputInit);\n\tINJECT(0x004474E0, DInputEnumDevices);\n\tINJECT(0x00447510, DInputEnumDevicesCallback);\n\tINJECT(0x00447600, FlaggedStringCreate);\n\tINJECT(0x00447620, GetJoystick);\n\tINJECT(0x00447670, DInputKeyboardCreate);\n\tINJECT(0x00447740, DInputKeyboardRelease);\n\tINJECT(0x00447770, DInputJoystickCreate);\n//\tINJECT(----------, DInputJoystickRelease);\n\tINJECT(0x00447860, WinInStart);\n\tINJECT(0x00447890, WinInFinish);\n\tINJECT(0x004478A0, WinInRunControlPanel);\n}\n"
  },
  {
    "path": "specific/init_input.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef INIT_INPUT_H_INCLUDED\n#define INIT_INPUT_H_INCLUDED\n\n#include \"global/types.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\ntypedef enum {\n\tJT_NONE,\n\tJT_DIRECTINPUT,\n\tJT_PLAYSTATION,\n\tJT_XINPUT,\n} JOYTYPE;\n\nJOYTYPE GetJoystickType();\nbool IsJoyVibrationSupported();\nbool IsJoyLedColorSupported();\n#endif // FEATURE_INPUT_IMPROVED\n\n/*\n * Function list\n */\nbool __cdecl DInputCreate(); // 0x004472A0\nvoid __cdecl DInputRelease(); // 0x004472D0\nvoid __cdecl WinInReadKeyboard(LPVOID lpInputData); // 0x004472F0\nDWORD __cdecl WinInReadJoystick(int *xPos, int *yPos); // 0x00447350\nbool __cdecl WinInputInit(); // 0x00447460\nbool __cdecl DInputEnumDevices(JOYSTICK_LIST *joystickList); // 0x004474E0\nBOOL CALLBACK DInputEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef); // 0x00447510\nvoid __thiscall FlaggedStringCreate(STRING_FLAGGED *item, DWORD dwSize); // 0x00447600\nJOYSTICK_NODE *__cdecl GetJoystick(GUID *lpGuid); // 0x00447620\nvoid __cdecl DInputKeyboardCreate(); // 0x00447670\nvoid __cdecl DInputKeyboardRelease(); // 0x00447740\nbool __cdecl DInputJoystickCreate(); // 0x00447770\nvoid __cdecl DInputJoystickRelease(); // NULL function in the original game\nvoid __cdecl WinInStart(); // 0x00447860\nvoid __cdecl WinInFinish(); // 0x00447890\nvoid __cdecl WinInRunControlPanel(HWND hWnd); // 0x004478A0\n\n#endif // INIT_INPUT_H_INCLUDED\n"
  },
  {
    "path": "specific/init_sound.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/init_sound.h\"\n#include \"global/vars.h\"\n\nextern void __thiscall FlaggedStringCreate(STRING_FLAGGED *item, DWORD dwSize);\nextern void __thiscall FlaggedStringDelete(STRING_FLAGGED *item);\nextern bool FlaggedStringCopy(STRING_FLAGGED *dst, STRING_FLAGGED *src);\n\n#ifdef FEATURE_EXTENDED_LIMITS\nDWORD SampleFreqs[370];\nLPDIRECTSOUNDBUFFER SampleBuffers[370];\n#endif // FEATURE_EXTENDED_LIMITS\n\nSOUND_ADAPTER_NODE *__cdecl GetSoundAdapter(GUID *lpGuid) {\n\tSOUND_ADAPTER_NODE *adapter;\n\n\tif( lpGuid != NULL ) {\n\t\tfor( adapter = SoundAdapterList.head; adapter; adapter = adapter->next ) {\n\t\t\tif( !memcmp(&adapter->body.adapterGuid, lpGuid, sizeof(GUID)) )\n\t\t\t\treturn adapter;\n\t\t}\n\t}\n\treturn PrimarySoundAdapter;\n}\n\nvoid __cdecl WinSndFreeAllSamples() {\n\tif( !IsSoundEnabled )\n\t\treturn;\n\n\tfor( DWORD i=0; i<ARRAY_SIZE(SampleBuffers); ++i ) {\n\t\tif( SampleBuffers[i] != NULL ) {\n\t\t\tSampleBuffers[i]->Release();\n\t\t\tSampleBuffers[i] = NULL;\n\t\t}\n\t}\n}\n\nbool __cdecl WinSndMakeSample(DWORD sampleIdx, LPWAVEFORMATEX format, const LPVOID data, DWORD dataSize) {\n\tLPVOID lpvAudioPtr;\n\tDWORD dwAudioBytes;\n\tDSBUFFERDESC desc;\n\n\tif( DSound == NULL || !IsSoundEnabled || sampleIdx >= ARRAY_SIZE(SampleBuffers) )\n\t\treturn false;\n\n\t// NOTE: this check is absent in the original game\n\tif( SampleBuffers[sampleIdx] != NULL ) {\n\t\tSampleBuffers[sampleIdx]->Release();\n\t\tSampleBuffers[sampleIdx] = NULL;\n\t}\n\n\tdesc.dwSize = sizeof(DSBUFFERDESC);\n\tdesc.dwFlags = DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN|DSBCAPS_CTRLFREQUENCY|DSBCAPS_LOCSOFTWARE;\n\tdesc.dwBufferBytes = dataSize;\n\tdesc.dwReserved = 0;\n\tdesc.lpwfxFormat = format;\n\n\tif FAILED(DSound->CreateSoundBuffer(&desc, &SampleBuffers[sampleIdx], NULL))\n\t\treturn false;\n\n\tif FAILED(SampleBuffers[sampleIdx]->Lock(0, dataSize, &lpvAudioPtr, &dwAudioBytes, NULL, NULL, 0))\n\t\treturn false;\n\n\tmemcpy(lpvAudioPtr, data, dwAudioBytes);\n\n\tif FAILED(SampleBuffers[sampleIdx]->Unlock(lpvAudioPtr, dwAudioBytes, NULL, 0))\n\t\treturn false;\n\n\tSampleFreqs[sampleIdx] = format->nSamplesPerSec;\n\treturn true;\n}\n\nbool __cdecl WinSndIsChannelPlaying(DWORD channel) {\n\tDWORD status;\n\n\tif( ChannelBuffers[channel] == NULL || FAILED(ChannelBuffers[channel]->GetStatus(&status)) )\n\t\treturn false;\n\n\tif( (status & DSBSTATUS_PLAYING) == 0 ) {\n\t\tChannelBuffers[channel]->Release();\n\t\tChannelBuffers[channel] = NULL;\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nint __cdecl WinSndPlaySample(DWORD sampleIdx, int volume, DWORD pitch, int pan, DWORD flags) {\n\tLPDIRECTSOUNDBUFFER dsBuffer = NULL;\n\tint channel = WinSndGetFreeChannelIndex();\n\n\tif( channel < 0 )\n\t\treturn -1;\n\n\tif( FAILED(DSound->DuplicateSoundBuffer(SampleBuffers[sampleIdx], &dsBuffer)) ||\n\t\tFAILED(dsBuffer->SetVolume(volume)) ||\n\t\tFAILED(dsBuffer->SetFrequency(SampleFreqs[sampleIdx] * pitch / PHD_ONE)) ||\n\t\tFAILED(dsBuffer->SetPan(pan)) ||\n\t\tFAILED(dsBuffer->SetCurrentPosition(0)) ||\n\t\tFAILED(dsBuffer->Play(0, 0, flags)) )\n\t{\n\t\treturn -2;\n\t}\n\n\tChannelSamples[channel] = sampleIdx;\n\tChannelBuffers[channel] = dsBuffer;\n\n\treturn channel;\n}\n\nint __cdecl WinSndGetFreeChannelIndex() {\n\tfor( int i=0; i<32; ++i ) {\n\t\tif( ChannelBuffers[i] == NULL )\n\t\t\treturn i;\n\t}\n\n\tfor( int i=0; i<32; ++i ) {\n\t\tif( !WinSndIsChannelPlaying(i) )\n\t\t\treturn i;\n\t}\n\n\treturn -1;\n}\n\nvoid __cdecl WinSndAdjustVolumeAndPan(int channel, int volume, int pan) {\n\tif( channel >= 0 && ChannelBuffers[channel] != NULL ) {\n\t\tChannelBuffers[channel]->SetVolume(volume);\n\t\tChannelBuffers[channel]->SetPan(pan);\n\t}\n}\n\nvoid __cdecl WinSndAdjustPitch(int channel, DWORD pitch) {\n\tif( channel >= 0 && ChannelBuffers[channel] != NULL ) {\n\t\tChannelBuffers[channel]->SetFrequency(SampleFreqs[ChannelSamples[channel]] * pitch / PHD_ONE);\n\t}\n}\n\nvoid __cdecl WinSndStopSample(int channel) {\n\tif( channel >= 0 && ChannelBuffers[channel] != NULL ) {\n\t\tChannelBuffers[channel]->Stop();\n\t\tChannelBuffers[channel]->Release();\n\t\tChannelBuffers[channel] = NULL;\n\t}\n}\n\nbool __cdecl WinSndInit() {\n\tSOUND_ADAPTER_NODE *node, *nextNode;\n\n\tfor( node = SoundAdapterList.head; node; node = nextNode ) {\n\t\tnextNode = node->next;\n\t\tFlaggedStringDelete(&node->body.module);\n\t\tFlaggedStringDelete(&node->body.description);\n\t\tdelete(node);\n\t}\n\n\tSoundAdapterList.head = NULL;\n\tSoundAdapterList.tail = NULL;\n\tSoundAdapterList.dwCount = 0;\n\n\tPrimarySoundAdapter = NULL;\n\n\tif( !DSoundEnumerate(&SoundAdapterList) )\n\t\treturn false;\n\n\tfor( node = SoundAdapterList.head; node; node = node->next ) {\n\t\tif( node->body.lpAdapterGuid == NULL ) { // Primary adapter GUID is NULL\n\t\t\tPrimarySoundAdapter = node;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn true;\n}\n\nbool __cdecl DSoundEnumerate(SOUND_ADAPTER_LIST *adapterList) {\n\treturn SUCCEEDED(DirectSoundEnumerate(DSoundEnumCallback, (LPVOID)adapterList));\n}\n\nBOOL CALLBACK DSoundEnumCallback(LPGUID lpGuid, LPCTSTR lpcstrDescription, LPCTSTR lpcstrModule, LPVOID lpContext) {\n\tSOUND_ADAPTER_LIST *adapterList = (SOUND_ADAPTER_LIST *)lpContext;\n\tSOUND_ADAPTER_NODE *adapterNode = new SOUND_ADAPTER_NODE;\n\n\tif( adapterNode == NULL )\n\t\treturn TRUE;\n\n\tadapterNode->next = NULL;\n\tadapterNode->previous = adapterList->tail;\n\n\tif( !adapterList->head )\n\t\tadapterList->head = adapterNode;\n\n\tif( adapterList->tail )\n\t\tadapterList->tail->next = adapterNode;\n\n\tadapterList->tail = adapterNode;\n\tadapterList->dwCount++;\n\n\tif( lpGuid == NULL ) {\n\t\tmemset(&adapterNode->body.adapterGuid, 0, sizeof(GUID));\n\t\tadapterNode->body.lpAdapterGuid = NULL;\n\t} else {\n\t\tadapterNode->body.adapterGuid = *lpGuid;\n\t\tadapterNode->body.lpAdapterGuid = &adapterNode->body.adapterGuid;\n\t}\n\n\tFlaggedStringCreate(&adapterNode->body.description, 256);\n\tFlaggedStringCreate(&adapterNode->body.module, 256);\n\tlstrcpy(adapterNode->body.description.lpString, lpcstrDescription);\n\tlstrcpy(adapterNode->body.module.lpString, lpcstrModule);\n\n\treturn TRUE;\n}\n\nvoid __cdecl WinSndStart(HWND hWnd) {\n\tmemset(SampleBuffers, 0, sizeof(SampleBuffers));\n\tmemset(ChannelBuffers, 0, sizeof(ChannelBuffers));\n\n\tCamera.isLaraMic = SavedAppSettings.LaraMic;\n\tIsSoundEnabled = false;\n\n\tif( !SavedAppSettings.SoundEnabled || SavedAppSettings.PreferredSoundAdapter == NULL )\n\t\treturn;\n\n\tSOUND_ADAPTER *preferred = &SavedAppSettings.PreferredSoundAdapter->body;\n\tCurrentSoundAdapter = *preferred;\n\n\tFlaggedStringCopy(&CurrentSoundAdapter.description, &preferred->description);\n\tFlaggedStringCopy(&CurrentSoundAdapter.module, &preferred->module);\n\n\tif( !DSoundCreate(CurrentSoundAdapter.lpAdapterGuid) )\n\t\treturn;\n\n\tif( hWnd == NULL )\n\t\thWnd = HGameWindow;\n\n\tif FAILED(DSound->SetCooperativeLevel(hWnd, DSSCL_EXCLUSIVE))\n\t\tthrow ERR_CantSetDSCooperativeLevel;\n\n\tif( DSoundBufferTest() )\n\t\tIsSoundEnabled = true;\n}\n\nbool __cdecl DSoundCreate(GUID *lpGuid) {\n#if (DIRECTSOUND_VERSION >= 0x800)\n\treturn SUCCEEDED(DirectSoundCreate8(lpGuid, &DSound, NULL));\n#else // (DIRECTSOUND_VERSION >= 0x800)\n\treturn SUCCEEDED(DirectSoundCreate(lpGuid, &DSound, NULL));\n#endif // (DIRECTSOUND_VERSION >= 0x800)\n}\n\nbool __cdecl DSoundBufferTest() {\n\tWAVEFORMATEX format;\n\tDSBUFFERDESC desc;\n\tLPDIRECTSOUNDBUFFER dsBuffer;\n\n\tdesc.dwSize = sizeof(DSBUFFERDESC);\n\tdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;\n\tdesc.dwBufferBytes = 0;\n\tdesc.dwReserved = 0;\n\tdesc.lpwfxFormat = NULL;\n\n\tif FAILED(DSound->CreateSoundBuffer(&desc, &dsBuffer, NULL))\n\t\treturn false;\n\n\tformat.wFormatTag = WAVE_FORMAT_PCM;\n\tformat.nChannels = 2;\n\tformat.nSamplesPerSec = 11025;\n\tformat.nAvgBytesPerSec = 44100;\n\tformat.nBlockAlign = 4;\n\tformat.wBitsPerSample = 16;\n\tformat.cbSize = 0;\n\n\tbool result = SUCCEEDED(dsBuffer->SetFormat(&format));\n\tdsBuffer->Release();\n\treturn result;\n}\n\nvoid __cdecl WinSndFinish() {\n\tWinSndFreeAllSamples();\n\tif( DSound != NULL ) {\n\t\tDSound->Release();\n\t\tDSound = NULL;\n\t}\n}\n\nbool __cdecl WinSndIsSoundEnabled() {\n\treturn IsSoundEnabled;\n}\n\n/*\n * Inject function\n */\nvoid Inject_InitSound() {\n\tINJECT(0x00447C70, GetSoundAdapter);\n\tINJECT(0x00447CC0, WinSndFreeAllSamples);\n\tINJECT(0x00447CF0, WinSndMakeSample);\n\tINJECT(0x00447E00, WinSndIsChannelPlaying);\n\tINJECT(0x00447E50, WinSndPlaySample);\n\tINJECT(0x00447F40, WinSndGetFreeChannelIndex);\n\tINJECT(0x00447F80, WinSndAdjustVolumeAndPan);\n\tINJECT(0x00447FB0, WinSndAdjustPitch);\n\tINJECT(0x00447FF0, WinSndStopSample);\n\tINJECT(0x00448060, WinSndInit);\n\tINJECT(0x00448100, DSoundEnumerate);\n\tINJECT(0x00448120, DSoundEnumCallback);\n\tINJECT(0x00448210, WinSndStart);\n\tINJECT(0x00448390, DSoundCreate);\n\tINJECT(0x004483B0, DSoundBufferTest);\n\tINJECT(0x00448480, WinSndFinish);\n\tINJECT(0x004484B0, WinSndIsSoundEnabled);\n}\n"
  },
  {
    "path": "specific/init_sound.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef INIT_SOUND_H_INCLUDED\n#define INIT_SOUND_H_INCLUDED\n\n#include \"global/types.h\"\n\n#define VOLUME_PCT(x) (DSBVOLUME_MIN+(DSBVOLUME_MAX-DSBVOLUME_MIN)*(x)/100)\n\n/*\n * Function list\n */\nSOUND_ADAPTER_NODE *__cdecl GetSoundAdapter(GUID *lpGuid); // 0x00447C70\nvoid __cdecl WinSndFreeAllSamples(); // 0x00447CC0\nbool __cdecl WinSndMakeSample(DWORD sampleIdx, LPWAVEFORMATEX format, const LPVOID data, DWORD dataSize); // 0x00447CF0\nbool __cdecl WinSndIsChannelPlaying(DWORD channel); // 0x00447E00\nint __cdecl WinSndPlaySample(DWORD sampleIdx, int volume, DWORD pitch, int pan, DWORD flags); // 0x00447E50\nint __cdecl WinSndGetFreeChannelIndex(); // 0x00447F40\nvoid __cdecl WinSndAdjustVolumeAndPan(int channel, int volume, int pan); // 0x00447F80\nvoid __cdecl WinSndAdjustPitch(int channel, DWORD pitch); // 0x00447FB0\nvoid __cdecl WinSndStopSample(int channel); // 0x00447FF0\nbool __cdecl WinSndInit(); // 0x00448060\nbool __cdecl DSoundEnumerate(SOUND_ADAPTER_LIST *adapterList); // 0x00448100\nBOOL CALLBACK DSoundEnumCallback(LPGUID lpGuid, LPCTSTR lpcstrDescription, LPCTSTR lpcstrModule, LPVOID lpContext); // 0x00448120\nvoid __cdecl WinSndStart(HWND hWnd); // 0x00448210\nbool __cdecl DSoundCreate(GUID *lpGuid); // 0x00448390\nbool __cdecl DSoundBufferTest(); // 0x004483B0\nvoid __cdecl WinSndFinish(); // 0x00448480\nbool __cdecl WinSndIsSoundEnabled(); // 0x004484B0\n\n#endif // INIT_SOUND_H_INCLUDED\n"
  },
  {
    "path": "specific/input.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/input.h\"\n#include \"game/health.h\"\n#include \"game/invfunc.h\"\n#include \"game/laramisc.h\"\n#include \"specific/display.h\"\n#include \"specific/init_display.h\"\n#include \"specific/init_input.h\"\n#include \"specific/screenshot.h\"\n#include \"specific/winvid.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_INPUT_IMPROVED\nbool WalkToSidestep = false;\n#endif // FEATURE_INPUT_IMPROVED\n\n// Macros\n#define KEY_DOWN(a)\t\t((DIKeys[(a)]&0x80)!=0)\n#define TOGGLE(a)\t\t{(a)=!(a);}\n\n// NOTE: not presented in the original game\nstatic BOOL JoyKey(KEYMAP keyMap) {\n#ifdef FEATURE_HUD_IMPROVED\n\tif( keyMap < 4 ) return FALSE; // ignore direction keys\n\tUINT16 key = Layout[CTRL_Joystick].key[keyMap];\n\treturn CHK_ANY(JoyKeys, (1 << key));\n#else // FEATURE_HUD_IMPROVED\n\tUINT16 key = Layout[CTRL_Custom].key[keyMap];\n\treturn ( key >= 0x100 && CHK_ANY(JoyKeys, (1 << key)) );\n#endif // FEATURE_HUD_IMPROVED\n}\n\n// NOTE: not presented in the original game\nstatic BOOL KbdKey(KEYMAP keyMap, bool isCustom) {\n\tUINT16 key = Layout[isCustom ? CTRL_Custom : CTRL_Default].key[keyMap];\n\tif( key < 0x100 ) {\n\t\tif KEY_DOWN(key) {\n\t\t\treturn TRUE;\n\t\t}\n\t\tif( key == DIK_LCONTROL )\treturn KEY_DOWN(DIK_RCONTROL);\n\t\tif( key == DIK_RCONTROL )\treturn KEY_DOWN(DIK_LCONTROL);\n\t\tif( key == DIK_LSHIFT )\t\treturn KEY_DOWN(DIK_RSHIFT);\n\t\tif( key == DIK_RSHIFT )\t\treturn KEY_DOWN(DIK_LSHIFT);\n\t\tif( key == DIK_LMENU )\t\treturn KEY_DOWN(DIK_RMENU);\n\t\tif( key == DIK_RMENU )\t\treturn KEY_DOWN(DIK_LMENU);\n\t}\n\treturn FALSE;\n}\n\n// NOTE: the original function is splitted into JoyKey() and KbdKey()\nBOOL __cdecl Key(KEYMAP keyMap) {\n\treturn JoyKey(keyMap) || KbdKey(keyMap, true) || (!ConflictLayout[keyMap] && KbdKey(keyMap, false));\n}\n\nbool __cdecl S_UpdateInput() {\n\t// NOTE: some of these isF*KeyPressed are presented in the original code.\n\t// But some has been added by me (marked as + below)\n\t// This prevents from multiple actions by one key press\n\tstatic bool isScreenShotKeyPressed = false; // +\n\tstatic bool isF1KeyPressed = false; // +\n\tstatic bool isF2KeyPressed = false; // +\n\tstatic bool isF3KeyPressed = false;\n\tstatic bool isF4KeyPressed = false;\n\tstatic bool isF7KeyPressed = false;\n\tstatic bool isF8KeyPressed = false;\n\tstatic bool isF11KeyPressed = false;\n\tstatic bool isF12KeyPressed = false; // +\n\tstatic BYTE mediPackCooldown = 0;\n\tbool isShiftKeyPressed;\n\tDISPLAY_MODE_NODE *mode;\n\tDISPLAY_MODE_LIST *modeList;\n\tDISPLAY_MODE targetMode;\n\tAPP_SETTINGS newSettings;\n\tint joyXPos = 0;\n\tint joyYPos = 0;\n\tDWORD input = 0;\n\n\tWinVidSpinMessageLoop(false);\n\tWinInReadKeyboard(DIKeys);\n\tJoyKeys = WinInReadJoystick(&joyXPos, &joyYPos);\n\n\t// Joystick Y\n\tif( joyYPos < -8 ) {\n\t\tinput |= IN_FORWARD;\n\t}\n\telse if( joyYPos > 8 ) {\n\t\tinput |= IN_BACK;\n\t}\n\n\t// Joystick X\n\tif( joyXPos < -8 ) {\n\t\tinput |= IN_LEFT;\n\t}\n\telse if( joyXPos > 8 ) {\n\t\tinput |= IN_RIGHT;\n\t}\n\n\t// Key maps\n\tif( Key(KM_Forward) ) {\n\t\tinput |= IN_FORWARD;\n\t}\n\tif( Key(KM_Back) ) {\n\t\tinput |= IN_BACK;\n\t}\n\tif( Key(KM_Left) ) {\n\t\tinput |= IN_LEFT;\n\t}\n\tif( Key(KM_Right) ) {\n\t\tinput |= IN_RIGHT;\n\t}\n\tif( Key(KM_StepLeft) ) {\n\t\tinput |= IN_STEPL;\n\t}\n\tif( Key(KM_StepRight) ) {\n\t\tinput |= IN_STEPR;\n\t}\n\tif( Key(KM_Slow) ) {\n\t\tinput |= IN_SLOW;\n\t}\n\tif( Key(KM_Jump) ) {\n\t\tinput |= IN_JUMP;\n\t}\n\tif( Key(KM_Action) ) {\n\t\tinput |= IN_ACTION;\n\t}\n\tif( Key(KM_WeaponDraw) ) {\n\t\tinput |= IN_DRAW;\n\t}\n\tif( Key(KM_Flare ) ) {\n\t\tinput |= IN_FLARE;\n\t}\n\tif( Key(KM_Look) ) {\n\t\tinput |= IN_LOOK;\n\t}\n\tif( Key(KM_Roll) ) {\n\t\tinput |= IN_ROLL;\n\t}\n\tif( Key(KM_Option) && Camera.type != CAM_Cinematic ) {\n\t\tinput |= IN_OPTION;\n\t}\n\n\t// Key combinations and alternatives\n#ifdef FEATURE_HUD_IMPROVED\n\tif( Key(KM_Step) ) {\n\t\tif( CHK_ANY(input, IN_LEFT) ) {\n\t\t\tinput &= ~(IN_LEFT|IN_FORWARD|IN_BACK);\n\t\t\tinput |= IN_STEPL;\n\t\t} else if( CHK_ANY(input, IN_RIGHT) ) {\n\t\t\tinput &= ~(IN_RIGHT|IN_FORWARD|IN_BACK);\n\t\t\tinput |= IN_STEPR;\n\t\t} else {\n\t\t\tinput |= IN_SLOW;\n\t\t}\n\t}\n#endif // FEATURE_HUD_IMPROVED\n#ifdef FEATURE_INPUT_IMPROVED\n\tif( WalkToSidestep && CHK_ANY(input, IN_SLOW) && !CHK_ANY(input, IN_FORWARD|IN_BACK|IN_STEPL|IN_STEPR) ) {\n\t\tif( CHK_ANY(input, IN_LEFT) ) {\n\t\t\tinput &= ~IN_LEFT;\n\t\t\tinput |= IN_STEPL;\n\t\t} else if( CHK_ANY(input, IN_RIGHT) ) {\n\t\t\tinput &= ~IN_RIGHT;\n\t\t\tinput |= IN_STEPR;\n\t\t}\n\t}\n#endif // FEATURE_INPUT_IMPROVED\n\tif( CHK_ALL(input, IN_FORWARD|IN_BACK) ) {\n\t\tinput |= IN_ROLL;\n\t}\n\tif( KEY_DOWN(DIK_RETURN) || CHK_ANY(input, IN_ACTION) ) {\n\t\tinput |= IN_SELECT;\n\t}\n\t// NOTE: there is no KM_WeaponDraw for Deselect in the original game\n\tif( KEY_DOWN(DIK_ESCAPE) || JoyKey(KM_WeaponDraw) ) {\n\t\tinput |= IN_DESELECT;\n\t}\n\tif( CHK_ALL(input, IN_STEPL|IN_STEPR) ) {\n\t\tinput &= ~(IN_STEPL|IN_STEPR);\n\t}\n\n\t// If FMV is playing just save input status and exit here\n\tif( IsFmvPlaying )\n\t\tgoto EXIT;\n\n\t// NOTE: this check is absent in the original game\n\t// it fixes a bug, when the player could interfere with the demo level\n\tif( !IsDemoLevelType ) {\n\t\t// Weapon requests\n\t\tif( KEY_DOWN(DIK_1) && Inv_RequestItem(ID_PISTOL_OPTION) ) {\n\t\t\tLara.request_gun_type = LGT_Pistols;\n\t\t}\n\t\telse if(KEY_DOWN(DIK_2) && Inv_RequestItem(ID_SHOTGUN_OPTION) ) {\n\t\t\tLara.request_gun_type = LGT_Shotgun;\n\t\t}\n\t\telse if( KEY_DOWN(DIK_3) && Inv_RequestItem(ID_MAGNUM_OPTION) ) {\n\t\t\tLara.request_gun_type = LGT_Magnums;\n\t\t}\n\t\telse if( KEY_DOWN(DIK_4) && Inv_RequestItem(ID_UZI_OPTION) ) {\n\t\t\tLara.request_gun_type = LGT_Uzis;\n\t\t}\n\t\telse if( KEY_DOWN(DIK_5) && Inv_RequestItem(ID_HARPOON_OPTION) ) {\n\t\t\tLara.request_gun_type = LGT_Harpoon;\n\t\t}\n\t\telse if( KEY_DOWN(DIK_6) && Inv_RequestItem(ID_M16_OPTION) ) {\n\t\t\tLara.request_gun_type = LGT_M16;\n\t\t}\n\t\telse if( KEY_DOWN(DIK_7) && Inv_RequestItem(ID_GRENADE_OPTION) ) {\n\t\t\tLara.request_gun_type = LGT_Grenade;\n\t\t}\n\t\telse if( KEY_DOWN(DIK_0) && Inv_RequestItem(ID_FLARES_OPTION) ) {\n\t\t\tLara.request_gun_type = LGT_Flare;\n\t\t}\n\n\t\t// MediPack requests\n\t\tif( mediPackCooldown > 0 ) {\n\t\t\t--mediPackCooldown; // MediPack shortcuts have half second cooldown\n\t\t} else {\n\t\t\tif( KEY_DOWN(DIK_8) && Inv_RequestItem(ID_SMALL_MEDIPACK_OPTION) ) {\n\t\t\t\tUseItem(ID_SMALL_MEDIPACK_OPTION);\n\t\t\t\tmediPackCooldown = 15;\n\t\t\t}\n\t\t\telse if( KEY_DOWN(DIK_9) && Inv_RequestItem(ID_LARGE_MEDIPACK_OPTION) ) {\n\t\t\t\tUseItem(ID_LARGE_MEDIPACK_OPTION);\n\t\t\t\tmediPackCooldown = 15;\n\t\t\t}\n\t\t}\n#ifdef FEATURE_CHEAT\n\t\t// Cheats\n\t\tstatic bool isStuffCheatKeyPressed = false;\n\t\tif( KEY_DOWN(DIK_I) ) {\n\t\t\tif( !isStuffCheatKeyPressed ) {\n\t\t\t\tisStuffCheatKeyPressed = true;\n\t\t\t\tinput |= IN_STUFFCHEAT;\n\t\t\t}\n\t\t} else {\n\t\t\tisStuffCheatKeyPressed = false;\n\t\t}\n\n\t\tif( KEY_DOWN(DIK_O) ) {\n\t\t\tinput |= IN_DOZYCHEAT;\n\t\t}\n#endif // FEATURE_CHEAT\n\t}\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tstatic bool isPauseKeyPressed = false;\n#ifdef FEATURE_HUD_IMPROVED\n\tif( Key(KM_Pause) )\n#else // FEATURE_HUD_IMPROVED\n\tif( KEY_DOWN(DIK_P) )\n#endif // FEATURE_HUD_IMPROVED\n\t{\n\t\tif( !isPauseKeyPressed ) {\n\t\t\tisPauseKeyPressed = true;\n\t\t\tinput |= IN_PAUSE;\n\t\t}\n\t} else {\n\t\tisPauseKeyPressed = false;\n\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\t// Screenshot\n#ifdef FEATURE_SCREENSHOT_IMPROVED\n\tif( KEY_DOWN(DIK_BACK) ) { // BackSpace Key instead of S\n#else // !FEATURE_SCREENSHOT_IMPROVED\n\tif( KEY_DOWN(DIK_S) ) {\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\t\tif( !isScreenShotKeyPressed ) {\n\t\t\tisScreenShotKeyPressed = true;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\tScreenShot(NULL);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\t\tScreenShot(PrimaryBufferSurface);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t}\n\t} else {\n\t\tisScreenShotKeyPressed = false;\n\t}\n\n\t// Save/Load Game\n\tif( !CHK_ANY(GF_GameFlow.flags, GFF_LoadSaveDisabled) ) {\n\t\tif( KEY_DOWN(DIK_F5) )\n\t\t\tinput |= IN_SAVE;\n\t\telse if( KEY_DOWN(DIK_F6) )\n\t\t\tinput |= IN_LOAD;\n\t}\n\n\t// Shift Key check\n\tisShiftKeyPressed = KEY_DOWN(DIK_LSHIFT) || KEY_DOWN(DIK_RSHIFT);\n\n\t// Graphics option toggles\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\n\t\t// Software Renderer F7 key\n\t\tif( KEY_DOWN(DIK_F7) ) {\n\t\t\tif( !isF7KeyPressed ) {\n\t\t\t\tisF7KeyPressed = true;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\tif( isShiftKeyPressed ) {\n\t\t\t\t\t// Triple Buffer (Shift + F7)\n\t\t\t\t\tif( SavedAppSettings.FullScreen ) {\n\t\t\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\t\t\tTOGGLE(newSettings.TripleBuffering);\n\t\t\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Perspective Correction (F7). For SW this means Detail Level: single or double perspective distance\n\t\t\t\t\tTOGGLE(SavedAppSettings.PerspectiveCorrect);\n\t\t\t\t\tif( SavedAppSettings.PerspectiveCorrect ) {\n\t\t\t\t\t\tDetailLevel = 2;\n\t\t\t\t\t\tPerspectiveDistance = SW_DETAIL_HIGH;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tDetailLevel = 1;\n\t\t\t\t\t\tPerspectiveDistance = SW_DETAIL_MEDIUM;\n\t\t\t\t\t}\n\t\t\t\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t}\n\t\t} else {\n\t\t\tisF7KeyPressed = false;\n\t\t}\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\t\t// Software Renderer F11 key\n\t\tif( KEY_DOWN(DIK_F11) ) {\n\t\t\tif( !isF11KeyPressed ) {\n\t\t\t\tisF11KeyPressed = true;\n\t\t\t\t// Lighting Contrast (F11)\n\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\tnewSettings.LightingMode = (newSettings.LightingMode + 1) % 3;\n\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t}\n\t\t} else {\n\t\t\tisF11KeyPressed = false;\n\t\t}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t} else {\n\n\t\t// Hardware Renderer F7 key\n\t\tif( KEY_DOWN(DIK_F7) ) {\n\t\t\tif( !isF7KeyPressed ) {\n\t\t\t\tisF7KeyPressed = true;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\tif( isShiftKeyPressed ) {\n\t\t\t\t\t// Triple Buffer (Shift + F7)\n\t\t\t\t\tif( SavedAppSettings.FullScreen ) {\n\t\t\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\t\t\tTOGGLE(newSettings.TripleBuffering);\n\t\t\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t\t\t}\n\t\t\t\t} else\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t{\n\t\t\t\t\t// ZBuffer (F7)\n\t\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\t\tTOGGLE(newSettings.ZBuffer);\n\t\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tisF7KeyPressed = false;\n\t\t}\n\n\t\t// Hardware Renderer F8 key\n\t\tif( KEY_DOWN(DIK_F8) ) {\n\t\t\tif( !isF8KeyPressed ) {\n\t\t\t\tisF8KeyPressed = true;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\tif( isShiftKeyPressed ) {\n\t\t\t\t\t// Perspective Correction (Shift + F8)\n\t\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\t\tTOGGLE(newSettings.PerspectiveCorrect);\n\t\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t\t} else\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t{\n\t\t\t\t\t// Bilinear Filtering (F8)\n\t\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\t\tTOGGLE(newSettings.BilinearFiltering);\n\t\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tisF8KeyPressed = false;\n\t\t}\n\n\t\t// Hardware Renderer F11 key\n\t\tif( KEY_DOWN(DIK_F11) ) {\n\t\t\tif( !isF11KeyPressed ) {\n\t\t\t\tisF11KeyPressed = true;\n#ifdef FEATURE_NOLEGACY_OPTIONS\n#if defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\t\t\t\t// Lighting Contrast (F11)\n\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\tnewSettings.LightingMode = (newSettings.LightingMode + 1) % 3;\n\t\t\t\tGameApplySettings(&newSettings);\n#endif // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n#else // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t// Dithering (F11)\n\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\tTOGGLE(newSettings.Dither);\n\t\t\t\tGameApplySettings(&newSettings);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t}\n\t\t} else {\n\t\t\tisF11KeyPressed = false;\n\t\t}\n\t}\n\n\t// Check F12 key if view mode is not locked\n\tif( !IsVidModeLock ) {\n\t\tif( KEY_DOWN(DIK_F12) ) {\n\t\t\tif( !isF12KeyPressed ) {\n\t\t\t\tisF12KeyPressed = true;\n\t\t\t\tnewSettings = SavedAppSettings;\n\n\t\t\t\tif( !isShiftKeyPressed ) {\n\t\t\t\t\t// FullScreen/Windowed Toggle (F12)\n\t\t\t\t\tTOGGLE(newSettings.FullScreen);\n\n\t\t\t\t\tif( SavedAppSettings.FullScreen ) {\n\n\t\t\t\t\t\t// FullScreen to Windowed\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t\tCLAMPL(newSettings.WindowWidth, 320);\n\t\t\t\t\t\tCLAMPL(newSettings.WindowHeight, 240);\n\t\t\t\t\t\tnewSettings.WindowWidth = CalculateWindowWidth(newSettings.WindowWidth, newSettings.WindowHeight);\n#else // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t\tint winWidth  = MAX(PhdWinWidth, 320);\n\t\t\t\t\t\tint winHeight = MAX(PhdWinHeight, 240);\n\n\t\t\t\t\t\tnewSettings.WindowHeight = winHeight;\n\t\t\t\t\t\tnewSettings.WindowWidth = CalculateWindowWidth(winWidth, winHeight);\n\t\t\t\t\t\tnewSettings.TripleBuffering = false;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t\tGameApplySettings(&newSettings);\n\n\t\t\t\t\t\t// Reset inner screen size for windowed mode\n\t\t\t\t\t\tGameSizer = 1.0;\n\t\t\t\t\t\tScreenSizer = 1.0;\n\t\t\t\t\t\tsetup_screen_size();\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\t// Windowed to FullScreen\n\t\t\t\t\t\tif( SavedAppSettings.RenderMode == RM_Hardware )\n\t\t\t\t\t\t\tmodeList = &CurrentDisplayAdapter.hwDispModeList;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tmodeList = &CurrentDisplayAdapter.swDispModeList;\n\n\t\t\t\t\t\tif( modeList->dwCount > 0 ) {\n\t\t\t\t\t\t\ttargetMode.width  = GameVidWidth;\n\t\t\t\t\t\t\ttargetMode.height = GameVidHeight;\n\t\t\t\t\t\t\ttargetMode.bpp = GameVidBPP;\n\t\t\t\t\t\t\ttargetMode.vga = VGA_NoVga;\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t\t\tif( SavedAppSettings.VideoMode ) {\n\t\t\t\t\t\t\t\ttargetMode.width = SavedAppSettings.VideoMode->body.width;\n\t\t\t\t\t\t\t\ttargetMode.height = SavedAppSettings.VideoMode->body.height;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif( modeList->head ) {\n\t\t\t\t\t\t\t\ttargetMode.bpp = modeList->head->body.bpp;\n\t\t\t\t\t\t\t\ttargetMode.vga = modeList->head->body.vga;\n\t\t\t\t\t\t\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t\t\t\t\t\t\tfor( mode = modeList->head; mode != NULL; mode = mode->next ) {\n\t\t\t\t\t\t\t\tif( !CompareVideoModes(&mode->body, &targetMode) )\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif( mode == NULL ) {\n\t\t\t\t\t\t\t\tmode = modeList->tail;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tnewSettings.VideoMode = mode;\n\t\t\t\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Check Shift+F12 key if Inventory is not active now\n\t\t\t\telse if( !IsInventoryActive ) {\n\t\t\t\t\t// Renderer Toggle (Shift + F12)\n\n\t\t\t\t\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\t\t\t\t\t// Software to Hardware\n\t\t\t\t\t\tnewSettings.RenderMode = RM_Hardware;\n\t\t\t\t\t\tmodeList = &CurrentDisplayAdapter.hwDispModeList;\n\t\t\t\t\t\ttargetMode.bpp = 16;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Hardware to Software\n\t\t\t\t\t\tnewSettings.RenderMode = RM_Software;\n\t\t\t\t\t\tmodeList = &CurrentDisplayAdapter.swDispModeList;\n\t\t\t\t\t\ttargetMode.bpp = 8;\n\t\t\t\t\t}\n\n\t\t\t\t\tif( modeList->dwCount > 0 ) {\n\t\t\t\t\t\ttargetMode.width  = GameVidWidth;\n\t\t\t\t\t\ttargetMode.height = GameVidHeight;\n\t\t\t\t\t\ttargetMode.vga = VGA_NoVga;\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t\tif( SavedAppSettings.VideoMode ) {\n\t\t\t\t\t\t\ttargetMode.width = SavedAppSettings.VideoMode->body.width;\n\t\t\t\t\t\t\ttargetMode.height = SavedAppSettings.VideoMode->body.height;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif( modeList->head ) {\n\t\t\t\t\t\t\ttargetMode.bpp = modeList->head->body.bpp;\n\t\t\t\t\t\t\ttargetMode.vga = modeList->head->body.vga;\n\t\t\t\t\t\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t\t\t\t\t\tfor( mode = modeList->head; mode != NULL; mode = mode->next ) {\n\t\t\t\t\t\t\tif( !CompareVideoModes(&mode->body, &targetMode) )\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif( mode == NULL ) {\n\t\t\t\t\t\t\tmode = modeList->tail;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tnewSettings.VideoMode = mode;\n#if (DIRECT3D_VERSION < 0x900)\n\t\t\t\t\t\tnewSettings.FullScreen = true;\n#endif // (DIRECT3D_VERSION < 0x900)\n\t\t\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tisF12KeyPressed = false;\n\t\t}\n\t}\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\tchar msg[32] = {0};\n\t\tconst char *levels[3] = {\n\t\t\tGF_GameStringTable[GSI_Detail_Low],\n\t\t\tGF_GameStringTable[GSI_Detail_Medium],\n\t\t\tGF_GameStringTable[GSI_Detail_High],\n\t\t};\n\t\t// Decrease Software Renderer Detail Level\n\t\tif( KEY_DOWN(DIK_F3) ) {\n\t\t\tif( !isF3KeyPressed && DetailLevel > 0 ) {\n\t\t\t\tisF3KeyPressed = true;\n\t\t\t\tswitch( --DetailLevel ) {\n\t\t\t\t\tcase 0: PerspectiveDistance = SW_DETAIL_LOW; break;\n\t\t\t\t\tcase 1: PerspectiveDistance = SW_DETAIL_MEDIUM; break;\n\t\t\t\t\tcase 2: PerspectiveDistance = SW_DETAIL_HIGH; break;\n\t\t\t\t}\n\t\t\t\tsnprintf(msg, sizeof(msg), \"Detail Level: %s\", levels[DetailLevel]);\n\t\t\t}\n\t\t} else {\n\t\t\tisF3KeyPressed = false;\n\t\t}\n\n\t\t// Increase Software Renderer Detail Level\n\t\tif( KEY_DOWN(DIK_F4) ) {\n\t\t\tif( !isF4KeyPressed && DetailLevel < 2 ) {\n\t\t\t\tisF4KeyPressed = true;\n\t\t\t\tswitch( ++DetailLevel ) {\n\t\t\t\t\tcase 0: PerspectiveDistance = SW_DETAIL_LOW; break;\n\t\t\t\t\tcase 1: PerspectiveDistance = SW_DETAIL_MEDIUM; break;\n\t\t\t\t\tcase 2: PerspectiveDistance = SW_DETAIL_HIGH; break;\n\t\t\t\t}\n\t\t\t\tsnprintf(msg, sizeof(msg), \"Detail Level: %s\", levels[DetailLevel]);\n\t\t\t}\n\t\t} else {\n\t\t\tisF4KeyPressed = false;\n\t\t}\n\t\tif( *msg ) DisplayModeInfo(msg);\n\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t// Check if we cannot change full screen video parameters here\n\tif( IsVidSizeLock ||\n\t\tCamera.type == CAM_Cinematic ||\n\t\t!SavedAppSettings.FullScreen ||\n\t\tCHK_ANY(GF_GameFlow.flags, GFF_ScreenSizingDisabled) )\n\t{\n\t\tgoto EXIT;\n\t}\n\n\t// Decrease resolution/depth (F1)\n\tif( KEY_DOWN(DIK_F1) ) {\n\t\tif( !isF1KeyPressed ) {\n\t\t\tisF1KeyPressed = true;\n\t\t\tmode = SavedAppSettings.VideoMode;\n\n\t\t\t// Get previous videomode (enough for Software Renderer)\n\t\t\tif( mode != NULL ) {\n\t\t\t\tmode = mode->previous;\n\t\t\t}\n\t\t\t// Additional checks for Hardware Renderer\n\t\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\t\tfor( ; mode != NULL; mode = mode->previous ) {\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t// Decrease depth (Shift + F1)\n\t\t\t\t\tif( isShiftKeyPressed ) {\n\t\t\t\t\t\tif( mode->body.width  == SavedAppSettings.VideoMode->body.width &&\n\t\t\t\t\t\t\tmode->body.height == SavedAppSettings.VideoMode->body.height &&\n\t\t\t\t\t\t\tmode->body.vga == SavedAppSettings.VideoMode->body.vga &&\n\t\t\t\t\t\t\tmode->body.bpp <  SavedAppSettings.VideoMode->body.bpp )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t// Decrease resolution (F1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif( mode->body.vga == SavedAppSettings.VideoMode->body.vga &&\n\t\t\t\t\t\t\tmode->body.bpp == SavedAppSettings.VideoMode->body.bpp )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif( mode != NULL ) {\n\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\tnewSettings.VideoMode = mode;\n\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisF1KeyPressed = false;\n\t}\n\n\t// Increase resolution/depth (F2)\n\tif( KEY_DOWN(DIK_F2) ) {\n\t\tif( !isF2KeyPressed ) {\n\t\t\tisF2KeyPressed = true;\n\t\t\tmode = SavedAppSettings.VideoMode;\n\n\t\t\t// Get next videomode (enough for Software Renderer)\n\t\t\tif( mode != NULL ) {\n\t\t\t\tmode = mode->next;\n\t\t\t}\n\t\t\t// Additional checks for Hardware Renderer\n\t\t\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\t\t\tfor( ; mode != NULL; mode = mode->next ) {\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t// Increase depth (Shift + F2)\n\t\t\t\t\tif( isShiftKeyPressed ) {\n\t\t\t\t\t\tif( mode->body.width  == SavedAppSettings.VideoMode->body.width &&\n\t\t\t\t\t\t\tmode->body.height == SavedAppSettings.VideoMode->body.height &&\n\t\t\t\t\t\t\tmode->body.vga == SavedAppSettings.VideoMode->body.vga &&\n\t\t\t\t\t\t\tmode->body.bpp >  SavedAppSettings.VideoMode->body.bpp )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\t// Increase resolution (F2)\n\t\t\t\t\t{\n\t\t\t\t\t\tif( mode->body.vga == SavedAppSettings.VideoMode->body.vga &&\n\t\t\t\t\t\t\tmode->body.bpp == SavedAppSettings.VideoMode->body.bpp )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif( mode != NULL ) {\n\t\t\t\tnewSettings = SavedAppSettings;\n\t\t\t\tnewSettings.VideoMode = mode;\n\t\t\t\tGameApplySettings(&newSettings);\n\t\t\t}\n\t\t}\n\t}else {\n\t\tisF2KeyPressed = false;\n\t}\n\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t// Decrease inner screen size (F3)\n\tif( KEY_DOWN(DIK_F3) ) {\n\t\tif( !isF3KeyPressed ) {\n\t\t\tisF3KeyPressed = true;\n\t\t\tDecreaseScreenSize();\n\t\t}\n\t} else {\n\t\tisF3KeyPressed = false;\n\t}\n\n\t// Increase inner screen size (F4)\n\tif( KEY_DOWN(DIK_F4) ) {\n\t\tif( !isF4KeyPressed ) {\n\t\t\tisF4KeyPressed = true;\n\t\t\tIncreaseScreenSize();\n\t\t}\n\t} else {\n\t\tisF4KeyPressed = false;\n\t}\n#endif // !FEATURE_NOLEGACY_OPTIONS\n\nEXIT :\n\tInputStatus = input;\n\treturn IsGameToExit;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Input() {\n\tINJECT(0x0044D9B0, Key);\n\tINJECT(0x0044DAD0, S_UpdateInput);\n}\n"
  },
  {
    "path": "specific/input.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef INPUT_H_INCLUDED\n#define INPUT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nBOOL __cdecl Key(KEYMAP keyMap); // 0x0044D9B0\nbool __cdecl S_UpdateInput(); // 0x0044DAD0\n\n#endif // INPUT_H_INCLUDED\n"
  },
  {
    "path": "specific/option.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/option.h\"\n#include \"game/invtext.h\"\n#include \"game/sound.h\"\n#include \"game/text.h\"\n#include \"specific/game.h\"\n#include \"specific/init_input.h\"\n#include \"specific/output.h\"\n#include \"specific/sndpc.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_HUD_IMPROVED\n#include \"modding/psx_bar.h\"\n\nextern DWORD InvTextBoxMode;\n\nbool JoystickHintsEnabled = true;\n\nCONTROL_LAYOUT Layout[3] = {\n\t{\t// Joystick Layout\n\t\t0,0,0,0, // directions are not mappable, so they are ignored\n\t\t10, // Step Left\n\t\t11, // Step Right\n\t\t7, // Step\n\t\t5, // Walk\n\t\t3, // Jump\n\t\t2, // Action\n\t\t1, // Roll\n\t\t0, // Draw Weapon\n\t\t6, // Flare\n\t\t4, // Look\n\t\t8, // Inventory\n\t\t9, // Pause\n\t},\n\t{\t// User Keyboard Layout\n\t\tDIK_NUMPAD8, // Run\n\t\tDIK_NUMPAD2, // Back\n\t\tDIK_NUMPAD4, // Left\n\t\tDIK_NUMPAD6, // Right\n\t\tDIK_NUMPAD7, // Step Left\n\t\tDIK_NUMPAD9, // Step Right\n\t\tDIK_DIVIDE, // Step\n\t\tDIK_NUMPAD1, // Walk\n\t\tDIK_ADD, // Jump\n\t\tDIK_NUMPADENTER, // Action\n\t\tDIK_NUMPAD5, // Roll\n\t\tDIK_NUMPAD3, // Draw Weapon\n\t\tDIK_SUBTRACT, // Flare\n\t\tDIK_NUMPAD0, // Look\n\t\tDIK_DECIMAL, // Inventory\n\t\tDIK_MULTIPLY, // Pause\n\t},\n\t{\t// Default Keyboard Layout\n\t\tDIK_UP, // Run\n\t\tDIK_DOWN, // Back\n\t\tDIK_LEFT, // Left\n\t\tDIK_RIGHT, // Right\n\t\tDIK_DELETE, // Step Left\n\t\tDIK_NEXT, // Step Right\n\t\tDIK_PERIOD, // Step\n\t\tDIK_RSHIFT, // Walk\n\t\tDIK_RMENU, // Jump\n\t\tDIK_RCONTROL, // Action\n\t\tDIK_END, // Roll\n\t\tDIK_SPACE, // Draw Weapon\n\t\tDIK_SLASH, // Flare\n\t\tDIK_NUMPAD0, // Look\n\t\tDIK_ESCAPE, // Inventory\n\t\tDIK_P, // Pause\n\t},\n};\n\nINVENTORY_ITEM *InvOptionList[5] = {\n\t&InvPassportOption,\n\t&InvSoundOption,\n\t&InvDetailOption,\n\t&InvControlOption,\n\t&InvPhotoOption,\n};\n\n__int16 InvOptionObjectsCount = ARRAY_SIZE(InvOptionList);\n\nbool ConflictLayout[ARRAY_SIZE(Layout->key)];\nTEXT_STR_INFO *CtrlTextA[ARRAY_SIZE(Layout->key)];\nTEXT_STR_INFO *CtrlTextB[ARRAY_SIZE(Layout->key)];\nTEXT_STR_INFO *CtrlTextC[ARRAY_SIZE(Layout->key)];\n\nstatic DWORD LayoutPage = CTRL_Joystick;\n#else // FEATURE_HUD_IMPROVED\nstatic DWORD LayoutPage = CTRL_Default;\n#endif // FEATURE_HUD_IMPROVED\n\n/*\n * Passport option box parameters\n */\n#define PASSPORT_LINE_COUNT\t(10)\n// Y coordinates relative to the bottom of the screen\n#ifdef FEATURE_HUD_IMPROVED\n#define PASSPORT_Y_BOX\t\t(-44)\n#else // FEATURE_HUD_IMPROVED\n#define PASSPORT_Y_BOX\t\t(-32)\n#endif\n#define PASSPORT_Y_TITLE\t(-16)\n\n/*\n * Detail option box parameters\n */\n#define DETAIL_WIDTH_L\t\t(160)\n#define DETAIL_WIDTH_M\t\t(DETAIL_WIDTH_L - 4)\n#define DETAIL_WIDTH_S\t\t(DETAIL_WIDTH_L - 12)\n\n#define DETAIL_LN_HEIGHT\t(25)\n#define DETAIL_HEIGHT\t\t(DETAIL_LN_HEIGHT * 3 + 32)\n// Y coordinates relative to the center of the screen\n#define DETAIL_Y_BOX\t\t(-32)\n#define DETAIL_Y_TITLE\t\t(DETAIL_Y_BOX + 2)\n#define DETAIL_Y_LINE1\t\t(DETAIL_LN_HEIGHT * 0)\n#define DETAIL_Y_LINE2\t\t(DETAIL_LN_HEIGHT * 1)\n#define DETAIL_Y_LINE3\t\t(DETAIL_LN_HEIGHT * 2)\n\n#define DETAIL_NEARZ\t\t(8)\n#define DETAIL_FARZ\t\t\t(16)\n\n/*\n * Sound option box parameters\n */\n#define SOUND_WIDTH_L\t\t(140)\n#define SOUND_WIDTH_M\t\t(SOUND_WIDTH_L - 4)\n#define SOUND_WIDTH_S\t\t(SOUND_WIDTH_L - 12)\n\n#define SOUND_LN_HEIGHT\t\t(25)\n#define SOUND_HEIGHT\t\t(SOUND_LN_HEIGHT * 2 + 32)\n// Y coordinates relative to the center of the screen\n#define SOUND_Y_BOX\t\t\t(-32)\n#define SOUND_Y_TITLE\t\t(SOUND_Y_BOX + 2)\n#define SOUND_Y_LINE1\t\t(SOUND_LN_HEIGHT * 0)\n#define SOUND_Y_LINE2\t\t(SOUND_LN_HEIGHT * 1)\n\n#define SOUND_NEARZ\t\t\t(8)\n#define SOUND_FARZ\t\t\t(48)\n\n/*\n * Control option box parameters\n */\n#define CONTROL_LINE_COUNT\t(ARRAY_SIZE(Layout->key)/2)\n#define CONTROL_LN_HEIGHT\t(15)\n\n#ifdef FEATURE_HUD_IMPROVED\n#define CONTROL_WIDTH_LOW\t(300)\n#define CONTROL_HEIGHT_LOW\t(CONTROL_LN_HEIGHT * CONTROL_LINE_COUNT + 26)\n\n#define CONTROL_WIDTH_HIGH\t(360)\n#define CONTROL_HEIGHT_HIGH\tCONTROL_HEIGHT_LOW\n\n#define CONTROL_COLUMN_C\t(15)\n#define CONTROL_COLUMN_B2\t(30)\n#define CONTROL_COLUMN_B1\t(40)\n#define CONTROL_COLUMN_A\t(60)\n\n// Y coordinates relative to the center of the screen\n#define CONTROL_Y_BOX\t\t(-70)\n#define CONTROL_Y_TITLE\t\t(CONTROL_Y_BOX + 4)\n#define CONTROL_Y_LINE1\t\t(CONTROL_LN_HEIGHT * 0 + CONTROL_Y_BOX + 24)\n#define CONTROL_Y_LINE2\t\t(CONTROL_LN_HEIGHT * 1 + CONTROL_Y_BOX + 24)\n#define CONTROL_Y_LINE3\t\t(CONTROL_LN_HEIGHT * 2 + CONTROL_Y_BOX + 24)\n#define CONTROL_Y_LINE4\t\t(CONTROL_LN_HEIGHT * 3 + CONTROL_Y_BOX + 24)\n#define CONTROL_Y_LINE5\t\t(CONTROL_LN_HEIGHT * 4 + CONTROL_Y_BOX + 24)\n#define CONTROL_Y_LINE6\t\t(CONTROL_LN_HEIGHT * 5 + CONTROL_Y_BOX + 24)\n#define CONTROL_Y_LINE7\t\t(CONTROL_LN_HEIGHT * 6 + CONTROL_Y_BOX + 24)\n#define CONTROL_Y_LINE8\t\t(CONTROL_LN_HEIGHT * 7 + CONTROL_Y_BOX + 24)\n#else // FEATURE_HUD_IMPROVED\n#define CONTROL_WIDTH_LOW\t(300)\n#define CONTROL_HEIGHT_LOW\t(CONTROL_LN_HEIGHT * CONTROL_LINE_COUNT + 35)\n\n#define CONTROL_WIDTH_HIGH\t(420)\n#define CONTROL_HEIGHT_HIGH\t(CONTROL_LN_HEIGHT * CONTROL_LINE_COUNT + 45)\n\n#define CONTROL_COLUMN_B\t(10)\n#define CONTROL_COLUMN_A\t(80)\n\n// Y coordinates relative to the center of the screen\n#define CONTROL_Y_BOX\t\t(-55)\n#define CONTROL_Y_TITLE\t\t(CONTROL_Y_BOX + 5)\n#define CONTROL_Y_LINE1\t\t(CONTROL_LN_HEIGHT * 0 + CONTROL_Y_BOX + 30)\n#define CONTROL_Y_LINE2\t\t(CONTROL_LN_HEIGHT * 1 + CONTROL_Y_BOX + 30)\n#define CONTROL_Y_LINE3\t\t(CONTROL_LN_HEIGHT * 2 + CONTROL_Y_BOX + 30)\n#define CONTROL_Y_LINE4\t\t(CONTROL_LN_HEIGHT * 3 + CONTROL_Y_BOX + 30)\n#define CONTROL_Y_LINE5\t\t(CONTROL_LN_HEIGHT * 4 + CONTROL_Y_BOX + 30)\n#define CONTROL_Y_LINE6\t\t(CONTROL_LN_HEIGHT * 5 + CONTROL_Y_BOX + 30)\n#define CONTROL_Y_LINE7\t\t(CONTROL_LN_HEIGHT * 6 + CONTROL_Y_BOX + 30)\n#endif // FEATURE_HUD_IMPROVED\n\n#define CONTROL_NEARZ\t\t(16)\n#define CONTROL_FARZ\t\t(48)\n\nextern GOURAUD_FILL ReqBgndGour1;\nextern GOURAUD_OUTLINE ReqBgndGour2;\n\nextern GOURAUD_FILL ReqMainGour1;\nextern GOURAUD_OUTLINE ReqMainGour2;\n\nextern GOURAUD_FILL ReqSelGour1;\nextern GOURAUD_OUTLINE ReqSelGour2;\n\n/*\n * Control key names\n */\n#ifdef FEATURE_HUD_IMPROVED\nstatic LPCSTR ControlKeysText[0x110] = {\n\tNULL,           K(\"esc\"),       K(\"1\"),         K(\"2\"),         K(\"3\"),         K(\"4\"),         K(\"5\"),         K(\"6\"),\n\tK(\"7\"),         K(\"8\"),         K(\"9\"),         K(\"0\"),         K(\"-\"),         K(\"=\"),         K(\"backspace\"), K(\"tab\"),\n\tK(\"q\"),         K(\"w\"),         K(\"e\"),         K(\"r\"),         K(\"t\"),         K(\"y\"),         K(\"u\"),         K(\"i\"),\n\tK(\"o\"),         K(\"p\"),         K(\"[\"),         K(\"]\"),         K(\"return\"),    K(\"ctrl\"),      K(\"a\"),         K(\"s\"),\n\tK(\"d\"),         K(\"f\"),         K(\"g\"),         K(\"h\"),         K(\"j\"),         K(\"k\"),         K(\"l\"),         K(\";\"),\n\tK(\"'\"),         K(\"`\"),         K(\"shift\"),     K(\"\\\\\"),        K(\"z\"),         K(\"x\"),         K(\"c\"),         K(\"v\"),\n\tK(\"b\"),         K(\"n\"),         K(\"m\"),         K(\",\"),         K(\".\"),         K(\"/\"),         K(\"shift\"),     K(\"pad*\"),\n\tK(\"alt\"),       K(\"space\"),     K(\"capslock\"),  NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           K(\"numlock\"),   NULL,           K(\"pad7\"),\n\tK(\"pad8\"),      K(\"pad9\"),      K(\"pad-\"),      K(\"pad4\"),      K(\"pad5\"),      K(\"pad6\"),      K(\"pad+\"),      K(\"pad1\"),\n\tK(\"pad2\"),      K(\"pad3\"),      K(\"pad0\"),      K(\"pad.\"),      NULL,           NULL,           K(\"<\"),         NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           K(\"enter\"),     K(\"ctrl\"),      NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           K(\"shift\"),     NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           K(\"pad/\"),      NULL,           NULL,\n\tK(\"alt\"),       NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           K(\"home\"),\n\tK(\"up\"),        K(\"pageup\"),    NULL,           K(\"left\"),      NULL,           K(\"right\"),     NULL,           K(\"end\"),\n\tK(\"down\"),      K(\"pagedown\"),  K(\"insert\"),    K(\"delete\"),    NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tNULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,           NULL,\n\tK(\"joy1\"),      K(\"joy2\"),      K(\"joy3\"),      K(\"joy4\"),      K(\"joy5\"),      K(\"joy6\"),      K(\"joy7\"),      K(\"joy8\"),\n\tK(\"joy9\"),      K(\"joy10\"),     K(\"joy11\"),     K(\"joy12\"),     K(\"joy13\"),     K(\"joy14\"),     K(\"joy15\"),     K(\"joy16\"),\n};\n\nstatic TEXT_STR_INFO *SelectHintText, *ContinueHintText, *DeselectHintText;\n\ntypedef enum {\n\tHINT_HIDDEN,\n\tHINT_JOYSTICK,\n\tHINT_KEYBOARD,\n} HINT_MODE;\n\nstatic const char *GetHintText(HINT_MODE mode, KEYMAP joyKeyMap, DWORD kbdKeyCode, const char *message) {\n\tstatic char text[64] = {0};\n\tconst char *key = NULL;\n\tif( mode == HINT_JOYSTICK && Layout[CTRL_Joystick].key[joyKeyMap] < 0x10 ) {\n\t\tkey = ControlKeysText[0x100 + Layout[CTRL_Joystick].key[joyKeyMap]];\n\t} else {\n\t\tkey = ControlKeysText[kbdKeyCode];\n\t}\n\tsnprintf(text, sizeof(text), \"%s %s\", key, message);\n\treturn text;\n}\n\nstatic void UpdateJoystickHintText(HINT_MODE selectMode, HINT_MODE continueMode, HINT_MODE deselectMode) {\n\tif( SelectHintText != NULL ) {\n\t\tif( selectMode != HINT_HIDDEN ) {\n\t\t\tT_ChangeText(SelectHintText, GetHintText(selectMode, KM_Action, DIK_RETURN, \"Select\"));\n\t\t}\n\t\tT_HideText(SelectHintText, selectMode == HINT_HIDDEN);\n\t}\n\tif( ContinueHintText != NULL ) {\n\t\tif( continueMode != HINT_HIDDEN ) {\n\t\t\tT_ChangeText(ContinueHintText, GetHintText(continueMode, KM_Action, DIK_RETURN, \"Continue\"));\n\t\t}\n\t\tT_HideText(ContinueHintText, continueMode == HINT_HIDDEN);\n\t}\n\tif( DeselectHintText != NULL ) {\n\t\tif( deselectMode != HINT_HIDDEN ) {\n\t\t\tT_ChangeText(DeselectHintText, GetHintText(deselectMode, KM_WeaponDraw, DIK_ESCAPE, \"Go Back\"));\n\t\t}\n\t\tT_HideText(DeselectHintText, deselectMode == HINT_HIDDEN);\n\t}\n}\n\nvoid RemoveJoystickHintText(bool isSelect, bool isContinue, bool isDeselect) {\n\tif( isSelect ) {\n\t\tT_RemovePrint(SelectHintText);\n\t\tSelectHintText = NULL;\n\t}\n\tif( isContinue ) {\n\t\tT_RemovePrint(ContinueHintText);\n\t\tContinueHintText = NULL;\n\t}\n\tif( isDeselect ) {\n\t\tT_RemovePrint(DeselectHintText);\n\t\tDeselectHintText = NULL;\n\t}\n}\n\nvoid DisplayJoystickHintText(bool isSelect, bool isContinue, bool isDeselect) {\n\tif( !JoystickHintsEnabled ) return;\n#ifdef FEATURE_INPUT_IMPROVED\n\tif( GetJoystickType() == JT_NONE ) return;\n#else // FEATURE_INPUT_IMPROVED\n\tif( !SavedAppSettings.JoystickEnabled || !SavedAppSettings.PreferredJoystick ) return;\n#endif // FEATURE_INPUT_IMPROVED\n\n\tbool isRealignX = false;\n\tstatic int renderWidth = 0;\n\tif( renderWidth != GetRenderWidthDownscaled() ) {\n\t\tisRealignX = true;\n\t\trenderWidth = GetRenderWidthDownscaled();\n\t}\n\tint x = (renderWidth > 325) ? (renderWidth - 320) / 2 : 2;\n\n\tif( isSelect && SelectHintText == NULL ) {\n\t\tSelectHintText = T_Print(x, -40, 0, GetHintText(HINT_JOYSTICK, KM_Action, DIK_RETURN, \"Select\"));\n\t\tT_BottomAlign(SelectHintText, 1);\n\t} else if( isRealignX && SelectHintText != NULL ) {\n\t\tSelectHintText->xPos = x;\n\t}\n\tif( isContinue && ContinueHintText == NULL ) {\n\t\tContinueHintText = T_Print(0, -40, 0, GetHintText(HINT_JOYSTICK, KM_Action, DIK_RETURN, \"Continue\"));\n\t\tT_BottomAlign(ContinueHintText, 1);\n\t\tT_CentreH(ContinueHintText, 1);\n\t}\n\tif( isDeselect && DeselectHintText == NULL ) {\n\t\tDeselectHintText = T_Print(-x, -40, 0, GetHintText(HINT_JOYSTICK, KM_WeaponDraw, DIK_ESCAPE, \"Go Back\"));\n\t\tT_BottomAlign(DeselectHintText, 1);\n\t\tT_RightAlign(DeselectHintText, 1);\n\t} else if( isRealignX && DeselectHintText != NULL ) {\n\t\tDeselectHintText->xPos = -x;\n\t}\n}\n\nstatic void DrawVolumeBar(int x, int y, int percent, int alpha) {\n\t// draw at least one percent\n\tCLAMP(percent, 1, 100);\n\t// coordinates are relative to the center of the screen\n\tint width = GetRenderScale(100);\n\tint height = GetRenderScale(5);\n\tint pixel = GetRenderScale(1);\n\tint x0 = PhdWinMinX + GetRenderScale(x) + (GetRenderWidth() - width) / 2;\n\tint x1 = x0 + width;\n\tint y0 = PhdWinMinY + GetRenderScale(y) + (GetRenderHeight() - height) / 2;\n\tint y1 = y0 + height;\n\tint bar = width * percent / 100;\n\tif( SavedAppSettings.ZBuffer ) {\n\t\tPSX_DrawAirBar(x0, y0, x1, y1, bar, pixel, alpha);\n\t} else {\n\t\tPSX_InsertAirBar(x0, y0, x1, y1, bar, pixel, alpha);\n\t}\n}\n\nvoid DisplayVolumeBars(bool isSmooth) {\n\tstatic int soundVolumePos = 0;\n\tstatic int musicVolumePos = 0;\n\tif( isSmooth ) {\n\t\tif( musicVolumePos < MusicVolume*10 ) {\n\t\t\tmusicVolumePos += 2;\n\t\t} else if( musicVolumePos > MusicVolume*10 ) {\n\t\t\tmusicVolumePos -= 2;\n\t\t}\n\t\tif( soundVolumePos < SoundVolume*10 ) {\n\t\t\tsoundVolumePos += 2;\n\t\t} else if( soundVolumePos > SoundVolume*10 ) {\n\t\t\tsoundVolumePos -= 2;\n\t\t}\n\t} else {\n\t\tmusicVolumePos = MusicVolume*10;\n\t\tsoundVolumePos = SoundVolume*10;\n\t}\n\tDrawVolumeBar(10, -5, musicVolumePos, SoundOptionLine ? 100 : 255);\n\tDrawVolumeBar(10, 20, soundVolumePos, SoundOptionLine ? 255 : 100);\n\tif( SoundOptionLine ) {\n\t\tPlaySoundEffect(113, NULL, SFX_ALWAYS); // ticking clock sound\n\t}\n}\n\nstatic const char *GetEmptyOptName(void) {\n\treturn \"\";\n}\n\nstatic const char *GetEmptyOptState(void) {\n\treturn \"\";\n}\n\nstatic const char *ToggleEmptyOptState(void) {\n\treturn GetEmptyOptState();\n}\n\nstatic const char *GetShowHintsOptName(void) {\n\treturn \"Show Hints\";\n}\n\nstatic const char *GetShowHintsOptState(void) {\n\treturn JoystickHintsEnabled ? GF_SpecificStringTable[SSI_On] : GF_SpecificStringTable[SSI_Off];\n}\n\nstatic const char *ToggleShowHintsOptState(void) {\n\tJoystickHintsEnabled = !JoystickHintsEnabled;\n\tif( JoystickHintsEnabled ) {\n\t\tDisplayJoystickHintText(true, false, true);\n\t} else {\n\t\tRemoveJoystickHintText(true, false, true);\n\t}\n\treturn GetShowHintsOptState();\n}\n\n#ifdef FEATURE_INPUT_IMPROVED\nextern bool JoystickVibrationEnabled;\nextern bool JoystickLedColorEnabled;\n\nstatic const char *GetVibrationOptName(void) {\n\treturn \"Vibration\";\n}\n\nstatic const char *GetVibrationOptState(void) {\n\tif( !IsJoyVibrationSupported() ) return GF_GameStringTable[GSI_String_NA];\n\treturn JoystickVibrationEnabled ? GF_SpecificStringTable[SSI_On] : GF_SpecificStringTable[SSI_Off];\n}\n\nstatic const char *ToggleVibrationOptState(void) {\n\tif( IsJoyVibrationSupported() ) {\n\t\tJoystickVibrationEnabled = !JoystickVibrationEnabled;\n\t}\n\treturn GetVibrationOptState();\n}\n\nstatic const char *GetLightbarOptName(void) {\n\treturn IsJoyLedColorSupported() ? \"Light Bar\" : \"\";\n}\n\nstatic const char *GetLightbarOptState(void) {\n\tif( !IsJoyLedColorSupported() ) return \"\";\n\treturn JoystickLedColorEnabled ? GF_SpecificStringTable[SSI_On] : GF_SpecificStringTable[SSI_Off];\n}\n\nstatic const char *ToggleLightbarOptState(void) {\n\tif( IsJoyLedColorSupported() ) {\n\t\tJoystickLedColorEnabled = !JoystickLedColorEnabled;\n\t}\n\treturn GetLightbarOptState();\n}\n#endif // FEATURE_INPUT_IMPROVED\n\ntypedef struct {\n\tconst char *(*getName)(void);\n\tconst char *(*getState)(void);\n\tconst char *(*toggle)(void);\n} JOYOPT;\n\nstatic JOYOPT JoystickOpts[4] = {\n\t{GetShowHintsOptName, GetShowHintsOptState, ToggleShowHintsOptState},\n#ifdef FEATURE_INPUT_IMPROVED\n\t{GetVibrationOptName, GetVibrationOptState, ToggleVibrationOptState},\n\t{GetLightbarOptName, GetLightbarOptState, ToggleLightbarOptState},\n#else // FEATURE_INPUT_IMPROVED\n\t{GetEmptyOptName, GetEmptyOptState, ToggleEmptyOptState},\n\t{GetEmptyOptName, GetEmptyOptState, ToggleEmptyOptState},\n#endif // FEATURE_INPUT_IMPROVED\n\t{GetEmptyOptName, GetEmptyOptState, ToggleEmptyOptState},\n};\n#else // FEATURE_HUD_IMPROVED\nstatic LPCSTR ControlKeysText[0x110] = {\n\tNULL,   \"ESC\",   \"1\",     \"2\",     \"3\",     \"4\",     \"5\",     \"6\",\n\t\"7\",    \"8\",     \"9\",     \"0\",     \"-\",     \"+\",     \"BKSP\",  \"TAB\",\n\t\"Q\",    \"W\",     \"E\",     \"R\",     \"T\",     \"Y\",     \"U\",     \"I\",\n\t\"O\",    \"P\",     \"<\",     \">\",     \"RET\",   \"CTRL\",  \"A\",     \"S\",\n\t\"D\",    \"F\",     \"G\",     \"H\",     \"J\",     \"K\",     \"L\",     \";\",\n\t\"'\",    \"`\",     \"SHIFT\", \"#\",     \"Z\",     \"X\",     \"C\",     \"V\",\n\t\"B\",    \"N\",     \"M\",     \",\",     \".\",     \"/\",     \"SHIFT\", \"PADx\",\n\t\"ALT\",  \"SPACE\", \"CAPS\",  NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    \"NMLK\",  NULL,    \"PAD7\",\n\t\"PAD8\", \"PAD9\",  \"PAD-\",  \"PAD4\",  \"PAD5\",  \"PAD6\",  \"PAD+\",  \"PAD1\",\n\t\"PAD2\", \"PAD3\",  \"PAD0\",  \"PAD.\",  NULL,    NULL,    \"\\\\\",    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    \"ENTER\", \"CTRL\",  NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    \"SHIFT\", NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    \"PAD/\",  NULL,    NULL,\n\t\"ALT\",  NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    \"HOME\",\n\t\"UP\",   \"PGUP\",  NULL,    \"LEFT\",  NULL,    \"RIGHT\", NULL,    \"END\",\n\t\"DOWN\", \"PGDN\",  \"INS\",   \"DEL\",   NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\tNULL,   NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,\n\t\"JOY1\", \"JOY2\",  \"JOY3\",  \"JOY4\",  \"JOY5\",  \"JOY6\",  \"JOY7\",  \"JOY8\",\n\t\"JOY9\", \"JOY10\", \"JOY11\", \"JOY12\", \"JOY13\", \"JOY14\", \"JOY15\", \"JOY16\",\n};\n#endif // FEATURE_HUD_IMPROVED\n\n// NOTE: not presented in the original game. SetPCRequesterSize() used directly instead\nvoid SetPassportRequesterSize(REQUEST_INFO *req) {\n#ifdef FEATURE_HUD_IMPROVED\n\textern DWORD SavegameSlots;\n\tdouble scale = (double)GetRenderHeight() / (double)GetRenderScale(480);\n\tDWORD adjust = ( scale > 1.0 ) ? 5 : 0;\n\tDWORD lines = (PASSPORT_LINE_COUNT + adjust) * scale - adjust;\n\tCLAMP(lines, 5, SavegameSlots);\n\tSetPCRequesterSize(req, lines, PASSPORT_Y_BOX);\n#else // !FEATURE_HUD_IMPROVED\n\tSetPCRequesterSize(req, PASSPORT_LINE_COUNT, PASSPORT_Y_BOX);\n#endif // FEATURE_HUD_IMPROVED\n}\n\nvoid __cdecl do_inventory_options(INVENTORY_ITEM *item) {\n\tswitch( item->objectID ) {\n\t// passport\n\t\tcase ID_PASSPORT_OPTION:\n\t\t\tdo_passport_option(item);\n\t\t\tbreak;\n\t// gamma\n\t\tcase ID_GAMMA_OPTION:\n\t\t\tdo_gamma_option(item);\n\t\t\tbreak;\n\t// detail\n\t\tcase ID_DETAIL_OPTION:\n\t\t\tdo_detail_option(item);\n\t\t\tbreak;\n\t// sound\n\t\tcase ID_SOUND_OPTION:\n\t\t\tdo_sound_option(item);\n\t\t\tbreak;\n\t// control\n\t\tcase ID_CONTROL_OPTION:\n\t\t\tdo_control_option(item);\n\t\t\tbreak;\n\t// statistics\n\t\tcase ID_COMPASS_OPTION:\n\t\t\tdo_compass_option(item);\n\t\t\tbreak;\n\t// weapons\n\t\tcase ID_PISTOL_OPTION:\n\t\tcase ID_SHOTGUN_OPTION:\n\t\tcase ID_MAGNUM_OPTION:\n\t\tcase ID_UZI_OPTION:\n\t\tcase ID_HARPOON_OPTION:\n\t\tcase ID_M16_OPTION:\n\t\tcase ID_GRENADE_OPTION:\n\t// medipacks\n\t\tcase ID_SMALL_MEDIPACK_OPTION:\n\t\tcase ID_LARGE_MEDIPACK_OPTION:\n\t// puzzles\n\t\tcase ID_PUZZLE_OPTION1:\n\t\tcase ID_PUZZLE_OPTION2:\n\t\tcase ID_PUZZLE_OPTION3:\n\t\tcase ID_PUZZLE_OPTION4:\n\t// keys\n\t\tcase ID_KEY_OPTION1:\n\t\tcase ID_KEY_OPTION2:\n\t\tcase ID_KEY_OPTION3:\n\t\tcase ID_KEY_OPTION4:\n\t// pickups\n\t\tcase ID_PICKUP_OPTION1:\n\t\tcase ID_PICKUP_OPTION2:\n\t\t\tInputDB |= IN_SELECT;\n\t\t\tbreak;\n\t// ammo\n\t\tcase ID_PISTOL_AMMO_OPTION:\n\t\tcase ID_SHOTGUN_AMMO_OPTION:\n\t\tcase ID_MAGNUM_AMMO_OPTION:\n\t\tcase ID_UZI_AMMO_OPTION:\n\t\tcase ID_HARPOON_AMMO_OPTION:\n\t\tcase ID_M16_AMMO_OPTION:\n\t\tcase ID_GRENADE_AMMO_OPTION:\n\t\t\tbreak;\n\t// other\n\t\tdefault:\n\t\t\tif( CHK_ANY(InputDB, IN_SELECT|IN_DESELECT) ) {\n\t\t\t\titem->goalFrame = 0;\n\t\t\t\titem->animDirection = -1;\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\n#ifdef FEATURE_HUD_IMPROVED\nstatic void SetPassportTextInfo(GAME_STRING_ID id, bool left, bool right) {\n\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\tchar text[64] = {0};\n\t\tsnprintf(text, sizeof(text), \"%c    %s   %c \", left?'\\x11':' ', GF_GameStringTable[id], right?'\\x12':' ');\n\t\tPassportTextInfo = T_Print(0, PASSPORT_Y_TITLE, 0, text);\n\t} else {\n\t\tPassportTextInfo = T_Print(0, PASSPORT_Y_TITLE, 0, GF_GameStringTable[id]);\n\t}\n}\n#endif // FEATURE_HUD_IMPROVED\n\nvoid __cdecl do_passport_option(INVENTORY_ITEM *item) {\n\tstatic int passportMode = 0;\n\tint frame, page, select;\n\tREQUEST_INFO *requester;\n\n\tT_RemovePrint(InvItemText[0]);\n\tInvItemText[0] = NULL;\n\n\tframe = item->goalFrame - item->openFrame;\n\tpage = ( (frame % 5) == 0 ) ? (frame / 5) : -1;\n\n#ifdef FEATURE_HUD_IMPROVED\n\tbool left = page > 0;\n\tbool right = page < 2;\n\n\tif( InventoryMode == INV_DeathMode ) {\n\t\tInputDB &= ~IN_DESELECT;\n\t}\n#endif // FEATURE_HUD_IMPROVED\n\n\tif( InventoryMode == INV_LoadMode ||\n\t\tInventoryMode == INV_SaveMode ||\n\t\tCHK_ANY(GF_GameFlow.flags, GFF_LoadSaveDisabled) )\n\t{\n\t\tInputDB &= ~(IN_LEFT|IN_RIGHT);\n#ifdef FEATURE_HUD_IMPROVED\n\t\tleft = false;\n\t\tright = false;\n#endif // FEATURE_HUD_IMPROVED\n\t}\n\n\tInventoryExtraData[0] = page; // NOTE: moved here from the end\n\tswitch( page ) {\n\t\tcase 0 : // load game\n\t\t\tif( CHK_ANY(GF_GameFlow.flags, GFF_LoadSaveDisabled) ) {\n\t\t\t\tInputDB = IN_RIGHT;\n\t\t\t}\n\t\t\telse if( passportMode == 1 ) {\n\t\t\t\tSetPassportRequesterSize(&LoadGameRequester);\n\t\t\t\tselect = Display_Requester(&LoadGameRequester, TRUE, TRUE);\n\t\t\t\tif( select == 0 ) {\n\t\t\t\t\tif( CHK_ANY(InputDB, IN_RIGHT) ) {\n\t\t\t\t\t\tRemove_Requester(&LoadGameRequester);\n\t\t\t\t\t\tpassportMode = 0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tInputStatus = 0;\n\t\t\t\t\t\tInputDB = 0;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif( select > 0 ) {\n\t\t\t\t\t\tInventoryExtraData[1] = select - 1;\n\t\t\t\t\t}\n\t\t\t\t\tpassportMode = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if( passportMode == 0 ) {\n\t\t\t\tif( SavedGamesCount == 0 || InventoryMode == INV_SaveMode ) {\n\t\t\t\t\tInputDB = IN_RIGHT;\n\t\t\t\t} else {\n\t\t\t\t\tif( PassportTextInfo == NULL ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\t\t\tSetPassportTextInfo(GSI_Passport_LoadGame, left, right);\n#else // FEATURE_HUD_IMPROVED\n\t\t\t\t\t\tPassportTextInfo = T_Print(0, PASSPORT_Y_TITLE, 0, GF_GameStringTable[GSI_Passport_LoadGame]);\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t\t\t\tT_BottomAlign(PassportTextInfo, 1);\n\t\t\t\t\t\tT_CentreH(PassportTextInfo, 1);\n\t\t\t\t\t}\n\t\t\t\t\tT_RemovePrint(InvRingText);\n\t\t\t\t\tInvRingText = NULL;\n\t\t\t\t\tT_RemovePrint(InvItemText[0]);\n\t\t\t\t\tInvItemText[0] = NULL;\n\t\t\t\t\tGetSavedGamesList(&LoadGameRequester);\n\t\t\t\t\tSetRequesterHeading(&LoadGameRequester, GF_GameStringTable[GSI_Passport_LoadGame], 0, NULL, 0);\n\t\t\t\t\tpassportMode = 1;\n\t\t\t\t\tInputStatus = 0;\n\t\t\t\t\tInputDB = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 1 : // new game | save game | restart level\n\t\t\tif( CHK_ANY(GF_GameFlow.flags, GFF_LoadSaveDisabled) ) {\n\t\t\t\tInputDB = IN_RIGHT;\n\t\t\t}\n\t\t\telse if( passportMode == 1 || passportMode == 2 ) {\n\t\t\t\trequester = ( passportMode == 1 ) ? &LoadGameRequester : &SaveGameRequester;\n\n\t\t\t\tSetPassportRequesterSize(requester);\n\t\t\t\tselect = Display_Requester(requester, TRUE, TRUE);\n\t\t\t\tif( select == 0 ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\t\tif( SavedGamesCount == 0 ) InputDB &= ~IN_LEFT;\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t\t\tif( CHK_ANY(InputDB, IN_LEFT|IN_RIGHT) ) {\n\t\t\t\t\t\tRemove_Requester(requester);\n\t\t\t\t\t\tpassportMode = 0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tInputStatus = 0;\n\t\t\t\t\t\tInputDB = 0;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif( select > 0 ) {\n\t\t\t\t\t\tInventoryExtraData[1] = select - 1;\n\t\t\t\t\t}\n\t\t\t\t\tpassportMode = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if( passportMode == 0 ) {\n\t\t\t\tif( InventoryMode == INV_DeathMode ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\t\tif( PassportTextInfo == NULL ) {\n\t\t\t\t\t\tif( SavedGamesCount == 0 ) left = false;\n\t\t\t\t\t\tSetPassportTextInfo(GSI_Passport_RestartLevel, left, right);\n\t\t\t\t\t\tT_BottomAlign(PassportTextInfo, 1);\n\t\t\t\t\t\tT_CentreH(PassportTextInfo, 1);\n\t\t\t\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\t\t\t\tInputDB = ( item->animDirection == -1 ) ? IN_LEFT : IN_RIGHT;\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t\t} else {\n\t\t\t\t\tif( PassportTextInfo == NULL ) {\n\t\t\t\t\t\tGAME_STRING_ID textID;\n\t\t\t\t\t\tif( InventoryMode != INV_TitleMode && CurrentLevel != 0 )\n\t\t\t\t\t\t\ttextID = GSI_Passport_SaveGame;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\ttextID = GSI_Passport_NewGame;\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\t\t\tif( SavedGamesCount == 0 ) left = false;\n\t\t\t\t\t\tSetPassportTextInfo(textID, left, right);\n#else // FEATURE_HUD_IMPROVED\n\t\t\t\t\t\tPassportTextInfo = T_Print(0, PASSPORT_Y_TITLE, 0, GF_GameStringTable[textID]);\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t\t\t\tT_BottomAlign(PassportTextInfo, 1);\n\t\t\t\t\t\tT_CentreH(PassportTextInfo, 1);\n\t\t\t\t\t}\n\n\t\t\t\t\tif( InventoryMode != INV_TitleMode && CurrentLevel != 0 ) {\n\t\t\t\t\t\tT_RemovePrint(InvRingText);\n\t\t\t\t\t\tInvRingText = NULL;\n\t\t\t\t\t\tT_RemovePrint(InvItemText[0]);\n\t\t\t\t\t\tInvItemText[0] = NULL;\n\t\t\t\t\t\tGetSavedGamesList(&LoadGameRequester);\n\t\t\t\t\t\tSetRequesterHeading(&LoadGameRequester, GF_GameStringTable[GSI_Passport_SaveGame], 0, NULL, 0);\n\t\t\t\t\t\tpassportMode = 1;\n\t\t\t\t\t\tInputStatus = 0;\n\t\t\t\t\t\tInputDB = 0;\n\t\t\t\t\t}\n\t\t\t\t\telse if( CHK_ANY(GF_GameFlow.flags, GFF_SelectAnyLevel) ) {\n\t\t\t\t\t\tT_RemovePrint(InvItemText[0]);\n\t\t\t\t\t\tInvItemText[0] = 0;\n\t\t\t\t\t\tInit_Requester(&SaveGameRequester);\n\t\t\t\t\t\tGetValidLevelsList(&SaveGameRequester);\n\t\t\t\t\t\tSetRequesterHeading(&SaveGameRequester, GF_GameStringTable[GSI_Passport_SelectLevel], 0, NULL, 0);\n\t\t\t\t\t\tpassportMode = 2;\n\t\t\t\t\t\tInputStatus = 0;\n\t\t\t\t\t\tInputDB = 0;\n\t\t\t\t\t}\n\t\t\t\t\telse if( CHK_ANY(InputDB, IN_SELECT) ) {\n\t\t\t\t\t\tInventoryExtraData[1] = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 2 : // exit game | exit to title\n\t\t\tif( PassportTextInfo == NULL ) {\n\t\t\t\tGAME_STRING_ID textID;\n\t\t\t\tif( InventoryMode == INV_TitleMode ) {\n\t\t\t\t\ttextID = GSI_Passport_ExitGame;\n\t\t\t\t}\n\t\t\t\telse if( CHK_ANY(GF_GameFlow.flags, GFF_DemoVersion) ) {\n\t\t\t\t\ttextID = GSI_Passport_ExitDemo;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttextID = GSI_Passport_ExitToTitle;\n\t\t\t\t}\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\tSetPassportTextInfo(textID, left, right);\n#else // FEATURE_HUD_IMPROVED\n\t\t\t\tPassportTextInfo = T_Print(0, PASSPORT_Y_TITLE, 0, GF_GameStringTable[textID]);\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t\tT_BottomAlign(PassportTextInfo, 1);\n\t\t\t\tT_CentreH(PassportTextInfo, 1);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tdefault :\n\t\t\tbreak;\n\t}\n\n#ifdef FEATURE_HUD_IMPROVED\n\tif( CHK_ANY(InputDB, IN_LEFT) && (InventoryMode != INV_DeathMode || SavedGamesCount != 0 || page > 1) ) {\n#else // FEATURE_HUD_IMPROVED\n\tif( CHK_ANY(InputDB, IN_LEFT) && (InventoryMode != INV_DeathMode || SavedGamesCount != 0) ) {\n#endif // FEATURE_HUD_IMPROVED\n\t\titem->animDirection = -1;\n\t\titem->goalFrame -= 5;\n\t\tif( SavedGamesCount != 0 ) {\n\t\t\tif( item->goalFrame < item->openFrame ) {\n\t\t\t\titem->goalFrame = item->openFrame;\n\t\t\t} else {\n\t\t\t\tPlaySoundEffect(115, NULL, SFX_ALWAYS); // page flip SFX\n\t\t\t\tT_RemovePrint(PassportTextInfo);\n\t\t\t\tPassportTextInfo = NULL;\n\t\t\t}\n\t\t} else {\n\t\t\tif( item->goalFrame < item->openFrame + 5 ) {\n\t\t\t\titem->goalFrame = item->openFrame + 5;\n\t\t\t} else {\n\t\t\t\tT_RemovePrint(PassportTextInfo);\n\t\t\t\tPassportTextInfo = NULL;\n\t\t\t}\n\t\t}\n\t\tInputStatus = 0;\n\t\tInputDB = 0;\n\t}\n\n\tif( CHK_ANY(InputDB, IN_RIGHT) ) {\n\t\titem->animDirection = 1;\n\t\titem->goalFrame += 5;\n\t\tif( item->goalFrame > item->framesTotal - 6 ) {\n\t\t\titem->goalFrame = item->framesTotal - 6;\n\t\t} else {\n\t\t\tPlaySoundEffect(115, NULL, SFX_ALWAYS); // page flip SFX\n\t\t\tT_RemovePrint(PassportTextInfo);\n\t\t\tPassportTextInfo = NULL;\n\t\t}\n\t\tInputStatus = 0;\n\t\tInputDB = 0;\n\t}\n\n\tif( CHK_ANY(InputDB, IN_DESELECT) ) {\n\t\tif( InventoryMode == INV_DeathMode ) {\n\t\t\tInputStatus = 0;\n\t\t\tInputDB = 0;\n\t\t} else {\n\t\t\tif( page == 2 ) {\n\t\t\t\titem->animDirection = 1;\n\t\t\t\titem->goalFrame = item->framesTotal - 1;\n\t\t\t} else {\n\t\t\t\titem->animDirection = -1;\n\t\t\t\titem->goalFrame = 0;\n\t\t\t}\n\t\t\tT_RemovePrint(PassportTextInfo);\n\t\t\tPassportTextInfo = NULL;\n\t\t}\n\t}\n\n\tif( CHK_ANY(InputDB, IN_SELECT) ) {\n\t\t// NOTE: InventoryExtraData[0]=page moved from here to the line before the switch\n\t\tif( page == 2 ) {\n\t\t\titem->animDirection = 1;\n\t\t\titem->goalFrame = item->framesTotal - 1;\n\t\t} else {\n\t\t\titem->animDirection = -1;\n\t\t\titem->goalFrame = 0;\n\t\t}\n\t\tT_RemovePrint(PassportTextInfo);\n\t\tPassportTextInfo = NULL;\n\t}\n}\n\nvoid __cdecl do_gamma_option(INVENTORY_ITEM *item) {\n// null function\n}\n\nvoid __cdecl do_detail_option(INVENTORY_ITEM *item) {\n\tstatic TEXT_STR_INFO *DetailTextInfo[5] = {NULL};\n\tDWORD i;\n\n\tif( DetailTextInfo[0] == NULL ) {\n\t\tDetailTextInfo[4] = T_Print(0, DETAIL_Y_TITLE, 0, GF_GameStringTable[GSI_Detail_SelectDetail]);\n\t\tDetailTextInfo[3] = T_Print(0, DETAIL_Y_BOX, 0, \" \");\n\t\tDetailTextInfo[2] = T_Print(0, DETAIL_Y_LINE1, 0, GF_GameStringTable[GSI_Detail_High]);\n\t\tDetailTextInfo[1] = T_Print(0, DETAIL_Y_LINE2, 0, GF_GameStringTable[GSI_Detail_Medium]);\n\t\tDetailTextInfo[0] = T_Print(0, DETAIL_Y_LINE3, 0, GF_GameStringTable[GSI_Detail_Low]);\n\n\t\tT_AddBackground(DetailTextInfo[4], DETAIL_WIDTH_M, 0, 0, 0, DETAIL_NEARZ, ICLR_Black, &ReqMainGour1, 0);\n\t\tT_AddOutline(DetailTextInfo[4], TRUE, ICLR_Orange, &ReqMainGour2, 0);\n\n\t\tT_AddBackground(DetailTextInfo[DetailLevel], DETAIL_WIDTH_S, 0, 0, 0, DETAIL_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\tT_AddOutline(DetailTextInfo[DetailLevel], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n\n\t\tT_AddBackground(DetailTextInfo[3], DETAIL_WIDTH_L, DETAIL_HEIGHT, 0, 0, DETAIL_FARZ, ICLR_Black, &ReqBgndGour1, 0);\n\t\tT_AddOutline(DetailTextInfo[3], TRUE, ICLR_Blue, &ReqBgndGour2, 0);\n\n\t\tfor( i=0; i<ARRAY_SIZE(DetailTextInfo); ++i ) {\n\t\t\tT_CentreH(DetailTextInfo[i], 1);\n\t\t\tT_CentreV(DetailTextInfo[i], 1);\n\t\t}\n\t}\n\n\tif( CHK_ANY(InputDB, IN_BACK) && DetailLevel > 0 ) {\n\t\tT_RemoveOutline(DetailTextInfo[DetailLevel]);\n\t\tT_RemoveBackground(DetailTextInfo[DetailLevel]);\n\t\t--DetailLevel;\n\t\tT_AddOutline(DetailTextInfo[DetailLevel], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n\t\tT_AddBackground(DetailTextInfo[DetailLevel], DETAIL_WIDTH_S, 0, 0, 0, DETAIL_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t}\n\n\tif ( CHK_ANY(InputDB, IN_FORWARD) && DetailLevel < 2 ) {\n\t\tT_RemoveOutline(DetailTextInfo[DetailLevel]);\n\t\tT_RemoveBackground(DetailTextInfo[DetailLevel]);\n\t\t++DetailLevel;\n\t\tT_AddOutline(DetailTextInfo[DetailLevel], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n\t\tT_AddBackground(DetailTextInfo[DetailLevel], DETAIL_WIDTH_S, 0, 0, 0, DETAIL_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t}\n\n\tswitch( DetailLevel ) {\n\t\tcase 2 :\n\t\t\t// NOTE: maybe supposed to be SW_DETAIL_HIGH? Anyway this menu is disabled by Core\n\t\t\tPerspectiveDistance = SW_DETAIL_ULTRA;\n\t\t\tbreak;\n\t\tcase 1 :\n\t\t\tPerspectiveDistance = SW_DETAIL_MEDIUM;\n\t\t\tbreak;\n\t\tcase 0 :\n\t\tdefault :\n\t\t\tPerspectiveDistance = SW_DETAIL_LOW;\n\t\t\tbreak;\n\t}\n\n\tif( CHK_ANY(InputDB, IN_SELECT|IN_DESELECT) ) {\n\t\tfor( i=0; i<ARRAY_SIZE(DetailTextInfo); ++i ) {\n\t\t\tT_RemovePrint(DetailTextInfo[i]);\n\t\t\tDetailTextInfo[i] = NULL;\n\t\t}\n\t}\n}\n\nvoid __cdecl do_sound_option(INVENTORY_ITEM *item) {\n#ifdef FEATURE_HUD_IMPROVED\n\tstatic TEXT_STR_INFO *SoundTextInfo[8] = {NULL};\n#else // FEATURE_HUD_IMPROVED\n\tstatic TEXT_STR_INFO *SoundTextInfo[4] = {NULL};\n#endif // FEATURE_HUD_IMPROVED\n\tchar volumeString[20];\n\tDWORD i;\n\n\tif( SoundTextInfo[0] == NULL ) {\n\t\tCLAMP(MusicVolume, 0, 10);\n\t\tCLAMP(SoundVolume, 0, 10);\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\t\tSoundTextInfo[0] = T_Print(-55, 0, 0, \"|\"); // Char '|' is musical note picture\n\t\t\tSoundTextInfo[1] = T_Print(-55, 25, 0, \"}\"); // Char '}' is dynamic speaker picture\n\t\t} else {\n\t\t\tSoundTextInfo[0] = T_Print(0, 0, 0, \"\");\n\t\t\tSoundTextInfo[1] = T_Print(0, 25, 0, \"\");\n\t\t\tSoundTextInfo[4] = T_Print(-15, 0, 0, \"|\"); // Char '|' is musical note picture\n\t\t\tSoundTextInfo[5] = T_Print(-15, 25, 0, \"}\"); // Char '}' is dynamic speaker picture\n\t\t\tsprintf(volumeString, \"%2d\", MusicVolume);\n\t\t\tSoundTextInfo[6] = T_Print(10, 0, 0, volumeString);\n\t\t\tsprintf(volumeString, \"%2d\", SoundVolume);\n\t\t\tSoundTextInfo[7] = T_Print(10, 25, 0, volumeString);\n\n\t\t\tT_AddBackground(SoundTextInfo[0], SOUND_WIDTH_S, 0, 0, 0, SOUND_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\t\tT_AddOutline(SoundTextInfo[0], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\tsprintf(volumeString, \"| %2d\", MusicVolume); // Char '|' is musical note picture\n\t\tSoundTextInfo[0] = T_Print(0, 0, 0, volumeString);\n\t\tsprintf(volumeString, \"} %2d\", SoundVolume); // Char '}' is dynamic speaker picture\n\t\tSoundTextInfo[1] = T_Print(0, 25, 0, volumeString);\n\n\t\tT_AddBackground(SoundTextInfo[0], SOUND_WIDTH_S, 0, 0, 0, SOUND_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\tT_AddOutline(SoundTextInfo[0], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n#endif // FEATURE_HUD_IMPROVED\n\n\t\tSoundTextInfo[2] = T_Print(0, SOUND_Y_BOX, 0, \" \");\n\t\tT_AddBackground(SoundTextInfo[2], SOUND_WIDTH_L, SOUND_HEIGHT, 0, 0, SOUND_FARZ, ICLR_Black, &ReqBgndGour1, 0);\n\t\tT_AddOutline(SoundTextInfo[2], TRUE, ICLR_Blue, &ReqBgndGour2, 0);\n\n\t\tSoundTextInfo[3] = T_Print(0, SOUND_Y_TITLE, 0, GF_SpecificStringTable[SSI_SetVolumes]);\n\t\tT_AddBackground(SoundTextInfo[3], SOUND_WIDTH_M, 0, 0, 0, SOUND_NEARZ, ICLR_Black, &ReqMainGour1, 0);\n\t\tT_AddOutline(SoundTextInfo[3], TRUE, ICLR_Blue, &ReqMainGour2, 0);\n\n\t\tfor( i=0; i<ARRAY_SIZE(SoundTextInfo); ++i ) {\n\t\t\tT_CentreH(SoundTextInfo[i], 1);\n\t\t\tT_CentreV(SoundTextInfo[i], 1);\n\t\t}\n\t}\n\n\tif( CHK_ANY(InputDB, IN_FORWARD) && SoundOptionLine > 0 ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\t\t--SoundOptionLine;\n\t\t} else {\n\t\t\tT_RemoveOutline(SoundTextInfo[SoundOptionLine]);\n\t\t\tT_RemoveBackground(SoundTextInfo[SoundOptionLine]);\n\t\t\t--SoundOptionLine;\n\t\t\tT_AddBackground(SoundTextInfo[SoundOptionLine], SOUND_WIDTH_S, 0, 0, 0, SOUND_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\t\tT_AddOutline(SoundTextInfo[SoundOptionLine], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\tT_RemoveOutline(SoundTextInfo[SoundOptionLine]);\n\t\tT_RemoveBackground(SoundTextInfo[SoundOptionLine]);\n\t\t--SoundOptionLine;\n\t\tT_AddBackground(SoundTextInfo[SoundOptionLine], SOUND_WIDTH_S, 0, 0, 0, SOUND_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\tT_AddOutline(SoundTextInfo[SoundOptionLine], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n#endif // FEATURE_HUD_IMPROVED\n\t}\n\n\tif( CHK_ANY(InputDB, IN_BACK) && SoundOptionLine < 1 ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode ) {\n\t\t\t++SoundOptionLine;\n\t\t} else {\n\t\t\tT_RemoveOutline(SoundTextInfo[SoundOptionLine]);\n\t\t\tT_RemoveBackground(SoundTextInfo[SoundOptionLine]);\n\t\t\t++SoundOptionLine;\n\t\t\tT_AddBackground(SoundTextInfo[SoundOptionLine], SOUND_WIDTH_S, 0, 0, 0, SOUND_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\t\tT_AddOutline(SoundTextInfo[SoundOptionLine], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\tT_RemoveOutline(SoundTextInfo[SoundOptionLine]);\n\t\tT_RemoveBackground(SoundTextInfo[SoundOptionLine]);\n\t\t++SoundOptionLine;\n\t\tT_AddBackground(SoundTextInfo[SoundOptionLine], SOUND_WIDTH_S, 0, 0, 0, SOUND_NEARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\tT_AddOutline(SoundTextInfo[SoundOptionLine], TRUE, ICLR_Orange, &ReqSelGour2, 0);\n#endif // FEATURE_HUD_IMPROVED\n\t}\n\n\tswitch( SoundOptionLine ) {\n\t\tcase 0 :\n\t\t\tif( CHK_ANY(InputStatus, IN_LEFT) && MusicVolume > 0 )\n\t\t\t\t--MusicVolume;\n\t\t\telse if( CHK_ANY(InputStatus, IN_RIGHT) && MusicVolume < 10 )\n\t\t\t\t++MusicVolume;\n\t\t\telse\n\t\t\t\tbreak;\n\n\t\t\tIsInvOptionsDelay = TRUE;\n\t\t\tInvOptionsDelayCounter = 5 * TICKS_PER_FRAME;\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tS_CDVolume(( MusicVolume == 0 ) ? 0 : (25 * MusicVolume + 5));\n\t\t\tif( SavedAppSettings.RenderMode != RM_Hardware || !InvTextBoxMode ) {\n\t\t\t\tsprintf(volumeString, \"%2d\", MusicVolume);\n\t\t\t\tT_ChangeText(SoundTextInfo[6], volumeString);\n\t\t\t\tPlaySoundEffect(115, NULL, SFX_ALWAYS); // page flip SFX\n\t\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\t\tsprintf(volumeString, \"| %2d\", MusicVolume); // Char '|' is musical note picture\n\t\t\tT_ChangeText(SoundTextInfo[0], volumeString);\n\t\t\tS_CDVolume(( MusicVolume == 0 ) ? 0 : (25 * MusicVolume + 5));\n\t\t\tPlaySoundEffect(115, NULL, SFX_ALWAYS); // page flip SFX\n#endif // FEATURE_HUD_IMPROVED\n\t\t\tbreak;\n\n\t\tcase 1 :\n\t\t\tif( CHK_ANY(InputStatus, IN_LEFT) && SoundVolume > 0 )\n\t\t\t\t--SoundVolume;\n\t\t\telse if( CHK_ANY(InputStatus, IN_RIGHT) && SoundVolume < 10 )\n\t\t\t\t++SoundVolume;\n\t\t\telse\n\t\t\t\tbreak;\n\n\t\t\tIsInvOptionsDelay = TRUE;\n\t\t\tInvOptionsDelayCounter = 5 * TICKS_PER_FRAME;\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tS_SoundSetMasterVolume(( SoundVolume == 0 ) ? 0 : (6 * SoundVolume + 4));\n\t\t\tif( SavedAppSettings.RenderMode != RM_Hardware || !InvTextBoxMode ) {\n\t\t\t\tsprintf(volumeString, \"%2d\", SoundVolume);\n\t\t\t\tT_ChangeText(SoundTextInfo[7], volumeString);\n\t\t\t\tPlaySoundEffect(115, NULL, SFX_ALWAYS); // page flip SFX\n\t\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\t\tsprintf(volumeString, \"} %2d\", SoundVolume); // Char '}' is dynamic speaker picture\n\t\t\tT_ChangeText(SoundTextInfo[1], volumeString);\n\t\t\tS_SoundSetMasterVolume(( SoundVolume == 0 ) ? 0 : (6 * SoundVolume + 4));\n\t\t\tPlaySoundEffect(115, NULL, SFX_ALWAYS); // page flip SFX\n#endif // FEATURE_HUD_IMPROVED\n\t\t\tbreak;\n\n\t\tdefault :\n\t\t\tbreak;\n\t}\n\n#ifndef FEATURE_HUD_IMPROVED\n\t// NOTE: this is leftover from the original code. The code is unused\n\tInvSpriteSoundVolume[6].param1 = SoundVolume;\n\tInvSpriteSoundVolumeLow[6].param1 = SoundVolume;\n\tInvSpriteMusicVolume[6].param1 = MusicVolume;\n\tInvSpriteMusicVolumeLow[6].param1 = MusicVolume;\n#endif // FEATURE_HUD_IMPROVED\n\n\tif( CHK_ANY(InputDB, IN_SELECT|IN_DESELECT) ) {\n\t\tfor( i=0; i<ARRAY_SIZE(SoundTextInfo); ++i ) {\n\t\t\tT_RemovePrint(SoundTextInfo[i]);\n\t\t\tSoundTextInfo[i] = NULL;\n\t\t}\n\t}\n}\n\nvoid __cdecl do_compass_option(INVENTORY_ITEM *item) {\n\tif( CurrentLevel == 0 ) {\n\t\t// level is Assault (Lara's Home)\n\t\tShowGymStatsText();\n\t} else {\n\t\t// normal level\n\t\tint hours, minutes, seconds;\n\t\tchar timeString[32] = {0};\n\n\t\tseconds = SaveGame.statistics.timer / 30 % 60;\n\t\tminutes = SaveGame.statistics.timer / 30 / 60 % 60;\n\t\thours   = SaveGame.statistics.timer / 30 / 60 / 60;\n\t\tsprintf(timeString, \"%02d:%02d:%02d\", hours, minutes, seconds);\n\t\tShowStatsText(timeString, TRUE);\n\t}\n\n\tif( CHK_ANY(InputDB, IN_SELECT|IN_DESELECT) ) {\n\t\titem->animDirection = 1;\n\t\titem->goalFrame = item->framesTotal - 1;\n\t}\n\n\tPlaySoundEffect(113, NULL, SFX_ALWAYS); // ticking clock sound\n}\n\nvoid __cdecl FlashConflicts() {\n\tUINT16 key;\n\tDWORD skip = 0;\n#ifdef FEATURE_HUD_IMPROVED\n\tif( LayoutPage == CTRL_Joystick ) skip = 4;\n#endif // FEATURE_HUD_IMPROVED\n\n\tfor( DWORD i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\tkey = Layout[LayoutPage].key[i];\n\t\tT_FlashText(CtrlTextB[i], 0, 0);\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( i<skip ) continue;\n#endif // FEATURE_HUD_IMPROVED\n\t\tfor( DWORD j=skip; j<CONTROL_LINE_COUNT*2; ++j ) {\n\t\t\tif( (i != j) && (key == Layout[LayoutPage].key[j]) ) {\n\t\t\t\tT_FlashText(CtrlTextB[i], 1, 20);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid __cdecl DefaultConflict() {\n\tfor( DWORD i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\tConflictLayout[i] = false;\n\n\t\tfor( DWORD j=0; j<CONTROL_LINE_COUNT*2; ++j ) {\n\t\t\tif( Layout[CTRL_Custom].key[j] == Layout[CTRL_Default].key[i] ) {\n\t\t\t\tConflictLayout[i] = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\n#ifdef FEATURE_HUD_IMPROVED\nstatic const char *GetControlsHeaderString() {\n\tconst char *header = (LayoutPage == CTRL_Joystick) ? \"Gamepad\" : \"Keyboard\";\n\tif( SavedAppSettings.RenderMode == RM_Hardware && InvTextBoxMode && KeyCursor < 0 ) {\n\t\tstatic char text[64] = {0};\n\t\tsnprintf(text, sizeof(text), \" \\x11    %s   \\x12  \", header);\n\t\treturn text;\n\t}\n\treturn header;\n}\n#endif // FEATURE_HUD_IMPROVED\n\nvoid __cdecl do_control_option(INVENTORY_ITEM *item) {\n\tstatic int KeySelector = 0;\n\tint i;\n\n#ifdef FEATURE_HUD_IMPROVED\n#ifdef FEATURE_INPUT_IMPROVED\n\tbool isJoystickUnavailable = ( GetJoystickType() == JT_NONE );\n#else // FEATURE_INPUT_IMPROVED\n\tbool isJoystickUnavailable = ( !SavedAppSettings.JoystickEnabled || !SavedAppSettings.PreferredJoystick );\n#endif // FEATURE_INPUT_IMPROVED\n\tstatic int renderWidth = 0;\n\tif( renderWidth != GetRenderWidthDownscaled() ) {\n\t\tT_RemovePrint(ControlTextInfo[0]);\n\t\tControlTextInfo[0] = NULL;\n\t\tT_RemovePrint(ControlTextInfo[1]);\n\t\tControlTextInfo[1] = NULL;\n\t\tS_RemoveCtrlText();\n\t\trenderWidth = GetRenderWidthDownscaled();\n\t}\n#endif // !FEATURE_HUD_IMPROVED\n\n\tif( ControlTextInfo[0] == NULL ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( isJoystickUnavailable ) {\n\t\t\tLayoutPage = CTRL_Custom;\n\t\t\tKeyCursor = 0;\n\t\t} else {\n\t\t\tKeyCursor = -1;\n\t\t}\n\t\tKeySelector = 0;\n\t\tControlTextInfo[0] = T_Print(0, CONTROL_Y_TITLE, 0, GetControlsHeaderString());\n#else // FEATURE_HUD_IMPROVED\n\t\tControlTextInfo[0] = T_Print(0, CONTROL_Y_TITLE, 0, GF_SpecificStringTable[(LayoutPage == CTRL_Default) ? SSI_DefaultKeys : SSI_UserKeys]);\n#endif // FEATURE_HUD_IMPROVED\n\t\tT_CentreH(ControlTextInfo[0], 1);\n\t\tT_CentreV(ControlTextInfo[0], 1);\n\n\t\tS_ShowControls();\n#ifdef FEATURE_HUD_IMPROVED\n\t\tif( KeyCursor == -1 ) {\n\t\t\tT_AddBackground(ControlTextInfo[0], 0, 0, 0, 0, CONTROL_FARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\t\tT_AddOutline(ControlTextInfo[0], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\t\t} else {\n\t\t\tCtrlTextA[KeyCursor]->zPos = 0;\n\t\t\tT_AddBackground(CtrlTextA[KeyCursor], 0, 0, 0, 0, 0, ICLR_Black, &ReqSelGour1, 0);\n\t\t\tT_AddOutline(CtrlTextA[KeyCursor], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\tKeyCursor = -1;\n\t\tT_AddBackground(ControlTextInfo[0], 0, 0, 0, 0, CONTROL_FARZ, ICLR_Black, &ReqSelGour1, 0);\n\t\tT_AddOutline(ControlTextInfo[0], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n#endif // FEATURE_HUD_IMPROVED\n\t\tFlashConflicts(); // NOTE: this line is absent in the original game\n\t}\n\n\tswitch( KeySelector ) {\n\t\tcase 0 :\n\t\t\tif( CHK_ANY(InputDB, IN_LEFT|IN_RIGHT) ) {\n\t\t\t\tif( KeyCursor == -1 ) {\n\t\t\t\t\tLayoutPage = !LayoutPage;\n\t\t\t\t\tS_ChangeCtrlText();\n\t\t\t\t\tFlashConflicts();\n\t\t\t\t} else {\n\t\t\t\t\tCtrlTextA[KeyCursor]->zPos = CONTROL_NEARZ;\n\t\t\t\t\tT_RemoveBackground(CtrlTextA[KeyCursor]);\n\t\t\t\t\tT_RemoveOutline(CtrlTextA[KeyCursor]);\n\n\t\t\t\t\tif( KeyCursor < (int)CONTROL_LINE_COUNT ) {\n\t\t\t\t\t\tKeyCursor += CONTROL_LINE_COUNT;\n\t\t\t\t\t} else if ( KeyCursor < (int)CONTROL_LINE_COUNT*2 ) {\n\t\t\t\t\t\tKeyCursor -= CONTROL_LINE_COUNT;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tKeyCursor = CONTROL_LINE_COUNT;\n\t\t\t\t\t}\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\t\twhile( KeyCursor >= 0 && !*CtrlTextA[KeyCursor]->pString ) {\n\t\t\t\t\t\t--KeyCursor;\n\t\t\t\t\t}\n\t\t\t\t\tif( KeyCursor == -1 ) {\n\t\t\t\t\t\twhile( ++KeyCursor < (int)CONTROL_LINE_COUNT*2 && !*CtrlTextA[KeyCursor]->pString ) {}\n\t\t\t\t\t}\n\n\t\t\t\t\tT_ChangeText(ControlTextInfo[0], GetControlsHeaderString());\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t\t\tCtrlTextA[KeyCursor]->zPos = 0;\n\t\t\t\t\tT_AddBackground(CtrlTextA[KeyCursor], 0, 0, 0, 0, 0, ICLR_Black, &ReqSelGour1, 0);\n\t\t\t\t\tT_AddOutline(CtrlTextA[KeyCursor], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if( (CHK_ANY(InputDB, IN_DESELECT) && !CHK_ANY(InputDB, IN_SELECT)) || (CHK_ANY(InputDB, IN_SELECT) && KeyCursor == -1) ) {\n\t\t\t\tT_RemovePrint(ControlTextInfo[0]);\n\t\t\t\tControlTextInfo[0] = NULL;\n\t\t\t\tT_RemovePrint(ControlTextInfo[1]);\n\t\t\t\tControlTextInfo[1] = NULL;\n\t\t\t\tS_RemoveCtrlText();\n\t\t\t\tDefaultConflict();\n\t\t\t\treturn;\n\t\t\t}\n\n#ifndef FEATURE_HUD_IMPROVED\n\t\t\tif( LayoutPage == CTRL_Default )\n\t\t\t\tbreak;\n#endif // FEATURE_HUD_IMPROVED\n\n\t\t\tif( CHK_ANY(InputDB, IN_SELECT) ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\tif( LayoutPage == CTRL_Joystick && KeyCursor >= 0 && KeyCursor < 4 ) {\n\t\t\t\t\tT_ChangeText(CtrlTextB[KeyCursor], JoystickOpts[KeyCursor].toggle());\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tUpdateJoystickHintText(HINT_HIDDEN, HINT_KEYBOARD, HINT_KEYBOARD);\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t\tKeySelector = 1;\n\n\t\t\t\tCtrlTextA[KeyCursor]->zPos = CONTROL_NEARZ;\n\t\t\t\tT_RemoveBackground(CtrlTextA[KeyCursor]);\n\t\t\t\tT_RemoveOutline(CtrlTextA[KeyCursor]);\n\n\t\t\t\tCtrlTextB[KeyCursor]->zPos = 0;\n\t\t\t\tT_AddBackground(CtrlTextB[KeyCursor], 0, 0, 0, 0, 0, ICLR_Black, &ReqSelGour1, 0);\n\t\t\t\tT_AddOutline(CtrlTextB[KeyCursor], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\t\t\t}\n\t\t\telse if( CHK_ANY(InputDB, IN_FORWARD) ) {\n\t\t\t\tif( KeyCursor == -1 ) {\n\t\t\t\t\tT_RemoveBackground(ControlTextInfo[0]);\n\t\t\t\t\tT_RemoveOutline(ControlTextInfo[0]);\n\t\t\t\t} else {\n\t\t\t\t\tCtrlTextA[KeyCursor]->zPos = CONTROL_NEARZ;\n\t\t\t\t\tT_RemoveBackground(CtrlTextA[KeyCursor]);\n\t\t\t\t\tT_RemoveOutline(CtrlTextA[KeyCursor]);\n\t\t\t\t}\n\n\t\t\t\tif( --KeyCursor < -1 ) {\n\t\t\t\t\tKeyCursor = CONTROL_LINE_COUNT*2 - 1;\n\t\t\t\t}\n\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\twhile( KeyCursor >= 0 && !*CtrlTextA[KeyCursor]->pString ) {\n\t\t\t\t\t--KeyCursor;\n\t\t\t\t}\n\n\t\t\t\tif( isJoystickUnavailable && KeyCursor == -1 ) {\n\t\t\t\t\tKeyCursor = CONTROL_LINE_COUNT*2 - 1;\n\t\t\t\t\twhile( KeyCursor >= 0 && !*CtrlTextA[KeyCursor]->pString ) {\n\t\t\t\t\t\t--KeyCursor;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tT_ChangeText(ControlTextInfo[0], GetControlsHeaderString());\n#endif // FEATURE_HUD_IMPROVED\n\n\t\t\t\tif( KeyCursor == -1 ) {\n\t\t\t\t\tT_AddBackground(ControlTextInfo[0], 0, 0, 0, 0, 0, ICLR_Black, &ReqSelGour1, 0);\n\t\t\t\t\tT_AddOutline(ControlTextInfo[0], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\t\t\t\t} else {\n\t\t\t\t\tCtrlTextA[KeyCursor]->zPos = 0;\n\t\t\t\t\tT_AddBackground(CtrlTextA[KeyCursor], 0, 0, 0, 0, 0, ICLR_Black, &ReqSelGour1, 0);\n\t\t\t\t\tT_AddOutline(CtrlTextA[KeyCursor], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if( CHK_ANY(InputDB, IN_BACK) ) {\n\t\t\t\tif( KeyCursor == -1 ) {\n\t\t\t\t\tT_RemoveBackground(ControlTextInfo[0]);\n\t\t\t\t\tT_RemoveOutline(ControlTextInfo[0]);\n\t\t\t\t} else {\n\t\t\t\t\tCtrlTextA[KeyCursor]->zPos = CONTROL_NEARZ;\n\t\t\t\t\tT_RemoveBackground(CtrlTextA[KeyCursor]);\n\t\t\t\t\tT_RemoveOutline(CtrlTextA[KeyCursor]);\n\t\t\t\t}\n\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\t++KeyCursor;\n\t\t\t\twhile( KeyCursor < (int)CONTROL_LINE_COUNT*2 && !*CtrlTextA[KeyCursor]->pString ) {\n\t\t\t\t\t++KeyCursor;\n\t\t\t\t}\n\t\t\t\tif( KeyCursor >= (int)CONTROL_LINE_COUNT*2 ) {\n\t\t\t\t\tif( isJoystickUnavailable ) {\n\t\t\t\t\t\tKeyCursor = 0;\n\t\t\t\t\t\twhile( KeyCursor < (int)CONTROL_LINE_COUNT*2 && !*CtrlTextA[KeyCursor]->pString ) {\n\t\t\t\t\t\t\t++KeyCursor;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tKeyCursor = -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tT_ChangeText(ControlTextInfo[0], GetControlsHeaderString());\n#else // FEATURE_HUD_IMPROVED\n\t\t\t\tif( ++KeyCursor >= (int)CONTROL_LINE_COUNT*2 ) {\n\t\t\t\t\tKeyCursor = -1;\n\t\t\t\t}\n#endif // FEATURE_HUD_IMPROVED\n\n\t\t\t\tif( KeyCursor == -1 ) {\n\t\t\t\t\tT_AddBackground(ControlTextInfo[0], 0, 0, 0, 0, 0, ICLR_Black, &ReqSelGour1, 0);\n\t\t\t\t\tT_AddOutline(ControlTextInfo[0], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\t\t\t\t} else {\n\t\t\t\t\tCtrlTextA[KeyCursor]->zPos = 0;\n\t\t\t\t\tT_AddBackground(CtrlTextA[KeyCursor], 0, 0, 0, 0, 0, ICLR_Black, &ReqSelGour1, 0);\n\t\t\t\t\tT_AddOutline(CtrlTextA[KeyCursor], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 1:\n\t\t\t// NOTE: InputDB replaced by InputStatus here. This fixes the original game bug\n\t\t\tif( !CHK_ANY(InputStatus, IN_SELECT) && !CHK_ANY(DIKeys[DIK_RETURN], 0x80) ) {\n\t\t\t\tKeySelector = 2;\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 2:\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\ti = 0;\n\t\t\tif( LayoutPage == CTRL_Joystick && CHK_ANY(JoyKeys, 0xFFFF) ) {\n\t\t\t\tfor( i = 0; i < 0x10; ++i ) {\n\t\t\t\t\tif( CHK_ANY((1 << i), JoyKeys) )\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif( i == 0x10 ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ti += 0x100;\n\t\t\t} else if( LayoutPage == CTRL_Custom || CHK_ANY(DIKeys[DIK_ESCAPE], 0x80) )\n#else // FEATURE_HUD_IMPROVED\n\t\t\tif( JoyKeys != 0 ) {\n\t\t\t\tfor( i = 0; i < 0x20; ++i ) {\n\t\t\t\t\tif( CHK_ANY((1 << i), JoyKeys) )\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif( i == 0x20 ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ti += 0x100;\n\t\t\t} else\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t{\n\t\t\t\tfor( i = 0; i < 0x100; ++i ) {\n\t\t\t\t\tif( CHK_ANY(DIKeys[i], 0x80) )\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif( i == 0x100 ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif( i != 0 && ControlKeysText[i] != NULL && i != DIK_RETURN &&\n\t\t\t\ti != DIK_LEFT && i != DIK_RIGHT && i != DIK_UP && i != DIK_DOWN )\n\t\t\t{\n\t\t\t\tif( i != DIK_ESCAPE ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\t\t\tLayout[LayoutPage].key[KeyCursor] = (i >= 0x100) ? i-0x100 : i;\n\t\t\t\t\tif( Layout[LayoutPage].key[KeyCursor] == DIK_LCONTROL )\n\t\t\t\t\t\tLayout[LayoutPage].key[KeyCursor] = DIK_RCONTROL;\n\t\t\t\t\tif( Layout[LayoutPage].key[KeyCursor] == DIK_LSHIFT )\n\t\t\t\t\t\tLayout[LayoutPage].key[KeyCursor] = DIK_RSHIFT;\n\t\t\t\t\tif( Layout[LayoutPage].key[KeyCursor] == DIK_LMENU )\n\t\t\t\t\t\tLayout[LayoutPage].key[KeyCursor] = DIK_RMENU;\n\t\t\t\t\tDefaultConflict();\n\t\t\t\t\tS_ChangeCtrlText();\n#else // FEATURE_HUD_IMPROVED\n\t\t\t\t\tLayout[LayoutPage].key[KeyCursor] = i;\n\t\t\t\t\tT_ChangeText(CtrlTextB[KeyCursor], ControlKeysText[i]);\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t\t}\n\n\t\t\t\tCtrlTextB[KeyCursor]->zPos = CONTROL_NEARZ;\n\t\t\t\tT_RemoveBackground(CtrlTextB[KeyCursor]);\n\t\t\t\tT_RemoveOutline(CtrlTextB[KeyCursor]);\n\n\t\t\t\tCtrlTextA[KeyCursor]->zPos = 0;\n\t\t\t\tT_AddBackground(CtrlTextA[KeyCursor], 0, 0, 0, 0, 0, ICLR_Black, &ReqSelGour1, 0);\n\t\t\t\tT_AddOutline(CtrlTextA[KeyCursor], TRUE, ICLR_Blue, &ReqSelGour2, 0);\n\n\t\t\t\tKeySelector = 3;\n\t\t\t\tFlashConflicts();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 3:\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tif( LayoutPage == CTRL_Joystick )\n#else // FEATURE_HUD_IMPROVED\n\t\t\tif( CHK_ANY(Layout[LayoutPage].key[KeyCursor], 0x100) )\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t{\n\t\t\t\tif( !CHK_ANY((1 << Layout[LayoutPage].key[KeyCursor]), JoyKeys) ) {\n\t\t\t\t\tKeySelector = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if( !CHK_ANY(DIKeys[Layout[LayoutPage].key[KeyCursor]], 0x80) ) {\n\t\t\t\tKeySelector = 0;\n#ifndef FEATURE_HUD_IMPROVED\n\t\t\t\tif( Layout[LayoutPage].key[KeyCursor] == DIK_LCONTROL )\n\t\t\t\t\tLayout[LayoutPage].key[KeyCursor] = DIK_RCONTROL;\n\t\t\t\tif( Layout[LayoutPage].key[KeyCursor] == DIK_LSHIFT )\n\t\t\t\t\tLayout[LayoutPage].key[KeyCursor] = DIK_RSHIFT;\n\t\t\t\tif( Layout[LayoutPage].key[KeyCursor] == DIK_LMENU )\n\t\t\t\t\tLayout[LayoutPage].key[KeyCursor] = DIK_RMENU;\n\t\t\t\tFlashConflicts();\n#endif // FEATURE_HUD_IMPROVED\n\t\t\t}\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tif( KeySelector == 0 ) {\n\t\t\t\tUpdateJoystickHintText(HINT_JOYSTICK, HINT_JOYSTICK, HINT_JOYSTICK);\n\t\t\t}\n#endif // FEATURE_HUD_IMPROVED\n\t\t\tbreak;\n\t}\n\n\tInputStatus = 0;\n\tInputDB = 0;\n}\n\nvoid __cdecl S_ShowControls() {\n\tDWORD i;\n\tint x0, x1, xCenter;\n\tbool isCompact;\n\n#ifdef FEATURE_HUD_IMPROVED\n\txCenter = GetRenderWidthDownscaled() / 2;\n\tisCompact = (xCenter < (CONTROL_WIDTH_HIGH + 20) / 2);\n\n\tif( CtrlTextC[0] == NULL ) {\n\t\tx1 = CONTROL_COLUMN_C;\n\t\tx0 = x1 - (isCompact ? CONTROL_WIDTH_LOW : CONTROL_WIDTH_HIGH) / 2;\n\n\t\tCtrlTextC[0]  = T_Print(x0, CONTROL_Y_LINE1, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[0]]);\n\t\tCtrlTextC[1]  = T_Print(x0, CONTROL_Y_LINE2, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[1]]);\n\t\tCtrlTextC[2]  = T_Print(x0, CONTROL_Y_LINE3, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[2]]);\n\t\tCtrlTextC[3]  = T_Print(x0, CONTROL_Y_LINE4, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[3]]);\n\t\tCtrlTextC[4]  = T_Print(x0, CONTROL_Y_LINE5, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[4]]);\n\t\tCtrlTextC[5]  = T_Print(x0, CONTROL_Y_LINE6, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[5]]);\n\t\tCtrlTextC[6]  = T_Print(x0, CONTROL_Y_LINE7, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[6]]);\n\t\tCtrlTextC[7]  = T_Print(x0, CONTROL_Y_LINE8, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[7]]);\n\n\t\tCtrlTextC[8]  = T_Print(x1, CONTROL_Y_LINE1, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[8]]);\n\t\tCtrlTextC[9]  = T_Print(x1, CONTROL_Y_LINE2, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[9]]);\n\t\tCtrlTextC[10] = T_Print(x1, CONTROL_Y_LINE3, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[10]]);\n\t\tCtrlTextC[11] = T_Print(x1, CONTROL_Y_LINE4, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[11]]);\n\t\tCtrlTextC[12] = T_Print(x1, CONTROL_Y_LINE5, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[12]]);\n\t\tCtrlTextC[13] = T_Print(x1, CONTROL_Y_LINE6, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[13]]);\n\t\tCtrlTextC[14] = T_Print(x1, CONTROL_Y_LINE7, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[14]]);\n\t\tCtrlTextC[15] = T_Print(x1, CONTROL_Y_LINE8, CONTROL_NEARZ, ControlKeysText[Layout[CTRL_Default].key[15]]);\n\n\t\tfor( i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\t\tT_CentreV(CtrlTextC[i], 1);\n\t\t\tT_CentreH(CtrlTextC[i], 1);\n\t\t\tT_HideText(CtrlTextC[i], (LayoutPage == CTRL_Joystick || ConflictLayout[i]) ? 1 : 0);\n\t\t}\n\t}\n#else // !FEATURE_HUD_IMPROVED\n\txCenter = GetRenderWidth() / 2;\n\tCLAMPG(xCenter, 320);\n\tisCompact = (xCenter < 320);\n#endif // FEATURE_HUD_IMPROVED\n\n\tif( CtrlTextB[0] == NULL ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\tDWORD base = (LayoutPage == CTRL_Joystick) ? 0x100 : 0;\n\n\t\tx1 = ( LayoutPage == CTRL_Joystick ) ? CONTROL_COLUMN_B2 : CONTROL_COLUMN_B1;\n\t\tx0 = x1 - (isCompact ? CONTROL_WIDTH_LOW : CONTROL_WIDTH_HIGH) / 2;\n\n\t\tif( LayoutPage == CTRL_Joystick ) {\n\t\t\tCtrlTextB[0]  = T_Print(x0, CONTROL_Y_LINE1, CONTROL_NEARZ, JoystickOpts[0].getState());\n\t\t\tCtrlTextB[1]  = T_Print(x0, CONTROL_Y_LINE2, CONTROL_NEARZ, JoystickOpts[1].getState());\n\t\t\tCtrlTextB[2]  = T_Print(x0, CONTROL_Y_LINE3, CONTROL_NEARZ, JoystickOpts[2].getState());\n\t\t\tCtrlTextB[3]  = T_Print(x0, CONTROL_Y_LINE4, CONTROL_NEARZ, JoystickOpts[3].getState());\n\t\t} else {\n\t\t\tCtrlTextB[0]  = T_Print(x0, CONTROL_Y_LINE1, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[0]]);\n\t\t\tCtrlTextB[1]  = T_Print(x0, CONTROL_Y_LINE2, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[1]]);\n\t\t\tCtrlTextB[2]  = T_Print(x0, CONTROL_Y_LINE3, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[2]]);\n\t\t\tCtrlTextB[3]  = T_Print(x0, CONTROL_Y_LINE4, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[3]]);\n\t\t}\n\t\tCtrlTextB[4]  = T_Print(x0, CONTROL_Y_LINE5, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[4]]);\n\t\tCtrlTextB[5]  = T_Print(x0, CONTROL_Y_LINE6, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[5]]);\n\t\tCtrlTextB[6]  = T_Print(x0, CONTROL_Y_LINE7, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[6]]);\n\t\tCtrlTextB[7]  = T_Print(x0, CONTROL_Y_LINE8, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[7]]);\n\n\t\tCtrlTextB[8]  = T_Print(x1, CONTROL_Y_LINE1, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[8]]);\n\t\tCtrlTextB[9]  = T_Print(x1, CONTROL_Y_LINE2, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[9]]);\n\t\tCtrlTextB[10] = T_Print(x1, CONTROL_Y_LINE3, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[10]]);\n\t\tCtrlTextB[11] = T_Print(x1, CONTROL_Y_LINE4, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[11]]);\n\t\tCtrlTextB[12] = T_Print(x1, CONTROL_Y_LINE5, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[12]]);\n\t\tCtrlTextB[13] = T_Print(x1, CONTROL_Y_LINE6, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[13]]);\n\t\tCtrlTextB[14] = T_Print(x1, CONTROL_Y_LINE7, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[14]]);\n\t\tCtrlTextB[15] = T_Print(x1, CONTROL_Y_LINE8, CONTROL_NEARZ, ControlKeysText[base + Layout[LayoutPage].key[15]]);\n\n\t\tfor( i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\t\tx1 = CONTROL_COLUMN_B2;\n\t\t\tx0 = x1 - (isCompact ? CONTROL_WIDTH_LOW : CONTROL_WIDTH_HIGH) / 2;\n\t\t\tif( LayoutPage != CTRL_Joystick && ConflictLayout[i] ) {\n\t\t\t\tCtrlTextB[i]->xPos = (i < CONTROL_LINE_COUNT) ? x0 : x1;\n\t\t\t}\n\t\t\tT_CentreH(CtrlTextB[i], 1);\n\t\t\tT_CentreV(CtrlTextB[i], 1);\n\t\t}\n#else // FEATURE_HUD_IMPROVED\n\t\tx0 = xCenter - (isCompact ? CONTROL_WIDTH_LOW : CONTROL_WIDTH_HIGH) / 2 + CONTROL_COLUMN_B;\n\t\tx1 = xCenter + CONTROL_COLUMN_B;\n\n\t\tCtrlTextB[0]  = T_Print(x0, CONTROL_Y_LINE1, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[0]]);\n\t\tCtrlTextB[1]  = T_Print(x0, CONTROL_Y_LINE2, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[1]]);\n\t\tCtrlTextB[2]  = T_Print(x0, CONTROL_Y_LINE3, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[2]]);\n\t\tCtrlTextB[3]  = T_Print(x0, CONTROL_Y_LINE4, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[3]]);\n\t\tCtrlTextB[4]  = T_Print(x0, CONTROL_Y_LINE5, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[4]]);\n\t\tCtrlTextB[5]  = T_Print(x0, CONTROL_Y_LINE6, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[5]]);\n\t\tCtrlTextB[6]  = T_Print(x0, CONTROL_Y_LINE7, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[6]]);\n\n\t\tCtrlTextB[7]  = T_Print(x1, CONTROL_Y_LINE1, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[7]]);\n\t\tCtrlTextB[8]  = T_Print(x1, CONTROL_Y_LINE2, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[8]]);\n\t\tCtrlTextB[9]  = T_Print(x1, CONTROL_Y_LINE3, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[9]]);\n\t\tCtrlTextB[10] = T_Print(x1, CONTROL_Y_LINE4, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[10]]);\n\t\tCtrlTextB[11] = T_Print(x1, CONTROL_Y_LINE5, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[11]]);\n\t\tCtrlTextB[12] = T_Print(x1, CONTROL_Y_LINE6, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[12]]);\n\t\tCtrlTextB[13] = T_Print(x1, CONTROL_Y_LINE7, CONTROL_NEARZ, ControlKeysText[Layout[LayoutPage].key[13]]);\n\n\t\tfor( i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\t\tT_CentreV(CtrlTextB[i], 1);\n\t\t}\n\n\t\tKeyCursor = 0;\n#endif // FEATURE_HUD_IMPROVED\n\t}\n\n\tif( CtrlTextA[0] == NULL ) {\n\t\tx0 = xCenter - (isCompact ? CONTROL_WIDTH_LOW : CONTROL_WIDTH_HIGH) / 2 + CONTROL_COLUMN_A;\n#ifdef FEATURE_HUD_IMPROVED\n\t\tx1 = xCenter + CONTROL_COLUMN_A;\n\n\t\tif( LayoutPage == CTRL_Joystick ) {\n\t\t\tCtrlTextA[0]  = T_Print(x0, CONTROL_Y_LINE1, CONTROL_NEARZ, JoystickOpts[0].getName());\n\t\t\tCtrlTextA[1]  = T_Print(x0, CONTROL_Y_LINE2, CONTROL_NEARZ, JoystickOpts[1].getName());\n\t\t\tCtrlTextA[2]  = T_Print(x0, CONTROL_Y_LINE3, CONTROL_NEARZ, JoystickOpts[2].getName());\n\t\t\tCtrlTextA[3]  = T_Print(x0, CONTROL_Y_LINE4, CONTROL_NEARZ, JoystickOpts[3].getName());\n\t\t} else {\n\t\t\tCtrlTextA[0]  = T_Print(x0, CONTROL_Y_LINE1, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Run]);\n\t\t\tCtrlTextA[1]  = T_Print(x0, CONTROL_Y_LINE2, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Back]);\n\t\t\tCtrlTextA[2]  = T_Print(x0, CONTROL_Y_LINE3, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Left]);\n\t\t\tCtrlTextA[3]  = T_Print(x0, CONTROL_Y_LINE4, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Right]);\n\t\t}\n\t\tCtrlTextA[4]  = T_Print(x0, CONTROL_Y_LINE5, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_StepLeft]);\n\t\tCtrlTextA[5]  = T_Print(x0, CONTROL_Y_LINE6, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_StepRight]);\n\t\tCtrlTextA[6]  = T_Print(x0, CONTROL_Y_LINE7, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Step]);\n\t\tCtrlTextA[7]  = T_Print(x0, CONTROL_Y_LINE8, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Walk]);\n\n\t\tCtrlTextA[8]  = T_Print(x1, CONTROL_Y_LINE1, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Jump]);\n\t\tCtrlTextA[9]  = T_Print(x1, CONTROL_Y_LINE2, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Action]);\n\t\tCtrlTextA[10] = T_Print(x1, CONTROL_Y_LINE3, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Roll]);\n\t\tCtrlTextA[11] = T_Print(x1, CONTROL_Y_LINE4, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_DrawWeapon]);\n\t\tCtrlTextA[12] = T_Print(x1, CONTROL_Y_LINE5, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Flare]);\n\t\tCtrlTextA[13] = T_Print(x1, CONTROL_Y_LINE6, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Look]);\n\t\tCtrlTextA[14] = T_Print(x1, CONTROL_Y_LINE7, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Inventory]);\n\t\tCtrlTextA[15] = T_Print(x1, CONTROL_Y_LINE8, CONTROL_NEARZ, \"Pause\");\n#else // !FEATURE_HUD_IMPROVED\n\t\tx1 = xCenter + CONTROL_COLUMN_A + 10;\n\n\t\tCtrlTextA[0]  = T_Print(x0, CONTROL_Y_LINE1, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Run]);\n\t\tCtrlTextA[1]  = T_Print(x0, CONTROL_Y_LINE2, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Back]);\n\t\tCtrlTextA[2]  = T_Print(x0, CONTROL_Y_LINE3, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Left]);\n\t\tCtrlTextA[3]  = T_Print(x0, CONTROL_Y_LINE4, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Right]);\n\t\tCtrlTextA[4]  = T_Print(x0, CONTROL_Y_LINE5, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_StepLeft]);\n\t\tCtrlTextA[5]  = T_Print(x0, CONTROL_Y_LINE6, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_StepRight]);\n\t\tCtrlTextA[6]  = T_Print(x0, CONTROL_Y_LINE7, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Walk]);\n\n\t\tCtrlTextA[7]  = T_Print(x1, CONTROL_Y_LINE1, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Jump]);\n\t\tCtrlTextA[8]  = T_Print(x1, CONTROL_Y_LINE2, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Action]);\n\t\tCtrlTextA[9]  = T_Print(x1, CONTROL_Y_LINE3, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_DrawWeapon]);\n\t\tCtrlTextA[10] = T_Print(x1, CONTROL_Y_LINE4, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Flare]);\n\t\tCtrlTextA[11] = T_Print(x1, CONTROL_Y_LINE5, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Look]);\n\t\tCtrlTextA[12] = T_Print(x1, CONTROL_Y_LINE6, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Roll]);\n\t\tCtrlTextA[13] = T_Print(x1, CONTROL_Y_LINE7, CONTROL_NEARZ, GF_GameStringTable[GSI_Keymap_Inventory]);\n#endif // FEATURE_HUD_IMPROVED\n\t\tfor( i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\t\tT_CentreV(CtrlTextA[i], 1);\n\t\t}\n\t}\n\n\tControlTextInfo[1] = T_Print(0, CONTROL_Y_BOX, 0, \" \");\n\tT_CentreV(ControlTextInfo[1], 1);\n\tT_CentreH(ControlTextInfo[1], 1);\n\tT_AddOutline(ControlTextInfo[1], TRUE, ICLR_Blue, &ReqBgndGour2, 0);\n\n\tif( isCompact ) {\n\t\tfor( i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n#ifdef FEATURE_HUD_IMPROVED\n\t\t\tT_SetScale(CtrlTextA[i], PHD_ONE*3/4, PHD_ONE);\n#else // !FEATURE_HUD_IMPROVED\n\t\t\tT_SetScale(CtrlTextB[i], PHD_ONE/2, PHD_ONE);\n\t\t\tT_SetScale(CtrlTextA[i], PHD_ONE/2, PHD_ONE);\n#endif // FEATURE_HUD_IMPROVED\n\t\t}\n\t\tT_AddBackground(ControlTextInfo[1], CONTROL_WIDTH_LOW, CONTROL_HEIGHT_LOW, 0, 0, CONTROL_FARZ, ICLR_Black, &ReqBgndGour1, 0);\n\t} else {\n\t\tT_AddBackground(ControlTextInfo[1], CONTROL_WIDTH_HIGH, CONTROL_HEIGHT_HIGH, 0, 0, CONTROL_FARZ, ICLR_Black, &ReqBgndGour1, 0);\n\t}\n}\n\nvoid __cdecl S_ChangeCtrlText() {\n\tUINT16 key;\n#ifdef FEATURE_HUD_IMPROVED\n\tT_ChangeText(ControlTextInfo[0], GetControlsHeaderString());\n\n\tfor( DWORD i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\tT_HideText(CtrlTextC[i], (LayoutPage == CTRL_Joystick || ConflictLayout[i]) ? 1 : 0);\n\t}\n\n\tif( LayoutPage == CTRL_Joystick ) {\n\t\tfor( DWORD i=0; i<4; ++i ) {\n\t\t\tT_ChangeText(CtrlTextA[i], JoystickOpts[i].getName());\n\t\t\tT_ChangeText(CtrlTextB[i], JoystickOpts[i].getState());\n\t\t}\n\t} else {\n\t\tT_ChangeText(CtrlTextA[0], GF_GameStringTable[GSI_Keymap_Run]);\n\t\tT_ChangeText(CtrlTextA[1], GF_GameStringTable[GSI_Keymap_Back]);\n\t\tT_ChangeText(CtrlTextA[2], GF_GameStringTable[GSI_Keymap_Left]);\n\t\tT_ChangeText(CtrlTextA[3], GF_GameStringTable[GSI_Keymap_Right]);\n\t}\n\n\tbool isCompact = ( GetRenderWidthDownscaled() < CONTROL_WIDTH_HIGH + 20 );\n\tfor( DWORD i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\tint x1 = ( LayoutPage == CTRL_Joystick || ConflictLayout[i] ) ? CONTROL_COLUMN_B2 : CONTROL_COLUMN_B1;\n\t\tint x0 = x1 - (isCompact ? CONTROL_WIDTH_LOW : CONTROL_WIDTH_HIGH) / 2;\n\t\tCtrlTextB[i]->xPos = (i < CONTROL_LINE_COUNT) ? x0 : x1;\n\t\tT_CentreH(CtrlTextB[i], 1);\n\t}\n\n\tfor( DWORD i=(LayoutPage == CTRL_Joystick)? 4 : 0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\tkey = Layout[LayoutPage].key[i];\n\t\tswitch( LayoutPage ) {\n\t\t\tcase CTRL_Joystick:\n\t\t\t\tif( key < 0x10 && ControlKeysText[key+0x100] != NULL )\n\t\t\t\t\tT_ChangeText(CtrlTextB[i], ControlKeysText[key+0x100]);\n\t\t\t\telse\n\t\t\t\t\tT_ChangeText(CtrlTextB[i], \"?\");\n\t\t\t\tbreak;\n\t\t\tcase CTRL_Custom:\n\t\t\t\tif( key < 0x100 && ControlKeysText[key] != NULL )\n\t\t\t\t\tT_ChangeText(CtrlTextB[i], ControlKeysText[key]);\n\t\t\t\telse\n\t\t\t\t\tT_ChangeText(CtrlTextB[i], \"?\");\n\t\t\t\tbreak;\n\t\t}\n\t}\n#else // FEATURE_HUD_IMPROVED\n\tchar headerStr[40];\n\n\tif( LayoutPage == CTRL_Default ) {\n\t\tT_ChangeText(ControlTextInfo[0], GF_SpecificStringTable[SSI_DefaultKeys]);\n\t} else {\n\t\t// NOTE: it seems Core wanted to use several custom control layout pages\n\t\tsprintf(headerStr, GF_SpecificStringTable[SSI_UserKeys], LayoutPage);\n\t\tT_ChangeText(ControlTextInfo[0], headerStr);\n\t}\n\n\tfor( DWORD i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\tkey = Layout[LayoutPage].key[i];\n\t\t// NOTE: there was no key range check in the original code\n\t\tif( key < 0x110 && ControlKeysText[key] != NULL )\n\t\t\tT_ChangeText(CtrlTextB[i], ControlKeysText[key]);\n\t\telse\n\t\t\tT_ChangeText(CtrlTextB[i], \"BAD\");\n\t}\n#endif // FEATURE_HUD_IMPROVED\n}\n\nvoid __cdecl S_RemoveCtrlText() {\n\tfor( DWORD i=0; i<CONTROL_LINE_COUNT*2; ++i ) {\n\t\tT_RemovePrint(CtrlTextA[i]);\n\t\tT_RemovePrint(CtrlTextB[i]);\n\t\tCtrlTextA[i] = NULL;\n\t\tCtrlTextB[i] = NULL;\n#ifdef FEATURE_HUD_IMPROVED\n\t\tT_RemovePrint(CtrlTextC[i]);\n\t\tCtrlTextC[i] = NULL;\n#endif // FEATURE_HUD_IMPROVED\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Option() {\n\tINJECT(0x0044EE80, do_inventory_options);\n\tINJECT(0x0044EF90, do_passport_option);\n//\tINJECT(----------, do_gamma_option); // NOTE: this is null in the original code\n\tINJECT(0x0044F5E0, do_detail_option);\n\tINJECT(0x0044F8C0, do_sound_option);\n\tINJECT(0x0044FD60, do_compass_option);\n\tINJECT(0x0044FE20, FlashConflicts);\n\tINJECT(0x0044FEA0, DefaultConflict);\n\tINJECT(0x0044FEE0, do_control_option);\n\tINJECT(0x004505F0, S_ShowControls);\n\tINJECT(0x00450AC0, S_ChangeCtrlText);\n\tINJECT(0x00450B60, S_RemoveCtrlText);\n}\n"
  },
  {
    "path": "specific/option.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef OPTION_H_INCLUDED\n#define OPTION_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl do_inventory_options(INVENTORY_ITEM *item); // 0x0044EE80\nvoid __cdecl do_passport_option(INVENTORY_ITEM *item); // 0x0044EF90\nvoid __cdecl do_gamma_option(INVENTORY_ITEM *item); // ----------\nvoid __cdecl do_detail_option(INVENTORY_ITEM *item); // 0x0044F5E0\nvoid __cdecl do_sound_option(INVENTORY_ITEM *item); // 0x0044F8C0\nvoid __cdecl do_compass_option(INVENTORY_ITEM *item); // 0x0044FD60\nvoid __cdecl FlashConflicts(); // 0x0044FE20\nvoid __cdecl DefaultConflict(); // 0x0044FEA0\nvoid __cdecl do_control_option(INVENTORY_ITEM *item); // 0x0044FEE0\nvoid __cdecl S_ShowControls(); // 0x004505F0\nvoid __cdecl S_ChangeCtrlText(); // 0x00450AC0\nvoid __cdecl S_RemoveCtrlText(); // 0x00450B60\n\n#endif // OPTION_H_INCLUDED\n"
  },
  {
    "path": "specific/output.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/output.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"3dsystem/phd_math.h\"\n#include \"game/gameflow.h\"\n#include \"specific/background.h\"\n#include \"specific/display.h\"\n#include \"specific/file.h\"\n#include \"specific/game.h\"\n#include \"specific/hwr.h\"\n#include \"specific/init.h\"\n#include \"specific/init_display.h\"\n#include \"specific/input.h\"\n#include \"specific/texture.h\"\n#include \"specific/utils.h\"\n#include \"specific/winvid.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_HUD_IMPROVED\n#include \"modding/psx_bar.h\"\n\nDWORD HealthBarMode = 2;\nbool PsxBarPosEnabled = true;\ndouble GameGUI_Scale = 1.0;\ndouble InvGUI_Scale = 1.0;\n#endif // FEATURE_HUD_IMPROVED\n\n#ifdef FEATURE_VIEW_IMPROVED\nextern int CalculateFogShade(int depth);\n#endif // FEATURE_VIEW_IMPROVED\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nDWORD ShadowMode = 1;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/background_new.h\"\n\nextern DWORD BGND_PictureWidth;\nextern DWORD BGND_PictureHeight;\nextern bool BGND_IsCaptured;\n\nextern DWORD InvBackgroundMode;\nextern DWORD StatsBackgroundMode;\nextern bool IsFadeToBlack;\n\nDWORD PauseBackgroundMode = 1;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\ntypedef struct ShadowInfo_t {\n\t__int16 x;\n\t__int16 y;\n\t__int16 z;\n\t__int16 radius;\n\t__int16 polyCount;\n\t__int16 vertexCount;\n\tPOS_3D vertex[32]; // original size was 8\n} SHADOW_INFO;\n\n// NOTE: there was no such backup in the original game\nPHD_TEXTURE TextureBackupUV[ARRAY_SIZE(PhdTextureInfo)];\n\n#if (DIRECT3D_VERSION >= 0x900)\nstatic bool SWR_StretchBlt(SWR_BUFFER *dstBuf, RECT *dstRect, SWR_BUFFER *srcBuf, RECT *srcRect) {\n\tif( !srcBuf || !srcBuf->bitmap || !srcBuf->width || !srcBuf->height ||\n\t\t!dstBuf || !dstBuf->bitmap || !dstBuf->width || !dstBuf->height )\n\t{\n\t\treturn false;\n\t}\n\n\tint sx = 0;\n\tint sy = 0;\n\tint sw = srcBuf->width;\n\tint sh = srcBuf->height;\n\tif( srcRect ) {\n\t\tsx = srcRect->left;\n\t\tsy = srcRect->top;\n\t\tsw = srcRect->right;\n\t\tsh = srcRect->bottom;\n\t\tCLAMP(sx, 0, (int)srcBuf->width);\n\t\tCLAMP(sy, 0, (int)srcBuf->height);\n\t\tCLAMP(sw, 0, (int)srcBuf->width);\n\t\tCLAMP(sh, 0, (int)srcBuf->height);\n\t\tsw -= sx;\n\t\tsh -= sy;\n\t\tif( !sw || !sh ) return false;\n\t}\n\n\tint dx = 0;\n\tint dy = 0;\n\tint dw = dstBuf->width;\n\tint dh = dstBuf->height;\n\tif( dstRect ) {\n\t\tdx = dstRect->left;\n\t\tdy = dstRect->top;\n\t\tdw = dstRect->right;\n\t\tdh = dstRect->bottom;\n\t\tCLAMP(dx, 0, (int)dstBuf->width);\n\t\tCLAMP(dy, 0, (int)dstBuf->height);\n\t\tCLAMP(dw, 0, (int)dstBuf->width);\n\t\tCLAMP(dh, 0, (int)dstBuf->height);\n\t\tdw -= dx;\n\t\tdh -= dy;\n\t\tif( !dw || !dh ) return false;\n\t}\n\n\tif( dw < 0 ) {\n\t\tdx += dw;\n\t\tdw = -dw;\n\t\tsx += sw;\n\t\tsw = -sw;\n\t}\n\n\tif( dh < 0 ) {\n\t\tdy += dh;\n\t\tdh = -dh;\n\t\tsy += sh;\n\t\tsh = -sh;\n\t}\n\n\n\tint *x = (int *)malloc(sizeof(int) * dw);\n\tif( !x ) return false;\n\n\tfor( int i = 0; i < dw; ++i ) {\n\t\tx[i] = i * sw / dw;\n\t}\n\n\tfor( int j = 0; j < dh; ++j ) {\n\t\tint y = j * sh / dh;\n\t\tLPBYTE src = srcBuf->bitmap + srcBuf->width * y + sx;\n\t\tLPBYTE dst = dstBuf->bitmap + dstBuf->width * j + dx;\n\t\tfor( int i = 0; i < dw; ++i ) {\n\t\t\tdst[i] = src[x[i]];\n\t\t}\n\t}\n\n\tfree(x);\n\treturn true;\n}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\nint __cdecl GetRenderScale(int unit) {\n#ifdef FEATURE_HUD_IMPROVED\n\tint baseWidth = 640 / (IsVidSizeLock ? InvGUI_Scale : GameGUI_Scale);\n\tint baseHeight = 480 / (IsVidSizeLock ? InvGUI_Scale : GameGUI_Scale);\n#else // !FEATURE_HUD_IMPROVED\n\tint baseWidth = 640;\n\tint baseHeight = 480;\n#endif // FEATURE_HUD_IMPROVED\n\tint scaleX = (PhdWinWidth > baseWidth) ? MulDiv(PhdWinWidth, unit, baseWidth) : unit;\n\tint scaleY = (PhdWinHeight > baseHeight) ? MulDiv(PhdWinHeight, unit, baseHeight) : unit;\n\treturn MIN(scaleX, scaleY);\n}\n\nint __cdecl GetRenderHeightDownscaled() {\n\treturn PhdWinHeight * PHD_ONE / GetRenderScale(PHD_ONE);\n}\n\nint __cdecl GetRenderWidthDownscaled() {\n\treturn PhdWinWidth * PHD_ONE / GetRenderScale(PHD_ONE);\n}\n\nint __cdecl GetRenderHeight() {\n\treturn PhdWinHeight;\n}\n\nint __cdecl GetRenderWidth() {\n\treturn PhdWinWidth;\n}\n\nvoid __cdecl S_InitialisePolyList(BOOL clearBackBuffer) {\n\tDWORD flags = 0;\n\n\tif( WinVidNeedToResetBuffers ) {\n#if (DIRECT3D_VERSION < 0x900)\n\t\tRestoreLostBuffers();\n#endif // (DIRECT3D_VERSION < 0x900)\n\t\tWinVidSpinMessageLoop(false);\n\t\tif( SavedAppSettings.FullScreen ) {\n\t\t\tflags = CLRB_BackBuffer|CLRB_PrimaryBuffer;\n\t\t\tif( SavedAppSettings.RenderMode == RM_Software )\n\t\t\t\tflags |= CLRB_RenderBuffer;\n\t\t\tif( SavedAppSettings.TripleBuffering )\n\t\t\t\tflags |= CLRB_ThirdBuffer;\n#if (DIRECT3D_VERSION < 0x900)\n\t\t\tWaitPrimaryBufferFlip();\n#endif // (DIRECT3D_VERSION < 0x900)\n\t\t} else {\n\t\t\tflags = CLRB_WindowedPrimaryBuffer;\n\t\t\tif( SavedAppSettings.RenderMode == RM_Hardware )\n\t\t\t\tflags |= CLRB_BackBuffer;\n\t\t\telse\n\t\t\t\tflags |= CLRB_RenderBuffer;\n\t\t}\n\t\tClearBuffers(flags, 0);\n\t\tclearBackBuffer = FALSE; // already cleared here\n\t\tWinVidNeedToResetBuffers = false;\n\t}\n\n\tflags = CLRB_PhdWinSize;\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\t// Software Renderer\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tif( clearBackBuffer )\n\t\t\tflags |= CLRB_BackBuffer|CLRB_RenderBuffer;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tflags |= CLRB_RenderBuffer;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tClearBuffers(flags, 0);\n\t} else {\n\t\t// Hardware Renderer\n\t\tif( clearBackBuffer )\n\t\t\tflags |= CLRB_BackBuffer;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tif( SavedAppSettings.ZBuffer )\n\t\t\tflags |= CLRB_ZBuffer;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tif( SavedAppSettings.ZBuffer && ZBufferSurface != NULL )\n\t\t\tflags |= CLRB_ZBuffer;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\t\tClearBuffers(flags, 0);\n\t\tHWR_BeginScene();\n\t\tHWR_EnableZBuffer(true, true);\n\t}\n\tphd_InitPolyList();\n#if defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION < 0x900)\n\tFreeEnvmapTexture();\n#endif // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION < 0x900)\n}\n\nDWORD __cdecl S_DumpScreen() {\n\tDWORD ticks = SyncTicks(TICKS_PER_FRAME); // NOTE: there was another code in the original game\n\tScreenPartialDump();\n\treturn ticks;\n}\n\nvoid __cdecl S_ClearScreen() {\n\tScreenClear(false);\n}\n\nvoid __cdecl S_InitialiseScreen(GF_LEVEL_TYPE levelType) {\n\tif( levelType < 0 ) {\n\t\t// No Level\n\t\tFadeToPal(0, GamePalette8);\n\t} else {\n\t\tif( levelType != GFL_TITLE ) {\n\t\t\t// Not title\n\t\t\tTempVideoRemove();\n\t\t}\n\t\t// Title or Any Level\n\t\tFadeToPal(30, GamePalette8);\n\t}\n\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tHWR_InitState();\n\t}\n}\n\nvoid __cdecl S_OutputPolyList() {\n\tDDSDESC desc;\n\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\t// Software renderer\n\t\tphd_SortPolyList();\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t// prefetch surface lock\n\t\textern LPDDS CaptureBufferSurface;\n\t\tHRESULT rc = CaptureBufferSurface->LockRect(&desc, NULL, D3DLOCK_DONOTWAIT);\n\t\tif( FAILED(rc) && rc != D3DERR_WASSTILLDRAWING ) {\n\t\t\treturn;\n\t\t}\n\t\t// do software rendering\n\t\textern void PrepareSWR(int pitch, int height);\n\t\tPrepareSWR(RenderBuffer.width, RenderBuffer.height);\n\t\tphd_PrintPolyList(RenderBuffer.bitmap);\n\t\t// finish surface lock\n\t\tif( rc == D3DERR_WASSTILLDRAWING && FAILED(CaptureBufferSurface->LockRect(&desc, NULL, 0)) ) {\n\t\t\treturn;\n\t\t}\n\t\t// copy bitmap to surface\n\t\tBYTE *src = RenderBuffer.bitmap;\n\t\tfor( DWORD i=0; i<RenderBuffer.height; ++i ) {\n\t\t\tDWORD *dst = (DWORD *)((BYTE *)desc.pBits + desc.Pitch * i);\n\t\t\tfor( DWORD j=0; j<RenderBuffer.width; ++j ) {\n\t\t\t\tif( *src ) {\n\t\t\t\t\tBYTE r = WinVidPalette[*src].peRed;\n\t\t\t\t\tBYTE g = WinVidPalette[*src].peGreen;\n\t\t\t\t\tBYTE b = WinVidPalette[*src].peBlue;\n\t\t\t\t\t*dst++ = RGB_MAKE(r, g, b);\n\t\t\t\t} else {\n\t\t\t\t\t*dst++ = 0;\n\t\t\t\t}\n\t\t\t\t++src;\n\t\t\t}\n\t\t}\n\t\t// unlock surface\n\t\tCaptureBufferSurface->UnlockRect();\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tif SUCCEEDED(WinVidBufferLock(RenderBufferSurface, &desc, DDLOCK_WRITEONLY|DDLOCK_WAIT)) {\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\t\textern void PrepareSWR(int pitch, int height);\n\t\t\tPrepareSWR(desc.lPitch, desc.dwHeight);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\tphd_PrintPolyList((BYTE *)desc.lpSurface);\n\t\t\tWinVidBufferUnlock(RenderBufferSurface, &desc);\n\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t} else {\n\t\t// Hardware renderer\n\t\tif( !SavedAppSettings.ZBuffer || !SavedAppSettings.DontSortPrimitives ) {\n\t\t\tphd_SortPolyList();\n\t\t}\n\t\tHWR_DrawPolyList();\n\t\tD3DDev->EndScene();\n\t}\n}\n\nint __cdecl S_GetObjectBounds(__int16 *bPtr) {\n\tint xMin, xMax, yMin, yMax, zMin, zMax;\n\tint numZ, xv, yv, zv;\n\tPHD_VECTOR vtx[8];\n\n\tif( PhdMatrixPtr->_23 >= PhdFarZ )\n\t\treturn 0; // object box is out of screen\n\n\txMin = bPtr[0];\n\txMax = bPtr[1];\n\tyMin = bPtr[2];\n\tyMax = bPtr[3];\n\tzMin = bPtr[4];\n\tzMax = bPtr[5];\n\n\tvtx[0].x = xMin;\tvtx[0].y = yMin;\tvtx[0].z = zMin;\n\tvtx[1].x = xMax;\tvtx[1].y = yMin;\tvtx[1].z = zMin;\n\tvtx[2].x = xMax;\tvtx[2].y = yMax;\tvtx[2].z = zMin;\n\tvtx[3].x = xMin;\tvtx[3].y = yMax;\tvtx[3].z = zMin;\n\tvtx[4].x = xMin;\tvtx[4].y = yMin;\tvtx[4].z = zMax;\n\tvtx[5].x = xMax;\tvtx[5].y = yMin;\tvtx[5].z = zMax;\n\tvtx[6].x = xMax;\tvtx[6].y = yMax;\tvtx[6].z = zMax;\n\tvtx[7].x = xMin;\tvtx[7].y = yMax;\tvtx[7].z = zMax;\n\n\txMin = yMin = +0x3FFFFFFF;\n\txMax = yMax = -0x3FFFFFFF;\n\n\tnumZ = 0;\n\n\tfor( int i=0; i<8; ++i ) {\n\t\tzv = PhdMatrixPtr->_20 * vtx[i].x +\n\t\t\t PhdMatrixPtr->_21 * vtx[i].y +\n\t\t\t PhdMatrixPtr->_22 * vtx[i].z +\n\t\t\t PhdMatrixPtr->_23;\n\n\t\tif( zv > PhdNearZ && zv < PhdFarZ ) {\n\t\t\t++numZ;\n\t\t\tzv /= PhdPersp;\n\n\t\t\txv = (PhdMatrixPtr->_00 * vtx[i].x +\n\t\t\t\t  PhdMatrixPtr->_01 * vtx[i].y +\n\t\t\t\t  PhdMatrixPtr->_02 * vtx[i].z +\n\t\t\t\t  PhdMatrixPtr->_03) / zv;\n\n\t\t\tif( xMin > xv )\n\t\t\t\txMin = xv;\n\t\t\tif( xMax < xv )\n\t\t\t\txMax = xv;\n\n\t\t\tyv = (PhdMatrixPtr->_10 * vtx[i].x +\n\t\t\t\t  PhdMatrixPtr->_11 * vtx[i].y +\n\t\t\t\t  PhdMatrixPtr->_12 * vtx[i].z +\n\t\t\t\t  PhdMatrixPtr->_13) / zv;\n\n\t\t\tif( yMin > yv )\n\t\t\t\tyMin = yv;\n\t\t\tif( yMax < yv )\n\t\t\t\tyMax = yv;\n\t\t}\n\t}\n\n\txMin += PhdWinCenterX;\n\txMax += PhdWinCenterX;\n\tyMin += PhdWinCenterY;\n\tyMax += PhdWinCenterY;\n\n\tif( numZ == 0 || xMin > PhdWinRight || yMin > PhdWinBottom || xMax < PhdWinLeft || yMax < PhdWinTop )\n\t\treturn 0; // object box is out of screen\n\n\tif ( numZ < 8 || xMin < 0 || yMin < 0 || xMax > PhdWinMaxX || yMax > PhdWinMaxY )\n\t\treturn -1; // object box is clipped\n\n\treturn 1; // object box is totally on screen\n}\n\nvoid __cdecl S_InsertBackPolygon(int x0, int y0, int x1, int y1) {\n\tins_flat_rect(PhdWinMinX + x0, PhdWinMinY + y0,\n\t\t\t\t  PhdWinMinX + x1, PhdWinMinY + y1,\n\t\t\t\t  PhdFarZ + 1, InvColours[ICLR_Black]);\n}\n\nvoid __cdecl S_PrintShadow(__int16 radius, __int16 *bPtr, ITEM_INFO *item) {\n\tstatic SHADOW_INFO ShadowInfo = {\n\t\t.x = 0,\n\t\t.y = 0,\n\t\t.z = 0,\n\t\t.radius = 0x7FFF,\n\t\t.polyCount = 1,\n\t\t.vertexCount = 8,\n\t\t.vertex = {{0,0,0}},\n\t};\n\tint x0, x1, z0, z1, midX, midZ, xAdd, zAdd;\n\n\tx0 = bPtr[0];\n\tx1 = bPtr[1];\n\tz0 = bPtr[4];\n\tz1 = bPtr[5];\n\n\tmidX = (x0 + x1) / 2;\n\txAdd = (x1 - x0) * radius / 0x400;\n\tmidZ = (z0 + z1) / 2;\n\tzAdd = (z1 - z0) * radius / 0x400;\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tif( ShadowMode == 1 ) {\n\t\t// The shadow is a circle\n\t\tShadowInfo.vertexCount = 32;\n\t\tfor( int i = 0; i < ShadowInfo.vertexCount; ++i ) {\n\t\t\tint angle = (PHD_180 + i * PHD_360) / ShadowInfo.vertexCount;\n\t\t\tShadowInfo.vertex[i].x = midX + (xAdd * 2) * phd_sin(angle) / PHD_IONE;\n\t\t\tShadowInfo.vertex[i].z = midZ + (zAdd * 2) * phd_cos(angle) / PHD_IONE;\n\t\t}\n\t} else\n#endif // FEATURE_VIDEOFX_IMPROVED\n\t{\n\t\t// The shadow is an octagon\n\t\tShadowInfo.vertexCount = 8;\n\t\tShadowInfo.vertex[0].x = midX - xAdd;\n\t\tShadowInfo.vertex[0].z = midZ + zAdd * 2;\n\t\tShadowInfo.vertex[1].x = midX + xAdd;\n\t\tShadowInfo.vertex[1].z = midZ + zAdd * 2;\n\t\tShadowInfo.vertex[2].x = midX + xAdd * 2;\n\t\tShadowInfo.vertex[2].z = midZ + zAdd;\n\t\tShadowInfo.vertex[3].x = midX + xAdd * 2;\n\t\tShadowInfo.vertex[3].z = midZ - zAdd;\n\t\tShadowInfo.vertex[4].x = midX + xAdd;\n\t\tShadowInfo.vertex[4].z = midZ - zAdd * 2;\n\t\tShadowInfo.vertex[5].x = midX - xAdd;\n\t\tShadowInfo.vertex[5].z = midZ - zAdd * 2;\n\t\tShadowInfo.vertex[6].x = midX - xAdd * 2;\n\t\tShadowInfo.vertex[6].z = midZ - zAdd;\n\t\tShadowInfo.vertex[7].x = midX - xAdd * 2;\n\t\tShadowInfo.vertex[7].z = midZ + zAdd;\n\t}\n\n\t// Update screen parameters\n\tFltWinLeft\t\t= (double)(PhdWinMinX + PhdWinLeft);\n\tFltWinTop\t\t= (double)(PhdWinMinY + PhdWinTop);\n\tFltWinRight\t\t= (double)(PhdWinMinX + PhdWinRight+1);\n\tFltWinBottom\t= (double)(PhdWinMinY + PhdWinBottom+1);\n\tFltWinCenterX\t= (double)(PhdWinMinX + PhdWinCenterX);\n\tFltWinCenterY\t= (double)(PhdWinMinY + PhdWinCenterY);\n\n\t// Transform and print the shadow\n\tphd_PushMatrix();\n\tphd_TranslateAbs(item->pos.x, item->floor, item->pos.z);\n\tphd_RotY(item->pos.rotY);\n\tif( calc_object_vertices(&ShadowInfo.polyCount) ) {\n\t\t// NOTE: Here 24 is DepthQ index (shade factor).\n\t\t// 0 lightest, 15 no shade, 31 darkest (pitch black).\n\t\t// But original code has value 32 supposed to be interpreted as 24 (which means 50% darker)\n\t\t// Also 32 is maximum valid value in the original code, though it is DepthQTable range violation.\n\t\t// This trick worked because DepthQIndex array was right after DepthQ array in the memory\n\t\t// (DepthQIndex is equal to &DepthQ[24].index).This allocation is not guaranteed on some systems, so it was fixed\n\t\tins_poly_trans8(PhdVBuf, 24);\n\t}\n\tphd_PopMatrix();\n}\n\nvoid __cdecl S_CalculateLight(int x, int y, int z, __int16 roomNumber) {\n\tROOM_INFO *room;\n\tint xDist, yDist, zDist, distance, radius, depth;\n\tint xBrightest=0, yBrightest=0, zBrightest=0;\n\tint brightest, adder;\n\tint shade, shade1, shade2;\n\tint falloff, falloff1, falloff2;\n\tint intensity, intensity1, intensity2;\n\tint lightShade;\n\tVECTOR_ANGLES angles;\n\n\troom = &RoomInfo[roomNumber];\n\tbrightest = 0;\n\n\t// Static light calculation\n\tif( room->lightMode != 0 ) {\n\t\tlightShade = RoomLightShades[room->lightMode];\n\t\tfor( int i = 0; i < room->numLights; ++i ) {\n\t\t\txDist = x - room->light[i].x;\n\t\t\tyDist = y - room->light[i].y;\n\t\t\tzDist = z - room->light[i].z;\n\t\t\tfalloff1 = room->light[i].fallOff1;\n\t\t\tfalloff2 = room->light[i].fallOff2;\n\t\t\tintensity1 = room->light[i].intensity1;\n\t\t\tintensity2 = room->light[i].intensity2;\n\n\t\t\tdistance = (SQR(xDist) + SQR(yDist) + SQR(zDist)) >> 12;\n\t\t\tfalloff1 = SQR(falloff1) >> 12;\n\t\t\tfalloff2 = SQR(falloff2) >> 12;\n\t\t\tshade1 = falloff1 * intensity1 / (falloff1 + distance);\n\t\t\tshade2 = falloff2 * intensity2 / (falloff2 + distance);\n\n\t\t\tshade = shade1 + (shade2 - shade1) * lightShade / (WIBBLE_SIZE-1);\n\t\t\tif( shade > brightest ) {\n\t\t\t\tbrightest = shade;\n\t\t\t\txBrightest = xDist;\n\t\t\t\tyBrightest = yDist;\n\t\t\t\tzBrightest = zDist;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor( int i = 0; i < room->numLights; ++i ) {\n\t\t\txDist = x - room->light[i].x;\n\t\t\tyDist = y - room->light[i].y;\n\t\t\tzDist = z - room->light[i].z;\n\t\t\tfalloff = room->light[i].fallOff1;\n\t\t\tintensity = room->light[i].intensity1;\n\n\t\t\tfalloff = SQR(falloff) >> 12;\n\t\t\tdistance = (SQR(xDist) + SQR(yDist) + SQR(zDist)) >> 12;\n\n\t\t\tshade = falloff * intensity / (falloff + distance);\n\t\t\tif( shade > brightest ) {\n\t\t\t\tbrightest = shade;\n\t\t\t\txBrightest = xDist;\n\t\t\t\tyBrightest = yDist;\n\t\t\t\tzBrightest = zDist;\n\t\t\t}\n\t\t}\n\t}\n\tadder = brightest;\n\n\t// Dynamic light calculation\n\tfor( DWORD i = 0; i < DynamicLightCount; ++i ) {\n\t\txDist = x - DynamicLights[i].x;\n\t\tyDist = y - DynamicLights[i].y;\n\t\tzDist = z - DynamicLights[i].z;\n\t\tfalloff = DynamicLights[i].fallOff1;\n\t\tintensity = DynamicLights[i].intensity1;\n\n\t\tradius = 1 << falloff;\n\n\t\tif( (xDist >= -radius && xDist <= radius) &&\n\t\t\t(yDist >= -radius && yDist <= radius) &&\n\t\t\t(zDist >= -radius && zDist <= radius) )\n\t\t{\n\t\t\tdistance = SQR(xDist) + SQR(yDist) + SQR(zDist);\n\t\t\tif( distance <= SQR(radius) ) {\n\t\t\t\tshade = (1 << intensity) - (distance >> (2 * falloff - intensity));\n\t\t\t\tif( shade > brightest ) {\n\t\t\t\t\tbrightest = shade;\n\t\t\t\t\txBrightest = xDist;\n\t\t\t\t\tyBrightest = yDist;\n\t\t\t\t\tzBrightest = zDist;\n\t\t\t\t}\n\t\t\t\tadder += shade;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Light finalization\n\tadder = adder/2;\n\tif( adder == 0 ) {\n\t\tLsAdder = room->ambient1;\n\t\tLsDivider = 0;\n\t} else {\n\t\tLsAdder = room->ambient1 - adder;\n\t\tLsDivider = (1 << (W2V_SHIFT + 12)) / adder;\n\t\tphd_GetVectorAngles(xBrightest, yBrightest, zBrightest, &angles);\n\t\tphd_RotateLight(angles.pitch, angles.yaw);\n\t}\n\n\t// Fog calculation\n\tdepth = PhdMatrixPtr->_23 >> W2V_SHIFT;\n#ifdef FEATURE_VIEW_IMPROVED\n\tLsAdder += CalculateFogShade(depth);\n#else // !FEATURE_VIEW_IMPROVED\n\tif( depth > DEPTHQ_START ) // fog begin\n\t\tLsAdder += depth - DEPTHQ_START;\n#endif // FEATURE_VIEW_IMPROVED\n\tif( LsAdder > 0x1FFF ) // fog end\n\t\tLsAdder = 0x1FFF;\n}\n\nvoid __cdecl S_CalculateStaticLight(__int16 adder) {\n\tint depth;\n\n\tLsAdder = adder - 0x1000;\n\tdepth = PhdMatrixPtr->_23 >> W2V_SHIFT;\n#ifdef FEATURE_VIEW_IMPROVED\n\tLsAdder += CalculateFogShade(depth);\n#else // !FEATURE_VIEW_IMPROVED\n\tif( depth > DEPTHQ_START ) // fog begin\n\t\tLsAdder += depth - DEPTHQ_START;\n#endif // FEATURE_VIEW_IMPROVED\n\tif( LsAdder > 0x1FFF ) // fog end\n\t\tLsAdder = 0x1FFF;\n}\n\nvoid __cdecl S_CalculateStaticMeshLight(int x, int y, int z, int shade1, int shade2, ROOM_INFO *room) {\n\tint adder, shade, falloff, intensity;\n\tint xDist, yDist, zDist, distance, radius;\n\n\tadder = shade1;\n\tif( room->lightMode != 0 ) {\n\t\tadder += (shade2 - shade1) * RoomLightShades[room->lightMode] / (WIBBLE_SIZE-1);\n\t}\n\n\tfor( DWORD i = 0; i < DynamicLightCount; ++i ) {\n\t\txDist = x - DynamicLights[i].x;\n\t\tyDist = y - DynamicLights[i].y;\n\t\tzDist = z - DynamicLights[i].z;\n\t\tfalloff = DynamicLights[i].fallOff1;\n\t\tintensity = DynamicLights[i].intensity1;\n\n\t\tradius = 1 << falloff;\n\n\t\tif( (xDist >= -radius && xDist <= radius) &&\n\t\t\t(yDist >= -radius && yDist <= radius) &&\n\t\t\t(zDist >= -radius && zDist <= radius) )\n\t\t{\n\t\t\tdistance = SQR(xDist) + SQR(yDist) + SQR(zDist);\n\t\t\tif( distance <= SQR(radius) ) {\n\t\t\t\tshade = (1 << intensity) - (distance >> (2 * falloff - intensity));\n\t\t\t\tadder -= shade;\n\t\t\t\tif( adder < 0 ) {\n\t\t\t\t\tadder = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tS_CalculateStaticLight(adder);\n}\n\nvoid __cdecl S_LightRoom(ROOM_INFO *room) {\n\tint shade, falloff, intensity;\n\tint xPos, yPos, zPos;\n\tint xDist, yDist, zDist, distance, radius;\n\tint roomVtxCount;\n\tROOM_VERTEX_INFO *roomVtx;\n\n\n\tif( room->lightMode != 0 ) {\n\t\tint *roomLightTable = RoomLightTables[RoomLightShades[room->lightMode]].table;\n\t\troomVtxCount = *room->data;\n\t\troomVtx = (ROOM_VERTEX_INFO *)(room->data + 1);\n\t\tfor( int i = 0; i < roomVtxCount; ++i ) {\n\t\t\t__int16 wibble = roomLightTable[roomVtx[i].lightTableValue % WIBBLE_SIZE];\n\t\t\troomVtx[i].lightAdder = roomVtx[i].lightBase + wibble;\n\t\t}\n\t}\n\telse if( (room->flags & 0x10) != 0 ) {\n\t\troomVtxCount = *room->data;\n\t\troomVtx = (ROOM_VERTEX_INFO *)(room->data + 1);\n\t\tfor( int i = 0; i < roomVtxCount; ++i ) {\n\t\t\troomVtx[i].lightAdder = roomVtx[i].lightBase;\n\t\t}\n\t\troom->flags &= ~0x10;\n\t}\n\n\tint xMin = 0x400;\n\tint zMin = 0x400;\n\tint xMax = 0x400 * (room->ySize - 1);\n\tint zMax = 0x400 * (room->xSize - 1);\n\n\tfor( DWORD i = 0; i < DynamicLightCount; ++i ) {\n\t\txPos = DynamicLights[i].x - room->x;\n\t\tyPos = DynamicLights[i].y;\n\t\tzPos = DynamicLights[i].z - room->z;\n\t\tfalloff = DynamicLights[i].fallOff1;\n\t\tintensity = DynamicLights[i].intensity1;\n\n\t\tradius = 1 << falloff;\n\n\t\tif( xPos + radius >= xMin && zPos + radius >= zMin && xPos - radius <= xMax && zPos - radius <= zMax ) {\n\t\t\troom->flags |= 0x10;\n\t\t\troomVtxCount = *room->data;\n\t\t\troomVtx = (ROOM_VERTEX_INFO *)(room->data + 1);\n\t\t\tfor( int j = 0; j < roomVtxCount; ++j ) {\n\t\t\t\tif( roomVtx[j].lightAdder != 0 ) {\n\t\t\t\t\txDist = roomVtx[j].x - xPos;\n\t\t\t\t\tyDist = roomVtx[j].y - yPos;\n\t\t\t\t\tzDist = roomVtx[j].z - zPos;\n\t\t\t\t\tif( (xDist >= -radius && xDist <= radius) &&\n\t\t\t\t\t\t(yDist >= -radius && yDist <= radius) &&\n\t\t\t\t\t\t(zDist >= -radius && zDist <= radius) )\n\t\t\t\t\t{\n\t\t\t\t\t\tdistance = SQR(xDist) + SQR(yDist) + SQR(zDist);\n\t\t\t\t\t\tif( distance <= SQR(radius) ) {\n\t\t\t\t\t\t\tshade = (1 << intensity) - (distance >> (2 * falloff - intensity));\n\t\t\t\t\t\t\troomVtx[j].lightAdder -= shade;\n\t\t\t\t\t\t\tif( roomVtx[j].lightAdder < 0 )\n\t\t\t\t\t\t\t\troomVtx[j].lightAdder = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid __cdecl S_DrawHealthBar(int percent) {\n#ifdef FEATURE_HUD_IMPROVED\n\tint barWidth = GetRenderScale(100);\n\tint barHeight = GetRenderScale(5);\n\tint barXOffset = GetRenderScale((PsxBarPosEnabled && !IsInventoryActive ) ? 20 : 8);\n\tint barYOffset = GetRenderScale((PsxBarPosEnabled && !IsInventoryActive ) ? 18 : 8);\n\tint pixel = GetRenderScale(1);\n\tint x0, x1;\n\n\tif( PsxBarPosEnabled ) {\n\t\tx1 = PhdWinMinX + DumpWidth - barXOffset;\n\t\tx0 = x1 - barWidth;\n\t} else {\n\t\tx0 = PhdWinMinX + barXOffset;\n\t\tx1 = x0 + barWidth;\n\t}\n\n\tint y0 = PhdWinMinY + barYOffset;\n\tint y1 = y0 + barHeight;\n\n\tint bar = barWidth * percent / PHD_ONE;\n\n\t// Disable underwater shading\n\tIsShadeEffect = false;\n\n\tif( HealthBarMode != 0 && SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tif( SavedAppSettings.ZBuffer ) {\n\t\t\tPSX_DrawHealthBar(x0, y0, x1, y1, bar, pixel, 255);\n\t\t} else {\n\t\t\tPSX_InsertHealthBar(x0, y0, x1, y1, bar, pixel, 255);\n\t\t}\n\t\treturn;\n\t}\n\n\t// Frame\n\tins_flat_rect(x0-pixel*2, y0-pixel*2, x1+pixel*2, y1+pixel*2, PhdNearZ + 50, InvColours[ICLR_White]);\n\tins_flat_rect(x0-pixel*1, y0-pixel*1, x1+pixel*2, y1+pixel*2, PhdNearZ + 40, InvColours[ICLR_Gray]);\n\tins_flat_rect(x0-pixel*1, y0-pixel*1, x1+pixel*1, y1+pixel*1, PhdNearZ + 30, InvColours[ICLR_Black]);\n\n\t// Health bar\n\tif( bar > 0 ) {\n\t\tins_flat_rect(x0, y0+pixel*0, x0+bar, y0+barHeight,\tPhdNearZ + 20, InvColours[ICLR_Red]);\n\t\tins_flat_rect(x0, y0+pixel*1, x0+bar, y0+pixel*2,\tPhdNearZ + 10, InvColours[ICLR_Orange]);\n\t}\n#else // !FEATURE_HUD_IMPROVED\n\tint i;\n\n\tint barWidth = 100;\n\tint barHeight = 5;\n\n\tint x0 = 8;\n\tint y0 = 8;\n\tint x1 = x0 + barWidth;\n\tint y1 = y0 + barHeight;\n\n\tint bar = barWidth * percent / 100;\n\n\t// Disable underwater shading\n\tIsShadeEffect = false;\n\n\t// Black background\n\tfor( i = 0; i < (barHeight+2); ++i )\n\t\tins_line(x0-2, y0+i-1, x1+1, y0+i-1, PhdNearZ + 50, InvColours[ICLR_Black]);\n\n\t// Dark frame\n\tins_line(x0-2, y1+1, x1+2, y1+1, PhdNearZ + 40, InvColours[ICLR_Gray]);\n\tins_line(x1+2, y0-2, x1+2, y1+1, PhdNearZ + 40, InvColours[ICLR_Gray]);\n\n\t// Light frame\n\tins_line(x0-2, y0-2, x1+2, y0-2, PhdNearZ + 30, InvColours[ICLR_White]);\n\tins_line(x0-2, y1+1, x0-2, y0-2, PhdNearZ + 30, InvColours[ICLR_White]);\n\n\t// Health bar\n\tif( bar > 0 ) {\n\t\tfor( i = 0; i < barHeight; ++i )\n\t\t\tins_line(x0, y0+i, x0+bar, y0+i, PhdNearZ + 20, ( i == 1 ) ? InvColours[ICLR_Orange] : InvColours[ICLR_Red]);\n\t}\n#endif // FEATURE_HUD_IMPROVED\n}\n\nvoid __cdecl S_DrawAirBar(int percent) {\n#ifdef FEATURE_HUD_IMPROVED\n\tint barWidth = GetRenderScale(100);\n\tint barHeight = GetRenderScale(5);\n\tint barXOffset = GetRenderScale(PsxBarPosEnabled ? 20 : 8);\n\tint barYOffset = GetRenderScale(PsxBarPosEnabled ? 32 : 8);\n\tint pixel = GetRenderScale(1);\n\n\tint x1 = PhdWinMinX + DumpWidth - barXOffset;\n\tint x0 = x1 - barWidth;\n\tint y0 = PhdWinMinY + barYOffset;\n\tint y1 = y0 + barHeight;\n\n\tint bar = barWidth * percent / PHD_ONE;\n\n\t// Disable underwater shading\n\tIsShadeEffect = false;\n\n\tif( HealthBarMode != 0 && SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tif( SavedAppSettings.ZBuffer ) {\n\t\t\tPSX_DrawAirBar(x0, y0, x1, y1, bar, pixel, 255);\n\t\t} else {\n\t\t\tPSX_InsertAirBar(x0, y0, x1, y1, bar, pixel, 255);\n\t\t}\n\t\treturn;\n\t}\n\n\t// Frame\n\tins_flat_rect(x0-pixel*2, y0-pixel*2, x1+pixel*2, y1+pixel*2, PhdNearZ + 50, InvColours[ICLR_White]);\n\tins_flat_rect(x0-pixel*1, y0-pixel*1, x1+pixel*2, y1+pixel*2, PhdNearZ + 40, InvColours[ICLR_Gray]);\n\tins_flat_rect(x0-pixel*1, y0-pixel*1, x1+pixel*1, y1+pixel*1, PhdNearZ + 30, InvColours[ICLR_Black]);\n\n\t// Air bar\n\tif( bar > 0 ) {\n\t\tins_flat_rect(x0, y0+pixel*0, x0+bar, y0+barHeight,\tPhdNearZ + 20, InvColours[ICLR_Blue]);\n\t\tins_flat_rect(x0, y0+pixel*1, x0+bar, y0+pixel*2,\tPhdNearZ + 10, InvColours[ICLR_White]);\n\t}\n#else // !FEATURE_HUD_IMPROVED\n\tint i;\n\n\tint barWidth = 100;\n\tint barHeight = 5;\n\n\tint x1 = DumpWidth - 10;\n\tint x0 = x1 - barWidth;\n\tint y0 = 8;\n\tint y1 = y0 + barHeight;\n\n\tint bar = barWidth * percent / 100;\n\n\t// Disable underwater shading\n\tIsShadeEffect = false;\n\n\t// Black background\n\tfor( i = 0; i < (barHeight+2); ++i )\n\t\tins_line(x0-2, y0+i-1, x1+1, y0+i-1, PhdNearZ + 50, InvColours[ICLR_Black]);\n\n\t// Dark frame\n\tins_line(x0-2, y1+1, x1+2, y1+1, PhdNearZ + 40, InvColours[ICLR_Gray]);\n\tins_line(x1+2, y0-2, x1+2, y1+1, PhdNearZ + 40, InvColours[ICLR_Gray]);\n\n\t// Light frame\n\tins_line(x0-2, y0-2, x1+2, y0-2, PhdNearZ + 30, InvColours[ICLR_White]);\n\tins_line(x0-2, y1+1, x0-2, y0-2, PhdNearZ + 30, InvColours[ICLR_White]);\n\n\t// Air bar\n\tif( bar > 0 ) {\n\t\tfor( i = 0; i < barHeight; ++i )\n\t\t\tins_line(x0, y0+i, x0+bar, y0+i, PhdNearZ + 20, ( i == 1 ) ? InvColours[ICLR_White] : InvColours[ICLR_Blue]);\n\t}\n#endif // FEATURE_HUD_IMPROVED\n}\n\nvoid __cdecl AnimateTextures(int nTicks) {\n\tstatic int tickComp = 0;\n\t__int16 i, j;\n\t__int16 *ptr;\n\tPHD_TEXTURE temp1, temp2;\n\n\ttickComp += nTicks;\n\twhile( tickComp > TICKS_PER_FRAME * 5 ) {\n\t\tptr = AnimatedTextureRanges;\n\t\ti = *(ptr++);\n\t\tfor( ; i>0; --i, ++ptr ) {\n\t\t\tj = *(ptr++);\n\t\t\ttemp1 = PhdTextureInfo[*ptr];\n\t\t\ttemp2 = TextureBackupUV[*ptr];\n\t\t\tfor ( ; j>0; --j, ++ptr ) {\n\t\t\t\tPhdTextureInfo[ptr[0]] = PhdTextureInfo[ptr[1]];\n\t\t\t\tTextureBackupUV[ptr[0]] = TextureBackupUV[ptr[1]];\n\t\t\t}\n\t\t\tPhdTextureInfo[*ptr] = temp1;\n\t\t\tTextureBackupUV[*ptr] = temp2;\n\t\t}\n\t\ttickComp -= TICKS_PER_FRAME * 5;\n\t}\n}\n\nvoid __cdecl S_SetupBelowWater(BOOL underwater) {\n\tif( IsWet != underwater ) {\n\t\tFadeToPal(1, underwater ? WaterPalette : GamePalette8);\n\t\tIsWet = underwater;\n\t}\n\tIsWaterEffect = true;\n\tIsShadeEffect = true;\n\tIsWibbleEffect = !underwater;\n}\n\nvoid __cdecl S_SetupAboveWater(BOOL underwater) {\n\tIsWaterEffect = false;\n\tIsShadeEffect = underwater;\n\tIsWibbleEffect = underwater;\n}\n\nvoid __cdecl S_AnimateTextures(int nTicks) {\n\tWibbleOffset = (WibbleOffset + nTicks / TICKS_PER_FRAME) % WIBBLE_SIZE;\n\tRoomLightShades[1] = GetRandomDraw() & (WIBBLE_SIZE-1);\n\tRoomLightShades[2] = (WIBBLE_SIZE-1) * (phd_sin(WibbleOffset * PHD_360 / WIBBLE_SIZE) + PHD_IONE) / 2 / PHD_IONE;\n\n\tif( GF_SunsetEnabled ) {\n\t\t// NOTE: in the original game there was: SunsetTimer += nTicks;\n\t\t// so the timer was reset every time when the saved game is loaded\n\t\tSunsetTimer = SaveGame.statistics.timer * TICKS_PER_FRAME;\n\t\tCLAMPG(SunsetTimer, SUNSET_TIMEOUT);\n\t\tRoomLightShades[3] = (WIBBLE_SIZE-1) * SunsetTimer / SUNSET_TIMEOUT;\n\t}\n\tAnimateTextures(nTicks);\n}\n\nvoid __cdecl S_DisplayPicture(LPCTSTR fileName, BOOL isTitle) {\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tif( !isTitle ) {\n\t\tinit_game_malloc();\n\t}\n\tBGND2_LoadPicture(fileName, isTitle, FALSE);\n#else // !FEATURE_BACKGROUND_IMPROVED\n\tDWORD bytesRead;\n\tHANDLE hFile;\n\tDWORD fileSize;\n\tDWORD bitmapSize;\n\tBYTE *fileData;\n\tBYTE *bitmapData;\n\tLPCTSTR fullPath;\n\n\tfullPath = GetFullPath(fileName);\n\thFile = CreateFile(fullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile == INVALID_HANDLE_VALUE )\n\t\treturn;\n\n\tif( !isTitle )\n\t\tinit_game_malloc();\n\n\tfileSize = GetFileSize(hFile, NULL);\n\tfileData = (BYTE *)game_malloc(fileSize, GBUF_LoadPiccyBuffer);\n\tReadFile(hFile, fileData, fileSize, &bytesRead, NULL);\n\tCloseHandle(hFile);\n\n\tbitmapSize = 640*480;\n\tbitmapData = (BYTE *)game_malloc(bitmapSize, GBUF_LoadPiccyBuffer);\n\tDecompPCX(fileData, fileSize, bitmapData, PicPalette);\n\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tif( PictureBuffer.bitmap != NULL)\n\t\t\tmemcpy(PictureBuffer.bitmap, bitmapData, PictureBuffer.width * PictureBuffer.height);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tWinVidCopyBitmapToBuffer(PictureBufferSurface, bitmapData);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t} else {\n\t\tBGND_Make640x480(bitmapData, PicPalette);\n\t}\n\n\tif( !isTitle ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tmemcpy(GamePalette8, PicPalette, sizeof(GamePalette8));\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tCopyBitmapPalette(PicPalette, bitmapData, bitmapSize, GamePalette8);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n\n\tgame_free(fileSize + bitmapSize);\n#endif // FEATURE_BACKGROUND_IMPROVED\n}\n\nvoid __cdecl S_SyncPictureBufferPalette() {\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( PictureBuffer.bitmap == NULL ) return;\n\tSyncSurfacePalettes(PictureBuffer.bitmap, PictureBuffer.width, PictureBuffer.height, PictureBuffer.width, PicPalette, PictureBuffer.bitmap, PictureBuffer.width, GamePalette8, TRUE);\n\tmemcpy(PicPalette, GamePalette8, sizeof(PicPalette));\n#else // (DIRECT3D_VERSION >= 0x900)\n\tDDSDESC desc;\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tint width = BGND_PictureWidth;\n\tint height = BGND_PictureHeight;\n#else // !FEATURE_BACKGROUND_IMPROVED\n\tint width = 640;\n\tint height = 480;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\tif( PictureBufferSurface == NULL || FAILED(WinVidBufferLock(PictureBufferSurface, &desc, DDLOCK_WRITEONLY|DDLOCK_WAIT)) )\n\t\treturn;\n\n\tSyncSurfacePalettes(desc.lpSurface, width, height, desc.lPitch, PicPalette, desc.lpSurface, desc.lPitch, GamePalette8, TRUE);\n\tWinVidBufferUnlock(PictureBufferSurface, &desc);\n\tmemcpy(PicPalette, GamePalette8, sizeof(PicPalette));\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __cdecl S_DontDisplayPicture() {\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tBGND_Free();\n\t\tBGND_PictureIsReady = false;\n\t}\n}\n\nvoid __cdecl ScreenDump() {\n\tUpdateFrame(true, NULL);\n}\n\nvoid __cdecl ScreenPartialDump() {\n\tUpdateFrame(true, &PhdWinRect);\n}\n\nvoid __cdecl FadeToPal(int fadeValue, RGB888 *palette) {\n\tint i, j;\n\tint palStartIdx = 0;\n\tint palEndIdx = 256;\n#if (DIRECT3D_VERSION < 0x900)\n\tint palSize = 256;\n#endif // (DIRECT3D_VERSION < 0x900)\n\tPALETTEENTRY fadePal[256];\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.RenderMode != RM_Software )\n\t\treturn;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( !GameVid_IsVga )\n\t\treturn;\n\n\tif( GameVid_IsWindowedVga ) {\n\t\tpalStartIdx += 10;\n\t\tpalEndIdx -= 10;\n\t\tpalSize -= 20;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( fadeValue <= 1 ) {\n\t\tfor( i=palStartIdx; i<palEndIdx; ++i ) {\n\t\t\tWinVidPalette[i].peRed   = palette[i].red;\n\t\t\tWinVidPalette[i].peGreen = palette[i].green;\n\t\t\tWinVidPalette[i].peBlue  = palette[i].blue;\n\t\t}\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tS_InitialisePolyList(FALSE);\n\t\tS_OutputPolyList();\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tDDrawPalette->SetEntries(0, palStartIdx, palSize, &WinVidPalette[palStartIdx]);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\treturn;\n\t}\n\n\tfor( i=palStartIdx; i<palEndIdx; ++i ) {\n\t\tfadePal[i] = WinVidPalette[i];\n\t}\n\n\tfor( j=0; j<=fadeValue; ++j ) {\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t\tif( S_UpdateInput() ) return;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\t\tfor( i=palStartIdx; i<palEndIdx; ++i ) {\n\t\t\tWinVidPalette[i].peRed   = fadePal[i].peRed   + (palette[i].red   - fadePal[i].peRed)   * j / fadeValue;\n\t\t\tWinVidPalette[i].peGreen = fadePal[i].peGreen + (palette[i].green - fadePal[i].peGreen) * j / fadeValue;\n\t\t\tWinVidPalette[i].peBlue  = fadePal[i].peBlue  + (palette[i].blue  - fadePal[i].peBlue)  * j / fadeValue;\n\t\t}\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tS_InitialisePolyList(FALSE);\n\t\tS_OutputPolyList();\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tDDrawPalette->SetEntries(0, palStartIdx, palSize, &WinVidPalette[palStartIdx]);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tS_DumpScreen();\n\t}\n}\n\nvoid __cdecl ScreenClear(bool isPhdWinSize) {\n\tDWORD flags = ( SavedAppSettings.RenderMode == RM_Hardware ) ? CLRB_BackBuffer : CLRB_RenderBuffer;\n\n\tif( isPhdWinSize )\n\t\tflags |= CLRB_PhdWinSize;\n\n\tClearBuffers(flags, 0);\n}\n\nvoid __cdecl S_CopyScreenToBuffer() {\n#if (DIRECT3D_VERSION < 0x900)\n\tDDSDESC desc;\n#endif // (DIRECT3D_VERSION < 0x900)\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tDWORD bgndMode = 0;\n\tif( IsFadeToBlack ) {\n\t\tbgndMode = 0;\n\t} else if( IsInventoryActive ) {\n\t\tbgndMode = InvBackgroundMode;\n\t} else if( GF_CurrentEvent() == GFE_LEVCOMPLETE ) {\n\t\tbgndMode = StatsBackgroundMode;\n\t}\n\tDWORD width = PhdWinWidth;\n\tDWORD height = PhdWinHeight;\n#else // !FEATURE_BACKGROUND_IMPROVED\n\tDWORD width = 640;\n\tDWORD height = 480;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tif( PictureBuffer.bitmap == NULL ||\n\t\t\tPictureBuffer.width != width ||\n\t\t\tPictureBuffer.height != height )\n\t\t{\n\t\t\tBGND_PictureWidth = width;\n\t\t\tBGND_PictureHeight = height;\n\t\t\ttry {\n\t\t\t\tCreatePictureBuffer();\n\t\t\t} catch(...) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tif( PictureBufferSurface != NULL &&\n\t\t\t(BGND_PictureWidth != width || BGND_PictureHeight != height) )\n\t\t{\n\t\t\tPictureBufferSurface->Release();\n\t\t\tPictureBufferSurface = NULL;\n\t\t}\n\t\tif( PictureBufferSurface == NULL ) {\n\t\t\tBGND_PictureWidth = width;\n\t\t\tBGND_PictureHeight = height;\n\t\t\ttry {\n\t\t\t\tCreatePictureBuffer();\n\t\t\t} catch(...) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tSWR_StretchBlt(&PictureBuffer, NULL, &RenderBuffer, &GameVidRect);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tPictureBufferSurface->Blt(NULL, RenderBufferSurface, &GameVidRect, DDBLT_WAIT, NULL);\n#endif // (DIRECT3D_VERSION >= 0x900)\n#if (DIRECT3D_VERSION >= 0x900)\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t\tif( InventoryMode != INV_PauseMode || PauseBackgroundMode != 0 )\n#endif // FEATURE_BACKGROUND_IMPROVED\n\t\t{\n\t\t\tBYTE *ptr = PictureBuffer.bitmap;\n\t\t\tDWORD num = PictureBuffer.width * PictureBuffer.height;\n\t\t\tfor( DWORD i = 0; i < num; ++i ) {\n\t\t\t\tptr[i] = DepthQIndex[ptr[i]];\n\t\t\t}\n\t\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tif(\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t\t\t(InventoryMode != INV_PauseMode || PauseBackgroundMode != 0) &&\n#endif // FEATURE_BACKGROUND_IMPROVED\n\t\t\tSUCCEEDED(WinVidBufferLock(PictureBufferSurface, &desc, DDLOCK_WRITEONLY|DDLOCK_WAIT)) )\n\t\t{\n\t\t\tBYTE *surface = (BYTE *)desc.lpSurface;\n\n\t\t\tfor( DWORD i = 0; i < height; ++i ) {\n\t\t\t\tfor( DWORD j = 0; j < width; ++j ) {\n\t\t\t\t\tsurface[j] = DepthQIndex[surface[j]];\n\t\t\t\t}\n\t\t\t\tsurface += desc.lPitch;\n\t\t\t}\n\t\t\tWinVidBufferUnlock(PictureBufferSurface, &desc);\n\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tmemcpy(PicPalette, GamePalette8, sizeof(PicPalette));\n\t}\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\telse if( bgndMode == 0 ) {\n\t\tBGND2_CapturePicture();\n\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n}\n\nvoid __cdecl S_CopyBufferToScreen() {\n#if defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\tDWORD color = SavedAppSettings.LightingMode ? 0xFF808080 : 0xFFFFFFFF;\n#else // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n\tDWORD color = 0xFFFFFFFF; // vertex color (ARGB white)\n#endif // defined(FEATURE_VIDEOFX_IMPROVED) && (DIRECT3D_VERSION >= 0x900)\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tDWORD bgndMode = 0;\n\tif( IsFadeToBlack ) {\n\t\tbgndMode = 0;\n\t} else if( IsInventoryActive ) {\n\t\tbgndMode = InvBackgroundMode;\n\t} else if( GF_CurrentEvent() == GFE_LEVCOMPLETE ) {\n\t\tbgndMode = StatsBackgroundMode;\n\t}\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tif( PictureBuffer.bitmap == NULL ) {\n\t\t\treturn;\n\t\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tif( PictureBufferSurface == NULL ) { // NOTE: additional check just in case\n\t\t\treturn;\n\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tif( memcmp(GamePalette8, PicPalette, sizeof(PicPalette)) ) {\n\t\t\tS_SyncPictureBufferPalette();\n\t\t}\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\t\tRECT rect = PhdWinRect;\n\t\tBGND2_CalculatePictureRect(&rect);\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tClearBuffers(CLRB_RenderBuffer, 0);\n\t\tSWR_StretchBlt(&RenderBuffer, &rect, &PictureBuffer, NULL);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tRenderBufferSurface->Blt(&rect, PictureBufferSurface, NULL, DDBLT_WAIT, NULL);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n\telse if( BGND_PictureIsReady && (!BGND_IsCaptured || bgndMode == 0) ) {\n\t\tHWR_EnableZBuffer(false, false);\n\t\tRECT rect = PhdWinRect;\n\t\tif( !BGND_IsCaptured ) {\n\t\t\tBGND2_LoadPicture(NULL, FALSE, TRUE); // reload picture if required\n\t\t}\n\t\tBGND_DrawInGameBlack(); // draw black background for picture margins\n\t\tBGND2_CalculatePictureRect(&rect);\n\t\tBGND2_DrawTextures(&rect, color);\n\t\tif( BGND_IsCaptured ) {\n\t\t\tif( InventoryMode != INV_PauseMode ) {\n\t\t\t\tBGND2_FadeTo(128, -12); // the captured background image fades out to 50%\n\t\t\t} else if( PauseBackgroundMode != 0 ) {\n\t\t\t\tBGND2_FadeTo(128, -128); // the captured background image instantly gets 50%\n\t\t\t}\n\t\t}\n\n#else // !FEATURE_BACKGROUND_IMPROVED\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tSWR_StretchBlt(&RenderBuffer, &GameVidRect, &PictureBuffer, NULL);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tRenderBufferSurface->Blt(&GameVidRect, PictureBufferSurface, NULL, DDBLT_WAIT, NULL);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n\telse if( BGND_PictureIsReady ) {\n\t\tBGND_GetPageHandles();\n\t\tHWR_EnableZBuffer(false, false);\n\n\t\tstatic const int tileX[4] = {0, 256, 512, 640};\n\t\tstatic const int tileY[3] = {0, 256, 480};\n\t\tint i, x[4], y[3];\n\n\t\tfor( i = 0; i < 4; ++i )\n\t\t\t x[i] = tileX[i] * PhdWinWidth / 640 + PhdWinMinX;\n\t\tfor( i = 0; i < 3; ++i )\n\t\t\t y[i] = tileY[i] * PhdWinHeight / 480 + PhdWinMinY;\n\n\t\tDrawTextureTile(x[0], y[0], x[1]-x[0], y[1]-y[0], BGND_PageHandles[0],\n\t\t\t\t\t\t0, 0, 256, 256, color, color, color, color);\n\t\tDrawTextureTile(x[1], y[0], x[2]-x[1], y[1]-y[0], BGND_PageHandles[1],\n\t\t\t\t\t\t0, 0, 256, 256, color, color, color, color);\n\t\tDrawTextureTile(x[2], y[0], x[3]-x[2], y[1]-y[0], BGND_PageHandles[2],\n\t\t\t\t\t\t0, 0, 128, 256, color, color, color, color);\n\t\tDrawTextureTile(x[0], y[1], x[1]-x[0], y[2]-y[1], BGND_PageHandles[3],\n\t\t\t\t\t\t0, 0, 256, 224, color, color, color, color);\n\t\tDrawTextureTile(x[1], y[1], x[2]-x[1], y[2]-y[1], BGND_PageHandles[4],\n\t\t\t\t\t\t0, 0, 256, 224, color, color, color, color);\n\t\tDrawTextureTile(x[2], y[1], x[3]-x[2], y[2]-y[1], BGND_PageHandles[2],\n\t\t\t\t\t\t128, 0, 128, 224, color, color, color, color);\n#endif // FEATURE_BACKGROUND_IMPROVED\n\t\tHWR_EnableZBuffer(true, true);\n\t}\n\telse {\n\t\tBGND_DrawInGameBackground();\n\t}\n}\n\nBOOL __cdecl DecompPCX(LPCBYTE pcx, DWORD pcxSize, LPBYTE pic, RGB888 *pal) {\n\tPCX_HEADER *header;\n\tDWORD w, h, width, height, pitch;\n\tLPCBYTE src;\n\tLPBYTE dst;\n\n\theader = (PCX_HEADER *)pcx;\n\twidth  = header->xMax - header->xMin + 1;\n\theight = header->yMax - header->yMin + 1;\n\n\tif( header->manufacturer != 10 ||\n\t\theader->version < 5 ||\n\t\theader->bpp != 8 ||\n\t\theader->rle != 1 ||\n\t\theader->planes != 1 ||\n\t\twidth*height == 0 )\n\t{\n\t\treturn FALSE;\n\t}\n\n\tsrc = pcx + sizeof(PCX_HEADER);\n\tdst = pic;\n\tpitch = width + width%2; // add padding if required\n\th = 0;\n\tw = 0;\n\n\t// NOTE: PCX decoder slightly redesigned to be more compatible and stable\n\twhile( h < height ) {\n\t\tif( (*src & 0xC0) == 0xC0 ) {\n\t\t\tBYTE n = (*src++) & 0x3F;\n\t\t\tBYTE c = *src++;\n\t\t\tif( n > 0 ) {\n\t\t\t\tif( w < width ) {\n\t\t\t\t\tCLAMPG(n, width - w);\n\t\t\t\t\tmemset(dst, c, n);\n\t\t\t\t\tdst += n;\n\t\t\t\t}\n\t\t\t\tw += n;\n\t\t\t}\n\t\t} else {\n\t\t\t*dst++ = *src++;\n\t\t\t++w;\n\t\t}\n\t\tif( w >= pitch ) {\n\t\t\tw = 0;\n\t\t\t++h;\n\t\t}\n\t}\n\n\tif( pal != NULL)\n\t\tmemcpy(pal, pcx + pcxSize - sizeof(RGB888)*256, sizeof(RGB888)*256);\n\n\treturn TRUE;\n}\n\n// NOTE: this function is not presented in the original game\nint GetPcxResolution(LPCBYTE pcx, DWORD pcxSize, DWORD *width, DWORD *height) {\n\tPCX_HEADER *header;\n\n\tif( pcx == NULL || pcxSize <= sizeof(PCX_HEADER) || width == NULL || height == NULL ) {\n\t\treturn -1;\n\t}\n\n\theader  = (PCX_HEADER *)pcx;\n\t*width  = header->xMax - header->xMin + 1;\n\t*height = header->yMax - header->yMin + 1;\n\n\tif( header->manufacturer != 10 ||\n\t\theader->version < 5 ||\n\t\theader->bpp != 8 ||\n\t\theader->rle != 1 ||\n\t\theader->planes != 1 ||\n\t\t*width == 0 ||\n\t\t*height == 0 )\n\t{\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Output() {\n\tINJECT(0x00450BA0, GetRenderHeight);\n\tINJECT(0x00450BB0, GetRenderWidth);\n\tINJECT(0x00450BC0, S_InitialisePolyList);\n\tINJECT(0x00450CB0, S_DumpScreen);\n\tINJECT(0x00450CF0, S_ClearScreen);\n\tINJECT(0x00450D00, S_InitialiseScreen);\n\tINJECT(0x00450D40, S_OutputPolyList);\n\tINJECT(0x00450D80, S_GetObjectBounds);\n\tINJECT(0x00450FF0, S_InsertBackPolygon);\n\tINJECT(0x00451040, S_PrintShadow);\n\tINJECT(0x00451240, S_CalculateLight);\n\tINJECT(0x00451540, S_CalculateStaticLight);\n\tINJECT(0x00451580, S_CalculateStaticMeshLight);\n\tINJECT(0x004516B0, S_LightRoom);\n\tINJECT(0x004518C0, S_DrawHealthBar);\n\tINJECT(0x00451A90, S_DrawAirBar);\n\tINJECT(0x00451C90, AnimateTextures);\n\tINJECT(0x00451D50, S_SetupBelowWater);\n\tINJECT(0x00451DB0, S_SetupAboveWater);\n\tINJECT(0x00451DE0, S_AnimateTextures);\n\tINJECT(0x00451EA0, S_DisplayPicture);\n\tINJECT(0x00451FB0, S_SyncPictureBufferPalette);\n\tINJECT(0x00452030, S_DontDisplayPicture);\n\tINJECT(0x00452040, ScreenDump);\n\tINJECT(0x00452050, ScreenPartialDump);\n\tINJECT(0x00452060, FadeToPal);\n\tINJECT(0x00452230, ScreenClear);\n\tINJECT(0x00452260, S_CopyScreenToBuffer);\n\tINJECT(0x00452310, S_CopyBufferToScreen);\n\tINJECT(0x00452360, DecompPCX);\n}\n"
  },
  {
    "path": "specific/output.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef OUTPUT_H_INCLUDED\n#define OUTPUT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nint __cdecl GetRenderScale(int unit);\nint __cdecl GetRenderHeightDownscaled();\nint __cdecl GetRenderWidthDownscaled();\nint __cdecl GetRenderHeight(); // 0x00450BA0\nint __cdecl GetRenderWidth(); // 0x00450BB0\nvoid __cdecl S_InitialisePolyList(BOOL clearBackBuffer); // 0x00450BC0\nDWORD __cdecl S_DumpScreen(); // 0x00450CB0\nvoid __cdecl S_ClearScreen(); // 0x00450CF0\nvoid __cdecl S_InitialiseScreen(GF_LEVEL_TYPE levelType); // 0x00450D00\nvoid __cdecl S_OutputPolyList(); // 0x00450D40\nint __cdecl S_GetObjectBounds(__int16 *bPtr); // 0x00450D80\nvoid __cdecl S_InsertBackPolygon(int x0, int y0, int x1, int y1); // 0x00450FF0\nvoid __cdecl S_PrintShadow(__int16 radius, __int16 *bPtr, ITEM_INFO *item); // 0x00451040\nvoid __cdecl S_CalculateLight(int x, int y, int z, __int16 roomNumber); // 0x00451240\nvoid __cdecl S_CalculateStaticLight(__int16 adder); // 0x00451540\nvoid __cdecl S_CalculateStaticMeshLight(int x, int y, int z, int shade1, int shade2, ROOM_INFO *room); // 0x00451580\nvoid __cdecl S_LightRoom(ROOM_INFO *room); // 0x004516B0\nvoid __cdecl S_DrawHealthBar(int percent); // 0x004518C0\nvoid __cdecl S_DrawAirBar(int percent); // 0x00451A90\nvoid __cdecl AnimateTextures(int nTicks); // 0x00451C90\nvoid __cdecl S_SetupBelowWater(BOOL underwater); // 0x00451D50\nvoid __cdecl S_SetupAboveWater(BOOL underwater); // 0x00451DB0\nvoid __cdecl S_AnimateTextures(int nTicks); // 0x00451DE0\nvoid __cdecl S_DisplayPicture(LPCTSTR fileName, BOOL reallocGame); // 0x00451EA0\nvoid __cdecl S_SyncPictureBufferPalette(); // 0x00451FB0\nvoid __cdecl S_DontDisplayPicture(); // 0x00452030\nvoid __cdecl ScreenDump(); // 0x00452040\nvoid __cdecl ScreenPartialDump(); // 0x00452050\nvoid __cdecl FadeToPal(int fadeValue, RGB888 *palette); // 0x00452060\nvoid __cdecl ScreenClear(bool isPhdWinSize); // 0x00452230\nvoid __cdecl S_CopyScreenToBuffer(); // 0x00452260\nvoid __cdecl S_CopyBufferToScreen(); // 0x00452310\nBOOL __cdecl DecompPCX(LPCBYTE pcx, DWORD pcxSize, LPBYTE pic, RGB888 *pal); // 0x00452360\n\n// NOTE: this function is not presented in the original game\nint GetPcxResolution(LPCBYTE pcx, DWORD pcxSize, DWORD *width, DWORD *height);\n\n#endif // OUTPUT_H_INCLUDED\n"
  },
  {
    "path": "specific/registry.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/registry.h\"\n#include \"global/vars.h\"\n\nstatic const BYTE GuidMask[] = { '{',3,2,1,0,'-',5,4,'-',7,6,'-',8,9,10,11,12,13,14,15,'}' };\nstatic const char HexChars[] = \"0123456789ABCDEF\";\n\nstatic inline BYTE HexChar(char c) {\n\tif( c>='0' && c<='9' )\n\t\treturn c-'0';\n\tif( c>='A' && c<='F' )\n\t\treturn c-'A'+10;\n\tif( c>='a' && c<='f' )\n\t\treturn c-'a'+10;\n\treturn 0xFF;\n}\n\nLPCTSTR __cdecl GuidBinaryToString(GUID *guid) {\n\tstatic char guidStringBuffer[GUID_STRING_SIZE];\n\tLPTSTR strPtr = guidStringBuffer;\n\n\tfor( DWORD i=0; i<sizeof(GuidMask); ++i ) {\n\t\tif( GuidMask[i] >= 16 ) {\n\t\t\t*(strPtr++) = GuidMask[i];\n\t\t} else {\n\t\t\tBYTE code = ((BYTE *)guid)[GuidMask[i]];\n\t\t\t*(strPtr++) = HexChars[code >> 4];\n\t\t\t*(strPtr++) = HexChars[code & 0xF];\n\t\t}\n\t}\n\t*strPtr = 0;\n\treturn guidStringBuffer;\n}\n\nbool __cdecl GuidStringToBinary(LPCTSTR lpString, GUID *guid) {\n\tfor( DWORD i=0; i<sizeof(GuidMask); ++i ) {\n\t\tif( GuidMask[i] >= 16 ) {\n\t\t\tif( *(lpString++) != GuidMask[i] )\n\t\t\t\treturn false;\n\t\t} else {\n\t\t\tBYTE hex1 = HexChar(*(lpString++));\n\t\t\tBYTE hex2 = HexChar(*(lpString++));\n\t\t\tif( hex1 >= 16 || hex2 >= 16 )\n\t\t\t\treturn false;\n\n\t\t\t((BYTE *)guid)[GuidMask[i]] = (hex1 << 4)|(hex2 & 0xF);\n\t\t}\n\t}\n\treturn ( *lpString == 0 ); // check if the string ends with zero\n}\n\nBOOL __cdecl OpenRegistryKey(LPCTSTR lpSubKey) {\n\treturn ( ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &HKey, &RegKeyDisposition) );\n}\n\nbool __cdecl IsNewRegistryKeyCreated() {\n\treturn ( RegKeyDisposition == REG_CREATED_NEW_KEY );\n}\n\nLONG __cdecl CloseRegistryKey() {\n\treturn RegCloseKey(HKey);\n}\n\nLONG __cdecl SetRegistryDwordValue(LPCTSTR lpValueName, DWORD value) {\n\treturn RegSetValueEx(HKey, lpValueName, 0, REG_DWORD, (const BYTE *)&value, sizeof(DWORD));\n}\n\nLONG __cdecl SetRegistryBoolValue(LPCTSTR lpValueName, bool value) {\n\tDWORD dwValue = value;\n\treturn RegSetValueEx(HKey, lpValueName, 0, REG_DWORD, (const BYTE *)&dwValue, sizeof(DWORD));\n}\n\nLONG __cdecl SetRegistryFloatValue(LPCTSTR lpValueName, double value) {\n\tint stringLen;\n\tchar stringBuf[64];\n\n\tstringLen = sprintf(stringBuf, \"%.5f\", value);\n\treturn SetRegistryStringValue(lpValueName, stringBuf, stringLen);\n}\n\nLONG __cdecl SetRegistryBinaryValue(LPCTSTR lpValueName, LPBYTE value, DWORD valueSize) {\n\tif( value != NULL )\n\t\treturn RegSetValueEx(HKey, lpValueName, 0, REG_BINARY, value, valueSize);\n\telse\n\t\treturn RegDeleteValue(HKey, lpValueName);\n}\n\nLONG __cdecl SetRegistryStringValue(LPCTSTR lpValueName, LPCTSTR value, int length) {\n\tif( value == NULL )\n\t\treturn RegDeleteValue(HKey, lpValueName);\n\n\tif( length < 0 )\n\t\tlength = lstrlen(value);\n\n\treturn RegSetValueEx(HKey, lpValueName, 0, REG_SZ, (const BYTE *)value, length+1);\n}\n\nLONG __cdecl DeleteRegistryValue(LPCTSTR lpValueName) {\n\treturn RegDeleteValue(HKey, lpValueName);\n}\n\nbool __cdecl GetRegistryDwordValue(LPCTSTR lpValueName, DWORD *pValue, DWORD defaultValue) {\n\tDWORD dwType;\n\tDWORD dwSize = sizeof(DWORD);\n\n\tif( ERROR_SUCCESS == RegQueryValueEx(HKey, lpValueName, 0, &dwType, (LPBYTE)pValue, &dwSize) &&\n\t\tdwType == REG_DWORD && dwSize == sizeof(DWORD) )\n\t{\n\t\treturn true;\n\t}\n\n\tSetRegistryDwordValue(lpValueName, defaultValue);\n\t*pValue = defaultValue;\n\treturn false;\n}\n\nbool __cdecl GetRegistryBoolValue(LPCTSTR lpValueName, bool *pValue, bool defaultValue) {\n\tDWORD dwType, dwValue;\n\tDWORD dwSize = sizeof(DWORD);\n\n\tif( ERROR_SUCCESS == RegQueryValueEx(HKey, lpValueName, 0, &dwType, (LPBYTE)&dwValue, &dwSize) &&\n\t\tdwType == REG_DWORD && dwSize == sizeof(DWORD) )\n\t{\n\t\t*pValue = dwValue ? true : false;\n\t\treturn true;\n\t}\n\n\tSetRegistryBoolValue(lpValueName, defaultValue);\n\t*pValue = defaultValue;\n\treturn false;\n}\n\nbool __cdecl GetRegistryFloatValue(LPCTSTR lpValueName, double *value, double defaultValue) {\n\tchar stringBuf[64];\n\n\tif( GetRegistryStringValue(lpValueName, stringBuf, sizeof(stringBuf), NULL) ) {\n\t\t*value = atof(stringBuf);\n\t\treturn true;\n\t}\n\n\tSetRegistryFloatValue(lpValueName, defaultValue);\n\t*value = defaultValue;\n\treturn false;\n}\n\nbool __cdecl GetRegistryBinaryValue(LPCTSTR lpValueName, LPBYTE value, DWORD valueSize, LPBYTE defaultValue) {\n\tDWORD dwType;\n\tDWORD dwSize = valueSize;\n\n\tif( ERROR_SUCCESS == RegQueryValueEx(HKey, lpValueName, 0, &dwType, value, &dwSize) &&\n\t\tdwType == REG_BINARY && dwSize == valueSize )\n\t{\n\t\treturn true;\n\t}\n\n\tif( defaultValue != NULL )\n\t\tSetRegistryBinaryValue(lpValueName, defaultValue, valueSize);\n\telse\n\t\tRegDeleteValue(HKey, lpValueName);\n\n\treturn false;\n}\n\nbool __cdecl GetRegistryStringValue(LPCTSTR lpValueName, LPTSTR value, DWORD maxSize, LPCTSTR defaultValue) {\n\tDWORD dwType;\n\tDWORD dwSize = maxSize;\n\n\tif( ERROR_SUCCESS == RegQueryValueEx(HKey, lpValueName, 0, &dwType, (LPBYTE)value, &dwSize) &&\n\t\tdwType == REG_SZ )\n\t{\n\t\treturn true;\n\t}\n\n\tif( defaultValue != NULL ) {\n\t\tSetRegistryStringValue(lpValueName, defaultValue, -1);\n\t\tdwSize = lstrlen(defaultValue) + 1;\n\t\tif( dwSize > maxSize ) {\n\t\t\tdwSize = maxSize-1;\n\t\t\tvalue[dwSize] = 0;\n\t\t}\n\t\tmemcpy(value, defaultValue, dwSize);\n\t} else {\n\t\tRegDeleteValue(HKey, lpValueName);\n\t}\n\treturn false;\n}\n\nbool __cdecl GetRegistryGuidValue(LPCTSTR lpValueName, GUID *value, GUID *defaultValue) {\n\tLPCTSTR guidString;\n\tchar guidStringBuffer[GUID_STRING_SIZE];\n\n\tif( GetRegistryStringValue(lpValueName, guidStringBuffer, GUID_STRING_SIZE, NULL) &&\n\t\tGuidStringToBinary(guidStringBuffer, value) )\n\t{\n\t\treturn true;\n\t}\n\n\tif( defaultValue != NULL ) {\n\t\tguidString = GuidBinaryToString(defaultValue);\n\t\tSetRegistryStringValue(lpValueName, guidString, GUID_STRING_SIZE-1);\n\t\t*value = *defaultValue;\n\t} else {\n\t\tRegDeleteValue(HKey, lpValueName);\n\t}\n\n\treturn false;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Registry() {\n\tINJECT(0x00456A20, GuidBinaryToString);\n\tINJECT(0x00456A80, GuidStringToBinary);\n\tINJECT(0x00456B30, OpenRegistryKey);\n\tINJECT(0x00456B60, IsNewRegistryKeyCreated);\n\tINJECT(0x00456B70, CloseRegistryKey);\n\tINJECT(0x00456B80, SetRegistryDwordValue);\n\tINJECT(0x00456BA0, SetRegistryBoolValue);\n\tINJECT(0x00456BD0, SetRegistryFloatValue);\n\tINJECT(0x00456C10, SetRegistryBinaryValue);\n\tINJECT(0x00456C50, SetRegistryStringValue);\n\tINJECT(0x00456CA0, DeleteRegistryValue);\n\tINJECT(0x00456CC0, GetRegistryDwordValue);\n\tINJECT(0x00456D20, GetRegistryBoolValue);\n\tINJECT(0x00456DA0, GetRegistryFloatValue);\n\tINJECT(0x00456E00, GetRegistryBinaryValue);\n\tINJECT(0x00456E80, GetRegistryStringValue);\n\tINJECT(0x00456F20, GetRegistryGuidValue);\n}\n"
  },
  {
    "path": "specific/registry.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef REGISTRY_H_INCLUDED\n#define REGISTRY_H_INCLUDED\n\n#include \"global/types.h\"\n\n// Registry path\n#define REG_TR2_PATH\t\t\t\"Software\\\\Core Design\\\\Tomb Raider II\"\n\n// Registry keys\n#define REG_SYSTEM_KEY\t\t\t\"System\"\n#define REG_GAME_KEY\t\t\t\"Game\"\n#define REG_VIEW_KEY\t\t\t\"View\"\n#define REG_BUGS_KEY\t\t\t\"Bugs\"\n\n// DWORD value names\n#define REG_DISPLAY_ADAPTER\t\t\"PreferredDisplayAdapterGUID\"\n#define REG_SOUND_ADAPTER\t\t\"PreferredSoundAdapterGUID\"\n#define REG_JOYSTICK\t\t\t\"PreferredJoystickGUID\"\n#define REG_RENDERER\t\t\t\"RenderMode\"\n#define REG_FS_WIDTH\t\t\t\"FullScreenWidth\"\n#define REG_FS_HEIGHT\t\t\t\"FullScreenHeight\"\n#define REG_FS_BPP\t\t\t\t\"FullScreenBPP\"\n#define REG_WIN_WIDTH\t\t\t\"WindowWidth\"\n#define REG_WIN_HEIGHT\t\t\t\"WindowHeight\"\n#define REG_WIN_ASPECT\t\t\t\"AspectMode\"\n#define REG_ADJUST_MODE\t\t\t\"TexelAdjustMode\"\n#define REG_ADJUST_NEAREST\t\t\"NearestAdjustment\"\n#define REG_ADJUST_LINEAR\t\t\"LinearAdjustment\"\n#define REG_LIGHTING_MODE\t\t\"LightingMode\"\n#define REG_MUSIC_VOLUME\t\t\"MusicVolume\"\n#define REG_SOUND_VOLUME\t\t\"SoundFXVolume\"\n#define REG_DETAIL_LEVEL\t\t\"DetailLevel\"\n#define REG_INVBGND_MODE\t\t\"InvBackgroundMode\"\n#define REG_STATSBGND_MODE\t\t\"StatsBackgroundMode\"\n#define REG_PICTURE_STRETCH\t\t\"PictureStretchLimit\"\n#define REG_LOADING_SCREENS\t\t\"LoadingScreens\"\n#define REG_CUSTOM_WATER_COLOR\t\"CustomWaterColor\"\n#define REG_SHADOW_MODE\t\t\t\"ShadowMode\"\n#define REG_REFLECTION_MODE\t\t\"ReflectionMode\"\n#define REG_ALPHABLEND_MODE\t\t\"AlphaBlendMode\"\n#define REG_INVTEXTBOX_MODE\t\t\"InvTextBoxMode\"\n#define REG_HEALTHBAR_MODE\t\t\"HealthBarMode\"\n#define REG_PICKUPITEM_MODE\t\t\"PickupItemMode\"\n#define REG_DEMOTEXT_MODE\t\t\"DemoTextMode\"\n#define REG_SAVEGAME_SLOTS\t\t\"SavegameSlots\"\n#define REG_SCREENSHOT_FORMAT\t\"ScreenshotFormat\"\n#define REG_JOYSTICK_BTN_STYLE\t\"JoystickButtonStyle\"\n#define REG_PAUSEBGND_MODE\t\t\"PauseBackgroundMode\"\n\n// BOOL value names\n#define REG_PERSPECTIVE\t\t\t\"PerspectiveCorrect\"\n#define REG_DITHER\t\t\t\t\"Dither\"\n#define REG_ZBUFFER\t\t\t\t\"ZBuffer\"\n#define REG_BILINEAR\t\t\t\"BilinearFiltering\"\n#define REG_TRIPLEBUFFER\t\t\"TripleBuffering\"\n#define REG_FULLSCREEN\t\t\t\"FullScreen\"\n#define REG_SOUND_ENABLE\t\t\"SoundEnabled\"\n#define REG_LARA_MIC\t\t\t\"LaraMic\"\n#define REG_JOY_ENABLE\t\t\t\"JoystickEnabled\"\n#define REG_16BIT_DISABLE\t\t\"Disable16BitTextures\"\n#define REG_SORT_DISABLE\t\t\"DontSortPrimitives\"\n#define REG_FLIP_BROKEN\t\t\t\"FlipBroken\"\n#define REG_FMV_DISABLE\t\t\t\"DisableFMV\"\n#define REG_PSXBARPOS_ENABLE\t\"EnablePsxBarPos\"\n#define REG_PSXFOV_ENABLE\t\t\"EnablePsxFov\"\n#define REG_BAREFOOT_SFX_ENABLE\t\"BarefootSFX\"\n#define REG_REMASTER_PIX_ENABLE\t\"RemasteredPictures\"\n#define REG_WALK_TO_SIDESTEP\t\"WalkToSidestep\"\n#define REG_JOYSTICK_VIBRATION\t\"JoystickVibration\"\n#define REG_JOYSTICK_LED_COLOR\t\"JoystickLedColor\"\n#define REG_JOYSTICK_HINTS\t\t\"JoystickHints\"\n#define REG_AVOID_INTERLACED\t\"AvoidInterlacedVideoModes\"\n#define REG_RUNNING_M16_FIX\t\t\"RunningM16fix\"\n#define REG_LOWCEILING_JUMP_FIX\t\"LowCeilingJumpFix\"\n\n// FLOAT value names\n#define REG_GAME_SIZER\t\t\"Sizer\"\n#define REG_INV_MUSIC_MUTE\t\"InvMusicMute\"\n#define REG_UW_MUSIC_MUTE\t\"UwMusicMute\"\n#define REG_DRAW_DISTANCE\t\"DrawDistance\"\n#define REG_FOG_BEGIN\t\t\"FogBegin\"\n#define REG_FOG_END\t\t\t\"FogEnd\"\n#define REG_UW_FOG_BEGIN\t\"UwFogBegin\"\n#define REG_UW_FOG_END\t\t\"UwFogEnd\"\n#define REG_GAME_GUI_SCALE\t\"GameGUIScale\"\n#define REG_INV_GUI_SCALE\t\"InvGUIScale\"\n\n// BINARY value names\n#define REG_GAME_LAYOUT\t\t\"Layout\"\n#define REG_GAME_KBD_LAYOUT\t\"KeyboardLayout\"\n#define REG_GAME_JOY_LAYOUT\t\"JoystickLayout\"\n#define REG_GAME_ASSAULT\t\"Assault\"\n\n// STRING value names\n#define REG_SCREENSHOT_PATH\t\"ScreenshotPath\"\n#define REG_PICTURE_SUFFIX\t\"PictureSuffix\"\n\n// GUID string size\n#define GUID_STRING_SIZE (sizeof(\"{00112233-4455-6677-8899AABBCCDDEEFF}\"))\n\n/*\n * Function list\n */\nLPCTSTR __cdecl GuidBinaryToString(GUID *guid); // 0x00456A20\nbool __cdecl GuidStringToBinary(LPCTSTR lpString, GUID *guid); // 0x00456A80\nBOOL __cdecl OpenRegistryKey(LPCTSTR lpSubKey); // 0x00456B30\nbool __cdecl IsNewRegistryKeyCreated(); // 0x00456B60\nLONG __cdecl CloseRegistryKey(); // 0x00456B70\nLONG __cdecl SetRegistryDwordValue(LPCTSTR lpValueName, DWORD value); // 0x00456B80\nLONG __cdecl SetRegistryBoolValue(LPCTSTR lpValueName, bool value); // 0x00456BA0\nLONG __cdecl SetRegistryFloatValue(LPCTSTR lpValueName, double value); // 0x00456BD0\nLONG __cdecl SetRegistryBinaryValue(LPCTSTR lpValueName, LPBYTE value, DWORD valueSize); // 0x00456C10\nLONG __cdecl SetRegistryStringValue(LPCTSTR lpValueName, LPCTSTR value, int length); // 0x00456C50\nLONG __cdecl DeleteRegistryValue(LPCTSTR lpValueName); // 0x00456CA0\nbool __cdecl GetRegistryDwordValue(LPCTSTR lpValueName, DWORD *pValue, DWORD defaultValue); // 0x00456CC0\nbool __cdecl GetRegistryBoolValue(LPCTSTR lpValueName, bool *pValue, bool defaultValue); // 0x00456D20\nbool __cdecl GetRegistryFloatValue(LPCTSTR lpValueName, double *value, double defaultValue); // 0x00456DA0\nbool __cdecl GetRegistryBinaryValue(LPCTSTR lpValueName, LPBYTE value, DWORD valueSize, LPBYTE defaultValue); // 0x00456E00\nbool __cdecl GetRegistryStringValue(LPCTSTR lpValueName, LPTSTR value, DWORD maxSize, LPCTSTR defaultValue); // 0x00456E80\nbool __cdecl GetRegistryGuidValue(LPCTSTR lpValueName, GUID *value, GUID *defaultValue); // 0x00456F20\n\n#endif // REGISTRY_H_INCLUDED\n"
  },
  {
    "path": "specific/screenshot.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/screenshot.h\"\n#include \"specific/winvid.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_SCREENSHOT_IMPROVED\n#include \"modding/file_utils.h\"\n#include \"modding/gdi_utils.h\"\n\nextern LPDDS CaptureBufferSurface;\n\nDWORD ScreenshotFormat = 1;\nchar ScreenshotPath[MAX_PATH];\n\ntypedef struct {\n\tHBITMAP bitmap;\n\tGDI_FILEFMT format;\n\tBYTE quality;\n\tchar fileName[MAX_PATH];\n} TASK_PARAMS;\n\nstatic DWORD WINAPI SaveImageTask(CONST LPVOID lpParam) {\n\tTASK_PARAMS *params = (TASK_PARAMS *)lpParam;\n\tif( params != NULL ) {\n\t\tif( params->bitmap != NULL ) {\n\t\t\tGDI_SaveImageFile(params->fileName, params->format, params->quality, params->bitmap);\n\t\t\tDeleteObject(params->bitmap);\n\t\t}\n\t\tdelete params;\n\t}\n\tExitThread(0);\n}\n\nstatic void __cdecl ScreenShotPNG(LPDDS screen) {\n\tstatic SYSTEMTIME lastTime = {0, 0, 0, 0, 0, 0, 0, 0};\n\tstatic int lastIndex = 0;\n\tRECT rect = {0, 0, 0, 0};\n\tHDC dc;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tscreen = NULL;\n\tDISPLAY_MODE mode;\n\n\tif( CaptureBufferSurface != NULL ) {\n\t\tscreen = CaptureBufferSurface;\n\t} else if( !WinVidGetDisplayMode(&mode)\n\t\t|| FAILED(D3DDev->CreateOffscreenPlainSurface(mode.width, mode.height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &screen, NULL))\n\t\t|| FAILED(D3DDev->GetFrontBufferData(0, screen)) )\n\t{\n\t\tif( screen != NULL ) screen->Release();\n\t\treturn;\n\t}\n\n\tif FAILED(screen->GetDC(&dc)) {\n\t\tif( screen != CaptureBufferSurface ) {\n\t\t\tscreen->Release();\n\t\t}\n\t\treturn;\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( screen == NULL || FAILED(screen->GetDC(&dc)) ) {\n\t\treturn;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( GetClientRect(HGameWindow, &rect) ) {\n\t\tHBITMAP bitmap;\n\t\tLPVOID lpBits;\n\n\t\tif( CaptureBufferSurface == NULL ) {\n\t\t\tMapWindowPoints(HGameWindow, GetParent(HGameWindow), (LPPOINT)&rect, 2);\n\t\t}\n\n\t\tbitmap = CreateBitmapFromDC(dc, &rect, &lpBits, WinVidPalette);\n\t\tif( bitmap != NULL ) {\n\t\t\tTASK_PARAMS *params = new TASK_PARAMS;\n\t\t\tparams->bitmap = bitmap;\n\t\t\tparams->format = GDI_PNG;\n\t\t\tparams->quality = 100;\n\n\t\t\tCreateDateTimeFilename(params->fileName, sizeof(params->fileName), ScreenshotPath, \".png\", &lastTime, &lastIndex);\n\t\t\tCreateDirectories(params->fileName, true);\n\t\t\tif( !CreateThread(NULL, 0, &SaveImageTask, params, 0, NULL) ) {\n\t\t\t\t// if failed to create a thread, we just save the image\n\t\t\t\tGDI_SaveImageFile(params->fileName, params->format, params->quality, params->bitmap);\n\t\t\t\tDeleteObject(bitmap);\n\t\t\t\tdelete params;\n\t\t\t}\n\t\t}\n\t}\n\tscreen->ReleaseDC(dc);\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( screen != CaptureBufferSurface ) {\n\t\tscreen->Release();\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n\nstatic TGA_HEADER ScreenShotTgaHeader = {\n\t0, 0,\n\t.dataTypeCode = 2, // Uncompressed, RGB images\n\t0, 0, 0, 0, 0,\n\t.width = 320,\n\t.height = 256,\n\t.bpp = 16,\n\t.imageDescriptor = 0,\n};\n\n\n// NOTE: This function is not presented in the original code\n// but the code is taken away form ScreenShot() and extended\n// to be compatible with 24/32 bit\nstatic void __cdecl ScreenShotTGA(LPDDS screen, BYTE tgaBpp) {\n\tstatic int scrshotNumber = 0;\n\tDWORD i, j;\n\tBYTE *src, *dst;\n\tDDSDESC desc;\n\tBYTE *tgaPic = NULL;\n\tHANDLE hFile = INVALID_HANDLE_VALUE;\n\tDWORD bytesWritten;\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\tchar fileName[MAX_PATH];\n#else // !FEATURE_SCREENSHOT_IMPROVED\n\tchar fileName[128];\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\tDWORD width = 0;\n\tDWORD height = 0;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( tgaBpp != 24 )\n\t\treturn;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( tgaBpp != 16 && tgaBpp != 24 )\n\t\treturn;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tmemset(&desc, 0, sizeof(desc));\n#if (DIRECT3D_VERSION < 0x900)\n\tdesc.dwSize = sizeof(desc);\n#endif // (DIRECT3D_VERSION < 0x900)\n\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\tRECT rect = {0,0,0,0};\n\n\t// do game window screenshot, not the whole screen\n\tif( GetClientRect(HGameWindow, &rect) ) {\n\t\tif( CaptureBufferSurface == NULL ) {\n\t\t\tMapWindowPoints(HGameWindow, GetParent(HGameWindow), (LPPOINT)&rect, 2);\n\t\t}\n\t\twidth = ABS(rect.right - rect.left);\n\t\theight = ABS(rect.bottom - rect.top);\n\t}\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tscreen = NULL;\n\tDISPLAY_MODE mode;\n\n\tif( CaptureBufferSurface != NULL ) {\n\t\tscreen = CaptureBufferSurface;\n\t} else if( !WinVidGetDisplayMode(&mode)\n\t\t|| FAILED(D3DDev->CreateOffscreenPlainSurface(mode.width, mode.height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &screen, NULL))\n\t\t|| FAILED(D3DDev->GetFrontBufferData(0, screen)) )\n\t{\n\t\tgoto CLEANUP;\n\t}\n\n\tif FAILED(screen->LockRect(&desc, &rect, D3DLOCK_READONLY)) {\n\t\tgoto CLEANUP;\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tHRESULT rc;\n\tdo {\n\t\trc = screen->Lock(&rect, &desc, DDLOCK_READONLY|DDLOCK_WAIT, NULL);\n\t} while( rc == DDERR_WASSTILLDRAWING );\n\n\tif( rc == DDERR_SURFACELOST )\n\t\trc = screen->Restore();\n\tif FAILED(rc)\n\t\treturn;\n\n\tif( width == 0 || width > desc.dwWidth )\n\t\twidth = desc.dwWidth;\n\tif( height == 0 || height > desc.dwHeight )\n\t\theight = desc.dwHeight;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tscrshotNumber = CreateSequenceFilename(fileName, sizeof(fileName), ScreenshotPath, \".tga\", \"tomb\", 4, scrshotNumber);\n\tif( scrshotNumber < 0 ) goto CLEANUP;\n\t++scrshotNumber;\n\tCreateDirectories(fileName, true); // create whole path just in case if it's not created yet\n#else // !FEATURE_SCREENSHOT_IMPROVED\n#if (DIRECT3D_VERSION < 0x900)\n\tif FAILED(WinVidBufferLock(screen, &desc, DDLOCK_WRITEONLY|DDLOCK_WAIT))\n\t\treturn;\n\n\twidth = desc.dwWidth;\n\theight = desc.dwHeight;\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\twsprintf(fileName, \"tomb%04d.tga\", scrshotNumber++);\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n\thFile = CreateFile(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile == INVALID_HANDLE_VALUE )\n\t\tgoto CLEANUP;\n\n\tScreenShotTgaHeader.width = width;\n\tScreenShotTgaHeader.height = height;\n\tScreenShotTgaHeader.bpp = tgaBpp;\n\tWriteFile(hFile, &ScreenShotTgaHeader, sizeof(TGA_HEADER), &bytesWritten, NULL);\n\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\t// NOTE: There was unsafe memory usage in the original code. The game just used GameAllocMemPointer buffer!\n\t// No new memory allocations. On higher resolutions there was critical data overwriting and game crashed\n\ttgaPic = (BYTE *)GlobalAlloc(GMEM_FIXED, width*height*(tgaBpp/8));\n#else // !FEATURE_SCREENSHOT_IMPROVED\n\ttgaPic = (BYTE *)GameAllocMemPointer;\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n\tif( tgaPic == NULL )\n\t\tgoto CLEANUP;\n\n\t// We need to load bitmap lines to TGA starting from the bottom line\n#if (DIRECT3D_VERSION >= 0x900)\n\tsrc = (BYTE *)desc.pBits + desc.Pitch*(height - 1);\n#else // (DIRECT3D_VERSION >= 0x900)\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\t// NOTE: There was bug in the original formula: src = lpSurface + lPitch * dwHeight\n\t// Height must be subtracted by 1 in this formula\n\tsrc = (BYTE *)desc.lpSurface + desc.lPitch*(height - 1);\n#else // !FEATURE_SCREENSHOT_IMPROVED\n\tsrc = (BYTE *)desc.lpSurface + desc.lPitch*height;\n#endif // FEATURE_SCREENSHOT_IMPROVED\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tdst = tgaPic;\n#if (DIRECT3D_VERSION >= 0x900)\n\tfor( i=0; i < height; ++i ) {\n\t\tfor( j=0; j < width; ++j ) {\n\t\t\t((RGB888 *)dst)[j] = *(RGB888*)(src + j * 4);\n\t\t}\n\t\tsrc -= desc.Pitch;\n\t\tdst += sizeof(RGB888)*width;\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( tgaBpp == 16 ) {\n\t\tfor( i=0; i < height; ++i ) {\n\t\t\t// R5G6B5 - not TGA compatible\n\t\t\tif( desc.ddpfPixelFormat.dwRBitMask == 0xF800 ) {\n\t\t\t\t// right shift highest 10 bits (R+G) over lowest G bit\n\t\t\t\tfor( j=0; j < width; ++j ) {\n\t\t\t\t\tUINT16 sample = ((UINT16 *)src)[j];\n\t\t\t\t\t((UINT16 *)dst)[j] = ((sample & 0xFFC0) >> 1) | (sample & 0x001F);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// X1R5G5B5 - already TGA compatible\n\t\t\t\tmemcpy(dst, src, sizeof(UINT16)*width);\n\t\t\t}\n\t\t\tsrc -= desc.lPitch;\n\t\t\tdst += sizeof(UINT16)*width;\n\t\t}\n\t} else {\n\t\tfor( i=0; i < height; ++i ) {\n\t\t\tif( desc.ddpfPixelFormat.dwRGBBitCount == 24 ) {\n\t\t\t\tmemcpy(dst, src, sizeof(RGB888)*width);\n\t\t\t} else {\n\t\t\t\tfor( j=0; j < width; ++j ) {\n\t\t\t\t\t((RGB888 *)dst)[j] = *(RGB888*)(src + j * (desc.ddpfPixelFormat.dwRGBBitCount / 8));\n\t\t\t\t}\n\t\t\t}\n\t\t\tsrc -= desc.lPitch;\n\t\t\tdst += sizeof(RGB888)*width;\n\t\t}\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\tWriteFile(hFile, tgaPic, width*height*(tgaBpp/8), &bytesWritten, NULL);\n\nCLEANUP :\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\tif( tgaPic != NULL )\n\t\tGlobalFree((HGLOBAL)tgaPic);\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n\tif( hFile != INVALID_HANDLE_VALUE )\n\t\tCloseHandle(hFile);\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( screen != NULL ) {\n\t\tscreen->UnlockRect();\n\t\tif( screen != CaptureBufferSurface ) {\n\t\t\tscreen->Release();\n\t\t}\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\tscreen->Unlock(desc.lpSurface);\n#else // !FEATURE_SCREENSHOT_IMPROVED\n\tWinVidBufferUnlock(screen, &desc);\n#endif // FEATURE_SCREENSHOT_IMPROVED\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\n\nvoid __cdecl ScreenShotPCX() {\n\tstatic int scrshotNumber = 0;\n#if (DIRECT3D_VERSION < 0x900)\n\tHRESULT rc;\n\tLPDDS screen;\n\tDDSDESC desc;\n#endif // (DIRECT3D_VERSION < 0x900)\n\tBYTE *pcxData = NULL;\n\tDWORD pcxSize;\n\tHANDLE hFile = INVALID_HANDLE_VALUE;\n\tDWORD bytesWritten;\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\tchar fileName[MAX_PATH];\n#else // !FEATURE_SCREENSHOT_IMPROVED\n\tchar fileName[128];\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( !RenderBuffer.bitmap || !RenderBuffer.width || !RenderBuffer.height ) return;\n\tpcxSize = CompPCX(RenderBuffer.bitmap, RenderBuffer.width, RenderBuffer.height, GamePalette8, &pcxData);\n#else // (DIRECT3D_VERSION >= 0x900)\n\tscreen = ( SavedAppSettings.RenderMode == RM_Software ) ? RenderBufferSurface : PrimaryBufferSurface;\n\tdesc.dwSize = sizeof(desc);\n\n\tdo {\n\t\trc = screen->Lock(NULL, &desc, DDLOCK_SURFACEMEMORYPTR, NULL);\n\t} while( rc == DDERR_WASSTILLDRAWING );\n\n\tif( rc == DDERR_SURFACELOST )\n\t\trc = screen->Restore();\n\tif FAILED(rc)\n\t\treturn;\n\n\tpcxSize = CompPCX((BYTE *)desc.lpSurface, desc.dwWidth, desc.dwHeight, GamePalette8, &pcxData);\n\tscreen->Unlock(&desc);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( pcxSize == 0 || pcxData == NULL )\n\t\treturn;\n\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\tscrshotNumber = CreateSequenceFilename(fileName, sizeof(fileName), ScreenshotPath, \".pcx\", \"tomb\", 4, scrshotNumber);\n\tif( scrshotNumber < 0 ) return;\n\t++scrshotNumber;\n\tCreateDirectories(fileName, true); // create whole path just in case if it is not created yet\n#else // !FEATURE_SCREENSHOT_IMPROVED\n\tif( ++scrshotNumber > 9999 ) scrshotNumber = 1;\n\twsprintf(fileName, \"tomb%04d.pcx\", scrshotNumber);\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n\thFile = CreateFile(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n\tif( hFile != INVALID_HANDLE_VALUE ) {\n\t\tWriteFile(hFile, pcxData, pcxSize, &bytesWritten, NULL);\n\t\tCloseHandle(hFile);\n\t}\n\tGlobalFree(pcxData);\n}\n\n\nDWORD __cdecl CompPCX(BYTE *bitmap, DWORD width, DWORD height, RGB888 *palette, BYTE **pcxData) {\n\tDWORD i;\n\tPCX_HEADER *pcxHeader;\n\tBYTE *picData;\n\n\t*pcxData = (BYTE *)GlobalAlloc(GMEM_FIXED, width*height*2 + sizeof(PCX_HEADER) + sizeof(RGB888)*256);\n\tif( *pcxData == NULL )\n\t\treturn 0;\n\n\tpcxHeader = *(PCX_HEADER **)pcxData;\n\n\tpcxHeader->manufacturer = 10;\n\tpcxHeader->version = 5;\n\tpcxHeader->rle = 1;\n\tpcxHeader->bpp = 8;\n\tpcxHeader->planes = 1;\n\n\tpcxHeader->xMin = 0;\n\tpcxHeader->yMin = 0;\n\tpcxHeader->xMax = width - 1;\n\tpcxHeader->yMax = height - 1;\n\tpcxHeader->h_dpi = width;\n\tpcxHeader->v_dpi = height;\n\tpcxHeader->bytesPerLine = width;\n\n\tpicData = *pcxData + sizeof(PCX_HEADER);\n\tfor( i=0; i<height; ++i ) {\n\t\tpicData += EncodeLinePCX(bitmap, width, picData);\n\t\tbitmap += width;\n\t}\n\n\t*(picData++) = 0x0C;\n\tmemcpy(picData, palette, sizeof(RGB888)*256);\n\n\treturn (DWORD)(picData - *pcxData + sizeof(RGB888)*256); // pcx data size\n}\n\n\nDWORD __cdecl EncodeLinePCX(BYTE *src, DWORD width, BYTE *dst) {\n\tBYTE current, add;\n\tDWORD total = 0;\n\tBYTE runCount = 1;\n\tBYTE last = *src;\n\n\tfor( DWORD i=1; i<width; ++i ) {\n\t\tcurrent = *(++src);\n\t\tif( current == last ) {\n\t\t\t++runCount;\n\t\t\tif( runCount == 63 ) {\n\t\t\t\tadd = EncodePutPCX(last, runCount, dst);\n\t\t\t\tif( add == 0 ) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\ttotal += add;\n\t\t\t\tdst += add;\n\t\t\t\trunCount = 0;\n\t\t\t}\n\t\t} else {\n\t\t\tif( runCount != 0 ) {\n\t\t\t\tadd = EncodePutPCX(last, runCount, dst);\n\t\t\t\tif( add == 0 ) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\ttotal += add;\n\t\t\t\tdst += add;\n\t\t\t}\n\t\t\tlast = current;\n\t\t\trunCount = 1;\n\t\t}\n\t}\n\n\tif( runCount ) {\n\t\tadd = EncodePutPCX(last, runCount, dst);\n\t\tif( add == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\ttotal += add;\n\t\tdst += add;\n\t}\n\treturn total;\n}\n\n\nDWORD __cdecl EncodePutPCX(BYTE value, BYTE num, BYTE *buffer) {\n\tif( num == 0 || num > 63 ) {\n\t\treturn 0;\n\t}\n\n\tif( num == 1 && (value & 0xC0) != 0xC0 ) {\n\t\tbuffer[0] = value;\n\t\treturn 1;\n\t}\n\n\tbuffer[0] = num | 0xC0;\n\tbuffer[1] = value;\n\treturn 2;\n}\n\n\nvoid __cdecl ScreenShot(LPDDS screen) {\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n#if (DIRECT3D_VERSION < 0x900)\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\tscreen = RenderBufferSurface;\n\t} else if( CaptureBufferSurface != NULL ) {\n\t\tscreen = CaptureBufferSurface;\n\t}\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\tif( ScreenshotFormat > 0 ) {\n\t\tScreenShotPNG(screen);\n\t\treturn;\n\t}\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( SavedAppSettings.RenderMode == RM_Software ) {\n\t\tScreenShotPCX();\n\t} else {\n\t\tScreenShotTGA(screen, 24);\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tDDSDESC desc;\n\n\tmemset(&desc, 0, sizeof(desc));\n\tdesc.dwSize = sizeof(desc);\n\n\tif SUCCEEDED( screen->GetSurfaceDesc(&desc)) {\n\t\tswitch( desc.ddpfPixelFormat.dwRGBBitCount ) {\n\t\t\tcase 8 :\n\t\t\t\tScreenShotPCX();\n\t\t\t\tbreak;\n\n\t\t\tcase 16 :\n\t\t\t\tScreenShotTGA(screen, 16);\n\t\t\t\tbreak;\n\n#if defined(FEATURE_SCREENSHOT_IMPROVED)\n\t\t\tcase 24 :\n\t\t\tcase 32 :\n\t\t\t\t// NOTE: the original game cannot make 24/32 bit screenshots\n\t\t\t\tScreenShotTGA(screen, 24);\n\t\t\t\tbreak;\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n\t\t\tdefault :\n\t\t\t\tbreak;\n\t\t}\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\n\n/*\n * Inject function\n */\nvoid Inject_Screenshot() {\n\tINJECT(0x0044E9A0, ScreenShotPCX);\n\tINJECT(0x0044EAB0, CompPCX);\n\tINJECT(0x0044EB60, EncodeLinePCX);\n\tINJECT(0x0044EC40, EncodePutPCX);\n\tINJECT(0x0044EC80, ScreenShot);\n}\n"
  },
  {
    "path": "specific/screenshot.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SCREENSHOT_H_INCLUDED\n#define SCREENSHOT_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __cdecl ScreenShotPCX(); // 0x0044E9A0\nDWORD __cdecl CompPCX(BYTE *bitmap, DWORD width, DWORD height, RGB888 *palette, BYTE **pcxData); // 0x0044EAB0\nDWORD __cdecl EncodeLinePCX(BYTE *src, DWORD width, BYTE *dst); // 0x0044EB60\nDWORD __cdecl EncodePutPCX(BYTE value, BYTE num, BYTE *buffer); // 0x0044EC40\nvoid __cdecl ScreenShot(LPDDS screen); // 0x0044EC80\n\n#endif // SCREENSHOT_H_INCLUDED\n"
  },
  {
    "path": "specific/setupdlg.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/setupdlg.h\"\n#include \"specific/init_display.h\"\n#include \"specific/init_input.h\"\n#include \"specific/init_sound.h\"\n#include \"specific/registry.h\"\n#include \"specific/setupwnd.h\"\n#include \"specific/utils.h\"\n#include \"specific/winvid.h\"\n#include \"global/resource.h\"\n#include \"global/vars.h\"\n#include <commctrl.h>\n\n#if defined(FEATURE_NOLEGACY_OPTIONS) || defined(FEATURE_VIDEOFX_IMPROVED)\nAPP_SETTINGS ChangedAppSettings, SavedAppSettings;\n#endif // defined(FEATURE_NOLEGACY_OPTIONS) || defined(FEATURE_VIDEOFX_IMPROVED)\n\nstatic LPCTSTR String_Software3d = \"Software (256 Colors)\";\nstatic LPCTSTR String_Hardware3d = \"Hardware 3D Acceleration\";\nstatic LPCTSTR String_FullScreen = \"Full Screen\";\nstatic LPCTSTR String_Windowed = \"Windowed\";\nstatic LPCTSTR String_ZBuffered = \"Z Buffered\";\nstatic LPCTSTR String_BilinearFiltered = \"Bilinear Filtered\";\n\n#ifndef FEATURE_NOLEGACY_OPTIONS\nstatic LPCTSTR String_Dithered = \"Dithered\";\nstatic LPCTSTR String_TripleBuffered = \"Triple Buffered\";\nstatic LPCTSTR String_PerspectiveCorrect = \"Perspective Correct\";\n#endif // FEATURE_NOLEGACY_OPTIONS\n\nstatic LPCTSTR String_None = \"None\";\nstatic LPCTSTR String_NA = \"n/a\";\nstatic LPCTSTR String_Enabled = \"Enabled\";\nstatic LPCTSTR String_Disabled = \"Disabled\";\nstatic LPCTSTR String_Lara = \"Lara\";\nstatic LPCTSTR String_Camera = \"Camera\";\nstatic LPCTSTR Strings_Aspect[] = {\" (4:3)\", \" (16:9)\", \"\"};\n\n#ifndef FEATURE_NOLEGACY_OPTIONS\nstatic LPCTSTR String_HighColor = \"High Color\";\nstatic LPCTSTR String_TrueColor = \"True Color\";\nstatic LPCTSTR String_256Color = \"256 Color\";\nstatic LPCTSTR String_ModeX = \"Mode X\";\nstatic LPCTSTR String_StandardVga = \"Standard VGA\";\n#endif // FEATURE_NOLEGACY_OPTIONS\n\nstatic LPCTSTR String_VidTestPassed = \"PASSED\";\nstatic LPCTSTR String_VidTestFailed = \"FAILED\";\nstatic LPCTSTR String_VidSettingsOK = \"Current Settings OK\";\n\nbool __cdecl OpenGameRegistryKey(LPCTSTR key) {\n\tif( key == NULL )\n\t\treturn OpenRegistryKey(REG_TR2_PATH);\n\n\tchar buf[256];\n\twsprintf(buf, \"%s\\\\%s\", REG_TR2_PATH, key);\n\treturn OpenRegistryKey(buf);\n}\n\nLONG __cdecl CloseGameRegistryKey() {\n  return CloseRegistryKey();\n}\n\nbool __cdecl SE_WriteAppSettings(APP_SETTINGS *settings) {\n\tLPCTSTR guidString;\n\n\tif( !OpenGameRegistryKey(REG_SYSTEM_KEY) )\n\t\treturn false;\n\n\tif( settings->PreferredDisplayAdapter != NULL && settings->PreferredDisplayAdapter != PrimaryDisplayAdapter ) {\n\t\tguidString = GuidBinaryToString(&settings->PreferredDisplayAdapter->body.adapterGuid);\n\t\tSetRegistryStringValue(REG_DISPLAY_ADAPTER, guidString, GUID_STRING_SIZE-1);\n\t} else {\n\t\tDeleteRegistryValue(REG_DISPLAY_ADAPTER);\n\t}\n\n\tif( settings->PreferredSoundAdapter != NULL && settings->PreferredSoundAdapter != PrimarySoundAdapter ) {\n\t\tguidString = GuidBinaryToString(&settings->PreferredSoundAdapter->body.adapterGuid);\n\t\tSetRegistryStringValue(REG_SOUND_ADAPTER, guidString, GUID_STRING_SIZE-1);\n\t} else {\n\t\tDeleteRegistryValue(REG_SOUND_ADAPTER);\n\t}\n\n\tif( settings->PreferredJoystick != NULL ) {\n\t\tguidString = GuidBinaryToString(&settings->PreferredJoystick->body.joystickGuid);\n\t\tSetRegistryStringValue(REG_JOYSTICK, guidString, GUID_STRING_SIZE-1);\n\t} else {\n\t\tDeleteRegistryValue(REG_JOYSTICK);\n\t}\n\n\tSetRegistryDwordValue(REG_RENDERER, settings->RenderMode);\n\n\tif( settings->PreferredDisplayAdapter != NULL && settings->VideoMode != NULL ) {\n\t\tSetRegistryDwordValue(REG_FS_WIDTH,\t\tsettings->VideoMode->body.width);\n\t\tSetRegistryDwordValue(REG_FS_HEIGHT,\tsettings->VideoMode->body.height);\n\t\tSetRegistryDwordValue(REG_FS_BPP,\t\tsettings->VideoMode->body.bpp);\n\t} else {\n\t\tDeleteRegistryValue(REG_FS_WIDTH);\n\t\tDeleteRegistryValue(REG_FS_HEIGHT);\n\t\tDeleteRegistryValue(REG_FS_BPP);\n\t}\n\n\tSetRegistryDwordValue(REG_WIN_WIDTH,\t\tsettings->WindowWidth);\n\tSetRegistryDwordValue(REG_WIN_HEIGHT,\t\tsettings->WindowHeight);\n\tSetRegistryDwordValue(REG_WIN_ASPECT,\t\tsettings->AspectMode);\n\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\tSetRegistryDwordValue(REG_ADJUST_MODE,\t\tsettings->TexelAdjustMode);\n\tSetRegistryDwordValue(REG_ADJUST_NEAREST,\tsettings->NearestAdjustment);\n\tSetRegistryDwordValue(REG_ADJUST_LINEAR,\tsettings->LinearAdjustment);\n\n\tSetRegistryBoolValue(REG_PERSPECTIVE,\t\tsettings->PerspectiveCorrect);\n\tSetRegistryBoolValue(REG_DITHER,\t\t\tsettings->Dither);\n\tSetRegistryBoolValue(REG_TRIPLEBUFFER,\t\tsettings->TripleBuffering);\n\tSetRegistryBoolValue(REG_16BIT_DISABLE,\t\tsettings->Disable16BitTextures);\n\tSetRegistryBoolValue(REG_SORT_DISABLE,\t\tsettings->DontSortPrimitives);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\tSetRegistryBoolValue(REG_ZBUFFER,\t\t\tsettings->ZBuffer);\n\tSetRegistryBoolValue(REG_BILINEAR,\t\t\tsettings->BilinearFiltering);\n\tSetRegistryBoolValue(REG_FULLSCREEN,\t\tsettings->FullScreen);\n\tSetRegistryBoolValue(REG_SOUND_ENABLE,\t\tsettings->SoundEnabled);\n\tSetRegistryBoolValue(REG_LARA_MIC,\t\t\tsettings->LaraMic);\n\tSetRegistryBoolValue(REG_JOY_ENABLE,\t\tsettings->JoystickEnabled);\n\tSetRegistryBoolValue(REG_FMV_DISABLE,\t\tsettings->DisableFMV);\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tSetRegistryDwordValue(REG_LIGHTING_MODE,\tsettings->LightingMode);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tCloseGameRegistryKey();\n\treturn true;\n}\n\nint __cdecl SE_ReadAppSettings(APP_SETTINGS *settings) {\n\tbool rc;\n\tGUID guid;\n\tDISPLAY_MODE targetMode;\n\tDISPLAY_MODE_LIST *modeList;\n\tDISPLAY_MODE_NODE *mode;\n\n\tif( !OpenGameRegistryKey(REG_SYSTEM_KEY) )\n\t\treturn 0;\n\n\trc = GetRegistryGuidValue(REG_DISPLAY_ADAPTER, &guid, NULL);\n\tsettings->PreferredDisplayAdapter = WinVidGetDisplayAdapter(rc ? &guid : NULL);\n\n\trc = GetRegistryGuidValue(REG_SOUND_ADAPTER, &guid, NULL);\n\tsettings->PreferredSoundAdapter = GetSoundAdapter(rc ? &guid : NULL);\n\n\trc = GetRegistryGuidValue(REG_JOYSTICK, &guid, NULL);\n\tsettings->PreferredJoystick = GetJoystick(rc ? &guid : NULL);\n\n\tGetRegistryDwordValue(REG_RENDERER, (DWORD *)&settings->RenderMode, RM_Hardware);\n\tif( settings->RenderMode < RM_Software || settings->RenderMode > RM_Hardware )\n\t\tsettings->RenderMode = RM_Hardware;\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tGetRegistryDwordValue(REG_FS_WIDTH,\t\t(DWORD *)&targetMode.width,\t\t1920);\n\tGetRegistryDwordValue(REG_FS_HEIGHT,\t(DWORD *)&targetMode.height,\t1080);\n\tGetRegistryDwordValue(REG_FS_BPP,\t\t(DWORD *)&targetMode.bpp,\t\t32);\n#else // FEATURE_NOLEGACY_OPTIONS\n\tGetRegistryDwordValue(REG_FS_WIDTH,\t\t(DWORD *)&targetMode.width,\t\t640);\n\tGetRegistryDwordValue(REG_FS_HEIGHT,\t(DWORD *)&targetMode.height,\t480);\n\tGetRegistryDwordValue(REG_FS_BPP,\t\t(DWORD *)&targetMode.bpp,\t\t16);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\ttargetMode.vga = VGA_NoVga;\n\tif( settings->RenderMode == RM_Software )\n\t\ttargetMode.bpp = 8;\n\n\tif( settings->RenderMode == RM_Hardware )\n\t\tmodeList = &settings->PreferredDisplayAdapter->body.hwDispModeList;\n\telse\n\t\tmodeList = &settings->PreferredDisplayAdapter->body.swDispModeList;\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tif( modeList->head ) {\n\t\ttargetMode.bpp = modeList->head->body.bpp;\n\t\ttargetMode.vga = modeList->head->body.vga;\n\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\tfor( mode = modeList->head; mode; mode = mode->next ) {\n\t\tif( !CompareVideoModes(&mode->body, &targetMode) )\n\t\t\tbreak;\n\t}\n\tsettings->VideoMode = mode ? mode : modeList->tail;\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tGetRegistryDwordValue(REG_WIN_WIDTH,\t(DWORD *)&settings->WindowWidth,\t1024);\n\tGetRegistryDwordValue(REG_WIN_HEIGHT,\t(DWORD *)&settings->WindowHeight,\t768);\n\tGetRegistryDwordValue(REG_WIN_ASPECT,\t(DWORD *)&settings->AspectMode,\t\tAM_Any);\n#else // FEATURE_NOLEGACY_OPTIONS\n\tGetRegistryDwordValue(REG_WIN_WIDTH,\t(DWORD *)&settings->WindowWidth,\t512);\n\tGetRegistryDwordValue(REG_WIN_HEIGHT,\t(DWORD *)&settings->WindowHeight,\t384);\n\tGetRegistryDwordValue(REG_WIN_ASPECT,\t(DWORD *)&settings->AspectMode,\t\tAM_4_3);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\tif( settings->AspectMode < AM_4_3 || settings->AspectMode > AM_Any )\n\t\tsettings->AspectMode = AM_4_3;\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tsettings->TexelAdjustMode = TAM_BilinearOnly;\n\tsettings->NearestAdjustment = 1;\n\tsettings->LinearAdjustment = 128;\n\tsettings->PerspectiveCorrect = true;\n\tsettings->Dither = true;\n\tsettings->TripleBuffering = false;\n\tsettings->Disable16BitTextures = false;\n\tsettings->DontSortPrimitives = false;\n\tsettings->FlipBroken = false;\n#else // FEATURE_NOLEGACY_OPTIONS\n\tGetRegistryDwordValue(REG_ADJUST_MODE,\t\t(DWORD *)&settings->TexelAdjustMode,\tTAM_Always);\n\tGetRegistryDwordValue(REG_ADJUST_NEAREST,\t(DWORD *)&settings->NearestAdjustment,\t16);\n\tGetRegistryDwordValue(REG_ADJUST_LINEAR,\t(DWORD *)&settings->LinearAdjustment,\t128);\n\n\tif( settings->TexelAdjustMode < TAM_Disabled || settings->TexelAdjustMode > TAM_Always )\n\t\tsettings->TexelAdjustMode = TAM_Always;\n\n\tCLAMP(settings->NearestAdjustment, 0, 256);\n\tCLAMP(settings->LinearAdjustment, 0, 256);\n\n\tGetRegistryBoolValue(REG_PERSPECTIVE,\t&settings->PerspectiveCorrect,\t\tsettings->RenderMode == RM_Hardware);\n\tGetRegistryBoolValue(REG_DITHER,\t\t&settings->Dither,\t\t\t\t\tfalse);\n\tGetRegistryBoolValue(REG_TRIPLEBUFFER,\t&settings->TripleBuffering,\t\t\tfalse);\n\tGetRegistryBoolValue(REG_16BIT_DISABLE,\t&settings->Disable16BitTextures,\tfalse);\n\tGetRegistryBoolValue(REG_SORT_DISABLE,\t&settings->DontSortPrimitives,\t\tfalse);\n\tGetRegistryBoolValue(REG_FLIP_BROKEN,\t&settings->FlipBroken,\t\t\t\tfalse);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\tGetRegistryBoolValue(REG_ZBUFFER,\t\t&settings->ZBuffer,\t\t\t\t\ttrue);\n\tGetRegistryBoolValue(REG_BILINEAR,\t\t&settings->BilinearFiltering,\t\ttrue);\n\tGetRegistryBoolValue(REG_FULLSCREEN,\t&settings->FullScreen,\t\t\t\ttrue);\n\tGetRegistryBoolValue(REG_SOUND_ENABLE,\t&settings->SoundEnabled,\t\t\ttrue);\n\tGetRegistryBoolValue(REG_LARA_MIC,\t\t&settings->LaraMic,\t\t\t\t\tfalse);\n\tGetRegistryBoolValue(REG_JOY_ENABLE,\t&settings->JoystickEnabled,\t\t\ttrue);\n\tGetRegistryBoolValue(REG_FMV_DISABLE,\t&settings->DisableFMV,\t\t\t\tfalse);\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tGetRegistryDwordValue(REG_LIGHTING_MODE, (DWORD *)&settings->LightingMode, true);\n\tCLAMPG(settings->LightingMode, 2);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n\tCloseGameRegistryKey();\n\treturn IsNewRegistryKeyCreated() ? 2 : 1;\n}\n\nbool __cdecl SE_GraphicsTestStart() {\n\ttry {\n\t\tWinVidStart();\n\t\tRenderStart(true);\n\t} catch(int error) {\n\t\tLPCTSTR errorString = DecodeErrorMessage(error);\n\t\t// 'Test Result' Static\n\t\tSetDlgItemText(GraphicsDialogHandle, ID_GRAPH_STATIC_TESTRESULT, String_VidTestFailed);\n\t\t// 'Test Result Details' Static\n\t\tSetDlgItemText(GraphicsDialogHandle, ID_GRAPH_STATIC_TESTDETAIL, errorString);\n\t\treturn false;\n\t}\n\t// 'Test Result' Static\n\tSetDlgItemText(GraphicsDialogHandle, ID_GRAPH_STATIC_TESTRESULT, String_VidTestPassed);\n\t// 'Test Result Details' Static\n\tSetDlgItemText(GraphicsDialogHandle, ID_GRAPH_STATIC_TESTDETAIL, String_VidSettingsOK);\n\treturn true;\n}\n\nvoid __cdecl SE_GraphicsTestFinish() {\n\tRenderFinish(true);\n\tWinVidFinish();\n\tWinVidHideGameWindow();\n}\n\nint __cdecl SE_GraphicsTestExecute() {\n\treturn 0;\n}\n\nint __cdecl SE_GraphicsTest() {\n\tint result = 0;\n\tAPP_SETTINGS backupAppSettings = SavedAppSettings;\n\n\tif( SE_GraphicsTestStart() )\n\t\tresult = SE_GraphicsTestExecute();\n\n\tSE_GraphicsTestFinish();\n\tSavedAppSettings = backupAppSettings;\n\treturn result;\n}\n\nvoid __cdecl SE_DefaultGraphicsSettings() {\n\tDISPLAY_ADAPTER_NODE *adapter, *swAdapter, *hwAdapter;\n\tDISPLAY_MODE_LIST *modeList;\n\tDISPLAY_MODE_NODE *mode;\n\tDISPLAY_MODE targetMode;\n\n\thwAdapter = NULL;\n\tswAdapter = NULL;\n\n\tfor( adapter = DisplayAdapterList.head; adapter; adapter = adapter->next ) {\n\t\tif( adapter->body.lpAdapterGuid == NULL )\n\t\t\tswAdapter = adapter;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\thwAdapter = adapter;\n\t\t\tChangedAppSettings.ZBuffer = true;\n\t\t\tChangedAppSettings.BilinearFiltering = true;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tif( adapter->body.hwRenderSupported && (hwAdapter == NULL || adapter != swAdapter) )\n\t\t{\n\t\t\thwAdapter = adapter;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\tChangedAppSettings.PerspectiveCorrect = adapter->body.perspectiveCorrectSupported;\n\t\t\tChangedAppSettings.Dither = adapter->body.ditherSupported;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\tChangedAppSettings.ZBuffer = adapter->body.zBufferSupported;\n\t\t\tChangedAppSettings.BilinearFiltering = adapter->body.linearFilterSupported;\n\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n\n\tif( hwAdapter != NULL ) {\n\t\tChangedAppSettings.PreferredDisplayAdapter = hwAdapter;\n\t\tChangedAppSettings.RenderMode = RM_Hardware;\n\t} else {\n\t\tChangedAppSettings.PreferredDisplayAdapter = swAdapter;\n\t\tChangedAppSettings.RenderMode = RM_Software;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\tChangedAppSettings.PerspectiveCorrect = true;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t}\n\n\tChangedAppSettings.FullScreen = true;\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tChangedAppSettings.AspectMode = AM_Any;\n\tChangedAppSettings.WindowWidth = 1024;\n\tChangedAppSettings.WindowHeight = 768;\n#else // FEATURE_NOLEGACY_OPTIONS\n\tChangedAppSettings.WindowWidth = 512;\n\tChangedAppSettings.WindowHeight = 384;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\tif( ChangedAppSettings.PreferredDisplayAdapter == NULL )\n\t\treturn;\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\ttargetMode.width = 1920;\n\ttargetMode.height = 1080;\n\ttargetMode.bpp = 32;\n#else // FEATURE_NOLEGACY_OPTIONS\n\ttargetMode.width = 640;\n\ttargetMode.height = 480;\n\ttargetMode.bpp = 16;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\ttargetMode.vga = VGA_NoVga;\n\n\tif( ChangedAppSettings.RenderMode == RM_Hardware )\n\t\tmodeList = &ChangedAppSettings.PreferredDisplayAdapter->body.hwDispModeList;\n\telse\n\t\tmodeList = &ChangedAppSettings.PreferredDisplayAdapter->body.swDispModeList;\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tif( modeList->head ) {\n\t\ttargetMode.bpp = modeList->head->body.bpp;\n\t\ttargetMode.vga = modeList->head->body.vga;\n\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\tfor( mode = modeList->head; mode; mode = mode->next ) {\n\t\tif( !CompareVideoModes(&mode->body, &targetMode) )\n\t\t\tbreak;\n\t}\n\tChangedAppSettings.VideoMode = mode ? mode : modeList->tail;\n}\n\nbool __cdecl SE_SoundTestStart() {\n\tBYTE *waveFile;\n\tWAVEFORMATEX format;\n\tDWORD dataSize;\n\tLPVOID data;\n\ttry {\n\t\tWinSndStart(SoundDialogHandle);\n\t} catch(...) {\n\t\treturn false;\n\t}\n\twaveFile = (BYTE *)UT_LoadResource(MAKEINTRESOURCE(IDR_WAVESAMPLE), \"WAVE\");\n\tformat = *(WAVEFORMATEX *)&waveFile[0x14];\n\tformat.cbSize = 0;\n\tdataSize = *(DWORD *)&waveFile[0x28];\n\tdata = &waveFile[0x2C];\n\n\treturn WinSndMakeSample(0, &format, data, dataSize);\n}\n\nvoid __cdecl SE_SoundTestFinish() {\n\tWinSndFinish();\n}\n\nint __cdecl SE_SoundTestExecute() {\n\tint channel = WinSndPlaySample(0, VOLUME_PCT(90), PHD_ONE, DSBPAN_CENTER, 0);\n\n\tif( channel >= 0 )\n\t\twhile( WinSndIsChannelPlaying(channel) ) /* just wait */;\n\n\treturn 0;\n}\n\nint __cdecl SE_SoundTest() {\n\tint result = 0;\n\n\tAPP_SETTINGS backupAppSettings = SavedAppSettings;\n\tSavedAppSettings = ChangedAppSettings;\n\n\tif( SE_SoundTestStart() )\n\t\tresult = SE_SoundTestExecute();\n\n\tSE_SoundTestFinish();\n\tSavedAppSettings = backupAppSettings;\n\treturn result;\n}\n\nint CALLBACK SE_PropSheetCallback(HWND hwndDlg, UINT uMsg, LPARAM lParam) {\n\tswitch( uMsg ) {\n\t\tcase PSCB_PRECREATE :\n\t\t\tGraphicsDialogHandle = NULL;\n\t\t\tbreak;\n\n\t\tcase PSCB_INITIALIZED :\n\t\t\tSE_PropSheetWndHandle = hwndDlg;\n\t\t\tSE_OldPropSheetWndProc = (WNDPROC)SetWindowLong(hwndDlg, GWL_WNDPROC, (LONG)SE_NewPropSheetWndProc);\n\t\t\tbreak;\n\t}\n\treturn 0;\n}\n\nLRESULT CALLBACK SE_NewPropSheetWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {\n\tswitch( uMsg ) {\n\t\tcase WM_DESTROY :\n\t\t\tSetWindowLong(hWnd, GWL_WNDPROC, (LONG)SE_OldPropSheetWndProc);\n\t\t\tbreak;\n\n\t\tcase WM_DISPLAYCHANGE :\n\t\t\tif( GraphicsDialogHandle != NULL )\n\t\t\t\tPostMessage(GraphicsDialogHandle, uMsg, wParam, lParam);\n\t\t\tbreak;\n\t}\n\treturn CallWindowProc(SE_OldPropSheetWndProc, hWnd, uMsg, wParam, lParam);\n}\n\nbool __cdecl SE_ShowSetupDialog(HWND hParent, bool isDefault) {\n\tstatic bool initOnce = false;\n\tPROPSHEETHEADER sheetHeader;\n\tPROPSHEETPAGE sheetPages[5];\n\n\tChangedAppSettings = SavedAppSettings;\n\tif( isDefault ) {\n\t\tSE_DefaultGraphicsSettings();\n\t\tChangedAppSettings.SoundEnabled = true;\n\t}\n\n\tmemset(sheetPages, 0, sizeof(sheetPages));\n\tmemset(&sheetHeader, 0, sizeof(sheetHeader));\n\tfor( int i=0; i<5; ++i ) {\n\t\tsheetPages[i].dwSize = sizeof(PROPSHEETPAGE);\n\t\tsheetPages[i].dwFlags = PSP_DEFAULT;\n\t\tsheetPages[i].hInstance = GameModule;\n\t}\n\n\tsheetPages[0].pszTemplate = MAKEINTRESOURCE(IDD_OPTIONS); // 'Options' Tab\n\tsheetPages[0].pfnDlgProc = SE_OptionsDlgProc;\n\tsheetPages[1].pszTemplate = MAKEINTRESOURCE(IDD_GRAPHICS); // 'Graphics' Tab\n\tsheetPages[1].pfnDlgProc = SE_GraphicsDlgProc;\n\tsheetPages[2].pszTemplate = MAKEINTRESOURCE(IDD_SOUND); // 'Sound' Tab\n\tsheetPages[2].pfnDlgProc = SE_SoundDlgProc;\n\tsheetPages[3].pszTemplate = MAKEINTRESOURCE(IDD_CONTROLS); // 'Controls' Tab\n\tsheetPages[3].pfnDlgProc = SE_ControlsDlgProc;\n\tsheetPages[4].pszTemplate = MAKEINTRESOURCE(IDD_ADVANCED); // 'Advanced' Tab\n\tsheetPages[4].pfnDlgProc = SE_AdvancedDlgProc;\n\n\tsheetHeader.dwSize = sizeof(PROPSHEETHEADER);\n\tsheetHeader.dwFlags = PSH_USECALLBACK|PSH_NOAPPLYNOW|PSH_PROPSHEETPAGE|PSH_USEHICON;\n\tsheetHeader.hwndParent = hParent;\n\tsheetHeader.hInstance = GameModule;\n\tsheetHeader.hIcon = (HICON)LoadImage(GameModule, MAKEINTRESOURCE(IDI_MAINICON), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);\n\tsheetHeader.pszCaption = GameDialogName;\n\tsheetHeader.nPages = 5;\n\tsheetHeader.nStartPage = 1;\n\tsheetHeader.ppsp = sheetPages;\n\tsheetHeader.pfnCallback = SE_PropSheetCallback;\n\n\tif( !initOnce ) {\n\t\tInitCommonControls();\n\t\tSE_RegisterSetupWindowClass();\n\t\tinitOnce = true;\n\t}\n\tIsSetupDialogCentered = false;\n\n\tif( PropertySheet(&sheetHeader) != 1 )\n\t\treturn false;\n\n\tSavedAppSettings = ChangedAppSettings;\n\treturn true;\n}\n\nINT_PTR CALLBACK SE_GraphicsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {\n\tstatic bool isGraphicsTest = false;\n\n\tswitch( uMsg ) {\n\t\tcase WM_INITDIALOG :\n\t\t\tGraphicsDialogHandle = hwndDlg;\n\t\t\tisGraphicsTest = false;\n\t\t\tif( !IsSetupDialogCentered ) {\n\t\t\t\tUT_CenterWindow(GetParent(hwndDlg));\n\t\t\t\tIsSetupDialogCentered = true;\n\t\t\t}\n\t\t\tSE_GraphicsDlgInit(hwndDlg);\n\t\t\treturn 1;\n\n\t\tcase WM_DESTROY :\n\t\t\tGraphicsDialogHandle = NULL;\n\t\t\tbreak;\n\n\t\tcase WM_DISPLAYCHANGE :\n\t\t\tif( !isGraphicsTest ) {\n\t\t\t\tif( SE_DisplayAdapter != NULL )\n\t\t\t\t\tWinVidSetDisplayAdapter(&SE_DisplayAdapter->body);\n\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase WM_HSCROLL :\n\t\t\tif( (HWND)lParam == GetDlgItem(hwndDlg, ID_GRAPH_SLIDER_WINDOWED) ) { // 'Windowed Mode' Slider\n\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase WM_COMMAND :\n\t\t\tif( HIWORD(wParam) == 0 ) { // Buttons\n\t\t\t\tbool isCheck = ( 1 == SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) );\n\t\t\t\tswitch( LOWORD(wParam) ) {\n\t\t\t\t\tcase ID_GRAPH_BUTTON_SWRENDER : // 'Software 256 Colour Renderer' RadioButton\n\t\t\t\t\t\tChangedAppSettings.RenderMode = RM_Software;\n\t\t\t\t\t\tSE_GraphicsDlgFullScreenModesUpdate(hwndDlg);\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_HWRENDER : // 'Hardware 3D Acceleration' RadioButton\n\t\t\t\t\t\tChangedAppSettings.RenderMode = RM_Hardware;\n\t\t\t\t\t\tSE_GraphicsDlgFullScreenModesUpdate(hwndDlg);\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\tcase ID_GRAPH_BUTTON_PERSPECTIVE : // 'Perspective Correct' CheckBox\n\t\t\t\t\t\tChangedAppSettings.PerspectiveCorrect = isCheck;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_DITHER : // 'Dither' CheckBox\n\t\t\t\t\t\tChangedAppSettings.Dither = isCheck;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\tcase ID_GRAPH_BUTTON_ZBUFFER : // 'Z Buffer' CheckBox\n\t\t\t\t\t\tChangedAppSettings.ZBuffer = isCheck;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_BILINEAR : // 'Bilinear Filter' CheckBox\n\t\t\t\t\t\tChangedAppSettings.BilinearFiltering = isCheck;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\tcase ID_GRAPH_BUTTON_TRIPLEBUFFER : // 'Triple Buffer' CheckBox\n\t\t\t\t\t\tChangedAppSettings.TripleBuffering = isCheck;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\tcase ID_GRAPH_BUTTON_FULLSCREEN : // 'Full Screen' RadioButton\n\t\t\t\t\t\tChangedAppSettings.FullScreen = true;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_WINDOWED : // 'Windowed' RadioButton\n\t\t\t\t\t\tChangedAppSettings.FullScreen = false;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_TEST : // 'Test' Button\n\t\t\t\t\t\tisGraphicsTest = true;\n\t\t\t\t\t\tif( 0 != SE_GraphicsTest() ) {\n\t\t\t\t\t\t\t// test fatal error - close Setup Dialog (this never happens though)\n\t\t\t\t\t\t\tPostMessage(SE_PropSheetWndHandle, PSM_PRESSBUTTON, PSBTN_CANCEL, 0);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisGraphicsTest = false;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_ASPECT_4_3 : // '4:3' RadioButton\n\t\t\t\t\t\tChangedAppSettings.AspectMode = AM_4_3;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_ASPECT_16_9 : // '16:9' RadioButton\n\t\t\t\t\t\tChangedAppSettings.AspectMode = AM_16_9;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_ASPECT_ANY : // 'Any' RadioButton\n\t\t\t\t\t\tChangedAppSettings.AspectMode = AM_Any;\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_BUTTON_DEFAULT : // 'Use Defaults' Button\n\t\t\t\t\t\tSE_DefaultGraphicsSettings();\n\t\t\t\t\t\tSE_GraphicsDlgInit(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else if( HIWORD(wParam) == 1 ) { // ComboBoxes\n\t\t\t\tDWORD selectedIndex = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0);\n\t\t\t\tDISPLAY_MODE_NODE *selected = (DISPLAY_MODE_NODE *)SendMessage((HWND)lParam, CB_GETITEMDATA, selectedIndex, 0);\n\t\t\t\tswitch( LOWORD(wParam) ) {\n\t\t\t\t\tcase ID_GRAPH_COMBOBOX_ADAPTER : // 'Graphics Card' ComboBox\n\t\t\t\t\t\tSE_GraphicsAdapterSet(hwndDlg, (DISPLAY_ADAPTER_NODE *)selected);\n\t\t\t\t\t\tSE_GraphicsDlgUpdate(hwndDlg);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_GRAPH_COMBOBOX_FULLSCREEN : // 'Full Screen Mode' ComboBox\n\t\t\t\t\t\tChangedAppSettings.VideoMode = selected;\n\t\t\t\t\t\tSE_FullScreenMode = selected->body;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t}\n\treturn 0;\n}\n\nvoid __cdecl SE_GraphicsDlgFullScreenModesUpdate(HWND hwndDlg) {\n\tHWND comboBox;\n\tDWORD addedIndex, selectedIndex;\n\tDISPLAY_MODE_LIST *modeList;\n\tDISPLAY_MODE_NODE *mode, *selected;\n\tchar stringBuf[256];\n\n\tcomboBox = GetDlgItem(hwndDlg, ID_GRAPH_COMBOBOX_FULLSCREEN); // 'Full Screen Mode' ComboBox\n\tSendMessage(comboBox, CB_RESETCONTENT, 0, 0);\n\n\tif( ChangedAppSettings.RenderMode == RM_Hardware ) {\n\t\tmodeList = &ChangedAppSettings.PreferredDisplayAdapter->body.hwDispModeList;\n\t} else {\n\t\tmodeList = &ChangedAppSettings.PreferredDisplayAdapter->body.swDispModeList;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tSE_FullScreenMode.bpp = 32;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tSE_FullScreenMode.bpp = 8;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t}\n\tSE_FullScreenMode.vga = VGA_NoVga;\n\n\tif( modeList->dwCount == 0 || modeList->head == NULL ) {\n\t\tEnableWindow(comboBox, FALSE);\n\t\treturn;\n\t}\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tif( modeList->head ) {\n\t\tSE_FullScreenMode.bpp = modeList->head->body.bpp;\n\t\tSE_FullScreenMode.vga = modeList->head->body.vga;\n\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\tfor( mode = modeList->head; mode; mode = mode->next ) {\n\t\tif( !CompareVideoModes(&mode->body, &SE_FullScreenMode) )\n\t\t\tbreak;\n\t}\n\tselected = mode ? mode : modeList->tail;\n\n\tselectedIndex = 0;\n\tfor( mode = modeList->head; mode; mode = mode->next ) {\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\twsprintf(stringBuf, \"%dx%d\", mode->body.width, mode->body.height);\n#else // FEATURE_NOLEGACY_OPTIONS\n\t\tLPCTSTR lpColorString = \"\";\n\t\tswitch( mode->body.vga ) {\n\t\t\tcase VGA_NoVga :\n\t\t\t\tswitch( mode->body.bpp ) {\n\t\t\t\t\tcase 16:\n\t\t\t\t\t\tlpColorString = String_HighColor;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 24:\n\t\t\t\t\tcase 32:\n\t\t\t\t\t\tlpColorString = String_TrueColor;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase VGA_256Color :\n\t\t\t\tlpColorString = String_256Color;\n\t\t\t\tbreak;\n\t\t\tcase VGA_ModeX :\n\t\t\t\tlpColorString = String_ModeX;\n\t\t\t\tbreak;\n\t\t\tcase VGA_Standard :\n\t\t\t\tlpColorString = String_StandardVga;\n\t\t\t\tbreak;\n\t\t}\n\t\twsprintf(stringBuf, \"%dx%d %s\", mode->body.width, mode->body.height, lpColorString);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\taddedIndex = SendMessage(comboBox, CB_ADDSTRING, 0, (LPARAM)stringBuf);\n\t\tSendMessage(comboBox, CB_SETITEMDATA, addedIndex, (LPARAM)mode);\n\t\tif( mode == selected )\n\t\t\tselectedIndex = addedIndex;\n\t}\n\n\tSendMessage(comboBox, CB_SETCURSEL, selectedIndex, 0);\n\tselected = (DISPLAY_MODE_NODE *)SendMessage(comboBox, CB_GETITEMDATA, selectedIndex, 0);\n\tChangedAppSettings.VideoMode = selected;\n\n\tif( selected != NULL )\n\t\tSE_FullScreenMode = selected->body;\n\n\tEnableWindow(comboBox, (modeList->dwCount > 1));\n}\n\nvoid __cdecl SE_GraphicsAdapterSet(HWND hwndDlg, DISPLAY_ADAPTER_NODE *adapter) {\n\tChangedAppSettings.PreferredDisplayAdapter = adapter;\n\tSE_GraphicsDlgFullScreenModesUpdate(hwndDlg);\n}\n\nvoid __cdecl SE_GraphicsDlgUpdate(HWND hwndDlg) {\n\tHWND hItem;\n\tchar stringWindowRes[16];\n\tbool renderAvailable;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\tbool perspectiveCorrectAvailable;\n\tbool ditherAvailable;\n\tbool tripleBufferingAvailable;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\tbool zBufferAvailable;\n\tbool bilinearFilteringAvailable;\n\tbool windowedSizeAvailable;\n\tbool windowedModeAvailable;\n\tbool fullScreenModeAvailable;\n\tbool fullScreenModeListAvailable;\n\tbool windowedModeListAvailable;\n\tDWORD fullScreenVideoModesCount;\n\tDISPLAY_ADAPTER *preferred = &ChangedAppSettings.PreferredDisplayAdapter->body;\n#if (DIRECT3D_VERSION >= 0x900)\n\tbool isSWSupported = true;\n\tbool isHWSupported = true;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tbool isSWSupported = ( preferred->swDispModeList.dwCount > 0 || preferred->swWindowedSupported );\n\tbool isHWSupported = ( preferred->hwDispModeList.dwCount > 0 || preferred->hwWindowedSupported );\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tif( (ChangedAppSettings.RenderMode == RM_Software && !isSWSupported) ||\n\t\t(ChangedAppSettings.RenderMode == RM_Hardware && !isHWSupported) )\n\t{\n\t\tChangedAppSettings.RenderMode = RM_Unknown;\n\t}\n\n\tif( ChangedAppSettings.RenderMode == RM_Unknown ) {\n\t\tif( isHWSupported ) {\n\t\t\tChangedAppSettings.RenderMode = RM_Hardware;\n\t\t} else if( isSWSupported ) {\n\t\t\tChangedAppSettings.RenderMode = RM_Software;\n\t\t}\n\t\tSE_GraphicsDlgFullScreenModesUpdate(hwndDlg);\n\t}\n\n\tif( ChangedAppSettings.RenderMode == RM_Software ) {\n\t\t// Software Renderer\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\tperspectiveCorrectAvailable = true;\n\t\tditherAvailable = false;\n\t\ttripleBufferingAvailable = true;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\tzBufferAvailable = false;\n\t\tbilinearFilteringAvailable = false;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\twindowedModeAvailable = true;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\twindowedModeAvailable = preferred->swWindowedSupported;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tfullScreenModeAvailable = ( preferred->swDispModeList.dwCount > 0 );\n\t\tfullScreenVideoModesCount = preferred->swDispModeList.dwCount;\n\t} else if( ChangedAppSettings.RenderMode == RM_Hardware ) {\n\t\t// Hardware Renderer\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\tperspectiveCorrectAvailable = preferred->perspectiveCorrectSupported;\n\t\tditherAvailable = preferred->ditherSupported;\n\t\ttripleBufferingAvailable = true;\n#endif // FEATURE_NOLEGACY_OPTIONS\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tzBufferAvailable = true;\n\t\tbilinearFilteringAvailable = true;\n\t\twindowedModeAvailable = true;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tzBufferAvailable = preferred->zBufferSupported;\n\t\tbilinearFilteringAvailable = preferred->linearFilterSupported;\n\t\twindowedModeAvailable = preferred->hwWindowedSupported;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tfullScreenModeAvailable = ( preferred->hwDispModeList.dwCount > 0 );\n\t\tfullScreenVideoModesCount = preferred->hwDispModeList.dwCount;\n\t} else {\n\t\t// Unknown Renderer\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\tperspectiveCorrectAvailable = false;\n\t\tditherAvailable = false;\n\t\ttripleBufferingAvailable = false;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\tzBufferAvailable = false;\n\t\tbilinearFilteringAvailable = false;\n\t\twindowedModeAvailable = false;\n\t\tfullScreenModeAvailable = false;\n\t\tfullScreenVideoModesCount = 0;\n\t}\n\n\tif( !windowedModeAvailable ) {\n\t\tChangedAppSettings.FullScreen = true;\n\t} else if( !fullScreenModeAvailable ) {\n\t\tChangedAppSettings.FullScreen = false;\n\t}\n\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\tif( !ChangedAppSettings.FullScreen )\n\t\ttripleBufferingAvailable = false;\n\tif( !perspectiveCorrectAvailable )\n\t\tChangedAppSettings.PerspectiveCorrect = false;\n\tif( !ditherAvailable )\n\t\tChangedAppSettings.Dither = false;\n\tif( !tripleBufferingAvailable )\n\t\tChangedAppSettings.TripleBuffering = false;\n\tif( !zBufferAvailable )\n\t\tChangedAppSettings.ZBuffer = false;\n\tif( !bilinearFilteringAvailable )\n\t\tChangedAppSettings.BilinearFiltering = false;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\trenderAvailable = ( ChangedAppSettings.RenderMode != RM_Unknown );\n\twindowedSizeAvailable = ( preferred->screenWidth > 0 );\n\tfullScreenModeListAvailable = ( ChangedAppSettings.FullScreen && renderAvailable );\n\twindowedModeListAvailable = ( !ChangedAppSettings.FullScreen && windowedSizeAvailable );\n\n\t// 'Graphics Output Method' GroupBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_GROUPBOX_RENDER);\n\tEnableWindow(hItem, renderAvailable);\n\n\t// 'Software 256 Colour Renderer' RadioButton\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_SWRENDER);\n\tEnableWindow(hItem, isSWSupported);\n\tSendMessage(hItem, BM_SETCHECK, (ChangedAppSettings.RenderMode == RM_Software), 0);\n\n\t// 'Hardware 3D Acceleration' RadioButton\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_HWRENDER);\n\tEnableWindow(hItem, isHWSupported);\n\tSendMessage(hItem, BM_SETCHECK, (ChangedAppSettings.RenderMode == RM_Hardware), 0);\n\n\t// 'Perspective Correct' CheckBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_PERSPECTIVE);\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tShowWindow(hItem, SW_HIDE);\n#else // FEATURE_NOLEGACY_OPTIONS\n\tEnableWindow(hItem, perspectiveCorrectAvailable);\n\tSendMessage(hItem, BM_SETCHECK, ChangedAppSettings.PerspectiveCorrect, 0);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t// 'Dither' CheckBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_DITHER);\n#ifdef FEATURE_NOLEGACY_OPTIONS\n    POINT checkPos = {0, 0};\n    MapWindowPoints(hItem, hwndDlg, &checkPos, 1);\n\tShowWindow(hItem, SW_HIDE);\n#else // FEATURE_NOLEGACY_OPTIONS\n\tEnableWindow(hItem, ditherAvailable);\n\tSendMessage(hItem, BM_SETCHECK, ChangedAppSettings.Dither, 0);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t// 'Triple Buffer' CheckBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_TRIPLEBUFFER);\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tShowWindow(hItem, SW_HIDE);\n#else // FEATURE_NOLEGACY_OPTIONS\n\tEnableWindow(hItem, tripleBufferingAvailable);\n\tSendMessage(hItem, BM_SETCHECK, ChangedAppSettings.TripleBuffering, 0);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t// 'Z Buffer' CheckBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_ZBUFFER);\n\tEnableWindow(hItem, zBufferAvailable);\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tSendMessage(hItem, BM_SETCHECK, zBufferAvailable ? ChangedAppSettings.ZBuffer : 0, 0);\n#else // FEATURE_NOLEGACY_OPTIONS\n\tSendMessage(hItem, BM_SETCHECK, ChangedAppSettings.ZBuffer, 0);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t// 'Bilinear Filter' CheckBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_BILINEAR);\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tif( checkPos.x && checkPos.y ) {\n\t\tSetWindowPos(hItem, HWND_TOP, checkPos.x, checkPos.y, 0, 0, SWP_NOZORDER|SWP_NOSIZE);\n\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\tEnableWindow(hItem, bilinearFilteringAvailable);\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tSendMessage(hItem, BM_SETCHECK, bilinearFilteringAvailable ? ChangedAppSettings.BilinearFiltering : 0, 0);\n#else // FEATURE_NOLEGACY_OPTIONS\n\tSendMessage(hItem, BM_SETCHECK, ChangedAppSettings.BilinearFiltering, 0);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t// 'Display Type' GroupBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_GROUPBOX_DISPLAY);\n\tEnableWindow(hItem, (windowedModeAvailable || fullScreenModeAvailable));\n\n\t// 'Windowed' RadioButton\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_WINDOWED);\n\tEnableWindow(hItem, windowedModeAvailable);\n\tSendMessage(hItem, BM_SETCHECK, (!ChangedAppSettings.FullScreen && windowedModeAvailable), 0);\n\n\t// 'Full Screen' RadioButton\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_FULLSCREEN);\n\tEnableWindow(hItem, fullScreenModeAvailable);\n\tSendMessage(hItem, BM_SETCHECK, (ChangedAppSettings.FullScreen && fullScreenModeAvailable), 0);\n\n\t// 'Full Screen Mode' GroupBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_GROUPBOX_FULLSCREEN);\n\tEnableWindow(hItem, fullScreenModeListAvailable);\n\n\t// 'Full Screen Mode' ComboBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_COMBOBOX_FULLSCREEN);\n\tEnableWindow(hItem, (fullScreenModeListAvailable && fullScreenVideoModesCount > 1));\n\n\t// 'Windowed Mode' GroupBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_GROUPBOX_WINDOWED);\n\tEnableWindow(hItem, windowedModeListAvailable);\n\n\t// 'Small Windowed Mode' Static\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_STATIC_RES_SMALL);\n\tEnableWindow(hItem, windowedModeListAvailable);\n\n\t// 'Large Windowed Mode' Static\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_STATIC_RES_LARGE);\n\tEnableWindow(hItem, windowedModeListAvailable);\n\n\t// 'Windowed Mode Resolution' Static\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_STATIC_RESOLUTION);\n\tEnableWindow(hItem, windowedModeListAvailable);\n\n\t// '4:3 Aspect' RadioButton\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_ASPECT_4_3);\n\tEnableWindow(hItem, windowedModeListAvailable);\n\tSendMessage(hItem, BM_SETCHECK, (ChangedAppSettings.AspectMode == AM_4_3), 0);\n\n\t// '16:9 Aspect' RadioButton\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_ASPECT_16_9);\n\tEnableWindow(hItem, windowedModeListAvailable);\n\tSendMessage(hItem, BM_SETCHECK, (ChangedAppSettings.AspectMode == AM_16_9), 0);\n\n\t// 'Any Aspect' RadioButton\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_ASPECT_ANY);\n\tEnableWindow(hItem, windowedModeListAvailable);\n\tSendMessage(hItem, BM_SETCHECK, (ChangedAppSettings.AspectMode == AM_Any), 0);\n\n\t// 'Windowed Mode' Slider\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_SLIDER_WINDOWED);\n\tEnableWindow(hItem, windowedModeListAvailable);\n\tif( windowedSizeAvailable ) {\n\t\tint minPosition = 0;\n\t\tint maxWidth = preferred->screenWidth;\n\t\tint maxPosition = ((maxWidth - 320 ) / 32) & 0xFFFF;\n\n\t\tSendMessage(hItem, TBM_SETRANGE, 1, ((maxPosition<<0x10)|minPosition));\n\t\tDWORD sliderPosition = SendMessage(hItem, TBM_GETPOS, 0, 0);\n\t\tChangedAppSettings.WindowWidth = sliderPosition * 32 + 320;\n\n\t\tswitch( ChangedAppSettings.AspectMode ) {\n\t\t\tcase AM_4_3 :\n\t\t\t\tChangedAppSettings.WindowHeight = ChangedAppSettings.WindowWidth*3/4;\n\t\t\t\tbreak;\n\t\t\tcase AM_16_9 :\n\t\t\t\tChangedAppSettings.WindowHeight = ChangedAppSettings.WindowWidth*9/16;\n\t\t\t\tbreak;\n\t\t\tcase AM_Any :\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\tChangedAppSettings.WindowHeight = ChangedAppSettings.WindowWidth*3/4;\n#else // !FEATURE_NOLEGACY_OPTIONS\n\t\t\t\tChangedAppSettings.WindowHeight = ChangedAppSettings.WindowWidth;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t// 'Windowed Mode Resolution' Static\n\tif( windowedSizeAvailable )\n\t\twsprintf(stringWindowRes, \"%dx%d\", ChangedAppSettings.WindowWidth, ChangedAppSettings.WindowHeight);\n\telse\n\t\t*stringWindowRes = 0;\n\tSetDlgItemText(hwndDlg, ID_GRAPH_STATIC_RESOLUTION, stringWindowRes);\n\n\t// 'Graphics Options' GroupBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_GROUPBOX_OPTIONS);\n\tEnableWindow(hItem, renderAvailable);\n\n\t// 'Test Settings' GroupBox\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_GROUPBOX_TEST);\n\tEnableWindow(hItem, renderAvailable);\n\n\t// 'Test' Button\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_BUTTON_TEST);\n\tEnableWindow(hItem, renderAvailable);\n\n\t// 'Test Result' Static\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_STATIC_TESTRESULT);\n\tEnableWindow(hItem, renderAvailable);\n\n\t// 'Test Details' Static\n\thItem = GetDlgItem(hwndDlg, ID_GRAPH_STATIC_TESTDETAIL);\n\tEnableWindow(hItem, renderAvailable);\n}\n\nvoid __cdecl SE_GraphicsDlgInit(HWND hwndDlg) {\n\tHWND comboBox, slider;\n\tDWORD addedIndex, selectedIndex;\n\tDISPLAY_ADAPTER_NODE *adapter, *selected;\n\n\tcomboBox = GetDlgItem(hwndDlg, ID_GRAPH_COMBOBOX_ADAPTER); // 'Graphics Card' ComboBox\n\tSendMessage(comboBox, CB_RESETCONTENT, 0, 0);\n\n\tselectedIndex = 0;\n\tSE_DisplayAdapter = NULL;\n\tfor( adapter = DisplayAdapterList.head; adapter; adapter = adapter->next ) {\n\t\taddedIndex = SendMessage(comboBox, CB_ADDSTRING, 0, (LPARAM)adapter->body.driverDescription.lpString);\n\t\tSendMessage(comboBox, CB_SETITEMDATA, addedIndex, (LPARAM)adapter);\n\t\tif( adapter == ChangedAppSettings.PreferredDisplayAdapter )\n\t\t\tselectedIndex = addedIndex;\n\t\tif( adapter->body.lpAdapterGuid == NULL )\n\t\t\tSE_DisplayAdapter = adapter;\n\t\tWinVidSetDisplayAdapter(&adapter->body);\n\t}\n\n\tSendMessage(comboBox, CB_SETCURSEL, selectedIndex, 0);\n\tEnableWindow(comboBox, (DisplayAdapterList.dwCount > 1)); // NOTE: original was be >0. But there is no reason to select 1/1 adapter\n\tif( DisplayAdapterList.dwCount > 0 ) {\n\t\tselected = (DISPLAY_ADAPTER_NODE *)SendMessage(comboBox, CB_GETITEMDATA, selectedIndex, 0);\n\t\tif( ChangedAppSettings.VideoMode != NULL ) {\n\t\t\tSE_FullScreenMode = ChangedAppSettings.VideoMode->body;\n\t\t\tSE_GraphicsAdapterSet(hwndDlg, selected);\n\t\t} else {\n\t\t\tSE_FullScreenMode.width = 640;\n\t\t\tSE_FullScreenMode.height = 480;\n\t\t\tSE_FullScreenMode.bpp = 0;\n\t\t\tSE_FullScreenMode.vga = VGA_NoVga;\n\t\t\tSE_GraphicsAdapterSet(hwndDlg, selected);\n\t\t}\n\t}\n\n\tslider = GetDlgItem(hwndDlg, ID_GRAPH_SLIDER_WINDOWED); // 'Windowed Mode' Slider\n\tSendMessage(slider, TBM_SETPOS, TRUE, (ChangedAppSettings.WindowWidth - 320) / 32);\n\n\tSE_GraphicsDlgUpdate(hwndDlg);\n}\n\nINT_PTR CALLBACK SE_SoundDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {\n\tstatic HWND hImage = NULL;\n\n\tswitch( uMsg ) {\n\t\tcase WM_INITDIALOG :\n\t\t\tSoundDialogHandle = hwndDlg;\n\t\t\thImage = GetDlgItem(hwndDlg, ID_SOUND_WINDOW_IMAGE);\n\t\t\tSE_SoundDlgInit(hwndDlg);\n\t\t\treturn 1;\n\n\t\tcase WM_COMMAND :\n\t\t\tif( HIWORD(wParam) == 0 ) { // Buttons\n\t\t\t\tswitch( LOWORD(wParam) ) {\n\t\t\t\t\tcase ID_SOUND_BUTTON_SFX_ENABLE : // 'Enable Sound' CheckBox\n\t\t\t\t\t\tChangedAppSettings.SoundEnabled = (1 == SendMessage((HWND)lParam, BM_GETCHECK, 0, 0));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_SOUND_BUTTON_MIC_CAMERA : // 'Camera Microphone Position' RadioButton\n\t\t\t\t\t\tChangedAppSettings.LaraMic = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_SOUND_BUTTON_MIC_LARA : // 'Lara Microphone Position' RadioButton\n\t\t\t\t\t\tChangedAppSettings.LaraMic = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_SOUND_BUTTON_TEST : // 'Test' Button\n\t\t\t\t\t\tif( 0 != SE_SoundTest() ) {\n\t\t\t\t\t\t\t// test fatal error - close Setup Dialog (this never happens though)\n\t\t\t\t\t\t\tPostMessage(SE_PropSheetWndHandle, PSM_PRESSBUTTON, PSBTN_CANCEL, 0);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tSendMessage((HWND)lParam, BM_SETCHECK, 0, 0);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else if( HIWORD(wParam) == 1 ) { // ComboBoxes\n\t\t\t\tif( LOWORD(wParam) == ID_SOUND_COMBOBOX_ADAPTER ) { // 'Sound Card' ComboBox\n\t\t\t\t\tDWORD index = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0);\n\t\t\t\t\tSOUND_ADAPTER_NODE *adapter = (SOUND_ADAPTER_NODE *)SendMessage((HWND)lParam, CB_GETITEMDATA, index, 0);\n\t\t\t\t\tSE_SoundAdapterSet(hwndDlg, adapter);\n\t\t\t\t\tSE_SoundDlgUpdate(hwndDlg);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t}\n\tSE_PassMessageToImage(hImage, uMsg, wParam);\n\treturn 0;\n}\n\nvoid __cdecl SE_SoundAdapterSet(HWND hwndDlg, SOUND_ADAPTER_NODE *adapter) {\n\tChangedAppSettings.PreferredSoundAdapter = adapter;\n}\n\nvoid __cdecl SE_SoundDlgUpdate(HWND hwndDlg) {\n\tHWND hItem;\n\tbool isAvailable = ( SoundAdapterList.dwCount > 0 );\n\n\t// 'Microphone Position' GroupBox\n\thItem = GetDlgItem(hwndDlg, ID_SOUND_GROUPBOX_MIC);\n\tEnableWindow(hItem, isAvailable);\n\n\t// 'Sound Output' GroupBox\n\thItem = (HWND)GetDlgItem(hwndDlg, ID_SOUND_GROUPBOX_OUTPUT);\n\tEnableWindow(hItem, isAvailable);\n\n\t// 'Enable Sound' CheckBox\n\thItem = (HWND)GetDlgItem(hwndDlg, ID_SOUND_BUTTON_SFX_ENABLE);\n\tEnableWindow(hItem, isAvailable);\n\tSendMessage(hItem, BM_SETCHECK, (isAvailable && ChangedAppSettings.SoundEnabled), 0);\n\n\t// 'Camera' RadioButton\n\thItem = (HWND)GetDlgItem(hwndDlg, ID_SOUND_BUTTON_MIC_CAMERA);\n\tEnableWindow(hItem, isAvailable);\n\tSendMessage(hItem, BM_SETCHECK, !ChangedAppSettings.LaraMic, 0);\n\n\t// 'Lara' RadioButton\n\thItem = (HWND)GetDlgItem(hwndDlg, ID_SOUND_BUTTON_MIC_LARA);\n\tEnableWindow(hItem, isAvailable);\n\tSendMessage(hItem, BM_SETCHECK, ChangedAppSettings.LaraMic, 0);\n\n\t// 'Test' Button\n\thItem = (HWND)GetDlgItem(hwndDlg, ID_SOUND_BUTTON_TEST);\n\tEnableWindow(hItem, isAvailable);\n}\n\nvoid __cdecl SE_SoundDlgInit(HWND hwndDlg) {\n\tHWND comboBox;\n\tDWORD addedIndex, selectedIndex;\n\tSOUND_ADAPTER_NODE *adapter, *selected;\n\n\t// 'Sound Adapter' ComboBox\n\tcomboBox = GetDlgItem(hwndDlg, ID_SOUND_COMBOBOX_ADAPTER);\n\tSendMessage(comboBox, CB_RESETCONTENT, 0, 0);\n\n\tselectedIndex = 0;\n\tfor( adapter = SoundAdapterList.head; adapter; adapter = adapter->next ) {\n\t\taddedIndex = SendMessage(comboBox, CB_ADDSTRING, 0, (LPARAM)adapter->body.description.lpString);\n\t\tSendMessage(comboBox, CB_SETITEMDATA, addedIndex, (LPARAM)adapter);\n\t\tif( adapter == ChangedAppSettings.PreferredSoundAdapter )\n\t\t\tselectedIndex = addedIndex;\n\t}\n\n\tSendMessage(comboBox, CB_SETCURSEL, selectedIndex, 0);\n\tEnableWindow(comboBox, (SoundAdapterList.dwCount > 1));\n\tif( SoundAdapterList.dwCount > 0 ) {\n\t\tselected = (SOUND_ADAPTER_NODE *)SendMessage(comboBox, CB_GETITEMDATA, selectedIndex, 0);\n\t\tSE_SoundAdapterSet(hwndDlg, selected);\n\t}\n\tSE_SoundDlgUpdate(hwndDlg);\n}\n\nINT_PTR CALLBACK SE_ControlsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {\n\tstatic HWND hImage = NULL;\n\n\tswitch( uMsg ) {\n\t\tcase WM_INITDIALOG :\n\t\t\thImage = GetDlgItem(hwndDlg, ID_CTRLS_WINDOW_IMAGE);\n\t\t\tSE_ControlsDlgInit(hwndDlg);\n\t\t\treturn 1;\n\n\t\tcase WM_COMMAND :\n\t\t\tif( HIWORD(wParam) == 0 ) { // Buttons\n\t\t\t\tswitch( LOWORD(wParam) ) {\n\t\t\t\t\tcase ID_CTRLS_BUTTON_JOYSTICK_ENABLE : // 'Enable Joystick' checkbox\n\t\t\t\t\t\tChangedAppSettings.JoystickEnabled = (1 == SendMessage((HWND)lParam, BM_GETCHECK, 0, 0));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_CTRLS_BUTTON_CTL_PANEL : // 'Run Control Panel' Button\n\t\t\t\t\t\tDInputCreate();\n\t\t\t\t\t\tWinInRunControlPanel(hwndDlg);\n\t\t\t\t\t\tDInputRelease();\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else if( HIWORD(wParam) == 1 ) { // ComboBoxes\n\t\t\t\tif( LOWORD(wParam) == ID_CTRLS_COMBOBOX_JOYSTICK ) { // 'Joystick' ComboBox\n\t\t\t\t\tDWORD index = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0);\n\t\t\t\t\tJOYSTICK_NODE *joystick = (JOYSTICK_NODE *)SendMessage((HWND)lParam, CB_GETITEMDATA, index, 0);\n\t\t\t\t\tSE_ControlsJoystickSet(hwndDlg, joystick);\n\t\t\t\t\tSE_ControlsDlgUpdate(hwndDlg);\n\t\t\t\t}\n\t\t\t}\n\t}\n\tSE_PassMessageToImage(hImage, uMsg, wParam);\n\treturn 0;\n}\n\nvoid __cdecl SE_ControlsJoystickSet(HWND hwndDlg, JOYSTICK_NODE *joystick) {\n\tChangedAppSettings.PreferredJoystick = joystick;\n}\n\nvoid __cdecl SE_ControlsDlgUpdate(HWND hwndDlg) {\n\tbool isAvailable = ( JoystickList.dwCount > 0 );\n\tbool isCheck = ( isAvailable && ChangedAppSettings.JoystickEnabled );\n\t// 'Enable Joystick' CheckBox\n\tHWND checkBox = GetDlgItem(hwndDlg, ID_CTRLS_BUTTON_JOYSTICK_ENABLE);\n#ifdef FEATURE_INPUT_IMPROVED\n\tbool isDInput = false;\n\tif( isAvailable && ChangedAppSettings.PreferredJoystick ) {\n\t\tisDInput = ChangedAppSettings.PreferredJoystick->body.iface == JOY_DirectInput;\n\t}\n\tEnableWindow(GetDlgItem(hwndDlg, ID_CTRLS_BUTTON_CTL_PANEL), isDInput);\n#endif // FEATURE_INPUT_IMPROVED\n\tEnableWindow(checkBox, isAvailable);\n\tSendMessage(checkBox, BM_SETCHECK, isCheck, 0);\n}\n\nvoid __cdecl SE_ControlsDlgInit(HWND hwndDlg) {\n\tHWND comboBox;\n\tDWORD addedIndex, selectedIndex;\n\tJOYSTICK_NODE *joystick, *selected;\n\n\tcomboBox = GetDlgItem(hwndDlg, ID_CTRLS_COMBOBOX_JOYSTICK); // 'Joystick' ComboBox\n\tSendMessage(comboBox, CB_RESETCONTENT, 0, 0);\n\n\tselectedIndex = 0;\n\tfor( joystick = JoystickList.head; joystick; joystick = joystick->next ) {\n\t\taddedIndex = SendMessage(comboBox, CB_ADDSTRING, 0, (LPARAM)joystick->body.productName.lpString);\n\t\tSendMessage(comboBox, CB_SETITEMDATA, addedIndex, (LPARAM)joystick);\n\t\tif( joystick == ChangedAppSettings.PreferredJoystick )\n\t\t\tselectedIndex = addedIndex;\n\t}\n\n\tSendMessage(comboBox, CB_SETCURSEL, selectedIndex, 0);\n\tEnableWindow(comboBox, (JoystickList.dwCount > 1)); // NOTE: original was >0. But there is no reason to select 1/1 joystick\n\tif( JoystickList.dwCount > 0 ) {\n\t\tselected = (JOYSTICK_NODE *)SendMessage(comboBox, CB_GETITEMDATA, selectedIndex, 0);\n\t\tSE_ControlsJoystickSet(hwndDlg, selected);\n\t}\n\tSE_ControlsDlgUpdate(hwndDlg);\n}\n\nINT_PTR CALLBACK SE_OptionsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {\n\tHWND hImage = NULL;\n\tswitch( uMsg ) {\n\t\tcase WM_INITDIALOG :\n\t\t\thImage = GetDlgItem(hwndDlg, ID_OPTNS_WINDOW_IMAGE);\n\t\t\tif( !IsSetupDialogCentered ) {\n\t\t\t\tUT_CenterWindow(GetParent(hwndDlg));\n\t\t\t\tIsSetupDialogCentered = true;\n\t\t\t}\n\t\t\treturn 1;\n\n\t\tcase WM_NOTIFY :\n\t\t\tif( ((LPNMHDR)lParam)->code == ((UINT)PSN_SETACTIVE) )\n\t\t\t\tSE_OptionsDlgUpdate(hwndDlg);\n\t\t\tbreak;\n\t}\n\tSE_PassMessageToImage(hImage, uMsg, wParam);\n\treturn 0;\n}\n\nvoid __cdecl SE_OptionsDlgUpdate(HWND hwndDlg) {\n\tLPCTSTR lpString;\n\tchar resultString[256];\n\n\tif( ChangedAppSettings.PreferredDisplayAdapter != NULL ) {\n\t\t// 'Graphics' Static\n\t\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_GRAPHICS, ChangedAppSettings.PreferredDisplayAdapter->body.driverDescription.lpString);\n\n\t\t// 'Using:' Static\n\t\tif( ChangedAppSettings.RenderMode == RM_Hardware )\n\t\t\tlpString = String_Hardware3d;\n\t\telse\n\t\t\tlpString = String_Software3d;\n\t\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_USING, lpString);\n\n\t\t// 'Display:' Static\n\t\tif( ChangedAppSettings.FullScreen && ChangedAppSettings.VideoMode )\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\t\twsprintf(resultString, \"%s %dx%d\", String_FullScreen, ChangedAppSettings.VideoMode->body.width, ChangedAppSettings.VideoMode->body.height);\n#else // FEATURE_NOLEGACY_OPTIONS\n\t\t\twsprintf(resultString, \"%s %dx%dx%d\", String_FullScreen, ChangedAppSettings.VideoMode->body.width, ChangedAppSettings.VideoMode->body.height, ChangedAppSettings.VideoMode->body.bpp);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\telse\n\t\t\twsprintf(resultString, \"%s %dx%d%s\", String_Windowed, ChangedAppSettings.WindowWidth, ChangedAppSettings.WindowHeight, Strings_Aspect[ChangedAppSettings.AspectMode]);\n\t\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_DISPLAY, resultString);\n\n\t\t// 'Options:' Static\n\t\tbool isNext = false;\n\t\tLPTSTR pResultString = resultString;\n\t\tSE_OptionsStrCat(&pResultString, ChangedAppSettings.ZBuffer, &isNext, String_ZBuffered);\n\t\tSE_OptionsStrCat(&pResultString, ChangedAppSettings.BilinearFiltering, &isNext, String_BilinearFiltered);\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\tSE_OptionsStrCat(&pResultString, ChangedAppSettings.Dither, &isNext, String_Dithered);\n\t\tSE_OptionsStrCat(&pResultString, ChangedAppSettings.TripleBuffering, &isNext, String_TripleBuffered);\n\t\tSE_OptionsStrCat(&pResultString, ChangedAppSettings.PerspectiveCorrect, &isNext, String_PerspectiveCorrect);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t*pResultString = 0;\n\t\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_OPTIONS, resultString);\n\t} else {\n\t\t// 'Graphics' Static\n\t\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_GRAPHICS, String_None);\n\t\t// 'Using:' Static\n\t\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_USING, String_NA);\n\t\t// 'Display:' Static\n\t\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_DISPLAY, String_NA);\n\t\t// 'Options:' Static\n\t\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_OPTIONS, String_NA);\n\t}\n\n\t// 'Sound:' Static\n\tif( ChangedAppSettings.PreferredSoundAdapter != NULL )\n\t\tlpString = ChangedAppSettings.PreferredSoundAdapter->body.description.lpString;\n\telse\n\t\tlpString = String_None;\n\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_SOUND, lpString);\n\n\t// 'Sound Effects:' Static\n\tif( ChangedAppSettings.SoundEnabled )\n\t\tlpString = String_Enabled;\n\telse\n\t\tlpString = String_Disabled;\n\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_SFX, lpString);\n\n\t// 'Microphone Position' Static\n\tif( ChangedAppSettings.LaraMic )\n\t\tlpString = String_Lara;\n\telse\n\t\tlpString = String_Camera;\n\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_MIC, lpString);\n\n\t// 'Joystick' Static\n\tif( ChangedAppSettings.PreferredJoystick != NULL )\n\t\tlpString = ChangedAppSettings.PreferredJoystick->body.productName.lpString;\n\telse\n\t\tlpString = String_None;\n\tSetDlgItemText(hwndDlg, ID_OPTNS_STATIC_JOYSTICK, lpString);\n}\n\nvoid __cdecl SE_OptionsStrCat(LPTSTR *dstString, bool isEnabled, bool *isNext, LPCTSTR srcString) {\n\tif( !isEnabled )\n\t\treturn;\n\n\tif( *isNext ) {\n\t\t*(*dstString)++ = ',';\n\t\t*(*dstString)++ = ' ';\n\t}\n\n\twhile( *srcString )\n\t\t*(*dstString)++ = *srcString++;\n\n\t*isNext = true;\n}\n\nINT_PTR CALLBACK SE_AdvancedDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {\n\tstatic HWND hImage = NULL;\n\n\tswitch( uMsg ) {\n\t\tcase WM_INITDIALOG :\n\t\t\thImage = GetDlgItem(hwndDlg, ID_ADVNC_WINDOW_IMAGE);\n\t\t\tSE_AdvancedDlgInit(hwndDlg);\n\t\t\treturn 1;\n\n\t\tcase WM_COMMAND :\n\t\t\tif( HIWORD(wParam) == 0 ) { // Buttons\n\t\t\t\tbool isCheck = ( 1 == SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) );\n\t\t\t\tswitch( LOWORD(wParam) ) {\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\tcase ID_ADVNC_BUTTON_16BIT_DISABLE : // 'Disable 16 bit textures' CheckBox\n\t\t\t\t\t\tChangedAppSettings.Disable16BitTextures = isCheck;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_ADVNC_BUTTON_SORT_DISABLE : // 'Don't sort transparent polys' CheckBox\n\t\t\t\t\t\tChangedAppSettings.DontSortPrimitives = isCheck;\n\t\t\t\t\t\tbreak;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\tcase ID_ADVNC_BUTTON_FMV_DISABLE : // 'Disable FMV' CheckBox\n\t\t\t\t\t\tChangedAppSettings.DisableFMV = isCheck;\n\t\t\t\t\t\tbreak;\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t\tcase ID_ADVNC_BUTTON_ADJUST_DISABLE : // 'Don't adjust' RadioButton\n\t\t\t\t\t\tChangedAppSettings.TexelAdjustMode = TAM_Disabled;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_ADVNC_BUTTON_ADJUST_BILINEAR : // 'Adjust when bilinear filtering' RadioButton\n\t\t\t\t\t\tChangedAppSettings.TexelAdjustMode = TAM_BilinearOnly;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase ID_ADVNC_BUTTON_ADJUST_ALWAYS : // 'Always adjust' RadioButton\n\t\t\t\t\t\tChangedAppSettings.TexelAdjustMode = TAM_Always;\n\t\t\t\t\t\tbreak;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\t\t\t}\n\t\t\t\tSE_AdvancedDlgUpdate(hwndDlg);\n\t\t\t}\n\t\t\tbreak;\n\t}\n\tSE_PassMessageToImage(hImage, uMsg, wParam);\n\treturn 0;\n}\n\nvoid __cdecl SE_AdvancedDlgUpdate(HWND hwndDlg) {\n\t// 'Disable 16 bit textures' CheckBox\n\tCheckDlgButton(hwndDlg, ID_ADVNC_BUTTON_16BIT_DISABLE,\t\tChangedAppSettings.Disable16BitTextures);\n\t// 'Don't sort transparent polys' CheckBox\n\tCheckDlgButton(hwndDlg, ID_ADVNC_BUTTON_SORT_DISABLE,\t\tChangedAppSettings.DontSortPrimitives);\n\t// 'Disable FMV' CheckBox\n\tCheckDlgButton(hwndDlg, ID_ADVNC_BUTTON_FMV_DISABLE,\t\tChangedAppSettings.DisableFMV);\n\t// 'Don't adjust' RadioButton\n\tCheckDlgButton(hwndDlg, ID_ADVNC_BUTTON_ADJUST_DISABLE,\t\tChangedAppSettings.TexelAdjustMode == TAM_Disabled);\n\t// 'Adjust when bilinear filtering' RadioButton\n\tCheckDlgButton(hwndDlg, ID_ADVNC_BUTTON_ADJUST_BILINEAR,\tChangedAppSettings.TexelAdjustMode == TAM_BilinearOnly);\n \t// 'Always adjust' RadioButton\n \tCheckDlgButton(hwndDlg, ID_ADVNC_BUTTON_ADJUST_ALWAYS,\t\tChangedAppSettings.TexelAdjustMode == TAM_Always);\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tEnableWindow(GetDlgItem(hwndDlg, ID_ADVNC_BUTTON_16BIT_DISABLE), FALSE);\n\tEnableWindow(GetDlgItem(hwndDlg, ID_ADVNC_BUTTON_SORT_DISABLE), FALSE);\n\tEnableWindow(GetDlgItem(hwndDlg, ID_ADVNC_BUTTON_ADJUST_DISABLE), FALSE);\n\tEnableWindow(GetDlgItem(hwndDlg, ID_ADVNC_BUTTON_ADJUST_BILINEAR), FALSE);\n\tEnableWindow(GetDlgItem(hwndDlg, ID_ADVNC_BUTTON_ADJUST_ALWAYS), FALSE);\n#endif // FEATURE_NOLEGACY_OPTIONS\n}\n\nvoid __cdecl SE_AdvancedDlgInit(HWND hwndDlg) {\n\tSE_AdvancedDlgUpdate(hwndDlg);\n}\n\nHWND __cdecl SE_FindSetupDialog() {\n\treturn FindWindow(WC_DIALOG, GameDialogName);\n}\n\n/*\n * Inject function\n */\nvoid Inject_SetupDlg() {\n\tINJECT(0x00452480, OpenGameRegistryKey);\n\tINJECT(0x004524D0, CloseGameRegistryKey);\n\tINJECT(0x004524E0, SE_WriteAppSettings);\n\tINJECT(0x00452760, SE_ReadAppSettings);\n\tINJECT(0x00452AC0, SE_GraphicsTestStart);\n\tINJECT(0x00452B90, SE_GraphicsTestFinish);\n\tINJECT(0x00452BB0, SE_GraphicsTestExecute);\n\tINJECT(0x00452BC0, SE_GraphicsTest);\n\tINJECT(0x00452C20, SE_DefaultGraphicsSettings);\n\tINJECT(0x00452D70, SE_SoundTestStart);\n\tINJECT(0x00452E30, SE_SoundTestFinish);\n\tINJECT(0x00452E40, SE_SoundTestExecute);\n\tINJECT(0x00452E80, SE_SoundTest);\n\tINJECT(0x00452EE0, SE_PropSheetCallback);\n\tINJECT(0x00452F20, SE_NewPropSheetWndProc);\n\tINJECT(0x00452F80, SE_ShowSetupDialog);\n\tINJECT(0x00453150, SE_GraphicsDlgProc);\n\tINJECT(0x00453560, SE_GraphicsDlgFullScreenModesUpdate);\n\tINJECT(0x00453750, SE_GraphicsAdapterSet);\n\tINJECT(0x00453770, SE_GraphicsDlgUpdate);\n\tINJECT(0x00453EB0, SE_GraphicsDlgInit);\n\tINJECT(0x00454030, SE_SoundDlgProc);\n\tINJECT(0x004541C0, SE_SoundAdapterSet);\n\tINJECT(0x004541D0, SE_SoundDlgUpdate);\n\tINJECT(0x004542F0, SE_SoundDlgInit);\n\tINJECT(0x004543B0, SE_ControlsDlgProc);\n\tINJECT(0x004544D0, SE_ControlsJoystickSet);\n\tINJECT(0x004544D0, SE_ControlsDlgUpdate);\n\tINJECT(0x00454540, SE_ControlsDlgInit);\n\tINJECT(0x00454690, SE_OptionsDlgUpdate);\n\tINJECT(0x004548D0, SE_OptionsStrCat);\n\tINJECT(0x00454920, SE_AdvancedDlgProc);\n\tINJECT(0x00454A30, SE_AdvancedDlgUpdate);\n\tINJECT(0x00454AE0, SE_AdvancedDlgInit);\n\tINJECT(0x00454AF0, SE_FindSetupDialog);\n}\n"
  },
  {
    "path": "specific/setupdlg.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SETUPDLG_H_INCLUDED\n#define SETUPDLG_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nbool __cdecl OpenGameRegistryKey(LPCTSTR key); // 0x00452480\nLONG __cdecl CloseGameRegistryKey(); // 0x004524D0\nbool __cdecl SE_WriteAppSettings(APP_SETTINGS *settings); // 0x004524E0\nint __cdecl SE_ReadAppSettings(APP_SETTINGS *settings); // 0x00452760\nbool __cdecl SE_GraphicsTestStart(); // 0x00452AC0\nvoid __cdecl SE_GraphicsTestFinish(); // 0x00452B90\nint __cdecl SE_GraphicsTestExecute(); // 0x00452BB0\nint __cdecl SE_GraphicsTest(); // 0x00452BC0\nvoid __cdecl SE_DefaultGraphicsSettings(); // 0x00452C20\nbool __cdecl SE_SoundTestStart(); // 0x00452D70\nvoid __cdecl SE_SoundTestFinish(); // 0x00452E30\nint __cdecl SE_SoundTestExecute(); // 0x00452E40\nint __cdecl SE_SoundTest(); // 0x00452E80\nint CALLBACK SE_PropSheetCallback(HWND hwndDlg, UINT uMsg, LPARAM lParam); // 0x00452EE0\nLRESULT CALLBACK SE_NewPropSheetWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); // 0x00452F20\nbool __cdecl SE_ShowSetupDialog(HWND hParent, bool isDefault); // 0x00452F80\nINT_PTR CALLBACK SE_GraphicsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); // 0x00453150\nvoid __cdecl SE_GraphicsDlgFullScreenModesUpdate(HWND hwndDlg); // 0x00453560\nvoid __cdecl SE_GraphicsAdapterSet(HWND hwndDlg, DISPLAY_ADAPTER_NODE *adapter); // 0x00453750\nvoid __cdecl SE_GraphicsDlgUpdate(HWND hwndDlg); // 0x00453770\nvoid __cdecl SE_GraphicsDlgInit(HWND hwndDlg); // 0x00453EB0\nINT_PTR CALLBACK SE_SoundDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); // 0x00454030\nvoid __cdecl SE_SoundAdapterSet(HWND hwndDlg, SOUND_ADAPTER_NODE *adapter); // 0x004541C0\nvoid __cdecl SE_SoundDlgUpdate(HWND hwndDlg); // 0x004541D0\nvoid __cdecl SE_SoundDlgInit(HWND hwndDlg); // 0x004542F0\nINT_PTR CALLBACK SE_ControlsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); // 0x004543B0\nvoid __cdecl SE_ControlsJoystickSet(HWND hwndDlg, JOYSTICK_NODE *joystick); // 0x004544C0\nvoid __cdecl SE_ControlsDlgUpdate(HWND hwndDlg); // 0x004544D0\nvoid __cdecl SE_ControlsDlgInit(HWND hwndDlg); // 0x00454540\nINT_PTR CALLBACK SE_OptionsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); // 0x00454600\nvoid __cdecl SE_OptionsDlgUpdate(HWND hwndDlg); // 0x00454690\nvoid __cdecl SE_OptionsStrCat(LPTSTR *dstString, bool isEnabled, bool *isNext, const LPCTSTR srcString); // 0x004548D0\nINT_PTR CALLBACK SE_AdvancedDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); // 0x00454920\nvoid __cdecl SE_AdvancedDlgUpdate(HWND hwndDlg); // 0x00454A30\nvoid __cdecl SE_AdvancedDlgInit(HWND hwndDlg); // 0x00454AE0\nHWND __cdecl SE_FindSetupDialog(); // 0x00454AF0\n\n#endif // SETUPDLG_H_INCLUDED\n"
  },
  {
    "path": "specific/setupwnd.cpp",
    "content": "/*\n * Copyright (c) 2017 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/setupwnd.h\"\n#include \"specific/utils.h\"\n#include \"global/vars.h\"\n#include <cpl.h>\n\n#define WINLONG_X\t(0)\n#define WINLONG_Y\t(4)\n#define WINLONG_BMP\t(8)\n\nstatic void SE_CenterBitmapResource(HWND hWnd, BITMAP_RESOURCE *pBitmap, LPCTSTR imageName) {\n\tint x, y, width, height;\n\n\tif( pBitmap == NULL || imageName == NULL || *imageName == 0 )\n\t\treturn;\n\n\tSE_LoadBitmapResource(pBitmap, imageName);\n\n\tx = (int)GetWindowLong(hWnd, WINLONG_X);\n\ty = (int)GetWindowLong(hWnd, WINLONG_Y);\n\twidth = pBitmap->bmpInfo->bmiHeader.biWidth + 4;\n\theight = pBitmap->bmpInfo->bmiHeader.biHeight + 4;\n\n\tMoveWindow(hWnd, x-width/2, y-height/2, width, height, TRUE);\n}\n\nvoid __thiscall SE_ReleaseBitmapResource(BITMAP_RESOURCE *bmpRsrc) {\n\tif( bmpRsrc->hPalette != NULL ) {\n\t\tDeleteObject(bmpRsrc->hPalette);\n\t\tbmpRsrc->hPalette = NULL;\n\t}\n\n\tif( bmpRsrc->bmpData != NULL && (bmpRsrc->flags & 1) != 0 ) {\n\t\tfree(bmpRsrc->bmpData);\n\t\tbmpRsrc->bmpData = NULL;\n\t}\n}\n\nvoid __thiscall SE_LoadBitmapResource(BITMAP_RESOURCE *bmpRsrc, LPCTSTR lpName) {\n\tstatic LOGPALETTE *logPalette = (LOGPALETTE *)malloc(sizeof(LOGPALETTE) + sizeof(PALETTEENTRY)*255);\n\tPALETTEENTRY *bmpPalette;\n\tBYTE *bitmap;\n\n\tif( bmpRsrc->hPalette != NULL ) {\n\t\tDeleteObject(bmpRsrc->hPalette);\n\t\tbmpRsrc->hPalette = NULL;\n\t}\n\n\tbitmap = (BYTE *)UT_LoadResource(lpName, RT_BITMAP);\n\tbmpRsrc->bmpInfo = (PBITMAPINFO)bitmap;\n\tbmpRsrc->flags = 0;\n\n\tif( bitmap == NULL )\n\t\treturn;\n\n\tbmpPalette = (PALETTEENTRY *)(bitmap + sizeof(BITMAPINFOHEADER));\n\tbmpRsrc->bmpData = bitmap + sizeof(BITMAPINFOHEADER) + sizeof(PALETTEENTRY)*256;\n\n\tlogPalette->palVersion = 0x0300;\n\tlogPalette->palNumEntries = 256;\n\n\tfor( int i=0; i<256; ++i ) {\n\t\tlogPalette->palPalEntry[i].peRed\t= bmpPalette[i].peRed;\n\t\tlogPalette->palPalEntry[i].peGreen\t= bmpPalette[i].peGreen;\n\t\tlogPalette->palPalEntry[i].peBlue\t= bmpPalette[i].peBlue;\n\t\tlogPalette->palPalEntry[i].peFlags\t= (i>=10 && i<246) ? PC_NOCOLLAPSE : 0;\n\t}\n\tbmpRsrc->hPalette = CreatePalette(logPalette);\n}\n\nvoid __thiscall SE_DrawBitmap(BITMAP_RESOURCE *bmpRsrc, HDC hdc, int x, int y) {\n\tint width, height;\n\tHPALETTE hPalette;\n\n\tif( bmpRsrc->hPalette == NULL)\n\t\treturn;\n\n\twidth = bmpRsrc->bmpInfo->bmiHeader.biWidth;\n\theight = bmpRsrc->bmpInfo->bmiHeader.biHeight;\n\n\thPalette = SelectPalette(hdc, bmpRsrc->hPalette, FALSE);\n\tRealizePalette(hdc);\n\tSetDIBitsToDevice(hdc, x, y, width, height, 0, 0, 0, height, bmpRsrc->bmpData, bmpRsrc->bmpInfo, DIB_RGB_COLORS);\n\tSelectPalette(hdc, hPalette, FALSE);\n}\n\nvoid __thiscall SE_UpdateBitmapPalette(BITMAP_RESOURCE *bmpRsrc, HWND hWnd, HWND hSender) {\n\tif( bmpRsrc->hPalette != NULL && hSender != hWnd )\n\t\tSE_ChangeBitmapPalette(bmpRsrc, hWnd);\n}\n\nvoid __thiscall SE_ChangeBitmapPalette(BITMAP_RESOURCE *bmpRsrc, HWND hWnd) {\n\tHDC hdc;\n\tHPALETTE hPalette;\n\n\tif( bmpRsrc->hPalette == NULL)\n\t\treturn;\n\n\thdc = GetDC(hWnd);\n\thPalette = SelectPalette(hdc, bmpRsrc->hPalette, FALSE);\n\tUnrealizeObject(bmpRsrc->hPalette);\n\tRealizePalette(hdc);\n\tSelectPalette(hdc, hPalette, FALSE);\n\tReleaseDC(hWnd, hdc);\n}\n\nbool __cdecl SE_RegisterSetupWindowClass() {\n\tWNDCLASSA wndClass;\n\tmemset(&wndClass, 0, sizeof(WNDCLASSA));\n\twndClass.style = CS_HREDRAW|CS_VREDRAW;\n\twndClass.lpfnWndProc = SE_SetupWindowProc;\n\twndClass.hInstance = GameModule;\n\twndClass.hCursor = LoadCursor(NULL, IDC_ARROW);\n\twndClass.lpszClassName = DialogClassName;\n\twndClass.cbWndExtra = sizeof(LONG) * 3;\n\n\treturn ( 0 != RegisterClass(&wndClass) );\n}\n\nLRESULT CALLBACK SE_SetupWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {\n\tRECT rect;\n\tPOINT point;\n\tHDC hdc;\n\tPAINTSTRUCT paint;\n\tchar imageName[64];\n\tBITMAP_RESOURCE *pBitmap = (BITMAP_RESOURCE *)GetWindowLong(hWnd, WINLONG_BMP);\n\n\tswitch( uMsg ) {\n\t\tcase WM_CREATE :\n\t\t\tGetClientRect(hWnd, &rect);\n\t\t\tpoint.x = rect.right / 2;\n\t\t\tpoint.y = rect.bottom / 2;\n\t\t\tMapWindowPoints(hWnd, GetParent(hWnd), &point, 1);\n\t\t\tSetWindowLong(hWnd, WINLONG_X, (LONG)point.x);\n\t\t\tSetWindowLong(hWnd, WINLONG_Y, (LONG)point.y);\n\t\t\tpBitmap = new BITMAP_RESOURCE;\n\t\t\tif( pBitmap != NULL ) {\n\t\t\t\tmemset(pBitmap, 0, sizeof(BITMAP_RESOURCE));\n\t\t\t\tSetWindowLong(hWnd, WINLONG_BMP, (LONG)pBitmap);\n\t\t\t\tGetWindowText(hWnd, imageName, sizeof(imageName));\n\t\t\t\tSE_CenterBitmapResource(hWnd, pBitmap, imageName);\n\t\t\t}\n\t\t\treturn 0;\n\n\t\tcase WM_DESTROY :\n\t\t\tif( pBitmap != NULL ) {\n\t\t\t\tSE_ReleaseBitmapResource(pBitmap);\n\t\t\t\tdelete(pBitmap);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase WM_PAINT :\n\t\t\tGetClientRect(hWnd, &rect);\n\t\t\thdc = BeginPaint(hWnd, &paint);\n\t\t\tDrawEdge(hdc, &rect, BDR_RAISEDINNER|BDR_SUNKENOUTER, BF_ADJUST|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT);\n\t\t\tSE_DrawBitmap(pBitmap, hdc, rect.left, rect.top);\n\t\t\tEndPaint(hWnd, &paint);\n\t\t\treturn 0;\n\n\t\tcase WM_QUERYNEWPALETTE :\n\t\t\tSE_ChangeBitmapPalette(pBitmap, hWnd);\n\t\t\tInvalidateRect(hWnd, NULL, FALSE);\n\t\t\tUpdateWindow(hWnd);\n\t\t\treturn 1;\n\n\t\tcase WM_PALETTECHANGED :\n\t\t\tSE_UpdateBitmapPalette(pBitmap, hWnd, (HWND)wParam);\n\t\t\tInvalidateRect(hWnd, NULL, FALSE);\n\t\t\tUpdateWindow(hWnd);\n\t\t\tbreak;\n\n\t\tcase WM_CPL_LAUNCH :\n\t\t\tSE_CenterBitmapResource(hWnd, pBitmap, (LPCTSTR)wParam);\n\t\t\treturn 0;\n\t}\n\treturn DefWindowProc(hWnd, uMsg, wParam, lParam);\n}\n\nvoid __cdecl SE_PassMessageToImage(HWND hWnd, UINT uMsg, WPARAM wParam) {\n\tif( uMsg == WM_QUERYNEWPALETTE || uMsg == WM_PALETTECHANGED )\n\t\tSendMessage(hWnd, uMsg, wParam, 0);\n}\n\n/*\n * Inject function\n */\nvoid Inject_SetupWnd() {\n\tINJECT(0x00456FC0, SE_ReleaseBitmapResource);\n\tINJECT(0x00457000, SE_LoadBitmapResource);\n\tINJECT(0x004570D0, SE_DrawBitmap);\n\tINJECT(0x00457140, SE_UpdateBitmapPalette);\n\tINJECT(0x00457160, SE_ChangeBitmapPalette);\n\tINJECT(0x004571C0, SE_RegisterSetupWindowClass);\n\tINJECT(0x00457230, SE_SetupWindowProc);\n\tINJECT(0x00457470, SE_PassMessageToImage);\n}\n"
  },
  {
    "path": "specific/setupwnd.h",
    "content": "/*\n * Copyright (c) 2017 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SETUPWND_H_INCLUDED\n#define SETUPWND_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nvoid __thiscall SE_ReleaseBitmapResource(BITMAP_RESOURCE *bmpRsrc); // 0x00456FC0\nvoid __thiscall SE_LoadBitmapResource(BITMAP_RESOURCE *bmpRsrc, LPCTSTR lpName); // 0x00457000\nvoid __thiscall SE_DrawBitmap(BITMAP_RESOURCE *bmpRsrc, HDC hdc, int x, int y); // 0x004570D0\nvoid __thiscall SE_UpdateBitmapPalette(BITMAP_RESOURCE *bmpRsrc, HWND hWnd, HWND hSender); // 0x00457140\nvoid __thiscall SE_ChangeBitmapPalette(BITMAP_RESOURCE *bmpRsrc, HWND hWnd); // 0x00457160\nbool __cdecl SE_RegisterSetupWindowClass(); // 0x004571C0\nLRESULT CALLBACK SE_SetupWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); // 0x00457230\nvoid __cdecl SE_PassMessageToImage(HWND hWnd, UINT uMsg, WPARAM wParam); // 0x00457470\n\n#endif // SETUPWND_H_INCLUDED\n"
  },
  {
    "path": "specific/smain.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/smain.h\"\n#include \"game/cinema.h\"\n#include \"game/demo.h\"\n#include \"game/gameflow.h\"\n#include \"game/inventory.h\"\n#include \"game/invfunc.h\"\n#include \"game/missile.h\"\n#include \"game/savegame.h\"\n#include \"game/setup.h\"\n#include \"game/sound.h\"\n#include \"game/text.h\"\n#include \"specific/display.h\"\n#include \"specific/frontend.h\"\n#include \"specific/game.h\"\n#include \"specific/hwr.h\"\n#include \"specific/init.h\"\n#include \"specific/input.h\"\n#include \"specific/option.h\"\n#include \"specific/output.h\"\n#include \"specific/registry.h\"\n#include \"specific/setupdlg.h\"\n#include \"specific/sndpc.h\"\n#include \"specific/winmain.h\"\n#include \"modding/background_new.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_HUD_IMPROVED\nextern DWORD DemoTextMode;\nextern DWORD JoystickButtonStyle;\nextern DWORD SavegameSlots;\nextern DWORD InvTextBoxMode;\nextern DWORD HealthBarMode;\nextern bool PsxBarPosEnabled;\nextern bool JoystickHintsEnabled;\nextern double GameGUI_Scale;\nextern double InvGUI_Scale;\n#endif // FEATURE_HUD_IMPROVED\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\nstatic char PictureSuffix[32];\nextern DWORD InvBackgroundMode;\nextern DWORD StatsBackgroundMode;\nextern DWORD PauseBackgroundMode;\nextern DWORD PictureStretchLimit;\nextern bool LoadingScreensEnabled;\nextern bool RemasteredPixEnabled;\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nextern DWORD ShadowMode;\nextern DWORD AlphaBlendMode;\nextern DWORD ReflectionMode;\nextern DWORD PickupItemMode;\nextern bool CustomWaterColorEnabled;\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n#ifdef FEATURE_SCREENSHOT_IMPROVED\nextern DWORD ScreenshotFormat;\nextern char ScreenshotPath[MAX_PATH];\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/joy_output.h\"\nextern bool WalkToSidestep;\nextern bool JoystickVibrationEnabled;\nextern bool JoystickLedColorEnabled;\n#endif // FEATURE_INPUT_IMPROVED\n\n#ifdef FEATURE_MOD_CONFIG\nextern bool BarefootSfxEnabled;\n#endif // FEATURE_MOD_CONFIG\n\n#ifdef FEATURE_AUDIO_IMPROVED\nextern double InventoryMusicMute;\nextern double UnderwaterMusicMute;\n#endif // FEATURE_AUDIO_IMPROVED\n\n#ifdef FEATURE_VIEW_IMPROVED\nextern bool PsxFovEnabled;\nextern double ViewDistanceFactor;\nextern double FogBeginFactor;\nextern double FogEndFactor;\nextern double WaterFogBeginFactor;\nextern double WaterFogEndFactor;\n#endif // FEATURE_VIEW_IMPROVED\n\n#ifdef FEATURE_GAMEPLAY_FIXES\nextern bool IsRunningM16fix;\nextern bool IsLowCeilingJumpFix;\n#endif // FEATURE_GAMEPLAY_FIXES\n\n#ifdef FEATURE_GOLD\nextern bool IsGold();\n#endif\n\n#ifdef FEATURE_ASSAULT_SAVE\nvoid SaveAssault() {\n\tOpenGameRegistryKey(REG_GAME_KEY);\n\tSetRegistryBinaryValue(REG_GAME_ASSAULT, (LPBYTE)&Assault, sizeof(ASSAULT_STATS));\n\tCloseGameRegistryKey();\n}\n#endif // FEATURE_ASSAULT_SAVE\n\nBOOL __cdecl GameMain() {\n\t__int16 gfOption, gfDirection, gfParameter;\n\tbool isFrontendFail, isLoopContinue, bonusFlag;\n\n\tHiRes = 0;\n\tScreenSizer = 1.0;\n\tGameSizer = 1.0;\n\n\tif( !S_InitialiseSystem() )\n\t\treturn FALSE;\n\n\tLPCTSTR scriptFileName = \"data\\\\tombPC.dat\";\n#ifdef FEATURE_GOLD\n\tif( IsGold() ) {\n\t\tscriptFileName = \"data\\\\tombPCg.dat\";\n\t}\n#endif // FEATURE_GOLD\n\n\tif ( !GF_LoadScriptFile(scriptFileName) ) {\n\t\tS_ExitSystem(\"GameMain: could not load script file\");\n\t\treturn FALSE; // the app is terminated here\n\t}\n\n\tSOUND_Init();\n\tInitialiseStartInfo();\n\t// NOTE: S_FrontEndCheck() called before S_LoadSettings() in the original game\n\tS_LoadSettings();\n\tS_FrontEndCheck();\n\tHiRes = -1;\n\n\t// NOTE: this HWR init was absent in the original code, but must be done here\n\tif( SavedAppSettings.RenderMode == RM_Hardware ) {\n\t\tHWR_InitState();\n\t}\n\n\tGameMemoryPointer = (BYTE *)GlobalAlloc(GMEM_FIXED, GameMemorySize);\n\tif( GameMemoryPointer == NULL ) {\n\t\tlstrcpy(StringToShow, \"GameMain: could not allocate malloc_buffer\");\n\t\treturn FALSE;\n\t}\n\n\tHiRes = 0;\n\tTempVideoAdjust(1, 1.0);\n\tS_UpdateInput();\n\tIsVidModeLock = true;\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tint res = -1;\n\tif( *PictureSuffix ) {\n\t\tchar fname[256];\n\t\tsnprintf(fname, sizeof(fname), \"data\\\\legal%s.pcx\", PictureSuffix);\n\t\tres = BGND2_LoadPicture(fname, FALSE, FALSE);\n\t}\n\tif( res ) {\n\t\tres = BGND2_LoadPicture(\"data\\\\legal.pcx\", FALSE, FALSE);\n\t}\n\tif( !res ) {\n\t\tBGND2_ShowPicture(30, 90, 10, 2, TRUE);\n\t}\n#else // FEATURE_BACKGROUND_IMPROVED\n#ifdef FEATURE_GOLD\n\tS_DisplayPicture(IsGold()?\"data\\\\legalg.pcx\":\"data\\\\legal.pcx\", FALSE);\n#else // !FEATURE_GOLD\n\tS_DisplayPicture(\"data\\\\legal.pcx\", FALSE);\n#endif // !FEATURE_GOLD\n\tS_InitialisePolyList(FALSE);\n\tS_CopyBufferToScreen();\n\tS_OutputPolyList();\n\tS_DumpScreen();\n\tFadeToPal(30, GamePalette8); // fade in 30 frames / 1.0 second (software renderer only)\n\tS_Wait(90 * TICKS_PER_FRAME, TRUE); // wait 90 frames / 3.0 seconds (enable keyboard)\n\tS_FadeToBlack(); // fade out 12 frames / 0.4 second (software renderer only)\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tS_DontDisplayPicture();\n\tIsVidModeLock = false;\n\n\tisFrontendFail = GF_DoFrontEndSequence();\n\tif( IsGameToExit ) {\n\t\treturn TRUE;\n\t}\n\tif( isFrontendFail ) {\n\t\tlstrcpy(StringToShow, \"GameMain: failed in GF_DoFrontEndSequence()\");\n\t\treturn FALSE;\n\t}\n\n\tS_FadeToBlack();\n\tIsTitleLoaded = FALSE;\n\n\tgfOption = GF_GameFlow.firstOption;\n\tisLoopContinue = true;\n\n\twhile( isLoopContinue ) {\n\t\tgfDirection = gfOption & 0xFF00;\n\t\tgfParameter = gfOption & 0x00FF;\n\t\tswitch( gfDirection ) {\n\n\t\t\tcase GF_START_GAME :\n\t\t\t\tif( GF_GameFlow.singleLevel >= 0 ) {\n\t\t\t\t\tgfOption = GF_DoLevelSequence(GF_GameFlow.singleLevel, GFL_NORMAL);\n\t\t\t\t} else {\n\t\t\t\t\tif( gfParameter > GF_GameFlow.num_Levels ) {\n\t\t\t\t\t\twsprintf(StringToShow, \"GameMain: STARTGAME with invalid level number (%d)\", gfParameter);\n\t\t\t\t\t\treturn FALSE;\n\t\t\t\t\t}\n\t\t\t\t\tgfOption = GF_DoLevelSequence(gfParameter, GFL_NORMAL);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase GF_START_SAVEDGAME :\n\t\t\t\tS_LoadGame(&SaveGame, sizeof(SAVEGAME_INFO), gfParameter);\n\t\t\t\tif( SaveGame.currentLevel > GF_GameFlow.num_Levels ) {\n\t\t\t\t\twsprintf(StringToShow, \"GameMain: STARTSAVEDGAME with invalid level number (%d)\", SaveGame.currentLevel);\n\t\t\t\t\treturn FALSE;\n\t\t\t\t}\n\t\t\t\tgfOption = GF_DoLevelSequence(SaveGame.currentLevel, GFL_SAVED);\n\t\t\t\tbreak;\n\n\t\t\tcase GF_START_CINE :\n\t\t\t\tStartCinematic(gfParameter);\n\t\t\t\tgfOption = GF_EXIT_TO_TITLE;\n\t\t\t\tbreak;\n\n\t\t\tcase GF_START_DEMO :\n\t\t\t\t// NOTE: there is no such bonus flag reset in the original game\n\t\t\t\tbonusFlag = SaveGame.bonusFlag; // backup bonusFlag\n\t\t\t\tSaveGame.bonusFlag = 0; // remove bonusFlag while Demo is playing\n\t\t\t\tgfOption = DoDemoSequence(-1);\n\t\t\t\tSaveGame.bonusFlag = bonusFlag; // restore bonusFlag\n\t\t\t\tbreak;\n\n\t\t\tcase GF_LEVEL_COMPLETE :\n\t\t\t\tgfOption = LevelCompleteSequence();\n\t\t\t\tbreak;\n\n\t\t\tcase GF_EXIT_TO_TITLE :\n\t\t\tcase GF_EXIT_TO_OPTION :\n\t\t\t\tif( (GF_GameFlow.flags & GFF_TitleDisabled) != 0 ) {\n\t\t\t\t\tgfOption = GF_GameFlow.titleReplace;\n\t\t\t\t\tif( gfOption == GF_EXIT_TO_TITLE || gfOption < 0 ) {\n\t\t\t\t\t\tlstrcpy(StringToShow, \"GameMain Failed: Title disabled & no replacement\");\n\t\t\t\t\t\treturn FALSE;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tgfOption = TitleSequence();\n\t\t\t\t\tGF_StartGame = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase GF_START_FMV :\n\t\t\tcase GF_EXIT_GAME :\n\t\t\tdefault :\n\t\t\t\tisLoopContinue = false;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tS_SaveSettings();\n\tShutdownGame();\n\treturn TRUE;\n}\n\n__int16 __cdecl TitleSequence() {\n\tT_InitPrint();\n\tTempVideoAdjust(1, 1.0);\n\tNoInputCounter = 0;\n\n\tif( !IsTitleLoaded ) {\n\t\tif( !InitialiseLevel(0, 0) )\n\t\t\treturn GF_EXIT_GAME;\n\t\tIsTitleLoaded = TRUE;\n\t}\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tint res = -1;\n\tif( *PictureSuffix ) {\n\t\tchar fname[256];\n\t\tsnprintf(fname, sizeof(fname), \"data\\\\title%s.pcx\", PictureSuffix);\n\t\tres = BGND2_LoadPicture(fname, TRUE, FALSE);\n\t}\n\tif( res ) {\n\t\tres = BGND2_LoadPicture(\"data\\\\title.pcx\", TRUE, FALSE);\n\t}\n\tif( !res ) {\n\t\t// NOTE: title menu fade-in was absent in the original game\n\t\tBGND2_ShowPicture(15, 0, 0, 0, FALSE);\n\t}\n#elif defined(FEATURE_GOLD)\n\tS_DisplayPicture(IsGold()?\"data\\\\titleg.pcx\":\"data\\\\title.pcx\", TRUE);\n#else // FEATURE_BACKGROUND_IMPROVED\n\tS_DisplayPicture(\"data\\\\title.pcx\", TRUE);\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n\tif( GF_GameFlow.titleTrack != 0 )\n\t\tS_CDPlay(GF_GameFlow.titleTrack, TRUE);\n\n\tDisplay_Inventory(INV_TitleMode);\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tBGND2_ShowPicture(0, 0, 10, 2, FALSE);\n#else // FEATURE_BACKGROUND_IMPROVED\n\tS_FadeToBlack();\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tS_DontDisplayPicture();\n\tS_CDStop();\n\n\tif( IsResetFlag ) {\n\t\tIsResetFlag = FALSE;\n\t\treturn GF_START_DEMO;\n\t}\n\n\tif( InventoryChosen == ID_PHOTO_OPTION )\n\t\treturn GF_START_GAME | 0;\n\n\tif( InventoryChosen == ID_PASSPORT_OPTION ) {\n\t\tif ( InventoryExtraData[0] == 0 ) {\n\t\t\t__int16 slotNumber = InventoryExtraData[1];\n\n\t\t\tInv_RemoveAllItems();\n\t\t\tS_LoadGame(&SaveGame, sizeof(SAVEGAME_INFO), slotNumber);\n\n\t\t\treturn GF_START_SAVEDGAME | slotNumber;\n\t\t}\n\n\t\tif( InventoryExtraData[0] == 1 ) {\n\t\t\t__int16 levelID = 1;\n\n\t\t\tInitialiseStartInfo();\n\t\t\tif( (GF_GameFlow.flags & GFF_SelectAnyLevel) != 0 )\n\t\t\t\tlevelID = InventoryExtraData[1] + 1;\n\n\t\t\treturn GF_START_GAME | levelID;\n\t\t}\n\t}\n\treturn GF_EXIT_GAME;\n}\n\nvoid __cdecl CheckCheatMode() {\n\tstatic int mode = 0;\n\tstatic int turn = 0;\n\tstatic __int16 angle = 0;\n\tstatic bool isFlare = false;\n\t__int16 as = LaraItem->currentAnimState;\n\n\t// Cheat is disabled in Lara home and final level\n\tif( CurrentLevel == 0 || CurrentLevel == GF_GameFlow.num_Levels-GF_GameFlow.num_Demos-1 )\n\t\treturn;\n\n\tswitch( mode ) {\n\n\t\tcase 0:\n\t\t\t// Any State -> Step forward\n\t\t\tif( as == AS_WALK )\n\t\t\t\tmode = 1;\n\t\t\tbreak;\n\n\t\tcase 1 :\n\t\t\t// Check flare\n\t\t\tisFlare = ( Lara.gun_type == LGT_Flare );\n\t\t\t// Step forward -> Stop\n\t\t\tif( as != AS_WALK )\n\t\t\t\tmode = ( as == AS_STOP ) ? 2 : 0;\n\t\t\tbreak;\n\n\t\tcase 2 :\n\t\t\t// Stop -> Step back\n\t\t\tif( as != AS_STOP )\n\t\t\t\tmode = ( as == AS_BACK ) ? 3 : 0;\n\t\t\tbreak;\n\n\t\tcase 3 :\n\t\t\t// Step back -> Stop\n\t\t\tif( as != AS_BACK )\n\t\t\t\tmode = ( as == AS_STOP ) ? 4 : 0;\n\t\t\tbreak;\n\n\t\tcase 4 :\n\t\t\t// Stop -> Start turn left / right\n\t\t\tif( as != AS_STOP ) {\n\t\t\t\tturn = 0;\n\t\t\t\tangle = LaraItem->pos.rotY;\n\t\t\t\tmode = ( as == AS_TURN_L ) ? 5 : ( as == AS_TURN_R ) ? 6 : 0;\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 5 :\n\t\t\t// Continue turn left (required at least 518 degrees / 1.44 spins)\n\t\t\tif( as == AS_TURN_L || as == AS_FASTTURN ) {\n\t\t\t\tturn += (__int16)(LaraItem->pos.rotY - angle);\n\t\t\t\tangle = LaraItem->pos.rotY;\n\t\t\t} else {\n\t\t\t\tmode = ( turn < -0x17000 ) ? 7 : 0;\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 6 :\n\t\t\t// Continue turn right (required at least 518 degrees / 1.44 spins)\n\t\t\tif ( as == AS_TURN_R || as == AS_FASTTURN ) {\n\t\t\t\tturn += (__int16)(LaraItem->pos.rotY - angle);\n\t\t\t\tangle = LaraItem->pos.rotY;\n\t\t\t} else {\n\t\t\t\tmode = ( turn > 0x17000 ) ? 7 : 0;\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 7 :\n\t\t\t// Stop -> Start jump\n\t\t\tif( as != AS_STOP )\n\t\t\t\tmode = ( as == AS_COMPRESS ) ? 8 : 0;\n\t\t\tbreak;\n\n\t\tcase 8 :\n\t\t\t// Start falling\n\t\t\tif( LaraItem->fallSpeed > 0 ) {\n\t\t\t\t// Check if jump interrupted\n\t\t\t\tif( as != AS_FORWARDJUMP && as != AS_BACKJUMP ) {\n\t\t\t\t\t// Finish cheat sequence with no action\n\t\t\t\t} // Check if flare is not active\n\t\t\t\telse if( !isFlare || Lara.gun_type != LGT_Flare ) {\n\t\t\t\t\t// Explode Lara!\n\t\t\t\t\tExplodingDeath(Lara.item_number, 0xFFFFFFFF, 1);\n\t\t\t\t\tLaraItem->hitPoints = 0;\n\t\t\t\t\tLaraItem->flags |= IFL_INVISIBLE;\n#ifdef FEATURE_INPUT_IMPROVED\n\t\t\t\t\tJoyRumbleExplode(LaraItem->pos.x, LaraItem->pos.y, LaraItem->pos.z, 0x1400, true);\n#endif // FEATURE_INPUT_IMPROVED\n\t\t\t\t} // Check jump forward\n\t\t\t\telse if( as == AS_FORWARDJUMP ) {\n\t\t\t\t\t// Complete level\n\t\t\t\t\tIsLevelComplete = TRUE;\n\t\t\t\t} // Check jump backward\n\t\t\t\telse if( as == AS_BACKJUMP ) {\n\t\t\t\t\t// Give weapon and ammo\n\t\t\t\t\t// NOTE: additional weapon availability checks not presented in the original game\n\t\t\t\t\tif( Objects[ID_SHOTGUN_OPTION].loaded ) {\n\t\t\t\t\t\tif( !Inv_RequestItem(ID_SHOTGUN_ITEM) ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_SHOTGUN_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tLara.shotgun_ammo = SaveGame.bonusFlag ? 10001 : 500;\n\t\t\t\t\t}\n\t\t\t\t\tif( Objects[ID_MAGNUM_OPTION].loaded ) {\n\t\t\t\t\t\tif( !Inv_RequestItem(ID_MAGNUM_ITEM) ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_MAGNUM_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tLara.magnum_ammo = SaveGame.bonusFlag ? 10001 : 500;\n\t\t\t\t\t}\n\t\t\t\t\tif( Objects[ID_UZI_OPTION].loaded ) {\n\t\t\t\t\t\tif( !Inv_RequestItem(ID_UZI_ITEM) ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_UZI_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tLara.uzi_ammo = SaveGame.bonusFlag ? 10001 : 5000;\n\t\t\t\t\t}\n\t\t\t\t\tif( Objects[ID_HARPOON_OPTION].loaded ) {\n\t\t\t\t\t\tif( !Inv_RequestItem(ID_HARPOON_ITEM) ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_HARPOON_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tLara.harpoon_ammo = SaveGame.bonusFlag ? 10001 : 5000;\n\t\t\t\t\t}\n\t\t\t\t\tif( Objects[ID_M16_OPTION].loaded ) {\n\t\t\t\t\t\tif( !Inv_RequestItem(ID_M16_ITEM) ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_M16_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tLara.m16_ammo = SaveGame.bonusFlag ? 10001 : 5000;\n\t\t\t\t\t}\n\t\t\t\t\tif( Objects[ID_GRENADE_OPTION].loaded ) {\n\t\t\t\t\t\tif( !Inv_RequestItem(ID_GRENADE_ITEM) ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_GRENADE_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tLara.grenade_ammo = SaveGame.bonusFlag ? 10001 : 5000;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Give medipacks and flares\n\t\t\t\t\tfor( int i=0; i<50; ++i ) {\n\t\t\t\t\t\t// NOTE: there are no limits in the original code, but it works wrong without limits\n\t\t\t\t\t\tif( Objects[ID_SMALL_MEDIPACK_OPTION].loaded && Inv_RequestItem(ID_SMALL_MEDIPACK_ITEM) < 240 ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_SMALL_MEDIPACK_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif( Objects[ID_LARGE_MEDIPACK_OPTION].loaded && Inv_RequestItem(ID_LARGE_MEDIPACK_ITEM) < 240 ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_LARGE_MEDIPACK_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif( Objects[ID_FLARES_OPTION].loaded && Inv_RequestItem(ID_FLARE_ITEM) < 240 ) {\n\t\t\t\t\t\t\tInv_AddItem(ID_FLARE_ITEM);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Play SFX\n\t\t\t\t\tPlaySoundEffect(7, NULL, SFX_ALWAYS);\n\t\t\t\t}\n\t\t\t\tmode = 0;\n\t\t\t}\n\t\t\tbreak;\n\n\t\tdefault :\n\t\t\tmode = 0;\n\t\t\tbreak;\n\t}\n}\n\nvoid __cdecl S_SaveSettings() {\n\tOpenGameRegistryKey(REG_GAME_KEY);\n\tSetRegistryDwordValue(REG_MUSIC_VOLUME, MusicVolume);\n\tSetRegistryDwordValue(REG_SOUND_VOLUME, SoundVolume);\n\tSetRegistryDwordValue(REG_DETAIL_LEVEL, DetailLevel);\n\n#ifndef FEATURE_NOLEGACY_OPTIONS\n\tSetRegistryFloatValue(REG_GAME_SIZER, GameSizer);\n#endif // FEATURE_NOLEGACY_OPTIONS\n#ifdef FEATURE_HUD_IMPROVED\n\tSetRegistryBinaryValue(REG_GAME_JOY_LAYOUT, Layout[CTRL_Joystick].key, sizeof(CONTROL_LAYOUT));\n\tSetRegistryBinaryValue(REG_GAME_KBD_LAYOUT, Layout[CTRL_Custom].key, sizeof(CONTROL_LAYOUT));\n\tSetRegistryBoolValue(REG_JOYSTICK_HINTS, JoystickHintsEnabled);\n#else // FEATURE_HUD_IMPROVED\n\tSetRegistryBinaryValue(REG_GAME_LAYOUT, (LPBYTE)Layout[CTRL_Custom].key, sizeof(CONTROL_LAYOUT));\n#endif // FEATURE_HUD_IMPROVED\n#ifdef FEATURE_INPUT_IMPROVED\n\tSetRegistryBoolValue(REG_JOYSTICK_VIBRATION, JoystickVibrationEnabled);\n#endif // FEATURE_INPUT_IMPROVED\n\tCloseGameRegistryKey();\n\n#ifdef FEATURE_VIEW_IMPROVED\n\tOpenGameRegistryKey(REG_VIEW_KEY);\n\tSetRegistryFloatValue(REG_DRAW_DISTANCE, ViewDistanceFactor);\n\tSetRegistryFloatValue(REG_FOG_BEGIN, FogBeginFactor);\n\tSetRegistryFloatValue(REG_FOG_END, FogEndFactor);\n\tSetRegistryFloatValue(REG_UW_FOG_BEGIN, WaterFogBeginFactor);\n\tSetRegistryFloatValue(REG_UW_FOG_END, WaterFogEndFactor);\n\tCloseGameRegistryKey();\n#endif // FEATURE_VIEW_IMPROVED\n}\n\nvoid __cdecl S_LoadSettings() {\n\tDWORD soundVol = 0;\n\tDWORD musicVol = 0;\n\n\tOpenGameRegistryKey(REG_GAME_KEY);\n\tGetRegistryDwordValue(REG_MUSIC_VOLUME, &musicVol, 10); // NOTE: There was bug in the original code. 165 instead of 10.\n\tGetRegistryDwordValue(REG_SOUND_VOLUME, &soundVol, 10);\n\tGetRegistryDwordValue(REG_DETAIL_LEVEL, &DetailLevel, 1);\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tGameSizer = 1.0;\n#else // FEATURE_NOLEGACY_OPTIONS\n\tGetRegistryFloatValue(REG_GAME_SIZER, &GameSizer, 1.0);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n#ifdef FEATURE_HUD_IMPROVED\n\tGetRegistryBinaryValue(REG_GAME_JOY_LAYOUT, Layout[CTRL_Joystick].key, sizeof(CONTROL_LAYOUT), NULL);\n\tif( !GetRegistryBinaryValue(REG_GAME_KBD_LAYOUT, Layout[CTRL_Custom].key, sizeof(CONTROL_LAYOUT), NULL) ) {\n\t\tUINT16 legacy[14];\n\t\tif( GetRegistryBinaryValue(REG_GAME_LAYOUT, (LPBYTE)legacy, sizeof(legacy), NULL) ) {\n\t\t\t// migrate the legacy keyboard Layout to the new one\n\t\t\tUINT16 remap[14] = {0,1,2,3,4,5, 7,8,9, 11,12,13, 10,14};\n\t\t\tfor( int i=0; i<14; ++i ) {\n\t\t\t\tif( legacy[i] < 0x100 ) {\n\t\t\t\t\tLayout[CTRL_Custom].key[remap[i]] = legacy[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tGetRegistryDwordValue(REG_DEMOTEXT_MODE, &DemoTextMode, 0);\n\tGetRegistryDwordValue(REG_JOYSTICK_BTN_STYLE, &JoystickButtonStyle, 0);\n\tGetRegistryDwordValue(REG_SAVEGAME_SLOTS, &SavegameSlots, 0);\n\tGetRegistryDwordValue(REG_INVTEXTBOX_MODE, &InvTextBoxMode, 1);\n\tGetRegistryDwordValue(REG_HEALTHBAR_MODE, &HealthBarMode, 2);\n\tGetRegistryBoolValue(REG_PSXBARPOS_ENABLE, &PsxBarPosEnabled, true);\n\tGetRegistryBoolValue(REG_JOYSTICK_HINTS, &JoystickHintsEnabled, true);\n\tGetRegistryFloatValue(REG_GAME_GUI_SCALE, &GameGUI_Scale, 1.0);\n\tGetRegistryFloatValue(REG_INV_GUI_SCALE, &InvGUI_Scale, 1.0);\n\tif( JoystickButtonStyle > 3 ) {\n\t\tJoystickButtonStyle = 0;\n\t}\n\tCLAMP(SavegameSlots, 16, 24);\n\tCLAMP(GameGUI_Scale, 0.5, 2.0);\n\tCLAMP(InvGUI_Scale, 0.5, 2.0);\n#else // FEATURE_HUD_IMPROVED\n\tGetRegistryBinaryValue(REG_GAME_LAYOUT, (LPBYTE)Layout[CTRL_Custom].key, sizeof(CONTROL_LAYOUT), NULL);\n#endif // FEATURE_HUD_IMPROVED\n\n#ifdef FEATURE_INPUT_IMPROVED\n\tGetRegistryBoolValue(REG_WALK_TO_SIDESTEP, &WalkToSidestep, false);\n\tGetRegistryBoolValue(REG_JOYSTICK_VIBRATION, &JoystickVibrationEnabled, true);\n\tGetRegistryBoolValue(REG_JOYSTICK_LED_COLOR, &JoystickLedColorEnabled, true);\n#endif // FEATURE_INPUT_IMPROVED\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tGetRegistryDwordValue(REG_INVBGND_MODE, &InvBackgroundMode, 2);\n\tGetRegistryDwordValue(REG_STATSBGND_MODE, &StatsBackgroundMode, 0);\n\tGetRegistryDwordValue(REG_PAUSEBGND_MODE, &PauseBackgroundMode, 1);\n\tGetRegistryDwordValue(REG_PICTURE_STRETCH, &PictureStretchLimit, 10);\n\tGetRegistryBoolValue(REG_REMASTER_PIX_ENABLE, &RemasteredPixEnabled, true);\n\tGetRegistryBoolValue(REG_LOADING_SCREENS, &LoadingScreensEnabled, true);\n\tGetRegistryStringValue(REG_PICTURE_SUFFIX, PictureSuffix, sizeof(PictureSuffix), \"\");\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tGetRegistryDwordValue(REG_SHADOW_MODE, &ShadowMode, 1);\n\tGetRegistryDwordValue(REG_ALPHABLEND_MODE, &AlphaBlendMode, 2);\n\tGetRegistryDwordValue(REG_REFLECTION_MODE, &ReflectionMode, 2);\n\tGetRegistryDwordValue(REG_PICKUPITEM_MODE, &PickupItemMode, 1);\n\tGetRegistryBoolValue(REG_CUSTOM_WATER_COLOR, &CustomWaterColorEnabled, true);\n\tCLAMPG(AlphaBlendMode, 2);\n\tCLAMPG(ReflectionMode, 3);\n#endif // FEATURE_VIDEOFX_IMPROVED\n\n#ifdef FEATURE_SCREENSHOT_IMPROVED\n\tGetRegistryDwordValue(REG_SCREENSHOT_FORMAT, &ScreenshotFormat, 1);\n\tGetRegistryStringValue(REG_SCREENSHOT_PATH, ScreenshotPath, sizeof(ScreenshotPath), \".\\\\screenshots\");\n#endif // FEATURE_SCREENSHOT_IMPROVED\n\n#ifdef FEATURE_ASSAULT_SAVE\n\tGetRegistryBinaryValue(REG_GAME_ASSAULT, (LPBYTE)&Assault, sizeof(Assault), NULL);\n\tif( Assault.bestTime[0] > 0 ) {\n\t\tAssaultBestTime = Assault.bestTime[0];\n\t}\n#endif // FEATURE_ASSAULT_SAVE\n\n#ifdef FEATURE_AUDIO_IMPROVED\n\tGetRegistryFloatValue(REG_INV_MUSIC_MUTE, &InventoryMusicMute, 0.8);\n\tGetRegistryFloatValue(REG_UW_MUSIC_MUTE, &UnderwaterMusicMute, 0.8);\n\tCLAMP(InventoryMusicMute, 0.0, 1.0);\n\tCLAMP(UnderwaterMusicMute, 0.0, 1.0);\n#endif // FEATURE_AUDIO_IMPROVED\n\n#ifdef FEATURE_VIEW_IMPROVED\n\tGetRegistryBoolValue(REG_PSXFOV_ENABLE, &PsxFovEnabled, false);\n#endif // FEATURE_VIEW_IMPROVED\n\n#ifdef FEATURE_MOD_CONFIG\n\tGetRegistryBoolValue(REG_BAREFOOT_SFX_ENABLE, &BarefootSfxEnabled, true);\n#endif // FEATURE_MOD_CONFIG\n\n#ifdef FEATURE_GOLD\n\tif( IsGold() ) {\n\t\t// This RJF check is presented in \"The Golden Mask\" only\n\t\tDWORD rjf = 0;\n\t\tGetRegistryDwordValue(\"RJF\", &rjf, 0);\n\t\tif( rjf == 150868 ) {\n\t\t\tGF_GameFlow.flags |= GFF_SelectAnyLevel;\n\t\t} else {\n\t\t\tDeleteRegistryValue(\"RJF\");\n\t\t}\n\t}\n#endif // FEATURE_GOLD\n\n\tCloseGameRegistryKey();\n\n\t// NOTE: There was no such call in the original code, which produces control configuration bugs\n\tDefaultConflict();\n\n\t// NOTE: There was no such volume range check in the original game\n\tSoundVolume = (soundVol > 10) ? 10 : soundVol;\n\tMusicVolume = (musicVol > 10) ? 10 : musicVol;\n\tS_SoundSetMasterVolume(6 * SoundVolume + 4);\t// 4,  10,  16,  22,  28,  34,  40,  46,  52,  58,  64\n\tS_CDVolume(MusicVolume ? MusicVolume*25+5 : 0);\t// 0,  30,  55,  80, 105, 130, 155, 180, 205, 230, 255\n\n#ifdef FEATURE_GAMEPLAY_FIXES\n\tOpenGameRegistryKey(REG_BUGS_KEY);\n\tGetRegistryBoolValue(REG_RUNNING_M16_FIX, &IsRunningM16fix, false);\n\tGetRegistryBoolValue(REG_LOWCEILING_JUMP_FIX, &IsLowCeilingJumpFix, true);\n\tCloseGameRegistryKey();\n#endif // FEATURE_GAMEPLAY_FIXES\n\n#ifdef FEATURE_VIEW_IMPROVED\n\tOpenGameRegistryKey(REG_VIEW_KEY);\n\tGetRegistryFloatValue(REG_DRAW_DISTANCE, &ViewDistanceFactor, 6.0);\n\tGetRegistryFloatValue(REG_FOG_BEGIN, &FogBeginFactor, 1.0);\n\tGetRegistryFloatValue(REG_FOG_END, &FogEndFactor, 6.0);\n\tGetRegistryFloatValue(REG_UW_FOG_BEGIN, &WaterFogBeginFactor, 0.6);\n\tGetRegistryFloatValue(REG_UW_FOG_END, &WaterFogEndFactor, 1.0);\n\tCloseGameRegistryKey();\n\n\tCLAMP(ViewDistanceFactor, 1.0, 6.0);\n\tCLAMP(FogEndFactor, 0.0, ViewDistanceFactor);\n\tCLAMP(FogBeginFactor, 0.0, FogEndFactor);\n\tCLAMP(WaterFogEndFactor, 0.0, FogEndFactor);\n\tCLAMP(WaterFogBeginFactor, 0.0, FogBeginFactor);\n\n\tsetup_screen_size();\n#endif // FEATURE_VIEW_IMPROVED\n}\n\n// NOTE: this function is presented in the \"Golden Mask\" only\nvoid __cdecl EnableLevelSelect() {\n#ifdef FEATURE_GOLD\n\tif( IsGold() ) {\n\t\tOpenGameRegistryKey(REG_GAME_KEY);\n\t\t// NOTE: It seems that RJF=150868 refers to\n\t\t// Richard J. Flower (\"The Golden Mask\" programmer)\n\t\t// and probably his birthday on August 15th, 1968.\n\t\tSetRegistryDwordValue(\"RJF\", 150868);\n\t\tGF_GameFlow.flags |= GFF_SelectAnyLevel;\n\t\tCloseGameRegistryKey();\n\t}\n#endif // FEATURE_GOLD\n}\n\n/*\n * Inject function\n */\nvoid Inject_SMain() {\n\tINJECT(0x00454B10, GameMain);\n\tINJECT(0x00454DE0, TitleSequence);\n\tINJECT(0x00454EF0, CheckCheatMode);\n\tINJECT(0x00455250, S_SaveSettings);\n\tINJECT(0x004552D0, S_LoadSettings);\n}\n"
  },
  {
    "path": "specific/smain.h",
    "content": "/*\n * Copyright (c) 2017-2019 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SMAIN_H_INCLUDED\n#define SMAIN_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nBOOL __cdecl GameMain(); // 0x00454B10\n__int16 __cdecl TitleSequence(); // 0x00454DE0\nvoid __cdecl CheckCheatMode(); // 0x00454EF0\nvoid __cdecl S_SaveSettings(); // 0x00455250\nvoid __cdecl S_LoadSettings(); // 0x004552D0\nvoid __cdecl EnableLevelSelect(); // tomb2gold:0x00455960\n\n#endif // SMAIN_H_INCLUDED\n"
  },
  {
    "path": "specific/sndpc.cpp",
    "content": "/*\n * Copyright (c) 2017 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/sndpc.h\"\n#include \"game/sound.h\"\n#include \"specific/file.h\"\n#include \"specific/init_sound.h\"\n#include \"specific/utils.h\"\n#include \"global/resource.h\"\n#include \"global/vars.h\"\n\n#ifdef FEATURE_AUDIO_IMPROVED\ndouble InventoryMusicMute = 0.8;\ndouble UnderwaterMusicMute = 0.8;\n#endif // FEATURE_AUDIO_IMPROVED\n\n#ifdef FEATURE_PAULD_CDAUDIO\n#include \"modding/cd_pauld.h\"\nstatic bool PaulD_isActive = false;\n#endif // FEATURE_PAULD_CDAUDIO\n\n// NOTE: There is no such flag in the original game.\n// It is added to provide additional protection against crashes\nstatic bool isCDAudioEnabled = false;\n// NOTE: this variable is absent in the original game\nstatic DWORD CDVolume = 0;\n\nint __cdecl S_SoundPlaySample(int channel, UINT16 volume, int pitch, int pan) {\n\tif( !SoundIsActive )\n\t\treturn -3;\n\n\tint calcPan = S_Sound_CalculateSamplePan(pan);\n\tint calcVolume = S_Sound_CalculateSampleVolume(volume);\n\treturn WinSndPlaySample(channel, calcVolume, pitch, calcPan, 0);\n}\n\nint __cdecl S_Sound_CalculateSampleVolume(DWORD volume) {\n\treturn (int)(((double)(S_MasterVolume * volume)/0x200000.p0 - 1.0) * 5000.0);\n}\n\nint __cdecl S_Sound_CalculateSamplePan(__int16 pan) {\n\treturn pan/16;\n}\n\nint __cdecl S_SoundPlaySampleLooped(int channel, UINT16 volume, DWORD pitch, int pan) {\n\tif( !SoundIsActive )\n\t\treturn -3;\n\n\tint calcPan = S_Sound_CalculateSamplePan(pan);\n\tint calcVolume = S_Sound_CalculateSampleVolume(volume);\n\treturn WinSndPlaySample(channel, calcVolume, pitch, calcPan, DSBPLAY_LOOPING);\n}\n\nvoid __cdecl S_SoundSetPanAndVolume(int channel, int pan, UINT16 volume) {\n\tif( SoundIsActive ) {\n\t\tint calcPan = S_Sound_CalculateSamplePan(pan);\n\t\tint calcVolume = S_Sound_CalculateSampleVolume(volume);\n\t\tWinSndAdjustVolumeAndPan(channel, calcVolume, calcPan);\n\t}\n}\n\nvoid __cdecl S_SoundSetPitch(int channel, DWORD pitch) {\n\tif( SoundIsActive )\n\t\tWinSndAdjustPitch(channel, pitch);\n}\n\nvoid __cdecl S_SoundSetMasterVolume(DWORD volume) {\n\tS_MasterVolume = volume;\n}\n\nvoid __cdecl S_SoundStopSample(int channel) {\n\tif( SoundIsActive )\n\t\tWinSndStopSample(channel);\n}\n\nvoid __cdecl S_SoundStopAllSamples() {\n\tif( SoundIsActive )\n\t\tfor( DWORD i=0; i<32; ++i )\n\t\t\tWinSndStopSample(i);\n}\n\nBOOL __cdecl S_SoundSampleIsPlaying(int channel) {\n\tif( !SoundIsActive )\n\t\treturn FALSE;\n\n\treturn WinSndIsChannelPlaying(channel);\n}\n\nbool __cdecl CD_Init() {\n\tMCI_OPEN_PARMS openParams;\n\tMCI_SET_PARMS setParams;\n\n#ifndef FEATURE_NOCD_DATA\n\twhile( !SelectDrive() ) {\n\t\tif( !CD_NoteAlert(MAKEINTRESOURCE(IDD_CD_PROMPT), HGameWindow) )\n\t\t\treturn false;\n\t}\n#endif // !FEATURE_NOCD_DATA\n\n#ifdef FEATURE_PAULD_CDAUDIO\n\tPaulD_isActive = PaulD_CD_Init();\n\tif( PaulD_isActive ) return true;\n#endif // FEATURE_PAULD_CDAUDIO\n\n\tif( isCDAudioEnabled )\n\t\treturn true;\n\n\topenParams.lpstrDeviceType = \"cdaudio\";\n\tif( 0 == mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, (DWORD_PTR)&openParams) ) {\n\t\tMciDeviceID = openParams.wDeviceID;\n\t\tsetParams.dwTimeFormat = MCI_FORMAT_TMSF;\n\t\tmciSendCommand(MciDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&setParams);\n\t\tisCDAudioEnabled = true;\n\t}\n\treturn true;\n}\n\nvoid __cdecl CD_Cleanup() {\n\tMCI_GENERIC_PARMS params;\n\n#ifdef FEATURE_PAULD_CDAUDIO\n\tif( PaulD_isActive ) {\n\t\tPaulD_CD_Cleanup();\n\t\treturn;\n\t}\n#endif // FEATURE_PAULD_CDAUDIO\n\n\tif( !isCDAudioEnabled )\n\t\treturn;\n\n\tmciSendCommand(MciDeviceID, MCI_STOP, 0, (DWORD_PTR)&params);\n\tmciSendCommand(MciDeviceID, MCI_CLOSE, 0, (DWORD_PTR)&params);\n\tisCDAudioEnabled = false;\n}\n\nvoid __cdecl S_CDLoop() {\n\tint rc;\n\tMCI_PLAY_PARMS playParams;\n\tMCI_STATUS_PARMS statusParams;\n\n#ifdef FEATURE_PAULD_CDAUDIO\n\tif( PaulD_isActive ) {\n\t\tPaulD_CDLoop();\n\t\treturn;\n\t}\n#endif // FEATURE_PAULD_CDAUDIO\n\n\tif( CD_LoopTrack == 0 || ++CD_LoopCounter < 150 )\n\t\treturn;\n\n\tCD_LoopCounter = 0;\n\tstatusParams.dwItem = MCI_STATUS_MODE;\n\trc = mciSendCommand(MciDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&statusParams);\n\tif( (rc == 0) && (statusParams.dwReturn == MCI_MODE_STOP) ) {\n\t\tplayParams.dwFrom = CD_LoopTrack;\n\t\tplayParams.dwTo = CD_LoopTrack + 1;\n\t\tmciSendCommand(MciDeviceID, MCI_PLAY, MCI_NOTIFY_FAILURE|MCI_NOTIFY_ABORTED, (DWORD_PTR)&playParams);\n\t}\n}\n\nvoid __cdecl S_CDPlay(__int16 trackID, BOOL isLooped) {\n\t__int16 track;\n\tMCI_PLAY_PARMS playParams;\n\n#ifdef FEATURE_PAULD_CDAUDIO\n\tif( PaulD_isActive ) {\n\t\tPaulD_CDPlay(trackID, isLooped);\n\t\treturn;\n\t}\n#endif // FEATURE_PAULD_CDAUDIO\n\n\tif( MusicVolume == 0 )\n\t\treturn;\n\n\tCD_TrackID = trackID;\n\ttrack = GetRealTrack(trackID);\n\tplayParams.dwFrom = track;\n\tplayParams.dwTo = track + 1;\n\tmciSendCommand(MciDeviceID, MCI_PLAY, MCI_NOTIFY_FAILURE|MCI_NOTIFY_ABORTED, (DWORD_PTR)&playParams);\n\n\tif( isLooped ) {\n\t\tCD_LoopTrack = track;\n\t\tCD_LoopCounter = 120;\n\t}\n}\n\nvoid __cdecl S_CDStop() {\n\tMCI_GENERIC_PARMS params;\n\n#ifdef FEATURE_PAULD_CDAUDIO\n\tif( PaulD_isActive ) {\n\t\tPaulD_CDStop();\n\t\treturn;\n\t}\n#endif // FEATURE_PAULD_CDAUDIO\n\n\tif( CD_TrackID > 0 ) {\n\t\tmciSendCommand(MciDeviceID, MCI_STOP, 0, (DWORD_PTR)&params);\n\t\tCD_TrackID = 0;\n\t\tCD_LoopTrack = 0;\n\t}\n}\n\nBOOL __cdecl StartSyncedAudio(int trackID) {\n\t__int16 track;\n\tMCI_PLAY_PARMS playParams;\n\tMCI_SET_PARMS setParams;\n\n#ifdef FEATURE_PAULD_CDAUDIO\n\tif( PaulD_isActive )\n\t\treturn PaulD_StartSyncedAudio(trackID);\n#endif // FEATURE_PAULD_CDAUDIO\n\n\tCD_TrackID = trackID;\n\ttrack = GetRealTrack(trackID);\n\n\tsetParams.dwTimeFormat = MCI_FORMAT_TMSF;\n\tif( 0 != mciSendCommand(MciDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&setParams) )\n\t\treturn FALSE;\n\n\tplayParams.dwFrom = track;\n\tplayParams.dwTo = track + 1;\n\treturn ( 0 == mciSendCommand(MciDeviceID, MCI_PLAY, MCI_NOTIFY_FAILURE|MCI_NOTIFY_ABORTED, (DWORD_PTR)&playParams) );\n}\n\nDWORD __cdecl S_CDGetLoc() {\n\tDWORD pos;\n\tMCI_STATUS_PARMS statusParams;\n\n#ifdef FEATURE_PAULD_CDAUDIO\n\tif( PaulD_isActive )\n\t\treturn PaulD_CDGetLoc();\n#endif // FEATURE_PAULD_CDAUDIO\n\n\tstatusParams.dwItem = MCI_STATUS_POSITION;\n\tif( 0 != mciSendCommand(MciDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&statusParams) )\n\t\treturn 0;\n\n\tpos = statusParams.dwReturn;\n\t// calculate audio frames position (75 audio frames per second)\n\treturn (MCI_TMSF_MINUTE(pos)*60 + MCI_TMSF_SECOND(pos))*75 + MCI_TMSF_FRAME(pos);\n}\n\nvoid __cdecl S_CDVolume(DWORD volume) {\n\tAUXCAPS caps;\n\tbool isVolumeSet = false;\n\tUINT deviceID = (UINT)(-1);\n\tUINT auxDevCount = auxGetNumDevs();\n\tCDVolume = volume; // NOTE: store current CD Audio volume\n\n#ifdef FEATURE_PAULD_CDAUDIO\n\tif( PaulD_isActive ) {\n\t\tPaulD_CDVolume(volume);\n\t\treturn;\n\t}\n#endif // FEATURE_PAULD_CDAUDIO\n\n\tif( auxDevCount == 0)\n\t\treturn;\n\n\tvolume *= 0x100; // 0 .. 255 -> 0..65280\n\n\tfor( UINT i=0; i<auxDevCount; ++i ) {\n\t\tauxGetDevCaps(i, &caps, sizeof(AUXCAPS));\n\n\t\tswitch( caps.wTechnology ) {\n\t\t\tcase AUXCAPS_CDAUDIO :\n\t\t\t\tauxSetVolume(i, MAKELONG(volume, volume));\n\t\t\t\tisVolumeSet = true;\n\t\t\t\tbreak;\n\n\t\t\tcase AUXCAPS_AUXIN :\n\t\t\t\tdeviceID = i;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tif( !isVolumeSet && deviceID != (UINT)(-1) )\n\t\tauxSetVolume(deviceID, MAKELONG(volume, volume));\n}\n\nDWORD __cdecl S_GetCDVolume() {\n\treturn CDVolume;\n}\n\n/*\n * Inject function\n */\nvoid Inject_SndPC() {\n\tINJECT(0x004553B0, S_SoundPlaySample);\n\tINJECT(0x00455400, S_Sound_CalculateSampleVolume);\n\tINJECT(0x00455430, S_Sound_CalculateSamplePan);\n\tINJECT(0x00455460, S_SoundPlaySampleLooped);\n\tINJECT(0x004554B0, S_SoundSetPanAndVolume);\n\tINJECT(0x004554F0, S_SoundSetPitch);\n\tINJECT(0x00455510, S_SoundSetMasterVolume);\n\tINJECT(0x00455520, S_SoundStopSample);\n\tINJECT(0x00455540, S_SoundStopAllSamples);\n\tINJECT(0x00455550, S_SoundSampleIsPlaying);\n\tINJECT(0x00455570, CD_Init);\n\tINJECT(0x00455600, CD_Cleanup);\n\tINJECT(0x00455640, S_CDLoop);\n\tINJECT(0x004556E0, S_CDPlay);\n\tINJECT(0x00455760, S_CDStop);\n\tINJECT(0x004557A0, StartSyncedAudio);\n\tINJECT(0x00455830, S_CDGetLoc);\n\tINJECT(0x004558A0, S_CDVolume);\n}\n"
  },
  {
    "path": "specific/sndpc.h",
    "content": "/*\n * Copyright (c) 2017 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef SNDPC_H_INCLUDED\n#define SNDPC_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nint __cdecl S_SoundPlaySample(int channel, UINT16 volume, int pitch, int pan); // 0x004553B0\nint __cdecl S_Sound_CalculateSampleVolume(DWORD volume); // 0x00455400\nint __cdecl S_Sound_CalculateSamplePan(__int16 pan); // 0x00455430\nint __cdecl S_SoundPlaySampleLooped(int channel, UINT16 volume, DWORD pitch, int pan); // 0x00455460\nvoid __cdecl S_SoundSetPanAndVolume(int channel, int pan, UINT16 volume); // 0x004554B0\nvoid __cdecl S_SoundSetPitch(int channel, DWORD pitch); // 0x004554F0\nvoid __cdecl S_SoundSetMasterVolume(DWORD volume); // 0x00455510\nvoid __cdecl S_SoundStopSample(int channel); // 0x00455520\nvoid __cdecl S_SoundStopAllSamples(); // 0x00455540\nBOOL __cdecl S_SoundSampleIsPlaying(int channel); // 0x00455550\nbool __cdecl CD_Init(); // 0x00455570\nvoid __cdecl CD_Cleanup(); // 0x00455600\nvoid __cdecl S_CDLoop(); // 0x00455640\nvoid __cdecl S_CDPlay(__int16 trackID, BOOL isLooped); // 0x004556E0\nvoid __cdecl S_CDStop(); // 0x00455760\nBOOL __cdecl StartSyncedAudio(int trackID); // 0x004557A0\nDWORD __cdecl S_CDGetLoc(); // 0x00455830\nvoid __cdecl S_CDVolume(DWORD volume); // 0x004558A0\nDWORD __cdecl S_GetCDVolume(); // NOTE: this function is not presented in the original game\n\n#endif // SNDPC_H_INCLUDED\n"
  },
  {
    "path": "specific/texture.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/texture.h\"\n#include \"3dsystem/3d_gen.h\"\n#include \"specific/hwr.h\"\n#include \"specific/winvid.h\"\n#include \"global/vars.h\"\n#include <limits.h>\n\n#ifdef FEATURE_BACKGROUND_IMPROVED\n#include \"modding/background_new.h\"\n#endif // FEATURE_BACKGROUND_IMPROVED\n\n#ifdef FEATURE_EXTENDED_LIMITS\nPHD_TEXTURE PhdTextureInfo[0x2000];\nBYTE LabTextureUVFlags[0x2000];\nBYTE *TexturePageBuffer8[128];\nHWR_TEXHANDLE HWR_PageHandles[128];\nint HWR_TexturePageIndexes[128];\n#endif // FEATURE_EXTENDED_LIMITS\n\n#if defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_BACKGROUND_IMPROVED)\nTEXPAGE_DESC TexturePages[256];\n#else // defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_BACKGROUND_IMPROVED)\nTEXPAGE_DESC TexturePages[32];\n#endif // defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_BACKGROUND_IMPROVED)\n\n#if (DIRECT3D_VERSION >= 0x900)\nRGB888 *TexturePalettes[256];\n#elif defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_BACKGROUND_IMPROVED)\nLPDIRECTDRAWPALETTE TexturePalettes[256];\n#else // defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_BACKGROUND_IMPROVED)\nLPDIRECTDRAWPALETTE TexturePalettes[16];\n#endif // defined(FEATURE_EXTENDED_LIMITS) || defined(FEATURE_BACKGROUND_IMPROVED)\n\n#ifdef FEATURE_VIDEOFX_IMPROVED\nDWORD ReflectionMode = 2;\n\n#if (DIRECT3D_VERSION >= 0x900)\nstatic LPDIRECT3DTEXTURE9 EnvmapTexture = NULL;\n#else // (DIRECT3D_VERSION >= 0x900)\nextern LPDDS EnvmapBufferSurface;\nextern LPDDS CaptureBufferSurface;\nstatic LPDIRECT3DTEXTURE2 EnvmapTexture = NULL;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\nstatic HWR_TEXHANDLE EnvmapTextureHandle = 0;\n\nstatic DWORD GetEnvmapSide() {\n\tstatic const DWORD mapside[] = {64, 256, 1024};\n\tif( ReflectionMode < 1 || ReflectionMode > 3 ) return 0;\n\tDWORD side = MIN(mapside[3 - ReflectionMode], GetMaxTextureSize());\n\tDWORD sideLimit = MIN(GameVidWidth, GameVidHeight);\n\twhile( side > sideLimit ) side >>= 1;\n\treturn side;\n}\n\n#if (DIRECT3D_VERSION >= 0x900)\nstatic bool __cdecl CreateEnvmapTexture() {\n\tif( EnvmapTexture != NULL ) FreeEnvmapTexture();\n\tDWORD side = GetEnvmapSide();\n\tif( !side ) return false;\n\tif( EnvmapTexture ) return true;\n\treturn SUCCEEDED(D3DDev->CreateTexture(side, side, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &EnvmapTexture, 0));\n}\n#else // (DIRECT3D_VERSION >= 0x900)\nstatic bool __cdecl CreateEnvmapBufferSurface() {\n\tDWORD side = GetEnvmapSide();\n\tif( !side ) return false;\n\tif( EnvmapBufferSurface ) return true;\n\n\tDDSDESC dsp;\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS;\n\tdsp.dwWidth = side;\n\tdsp.dwHeight = side;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY|DDSCAPS_TEXTURE;\n\n\tif FAILED(DDrawSurfaceCreate(&dsp, &EnvmapBufferSurface))\n\t\treturn -1;\n\n\tWinVidClearBuffer(EnvmapBufferSurface, NULL, 0);\n\treturn 0;\n}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\nvoid FreeEnvmapTexture() {\n\tif( EnvmapTexture ) {\n\t\tEnvmapTexture->Release();\n\t\tEnvmapTexture = NULL;\n\t}\n\tEnvmapTextureHandle = 0;\n}\n\nbool SetEnvmapTexture(LPDDS surface) {\n\tEnvmapTextureHandle = 0;\n\n\t// Getting centred square area of the screen\n\tint side = MIN(GameVidWidth, GameVidHeight);\n\tint x = (GameVidWidth - side) / 2;\n\tint y = (GameVidHeight - side) / 2;\n\tRECT srcRect = {\n\t\t.left\t= GameVidRect.left + x,\n\t\t.top\t= GameVidRect.top  + y,\n\t\t.right\t= GameVidRect.left + x + side,\n\t\t.bottom\t= GameVidRect.top  + y + side,\n\t};\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( EnvmapTexture == NULL && !CreateEnvmapTexture() ) return false;\n\tLPDDS texSurface = NULL;\n\n\tif SUCCEEDED(EnvmapTexture->GetSurfaceLevel(0, &texSurface)) {\n\t\tif SUCCEEDED(D3DDev->StretchRect(surface, &srcRect, texSurface, NULL, D3DTEXF_LINEAR)) {\n\t\t\tEnvmapTextureHandle = EnvmapTexture;\n\t\t}\n\t\ttexSurface->Release();\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( !CreateEnvmapBufferSurface() ) return false;\n\tif( EnvmapTexture ) FreeEnvmapTexture();\n\tEnvmapBufferSurface->Blt(NULL, surface, &srcRect, DDBLT_WAIT, NULL);\n\tEnvmapTexture = Create3DTexture(EnvmapBufferSurface);\n\tif( EnvmapTexture ) {\n\t\tEnvmapTexture->GetHandle(D3DDev, &EnvmapTextureHandle);\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\treturn ( EnvmapTextureHandle != 0 );\n}\n\nHWR_TEXHANDLE GetEnvmapTextureHandle() {\n#if (DIRECT3D_VERSION < 0x900)\n\tif( EnvmapTextureHandle ) return EnvmapTextureHandle;\n\tSetEnvmapTexture(CaptureBufferSurface ? CaptureBufferSurface : PrimaryBufferSurface);\n#endif // (DIRECT3D_VERSION < 0x900)\n\treturn EnvmapTextureHandle;\n}\n#endif // FEATURE_VIDEOFX_IMPROVED\n\nDWORD GetMaxTextureSize() {\n#if (DIRECT3D_VERSION >= 0x900)\n\treturn MIN(CurrentDisplayAdapter.caps.MaxTextureWidth, CurrentDisplayAdapter.caps.MaxTextureHeight);\n#else // (DIRECT3D_VERSION >= 0x900)\n\treturn MIN(CurrentDisplayAdapter.D3DHWDeviceDesc.dwMaxTextureWidth, CurrentDisplayAdapter.D3DHWDeviceDesc.dwMaxTextureHeight);\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nint GetTextureSideByPage(int page) {\n\tif( page < 0 ) return 256;\n\tpage = HWR_TexturePageIndexes[page];\n\tif( page < 0 ) return 256;\n\treturn TexturePages[page].width;\n}\n\nint GetTextureSideByHandle(HWR_TEXHANDLE handle) {\n\tfor( DWORD i=0; i<ARRAY_SIZE(HWR_TexturePageIndexes); ++i ) {\n\t\tif( HWR_TexturePageIndexes[i] >= 0 && HWR_PageHandles[i] == handle ) {\n\t\t\treturn TexturePages[HWR_TexturePageIndexes[i]].width;\n\t\t}\n\t}\n\treturn 256;\n}\n\nvoid __cdecl CopyBitmapPalette(RGB888 *srcPal, BYTE *srcBitmap, int bitmapSize, RGB888 *destPal) {\n\tint i, j;\n#if (DIRECT3D_VERSION < 0x900)\n\tHDC hdc;\n\tPALETTEENTRY firstSysPalEntries[10];\n\tPALETTEENTRY lastSysPalEntries[10];\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\tfor( i=0; i<256; ++i ) {\n\t\tSortBuffer[i]._0 = i;\n\t\tSortBuffer[i]._1 = 0;\n\t}\n\n\tfor( i=0; i<bitmapSize; ++i ) {\n\t\tSortBuffer[srcBitmap[i]]._1++;\n\t}\n\n\tdo_quickysorty(0, 255);\n\n#if (DIRECT3D_VERSION >= 0x900)\n\t// middle palette entries\n\tfor( j=0; j<256; ++j ) {\n\t\tdestPal[j] = srcPal[SortBuffer[j]._0];\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\thdc = GetDC(NULL);\n\tGetSystemPaletteEntries(hdc, 0,   10, firstSysPalEntries);\n\tGetSystemPaletteEntries(hdc, 246, 10, lastSysPalEntries);\n\tReleaseDC(NULL, hdc);\n\n\t// first palette entries\n\tfor( i=0; i<8; ++i ) {\n\t\tdestPal[i].red   = firstSysPalEntries[i].peRed;\n\t\tdestPal[i].green = firstSysPalEntries[i].peGreen;\n\t\tdestPal[i].blue  = firstSysPalEntries[i].peBlue;\n\t}\n\tmemset(&destPal[8], 0, 2*sizeof(RGB888));\n\n\t// middle palette entries\n\tfor( i=0, j=10; i<236; ++i, ++j ) {\n\t\tdestPal[j] = srcPal[SortBuffer[i]._0];\n\t}\n\n\t// last palette entries\n\tmemset(&destPal[246], 0, 1*sizeof(RGB888));\n\tfor( i=1, j=247; i<10; ++i, ++j ) {\n\t\tdestPal[j].red   = lastSysPalEntries[i].peRed;\n\t\tdestPal[j].green = lastSysPalEntries[i].peGreen;\n\t\tdestPal[j].blue  = lastSysPalEntries[i].peBlue;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nBYTE __cdecl FindNearestPaletteEntry(RGB888 *palette, int red, int green, int blue, bool ignoreSysPalette) {\n\tint i;\n\tint diffRed, diffGreen, diffBlue, diffTotal;\n\tint diffMin = INT_MAX;\n\tint palStartIdx = 0;\n\tint palEndIdx = 256;\n\tBYTE result = 0;\n\n#if (DIRECT3D_VERSION < 0x900)\n\tif( ignoreSysPalette ) {\n\t\tpalStartIdx += 10;\n\t\tpalEndIdx -= 10;\n\t}\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\tfor( i=palStartIdx; i<palEndIdx; ++i ) {\n\t\tdiffRed   = red   - palette[i].red;\n\t\tdiffGreen = green - palette[i].green;\n\t\tdiffBlue  = blue  - palette[i].blue;\n\t\tdiffTotal = diffRed*diffRed + diffGreen*diffGreen + diffBlue*diffBlue;\n\t\tif( diffTotal < diffMin ) {\n\t\t\tdiffMin = diffTotal;\n\t\t\tresult = i;\n\t\t}\n\t}\n\treturn result;\n}\n\nvoid __cdecl SyncSurfacePalettes(void *srcData, int width, int height, int srcPitch, RGB888 *srcPalette, void *dstData, int dstPitch, RGB888 *dstPalette, bool preserveSysPalette) {\n\tint i, j;\n\tBYTE *src, *dst;\n\tBYTE bufPalette[256];\n\n\tfor( i=0; i<256; ++i ) {\n\t\tbufPalette[i] = FindNearestPaletteEntry(dstPalette, srcPalette[i].red, srcPalette[i].green, srcPalette[i].blue, preserveSysPalette);\n\t}\n\n\tsrc = (BYTE *)srcData;\n\tdst = (BYTE *)dstData;\n\n\tfor( i=0; i<height; ++i ) {\n\t\tfor( j=0; j<width; ++j ) {\n\t\t\t*(dst++) = bufPalette[*(src++)];\n\t\t}\n\t\tsrc += srcPitch - width;\n\t\tdst += dstPitch - width;\n\t}\n}\n\nint __cdecl CreateTexturePalette(RGB888 *pal) {\n#if (DIRECT3D_VERSION >= 0x900)\n\tint palIndex = GetFreePaletteIndex();\n\tif( palIndex < 0 )\n\t\treturn -1;\n\n\tTexturePalettes[palIndex] = (RGB888 *)malloc(sizeof(RGB888) * 256);\n\tif( TexturePalettes[palIndex] == NULL )\n\t\treturn -1;\n\n\tmemcpy(TexturePalettes[palIndex], pal, sizeof(RGB888) * 256);\n\treturn palIndex;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tint palIndex;\n\tPALETTEENTRY palEntries[256];\n\n\tpalIndex = GetFreePaletteIndex();\n\tif( palIndex < 0 )\n\t\treturn -1;\n\n\tfor( int i=0; i<256; ++i ) {\n\t\tpalEntries[i].peRed   = pal[i].red;\n\t\tpalEntries[i].peGreen = pal[i].green;\n\t\tpalEntries[i].peBlue  = pal[i].blue;\n\t\tpalEntries[i].peFlags = 0;\n\t}\n\n\tif FAILED(DDraw->CreatePalette(DDPCAPS_ALLOW256|DDPCAPS_8BIT, palEntries, &TexturePalettes[palIndex], NULL))\n\t\treturn -1;\n\n\treturn palIndex;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nint __cdecl GetFreePaletteIndex() {\n\tfor( DWORD i=0; i<ARRAY_SIZE(TexturePalettes); ++i ) {\n\t\tif( TexturePalettes[i] == NULL )\n\t\t\treturn i;\n\t}\n\treturn -1;\n}\n\nvoid __cdecl FreePalette(int paletteIndex) {\n\tif( TexturePalettes[paletteIndex] != NULL ) {\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tfree(TexturePalettes[paletteIndex]);\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tTexturePalettes[paletteIndex]->Release();\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\tTexturePalettes[paletteIndex] = NULL;\n\t}\n}\n\nvoid __cdecl SafeFreePalette(int paletteIndex) {\n\tif( paletteIndex >= 0 ) {\n\t\tFreePalette(paletteIndex);\n\t}\n}\n\n#if (DIRECT3D_VERSION >= 0x900)\nint __cdecl CreateTexturePage(int width, int height, bool alpha)\n#else // (DIRECT3D_VERSION >= 0x900)\nint __cdecl CreateTexturePage(int width, int height, LPDIRECTDRAWPALETTE palette)\n#endif // (DIRECT3D_VERSION >= 0x900)\n{\n\tint pageIndex = GetFreeTexturePageIndex();\n\tif( pageIndex < 0 )\n\t\treturn -1;\n\n\tmemset(&TexturePages[pageIndex], 0, sizeof(TEXPAGE_DESC));\n\tTexturePages[pageIndex].status = 1;\n\tTexturePages[pageIndex].width = width;\n\tTexturePages[pageIndex].height = height;\n#if (DIRECT3D_VERSION >= 0x900)\n\tif FAILED(D3DDev->CreateTexture(width, height, 1, 0, alpha ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &TexturePages[pageIndex].texture, 0))\n\t\treturn -1;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tTexturePages[pageIndex].palette = palette;\n\tif( !CreateTexturePageSurface(&TexturePages[pageIndex]) )\n\t\treturn -1;\n\n\tTexturePageInit(&TexturePages[pageIndex]);\n#endif // (DIRECT3D_VERSION >= 0x900)\n\treturn pageIndex;\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl CreateTexturePageSurface(TEXPAGE_DESC *desc) {\n\tDDSDESC dsp;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_PIXELFORMAT|DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS;\n\tdsp.dwWidth  = desc->width;\n\tdsp.dwHeight = desc->height;\n\tdsp.ddpfPixelFormat = TextureFormat.pixelFmt;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_TEXTURE|DDSCAPS_SYSTEMMEMORY;\n\tif FAILED(DDrawSurfaceCreate(&dsp, &desc->sysMemSurface))\n\t\treturn false;\n\n\treturn ( (desc->palette == NULL) || SUCCEEDED(desc->sysMemSurface->SetPalette(desc->palette)) );\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nint __cdecl GetFreeTexturePageIndex() {\n\tfor( DWORD i=0; i<ARRAY_SIZE(TexturePages); ++i ) {\n\t\tif( (TexturePages[i].status & 1) == 0 )\n\t\t\treturn i;\n\t}\n\treturn -1;\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl TexturePageInit(TEXPAGE_DESC *page) {\n\tDDSDESC dsp;\n\tDDCOLORKEY colorKey;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\tdsp.dwFlags = DDSD_PIXELFORMAT|DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS;\n\tdsp.dwWidth = page->width;;\n\tdsp.dwHeight = page->height;\n\tdsp.ddpfPixelFormat = TextureFormat.pixelFmt;\n\tdsp.ddsCaps.dwCaps = DDSCAPS_ALLOCONLOAD|DDSCAPS_VIDEOMEMORY|DDSCAPS_TEXTURE;\n\n\tif( FAILED(DDrawSurfaceCreate(&dsp, &page->vidMemSurface)) || page->vidMemSurface == NULL ) {\n\t\treturn false;\n\t}\n\n\tif( page->palette ) {\n\t\tcolorKey.dwColorSpaceLowValue = 0;\n\t\tcolorKey.dwColorSpaceHighValue = 0;\n\t\tif( FAILED(page->vidMemSurface->SetPalette(page->palette)) ||\n\t\t\tFAILED(page->vidMemSurface->SetColorKey(DDCKEY_SRCBLT, &colorKey)) )\n\t\t{\n\t\t\tpage->vidMemSurface->Release();\n\t\t\tpage->vidMemSurface = NULL;\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tpage->texture3d = Create3DTexture(page->vidMemSurface);\n\tif( page->texture3d == NULL ) {\n\t\tpage->vidMemSurface->Release();\n\t\tpage->vidMemSurface = NULL;\n\t\treturn false;\n\t}\n\n\tif FAILED(page->texture3d->GetHandle(D3DDev, &page->texHandle)) {\n\t\tpage->texture3d->Release();\n\t\tpage->texture3d = NULL;\n\n\t\tpage->vidMemSurface->Release();\n\t\tpage->vidMemSurface = NULL;\n\n\t\tpage->texHandle = 0;\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nLPDIRECT3DTEXTURE2 __cdecl Create3DTexture(LPDDS surface) {\n\tLPDIRECT3DTEXTURE2 texture3d = NULL;\n\tif FAILED(surface->QueryInterface(IID_IDirect3DTexture2, (LPVOID *)&texture3d)) {\n\t\treturn NULL;\n\t}\n\treturn texture3d;\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nvoid __cdecl SafeFreeTexturePage(int pageIndex) {\n\tif( pageIndex >= 0 && (TexturePages[pageIndex].status & 1) != 0 ) {\n\t\tFreeTexturePage(pageIndex);\n\t}\n}\n\nvoid __cdecl FreeTexturePage(int pageIndex) {\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( TexturePages[pageIndex].texture != NULL ) {\n\t\tTexturePages[pageIndex].texture->Release();\n\t\tTexturePages[pageIndex].texture = NULL;\n\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\tTexturePageReleaseVidMemSurface(&TexturePages[pageIndex]);\n\n\tif( TexturePages[pageIndex].sysMemSurface != NULL ) {\n\t\tTexturePages[pageIndex].sysMemSurface->Release();\n\t\tTexturePages[pageIndex].sysMemSurface = NULL;\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\tTexturePages[pageIndex].status = 0;\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl TexturePageReleaseVidMemSurface(TEXPAGE_DESC *page) {\n\tHWR_ResetTexSource();\n\tpage->texHandle = 0;\n\tif( page->texture3d ) {\n\t\tpage->texture3d->Release();\n\t\tpage->texture3d = NULL;\n\t}\n\tif( page->vidMemSurface ) {\n\t\tpage->vidMemSurface->Release();\n\t\tpage->vidMemSurface = NULL;\n\t}\n}\n\nbool __cdecl ReloadTextures(bool reset) {\n\tbool result = true;\n\n\tfor( DWORD i=0; i<ARRAY_SIZE(TexturePages); ++i ) {\n\t\tif( (TexturePages[i].status & 1) != 0 )\n\t\t\tresult &= LoadTexturePage(i, reset);\n\t}\n\treturn result;\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nvoid __cdecl FreeTexturePages() {\n#ifdef FEATURE_VIDEOFX_IMPROVED\n\tFreeEnvmapTexture();\n#endif // FEATURE_VIDEOFX_IMPROVED\n#ifdef FEATURE_BACKGROUND_IMPROVED\n\tBGND2_CleanupCaptureTextures();\n#endif // FEATURE_BACKGROUND_IMPROVED\n\tfor( DWORD i=0; i<ARRAY_SIZE(TexturePages); ++i ) {\n\t\tif( (TexturePages[i].status & 1) != 0 )\n\t\t\tFreeTexturePage(i);\n\t}\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl LoadTexturePage(int pageIndex, bool reset) {\n\tbool rc = false;\n\n\tif( pageIndex < 0 )\n\t\treturn false;\n\n\tif( reset || TexturePages[pageIndex].vidMemSurface == NULL ) {\n\t\trc = SUCCEEDED(DDrawSurfaceRestoreLost(TexturePages[pageIndex].vidMemSurface, NULL, false));\n\t}\n\n\tif( !rc ) {\n\t\tTexturePageReleaseVidMemSurface(&TexturePages[pageIndex]);\n\t\trc = TexturePageInit(&TexturePages[pageIndex]);\n\t}\n\n\tif( !rc )\n\t\treturn false;\n\n\tDDrawSurfaceRestoreLost(TexturePages[pageIndex].sysMemSurface, NULL, false);\n\tLPDIRECT3DTEXTURE2 sysMemTexture = Create3DTexture(TexturePages[pageIndex].sysMemSurface);\n\n\tif( sysMemTexture == NULL )\n\t\treturn false;\n\n\trc = SUCCEEDED(TexturePages[pageIndex].texture3d->Load(sysMemTexture));\n\tsysMemTexture->Release();\n\n\treturn rc;\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\nHWR_TEXHANDLE __cdecl GetTexturePageHandle(int pageIndex) {\n\tif( pageIndex < 0 )\n\t\treturn 0;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\treturn TexturePages[pageIndex].texture;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( TexturePages[pageIndex].vidMemSurface &&\n\t\tTexturePages[pageIndex].vidMemSurface->IsLost() == DDERR_SURFACELOST )\n\t{\n\t\tLoadTexturePage(pageIndex, 1);\n\t}\n\n\treturn TexturePages[pageIndex].texHandle;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nint __cdecl AddTexturePage8(int width, int height, BYTE *pageBuffer, int palIndex) {\n#if (DIRECT3D_VERSION >= 0x900)\n\tint pageIndex = CreateTexturePage(width, height, true);\n\tif( pageIndex < 0 )\n\t\treturn -1;\n\n\tDDSDESC desc;\n\tif FAILED(TexturePages[pageIndex].texture->LockRect(0, &desc, NULL, 0)) {\n\t\treturn -1;\n\t}\n\tBYTE *src = pageBuffer;\n\tfor( int i=0; i<height; ++i ) {\n\t\tDWORD *dst = (DWORD *)((BYTE *)desc.pBits + desc.Pitch * i);\n\t\tfor( int j=0; j<width; ++j ) {\n\t\t\tif( *src ) {\n\t\t\t\tBYTE r = TexturePalettes[palIndex][*src].red;\n\t\t\t\tBYTE g = TexturePalettes[palIndex][*src].green;\n\t\t\t\tBYTE b = TexturePalettes[palIndex][*src].blue;\n\t\t\t\t*dst++ = RGBA_MAKE(r, g, b, 0xFF);\n\t\t\t} else {\n\t\t\t\t*dst++ = 0;\n\t\t\t}\n\t\t\t++src;\n\t\t}\n\t}\n\tTexturePages[pageIndex].texture->UnlockRect(0);\n\n\treturn pageIndex;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tint pageIndex;\n\tBYTE *src, *dst;\n\tDDSDESC desc;\n\n\tif( palIndex < 0 )\n\t\treturn -1;\n\n\tpageIndex = CreateTexturePage(width, height, TexturePalettes[palIndex]);\n\tif( pageIndex < 0 )\n\t\treturn -1;\n\n\tif FAILED(WinVidBufferLock(TexturePages[pageIndex].sysMemSurface, &desc, DDLOCK_WRITEONLY|DDLOCK_WAIT))\n\t\treturn -1;\n\n\tsrc = pageBuffer;\n\tdst = (BYTE *)desc.lpSurface;\n\tfor( int i=0; i<height; ++i ) {\n\t\tmemcpy(dst, src, width);\n\t\tsrc += width;\n\t\tdst += desc.lPitch;\n\t}\n\tWinVidBufferUnlock(TexturePages[pageIndex].sysMemSurface, &desc);\n\tLoadTexturePage(pageIndex, false);\n\n\treturn pageIndex;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nint __cdecl AddTexturePage16(int width, int height, BYTE *pageBuffer) {\n#if (DIRECT3D_VERSION >= 0x900)\n\tint pageIndex = CreateTexturePage(width, height, true);\n\tif( pageIndex < 0 )\n\t\treturn -1;\n\n\tDDSDESC desc;\n\tif FAILED(TexturePages[pageIndex].texture->LockRect(0, &desc, NULL, 0)) {\n\t\treturn -1;\n\t}\n\tUINT16 *src = (UINT16 *)pageBuffer;\n\tfor( int i=0; i<height; ++i ) {\n\t\tDWORD *dst = (DWORD *)((BYTE *)desc.pBits + desc.Pitch * i);\n\t\tfor( int j=0; j<width; ++j ) {\n\t\t\tBYTE r = ((*src >> 7) & 0xF8) | ((*src >> 13) & 0x07);\n\t\t\tBYTE g = ((*src >> 2) & 0xF8) | ((*src >>  7) & 0x07);\n\t\t\tBYTE b = ((*src << 3) & 0xF8) | ((*src >>  2) & 0x07);\n\t\t\tBYTE a = (*src & 0x8000) ? 0xFF : 0;\n\t\t\t*dst++ = RGBA_MAKE(r, g, b, a);\n\t\t\t++src;\n\t\t}\n\t}\n\tTexturePages[pageIndex].texture->UnlockRect(0);\n\n\treturn pageIndex;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tint i, j, k;\n\tint pageIndex, bytesPerPixel;\n\tBYTE *src, *dst, *subdst;\n\tBYTE srcRed, srcGreen, srcBlue, srcAlpha;\n\tDWORD compatibleColor;\n\tDDSDESC desc;\n\n\tpageIndex = CreateTexturePage(width, height, NULL);\n\tif( pageIndex < 0 )\n\t\treturn -1;\n\n\tif FAILED(WinVidBufferLock(TexturePages[pageIndex].sysMemSurface, &desc, DDLOCK_WRITEONLY|DDLOCK_WAIT))\n\t\treturn -1;\n\n\tif( TexturesHaveCompatibleMasks ) {\n\t\tsrc = (BYTE *)pageBuffer;\n\t\tdst = (BYTE *)desc.lpSurface;\n\t\tfor( i=0; i<height; ++i ) {\n\t\t\tmemcpy(dst, src, width*2);\n\t\t\tsrc += width*2;\n\t\t\tdst += desc.lPitch;\n\t\t}\n\t} else {\n\t\tsrc = pageBuffer;\n\t\tdst = (BYTE *)desc.lpSurface;\n\t\tbytesPerPixel = (TextureFormat.bpp + 7) / 8;\n\t\tfor( i=0; i<height; ++i ) {\n\t\t\tsubdst = dst;\n\t\t\tfor( j=0; j<width; ++j ) {\n\t\t\t\tsrcRed   = (*(UINT16 *)src >>  7) & 0xF8;\n\t\t\t\tsrcGreen = (*(UINT16 *)src >>  2) & 0xF8;\n\t\t\t\tsrcBlue  = (*(UINT16 *)src <<  3) & 0xF8;\n\t\t\t\tsrcAlpha = (*(UINT16 *)src >> 15) & 1;\n\t\t\t\tcompatibleColor = CalculateCompatibleColor(&TextureFormat.colorBitMasks, srcRed, srcGreen, srcBlue, srcAlpha);\n\t\t\t\tfor( k=0; k<bytesPerPixel; ++k ) {\n\t\t\t\t\t*(subdst++) = compatibleColor & 0xFF;\n\t\t\t\t\tcompatibleColor >>= 8;\n\t\t\t\t}\n\t\t\t\tsrc += 2;\n\t\t\t}\n\t\t\tdst += desc.lPitch;\n\t\t}\n\t}\n\n\tWinVidBufferUnlock(TexturePages[pageIndex].sysMemSurface, &desc);\n\tLoadTexturePage(pageIndex, false);\n\n\treturn pageIndex;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\n#if (DIRECT3D_VERSION >= 0x900)\n// NOTE: this function is not presented in the original game\nint AddTexturePage32(int width, int height, BYTE *pageBuffer, bool alpha) {\n\tint pageIndex = CreateTexturePage(width, height, alpha);\n\tif( pageIndex < 0 )\n\t\treturn -1;\n\n\tDDSDESC desc;\n\tif FAILED(TexturePages[pageIndex].texture->LockRect(0, &desc, NULL, 0)) {\n\t\treturn -1;\n\t}\n\tDWORD *src = (DWORD *)pageBuffer;\n\tfor( int i=0; i<height; ++i ) {\n\t\tDWORD *dst = (DWORD *)((BYTE *)desc.pBits + desc.Pitch * i);\n\t\tmemcpy(dst, src, sizeof(DWORD) * width);\n\t\tsrc += width;\n\t}\n\tTexturePages[pageIndex].texture->UnlockRect(0);\n\n\treturn pageIndex;\n}\n\n// NOTE: this function is not presented in the original game\nint AddExternalTexture(LPCTSTR fileName, bool alpha) {\n\tint pageIndex = GetFreeTexturePageIndex();\n\tif( pageIndex < 0 )\n\t\treturn -1;\n\n\tmemset(&TexturePages[pageIndex], 0, sizeof(TEXPAGE_DESC));\n\tHRESULT res = D3DXCreateTextureFromFileEx(D3DDev, fileName, D3DX_DEFAULT, D3DX_DEFAULT, 0,\n\t\t\t\t\t\t\t\t0, alpha ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8, D3DPOOL_MANAGED,\n\t\t\t\t\t\t\t\tD3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &TexturePages[pageIndex].texture);\n\tif FAILED(res)\n\t\treturn -1;\n\n\tD3DSURFACE_DESC desc;\n\tif FAILED(TexturePages[pageIndex].texture->GetLevelDesc(0, &desc)) {\n\t\tTexturePages[pageIndex].texture->Release();\n\t\tTexturePages[pageIndex].texture = NULL;\n\t\treturn -1;\n\t}\n\n\tTexturePages[pageIndex].status = 1|2;\n\tTexturePages[pageIndex].width = desc.Width;\n\tTexturePages[pageIndex].height = desc.Height;\n\treturn pageIndex;\n}\n\n// NOTE: this function is not presented in the original game\nbool IsExternalTexture(int page) {\n\tif (page < 0 || page >= (int)ARRAY_SIZE(HWR_TexturePageIndexes))\n\t\treturn false;\n\n\tpage = HWR_TexturePageIndexes[page];\n\tif (page < 0 || page >= (int)ARRAY_SIZE(TexturePages))\n\t\treturn false;\n\n\treturn CHK_ALL(TexturePages[page].status, 1|2);\n}\n\n#else // (DIRECT3D_VERSION >= 0x900)\nHRESULT CALLBACK EnumTextureFormatsCallback(LPDDSDESC lpDdsd, LPVOID lpContext) {\n\tLPDDPIXELFORMAT lpDDPixFmt = &lpDdsd->ddpfPixelFormat;\n\n\tif( lpDDPixFmt->dwRGBBitCount < 8 )\n\t\treturn D3DENUMRET_OK;\n\n\tif( SavedAppSettings.Disable16BitTextures || lpDDPixFmt->dwRGBBitCount < 16 ) {\n\t\tif( CHK_ANY(lpDDPixFmt->dwFlags, DDPF_PALETTEINDEXED8) ) {\n\t\t\tTextureFormat.pixelFmt = *lpDDPixFmt;\n\t\t\tTextureFormat.bpp = 8;\n\t\t\tTexturesAlphaChannel = false;\n\t\t\tif( SavedAppSettings.Disable16BitTextures ) {\n\t\t\t\tTexturesHaveCompatibleMasks = false;\n\t\t\t\treturn D3DENUMRET_CANCEL; // NOTE: not presented in the original code\n\t\t\t}\n\t\t}\n\t} else if( CHK_ANY(lpDDPixFmt->dwFlags, DDPF_RGB) ) {\n\t\tTextureFormat.pixelFmt = *lpDDPixFmt;\n\t\tTextureFormat.bpp = 16;\n\t\tTexturesAlphaChannel = CHK_ANY(lpDDPixFmt->dwFlags, DDPF_ALPHAPIXELS);\n\t\tWinVidGetColorBitMasks(&TextureFormat.colorBitMasks, lpDDPixFmt);\n\t\tif( TextureFormat.bpp == 16 &&\n\t\t\tTextureFormat.colorBitMasks.dwRGBAlphaBitDepth\t== 1  &&\n\t\t\tTextureFormat.colorBitMasks.dwRBitDepth\t\t\t== 5  &&\n\t\t\tTextureFormat.colorBitMasks.dwGBitDepth\t\t\t== 5  &&\n\t\t\tTextureFormat.colorBitMasks.dwBBitDepth\t\t\t== 5  &&\n\t\t\tTextureFormat.colorBitMasks.dwRGBAlphaBitOffset\t== 15 &&\n\t\t\tTextureFormat.colorBitMasks.dwRBitOffset\t\t== 10 &&\n\t\t\tTextureFormat.colorBitMasks.dwGBitOffset\t\t== 5  &&\n\t\t\tTextureFormat.colorBitMasks.dwBBitOffset\t\t== 0 )\n\t\t{\n\t\t\tTexturesHaveCompatibleMasks = true;\n\t\t\treturn D3DENUMRET_CANCEL;\n\t\t}\n\t}\n\n\tTexturesHaveCompatibleMasks = false;\n\treturn D3DENUMRET_OK;\n}\n\nHRESULT __cdecl EnumerateTextureFormats() {\n\tmemset(&TextureFormat, 0, sizeof(TEXTURE_FORMAT));\n\tHRESULT ret = D3DDev->EnumTextureFormats(EnumTextureFormatsCallback, NULL);\n\t// NOTE: there is no such check in the original code\n\tif( SavedAppSettings.Disable16BitTextures && TextureFormat.bpp < 8 ) {\n\t\tSavedAppSettings.Disable16BitTextures = false;\n\t\tret = D3DDev->EnumTextureFormats(EnumTextureFormatsCallback, NULL);\n\t}\n\treturn ret;\n}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\nvoid __cdecl CleanupTextures() {\n\tFreeTexturePages();\n\tfor( DWORD i=0; i<ARRAY_SIZE(TexturePalettes); ++i ) {\n\t\tif( TexturePalettes[i] != NULL )\n\t\t\tFreePalette(i);\n\t}\n}\n\nbool __cdecl InitTextures() {\n\tmemset(TexturePages,  0, sizeof(TexturePages));\n\tmemset(TexturePalettes, 0, sizeof(TexturePalettes));\n\treturn true;\n}\n\n/*\n * Inject function\n */\nvoid Inject_Texture() {\n\tINJECT(0x00455990, CopyBitmapPalette);\n\tINJECT(0x00455AD0, FindNearestPaletteEntry);\n\tINJECT(0x00455BA0, SyncSurfacePalettes);\n\tINJECT(0x00455C50, CreateTexturePalette);\n\tINJECT(0x00455CE0, GetFreePaletteIndex);\n\tINJECT(0x00455D00, FreePalette);\n\tINJECT(0x00455D30, SafeFreePalette);\n\tINJECT(0x00455EB0, CreateTexturePage);\n\tINJECT(0x00455DF0, GetFreeTexturePageIndex);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00455E10, CreateTexturePageSurface);\n\tINJECT(0x00455EB0, TexturePageInit);\n\tINJECT(0x00456030, Create3DTexture);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00456060, SafeFreeTexturePage);\n\tINJECT(0x00456080, FreeTexturePage);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x004560C0, TexturePageReleaseVidMemSurface);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00456100, FreeTexturePages);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x004561E0, ReloadTextures);\n\tINJECT(0x00456130, LoadTexturePage);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00456220, GetTexturePageHandle);\n\tINJECT(0x00456260, AddTexturePage8);\n\tINJECT(0x00456360, AddTexturePage16);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00456500, EnumTextureFormatsCallback);\n\tINJECT(0x00456620, EnumerateTextureFormats);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00456650, CleanupTextures);\n\tINJECT(0x00456660, InitTextures);\n}\n"
  },
  {
    "path": "specific/texture.h",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef TEXTURE_H_INCLUDED\n#define TEXTURE_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n// NOTE: these functions are not presented in the original game\n#ifdef FEATURE_VIDEOFX_IMPROVED\nvoid FreeEnvmapTexture();\nbool SetEnvmapTexture(LPDDS surface);\nHWR_TEXHANDLE GetEnvmapTextureHandle();\n#endif // FEATURE_VIDEOFX_IMPROVED\nDWORD GetMaxTextureSize();\nint GetTextureSideByPage(int page);\nint GetTextureSideByHandle(HWR_TEXHANDLE handle);\n\nvoid __cdecl CopyBitmapPalette(RGB888 *srcPal, BYTE *srcBitmap, int bitmapSize, RGB888 *destPal); // 0x00455990\nBYTE __cdecl FindNearestPaletteEntry(RGB888 *palette, int red, int green, int blue, bool ignoreSysPalette); // 0x00455AD0\nvoid __cdecl SyncSurfacePalettes(void *srcData, int width, int height, int srcPitch, RGB888 *srcPalette, void *dstData, int dstPitch, RGB888 *dstPalette, bool preserveSysPalette); // 0x00455BA0\nint __cdecl CreateTexturePalette(RGB888 *pal); // 0x00455C50\nint __cdecl GetFreePaletteIndex(); // 0x00455CE0\nvoid __cdecl FreePalette(int paletteIndex); // 0x00455D00\nvoid __cdecl SafeFreePalette(int paletteIndex); // 0x00455D30\n#if (DIRECT3D_VERSION >= 0x900)\nint __cdecl CreateTexturePage(int width, int height, bool alpha);\n#else // (DIRECT3D_VERSION >= 0x900)\nint __cdecl CreateTexturePage(int width, int height, LPDIRECTDRAWPALETTE palette); // 0x00455D80\n#endif // (DIRECT3D_VERSION >= 0x900)\nint __cdecl GetFreeTexturePageIndex(); // 0x00455DF0\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl CreateTexturePageSurface(TEXPAGE_DESC *desc); // 0x00455E10\nbool __cdecl TexturePageInit(TEXPAGE_DESC *page); // 0x00455EB0\nLPDIRECT3DTEXTURE2 __cdecl Create3DTexture(LPDDS surface); // 0x00456030\n#endif // (DIRECT3D_VERSION < 0x900)\nvoid __cdecl SafeFreeTexturePage(int pageIndex); // 0x00456060\nvoid __cdecl FreeTexturePage(int pageIndex); // 0x00456080\n#if (DIRECT3D_VERSION < 0x900)\nvoid __cdecl TexturePageReleaseVidMemSurface(TEXPAGE_DESC *page); // 0x004560C0\n#endif // (DIRECT3D_VERSION < 0x900)\nvoid __cdecl FreeTexturePages(); // 0x00456100\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl LoadTexturePage(int pageIndex, bool reset); // 0x00456130\nbool __cdecl ReloadTextures(bool reset); // 0x004561E0\n#endif // (DIRECT3D_VERSION < 0x900)\nHWR_TEXHANDLE __cdecl GetTexturePageHandle(int pageIndex); // 0x00456220\nint __cdecl AddTexturePage8(int width, int height, BYTE *pageBuffer, int palIndex); // 0x00456260\nint __cdecl AddTexturePage16(int width, int height, BYTE *pageBuffer); // 0x00456360\n#if (DIRECT3D_VERSION >= 0x900)\nint AddTexturePage32(int width, int height, BYTE *pageBuffer, bool alpha); // NOTE: this function is not presented in the original game\nint AddExternalTexture(LPCTSTR fileName, bool alpha); // NOTE: this function is not presented in the original game\nbool IsExternalTexture(int page); // NOTE: this function is not presented in the original game\n#else // (DIRECT3D_VERSION >= 0x900)\nHRESULT CALLBACK EnumTextureFormatsCallback(LPDDSDESC lpDdsd, LPVOID lpContext); // 0x00456500\nHRESULT __cdecl EnumerateTextureFormats(); // 0x00456620\n#endif // (DIRECT3D_VERSION >= 0x900)\nvoid __cdecl CleanupTextures(); // 0x00456650\nbool __cdecl InitTextures(); // 0x00456660\n\n#endif // TEXTURE_H_INCLUDED\n"
  },
  {
    "path": "specific/utils.cpp",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/utils.h\"\n#include \"global/vars.h\"\n\nstatic LONGLONG TIME_Ticks, TIME_Start_us;\nstatic double TIME_Frequency, TIME_Period_us;\n\nDWORD __cdecl SyncTicks(DWORD skip) {\n\tdouble target = (double)skip;\n\tdouble elapsed = 0.0;\n\tLONGLONG lastTicks = TIME_Ticks;\n\tdo {\n\t\tUpdateTicks();\n\t\telapsed = (double)(TIME_Ticks - lastTicks) / TIME_Frequency;\n\t} while( elapsed < target );\n\treturn (DWORD)elapsed;\n}\n\n// NOTE: redesigned to make it more accurate\nvoid __cdecl UpdateTicks() {\n\tLARGE_INTEGER counter;\n\n\tQueryPerformanceCounter(&counter);\n\tTIME_Ticks = counter.QuadPart;\n}\n\nbool __cdecl TIME_Init() {\n\tLARGE_INTEGER frequency;\n\n\tif( !QueryPerformanceFrequency(&frequency) )\n\t\treturn false;\n\n\tTIME_Frequency = (double)frequency.QuadPart / (double)TICKS_PER_SECOND;\n\tUpdateTicks();\n\treturn true;\n}\n\n// NOTE: redesigned to make it more accurate\nDWORD __cdecl Sync() {\n\tLONGLONG lastTicks = TIME_Ticks;\n\tUpdateTicks();\n\treturn (DWORD)((double)(TIME_Ticks - lastTicks) / TIME_Frequency);\n}\n\nLPVOID __cdecl UT_LoadResource(LPCTSTR lpName, LPCTSTR lpType) {\n\tHRSRC hRes = FindResource(GameModule, lpName, lpType);\n\tif( hRes == NULL )\n\t\treturn NULL;\n\n\tHGLOBAL hGlb = LoadResource(GameModule, hRes);\n\tif( hGlb == NULL )\n\t\treturn NULL;\n\n\treturn LockResource(hGlb);;\n}\n\n// NOTE: redesigned to make it more accurate\nvoid __cdecl UT_InitAccurateTimer() {\n\tLARGE_INTEGER frequency, counter;\n\tif( QueryPerformanceFrequency(&frequency) ) {\n\t\tTIME_Period_us = 1.0 / (double)frequency.QuadPart; // Tick period for one microsecond\n\t\tQueryPerformanceCounter(&counter);\n\t\tTIME_Start_us = counter.QuadPart;\n\t} else {\n\t\tTIME_Period_us = 0.0;\n\t\tTIME_Start_us = 0;\n\t}\n}\n\n// NOTE: redesigned to make it more accurate\ndouble __cdecl UT_Microseconds() {\n\tLARGE_INTEGER counter;\n\n\tQueryPerformanceCounter(&counter);\n\treturn (double)(counter.QuadPart - TIME_Start_us) * TIME_Period_us;\n}\n\nBOOL __cdecl UT_CenterWindow(HWND hWnd) {\n\tint x, y;\n\tRECT screenArea, windowArea;\n\n\tSystemParametersInfo(SPI_GETWORKAREA, 0, &screenArea, 0);\n\tGetWindowRect(hWnd, &windowArea);\n\tx = (screenArea.left + screenArea.right) / 2 - (windowArea.right - windowArea.left) / 2;\n\ty = (screenArea.top + screenArea.bottom) / 2 - (windowArea.bottom - windowArea.top) / 2;\n\n\treturn SetWindowPos(hWnd, 0, x, y, -1, -1, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE);\n}\n\nLPTSTR __cdecl UT_FindArg(LPCTSTR str) {\n\tLPTSTR next = strstr(CommandLinePtr, str);\n\treturn ( next ) ? next += lstrlen(str) : NULL;\n}\n\nint __cdecl UT_MessageBox(LPCTSTR lpText, HWND hWnd) {\n\treturn MessageBox(hWnd, lpText, MessageBoxName, MB_ICONERROR);\n}\n\nint __cdecl UT_ErrorBox(UINT uID, HWND hWnd) {\n\tchar str[256];\n\n\tif( !LoadString(GameModule, uID, str, 256))\n\t\treturn 0;\n\n\treturn UT_MessageBox(str, hWnd);\n}\n\nBOOL __cdecl CD_NoteAlert(LPCTSTR lpTemplateName, HWND hWndParent) {\n\treturn ( 0 != DialogBoxParam(GameModule, lpTemplateName, hWndParent, DialogBoxProc, 0) );\n}\n\nINT_PTR CALLBACK DialogBoxProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {\n\tswitch( uMsg ) {\n\t\tcase WM_INITDIALOG :\n\t\t\tUT_CenterWindow(hwndDlg);\n\t\t\tbreak;\n\n\t\tcase WM_COMMAND :\n\t\t\tswitch( LOWORD(wParam) ) {\n\t\t\t\tcase IDOK :\n\t\t\t\t\tEndDialog(hwndDlg, 1);\n\t\t\t\t\treturn TRUE;\n\t\t\t\tcase IDCANCEL :\n\t\t\t\t\tEndDialog(hwndDlg, 0);\n\t\t\t\t\treturn TRUE;\n\t\t\t}\n\t\t\tbreak;\n\t}\n\treturn FALSE;\n}\n\nvoid __cdecl UT_MemBlt(BYTE *dstBuf, DWORD dstX, DWORD dstY, DWORD width, DWORD height, DWORD dstPitch,\n\t\t\t\t\t   BYTE *srcBuf, DWORD srcX, DWORD srcY, DWORD srcPitch)\n{\n\tBYTE *src = srcBuf + srcX + srcY * srcPitch;\n\tBYTE *dst = dstBuf + dstX + dstY * dstPitch;\n\n\tfor( DWORD i=0; i<height; ++i ) {\n\t\tmemcpy(dst, src, width);\n\t\tsrc += srcPitch;\n\t\tdst += dstPitch;\n\t}\n}\n\n/*\n * Inject function\n */\nvoid Inject_Utils() {\n\tINJECT(0x00456680, UpdateTicks);\n\tINJECT(0x004566C0, TIME_Init);\n\tINJECT(0x00456720, Sync);\n\tINJECT(0x00456780, UT_LoadResource);\n\tINJECT(0x004567C0, UT_InitAccurateTimer);\n\tINJECT(0x00456820, UT_Microseconds);\n\tINJECT(0x00456870, UT_CenterWindow);\n\tINJECT(0x004568E0, UT_FindArg);\n\tINJECT(0x00456910, UT_MessageBox);\n\tINJECT(0x00456930, UT_ErrorBox);\n\tINJECT(0x00456980, CD_NoteAlert);\n\tINJECT(0x004569B0, DialogBoxProc);\n\tINJECT(0x004574A0, UT_MemBlt);\n}\n"
  },
  {
    "path": "specific/utils.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef UTILS_H_INCLUDED\n#define UTILS_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\nDWORD __cdecl SyncTicks(DWORD skip); // NOTE: this function is not presented in the original game\nvoid __cdecl UpdateTicks(); // 0x00456680\nbool __cdecl TIME_Init(); // 0x004566C0\nDWORD __cdecl Sync(); // 0x00456720\nLPVOID __cdecl UT_LoadResource(LPCTSTR lpName, LPCTSTR lpType); // 0x00456780\nvoid __cdecl UT_InitAccurateTimer(); // 0x004567C0\ndouble __cdecl UT_Microseconds(); // 0x00456820\nBOOL __cdecl UT_CenterWindow(HWND hWnd); // 0x00456870\nLPTSTR __cdecl UT_FindArg(LPCTSTR str); // 0x004568E0\nint __cdecl UT_MessageBox(LPCTSTR lpText, HWND hWnd); // 0x00456910\nint __cdecl UT_ErrorBox(UINT uID, HWND hWnd); // 0x00456930\nBOOL __cdecl CD_NoteAlert(LPCTSTR lpTemplateName, HWND hWndParent); // 0x00456980\nINT_PTR CALLBACK DialogBoxProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam); // 0x004569B0\nvoid __cdecl UT_MemBlt(BYTE *dstBuf, DWORD dstX, DWORD dstY, DWORD width, DWORD height, DWORD dstPitch,\n\t\t\t\t\t   BYTE *srcBuf, DWORD srcX, DWORD srcY, DWORD srcPitch); // 0x004574A0\n#endif // UTILS_H_INCLUDED\n"
  },
  {
    "path": "specific/winmain.cpp",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/winmain.h\"\n#include \"specific/background.h\"\n#include \"specific/fmv.h\"\n#include \"specific/hwr.h\"\n#include \"specific/init.h\"\n#include \"specific/init_3d.h\"\n#include \"specific/init_display.h\"\n#include \"specific/init_input.h\"\n#include \"specific/init_sound.h\"\n#include \"specific/registry.h\"\n#include \"specific/setupdlg.h\"\n#include \"specific/smain.h\"\n#include \"specific/sndpc.h\"\n#include \"specific/texture.h\"\n#include \"specific/utils.h\"\n#include \"specific/winvid.h\"\n#include \"global/resource.h\"\n#include \"global/vars.h\"\n\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n#include \"modding/gdi_utils.h\"\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\nextern bool AvoidInterlacedVideoModes;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n#if defined(_MSC_VER)\n#include <se.h>\n\nstatic void SEH_TR(unsigned int error, EXCEPTION_POINTERS* pExp) {\n\tthrow error;\n}\n#endif // _MSC_VER\n\n#ifdef FEATURE_GOLD\nstatic bool gold = false;\n\nvoid SetGold(bool state) {\n\tgold = state;\n}\n\nbool IsGold() {\n\treturn gold;\n}\n#endif\n\nint __cdecl RenderErrorBox(int errorCode) {\n\tchar errorText[128];\n\tLPCTSTR errorMessage = DecodeErrorMessage(errorCode);\n\twsprintf(errorText, \"Render init failed with \\\"%s\\\"\", errorMessage);\n\treturn UT_MessageBox(errorText, 0);\n}\n\nint CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd) {\n\tHWND gameWindow, setupDialog;\n\tint rc, initStatus, appSettingsStatus;\n\tbool isSetupRequested;\n\n\tGameModule = hInstance;\n\tCommandLinePtr = lpCmdLine;\n\n\t// If another game instance is already run, show its window\n\tgameWindow = WinVidFindGameWindow();\n\tif( gameWindow != NULL ) {\n\t\tsetupDialog = SE_FindSetupDialog();\n\t\tSetForegroundWindow(setupDialog ? setupDialog : gameWindow);\n\t\texit(0); // NOTE: there may be bugs on some systems if we just return here\n\t}\n\n#ifdef _DEBUG\n\tfflush(stdout);\n\tfreopen(\"./TR2Main.log\", \"w\", stdout);\n#endif // _DEBUG\n\n#if defined(_MSC_VER)\n\t_set_se_translator(SEH_TR);\n#endif // _MSC_VER\n\n\ttry {\n\t\tisSetupRequested = ( UT_FindArg(\"setup\") != NULL );\n#ifdef FEATURE_GOLD\n\t\tSetGold(UT_FindArg(\"gold\") != NULL);\n#endif\n\n\t\tinitStatus = Init(isSetupRequested);\n\t\tif( initStatus == 0 ) {\n#if (DIRECT3D_VERSION > 0x500)\n\t\t\tchar msg[256] = {0};\n\t\t\tsnprintf(msg, sizeof(msg), \"Tomb Raider II requires Microsoft DirectX %d to be installed.\", DIRECT3D_VERSION/0x100);\n\t\t\tUT_MessageBox(msg, NULL);\n#else // (DIRECT3D_VERSION > 0x500)\n\t\t\tUT_ErrorBox(IDS_DX5_REQUIRED, NULL); // \"Tomb Raider II requires Microsoft DirectX 5 to be installed.\"\n#endif // (DIRECT3D_VERSION > 0x500)\n\t\t}\n\t\tif( initStatus != 1 )\n\t\t\tgoto EXIT;\n\n\t\tappSettingsStatus = SE_ReadAppSettings(&SavedAppSettings);\n\n\t\tif( appSettingsStatus == 0 )\n\t\t\tgoto EXIT;\n\n\t\tif( isSetupRequested || appSettingsStatus == 2) {\n\t\t\tif( !SE_ShowSetupDialog(NULL, appSettingsStatus == 2) )\n\t\t\t\tgoto EXIT;\n\t\t\tSE_WriteAppSettings(&SavedAppSettings);\n\t\t\tif( isSetupRequested )\n\t\t\t\tgoto EXIT;\n\t\t}\n\n\t\twhile( 0 != (rc = WinGameStart()) ) {\n\t\t\tWinGameFinish();\n\t\t\tRenderErrorBox(rc);\n\n\t\t\tif( !SE_ShowSetupDialog(NULL, false) )\n\t\t\t\tgoto EXIT;\n\t\t\tSE_WriteAppSettings(&SavedAppSettings);\n\t\t}\n\n\t\tStopInventory = false;\n\t\tIsGameToExit = false;\n\t\tGameMain();\n\n\t\tWinGameFinish();\n\t\tSE_WriteAppSettings(&SavedAppSettings);\n\n\t} catch(...) {\n\t\tWinGameFinish();\n\t\tWinCleanup();\n\t\tabort();\n\t}\nEXIT :\n\tWinCleanup();\n\texit(AppResultCode); // NOTE: there may be bugs on some systems if we just return here\n}\n\nint __cdecl Init(bool skipCDInit) {\n\tif( !skipCDInit && !CD_Init() )\n\t\treturn 2;\n\n\tUT_InitAccurateTimer();\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tif( OpenGameRegistryKey(REG_SYSTEM_KEY) ) {\n\t\tGetRegistryBoolValue(REG_AVOID_INTERLACED, &AvoidInterlacedVideoModes, false);\n\t\tCloseGameRegistryKey();\n\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\tif(\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n\t\tGDI_Init() &&\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n\t\tWinVidInit() &&\n\t\tDirect3DInit() &&\n\t\tRenderInit() &&\n\t\tInitTextures() &&\n\t\tWinSndInit() &&\n\t\tWinInputInit() &&\n\t\tTIME_Init() &&\n\t\tHWR_Init() &&\n\t\tBGND_Init() )\n\t{\n\t\tFMV_Init(); // FMV Init is not critical to fail whole game\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\nvoid __cdecl WinCleanup() {\n\tWinVidFreeWindow();\n\tCD_Cleanup();\n\tFMV_Cleanup();\n#if defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n\tGDI_Cleanup();\n#endif // defined(FEATURE_SCREENSHOT_IMPROVED) || defined(FEATURE_BACKGROUND_IMPROVED)\n}\n\nint __cdecl WinGameStart() {\n\ttry {\n\t\tWinVidStart();\n\t\tRenderStart(true);\n\t\tWinSndStart(NULL);\n\t\tWinInStart();\n\t} catch(int error) {\n\t\treturn error;\n\t}\n\treturn 0;\n}\n\nvoid __cdecl WinGameFinish() {\n\tWinInFinish();\n\tWinSndFinish();\n\tRenderFinish(true);\n\tWinVidFinish();\n\tWinVidHideGameWindow();\n\tif( *StringToShow )\n\t\tMessageBox(NULL, StringToShow, NULL, MB_ICONWARNING);\n}\n\nvoid __cdecl S_ExitSystem(LPCTSTR message) {\n\tShutdownGame();\n\tlstrcpy(StringToShow, message);\n\tWinGameFinish();\n\tWinCleanup();\n\texit(1); // the app is terminated here\n}\n\n/*\n * Inject function\n */\nvoid Inject_WinMain() {\n\tINJECT(0x0044E5A0, RenderErrorBox);\n\tINJECT(0x0044E5E0, WinMain);\n\tINJECT(0x0044E7B0, Init);\n\tINJECT(0x0044E830, WinCleanup);\n\tINJECT(0x0044E860, WinGameStart);\n\tINJECT(0x0044E8E0, WinGameFinish);\n\tINJECT(0x0044E950, S_ExitSystem);\n}\n"
  },
  {
    "path": "specific/winmain.h",
    "content": "/*\n * Copyright (c) 2017-2018 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef WINMAIN_H_INCLUDED\n#define WINMAIN_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n\nint __cdecl RenderErrorBox(int errorCode); // 0x0044E5A0\nint CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd); // 0x0044E5E0\nint __cdecl Init(bool skipCDInit); // 0x0044E7B0\nvoid __cdecl WinCleanup(); // 0x0044E830\nint __cdecl WinGameStart(); // 0x0044E860\nvoid __cdecl WinGameFinish(); // 0x0044E8E0\nvoid __cdecl S_ExitSystem(LPCTSTR message); // 0x0044E950\n\n#endif // WINMAIN_H_INCLUDED\n"
  },
  {
    "path": "specific/winvid.cpp",
    "content": "/*\n * Copyright (c) 2017-2021 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#include \"global/precompiled.h\"\n#include \"specific/winvid.h\"\n#include \"specific/init_3d.h\"\n#include \"specific/init_display.h\"\n#include \"specific/sndpc.h\"\n#include \"global/resource.h\"\n#include \"global/vars.h\"\n#include \"global/memmem.h\"\n\n#if (DIRECT3D_VERSION > 0x500)\nDISPLAY_ADAPTER CurrentDisplayAdapter;\n#endif // (DIRECT3D_VERSION > 0x500)\n\n#ifdef FEATURE_WINDOW_STYLE_FIX\nstatic void setWindowStyle(bool isFullScreen) {\n\tstatic const DWORD fullScreenFlags = WS_POPUP;\n\tstatic const DWORD windowedFlags = WS_OVERLAPPEDWINDOW; // WS_BORDER|WS_DLGFRAME|WS_SYSMENU|WS_SIZEBOX|WS_MINIMIZEBOX|WS_MAXIMIZEBOX\n\tDWORD style = GetWindowLong(HGameWindow, GWL_STYLE);\n\tstyle &= ~(isFullScreen ? windowedFlags : fullScreenFlags);\n\tstyle |= (isFullScreen ? fullScreenFlags : windowedFlags);\n\tSetWindowLong(HGameWindow, GWL_STYLE, style);\n}\n#endif // FEATURE_WINDOW_STYLE_FIX\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\nbool AvoidInterlacedVideoModes = false;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n#ifdef FEATURE_INPUT_IMPROVED\n#include \"modding/raw_input.h\"\n#include \"modding/joy_output.h\"\n#endif // FEATURE_INPUT_IMPROVED\n\nstatic bool InsertDisplayModeInListSorted(DISPLAY_MODE_LIST *modeList, DISPLAY_MODE *srcMode) {\n\tDISPLAY_MODE_NODE *node = NULL;\n\tDISPLAY_MODE *dstMode = NULL;\n\n\tif( !modeList->head || CompareVideoModes(srcMode, &modeList->head->body) ) {\n\t\tdstMode = InsertDisplayModeInListHead(modeList);\n\t\tgoto FILL;\n\t}\n\tfor( node = modeList->head; node; node = node->next ) {\n\t\tif( CompareVideoModes(srcMode, &node->body) ) {\n\t\t\tdstMode = InsertDisplayMode(modeList, node);\n\t\t\tgoto FILL;\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t} else if( !memcmp(srcMode, &node->body, sizeof(DISPLAY_MODE)) ) {\n\t\t\treturn false;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t}\n\t}\n\tdstMode = InsertDisplayModeInListTail(modeList);\n\nFILL:\n\tif( dstMode ) {\n\t\t*dstMode = *srcMode;\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nstatic bool DisplayModeListCopy(DISPLAY_MODE_LIST *dst, DISPLAY_MODE_LIST *src) {\n\tif( dst == NULL || src == NULL || dst == src )\n\t\treturn false;\n\n\tDISPLAY_MODE_NODE *node;\n\tDISPLAY_MODE *dstMode;\n\n\tDisplayModeListDelete(dst);\n\tfor( node = src->head; node; node = node->next ) {\n\t\tdstMode = InsertDisplayModeInListTail(dst);\n\t\t*dstMode = node->body;\n\t}\n\treturn true;\n}\n\nbool FlaggedStringCopy(STRING_FLAGGED *dst, STRING_FLAGGED *src) {\n\tif( dst == NULL || src == NULL || dst == src || !src->isPresented )\n\t\treturn false;\n\n\tsize_t srcLen = lstrlen(src->lpString);\n\n\tdst->isPresented = false;\n\tdst->lpString = new char[srcLen + 1];\n\n\tif( dst->lpString == NULL )\n\t\treturn false;\n\n\tif( srcLen > 0 ) {\n\t\tlstrcpy(dst->lpString, src->lpString);\n\t} else {\n\t\t*dst->lpString = 0;\n\t}\n\tdst->isPresented = true;\n\treturn true;\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl DDrawCreate(LPGUID lpGUID) {\n\tif FAILED(DirectDrawCreate(lpGUID, &DDrawInterface, 0))\n\t\treturn false;\n\n\tif FAILED(DDrawInterface->QueryInterface(IID_IDirectDraw2, (LPVOID *)&DDraw))\n\t\treturn false;\n\n\tDDraw->SetCooperativeLevel(HGameWindow, DDSCL_NORMAL);\n\treturn true;\n}\n\nvoid __cdecl DDrawRelease() {\n\tif( DDraw ) {\n\t\tDDraw->Release();\n\t\tDDraw = NULL;\n\t}\n\tif( DDrawInterface ) {\n\t\tDDrawInterface->Release();\n\t\tDDrawInterface = NULL;\n\t}\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nvoid __cdecl GameWindowCalculateSizeFromClient(int *width, int *height) {\n\tDWORD style, styleEx;\n\tRECT rect = {0, 0, *width, *height};\n\n\tstyle = GetWindowLong(HGameWindow, GWL_STYLE);\n\tstyleEx = GetWindowLong(HGameWindow, GWL_EXSTYLE);\n\tAdjustWindowRectEx(&rect, style, FALSE, styleEx);\n\n\t*width  = rect.right  - rect.left;\n\t*height = rect.bottom - rect.top;\n}\n\nvoid __cdecl GameWindowCalculateSizeFromClientByZero(int *width, int *height) {\n\tDWORD style, styleEx;\n\tRECT rect = {0, 0, 0, 0};\n\n\tstyle = GetWindowLong(HGameWindow, GWL_STYLE);\n\tstyleEx = GetWindowLong(HGameWindow, GWL_EXSTYLE);\n\tAdjustWindowRectEx(&rect, style, FALSE, styleEx);\n\n\t*width  += rect.left - rect.right;\n\t*height += rect.top  - rect.bottom;;\n}\n\nvoid __cdecl WinVidSetMinWindowSize(int width, int height) {\n\tMinWindowClientWidth = width;\n\tMinWindowClientHeight = height;\n\tGameWindowCalculateSizeFromClient(&width, &height);\n\tMinWindowWidth = width;\n\tMinWindowHeight = height;\n\tIsMinWindowSizeSet = true;\n}\n\nvoid __cdecl WinVidClearMinWindowSize() {\n\tIsMinWindowSizeSet = false;\n}\n\nvoid __cdecl WinVidSetMaxWindowSize(int width, int height) {\n\tMaxWindowClientWidth = width;\n\tMaxWindowClientHeight = height;\n\tGameWindowCalculateSizeFromClient(&width, &height);\n\tMaxWindowWidth = width;\n\tMaxWindowHeight = height;\n\tIsMaxWindowSizeSet = true;\n}\n\nvoid __cdecl WinVidClearMaxWindowSize() {\n\tIsMaxWindowSizeSet = false;\n}\n\nint __cdecl CalculateWindowWidth(int width, int height) {\n\tswitch( SavedAppSettings.AspectMode ) {\n\t\tcase AM_4_3 :\n\t\t\treturn height*4/3;\n\t\tcase AM_16_9 :\n\t\t\treturn height*16/9;\n\t\tdefault :\n\t\t\tbreak;\n\t}\n\treturn width;\n}\n\nint __cdecl CalculateWindowHeight(int width, int height) {\n\tswitch( SavedAppSettings.AspectMode ) {\n\t\tcase AM_4_3 :\n\t\t\treturn width*3/4;\n\t\tcase AM_16_9 :\n\t\t\treturn width*9/16;\n\t\tdefault :\n\t\t\tbreak;\n\t}\n\treturn height;\n}\n\nbool __cdecl WinVidGetMinMaxInfo(LPMINMAXINFO info) {\n\n\tif( !IsGameWindowCreated )\n\t\treturn false;\n\n\tif( IsGameFullScreen ) {\n\t\tinfo->ptMinTrackSize.x = FullScreenWidth;\n\t\tinfo->ptMinTrackSize.y = FullScreenHeight;\n\n\t\tinfo->ptMaxTrackSize.x = FullScreenWidth;\n\t\tinfo->ptMaxTrackSize.y = FullScreenHeight;\n\t\tinfo->ptMaxSize.x = FullScreenWidth;\n\t\tinfo->ptMaxSize.y = FullScreenHeight;\n\t\treturn true;\n\t}\n\n\tif( IsMinWindowSizeSet ) {\n\t\tinfo->ptMinTrackSize.x = MinWindowWidth;\n\t\tinfo->ptMinTrackSize.y = MinWindowHeight;\n\t}\n\n\tif( IsMinMaxInfoSpecial ) {\n\t\tint newWindowWidth = GameWindowWidth;\n\t\tint newWindowHeight = GameWindowHeight;\n\t\tGameWindowCalculateSizeFromClient(&newWindowWidth, &newWindowHeight);\n\n\t\tinfo->ptMaxTrackSize.x = newWindowWidth;\n\t\tinfo->ptMaxTrackSize.y = newWindowHeight;\n\t\tinfo->ptMaxSize.x = newWindowWidth;\n\t\tinfo->ptMaxSize.y = newWindowHeight;\n\t}\n\telse if( IsMaxWindowSizeSet ) {\n\t\tinfo->ptMaxTrackSize.x = MaxWindowWidth;\n\t\tinfo->ptMaxTrackSize.y = MaxWindowHeight;\n\t\tinfo->ptMaxSize.x = MaxWindowWidth;\n\t\tinfo->ptMaxSize.y = MaxWindowHeight;\n\t}\n\n\treturn ( IsMinWindowSizeSet || IsMaxWindowSizeSet );\n}\n\nHWND __cdecl WinVidFindGameWindow() {\n\treturn FindWindow(GameClassName, GameWindowName);\n}\n\nbool __cdecl WinVidSpinMessageLoop(bool needWait) {\n\tstatic int messageLoopCounter = 0;\n\tMSG msg;\n\n\tif( IsMessageLoopClosed )\n\t\treturn false;\n\n\t++messageLoopCounter;\n\tdo {\n\t\tif( needWait )\n\t\t\tWaitMessage();\n\t\telse\n\t\t\tneedWait = true;\n\n\t\twhile( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) {\n\t\t\tTranslateMessage(&msg);\n\t\t\tDispatchMessage(&msg);\n\t\t\tif( msg.message == WM_QUIT ) {\n\t\t\t\tAppResultCode = msg.wParam;\n\t\t\t\tIsGameToExit = true;\n\t\t\t\tStopInventory = true;\n\t\t\t\tIsMessageLoopClosed = true;\n\t\t\t\t--messageLoopCounter;\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t} while( !IsGameWindowActive || IsGameWindowMinimized );\n\n\t--messageLoopCounter;\n\treturn true;\n}\n\nvoid __cdecl WinVidShowGameWindow(int nCmdShow) {\n\tif( nCmdShow != SW_SHOW || !IsGameWindowShow ) {\n\t\tIsGameWindowUpdating = TRUE;\n\t\tShowWindow(HGameWindow, nCmdShow);\n\t\tUpdateWindow(HGameWindow);\n\t\tIsGameWindowUpdating = FALSE;\n\t\tIsGameWindowShow = TRUE;\n\t}\n}\n\nvoid __cdecl WinVidHideGameWindow() {\n\tif( IsGameWindowShow ) {\n\t\tIsGameWindowUpdating = TRUE;\n\t\tShowWindow(HGameWindow, SW_HIDE);\n\t\tUpdateWindow(HGameWindow);\n\t\tIsGameWindowUpdating = FALSE;\n\t\tIsGameWindowShow = FALSE;\n\t}\n}\n\nvoid __cdecl WinVidSetGameWindowSize(int width, int height) {\n\tGameWindowCalculateSizeFromClient(&width, &height);\n\tSetWindowPos(HGameWindow, NULL, 0, 0, width, height, SWP_NOCOPYBITS|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE);\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl ShowDDrawGameWindow(bool active) {\n\tDWORD flags;\n\tHRESULT rc;\n\tRECT rect;\n\n\tif( !HGameWindow || !DDraw )\n\t\treturn false;\n\n\tif( IsDDrawGameWindowShow )\n\t\treturn true;\n\n\tGetWindowRect(HGameWindow, &rect);\n\tGameWindow_X = rect.left;\n\tGameWindow_Y = rect.top;\n\n\tif( active )\n\t\tWinVidShowGameWindow(SW_SHOW);\n\n\tflags = DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN;\n\tif( !active )\n\t\tflags |= DDSCL_NOWINDOWCHANGES;\n\n\tIsGameWindowUpdating = TRUE;\n\trc = DDraw->SetCooperativeLevel(HGameWindow, flags);\n\tIsGameWindowUpdating = FALSE;\n\n\tif SUCCEEDED(rc) {\n\t\tIsDDrawGameWindowShow = TRUE;\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nbool __cdecl HideDDrawGameWindow() {\n\tbool result = false;\n\n\tif( HGameWindow == NULL || DDraw == NULL )\n\t\treturn false;\n\n\tif( !IsDDrawGameWindowShow )\n\t\treturn true;\n\n\tWinVidHideGameWindow();\n\n\tIsGameWindowUpdating = TRUE;\n\tif SUCCEEDED(DDraw->SetCooperativeLevel(HGameWindow, DDSCL_NORMAL)) {\n\t\tIsDDrawGameWindowShow = FALSE;\n\t\tSetWindowPos(HGameWindow, 0, GameWindow_X, GameWindow_Y, 0, 0, SWP_NOCOPYBITS|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE);\n\t\tresult = true;\n\t}\n\tIsGameWindowUpdating = FALSE;\n\n\treturn result;\n}\n\nHRESULT __cdecl DDrawSurfaceCreate(LPDDSDESC dsp, LPDDS *surface) {\n\tLPDIRECTDRAWSURFACE subSurface;\n\tHRESULT rc = DDraw->CreateSurface(dsp, &subSurface, NULL);\n\n\tif SUCCEEDED(rc) {\n\t\trc = subSurface->QueryInterface(IID_IDirectDrawSurface3, (LPVOID *)surface);\n\t\tsubSurface->Release();\n\t}\n\n\treturn rc;\n}\n\nHRESULT __cdecl DDrawSurfaceRestoreLost(LPDDS surface1, LPDDS surface2, bool blank) {\n\tif( surface1 == NULL ) // NOTE: additional check just in case\n\t\treturn 0;\n\n\tHRESULT rc = surface1->IsLost();\n\tif( rc != DDERR_SURFACELOST )\n\t\treturn rc;\n\n\trc = (surface2 ? surface2 : surface1)->Restore();\n\tif( blank && SUCCEEDED(rc) )\n\t\tWinVidClearBuffer(surface1, 0, 0);\n\n\treturn rc;\n}\n\nbool __cdecl WinVidClearBuffer(LPDDS surface, LPRECT rect, DWORD fillColor) {\n\tDDBLTFX bltFx;\n\n\tif( surface == NULL ) // NOTE: additional check just in case\n\t\treturn 0;\n\n\tmemset(&bltFx, 0, sizeof(DDBLTFX));\n\tbltFx.dwSize = sizeof(DDBLTFX);\n\tbltFx.dwFillColor = fillColor;\n\n\treturn SUCCEEDED(surface->Blt(rect, NULL, NULL, DDBLT_WAIT|DDBLT_COLORFILL, &bltFx));\n}\n\nHRESULT __cdecl WinVidBufferLock(LPDDS surface, LPDDSDESC desc, DWORD flags) {\n\tmemset(desc, 0, sizeof(DDSDESC));\n\tdesc->dwSize = sizeof(DDSDESC);\n\n\tHRESULT result = surface->Lock(NULL, desc, flags, NULL);\n\tif SUCCEEDED(result) {\n\t\t++LockedBufferCount;\n\t}\n\treturn result;\n}\n\nHRESULT __cdecl WinVidBufferUnlock(LPDDS surface, LPDDSDESC desc) {\n\tHRESULT result = surface->Unlock(desc->lpSurface);\n\tif SUCCEEDED(result) {\n\t\t--LockedBufferCount;\n\t}\n\treturn result;\n}\n\nbool __cdecl WinVidCopyBitmapToBuffer(LPDDS surface, BYTE *bitmap) {\n\tDWORD i;\n\tBYTE *src, *dst;\n\tDDSDESC desc;\n\tif( surface == NULL || bitmap == NULL ) // NOTE: additional check just in case\n\t\treturn false;\n\n\tif FAILED(WinVidBufferLock(surface, &desc, DDLOCK_WRITEONLY|DDLOCK_WAIT))\n\t\treturn false;\n\n\tsrc = bitmap;\n\tdst = (BYTE *)desc.lpSurface;\n\tfor( i=0; i<desc.dwHeight; ++i ) {\n\t\tmemcpy(dst, src, desc.dwWidth);\n\t\tsrc += desc.dwWidth;\n\t\tdst += desc.lPitch;\n\t}\n\n\tWinVidBufferUnlock(surface, &desc);\n\treturn true;\n}\n\nDWORD __cdecl GetRenderBitDepth(DWORD dwRGBBitCount) {\n\tswitch( dwRGBBitCount ) {\n\t\tcase  1 : return DDBD_1;\n\t\tcase  2 : return DDBD_2;\n\t\tcase  4 : return DDBD_4;\n\t\tcase  8 : return DDBD_8;\n\t\tcase 16 : return DDBD_16;\n\t\tcase 24 : return DDBD_24;\n\t\tcase 32 : return DDBD_32;\n\t}\n\treturn 0;\n}\n\nvoid __thiscall WinVidGetColorBitMasks(COLOR_BIT_MASKS *bm, LPDDPIXELFORMAT pixelFormat) {\n\tbm->dwRBitMask\t\t\t= pixelFormat->dwRBitMask;\n\tbm->dwGBitMask\t\t\t= pixelFormat->dwGBitMask;\n\tbm->dwBBitMask\t\t\t= pixelFormat->dwBBitMask;\n\tbm->dwRGBAlphaBitMask\t= pixelFormat->dwRGBAlphaBitMask;\n\n\tBitMaskGetNumberOfBits(bm->dwRBitMask,\t\t\t&bm->dwRBitDepth,\t\t\t&bm->dwRBitOffset);\n\tBitMaskGetNumberOfBits(bm->dwGBitMask,\t\t\t&bm->dwGBitDepth,\t\t\t&bm->dwGBitOffset);\n\tBitMaskGetNumberOfBits(bm->dwBBitMask,\t\t\t&bm->dwBBitDepth,\t\t\t&bm->dwBBitOffset);\n\tBitMaskGetNumberOfBits(bm->dwRGBAlphaBitMask,\t&bm->dwRGBAlphaBitDepth,\t&bm->dwRGBAlphaBitOffset);\n}\n\nvoid __cdecl BitMaskGetNumberOfBits(DWORD bitMask, DWORD *bitDepth, DWORD *bitOffset) {\n\tDWORD i;\n\n\tif( !bitMask ) {\n\t\t*bitOffset = 0;\n\t\t*bitDepth = 0;\n\t\treturn;\n\t}\n\n\tfor( i = 0; (bitMask & 1) == 0; ++i ) {\n\t\tbitMask >>= 1;\n\t}\n\t*bitOffset = i;\n\n\tfor( i = 0; bitMask != 0; ++i ) {\n\t\tbitMask >>= 1;\n\t}\n\t*bitDepth = i;\n}\n\nDWORD __cdecl CalculateCompatibleColor(COLOR_BIT_MASKS *mask, int red, int green, int blue, int alpha) {\n\treturn\t(red\t>> (8 - mask->dwRBitDepth)\t\t\t<< mask->dwRBitOffset) |\n\t\t\t(green\t>> (8 - mask->dwGBitDepth)\t\t\t<< mask->dwGBitOffset) |\n\t\t\t(blue\t>> (8 - mask->dwBBitDepth)\t\t\t<< mask->dwBBitOffset) |\n\t\t\t(alpha\t>> (8 - mask->dwRGBAlphaBitDepth)\t<< mask->dwRGBAlphaBitOffset);\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nbool __cdecl WinVidGetDisplayMode(DISPLAY_MODE *dispMode) {\n#if (DIRECT3D_VERSION >= 0x900)\n\tbool d3dClean = false;\n\tif( D3D == NULL ) {\n\t\tif( !D3DCreate() ) return false;\n\t\td3dClean = true;\n\t}\n\tD3DDISPLAYMODE mode;\n\tHRESULT res = D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);\n\tif( d3dClean ) D3DRelease();\n\tif( SUCCEEDED(res) && mode.Format == D3DFMT_X8R8G8B8 ) {\n\t\tdispMode->width = mode.Width;\n\t\tdispMode->height = mode.Height;\n\t\tdispMode->bpp = 32;\n\t\tdispMode->vga = VGA_NoVga;\n\t\treturn true;\n\t}\n\treturn false;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tDDSDESC dsp;\n\n\tmemset(&dsp, 0, sizeof(dsp));\n\tdsp.dwSize = sizeof(dsp);\n\n\tif( SUCCEEDED(DDraw->GetDisplayMode(&dsp)) &&\n\t\t((dsp.dwFlags & DDSD_WIDTH) != 0) &&\n\t\t((dsp.dwFlags & DDSD_HEIGHT) != 0) &&\n\t\t((dsp.dwFlags & DDSD_PIXELFORMAT) != 0) &&\n\t\t((dsp.ddpfPixelFormat.dwFlags & DDPF_RGB) != 0) )\n\t{\n\t\tdispMode->width = dsp.dwWidth;\n\t\tdispMode->height = dsp.dwHeight;\n\t\tdispMode->bpp = dsp.ddpfPixelFormat.dwRGBBitCount;\n\n\t\tif( (dsp.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) != 0 )\n\t\t\tdispMode->vga = VGA_256Color;\n\t\telse\n\t\t\tdispMode->vga = VGA_NoVga;\n\n\t\treturn true;\n\t}\n\n\treturn false;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nbool __cdecl WinVidGoFullScreen(DISPLAY_MODE *dispMode) {\n\tFullScreenWidth = dispMode->width;\n\tFullScreenHeight = dispMode->height;\n\tFullScreenBPP = dispMode->bpp;\n\tFullScreenVGA = dispMode->vga;\n\n#ifdef FEATURE_WINDOW_STYLE_FIX\n\tsetWindowStyle(true);\n#endif // FEATURE_WINDOW_STYLE_FIX\n\n#if (DIRECT3D_VERSION < 0x900)\n\tHRESULT rc;\n\tif( !ShowDDrawGameWindow(true) )\n\t\tgoto FAIL;\n\n\tIsGameWindowUpdating = true;\n\trc = DDraw->SetDisplayMode(dispMode->width, dispMode->height, dispMode->bpp, 0, (dispMode->vga == VGA_Standard) ? DDSDM_STANDARDVGAMODE : 0);\n\tIsGameWindowUpdating = false;\n\n\tif FAILED(rc)\n\t\tgoto FAIL;\n#endif // (DIRECT3D_VERSION < 0x900)\n\n\tIsGameFullScreen = true;\n\treturn true;\n\n#if (DIRECT3D_VERSION < 0x900)\nFAIL :\n#ifdef FEATURE_WINDOW_STYLE_FIX\n\tsetWindowStyle(false);\n#endif // FEATURE_WINDOW_STYLE_FIX\n\treturn false;\n#endif // (DIRECT3D_VERSION < 0x900)\n}\n\nbool __cdecl WinVidGoWindowed(int width, int height, DISPLAY_MODE *dispMode) {\n\tint maxWidth, maxHeight;\n\tRECT rect;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tif( !WinVidGetDisplayMode(dispMode) )\n\t\treturn false;\n#else // (DIRECT3D_VERSION >= 0x900)\n\tif( !HideDDrawGameWindow() || !WinVidGetDisplayMode(dispMode) )\n\t\treturn false;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n#ifdef FEATURE_WINDOW_STYLE_FIX\n\tsetWindowStyle(false);\n#endif // FEATURE_WINDOW_STYLE_FIX\n\n\tmaxWidth = dispMode->width;\n\tmaxHeight = CalculateWindowHeight(dispMode->width, dispMode->height);\n\n\tif( maxHeight > dispMode->height ) {\n\t\tmaxHeight = dispMode->height;\n\t\tmaxWidth = CalculateWindowWidth(dispMode->width, dispMode->height);\n\t}\n\tWinVidSetMaxWindowSize(maxWidth, maxHeight);\n\n\tif( width > maxWidth || height > maxHeight ) {\n\t\twidth = maxWidth;\n\t\theight = maxHeight;\n\t}\n\n\tIsGameFullScreen = false;\n\tIsGameWindowUpdating = true;\n\tWinVidSetGameWindowSize(width, height);\n\tIsGameWindowUpdating = false;\n\n\tGetClientRect(HGameWindow, &rect);\n\tMapWindowPoints(HGameWindow, NULL, (LPPOINT)&rect, 2);\n\n\tif( (rect.left > 0 || rect.right < dispMode->width) &&\n\t\t(rect.top > 0 || rect.bottom < dispMode->height) )\n\t{\n\t\tWinVidShowGameWindow(SW_SHOW);\n\t} else {\n\t\tWinVidShowGameWindow(SW_MAXIMIZE);\n\t}\n\n\tdispMode->width = width;\n\tdispMode->height = height;\n\treturn true;\n}\n\nvoid __cdecl WinVidSetDisplayAdapter(DISPLAY_ADAPTER *dispAdapter) {\n\tbool rc;\n\tDISPLAY_MODE dispMode;\n\n\tdispAdapter->screenWidth = 0;\n#if (DIRECT3D_VERSION < 0x900)\n\tdispAdapter->swWindowedSupported = false;\n\tdispAdapter->hwWindowedSupported = false;\n\n\t// Primary adapter GUID is NULL. Secondary adapter is not applicable\n\tif( dispAdapter->lpAdapterGuid != NULL )\n\t\treturn;\n\n\tif( !DDrawCreate(NULL) ) return;\n#endif // (DIRECT3D_VERSION < 0x900)\n\trc = WinVidGetDisplayMode(&dispMode);\n#if (DIRECT3D_VERSION < 0x900)\n\tDDrawRelease();\n#endif // (DIRECT3D_VERSION < 0x900)\n\tif( !rc ) return;\n\n\tdispMode.width &= ~0x1F;\n\tif( dispMode.width*3/4 > dispMode.height )\n\t\tdispMode.width = (dispMode.height*4/3) & ~0x1F;\n\n\tdispAdapter->screenWidth = dispMode.width;\n#if (DIRECT3D_VERSION < 0x900)\n\tdispAdapter->swWindowedSupported = ( dispMode.vga == VGA_256Color );\n\tdispAdapter->hwWindowedSupported = ( dispAdapter->hwRenderSupported &&\n\t\t((dispAdapter->D3DHWDeviceDesc.dwFlags & D3DDD_DEVICERENDERBITDEPTH) != 0) &&\n\t\t((GetRenderBitDepth(dispMode.bpp) & dispAdapter->D3DHWDeviceDesc.dwDeviceRenderBitDepth) != 0) );\n#endif // (DIRECT3D_VERSION < 0x900)\n}\n\nbool __thiscall CompareVideoModes(DISPLAY_MODE *mode1, DISPLAY_MODE *mode2) {\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\tif( mode1->bpp < mode2->bpp ) return true;\n\tif( mode1->bpp > mode2->bpp ) return false;\n\tif( mode1->width < mode2->width ) return true;\n\tif( mode1->width > mode2->width ) return false;\n\tif( mode1->height < mode2->height ) return true;\n\tif( mode1->height > mode2->height ) return false;\n#else // !FEATURE_NOLEGACY_OPTIONS\n\tDWORD square1 = mode1->width * mode1->height;\n\tDWORD square2 = mode2->width * mode2->height;\n\tif( square1 < square2 ) return true;\n\tif( square1 > square2 ) return false;\n\tif( mode1->bpp < mode2->bpp ) return true;\n\tif( mode1->bpp > mode2->bpp ) return false;\n#endif // FEATURE_NOLEGACY_OPTIONS\n\tif( mode1->vga < mode2->vga ) return true;\n\tif( mode1->vga > mode2->vga ) return false;\n\t// equal state\n\treturn false;\n}\n\n#ifdef FEATURE_NOLEGACY_OPTIONS\nstatic void DeleteDisplayMode(DISPLAY_MODE_LIST *modeList, DISPLAY_MODE_NODE *node) {\n\tif( !modeList || !node ) return;\n\tDISPLAY_MODE_NODE *previous = node->previous;\n\tDISPLAY_MODE_NODE *next = node->next;\n\tif( previous ) previous->next = next;\n\tif( next ) next->previous = previous;\n\tif( modeList->head == node ) modeList->head = next;\n\tif( modeList->tail == node ) modeList->tail = previous;\n\tif( modeList->dwCount ) --modeList->dwCount;\n\tdelete(node);\n}\n\nstatic DWORD GetProgressiveDisplayModes(DWORD bpp, DEVMODE *modes, DWORD modeNum) {\n\tDWORD idx = 0;\n\tDWORD num = 0;\n\tif( modes == NULL ) {\n\t\tDEVMODE mode;\n\t\tmemset(&mode, 0, sizeof(mode));\n\t\tmode.dmSize = sizeof(mode);\n\t\twhile( EnumDisplaySettings(NULL, idx++, &mode) ) {\n\t\t\tif( mode.dmBitsPerPel == bpp && !CHK_ANY(mode.dmDisplayFlags, DM_INTERLACED) ) {\n\t\t\t\t++num;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tmemset(modes, 0, sizeof(DEVMODE) * modeNum);\n\t\twhile( num < modeNum ) {\n\t\t\tmodes[num].dmSize = sizeof(DEVMODE);\n\t\t\tif( !EnumDisplaySettings(NULL, idx++, &modes[num]) ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif( modes[num].dmBitsPerPel == bpp && !CHK_ANY(modes[num].dmDisplayFlags, DM_INTERLACED) ) {\n\t\t\t\t++num;\n\t\t\t}\n\t\t}\n\t}\n\treturn num;\n}\n\nstatic bool IsModeInList(DISPLAY_MODE *mode, DEVMODE *modes, DWORD modeNum) {\n\tif( !mode || !modes || !modeNum ) return false;\n\tfor( DWORD i = 0; i < modeNum; ++i ) {\n\t\tif( modes[i].dmPelsWidth  == (DWORD)mode->width  &&\n\t\t\tmodes[i].dmPelsHeight == (DWORD)mode->height &&\n\t\t\tmodes[i].dmBitsPerPel == (DWORD)mode->bpp )\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nstatic void FilterDisplayModes(DISPLAY_MODE_LIST *modeList) {\n\tDWORD wlistSize = 0;\n\tDEVMODE *whitelist = NULL;\n\tDISPLAY_MODE_NODE *mode, *next;\n\tint bppMax = 8;\n\tfor( mode = modeList->head; mode; mode = mode->next ) {\n\t\tCLAMPL(bppMax, mode->body.bpp);\n\t}\n\tif( AvoidInterlacedVideoModes ) {\n\t\twlistSize = GetProgressiveDisplayModes(bppMax, NULL, 0);\n\t\tif( wlistSize ) {\n\t\t\twhitelist = (DEVMODE *)malloc(sizeof(DEVMODE) * wlistSize);\n\t\t\tif( whitelist ) {\n\t\t\t\tGetProgressiveDisplayModes(bppMax, whitelist, wlistSize);\n\t\t\t}\n\t\t}\n\t}\n\tfor( mode = modeList->head; mode; mode = next ) {\n\t\tnext = mode->next;\n\t\tif( mode->body.bpp < bppMax || (whitelist && !IsModeInList(&mode->body, whitelist, wlistSize)) ) {\n\t\t\tDeleteDisplayMode(modeList, mode);\n\t\t}\n\t}\n\tif( whitelist ) {\n\t\tfree(whitelist);\n\t}\n}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\nbool __cdecl WinVidGetDisplayModes() {\n\tDISPLAY_ADAPTER_NODE *adapter;\n#if (DIRECT3D_VERSION >= 0x900)\n\tbool d3dClean = false;\n\tif( D3D == NULL ) {\n\t\tif( !D3DCreate() ) return false;\n\t\td3dClean = true;\n\t}\n\tfor( adapter = DisplayAdapterList.head; adapter; adapter = adapter->next ) {\n\t\tUINT num = D3D->GetAdapterModeCount(adapter->body.index, D3DFMT_X8R8G8B8);\n\t\tfor( UINT i = 0; i < num; ++i ) {\n\t\t\tD3DDISPLAYMODE mode;\n\t\t\tif FAILED(D3D->EnumAdapterModes(adapter->body.index, D3DFMT_X8R8G8B8, i, &mode)) continue;\n\t\t\tDISPLAY_MODE videoMode = {(int)mode.Width, (int)mode.Height, 32, VGA_NoVga};\n\t\t\tInsertDisplayModeInListSorted(&adapter->body.hwDispModeList, &videoMode);\n\t\t\tInsertDisplayModeInListSorted(&adapter->body.swDispModeList, &videoMode);\n\t\t}\n\t\tFilterDisplayModes(&adapter->body.hwDispModeList);\n\t}\n\tif( d3dClean ) D3DRelease();\n#else // (DIRECT3D_VERSION >= 0x900)\n\tfor( adapter = DisplayAdapterList.head; adapter; adapter = adapter->next ) {\n\t\tDDrawCreate(adapter->body.lpAdapterGuid);\n\t\tShowDDrawGameWindow(false);\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\tDDraw->EnumDisplayModes(0, NULL, (LPVOID)&adapter->body, EnumDisplayModesCallback);\n\t\tFilterDisplayModes(&adapter->body.hwDispModeList);\n#else // FEATURE_NOLEGACY_OPTIONS\n\t\tDDraw->EnumDisplayModes(DDEDM_STANDARDVGAMODES, NULL, (LPVOID)&adapter->body, EnumDisplayModesCallback);\n#endif // FEATURE_NOLEGACY_OPTIONS\n\t\tHideDDrawGameWindow();\n\t\tDDrawRelease();\n\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\treturn true;\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nHRESULT WINAPI EnumDisplayModesCallback(LPDDSDESC lpDDSurfaceDesc, LPVOID lpContext) {\n\tDISPLAY_ADAPTER *adapter = (DISPLAY_ADAPTER *)lpContext;\n\tDISPLAY_MODE videoMode;\n\tVGA_MODE vgaMode = VGA_NoVga;\n\tDWORD renderBitDepth = 0;\n\tbool swRendererSupported = false;\n\n\tif( (lpDDSurfaceDesc->dwFlags & (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT)) != (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT) ||\n\t\t(lpDDSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_RGB) == 0 )\n\t{\n\t\treturn DDENUMRET_OK;\n\t}\n\n\tif( (lpDDSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) != 0 &&\n\t\tlpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 8 )\n\t{\n#ifdef FEATURE_NOLEGACY_OPTIONS\n\t\t// Check software renderer requirements for 8 bit display modes\n\t\tif( lpDDSurfaceDesc->dwHeight % 4 != 0 ||\n\t\t\tCHK_ANY(lpDDSurfaceDesc->ddsCaps.dwCaps, DDSCAPS_MODEX|DDSCAPS_STANDARDVGAMODE) )\n\t\t{\n\t\t\treturn DDENUMRET_OK;\n\t\t}\n\n\t\tvgaMode = VGA_256Color;\n#else // FEATURE_NOLEGACY_OPTIONS\n\t\tif( CHK_ANY(lpDDSurfaceDesc->ddsCaps.dwCaps, DDSCAPS_MODEX) ) {\n\t\t\tvgaMode = VGA_ModeX;\n\t\t} else if( CHK_ANY(lpDDSurfaceDesc->ddsCaps.dwCaps, DDSCAPS_STANDARDVGAMODE) ) {\n\t\t\tvgaMode = VGA_Standard;\n\t\t} else {\n\t\t\tvgaMode = VGA_256Color;\n\t\t}\n#endif // FEATURE_NOLEGACY_OPTIONS\n\n\t\tif( lpDDSurfaceDesc->dwWidth == 320 &&\n\t\t\tlpDDSurfaceDesc->dwHeight == 200 &&\n\t\t\t(!adapter->isVgaMode1Presented || vgaMode < adapter->vgaMode1.vga) )\n\t\t{\n\t\t\tadapter->vgaMode1.width = 320;\n\t\t\tadapter->vgaMode1.height = 200;\n\t\t\tadapter->vgaMode1.bpp = 8;\n\t\t\tadapter->vgaMode1.vga = vgaMode;\n\t\t\tadapter->isVgaMode1Presented = true;\n\t\t}\n\n\t\tif( lpDDSurfaceDesc->dwWidth == 640 &&\n\t\t\tlpDDSurfaceDesc->dwHeight == 480 &&\n\t\t\t(!adapter->isVgaMode2Presented || vgaMode < adapter->vgaMode2.vga) )\n\t\t{\n\t\t\tadapter->vgaMode2.width = 640;\n\t\t\tadapter->vgaMode2.height = 480;\n\t\t\tadapter->vgaMode2.bpp = 8;\n\t\t\tadapter->vgaMode2.vga = vgaMode;\n\t\t\tadapter->isVgaMode2Presented = true;\n\t\t}\n\t\tswRendererSupported = true;\n\t}\n\n\tvideoMode.width = lpDDSurfaceDesc->dwWidth;\n\tvideoMode.height = lpDDSurfaceDesc->dwHeight;\n\tvideoMode.bpp = lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount;\n\tvideoMode.vga = vgaMode;\n\n\trenderBitDepth = GetRenderBitDepth(lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount);\n\n\tif( adapter->hwRenderSupported && 0 != ( renderBitDepth & adapter->D3DHWDeviceDesc.dwDeviceRenderBitDepth) )\n\t\tInsertDisplayModeInListSorted(&adapter->hwDispModeList, &videoMode);\n\n\tif( swRendererSupported )\n\t\tInsertDisplayModeInListSorted(&adapter->swDispModeList, &videoMode);\n\n\treturn DDENUMRET_OK;\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nbool __cdecl WinVidInit() {\n\tAppResultCode = 0;\n#if (DIRECT3D_VERSION <= 0x700)\n\t// NOTE: We can hack DirectDraw to support surface resolutions greater than 2048x2048.\n\t// Not presented in the original game. Many thanks to Gemini-Loboto3 for this idea!\n#if (DIRECT3D_VERSION == 0x700)\n\tHMODULE hd3d = LoadLibrary(\"d3dim700.dll\");\n#else // (DIRECT3D_VERSION == 0x700)\n\tHMODULE hd3d = LoadLibrary(\"d3dim.dll\");\n#endif // (DIRECT3D_VERSION == 0x700)\n\tif( hd3d ) {\n\t\tPIMAGE_DOS_HEADER pDosHeader;\n\t\tPIMAGE_NT_HEADERS pNtHeader;\n\t\tDWORD dwCodeBase;\n\t\tDWORD dwCodeSize;\n\t\tDWORD dwPatchBase;\n\t\tDWORD dwOldProtect;\n\n\t\tpDosHeader = (PIMAGE_DOS_HEADER)hd3d;\n\t\tpNtHeader = (PIMAGE_NT_HEADERS)((char*)pDosHeader + pDosHeader->e_lfanew);\n\t\tdwCodeBase = (DWORD)hd3d + pNtHeader->OptionalHeader.BaseOfCode;\n\t\tdwCodeSize = pNtHeader->OptionalHeader.SizeOfCode;\n\n\t\tstatic BYTE wantedBytes[] = {0xB8, 0x00, 0x08, 0x00, 0x00, 0x39};\n\t\tdwPatchBase = (DWORD)memmem((void*)dwCodeBase, dwCodeSize, wantedBytes, sizeof(wantedBytes));\n\t\tif( dwPatchBase ) {\n\t\t\tdwPatchBase++;\n\t\t\tVirtualProtect((LPVOID)dwPatchBase, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect);\n\t\t\t*(DWORD*)dwPatchBase = ~0;\n\t\t\tVirtualProtect((LPVOID)dwPatchBase, 4, dwOldProtect, &dwOldProtect);\n\t\t}\n\t}\n#endif // (DIRECT3D_VERSION <= 0x700)\n\treturn ( WinVidRegisterGameWindowClass() &&\n\t\t\t WinVidCreateGameWindow() &&\n\t\t\t WinVidGetDisplayAdapters() &&\n\t\t\t DisplayAdapterList.dwCount &&\n\t\t\t WinVidGetDisplayModes() );\n}\n\nbool __cdecl WinVidGetDisplayAdapters() {\n\tDISPLAY_ADAPTER_NODE *node, *nextNode;\n\n\tfor( node = DisplayAdapterList.head; node; node = nextNode ) {\n\t\tnextNode = node->next;\n\t\tDisplayModeListDelete(&node->body.swDispModeList);\n\t\tDisplayModeListDelete(&node->body.hwDispModeList);\n\t\tFlaggedStringDelete(&node->body.driverName);\n\t\tFlaggedStringDelete(&node->body.driverDescription);\n\t\tdelete(node);\n\t}\n\n\tDisplayAdapterList.head = NULL;\n\tDisplayAdapterList.tail = NULL;\n\tDisplayAdapterList.dwCount = 0;\n\n\tPrimaryDisplayAdapter = NULL;\n\n\tif( !EnumerateDisplayAdapters(&DisplayAdapterList) )\n\t\treturn false;\n\n#if (DIRECT3D_VERSION >= 0x900)\n\tPrimaryDisplayAdapter = DisplayAdapterList.head;\n\treturn ( PrimaryDisplayAdapter != NULL );\n#else // (DIRECT3D_VERSION >= 0x900)\n\tfor( node = DisplayAdapterList.head; node; node = node->next ) {\n\t\tif( node->body.lpAdapterGuid == NULL ) { // Primary adapter GUID is NULL\n\t\t\tPrimaryDisplayAdapter = node;\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\nvoid __thiscall FlaggedStringDelete(STRING_FLAGGED *item) {\n\tif( item->isPresented && item->lpString ) {\n\t\tdelete[] item->lpString;\n\t\titem->lpString = NULL;\n\t\titem->isPresented = false;\n\t}\n}\n\nbool __cdecl EnumerateDisplayAdapters(DISPLAY_ADAPTER_LIST *displayAdapterList) {\n#if (DIRECT3D_VERSION >= 0x900)\n\tbool d3dClean = false;\n\tif( D3D == NULL ) {\n\t\tif( !D3DCreate() ) return false;\n\t\td3dClean = true;\n\t}\n\tUINT num = D3D->GetAdapterCount();\n\tfor( UINT i = 0; i < num; ++i ) {\n\t\tD3DADAPTER_IDENTIFIER9 id;\n\t\tD3DCAPS9 caps;\n\t\tif( FAILED(D3D->GetAdapterIdentifier(i, 0, &id)) || FAILED(D3D->GetDeviceCaps(i, D3DDEVTYPE_HAL, &caps)) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tDISPLAY_ADAPTER_NODE *listNode = new DISPLAY_ADAPTER_NODE;\n\t\tif( listNode == NULL ) break;\n\n\t\tlistNode->next = NULL;\n\t\tlistNode->previous = displayAdapterList->tail;\n\n\t\tFlaggedStringsCreate(&listNode->body);\n\t\tDisplayModeListInit(&listNode->body.hwDispModeList);\n\t\tDisplayModeListInit(&listNode->body.swDispModeList);\n\n\t\tif( !displayAdapterList->head )\n\t\t\tdisplayAdapterList->head = listNode;\n\n\t\tif( displayAdapterList->tail )\n\t\t\tdisplayAdapterList->tail->next = listNode;\n\n\t\tdisplayAdapterList->tail = listNode;\n\t\tdisplayAdapterList->dwCount++;\n\n\t\tlistNode->body.adapterGuid = id.DeviceIdentifier;\n\t\tlistNode->body.lpAdapterGuid = &listNode->body.adapterGuid;\n\n\t\tlstrcpy(listNode->body.driverDescription.lpString, id.Description);\n\t\tlstrcpy(listNode->body.driverName.lpString, id.DeviceName);\n\n\t\tlistNode->body.index = i;\n\t\tlistNode->body.caps = caps;\n\t}\n\tif( d3dClean ) D3DRelease();\n\treturn true;\n#else // (DIRECT3D_VERSION >= 0x900)\n\treturn SUCCEEDED(DirectDrawEnumerate(EnumDisplayAdaptersCallback, (LPVOID)displayAdapterList));\n#endif // (DIRECT3D_VERSION >= 0x900)\n}\n\n#if (DIRECT3D_VERSION < 0x900)\nBOOL WINAPI EnumDisplayAdaptersCallback(GUID FAR *lpGUID, LPTSTR lpDriverDescription, LPTSTR lpDriverName, LPVOID lpContext) {\n\tDDCAPS driverCaps;\n\tDDCAPS helCaps;\n\tDISPLAY_ADAPTER_NODE *listNode = new DISPLAY_ADAPTER_NODE;\n\tDISPLAY_ADAPTER_LIST *adapterList = (DISPLAY_ADAPTER_LIST *)lpContext;\n\n\tif( listNode == NULL || !DDrawCreate(lpGUID) )\n\t\treturn TRUE;\n\n\tmemset(&driverCaps, 0, sizeof(driverCaps));\n\tmemset(&helCaps, 0, sizeof(helCaps));\n\tdriverCaps.dwSize = sizeof(DDCAPS);\n\thelCaps.dwSize = sizeof(DDCAPS);\n\n\tif FAILED(DDraw->GetCaps(&driverCaps, &helCaps))\n\t\tgoto CLEANUP;\n\n\tlistNode->next = NULL;\n\tlistNode->previous = adapterList->tail;\n\n\tFlaggedStringsCreate(&listNode->body);\n\tDisplayModeListInit(&listNode->body.hwDispModeList);\n\tDisplayModeListInit(&listNode->body.swDispModeList);\n\n\tif( !adapterList->head )\n\t\tadapterList->head = listNode;\n\n\tif( adapterList->tail )\n\t\tadapterList->tail->next = listNode;\n\n\tadapterList->tail = listNode;\n\tadapterList->dwCount++;\n\n\tif( lpGUID ) {\n\t\t// Any secondary adapter\n\t\tlistNode->body.adapterGuid = *lpGUID;\n\t\tlistNode->body.lpAdapterGuid = &listNode->body.adapterGuid;\n\t} else {\n\t\t// Primary adapter (GUID is NULL)\n\t\tmemset(&listNode->body.adapterGuid, 0, sizeof(GUID));\n\t\tlistNode->body.lpAdapterGuid = NULL;\n\t}\n\n\tlstrcpy(listNode->body.driverDescription.lpString, lpDriverDescription);\n\tlstrcpy(listNode->body.driverName.lpString, lpDriverName);\n\n\tlistNode->body.driverCaps = driverCaps;\n\tlistNode->body.helCaps = helCaps;\n\n\tlistNode->body.screenWidth = 0;\n\tlistNode->body.hwRenderSupported = false;\n\tlistNode->body.swWindowedSupported = false;\n\tlistNode->body.hwWindowedSupported = false;\n\tlistNode->body.isVgaMode1Presented = false;\n\tlistNode->body.isVgaMode2Presented = false;\n\n\tEnumerate3DDevices(&listNode->body);\n\nCLEANUP :\n\tDDrawRelease();\n\treturn TRUE;\n}\n#endif // (DIRECT3D_VERSION < 0x900)\n\nvoid __thiscall FlaggedStringsCreate(DISPLAY_ADAPTER *adapter) {\n\tLPTSTR lpDriverDescription = new char[256];\n\tLPTSTR lpDriverName = new char[256];\n\n\tif( lpDriverDescription ) {\n\t\t*lpDriverDescription = 0;\n\t\tadapter->driverDescription.lpString = lpDriverDescription;\n\t\tadapter->driverDescription.isPresented = true;\n\t}\n\n\tif( lpDriverName ) {\n\t\t*lpDriverName = 0;\n\t\tadapter->driverName.lpString = lpDriverName;\n\t\tadapter->driverName.isPresented = true;\n\t}\n}\n\nbool __cdecl WinVidRegisterGameWindowClass() {\n\tWNDCLASSEXA wndClass;\n\n\tmemset(&wndClass, 0, sizeof(wndClass));\n\twndClass.cbSize = sizeof(wndClass);\n\twndClass.style = 0;\n\twndClass.lpfnWndProc = WinVidGameWindowProc;\n\twndClass.hInstance = GameModule;\n\twndClass.hIcon = LoadIcon(GameModule, MAKEINTRESOURCE(IDI_MAINICON));\n\twndClass.hCursor = LoadCursor(NULL, IDC_ARROW);\n\twndClass.lpszClassName = GameClassName;\n\n\treturn ( RegisterClassEx(&wndClass) != 0 );\n}\n\nLRESULT CALLBACK WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {\n\tHDC hdc;\n#if (DIRECT3D_VERSION < 0x900)\n\tLPDDS surface;\n#endif // (DIRECT3D_VERSION < 0x900)\n\tHBRUSH hBrush;\n\tPAINTSTRUCT paint;\n#ifdef FEATURE_AUDIO_IMPROVED\n\tstatic DWORD cdVolume = 0;\n#endif // FEATURE_AUDIO_IMPROVED\n\n\tif( IsFmvPlaying ) {\n\t\tswitch( Msg ) {\n\t\t\tcase WM_DESTROY :\n\t\t\t\tIsGameWindowCreated = false;\n\t\t\t\tHGameWindow = NULL;\n\t\t\t\tPostQuitMessage(0);\n\t\t\t\tbreak;\n\n\t\t\tcase WM_MOVE :\n\t\t\t\tGameWindowPositionX = (int)(short)LOWORD(lParam);\n\t\t\t\tGameWindowPositionY = (int)(short)HIWORD(lParam);\n\t\t\t\tbreak;\n\n\t\t\tcase WM_ACTIVATEAPP :\n\t\t\t\tIsGameWindowActive = ( wParam != 0 );\n\t\t\t\tbreak;\n\n\t\t\tcase WM_SYSCOMMAND :\n\t\t\t\tif( wParam == SC_KEYMENU ) return 0;\n\t\t\t\tbreak;\n\t\t}\n\t\treturn DefWindowProc(hWnd, Msg, wParam, lParam);\n\t}\n\n\tswitch( Msg ) {\n\t\tcase WM_CREATE :\n\t\t\tIsGameWindowCreated = true;\n\t\t\tbreak;\n\n\t\tcase WM_DESTROY :\n\t\t\tIsGameWindowCreated = false;\n\t\t\tHGameWindow = NULL;\n\t\t\tPostQuitMessage(0);\n\t\t\tbreak;\n\n\t\tcase WM_MOVE :\n\t\t\tGameWindowPositionX = (int)(short)LOWORD(lParam);\n\t\t\tGameWindowPositionY = (int)(short)HIWORD(lParam);\n\t\t\tbreak;\n\n\t\tcase WM_SIZE:\n\t\t\tswitch( wParam ) {\n\t\t\t\tcase SIZE_RESTORED :\n\t\t\t\t\tIsGameWindowMinimized = false;\n\t\t\t\t\tIsGameWindowMaximized = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase SIZE_MAXIMIZED :\n\t\t\t\t\tIsGameWindowMinimized = false;\n\t\t\t\t\tIsGameWindowMaximized = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase SIZE_MINIMIZED :\n\t\t\t\t\tIsGameWindowMinimized = true;\n\t\t\t\t\tIsGameWindowMaximized = false;\n\t\t\t\t\t// fall through\n\t\t\t\tdefault :\n\t\t\t\t\treturn DefWindowProc(hWnd, Msg, wParam, lParam);\n\t\t\t}\n\n\t\t\tif( IsGameFullScreen ||\n\t\t\t\t((int)(short)LOWORD(lParam) == GameWindowWidth && (int)(short)HIWORD(lParam) == GameWindowHeight) )\n\t\t\t\tbreak;\n\n\t\t\tGameWindowWidth  = (int)(short)LOWORD(lParam);\n\t\t\tGameWindowHeight = (int)(short)HIWORD(lParam);\n\t\t\tif( IsGameWindowUpdating )\n\t\t\t\tbreak;\n\n\t\t\tUpdateGameResolution();\n\t\t\tbreak;\n\n\t\tcase WM_PAINT :\n\t\t\thdc = BeginPaint(hWnd, &paint);\n#if (DIRECT3D_VERSION >= 0x900)\n\t\t\tif( IsGameFullScreen || D3DDev == NULL || FAILED(D3DDev->TestCooperativeLevel()) ) {\n\t\t\t\thBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);\n\t\t\t\tFillRect(hdc, &paint.rcPaint, hBrush);\n\t\t\t} else {\n\t\t\t\tD3DDev->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0, 0);\n\t\t\t\tD3DDev->Present(NULL, NULL, NULL, NULL);\n\t\t\t}\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\t\tsurface = ( SavedAppSettings.RenderMode == RM_Software ) ? RenderBufferSurface : BackBufferSurface;\n\t\t\tif( IsGameFullScreen || !PrimaryBufferSurface || !surface ) {\n\t\t\t\thBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);\n\t\t\t\tFillRect(hdc, &paint.rcPaint, hBrush);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif( SavedAppSettings.RenderMode == RM_Software &&\n\t\t\t\t\t!WinVidCheckGameWindowPalette(hWnd) &&\n\t\t\t\t\tRenderBufferSurface )\n\t\t\t\t{\n\t\t\t\t\tWinVidClearBuffer(RenderBufferSurface, NULL, 0);\n\t\t\t\t}\n\t\t\t\tUpdateFrame(false, NULL);\n\t\t\t}\n#endif // (DIRECT3D_VERSION >= 0x900)\n\t\t\tEndPaint(hWnd, &paint);\n\t\t\treturn 0;\n\n\t\tcase WM_ACTIVATE :\n#if (DIRECT3D_VERSION < 0x900)\n\t\t\tif( LOWORD(wParam) && DDrawPalette && PrimaryBufferSurface )\n\t\t\t\tPrimaryBufferSurface->SetPalette(DDrawPalette);\n#endif // (DIRECT3D_VERSION < 0x900)\n\t\t\tbreak;\n\n\t\tcase WM_ERASEBKGND :\n\t\t\treturn 1;\n\n\t\tcase WM_ACTIVATEAPP :\n#ifdef FEATURE_AUDIO_IMPROVED\n\t\t\t// NOTE: If CD audio volume is set to zero, music is paused.\n\t\t\t// To resume the music, the volume must be set to non zero value.\n\t\t\tif( wParam && !IsGameWindowActive ) {\n\t\t\t\tif( cdVolume ) {\n\t\t\t\t\tS_CDVolume(cdVolume);\n\t\t\t\t}\n\t\t\t} else if ( !wParam && IsGameWindowActive ) {\n\t\t\t\tcdVolume = S_GetCDVolume();\n\t\t\t\tS_CDVolume(0);\n\t\t\t}\n#endif // FEATURE_AUDIO_IMPROVED\n#ifdef FEATURE_INPUT_IMPROVED\n\t\t\tif( !wParam && IsGameWindowActive ) {\n\t\t\t\tJoyVibrationMute();\n\t\t\t}\n#endif // FEATURE_INPUT_IMPROVED\n\t\t\tif( wParam && !IsGameWindowActive && IsGameFullScreen && SavedAppSettings.RenderMode == RM_Hardware )\n\t\t\t\tWinVidNeedToResetBuffers = true;\n\t\t\tIsGameWindowActive = ( wParam != 0 );\n\t\t\tbreak;\n\n\t\tcase WM_SETCURSOR :\n\t\t\tif( IsGameFullScreen ) {\n\t\t\t\tSetCursor(NULL);\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase WM_GETMINMAXINFO :\n\t\t\tif( WinVidGetMinMaxInfo((LPMINMAXINFO)lParam) )\n\t\t\t\treturn 0;\n\t\t\tbreak;\n\n\t\tcase WM_NCPAINT :\n\t\tcase WM_NCLBUTTONDOWN :\n\t\tcase WM_NCLBUTTONDBLCLK :\n\t\tcase WM_NCRBUTTONDOWN :\n\t\tcase WM_NCRBUTTONDBLCLK :\n\t\tcase WM_NCMBUTTONDOWN :\n\t\tcase WM_NCMBUTTONDBLCLK :\n\t\t\tif( IsGameFullScreen ) return 0;\n\t\t\tbreak;\n\n\t\tcase WM_SYSCOMMAND :\n\t\t\tif( wParam == SC_KEYMENU ) return 0;\n\t\t\tbreak;\n\n\t\tcase WM_SIZING :\n\t\t\tWinVidResizeGameWindow(hWnd, wParam, (LPRECT)lParam);\n\t\t\tbreak;\n\n\t\tcase WM_MOVING :\n\t\t\tif( IsGameFullScreen || IsGameWindowMaximized ) {\n\t\t\t\tGetWindowRect(hWnd, (LPRECT)lParam);\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase WM_ENTERSIZEMOVE :\n\t\t\tIsGameWindowChanging = true;\n\t\t\tbreak;\n\n\t\tcase WM_EXITSIZEMOVE :\n\t\t\tIsGameWindowChanging = false;\n\t\t\tbreak;\n\n#if (DIRECT3D_VERSION < 0x900)\n\t\tcase WM_PALETTECHANGED :\n\t\t\tif( hWnd != (HWND)wParam && !IsGameFullScreen && DDrawPalette )\n\t\t\t\tInvalidateRect(hWnd, NULL, FALSE);\n\t\t\tbreak;\n#endif // (DIRECT3D_VERSION < 0x900)\n\t}\n\treturn DefWindowProc(hWnd, Msg, wParam, lParam);\n}\n\nvoid __cdecl WinVidResizeGameWindow(HWND hWnd, int edge, LPRECT rect) {\n\tbool isShiftPressed;\n\tint width, height;\n\n\tif( IsGameFullScreen ) {\n\t\trect->left = 0;\n\t\trect->top = 0;\n\t\trect->right = FullScreenWidth;\n\t\trect->bottom = FullScreenHeight;\n\t}\n\n\tisShiftPressed = ( GetAsyncKeyState(VK_SHIFT) < 0 );\n\twidth  = rect->right  - rect->left;\n\theight = rect->bottom - rect->top;\n\tGameWindowCalculateSizeFromClientByZero(&width, &height);\n\n\tif( edge == WMSZ_TOP || edge == WMSZ_BOTTOM ) {\n\t\tif( isShiftPressed )\n\t\t\theight &= ~0x1F;\n\t\twidth = CalculateWindowWidth(width, height);\n\t} else {\n\t\tif( isShiftPressed )\n\t\t\twidth &= ~0x1F;\n\t\theight = CalculateWindowHeight(width, height);\n\t}\n\n\tif( IsMinWindowSizeSet ) {\n\t\tif( width < MinWindowClientWidth )\n\t\t\twidth = MinWindowClientWidth;\n\t\tif( height < MinWindowClientHeight )\n\t\t\theight = MinWindowClientHeight;\n\t}\n\n\tif( IsMaxWindowSizeSet ) {\n\t\tif( width > MaxWindowClientWidth )\n\t\t\twidth = MaxWindowClientWidth;\n\t\tif( height > MaxWindowClientHeight )\n\t\t\theight = MaxWindowClientHeight;\n\t}\n\n\tGameWindowCalculateSizeFromClient(&width, &height);\n\n\tswitch( edge ) {\n\t\tcase WMSZ_TOPLEFT :\n\t\t\trect->left = rect->right - width;\n\t\t\trect->top = rect->bottom - height;\n\t\t\tbreak;\n\n\t\tcase WMSZ_RIGHT :\n\t\tcase WMSZ_BOTTOM :\n\t\tcase WMSZ_BOTTOMRIGHT :\n\t\t\trect->right = rect->left + width;\n\t\t\trect->bottom = rect->top + height;\n\t\t\tbreak;\n\n\t\tcase WMSZ_LEFT :\n\t\tcase WMSZ_BOTTOMLEFT :\n\t\t\trect->left = rect->right - width;\n\t\t\trect->bottom = rect->top + height;\n\t\t\tbreak;\n\n\t\tcase WMSZ_TOP :\n\t\tcase WMSZ_TOPRIGHT :\n\t\t\trect->right = rect->left + width;\n\t\t\trect->top = rect->bottom - height;\n\t\t\tbreak;\n\t}\n}\n\nbool __cdecl WinVidCheckGameWindowPalette(HWND hWnd) {\n\tHDC hdc;\n\tPALETTEENTRY sysPalette[256];\n\tRGB888 bufPalette[256];\n\n\thdc = GetDC(hWnd);\n\tif( hdc == NULL )\n\t\treturn false;\n\n\tGetSystemPaletteEntries(hdc, 0, 256, sysPalette);\n\tReleaseDC(hWnd, hdc);\n\n\tfor( int i=0; i < 256; ++i ) {\n\t\tbufPalette[i].red   = sysPalette[i].peRed;\n\t\tbufPalette[i].green = sysPalette[i].peGreen;\n\t\tbufPalette[i].blue  = sysPalette[i].peBlue;\n\t}\n\n\treturn ( !memcmp(bufPalette, GamePalette8, sizeof(bufPalette)) );\n}\n\nbool __cdecl WinVidCreateGameWindow() {\n\tRECT rect;\n\n\tIsGameWindowActive\t\t= true;\n\tIsGameWindowShow\t\t= true;\n\tIsDDrawGameWindowShow\t= false;\n\tIsMessageLoopClosed\t\t= false;\n\tIsGameWindowUpdating\t= false;\n\tIsGameWindowMinimized\t= false;\n\tIsGameWindowMaximized\t= false;\n\tIsGameWindowCreated\t\t= false;\n\tIsGameFullScreen\t\t= false;\n\tIsMinMaxInfoSpecial\t\t= false;\n\tIsGameWindowChanging\t= false;\n\tWinVidClearMinWindowSize();\n\tWinVidClearMaxWindowSize();\n\n\tHGameWindow = CreateWindowEx(WS_EX_APPWINDOW, GameClassName, GameWindowName, WS_OVERLAPPEDWINDOW,\n\t\t\t\t\t\t\t\tCW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,\n\t\t\t\t\t\t\t\tNULL, NULL, GameModule, NULL);\n\tif( HGameWindow == NULL)\n\t\treturn false;\n\n\tGetWindowRect(HGameWindow, &rect);\n\tGameWindow_X = rect.left;\n\tGameWindow_Y = rect.top;\n\tWinVidHideGameWindow();\n\n\treturn true;\n}\n\nvoid __cdecl WinVidFreeWindow() {\n\tWinVidExitMessage();\n\tUnregisterClass(GameClassName, GameModule);\n}\n\nvoid __cdecl WinVidExitMessage() {\n\tif( HGameWindow && IsWindow(HGameWindow) ) {\n\t\tPostMessage(HGameWindow, WM_CLOSE, 0, 0);\n\t\twhile( WinVidSpinMessageLoop(false) ) /* just wait */;\n\t\tHGameWindow = NULL;\n\t}\n}\n\nDISPLAY_ADAPTER_NODE *__cdecl WinVidGetDisplayAdapter(GUID *lpGuid) {\n\tDISPLAY_ADAPTER_NODE *adapter;\n\n\tif( lpGuid != NULL ) {\n\t\tfor( adapter = DisplayAdapterList.head; adapter; adapter = adapter->next ) {\n\t\t\tif( !memcmp(&adapter->body.adapterGuid, lpGuid, sizeof(GUID)) )\n\t\t\t\treturn adapter;\n\t\t}\n\t}\n\treturn PrimaryDisplayAdapter;\n}\n\nvoid __cdecl WinVidStart() {\n\tif( SavedAppSettings.PreferredDisplayAdapter == NULL )\n#if (DIRECT3D_VERSION >= 0x900)\n\t\tthrow ERR_CantInitRenderer;\n#else // (DIRECT3D_VERSION >= 0x900)\n\t\tthrow ERR_CantCreateDirectDraw;\n#endif // (DIRECT3D_VERSION >= 0x900)\n\n\tDISPLAY_ADAPTER *preferred = &SavedAppSettings.PreferredDisplayAdapter->body;\n\tCurrentDisplayAdapter = *preferred;\n\n\tFlaggedStringCopy(&CurrentDisplayAdapter.driverDescription, &preferred->driverDescription);\n\tFlaggedStringCopy(&CurrentDisplayAdapter.driverName, &preferred->driverName);\n\n\tDisplayModeListInit(&CurrentDisplayAdapter.hwDispModeList);\n\tDisplayModeListCopy(&CurrentDisplayAdapter.hwDispModeList, &preferred->hwDispModeList);\n\n\tDisplayModeListInit(&CurrentDisplayAdapter.swDispModeList);\n\tDisplayModeListCopy(&CurrentDisplayAdapter.swDispModeList, &preferred->swDispModeList);\n\n#if (DIRECT3D_VERSION < 0x900)\n\tif( !DDrawCreate(CurrentDisplayAdapter.lpAdapterGuid) )\n\t\tthrow ERR_CantCreateDirectDraw;\n#endif // (DIRECT3D_VERSION < 0x900)\n}\n\nvoid __cdecl WinVidFinish() {\n#if (DIRECT3D_VERSION < 0x900)\n\tif( IsDDrawGameWindowShow )\n\t\tHideDDrawGameWindow();\n\tDDrawRelease();\n#endif // (DIRECT3D_VERSION < 0x900)\n}\n\nvoid __thiscall DisplayModeListInit(DISPLAY_MODE_LIST *pList) {\n\tpList->head = NULL;\n\tpList->tail = NULL;\n\tpList->dwCount = 0;\n}\n\nvoid __thiscall DisplayModeListDelete(DISPLAY_MODE_LIST *pList) {\n\tDISPLAY_MODE_NODE *node;\n\tDISPLAY_MODE_NODE *nextNode;\n\n\tfor( node = pList->head; node; node = nextNode ) {\n\t\tnextNode = node->next;\n\t\tdelete(node);\n\t}\n\tDisplayModeListInit(pList);\n}\n\nDISPLAY_MODE *__thiscall InsertDisplayMode(DISPLAY_MODE_LIST *modeList, DISPLAY_MODE_NODE *before) {\n\tif( !before || !before->previous )\n\t\treturn InsertDisplayModeInListHead(modeList);\n\n\tDISPLAY_MODE_NODE *node = new DISPLAY_MODE_NODE;\n\tif( !node )\n\t\treturn NULL;\n\n\tbefore->previous->next = node;\n\tnode->previous = before->previous;\n\n\tbefore->previous = node;\n\tnode->next = before;\n\n\tmodeList->dwCount++;\n\treturn &node->body;\n}\n\nDISPLAY_MODE *__thiscall InsertDisplayModeInListHead(DISPLAY_MODE_LIST *modeList) {\n\tDISPLAY_MODE_NODE *node = new DISPLAY_MODE_NODE;\n\tif( !node )\n\t\treturn NULL;\n\n\tnode->next = modeList->head;\n\tnode->previous = NULL;\n\n\tif( modeList->head )\n\t\tmodeList->head->previous = node;\n\n\tif( !modeList->tail )\n\t\tmodeList->tail = node;\n\n\tmodeList->head = node;\n\tmodeList->dwCount++;\n\treturn &node->body;\n}\n\nDISPLAY_MODE *__thiscall InsertDisplayModeInListTail(DISPLAY_MODE_LIST *modeList) {\n\tDISPLAY_MODE_NODE *node = new DISPLAY_MODE_NODE;\n\tif( !node )\n\t\treturn NULL;\n\n\tnode->next = NULL;\n\tnode->previous = modeList->tail;\n\n\tif( modeList->tail )\n\t\tmodeList->tail->next = node;\n\n\tif( !modeList->head )\n\t\tmodeList->head = node;\n\n\tmodeList->tail = node;\n\tmodeList->dwCount++;\n\treturn &node->body;\n}\n\n/*\n * Inject function\n */\nvoid Inject_WinVid() {\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00444C80, DDrawCreate);\n\tINJECT(0x00444CE0, DDrawRelease);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00444D20, GameWindowCalculateSizeFromClient);\n\tINJECT(0x00444DA0, GameWindowCalculateSizeFromClientByZero);\n\tINJECT(0x00444E10, WinVidSetMinWindowSize);\n\tINJECT(0x00444E60, WinVidClearMinWindowSize);\n\tINJECT(0x00444E70, WinVidSetMaxWindowSize);\n\tINJECT(0x00444EC0, WinVidClearMaxWindowSize);\n\tINJECT(0x00444ED0, CalculateWindowWidth);\n\tINJECT(0x00444F20, CalculateWindowHeight);\n\tINJECT(0x00444F50, WinVidGetMinMaxInfo);\n\tINJECT(0x00445060, WinVidFindGameWindow);\n\tINJECT(0x00445080, WinVidSpinMessageLoop);\n\tINJECT(0x00445170, WinVidShowGameWindow);\n\tINJECT(0x004451C0, WinVidHideGameWindow);\n\tINJECT(0x00445200, WinVidSetGameWindowSize);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00445240, ShowDDrawGameWindow);\n\tINJECT(0x004452F0, HideDDrawGameWindow);\n\tINJECT(0x00445380, DDrawSurfaceCreate);\n\tINJECT(0x004453D0, DDrawSurfaceRestoreLost);\n\tINJECT(0x00445420, WinVidClearBuffer);\n\tINJECT(0x00445470, WinVidBufferLock);\n\tINJECT(0x004454B0, WinVidBufferUnlock);\n\tINJECT(0x004454E0, WinVidCopyBitmapToBuffer);\n\tINJECT(0x00445570, GetRenderBitDepth);\n\tINJECT(0x00445600, WinVidGetColorBitMasks);\n\tINJECT(0x00445680, BitMaskGetNumberOfBits);\n\tINJECT(0x004456D0, CalculateCompatibleColor);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00445740, WinVidGetDisplayMode);\n\tINJECT(0x004457D0, WinVidGoFullScreen);\n\tINJECT(0x00445860, WinVidGoWindowed);\n\tINJECT(0x00445970, WinVidSetDisplayAdapter);\n\tINJECT(0x00445A50, CompareVideoModes);\n\tINJECT(0x00445AA0, WinVidGetDisplayModes);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00445B00, EnumDisplayModesCallback);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00445EC0, WinVidInit);\n\tINJECT(0x00445F00, WinVidGetDisplayAdapters);\n\tINJECT(0x00445FB0, FlaggedStringDelete);\n\tINJECT(0x00445FD0, EnumerateDisplayAdapters);\n#if (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x00445FF0, EnumDisplayAdaptersCallback);\n#endif // (DIRECT3D_VERSION < 0x900)\n\tINJECT(0x004461B0, FlaggedStringsCreate);\n\tINJECT(0x004461F0, WinVidRegisterGameWindowClass);\n\tINJECT(0x00446260, WinVidGameWindowProc);\n\tINJECT(0x00446870, WinVidResizeGameWindow);\n\tINJECT(0x00446A50, WinVidCheckGameWindowPalette);\n\tINJECT(0x00446B10, WinVidCreateGameWindow);\n\tINJECT(0x00446BE0, WinVidFreeWindow);\n\tINJECT(0x00446C10, WinVidExitMessage);\n\tINJECT(0x00446C60, WinVidGetDisplayAdapter);\n\tINJECT(0x00446CB0, WinVidStart);\n\tINJECT(0x00447030, WinVidFinish);\n\tINJECT(0x00447050, DisplayModeListInit);\n\tINJECT(0x00447060, DisplayModeListDelete);\n//\tINJECT(0x004470A0, InsertDisplayMode); // NOTE: new one is not compatible anymore (original one is junk!!!)\n\tINJECT(0x004470C0, InsertDisplayModeInListHead);\n\tINJECT(0x00447110, InsertDisplayModeInListTail);\n}\n"
  },
  {
    "path": "specific/winvid.h",
    "content": "/*\n * Copyright (c) 2017-2020 Michael Chaban. All rights reserved.\n * Original game is created by Core Design Ltd. in 1997.\n * Lara Croft and Tomb Raider are trademarks of Embracer Group AB.\n *\n * This file is part of TR2Main.\n *\n * TR2Main is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * TR2Main is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with TR2Main.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n#ifndef WINVID_H_INCLUDED\n#define WINVID_H_INCLUDED\n\n#include \"global/types.h\"\n\n/*\n * Function list\n */\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl DDrawCreate(LPGUID lpGUID); // 0x00444C80\nvoid __cdecl DDrawRelease(); // 0x00444CE0\n#endif // (DIRECT3D_VERSION < 0x900)\nvoid __cdecl GameWindowCalculateSizeFromClient(int *width, int *height); // 0x00444D20\nvoid __cdecl GameWindowCalculateSizeFromClientByZero(int *width, int *height); // 0x00444DA0\nvoid __cdecl WinVidSetMinWindowSize(int width, int height); // 0x00444E10\nvoid __cdecl WinVidClearMinWindowSize(); // 0x00444E60\nvoid __cdecl WinVidSetMaxWindowSize(int width, int height); // 0x00444E70\nvoid __cdecl WinVidClearMaxWindowSize(); // 0x00444EC0\nint __cdecl CalculateWindowWidth(int width, int height); // 0x00444ED0\nint __cdecl CalculateWindowHeight(int width, int height); // 0x00444F20\nbool __cdecl WinVidGetMinMaxInfo(LPMINMAXINFO info); // 0x00444F50\nHWND __cdecl WinVidFindGameWindow(); // 0x00445060\nbool __cdecl WinVidSpinMessageLoop(bool needWait); // 0x00445080\nvoid __cdecl WinVidShowGameWindow(int nCmdShow); // 0x00445170\nvoid __cdecl WinVidHideGameWindow(); // 0x004451C0\nvoid __cdecl WinVidSetGameWindowSize(int width, int height); // 0x00445200\n#if (DIRECT3D_VERSION < 0x900)\nbool __cdecl ShowDDrawGameWindow(bool active); // 0x00445240\nbool __cdecl HideDDrawGameWindow(); // 0x004452F0\nHRESULT __cdecl DDrawSurfaceCreate(LPDDSDESC dsp, LPDDS *surface); // 0x00445380\nHRESULT __cdecl DDrawSurfaceRestoreLost(LPDDS surface1, LPDDS surface2, bool blank); // 0x004453D0\nbool __cdecl WinVidClearBuffer(LPDDS surface, LPRECT rect, DWORD fillColor); // 0x00445420\nHRESULT __cdecl WinVidBufferLock(LPDDS surface, LPDDSDESC desc, DWORD flags); // 0x00445470\nHRESULT __cdecl WinVidBufferUnlock(LPDDS surface, LPDDSDESC desc); // 0x004454B0\nbool __cdecl WinVidCopyBitmapToBuffer(LPDDS surface, BYTE *bitmap); // 0x004454E0\nDWORD __cdecl GetRenderBitDepth(DWORD dwRGBBitCount); // 0x00445570\nvoid __thiscall WinVidGetColorBitMasks(COLOR_BIT_MASKS *bm, LPDDPIXELFORMAT pixelFormat); // 0x00445600\nvoid __cdecl BitMaskGetNumberOfBits(DWORD bitMask, DWORD *bitDepth, DWORD *bitOffset); // 0x00445680\nDWORD __cdecl CalculateCompatibleColor(COLOR_BIT_MASKS *mask, int red, int green, int blue, int alpha); // 0x004456D0\n#endif // (DIRECT3D_VERSION < 0x900)\nbool __cdecl WinVidGetDisplayMode(DISPLAY_MODE *dispMode); // 0x00445740\nbool __cdecl WinVidGoFullScreen(DISPLAY_MODE *dispMode); // 0x004457D0\nbool __cdecl WinVidGoWindowed(int width, int height, DISPLAY_MODE *dispMode); // 0x00445860\nvoid __cdecl WinVidSetDisplayAdapter(DISPLAY_ADAPTER *dispAdapter); // 0x00445970\nbool __thiscall CompareVideoModes(DISPLAY_MODE *mode1, DISPLAY_MODE *mode2); // 0x00445A50\nbool __cdecl WinVidGetDisplayModes(); // 0x00445AA0\n#if (DIRECT3D_VERSION < 0x900)\nHRESULT WINAPI EnumDisplayModesCallback(LPDDSDESC lpDDSurfaceDesc, LPVOID lpContext); // 0x00445B00\n#endif // (DIRECT3D_VERSION < 0x900)\nbool __cdecl WinVidInit(); // 0x00445EC0\nbool __cdecl WinVidGetDisplayAdapters(); // 0x00445F00\nvoid __thiscall FlaggedStringDelete(STRING_FLAGGED *item); // 0x00445FB0\nbool __cdecl EnumerateDisplayAdapters(DISPLAY_ADAPTER_LIST *displayAdapterList); // 0x00445FD0\n#if (DIRECT3D_VERSION < 0x900)\nBOOL WINAPI EnumDisplayAdaptersCallback(GUID FAR *lpGUID, LPTSTR lpDriverDescription, LPTSTR lpDriverName, LPVOID lpContext); // 0x00445FF0\n#endif // (DIRECT3D_VERSION < 0x900)\nvoid __thiscall FlaggedStringsCreate(DISPLAY_ADAPTER *adapter); // 0x004461B0\nbool __cdecl WinVidRegisterGameWindowClass(); // 0x004461F0\nLRESULT CALLBACK WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); // 0x00446260\nvoid __cdecl WinVidResizeGameWindow(HWND hWnd, int edge, LPRECT rect); // 0x00446870\nbool __cdecl WinVidCheckGameWindowPalette(HWND hWnd); // 0x00446A50\nbool __cdecl WinVidCreateGameWindow(); // 0x00446B10\nvoid __cdecl WinVidFreeWindow(); // 0x00446BE0\nvoid __cdecl WinVidExitMessage(); // 0x00446C10\nDISPLAY_ADAPTER_NODE *__cdecl WinVidGetDisplayAdapter(GUID *lpGuid); // 0x00446C60\nvoid __cdecl WinVidStart(); // 0x00446CB0\nvoid __cdecl WinVidFinish(); // 0x00447030\nvoid __thiscall DisplayModeListInit(DISPLAY_MODE_LIST *pList); // 0x00447050\nvoid __thiscall DisplayModeListDelete(DISPLAY_MODE_LIST *pList); // 0x00447060\nDISPLAY_MODE *__thiscall InsertDisplayMode(DISPLAY_MODE_LIST *modeList, DISPLAY_MODE_NODE *before); // 0x004470A0\nDISPLAY_MODE *__thiscall InsertDisplayModeInListHead(DISPLAY_MODE_LIST *modeList); // 0x004470C0\nDISPLAY_MODE *__thiscall InsertDisplayModeInListTail(DISPLAY_MODE_LIST *modeList); // 0x00447110\n\n#endif // WINVID_H_INCLUDED\n"
  }
]