Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: D2BS.cpp
- ===================================================================
- --- D2BS.cpp (revision 1689)
- +++ D2BS.cpp (working copy)
- @@ -18,7 +18,7 @@
- #endif
- static HANDLE hD2Thread = INVALID_HANDLE_VALUE;
- -
- +static HANDLE hEventThread = INVALID_HANDLE_VALUE;
- BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved)
- {
- switch(dwReason)
- @@ -76,6 +76,7 @@
- BOOL Startup(void)
- {
- + InitializeCriticalSection(&Vars.cEventSection);
- InitializeCriticalSection(&Vars.cRoomSection);
- InitializeCriticalSection(&Vars.cMiscSection);
- InitializeCriticalSection(&Vars.cScreenhookSection);
- @@ -103,7 +104,7 @@
- if((hD2Thread = CreateThread(NULL, NULL, D2Thread, NULL, NULL, NULL)) == NULL)
- return FALSE;
- -
- + hEventThread = CreateThread(0, 0, EventThread, NULL, 0, 0);
- return TRUE;
- }
- Index: D2BS.h
- ===================================================================
- --- D2BS.h (revision 1689)
- +++ D2BS.h (working copy)
- @@ -6,7 +6,7 @@
- #define XP_WIN
- #define JS_THREADSAFE
- -#define D2BS_VERSION "1.4.1688"
- +#define D2BS_VERSION "1.4.1689"
- #include <windows.h>
- #include <vector>
- @@ -78,7 +78,8 @@
- std::map<unsigned __int32, CellFile*> mCachedCellFiles;
- std::vector<std::pair<DWORD, DWORD> > vUnitList;
- -
- + std::list<Event*> EventList;
- + CRITICAL_SECTION cEventSection;
- CRITICAL_SECTION cRoomSection;
- CRITICAL_SECTION cMiscSection;
- CRITICAL_SECTION cScreenhookSection;
- Index: D2Handlers.cpp
- ===================================================================
- --- D2Handlers.cpp (revision 1689)
- +++ D2Handlers.cpp (working copy)
- @@ -349,7 +349,7 @@
- break;
- case WM_MOUSEMOVE:
- // would be nice to enable these events but they bog down too much
- - //MouseMoveEvent(pt);
- + MouseMoveEvent(pt);
- //Genhook::ForEachVisibleHook(HoverHook, &helper, 1);
- break;
- }
- Index: Map/Diablo_II/ActMap.cpp
- ===================================================================
- --- Map/Diablo_II/ActMap.cpp (revision 1689)
- +++ Map/Diablo_II/ActMap.cpp (working copy)
- @@ -208,7 +208,8 @@
- return val;
- }
- -void ActMap::CleanUp(void){
- +void ActMap::CleanUp(void) const
- +{
- for(RoomList::iterator it = RoomsAdded.begin(); it != RoomsAdded.end(); it++)
- RemoveRoomData(*it);
- Index: Map/Diablo_II/ActMap.h
- ===================================================================
- --- Map/Diablo_II/ActMap.h (revision 1689)
- +++ Map/Diablo_II/ActMap.h (working copy)
- @@ -49,8 +49,7 @@
- class ActMap : public Map
- {
- public:
- - void ActMap::CleanUp(void);
- -
- +
- enum CollisionFlag {
- None = 0x0000,
- BlockWalk = 0x0001,
- @@ -114,7 +113,8 @@
- ~ActMap(void);
- public:
- -
- + void CleanUp(void) const;
- +
- static ActMap* GetMap(Level* level);
- static void ClearCache(void);
- void Dump(const char* file, const PointList& points) const;
- Index: Map/Diablo_II/LevelMap.cpp
- ===================================================================
- --- Map/Diablo_II/LevelMap.cpp (revision 1689)
- +++ Map/Diablo_II/LevelMap.cpp (working copy)
- @@ -16,7 +16,10 @@
- cache[level->dwLevelNo] = map;
- return map;
- }
- -
- +void LevelMap::CleanUp(void) const
- +{
- + //Dummy Sub here because act map has it
- +}
- void LevelMap::ClearCache(void)
- {
- LevelMapList::iterator end = cache.end();
- Index: Map/Diablo_II/LevelMap.h
- ===================================================================
- --- Map/Diablo_II/LevelMap.h (revision 1689)
- +++ Map/Diablo_II/LevelMap.h (working copy)
- @@ -42,7 +42,7 @@
- class LevelMap : public Map
- {
- public:
- - void LevelMap::CleanUp(void);
- +
- enum CollisionFlag {
- None = 0x0000,
- @@ -116,11 +116,11 @@
- ~LevelMap(void);
- public:
- -
- +
- static LevelMap* GetMap(Level* level);
- static void ClearCache(void);
- void Dump(const char* file, const PointList& points) const;
- -
- + void CleanUp(void) const;
- Point AbsToRelative(const Point& point) const;
- Point RelativeToAbs(const Point& point) const;
- Index: Map/Map.h
- ===================================================================
- --- Map/Map.h (revision 1689)
- +++ Map/Map.h (working copy)
- @@ -14,7 +14,7 @@
- {
- public:
- virtual void Dump(const char* file, const PointList& points) const = 0;
- -
- + virtual void CleanUp(void) const = 0;
- virtual int GetWidth(void) const = 0;
- virtual int GetHeight(void) const = 0;
- Index: Map/Path/AStarPath.h
- ===================================================================
- --- Map/Path/AStarPath.h (revision 1689)
- +++ Map/Path/AStarPath.h (working copy)
- @@ -78,7 +78,7 @@
- alloc.construct(begin, Node(start, NULL, 0, estimate(map, start, end)));
- nodes.push_back(begin);
- open.push(begin);
- -
- + DWORD ticks = GetTickCount();
- while(!open.empty())
- {
- Node* current = open.top();
- @@ -91,7 +91,16 @@
- *result = current;
- return;
- }
- -
- + // this is to make d2 not completly freeze on long paths.
- + if (GetTickCount() - ticks > 500){
- + map->CleanUp();
- + LeaveCriticalSection(&Vars.cGameLoopSection);
- + InterlockedDecrement(&Vars.SectionCount);
- + Sleep(1);
- + InterlockedIncrement(&Vars.SectionCount);
- + EnterCriticalSection(&Vars.cGameLoopSection);
- + ticks=GetTickCount();
- + }
- bool result = closed.insert(current->point).second;
- assert(result == true);
- (void)(result); // shut up compiler about unused variable warning
- @@ -134,7 +143,7 @@
- {
- Node* result = NULL;
- Point start = _start, end = _end;
- -
- +
- // if we don't have a valid start and end, try mutating the points
- if(reducer->Reject(start, abs))
- reducer->MutatePoint(start, abs);
- Index: Script.cpp
- ===================================================================
- --- Script.cpp (revision 1689)
- +++ Script.cpp (working copy)
- @@ -433,10 +433,24 @@
- evt->argc = argc;
- evt->argv = argv;
- evt->object = globalObject;
- +
- + int timeout = 0;
- + while(! TryEnterCriticalSection(&Vars.cEventSection) )
- + {
- + timeout++ ;
- + if(timeout > 3)
- + {
- + HANDLE hThread;
- + hThread = CreateThread(0, 0, FuncThread, evt, 0, 0);
- + CloseHandle(hThread);
- + return;
- + }
- + Sleep(10);
- + }
- - HANDLE hThread;
- - hThread = CreateThread(0, 0, FuncThread, evt, 0, 0);
- - CloseHandle(hThread);
- + Vars.EventList.push_front(evt);
- + LeaveCriticalSection(&Vars.cEventSection);
- +
- }
- bool Script::ExecEvent(char* evtName, uintN argc, AutoRoot** argv)
- {
- @@ -593,3 +607,90 @@
- return block;
- }
- +DWORD WINAPI EventThread(LPVOID lpParam)
- +{
- +
- + while(Vars.bNeedShutdown)
- + {
- + Sleep(10);
- + while(Vars.EventList.size() > 0)
- + {
- + EnterCriticalSection(&Vars.cEventSection);
- + Event* evt = Vars.EventList.back();
- + Vars.EventList.pop_back();
- + LeaveCriticalSection(&Vars.cEventSection);
- +
- + JSContext* cx = JS_NewContext(ScriptEngine::GetRuntime(), 8192);
- + JS_SetContextPrivate(cx, evt->owner);
- + JS_BeginRequest(cx);
- +
- + callEventFunction(cx,evt); // call the first event
- + bool match = false; // vars to keep event list unlocked dont want the list locked while in event call
- + bool fullSearch = false;
- + while (!fullSearch)
- + {
- + match = false;
- + EnterCriticalSection(&Vars.cEventSection); // call any other events on the que with the same script
- + for(list<Event*>::iterator it = Vars.EventList.begin(); it != Vars.EventList.end(); it++)
- + {
- + if((*it)->owner->GetThreadId() == evt->owner->GetThreadId())
- + {
- + match = true;
- + evt=(*it);
- + Vars.EventList.erase(it);
- + break;
- + }
- + }
- + LeaveCriticalSection(&Vars.cEventSection);
- + if(match)
- + callEventFunction(cx,evt);
- + else
- + fullSearch = true;
- + }
- +
- + JS_DestroyContextNoGC(cx);
- + // we have to clean up the event
- + for(uintN i = 0; i < evt->argc; i++)
- + {
- + evt->argv[i]->Release();
- + if(evt->argv[i])
- + delete evt->argv[i];
- + }
- + if(evt->argv)
- + delete[] evt->argv;
- + delete evt;
- + }
- + }
- + return true;
- +}
- +bool callEventFunction(JSContext* cx ,Event* evt)
- +{
- + bool block =false;
- + if(evt->owner->IsRunning() && !(evt->owner->GetState() == InGame && ClientState() != ClientStateInGame))
- + {
- + jsval* args = new jsval[evt->argc];
- + for(uintN i = 0; i < evt->argc; i++)
- + {
- + args[i] = *evt->argv[i]->value();
- + if(JS_AddRoot(&args[i]) == JS_FALSE)
- + {
- + if(evt->argv)
- + delete[] evt->argv;
- + delete evt;
- + return false;
- + }
- + }
- + jsval rval = JSVAL_VOID;
- +
- + for(FunctionList::iterator it = evt->functions.begin(); it != evt->functions.end(); it++)
- + {
- + JS_CallFunctionValue(cx, evt->object, *(*it)->value(), evt->argc, args, &rval);
- + block |= (JSVAL_IS_BOOLEAN(rval) && JSVAL_TO_BOOLEAN(rval));
- + }
- +
- + for(uintN i = 0; i < evt->argc; i++)
- + JS_RemoveRoot(&args[i]);
- + delete[] args;
- + }
- +return block;
- +}
- Index: Script.h
- ===================================================================
- --- Script.h (revision 1689)
- +++ Script.h (working copy)
- @@ -107,3 +107,5 @@
- DWORD WINAPI RunCommandThread(void* data);
- DWORD WINAPI ScriptThread(void* data);
- DWORD WINAPI FuncThread(void* data);
- +DWORD WINAPI EventThread(LPVOID lpParam);
- +bool callEventFunction(JSContext* cx ,Event* evt);
- \ No newline at end of file
Add Comment
Please, Sign In to add comment