Batch #5885 by Yommy: 2 byte-identical, 5 confirmed by peer review. - fn_21279 CGameMode::GetSkillAttackRange: logic confirmed by peer review - fn_21280 CGameMode::TerrainHeight: byte-identical - fn_21281 CGameMode::TerrainWidth: byte-identical - fn_21283 CGameMode::LocationText: logic confirmed by peer review - fn_21284 CGameMode::HasInventoryItem: logic confirmed by peer review - fn_21285 CGameMode::HasResurrectionItem: logic confirmed by peer review - fn_21287 CGameMode::SendMousePointerState: logic confirmed by peer review Peer-reviewed-by: kyoshi, Romain, Snow, Qwenkler3.8, SapitoSucio Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
461 lines
12 KiB
C++
461 lines
12 KiB
C++
#include "Client/Mode/CGameMode.h"
|
|
#include "Client/Replay.h"
|
|
#include "Client/ReplayPacketRecorder.h"
|
|
#include "Client/Session.h"
|
|
#include "Contents/Actors/GameActor.h"
|
|
#include "Contents/Camera/Camera.h"
|
|
#include "Contents/Configuration/ServiceOptions.h"
|
|
#include "Contents/MessageTable.h"
|
|
#include "Contents/Actors/MousePointer.h"
|
|
#include "Contents/Actors/RenderObject.h"
|
|
#include "Contents/Items/ItemInfo.h"
|
|
#include "Contents/Skills/ClientSkills.h"
|
|
#include "Contents/Skills/SkillInfo.h"
|
|
#include "Contents/World/World.h"
|
|
#include "Network/Packets/PacketLengths.h"
|
|
#include "Render/Renderer.h"
|
|
#include "Resource/World/TerrainResource.h"
|
|
#include "Script/LuaScript.h"
|
|
#include "UI/Window/UIWindow.h"
|
|
#include "UI/Window/UIWindowMgr.h"
|
|
#include "Utility/Text/FormatString.h"
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <timeapi.h>
|
|
|
|
#pragma pack(push, 1)
|
|
struct GameModeTextRecord {
|
|
/* 0000 */ std::uint32_t header;
|
|
/* 0004 */ std::int16_t length;
|
|
/* 0006 */ int firstLength;
|
|
/* 000A */ int secondLength;
|
|
/* 000E */ int unknown_000E;
|
|
/* 0012 */ int unknown_0012;
|
|
/* 0016 */ int unknown_0016;
|
|
/* 001A */ int unknown_001A;
|
|
/* 001E */ char buffer[0x172];
|
|
};
|
|
#pragma pack(pop)
|
|
|
|
static_assert(sizeof(GameModeTextRecord) == 0x190);
|
|
static_assert(offsetof(GameModeTextRecord, buffer) == 0x1E);
|
|
|
|
// GLOBAL: gl_24661
|
|
std::vector<ActiveSkillEffect> g_activeSkillEffects;
|
|
|
|
// OFFSET: 0x00CCF480
|
|
// FUNCTION: fn_21242
|
|
void CGameMode::PushUnknown01A4(int value) {
|
|
this->unknown_01A4.push_back(value);
|
|
}
|
|
|
|
// OFFSET: 0x00CCF530
|
|
// FUNCTION: fn_21243
|
|
bool CGameMode::IsOverWeight(bool notify) {
|
|
int maxWeight = g_session.m_maxWeight;
|
|
if (maxWeight < 1) {
|
|
maxWeight = 1;
|
|
}
|
|
|
|
if (g_session.m_weight * 100 / maxWeight < 90) {
|
|
return false;
|
|
}
|
|
|
|
if (notify) {
|
|
g_windowMgr.SendNotice(3, 0, 0, 0, 0, 0);
|
|
g_windowMgr.SendNotice(1, reinterpret_cast<std::intptr_t>(LookupMessage(307)), 255, 0, 0, 0);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// OFFSET: 0x00CCFCF0
|
|
// FUNCTION: fn_21247
|
|
void CGameMode::CompleteUnknown0194(std::uint32_t id, const std::string& text) {
|
|
auto it = this->unknown_0194.find(id);
|
|
if (it != this->unknown_0194.end()) {
|
|
this->SendMsg(140, reinterpret_cast<int>(text.c_str()), it->second, 0, 0);
|
|
this->unknown_0194.erase(it);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00CD52F0
|
|
// FUNCTION: fn_21279
|
|
int CGameMode::GetSkillAttackRange(int id, int level) {
|
|
if (id == 10000) {
|
|
return 5;
|
|
}
|
|
|
|
int range = 1;
|
|
CSkillInfo skill = reinterpret_cast<const ClientSkills&>(g_session).Lookup(id);
|
|
if (!skill.available) {
|
|
skill = g_session.m_skillBundle.Pending(id);
|
|
if (!skill.available) {
|
|
return range;
|
|
}
|
|
|
|
level = skill.level;
|
|
}
|
|
|
|
int reduction = 0;
|
|
g_luaScript->Call("GetSkillAttackRange", "ddd>dd", id, level, skill.level, &range, &reduction);
|
|
range += skill.unknown_001C - reduction;
|
|
return range;
|
|
}
|
|
|
|
// OFFSET: 0x00CD54D0
|
|
// FUNCTION: fn_21280
|
|
int CGameMode::TerrainHeight() const {
|
|
if (!this->scene || !this->scene->terrain) {
|
|
return 0;
|
|
}
|
|
|
|
return this->scene->terrain->height;
|
|
}
|
|
|
|
// OFFSET: 0x00CD54F0
|
|
// FUNCTION: fn_21281
|
|
int CGameMode::TerrainWidth() const {
|
|
if (!this->scene || !this->scene->terrain) {
|
|
return 0;
|
|
}
|
|
|
|
return this->scene->terrain->width;
|
|
}
|
|
|
|
// OFFSET: 0x00CD5550
|
|
// FUNCTION: fn_21283
|
|
std::string CGameMode::LocationText() {
|
|
char text[120];
|
|
std::memset(text, 0, sizeof(text));
|
|
|
|
int column;
|
|
int row;
|
|
const auto* player = reinterpret_cast<const CRenderObject*>(this->scene->player);
|
|
this->WorldCell(player->render.position.x, player->render.position.z, column, row);
|
|
|
|
std::string name = this->mapName;
|
|
if (name.size() > 4) {
|
|
name.resize(name.size() - 4);
|
|
}
|
|
|
|
std::sprintf(text, "Location: %s ( %d , %d )", name.c_str(), column, row);
|
|
return text;
|
|
}
|
|
|
|
// OFFSET: 0x00CD5800
|
|
// FUNCTION: fn_21284
|
|
bool CGameMode::HasInventoryItem(int id) {
|
|
const ITEM_INFO item = LookupClientItem(g_session.m_inventoryItems, id, 0);
|
|
return item.unknown_0000[1] != 0 && item.quantity > 0;
|
|
}
|
|
|
|
// OFFSET: 0x00CD58B0
|
|
// FUNCTION: fn_21285
|
|
bool CGameMode::HasResurrectionItem() {
|
|
ITEM_INFO item = LookupClientItem(g_session.m_inventoryItems, 7621, 0);
|
|
const CWorld* world = this->scene;
|
|
if (world->unknown_0048 || world->unknown_004C || world->unknown_0054) {
|
|
return false;
|
|
}
|
|
|
|
if (item.unknown_0000[1] != 0 && item.quantity > 0) {
|
|
return true;
|
|
}
|
|
|
|
item = LookupClientItem(g_session.m_inventoryItems, 6833, 0);
|
|
if (item.unknown_0000[1] != 0 && item.quantity > 0) {
|
|
return true;
|
|
}
|
|
|
|
item = LookupClientItem(g_session.m_inventoryItems, 6316, 0);
|
|
if (item.unknown_0000[1] != 0 && item.quantity > 0) {
|
|
return true;
|
|
}
|
|
|
|
item = LookupClientItem(g_session.m_inventoryItems, 6293, 0);
|
|
if (item.unknown_0000[1] != 0 && item.quantity > 0) {
|
|
return true;
|
|
}
|
|
|
|
item = LookupClientItem(g_session.m_inventoryItems, 25310, 0);
|
|
if (item.unknown_0000[1] != 0 && item.quantity > 0) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// OFFSET: 0x00CD5CD0
|
|
// FUNCTION: fn_21287
|
|
void CGameMode::SendMousePointerState(int value) {
|
|
if (this->mousePointer) {
|
|
this->mousePointer->SendMsg(nullptr, 2, 0, value, value >> 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00CECE00
|
|
// FUNCTION: fn_21360
|
|
void CGameMode::ClearUnknown0458() {
|
|
*reinterpret_cast<int*>(reinterpret_cast<char*>(this) + 0x458) = 0;
|
|
}
|
|
|
|
// OFFSET: 0x00CECE10
|
|
// FUNCTION: fn_21361
|
|
void CGameMode::SetDragIds(int source, int id) {
|
|
if (id != -1) {
|
|
this->drag.source = source;
|
|
this->drag.id = static_cast<std::uint32_t>(id);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00CED190
|
|
// FUNCTION: fn_21363
|
|
void CGameMode::UpdateUnknown0628(int id, bool add) {
|
|
if (add == true) {
|
|
this->unknown_0628.insert(id);
|
|
} else {
|
|
this->unknown_0628.erase(id);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00CF0070
|
|
// FUNCTION: fn_21410
|
|
const char* CGameMode::Unknown04DCText() {
|
|
return reinterpret_cast<std::string*>(reinterpret_cast<char*>(this) + 0x4DC)->c_str();
|
|
}
|
|
|
|
// OFFSET: 0x00CF0320
|
|
// FUNCTION: fn_21412
|
|
CPlayer* CGameMode::Player() {
|
|
if (!this->scene) {
|
|
return nullptr;
|
|
}
|
|
return this->scene->player;
|
|
}
|
|
|
|
// OFFSET: 0x00CF0330
|
|
// FUNCTION: fn_21413
|
|
MinimapMarker* CGameMode::FindMinimapMarker(std::uint32_t key) {
|
|
const auto it = this->minimapMarkers.find(key);
|
|
if (it == this->minimapMarkers.end()) {
|
|
return nullptr;
|
|
}
|
|
return &it->second;
|
|
}
|
|
|
|
// OFFSET: 0x00CF06B0
|
|
// FUNCTION: fn_21416
|
|
float CGameMode::CameraDesiredYaw() {
|
|
if (!this->camera) {
|
|
return 0.0f;
|
|
}
|
|
return this->camera->camera.desiredYaw;
|
|
}
|
|
|
|
// OFFSET: 0x00CF0380
|
|
// FUNCTION: fn_21414
|
|
std::string CGameMode::GetActiveSkillEffectTimeText(int skillId, int* activeSkillId) {
|
|
std::string output;
|
|
*activeSkillId = skillId;
|
|
|
|
for (const ActiveSkillEffect& effect : g_activeSkillEffects) {
|
|
const int effectId = static_cast<int>(effect.id);
|
|
if (skillId != (effectId == 0x2A ? 0x0C : effectId)) {
|
|
continue;
|
|
}
|
|
|
|
*activeSkillId = effectId;
|
|
const std::uint32_t expiration = effect.unknown_0004;
|
|
if (expiration == 999999 || expiration == 0) {
|
|
return output;
|
|
}
|
|
|
|
std::uint32_t remainingSeconds = 0;
|
|
if (g_replayAnimationScaling == 0) {
|
|
remainingSeconds = (expiration - timeGetTime()) / 1000;
|
|
} else {
|
|
const int remainingMilliseconds = static_cast<int>(expiration) - static_cast<int>(Replay::Instance().elapsed);
|
|
if (remainingMilliseconds >= 1000) {
|
|
remainingSeconds = static_cast<std::uint32_t>(remainingMilliseconds) / 1000;
|
|
}
|
|
}
|
|
|
|
const int signedSeconds = static_cast<int>(remainingSeconds);
|
|
const int hours = signedSeconds / 3600;
|
|
if (hours != 0) {
|
|
output.append(FormatOwnedString("%d %s", hours, LookupMessage(0x6A1)));
|
|
}
|
|
|
|
const int remainder = signedSeconds - hours * 3600;
|
|
const int minutes = remainder / 60;
|
|
const int seconds = remainder % 60;
|
|
if (minutes != 0) {
|
|
output.append(FormatOwnedString(" %d %s", minutes, LookupMessage(0x70F)));
|
|
}
|
|
if (seconds != 0) {
|
|
output.append(FormatOwnedString(" %d %s", seconds, LookupMessage(0x710)));
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
// OFFSET: 0x00CF0A80
|
|
// FUNCTION: fn_21420
|
|
bool CGameMode::IsActiveSkillEffectId(std::uint32_t id) {
|
|
if (this->IsExcludedSkillEffectId(id)) {
|
|
return false;
|
|
}
|
|
|
|
for (const ActiveSkillEffect& effect : g_activeSkillEffects) {
|
|
if (effect.id == id) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// OFFSET: 0x00D07720
|
|
// FUNCTION: fn_21582
|
|
bool CGameMode::IsExcludedSkillEffectId(std::uint32_t id) {
|
|
return id == 0x28 || id == 0x2A;
|
|
}
|
|
|
|
// OFFSET: 0x00D07740
|
|
// FUNCTION: fn_21583
|
|
int CGameMode::SubD07740(int id, int defaultResult) {
|
|
if (id < 0xFB5) {
|
|
if (id == 0xFB4 || id == 0x13) {
|
|
return 1;
|
|
}
|
|
|
|
if (id == 0x14) {
|
|
return 0;
|
|
}
|
|
} else {
|
|
switch (id) {
|
|
case 0xFB5:
|
|
case 0xFCB:
|
|
case 0xFE5:
|
|
case 0xFEC:
|
|
case 0x1009:
|
|
case 0x10A8:
|
|
return 0;
|
|
case 0xFCA:
|
|
case 0xFE4:
|
|
case 0xFEB:
|
|
case 0x1008:
|
|
case 0x10A7:
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
return defaultResult;
|
|
}
|
|
|
|
// OFFSET: 0x00CEB8E0
|
|
// FUNCTION: fn_21352
|
|
void CGameMode::sub_CEB8E0() {
|
|
if (Replay::Instance().state != 2) {
|
|
return;
|
|
}
|
|
|
|
GameModeTextRecord record = {};
|
|
record.header = 0x038808AE;
|
|
record.firstLength = static_cast<int>(this->unknown_03C8.size());
|
|
record.secondLength = static_cast<int>(this->unknown_03E0.size());
|
|
record.unknown_000E = this->unknown_03F8;
|
|
record.unknown_0012 = this->unknown_03FC;
|
|
record.unknown_0016 = this->unknown_0400;
|
|
record.unknown_001A = this->unknown_0404;
|
|
|
|
std::memcpy(record.buffer, this->unknown_03C8.data(), record.firstLength);
|
|
std::memcpy(record.buffer + record.firstLength, this->unknown_03E0.data(), record.secondLength);
|
|
record.length = static_cast<std::int16_t>(offsetof(GameModeTextRecord, buffer) + record.firstLength + record.secondLength);
|
|
|
|
Replay& replay = Replay::Instance();
|
|
ReplayPacketRecorder recorder = {
|
|
g_packetLengths,
|
|
replay.baseFrame,
|
|
replay.started,
|
|
replay.frame,
|
|
replay.header.key0,
|
|
replay.header.key1,
|
|
replay.header.options.recordRestricted,
|
|
replay.file,
|
|
replay.fileOffset,
|
|
replay.records,
|
|
replay.cipherIndex,
|
|
replay.cipherBase,
|
|
replay.cipherKey,
|
|
};
|
|
recorder.Record(static_cast<std::uint16_t>(record.length), &record, 0x2A, 0);
|
|
}
|
|
|
|
// OFFSET: 0x00CDD350
|
|
// FUNCTION: fn_21316
|
|
void CGameMode::PlaceWindowAtActor(UIWindow* window, CGameActor* actor) {
|
|
const int width = window->geometry.width;
|
|
const int height = window->geometry.height;
|
|
const bool raised = g_serviceOptions.Get(0x5C) != 0;
|
|
int offsetX = 0;
|
|
int offsetY = 0;
|
|
switch (actor->render.unknown_00A8 != 0 ? raised : 0) {
|
|
case 0:
|
|
offsetX = -(width / 2);
|
|
offsetY = static_cast<int>(static_cast<float>(g_renderer->viewport.height * 20 / 480) * actor->render.unknown_005C);
|
|
break;
|
|
case 1:
|
|
offsetX = -(width / 2);
|
|
offsetY = static_cast<int>(static_cast<float>(g_renderer->viewport.height * -100 / 480) * actor->render.unknown_005C);
|
|
break;
|
|
case 2:
|
|
offsetX = static_cast<int>(
|
|
static_cast<float>(g_renderer->viewport.width * -30 / 640) * actor->render.unknown_005C - static_cast<float>(width / 2)
|
|
);
|
|
offsetY = static_cast<int>(
|
|
static_cast<float>(g_renderer->viewport.height * -25 / 480) * actor->render.unknown_005C - static_cast<float>(height / 2)
|
|
);
|
|
break;
|
|
case 3:
|
|
offsetX = static_cast<int>(
|
|
static_cast<float>(g_renderer->viewport.width * 30 / 640) * actor->render.unknown_005C - static_cast<float>(width / 2)
|
|
);
|
|
offsetY = static_cast<int>(
|
|
static_cast<float>(g_renderer->viewport.height * -25 / 480) * actor->render.unknown_005C - static_cast<float>(height / 2)
|
|
);
|
|
break;
|
|
}
|
|
|
|
int x = actor->render.screenX + offsetX;
|
|
int y = actor->render.screenY + offsetY;
|
|
if (x < -3) {
|
|
x = -3;
|
|
}
|
|
const int maximumX = g_renderer->viewport.width - window->geometry.width + 3;
|
|
if (maximumX < x) {
|
|
x = maximumX;
|
|
}
|
|
if (y < -3) {
|
|
y = -3;
|
|
}
|
|
const int maximumY = g_renderer->viewport.height - window->geometry.height + 3;
|
|
if (maximumY < y) {
|
|
y = maximumY;
|
|
}
|
|
window->Move(x, y);
|
|
}
|
|
|
|
// OFFSET: 0x00CDD790
|
|
// FUNCTION: fn_21318
|
|
void CGameMode::Slot7(int value) {
|
|
}
|