From 2a32d07c242e6e999bed517915fe8384ca88538b Mon Sep 17 00:00:00 2001 From: "Nasir W." <116527368+nasiratif@users.noreply.github.com> Date: Wed, 8 Apr 2026 21:41:25 -0400 Subject: [PATCH 1/3] DarkEdif: CFile fixes CFile was using unsigned int in places that should be unsigned long. --- DarkEdif/Inc/Windows/CFile.hpp | 56 +++++++++---------- .../Inc/Windows/MMFWindowsMasterHeader.hpp | 26 ++++----- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/DarkEdif/Inc/Windows/CFile.hpp b/DarkEdif/Inc/Windows/CFile.hpp index f77cf994..7596e5ac 100644 --- a/DarkEdif/Inc/Windows/CFile.hpp +++ b/DarkEdif/Inc/Windows/CFile.hpp @@ -18,16 +18,16 @@ enum class CFCERROR { FusionAPIImport HFILE FusionAPI File_OpenA(const char * fname, int mode); FusionAPIImport HFILE FusionAPI File_CreateA(const char * fname); -FusionAPIImport int FusionAPI File_Read(HFILE hf, void * buf, unsigned int len); -FusionAPIImport int FusionAPI File_ReadAndCount(HFILE hf, void * buf, unsigned int len); +FusionAPIImport int FusionAPI File_Read(HFILE hf, void * buf, DWORD len); +FusionAPIImport int FusionAPI File_ReadAndCount(HFILE hf, void * buf, DWORD len); FusionAPIImport int FusionAPI File_ReadShortIntelData(HFILE hf, void ** pBuf); FusionAPIImport int FusionAPI File_ReadShortIntelString(HFILE hf, void ** pBuf); FusionAPIImport int FusionAPI File_ReadLongIntelData(HFILE hf, void ** pBuf); -FusionAPIImport int FusionAPI File_Write(HFILE hf, void * buf, unsigned int len); -FusionAPIImport unsigned int FusionAPI File_GetPosition(HFILE hf); -FusionAPIImport unsigned int FusionAPI File_SeekBegin(HFILE hf, long pos); -FusionAPIImport unsigned int FusionAPI File_SeekCurrent(HFILE hf, long pos); -FusionAPIImport unsigned int FusionAPI File_SeekEnd(HFILE hf, long pos); +FusionAPIImport int FusionAPI File_Write(HFILE hf, void * buf, DWORD len); +FusionAPIImport DWORD FusionAPI File_GetPosition(HFILE hf); +FusionAPIImport DWORD FusionAPI File_SeekBegin(HFILE hf, long pos); +FusionAPIImport DWORD FusionAPI File_SeekCurrent(HFILE hf, long pos); +FusionAPIImport DWORD FusionAPI File_SeekEnd(HFILE hf, long pos); FusionAPIImport long FusionAPI File_GetLength(HFILE hf); FusionAPIImport void FusionAPI File_Close(HFILE hf); FusionAPIImport BOOL FusionAPI File_ExistA(const char * pName); @@ -106,14 +106,14 @@ class FusionAPIImport CInputBufFile : public CInputFile static CInputBufFile * NewInstance(); int Create(HFILE hf); - int Create(HFILE hf, unsigned int dwOffset, unsigned int dwSize); + int Create(HFILE hf, DWORD dwOffset, DWORD dwSize); int Create(const char * filename); - int Create(const char * filename, unsigned int dwOffset, unsigned int dwSize); + int Create(const char * filename, DWORD dwOffset, DWORD dwSize); int Create(const UShortWCHAR * filename); - int Create(const UShortWCHAR * filename, unsigned int dwOffset, unsigned int dwSize); + int Create(const UShortWCHAR * filename, DWORD dwOffset, DWORD dwSize); - virtual int Read(unsigned char * dest, unsigned int lsize); - virtual int Read(unsigned char * dest, unsigned int lsize, LPDWORD pRead); + virtual int Read(unsigned char * dest, DWORD lsize); + virtual int Read(unsigned char * dest, DWORD lsize, LPDWORD pRead); virtual int ReadByte(unsigned char * dest); // virtual int ReadWord(LPWORD dest); // virtual int ReadDWord(LPDWORD dest); @@ -131,18 +131,18 @@ class FusionAPIImport CInputBufFile : public CInputFile virtual UShortWCHAR * GetFileNameW(); protected: - int Attach(HANDLE hnd, unsigned int dwOffset, unsigned int dwSize); + int Attach(HANDLE hnd, DWORD dwOffset, DWORD dwSize); private: HFILE m_hf; - unsigned int m_curpos; + DWORD m_curpos; unsigned char * m_buffer; unsigned char * m_bufcurr; - unsigned int m_remains; + DWORD m_remains; UShortWCHAR * m_fnameW; char * m_fnameA; - unsigned int m_startOffset; - unsigned int m_length; + DWORD m_startOffset; + DWORD m_length; }; typedef CInputBufFile * LPINPUTBUFFILE; @@ -182,8 +182,8 @@ class FusionAPIImport CInputMemFile : public CInputFile private: unsigned char * m_buffer; unsigned char * m_bufcurr; - unsigned int m_curpos; - unsigned int m_remains; + DWORD m_curpos; + DWORD m_remains; BOOL m_bAutoDelete; }; //typedef CInputMemFile * LPINPUTMEMFILE; @@ -206,7 +206,7 @@ class FusionAPIImport COutputFile virtual int Write(unsigned char * pb, UINT sz) = 0; virtual int Flush() = 0; - virtual unsigned int GetLength() = 0; + virtual DWORD GetLength() = 0; virtual long GetPosition() = 0; virtual long Seek(long pos, int method) = 0; @@ -224,14 +224,14 @@ class FusionAPIImport COutputMemFile : public COutputFile virtual ~COutputMemFile(); int Create(UINT nBlockSize = 512); - int Create(unsigned char * buffer, unsigned int nBufferSize = 0x7FFFFFF); + int Create(unsigned char * buffer, DWORD nBufferSize = 0x7FFFFFF); unsigned char * GetBuffer(); unsigned char * DetachBuffer(); static void FreeBuffer(unsigned char * pBuffer); // car il faut libérer à l'interieur de la DLL virtual int Write(unsigned char * pb, UINT sz); virtual int Flush(); - virtual unsigned int GetLength(); + virtual DWORD GetLength(); virtual long GetPosition(); virtual long Seek(long pos, int method); @@ -242,9 +242,9 @@ class FusionAPIImport COutputMemFile : public COutputFile private: unsigned char * m_buffer; unsigned char * m_curptr; - unsigned int m_totalsize; - unsigned int m_cursize; - unsigned int m_blocksize; + DWORD m_totalsize; + DWORD m_cursize; + DWORD m_blocksize; BOOL m_bReallocable; }; @@ -261,7 +261,7 @@ class FusionAPIImport COutputBufFile : public COutputFile virtual int Write(unsigned char * pb, UINT sz); virtual int Flush(); - virtual unsigned int GetLength(); + virtual DWORD GetLength(); virtual long GetPosition(); virtual long Seek(long pos, int method); @@ -274,8 +274,8 @@ class FusionAPIImport COutputBufFile : public COutputFile UShortWCHAR * m_fnameW; unsigned char * m_buffer; unsigned char * m_curptr; - unsigned int m_cursize; - unsigned int m_buffersize; + DWORD m_cursize; + DWORD m_buffersize; BOOL m_bBuffered; char * m_fnameA; }; diff --git a/DarkEdif/Inc/Windows/MMFWindowsMasterHeader.hpp b/DarkEdif/Inc/Windows/MMFWindowsMasterHeader.hpp index 9ab431af..48ac645a 100644 --- a/DarkEdif/Inc/Windows/MMFWindowsMasterHeader.hpp +++ b/DarkEdif/Inc/Windows/MMFWindowsMasterHeader.hpp @@ -4298,7 +4298,7 @@ struct mv { HPALETTE HPal256; // 256 color palette unsigned short AppMode, // Screen mode with flags ScrMode; // Screen mode (SM_8=256, SM_15=32768, SM_16=65536, SM_32=16 million colors) - unsigned int EditDXDocToClient, // Edit time only: top-left coordinates + DWORD EditDXDocToClient, // Edit time only: top-left coordinates EditDYDocToClient; CImageFilterMgr * ImgFilterMgr; // Image filter manager CSoundFilterMgr * SndFilterMgr; // Sound filter manager @@ -4315,7 +4315,7 @@ struct mv { // Runtime RunHeader * RunHdr; // Current RunHeader - unsigned int PextsHoldingGlobals; // Preferences (sound on/off) + DWORD PextsHoldingGlobals; // Preferences (sound on/off) TCHAR * subType; BOOL FullScreen; // Full screen mode TCHAR * MainAppFileName; // App filename @@ -4327,7 +4327,7 @@ struct mv { TCHAR ** ExtList; int NbDllTrans; dllTrans* DllTransList; - unsigned int JoyCaps[32]; + DWORD JoyCaps[32]; HHOOK HMsgHook; int ModalLoop; int ModalSubAppCount; @@ -4337,7 +4337,7 @@ struct mv { //////////// // Editor: Open Help file - void (CALLBACK * HelpA) (const char * pHelpFile, unsigned int nID, LPARAM lParam); + void (CALLBACK * HelpA) (const char * pHelpFile, DWORD nID, LPARAM lParam); // Editor: Get default font for object creation // pStyle can be NULL to ignore; cbSize is size of pStyle's buffer. @@ -4358,29 +4358,29 @@ struct mv { void (CALLBACK * UnregisterDialogBox) (HWND hDlg); // Runtime: Add surface as backdrop object - void (CALLBACK * AddBackdrop) (cSurface * pSf, int x, int y, unsigned int dwInkEffect, unsigned int dwInkEffectParam, int nObstacleType, int nLayer); + void (CALLBACK * AddBackdrop) (cSurface * pSf, int x, int y, DWORD dwInkEffect, DWORD dwInkEffectParam, int nObstacleType, int nLayer); // Runtime: Binary files - BOOL (CALLBACK * GetFileA)(const char * pPath, char * pFilePath, unsigned int dwFlags); + BOOL (CALLBACK * GetFileA)(const char * pPath, char * pFilePath, DWORD dwFlags); void (CALLBACK * ReleaseFileA)(const char * pPath); - HANDLE (CALLBACK * OpenHFileA)(const char * pPath, unsigned int * pDwSize, unsigned int dwFlags); + HANDLE (CALLBACK * OpenHFileA)(const char * pPath, DWORD * pDwSize, DWORD dwFlags); void (CALLBACK * CloseHFile)(HANDLE hf); // Plugin: download file int (CALLBACK * LoadNetFileA) (char * pFilename); // Plugin: send command to Vitalize - int (CALLBACK * NetCommandA) (int, void *, unsigned int, void *, unsigned int); + int (CALLBACK * NetCommandA) (int, void *, DWORD, void *, DWORD); // Editor & Runtime: Returns the version of MMF or of the runtime // Return is a bitmask of three different flag sets; MMFVERSION_MASK, MMFBUILD_MASK, MMFVERFLAG_MASK - unsigned int (CALLBACK * GetVersion) (); + DWORD (CALLBACK * GetVersion) (); // Editor & Runtime: callback function for properties or other functions LRESULT (CALLBACK * CallFunction) (EDITDATA * edPtr, CallFunctionIDs nFnc, LPARAM lParam1, LPARAM lParam2, LPARAM lParam3); // Editor: Open Help file (UNICODE) - void (CALLBACK * HelpW) (const wchar_t * pHelpFile, unsigned int nID, LPARAM lParam); + void (CALLBACK * HelpW) (const wchar_t * pHelpFile, DWORD nID, LPARAM lParam); // Editor: Get default font for object creation (UNICODE) // pStyle can be NULL to ignore; cbSize is size of pStyle's buffer in WCHARs. @@ -4392,15 +4392,15 @@ struct mv { BOOL (CALLBACK * EditAnimationW) (EDITDATA * edPtr, EditAnimationParamsW * Params, HWND Parent); // Runtime: Binary files (UNICODE) - BOOL (CALLBACK * GetFileW)(const wchar_t * pPath, wchar_t * pFilePath, unsigned int dwFlags); + BOOL (CALLBACK * GetFileW)(const wchar_t * pPath, wchar_t * pFilePath, DWORD dwFlags); void (CALLBACK * ReleaseFileW)(const wchar_t * pPath); - HANDLE (CALLBACK * OpenHFileW)(const wchar_t * pPath, unsigned int * pDwSize, unsigned int dwFlags); + HANDLE (CALLBACK * OpenHFileW)(const wchar_t * pPath, DWORD * pDwSize, DWORD dwFlags); // Plugin: download file int (CALLBACK * LoadNetFileW) (wchar_t * pFilename); // Plugin: send command to Vitalize - int (CALLBACK * NetCommandW) (int, void *, unsigned int, void *, unsigned int); + int (CALLBACK * NetCommandW) (int, void *, DWORD, void *, DWORD); // Place-holder for next versions void * AdditionalFncs[6]; From 01d3104212da2354c9e5b9ac197c8641d565f5eb Mon Sep 17 00:00:00 2001 From: "Nasir W." <116527368+nasiratif@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:35:27 -0400 Subject: [PATCH 2/3] DarkEdif: GetDependencies fix GetDependencies was incorrectly checking if already inited. --- DarkEdif/DarkEdif Template/DarkExt.json | 2 +- DarkEdif/Lib/Shared/Edif.General.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DarkEdif/DarkEdif Template/DarkExt.json b/DarkEdif/DarkEdif Template/DarkExt.json index eeefd454..3cb749d2 100644 --- a/DarkEdif/DarkEdif Template/DarkExt.json +++ b/DarkEdif/DarkEdif Template/DarkExt.json @@ -2,7 +2,7 @@ // 4-character identifer that uniquely identifies your extension. // Can be letters, numbers, or punctuation, but must be 4 ASCII characters. "Identifier": "EXMP", - "Dependencies": "", + "Dependencies": [ "" ], "UK English": { "About": { "Name": "DarkEdif Template", diff --git a/DarkEdif/Lib/Shared/Edif.General.cpp b/DarkEdif/Lib/Shared/Edif.General.cpp index 8f4cafd5..90f5ce78 100644 --- a/DarkEdif/Lib/Shared/Edif.General.cpp +++ b/DarkEdif/Lib/Shared/Edif.General.cpp @@ -107,7 +107,7 @@ const TCHAR ** FusionAPI GetDependencies() // This is pointed to by Dependencies. static TCHAR singleton[1024]; - if (!Dependencies) + if (!Dependencies[0]) { const json_value &DependenciesJSON = Edif::SDK->json["Dependencies"sv]; TCHAR* singletonPtr = singleton; From 186c25f328173aad209d9be4bc7820e33e4f2a97 Mon Sep 17 00:00:00 2001 From: Phi Date: Fri, 19 Jun 2026 23:20:09 +0100 Subject: [PATCH 3/3] DarkEdif: Expand GetDependencies Fleshing out GetDependencies to be a bit more robust after Nasir's fix. --- DarkEdif/Lib/Shared/Edif.General.cpp | 48 ++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/DarkEdif/Lib/Shared/Edif.General.cpp b/DarkEdif/Lib/Shared/Edif.General.cpp index 90f5ce78..3b3cadab 100644 --- a/DarkEdif/Lib/Shared/Edif.General.cpp +++ b/DarkEdif/Lib/Shared/Edif.General.cpp @@ -99,24 +99,29 @@ void FusionAPI UnloadObject(mv * mV, EDITDATA * edPtr, int reserved) } +// This is pointed to by Dependencies, as a stream of null-terminated TCHAR strings. +static TCHAR singleton[1024]; const TCHAR * Dependencies[32] = {}; const TCHAR ** FusionAPI GetDependencies() { #pragma DllExportHint - // This is pointed to by Dependencies. - static TCHAR singleton[1024]; - if (!Dependencies[0]) { + // CurLang shouldn't be used here; GetDependencies may be requested early const json_value &DependenciesJSON = Edif::SDK->json["Dependencies"sv]; + TCHAR* singletonPtr = singleton; std::size_t Offset = 0; + // If external JSON, add our own JSON to the requested list if (Edif::ExternalJSON) { - TCHAR JSONFilename [MAX_PATH]; + // We calculate filename live, assuming the MFX is being used like a dummy, + // and so we can't rely on the PROJECT_TARGET_NAME defines. + // +2 for the off chance of mfx being exactly MAX_PATH chars. + TCHAR JSONFilename [MAX_PATH + 2]; GetModuleFileName (hInstLib, JSONFilename, sizeof (JSONFilename) / sizeof(*JSONFilename)); @@ -134,21 +139,44 @@ const TCHAR ** FusionAPI GetDependencies() // We append it, then add a pointer to what we just appended // to our pointer list - _tcscpy(singletonPtr, ++Iterator); + _tcscpy_s(singletonPtr, std::size(singleton), ++Iterator); Dependencies[Offset++] = singletonPtr; singletonPtr += _tcslen(singletonPtr) + 1; } - for (unsigned int i = 0; i < DependenciesJSON.u.array.length; ++i) + // Add any other JSON dependencies, or abort + if (DependenciesJSON.type == json_none) + return Dependencies; + + std::tstring tstr; + if (DependenciesJSON.type == json_string) { - std::tstring tstr = DarkEdif::UTF8ToTString(DependenciesJSON[i]); + if (DependenciesJSON.u.string.length != 0) + { + tstr = DarkEdif::UTF8ToTString(DependenciesJSON); + _tcscpy_s(singletonPtr, std::size(singleton) - (singletonPtr - singleton), tstr.c_str()); + Dependencies[Offset++] = singletonPtr; + singletonPtr += _tcslen(singletonPtr) + 1; + } - _tcscpy(singletonPtr, tstr.c_str()); + return Dependencies; + } + + if (DependenciesJSON.type != json_array) + return DarkEdif::MsgBox::Error(_T("GetDependencies() error"), _T("DarkExt.json contains incorrect Dependencies type.")), nullptr; + + // Limit of 31 entries, as Dependencies must end with a null entry. + // If JSON will be inserted as dependency too, then limit is 30. + if (DependenciesJSON.u.array.length > std::size(Dependencies) - (Edif::ExternalJSON ? 2 : 1)) + return DarkEdif::MsgBox::Error(_T("GetDependencies() error"), _T("DarkExt.json contains too many dependencies.")), nullptr; + + for (unsigned int i = 0; i < DependenciesJSON.u.array.length; ++i) + { + tstr = DarkEdif::UTF8ToTString(DependenciesJSON[i]); + _tcscpy_s(singletonPtr, std::size(singleton) - (singletonPtr - singleton), tstr.c_str()); Dependencies[Offset++] = singletonPtr; singletonPtr += tstr.size() + 1; } - - Dependencies[Offset] = 0; } return Dependencies;