Files
LifeProject/LifeExport/LifeExport.cpp
T
2025-05-13 02:46:21 +03:00

163 lines
3.3 KiB
C++

// LifeExport.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "LifeExport.h"
#include "IGame/IGame.h"
#include "IGame/IGameObject.h"
#include <max.h>
//#include "IGame/IGameFX.h"
#include "3dsmaxport.h"
#include <stdio.h>
#include <string>
#define MYEXP_CLASS_ID Class_ID(0x6b1850ce, 0x77e51de8)
HMODULE hMod;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
hMod = hModule;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
class LifeExport : public SceneExport
{
public:
int ExtCount()
{
return 1;
}
const MCHAR * Ext(int n)
{
return _TEXT("vmf");
}
const MCHAR * LongDesc()
{
return _TEXT("LifeEngine export plugin");
}
const MCHAR * ShortDesc()
{
return _TEXT("LifeEngine export");
}
const MCHAR * AuthorName()
{
return _TEXT("Sergei Serb (L)");
}
const MCHAR * CopyrightMessage()
{
return _TEXT("Massive Dynamics (L)");
}
const MCHAR * OtherMessage1()
{
return _TEXT("trololo");
}
const MCHAR * OtherMessage2()
{
return _TEXT("trololo");
}
unsigned int Version()
{
return 1;
}
void ShowAbout(HWND hWnd)
{
}
int DoExport(const MCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts=FALSE, DWORD options=0)
{
typedef int (*ExportFunc)(const MCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options);
wchar_t dir[512];
GetModuleFileNameW(hMod, dir, sizeof(dir));
std::wstring srcPath(dir);
int pos = srcPath.find_last_of(_TEXT("/\\"));
std::wstring directory = srcPath.substr(0, pos);
directory += _TEXT("\\LifeExportInternal.dll");
HMODULE lib = LoadLibrary(directory.c_str());
std::string result = lib == 0 ? "Failed to load export DLL!" : "Succeeded to load export DLL!";
FILE* f = fopen("C:\\#export_root.txt", "wb");
char buf[512];
sprintf(buf, "\n\nResult: %s\n", result.c_str());
//fwrite(directory.c_str(), 1,directory.length(), f);
fwrite(buf, 1,strlen(buf), f);
if(lib)
{
ExportFunc func = (ExportFunc)GetProcAddress(lib, "DoExport");
sprintf(buf, "Try to get export func: %i\n", (func != 0));
fwrite(buf, 1,strlen(buf), f);
if(func != 0)
{
func(name, ei, i, suppressPrompts, options);
}
FreeLibrary(lib);
}
fclose(f);
return TRUE;
}
};
class MyPlugClassDesc : public ClassDesc
{
public:
int IsPublic() { return 1; }
void* Create(BOOL Loading = FALSE) { return new LifeExport(); }
const TCHAR * ClassName() { return _T("LifeExport"); }
SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; }
Class_ID ClassID() { return MYEXP_CLASS_ID; }
const TCHAR * Category() { return _T(""); }
};
static MyPlugClassDesc desc;
LIFEEXPORT_API const TCHAR* LibDescription()
{
return _TEXT("LifeEngine export plugin");
}
//TODO: Must change this number when adding a new class
LIFEEXPORT_API int LibNumberClasses()
{
return 1;
}
LIFEEXPORT_API ClassDesc* LibClassDesc(int i)
{
switch(i) {
case 0: return new MyPlugClassDesc();
default: return 0;
}
}
LIFEEXPORT_API ULONG LibVersion()
{
return VERSION_3DSMAX;
}
// Let the plug-in register itself for deferred loading
LIFEEXPORT_API ULONG CanAutoDefer()
{
return 1;
}