mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-05-22 10:44:49 +00:00
246 lines
7.6 KiB
C++
246 lines
7.6 KiB
C++
#include "stdafx.h"
|
|
#include "Windows64_DiscordPresence.h"
|
|
#include "..\Common\Consoles_App.h"
|
|
#include "..\User.h"
|
|
#include "..\..\Minecraft.Client\Minecraft.h"
|
|
#include "..\..\Minecraft.Client\MinecraftServer.h"
|
|
#include "..\..\Minecraft.World\LevelSettings.h"
|
|
|
|
CConsoleMinecraftApp app;
|
|
|
|
CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp()
|
|
{
|
|
m_bShutdown = false;
|
|
}
|
|
|
|
void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId)
|
|
{
|
|
g_DiscordPresence.SetPresenceContext(contextId);
|
|
}
|
|
|
|
void CConsoleMinecraftApp::StoreLaunchData() {}
|
|
|
|
void CConsoleMinecraftApp::ExitGame()
|
|
{
|
|
m_bShutdown = true;
|
|
}
|
|
|
|
void CConsoleMinecraftApp::FatalLoadError()
|
|
{
|
|
ExitGame();
|
|
}
|
|
|
|
LONG WINAPI CConsoleMinecraftApp::UnhandledExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo)
|
|
{
|
|
/*
|
|
SYSTEMTIME st;
|
|
GetLocalTime(&st);
|
|
|
|
char exeName[MAX_PATH];
|
|
GetModuleFileNameA(nullptr, exeName, MAX_PATH);
|
|
PathStripPath(exeName);
|
|
PathRemoveExtension(exeName);
|
|
|
|
char dumpFilePath[MAX_PATH];
|
|
sprintf(dumpFilePath, "%s_crash_%02d_%02d_%04d_%02d_%02d_%02d.dmp", exeName, st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond);
|
|
|
|
HANDLE hDumpFile = CreateFile(dumpFilePath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
if (hDumpFile != INVALID_HANDLE_VALUE)
|
|
{
|
|
MINIDUMP_EXCEPTION_INFORMATION mei{};
|
|
mei.ThreadId = GetCurrentThreadId();
|
|
mei.ExceptionPointers = pExceptionInfo;
|
|
mei.ClientPointers = FALSE;
|
|
|
|
MINIDUMP_TYPE dumpType =
|
|
#ifdef _DEBUG
|
|
MiniDumpWithFullMemory;
|
|
#else
|
|
(MINIDUMP_TYPE)(MiniDumpWithDataSegs | MiniDumpWithHandleData | MiniDumpWithThreadInfo);
|
|
#endif
|
|
|
|
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, dumpType, pExceptionInfo ? &mei : nullptr, nullptr, nullptr);
|
|
CloseHandle(hDumpFile);
|
|
}
|
|
|
|
auto ExceptionName = [](DWORD code) -> const wchar_t*
|
|
{
|
|
switch (code)
|
|
{
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
|
return L"Access Violation";
|
|
|
|
case EXCEPTION_STACK_OVERFLOW:
|
|
return L"Stack Overflow";
|
|
|
|
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
|
return L"Integer Divide by Zero";
|
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
|
return L"Illegal Instruction";
|
|
|
|
case EXCEPTION_IN_PAGE_ERROR:
|
|
return L"In-Page Error";
|
|
|
|
case EXCEPTION_BREAKPOINT:
|
|
return L"Breakpoint";
|
|
|
|
default:
|
|
return L"Unknown Exception Name";
|
|
}
|
|
};
|
|
|
|
char logPath[MAX_PATH];
|
|
sprintf_s(logPath, "%s_crash_%02d_%02d_%04d_%02d_%02d_%02d.txt", exeName, st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond);
|
|
|
|
HANDLE hLogFile = CreateFile(logPath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
if (hLogFile != INVALID_HANDLE_VALUE)
|
|
{
|
|
char buf[1024];
|
|
int len = sprintf_s(buf, "Exception Code: 0x%08X (%ls)\nException Address: 0x%p", pExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionName(pExceptionInfo->ExceptionRecord->ExceptionCode), pExceptionInfo->ExceptionRecord->ExceptionAddress);
|
|
|
|
DWORD written;
|
|
WriteFile(hLogFile, buf, len, &written, nullptr);
|
|
CloseHandle(hLogFile);
|
|
}
|
|
|
|
char msg[1024];
|
|
|
|
if (pExceptionInfo && pExceptionInfo->ExceptionRecord)
|
|
{
|
|
DWORD code = pExceptionInfo->ExceptionRecord->ExceptionCode;
|
|
void* addr = pExceptionInfo->ExceptionRecord->ExceptionAddress;
|
|
|
|
sprintf_s(msg, "%s has run into a fatal error and must be closed.\n\nException: 0x%08X (%s)\nAddress: 0x%p\n\nA crash dump and log file have been written.", exeName, code, ExceptionName(code), addr);
|
|
}
|
|
else
|
|
{
|
|
sprintf_s(msg, "%s has run into a fatal error and must be closed.\n\nNo exception information was available.\n", exeName);
|
|
}
|
|
|
|
char title[1024];
|
|
sprintf_s(title, "%s - Fatal Error", exeName);
|
|
MessageBox(nullptr, msg, title, MB_OK | MB_ICONERROR);
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
*/
|
|
}
|
|
|
|
void CConsoleMinecraftApp::CaptureSaveThumbnail()
|
|
{
|
|
RenderManager.CaptureThumbnail(&m_ThumbnailBuffer);
|
|
}
|
|
void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *pbData,DWORD *pdwSize)
|
|
{
|
|
// On a save caused by a create world, the thumbnail capture won't have happened
|
|
if (m_ThumbnailBuffer.Allocated())
|
|
{
|
|
if (pbData)
|
|
{
|
|
*pbData = new BYTE[m_ThumbnailBuffer.GetBufferSize()];
|
|
*pdwSize = m_ThumbnailBuffer.GetBufferSize();
|
|
memcpy(*pbData, m_ThumbnailBuffer.GetBufferPointer(), *pdwSize);
|
|
}
|
|
m_ThumbnailBuffer.Release();
|
|
}
|
|
else
|
|
{
|
|
// No capture happened (e.g. first save on world creation) leave thumbnail as nullptr
|
|
if (pbData) *pbData = nullptr;
|
|
if (pdwSize) *pdwSize = 0;
|
|
}
|
|
}
|
|
void CConsoleMinecraftApp::ReleaseSaveThumbnail()
|
|
{
|
|
if (m_ThumbnailBuffer.Allocated())
|
|
m_ThumbnailBuffer.Release();
|
|
}
|
|
|
|
void CConsoleMinecraftApp::GetScreenshot(int iPad,PBYTE *pbData,DWORD *pdwSize) {}
|
|
|
|
void CConsoleMinecraftApp::TemporaryCreateGameStart()
|
|
{
|
|
////////////////////////////////////////////////////////////////////////////////////////////// From CScene_Main::OnInit
|
|
|
|
app.setLevelGenerationOptions(nullptr);
|
|
|
|
// From CScene_Main::RunPlayGame
|
|
Minecraft *pMinecraft=Minecraft::GetInstance();
|
|
app.ReleaseSaveThumbnail();
|
|
ProfileManager.SetLockedProfile(0);
|
|
extern wchar_t g_Win64UsernameW[17];
|
|
pMinecraft->user->name = g_Win64UsernameW;
|
|
app.ApplyGameSettingsChanged(0);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit
|
|
MinecraftServer::resetFlags();
|
|
|
|
// From CScene_MultiGameJoinLoad::OnNotifyPressEx
|
|
app.SetTutorialMode( false );
|
|
app.SetCorruptSaveDeleted(false);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameCreate::CreateGame
|
|
|
|
app.ClearTerrainFeaturePosition();
|
|
wstring wWorldName = L"TestWorld";
|
|
|
|
StorageManager.ResetSaveData();
|
|
StorageManager.SetSaveTitle(wWorldName.c_str());
|
|
|
|
bool isFlat = false;
|
|
int64_t seedValue = 0; // BiomeSource::findSeed(isFlat?LevelType::lvl_flat:LevelType::lvl_normal); // 4J - was (new Random())->nextLong() - now trying to actually find a seed to suit our requirements
|
|
|
|
NetworkGameInitData *param = new NetworkGameInitData();
|
|
param->seed = seedValue;
|
|
param->saveData = nullptr;
|
|
|
|
app.SetGameHostOption(eGameHostOption_Difficulty,0);
|
|
app.SetGameHostOption(eGameHostOption_FriendsOfFriends,0);
|
|
app.SetGameHostOption(eGameHostOption_Gamertags,1);
|
|
app.SetGameHostOption(eGameHostOption_BedrockFog,1);
|
|
|
|
app.SetGameHostOption(eGameHostOption_GameType,GameType::CREATIVE->getId() ); // LevelSettings::GAMETYPE_SURVIVAL
|
|
app.SetGameHostOption(eGameHostOption_LevelType, 0 );
|
|
app.SetGameHostOption(eGameHostOption_Structures, 1 );
|
|
app.SetGameHostOption(eGameHostOption_BonusChest, 0 );
|
|
|
|
app.SetGameHostOption(eGameHostOption_PvP, 1);
|
|
app.SetGameHostOption(eGameHostOption_TrustPlayers, 1 );
|
|
app.SetGameHostOption(eGameHostOption_FireSpreads, 1 );
|
|
app.SetGameHostOption(eGameHostOption_TNT, 1 );
|
|
app.SetGameHostOption(eGameHostOption_HostCanFly, 1);
|
|
app.SetGameHostOption(eGameHostOption_HostCanChangeHunger, 1);
|
|
app.SetGameHostOption(eGameHostOption_HostCanBeInvisible, 1 );
|
|
|
|
param->settings = app.GetGameHostOption( eGameHostOption_All );
|
|
|
|
g_NetworkManager.FakeLocalPlayerJoined();
|
|
|
|
LoadingInputParams *loadingParams = new LoadingInputParams();
|
|
loadingParams->func = &CGameNetworkManager::RunNetworkGameThreadProc;
|
|
loadingParams->lpParam = static_cast<LPVOID>(param);
|
|
|
|
// Reset the autosave time
|
|
app.SetAutosaveTimerTime();
|
|
|
|
C4JThread* thread = new C4JThread(loadingParams->func, loadingParams->lpParam, "RunNetworkGame");
|
|
thread->Run();
|
|
}
|
|
|
|
int CConsoleMinecraftApp::GetLocalTMSFileIndex(WCHAR *wchTMSFile,bool bFilenameIncludesExtension,eFileExtensionType eEXT)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
int CConsoleMinecraftApp::LoadLocalTMSFile(WCHAR *wchTMSFile)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
int CConsoleMinecraftApp::LoadLocalTMSFile(WCHAR *wchTMSFile, eFileExtensionType eExt)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
void CConsoleMinecraftApp::FreeLocalTMSFiles(eTMSFileType eType) {}
|