Welcome to Open Carnage

A resource for Halo Custom Edition and MCC modding, with unique means of rewarding content creation and support. Have a wander to see why we're worth the time!

EST. 14th of February, 2012

Sign in to follow this  
Followers 0
WaeV

Introduction to Memory Editing with Python and Halolib

Hi Everyone!

Halolib is free software I wrote for reading and editing Halo maps. You can edit files on disk, and even live-edit the map Halo PC is running from memory! It is written in Python 3, and distributed as source code. This guide will show you how to operate Halolib the way I do, using Visual Studio.

Visual Studio is a hefty download of several gigabytes. You can use whichever text editor or IDE you prefer, but I found Visual Studio to suck the least, after a thorough comparison here.
 
My setup includes the following programs, installed on Windows 64-bit: git, Anaconda Python 3.5, and Visual Studio Community 2015. You can reproduce my setup by following these instructions.
 
1. Downloading from GitHub
 

 


The project is hosted at https://github.com/ChadSki/halolib and the git download url is https://github.com/ChadSki/halolib.git.

Open PowerShell and type


git clone https://github.com/ChadSki/halolib.git

 
Then change directory into the newly created folder


cd halolib

 
cTLpu97.png
 
You should be on the master branch and fully up to date.

If your git repo gets confused, just delete it and download a new one.

git.png


 
2. Opening the Project, Running Tests
 

 


Open `halolib.sln` with Visual Studio.

V7tjzDA.png

We should run tests to make sure that everything is working propertly.

DnAC8Vz.png

Green checkmarks means we're good to go!



3. Loading a Map, Printing Tag Names
 

 


Now that we know everything is set up and working, launch an interactive Python window. In the menus, that's View > Other Windows > Python Interactive. The bitness doesn't really matter, but I always use 64-bit.

kpHkBxv.png

Begin by importing halolib. Then load a map from Halo's memory like so.


import halolib
map = halolib.HaloMap.from_memory()

But make sure that Halo is actually running! As of the 1.0 release, you ought to be using Halo PC 1.10.

WBPf22N.png
fancy autocomplete

Just for fun, let's print the name of every tag in the map.


for tag in map.tags():
    print(tag)

8bBhKjl.png

That was a lot of tags! We can add quoted strings to filter it down. Let's look for weapon tags with "pistol" in their name.

 


for tag in map.tags('weap', 'pistol'):
    print(tag)

jmiiBx6.png

Two results! Let's use a teensy bit of regular expressions to make sure we only match the human pistol.

 


for tag in map.tags('weap', '[^ ]pistol'):
    print(tag)

The "[^ ]" means "match any character except for space".

hpbL4Gm.png

Cool, now we're only matching the human pistol.\

 

4. Using Variables, Editing Tags

 

 

Let's assign the pistol to a variable.


pistol = map.tag('weap', '[^ ]pistol')

Two things of note: first, when I only want one tag, I say map.tag instead of map.tags.

Second, if you just type a variable name and hit enter, the console will show you a representation of that object, as pictured below.

k0GBTAL.png

Weapons have several nested structs, so they can look a little complicated. Let's walk through it:

  1. "triggers" is a struct array. It holds a variable number of trigger structs.
  2. The pistol only has one trigger. So we'll access it using [0]. (Programmers start counting from 0.)
  3. Inside the trigger struct, there is "projectile", a tag reference.

Let's put that all together and make the pistol shoot rockets!


pistol.triggers[0].projectile = map.tag('proj', 'rocket')

WDozRcX.png

u9UsjBq.png

 

Well done! Let's do something similar with the banshee.

 

First, find the multiplayer banshee weapon.


banshee_gun = map.tag('weap', 'mp', 'banshee')

 

If you provide multiple quoted strings, only tags which contain each name fragment will be returned. In this case, adding "mp" is enough to make sure we get the multiplayer banshee's tag.

 

RDcZtpM.png

 

Now, let's make it shoot warthogs!

 

IUJwxUl.png

 

M6pLcvo.png

 

This tutorial is a rather rough draft, so feedback and "this didn't work" reports are appreciated. I'll be revising this tutorial, and hopefully writing others.

Nickster5000, NeX, Tucker933 and 1 other like this

Share this post


Link to post
Share on other sites

Tiddy-bits:

SWvZJTp.jpg
Tucker933, NeX, Kavawuvi and 1 other like this

 

 

4VWJfoZ.gif

"You fix my mistakes is what you do." - Tucker
"You're useless." - Tucker 2 minutes later

"You're sort of cool in some ways." - Kavawuvi

 

"Fuck off." - Mint Blitz

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0
  • Recently Browsing   0 members

    No registered users viewing this page.