Skip to content

Instantly share code, notes, and snippets.

@TrueBrain
TrueBrain / extension.md
Last active January 6, 2021 14:57
GameScript identities

This is meant as extension on: https://wiki.openttd.org/en/Development/Design%20Drafts/Scripts/Capability-based%20API

In addition to having capabilities, GS would benefit from being able to instantiate controllers for certain objects.

For example, take a town. Currently either a GS controls all towns or it doesn't. By adding capabilities, as written in the wiki, it can either share all towns with other GSes or keep them all for him self. I would propose a more fine-graned method: instances.

Every GS has a function like: HasInstanceFor(capability). As example: HasInstanceFor(TownGrowth). The GS either returns 0 if it has nothing for this capability, or N with N > 0 for how many different forms it has for this instance. Next, OpenTTD adds up all the Ns, picks a random number in range, and selects that GS + index to handle that town now forths. For example: GetInstanceFor(TownGrowth, 2).

@TrueBrain
TrueBrain / network-improvements.md
Last active December 23, 2020 14:04
OpenTTD Network Improvements

Phase 1 - Add crypto

  • Add crypto library to OpenTTD
  • Generate a single crypto-based unique identifier on clients
  • On joining the server, the client gives the server his crypto-based unique identifier
  • The server challenges the client to validate he is the owner of this crypto-based unique identifier
  • On creating a new company, the server adds the unique identifier to the access list of the company
  • On joining a company, before a password is asked, the server checks if you are on the access list of the company, and lets you in passwordless if you are
  • The crypto-based unique identifiers who have access to companies are stored in the savegame
  • Reloading a savegame on the same server keeps the access list intact
@TrueBrain
TrueBrain / proposal-milek7.md
Last active December 19, 2020 22:10
OpenTTD multiplayer

Decentralized local authentication

Use a public key (pubkey) / secret key (secret) to authenticate yourself with the server. At login, you authenticate yourself to the server. If you protect your company, this is done based on your pubkey. This means that only you with the correct secret can still join that company.

A server stores this pubkey in the savegame, to make company protections survive restarts.

Server sharing pubkeys

@TrueBrain
TrueBrain / change_x_to_u.py
Last active December 14, 2020 18:49
Replace \x escape in C-strings to \u escape
import re
import sys
def replace_utf8(match):
char = match.group(0)
char = chr(int(char[2:4], 16)) + chr(int(char[6:8], 16))
char = char.encode("raw_unicode_escape").decode()
char = char.encode("unicode_escape").decode()
char = char.replace("\\x", "\\u00")
@TrueBrain
TrueBrain / Dockerfile
Created December 8, 2020 20:16
Emscripten + LZMA
FROM emscripten/emsdk
COPY emsdk-liblzma.patch /
RUN cd /emsdk/upstream/emscripten && patch -p1 < /emsdk-liblzma.patch
@TrueBrain
TrueBrain / nullptr_addition.patch
Last active December 4, 2020 21:10
News crash fix
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index a3f73d729..055979951 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -255,7 +255,7 @@ NewsDisplay NewsTypeData::GetDisplay() const
uint index;
const SettingDesc *sd = GetSettingFromName(this->name, &index);
assert(sd != nullptr);
- void *ptr = GetVariableAddress(nullptr, &sd->save);
+ void *ptr = GetVariableAddress(&_settings_game, &sd->save);
@TrueBrain
TrueBrain / features.md
Last active November 26, 2020 20:26
IRC Bot

Supported features

GitHub

  • GitHub event -> announcements (via .dorpsgek.yml)

User

  • User registration via Pull Request
  • Hostname to "auto" identify (especially in combination with NickServ and *.user.oftc.net a simple way for anyone to identify)
  • Channel permissions via Pull Request
@TrueBrain
TrueBrain / index.js
Last active September 18, 2020 21:18
grfsearch.openttd.org
'use strict';
const querystring = require('querystring');
exports.handler = (event, context, callback) => {
var request = event.Records[0].cf.request;
const params = querystring.parse(request.querystring);
var redirect_uri = '/index.php';
def func_00821b():
if False: yield
lda8((Pointer((cpu.dh << 8), 0xff, 0x13)) if (cpu.flag_e and cpu.dl == 0) else (Pointer(0, 0xffff, cpu.d + 0x13)))
sta8(Pointer(0, 0xffffff, (cpu.dbr << 16) + ((0x2100) & 0xffff)))
lda8((Pointer((cpu.dh << 8), 0xff, 0x9b)) if (cpu.flag_e and cpu.dl == 0) else (Pointer(0, 0xffff, cpu.d + 0x9b)))
sta8(Pointer(0, 0xffffff, (cpu.dbr << 16) + ((0x420c) & 0xffff)))
rep(0b00110000)
plb8()
pld16()
ply16()
@TrueBrain
TrueBrain / legal-entity.md
Last active September 10, 2024 05:35
Signing binaries and getting on Steam