#🪅-progaming
1 messages · Page 23 of 1
i learnt through trial and error lmao
one time i wrote parser and it was regex based haha
the whole parser is somewhere in the 3500 range i think
thats cool
i once wanted to implement inline xml into java(like jsx) xD, would prolly need a parser for that too
that actually sounds kinda fun
the only problem with that is you need to actually determine where the xml is located
interrupting the build process and modifying the input files is no problem with gradle plugins
i wonder how jsx does that
because you can have xml anywhere
as an expression
Jsx doesn't edit the input files to substitute with non-jsx, it edits the parser to support jsx
Just add another form to the expr parser and you're all set
wait but i thought rollup edits the input files into React.createElement
No, React.createElement goes in the output files
couldve edited the antl4 parser rules to support it, but ive got no idea how to do so, and editing the compiler itself is too much work
Yes, to support new syntactic forms you add them to the grammar
I thought that was kinda obvious
it is, but as i said, im too lazy to understand how antl4 works
well maybe sometime in future when im not too lazy
imagine having a frontend java framework
i mean jsp
or vaadin
squished pip
tree-sitter is written in js which is nice
Tree-sitter grammar for Lit, a language that is designed to compile to Lua but be better - PoolloverNathan/tree-sitter-lit
the ohfuck_expr
lol
ohfuck_expr: $ => prec("throw", seq("ohfuck", field("message", $.string))), peak code
basically an abort
someone asked for more serious panics
there's three severities:
erroris likebail!()panicis likepanic!()ohfuckiseprintln!()(with a stack) thenabort()
also any syntax errors are considered comments
ohfuck should be worse than panic
THEY FLIPPED THE WHOLE PLOT IN 8 MINUTES
HOLY SHIT
what bro
not its not
its c
the core is c
idk if they've completely moved to rust

the rust code is bindings
B I N D I N G S
rust so bloated the bindings are bigger than the c project
insane indeed
Any updates for running rust on iPadOS?
you can be whatever you want
can I be you
no
Do you want to be him
buy frog fursuit and you will be wing
it is
the program immediately exits
panics are catchable
arc is so bad on windows 😭
Anyone know how to fix the role duper in third party, it’s giving me a few errors after running pnpm build
🤯
i dont remember if i posted before but i saw inlay hint "either type" and got confused
what the heck is this language
looks like someone ate rust cereal and go milk and puked it all out
oh wait
its gotta be zig
people always talk about how cursed the syntax is
i like the syntax
why use anything other than javascript
Why use anything
why even exist
good question, sometimes I go on an existential crisis but then remember, life is all about bloons td 6
consider https://c3-lang.org
C3 is a programming language that builds on the syntax and semantics of the C language, with the goal of evolving it while still retaining familiarity for C programmers.
syntax is actually very shrimple
nothing unexpected
learn raku
you will never complain about other languages' syntax ever again
id use zig over rust
C?
never touching c
or c++ for that matter
those are horrid codebases
but ngl all the cool arcane software ive seen is in c(++)
C is nice
I like C for it's simplicity
https://hp.vector.co.jp/authors/VA013651/freeSoftware/mkbold-mkitalic.html the algorithm is so simple i fucking love it
The tool to make X BDF font bold and italic.
C is simple, the code you write is not
(it applies to everyone)
just dont use heap allocation and youre good to go /s
template<typename T, typename F, typename R>
R scopedAlloc(F callback) {
T t;
return callback(t);
}```
i was talking about C, not C++
C++ is very questionable language
int scopedAlloc(int(*callback)(*int[], int), int size, int arg) {
int mem[size];
return callback(&mem, arg);
}```
is there a more aesthetically-pleasing way to write this?
let try printer = printer;
that's a thing?
can't add a non-ambiguous From<> impl here
Yeah that's just ? operator
Optionally with .map_err() inbetween
let printer = printer.map_err(Error::NoReadline)?;
nice
what the heck is bail
Probably anyhow's
macro named after anyhow::bail, as it serves a similar purpose
return Err($e.into())
what’s the point
essentially throw
yeah but why
slightly less typing
The correct implementation is Err::<!, _>(e)?
horror
fixing
Which works correctly with (nightly) try blocks
But due to using !, requires nightly itself
my rust flake uses nightly by default, conveniently
actually not just by default I haven't implemented changing the toolchain at all
does rust have contracts
compile/runtime constraints set by a function for its parameters
oh, compile-time asserts? yes
on parameters of all calls? not to my knowledge
It does not allow type checking beyond what the type system allows, no
can't outtypecheck the typechecker
some syntax ive been dreaming up is like
fn foo(a: 3000 > i32, b: string.starts_with(“awa”), c: -1 < f32 <= 1) for contracts
that would be soooo cool
that'd be neat
language I'm working on lets you have if types, but currently only the parser supports them
like
(e.g. int if self > 2)
the check will be done at runtime as of now
fn foo(a: if _ < 1 { i32 } else { f32 })
that's a different feature
I'd prefer ```rs
fn foo(a: i32, b: &str, c: f32)
assert
3000 > a,
b.starts_with("awa"),
-1 < c,
c <= 1
i know but imagine if that was a thing
types are values, but a type cant refer to what it will eventually be
how would that be possible
Dependent types is a thing
oh those
A very complicated thing that's never made it out of academia
treat it as an arbitrary f64 to test the constraint and then convert it to the correct type afterwards
me when i need a compile time random number so i transmute an empty struct to get its type id
you can't have ∀(a : {! something referring to a !}) -> …, can you?
you make me want to add this as a cursed feature to my language
i need to study type theory
for all a there exists some a such that whatever the heck the rest of it is
{! … !} is a hole
oh
∀(a :: b) -> dependently qualifies a as a b
recursive dependent types
horror
fibonacci sequence at the type level
that should be possible using normal ghc type families
and peano numbers
i’ve done it before
what isn't
having to use jquery in my web dev class @royal nymph you love
typescript has dependent types
someone made a whole fucking typescript type checker in the type system
lmfao
type-level typescript compiler when
@valid jetty hii
now if we could only splice them in somehow
\(\(…)) is cursed syntax (from my language)
found it https://github.com/ronami/HypeScript
where do you keep all of this i can’t find any of it on github
nathan@nathanlaptopv:stuff/tree-sitter-lit but I can't push until next tuesday
what am i looking at
does that splice raw llvm in?
it’s not llvm but essentially yes
it puts that text without any transformations directly into the IR file
i kinda have that
__MANUAL_RETURN__ tells the compiler not to include an automatic return at the end
\() splices strings into strings, and other types of things into program source
no real IR yet
both lua and llvm as targets
mainly lua
but llvm for testing scripts and standalone use
maybe consider wasm too
doesn't llvm do wasm?
Did I mention that the code I'm currently working on has 85 levels of indentation at one point?
I'm writing a decompiler, and it currently doesn't properly unnest elseifs
might just let you define a function that takes a typed ast and returns the program output
if num == 0
do0()
else
if num == 1
do1()
else
…
…84 chained else ifs?
I didn't write this shit y'know
an else-if is technically an if statement inside of the else block
ok can y’all help me clear up something
structs are contiguous memory right
so
a struct with 4 chars
usually
is 32 bits
what lang's chars
If char is 8 bits, yes
C
rust chars are u32
ah, then probably
nono C chars
c doesn't align chars right?
raylib allows you to directly pass a 32 bit integer to a function instead of a struct worth of 32 bits
how does that work
a struct is a pointer to the start of the memory
an integer is just an integer
A struct is just the memory
structs usually are the data itself
Unless your language boxes it behind the scenes
you can’t store a struct by value
Why not
because you’re not allowed to i guess idk lol
ik in C it's common to stuff 32 bytes of state into int parameters
in llvm you allocate memory and put things at the offset you need
that’s still a pointer tho
raylib however allows you to pass both a Color struct and an integer into the ClearBackground function
probably just overlapping representations
A {u8, u8, u8, u8} and a u32 have the same memory representation
in elle a struct is a pointer, and the function still works fine for both a Color struct (pointer to the start of that stack memory) and directly an integer
Is this left like this when making a plugin?
yes but in theory i should be passing the address to that integer
to make the same behavior
but i’m just passing an integer directly and it works
no it’s kinda hard to explain what i mean
when any struct is created it’s usually just syntactic sugar
struct Foo { u8, u8, u8, u8 }
Foo { 255, 0, 0, 255 }
would do
%Foo = alloca 4 # in bytes
store 255 %Foo
store 0 %Foo + 1
store 0 %Foo + 2
store 255 %Foo + 3
you don’t really have a struct by value you have a reference to the start of that stack allocated memory
so how in the heck, when passing an integer directly into the ClearBackground struct, does it recognize it as the whole struct, it makes no sense to me
to access any fields it needs to calculate an offset, but an offset to what it was given just a number
how do you load 0xFF0000FF + 1 and get 0 (ideally it would be load %Foo + 1)
i believe that when optimizing C it does get turned into an integer directly instead of making the struct but my question is how structs by value then work
i hope that makes sense
this has always been a big cloud to me
what do the calls look like in ir?
it generates this
target triple = "arm64-apple-macosx13.0.0"
%struct.Color = type { i8, i8, i8, i8 }
@__const.main.color = private unnamed_addr constant %struct.Color { i8 -1, i8 0, i8 0, i8 -1 }, align 1
; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @main() #0 {
%1 = alloca %struct.Color, align 1
%2 = bitcast %struct.Color* %1 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %2, i8* align 1 getelementptr inbounds (%struct.Color, %struct.Color* @__const.main.color, i32 0, i32 0), i64 4, i1 false)
ret i32 0
}
; Function Attrs: argmemonly nofree nounwind willreturn
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #1
doing ```c
#include <stdio.h>
#include <raylib.h>
int main() {
Color color = { 255, 0, 0, 255 };
}
it actually makes it static memory but wait
if you make the struct big enough it no longer creates it like that
target triple = "arm64-apple-macosx13.0.0"
%struct.Foo = type { i32, i8, i64, %struct.Bar, %struct.Bar* }
%struct.Bar = type { i32, i64 }
; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @main() #0 {
%1 = alloca %struct.Foo, align 8
%2 = bitcast %struct.Foo* %1 to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %2, i8 0, i64 40, i1 false)
%3 = bitcast i8* %2 to %struct.Foo*
%4 = getelementptr inbounds %struct.Foo, %struct.Foo* %3, i32 0, i32 0
store i32 100, i32* %4, align 8
%5 = getelementptr inbounds %struct.Foo, %struct.Foo* %3, i32 0, i32 1
store i8 12, i8* %5, align 4
%6 = getelementptr inbounds %struct.Foo, %struct.Foo* %3, i32 0, i32 2
store i64 10000, i64* %6, align 8
ret i32 0
}
; Function Attrs: argmemonly nofree nounwind willreturn writeonly
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #1
``` it creates it how i was saying
with this
typedef struct {
int awa;
unsigned long long bwa;
} Bar;
typedef struct {
int a;
char b;
long long c;
Bar bar;
Bar *pBar;
} Foo;
int main() {
Foo a = { 100, 12, 10000 };
}
ive literally written structs in my language that follow the C abi and theyre still a big black box to me
and every time i ask about it i get nowhere
and ai has not been any help it has absolutely no idea
and ive asked at school but my teachers dont know enough about compilers to understand what im doing
its so frustrating
so how in the heck, when passing an integer directly into the ClearBackground struct, does it recognize it as the whole struct, it makes no sense to me
dont you know based on size whether its passed in register or stack?
i know that but how does the C function know
well the function does too xd
c calling convention
or am i missing something?
if you both know the arguments, and you both target the same calling convention you both know when to pass arguments in what way
wait i think looking at the implementation might help maybe
nvm
its passed through a register right but the function is still calculating an offset into that struct which in this case it shouldnt be able to do because it has an integer directly through a register
unless in this case color.b !== *(color + 2) and instead color.b === (color >> 8) & 0xFF in which case how is that dictinction made
in which case how is that dictinction made
depends on your abi :p
i think this one explains it fairly well i guess? https://gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/artifacts/master/raw/x86-64-ABI/abi.pdf?job=build
but like i said, this is one of the possible abis
under uhhh 3.2.3 parameter passing
my bad for being silly earlier :p been a while since i did this stuff, had to look up a bunch
theres also the 5k pages i386 intel manual, maybe youll find something useful in there, i couldnt
this page has lots more abis https://wiki.osdev.org/System_V_ABI
afaik parameters passed through registers are an optimization (or when explicitly marked with the register keyword), usually it's on the stack?
zig has some really cool ideas man https://github.com/ziglang/zig/issues/16313
dude what the fuck did i just overhear from the cpp talk im listening to
its like background noise and hes like "they have ways of grooming the state of your program" 😭
result location semantics are a bit complicated but really cool actually
Any goog C hashtag developers here, maybe could someone give me some hints on how to make my code quality improve a bit? (please dont suggest to change language)
repo link
it is an optimization yeah but my question is rather how the function's shape doesnt change
when its passed through the register you still .r .g .b .a on the struct just fine
thats what im confused about
thats what ill read about later i guess
ive written my fair share of c# code in the past maybe i can help a little bit idk oop
blobcatcozy
dont laughg please https://github.com/KoblizekXD/NetRemapper/tree/master/NetRemapper-API
new color scheme just dropped
one big thing I notice are complex nested if / else blocks
you should avoid that
restructure your code to have less of that
great, yeah thats also one thing i kinda thought would be eye-striking
bad:
foreach (...) {
if (foo) {
//....
} else {
if (bar)....
}
}
better:
foreach (...) {
if (foo) {
// ....
continue;
}
if (bar)...
Nothing wrong with elseifs, just format them as such
Though continue is also nice, shows that there's nothing hiding below the last else
no because in the else block there's more if else
well it's somewhat subjective, but generally avoiding deep nesting is good
If its ```cs
foreach (...) {
if (foo) {
//....
} else {
if (bar)....
if (baz)....
}
}
MappingsReader.cs: Lines 35-78
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];
if (i == 0)
{
string[] splitted = line.Split("\t", StringSplitOptions.RemoveEmptyEntries);
if (splitted[0] == "netmap")
{
mappings = new(Enum.Parse<MappingsFormat>(splitted[1]));
}
else
{
throw new IOException("Invalid mappings file format.");
}
} else if (i == 1)
{
if (mappings == null) throw new Exception("Invalid mappings file format(header not initialized).");
mappings.Namespaces = [.. line.Split("\t", StringSplitOptions.RemoveEmptyEntries)];
} else
{
if (mappings == null) throw new Exception("Invalid mappings file format(header not initialized).");
string[] splitted = line.Split("\t", StringSplitOptions.RemoveEmptyEntries);
if (splitted.Length == 0) continue;
if (splitted[0] == "c")
{
if (currentTypeDefinition != null)
{
mappings.TypeDefinitions.Add(currentTypeDefinition);
}
currentTypeDefinition = new([.. mappings.Namespaces], splitted.Skip(1).ToArray());
} else if (splitted[0] == "f")
{
currentTypeDefinition?.FieldDefinitions.Add(new([.. mappings.Namespaces], splitted.Skip(1).ToArray()));
} else if (splitted[0] == "m")
{
currentTypeDefinition?.MethodDefinitions.Add(new([.. mappings.Namespaces], splitted.Skip(1).ToArray()));
}
else continue;
}
}
this is what I was talking about
if-ception
bad
string[] splitted = line.Split("\t", StringSplitOptions.RemoveEmptyEntries);
if (splitted[0] == "netmap")
{
mappings = new(Enum.Parse<MappingsFormat>(splitted[1]));
}
else
{
throw new IOException("Invalid mappings file format.");
}
good
string[] splitted = line.Split("\t", StringSplitOptions.RemoveEmptyEntries);
if (splitted[0] != "netmap") throw new IOException("Invalid mappings file format.");
mappings = new(Enum.Parse<MappingsFormat>(splitted[1]));
this should just be a switch
maybe should've setupped sonarqube in my ci >:(
imma fix those once im on windows, im on linux rn
do it on linux smh
i used c# primarily for windows only dev
NetRemapper.cs: Lines 117-143
if (instruction.Operand is MemberReference member)
{
if (Mappings.GetType(member.DeclaringType.Name, DefaultNamespace) is TypeDefinitionEntry typeDefinition)
{
WriteIfVerbose($"Remapping reference to {member.Name}'s type {member.DeclaringType.Name} -> {typeDefinition[TargetNamespace]}");
member.DeclaringType = new(member.DeclaringType.Namespace, typeDefinition.Names[TargetNamespace], member.DeclaringType.Module, member.DeclaringType.Scope);
// member.DeclaringType.Name = typeDefinition.Names[TargetNamespace];
}
}
if (instruction.Operand is MethodReference mRef)
{
if (Mappings.GetMethod(mRef.Name, DefaultNamespace, mRef.Name, TargetNamespace) is MethodDefinitionEntry e)
{
WriteIfVerbose($"Remapping method reference {mRef.Name} -> {e[TargetNamespace]}");
mRef.Name = e.Names[TargetNamespace];
processor.Replace(instruction, processor.Create(instruction.OpCode, mRef));
}
} else if (instruction.Operand is FieldReference fRef)
{
if (Mappings.GetField(fRef.Name, DefaultNamespace, fRef.Name, TargetNamespace) is FieldDefinitionEntry e)
{
WriteIfVerbose($"Remapping field reference {fRef.Name} -> {e[TargetNamespace]}");
fRef.Name = e.Names[TargetNamespace];
processor.Replace(instruction, processor.Create(instruction.OpCode, fRef));
}
}
you can use a witch for this
Witches are very good at csharp, what with those cauldrons and brooms of theirs
switch (instruction.Operand)
{
case MemberReference member:
case MethodReference method:
case FieldReference field:
}
java doesnt have this at all i think
c# has it since C# 7
thanks to pattern matching
it doesn't have the member
lol
it does
it's in jdk 17 too
which means its been out for long time
if (x instanceof MethodReference) {
((MethodReference) x).doStuff();
}
oh really?
i only did android dev where we use ancient java
Java has the switch case statement since Java 8's release
// As of Java 21
static String formatterPatternSwitch(Object obj) {
return switch (obj) {
case Integer i -> String.format("int %d", i);
case Long l -> String.format("long %d", l);
case Double d -> String.format("double %f", d);
case String s -> String.format("String %s", s);
default -> obj.toString();
};
}
we don't get the luxury of new java 
ayo
new java lowkey good
gonna hop on
yea
i mean i always look at how they implemented string interpolation and then removed it 2 versions later and laugh
the new FFI is really nice
I never really did much beyond java 8
build.gradle.kts: Line 46
sourceCompatibility = JavaVersion.VERSION_11
this is the java 11 way 😭
it doesn't even automatically infer the type
u gotta manually cast
oh wow 😭
this feels illegal
i remember writing java 8 when i was writing minecraft clients when i was on elementary school
horrible way to learn coding btw
dont do that
i miss 2020
Most of my java 8 was also minecraft shit, until I switched to kotlin

so true
you can literally do it with FG and have it completely with gradle
idk if I ever properly decompiled with mcp back in the day
it was always such a big mess to do, sometimes it gave you weird errors and shit
not even mentioning it was meant for eclipse
yop
nowadays you are expected to maintain mods for 2 modloaders on every version released in the past 2 years
so setupping the idea workspace was such a pain
i learnt (properly) coding with Discord mods
Aliucord and Vencord
In my later era of mc modding I just homebrewed my whole own tech stack
with Aliucord i learnt Java, Kotlin and a bit of C++
i was ultimate minecraft client skidder
nowadays hopping languages is pretty easy
I wish I could quickly pull up the reflection + annotation based forge registration system class
yeah once you're good at one language it's pretty straight forward to learn more
I can pick up most new languages decently well within a few days, just need to look up a bunch of stuff
i wonder what i was smoking here
java streams 😭
best java 8 feature though
java designers be like "how can i make this feature be as awful as possible"
okay go write list sql with linq lol
😭
wtf is this icon loader shit 
Love the ligatures
var scoreQuery = scores.Where(score => score > 80);
we were making a modloader
it was such a fun ngl
but then realized we didnt have working reobfuscation + diffing
so we dropped the project
NO
couldve just used FG
so cursed
I made a custom format for bytecode patches
mc/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask.doTask(Lmc/client/renderer/ChunkBufferBuilderPack;)Ljava/util/concurrent/CompletableFuture;
+ALOAD 0
+GETFIELD mc/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask.region : Lmc/client/renderer/chunk/RenderChunkRegion;
+IFNULL @L0
+ GETSTATIC kawaru/zu/Minimap.INSTANCE : Lkawaru/zu/Minimap;
+ ALOAD 0
+ GETFIELD mc/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask.region : Lmc/client/renderer/chunk/RenderChunkRegion;
+ GETFIELD mc/client/renderer/chunk/RenderChunkRegion.chunks : [[Lmc/world/level/chunk/LevelChunk;
+ INVOKEVIRTUAL kawaru/zu/Minimap.invalidate([[Lmc/world/level/chunk/LevelChunk;)V
+@L0
NEW mc/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk
I never did reobfuscation eitther
i didnt understand any shit from this, i think i was using binpatch for binary patching or smth like that
or wait
bsdiff
it was i think
now i need to write stupid nextjs undeployable applications because greedy corporate wants my money
has anyone here ever worked with supabase? i want to implement auth & some simple tables in my database, and looking for new stuff to try out
wdym streams are awesome
like fr streams are amazing
https://onlinegdb.com/1FyBWLo0I
the perf is not perfect, but it's fine
Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
yeah i think its implemented well
i like streams
im not sure how java would've iimplemented it differently
they also make parallelism quite easy if your thing is built with it in mind
as in stream parallelism
welp you can see an example in the thing i shared
i should probably add smth to time the code
but you can set smth like 0 1000000 as launch args and see how it perform
printing to console is slower than processing everything even if you add other rules than fizz and buzz
do u guys think asp.net core with blazor is good to make pages?
(already kinda experienced in c#)
also better formatting
instead of
return GetType(type, typeNs)?.FieldDefinitions.FirstOrDefault(field => field.Names[ns] == name);
return GetType(type, typeNs)
?.FieldDefinitions
.FirstOrDefault(field => field.Names[ns] == name);
long lines are harder to read
but the main issue is too much nesting I agree
Id split up some of those long functions as well
do it like rust where its max 79 characters horizontally before it splits it onto multiple lines
okay
Rust defaults to 100 though
i swear i read somewhere that rustfmt is 79 characters wide
i remember it because i was like "why not 80"
https://rust-lang.github.io/rustfmt/?version=v1.6.0&search=#max_width says default is 100
hm i see
avg systems programmer with monitor that can only display 80 characters wide
I think most programming happens on non-toy hardware
i do like either 100 or 120 chars sometimes
sometimes splitting lines makes it less readable
Raskell
Ruskell
please close the zip file
try (ZipFile zip = new ZipFile(modFile)) {
}
just use mixin
Its a 2 year old code bruh
do you never continue a project you abandoned for 2 years
No wtf
Is this even a thing in java 8
Also i think i closed the zip file inside the Utils.findin method
yes
but you create the zipfile twice
@calm ruin you
Yes me
finally i have a copy of this in my folder of funny
Suppose i would like to revisit making my mod loader again, which stuff should i choose? I should probably go with fabric(and mixins approach instead of decompiling), but which version?
Im not sure if its worth trying to do something like this on new version as they are pretty maintened
sorry if this question doesnt belong here (or if its too generic) but generally speaking how does vencord work? how does it hook into discord's components and stuff? im trying to write something similar for another react app, which also uses webpack so i assume it'd be similar
It uses some dark magic to hook into the webpack internals - I think Nucky is the expert at that part - and then regex replaces modules when loading them
that's insane and i'd love to learn more somehow
looking at the official vencord repo i can't realllyyyy find what's actually doing the dark magic lol
it might also be worth noting i have full source maps for this react app if it helps at all
has anyone here used emscripten
i got a crazy idea to make https://github.com/nillerusr/source-engine work in the browser
it's poorly documented tho
or if you want a completely different approach
it's not really that complicated
first you need to understand that the webpack runtime is just a replica of node.js' common js module system
@royal nymph hi
every source file gets its own ID (essentially filename), say 123456
then it transpiles something like
import { doThing } from "./somewhere";
export function stuff() {
doThing(42);
}
to
123456: function (module, exports, require) {
"use strict";
require.defineExports(exports, {
stuff: function() {
return stuff;
}
})
var somewhere = require(98765);
function stuff() {
(0, somewhere.doThing)(42);
}
}
then when the code gets minified, it looks something like this
where e, t, n are module, exports, require, n.d is require.defineExports (it uses functions which get turned into getters so that if the variable changes, the export also updates)
and n(12345) means require(12345)
why doesn't it just use e.g. get stuff()
and store constants constant
actually hmm can you reassign exported functions
get stuff turns into the same as object.defineProperty(a, "b", {
get() {}
})
which is what webpack does
now this is the module definition
you can access the module definition via webpackRequire.m[12345]. and you can require it via webpackRequire(12345)
upon calling webpackRequire, webpack looks up the module definition and initialises the module for you and retrieves the exports
then the exports get cached in webpackRequire.c[12345] and reused the next time you import the module, so it is only loaded once
ah, it's downcompiled
what vencord does in essence is monkeypatch webpackRequire.m
every time a new module definition gets added, we patch that
more like webpack is built internally to use that approach instead of generating code with get stuff() {}
ah, and patches are effectively a .replace() on the module definition source?
guh how does this even choose gcc
yes
i cant find any references to gcc exectuable
webpack organises modules into chunks. a chunk is one javascript file that contains 1 or more modules that register themselves with webpack when the file is executed
a chunk looks like something this:
(this.webpackChunkdiscord_app = this.webpackChunkdiscord_app || []).push([["26182"], {
12345: function(module, exports, require) {
},
98765: function(module, exports, require) {
}
}]);
this chunk contains modules 12345 and 98765 and pushes them to webpackChunkdiscord_app
this webpackChunkdiscord_app is a global array with a custom webpack push function which adds the modules and stuff
the way vencord works is that we monkey patch webpackChunkdiscord_app.push with our own function
extremely dumbed down, this patch looks something like this:
const originalPush = webpackChunkdiscord_app.push;
webpackChunkdiscord_app.push = function (unused, chunks, alsoUnused) {
for (const moduleId in chunks) {
const original = chunks[moduleId];
let source = original.toString();
patches.forEach(p => source = source.replace(p.match, p.replace));
chunks[moduleId] = eval(source);
}
return originalPush.call(unused, chunks, alsoUnused);
}
but then how do you know what chunk does what?
how do you mean that exactly?
there's e.g. Vencord.Webpack.findByProps to return a module with a certain export
like for example, vencord exposes many apis via the Vencord object (?), but how do you know what they all do?
not the ones in the vencord object themselves, but looking at all of the webpack chunks, how do you know what to patch?
by reverse engineering
oh wait i remembered i have a full source map of this site
It finds whichever module contains some specific substrings
you use tools like keyword search, react devtools, etc, to find the code you want to use or patch
look what you did nullptr
you summoned nuckys
the webpack obsessed user
that used to be me but nuckyz stole my job
Your job is closing prs
someone already has remade hl1 in the browser, search xash3d
that's hl1 I mean hl2
okok so i did my due dilligence, looked into how webpack works and got it all working and hooking into the app!! however, i've gotten to a point where i want to show a toast using their components. using the source map i've determined they do it like this:
import { ToastType } from "../consts";
import { showToast } from "../toast";
import ToastLayout from "../ToastLayout";
function SpeechRecognitionNotSupportedToast() {
return (
<ToastLayout type={ToastType.warning}>
{{
title: "Sorry!",
description: "This feature is not supported on your device."
}}
</ToastLayout>
);
}
export const showSpeechRecognitionNotSupportedToast = () =>
showToast(SpeechRecognitionNotSupportedToast, {
toastId: "speechRecognitionNotSupportedToast"
});```
i already have jsx bundling and react working properly in my userscript. my question is - how can i import that ToastType and showToast from my code? i can determine where they live in the webpack chunks but that's about it - i have no clue how to use them
If the module is known (and known to be sufficiently stable), just wreq() it
If it's not, vencord has a bunch of tricks for finding modules by searching their text
oh nono this isn't a vencord plugin
this is a seperate site which happens to use webpack which im trying to mess with, which is why im asking here
oh right i misread
Did you know you can copypaste code from open source projects
yeah my bad 😭
(Assuming a permissive license)
earlier, a webpack require function was mentioned - is this something i need to write myself?
It's kinda the function the whole webpack system is built around
i mean i know modules take a require function, but i mean do i need to write the method which "imports" the modules from the webpack chunk array
like uhh hold on
i know that n.d defines exports, but i dont know how to access those. i need d, exported as C (which is the component)
d is available as require(783415).C, if you can get your hands on require
but then how do i get require? do i just need to intercept any push and then make that function globally available
or is there some more elegant way
I'm not 100% sure what is the modern solution to that
But in ages past, it was common to push a fake module designated as an init, meaning it's loaded right away, and then you store the passed require function somewhere accessible
oh i think i know how to do that? hold on
window.webpackChunks.push([
[""],
{},
(require) => {
// ...make require available globally
},
]);```
I don't remember the exact details, but if that works, it works
i used that earlier (i think?) and i ran into an issue i cant remember so bear with me for a sec
oh nvm it does work now
actually i do have one more question
@fleet cedar is there a reliable way to wait for all webpack modules to load?
or are they loaded on the fly
Depends on the webpack setup
The easiest way is to monkeypatch some suitable module so that it calls into your code when run
Requires finding such a suitable module in the first place, though
rust enjoyers, what are some good rust crates for creating a parser for a propitiatory binary file format?
- can’t use bitter because the file has both little- and big-endian values
- nom seems too complicated
- others are uhhhh
or should i just go make all that binary reading stuff by myself
rather than using a lib
Do you need bit-level stuff or only byte-level?
uhhh byte-level ig, tho I’m unsure what bit-level would be
scroll?
i know somoene who wrote an arsc/axml parser+writer with scroll
seems pretty good
I find that gospel suits all my needs, but that's because I made it
o thanks that looks good
tho tbh it seems like it’d be easier to just create the helper methods by myself lol
let’s just hope the performance won’t suck ass
also I wish it was possible to do stuff like that in rust:
// pseudocode
struct File {
name_len: i32,
name: String[name_len],
}
struct Folder{
name_len: i32,
name: String[name_len],
files_count: i32,
files: [File, files_count],
subfolders_count: i32,
subfolders: [Folder, subfolders_count]
}```
cuz ts would make parsing much easier
but I get that’s not how structs work
tho maybe i can do something like that via rust macros
i heard u can do some cool shit with them
That wouldn't make sense in reality though, what if you change name_len
But yeah it would be totally possible to make some parsing library that does something like ```rs
struct File {
#[blah(len = .read_i32())]
name: String
}
uhhhh what if just make the struct immutable or like recreate it on every change
Rust does not have a concept of immutable structs
Something like this neither can nor should be part of the type system
But it would be totally legit to have it as part of a macro
Something like rs #[binstruct] struct Folder{ #[binstruct(meta)] name_len: i32, #[binstruct(len = name_len)] name: String, #[binstruct(meta)] files_count: i32, #[binstruct(len = files_count)] files: Vec<File>, #[binstruct(meta)] subfolders_count: i32, #[binstruct(len = subfolders_count)] subfolders: Vec<Folder> } which would produce something like ```rs
struct Folder {
name: String,
files: Vec<File>,
subfolders: Vec<Folder>
}
impl Folder {
fn read(...) -> Result<Folder> { ... }
fn write(&self, ...) -> Result<()> { ... }
Though imo it's faster and more flexible to just write the read and write functions directly, rather than messing around with extra abstractions
hm what if the macro returned a struct with pointers to the needed values of different types
What do you mean
fair but writing and reading the code would be easier ig
uhhh ima try to explain what i mean once my class is over
If the file data is a plain sequence of values, writing it as a struct with fancy macros might be nice
In my experience, that's an uncommon enough occurrence that it's not worth optimizing for
nvm after thinking about it more than one minute I realized it doesn’t make sense
- the pointer should point to the actual data meaning I’d have to keep in memory the whole file + extra 8 bytes (if my understanding of pointer64 meaning it consists of 8 bytes) for each uhh field
Oh, you mean pointers for each u8? Yeah don't do that
hm what if I made a custom file format and a parser for it that would allow typing stuff like that
okay no that won’t work either ig as i’ll have to access these fields somehow but i can’t create a struct like that in rust
guhhhh
nom
nom is great
i've used it before
you can do byte level, it has good helpers too
I tried to understand how to work with it, opened the examples and it looked so complicated icl
also I’m not sure which of those I need to use to get the bytes: BufReader or Cursor or File or something else
its really simple
you have a function with takes some input -> you call some nom helper, it you give you a result of the parsed data and the remaining input -> you modify the parsed data as you like, you return the remainiing input and your data
you can use either of those 3
they all implement io::Read
if you want peak performance you can look at how dbs handle files, they do insane optimization for speed and how files are actually read
it was so easy in python unpack("<h", file.read(4))
you mean db readers made in rust?

on rust forum I’ve only found the methods that are much more complicated
io::Read use an array of 4 bytes ([u8; 4])
u32::from_le_bytes convert the array to a u32 (as a little endian)
apparently h in unpack is a short, does python discard the extra bytes
The buffer’s size in bytes must match the size required by the format, as reflected by calcsize().
struct.unpack gives error if size mismatch
oh
like how dbs handle files in general, you can apply the same concepts in rust; but then again, thats only if you're really really concerned about perf, most of the time you can get away with normal file reads
the file Im trying to parse is like 300MB, idk if the perf matters at that point
I prefer reading the whole thing into a Vec<u8> first, or sometimes mmapping it
Interleaving parsing and io is not my cup of tea
and
you an apply the same concepts in rust
the thing is I’m not really familiar with rust (I started reading the book like two months ago but got lazy after the first two days and didn’t move further than chapter 4 😭), I wanted to learn rust by creating this parser but this looks kinda hard to me
that’d mean I have to have 300mb of u8’s in memory?
what kind of format are you parsing
mmaps let you buffer
or is chunking the right wordd
i never got past reading the docs of mmaps and then i gave up cause pointers were involved 
there actually two file formats that are linked. They store game assets for a small game
Mmap tells the os to make a file available as if it was ram
and no there aren’t any parsers for that format
i'd recommend nom tbh
it has a ton of helpers and needs little getting used to
fn from_hex(input: &str) -> Result<u8, std::num::ParseIntError> {
u8::from_str_radix(input, 16)
}
fn is_hex_digit(c: char) -> bool {
c.is_digit(16)
}
fn hex_primary(input: &str) -> IResult<&str, u8> {
map_res(take_while_m_n(2, 2, is_hex_digit), from_hex)(input)
}
fn hex_color(input: &str) -> IResult<&str, Color> {
let (input, _) = tag("#")(input)?;
let (input, (red, green, blue)) = tuple((hex_primary, hex_primary, hex_primary))(input)?;
Ok((input, Color { red, green, blue }))
}
the example in the readme shows pretty much all you need
will it be better performance-wise to use nom than use my own helpers?
no clue
i do like the idea of rolling out your own parsing helpers but i wouldnt recommend it to a beginner (rust can be horrid)
rust is so hard compared to what I’ve used so far (c#, py) 
I just handroll stuff with ```rs
let foo = f.u32()?;
let bar = f.slice(foo as usize)?;
Declared on the Reader object
The only traits involved are a pair of extension traits that add u32 as an alias for u32_le or for u32_be, for the common case that a file is primarily a single endianness
i recently saw a crate that used a dsl or i think yaml to descriibe formats ande generate parsers for it
well not recently
been a year
https://github.com/yeslogic/fathom damn they're still in fucking alpha
def pixel = {
red <- u8,
green <- u8,
blue <- u8,
};
def main = {
width <- u16le,
height <- u16le,
pixels <- repeat_len16 (width * height) pixel,
};
i like their dsl tho
can someoen make treesitter but for binary formats
what module (trait? not really familiar with these yet) are these helpers in? Cuz I’m looking in bytes module and I’m uhhhhh unsure it’s that handy
depends on the data you're parsing
say, I need a func to get an LE u32
Everything I've seen about nom seems terrible, it seems extremely unfocused
Like, what's even its audience?
The streaming stuff seems like it's for parsing network protocols
But then why are combinators for stripping whitespace
does take uh slice (or what’s it called) it? like if I do take again will it take the first four bytes or the next four bytes?
How do I read a u32 and then parse data at that position?
That is an extremely common operation in binary file formats, but rare in streaming formats
And seriously, let (input, _) = tag("#")(input)?;? That's the best you can do?
input.check(b"#")?, bruh
input.u32_le()?
yeah it can
jfc
looks scary
you can try this
or this
jeez im slowly loosing my ability to type english
from their examples it doesn’t really seem like i can do something like that there
struct File {
name_len: i32,
name: String[name_len],
}
struct Folder{
name_len: i32,
name: String[name_len],
files_count: i32,
files: [File, files_count],
subfolders_count: i32,
subfolders: [Folder, subfolders_count]
}```
does it even support arrays
If your format contains pointers, I would unironically recommend my gospel
Looking at them again, the docs are a bit cringe in places, though
it does

Yeah, that's one of the cringe parts
okay nvm fathom does not come as a library
love
It felt very clever when I wrote it, but in retrospect it doesn't exactly aid discoverability
Result<()> my beloved
Though on the other hand, without that trick there'd be {u,i}{8,16,32,64,128}_{le,be}, plus f{32,64}_{le,be} = 24 functions for primitives, and another 10 for ptr32_le and that'd clutter the docs quite a bit
Biden's Executive Order 14071, forbids Russians from working with or using GPL'd software made in the USA. And that includes the Linux Kernel.
More from The Lunduke Journal:
https://lunduke.com/
tbh his message doesn’t
make his decision any clear lol
I mean I get they don’t have any choice but to follow these regulations but
but removing people from contributors?
what this is just stupid as hell
i am a binary format
Something something nonbinary
Are you enjoying being a water bottle dispenser
This adds more context which i think is useful https://social.kernel.org/objects/860ef93c-229b-4070-8ee6-cb80d1f51337
@tusooa@kazv.moe Heh, you're trying to convince a "Russian identified person" in one of the senior positions in the Linux Foundation that the Linux Foundation is being unfair towards "Russian identified people." It's pretty hilarious.
I'm not a lawyer and I don't speak for the LF, so I won't give you any kind of "official comment." But here's my view of it.
The people removed from maintainer positions were identified as employed by companies on the US and EU sanctions list. These companies are directly involved in the Russian military complex and therefore are directly complicit in war crimes being committed daily in Ukraine. If these maintainers want to think that they are "just techies helping improve the Linux kernel," or that "they are outside of politics," then they are fucking wrong. If they work for companies that develop weaponry or logistics used by the Russian military, they are complicit in Russia's war crimes, and I hold them responsible at a very personal level -- and that's my official comment on the situation.
(i didn't watch the video so i don't know what it might talk about, but i know about the situation in general)
lol
politicians are too busy acting like kids but with real life weapons
:(
are u okay bro?
damn https://blog.jetbrains.com/blog/2024/10/24/webstorm-and-rider-are-now-free-for-non-commercial-use/
if you’re using a non-commercial license, you cannot opt out of the collection of anonymous usage statistics.
if its free, you're the product
seems fair to me
they give an insanely good IDE for the price of you just giving them statistics
coding in c# without an ide is painful
use vscode
it's probably not that hard to block by just redirecting the telemetry api to localhost
i shall interject for a moment; nvim
Nvim
nvim my beloved
Id rather zed
yop
zed looks neat
I will never go back to an ide after nvim
vscode just works
seems to just be like that for that style of language
you need an ide for jvm stuff too
do you reaaaaallllllly neeed an ide
need? no. really fucking useful? yop
for the jvm yes, autocomplete and shit is super bad without one
its useful sure but why would i spend 2 minutes opening an ide when i could spend 2 hours configuring nvim to give me peak experience :^)
try kotlin on nvim and you realize really fast why ppl use jetbrains for that
it doesn’t really take 2 minutes to open
for other languages vscode/(n)vim/nano etc works fine
see the solution is to not do kotlin
i tried doing cadence on whatever shitbrain's thing was for kotlin (it refused to work)
nano nop
it takes a few seconds to open and an hour for gradle to sync
fwiw i dont have the top of the line laptop
ides are beefy
this is why i dont like ides, i dont use most of their tools anyways
oh intellij never really used that
but other jetbrains ides they seem p fast (ig)
they all use intellij as a base
i could probably make nvim handle kotlin/java in a sane way but thats only if i ever touch j*va
Makes sense since the first party has their own line of ides
yeah well i am not gonna be doing kotlin and or java in the foreseeable future
yeah but grade taking an hour to sync as you said is only inrellij thingy right?
gradle is a jvm thing
intellij just syncs gradle on launch
gradle being slow isn't something jetbrains can do anything about
when free goland
i mean i have a jb license so not a big deal
but still
is go support not great in vscode
goland is nicer
atleast there are 3rd party ones
well how good they are i have no clue
but i'll take anything that runs
they be ass
they are not good
goland jumpscare
as opposed to the one time i opened jetbrains apps
EW DEFAULT THEME
vee will use catppuccin
wait vee have you themed anything on your system
noooo vee is a gnome user
vee likes gruvbox
vscode, terminal
gnome so good
iirc
vscode
btw @dawn ledge what's so bad about zed
this looks like a nice FOSS project that is both fast and p simple
well
(i tried pre official binary launch so take my opinion as outdated) but its veryy buggy and sucks
thats more like it
linux atleast
i used zed with vim mappings for c# without an lsp
Elle lsp
it worked fine
gotta have waifu at all times
I must say you have horrible theme
programmers can't do their job without anime girl in the corner
i did this for visual studio but with hatsune miku
Wrong
I have my anime girl centered
my only issue with zed on windows was some LSPs not working but I'm not sure if it's Zed's issue rather than Treesitter (afaik that's what it uses for like LSPs, linters and all that stuff) as I've had some issues with them not working in nvim either 
my current theme (i am very indecisive)
they want you to capitalize the p
look at my glorious theme
well then the logical conclusion is to just succumb to jetbrains
yes
false
that is why they did that
real ones use
DELETE
real
why does red theme even exist in default vscode themes
i hope pascal case dies a painful death
REMOVE THE NIX STUFF
LMAO
i hate pascal case so much
send wallpaper (WITHOUT THE NIX STZUFF)))
me when I'm trying to write code but get sent to hell for using js ecosystem
snake case > camel case > kebab case >>>>>> pascal case
I don't think that's a thing
u guys almost made me forget what i wanted to do
pascal snake case
I've heard from a guy working on our project and whose nvim is the only code editor that he couldn't make nvim that good for c# developing as rider was ¯_(ツ)_/¯
i will add Country to this
but anyway you can edit the nix out of it
nvim is as good as any ide if you’re willing to write plugins for it
replace it with ferora logo or smth
WHAT IS MANTI CHEAT TEST

if i have to write a plugin for my ide to work then its a bad ide
TELL
also I believe resharper is much much better than omnisharp (or whtevr is used there)
flashbang
its a good text editor though
did you create that account
i can't use light themes bc it fucks with my astigmatism
I mean that's kinda fair but if only there was like one single LSP as there is for like rust
i would assume omnisharp yeah
i tried to get that on zed but i couldn’t figure it out
rustcsharp-analyzer 


ghostty has panes and tabs inbuilt but i still use tmux cause ghostty uses gtk (gtks sucks ass)
wezterm 
im not so sure that’s right
why are all the terminal emulators not available on windows 
why is nothing available on windows
has the zed team put any focus into actually releasing on windows or are they still obsessed with ai
because windows is alreaady very good
yeah they said it'll release before the end of 2024
it doesnt need need stuff like terminal emulators
it’s not unix based
at least that's what their site says
windows terminal so good
2 months
everyonnehates windows if you want windows stuff use wsl
i've tried all sorts of editors sublime, atom, vscode, zed, admittedly even shitjetbrains but nvim is just great
i love being able to customize everything with (bad) lua
latter
zed devs are ai shills
this is why i dont like zed
i dont fucking need ai
i hate ai
i just want zed to run on my computer
the thing a program is supposed to do
true
they managed to write a 2d ui framework that just doesn't work sometimes
i have been programming without ai since forever and even when i was in the copilot test group it didnt do much (well it was a preview release) but still ai doesnt really contribute much to me in general and i really hate ai cause everyone around me are fucking idiots and think ai tools are like some omnipotent things
huh I can't find where I found about "by the end of 2024" but I swear I didn't make this up lol
average rust dev
js framework memes but rust gui crates
zed just dislikes my gpu
i am guilty of being a part
my gpu meets the posted requirements but just doesn't work
do yall think windows would suck less ass if it was unix like
It fucking didn't
i did get it to run via wsl but it was very hacky and half the functionality was missing
i know it can run it just doesn't
you can just build it for windows yourself tho
i did
ah
thats how i know it doesn't work
i used a community build and built it myself and neither worked
whenever i see some nice gui app its either macos only or windows only and i as a linux user am left out
just wait for the year of the linux desktop
surely that won't take long
every year they go "this is the year of the linux desktop! i swear!" and the cycle continues
https://rxddit.com/r/unixporn/comments/1chehys/kde_got_diagnosed_with_autism_yesterday_there there were signs
and if its macos only it costs like $50
apple is definitely the platform to use if you hate having money lying around
realistically the year of the linux deskop is probably like 3+ years from now
people will be saying this in 3 years
most apple users earn enough to buy the newest iphone every year
yop
i have seen 2 types of apple users
- they have too much money and are obsessed with their walled garden
- have no clue what ios is and have an iphone just to show off
bc spammers always promise $50 steam gift cards
seems like a lua ls issue rather than zed
the wording implies you can increase that limit
yeah I don't mean it's zed's issue
oneshot here i think refers to channels
idk why it fails to use rust-analyzer even tho it works well in nvim
it even tries to access the rust-analyzer from nvim's mason packages (the one that alr works in nvim)
[2024-10-24T21:10:39+03:00 ERROR fs.rs] Error { code: -3, klass: 2, message: "failed to resolve path 'C:/Users/faint/AppData/Local/nvim-data/mason/packages/lua-language-server/meta/3rd/busted/../../../.git/modules/meta/3rd/busted': The system cannot find the path specified.\r\n" }
windows issues


i like my supermaven autocomplete but i hate all other usage of it
omg it works now! compiling the release version of zed seems to have fixed it
tho I'm not sure the error highlighting is supposed to look like uh that
like the "waves" look too uh big
Join me for an October scary story as we try to find the identity of the scariest C++ cast.
The original inspiration for implementing public_cast came from here. I wrote my own version which is more modern and (IMHO) easier to understand, but I take no credit for the ingenuity (and devilishness) of the basic implementation technique.
https://gi...
spooktober
scary
@valid jetty watch
oh lmao
what xd
bad panic handler
me trying not to procrastinate
fellow vencorians, im programming newbie and trying to make table of elems with numerated ids for later use in my js, but all of them lack numbers in their ids, why could this happen?
code:
let tableRowsPattern = `
<ul class="mTRow" id="mTR{{i}}">
</ul>
`
let rowTemp = Handlebars.compile(tableRowsPattern)
for (let i = 0; i < 16; i++) {
mainGrid.innerHTML += rowTemp(i)
}
try rowTemp({ i }) maybe?
never used handlebars but i bet that, since it templates variables by name, you're supposed to pass an object






