Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a simple functioning DLL without any of the mission exports
- // that can be compiled with GCC with the command:
- // gcc.exe simpledll.c -o simpledll.dll -shared
- // BZ2 Loads DLL module with LoadLibrary(..., "DLL Name From BZN")
- // BZ2 looks for "GetMisnAPI" export in DLL, using GetProcAddress("GetMisnAPI")
- // BZ2 fills a MisnImport struct with a call to FillMisnImport(MisnImport*)
- // BZ2 calls GetMisnAPI(MisnImport*) passing a pointer to the filled struct
- // In GetMisnAPI, DLL fills its global MisnExport struct inside GetMisnAPI, and returns a pointer to it for BZ2.
- // BZ2 starts calling stuff in MisnExport
- #define TARGET_BZCC
- #ifdef TARGET_BZCC
- // Nathan = "~GSH"
- // Brad = "BRAD"
- // Ken = "KEN3"
- // Brain = "BAL1"
- #define LATEST_DLL_VERSION 0X4C89322E
- #define LATEST_DLL_VERSION_MODIFIER "BAL1"
- #else
- #define LATEST_DLL_VERSION 0x4C89322D
- #define LATEST_DLL_VERSION_MODIFIER "~GSH"
- #endif
- #include <windows.h>
- #include <stdio.h> // _snprintf
- #define DLLAPI __cdecl
- typedef char bool;
- typedef char* Name;
- typedef int Handle;
- typedef int TeamNum;
- typedef float Time;
- typedef float Dist;
- typedef int ScrapValue;
- typedef unsigned long DWORD;
- typedef DWORD DPID;
- #define DPID_UNKNOWN 0xFFFFFFFF
- // Set of return codes from the PlayerEjected/PlayerKilled call to DLL
- enum EjectKillRetCodes {
- DoEjectPilot, // Do 'standard' eject
- DoRespawnSafest, // Respawn a 'PLAYER' at safest spawnpoint
- DLLHandled, // DLL handled actions. Do nothing ingame
- DoGameOver // Game over, man.
- };
- typedef void GameObject;
- typedef void AiPath;
- bool Save(bool missionSave) {
- char msg[256];
- _snprintf(msg, 256, "missionSave=%d", missionSave);
- MessageBox(0, msg, "Save", MB_OK);
- return missionSave;
- }
- bool Load(bool missionSave) {
- char msg[256];
- _snprintf(msg, 256, "missionSave=%d", missionSave);
- MessageBox(0, msg, "Load", MB_OK);
- return missionSave;
- }
- bool PostLoad(bool missionSave) {
- char msg[256];
- _snprintf(msg, 256, "missionSave=%d", missionSave);
- MessageBox(0, msg, "PostLoad", MB_OK);
- return missionSave;
- }
- void AddObject(Handle h) {
- char msg[256];
- _snprintf(msg, 256, "Handle: 0x%x", h);
- MessageBox(0, msg, "AddObject", MB_OK);
- }
- // wingdi.h (included in windows.h) has a DeleteObject so I put an underscore
- void _DeleteObject(Handle h) {
- char msg[256];
- _snprintf(msg, 256, "Handle: 0x%x", h);
- MessageBox(0, msg, "DeleteObject", MB_OK);
- }
- void PostRun(void) {
- MessageBox(0, "PostRun", "PostRun", MB_OK);
- }
- bool AddPlayer(DPID id, int Team, bool ShouldCreateThem) {
- char msg[256];
- _snprintf(msg, 256, "DPID=%d\nTeam=%d\nShouldCreate=%d", id, Team, ShouldCreateThem);
- MessageBox(0, msg, "AddPlayer", MB_OK);
- return 0;
- }
- void DeletePlayer(DPID id) {
- char msg[256];
- _snprintf(msg, 256, "DPID=%d", id);
- MessageBox(0, msg, "DeletePlayer", MB_OK);
- };
- int PlayerEjected(Handle DeadObjectHandle) {
- char msg[256];
- _snprintf(msg, 256, "DeadObjectHandle=0x%x", DeadObjectHandle);
- MessageBox(0, msg, "PlayerEjected", MB_OK);
- return DoGameOver;
- }
- int ObjectKilled(Handle DeadObjectHandle, Handle KillersHandle) {
- char msg[256];
- _snprintf(msg, 256, "DeadObjectHandle=0x%x\nKillersHandle=0x%x", DeadObjectHandle, KillersHandle);
- MessageBox(0, msg, "PlayerEjected", MB_OK);
- return DoEjectPilot;
- }
- int ObjectSniped(Handle DeadObjectHandle, Handle SnipersHandle) {
- char msg[256];
- _snprintf(msg, 256, "DeadObjectHandle=0x%x\nSnipersHandle=0x%x", DeadObjectHandle, SnipersHandle);
- MessageBox(0, msg, "ObjectSniped", MB_OK);
- return DoEjectPilot;
- }
- char* GetNextRandomVehicleODF(int ForTeam) {
- char msg[256];
- _snprintf(msg, 256, "ForTeam=%d", ForTeam);
- MessageBox(0, msg, "GetNextRandomVehicleODF", MB_OK);
- return "player";
- }
- void SetWorld(int nextWorld) {
- char msg[256];
- _snprintf(msg, 256, "nextWorld=%d", nextWorld);
- MessageBox(0, msg, "SetWorld", MB_OK);
- }
- void ProcessCommand(unsigned long crc) {
- char msg[256];
- _snprintf(msg, 256, "crc=%lu", crc);
- MessageBox(0, msg, "ProcessCommand", MB_OK);
- }
- void SetRandomSeed(unsigned long seed) {
- // Parameter is not pointer type, so not sure what we would do here?
- };
- void InitialSetup() {
- MessageBox(0, "InitialSetup", "InitialSetup", MB_OK);
- }
- void Update(void) {
- // Called every game tick
- }
- typedef struct MisnImport {
- float time;
- void (DLLAPI *FailMission)(Time t, char* fileName);
- void (DLLAPI *SucceedMission)(Time t, char* fileName);
- void (DLLAPI *ChangeSide)(void);
- ScrapValue (DLLAPI *AddScrap)(TeamNum t, ScrapValue v);
- ScrapValue (DLLAPI *SetScrap)(TeamNum t, ScrapValue v);
- ScrapValue (DLLAPI *GetScrap)(TeamNum t);
- ScrapValue (DLLAPI *GetMaxScrap)(TeamNum t);
- Handle (DLLAPI *GetTug)(Handle h);
- bool (DLLAPI *HasCargo)(Handle h);
- Dist (DLLAPI *GetDistanceObject)(Handle *h1, Handle *h2);
- Dist (DLLAPI *GetDistancePath)(Handle *h1, Name path, int point);
- Dist (DLLAPI *GetDistancePathPtr)(Handle *h1, AiPath *path, int point);
- Handle (DLLAPI *GetNearestObject)(Handle h);
- Handle (DLLAPI *GetNearestVehicleObject)(Handle h);
- Handle (DLLAPI *GetNearestVehiclePath)(Name path, int point);
- Handle (DLLAPI *GetNearestBuilding)(Handle h);
- Handle (DLLAPI *GetNearestEnemy)(Handle h);
- } MisnImport;
- typedef struct MisnExport {
- MisnImport *misnImport;
- unsigned long version;
- unsigned long VersionModifier;
- void (DLLAPI *InitialSetup)(void);
- bool (DLLAPI *Save)(bool missionSave);
- bool (DLLAPI *Load)(bool missionSave);
- bool (DLLAPI *PostLoad)(bool missionSave);
- void (DLLAPI *AddObject)(Handle h);
- void (DLLAPI *DeleteObject)(Handle h);
- void (DLLAPI *Update)(void);
- void (DLLAPI *PostRun)(void);
- bool (DLLAPI *AddPlayer)(DPID id, int Team, bool ShouldCreateThem);
- void (DLLAPI *DeletePlayer)(DPID id);
- int (DLLAPI *PlayerEjected)(Handle DeadObjectHandle); // return type is EjectKillRetCodes
- int (DLLAPI *ObjectKilled)(Handle DeadObjectHandle, Handle KillersHandle); // return type is EjectKillRetCodes
- int (DLLAPI *ObjectSniped)(Handle DeadObjectHandle, Handle KillersHandle); // return type is EjectKillRetCodes
- char* (DLLAPI *GetNextRandomVehicleODF)(int ForTeam);
- void (DLLAPI *SetWorld)(int nextWorld);
- void (DLLAPI *ProcessCommand)(unsigned long crc);
- void (DLLAPI *SetRandomSeed)(unsigned long seed);
- } MisnExport;
- MisnExport global_misnexport;
- #define SIGNATURE_TO_UINT32(s) _byteswap_ulong(s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24)
- // Function must be in export table of DLL (default in gcc I think)
- MisnExport* GetMisnAPI(MisnImport *misnimport) {
- MessageBox(0, "DLL has been called by game.", "GetMisnAPI", MB_OK);
- MisnExport *misnexport = &global_misnexport;
- misnexport->misnImport = (void*)misnimport;
- misnexport->version = LATEST_DLL_VERSION;
- misnexport->VersionModifier = SIGNATURE_TO_UINT32(LATEST_DLL_VERSION_MODIFIER);
- misnexport->Save = Save;
- misnexport->Load = Load;
- misnexport->PostLoad = PostLoad;
- misnexport->AddObject = AddObject;
- misnexport->DeleteObject = _DeleteObject;
- misnexport->Update = Update;
- misnexport->PostRun = PostRun;
- misnexport->AddPlayer = AddPlayer;
- misnexport->DeletePlayer = DeletePlayer;
- misnexport->PlayerEjected = PlayerEjected;
- misnexport->ObjectKilled = ObjectKilled;
- misnexport->ObjectSniped = ObjectSniped;
- misnexport->GetNextRandomVehicleODF = GetNextRandomVehicleODF;
- misnexport->SetWorld = SetWorld;
- misnexport->ProcessCommand = ProcessCommand;
- misnexport->SetRandomSeed = SetRandomSeed;
- misnexport->InitialSetup = InitialSetup;
- return misnexport;
- }
- BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
- // Perform actions based on the reason for calling.
- switch( fdwReason )
- {
- case DLL_PROCESS_ATTACH:
- MessageBox(NULL, "DLL_PROCESS_ATTACH", "DLL_PROCESS_ATTACH", MB_OK);
- break;
- case DLL_THREAD_ATTACH:
- // Do thread-specific initialization.
- break;
- case DLL_THREAD_DETACH:
- // Do thread-specific cleanup.
- break;
- case DLL_PROCESS_DETACH:
- MessageBox(NULL, "DLL_PROCESS_DETACH", "DLL_PROCESS_DETACH", MB_OK);
- if (lpvReserved != NULL) {
- break; // do not do cleanup if process termination scenario
- }
- // Perform any necessary cleanup.
- break;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement