Skip to content

Commit

Permalink
semi working backup point, events disabled, roots Alot of work
Browse files Browse the repository at this point in the history
  • Loading branch information
bobode committed May 26, 2012
1 parent fefee25 commit 649cb47
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 80 deletions.
5 changes: 3 additions & 2 deletions AutoRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ AutoRoot::~AutoRoot() {
DebugBreak();
exit(3);
}
JS_RemoveRoot(&var);
//JS_RemoveRoot(&var);
}

void AutoRoot::Take()
{
count++;
JS_AddNamedRootRT(ScriptEngine::GetRuntime(), &var, "AutoRoot");
//JS_AddNamedValueRoot(ScriptEngine::GetGlobalContext(), &var, "AutoRoot");
//JS_AddNamedRootRT(ScriptEngine::GetRuntime(), &var, "AutoRoot");
}

void AutoRoot::Release()
Expand Down
2 changes: 1 addition & 1 deletion D2BS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ BOOL Startup(void)

if((hD2Thread = CreateThread(NULL, NULL, D2Thread, NULL, NULL, NULL)) == NULL)
return FALSE;
hEventThread = CreateThread(0, 0, EventThread, NULL, 0, 0);
// hEventThread = CreateThread(0, 0, EventThread, NULL, 0, 0);
return TRUE;
}

Expand Down
14 changes: 7 additions & 7 deletions D2BS.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D2BS", "D2BS.vcproj", "{0EB43FEB-A856-4370-9F46-C8D252D9E153}"
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D2BS", "D2BS.vcxproj", "{0EB43FEB-A856-4370-9F46-C8D252D9E153}"
EndProject
Global
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Packaging|Win32 = Packaging|Win32
Expand All @@ -24,4 +20,8 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions D2BS.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@
<Filter
Name="Engine"
>
<File
RelativePath=".\AutoRoot.cpp"
>
</File>
<File
RelativePath=".\AutoRoot.h"
>
Expand Down
Binary file added Debug/D2BS.exe
Binary file not shown.
56 changes: 29 additions & 27 deletions JSCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ JSAPI_FUNC(my_load)
return JS_FALSE;
}

char* file = NULL;
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "s", &file))
return JS_FALSE;
char *file = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));

if(strlen(file) > (_MAX_FNAME + _MAX_PATH - strlen(Vars.szScriptPath)))
{
Expand Down Expand Up @@ -123,10 +121,8 @@ JSAPI_FUNC(my_include)
return JS_FALSE;
}

char* file = NULL;
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "s", &file))
return JS_FALSE;

char *file = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));

if(strlen(file) > (_MAX_FNAME + _MAX_PATH - strlen(Vars.szScriptPath) - 6))
{
JS_ReportError(cx, "File name too long!");
Expand Down Expand Up @@ -185,10 +181,8 @@ JSAPI_FUNC(my_getThreadPriority)

JSAPI_FUNC(my_isIncluded)
{
char* file = NULL;
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "s", &file))
return JS_FALSE;

char *file = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));

if(strlen(file) > (_MAX_FNAME+_MAX_PATH-strlen(Vars.szScriptPath)-6))
{
JS_ReportError(cx, "File name too long");
Expand Down Expand Up @@ -250,15 +244,17 @@ JSAPI_FUNC(my_debugLog)
}
JSAPI_FUNC(my_copy)
{
char *data = NULL;
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "s", &data))
return JS_FALSE;

char *data = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));

JS_ValueToString(cx,JS_ARGV(cx, vp)[0]);
HGLOBAL hText;
char *pText;
hText = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, strlen(data)+1);
pText = (char*)GlobalLock(hText);
strcpy_s(pText,strlen(data)+1, data);
char* tempData;


strcpy_s(pText,strlen(data)+1, tempData);
GlobalUnlock(hText);

OpenClipboard(NULL);
Expand Down Expand Up @@ -289,14 +285,22 @@ JSAPI_FUNC(my_sendCopyData)
HWND hWnd = NULL;

if(argc > 1 && JSVAL_IS_NUMBER(JS_ARGV(cx, vp)[1]) && !JSVAL_IS_NULL(JS_ARGV(cx, vp)[1]))
JS_ValueToECMAUint32(cx, JS_ARGV(cx, vp)[1], (uint32*)&hWnd);

if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "ssis", &windowClassName, &windowName, &nModeId, &data))
return JS_FALSE;

if(_strcmpi(windowClassName, "null") == 0)
JS_ValueToECMAUint32(cx, JS_ARGV(cx, vp)[1], (uint32*) &hWnd);
else
{
if (JSVAL_IS_STRING(JS_ARGV(cx, vp)[0]))
windowClassName = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));
if (JSVAL_IS_STRING(JS_ARGV(cx, vp)[1]))
windowName = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[1]));
if (JSVAL_IS_STRING(JS_ARGV(cx, vp)[2]))
data = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[2]));

}


if(windowClassName && _strcmpi(windowClassName, "null") == 0)
windowClassName = NULL;
if(_strcmpi(windowName, "null") == 0)
if(windowName && _strcmpi(windowName, "null") == 0)
windowName = NULL;
if(hWnd == NULL)
{
Expand Down Expand Up @@ -445,10 +449,8 @@ JSAPI_FUNC(my_hideConsole)

JSAPI_FUNC(my_loadMpq)
{
char* path = NULL;
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "s", &path))
return JS_FALSE;

char *path = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));

if(isValidPath(path))
LoadMPQ(path);

Expand Down
2 changes: 1 addition & 1 deletion JSExits.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "JSExits.h"

//JSAPI_EMPTY_CTOR(exit)
EMPTY_CTOR(exit)

void exit_finalize(JSContext *cx, JSObject *obj)
{
Expand Down
19 changes: 14 additions & 5 deletions JSMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,16 @@ JSAPI_FUNC(my_createGame)
return JS_TRUE;

char *name = NULL, *pass = NULL;
jschar *jsname = NULL , *jspass = NULL;
int32 diff = 3;
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "s/si", &name, &pass, &diff))
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "W/Wi", &jsname, &jspass, &diff))
{
JS_ReportError(cx, "Invalid arguments specified to createGame");
return JS_FALSE;
}
name = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));
pass = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[1]));

if(!pass)
pass = "";

Expand All @@ -289,13 +293,15 @@ JSAPI_FUNC(my_joinGame)
{
if(ClientState() != ClientStateMenu)
return JS_TRUE;

jschar *jsname = NULL , *jspass = NULL;
char *name = NULL, *pass = NULL;
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "s/s", &name, &pass))
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "W/W", &jsname, &jspass))
{
JS_ReportError(cx, "Invalid arguments specified to createGame");
return JS_FALSE;
}
name = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));
pass = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[1]));
if(!pass)
pass = "";

Expand Down Expand Up @@ -373,11 +379,14 @@ JSAPI_FUNC(my_createCharacter)
return JS_TRUE;

char* name = NULL;
jschar* jsname= NULL;
int32 type = -1;
JSBool hc = JS_FALSE, ladder = JS_FALSE;
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "si/bb", &name, &type, &hc, &ladder))
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "Wi/bb", &jsname, &type, &hc, &ladder))
return JS_FALSE;

name = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));

JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(!!OOG_CreateCharacter(name, type, !!hc, !!ladder)));
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(!!OOG_CreateCharacter(name, type, !!hc, !!ladder)));
return JS_TRUE;
}
3 changes: 1 addition & 2 deletions JSParty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ JSAPI_FUNC(my_getParty)

if(JSVAL_IS_STRING(JS_ARGV(cx, vp)[0]))
{
if(!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "s", &nPlayerName))
THROW_ERROR(cx, "Unable to get Name");
char *nPlayerName = JS_EncodeString(cx,JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));
}
else if(JSVAL_IS_INT(JS_ARGV(cx, vp)[0]))
{
Expand Down
2 changes: 1 addition & 1 deletion JSScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "D2BS.h"
#include "Helpers.h"

//JSAPI_EMPTY_CTOR(script)
EMPTY_CTOR(script)

struct FindHelper
{
Expand Down
5 changes: 3 additions & 2 deletions JSUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ JSAPI_PROP(unit_getProperty)

if(ClientState() != ClientStateInGame)
return JS_TRUE;

myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, JS_THIS_OBJECT(cx, vp));
//JSObject* obj ;
//JS_ValueToObject(cx, JS_CALLEE(cx,vp),obj);
myUnit* lpUnit = (myUnit*)JS_GetPrivate(cx, obj);
if(!lpUnit || (lpUnit->_dwPrivateType & PRIVATE_UNIT) != PRIVATE_UNIT)
return JS_TRUE;

Expand Down
14 changes: 8 additions & 6 deletions ScreenHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ Genhook::Genhook(Script* nowner, JSObject* nself, uint x, uint y, ushort nopacit
//InitializeCriticalSection(&hookSection);
clicked = JSVAL_VOID;
hovered = JSVAL_VOID;
JS_AddRoot(&self);
self = nself;
JS_AddObjectRoot(owner->GetContext(),&self);
//JS_AddRoot(&self);
SetX(x); SetY(y);
visible.push_back(this);
}
Expand All @@ -191,7 +192,8 @@ Genhook::~Genhook(void) {
JS_RemoveRoot(&clicked);
if(owner && !JSVAL_IS_VOID(hovered))
JS_RemoveRoot(&hovered);
JS_RemoveRoot(&self);
JS_RemoveObjectRoot(owner->GetContext(), &self);
//JS_RemoveRoot(&self);

EnterCriticalSection(&globalSection);

Expand Down Expand Up @@ -276,10 +278,10 @@ void Genhook::SetClickHandler(jsval handler)
Lock();
if(!JSVAL_IS_VOID(clicked))
JS_RemoveRoot(&clicked);
JSContext* cx = ScriptEngine::GetGlobalContext();
JSContext* cx = owner->GetContext();


JS_SetContextThread(cx);
//JS_SetContextThread(cx);
JS_BeginRequest(cx);
if(JSVAL_IS_FUNCTION(cx, handler))
clicked = handler;
Expand All @@ -289,12 +291,12 @@ void Genhook::SetClickHandler(jsval handler)
{
Unlock();
JS_EndRequest(cx);
JS_ClearContextThread(cx);
//JS_ClearContextThread(cx);
return;
}
}
JS_EndRequest(cx);
JS_ClearContextThread(cx);
//JS_ClearContextThread(cx);
Unlock();
}

Expand Down
Loading

0 comments on commit 649cb47

Please sign in to comment.