Skip to content

Commit

Permalink
attempt at 1.8 js. has alot of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bobode committed May 20, 2012
1 parent c30be47 commit 3962846
Show file tree
Hide file tree
Showing 70 changed files with 9,614 additions and 6,941 deletions.
2 changes: 1 addition & 1 deletion D2BS.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma once

#define XP_WIN
#define JS_THREADSAFE
//#define JS_THREADSAFE

#define D2BS_VERSION "1.4.1703"

Expand Down
36 changes: 15 additions & 21 deletions D2BS.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,11 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="$(NoInherit) kernel32.lib user32.lib gdi32.lib shlwapi.lib advapi32.lib dbghelp.lib js32/js32.lib"
AdditionalDependencies="kernel32.lib user32.lib gdi32.lib shlwapi.lib advapi32.lib dbghelp.lib dependencies\libs\debug\mozjs.lib $(NOINHERIT)"
LinkIncremental="1"
SuppressStartupBanner="true"
UACExecutionLevel="2"
UACUIAccess="true"
ModuleDefinitionFile=""
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
Expand Down Expand Up @@ -512,55 +514,51 @@
Name="Engine Imports"
>
<File
RelativePath=".\js32\jsapi.h"
>
</File>
<File
RelativePath=".\js32\jscompat.h"
RelativePath=".\dependencies\include\js-config.h"
>
</File>
<File
RelativePath=".\js32\jsconfig.h"
RelativePath=".\dependencies\include\jsapi.h"
>
</File>
<File
RelativePath=".\js32\jscpucfg.h"
RelativePath=".\dependencies\include\jscompat.h"
>
</File>
<File
RelativePath=".\js32\jsdbgapi.h"
RelativePath=".\dependencies\include\jscpucfg.h"
>
</File>
<File
RelativePath=".\js32\jslong.h"
RelativePath=".\dependencies\include\jsinttypes.h"
>
</File>
<File
RelativePath=".\js32\jsopcode.h"
RelativePath=".\dependencies\include\jsotypes.h"
>
</File>
<File
RelativePath=".\js32\jsosdep.h"
RelativePath=".\dependencies\include\jsproto.tbl"
>
</File>
<File
RelativePath=".\js32\jsotypes.h"
RelativePath=".\dependencies\include\jspubtd.h"
>
</File>
<File
RelativePath=".\js32\jsprvtd.h"
RelativePath=".\dependencies\include\jstypes.h"
>
</File>
<File
RelativePath=".\js32\jspubtd.h"
RelativePath=".\dependencies\include\jsutil.h"
>
</File>
<File
RelativePath=".\js32\jstypes.h"
RelativePath=".\dependencies\include\jsval.h"
>
</File>
<File
RelativePath=".\js32\jsutil.h"
RelativePath=".\dependencies\include\jsversion.h"
>
</File>
</Filter>
Expand Down Expand Up @@ -867,10 +865,6 @@
<Filter
Name="Engine"
>
<File
RelativePath=".\AutoRoot.cpp"
>
</File>
<File
RelativePath=".\AutoRoot.h"
>
Expand Down
4 changes: 2 additions & 2 deletions File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool writeValue(FILE* fptr, JSContext* cx, jsval value, bool isBinary, bool lock
return true;
break;
case JSTYPE_STRING:
str = JS_GetStringBytes(JSVAL_TO_STRING(value));
str = JS_EncodeString(cx,JSVAL_TO_STRING(value));
if(locking)
result = fwrite(str, sizeof(char), strlen(str), fptr);
else
Expand Down Expand Up @@ -171,7 +171,7 @@ bool writeValue(FILE* fptr, JSContext* cx, jsval value, bool isBinary, bool lock
else
{
JSString* jsstr = JS_ValueToString(cx, value);
str = JS_GetStringBytes(jsstr);
str = JS_EncodeString(cx,jsstr);
if(locking)
result = fwrite(str, sizeof(char), strlen(str), fptr);
else
Expand Down
19 changes: 10 additions & 9 deletions JSArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "CriticalSections.h"
#include "MapHeader.h"

EMPTY_CTOR(area)
JSAPI_EMPTY_CTOR(area)

void area_finalize(JSContext *cx, JSObject *obj)
{
Expand All @@ -29,7 +29,9 @@ JSAPI_PROP(area_getProperty)
if(!pLevel)
return JS_FALSE;

switch(JSVAL_TO_INT(id))
jsval ID;
JS_IdToValue(cx,id,&ID);
switch(JSVAL_TO_INT(ID))
{
case AUNIT_EXITS:
{
Expand Down Expand Up @@ -107,8 +109,8 @@ JSAPI_FUNC(my_getArea)

if(argc == 1)
{
if(JSVAL_IS_INT(argv[0]))
JS_ValueToECMAInt32(cx, argv[0], &nArea);
if(JSVAL_IS_INT(JS_ARGV(cx, vp)[0]))
JS_ValueToECMAInt32(cx, JS_ARGV(cx, vp)[0], &nArea);
else
THROW_ERROR(cx, "Invalid parameter passed to getArea!");
}
Expand All @@ -120,14 +122,14 @@ JSAPI_FUNC(my_getArea)

if(!pLevel)
{
*rval = JSVAL_FALSE;
JS_SET_RVAL(cx, vp, JSVAL_FALSE);
return JS_TRUE;
}

myArea* pArea = new myArea;
if(!pArea)
{
*rval = JSVAL_FALSE;
JS_SET_RVAL(cx, vp, JSVAL_FALSE);
return JS_TRUE;
}

Expand All @@ -141,8 +143,7 @@ JSAPI_FUNC(my_getArea)
pArea = NULL;
THROW_ERROR(cx, "Failed to build area unit!");
}

*rval = OBJECT_TO_JSVAL(unit);

JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(unit));

return JS_TRUE;
}
61 changes: 33 additions & 28 deletions JSControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Helpers.h"
#include "D2Helpers.h"

EMPTY_CTOR(control)
JSAPI_EMPTY_CTOR(control)

void control_finalize(JSContext *cx, JSObject *obj)
{
Expand All @@ -21,15 +21,17 @@ JSAPI_PROP(control_getProperty)
if(ClientState() != ClientStateMenu)
return JS_FALSE;

ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
ControlData *pData = ((ControlData*)JS_GetPrivate(cx, JS_THIS_OBJECT(cx, vp)));
if(!pData)
return JS_FALSE;

Control* ctrl = findControl(pData->dwType, (char *)NULL, -1, pData->dwX, pData->dwY, pData->dwSizeX, pData->dwSizeY);
if(!ctrl)
return JS_FALSE;

switch(JSVAL_TO_INT(id))
jsval ID;
JS_IdToValue(cx,id,&ID);
switch(JSVAL_TO_INT(ID))
{
case CONTROL_TEXT:
if(ctrl->dwIsCloaked != 33)
Expand Down Expand Up @@ -83,25 +85,27 @@ JSAPI_PROP(control_getProperty)
return JS_TRUE;
}

JSAPI_PROP(control_setProperty)
JSAPI_STRICT_PROP(control_setProperty)
{
if(ClientState() != ClientStateMenu)
return JS_FALSE;

ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
ControlData *pData = ((ControlData*)JS_GetPrivate(cx, JS_THIS_OBJECT(cx, vp)));
if(!pData)
return JS_FALSE;

Control* ctrl = findControl(pData->dwType, (char *)NULL, -1, pData->dwX, pData->dwY, pData->dwSizeX, pData->dwSizeY);
if(!ctrl)
return JS_FALSE;

switch(JSVAL_TO_INT(id))
jsval ID;
JS_IdToValue(cx,id,&ID);
switch(JSVAL_TO_INT(ID))
{
case CONTROL_TEXT:
if(ctrl->dwType == 1 && JSVAL_IS_STRING(*vp))
{
char* pText = JS_GetStringBytes(JS_ValueToString(cx, *vp));
char* pText = JS_EncodeString(cx,JS_ValueToString(cx, *vp));
if(!pText)
return JS_TRUE;
wchar_t* szwText = AnsiToUnicode(pText);
Expand All @@ -121,7 +125,7 @@ JSAPI_PROP(control_setProperty)
case CONTROL_CURSORPOS:
if(JSVAL_IS_INT(*vp))
{
DWORD dwPos;
uint32 dwPos;
if(!JS_ValueToECMAUint32(cx, *vp, &dwPos))
THROW_ERROR(cx, "Invalid cursor position value");
memset((void*)&ctrl->dwCursorPos, dwPos, sizeof(DWORD));
Expand All @@ -143,7 +147,7 @@ JSAPI_FUNC(control_getNext)
if(ClientState() != ClientStateMenu)
return JS_TRUE;

ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
ControlData *pData = ((ControlData*)JS_GetPrivate(cx, JS_THIS_OBJECT(cx, vp)));
if(!pData)
return JS_TRUE;

Expand All @@ -161,15 +165,16 @@ JSAPI_FUNC(control_getNext)
pData->dwY = pData->pControl->dwPosY;
pData->dwSizeX = pData->pControl->dwSizeX;
pData->dwSizeY = pData->pControl->dwSizeY;
JS_SetPrivate(cx, obj, pData);
*rval = OBJECT_TO_JSVAL(obj);
JS_SetPrivate(cx, JS_THIS_OBJECT(cx, vp), pData);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(JS_THIS_OBJECT(cx, vp)));
}
else
{
JSObject* obj = JS_THIS_OBJECT(cx, vp);
JS_ClearScope(cx, obj);
if(JS_ValueToObject(cx, JSVAL_NULL, &obj) == JS_FALSE)
return JS_TRUE;
*rval = JSVAL_FALSE;
JS_SET_RVAL(cx, vp, JSVAL_FALSE);
}

return JS_TRUE;
Expand All @@ -180,23 +185,23 @@ JSAPI_FUNC(control_click)
if(ClientState() != ClientStateMenu)
return JS_TRUE;

ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
ControlData *pData = ((ControlData*)JS_GetPrivate(cx, JS_THIS_OBJECT(cx, vp)));
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_SET_RVAL(cx, vp, INT_TO_JSVAL(0));
return JS_TRUE;
}

uint32 x = (uint32)-1, y = (uint32)-1;

if(argc > 1 && JSVAL_IS_INT(argv[0]) && JSVAL_IS_INT(argv[1]))
if(argc > 1 && JSVAL_IS_INT(JS_ARGV(cx, vp)[0]) && JSVAL_IS_INT(JS_ARGV(cx, vp)[1]))
{
JS_ValueToECMAUint32(cx, argv[0], &x);
JS_ValueToECMAUint32(cx, argv[1], &y);
JS_ValueToECMAUint32(cx, JS_ARGV(cx, vp)[0], &x);
JS_ValueToECMAUint32(cx, JS_ARGV(cx, vp)[1], &y);
}

clickControl(pControl, x, y);
Expand All @@ -209,21 +214,21 @@ JSAPI_FUNC(control_setText)
if(ClientState() != ClientStateMenu)
return JS_TRUE;

ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
ControlData *pData = ((ControlData*)JS_GetPrivate(cx, JS_THIS_OBJECT(cx, vp)));
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_SET_RVAL(cx, vp,INT_TO_JSVAL(0));
return JS_TRUE;
}

if(argc < 0 || !JSVAL_IS_STRING(argv[0]))
if(argc < 0 || !JSVAL_IS_STRING(JS_ARGV(cx, vp)[0]))
return JS_TRUE;

char* pText = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char* pText = JS_EncodeString(cx,JS_ValueToString(cx, JS_ARGV(cx, vp)[0]));
if(!pText)
return JS_TRUE;
wchar_t* szwText = AnsiToUnicode(pText);
Expand All @@ -239,22 +244,23 @@ JSAPI_FUNC(control_getText)
if(ClientState() != ClientStateMenu)
return JS_TRUE;

ControlData *pData = ((ControlData*)JS_GetPrivate(cx, obj));
ControlData *pData = ((ControlData*)JS_GetPrivate(cx, JS_THIS_OBJECT(cx, vp)));
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_SET_RVAL(cx, vp, INT_TO_JSVAL(0));
return JS_TRUE;
}

if(pControl->dwType != 4 || !pControl->pFirstText)
return JS_TRUE;

JSObject* pReturnArray = JS_NewArrayObject(cx, 0, NULL);
*rval = OBJECT_TO_JSVAL(pReturnArray);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(pReturnArray));

int nArrayCount = 0;

for(ControlText* pText = pControl->pFirstText; pText; pText = pText->pNext)
Expand Down Expand Up @@ -283,8 +289,8 @@ JSAPI_FUNC(my_getControl)
int32 *args[] = {&nType, &nX, &nY, &nXSize, &nYSize};

for(uintN i = 0; i < argc; i++)
if(JSVAL_IS_INT(argv[i]))
JS_ValueToECMAInt32(cx, argv[i], args[i]);
if(JSVAL_IS_INT(JS_ARGV(cx, vp)[i]))
JS_ValueToECMAInt32(cx, JS_ARGV(cx, vp)[i], args[i]);

Control* pControl = findControl(nType, (char*)NULL, -1, nX, nY, nXSize, nYSize);
if(!pControl)
Expand All @@ -301,7 +307,6 @@ JSAPI_FUNC(my_getControl)
if(!control)
THROW_ERROR(cx, "Failed to build control!");

*rval = OBJECT_TO_JSVAL(control);

JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(control));
return JS_TRUE;
}
2 changes: 1 addition & 1 deletion JSControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ JSAPI_FUNC(control_setText);
JSAPI_FUNC(control_getText);

JSAPI_PROP(control_getProperty);
JSAPI_PROP(control_setProperty);
JSAPI_STRICT_PROP(control_setProperty);

struct ControlData {
DWORD _dwPrivate;
Expand Down
Loading

0 comments on commit 3962846

Please sign in to comment.