I think the problem is that
stuff->Write(space, timeBuffer, 6); // My code I run in new space
&
stuff->writeJump(space + 6, info.baseAddr + 0xDD7E); // jump back 6 bytes ahead of first
the first line causes a problem because...you only copy 6 bytes out of timeBuffer -- so
not the whole cpu instruction..!
your codecave will be 6 bytes of timeBuffer + jump back
BYTE timeBuffer[] = {0xC7, 0x86, 0x7C, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
c7,86,7c,03,00,00, + ff,25, +{first 2 bytes of addr} == 10 byte mov instruction
not the cpu instruction you want to execute.
You're only copying part of the mov instruction: But since the first few bytes are set up like the move instruction, that's what it is, and the cpu expects it to be 10 bytes, so it reads 10 bytes. Because you only copied over 6, the next 4 bytes it will get are part of the jump-back instruction! 0xff,0x25, and the first 2 bytes of the address you pass in. It's still a move instruction, but not the one you want : p After this point, the cpu will continue decoding the next bytes in ram, and since it took a chunk off the "jump back" instruction (it took the ff,25,first 2 bytes of addr), the jump-back instruction is now incomplete! The cpu's next instruction will be...the last 2 bytes of the addr we passed in -- random, and probably junk. This would cause a crash.
"It does however work if I fill the code I am patching with nop's."
because copying 6 bytes of nop's results in 6 complete instructions. copying 6 bytes of mov [esi+0x37c],0x1 isn't a complete instruction
(^^edit: I assumed you were talking about writing nops to *your codecave* and having that work.. ie. if the nops work, and your code doesn't, there is a problem with your code. But looking at your code you nopped the game-code instruction -- maybe you tried both? Anyway, your codecave *could* consist of 6 nops + a jmp back)
solution: (line1) copy the whole 'timeBuffer' instruction into your codecave (change 6 to 10 ofc)
(line2) change where the jumpback gets written (change 6 to length of timeBuffer, again 10)
maybe?