Decrypted
Decrypted
CC#
Created by Nolram on 3/16/2025 in #help
NativeAOT Serialization Troubles
Could also have been that none of the ModuleInitializers were called and as a result all types had to be registered manually. Don't have access to the project anymore and cannot check sorry
13 replies
CC#
Created by Nolram on 3/16/2025 in #help
NativeAOT Serialization Troubles
Iirc we had some issues where ModuleInitializer was not called with NativeAOT for some reason and union types were not registered. Had to manually register them. Like
// (ushort, Type)[]
var formatter = new DynamicUnionFormatter<IFooBarBaz>(
(0, typeof(Foo)),
(1, typeof(Bar)),
(2, typeof(Baz))
);

MemoryPackFormatterProvider.Register(formatter);
// (ushort, Type)[]
var formatter = new DynamicUnionFormatter<IFooBarBaz>(
(0, typeof(Foo)),
(1, typeof(Bar)),
(2, typeof(Baz))
);

MemoryPackFormatterProvider.Register(formatter);
13 replies
CC#
Created by MoscaCareca on 3/13/2025 in #help
C# 5+ compiler
https://github.com/pythonnet/pythonnet might this be of any use? Used this in one project to call python scripts from C# but should be able to do the reverse. Could use this to import C# assemblies to compile the .cs file?
72 replies
CC#
Created by Vlad on 4/2/2024 in #help
Feeding Random into itself - does it "corrupt the randomness"?
public class Rng
{
public byte[] State => _state;

private byte[] _state = new byte[32];

public Rng(int seed)
{
var rand = new Random(seed);

// fill state from seed
rand.NextBytes(_state);
}

public Rng(byte[] state)
{
_state = state;
}

public int Next()
{
// Hash new state
if (!SHA256.TryHashData(_state, _state, out _))
{
throw new InvalidOperationException();
}

var bigInt = new BigInteger(_state);

return (int)(bigInt % int.MaxValue);
}
}
public class Rng
{
public byte[] State => _state;

private byte[] _state = new byte[32];

public Rng(int seed)
{
var rand = new Random(seed);

// fill state from seed
rand.NextBytes(_state);
}

public Rng(byte[] state)
{
_state = state;
}

public int Next()
{
// Hash new state
if (!SHA256.TryHashData(_state, _state, out _))
{
throw new InvalidOperationException();
}

var bigInt = new BigInteger(_state);

return (int)(bigInt % int.MaxValue);
}
}
This uses SHA256 to hash the state on top of itself You can then persist the 32 byte state and resume from it when required. Not sure if this is the best way to do this. I don't even know if the bigInt % int.MaxValue is safe operation for converting to int..
61 replies
CC#
Created by Vlad on 4/2/2024 in #help
Feeding Random into itself - does it "corrupt the randomness"?
I got resumable rand class somewhere, let me try to find it
61 replies