Skip to content

Commit

Permalink
1.0.11.0 - Pointer.copyTo
Browse files Browse the repository at this point in the history
  • Loading branch information
karikera committed Jan 12, 2022
1 parent a17f4d3 commit f8de8f0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bdsx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void nodegate::initNativeModule(void* exports_raw) noexcept
bedrock_server_exe.set(u"mainOriginal12Bytes", VoidPointer::make(s_bedrockMainOriginal12Bytes));
bedrock_server_exe.setMethod(u"forceKill", kr::terminate);
}

{
JsValue cgate = JsNewObject;
exports.set(u"cgate", cgate);
Expand Down Expand Up @@ -270,6 +270,10 @@ void nodegate::initNativeModule(void* exports_raw) noexcept

cgate.set(u"toWide", VoidPointer::make(String_toWide));
cgate.set(u"toUtf8", VoidPointer::make(String_toUtf8));

#ifndef NDEBUG
cgate.setMethod(u"memcheck", memcheck);
#endif
}

{
Expand Down
12 changes: 12 additions & 0 deletions bdsx/staticpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ void StaticPointer::copyFrom(VoidPointer* from, int bytes, int this_offset, int
accessViolation(m_address);
}
}
void StaticPointer::copyTo(kr::JsValue buffer, int bytes, int offset) throws(kr::JsException) {
VoidPointer* ptr = buffer.getNativeObject<VoidPointer>();
if (ptr != nullptr) {
memcpy(ptr->getAddressRaw(), m_address + offset, (uint32_t)bytes);
return;
}
WBuffer buf = buffer.getBuffer();
if (buf == nullptr) throw JsException(u"argument must be buffer or pointer");
size_t minv = maxt((size_t)buf.size(), (uint32_t)bytes);
memcpy(buf.data(), m_address + offset, minv);
}
void StaticPointer::setBoolean(bool v, int offset) throws(JsException)
{
return _setas(v, offset);
Expand Down Expand Up @@ -556,6 +567,7 @@ void StaticPointer::initMethods(JsClassT<StaticPointer>* cls) noexcept

cls->setMethod(u"fill", &StaticPointer::fill);
cls->setMethod(u"copyFrom", &StaticPointer::copyFrom);
cls->setMethod(u"copyTo", &StaticPointer::copyTo);
cls->setMethod(u"setBoolean", &StaticPointer::setBoolean);
cls->setMethod(u"setUint8", &StaticPointer::setUint8);
cls->setMethod(u"setUint16", &StaticPointer::setUint16);
Expand Down
1 change: 1 addition & 0 deletions bdsx/staticpointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class StaticPointer :public kr::JsObjectT<StaticPointer, VoidPointer>

void fill(int bytevalue, int bytes, int offset) throws(kr::JsException);
void copyFrom(VoidPointer* from, int bytes, int this_offset, int from_offset) throws(kr::JsException);
void copyTo(kr::JsValue buffer, int bytes, int offset) throws(kr::JsException);
void setBoolean(bool v, int offset) throws(kr::JsException);
void setUint8(uint8_t v, int offset) throws(kr::JsException);
void setUint16(uint16_t v, int offset) throws(kr::JsException);
Expand Down
2 changes: 1 addition & 1 deletion bdsx/version.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

set BDSX_CORE_VERSION=1.0.10.0
set BDSX_CORE_VERSION=1.0.11.0

0 comments on commit f8de8f0

Please sign in to comment.