diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index 341164441..fa2aacf78 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -374,7 +374,7 @@ void DFHack::bitfieldToString(std::vector *pvec, const void *p, unsigned size, const bitfield_item_info *items) { for (unsigned i = 0; i < size; i++) { - int value = getBitfieldField(p, i, std::min(1,items[i].size)); + int value = getBitfieldField(p, i, std::max(1,items[i].size)); if (value) { std::string name = format_key(items[i].name, i); diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp index e71977960..9f2689fa9 100644 --- a/library/LuaTypes.cpp +++ b/library/LuaTypes.cpp @@ -894,7 +894,7 @@ static int meta_bitfield_len(lua_State *state) static void read_bitfield(lua_State *state, uint8_t *ptr, bitfield_identity *id, int idx) { - int size = id->getBits()[idx].size; + int size = std::max(1, id->getBits()[idx].size); int value = getBitfieldField(ptr, idx, size); if (size <= 1) @@ -951,7 +951,7 @@ static int meta_bitfield_newindex(lua_State *state) } int idx = check_container_index(state, id->getNumBits(), 2, iidx, "write"); - int size = id->getBits()[idx].size; + int size = std::max(1, id->getBits()[idx].size); if (lua_isboolean(state, 3) || lua_isnil(state, 3)) setBitfieldField(ptr, idx, size, lua_toboolean(state, 3)); diff --git a/library/VTableInterpose.cpp b/library/VTableInterpose.cpp index 079890fe4..583ef5184 100644 --- a/library/VTableInterpose.cpp +++ b/library/VTableInterpose.cpp @@ -335,8 +335,14 @@ void VMethodInterposeLinkBase::on_host_delete(virtual_identity *from) } } -bool VMethodInterposeLinkBase::apply() +bool VMethodInterposeLinkBase::apply(bool enable) { + if (!enable) + { + remove(); + return true; + } + if (is_applied()) return true; if (!host->vtable_ptr) diff --git a/library/include/VTableInterpose.h b/library/include/VTableInterpose.h index c9482f82c..7ba6b67aa 100644 --- a/library/include/VTableInterpose.h +++ b/library/include/VTableInterpose.h @@ -159,7 +159,7 @@ namespace DFHack ~VMethodInterposeLinkBase(); bool is_applied() { return applied; } - bool apply(); + bool apply(bool enable = true); void remove(); };