Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
noah- committed Nov 22, 2018
1 parent 528f59c commit e44af3a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion D2BS.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define XP_WIN
#endif

#define D2BS_VERSION "1.5.1876U"
#define D2BS_VERSION "1.5.1877U"

#include <windows.h>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion D2BS.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<WarningLevel>Level4</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<DisableSpecificWarnings>4100;4127;4800;4480;4740;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<DisableSpecificWarnings>4100;4127;4800;4480;4740;4530;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<CompileAsManaged>false</CompileAsManaged>
<ExceptionHandling>false</ExceptionHandling>
</ClCompile>
Expand Down
2 changes: 1 addition & 1 deletion D2Intercepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ LONG WINAPI MyUnhandledExceptionFilter(_In_ struct _EXCEPTION_POINTERS* Exceptio
HANDLE hFile = INVALID_HANDLE_VALUE;
for (int i = 0; hFile == INVALID_HANDLE_VALUE; ++i) {
char fname[100];
sprintf(fname, "Crash%03d.dump", i);
sprintf_s(fname, "Crash%03d.dump", i);
hFile = CreateFile(fname, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
}
DWORD ProcessId = GetCurrentProcessId();
Expand Down
3 changes: 2 additions & 1 deletion File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ bool writeValue(FILE* fptr, JSContext* cx, jsval value, bool isBinary, bool lock
result = fwrite(str, sizeof(char), strlen(str), fptr);
else
result = _fwrite_nolock(str, sizeof(char), strlen(str), fptr);
return (int)strlen(str) == result;

JS_free(cx, str);
return (int)strlen(str) == result;
break;
case JSTYPE_NUMBER:
if (isBinary) {
Expand Down
18 changes: 6 additions & 12 deletions JSCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ JSAPI_FUNC(my_utf8ToEuc) {
JS_free(cx, Text);
delete[] szText;
delete[] euc;
return JS_TRUE;
}

JSAPI_FUNC(my_print) {
Expand Down Expand Up @@ -339,7 +340,6 @@ JSAPI_FUNC(my_copy) {
char* pText;
hText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, strlen(data) + 1);
pText = (char*)GlobalLock(hText);
char* tempData;

strcpy_s(pText, strlen(data) + 1, data);
GlobalUnlock(hText);
Expand Down Expand Up @@ -557,31 +557,28 @@ JSAPI_FUNC(my_sendPacket) {

if (!Vars.bEnableUnsupported) {
THROW_WARNING(cx, vp, "sendPacket requires EnableUnsupported = true in d2bs.ini");
return JS_TRUE;
}

JS_BeginRequest(cx);
BYTE* aPacket;
uint32 len = 0;
JS_BeginRequest(cx);

if (JSVAL_IS_OBJECT(JS_ARGV(cx, vp)[0])) {
JSObject* obj;
JS_ValueToObject(cx, JS_ARGV(cx, vp)[0], &obj);

if (!JS_IsArrayBufferObject(obj)) {
THROW_WARNING(cx, vp, "invalid ArrayBuffer parameter");
JS_EndRequest(cx);
return JS_TRUE;
THROW_WARNING(cx, vp, "invalid ArrayBuffer parameter");
}

len = JS_GetArrayBufferByteLength(obj);
aPacket = new BYTE[len];
memcpy(aPacket, JS_GetArrayBufferData(obj), len);
} else {
if (argc % 2 != 0) {
THROW_WARNING(cx, vp, "invalid packet format");
JS_EndRequest(cx);
return JS_TRUE;
THROW_WARNING(cx, vp, "invalid packet format");
}

aPacket = new BYTE[2 * argc];
Expand All @@ -605,7 +602,6 @@ JSAPI_FUNC(my_getPacket) {

if (!Vars.bEnableUnsupported) {
THROW_WARNING(cx, vp, "getPacket requires EnableUnsupported = true in d2bs.ini");
return JS_TRUE;
}

JS_BeginRequest(cx);
Expand All @@ -617,19 +613,17 @@ JSAPI_FUNC(my_getPacket) {
JS_ValueToObject(cx, JS_ARGV(cx, vp)[0], &obj);

if (!JS_IsArrayBufferObject(obj)) {
THROW_WARNING(cx, vp, "invalid ArrayBuffer parameter");
JS_EndRequest(cx);
return JS_TRUE;
THROW_WARNING(cx, vp, "invalid ArrayBuffer parameter");
}

len = JS_GetArrayBufferByteLength(obj);
aPacket = new BYTE[len];
memcpy(aPacket, JS_GetArrayBufferData(obj), len);
} else {
if (argc % 2 != 0) {
THROW_WARNING(cx, vp, "invalid packet format");
JS_EndRequest(cx);
return JS_TRUE;
THROW_WARNING(cx, vp, "invalid packet format");
}

aPacket = new BYTE[2 * argc];
Expand Down
2 changes: 0 additions & 2 deletions JSGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,14 +1424,12 @@ JSAPI_FUNC(my_moveNPC) {

if (!Vars.bEnableUnsupported) {
THROW_WARNING(cx, vp, "moveNPC requires EnableUnsupported = true in d2bs.ini");
return JS_TRUE;
}

if (argc < 2)
THROW_ERROR(cx, "Not enough parameters were passed to moveNPC!");

JS_SET_RVAL(cx, vp, JSVAL_FALSE);

myUnit* pNpc = (myUnit*)JS_GetPrivate(cx, JSVAL_TO_OBJECT(JS_ARGV(cx, vp)[0]));

if (!pNpc || pNpc->dwType != 1)
Expand Down
4 changes: 1 addition & 3 deletions JSSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ JSAPI_FUNC(socket_close) {

JSAPI_FUNC(socket_send) {
SocketData* sData = (SocketData*)JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx, vp), &socket_class, NULL);

char* msg = NULL;
int32 port = 0;

if (JSVAL_IS_STRING(JS_ARGV(cx, vp)[0]))
msg = JS_EncodeString(cx, JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]));

Expand Down Expand Up @@ -159,7 +158,6 @@ JSAPI_FUNC(socket_read) {
}

void socket_finalize(JSFreeOp* fop, JSObject* obj) {

SocketData* sData = (SocketData*)JS_GetPrivate(obj);
if (sData) {
closesocket(sData->socket);
Expand Down
12 changes: 6 additions & 6 deletions ScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void ScriptEngine::DisposeScript(Script* script) {
// bad things happen if we delete from another thread
Event* evt = new Event;
evt->owner = script;
evt->name = strdup("DisposeMe");
evt->name = _strdup("DisposeMe");
script->FireEvent(evt);
}
}
Expand Down Expand Up @@ -603,7 +603,7 @@ bool ExecScriptEvent(Event* evt, bool clearList) {
argv[2] = JS_NumberValue(*(DWORD*)evt->arg3);
argv[3] = JS_NumberValue(*(DWORD*)evt->arg4);

for (int j = 0; j < evt->argc; j++)
for (uint j = 0; j < evt->argc; j++)
JS_AddValueRoot(cx, &argv[j]);

jsval rval;
Expand Down Expand Up @@ -706,7 +706,7 @@ bool ExecScriptEvent(Event* evt, bool clearList) {
for (uint i = 0; i < *argc; i++)
evt->argv[i]->read(cx, &argv[i]);

for (int j = 0; j < *argc; j++)
for (uint j = 0; j < *argc; j++)
JS_AddValueRoot(cx, &argv[j]);

jsval rval;
Expand All @@ -715,7 +715,7 @@ bool ExecScriptEvent(Event* evt, bool clearList) {
}
JS_EndRequest(cx);

for (int j = 0; j < *argc; j++)
for (uint j = 0; j < *argc; j++)
JS_RemoveValueRoot(cx, &argv[j]);
}
for (uint i = 0; i < evt->argc; i++) {
Expand All @@ -732,14 +732,14 @@ bool ExecScriptEvent(Event* evt, bool clearList) {
if (!clearList) {
BYTE* help = (BYTE*)evt->arg1;
DWORD* size = (DWORD*)evt->arg2;
DWORD* argc = (DWORD*)1;
// DWORD* argc = (DWORD*)1;
JS_BeginRequest(cx);

JSObject* arr = JS_NewUint8Array(cx, *size);
// JSObject* arr = JS_NewArrayObject(cx, 0, NULL);

JS_AddRoot(cx, &arr);
for (int i = 0; i < *size; i++) {
for (uint i = 0; i < *size; i++) {
jsval jsarr = UINT_TO_JSVAL(help[i]);
JS_SetElement(cx, arr, i, &jsarr);
}
Expand Down

0 comments on commit e44af3a

Please sign in to comment.