the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1// Minecraft.cpp : Defines the entry point for the application.
2//
3
4#include "stdafx.h"
5
6#include <assert.h>
7#include <ShellScalingApi.h>
8#include "GameConfig\Minecraft.spa.h"
9#include "..\MinecraftServer.h"
10#include "..\LocalPlayer.h"
11#include "..\..\Minecraft.World\ItemInstance.h"
12#include "..\..\Minecraft.World\MapItem.h"
13#include "..\..\Minecraft.World\Recipes.h"
14#include "..\..\Minecraft.World\Recipy.h"
15#include "..\..\Minecraft.World\Language.h"
16#include "..\..\Minecraft.World\StringHelpers.h"
17#include "..\..\Minecraft.World\AABB.h"
18#include "..\..\Minecraft.World\Vec3.h"
19#include "..\..\Minecraft.World\Level.h"
20#include "..\..\Minecraft.World\net.minecraft.world.level.tile.h"
21
22#include "..\ClientConnection.h"
23#include "..\User.h"
24#include "..\..\Minecraft.World\Socket.h"
25#include "..\..\Minecraft.World\ThreadName.h"
26#include "..\..\Minecraft.Client\StatsCounter.h"
27#include "..\ConnectScreen.h"
28//#include "Social\SocialManager.h"
29//#include "Leaderboards\LeaderboardManager.h"
30//#include "XUI\XUI_Scene_Container.h"
31//#include "NetworkManager.h"
32#include "..\..\Minecraft.Client\Tesselator.h"
33#include "..\..\Minecraft.Client\Options.h"
34#include "Sentient\SentientManager.h"
35#include "..\..\Minecraft.World\IntCache.h"
36#include "..\Textures.h"
37#include "Resource.h"
38#include "..\..\Minecraft.World\compression.h"
39#include "..\..\Minecraft.World\OldChunkStorage.h"
40#include "Network\WinsockNetLayer.h"
41
42#include "Xbox/resource.h"
43
44#ifdef _MSC_VER
45#pragma comment(lib, "legacy_stdio_definitions.lib")
46#endif
47
48HINSTANCE hMyInst;
49LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
50char chGlobalText[256];
51uint16_t ui16GlobalText[256];
52
53#define THEME_NAME "584111F70AAAAAAA"
54#define THEME_FILESIZE 2797568
55
56//#define THREE_MB 3145728 // minimum save size (checking for this on a selected device)
57//#define FIVE_MB 5242880 // minimum save size (checking for this on a selected device)
58//#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device)
59#define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device)
60
61//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU
62#define NUM_PROFILE_VALUES 5
63#define NUM_PROFILE_SETTINGS 4
64DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]=
65{
66#ifdef _XBOX
67 XPROFILE_OPTION_CONTROLLER_VIBRATION,
68 XPROFILE_GAMER_YAXIS_INVERSION,
69 XPROFILE_GAMER_CONTROL_SENSITIVITY,
70 XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL,
71 XPROFILE_TITLE_SPECIFIC1,
72#else
73 0,0,0,0,0
74#endif
75};
76
77//-------------------------------------------------------------------------------------
78// Time Since fAppTime is a float, we need to keep the quadword app time
79// as a LARGE_INTEGER so that we don't lose precision after running
80// for a long time.
81//-------------------------------------------------------------------------------------
82
83BOOL g_bWidescreen = TRUE;
84
85int g_iScreenWidth = 1920;
86int g_iScreenHeight = 1080;
87
88char g_Win64Username[17] = { 0 };
89wchar_t g_Win64UsernameW[17] = { 0 };
90UINT g_ScreenWidth = 1920;
91UINT g_ScreenHeight = 1080;
92
93// Fullscreen toggle state
94static bool g_isFullscreen = false;
95static WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };
96
97void DefineActions(void)
98{
99 // The app needs to define the actions required, and the possible mappings for these
100
101 // Split into Menu actions, and in-game actions
102
103 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _360_JOY_BUTTON_A);
104 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _360_JOY_BUTTON_B);
105 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_X, _360_JOY_BUTTON_X);
106 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
107 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _360_JOY_BUTTON_A);
108 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B);
109 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
110 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
111 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
112 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
113 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LT);
114 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
115 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
116 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
117 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START);
118
119 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
120 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
121 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
122 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
123 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
124 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
125
126 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_A);
127 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
128 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
129 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
130 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
131 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
132 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
133 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
134 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
135 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_LT);
136 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_RT);
137 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
138 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_LB);
139 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
140 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START);
141 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
142 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_RTHUMB);
143 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
144 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB);
145 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK);
146
147 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
148 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
149 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
150 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
151
152 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _360_JOY_BUTTON_A);
153 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _360_JOY_BUTTON_B);
154 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_X, _360_JOY_BUTTON_X);
155 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
156 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _360_JOY_BUTTON_A);
157 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B);
158 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
159 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
160 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
161 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
162 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LB);
163 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
164 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
165 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
166 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START);
167
168 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
169 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
170 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
171 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
172 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
173 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
174
175 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_RB);
176 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
177 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
178 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
179 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
180 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
181 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
182 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
183 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
184 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT);
185 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_LT);
186 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT);
187 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT);
188 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
189 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START);
190 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
191 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LTHUMB);
192 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
193 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_RTHUMB);
194 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK);
195
196 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
197 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
198 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
199 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
200
201 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _360_JOY_BUTTON_A);
202 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _360_JOY_BUTTON_B);
203 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_X, _360_JOY_BUTTON_X);
204 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
205 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _360_JOY_BUTTON_A);
206 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B);
207 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
208 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
209 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
210 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
211 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LB);
212 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
213 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
214 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
215
216 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_LT);
217 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
218 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
219 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
220 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
221 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
222 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
223 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
224 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
225 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT);
226 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_A);
227 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT);
228 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT);
229 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
230 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START);
231 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
232 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LB);
233 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
234 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB);
235 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK);
236 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START);
237
238 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
239 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
240 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
241 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
242 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
243 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
244
245 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
246 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
247 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
248 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
249}
250
251#if 0
252HRESULT InitD3D( IDirect3DDevice9 **ppDevice,
253 D3DPRESENT_PARAMETERS *pd3dPP )
254{
255 IDirect3D9 *pD3D;
256
257 pD3D = Direct3DCreate9( D3D_SDK_VERSION );
258
259 // Set up the structure used to create the D3DDevice
260 // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing,
261 // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this
262 // mode so don't need this functionality.
263
264 ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) );
265 XVIDEO_MODE VideoMode;
266 XGetVideoMode( &VideoMode );
267 g_bWidescreen = VideoMode.fIsWideScreen;
268 pd3dPP->BackBufferWidth = 1280;
269 pd3dPP->BackBufferHeight = 720;
270 pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8;
271 pd3dPP->BackBufferCount = 1;
272 pd3dPP->EnableAutoDepthStencil = TRUE;
273 pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8;
274 pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD;
275 pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
276 //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX;
277 //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled
278 // in the launcher/dashboard.
279 if(g_bWidescreen)
280 pd3dPP->Flags=0;
281 else
282 pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX;
283
284 // Create the device.
285 return pD3D->CreateDevice(
286 0,
287 D3DDEVTYPE_HAL,
288 NULL,
289 D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES,
290 pd3dPP,
291 ppDevice );
292}
293#endif
294//#define MEMORY_TRACKING
295
296#ifdef MEMORY_TRACKING
297void ResetMem();
298void DumpMem();
299void MemPixStuff();
300#else
301void MemSect(int sect)
302{
303}
304#endif
305
306HINSTANCE g_hInst = NULL;
307HWND g_hWnd = NULL;
308D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
309D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
310ID3D11Device* g_pd3dDevice = NULL;
311ID3D11DeviceContext* g_pImmediateContext = NULL;
312IDXGISwapChain* g_pSwapChain = NULL;
313ID3D11RenderTargetView* g_pRenderTargetView = NULL;
314ID3D11DepthStencilView* g_pDepthStencilView = NULL;
315ID3D11Texture2D* g_pDepthStencilBuffer = NULL;
316
317//
318// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
319//
320// PURPOSE: Processes messages for the main window.
321//
322// WM_COMMAND - process the application menu
323// WM_PAINT - Paint the main window
324// WM_DESTROY - post a quit message and return
325//
326//
327LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
328{
329 int wmId, wmEvent;
330 PAINTSTRUCT ps;
331 HDC hdc;
332
333 switch (message)
334 {
335 case WM_COMMAND:
336 wmId = LOWORD(wParam);
337 wmEvent = HIWORD(wParam);
338 // Parse the menu selections:
339 switch (wmId)
340 {
341 case IDM_EXIT:
342 DestroyWindow(hWnd);
343 break;
344
345 default:
346 return DefWindowProc(hWnd, message, wParam, lParam);
347 }
348 break;
349 case WM_PAINT:
350 hdc = BeginPaint(hWnd, &ps);
351 // TODO: Add any drawing code here...
352 EndPaint(hWnd, &ps);
353 break;
354 case WM_DESTROY:
355 PostQuitMessage(0);
356 break;
357
358 // Keyboard/Mouse input handling
359 case WM_KEYDOWN:
360 if (!(lParam & 0x40000000)) // ignore auto-repeat
361 KMInput.OnKeyDown(wParam);
362 break;
363 case WM_KEYUP:
364 KMInput.OnKeyUp(wParam);
365 break;
366 case WM_SYSKEYDOWN:
367 if (wParam == VK_MENU) // Alt key
368 {
369 if (!(lParam & 0x40000000))
370 KMInput.OnKeyDown(wParam);
371 return 0; // prevent default Alt behavior
372 }
373 return DefWindowProc(hWnd, message, wParam, lParam);
374 case WM_SYSKEYUP:
375 if (wParam == VK_MENU)
376 {
377 KMInput.OnKeyUp(wParam);
378 return 0;
379 }
380 return DefWindowProc(hWnd, message, wParam, lParam);
381 case WM_INPUT:
382 KMInput.OnRawMouseInput(lParam);
383 break;
384 case WM_LBUTTONDOWN:
385 KMInput.OnMouseButton(0, true);
386 break;
387 case WM_LBUTTONUP:
388 KMInput.OnMouseButton(0, false);
389 break;
390 case WM_RBUTTONDOWN:
391 KMInput.OnMouseButton(1, true);
392 break;
393 case WM_RBUTTONUP:
394 KMInput.OnMouseButton(1, false);
395 break;
396 case WM_MBUTTONDOWN:
397 KMInput.OnMouseButton(2, true);
398 break;
399 case WM_MBUTTONUP:
400 KMInput.OnMouseButton(2, false);
401 break;
402 case WM_MOUSEWHEEL:
403 KMInput.OnMouseWheel(GET_WHEEL_DELTA_WPARAM(wParam));
404 break;
405 case WM_MOUSEMOVE:
406 KMInput.OnMouseMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
407 break;
408 case WM_ACTIVATE:
409 if (LOWORD(wParam) == WA_INACTIVE)
410 KMInput.SetCapture(false);
411 break;
412 case WM_SETFOCUS:
413 {
414 // Re-capture when window receives focus (e.g., after clicking on it)
415 Minecraft *pMinecraft = Minecraft::GetInstance();
416 bool shouldCapture = pMinecraft && app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL;
417 if (shouldCapture)
418 KMInput.SetCapture(true);
419 }
420 break;
421 case WM_KILLFOCUS:
422 KMInput.SetCapture(false);
423 KMInput.ClearAllState();
424 break;
425
426 case WM_SETCURSOR:
427 // Hide the OS cursor when an Iggy/Flash menu is displayed (it has its own Flash cursor)
428 if (LOWORD(lParam) == HTCLIENT && !KMInput.IsCaptured() && ui.GetMenuDisplayed(0))
429 {
430 SetCursor(NULL);
431 return TRUE;
432 }
433 return DefWindowProc(hWnd, message, wParam, lParam);
434 default:
435 return DefWindowProc(hWnd, message, wParam, lParam);
436 }
437 return 0;
438}
439
440//
441// FUNCTION: MyRegisterClass()
442//
443// PURPOSE: Registers the window class.
444//
445ATOM MyRegisterClass(HINSTANCE hInstance)
446{
447 WNDCLASSEX wcex;
448
449 wcex.cbSize = sizeof(WNDCLASSEX);
450
451 wcex.style = CS_HREDRAW | CS_VREDRAW;
452 wcex.lpfnWndProc = WndProc;
453 wcex.cbClsExtra = 0;
454 wcex.cbWndExtra = 0;
455 wcex.hInstance = hInstance;
456 wcex.hIcon = LoadIcon(hInstance, "Minecraft");
457 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
458 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
459 wcex.lpszMenuName = "Minecraft";
460 wcex.lpszClassName = "MinecraftClass";
461 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_MINECRAFTWINDOWS));
462
463 return RegisterClassEx(&wcex);
464}
465
466//
467// FUNCTION: InitInstance(HINSTANCE, int)
468//
469// PURPOSE: Saves instance handle and creates main window
470//
471// COMMENTS:
472//
473// In this function, we save the instance handle in a global variable and
474// create and display the main program window.
475//
476BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
477{
478 g_hInst = hInstance; // Store instance handle in our global variable
479
480 RECT wr = {0, 0, g_iScreenWidth, g_iScreenHeight}; // set the size, but not the position
481 AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); // adjust the size
482
483 g_hWnd = CreateWindow( "MinecraftClass",
484 "Minecraft",
485 WS_OVERLAPPEDWINDOW,
486 CW_USEDEFAULT,
487 0,
488 wr.right - wr.left, // width of the window
489 wr.bottom - wr.top, // height of the window
490 NULL,
491 NULL,
492 hInstance,
493 NULL);
494
495 if (!g_hWnd)
496 {
497 return FALSE;
498 }
499
500 ShowWindow(g_hWnd, nCmdShow);
501 UpdateWindow(g_hWnd);
502
503 return TRUE;
504}
505
506// 4J Stu - These functions are referenced from the Windows Input library
507void ClearGlobalText()
508{
509 // clear the global text
510 memset(chGlobalText,0,256);
511 memset(ui16GlobalText,0,512);
512}
513
514uint16_t *GetGlobalText()
515{
516 //copy the ch text to ui16
517 char * pchBuffer=(char *)ui16GlobalText;
518 for(int i=0;i<256;i++)
519 {
520 pchBuffer[i*2]=chGlobalText[i];
521 }
522 return ui16GlobalText;
523}
524void SeedEditBox()
525{
526 DialogBox(hMyInst, MAKEINTRESOURCE(IDD_SEED),
527 g_hWnd, reinterpret_cast<DLGPROC>(DlgProc));
528}
529
530
531//---------------------------------------------------------------------------
532LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
533{
534 switch(Msg)
535 {
536 case WM_INITDIALOG:
537 return TRUE;
538
539 case WM_COMMAND:
540 switch(wParam)
541 {
542 case IDOK:
543 // Set the text
544 GetDlgItemText(hWndDlg,IDC_EDIT,chGlobalText,256);
545 EndDialog(hWndDlg, 0);
546 return TRUE;
547 }
548 break;
549 }
550
551 return FALSE;
552}
553
554//--------------------------------------------------------------------------------------
555// Create Direct3D device and swap chain
556//--------------------------------------------------------------------------------------
557HRESULT InitDevice()
558{
559 HRESULT hr = S_OK;
560
561 RECT rc;
562 GetClientRect( g_hWnd, &rc );
563 UINT width = rc.right - rc.left;
564 UINT height = rc.bottom - rc.top;
565//app.DebugPrintf("width: %d, height: %d\n", width, height);
566 width = g_iScreenWidth;
567 height = g_iScreenHeight;
568app.DebugPrintf("width: %d, height: %d\n", width, height);
569
570 UINT createDeviceFlags = 0;
571#ifdef _DEBUG
572 createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
573#endif
574
575 D3D_DRIVER_TYPE driverTypes[] =
576 {
577 D3D_DRIVER_TYPE_HARDWARE,
578 D3D_DRIVER_TYPE_WARP,
579 D3D_DRIVER_TYPE_REFERENCE,
580 };
581 UINT numDriverTypes = ARRAYSIZE( driverTypes );
582
583 D3D_FEATURE_LEVEL featureLevels[] =
584 {
585 D3D_FEATURE_LEVEL_11_0,
586 D3D_FEATURE_LEVEL_10_1,
587 D3D_FEATURE_LEVEL_10_0,
588 };
589 UINT numFeatureLevels = ARRAYSIZE( featureLevels );
590
591 DXGI_SWAP_CHAIN_DESC sd;
592 ZeroMemory( &sd, sizeof( sd ) );
593 sd.BufferCount = 1;
594 sd.BufferDesc.Width = width;
595 sd.BufferDesc.Height = height;
596 sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
597 sd.BufferDesc.RefreshRate.Numerator = 60;
598 sd.BufferDesc.RefreshRate.Denominator = 1;
599 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
600 sd.OutputWindow = g_hWnd;
601 sd.SampleDesc.Count = 1;
602 sd.SampleDesc.Quality = 0;
603 sd.Windowed = TRUE;
604
605 for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
606 {
607 g_driverType = driverTypes[driverTypeIndex];
608 hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
609 D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
610 if( HRESULT_SUCCEEDED( hr ) )
611 break;
612 }
613 if( FAILED( hr ) )
614 return hr;
615
616 // Create a render target view
617 ID3D11Texture2D* pBackBuffer = NULL;
618 hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
619 if( FAILED( hr ) )
620 return hr;
621
622 // Create a depth stencil buffer
623 D3D11_TEXTURE2D_DESC descDepth;
624 ZeroMemory(&descDepth, sizeof(descDepth));
625
626 descDepth.Width = width;
627 descDepth.Height = height;
628 descDepth.MipLevels = 1;
629 descDepth.ArraySize = 1;
630 descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
631 descDepth.SampleDesc.Count = 1;
632 descDepth.SampleDesc.Quality = 0;
633 descDepth.Usage = D3D11_USAGE_DEFAULT;
634 descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
635 descDepth.CPUAccessFlags = 0;
636 descDepth.MiscFlags = 0;
637 hr = g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencilBuffer);
638
639 D3D11_DEPTH_STENCIL_VIEW_DESC descDSView;
640 ZeroMemory(&descDSView, sizeof(descDSView));
641 descDSView.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
642 descDSView.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
643 descDSView.Texture2D.MipSlice = 0;
644
645 hr = g_pd3dDevice->CreateDepthStencilView(g_pDepthStencilBuffer, &descDSView, &g_pDepthStencilView);
646
647 hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
648 pBackBuffer->Release();
649 if( FAILED( hr ) )
650 return hr;
651
652 g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, g_pDepthStencilView );
653
654 // Setup the viewport
655 D3D11_VIEWPORT vp;
656 vp.Width = (FLOAT)width;
657 vp.Height = (FLOAT)height;
658 vp.MinDepth = 0.0f;
659 vp.MaxDepth = 1.0f;
660 vp.TopLeftX = 0;
661 vp.TopLeftY = 0;
662 g_pImmediateContext->RSSetViewports( 1, &vp );
663
664 RenderManager.Initialise(g_pd3dDevice, g_pSwapChain);
665
666 return S_OK;
667}
668
669//--------------------------------------------------------------------------------------
670// Render the frame
671//--------------------------------------------------------------------------------------
672void Render()
673{
674 // Just clear the backbuffer
675 float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha
676
677 g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor );
678 g_pSwapChain->Present( 0, 0 );
679}
680
681//--------------------------------------------------------------------------------------
682// Toggle borderless fullscreen
683//--------------------------------------------------------------------------------------
684void ToggleFullscreen()
685{
686 DWORD dwStyle = GetWindowLong(g_hWnd, GWL_STYLE);
687 if (!g_isFullscreen)
688 {
689 MONITORINFO mi = { sizeof(mi) };
690 if (GetWindowPlacement(g_hWnd, &g_wpPrev) &&
691 GetMonitorInfo(MonitorFromWindow(g_hWnd, MONITOR_DEFAULTTOPRIMARY), &mi))
692 {
693 SetWindowLong(g_hWnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
694 SetWindowPos(g_hWnd, HWND_TOP,
695 mi.rcMonitor.left, mi.rcMonitor.top,
696 mi.rcMonitor.right - mi.rcMonitor.left,
697 mi.rcMonitor.bottom - mi.rcMonitor.top,
698 SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
699 }
700 }
701 else
702 {
703 SetWindowLong(g_hWnd, GWL_STYLE, dwStyle | WS_OVERLAPPEDWINDOW);
704 SetWindowPlacement(g_hWnd, &g_wpPrev);
705 SetWindowPos(g_hWnd, NULL, 0, 0, 0, 0,
706 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
707 }
708 g_isFullscreen = !g_isFullscreen;
709}
710
711//--------------------------------------------------------------------------------------
712// Clean up the objects we've created
713//--------------------------------------------------------------------------------------
714void CleanupDevice()
715{
716 if( g_pImmediateContext ) g_pImmediateContext->ClearState();
717
718 if( g_pRenderTargetView ) g_pRenderTargetView->Release();
719 if( g_pSwapChain ) g_pSwapChain->Release();
720 if( g_pImmediateContext ) g_pImmediateContext->Release();
721 if( g_pd3dDevice ) g_pd3dDevice->Release();
722}
723
724int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
725 _In_opt_ HINSTANCE hPrevInstance,
726 _In_ LPTSTR lpCmdLine,
727 _In_ int nCmdShow)
728{
729 UNREFERENCED_PARAMETER(hPrevInstance);
730 UNREFERENCED_PARAMETER(lpCmdLine);
731
732 // 4J-Win64: set CWD to exe dir so asset paths resolve correctly
733 {
734 char szExeDir[MAX_PATH] = {};
735 GetModuleFileNameA(NULL, szExeDir, MAX_PATH);
736 char *pSlash = strrchr(szExeDir, '\\');
737 if (pSlash) { *(pSlash + 1) = '\0'; SetCurrentDirectoryA(szExeDir); }
738 }
739
740 // Declare DPI awareness so GetSystemMetrics returns physical pixels
741 SetProcessDPIAware();
742 g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
743 g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN);
744
745 if(lpCmdLine)
746 {
747 if(lpCmdLine[0] == '1')
748 {
749 g_iScreenWidth = 1280;
750 g_iScreenHeight = 720;
751 }
752 else if(lpCmdLine[0] == '2')
753 {
754 g_iScreenWidth = 640;
755 g_iScreenHeight = 480;
756 }
757 else if(lpCmdLine[0] == '3')
758 {
759 // Vita
760 g_iScreenWidth = 720;
761 g_iScreenHeight = 408;
762
763 // Vita native
764 //g_iScreenWidth = 960;
765 //g_iScreenHeight = 544;
766 }
767
768 char cmdLineA[1024];
769 strncpy_s(cmdLineA, sizeof(cmdLineA), lpCmdLine, _TRUNCATE);
770
771 char* nameArg = strstr(cmdLineA, "-name ");
772 if (nameArg)
773 {
774 nameArg += 6;
775 while (*nameArg == ' ') nameArg++;
776 char nameBuf[17];
777 int n = 0;
778 while (nameArg[n] && nameArg[n] != ' ' && n < 16) { nameBuf[n] = nameArg[n]; n++; }
779 nameBuf[n] = 0;
780 strncpy_s(g_Win64Username, 17, nameBuf, _TRUNCATE);
781 }
782 }
783
784 if (g_Win64Username[0] == 0)
785 {
786 DWORD sz = 17;
787 static bool seeded = false;
788 if (!seeded)
789 {
790 seeded = true;
791 srand((unsigned int)time(NULL));
792 }
793
794 int r = rand() % 10000; // 0�9999
795
796 snprintf(g_Win64Username, 17, "Player%04d", r);
797
798 g_Win64Username[16] = 0;
799 }
800
801 MultiByteToWideChar(CP_ACP, 0, g_Win64Username, -1, g_Win64UsernameW, 17);
802
803 // Initialize global strings
804 MyRegisterClass(hInstance);
805
806 // Perform application initialization:
807 if (!InitInstance (hInstance, nCmdShow))
808 {
809 return FALSE;
810 }
811
812 hMyInst=hInstance;
813
814 if( FAILED( InitDevice() ) )
815 {
816 CleanupDevice();
817 return 0;
818 }
819
820#if 0
821 // Main message loop
822 MSG msg = {0};
823 while( WM_QUIT != msg.message )
824 {
825 if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
826 {
827 TranslateMessage( &msg );
828 DispatchMessage( &msg );
829 }
830 else
831 {
832 Render();
833 }
834 }
835
836 return (int) msg.wParam;
837#endif
838
839 static bool bTrialTimerDisplayed=true;
840
841#ifdef MEMORY_TRACKING
842 ResetMem();
843 MEMORYSTATUS memStat;
844 GlobalMemoryStatus(&memStat);
845 printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024));
846#endif
847
848#if 0
849 // Initialize D3D
850 hr = InitD3D( &pDevice, &d3dpp );
851 g_pD3DDevice = pDevice;
852 if( FAILED(hr) )
853 {
854 app.DebugPrintf
855 ( "Failed initializing D3D.\n" );
856 return -1;
857 }
858
859 // Initialize the application, assuming sharing of the d3d interface.
860 hr = app.InitShared( pDevice, &d3dpp,
861 XuiPNGTextureLoader );
862
863 if ( FAILED(hr) )
864 {
865 app.DebugPrintf
866 ( "Failed initializing application.\n" );
867
868 return -1;
869 }
870
871#endif
872 app.loadMediaArchive();
873
874 RenderManager.Initialise(g_pd3dDevice, g_pSwapChain);
875
876 app.loadStringTable();
877 ui.init(g_pd3dDevice,g_pImmediateContext,g_pRenderTargetView,g_pDepthStencilView,g_iScreenWidth,g_iScreenHeight);
878
879 ////////////////
880 // Initialise //
881 ////////////////
882
883 // Set the number of possible joypad layouts that the user can switch between, and the number of actions
884 InputManager.Initialise(1,3,MINECRAFT_ACTION_MAX, ACTION_MAX_MENU);
885
886 // Initialize keyboard/mouse input
887 KMInput.Init(g_hWnd);
888
889 // Set the default joypad action mappings for Minecraft
890 DefineActions();
891 InputManager.SetJoypadMapVal(0,0);
892 InputManager.SetKeyRepeatRate(0.3f,0.2f);
893
894 // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings
895 ProfileManager.Initialise(TITLEID_MINECRAFT,
896 app.m_dwOfferID,
897 PROFILE_VERSION_10,
898 NUM_PROFILE_VALUES,
899 NUM_PROFILE_SETTINGS,
900 dwProfileSettingsA,
901 app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT,
902 &app.uiGameDefinedDataChangedBitmask
903 );
904#if 0
905 // register the awards
906 ProfileManager.RegisterAward(eAward_TakingInventory, ACHIEVEMENT_01, eAwardType_Achievement);
907 ProfileManager.RegisterAward(eAward_GettingWood, ACHIEVEMENT_02, eAwardType_Achievement);
908 ProfileManager.RegisterAward(eAward_Benchmarking, ACHIEVEMENT_03, eAwardType_Achievement);
909 ProfileManager.RegisterAward(eAward_TimeToMine, ACHIEVEMENT_04, eAwardType_Achievement);
910 ProfileManager.RegisterAward(eAward_HotTopic, ACHIEVEMENT_05, eAwardType_Achievement);
911 ProfileManager.RegisterAward(eAward_AquireHardware, ACHIEVEMENT_06, eAwardType_Achievement);
912 ProfileManager.RegisterAward(eAward_TimeToFarm, ACHIEVEMENT_07, eAwardType_Achievement);
913 ProfileManager.RegisterAward(eAward_BakeBread, ACHIEVEMENT_08, eAwardType_Achievement);
914 ProfileManager.RegisterAward(eAward_TheLie, ACHIEVEMENT_09, eAwardType_Achievement);
915 ProfileManager.RegisterAward(eAward_GettingAnUpgrade, ACHIEVEMENT_10, eAwardType_Achievement);
916 ProfileManager.RegisterAward(eAward_DeliciousFish, ACHIEVEMENT_11, eAwardType_Achievement);
917 ProfileManager.RegisterAward(eAward_OnARail, ACHIEVEMENT_12, eAwardType_Achievement);
918 ProfileManager.RegisterAward(eAward_TimeToStrike, ACHIEVEMENT_13, eAwardType_Achievement);
919 ProfileManager.RegisterAward(eAward_MonsterHunter, ACHIEVEMENT_14, eAwardType_Achievement);
920 ProfileManager.RegisterAward(eAward_CowTipper, ACHIEVEMENT_15, eAwardType_Achievement);
921 ProfileManager.RegisterAward(eAward_WhenPigsFly, ACHIEVEMENT_16, eAwardType_Achievement);
922 ProfileManager.RegisterAward(eAward_LeaderOfThePack, ACHIEVEMENT_17, eAwardType_Achievement);
923 ProfileManager.RegisterAward(eAward_MOARTools, ACHIEVEMENT_18, eAwardType_Achievement);
924 ProfileManager.RegisterAward(eAward_DispenseWithThis, ACHIEVEMENT_19, eAwardType_Achievement);
925 ProfileManager.RegisterAward(eAward_InToTheNether, ACHIEVEMENT_20, eAwardType_Achievement);
926
927 ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK);
928 ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK);
929
930 ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK);
931 ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK);
932 ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK);
933
934 ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE);
935
936 // Rich Presence init - number of presences, number of contexts
937 ProfileManager.RichPresenceInit(4,1);
938 ProfileManager.RegisterRichPresenceContext(CONTEXT_GAME_STATE);
939
940 // initialise the storage manager with a default save display name, a Minimum save size, and a callback for displaying the saving message
941 StorageManager.Init(app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app);
942 // Set up the global title storage path
943 StorageManager.StoreTMSPathName();
944
945 // set a function to be called when there's a sign in change, so we can exit a level if the primary player signs out
946 ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app);
947
948 // set a function to be called when the ethernet is disconnected, so we can back out if required
949 ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app);
950
951#endif
952 // Set a callback for the default player options to be set - when there is no profile data for the player
953 ProfileManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app);
954#if 0
955 // Set a callback to deal with old profile versions needing updated to new versions
956 ProfileManager.SetOldProfileVersionCallback(&CConsoleMinecraftApp::OldProfileVersionCallback,(LPVOID)&app);
957
958 // Set a callback for when there is a read error on profile data
959 ProfileManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback,(LPVOID)&app);
960
961#endif
962 // QNet needs to be setup after profile manager, as we do not want its Notify listener to handle
963 // XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the
964 // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet.
965 g_NetworkManager.Initialise();
966
967 for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++)
968 {
969 IQNet::m_player[i].m_smallId = (BYTE)i;
970 IQNet::m_player[i].m_isRemote = false;
971 IQNet::m_player[i].m_isHostPlayer = (i == 0);
972 swprintf_s(IQNet::m_player[i].m_gamertag, 32, L"Player%d", i);
973 }
974 extern wchar_t g_Win64UsernameW[17];
975 wcscpy_s(IQNet::m_player[0].m_gamertag, 32, g_Win64UsernameW);
976
977 WinsockNetLayer::Initialize();
978
979 // 4J-PB moved further down
980 //app.InitGameSettings();
981
982 // debug switch to trial version
983 ProfileManager.SetDebugFullOverride(true);
984
985#if 0
986 //ProfileManager.AddDLC(2);
987 StorageManager.SetDLCPackageRoot("DLCDrive");
988 StorageManager.RegisterMarketplaceCountsCallback(&CConsoleMinecraftApp::MarketplaceCountsCallback,(LPVOID)&app);
989 // Kinect !
990
991 if(XNuiGetHardwareStatus()!=0)
992 {
993 // If the Kinect Sensor is not physically connected, this function returns 0.
994 NuiInitialize(NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH |
995 NUI_INITIALIZE_FLAG_EXTRAPOLATE_FLOOR_PLANE | NUI_INITIALIZE_FLAG_USES_FITNESS | NUI_INITIALIZE_FLAG_NUI_GUIDE_DISABLED | NUI_INITIALIZE_FLAG_SUPPRESS_AUTOMATIC_UI,NUI_INITIALIZE_DEFAULT_HARDWARE_THREAD );
996 }
997
998 // Sentient !
999 hr = TelemetryManager->Init();
1000
1001#endif
1002 // Initialise TLS for tesselator, for this main thread
1003 Tesselator::CreateNewThreadStorage(1024*1024);
1004 // Initialise TLS for AABB and Vec3 pools, for this main thread
1005 AABB::CreateNewThreadStorage();
1006 Vec3::CreateNewThreadStorage();
1007 IntCache::CreateNewThreadStorage();
1008 Compression::CreateNewThreadStorage();
1009 OldChunkStorage::CreateNewThreadStorage();
1010 Level::enableLightingCache();
1011 Tile::CreateNewThreadStorage();
1012
1013 Minecraft::main();
1014 Minecraft *pMinecraft=Minecraft::GetInstance();
1015
1016 app.InitGameSettings();
1017
1018#if 0
1019 //bool bDisplayPauseMenu=false;
1020
1021 // set the default gamma level
1022 float fVal=50.0f*327.68f;
1023 RenderManager.UpdateGamma((unsigned short)fVal);
1024
1025 // load any skins
1026 //app.AddSkinsToMemoryTextureFiles();
1027
1028 // set the achievement text for a trial achievement, now we have the string table loaded
1029 ProfileManager.SetTrialTextStringTable(app.GetStringTable(),IDS_CONFIRM_OK, IDS_CONFIRM_CANCEL);
1030 ProfileManager.SetTrialAwardText(eAwardType_Achievement,IDS_UNLOCK_TITLE,IDS_UNLOCK_ACHIEVEMENT_TEXT);
1031 ProfileManager.SetTrialAwardText(eAwardType_GamerPic,IDS_UNLOCK_TITLE,IDS_UNLOCK_GAMERPIC_TEXT);
1032 ProfileManager.SetTrialAwardText(eAwardType_AvatarItem,IDS_UNLOCK_TITLE,IDS_UNLOCK_AVATAR_TEXT);
1033 ProfileManager.SetTrialAwardText(eAwardType_Theme,IDS_UNLOCK_TITLE,IDS_UNLOCK_THEME_TEXT);
1034 ProfileManager.SetUpsellCallback(&app.UpsellReturnedCallback,&app);
1035
1036 // Set up a debug character press sequence
1037#ifndef _FINAL_BUILD
1038 app.SetDebugSequence("LRLRYYY");
1039#endif
1040
1041 // Initialise the social networking manager.
1042 CSocialManager::Instance()->Initialise();
1043
1044 // Update the base scene quick selects now that the minecraft class exists
1045 //CXuiSceneBase::UpdateScreenSettings(0);
1046#endif
1047 app.InitialiseTips();
1048#if 0
1049
1050 DWORD initData=0;
1051
1052#ifndef _FINAL_BUILD
1053#ifndef _DEBUG
1054#pragma message(__LOC__"Need to define the _FINAL_BUILD before submission")
1055#endif
1056#endif
1057
1058 // Set the default sound levels
1059 pMinecraft->options->set(Options::Option::MUSIC,1.0f);
1060 pMinecraft->options->set(Options::Option::SOUND,1.0f);
1061
1062 app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData);
1063#endif
1064
1065 // Set the default sound levels
1066 pMinecraft->options->set(Options::Option::MUSIC,1.0f);
1067 pMinecraft->options->set(Options::Option::SOUND,1.0f);
1068
1069 //app.TemporaryCreateGameStart();
1070
1071 //Sleep(10000);
1072#if 0
1073 // Intro loop ?
1074 while(app.IntroRunning())
1075 {
1076 ProfileManager.Tick();
1077 // Tick XUI
1078 app.RunFrame();
1079
1080 // 4J : WESTY : Added to ensure we always have clear background for intro.
1081 RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255));
1082 RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1083
1084 // Render XUI
1085 hr = app.Render();
1086
1087 // Present the frame.
1088 RenderManager.Present();
1089
1090 // Update XUI Timers
1091 hr = XuiTimersRun();
1092 }
1093#endif
1094 MSG msg = {0};
1095 while( WM_QUIT != msg.message && !app.m_bShutdown)
1096 {
1097 if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
1098 {
1099 TranslateMessage( &msg );
1100 DispatchMessage( &msg );
1101 continue;
1102 }
1103 RenderManager.StartFrame();
1104#if 0
1105 if(pMinecraft->soundEngine->isStreamingWavebankReady() &&
1106 !pMinecraft->soundEngine->isPlayingStreamingGameMusic() &&
1107 !pMinecraft->soundEngine->isPlayingStreamingCDMusic() )
1108 {
1109 // play some music in the menus
1110 pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false);
1111 }
1112#endif
1113
1114 // static bool bPlay=false;
1115 // if(bPlay)
1116 // {
1117 // bPlay=false;
1118 // app.audio.PlaySound();
1119 // }
1120
1121 app.UpdateTime();
1122 PIXBeginNamedEvent(0,"Input manager tick");
1123 InputManager.Tick();
1124 KMInput.Tick();
1125 PIXEndNamedEvent();
1126 PIXBeginNamedEvent(0,"Profile manager tick");
1127 // ProfileManager.Tick();
1128 PIXEndNamedEvent();
1129 PIXBeginNamedEvent(0,"Storage manager tick");
1130 StorageManager.Tick();
1131 PIXEndNamedEvent();
1132 PIXBeginNamedEvent(0,"Render manager tick");
1133 RenderManager.Tick();
1134 PIXEndNamedEvent();
1135
1136 // Tick the social networking manager.
1137 PIXBeginNamedEvent(0,"Social network manager tick");
1138 // CSocialManager::Instance()->Tick();
1139 PIXEndNamedEvent();
1140
1141 // Tick sentient.
1142 PIXBeginNamedEvent(0,"Sentient tick");
1143 MemSect(37);
1144 // SentientManager.Tick();
1145 MemSect(0);
1146 PIXEndNamedEvent();
1147
1148 PIXBeginNamedEvent(0,"Network manager do work #1");
1149 g_NetworkManager.DoWork();
1150 PIXEndNamedEvent();
1151
1152 // LeaderboardManager::Instance()->Tick();
1153 // Render game graphics.
1154 if(app.GetGameStarted())
1155 {
1156 pMinecraft->applyFrameMouseLook(); // Per-frame mouse look (before ticks + render)
1157 pMinecraft->run_middle();
1158 app.SetAppPaused( g_NetworkManager.IsLocalGame() && g_NetworkManager.GetPlayerCount() == 1 && ui.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()) );
1159 }
1160 else
1161 {
1162 MemSect(28);
1163 pMinecraft->soundEngine->tick(NULL, 0.0f);
1164 MemSect(0);
1165 pMinecraft->textures->tick(true,false);
1166 IntCache::Reset();
1167 if( app.GetReallyChangingSessionType() )
1168 {
1169 pMinecraft->tickAllConnections(); // Added to stop timing out when we are waiting after converting to an offline game
1170 }
1171 }
1172
1173 pMinecraft->soundEngine->playMusicTick();
1174
1175#ifdef MEMORY_TRACKING
1176 static bool bResetMemTrack = false;
1177 static bool bDumpMemTrack = false;
1178
1179 MemPixStuff();
1180
1181 if( bResetMemTrack )
1182 {
1183 ResetMem();
1184 MEMORYSTATUS memStat;
1185 GlobalMemoryStatus(&memStat);
1186 printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024));
1187 bResetMemTrack = false;
1188 }
1189
1190 if( bDumpMemTrack )
1191 {
1192 DumpMem();
1193 bDumpMemTrack = false;
1194 MEMORYSTATUS memStat;
1195 GlobalMemoryStatus(&memStat);
1196 printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024));
1197 printf("Renderer used: %d\n",RenderManager.CBuffSize(-1));
1198 }
1199#endif
1200#if 0
1201 static bool bDumpTextureUsage = false;
1202 if( bDumpTextureUsage )
1203 {
1204 RenderManager.TextureGetStats();
1205 bDumpTextureUsage = false;
1206 }
1207#endif
1208 ui.tick();
1209 ui.render();
1210#if 0
1211 app.HandleButtonPresses();
1212
1213 // store the minecraft renderstates, and re-set them after the xui render
1214 GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA);
1215
1216 // Tick XUI
1217 PIXBeginNamedEvent(0,"Xui running");
1218 app.RunFrame();
1219 PIXEndNamedEvent();
1220
1221 // Render XUI
1222
1223 PIXBeginNamedEvent(0,"XUI render");
1224 MemSect(7);
1225 hr = app.Render();
1226 MemSect(0);
1227 GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2);
1228 PIXEndNamedEvent();
1229
1230 for(int i=0;i<8;i++)
1231 {
1232 if(RenderStateA2[i]!=RenderStateA[i])
1233 {
1234 //printf("Reseting RenderStateA[%d] after a XUI render\n",i);
1235 pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]);
1236 }
1237 }
1238 for(int i=0;i<5;i++)
1239 {
1240 if(SamplerStateA2[i]!=SamplerStateA[i])
1241 {
1242 //printf("Reseting SamplerStateA[%d] after a XUI render\n",i);
1243 pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]);
1244 }
1245 }
1246
1247 RenderManager.Set_matrixDirty();
1248#endif
1249 // Present the frame.
1250 RenderManager.Present();
1251
1252 ui.CheckMenuDisplayed();
1253
1254 // Update mouse capture: capture when in-game and no menu is open
1255 {
1256 static bool altToggleSuppressCapture = false;
1257 bool shouldCapture = app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL;
1258 // Left Alt key toggles capture on/off for debugging
1259 if (KMInput.IsKeyPressed(VK_MENU))
1260 {
1261 if (KMInput.IsCaptured()) { KMInput.SetCapture(false); altToggleSuppressCapture = true; }
1262 else if (shouldCapture) { KMInput.SetCapture(true); altToggleSuppressCapture = false; }
1263 }
1264 else if (!shouldCapture)
1265 {
1266 if (KMInput.IsCaptured()) KMInput.SetCapture(false);
1267 altToggleSuppressCapture = false;
1268 }
1269 else if (shouldCapture && !KMInput.IsCaptured() && GetFocus() == g_hWnd && !altToggleSuppressCapture)
1270 {
1271 KMInput.SetCapture(true);
1272 }
1273 }
1274
1275 // F3 toggles the debug console overlay, F11 toggles fullscreen
1276 if (KMInput.IsKeyPressed(VK_F3))
1277 {
1278 static bool s_debugConsole = false;
1279 s_debugConsole = !s_debugConsole;
1280 ui.ShowUIDebugConsole(s_debugConsole);
1281 }
1282
1283#ifdef _DEBUG_MENUS_ENABLED
1284 if (KMInput.IsKeyPressed(VK_F4))
1285 {
1286 ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_DebugOverlay, NULL, eUILayer_Debug);
1287 }
1288#endif
1289
1290 if (KMInput.IsKeyPressed(VK_F11))
1291 {
1292 ToggleFullscreen();
1293 }
1294
1295 // TAB opens game info menu. - Vvis :3 - Updated by detectiveren
1296 if (KMInput.IsKeyPressed(VK_TAB) && !ui.GetMenuDisplayed(0))
1297 {
1298 if (Minecraft* pMinecraft = Minecraft::GetInstance())
1299 {
1300 {
1301 ui.NavigateToScene(0, eUIScene_InGameInfoMenu);
1302
1303 }
1304 }
1305 }
1306
1307#ifdef _DEBUG_MENUS_ENABLED
1308 // F3 toggles onscreen debug info
1309 if (KMInput.IsKeyPressed(VK_F3))
1310 {
1311 if (Minecraft* pMinecraft = Minecraft::GetInstance())
1312 {
1313 if (pMinecraft->options && app.DebugSettingsOn())
1314 {
1315 pMinecraft->options->renderDebug = !pMinecraft->options->renderDebug;
1316 }
1317 }
1318 }
1319
1320 // F4 opens debug overlay
1321 if (KMInput.IsKeyPressed(VK_F4))
1322 {
1323 if (Minecraft* pMinecraft = Minecraft::GetInstance())
1324 {
1325 if (pMinecraft->options && app.DebugSettingsOn() &&
1326 app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL)
1327 {
1328 ui.NavigateToScene(0, eUIScene_DebugOverlay, NULL, eUILayer_Debug);
1329 }
1330 }
1331 }
1332#endif
1333
1334#if 0
1335 // has the game defined profile data been changed (by a profile load)
1336 if(app.uiGameDefinedDataChangedBitmask!=0)
1337 {
1338 void *pData;
1339 for(int i=0;i<XUSER_MAX_COUNT;i++)
1340 {
1341 if(app.uiGameDefinedDataChangedBitmask&(1<<i))
1342 {\
1343 // It has - game needs to update its values with the data from the profile
1344 pData=ProfileManager.GetGameDefinedProfileData(i);
1345 // reset the changed flag
1346 app.ClearGameSettingsChangedFlag(i);
1347 app.DebugPrintf("*** - APPLYING GAME SETTINGS CHANGE for pad %d\n",i);
1348 app.ApplyGameSettingsChanged(i);
1349
1350#ifdef _DEBUG_MENUS_ENABLED
1351 if(app.DebugSettingsOn())
1352 {
1353 app.ActionDebugMask(i);
1354 }
1355 else
1356 {
1357 // force debug mask off
1358 app.ActionDebugMask(i,true);
1359 }
1360#endif
1361 // clear the stats first - there could have beena signout and sign back in in the menus
1362 // need to clear the player stats - can't assume it'll be done in setlevel - we may not be in the game
1363 pMinecraft->stats[ i ]->clear();
1364 pMinecraft->stats[i]->parse(pData);
1365 }
1366 }
1367
1368 // Check to see if we can post to social networks.
1369 CSocialManager::Instance()->RefreshPostingCapability();
1370
1371 // clear the flag
1372 app.uiGameDefinedDataChangedBitmask=0;
1373
1374 // Check if any profile write are needed
1375 app.CheckGameSettingsChanged();
1376 }
1377 PIXEndNamedEvent();
1378 app.TickDLCOffersRetrieved();
1379 app.TickTMSPPFilesRetrieved();
1380
1381 PIXBeginNamedEvent(0,"Network manager do work #2");
1382 g_NetworkManager.DoWork();
1383 PIXEndNamedEvent();
1384
1385 PIXBeginNamedEvent(0,"Misc extra xui");
1386 // Update XUI Timers
1387 hr = XuiTimersRun();
1388
1389#endif
1390 // Any threading type things to deal with from the xui side?
1391 app.HandleXuiActions();
1392
1393#if 0
1394 PIXEndNamedEvent();
1395#endif
1396
1397 // 4J-PB - Update the trial timer display if we are in the trial version
1398 if(!ProfileManager.IsFullVersion())
1399 {
1400 // display the trial timer
1401 if(app.GetGameStarted())
1402 {
1403 // 4J-PB - if the game is paused, add the elapsed time to the trial timer count so it doesn't tick down
1404 if(app.IsAppPaused())
1405 {
1406 app.UpdateTrialPausedTimer();
1407 }
1408 ui.UpdateTrialTimer(ProfileManager.GetPrimaryPad());
1409 }
1410 }
1411 else
1412 {
1413 // need to turn off the trial timer if it was on , and we've unlocked the full version
1414 if(bTrialTimerDisplayed)
1415 {
1416 ui.ShowTrialTimer(false);
1417 bTrialTimerDisplayed=false;
1418 }
1419 }
1420
1421 // Fix for #7318 - Title crashes after short soak in the leaderboards menu
1422 // A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset
1423 Vec3::resetPool();
1424
1425 KMInput.EndFrame();
1426 }
1427
1428 // Free resources, unregister custom classes, and exit.
1429 // app.Uninit();
1430 g_pd3dDevice->Release();
1431}
1432
1433#ifdef MEMORY_TRACKING
1434
1435int totalAllocGen = 0;
1436unordered_map<int,int> allocCounts;
1437bool trackEnable = false;
1438bool trackStarted = false;
1439volatile size_t sizeCheckMin = 1160;
1440volatile size_t sizeCheckMax = 1160;
1441volatile int sectCheck = 48;
1442CRITICAL_SECTION memCS;
1443DWORD tlsIdx;
1444
1445LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes)
1446{
1447 if( !trackStarted )
1448 {
1449 void *p = XMemAllocDefault(dwSize,dwAllocAttributes);
1450 size_t realSize = XMemSizeDefault(p, dwAllocAttributes);
1451 totalAllocGen += realSize;
1452 return p;
1453 }
1454
1455 EnterCriticalSection(&memCS);
1456
1457 void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes);
1458 size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16;
1459
1460 if( trackEnable )
1461 {
1462#if 1
1463 int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f;
1464 *(((unsigned char *)p)+realSize) = sect;
1465
1466 if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) )
1467 {
1468 app.DebugPrintf("Found one\n");
1469 }
1470#endif
1471
1472 if( p )
1473 {
1474 totalAllocGen += realSize;
1475 trackEnable = false;
1476 int key = ( sect << 26 ) | realSize;
1477 int oldCount = allocCounts[key];
1478 allocCounts[key] = oldCount + 1;
1479
1480 trackEnable = true;
1481 }
1482 }
1483
1484 LeaveCriticalSection(&memCS);
1485
1486 return p;
1487}
1488
1489void* operator new (size_t size)
1490{
1491 return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP));
1492}
1493
1494void operator delete (void *p)
1495{
1496 XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP));
1497}
1498
1499void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes)
1500{
1501 bool special = false;
1502 if( dwAllocAttributes == 0 )
1503 {
1504 dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP);
1505 special = true;
1506 }
1507 if(!trackStarted )
1508 {
1509 size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes);
1510 XMemFreeDefault(pAddress, dwAllocAttributes);
1511 totalAllocGen -= realSize;
1512 return;
1513 }
1514 EnterCriticalSection(&memCS);
1515 if( pAddress )
1516 {
1517 size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16;
1518
1519 if(trackEnable)
1520 {
1521 int sect = *(((unsigned char *)pAddress)+realSize);
1522 totalAllocGen -= realSize;
1523 trackEnable = false;
1524 int key = ( sect << 26 ) | realSize;
1525 int oldCount = allocCounts[key];
1526 allocCounts[key] = oldCount - 1;
1527 trackEnable = true;
1528 }
1529 XMemFreeDefault(pAddress, dwAllocAttributes);
1530 }
1531 LeaveCriticalSection(&memCS);
1532}
1533
1534SIZE_T WINAPI XMemSize(
1535 PVOID pAddress,
1536 DWORD dwAllocAttributes
1537 )
1538{
1539 if( trackStarted )
1540 {
1541 return XMemSizeDefault(pAddress, dwAllocAttributes) - 16;
1542 }
1543 else
1544 {
1545 return XMemSizeDefault(pAddress, dwAllocAttributes);
1546 }
1547}
1548
1549void DumpMem()
1550{
1551 int totalLeak = 0;
1552 for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ )
1553 {
1554 if(it->second > 0 )
1555 {
1556 app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second);
1557 totalLeak += ( it->first & 0x03ffffff ) * it->second;
1558 }
1559 }
1560 app.DebugPrintf("Total %d\n",totalLeak);
1561}
1562
1563void ResetMem()
1564{
1565 if( !trackStarted )
1566 {
1567 trackEnable = true;
1568 trackStarted = true;
1569 totalAllocGen = 0;
1570 InitializeCriticalSection(&memCS);
1571 tlsIdx = TlsAlloc();
1572 }
1573 EnterCriticalSection(&memCS);
1574 trackEnable = false;
1575 allocCounts.clear();
1576 trackEnable = true;
1577 LeaveCriticalSection(&memCS);
1578}
1579
1580void MemSect(int section)
1581{
1582 unsigned int value = (unsigned int)TlsGetValue(tlsIdx);
1583 if( section == 0 ) // pop
1584 {
1585 value = (value >> 6) & 0x03ffffff;
1586 }
1587 else
1588 {
1589 value = (value << 6) | section;
1590 }
1591 TlsSetValue(tlsIdx, (LPVOID)value);
1592}
1593
1594void MemPixStuff()
1595{
1596 const int MAX_SECT = 46;
1597
1598 int totals[MAX_SECT] = {0};
1599
1600 for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ )
1601 {
1602 if(it->second > 0 )
1603 {
1604 int sect = ( it->first >> 26 ) & 0x3f;
1605 int bytes = it->first & 0x03ffffff;
1606 totals[sect] += bytes * it->second;
1607 }
1608 }
1609
1610 unsigned int allSectsTotal = 0;
1611 for( int i = 0; i < MAX_SECT; i++ )
1612 {
1613 allSectsTotal += totals[i];
1614 PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i);
1615 }
1616
1617 PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages");
1618}
1619
1620#endif