Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Vehicle & Remote Method Enhancements #102

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions OmsiExtensionsCLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Reflection;
Expand Down Expand Up @@ -54,37 +55,54 @@ static void Main(string[] args)
Console.WriteLine($"Read data: map:{map?.Name} path:{map?.Filename} friendly:{map?.FriendlyName}".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"Time: {omsi.Globals.Time.Day}/{omsi.Globals.Time.Month}/{omsi.Globals.Time.Year} - {omsi.Globals.Time.Hour}:{omsi.Globals.Time.Minute}:{omsi.Globals.Time.Second:F2} ");
Console.WriteLine($"Camera pos: {cam.Pos} ".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"{omsi.Globals.Drivers}".PadRight(Console.WindowWidth - 1));
//Console.WriteLine($"{omsi.Globals.Drivers}".PadRight(Console.WindowWidth - 1));

/*if(!dXTests.IsReady)
dXTests.CreateTexture();
if(dXTests.IsReady)
dXTests.UpdateTexture();*/
///*if(!dXTests.IsReady)
// dXTests.CreateTexture();
//if(dXTests.IsReady)
// dXTests.UpdateTexture();*/

Console.WriteLine($"[MOUSE] pos: {progMan.MausPos}".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"[MOUSE] ray_pos: {progMan.MausLine3DPos} ray_dir: {progMan.MausLine3DDir}".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"[MOUSE] mouse_mesh_event: {progMan.Maus_MeshEvent}".PadRight(Console.WindowWidth - 1));
CheckClickPos(progMan, meshes, meshInsts);
//Console.WriteLine($"[MOUSE] pos: {progMan.MausPos}".PadRight(Console.WindowWidth - 1));
//Console.WriteLine($"[MOUSE] ray_pos: {progMan.MausLine3DPos} ray_dir: {progMan.MausLine3DDir}".PadRight(Console.WindowWidth - 1));
//Console.WriteLine($"[MOUSE] mouse_mesh_event: {progMan.Maus_MeshEvent}".PadRight(Console.WindowWidth - 1));
//CheckClickPos(progMan, meshes, meshInsts);

Console.WriteLine($"Loaded textures: {textures.Count}");
Console.WriteLine($"Path id: {playerVehicle.PathInfo.path.path}");
//Console.WriteLine($"Loaded textures: {textures.Count}");
//Console.WriteLine($"Path id: {playerVehicle.PathInfo.path.path}");

/*Console.WriteLine("".PadRight(Console.WindowWidth-1));
try
{
if (omsi.Globals.PlayerVehicle != null)
{
Console.WriteLine($"INEO_PS_Matricule: {omsi.Globals.PlayerVehicle.GetStringVariable("INEO_Login")}".PadRight(Console.WindowWidth - 1));
///*Console.WriteLine("".PadRight(Console.WindowWidth-1));
//try
//{
// if (omsi.Globals.PlayerVehicle != null)
// {
// Console.WriteLine($"INEO_PS_Matricule: {omsi.Globals.PlayerVehicle.GetStringVariable("INEO_Login")}".PadRight(Console.WindowWidth - 1));


omsi.Globals.PlayerVehicle.SetStringVariable("INEO_Login", toggle ? "thomas" : "01234");
toggle = !toggle;
}
}
catch (Exception e) { Console.WriteLine(e.Message); }*/
// omsi.Globals.PlayerVehicle.SetStringVariable("INEO_Login", toggle ? "thomas" : "01234");
// toggle = !toggle;
// }
//}
//catch (Exception e) { Console.WriteLine(e.Message); }*/
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably shouldn't have been committed...



var OMSIRM = omsi.RemoteMethods;
//OMSIRM.PlaceRandomBus();
Console.WriteLine("Placed");

OMSIRM.OmsiSetCriticalSectionLock(omsi.Globals.ProgamManager.CS_MakeVehiclePtr).ContinueWith((_) =>
{
OMSIRM.MakeVehicle(@"Vehicles\GPM_MAN_LionsCity_M\MAN_A47.bus", __copyToMainList: true).ContinueWith((id) =>
{
Console.WriteLine($"Spawned Vehicle ID: {id.Result}");
OMSIRM.OmsiReleaseCriticalSectionLock(omsi.Globals.ProgamManager.CS_MakeVehiclePtr).ContinueWith((_)=>Console.WriteLine($"Unlock"));
});
});
break;
Debugger.Break();

Thread.Sleep(20);
}
Console.ReadLine();
}

private static void CheckClickPos(OmsiProgMan progMan, MemArrayList<OmsiAnimSubMesh> meshes, MemArrayList<OmsiAnimSubMeshInst> meshInsts)
Expand Down
64 changes: 64 additions & 0 deletions OmsiHook/FastBinaryWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OmsiHook;

internal static class FastBinaryWriter
{
public static void Write(Span<byte> buffer, ref int pos, int data)
{
BitConverter.TryWriteBytes(buffer[pos..], data);
pos += 4;
}

public static void Write(Span<byte> buffer, ref int pos, uint data)
{
BitConverter.TryWriteBytes(buffer[pos..], data);
pos += 4;
}

public static void Write(Span<byte> buffer, ref int pos, short data)
{
BitConverter.TryWriteBytes(buffer[pos..], data);
pos += 2;
}
public static void Write(Span<byte> buffer, ref int pos, ushort data)
{
BitConverter.TryWriteBytes(buffer[pos..], data);
pos += 2;
}

public static void Write(Span<byte> buffer, ref int pos, byte data, int advance = 1)
{
BitConverter.TryWriteBytes(buffer[pos..], data);
pos += advance;
}

public static void Write(Span<byte> buffer, ref int pos, sbyte data)
{
BitConverter.TryWriteBytes(buffer[pos..], data);
pos += 1;
}

public static void Write(Span<byte> buffer, ref int pos, bool data)
{
BitConverter.TryWriteBytes(buffer[pos..], data);
pos += 1;
}

public static void Write(Span<byte> buffer, ref int pos, float data)
{
BitConverter.TryWriteBytes(buffer[pos..], data);
pos += 4;
}

public static void Write(byte[] buffer, ref int pos, int data)
{
BitConverter.TryWriteBytes(buffer.AsSpan()[pos..], data);
pos += 4;
}
}
10 changes: 9 additions & 1 deletion OmsiHook/OmsiHookRPCMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ internal static class OmsiHookRPCMethods
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum RemoteMethod : int
{
None,
CloseRPCConnection,
TProgManMakeVehicle,
TTempRVListCreate,
CopyTempListIntoMainList,
TProgManPlaceRandomBus,
GetMem,
FreeMem,
Expand All @@ -26,14 +28,18 @@ internal enum RemoteMethod : int
GetTextureLevelCount,
IsTexture,
RVTriggerXML,
SoundTrigger
SoundTrigger,
SetCriticalSectionLock,
ReleaseCriticalSectionLock
}

internal static readonly ReadOnlyDictionary<RemoteMethod, int> RemoteMethodsArgsSizes = new(new Dictionary<RemoteMethod, int>()
{
{ RemoteMethod.None, 0 },
{ RemoteMethod.CloseRPCConnection, 4 },
{ RemoteMethod.TProgManMakeVehicle, 61 },
{ RemoteMethod.TTempRVListCreate, 8 },
{ RemoteMethod.CopyTempListIntoMainList, 8 },
{ RemoteMethod.TProgManPlaceRandomBus, 35 },
{ RemoteMethod.GetMem, 4 },
{ RemoteMethod.FreeMem, 4 },
Expand All @@ -46,6 +52,8 @@ internal enum RemoteMethod : int
{ RemoteMethod.IsTexture, 4 },
{ RemoteMethod.RVTriggerXML, 12 },
{ RemoteMethod.SoundTrigger, 12 },
{ RemoteMethod.SetCriticalSectionLock, 4 },
{ RemoteMethod.ReleaseCriticalSectionLock, 4 },
});
}
}
Loading