Skip to content

Instantly share code, notes, and snippets.

@Suor
Suor / rosetta_ru.nut
Created October 16, 2024 15:33
Battle Brothers mod translation example
local rosetta = {
mod = "mod_necro"
// source_lang = "en"
lang = "ru"
version = "0.3.0"
// minVersion = "0.2.1"
}
local function green(text) {
return ::Const.UI.getColorized(text + "", ::Const.UI.Color.PositiveValue)
@Suor
Suor / cantok_wrap.py
Last active January 19, 2024 16:19
A way to enforce cantok on any coroutine
import asyncio
class AbstractToken:
async def wait(self, is_async=True): # A placeholder for the real thing
await asyncio.sleep(0.2)
return
async def wrap(self, task):
future = asyncio.ensure_future(task)
@Suor
Suor / console.nut
Created September 27, 2023 05:17
Dev Console Cheatsheat
// Cycle bros
local bros = World.getPlayerRoster().getAll();
foreach (bro in bros) {
logInfo(bro.getName());
// ...
}
// Add skill to a bro
local bro = ::getBro("Hubert")
local trait = this.new("scripts/skills/traits/master_trait");
@Suor
Suor / mod_hackfix.nut
Created September 14, 2023 09:50
Cook and Blacksmith fix
// Cook and Blacksmith fix
::mods_queue(hx.ID, null, function () {
logInfo("load hitpoints debug and fix");
local inAssetManagerUpdate = false;
local gen = ::rng_new();
::mods_hookNewObjectOnce("states/world/asset_manager", function (o) {
this.logInfo("hx: hook asset_manager");
local update = o.update;
Script Error
the index 'getID' does not exist
Function:
onUse -> scripts/skills/actives/cascade_skill.nut : 90
Variables:
ret = True, target = Table, _targetTile = Instance, _user = Instance, this = Table
Function:
-> msu/hooks/skills/skill.nut : 334
Variables:
use = Function, targetEntity = Table, container = Instance, _forFree = True, _targetTile = Instance, this = Table
@Suor
Suor / fix-ranged-ai.nut
Created August 30, 2023 10:34
Fix ranged AI evaluation on a dead target in Battle Brothers
::mods_hookExactClass("ai/tactical/behaviors/ai_engage_ranged", function (o) {
local function isRelevant(_actor) {
return !_actor.isNull() && !_actor.m.IsDying && _actor.m.IsAlive;
}
local function cleanup(_b) {
_b.m.ValidTargets = _b.m.ValidTargets.filter(@(_, t) isRelevant(t.Actor));
_b.m.PotentialDanger = _b.m.PotentialDanger.filter(@(_, a) isRelevant(a));
}
@Suor
Suor / 1-plus-n.md
Created March 22, 2023 11:11
Trying to make ChatGPT to write a blog post

> Write a blog post about this code trick:

import logging
import os

from funcy import monkey

from django.db.models.query_utils import DeferredAttribute
@Suor
Suor / sizes.py
Last active October 30, 2021 16:31
Different way to calculate struct size
import gc
import sys
import types
from collection import deque
import random
def getsize(obj):
BLACKLIST = type, types.ModuleType, types.FunctionType
if isinstance(obj, BLACKLIST):
@Suor
Suor / mod_fix_ambitions.nut
Created January 21, 2021 18:45
Battle Brothers: debug ambitions not happening
::mods_registerMod("mod_fix_ambitions", 0.1, "Fix ambitions not fullfilling");
::mods_queue("mod_fix_ambitions", "mod_hooks(>=19)", function() {
this.logInfo("fa: loading");
::mods_hookNewObject("ambitions/ambition_manager", function(obj) {
this.logInfo("fa: hook ambition manager");
local update = obj.update;
obj.update = function() {
this.logInfo("fa: ambitions.update available=" + this.isAvailable() + " ambition=" + this.m.ActiveAmbition);
@Suor
Suor / getsize.py
Created January 15, 2021 12:35
Get python structure total memory size
def getsize(obj):
import sys
from types import ModuleType, FunctionType
from gc import get_referents
BLACKLIST = type, ModuleType, FunctionType
if isinstance(obj, BLACKLIST):
raise TypeError('getsize() does not take argument of type: '+ str(type(obj)))
seen_ids = set()
size = 0
objects = [obj]