Skip to content

Instantly share code, notes, and snippets.

View byteandahalf's full-sized avatar

Byteandahalf byteandahalf

View GitHub Profile
@byteandahalf
byteandahalf / MCPE Windows 10.4 Symbolicate.idc
Last active August 29, 2015 14:11
Using this in IDA will add some symbols to the Minecraft PE Windows Phone executable
#include <idc.idc>
#define sym(addr, sym) symbolicateAddr(addr, sym)
static symbolicateAddr(addr, sym) {
MakeFunction(addr, BADADDR);
if(MakeNameEx(addr, sym, SN_NOWARN)) return;
auto i;
for(i = 0; i < 999; i++) if(MakeNameEx(addr, form("%s_%d", sym, i), SN_NOWARN)) return;
}
@byteandahalf
byteandahalf / Redstone Renderer.cpp
Created December 20, 2014 19:45
Code for rendering Redstone dust in Minecraft Pocket Edition
bool TileTessellator::tessellateRedstoneTileInWorld(RedstoneTile* tile, int x, int y, int z, TilePos const& pos, TileSource* tilesource) {
Tessellator* tessellator = tessellator_inst;
int data = (int) tilesource->getData(x, y, z);
// implement my own Texture system because of issues with MCPE's normal TextureUVCoordinateSet
RendererTexture* cross = new RendererTexture(0.0625F, 0.0937F, 0.5F, 0.5625F, 16, 16); // Cross texture
RendererTexture* line = new RendererTexture(0.125F, 0.1562F, 0.5F, 0.5625F, 16, 16); // line texture
RendererTexture* cross_overlay = new RendererTexture(0.0938F, 0.125F, 0.5F, 0.5625F, 16, 16); // cross overlay
RendererTexture* line_overlay = new RendererTexture(0.1563F, 0.1875F, 0.5F, 0.5625F, 16, 16); // line overlay
@byteandahalf
byteandahalf / NewItem.cpp
Created December 31, 2014 05:49
Adding a new item in C++ MCPE
static Item* newItem() {
Item* myItem = (Item*) ::operator new((std::size_t) 76); // allocate memory
Item::Item(myItem, 55); // call the MCPE Item constructor
Item::items[55] = myItem; // Add the item to MCPE's global item list
*((void***) myItem) = *((void***) Item::items[259]); // give it a normal item vtable, in this case we steal it from flint and steel
Item::setDescriptionId("myitem"); // give it a name
I18n::_strings["item.myitem.name"] = "My YOLO itemmm"; // register the name
myItem->maxStackSize = 30; // max stack of 30 lololol
return myItem;
}
@byteandahalf
byteandahalf / virtualutils.h
Created January 6, 2015 03:30
Dynamically hook vtable functions
#pragma once
#include <dlfcn.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
uintptr_t DynamicHookVirtual(void** vtable, char* mangled, int end, void* myfunc) {
int index = -1;
@byteandahalf
byteandahalf / New Item iOS.cpp
Last active August 29, 2015 14:14
Adds a new item to MCPE iOS :D
#include <iostream>
#include <substrate.h>
#include <mach-o/dyld.h>
#include <string>
#include <stdbool.h>
#include <stddef.h>
#include <sstream>
#include <iomanip>
#include <vector>
#include <cstring>
@byteandahalf
byteandahalf / demangle.txt
Last active March 23, 2020 17:11
How to demangle C++
Let's say we have this mangled symbol: _ZN5Class8functionEiifb10OtherClass
To demangle this, we start by removing the _Z (I'm not sure what this means)
N means that the following is the class name (There is no N is classless functions)
Next is the length of the class name (in this case 5), followed by the class name (Class)
Class::
Now we have the length of the function name (8 here) and then the function name (function)
Class::function
@byteandahalf
byteandahalf / Entity.h
Last active August 29, 2015 14:15
Full entity struct :D
class Entity {
void** vtable; // 0
SynchedEntityData data; // 4; 28 bytes
float x; // 32
float y; // 36
float z; // 40
ChunkPos chunkPos; // 44; 8 bytes
int entityId; // 52
float viewScale; // 56
TileSource* region; // 60
@byteandahalf
byteandahalf / RenderBrewingStand.cpp
Created May 1, 2015 11:40
Rendering code for a brewing stand in MCPE
bool TileTessellator::tessellateBrewingStandTileInWorld(BrewingStandTile* tile, int x, int y, int z, TileSource* region) {
Tessellator* tess = this->tessellator_inst;
// render the center blaze rod
setRenderBounds(AABB({0.4375, 0.0, 0.4375}, {0.5625, 0.875, 0.5625}));
tessellateBlockInWorld(tile, {x, y, z});
// render the 3 blocks on the bottom
forcedUV = tile->getTextureUVCoordinateSet("brewing_stand_base", 0);
useForcedUV = true;
#include <idc.idc>
static symbol(addr, sym) {
MakeFunction(addr, BADADDR);
if(MakeNameEx(addr, sym, SN_NOWARN)) return;
auto i;
for(i = 0; i < 999; i++) if(MakeNameEx(addr, form("%s_%d", sym, i), SN_NOWARN)) return;
}
static main() {
#include <idc.idc>
static symbol(addr, sym) {
MakeFunction(addr, BADADDR);
if(MakeNameEx(addr, sym, SN_NOWARN)) return;
auto i;
for(i = 0; i < 999; i++) if(MakeNameEx(addr, form("%s_%d", sym, i), SN_NOWARN)) return;
}
static main() {