Skip to content

Instantly share code, notes, and snippets.

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#define MEMORY_FIX_OFFSET 0x40440000
// Ensure correct alignment
#pragma pack(push, 1)
@ChadSki
ChadSki / FieldControlSelector.cs
Last active August 29, 2015 14:01
Databinding to Dynamic Objects?
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Quickbeam.Low;
namespace MetroIde.Controls.MetaEditor
{
public class FieldControlSelector : DataTemplateSelector
{
if location == 'file':
ByteAccess = FileByteAccessBuilder(map_path).CreateByteAccess
else: # location == 'mem'
ByteAccess = WinMemoryByteAccessBuilder('halo').CreateByteAccess
load_plugins()
MapHeader = plugin_classes['map_header']
map_header = MapHeader(
ByteAccess(
0x6A8154,
@ChadSki
ChadSki / gist:550668f632c215168e36
Last active August 29, 2015 14:01
Nested Dictionary Comprehensions
def class_from_xml(struct_layout):
"""Define a new class based on the given struct layout defined in xml.
"""
# { field_name => ObservableField_constructor_params }
field_params = {
field.attrib['name']: {
'field_type': field.tag,
'offset': int(field.attrib.get('offset'), 0),
'length': int(field.attrib.get('length', '0'), 0),
'reverse': field.attrib.get('reverse', 'false') == 'true',
if location == 'file':
# Usually the tag index directly follows the index header. However,
# some forms of map protection move the tag index to other locations.
index_offset = map_header.index_offset + index_header.primary_magic - 0x40440000
# On disk, we need to use a magic value to convert pointers into file offsets.
# The magic value is based on the index location within the file, since this
# always appears at the same place in memory.
map_magic = index_header.primary_magic - index_offset
# ensure plugins are loaded
if len(plugin_classes) == 0:
load_plugins()
def load_map(map_path=None):
"""Loads a map from Halo.exe's memory, or from disk if given a filepath. Loading a
map requires that plugins have already been loaded.
"""
# end result, constructed now (because we need the reference) but init'd at the end
halomap = HaloMap()
@ChadSki
ChadSki / test.py
Last active August 29, 2015 14:02
XML Plugins vs Python DSL
plugin_classes['test'] = struct(size=0x450, fields={
"collision": reference(0x70),
"velocity": float32(0x3B4),
"weapons": struct_array(0x2D8, struct(size=36, fields={
"weapon": reference(0x0),})),
"hypothetical": struct_array(0x164, struct(size=0x8, fields={
"doubly_nested": struct_array(0x20, struct(size=0x30, fields={
"foobar": reference(0x0),
"quxbaz": uint32(0x0A),
"function": enum16(0x10, options={
@ChadSki
ChadSki / better_names.xml
Last active August 29, 2015 14:02
Alternative Plugin Syntax?
<!-- Invalid plugin, for syntax demonstration only -->
<plugin name="weap" struct_size="0x504">
<float32 name="initial_rounds_per_second" offset="0x4" />
<float32 name="final_rounds_per_second" offset="0x8" />
<float32 name="rounds_per_second_acceleration" offset="0xA" />
<float32 name="rounds_per_second_deceleration" offset="0xC" />
<uint16 name="projectiles_per_shot" offset="0x6E" />
<struct_array name="magazines" offset="0xF0" struct_size='112'>
<uint16 name="rounds_recharged" offset="0x4" />
<uint16 name="rounds_total_initial" offset="0x6" />
@ChadSki
ChadSki / gist:f065c6aaadc31723924c
Last active August 29, 2015 14:02
Halo Tag Size in C
// start with the largest possible size
uint32_t tagSize = (0x40440000 + header->metaSize) - tag.data;
for(uint32_t q=0;q<tagCount;q++) {
// skip if the offset starts before the tag in question
if(tags[q].data <= tag.data) continue;
// skip when the offsets are the same
if(tag.data == tags[q].data) continue;
@ChadSki
ChadSki / thebook.md
Last active August 29, 2015 14:06
Alan Watts excerpt

If the human organism is fascinating, the environment which accompanies it is equally so – and not merely as a collection of particular things and events. Chemistry, biology, geology, and astronomy, are special fascinations with the details of our environment, but metaphysics is fascination with the whole story.

I find it almost impossible to imagine a sensitive human being bereft of metaphysical wonder, a person who does not have that marvelous urge to ask a question that cannot quite be formulated. But the question almost always implies a search for something basic to everything, for an underlying unity which our ordinary thinking and feeling do not grasp. Thought and sensation are analytical and selective, and thus present the world as no more than a multiplicity of things and events. Man has, however, a "metaphysical instinct" which apparent multiplicity does not satisfy.

Man is intuitively certain that the entire multitude of things and events is "on" or "in". Something as reflections are on a mirror,