mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
C client: Change %x to only print 32 bits of hex on 32 bit systems
This commit is contained in:
parent
124d87e227
commit
a57d261703
@ -87,5 +87,5 @@ void String_Format4(str, format, a1, a2, a3, a4);
|
|||||||
| ```%c``` | char* | ```%c``` of ```"ABCD"``` = ```ABCD``` |
|
| ```%c``` | char* | ```%c``` of ```"ABCD"``` = ```ABCD``` |
|
||||||
| ```%s``` | String | ```%s``` of ```{"ABCD", 2, 4}``` = ```AB``` |
|
| ```%s``` | String | ```%s``` of ```{"ABCD", 2, 4}``` = ```AB``` |
|
||||||
| ```%r``` | char, raw | ```%r``` of ```47``` = ```\``` |
|
| ```%r``` | char, raw | ```%r``` of ```47``` = ```\``` |
|
||||||
| ```%x``` | UInt64, hex | ```%x``` of ```31``` = ```2F``` |
|
| ```%x``` | UIntPtr, hex | ```%x``` of ```31``` = ```2F``` |
|
||||||
| ```%y``` | UInt32, hex | ```%y``` of ```11``` = ```B``` |
|
| ```%h``` | UInt32, hex | ```%h``` of ```11``` = ```B``` |
|
||||||
|
@ -205,7 +205,7 @@ static void AsyncDownloader_ProcessRequest(struct AsyncRequest* request) {
|
|||||||
|
|
||||||
if (request->ResultData) {
|
if (request->ResultData) {
|
||||||
UInt32 size = request->ResultSize;
|
UInt32 size = request->ResultSize;
|
||||||
UInt64 addr = (UInt64)request->ResultData;
|
UIntPtr addr = (UIntPtr)request->ResultData;
|
||||||
Platform_Log2("HTTP returned data: %i bytes at %x", &size, &addr);
|
Platform_Log2("HTTP returned data: %i bytes at %x", &size, &addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,10 +142,10 @@ static void Chat_AppendLog(const String* text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Chat_LogError(ReturnCode result, const char* place) {
|
void Chat_LogError(ReturnCode result, const char* place) {
|
||||||
Chat_Add4("&cError %y when %c", &result, place, NULL, NULL);
|
Chat_Add4("&cError %h when %c", &result, place, NULL, NULL);
|
||||||
}
|
}
|
||||||
void Chat_LogError2(ReturnCode result, const char* place, const String* path) {
|
void Chat_LogError2(ReturnCode result, const char* place, const String* path) {
|
||||||
Chat_Add4("&cError %y when %c '%s'", &result, place, path, NULL);
|
Chat_Add4("&cError %h when %c '%s'", &result, place, path, NULL);
|
||||||
}
|
}
|
||||||
void Chat_Add1(const char* format, const void* a1) {
|
void Chat_Add1(const char* format, const void* a1) {
|
||||||
Chat_Add4(format, a1, NULL, NULL, NULL);
|
Chat_Add4(format, a1, NULL, NULL, NULL);
|
||||||
|
@ -9,6 +9,11 @@ typedef unsigned __int8 UInt8;
|
|||||||
typedef unsigned __int16 UInt16;
|
typedef unsigned __int16 UInt16;
|
||||||
typedef unsigned __int32 UInt32;
|
typedef unsigned __int32 UInt32;
|
||||||
typedef unsigned __int64 UInt64;
|
typedef unsigned __int64 UInt64;
|
||||||
|
#ifdef _WIN64
|
||||||
|
typedef unsigned __int64 UIntPtr;
|
||||||
|
#else
|
||||||
|
typedef unsigned int UIntPtr;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef signed __int8 Int8;
|
typedef signed __int8 Int8;
|
||||||
typedef signed __int16 Int16;
|
typedef signed __int16 Int16;
|
||||||
@ -21,6 +26,7 @@ typedef uint8_t UInt8;
|
|||||||
typedef uint16_t UInt16;
|
typedef uint16_t UInt16;
|
||||||
typedef uint32_t UInt32;
|
typedef uint32_t UInt32;
|
||||||
typedef uint64_t UInt64;
|
typedef uint64_t UInt64;
|
||||||
|
typedef uintptr_t UIntPtr;
|
||||||
|
|
||||||
typedef int8_t Int8;
|
typedef int8_t Int8;
|
||||||
typedef int16_t Int16;
|
typedef int16_t Int16;
|
||||||
|
@ -53,7 +53,7 @@ static void D3D9_FreeResource(GfxResourceID* resource) {
|
|||||||
*resource = NULL;
|
*resource = NULL;
|
||||||
if (refCount <= 0) return;
|
if (refCount <= 0) return;
|
||||||
|
|
||||||
UInt64 addr = (UInt64)(unk);
|
UIntPtr addr = (UIntPtr)unk;
|
||||||
Platform_Log2("D3D9 resource has %i outstanding references! ID 0x%x", &refCount, &addr);
|
Platform_Log2("D3D9 resource has %i outstanding references! ID 0x%x", &refCount, &addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ void Entity_SetModel(struct Entity* e, const String* model) {
|
|||||||
name = String_FromReadonly("humanoid");
|
name = String_FromReadonly("humanoid");
|
||||||
e->ModelScale = Vector3_Create1(2.0f);
|
e->ModelScale = Vector3_Create1(2.0f);
|
||||||
}
|
}
|
||||||
e->ModelIsSheepNoFur = String_CaselessEqualsConst(&name, "sheep_nofur");
|
e->_ModelIsSheepNoFur = String_CaselessEqualsConst(&name, "sheep_nofur");
|
||||||
|
|
||||||
e->ModelBlock = BLOCK_AIR;
|
e->ModelBlock = BLOCK_AIR;
|
||||||
e->Model = ModelCache_Get(&name);
|
e->Model = ModelCache_Get(&name);
|
||||||
|
@ -74,7 +74,7 @@ struct Entity {
|
|||||||
|
|
||||||
struct Model* Model;
|
struct Model* Model;
|
||||||
BlockID ModelBlock; /* BlockID, if model name was originally a vaid block id. */
|
BlockID ModelBlock; /* BlockID, if model name was originally a vaid block id. */
|
||||||
bool ModelIsSheepNoFur; /* Hacky, but only sheep model relies on model name. So use just 1 byte. */
|
bool _ModelIsSheepNoFur; /* Hacky, but only sheep model relies on model name. So use just 1 byte. */
|
||||||
struct AABB ModelAABB;
|
struct AABB ModelAABB;
|
||||||
Vector3 ModelScale, Size;
|
Vector3 ModelScale, Size;
|
||||||
float StepSize;
|
float StepSize;
|
||||||
|
@ -16,7 +16,7 @@ static void ErrorHandler_DumpCommon(String* str, void* ctx);
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <imagehlp.h>
|
#include <imagehlp.h>
|
||||||
|
|
||||||
struct StackPointers { UInt64 Instruction, Frame, Stack; };
|
struct StackPointers { UIntPtr Instruction, Frame, Stack; };
|
||||||
struct SymbolAndName { IMAGEHLP_SYMBOL Symbol; char Name[256]; };
|
struct SymbolAndName { IMAGEHLP_SYMBOL Symbol; char Name[256]; };
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ static Int32 ErrorHandler_GetFrames(CONTEXT* ctx, struct StackPointers* pointers
|
|||||||
static BOOL CALLBACK ErrorHandler_DumpModule(const char* name, ULONG_PTR base, ULONG size, void* ctx) {
|
static BOOL CALLBACK ErrorHandler_DumpModule(const char* name, ULONG_PTR base, ULONG size, void* ctx) {
|
||||||
char buffer[STRING_SIZE * 4];
|
char buffer[STRING_SIZE * 4];
|
||||||
String str = String_FromArray(buffer);
|
String str = String_FromArray(buffer);
|
||||||
DWORD64 start = base, end = base + (size - 1);
|
UIntPtr start = base, end = base + (size - 1);
|
||||||
|
|
||||||
String_Format3(&str, "%c = %x-%x\r\n", name, &start, &end);
|
String_Format3(&str, "%c = %x-%x\r\n", name, &start, &end);
|
||||||
ErrorHandler_Log(&str);
|
ErrorHandler_Log(&str);
|
||||||
@ -88,7 +88,7 @@ static void ErrorHandler_Backtrace(String* backtrace, void* ctx) {
|
|||||||
|
|
||||||
for (i = 0; i < frames; i++) {
|
for (i = 0; i < frames; i++) {
|
||||||
Int32 number = i + 1;
|
Int32 number = i + 1;
|
||||||
UInt64 addr = (UInt64)pointers[i].Instruction;
|
UIntPtr addr = pointers[i].Instruction;
|
||||||
|
|
||||||
char strBuffer[STRING_SIZE * 10];
|
char strBuffer[STRING_SIZE * 10];
|
||||||
String str = String_FromArray(strBuffer);
|
String str = String_FromArray(strBuffer);
|
||||||
@ -141,9 +141,9 @@ static void ErrorHandler_DumpRegisters(CONTEXT* ctx) {
|
|||||||
String_AppendConst(&str, "-- registers --\r\n");
|
String_AppendConst(&str, "-- registers --\r\n");
|
||||||
|
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
String_Format3(&str, "eax=%y ebx=%y ecx=%y\r\n", &ctx->Eax, &ctx->Ebx, &ctx->Ecx);
|
String_Format3(&str, "eax=%x ebx=%x ecx=%x\r\n", &ctx->Eax, &ctx->Ebx, &ctx->Ecx);
|
||||||
String_Format3(&str, "edx=%y esi=%y edi=%y\r\n", &ctx->Edx, &ctx->Esi, &ctx->Edi);
|
String_Format3(&str, "edx=%x esi=%x edi=%x\r\n", &ctx->Edx, &ctx->Esi, &ctx->Edi);
|
||||||
String_Format3(&str, "eip=%y ebp=%y esp=%y\r\n", &ctx->Eip, &ctx->Ebp, &ctx->Esp);
|
String_Format3(&str, "eip=%x ebp=%x esp=%x\r\n", &ctx->Eip, &ctx->Ebp, &ctx->Esp);
|
||||||
#elif _M_X64
|
#elif _M_X64
|
||||||
String_Format3(&str, "rax=%x rbx=%x rcx=%x\r\n", &ctx->Rax, &ctx->Rbx, &ctx->Rcx);
|
String_Format3(&str, "rax=%x rbx=%x rcx=%x\r\n", &ctx->Rax, &ctx->Rbx, &ctx->Rcx);
|
||||||
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\r\n", &ctx->Rdx, &ctx->Rsi, &ctx->Rdi);
|
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\r\n", &ctx->Rdx, &ctx->Rsi, &ctx->Rdi);
|
||||||
@ -177,9 +177,9 @@ static LONG WINAPI ErrorHandler_UnhandledFilter(struct _EXCEPTION_POINTERS* pInf
|
|||||||
char msgBuffer[STRING_SIZE * 2 + 1];
|
char msgBuffer[STRING_SIZE * 2 + 1];
|
||||||
String msg = String_NT_Array(msgBuffer);
|
String msg = String_NT_Array(msgBuffer);
|
||||||
|
|
||||||
UInt32 code = (UInt32)pInfo->ExceptionRecord->ExceptionCode;
|
UInt32 code = (UInt32)pInfo->ExceptionRecord->ExceptionCode;
|
||||||
UInt64 addr = (UInt64)pInfo->ExceptionRecord->ExceptionAddress;
|
UIntPtr addr = (UIntPtr)pInfo->ExceptionRecord->ExceptionAddress;
|
||||||
String_Format2(&msg, "Unhandled exception 0x%y at 0x%x", &code, &addr);
|
String_Format2(&msg, "Unhandled exception 0x%h at 0x%x", &code, &addr);
|
||||||
msg.buffer[msg.length] = '\0';
|
msg.buffer[msg.length] = '\0';
|
||||||
|
|
||||||
ErrorHandler_DumpRegisters(pInfo->ContextRecord);
|
ErrorHandler_DumpRegisters(pInfo->ContextRecord);
|
||||||
@ -490,7 +490,7 @@ static void ErrorHandler_Backtrace(String* backtrace_, void* ctx) {
|
|||||||
|
|
||||||
for (i = 0; i < frames; i++) {
|
for (i = 0; i < frames; i++) {
|
||||||
Int32 number = i + 1;
|
Int32 number = i + 1;
|
||||||
UInt64 addr = (UInt64)addrs[i];
|
UIntPtr addr = (UIntPtr)addrs[i];
|
||||||
|
|
||||||
char strBuffer[STRING_SIZE * 5];
|
char strBuffer[STRING_SIZE * 5];
|
||||||
String str = String_FromArray(strBuffer);
|
String str = String_FromArray(strBuffer);
|
||||||
@ -520,9 +520,9 @@ static void ErrorHandler_DumpRegisters(void* ctx) {
|
|||||||
|
|
||||||
/* TODO: There must be a better way of getting these.. */
|
/* TODO: There must be a better way of getting these.. */
|
||||||
#ifdef __i386__
|
#ifdef __i386__
|
||||||
String_Format3(&str, "eax=%y ebx=%y ecx=%y\n", &r.gregs[11], &r.gregs[8], &r.gregs[10]);
|
String_Format3(&str, "eax=%x ebx=%x ecx=%x\n", &r.gregs[11], &r.gregs[8], &r.gregs[10]);
|
||||||
String_Format3(&str, "edx=%y esi=%y edi=%y\n", &r.gregs[9], &r.gregs[5], &r.gregs[4]);
|
String_Format3(&str, "edx=%x esi=%x edi=%x\n", &r.gregs[9], &r.gregs[5], &r.gregs[4]);
|
||||||
String_Format3(&str, "eip=%y ebp=%y esp=%y\n", &r.gregs[14], &r.gregs[6], &r.gregs[7]);
|
String_Format3(&str, "eip=%x ebp=%x esp=%x\n", &r.gregs[14], &r.gregs[6], &r.gregs[7]);
|
||||||
#elif __x86_64__
|
#elif __x86_64__
|
||||||
String_Format3(&str, "rax=%x rbx=%x rcx=%x\n", &r.gregs[13], &r.gregs[11], &r.gregs[14]);
|
String_Format3(&str, "rax=%x rbx=%x rcx=%x\n", &r.gregs[13], &r.gregs[11], &r.gregs[14]);
|
||||||
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\n", &r.gregs[12], &r.gregs[9], &r.gregs[8]);
|
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\n", &r.gregs[12], &r.gregs[9], &r.gregs[8]);
|
||||||
@ -576,8 +576,8 @@ static void ErrorHandler_SignalHandler(int sig, siginfo_t* info, void* ctx) {
|
|||||||
char msgBuffer[STRING_SIZE * 2 + 1];
|
char msgBuffer[STRING_SIZE * 2 + 1];
|
||||||
String msg = String_NT_Array(msgBuffer);
|
String msg = String_NT_Array(msgBuffer);
|
||||||
|
|
||||||
Int32 type = info->si_signo, code = info->si_code;
|
Int32 type = info->si_signo, code = info->si_code;
|
||||||
UInt64 addr = (UInt64)info->si_addr;
|
UIntPtr addr = (UIntPtr)info->si_addr;
|
||||||
String_Format3(&msg, "Unhandled signal %i (code %i) at 0x%x", &type, &code, &addr);
|
String_Format3(&msg, "Unhandled signal %i (code %i) at 0x%x", &type, &code, &addr);
|
||||||
msg.buffer[msg.length] = '\0';
|
msg.buffer[msg.length] = '\0';
|
||||||
|
|
||||||
@ -638,9 +638,9 @@ static void ErrorHandler_FailCommon(ReturnCode result, const char* raw_msg, void
|
|||||||
char msgBuffer[3070 + 1];
|
char msgBuffer[3070 + 1];
|
||||||
String msg = String_NT_Array(msgBuffer);
|
String msg = String_NT_Array(msgBuffer);
|
||||||
|
|
||||||
String_Format3(&msg, "ClassiCube crashed.%cMessge: %c%c", Platform_NewLine, raw_msg, Platform_NewLine);
|
String_Format3(&msg, "ClassiCube crashed.%cMessage: %c%c", Platform_NewLine, raw_msg, Platform_NewLine);
|
||||||
if (result) {
|
if (result) {
|
||||||
String_Format2(&msg, "%y%c", &result, Platform_NewLine);
|
String_Format2(&msg, "%h%c", &result, Platform_NewLine);
|
||||||
} else { result = 1; }
|
} else { result = 1; }
|
||||||
|
|
||||||
ErrorHandler_Log(&msg);
|
ErrorHandler_Log(&msg);
|
||||||
|
@ -35,7 +35,8 @@ static void HeldBlockRenderer_RenderModel(void) {
|
|||||||
Model_RenderArm(model, &held_entity);
|
Model_RenderArm(model, &held_entity);
|
||||||
Gfx_SetAlphaTest(false);
|
Gfx_SetAlphaTest(false);
|
||||||
} else {
|
} else {
|
||||||
String name = String_FromConst("block"); model = ModelCache_Get(&name);
|
String block = String_FromConst("block");
|
||||||
|
model = ModelCache_Get(&block);
|
||||||
held_entity.ModelScale = Vector3_Create1(0.4f);
|
held_entity.ModelScale = Vector3_Create1(0.4f);
|
||||||
|
|
||||||
GfxCommon_SetupAlphaState(Block_Draw[held_block]);
|
GfxCommon_SetupAlphaState(Block_Draw[held_block]);
|
||||||
|
@ -454,7 +454,7 @@ static void SheepModel_DrawModel(struct Entity* entity) {
|
|||||||
Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &Sheep_RightLegBack, false);
|
Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &Sheep_RightLegBack, false);
|
||||||
Model_UpdateVB();
|
Model_UpdateVB();
|
||||||
|
|
||||||
if (entity->ModelIsSheepNoFur) return;
|
if (entity->_ModelIsSheepNoFur) return;
|
||||||
Gfx_BindTexture(ModelCache_Textures[fur_Index].TexID);
|
Gfx_BindTexture(ModelCache_Textures[fur_Index].TexID);
|
||||||
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &Fur_Head, true);
|
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &Fur_Head, true);
|
||||||
|
|
||||||
|
@ -192,8 +192,8 @@ void Window_Create(Int32 x, Int32 y, Int32 width, Int32 height, const String* ti
|
|||||||
win_rootWin = DisplayDevice_Meta[2];
|
win_rootWin = DisplayDevice_Meta[2];
|
||||||
|
|
||||||
/* Open a display connection to the X server, and obtain the screen and root window */
|
/* Open a display connection to the X server, and obtain the screen and root window */
|
||||||
UInt64 addr = (UInt64)win_display;
|
UIntPtr addr = (UIntPtr)win_display;
|
||||||
Platform_Log3("Display: %y, Screen %i, Root window: %y", &addr, &win_screen, &win_rootWin);
|
Platform_Log3("Display: %x, Screen %i, Root window: %h", &addr, &win_screen, &win_rootWin);
|
||||||
|
|
||||||
Window_RegisterAtoms();
|
Window_RegisterAtoms();
|
||||||
win_visual = GLContext_SelectVisual(mode);
|
win_visual = GLContext_SelectVisual(mode);
|
||||||
|
@ -10,7 +10,7 @@ struct AsyncRequest;
|
|||||||
|
|
||||||
enum SOCKET_SELECT { SOCKET_SELECT_READ, SOCKET_SELECT_WRITE };
|
enum SOCKET_SELECT { SOCKET_SELECT_READ, SOCKET_SELECT_WRITE };
|
||||||
#if CC_BUILD_WIN
|
#if CC_BUILD_WIN
|
||||||
typedef void* SocketPtr;
|
typedef UIntPtr SocketPtr;
|
||||||
#else
|
#else
|
||||||
typedef Int32 SocketPtr;
|
typedef Int32 SocketPtr;
|
||||||
#endif
|
#endif
|
||||||
|
12
src/String.c
12
src/String.c
@ -226,7 +226,7 @@ bool String_AppendReal32(String* str, float num, Int32 fracDigits) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String_Hex32(String* str, UInt32 value) {
|
NOINLINE_ static bool String_Hex32(String* str, UInt32 value) {
|
||||||
char hex[9]; hex[8] = '\0';
|
char hex[9]; hex[8] = '\0';
|
||||||
Int32 i;
|
Int32 i;
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ bool String_Hex32(String* str, UInt32 value) {
|
|||||||
return String_AppendConst(str, hex);
|
return String_AppendConst(str, hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String_Hex64(String* str, UInt64 value) {
|
NOINLINE_ static bool String_Hex64(String* str, UInt64 value) {
|
||||||
char hex[17]; hex[16] = '\0';
|
char hex[17]; hex[16] = '\0';
|
||||||
Int32 i;
|
Int32 i;
|
||||||
|
|
||||||
@ -450,8 +450,12 @@ void String_Format4(String* str, const char* format, const void* a1, const void*
|
|||||||
case 'r':
|
case 'r':
|
||||||
String_Append(str, *((char*)arg)); break;
|
String_Append(str, *((char*)arg)); break;
|
||||||
case 'x':
|
case 'x':
|
||||||
String_Hex64(str, *((UInt64*)arg)); break;
|
if (sizeof(UIntPtr) == 4) {
|
||||||
case 'y':
|
String_Hex32(str, *((UInt32*)arg)); break;
|
||||||
|
} else {
|
||||||
|
String_Hex64(str, *((UInt64*)arg)); break;
|
||||||
|
}
|
||||||
|
case 'h':
|
||||||
String_Hex32(str, *((UInt32*)arg)); break;
|
String_Hex32(str, *((UInt32*)arg)); break;
|
||||||
default:
|
default:
|
||||||
ErrorHandler_Fail("Invalid type for string format");
|
ErrorHandler_Fail("Invalid type for string format");
|
||||||
|
@ -58,8 +58,6 @@ NOINLINE_ bool String_AppendInt32(String* str, Int32 num);
|
|||||||
NOINLINE_ bool String_AppendUInt32(String* str, UInt32 num);
|
NOINLINE_ bool String_AppendUInt32(String* str, UInt32 num);
|
||||||
NOINLINE_ bool String_AppendUInt64(String* str, UInt64 num);
|
NOINLINE_ bool String_AppendUInt64(String* str, UInt64 num);
|
||||||
NOINLINE_ bool String_AppendReal32(String* str, float num, Int32 fracDigits); /* TODO: Need to account for , or . for decimal */
|
NOINLINE_ bool String_AppendReal32(String* str, float num, Int32 fracDigits); /* TODO: Need to account for , or . for decimal */
|
||||||
NOINLINE_ bool String_Hex32(String* str, UInt32 value);
|
|
||||||
NOINLINE_ bool String_Hex64(String* str, UInt64 value);
|
|
||||||
NOINLINE_ bool String_AppendConst(String* str, const char* src);
|
NOINLINE_ bool String_AppendConst(String* str, const char* src);
|
||||||
NOINLINE_ bool String_AppendString(String* str, const String* src);
|
NOINLINE_ bool String_AppendString(String* str, const String* src);
|
||||||
NOINLINE_ bool String_AppendColorless(String* str, const String* src);
|
NOINLINE_ bool String_AppendColorless(String* str, const String* src);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user