Jump to content
Official BF Editor Forums
Sign in to follow this  
amideadyet

Loading an unrestricted python interpreter

Recommended Posts

It's been a while since I posted here... figured I'd share some of the things I've been working on since I started messing with 2142 again.

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. 

https://gist.github.com/AndrewMarumoto/36f710b8e35dd99580ccf35a42eef713

^ instructions for doing so

 

Share this post


Link to post
Share on other sites
Quote

I'll be posting again soon about using it to dynamically add python callbacks for game events that are currently inaccessible to python.

I want to know more! What else can you access? I've always wanted to be able to alter the momentum of objects in the server, but was limited to position/rotation.

Share this post


Link to post
Share on other sites

You can access literally anything the gameserver does, the only thing stopping you is the need to reverse engineer the relevant parts of the server executable and then (if you're hooking stuff) write the code to bootstrap python integration in assembly.  So far, I've got a simple proof of concept working hooking comm rose events and having them call out to python code.  Also have a thing that lets you change the server fps limit on the fly, but that's fairly simple in comparison.

This stuff is all possible through static patching, but it's so much cleaner to do it at runtime using ctypes.

Share this post


Link to post
Share on other sites

That's the most exciting thing I've heard. I have so many ideas, looking forward to any kind of write up you can make on it.

 

p.s. Long time no see!!

Edited by Freeze

Share this post


Link to post
Share on other sites
1 hour ago, Notwithstanding said:

Could this interpreter also be used for BF2 btw?

Yeah, not much different besides the name of the server directory in that regard.  I haven't tested it personally for bf2, but it's been done before.

Share this post


Link to post
Share on other sites

If anyone succeeds in building from source on Windows I'd appreciate the process you used. Going to get one of my Pis out for this I guess.

Share this post


Link to post
Share on other sites

This is all new territory for me but wouldn't I need to build it to hook into events? Or can I skip that entirely using ctypes at runtime?

Edited by Freeze

Share this post


Link to post
Share on other sites

All things game related are in the server executable, the python library is just python (normal python, nothing game related, and nothing stripped out).  I'm a bit busy with finals this week, but I'll see if I can get the writeup on hooking new events finished when I get a chance.

EDIT: Ah, btw, you're not gonna be able to run it on a Pi.  There aren't any ARM builds afaik.

Edited by amideadyet

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  

×