Skip to content

Commit 0a7ce03

Browse files
added GetBitmapResource
1 parent 4b10693 commit 0a7ce03

File tree

11 files changed

+82
-5
lines changed

11 files changed

+82
-5
lines changed

XEditLib.dll

0 Bytes
Binary file not shown.

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"src/messages.cc",
1010
"src/setup.cc",
1111
"src/archives.cc",
12+
"src/textures.cc",
1213
"src/files.cc",
1314
"src/masters.cc",
1415
"src/elements.cc",

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require('./lib/meta')(lib, xelib, helpers);
77
require('./lib/messages')(lib, xelib, helpers);
88
require('./lib/setup')(lib, xelib, helpers);
99
require('./lib/archives')(lib, xelib, helpers);
10+
require('./lib/textures')(lib, xelib, helpers);
1011
require('./lib/files')(lib, xelib, helpers);
1112
require('./lib/masters')(lib, xelib, helpers);
1213
require('./lib/elements')(lib, xelib, helpers);

lib/helpers.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ module.exports = function(lib, xelib) {
1414
return a;
1515
};
1616

17+
helpers.readImageData = function(buf, width, height) {
18+
let a = new Uint8ClampedArray(buf);
19+
return new ImageData(a, width, height);
20+
};
21+
1722
helpers.wcb = function(value) {
1823
let buf = Buffer.alloc((value.length + 1) * 2, 0);
1924
buf.write(value, 0, 'ucs2');
@@ -115,6 +120,22 @@ module.exports = function(lib, xelib) {
115120
return str !== '' ? str.split('\r\n') : [];
116121
};
117122

123+
helpers.GetImageData = function(callback) {
124+
let _width = Buffer.alloc(4, 0),
125+
_height = Buffer.alloc(4, 0);
126+
callback(_width, _height);
127+
let width = _width.readInt32LE(0),
128+
height = _height.readInt32LE(0);
129+
if (width < 1 || height < 1)
130+
throw new Error(`Invalid ImageData dimensions: ${width} x ${height}`);
131+
let len = width * height,
132+
buf = Buffer.alloc(len, 0);
133+
if (xelib.verbose) xelib.logger.info(`GetResultBytes(len: ${len})`);
134+
if (!lib.GetResultBytes(buf, len))
135+
helpers.Fail('GetResultBytes failed');
136+
return helpers.readImageData(buf, width, height);
137+
};
138+
118139
helpers.GetDictionary = function(callback, method = 'GetResultString') {
119140
let pairs = helpers.GetStringArray(callback, method),
120141
dictionary = {};

lib/textures.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = function(lib, xelib, helpers) {
2+
let { Fail, GetImageData, wcb } = helpers;
3+
4+
// FILE HANDLING METHODS
5+
Object.assign(xelib, {
6+
GetBitmapResource: function(resourceName) {
7+
return GetImageData(function(_width, _height) {
8+
if (!lib.GetBitmapResource(wcb(resourceName), _width, _height))
9+
Fail(`Failed to get bitmap resource for ${resourceName}`);
10+
});
11+
}
12+
});
13+
};

src/lib.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ typedef Integer* PInteger;
1616
typedef std::wstring* PWChar;
1717

1818
// function declaration
19-
const int NUM_FUNCTIONS = 153;
19+
const int NUM_FUNCTIONS = 155;
2020

2121
static const char* FUNCTION_NAMES [NUM_FUNCTIONS] = {
2222
// META METHODS
23-
"InitXEdit", "CloseXEdit", "GetResultString", "GetResultArray", "GetGlobal", "GetGlobals",
24-
"SetSortMode", "Release", "ReleaseNodes", "Switch", "GetDuplicateHandles", "CleanStore",
25-
"ResetStore",
23+
"InitXEdit", "CloseXEdit", "GetResultString", "GetResultArray", "GetResultBytes",
24+
"GetGlobal", "GetGlobals", "SetSortMode", "Release", "ReleaseNodes", "Switch",
25+
"GetDuplicateHandles", "CleanStore", "ResetStore",
2626
// MESSAGE METHODS
2727
"GetMessagesLength", "GetMessages", "ClearMessages", "GetExceptionMessageLength",
2828
"GetExceptionMessage", "GetExceptionStackLength", "GetExceptionStack",
@@ -32,6 +32,8 @@ static const char* FUNCTION_NAMES [NUM_FUNCTIONS] = {
3232
"GetLoaderStatus", "UnloadPlugin",
3333
// ARCHIVE HANDLING METHODS
3434
"ExtractContainer", "ExtractFile", "GetContainerFiles", "GetLoadedContainers", "LoadContainer",
35+
// TEXTURE HANDLING METHODS
36+
"GetBitmapResource",
3537
// FILE HANDLING METHODS
3638
"AddFile", "FileByIndex", "FileByLoadOrder", "FileByName", "FileByAuthor", "NukeFile",
3739
"RenameFile", "SaveFile", "GetRecordCount", "GetOverrideRecordCount", "MD5Hash", "CRCHash",
@@ -73,6 +75,7 @@ struct functions_struct {
7375
void (__cdecl* CloseXEdit)();
7476
WordBool (__cdecl* GetResultString)(PWChar, Integer);
7577
WordBool (__cdecl* GetResultArray)(PCardinal, Integer);
78+
WordBool (__cdecl* GetResultBytes)(PByte, Integer);
7679
WordBool (__cdecl* GetGlobal)(PWChar, PInteger);
7780
WordBool (__cdecl* GetGlobals)(PInteger);
7881
WordBool (__cdecl* SetSortMode)(Byte, WordBool);
@@ -110,6 +113,8 @@ struct functions_struct {
110113
WordBool (__cdecl* GetContainerFiles)(PWChar, PInteger);
111114
WordBool (__cdecl* GetLoadedContainers)(PInteger);
112115
WordBool (__cdecl* LoadContainer)(PWChar);
116+
// TEXTURE HANDLING METHODS
117+
WordBool (__cdecl* GetBitmapResource)(PWChar, PInteger, PInteger);
113118
// FILE HANDLING METHODS
114119
WordBool (__cdecl* AddFile)(PWChar, PCardinal);
115120
WordBool (__cdecl* FileByIndex)(Integer, PCardinal);

src/meta.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ NAN_METHOD(GetResultArray) {
3838
info.GetReturnValue().Set(Nan::New((bool) success));
3939
}
4040

41+
NAN_METHOD(GetResultBytes) {
42+
PByte result = (PByte) node::Buffer::Data(info[0]->ToObject());
43+
Integer len = info[1]->Int32Value();
44+
WordBool success = true;
45+
if (len > 0) success = xelib.functions.GetResultBytes(result, len);
46+
info.GetReturnValue().Set(Nan::New((bool) success));
47+
}
48+
4149
NAN_METHOD(GetGlobal) {
4250
PWChar key = (PWChar) node::Buffer::Data(info[0]->ToObject());
4351
PInteger len = (PInteger) node::Buffer::Data(info[1]->ToObject());

src/meta.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ NAN_METHOD(InitXEdit);
77
NAN_METHOD(CloseXEdit);
88
NAN_METHOD(GetResultString);
99
NAN_METHOD(GetResultArray);
10+
NAN_METHOD(GetResultBytes);
1011
NAN_METHOD(GetGlobal);
1112
NAN_METHOD(GetGlobals);
1213
NAN_METHOD(SetSortMode);

src/textures.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <nan.h>
2+
#include "textures.h"
3+
#include "lib.h"
4+
5+
using namespace Nan;
6+
7+
NAN_METHOD(GetBitmapResource) {
8+
PWChar name = (PWChar) node::Buffer::Data(info[0]->ToObject());
9+
PInteger width = (PInteger) node::Buffer::Data(info[1]->ToObject());
10+
PInteger height = (PInteger) node::Buffer::Data(info[2]->ToObject());
11+
WordBool success = xelib.functions.GetBitmapResource(name, width, height);
12+
info.GetReturnValue().Set(Nan::New((bool) success));
13+
}

src/textures.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef XELIB_TEXTURES_H
2+
#define XELIB_TEXTURES_H
3+
4+
#include <nan.h>
5+
6+
// NAN METHODS
7+
NAN_METHOD(GetBitmapResource);
8+
9+
#endif

0 commit comments

Comments
 (0)