Skip to content

Instantly share code, notes, and snippets.

View angavrilov's full-sized avatar

Alexander Gavrilov angavrilov

View GitHub Profile
@angavrilov
angavrilov / gist:926972
Created April 19, 2011 07:45
mmap injection on linux (emulation of VirtualAllocEx)
/* Support for executing system calls in the context of the game process. */
static const int injection_size = 4;
static const char nop_code_bytes[injection_size] = {
/* This is the byte pattern used to pad function
addresses to multiples of 16 bytes. It consists
of RET and a sequence of NOPs. The NOPs are not
supposed to be used, so they can be overwritten. */
0xC3, 0x90, 0x90, 0x90
@angavrilov
angavrilov / gist:961587
Created May 8, 2011 18:44
895d540: compute creature temperature
args: eax, edx, ecx, stack
args: creature, arg_temp, arg2#1, arg3/*10*/
/* offsets:
creature:
0x308 vector* body_part_info_vec
0x654 vector body_part_temp_vec
inventory item:
@angavrilov
angavrilov / gist:972531
Created May 14, 2011 19:21
function names
08117480 flagarrayst::has_flag{flag}
080e49d0 world::?getMapBlock{x,y,z}
089d53b0 world::?getMaterial{subidx,index}
088c9d00 ??computeClothingInsulation
088c9830 ??computeClothingInsulation2
0813a840 ??computeClothingInsulation3
08a3fe70 world::?handleFlows
080801f0 world::?handleBlockTemps
0895d540 ??computeCreatureTemp
08946b70 ??computeBodyPartTemp
@angavrilov
angavrilov / filter.pl
Created May 23, 2011 14:12
DF thought codes
my %lines;
my %switches;
my %jumps;
while (<>) {
$jumps{hex $1}{hex $2}++ if (/^n([0-9a-f]+)\s+->\s+n([0-9a-f]+)/);
if (/^n([0-9a-f]+)\s+->\s+n([0-9a-f]+)\s+\[label=\"([0-9,-]+)\"/) {
$switches{hex $1}{$3} = hex $2;
} elsif (/^n([0-9a-f]+)\s+\[label=\".*?\\l'(.*)'\\l/) {
@angavrilov
angavrilov / slime-utils-walker.lisp
Created October 29, 2011 08:23
A macroexpand-in-context hack for SLIME
(require 'asdf)
(asdf:load-system :hu.dwim.walker)
;;;; Walker interface implementation
(defpackage :swank-macro-context
(:use :cl :hu.dwim.walker :hu.dwim.def :contextl :metabang-bind)
(:export #:apply-expander))
(in-package :swank-macro-context)
@angavrilov
angavrilov / general_ref_unit.h
Created December 14, 2011 15:47
Sample structures from the code generator
#ifndef DF_GENERAL_REF_UNIT_H
#define DF_GENERAL_REF_UNIT_H
#ifndef DF_GENERAL_REF_H
#include "general_ref.h"
#endif
namespace df {
struct general_ref_unit : general_ref {
int32_t unit_id;
static virtual_identity<general_ref_unit> _identity;
protected:
void __cdecl sub_89289C0(int unit)
{
int unit; // esi@1
int unf_vec_end; // eax@3
int v3; // edx@3
int v4; // edx@4
int unf_vec_start; // ecx@4
int item_id; // edi@5
signed int v7; // edx@7
signed int v8; // eax@8
@angavrilov
angavrilov / filter.pl
Created January 6, 2012 10:33
job_item.unk1 to items.other vector mapping
my %lines;
my %switches;
my %jumps;
while (<>) {
$jumps{hex $1}{hex $2}++ if (/^n([0-9a-f]+)\s+->\s+n([0-9a-f]+)/);
if (/^n([0-9a-f]+)\s+->\s+n([0-9a-f]+)\s+\[label=\"([0-9,-]+)\"/) {
$switches{hex $1}{$3} = hex $2;
} elsif (/^n([0-9a-f]+)\s+\[label=\".*?\\nmov\s+eax,0x([0-9a-fA-F]+)\\l/) {
@angavrilov
angavrilov / cmptiles.lua
Created April 20, 2012 11:23
Lua script to list and/or compare tiletype subsets
-- Lists and/or compares two tiletype material groups.
-- Usage: lua cmptiles.lua material1 [material2]
local nmat1,nmat2=...
local mat1 = df.tiletype_material[nmat1]
local mat2 = df.tiletype_material[nmat2]
local tmat1 = {}
local tmat2 = {}
@angavrilov
angavrilov / check_block_items.lua
Created May 7, 2012 17:01
A script to verify integrity of block item lists and occupancy.
-- This scripts verifies that:
--
-- 1) Item has flags.on_ground <=> it is in the correct block item list
-- 2) A tile has items in block item list <=> it has occupancy.item
function check_block_items()
local cnt = 0
local icnt = 0
local found = {}