elpupper
elpupper
Explore posts from servers
CC#
Created by elpupper on 6/22/2024 in #help
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
public required MemoryFunctionVoid<IntPtr, IntPtr, int, bool, float, IntPtr> ProcessUsercmds;

// access the signatures in Load function
ProcessUsercmds = new(GameData.GetSignature("ProcessUsercmds"));
ProcessUsercmds.Hook(_OnProcessUsercmds, HookMode.Pre);


public HookResult _OnProcessUsercmds(DynamicHook h)
{
Logger.LogInformation("OnProcessUsercmds");
Logger.LogInformation("Param0: {value}", h.GetParam<IntPtr>(0));
nint ptr = h.GetParam<IntPtr>(0);
if (ptr == IntPtr.Zero)
return HookResult.Continue;
Logger.LogInformation("Ptr: {value}", ptr);
unsafe
{
// error happens here i tried CCSPlayerController player = new(ptr) but same error
// Whatever I try to do here to recast the type i just get that same error and ONLY in windows
CCSPlayerController player = ReinterpretCast<IntPtr, CCSPlayerController>(ptr);
Logger.LogInformation("Player: {value}", player);
Logger.LogInformation("Player SteamID: {value}", player.SteamID);
}
//Logger.LogInformation("Param0[CCSPlayerController*]: {value}", h.GetParam<CCSPlayerController>(0));
Logger.LogInformation("Param1[CUserCmd*]: {value}", h.GetParam<IntPtr>(1));
Logger.LogInformation("Param2[cmdCount]: {value}", h.GetParam<int>(2));
Logger.LogInformation("Param3[paused]: {value}", h.GetParam<bool>(3));
Logger.LogInformation("Param4[margin]: {value}", h.GetParam<float>(4));

return HookResult.Continue;
}

public required MemoryFunctionVoid<IntPtr, IntPtr, int, bool, float, IntPtr> ProcessUsercmds;

// access the signatures in Load function
ProcessUsercmds = new(GameData.GetSignature("ProcessUsercmds"));
ProcessUsercmds.Hook(_OnProcessUsercmds, HookMode.Pre);


public HookResult _OnProcessUsercmds(DynamicHook h)
{
Logger.LogInformation("OnProcessUsercmds");
Logger.LogInformation("Param0: {value}", h.GetParam<IntPtr>(0));
nint ptr = h.GetParam<IntPtr>(0);
if (ptr == IntPtr.Zero)
return HookResult.Continue;
Logger.LogInformation("Ptr: {value}", ptr);
unsafe
{
// error happens here i tried CCSPlayerController player = new(ptr) but same error
// Whatever I try to do here to recast the type i just get that same error and ONLY in windows
CCSPlayerController player = ReinterpretCast<IntPtr, CCSPlayerController>(ptr);
Logger.LogInformation("Player: {value}", player);
Logger.LogInformation("Player SteamID: {value}", player.SteamID);
}
//Logger.LogInformation("Param0[CCSPlayerController*]: {value}", h.GetParam<CCSPlayerController>(0));
Logger.LogInformation("Param1[CUserCmd*]: {value}", h.GetParam<IntPtr>(1));
Logger.LogInformation("Param2[cmdCount]: {value}", h.GetParam<int>(2));
Logger.LogInformation("Param3[paused]: {value}", h.GetParam<bool>(3));
Logger.LogInformation("Param4[margin]: {value}", h.GetParam<float>(4));

return HookResult.Continue;
}

this code works completely fine in linux but not on windows
103 replies