Skip to content

Instantly share code, notes, and snippets.

@ChadSki
ChadSki / gist:6737485
Last active December 24, 2015 03:29
Class definitions?
class obje(HaloStruct):
model = reference(offset=0x28)
animation = reference(offset=0x38)
collision = reference(offset=0x70)
physics = reference(offset=0x80)
class weap(obje):
magazines = reflexive(offset=0x4F0, size=112,
rounds_recharged = uint16(offset=0x4),
rounds_total_initial = uint16(offset=0x6),
@ChadSki
ChadSki / gist:6738055
Last active December 24, 2015 03:29
Docstrings with ascii diagrams
def loneid(*, offset):
"""
____ident____
| |
| E1 75 01 45 |
|_____________|
"""
def fget(self):
buf = self.access.read_bytes(offset, 4)
ident = read_uint32(<int><char*>buf)
@ChadSki
ChadSki / gist:6797377
Last active December 24, 2015 12:19
PyNotifyPropertyChanged proposal
# Defining a class with a property
class Foo(object):
def __init__(self):
self._bar = 0
@property
def bar(self):
return self._bar
@bar.setter
@ChadSki
ChadSki / gist:6911978
Created October 10, 2013 02:16
list comprehension gone too far?
index_entries = [IndexEntry(
FileAccess(
IndexEntry.struct_size * i + index_location,
IndexEntry.struct_size),
map_magic,
halomap) for i in range(index_header.tag_count)]
@ChadSki
ChadSki / gist:6912939
Created October 10, 2013 04:12
load_map_common proposal
def load_map_common(access_type, map_path=None):
# access_type is either 'file' or 'mem'
halomap = {
'file': lambda: HaloMap(open(map_path, 'r+b')),
'mem': lambda: HaloMap(None)
}[access_type]()
# class for reading/writing bytes to a delineated area
ByteAccess = {
@ChadSki
ChadSki / gist:7012482
Created October 16, 2013 18:28
List Comprehensions
index_entries = []
for i in range(index_header.tag_count):
ie = IndexEntry(
FileAccess(
IndexEntry.struct_size * i + index_location,
IndexEntry.struct_size),
map_magic,
halomap)
index_entries.append(ie)
@ChadSki
ChadSki / gist:7251222
Created October 31, 2013 15:02
Open Sauce SLOC
D:\Users\Chad\Downloads> .\cloc-1.60.exe .\open-sauce-0260d0c62a2d
1980 text files.
1886 unique files.
836 files ignored.
http://cloc.sourceforge.net v 1.60 T=4.14 s (373.4 files/s, 91464.7 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C# 593 19588 33592 117596
@ChadSki
ChadSki / gist:7992383
Last active March 29, 2025 00:21
Dynamically define C# value types (structs) at runtime with a dynamic assembly
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Text;
namespace DevConsole
{
#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
{