Maintenance: Define every global once in its owner unit; session members replace member globals

Batch #906 by ragnarok-clanker: no function's compiled code changes; checked with 9 compiled unit(s), including every includer of Source/Client/Session.h, Source/Client/Registry.h, Source/Client/Application/LaunchInfo.h, Source/Client/Application/Launcher.h, Source/Client/Mode/ActiveGameMode.h, Source/Render/DeviceSelection.h.
Adds to the build: Source/Client/Session.cpp, Source/Client/Registry.cpp, Source/Client/Application/LaunchInfo.cpp, Source/Render/DeviceSelection.cpp
This commit is contained in:
ragnarok-clanker 2026-10-26 18:34:25 +00:00
commit f575258340
16 changed files with 126 additions and 68 deletions

View file

@ -0,0 +1,5 @@
#include "Client/Application/LaunchInfo.h"
// STATIC: 0x0171dd30
// GLOBAL: gl_24473
std::uint32_t g_launchInfo[32];

View file

@ -0,0 +1,8 @@
#ifndef RAGNAROK_SOURCE_CLIENT_APPLICATION_LAUNCHINFO_H
#define RAGNAROK_SOURCE_CLIENT_APPLICATION_LAUNCHINFO_H
#include <cstdint>
extern std::uint32_t g_launchInfo[32];
#endif

View file

@ -1,8 +1,13 @@
#include "Client/Application/Launcher.h"
#include <cstdint>
#include <cstring>
#include <windows.h>
// STATIC: 0x0173ad64
// GLOBAL: gl_24472
std::uint32_t g_clientVersion;
// OFFSET: 0x00E58820
// FUNCTION: fn_24363
bool RestartFromCommandLine(char* commandLine) {

View file

@ -1,8 +1,11 @@
#ifndef RAGNAROK_SOURCE_CLIENT_APPLICATION_LAUNCHER_H
#define RAGNAROK_SOURCE_CLIENT_APPLICATION_LAUNCHER_H
#include <cstdint>
#include <windows.h>
extern std::uint32_t g_clientVersion;
bool RestartFromCommandLine(char* commandLine);
void ExitForProtectionCheck(const char* commandLine);

View file

@ -1,5 +1,8 @@
#include "Client/Application/LaunchInfo.h"
#include "Client/Application/Launcher.h"
#include "Client/Mode/ActiveGameMode.h"
#include "Client/Application/UnhandledExceptionHandler.h"
#include "Client/Session.h"
#include <windows.h>
#include <dbghelp.h>
@ -29,46 +32,14 @@ char g_moduleBaseName[260] = {};
// GLOBAL: gl_24360
char g_crashString[8096] = {};
// STATIC: 0x0173ad64
// GLOBAL: gl_24472
extern uint32_t g_clientVersion;
// STATIC: 0x0171dd30
// GLOBAL: gl_24473
extern uint32_t g_launchInfo[32];
// STATIC: 0x01733550
// GLOBAL: gl_24476
extern int g_playerX;
// STATIC: 0x01733554
// GLOBAL: gl_24477
extern int g_playerY;
// STATIC: 0x0173a770
// GLOBAL: gl_24478
extern int64_t g_startTimeTicks;
// STATIC: 0x0173a778
// GLOBAL: gl_24479
extern int64_t g_loginTimeTicks;
// STATIC: 0x01732638
// GLOBAL: gl_24474
extern const uint8_t g_session[];
namespace {
int ReadPlayerJob() {
int job;
std::memcpy(&job, g_session + 0x1628, sizeof(job));
return job;
return g_session.m_job;
}
const char* ReadPlayerJobName(int jobId) {
const char* const* namesBegin;
const char* const* namesEnd;
std::memcpy(&namesBegin, g_session + 0xFA8, sizeof(namesBegin));
std::memcpy(&namesEnd, g_session + 0xFAC, sizeof(namesEnd));
const char* const* namesBegin = g_session.m_jobNamesBegin;
const char* const* namesEnd = g_session.m_jobNamesEnd;
if (!namesBegin || !namesEnd || namesBegin >= namesEnd) {
return "";
@ -358,10 +329,10 @@ LONG WINAPI TopLevelExceptionFilter(EXCEPTION_POINTERS* exceptionInfo) {
const char* mapName = ReadCurrentMapName();
if (mapName != nullptr) {
sprintf(&g_crashString[strlen(g_crashString)], "%s %d %d\r\n", mapName, g_playerX, g_playerY);
sprintf(&g_crashString[strlen(g_crashString)], "%s %d %d\r\n", mapName, g_session.m_playerX, g_session.m_playerY);
}
sprintf(&g_crashString[strlen(g_crashString)], "\r\n%I64d - %I64d", g_startTimeTicks / 10000000LL, g_loginTimeTicks / 10000000LL);
sprintf(&g_crashString[strlen(g_crashString)], "\r\n%I64d - %I64d", g_session.m_startTimeTicks / 10000000LL, g_session.m_loginTimeTicks / 10000000LL);
int64_t reportTime = _Xtime_get_ticks() / 10000000LL;
PROCESS_MEMORY_COUNTERS memCounters = {};

View file

@ -1,5 +1,9 @@
#include "Client/Mode/ActiveGameMode.h"
// STATIC: 0x013495b8
// GLOBAL: gl_24475
CWorld g_world = {1};
// FUNCTION: fn_17831
CGameMode* CWorld::ActiveGameMode() {
return this->state == 1 ? this->gameMode : nullptr;

View file

@ -4,16 +4,14 @@
class CGameMode;
struct CWorld {
unsigned char unknown_0000[4];
CGameMode* gameMode;
unsigned char unknown_0008[0x50];
int state;
/* 0000 */ int running;
/* 0004 */ CGameMode* gameMode;
/* 0008 */ unsigned char unknown_0008[0x50];
/* 0058 */ int state;
CGameMode* ActiveGameMode();
};
// STATIC: 0x013495b8
// GLOBAL: gl_24475
extern CWorld g_world;
#endif

View file

@ -0,0 +1,5 @@
#include "Client/Registry.h"
// STATIC: 0x01348F80
// GLOBAL: gl_21922
const char* g_subKey;

6
Source/Client/Registry.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef RAGNAROK_SOURCE_CLIENT_REGISTRY_H
#define RAGNAROK_SOURCE_CLIENT_REGISTRY_H
extern const char* g_subKey;
#endif

View file

@ -0,0 +1,5 @@
#include "Client/Session.h"
// STATIC: 0x01732638
// GLOBAL: gl_24474
CSession g_session;

40
Source/Client/Session.h Normal file
View file

@ -0,0 +1,40 @@
#ifndef RAGNAROK_SOURCE_CLIENT_SESSION_H
#define RAGNAROK_SOURCE_CLIENT_SESSION_H
#include <cstddef>
#include <cstdint>
class LuaScript;
class CSession {
public:
/* 0000 */ unsigned char unknown_0000[0xF18];
/* 0F18 */ int m_playerX;
/* 0F1C */ int m_playerY;
/* 0F20 */ unsigned char unknown_0F20[0x88];
/* 0FA8 */ const char* const* m_jobNamesBegin;
/* 0FAC */ const char* const* m_jobNamesEnd;
/* 0FB0 */ unsigned char unknown_0FB0[0x678];
/* 1628 */ int m_job;
/* 162C */ unsigned char unknown_162C[0x43AC];
/* 59D8 */ LuaScript* m_hotkeyScript;
/* 59DC */ unsigned char unknown_59DC[0x275C];
/* 8138 */ std::int64_t m_startTimeTicks;
/* 8140 */ std::int64_t m_loginTimeTicks;
/* 8148 */ int unknown_8148;
};
extern CSession g_session;
#if defined(_WIN32) && !defined(_WIN64)
static_assert(offsetof(CSession, m_playerX) == 0xF18);
static_assert(offsetof(CSession, m_playerY) == 0xF1C);
static_assert(offsetof(CSession, m_jobNamesBegin) == 0xFA8);
static_assert(offsetof(CSession, m_jobNamesEnd) == 0xFAC);
static_assert(offsetof(CSession, m_job) == 0x1628);
static_assert(offsetof(CSession, m_hotkeyScript) == 0x59D8);
static_assert(offsetof(CSession, m_startTimeTicks) == 0x8138);
static_assert(offsetof(CSession, m_loginTimeTicks) == 0x8140);
#endif
#endif

View file

@ -1,18 +1,15 @@
#include "Client/Session.h"
#include "Contents/Hotkeys/UserHotkeyScript.h"
#include "Network/TextEncoding.h"
// STATIC: 0x01738010
// GLOBAL: gl_24495
extern LuaScript* g_hotkeyLuaScript;
// OFFSET: 0x005F7D60
// FUNCTION: fn_04055
void ClearUserHotkeys() {
std::string path = "SaveData\\UserKeys";
path += ".lua";
if (!path.empty()) {
if (g_hotkeyLuaScript != nullptr) {
g_hotkeyLuaScript->Call("ClearUserHotKeys", "s", path.c_str());
if (g_session.m_hotkeyScript != nullptr) {
g_session.m_hotkeyScript->Call("ClearUserHotKeys", "s", path.c_str());
}
}
}
@ -23,8 +20,8 @@ void SaveUserHotkeys() {
std::string path = "SaveData\\UserKeys";
path += ".lua";
if (!path.empty()) {
if (g_hotkeyLuaScript != nullptr) {
g_hotkeyLuaScript->Call("SaveUserHotKeys2", "s", path.c_str());
if (g_session.m_hotkeyScript != nullptr) {
g_session.m_hotkeyScript->Call("SaveUserHotKeys2", "s", path.c_str());
}
}
}
@ -32,7 +29,7 @@ void SaveUserHotkeys() {
// OFFSET: 0x005F8B20
// FUNCTION: fn_04064
void __stdcall ChangeUserHotkey(int tab, int index, int key1, int key2, const std::string& description) {
g_hotkeyLuaScript->Call("ChangeUserHotKey", "ddsdd", tab + 1, index, description.c_str(), key1, key2);
g_session.m_hotkeyScript->Call("ChangeUserHotKey", "ddsdd", tab + 1, index, description.c_str(), key1, key2);
}
// OFFSET: 0x005BD660

View file

@ -0,0 +1,13 @@
#include "Render/DeviceSelection.h"
// STATIC: 0x0173A878
// GLOBAL: gl_24397
unsigned char g_guidDevice[16];
// STATIC: 0x0173A888
// GLOBAL: gl_24513
unsigned char g_guidDriver[16];
// STATIC: 0x0173A898
// GLOBAL: gl_24514
char g_deviceName[40];

View file

@ -0,0 +1,8 @@
#ifndef RAGNAROK_SOURCE_RENDER_DEVICESELECTION_H
#define RAGNAROK_SOURCE_RENDER_DEVICESELECTION_H
extern unsigned char g_guidDevice[16];
extern unsigned char g_guidDriver[16];
extern char g_deviceName[40];
#endif

View file

@ -1,3 +1,5 @@
#include "Client/Registry.h"
#include "Render/DeviceSelection.h"
#include "Render/DisplayMode.h"
#include <algorithm>
@ -53,22 +55,6 @@ std::vector<DisplayMode> EnumerateDisplayModesDX9(UINT adapter) {
return result;
}
// STATIC: 0x01348F80
// GLOBAL: gl_21922
extern const char* g_subKey;
// STATIC: 0x0173A878
// GLOBAL: gl_24397
extern unsigned char g_guidDevice[16];
// STATIC: 0x0173A888
// GLOBAL: gl_24513
extern unsigned char g_guidDriver[16];
// STATIC: 0x0173A898
// GLOBAL: gl_24514
extern char g_deviceName[40];
// OFFSET: 0x0056A7E0
// FUNCTION: fn_02297
LSTATUS SaveDisplayDeviceSettings() {

View file

@ -202,6 +202,7 @@
"Source/Client/Application/ApplicationMessages.cpp": 4,
"Source/Client/Application/ApplicationWindow.cpp": 0,
"Source/Client/Application/ErrorDialog.cpp": 0,
"Source/Client/Application/LaunchInfo.cpp": 0,
"Source/Client/Application/Launcher.cpp": 0,
"Source/Client/Application/UnhandledExceptionHandler.cpp": 0,
"Source/Client/Browser/BrowserAddressBar.cpp": 0,
@ -235,7 +236,9 @@
"Source/Client/Mode/ModeCursor.cpp": 0,
"Source/Client/Mode/ModeDragState.cpp": 2,
"Source/Client/Mode/ModeTooltip.cpp": 2,
"Source/Client/Registry.cpp": 0,
"Source/Client/ReplayPacketRecorder.cpp": 2,
"Source/Client/Session.cpp": 0,
"Source/Contents/ActorNameCard.cpp": 4,
"Source/Contents/ActorNameDirectory.cpp": 4,
"Source/Contents/Actors/AttackMotion.cpp": 4,
@ -433,6 +436,7 @@
"Source/Render/DeviceContext/DCBitmap.cpp": 0,
"Source/Render/DeviceContext/DCSurface.cpp": 0,
"Source/Render/DeviceContext/DeviceContext.cpp": 0,
"Source/Render/DeviceSelection.cpp": 0,
"Source/Render/Direct3DErrors.cpp": 0,
"Source/Render/DisplayMode.cpp": 0,
"Source/Render/Primitives/DepthAlpha.cpp": 0,