rodecomp/Source/Resource/Sprites/ActionResource.cpp
ragnarok-clanker dc3d5ce1a5 Maintenance: Resubmission of 14942 (gate: three existing in-class helpers whose lines changed lacked an annotation; marked // INLINED
Batch #14943 by ragnarok-clanker: no function's compiled code changes; checked with 741 compiled unit(s), including every includer of Source/ActorPickNode.h, Source/Client/Browser/BrowserClientSite.h, Source/Client/Browser/BrowserPopupDispatch.h, Source/Client/Mode/CGameMode.h, Source/Client/Mode/CLoginMode.h, Source/Client/Mode/CMode.h, Source/Client/Mode/ModeDragState.h, Source/Client/Replay.h, Source/Client/Session.h, Source/Client/Stove/StoveMgr.h, Source/Contents/AchievementMgr.h, Source/Contents/ActorNameCard.h, Source/Contents/Actors/CharacterRender.h, Source/Contents/Actors/EffectActors.h, Source/Contents/Actors/GameActor.h, Source/Contents/Actors/GrannyGameActor.h, Source/Contents/Actors/GroundScope.h, Source/Contents/Actors/Item.h, Source/Contents/Actors/Npc.h, Source/Contents/Actors/Pc.h, Source/Contents/Actors/RenderObjectState.h, Source/Contents/Actors/Skill.h, Source/Contents/AdventureGuideMgr.h, Source/Contents/Camera/Camera.h, Source/Contents/Camera/CameraState.h, Source/Contents/CashEmotionMgr.h, Source/Contents/Configuration/GameSettingsMgr.h, Source/Contents/EffectResourceSwitcher.h, Source/Contents/Effects/AMachineEffect.h, Source/Contents/Effects/AcidifiedThrow.h, Source/Contents/Effects/AxeBoomerang.h, Source/Contents/Effects/BlastForge.h, Source/Contents/Effects/CaneOfEvilEyeEffect.h, Source/Contents/Effects/CharacterParticleBundle.h, Source/Contents/Effects/CloudKillEffect.h, Source/Contents/Effects/Effect.h, Source/Contents/Effects/EffectActor.h, Source/Contents/Effects/EffectEmitter.h, Source/Contents/Effects/EffectMaker.h, Source/Contents/Effects/EffectPrimitiveState.h, Source/Contents/Effects/FuumaShouakuEffect.h, Source/Contents/Effects/GravityControlEffect.h, Source/Contents/Effects/HealSpEffect.h, Source/Contents/Effects/Level99Effect.h, Source/Contents/Effects/MapChainEffect.h, Source/Contents/Effects/MonsterSkillEffects.h, Source/Contents/Effects/MsgEffect.h, Source/Contents/Effects/NyanggrassEffect.h, Source/Contents/Effects/Particle.h, Source/Contents/Effects/PowderingEffect.h, Source/Contents/Effects/RagEffectState.h, Source/Contents/Effects/RectUpEffect.h, Source/Contents/Effects/ShadowExceedEffect.h, Source/Contents/Effects/SkillEffects.h, Source/Contents/Effects/SpriteParticle.h, Source/Contents/Effects/StormCannonEffect.h, Source/Contents/Effects/ThrowEffects.h, Source/Contents/EntryQueueMgr.h, Source/Contents/EquipmentResourceMgr.h, Source/Contents/FlyingShipRouteInfo.h, Source/Contents/Ground/GroundGeometry.h, Source/Contents/GuildInfo.h, Source/Contents/Items/ItemDescription.h, Source/Contents/Items/ItemInfo.h, Source/Contents/MapSkyMgr.h, Source/Contents/Messenger/MessengerWindows.h, Source/Contents/Models/ModelNode.h, Source/Contents/NavigationManager.h, Source/Contents/Party/AdventurerAgencyMgr.h, Source/Contents/RDamageVar.h, Source/Contents/RenewQuestMgr.h, Source/Contents/ReputeMgr.h, Source/Contents/RodexMailStore.h, Source/Contents/RouletteMgr.h, Source/Contents/Schedule/Schedule.h, Source/Contents/SignBoard/SignBoard.h, Source/Contents/Skills/ClientSkills.h, Source/Contents/Skills/PlayerSkillBundle.h, Source/Contents/Skills/SkillInfo.h, Source/Contents/SpriteLayerDrawing.h, Source/Contents/TipBoxTitles.h, Source/Contents/UserData/AccountLinkedUserDataMgr.h, Source/Contents/UserData/NormalItemSlots.h, Source/Contents/World/World.h, Source/Contents/WorldView/WorldViewData.h, Source/Render/Primitives/LightmappedPrimitive.h, Source/Render/Primitives/RenderPrimitive.h, Source/Render/Renderer.h, Source/Render/Textures/SpritePixels.h, Source/Render/Textures/Texture.h, Source/Resource/EZeffectResource.h, Source/Resource/Models/AnimatedModelResource.h, Source/Resource/Models/GrannyModelResource.h, Source/Resource/Sprites/ActionResource.h, Source/Resource/World/GroundResource.h, Source/Resource/World/WorldResource.h, Source/Resource/XmlNode.h, Source/UI/AdventureGuide/UIAdventureGuide.h, Source/UI/Buttons/UIBmpRadioBtn.h, Source/UI/Buttons/UIDescriptRace.h, Source/UI/Buttons/UIItemTagButton.h, Source/UI/Buttons/UISlotBmpButton.h, Source/UI/Buttons/UISpriteButton.h, Source/UI/Buttons/UITVTextButton.h, Source/UI/Buttons/UITextureButton.h, Source/UI/CashEmotion/UICashEmotionListWnd.h, Source/UI/CashEmotion/UICashEmotionPack.h, Source/UI/CashShop/UICashShopWnd.h, Source/UI/Chat/UIChatRoomMakeWnd.h, Source/UI/Chat/UIChatRoomTitle.h, Source/UI/Chat/UINewChatWnd.h, Source/UI/Chat/UISubChatHisWnd.h, Source/UI/Chat/UISubChatMiniWnd.h, Source/UI/Chat/UIWhisperWnd.h, Source/UI/Clan/UIClanWnd.h, Source/UI/Dialogs/UIBookWnd.h, Source/UI/Dialogs/UIChooseWarpWnd.h, Source/UI/Dialogs/UIMenuWnd.h, Source/UI/Dialogs/UIMiniMapWnd.h, Source/UI/Dialogs/UIMinimapZoomWnd.h, Source/UI/Dialogs/UINpcEditDialogWnd.h, Source/UI/Dialogs/UIPasswordWnd.h, Source/UI/Dialogs/UISayDialogWnd.h, Source/UI/Dialogs/UISelectCartWnd.h, Source/UI/Dialogs/UITipboxWnd.h, Source/UI/Edit/UIEditBoxEx.h, Source/UI/Edit/UIEditCtrl.h, Source/UI/Edit/UIEditCtrl_Currency.h, Source/UI/Edit/UIItemTagCtrl.h, Source/UI/Enchant/EnchantUI.h, Source/UI/Exchange/UIExchangeUI.h, Source/UI/FrameSkin.h, Source/UI/GameSettings/GameSettingsUI.h, Source/UI/Gauges/UIPcGage.h, Source/UI/Guild/UIGuildHelperWnd.h, Source/UI/Guild/UIGuildWnd.h, Source/UI/Guild/UIGuild_Storage_Log.h, Source/UI/Item/UIEquipmentPropertiesWnd.h, Source/UI/Item/UIItemBaseWnd.h, Source/UI/Item/UIItemPurchaseWnd.h, Source/UI/Item/UIItemSellWnd2.h, Source/UI/Item/UIItemShopWnd.h, Source/UI/Item/UIItemShopWnd2.h, Source/UI/Item/UIItemStoreFindWnd.h, Source/UI/Item/UIItemStoreSubWnd.h, Source/UI/Item/UIItemStoreWnd.h, Source/UI/Item/UIItemWnd.h, Source/UI/Item/UIMerchantItemLogWnd.h, Source/UI/Item/UIParaItemShopWnd.h, Source/UI/Items/UICardItemIllustWnd.h, Source/UI/Items/UIEquipWnd.h, Source/UI/Items/UIExchangeWnd.h, Source/UI/Items/UIGameItem.h, Source/UI/Items/UIItemCollectionWnd.h, Source/UI/Items/UIItemIdentifyWnd.h, Source/UI/Items/UIItemParamChangeDisplayWnd.h, Source/UI/Items/UISwapEquipmentWnd.h, Source/UI/Layout/WindowGeometry.h, Source/UI/Lists/UIChatHisBox.h, Source/UI/Lists/UIComboBoxV2Wnd.h, Source/UI/Lists/UIImgMenu.h, Source/UI/Lists/UIListBoxID.h, Source/UI/Lists/UIListBoxTemplate.h, Source/UI/Lists/UIMemberListBox.h, Source/UI/Lists/UITabControl.h, Source/UI/Lists/UITagListBox.h, Source/UI/Lists/UITreeView.h, Source/UI/Menu/UIMenuIconWnd.h, Source/UI/Navigation/UINavigationV4Wnd.h, Source/UI/ProbabilityTable/UIProbabilityTable.h, Source/UI/Quest/UIQuestDisplay.h, Source/UI/Quest/UIRenewQuestUI.h, Source/UI/Quest/UIRenewQuestWnd.h, Source/UI/Rodex/UIRodexComposeWnd.h, Source/UI/Rodex/UIRodexInboxWnd.h, Source/UI/RuneSystem/UIRuneSystemWindows.h, Source/UI/RuneSystem/UIRuneSystemWnd.h, Source/UI/Shop/UIMerchantItemMyShopWnd.h, Source/UI/Shop/UIMerchantItemPurchaseMSGWnd.h, Source/UI/Shop/UIMerchantItemPurchaseWnd.h, Source/UI/Shop/UIMerchantItemShopWnd.h, Source/UI/Shop/UIMerchantMirrorItemWnd.h, Source/UI/Shop/UIMerchantShopMakeWnd.h, Source/UI/Shop/UIMerchantShopTitle.h, Source/UI/Skill/UISkillDescribeWnd.h, Source/UI/Skill/UISkillListWnd.h, Source/UI/SkillDelayInfo/SkillDelayInfo.h, Source/UI/StylingShop/UIStylingShopWnd.h, Source/UI/Text/CreateLineInfo.h, Source/UI/Text/UIAchWnd.h, Source/UI/Text/UIBalloonText.h, Source/UI/Text/UINameBalloonText.h, Source/UI/Text/UIStaticTextControl.h, Source/UI/Text/UIString.h, Source/UI/Text/UITextViewerControl.h, Source/UI/UIBarGraph.h, Source/UI/UIBartermarketWnd.h, Source/UI/UIChangeMaterialWnd.h, Source/UI/UIGradeEnchantWnd.h, Source/UI/UILapineScrollBar.h, Source/UI/UIMacroBlackListCheckWnd.h, Source/UI/UIMacroDetectorWnd.h, Source/UI/UIMacroReport.h, Source/UI/UIMacroUserInfoWnd.h, Source/UI/UIPreviewEquipWnd.h, Source/UI/UIRefiningWnd.h, Source/UI/UIScrollWnd.h, Source/UI/UISlotBitmap.h, Source/UI/Window/FuncDrawWNDChar.h, Source/UI/Window/UIBattleMsgOptionWnd.h, Source/UI/Window/UIChatRoomWnd.h, Source/UI/Window/UICollectionSystemWnd.h, Source/UI/Window/UIControl.h, Source/UI/Window/UIHomunInfoWnd.h, Source/UI/Window/UIHotKeyWnd.h, Source/UI/Window/UIJobListWnd.h, Source/UI/Window/UILoginOTPWnd.h, Source/UI/Window/UILoginWnd.h, Source/UI/Window/UIMakeCharWnd.h, Source/UI/Window/UIMonsterDisplayWnd.h, Source/UI/Window/UIMonsterInfoWnd.h, Source/UI/Window/UINavigationHelpWnd.h, Source/UI/Window/UINavigationWnd.h, Source/UI/Window/UINewMakeCharWnd.h, Source/UI/Window/UINewSelectCharWnd.h, Source/UI/Window/UINoticeWnd.h, Source/UI/Window/UIPetInfoWnd.h, Source/UI/Window/UIRegisterMgr.h, Source/UI/Window/UIRoMapWnd.h, Source/UI/Window/UIRodexContentsWnd.h, Source/UI/Window/UISecondCostumeWnd.h, Source/UI/Window/UISeekPartyMBWnd.h, Source/UI/Window/UISeekPartyWnd.h, Source/UI/Window/UISelCharForUServerWnd.h, Source/UI/Window/UISerachStoreInfoWnd.h, Source/UI/Window/UITransMenuWnd.h, Source/UI/Window/UIWindow.h, Source/UI/Window/UIWindowMgr.h, Source/UI/Window/UIWindowMgr.inl, Source/Utility/Lexicon/LexiconSerializer.h.
2026-11-08 16:44:36 +00:00

285 lines
7.9 KiB
C++

#include "Client/Application/ErrorDialog.h"
#include "File/File.h"
#include "Render/DeviceContext/DCSurface.h"
#include "Resource/Sprites/ActionResource.h"
#include "Resource/Bitmap/BitmapResource.h"
#include "Resource/ResourceByteReader.h"
#include "Resource/ResourceMgr.h"
#include "Resource/Sprites/SpriteResource.h"
#include "Utility/Math/ScalarConversion.h"
#include <algorithm>
#include <cstring>
namespace {
// INLINED
int RelativeCoordinate(int position, int extent, float scale) {
const int center = extent / 2 + extent % 2;
const float offset = static_cast<float>(center) * scale;
const float coordinate = static_cast<float>(position) - offset;
return TruncateToInt(coordinate / scale);
}
}
// OFFSET: 0x00745FB0
// FUNCTION: fn_07767
CActRes::CActRes() {
this->maximumCells = 0;
}
// INLINED
CActRes::~CActRes() = default;
// OFFSET: 0x007436B0
// FUNCTION: fn_07749
CActRes* CActRes::Create() {
return new CActRes;
}
// OFFSET: 0x007437B0
// FUNCTION: fn_07750
bool CActRes::Load(const char* name) {
CFile file;
if (!file.Open(name, 0, true, false)) {
ShowErrorDialog(GetRenderSystemHolder()->system, (std::string("Cannot find File : ") + std::string(name)).c_str(), 0);
return false;
}
struct Header {
std::uint16_t magic;
std::uint16_t version;
std::uint16_t count;
unsigned char reserved[10];
} header;
file.Read(&header, sizeof(header));
if (header.magic != 0x4341) {
ShowErrorDialog(GetRenderSystemHolder()->system, "Illegal file format", 0);
ShowErrorDialog(GetRenderSystemHolder()->system, name, 0);
file.Close();
return false;
}
std::string spriteName(name);
spriteName.resize(spriteName.size() - 4);
spriteName.append(".spr", 4);
if (header.version > 0x0205) {
ShowErrorDialog(GetRenderSystemHolder()->system, "Unsupported Version. Content may be corrupted", 0);
file.Close();
return false;
}
this->Unload();
this->animations.resize(header.count);
this->speeds.resize(header.count, 4.0f);
for (unsigned animationIndex = 0; animationIndex < this->animations.size(); ++animationIndex) {
std::vector<ActionFrame>& animation = this->animations[animationIndex];
int frameCount;
file.Read(&frameCount, sizeof(frameCount));
animation.resize(frameCount);
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
std::int32_t range1[4];
std::int32_t range2[4];
file.Read(range1, sizeof(range1));
file.Read(range2, sizeof(range2));
int cellCount;
file.Read(&cellCount, sizeof(cellCount));
ActionFrame& frame = animation[frameIndex];
frame.sound = -1;
frame.cellCount = cellCount;
frame.cells.resize(std::min(static_cast<unsigned>(cellCount), 1000u));
frame.anchors.clear();
frame.anchorCount = 0;
std::memcpy(frame.rangeBounds, range1, sizeof(range1));
std::memcpy(frame.rangeBounds + 4, range2, sizeof(range2));
if (this->maximumCells < cellCount) {
this->maximumCells = cellCount;
}
for (int index = 0; index < cellCount; ++index) {
SpriteFrameCell& cell = frame.cells[index];
if (header.version < 0x0200) {
file.Read(&cell, 16);
cell.color = 0xFFFFFFFFu;
cell.scaleX = 1.0f;
cell.scaleY = 1.0f;
cell.rotation = 0;
cell.imageType = 0;
continue;
}
if (header.version < 0x0204) {
struct LegacyCell {
std::int32_t x;
std::int32_t y;
std::int32_t image;
std::int32_t mirrored;
std::uint32_t color;
float scale;
std::int32_t rotation;
std::int32_t imageType;
} legacy;
file.Read(&legacy, sizeof(legacy));
cell = {legacy.x, legacy.y, legacy.image, legacy.mirrored, legacy.color, legacy.scale, legacy.scale, legacy.rotation, legacy.imageType};
} else {
file.Read(&cell, sizeof(cell));
}
if (header.version >= 0x0205) {
int width;
int height;
file.Read(&width, sizeof(width));
file.Read(&height, sizeof(height));
if (cell.image != -1) {
cell.x = RelativeCoordinate(cell.x, width, cell.scaleX);
cell.y = RelativeCoordinate(cell.y, height, cell.scaleY);
}
} else if (cell.image != -1) {
auto* sprite = static_cast<CSprRes*>(ResourceMgr::Instance().Load(spriteName.c_str()));
if (sprite) {
const SpriteRleImage* image = sprite->images[cell.imageType][cell.image];
if (image) {
const int width = image->width * (image->doubleWidth != 0 ? 2 : 1);
const int height = image->height * (image->doubleHeight != 0 ? 2 : 1);
cell.x = RelativeCoordinate(cell.x, width, cell.scaleX);
cell.y = RelativeCoordinate(cell.y, height, cell.scaleY);
}
}
}
}
if (header.version >= 0x0200) {
file.Read(&frame.sound, sizeof(frame.sound));
if (header.version == 0x0200) {
frame.sound = -1;
}
}
if (header.version >= 0x0203) {
int count;
file.Read(&count, sizeof(count));
frame.anchorCount = count;
frame.anchors.resize(static_cast<unsigned>(count));
for (int index = 0; index < count; ++index) {
struct AnchorRecord {
int unused;
ActionAnchor anchor;
} anchor;
file.Read(&anchor, sizeof(anchor));
frame.anchors[index] = anchor.anchor;
}
}
}
}
if (header.version >= 0x0201) {
int count;
file.Read(&count, sizeof(count));
this->sounds.resize(static_cast<unsigned>(count));
for (int index = 0; index < count; ++index) {
char sound[40];
file.Read(sound, sizeof(sound));
this->sounds[index] = sound;
}
}
if (header.version >= 0x0202) {
for (int index = 0; index < header.count; ++index) {
file.Read(&this->speeds[index], sizeof(float));
}
}
file.Close();
return true;
}
// OFFSET: 0x007445A0
// FUNCTION: fn_07751
void CActRes::Unload() {
this->animations.clear();
this->sounds.clear();
}
// OFFSET: 0x00746F80
// FUNCTION: fn_07783
const std::vector<ActionFrame>& CActRes::Animation(unsigned index) const {
if (index < this->animations.size()) {
return this->animations[index];
}
// STATIC: 0x0138D700
// GLOBAL: gl_25519
static const std::vector<ActionFrame> missingAnimation;
return missingAnimation;
}
// OFFSET: 0x00747050
// FUNCTION: fn_07784
const SpriteFrameCell& ActionFrame::Cell(unsigned index) const {
if (index < this->cells.size()) {
return this->cells[index];
}
// STATIC: 0x0132A1A8
static const SpriteFrameCell missing{0, 0, -1, 0, 0xFFFFFFFFu, 1.0f, 1.0f, 0, 0};
return missing;
}
// OFFSET: 0x00747090
// FUNCTION: fn_07785
float CActRes::Speed(unsigned index) const {
if (index < this->speeds.size()) {
return this->speeds[index];
}
return 4.0f;
}
// OFFSET: 0x007470E0
// FUNCTION: fn_07786
const char* CActRes::Sound(unsigned index) const {
return index < this->sounds.size() ? this->sounds[index].c_str() : "";
}
// OFFSET: 0x00747170
// FUNCTION: fn_07787
const ActionFrame& CActRes::Frame(unsigned animation, unsigned frame) const {
const auto& frames = this->Animation(animation);
if (frame < frames.size()) {
return frames[frame];
}
if (!frames.empty()) {
return frames.front();
}
// GLOBAL: gl_24507
static const ActionFrame missing;
return missing;
}
// OFFSET: 0x00747370
// FUNCTION: fn_07788
unsigned CActRes::FrameCount(unsigned animation) const {
const auto& frames = this->Animation(animation);
return (std::max)(static_cast<unsigned>(frames.size()), 1u);
}
// INLINED
CActRes::CActRes(const char* extension, const char* prefix) {
ResourceMgr::Instance().Register(extension, prefix, this);
}
// GLOBAL: gl_25546
CActRes g_actPrototype("act", "sprite\\");