pouët.net

64k intro in c#

category: code [glöplog]
fxgen: my 4kb intro on last page could also do red if wanted ;) and that's with proper fullscreen and exit on escape (ofcourse it's a bit of a way from having a render loop)

You are doing way too much stuff - exception handling and cleanup in an intro? wtf!?
You shouldn't need a timer either, you just need to trigger a new repaint when done wih a frame.

But I see you're already on the slippery slope that makes it hard for me to see the point of .net intros (unlike demos). By doing winforms and win32 binding you are windows+x86 only, and a multiplatform solution can never compete with that setup (in a compo/whatever where windows only is allowed). Next step will be to drop winforms and simply open a win32 window like any native intro...
In other words, when is it .net and when is it native? the "more native" I make it the smaller it will be..

This should compile to 4kb if you make sure you have no garbage in the rest of your project:
Code:namespace d { static class p { static void Main() { var f = new Form() { BackColor = System.Drawing.Color.Gray, WindowState = FormWindowState.Maximized, FormBorderStyle = FormBorderStyle.None }; f.KeyUp += delegate { f.Close(); }; Application.Run(f); } } }
added on the 2019-12-19 22:57:07 by Psycho Psycho
fxgen: haven't had the time to look at it, please be patient :) (but as Psycho said: you can still throw out a lot of unneeded stuff). then you can start munging the PE/COFF headers, and the MetaData tables.

Psycho: you'll basically need to do PInvokes as soon as you want to do OpenGL stuff, as there's no standard wrapper lib for it. basic WinForms graphics should be ok, but that's also uuurghhhh (but viable for 4ks, I guess, unlike OpenGL)
added on the 2019-12-19 23:44:18 by porocyon porocyon
C# supports basic preprocessing (just bools though) like C++, so a) you can ditch all error handling in the release, also, you can probably still make it multi-platform that way as well.
added on the 2019-12-20 00:07:42 by maali maali
Compress IL Code for Intro Part it's not really a problem, this is a lot of works ... but not the problem.

The main problem is the Starter code (unpacker) that launch the Intro.
The unpacker is written in C# too and I can't compress it. We must look at PE headers, Metadata tables and executable size aligment ...
added on the 2019-12-20 14:24:43 by fxgen fxgen
I didn´t read it all, just skipped about 50% of it! ;)
But i knew it ain´t possible and said so in one of my first 2 posts already! ;)
You will get stuck at some point anyway! I had a big laugh-out because of that, just because you guys still try to beat sth i was sure isn´t beatable 10 years ago already, concluded so 8 years ago for real! :P :D :D :D
Thanx for trying, tho! (The laugh was worth it! :D )

You cannot fuck with PE-headers, etc. in C#! ;)

P.S.: Kewl Bonuz-pointz to Maali...didn´t know you are a coder at all, yet! But you proved me wrongz0rz! :D
Will the real Hardy please stand up?
added on the 2019-12-22 09:32:21 by SiR SiR
fxgen: very nice work so far, keep going! I'd be really surprised if some PE/header hacking wasn't possible; I'd bet there's quite a lot of relatively low hanging fruit, and I'd be willing to bet you'll get better gains starting there than in the unpacker. Bonus points for continuing to ignore hardy's asshat comments (honestly, I'm actually shocked at how much of a dick he's being).
added on the 2019-12-22 14:26:21 by ferris ferris
Shocked, but not surprised?
added on the 2019-12-22 14:35:31 by Gargaj Gargaj
If we use dot net core to launch your intro we do not need PE-header ... so we our opengl creation context is less than 4k !

dotnet.exe intro64.dll

but this is not installed by default on windows so not allowed in demoparty ... maybe with .net 5.0

for the comments, I demonstrated that we could do it in C#, yes it's better to do it with C/C++ but Its possible ;-)

sorry if i offended people :-)
added on the 2019-12-22 16:43:05 by fxgen fxgen
I don't think using .NET Core stuff will be possible.

While it's true that some header hacking isn't possible (eg. I'm pretty sure the "MZfarbrauschPE" trick won't work), but I'm pretty sure the metadata tables can have some omissions, and could maybe overlap with the PE headers. There's a .NET hello world program written in NASM available here, could maybe be a good starting point (but it'll probably need some modifications to work with .NET 4)

Also ignore hardy, he's being a dick.
added on the 2019-12-22 16:55:14 by porocyon porocyon
Even if a lot of headers can't be folded, I'm sure there are still fields that could be used to store [compressed] data. In squishy/kkrunchy, for example, all of the space between the exe header and the collapsed section is used to store compressed data. It gets loaded by adjusting the header size field to span the entire region between the image base address and the first section, and it's read at runtime like any other read-only data. I'd be surprised if this didn't work for a .net binary, and alleviates the need to do most of the folding in the first place. Ideally the MZ header could be used for useful data in a similar fashion (in fact iirc Conspiracy's kkrunchy fork doesn't fold the PE header into the MZ header [for signing compatibility reasons?] and instead uses that space for ASCII art/flair).
added on the 2019-12-22 17:10:39 by ferris ferris
Quote:
(in fact iirc Conspiracy's kkrunchy fork doesn't fold the PE header into the MZ header [for signing compatibility reasons?] and instead uses that space for ASCII art/flair).


Yeah that's the reason. The MS signing tool checks if the PE header offset at 0x3C in the MZ header points to before or to 0x3C and if it does it determines that the binary is not in fact an executable and doesn't sign it. We did this when experimenting with binary signing to combat the false positive AV stuff to no avail. We did keep it because of the fun hidden flair and better binary compatibility though at the minor cost of 48 bytes.
added on the 2019-12-23 02:00:43 by BoyC BoyC
I´m just doing my voluntary troll-work here! ;)
Maybe i just want to push you...so you finally prove me wrong! :)
As said: C# is my favourite language...would love to see it coming true!
Is someone is interested to do an 64k intro in C# ?
added on the 2019-12-24 13:43:11 by fxgen fxgen
Is it possible for a native process to launch a CLR process from data in memory? If so, a native cruncher could be used, and there might be more flexibility as to the representation (and post-decompression transformation) of the various kinds of data.
added on the 2019-12-25 21:53:40 by Blueberry Blueberry
Blueberry: that's technically possible (using the functions from mscoree.dll), but afaics it only expects data that's already formatted as a .NET assembly/PE (see this and this), which I guess could be done, but it'd be better if it'd only need the actual MD tables and bytecode without requiring the PE overhead.

Also this won't work on Mono :< (it'd need a completely different loading stub, ofc, plus it'd have to be an ELF)

(Alternatively, PowerShell decompression scripts, which, AAAAAAAAAAAAAAAAAAAAAAA)

Anyway, I don't think the bytecode for a pure .NET unpacker would be that large either. (But then there's still the MD tables... sigh.)
added on the 2019-12-25 22:25:06 by porocyon porocyon
If few bytes of bootstrapping is not an issue, you can dynamically create and/or execute C# code using PowerShell. This practically means that you could consider leaving out the .exe compiling stage. PowerShell also has out-of-box DEFLATE and GZip support.

Also PowerShell intro (with some, but not great, audiovisuals) can be done in 1K. PowerShell&C# is portable but you'd need to restrict yourself from some more interesting hacks. Windows PowerShell,C#,.NET seems to offer all kinds of bells and whistles for just a few bytes that are practically unexplored by the demoscene community.

Now go do 1K, 4K, 64K, demo or what ever you want with C# :D
added on the 2019-12-28 07:30:38 by waffle waffle
Perhaps relevant: https://medium.com/@MStrehovsky/building-a-self-contained-game-in-c-under-8-kilobytes-74c3cf60ea04
added on the 2020-01-03 18:15:12 by dr_evil dr_evil
dr_evil: that gives you a native binary, not a .NET one
added on the 2020-01-03 19:11:33 by porocyon porocyon
True, but isn't this thread about doing something in C#?
added on the 2020-01-03 19:40:04 by dr_evil dr_evil
By using crinkler and 32bit instead of 64bit he now got it down to 2121 bytes.
added on the 2020-01-10 08:17:52 by dr_evil dr_evil
saw this post today and got reminded of this thread
https://blog.washi.dev/posts/tinysharp/
added on the 2023-07-09 19:20:05 by psenough psenough
Why would anybody seriously consider using C# for making a 64k intro? C# isn't made for producing heavily size optimized executables.
added on the 2023-07-10 08:40:44 by Adok Adok
Hi Adok, is this your first time at the demoscene? :)

BB Image
added on the 2023-07-10 10:38:10 by evilpaul evilpaul
"We choose to do these things not because they are easy, but because we thought they would be easy."
added on the 2023-07-10 10:51:53 by gigabates gigabates

login