Files
2026-09-14 16:26:34 -07:00

1737 lines
57 KiB
C++

// Minecraft.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <assert.h>
#include <shellapi.h>
#include "GameConfig\Minecraft.spa.h"
#include "..\MinecraftServer.h"
#include "..\LocalPlayer.h"
#include "..\..\Minecraft.World\ItemInstance.h"
#include "..\..\Minecraft.World\MapItem.h"
#include "..\..\Minecraft.World\Recipes.h"
#include "..\..\Minecraft.World\Recipy.h"
#include "..\..\Minecraft.World\Language.h"
#include "..\..\Minecraft.World\StringHelpers.h"
#include "..\..\Minecraft.World\AABB.h"
#include "..\..\Minecraft.World\Vec3.h"
#include "..\..\Minecraft.World\Level.h"
#include "..\..\Minecraft.World\net.minecraft.world.level.tile.h"
#include "..\ClientConnection.h"
#include "..\User.h"
#include "..\..\Minecraft.World\Socket.h"
#include "..\..\Minecraft.World\ThreadName.h"
#include "..\..\Minecraft.Client\StatsCounter.h"
#include "..\ConnectScreen.h"
#include "..\..\Minecraft.Client\Tesselator.h"
#include "..\..\Minecraft.Client\Options.h"
#include "Sentient\SentientManager.h"
#include "..\..\Minecraft.World\IntCache.h"
#include "..\Textures.h"
#include "Resource.h"
#include "..\..\Minecraft.World\compression.h"
#include "..\..\Minecraft.World\OldChunkStorage.h"
#include "Windows64_Minecraft.h"
#include "Xbox/resource.h"
#include <vector>
#include "..\Common\UI\DirectTextEdit.h"
#include "..\Common\UI\UIControl_TextInput.h"
#include "..\Common\UI\UIScene.h"
BOOL g_bResolutionSetByCMD = FALSE;
HINSTANCE hMyInst;
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };
char chGlobalText[256];
uint16_t ui16GlobalText[256];
#define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device)
#define NUM_PROFILE_VALUES 5
#define NUM_PROFILE_SETTINGS 4
DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]=
{
0,0,0,0,0
};
//str1k3r - request dedicated GPU from AMD and NVIDIA drivers
extern "C"
{
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
__declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
}
BOOL g_bWidescreen = TRUE;
char g_Username[32];
BOOL g_isFullscreen = FALSE;
int g_iScreenWidth = 1280;
int g_iScreenHeight = 720;
int g_iWindowClientW = 1280;
int g_iWindowClientH = 720;
static bool s_bEscapeKeyPrev = false;
static bool s_bMenuMouseLPrev = false;
static bool s_bMenuMouseRPrev = false;
static int s_iWheelCarry = 0;
static void TickMenuNavKeys(int iPad, bool bMenuOpen)
{
struct NavKey { int vk; int altVk; unsigned int action; bool repeat; bool prev; };
static NavKey s_keys[] =
{
{ 'W', VK_UP, ACTION_MENU_UP, true, false },
{ 'S', VK_DOWN, ACTION_MENU_DOWN, true, false },
{ 'A', VK_LEFT, ACTION_MENU_LEFT, true, false },
{ 'D', VK_RIGHT, ACTION_MENU_RIGHT, true, false },
{ 'F', VK_RETURN, ACTION_MENU_OK, false, false },
{ 'Q', 0, ACTION_MENU_LEFT_SCROLL, false, false },
{ 'E', 0, ACTION_MENU_RIGHT_SCROLL, false, false },
};
bool bActive = bMenuOpen && !DirectTextEdit::IsActive();
for (int i = 0; i < sizeof(s_keys) / sizeof(s_keys[0]); ++i)
{
NavKey &k = s_keys[i];
bool down = InputManager.IsKeyDown(k.vk) || (k.altVk != 0 && InputManager.IsKeyDown(k.altVk));
if (bActive)
{
unsigned int button = InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), k.action);
if (k.repeat)
{
if (down)
InputManager.MapTouchInput(iPad, button);
}
else if (down && !k.prev)
{
InputManager.MapTouchInput(iPad, button);
}
}
k.prev = down;
}
}
int g_iPendingHotbarScroll = 0;
static Windows64LaunchArgs ParseLaunchArgs()
{
Windows64LaunchArgs args = {};
args.resolution = 0;
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argv == nullptr)
return args;
if (argc > 1 && lstrlenW(argv[1]) == 1)
{
if (argv[1][0] >= L'1' && argv[1][0] <= L'6')
args.resolution = argv[1][0] - L'0';
}
for (int i = 1; i < argc; ++i)
{
if (_wcsicmp(argv[i], L"-fullscreen") == 0)
{
args.fullscreen = true;
}
else if (_wcsicmp(argv[i], L"-no-vsync") == 0) //str1k3r - we all remember -femboysarecool right? also thank u neoapps for naming this arg
{
args.vsync = true;
}
else if (_wcsicmp(argv[i], L"-resolution") == 0)
{
if (i + 1 < argc && argv[i + 1][0] >= L'1' && argv[i + 1][0] <= L'6')
{
args.resolution = argv[++i][0] - L'0';
}
}
else if (_wcsicmp(argv[i], L"-name") == 0)
{
args.name = true;
if (i + 1 < argc)
{
app.CopyWideArgToAnsi(argv[i + 1], g_Username, sizeof(g_Username));
app.SetFakeGamertag(g_Username);
}
}
}
LocalFree(argv);
return args;
}
void DefineActions(void)
{
// The app needs to define the actions required, and the possible mappings for these
// Split into Menu actions, and in-game actions
if(InputManager.IsSelectBackSwapped())
{
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _360_JOY_BUTTON_A);
}
else
{
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B);
}
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_X, _360_JOY_BUTTON_X);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_LT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_RT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_LB);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_RTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
if(InputManager.IsSelectBackSwapped())
{
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _360_JOY_BUTTON_A);
}
else
{
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B);
}
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_X, _360_JOY_BUTTON_X);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LB);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_RB);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_LT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_RTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
if(InputManager.IsSelectBackSwapped())
{
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _360_JOY_BUTTON_A);
}
else
{
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B);
}
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_X, _360_JOY_BUTTON_X);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LB);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_LT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_A);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LB);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
}
void MemSect(int sect)
{
//str1k3r - i feel like something should go here, i just dont know what
}
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
ID3D11Device* g_pd3dDevice = NULL;
ID3D11DeviceContext* g_pImmediateContext = NULL;
IDXGISwapChain* g_pSwapChain = NULL;
ID3D11RenderTargetView* g_pRenderTargetView = NULL;
ID3D11DepthStencilView* g_pDepthStencilView = NULL;
ID3D11Texture2D* g_pDepthStencilBuffer = NULL;
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT || LOWORD(lParam) == HTCAPTION)
{
SetCursor((HCURSOR)GetClassLongPtr(hWnd, GCLP_HCURSOR));
return TRUE;
}
break;
case WM_ENTERMENULOOP:
case WM_ENTERSIZEMOVE:
SetTimer(hWnd, 1, USER_TIMER_MINIMUM, NULL);
break;
case WM_EXITMENULOOP:
case WM_EXITSIZEMOVE:
KillTimer(hWnd, 1);
break;
case WM_ERASEBKGND:
return 1;
case WM_TIMER:
if (wParam == 1)
{
// Tick UI
ui.tick();
ui.render();
RenderManager.Present();
ui.CheckMenuDisplayed();
// Tick Managers
app.UpdateTime();
InputManager.Tick();
StorageManager.Tick();
RenderManager.Tick();
// Tick Music
Minecraft *pMinecraft=Minecraft::GetInstance();
pMinecraft->soundEngine->tick(NULL, 0.0f);
pMinecraft->soundEngine->playMusicTick();
}
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if (!(lParam & 0x40000000))
{
InputManager.OnKeyDown((int)wParam);
}
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_KEYUP:
case WM_SYSKEYUP:
InputManager.OnKeyUp((int)wParam);
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_CHAR:
InputManager.OnChar((wchar_t)wParam);
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_INPUT:
{
UINT dwSize = 0;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, nullptr, &dwSize, sizeof(RAWINPUTHEADER));
if (dwSize > 0 && dwSize <= 256)
{
BYTE rawBuffer[256];
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, rawBuffer, &dwSize, sizeof(RAWINPUTHEADER)) == dwSize)
{
const RAWINPUT* raw = (RAWINPUT*)rawBuffer;
if (raw->header.dwType == RIM_TYPEMOUSE)
{
InputManager.OnRawMouseDelta(raw->data.mouse.lLastX, raw->data.mouse.lLastY);
}
}
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_SIZE:
g_iWindowClientW = LOWORD(lParam);
g_iWindowClientH = HIWORD(lParam);
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_MOUSEMOVE:
InputManager.OnMouseMove(LOWORD(lParam), HIWORD(lParam));
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_LBUTTONDOWN:
InputManager.OnLButtonDown(LOWORD(lParam), HIWORD(lParam));
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_LBUTTONUP:
InputManager.OnLButtonUp(LOWORD(lParam), HIWORD(lParam));
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_RBUTTONDOWN:
InputManager.OnRButtonDown(LOWORD(lParam), HIWORD(lParam));
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_RBUTTONUP:
InputManager.OnRButtonUp(LOWORD(lParam), HIWORD(lParam));
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_MBUTTONDOWN:
InputManager.OnMButtonDown(LOWORD(lParam), HIWORD(lParam));
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_MBUTTONUP:
InputManager.OnMButtonUp(LOWORD(lParam), HIWORD(lParam));
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_MOUSEWHEEL:
{
POINT pt = { (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam) };
ScreenToClient(hWnd, &pt);
InputManager.OnMouseWheel((short)HIWORD(wParam), pt.x, pt.y);
}
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_KILLFOCUS:
InputManager.SetWindowFocused(false);
if (InputManager.IsMouseCaptured())
InputManager.SetMouseCaptured(false);
break;
case WM_SETFOCUS:
InputManager.SetWindowFocused(true);
break;
case WM_CLOSE:
app.ExitGame();
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, "Minecraft");
wcex.hCursor = (HCURSOR)LoadImage(hInstance, MAKEINTRESOURCE(IDC_POINTER), IMAGE_CURSOR, 0, 0, LR_SHARED);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = "Minecraft";
wcex.lpszClassName = "MinecraftClass";
wcex.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MINECRAFTWINDOWS64));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
g_hInst = hInstance; // Store instance handle in our global variable
RECT wr = {0, 0, g_iScreenWidth, g_iScreenHeight}; // set the size, but not the position
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); // adjust the size
g_hWnd = CreateWindow( "MinecraftClass",
"Minecraft",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
wr.right - wr.left, // width of the window
wr.bottom - wr.top, // height of the window
NULL,
NULL,
hInstance,
NULL);
if (!g_hWnd)
{
return FALSE;
}
ShowWindow(g_hWnd, (nCmdShow != SW_HIDE) ? SW_SHOWMAXIMIZED : nCmdShow);
UpdateWindow(g_hWnd);
RECT rcClient;
if (GetClientRect(g_hWnd, &rcClient))
{
g_iWindowClientW = rcClient.right - rcClient.left;
g_iWindowClientH = rcClient.bottom - rcClient.top;
}
return TRUE;
}
// 4J Stu - These functions are referenced from the Windows Input library
void ClearGlobalText()
{
// clear the global text
memset(chGlobalText,0,256);
memset(ui16GlobalText,0,512);
}
uint16_t *GetGlobalText()
{
//copy the ch text to ui16
char * pchBuffer=(char *)ui16GlobalText;
for(int i=0;i<256;i++)
{
pchBuffer[i*2]=chGlobalText[i];
}
return ui16GlobalText;
}
void SeedEditBox()
{
DialogBox(hMyInst, MAKEINTRESOURCE(IDD_SEED),
g_hWnd, reinterpret_cast<DLGPROC>(DlgProc));
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
// Set the text
GetDlgItemText(hWndDlg,IDC_EDIT,chGlobalText,256);
EndDialog(hWndDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
namespace DirectTextEdit
{
static UIControl_TextInput *s_ctrl = NULL;
static UIControl *s_parent = NULL;
static bool s_mousePrev = false;
static LineNavCallback s_navCb = NULL;
static LPVOID s_navParam = NULL;
static CommitCallback s_callback = NULL;
static LPVOID s_param = NULL;
static wstring s_text;
static wstring s_initial;
static size_t s_caret = 0;
static bool s_selAll = false;
static unsigned int s_maxChars = 0;
static int s_keyMode = 0;
static vector<pair<wstring, size_t> > s_undo;
static wstring s_clipboard;
static bool s_keyPrev[256] = { false };
static int s_repKey = 0;
static int s_repDelay = 0;
static bool s_commitReady = false;
static wstring s_commitText;
enum { UNDO_CAP = 64, REPEAT_DELAY_FRAMES = 24, REPEAT_RATE_FRAMES = 2 };
static void PushUndo()
{
if (s_undo.size() >= UNDO_CAP)
s_undo.erase(s_undo.begin());
s_undo.push_back(make_pair(s_text, s_caret));
}
static bool CharAllowed(wchar_t ch)
{
if (ch < 0x20 || ch == 0x7F)
return false;
if (s_keyMode == C_4JInput::EKeyboardMode_Numeric)
return (ch >= L'0' && ch <= L'9') || ch == L'-' || ch == L'+';
return true;
}
static void PushToFlash()
{
if (!s_ctrl)
return;
s_ctrl->setLabel(s_text.c_str());
s_ctrl->SyncCaret((int)s_caret, (int)s_text.length());
}
static void InsertText(const wstring &ins)
{
if (ins.empty() || !s_ctrl)
return;
wstring filtered;
for (size_t i = 0; i < ins.length(); ++i)
if (CharAllowed(ins[i]))
filtered += ins[i];
if (filtered.empty())
return;
PushUndo();
if (s_selAll)
{
s_text.clear();
s_caret = 0;
s_selAll = false;
}
if (s_text.length() + filtered.length() > s_maxChars)
filtered.erase(s_maxChars > s_text.length() ? s_maxChars - s_text.length() : 0);
s_text.insert(s_caret, filtered);
s_caret += filtered.length();
PushToFlash();
}
static void ActBackspace()
{
if (!s_ctrl)
return;
if (s_selAll)
{
s_selAll = false;
if (s_text.empty())
return;
PushUndo();
s_text.clear();
s_caret = 0;
PushToFlash();
return;
}
if (s_caret == 0)
return;
PushUndo();
s_text.erase(s_caret - 1, 1);
--s_caret;
PushToFlash();
}
static void ActDelete()
{
if (!s_ctrl)
return;
if (s_selAll)
{
s_selAll = false;
if (s_text.empty())
return;
PushUndo();
s_text.clear();
s_caret = 0;
PushToFlash();
return;
}
if (s_caret >= s_text.length())
return;
PushUndo();
s_text.erase(s_caret, 1);
PushToFlash();
}
static void ActLeft()
{
if (!s_ctrl || s_caret == 0)
{
s_selAll = false;
return;
}
s_selAll = false;
--s_caret;
PushToFlash();
}
static void ActRight()
{
if (!s_ctrl)
return;
s_selAll = false;
if (s_caret < s_text.length())
{
++s_caret;
PushToFlash();
}
}
static void ActHome()
{
if (!s_ctrl)
return;
s_selAll = false;
if (s_caret != 0)
{
s_caret = 0;
PushToFlash();
}
}
static void ActEnd()
{
if (!s_ctrl)
return;
s_selAll = false;
if (s_caret != s_text.length())
{
s_caret = s_text.length();
PushToFlash();
}
}
static void CopyToClipboard(const wstring &s)
{
s_clipboard = s;
InputManager.SetClipboardText(s.c_str());
}
static bool ClipboardText(wstring &out)
{
wchar_t buf[512];
int n = InputManager.GetClipboardText(buf, 512);
if (n > 0)
{
out.assign(buf, n);
return true;
}
if (!s_clipboard.empty())
{
out = s_clipboard;
return true;
}
return false;
}
static bool FreshPress(int vk)
{
return vk >= 0 && vk < 256 && InputManager.IsKeyDown(vk) && !s_keyPrev[vk];
}
static void PollRepeatKey(int vk, void (*action)())
{
bool down = InputManager.IsKeyDown(vk);
if (down && !s_keyPrev[vk])
{
action();
s_repKey = vk;
s_repDelay = REPEAT_DELAY_FRAMES;
}
else if (down && s_repKey == vk)
{
if (--s_repDelay <= 0)
{
action();
s_repDelay = REPEAT_RATE_FRAMES;
}
}
else if (!down && s_repKey == vk)
{
s_repKey = 0;
}
}
static bool ClickOutsideBox()
{
if (!s_ctrl)
return false;
UIScene *scene = s_ctrl->getParentScene();
if (!scene)
return false;
float movieW = (float)scene->getMovieWidth();
float movieH = (float)scene->getMovieHeight();
float fx = (float)InputManager.GetMouseX();
float fy = (float)InputManager.GetMouseY();
if (movieW > 0.0f && movieH > 0.0f && g_iWindowClientW > 0 && g_iWindowClientH > 0)
{
fx = fx * (movieW / (float)g_iWindowClientW);
fy = fy * (movieH / (float)g_iWindowClientH);
}
float ox = 0.0f, oy = 0.0f;
if (s_parent)
{
s_parent->UpdateControl();
ox = (float)s_parent->getXPos();
oy = (float)s_parent->getYPos();
}
s_ctrl->UpdateControl();
float w = (float)s_ctrl->getWidth();
float h = (float)s_ctrl->getHeight();
if (w < 4.0f || h < 4.0f)
return false;
float x = ox + (float)s_ctrl->getXPos();
float y = oy + (float)s_ctrl->getYPos();
return fx < x || fx >= x + w || fy < y || fy >= y + h;
}
void Begin(UIControl_TextInput *ctrl, UIControl *parent,
const wchar_t *initialText,
unsigned int maxChars, int keyboardMode,
CommitCallback callback, LPVOID param)
{
if (!ctrl)
return;
if (s_ctrl == ctrl)
return;
if (s_ctrl)
Finish(true);
s_ctrl = ctrl;
s_parent = parent;
s_mousePrev = InputManager.IsMouseLDown();
s_callback = callback;
s_param = param;
s_text = initialText ? initialText : L"";
s_initial = s_text;
s_caret = s_text.length();
s_selAll = false;
s_maxChars = maxChars;
s_keyMode = keyboardMode;
s_undo.clear();
memset(s_keyPrev, 0, sizeof(s_keyPrev));
s_repKey = 0;
ctrl->setFocus(true);
PushToFlash();
}
bool IsActive()
{
return s_ctrl != NULL;
}
void SetLineNav(LineNavCallback callback, LPVOID param)
{
if (!s_ctrl)
return;
s_navCb = callback;
s_navParam = param;
}
static void DoLineNav(int vk, int dir)
{
LineNavCallback cb = s_navCb;
LPVOID p = s_navParam;
Finish(true);
if (cb)
cb(p, dir);
s_keyPrev[vk] = true;
s_repKey = vk;
s_repDelay = REPEAT_DELAY_FRAMES;
}
static void PollNavKey(int vk, int dir)
{
if (!s_navCb)
return;
bool down = InputManager.IsKeyDown(vk);
if (down && !s_keyPrev[vk])
{
DoLineNav(vk, dir);
}
else if (down && s_repKey == vk)
{
if (--s_repDelay <= 0)
{
DoLineNav(vk, dir);
s_repDelay = REPEAT_RATE_FRAMES;
}
}
else if (!down && s_repKey == vk)
{
s_repKey = 0;
}
}
void Tick()
{
if (!s_ctrl)
return;
s_ctrl->RefreshFocus();
{
UIScene *pinScene = s_ctrl->getParentScene();
if (pinScene && s_ctrl->getId() >= 0)
pinScene->SetFocusToElement(s_ctrl->getId(), true);
}
bool mouseDown = InputManager.IsMouseLDown();
if (mouseDown && !s_mousePrev)
{
if (ClickOutsideBox())
{
Finish(true);
s_mousePrev = mouseDown;
for (int v = 0; v < 256; ++v)
s_keyPrev[v] = InputManager.IsKeyDown(v);
return;
}
}
s_mousePrev = mouseDown;
bool ctrlDown = InputManager.IsKeyDown(VK_CONTROL) && !InputManager.IsKeyDown(VK_MENU);
if (ctrlDown)
{
if (FreshPress('A'))
{
s_selAll = !s_text.empty();
}
else if (FreshPress('C'))
{
CopyToClipboard(s_text);
}
else if (FreshPress('X'))
{
CopyToClipboard(s_text);
if (!s_text.empty())
{
PushUndo();
s_text.clear();
s_caret = 0;
s_selAll = false;
PushToFlash();
}
}
else if (FreshPress('V'))
{
wstring pasted;
if (ClipboardText(pasted))
InsertText(pasted);
}
else if (FreshPress('Z'))
{
if (!s_undo.empty())
{
s_text = s_undo.back().first;
s_caret = s_undo.back().second;
if (s_caret > s_text.length())
s_caret = s_text.length();
s_undo.pop_back();
s_selAll = false;
PushToFlash();
}
}
}
if (FreshPress(VK_RETURN))
{
if (s_navCb)
{
LineNavCallback cb = s_navCb;
LPVOID p = s_navParam;
Finish(true);
cb(p, +1);
}
else
{
Finish(true);
}
}
else if (FreshPress(VK_ESCAPE))
{
Finish(false);
}
else if (s_ctrl)
{
int n = InputManager.GetCharCount();
if (n > 0)
{
wstring ins;
for (int i = 0; i < n; ++i)
ins += InputManager.GetChar(i);
InsertText(ins);
}
PollRepeatKey(VK_BACK, ActBackspace);
PollRepeatKey(VK_DELETE, ActDelete);
PollRepeatKey(VK_LEFT, ActLeft);
PollRepeatKey(VK_RIGHT, ActRight);
PollRepeatKey(VK_HOME, ActHome);
PollRepeatKey(VK_END, ActEnd);
PollNavKey(VK_UP, -1);
PollNavKey(VK_DOWN, +1);
}
for (int v = 0; v < 256; ++v)
s_keyPrev[v] = InputManager.IsKeyDown(v);
}
void Finish(bool accepted)
{
if (!s_ctrl)
return;
UIControl_TextInput *ctrl = s_ctrl;
s_ctrl = NULL;
if (!accepted)
{
s_text = s_initial;
s_caret = 0;
ctrl->setLabel(s_text.c_str());
}
ctrl->setFocus(false);
if (s_callback)
{
s_commitReady = true;
s_commitText = accepted ? s_text : L"";
CommitCallback cb = s_callback;
LPVOID p = s_param;
s_callback = NULL;
s_param = NULL;
cb(p, accepted);
s_commitReady = false;
}
s_undo.clear();
s_selAll = false;
s_repKey = 0;
s_navCb = NULL;
s_navParam = NULL;
}
bool TakeText(uint16_t *outText, unsigned int outCapacity)
{
if (!s_commitReady || !outText || outCapacity == 0)
return false;
unsigned int n = (unsigned int)s_commitText.length();
if (n >= outCapacity)
n = outCapacity - 1;
for (unsigned int i = 0; i < n; ++i)
outText[i] = (uint16_t)s_commitText[i];
outText[n] = 0;
return true;
}
};
//--------------------------------------------------------------------------------------
// Create Direct3D device and swap chain
//--------------------------------------------------------------------------------------
HRESULT InitDevice()
{
HRESULT hr = S_OK;
//str1k3r - use screen size instead of window size & detect if its widescreen or not
if (!g_bResolutionSetByCMD)
{
HMONITOR hMonitor = MonitorFromWindow(g_hWnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO monitorInfo = { sizeof(MONITORINFO) };
if (GetMonitorInfo(hMonitor, &monitorInfo))
{
g_iScreenWidth = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left;
g_iScreenHeight = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top;
}
else
{
g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN);
}
}
//str1k3r - stop hardcoding size and just use the screens actual size
UINT width = g_iScreenWidth;
UINT height = g_iScreenHeight;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
app.DebugPrintf("Screen Width: %d, Screen Height: %d\n", width, height);
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
#ifdef _DEBUG //str1k3r - using this can actually SLOW stuff down, as its ran on the CPU instead of the GPU also only intended for debugging
D3D_DRIVER_TYPE_REFERENCE,
#endif
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 2;
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 0;
sd.BufferDesc.RefreshRate.Denominator = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = g_hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if (hr == E_INVALIDARG && numFeatureLevels > 1 && featureLevels[0] == D3D_FEATURE_LEVEL_11_1)
{
hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, &featureLevels[1], numFeatureLevels - 1,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
}
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
return hr;
// Create a render target view
ID3D11Texture2D* pBackBuffer = NULL;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
if( FAILED( hr ) )
return hr;
// Create a depth stencil buffer
D3D11_TEXTURE2D_DESC descDepth;
descDepth.Width = width;
descDepth.Height = height;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDepth.SampleDesc.Count = 1;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
hr = g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencilBuffer);
D3D11_DEPTH_STENCIL_VIEW_DESC descDSView;
ZeroMemory(&descDSView, sizeof(descDSView));
descDSView.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDSView.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
descDSView.Texture2D.MipSlice = 0;
hr = g_pd3dDevice->CreateDepthStencilView(g_pDepthStencilBuffer, &descDSView, &g_pDepthStencilView);
hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
pBackBuffer->Release();
if( FAILED( hr ) )
return hr;
g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, g_pDepthStencilView );
// Setup the viewport
D3D11_VIEWPORT vp;
vp.Width = (FLOAT)width;
vp.Height = (FLOAT)height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
g_pImmediateContext->RSSetViewports( 1, &vp );
//RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); //str1k3r - this was getting ran twice, keeping this commented out just incase
return S_OK;
}
//--------------------------------------------------------------------------------------
// Render the frame
//--------------------------------------------------------------------------------------
void Render()
{
// Just clear the backbuffer
float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha
g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor );
g_pSwapChain->Present( 0, 0 );
}
//--------------------------------------------------------------------------------------
// Toggle borderless fullscreen
// Credits to the smartCMD repo for this
// This is the proper way to do this therefore we just took it
//--------------------------------------------------------------------------------------
void ToggleFullscreen()
{
const DWORD dwStyle = GetWindowLong(g_hWnd, GWL_STYLE);
if (!g_isFullscreen)
{
MONITORINFO mi = { sizeof(mi) };
if (GetWindowPlacement(g_hWnd, &g_wpPrev) &&
GetMonitorInfo(MonitorFromWindow(g_hWnd, MONITOR_DEFAULTTOPRIMARY), &mi))
{
SetWindowLong(g_hWnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
SetWindowPos(g_hWnd, HWND_TOP,
mi.rcMonitor.left, mi.rcMonitor.top,
mi.rcMonitor.right - mi.rcMonitor.left,
mi.rcMonitor.bottom - mi.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
}
else
{
SetWindowLong(g_hWnd, GWL_STYLE, dwStyle | WS_OVERLAPPEDWINDOW);
SetWindowPlacement(g_hWnd, &g_wpPrev);
SetWindowPos(g_hWnd, nullptr, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
g_isFullscreen = !g_isFullscreen;
}
//--------------------------------------------------------------------------------------
// Clean up the objects we've created
//--------------------------------------------------------------------------------------
void CleanupDevice()
{
if( g_pImmediateContext ) g_pImmediateContext->ClearState();
if( g_pRenderTargetView ) g_pRenderTargetView->Release();
if( g_pSwapChain ) g_pSwapChain->Release();
if( g_pImmediateContext ) g_pImmediateContext->Release();
if( g_pd3dDevice ) g_pd3dDevice->Release();
}
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
//str1k3r - tell windows that we are aware of high DPI displays
SetProcessDPIAware();
Windows64LaunchArgs launchArgs = ParseLaunchArgs();
if(launchArgs.resolution != 0)
{
if(launchArgs.resolution == 1)
{
// 2160p
g_iScreenWidth = 3840;
g_iScreenHeight = 2160;
g_bResolutionSetByCMD = TRUE;
}
else if(launchArgs.resolution == 2)
{
// 1440p
g_iScreenWidth = 2560;
g_iScreenHeight = 1440;
g_bResolutionSetByCMD = TRUE;
}
else if (launchArgs.resolution == 3)
{
// 1080p
g_iScreenWidth = 1920;
g_iScreenHeight = 1080;
g_bResolutionSetByCMD = TRUE;
}
else if(launchArgs.resolution == 4)
{
// 720p
g_iScreenWidth = 1280;
g_iScreenHeight = 720;
g_bResolutionSetByCMD = TRUE;
}
else if(launchArgs.resolution == 5)
{
// 480p
g_iScreenWidth = 640;
g_iScreenHeight = 480;
g_bResolutionSetByCMD = TRUE;
}
else if(launchArgs.resolution == 6)
{
// Vita Native, 544p
g_iScreenWidth = 960;
g_iScreenHeight = 544;
g_bResolutionSetByCMD = TRUE;
}
}
// Initialize global strings
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hMyInst=hInstance;
if( FAILED( InitDevice() ) )
{
CleanupDevice();
return 0;
}
if(launchArgs.fullscreen)
{
ToggleFullscreen();
}
static bool bTrialTimerDisplayed=true;
app.loadMediaArchive();
RenderManager.Initialise(g_pd3dDevice, g_pSwapChain);
//str1k3r - set the resolution that we have at time of launch
RenderManager.setResolution(g_iScreenWidth, g_iScreenHeight);
app.loadStringTable();
ui.init(g_pd3dDevice,g_pImmediateContext,g_pRenderTargetView,g_pDepthStencilView,g_iScreenWidth,g_iScreenHeight);
////////////////
// Initialise //
////////////////
// Set the number of possible joypad layouts that the user can switch between, and the number of actions
InputManager.Initialise(1,3,MINECRAFT_ACTION_MAX, ACTION_MAX_MENU);
// Set the default joypad action mappings for Minecraft
DefineActions();
InputManager.SetJoypadMapVal(0,0);
InputManager.SetKeyRepeatRate(0.3f,0.2f);
//str1k3r - load username.txt if we havent ran the -name arg
if(!launchArgs.name) ProfileManager.LoadGamertag();
// Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings
ProfileManager.Initialise(TITLEID_MINECRAFT,
app.m_dwOfferID,
PROFILE_VERSION_12,
NUM_PROFILE_VALUES,
NUM_PROFILE_SETTINGS,
dwProfileSettingsA,
app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT,
&app.uiGameDefinedDataChangedBitmask
);
// initialise the storage manager with a default save display name, a Minimum save size, and a callback for displaying the saving message
StorageManager.Init(0,app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app,"");
// Set a callback for the default player options to be set - when there is no profile data for the player
ProfileManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app);
// QNet needs to be setup after profile manager, as we do not want its Notify listener to handle
// XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the
// ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet.
g_NetworkManager.Initialise();
// debug switch to trial version
ProfileManager.SetDebugFullOverride(true);
// Initialise TLS for tesselator, for this main thread
Tesselator::CreateNewThreadStorage(1024*1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage();
IntCache::CreateNewThreadStorage();
Compression::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
Tile::CreateNewThreadStorage();
Minecraft::main();
Minecraft *pMinecraft=Minecraft::GetInstance();
app.InitGameSettings();
app.InitialiseTips();
#ifdef _TEMPORARY_CREATE_GAME
app.TemporaryCreateGameStart();
Sleep(10000);
#endif
MSG msg = {0};
while( WM_QUIT != msg.message )
{
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if (msg.message == WM_QUIT) break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
if (msg.message == WM_QUIT) break;
RenderManager.StartFrame();
app.UpdateTime();
if (app.GetGameStarted())
{
int iPad = ProfileManager.GetPrimaryPad();
TickMenuNavKeys(iPad, ui.GetMenuDisplayed(iPad) || pMinecraft->screen != NULL);
if (ui.GetMenuDisplayed(iPad) || pMinecraft->screen != NULL)
{
if (InputManager.IsKeyDown(VK_ESCAPE) && !s_bEscapeKeyPrev && !DirectTextEdit::IsActive())
{
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_CANCEL));
}
bool bMouseL = InputManager.IsMouseLDown();
bool bMouseR = InputManager.IsMouseRDown();
if (bMouseL && !s_bMenuMouseLPrev)
{
if (InputManager.IsKeyDown(VK_SHIFT))
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_Y));
else if (!ui.IsCraftingMenuDisplayed(iPad))
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_A));
}
if (bMouseR && !s_bMenuMouseRPrev)
{
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_X));
}
s_bMenuMouseLPrev = bMouseL;
s_bMenuMouseRPrev = bMouseR;
int iWheelMenu = InputManager.GetMouseWheelDelta();
if (iWheelMenu > 0)
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OTHER_STICK_UP));
else if (iWheelMenu < 0)
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OTHER_STICK_DOWN));
s_iWheelCarry = 0;
g_iPendingHotbarScroll = 0;
}
else
{
if (InputManager.IsMouseLDown()) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_ACTION));
if (InputManager.IsMouseRDown()) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_USE));
if (!DirectTextEdit::IsActive())
{
if (InputManager.IsKeyDown('Q')) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_DROP));
if (InputManager.IsKeyDown(VK_SHIFT)) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_SNEAK_TOGGLE));
if (InputManager.IsKeyDown('E')) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_INVENTORY));
if (InputManager.IsKeyDown('F')) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_RENDER_THIRD_PERSON));
if (InputManager.IsKeyDown(VK_ESCAPE)) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_PAUSEMENU));
if (InputManager.IsKeyDown('R')) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_CRAFTING));
if (InputManager.IsKeyDown(VK_TAB)) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_GAME_INFO));
}
s_iWheelCarry += InputManager.GetMouseWheelDelta();
int iNewNotches = s_iWheelCarry / 120;
if (iNewNotches != 0)
{
s_iWheelCarry -= iNewNotches * 120;
g_iPendingHotbarScroll += iNewNotches;
if (g_iPendingHotbarScroll > 12) g_iPendingHotbarScroll = 12;
else if (g_iPendingHotbarScroll < -12) g_iPendingHotbarScroll = -12;
}
}
s_bEscapeKeyPrev = InputManager.IsKeyDown(VK_ESCAPE);
}
else
{
int iPad = ProfileManager.GetPrimaryPad();
TickMenuNavKeys(iPad, ui.GetMenuDisplayed(iPad) ? true : false);
if (ui.GetMenuDisplayed(iPad))
{
if (InputManager.IsKeyDown(VK_ESCAPE) && !s_bEscapeKeyPrev && !DirectTextEdit::IsActive())
{
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_CANCEL));
}
bool bMouseL = InputManager.IsMouseLDown();
bool bMouseR = InputManager.IsMouseRDown();
if (bMouseL && !s_bMenuMouseLPrev)
{
if (!ui.IsSkinSelectMenuDisplayed(iPad))
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OK));
}
s_bMenuMouseLPrev = bMouseL;
s_bMenuMouseRPrev = bMouseR;
int iWheelMenu = InputManager.GetMouseWheelDelta();
if (iWheelMenu > 0)
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OTHER_STICK_UP));
else if (iWheelMenu < 0)
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OTHER_STICK_DOWN));
}
s_bEscapeKeyPrev = InputManager.IsKeyDown(VK_ESCAPE);
}
{
int iPad = ProfileManager.GetPrimaryPad();
bool bPointerMenu = ui.IsContainerMenuDisplayed(iPad) && !ui.IsCraftingMenuDisplayed(iPad);
if (bPointerMenu && !InputManager.IsMouseCaptured())
{
while (ShowCursor(FALSE) >= 0) {}
}
else if (!InputManager.IsMouseCaptured())
{
while (ShowCursor(TRUE) < 0) {}
}
}
DirectTextEdit::Tick();
PIXBeginNamedEvent(0,"Input manager tick mouse");
InputManager.TickKBM();
PIXEndNamedEvent();
PIXBeginNamedEvent(0,"Input manager tick");
if (GetFocus())
{
InputManager.Tick();
}
PIXEndNamedEvent();
/*PIXBeginNamedEvent(0,"Profile manager tick");
ProfileManager.Tick();
PIXEndNamedEvent();*/
PIXBeginNamedEvent(0,"Storage manager tick");
StorageManager.Tick();
PIXEndNamedEvent();
PIXBeginNamedEvent(0,"Render manager tick");
RenderManager.Tick();
PIXEndNamedEvent();
PIXBeginNamedEvent(0,"Network manager do work #1");
// g_NetworkManager.DoWork();
PIXEndNamedEvent();
// LeaderboardManager::Instance()->Tick();
// Render game graphics.
if(app.GetGameStarted())
{
pMinecraft->run_middle();
app.SetAppPaused( g_NetworkManager.IsLocalGame() && g_NetworkManager.GetPlayerCount() == 1 && ui.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()) );
}
else
{
MemSect(28);
pMinecraft->soundEngine->tick(NULL, 0.0f);
MemSect(0);
pMinecraft->textures->tick(true,false);
IntCache::Reset();
if( app.GetReallyChangingSessionType() )
{
pMinecraft->tickAllConnections(); // Added to stop timing out when we are waiting after converting to an offline game
}
}
pMinecraft->soundEngine->playMusicTick();
ui.tick();
ui.render();
//str1k3r - update resolution
ui.updateResolution(g_iScreenWidth, g_iScreenHeight);
// Present the frame.
RenderManager.Present();
ui.CheckMenuDisplayed();
// Any threading type things to deal with from the xui side?
app.HandleUIActions();
isF11Pressed = (GetAsyncKeyState(VK_F11) & 0x8000) != 0;
if(isF11Pressed && !wasF11Pressed && GetFocus())
{
ToggleFullscreen();
}
else if(isF11Pressed && !wasF11Pressed && GetFocus())
{
ToggleFullscreen();
}
wasF11Pressed = isF11Pressed;
if(app.GetGameStarted())
{
if(ui.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()))
{
if(launchArgs.vsync) RenderManager.SetVSync(true);
}
else
{
if(launchArgs.vsync) RenderManager.SetVSync(false);
}
}
if(launchArgs.vsync && !app.GetGameStarted()) RenderManager.SetVSync(true);
// 4J-PB - Update the trial timer display if we are in the trial version
if(!ProfileManager.IsFullVersion())
{
// display the trial timer
if(app.GetGameStarted())
{
// 4J-PB - if the game is paused, add the elapsed time to the trial timer count so it doesn't tick down
if(app.IsAppPaused())
{
app.UpdateTrialPausedTimer();
}
ui.UpdateTrialTimer(ProfileManager.GetPrimaryPad());
}
}
else
{
// need to turn off the trial timer if it was on , and we've unlocked the full version
if(bTrialTimerDisplayed)
{
ui.ShowTrialTimer(false);
bTrialTimerDisplayed=false;
}
}
// Fix for #7318 - Title crashes after short soak in the leaderboards menu
// A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset
Vec3::resetPool();
}
//str1k3r - shutdown server & network manager
MinecraftServer::HaltServer();
g_NetworkManager.Terminate();
//str1k3r - unregister the minecraft window class
UnregisterClass("MinecraftClass", g_hInst);
//str1k3r - shutdown Iggy
ui.shutdown();
IggyShutdown();
//str1k3r - shutdown mss :3
AIL_shutdown();
//str1k3r - cleanup DirectX stuff
CleanupDevice();
//str1k3r - pass exitcode to OS, removed app.ExitGame() as that made it always exit with 0
return (int)msg.wParam;
}