This commit is contained in:
watrabi
2025-09-18 17:55:52 -04:00
commit 977f1ff4b8
15030 changed files with 17324420 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
/* Copyright 2003-2005 ROBLOX Corporation, All Rights Reserved */
#include "rbx/Debug.h"
#include "RbxAssert.h"
#include "RbxFormat.h"
#include <algorithm>
const int CRASHONASSERT = 255;
void ReleaseAssert(int channel, const char* msg) {
if(channel == CRASHONASSERT)
RBXCRASH(msg);
else
FLog::FastLog(channel, msg, 0);
}
namespace RBX
{
// overload this in the debugger to pass by the crash
volatile bool Debugable::doCrashEnabled = true;
void Debugable::doCrash()
{
if(doCrashEnabled)
{
DebugBreak();
}
}
#pragma optimize ("", off )
void Debugable::doCrash(const char* message)
{
#if defined(RBX_PLATFORM_DURANGO)
OutputDebugStringA("ASSERTION FAILED: ");
OutputDebugStringA(message);
OutputDebugStringA("\n");
if (!IsDebuggerPresent())
return;
#endif
if (doCrashEnabled)
{
DebugBreak();
}
}
#pragma optimize ("", on )
} // rbx namespace
+167
View File
@@ -0,0 +1,167 @@
#include "rbx/Log.h"
#include "RbxFormat.h"
#ifdef _WIN32
#include <Windows.h>
#define sprints sprintf_s
#define wcstombs wcstombs_s
#else
#endif
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/date_time/gregorian/gregorian.hpp"
#include "boost/date_time/gregorian/greg_year.hpp"
using namespace RBX;
#include "rbx/rbxTime.h"
ILogProvider* Log::provider = NULL;
Log::Severity Log::aggregateWorstSeverity = Log::Information;
void Log::timeStamp(std::ofstream& stream, bool includeDate)
{
boost::posix_time::ptime stime(boost::posix_time::second_clock::local_time());
char s[256];
if (includeDate)
{
boost::gregorian::date date(stime.date());
snprintf(s, ARRAYSIZE(s), "%02u.%02u.%u ", date.day().as_number(), date.month().as_number(), (unsigned short)date.year());
stream << s;
}
boost::posix_time::time_duration dur(stime.time_of_day());
snprintf(s, ARRAYSIZE(s), "%02u:%02u:%02u.%03u (%03.07f)", dur.hours(), dur.minutes(), dur.seconds(), (unsigned short)dur.total_milliseconds(), Time::nowFastSec());
stream << s;
stream.flush();
}
Log::Log(const char* logFile, const char* name)
:stream(logFile)
,logFile(logFile)
,worstSeverity(Information)
,name(name)
{
Log::timeStamp(stream, true);
stream << "Log \"" << name << "\"\n";
stream.flush();
}
Log::~Log(void)
{
Log::timeStamp(stream, true);
stream << "End Log\n";
}
void Log::setLogProvider(ILogProvider* provider)
{
Log::provider = provider;
}
void Log::writeEntry(Severity severity, const wchar_t* message)
{
// Convert to a char*
size_t origsize = wcslen(message) + 1;
const size_t newsize = origsize+100;
size_t convertedChars = 0;
char* nstring = new char[newsize];
#ifdef _WIN32
wcstombs_s(&convertedChars, nstring, origsize, message, _TRUNCATE);
#else
convertedChars = wcstombs(nstring, message, origsize);
#endif
if ( convertedChars >= origsize-1 )
nstring[origsize-1] = '\0';
writeEntry(severity, nstring);
delete [] nstring;
}
void Log::writeEntry(Severity severity, const char* message)
{
static const char* error = " Error: ";
static const char* warning = " Warning: ";
static const char* information = " ";
Log::timeStamp(stream, false);
switch (severity)
{
case Log::Error:
stream << error;
break;
case Log::Warning:
stream << warning;
break;
case Log::Information:
stream << information;
break;
}
stream << message;
stream << '\n';
stream.flush();
}
std::string Log::formatMem(unsigned int bytes)
{
char buffer[64];
if (bytes<1000)
snprintf(buffer, ARRAYSIZE(buffer), "%dB", bytes);
else if (bytes<100000)
snprintf(buffer, ARRAYSIZE(buffer), "%.1fKB", ((double)bytes)/1000.0);
else if (bytes<1000000)
snprintf(buffer, ARRAYSIZE(buffer), "%.0fKB", ((double)bytes)/1000.0);
else if (bytes<100000000)
snprintf(buffer, ARRAYSIZE(buffer), "%.1fMB", ((double)bytes)/1000000.0);
else if (bytes<1000000000)
snprintf(buffer, ARRAYSIZE(buffer), "%.0fMB", ((double)bytes)/1000000.0);
#ifdef _WIN32
// NOTE: 100000000000 is too big to fit in uint. EL
else if (bytes<100000000000)
snprintf(buffer, ARRAYSIZE(buffer), "%.1fGB", ((double)bytes)/1000000000.0);
#endif
else
snprintf(buffer, ARRAYSIZE(buffer), "%.0fGB", ((double)bytes)/1000000000.0);
return buffer;
}
std::string Log::formatTime(double time)
{
char buffer[64];
if (time==0.0)
snprintf(buffer, ARRAYSIZE(buffer), "0s");
if (time<0.0)
snprintf(buffer, ARRAYSIZE(buffer), "%.3gs", time);
else if (time>=0.1)
snprintf(buffer, ARRAYSIZE(buffer), "%.3gs", time);
else
snprintf(buffer, ARRAYSIZE(buffer), "%.3gms", time*1000.0);
return buffer;
}
void Log::timeStamp(bool includeDate)
{
Log::timeStamp(Log::currentStream(), includeDate);
}
LOGVARIABLE(Crash, 1)
LOGVARIABLE(HangDetection, 0)
LOGVARIABLE(ContentProviderCleanup, 0)
LOGVARIABLE(ISteppedLifetime, 0)
LOGVARIABLE(MutexLifetime, 0)
LOGVARIABLE(TaskScheduler, 0)
LOGVARIABLE(TaskSchedulerInit, 0)
LOGVARIABLE(TaskSchedulerRun, 0)
LOGVARIABLE(TaskSchedulerFindJob, 0)
LOGVARIABLE(TaskSchedulerSteps, 0)
LOGVARIABLE(Asserts, 0)
LOGVARIABLE(FWLifetime, 0)
LOGVARIABLE(FWUpdate, 0)
LOGVARIABLE(KernelStats, 0)
void initBaseLog()
{
}
+20
View File
@@ -0,0 +1,20 @@
/*
* RbxCrash.cpp
* MacClient
*
* Created by elebel on 7/20/10.
* Copyright 2010 Roblox. All rights reserved.
*
*/
#include "rbx/Debug.h"
void RBXCRASH()
{
RBX::Debugable::doCrash();
}
void RBXCRASH(const char* message)
{
RBX::Debugable::doCrash(message);
}
+336
View File
@@ -0,0 +1,336 @@
/**
@file RegistryUtil.cpp
@created 2006-04-06
@edited 2006-04-24
Copyright 2000-2006, Morgan McGuire.
All rights reserved.
*/
// This prevent inclusion of winsock.h in windows.h, which prevents windows redifinition errors
// Look at winsock2.h for details, winsock2.h is #included from boost.hpp & other places.
#ifdef _WIN32
#define _WINSOCKAPI_
#include "Util/RegistryUtil.h"
#undef min
#undef max
#include "Rbx/Debug.h"
// declare HKEY constants as needed for VC6
#if !defined(HKEY_PERFORMANCE_DATA)
#define HKEY_PERFORMANCE_DATA (( HKEY ) ((LONG)0x80000004) )
#endif
#if !defined(HKEY_PERFORMANCE_TEXT)
#define HKEY_PERFORMANCE_TEXT (( HKEY ) ((LONG)0x80000050) )
#endif
#if !defined(HKEY_PERFORMANCE_NLSTEXT)
#define HKEY_PERFORMANCE_NLSTEXT (( HKEY ) ((LONG)0x80000060) )
#endif
namespace RBX {
// static helpers
static HKEY getKeyFromString(const char* str, size_t length);
bool RegistryUtil::keyExists(const std::string& key) {
size_t pos = key.find('\\', 0);
if ( pos == std::string::npos ) {
return false;
}
HKEY hkey = getKeyFromString(key.c_str(), pos);
if ( hkey == NULL ) {
return false;
}
RBXASSERT(key.size() > (pos + 1));
HKEY openKey;
INT32 result = RegOpenKeyEx(hkey, (key.c_str() + pos + 1), 0, KEY_READ, &openKey);
if ( result == ERROR_SUCCESS ) {
RegCloseKey(openKey);
return true;
} else {
return false;
}
}
bool RegistryUtil::read32bitNumber(const std::string& key, INT32& valueData) {
size_t pos = key.find('\\', 0);
if ( pos == std::string::npos ) {
return false;
}
HKEY hkey = getKeyFromString(key.c_str(), pos);
if ( hkey == NULL ) {
return false;
}
RBXASSERT(key.size() > (pos + 1));
size_t valuePos = key.rfind('\\');
if ( valuePos != std::string::npos ) {
std::string subKey = key.substr(pos + 1, valuePos - pos - 1);
std::string value = key.substr(valuePos + 1, key.size() - valuePos);
HKEY openKey;
INT32 result = RegOpenKeyEx(hkey, subKey.c_str(), 0, KEY_READ, &openKey);
if ( result == ERROR_SUCCESS ) {
UINT32 dataSize = sizeof(INT32);
result = RegQueryValueEx(openKey, value.c_str(), NULL, NULL, reinterpret_cast<LPBYTE>(&valueData), reinterpret_cast<LPDWORD>(&dataSize));
RBXASSERT(result == ERROR_SUCCESS && "Could not read registry key value.");
RegCloseKey(openKey);
return (result == ERROR_SUCCESS);
}
}
return false;
}
bool RegistryUtil::readBinaryData(const std::string& key, BYTE* valueData, UINT32& dataSize) {
size_t pos = key.find('\\', 0);
if ( pos == std::string::npos ) {
return false;
}
HKEY hkey = getKeyFromString(key.c_str(), pos);
if ( hkey == NULL ) {
return false;
}
RBXASSERT(key.size() > (pos + 1));
size_t valuePos = key.rfind('\\');
if ( valuePos != std::string::npos ) {
std::string subKey = key.substr(pos + 1, valuePos - pos - 1);
std::string value = key.substr(valuePos + 1, key.size() - valuePos);
HKEY openKey;
INT32 result = RegOpenKeyEx(hkey, subKey.c_str(), 0, KEY_READ, &openKey);
if ( result == ERROR_SUCCESS ) {
if ( valueData == NULL ) {
result = RegQueryValueEx(openKey, value.c_str(), NULL, NULL, NULL, reinterpret_cast<LPDWORD>(&dataSize));
} else {
result = RegQueryValueEx(openKey, value.c_str(), NULL, NULL, valueData, reinterpret_cast<LPDWORD>(&dataSize));
}
RBXASSERT(result == ERROR_SUCCESS && "Could not read registry key value.");
RegCloseKey(openKey);
return (result == ERROR_SUCCESS);
}
}
return false;
}
bool RegistryUtil::readString(const std::string& key, std::string& valueData) {
size_t pos = key.find('\\', 0);
if ( pos == std::string::npos ) {
return false;
}
HKEY hkey = getKeyFromString(key.c_str(), pos);
if ( hkey == NULL ) {
return false;
}
RBXASSERT(key.size() > (pos + 1));
size_t valuePos = key.rfind('\\');
if ( valuePos != std::string::npos ) {
std::string subKey = key.substr(pos + 1, valuePos - pos - 1);
std::string value = key.substr(valuePos + 1, key.size() - valuePos);
HKEY openKey;
INT32 result = RegOpenKeyEx(hkey, subKey.c_str(), 0, KEY_READ, &openKey);
if ( result == ERROR_SUCCESS ) {
UINT32 dataSize = 0;
result = RegQueryValueEx(openKey, value.c_str(), NULL, NULL, NULL, reinterpret_cast<LPDWORD>(&dataSize));
if ( result == ERROR_SUCCESS ) {
char* tmpStr = new char[dataSize];
memset(tmpStr, 0, dataSize);
result = RegQueryValueEx(openKey, value.c_str(), NULL, NULL, reinterpret_cast<LPBYTE>(tmpStr), reinterpret_cast<LPDWORD>(&dataSize));
if ( result == ERROR_SUCCESS ) {
valueData = tmpStr;
}
delete[] tmpStr;
}
//RBXASSERT(result == ERROR_SUCCESS && "Could not read registry key value.");
RegCloseKey(openKey);
return (result == ERROR_SUCCESS);
}
}
return false;
}
bool RegistryUtil::write32bitNumber(const std::string& key, INT32 valueData) {
size_t pos = key.find('\\', 0);
if ( pos == std::string::npos ) {
return false;
}
HKEY hkey = getKeyFromString(key.c_str(), pos);
if ( hkey == NULL ) {
return false;
}
RBXASSERT(key.size() > (pos + 1));
size_t valuePos = key.rfind('\\');
if ( valuePos != std::string::npos ) {
std::string subKey = key.substr(pos + 1, valuePos - pos - 1);
std::string value = key.substr(valuePos + 1, key.size() - valuePos);
HKEY openKey;
INT32 result = RegOpenKeyEx(hkey, subKey.c_str(), 0, KEY_ALL_ACCESS, &openKey);
if ( result == ERROR_SUCCESS ) {
result = RegSetValueEx(openKey, value.c_str(), NULL, REG_DWORD, reinterpret_cast<const BYTE*>(&valueData), sizeof(INT32));
RBXASSERT(result == ERROR_SUCCESS && "Could not write registry key value.");
RegCloseKey(openKey);
return (result == ERROR_SUCCESS);
}
}
return false;
}
bool RegistryUtil::writeBinaryData(const std::string& key, const BYTE* valueData, UINT32 dataSize) {
RBXASSERT(valueData);
size_t pos = key.find('\\', 0);
if ( pos == std::string::npos ) {
return false;
}
HKEY hkey = getKeyFromString(key.c_str(), pos);
if ( hkey == NULL ) {
return false;
}
RBXASSERT(key.size() > (pos + 1));
size_t valuePos = key.rfind('\\');
if ( valuePos != std::string::npos ) {
std::string subKey = key.substr(pos + 1, valuePos - pos - 1);
std::string value = key.substr(valuePos + 1, key.size() - valuePos);
HKEY openKey;
INT32 result = RegOpenKeyEx(hkey, subKey.c_str(), 0, KEY_ALL_ACCESS, &openKey);
if ( result == ERROR_SUCCESS ) {
if (valueData) {
result = RegSetValueEx(openKey, value.c_str(), NULL, REG_BINARY, reinterpret_cast<const BYTE*>(valueData), dataSize);
}
RBXASSERT(result == ERROR_SUCCESS && "Could not write registry key value.");
RegCloseKey(openKey);
return (result == ERROR_SUCCESS);
}
}
return false;
}
bool RegistryUtil::writeString(const std::string& key, const std::string& valueData) {
size_t pos = key.find('\\', 0);
if ( pos == std::string::npos ) {
return false;
}
HKEY hkey = getKeyFromString(key.c_str(), pos);
if ( hkey == NULL ) {
return false;
}
RBXASSERT(key.size() > (pos + 1));
size_t valuePos = key.rfind('\\');
if ( valuePos != std::string::npos ) {
std::string subKey = key.substr(pos + 1, valuePos - pos - 1);
std::string value = key.substr(valuePos + 1, key.size() - valuePos);
HKEY openKey;
INT32 result = RegOpenKeyEx(hkey, subKey.c_str(), 0, KEY_ALL_ACCESS, &openKey);
if ( result == ERROR_SUCCESS ) {
result = RegSetValueEx(openKey, value.c_str(), NULL, REG_SZ, reinterpret_cast<const BYTE*>(valueData.c_str()), (valueData.size() + 1));
RBXASSERT(result == ERROR_SUCCESS && "Could not write registry key value.");
RegCloseKey(openKey);
return (result == ERROR_SUCCESS);
}
}
return false;
}
// static helpers
static HKEY getKeyFromString(const char* str, UINT32 length) {
RBXASSERT(str);
if (str) {
if ( strncmp(str, "HKEY_CLASSES_ROOT", length) == 0 ) {
return HKEY_CLASSES_ROOT;
} else if ( strncmp(str, "HKEY_CURRENT_CONFIG", length) == 0 ) {
return HKEY_CURRENT_CONFIG;
} else if ( strncmp(str, "HKEY_CURRENT_USER", length) == 0 ) {
return HKEY_CURRENT_USER;
} else if ( strncmp(str, "HKEY_LOCAL_MACHINE", length) == 0 ) {
return HKEY_LOCAL_MACHINE;
} else if ( strncmp(str, "HKEY_PERFORMANCE_DATA", length) == 0 ) {
return HKEY_PERFORMANCE_DATA;
} else if ( strncmp(str, "HKEY_PERFORMANCE_NLSTEXT", length) == 0 ) {
return HKEY_PERFORMANCE_NLSTEXT;
} else if ( strncmp(str, "HKEY_PERFORMANCE_TEXT", length) == 0 ) {
return HKEY_PERFORMANCE_TEXT;
} else if ( strncmp(str, "HKEY_CLASSES_ROOT", length) == 0 ) {
return HKEY_CLASSES_ROOT;
} else {
return NULL;
}
} else {
return NULL;
}
}
} // namespace G3D
#endif
+15
View File
@@ -0,0 +1,15 @@
#include "util/StreamHelpers.h"
namespace RBX
{
void readStreamIntoString(std::istream &stream, std::string& content)
{
size_t contentLength = 0;
stream.seekg(0, std::ios::end);
contentLength = static_cast<size_t>(stream.tellg());
stream.seekg(0, std::ios::beg);
content = std::string(contentLength, '\0');
stream.read(&content[0], contentLength);
}
} // RBX