MCPcopy Create free account
hub / github.com/DFHack/dfhack / checkState

Method checkState

library/binpatch.cpp:153–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153BinaryPatch::State BinaryPatch::checkState(const patch_byte *ptr, size_t len)
154{
155 int state = 0;
156
157 for (size_t i = 0; i < entries.size(); i++)
158 {
159 Byte &bv = entries[i];
160
161 if (bv.offset >= len)
162 {
163 cerr << "Offset out of range: 0x" << std::hex << bv.offset << std::dec << endl;
164 return Conflict;
165 }
166
167 patch_byte cv = ptr[bv.offset];
168 if (bv.old_val == cv)
169 state |= Unapplied;
170 else if (bv.new_val == cv)
171 state |= Applied;
172 else
173 {
174 cerr << std::hex << bv.offset << ": "
175 << unsigned(bv.old_val) << " " << unsigned(bv.new_val)
176 << ", but currently " << unsigned(cv) << std::dec << endl;
177 return Conflict;
178 }
179 }
180
181 return State(state);
182}
183
184void BinaryPatch::apply(patch_byte *ptr, size_t len, bool newv)
185{

Callers 1

mainFunction · 0.80

Calls 2

StateEnum · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected