mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-05 15:36:38 +00:00
svn -> git Migration
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
SET(sharedmem_src
|
||||
DLLMain.cpp
|
||||
Doors.cpp
|
||||
Items.cpp
|
||||
Loot.cpp
|
||||
MMF.cpp
|
||||
MMFMutex.cpp
|
||||
NPCFactionLists.cpp
|
||||
Opcodes.cpp
|
||||
SkillCaps.cpp
|
||||
Spells.cpp
|
||||
)
|
||||
|
||||
SET(sharedmem_headers
|
||||
Doors.h
|
||||
Items.h
|
||||
Loot.h
|
||||
MMF.h
|
||||
MMFMutex.h
|
||||
NPCFactionLists.h
|
||||
Opcodes.h
|
||||
SkillCaps.h
|
||||
Spells.h
|
||||
)
|
||||
|
||||
SET(EQEMU_MAX_ITEMS 300000 CACHE STRING "Maxium number of items to load into memory. Make sure this is bigger than the total number of items in the server database")
|
||||
SET(EQEMU_MAX_DOORS 30000 CACHE STRING "Maxium number of doors to load into memory. Make sure this is bigger than the total number of doors in the server database")
|
||||
SET(EQEMU_MAX_FACTIONLIST_IDS 50000 CACHE STRING "Maxium number of FactionList IDs to load into memory. Make sure this is bigger than the total number of FactionList IDs in the server database")
|
||||
|
||||
ADD_DEFINITIONS(-DMMF_EQMAX_ITEMS=${EQEMU_MAX_ITEMS})
|
||||
ADD_DEFINITIONS(-DMMF_MAX_Door_ID=${EQEMU_MAX_DOORS})
|
||||
ADD_DEFINITIONS(-DMMF_MAX_NPCFactionList_ID=${EQEMU_MAX_FACTIONLIST_IDS})
|
||||
|
||||
ADD_LIBRARY(EMuShareMem SHARED ${sharedmem_src} ${sharedmem_headers})
|
||||
TARGET_LINK_LIBRARIES(EMuShareMem Common)
|
||||
|
||||
IF(UNIX)
|
||||
TARGET_LINK_LIBRARIES(EMuShareMem "dl")
|
||||
TARGET_LINK_LIBRARIES(EMuShareMem "m")
|
||||
TARGET_LINK_LIBRARIES(EMuShareMem "rt")
|
||||
TARGET_LINK_LIBRARIES(EMuShareMem "pthread")
|
||||
ENDIF(UNIX)
|
||||
|
||||
SET(LIBRARY_OUTPUT_PATH ../Bin)
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
EMuShareMem.dll
|
||||
by Quagmire
|
||||
Released under GPL
|
||||
|
||||
This DLL's purpose it to hold a single shared copy of items, npctypes, spells, and other
|
||||
stuff that's normally cached in memory, thus allowing all processes on the server to share
|
||||
one copy of the data, greatly reducing the amount of RAM used.
|
||||
*/
|
||||
#ifdef _WINDOWS
|
||||
|
||||
#include <windows.h>
|
||||
void CloseMemShare();
|
||||
|
||||
BOOL WINAPI DllMain(
|
||||
HINSTANCE hinstDLL, // handle to DLL module
|
||||
DWORD fdwReason, // reason for calling function
|
||||
LPVOID lpReserved ) // reserved
|
||||
{
|
||||
// Perform actions based on the reason for calling.
|
||||
switch( fdwReason )
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH: {
|
||||
break;
|
||||
}
|
||||
case DLL_THREAD_DETACH: {
|
||||
break;
|
||||
}
|
||||
case DLL_PROCESS_DETACH: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE; // Successful DLL_PROCESS_ATTACH.
|
||||
}
|
||||
|
||||
#endif //WIN32
|
||||
@@ -0,0 +1,136 @@
|
||||
#include "../common/debug.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "Doors.h"
|
||||
#include "../common/timer.h"
|
||||
#include "MMF.h"
|
||||
|
||||
MMF DoorsMMF;
|
||||
const MMFDoors_Struct* MMFDoorsData = 0;
|
||||
MMFDoors_Struct* MMFDoorsData_Writable = 0;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
extern "C" __declspec(dllexport) const Door* GetDoor(uint32 id) {
|
||||
return pGetDoor(id);
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) bool AddDoor(uint32 id, const Door* door) {
|
||||
return pAddDoor(id, door);
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) bool DLLLoadDoors(CALLBACK_DBLoadDoors cbDBLoadDoors, uint32 iDoorstructSize, int32* iDoorsCount, uint32* iMaxDoorID) {
|
||||
return pDLLLoadDoors(cbDBLoadDoors, iDoorstructSize, iDoorsCount, iMaxDoorID);
|
||||
};
|
||||
#else
|
||||
extern "C" const Door* GetDoor(uint32 id) {
|
||||
return pGetDoor(id);
|
||||
};
|
||||
|
||||
extern "C" bool AddDoor(uint32 id, const Door* door) {
|
||||
return pAddDoor(id, door);
|
||||
};
|
||||
|
||||
extern "C" bool DLLLoadDoors(CALLBACK_DBLoadDoors cbDBLoadDoors, uint32 iDoorstructSize, int32* iDoorsCount, uint32* iMaxDoorID) {
|
||||
return pDLLLoadDoors(cbDBLoadDoors, iDoorstructSize, iDoorsCount, iMaxDoorID);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
bool pAddDoor(uint32 id, const Door* door) {
|
||||
if (!MMFDoorsData_Writable)
|
||||
return false;
|
||||
if (id > MMF_MAX_Door_ID || MMFDoorsData_Writable->NextFreeIndex >= MMFDoorsData_Writable->DoorCount)
|
||||
return false;
|
||||
if (MMFDoorsData_Writable->DoorIndex[id] != 0xFFFFFFFF)
|
||||
return false;
|
||||
|
||||
MMFDoorsData_Writable->DoorIndex[id] = MMFDoorsData_Writable->NextFreeIndex++;
|
||||
memcpy(&MMFDoorsData_Writable->Doors[MMFDoorsData_Writable->DoorIndex[id]], door, sizeof(Door));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pDLLLoadDoors(CALLBACK_DBLoadDoors cbDBLoadDoors, uint32 iDoorstructSize, int32* iDoorsCount, uint32* iMaxDoorID) {
|
||||
if (iDoorstructSize != sizeof(Door)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadDoors: iDoorstructSize != sizeof(Door)" << endl;
|
||||
cout << "Door struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
if (*iMaxDoorID > MMF_MAX_Door_ID) {
|
||||
cout << "Error: EMuShareMem: pDLLLoadDoors: iMaxDoorID > MMF_MAX_Door_ID" << endl;
|
||||
cout << "You need to increase the define in Doors.h." << endl;
|
||||
return false;
|
||||
}
|
||||
uint32 tmpMemSize = sizeof(MMFDoors_Struct) + 256 + (sizeof(Door) * (*iDoorsCount));
|
||||
if (DoorsMMF.Open("EQEMuDoors", tmpMemSize)) {
|
||||
if (DoorsMMF.CanWrite()) {
|
||||
MMFDoorsData_Writable = (MMFDoors_Struct*) DoorsMMF.GetWriteableHandle();
|
||||
if (!MMFDoorsData_Writable) {
|
||||
cout << "Error: EMuShareMem: DLLLoadDoors: !MMFDoorsData_Writable" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(MMFDoorsData_Writable, 0, tmpMemSize);
|
||||
for(int i=0; i<MMF_MAX_Door_ID; i++)
|
||||
MMFDoorsData_Writable->DoorIndex[i] = 0xFFFFFFFF;
|
||||
MMFDoorsData_Writable->MaxDoorID = *iMaxDoorID;
|
||||
MMFDoorsData_Writable->DoorCount = *iDoorsCount;
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (!cbDBLoadDoors(*iDoorsCount, *iMaxDoorID)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadDoors: !cbDBLoadDoors" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
MMFDoorsData_Writable = 0;
|
||||
DoorsMMF.SetLoaded();
|
||||
MMFDoorsData = (const MMFDoors_Struct*) DoorsMMF.GetHandle();
|
||||
if (!MMFDoorsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadDoors: !MMFDoorsData (CanWrite=true)" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (!DoorsMMF.IsLoaded()) {
|
||||
Timer::SetCurrentTime();
|
||||
uint32 starttime = Timer::GetCurrentTime();
|
||||
while ((!DoorsMMF.IsLoaded()) && ((Timer::GetCurrentTime() - starttime) < 300000)) {
|
||||
Sleep(10);
|
||||
Timer::SetCurrentTime();
|
||||
}
|
||||
if (!DoorsMMF.IsLoaded()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadDoors: !DoorsMMF.IsLoaded() (timeout)" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MMFDoorsData = (const MMFDoors_Struct*) DoorsMMF.GetHandle();
|
||||
if (!MMFDoorsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadDoors: !MMFDoorsData (CanWrite=false)" << endl;
|
||||
return false;
|
||||
}
|
||||
*iMaxDoorID = MMFDoorsData->MaxDoorID;
|
||||
*iDoorsCount = MMFDoorsData->DoorCount;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "Error Loading Doors: Doors.cpp: pDLLLoadDoors: ret == 0" << endl;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const Door* pGetDoor(uint32 id) {
|
||||
if (MMFDoorsData == 0 || (!DoorsMMF.IsLoaded()) || id > MMF_MAX_Door_ID || MMFDoorsData->DoorIndex[id] == 0xFFFFFFFF)
|
||||
return 0;
|
||||
return &MMFDoorsData->Doors[MMFDoorsData->DoorIndex[id]];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "../common/types.h"
|
||||
#include "../zone/zonedump.h"
|
||||
#include "../common/EMuShareMem.h"
|
||||
|
||||
// MMF_MAX_Door_ID: Make sure this is bigger than the highest Door ID#
|
||||
#ifndef MMF_MAX_Door_ID
|
||||
#define MMF_MAX_Door_ID 30000
|
||||
#endif
|
||||
// MMF_MAX_Door_MEM: Maxium number of Doors to load into memory. Make sure this is bigger
|
||||
// than the total number of Doors in the server's database!
|
||||
|
||||
struct MMFDoors_Struct {
|
||||
uint32 MaxDoorID;
|
||||
uint32 NextFreeIndex;
|
||||
uint32 DoorCount;
|
||||
uint32 DoorIndex[MMF_MAX_Door_ID+1];
|
||||
Door Doors[0];
|
||||
};
|
||||
|
||||
bool pDLLLoadDoors(CALLBACK_DBLoadDoors cbDBLoadDoors, uint32 iDoorstructSize, int32* iDoorsCount, uint32* iMaxDoorID);
|
||||
bool pAddDoor(uint32 id, const Door* door);
|
||||
const Door* pGetDoor(uint32 id);
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Note: Do NOT change this to load items on an as-needed basis. Since this memory is
|
||||
accessed from multiple threads, you'd need mutex's all over the place if it was
|
||||
ever to be modified/updated/added to. The overhead of the mutexes would be alot more
|
||||
in the long run than the delay in loading.
|
||||
|
||||
-Quagmire
|
||||
*/
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "Items.h"
|
||||
#include "../common/timer.h"
|
||||
#include "MMF.h"
|
||||
|
||||
MMF ItemsMMF;
|
||||
const MMFItems_Struct* MMFItemsData = 0;
|
||||
MMFItems_Struct* MMFItemsData_Writable = 0;
|
||||
|
||||
DLLFUNC bool AddItem(uint32 id, const Item_Struct* item) {
|
||||
if (!MMFItemsData_Writable) {
|
||||
return false;
|
||||
}
|
||||
if (id > MMF_EQMAX_ITEMS || MMFItemsData_Writable->NextFreeIndex >= MMFItemsData_Writable->ItemCount) {
|
||||
return false;
|
||||
}
|
||||
if (MMFItemsData_Writable->ItemIndex[id] != 0xFFFF) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 nextid = MMFItemsData_Writable->NextFreeIndex++;
|
||||
MMFItemsData_Writable->ItemIndex[id] = nextid;
|
||||
memcpy(&MMFItemsData_Writable->Items[nextid], item, sizeof(Item_Struct));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DLLFUNC bool DLLLoadItems(CALLBACK_DBLoadItems cbDBLoadItems, uint32 iItemStructSize, int32* iItemCount, uint32* iMaxItemID) {
|
||||
if (iItemStructSize != sizeof(Item_Struct)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadItems: iItemStructSize != sizeof(Item_Struct)" << endl;
|
||||
cout << "Item_Struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
if (*iMaxItemID > MMF_EQMAX_ITEMS) {
|
||||
cout << "Error: EMuShareMem: pDLLLoadItems: iMaxItemID > MMF_EQMAX_ITEMS" << endl;
|
||||
cout << "You need to increase the define in Items.h." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
MMFItemsData_Writable = 0;
|
||||
//Allocate the shared memory for the item structures
|
||||
uint32 tmpMemSize = sizeof(MMFItems_Struct) + 256 + (sizeof(Item_Struct) * (*iItemCount));
|
||||
//cout << tmpMemSize << endl;
|
||||
if (ItemsMMF.Open("EQEMuItems", tmpMemSize)) {
|
||||
if (ItemsMMF.CanWrite()) {
|
||||
MMFItemsData_Writable = (MMFItems_Struct*) ItemsMMF.GetWriteableHandle();
|
||||
if (!MMFItemsData_Writable) {
|
||||
cout << "Error: EMuShareMem: DLLLoadItems: !MMFItemsData_Writable" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(MMFItemsData_Writable, 0, tmpMemSize);
|
||||
for(int i=0; i<MMF_EQMAX_ITEMS; i++)
|
||||
MMFItemsData_Writable->ItemIndex[i] = 0xFFFF;
|
||||
MMFItemsData_Writable->MaxItemID = *iMaxItemID;
|
||||
MMFItemsData_Writable->ItemCount = *iItemCount;
|
||||
//the writable handle has been created, do the load below after we have the
|
||||
//serialization handle as well.
|
||||
} else {
|
||||
if (!ItemsMMF.IsLoaded()) {
|
||||
Timer::SetCurrentTime();
|
||||
uint32 starttime = Timer::GetCurrentTime();
|
||||
while ((!ItemsMMF.IsLoaded()) && ((Timer::GetCurrentTime() - starttime) < 300000)) {
|
||||
Sleep(10);
|
||||
Timer::SetCurrentTime();
|
||||
}
|
||||
if (!ItemsMMF.IsLoaded()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadItems: !ItemsMMF.IsLoaded() (timeout)" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MMFItemsData = (const MMFItems_Struct*) ItemsMMF.GetHandle();
|
||||
if (!MMFItemsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadItems: !MMFItemsData (CanWrite=false)" << endl;
|
||||
return false;
|
||||
}
|
||||
*iMaxItemID = MMFItemsData->MaxItemID;
|
||||
*iItemCount = MMFItemsData->ItemCount;
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
cout << "Error Loading Items: Items.cpp: pDLLLoadItems: Open() == false" << endl;
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (!cbDBLoadItems(*iItemCount, *iMaxItemID)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadItems: !cbDBLoadItems" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (!cbDBLoadItems(*iItemCount, *iMaxItemID)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadItems: !cbDBLoadItems" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Now, Disable the write handle and get the read handle.
|
||||
//do this for both item struct and serialization data
|
||||
|
||||
MMFItemsData_Writable = 0;
|
||||
ItemsMMF.SetLoaded();
|
||||
MMFItemsData = (const MMFItems_Struct*) ItemsMMF.GetHandle();
|
||||
if (!MMFItemsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadItems: !MMFItemsData (CanWrite=true)" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
DLLFUNC const Item_Struct* GetItem(uint32 id) {
|
||||
if (MMFItemsData == 0 || (!ItemsMMF.IsLoaded()) || id > MMF_EQMAX_ITEMS || MMFItemsData->ItemIndex[id] == 0xFFFF)
|
||||
return 0;
|
||||
return &MMFItemsData->Items[MMFItemsData->ItemIndex[id]];
|
||||
}
|
||||
|
||||
DLLFUNC const Item_Struct* IterateItems(uint32* NextIndex) {
|
||||
if (MMFItemsData == 0 || (!ItemsMMF.IsLoaded()) || (*NextIndex) > MMF_EQMAX_ITEMS)
|
||||
return 0;
|
||||
do {
|
||||
if (MMFItemsData->ItemIndex[*NextIndex] != 0xFFFF)
|
||||
return &MMFItemsData->Items[MMFItemsData->ItemIndex[(*NextIndex)++]];
|
||||
} while (++(*NextIndex) < MMF_EQMAX_ITEMS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "../common/types.h"
|
||||
#include "../common/eq_packet_structs.h"
|
||||
#include "../common/EMuShareMem.h"
|
||||
|
||||
// MMF_EQMAX_ITEMS: Make sure this is bigger than the highest item ID#
|
||||
#ifndef MMF_EQMAX_ITEMS
|
||||
#define MMF_EQMAX_ITEMS 300000
|
||||
#endif
|
||||
// MMF_MEMMAX_ITEMS: Maxium number of items to load into memory. Make sure this is bigger
|
||||
// than the total number of items in the server's database!
|
||||
|
||||
struct MMFItems_Struct {
|
||||
uint32 MaxItemID;
|
||||
uint32 NextFreeIndex;
|
||||
uint32 ItemCount;
|
||||
uint32 ItemIndex[MMF_EQMAX_ITEMS+1];
|
||||
Item_Struct Items[0];
|
||||
};
|
||||
|
||||
//#define MMF_MAX_ITEMS_MEMSIZE sizeof(MMFItems_Struct) + 256
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
#include "../common/debug.h"
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "Loot.h"
|
||||
#include "../common/timer.h"
|
||||
#include "MMF.h"
|
||||
|
||||
MMF LootMMF;
|
||||
const MMFLoot_Struct* MMFLootData = 0;
|
||||
MMFLoot_Struct* MMFLootData_Writable = 0;
|
||||
uint32* LootTable;
|
||||
uint32* LootDrop;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#define exportfunc extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#define exportfunc extern "C"
|
||||
#endif
|
||||
|
||||
exportfunc const LootTable_Struct* GetLootTable(uint32 id) {
|
||||
return pGetLootTable(id);
|
||||
};
|
||||
exportfunc const LootDrop_Struct* GetLootDrop(uint32 id) {
|
||||
return pGetLootDrop(id);
|
||||
};
|
||||
|
||||
exportfunc bool AddLootTable(uint32 id, const LootTable_Struct* lts) {
|
||||
return pAddLootTable(id, lts);
|
||||
};
|
||||
exportfunc bool AddLootDrop(uint32 id, const LootDrop_Struct* lds) {
|
||||
return pAddLootDrop(id, lds);
|
||||
};
|
||||
|
||||
exportfunc bool DLLLoadLoot(CALLBACK_DBLoadLoot cbDBLoadLoot,
|
||||
uint32 iLootTableStructsize, uint32 iLootTableCount, uint32 iMaxLootTable,
|
||||
uint32 iLootTableEntryStructsize, uint32 iLootTableEntryCount,
|
||||
uint32 iLootDropStructsize, uint32 iLootDropCount, uint32 iMaxLootDrop,
|
||||
uint32 iLootDropEntryStructsize, uint32 iLootDropEntryCount
|
||||
) {
|
||||
return pDLLLoadLoot(cbDBLoadLoot,
|
||||
iLootTableStructsize, iLootTableCount, iMaxLootTable,
|
||||
iLootTableEntryStructsize, iLootTableEntryCount,
|
||||
iLootDropStructsize, iLootDropCount, iMaxLootDrop,
|
||||
iLootDropEntryStructsize, iLootDropEntryCount);
|
||||
};
|
||||
|
||||
|
||||
bool pAddLootTable(uint32 id, const LootTable_Struct* lts) {
|
||||
if (!MMFLootData_Writable)
|
||||
return false;
|
||||
if (id > MMFLootData_Writable->MaxLootTableID)
|
||||
return false;
|
||||
if (!LootTable || LootTable[id] != 0)
|
||||
return false;
|
||||
|
||||
uint32 tmp = sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lts->NumEntries);
|
||||
if (MMFLootData_Writable->dataindex + tmp >= MMFLootData_Writable->datamax)
|
||||
return false;
|
||||
LootTable[id] = MMFLootData_Writable->dataindex;
|
||||
memcpy(&MMFLootData_Writable->data[MMFLootData_Writable->dataindex], lts, tmp);
|
||||
MMFLootData_Writable->dataindex += tmp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pAddLootDrop(uint32 id, const LootDrop_Struct* lds) {
|
||||
if (!MMFLootData_Writable)
|
||||
return false;
|
||||
if (id > MMFLootData_Writable->MaxLootDropID)
|
||||
return false;
|
||||
if (!LootDrop || LootDrop[id] != 0)
|
||||
return false;
|
||||
|
||||
uint32 tmp = sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * lds->NumEntries);
|
||||
if (MMFLootData_Writable->dataindex + tmp >= MMFLootData_Writable->datamax)
|
||||
return false;
|
||||
LootDrop[id] = MMFLootData_Writable->dataindex;
|
||||
memcpy(&MMFLootData_Writable->data[MMFLootData_Writable->dataindex], lds, tmp);
|
||||
MMFLootData_Writable->dataindex += tmp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pDLLLoadLoot(CALLBACK_DBLoadLoot cbDBLoadLoot,
|
||||
uint32 iLootTableStructsize, uint32 iLootTableCount, uint32 iMaxLootTable,
|
||||
uint32 iLootTableEntryStructsize, uint32 iLootTableEntryCount,
|
||||
uint32 iLootDropStructsize, uint32 iLootDropCount, uint32 iMaxLootDrop,
|
||||
uint32 iLootDropEntryStructsize, uint32 iLootDropEntryCount
|
||||
) {
|
||||
#if 0
|
||||
cout << "iLootTableCount: " << iLootTableCount << endl;
|
||||
cout << "iMaxLootTable: " << iMaxLootTable << endl;
|
||||
cout << "iLootTableEntryCount: " << iLootTableEntryCount << endl;
|
||||
cout << "iLootDropCount: " << iLootDropCount << endl;
|
||||
cout << "iMaxLootDrop: " << iMaxLootDrop << endl;
|
||||
cout << "iLootDropEntryCount: " << iLootDropEntryCount << endl;
|
||||
#endif
|
||||
if (iLootTableStructsize != sizeof(LootTable_Struct)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: iLootTableStructsize != sizeof(LootTable_Struct)" << endl;
|
||||
cout << "Item_Struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
if (iLootTableEntryStructsize != sizeof(LootTableEntries_Struct)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: iLootTableEntryStructsize != sizeof(LootTableEntries_Struct)" << endl;
|
||||
cout << "Item_Struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
if (iLootDropStructsize != sizeof(LootDrop_Struct)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: iLootDropStructsize != sizeof(LootDrop_Struct)" << endl;
|
||||
cout << "Item_Struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
if (iLootDropEntryStructsize != sizeof(LootDropEntries_Struct)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: iLootDropEntryStructsize != sizeof(LootDropEntries_Struct)" << endl;
|
||||
cout << "Item_Struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 tmpMemSize = sizeof(MMFLoot_Struct) + 256
|
||||
+ (sizeof(uint32) * (iMaxLootTable+1))
|
||||
+ (sizeof(LootTable_Struct) * iLootTableCount) + (sizeof(LootTableEntries_Struct) * iLootTableEntryCount)
|
||||
+ (sizeof(uint32) * (iMaxLootDrop+1))
|
||||
+ (sizeof(LootDrop_Struct) * iLootDropCount) + (sizeof(LootDropEntries_Struct) * iLootDropEntryCount)
|
||||
;
|
||||
if (LootMMF.Open("EQEMuLoot", tmpMemSize)) {
|
||||
if (LootMMF.CanWrite()) {
|
||||
MMFLootData_Writable = (MMFLoot_Struct*) LootMMF.GetWriteableHandle();
|
||||
if (!MMFLootData_Writable) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: !MMFLootData_Writable" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(MMFLootData_Writable, 0, tmpMemSize);
|
||||
MMFLootData_Writable->LootTableCount = iLootTableCount;
|
||||
MMFLootData_Writable->MaxLootTableID = iMaxLootTable;
|
||||
MMFLootData_Writable->LootDropCount = iLootDropCount;
|
||||
MMFLootData_Writable->MaxLootDropID = iMaxLootDrop;
|
||||
MMFLootData_Writable->datamax = tmpMemSize - sizeof(MMFLoot_Struct);
|
||||
|
||||
MMFLootData_Writable->dataindex = 0;
|
||||
MMFLootData_Writable->LootTableOffset = MMFLootData_Writable->dataindex;
|
||||
MMFLootData_Writable->dataindex += (sizeof(uint32) * (iMaxLootTable+1));
|
||||
MMFLootData_Writable->LootDropOffset = MMFLootData_Writable->dataindex;
|
||||
MMFLootData_Writable->dataindex += (sizeof(uint32) * (iMaxLootDrop+1));
|
||||
|
||||
LootTable = (uint32*) &MMFLootData_Writable->data[MMFLootData_Writable->LootTableOffset];
|
||||
LootDrop = (uint32*) &MMFLootData_Writable->data[MMFLootData_Writable->LootDropOffset];
|
||||
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (!cbDBLoadLoot()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: !cbDBLoadLoot" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
MMFLootData_Writable = 0;
|
||||
LootMMF.SetLoaded();
|
||||
}
|
||||
else {
|
||||
if (!LootMMF.IsLoaded()) {
|
||||
Timer::SetCurrentTime();
|
||||
uint32 starttime = Timer::GetCurrentTime();
|
||||
while ((!LootMMF.IsLoaded()) && ((Timer::GetCurrentTime() - starttime) < 300000)) {
|
||||
Sleep(10);
|
||||
Timer::SetCurrentTime();
|
||||
}
|
||||
if (!LootMMF.IsLoaded()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: !LootMMF.IsLoaded() (timeout)" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "Error Loading Loot: Loot.cpp: pDLLLoadLoot: Open() == false" << endl;
|
||||
return false;
|
||||
}
|
||||
MMFLootData = (const MMFLoot_Struct*) LootMMF.GetHandle();
|
||||
if (!MMFLootData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: !MMFLootData" << endl;
|
||||
MMFLootData = 0;
|
||||
return false;
|
||||
}
|
||||
if (MMFLootData->LootTableCount != iLootTableCount
|
||||
|| MMFLootData->MaxLootTableID != iMaxLootTable
|
||||
|| MMFLootData->LootDropCount != iLootDropCount
|
||||
|| MMFLootData->MaxLootDropID != iMaxLootDrop) {
|
||||
cout << "Error: EMuShareMem: DLLLoadLoot: Count/Max mismatch" << endl;
|
||||
MMFLootData = 0;
|
||||
return false;
|
||||
}
|
||||
LootTable = (uint32*) &MMFLootData->data[MMFLootData->LootTableOffset];
|
||||
LootDrop = (uint32*) &MMFLootData->data[MMFLootData->LootDropOffset];
|
||||
return true;
|
||||
};
|
||||
|
||||
const LootTable_Struct* pGetLootTable(uint32 id) {
|
||||
if (MMFLootData == 0 || !LootMMF.IsLoaded())
|
||||
return 0;
|
||||
if (id > MMFLootData->MaxLootTableID || LootTable[id] == 0)
|
||||
return 0;
|
||||
return (LootTable_Struct*) &MMFLootData->data[LootTable[id]];
|
||||
}
|
||||
|
||||
const LootDrop_Struct* pGetLootDrop(uint32 id) {
|
||||
if (MMFLootData == 0 || !LootMMF.IsLoaded())
|
||||
return 0;
|
||||
if (id > MMFLootData->MaxLootDropID || LootDrop[id] == 0)
|
||||
return 0;
|
||||
return (LootDrop_Struct*) &MMFLootData->data[LootDrop[id]];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "../common/types.h"
|
||||
#include "../common/eq_packet_structs.h"
|
||||
#include "../common/EMuShareMem.h"
|
||||
|
||||
#pragma pack(1)
|
||||
struct MMFLoot_Struct {
|
||||
bool Loaded;
|
||||
uint32 MaxLootTableID;
|
||||
uint32 LootTableCount;
|
||||
uint32 LootTableOffset;
|
||||
uint32 MaxLootDropID;
|
||||
uint32 LootDropCount;
|
||||
uint32 LootDropOffset;
|
||||
uint32 datamax;
|
||||
uint32 dataindex;
|
||||
uint8 data[0];
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
bool pDLLLoadLoot(CALLBACK_DBLoadLoot cbDBLoadLoot,
|
||||
uint32 iLootTableStructsize, uint32 iLootTableCount, uint32 iMaxLootTable,
|
||||
uint32 iLootTableEntryStructsize, uint32 iLootTableEntryCount,
|
||||
uint32 iLootDropStructsize, uint32 iLootDropCount, uint32 iMaxLootDrop,
|
||||
uint32 iLootDropEntryStructsize, uint32 iLootDropEntryCount
|
||||
);
|
||||
bool pAddLootTable(uint32 id, const LootTable_Struct* lts);
|
||||
bool pAddLootDrop(uint32, const LootDrop_Struct* lds);
|
||||
const LootTable_Struct* pGetLootTable(uint32 id);
|
||||
const LootDrop_Struct* pGetLootDrop(uint32 id);
|
||||
@@ -0,0 +1,353 @@
|
||||
// start mingw
|
||||
#ifdef __MINGW32__
|
||||
#define __try
|
||||
#define __finally
|
||||
#endif
|
||||
// end mingw
|
||||
|
||||
#include "MMF.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _WINDOWS
|
||||
#define snprintf _snprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#define strncasecmp _strnicmp
|
||||
#define strcasecmp _stricmp
|
||||
#else
|
||||
#include "MMFMutex.h"
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
MMF::MMF() {
|
||||
SharedMemory = 0;
|
||||
pCanWrite = false;
|
||||
#ifdef _WINDOWS
|
||||
hMapObject = NULL;
|
||||
lpvMem = 0;
|
||||
#else
|
||||
lpvMem = 0;
|
||||
pMMFMutex = 0;
|
||||
m_alloc = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
MMF::~MMF() {
|
||||
Close();
|
||||
}
|
||||
|
||||
bool MMF::Open(const char* iName, uint32 iSize) {
|
||||
if (iSize < 1) {
|
||||
cout << "Error Loading MMF: " << __FILE__ << ":" << __LINE__ << " OpenMMF: iSize < 1" << endl;
|
||||
return false;
|
||||
}
|
||||
if (strlen(iName) < 2) {
|
||||
cout << "Error Loading MMF: " << __FILE__ << ":" << __LINE__ << " OpenMMF: strlen(iName) < 2" << endl;
|
||||
return false;
|
||||
}
|
||||
char MMFname[200];
|
||||
memset(MMFname, 0, sizeof(MMFname));
|
||||
snprintf(MMFname, sizeof(MMFname), "memfilemap_%s", iName);
|
||||
uint32 tmpSize = sizeof(MMF_Struct) + iSize;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
char MMFMutexName[200];
|
||||
memset(MMFMutexName, 0, sizeof(MMFMutexName));
|
||||
snprintf(MMFMutexName, sizeof(MMFMutexName), "MutexToProtectOpenMMF_%s", iName);
|
||||
|
||||
HANDLE hMutex;
|
||||
hMutex = CreateMutex(
|
||||
NULL, // no security attributes
|
||||
FALSE, // initially not owned
|
||||
MMFMutexName); // name of mutex
|
||||
|
||||
if (hMutex == NULL) {
|
||||
cout << "Error Loading MMF: " << __FILE__ << ":" << __LINE__ << " OpenMMF: hMutex == Null" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD dwWaitResult;
|
||||
// Request ownership of mutex.
|
||||
dwWaitResult = WaitForSingleObject(
|
||||
hMutex, // handle to mutex
|
||||
2000L); // two-second time-out interval
|
||||
|
||||
if (dwWaitResult != WAIT_OBJECT_0) {
|
||||
// Mutex not aquired, crap out
|
||||
cout << "Error Loading MMF: " << __FILE__ << ":" << __LINE__ << " OpenMMF: dwWaitResult != WAIT_OBJECT_0" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finally, ready to rock.
|
||||
bool fInit = false;
|
||||
__try {
|
||||
hMapObject = CreateFileMapping(
|
||||
INVALID_HANDLE_VALUE, // use paging file
|
||||
NULL, // default security attributes
|
||||
PAGE_READWRITE, // read/write access
|
||||
0, // size: high 32-bits
|
||||
tmpSize, // size: low 32-bits
|
||||
MMFname); // name of map object
|
||||
if (hMapObject == NULL) {
|
||||
cout << "Error Loading MMF: " << __FILE__ << ":" << __LINE__ << " OpenMMF: hMapObject == Null" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// The first process to attach initializes memory.
|
||||
|
||||
fInit = (bool) (GetLastError() != ERROR_ALREADY_EXISTS);
|
||||
|
||||
// Get a pointer to the file-mapped shared memory.
|
||||
|
||||
lpvMem = MapViewOfFile(
|
||||
hMapObject, // object to map view of
|
||||
FILE_MAP_WRITE, // read/write access
|
||||
0, // high offset: map from
|
||||
0, // low offset: beginning
|
||||
0); // default: map entire file
|
||||
if (lpvMem == NULL) {
|
||||
cout << "Error Loading MMF: " << __FILE__ << ":" << __LINE__ << " OpenMMF: lpvMem == Null" << endl;
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
SharedMemory = (MMF_Struct*) lpvMem;
|
||||
// Initialize memory if this is the first process.
|
||||
if (fInit) {
|
||||
memset(lpvMem, 0, sizeof(MMF_Struct));
|
||||
pCanWrite = true;
|
||||
SharedMemory->Loaded = false;
|
||||
SharedMemory->datasize = iSize;
|
||||
}
|
||||
else {
|
||||
pCanWrite = false;
|
||||
if (SharedMemory->datasize != iSize) {
|
||||
cout << "Error Loading MMF: " << __FILE__ << ":" << __LINE__ << " OpenMMF: SharedMemory->datasize != iSize" << endl;
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // end of try block
|
||||
|
||||
__finally {
|
||||
// Clean up the Mutex stuff
|
||||
if (!ReleaseMutex(hMutex)) {
|
||||
cout << "Error Loading MMF: " << __FILE__ << ":" << __LINE__ << " OpenMMF: !ReleaseMutex(hMutex)" << endl;
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
CloseHandle(hMutex);
|
||||
|
||||
return true;
|
||||
#else //else, NOT WINDOWS
|
||||
int load_share;
|
||||
//int max_share = 7;
|
||||
key_t share_key;
|
||||
switch (MMFname[16]) {
|
||||
case 'I': load_share = 0; break;
|
||||
case 'N': load_share = 1; break;
|
||||
case 'D': load_share = 2; break;
|
||||
case 'S': load_share = 3; break;
|
||||
case 'F': load_share = 4; break;
|
||||
case 'L': load_share = 5; break;
|
||||
case 'M': load_share = 6; break;
|
||||
case 'O': load_share = 7; break;
|
||||
case 'Z': load_share = 8; break;
|
||||
case 'K': load_share = 9; break;
|
||||
#ifdef CATCH_CRASH
|
||||
default:
|
||||
cerr<<"Failed to load shared memory segment="<<MMFname<<" ("<<MMFname[16]<<")"<<endl;
|
||||
// malloc some memory here or something fancy
|
||||
return false; // and make this return true
|
||||
break;
|
||||
#else
|
||||
default: cerr<<"FATAL="<<(char)MMFname[16]<<endl; return false; break;
|
||||
#endif
|
||||
}
|
||||
switch (load_share) {
|
||||
// Item
|
||||
case 0: share_key = ftok(".", 'I'); break;
|
||||
// Npctype
|
||||
case 1: share_key = ftok(".", 'N'); break;
|
||||
// Door
|
||||
case 2: share_key = ftok(".", 'D'); break;
|
||||
// Spell
|
||||
case 3: share_key = ftok(".", 'S'); break;
|
||||
// Faction
|
||||
case 4: share_key = ftok(".", 'F'); break;
|
||||
// Loot
|
||||
case 5: share_key = ftok(".", 'L'); break;
|
||||
// ??
|
||||
case 6: share_key = ftok(".", 'M'); break;
|
||||
// Opcodes
|
||||
case 7: share_key = ftok(".", 'O'); break;
|
||||
// Item Serialization
|
||||
case 8: share_key = ftok(".", 'Z'); break;
|
||||
// Skills
|
||||
case 9: share_key = ftok(".", 'K'); break;
|
||||
// ERROR Fatal
|
||||
default: cerr<<"Opps!"<<endl; share_key = 0xFF; break;
|
||||
}
|
||||
pMMFMutex = new MMFMutex(share_key);
|
||||
if (!pMMFMutex){
|
||||
assert(false);
|
||||
}
|
||||
//if (!tmpSize) {
|
||||
int share_id = shmget(share_key, tmpSize, IPC_CREAT|IPC_EXCL|SHM_R|SHM_W);
|
||||
if ( share_id <= 0) {
|
||||
share_id = shmget(share_key, tmpSize, IPC_CREAT|IPC_NOWAIT);
|
||||
if (share_id <= 0) {
|
||||
shmid_ds mem_size;
|
||||
share_id = shmget(share_key, 1, IPC_CREAT|IPC_NOWAIT|SHM_R|SHM_W);
|
||||
if(share_id == -1) {
|
||||
cerr << "failed to get 0-length shared mem: " << strerror(errno) << endl;
|
||||
}
|
||||
if ((lpvMem = shmat(share_id, NULL,SHM_RDONLY)) == (void *)-1) {
|
||||
cerr << "shmat failed! " << strerror(errno) << endl;
|
||||
}
|
||||
if( (shmctl(share_id, IPC_STAT, &mem_size)) == 0){
|
||||
if (mem_size.shm_segsz != int(tmpSize)){ //comparison between signed and unsigned integer expressions
|
||||
cout<<"[Warning] requested shared memory of size:"<<tmpSize<<" but that Key is already in use with size:"<< mem_size.shm_segsz<<endl;
|
||||
shmid_ds mem_users;
|
||||
if( (shmctl(share_id, IPC_STAT, &mem_users)) == 0 && mem_users.shm_nattch == 1){
|
||||
cout<<"[Warning] Attempting resize"<<endl;
|
||||
shmctl(share_id, IPC_RMID, 0);
|
||||
shmdt(lpvMem);
|
||||
if ((share_id = shmget(share_key, tmpSize, IPC_CREAT|IPC_EXCL|SHM_R|SHM_W)) <= 0) {
|
||||
// Failed proceed on malloc
|
||||
cerr<<"[Error] Failed to resize" << strerror(errno) <<endl;
|
||||
}
|
||||
else{
|
||||
cerr<<"[Error] Resize successful." << endl;
|
||||
// Success
|
||||
lpvMem = shmat(share_id, NULL, SHM_R|SHM_W);
|
||||
memset(lpvMem, 0, sizeof(MMF_Struct));
|
||||
pCanWrite = true;
|
||||
SharedMemory = (MMF_Struct*) lpvMem;
|
||||
SharedMemory->Loaded = false;
|
||||
SharedMemory->datasize = iSize;
|
||||
pMMFMutex->Release(this);
|
||||
delete pMMFMutex;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
cout<<"[Warning] Resize not possible"<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Can not attatch to shared memory we'll malloc it here
|
||||
if ((lpvMem == 0 || lpvMem == (void *)-1) && (lpvMem = malloc(tmpSize))) {
|
||||
cout<<"[Warning] Could not attach to shared memory proceeding on isolated memory (share_id <= 0)"<<endl;
|
||||
// Success!
|
||||
m_alloc = true;
|
||||
memset(lpvMem, 0, sizeof(MMF_Struct));
|
||||
pCanWrite = true;
|
||||
SharedMemory = (MMF_Struct*) lpvMem;
|
||||
SharedMemory->datasize = iSize;
|
||||
SharedMemory->Loaded = false;
|
||||
pMMFMutex->Release(this);
|
||||
delete pMMFMutex;
|
||||
return true;
|
||||
} else if (!lpvMem){
|
||||
//LogFile->write(EQEMuLog::Error, "Could not connect to shared memory and allocation of isolated memory failed.");
|
||||
cout<<"Could not connect to shared memory and allocation of isolated memory failed."<<endl;
|
||||
pMMFMutex->Release(this);
|
||||
delete pMMFMutex;
|
||||
exit(1);
|
||||
}
|
||||
pCanWrite = false;
|
||||
SharedMemory = (MMF_Struct*) lpvMem;
|
||||
if (SharedMemory->datasize != iSize) {
|
||||
cerr<<"SharedMemory->datasize("<<SharedMemory->datasize<<") != iSize("<<iSize<<"), We can rebuild him faster better STRONGER!"<<endl;
|
||||
cerr<<"Or not.. restart all servers on this machine"<<endl;
|
||||
shmctl(share_id, IPC_RMID, 0);
|
||||
pMMFMutex->Release(this);
|
||||
exit(1);
|
||||
}
|
||||
pMMFMutex->Release(this);
|
||||
delete pMMFMutex;
|
||||
return true;
|
||||
}
|
||||
shmid_ds mem_users;
|
||||
if ((shmctl(share_id, IPC_STAT, &mem_users)) != 0) {
|
||||
if ((lpvMem = malloc(tmpSize))) {
|
||||
// Success!
|
||||
cout<<"[Warning] Could not attach to shared memory proceeding on isolated memory"<<endl;
|
||||
m_alloc = true;
|
||||
memset(lpvMem, 0, sizeof(MMF_Struct));
|
||||
pCanWrite = true;
|
||||
SharedMemory = (MMF_Struct*) lpvMem;
|
||||
SharedMemory->datasize = iSize;
|
||||
SharedMemory->Loaded = false;
|
||||
pMMFMutex->Release(this);
|
||||
delete pMMFMutex;
|
||||
return true;
|
||||
} else {
|
||||
//LogFile->write(EQEMuLog::Error, "Could not connect to shared memory and allocation of isolated memory failed.");
|
||||
cout<<"Could not connect to shared memory and allocation of isolated memory failed."<<endl;
|
||||
pMMFMutex->Release(this);
|
||||
delete pMMFMutex;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
lpvMem = shmat(share_id, NULL,SHM_RDONLY);
|
||||
pCanWrite = false;
|
||||
SharedMemory = (MMF_Struct*) lpvMem;
|
||||
//cerr << "lpvMem=" << (int)lpvMem << endl;
|
||||
if (lpvMem==(void *)-1 || SharedMemory->datasize != iSize) {
|
||||
cerr<<"SharedMemory->datasize("<<SharedMemory->datasize<<") != iSize("<<iSize<<"), or "<<((void *)lpvMem)<<"==-1, We can rebuild him faster better STRONGER!"<<endl;
|
||||
cerr<<"Or not.. restart all servers on this machine"<<endl;
|
||||
shmctl(share_id, IPC_RMID, 0);
|
||||
pMMFMutex->Release(this);
|
||||
exit(1);
|
||||
}
|
||||
pMMFMutex->Release(this);
|
||||
delete pMMFMutex;
|
||||
return true;
|
||||
}
|
||||
lpvMem = shmat(share_id, NULL, SHM_R|SHM_W);
|
||||
memset(lpvMem, 0, sizeof(MMF_Struct));
|
||||
pCanWrite = true;
|
||||
SharedMemory = (MMF_Struct*) lpvMem;
|
||||
SharedMemory->Loaded = false;
|
||||
SharedMemory->datasize = iSize;
|
||||
//}
|
||||
pMMFMutex->Release(this);
|
||||
delete pMMFMutex;
|
||||
return true;
|
||||
|
||||
#endif //end NOT WINDOWS
|
||||
}
|
||||
|
||||
void MMF::Close() {
|
||||
SharedMemory = 0;
|
||||
pCanWrite = false;
|
||||
#ifdef _WINDOWS
|
||||
if (lpvMem) {
|
||||
// Unmap shared memory from the process's address space.
|
||||
UnmapViewOfFile(lpvMem);
|
||||
lpvMem = 0;
|
||||
}
|
||||
if (hMapObject) {
|
||||
// Close the process's handle to the file-mapping object.
|
||||
CloseHandle(hMapObject);
|
||||
hMapObject = NULL;
|
||||
}
|
||||
#else
|
||||
if (lpvMem) {
|
||||
if (m_alloc == true)
|
||||
free(lpvMem);
|
||||
else
|
||||
if (shmdt(lpvMem) == -1)
|
||||
//LogFile->write(EQEMuLog::Error, "Warning something odd happened freeing shared memory");
|
||||
cout<<"Warning something odd happened freeing shared memory"<<endl;
|
||||
lpvMem = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef MMF_H
|
||||
#define MMF_H
|
||||
#include "../common/types.h"
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
//#include "MMFMutex.h"
|
||||
class MMFMutex;
|
||||
#endif
|
||||
|
||||
class MMF {
|
||||
public:
|
||||
struct MMF_Struct {
|
||||
bool Loaded;
|
||||
uint32 datasize;
|
||||
uint8 data[0];
|
||||
};
|
||||
|
||||
MMF();
|
||||
virtual ~MMF();
|
||||
|
||||
bool Open(const char* iName, uint32 iSize);
|
||||
void Close();
|
||||
const void* GetHandle() { if (IsLoaded()) { return SharedMemory->data; } return 0; }
|
||||
void* GetWriteableHandle() { if (!IsLoaded() && CanWrite()) { return SharedMemory->data; } return 0; }
|
||||
|
||||
inline bool IsOpen() { return (bool) (SharedMemory != 0); }
|
||||
inline bool IsLoaded() { if (SharedMemory) { return SharedMemory->Loaded; } return false; }
|
||||
bool SetLoaded() { if (SharedMemory && CanWrite()) { SharedMemory->Loaded = true; return true; } return false; }
|
||||
inline bool CanWrite() { if (SharedMemory) { return pCanWrite; } return false; }
|
||||
|
||||
#ifndef WIN32
|
||||
bool m_alloc;
|
||||
#endif
|
||||
private:
|
||||
bool pCanWrite;
|
||||
MMF_Struct* SharedMemory;
|
||||
#ifdef _WINDOWS
|
||||
HANDLE hMapObject;
|
||||
LPVOID lpvMem;
|
||||
#else
|
||||
void* lpvMem;
|
||||
MMFMutex* pMMFMutex;
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,126 @@
|
||||
#include "MMFMutex.h"
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
MMFMutex::MMFMutex( int key )
|
||||
{
|
||||
m_key = key;
|
||||
|
||||
if( m_key == 0 )
|
||||
{
|
||||
// initialize POSIX semaphore
|
||||
sem_init( &m_semaphore, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// currently, this thread does not own the semaphore
|
||||
m_owner = 0;
|
||||
m_recursive_count = 0;
|
||||
|
||||
// try to get an existing semaphore. the access permissions are "full access for everyone"
|
||||
m_id = semget(m_key, 1, 0x1b6);
|
||||
if( m_id == -1 )
|
||||
{
|
||||
// it doesn't exist yet, try to create a new one
|
||||
m_id = semget(m_key, 1, IPC_CREAT | 0x1b6);
|
||||
if( m_id != -1 )
|
||||
{
|
||||
// initialize it to 1
|
||||
semun data;
|
||||
data.val = 1;
|
||||
semctl(m_id, 0, SETVAL, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MMFMutex::~MMFMutex()
|
||||
{
|
||||
if( m_key == 0 )
|
||||
{
|
||||
sem_destroy(&m_semaphore);
|
||||
}
|
||||
else
|
||||
{
|
||||
semctl(m_id, 0, IPC_RMID, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool MMFMutex::Lock( uint32 dwTimeout )
|
||||
{
|
||||
if( m_owner == pthread_self() )
|
||||
{
|
||||
m_recursive_count++;
|
||||
return true;
|
||||
}
|
||||
bool bUseTimeout = (dwTimeout != 0);
|
||||
while(true) {
|
||||
bool bGotSemaphore = false;
|
||||
if( m_key == 0 )
|
||||
{
|
||||
bGotSemaphore = (sem_trywait(&m_semaphore) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct sembuf operations[1];
|
||||
operations[0].sem_num = 0;
|
||||
operations[0].sem_op = -1;
|
||||
operations[0].sem_flg = SEM_UNDO|IPC_NOWAIT;
|
||||
bGotSemaphore = (semop(m_id, operations, 1) >= 0);
|
||||
}
|
||||
if( bGotSemaphore )
|
||||
{
|
||||
m_owner = pthread_self();
|
||||
m_recursive_count = 1;
|
||||
return true;
|
||||
}
|
||||
sleep(1);
|
||||
if( bUseTimeout )
|
||||
{
|
||||
if( dwTimeout > 1000 )
|
||||
dwTimeout -= 1000;
|
||||
else
|
||||
dwTimeout = 0;
|
||||
|
||||
if( dwTimeout == 0 )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
void MMFMutex::Release(const MMF* pMMF)
|
||||
{
|
||||
if( m_owner != pthread_self() && pMMF->m_alloc != true )
|
||||
{
|
||||
//We're supposed to explode here with an assert
|
||||
//assert(false);
|
||||
}
|
||||
else if ( pMMF->m_alloc == true ){
|
||||
// Just do it nothing is useing but us
|
||||
return;
|
||||
}
|
||||
else if( m_recursive_count > 1 )
|
||||
{
|
||||
m_recursive_count--;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_key == 0 )
|
||||
{
|
||||
sem_post(&m_semaphore);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
struct sembuf operations[1];
|
||||
operations[0].sem_num = 0;
|
||||
operations[0].sem_op = 1;
|
||||
operations[0].sem_flg = SEM_UNDO;
|
||||
semop(m_id, operations, 1);
|
||||
}
|
||||
m_recursive_count = 0;
|
||||
m_owner = 0;
|
||||
}
|
||||
}
|
||||
#endif //!WIN32
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef MMFMUTEX_H
|
||||
#define MMFMUTEX_H
|
||||
#ifndef WIN32
|
||||
#include <sys/types.h> // moved before sys/shm.h for freeBSD
|
||||
#include <sys/shm.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <semaphore.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include "../common/types.h"
|
||||
|
||||
#include "MMF.h"
|
||||
|
||||
// the manuals say you have to define this struct your self.
|
||||
#if !defined FREEBSD || defined __NetBSD__ // for BSDs
|
||||
union semun
|
||||
{
|
||||
int val;
|
||||
struct semid_ds* buf;
|
||||
unsigned short int *array;
|
||||
struct seminfo *__buf;
|
||||
};
|
||||
#endif // for freeBSD
|
||||
|
||||
class MMFMutex
|
||||
{
|
||||
public:
|
||||
MMFMutex(int iIndex);
|
||||
virtual ~MMFMutex();
|
||||
bool Lock( uint32 dwTimeout = 0 );
|
||||
void Release(const MMF*);
|
||||
|
||||
protected:
|
||||
int m_id;
|
||||
key_t m_key;
|
||||
pthread_t m_owner;
|
||||
sem_t m_semaphore;
|
||||
int m_recursive_count;
|
||||
};
|
||||
#endif //!WIN32
|
||||
#endif
|
||||
@@ -0,0 +1,178 @@
|
||||
#include "../common/debug.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "NPCFactionLists.h"
|
||||
#include "../common/timer.h"
|
||||
#include "MMF.h"
|
||||
|
||||
MMF NPCFactionListsMMF;
|
||||
const MMFNPCFactionLists_Struct* MMFNPCFactionListsData = 0;
|
||||
MMFNPCFactionLists_Struct* MMFNPCFactionListsData_Writable = 0;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
extern "C" __declspec(dllexport) const NPCFactionList* GetNPCFactionList(uint32 id) {
|
||||
return pGetNPCFactionList(id);
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) bool AddNPCFactionList(uint32 id, const NPCFactionList* nfl) {
|
||||
return pAddNPCFactionList(id, nfl);
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) bool DLLLoadNPCFactionLists(CALLBACK_DBLoadNPCFactionLists cbDBLoadNPCFactionLists, uint32 iNPCFactionListStructSize, int32* iNPCFactionListsCount, uint32* iMaxNPCFactionListID, uint8 iMaxNPCFactions) {
|
||||
return pDLLLoadNPCFactionLists(cbDBLoadNPCFactionLists, iNPCFactionListStructSize, iNPCFactionListsCount, iMaxNPCFactionListID, iMaxNPCFactions);
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) bool SetNPCFaction(uint32 id, uint32* factionid, int32* factionvalue, int8 *factionnpcvalue, uint8 *factiontemp) {
|
||||
return pSetNPCFaction(id, factionid, factionvalue, factionnpcvalue, factiontemp);
|
||||
}
|
||||
#else
|
||||
extern "C" const NPCFactionList* GetNPCFactionList(uint32 id) {
|
||||
return pGetNPCFactionList(id);
|
||||
};
|
||||
|
||||
extern "C" bool AddNPCFactionList(uint32 id, const NPCFactionList* nfl) {
|
||||
return pAddNPCFactionList(id, nfl);
|
||||
};
|
||||
|
||||
extern "C" bool DLLLoadNPCFactionLists(CALLBACK_DBLoadNPCFactionLists cbDBLoadNPCFactionLists, uint32 iNPCFactionListStructSize, int32* iNPCFactionListsCount, uint32* iMaxNPCFactionListID, uint8 iMaxNPCFactions) {
|
||||
return pDLLLoadNPCFactionLists(cbDBLoadNPCFactionLists, iNPCFactionListStructSize, iNPCFactionListsCount, iMaxNPCFactionListID, iMaxNPCFactions);
|
||||
};
|
||||
|
||||
extern "C" bool SetNPCFaction(uint32 id, uint32* factionid, int32* factionvalue, int8 *factionnpcvalue, uint8 *factiontemp) {
|
||||
return pSetNPCFaction(id, factionid, factionvalue, factionnpcvalue, factiontemp);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool pAddNPCFactionList(uint32 id, const NPCFactionList* nfl) {
|
||||
if (!MMFNPCFactionListsData_Writable){
|
||||
if (EQDEBUG>=1) cout<<"[Debug] !MMFNPCFactionListsData_Writable"<<endl;
|
||||
return false;
|
||||
}
|
||||
if (id > MMF_MAX_NPCFactionList_ID || MMFNPCFactionListsData_Writable->NextFreeIndex >= MMFNPCFactionListsData_Writable->NPCFactionListCount){
|
||||
if (EQDEBUG>=1) cout<<"[Debug] id > MMF_MAX_NPCFactionList_ID || MMFNPCFactionListsData_Writable->NextFreeIndex >= MMFNPCFactionListsData_Writable->NPCFactionListCount"<<endl;
|
||||
return false;
|
||||
}
|
||||
if (MMFNPCFactionListsData_Writable->NPCFactionListIndex[id] != 0xFFFFFFFF){
|
||||
if (EQDEBUG>=1) cout<<"[Debug] MMFNPCFactionListsData_Writable->NPCFactionListIndex[id] != 0xFFFFFFFF"<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
MMFNPCFactionListsData_Writable->NPCFactionListIndex[id] = MMFNPCFactionListsData_Writable->NextFreeIndex++;
|
||||
memcpy(&MMFNPCFactionListsData_Writable->NPCFactionLists[MMFNPCFactionListsData_Writable->NPCFactionListIndex[id]], nfl, sizeof(NPCFactionList));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pSetNPCFaction(uint32 id, uint32* factionid, int32* factionvalue, int8 *factionnpcvalue, uint8 *factiontemp) {
|
||||
if (!MMFNPCFactionListsData_Writable) {
|
||||
if(EQDEBUG>=1) cout<<"[Debug] !MMFNPCFactionListsData_Writable"<<endl;
|
||||
return false;
|
||||
}
|
||||
if (id > MMF_MAX_NPCFactionList_ID) {
|
||||
if(EQDEBUG>=1) cout<<"[Debug] id > MMF_MAX_NPCFactionList_ID"<<endl;
|
||||
return false;
|
||||
}
|
||||
if (MMFNPCFactionListsData_Writable->NPCFactionListIndex[id] == 0xFFFFFFFF) {
|
||||
if(EQDEBUG>=1) cout<<"[Debug] MMFNPCFactionListsData_Writable->NPCFactionListIndex[id="<<id<<"] == 0xFFFFFFFF"<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i=0; i<MAX_NPC_FACTIONS; i++) {
|
||||
MMFNPCFactionListsData_Writable->NPCFactionLists[MMFNPCFactionListsData_Writable->NPCFactionListIndex[id]].factionid[i] = factionid[i];
|
||||
MMFNPCFactionListsData_Writable->NPCFactionLists[MMFNPCFactionListsData_Writable->NPCFactionListIndex[id]].factionvalue[i] = factionvalue[i];
|
||||
MMFNPCFactionListsData_Writable->NPCFactionLists[MMFNPCFactionListsData_Writable->NPCFactionListIndex[id]].factionnpcvalue[i] = factionnpcvalue[i];
|
||||
MMFNPCFactionListsData_Writable->NPCFactionLists[MMFNPCFactionListsData_Writable->NPCFactionListIndex[id]].factiontemp[i] = factiontemp[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pDLLLoadNPCFactionLists(CALLBACK_DBLoadNPCFactionLists cbDBLoadNPCFactionLists, uint32 iNPCFactionListStructSize, int32* iNPCFactionListsCount, uint32* iMaxNPCFactionListID, uint8 iMaxNPCFactions) {
|
||||
if (iNPCFactionListStructSize != sizeof(NPCFactionList)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCFactionLists: iNPCFactionListStructSize != sizeof(NPCFactionList)" << endl;
|
||||
cout << "NPCFactionList struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
if (iMaxNPCFactions != MAX_NPC_FACTIONS) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCFactionLists: iMaxNPCFactions != MAX_NPC_FACTIONS" << endl;
|
||||
cout << "NPCFactionList struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
if (*iMaxNPCFactionListID > MMF_MAX_NPCFactionList_ID) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCFactionLists: iMaxNPCFactions > MMF_MAX_NPCFactionList_ID" << endl;
|
||||
cout << "You need to increase the define in NPCFactionList.h." << endl;
|
||||
return false;
|
||||
}
|
||||
uint32 tmpMemSize = sizeof(MMFNPCFactionLists_Struct) + 256 + (sizeof(NPCFactionList) * (*iNPCFactionListsCount));
|
||||
if (NPCFactionListsMMF.Open("EQEMuFactionLists", tmpMemSize)) {
|
||||
// MMFNPCFactionListsData = (const MMFNPCFactionLists_Struct*) NPCFactionListsMMF.GetHandle();
|
||||
if (NPCFactionListsMMF.CanWrite()) {
|
||||
MMFNPCFactionListsData_Writable = (MMFNPCFactionLists_Struct*) NPCFactionListsMMF.GetWriteableHandle();
|
||||
if (!MMFNPCFactionListsData_Writable) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCFactionLists: !MMFNPCFactionListsData_Writable" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(MMFNPCFactionListsData_Writable, 0, tmpMemSize);
|
||||
for(int i=0; i<MMF_MAX_NPCFactionList_ID; i++)
|
||||
MMFNPCFactionListsData_Writable->NPCFactionListIndex[i] = 0xFFFFFFFF;
|
||||
MMFNPCFactionListsData_Writable->MaxNPCFactionListID = *iMaxNPCFactionListID;
|
||||
MMFNPCFactionListsData_Writable->NPCFactionListCount = *iNPCFactionListsCount;
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (!cbDBLoadNPCFactionLists(MMFNPCFactionListsData_Writable->NPCFactionListCount, MMFNPCFactionListsData_Writable->MaxNPCFactionListID)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCFactionLists: !cbDBLoadNPCFactionLists" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
MMFNPCFactionListsData_Writable = 0;
|
||||
NPCFactionListsMMF.SetLoaded();
|
||||
MMFNPCFactionListsData = (const MMFNPCFactionLists_Struct*) NPCFactionListsMMF.GetHandle();
|
||||
if (!MMFNPCFactionListsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCFactionLists: !MMFNPCFactionListsData (CanWrite=true)" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (!NPCFactionListsMMF.IsLoaded()) {
|
||||
Timer::SetCurrentTime();
|
||||
uint32 starttime = Timer::GetCurrentTime();
|
||||
while ((!NPCFactionListsMMF.IsLoaded()) && ((Timer::GetCurrentTime() - starttime) < 300000)) {
|
||||
Sleep(100);
|
||||
Timer::SetCurrentTime();
|
||||
}
|
||||
if (!NPCFactionListsMMF.IsLoaded()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCFactionLists: !NPCFactionListsMMF.IsLoaded() (timeout)" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MMFNPCFactionListsData = (const MMFNPCFactionLists_Struct*) NPCFactionListsMMF.GetHandle();
|
||||
if (!MMFNPCFactionListsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCFactionLists: !MMFNPCFactionListsData (CanWrite=false)" << endl;
|
||||
return false;
|
||||
}
|
||||
*iMaxNPCFactionListID = MMFNPCFactionListsData->MaxNPCFactionListID;
|
||||
*iNPCFactionListsCount = MMFNPCFactionListsData->NPCFactionListCount;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "Error Loading NPCFactionLists: NPCFactionLists.cpp: pDLLLoadNPCFactionLists: Open() == false" << endl;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const NPCFactionList* pGetNPCFactionList(uint32 id) {
|
||||
if (MMFNPCFactionListsData == 0 || (!NPCFactionListsMMF.IsLoaded()) || id > MMF_MAX_NPCFactionList_ID || MMFNPCFactionListsData->NPCFactionListIndex[id] == 0xFFFFFFFF)
|
||||
return 0;
|
||||
return &MMFNPCFactionListsData->NPCFactionLists[MMFNPCFactionListsData->NPCFactionListIndex[id]];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "../common/types.h"
|
||||
#include "../zone/features.h"
|
||||
#include "../zone/faction.h"
|
||||
#include "../common/EMuShareMem.h"
|
||||
|
||||
// MMF_MAX_NPCFactionList_ID: Make sure this is bigger than the highest NPCFactionList ID#
|
||||
#ifndef MMF_MAX_NPCFactionList_ID
|
||||
#define MMF_MAX_NPCFactionList_ID 50000
|
||||
#endif
|
||||
|
||||
struct MMFNPCFactionLists_Struct {
|
||||
uint32 MaxNPCFactionListID;
|
||||
uint32 NextFreeIndex;
|
||||
uint32 NPCFactionListCount;
|
||||
uint32 NPCFactionListIndex[MMF_MAX_NPCFactionList_ID+1];
|
||||
NPCFactionList NPCFactionLists[0];
|
||||
};
|
||||
|
||||
bool pDLLLoadNPCFactionLists(CALLBACK_DBLoadNPCFactionLists cbDBLoadNPCFactionLists, uint32 iNPCFactionListStructSize, int32* iNPCFactionListCount, uint32* iMaxNPCFactionListID, uint8 iMaxNPCFactions);
|
||||
bool pAddNPCFactionList(uint32 id, const NPCFactionList* nfl);
|
||||
bool pSetNPCFaction(uint32 id, uint32* factionid, int32* factionvalue, int8 *factionnpcvalue, uint8 *factiontemp);
|
||||
const NPCFactionList* pGetNPCFactionList(uint32 id);
|
||||
@@ -0,0 +1,137 @@
|
||||
#include "../common/debug.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "NPCTypes.h"
|
||||
#include "../common/timer.h"
|
||||
#include "MMF.h"
|
||||
|
||||
MMF NPCTypesMMF;
|
||||
const MMFNPCTypes_Struct* MMFNPCTypesData = 0;
|
||||
MMFNPCTypes_Struct* MMFNPCTypesData_Writable = 0;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
extern "C" __declspec(dllexport) const NPCType* GetNPCType(uint32 id) {
|
||||
return pGetNPCType(id);
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) bool AddNPCType(uint32 id, const NPCType* npctype) {
|
||||
return pAddNPCType(id, npctype);
|
||||
};
|
||||
|
||||
/*extern "C" __declspec(dllexport) bool DLLLoadNPCTypes(CALLBACK_DBLoadNPCTypes cbDBLoadNPCTypes, uint32 iNPCTypeStructSize, int32* iNPCTypesCount, uint32* iMaxNPCTypeID) {
|
||||
return pDLLLoadNPCTypes(cbDBLoadNPCTypes, iNPCTypeStructSize, iNPCTypesCount, iMaxNPCTypeID);
|
||||
};*/
|
||||
|
||||
#else
|
||||
extern "C" const NPCType* GetNPCType(uint32 id) {
|
||||
return pGetNPCType(id);
|
||||
};
|
||||
|
||||
extern "C" bool AddNPCType(uint32 id, const NPCType* npctype) {
|
||||
return pAddNPCType(id, npctype);
|
||||
};
|
||||
|
||||
extern "C" bool DLLLoadNPCTypes(CALLBACK_DBLoadNPCTypes cbDBLoadNPCTypes, uint32 iNPCTypeStructSize, int32* iNPCTypesCount, uint32* iMaxNPCTypeID) {
|
||||
return pDLLLoadNPCTypes(cbDBLoadNPCTypes, iNPCTypeStructSize, iNPCTypesCount, iMaxNPCTypeID);
|
||||
};
|
||||
#endif
|
||||
|
||||
bool pAddNPCType(uint32 id, const NPCType* npctype) {
|
||||
if (!MMFNPCTypesData_Writable)
|
||||
return false;
|
||||
if (id > MMF_MAX_NPCTYPE_ID || MMFNPCTypesData_Writable->NextFreeIndex >= MMFNPCTypesData_Writable->NPCTypeCount)
|
||||
return false;
|
||||
if (MMFNPCTypesData_Writable->NPCTypeIndex[id] != 0xFFFFFFFF)
|
||||
return false;
|
||||
|
||||
MMFNPCTypesData_Writable->NPCTypeIndex[id] = MMFNPCTypesData_Writable->NextFreeIndex++;
|
||||
memcpy(&MMFNPCTypesData_Writable->NPCTypes[MMFNPCTypesData_Writable->NPCTypeIndex[id]], npctype, sizeof(NPCType));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*bool pDLLLoadNPCTypes(CALLBACK_DBLoadNPCTypes cbDBLoadNPCTypes, uint32 iNPCTypeStructSize, int32* iNPCTypesCount, uint32* iMaxNPCTypeID) {
|
||||
if (iNPCTypeStructSize != sizeof(NPCType)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCTypes: iNPCTypeStructSize != sizeof(NPCType)" << endl;
|
||||
cout << "NPCType struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
if (*iMaxNPCTypeID > MMF_MAX_NPCTYPE_ID) {
|
||||
cout << "Error: EMuShareMem: pDLLLoadNPCTypes: iMaxNPCTypeID > MMF_MAX_NPCTYPE_ID" << endl;
|
||||
cout << "You need to increase the define in NPCTypes.h." << endl;
|
||||
return false;
|
||||
}
|
||||
uint32 tmpMemSize = sizeof(MMFNPCTypes_Struct) + 256 + (sizeof(NPCType) * (*iNPCTypesCount));
|
||||
if (NPCTypesMMF.Open("EQEMuNPCTypes", tmpMemSize)) {
|
||||
// MMFNPCTypesData = (const MMFNPCTypes_Struct*) NPCTypesMMF.GetHandle();
|
||||
if (NPCTypesMMF.CanWrite()) {
|
||||
MMFNPCTypesData_Writable = (MMFNPCTypes_Struct*) NPCTypesMMF.GetWriteableHandle();
|
||||
if (!MMFNPCTypesData_Writable) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCTypes: !MMFNPCTypesData_Writable" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(MMFNPCTypesData_Writable, 0, tmpMemSize);
|
||||
for(int i=0; i<MMF_MAX_NPCTYPE_ID; i++)
|
||||
MMFNPCTypesData_Writable->NPCTypeIndex[i] = 0xFFFFFFFF;
|
||||
MMFNPCTypesData_Writable->MaxNPCTypeID = *iMaxNPCTypeID;
|
||||
MMFNPCTypesData_Writable->NPCTypeCount = *iNPCTypesCount;
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (!cbDBLoadNPCTypes(MMFNPCTypesData_Writable->NPCTypeCount, MMFNPCTypesData_Writable->MaxNPCTypeID)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCTypes: !cbDBLoadNPCTypes" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
MMFNPCTypesData_Writable = 0;
|
||||
NPCTypesMMF.SetLoaded();
|
||||
MMFNPCTypesData = (const MMFNPCTypes_Struct*) NPCTypesMMF.GetHandle();
|
||||
if (!MMFNPCTypesData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCTypes: !MMFNPCTypesData (CanWrite=true)" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (!NPCTypesMMF.IsLoaded()) {
|
||||
Timer::SetCurrentTime();
|
||||
uint32 starttime = Timer::GetCurrentTime();
|
||||
while ((!NPCTypesMMF.IsLoaded()) && ((Timer::GetCurrentTime() - starttime) < 300000)) {
|
||||
Sleep(100);
|
||||
Timer::SetCurrentTime();
|
||||
}
|
||||
if (!NPCTypesMMF.IsLoaded()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCTypes: !NPCTypesMMF.IsLoaded() (timeout)" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MMFNPCTypesData = (const MMFNPCTypes_Struct*) NPCTypesMMF.GetHandle();
|
||||
if (!MMFNPCTypesData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadNPCTypes: !MMFNPCTypesData (CanWrite=false)" << endl;
|
||||
return false;
|
||||
}
|
||||
*iMaxNPCTypeID = MMFNPCTypesData->MaxNPCTypeID;
|
||||
*iNPCTypesCount = MMFNPCTypesData->NPCTypeCount;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "Error Loading NPCTypes: NPCTypes.cpp: pDLLLoadNPCTypes: Open() == false" << endl;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};*/
|
||||
|
||||
const NPCType* pGetNPCType(uint32 id) {
|
||||
if (MMFNPCTypesData == 0 || (!NPCTypesMMF.IsLoaded()) || id > MMF_MAX_NPCTYPE_ID || MMFNPCTypesData->NPCTypeIndex[id] == 0xFFFFFFFF)
|
||||
return 0;
|
||||
return &MMFNPCTypesData->NPCTypes[MMFNPCTypesData->NPCTypeIndex[id]];
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "../common/types.h"
|
||||
#include "../zone/zonedump.h"
|
||||
#include "../common/EMuShareMem.h"
|
||||
|
||||
// MMF_MAX_NPCTYPE_ID: Make sure this is bigger than the highest NPCType ID#
|
||||
#define MMF_MAX_NPCTYPE_ID 400000
|
||||
|
||||
struct MMFNPCTypes_Struct {
|
||||
uint32 MaxNPCTypeID;
|
||||
uint32 NextFreeIndex;
|
||||
uint32 NPCTypeCount;
|
||||
uint32 NPCTypeIndex[MMF_MAX_NPCTYPE_ID+1];
|
||||
NPCType NPCTypes[0];
|
||||
};
|
||||
|
||||
//bool pDLLLoadNPCTypes(CALLBACK_DBLoadNPCTypes cbDBLoadNPCTypes, uint32 iNPCTypeStructSize, int32* iNPCTypesCount, uint32* iMaxNPCTypeID);
|
||||
bool pAddNPCType(uint32 id, const NPCType* npctype);
|
||||
const NPCType* pGetNPCType(uint32 id);
|
||||
@@ -0,0 +1,140 @@
|
||||
#include "../common/debug.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "Opcodes.h"
|
||||
#include "../common/timer.h"
|
||||
#include "MMF.h"
|
||||
|
||||
MMF OpcodesMMF;
|
||||
const MMFOpcodes_Struct* MMFOpcodesData = 0;
|
||||
MMFOpcodes_Struct* MMFOpcodesData_Writable = 0;
|
||||
const uint16 *MMFOpcodesData_emu_to_eq = NULL;
|
||||
uint16 *MMFOpcodesData_emu_to_eq_write = NULL;
|
||||
|
||||
//we choose to store all opcodes as 16 bits, so if they are a different
|
||||
//size in emu, they are gunna get casted to 16 bits... prolly will never
|
||||
//be a problem, but I figured it was noteworthy
|
||||
|
||||
|
||||
DLLFUNC uint16 GetEQOpcode(uint16 emu_op) {
|
||||
if (MMFOpcodesData == 0 || (!OpcodesMMF.IsLoaded()) || emu_op >= MMFOpcodesData->EmuOpcodeCount )
|
||||
return 0;
|
||||
return MMFOpcodesData_emu_to_eq[emu_op];
|
||||
}
|
||||
|
||||
DLLFUNC uint16 GetEmuOpcode(uint16 eq_op) {
|
||||
if (MMFOpcodesData == 0 || (!OpcodesMMF.IsLoaded()) || eq_op >= MMFOpcodesData->EQOpcodeCount )
|
||||
return 0;
|
||||
return MMFOpcodesData->eq_to_emu[eq_op];
|
||||
}
|
||||
|
||||
DLLFUNC bool SetOpcodePair(uint16 emu_op, uint16 eq_op) {
|
||||
if (!MMFOpcodesData_Writable || !MMFOpcodesData_emu_to_eq_write)
|
||||
return false;
|
||||
if (emu_op >= MMFOpcodesData_Writable->EmuOpcodeCount || eq_op >= MMFOpcodesData_Writable->EQOpcodeCount)
|
||||
return false;
|
||||
|
||||
MMFOpcodesData_emu_to_eq_write[emu_op] = eq_op;
|
||||
MMFOpcodesData_Writable->eq_to_emu[eq_op] = emu_op;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DLLFUNC void ClearEQOpcodes() {
|
||||
if (!MMFOpcodesData_Writable)
|
||||
return;
|
||||
|
||||
memset(MMFOpcodesData_Writable->eq_to_emu, 0, sizeof(uint16)*MMFOpcodesData->EQOpcodeCount);
|
||||
|
||||
}
|
||||
|
||||
DLLFUNC bool DLLLoadOpcodes(CALLBACK_DBLoadOpcodes cb, uint32 opsize, uint32 eq_count, uint32 emu_count, const char *filename) {
|
||||
if(opsize != sizeof(uint16)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadOpcodes: opsize != sizeof(uint16)" << endl;
|
||||
cout << "Opcode size has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
uint32 tmpMemSize = sizeof(MMFOpcodes_Struct) + opsize * (eq_count+emu_count);
|
||||
if (OpcodesMMF.Open("EQEMuOpcodes", tmpMemSize)) {
|
||||
if (OpcodesMMF.CanWrite()) {
|
||||
MMFOpcodesData_Writable = (MMFOpcodes_Struct*) OpcodesMMF.GetWriteableHandle();
|
||||
if (!MMFOpcodesData_Writable) {
|
||||
cout << "Error: EMuShareMem: DLLLoadOpcodes: !MMFOpcodesData_Writable" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//emu_to_eq is right after eq_to_emu
|
||||
MMFOpcodesData_emu_to_eq = MMFOpcodesData_Writable->eq_to_emu + eq_count;
|
||||
MMFOpcodesData_emu_to_eq_write = MMFOpcodesData_Writable->eq_to_emu + eq_count;
|
||||
|
||||
//we need to memset the eq opcodes
|
||||
memset(MMFOpcodesData_Writable->eq_to_emu, 0, sizeof(uint16)*eq_count);
|
||||
|
||||
MMFOpcodesData_Writable->EQOpcodeCount = eq_count;
|
||||
MMFOpcodesData_Writable->EmuOpcodeCount = emu_count;
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (!cb(filename)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadOpcodes: !cbDBLoadOpcodes" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//we dont disable the write handle here, so we can reload them
|
||||
//MMFOpcodesData_Writable = 0;
|
||||
|
||||
OpcodesMMF.SetLoaded();
|
||||
MMFOpcodesData = (const MMFOpcodes_Struct*) OpcodesMMF.GetHandle();
|
||||
if (!MMFOpcodesData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadOpcodes: !MMFOpcodesData (CanWrite=true)" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (!OpcodesMMF.IsLoaded()) {
|
||||
Timer::SetCurrentTime();
|
||||
uint32 starttime = Timer::GetCurrentTime();
|
||||
while ((!OpcodesMMF.IsLoaded()) && ((Timer::GetCurrentTime() - starttime) < 300000)) {
|
||||
Sleep(10);
|
||||
Timer::SetCurrentTime();
|
||||
}
|
||||
if (!OpcodesMMF.IsLoaded()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadOpcodes: !OpcodesMMF.IsLoaded() (timeout)" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MMFOpcodesData = (const MMFOpcodes_Struct*) OpcodesMMF.GetHandle();
|
||||
if (!MMFOpcodesData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadOpcodes: !MMFOpcodesData (CanWrite=false)" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//emu_to_eq is right after eq_to_emu
|
||||
MMFOpcodesData_emu_to_eq = MMFOpcodesData->eq_to_emu + MMFOpcodesData->EQOpcodeCount;
|
||||
|
||||
//cheat a little so we can retain writeable handles for reloading
|
||||
MMFOpcodesData_Writable = const_cast<MMFOpcodes_Struct*>(MMFOpcodesData);
|
||||
MMFOpcodesData_emu_to_eq_write = MMFOpcodesData_Writable->eq_to_emu + eq_count;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "Error Loading Opcodes: Opcodes.cpp: pDLLLoadOpcodes: ret == 0, size = " << tmpMemSize << endl;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "../common/types.h"
|
||||
#include "../common/EMuShareMem.h"
|
||||
|
||||
struct MMFOpcodes_Struct {
|
||||
uint32 EQOpcodeCount;
|
||||
uint32 EmuOpcodeCount;
|
||||
uint16 eq_to_emu[0];
|
||||
//uint16 emu_to_eq[0]; //logical, not really here... EQOpcodeCount indexes in
|
||||
};
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
#include "../common/debug.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "SkillCaps.h"
|
||||
#include "../common/timer.h"
|
||||
#include "MMF.h"
|
||||
|
||||
MMF SkillCapsMMF;
|
||||
const MMFSkillCaps_Struct* MMFSkillCapsData = 0;
|
||||
MMFSkillCaps_Struct* MMFSkillCapsData_Writable = 0;
|
||||
|
||||
|
||||
DLLFUNC uint16 GetSkillCap(uint8 Class_, uint8 Skill, uint8 Level) {
|
||||
if (MMFSkillCapsData == 0 || (!SkillCapsMMF.IsLoaded()))
|
||||
return 0;
|
||||
if (Class_ >= MMFSkillCapsData->ClassCount || Skill >= MMFSkillCapsData->SkillCount || Level >= MMFSkillCapsData->LevelCount)
|
||||
return(0);
|
||||
|
||||
uint32 index =
|
||||
(((Class_ * MMFSkillCapsData->SkillCount) + Skill) * MMFSkillCapsData->LevelCount)
|
||||
+ Level;
|
||||
|
||||
return MMFSkillCapsData->caps[index];
|
||||
}
|
||||
|
||||
DLLFUNC bool SetSkillCap(uint8 Class_, uint8 Skill, uint8 Level, uint16 cap) {
|
||||
if (!MMFSkillCapsData_Writable)
|
||||
return false;
|
||||
if (Class_ >= MMFSkillCapsData_Writable->ClassCount || Skill >= MMFSkillCapsData_Writable->SkillCount || Level >= MMFSkillCapsData_Writable->LevelCount)
|
||||
return false;
|
||||
|
||||
uint32 index =
|
||||
(((Class_ * MMFSkillCapsData_Writable->SkillCount) + Skill) * MMFSkillCapsData_Writable->LevelCount)
|
||||
+ Level;
|
||||
|
||||
MMFSkillCapsData_Writable->caps[index] = cap;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DLLFUNC uint8 GetTrainLevel(uint8 Class_, uint8 Skill, uint8 Level){
|
||||
if (MMFSkillCapsData == 0 || (!SkillCapsMMF.IsLoaded()))
|
||||
return 0;
|
||||
if (Class_ >= MMFSkillCapsData->ClassCount || Skill >= MMFSkillCapsData->SkillCount || Level >= MMFSkillCapsData->LevelCount)
|
||||
return(0);
|
||||
|
||||
uint32 index = (((Class_ * MMFSkillCapsData->SkillCount) + Skill) * MMFSkillCapsData->LevelCount);
|
||||
|
||||
for(int x = 0; x < Level; x++){
|
||||
if(MMFSkillCapsData->caps[index + x]){
|
||||
return (x);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
DLLFUNC void ClearSkillCaps() {
|
||||
if (!MMFSkillCapsData_Writable)
|
||||
return;
|
||||
|
||||
memset(MMFSkillCapsData_Writable->caps, 0,
|
||||
sizeof(uint16)*(MMFSkillCapsData->ClassCount*MMFSkillCapsData->SkillCount*MMFSkillCapsData->LevelCount));
|
||||
|
||||
}
|
||||
|
||||
DLLFUNC bool LoadSkillCaps(CALLBACK_DBLoadSkillCaps cb, uint32 opsize, uint8 ClassCount, uint8 SkillCount, uint8 LevelCount) {
|
||||
if(opsize != sizeof(uint16)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSkillCaps: opsize != sizeof(uint16)" << endl;
|
||||
cout << "SkillCap size has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
uint32 tmpMemSize = sizeof(MMFSkillCaps_Struct) + opsize * (ClassCount*SkillCount*LevelCount);
|
||||
if (SkillCapsMMF.Open("EQEMuKSkillCaps", tmpMemSize)) {
|
||||
if (SkillCapsMMF.CanWrite()) {
|
||||
MMFSkillCapsData_Writable = (MMFSkillCaps_Struct*) SkillCapsMMF.GetWriteableHandle();
|
||||
if (!MMFSkillCapsData_Writable) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSkillCaps: !MMFSkillCapsData_Writable" << endl;
|
||||
return false;
|
||||
}
|
||||
//we need to memset the eq SkillCaps
|
||||
memset(MMFSkillCapsData_Writable->caps, 0, sizeof(uint16)*(ClassCount*SkillCount*LevelCount));
|
||||
|
||||
MMFSkillCapsData_Writable->ClassCount = ClassCount;
|
||||
MMFSkillCapsData_Writable->SkillCount = SkillCount;
|
||||
MMFSkillCapsData_Writable->LevelCount = LevelCount;
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (!cb()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSkillCaps: !cbDBLoadSkillCaps" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
MMFSkillCapsData_Writable = 0;
|
||||
|
||||
SkillCapsMMF.SetLoaded();
|
||||
MMFSkillCapsData = (const MMFSkillCaps_Struct*) SkillCapsMMF.GetHandle();
|
||||
if (!MMFSkillCapsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSkillCaps: !MMFSkillCapsData (CanWrite=true)" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (!SkillCapsMMF.IsLoaded()) {
|
||||
Timer::SetCurrentTime();
|
||||
uint32 starttime = Timer::GetCurrentTime();
|
||||
while ((!SkillCapsMMF.IsLoaded()) && ((Timer::GetCurrentTime() - starttime) < 300000)) {
|
||||
Sleep(10);
|
||||
Timer::SetCurrentTime();
|
||||
}
|
||||
if (!SkillCapsMMF.IsLoaded()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSkillCaps: !SkillCapsMMF.IsLoaded() (timeout)" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MMFSkillCapsData = (const MMFSkillCaps_Struct*) SkillCapsMMF.GetHandle();
|
||||
if (!MMFSkillCapsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSkillCaps: !MMFSkillCapsData (CanWrite=false)" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "Error Loading SkillCaps: SkillCaps.cpp: pDLLLoadSkillCaps: ret == 0, size = " << tmpMemSize << endl;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "../common/types.h"
|
||||
#include "../common/EMuShareMem.h"
|
||||
|
||||
struct MMFSkillCaps_Struct {
|
||||
uint8 ClassCount;
|
||||
uint8 SkillCount;
|
||||
uint8 LevelCount;
|
||||
uint16 caps[0];
|
||||
};
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#include "../common/debug.h"
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../common/unix.h"
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "Spells.h"
|
||||
#include "../common/timer.h"
|
||||
//#include "../zone/masterentity.h"
|
||||
#include "MMF.h"
|
||||
|
||||
MMF SpellsMMF;
|
||||
const MMFSpells_Struct* MMFSpellsData = 0;
|
||||
MMFSpells_Struct* MMFSpellsData_Writable = 0;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
extern "C" __declspec(dllexport) bool DLLLoadSPDat(const CALLBACK_FileLoadSPDat cbFileLoadSPDat, const void** oSpellsPointer, int32* oSPDAT_RECORDS, uint32 iSPDat_Struct_Size) {
|
||||
return pDLLLoadSPDat(cbFileLoadSPDat, oSpellsPointer, oSPDAT_RECORDS, iSPDat_Struct_Size);
|
||||
};
|
||||
#else
|
||||
extern "C" bool DLLLoadSPDat(const CALLBACK_FileLoadSPDat cbFileLoadSPDat, const void** oSpellsPointer, int32* oSPDAT_RECORDS, uint32 iSPDat_Struct_Size) {
|
||||
return pDLLLoadSPDat(cbFileLoadSPDat, oSpellsPointer, oSPDAT_RECORDS, iSPDat_Struct_Size);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
bool pDLLLoadSPDat(const CALLBACK_FileLoadSPDat cbFileLoadSPDat, const void** oSpellsPointer, int32* oSPDAT_RECORDS, uint32 iSPDat_Struct_Size) {
|
||||
if (iSPDat_Struct_Size != sizeof(SPDat_Spell_Struct)) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSPDat: iSPDat_Struct_Size != sizeof(SPDat_Spell_Struct)" << endl;
|
||||
cout << "SPDat_Spell_Struct has changed, EMuShareMem.dll needs to be recompiled." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 tmpMemSize = sizeof(MMFSpells_Struct) + 256 + (sizeof(SPDat_Spell_Struct) * (*oSPDAT_RECORDS));
|
||||
if (SpellsMMF.Open("EQEMuSpells", tmpMemSize)) {
|
||||
if (SpellsMMF.CanWrite()) {
|
||||
MMFSpellsData_Writable = (MMFSpells_Struct*) SpellsMMF.GetWriteableHandle();
|
||||
if (!MMFSpellsData_Writable) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSPDat: !MMFSpellsData_Writable" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(MMFSpellsData_Writable, 0, tmpMemSize);
|
||||
MMFSpellsData_Writable->SPDAT_RECORDS = *oSPDAT_RECORDS;
|
||||
// use a callback so the DB functions are done in the main exe
|
||||
// this way the DLL doesnt have to open a connection to mysql
|
||||
if (MMFSpellsData_Writable->SPDAT_RECORDS > 0) {
|
||||
cbFileLoadSPDat(&MMFSpellsData_Writable->spells[0], MMFSpellsData_Writable->SPDAT_RECORDS-1);
|
||||
*oSpellsPointer = &MMFSpellsData_Writable->spells[0];
|
||||
}
|
||||
else
|
||||
*oSpellsPointer = 0;
|
||||
|
||||
MMFSpellsData_Writable = 0;
|
||||
SpellsMMF.SetLoaded();
|
||||
MMFSpellsData = (const MMFSpells_Struct*) SpellsMMF.GetHandle();
|
||||
if (!MMFSpellsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSPDat: !MMFSpellsData (CanWrite=true)" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (!SpellsMMF.IsLoaded()) {
|
||||
Timer::SetCurrentTime();
|
||||
uint32 starttime = Timer::GetCurrentTime();
|
||||
while ((!SpellsMMF.IsLoaded()) && ((Timer::GetCurrentTime() - starttime) < 300000)) {
|
||||
Sleep(100);
|
||||
Timer::SetCurrentTime();
|
||||
}
|
||||
if (!SpellsMMF.IsLoaded()) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSPDat: !SpellsMMF.IsLoaded() (timeout)" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MMFSpellsData = (const MMFSpells_Struct*) SpellsMMF.GetHandle();
|
||||
if (!MMFSpellsData) {
|
||||
cout << "Error: EMuShareMem: DLLLoadSPDat: !SpellsMMF (CanWrite=false)" << endl;
|
||||
return false;
|
||||
}
|
||||
*oSPDAT_RECORDS = MMFSpellsData->SPDAT_RECORDS;
|
||||
if (MMFSpellsData->SPDAT_RECORDS > 0)
|
||||
*oSpellsPointer = &MMFSpellsData->spells[0];
|
||||
else
|
||||
*oSpellsPointer = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "Error Loading SPDat: Spells.cpp: pDLLLoadSPDat: Open() == false" << endl;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef MEMSHARE_SPELLS_H
|
||||
#define MEMSHARE_SPELLS_H
|
||||
|
||||
#include "../common/types.h"
|
||||
#include "../zone/spdat.h"
|
||||
#include "../common/EMuShareMem.h"
|
||||
|
||||
struct MMFSpells_Struct {
|
||||
uint32 SPDAT_RECORDS; // maxspellid + 1, size of array
|
||||
SPDat_Spell_Struct spells[0];
|
||||
};
|
||||
|
||||
bool pDLLLoadSPDat(const CALLBACK_FileLoadSPDat cbFileLoadSPDat, const void** oSpellsPointer, int32* oSPDAT_RECORDS, uint32 iSPDat_Struct_Size);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user