Skip to content

Instantly share code, notes, and snippets.

@byteandahalf
Forked from Khristian-kun/Main.cpp
Last active November 16, 2015 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byteandahalf/f67ca550c3b5b4c473fe to your computer and use it in GitHub Desktop.
Save byteandahalf/f67ca550c3b5b4c473fe to your computer and use it in GitHub Desktop.
Override Lava Bucket
#include <string>
class TextureUVCoordinateSet;
struct Item {
void** vtable; // 0
static void initItems();
static TextureUVCoordinateSet getTextureUVCoordinateSet(const std::string&, int);
static Item* mItems[512];
};
const TextureUVCoordinateSet& _myGetIcon(Item* ptr, int data, int, bool) {
switch(data) {
case 1: // Milk
return Item::getTextureUVCoordinateSet("bucket", 1);
case 8: // Water
return Item::getTextureUVCoordinateSet("bucket", 2);
case 10: // Lava
return Item::getTextureUVCoordinateSet("coal", 0); // Return a custom texture for lava.
default: // Empty
return Item::getTextureUVCoordinateSet("bucket", 0);
}
}
void (*_Item$initItems)();
void Item$initItems() {
// Call the real pointer so that all Items will be initialized
_Item$initItems();
// Get the BucketItem vtable and replace the 45th function (_ZNK4Item7getIconEiib) with our own code.
Item::mItems[325]->vtable[45] = (void*) &_myGetItem;
}
// Add this into your JNI_OnLoad in your addon.
MSHookFunction((void*) &Item::initItems, (void*) &Item$initItems, (void**) &_Item$initItems);
@Khristian-kun
Copy link

thanks for the example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment