diff --git a/Source/Resource/Bitmap/BitmapImage.h b/Source/Resource/Bitmap/BitmapImage.h index 358d1f43..afba7e2c 100644 --- a/Source/Resource/Bitmap/BitmapImage.h +++ b/Source/Resource/Bitmap/BitmapImage.h @@ -3,7 +3,6 @@ #include -class IJL15Runtime; struct BitmapImage { /* 0110 */ int alpha; @@ -20,7 +19,7 @@ struct BitmapImage { bool DecodeBitmap(const void* data, int bytes, bool iconOnly); bool DecodeTga(const void* data, int bytes); bool DecodePng(const void* data, int bytes, const char* name); - bool DecodeJpeg(const void* data, int bytes, IJL15Runtime& runtime); + bool DecodeJpeg(const void* data, int bytes); }; #if defined(_WIN32) && !defined(_WIN64) diff --git a/Source/Resource/Bitmap/BitmapImageJpeg.cpp b/Source/Resource/Bitmap/BitmapImageJpeg.cpp index c5f57916..af608df5 100644 --- a/Source/Resource/Bitmap/BitmapImageJpeg.cpp +++ b/Source/Resource/Bitmap/BitmapImageJpeg.cpp @@ -5,9 +5,9 @@ // OFFSET: 0x0074BCC0 // FUNCTION: fn_07871 -bool BitmapImage::DecodeJpeg(const void* data, int bytes, IJL15Runtime& runtime) { +bool BitmapImage::DecodeJpeg(const void* data, int bytes) { IJL15Properties properties = {}; - if (runtime.initialize(&properties) != 0) { + if (ijlInit(&properties) != 0) { return false; } @@ -15,7 +15,7 @@ bool BitmapImage::DecodeJpeg(const void* data, int bytes, IJL15Runtime& runtime) properties.jpegSize = bytes; unsigned char* source; - if (runtime.read(&properties, 1) == 0) { + if (ijlRead(&properties, 1) == 0) { this->width = properties.jpegWidth; this->height = properties.jpegHeight; const std::uint32_t count = static_cast(this->width) * static_cast(this->height); @@ -28,7 +28,7 @@ bool BitmapImage::DecodeJpeg(const void* data, int bytes, IJL15Runtime& runtime) properties.dibChannels = 3; properties.dibPadding = 0; - if (runtime.read(&properties, 3) != 0) { + if (ijlRead(&properties, 3) != 0) { std::free(source); std::free(this->pixels); this->pixels = nullptr; @@ -39,7 +39,7 @@ bool BitmapImage::DecodeJpeg(const void* data, int bytes, IJL15Runtime& runtime) source = reinterpret_cast(this); } - runtime.release(&properties); + ijlFree(&properties); for (int y = 0; y < this->height; ++y) { const unsigned char* input = source + 3u * (static_cast(y) * this->width); diff --git a/Source/Resource/Bitmap/BitmapResource.cpp b/Source/Resource/Bitmap/BitmapResource.cpp index 566f11b1..078a478e 100644 --- a/Source/Resource/Bitmap/BitmapResource.cpp +++ b/Source/Resource/Bitmap/BitmapResource.cpp @@ -1,37 +1,35 @@ #include "Client/Application/ErrorDialog.h" +#include "File/File.h" +#include "Render/DeviceContext/DCSurface.h" #include "Resource/Bitmap/BitmapResource.h" #include #include -// OFFSET: 0x00749580 -// FUNCTION: fn_07861 -CBitmapRes::CBitmapRes(BitmapResourceContext& context) : m_context(&context) { -} - // INLINED CBitmapRes::~CBitmapRes() = default; // OFFSET: 0x00749580 // FUNCTION: fn_07847 CBitmapRes* CBitmapRes::Create() { - return new CBitmapRes(*this->m_context); + return new CBitmapRes; } // OFFSET: 0x00749630 // FUNCTION: fn_07848 bool CBitmapRes::Load(const char* name) { + CFile file; bool result = false; - if (name && this->m_context->file.Open(name)) { - if (this->Decode(name, this->m_context->file.Data(), this->m_context->file.Size(), false)) { - this->m_context->file.Close(); + if (name && file.Open(name, 0, true, false)) { + if (this->Decode(name, file.GetData(), file.GetSize(), false)) { + file.Close(); result = true; } else { - this->m_context->file.Close(); + file.Close(); } } - this->m_context->file.Close(); + file.Close(); return result; } @@ -58,13 +56,13 @@ bool CBitmapRes::Decode(const char* name, const void* data, int bytes, bool icon } if (lstrcmpiA(extension, ".jpg") == 0) { - return this->image.DecodeJpeg(data, bytes, this->m_context->jpeg); + return this->image.DecodeJpeg(data, bytes); } if (lstrcmpiA(extension, ".png") == 0) { return this->image.DecodePng(data, bytes, name); } - ShowErrorDialog(this->m_context->renderSystem, "Unsupport fileformat!", 0); + ShowErrorDialog(GetRenderSystemHolder()->system, "Unsupport fileformat!", 0); return false; } diff --git a/Source/Resource/Bitmap/BitmapResource.h b/Source/Resource/Bitmap/BitmapResource.h index 5aa69d91..6da053f2 100644 --- a/Source/Resource/Bitmap/BitmapResource.h +++ b/Source/Resource/Bitmap/BitmapResource.h @@ -6,8 +6,6 @@ #include -class IJL15Runtime; - class ResourceBytes { public: virtual bool Open(const char* name) = 0; @@ -19,34 +17,20 @@ protected: ~ResourceBytes() = default; }; -struct BitmapResourceContext { - ResourceBytes& file; - IJL15Runtime& jpeg; - CRenderSystemBase* renderSystem; -}; - class CBitmapRes : public CRes { public: CBitmapRes(); - explicit CBitmapRes(BitmapResourceContext& context); ~CBitmapRes() override; CBitmapRes* Create() override; bool Load(const char* name) override; void Unload() override; virtual bool Decode(const char* name, const void* data, int bytes, bool iconOnly); - // INLINED - BitmapResourceContext& Context() const { - return *this->m_context; - } /* 0110 */ BitmapImage image; - -protected: - BitmapResourceContext* m_context; }; #if defined(_WIN32) && !defined(_WIN64) -static_assert(sizeof(CBitmapRes) == 296); +static_assert(sizeof(CBitmapRes) == 292); static_assert(offsetof(CBitmapRes, image) == 0x0110); #endif diff --git a/Source/Resource/Bitmap/IJL15Runtime.h b/Source/Resource/Bitmap/IJL15Runtime.h index a035a974..105ee42c 100644 --- a/Source/Resource/Bitmap/IJL15Runtime.h +++ b/Source/Resource/Bitmap/IJL15Runtime.h @@ -30,6 +30,12 @@ struct IJL15Properties { alignas(8) unsigned char privateProperties[19984]; }; +extern "C" { +__declspec(dllimport) int __stdcall ijlInit(IJL15Properties* properties); +__declspec(dllimport) int __stdcall ijlRead(IJL15Properties* properties, int operation); +__declspec(dllimport) int __stdcall ijlFree(IJL15Properties* properties); +} + class IJL15Runtime { public: IJL15Runtime(); diff --git a/Source/Resource/EmblemResource.cpp b/Source/Resource/EmblemResource.cpp index 7f108877..d9a6f430 100644 --- a/Source/Resource/EmblemResource.cpp +++ b/Source/Resource/EmblemResource.cpp @@ -16,17 +16,13 @@ namespace { } } -// INLINED -CEmblemRes::CEmblemRes(BitmapResourceContext& context) : gif(context) { -} - // INLINED CEmblemRes::~CEmblemRes() = default; // OFFSET: 0x0074C9F0 // FUNCTION: fn_07880 CEmblemRes* CEmblemRes::Create() { - return new CEmblemRes(this->gif.Context()); + return new CEmblemRes; } // OFFSET: 0x0074CA90 diff --git a/Source/Resource/EmblemResource.h b/Source/Resource/EmblemResource.h index fef8bc2e..cd47d3b4 100644 --- a/Source/Resource/EmblemResource.h +++ b/Source/Resource/EmblemResource.h @@ -7,7 +7,6 @@ class CEmblemRes : public CRes { public: CEmblemRes(); - explicit CEmblemRes(BitmapResourceContext& context); ~CEmblemRes() override; void Slot02() override; bool IsTransient() override; diff --git a/Source/Resource/GifResource.cpp b/Source/Resource/GifResource.cpp index 85e45680..abc9bf09 100644 --- a/Source/Resource/GifResource.cpp +++ b/Source/Resource/GifResource.cpp @@ -52,7 +52,8 @@ namespace { } } -// INLINED +// OFFSET: 0x0074A1D0 +// FUNCTION: fn_07861 CBitmapRes::CBitmapRes() { } @@ -61,18 +62,13 @@ CBitmapRes::CBitmapRes() { CGifRes::CGifRes() : loopCount(0), unknown_0132(0), currentFrame(0), lastFrameTime(0), animated(false), frameChanged(false) { } -// INLINED -CGifRes::CGifRes(BitmapResourceContext& context) - : CBitmapRes(context), loopCount(0), unknown_0132(0), currentFrame(0), lastFrameTime(0), animated(false), frameChanged(false) { -} - // INLINED CGifRes::~CGifRes() = default; // OFFSET: 0x00749910 // FUNCTION: fn_07852 CGifRes* CGifRes::Create() { - return new CGifRes(*this->m_context); + return new CGifRes; } // OFFSET: 0x00749A10 diff --git a/Source/Resource/GifResource.h b/Source/Resource/GifResource.h index b8174bb1..1630de71 100644 --- a/Source/Resource/GifResource.h +++ b/Source/Resource/GifResource.h @@ -13,7 +13,6 @@ public: using Frame = std::pair; CGifRes(); - explicit CGifRes(BitmapResourceContext& context); ~CGifRes() override; void Slot02() override; bool IsTransient() override; diff --git a/Source/Resource/Models/AnimatedModelResource.cpp b/Source/Resource/Models/AnimatedModelResource.cpp index 1266fc14..b66233cb 100644 --- a/Source/Resource/Models/AnimatedModelResource.cpp +++ b/Source/Resource/Models/AnimatedModelResource.cpp @@ -54,9 +54,9 @@ AnimatedModelNode::~AnimatedModelNode() { // OFFSET: 0x007550E0 // FUNCTION: fn_07979 -C3dAnimModelRes::C3dAnimModelRes(ModelResourceContext& context) +C3dAnimModelRes::C3dAnimModelRes() : unknown_0110(0), unknown_0114(nullptr), shade(2), frameCount(0), animationLength(0), speed(1.0f), unknown_0150(0), unknown_0154(0.0f), unknown_0158(0.0f), - unknown_015C(0.0f), alpha(255), m_context(&context) { + unknown_015C(0.0f), alpha(255) { } // OFFSET: 0x00756480 @@ -68,7 +68,7 @@ C3dAnimModelRes::~C3dAnimModelRes() { // OFFSET: 0x007521F0 // FUNCTION: fn_07956 C3dAnimModelRes* C3dAnimModelRes::Create() { - return new C3dAnimModelRes(*this->m_context); + return new C3dAnimModelRes; } // OFFSET: 0x00752380 @@ -91,14 +91,14 @@ void C3dAnimModelRes::Unload() { // OFFSET: 0x00752390 // FUNCTION: fn_07958 bool C3dAnimModelRes::Load(const char* name) { - auto& file = this->m_context->file; + CFile file; - if (!file.Open(name)) { + if (!file.Open(name, 0, true, false)) { file.Close(); return false; } - ResourceByteReader input{static_cast(file.Data()), static_cast(file.Size())}; + ResourceByteReader input{static_cast(file.GetData()), static_cast(file.GetSize())}; char magic[5]; unsigned char major; unsigned char minor; @@ -144,7 +144,7 @@ bool C3dAnimModelRes::Load(const char* name) { input.Read(&marker, 4); if (marker != 0x12345678u) { - ShowErrorDialog(this->m_context->renderSystem, "data corrupt", 0); + ShowErrorDialog(GetRenderSystemHolder()->system, "data corrupt", 0); file.Close(); return false; } @@ -194,7 +194,7 @@ bool C3dAnimModelRes::Load(const char* name) { input.Read(&marker, 4); if (marker != 0x12345678u) { - ShowErrorDialog(this->m_context->renderSystem, "data corrupt", 0); + ShowErrorDialog(GetRenderSystemHolder()->system, "data corrupt", 0); file.Close(); return false; } @@ -253,21 +253,10 @@ C3dGrannyModelRes::C3dGrannyModelRes() { this->unknown_03B0 = 0; } -// INLINED -C3dGrannyModelRes::C3dGrannyModelRes(ModelResourceContext& context) : m_context(&context) { - this->position[0] = 0.0f; - this->position[1] = 0.0f; - this->position[2] = 0.0f; - this->instance = nullptr; - this->model = nullptr; - this->job = 0; - this->unknown_03B0 = 0; -} - // OFFSET: 0x00753540 // FUNCTION: fn_07961 C3dGrannyModelRes* C3dGrannyModelRes::Create() { - return new C3dGrannyModelRes(*this->m_context); + return new C3dGrannyModelRes; } // OFFSET: 0x00753620 diff --git a/Source/Resource/Models/AnimatedModelResource.h b/Source/Resource/Models/AnimatedModelResource.h index 2e50c682..eed4355a 100644 --- a/Source/Resource/Models/AnimatedModelResource.h +++ b/Source/Resource/Models/AnimatedModelResource.h @@ -57,7 +57,7 @@ private: class C3dAnimModelRes : public CRes { public: - explicit C3dAnimModelRes(ModelResourceContext& context); + C3dAnimModelRes(); ~C3dAnimModelRes() override; C3dAnimModelRes* Create() override; bool Load(const char* name) override; @@ -77,9 +77,6 @@ public: /* 0158 */ float unknown_0158; /* 015C */ float unknown_015C; /* 0160 */ std::uint32_t alpha; - -private: - ModelResourceContext* m_context; }; static_assert(sizeof(AnimatedModelFace) == 24); diff --git a/Source/Resource/Models/GrannyModelResource.h b/Source/Resource/Models/GrannyModelResource.h index dd815b05..bb7701c9 100644 --- a/Source/Resource/Models/GrannyModelResource.h +++ b/Source/Resource/Models/GrannyModelResource.h @@ -221,7 +221,6 @@ struct GrannyHairPivot { class C3dGrannyModelRes : public CRes { public: C3dGrannyModelRes(); - explicit C3dGrannyModelRes(ModelResourceContext& context); C3dGrannyModelRes* Create() override; bool Load(const char* name) override; void RebindMeshes(const C3dGrannyModelRes& target); @@ -265,9 +264,6 @@ public: /* 03AC */ unsigned job; /* 03B0 */ GrannyHairPivot* unknown_03B0; /* 03B4 */ granny_skeleton* skeleton; - -private: - ModelResourceContext* m_context; }; extern GrannyAnimationLibrary g_grannyAnimationLibrary; diff --git a/Source/Resource/Models/ModelResource.cpp b/Source/Resource/Models/ModelResource.cpp index d8a53616..35a526ee 100644 --- a/Source/Resource/Models/ModelResource.cpp +++ b/Source/Resource/Models/ModelResource.cpp @@ -80,7 +80,7 @@ ModelNodeV2::~ModelNodeV2() = default; // OFFSET: 0x007553E0 // FUNCTION: fn_07982 -C3dModelRes::C3dModelRes(ModelResourceContext& context) : major(0), shade(0), alpha(255), m_context(&context) { +C3dModelRes::C3dModelRes() : major(0), shade(0), alpha(255) { } // OFFSET: 0x007567B0 @@ -89,7 +89,7 @@ C3dModelRes::~C3dModelRes() = default; // OFFSET: 0x00755560 // FUNCTION: fn_07983 -C3dModelResV1::C3dModelResV1(ModelResourceContext& context) : C3dModelRes(context), animationLength(0) { +C3dModelResV1::C3dModelResV1() : animationLength(0) { } // INLINED @@ -98,7 +98,7 @@ C3dModelResV1::~C3dModelResV1() = default; // OFFSET: 0x00750A70 // FUNCTION: fn_07949 C3dModelResV1* C3dModelResV1::Create() { - return new C3dModelResV1(*this->m_context); + return new C3dModelResV1; } // OFFSET: 0x007593C0 @@ -231,20 +231,20 @@ inline void C3dModelResV1::ReadNode(ResourceByteReader& input, unsigned minor, c // OFFSET: 0x00750B10 // FUNCTION: fn_07950 bool C3dModelResV1::Load(const char* name) { - auto& file = this->m_context->file; + CFile file; - if (!file.Open(name)) { + if (!file.Open(name, 0, true, false)) { file.Close(); return false; } - ResourceByteReader input{static_cast(file.Data()), static_cast(file.Size())}; + ResourceByteReader input{static_cast(file.GetData()), static_cast(file.GetSize())}; char magic[5]{}; input.Read(magic, 4); if (std::strcmp(magic, "GRSM") != 0) { constexpr char message[] = "모델파일이 아닙니다. 형식을 다시한번 확인해주세요."; - ShowErrorDialog(this->m_context->renderSystem, message, 0); + ShowErrorDialog(GetRenderSystemHolder()->system, message, 0); file.Close(); return false; @@ -258,7 +258,7 @@ bool C3dModelResV1::Load(const char* name) { if (major != 1 || minor > 5) { constexpr char message[] = "지원되지 않는 버젼입니다. 내용물이 깨져있을 수 있습니다"; - ShowErrorDialog(this->m_context->renderSystem, message, 0); + ShowErrorDialog(GetRenderSystemHolder()->system, message, 0); file.Close(); return false; @@ -383,7 +383,7 @@ void C3dGrannyModelRes::InstantiateModel(GrannyModelInstance* target, const gran entry.deformer = GrannyNewMeshDeformer(GrannyGetMeshVertexType(mesh), GrannyPNT332VertexType, 2); if (!entry.deformer) { - ShowErrorDialog(this->m_context->renderSystem, "Granny didn't find a matching deformer for the vertex format used by mesh", 0); + ShowErrorDialog(GetRenderSystemHolder()->system, "Granny didn't find a matching deformer for the vertex format used by mesh", 0); } } else { entry.vertices = new unsigned char[vertexBytes]; diff --git a/Source/Resource/Models/ModelResource.h b/Source/Resource/Models/ModelResource.h index f6b351f2..6f739dd3 100644 --- a/Source/Resource/Models/ModelResource.h +++ b/Source/Resource/Models/ModelResource.h @@ -91,15 +91,10 @@ public: /* 00AC */ std::map textureKeys; }; -struct ModelResourceContext { - ResourceBytes& file; - CRenderSystemBase*& renderSystem; -}; - class C3dModelRes : public CRes { friend class ModelNode; public: - explicit C3dModelRes(ModelResourceContext& context); + C3dModelRes(); ~C3dModelRes() override; bool Load(const char* name) override; void Unload() override; @@ -117,13 +112,11 @@ public: /* 0150 */ unsigned char alpha; /* 0154 */ std::list movieNames; -protected: - ModelResourceContext* m_context; }; class C3dModelResV1 : public C3dModelRes { public: - explicit C3dModelResV1(ModelResourceContext& context); + C3dModelResV1(); ~C3dModelResV1() override; C3dModelResV1* Create() override; bool Load(const char* name) override; @@ -135,7 +128,7 @@ private: class C3dModelResV2 : public C3dModelRes { public: - explicit C3dModelResV2(ModelResourceContext& context); + C3dModelResV2(); ~C3dModelResV2() override; C3dModelResV2* Create() override; bool Load(const char* name) override; diff --git a/Source/Resource/Models/ModelResourceV2.cpp b/Source/Resource/Models/ModelResourceV2.cpp index 11762067..8e0b2197 100644 --- a/Source/Resource/Models/ModelResourceV2.cpp +++ b/Source/Resource/Models/ModelResourceV2.cpp @@ -1,3 +1,5 @@ +#include "Render/DeviceContext/DCSurface.h" +#include "File/File.h" #include "Client/Application/ErrorDialog.h" #include "Render/Textures/Texture.h" #include "Render/Textures/TextureCache.h" @@ -29,7 +31,7 @@ namespace { // OFFSET: 0x007555C0 // FUNCTION: fn_07984 -C3dModelResV2::C3dModelResV2(ModelResourceContext& context) : C3dModelRes(context), framesPerSecond(0.0f), animationLength(0) { +C3dModelResV2::C3dModelResV2() : framesPerSecond(0.0f), animationLength(0) { } // INLINED @@ -38,7 +40,7 @@ C3dModelResV2::~C3dModelResV2() = default; // OFFSET: 0x00751ED0 // FUNCTION: fn_07953 C3dModelResV2* C3dModelResV2::Create() { - return new C3dModelResV2(*this->m_context); + return new C3dModelResV2; } // INLINED @@ -55,20 +57,20 @@ inline void C3dModelResV2::ReadVersion(ResourceByteReader& input, unsigned minor // OFFSET: 0x00751F70 // FUNCTION: fn_07954 bool C3dModelResV2::Load(const char* name) { - auto& file = this->m_context->file; + CFile file; - if (!file.Open(name)) { + if (!file.Open(name, 0, true, false)) { file.Close(); return false; } - ResourceByteReader input{static_cast(file.Data()), static_cast(file.Size())}; + ResourceByteReader input{static_cast(file.GetData()), static_cast(file.GetSize())}; char magic[5]{}; input.Read(magic, 4); if (std::strcmp(magic, "GRSM") != 0) { constexpr char message[] = "모델파일이 아닙니다. 형식을 다시한번 확인해주세요."; - ShowErrorDialog(this->m_context->renderSystem, message, 0); + ShowErrorDialog(GetRenderSystemHolder()->system, message, 0); file.Close(); return false; diff --git a/Source/Resource/Sprites/ActionResource.cpp b/Source/Resource/Sprites/ActionResource.cpp index 6c2f2c88..3080b591 100644 --- a/Source/Resource/Sprites/ActionResource.cpp +++ b/Source/Resource/Sprites/ActionResource.cpp @@ -1,4 +1,6 @@ #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" @@ -20,40 +22,31 @@ namespace { } } -// OFFSET: 0x007436B0 -// FUNCTION: fn_07767 -CActRes::CActRes(ActionResourceContext& context) : maximumCells(0), m_context(&context) { +// INLINED +CActRes::CActRes() : maximumCells(0) { } -// INLINED +// OFFSET: 0x00745FB0 +// FUNCTION: fn_07767 CActRes::~CActRes() = default; // OFFSET: 0x007436B0 // FUNCTION: fn_07749 CActRes* CActRes::Create() { - return new CActRes(*this->m_context); + return new CActRes; } // OFFSET: 0x007437B0 // FUNCTION: fn_07750 bool CActRes::Load(const char* name) { - auto& context = *this->m_context; - auto& file = context.file; - struct CloseFile { - ResourceBytes& file; - - ~CloseFile() { - file.Close(); - } - } close{file}; - - if (!file.Open(name)) { + CFile file; + if (!file.Open(name, 0, true, false)) { const std::string message = std::string("Cannot find File : ") + name; - ShowErrorDialog(context.renderSystem, message.c_str(), 0); + ShowErrorDialog(GetRenderSystemHolder()->system, message.c_str(), 0); return false; } - ResourceByteReader input{static_cast(file.Data()), static_cast(file.Size())}; + ResourceByteReader input{static_cast(file.GetData()), static_cast(file.GetSize())}; struct Header { std::uint16_t magic; std::uint16_t version; @@ -63,8 +56,8 @@ bool CActRes::Load(const char* name) { input.Read(&header, sizeof(header)); if (header.magic != 0x4341) { - ShowErrorDialog(context.renderSystem, "Illegal file format", 0); - ShowErrorDialog(context.renderSystem, name, 0); + ShowErrorDialog(GetRenderSystemHolder()->system, "Illegal file format", 0); + ShowErrorDialog(GetRenderSystemHolder()->system, name, 0); file.Close(); return false; @@ -75,7 +68,7 @@ bool CActRes::Load(const char* name) { spriteName.append(".spr", 4); if (header.version > 0x0205) { - ShowErrorDialog(context.renderSystem, "Unsupported Version. Content may be corrupted", 0); + ShowErrorDialog(GetRenderSystemHolder()->system, "Unsupported Version. Content may be corrupted", 0); file.Close(); return false; } @@ -141,7 +134,7 @@ bool CActRes::Load(const char* name) { cell.y = RelativeCoordinate(cell.y, height, cell.scaleY); } } else if (cell.image != -1) { - auto* sprite = static_cast(context.resources.Load(spriteName.c_str())); + auto* sprite = static_cast(ResourceMgr::Instance().Load(spriteName.c_str())); if (sprite) { const SpriteRleImage* image = sprite->images[cell.imageType][cell.image]; diff --git a/Source/Resource/Sprites/ActionResource.h b/Source/Resource/Sprites/ActionResource.h index 8fd99e9b..e1ff3d29 100644 --- a/Source/Resource/Sprites/ActionResource.h +++ b/Source/Resource/Sprites/ActionResource.h @@ -28,15 +28,9 @@ struct ActionFrame { const SpriteFrameCell& Cell(unsigned index) const; }; -struct ActionResourceContext { - ResourceBytes& file; - ResourceMgr& resources; - CRenderSystemBase*& renderSystem; -}; - class CActRes : public CRes { public: - explicit CActRes(ActionResourceContext& context); + CActRes(); ~CActRes() override; CActRes* Create() override; bool Load(const char* name) override; @@ -52,14 +46,12 @@ public: /* 0120 */ std::vector sounds; /* 012C */ std::vector speeds; -private: - ActionResourceContext* m_context; }; static_assert(sizeof(ActionAnchor) == 12); #if defined(_WIN32) && !defined(_WIN64) static_assert(sizeof(ActionFrame) == 68); -static_assert(sizeof(CActRes) == 316); +static_assert(sizeof(CActRes) == 312); static_assert(offsetof(ActionAnchor, y) == 0x0004); static_assert(offsetof(ActionAnchor, unknown_0008) == 0x0008); static_assert(offsetof(ActionFrame, cells) == 0x0020); diff --git a/Source/Resource/Sprites/SpriteResource.cpp b/Source/Resource/Sprites/SpriteResource.cpp index 432bab76..ad0a8bb4 100644 --- a/Source/Resource/Sprites/SpriteResource.cpp +++ b/Source/Resource/Sprites/SpriteResource.cpp @@ -1,48 +1,43 @@ #include "Client/Application/ErrorDialog.h" +#include "File/File.h" #include "Render/RenderSystemBase.h" #include "Render/Textures/Texture.h" #include "Resource/Bitmap/BitmapResource.h" #include "Resource/ResourceByteReader.h" #include "Resource/Sprites/SpriteResource.h" +#include "Render/DeviceContext/DCSurface.h" +#include "Render/Textures/TextureCache.h" +#include "Resource/ResourcePreload.h" #include #include #include -// OFFSET: 0x0075FE90 -// FUNCTION: fn_08060 -CSprRes::CSprRes(SpriteResourceContext& context) : indexedCount(0), m_context(&context) { +// INLINED +CSprRes::CSprRes() : indexedCount(0) { } -// INLINED +// OFFSET: 0x00760F50 +// FUNCTION: fn_08060 CSprRes::~CSprRes() = default; // OFFSET: 0x0075FE90 // FUNCTION: fn_08053 CSprRes* CSprRes::Create() { - return new CSprRes(*this->m_context); + return new CSprRes; } // OFFSET: 0x0075FF40 // FUNCTION: fn_08054 bool CSprRes::Load(const char* name) { - auto& context = *this->m_context; - auto& file = context.file; - struct CloseFile { - ResourceBytes& file; - - ~CloseFile() { - file.Close(); - } - } close{file}; - - if (!file.Open(name)) { + CFile file; + if (!file.Open(name, 0, true, false)) { const std::string message = std::string("Spr :: Cannot find File : ") + name; - ShowErrorDialog(context.renderSystem, message.c_str(), 0); + ShowErrorDialog(GetRenderSystemHolder()->system, message.c_str(), 0); return false; } - ResourceByteReader input{static_cast(file.Data()), static_cast(file.Size())}; + ResourceByteReader input{static_cast(file.GetData()), static_cast(file.GetSize())}; struct Header { std::uint16_t magic; std::uint16_t version; @@ -51,13 +46,13 @@ bool CSprRes::Load(const char* name) { input.Read(&header, sizeof(header)); if (header.magic != 0x5053) { - ShowErrorDialog(context.renderSystem, "Illegal File Format", 0); - ShowErrorDialog(context.renderSystem, name, 0); + ShowErrorDialog(GetRenderSystemHolder()->system, "Illegal File Format", 0); + ShowErrorDialog(GetRenderSystemHolder()->system, name, 0); return false; } if (header.version > 0x0201) { - ShowErrorDialog(context.renderSystem, "Unsupported Version. Content may be corrupted", 0); + ShowErrorDialog(GetRenderSystemHolder()->system, "Unsupported Version. Content may be corrupted", 0); return false; } @@ -85,7 +80,7 @@ bool CSprRes::Load(const char* name) { image->height = static_cast(dimensions[1]); std::uint16_t encodedBytes; - if (context.halfWidth == 0 && context.halfHeight == 0) { + if (g_spriteHalfWidth == 0 && g_spriteHalfHeight == 0) { if (header.version < 0x0201) { const int count = image->width * image->height; auto* pixels = static_cast(::operator new(count)); @@ -133,17 +128,17 @@ bool CSprRes::Load(const char* name) { input.Read(pixels, count); } - auto* reduced = ReduceSprite(pixels, dimensions[0], dimensions[1], context.halfWidth, context.halfHeight); + auto* reduced = ReduceSprite(pixels, dimensions[0], dimensions[1], g_spriteHalfWidth, g_spriteHalfHeight); std::free(pixels); - image->runs = EncodeSpriteRuns(reduced, dimensions[0] / (context.halfWidth + 1), dimensions[1] / (context.halfHeight + 1), encodedBytes); + image->runs = EncodeSpriteRuns(reduced, dimensions[0] / (g_spriteHalfWidth + 1), dimensions[1] / (g_spriteHalfHeight + 1), encodedBytes); std::free(reduced); - if (context.halfWidth != 0) { + if (g_spriteHalfWidth != 0) { image->width /= 2; image->unknown_0004 = 1; } - if (context.halfHeight != 0) { + if (g_spriteHalfHeight != 0) { image->height /= 2; image->unknown_0006 = 1; } @@ -169,19 +164,19 @@ bool CSprRes::Load(const char* name) { } } - const int width = context.halfWidth != 0 ? image->width / 2 : image->width; - const int height = context.halfHeight != 0 ? image->height / 2 : image->height; - CTexture* texture = context.renderSystem ? context.renderSystem->CreateTexture(width, height, TextureFormat::A4R4G4B4, false, false) : nullptr; + const int width = g_spriteHalfWidth != 0 ? image->width / 2 : image->width; + const int height = g_spriteHalfHeight != 0 ? image->height / 2 : image->height; + CTexture* texture = CreateTexture(width, height, TextureFormat::A4R4G4B4, false, false); image->unknown_0008 = texture; texture->Upload(0, 0, image->width, image->height, pixels, 0, 0); std::free(pixels); - if (context.halfWidth != 0) { + if (g_spriteHalfWidth != 0) { image->width /= 2; image->unknown_0004 = 1; } - if (context.halfHeight != 0) { + if (g_spriteHalfHeight != 0) { image->height /= 2; image->unknown_0006 = 1; } diff --git a/Source/Resource/Sprites/SpriteResource.h b/Source/Resource/Sprites/SpriteResource.h index dbd53d06..9196d6c8 100644 --- a/Source/Resource/Sprites/SpriteResource.h +++ b/Source/Resource/Sprites/SpriteResource.h @@ -8,16 +8,9 @@ class ResourceBytes; -struct SpriteResourceContext { - ResourceBytes& file; - CRenderSystemBase*& renderSystem; - const int& halfWidth; - const int& halfHeight; -}; - class CSprRes : public CRes { public: - explicit CSprRes(SpriteResourceContext& context); + CSprRes(); ~CSprRes() override; CSprRes* Create() override; bool Load(const char* name) override; @@ -27,8 +20,6 @@ public: /* 0510 */ std::vector images[2]; /* 0528 */ int indexedCount; -private: - SpriteResourceContext* m_context; }; std::uint8_t* EncodeSpriteRuns(const std::uint8_t* pixels, int width, int height, std::uint16_t& bytes); @@ -36,7 +27,7 @@ std::uint8_t* ReduceSprite(const std::uint8_t* pixels, int width, int height, in void ConvertSpritePalette(std::uint32_t* output, const std::uint8_t* input, int count); #if defined(_WIN32) && !defined(_WIN64) -static_assert(sizeof(CSprRes) == 1328); +static_assert(sizeof(CSprRes) == 1324); static_assert(sizeof(SpriteRleImage) == 16); #endif diff --git a/Source/UI/Buttons/UIBmpRadioBtn.cpp b/Source/UI/Buttons/UIBmpRadioBtn.cpp index 2b50311e..8d221f79 100644 --- a/Source/UI/Buttons/UIBmpRadioBtn.cpp +++ b/Source/UI/Buttons/UIBmpRadioBtn.cpp @@ -12,8 +12,7 @@ UIBmpRadioBtn::UIBmpRadioBtn() : UIWindow(0) { // OFFSET: 0x0086C720 // FUNCTION: fn_11029 -UICaptchaImage::UICaptchaImage(BitmapResourceContext& bitmaps) - : UIWindow(0), m_bitmap(bitmaps) { +UICaptchaImage::UICaptchaImage() : UIWindow(0) { } // OFFSET: 0x00870390 diff --git a/Source/UI/Buttons/UIBmpRadioBtn.h b/Source/UI/Buttons/UIBmpRadioBtn.h index e624a2dc..d2c717db 100644 --- a/Source/UI/Buttons/UIBmpRadioBtn.h +++ b/Source/UI/Buttons/UIBmpRadioBtn.h @@ -58,7 +58,6 @@ public: class UICaptchaImage : public UIWindow { public: UICaptchaImage(); - UICaptchaImage(BitmapResourceContext& bitmaps); ~UICaptchaImage() override; void Paint() override; void Slot28(int x, int y) override;