Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: Control.cpp
- ===================================================================
- --- Control.cpp (revision 1003)
- +++ Control.cpp (working copy)
- -163,7 +163,7 @@
- return false;
- }
- -BOOL OOG_CreateCharacter(char* szCharacter, int type, bool hardcore, bool ladder)
- +BOOL OOG_CreateCharacter(char* szCharacter, int type, bool hardcore, bool ladder, bool expansion)
- {
- if(OOG_GetLocation() != OOG_CHAR_SELECT || strlen(szCharacter) > 15 || type > 6 || type < 0)
- return FALSE;
- -203,7 +203,7 @@
- return FALSE; // something bad happened?
- // set the name
- -// ctrl = findControl();
- + //ctrl = findControl();
- // still need to find the name editbox, set the name, and click the various
- // checkboxes and the ok button
- Index: Control.h
- ===================================================================
- --- Control.h (revision 1003)
- +++ Control.h (working copy)
- -6,7 +6,7 @@
- Control* findControl(int Type, int LocaleID, int Disabled, int PosX, int PosY, int SizeX, int SizeY);
- Control* findControl(int Type, char* Text, int Disabled, int PosX, int PosY, int SizeX, int SizeY);
- bool clickControl(Control* pControl, int x = -1, int y = -1);
- -BOOL OOG_CreateCharacter(char* szCharacter, int type, bool hardcore, bool ladder);
- +BOOL OOG_CreateCharacter(char* szCharacter, int type, bool hardcore, bool ladder, bool expansion);
- BOOL OOG_SelectCharacter(char * szCharacter);
- BOOL OOG_SelectGateway(char * szGateway, size_t strSize);
- void SetControlText(Control* pControl, const char* Text);
- Index: Core.cpp
- ===================================================================
- --- Core.cpp (revision 1008)
- +++ Core.cpp (working copy)
- -18,12 +18,11 @@
- if(str.length() < 1 || maxlen < 2)
- return false;
- - size_t pos, len;
- + size_t pos;
- string tmp(str);
- while(tmp.length() > maxlen)
- {
- - len = tmp.length();
- // maxlen-1 since std::string::npos indexes from 0
- pos = tmp.find_last_of(delim, maxlen-1);
- if(!pos || pos == string::npos)
- -44,11 +43,9 @@
- else
- DebugBreak();
- }
- - if(!tmp.length())
- - DebugBreak();
- - if(tmp.length())
- - lst.push_back(tmp);
- + ASSERT(tmp.length());
- + lst.push_back(tmp);
- return true;
- }
- -68,42 +65,39 @@
- replace(str, str + len, REPLACE_CHAR, '%');
- - const uint maxlen = 98;
- -
- // Break into lines through \n.
- list<string> lines;
- string temp;
- stringstream ss(str);
- +
- + delete[] str;
- + str = NULL;
- +
- + const uint maxlen = 98;
- +
- while(getline(ss, temp))
- SplitLines(temp, maxlen, ' ', lines);
- EnterCriticalSection(&Vars.cPrintSection);
- - if(Vars.bUseGamePrint)
- +
- + for(list<string>::iterator it = lines.begin(); it != lines.end(); ++it)
- {
- - if(ClientState() == ClientStateInGame)
- + if(Vars.bUseGamePrint)
- {
- - // Convert and send every line.
- - for(list<string>::iterator it = lines.begin(); it != lines.end(); ++it)
- + if(ClientState() == ClientStateInGame)
- {
- - wchar_t * output = AnsiToUnicode(it->c_str());
- + wchar_t *output = AnsiToUnicode(it->c_str());
- D2CLIENT_PrintGameString(output, 0);
- delete [] output;
- }
- + else if(ClientState() == ClientStateMenu && findControl(4, (char *)NULL, -1, 28, 410, 354, 298))
- + D2MULTI_PrintChannelText((char* )it->c_str(), 0);
- }
- - else if(ClientState() == ClientStateMenu && findControl(4, (char *)NULL, -1, 28, 410, 354, 298))
- - {
- - // TODO: Double check this function, make sure it is working as intended.
- - for(list<string>::iterator it = lines.begin(); it != lines.end(); ++it)
- - D2MULTI_PrintChannelText((char* )it->c_str(), 0);
- - }
- - }
- - for(list<string>::iterator it = lines.begin(); it != lines.end(); ++it)
- + else
- Console::AddLine(*it);
- + }
- LeaveCriticalSection(&Vars.cPrintSection);
- -
- - delete[] str;
- - str = NULL;
- }
- void __declspec(naked) __fastcall Say_ASM(DWORD dwPtr)
- Index: D2Handlers.cpp
- ===================================================================
- --- D2Handlers.cpp (revision 1003)
- +++ D2Handlers.cpp (working copy)
- -36,8 +36,9 @@
- ClientGameState oldState = ClientState();
- while(Vars.bActive)
- {
- + // TODO look at this more
- ClientGameState state = ClientState();
- - if(oldState != state)
- + if((state == ClientStateInGame || state == ClientStateMenu) && oldState != state)
- {
- // we switched from in game to out or something
- JS_TriggerAllOperationCallbacks(ScriptEngine::GetRuntime());
- -55,11 +56,11 @@
- (!IsTownLevel(GetPlayerArea()) &&
- (Vars.nChickenHP && Vars.nChickenHP >= GetUnitHP(D2CLIENT_GetPlayerUnit())) ||
- (Vars.nChickenMP && Vars.nChickenMP >= GetUnitMP(D2CLIENT_GetPlayerUnit()))))
- - D2CLIENT_ExitGame();
- + D2CLIENT_ExitGame();
- }
- else
- {
- - Sleep(1000);
- + //Sleep(1000);
- Vars.dwGameTime = GetTickCount();
- D2CLIENT_InitInventory();
- -81,11 +82,10 @@
- }
- break;
- }
- - case ClientStateBusy:
- - case ClientStateNull:
- + default:
- break;
- }
- - Sleep(50);
- + Sleep(10);
- }
- ScriptEngine::Shutdown();
- -98,16 +98,14 @@
- if(Vars.bDontCatchNextMsg)
- {
- Vars.bDontCatchNextMsg = FALSE;
- - return NULL;
- + return 0;
- }
- char* szBuffer = UnicodeToAnsi(wMsg);
- bool result = false;
- if(szBuffer[0] == '.')
- - {
- result = ProcessCommand(szBuffer+1, false);
- - }
- delete[] szBuffer;
- -129,7 +127,7 @@
- case 0xA7: return DelayedStateHandler(pPacket, dwSize);
- }
- - return TRUE;
- + return 1;
- }
- LONG WINAPI GameEventHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- -181,7 +179,7 @@
- bool chatBoxOpen = gameState ? !!D2CLIENT_GetUIState(5) : false;
- bool escMenuOpen = gameState ? !!D2CLIENT_GetUIState(9) : false;
- - if (altState && wParam == VK_F4)
- + if(altState && wParam == VK_F4)
- return CallNextHookEx(NULL, code, wParam, lParam);
- if(Vars.bBlockKeys)
- -198,7 +196,7 @@
- return CallNextHookEx(NULL, code, wParam, lParam);
- }
- - }
- + }
- else if(wParam == VK_ESCAPE && Console::IsVisible())
- {
- if(isDown && !isRepeat && code == HC_ACTION )
- -323,7 +321,7 @@
- DrawLogo();
- Console::Draw();
- }
- - Sleep(10);
- + Sleep(1);
- }
- void GameDrawOOG(void)
- -365,26 +363,31 @@
- PlayerAssignEvent(pPlayer->dwUnitId);
- }
- -BOOL __stdcall GameLoop(LPMSG lpMsg, HWND hWnd, UINT wMsgFIlterMin, UINT wMsgFilterMax, UINT wRemoveMsg)
- +BOOL __stdcall GameLoop(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg)
- {
- if(Vars.bGameLoopEntered)
- - {
- LeaveCriticalSection(&Vars.cGameLoopSection);
- - }
- - else Vars.bGameLoopEntered = true;
- + else
- + Vars.bGameLoopEntered = true;
- EnterCriticalSection(&Vars.cGameLoopSection);
- - return PeekMessage(lpMsg, hWnd, wMsgFIlterMin, wMsgFilterMax, wRemoveMsg);
- + /*
- + * Temporary hack needed to avoid issues with WaitForClientState when
- + * entering Tyreals portal after killing baal for quest, I'm looking
- + * into a solution.
- + */
- + //BOOL ret = PeekMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
- + //Sleep(1);
- + return PeekMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
- }
- void GameLeave(void)
- {
- if(Vars.bGameLoopEntered)
- - {
- LeaveCriticalSection(&Vars.cGameLoopSection);
- - }
- - else Vars.bGameLoopEntered = true;
- + else
- + Vars.bGameLoopEntered = true;
- // Stop ingame scripts at this point ..
- // otherwise we deadlock ...
- Index: D2Helpers.cpp
- ===================================================================
- --- D2Helpers.cpp (revision 1005)
- +++ D2Helpers.cpp (working copy)
- -144,6 +144,22 @@
- ClientGameState ClientState(void)
- {
- +
- + // Temp debugging helper for spammage.
- +#if 0
- + static DWORD tick = GetTickCount();
- + static int times;
- + if(GetTickCount() - tick <= 1000)
- + {
- + times++;
- + if(times > 200)
- + {
- + times = 0;
- + DebugBreak();
- + }
- + }
- +#endif
- +
- if(*p_D2CLIENT_PlayerUnit && !(*p_D2WIN_FirstControl))
- {
- if((*p_D2CLIENT_PlayerUnit)->pInventory &&
- -160,26 +176,39 @@
- else if(!(*p_D2CLIENT_PlayerUnit) && *p_D2WIN_FirstControl)
- return ClientStateMenu;
- else if(!(*p_D2CLIENT_PlayerUnit) && !(*p_D2WIN_FirstControl))
- - return ClientStateNull;
- + {
- + // Throttle since we need to wait anyways.
- + Sleep(10);
- + return ClientStateBusy;
- + }
- +
- //#ifdef DEBUG
- // else
- // DebugBreak();
- //#endif
- +
- + // This should only happen on injection
- + Sleep(50);
- return ClientStateNull;
- }
- -bool WaitForGameReady(void)
- +bool WaitForClientState(ClientGameState WantedState)
- {
- DWORD start = GetTickCount();
- do
- {
- switch(ClientState())
- {
- - case ClientStateNull: case ClientStateMenu: return false;
- - case ClientStateInGame: return true;
- + case ClientStateInGame:
- + if(WantedState == ClientStateInGame)
- + return true;
- + case ClientStateMenu:
- + if(WantedState == ClientStateMenu)
- + return true;
- }
- Sleep(10);
- - } while((Vars.dwGameTimeout == 0 ) || (Vars.dwGameTimeout > 0 && (GetTickCount() - start) < Vars.dwGameTimeout));
- + } while(Vars.dwGameTimeout == 0 || (Vars.dwGameTimeout > 0 && (GetTickCount() - start) < Vars.dwGameTimeout));
- +
- return false;
- }
- -219,7 +248,8 @@
- INT GetSkill(WORD wSkillId)
- {
- - if(!D2CLIENT_GetPlayerUnit()) return 0;
- + if(!D2CLIENT_GetPlayerUnit())
- + return 0;
- for(Skill* pSkill = D2CLIENT_GetPlayerUnit()->pInfo->pFirstSkill; pSkill; pSkill = pSkill->pNextSkill)
- if(pSkill->pSkillInfo->wSkillId == wSkillId)
- Index: D2Helpers.h
- ===================================================================
- --- D2Helpers.h (revision 1003)
- +++ D2Helpers.h (working copy)
- -19,7 +19,7 @@
- WORD GetUnitY(UnitAny* pUnit);
- ClientGameState ClientState(void);
- bool GameReady(void);
- -bool WaitForGameReady(void);
- +bool WaitForClientState(ClientGameState WantedState = ClientStateInGame);
- DWORD GetPlayerArea(void);
- void ScreenSizeCheck(POINT* pPoint);
- void SendMouseClick(INT x, INT y, INT clicktype);
- Index: Helpers.cpp
- ===================================================================
- --- Helpers.cpp (revision 1009)
- +++ Helpers.cpp (working copy)
- -67,17 +67,10 @@
- void InitSettings(void)
- {
- - char fname[_MAX_FNAME+MAX_PATH],
- - scriptPath[_MAX_FNAME+MAX_PATH],
- - debug[6],
- - blockMinimize[6],
- - quitOnHostile[6],
- - quitOnError[6],
- - maxGameTime[6],
- - gameTimeout[6],
- - startAtMenu[6],
- - disableCache[6],
- - memUsage[6],
- + char fname[_MAX_FNAME+MAX_PATH], scriptPath[_MAX_FNAME+MAX_PATH],
- + debug[6], blockMinimize[6], quitOnHostile[6],
- + quitOnError[6], maxGameTime[6], gameTimeout[6],
- + startAtMenu[6], disableCache[6], memUsage[6],
- gamePrint[6];
- sprintf_s(fname, sizeof(fname), "%sd2bs.ini", Vars.szPath);
- -117,6 +110,9 @@
- int i = 0;
- while(!Vars.bActive)
- {
- + Sleep(50);
- + i++;
- +
- if(i >= 300)
- {
- MessageBox(0, "Failed to set hooks, exiting!", "D2BS", 0);
- -151,8 +147,6 @@
- if(ClientState() == ClientStateMenu && Vars.bStartAtMenu)
- clickControl(*p_D2WIN_FirstControl);
- }
- - Sleep(50);
- - i++;
- }
- return true;
- }
- -162,7 +156,7 @@
- return (ClientState() == ClientStateInGame ? "default.dbj" : ClientState() == ClientStateMenu ? "starter.dbj" : NULL);
- }
- -ScriptState GetStarterScriptState(void)
- +ScriptType GetStarterScriptType(void)
- {
- // the default return is InGame because that's the least harmful of the options
- return (ClientState() == ClientStateInGame ? InGame : ClientState() == ClientStateMenu ? OutOfGame : InGame);
- -174,11 +168,11 @@
- return (script && CreateThread(0, 0, ScriptThread, script, 0, 0) != INVALID_HANDLE_VALUE);
- }
- -bool StartScript(const char* scriptname, ScriptState state)
- +bool StartScript(const char* scriptname, ScriptType scriptType)
- {
- char file[_MAX_FNAME+_MAX_PATH];
- sprintf_s(file, _MAX_FNAME+_MAX_PATH, "%s\\%s", Vars.szScriptPath, scriptname);
- - Script* script = ScriptEngine::CompileFile(file, state);
- + Script* script = ScriptEngine::CompileFile(file, scriptType);
- return (script && CreateThread(0, 0, ScriptThread, script, 0, 0) != INVALID_HANDLE_VALUE);
- }
- -196,7 +190,7 @@
- Sleep(500);
- const char* script = GetStarterScriptName();
- - if(StartScript(script, GetStarterScriptState()))
- + if(StartScript(script, GetStarterScriptType()))
- Print("ÿc2D2BSÿc0 :: Started %s", script);
- else
- Print("ÿc2D2BSÿc0 :: Failed to start %s", script);
- -216,7 +210,7 @@
- if(_strcmpi(argv, "start") == 0)
- {
- const char* script = GetStarterScriptName();
- - if(StartScript(script, GetStarterScriptState()))
- + if(StartScript(script, GetStarterScriptType()))
- Print("ÿc2D2BSÿc0 :: Started %s", script);
- else
- Print("ÿc2D2BSÿc0 :: Failed to start %s", script);
- -239,7 +233,7 @@
- else if(_strcmpi(argv, "load") == 0)
- {
- const char* script = command+5;
- - if(StartScript(script, GetStarterScriptState()))
- + if(StartScript(script, GetStarterScriptType()))
- Print("ÿc2D2BSÿc0 :: Started %s", script);
- else
- Print("ÿc2D2BSÿc0 :: Failed to start %s", script);
- -266,7 +260,7 @@
- void GameJoined(void)
- {
- Print("ÿc2D2BSÿc0 :: Starting default.dbj");
- - if(StartScript(GetStarterScriptName(), GetStarterScriptState()))
- + if(StartScript(GetStarterScriptName(), GetStarterScriptType()))
- Print("ÿc2D2BSÿc0 :: default.dbj running.");
- else
- Print("ÿc2D2BSÿc0 :: Failed to start default.dbj!");
- -277,7 +271,7 @@
- if(beginStarter)
- {
- Print("ÿc2D2BSÿc0 :: Starting starter.dbj");
- - if(StartScript(GetStarterScriptName(), GetStarterScriptState()))
- + if(StartScript(GetStarterScriptName(), GetStarterScriptType()))
- Print("ÿc2D2BSÿc0 :: starter.dbj running.");
- else
- Print("ÿc2D2BSÿc0 :: Failed to start starter.dbj!");
- Index: Helpers.h
- ===================================================================
- --- Helpers.h (revision 1003)
- +++ Helpers.h (working copy)
- -13,7 +13,7 @@
- void InitSettings(void);
- bool InitHooks(void);
- bool ExecCommand(const char* command);
- -bool StartScript(const char* script, ScriptState state);
- +bool StartScript(const char* script, ScriptType scriptType);
- void Reload(void);
- bool ProcessCommand(const char* command, bool unprocessedIsCommand);
- Index: JSArea.cpp
- ===================================================================
- --- JSArea.cpp (revision 1003)
- +++ JSArea.cpp (working copy)
- -106,7 +106,7 @@
- JSAPI_FUNC(my_getArea)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- int32 nArea = GetPlayerArea();
- Index: JSControl.cpp
- ===================================================================
- --- JSControl.cpp (revision 1003)
- +++ JSControl.cpp (working copy)
- -143,9 +143,9 @@
- if(ClientState() != ClientStateMenu)
- return JS_TRUE;
- - ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
- + ControlData *pData = (ControlData*)JS_GetPrivate(cx, obj);
- if(!pData)
- - return JS_TRUE;
- + return JS_FALSE;
- Control* pControl = findControl(pData->dwType, (char *)NULL, -1, pData->dwX, pData->dwY, pData->dwSizeX, pData->dwSizeY);
- if(pControl && pControl->pNext)
- -168,7 +168,8 @@
- {
- JS_ClearScope(cx, obj);
- if(JS_ValueToObject(cx, JSVAL_NULL, &obj) == JS_FALSE)
- - return JS_TRUE;
- + return JS_FALSE;
- +
- *rval = JSVAL_FALSE;
- }
- -180,7 +181,7 @@
- if(ClientState() != ClientStateMenu)
- return JS_TRUE;
- - ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
- + ControlData *pData = (ControlData*)JS_GetPrivate(cx, obj);
- if(!pData)
- return JS_TRUE;
- -239,19 +240,28 @@
- if(ClientState() != ClientStateMenu)
- return JS_TRUE;
- - ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
- + ControlData *pData = (ControlData*)JS_GetPrivate(cx, obj);
- if(!pData)
- return JS_TRUE;
- Control* pControl = findControl(pData->dwType, (char *)NULL, -1, pData->dwX, pData->dwY, pData->dwSizeX, pData->dwSizeY);
- if(!pControl)
- {
- - *rval = INT_TO_JSVAL(0);
- + JS_ClearScope(cx, obj);
- + if(JS_ValueToObject(cx, JSVAL_NULL, &obj) == JS_FALSE)
- + return JS_FALSE;
- + *rval = JSVAL_FALSE;
- return JS_TRUE;
- }
- if(pControl->dwType != 4 || !pControl->pFirstText)
- + {
- + JS_ClearScope(cx, obj);
- + if(JS_ValueToObject(cx, JSVAL_NULL, &obj) == JS_FALSE)
- + return JS_FALSE;
- + *rval = JSVAL_FALSE;
- return JS_TRUE;
- + }
- JSObject* pReturnArray = JS_NewArrayObject(cx, 0, NULL);
- INT nArrayCount = 0;
- -283,13 +293,19 @@
- int32 nType = -1, nX = -1, nY = -1, nXSize = -1, nYSize = -1;
- int32 *args[] = {&nType, &nX, &nY, &nXSize, &nYSize};
- - for(uintN i = 0; i < argc; i++)
- + for(uintN i = 0; i < 5; i++)
- if(JSVAL_IS_INT(argv[i]))
- JS_ValueToECMAInt32(cx, argv[i], args[i]);
- Control* pControl = findControl(nType, (char*)NULL, -1, nX, nY, nXSize, nYSize);
- if(!pControl)
- + {
- + JS_ClearScope(cx, obj);
- + if(JS_ValueToObject(cx, JSVAL_NULL, &obj) == JS_FALSE)
- + return JS_FALSE;
- + *rval = JSVAL_FALSE;
- return JS_TRUE;
- + }
- ControlData* data = new ControlData;
- data->dwType = nType;
- Index: JSCore.cpp
- ===================================================================
- --- JSCore.cpp (revision 1003)
- +++ JSCore.cpp (working copy)
- -2,13 +2,13 @@
- #include <windows.h>
- #include <ddeml.h>
- -//#include "js32.h"
- -//#include "Script.h"
- +#include "js32.h"
- +#include "Script.h"
- #include "JSCore.h"
- #include "Core.h"
- #include "Helpers.h"
- #include "dde.h"
- -//#include "ScriptEngine.h"
- +#include "ScriptEngine.h"
- //#include "D2BS.h"
- #include "Events.h"
- #include "Console.h"
- -60,21 +60,6 @@
- else
- JS_ReportWarning(cx, "delay(0) called, argument must be >= 1");
- -/* if(argc == 1 && JSVAL_IS_INT(argv[0]))
- - {
- - int nDelay = JSVAL_TO_INT(argv[0]);
- - if(nDelay)
- - {
- - jsrefcount depth = JS_SuspendRequest(cx);
- -
- - Sleep(nDelay);
- -
- - JS_ResumeRequest(cx, depth);
- - }
- - else
- - JS_ReportWarning(cx, "delay(0) called, argument must be >= 1");
- - }*/
- -
- return JS_TRUE;
- }
- -100,13 +85,15 @@
- }
- char buf[_MAX_PATH+_MAX_FNAME];
- - ScriptState scriptState = script->GetState();
- - if(scriptState == Command)
- - scriptState = (ClientState() == ClientStateInGame ? InGame : OutOfGame);
- + ScriptType scriptType = script->GetScriptType();
- + if(scriptType == Command)
- + scriptType = ClientState() == ClientStateInGame ? InGame : OutOfGame;
- sprintf_s(buf, sizeof(buf), "%s\\%s", Vars.szScriptPath, file);
- +
- + _strlwr_s(buf, _MAX_PATH+_MAX_FNAME);
- StringReplace(buf, '/', '\\', _MAX_PATH+_MAX_FNAME);
- - Script* newScript = ScriptEngine::CompileFile(buf, scriptState);
- + Script* newScript = ScriptEngine::CompileFile(buf, scriptType);
- if(newScript)
- {
- CreateThread(0, 0, ScriptThread, newScript, 0, 0);
- -119,38 +106,6 @@
- *rval = JSVAL_FALSE;
- }
- -/* if(argc > 0 && JSVAL_IS_STRING(argv[0]))
- - {
- - Script* execScript = (Script*)JS_GetContextPrivate(cx);
- - ScriptState scriptState = execScript->GetState();
- - if(scriptState == Command)
- - scriptState = (GameReady() ? InGame : OutOfGame);
- -
- - char* lpszFileName = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
- - if(!(lpszFileName && lpszFileName[0]))
- - THROW_ERROR(cx, obj, "Could not convert or empty string");
- - StringReplace(lpszFileName, '/', '\\');
- - if(strlen(lpszFileName) < (_MAX_FNAME + _MAX_PATH - strlen(Vars.szScriptPath)))
- - {
- - char lpszBuf[_MAX_PATH+_MAX_FNAME];
- - sprintf_s(lpszBuf, sizeof(lpszBuf), "%s\\%s", Vars.szScriptPath, lpszFileName);
- - Script* script = ScriptEngine::CompileFile(lpszBuf, scriptState);
- - if(script)
- - {
- - CreateThread(0, 0, ScriptThread, script, 0, 0);
- - *rval = JSVAL_TRUE;
- - }
- - else
- - {
- - // TODO: Should this actually be there? No notification is bad, but do we want this? maybe throw an exception?
- - Print("File \"%s\" not found.", lpszFileName);
- - *rval = JSVAL_FALSE;
- - }
- - }
- - else
- - THROW_ERROR(cx, obj, "File name exceeds max name length");
- - }*/
- -
- return JS_TRUE;
- }
- -177,26 +132,10 @@
- char buf[_MAX_PATH+_MAX_FNAME];
- sprintf_s(buf, sizeof(buf), "%s\\libs\\%s", Vars.szScriptPath, file);
- +
- if(_access(buf, 0) == 0)
- *rval = BOOLEAN_TO_JSVAL(script->Include(buf));
- -/* if(argc > 0 && JSVAL_IS_STRING(argv[0]))
- - {
- - Script* script = (Script*)JS_GetContextPrivate(cx);
- - if(script)
- - {
- - char * lpszFileName = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
- - if(lpszFileName && strlen(lpszFileName) <= _MAX_FNAME)
- - {
- - char lpszBuf[_MAX_PATH+_MAX_FNAME];
- - sprintf_s(lpszBuf, sizeof(lpszBuf), "%s\\libs\\%s", Vars.szScriptPath, lpszFileName);
- - StringReplace(lpszFileName, '/', '\\');
- - if(_access(lpszBuf, 0) == 0)
- - *rval = BOOLEAN_TO_JSVAL(script->Include(lpszBuf));
- - }
- - }
- - }*/
- -
- return JS_TRUE;
- }
- Index: JSGame.cpp
- ===================================================================
- --- JSGame.cpp (revision 1008)
- +++ JSGame.cpp (working copy)
- -70,7 +70,7 @@
- JSAPI_FUNC(my_clickMap)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- uint16 nClickType = 0, nShift = 0, nX = 0xFFFF, nY = 0xFFFF;
- -120,7 +120,7 @@
- JSAPI_FUNC(my_acceptTrade)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- // TODO: Fix this nonsense.
- -167,7 +167,7 @@
- JSAPI_FUNC(my_getPath)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 5)
- -307,7 +307,7 @@
- JSAPI_FUNC(my_getCollision)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 3 || !JSVAL_IS_INT(argv[0]) || !JSVAL_IS_INT(argv[1]) || !JSVAL_IS_INT(argv[2]))
- -340,7 +340,7 @@
- CriticalMisc myMisc;
- myMisc.EnterSection();
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(*p_D2CLIENT_TransactionDialog != 0 || *p_D2CLIENT_TransactionDialogs != 0 || *p_D2CLIENT_TransactionDialogs_2 != 0)
- -697,7 +697,7 @@
- JSAPI_FUNC(my_getDistance)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- // TODO: Add the type of distance to the api design
- -785,7 +785,7 @@
- JSAPI_FUNC(my_gold)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- jsint nGold = NULL;
- -803,7 +803,7 @@
- JSAPI_FUNC(my_checkCollision)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc == 3 && JSVAL_IS_OBJECT(argv[0]) && JSVAL_IS_OBJECT(argv[1]) && JSVAL_IS_INT(argv[2]))
- -830,7 +830,7 @@
- JSAPI_FUNC(my_getMercHP)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(D2CLIENT_GetPlayerUnit() && D2CLIENT_GetPlayerUnit()->pAct)
- -950,7 +950,7 @@
- JSAPI_FUNC(my_getTradeInfo)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 1)
- -986,7 +986,7 @@
- JSAPI_FUNC(my_getUIFlag)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 1 || !JSVAL_IS_INT(argv[0]))
- -1003,7 +1003,7 @@
- JSAPI_FUNC(my_getWaypoint)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 1 || !JSVAL_IS_INT(argv[0]))
- -1084,7 +1084,7 @@
- JSAPI_FUNC(my_clickParty)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- *rval = JSVAL_FALSE;
- -1188,7 +1188,7 @@
- {
- *rval = JSVAL_FALSE;
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- jsint nParameter = NULL;
- -1221,7 +1221,7 @@
- JSAPI_FUNC(my_transmute)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- D2CLIENT_Transmute();
- -1231,7 +1231,7 @@
- JSAPI_FUNC(my_getPlayerFlag)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc != 3 || !JSVAL_IS_NUMBER(argv[0]) || !JSVAL_IS_NUMBER(argv[1]) || !JSVAL_IS_NUMBER(argv[2]))
- -1296,7 +1296,7 @@
- JSAPI_FUNC(my_submitItem)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(UnitAny* pUnit = D2CLIENT_GetCursorItem())
- -1312,7 +1312,7 @@
- JSAPI_FUNC(my_getInteractedNPC)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- UnitAny* pNPC = D2CLIENT_GetCurrentInteractingNPC();
- Index: JSMenu.cpp
- ===================================================================
- --- JSMenu.cpp (revision 1003)
- +++ JSMenu.cpp (working copy)
- -128,23 +128,23 @@
- break;
- }
- - case OOG_MAIN_MENU_CONNECTING:
- + case OOG_MAIN_MENU_CONNECTING:
- case OOG_CHARACTER_SELECT_PLEASE_WAIT:
- - case OOG_PLEASE_WAIT:
- + case OOG_PLEASE_WAIT:
- case OOG_GATEWAY:
- - case OOG_CHARACTER_SELECT_NO_CHARS:
- + case OOG_CHARACTER_SELECT_NO_CHARS:
- case OOG_NONE:
- timeout++;
- break;
- - case OOG_LOBBY:
- - case OOG_INLINE:
- - case OOG_CHAT:
- + case OOG_LOBBY:
- + case OOG_INLINE:
- + case OOG_CHAT:
- case OOG_CREATE:
- - case OOG_JOIN:
- - case OOG_LADDER:
- - case OOG_CHANNEL:
- - case OOG_GAME_EXIST:
- - case OOG_GAME_DOES_NOT_EXIST:
- + case OOG_JOIN:
- + case OOG_LADDER:
- + case OOG_CHANNEL:
- + case OOG_GAME_EXIST:
- + case OOG_GAME_DOES_NOT_EXIST:
- loginComplete=TRUE;
- break;
- case OOG_UNABLE_TO_CONNECT:
- -161,13 +161,13 @@
- break;
- default:
- errorMsg = "Unhandled login location";
- - break;
- + break;
- }
- if(_strcmpi(errorMsg, ""))
- {
- Vars.bBlockKeys = Vars.bBlockMouse = FALSE;
- - THROW_ERROR(cx, errorMsg);
- + THROW_ERROR(cx, errorMsg);
- break;
- }
- -290,8 +290,8 @@
- {
- char settings[600] = "";
- sprintf_s(settings, sizeof(settings),
- - "mode=%s\tgateway=%s\tusername=%s\tpassword=%s\tcharacter=%s\tspdifficulty=%d\t",
- - mode, gateway, username, password, charname, spdifficulty);
- + "mode=%s\tgateway=%s\tusername=%s\tpassword=%s\tcharacter=%s\tspdifficulty=%d\t",
- + mode, gateway, username, password, charname, spdifficulty);
- StringReplace(settings, '\t', '\0', 600);
- WritePrivateProfileSection(*args[0], settings, file);
- -317,10 +317,10 @@
- char* name = NULL;
- int32 type = -1;
- - JSBool hc = JS_FALSE, ladder = JS_FALSE;
- - if(!JS_ConvertArguments(cx, argc, argv, "si/bb", &name, &type, &hc, &ladder))
- + JSBool hardcore = JS_FALSE, ladder = JS_FALSE, expansion = JS_TRUE;
- + if(!JS_ConvertArguments(cx, argc, argv, "si/bbb", &name, &type, &hardcore, &ladder, &expansion))
- return JS_FALSE;
- - *rval = BOOLEAN_TO_JSVAL(!!OOG_CreateCharacter(name, type, !!hc, !!ladder));
- + *rval = BOOLEAN_TO_JSVAL(!!OOG_CreateCharacter(name, type, !!hardcore, !!ladder, !!expansion));
- return JS_TRUE;
- -}
- \ No newline at end of file
- +}
- Index: JSParty.cpp
- ===================================================================
- --- JSParty.cpp (revision 1003)
- +++ JSParty.cpp (working copy)
- -52,7 +52,7 @@
- JSAPI_FUNC(party_getNext)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- RosterUnit *pUnit = (RosterUnit*)JS_GetPrivate(cx, obj);
- -82,7 +82,7 @@
- JSAPI_FUNC(my_getParty)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- RosterUnit* pUnit = *p_D2CLIENT_PlayerUnitList;
- Index: JSPresetUnit.cpp
- ===================================================================
- --- JSPresetUnit.cpp (revision 1003)
- +++ JSPresetUnit.cpp (working copy)
- -55,7 +55,7 @@
- JSAPI_FUNC(my_getPresetUnits)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 1)
- -140,7 +140,7 @@
- JSAPI_FUNC(my_getPresetUnit)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 1)
- Index: JSRoom.cpp
- ===================================================================
- --- JSRoom.cpp (revision 1003)
- +++ JSRoom.cpp (working copy)
- -390,7 +390,7 @@
- JSAPI_FUNC(my_getRoom)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- CriticalRoom cRoom;
- Index: JSScreenHook.cpp
- ===================================================================
- --- JSScreenHook.cpp (revision 1003)
- +++ JSScreenHook.cpp (working copy)
- -168,7 +168,7 @@
- {
- Script* script = (Script*)JS_GetContextPrivate(cx);
- - ScreenhookState state = (script->GetState () == OutOfGame) ? OOG : IG;
- + ScreenhookState state = (script->GetScriptType() == OutOfGame) ? OOG : IG;
- uint x = 0, y = 0, x2 = 0, y2 = 0;
- ushort color = 0, opacity = 0;
- Align align = Left;
- -317,7 +317,7 @@
- {
- Script* script = (Script*)JS_GetContextPrivate(cx);
- - ScreenhookState state = (script->GetState () == OutOfGame) ? OOG : IG;
- + ScreenhookState state = (script->GetScriptType () == OutOfGame) ? OOG : IG;
- int x = 0, y = 0, x2 = 0, y2 = 0;
- ushort color = 0;
- bool automap = false;
- -449,7 +449,7 @@
- {
- Script* script = (Script*)JS_GetContextPrivate(cx);
- - ScreenhookState state = (script->GetState () == OutOfGame) ? OOG : IG;
- + ScreenhookState state = (script->GetScriptType () == OutOfGame) ? OOG : IG;
- uint x = 0, y = 0;
- ushort color = 0, font = 0;
- Align align = Left;
- -598,7 +598,7 @@
- {
- Script* script = (Script*)JS_GetContextPrivate(cx);
- - ScreenhookState state = (script->GetState () == OutOfGame) ? OOG : IG;
- + ScreenhookState state = (script->GetScriptType () == OutOfGame) ? OOG : IG;
- uint x = 0, y = 0;
- ushort color = 0;
- Align align = Left;
- Index: JSScript.cpp
- ===================================================================
- --- JSScript.cpp (revision 1003)
- +++ JSScript.cpp (working copy)
- -38,7 +38,7 @@
- }
- break;
- case SCRIPT_GAMETYPE:
- - *vp = script->GetState() == InGame ? INT_TO_JSVAL(0) : INT_TO_JSVAL(1);
- + *vp = script->GetScriptType() == InGame ? INT_TO_JSVAL(0) : INT_TO_JSVAL(1);
- break;
- case SCRIPT_RUNNING:
- *vp = BOOLEAN_TO_JSVAL(script->IsRunning());
- -133,8 +133,7 @@
- else if(argc == 1 && JSVAL_IS_STRING(argv[0]))
- {
- char* name = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
- - if(name)
- - StringReplace(name, '/', '\\', strlen(name));
- +
- FindHelper args = {0, name, NULL};
- ScriptEngine::ForEachScript(FindScriptByName, &args, 1);
- if(args.script != NULL)
- -161,7 +160,7 @@
- static uint pathlen = strlen(Vars.szScriptPath) + 1;
- const char* fname = script->GetFilename();
- // calculate the relative name from the filename
- - const char* relName = (strlen(fname) > pathlen ? fname + pathlen : fname);
- + const char* relName = strlen(fname) > pathlen ? fname + pathlen : fname;
- if(_strcmpi(relName, helper->name) == 0)
- {
- helper->script = script;
- Index: JSUnit.cpp
- ===================================================================
- --- JSUnit.cpp (revision 1005)
- +++ JSUnit.cpp (working copy)
- -608,7 +608,7 @@
- JSAPI_FUNC(unit_cancel)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc == 1 && JSVAL_IS_INT(argv[0]))
- -679,7 +679,7 @@
- JSAPI_FUNC(unit_interact)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -696,7 +696,7 @@
- if(pUnit->dwType == UNIT_ITEM && pUnit->dwMode != ITEM_MODE_ON_GROUND && pUnit->dwMode != ITEM_MODE_BEING_DROPPED)
- {
- - INT nLocation = GetItemLocation(pUnit);
- + INT nLocation = GetItemLocation(pUnit);
- BYTE aPacket[13] = {NULL};
- -738,7 +738,8 @@
- else
- {
- *rval = JSVAL_TRUE;
- - ClickMap(0, GetUnitX(pUnit), GetUnitY(pUnit), FALSE, pUnit);
- + //ClickMap(0, GetUnitX(pUnit), GetUnitY(pUnit), FALSE, pUnit);
- + ClickMap(0, 0xFFFF, 0xFFFF, FALSE, pUnit);
- //D2CLIENT_Interact(pUnit, 0x45);
- }
- -750,7 +751,7 @@
- JSAPI_FUNC(unit_getStat)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -939,7 +940,7 @@
- JSAPI_FUNC(unit_getState)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -970,7 +971,7 @@
- JSAPI_FUNC(item_getFlags)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -990,7 +991,7 @@
- JSAPI_FUNC(item_getFlag)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 1 || !JSVAL_IS_INT(argv[0]))
- -1017,7 +1018,7 @@
- {
- DEPRECATED;
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- INT diff = D2CLIENT_GetDifficulty();
- -1066,7 +1067,7 @@
- JSAPI_FUNC(item_getItemCost)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- jsint nMode;
- -1113,7 +1114,7 @@
- JSAPI_FUNC(unit_getItems)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -1170,7 +1171,7 @@
- JSAPI_FUNC(unit_getSkill)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- jsint nSkillId = NULL;
- -1295,7 +1296,7 @@
- CriticalMisc myMisc;
- myMisc.EnterSection();
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(*p_D2CLIENT_TransactionDialog != 0 || *p_D2CLIENT_TransactionDialogs != 0 || *p_D2CLIENT_TransactionDialogs_2 != 0)
- -1389,7 +1390,7 @@
- JSAPI_FUNC(unit_getParent)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -1468,7 +1469,7 @@
- // Works only on players sinces monsters _CANT_ have mercs!
- JSAPI_FUNC(unit_getMerc)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -1557,7 +1558,7 @@
- // unit.setSkill( int skillId OR String skillName, int hand [, int itemGlobalId] );
- JSAPI_FUNC(unit_setskill)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- WORD nSkillId = (WORD)-1;
- -1587,7 +1588,7 @@
- JSAPI_FUNC(my_overhead)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit *pmyUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -1620,7 +1621,7 @@
- JSAPI_FUNC(unit_getItem)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit *pmyUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -1681,7 +1682,7 @@
- JSAPI_FUNC(unit_move)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- myUnit *pmyUnit = (myUnit*)JS_GetPrivate(cx, obj);
- -1724,7 +1725,7 @@
- JSAPI_FUNC(unit_getEnchant)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 1 || !JSVAL_IS_INT(argv[0]))
- -1756,7 +1757,7 @@
- JSAPI_FUNC(unit_getQuest)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 2 || !JSVAL_IS_INT(argv[0]) || !JSVAL_IS_INT(argv[1]))
- -1772,7 +1773,7 @@
- JSAPI_FUNC(unit_getMinionCount)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- if(argc < 1 || !JSVAL_IS_INT(argv[0]))
- -1799,7 +1800,7 @@
- JSAPI_FUNC(me_getRepairCost)
- {
- - if(!WaitForGameReady())
- + if(!WaitForClientState())
- THROW_ERROR(cx, "Game not ready");
- UnitAny* npc = D2CLIENT_GetCurrentInteractingNPC();
- Index: Script.cpp
- ===================================================================
- --- Script.cpp (revision 1006)
- +++ Script.cpp (working copy)
- -13,21 +13,21 @@
- using namespace std;
- -Script::Script(const char* file, ScriptState state) :
- +Script::Script(const char* file, ScriptType scriptType) :
- context(NULL), globalObject(NULL), scriptObject(NULL), script(NULL), execCount(0),
- - isAborted(false), isPaused(false), isReallyPaused(false), scriptState(state),
- + isAborted(false), isPaused(false), isReallyPaused(false), scriptType(scriptType),
- threadHandle(INVALID_HANDLE_VALUE), threadId(0)
- {
- InitializeCriticalSection(&lock);
- EnterCriticalSection(&lock);
- - if(scriptState == Command)
- + if(scriptType == Command)
- {
- fileName = string("Command Line");
- }
- else
- {
- - if(_access(file, 0) != 0)
- + if(!!_access(file, 0))
- throw std::exception("File not found");
- char* tmpName = _strdup(file);
- -35,34 +35,60 @@
- throw std::exception("Could not dup filename");
- _strlwr_s(tmpName, strlen(file)+1);
- +
- fileName = string(tmpName);
- replace(fileName.begin(), fileName.end(), '/', '\\');
- +
- free(tmpName);
- }
- +
- try
- {
- context = JS_NewContext(ScriptEngine::GetRuntime(), 0x2000);
- if(!context)
- throw std::exception("Couldn't create the context");
- + }
- + catch(std::exception &)
- + {
- + LeaveCriticalSection(&lock);
- + throw;
- + }
- + try
- + {
- JS_SetContextPrivate(context, this);
- JS_BeginRequest(context);
- globalObject = JS_GetGlobalObject(context);
- jsval meVal = JSVAL_VOID;
- - if(JS_GetProperty(GetContext(), globalObject, "me", &meVal) != JS_FALSE)
- + if(JS_GetProperty(context, globalObject, "me", &meVal) != JS_FALSE)
- {
- JSObject* meObject = JSVAL_TO_OBJECT(meVal);
- - me = (myUnit*)JS_GetPrivate(GetContext(), meObject);
- + me = (myUnit*)JS_GetPrivate(context, meObject);
- }
- + else
- + throw std::exception("Couldn't get me object");
- - if(state == Command)
- - script = JS_CompileScript(context, globalObject, file, strlen(file), "Command Line", 1);
- + if(scriptType == Command)
- + script = JS_CompileScript(context, globalObject, fileName.c_str(), strlen(fileName.c_str()), "Command Line", 1);
- else
- script = JS_CompileFile(context, globalObject, fileName.c_str());
- +
- if(!script)
- throw std::exception("Couldn't compile the script");
- + }
- + catch(std::exception &)
- + {
- + JS_EndRequest(context);
- + JS_DestroyContext(context);
- +
- + LeaveCriticalSection(&lock);
- + throw;
- + }
- +
- + try
- + {
- scriptObject = JS_NewScriptObject(context, script);
- if(!scriptObject)
- throw std::exception("Couldn't create the script object");
- -74,16 +100,19 @@
- JS_ClearContextThread(context);
- LeaveCriticalSection(&lock);
- - } catch(std::exception&) {
- + }
- + catch(std::exception&)
- + {
- if(scriptObject)
- + {
- JS_RemoveRoot(&scriptObject);
- - if(script && !scriptObject)
- + }
- + else
- JS_DestroyScript(context, script);
- - if(context)
- - {
- - JS_EndRequest(context);
- - JS_DestroyContext(context);
- - }
- +
- + JS_EndRequest(context);
- + JS_DestroyContext(context);
- +
- LeaveCriticalSection(&lock);
- throw;
- }
- -103,7 +132,8 @@
- JS_RemoveRoot(&globalObject);
- JS_RemoveRoot(&scriptObject);
- - JS_DestroyContextNoGC(context);
- + JS_EndRequest(context);
- + JS_DestroyContext(context);
- context = NULL;
- scriptObject = NULL;
- -111,8 +141,12 @@
- script = NULL;
- includes.clear();
- - if(threadHandle)
- + if(threadHandle != INVALID_HANDLE_VALUE)
- + {
- CloseHandle(threadHandle);
- + threadHandle = INVALID_HANDLE_VALUE;
- + }
- +
- LeaveCriticalSection(&lock);
- DeleteCriticalSection(&lock);
- }
- -150,7 +184,7 @@
- JS_CallFunctionValue(GetContext(), globalObject, main, 0, NULL, &dummy);
- }
- - if(GetState() == Command)
- + if(GetScriptType() == Command)
- {
- // if we just processed a command, print the results of the command
- if(!JSVAL_IS_NULL(dummy) && !JSVAL_IS_VOID(dummy))
- -202,15 +236,13 @@
- EnterCriticalSection(&lock);
- + if(context && JS_IsRunning(context))
- + JS_TriggerOperationCallback(context);
- +
- // tell everyone else that the script is aborted FIRST
- isAborted = true;
- isPaused = false;
- isReallyPaused = false;
- - if(GetState() != Command)
- - {
- - const char* displayName = fileName.c_str() + strlen(Vars.szScriptPath) + 1;
- - Print("Script %s ended", displayName);
- - }
- ClearAllEvents();
- Genhook::Clean(this);
- -225,21 +257,28 @@
- Sleep(10);
- }
- - if(threadHandle)
- + if(threadHandle != INVALID_HANDLE_VALUE)
- + {
- CloseHandle(threadHandle);
- - threadHandle = NULL;
- + threadHandle = INVALID_HANDLE_VALUE;
- + }
- +
- + if(GetScriptType() != Command)
- + Print("Script %s ended", fileName.c_str() + strlen(Vars.szScriptPath) + 1);
- +
- LeaveCriticalSection(&lock);
- }
- bool Script::IsIncluded(const char* file)
- {
- - uint count = 0;
- char* fname = _strdup(file);
- if(!fname)
- return false;
- _strlwr_s(fname, strlen(fname)+1);
- StringReplace(fname, '/', '\\', strlen(fname));
- +
- + uint count = 0;
- count = includes.count(string(fname));
- free(fname);
- -256,9 +295,8 @@
- _strlwr_s(fname, strlen(fname)+1);
- StringReplace(fname, '/', '\\', strlen(fname));
- // ignore already included, 'in-progress' includes, and self-inclusion
- - if(!!includes.count(string(fname)) ||
- - !!inProgress.count(string(fname)) ||
- - (fileName == string(fname)))
- + string fName(fname);
- + if(!!includes.count(fName) || !!inProgress.count(fName) || fileName == fName)
- {
- LeaveCriticalSection(&lock);
- free(fname);
- -378,7 +416,7 @@
- void Script::ExecEvent(const char* evtName, const char* format, uintN argc, void* argv)
- {
- if((!IsAborted() && !IsPaused() && functions.count(evtName)) &&
- - IsRunning() && !(GetState() == InGame && ClientState() != ClientStateInGame))
- + IsRunning() && !(GetScriptType() == InGame && ClientState() != ClientStateInGame))
- {
- FunctionList funcs = functions[evtName];
- JSContext* cx = JS_NewContext(ScriptEngine::GetRuntime(), 8192);
- -403,7 +441,7 @@
- void Script::ExecEventAsync(const char* evtName, const char* format, ArgList* args)
- {
- - if((!IsAborted() && !IsPaused() && functions.count(evtName)))
- + if(!IsAborted() && !IsPaused() && functions.count(evtName))
- {
- Event* evt = new Event;
- evt->owner = this;
- -438,7 +476,7 @@
- if(!evt)
- return;
- - if(evt->owner->IsRunning() && !(evt->owner->GetState() == InGame && ClientState() != ClientStateInGame))
- + if(evt->owner->IsRunning() && !(evt->owner->GetScriptType() == InGame && ClientState() != ClientStateInGame))
- {
- JSContext* cx = JS_NewContext(ScriptEngine::GetRuntime(), 8192);
- JS_SetContextPrivate(cx, evt->owner);
- -452,12 +490,18 @@
- {
- switch(it->second)
- {
- - case String: argv[i] = STRING_TO_JSVAL((JSString*)it->first); break;
- + case String:
- + argv[i] = STRING_TO_JSVAL((JSString*)it->first);
- + break;
- case SignedInt: case UnsignedInt: case Double: case UnsignedShort:
- JS_NewNumberValue(cx, (jsdouble)it->first, &argv[i]);
- break;
- - case Boolean: argv[i] = BOOLEAN_TO_JSVAL((JSBool)it->first); break;
- - case JSVal: argv[i] = (jsval)it->first; break;
- + case Boolean:
- + argv[i] = BOOLEAN_TO_JSVAL((JSBool)it->first);
- + break;
- + case JSVal:
- + argv[i] = (jsval)it->first;
- + break;
- }
- }
- -476,8 +520,12 @@
- {
- switch(it->second)
- {
- - case JSVal: JS_RemoveRoot((jsval*)&(it->first)); break;
- - case String: JS_RemoveRoot((JSString*)&(it->first)); break;
- + case JSVal:
- + JS_RemoveRoot((jsval*)&(it->first));
- + break;
- + case String:
- + JS_RemoveRoot((JSString*)&(it->first));
- + break;
- }
- }
- Index: Script.h
- ===================================================================
- --- Script.h (revision 1006)
- +++ Script.h (working copy)
- -10,7 +10,7 @@
- #include "AutoRoot.h"
- #include "JSUnit.h"
- -enum ScriptState {
- +enum ScriptType {
- InGame,
- OutOfGame,
- Command
- -34,8 +34,8 @@
- static JSClass global_obj = {
- "global", JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
- - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
- - JSCLASS_NO_OPTIONAL_MEMBERS
- + JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
- + JSCLASS_NO_OPTIONAL_MEMBERS
- };
- class Script;
- -60,12 +60,13 @@
- private:
- std::string fileName;
- int execCount;
- - ScriptState scriptState;
- + ScriptType scriptType;
- JSContext* context;
- JSScript* script;
- myUnit* me;
- JSObject *globalObject, *scriptObject;
- +
- bool isLocked, isPaused, isReallyPaused, isAborted;
- IncludeList includes, inProgress;
- -74,7 +75,7 @@
- DWORD threadId;
- CRITICAL_SECTION lock;
- - Script(const char* file, ScriptState state);
- + Script(const char* file, ScriptType type);
- Script(const Script&);
- Script& operator=(const Script&);
- ~Script(void);
- -94,7 +95,7 @@
- JSContext* GetContext(void) { return context; }
- JSObject* GetGlobalObject(void) { return globalObject; }
- JSObject* GetScriptObject(void) { return scriptObject; }
- - ScriptState GetState(void) { return scriptState; }
- + ScriptType GetScriptType(void) { return scriptType; }
- int GetExecutionCount(void);
- DWORD GetThreadId(void);
- // UGLY HACK to fix up the player gid on game join for cached scripts/oog scripts
- Index: ScriptEngine.cpp
- ===================================================================
- --- ScriptEngine.cpp (revision 1005)
- +++ ScriptEngine.cpp (working copy)
- -27,7 +27,7 @@
- bool __fastcall StopScript(Script* script, void* argv, uint argc);
- bool __fastcall GCPauseScript(Script* script, void* argv, uint argc);
- -Script* ScriptEngine::CompileFile(const char* file, ScriptState state, bool recompile)
- +Script* ScriptEngine::CompileFile(const char* file, ScriptType scriptType, bool recompile)
- {
- if(GetState() != Running)
- return NULL;
- -52,7 +52,7 @@
- return ret;
- }
- }
- - Script* script = new Script(fileName, state);
- + Script* script = new Script(fileName, scriptType);
- scripts[fileName] = script;
- LeaveCriticalSection(&lock);
- delete[] fileName;
- -354,7 +354,7 @@
- bool __fastcall StopIngameScript(Script* script, void*, uint)
- {
- - if(script->GetState() == InGame)
- + if(script->GetScriptType() == InGame)
- script->Stop(true);
- return true;
- }
- -390,12 +390,14 @@
- bool pause = script->IsPaused();
- if(pause)
- + {
- script->SetPauseState(true);
- + JS_MaybeGC(cx);
- + }
- +
- while(script->IsPaused())
- - {
- Sleep(50);
- - JS_MaybeGC(cx);
- - }
- +
- if(pause)
- script->SetPauseState(false);
- -403,7 +405,7 @@
- script->UpdatePlayerGid();
- - return !!!(JSBool)(script->IsAborted() || ((script->GetState() != OutOfGame) && !D2CLIENT_GetPlayerUnit()));
- + return !!!(JSBool)(script->IsAborted() || (script->GetScriptType() != OutOfGame && ClientState() != ClientStateInGame));
- }
- JSBool contextCallback(JSContext* cx, uintN contextOp)
- -486,14 +488,19 @@
- {
- while(ScriptEngine::GetState() != Stopped)
- {
- - EventHelper* helper = (EventHelper*)InterlockedPopEntrySList(&ScriptEngine::eventList);
- - if(helper)
- + while(QueryDepthSList(&ScriptEngine::eventList) > 0)
- {
- - // execute it on every script
- - ScriptEngine::ForEachScript(ExecEventOnScript, helper, 1);
- - delete helper;
- + EventHelper* helper = (EventHelper*)InterlockedPopEntrySList(&ScriptEngine::eventList);
- + if(helper)
- + {
- + // execute it on every script
- + ScriptEngine::ForEachScript(ExecEventOnScript, helper, 1);
- + delete helper;
- + }
- + else
- + DebugBreak();
- }
- - Sleep(10);
- + Sleep(1);
- }
- }
- Index: ScriptEngine.h
- ===================================================================
- --- ScriptEngine.h (revision 1003)
- +++ ScriptEngine.h (working copy)
- -49,7 +49,7 @@
- static void FlushCache(void);
- - static Script* CompileFile(const char* file, ScriptState state, bool recompile = false);
- + static Script* CompileFile(const char* file, ScriptType scriptType, bool recompile = false);
- static Script* CompileCommand(const char* command);
- static void DisposeScript(Script* script);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement