Skip to content

Instantly share code, notes, and snippets.

@AndrewMarumoto
AndrewMarumoto / bf2142_python_hooks.md
Last active February 20, 2023 18:44
Adding new python hooks to Battlefield 2142

Overview

This is a proof of concept for hooking events that are normally inaccessible from python. It assumes you've set up an unrestricted python interpreter for 2142 and installed ctypes. The hooking is done dynamically through python, rather than by statically modifying the executable.

Caveats

  • The code here is for 64 bit systems, it will not work as is on 32 bit
  • The offsets may be different depending on which 2142 patch you're working with
  • If you want to add new events, you'll need to reverse engineer the relevant parts of the server to find the offsets
  • You'll also need to be able to write assembly

Example: hooking comm rose events

@AndrewMarumoto
AndrewMarumoto / bf2142_python_upgrade.md
Last active December 15, 2016 04:25
Instructions for loading an unrestricted python into Battlefield 2142

Background

The python interpreter included with vanilla Battlefield 2142 is lacking a fairly large amount of functionality. Much of this involves restrictions on OS interaction, as well as the removal of threading support and the ability to load C extensions. Due to this, a large chunk of the standard library is broken as it depends on functionality that was removed. The goal here is to replace 2142's python interpreter with an unrestricted one and to include the full standard library.

Caveats

  • The instructions provided here are for the 64 bit linux server, but the process should work with minor adjustments on 32 bit linux and on windows.
  • In Battlefield 2142's custom python interpreter, if an exception is uncaught it will not crash the entire server (like it would in bf2 iirc). Without additional modifications, this process will cause uncaught python exceptions to crash the entire server.
  • There is an old blog post about doing this for bf2, but it's very brief and does it in a way that's not e