System.AccessViolationException In windows but not in linux
I come here alas, I could not figure this out for 3 days now
I am basically writing a plugin for CS2 dedicated servers using CS#
My goal is to access the subtick movements introduced in cs2 to record some movements as keypressed dont call commands till the next game tick
so basically I have
this code works completely fine in linux but not on windows
61 Replies
Could you define the idea behind the code? What's it's intended purpose?
And could we get the implementation of
To ReinterpretCast<From, To>(From value)
please?ah yes sorry
the idea rn atleast is to be able t get the steamid from the player
this gives us the playercontroller and we can do a lot of things with it
but for now just something basic like printing the user's steamid
but the end goal is to be able to access the subtick params
Generally speaking, it's not desireable to use a hidden/undocumented C# operator like
__makeref()
. The desired behavior can be written as return Unsafe.As<TSource, TDest>(ref source);
The Unsafe
helper class is exposed from System.Runtime.CompilerServices
.
This is of course assuming both types are the same size, and are both value types. Something tells me the IntPtr
aka nint
is actually a CCSPlayerController*
or similar, in which case the desired code should be something like this:
Is my assumption correct?yes
i tried that as well
CCSPlayerController does take a pointer
Could we get a definition of the type in question?
Is it just a wrapper around a pointer?
Oh god that's a class... In which case,
new CCSPlayerController(ptr)
should be used.thats what i did
and i still get that error
Do you know if the pointer is valid? It could be non-null and yet still not be valid.
yes
it is valid
it is from a sig from the modding community
What's the stack trace of the exception?
let me try to get it again
server crashes so fast without logs
here i will try it with
CCSPlayerController player = *(CCSPlayerController*)ptr;
Won't work if CCSPlayerController is a
class
At least it won't work as intended
If the pointer to object reference feature is implemented yet.
In any case, the exception tells me that some pointer or another isn't being interpretted correctly.
@Gamma_Draconis here it is
at System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array, IntPtr, System.Object)
This right here...i dont understand this
I don't understand it either because you're not accessing an array...
ill try iwth
CCSPlayerController player = ReinterpretCast<IntPtr, CCSPlayerController>(ptr);
and get the full thing
owe i got a big error
1 secYeah no, I expected that to fail.
Can I get the implementation of
DynamicHook
?GitHub
CounterStrikeSharp/managed/CounterStrikeSharp.API/Modules/Memory/Dy...
CounterStrikeSharp allows you to write server plugins in C# for Counter-Strike 2/Source2/CS2 - roflmuffin/CounterStrikeSharp
ok
i will send you those next time
and we use this to process signatures
https://github.com/roflmuffin/CounterStrikeSharp/blob/main/managed/CounterStrikeSharp.API/Modules/Memory/DynamicFunctions/MemoryFunctionVoid.cs
tell me about it
I'd expect a function pointer to be here... but instead I get... whatever the heck that is.
That does not help me or anyone else debug an access violation.
what do you suggest i do
Talk to a maintainer of the codebase about it. If that should fail, I haven't a clue.
ok
The maintainers of CounterStrikeSharp specifically, in case that wasn't clear. ^_^
yes i get it im not that incompentent
I can never be sure with some people lol
i just dont understand c# that much
dont blame ya
I'm certain this is just a lack of understanding of what to do here, but I am not the source of this knowledge.
thought i mighta said something that made me seem crazy
Nah, you're good. lol
Wait..
uhoh
Could it be that it needs to be written out as
h.GetParam<CCSPlayerController>(0)
? Or does that not work?no because of memoryfunctionvoid
even if i had
public required MemoryFunctionVoid<CCSPlayerController, IntPtr, int, bool, float, IntPtr> ProcessUsercmds;
Why wouldn't that work? Do you know?
let me try again
i forgot the error
It looks like, according to the stack trace, the general setup is supported, but something's not being looked at right. Talk to a maintainer, see what they think.
Do you control what's passed as the first argument at all?
Or is the caller in Native?
wel uy usee
its all really based on metamod
i32 FASTCALL movement::Detour_ProcessUsercmds(CCSPlayerController *controller, void *cmds, int numcmds, bool paused, float margin)
If
new CCSPlayerController(ptr);
doesn't work, I imagine it's a bug in the framework's code somewhere.
So I don't think this is on you at all, given that definition.but why does this work in linux
Memory layout can change between windows and linux.
If they're using constant field offsets, that could screw things up.
thats why we have
signatures
Signatures affect method calls only, memory layout affects objects and data structures in memory
yes but its consistent
Padding and so forth add into that
btw
it doesnt even let me try catch these things
This is a runtime level exception, it wouldn't let anyone try to catch them.
Something about this isn't right, in this particular circumstance.
That's as far as I can go.
why
Wait, no, not that... This
According to the exception stack trace
get_Raw
being the Raw
property's getterim sicka this
i giveup
fuck cs2